@flowgram.ai/form-materials 0.1.0-alpha.10 → 0.1.0-alpha.12
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.ts +11 -5
- package/bin/materials.ts +10 -1
- package/dist/esm/index.js +1996 -1361
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +328 -114
- package/dist/index.d.ts +328 -114
- package/dist/index.js +2096 -1472
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
- package/src/components/assign-row/components/blur-input.tsx +27 -0
- package/src/components/assign-row/config.json +11 -0
- package/src/components/assign-row/index.tsx +84 -0
- package/src/components/assign-row/types.ts +25 -0
- package/src/components/assign-rows/config.json +11 -0
- package/src/components/assign-rows/index.tsx +59 -0
- package/src/components/batch-outputs/config.json +2 -1
- package/src/components/batch-outputs/index.tsx +4 -12
- package/src/components/batch-variable-selector/config.json +6 -2
- package/src/components/batch-variable-selector/index.tsx +1 -1
- package/src/components/code-editor/config.json +2 -1
- package/src/components/code-editor/index.tsx +23 -1
- package/src/components/code-editor/language-features.ts +23 -3
- package/src/components/code-editor/theme/light.ts +2 -2
- package/src/components/code-editor-mini/config.json +7 -0
- package/src/components/code-editor-mini/index.tsx +31 -0
- package/src/components/condition-row/config.json +10 -2
- package/src/components/condition-row/constants.ts +6 -8
- package/src/components/condition-row/hooks/useOp.tsx +3 -1
- package/src/components/condition-row/hooks/useRule.ts +2 -2
- package/src/components/condition-row/index.tsx +2 -1
- package/src/components/condition-row/types.ts +3 -1
- package/src/components/constant-input/config.json +6 -3
- package/src/components/constant-input/index.tsx +18 -62
- package/src/components/constant-input/types.ts +6 -9
- package/src/components/display-flow-value/config.json +8 -0
- package/src/components/display-flow-value/index.tsx +59 -0
- package/src/components/display-inputs-values/config.json +9 -0
- package/src/components/display-inputs-values/index.tsx +27 -0
- package/src/components/display-inputs-values/styles.ts +12 -0
- package/src/components/display-outputs/config.json +10 -0
- package/src/components/display-outputs/index.tsx +64 -0
- package/src/components/display-outputs/styles.ts +12 -0
- package/src/components/display-schema-tag/config.json +10 -0
- package/src/components/display-schema-tag/index.tsx +44 -0
- package/src/components/display-schema-tag/styles.ts +28 -0
- package/src/components/display-schema-tree/config.json +11 -0
- package/src/components/display-schema-tree/index.tsx +74 -0
- package/src/components/display-schema-tree/styles.tsx +90 -0
- package/src/components/dynamic-value-input/config.json +11 -2
- package/src/components/dynamic-value-input/hooks.ts +53 -0
- package/src/components/dynamic-value-input/index.tsx +64 -13
- package/src/components/dynamic-value-input/styles.tsx +28 -2
- package/src/components/index.ts +9 -0
- package/src/components/inputs-values/components/blur-input.tsx +27 -0
- package/src/components/inputs-values/config.json +13 -0
- package/src/components/inputs-values/index.tsx +73 -0
- package/src/components/inputs-values/styles.tsx +19 -0
- package/src/components/inputs-values/types.ts +22 -0
- package/src/components/json-editor-with-variables/index.tsx +47 -1
- package/src/components/json-schema-editor/config.json +2 -2
- package/src/components/json-schema-editor/default-value.tsx +1 -1
- package/src/components/json-schema-editor/hooks.tsx +4 -2
- package/src/components/json-schema-editor/index.tsx +15 -2
- package/src/components/json-schema-editor/types.ts +1 -1
- package/src/components/prompt-editor/index.tsx +2 -1
- package/src/components/prompt-editor/types.tsx +1 -0
- package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +1 -1
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +6 -3
- package/src/components/type-selector/config.json +6 -2
- package/src/components/type-selector/index.tsx +55 -12
- package/src/components/variable-selector/config.json +6 -2
- package/src/components/variable-selector/index.tsx +34 -13
- package/src/components/variable-selector/styles.tsx +18 -8
- package/src/components/variable-selector/use-variable-tree.tsx +19 -22
- package/src/effects/auto-rename-ref/index.ts +59 -8
- package/src/effects/index.ts +3 -1
- package/src/effects/listen-ref-schema-change/config.json +10 -0
- package/src/effects/listen-ref-schema-change/index.ts +56 -0
- package/src/effects/listen-ref-value-change/config.json +9 -0
- package/src/effects/listen-ref-value-change/index.ts +53 -0
- package/src/effects/provide-json-schema-outputs/config.json +4 -5
- package/src/effects/provide-json-schema-outputs/index.ts +1 -3
- package/src/effects/sync-variable-title/index.ts +1 -0
- package/src/effects/validate-when-variable-sync/config.json +5 -0
- package/src/effects/validate-when-variable-sync/index.ts +35 -0
- package/src/form-plugins/index.ts +3 -1
- package/src/form-plugins/infer-assign-plugin/config.json +7 -0
- package/src/form-plugins/infer-assign-plugin/index.ts +90 -0
- package/src/form-plugins/infer-inputs-plugin/config.json +9 -0
- package/src/form-plugins/infer-inputs-plugin/index.ts +108 -0
- package/src/hooks/index.tsx +6 -0
- package/src/hooks/use-object-list/config.json +8 -0
- package/src/hooks/use-object-list/index.tsx +136 -0
- package/src/index.ts +3 -1
- package/src/{typings/json-schema → plugins/disable-declaration-plugin}/config.json +1 -1
- package/src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts +31 -0
- package/src/plugins/disable-declaration-plugin/index.tsx +6 -0
- package/src/plugins/index.ts +7 -0
- package/src/plugins/json-schema-preset/config.json +9 -0
- package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +28 -0
- package/src/plugins/json-schema-preset/index.tsx +41 -0
- package/src/plugins/json-schema-preset/manager.ts +18 -0
- package/src/plugins/json-schema-preset/type-definition/array.tsx +24 -0
- package/src/plugins/json-schema-preset/type-definition/boolean.tsx +32 -0
- package/src/plugins/json-schema-preset/type-definition/index.tsx +24 -0
- package/src/plugins/json-schema-preset/type-definition/integer.tsx +24 -0
- package/src/plugins/json-schema-preset/type-definition/number.tsx +24 -0
- package/src/plugins/json-schema-preset/type-definition/object.tsx +24 -0
- package/src/plugins/json-schema-preset/type-definition/string.tsx +18 -0
- package/src/{utils → shared}/index.ts +0 -1
- package/src/typings/flow-value/config.json +3 -1
- package/src/typings/flow-value/index.ts +11 -0
- package/src/typings/index.ts +0 -1
- package/src/validate/index.tsx +6 -0
- package/src/validate/validate-flow-value/config.json +7 -0
- package/src/validate/validate-flow-value/index.tsx +73 -0
- package/src/components/batch-outputs/use-list.ts +0 -86
- package/src/components/type-selector/constants.tsx +0 -364
- package/src/effects/provide-batch-outputs/config.json +0 -5
- package/src/effects/provide-batch-outputs/index.ts +0 -38
- package/src/typings/json-schema/index.ts +0 -36
- package/src/utils/json-schema/config.json +0 -5
- package/src/utils/json-schema/index.ts +0 -180
- /package/src/{utils → shared}/format-legacy-refs/config.json +0 -0
- /package/src/{utils → shared}/format-legacy-refs/index.ts +0 -0
- /package/src/{utils → shared}/format-legacy-refs/readme.md +0 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { set, uniqBy } from 'lodash';
|
|
7
|
+
import { JsonSchemaUtils } from '@flowgram.ai/json-schema';
|
|
8
|
+
import {
|
|
9
|
+
ASTFactory,
|
|
10
|
+
createEffectFromVariableProvider,
|
|
11
|
+
defineFormPluginCreator,
|
|
12
|
+
FlowNodeRegistry,
|
|
13
|
+
getNodeForm,
|
|
14
|
+
getNodeScope,
|
|
15
|
+
} from '@flowgram.ai/editor';
|
|
16
|
+
|
|
17
|
+
import { IFlowRefValue, IFlowValue } from '../../typings';
|
|
18
|
+
|
|
19
|
+
type AssignValueType =
|
|
20
|
+
| {
|
|
21
|
+
operator: 'assign';
|
|
22
|
+
left?: IFlowRefValue;
|
|
23
|
+
right?: IFlowValue;
|
|
24
|
+
}
|
|
25
|
+
| {
|
|
26
|
+
operator: 'declare';
|
|
27
|
+
left?: string;
|
|
28
|
+
right?: IFlowValue;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
interface InputConfig {
|
|
32
|
+
assignKey: string;
|
|
33
|
+
outputKey: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const createInferAssignPlugin = defineFormPluginCreator<InputConfig>({
|
|
37
|
+
onSetupFormMeta({ addFormatOnSubmit, mergeEffect }, { assignKey, outputKey }) {
|
|
38
|
+
if (!assignKey || !outputKey) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
mergeEffect({
|
|
43
|
+
[assignKey]: createEffectFromVariableProvider({
|
|
44
|
+
parse: (value: AssignValueType[], ctx) => {
|
|
45
|
+
const declareRows = uniqBy(
|
|
46
|
+
value.filter((_v) => _v.operator === 'declare' && _v.left && _v.right),
|
|
47
|
+
'left'
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return [
|
|
51
|
+
ASTFactory.createVariableDeclaration({
|
|
52
|
+
key: `${ctx.node.id}`,
|
|
53
|
+
meta: {
|
|
54
|
+
title: getNodeForm(ctx.node)?.getValueIn('title'),
|
|
55
|
+
icon: ctx.node.getNodeRegistry<FlowNodeRegistry>().info?.icon,
|
|
56
|
+
},
|
|
57
|
+
type: ASTFactory.createObject({
|
|
58
|
+
properties: declareRows.map((_v) =>
|
|
59
|
+
ASTFactory.createProperty({
|
|
60
|
+
key: _v.left as string,
|
|
61
|
+
type:
|
|
62
|
+
_v.right?.type === 'constant'
|
|
63
|
+
? JsonSchemaUtils.schemaToAST(_v.right?.schema || {})
|
|
64
|
+
: undefined,
|
|
65
|
+
initializer:
|
|
66
|
+
_v.right?.type === 'ref'
|
|
67
|
+
? ASTFactory.createKeyPathExpression({
|
|
68
|
+
keyPath: _v.right?.content || [],
|
|
69
|
+
})
|
|
70
|
+
: {},
|
|
71
|
+
})
|
|
72
|
+
),
|
|
73
|
+
}),
|
|
74
|
+
}),
|
|
75
|
+
];
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
addFormatOnSubmit((formData, ctx) => {
|
|
81
|
+
set(
|
|
82
|
+
formData,
|
|
83
|
+
outputKey,
|
|
84
|
+
JsonSchemaUtils.astToSchema(getNodeScope(ctx.node).output.variables?.[0]?.type)
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return formData;
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { get, set } from 'lodash';
|
|
7
|
+
import { JsonSchemaUtils, IJsonSchema } from '@flowgram.ai/json-schema';
|
|
8
|
+
import {
|
|
9
|
+
defineFormPluginCreator,
|
|
10
|
+
getNodePrivateScope,
|
|
11
|
+
getNodeScope,
|
|
12
|
+
Scope,
|
|
13
|
+
} from '@flowgram.ai/editor';
|
|
14
|
+
|
|
15
|
+
import { IFlowConstantValue, IFlowRefValue, IFlowTemplateValue } from '../../typings';
|
|
16
|
+
|
|
17
|
+
interface InputConfig {
|
|
18
|
+
sourceKey: string;
|
|
19
|
+
targetKey: string;
|
|
20
|
+
scope?: 'private' | 'public';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const createInferInputsPlugin = defineFormPluginCreator<InputConfig>({
|
|
24
|
+
onSetupFormMeta({ addFormatOnSubmit }, { sourceKey, targetKey, scope }) {
|
|
25
|
+
if (!sourceKey || !targetKey) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
addFormatOnSubmit((formData, ctx) => {
|
|
30
|
+
set(
|
|
31
|
+
formData,
|
|
32
|
+
targetKey,
|
|
33
|
+
infer(
|
|
34
|
+
get(formData, sourceKey),
|
|
35
|
+
scope === 'private' ? getNodePrivateScope(ctx.node) : getNodeScope(ctx.node)
|
|
36
|
+
)
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return formData;
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
function isRef(value: any): value is IFlowRefValue {
|
|
45
|
+
return (
|
|
46
|
+
value?.type === 'ref' && Array.isArray(value?.content) && typeof value?.content[0] === 'string'
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function isTemplate(value: any): value is IFlowTemplateValue {
|
|
51
|
+
return value?.type === 'template' && typeof value?.content === 'string';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isConstant(value: any): value is IFlowConstantValue {
|
|
55
|
+
return value?.type === 'constant' && typeof value?.content !== 'undefined';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const infer = (values: any, scope: Scope): IJsonSchema | undefined => {
|
|
59
|
+
if (typeof values === 'object') {
|
|
60
|
+
if (isConstant(values)) {
|
|
61
|
+
if (values?.schema) {
|
|
62
|
+
return values.schema;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (typeof values.content === 'string') {
|
|
66
|
+
return {
|
|
67
|
+
type: 'string',
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (typeof values.content === 'number') {
|
|
72
|
+
return {
|
|
73
|
+
type: 'number',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (typeof values.content === 'boolean') {
|
|
78
|
+
return {
|
|
79
|
+
type: 'boolean',
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (isRef(values)) {
|
|
85
|
+
const variable = scope.available.getByKeyPath(values?.content);
|
|
86
|
+
const schema = variable?.type ? JsonSchemaUtils.astToSchema(variable?.type) : undefined;
|
|
87
|
+
|
|
88
|
+
return schema;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (isTemplate(values)) {
|
|
92
|
+
return {
|
|
93
|
+
type: 'string',
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
type: 'object',
|
|
99
|
+
properties: Object.keys(values).reduce((acc, key) => {
|
|
100
|
+
const schema = infer(values[key], scope);
|
|
101
|
+
if (schema) {
|
|
102
|
+
acc[key] = schema;
|
|
103
|
+
}
|
|
104
|
+
return acc;
|
|
105
|
+
}, {} as Record<string, IJsonSchema>),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
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 { nanoid } from 'nanoid';
|
|
9
|
+
import { difference, get, isObject, set } from 'lodash';
|
|
10
|
+
|
|
11
|
+
function genId() {
|
|
12
|
+
return nanoid();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ListItem<ValueType> {
|
|
16
|
+
id: string;
|
|
17
|
+
key?: string;
|
|
18
|
+
value?: ValueType;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type ObjectType<ValueType> = Record<string, ValueType | undefined>;
|
|
22
|
+
|
|
23
|
+
export function useObjectList<ValueType>({
|
|
24
|
+
value,
|
|
25
|
+
onChange,
|
|
26
|
+
sortIndexKey,
|
|
27
|
+
}: {
|
|
28
|
+
value?: ObjectType<ValueType>;
|
|
29
|
+
onChange: (value?: ObjectType<ValueType>) => void;
|
|
30
|
+
sortIndexKey?: string;
|
|
31
|
+
}) {
|
|
32
|
+
const [list, setList] = useState<ListItem<ValueType>[]>([]);
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
setList((_prevList) => {
|
|
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
|
+
|
|
40
|
+
const oldKeys = _prevList.map((item) => item.key).filter(Boolean) as string[];
|
|
41
|
+
const addKeys = difference(newKeys, oldKeys);
|
|
42
|
+
|
|
43
|
+
return _prevList
|
|
44
|
+
.filter((item) => !item.key || newKeys.includes(item.key))
|
|
45
|
+
.map((item) => ({
|
|
46
|
+
id: item.id,
|
|
47
|
+
key: item.key,
|
|
48
|
+
value: item.key ? value?.[item.key!] : item.value,
|
|
49
|
+
}))
|
|
50
|
+
.concat(
|
|
51
|
+
addKeys.map((_key) => ({
|
|
52
|
+
id: genId(),
|
|
53
|
+
key: _key,
|
|
54
|
+
value: value?.[_key],
|
|
55
|
+
}))
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
}, [value]);
|
|
59
|
+
|
|
60
|
+
const add = () => {
|
|
61
|
+
setList((prevList) => [
|
|
62
|
+
...prevList,
|
|
63
|
+
{
|
|
64
|
+
id: genId(),
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const updateValue = (itemId: string, value: ValueType) => {
|
|
70
|
+
setList((prevList) => {
|
|
71
|
+
const nextList = prevList.map((_item) => {
|
|
72
|
+
if (_item.id === itemId) {
|
|
73
|
+
return {
|
|
74
|
+
..._item,
|
|
75
|
+
value,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return _item;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
onChange(
|
|
82
|
+
Object.fromEntries(
|
|
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
|
+
})
|
|
92
|
+
)
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
return nextList;
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const updateKey = (itemId: string, key: string) => {
|
|
100
|
+
setList((prevList) => {
|
|
101
|
+
const nextList = prevList.map((_item) => {
|
|
102
|
+
if (_item.id === itemId) {
|
|
103
|
+
return {
|
|
104
|
+
..._item,
|
|
105
|
+
key,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return _item;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
onChange(
|
|
112
|
+
Object.fromEntries(
|
|
113
|
+
nextList.filter((item) => item.key).map((item) => [item.key!, item.value])
|
|
114
|
+
)
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
return nextList;
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const remove = (itemId: string) => {
|
|
122
|
+
setList((prevList) => {
|
|
123
|
+
const nextList = prevList.filter((_item) => _item.id !== itemId);
|
|
124
|
+
|
|
125
|
+
onChange(
|
|
126
|
+
Object.fromEntries(
|
|
127
|
+
nextList.filter((item) => item.key).map((item) => [item.key!, item.value])
|
|
128
|
+
)
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
return nextList;
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
return { list, add, updateKey, updateValue, remove };
|
|
136
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
ASTMatch,
|
|
8
|
+
definePluginCreator,
|
|
9
|
+
type GlobalEventActionType,
|
|
10
|
+
VariableEngine,
|
|
11
|
+
} from '@flowgram.ai/editor';
|
|
12
|
+
|
|
13
|
+
export const createDisableDeclarationPlugin = definePluginCreator<void>({
|
|
14
|
+
onInit(ctx) {
|
|
15
|
+
const variableEngine = ctx.get(VariableEngine);
|
|
16
|
+
|
|
17
|
+
const handleEvent = (action: GlobalEventActionType) => {
|
|
18
|
+
if (ASTMatch.isVariableDeclaration(action.ast)) {
|
|
19
|
+
if (!action.ast.meta?.disabled) {
|
|
20
|
+
action.ast.updateMeta({
|
|
21
|
+
...(action.ast.meta || {}),
|
|
22
|
+
disabled: true,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
variableEngine.onGlobalEvent('NewAST', handleEvent);
|
|
29
|
+
variableEngine.onGlobalEvent('UpdateAST', handleEvent);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
BaseTypeManager,
|
|
8
|
+
jsonSchemaContainerModule,
|
|
9
|
+
JsonSchemaTypeManager,
|
|
10
|
+
} from '@flowgram.ai/json-schema';
|
|
11
|
+
import { definePluginCreator } from '@flowgram.ai/editor';
|
|
12
|
+
|
|
13
|
+
import { jsonSchemaTypePreset } from './type-definition';
|
|
14
|
+
import { JsonSchemaTypeRegistry } from './manager';
|
|
15
|
+
|
|
16
|
+
export const createTypePresetPlugin = definePluginCreator<{
|
|
17
|
+
types?: Partial<JsonSchemaTypeRegistry> & Pick<JsonSchemaTypeRegistry, 'type'>[];
|
|
18
|
+
unregisterTypes?: string[];
|
|
19
|
+
}>({
|
|
20
|
+
onInit(ctx, opts) {
|
|
21
|
+
const typeManager = ctx.get(BaseTypeManager) as JsonSchemaTypeManager;
|
|
22
|
+
jsonSchemaTypePreset.forEach((_type) => typeManager.register(_type));
|
|
23
|
+
|
|
24
|
+
opts.types?.forEach((_type) => typeManager.register(_type));
|
|
25
|
+
opts.unregisterTypes?.forEach((_type) => typeManager.unregister(_type));
|
|
26
|
+
},
|
|
27
|
+
containerModules: [jsonSchemaContainerModule],
|
|
28
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
type IJsonSchema,
|
|
9
|
+
JsonSchemaUtils,
|
|
10
|
+
useTypeManager as useOriginTypeManager,
|
|
11
|
+
TypePresetProvider as OriginTypePresetProvider,
|
|
12
|
+
JsonSchemaTypeManager,
|
|
13
|
+
type JsonSchemaBasicType,
|
|
14
|
+
} from '@flowgram.ai/json-schema';
|
|
15
|
+
|
|
16
|
+
import { jsonSchemaTypePreset } from './type-definition';
|
|
17
|
+
import { type JsonSchemaTypeRegistry, type ConstantRendererProps } from './manager';
|
|
18
|
+
import { createTypePresetPlugin } from './create-type-preset-plugin';
|
|
19
|
+
|
|
20
|
+
const useTypeManager = () =>
|
|
21
|
+
useOriginTypeManager() as JsonSchemaTypeManager<IJsonSchema, JsonSchemaTypeRegistry>;
|
|
22
|
+
|
|
23
|
+
const JsonSchemaTypePresetProvider = ({
|
|
24
|
+
types = [],
|
|
25
|
+
children,
|
|
26
|
+
}: React.PropsWithChildren<{ types: JsonSchemaTypeRegistry[] }>) => (
|
|
27
|
+
<OriginTypePresetProvider types={[...jsonSchemaTypePreset, ...types]}>
|
|
28
|
+
{children}
|
|
29
|
+
</OriginTypePresetProvider>
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
createTypePresetPlugin,
|
|
34
|
+
useTypeManager,
|
|
35
|
+
JsonSchemaTypePresetProvider,
|
|
36
|
+
IJsonSchema,
|
|
37
|
+
JsonSchemaUtils,
|
|
38
|
+
JsonSchemaTypeRegistry,
|
|
39
|
+
ConstantRendererProps,
|
|
40
|
+
JsonSchemaBasicType,
|
|
41
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { JsonSchemaTypeRegistry as OriginJsonSchemaTypeRegistry } from '@flowgram.ai/json-schema';
|
|
7
|
+
|
|
8
|
+
export interface ConstantRendererProps<Value = any> {
|
|
9
|
+
value?: Value;
|
|
10
|
+
onChange?: (value: Value) => void;
|
|
11
|
+
readonly?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface JsonSchemaTypeRegistry<Value = any> extends OriginJsonSchemaTypeRegistry {
|
|
14
|
+
/**
|
|
15
|
+
* Render Constant Input
|
|
16
|
+
*/
|
|
17
|
+
ConstantRenderer: React.FC<ConstantRendererProps<Value>>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* eslint-disable react/prop-types */
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
9
|
+
import { CodeEditorMini } from '@/components/code-editor-mini';
|
|
10
|
+
|
|
11
|
+
import { type JsonSchemaTypeRegistry } from '../manager';
|
|
12
|
+
|
|
13
|
+
export const arrayRegistry: Partial<JsonSchemaTypeRegistry> = {
|
|
14
|
+
type: 'array',
|
|
15
|
+
ConstantRenderer: (props) => (
|
|
16
|
+
<CodeEditorMini
|
|
17
|
+
value={props.value}
|
|
18
|
+
languageId="json"
|
|
19
|
+
onChange={(v) => props.onChange?.(v)}
|
|
20
|
+
placeholder="Please Input Array"
|
|
21
|
+
readonly={props.readonly}
|
|
22
|
+
/>
|
|
23
|
+
),
|
|
24
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* eslint-disable react/prop-types */
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
9
|
+
import { Select } from '@douyinfe/semi-ui';
|
|
10
|
+
|
|
11
|
+
import { type JsonSchemaTypeRegistry } from '../manager';
|
|
12
|
+
|
|
13
|
+
export const booleanRegistry: Partial<JsonSchemaTypeRegistry> = {
|
|
14
|
+
type: 'boolean',
|
|
15
|
+
ConstantRenderer: (props) => {
|
|
16
|
+
const { value, onChange, ...rest } = props;
|
|
17
|
+
return (
|
|
18
|
+
<Select
|
|
19
|
+
placeholder="Please Select Boolean"
|
|
20
|
+
size="small"
|
|
21
|
+
disabled={props.readonly}
|
|
22
|
+
optionList={[
|
|
23
|
+
{ label: 'True', value: 1 },
|
|
24
|
+
{ label: 'False', value: 0 },
|
|
25
|
+
]}
|
|
26
|
+
value={value ? 1 : 0}
|
|
27
|
+
onChange={(value) => onChange?.(!!value)}
|
|
28
|
+
{...rest}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { jsonSchemaTypeManager } from '@flowgram.ai/json-schema';
|
|
7
|
+
|
|
8
|
+
import { stringRegistry } from './string';
|
|
9
|
+
import { objectRegistry } from './object';
|
|
10
|
+
import { numberRegistry } from './number';
|
|
11
|
+
import { integerRegistry } from './integer';
|
|
12
|
+
import { booleanRegistry } from './boolean';
|
|
13
|
+
import { arrayRegistry } from './array';
|
|
14
|
+
|
|
15
|
+
export const jsonSchemaTypePreset = [
|
|
16
|
+
stringRegistry,
|
|
17
|
+
objectRegistry,
|
|
18
|
+
numberRegistry,
|
|
19
|
+
integerRegistry,
|
|
20
|
+
booleanRegistry,
|
|
21
|
+
arrayRegistry,
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
jsonSchemaTypePreset.forEach((_type) => jsonSchemaTypeManager.register(_type));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* eslint-disable react/prop-types */
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
9
|
+
import { InputNumber } from '@douyinfe/semi-ui';
|
|
10
|
+
|
|
11
|
+
import { type JsonSchemaTypeRegistry } from '../manager';
|
|
12
|
+
|
|
13
|
+
export const integerRegistry: Partial<JsonSchemaTypeRegistry> = {
|
|
14
|
+
type: 'integer',
|
|
15
|
+
ConstantRenderer: (props) => (
|
|
16
|
+
<InputNumber
|
|
17
|
+
placeholder="Please Input Integer"
|
|
18
|
+
size="small"
|
|
19
|
+
disabled={props.readonly}
|
|
20
|
+
precision={0}
|
|
21
|
+
{...props}
|
|
22
|
+
/>
|
|
23
|
+
),
|
|
24
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* eslint-disable react/prop-types */
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
9
|
+
import { InputNumber } from '@douyinfe/semi-ui';
|
|
10
|
+
|
|
11
|
+
import { type JsonSchemaTypeRegistry } from '../manager';
|
|
12
|
+
|
|
13
|
+
export const numberRegistry: Partial<JsonSchemaTypeRegistry> = {
|
|
14
|
+
type: 'number',
|
|
15
|
+
ConstantRenderer: (props) => (
|
|
16
|
+
<InputNumber
|
|
17
|
+
placeholder="Please Input Number"
|
|
18
|
+
size="small"
|
|
19
|
+
disabled={props.readonly}
|
|
20
|
+
hideButtons
|
|
21
|
+
{...props}
|
|
22
|
+
/>
|
|
23
|
+
),
|
|
24
|
+
};
|