@flowgram.ai/form-materials 0.1.8
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/bin/index.js +63 -0
- package/bin/materials.js +72 -0
- package/bin/project.js +72 -0
- package/dist/esm/index.js +845 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +879 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -0
- package/src/components/index.ts +3 -0
- package/src/components/json-schema-editor/config.json +5 -0
- package/src/components/json-schema-editor/hooks.tsx +114 -0
- package/src/components/json-schema-editor/index.tsx +196 -0
- package/src/components/json-schema-editor/styles.tsx +145 -0
- package/src/components/json-schema-editor/types.ts +11 -0
- package/src/components/type-selector/config.json +5 -0
- package/src/components/type-selector/constants.tsx +359 -0
- package/src/components/type-selector/index.tsx +54 -0
- package/src/components/type-selector/types.ts +19 -0
- package/src/components/variable-selector/config.json +5 -0
- package/src/components/variable-selector/index.tsx +45 -0
- package/src/components/variable-selector/use-variable-tree.tsx +73 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useScopeAvailable, ASTMatch, BaseVariableField } from '@flowgram.ai/editor';
|
|
4
|
+
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
5
|
+
import { Icon } from '@douyinfe/semi-ui';
|
|
6
|
+
|
|
7
|
+
import { ArrayIcons, VariableTypeIcons } from '../type-selector/constants';
|
|
8
|
+
|
|
9
|
+
type VariableField = BaseVariableField<{ icon?: string | JSX.Element; title?: string }>;
|
|
10
|
+
|
|
11
|
+
export function useVariableTree(): TreeNodeData[] {
|
|
12
|
+
const available = useScopeAvailable();
|
|
13
|
+
|
|
14
|
+
const getVariableTypeIcon = useCallback((variable: VariableField) => {
|
|
15
|
+
if (variable.meta.icon) {
|
|
16
|
+
if (typeof variable.meta.icon === 'string') {
|
|
17
|
+
return <img style={{ marginRight: 8 }} width={12} height={12} src={variable.meta.icon} />;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return variable.meta.icon;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const _type = variable.type;
|
|
24
|
+
|
|
25
|
+
if (ASTMatch.isArray(_type)) {
|
|
26
|
+
return (
|
|
27
|
+
<Icon
|
|
28
|
+
size="small"
|
|
29
|
+
svg={ArrayIcons[_type.items?.kind.toLowerCase()] || VariableTypeIcons.array}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (ASTMatch.isCustomType(_type)) {
|
|
35
|
+
return <Icon size="small" svg={VariableTypeIcons[_type.typeName.toLowerCase()]} />;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return <Icon size="small" svg={VariableTypeIcons[variable.type?.kind.toLowerCase()]} />;
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
41
|
+
const renderVariable = (
|
|
42
|
+
variable: VariableField,
|
|
43
|
+
parentFields: VariableField[] = []
|
|
44
|
+
): TreeNodeData | null => {
|
|
45
|
+
let type = variable?.type;
|
|
46
|
+
|
|
47
|
+
let children: TreeNodeData[] | undefined;
|
|
48
|
+
|
|
49
|
+
if (ASTMatch.isObject(type)) {
|
|
50
|
+
children = (type.properties || [])
|
|
51
|
+
.map((_property) => renderVariable(_property as VariableField, [...parentFields, variable]))
|
|
52
|
+
.filter(Boolean) as TreeNodeData[];
|
|
53
|
+
|
|
54
|
+
if (!children?.length) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const currPath = [...parentFields.map((_field) => _field.key), variable.key].join('.');
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
key: currPath,
|
|
63
|
+
label: variable.meta.title || variable.key,
|
|
64
|
+
value: currPath,
|
|
65
|
+
icon: getVariableTypeIcon(variable),
|
|
66
|
+
children,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return [...available.variables.slice(0).reverse()]
|
|
71
|
+
.map((_variable) => renderVariable(_variable as VariableField))
|
|
72
|
+
.filter(Boolean) as TreeNodeData[];
|
|
73
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|