@flowgram.ai/form-materials 0.1.0-alpha.11 → 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.
Files changed (121) hide show
  1. package/bin/index.ts +11 -5
  2. package/bin/materials.ts +10 -1
  3. package/dist/esm/index.js +1917 -1371
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/index.d.mts +320 -113
  6. package/dist/index.d.ts +320 -113
  7. package/dist/index.js +2023 -1484
  8. package/dist/index.js.map +1 -1
  9. package/package.json +5 -4
  10. package/src/components/assign-row/components/blur-input.tsx +27 -0
  11. package/src/components/assign-row/config.json +11 -0
  12. package/src/components/assign-row/index.tsx +84 -0
  13. package/src/components/assign-row/types.ts +25 -0
  14. package/src/components/assign-rows/config.json +11 -0
  15. package/src/components/assign-rows/index.tsx +59 -0
  16. package/src/components/batch-outputs/config.json +2 -1
  17. package/src/components/batch-outputs/index.tsx +4 -12
  18. package/src/components/batch-variable-selector/config.json +6 -2
  19. package/src/components/batch-variable-selector/index.tsx +1 -1
  20. package/src/components/code-editor/index.tsx +7 -0
  21. package/src/components/code-editor/language-features.ts +22 -1
  22. package/src/components/code-editor/theme/light.ts +1 -1
  23. package/src/components/code-editor-mini/config.json +7 -0
  24. package/src/components/code-editor-mini/index.tsx +31 -0
  25. package/src/components/condition-row/config.json +10 -2
  26. package/src/components/condition-row/constants.ts +6 -8
  27. package/src/components/condition-row/hooks/useOp.tsx +3 -1
  28. package/src/components/condition-row/hooks/useRule.ts +2 -2
  29. package/src/components/condition-row/index.tsx +2 -1
  30. package/src/components/condition-row/types.ts +3 -1
  31. package/src/components/constant-input/config.json +6 -3
  32. package/src/components/constant-input/index.tsx +18 -62
  33. package/src/components/constant-input/types.ts +6 -9
  34. package/src/components/display-flow-value/config.json +8 -0
  35. package/src/components/display-flow-value/index.tsx +59 -0
  36. package/src/components/display-inputs-values/config.json +9 -0
  37. package/src/components/display-inputs-values/index.tsx +27 -0
  38. package/src/components/display-inputs-values/styles.ts +12 -0
  39. package/src/components/display-outputs/config.json +10 -0
  40. package/src/components/display-outputs/index.tsx +64 -0
  41. package/src/components/display-outputs/styles.ts +12 -0
  42. package/src/components/display-schema-tag/config.json +10 -0
  43. package/src/components/display-schema-tag/index.tsx +44 -0
  44. package/src/components/display-schema-tag/styles.ts +28 -0
  45. package/src/components/display-schema-tree/config.json +11 -0
  46. package/src/components/display-schema-tree/index.tsx +74 -0
  47. package/src/components/display-schema-tree/styles.tsx +90 -0
  48. package/src/components/dynamic-value-input/config.json +11 -2
  49. package/src/components/dynamic-value-input/hooks.ts +53 -0
  50. package/src/components/dynamic-value-input/index.tsx +64 -13
  51. package/src/components/dynamic-value-input/styles.tsx +28 -2
  52. package/src/components/index.ts +9 -0
  53. package/src/components/inputs-values/components/blur-input.tsx +27 -0
  54. package/src/components/inputs-values/config.json +13 -0
  55. package/src/components/inputs-values/index.tsx +73 -0
  56. package/src/components/inputs-values/styles.tsx +19 -0
  57. package/src/components/inputs-values/types.ts +22 -0
  58. package/src/components/json-schema-editor/config.json +2 -2
  59. package/src/components/json-schema-editor/default-value.tsx +1 -1
  60. package/src/components/json-schema-editor/hooks.tsx +1 -1
  61. package/src/components/json-schema-editor/index.tsx +15 -2
  62. package/src/components/json-schema-editor/types.ts +1 -1
  63. package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +1 -1
  64. package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +6 -3
  65. package/src/components/type-selector/config.json +6 -2
  66. package/src/components/type-selector/index.tsx +55 -12
  67. package/src/components/variable-selector/config.json +6 -2
  68. package/src/components/variable-selector/index.tsx +34 -13
  69. package/src/components/variable-selector/styles.tsx +18 -8
  70. package/src/components/variable-selector/use-variable-tree.tsx +19 -22
  71. package/src/effects/index.ts +3 -1
  72. package/src/effects/listen-ref-schema-change/config.json +10 -0
  73. package/src/effects/listen-ref-schema-change/index.ts +56 -0
  74. package/src/effects/listen-ref-value-change/config.json +9 -0
  75. package/src/effects/listen-ref-value-change/index.ts +53 -0
  76. package/src/effects/provide-json-schema-outputs/config.json +4 -5
  77. package/src/effects/provide-json-schema-outputs/index.ts +1 -3
  78. package/src/effects/sync-variable-title/index.ts +1 -0
  79. package/src/effects/validate-when-variable-sync/config.json +5 -0
  80. package/src/effects/validate-when-variable-sync/index.ts +35 -0
  81. package/src/form-plugins/index.ts +3 -1
  82. package/src/form-plugins/infer-assign-plugin/config.json +7 -0
  83. package/src/form-plugins/infer-assign-plugin/index.ts +90 -0
  84. package/src/form-plugins/infer-inputs-plugin/config.json +9 -0
  85. package/src/form-plugins/infer-inputs-plugin/index.ts +108 -0
  86. package/src/hooks/index.tsx +6 -0
  87. package/src/hooks/use-object-list/config.json +8 -0
  88. package/src/hooks/use-object-list/index.tsx +136 -0
  89. package/src/index.ts +3 -1
  90. package/src/{typings/json-schema → plugins/disable-declaration-plugin}/config.json +1 -1
  91. package/src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts +31 -0
  92. package/src/plugins/disable-declaration-plugin/index.tsx +6 -0
  93. package/src/plugins/index.ts +7 -0
  94. package/src/plugins/json-schema-preset/config.json +9 -0
  95. package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +28 -0
  96. package/src/plugins/json-schema-preset/index.tsx +41 -0
  97. package/src/plugins/json-schema-preset/manager.ts +18 -0
  98. package/src/plugins/json-schema-preset/type-definition/array.tsx +24 -0
  99. package/src/plugins/json-schema-preset/type-definition/boolean.tsx +32 -0
  100. package/src/plugins/json-schema-preset/type-definition/index.tsx +24 -0
  101. package/src/plugins/json-schema-preset/type-definition/integer.tsx +24 -0
  102. package/src/plugins/json-schema-preset/type-definition/number.tsx +24 -0
  103. package/src/plugins/json-schema-preset/type-definition/object.tsx +24 -0
  104. package/src/plugins/json-schema-preset/type-definition/string.tsx +18 -0
  105. package/src/{utils → shared}/index.ts +0 -1
  106. package/src/typings/flow-value/config.json +3 -1
  107. package/src/typings/flow-value/index.ts +11 -0
  108. package/src/typings/index.ts +0 -1
  109. package/src/validate/index.tsx +6 -0
  110. package/src/validate/validate-flow-value/config.json +7 -0
  111. package/src/validate/validate-flow-value/index.tsx +73 -0
  112. package/src/components/batch-outputs/use-list.ts +0 -86
  113. package/src/components/type-selector/constants.tsx +0 -364
  114. package/src/effects/provide-batch-outputs/config.json +0 -5
  115. package/src/effects/provide-batch-outputs/index.ts +0 -38
  116. package/src/typings/json-schema/index.ts +0 -36
  117. package/src/utils/json-schema/config.json +0 -5
  118. package/src/utils/json-schema/index.ts +0 -180
  119. /package/src/{utils → shared}/format-legacy-refs/config.json +0 -0
  120. /package/src/{utils → shared}/format-legacy-refs/index.ts +0 -0
  121. /package/src/{utils → shared}/format-legacy-refs/readme.md +0 -0
