@flowgram.ai/form-materials 0.1.0-alpha.13 → 0.1.0-alpha.14

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 (97) hide show
  1. package/bin/index.ts +0 -11
  2. package/bin/materials.ts +29 -2
  3. package/dist/esm/chunk-727SU246.js +13 -0
  4. package/dist/esm/chunk-727SU246.js.map +1 -0
  5. package/dist/esm/chunk-DEZUEMUM.js +284 -0
  6. package/dist/esm/chunk-DEZUEMUM.js.map +1 -0
  7. package/dist/esm/chunk-DUOXDOUE.js +477 -0
  8. package/dist/esm/chunk-DUOXDOUE.js.map +1 -0
  9. package/dist/esm/editor-6UMULJYB.js +180 -0
  10. package/dist/esm/editor-6UMULJYB.js.map +1 -0
  11. package/dist/esm/editor-EYOQTGMT.js +282 -0
  12. package/dist/esm/editor-EYOQTGMT.js.map +1 -0
  13. package/dist/esm/editor-OXPGKPF5.js +167 -0
  14. package/dist/esm/editor-OXPGKPF5.js.map +1 -0
  15. package/dist/esm/editor-VO6YAXRC.js +249 -0
  16. package/dist/esm/editor-VO6YAXRC.js.map +1 -0
  17. package/dist/esm/editor-XYLKTB6L.js +365 -0
  18. package/dist/esm/editor-XYLKTB6L.js.map +1 -0
  19. package/dist/esm/index.js +1110 -2306
  20. package/dist/esm/index.js.map +1 -1
  21. package/dist/index.d.mts +298 -59
  22. package/dist/index.d.ts +298 -59
  23. package/dist/index.js +3932 -2681
  24. package/dist/index.js.map +1 -1
  25. package/package.json +9 -8
  26. package/src/components/batch-outputs/index.tsx +3 -2
  27. package/src/components/code-editor/editor.tsx +89 -0
  28. package/src/components/code-editor/index.tsx +5 -89
  29. package/src/components/code-editor/language-features.ts +18 -18
  30. package/src/components/code-editor/theme/dark.ts +49 -30
  31. package/src/components/code-editor/theme/light.ts +56 -32
  32. package/src/components/code-editor-mini/index.tsx +2 -2
  33. package/src/components/condition-row/constants.ts +8 -0
  34. package/src/components/condition-row/index.tsx +4 -0
  35. package/src/components/db-condition-row/hooks/use-left.tsx +66 -0
  36. package/src/components/db-condition-row/hooks/use-op.tsx +59 -0
  37. package/src/components/db-condition-row/index.tsx +93 -0
  38. package/src/components/db-condition-row/styles.tsx +43 -0
  39. package/src/components/db-condition-row/types.ts +34 -0
  40. package/src/components/display-flow-value/index.tsx +2 -12
  41. package/src/components/display-inputs-values/index.tsx +44 -6
  42. package/src/components/dynamic-value-input/hooks.ts +25 -4
  43. package/src/components/dynamic-value-input/index.tsx +21 -12
  44. package/src/components/dynamic-value-input/styles.tsx +14 -4
  45. package/src/components/index.ts +3 -0
  46. package/src/components/inputs-values/index.tsx +14 -3
  47. package/src/components/inputs-values/styles.tsx +1 -1
  48. package/src/components/inputs-values-tree/hooks/use-child-list.tsx +76 -0
  49. package/src/components/inputs-values-tree/index.tsx +62 -0
  50. package/src/components/inputs-values-tree/row.tsx +177 -0
  51. package/src/components/inputs-values-tree/styles.tsx +128 -0
  52. package/src/components/inputs-values-tree/types.ts +21 -0
  53. package/src/components/json-editor-with-variables/editor.tsx +69 -0
  54. package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +6 -5
  55. package/src/components/json-editor-with-variables/index.tsx +5 -59
  56. package/src/components/json-schema-editor/default-value.tsx +1 -3
  57. package/src/components/json-schema-editor/hooks.tsx +14 -3
  58. package/src/components/json-schema-editor/index.tsx +18 -58
  59. package/src/components/json-schema-editor/styles.tsx +12 -55
  60. package/src/components/json-schema-editor/types.ts +0 -1
  61. package/src/components/prompt-editor/editor.tsx +81 -0
  62. package/src/components/prompt-editor/index.tsx +5 -62
  63. package/src/components/prompt-editor-with-inputs/editor.tsx +25 -0
  64. package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +11 -0
  65. package/src/components/prompt-editor-with-inputs/index.tsx +5 -16
  66. package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +34 -17
  67. package/src/components/prompt-editor-with-variables/editor.tsx +22 -0
  68. package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +12 -20
  69. package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +13 -1
  70. package/src/components/prompt-editor-with-variables/index.tsx +5 -13
  71. package/src/components/type-selector/index.tsx +12 -2
  72. package/src/components/variable-selector/context.tsx +28 -0
  73. package/src/components/variable-selector/index.tsx +10 -1
  74. package/src/components/variable-selector/use-variable-tree.tsx +3 -3
  75. package/src/effects/auto-rename-ref/index.ts +7 -54
  76. package/src/effects/validate-when-variable-sync/index.ts +1 -1
  77. package/src/form-plugins/infer-assign-plugin/index.ts +1 -1
  78. package/src/form-plugins/infer-inputs-plugin/index.ts +4 -76
  79. package/src/hooks/use-object-list/index.tsx +35 -7
  80. package/src/index.ts +1 -0
  81. package/src/plugins/json-schema-preset/manager.ts +1 -0
  82. package/src/plugins/json-schema-preset/type-definition/date-time.tsx +25 -0
  83. package/src/plugins/json-schema-preset/type-definition/index.tsx +2 -0
  84. package/src/plugins/json-schema-preset/type-definition/string.tsx +18 -9
  85. package/src/shared/flow-value/index.ts +6 -0
  86. package/src/shared/flow-value/schema.ts +38 -0
  87. package/src/shared/flow-value/utils.ts +201 -0
  88. package/src/shared/format-legacy-refs/index.ts +1 -1
  89. package/src/shared/index.ts +3 -0
  90. package/src/shared/lazy-suspense/index.tsx +28 -0
  91. package/src/shared/polyfill-create-root/index.tsx +33 -0
  92. package/src/typings/flow-value/index.ts +3 -1
  93. package/src/validate/validate-flow-value/index.tsx +4 -16
  94. package/src/components/json-schema-editor/components/blur-input.tsx +0 -27
  95. package/src/plugins/disable-declaration-plugin/config.json +0 -5
  96. package/src/plugins/json-schema-preset/config.json +0 -9
  97. /package/src/components/{inputs-values/components/blur-input.tsx → blur-input/index.tsx} +0 -0
