@cozeloop/prompt-components 0.0.1 → 0.0.2
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/edenx.config.d.ts +2 -0
- package/dist/{es/basic-editor/extensions/go-syntax.js → go-syntax-067c4f5d.mjs} +16 -9
- package/dist/go-syntax-4deb0289.js +8 -0
- package/dist/{es/basic-editor/extensions/go-theme.js → go-theme-062a6df6.mjs} +3 -4
- package/dist/go-theme-fbd8a4fa.js +1 -0
- package/dist/index.cjs +61 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2788 -0
- package/dist/{types → src}/basic-editor/custom-facet.d.ts +2 -1
- package/dist/src/basic-editor/diff.d.ts +16 -0
- package/dist/src/basic-editor/extensions/go-syntax.d.ts +71 -0
- package/dist/src/basic-editor/extensions/go-template.d.ts +1 -0
- package/dist/{types → src}/basic-editor/extensions/go-theme.d.ts +1 -1
- package/dist/src/basic-editor/extensions/jinja.d.ts +4 -0
- package/dist/{types → src}/basic-editor/extensions/keymap.d.ts +3 -2
- package/dist/src/basic-editor/extensions/language-support.d.ts +2 -0
- package/dist/src/basic-editor/extensions/markdown.d.ts +2 -0
- package/dist/src/basic-editor/extensions/search/dom/icon.d.ts +59 -0
- package/dist/src/basic-editor/extensions/search/dom/match-count.d.ts +14 -0
- package/dist/src/basic-editor/extensions/search/index.d.ts +1 -0
- package/dist/src/basic-editor/extensions/search/panel.d.ts +33 -0
- package/dist/src/basic-editor/extensions/search/theme.d.ts +1 -0
- package/dist/src/basic-editor/extensions/validation.d.ts +8 -0
- package/dist/src/basic-editor/extensions/variable.d.ts +11 -0
- package/dist/src/basic-editor/index.d.ts +29 -0
- package/dist/{types → src}/code-editor/index.d.ts +1 -1
- package/dist/src/code-editor/json-editor.d.ts +18 -0
- package/dist/src/code-editor/raw-text-editor.d.ts +11 -0
- package/dist/{types → src}/consts/index.d.ts +1 -1
- package/dist/src/dev-layout/index.d.ts +7 -0
- package/dist/{types → src}/index.d.ts +7 -7
- package/dist/src/mermaid-diagram/index.d.ts +12 -0
- package/dist/src/mermaid-diagram/use-svg-pan-zoom.d.ts +12 -0
- package/dist/{types → src}/mermaid-diagram/utils.d.ts +1 -1
- package/dist/src/model-config-editor/basic-type.d.ts +13 -0
- package/dist/src/model-config-editor/model-config-form.d.ts +13 -0
- package/dist/src/model-config-editor/popover-type.d.ts +19 -0
- package/dist/src/model-select/index.d.ts +27 -0
- package/dist/src/model-select/model-option/index.d.ts +25 -0
- package/dist/src/model-select/model-option-group/index.d.ts +16 -0
- package/dist/src/prompt-editor/index.d.ts +31 -0
- package/dist/src/prompt-editor/message-type-select.d.ts +11 -0
- package/dist/src/schema-editor/index.d.ts +11 -0
- package/dist/{types → src}/utils/base.d.ts +5 -4
- package/dist/src/utils/model-config.d.ts +5 -0
- package/dist/style.css +1 -0
- package/dist/test-build.d.ts +7 -0
- package/dist/vite.config.d.ts +2 -0
- package/package.json +15 -5
- package/dist/es/basic-editor/custom-facet.js +0 -9
- package/dist/es/basic-editor/diff.js +0 -138
- package/dist/es/basic-editor/extensions/go-template.js +0 -16
- package/dist/es/basic-editor/extensions/jinja.js +0 -80
- package/dist/es/basic-editor/extensions/keymap.js +0 -442
- package/dist/es/basic-editor/extensions/language-support.js +0 -12
- package/dist/es/basic-editor/extensions/markdown.js +0 -58
- package/dist/es/basic-editor/extensions/search/dom/icon.js +0 -250
- package/dist/es/basic-editor/extensions/search/dom/match-count.js +0 -33
- package/dist/es/basic-editor/extensions/search/index.js +0 -18
- package/dist/es/basic-editor/extensions/search/panel.js +0 -418
- package/dist/es/basic-editor/extensions/search/theme.js +0 -184
- package/dist/es/basic-editor/extensions/validation.js +0 -84
- package/dist/es/basic-editor/extensions/validation.module.js +0 -5
- package/dist/es/basic-editor/extensions/validation_module.css +0 -7
- package/dist/es/basic-editor/extensions/variable.js +0 -178
- package/dist/es/basic-editor/index.js +0 -171
- package/dist/es/code-editor/code-editor.js +0 -83
- package/dist/es/code-editor/index.js +0 -12
- package/dist/es/code-editor/json-editor.js +0 -157
- package/dist/es/code-editor/raw-text-editor.js +0 -46
- package/dist/es/code-editor/text-editor.js +0 -41
- package/dist/es/code-editor/themes/coze-dark.js +0 -112
- package/dist/es/code-editor/themes/coze-light.js +0 -118
- package/dist/es/consts/index.js +0 -12
- package/dist/es/dev-layout/index.js +0 -35
- package/dist/es/index.js +0 -66
- package/dist/es/mermaid-diagram/index.js +0 -148
- package/dist/es/mermaid-diagram/index.module.js +0 -5
- package/dist/es/mermaid-diagram/index_module.css +0 -4
- package/dist/es/mermaid-diagram/use-svg-pan-zoom.js +0 -49
- package/dist/es/mermaid-diagram/utils.js +0 -74
- package/dist/es/model-config-editor/basic-type.js +0 -73
- package/dist/es/model-config-editor/index.module.js +0 -5
- package/dist/es/model-config-editor/index_module.css +0 -8
- package/dist/es/model-config-editor/model-config-form.js +0 -130
- package/dist/es/model-config-editor/popover-type.js +0 -118
- package/dist/es/model-select/index.js +0 -136
- package/dist/es/model-select/index.module.js +0 -5
- package/dist/es/model-select/index_module.css +0 -14
- package/dist/es/model-select/model-option/index.js +0 -161
- package/dist/es/model-select/model-option/index.module.js +0 -5
- package/dist/es/model-select/model-option/index_module.css +0 -23
- package/dist/es/model-select/model-option-group/index.js +0 -44
- package/dist/es/prompt-editor/index.js +0 -188
- package/dist/es/prompt-editor/index.module.js +0 -5
- package/dist/es/prompt-editor/index_module.css +0 -71
- package/dist/es/prompt-editor/message-type-select.js +0 -74
- package/dist/es/schema-editor/index.js +0 -43
- package/dist/es/utils/base.js +0 -53
- package/dist/es/utils/model-config.js +0 -32
- package/dist/lib/basic-editor/custom-facet.js +0 -33
- package/dist/lib/basic-editor/diff.js +0 -167
- package/dist/lib/basic-editor/extensions/go-syntax.js +0 -146
- package/dist/lib/basic-editor/extensions/go-template.js +0 -50
- package/dist/lib/basic-editor/extensions/go-theme.js +0 -1091
- package/dist/lib/basic-editor/extensions/jinja.js +0 -100
- package/dist/lib/basic-editor/extensions/keymap.js +0 -465
- package/dist/lib/basic-editor/extensions/language-support.js +0 -32
- package/dist/lib/basic-editor/extensions/markdown.js +0 -78
- package/dist/lib/basic-editor/extensions/search/dom/icon.js +0 -291
- package/dist/lib/basic-editor/extensions/search/dom/match-count.js +0 -67
- package/dist/lib/basic-editor/extensions/search/index.js +0 -38
- package/dist/lib/basic-editor/extensions/search/panel.js +0 -429
- package/dist/lib/basic-editor/extensions/search/theme.js +0 -208
- package/dist/lib/basic-editor/extensions/validation.js +0 -118
- package/dist/lib/basic-editor/extensions/validation.module.js +0 -25
- package/dist/lib/basic-editor/extensions/validation_module.css +0 -7
- package/dist/lib/basic-editor/extensions/variable.js +0 -190
- package/dist/lib/basic-editor/index.js +0 -193
- package/dist/lib/code-editor/code-editor.js +0 -117
- package/dist/lib/code-editor/index.js +0 -40
- package/dist/lib/code-editor/json-editor.js +0 -184
- package/dist/lib/code-editor/raw-text-editor.js +0 -70
- package/dist/lib/code-editor/text-editor.js +0 -75
- package/dist/lib/code-editor/themes/coze-dark.js +0 -136
- package/dist/lib/code-editor/themes/coze-light.js +0 -142
- package/dist/lib/consts/index.js +0 -38
- package/dist/lib/dev-layout/index.js +0 -69
- package/dist/lib/index.js +0 -110
- package/dist/lib/mermaid-diagram/index.js +0 -174
- package/dist/lib/mermaid-diagram/index.module.js +0 -25
- package/dist/lib/mermaid-diagram/index_module.css +0 -4
- package/dist/lib/mermaid-diagram/use-svg-pan-zoom.js +0 -83
- package/dist/lib/mermaid-diagram/utils.js +0 -98
- package/dist/lib/model-config-editor/basic-type.js +0 -105
- package/dist/lib/model-config-editor/index.module.js +0 -25
- package/dist/lib/model-config-editor/index_module.css +0 -8
- package/dist/lib/model-config-editor/model-config-form.js +0 -149
- package/dist/lib/model-config-editor/popover-type.js +0 -145
- package/dist/lib/model-select/index.js +0 -170
- package/dist/lib/model-select/index.module.js +0 -25
- package/dist/lib/model-select/index_module.css +0 -14
- package/dist/lib/model-select/model-option/index.js +0 -188
- package/dist/lib/model-select/model-option/index.module.js +0 -25
- package/dist/lib/model-select/model-option/index_module.css +0 -23
- package/dist/lib/model-select/model-option-group/index.js +0 -75
- package/dist/lib/prompt-editor/index.js +0 -218
- package/dist/lib/prompt-editor/index.module.js +0 -25
- package/dist/lib/prompt-editor/index_module.css +0 -71
- package/dist/lib/prompt-editor/message-type-select.js +0 -108
- package/dist/lib/schema-editor/index.js +0 -77
- package/dist/lib/utils/base.js +0 -82
- package/dist/lib/utils/model-config.js +0 -57
- package/dist/types/basic-editor/diff.d.ts +0 -15
- package/dist/types/basic-editor/extensions/go-syntax.d.ts +0 -71
- package/dist/types/basic-editor/extensions/go-template.d.ts +0 -1
- package/dist/types/basic-editor/extensions/jinja.d.ts +0 -6
- package/dist/types/basic-editor/extensions/language-support.d.ts +0 -2
- package/dist/types/basic-editor/extensions/markdown.d.ts +0 -2
- package/dist/types/basic-editor/extensions/search/dom/icon.d.ts +0 -59
- package/dist/types/basic-editor/extensions/search/dom/match-count.d.ts +0 -14
- package/dist/types/basic-editor/extensions/search/index.d.ts +0 -1
- package/dist/types/basic-editor/extensions/search/panel.d.ts +0 -32
- package/dist/types/basic-editor/extensions/search/theme.d.ts +0 -1
- package/dist/types/basic-editor/extensions/validation.d.ts +0 -10
- package/dist/types/basic-editor/extensions/variable.d.ts +0 -14
- package/dist/types/basic-editor/index.d.ts +0 -28
- package/dist/types/code-editor/code-editor.d.ts +0 -23
- package/dist/types/code-editor/json-editor.d.ts +0 -17
- package/dist/types/code-editor/raw-text-editor.d.ts +0 -11
- package/dist/types/code-editor/text-editor.d.ts +0 -23
- package/dist/types/code-editor/themes/coze-dark.d.ts +0 -1
- package/dist/types/code-editor/themes/coze-light.d.ts +0 -1
- package/dist/types/dev-layout/index.d.ts +0 -13
- package/dist/types/mermaid-diagram/index.d.ts +0 -12
- package/dist/types/mermaid-diagram/use-svg-pan-zoom.d.ts +0 -17
- package/dist/types/model-config-editor/basic-type.d.ts +0 -19
- package/dist/types/model-config-editor/model-config-form.d.ts +0 -14
- package/dist/types/model-config-editor/popover-type.d.ts +0 -25
- package/dist/types/model-select/index.d.ts +0 -38
- package/dist/types/model-select/model-option/index.d.ts +0 -30
- package/dist/types/model-select/model-option-group/index.d.ts +0 -15
- package/dist/types/prompt-editor/index.d.ts +0 -30
- package/dist/types/prompt-editor/message-type-select.d.ts +0 -16
- package/dist/types/schema-editor/index.d.ts +0 -18
- package/dist/types/utils/model-config.d.ts +0 -4
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
21
|
-
import { useEffect, useState } from "react";
|
|
22
|
-
import {
|
|
23
|
-
Mention,
|
|
24
|
-
getCurrentMentionReplaceRange,
|
|
25
|
-
useEditor,
|
|
26
|
-
PositionMirror,
|
|
27
|
-
useLatest
|
|
28
|
-
} from "@coze-editor/editor/react";
|
|
29
|
-
import { Popover, Typography } from "@coze-arch/coze-design";
|
|
30
|
-
function Variable({
|
|
31
|
-
variables,
|
|
32
|
-
isGoTemplate
|
|
33
|
-
}) {
|
|
34
|
-
const [posKey, setPosKey] = useState("");
|
|
35
|
-
const [visible, setVisible] = useState(false);
|
|
36
|
-
const [position, setPosition] = useState(-1);
|
|
37
|
-
const editor = useEditor();
|
|
38
|
-
function insert(variableName) {
|
|
39
|
-
const range = getCurrentMentionReplaceRange(editor.$view.state);
|
|
40
|
-
if (!range) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
editor.replaceText(__spreadProps(__spreadValues({}, range), {
|
|
44
|
-
text: isGoTemplate ? `{{.${variableName}}}` : `{{${variableName}}}`,
|
|
45
|
-
cursorOffset: variableName ? 0 : -2
|
|
46
|
-
}));
|
|
47
|
-
setVisible(false);
|
|
48
|
-
}
|
|
49
|
-
function handleOpenChange(e) {
|
|
50
|
-
setPosition(e.state.selection.main.head);
|
|
51
|
-
setVisible(e.value && variables.length > 0);
|
|
52
|
-
}
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
if (!editor) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (visible) {
|
|
58
|
-
editor.disableKeybindings(["ArrowUp", "ArrowDown", "Enter"]);
|
|
59
|
-
} else {
|
|
60
|
-
editor.disableKeybindings([]);
|
|
61
|
-
}
|
|
62
|
-
}, [editor, visible]);
|
|
63
|
-
const selectedIndex = usePopoverNavigation({
|
|
64
|
-
enable: visible,
|
|
65
|
-
variables,
|
|
66
|
-
onApply: insert
|
|
67
|
-
});
|
|
68
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
69
|
-
/* @__PURE__ */ jsx(
|
|
70
|
-
Mention,
|
|
71
|
-
{
|
|
72
|
-
trigger: (tr) => {
|
|
73
|
-
if (tr.docChanged) {
|
|
74
|
-
let context = void 0;
|
|
75
|
-
tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
|
|
76
|
-
if (fromA > 0 && // 新增,非替换
|
|
77
|
-
fromA === toA && // 新增内容为 {
|
|
78
|
-
inserted.toString() === "{}" && // { 前还有个 {
|
|
79
|
-
tr.state.sliceDoc(
|
|
80
|
-
Math.max(0, fromA - 1),
|
|
81
|
-
Math.max(0, fromA)
|
|
82
|
-
) === "{") {
|
|
83
|
-
context = {
|
|
84
|
-
from: fromB - 1,
|
|
85
|
-
to: toB + 1,
|
|
86
|
-
triggerCharacter: "{{",
|
|
87
|
-
cursorPosition: tr.state.selection.main.head
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
return context;
|
|
92
|
-
}
|
|
93
|
-
return void 0;
|
|
94
|
-
},
|
|
95
|
-
onOpenChange: handleOpenChange
|
|
96
|
-
}
|
|
97
|
-
),
|
|
98
|
-
/* @__PURE__ */ jsx(
|
|
99
|
-
Popover,
|
|
100
|
-
{
|
|
101
|
-
visible,
|
|
102
|
-
trigger: "custom",
|
|
103
|
-
position: "topLeft",
|
|
104
|
-
rePosKey: posKey,
|
|
105
|
-
content: /* @__PURE__ */ jsxs("div", { className: "p-1 min-w-[100px] flex flex-col gap-1", children: [
|
|
106
|
-
/* @__PURE__ */ jsx(Typography.Text, { type: "secondary", strong: true, children: "插入变量" }),
|
|
107
|
-
/* @__PURE__ */ jsx("div", { className: "max-h-[200px] overflow-y-auto", children: variables.map((variable, index) => /* @__PURE__ */ jsx(
|
|
108
|
-
"div",
|
|
109
|
-
{
|
|
110
|
-
className: `cursor-pointer hover:bg-gray-100 px-2 py-1 mb-0.5 rounded ${selectedIndex === index ? "!bg-gray-200" : ""}`,
|
|
111
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
112
|
-
onClick: () => (variable == null ? void 0 : variable.key) && insert(variable.key),
|
|
113
|
-
children: variable.key
|
|
114
|
-
},
|
|
115
|
-
variable.key
|
|
116
|
-
)) })
|
|
117
|
-
] }),
|
|
118
|
-
onClickOutSide: () => setVisible(false),
|
|
119
|
-
children: /* @__PURE__ */ jsx(
|
|
120
|
-
PositionMirror,
|
|
121
|
-
{
|
|
122
|
-
position,
|
|
123
|
-
onChange: () => setPosKey(String(Math.random()))
|
|
124
|
-
}
|
|
125
|
-
)
|
|
126
|
-
}
|
|
127
|
-
)
|
|
128
|
-
] });
|
|
129
|
-
}
|
|
130
|
-
function usePopoverNavigation(options) {
|
|
131
|
-
const { enable, variables, onApply } = options;
|
|
132
|
-
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
133
|
-
const indexRef = useLatest(selectedIndex);
|
|
134
|
-
const variablesRef = useLatest([...variables, { key: "" }]);
|
|
135
|
-
const onApplyRef = useLatest(onApply);
|
|
136
|
-
useEffect(() => {
|
|
137
|
-
setSelectedIndex(0);
|
|
138
|
-
}, [enable]);
|
|
139
|
-
useEffect(() => {
|
|
140
|
-
if (!enable) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
function handleNavigation(e) {
|
|
144
|
-
switch (e.key) {
|
|
145
|
-
case "ArrowUp":
|
|
146
|
-
setSelectedIndex((prevIndex) => {
|
|
147
|
-
const nextIndex = prevIndex - 1;
|
|
148
|
-
return Math.max(0, nextIndex);
|
|
149
|
-
});
|
|
150
|
-
break;
|
|
151
|
-
case "ArrowDown":
|
|
152
|
-
setSelectedIndex((prevIndex) => {
|
|
153
|
-
const nextIndex = prevIndex + 1;
|
|
154
|
-
return Math.min(variablesRef.current.length - 1, nextIndex);
|
|
155
|
-
});
|
|
156
|
-
break;
|
|
157
|
-
case "Enter": {
|
|
158
|
-
const variableName = variablesRef.current[indexRef.current];
|
|
159
|
-
if (variableName) {
|
|
160
|
-
onApplyRef.current(variableName.key || "");
|
|
161
|
-
}
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
default:
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
document.addEventListener("keydown", handleNavigation, false);
|
|
169
|
-
return () => {
|
|
170
|
-
document.removeEventListener("keydown", handleNavigation, false);
|
|
171
|
-
};
|
|
172
|
-
}, [enable]);
|
|
173
|
-
return selectedIndex;
|
|
174
|
-
}
|
|
175
|
-
var variable_default = Variable;
|
|
176
|
-
export {
|
|
177
|
-
variable_default as default
|
|
178
|
-
};
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
21
|
-
import {
|
|
22
|
-
forwardRef,
|
|
23
|
-
useEffect,
|
|
24
|
-
useImperativeHandle,
|
|
25
|
-
useMemo,
|
|
26
|
-
useRef
|
|
27
|
-
} from "react";
|
|
28
|
-
import {
|
|
29
|
-
EditorProvider,
|
|
30
|
-
Renderer,
|
|
31
|
-
Placeholder
|
|
32
|
-
} from "@coze-editor/editor/react";
|
|
33
|
-
import preset from "@coze-editor/editor/preset-prompt";
|
|
34
|
-
import { EditorView, keymap } from "@codemirror/view";
|
|
35
|
-
import { Prec } from "@codemirror/state";
|
|
36
|
-
import { indentWithTab } from "@codemirror/commands";
|
|
37
|
-
import Variable from "./extensions/variable";
|
|
38
|
-
import Validation from "./extensions/validation";
|
|
39
|
-
import { search } from "./extensions/search";
|
|
40
|
-
import MarkdownHighlight from "./extensions/markdown";
|
|
41
|
-
import LanguageSupport from "./extensions/language-support";
|
|
42
|
-
import { insertFourSpaces } from "./extensions/keymap";
|
|
43
|
-
import JinjaHighlight from "./extensions/jinja";
|
|
44
|
-
import { goExtension } from "./extensions/go-template";
|
|
45
|
-
const extensions = [
|
|
46
|
-
EditorView.theme({
|
|
47
|
-
".cm-gutters": {
|
|
48
|
-
backgroundColor: "transparent",
|
|
49
|
-
borderRight: "none"
|
|
50
|
-
},
|
|
51
|
-
".cm-scroller": {
|
|
52
|
-
paddingLeft: "10px",
|
|
53
|
-
paddingRight: "6px !important"
|
|
54
|
-
}
|
|
55
|
-
}),
|
|
56
|
-
Prec.high(keymap.of([{ key: "Tab", run: insertFourSpaces }, indentWithTab]))
|
|
57
|
-
];
|
|
58
|
-
const PromptBasicEditor = forwardRef(
|
|
59
|
-
({
|
|
60
|
-
defaultValue,
|
|
61
|
-
onChange,
|
|
62
|
-
variables,
|
|
63
|
-
height,
|
|
64
|
-
minHeight,
|
|
65
|
-
maxHeight,
|
|
66
|
-
fontSize = 13,
|
|
67
|
-
forbidJinjaHighlight,
|
|
68
|
-
forbidVariables,
|
|
69
|
-
readOnly,
|
|
70
|
-
linePlaceholder = "请输入内容,支持按此格式书写变量:{{USER_NAME}}",
|
|
71
|
-
customExtensions = [],
|
|
72
|
-
autoScrollToBottom,
|
|
73
|
-
onBlur,
|
|
74
|
-
isGoTemplate,
|
|
75
|
-
onFocus,
|
|
76
|
-
canSearch,
|
|
77
|
-
children,
|
|
78
|
-
isJinja2Template
|
|
79
|
-
}, ref) => {
|
|
80
|
-
const editorRef = useRef(null);
|
|
81
|
-
useImperativeHandle(ref, () => ({
|
|
82
|
-
setEditorValue: (value) => {
|
|
83
|
-
var _a;
|
|
84
|
-
const editor = editorRef.current;
|
|
85
|
-
if (!editor) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
(_a = editor == null ? void 0 : editor.setValue) == null ? void 0 : _a.call(editor, value || "");
|
|
89
|
-
},
|
|
90
|
-
insertText: (text) => {
|
|
91
|
-
const editor = editorRef.current;
|
|
92
|
-
if (!editor) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const range = editor.getSelection();
|
|
96
|
-
if (!range) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
editor.replaceText(__spreadProps(__spreadValues({}, range), {
|
|
100
|
-
text,
|
|
101
|
-
cursorOffset: 0
|
|
102
|
-
}));
|
|
103
|
-
}
|
|
104
|
-
}));
|
|
105
|
-
const newExtensions = useMemo(() => {
|
|
106
|
-
const xExtensions = [...extensions, ...customExtensions];
|
|
107
|
-
const searchExt = canSearch ? [...search()] : [];
|
|
108
|
-
if (isGoTemplate) {
|
|
109
|
-
return [...xExtensions, goExtension, ...searchExt];
|
|
110
|
-
}
|
|
111
|
-
return [...xExtensions, ...searchExt];
|
|
112
|
-
}, [customExtensions, extensions, isGoTemplate, canSearch]);
|
|
113
|
-
useEffect(() => {
|
|
114
|
-
if (isJinja2Template || isGoTemplate) {
|
|
115
|
-
setTimeout(() => {
|
|
116
|
-
var _a;
|
|
117
|
-
(_a = editorRef.current) == null ? void 0 : _a.updateWholeDecorations();
|
|
118
|
-
}, 150);
|
|
119
|
-
}
|
|
120
|
-
}, [variables, isJinja2Template, isGoTemplate]);
|
|
121
|
-
return /* @__PURE__ */ jsxs(EditorProvider, { children: [
|
|
122
|
-
/* @__PURE__ */ jsx(
|
|
123
|
-
Renderer,
|
|
124
|
-
{
|
|
125
|
-
plugins: preset,
|
|
126
|
-
defaultValue,
|
|
127
|
-
options: {
|
|
128
|
-
editable: !readOnly,
|
|
129
|
-
readOnly,
|
|
130
|
-
height,
|
|
131
|
-
minHeight: minHeight || height,
|
|
132
|
-
maxHeight: maxHeight || height,
|
|
133
|
-
fontSize
|
|
134
|
-
},
|
|
135
|
-
onChange: (e) => onChange == null ? void 0 : onChange(e.value),
|
|
136
|
-
onFocus,
|
|
137
|
-
onBlur,
|
|
138
|
-
extensions: newExtensions,
|
|
139
|
-
didMount: (editor) => {
|
|
140
|
-
editorRef.current = editor;
|
|
141
|
-
if (autoScrollToBottom) {
|
|
142
|
-
editor.$view.dispatch({
|
|
143
|
-
effects: EditorView.scrollIntoView(
|
|
144
|
-
editor.$view.state.doc.length
|
|
145
|
-
)
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
),
|
|
151
|
-
!forbidVariables && /* @__PURE__ */ jsx(Variable, { variables: variables || [], isGoTemplate }),
|
|
152
|
-
/* @__PURE__ */ jsx(LanguageSupport, {}),
|
|
153
|
-
!forbidJinjaHighlight && !isGoTemplate && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
154
|
-
/* @__PURE__ */ jsx(
|
|
155
|
-
Validation,
|
|
156
|
-
{
|
|
157
|
-
variables,
|
|
158
|
-
isNormalTemplate: !isJinja2Template && !isGoTemplate
|
|
159
|
-
}
|
|
160
|
-
),
|
|
161
|
-
/* @__PURE__ */ jsx(JinjaHighlight, { isJinja2Template })
|
|
162
|
-
] }),
|
|
163
|
-
/* @__PURE__ */ jsx(MarkdownHighlight, {}),
|
|
164
|
-
/* @__PURE__ */ jsx(Placeholder, { children: linePlaceholder }),
|
|
165
|
-
children
|
|
166
|
-
] });
|
|
167
|
-
}
|
|
168
|
-
);
|
|
169
|
-
export {
|
|
170
|
-
PromptBasicEditor
|
|
171
|
-
};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { createRenderer, option } from "@coze-editor/editor/react";
|
|
2
|
-
import preset, { languages, themes } from "@coze-editor/editor/preset-code";
|
|
3
|
-
import { shell } from "@coze-editor/editor/language-shell";
|
|
4
|
-
import { json } from "@coze-editor/editor/language-json";
|
|
5
|
-
import { mixLanguages } from "@coze-editor/editor";
|
|
6
|
-
import { EditorView } from "@codemirror/view";
|
|
7
|
-
import { cozeLight } from "./themes/coze-light";
|
|
8
|
-
import { cozeDark } from "./themes/coze-dark";
|
|
9
|
-
languages.register("json", {
|
|
10
|
-
// mixLanguages 用于解决 「插值也使用了括号,导致无法正确高亮」的问题
|
|
11
|
-
language: mixLanguages({
|
|
12
|
-
outerLanguage: json.language
|
|
13
|
-
}),
|
|
14
|
-
languageService: json.languageService
|
|
15
|
-
});
|
|
16
|
-
languages.register("shell", shell);
|
|
17
|
-
themes.register("coze-light", cozeLight);
|
|
18
|
-
themes.register("coze-dark", cozeDark);
|
|
19
|
-
const minHeightOption = (value) => EditorView.theme({
|
|
20
|
-
".cm-content, .cm-gutter, .cm-right-gutter": {
|
|
21
|
-
minHeight: typeof value === "number" ? `${value}px` : typeof value === "string" ? value : "unset"
|
|
22
|
-
},
|
|
23
|
-
"&.cm-editor": {
|
|
24
|
-
minHeight: typeof value === "number" ? `${value}px` : typeof value === "string" ? value : "unset"
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
const maxHeightOption = (value) => EditorView.theme({
|
|
28
|
-
"&.cm-editor": {
|
|
29
|
-
maxHeight: typeof value === "number" ? `${value}px` : typeof value === "string" ? value : "unset"
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
const heightOption = (value) => EditorView.theme({
|
|
33
|
-
"&.cm-editor": {
|
|
34
|
-
height: typeof value === "number" ? `${value}px` : typeof value === "string" ? value : "unset"
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
const paddingOption = (value) => EditorView.theme({
|
|
38
|
-
"&.cm-editor": {
|
|
39
|
-
padding: typeof value === "number" ? `${value}px` : typeof value === "string" ? value : "unset"
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
const borderRadiusOption = (value) => EditorView.theme({
|
|
43
|
-
"&.cm-editor, .cm-gutters": {
|
|
44
|
-
borderRadius: typeof value === "number" ? `${value}px` : typeof value === "string" ? value : "unset"
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
const lineHeightOption = (value) => EditorView.theme({
|
|
48
|
-
".cm-content, .cm-gutter, .cm-right-gutter": {
|
|
49
|
-
lineHeight: typeof value === "number" ? `${value}px` : typeof value === "string" ? value : "unset"
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
function createStyleOptions() {
|
|
53
|
-
return [
|
|
54
|
-
option("minHeight", minHeightOption),
|
|
55
|
-
option("maxHeight", maxHeightOption),
|
|
56
|
-
option("editerHeight", heightOption),
|
|
57
|
-
option("borderRadius", borderRadiusOption),
|
|
58
|
-
option("padding", paddingOption),
|
|
59
|
-
option("lineHeight", lineHeightOption)
|
|
60
|
-
];
|
|
61
|
-
}
|
|
62
|
-
const builtinExtensions = [
|
|
63
|
-
EditorView.theme({
|
|
64
|
-
"&.cm-focused": {
|
|
65
|
-
outline: "none"
|
|
66
|
-
},
|
|
67
|
-
"& *": {
|
|
68
|
-
fontFamily: 'Menlo, Monaco, "Courier New", monospace'
|
|
69
|
-
}
|
|
70
|
-
}),
|
|
71
|
-
EditorView.theme({
|
|
72
|
-
"&.cm-content": {
|
|
73
|
-
wordBreak: "break-all"
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
];
|
|
77
|
-
const CodeEditor = createRenderer(
|
|
78
|
-
[...preset, ...createStyleOptions()],
|
|
79
|
-
builtinExtensions
|
|
80
|
-
);
|
|
81
|
-
export {
|
|
82
|
-
CodeEditor
|
|
83
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { EditorProvider } from "@coze-editor/editor/react";
|
|
2
|
-
import { CodeEditor } from "./code-editor";
|
|
3
|
-
import { TextEditor } from "./text-editor";
|
|
4
|
-
import { BaseJsonEditor } from "./json-editor";
|
|
5
|
-
import { BaseRawTextEditor } from "./raw-text-editor";
|
|
6
|
-
export {
|
|
7
|
-
BaseJsonEditor,
|
|
8
|
-
BaseRawTextEditor,
|
|
9
|
-
CodeEditor,
|
|
10
|
-
EditorProvider,
|
|
11
|
-
TextEditor
|
|
12
|
-
};
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import { jsx } from "react/jsx-runtime";
|
|
22
|
-
import React, {
|
|
23
|
-
useCallback,
|
|
24
|
-
useEffect,
|
|
25
|
-
useRef,
|
|
26
|
-
useImperativeHandle
|
|
27
|
-
} from "react";
|
|
28
|
-
import { EditorProvider } from "@coze-editor/editor/react";
|
|
29
|
-
import {
|
|
30
|
-
transformerCreator
|
|
31
|
-
} from "@coze-editor/editor/preset-code";
|
|
32
|
-
import { json } from "@coze-editor/editor/language-json";
|
|
33
|
-
import { EditorView } from "@codemirror/view";
|
|
34
|
-
import { CodeEditor } from "./code-editor";
|
|
35
|
-
const extensions = [
|
|
36
|
-
EditorView.theme({
|
|
37
|
-
".cm-activeLineGutter": {
|
|
38
|
-
backgroundColor: "transparent !important"
|
|
39
|
-
},
|
|
40
|
-
".cm-activeLine": {
|
|
41
|
-
backgroundColor: "transparent !important"
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
];
|
|
45
|
-
function findAllMatches(inputString, regex) {
|
|
46
|
-
const globalRegex = new RegExp(
|
|
47
|
-
regex,
|
|
48
|
-
regex.flags.includes("g") ? regex.flags : `${regex.flags}g`
|
|
49
|
-
);
|
|
50
|
-
let match;
|
|
51
|
-
const matches = [];
|
|
52
|
-
while (true) {
|
|
53
|
-
match = globalRegex.exec(inputString);
|
|
54
|
-
if (!match) {
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
if (match.index === globalRegex.lastIndex) {
|
|
58
|
-
globalRegex.lastIndex++;
|
|
59
|
-
}
|
|
60
|
-
matches.push({
|
|
61
|
-
match: match[0],
|
|
62
|
-
range: [match.index, match.index + match[0].length]
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return matches;
|
|
66
|
-
}
|
|
67
|
-
const transformer = transformerCreator((text) => {
|
|
68
|
-
const originalSource = text.toString();
|
|
69
|
-
const matches = findAllMatches(originalSource, /\{\{([^\}]*)\}\}/g);
|
|
70
|
-
if (matches.length > 0) {
|
|
71
|
-
matches.forEach(({ range }) => {
|
|
72
|
-
text.replaceRange(range[0], range[1], "null");
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return text;
|
|
76
|
-
});
|
|
77
|
-
const BaseJsonEditor = React.forwardRef(
|
|
78
|
-
(props, ref) => {
|
|
79
|
-
const {
|
|
80
|
-
value,
|
|
81
|
-
onChange,
|
|
82
|
-
placeholder,
|
|
83
|
-
className,
|
|
84
|
-
isDarkTheme,
|
|
85
|
-
readonly,
|
|
86
|
-
minHeight = "100px",
|
|
87
|
-
maxHeight,
|
|
88
|
-
editerHeight,
|
|
89
|
-
padding,
|
|
90
|
-
borderRadius
|
|
91
|
-
} = props;
|
|
92
|
-
const apiRef = useRef(null);
|
|
93
|
-
const handleChange = useCallback(
|
|
94
|
-
(e) => {
|
|
95
|
-
if (typeof onChange === "function") {
|
|
96
|
-
onChange(e.value);
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
[onChange]
|
|
100
|
-
);
|
|
101
|
-
useEffect(() => {
|
|
102
|
-
var _a;
|
|
103
|
-
(_a = apiRef.current) == null ? void 0 : _a.updateASTDecorations();
|
|
104
|
-
}, [isDarkTheme]);
|
|
105
|
-
useEffect(() => {
|
|
106
|
-
const editor = apiRef.current;
|
|
107
|
-
if (!editor) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (typeof value === "string" && value !== editor.getValue()) {
|
|
111
|
-
editor.setValue(value);
|
|
112
|
-
}
|
|
113
|
-
}, [value]);
|
|
114
|
-
const formatJson = () => __async(void 0, null, function* () {
|
|
115
|
-
var _a;
|
|
116
|
-
const view = (_a = apiRef.current) == null ? void 0 : _a.$view;
|
|
117
|
-
if (!view) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
view.dispatch(
|
|
121
|
-
yield json.languageService.format(view.state, {
|
|
122
|
-
tabSize: 2
|
|
123
|
-
})
|
|
124
|
-
);
|
|
125
|
-
});
|
|
126
|
-
useImperativeHandle(ref, () => ({
|
|
127
|
-
formatJson
|
|
128
|
-
}));
|
|
129
|
-
return /* @__PURE__ */ jsx(EditorProvider, { children: /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx(
|
|
130
|
-
CodeEditor,
|
|
131
|
-
{
|
|
132
|
-
defaultValue: value != null ? value : "",
|
|
133
|
-
onChange: handleChange,
|
|
134
|
-
options: {
|
|
135
|
-
placeholder,
|
|
136
|
-
lineWrapping: true,
|
|
137
|
-
theme: isDarkTheme ? "coze-dark" : "coze-light",
|
|
138
|
-
languageId: "json",
|
|
139
|
-
editable: !readonly,
|
|
140
|
-
transformer,
|
|
141
|
-
minHeight,
|
|
142
|
-
maxHeight,
|
|
143
|
-
editerHeight,
|
|
144
|
-
borderRadius,
|
|
145
|
-
padding,
|
|
146
|
-
fontSize: 13,
|
|
147
|
-
lineHeight: 20
|
|
148
|
-
},
|
|
149
|
-
didMount: (api) => apiRef.current = api,
|
|
150
|
-
extensions
|
|
151
|
-
}
|
|
152
|
-
) }) });
|
|
153
|
-
}
|
|
154
|
-
);
|
|
155
|
-
export {
|
|
156
|
-
BaseJsonEditor
|
|
157
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useCallback, useEffect, useRef } from "react";
|
|
3
|
-
import { EditorProvider } from "@coze-editor/editor/react";
|
|
4
|
-
import { TextEditor } from "./text-editor";
|
|
5
|
-
const BaseRawTextEditor = forwardRef(
|
|
6
|
-
(props, ref) => {
|
|
7
|
-
const { value, onChange, placeholder, className, minHeight, readonly } = props;
|
|
8
|
-
const apiRef = useRef(null);
|
|
9
|
-
const handleChange = useCallback(
|
|
10
|
-
(e) => {
|
|
11
|
-
if (typeof onChange === "function") {
|
|
12
|
-
onChange(e.value);
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
[onChange]
|
|
16
|
-
);
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
const editor = apiRef.current;
|
|
19
|
-
if (!editor) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (typeof value === "string" && value !== editor.getValue()) {
|
|
23
|
-
editor.setValue(value);
|
|
24
|
-
}
|
|
25
|
-
}, [value]);
|
|
26
|
-
return /* @__PURE__ */ jsx(EditorProvider, { children: /* @__PURE__ */ jsx("div", { ref, className, children: /* @__PURE__ */ jsx(
|
|
27
|
-
TextEditor,
|
|
28
|
-
{
|
|
29
|
-
defaultValue: value != null ? value : "",
|
|
30
|
-
onChange: handleChange,
|
|
31
|
-
options: {
|
|
32
|
-
placeholder,
|
|
33
|
-
lineWrapping: true,
|
|
34
|
-
minHeight,
|
|
35
|
-
fontSize: 13,
|
|
36
|
-
editable: !readonly,
|
|
37
|
-
lineHeight: 20
|
|
38
|
-
},
|
|
39
|
-
didMount: (api) => apiRef.current = api
|
|
40
|
-
}
|
|
41
|
-
) }) });
|
|
42
|
-
}
|
|
43
|
-
);
|
|
44
|
-
export {
|
|
45
|
-
BaseRawTextEditor
|
|
46
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { createRenderer, option } from "@coze-editor/editor/react";
|
|
2
|
-
import universal from "@coze-editor/editor/preset-universal";
|
|
3
|
-
import { mixLanguages } from "@coze-editor/editor";
|
|
4
|
-
import { keymap, EditorView } from "@codemirror/view";
|
|
5
|
-
import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
|
|
6
|
-
const RawEditorTheme = EditorView.theme({
|
|
7
|
-
"&.cm-editor": {
|
|
8
|
-
outline: "none"
|
|
9
|
-
},
|
|
10
|
-
"&.cm-content": {
|
|
11
|
-
wordBreak: "break-all"
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
const minHeightOption = (value) => EditorView.theme({
|
|
15
|
-
".cm-content, .cm-gutter, .cm-right-gutter": {
|
|
16
|
-
minHeight: typeof value === "number" ? `${value}px` : typeof value === "string" ? value : "unset"
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const lineHeightOption = (value) => EditorView.theme({
|
|
20
|
-
".cm-content, .cm-gutter, .cm-right-gutter": {
|
|
21
|
-
lineHeight: typeof value === "number" ? `${value}px` : typeof value === "string" ? value : "unset"
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
const extensions = [
|
|
25
|
-
mixLanguages({}),
|
|
26
|
-
RawEditorTheme,
|
|
27
|
-
// ...其他 extensions
|
|
28
|
-
history(),
|
|
29
|
-
keymap.of([...defaultKeymap, ...historyKeymap])
|
|
30
|
-
];
|
|
31
|
-
const TextEditor = createRenderer(
|
|
32
|
-
[
|
|
33
|
-
...universal,
|
|
34
|
-
option("minHeight", minHeightOption),
|
|
35
|
-
option("lineHeight", lineHeightOption)
|
|
36
|
-
],
|
|
37
|
-
extensions
|
|
38
|
-
);
|
|
39
|
-
export {
|
|
40
|
-
TextEditor
|
|
41
|
-
};
|