@chamn/engine 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component/CustomSchemaForm/components/Form/context.d.ts +2 -0
- package/dist/component/CustomSchemaForm/components/Form/index.d.ts +1 -0
- package/dist/component/CustomSchemaForm/components/SetterSwitcher/index.d.ts +2 -0
- package/dist/component/CustomSchemaForm/index.d.ts +3 -0
- package/dist/component/Workbench/index.d.ts +4 -0
- package/dist/core/pluginManager.d.ts +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +197 -0
- package/dist/index.js.map +1 -0
- package/dist/{index.es.js → index.mjs} +2995 -2944
- package/dist/index.mjs.map +1 -0
- package/dist/plugins/RightPanel/view.d.ts +4 -0
- package/package.json +12 -9
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -36
- package/.prettierrc.json +0 -7
- package/.storybook/main.js +0 -24
- package/.storybook/preview.js +0 -9
- package/CHANGELOG.md +0 -54
- package/__tests__/demo.test.ts +0 -3
- package/build.config.js +0 -88
- package/dist/index.cjs.js +0 -197
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.es.js.map +0 -1
- package/index.html +0 -16
- package/jest.config.js +0 -196
- package/public/Engine.module.scss.d.ts +0 -5
- package/public/_dev_/render.d.ts +0 -2
- package/public/component/CSSEditor/style.module.scss.d.ts +0 -6
- package/public/component/CSSPropertiesEditor/style.module.scss.d.ts +0 -15
- package/public/component/CSSPropertiesVariableBindEditor/style.module.scss.d.ts +0 -15
- package/public/component/CustomSchemaForm/components/Form/Field/style.module.scss.d.ts +0 -8
- package/public/component/CustomSchemaForm/components/SetterSwitcher/style.module.scss.d.ts +0 -7
- package/public/component/CustomSchemaForm/components/Setters/ArraySetter/style.module.scss.d.ts +0 -7
- package/public/component/CustomSchemaForm/components/Setters/CSSValueSetter/style.module.scss.d.ts +0 -6
- package/public/component/CustomSchemaForm/style.module.scss.d.ts +0 -11
- package/public/component/Workbench/style.module.scss.d.ts +0 -25
- package/public/plugins/AdvancePanel/style.module.scss.d.ts +0 -7
- package/public/plugins/ComponentLibrary/components/DragItem/style.module.scss.d.ts +0 -9
- package/public/plugins/ComponentLibrary/components/ListView/style.module.scss.d.ts +0 -12
- package/public/plugins/ComponentLibrary/style.module.scss.d.ts +0 -11
- package/public/plugins/Designer/components/DefaultSelectToolBar/style.module.scss.d.ts +0 -11
- package/public/plugins/Designer/style.module.scss.d.ts +0 -5
- package/public/plugins/GlobalStatePanel/style.module.scss.d.ts +0 -5
- package/public/plugins/OutlineTree/components/TreeView/style.module.scss.d.ts +0 -16
- package/public/plugins/PropertyPanel/style.module.scss.d.ts +0 -10
- package/public/plugins/RightPanel/style.module.scss.d.ts +0 -10
- package/public/plugins/VisualPanelPlus/style.module.scss.d.ts +0 -10
- package/public/render.umd.js +0 -42
- package/public/render.umd.js.map +0 -1
- package/src/Engine.module.scss +0 -10
- package/src/Engine.module.scss.d.ts +0 -5
- package/src/_dev_/index.css +0 -22
- package/src/_dev_/index.tsx +0 -5
- package/src/_dev_/page/Editor/index.tsx +0 -198
- package/src/_dev_/page/Editor/indexCustom.tsx +0 -274
- package/src/_dev_/page/Preview/index.tsx +0 -56
- package/src/_dev_/render.ts +0 -3
- package/src/_dev_/router.tsx +0 -14
- package/src/assets/react.svg +0 -4
- package/src/assets/styles/mixin.scss +0 -15
- package/src/component/CSSEditor/index.tsx +0 -247
- package/src/component/CSSEditor/style.module.scss +0 -22
- package/src/component/CSSEditor/style.module.scss.d.ts +0 -6
- package/src/component/CSSPropertiesEditor/cssProperties.ts +0 -1062
- package/src/component/CSSPropertiesEditor/index.tsx +0 -389
- package/src/component/CSSPropertiesEditor/style.module.scss +0 -46
- package/src/component/CSSPropertiesEditor/style.module.scss.d.ts +0 -15
- package/src/component/CSSPropertiesEditor/util.ts +0 -19
- package/src/component/CSSPropertiesVariableBindEditor/cssProperties.ts +0 -782
- package/src/component/CSSPropertiesVariableBindEditor/index.tsx +0 -366
- package/src/component/CSSPropertiesVariableBindEditor/style.module.scss +0 -48
- package/src/component/CSSPropertiesVariableBindEditor/style.module.scss.d.ts +0 -15
- package/src/component/CSSPropertiesVariableBindEditor/util.ts +0 -19
- package/src/component/ClassNameEditor/index.tsx +0 -91
- package/src/component/ClassNameEditor/style.module.scss +0 -0
- package/src/component/CustomSchemaForm/components/Form/Field/index.tsx +0 -81
- package/src/component/CustomSchemaForm/components/Form/Field/style.module.scss +0 -32
- package/src/component/CustomSchemaForm/components/Form/Field/style.module.scss.d.ts +0 -8
- package/src/component/CustomSchemaForm/components/Form/context.ts +0 -23
- package/src/component/CustomSchemaForm/components/Form/index.tsx +0 -71
- package/src/component/CustomSchemaForm/components/SetterSwitcher/index.tsx +0 -273
- package/src/component/CustomSchemaForm/components/SetterSwitcher/style.module.scss +0 -16
- package/src/component/CustomSchemaForm/components/SetterSwitcher/style.module.scss.d.ts +0 -7
- package/src/component/CustomSchemaForm/components/Setters/ArraySetter/ArrayItem.tsx +0 -55
- package/src/component/CustomSchemaForm/components/Setters/ArraySetter/SortItemOrderModal.tsx +0 -160
- package/src/component/CustomSchemaForm/components/Setters/ArraySetter/index.tsx +0 -129
- package/src/component/CustomSchemaForm/components/Setters/ArraySetter/style.module.scss +0 -22
- package/src/component/CustomSchemaForm/components/Setters/ArraySetter/style.module.scss.d.ts +0 -7
- package/src/component/CustomSchemaForm/components/Setters/BooleanSetter/index.tsx +0 -32
- package/src/component/CustomSchemaForm/components/Setters/CSSValueSetter/index.tsx +0 -78
- package/src/component/CustomSchemaForm/components/Setters/CSSValueSetter/style.module.scss +0 -7
- package/src/component/CustomSchemaForm/components/Setters/CSSValueSetter/style.module.scss.d.ts +0 -6
- package/src/component/CustomSchemaForm/components/Setters/ExpressionSetter/index.tsx +0 -47
- package/src/component/CustomSchemaForm/components/Setters/FunctionSetter/defaultDts.ts +0 -28
- package/src/component/CustomSchemaForm/components/Setters/FunctionSetter/index.tsx +0 -93
- package/src/component/CustomSchemaForm/components/Setters/JSONSetter/index.tsx +0 -80
- package/src/component/CustomSchemaForm/components/Setters/NumberSetter/index.tsx +0 -34
- package/src/component/CustomSchemaForm/components/Setters/SelectSetter/index.tsx +0 -35
- package/src/component/CustomSchemaForm/components/Setters/ShapeSetter/index.tsx +0 -65
- package/src/component/CustomSchemaForm/components/Setters/StringSetter/index.tsx +0 -30
- package/src/component/CustomSchemaForm/components/Setters/TextAreaSetter/index.tsx +0 -31
- package/src/component/CustomSchemaForm/components/Setters/index.ts +0 -26
- package/src/component/CustomSchemaForm/components/Setters/type.ts +0 -18
- package/src/component/CustomSchemaForm/context.ts +0 -20
- package/src/component/CustomSchemaForm/index.tsx +0 -93
- package/src/component/CustomSchemaForm/style.module.scss +0 -15
- package/src/component/CustomSchemaForm/style.module.scss.d.ts +0 -11
- package/src/component/CustomSchemaForm/utils.ts +0 -13
- package/src/component/MonacoEditor/index.tsx +0 -81
- package/src/component/Workbench/index.tsx +0 -329
- package/src/component/Workbench/style.module.scss +0 -159
- package/src/component/Workbench/style.module.scss.d.ts +0 -25
- package/src/core/pluginManager.ts +0 -151
- package/src/i18n/en_US/index.ts +0 -5
- package/src/i18n/index.ts +0 -39
- package/src/i18n/zh_CN/index.ts +0 -5
- package/src/index.tsx +0 -150
- package/src/material/innerMaterial.ts +0 -343
- package/src/plugins/AdvancePanel/index.tsx +0 -191
- package/src/plugins/AdvancePanel/style.module.scss +0 -8
- package/src/plugins/AdvancePanel/style.module.scss.d.ts +0 -7
- package/src/plugins/ComponentLibrary/components/DragItem/index.tsx +0 -65
- package/src/plugins/ComponentLibrary/components/DragItem/style.module.scss +0 -58
- package/src/plugins/ComponentLibrary/components/DragItem/style.module.scss.d.ts +0 -9
- package/src/plugins/ComponentLibrary/components/ListView/index.tsx +0 -50
- package/src/plugins/ComponentLibrary/components/ListView/style.module.scss +0 -27
- package/src/plugins/ComponentLibrary/components/ListView/style.module.scss.d.ts +0 -12
- package/src/plugins/ComponentLibrary/index.tsx +0 -184
- package/src/plugins/ComponentLibrary/localize/en_US/index.ts +0 -3
- package/src/plugins/ComponentLibrary/localize/index.ts +0 -3
- package/src/plugins/ComponentLibrary/localize/zh_CN/index.ts +0 -3
- package/src/plugins/ComponentLibrary/style.module.scss +0 -31
- package/src/plugins/ComponentLibrary/style.module.scss.d.ts +0 -11
- package/src/plugins/ComponentLibrary/util.ts +0 -14
- package/src/plugins/ComponentStatePanel/index.tsx +0 -59
- package/src/plugins/Designer/components/DefaultSelectToolBar/index.tsx +0 -94
- package/src/plugins/Designer/components/DefaultSelectToolBar/style.module.scss +0 -59
- package/src/plugins/Designer/components/DefaultSelectToolBar/style.module.scss.d.ts +0 -11
- package/src/plugins/Designer/components/GhostView/index.tsx +0 -18
- package/src/plugins/Designer/config.ts +0 -1
- package/src/plugins/Designer/index.tsx +0 -61
- package/src/plugins/Designer/localize/en_US/index.ts +0 -3
- package/src/plugins/Designer/localize/index.ts +0 -3
- package/src/plugins/Designer/localize/zh_CN/index.ts +0 -3
- package/src/plugins/Designer/style.module.scss +0 -10
- package/src/plugins/Designer/style.module.scss.d.ts +0 -5
- package/src/plugins/Designer/util.ts +0 -18
- package/src/plugins/Designer/view.tsx +0 -225
- package/src/plugins/DisplaySourceSchema/index.tsx +0 -76
- package/src/plugins/GlobalStatePanel/index.tsx +0 -96
- package/src/plugins/GlobalStatePanel/localize/en_US/index.ts +0 -3
- package/src/plugins/GlobalStatePanel/localize/index.ts +0 -3
- package/src/plugins/GlobalStatePanel/localize/zh_CN/index.ts +0 -3
- package/src/plugins/GlobalStatePanel/style.module.scss +0 -8
- package/src/plugins/GlobalStatePanel/style.module.scss.d.ts +0 -5
- package/src/plugins/History/index.tsx +0 -110
- package/src/plugins/OutlineTree/components/TreeView/context.ts +0 -43
- package/src/plugins/OutlineTree/components/TreeView/dataStruct.ts +0 -58
- package/src/plugins/OutlineTree/components/TreeView/index.tsx +0 -376
- package/src/plugins/OutlineTree/components/TreeView/style.module.scss +0 -93
- package/src/plugins/OutlineTree/components/TreeView/style.module.scss.d.ts +0 -16
- package/src/plugins/OutlineTree/components/TreeView/treeNode.tsx +0 -271
- package/src/plugins/OutlineTree/index.tsx +0 -39
- package/src/plugins/OutlineTree/localize/en_US/index.ts +0 -3
- package/src/plugins/OutlineTree/localize/index.ts +0 -3
- package/src/plugins/OutlineTree/localize/zh_CN/index.ts +0 -3
- package/src/plugins/OutlineTree/util.tsx +0 -302
- package/src/plugins/PropertyPanel/index.tsx +0 -63
- package/src/plugins/PropertyPanel/style.module.scss +0 -12
- package/src/plugins/PropertyPanel/style.module.scss.d.ts +0 -10
- package/src/plugins/PropertyPanel/utils.ts +0 -13
- package/src/plugins/RightPanel/index.tsx +0 -30
- package/src/plugins/RightPanel/style.module.scss +0 -16
- package/src/plugins/RightPanel/style.module.scss.d.ts +0 -10
- package/src/plugins/RightPanel/view.tsx +0 -177
- package/src/plugins/VisualPanel/index.tsx +0 -185
- package/src/plugins/VisualPanel/style.module.scss +0 -17
- package/src/plugins/VisualPanelPlus/index.tsx +0 -103
- package/src/plugins/VisualPanelPlus/style.module.scss +0 -20
- package/src/plugins/VisualPanelPlus/style.module.scss.d.ts +0 -10
- package/src/plugins/index.tsx +0 -26
- package/src/stories/Button.jsx +0 -50
- package/src/stories/Button.stories.jsx +0 -40
- package/src/stories/Introduction.stories.mdx +0 -194
- package/src/stories/assets/code-brackets.svg +0 -1
- package/src/stories/assets/colors.svg +0 -1
- package/src/stories/assets/comments.svg +0 -1
- package/src/stories/assets/direction.svg +0 -1
- package/src/stories/assets/flow.svg +0 -1
- package/src/stories/assets/plugin.svg +0 -1
- package/src/stories/assets/repo.svg +0 -1
- package/src/stories/assets/stackalt.svg +0 -1
- package/src/stories/button.css +0 -30
- package/src/stories/plugins/CSSEditor.stories.tsx +0 -75
- package/src/stories/plugins/VisualPanelPlus.stories.tsx +0 -74
- package/src/style.d.ts +0 -2
- package/src/typing.d.ts +0 -9
- package/src/utils/css.ts +0 -88
- package/src/utils/defaultEngineConfig.tsx +0 -55
- package/src/utils/index.ts +0 -12
- package/src/utils/logger.ts +0 -4
- package/src/vite-env.d.ts +0 -1
- package/tsconfig.json +0 -32
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
import { CFormContext, CFormContextData, ContextState } from './context';
|
|
4
|
-
|
|
5
|
-
export type CFormProps = {
|
|
6
|
-
name: string;
|
|
7
|
-
children?: ReactNode | ReactNode[];
|
|
8
|
-
initialValue?: Record<string, any>;
|
|
9
|
-
onValueChange?: (formData: Record<string, any>) => void;
|
|
10
|
-
};
|
|
11
|
-
export class CForm extends React.Component<CFormProps, CFormContextData> {
|
|
12
|
-
updateContext: (newState: ContextState) => void;
|
|
13
|
-
|
|
14
|
-
constructor(props: CFormProps) {
|
|
15
|
-
super(props);
|
|
16
|
-
this.updateContext = (newState: ContextState) => {
|
|
17
|
-
this.setState({
|
|
18
|
-
formState: newState,
|
|
19
|
-
});
|
|
20
|
-
this.props.onValueChange?.(this.formatValue(newState));
|
|
21
|
-
};
|
|
22
|
-
this.state = {
|
|
23
|
-
formName: props.name,
|
|
24
|
-
formState: props.initialValue ?? {},
|
|
25
|
-
conditionConfig: {},
|
|
26
|
-
updateContext: this.updateContext,
|
|
27
|
-
updateConditionConfig: (
|
|
28
|
-
name: string,
|
|
29
|
-
cb: (state: Record<string, any>) => boolean
|
|
30
|
-
) => {
|
|
31
|
-
this.setState({
|
|
32
|
-
conditionConfig: {
|
|
33
|
-
...this.state.conditionConfig,
|
|
34
|
-
[name]: cb,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getFieldsValue = () => {
|
|
42
|
-
return this.formatValue(this.state.formState);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
setFields = (state: Record<string, any>) => {
|
|
46
|
-
this.setState({
|
|
47
|
-
formState: state,
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
formatValue = (data: Record<string, any>) => {
|
|
52
|
-
const res: Record<string, any> = {};
|
|
53
|
-
const conditionConfig = this.state.conditionConfig;
|
|
54
|
-
Object.keys(data).forEach((key) => {
|
|
55
|
-
const isValid = conditionConfig[key]?.(data) ?? true;
|
|
56
|
-
if (isValid) {
|
|
57
|
-
res[key] = data[key];
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
return res;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
render(): ReactNode {
|
|
64
|
-
const { state } = this;
|
|
65
|
-
const { children } = this.props;
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<CFormContext.Provider value={state}>{children}</CFormContext.Provider>
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { SetterObjType } from '@chamn/model';
|
|
3
|
-
import Setters from '../Setters/index';
|
|
4
|
-
import { CField, CFieldProps } from '../Form/Field';
|
|
5
|
-
import { Collapse, Dropdown, MenuProps } from 'antd';
|
|
6
|
-
import { SwapOutlined } from '@ant-design/icons';
|
|
7
|
-
import styles from './style.module.scss';
|
|
8
|
-
import { CCustomSchemaFormContext } from '../../context';
|
|
9
|
-
|
|
10
|
-
export type SetterSwitcherProps = {
|
|
11
|
-
setters: SetterObjType[];
|
|
12
|
-
keyPaths: string[];
|
|
13
|
-
prefix?: React.ReactNode;
|
|
14
|
-
suffix?: React.ReactNode;
|
|
15
|
-
style?: React.CSSProperties;
|
|
16
|
-
useField?: boolean;
|
|
17
|
-
} & Omit<CFieldProps, 'children'>;
|
|
18
|
-
|
|
19
|
-
export const SetterSwitcher = ({ setters, keyPaths, condition, useField = true, ...props }: SetterSwitcherProps) => {
|
|
20
|
-
const [visible, setVisible] = useState(true);
|
|
21
|
-
const { onSetterChange, defaultSetterConfig, formRef, pluginCtx } = useContext(CCustomSchemaFormContext);
|
|
22
|
-
|
|
23
|
-
const [currentSetter, setCurrentSetter] = useState<SetterObjType | null>(() => {
|
|
24
|
-
const currentSetterName = defaultSetterConfig[keyPaths.join('.')]?.setter || '';
|
|
25
|
-
return setters.find((el) => el.componentName === currentSetterName) || setters[0];
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
let CurrentSetterComp = null;
|
|
29
|
-
if (currentSetter?.componentName) {
|
|
30
|
-
CurrentSetterComp = (Setters as any)[currentSetter?.componentName];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!CurrentSetterComp) {
|
|
34
|
-
CurrentSetterComp = () =>
|
|
35
|
-
(
|
|
36
|
-
<div
|
|
37
|
-
style={{
|
|
38
|
-
backgroundColor: 'whitesmoke',
|
|
39
|
-
margin: '5px 0',
|
|
40
|
-
padding: '5px',
|
|
41
|
-
borderRadius: '2px',
|
|
42
|
-
color: 'gray',
|
|
43
|
-
}}
|
|
44
|
-
>{`${currentSetter?.componentName} is not found.`}</div>
|
|
45
|
-
) as any;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const menuItems = setters.map((setter) => {
|
|
49
|
-
const setterName = setter?.componentName || '';
|
|
50
|
-
const setterRuntime = Setters[setterName];
|
|
51
|
-
return {
|
|
52
|
-
key: setter.componentName,
|
|
53
|
-
label: setterRuntime?.setterName || setter.componentName,
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const onChooseSetter: MenuProps['onClick'] = ({ key }) => {
|
|
58
|
-
const targetSetter = setters.find((setter) => setter.componentName === key);
|
|
59
|
-
if (targetSetter) {
|
|
60
|
-
setCurrentSetter(targetSetter);
|
|
61
|
-
onSetterChange?.(keyPaths, targetSetter.componentName);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
let switcher: any = (
|
|
66
|
-
<div
|
|
67
|
-
className={styles.switchBtn}
|
|
68
|
-
onClick={(e) => {
|
|
69
|
-
e.preventDefault();
|
|
70
|
-
e.stopPropagation();
|
|
71
|
-
}}
|
|
72
|
-
>
|
|
73
|
-
<Dropdown
|
|
74
|
-
trigger={['click']}
|
|
75
|
-
menu={{
|
|
76
|
-
selectable: true,
|
|
77
|
-
items: menuItems,
|
|
78
|
-
onClick: onChooseSetter,
|
|
79
|
-
defaultSelectedKeys: [currentSetter?.componentName || ''],
|
|
80
|
-
}}
|
|
81
|
-
>
|
|
82
|
-
<SwapOutlined />
|
|
83
|
-
</Dropdown>
|
|
84
|
-
</div>
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
if (menuItems.length === 1) {
|
|
88
|
-
switcher = null;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const setterProps = useMemo(() => {
|
|
92
|
-
let newProps = {
|
|
93
|
-
...(currentSetter?.props || {}),
|
|
94
|
-
};
|
|
95
|
-
const target = setters.find((el) => el.componentName === currentSetter?.componentName);
|
|
96
|
-
if (target) {
|
|
97
|
-
newProps = {
|
|
98
|
-
...newProps,
|
|
99
|
-
...target.props,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
return newProps;
|
|
103
|
-
}, [setters]);
|
|
104
|
-
|
|
105
|
-
const setterContext = {
|
|
106
|
-
formRef,
|
|
107
|
-
pluginCtx,
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const [collapseHeaderExt, setCollapseHeaderExt] = useState<any>([]);
|
|
111
|
-
const conditionProps = {
|
|
112
|
-
condition,
|
|
113
|
-
onConditionValueChange: (val: boolean) => {
|
|
114
|
-
setVisible(val);
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
-
let bodyView: any = null;
|
|
118
|
-
if (['ArraySetter'].includes(currentSetter?.componentName || '')) {
|
|
119
|
-
bodyView = (
|
|
120
|
-
<Collapse
|
|
121
|
-
bordered={false}
|
|
122
|
-
style={{
|
|
123
|
-
marginBottom: '10px',
|
|
124
|
-
}}
|
|
125
|
-
defaultActiveKey={[props.name]}
|
|
126
|
-
>
|
|
127
|
-
<Collapse.Panel
|
|
128
|
-
header={
|
|
129
|
-
<div className={styles.collapseHeader}>
|
|
130
|
-
<span
|
|
131
|
-
style={{
|
|
132
|
-
flex: 1,
|
|
133
|
-
}}
|
|
134
|
-
>
|
|
135
|
-
{props.label}
|
|
136
|
-
</span>
|
|
137
|
-
{collapseHeaderExt}
|
|
138
|
-
{switcher}
|
|
139
|
-
</div>
|
|
140
|
-
}
|
|
141
|
-
key={props.name}
|
|
142
|
-
>
|
|
143
|
-
{useField && (
|
|
144
|
-
<CField {...props} noStyle {...conditionProps}>
|
|
145
|
-
<CurrentSetterComp
|
|
146
|
-
{...setterProps}
|
|
147
|
-
setterContext={{
|
|
148
|
-
...setterContext,
|
|
149
|
-
keyPaths: [...keyPaths],
|
|
150
|
-
label: props.label,
|
|
151
|
-
setCollapseHeaderExt: setCollapseHeaderExt,
|
|
152
|
-
}}
|
|
153
|
-
/>
|
|
154
|
-
</CField>
|
|
155
|
-
)}
|
|
156
|
-
{!useField && (
|
|
157
|
-
<CurrentSetterComp
|
|
158
|
-
{...setterProps}
|
|
159
|
-
setterContext={{
|
|
160
|
-
...setterContext,
|
|
161
|
-
keyPaths: [...keyPaths],
|
|
162
|
-
label: props.label,
|
|
163
|
-
setCollapseHeaderExt: setCollapseHeaderExt,
|
|
164
|
-
}}
|
|
165
|
-
/>
|
|
166
|
-
)}
|
|
167
|
-
</Collapse.Panel>
|
|
168
|
-
</Collapse>
|
|
169
|
-
);
|
|
170
|
-
} else if (['ShapeSetter'].includes(currentSetter?.componentName || '')) {
|
|
171
|
-
bodyView = (
|
|
172
|
-
<div className={styles.shapeFieldBox}>
|
|
173
|
-
{props.prefix ?? null}
|
|
174
|
-
{(currentSetter?.props as any)?.collapse === false && (
|
|
175
|
-
<div style={{ width: '100%' }}>
|
|
176
|
-
{useField && (
|
|
177
|
-
<CField {...props} noStyle {...conditionProps}>
|
|
178
|
-
<CurrentSetterComp
|
|
179
|
-
{...setterProps}
|
|
180
|
-
setterContext={{
|
|
181
|
-
...setterContext,
|
|
182
|
-
keyPaths: [...keyPaths],
|
|
183
|
-
}}
|
|
184
|
-
/>
|
|
185
|
-
</CField>
|
|
186
|
-
)}
|
|
187
|
-
{!useField && (
|
|
188
|
-
<CurrentSetterComp
|
|
189
|
-
{...setterProps}
|
|
190
|
-
setterContext={{
|
|
191
|
-
...setterContext,
|
|
192
|
-
keyPaths: [...keyPaths],
|
|
193
|
-
}}
|
|
194
|
-
/>
|
|
195
|
-
)}
|
|
196
|
-
</div>
|
|
197
|
-
)}
|
|
198
|
-
{(currentSetter?.props as any)?.collapse !== false && (
|
|
199
|
-
<Collapse
|
|
200
|
-
bordered={false}
|
|
201
|
-
// defaultActiveKey={[props.name]}
|
|
202
|
-
style={{ flex: 1 }}
|
|
203
|
-
>
|
|
204
|
-
<Collapse.Panel
|
|
205
|
-
header={
|
|
206
|
-
<div className={styles.collapseHeader}>
|
|
207
|
-
<span
|
|
208
|
-
style={{
|
|
209
|
-
flex: 1,
|
|
210
|
-
}}
|
|
211
|
-
>
|
|
212
|
-
{props.label}
|
|
213
|
-
</span>
|
|
214
|
-
{switcher}
|
|
215
|
-
</div>
|
|
216
|
-
}
|
|
217
|
-
key={props.name}
|
|
218
|
-
>
|
|
219
|
-
<CField {...props} noStyle {...conditionProps}>
|
|
220
|
-
<CurrentSetterComp
|
|
221
|
-
{...setterProps}
|
|
222
|
-
setterContext={{
|
|
223
|
-
...setterContext,
|
|
224
|
-
keyPaths: [...keyPaths],
|
|
225
|
-
}}
|
|
226
|
-
/>
|
|
227
|
-
</CField>
|
|
228
|
-
</Collapse.Panel>
|
|
229
|
-
</Collapse>
|
|
230
|
-
)}
|
|
231
|
-
|
|
232
|
-
{props.suffix ?? null}
|
|
233
|
-
</div>
|
|
234
|
-
);
|
|
235
|
-
} else {
|
|
236
|
-
bodyView = (
|
|
237
|
-
<div style={{ display: 'flex', alignItems: 'center', paddingBottom: '8px' }}>
|
|
238
|
-
{props.prefix ?? null}
|
|
239
|
-
{useField && (
|
|
240
|
-
<CField
|
|
241
|
-
{...props}
|
|
242
|
-
condition={condition}
|
|
243
|
-
onConditionValueChange={(val) => {
|
|
244
|
-
setVisible(val);
|
|
245
|
-
}}
|
|
246
|
-
>
|
|
247
|
-
<CurrentSetterComp
|
|
248
|
-
{...setterProps}
|
|
249
|
-
setterContext={{
|
|
250
|
-
...setterContext,
|
|
251
|
-
keyPaths: [...keyPaths],
|
|
252
|
-
}}
|
|
253
|
-
/>
|
|
254
|
-
</CField>
|
|
255
|
-
)}
|
|
256
|
-
{!useField && (
|
|
257
|
-
<CurrentSetterComp
|
|
258
|
-
{...setterProps}
|
|
259
|
-
setterContext={{
|
|
260
|
-
...setterContext,
|
|
261
|
-
keyPaths: [...keyPaths],
|
|
262
|
-
}}
|
|
263
|
-
/>
|
|
264
|
-
)}
|
|
265
|
-
|
|
266
|
-
{switcher}
|
|
267
|
-
{props.suffix ?? null}
|
|
268
|
-
</div>
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return <div style={{ display: visible ? 'block' : 'none', overflow: 'auto' }}>{bodyView}</div>;
|
|
273
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from 'react';
|
|
2
|
-
import { CForm } from '../../Form';
|
|
3
|
-
import { SetterSwitcher } from '../../SetterSwitcher';
|
|
4
|
-
import { DeleteOutlined } from '@ant-design/icons';
|
|
5
|
-
import { SetterObjType } from '@chamn/model';
|
|
6
|
-
|
|
7
|
-
export function ArrayItem(props: {
|
|
8
|
-
index: number;
|
|
9
|
-
keyPaths: string[];
|
|
10
|
-
value: Record<string, any>;
|
|
11
|
-
setters: SetterObjType[];
|
|
12
|
-
style: React.CSSProperties;
|
|
13
|
-
onValueChange: (val: Record<string, any>) => void;
|
|
14
|
-
onDelete: () => void;
|
|
15
|
-
}) {
|
|
16
|
-
const { index, keyPaths, setters } = props;
|
|
17
|
-
|
|
18
|
-
const style = {
|
|
19
|
-
...props.style,
|
|
20
|
-
};
|
|
21
|
-
const objectValue = {
|
|
22
|
-
[index]: props.value,
|
|
23
|
-
};
|
|
24
|
-
const formRef = useRef<CForm>(null);
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
formRef.current?.setFields({
|
|
27
|
-
[index]: props.value,
|
|
28
|
-
});
|
|
29
|
-
}, [props.value]);
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<div style={style}>
|
|
33
|
-
<CForm ref={formRef} name={String(index)} initialValue={objectValue || {}} onValueChange={props.onValueChange}>
|
|
34
|
-
<SetterSwitcher
|
|
35
|
-
suffix={
|
|
36
|
-
<div
|
|
37
|
-
onClick={props.onDelete}
|
|
38
|
-
style={{
|
|
39
|
-
marginLeft: '8px',
|
|
40
|
-
cursor: 'pointer',
|
|
41
|
-
fontSize: '12px',
|
|
42
|
-
}}
|
|
43
|
-
>
|
|
44
|
-
<DeleteOutlined />
|
|
45
|
-
</div>
|
|
46
|
-
}
|
|
47
|
-
name={String(index)}
|
|
48
|
-
label={`元素${index}`}
|
|
49
|
-
keyPaths={[...keyPaths, String(index)]}
|
|
50
|
-
setters={setters}
|
|
51
|
-
></SetterSwitcher>
|
|
52
|
-
</CForm>
|
|
53
|
-
</div>
|
|
54
|
-
);
|
|
55
|
-
}
|
package/src/component/CustomSchemaForm/components/Setters/ArraySetter/SortItemOrderModal.tsx
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { CSS, Transform } from '@dnd-kit/utilities';
|
|
3
|
-
import { Modal, ModalProps } from 'antd';
|
|
4
|
-
import {
|
|
5
|
-
DndContext,
|
|
6
|
-
DragEndEvent,
|
|
7
|
-
KeyboardSensor,
|
|
8
|
-
PointerSensor,
|
|
9
|
-
useDraggable,
|
|
10
|
-
useSensor,
|
|
11
|
-
useSensors,
|
|
12
|
-
} from '@dnd-kit/core';
|
|
13
|
-
import { arrayMove, SortableContext, sortableKeyboardCoordinates, useSortable } from '@dnd-kit/sortable';
|
|
14
|
-
import { restrictToVerticalAxis } from '@dnd-kit/modifiers';
|
|
15
|
-
import { getRandomStr } from '@chamn/model';
|
|
16
|
-
import styles from './style.module.scss';
|
|
17
|
-
|
|
18
|
-
export type SortItemOrderProps = {
|
|
19
|
-
list: any[];
|
|
20
|
-
keyPaths: string[];
|
|
21
|
-
label: string;
|
|
22
|
-
sortLabelKey?: string;
|
|
23
|
-
onValueChange?: (newList: any[]) => void;
|
|
24
|
-
} & ModalProps;
|
|
25
|
-
|
|
26
|
-
export const SortItemOrderModal = ({
|
|
27
|
-
list,
|
|
28
|
-
onValueChange,
|
|
29
|
-
keyPaths,
|
|
30
|
-
label,
|
|
31
|
-
sortLabelKey,
|
|
32
|
-
...modalProps
|
|
33
|
-
}: SortItemOrderProps) => {
|
|
34
|
-
const [listValue, setListValue] = useState<{ val: any; id: string }[]>([]);
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
const innerList = list.map((el, index) => ({
|
|
37
|
-
val: el,
|
|
38
|
-
oldIndex: index,
|
|
39
|
-
id: getRandomStr(),
|
|
40
|
-
}));
|
|
41
|
-
setListValue(innerList);
|
|
42
|
-
}, [modalProps.open]);
|
|
43
|
-
|
|
44
|
-
const sensors = useSensors(
|
|
45
|
-
useSensor(PointerSensor, {
|
|
46
|
-
activationConstraint: {
|
|
47
|
-
distance: 15,
|
|
48
|
-
},
|
|
49
|
-
}),
|
|
50
|
-
useSensor(KeyboardSensor, {
|
|
51
|
-
coordinateGetter: sortableKeyboardCoordinates,
|
|
52
|
-
})
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
function handleDragEnd(event: DragEndEvent) {
|
|
56
|
-
const { active, over } = event;
|
|
57
|
-
if (active.id !== over?.id) {
|
|
58
|
-
const oldIndex = listValue.findIndex((el) => el.id === active?.id);
|
|
59
|
-
const newIndex = listValue.findIndex((el) => el.id === over?.id);
|
|
60
|
-
const newInnerListVal = arrayMove(listValue, oldIndex, newIndex);
|
|
61
|
-
const newVal = newInnerListVal.map((el) => {
|
|
62
|
-
return el.val;
|
|
63
|
-
});
|
|
64
|
-
setListValue(newInnerListVal);
|
|
65
|
-
onValueChange?.(newVal);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const [modalTransform, setModalTransform] = useState<Transform>({
|
|
70
|
-
x: 0,
|
|
71
|
-
y: 0,
|
|
72
|
-
scaleX: 1,
|
|
73
|
-
scaleY: 1,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
return (
|
|
77
|
-
<Modal
|
|
78
|
-
{...modalProps}
|
|
79
|
-
title={`Sort: ${label} [${keyPaths.join('.')}]`}
|
|
80
|
-
maskStyle={{
|
|
81
|
-
backgroundColor: 'rgba(0, 0, 0, 0.1)',
|
|
82
|
-
}}
|
|
83
|
-
modalRender={(modal) => {
|
|
84
|
-
return (
|
|
85
|
-
<DndContext
|
|
86
|
-
sensors={sensors}
|
|
87
|
-
onDragEnd={({ delta }) => {
|
|
88
|
-
const res = {
|
|
89
|
-
...modalTransform,
|
|
90
|
-
...delta,
|
|
91
|
-
x: modalTransform.x + (delta?.x || 0),
|
|
92
|
-
y: modalTransform.y + (delta?.y || 0),
|
|
93
|
-
};
|
|
94
|
-
setModalTransform(res);
|
|
95
|
-
}}
|
|
96
|
-
>
|
|
97
|
-
<ModalDragView modal={modal} transform={modalTransform} />
|
|
98
|
-
</DndContext>
|
|
99
|
-
);
|
|
100
|
-
}}
|
|
101
|
-
>
|
|
102
|
-
<div className={styles.sortModalBox}>
|
|
103
|
-
<DndContext sensors={sensors} onDragEnd={handleDragEnd} modifiers={[restrictToVerticalAxis]}>
|
|
104
|
-
<SortableContext items={listValue}>
|
|
105
|
-
{listValue.map(({ id, val }, index) => {
|
|
106
|
-
return <SortableItem key={id} id={id} index={index} label={val[sortLabelKey || '']} />;
|
|
107
|
-
})}
|
|
108
|
-
</SortableContext>
|
|
109
|
-
</DndContext>
|
|
110
|
-
</div>
|
|
111
|
-
</Modal>
|
|
112
|
-
);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const ModalDragView = ({ modal, transform }: { modal: React.ReactNode; transform: Transform }) => {
|
|
116
|
-
const id = useRef(getRandomStr());
|
|
117
|
-
const {
|
|
118
|
-
setNodeRef,
|
|
119
|
-
attributes,
|
|
120
|
-
listeners,
|
|
121
|
-
transform: tempTransform,
|
|
122
|
-
} = useDraggable({
|
|
123
|
-
id: id.current,
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
const finalTransform = {
|
|
127
|
-
...transform,
|
|
128
|
-
...tempTransform,
|
|
129
|
-
x: transform.x + (tempTransform?.x || 0),
|
|
130
|
-
y: transform.y + (tempTransform?.y || 0),
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
return (
|
|
134
|
-
<div
|
|
135
|
-
ref={setNodeRef}
|
|
136
|
-
style={{
|
|
137
|
-
pointerEvents: 'auto',
|
|
138
|
-
transform: CSS.Transform.toString(finalTransform),
|
|
139
|
-
}}
|
|
140
|
-
{...attributes}
|
|
141
|
-
{...listeners}
|
|
142
|
-
>
|
|
143
|
-
{modal}
|
|
144
|
-
</div>
|
|
145
|
-
);
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const SortableItem = (props: { id: string; index: string | number; label?: string }) => {
|
|
149
|
-
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id: props.id });
|
|
150
|
-
const style = {
|
|
151
|
-
transform: CSS.Transform.toString(transform),
|
|
152
|
-
transition,
|
|
153
|
-
};
|
|
154
|
-
const labelText = props.label || `Ele ${props.index}`;
|
|
155
|
-
return (
|
|
156
|
-
<div className={styles.dragItem} ref={setNodeRef} style={style} {...attributes} {...listeners}>
|
|
157
|
-
{labelText}
|
|
158
|
-
</div>
|
|
159
|
-
);
|
|
160
|
-
};
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { Button, ConfigProvider } from 'antd';
|
|
3
|
-
import { CSetterProps } from '../type';
|
|
4
|
-
import { getSetterList } from '../../../utils';
|
|
5
|
-
import { SetterType } from '@chamn/model';
|
|
6
|
-
|
|
7
|
-
import { ArrayItem } from './ArrayItem';
|
|
8
|
-
import { SortItemOrderModal } from './SortItemOrderModal';
|
|
9
|
-
import styles from './style.module.scss';
|
|
10
|
-
|
|
11
|
-
export type CArraySetterProps = {
|
|
12
|
-
item: {
|
|
13
|
-
setters: SetterType[];
|
|
14
|
-
initialValue?: any;
|
|
15
|
-
};
|
|
16
|
-
sortLabelKey?: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
function formatValue(value: unknown) {
|
|
20
|
-
if (Array.isArray(value)) {
|
|
21
|
-
return value;
|
|
22
|
-
} else {
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const ArraySetter = ({
|
|
28
|
-
onValueChange,
|
|
29
|
-
setterContext,
|
|
30
|
-
item: { setters, initialValue },
|
|
31
|
-
sortLabelKey,
|
|
32
|
-
...props
|
|
33
|
-
}: CSetterProps<CArraySetterProps>) => {
|
|
34
|
-
const { keyPaths, label } = setterContext;
|
|
35
|
-
const listValue: any[] = useMemo(() => {
|
|
36
|
-
return formatValue(props.value);
|
|
37
|
-
}, [props.value]);
|
|
38
|
-
|
|
39
|
-
const [sortVisible, setSortVisible] = useState(false);
|
|
40
|
-
const innerSetters = getSetterList(
|
|
41
|
-
setters || [
|
|
42
|
-
{
|
|
43
|
-
component: 'StringSetter',
|
|
44
|
-
},
|
|
45
|
-
]
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
if (setterContext.setCollapseHeaderExt) {
|
|
50
|
-
setterContext.setCollapseHeaderExt?.(
|
|
51
|
-
<Button
|
|
52
|
-
type="text"
|
|
53
|
-
size="small"
|
|
54
|
-
style={{
|
|
55
|
-
color: 'gray',
|
|
56
|
-
}}
|
|
57
|
-
onClick={(e) => {
|
|
58
|
-
e.preventDefault();
|
|
59
|
-
e.stopPropagation();
|
|
60
|
-
setSortVisible(true);
|
|
61
|
-
}}
|
|
62
|
-
>
|
|
63
|
-
sort
|
|
64
|
-
</Button>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
}, []);
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
<ConfigProvider
|
|
71
|
-
theme={{
|
|
72
|
-
token: {
|
|
73
|
-
borderRadius: 4,
|
|
74
|
-
},
|
|
75
|
-
}}
|
|
76
|
-
>
|
|
77
|
-
{listValue.map((val, index) => {
|
|
78
|
-
return (
|
|
79
|
-
<ArrayItem
|
|
80
|
-
key={index}
|
|
81
|
-
style={{ paddingBottom: '10px' }}
|
|
82
|
-
index={index}
|
|
83
|
-
keyPaths={keyPaths}
|
|
84
|
-
value={val}
|
|
85
|
-
onValueChange={(val) => {
|
|
86
|
-
listValue[index] = val[index];
|
|
87
|
-
onValueChange?.([...listValue]);
|
|
88
|
-
}}
|
|
89
|
-
setters={innerSetters}
|
|
90
|
-
onDelete={() => {
|
|
91
|
-
const newVal = [...listValue];
|
|
92
|
-
newVal.splice(index);
|
|
93
|
-
onValueChange?.(newVal);
|
|
94
|
-
}}
|
|
95
|
-
/>
|
|
96
|
-
);
|
|
97
|
-
})}
|
|
98
|
-
|
|
99
|
-
<Button
|
|
100
|
-
className={styles.addOneBtn}
|
|
101
|
-
size="small"
|
|
102
|
-
onClick={() => {
|
|
103
|
-
const newVal = [...listValue];
|
|
104
|
-
onValueChange?.([...newVal, initialValue ?? '']);
|
|
105
|
-
}}
|
|
106
|
-
>
|
|
107
|
-
Add One
|
|
108
|
-
</Button>
|
|
109
|
-
<SortItemOrderModal
|
|
110
|
-
label={label}
|
|
111
|
-
sortLabelKey={sortLabelKey}
|
|
112
|
-
onValueChange={(newVal) => {
|
|
113
|
-
onValueChange?.([...newVal]);
|
|
114
|
-
}}
|
|
115
|
-
open={sortVisible}
|
|
116
|
-
list={listValue}
|
|
117
|
-
keyPaths={keyPaths}
|
|
118
|
-
onCancel={() => {
|
|
119
|
-
setSortVisible(false);
|
|
120
|
-
}}
|
|
121
|
-
onOk={() => {
|
|
122
|
-
setSortVisible(false);
|
|
123
|
-
}}
|
|
124
|
-
/>
|
|
125
|
-
</ConfigProvider>
|
|
126
|
-
);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
ArraySetter.setterName = '数组设置器';
|