@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,25 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import type { Component } from 'vue';
7
+ import {
8
+ type IJsonSchema,
9
+ JsonSchemaTypeRegistry as OriginJsonSchemaTypeRegistry,
10
+ } from '@flowgram-vue/json-schema';
11
+
12
+ import { IConditionRule, IConditionRuleFactory } from '@/components/condition-context/types';
13
+
14
+ export interface ConstantRendererProps<Value = any> {
15
+ value?: Value;
16
+ onChange?: (value: Value) => void;
17
+ readonly?: boolean;
18
+ schema?: IJsonSchema;
19
+ [key: string]: any;
20
+ }
21
+
22
+ export interface JsonSchemaTypeRegistry<Value = any> extends OriginJsonSchemaTypeRegistry {
23
+ ConstantRenderer: Component;
24
+ conditionRule?: IConditionRule | IConditionRuleFactory;
25
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { defineComponent, h, type PropType } from 'vue';
7
+ import {
8
+ type IJsonSchema,
9
+ useTypeManager as useOriginTypeManager,
10
+ TypePresetProvider as OriginTypePresetProvider,
11
+ JsonSchemaTypeManager,
12
+ } from '@flowgram-vue/json-schema';
13
+
14
+ import { type JsonSchemaTypeRegistry } from './types';
15
+ import { initRegistries, jsonSchemaTypePreset } from './type-definition';
16
+
17
+ initRegistries();
18
+
19
+ export const useTypeManager = () =>
20
+ useOriginTypeManager() as unknown as JsonSchemaTypeManager<IJsonSchema, JsonSchemaTypeRegistry>;
21
+
22
+ export const JsonSchemaTypePresetProvider = defineComponent({
23
+ name: 'JsonSchemaTypePresetProvider',
24
+ props: {
25
+ types: {
26
+ type: Array as PropType<JsonSchemaTypeRegistry[]>,
27
+ default: () => [],
28
+ },
29
+ },
30
+ setup(props, { slots }) {
31
+ return () =>
32
+ h(
33
+ OriginTypePresetProvider,
34
+ { types: [...jsonSchemaTypePreset, ...props.types] },
35
+ () => slots.default?.()
36
+ );
37
+ },
38
+ });
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ export { FlowValueUtils } from './utils';
7
+ export {
8
+ type IFlowValueExtra,
9
+ type FlowValueType,
10
+ type IFlowValue,
11
+ type IFlowConstantValue,
12
+ type IFlowRefValue,
13
+ type IFlowExpressionValue,
14
+ type IFlowTemplateValue,
15
+ type IFlowConstantRefValue,
16
+ type IInputsValues,
17
+ } from './types';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import z from 'zod';
7
+
8
+ // Shared extra schema for flow value types
9
+ export const extraSchema = z
10
+ .object({
11
+ index: z.number().optional(),
12
+ })
13
+ .optional();
14
+
15
+ export const constantSchema = z.object({
16
+ type: z.literal('constant'),
17
+ content: z.any().optional(),
18
+ schema: z.any().optional(),
19
+ extra: extraSchema,
20
+ });
21
+
22
+ export const refSchema = z.object({
23
+ type: z.literal('ref'),
24
+ content: z.array(z.string()).optional(),
25
+ extra: extraSchema,
26
+ });
27
+
28
+ export const expressionSchema = z.object({
29
+ type: z.literal('expression'),
30
+ content: z.string().optional(),
31
+ extra: extraSchema,
32
+ });
33
+
34
+ export const templateSchema = z.object({
35
+ type: z.literal('template'),
36
+ content: z.string().optional(),
37
+ extra: extraSchema,
38
+ });
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { IJsonSchema } from '@flowgram-vue/json-schema';
7
+
8
+ export interface IFlowValueExtra {
9
+ index?: number;
10
+ }
11
+
12
+ export type FlowValueType = 'constant' | 'ref' | 'expression' | 'template';
13
+
14
+ export interface IFlowConstantValue {
15
+ type: 'constant';
16
+ content?: any;
17
+ schema?: IJsonSchema;
18
+ extra?: IFlowValueExtra;
19
+ }
20
+
21
+ export interface IFlowRefValue {
22
+ type: 'ref';
23
+ content?: string[];
24
+ extra?: IFlowValueExtra;
25
+ }
26
+
27
+ export interface IFlowExpressionValue {
28
+ type: 'expression';
29
+ content?: string;
30
+ extra?: IFlowValueExtra;
31
+ }
32
+
33
+ export interface IFlowTemplateValue {
34
+ type: 'template';
35
+ content?: string;
36
+ extra?: IFlowValueExtra;
37
+ }
38
+
39
+ export type IFlowValue =
40
+ | IFlowConstantValue
41
+ | IFlowRefValue
42
+ | IFlowExpressionValue
43
+ | IFlowTemplateValue;
44
+
45
+ export type IFlowConstantRefValue = IFlowConstantValue | IFlowRefValue;
46
+
47
+ export interface IInputsValues {
48
+ [key: string]: IInputsValues | IFlowValue | undefined;
49
+ }
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { isArray, isObject, isPlainObject, uniq } from 'lodash-es';
7
+ import { IJsonSchema, JsonSchemaUtils } from '@flowgram-vue/json-schema';
8
+ import { Scope } from '@flowgram-vue/variable-core';
9
+
10
+ import {
11
+ IFlowConstantValue,
12
+ IFlowRefValue,
13
+ IFlowExpressionValue,
14
+ IFlowTemplateValue,
15
+ IFlowValue,
16
+ IFlowConstantRefValue,
17
+ FlowValueType,
18
+ } from './types';
19
+ import { constantSchema, refSchema, expressionSchema, templateSchema } from './schema';
20
+
21
+ export namespace FlowValueUtils {
22
+ /**
23
+ * Check if the value is a constant type
24
+ */
25
+ export function isConstant(value: any): value is IFlowConstantValue {
26
+ return constantSchema.safeParse(value).success;
27
+ }
28
+
29
+ /**
30
+ * Check if the value is a reference type
31
+ */
32
+ export function isRef(value: any): value is IFlowRefValue {
33
+ return refSchema.safeParse(value).success;
34
+ }
35
+
36
+ /**
37
+ * Check if the value is an expression type
38
+ */
39
+ export function isExpression(value: any): value is IFlowExpressionValue {
40
+ return expressionSchema.safeParse(value).success;
41
+ }
42
+
43
+ /**
44
+ * Check if the value is a template type
45
+ */
46
+ export function isTemplate(value: any): value is IFlowTemplateValue {
47
+ return templateSchema.safeParse(value).success;
48
+ }
49
+
50
+ /**
51
+ * Check if the value is either a constant or reference type
52
+ */
53
+ export function isConstantOrRef(value: any): value is IFlowConstantRefValue {
54
+ return isConstant(value) || isRef(value);
55
+ }
56
+
57
+ /**
58
+ * Check if the value is a valid flow value type
59
+ */
60
+ export function isFlowValue(value: any): value is IFlowValue {
61
+ return isConstant(value) || isRef(value) || isExpression(value) || isTemplate(value);
62
+ }
63
+
64
+ /**
65
+ * Traverse all flow values in the given value
66
+ * @param value The value to traverse
67
+ * @param options The options to traverse
68
+ * @returns A generator of flow values
69
+ */
70
+ export function* traverse(
71
+ value: any,
72
+ options: {
73
+ includeTypes: FlowValueType[];
74
+ path?: string;
75
+ pathArr?: string[];
76
+ }
77
+ ): Generator<{ value: IFlowValue; path: string; pathArr: string[] }> {
78
+ const {
79
+ includeTypes = ['ref', 'template', 'expression', 'constant'],
80
+ path = '',
81
+ pathArr = [],
82
+ } = options || {};
83
+
84
+ if (isPlainObject(value)) {
85
+ if (isRef(value) && includeTypes.includes('ref')) {
86
+ yield { value, path, pathArr };
87
+ return;
88
+ }
89
+
90
+ if (isTemplate(value) && includeTypes.includes('template')) {
91
+ yield { value, path, pathArr };
92
+ return;
93
+ }
94
+
95
+ if (isExpression(value) && includeTypes.includes('expression')) {
96
+ yield { value, path, pathArr };
97
+ return;
98
+ }
99
+
100
+ if (isConstant(value) && includeTypes.includes('constant')) {
101
+ yield { value, path, pathArr };
102
+ return;
103
+ }
104
+
105
+ for (const [_key, _value] of Object.entries(value)) {
106
+ yield* traverse(_value, {
107
+ ...options,
108
+ path: path ? `${path}.${_key}` : _key,
109
+ pathArr: [...pathArr, _key],
110
+ });
111
+ }
112
+ return;
113
+ }
114
+
115
+ if (isArray(value)) {
116
+ for (const [_idx, _value] of value.entries()) {
117
+ yield* traverse(_value, {
118
+ ...options,
119
+ path: path ? `${path}[${_idx}]` : `[${_idx}]`,
120
+ pathArr: [...pathArr, `[${_idx}]`],
121
+ });
122
+ }
123
+ return;
124
+ }
125
+
126
+ return;
127
+ }
128
+
129
+ /**
130
+ * Get all key paths in the template value
131
+ * @param value The template value
132
+ * @returns A list of key paths
133
+ */
134
+ export function getTemplateKeyPaths(value: IFlowTemplateValue) {
135
+ // find all keyPath wrapped in {{}}
136
+ const keyPathReg = /\{\{([^\}\{]+)\}\}/g;
137
+ return uniq(value.content?.match(keyPathReg) || []).map((_keyPath) =>
138
+ _keyPath.slice(2, -2).split('.')
139
+ );
140
+ }
141
+
142
+ /**
143
+ * Infer the schema of the constant value
144
+ * @param value
145
+ * @returns
146
+ */
147
+ export function inferConstantJsonSchema(value: IFlowConstantValue): IJsonSchema | undefined {
148
+ if (value?.schema) {
149
+ return value.schema;
150
+ }
151
+
152
+ if (typeof value.content === 'string') {
153
+ return {
154
+ type: 'string',
155
+ };
156
+ }
157
+
158
+ if (typeof value.content === 'number') {
159
+ return {
160
+ type: 'number',
161
+ };
162
+ }
163
+
164
+ if (typeof value.content === 'boolean') {
165
+ return {
166
+ type: 'boolean',
167
+ };
168
+ }
169
+
170
+ if (isObject(value.content)) {
171
+ return {
172
+ type: 'object',
173
+ };
174
+ }
175
+ return undefined;
176
+ }
177
+
178
+ /**
179
+ * Infer the schema of the flow value
180
+ * @param values The flow value or object contains flow value
181
+ * @param scope
182
+ * @returns
183
+ */
184
+ export function inferJsonSchema(values: any, scope: Scope): IJsonSchema | undefined {
185
+ if (isPlainObject(values)) {
186
+ if (isConstant(values)) {
187
+ return inferConstantJsonSchema(values);
188
+ }
189
+
190
+ if (isRef(values)) {
191
+ const variable = scope.available.getByKeyPath(values?.content);
192
+ const schema = variable?.type ? JsonSchemaUtils.astToSchema(variable?.type) : undefined;
193
+
194
+ return schema;
195
+ }
196
+
197
+ if (isTemplate(values)) {
198
+ return { type: 'string' };
199
+ }
200
+
201
+ return {
202
+ type: 'object',
203
+ properties: Object.keys(values).reduce((acc, key) => {
204
+ const schema = inferJsonSchema((values as any)[key], scope);
205
+ if (schema) {
206
+ acc[key] = schema;
207
+ }
208
+ return acc;
209
+ }, {} as Record<string, IJsonSchema>),
210
+ };
211
+ }
212
+ }
213
+ }
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { isObject } from 'lodash-es';
7
+
8
+ interface LegacyFlowRefValueSchema {
9
+ type: 'ref';
10
+ content: string;
11
+ }
12
+
13
+ interface NewFlowRefValueSchema {
14
+ type: 'ref';
15
+ content: string[];
16
+ }
17
+
18
+ /**
19
+ * In flowgram 0.2.0, for introducing Loop variable functionality,
20
+ * the FlowRefValueSchema type definition is updated:
21
+ *
22
+ * interface LegacyFlowRefValueSchema {
23
+ * type: 'ref';
24
+ * content: string;
25
+ * }
26
+ *
27
+ * interface NewFlowRefValueSchema {
28
+ * type: 'ref';
29
+ * content: string[];
30
+ * }
31
+ *
32
+ *
33
+ * For making sure backend json will not be changed, we provide format legacy ref utils for updating the formData
34
+ *
35
+ * How to use:
36
+ *
37
+ * 1. Call formatLegacyRefOnSubmit on the formData before submitting
38
+ * 2. Call formatLegacyRefOnInit on the formData after submitting
39
+ *
40
+ * Example:
41
+ * import { formatLegacyRefOnSubmit, formatLegacyRefOnInit } from '@flowgram-vue/form-materials';
42
+ * formMeta: {
43
+ * formatOnSubmit: (data) => formatLegacyRefOnSubmit(data),
44
+ * formatOnInit: (data) => formatLegacyRefOnInit(data),
45
+ * }
46
+ */
47
+ export function formatLegacyRefOnSubmit(value: any): any {
48
+ if (isObject(value)) {
49
+ if (isLegacyFlowRefValueSchema(value)) {
50
+ return formatLegacyRefToNewRef(value);
51
+ }
52
+
53
+ return Object.fromEntries(
54
+ Object.entries(value).map(([key, value]: [string, any]) => [
55
+ key,
56
+ formatLegacyRefOnSubmit(value),
57
+ ])
58
+ );
59
+ }
60
+
61
+ if (Array.isArray(value)) {
62
+ return value.map(formatLegacyRefOnSubmit);
63
+ }
64
+
65
+ return value;
66
+ }
67
+
68
+ /**
69
+ * In flowgram 0.2.0, for introducing Loop variable functionality,
70
+ * the FlowRefValueSchema type definition is updated:
71
+ *
72
+ * interface LegacyFlowRefValueSchema {
73
+ * type: 'ref';
74
+ * content: string;
75
+ * }
76
+ *
77
+ * interface NewFlowRefValueSchema {
78
+ * type: 'ref';
79
+ * content: string[];
80
+ * }
81
+ *
82
+ *
83
+ * For making sure backend json will not be changed, we provide format legacy ref utils for updating the formData
84
+ *
85
+ * How to use:
86
+ *
87
+ * 1. Call formatLegacyRefOnSubmit on the formData before submitting
88
+ * 2. Call formatLegacyRefOnInit on the formData after submitting
89
+ *
90
+ * Example:
91
+ * import { formatLegacyRefOnSubmit, formatLegacyRefOnInit } from '@flowgram-vue/form-materials';
92
+ *
93
+ * formMeta: {
94
+ * formatOnSubmit: (data) => formatLegacyRefOnSubmit(data),
95
+ * formatOnInit: (data) => formatLegacyRefOnInit(data),
96
+ * }
97
+ */
98
+ export function formatLegacyRefOnInit(value: any): any {
99
+ if (isObject(value)) {
100
+ if (isNewFlowRefValueSchema(value)) {
101
+ return formatNewRefToLegacyRef(value);
102
+ }
103
+
104
+ return Object.fromEntries(
105
+ Object.entries(value).map(([key, value]: [string, any]) => [
106
+ key,
107
+ formatLegacyRefOnInit(value),
108
+ ])
109
+ );
110
+ }
111
+
112
+ if (Array.isArray(value)) {
113
+ return value.map(formatLegacyRefOnInit);
114
+ }
115
+
116
+ return value;
117
+ }
118
+
119
+ export function isLegacyFlowRefValueSchema(value: any): value is LegacyFlowRefValueSchema {
120
+ return (
121
+ isObject(value) &&
122
+ Object.keys(value).length === 2 &&
123
+ (value as any).type === 'ref' &&
124
+ typeof (value as any).content === 'string'
125
+ );
126
+ }
127
+
128
+ export function isNewFlowRefValueSchema(value: any): value is NewFlowRefValueSchema {
129
+ return (
130
+ isObject(value) &&
131
+ Object.keys(value).length === 2 &&
132
+ (value as any).type === 'ref' &&
133
+ Array.isArray((value as any).content)
134
+ );
135
+ }
136
+
137
+ export function formatLegacyRefToNewRef(value: LegacyFlowRefValueSchema) {
138
+ const keyPath = value.content.split('.');
139
+
140
+ if (keyPath[1] === 'outputs') {
141
+ return {
142
+ type: 'ref',
143
+ content: [`${keyPath[0]}.${keyPath[1]}`, ...(keyPath.length > 2 ? keyPath.slice(2) : [])],
144
+ };
145
+ }
146
+
147
+ return {
148
+ type: 'ref',
149
+ content: keyPath,
150
+ };
151
+ }
152
+
153
+ export function formatNewRefToLegacyRef(value: NewFlowRefValueSchema) {
154
+ return {
155
+ type: 'ref',
156
+ content: value.content.join('.'),
157
+ };
158
+ }
@@ -0,0 +1,38 @@
1
+ # Notice
2
+
3
+ In `@flowgram-vue/form-materials@0.2.0`, for introducing loop-related materials,
4
+
5
+ The FlowRefValueSchema type definition is updated:
6
+
7
+ ```typescript
8
+ interface LegacyFlowRefValueSchema {
9
+ type: 'ref';
10
+ content: string;
11
+ }
12
+
13
+ interface NewFlowRefValueSchema {
14
+ type: 'ref';
15
+ content: string[];
16
+ }
17
+ ```
18
+
19
+
20
+
21
+ For making sure backend json will not be changed in your application, we provide `format-legacy-ref` utils for upgrading
22
+
23
+
24
+ How to use:
25
+
26
+ 1. Call formatLegacyRefOnSubmit on the formData before submitting
27
+ 2. Call formatLegacyRefOnInit on the formData after submitting
28
+
29
+ Example:
30
+
31
+ ```typescript
32
+ import { formatLegacyRefOnSubmit, formatLegacyRefOnInit } from '@flowgram-vue/form-materials';
33
+
34
+ formMeta: {
35
+ formatOnSubmit: (data) => formatLegacyRefOnSubmit(data),
36
+ formatOnInit: (data) => formatLegacyRefOnInit(data),
37
+ }
38
+ ```
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ export {
7
+ FlowValueUtils,
8
+ type FlowValueType,
9
+ type IFlowConstantRefValue,
10
+ type IFlowConstantValue,
11
+ type IFlowExpressionValue,
12
+ type IFlowRefValue,
13
+ type IFlowTemplateValue,
14
+ type IFlowValue,
15
+ type IFlowValueExtra,
16
+ type IInputsValues,
17
+ } from './flow-value';
18
+ export {
19
+ formatLegacyRefOnInit,
20
+ formatLegacyRefOnSubmit,
21
+ formatLegacyRefToNewRef,
22
+ formatNewRefToLegacyRef,
23
+ isLegacyFlowRefValueSchema,
24
+ isNewFlowRefValueSchema,
25
+ } from './format-legacy-refs';
26
+ export { createInjectMaterial } from './inject-material';
27
+ export { lazySuspense, withSuspense } from './lazy-suspense';
28
+ export {
29
+ polyfillCreateRoot,
30
+ unstableSetCreateRoot,
31
+ type IPolyfillRoot,
32
+ } from './polyfill-create-root';
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { defineComponent, h, type Component } from 'vue';
7
+ import { FlowRendererComponentType, FlowRendererRegistry } from '@flowgram-vue/renderer';
8
+ import { usePlaygroundContainer } from '@flowgram-vue/core';
9
+
10
+ type WithRenderKey<T> = T & { renderKey?: string };
11
+
12
+ /**
13
+ * Wraps a Vue material so consumers can replace it via FlowRendererRegistry.
14
+ */
15
+ export function createInjectMaterial<Props>(
16
+ Component: WithRenderKey<Component>,
17
+ params?: {
18
+ renderKey?: string;
19
+ }
20
+ ): WithRenderKey<Component> {
21
+ const renderKey =
22
+ params?.renderKey || Component.renderKey || (Component as { name?: string }).name || '';
23
+
24
+ const InjectComponent = defineComponent({
25
+ name: `Inject${(Component as { name?: string }).name || 'Material'}`,
26
+ inheritAttrs: false,
27
+ setup(_props, { attrs, slots }) {
28
+ const container = usePlaygroundContainer();
29
+
30
+ return () => {
31
+ if (!container?.isBound?.(FlowRendererRegistry)) {
32
+ return h(Component, attrs, slots);
33
+ }
34
+
35
+ const rendererRegistry = container.get(FlowRendererRegistry);
36
+ const renderer = rendererRegistry.tryToGetRendererComponent(renderKey);
37
+
38
+ if (renderer?.type !== FlowRendererComponentType.VUE) {
39
+ return h(Component, attrs, slots);
40
+ }
41
+
42
+ return h(renderer.renderer as Component, attrs, slots);
43
+ };
44
+ },
45
+ }) as WithRenderKey<Component>;
46
+
47
+ InjectComponent.renderKey = renderKey;
48
+
49
+ return InjectComponent;
50
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { defineAsyncComponent, h, type AsyncComponentLoader, type Component } from 'vue';
7
+
8
+ export function withSuspense<T extends Component>(Component: T, _fallback?: Component): T {
9
+ return Component;
10
+ }
11
+
12
+ export function lazySuspense(loader: AsyncComponentLoader, fallback?: Component) {
13
+ return defineAsyncComponent({
14
+ loader,
15
+ loadingComponent: fallback || {
16
+ name: 'FgSkeleton',
17
+ render: () => h('div', { class: 'fg-skeleton' }),
18
+ },
19
+ });
20
+ }