@@ -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
@@ -5,6 +5,8 @@
5
5
 
6
6
  export * from './components';
7
7
  export * from './effects';
8
- export * from './utils';
8
+ export * from './shared';
9
9
  export * from './typings';
10
10
  export * from './form-plugins';
11
+ export * from './plugins';
12
+ export * from './validate';
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "json-schema",
2
+ "name": "disable-declaration-plugin",
3
3
  "depMaterials": [],
4
4
  "depPackages": []
5
5
  }
@@ -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,6 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ export { createDisableDeclarationPlugin } from './create-disable-declaration-plugin';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ export * from './json-schema-preset';
7
+ export * from './disable-declaration-plugin';
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "json-schema-preset",
3
+ "depMaterials": [
4
+ "components/code-editor-mini"
5
+ ],
6
+ "depPackages": [
7
+ "@flowgram.ai/json-schema"
8
+ ]
9
+ }
@@ -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
+ };
@@ -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 objectRegistry: Partial<JsonSchemaTypeRegistry> = {
14
+ type: 'object',
15
+ ConstantRenderer: (props) => (
16
+ <CodeEditorMini
17
+ value={props.value}
18
+ onChange={(v) => props.onChange?.(v)}
19
+ languageId="json"
20
+ placeholder="Please Input Object"
21
+ readonly={props.readonly}
22
+ />
23
+ ),
24
+ };
@@ -0,0 +1,18 @@
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 { Input } from '@douyinfe/semi-ui';
10
+
11
+ import { type JsonSchemaTypeRegistry } from '../manager';
12
+
13
+ export const stringRegistry: Partial<JsonSchemaTypeRegistry> = {
14
+ type: 'string',
15
+ ConstantRenderer: (props) => (
16
+ <Input placeholder="Please Input String" size="small" disabled={props.readonly} {...props} />
17
+ ),
18
+ };
@@ -4,4 +4,3 @@
4
4
  */
