@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
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useLayoutEffect } from "react";
|
|
3
|
-
import { isEqual, last } from "lodash-es";
|
|
4
|
-
import { Disposable, DisposableCollection, useCurrentScope } from "@flowgram.ai/editor";
|
|
5
|
-
import { useInjector } from "@flowgram.ai/coze-editor/react";
|
|
6
|
-
import { Popover } from "@douyinfe/semi-ui";
|
|
7
|
-
import { IconIssueStroked } from "@douyinfe/semi-icons";
|
|
8
|
-
import { Decoration, EditorView, MatchDecorator, ViewPlugin, WidgetType } from "@codemirror/view";
|
|
9
|
-
import { polyfillCreateRoot } from "../../../shared/index.mjs";
|
|
10
|
-
import { UIPopoverContent, UIRootTitle, UITag, UIVarName } from "../styles.mjs";
|
|
11
|
-
class VariableTagWidget extends WidgetType {
|
|
12
|
-
constructor({ keyPath, scope }){
|
|
13
|
-
super(), this.toDispose = new DisposableCollection(), this.renderIcon = (icon)=>{
|
|
14
|
-
if ('string' == typeof icon) return /*#__PURE__*/ jsx("img", {
|
|
15
|
-
style: {
|
|
16
|
-
marginRight: 8
|
|
17
|
-
},
|
|
18
|
-
width: 12,
|
|
19
|
-
height: 12,
|
|
20
|
-
src: icon
|
|
21
|
-
});
|
|
22
|
-
return icon;
|
|
23
|
-
};
|
|
24
|
-
this.keyPath = keyPath;
|
|
25
|
-
this.scope = scope;
|
|
26
|
-
}
|
|
27
|
-
renderVariable(v) {
|
|
28
|
-
if (!v) return void this.root.render(/*#__PURE__*/ jsx(UITag, {
|
|
29
|
-
prefixIcon: /*#__PURE__*/ jsx(IconIssueStroked, {}),
|
|
30
|
-
color: "amber",
|
|
31
|
-
children: "Unknown"
|
|
32
|
-
}));
|
|
33
|
-
const rootField = last(v.parentFields);
|
|
34
|
-
const rootTitle = /*#__PURE__*/ jsx(UIRootTitle, {
|
|
35
|
-
children: rootField?.meta.title ? `${rootField.meta.title} -` : ''
|
|
36
|
-
});
|
|
37
|
-
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
38
|
-
this.root.render(/*#__PURE__*/ jsx(Popover, {
|
|
39
|
-
content: /*#__PURE__*/ jsxs(UIPopoverContent, {
|
|
40
|
-
children: [
|
|
41
|
-
rootIcon,
|
|
42
|
-
rootTitle,
|
|
43
|
-
/*#__PURE__*/ jsx(UIVarName, {
|
|
44
|
-
children: v?.keyPath.slice(1).join('.')
|
|
45
|
-
})
|
|
46
|
-
]
|
|
47
|
-
}),
|
|
48
|
-
children: /*#__PURE__*/ jsxs(UITag, {
|
|
49
|
-
prefixIcon: rootIcon,
|
|
50
|
-
children: [
|
|
51
|
-
rootTitle,
|
|
52
|
-
/*#__PURE__*/ jsx(UIVarName, {
|
|
53
|
-
children: v?.key
|
|
54
|
-
})
|
|
55
|
-
]
|
|
56
|
-
})
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
toDOM(view) {
|
|
60
|
-
const dom = document.createElement('span');
|
|
61
|
-
this.root = polyfillCreateRoot(dom);
|
|
62
|
-
this.toDispose.push(Disposable.create(()=>{
|
|
63
|
-
this.root.unmount();
|
|
64
|
-
}));
|
|
65
|
-
this.toDispose.push(this.scope.available.trackByKeyPath(this.keyPath, (v)=>{
|
|
66
|
-
this.renderVariable(v);
|
|
67
|
-
}, {
|
|
68
|
-
triggerOnInit: false
|
|
69
|
-
}));
|
|
70
|
-
this.renderVariable(this.scope.available.getByKeyPath(this.keyPath));
|
|
71
|
-
return dom;
|
|
72
|
-
}
|
|
73
|
-
eq(other) {
|
|
74
|
-
return isEqual(this.keyPath, other.keyPath);
|
|
75
|
-
}
|
|
76
|
-
ignoreEvent() {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
destroy(dom) {
|
|
80
|
-
this.toDispose.dispose();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function VariableTagInject() {
|
|
84
|
-
const injector = useInjector();
|
|
85
|
-
const scope = useCurrentScope();
|
|
86
|
-
useLayoutEffect(()=>{
|
|
87
|
-
const atMatcher = new MatchDecorator({
|
|
88
|
-
regexp: /\{\{([^\}\{]+)\}\}/g,
|
|
89
|
-
decoration: (match)=>Decoration.replace({
|
|
90
|
-
widget: new VariableTagWidget({
|
|
91
|
-
keyPath: match[1]?.split('.') ?? [],
|
|
92
|
-
scope
|
|
93
|
-
})
|
|
94
|
-
})
|
|
95
|
-
});
|
|
96
|
-
return injector.inject([
|
|
97
|
-
ViewPlugin.fromClass(class {
|
|
98
|
-
constructor(view){
|
|
99
|
-
this.view = view;
|
|
100
|
-
this.decorations = atMatcher.createDeco(view);
|
|
101
|
-
}
|
|
102
|
-
update() {
|
|
103
|
-
this.decorations = atMatcher.createDeco(this.view);
|
|
104
|
-
}
|
|
105
|
-
}, {
|
|
106
|
-
decorations: (p)=>p.decorations,
|
|
107
|
-
provide (p) {
|
|
108
|
-
return EditorView.atomicRanges.of((view)=>view.plugin(p)?.decorations ?? Decoration.none);
|
|
109
|
-
}
|
|
110
|
-
})
|
|
111
|
-
]);
|
|
112
|
-
}, [
|
|
113
|
-
injector
|
|
114
|
-
]);
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
export { VariableTagInject };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import styled_components from "styled-components";
|
|
2
|
-
import { Tag } from "@douyinfe/semi-ui";
|
|
3
|
-
const UIRootTitle = styled_components.div`
|
|
4
|
-
margin-right: 4px;
|
|
5
|
-
min-width: 20px;
|
|
6
|
-
overflow: hidden;
|
|
7
|
-
text-overflow: ellipsis;
|
|
8
|
-
white-space: nowrap;
|
|
9
|
-
color: var(--semi-color-text-2);
|
|
10
|
-
`;
|
|
11
|
-
const UIVarName = styled_components.div`
|
|
12
|
-
overflow: hidden;
|
|
13
|
-
text-overflow: ellipsis;
|
|
14
|
-
white-space: nowrap;
|
|
15
|
-
`;
|
|
16
|
-
const UITag = styled_components(Tag)`
|
|
17
|
-
display: inline-flex;
|
|
18
|
-
align-items: center;
|
|
19
|
-
justify-content: flex-start;
|
|
20
|
-
max-width: 300px;
|
|
21
|
-
|
|
22
|
-
& .semi-tag-content-center {
|
|
23
|
-
justify-content: flex-start;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
&.semi-tag {
|
|
27
|
-
margin: 0 5px;
|
|
28
|
-
}
|
|
29
|
-
`;
|
|
30
|
-
const UIPopoverContent = styled_components.div`
|
|
31
|
-
padding: 10px;
|
|
32
|
-
display: inline-flex;
|
|
33
|
-
align-items: center;
|
|
34
|
-
justify-content: flex-start;
|
|
35
|
-
`;
|
|
36
|
-
export { UIPopoverContent, UIRootTitle, UITag, UIVarName };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { IFlowValue } from '../../../shared';
|
|
7
|
-
export declare function InputsTree({ inputsValues }: {
|
|
8
|
-
inputsValues: Record<string, IFlowValue>;
|
|
9
|
-
}): React.JSX.Element;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
import { Tag } from '@douyinfe/semi-ui';
|
|
6
|
-
export declare const UIRootTitle: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
7
|
-
export declare const UIVarName: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
8
|
-
export declare const UITag: import("styled-components").StyledComponent<typeof Tag, any, {}, never>;
|
|
9
|
-
export declare const UIPopoverContent: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -1,83 +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 {
|
|
9
|
-
Mention,
|
|
10
|
-
MentionOpenChangeEvent,
|
|
11
|
-
getCurrentMentionReplaceRange,
|
|
12
|
-
useEditor,
|
|
13
|
-
PositionMirror,
|
|
14
|
-
} from '@flowgram.ai/coze-editor/react';
|
|
15
|
-
import { EditorAPI } from '@flowgram.ai/coze-editor/preset-prompt';
|
|
16
|
-
import { Popover, Tree } from '@douyinfe/semi-ui';
|
|
17
|
-
|
|
18
|
-
import { useVariableTree } from '@/components/variable-selector';
|
|
19
|
-
|
|
20
|
-
export function VariableTree() {
|
|
21
|
-
const [posKey, setPosKey] = useState('');
|
|
22
|
-
const [visible, setVisible] = useState(false);
|
|
23
|
-
const [position, setPosition] = useState(-1);
|
|
24
|
-
const editor = useEditor<EditorAPI>();
|
|
25
|
-
|
|
26
|
-
function insert(variablePath: string) {
|
|
27
|
-
const range = getCurrentMentionReplaceRange(editor.$view.state);
|
|
28
|
-
|
|
29
|
-
if (!range) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
editor.replaceText({
|
|
34
|
-
...range,
|
|
35
|
-
text: '{{' + variablePath + '}}',
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
setVisible(false);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function handleOpenChange(e: MentionOpenChangeEvent) {
|
|
42
|
-
setPosition(e.state.selection.main.head);
|
|
43
|
-
setVisible(e.value);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (!editor) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
}, [editor, visible]);
|
|
51
|
-
|
|
52
|
-
const treeData = useVariableTree({});
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<>
|
|
56
|
-
<Mention triggerCharacters={['@']} onOpenChange={handleOpenChange} />
|
|
57
|
-
|
|
58
|
-
<Popover
|
|
59
|
-
visible={visible}
|
|
60
|
-
trigger="custom"
|
|
61
|
-
position="topLeft"
|
|
62
|
-
rePosKey={posKey}
|
|
63
|
-
content={
|
|
64
|
-
<div style={{ width: 300 }}>
|
|
65
|
-
<Tree
|
|
66
|
-
treeData={treeData}
|
|
67
|
-
onSelect={(v) => {
|
|
68
|
-
insert(v);
|
|
69
|
-
}}
|
|
70
|
-
/>
|
|
71
|
-
</div>
|
|
72
|
-
}
|
|
73
|
-
>
|
|
74
|
-
{/* PositionMirror allows the Popover to appear at the specified cursor position */}
|
|
75
|
-
<PositionMirror
|
|
76
|
-
position={position}
|
|
77
|
-
// When Doc scroll, update position
|
|
78
|
-
onChange={() => setPosKey(String(Math.random()))}
|
|
79
|
-
/>
|
|
80
|
-
</Popover>
|
|
81
|
-
</>
|
|
82
|
-
);
|
|
83
|
-
}
|
|
@@ -1,94 +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 {
|
|
9
|
-
Mention,
|
|
10
|
-
MentionOpenChangeEvent,
|
|
11
|
-
getCurrentMentionReplaceRange,
|
|
12
|
-
useEditor,
|
|
13
|
-
PositionMirror,
|
|
14
|
-
} from '@flowgram.ai/coze-editor/react';
|
|
15
|
-
import { EditorAPI } from '@flowgram.ai/coze-editor/preset-prompt';
|
|
16
|
-
import { Popover } from '@douyinfe/semi-ui';
|
|
17
|
-
|
|
18
|
-
import { IFlowValue } from '@/shared';
|
|
19
|
-
|
|
20
|
-
import { InputsPicker } from '../inputs-picker';
|
|
21
|
-
|
|
22
|
-
export function InputsTree({ inputsValues }: { inputsValues: Record<string, IFlowValue> }) {
|
|
23
|
-
const [posKey, setPosKey] = useState('');
|
|
24
|
-
const [visible, setVisible] = useState(false);
|
|
25
|
-
const [position, setPosition] = useState(-1);
|
|
26
|
-
const editor = useEditor<EditorAPI>();
|
|
27
|
-
|
|
28
|
-
function insert(variablePath: string) {
|
|
29
|
-
const range = getCurrentMentionReplaceRange(editor.$view.state);
|
|
30
|
-
|
|
31
|
-
if (!range) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
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
|
-
|
|
46
|
-
editor.replaceText({
|
|
47
|
-
...range,
|
|
48
|
-
text: '{{' + variablePath + '}}',
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
setVisible(false);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function handleOpenChange(e: MentionOpenChangeEvent) {
|
|
55
|
-
setPosition(e.state.selection.main.head);
|
|
56
|
-
setVisible(e.value);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
if (!editor) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
}, [editor, visible]);
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
<>
|
|
67
|
-
<Mention triggerCharacters={['{', '{}', '@']} onOpenChange={handleOpenChange} />
|
|
68
|
-
|
|
69
|
-
<Popover
|
|
70
|
-
visible={visible}
|
|
71
|
-
trigger="custom"
|
|
72
|
-
position="topLeft"
|
|
73
|
-
rePosKey={posKey}
|
|
74
|
-
content={
|
|
75
|
-
<div style={{ width: 300 }}>
|
|
76
|
-
<InputsPicker
|
|
77
|
-
inputsValues={inputsValues}
|
|
78
|
-
onSelect={(v) => {
|
|
79
|
-
insert(v);
|
|
80
|
-
}}
|
|
81
|
-
/>
|
|
82
|
-
</div>
|
|
83
|
-
}
|
|
84
|
-
>
|
|
85
|
-
{/* PositionMirror allows the Popover to appear at the specified cursor position */}
|
|
86
|
-
<PositionMirror
|
|
87
|
-
position={position}
|
|
88
|
-
// When Doc scroll, update position
|
|
89
|
-
onChange={() => setPosKey(String(Math.random()))}
|
|
90
|
-
/>
|
|
91
|
-
</Popover>
|
|
92
|
-
</>
|
|
93
|
-
);
|
|
94
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import React, { useLayoutEffect } from 'react';
|
|
7
|
-
|
|
8
|
-
import { isEqual, last } from 'lodash-es';
|
|
9
|
-
import {
|
|
10
|
-
BaseVariableField,
|
|
11
|
-
Disposable,
|
|
12
|
-
DisposableCollection,
|
|
13
|
-
Scope,
|
|
14
|
-
useCurrentScope,
|
|
15
|
-
} from '@flowgram.ai/editor';
|
|
16
|
-
import { useInjector } from '@flowgram.ai/coze-editor/react';
|
|
17
|
-
import { Popover } from '@douyinfe/semi-ui';
|
|
18
|
-
import { IconIssueStroked } from '@douyinfe/semi-icons';
|
|
19
|
-
import {
|
|
20
|
-
Decoration,
|
|
21
|
-
DecorationSet,
|
|
22
|
-
EditorView,
|
|
23
|
-
MatchDecorator,
|
|
24
|
-
ViewPlugin,
|
|
25
|
-
WidgetType,
|
|
26
|
-
} from '@codemirror/view';
|
|
27
|
-
|
|
28
|
-
import { IPolyfillRoot, polyfillCreateRoot } from '@/shared';
|
|
29
|
-
|
|
30
|
-
import { UIPopoverContent, UIRootTitle, UITag, UIVarName } from '../styles';
|
|
31
|
-
|
|
32
|
-
class VariableTagWidget extends WidgetType {
|
|
33
|
-
keyPath?: string[];
|
|
34
|
-
|
|
35
|
-
toDispose = new DisposableCollection();
|
|
36
|
-
|
|
37
|
-
scope: Scope;
|
|
38
|
-
|
|
39
|
-
root: IPolyfillRoot;
|
|
40
|
-
|
|
41
|
-
constructor({ keyPath, scope }: { keyPath?: string[]; scope: Scope }) {
|
|
42
|
-
super();
|
|
43
|
-
|
|
44
|
-
this.keyPath = keyPath;
|
|
45
|
-
this.scope = scope;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
renderIcon = (icon: string | JSX.Element) => {
|
|
49
|
-
if (typeof icon === 'string') {
|
|
50
|
-
return <img style={{ marginRight: 8 }} width={12} height={12} src={icon} />;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return icon;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
renderVariable(v?: BaseVariableField) {
|
|
57
|
-
if (!v) {
|
|
58
|
-
this.root.render(
|
|
59
|
-
<UITag prefixIcon={<IconIssueStroked />} color="amber">
|
|
60
|
-
Unknown
|
|
61
|
-
</UITag>
|
|
62
|
-
);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const rootField = last(v.parentFields);
|
|
67
|
-
|
|
68
|
-
const rootTitle = (
|
|
69
|
-
<UIRootTitle>{rootField?.meta.title ? `${rootField.meta.title} -` : ''}</UIRootTitle>
|
|
70
|
-
);
|
|
71
|
-
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
72
|
-
|
|
73
|
-
this.root.render(
|
|
74
|
-
<Popover
|
|
75
|
-
content={
|
|
76
|
-
<UIPopoverContent>
|
|
77
|
-
{rootIcon}
|
|
78
|
-
{rootTitle}
|
|
79
|
-
<UIVarName>{v?.keyPath.slice(1).join('.')}</UIVarName>
|
|
80
|
-
</UIPopoverContent>
|
|
81
|
-
}
|
|
82
|
-
>
|
|
83
|
-
<UITag prefixIcon={rootIcon}>
|
|
84
|
-
{rootTitle}
|
|
85
|
-
<UIVarName>{v?.key}</UIVarName>
|
|
86
|
-
</UITag>
|
|
87
|
-
</Popover>
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
toDOM(view: EditorView): HTMLElement {
|
|
92
|
-
const dom = document.createElement('span');
|
|
93
|
-
|
|
94
|
-
this.root = polyfillCreateRoot(dom);
|
|
95
|
-
|
|
96
|
-
this.toDispose.push(
|
|
97
|
-
Disposable.create(() => {
|
|
98
|
-
this.root.unmount();
|
|
99
|
-
})
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
this.toDispose.push(
|
|
103
|
-
this.scope.available.trackByKeyPath(
|
|
104
|
-
this.keyPath,
|
|
105
|
-
(v) => {
|
|
106
|
-
this.renderVariable(v);
|
|
107
|
-
},
|
|
108
|
-
{ triggerOnInit: false }
|
|
109
|
-
)
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
this.renderVariable(this.scope.available.getByKeyPath(this.keyPath));
|
|
113
|
-
|
|
114
|
-
return dom;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
eq(other: VariableTagWidget) {
|
|
118
|
-
return isEqual(this.keyPath, other.keyPath);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
ignoreEvent(): boolean {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
destroy(dom: HTMLElement): void {
|
|
126
|
-
this.toDispose.dispose();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function VariableTagInject() {
|
|
131
|
-
const injector = useInjector();
|
|
132
|
-
|
|
133
|
-
const scope = useCurrentScope();
|
|
134
|
-
|
|
135
|
-
// 基于 {{var}} 的正则进行匹配,匹配后进行自定义渲染
|
|
136
|
-
useLayoutEffect(() => {
|
|
137
|
-
const atMatcher = new MatchDecorator({
|
|
138
|
-
regexp: /\{\{([^\}\{]+)\}\}/g,
|
|
139
|
-
decoration: (match) =>
|
|
140
|
-
Decoration.replace({
|
|
141
|
-
widget: new VariableTagWidget({
|
|
142
|
-
keyPath: match[1]?.split('.') ?? [],
|
|
143
|
-
scope,
|
|
144
|
-
}),
|
|
145
|
-
}),
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
return injector.inject([
|
|
149
|
-
ViewPlugin.fromClass(
|
|
150
|
-
class {
|
|
151
|
-
decorations: DecorationSet;
|
|
152
|
-
|
|
153
|
-
constructor(private view: EditorView) {
|
|
154
|
-
this.decorations = atMatcher.createDeco(view);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
update() {
|
|
158
|
-
this.decorations = atMatcher.createDeco(this.view);
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
decorations: (p) => p.decorations,
|
|
163
|
-
provide(p) {
|
|
164
|
-
return EditorView.atomicRanges.of(
|
|
165
|
-
(view) => view.plugin(p)?.decorations ?? Decoration.none
|
|
166
|
-
);
|
|
167
|
-
},
|
|
168
|
-
}
|
|
169
|
-
),
|
|
170
|
-
]);
|
|
171
|
-
}, [injector]);
|
|
172
|
-
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import styled from 'styled-components';
|
|
7
|
-
import { Tag } from '@douyinfe/semi-ui';
|
|
8
|
-
|
|
9
|
-
export const UIRootTitle = styled.div`
|
|
10
|
-
margin-right: 4px;
|
|
11
|
-
min-width: 20px;
|
|
12
|
-
overflow: hidden;
|
|
13
|
-
text-overflow: ellipsis;
|
|
14
|
-
white-space: nowrap;
|
|
15
|
-
color: var(--semi-color-text-2);
|
|
16
|
-
`;
|
|
17
|
-
|
|
18
|
-
export const UIVarName = styled.div`
|
|
19
|
-
overflow: hidden;
|
|
20
|
-
text-overflow: ellipsis;
|
|
21
|
-
white-space: nowrap;
|
|
22
|
-
`;
|
|
23
|
-
|
|
24
|
-
export const UITag = styled(Tag)`
|
|
25
|
-
display: inline-flex;
|
|
26
|
-
align-items: center;
|
|
27
|
-
justify-content: flex-start;
|
|
28
|
-
max-width: 300px;
|
|
29
|
-
|
|
30
|
-
& .semi-tag-content-center {
|
|
31
|
-
justify-content: flex-start;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
&.semi-tag {
|
|
35
|
-
margin: 0 5px;
|
|
36
|
-
}
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
export const UIPopoverContent = styled.div`
|
|
40
|
-
padding: 10px;
|
|
41
|
-
display: inline-flex;
|
|
42
|
-
align-items: center;
|
|
43
|
-
justify-content: flex-start;
|
|
44
|
-
`;
|
|
File without changes
|
/package/dist/cjs/components/{json-editor-with-variables → coze-editor-extensions}/styles.js
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/esm/components/{json-editor-with-variables → coze-editor-extensions}/styles.mjs
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/types/components/{json-editor-with-variables → coze-editor-extensions}/styles.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|