@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
@@ -3,9 +3,9 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { useEffect, useState } from 'react';
6
+ import { useEffect, useRef, useState } from 'react';
7
7
 
8
- import { difference, omit } from 'lodash';
8
+ import { difference, omit } from 'lodash-es';
9
9
  import { produce } from 'immer';
10
10
  import { IJsonSchema, type JsonSchemaTypeManager, useTypeManager } from '@flowgram.ai/json-schema';
11
11
 
@@ -28,7 +28,16 @@ export function usePropertiesEdit(
28
28
 
29
29
  const [propertyList, setPropertyList] = useState<PropertyValueType[]>([]);
30
30
 
31
+ const effectVersion = useRef(0);
32
+ const changeVersion = useRef(0);
33
+
31
34
  useEffect(() => {
35
+ effectVersion.current = effectVersion.current + 1;
36
+ if (effectVersion.current === changeVersion.current) {
37
+ return;
38
+ }
39
+ effectVersion.current = changeVersion.current;
40
+
32
41
  // If the value is changed, update the property list
33
42
  setPropertyList((_list) => {
34
43
  const newNames = Object.entries(drilldownSchema?.properties || {})
@@ -44,7 +53,7 @@ export function usePropertiesEdit(
44
53
  key: item.key,
45
54
  name: item.name,
46
55
  isPropertyRequired: drilldownSchema?.required?.includes(item.name || '') || false,
47
- ...item,
56
+ ...(drilldownSchema?.properties?.[item.name || ''] || item || {}),
48
57
  }))
49
58
  .concat(
50
59
  addNames.map((_name) => ({
@@ -58,6 +67,8 @@ export function usePropertiesEdit(
58
67
  }, [drilldownSchema]);
59
68
 
60
69
  const updatePropertyList = (updater: (list: PropertyValueType[]) => PropertyValueType[]) => {
70
+ changeVersion.current = changeVersion.current + 1;
71
+
61
72
  setPropertyList((_list) => {
62
73
  const next = updater(_list);
63
74
 
@@ -18,6 +18,7 @@ import {
18
18
  } from '@douyinfe/semi-icons';
19
19
 
20
20
  import { InjectTypeSelector } from '@/components/type-selector';
21
+ import { BlurInput } from '@/components/blur-input';
21
22
 
22
23
  import { ConfigType, PropertyValueType } from './types';
23
24
  import {
@@ -28,10 +29,10 @@ import {
28
29
  UIContainer,
29
30
  UIExpandDetail,
30
31
  UILabel,
31
- UIProperties,
32
- UIPropertyLeft,
33
- UIPropertyMain,
34
- UIPropertyRight,
32
+ UITreeItems,
33
+ UITreeItemLeft,
34
+ UITreeItemMain,
35
+ UITreeItemRight,
35
36
  UIRequired,
36
37
  UIType,
37
38
  } from './styles';
@@ -39,7 +40,6 @@ import { UIName } from './styles';
39
40
  import { DefaultValueWrapper, UIRow } from './styles';
40
41
  import { usePropertiesEdit } from './hooks';
41
42
  import { DefaultValue } from './default-value';
42
- import { BlurInput } from './components/blur-input';
43
43
 
44
44
  const DEFAULT = { type: 'object' };
45
45
 
@@ -58,14 +58,13 @@ export function JsonSchemaEditor(props: {
58
58
 
59
59
  return (
60
60
  <UIContainer className={props.className}>
61
- <UIProperties>
62
- {propertyList.map((_property, index) => (
61
+ <UITreeItems>
62
+ {propertyList.map((_property) => (
63
63
  <PropertyEdit
64
64
  readonly={readonly}
65
65
  key={_property.key}
66
66
  value={_property}
67
67
  config={config}
68
- $index={index}
69
68
  onChange={(_v) => {
70
69
  onEditProperty(_property.key!, _v);
71
70
  }}
@@ -74,7 +73,7 @@ export function JsonSchemaEditor(props: {
74
73
  }}
75
74
  />
76
75
  ))}
77
- </UIProperties>
76
+ </UITreeItems>
78
77
  <Button
79
78
  disabled={readonly}
80
79
  size="small"
@@ -95,27 +94,9 @@ function PropertyEdit(props: {
95
94
  onRemove?: () => void;
96
95
  readonly?: boolean;
97
96
  $isLast?: boolean;
98
- $index?: number;
99
- $isFirst?: boolean;
100
- $parentExpand?: boolean;
101
- $parentType?: string;
102
- $showLine?: boolean;
103
97
  $level?: number; // 添加层级属性
104
98
  }) {
105
- const {
106
- value,
107
- config,
108
- readonly,
109
- $level = 0,
110
- onChange: onChangeProps,
111
- onRemove,
112
- $index,
113
- $isFirst,
114
- $isLast,
115
- $parentExpand = false,
116
- $parentType = '',
117
- $showLine,
118
- } = props;
99
+ const { value, config, readonly, $level = 0, onChange: onChangeProps, onRemove, $isLast } = props;
119
100
 
120
101
  const [expand, setExpand] = useState(false);
121
102
  const [collapse, setCollapse] = useState(false);
@@ -138,34 +119,20 @@ function PropertyEdit(props: {
138
119
 
139
120
  return (
140
121
  <>
141
- <UIPropertyLeft
142
- type={type}
143
- $index={$index}
144
- $isFirst={$isFirst}
145
- $isLast={$isLast}
146
- $showLine={$showLine}
147
- $isExpand={expand}
148
- $parentExpand={$parentExpand}
149
- $parentType={$parentType}
150
- >
122
+ <UITreeItemLeft $isLast={$isLast} $showLine={$level > 0} $showCollapse={showCollapse}>
151
123
  {showCollapse && (
152
124
  <UICollapseTrigger onClick={() => setCollapse((_collapse) => !_collapse)}>
153
125
  {collapse ? <IconChevronDown size="small" /> : <IconChevronRight size="small" />}
154
126
  </UICollapseTrigger>
155
127
  )}
156
- </UIPropertyLeft>
157
- <UIPropertyRight>
158
- <UIPropertyMain
159
- $showCollapse={showCollapse}
160
- $collapse={collapse}
161
- $expand={expand}
162
- type={type}
163
- >
128
+ </UITreeItemLeft>
129
+ <UITreeItemRight>
130
+ <UITreeItemMain>
164
131
  <UIRow>
165
132
  <UIName>
166
133
  <BlurInput
167
134
  disabled={readonly}
168
- placeholder={config?.placeholder ?? 'Input Variable Name'}
135
+ placeholder={config?.placeholder ?? I18n.t('Input Variable Name')}
169
136
  size="small"
170
137
  value={name}
171
138
  onChange={(value) => onChange('name', value)}
@@ -242,9 +209,7 @@ function PropertyEdit(props: {
242
209
  <DefaultValue
243
210
  value={defaultValue}
244
211
  schema={value}
245
- type={type}
246
212
  placeholder={config?.defaultValuePlaceholder ?? I18n.t('Default Value')}
247
- jsonFormatText={config?.jsonFormatText}
248
213
  onChange={(value) => onChange('default', value)}
249
214
  />
250
215
  </DefaultValueWrapper>
@@ -252,10 +217,10 @@ function PropertyEdit(props: {
252
217
  )}
253
218
  </UIExpandDetail>
254
219
  )}
255
- </UIPropertyMain>
220
+ </UITreeItemMain>
256
221
  {showCollapse && (
257
222
  <UICollapsible $collapse={collapse}>
258
- <UIProperties $shrink={true}>
223
+ <UITreeItems $shrink={true}>
259
224
  {propertyList.map((_property, index) => (
260
225
  <PropertyEdit
261
226
  readonly={readonly}
@@ -263,8 +228,6 @@ function PropertyEdit(props: {
263
228
  value={_property}
264
229
  config={config}
265
230
  $level={$level + 1} // 传递递增的层级
266
- $parentExpand={expand}
267
- $parentType={type}
268
231
  onChange={(_v) => {
269
232
  onEditProperty(_property.key!, _v);
270
233
  }}
@@ -272,15 +235,12 @@ function PropertyEdit(props: {
272
235
  onRemoveProperty(_property.key!);
273
236
  }}
274
237
  $isLast={index === propertyList.length - 1}
275
- $isFirst={index === 0}
276
- $index={index}
277
- $showLine={true}
278
238
  />
279
239
  ))}
280
- </UIProperties>
240
+ </UITreeItems>
281
241
  </UICollapsible>
282
242
  )}
283
- </UIPropertyRight>
243
+ </UITreeItemRight>
284
244
  </>
285
245
  );
286
246
  }
@@ -39,37 +39,30 @@ export const UILabel = styled.div`
39
39
  margin-bottom: 2px;
40
40
  `;
41
41
 
42
- export const UIProperties = styled.div<{ $shrink?: boolean }>`
42
+ export const UITreeItems = styled.div<{ $shrink?: boolean }>`
43
43
  display: grid;
44
44
  grid-template-columns: auto 1fr;
45
45
 
46
46
  ${({ $shrink }) =>
47
47
  $shrink &&
48
48
  css`
49
- padding-left: 10px;
49
+ padding-left: 3px;
50
50
  margin-top: 10px;
51
51
  `}
52
52
  `;
53
53
 
54
- export const UIPropertyLeft = styled.div<{
54
+ export const UITreeItemLeft = styled.div<{
55
55
  $isLast?: boolean;
56
56
  $showLine?: boolean;
57
- $isExpand?: boolean;
58
- type?: string;
59
- $isFirst?: boolean;
60
- $index?: number;
61
- $parentExpand?: boolean;
62
- $parentType?: string;
57
+ $showCollapse?: boolean;
63
58
  }>`
64
59
  grid-column: 1;
65
60
  position: relative;
66
61
  width: 16px;
67
62
 
68
- ${({ $showLine, $isLast, $parentType }) => {
69
- let height = '100%';
70
- if ($parentType && $isLast) {
71
- height = '24px';
72
- }
63
+ ${({ $showLine, $isLast, $showCollapse }) => {
64
+ let height = $isLast ? '24px' : '100%';
65
+ let width = $showCollapse ? '12px' : '30px';
73
66
 
74
67
  return (
75
68
  $showLine &&
@@ -79,7 +72,7 @@ export const UIPropertyLeft = styled.div<{
79
72
  content: '';
80
73
  height: ${height};
81
74
  position: absolute;
82
- left: -22px;
75
+ left: -14px;
83
76
  top: -16px;
84
77
  width: 1px;
85
78
  background: #d9d9d9;
@@ -90,9 +83,9 @@ export const UIPropertyLeft = styled.div<{
90
83
  /* 横线 */
91
84
  content: '';
92
85
  position: absolute;
93
- left: -22px; // 横线起点和竖线对齐
86
+ left: -14px; // 横线起点和竖线对齐
94
87
  top: 8px; // 跟随你的行高调整
95
- width: 18px; // 横线长度
88
+ width: ${width}; // 横线长度
96
89
  height: 1px;
97
90
  background: #d9d9d9;
98
91
  display: block;
@@ -102,7 +95,7 @@ export const UIPropertyLeft = styled.div<{
102
95
  }}
103
96
  `;
104
97
 
105
- export const UIPropertyRight = styled.div`
98
+ export const UITreeItemRight = styled.div`
106
99
  grid-column: 2;
107
100
  margin-bottom: 10px;
108
101
 
@@ -111,47 +104,11 @@ export const UIPropertyRight = styled.div`
111
104
  }
112
105
  `;
113
106
 
114
- export const UIPropertyMain = styled.div<{
115
- $expand?: boolean;
116
- type?: string;
117
- $collapse?: boolean;
118
- $showCollapse?: boolean;
119
- }>`
107
+ export const UITreeItemMain = styled.div<{}>`
120
108
  display: flex;
121
109
  flex-direction: column;
122
110
  gap: 10px;
123
111
  position: relative;
124
-
125
- ${({ $expand, type, $collapse, $showCollapse }) => {
126
- const beforeElement = `
127
- &::before {
128
- /* 竖线 */
129
- content: '';
130
- height: 100%;
131
- position: absolute;
132
- left: -12px;
133
- top: 18px;
134
- width: 1px;
135
- background: #d9d9d9;
136
- display: block;
137
- }`;
138
-
139
- return (
140
- $expand &&
141
- css`
142
- background-color: #f5f5f5;
143
- padding: 10px;
144
- border-radius: 4px;
145
-
146
- ${$showCollapse &&
147
- $collapse &&
148
- (type === 'array' || type === 'object') &&
149
- css`
150
- ${beforeElement}
151
- `}
152
- `
153
- );
154
- }}
155
112
  `;
156
113
 
157
114
  export const UICollapsible = styled.div<{ $collapse?: boolean }>`
@@ -22,5 +22,4 @@ export interface ConfigType {
22
22
  defaultValueTitle?: string;
23
23
  defaultValuePlaceholder?: string;
24
24
  addButtonText?: string;
25
- jsonFormatText?: string;
26
25
  }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import React, { useEffect, useRef } from 'react';
7
+
8
+ import {
9
+ Renderer,
10
+ EditorProvider,
11
+ ActiveLinePlaceholder,
12
+ InferValues,
13
+ } from '@coze-editor/editor/react';
14
+ import preset, { EditorAPI } from '@coze-editor/editor/preset-prompt';
15
+
16
+ import { PropsType } from './types';
17
+ import { UIContainer } from './styles';
18
+ import MarkdownHighlight from './extensions/markdown';
19
+ import LanguageSupport from './extensions/language-support';
20
+ import JinjaHighlight from './extensions/jinja';
21
+
22
+ type Preset = typeof preset;
23
+ type Options = Partial<InferValues<Preset[number]>>;
24
+
25
+ export interface PromptEditorPropsType extends PropsType {
26
+ options?: Options;
27
+ }
28
+
29
+ export function PromptEditor(props: PromptEditorPropsType) {
30
+ const {
31
+ value,
32
+ onChange,
33
+ readonly,
34
+ placeholder,
35
+ activeLinePlaceholder,
36
+ style,
37
+ hasError,
38
+ children,
39
+ disableMarkdownHighlight,
40
+ options,
41
+ } = props || {};
42
+
43
+ const editorRef = useRef<EditorAPI | null>(null);
44
+
45
+ useEffect(() => {
46
+ // listen to value change
47
+ if (editorRef.current?.getValue() !== value?.content) {
48
+ editorRef.current?.setValue(String(value?.content || ''));
49
+ }
50
+ }, [value]);
51
+
52
+ return (
53
+ <UIContainer $hasError={hasError} style={style}>
54
+ <EditorProvider>
55
+ <Renderer
56
+ didMount={(editor: EditorAPI) => {
57
+ editorRef.current = editor;
58
+ }}
59
+ plugins={preset}
60
+ defaultValue={String(value?.content)}
61
+ options={{
62
+ readOnly: readonly,
63
+ editable: !readonly,
64
+ placeholder,
65
+ ...options,
66
+ }}
67
+ onChange={(e) => {
68
+ onChange({ type: 'template', content: e.value });
69
+ }}
70
+ />
71
+ {activeLinePlaceholder && (
72
+ <ActiveLinePlaceholder>{activeLinePlaceholder}</ActiveLinePlaceholder>
73
+ )}
74
+ {!disableMarkdownHighlight && <MarkdownHighlight />}
75
+ <LanguageSupport />
76
+ <JinjaHighlight />
77
+ {children}
78
+ </EditorProvider>
79
+ </UIContainer>
80
+ );
81
+ }
@@ -3,67 +3,10 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import React, { useEffect, useRef } from 'react';
6
+ import { lazySuspense } from '@/shared';
7
7
 
8
- import { Renderer, EditorProvider, ActiveLinePlaceholder } from '@coze-editor/editor/react';
9
- import preset, { EditorAPI } from '@coze-editor/editor/preset-prompt';
8
+ export const PromptEditor = lazySuspense(() =>
9
+ import('./editor').then((module) => ({ default: module.PromptEditor }))
10
+ );
10
11
 
11
- import { PropsType } from './types';
12
- import { UIContainer } from './styles';
13
- import MarkdownHighlight from './extensions/markdown';
14
- import LanguageSupport from './extensions/language-support';
15
- import JinjaHighlight from './extensions/jinja';
16
-
17
- export type PromptEditorPropsType = PropsType;
18
-
19
- export function PromptEditor(props: PropsType) {
20
- const {
21
- value,
22
- onChange,
23
- readonly,
24
- placeholder,
25
- activeLinePlaceholder,
26
- style,
27
- hasError,
28
- children,
29
- disableMarkdownHighlight,
30
- } = props || {};
31
-
32
- const editorRef = useRef<EditorAPI | null>(null);
33
-
34
- useEffect(() => {
35
- // listen to value change
36
- if (editorRef.current?.getValue() !== value?.content) {
37
- editorRef.current?.setValue(String(value?.content || ''));
38
- }
39
- }, [value]);
40
-
41
- return (
42
- <UIContainer $hasError={hasError} style={style}>
43
- <EditorProvider>
44
- <Renderer
45
- didMount={(editor: EditorAPI) => {
46
- editorRef.current = editor;
47
- }}
48
- plugins={preset}
49
- defaultValue={String(value?.content)}
50
- options={{
51
- readOnly: readonly,
52
- editable: !readonly,
53
- placeholder,
54
- }}
55
- onChange={(e) => {
56
- onChange({ type: 'template', content: e.value });
57
- }}
58
- />
59
- {activeLinePlaceholder && (
60
- <ActiveLinePlaceholder>{activeLinePlaceholder}</ActiveLinePlaceholder>
61
- )}
62
- {!disableMarkdownHighlight && <MarkdownHighlight />}
63
- <LanguageSupport />
64
- <JinjaHighlight />
65
- {children}
66
- </EditorProvider>
67
- </UIContainer>
68
- );
69
- }
12
+ export type { PromptEditorPropsType } from './editor';
@@ -0,0 +1,25 @@
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 { InputsTree } from './extensions/inputs-tree';
11
+
12
+ export interface PromptEditorWithInputsProps extends PromptEditorPropsType {
13
+ inputsValues: any;
14
+ }
15
+
16
+ export function PromptEditorWithInputs({
17
+ inputsValues,
18
+ ...restProps
19
+ }: PromptEditorWithInputsProps) {
20
+ return (
21
+ <PromptEditor {...restProps}>
22
+ <InputsTree inputsValues={inputsValues} />
23
+ </PromptEditor>
24
+ );
25
+ }
@@ -32,6 +32,17 @@ export function InputsTree({ inputsValues }: { inputsValues: Record<string, IFlo
32
32
  return;
33
33
  }
34
34
 
35
+ /**
36
+ * When user input {{xxxx}}, {{{xxx}}}(more brackets if possible), replace all brackets with {{xxxx}}
37
+ */
38
+ let { from, to } = range;
39
+ while (editor.$view.state.doc.sliceString(from - 1, from) === '{') {
40
+ from--;
41
+ }
42
+ while (editor.$view.state.doc.sliceString(to, to + 1) === '}') {
43
+ to++;
44
+ }
45
+
35
46
  editor.replaceText({
36
47
  ...range,
37
48
  text: '{{' + variablePath + '}}',
@@ -3,21 +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 { IFlowValue } from '@/typings';
9
- import { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';
8
+ export const PromptEditorWithInputs = lazySuspense(() =>
9
+ import('./editor').then((module) => ({ default: module.PromptEditorWithInputs }))
10
+ );
10
11
 
11
- import { InputsTree } from './extensions/inputs-tree';
12
-
13
- interface PropsType extends PromptEditorPropsType {
14
- inputsValues: Record<string, IFlowValue>;
15
- }
16
-
17
- export function PromptEditorWithInputs({ inputsValues, ...restProps }: PropsType) {
18
- return (
19
- <PromptEditor {...restProps}>
20
- <InputsTree inputsValues={inputsValues} />
21
- </PromptEditor>
22
- );
23
- }
12
+ export type { PromptEditorWithInputsProps } from './editor';
@@ -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
+ }