5
5
 
6
6
  export * from './format-legacy-refs';
7
- export * from './json-schema';
@@ -1,5 +1,7 @@
1
1
  {
2
2
  "name": "flow-value",
3
3
  "depMaterials": [],
4
- "depPackages": []
4
+ "depPackages": [
5
+ "@flowgram.ai/json-schema"
6
+ ]
5
7
  }
@@ -3,24 +3,35 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
+ import { IJsonSchema } from '@flowgram.ai/json-schema';
7
+
8
+ export interface IFlowValueExtra {
9
+ index?: number;
10
+ }
11
+
6
12
  export interface IFlowConstantValue {
7
13
  type: 'constant';
8
14
  content?: string | number | boolean;
15
+ schema?: IJsonSchema;
16
+ extra?: IFlowValueExtra;
9
17
  }
10
18
 
11
19
  export interface IFlowRefValue {
12
20
  type: 'ref';
13
21
  content?: string[];
22
+ extra?: IFlowValueExtra;
14
23
  }
15
24
 
16
25
  export interface IFlowExpressionValue {
17
26
  type: 'expression';
18
27
  content?: string;
28
+ extra?: IFlowValueExtra;
19
29
  }
20
30
 
21
31
  export interface IFlowTemplateValue {
22
32
  type: 'template';
23
33
  content?: string;
34
+ extra?: IFlowValueExtra;
24
35
  }
25
36
 
26
37
  export type IFlowValue =
@@ -4,4 +4,3 @@
4
4
  */
5
5
 
6
6
  export * from './flow-value';
7
- export * from './json-schema';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ export * from './validate-flow-value';
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "validate-flow-value",
3
+ "depMaterials": [
4
+ "flow-value"
5
+ ],
6
+ "depPackages": []
7
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { isNil, uniq } from 'lodash';
7
+ import { FeedbackLevel, FlowNodeEntity, getNodeScope } from '@flowgram.ai/editor';
8
+
9
+ import { IFlowTemplateValue, IFlowValue } from '@/typings';
10
+
11
+ interface Context {
12
+ node: FlowNodeEntity;
13
+ required?: boolean;
14
+ errorMessages?: {
15
+ required?: string;
16
+ unknownVariable?: string;
17
+ };
18
+ }
19
+
20
+ export function validateFlowValue(value: IFlowValue | undefined, ctx: Context) {
21
+ const { node, required, errorMessages } = ctx;
22
+
23
+ const {
24
+ required: requiredMessage = 'Field is required',
25
+ unknownVariable: unknownVariableMessage = 'Unknown Variable',
26
+ } = errorMessages || {};
27
+
28
+ if (required && (isNil(value) || isNil(value?.content) || value?.content === '')) {
29
+ return {
30
+ level: FeedbackLevel.Error,
31
+ message: requiredMessage,
32
+ };
33
+ }
34
+
35
+ if (value?.type === 'ref') {
36
+ const variable = getNodeScope(node).available.getByKeyPath(value?.content || []);
37
+ if (!variable) {
38
+ return {
39
+ level: FeedbackLevel.Error,
40
+ message: unknownVariableMessage,
41
+ };
42
+ }
43
+ }
44
+
45
+ if (value?.type === 'template') {
46
+ const allRefs = getTemplateKeyPaths(value);
47
+
48
+ for (const ref of allRefs) {
49
+ const variable = getNodeScope(node).available.getByKeyPath(ref);
50
+ if (!variable) {
51
+ return {
52
+ level: FeedbackLevel.Error,
53
+ message: unknownVariableMessage,
54
+ };
55
+ }
56
+ }
57
+ }
58
+
59
+ return undefined;
60
+ }
61
+
62
+ /**
63
+ * get template key paths
64
+ * @param value
65
+ * @returns
66
+ */
67
+ function getTemplateKeyPaths(value: IFlowTemplateValue) {
68
+ // find all keyPath wrapped in {{}}
69
+ const keyPathReg = /{{(.*?)}}/g;
70
+ return uniq(value.content?.match(keyPathReg) || []).map((_keyPath) =>
71
+ _keyPath.slice(2, -2).split('.')
72
+ );
73
+ }