@flowgram.ai/form-materials 0.4.1 → 0.4.2
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/esm/index.js +98 -51
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +155 -107
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/display-flow-value/index.tsx +2 -12
- package/src/components/display-inputs-values/index.tsx +44 -6
- package/src/components/dynamic-value-input/hooks.ts +23 -2
- package/src/components/dynamic-value-input/index.tsx +1 -1
- package/src/components/inputs-values-tree/hooks/use-child-list.tsx +7 -2
- package/src/components/inputs-values-tree/row.tsx +18 -8
- package/src/shared/flow-value/schema.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowgram.ai/form-materials",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"homepage": "https://flowgram.ai/",
|
|
5
5
|
"repository": "https://github.com/bytedance/flowgram.ai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"@codemirror/state": "~6.5.2",
|
|
36
36
|
"typescript": "^5.8.3",
|
|
37
37
|
"zod": "^3.24.4",
|
|
38
|
-
"@flowgram.ai/editor": "0.4.
|
|
39
|
-
"@flowgram.ai/json-schema": "0.4.
|
|
38
|
+
"@flowgram.ai/editor": "0.4.2",
|
|
39
|
+
"@flowgram.ai/json-schema": "0.4.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/lodash": "^4.14.137",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"tsup": "^8.0.1",
|
|
53
53
|
"typescript": "^5.8.3",
|
|
54
54
|
"vitest": "^0.34.6",
|
|
55
|
-
"@flowgram.ai/
|
|
56
|
-
"@flowgram.ai/
|
|
55
|
+
"@flowgram.ai/ts-config": "0.4.2",
|
|
56
|
+
"@flowgram.ai/eslint-config": "0.4.2"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"react": ">=16.8",
|
|
@@ -9,6 +9,7 @@ import { JsonSchemaTypeManager, JsonSchemaUtils } from '@flowgram.ai/json-schema
|
|
|
9
9
|
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
10
10
|
|
|
11
11
|
import { IFlowValue } from '@/typings';
|
|
12
|
+
import { FlowValueUtils } from '@/shared';
|
|
12
13
|
import { DisplaySchemaTag } from '@/components/display-schema-tag';
|
|
13
14
|
|
|
14
15
|
interface PropsType {
|
|
@@ -31,18 +32,7 @@ export function DisplayFlowValue({ value, title, showIconInTree }: PropsType) {
|
|
|
31
32
|
return { type: 'string' };
|
|
32
33
|
}
|
|
33
34
|
if (value?.type === 'constant') {
|
|
34
|
-
|
|
35
|
-
return value?.schema;
|
|
36
|
-
}
|
|
37
|
-
if (typeof value?.content === 'string') {
|
|
38
|
-
return { type: 'string' };
|
|
39
|
-
}
|
|
40
|
-
if (typeof value?.content === 'number') {
|
|
41
|
-
return { type: 'number' };
|
|
42
|
-
}
|
|
43
|
-
if (typeof value?.content === 'boolean') {
|
|
44
|
-
return { type: 'boolean' };
|
|
45
|
-
}
|
|
35
|
+
return FlowValueUtils.inferConstantJsonSchema(value);
|
|
46
36
|
}
|
|
47
37
|
|
|
48
38
|
return { type: 'unknown' };
|
|
@@ -3,15 +3,19 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import React from 'react';
|
|
6
|
+
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { isPlainObject } from 'lodash';
|
|
9
|
+
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
10
|
+
|
|
11
|
+
import { FlowValueUtils } from '@/shared';
|
|
9
12
|
import { DisplayFlowValue } from '@/components/display-flow-value';
|
|
10
13
|
|
|
11
14
|
import { DisplayInputsWrapper } from './styles';
|
|
15
|
+
import { DisplaySchemaTag } from '../display-schema-tag';
|
|
12
16
|
|
|
13
17
|
interface PropsType {
|
|
14
|
-
value?:
|
|
18
|
+
value?: any;
|
|
15
19
|
showIconInTree?: boolean;
|
|
16
20
|
}
|
|
17
21
|
|
|
@@ -20,9 +24,43 @@ export function DisplayInputsValues({ value, showIconInTree }: PropsType) {
|
|
|
20
24
|
|
|
21
25
|
return (
|
|
22
26
|
<DisplayInputsWrapper>
|
|
23
|
-
{childEntries.map(([key, value]) =>
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
{childEntries.map(([key, value]) => {
|
|
28
|
+
if (FlowValueUtils.isFlowValue(value)) {
|
|
29
|
+
return (
|
|
30
|
+
<DisplayFlowValue key={key} title={key} value={value} showIconInTree={showIconInTree} />
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (isPlainObject(value)) {
|
|
35
|
+
return (
|
|
36
|
+
<DisplayInputsValueAllInTag
|
|
37
|
+
key={key}
|
|
38
|
+
title={key}
|
|
39
|
+
value={value}
|
|
40
|
+
showIconInTree={showIconInTree}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return null;
|
|
46
|
+
})}
|
|
26
47
|
</DisplayInputsWrapper>
|
|
27
48
|
);
|
|
28
49
|
}
|
|
50
|
+
|
|
51
|
+
export function DisplayInputsValueAllInTag({
|
|
52
|
+
value,
|
|
53
|
+
title,
|
|
54
|
+
showIconInTree,
|
|
55
|
+
}: PropsType & {
|
|
56
|
+
title: string;
|
|
57
|
+
}) {
|
|
58
|
+
const available = useScopeAvailable();
|
|
59
|
+
|
|
60
|
+
const schema = useMemo(
|
|
61
|
+
() => FlowValueUtils.inferJsonSchema(value, available.scope),
|
|
62
|
+
[available.version, value]
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return <DisplaySchemaTag title={title} value={schema} showIconInTree={showIconInTree} />;
|
|
66
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { useMemo, useState } from 'react';
|
|
6
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
@@ -33,9 +33,30 @@ export function useSelectSchema(
|
|
|
33
33
|
defaultSelectSchema = value?.schema || defaultSelectSchema;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
const changeVersion = useRef(0);
|
|
37
|
+
const effectVersion = useRef(0);
|
|
38
|
+
|
|
36
39
|
const [selectSchema, setSelectSchema] = useState(defaultSelectSchema);
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
effectVersion.current += 1;
|
|
43
|
+
if (changeVersion.current === effectVersion.current) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
effectVersion.current = changeVersion.current;
|
|
47
|
+
|
|
48
|
+
if (value?.type === 'constant' && value?.schema) {
|
|
49
|
+
setSelectSchema(value?.schema);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}, [value]);
|
|
53
|
+
|
|
54
|
+
const setSelectSchemaWithVersionUpdate = (schema: IJsonSchema) => {
|
|
55
|
+
setSelectSchema(schema);
|
|
56
|
+
changeVersion.current += 1;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return [selectSchema, setSelectSchemaWithVersionUpdate] as const;
|
|
39
60
|
}
|
|
40
61
|
|
|
41
62
|
export function useIncludeSchema(schemaFromProps?: IJsonSchema) {
|
|
@@ -107,7 +107,6 @@ export function DynamicValueInput({
|
|
|
107
107
|
onChange={(_v) => onChange({ type: 'constant', content: _v, schema: constantSchema })}
|
|
108
108
|
schema={constantSchema || { type: 'string' }}
|
|
109
109
|
readonly={readonly}
|
|
110
|
-
strategies={[...(constantProps?.strategies || [])]}
|
|
111
110
|
fallbackRenderer={() => (
|
|
112
111
|
<InjectVariableSelector
|
|
113
112
|
style={{ width: '100%' }}
|
|
@@ -117,6 +116,7 @@ export function DynamicValueInput({
|
|
|
117
116
|
/>
|
|
118
117
|
)}
|
|
119
118
|
{...constantProps}
|
|
119
|
+
strategies={[...(constantProps?.strategies || [])]}
|
|
120
120
|
/>
|
|
121
121
|
);
|
|
122
122
|
};
|
|
@@ -21,6 +21,7 @@ export function useChildList(
|
|
|
21
21
|
onChange?: (value: any) => void
|
|
22
22
|
): {
|
|
23
23
|
canAddField: boolean;
|
|
24
|
+
hasChildren: boolean;
|
|
24
25
|
list: ListItem[];
|
|
25
26
|
add: (key?: string) => void;
|
|
26
27
|
updateKey: (id: string, key: string) => void;
|
|
@@ -50,8 +51,6 @@ export function useChildList(
|
|
|
50
51
|
return undefined;
|
|
51
52
|
}, [value]);
|
|
52
53
|
|
|
53
|
-
console.log('debugger objectListValue', objectListValue);
|
|
54
|
-
|
|
55
54
|
const { list, add, updateKey, updateValue, remove } = useObjectList<any>({
|
|
56
55
|
value: objectListValue,
|
|
57
56
|
onChange: (value) => {
|
|
@@ -60,8 +59,14 @@ export function useChildList(
|
|
|
60
59
|
sortIndexKey: (value) => (FlowValueUtils.isFlowValue(value) ? 'extra.index' : ''),
|
|
61
60
|
});
|
|
62
61
|
|
|
62
|
+
const hasChildren = useMemo(
|
|
63
|
+
() => canAddField && (list.length > 0 || Object.keys(objectListValue || {}).length > 0),
|
|
64
|
+
[canAddField, list.length, Object.keys(objectListValue || {}).length]
|
|
65
|
+
);
|
|
66
|
+
|
|
63
67
|
return {
|
|
64
68
|
canAddField,
|
|
69
|
+
hasChildren,
|
|
65
70
|
list,
|
|
66
71
|
add,
|
|
67
72
|
updateKey,
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import React, { useState } from 'react';
|
|
6
|
+
import React, { useMemo, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { I18n } from '@flowgram.ai/editor';
|
|
9
9
|
import { IconButton, Input } from '@douyinfe/semi-ui';
|
|
10
10
|
import { IconChevronDown, IconChevronRight, IconDelete } from '@douyinfe/semi-icons';
|
|
11
11
|
|
|
12
|
+
import { IFlowConstantValue } from '@/typings';
|
|
12
13
|
import { ConstantInputStrategy } from '@/components/constant-input';
|
|
13
14
|
|
|
14
15
|
import { PropsType } from './types';
|
|
@@ -64,14 +65,26 @@ export function InputValueRow(
|
|
|
64
65
|
} = props;
|
|
65
66
|
const [collapse, setCollapse] = useState(false);
|
|
66
67
|
|
|
67
|
-
const { canAddField, list, add, updateKey, updateValue, remove } = useChildList(
|
|
68
|
+
const { canAddField, hasChildren, list, add, updateKey, updateValue, remove } = useChildList(
|
|
68
69
|
value,
|
|
69
70
|
onUpdateValue
|
|
70
71
|
);
|
|
71
72
|
|
|
72
|
-
const
|
|
73
|
+
const strategies = useMemo(
|
|
74
|
+
() => [...(hasChildren ? [AddObjectChildStrategy] : []), ...(constantProps?.strategies || [])],
|
|
75
|
+
[hasChildren, constantProps?.strategies]
|
|
76
|
+
);
|
|
73
77
|
|
|
74
|
-
const flowDisplayValue =
|
|
78
|
+
const flowDisplayValue = useMemo(
|
|
79
|
+
() =>
|
|
80
|
+
hasChildren
|
|
81
|
+
? ({
|
|
82
|
+
type: 'constant',
|
|
83
|
+
schema: { type: 'object' },
|
|
84
|
+
} as IFlowConstantValue)
|
|
85
|
+
: value,
|
|
86
|
+
[hasChildren, value]
|
|
87
|
+
);
|
|
75
88
|
|
|
76
89
|
return (
|
|
77
90
|
<>
|
|
@@ -101,10 +114,7 @@ export function InputValueRow(
|
|
|
101
114
|
hasError={hasError}
|
|
102
115
|
constantProps={{
|
|
103
116
|
...constantProps,
|
|
104
|
-
strategies
|
|
105
|
-
...(hasChildren ? [AddObjectChildStrategy] : []),
|
|
106
|
-
...(constantProps?.strategies || []),
|
|
107
|
-
],
|
|
117
|
+
strategies,
|
|
108
118
|
}}
|
|
109
119
|
/>
|
|
110
120
|
<UIActions>
|
|
@@ -14,7 +14,7 @@ export const extraSchema = z
|
|
|
14
14
|
|
|
15
15
|
export const constantSchema = z.object({
|
|
16
16
|
type: z.literal('constant'),
|
|
17
|
-
content: z.
|
|
17
|
+
content: z.any().optional(),
|
|
18
18
|
schema: z.any().optional(),
|
|
19
19
|
extra: extraSchema,
|
|
20
20
|
});
|