@flowgram.ai/form-materials 0.1.0-alpha.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.
Files changed (60) hide show
  1. package/bin/index.ts +94 -0
  2. package/bin/materials.ts +137 -0
  3. package/bin/project.ts +86 -0
  4. package/dist/esm/index.js +1978 -0
  5. package/dist/esm/index.js.map +1 -0
  6. package/dist/index.d.mts +285 -0
  7. package/dist/index.d.ts +285 -0
  8. package/dist/index.js +2018 -0
  9. package/dist/index.js.map +1 -0
  10. package/package.json +72 -0
  11. package/src/components/batch-variable-selector/config.json +5 -0
  12. package/src/components/batch-variable-selector/index.tsx +19 -0
  13. package/src/components/condition-row/config.json +5 -0
  14. package/src/components/condition-row/constants.ts +123 -0
  15. package/src/components/condition-row/hooks/useOp.tsx +45 -0
  16. package/src/components/condition-row/hooks/useRule.ts +26 -0
  17. package/src/components/condition-row/index.tsx +71 -0
  18. package/src/components/condition-row/styles.tsx +25 -0
  19. package/src/components/condition-row/types.ts +37 -0
  20. package/src/components/constant-input/config.json +6 -0
  21. package/src/components/constant-input/index.tsx +81 -0
  22. package/src/components/constant-input/types.ts +18 -0
  23. package/src/components/dynamic-value-input/config.json +5 -0
  24. package/src/components/dynamic-value-input/index.tsx +85 -0
  25. package/src/components/dynamic-value-input/styles.tsx +19 -0
  26. package/src/components/index.ts +7 -0
  27. package/src/components/json-schema-editor/components/blur-input.tsx +22 -0
  28. package/src/components/json-schema-editor/config.json +5 -0
  29. package/src/components/json-schema-editor/default-value.tsx +130 -0
  30. package/src/components/json-schema-editor/hooks.tsx +161 -0
  31. package/src/components/json-schema-editor/index.tsx +256 -0
  32. package/src/components/json-schema-editor/styles.tsx +235 -0
  33. package/src/components/json-schema-editor/types.ts +21 -0
  34. package/src/components/json-schema-editor/utils.ts +24 -0
  35. package/src/components/type-selector/config.json +5 -0
  36. package/src/components/type-selector/constants.tsx +359 -0
  37. package/src/components/type-selector/index.tsx +57 -0
  38. package/src/components/variable-selector/config.json +5 -0
  39. package/src/components/variable-selector/index.tsx +109 -0
  40. package/src/components/variable-selector/styles.tsx +43 -0
  41. package/src/components/variable-selector/use-variable-tree.tsx +101 -0
  42. package/src/effects/auto-rename-ref/config.json +5 -0
  43. package/src/effects/auto-rename-ref/index.ts +104 -0
  44. package/src/effects/index.ts +3 -0
  45. package/src/effects/provide-batch-input/config.json +5 -0
  46. package/src/effects/provide-batch-input/index.ts +38 -0
  47. package/src/effects/provide-batch-outputs/config.json +5 -0
  48. package/src/effects/provide-batch-outputs/index.ts +34 -0
  49. package/src/index.ts +4 -0
  50. package/src/typings/flow-value/config.json +5 -0
  51. package/src/typings/flow-value/index.ts +27 -0
  52. package/src/typings/index.ts +2 -0
  53. package/src/typings/json-schema/config.json +5 -0
  54. package/src/typings/json-schema/index.ts +31 -0
  55. package/src/utils/format-legacy-refs/config.json +5 -0
  56. package/src/utils/format-legacy-refs/index.ts +153 -0
  57. package/src/utils/format-legacy-refs/readme.md +38 -0
  58. package/src/utils/index.ts +2 -0
  59. package/src/utils/json-schema/config.json +5 -0
  60. package/src/utils/json-schema/index.ts +161 -0
