@flowgram-vue/form-materials 0.2.0

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 (177) hide show
  1. package/LICENSE +22 -0
  2. package/bin/run.sh +7 -0
  3. package/dist/index.cjs +0 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +0 -0
  7. package/dist/index.js.map +1 -0
  8. package/package.json +86 -0
  9. package/src/components/assign-row/assign-row.vue +69 -0
  10. package/src/components/assign-row/index.ts +7 -0
  11. package/src/components/assign-row/types.ts +25 -0
  12. package/src/components/assign-rows/assign-rows.vue +44 -0
  13. package/src/components/assign-rows/index.ts +6 -0
  14. package/src/components/batch-outputs/batch-outputs.vue +46 -0
  15. package/src/components/batch-outputs/index.ts +6 -0
  16. package/src/components/batch-outputs/styles.css +17 -0
  17. package/src/components/batch-outputs/types.ts +23 -0
  18. package/src/components/batch-variable-selector/batch-variable-selector.vue +24 -0
  19. package/src/components/batch-variable-selector/index.ts +6 -0
  20. package/src/components/blur-input/blur-input.vue +47 -0
  21. package/src/components/blur-input/index.ts +6 -0
  22. package/src/components/code-editor/base-code-editor.vue +44 -0
  23. package/src/components/code-editor/index.ts +58 -0
  24. package/src/components/code-editor/styles.css +27 -0
  25. package/src/components/code-editor/types.ts +20 -0
  26. package/src/components/code-editor/utils.ts +24 -0
  27. package/src/components/code-editor-mini/code-editor-mini.vue +16 -0
  28. package/src/components/code-editor-mini/index.ts +6 -0
  29. package/src/components/condition-context/context.ts +45 -0
  30. package/src/components/condition-context/hooks/use-condition.ts +120 -0
  31. package/src/components/condition-context/index.ts +14 -0
  32. package/src/components/condition-context/op.ts +86 -0
  33. package/src/components/condition-context/types.ts +22 -0
  34. package/src/components/condition-row/condition-row.vue +126 -0
  35. package/src/components/condition-row/index.ts +7 -0
  36. package/src/components/condition-row/styles.css +30 -0
  37. package/src/components/condition-row/types.ts +12 -0
  38. package/src/components/constant-input/constant-input.vue +48 -0
  39. package/src/components/constant-input/index.ts +7 -0
  40. package/src/components/constant-input/types.ts +23 -0
  41. package/src/components/coze-editor-extensions/extensions/inputs-tree.vue +16 -0
  42. package/src/components/coze-editor-extensions/extensions/variable-tag.vue +10 -0
  43. package/src/components/coze-editor-extensions/extensions/variable-tree.vue +18 -0
  44. package/src/components/coze-editor-extensions/index.ts +22 -0
  45. package/src/components/coze-editor-extensions/styles.css +41 -0
  46. package/src/components/db-condition-row/db-condition-row.vue +112 -0
  47. package/src/components/db-condition-row/index.ts +7 -0
  48. package/src/components/db-condition-row/styles.css +41 -0
  49. package/src/components/db-condition-row/types.ts +20 -0
  50. package/src/components/display-flow-value/display-flow-value.vue +46 -0
  51. package/src/components/display-flow-value/index.ts +6 -0
  52. package/src/components/display-inputs-values/display-inputs-value-all-in-tag.vue +26 -0
  53. package/src/components/display-inputs-values/display-inputs-values.vue +43 -0
  54. package/src/components/display-inputs-values/index.ts +7 -0
  55. package/src/components/display-inputs-values/styles.css +10 -0
  56. package/src/components/display-outputs/display-outputs.vue +62 -0
  57. package/src/components/display-outputs/index.ts +6 -0
  58. package/src/components/display-outputs/styles.css +10 -0
  59. package/src/components/display-schema-tag/display-schema-tag.vue +41 -0
  60. package/src/components/display-schema-tag/index.ts +6 -0
  61. package/src/components/display-schema-tag/styles.css +25 -0
  62. package/src/components/display-schema-tree/display-schema-tree.vue +55 -0
  63. package/src/components/display-schema-tree/index.ts +6 -0
  64. package/src/components/display-schema-tree/styles.css +84 -0
  65. package/src/components/dynamic-value-input/dynamic-value-input.vue +145 -0
  66. package/src/components/dynamic-value-input/hooks.ts +71 -0
  67. package/src/components/dynamic-value-input/index.ts +10 -0
  68. package/src/components/dynamic-value-input/styles.css +59 -0
  69. package/src/components/index.ts +84 -0
  70. package/src/components/inputs-values/index.ts +6 -0
  71. package/src/components/inputs-values/inputs-values.vue +67 -0
  72. package/src/components/inputs-values/styles.css +17 -0
  73. package/src/components/inputs-values/types.ts +23 -0
  74. package/src/components/inputs-values-tree/hooks/use-child-list.ts +65 -0
  75. package/src/components/inputs-values-tree/index.ts +6 -0
  76. package/src/components/inputs-values-tree/inputs-values-tree.vue +59 -0
  77. package/src/components/inputs-values-tree/row.vue +139 -0
  78. package/src/components/inputs-values-tree/styles.css +94 -0
  79. package/src/components/inputs-values-tree/types.ts +23 -0
  80. package/src/components/json-editor-with-variables/index.ts +7 -0
  81. package/src/components/json-editor-with-variables/json-editor-with-variables.vue +24 -0
  82. package/src/components/json-editor-with-variables/types.ts +8 -0
  83. package/src/components/json-schema-creator/index.ts +7 -0
  84. package/src/components/json-schema-creator/json-input-modal.vue +51 -0
  85. package/src/components/json-schema-creator/json-schema-creator.vue +27 -0
  86. package/src/components/json-schema-creator/types.ts +10 -0
  87. package/src/components/json-schema-creator/utils/json-to-schema.ts +50 -0
  88. package/src/components/json-schema-editor/default-value.vue +30 -0
  89. package/src/components/json-schema-editor/hooks.ts +134 -0
  90. package/src/components/json-schema-editor/index.ts +6 -0
  91. package/src/components/json-schema-editor/json-schema-editor.vue +53 -0
  92. package/src/components/json-schema-editor/property-edit.vue +222 -0
  93. package/src/components/json-schema-editor/styles.css +135 -0
  94. package/src/components/json-schema-editor/types.ts +25 -0
  95. package/src/components/prompt-editor/index.ts +7 -0
  96. package/src/components/prompt-editor/prompt-editor.vue +40 -0
  97. package/src/components/prompt-editor/styles.css +14 -0
  98. package/src/components/prompt-editor/types.ts +20 -0
  99. package/src/components/prompt-editor-with-inputs/index.ts +7 -0
  100. package/src/components/prompt-editor-with-inputs/prompt-editor-with-inputs.vue +18 -0
  101. package/src/components/prompt-editor-with-inputs/types.ts +11 -0
  102. package/src/components/prompt-editor-with-variables/index.ts +7 -0
  103. package/src/components/prompt-editor-with-variables/prompt-editor-with-variables.vue +19 -0
  104. package/src/components/prompt-editor-with-variables/types.ts +8 -0
  105. package/src/components/sql-editor-with-variables/index.ts +7 -0
  106. package/src/components/sql-editor-with-variables/sql-editor-with-variables.vue +24 -0
  107. package/src/components/sql-editor-with-variables/types.ts +8 -0
  108. package/src/components/type-selector/index.ts +11 -0
  109. package/src/components/type-selector/type-selector.vue +79 -0
  110. package/src/components/type-selector/types.ts +33 -0
  111. package/src/components/variable-selector/context.ts +44 -0
  112. package/src/components/variable-selector/index.ts +13 -0
  113. package/src/components/variable-selector/styles.css +70 -0
  114. package/src/components/variable-selector/types.ts +22 -0
  115. package/src/components/variable-selector/use-variable-tree.ts +108 -0
  116. package/src/components/variable-selector/variable-selector.vue +139 -0
  117. package/src/effects/auto-rename-ref/index.ts +109 -0
  118. package/src/effects/index.ts +12 -0
  119. package/src/effects/listen-ref-schema-change/index.ts +56 -0
  120. package/src/effects/listen-ref-value-change/index.ts +53 -0
  121. package/src/effects/provide-batch-input/index.ts +40 -0
  122. package/src/effects/provide-json-schema-outputs/index.ts +23 -0
  123. package/src/effects/sync-variable-title/index.ts +25 -0
  124. package/src/effects/validate-when-variable-sync/index.ts +34 -0
  125. package/src/env.d.ts +12 -0
  126. package/src/form-plugins/batch-outputs-plugin/index.ts +120 -0
  127. package/src/form-plugins/index.ts +8 -0
  128. package/src/form-plugins/infer-assign-plugin/index.ts +87 -0
  129. package/src/form-plugins/infer-inputs-plugin/index.ts +85 -0
  130. package/src/hooks/index.ts +6 -0
  131. package/src/hooks/use-object-list/index.ts +161 -0
  132. package/src/index.ts +125 -0
  133. package/src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts +27 -0
  134. package/src/plugins/disable-declaration-plugin/index.ts +6 -0
  135. package/src/plugins/index.ts +16 -0
  136. package/src/plugins/json-schema-preset/create-type-preset-plugin.ts +35 -0
  137. package/src/plugins/json-schema-preset/index.ts +25 -0
  138. package/src/plugins/json-schema-preset/type-definition/array.ts +38 -0
  139. package/src/plugins/json-schema-preset/type-definition/boolean.ts +47 -0
  140. package/src/plugins/json-schema-preset/type-definition/date-time.ts +60 -0
  141. package/src/plugins/json-schema-preset/type-definition/enum.ts +31 -0
  142. package/src/plugins/json-schema-preset/type-definition/index.ts +37 -0
  143. package/src/plugins/json-schema-preset/type-definition/integer.ts +47 -0
  144. package/src/plugins/json-schema-preset/type-definition/map.ts +34 -0
  145. package/src/plugins/json-schema-preset/type-definition/number.ts +46 -0
  146. package/src/plugins/json-schema-preset/type-definition/object.ts +34 -0
  147. package/src/plugins/json-schema-preset/type-definition/string.ts +52 -0
  148. package/src/plugins/json-schema-preset/types.ts +25 -0
  149. package/src/plugins/json-schema-preset/vue.ts +38 -0
  150. package/src/shared/flow-value/index.ts +17 -0
  151. package/src/shared/flow-value/schema.ts +38 -0
  152. package/src/shared/flow-value/types.ts +49 -0
  153. package/src/shared/flow-value/utils.ts +213 -0
  154. package/src/shared/format-legacy-refs/index.ts +158 -0
  155. package/src/shared/format-legacy-refs/readme.md +38 -0
  156. package/src/shared/index.ts +32 -0
  157. package/src/shared/inject-material/index.ts +50 -0
  158. package/src/shared/lazy-suspense/index.ts +20 -0
  159. package/src/shared/polyfill-create-root/index.ts +38 -0
  160. package/src/ui/fg-button.vue +27 -0
  161. package/src/ui/fg-cascader.vue +92 -0
  162. package/src/ui/fg-checkbox.vue +25 -0
  163. package/src/ui/fg-icon-button.vue +31 -0
  164. package/src/ui/fg-input.vue +50 -0
  165. package/src/ui/fg-modal.vue +37 -0
  166. package/src/ui/fg-popover.vue +19 -0
  167. package/src/ui/fg-select.vue +81 -0
  168. package/src/ui/fg-tag.vue +37 -0
  169. package/src/ui/fg-textarea.vue +42 -0
  170. package/src/ui/fg-tree-nodes.vue +48 -0
  171. package/src/ui/fg-tree-select.vue +86 -0
  172. package/src/ui/icons.ts +60 -0
  173. package/src/ui/index.ts +20 -0
  174. package/src/ui/styles.css +277 -0
  175. package/src/ui/types.ts +36 -0
  176. package/src/validate/index.ts +6 -0
  177. package/src/validate/validate-flow-value/index.ts +62 -0
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { ASTFactory } from '@flowgram-vue/variable-core';
7
+ import { createEffectFromVariableProvider } from '@flowgram-vue/node-variable-plugin';
8
+ import { type FlowNodeRegistry } from '@flowgram-vue/document';
9
+ import { type EffectOptions } from '@flowgram-vue/node';
10
+
11
+ import { IFlowRefValue } from '@/shared';
12
+
13
+ export const provideBatchInputEffect: EffectOptions[] = createEffectFromVariableProvider({
14
+ private: true,
15
+ parse: (value: IFlowRefValue, ctx) => [
16
+ ASTFactory.createVariableDeclaration({
17
+ key: `${ctx.node.id}_locals`,
18
+ meta: {
19
+ title: ctx.form?.getValueIn('title'),
20
+ icon: ctx.node.getNodeRegistry<FlowNodeRegistry>().info?.icon,
21
+ },
22
+ type: ASTFactory.createObject({
23
+ properties: [
24
+ ASTFactory.createProperty({
25
+ key: 'item',
26
+ initializer: ASTFactory.createEnumerateExpression({
27
+ enumerateFor: ASTFactory.createKeyPathExpression({
28
+ keyPath: value.content || [],
29
+ }),
30
+ }),
31
+ }),
32
+ ASTFactory.createProperty({
33
+ key: 'index',
34
+ type: ASTFactory.createNumber(),
35
+ }),
36
+ ],
37
+ }),
38
+ }),
39
+ ],
40
+ });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { JsonSchemaUtils, IJsonSchema } from '@flowgram-vue/json-schema';
7
+ import { ASTFactory } from '@flowgram-vue/variable-core';
8
+ import { createEffectFromVariableProvider } from '@flowgram-vue/node-variable-plugin';
9
+ import { type FlowNodeRegistry } from '@flowgram-vue/document';
10
+ import { type EffectOptions } from '@flowgram-vue/node';
11
+
12
+ export const provideJsonSchemaOutputs: EffectOptions[] = createEffectFromVariableProvider({
13
+ parse: (value: IJsonSchema, ctx) => [
14
+ ASTFactory.createVariableDeclaration({
15
+ key: `${ctx.node.id}`,
16
+ meta: {
17
+ title: ctx.form?.getValueIn('title') || ctx.node.id,
18
+ icon: ctx.node.getNodeRegistry<FlowNodeRegistry>().info?.icon,
19
+ },
20
+ type: JsonSchemaUtils.schemaToAST(value),
21
+ }),
22
+ ],
23
+ });
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { FlowNodeVariableData } from '@flowgram-vue/variable-layout';
7
+ import { type FlowNodeRegistry } from '@flowgram-vue/document';
8
+ import { DataEvent, type Effect, type EffectOptions } from '@flowgram-vue/node';
9
+
10
+ export const syncVariableTitle: EffectOptions[] = [
11
+ {
12
+ event: DataEvent.onValueChange,
13
+ effect: (({ value, context }) => {
14
+ context.node.getData(FlowNodeVariableData).allScopes.forEach((_scope) => {
15
+ _scope.output.variables.forEach((_var) => {
16
+ _var.updateMeta({
17
+ ...(_var.meta || {}),
18
+ title: value || context.node.id,
19
+ icon: context.node.getNodeRegistry<FlowNodeRegistry>().info?.icon,
20
+ });
21
+ });
22
+ });
23
+ }) as Effect,
24
+ },
25
+ ];
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { getNodeScope, getNodePrivateScope } from '@flowgram-vue/variable-layout';
7
+ import { DataEvent, type Effect, type EffectOptions } from '@flowgram-vue/node';
8
+
9
+ export const validateWhenVariableSync = ({
10
+ scope,
11
+ }: {
12
+ scope?: 'private' | 'public';
13
+ } = {}): EffectOptions[] => [
14
+ {
15
+ event: DataEvent.onValueInit,
16
+ effect: (({ context, form, name }) => {
17
+ const nodeScope =
18
+ scope === 'private' ? getNodePrivateScope(context.node) : getNodeScope(context.node);
19
+
20
+ const disposable = nodeScope.available.onListOrAnyVarChange(() => {
21
+ const errorKeys = Object.entries(form.state.errors || {})
22
+ .filter(([_, errors]) => errors?.length > 0)
23
+ .filter(([key]) => key.startsWith(name) || name.startsWith(key))
24
+ .map(([key]) => key);
25
+
26
+ if (errorKeys.length > 0) {
27
+ form.validate();
28
+ }
29
+ });
30
+
31
+ return () => disposable.dispose();
32
+ }) as Effect,
33
+ },
34
+ ];
package/src/env.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ declare module '*.vue' {
7
+ import type { DefineComponent } from 'vue';
8
+ const component: DefineComponent<object, object, unknown>;
9
+ export default component;
10
+ }
11
+
12
+ declare module '*.css';
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { set } from 'lodash-es';
7
+ import { JsonSchemaUtils } from '@flowgram-vue/json-schema';
8
+ import { ASTFactory } from '@flowgram-vue/variable-core';
9
+ import {
10
+ getNodePrivateScope,
11
+ getNodeScope,
12
+ ScopeChainTransformService,
13
+ FlowNodeScopeType,
14
+ } from '@flowgram-vue/variable-layout';
15
+ import { createEffectFromVariableProvider } from '@flowgram-vue/node-variable-plugin';
16
+ import { defineFormPluginCreator, type EffectOptions, type FormPluginCreator } from '@flowgram-vue/node';
17
+ import { type FlowNodeRegistry } from '@flowgram-vue/document';
18
+
19
+ import { IFlowRefValue } from '@/shared';
20
+
21
+ export const provideBatchOutputsEffect: EffectOptions[] = createEffectFromVariableProvider({
22
+ parse: (value: Record<string, IFlowRefValue>, ctx) => [
23
+ ASTFactory.createVariableDeclaration({
24
+ key: `${ctx.node.id}`,
25
+ meta: {
26
+ title: ctx.form?.getValueIn('title'),
27
+ icon: ctx.node.getNodeRegistry<FlowNodeRegistry>().info?.icon,
28
+ },
29
+ type: ASTFactory.createObject({
30
+ properties: Object.entries(value).map(([_key, value]) =>
31
+ ASTFactory.createProperty({
32
+ key: _key,
33
+ initializer: ASTFactory.createWrapArrayExpression({
34
+ wrapFor: ASTFactory.createKeyPathExpression({
35
+ keyPath: value?.content || [],
36
+ }),
37
+ }),
38
+ })
39
+ ),
40
+ }),
41
+ }),
42
+ ],
43
+ });
44
+
45
+ /**
46
+ * Free Layout only right now
47
+ */
48
+ export const createBatchOutputsFormPlugin: FormPluginCreator<{
49
+ outputKey: string;
50
+ /**
51
+ * if set, infer json schema to inferTargetKey when submit
52
+ */
53
+ inferTargetKey?: string;
54
+ }> = defineFormPluginCreator({
55
+ name: 'batch-outputs-plugin',
56
+ onSetupFormMeta({ mergeEffect, addFormatOnSubmit }, { outputKey, inferTargetKey }) {
57
+ mergeEffect({
58
+ [outputKey]: provideBatchOutputsEffect,
59
+ });
60
+
61
+ if (inferTargetKey) {
62
+ addFormatOnSubmit((formData, ctx) => {
63
+ const outputVariable = getNodeScope(ctx.node).output.variables?.[0];
64
+
65
+ if (outputVariable?.type) {
66
+ set(formData, inferTargetKey, JsonSchemaUtils.astToSchema(outputVariable?.type));
67
+ }
68
+
69
+ return formData;
70
+ });
71
+ }
72
+ },
73
+ onInit(ctx, { outputKey }) {
74
+ const chainTransformService = ctx.node.getService(ScopeChainTransformService);
75
+
76
+ const batchNodeType = ctx.node.flowNodeType;
77
+
78
+ const transformerId = `${batchNodeType}-outputs`;
79
+
80
+ if (chainTransformService.hasTransformer(transformerId)) {
81
+ return;
82
+ }
83
+
84
+ chainTransformService.registerTransformer(transformerId, {
85
+ transformCovers: (covers, ctx) => {
86
+ const node = ctx.scope.meta?.node;
87
+
88
+ // Child Node's variable can cover parent
89
+ if (node?.parent?.flowNodeType === batchNodeType) {
90
+ return [...covers, getNodeScope(node.parent)];
91
+ }
92
+
93
+ return covers;
94
+ },
95
+ transformDeps(scopes, ctx) {
96
+ const scopeMeta = ctx.scope.meta;
97
+
98
+ if (scopeMeta?.type === FlowNodeScopeType.private) {
99
+ return scopes;
100
+ }
101
+
102
+ const node = scopeMeta?.node;
103
+
104
+ // Public of Loop Node depends on child Node
105
+ if (node?.flowNodeType === batchNodeType) {
106
+ // Get all child blocks
107
+ const childBlocks = node.blocks;
108
+
109
+ // public scope of all child blocks
110
+ return [
111
+ getNodePrivateScope(node),
112
+ ...childBlocks.map((_childBlock) => getNodeScope(_childBlock)),
113
+ ];
114
+ }
115
+
116
+ return scopes;
117
+ },
118
+ });
119
+ },
120
+ });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ export { createBatchOutputsFormPlugin, provideBatchOutputsEffect } from './batch-outputs-plugin';
7
+ export { createInferAssignPlugin } from './infer-assign-plugin';
8
+ export { createInferInputsPlugin } from './infer-inputs-plugin';
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { set, uniqBy } from 'lodash-es';
7
+ import { JsonSchemaUtils } from '@flowgram-vue/json-schema';
8
+ import { ASTFactory } from '@flowgram-vue/variable-core';
9
+ import { getNodeScope } from '@flowgram-vue/variable-layout';
10
+ import { createEffectFromVariableProvider } from '@flowgram-vue/node-variable-plugin';
11
+ import { defineFormPluginCreator } from '@flowgram-vue/node';
12
+ import { type FlowNodeRegistry } from '@flowgram-vue/document';
13
+
14
+ import { IFlowRefValue, IFlowValue } from '@/shared';
15
+
16
+ type AssignValueType =
17
+ | {
18
+ operator: 'assign';
19
+ left?: IFlowRefValue;
20
+ right?: IFlowValue;
21
+ }
22
+ | {
23
+ operator: 'declare';
24
+ left?: string;
25
+ right?: IFlowValue;
26
+ };
27
+
28
+ interface InputConfig {
29
+ assignKey: string;
30
+ outputKey: string;
31
+ }
32
+
33
+ export const createInferAssignPlugin = defineFormPluginCreator<InputConfig>({
34
+ onSetupFormMeta({ addFormatOnSubmit, mergeEffect }, { assignKey, outputKey }) {
35
+ if (!assignKey || !outputKey) {
36
+ return;
37
+ }
38
+
39
+ mergeEffect({
40
+ [assignKey]: createEffectFromVariableProvider({
41
+ parse: (value: AssignValueType[], ctx) => {
42
+ const declareRows = uniqBy(
43
+ value.filter((_v) => _v.operator === 'declare' && _v.left && _v.right),
44
+ 'left'
45
+ );
46
+
47
+ return [
48
+ ASTFactory.createVariableDeclaration({
49
+ key: `${ctx.node.id}`,
50
+ meta: {
51
+ title: ctx.form?.getValueIn('title'),
52
+ icon: ctx.node.getNodeRegistry<FlowNodeRegistry>().info?.icon,
53
+ },
54
+ type: ASTFactory.createObject({
55
+ properties: declareRows.map((_v) =>
56
+ ASTFactory.createProperty({
57
+ key: _v.left as string,
58
+ type:
59
+ _v.right?.type === 'constant'
60
+ ? JsonSchemaUtils.schemaToAST(_v.right?.schema || {})
61
+ : undefined,
62
+ initializer:
63
+ _v.right?.type === 'ref'
64
+ ? ASTFactory.createKeyPathExpression({
65
+ keyPath: _v.right?.content || [],
66
+ })
67
+ : {},
68
+ })
69
+ ),
70
+ }),
71
+ }),
72
+ ];
73
+ },
74
+ }),
75
+ });
76
+
77
+ addFormatOnSubmit((formData, ctx) => {
78
+ set(
79
+ formData,
80
+ outputKey,
81
+ JsonSchemaUtils.astToSchema(getNodeScope(ctx.node).output.variables?.[0]?.type)
82
+ );
83
+
84
+ return formData;
85
+ });
86
+ },
87
+ });
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { get, omit, set } from 'lodash-es';
7
+ import { Immer } from 'immer';
8
+ import { getNodePrivateScope, getNodeScope } from '@flowgram-vue/variable-layout';
9
+ import { defineFormPluginCreator } from '@flowgram-vue/node';
10
+
11
+ import { FlowValueUtils } from '@/shared';
12
+
13
+ const { produce } = new Immer({ autoFreeze: false });
14
+
15
+ interface InputConfig {
16
+ sourceKey: string;
17
+ targetKey: string;
18
+ scope?: 'private' | 'public';
19
+ /**
20
+ * For backend runtime, constant schema is redundant, so we can choose to ignore it
21
+ */
22
+ ignoreConstantSchema?: boolean;
23
+ }
24
+
25
+ export const createInferInputsPlugin = defineFormPluginCreator<InputConfig>({
26
+ onSetupFormMeta(
27
+ { addFormatOnSubmit, addFormatOnInit },
28
+ { sourceKey, targetKey, scope, ignoreConstantSchema }
29
+ ) {
30
+ if (!sourceKey || !targetKey) {
31
+ return;
32
+ }
33
+
34
+ addFormatOnSubmit((formData, ctx) =>
35
+ produce(formData, (draft: any) => {
36
+ const sourceData = get(formData, sourceKey);
37
+
38
+ set(
39
+ draft,
40
+ targetKey,
41
+ FlowValueUtils.inferJsonSchema(
42
+ sourceData,
43
+ scope === 'private' ? getNodePrivateScope(ctx.node) : getNodeScope(ctx.node)
44
+ )
45
+ );
46
+
47
+ if (ignoreConstantSchema) {
48
+ for (const { value, path } of FlowValueUtils.traverse(sourceData, {
49
+ includeTypes: ['constant'],
50
+ })) {
51
+ if (FlowValueUtils.isConstant(value) && value?.schema) {
52
+ set(formData, `${sourceKey}.${path}`, omit(value, ['schema']));
53
+ }
54
+ }
55
+ }
56
+ })
57
+ );
58
+
59
+ if (ignoreConstantSchema) {
60
+ // Revert Schema in frontend
61
+ addFormatOnInit((formData, ctx) => {
62
+ const targetSchema = get(formData, targetKey);
63
+
64
+ if (!targetSchema) {
65
+ return formData;
66
+ }
67
+
68
+ // For backend data, it's not necessary to use immer
69
+ for (const { value, pathArr } of FlowValueUtils.traverse(get(formData, sourceKey), {
70
+ includeTypes: ['constant'],
71
+ })) {
72
+ if (FlowValueUtils.isConstant(value) && !value?.schema) {
73
+ const schemaPath = pathArr.map((_item) => `properties.${_item}`).join('.');
74
+ const schema = get(targetSchema, schemaPath);
75
+ if (schema) {
76
+ set(value, 'schema', schema);
77
+ }
78
+ }
79
+ }
80
+
81
+ return formData;
82
+ });
83
+ }
84
+ },
85
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ export { useObjectList } from './use-object-list';
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { ref, watch, type Ref } from 'vue';
7
+
8
+ import { nanoid } from 'nanoid';
9
+ import { difference, get, isObject, set } from 'lodash-es';
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 | ((item: ValueType | undefined) => string);
31
+ }): {
32
+ list: Ref<ListItem<ValueType>[]>;
33
+ add: (defaultValue?: ValueType) => void;
34
+ updateKey: (itemId: string, key: string) => void;
35
+ updateValue: (itemId: string, value: ValueType) => void;
36
+ remove: (itemId: string) => void;
37
+ } {
38
+ const list = ref<ListItem<ValueType>[]>([]) as Ref<ListItem<ValueType>[]>;
39
+ const effectVersion = ref(0);
40
+ const changeVersion = ref(0);
41
+
42
+ const getSortIndex = (item?: ValueType) => {
43
+ if (typeof sortIndexKey === 'function') {
44
+ return get(item, sortIndexKey(item)) || 0;
45
+ }
46
+ return get(item, sortIndexKey || '') || 0;
47
+ };
48
+
49
+ watch(
50
+ () => value,
51
+ () => {
52
+ effectVersion.value = effectVersion.value + 1;
53
+ if (effectVersion.value === changeVersion.value) {
54
+ return;
55
+ }
56
+ effectVersion.value = changeVersion.value;
57
+
58
+ const newKeys = Object.entries(value || {})
59
+ .sort((a, b) => getSortIndex(a[1]) - getSortIndex(b[1]))
60
+ .map(([key]) => key);
61
+
62
+ const oldKeys = list.value.map((item) => item.key).filter(Boolean) as string[];
63
+ const addKeys = difference(newKeys, oldKeys);
64
+
65
+ list.value = list.value
66
+ .filter((item) => !item.key || newKeys.includes(item.key))
67
+ .map((item) => ({
68
+ id: item.id,
69
+ key: item.key,
70
+ value: item.key ? value?.[item.key!] : item.value,
71
+ }))
72
+ .concat(
73
+ addKeys.map((_key) => ({
74
+ id: genId(),
75
+ key: _key,
76
+ value: value?.[_key],
77
+ }))
78
+ );
79
+ },
80
+ { immediate: true, deep: true }
81
+ );
82
+
83
+ const add = (defaultValue?: ValueType) => {
84
+ list.value = [
85
+ ...list.value,
86
+ {
87
+ id: genId(),
88
+ value: defaultValue,
89
+ },
90
+ ];
91
+ };
92
+
93
+ const updateValue = (itemId: string, nextValue: ValueType) => {
94
+ changeVersion.value = changeVersion.value + 1;
95
+
96
+ const nextList = list.value.map((_item) => {
97
+ if (_item.id === itemId) {
98
+ return {
99
+ ..._item,
100
+ value: nextValue,
101
+ };
102
+ }
103
+ return _item;
104
+ });
105
+
106
+ onChange(
107
+ Object.fromEntries(
108
+ nextList
109
+ .filter((item) => item.key)
110
+ .map((item) => [item.key!, item.value])
111
+ .map((_res, idx) => {
112
+ const indexKey =
113
+ typeof sortIndexKey === 'function'
114
+ ? sortIndexKey(_res[1] as ValueType | undefined)
115
+ : sortIndexKey;
116
+
117
+ if (isObject(_res[1]) && indexKey) {
118
+ set(_res[1], indexKey, idx);
119
+ }
120
+ return _res;
121
+ })
122
+ )
123
+ );
124
+
125
+ list.value = nextList;
126
+ };
127
+
128
+ const updateKey = (itemId: string, key: string) => {
129
+ changeVersion.value = changeVersion.value + 1;
130
+
131
+ const nextList = list.value.map((_item) => {
132
+ if (_item.id === itemId) {
133
+ return {
134
+ ..._item,
135
+ key,
136
+ };
137
+ }
138
+ return _item;
139
+ });
140
+
141
+ onChange(
142
+ Object.fromEntries(nextList.filter((item) => item.key).map((item) => [item.key!, item.value]))
143
+ );
144
+
145
+ list.value = nextList;
146
+ };
147
+
148
+ const remove = (itemId: string) => {
149
+ changeVersion.value = changeVersion.value + 1;
150
+
151
+ const nextList = list.value.filter((_item) => _item.id !== itemId);
152
+
153
+ onChange(
154
+ Object.fromEntries(nextList.filter((item) => item.key).map((item) => [item.key!, item.value]))
155
+ );
156
+
157
+ list.value = nextList;
158
+ };
159
+
160
+ return { list, add, updateKey, updateValue, remove };
161
+ }