@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.
Files changed (204) hide show
  1. package/dist/component/CustomSchemaForm/components/Form/context.d.ts +2 -0
  2. package/dist/component/CustomSchemaForm/components/Form/index.d.ts +1 -0
  3. package/dist/component/CustomSchemaForm/components/SetterSwitcher/index.d.ts +2 -0
  4. package/dist/component/CustomSchemaForm/index.d.ts +3 -0
  5. package/dist/component/Workbench/index.d.ts +4 -0
  6. package/dist/core/pluginManager.d.ts +5 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +197 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/{index.es.js → index.mjs} +2995 -2944
  11. package/dist/index.mjs.map +1 -0
  12. package/dist/plugins/RightPanel/view.d.ts +4 -0
  13. package/package.json +12 -9
  14. package/.eslintignore +0 -1
  15. package/.eslintrc.js +0 -36
  16. package/.prettierrc.json +0 -7
  17. package/.storybook/main.js +0 -24
  18. package/.storybook/preview.js +0 -9
  19. package/CHANGELOG.md +0 -54
  20. package/__tests__/demo.test.ts +0 -3
  21. package/build.config.js +0 -88
  22. package/dist/index.cjs.js +0 -197
  23. package/dist/index.cjs.js.map +0 -1
  24. package/dist/index.es.js.map +0 -1
  25. package/index.html +0 -16
  26. package/jest.config.js +0 -196
  27. package/public/Engine.module.scss.d.ts +0 -5
  28. package/public/_dev_/render.d.ts +0 -2
  29. package/public/component/CSSEditor/style.module.scss.d.ts +0 -6
  30. package/public/component/CSSPropertiesEditor/style.module.scss.d.ts +0 -15
  31. package/public/component/CSSPropertiesVariableBindEditor/style.module.scss.d.ts +0 -15
  32. package/public/component/CustomSchemaForm/components/Form/Field/style.module.scss.d.ts +0 -8
  33. package/public/component/CustomSchemaForm/components/SetterSwitcher/style.module.scss.d.ts +0 -7
  34. package/public/component/CustomSchemaForm/components/Setters/ArraySetter/style.module.scss.d.ts +0 -7
  35. package/public/component/CustomSchemaForm/components/Setters/CSSValueSetter/style.module.scss.d.ts +0 -6
  36. package/public/component/CustomSchemaForm/style.module.scss.d.ts +0 -11
  37. package/public/component/Workbench/style.module.scss.d.ts +0 -25
  38. package/public/plugins/AdvancePanel/style.module.scss.d.ts +0 -7
  39. package/public/plugins/ComponentLibrary/components/DragItem/style.module.scss.d.ts +0 -9
  40. package/public/plugins/ComponentLibrary/components/ListView/style.module.scss.d.ts +0 -12
  41. package/public/plugins/ComponentLibrary/style.module.scss.d.ts +0 -11
  42. package/public/plugins/Designer/components/DefaultSelectToolBar/style.module.scss.d.ts +0 -11
  43. package/public/plugins/Designer/style.module.scss.d.ts +0 -5
  44. package/public/plugins/GlobalStatePanel/style.module.scss.d.ts +0 -5
  45. package/public/plugins/OutlineTree/components/TreeView/style.module.scss.d.ts +0 -16
  46. package/public/plugins/PropertyPanel/style.module.scss.d.ts +0 -10
  47. package/public/plugins/RightPanel/style.module.scss.d.ts +0 -10
  48. package/public/plugins/VisualPanelPlus/style.module.scss.d.ts +0 -10
  49. package/public/render.umd.js +0 -42
  50. package/public/render.umd.js.map +0 -1
  51. package/src/Engine.module.scss +0 -10
  52. package/src/Engine.module.scss.d.ts +0 -5
  53. package/src/_dev_/index.css +0 -22
  54. package/src/_dev_/index.tsx +0 -5
  55. package/src/_dev_/page/Editor/index.tsx +0 -198
  56. package/src/_dev_/page/Editor/indexCustom.tsx +0 -274
  57. package/src/_dev_/page/Preview/index.tsx +0 -56
  58. package/src/_dev_/render.ts +0 -3
  59. package/src/_dev_/router.tsx +0 -14
  60. package/src/assets/react.svg +0 -4
  61. package/src/assets/styles/mixin.scss +0 -15
  62. package/src/component/CSSEditor/index.tsx +0 -247
  63. package/src/component/CSSEditor/style.module.scss +0 -22
  64. package/src/component/CSSEditor/style.module.scss.d.ts +0 -6
  65. package/src/component/CSSPropertiesEditor/cssProperties.ts +0 -1062
  66. package/src/component/CSSPropertiesEditor/index.tsx +0 -389
  67. package/src/component/CSSPropertiesEditor/style.module.scss +0 -46
  68. package/src/component/CSSPropertiesEditor/style.module.scss.d.ts +0 -15
  69. package/src/component/CSSPropertiesEditor/util.ts +0 -19
  70. package/src/component/CSSPropertiesVariableBindEditor/cssProperties.ts +0 -782
  71. package/src/component/CSSPropertiesVariableBindEditor/index.tsx +0 -366
  72. package/src/component/CSSPropertiesVariableBindEditor/style.module.scss +0 -48
  73. package/src/component/CSSPropertiesVariableBindEditor/style.module.scss.d.ts +0 -15
  74. package/src/component/CSSPropertiesVariableBindEditor/util.ts +0 -19
  75. package/src/component/ClassNameEditor/index.tsx +0 -91
  76. package/src/component/ClassNameEditor/style.module.scss +0 -0
  77. package/src/component/CustomSchemaForm/components/Form/Field/index.tsx +0 -81
  78. package/src/component/CustomSchemaForm/components/Form/Field/style.module.scss +0 -32
  79. package/src/component/CustomSchemaForm/components/Form/Field/style.module.scss.d.ts +0 -8
  80. package/src/component/CustomSchemaForm/components/Form/context.ts +0 -23
  81. package/src/component/CustomSchemaForm/components/Form/index.tsx +0 -71
  82. package/src/component/CustomSchemaForm/components/SetterSwitcher/index.tsx +0 -273
  83. package/src/component/CustomSchemaForm/components/SetterSwitcher/style.module.scss +0 -16
  84. package/src/component/CustomSchemaForm/components/SetterSwitcher/style.module.scss.d.ts +0 -7
  85. package/src/component/CustomSchemaForm/components/Setters/ArraySetter/ArrayItem.tsx +0 -55
  86. package/src/component/CustomSchemaForm/components/Setters/ArraySetter/SortItemOrderModal.tsx +0 -160
  87. package/src/component/CustomSchemaForm/components/Setters/ArraySetter/index.tsx +0 -129
  88. package/src/component/CustomSchemaForm/components/Setters/ArraySetter/style.module.scss +0 -22
  89. package/src/component/CustomSchemaForm/components/Setters/ArraySetter/style.module.scss.d.ts +0 -7
  90. package/src/component/CustomSchemaForm/components/Setters/BooleanSetter/index.tsx +0 -32
  91. package/src/component/CustomSchemaForm/components/Setters/CSSValueSetter/index.tsx +0 -78
  92. package/src/component/CustomSchemaForm/components/Setters/CSSValueSetter/style.module.scss +0 -7
  93. package/src/component/CustomSchemaForm/components/Setters/CSSValueSetter/style.module.scss.d.ts +0 -6
  94. package/src/component/CustomSchemaForm/components/Setters/ExpressionSetter/index.tsx +0 -47
  95. package/src/component/CustomSchemaForm/components/Setters/FunctionSetter/defaultDts.ts +0 -28
  96. package/src/component/CustomSchemaForm/components/Setters/FunctionSetter/index.tsx +0 -93
  97. package/src/component/CustomSchemaForm/components/Setters/JSONSetter/index.tsx +0 -80
  98. package/src/component/CustomSchemaForm/components/Setters/NumberSetter/index.tsx +0 -34
  99. package/src/component/CustomSchemaForm/components/Setters/SelectSetter/index.tsx +0 -35
  100. package/src/component/CustomSchemaForm/components/Setters/ShapeSetter/index.tsx +0 -65
  101. package/src/component/CustomSchemaForm/components/Setters/StringSetter/index.tsx +0 -30
  102. package/src/component/CustomSchemaForm/components/Setters/TextAreaSetter/index.tsx +0 -31
  103. package/src/component/CustomSchemaForm/components/Setters/index.ts +0 -26
  104. package/src/component/CustomSchemaForm/components/Setters/type.ts +0 -18
  105. package/src/component/CustomSchemaForm/context.ts +0 -20
  106. package/src/component/CustomSchemaForm/index.tsx +0 -93
  107. package/src/component/CustomSchemaForm/style.module.scss +0 -15
  108. package/src/component/CustomSchemaForm/style.module.scss.d.ts +0 -11
  109. package/src/component/CustomSchemaForm/utils.ts +0 -13
  110. package/src/component/MonacoEditor/index.tsx +0 -81
  111. package/src/component/Workbench/index.tsx +0 -329
  112. package/src/component/Workbench/style.module.scss +0 -159
  113. package/src/component/Workbench/style.module.scss.d.ts +0 -25
  114. package/src/core/pluginManager.ts +0 -151
  115. package/src/i18n/en_US/index.ts +0 -5
  116. package/src/i18n/index.ts +0 -39
  117. package/src/i18n/zh_CN/index.ts +0 -5
  118. package/src/index.tsx +0 -150
  119. package/src/material/innerMaterial.ts +0 -343
  120. package/src/plugins/AdvancePanel/index.tsx +0 -191
  121. package/src/plugins/AdvancePanel/style.module.scss +0 -8
  122. package/src/plugins/AdvancePanel/style.module.scss.d.ts +0 -7
  123. package/src/plugins/ComponentLibrary/components/DragItem/index.tsx +0 -65
  124. package/src/plugins/ComponentLibrary/components/DragItem/style.module.scss +0 -58
  125. package/src/plugins/ComponentLibrary/components/DragItem/style.module.scss.d.ts +0 -9
  126. package/src/plugins/ComponentLibrary/components/ListView/index.tsx +0 -50
  127. package/src/plugins/ComponentLibrary/components/ListView/style.module.scss +0 -27
  128. package/src/plugins/ComponentLibrary/components/ListView/style.module.scss.d.ts +0 -12
  129. package/src/plugins/ComponentLibrary/index.tsx +0 -184
  130. package/src/plugins/ComponentLibrary/localize/en_US/index.ts +0 -3
  131. package/src/plugins/ComponentLibrary/localize/index.ts +0 -3
  132. package/src/plugins/ComponentLibrary/localize/zh_CN/index.ts +0 -3
  133. package/src/plugins/ComponentLibrary/style.module.scss +0 -31
  134. package/src/plugins/ComponentLibrary/style.module.scss.d.ts +0 -11
  135. package/src/plugins/ComponentLibrary/util.ts +0 -14
  136. package/src/plugins/ComponentStatePanel/index.tsx +0 -59
  137. package/src/plugins/Designer/components/DefaultSelectToolBar/index.tsx +0 -94
  138. package/src/plugins/Designer/components/DefaultSelectToolBar/style.module.scss +0 -59
  139. package/src/plugins/Designer/components/DefaultSelectToolBar/style.module.scss.d.ts +0 -11
  140. package/src/plugins/Designer/components/GhostView/index.tsx +0 -18
  141. package/src/plugins/Designer/config.ts +0 -1
  142. package/src/plugins/Designer/index.tsx +0 -61
  143. package/src/plugins/Designer/localize/en_US/index.ts +0 -3
  144. package/src/plugins/Designer/localize/index.ts +0 -3
  145. package/src/plugins/Designer/localize/zh_CN/index.ts +0 -3
  146. package/src/plugins/Designer/style.module.scss +0 -10
  147. package/src/plugins/Designer/style.module.scss.d.ts +0 -5
  148. package/src/plugins/Designer/util.ts +0 -18
  149. package/src/plugins/Designer/view.tsx +0 -225
  150. package/src/plugins/DisplaySourceSchema/index.tsx +0 -76
  151. package/src/plugins/GlobalStatePanel/index.tsx +0 -96
  152. package/src/plugins/GlobalStatePanel/localize/en_US/index.ts +0 -3
  153. package/src/plugins/GlobalStatePanel/localize/index.ts +0 -3
  154. package/src/plugins/GlobalStatePanel/localize/zh_CN/index.ts +0 -3
  155. package/src/plugins/GlobalStatePanel/style.module.scss +0 -8
  156. package/src/plugins/GlobalStatePanel/style.module.scss.d.ts +0 -5
  157. package/src/plugins/History/index.tsx +0 -110
  158. package/src/plugins/OutlineTree/components/TreeView/context.ts +0 -43
  159. package/src/plugins/OutlineTree/components/TreeView/dataStruct.ts +0 -58
  160. package/src/plugins/OutlineTree/components/TreeView/index.tsx +0 -376
  161. package/src/plugins/OutlineTree/components/TreeView/style.module.scss +0 -93
  162. package/src/plugins/OutlineTree/components/TreeView/style.module.scss.d.ts +0 -16
  163. package/src/plugins/OutlineTree/components/TreeView/treeNode.tsx +0 -271
  164. package/src/plugins/OutlineTree/index.tsx +0 -39
  165. package/src/plugins/OutlineTree/localize/en_US/index.ts +0 -3
  166. package/src/plugins/OutlineTree/localize/index.ts +0 -3
  167. package/src/plugins/OutlineTree/localize/zh_CN/index.ts +0 -3
  168. package/src/plugins/OutlineTree/util.tsx +0 -302
  169. package/src/plugins/PropertyPanel/index.tsx +0 -63
  170. package/src/plugins/PropertyPanel/style.module.scss +0 -12
  171. package/src/plugins/PropertyPanel/style.module.scss.d.ts +0 -10
  172. package/src/plugins/PropertyPanel/utils.ts +0 -13
  173. package/src/plugins/RightPanel/index.tsx +0 -30
  174. package/src/plugins/RightPanel/style.module.scss +0 -16
  175. package/src/plugins/RightPanel/style.module.scss.d.ts +0 -10
  176. package/src/plugins/RightPanel/view.tsx +0 -177
  177. package/src/plugins/VisualPanel/index.tsx +0 -185
  178. package/src/plugins/VisualPanel/style.module.scss +0 -17
  179. package/src/plugins/VisualPanelPlus/index.tsx +0 -103
  180. package/src/plugins/VisualPanelPlus/style.module.scss +0 -20
  181. package/src/plugins/VisualPanelPlus/style.module.scss.d.ts +0 -10
  182. package/src/plugins/index.tsx +0 -26
  183. package/src/stories/Button.jsx +0 -50
  184. package/src/stories/Button.stories.jsx +0 -40
  185. package/src/stories/Introduction.stories.mdx +0 -194
  186. package/src/stories/assets/code-brackets.svg +0 -1
  187. package/src/stories/assets/colors.svg +0 -1
  188. package/src/stories/assets/comments.svg +0 -1
  189. package/src/stories/assets/direction.svg +0 -1
  190. package/src/stories/assets/flow.svg +0 -1
  191. package/src/stories/assets/plugin.svg +0 -1
  192. package/src/stories/assets/repo.svg +0 -1
  193. package/src/stories/assets/stackalt.svg +0 -1
  194. package/src/stories/button.css +0 -30
  195. package/src/stories/plugins/CSSEditor.stories.tsx +0 -75
  196. package/src/stories/plugins/VisualPanelPlus.stories.tsx +0 -74
  197. package/src/style.d.ts +0 -2
  198. package/src/typing.d.ts +0 -9
  199. package/src/utils/css.ts +0 -88
  200. package/src/utils/defaultEngineConfig.tsx +0 -55
  201. package/src/utils/index.ts +0 -12
  202. package/src/utils/logger.ts +0 -4
  203. package/src/vite-env.d.ts +0 -1
  204. package/tsconfig.json +0 -32
