@flowgram.ai/form-materials 0.4.10 → 0.4.12
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.
- package/dist/cjs/components/blur-input/index.js +2 -12
- package/dist/cjs/components/{prompt-editor-with-inputs/inputs-picker.js → coze-editor-extensions/extensions/inputs-tree.js} +70 -2
- package/dist/cjs/components/{prompt-editor-with-variables → coze-editor-extensions}/extensions/variable-tree.js +10 -7
- package/dist/cjs/components/coze-editor-extensions/index.js +86 -0
- package/dist/cjs/components/display-schema-tree/index.js +2 -2
- package/dist/cjs/components/index.js +11 -1
- package/dist/cjs/components/json-editor-with-variables/editor.js +10 -6
- package/dist/cjs/components/prompt-editor-with-inputs/editor.js +2 -2
- package/dist/cjs/components/prompt-editor-with-variables/editor.js +3 -4
- package/dist/cjs/components/type-selector/index.js +2 -2
- package/dist/cjs/components/variable-selector/index.js +1 -0
- package/dist/cjs/components/variable-selector/use-variable-tree.js +1 -2
- package/dist/cjs/index.js +10 -1
- package/dist/cjs/plugins/json-schema-preset/index.js +3 -13
- package/dist/cjs/plugins/json-schema-preset/react.js +50 -0
- package/dist/cjs/shared/inject-material/index.js +2 -1
- package/dist/esm/components/blur-input/index.mjs +2 -2
- package/dist/esm/components/coze-editor-extensions/extensions/inputs-tree.mjs +135 -0
- package/dist/esm/components/{prompt-editor-with-variables → coze-editor-extensions}/extensions/variable-tree.mjs +10 -7
- package/dist/esm/components/coze-editor-extensions/index.mjs +18 -0
- package/dist/esm/components/display-schema-tree/index.mjs +1 -1
- package/dist/esm/components/index.mjs +2 -1
- package/dist/esm/components/json-editor-with-variables/editor.mjs +8 -4
- package/dist/esm/components/prompt-editor-with-inputs/editor.mjs +2 -2
- package/dist/esm/components/prompt-editor-with-variables/editor.mjs +3 -4
- package/dist/esm/components/type-selector/index.mjs +1 -1
- package/dist/esm/components/variable-selector/index.mjs +1 -0
- package/dist/esm/components/variable-selector/use-variable-tree.mjs +1 -2
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/plugins/json-schema-preset/index.mjs +3 -13
- package/dist/esm/plugins/json-schema-preset/react.mjs +13 -0
- package/dist/esm/shared/inject-material/index.mjs +2 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/components/blur-input/index.d.ts +7 -1
- package/dist/types/components/{prompt-editor-with-inputs/inputs-picker.d.ts → coze-editor-extensions/extensions/inputs-tree.d.ts} +5 -0
- package/dist/types/components/{prompt-editor-with-variables → coze-editor-extensions}/extensions/variable-tree.d.ts +3 -1
- package/dist/types/components/coze-editor-extensions/index.d.ts +18 -0
- package/dist/types/components/display-schema-tree/index.d.ts +1 -1
- package/dist/types/components/dynamic-value-input/index.d.ts +3 -1
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/components/type-selector/index.d.ts +3 -1
- package/dist/types/components/variable-selector/index.d.ts +4 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/index.d.ts +3 -7
- package/dist/types/plugins/json-schema-preset/react.d.ts +11 -0
- package/dist/types/shared/inject-material/index.d.ts +6 -4
- package/dist/types/validate/validate-flow-value/index.d.ts +1 -1
- package/package.json +51 -12
- package/src/components/blur-input/index.tsx +9 -1
- package/src/components/{prompt-editor-with-inputs/inputs-picker.tsx → coze-editor-extensions/extensions/inputs-tree.tsx} +95 -5
- package/src/components/{prompt-editor-with-variables → coze-editor-extensions}/extensions/variable-tree.tsx +9 -3
- package/src/components/coze-editor-extensions/index.tsx +33 -0
- package/src/components/display-schema-tree/index.tsx +6 -4
- package/src/components/index.ts +5 -0
- package/src/components/json-editor-with-variables/editor.tsx +4 -4
- package/src/components/prompt-editor-with-inputs/editor.tsx +2 -3
- package/src/components/prompt-editor-with-variables/editor.tsx +3 -5
- package/src/components/type-selector/index.tsx +2 -3
- package/src/components/variable-selector/index.tsx +4 -2
- package/src/components/variable-selector/use-variable-tree.tsx +7 -4
- package/src/index.ts +3 -0
- package/src/plugins/json-schema-preset/index.tsx +4 -20
- package/src/plugins/json-schema-preset/react.tsx +28 -0
- package/src/shared/inject-material/index.tsx +10 -6
- package/src/validate/validate-flow-value/index.tsx +1 -2
- package/dist/cjs/components/json-editor-with-variables/extensions/variable-tree.js +0 -97
- package/dist/cjs/components/prompt-editor-with-inputs/extensions/inputs-tree.js +0 -101
- package/dist/cjs/components/prompt-editor-with-variables/extensions/variable-tag.js +0 -151
- package/dist/cjs/components/prompt-editor-with-variables/styles.js +0 -89
- package/dist/esm/components/json-editor-with-variables/extensions/variable-tree.mjs +0 -63
- package/dist/esm/components/prompt-editor-with-inputs/extensions/inputs-tree.mjs +0 -67
- package/dist/esm/components/prompt-editor-with-inputs/inputs-picker.mjs +0 -70
- package/dist/esm/components/prompt-editor-with-variables/extensions/variable-tag.mjs +0 -117
- package/dist/esm/components/prompt-editor-with-variables/styles.mjs +0 -36
- package/dist/types/components/json-editor-with-variables/extensions/variable-tree.d.ts +0 -6
- package/dist/types/components/prompt-editor-with-inputs/extensions/inputs-tree.d.ts +0 -9
- package/dist/types/components/prompt-editor-with-variables/extensions/variable-tag.d.ts +0 -5
- package/dist/types/components/prompt-editor-with-variables/styles.d.ts +0 -9
- package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +0 -83
- package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +0 -94
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +0 -174
- package/src/components/prompt-editor-with-variables/styles.tsx +0 -44
- /package/dist/cjs/components/{json-editor-with-variables → coze-editor-extensions}/extensions/variable-tag.js +0 -0
- /package/dist/cjs/components/{json-editor-with-variables → coze-editor-extensions}/styles.js +0 -0
- /package/dist/esm/components/{json-editor-with-variables → coze-editor-extensions}/extensions/variable-tag.mjs +0 -0
- /package/dist/esm/components/{json-editor-with-variables → coze-editor-extensions}/styles.mjs +0 -0
- /package/dist/types/components/{json-editor-with-variables → coze-editor-extensions}/extensions/variable-tag.d.ts +0 -0
- /package/dist/types/components/{json-editor-with-variables → coze-editor-extensions}/styles.d.ts +0 -0
- /package/src/components/{json-editor-with-variables → coze-editor-extensions}/extensions/variable-tag.tsx +0 -0
- /package/src/components/{json-editor-with-variables → coze-editor-extensions}/styles.tsx +0 -0
package/package.json
CHANGED
|
@@ -1,17 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowgram.ai/form-materials",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.12",
|
|
4
4
|
"homepage": "https://flowgram.ai/",
|
|
5
5
|
"repository": "https://github.com/bytedance/flowgram.ai",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"exports": {
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
10
|
+
"import": "./dist/esm/index.mjs",
|
|
11
|
+
"require": "./dist/cjs/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./components/*": {
|
|
14
|
+
"types": "./dist/types/components/*/index.d.ts",
|
|
15
|
+
"import": "./dist/esm/components/*/index.mjs",
|
|
16
|
+
"require": "./dist/cjs/components/*/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./effects/*": {
|
|
19
|
+
"types": "./dist/types/effects/*/index.d.ts",
|
|
20
|
+
"import": "./dist/esm/effects/*/index.mjs",
|
|
21
|
+
"require": "./dist/cjs/effects/*/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./hooks/*": {
|
|
24
|
+
"types": "./dist/types/hooks/*/index.d.ts",
|
|
25
|
+
"import": "./dist/esm/hooks/*/index.mjs",
|
|
26
|
+
"require": "./dist/cjs/hooks/*/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./shared/*": {
|
|
29
|
+
"types": "./dist/types/shared/*/index.d.ts",
|
|
30
|
+
"import": "./dist/esm/shared/*/index.mjs",
|
|
31
|
+
"require": "./dist/cjs/shared/*/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./form-plugins/*": {
|
|
34
|
+
"types": "./dist/types/form-plugins/*/index.d.ts",
|
|
35
|
+
"import": "./dist/esm/form-plugins/*/index.mjs",
|
|
36
|
+
"require": "./dist/cjs/form-plugins/*/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./plugins/*": {
|
|
39
|
+
"types": "./dist/types/plugins/*/index.d.ts",
|
|
40
|
+
"import": "./dist/esm/plugins/*/index.mjs",
|
|
41
|
+
"require": "./dist/cjs/plugins/*/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./validate/*": {
|
|
44
|
+
"types": "./dist/types/validate/*/index.d.ts",
|
|
45
|
+
"import": "./dist/esm/validate/*/index.mjs",
|
|
46
|
+
"require": "./dist/cjs/validate/*/index.js"
|
|
47
|
+
}
|
|
11
48
|
},
|
|
12
49
|
"main": "./dist/cjs/index.js",
|
|
13
50
|
"module": "./dist/esm/index.mjs",
|
|
14
51
|
"types": "./dist/types/index.d.ts",
|
|
52
|
+
"sideEffects": false,
|
|
15
53
|
"bin": {
|
|
16
54
|
"flowgram-form-materials": "./bin/run.sh"
|
|
17
55
|
},
|
|
@@ -30,9 +68,9 @@
|
|
|
30
68
|
"@codemirror/view": "~6.38.0",
|
|
31
69
|
"@codemirror/state": "~6.5.2",
|
|
32
70
|
"zod": "^3.24.4",
|
|
33
|
-
"@flowgram.ai/editor": "0.4.
|
|
34
|
-
"@flowgram.ai/json-schema": "0.4.
|
|
35
|
-
"@flowgram.ai/coze-editor": "0.4.
|
|
71
|
+
"@flowgram.ai/editor": "0.4.12",
|
|
72
|
+
"@flowgram.ai/json-schema": "0.4.12",
|
|
73
|
+
"@flowgram.ai/coze-editor": "0.4.12"
|
|
36
74
|
},
|
|
37
75
|
"devDependencies": {
|
|
38
76
|
"@types/lodash-es": "^4.17.12",
|
|
@@ -48,9 +86,10 @@
|
|
|
48
86
|
"typescript": "^5.8.3",
|
|
49
87
|
"vitest": "^0.34.6",
|
|
50
88
|
"@rslib/core": "~0.12.4",
|
|
89
|
+
"cross-env": "~7.0.3",
|
|
51
90
|
"@rsbuild/plugin-react": "^1.1.1",
|
|
52
|
-
"@flowgram.ai/eslint-config": "0.4.
|
|
53
|
-
"@flowgram.ai/ts-config": "0.4.
|
|
91
|
+
"@flowgram.ai/eslint-config": "0.4.12",
|
|
92
|
+
"@flowgram.ai/ts-config": "0.4.12"
|
|
54
93
|
},
|
|
55
94
|
"peerDependencies": {
|
|
56
95
|
"react": ">=16.8",
|
|
@@ -62,9 +101,9 @@
|
|
|
62
101
|
"registry": "https://registry.npmjs.org/"
|
|
63
102
|
},
|
|
64
103
|
"scripts": {
|
|
65
|
-
"build": "rslib build",
|
|
66
|
-
"build:fast": "rslib build",
|
|
67
|
-
"build:watch": "
|
|
104
|
+
"build": "cross-env NODE_ENV=production rslib build",
|
|
105
|
+
"build:fast": "cross-env NODE_ENV=development rslib build",
|
|
106
|
+
"build:watch": "npm run build:fast",
|
|
68
107
|
"name-export": "node scripts/name-export.js",
|
|
69
108
|
"clean": "rimraf dist",
|
|
70
109
|
"test": "exit 0",
|
|
@@ -3,9 +3,17 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
/* eslint-disable react/prop-types */
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
9
|
+
* SPDX-License-Identifier: MIT
|
|
10
|
+
*/
|
|
11
|
+
|
|
6
12
|
import React, { useEffect, useState } from 'react';
|
|
7
13
|
|
|
8
|
-
import
|
|
14
|
+
import { Input } from '@douyinfe/semi-ui';
|
|
15
|
+
|
|
16
|
+
type InputProps = React.ComponentPropsWithoutRef<typeof Input>;
|
|
9
17
|
|
|
10
18
|
export function BlurInput(props: InputProps) {
|
|
11
19
|
const [value, setValue] = useState('');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import React, { useMemo } from 'react';
|
|
6
|
+
import React, { useMemo, useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { isPlainObject, last } from 'lodash-es';
|
|
9
9
|
import {
|
|
@@ -13,10 +13,18 @@ import {
|
|
|
13
13
|
type BaseVariableField,
|
|
14
14
|
useScopeAvailable,
|
|
15
15
|
} from '@flowgram.ai/editor';
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
import {
|
|
17
|
+
Mention,
|
|
18
|
+
MentionOpenChangeEvent,
|
|
19
|
+
getCurrentMentionReplaceRange,
|
|
20
|
+
useEditor,
|
|
21
|
+
PositionMirror,
|
|
22
|
+
} from '@flowgram.ai/coze-editor/react';
|
|
23
|
+
import { EditorAPI } from '@flowgram.ai/coze-editor/preset-prompt';
|
|
24
|
+
import { type TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
25
|
+
import { Tree, Popover } from '@douyinfe/semi-ui';
|
|
26
|
+
|
|
27
|
+
import { IFlowValue, FlowValueUtils } from '@/shared';
|
|
20
28
|
|
|
21
29
|
type VariableField = BaseVariableField<{ icon?: string | JSX.Element; title?: string }>;
|
|
22
30
|
|
|
@@ -115,3 +123,85 @@ export function InputsPicker({
|
|
|
115
123
|
|
|
116
124
|
return <Tree treeData={treeData} onSelect={(v) => onSelect(v)} />;
|
|
117
125
|
}
|
|
126
|
+
|
|
127
|
+
const DEFAULT_TRIGGER_CHARACTERS = ['{', '{}', '@'];
|
|
128
|
+
|
|
129
|
+
export function InputsTree({
|
|
130
|
+
inputsValues,
|
|
131
|
+
triggerCharacters = DEFAULT_TRIGGER_CHARACTERS,
|
|
132
|
+
}: {
|
|
133
|
+
inputsValues: Record<string, IFlowValue>;
|
|
134
|
+
triggerCharacters?: string[];
|
|
135
|
+
}) {
|
|
136
|
+
const [posKey, setPosKey] = useState('');
|
|
137
|
+
const [visible, setVisible] = useState(false);
|
|
138
|
+
const [position, setPosition] = useState(-1);
|
|
139
|
+
const editor = useEditor<EditorAPI>();
|
|
140
|
+
|
|
141
|
+
function insert(variablePath: string) {
|
|
142
|
+
const range = getCurrentMentionReplaceRange(editor.$view.state);
|
|
143
|
+
|
|
144
|
+
if (!range) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* When user input {{xxxx}}, {{{xxx}}}(more brackets if possible), replace all brackets with {{xxxx}}
|
|
150
|
+
*/
|
|
151
|
+
let { from, to } = range;
|
|
152
|
+
while (editor.$view.state.doc.sliceString(from - 1, from) === '{') {
|
|
153
|
+
from--;
|
|
154
|
+
}
|
|
155
|
+
while (editor.$view.state.doc.sliceString(to, to + 1) === '}') {
|
|
156
|
+
to++;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
editor.replaceText({
|
|
160
|
+
...range,
|
|
161
|
+
text: '{{' + variablePath + '}}',
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
setVisible(false);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function handleOpenChange(e: MentionOpenChangeEvent) {
|
|
168
|
+
setPosition(e.state.selection.main.head);
|
|
169
|
+
setVisible(e.value);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
if (!editor) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}, [editor, visible]);
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<>
|
|
180
|
+
<Mention triggerCharacters={triggerCharacters} onOpenChange={handleOpenChange} />
|
|
181
|
+
|
|
182
|
+
<Popover
|
|
183
|
+
visible={visible}
|
|
184
|
+
trigger="custom"
|
|
185
|
+
position="topLeft"
|
|
186
|
+
rePosKey={posKey}
|
|
187
|
+
content={
|
|
188
|
+
<div style={{ width: 300, maxHeight: 300, overflowY: 'auto' }}>
|
|
189
|
+
<InputsPicker
|
|
190
|
+
inputsValues={inputsValues}
|
|
191
|
+
onSelect={(v) => {
|
|
192
|
+
insert(v);
|
|
193
|
+
}}
|
|
194
|
+
/>
|
|
195
|
+
</div>
|
|
196
|
+
}
|
|
197
|
+
>
|
|
198
|
+
{/* PositionMirror allows the Popover to appear at the specified cursor position */}
|
|
199
|
+
<PositionMirror
|
|
200
|
+
position={position}
|
|
201
|
+
// When Doc scroll, update position
|
|
202
|
+
onChange={() => setPosKey(String(Math.random()))}
|
|
203
|
+
/>
|
|
204
|
+
</Popover>
|
|
205
|
+
</>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
@@ -17,7 +17,13 @@ import { Popover, Tree } from '@douyinfe/semi-ui';
|
|
|
17
17
|
|
|
18
18
|
import { useVariableTree } from '@/components/variable-selector';
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
const DEFAULT_TRIGGER_CHARACTER = ['{', '{}', '@'];
|
|
21
|
+
|
|
22
|
+
export function VariableTree({
|
|
23
|
+
triggerCharacters = DEFAULT_TRIGGER_CHARACTER,
|
|
24
|
+
}: {
|
|
25
|
+
triggerCharacters?: string[];
|
|
26
|
+
}) {
|
|
21
27
|
const [posKey, setPosKey] = useState('');
|
|
22
28
|
const [visible, setVisible] = useState(false);
|
|
23
29
|
const [position, setPosition] = useState(-1);
|
|
@@ -65,7 +71,7 @@ export function VariableTree() {
|
|
|
65
71
|
|
|
66
72
|
return (
|
|
67
73
|
<>
|
|
68
|
-
<Mention triggerCharacters={
|
|
74
|
+
<Mention triggerCharacters={triggerCharacters} onOpenChange={handleOpenChange} />
|
|
69
75
|
|
|
70
76
|
<Popover
|
|
71
77
|
visible={visible}
|
|
@@ -73,7 +79,7 @@ export function VariableTree() {
|
|
|
73
79
|
position="topLeft"
|
|
74
80
|
rePosKey={posKey}
|
|
75
81
|
content={
|
|
76
|
-
<div style={{ width: 300 }}>
|
|
82
|
+
<div style={{ width: 300, maxHeight: 300, overflowY: 'auto' }}>
|
|
77
83
|
<Tree
|
|
78
84
|
treeData={treeData}
|
|
79
85
|
onSelect={(v) => {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { lazy } from 'react';
|
|
7
|
+
|
|
8
|
+
import { createInjectMaterial } from '@/shared';
|
|
9
|
+
|
|
10
|
+
export const EditorVariableTree = createInjectMaterial(
|
|
11
|
+
lazy(() =>
|
|
12
|
+
import('./extensions/variable-tree').then((module) => ({ default: module.VariableTree }))
|
|
13
|
+
),
|
|
14
|
+
{
|
|
15
|
+
renderKey: 'EditorVariableTree',
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const EditorVariableTagInject = createInjectMaterial(
|
|
20
|
+
lazy(() =>
|
|
21
|
+
import('./extensions/variable-tag').then((module) => ({ default: module.VariableTagInject }))
|
|
22
|
+
),
|
|
23
|
+
{
|
|
24
|
+
renderKey: 'EditorVariableTagInject',
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const EditorInputsTree = createInjectMaterial(
|
|
29
|
+
lazy(() => import('./extensions/inputs-tree').then((module) => ({ default: module.InputsTree }))),
|
|
30
|
+
{
|
|
31
|
+
renderKey: 'EditorInputsTree',
|
|
32
|
+
}
|
|
33
|
+
);
|
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
import {
|
|
9
|
+
type IJsonSchema,
|
|
10
|
+
type JsonSchemaTypeManager,
|
|
11
|
+
useTypeManager,
|
|
12
|
+
} from '@flowgram.ai/json-schema';
|
|
11
13
|
|
|
12
14
|
import { HorizontalLine, TreeItem, TreeLevel, TreeRow, TreeTitle } from './styles';
|
|
13
15
|
|
|
@@ -33,7 +35,7 @@ function SchemaTree(props: PropsType) {
|
|
|
33
35
|
parentKey = '',
|
|
34
36
|
} = props || {};
|
|
35
37
|
|
|
36
|
-
const typeManager = useTypeManager();
|
|
38
|
+
const typeManager = useTypeManager() as JsonSchemaTypeManager;
|
|
37
39
|
|
|
38
40
|
const config = typeManager.getTypeBySchema(schema);
|
|
39
41
|
const title = typeManager.getComplexText(schema);
|
package/src/components/index.ts
CHANGED
|
@@ -12,6 +12,11 @@ export { CodeEditor, type CodeEditorPropsType } from './code-editor';
|
|
|
12
12
|
export { CodeEditorMini } from './code-editor-mini';
|
|
13
13
|
export { ConditionRow, type ConditionRowValueType } from './condition-row';
|
|
14
14
|
export { ConstantInput, type ConstantInputStrategy } from './constant-input';
|
|
15
|
+
export {
|
|
16
|
+
EditorVariableTagInject,
|
|
17
|
+
EditorVariableTree,
|
|
18
|
+
EditorInputsTree,
|
|
19
|
+
} from './coze-editor-extensions';
|
|
15
20
|
export {
|
|
16
21
|
DBConditionRow,
|
|
17
22
|
type DBConditionOptionType,
|
|
@@ -9,10 +9,10 @@ import { I18n } from '@flowgram.ai/editor';
|
|
|
9
9
|
import { transformerCreator } from '@flowgram.ai/coze-editor/preset-code';
|
|
10
10
|
import { Text } from '@flowgram.ai/coze-editor/language-json';
|
|
11
11
|
|
|
12
|
+
import { EditorVariableTree, EditorVariableTagInject } from '@/components/coze-editor-extensions';
|
|
12
13
|
import { CodeEditor, type CodeEditorPropsType } from '@/components/code-editor';
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
import { VariableTagInject } from './extensions/variable-tag';
|
|
15
|
+
const TRIGGER_CHARACTERS = ['@'];
|
|
16
16
|
|
|
17
17
|
type Match = { match: string; range: [number, number] };
|
|
18
18
|
function findAllMatches(inputString: string, regex: RegExp): Match[] {
|
|
@@ -62,8 +62,8 @@ export function JsonEditorWithVariables(props: JsonEditorWithVariablesProps) {
|
|
|
62
62
|
...(props.options || {}),
|
|
63
63
|
}}
|
|
64
64
|
>
|
|
65
|
-
<
|
|
66
|
-
<
|
|
65
|
+
<EditorVariableTree triggerCharacters={TRIGGER_CHARACTERS} />
|
|
66
|
+
<EditorVariableTagInject />
|
|
67
67
|
</CodeEditor>
|
|
68
68
|
);
|
|
69
69
|
}
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
8
|
import { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';
|
|
9
|
-
|
|
10
|
-
import { InputsTree } from './extensions/inputs-tree';
|
|
9
|
+
import { EditorInputsTree } from '@/components/coze-editor-extensions';
|
|
11
10
|
|
|
12
11
|
export interface PromptEditorWithInputsProps extends PromptEditorPropsType {
|
|
13
12
|
inputsValues: any;
|
|
@@ -19,7 +18,7 @@ export function PromptEditorWithInputs({
|
|
|
19
18
|
}: PromptEditorWithInputsProps) {
|
|
20
19
|
return (
|
|
21
20
|
<PromptEditor {...restProps}>
|
|
22
|
-
<
|
|
21
|
+
<EditorInputsTree inputsValues={inputsValues} />
|
|
23
22
|
</PromptEditor>
|
|
24
23
|
);
|
|
25
24
|
}
|
|
@@ -6,17 +6,15 @@
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
8
|
import { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';
|
|
9
|
-
|
|
10
|
-
import { VariableTree } from './extensions/variable-tree';
|
|
11
|
-
import { VariableTagInject } from './extensions/variable-tag';
|
|
9
|
+
import { EditorVariableTree, EditorVariableTagInject } from '@/components/coze-editor-extensions';
|
|
12
10
|
|
|
13
11
|
export interface PromptEditorWithVariablesProps extends PromptEditorPropsType {}
|
|
14
12
|
|
|
15
13
|
export function PromptEditorWithVariables(props: PromptEditorWithVariablesProps) {
|
|
16
14
|
return (
|
|
17
15
|
<PromptEditor {...props}>
|
|
18
|
-
<
|
|
19
|
-
<
|
|
16
|
+
<EditorVariableTree />
|
|
17
|
+
<EditorVariableTagInject />
|
|
20
18
|
</PromptEditor>
|
|
21
19
|
);
|
|
22
20
|
}
|
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
|
-
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
8
|
+
import { IJsonSchema, useTypeManager, JsonSchemaTypeManager } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { Cascader, Icon, IconButton } from '@douyinfe/semi-ui';
|
|
10
10
|
|
|
11
11
|
import { createInjectMaterial } from '@/shared/inject-material';
|
|
12
|
-
import { useTypeManager } from '@/plugins';
|
|
13
12
|
|
|
14
13
|
export interface TypeSelectorProps {
|
|
15
14
|
value?: Partial<IJsonSchema>;
|
|
@@ -47,7 +46,7 @@ export function TypeSelector(props: TypeSelectorProps) {
|
|
|
47
46
|
|
|
48
47
|
const selectValue = useMemo(() => getTypeSelectValue(value), [value]);
|
|
49
48
|
|
|
50
|
-
const typeManager = useTypeManager();
|
|
49
|
+
const typeManager = useTypeManager() as JsonSchemaTypeManager;
|
|
51
50
|
|
|
52
51
|
const icon = typeManager.getDisplayIcon(value || {});
|
|
53
52
|
|
|
@@ -7,8 +7,8 @@ import React, { useMemo } from 'react';
|
|
|
7
7
|
|
|
8
8
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { I18n } from '@flowgram.ai/editor';
|
|
10
|
-
import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
|
|
11
|
-
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
10
|
+
import { type TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
|
|
11
|
+
import { type TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
12
12
|
import { Popover } from '@douyinfe/semi-ui';
|
|
13
13
|
import { IconChevronDownStroked, IconIssueStroked } from '@douyinfe/semi-icons';
|
|
14
14
|
|
|
@@ -73,6 +73,8 @@ export const VariableSelector = ({
|
|
|
73
73
|
return icon;
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
+
console.log('debugger treeValue', treeValue);
|
|
77
|
+
|
|
76
78
|
return (
|
|
77
79
|
<>
|
|
78
80
|
<UITreeSelect
|
|
@@ -5,13 +5,16 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useCallback } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
IJsonSchema,
|
|
10
|
+
JsonSchemaTypeManager,
|
|
11
|
+
JsonSchemaUtils,
|
|
12
|
+
useTypeManager,
|
|
13
|
+
} from '@flowgram.ai/json-schema';
|
|
9
14
|
import { ASTMatch, BaseVariableField, useAvailableVariables } from '@flowgram.ai/editor';
|
|
10
15
|
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
11
16
|
import { Icon } from '@douyinfe/semi-ui';
|
|
12
17
|
|
|
13
|
-
import { useTypeManager } from '@/plugins';
|
|
14
|
-
|
|
15
18
|
type VariableField = BaseVariableField<{
|
|
16
19
|
icon?: string | JSX.Element;
|
|
17
20
|
title?: string;
|
|
@@ -25,7 +28,7 @@ export function useVariableTree(params: {
|
|
|
25
28
|
}): TreeNodeData[] {
|
|
26
29
|
const { includeSchema, excludeSchema, skipVariable } = params;
|
|
27
30
|
|
|
28
|
-
const typeManager = useTypeManager();
|
|
31
|
+
const typeManager = useTypeManager() as JsonSchemaTypeManager;
|
|
29
32
|
const variables = useAvailableVariables();
|
|
30
33
|
|
|
31
34
|
const getVariableTypeIcon = useCallback((variable: VariableField) => {
|
package/src/index.ts
CHANGED
|
@@ -2,33 +2,17 @@
|
|
|
2
2
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
|
-
import React from 'react';
|
|
6
5
|
|
|
7
6
|
import {
|
|
8
|
-
type IJsonSchema,
|
|
9
|
-
JsonSchemaUtils,
|
|
10
|
-
useTypeManager as useOriginTypeManager,
|
|
11
|
-
TypePresetProvider as OriginTypePresetProvider,
|
|
12
|
-
JsonSchemaTypeManager,
|
|
13
7
|
type JsonSchemaBasicType,
|
|
8
|
+
JsonSchemaUtils,
|
|
9
|
+
type IJsonSchema,
|
|
14
10
|
} from '@flowgram.ai/json-schema';
|
|
15
11
|
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
12
|
+
import { useTypeManager, JsonSchemaTypePresetProvider } from './react';
|
|
13
|
+
import { ConstantRendererProps, type JsonSchemaTypeRegistry } from './manager';
|
|
18
14
|
import { createTypePresetPlugin } from './create-type-preset-plugin';
|
|
19
15
|
|
|
20
|
-
const useTypeManager = () =>
|
|
21
|
-
useOriginTypeManager() as JsonSchemaTypeManager<IJsonSchema, JsonSchemaTypeRegistry>;
|
|
22
|
-
|
|
23
|
-
const JsonSchemaTypePresetProvider = ({
|
|
24
|
-
types = [],
|
|
25
|
-
children,
|
|
26
|
-
}: React.PropsWithChildren<{ types: JsonSchemaTypeRegistry[] }>) => (
|
|
27
|
-
<OriginTypePresetProvider types={[...jsonSchemaTypePreset, ...types]}>
|
|
28
|
-
{children}
|
|
29
|
-
</OriginTypePresetProvider>
|
|
30
|
-
);
|
|
31
|
-
|
|
32
16
|
export {
|
|
33
17
|
createTypePresetPlugin,
|
|
34
18
|
useTypeManager,
|
|
@@ -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 from 'react';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
type IJsonSchema,
|
|
10
|
+
useTypeManager as useOriginTypeManager,
|
|
11
|
+
TypePresetProvider as OriginTypePresetProvider,
|
|
12
|
+
JsonSchemaTypeManager,
|
|
13
|
+
} from '@flowgram.ai/json-schema';
|
|
14
|
+
|
|
15
|
+
import { jsonSchemaTypePreset } from './type-definition';
|
|
16
|
+
import { type JsonSchemaTypeRegistry } from './manager';
|
|
17
|
+
|
|
18
|
+
export const useTypeManager = () =>
|
|
19
|
+
useOriginTypeManager() as JsonSchemaTypeManager<IJsonSchema, JsonSchemaTypeRegistry>;
|
|
20
|
+
|
|
21
|
+
export const JsonSchemaTypePresetProvider = ({
|
|
22
|
+
types = [],
|
|
23
|
+
children,
|
|
24
|
+
}: React.PropsWithChildren<{ types: JsonSchemaTypeRegistry[] }>) => (
|
|
25
|
+
<OriginTypePresetProvider types={[...jsonSchemaTypePreset, ...types]}>
|
|
26
|
+
{children}
|
|
27
|
+
</OriginTypePresetProvider>
|
|
28
|
+
);
|
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
usePlaygroundContainer,
|
|
12
12
|
} from '@flowgram.ai/editor';
|
|
13
13
|
|
|
14
|
+
type WithRenderKey<T> = T & { renderKey?: string };
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
17
|
* Creates a material component wrapper with dependency injection support
|
|
16
18
|
*
|
|
@@ -48,12 +50,15 @@ import {
|
|
|
48
50
|
* @returns Wrapper component with dependency injection support
|
|
49
51
|
*/
|
|
50
52
|
export function createInjectMaterial<Props>(
|
|
51
|
-
Component: React.FC<Props>
|
|
53
|
+
Component: WithRenderKey<React.FC<Props> | React.ExoticComponent<Props>>,
|
|
52
54
|
params?: {
|
|
53
55
|
renderKey?: string;
|
|
54
56
|
}
|
|
55
|
-
): React.FC<Props
|
|
56
|
-
|
|
57
|
+
): WithRenderKey<React.FC<Props>> {
|
|
58
|
+
// Determine render key: prioritize param specified, then component renderKey, finally component name
|
|
59
|
+
const renderKey = params?.renderKey || Component.renderKey || Component.name || '';
|
|
60
|
+
|
|
61
|
+
const InjectComponent: WithRenderKey<React.FC<Props>> = (props) => {
|
|
57
62
|
const container = usePlaygroundContainer();
|
|
58
63
|
|
|
59
64
|
// Check if renderer registry is bound in container
|
|
@@ -65,9 +70,6 @@ export function createInjectMaterial<Props>(
|
|
|
65
70
|
// Get renderer registry instance
|
|
66
71
|
const rendererRegistry = container.get(FlowRendererRegistry);
|
|
67
72
|
|
|
68
|
-
// Determine render key: prioritize param specified, then component renderKey, finally component name
|
|
69
|
-
const renderKey = params?.renderKey || Component.renderKey || Component.name || '';
|
|
70
|
-
|
|
71
73
|
// Get corresponding renderer from registry
|
|
72
74
|
const renderer = rendererRegistry.tryToGetRendererComponent(renderKey);
|
|
73
75
|
|
|
@@ -83,5 +85,7 @@ export function createInjectMaterial<Props>(
|
|
|
83
85
|
});
|
|
84
86
|
};
|
|
85
87
|
|
|
88
|
+
InjectComponent.renderKey = renderKey;
|
|
89
|
+
|
|
86
90
|
return InjectComponent;
|
|
87
91
|
}
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
import { isNil } from 'lodash-es';
|
|
7
7
|
import { FeedbackLevel, FlowNodeEntity, getNodeScope } from '@flowgram.ai/editor';
|
|
8
8
|
|
|
9
|
-
import { IFlowValue } from '@/shared';
|
|
10
|
-
import { FlowValueUtils } from '@/shared';
|
|
9
|
+
import { type IFlowValue, FlowValueUtils } from '@/shared';
|
|
11
10
|
|
|
12
11
|
interface Context {
|
|
13
12
|
node: FlowNodeEntity;
|