@flowgram.ai/form-materials 0.1.0-alpha.12 → 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 (164) hide show
  1. package/bin/index.ts +4 -29
  2. package/bin/materials.ts +56 -87
  3. package/bin/project.ts +4 -0
  4. package/bin/utils/import.ts +127 -0
  5. package/bin/utils/traverse-file.ts +60 -0
  6. package/dist/esm/chunk-727SU246.js +13 -0
  7. package/dist/esm/chunk-727SU246.js.map +1 -0
  8. package/dist/esm/chunk-DEZUEMUM.js +284 -0
  9. package/dist/esm/chunk-DEZUEMUM.js.map +1 -0
  10. package/dist/esm/chunk-DUOXDOUE.js +477 -0
  11. package/dist/esm/chunk-DUOXDOUE.js.map +1 -0
  12. package/dist/esm/editor-6UMULJYB.js +180 -0
  13. package/dist/esm/editor-6UMULJYB.js.map +1 -0
  14. package/dist/esm/editor-EYOQTGMT.js +282 -0
  15. package/dist/esm/editor-EYOQTGMT.js.map +1 -0
  16. package/dist/esm/editor-OXPGKPF5.js +167 -0
  17. package/dist/esm/editor-OXPGKPF5.js.map +1 -0
  18. package/dist/esm/editor-VO6YAXRC.js +249 -0
  19. package/dist/esm/editor-VO6YAXRC.js.map +1 -0
  20. package/dist/esm/editor-XYLKTB6L.js +365 -0
  21. package/dist/esm/editor-XYLKTB6L.js.map +1 -0
  22. package/dist/esm/index.js +1186 -2456
  23. package/dist/esm/index.js.map +1 -1
  24. package/dist/index.d.mts +363 -70
  25. package/dist/index.d.ts +363 -70
  26. package/dist/index.js +4064 -2887
  27. package/dist/index.js.map +1 -1
  28. package/package.json +9 -8
  29. package/src/components/assign-row/index.tsx +4 -4
  30. package/src/components/assign-rows/index.tsx +1 -1
  31. package/src/components/batch-outputs/index.tsx +7 -5
  32. package/src/components/batch-outputs/types.ts +1 -1
  33. package/src/components/batch-variable-selector/index.tsx +1 -1
  34. package/src/components/code-editor/editor.tsx +89 -0
  35. package/src/components/code-editor/index.tsx +5 -89
  36. package/src/components/code-editor/language-features.ts +18 -18
  37. package/src/components/code-editor/theme/dark.ts +49 -30
  38. package/src/components/code-editor/theme/light.ts +56 -32
  39. package/src/components/code-editor-mini/index.tsx +2 -2
  40. package/src/components/condition-row/constants.ts +10 -2
  41. package/src/components/condition-row/hooks/useOp.tsx +13 -9
  42. package/src/components/condition-row/hooks/useRule.ts +8 -4
  43. package/src/components/condition-row/index.tsx +31 -10
  44. package/src/components/condition-row/types.ts +5 -7
  45. package/src/components/constant-input/index.tsx +5 -2
  46. package/src/components/constant-input/types.ts +1 -1
  47. package/src/components/db-condition-row/hooks/use-left.tsx +66 -0
  48. package/src/components/db-condition-row/hooks/use-op.tsx +59 -0
  49. package/src/components/db-condition-row/index.tsx +93 -0
  50. package/src/components/db-condition-row/styles.tsx +43 -0
  51. package/src/components/db-condition-row/types.ts +34 -0
  52. package/src/components/display-flow-value/index.tsx +4 -14
  53. package/src/components/display-inputs-values/index.tsx +46 -7
  54. package/src/components/display-outputs/index.tsx +2 -1
  55. package/src/components/display-schema-tag/index.tsx +3 -2
  56. package/src/components/display-schema-tree/index.tsx +2 -1
  57. package/src/components/dynamic-value-input/hooks.ts +25 -4
  58. package/src/components/dynamic-value-input/index.tsx +33 -20
  59. package/src/components/dynamic-value-input/styles.tsx +14 -4
  60. package/src/components/index.ts +3 -0
  61. package/src/components/inputs-values/index.tsx +21 -8
  62. package/src/components/inputs-values/styles.tsx +1 -1
  63. package/src/components/inputs-values/types.ts +3 -3
  64. package/src/components/inputs-values-tree/hooks/use-child-list.tsx +76 -0
  65. package/src/components/inputs-values-tree/index.tsx +62 -0
  66. package/src/components/inputs-values-tree/row.tsx +177 -0
  67. package/src/components/inputs-values-tree/styles.tsx +128 -0
  68. package/src/components/inputs-values-tree/types.ts +21 -0
  69. package/src/components/json-editor-with-variables/editor.tsx +69 -0
  70. package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +6 -5
  71. package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +1 -1
  72. package/src/components/json-editor-with-variables/index.tsx +5 -58
  73. package/src/components/json-schema-editor/default-value.tsx +12 -108
  74. package/src/components/json-schema-editor/hooks.tsx +63 -93
  75. package/src/components/json-schema-editor/index.tsx +36 -70
  76. package/src/components/json-schema-editor/styles.tsx +12 -84
  77. package/src/components/json-schema-editor/types.ts +0 -1
  78. package/src/components/prompt-editor/editor.tsx +81 -0
  79. package/src/components/prompt-editor/index.tsx +5 -62
  80. package/src/components/prompt-editor/types.tsx +1 -1
  81. package/src/components/prompt-editor-with-inputs/editor.tsx +25 -0
  82. package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +13 -1
  83. package/src/components/prompt-editor-with-inputs/index.tsx +5 -15
  84. package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +34 -17
  85. package/src/components/prompt-editor-with-variables/editor.tsx +22 -0
  86. package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +12 -20
  87. package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +14 -2
  88. package/src/components/prompt-editor-with-variables/index.tsx +5 -12
  89. package/src/components/type-selector/index.tsx +21 -9
  90. package/src/components/variable-selector/context.tsx +28 -0
  91. package/src/components/variable-selector/index.tsx +19 -6
  92. package/src/components/variable-selector/use-variable-tree.tsx +4 -4
  93. package/src/effects/auto-rename-ref/index.ts +8 -55
  94. package/src/effects/listen-ref-schema-change/index.ts +1 -1
  95. package/src/effects/listen-ref-value-change/index.ts +1 -1
  96. package/src/effects/provide-batch-input/index.ts +1 -1
  97. package/src/effects/validate-when-variable-sync/index.ts +1 -1
  98. package/src/form-plugins/batch-outputs-plugin/index.ts +1 -1
  99. package/src/form-plugins/infer-assign-plugin/index.ts +2 -2
  100. package/src/form-plugins/infer-inputs-plugin/index.ts +4 -76
  101. package/src/hooks/use-object-list/index.tsx +35 -7
  102. package/src/index.ts +1 -0
  103. package/src/plugins/json-schema-preset/manager.ts +1 -0
  104. package/src/plugins/json-schema-preset/type-definition/array.tsx +3 -1
  105. package/src/plugins/json-schema-preset/type-definition/boolean.tsx +4 -3
  106. package/src/plugins/json-schema-preset/type-definition/date-time.tsx +25 -0
  107. package/src/plugins/json-schema-preset/type-definition/index.tsx +2 -0
  108. package/src/plugins/json-schema-preset/type-definition/integer.tsx +2 -1
  109. package/src/plugins/json-schema-preset/type-definition/number.tsx +2 -1
  110. package/src/plugins/json-schema-preset/type-definition/object.tsx +3 -1
  111. package/src/plugins/json-schema-preset/type-definition/string.tsx +19 -4
  112. package/src/shared/flow-value/index.ts +6 -0
  113. package/src/shared/flow-value/schema.ts +38 -0
  114. package/src/shared/flow-value/utils.ts +201 -0
  115. package/src/shared/format-legacy-refs/index.ts +1 -1
  116. package/src/shared/index.ts +4 -0
  117. package/src/shared/inject-material/README.md +170 -0
  118. package/src/shared/inject-material/README.zh.md +174 -0
  119. package/src/shared/inject-material/index.tsx +87 -0
  120. package/src/shared/lazy-suspense/index.tsx +28 -0
  121. package/src/shared/polyfill-create-root/index.tsx +33 -0
  122. package/src/typings/flow-value/index.ts +3 -1
  123. package/src/validate/validate-flow-value/index.tsx +4 -16
  124. package/src/components/assign-row/config.json +0 -11
  125. package/src/components/assign-rows/config.json +0 -11
  126. package/src/components/batch-outputs/config.json +0 -13
  127. package/src/components/batch-variable-selector/config.json +0 -9
  128. package/src/components/code-editor/config.json +0 -10
  129. package/src/components/code-editor-mini/config.json +0 -7
  130. package/src/components/condition-row/config.json +0 -13
  131. package/src/components/constant-input/config.json +0 -9
  132. package/src/components/display-flow-value/config.json +0 -8
  133. package/src/components/display-inputs-values/config.json +0 -9
  134. package/src/components/display-outputs/config.json +0 -10
  135. package/src/components/display-schema-tag/config.json +0 -10
  136. package/src/components/display-schema-tree/config.json +0 -11
  137. package/src/components/dynamic-value-input/config.json +0 -14
  138. package/src/components/inputs-values/config.json +0 -13
  139. package/src/components/json-editor-with-variables/config.json +0 -13
  140. package/src/components/json-schema-editor/components/blur-input.tsx +0 -27
  141. package/src/components/json-schema-editor/config.json +0 -13
  142. package/src/components/json-schema-editor/utils.ts +0 -29
  143. package/src/components/prompt-editor/config.json +0 -9
  144. package/src/components/prompt-editor-with-inputs/config.json +0 -13
  145. package/src/components/prompt-editor-with-variables/config.json +0 -13
  146. package/src/components/type-selector/config.json +0 -9
  147. package/src/components/variable-selector/config.json +0 -9
  148. package/src/effects/auto-rename-ref/config.json +0 -5
  149. package/src/effects/listen-ref-schema-change/config.json +0 -10
  150. package/src/effects/listen-ref-value-change/config.json +0 -9
  151. package/src/effects/provide-batch-input/config.json +0 -5
  152. package/src/effects/provide-json-schema-outputs/config.json +0 -7
  153. package/src/effects/sync-variable-title/config.json +0 -5
  154. package/src/effects/validate-when-variable-sync/config.json +0 -5
  155. package/src/form-plugins/batch-outputs-plugin/config.json +0 -7
  156. package/src/form-plugins/infer-assign-plugin/config.json +0 -7
  157. package/src/form-plugins/infer-inputs-plugin/config.json +0 -9
  158. package/src/hooks/use-object-list/config.json +0 -8
  159. package/src/plugins/disable-declaration-plugin/config.json +0 -5
  160. package/src/plugins/json-schema-preset/config.json +0 -9
  161. package/src/shared/format-legacy-refs/config.json +0 -5
  162. package/src/typings/flow-value/config.json +0 -7
  163. package/src/validate/validate-flow-value/config.json +0 -7
  164. /package/src/components/{inputs-values/components/blur-input.tsx → blur-input/index.tsx} +0 -0