@@ -0,0 +1,256 @@
1
+ import React, { useMemo, useState } from 'react';
2
+
3
+ import { Button, Checkbox, IconButton } from '@douyinfe/semi-ui';
4
+ import {
5
+ IconExpand,
6
+ IconShrink,
7
+ IconPlus,
8
+ IconChevronDown,
9
+ IconChevronRight,
10
+ IconMinus,
11
+ } from '@douyinfe/semi-icons';
12
+
13
+ import { TypeSelector } from '../type-selector';
14
+ import { IJsonSchema } from '../../typings';
15
+ import { ConfigType, PropertyValueType } from './types';
16
+ import {
17
+ IconAddChildren,
18
+ UIActions,
19
+ UICollapseTrigger,
20
+ UICollapsible,
21
+ UIContainer,
22
+ UIExpandDetail,
23
+ UILabel,
24
+ UIProperties,
25
+ UIPropertyLeft,
26
+ UIPropertyMain,
27
+ UIPropertyRight,
28
+ UIRequired,
29
+ UIType,
30
+ } from './styles';
31
+ import { UIName } from './styles';
32
+ import { DefaultValueWrapper, UIRow } from './styles';
33
+ import { usePropertiesEdit } from './hooks';
34
+ import { DefaultValue } from './default-value';
35
+ import { BlurInput } from './components/blur-input';
36
+
37
+ export function JsonSchemaEditor(props: {
38
+ value?: IJsonSchema;
39
+ onChange?: (value: IJsonSchema) => void;
40
+ config?: ConfigType;
41
+ }) {
42
+ const { value = { type: 'object' }, config = {}, onChange: onChangeProps } = props;
43
+ const { propertyList, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(
44
+ value,
45
+ onChangeProps
46
+ );
47
+
48
+ return (
49
+ <UIContainer>
50
+ <UIProperties>
51
+ {propertyList.map((_property, index) => (
52
+ <PropertyEdit
53
+ key={_property.key}
54
+ value={_property}
55
+ config={config}
56
+ $index={index}
57
+ onChange={(_v) => {
58
+ onEditProperty(_property.key!, _v);
59
+ }}
60
+ onRemove={() => {
61
+ onRemoveProperty(_property.key!);
62
+ }}
63
+ />
64
+ ))}
65
+ </UIProperties>
66
+ <Button size="small" style={{ marginTop: 10 }} icon={<IconPlus />} onClick={onAddProperty}>
67
+ {config?.addButtonText ?? 'Add'}
68
+ </Button>
69
+ </UIContainer>
70
+ );
71
+ }
72
+
73
+ function PropertyEdit(props: {
74
+ value?: PropertyValueType;
75
+ config?: ConfigType;
76
+ onChange?: (value: PropertyValueType) => void;
77
+ onRemove?: () => void;
78
+ $isLast?: boolean;
79
+ $index?: number;
80
+ $isFirst?: boolean;
81
+ $parentExpand?: boolean;
82
+ $parentType?: string;
83
+ $showLine?: boolean;
84
+ $level?: number; // 添加层级属性
85
+ }) {
86
+ const {
87
+ value,
88
+ config,
89
+ $level = 0,
90
+ onChange: onChangeProps,
91
+ onRemove,
92
+ $index,
93
+ $isFirst,
94
+ $isLast,
95
+ $parentExpand = false,
96
+ $parentType = '',
97
+ $showLine,
98
+ } = props;
99
+
100
+ const [expand, setExpand] = useState(false);
101
+ const [collapse, setCollapse] = useState(false);
102
+
103
+ const { name, type, items, default: defaultValue, description, isPropertyRequired } = value || {};
104
+
105
+ const typeSelectorValue = useMemo(() => ({ type, items }), [type, items]);
106
+
107
+ const { propertyList, isDrilldownObject, onAddProperty, onRemoveProperty, onEditProperty } =
108
+ usePropertiesEdit(value, onChangeProps);
109
+
110
+ const onChange = (key: string, _value: any) => {
111
+ onChangeProps?.({
112
+ ...(value || {}),
113
+ [key]: _value,
114
+ });
115
+ };
116
+
117
+ const showCollapse = isDrilldownObject && propertyList.length > 0;
118
+
119
+ return (
120
+ <>
121
+ <UIPropertyLeft
122
+ type={type}
123
+ $index={$index}
124
+ $isFirst={$isFirst}
125
+ $isLast={$isLast}
126
+ $showLine={$showLine}
127
+ $isExpand={expand}
128
+ $parentExpand={$parentExpand}
129
+ $parentType={$parentType}
130
+ >
131
+ {showCollapse && (
132
+ <UICollapseTrigger onClick={() => setCollapse((_collapse) => !_collapse)}>
133
+ {collapse ? <IconChevronDown size="small" /> : <IconChevronRight size="small" />}
134
+ </UICollapseTrigger>
135
+ )}
136
+ </UIPropertyLeft>
137
+ <UIPropertyRight>
138
+ <UIPropertyMain
139
+ $showCollapse={showCollapse}
140
+ $collapse={collapse}
141
+ $expand={expand}
142
+ type={type}
143
+ >
144
+ <UIRow>
145
+ <UIName>
146
+ <BlurInput
147
+ placeholder={config?.placeholder ?? 'Input Variable Name'}
148
+ size="small"
149
+ value={name}
150
+ onChange={(value) => onChange('name', value)}
151
+ />
152
+ </UIName>
153
+ <UIType>
154
+ <TypeSelector
155
+ value={typeSelectorValue}
156
+ onChange={(_value) => {
157
+ onChangeProps?.({
158
+ ...(value || {}),
159
+ ..._value,
160
+ });
161
+ }}
162
+ />
163
+ </UIType>
164
+ <UIRequired>
165
+ <Checkbox
166
+ checked={isPropertyRequired}
167
+ onChange={(e) => onChange('isPropertyRequired', e.target.checked)}
168
+ />
169
+ </UIRequired>
170
+ <UIActions>
171
+ <IconButton
172
+ size="small"
173
+ theme="borderless"
174
+ icon={expand ? <IconShrink size="small" /> : <IconExpand size="small" />}
175
+ onClick={() => {
176
+ setExpand((_expand) => !_expand);
177
+ }}
178
+ />
179
+ {isDrilldownObject && (
180
+ <IconButton
181
+ size="small"
182
+ theme="borderless"
183
+ icon={<IconAddChildren />}
184
+ onClick={() => {
185
+ onAddProperty();
186
+ setCollapse(true);
187
+ }}
188
+ />
189
+ )}
190
+ <IconButton
191
+ size="small"
192
+ theme="borderless"
193
+ icon={<IconMinus size="small" />}
194
+ onClick={onRemove}
195
+ />
196
+ </UIActions>
197
+ </UIRow>
198
+ {expand && (
199
+ <UIExpandDetail>
200
+ <UILabel>{config?.descTitle ?? 'Description'}</UILabel>
201
+ <BlurInput
202
+ size="small"
203
+ value={description}
204
+ onChange={(value) => onChange('description', value)}
205
+ placeholder={config?.descPlaceholder ?? 'Help LLM to understand the property'}
206
+ />
207
+ {$level === 0 && type && type !== 'array' && (
208
+ <>
209
+ <UILabel style={{ marginTop: 10 }}>
210
+ {config?.defaultValueTitle ?? 'Default Value'}
211
+ </UILabel>
212
+ <DefaultValueWrapper>
213
+ <DefaultValue
214
+ value={defaultValue}
215
+ schema={value}
216
+ type={type}
217
+ placeholder={config?.defaultValuePlaceholder}
218
+ jsonFormatText={config?.jsonFormatText}
219
+ onChange={(value) => onChange('default', value)}
220
+ />
221
+ </DefaultValueWrapper>
222
+ </>
223
+ )}
224
+ </UIExpandDetail>
225
+ )}
226
+ </UIPropertyMain>
227
+ {showCollapse && (
228
+ <UICollapsible $collapse={collapse}>
229
+ <UIProperties $shrink={true}>
230
+ {propertyList.map((_property, index) => (
231
+ <PropertyEdit
232
+ key={_property.key}
233
+ value={_property}
234
+ config={config}
235
+ $level={$level + 1} // 传递递增的层级
236
+ $parentExpand={expand}
237
+ $parentType={type}
238
+ onChange={(_v) => {
239
+ onEditProperty(_property.key!, _v);
240
+ }}
241
+ onRemove={() => {
242
+ onRemoveProperty(_property.key!);
243
+ }}
244
+ $isLast={index === propertyList.length - 1}
245
+ $isFirst={index === 0}
246
+ $index={index}
247
+ $showLine={true}
248
+ />
249
+ ))}
250
+ </UIProperties>
251
+ </UICollapsible>
252
+ )}
253
+ </UIPropertyRight>
254
+ </>
255
+ );
256
+ }
@@ -0,0 +1,235 @@
1
+ import React from 'react';
2
+
3
+ import styled, { css } from 'styled-components';
4
+ import Icon from '@douyinfe/semi-icons';
5
+
6
+ export const UIContainer = styled.div`
7
+ /* & .semi-input {
8
+ background-color: #fff;
9
+ border-radius: 6px;
10
+ height: 24px;
11
+ } */
12
+ `;
13
+
14
+ export const UIRow = styled.div`
15
+ display: flex;
16
+ align-items: center;
17
+ gap: 6px;
18
+ `;
19
+
20
+ export const UICollapseTrigger = styled.div`
21
+ cursor: pointer;
22
+ margin-right: 5px;
23
+ `;
24
+
25
+ export const UIExpandDetail = styled.div`
26
+ display: flex;
27
+ flex-direction: column;
28
+ `;
29
+
30
+ export const UILabel = styled.div`
31
+ font-size: 12px;
32
+ color: #999;
33
+ font-weight: 400;
34
+ margin-bottom: 2px;
35
+ `;
36
+
37
+ export const UIProperties = styled.div<{ $shrink?: boolean }>`
38
+ display: grid;
39
+ grid-template-columns: auto 1fr;
40
+
41
+ ${({ $shrink }) =>
42
+ $shrink &&
43
+ css`
44
+ padding-left: 10px;
45
+ margin-top: 10px;
46
+ `}
47
+ `;
48
+
49
+ export const UIPropertyLeft = styled.div<{
50
+ $isLast?: boolean;
51
+ $showLine?: boolean;
52
+ $isExpand?: boolean;
53
+ type?: string;
54
+ $isFirst?: boolean;
55
+ $index?: number;
56
+ $parentExpand?: boolean;
57
+ $parentType?: string;
58
+ }>`
59
+ grid-column: 1;
60
+ position: relative;
61
+ width: 16px;
62
+
63
+ ${({ $showLine, $isLast, $parentType }) => {
64
+ let height = '100%';
65
+ if ($parentType && $isLast) {
66
+ height = '24px';
67
+ }
68
+
69
+ return (
70
+ $showLine &&
71
+ css`
72
+ &::before {
73
+ /* 竖线 */
74
+ content: '';
75
+ height: ${height};
76
+ position: absolute;
77
+ left: -22px;
78
+ top: -16px;
79
+ width: 1px;
80
+ background: #d9d9d9;
81
+ display: block;
82
+ }
83
+
84
+ &::after {
85
+ /* 横线 */
86
+ content: '';
87
+ position: absolute;
88
+ left: -22px; // 横线起点和竖线对齐
89
+ top: 8px; // 跟随你的行高调整
90
+ width: 18px; // 横线长度
91
+ height: 1px;
92
+ background: #d9d9d9;
93
+ display: block;
94
+ }
95
+ `
96
+ );
97
+ }}
98
+ `;
99
+
100
+ export const UIPropertyRight = styled.div`
101
+ grid-column: 2;
102
+ margin-bottom: 10px;
103
+
104
+ &:last-child {
105
+ margin-bottom: 0px;
106
+ }
107
+ `;
108
+
109
+ export const UIPropertyMain = styled.div<{
110
+ $expand?: boolean;
111
+ type?: string;
112
+ $collapse?: boolean;
113
+ $showCollapse?: boolean;
114
+ }>`
115
+ display: flex;
116
+ flex-direction: column;
117
+ gap: 10px;
118
+ position: relative;
119
+
120
+ ${({ $expand, type, $collapse, $showCollapse }) => {
121
+ const beforeElement = `
122
+ &::before {
123
+ /* 竖线 */
124
+ content: '';
125
+ height: 100%;
126
+ position: absolute;
127
+ left: -12px;
128
+ top: 18px;
129
+ width: 1px;
130
+ background: #d9d9d9;
131
+ display: block;
132
+ }`;
133
+
134
+ return (
135
+ $expand &&
136
+ css`
137
+ background-color: #f5f5f5;
138
+ padding: 10px;
139
+ border-radius: 4px;
140
+
141
+ ${$showCollapse &&
142
+ $collapse &&
143
+ (type === 'array' || type === 'object') &&
144
+ css`
145
+ ${beforeElement}
146
+ `}
147
+ `
148
+ );
149
+ }}
150
+ `;
151
+
152
+ export const UICollapsible = styled.div<{ $collapse?: boolean }>`
153
+ display: none;
154
+
155
+ ${({ $collapse }) =>
156
+ $collapse &&
157
+ css`
158
+ display: block;
159
+ `}
160
+ `;
161
+
162
+ export const UIName = styled.div`
163
+ flex-grow: 1;
164
+ `;
165
+
166
+ export const UIType = styled.div``;
167
+
168
+ export const UIRequired = styled.div``;
169
+
170
+ export const UIActions = styled.div`
171
+ white-space: nowrap;
172
+ `;
173
+
174
+ const iconAddChildrenSvg = (
175
+ <svg
176
+ className="icon-icon icon-icon-coz_add_node "
177
+ width="1em"
178
+ height="1em"
179
+ viewBox="0 0 24 24"
180
+ fill="currentColor"
181
+ xmlns="http://www.w3.org/2000/svg"
182
+ >
183
+ <path
184
+ fillRule="evenodd"
185
+ clipRule="evenodd"
186
+ d="M11 6.49988C11 8.64148 9.50397 10.4337 7.49995 10.8884V15.4998C7.49995 16.0521 7.94767 16.4998 8.49995 16.4998H11.208C11.0742 16.8061 11 17.1443 11 17.4998C11 17.8554 11.0742 18.1936 11.208 18.4998H8.49995C6.8431 18.4998 5.49995 17.1567 5.49995 15.4998V10.8884C3.49599 10.4336 2 8.64145 2 6.49988C2 4.0146 4.01472 1.99988 6.5 1.99988C8.98528 1.99988 11 4.0146 11 6.49988ZM6.5 8.99988C7.88071 8.99988 9 7.88059 9 6.49988C9 5.11917 7.88071 3.99988 6.5 3.99988C5.11929 3.99988 4 5.11917 4 6.49988C4 7.88059 5.11929 8.99988 6.5 8.99988Z"
187
+ ></path>
188
+ <path d="M17.5 12.4999C18.0523 12.4999 18.5 12.9476 18.5 13.4999V16.4999H21.5C22.0523 16.4999 22.5 16.9476 22.5 17.4999C22.5 18.0522 22.0523 18.4999 21.5 18.4999H18.5V21.4999C18.5 22.0522 18.0523 22.4999 17.5 22.4999C16.9477 22.4999 16.5 22.0522 16.5 21.4999V18.4999H13.5C12.9477 18.4999 12.5 18.0522 12.5 17.4999C12.5 16.9476 12.9477 16.4999 13.5 16.4999H16.5V13.4999C16.5 12.9476 16.9477 12.4999 17.5 12.4999Z"></path>
189
+ </svg>
190
+ );
191
+
192
+ export const IconAddChildren = () => <Icon size="small" svg={iconAddChildrenSvg} />;
193
+
194
+ export const DefaultValueWrapper = styled.div`
195
+ margin: 0;
196
+ `;
197
+
198
+ export const JSONViewerWrapper = styled.div`
199
+ padding: 0 0 24px;
200
+ &:first-child {
201
+ margin-top: 0px;
202
+ }
203
+ `;
204
+
205
+ export const JSONHeader = styled.div`
206
+ display: flex;
207
+ justify-content: space-between;
208
+ align-items: center;
209
+ background-color: var(--semi-color-fill-0);
210
+ border-radius: 6px 6px 0 0;
211
+ height: 36px;
212
+ padding: 0 8px 0 12px;
213
+ `;
214
+
215
+ export const JSONHeaderLeft = styled.div`
216
+ display: flex;
217
+ align-items: center;
218
+ gap: 10px;
219
+ `;
220
+
221
+ export const JSONHeaderRight = styled.div`
222
+ display: flex;
223
+ align-items: center;
224
+ gap: 10px;
225
+ `;
226
+
227
+ export const ConstantInputWrapper = styled.div`
228
+ flex-grow: 1;
229
+
230
+ & .semi-tree-select,
231
+ & .semi-input-number,
232
+ & .semi-select {
233
+ width: 100%;
234
+ }
235
+ `;
@@ -0,0 +1,21 @@
1
+ import { IJsonSchema } from '../../typings';
2
+
3
+ export interface PropertyValueType extends IJsonSchema {
4
+ name?: string;
5
+ key?: number;
6
+ isPropertyRequired?: boolean;
7
+ }
8
+
9
+ export type PropertiesValueType = Pick<PropertyValueType, 'properties' | 'required'>;
10
+
11
+ export type JsonSchemaProperties = IJsonSchema['properties'];
12
+
13
+ export interface ConfigType {
14
+ placeholder?: string;
15
+ descTitle?: string;
16
+ descPlaceholder?: string;
17
+ defaultValueTitle?: string;
18
+ defaultValuePlaceholder?: string;
19
+ addButtonText?: string;
20
+ jsonFormatText?: string;
21
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Return the corresponding string description according to the type of the input value.根据输入值的类型返回对应的字符串描述。
3
+ * @param value - 需要判断类型的值。The value whose type needs to be judged.
4
+ * @returns 返回值的类型字符串 The type string of the return value('string', 'integer', 'number', 'boolean', 'object', 'array', 'other')。
5
+ */
6
+ export function getValueType(value: any): string {
7
+ const type = typeof value;
8
+
9
+ if (type === 'string') {
10
+ return 'string';
11
+ } else if (type === 'number') {
12
+ return Number.isInteger(value) ? 'integer' : 'number';
13
+ } else if (type === 'boolean') {
14
+ return 'boolean';
15
+ } else if (type === 'object') {
16
+ if (value === null) {
17
+ return 'other';
18
+ }
19
+ return Array.isArray(value) ? 'array' : 'object';
20
+ } else {
21
+ // undefined, function, symbol, bigint etc.
22
+ return 'other';
23
+ }
24
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "type-selector",
3
+ "depMaterials": ["typings/json-schema"],
4
+ "depPackages": ["@douyinfe/semi-ui", "@douyinfe/semi-icons"]
5
+ }