mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2024-11-21 03:15:49 +08:00
Merge pull request #351 from webzard-io/fix/windlike-patch
Fix/windlike patch
This commit is contained in:
commit
2a4d4d9dba
@ -40,6 +40,7 @@
|
||||
"@sunmao-ui/core": "^0.5.2",
|
||||
"@sunmao-ui/editor-sdk": "^0.1.3",
|
||||
"@sunmao-ui/runtime": "^0.5.2",
|
||||
"@sinclair/typebox": "^0.21.2",
|
||||
"acorn": "^8.7.0",
|
||||
"acorn-loose": "^8.3.0",
|
||||
"acorn-walk": "^8.2.0",
|
||||
@ -61,6 +62,7 @@
|
||||
"@sunmao-ui/vite-plugins": "^1.0.2",
|
||||
"@swc/core": "^1.2.121",
|
||||
"@types/codemirror": "^5.60.5",
|
||||
"@types/json-schema": "^7.0.7",
|
||||
"@types/lodash-es": "^4.17.5",
|
||||
"@types/tern": "^0.23.4",
|
||||
"@vitejs/plugin-react": "^1.0.1",
|
||||
|
@ -1,7 +1,8 @@
|
||||
import React from 'react';
|
||||
import { EventWidget, mergeWidgetOptionsIntoSchema } from '@sunmao-ui/editor-sdk';
|
||||
import { EventWidget } from '@sunmao-ui/editor-sdk';
|
||||
import { Box, IconButton, VStack } from '@chakra-ui/react';
|
||||
import { Static } from '@sinclair/typebox';
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { CloseIcon } from '@chakra-ui/icons';
|
||||
import { EventHandlerSchema } from '@sunmao-ui/runtime';
|
||||
import { ComponentSchema } from '@sunmao-ui/core';
|
||||
@ -13,19 +14,19 @@ type Props = {
|
||||
handler: Static<typeof EventHandlerSchema>;
|
||||
onChange: (handler: Static<typeof EventHandlerSchema>) => void;
|
||||
onRemove: () => void;
|
||||
hideEventType?: boolean;
|
||||
services: EditorServices;
|
||||
schema?: JSONSchema7;
|
||||
};
|
||||
|
||||
export const EventHandlerForm: React.FC<Props> = props => {
|
||||
const { handler, component, onChange, onRemove, hideEventType, services } = props;
|
||||
const { schema = EventHandlerSchema, handler, component, onChange, onRemove, services } = props;
|
||||
|
||||
return (
|
||||
<Box position="relative" width="100%">
|
||||
<VStack className={formWrapperCSS}>
|
||||
<EventWidget
|
||||
component={component}
|
||||
schema={mergeWidgetOptionsIntoSchema(EventHandlerSchema, { hideEventType })}
|
||||
schema={schema}
|
||||
value={handler}
|
||||
path={[]}
|
||||
level={1}
|
||||
|
@ -19,8 +19,9 @@ import { EventHandlerForm } from '../../ComponentForm/EventTraitForm/EventHandle
|
||||
import {
|
||||
FetchTraitPropertiesSchema,
|
||||
EventCallBackHandlerSchema,
|
||||
BaseEventSchema
|
||||
} from '@sunmao-ui/runtime';
|
||||
import { Static } from '@sinclair/typebox';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { EditorServices } from '../../../types';
|
||||
import { ComponentSchema } from '@sunmao-ui/core';
|
||||
|
||||
@ -94,7 +95,7 @@ export const Basic: React.FC<Props> = props => {
|
||||
<EventHandlerForm
|
||||
component={api}
|
||||
handler={{ type: '', ...handler }}
|
||||
hideEventType={true}
|
||||
schema={Type.Object(BaseEventSchema)}
|
||||
onChange={onChange}
|
||||
onRemove={onRemove}
|
||||
services={services}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { RuntimeComponentSchema } from '@sunmao-ui/core';
|
||||
import { ChildrenMap } from '../types';
|
||||
import { isFetchTraitComponent } from '../utils/trait';
|
||||
|
||||
export function resolveChildrenMap(components: RuntimeComponentSchema[]): {
|
||||
childrenMap: ChildrenMap<string>;
|
||||
@ -7,11 +8,16 @@ export function resolveChildrenMap(components: RuntimeComponentSchema[]): {
|
||||
} {
|
||||
const childrenMap: ChildrenMap<string> = {};
|
||||
const topLevelComponents: RuntimeComponentSchema[] = [];
|
||||
const fetchTraitComponents: RuntimeComponentSchema[] = [];
|
||||
|
||||
for (const c of components) {
|
||||
const slotTrait = c.traits.find(t => t.parsedType.name === 'slot');
|
||||
if (!slotTrait) {
|
||||
topLevelComponents.push(c);
|
||||
if (isFetchTraitComponent(c)) {
|
||||
fetchTraitComponents.push(c);
|
||||
} else {
|
||||
topLevelComponents.push(c);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const { id, slot } = slotTrait.properties.container as any;
|
||||
@ -58,6 +64,6 @@ export function resolveChildrenMap(components: RuntimeComponentSchema[]): {
|
||||
|
||||
return {
|
||||
childrenMap,
|
||||
topLevelComponents,
|
||||
topLevelComponents: [...topLevelComponents, ...fetchTraitComponents],
|
||||
};
|
||||
}
|
||||
|
5
packages/runtime/src/utils/trait.ts
Normal file
5
packages/runtime/src/utils/trait.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { ComponentSchema } from '@sunmao-ui/core';
|
||||
|
||||
export function isFetchTraitComponent(component: ComponentSchema): boolean {
|
||||
return component.type === 'core/v1/dummy' && component.traits.filter(trait=> trait.type === 'core/v1/fetch').length > 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user