@@ -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,201 @@
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.ai/json-schema';
8
+ import { Scope } from '@flowgram.ai/editor';
9
+
10
+ import {
11
+ IFlowConstantValue,
12
+ IFlowRefValue,
13
+ IFlowExpressionValue,
14
+ IFlowTemplateValue,
15
+ IFlowValue,
16
+ IFlowConstantRefValue,
17
+ FlowValueType,
18
+ } from '@/typings';
19
+
20
+ import { constantSchema, refSchema, expressionSchema, templateSchema } from './schema';
21
+
22
+ export namespace FlowValueUtils {
23
+ /**
24
+ * Check if the value is a constant type
25
+ */
26
+ export function isConstant(value: any): value is IFlowConstantValue {
27
+ return constantSchema.safeParse(value).success;
28
+ }
29
+
30
+ /**
31
+ * Check if the value is a reference type
32
+ */
33
+ export function isRef(value: any): value is IFlowRefValue {
34
+ return refSchema.safeParse(value).success;
35
+ }
36
+
37
+ /**
38
+ * Check if the value is an expression type
39
+ */
40
+ export function isExpression(value: any): value is IFlowExpressionValue {
41
+ return expressionSchema.safeParse(value).success;
42
+ }
43
+
44
+ /**
45
+ * Check if the value is a template type
46
+ */
47
+ export function isTemplate(value: any): value is IFlowTemplateValue {
48
+ return templateSchema.safeParse(value).success;
49
+ }
50
+
51
+ /**
52
+ * Check if the value is either a constant or reference type
53
+ */
54
+ export function isConstantOrRef(value: any): value is IFlowConstantRefValue {
55
+ return isConstant(value) || isRef(value);
56
+ }
57
+
58
+ /**
59
+ * Check if the value is a valid flow value type
60
+ */
61
+ export function isFlowValue(value: any): value is IFlowValue {
62
+ return isConstant(value) || isRef(value) || isExpression(value) || isTemplate(value);
63
+ }
64
+
65
+ /**
66
+ * Traverse all flow values in the given value
67
+ * @param value The value to traverse
68
+ * @param options The options to traverse
69
+ * @returns A generator of flow values
70
+ */
71
+ export function* traverse(
72
+ value: any,
73
+ options: {
74
+ includeTypes?: FlowValueType[];
75
+ path?: string;
76
+ }
77
+ ): Generator<{ value: IFlowValue; path: string }> {
78
+ const { includeTypes = ['ref', 'template'], path = '' } = options;
79
+
80
+ if (isPlainObject(value)) {
81
+ if (isRef(value) && includeTypes.includes('ref')) {
82
+ yield { value, path };
83
+ return;
84
+ }
85
+
86
+ if (isTemplate(value) && includeTypes.includes('template')) {
87
+ yield { value, path };
88
+ return;
89
+ }
90
+
91
+ if (isExpression(value) && includeTypes.includes('expression')) {
92
+ yield { value, path };
93
+ return;
94
+ }
95
+
96
+ if (isConstant(value) && includeTypes.includes('constant')) {
97
+ yield { value, path };
98
+ return;
99
+ }
100
+
101
+ for (const [_key, _value] of Object.entries(value)) {
102
+ yield* traverse(_value, { ...options, path: `${path}.${_key}` });
103
+ }
104
+ return;
105
+ }
106
+
107
+ if (isArray(value)) {
108
+ for (const [_idx, _value] of value.entries()) {
109
+ yield* traverse(_value, { ...options, path: `${path}[${_idx}]` });
110
+ }
111
+ return;
112
+ }
113
+
114
+ return;
115
+ }
116
+
117
+ /**
118
+ * Get all key paths in the template value
119
+ * @param value The template value
120
+ * @returns A list of key paths
121
+ */
122
+ export function getTemplateKeyPaths(value: IFlowTemplateValue) {
123
+ // find all keyPath wrapped in {{}}
124
+ const keyPathReg = /\{\{([^\}\{]+)\}\}/g;
125
+ return uniq(value.content?.match(keyPathReg) || []).map((_keyPath) =>
126
+ _keyPath.slice(2, -2).split('.')
127
+ );
128
+ }
129
+
130
+ /**
131
+ * Infer the schema of the constant value
132
+ * @param value
133
+ * @returns
134
+ */
135
+ export function inferConstantJsonSchema(value: IFlowConstantValue): IJsonSchema | undefined {
136
+ if (value?.schema) {
137
+ return value.schema;
138
+ }
139
+
140
+ if (typeof value.content === 'string') {
141
+ return {
142
+ type: 'string',
143
+ };
144
+ }
145
+
146
+ if (typeof value.content === 'number') {
147
+ return {
148
+ type: 'number',
149
+ };
150
+ }
151
+
152
+ if (typeof value.content === 'boolean') {
153
+ return {
154
+ type: 'boolean',
155
+ };
156
+ }
157
+
158
+ if (isObject(value.content)) {
159
+ return {
160
+ type: 'object',
161
+ };
162
+ }
163
+ return undefined;
164
+ }
165
+
166
+ /**
167
+ * Infer the schema of the flow value
168
+ * @param values The flow value or object contains flow value
169
+ * @param scope
170
+ * @returns
171
+ */
172
+ export function inferJsonSchema(values: any, scope: Scope): IJsonSchema | undefined {
173
+ if (isPlainObject(values)) {
174
+ if (isConstant(values)) {
175
+ return inferConstantJsonSchema(values);
176
+ }
177
+
178
+ if (isRef(values)) {
179
+ const variable = scope.available.getByKeyPath(values?.content);
180
+ const schema = variable?.type ? JsonSchemaUtils.astToSchema(variable?.type) : undefined;
181
+
182
+ return schema;
183
+ }
184
+
185
+ if (isTemplate(values)) {
186
+ return { type: 'string' };
187
+ }
188
+
189
+ return {
190
+ type: 'object',
191
+ properties: Object.keys(values).reduce((acc, key) => {
192
+ const schema = inferJsonSchema((values as any)[key], scope);
193
+ if (schema) {
194
+ acc[key] = schema;
195
+ }
196
+ return acc;
197
+ }, {} as Record<string, IJsonSchema>),
198
+ };
199
+ }
200
+ }
201
+ }
@@ -3,7 +3,7 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { isObject } from 'lodash';
6
+ import { isObject } from 'lodash-es';
7
7
 
