@flowgram.ai/form-materials 0.2.16 → 0.2.17
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/materials.ts +6 -1
- package/bin/project.ts +5 -0
- package/dist/esm/index.js +207 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +149 -6
- package/dist/index.d.ts +149 -6
- package/dist/index.js +202 -9
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/batch-outputs/config.json +12 -0
- package/src/components/batch-outputs/index.tsx +61 -0
- package/src/components/batch-outputs/styles.tsx +19 -0
- package/src/components/batch-outputs/types.ts +22 -0
- package/src/components/batch-outputs/use-list.ts +86 -0
- package/src/components/batch-variable-selector/index.tsx +5 -0
- package/src/components/condition-row/constants.ts +5 -0
- package/src/components/condition-row/hooks/useOp.tsx +5 -0
- package/src/components/condition-row/hooks/useRule.ts +5 -0
- package/src/components/condition-row/index.tsx +5 -0
- package/src/components/condition-row/styles.tsx +5 -0
- package/src/components/condition-row/types.ts +5 -0
- package/src/components/constant-input/index.tsx +5 -0
- package/src/components/constant-input/types.ts +5 -0
- package/src/components/dynamic-value-input/index.tsx +6 -0
- package/src/components/dynamic-value-input/styles.tsx +5 -0
- package/src/components/index.ts +6 -0
- package/src/components/json-schema-editor/components/blur-input.tsx +5 -0
- package/src/components/json-schema-editor/default-value.tsx +5 -0
- package/src/components/json-schema-editor/hooks.tsx +5 -0
- package/src/components/json-schema-editor/index.tsx +5 -0
- package/src/components/json-schema-editor/styles.tsx +5 -0
- package/src/components/json-schema-editor/types.ts +5 -0
- package/src/components/json-schema-editor/utils.ts +5 -0
- package/src/components/type-selector/constants.tsx +5 -0
- package/src/components/type-selector/index.tsx +5 -0
- package/src/components/variable-selector/index.tsx +7 -0
- package/src/components/variable-selector/styles.tsx +5 -0
- package/src/components/variable-selector/use-variable-tree.tsx +8 -3
- package/src/effects/auto-rename-ref/index.ts +5 -0
- package/src/effects/index.ts +5 -0
- package/src/effects/provide-batch-input/index.ts +5 -0
- package/src/effects/provide-batch-outputs/index.ts +5 -1
- package/src/effects/provide-json-schema-outputs/index.ts +5 -0
- package/src/effects/sync-variable-title/index.ts +5 -0
- package/src/form-plugins/batch-outputs-plugin/config.json +7 -0
- package/src/form-plugins/batch-outputs-plugin/index.ts +104 -0
- package/src/form-plugins/index.ts +6 -0
- package/src/index.ts +6 -0
- package/src/typings/flow-value/index.ts +5 -0
- package/src/typings/index.ts +5 -0
- package/src/typings/json-schema/index.ts +5 -0
- package/src/utils/format-legacy-refs/index.ts +5 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/json-schema/index.ts +6 -1
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.17",
|
|
4
4
|
"homepage": "https://flowgram.ai/",
|
|
5
5
|
"repository": "https://github.com/bytedance/flowgram.ai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"chalk": "^5.3.0",
|
|
31
31
|
"inquirer": "^9.2.7",
|
|
32
32
|
"immer": "~10.1.1",
|
|
33
|
-
"@flowgram.ai/editor": "0.2.
|
|
33
|
+
"@flowgram.ai/editor": "0.2.17"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/lodash": "^4.14.137",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"tsup": "^8.0.1",
|
|
47
47
|
"typescript": "^5.0.4",
|
|
48
48
|
"vitest": "^0.34.6",
|
|
49
|
-
"@flowgram.ai/eslint-config": "0.2.
|
|
50
|
-
"@flowgram.ai/ts-config": "0.2.
|
|
49
|
+
"@flowgram.ai/eslint-config": "0.2.17",
|
|
50
|
+
"@flowgram.ai/ts-config": "0.2.17"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"react": ">=16.8",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import { Button, Input } from '@douyinfe/semi-ui';
|
|
9
|
+
import { IconDelete, IconPlus } from '@douyinfe/semi-icons';
|
|
10
|
+
|
|
11
|
+
import { useList } from './use-list';
|
|
12
|
+
import { PropsType } from './types';
|
|
13
|
+
import { VariableSelector } from '../variable-selector';
|
|
14
|
+
import { UIRow, UIRows } from './styles';
|
|
15
|
+
|
|
16
|
+
export function BatchOutputs(props: PropsType) {
|
|
17
|
+
const { readonly, style } = props;
|
|
18
|
+
|
|
19
|
+
const { list, add, update, remove } = useList(props);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div>
|
|
23
|
+
<UIRows style={style}>
|
|
24
|
+
{list.map((item) => (
|
|
25
|
+
<UIRow key={item.id}>
|
|
26
|
+
<Input
|
|
27
|
+
style={{ width: 100 }}
|
|
28
|
+
disabled={readonly}
|
|
29
|
+
size="small"
|
|
30
|
+
value={item.key}
|
|
31
|
+
onChange={(v) => update({ ...item, key: v })}
|
|
32
|
+
/>
|
|
33
|
+
<VariableSelector
|
|
34
|
+
style={{ flexGrow: 1 }}
|
|
35
|
+
readonly={readonly}
|
|
36
|
+
value={item.value?.content}
|
|
37
|
+
onChange={(v) =>
|
|
38
|
+
update({
|
|
39
|
+
...item,
|
|
40
|
+
value: {
|
|
41
|
+
type: 'ref',
|
|
42
|
+
content: v,
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
/>
|
|
47
|
+
<Button
|
|
48
|
+
disabled={readonly}
|
|
49
|
+
icon={<IconDelete />}
|
|
50
|
+
size="small"
|
|
51
|
+
onClick={() => remove(item.id)}
|
|
52
|
+
/>
|
|
53
|
+
</UIRow>
|
|
54
|
+
))}
|
|
55
|
+
</UIRows>
|
|
56
|
+
<Button disabled={readonly} icon={<IconPlus />} size="small" onClick={add}>
|
|
57
|
+
Add
|
|
58
|
+
</Button>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import styled from 'styled-components';
|
|
7
|
+
|
|
8
|
+
export const UIRows = styled.div`
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
gap: 10px;
|
|
12
|
+
margin-bottom: 10px;
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
export const UIRow = styled.div`
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
gap: 5px;
|
|
19
|
+
`;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { IFlowRefValue } from '../../typings';
|
|
7
|
+
|
|
8
|
+
export type ValueType = Record<string, IFlowRefValue | undefined>;
|
|
9
|
+
|
|
10
|
+
export interface OutputItem {
|
|
11
|
+
id: number;
|
|
12
|
+
key?: string;
|
|
13
|
+
value?: IFlowRefValue;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface PropsType {
|
|
17
|
+
value?: ValueType;
|
|
18
|
+
onChange: (value?: ValueType) => void;
|
|
19
|
+
readonly?: boolean;
|
|
20
|
+
hasError?: boolean;
|
|
21
|
+
style?: React.CSSProperties;
|
|
22
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useEffect, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { difference } from 'lodash';
|
|
9
|
+
|
|
10
|
+
import { OutputItem, PropsType } from './types';
|
|
11
|
+
|
|
12
|
+
let _id = 0;
|
|
13
|
+
function genId() {
|
|
14
|
+
return _id++;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function useList({ value, onChange }: PropsType) {
|
|
18
|
+
const [list, setList] = useState<OutputItem[]>([]);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
setList((_prevList) => {
|
|
22
|
+
const newKeys = Object.keys(value || {});
|
|
23
|
+
const oldKeys = _prevList.map((item) => item.key).filter(Boolean) as string[];
|
|
24
|
+
const addKeys = difference(newKeys, oldKeys);
|
|
25
|
+
|
|
26
|
+
return _prevList
|
|
27
|
+
.filter((item) => !item.key || newKeys.includes(item.key))
|
|
28
|
+
.map((item) => ({
|
|
29
|
+
id: item.id,
|
|
30
|
+
key: item.key,
|
|
31
|
+
value: item.key ? value?.[item.key!] : undefined,
|
|
32
|
+
}))
|
|
33
|
+
.concat(
|
|
34
|
+
addKeys.map((_key) => ({
|
|
35
|
+
id: genId(),
|
|
36
|
+
key: _key,
|
|
37
|
+
value: value?.[_key],
|
|
38
|
+
}))
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
}, [value]);
|
|
42
|
+
|
|
43
|
+
const add = () => {
|
|
44
|
+
setList((prevList) => [
|
|
45
|
+
...prevList,
|
|
46
|
+
{
|
|
47
|
+
id: genId(),
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const update = (item: OutputItem) => {
|
|
53
|
+
setList((prevList) => {
|
|
54
|
+
const nextList = prevList.map((_item) => {
|
|
55
|
+
if (_item.id === item.id) {
|
|
56
|
+
return item;
|
|
57
|
+
}
|
|
58
|
+
return _item;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
onChange(
|
|
62
|
+
Object.fromEntries(
|
|
63
|
+
nextList.filter((item) => item.key).map((item) => [item.key!, item.value])
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return nextList;
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const remove = (itemId: number) => {
|
|
72
|
+
setList((prevList) => {
|
|
73
|
+
const nextList = prevList.filter((_item) => _item.id !== itemId);
|
|
74
|
+
|
|
75
|
+
onChange(
|
|
76
|
+
Object.fromEntries(
|
|
77
|
+
nextList.filter((item) => item.key).map((item) => [item.key!, item.value])
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return nextList;
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return { list, add, update, remove };
|
|
86
|
+
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import React, { useMemo } from 'react';
|
|
2
7
|
|
|
3
8
|
import { IconButton } from '@douyinfe/semi-ui';
|
|
@@ -19,6 +24,7 @@ interface PropsType {
|
|
|
19
24
|
schema?: IJsonSchema;
|
|
20
25
|
constantProps?: {
|
|
21
26
|
strategies?: Strategy[];
|
|
27
|
+
schema?: IJsonSchema; // set schema of constant input only
|
|
22
28
|
[key: string]: any;
|
|
23
29
|
};
|
|
24
30
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
export * from './variable-selector';
|
|
2
7
|
export * from './type-selector';
|
|
3
8
|
export * from './json-schema-editor';
|
|
@@ -5,3 +10,4 @@ export * from './batch-variable-selector';
|
|
|
5
10
|
export * from './constant-input';
|
|
6
11
|
export * from './dynamic-value-input';
|
|
7
12
|
export * from './condition-row';
|
|
13
|
+
export * from './batch-outputs';
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* Return the corresponding string description according to the type of the input value.根据输入值的类型返回对应的字符串描述。
|
|
3
8
|
* @param value - 需要判断类型的值。The value whose type needs to be judged.
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import React, { useMemo } from 'react';
|
|
2
7
|
|
|
3
8
|
import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
|
|
@@ -25,6 +30,8 @@ interface PropTypes {
|
|
|
25
30
|
|
|
26
31
|
export type VariableSelectorProps = PropTypes;
|
|
27
32
|
|
|
33
|
+
export { useVariableTree };
|
|
34
|
+
|
|
28
35
|
export const VariableSelector = ({
|
|
29
36
|
value,
|
|
30
37
|
config = {},
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import React, { useCallback } from 'react';
|
|
2
7
|
|
|
3
|
-
import {
|
|
8
|
+
import { ASTMatch, BaseVariableField, useAvailableVariables } from '@flowgram.ai/editor';
|
|
4
9
|
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
5
10
|
import { Icon } from '@douyinfe/semi-ui';
|
|
6
11
|
|
|
@@ -16,7 +21,7 @@ export function useVariableTree(params: {
|
|
|
16
21
|
}): TreeNodeData[] {
|
|
17
22
|
const { includeSchema, excludeSchema } = params;
|
|
18
23
|
|
|
19
|
-
const
|
|
24
|
+
const variables = useAvailableVariables();
|
|
20
25
|
|
|
21
26
|
const getVariableTypeIcon = useCallback((variable: VariableField) => {
|
|
22
27
|
if (variable.meta?.icon) {
|
|
@@ -92,7 +97,7 @@ export function useVariableTree(params: {
|
|
|
92
97
|
};
|
|
93
98
|
};
|
|
94
99
|
|
|
95
|
-
return [...
|
|
100
|
+
return [...variables.slice(0).reverse()]
|
|
96
101
|
.map((_variable) => renderVariable(_variable as VariableField))
|
|
97
102
|
.filter(Boolean) as TreeNodeData[];
|
|
98
103
|
}
|
package/src/effects/index.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import {
|
|
2
7
|
ASTFactory,
|
|
3
8
|
EffectOptions,
|
|
@@ -9,7 +14,6 @@ import {
|
|
|
9
14
|
import { IFlowRefValue } from '../../typings';
|
|
10
15
|
|
|
11
16
|
export const provideBatchOutputsEffect: EffectOptions[] = createEffectFromVariableProvider({
|
|
12
|
-
private: true,
|
|
13
17
|
parse: (value: Record<string, IFlowRefValue>, ctx) => [
|
|
14
18
|
ASTFactory.createVariableDeclaration({
|
|
15
19
|
key: `${ctx.node.id}`,
|