@chamn/engine 0.0.10 → 0.0.12

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 (205) 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} +3849 -3814
  11. package/dist/index.mjs.map +1 -0
  12. package/dist/material/innerMaterial.d.ts +1 -1
  13. package/dist/plugins/RightPanel/view.d.ts +4 -0
  14. package/package.json +12 -9
  15. package/.eslintignore +0 -1
  16. package/.eslintrc.js +0 -36
  17. package/.prettierrc.json +0 -7
  18. package/.storybook/main.js +0 -24
  19. package/.storybook/preview.js +0 -9
  20. package/CHANGELOG.md +0 -54
  21. package/__tests__/demo.test.ts +0 -3
  22. package/build.config.js +0 -88
  23. package/dist/index.cjs.js +0 -197
  24. package/dist/index.cjs.js.map +0 -1
  25. package/dist/index.es.js.map +0 -1
  26. package/index.html +0 -16
  27. package/jest.config.js +0 -196
  28. package/public/Engine.module.scss.d.ts +0 -5
  29. package/public/_dev_/render.d.ts +0 -2
  30. package/public/component/CSSEditor/style.module.scss.d.ts +0 -6
  31. package/public/component/CSSPropertiesEditor/style.module.scss.d.ts +0 -15
  32. package/public/component/CSSPropertiesVariableBindEditor/style.module.scss.d.ts +0 -15
  33. package/public/component/CustomSchemaForm/components/Form/Field/style.module.scss.d.ts +0 -8
  34. package/public/component/CustomSchemaForm/components/SetterSwitcher/style.module.scss.d.ts +0 -7
  35. package/public/component/CustomSchemaForm/components/Setters/ArraySetter/style.module.scss.d.ts +0 -7
  36. package/public/component/CustomSchemaForm/components/Setters/CSSValueSetter/style.module.scss.d.ts +0 -6
  37. package/public/component/CustomSchemaForm/style.module.scss.d.ts +0 -11
  38. package/public/component/Workbench/style.module.scss.d.ts +0 -25
  39. package/public/plugins/AdvancePanel/style.module.scss.d.ts +0 -7
  40. package/public/plugins/ComponentLibrary/components/DragItem/style.module.scss.d.ts +0 -9
  41. package/public/plugins/ComponentLibrary/components/ListView/style.module.scss.d.ts +0 -12
  42. package/public/plugins/ComponentLibrary/style.module.scss.d.ts +0 -11
  43. package/public/plugins/Designer/components/DefaultSelectToolBar/style.module.scss.d.ts +0 -11
  44. package/public/plugins/Designer/style.module.scss.d.ts +0 -5
  45. package/public/plugins/GlobalStatePanel/style.module.scss.d.ts +0 -5
  46. package/public/plugins/OutlineTree/components/TreeView/style.module.scss.d.ts +0 -16
  47. package/public/plugins/PropertyPanel/style.module.scss.d.ts +0 -10
  48. package/public/plugins/RightPanel/style.module.scss.d.ts +0 -10
  49. package/public/plugins/VisualPanelPlus/style.module.scss.d.ts +0 -10
  50. package/public/render.umd.js +0 -42
  51. package/public/render.umd.js.map +0 -1
  52. package/src/Engine.module.scss +0 -10
  53. package/src/Engine.module.scss.d.ts +0 -5
  54. package/src/_dev_/index.css +0 -22
  55. package/src/_dev_/index.tsx +0 -5
  56. package/src/_dev_/page/Editor/index.tsx +0 -198
  57. package/src/_dev_/page/Editor/indexCustom.tsx +0 -274
  58. package/src/_dev_/page/Preview/index.tsx +0 -56
  59. package/src/_dev_/render.ts +0 -3
  60. package/src/_dev_/router.tsx +0 -14
  61. package/src/assets/react.svg +0 -4
  62. package/src/assets/styles/mixin.scss +0 -15
  63. package/src/component/CSSEditor/index.tsx +0 -247
  64. package/src/component/CSSEditor/style.module.scss +0 -22
  65. package/src/component/CSSEditor/style.module.scss.d.ts +0 -6
  66. package/src/component/CSSPropertiesEditor/cssProperties.ts +0 -1062
  67. package/src/component/CSSPropertiesEditor/index.tsx +0 -389
  68. package/src/component/CSSPropertiesEditor/style.module.scss +0 -46
  69. package/src/component/CSSPropertiesEditor/style.module.scss.d.ts +0 -15
  70. package/src/component/CSSPropertiesEditor/util.ts +0 -19
  71. package/src/component/CSSPropertiesVariableBindEditor/cssProperties.ts +0 -782
  72. package/src/component/CSSPropertiesVariableBindEditor/index.tsx +0 -366
  73. package/src/component/CSSPropertiesVariableBindEditor/style.module.scss +0 -48
  74. package/src/component/CSSPropertiesVariableBindEditor/style.module.scss.d.ts +0 -15
  75. package/src/component/CSSPropertiesVariableBindEditor/util.ts +0 -19
  76. package/src/component/ClassNameEditor/index.tsx +0 -91
  77. package/src/component/ClassNameEditor/style.module.scss +0 -0
  78. package/src/component/CustomSchemaForm/components/Form/Field/index.tsx +0 -81
  79. package/src/component/CustomSchemaForm/components/Form/Field/style.module.scss +0 -32
  80. package/src/component/CustomSchemaForm/components/Form/Field/style.module.scss.d.ts +0 -8
  81. package/src/component/CustomSchemaForm/components/Form/context.ts +0 -23
  82. package/src/component/CustomSchemaForm/components/Form/index.tsx +0 -71
  83. package/src/component/CustomSchemaForm/components/SetterSwitcher/index.tsx +0 -273
  84. package/src/component/CustomSchemaForm/components/SetterSwitcher/style.module.scss +0 -16
  85. package/src/component/CustomSchemaForm/components/SetterSwitcher/style.module.scss.d.ts +0 -7
  86. package/src/component/CustomSchemaForm/components/Setters/ArraySetter/ArrayItem.tsx +0 -55
  87. package/src/component/CustomSchemaForm/components/Setters/ArraySetter/SortItemOrderModal.tsx +0 -160
  88. package/src/component/CustomSchemaForm/components/Setters/ArraySetter/index.tsx +0 -129
  89. package/src/component/CustomSchemaForm/components/Setters/ArraySetter/style.module.scss +0 -22
  90. package/src/component/CustomSchemaForm/components/Setters/ArraySetter/style.module.scss.d.ts +0 -7
  91. package/src/component/CustomSchemaForm/components/Setters/BooleanSetter/index.tsx +0 -32
  92. package/src/component/CustomSchemaForm/components/Setters/CSSValueSetter/index.tsx +0 -78
  93. package/src/component/CustomSchemaForm/components/Setters/CSSValueSetter/style.module.scss +0 -7
  94. package/src/component/CustomSchemaForm/components/Setters/CSSValueSetter/style.module.scss.d.ts +0 -6
  95. package/src/component/CustomSchemaForm/components/Setters/ExpressionSetter/index.tsx +0 -47
  96. package/src/component/CustomSchemaForm/components/Setters/FunctionSetter/defaultDts.ts +0 -28
  97. package/src/component/CustomSchemaForm/components/Setters/FunctionSetter/index.tsx +0 -93
  98. package/src/component/CustomSchemaForm/components/Setters/JSONSetter/index.tsx +0 -80
  99. package/src/component/CustomSchemaForm/components/Setters/NumberSetter/index.tsx +0 -34
  100. package/src/component/CustomSchemaForm/components/Setters/SelectSetter/index.tsx +0 -35
  101. package/src/component/CustomSchemaForm/components/Setters/ShapeSetter/index.tsx +0 -65
  102. package/src/component/CustomSchemaForm/components/Setters/StringSetter/index.tsx +0 -30
  103. package/src/component/CustomSchemaForm/components/Setters/TextAreaSetter/index.tsx +0 -31
  104. package/src/component/CustomSchemaForm/components/Setters/index.ts +0 -26
  105. package/src/component/CustomSchemaForm/components/Setters/type.ts +0 -18
  106. package/src/component/CustomSchemaForm/context.ts +0 -20
  107. package/src/component/CustomSchemaForm/index.tsx +0 -93
  108. package/src/component/CustomSchemaForm/style.module.scss +0 -15
  109. package/src/component/CustomSchemaForm/style.module.scss.d.ts +0 -11
  110. package/src/component/CustomSchemaForm/utils.ts +0 -13
  111. package/src/component/MonacoEditor/index.tsx +0 -81
  112. package/src/component/Workbench/index.tsx +0 -329
  113. package/src/component/Workbench/style.module.scss +0 -159
  114. package/src/component/Workbench/style.module.scss.d.ts +0 -25
  115. package/src/core/pluginManager.ts +0 -151
  116. package/src/i18n/en_US/index.ts +0 -5
  117. package/src/i18n/index.ts +0 -39
  118. package/src/i18n/zh_CN/index.ts +0 -5
  119. package/src/index.tsx +0 -150
  120. package/src/material/innerMaterial.ts +0 -343
  121. package/src/plugins/AdvancePanel/index.tsx +0 -191
  122. package/src/plugins/AdvancePanel/style.module.scss +0 -8
  123. package/src/plugins/AdvancePanel/style.module.scss.d.ts +0 -7
  124. package/src/plugins/ComponentLibrary/components/DragItem/index.tsx +0 -65
  125. package/src/plugins/ComponentLibrary/components/DragItem/style.module.scss +0 -58
  126. package/src/plugins/ComponentLibrary/components/DragItem/style.module.scss.d.ts +0 -9
  127. package/src/plugins/ComponentLibrary/components/ListView/index.tsx +0 -50
  128. package/src/plugins/ComponentLibrary/components/ListView/style.module.scss +0 -27
  129. package/src/plugins/ComponentLibrary/components/ListView/style.module.scss.d.ts +0 -12
  130. package/src/plugins/ComponentLibrary/index.tsx +0 -184
  131. package/src/plugins/ComponentLibrary/localize/en_US/index.ts +0 -3
  132. package/src/plugins/ComponentLibrary/localize/index.ts +0 -3
  133. package/src/plugins/ComponentLibrary/localize/zh_CN/index.ts +0 -3
  134. package/src/plugins/ComponentLibrary/style.module.scss +0 -31
  135. package/src/plugins/ComponentLibrary/style.module.scss.d.ts +0 -11
  136. package/src/plugins/ComponentLibrary/util.ts +0 -14
  137. package/src/plugins/ComponentStatePanel/index.tsx +0 -59
  138. package/src/plugins/Designer/components/DefaultSelectToolBar/index.tsx +0 -94
  139. package/src/plugins/Designer/components/DefaultSelectToolBar/style.module.scss +0 -59
  140. package/src/plugins/Designer/components/DefaultSelectToolBar/style.module.scss.d.ts +0 -11
  141. package/src/plugins/Designer/components/GhostView/index.tsx +0 -18
  142. package/src/plugins/Designer/config.ts +0 -1
  143. package/src/plugins/Designer/index.tsx +0 -61
  144. package/src/plugins/Designer/localize/en_US/index.ts +0 -3
  145. package/src/plugins/Designer/localize/index.ts +0 -3
  146. package/src/plugins/Designer/localize/zh_CN/index.ts +0 -3
  147. package/src/plugins/Designer/style.module.scss +0 -10
  148. package/src/plugins/Designer/style.module.scss.d.ts +0 -5
  149. package/src/plugins/Designer/util.ts +0 -18
  150. package/src/plugins/Designer/view.tsx +0 -225
  151. package/src/plugins/DisplaySourceSchema/index.tsx +0 -76
  152. package/src/plugins/GlobalStatePanel/index.tsx +0 -96
  153. package/src/plugins/GlobalStatePanel/localize/en_US/index.ts +0 -3
  154. package/src/plugins/GlobalStatePanel/localize/index.ts +0 -3
  155. package/src/plugins/GlobalStatePanel/localize/zh_CN/index.ts +0 -3
  156. package/src/plugins/GlobalStatePanel/style.module.scss +0 -8
  157. package/src/plugins/GlobalStatePanel/style.module.scss.d.ts +0 -5
  158. package/src/plugins/History/index.tsx +0 -110
  159. package/src/plugins/OutlineTree/components/TreeView/context.ts +0 -43
  160. package/src/plugins/OutlineTree/components/TreeView/dataStruct.ts +0 -58
  161. package/src/plugins/OutlineTree/components/TreeView/index.tsx +0 -376
  162. package/src/plugins/OutlineTree/components/TreeView/style.module.scss +0 -93
  163. package/src/plugins/OutlineTree/components/TreeView/style.module.scss.d.ts +0 -16
  164. package/src/plugins/OutlineTree/components/TreeView/treeNode.tsx +0 -271
  165. package/src/plugins/OutlineTree/index.tsx +0 -39
  166. package/src/plugins/OutlineTree/localize/en_US/index.ts +0 -3
  167. package/src/plugins/OutlineTree/localize/index.ts +0 -3
  168. package/src/plugins/OutlineTree/localize/zh_CN/index.ts +0 -3
  169. package/src/plugins/OutlineTree/util.tsx +0 -302
  170. package/src/plugins/PropertyPanel/index.tsx +0 -63
  171. package/src/plugins/PropertyPanel/style.module.scss +0 -12
  172. package/src/plugins/PropertyPanel/style.module.scss.d.ts +0 -10
  173. package/src/plugins/PropertyPanel/utils.ts +0 -13
  174. package/src/plugins/RightPanel/index.tsx +0 -30
  175. package/src/plugins/RightPanel/style.module.scss +0 -16
  176. package/src/plugins/RightPanel/style.module.scss.d.ts +0 -10
  177. package/src/plugins/RightPanel/view.tsx +0 -177
  178. package/src/plugins/VisualPanel/index.tsx +0 -185
  179. package/src/plugins/VisualPanel/style.module.scss +0 -17
  180. package/src/plugins/VisualPanelPlus/index.tsx +0 -103
  181. package/src/plugins/VisualPanelPlus/style.module.scss +0 -20
  182. package/src/plugins/VisualPanelPlus/style.module.scss.d.ts +0 -10
  183. package/src/plugins/index.tsx +0 -26
  184. package/src/stories/Button.jsx +0 -50
  185. package/src/stories/Button.stories.jsx +0 -40
  186. package/src/stories/Introduction.stories.mdx +0 -194
  187. package/src/stories/assets/code-brackets.svg +0 -1
  188. package/src/stories/assets/colors.svg +0 -1
  189. package/src/stories/assets/comments.svg +0 -1
  190. package/src/stories/assets/direction.svg +0 -1
  191. package/src/stories/assets/flow.svg +0 -1
  192. package/src/stories/assets/plugin.svg +0 -1
  193. package/src/stories/assets/repo.svg +0 -1
  194. package/src/stories/assets/stackalt.svg +0 -1
  195. package/src/stories/button.css +0 -30
  196. package/src/stories/plugins/CSSEditor.stories.tsx +0 -75
  197. package/src/stories/plugins/VisualPanelPlus.stories.tsx +0 -74
  198. package/src/style.d.ts +0 -2
  199. package/src/typing.d.ts +0 -9
  200. package/src/utils/css.ts +0 -88
  201. package/src/utils/defaultEngineConfig.tsx +0 -55
  202. package/src/utils/index.ts +0 -12
  203. package/src/utils/logger.ts +0 -4
  204. package/src/vite-env.d.ts +0 -1
  205. package/tsconfig.json +0 -32
