@flowgram.ai/form-materials 0.2.29 → 0.2.30
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 +116 -57
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +16 -3
- package/package.json +5 -5
- package/src/components/code-editor/index.tsx +7 -0
- package/src/components/code-editor/language-features.ts +22 -1
- package/src/components/condition-row/constants.ts +2 -8
- package/src/components/inputs-values/components/blur-input.tsx +27 -0
- package/src/components/inputs-values/index.tsx +16 -3
- package/src/components/inputs-values/types.ts +2 -1
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +6 -3
- package/src/components/variable-selector/index.tsx +4 -2
- package/src/components/variable-selector/use-variable-tree.tsx +6 -3
- package/src/hooks/use-object-list/index.tsx +16 -3
- package/src/typings/flow-value/index.ts +8 -0
- package/dist/index.d.ts +0 -540
- package/dist/index.js +0 -3632
- package/dist/index.js.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import React$1 from 'react';
|
|
|
2
2
|
import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
|
|
3
3
|
import { InferValues } from '@coze-editor/editor/react';
|
|
4
4
|
import preset from '@coze-editor/editor/preset-code';
|
|
5
|
-
import { EffectOptions, ASTNodeJSON, ASTNode, BaseType, FormPluginCreator } from '@flowgram.ai/editor';
|
|
5
|
+
import { BaseVariableField, EffectOptions, ASTNodeJSON, ASTNode, BaseType, FormPluginCreator } from '@flowgram.ai/editor';
|
|
6
6
|
import * as _flowgram_ai_node from '@flowgram.ai/node';
|
|
7
7
|
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
8
8
|
|
|
@@ -36,9 +36,14 @@ type IBasicJsonSchema = IJsonSchema<JsonSchemaBasicType>;
|
|
|
36
36
|
* SPDX-License-Identifier: MIT
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
|
+
type VariableField = BaseVariableField<{
|
|
40
|
+
icon?: string | JSX.Element;
|
|
41
|
+
title?: string;
|
|
42
|
+
}>;
|
|
39
43
|
declare function useVariableTree(params: {
|
|
40
44
|
includeSchema?: IJsonSchema | IJsonSchema[];
|
|
41
45
|
excludeSchema?: IJsonSchema | IJsonSchema[];
|
|
46
|
+
customSkip?: (variable: VariableField) => boolean;
|
|
42
47
|
}): TreeNodeData[];
|
|
43
48
|
|
|
44
49
|
/**
|
|
@@ -69,22 +74,29 @@ declare const VariableSelector: ({ value, config, onChange, style, readonly, inc
|
|
|
69
74
|
* SPDX-License-Identifier: MIT
|
|
70
75
|
*/
|
|
71
76
|
|
|
77
|
+
interface IFlowValueExtra {
|
|
78
|
+
index?: number;
|
|
79
|
+
}
|
|
72
80
|
interface IFlowConstantValue {
|
|
73
81
|
type: 'constant';
|
|
74
82
|
content?: string | number | boolean;
|
|
75
83
|
schema?: IJsonSchema;
|
|
84
|
+
extra?: IFlowValueExtra;
|
|
76
85
|
}
|
|
77
86
|
interface IFlowRefValue {
|
|
78
87
|
type: 'ref';
|
|
79
88
|
content?: string[];
|
|
89
|
+
extra?: IFlowValueExtra;
|
|
80
90
|
}
|
|
81
91
|
interface IFlowExpressionValue {
|
|
82
92
|
type: 'expression';
|
|
83
93
|
content?: string;
|
|
94
|
+
extra?: IFlowValueExtra;
|
|
84
95
|
}
|
|
85
96
|
interface IFlowTemplateValue {
|
|
86
97
|
type: 'template';
|
|
87
98
|
content?: string;
|
|
99
|
+
extra?: IFlowValueExtra;
|
|
88
100
|
}
|
|
89
101
|
type IFlowValue = IFlowConstantValue | IFlowRefValue | IFlowExpressionValue | IFlowTemplateValue;
|
|
90
102
|
type IFlowConstantRefValue = IFlowConstantValue | IFlowRefValue;
|
|
@@ -342,6 +354,7 @@ interface PropsType {
|
|
|
342
354
|
onChange: (value?: Record<string, IFlowValue | undefined>) => void;
|
|
343
355
|
readonly?: boolean;
|
|
344
356
|
hasError?: boolean;
|
|
357
|
+
schema?: IJsonSchema;
|
|
345
358
|
style?: React.CSSProperties;
|
|
346
359
|
constantProps?: {
|
|
347
360
|
strategies?: Strategy[];
|
|
@@ -354,7 +367,7 @@ interface PropsType {
|
|
|
354
367
|
* SPDX-License-Identifier: MIT
|
|
355
368
|
*/
|
|
356
369
|
|
|
357
|
-
declare function InputsValues({ value, onChange, style, readonly, constantProps }: PropsType): React$1.JSX.Element;
|
|
370
|
+
declare function InputsValues({ value, onChange, style, readonly, constantProps, schema, hasError, }: PropsType): React$1.JSX.Element;
|
|
358
371
|
|
|
359
372
|
/**
|
|
360
373
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
@@ -537,4 +550,4 @@ interface InputConfig {
|
|
|
537
550
|
}
|
|
538
551
|
declare const createInferInputsPlugin: _flowgram_ai_node.FormPluginCreator<InputConfig>;
|
|
539
552
|
|
|
540
|
-
export { ArrayIcons, BatchOutputs, BatchVariableSelector, CodeEditor, type CodeEditorPropsType, ConditionRow, type ConditionRowValueType, ConstantInput, DynamicValueInput, type IBasicJsonSchema, type IFlowConstantRefValue, type IFlowConstantValue, type IFlowExpressionValue, type IFlowRefValue, type IFlowTemplateValue, type IFlowValue, type IJsonSchema, InputsValues, JsonEditorWithVariables, type JsonSchemaBasicType, JsonSchemaEditor, JsonSchemaUtils, PromptEditor, type PromptEditorPropsType, PromptEditorWithInputs, PromptEditorWithVariables, TypeSelector, VariableSelector, type VariableSelectorProps, VariableTypeIcons, autoRenameRefEffect, createBatchOutputsFormPlugin, createInferInputsPlugin, formatLegacyRefOnInit, formatLegacyRefOnSubmit, formatLegacyRefToNewRef, formatNewRefToLegacyRef, getSchemaIcon, getTypeSelectValue, isLegacyFlowRefValueSchema, isNewFlowRefValueSchema, parseTypeSelectValue, provideBatchInputEffect, provideBatchOutputsEffect, provideJsonSchemaOutputs, syncVariableTitle, useVariableTree };
|
|
553
|
+
export { ArrayIcons, BatchOutputs, BatchVariableSelector, CodeEditor, type CodeEditorPropsType, ConditionRow, type ConditionRowValueType, ConstantInput, DynamicValueInput, type IBasicJsonSchema, type IFlowConstantRefValue, type IFlowConstantValue, type IFlowExpressionValue, type IFlowRefValue, type IFlowTemplateValue, type IFlowValue, type IFlowValueExtra, type IJsonSchema, InputsValues, JsonEditorWithVariables, type JsonSchemaBasicType, JsonSchemaEditor, JsonSchemaUtils, PromptEditor, type PromptEditorPropsType, PromptEditorWithInputs, PromptEditorWithVariables, TypeSelector, VariableSelector, type VariableSelectorProps, VariableTypeIcons, autoRenameRefEffect, createBatchOutputsFormPlugin, createInferInputsPlugin, formatLegacyRefOnInit, formatLegacyRefOnSubmit, formatLegacyRefToNewRef, formatNewRefToLegacyRef, getSchemaIcon, getTypeSelectValue, isLegacyFlowRefValueSchema, isNewFlowRefValueSchema, parseTypeSelectValue, provideBatchInputEffect, provideBatchOutputsEffect, provideJsonSchemaOutputs, syncVariableTitle, useVariableTree };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowgram.ai/form-materials",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.30",
|
|
4
4
|
"homepage": "https://flowgram.ai/",
|
|
5
5
|
"repository": "https://github.com/bytedance/flowgram.ai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@codemirror/view": "~6.38.0",
|
|
35
35
|
"@codemirror/state": "~6.5.2",
|
|
36
36
|
"typescript": "^5.8.3",
|
|
37
|
-
"@flowgram.ai/editor": "0.2.
|
|
37
|
+
"@flowgram.ai/editor": "0.2.30"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/lodash": "^4.14.137",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"tsup": "^8.0.1",
|
|
51
51
|
"typescript": "^5.8.3",
|
|
52
52
|
"vitest": "^0.34.6",
|
|
53
|
-
"@flowgram.ai/
|
|
54
|
-
"@flowgram.ai/
|
|
53
|
+
"@flowgram.ai/ts-config": "0.2.30",
|
|
54
|
+
"@flowgram.ai/eslint-config": "0.2.30"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"react": ">=16.8",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"build": "npm run build:fast -- --dts-resolve",
|
|
67
|
-
"build:fast": "tsup src/index.ts --format
|
|
67
|
+
"build:fast": "tsup src/index.ts --format esm --sourcemap --legacy-output",
|
|
68
68
|
"build:watch": "npm run build:fast -- --dts-resolve",
|
|
69
69
|
"clean": "rimraf dist",
|
|
70
70
|
"test": "exit 0",
|
|
@@ -15,6 +15,7 @@ import preset, { type EditorAPI } from '@coze-editor/editor/preset-code';
|
|
|
15
15
|
import { EditorView } from '@codemirror/view';
|
|
16
16
|
|
|
17
17
|
import { getSuffixByLanguageId } from './utils';
|
|
18
|
+
import { initTsWorker } from './language-features';
|
|
18
19
|
|
|
19
20
|
import './theme';
|
|
20
21
|
import './language-features';
|
|
@@ -54,6 +55,12 @@ export function CodeEditor({
|
|
|
54
55
|
}: CodeEditorPropsType) {
|
|
55
56
|
const editorRef = useRef<EditorAPI | null>(null);
|
|
56
57
|
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (languageId === 'typescript') {
|
|
60
|
+
initTsWorker();
|
|
61
|
+
}
|
|
62
|
+
}, [languageId]);
|
|
63
|
+
|
|
57
64
|
useEffect(() => {
|
|
58
65
|
// listen to value change
|
|
59
66
|
if (editorRef.current?.getValue() !== value) {
|
|
@@ -11,8 +11,8 @@ import { json } from '@coze-editor/editor/language-json';
|
|
|
11
11
|
import { mixLanguages } from '@coze-editor/editor';
|
|
12
12
|
|
|
13
13
|
languages.register('python', python);
|
|
14
|
-
languages.register('typescript', typescript);
|
|
15
14
|
languages.register('shell', shell);
|
|
15
|
+
languages.register('typescript', typescript);
|
|
16
16
|
|
|
17
17
|
languages.register('json', {
|
|
18
18
|
// mixLanguages is used to solve the problem that interpolation also uses parentheses, which causes incorrect highlighting
|
|
@@ -21,3 +21,24 @@ languages.register('json', {
|
|
|
21
21
|
}),
|
|
22
22
|
languageService: json.languageService,
|
|
23
23
|
});
|
|
24
|
+
|
|
25
|
+
let tsWorkerInit = false;
|
|
26
|
+
|
|
27
|
+
export const initTsWorker = () => {
|
|
28
|
+
if (tsWorkerInit) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
tsWorkerInit = true;
|
|
32
|
+
|
|
33
|
+
const tsWorker = new Worker(
|
|
34
|
+
new URL(`@coze-editor/editor/language-typescript/worker`, import.meta.url),
|
|
35
|
+
{ type: 'module' }
|
|
36
|
+
);
|
|
37
|
+
typescript.languageService.initialize(tsWorker, {
|
|
38
|
+
compilerOptions: {
|
|
39
|
+
// eliminate Promise error
|
|
40
|
+
lib: ['es2015', 'dom'],
|
|
41
|
+
noImplicitAny: false,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
};
|
|
@@ -13,8 +13,8 @@ export const rules: IRules = {
|
|
|
13
13
|
[Op.NOT_CONTAINS]: 'string',
|
|
14
14
|
[Op.IN]: 'array',
|
|
15
15
|
[Op.NIN]: 'array',
|
|
16
|
-
[Op.IS_EMPTY]:
|
|
17
|
-
[Op.IS_NOT_EMPTY]:
|
|
16
|
+
[Op.IS_EMPTY]: null,
|
|
17
|
+
[Op.IS_NOT_EMPTY]: null,
|
|
18
18
|
},
|
|
19
19
|
number: {
|
|
20
20
|
[Op.EQ]: 'number',
|
|
@@ -25,8 +25,6 @@ export const rules: IRules = {
|
|
|
25
25
|
[Op.LTE]: 'number',
|
|
26
26
|
[Op.IN]: 'array',
|
|
27
27
|
[Op.NIN]: 'array',
|
|
28
|
-
[Op.IS_EMPTY]: null,
|
|
29
|
-
[Op.IS_NOT_EMPTY]: null,
|
|
30
28
|
},
|
|
31
29
|
integer: {
|
|
32
30
|
[Op.EQ]: 'number',
|
|
@@ -37,8 +35,6 @@ export const rules: IRules = {
|
|
|
37
35
|
[Op.LTE]: 'number',
|
|
38
36
|
[Op.IN]: 'array',
|
|
39
37
|
[Op.NIN]: 'array',
|
|
40
|
-
[Op.IS_EMPTY]: null,
|
|
41
|
-
[Op.IS_NOT_EMPTY]: null,
|
|
42
38
|
},
|
|
43
39
|
boolean: {
|
|
44
40
|
[Op.EQ]: 'boolean',
|
|
@@ -47,8 +43,6 @@ export const rules: IRules = {
|
|
|
47
43
|
[Op.IS_FALSE]: null,
|
|
48
44
|
[Op.IN]: 'array',
|
|
49
45
|
[Op.NIN]: 'array',
|
|
50
|
-
[Op.IS_EMPTY]: null,
|
|
51
|
-
[Op.IS_NOT_EMPTY]: null,
|
|
52
46
|
},
|
|
53
47
|
object: {
|
|
54
48
|
[Op.IS_EMPTY]: null,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { useEffect, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import Input, { InputProps } from '@douyinfe/semi-ui/lib/es/input';
|
|
9
|
+
|
|
10
|
+
export function BlurInput(props: InputProps) {
|
|
11
|
+
const [value, setValue] = useState('');
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
setValue(props.value as string);
|
|
15
|
+
}, [props.value]);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<Input
|
|
19
|
+
{...props}
|
|
20
|
+
value={value}
|
|
21
|
+
onChange={(value) => {
|
|
22
|
+
setValue(value);
|
|
23
|
+
}}
|
|
24
|
+
onBlur={(e) => props.onChange?.(value, e)}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
-
import { Button, IconButton
|
|
8
|
+
import { Button, IconButton } from '@douyinfe/semi-ui';
|
|
9
9
|
import { IconDelete, IconPlus } from '@douyinfe/semi-icons';
|
|
10
10
|
|
|
11
11
|
import { PropsType } from './types';
|
|
@@ -13,11 +13,21 @@ import { DynamicValueInput } from '../dynamic-value-input';
|
|
|
13
13
|
import { IFlowConstantRefValue, IFlowValue } from '../../typings';
|
|
14
14
|
import { useObjectList } from '../../hooks';
|
|
15
15
|
import { UIRow, UIRows } from './styles';
|
|
16
|
+
import { BlurInput } from './components/blur-input';
|
|
16
17
|
|
|
17
|
-
export function InputsValues({
|
|
18
|
+
export function InputsValues({
|
|
19
|
+
value,
|
|
20
|
+
onChange,
|
|
21
|
+
style,
|
|
22
|
+
readonly,
|
|
23
|
+
constantProps,
|
|
24
|
+
schema,
|
|
25
|
+
hasError,
|
|
26
|
+
}: PropsType) {
|
|
18
27
|
const { list, updateKey, updateValue, remove, add } = useObjectList<IFlowValue | undefined>({
|
|
19
28
|
value,
|
|
20
29
|
onChange,
|
|
30
|
+
sortIndexKey: 'extra.index',
|
|
21
31
|
});
|
|
22
32
|
|
|
23
33
|
return (
|
|
@@ -25,18 +35,21 @@ export function InputsValues({ value, onChange, style, readonly, constantProps }
|
|
|
25
35
|
<UIRows style={style}>
|
|
26
36
|
{list.map((item) => (
|
|
27
37
|
<UIRow key={item.id}>
|
|
28
|
-
<
|
|
38
|
+
<BlurInput
|
|
29
39
|
style={{ width: 100, minWidth: 100, maxWidth: 100 }}
|
|
30
40
|
disabled={readonly}
|
|
31
41
|
size="small"
|
|
32
42
|
value={item.key}
|
|
33
43
|
onChange={(v) => updateKey(item.id, v)}
|
|
44
|
+
placeholder="Input Key"
|
|
34
45
|
/>
|
|
35
46
|
<DynamicValueInput
|
|
36
47
|
style={{ flexGrow: 1 }}
|
|
37
48
|
readonly={readonly}
|
|
38
49
|
value={item.value as IFlowConstantRefValue}
|
|
39
50
|
onChange={(v) => updateValue(item.id, v)}
|
|
51
|
+
schema={schema}
|
|
52
|
+
hasError={hasError}
|
|
40
53
|
constantProps={{
|
|
41
54
|
...constantProps,
|
|
42
55
|
strategies: [...(constantProps?.strategies || [])],
|
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { Strategy } from '../constant-input/types';
|
|
7
|
-
import { IFlowValue } from '../../typings';
|
|
7
|
+
import { IFlowValue, IJsonSchema } from '../../typings';
|
|
8
8
|
|
|
9
9
|
export interface PropsType {
|
|
10
10
|
value?: Record<string, IFlowValue | undefined>;
|
|
11
11
|
onChange: (value?: Record<string, IFlowValue | undefined>) => void;
|
|
12
12
|
readonly?: boolean;
|
|
13
13
|
hasError?: boolean;
|
|
14
|
+
schema?: IJsonSchema;
|
|
14
15
|
style?: React.CSSProperties;
|
|
15
16
|
constantProps?: {
|
|
16
17
|
strategies?: Strategy[];
|
|
@@ -67,10 +67,13 @@ class VariableTagWidget extends WidgetType {
|
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
const rootField = last(v.parentFields);
|
|
70
|
+
const rootField = last(v.parentFields) || v;
|
|
71
|
+
const isRoot = v.parentFields.length === 0;
|
|
71
72
|
|
|
72
73
|
const rootTitle = (
|
|
73
|
-
<UIRootTitle>
|
|
74
|
+
<UIRootTitle>
|
|
75
|
+
{rootField?.meta.title ? `${rootField.meta.title} ${isRoot ? '' : '-'} ` : ''}
|
|
76
|
+
</UIRootTitle>
|
|
74
77
|
);
|
|
75
78
|
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
76
79
|
|
|
@@ -86,7 +89,7 @@ class VariableTagWidget extends WidgetType {
|
|
|
86
89
|
>
|
|
87
90
|
<UITag prefixIcon={rootIcon}>
|
|
88
91
|
{rootTitle}
|
|
89
|
-
<UIVarName>{v?.key}</UIVarName>
|
|
92
|
+
{!isRoot && <UIVarName>{v?.key}</UIVarName>}
|
|
90
93
|
</UITag>
|
|
91
94
|
</Popover>
|
|
92
95
|
);
|
|
@@ -98,7 +98,9 @@ export const VariableSelector = ({
|
|
|
98
98
|
|
|
99
99
|
const rootTitle = (
|
|
100
100
|
<UIRootTitle>
|
|
101
|
-
{_option.rootMeta?.title
|
|
101
|
+
{_option.rootMeta?.title
|
|
102
|
+
? `${_option.rootMeta?.title} ${_option.isRoot ? '' : '-'} `
|
|
103
|
+
: null}
|
|
102
104
|
</UIRootTitle>
|
|
103
105
|
);
|
|
104
106
|
|
|
@@ -119,7 +121,7 @@ export const VariableSelector = ({
|
|
|
119
121
|
onClose={() => onChange(undefined)}
|
|
120
122
|
>
|
|
121
123
|
{rootTitle}
|
|
122
|
-
<UIVarName $inSelector>{_option.label}</UIVarName>
|
|
124
|
+
{!_option.isRoot && <UIVarName $inSelector>{_option.label}</UIVarName>}
|
|
123
125
|
</UITag>
|
|
124
126
|
</Popover>
|
|
125
127
|
</div>
|
|
@@ -18,8 +18,9 @@ type VariableField = BaseVariableField<{ icon?: string | JSX.Element; title?: st
|
|
|
18
18
|
export function useVariableTree(params: {
|
|
19
19
|
includeSchema?: IJsonSchema | IJsonSchema[];
|
|
20
20
|
excludeSchema?: IJsonSchema | IJsonSchema[];
|
|
21
|
+
customSkip?: (variable: VariableField) => boolean;
|
|
21
22
|
}): TreeNodeData[] {
|
|
22
|
-
const { includeSchema, excludeSchema } = params;
|
|
23
|
+
const { includeSchema, excludeSchema, customSkip } = params;
|
|
23
24
|
|
|
24
25
|
const variables = useAvailableVariables();
|
|
25
26
|
|
|
@@ -77,8 +78,9 @@ export function useVariableTree(params: {
|
|
|
77
78
|
const isSchemaExclude = excludeSchema
|
|
78
79
|
? JsonSchemaUtils.isASTMatchSchema(type, excludeSchema)
|
|
79
80
|
: false;
|
|
81
|
+
const isCustomSkip = customSkip ? customSkip(variable) : false;
|
|
80
82
|
|
|
81
|
-
const isSchemaMatch = isSchemaInclude && !isSchemaExclude;
|
|
83
|
+
const isSchemaMatch = isSchemaInclude && !isSchemaExclude && !isCustomSkip;
|
|
82
84
|
|
|
83
85
|
// If not match, and no children, return null
|
|
84
86
|
if (!isSchemaMatch && !children?.length) {
|
|
@@ -93,7 +95,8 @@ export function useVariableTree(params: {
|
|
|
93
95
|
icon: getVariableTypeIcon(variable),
|
|
94
96
|
children,
|
|
95
97
|
disabled: !isSchemaMatch,
|
|
96
|
-
rootMeta: parentFields[0]?.meta,
|
|
98
|
+
rootMeta: parentFields[0]?.meta || variable.meta,
|
|
99
|
+
isRoot: !parentFields?.length,
|
|
97
100
|
};
|
|
98
101
|
};
|
|
99
102
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { nanoid } from 'nanoid';
|
|
9
|
-
import { difference } from 'lodash';
|
|
9
|
+
import { difference, get, isObject, set } from 'lodash';
|
|
10
10
|
|
|
11
11
|
function genId() {
|
|
12
12
|
return nanoid();
|
|
@@ -23,15 +23,20 @@ type ObjectType<ValueType> = Record<string, ValueType | undefined>;
|
|
|
23
23
|
export function useObjectList<ValueType>({
|
|
24
24
|
value,
|
|
25
25
|
onChange,
|
|
26
|
+
sortIndexKey,
|
|
26
27
|
}: {
|
|
27
28
|
value?: ObjectType<ValueType>;
|
|
28
29
|
onChange: (value?: ObjectType<ValueType>) => void;
|
|
30
|
+
sortIndexKey?: string;
|
|
29
31
|
}) {
|
|
30
32
|
const [list, setList] = useState<ListItem<ValueType>[]>([]);
|
|
31
33
|
|
|
32
34
|
useEffect(() => {
|
|
33
35
|
setList((_prevList) => {
|
|
34
|
-
const newKeys = Object.
|
|
36
|
+
const newKeys = Object.entries(value || {})
|
|
37
|
+
.sort((a, b) => get(a[1], sortIndexKey || 0) - get(b[1], sortIndexKey || 0))
|
|
38
|
+
.map(([key]) => key);
|
|
39
|
+
|
|
35
40
|
const oldKeys = _prevList.map((item) => item.key).filter(Boolean) as string[];
|
|
36
41
|
const addKeys = difference(newKeys, oldKeys);
|
|
37
42
|
|
|
@@ -75,7 +80,15 @@ export function useObjectList<ValueType>({
|
|
|
75
80
|
|
|
76
81
|
onChange(
|
|
77
82
|
Object.fromEntries(
|
|
78
|
-
nextList
|
|
83
|
+
nextList
|
|
84
|
+
.filter((item) => item.key)
|
|
85
|
+
.map((item) => [item.key!, item.value])
|
|
86
|
+
.map((_res, idx) => {
|
|
87
|
+
if (isObject(_res[1]) && sortIndexKey) {
|
|
88
|
+
set(_res[1], sortIndexKey, idx);
|
|
89
|
+
}
|
|
90
|
+
return _res;
|
|
91
|
+
})
|
|
79
92
|
)
|
|
80
93
|
);
|
|
81
94
|
|
|
@@ -5,25 +5,33 @@
|
|
|
5
5
|
|
|
6
6
|
import { IJsonSchema } from '../json-schema';
|
|
7
7
|
|
|
8
|
+
export interface IFlowValueExtra {
|
|
9
|
+
index?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
export interface IFlowConstantValue {
|
|
9
13
|
type: 'constant';
|
|
10
14
|
content?: string | number | boolean;
|
|
11
15
|
schema?: IJsonSchema;
|
|
16
|
+
extra?: IFlowValueExtra;
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
export interface IFlowRefValue {
|
|
15
20
|
type: 'ref';
|
|
16
21
|
content?: string[];
|
|
22
|
+
extra?: IFlowValueExtra;
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
export interface IFlowExpressionValue {
|
|
20
26
|
type: 'expression';
|
|
21
27
|
content?: string;
|
|
28
|
+
extra?: IFlowValueExtra;
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
export interface IFlowTemplateValue {
|
|
25
32
|
type: 'template';
|
|
26
33
|
content?: string;
|
|
34
|
+
extra?: IFlowValueExtra;
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
export type IFlowValue =
|