@@ -1,366 +0,0 @@
1
- import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
2
- import { CSSPropertyList } from './cssProperties';
3
-
4
- import styles from './style.module.scss';
5
-
6
- import { AutoComplete, Button, ConfigProvider, Input, message } from 'antd';
7
- import { MinusOutlined, PlusOutlined } from '@ant-design/icons';
8
- import { getTextWidth } from './util';
9
- import { BaseSelectRef } from 'rc-select';
10
- import { useDebounceFn } from 'ahooks';
11
- import clsx from 'clsx';
12
- import { CNodePropsTypeEnum, JSExpressionPropType } from '@chamn/model';
13
- import { InputStatus } from 'antd/es/_util/statusUtils';
14
-
15
- const defaultPropertyOptions = CSSPropertyList.map((el) => {
16
- return {
17
- value: el,
18
- };
19
- });
20
-
21
- export type SinglePropertyEditorProps = {
22
- value?: {
23
- key: string;
24
- value: JSExpressionPropType;
25
- };
26
- onValueChange: (value: { key: string; value: JSExpressionPropType }) => void;
27
- onDelete?: () => void;
28
- onCreate?: (value: { key: string; value: JSExpressionPropType }) => {
29
- errorKey?: string[];
30
- } | void;
31
- mod?: 'create' | 'edit';
32
- };
33
-
34
- type SinglePropertyEditorRef = {
35
- reset: () => void;
36
- };
37
-
38
- const SinglePropertyEditor = forwardRef<SinglePropertyEditorRef, SinglePropertyEditorProps>(
39
- function SinglePropertyEditorCore(props, ref) {
40
- const [keyFormatStatus, setKeyFormatStatus] = useState<InputStatus>('');
41
- const [valueFormatStatus, setValueFormatStatus] = useState<InputStatus>('');
42
-
43
- const { mod = 'create' } = props;
44
- const [innerValue, setInnerVal] = useState<{
45
- key: string;
46
- value: JSExpressionPropType;
47
- }>({
48
- key: props.value?.key || '',
49
- value: props.value?.value || {
50
- type: CNodePropsTypeEnum.EXPRESSION,
51
- value: '',
52
- },
53
- });
54
-
55
- useEffect(() => {
56
- if (props.value) {
57
- setInnerVal(props.value);
58
- }
59
- }, [props.value]);
60
-
61
- const [propertyOptions, setPropertyOptions] = useState(defaultPropertyOptions);
62
-
63
- const onSearch = (searchText: string) => {
64
- const newOptions = defaultPropertyOptions.filter((el) => el.value.includes(searchText));
65
- if (!searchText) {
66
- setPropertyOptions(defaultPropertyOptions);
67
- } else {
68
- setPropertyOptions(newOptions);
69
- }
70
- };
71
-
72
- const updateOuterValue = () => {
73
- props.onValueChange({
74
- ...innerValue,
75
- });
76
- };
77
-
78
- const { run: updateOuterValueDebounce } = useDebounceFn(updateOuterValue, {
79
- wait: 20,
80
- });
81
-
82
- const [keyInputWidth, setKeyInputWidth] = useState(0);
83
-
84
- useEffect(() => {
85
- getTextWidth(innerValue.key, 13.33).then((w) => {
86
- let tempW = parseFloat(w);
87
- if (innerValue.key === '') {
88
- tempW = 200;
89
- }
90
- setKeyInputWidth(tempW + 6);
91
- });
92
- }, [innerValue.key]);
93
-
94
- const propertyKeyRef = useRef<BaseSelectRef | null>(null);
95
- const [focusState, setFocusState] = useState({
96
- key: false,
97
- value: false,
98
- });
99
- useImperativeHandle(
100
- ref,
101
- () => {
102
- return {
103
- reset: () => {
104
- setInnerVal({
105
- key: '',
106
- value: {
107
- type: CNodePropsTypeEnum.EXPRESSION,
108
- value: '',
109
- },
110
- });
111
- propertyKeyRef.current?.focus();
112
- },
113
- };
114
- },
115
- []
116
- );
117
-
118
- const innerOnCreate = () => {
119
- if (innerValue.key === '') {
120
- setKeyFormatStatus('error');
121
- return;
122
- }
123
- if (innerValue.value.value === '') {
124
- setValueFormatStatus('error');
125
- return;
126
- }
127
- setKeyFormatStatus('');
128
- setValueFormatStatus('');
129
-
130
- const res = props.onCreate?.(innerValue);
131
- if (res?.errorKey?.includes('key')) {
132
- setKeyFormatStatus('error');
133
- }
134
- if (res?.errorKey?.includes('value')) {
135
- setValueFormatStatus('error');
136
- }
137
- };
138
-
139
- return (
140
- <>
141
- <div className={styles.cssFieldBox}>
142
- <div className={styles.leftBox}>
143
- <div className={styles.row}>
144
- <span className={styles.fieldLabel}>Name</span>
145
- <AutoComplete
146
- status={keyFormatStatus}
147
- disabled={mod === 'edit'}
148
- ref={propertyKeyRef}
149
- onSearch={onSearch}
150
- dropdownMatchSelectWidth={200}
151
- value={innerValue.key}
152
- onChange={(val) => {
153
- setKeyFormatStatus('');
154
- setInnerVal({
155
- ...innerValue,
156
- key: val,
157
- });
158
- updateOuterValueDebounce();
159
- }}
160
- style={{
161
- width: `${keyInputWidth}px`,
162
- }}
163
- className={clsx([styles.inputBox])}
164
- onFocus={() => {
165
- setFocusState({
166
- key: true,
167
- value: false,
168
- });
169
- }}
170
- onBlur={() => {
171
- setFocusState({
172
- key: false,
173
- value: false,
174
- });
175
- }}
176
- placeholder="property"
177
- options={propertyOptions}
178
- />
179
- </div>
180
- <div className={styles.row}>
181
- <span className={styles.fieldLabel}>Value</span>
182
- <ConfigProvider
183
- theme={{
184
- token: {
185
- borderRadius: 4,
186
- },
187
- }}
188
- >
189
- <Input
190
- status={valueFormatStatus}
191
- value={innerValue.value.value}
192
- onChange={(e) => {
193
- setValueFormatStatus('');
194
- const newVal: {
195
- type: CNodePropsTypeEnum.EXPRESSION;
196
- value: string;
197
- } = {
198
- type: CNodePropsTypeEnum.EXPRESSION,
199
- value: e.target.value,
200
- };
201
- setInnerVal({
202
- ...innerValue,
203
- value: newVal,
204
- });
205
- }}
206
- onKeyDown={(e) => {
207
- if (e.code === 'Enter' && mod === 'create') {
208
- innerOnCreate();
209
- propertyKeyRef.current?.focus();
210
- }
211
- }}
212
- />
213
- </ConfigProvider>
214
- </div>
215
- </div>
216
- <div className={styles.rightBox}>
217
- {props.onDelete && mod === 'edit' && (
218
- <Button
219
- size="small"
220
- type="text"
221
- onClick={() => {
222
- props.onDelete?.();
223
- }}
224
- >
225
- <MinusOutlined
226
- style={{
227
- display: 'inline-flex',
228
- fontSize: '12px',
229
- }}
230
- />
231
- </Button>
232
- )}
233
- </div>
234
- {props.onCreate && mod === 'create' && (
235
- <div>
236
- <Button
237
- size="small"
238
- type="text"
239
- icon={
240
- <PlusOutlined
241
- style={{
242
- fontSize: '12px',
243
- display: 'inline-flex',
244
- }}
245
- />
246
- }
247
- onClick={innerOnCreate}
248
- ></Button>
249
- </div>
250
- )}
251
- </div>
252
- </>
253
- );
254
- }
255
- );
256
-
257
- export type CSSPropertiesVariableBindEditorProps = {
258
- initialValue?: { key: string; value: string }[];
259
- onValueChange?: (val: { key: string; value: string }[]) => void;
260
- };
261
- export type CSSPropertiesVariableBindEditorRef = {
262
- setValue: (val: { key: string; value: string }[]) => void;
263
- };
264
-
265
- export const CSSPropertiesVariableBindEditor = forwardRef<
266
- CSSPropertiesVariableBindEditorRef,
267
- CSSPropertiesVariableBindEditorProps
268
- >(function CSSPropertiesVariableBindEditorCore(props, ref) {
269
- const [propertyList, setPropertyList] = useState<{ key: string; value: any }[]>([]);
270
- useImperativeHandle(
271
- ref,
272
- () => {
273
- return {
274
- setValue: (val) => {
275
- setPropertyList(val);
276
- },
277
- };
278
- },
279
- []
280
- );
281
-
282
- useEffect(() => {
283
- if (props.initialValue) {
284
- setPropertyList(props.initialValue);
285
- }
286
- }, []);
287
-
288
- const [newProperty, setNewProperty] = useState({
289
- key: '',
290
- value: {
291
- type: CNodePropsTypeEnum.EXPRESSION,
292
- value: '',
293
- } as JSExpressionPropType,
294
- });
295
-
296
- const innerOnValueChange = (val: typeof propertyList) => {
297
- props.onValueChange?.(val);
298
- };
299
-
300
- const createPropertyRef = useRef<SinglePropertyEditorRef>(null);
301
- return (
302
- <ConfigProvider
303
- theme={{
304
- token: {
305
- borderRadius: 4,
306
- },
307
- }}
308
- >
309
- <div className={styles.cssBox}>
310
- {propertyList.map((el, index) => {
311
- return (
312
- <div key={index}>
313
- <SinglePropertyEditor
314
- value={el}
315
- mod={'edit'}
316
- onValueChange={(newVal) => {
317
- if (newVal.key === '') {
318
- propertyList.splice(index, 1);
319
- setPropertyList([...propertyList]);
320
- return;
321
- }
322
- propertyList[index] = newVal;
323
- setPropertyList([...propertyList]);
324
- innerOnValueChange(propertyList);
325
- }}
326
- onDelete={() => {
327
- propertyList.splice(index, 1);
328
- setPropertyList([...propertyList]);
329
- innerOnValueChange(propertyList);
330
- }}
331
- />
332
- </div>
333
- );
334
- })}
335
-
336
- <SinglePropertyEditor
337
- value={newProperty}
338
- ref={createPropertyRef}
339
- mod="create"
340
- onValueChange={(newVal) => {
341
- setNewProperty(newVal);
342
- }}
343
- onCreate={(val) => {
344
- const hasExits = propertyList.find((el) => el.key === val.key);
345
- if (hasExits) {
346
- message.error('The attribute name already exists, please replace');
347
- return {
348
- errorKey: ['key'],
349
- };
350
- }
351
- propertyList.push(val);
352
- setPropertyList([...propertyList]);
353
- innerOnValueChange(propertyList);
354
- setNewProperty({
355
- key: '',
356
- value: {
357
- type: CNodePropsTypeEnum.EXPRESSION,
358
- value: '',
359
- },
360
- });
361
- }}
362
- />
363
- </div>
364
- </ConfigProvider>
365
- );
366
- });
@@ -1,48 +0,0 @@
1
- .cssFieldBox {
2
- display: flex;
3
- color: $textColor !important;
4
- :global {
5
- .ant-select-selector input {
6
- color: $textColor !important;
7
- }
8
- }
9
- .row {
10
- display: flex;
11
- padding-bottom: 6px;
12
- align-items: center;
13
- }
14
-
15
- .fieldLabel {
16
- display: inline-block;
17
- width: 70px;
18
- flex-shrink: 0;
19
- font-size: 12px;
20
- }
21
-
22
- .leftBox {
23
- flex: 1;
24
- }
25
-
26
- .rightBox {
27
- padding-left: 10px;
28
- }
29
- .inputBox {
30
- flex: 1;
31
- }
32
- }
33
-
34
- .cssBox {
35
- overflow-x: hidden;
36
- :global {
37
- .ant-collapse-borderless > .ant-collapse-item {
38
- border-bottom: 1px solid #e4e4e4;
39
- }
40
-
41
- .ant-collapse-borderless > .ant-collapse-item:last-child {
42
- border-bottom: none;
43
- }
44
- .ant-collapse-content-box {
45
- padding-bottom: 30px !important;
46
- }
47
- }
48
- }
@@ -1,15 +0,0 @@
1
- import globalClassNames from '../../style.d';
2
- declare const classNames: typeof globalClassNames & {
3
- readonly cssFieldBox: 'cssFieldBox';
4
- readonly 'ant-select-selector': 'ant-select-selector';
5
- readonly row: 'row';
6
- readonly fieldLabel: 'fieldLabel';
7
- readonly leftBox: 'leftBox';
8
- readonly rightBox: 'rightBox';
9
- readonly inputBox: 'inputBox';
10
- readonly cssBox: 'cssBox';
11
- readonly 'ant-collapse-borderless': 'ant-collapse-borderless';
12
- readonly 'ant-collapse-item': 'ant-collapse-item';
13
- readonly 'ant-collapse-content-box': 'ant-collapse-content-box';
14
- };
15
- export = classNames;
@@ -1,19 +0,0 @@
1
- export const getTextWidth = async (text: string, fontSize = 14) => {
2
- return new Promise<string>((resolve, reject) => {
3
- const span = document.createElement('span');
4
- span.innerHTML = text;
5
- span.style.fontSize = `${fontSize}px`;
6
- span.style.position = 'fixed';
7
- span.style.left = '-1000px';
8
- span.style.bottom = '-1000px';
9
- span.style.display = 'inline-block';
10
- document.body.appendChild(span);
11
- setTimeout(() => {
12
- const style = window.getComputedStyle(span);
13
- resolve(style.width);
14
- setTimeout(() => {
15
- document.body.removeChild(span);
16
- });
17
- });
18
- });
19
- };
@@ -1,91 +0,0 @@
1
- import { forwardRef } from 'react';
2
- import { ConfigProvider } from 'antd';
3
- import { CustomSchemaForm } from '../CustomSchemaForm';
4
- import { ClassNameType, CMaterialPropsType, CNodePropsTypeEnum } from '@chamn/model';
5
-
6
- import styles from './style.module.scss';
7
-
8
- export type ClassNameEditorProps = {
9
- initialValue?: { key: string; value: string }[];
10
- onValueChange?: (val: ClassNameType[]) => void;
11
- };
12
- export type ClassNameEditorRef = {
13
- setValue: (val: { key: string; value: string }[]) => void;
14
- };
15
-
16
- const properties: CMaterialPropsType = [
17
- {
18
- title: 'Class Names',
19
- name: 'className',
20
- valueType: 'array',
21
- setters: [
22
- {
23
- componentName: 'ArraySetter',
24
- props: {
25
- sortLabelKey: 'name',
26
- item: {
27
- setters: [
28
- {
29
- componentName: 'ShapeSetter',
30
- props: {
31
- collapse: false,
32
- elements: [
33
- {
34
- name: 'name',
35
- title: '类名',
36
- valueType: 'string',
37
- setters: ['StringSetter'],
38
- },
39
- {
40
- name: 'status',
41
- title: '启用',
42
- valueType: 'boolean',
43
- setters: ['ExpressionSetter'],
44
- },
45
- ],
46
- },
47
- initialValue: {},
48
- },
49
- ],
50
- initialValue: {
51
- name: '',
52
- status: {
53
- type: CNodePropsTypeEnum.EXPRESSION,
54
- value: true,
55
- },
56
- },
57
- },
58
- },
59
- initialValue: [],
60
- },
61
- ],
62
- },
63
- ];
64
-
65
- export const ClassNameEditor = forwardRef<ClassNameEditorRef, ClassNameEditorProps>(function CSSPropertiesEditorCore(
66
- props,
67
- ref
68
- ) {
69
- return (
70
- <ConfigProvider
71
- theme={{
72
- token: {
73
- borderRadius: 4,
74
- },
75
- }}
76
- >
77
- <div>
78
- <CustomSchemaForm
79
- initialValue={[]}
80
- properties={properties}
81
- // eslint-disable-next-line @typescript-eslint/no-empty-function
82
- onSetterChange={function () {}}
83
- onValueChange={(newVal) => {
84
- props.onValueChange?.(newVal.className || []);
85
- }}
86
- defaultSetterConfig={{}}
87
- ></CustomSchemaForm>
88
- </div>
89
- </ConfigProvider>
90
- );
91
- });
File without changes
@@ -1,81 +0,0 @@
1
- import React, { isValidElement, ReactNode, useEffect } from 'react';
2
- import styles from './style.module.scss';
3
- import { Tooltip } from 'antd';
4
- import { CFormContext } from '../context';
5
- export type CFieldProps = {
6
- children: React.ReactNode;
7
- label?: string;
8
- tips?: ReactNode | (() => ReactNode);
9
- name: string;
10
- condition?: (formState: Record<string, any>) => boolean;
11
- onConditionValueChange?: (val: boolean) => void;
12
- noStyle?: boolean;
13
- };
14
-
15
- export const CField = (props: CFieldProps) => {
16
- const { children, label, tips, name } = props;
17
- let labelView: ReactNode = label;
18
- const { formState, updateContext, updateConditionConfig } =
19
- React.useContext(CFormContext);
20
- useEffect(() => {
21
- if (props.condition) {
22
- updateConditionConfig(name, props.condition);
23
- }
24
- }, []);
25
-
26
- useEffect(() => {
27
- const condition = props.condition ?? (() => true);
28
- const canRender = condition(formState);
29
- props.onConditionValueChange?.(canRender);
30
- }, [formState, props]);
31
-
32
- if (tips) {
33
- let newTip: any = tips;
34
- if (typeof tips === 'function') {
35
- newTip = tips();
36
- }
37
- labelView = (
38
- <Tooltip
39
- title={
40
- <span style={{ color: 'rgba(255,255,255,0.9', fontSize: '12px' }}>
41
- {newTip}
42
- </span>
43
- }
44
- color="rgba(50,50,50,0.8)"
45
- >
46
- <span className={styles.tipsLabel}>{label}</span>
47
- </Tooltip>
48
- );
49
- }
50
- let newChildren = children;
51
-
52
- if (isValidElement(children)) {
53
- const extraProps: any = {
54
- onValueChange: (val: any) => {
55
- updateContext({
56
- ...formState,
57
- [name]: val,
58
- });
59
- },
60
- };
61
- if ((formState as any)[name] !== undefined) {
62
- extraProps.value = (formState as any)[name];
63
- }
64
- newChildren = React.cloneElement(children, extraProps);
65
- }
66
- const condition = props.condition ?? (() => true);
67
- const canRender = condition(formState);
68
- if (!canRender) {
69
- return null;
70
- }
71
- if (props.noStyle) {
72
- return <>{newChildren}</>;
73
- }
74
-
75
- return (
76
- <div className={styles.fieldBox}>
77
- <div className={styles.label}>{labelView}</div>
78
- <div className={styles.content}>{newChildren}</div>
79
- </div>
80
- );
81
- };
@@ -1,32 +0,0 @@
1
- .fieldBox {
2
- display: flex;
3
- flex-wrap: nowrap;
4
- flex-shrink: 0;
5
- flex-grow: 1;
6
- min-width: 250px;
7
- align-items: center;
8
- .label {
9
- font-size: 12px;
10
- color: $textColor;
11
- padding-right: 10px;
12
- user-select: none;
13
- width: 60px;
14
- max-height: 40px;
15
- word-break: break-all;
16
- text-overflow: ellipsis;
17
- overflow: hidden;
18
- display: -webkit-box;
19
- -webkit-box-orient: vertical;
20
- -webkit-line-clamp: 2; /* 这里是超出几行省略 */
21
- }
22
- .tipsLabel {
23
- text-decoration-line: underline;
24
- text-decoration-style: dashed;
25
- text-underline-offset: 2px;
26
- cursor: help;
27
- word-break: break-all;
28
- }
29
- .content {
30
- flex: 1;
31
- }
32
- }
@@ -1,8 +0,0 @@
1
- import globalClassNames from '../../../../../style.d';
2
- declare const classNames: typeof globalClassNames & {
3
- readonly fieldBox: 'fieldBox';
4
- readonly label: 'label';
5
- readonly tipsLabel: 'tipsLabel';
6
- readonly content: 'content';
7
- };
8
- export = classNames;
@@ -1,23 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */
2
- import React from 'react';
3
-
4
- export type ContextState = Record<string, any>;
5
-
6
- export type CFormContextData = {
7
- formName: string;
8
- formState: ContextState;
9
- conditionConfig: Record<string, (state: ContextState) => boolean>;
10
- updateContext: (newState: ContextState) => void;
11
- updateConditionConfig: (
12
- name: string,
13
- cb: (state: ContextState) => boolean
14
- ) => void;
15
- };
16
-
17
- export const CFormContext = React.createContext<CFormContextData>({
18
- formName: '',
19
- formState: {},
20
- conditionConfig: {},
21
- updateContext: () => {},
22
- updateConditionConfig: () => {},
23
- });