@@ -5,7 +5,7 @@
5
5
 
6
6
  import React, { useMemo } from 'react';
7
7
 
8
- import { last } from 'lodash';
8
+ import { isPlainObject, last } from 'lodash-es';
9
9
  import {
10
10
  type ArrayType,
11
11
  ASTMatch,
@@ -16,7 +16,7 @@ import {
16
16
  import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
17
17
  import { Tree } from '@douyinfe/semi-ui';
18
18
 
19
- import { IFlowValue } from '../../typings';
19
+ import { FlowValueUtils } from '@/shared';
20
20
 
21
21
  type VariableField = BaseVariableField<{ icon?: string | JSX.Element; title?: string }>;
22
22
 
@@ -24,7 +24,7 @@ export function InputsPicker({
24
24
  inputsValues,
25
25
  onSelect,
26
26
  }: {
27
- inputsValues: Record<string, IFlowValue>;
27
+ inputsValues: any;
28
28
  onSelect: (v: string) => void;
29
29
  }) {
30
30
  const available = useScopeAvailable();
@@ -76,23 +76,40 @@ export function InputsPicker({
76
76
  };
77
77
  };
78
78
 
79
- const treeData: TreeNodeData[] = useMemo(
80
- () =>
81
- Object.entries(inputsValues).map(([key, value]) => {
82
- if (value?.type === 'ref') {
83
- const variable = available.getByKeyPath(value.content || []);
79
+ const getTreeData = (value: any, keyPath: string[]): TreeNodeData | undefined => {
80
+ const currKey = keyPath.join('.');
84
81
 
85
- if (variable) {
86
- return renderVariable(variable, [key]);
87
- }
82
+ if (FlowValueUtils.isFlowValue(value)) {
83
+ if (FlowValueUtils.isRef(value)) {
84
+ const variable = available.getByKeyPath(value.content || []);
85
+ if (variable) {
86
+ return renderVariable(variable, keyPath);
88
87
  }
88
+ }
89
+ return {
90
+ key: currKey,
91
+ value: currKey,
92
+ label: last(keyPath),
93
+ };
94
+ }
89
95
 
90
- return {
91
- key,
92
- value: key,
93
- label: key,
94
- };
95
- }),
96
+ if (isPlainObject(value)) {
97
+ return {
98
+ key: currKey,
99
+ value: currKey,
100
+ label: last(keyPath),
101
+ children: Object.entries(value)
102
+ .map(([key, value]) => getTreeData(value, [...keyPath, key])!)
103
+ .filter(Boolean),
104
+ };
105
+ }
106
+ };
107
+
108
+ const treeData: TreeNodeData[] = useMemo(
109
+ () =>
110
+ Object.entries(inputsValues)
111
+ .map(([key, value]) => getTreeData(value, [key])!)
112
+ .filter(Boolean),
96
113
  []
97
114
  );
98
115
 
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import React from 'react';
7
+
8
+ import { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';
9
+
10
+ import { VariableTree } from './extensions/variable-tree';
11
+ import { VariableTagInject } from './extensions/variable-tag';
12
+
13
+ export interface PromptEditorWithVariablesProps extends PromptEditorPropsType {}
14
+
15
+ export function PromptEditorWithVariables(props: PromptEditorWithVariablesProps) {
16
+ return (
17
+ <PromptEditor {...props}>
18
+ <VariableTree />
19
+ <VariableTagInject />
20
+ </PromptEditor>
21
+ );
22
+ }
@@ -3,10 +3,9 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import ReactDOM from 'react-dom';
7
6
  import React, { useLayoutEffect } from 'react';
8
7
 
9
- import { isEqual, last } from 'lodash';
8
+ import { isEqual, last } from 'lodash-es';
10
9
  import {
11
10
  BaseVariableField,
12
11
  Disposable,
@@ -26,6 +25,8 @@ import {
26
25
  WidgetType,
27
26
  } from '@codemirror/view';
28
27
 
28
+ import { IPolyfillRoot, polyfillCreateRoot } from '@/shared';
29
+
29
30
  import { UIPopoverContent, UIRootTitle, UITag, UIVarName } from '../styles';
30
31
 
31
32
  class VariableTagWidget extends WidgetType {
@@ -35,7 +36,7 @@ class VariableTagWidget extends WidgetType {
35
36
 
36
37
  scope: Scope;
37
38
 
38
- rootDOM?: HTMLSpanElement;
39
+ root: IPolyfillRoot;
39
40
 
40
41
  constructor({ keyPath, scope }: { keyPath?: string[]; scope: Scope }) {
41
42
  super();
@@ -52,14 +53,9 @@ class VariableTagWidget extends WidgetType {
52
53
  return icon;
53
54
  };
54
55
 
55
- renderReact(jsx: React.ReactElement) {
56
- // NOTICE: For React 19, upgrade to 'react-dom/client'
57
- ReactDOM.render(jsx, this.rootDOM!);
58
- }
59
-
60
56
  renderVariable(v?: BaseVariableField) {
61
57
  if (!v) {
62
- this.renderReact(
58
+ this.root.render(
63
59
  <UITag prefixIcon={<IconIssueStroked />} color="amber">
64
60
  Unknown
65
61
  </UITag>
@@ -67,17 +63,14 @@ class VariableTagWidget extends WidgetType {
67
63
  return;
68
64
  }
69
65
 
70
- const rootField = last(v.parentFields) || v;
71
- const isRoot = v.parentFields.length === 0;
66
+ const rootField = last(v.parentFields);
72
67
 
73
68
  const rootTitle = (
74
- <UIRootTitle>
75
- {rootField?.meta.title ? `${rootField.meta.title} ${isRoot ? '' : '-'} ` : ''}
76
- </UIRootTitle>
69
+ <UIRootTitle>{rootField?.meta.title ? `${rootField.meta.title} -` : ''}</UIRootTitle>
77
70
  );
78
71
  const rootIcon = this.renderIcon(rootField?.meta.icon);
79
72
 
80
- this.renderReact(
73
+ this.root.render(
81
74
  <Popover
82
75
  content={
83
76
  <UIPopoverContent>
@@ -89,7 +82,7 @@ class VariableTagWidget extends WidgetType {
89
82
  >
90
83
  <UITag prefixIcon={rootIcon}>
91
84
  {rootTitle}
92
- {!isRoot && <UIVarName>{v?.key}</UIVarName>}
85
+ <UIVarName>{v?.key}</UIVarName>
93
86
  </UITag>
94
87
  </Popover>
95
88
  );
@@ -98,12 +91,11 @@ class VariableTagWidget extends WidgetType {
98
91
  toDOM(view: EditorView): HTMLElement {
99
92
  const dom = document.createElement('span');
100
93
 
101
- this.rootDOM = dom;
94
+ this.root = polyfillCreateRoot(dom);
102
95
 
103
96
  this.toDispose.push(
104
97
  Disposable.create(() => {
105
- // NOTICE: For React 19, upgrade to 'react-dom/client'
106
- ReactDOM.unmountComponentAtNode(this.rootDOM!);
98
+ this.root.unmount();
107
99
  })
108
100
  );
109
101
 
@@ -143,7 +135,7 @@ export function VariableTagInject() {
143
135
  // 基于 {{var}} 的正则进行匹配,匹配后进行自定义渲染
144
136
  useLayoutEffect(() => {
145
137
  const atMatcher = new MatchDecorator({
146
- regexp: /\{\{([^\}]+)\}\}/g,
138
+ regexp: /\{\{([^\}\{]+)\}\}/g,
147
139
  decoration: (match) =>
148
140
  Decoration.replace({
149
141
  widget: new VariableTagWidget({
@@ -15,7 +15,7 @@ import {
15
15
  } from '@coze-editor/editor/react';
16
16
  import { EditorAPI } from '@coze-editor/editor/preset-prompt';
17
17
 
18
- import { useVariableTree } from '../../variable-selector';
18
+ import { useVariableTree } from '@/components/variable-selector';
19
19
 
20
20
  export function VariableTree() {
21
21
  const [posKey, setPosKey] = useState('');
@@ -30,8 +30,20 @@ export function VariableTree() {
30
30
  return;
31
31
  }
32
32
 
33
+ /**
34
+ * When user input {{xxxx}}, {{{xxx}}}(more brackets if possible), replace all brackets with {{xxxx}}
35
+ */
36
+ let { from, to } = range;
37
+ while (editor.$view.state.doc.sliceString(from - 1, from) === '{') {
38
+ from--;
39
+ }
40
+ while (editor.$view.state.doc.sliceString(to, to + 1) === '}') {
41
+ to++;
42
+ }
43
+
33
44
  editor.replaceText({
34
- ...range,
45
+ from,
46
+ to,
35
47
  text: '{{' + variablePath + '}}',
36
48
  });
37
49
 
@@ -3,17 +3,10 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import React from 'react';
6
+ import { lazySuspense } from '@/shared';
7
7
 
8
- import { VariableTree } from './extensions/variable-tree';
9
- import { VariableTagInject } from './extensions/variable-tag';
10
- import { PromptEditor, PromptEditorPropsType } from '../prompt-editor';
8
+ export const PromptEditorWithVariables = lazySuspense(() =>
9
+ import('./editor').then((module) => ({ default: module.PromptEditorWithVariables }))
10
+ );
11
11
 
12
- export function PromptEditorWithVariables(props: PromptEditorPropsType) {
13
- return (
14
- <PromptEditor {...props}>
15
- <VariableTree />
16
- <VariableTagInject />
17
- </PromptEditor>
18
- );
19
- }
12
+ export type { PromptEditorWithVariablesProps } from './editor';
@@ -8,9 +8,10 @@ import React, { useMemo } from 'react';
8
8
  import { IJsonSchema } from '@flowgram.ai/json-schema';
9
9
  import { Cascader, Icon, IconButton } from '@douyinfe/semi-ui';
10
10
 
11
- import { useTypeManager } from '../../plugins';
11
+ import { createInjectMaterial } from '@/shared/inject-material';
12
+ import { useTypeManager } from '@/plugins';
12
13
 
13
- interface PropTypes {
14
+ export interface TypeSelectorProps {
14
15
  value?: Partial<IJsonSchema>;
15
16
  onChange?: (value?: Partial<IJsonSchema>) => void;
16
17
  readonly?: boolean;
@@ -23,8 +24,6 @@ interface PropTypes {
23
24
 
24
25
  const labelStyle: React.CSSProperties = { display: 'flex', alignItems: 'center', gap: 5 };
25
26
 
26
- const firstUppercase = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
27
-
28
27
  export const getTypeSelectValue = (value?: Partial<IJsonSchema>): string[] | undefined => {
29
28
  if (value?.type === 'array' && value?.items) {
30
29
  return [value.type, ...(getTypeSelectValue(value.items) || [])];
@@ -43,7 +42,7 @@ export const parseTypeSelectValue = (value?: string[]): Partial<IJsonSchema> | u
43
42
  return { type };
44
43
  };
45
44
 
46
- export function TypeSelector(props: PropTypes) {
45
+ export function TypeSelector(props: TypeSelectorProps) {
47
46
  const { value, onChange, readonly, disabled, style } = props;
48
47
 
49
48
  const selectValue = useMemo(() => getTypeSelectValue(value), [value]);
@@ -61,7 +60,7 @@ export function TypeSelector(props: PropTypes) {
61
60
  label: (
62
61
  <div style={labelStyle}>
63
62
  <Icon size="small" svg={_type.icon} />
64
- {firstUppercase(_type.type)}
63
+ {typeManager.getTypeBySchema(_type)?.label || _type.type}
65
64
  </div>
66
65
  ),
67
66
  value: _type.type,
@@ -76,7 +75,7 @@ export function TypeSelector(props: PropTypes) {
76
75
  items: { type: _type.type },
77
76
  })}
78
77
  />
79
- {firstUppercase(_type.type)}
78
+ {typeManager.getTypeBySchema(_type)?.label || _type.type}
80
79
  </div>
81
80
  ),
82
81
  value: _type.type,
@@ -87,12 +86,22 @@ export function TypeSelector(props: PropTypes) {
87
86
  []
88
87
  );
89
88
 
89
+ const isDisabled = readonly || disabled;
90
+
90
91
  return (
91
92
  <Cascader
92
- disabled={readonly || disabled}
93
+ disabled={isDisabled}
93
94
  size="small"
94
95
  triggerRender={() => (
95
- <IconButton size="small" style={style} disabled={readonly || disabled} icon={icon} />
96
+ <IconButton
97
+ size="small"
98
+ style={{
99
+ ...(isDisabled ? { pointerEvents: 'none' } : {}),
100
+ ...(style || {}),
101
+ }}
102
+ disabled={isDisabled}
103
+ icon={icon}
104
+ />
96
105
  )}
97
106
  treeData={options}
98
107
  value={selectValue}
@@ -103,3 +112,6 @@ export function TypeSelector(props: PropTypes) {
103
112
  />
104
113
  );
105
114
  }
115
+
116
+ TypeSelector.renderKey = 'type-selector-render-key';
117
+ export const InjectTypeSelector = createInjectMaterial(TypeSelector);
@@ -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, { createContext, useContext, useMemo } from 'react';
7
+
8
+ import { BaseVariableField } from '@flowgram.ai/editor';
9
+
10
+ export const VariableSelectorContext = createContext<{
11
+ skipVariable?: (variable?: BaseVariableField) => boolean;
12
+ }>({});
13
+
14
+ export const useVariableSelectorContext = () => useContext(VariableSelectorContext);
15
+
16
+ export const VariableSelectorProvider = ({
17
+ children,
18
+ skipVariable,
19
+ }: {
20
+ skipVariable?: (variable?: BaseVariableField) => boolean;
21
+ children: React.ReactNode;
22
+ }) => {
23
+ const context = useMemo(() => ({ skipVariable }), [skipVariable]);
24
+
25
+ return (
26
+ <VariableSelectorContext.Provider value={context}>{children}</VariableSelectorContext.Provider>
27
+ );
28
+ };
@@ -6,15 +6,19 @@
6
6
  import React, { useMemo } from 'react';
7
7
 
8
8
  import { IJsonSchema } from '@flowgram.ai/json-schema';
9
+ import { I18n } from '@flowgram.ai/editor';
9
10
  import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
10
11
  import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
11
12
  import { Popover } from '@douyinfe/semi-ui';
12
13
  import { IconChevronDownStroked, IconIssueStroked } from '@douyinfe/semi-icons';
13
14
 
15
+ import { createInjectMaterial } from '@/shared';
16
+
14
17
  import { useVariableTree } from './use-variable-tree';
15
18
  import { UIPopoverContent, UIRootTitle, UITag, UITreeSelect, UIVarName } from './styles';
19
+ import { useVariableSelectorContext } from './context';
16
20
 
17
- interface PropTypes {
21
+ export interface VariableSelectorProps {
18
22
  value?: string[];
19
23
  config?: {
20
24
  placeholder?: string;
@@ -29,8 +33,6 @@ interface PropTypes {
29
33
  triggerRender?: (props: TriggerRenderProps) => React.ReactNode;
30
34
  }
31
35
 
32
- export type VariableSelectorProps = PropTypes;
33
-
34
36
  export { useVariableTree };
35
37
 
36
38
  export const VariableSelector = ({
@@ -43,8 +45,14 @@ export const VariableSelector = ({
43
45
  excludeSchema,
44
46
  hasError,
45
47
  triggerRender,
46
- }: PropTypes) => {
47
- const treeData = useVariableTree({ includeSchema, excludeSchema });
48
+ }: VariableSelectorProps) => {
49
+ const { skipVariable } = useVariableSelectorContext();
50
+
51
+ const treeData = useVariableTree({
52
+ includeSchema,
53
+ excludeSchema,
54
+ skipVariable,
55
+ });
48
56
 
49
57
  const treeValue = useMemo(() => {
50
58
  if (typeof value === 'string') {
@@ -130,8 +138,13 @@ export const VariableSelector = ({
130
138
  showClear={false}
131
139
  arrowIcon={<IconChevronDownStroked size="small" />}
132
140
  triggerRender={triggerRender}
133
- placeholder={config?.placeholder ?? 'Select Variable'}
141
+ placeholder={config?.placeholder ?? I18n.t('Select Variable')}
134
142
  />
135
143
  </>
136
144
  );
137
145
  };
146
+
147
+ VariableSelector.renderKey = 'variable-selector-render-key';
148
+ export const InjectVariableSelector = createInjectMaterial(VariableSelector);
149
+
150
+ export { VariableSelectorProvider } from './context';
@@ -10,7 +10,7 @@ import { ASTMatch, BaseVariableField, useAvailableVariables } from '@flowgram.ai
10
10
  import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
11
11
  import { Icon } from '@douyinfe/semi-ui';
12
12
 
13
- import { useTypeManager } from '../../plugins';
13
+ import { useTypeManager } from '@/plugins';
14
14
 
15
15
  type VariableField = BaseVariableField<{
16
16
  icon?: string | JSX.Element;
@@ -21,9 +21,9 @@ type VariableField = BaseVariableField<{
21
21
  export function useVariableTree(params: {
22
22
  includeSchema?: IJsonSchema | IJsonSchema[];
23
23
  excludeSchema?: IJsonSchema | IJsonSchema[];
24
- customSkip?: (variable: VariableField) => boolean;
24
+ skipVariable?: (variable: VariableField) => boolean;
25
25
  }): TreeNodeData[] {
26
- const { includeSchema, excludeSchema, customSkip } = params;
26
+ const { includeSchema, excludeSchema, skipVariable } = params;
27
27
 
28
28
  const typeManager = useTypeManager();
29
29
  const variables = useAvailableVariables();
@@ -69,7 +69,7 @@ export function useVariableTree(params: {
69
69
  const isSchemaExclude = excludeSchema
70
70
  ? JsonSchemaUtils.isASTMatchSchema(type, excludeSchema)
71
71
  : false;
72
- const isCustomSkip = customSkip ? customSkip(variable) : false;
72
+ const isCustomSkip = skipVariable ? skipVariable(variable) : false;
73
73
 
74
74
  // disabled in meta when created
75
75
  const isMetaDisabled = variable.meta?.disabled;
@@ -3,7 +3,6 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { isArray, isObject, uniq } from 'lodash';
7
6
  import {
8
7
  DataEvent,
9
8
  Effect,
@@ -11,7 +10,8 @@ import {
11
10
  VariableFieldKeyRenameService,
12
11
  } from '@flowgram.ai/editor';
13
12
 
14
- import { IFlowRefValue, IFlowTemplateValue } from '../../typings';
13
+ import { IFlowRefValue, IFlowTemplateValue } from '@/typings';
14
+ import { FlowValueUtils } from '@/shared';
15
15
 
16
16
  /**
17
17
  * Auto rename ref when form item's key is renamed
@@ -52,7 +52,7 @@ export const autoRenameRefEffect: EffectOptions[] = [
52
52
  }
53
53
  } else if (_v.type === 'template') {
54
54
  // template auto rename
55
- const templateKeyPaths = getTemplateKeyPaths(_v);
55
+ const templateKeyPaths = FlowValueUtils.getTemplateKeyPaths(_v);
56
56
  let hasMatch = false;
57
57
 
58
58
  templateKeyPaths.forEach((_keyPath) => {
@@ -93,34 +93,6 @@ function isKeyPathMatch(keyPath: string[] = [], targetKeyPath: string[]) {
93
93
  return targetKeyPath.every((_key, index) => _key === keyPath[index]);
94
94
  }
95
95
 
96
- /**
97
- * get template key paths
98
- * @param value
99
- * @returns
100
- */
101
- function getTemplateKeyPaths(value: IFlowTemplateValue) {
102
- // find all keyPath wrapped in {{}}
103
- const keyPathReg = /{{(.*?)}}/g;
104
- return uniq(value.content?.match(keyPathReg) || []).map((_keyPath) =>
105
- _keyPath.slice(2, -2).split('.')
106
- );
107
- }
108
-
109
- /**
110
- * If value is ref
111
- * @param value
112
- * @returns
113
- */
114
- function isRef(value: any): value is IFlowRefValue {
115
- return (
116
- value?.type === 'ref' && Array.isArray(value?.content) && typeof value?.content[0] === 'string'
117
- );
118
- }
119
-
120
- function isTemplate(value: any): value is IFlowTemplateValue {
121
- return value?.type === 'template' && typeof value?.content === 'string';
122
- }
123
-
124
96
  /**
125
97
  * Traverse value to find ref
126
98
  * @param value
@@ -132,29 +104,10 @@ function traverseRef(
132
104
  value: any,
133
105
  cb: (name: string, _v: IFlowRefValue | IFlowTemplateValue) => void
134
106
  ) {
135
- if (isObject(value)) {
136
- if (isRef(value)) {
137
- cb(name, value);
138
- return;
139
- }
140
-
141
- if (isTemplate(value)) {
142
- cb(name, value);
143
- return;
144
- }
145
-
146
- Object.entries(value).forEach(([_key, _value]) => {
147
- traverseRef(`${name}.${_key}`, _value, cb);
148
- });
149
- return;
150
- }
151
-
152
- if (isArray(value)) {
153
- value.forEach((_value, idx) => {
154
- traverseRef(`${name}[${idx}]`, _value, cb);
155
- });
156
- return;
107
+ for (const { value: _v, path } of FlowValueUtils.traverse(value, {
108
+ includeTypes: ['ref', 'template'],
109
+ path: name,
110
+ })) {
111
+ cb(path, _v as IFlowRefValue | IFlowTemplateValue);
157
112
  }
158
-
159
- return;
160
113
  }
@@ -13,7 +13,7 @@ import {
13
13
  getNodeScope,
14
14
  } from '@flowgram.ai/editor';
15
15
 
16
- import { IFlowRefValue } from '../../typings';
16
+ import { IFlowRefValue } from '@/typings';
17
17
 
18
18
  /**
19
19
  * Example:
@@ -12,7 +12,7 @@ import {
12
12
  getNodeScope,
13
13
  } from '@flowgram.ai/editor';
14
14
 
15
- import { IFlowRefValue } from '../../typings';
15
+ import { IFlowRefValue } from '@/typings';
16
16
 
17
17
  /**
18
18
  * Example:
@@ -11,7 +11,7 @@ import {
11
11
  getNodeForm,
12
12
  } from '@flowgram.ai/editor';
13
13
 
14
- import { IFlowRefValue } from '../../typings';
14
+ import { IFlowRefValue } from '@/typings';
15
15
 
16
16
  export const provideBatchInputEffect: EffectOptions[] = createEffectFromVariableProvider({
17
17
  private: true,
@@ -3,7 +3,7 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { isEmpty } from 'lodash';
6
+ import { isEmpty } from 'lodash-es';
7
7
  import {
8
8
  DataEvent,
9
9
  Effect,
@@ -17,7 +17,7 @@ import {
17
17
  FlowNodeScopeType,
18
18
  } from '@flowgram.ai/editor';
19
19
 
20
- import { IFlowRefValue } from '../../typings';
20
+ import { IFlowRefValue } from '@/typings';
21
21
 
22
22
  export const provideBatchOutputsEffect: EffectOptions[] = createEffectFromVariableProvider({
23
23
  parse: (value: Record<string, IFlowRefValue>, ctx) => [
@@ -3,7 +3,7 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { set, uniqBy } from 'lodash';
6
+ import { set, uniqBy } from 'lodash-es';
7
7
  import { JsonSchemaUtils } from '@flowgram.ai/json-schema';
8
8
  import {
9
9
  ASTFactory,
@@ -14,7 +14,7 @@ import {
14
14
  getNodeScope,
15
15
  } from '@flowgram.ai/editor';
16
16
 
17
- import { IFlowRefValue, IFlowValue } from '../../typings';
17
+ import { IFlowRefValue, IFlowValue } from '@/typings';
18
18
 
19
19
  type AssignValueType =
20
20
  | {