8
8
  interface LegacyFlowRefValueSchema {
9
9
  type: 'ref';
@@ -5,3 +5,6 @@
5
5
 
6
6
  export * from './format-legacy-refs';
7
7
  export * from './inject-material';
8
+ export * from './flow-value';
9
+ export * from './polyfill-create-root';
10
+ export * from './lazy-suspense';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import React, { ComponentType, lazy, Suspense } from 'react';
7
+
8
+ import { Skeleton } from '@douyinfe/semi-ui';
9
+
10
+ export function withSuspense<T extends ComponentType<any>>(
11
+ Component: T,
12
+ fallback?: React.ReactNode
13
+ ): T {
14
+ const WithSuspenseComponent: T = ((props: any) => (
15
+ <Suspense fallback={fallback || <Skeleton.Paragraph style={{ width: '100%' }} rows={1} />}>
16
+ <Component {...props} />
17
+ </Suspense>
18
+ )) as any;
19
+
20
+ return WithSuspenseComponent;
21
+ }
22
+
23
+ export function lazySuspense<T extends ComponentType<any>>(
24
+ params: Parameters<typeof lazy<T>>[0],
25
+ fallback?: React.ReactNode
26
+ ) {
27
+ return withSuspense(lazy(params), fallback);
28
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import * as ReactDOM from 'react-dom';
7
+
8
+ export interface IPolyfillRoot {
9
+ render(children: React.ReactNode): void;
10
+ unmount(): void;
11
+ }
12
+
13
+ /**
14
+ * React 18 polyfill
15
+ * @param dom
16
+ * @returns
17
+ */
18
+ let unstableCreateRoot = (dom: HTMLElement): IPolyfillRoot => ({
19
+ render(children: JSX.Element) {
20
+ ReactDOM.render(children, dom);
21
+ },
22
+ unmount() {
23
+ ReactDOM.unmountComponentAtNode(dom);
24
+ },
25
+ });
26
+
27
+ export function polyfillCreateRoot(dom: HTMLElement): IPolyfillRoot {
28
+ return unstableCreateRoot(dom);
29
+ }
30
+
31
+ export function unstableSetCreateRoot(createRoot: (dom: HTMLElement) => IPolyfillRoot) {
32
+ unstableCreateRoot = createRoot;
33
+ }
@@ -9,9 +9,11 @@ export interface IFlowValueExtra {
9
9
  index?: number;
10
10
  }
11
11
 
12
+ export type FlowValueType = 'constant' | 'ref' | 'expression' | 'template';
13
+
12
14
  export interface IFlowConstantValue {
13
15
  type: 'constant';
14
- content?: string | number | boolean;
16
+ content?: any;
15
17
  schema?: IJsonSchema;
16
18
  extra?: IFlowValueExtra;
17
19
  }
@@ -3,10 +3,11 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { isNil, uniq } from 'lodash';
6
+ import { isNil } from 'lodash-es';
7
7
  import { FeedbackLevel, FlowNodeEntity, getNodeScope } from '@flowgram.ai/editor';
8
8
 
9
- import { IFlowTemplateValue, IFlowValue } from '@/typings';
9
+ import { IFlowValue } from '@/typings';
10
+ import { FlowValueUtils } from '@/shared';
10
11
 
11
12
  interface Context {
12
13
  node: FlowNodeEntity;
@@ -43,7 +44,7 @@ export function validateFlowValue(value: IFlowValue | undefined, ctx: Context) {
43
44
  }
44
45
 
45
46
  if (value?.type === 'template') {
46
- const allRefs = getTemplateKeyPaths(value);
47
+ const allRefs = FlowValueUtils.getTemplateKeyPaths(value);
47
48
 
48
49
  for (const ref of allRefs) {
49
50
  const variable = getNodeScope(node).available.getByKeyPath(ref);
@@ -58,16 +59,3 @@ export function validateFlowValue(value: IFlowValue | undefined, ctx: Context) {
58
59
 
59
60
  return undefined;
60
61
  }
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
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
- * SPDX-License-Identifier: MIT
4
- */
5
-
6
- import React, { useEffect, useState } from 'react';
7
-
8
- import Input, { InputProps } from '@douyinfe/semi-ui/lib/es/input';
9
-
10
- export function BlurInput(props: InputProps) {
11
- const [value, setValue] = useState('');
12
-
13
- useEffect(() => {
14
- setValue(props.value as string);
15
- }, [props.value]);
16
-
17
- return (
18
- <Input
19
- {...props}
20
- value={value}
21
- onChange={(value) => {
22
- setValue(value);
23
- }}
24
- onBlur={(e) => props.onChange?.(value, e)}
25
- />
26
- );
27
- }
@@ -1,5 +0,0 @@
1
- {
2
- "name": "disable-declaration-plugin",
3
- "depMaterials": [],
4
- "depPackages": []
5
- }
@@ -1,9 +0,0 @@
1
- {
2
- "name": "json-schema-preset",
3
- "depMaterials": [
4
- "components/code-editor-mini"
5
- ],
6
- "depPackages": [
7
- "@flowgram.ai/json-schema"
8
- ]
9
- }