@@ -1,389 +0,0 @@
1
- import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
2
- import { CSSProperties, CSSPropertiesKey, CSSPropertyList } from './cssProperties';
3
-
4
- import styles from './style.module.scss';
5
-
6
- import { AutoComplete, Button, ConfigProvider, 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 { InputStatus } from 'antd/es/_util/statusUtils';
13
-
14
- const defaultPropertyOptions = CSSPropertyList.map((el) => {
15
- return {
16
- value: el,
17
- };
18
- });
19
-
20
- export type SinglePropertyEditorProps = {
21
- mode: 'create' | 'edit';
22
- value: {
23
- key: string;
24
- value: string;
25
- };
26
- allValues: {
27
- key: string;
28
- value: string;
29
- }[];
30
- onValueChange: (value: { key: string; value: string }) => void;
31
- onCreate?: (value: { key: string; value: string }) => void;
32
- onDelete?: () => void;
33
- };
34
-
35
- type SinglePropertyEditorRef = {
36
- reset: () => void;
37
- };
38
-
39
- export const SinglePropertyEditor = forwardRef<SinglePropertyEditorRef, SinglePropertyEditorProps>(
40
- function SinglePropertyEditorCore(props, ref) {
41
- const [keyFormatStatus, setKeyFormatStatus] = useState<InputStatus>('');
42
- const [valueFormatStatus, setValueFormatStatus] = useState<InputStatus>('');
43
- const { mode = 'edit' } = props;
44
- const isCreate = useMemo(() => {
45
- return mode === 'create';
46
- }, [mode]);
47
- const [innerValue, setInnerVal] = useState({
48
- key: props.value.key,
49
- value: props.value.value,
50
- });
51
-
52
- useEffect(() => {
53
- setInnerVal(props.value);
54
- }, [props.value]);
55
-
56
- const [propertyOptions, setPropertyOptions] = useState(defaultPropertyOptions);
57
-
58
- const [valueOptions, setValueOptions] = useState<{ value: string }[]>([]);
59
- const [allValueOptions, setAllValueOptions] = useState<{ value: string }[]>([]);
60
-
61
- const onSearch = (searchText: string) => {
62
- const newOptions = defaultPropertyOptions.filter((el) => el.value.includes(searchText));
63
- if (!searchText) {
64
- setPropertyOptions(defaultPropertyOptions);
65
- } else {
66
- setPropertyOptions(newOptions);
67
- }
68
- };
69
-
70
- const updateValueOptions = () => {
71
- let res: any[] = [];
72
- const tempProperty = CSSProperties[innerValue.key as unknown as CSSPropertiesKey];
73
-
74
- if (tempProperty) {
75
- res =
76
- tempProperty.values?.map((val) => {
77
- return {
78
- value: val,
79
- };
80
- }) || [];
81
- }
82
-
83
- setValueOptions(res);
84
- setAllValueOptions(res);
85
- };
86
-
87
- const onValueSearch = (searchText: string) => {
88
- const newOptions = allValueOptions.filter((el) => el.value.includes(searchText));
89
- if (!searchText) {
90
- setValueOptions(allValueOptions);
91
- } else {
92
- setValueOptions(newOptions);
93
- }
94
- };
95
-
96
- const updateKeyValue = () => {
97
- if (props.allValues.find((el) => el.key === innerValue.key)) {
98
- message.error(`${innerValue.key} is exits`);
99
- setKeyFormatStatus('error');
100
- return false;
101
- }
102
- return true;
103
- };
104
-
105
- const updateValValue = () => {
106
- if (isCreate) {
107
- if (innerValue.value) {
108
- props.onCreate?.(innerValue);
109
- } else {
110
- setValueFormatStatus('error');
111
- }
112
- } else {
113
- updateOuterValueDebounce();
114
- }
115
- };
116
-
117
- const updateOuterValue = () => {
118
- setKeyFormatStatus('');
119
- setValueFormatStatus('');
120
-
121
- props.onValueChange({
122
- ...innerValue,
123
- });
124
- };
125
-
126
- const { run: updateOuterValueDebounce } = useDebounceFn(updateOuterValue, {
127
- wait: 20,
128
- });
129
-
130
- const [keyInputWidth, setKeyInputWidth] = useState(0);
131
-
132
- useEffect(() => {
133
- getTextWidth(innerValue.key, 13.33).then((w) => {
134
- let tempW = parseFloat(w);
135
- if (innerValue.key === '') {
136
- tempW = 200;
137
- }
138
- setKeyInputWidth(tempW + 6);
139
- });
140
- }, [innerValue.key]);
141
-
142
- const propertyValueRef = useRef<BaseSelectRef | null>(null);
143
- const propertyKeyRef = useRef<BaseSelectRef | null>(null);
144
- const [focusState, setFocusState] = useState({
145
- key: false,
146
- value: false,
147
- });
148
- useImperativeHandle(
149
- ref,
150
- () => {
151
- return {
152
- reset: () => {
153
- setInnerVal({
154
- key: '',
155
- value: '',
156
- });
157
- propertyKeyRef.current?.focus();
158
- },
159
- };
160
- },
161
- []
162
- );
163
-
164
- return (
165
- <div className={styles.cssFieldBox}>
166
- <AutoComplete
167
- ref={propertyKeyRef}
168
- bordered={false}
169
- disabled={!isCreate}
170
- onSearch={onSearch}
171
- status={keyFormatStatus}
172
- dropdownMatchSelectWidth={200}
173
- value={innerValue.key}
174
- onChange={(val) => {
175
- setInnerVal({
176
- ...innerValue,
177
- key: val,
178
- });
179
- setKeyFormatStatus('');
180
- }}
181
- style={{
182
- width: `${keyInputWidth}px`,
183
- }}
184
- className={clsx([isCreate && styles.inputAuto, isCreate && focusState.key && styles.active])}
185
- onFocus={() => {
186
- setFocusState({
187
- key: true,
188
- value: false,
189
- });
190
- }}
191
- onBlur={() => {
192
- setFocusState({
193
- key: false,
194
- value: false,
195
- });
196
- updateKeyValue();
197
- }}
198
- onKeyDown={(e) => {
199
- if (e.code === 'Enter') {
200
- const res = updateKeyValue();
201
- if (res) {
202
- propertyValueRef.current?.focus();
203
- }
204
- }
205
- }}
206
- placeholder="property"
207
- options={propertyOptions}
208
- />
209
- <span>:</span>
210
- <AutoComplete
211
- bordered={false}
212
- ref={propertyValueRef}
213
- status={valueFormatStatus}
214
- dropdownMatchSelectWidth={200}
215
- value={innerValue.value}
216
- onChange={(val) => {
217
- updateValueOptions();
218
- setInnerVal({
219
- ...innerValue,
220
- value: val,
221
- });
222
- setValueFormatStatus('');
223
- if (!isCreate) {
224
- props.onCreate?.(innerValue);
225
- updateOuterValueDebounce();
226
- }
227
- }}
228
- style={{
229
- flex: 1,
230
- }}
231
- onFocus={() => {
232
- setFocusState({
233
- key: false,
234
- value: true,
235
- });
236
- }}
237
- onBlur={() => {
238
- setFocusState({
239
- key: false,
240
- value: false,
241
- });
242
- updateOuterValueDebounce();
243
- }}
244
- className={clsx([styles.inputAuto, focusState.value && styles.active])}
245
- placeholder="value"
246
- onSearch={onValueSearch}
247
- options={valueOptions}
248
- onKeyDown={(e) => {
249
- if (e.code === 'Enter') {
250
- updateValValue();
251
- }
252
- }}
253
- ></AutoComplete>
254
-
255
- {props.onDelete && mode === 'edit' && (
256
- <Button
257
- size="small"
258
- type="text"
259
- onClick={() => {
260
- props.onDelete?.();
261
- }}
262
- >
263
- <MinusOutlined
264
- style={{
265
- display: 'inline-flex',
266
- fontSize: '12px',
267
- }}
268
- />
269
- </Button>
270
- )}
271
- {props.onCreate && mode === 'create' && (
272
- <div>
273
- <Button
274
- size="small"
275
- type="text"
276
- icon={
277
- <PlusOutlined
278
- style={{
279
- fontSize: '12px',
280
- display: 'inline-flex',
281
- }}
282
- />
283
- }
284
- onClick={updateValValue}
285
- ></Button>
286
- </div>
287
- )}
288
- </div>
289
- );
290
- }
291
- );
292
-
293
- export type CSSPropertiesEditorProps = {
294
- initialValue?: { key: string; value: string }[];
295
- onValueChange?: (val: { key: string; value: string }[]) => void;
296
- };
297
- export type CSSPropertiesEditorRef = {
298
- setValue: (val: { key: string; value: string }[]) => void;
299
- };
300
-
301
- export const CSSPropertiesEditor = forwardRef<CSSPropertiesEditorRef, CSSPropertiesEditorProps>(
302
- function CSSPropertiesEditorCore(props, ref) {
303
- const [propertyList, setPropertyList] = useState<{ key: string; value: any }[]>([]);
304
-
305
- useImperativeHandle(
306
- ref,
307
- () => {
308
- return {
309
- setValue: (val) => {
310
- setPropertyList(val);
311
- },
312
- };
313
- },
314
- []
315
- );
316
-
317
- useEffect(() => {
318
- if (props.initialValue) {
319
- setPropertyList(props.initialValue);
320
- }
321
- }, []);
322
-
323
- const [newProperty, setNewProperty] = useState({
324
- key: '',
325
- value: '',
326
- });
327
-
328
- const innerOnValueChange = (val: typeof propertyList) => {
329
- props.onValueChange?.(val);
330
- };
331
-
332
- const createPropertyRef = useRef<SinglePropertyEditorRef>(null);
333
- return (
334
- <ConfigProvider
335
- theme={{
336
- token: {
337
- borderRadius: 4,
338
- },
339
- }}
340
- >
341
- <div className={styles.cssBox}>
342
- {propertyList.map((el, index) => {
343
- return (
344
- <div key={index}>
345
- <SinglePropertyEditor
346
- mode="edit"
347
- allValues={propertyList}
348
- value={el}
349
- onValueChange={(newVal) => {
350
- propertyList[index] = newVal;
351
- setPropertyList([...propertyList]);
352
- innerOnValueChange(propertyList);
353
- }}
354
- onDelete={() => {
355
- propertyList.splice(index, 1);
356
- setPropertyList([...propertyList]);
357
- innerOnValueChange(propertyList);
358
- }}
359
- />
360
- </div>
361
- );
362
- })}
363
- <SinglePropertyEditor
364
- allValues={propertyList}
365
- mode="create"
366
- value={newProperty}
367
- ref={createPropertyRef}
368
- onCreate={(newVal) => {
369
- if (newVal.key && newVal.value) {
370
- const newList = propertyList.filter((el) => el.key !== newVal.key);
371
- newList.push(newVal);
372
- setPropertyList(newList);
373
- innerOnValueChange(newList);
374
- createPropertyRef.current?.reset();
375
- setNewProperty({
376
- key: '',
377
- value: '',
378
- });
379
- }
380
- }}
381
- onValueChange={(newVal) => {
382
- setNewProperty(newVal);
383
- }}
384
- />
385
- </div>
386
- </ConfigProvider>
387
- );
388
- }
389
- );
@@ -1,46 +0,0 @@
1
- .cssFieldBox {
2
- display: flex;
3
- align-items: center;
4
- color: $textColor !important;
5
- :global {
6
- .ant-select-selector {
7
- padding: 0 !important;
8
- }
9
-
10
- .ant-select-single .ant-select-selector .ant-select-selection-search {
11
- inset-inline-start: 0px;
12
- inset-inline-end: 0px;
13
- }
14
-
15
- .ant-select-selector input {
16
- color: $textColor !important;
17
- }
18
- .ant-select-status-error {
19
- border-bottom: 1px solid red !important;
20
- }
21
- }
22
-
23
- .inputAuto {
24
- border-bottom: 1px solid rgba(128, 128, 128, 0.23);
25
- }
26
-
27
- .active {
28
- border-bottom: 1px solid rgb(128, 177, 255);
29
- }
30
- }
31
-
32
- .cssBox {
33
- overflow-x: hidden;
34
- :global {
35
- .ant-collapse-borderless > .ant-collapse-item {
36
- border-bottom: 1px solid #e4e4e4;
37
- }
38
-
39
- .ant-collapse-borderless > .ant-collapse-item:last-child {
40
- border-bottom: none;
41
- }
42
- .ant-collapse-content-box {
43
- padding-bottom: 30px !important;
44
- }
45
- }
46
- }
@@ -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 'ant-select-single': 'ant-select-single';
6
- readonly 'ant-select-selection-search': 'ant-select-selection-search';
7
- readonly 'ant-select-status-error': 'ant-select-status-error';
8
- readonly inputAuto: 'inputAuto';
9
- readonly active: 'active';
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
- };