@agent-arts/editor 0.1.0 → 0.1.1
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/editor.js +233 -342
- package/dist/editor.umd.cjs +1 -5
- package/dist/index.d.ts +6 -179
- package/package.json +1 -1
package/dist/editor.js
CHANGED
|
@@ -1,95 +1,95 @@
|
|
|
1
1
|
var I = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { StateEffect as k,
|
|
5
|
-
import { EditorView as
|
|
6
|
-
import { history as
|
|
7
|
-
const
|
|
8
|
-
class g extends
|
|
9
|
-
constructor(t,
|
|
10
|
-
super(), this.block = t, this.callbacks =
|
|
2
|
+
var L = (e, t, o) => t in e ? I(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
|
|
3
|
+
var u = (e, t, o) => L(e, typeof t != "symbol" ? t + "" : t, o);
|
|
4
|
+
import { StateEffect as k, StateField as x, Facet as y, EditorState as R } from "@codemirror/state";
|
|
5
|
+
import { EditorView as h, Decoration as a, WidgetType as T, ViewPlugin as _, keymap as W, drawSelection as N } from "@codemirror/view";
|
|
6
|
+
import { history as $, defaultKeymap as z, historyKeymap as O } from "@codemirror/commands";
|
|
7
|
+
const A = k.define(), D = k.define();
|
|
8
|
+
class g extends T {
|
|
9
|
+
constructor(t, o) {
|
|
10
|
+
super(), this.block = t, this.callbacks = o;
|
|
11
11
|
}
|
|
12
12
|
toDOM(t) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
return document.body.removeChild(
|
|
13
|
+
const o = document.createElement("span");
|
|
14
|
+
o.className = "cm-inline-block", o.setAttribute("data-block-id", this.block.id);
|
|
15
|
+
const n = document.createElement("input");
|
|
16
|
+
n.type = "text", n.className = "block-input", n.value = this.block.presetText || "", n.placeholder = this.block.placeholder || "请输入...";
|
|
17
|
+
const c = (s) => {
|
|
18
|
+
const i = document.createElement("span");
|
|
19
|
+
i.style.visibility = "hidden", i.style.position = "absolute", i.style.whiteSpace = "pre", i.style.font = "inherit", i.textContent = s || n.placeholder, document.body.appendChild(i);
|
|
20
|
+
const l = i.offsetWidth;
|
|
21
|
+
return document.body.removeChild(i), l + 10;
|
|
22
22
|
};
|
|
23
|
-
return
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
const s =
|
|
23
|
+
return n.style.width = `${c(n.value)}px`, n.oninput = (s) => {
|
|
24
|
+
const i = s.target.value;
|
|
25
|
+
n.style.width = `${c(i)}px`, this.callbacks.updateBlockText(this.block.id, i);
|
|
26
|
+
}, n.onfocus = () => {
|
|
27
|
+
const s = o.getBoundingClientRect();
|
|
28
28
|
this.callbacks.openPopup(this.block.id, s);
|
|
29
|
-
},
|
|
29
|
+
}, n.onmousedown = (s) => {
|
|
30
30
|
s.stopPropagation();
|
|
31
|
-
},
|
|
31
|
+
}, n.onclick = (s) => {
|
|
32
32
|
s.stopPropagation();
|
|
33
|
-
const
|
|
34
|
-
this.callbacks.openPopup(this.block.id,
|
|
35
|
-
},
|
|
36
|
-
if (s.key === "Backspace" &&
|
|
33
|
+
const i = o.getBoundingClientRect();
|
|
34
|
+
this.callbacks.openPopup(this.block.id, i);
|
|
35
|
+
}, n.onkeydown = (s) => {
|
|
36
|
+
if (s.key === "Backspace" && n.value === "") {
|
|
37
37
|
s.preventDefault();
|
|
38
|
-
const
|
|
38
|
+
const i = t.posAtDOM(o);
|
|
39
39
|
this.callbacks.deleteBlock(this.block.id), t.dispatch({
|
|
40
|
-
changes: { from:
|
|
41
|
-
selection: { anchor:
|
|
40
|
+
changes: { from: i, to: i + 1 },
|
|
41
|
+
selection: { anchor: i }
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
},
|
|
44
|
+
}, o.appendChild(n), o;
|
|
45
45
|
}
|
|
46
46
|
ignoreEvent() {
|
|
47
47
|
return !0;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
const w =
|
|
51
|
-
combine: (
|
|
52
|
-
}),
|
|
53
|
-
combine: (
|
|
54
|
-
}), v =
|
|
55
|
-
create(
|
|
56
|
-
const t =
|
|
57
|
-
if (!
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
return
|
|
50
|
+
const w = y.define({
|
|
51
|
+
combine: (e) => e[0]
|
|
52
|
+
}), S = y.define({
|
|
53
|
+
combine: (e) => e.length ? e[0] : []
|
|
54
|
+
}), v = x.define({
|
|
55
|
+
create(e) {
|
|
56
|
+
const t = e.facet(w), o = e.facet(S);
|
|
57
|
+
if (!o || o.length === 0) return a.none;
|
|
58
|
+
const n = o.slice().sort((c, s) => c.pos - s.pos).map(({ pos: c, len: s, block: i }) => {
|
|
59
|
+
const l = new g(i, t);
|
|
60
|
+
return a.replace({ widget: l }).range(c, c + (s || 1));
|
|
61
61
|
});
|
|
62
|
-
return
|
|
62
|
+
return a.set(n, !0);
|
|
63
63
|
},
|
|
64
|
-
update(
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
for (const
|
|
68
|
-
if (
|
|
69
|
-
const
|
|
70
|
-
widget: new g(
|
|
71
|
-
}).range(
|
|
72
|
-
|
|
73
|
-
} else if (
|
|
74
|
-
const
|
|
64
|
+
update(e, t) {
|
|
65
|
+
const o = t.state.facet(w);
|
|
66
|
+
e = e.map(t.changes);
|
|
67
|
+
for (const n of t.effects)
|
|
68
|
+
if (n.is(A)) {
|
|
69
|
+
const c = t.state.selection.main.head - 1, s = a.replace({
|
|
70
|
+
widget: new g(n.value, o)
|
|
71
|
+
}).range(c, c + 1);
|
|
72
|
+
e = e.update({ add: [s] });
|
|
73
|
+
} else if (n.is(D)) {
|
|
74
|
+
const c = n.value;
|
|
75
75
|
let s = null;
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
}), s !== null && (
|
|
80
|
-
filter: (
|
|
81
|
-
const
|
|
82
|
-
return !(
|
|
76
|
+
e.between(0, t.state.doc.length, (i, l, r) => {
|
|
77
|
+
const d = r.spec.widget;
|
|
78
|
+
d instanceof g && d.block.id === c.id && (s = i);
|
|
79
|
+
}), s !== null && (e = e.update({
|
|
80
|
+
filter: (i, l, r) => {
|
|
81
|
+
const d = r.spec.widget;
|
|
82
|
+
return !(d instanceof g && d.block.id === c.id);
|
|
83
83
|
},
|
|
84
|
-
add: [
|
|
85
|
-
widget: new g(
|
|
84
|
+
add: [a.replace({
|
|
85
|
+
widget: new g(c, o)
|
|
86
86
|
}).range(s, s + 1)]
|
|
87
87
|
}));
|
|
88
88
|
}
|
|
89
|
-
return
|
|
89
|
+
return e;
|
|
90
90
|
},
|
|
91
|
-
provide: (
|
|
92
|
-
}),
|
|
91
|
+
provide: (e) => h.decorations.from(e)
|
|
92
|
+
}), j = h.theme({
|
|
93
93
|
".cm-inline-block": {
|
|
94
94
|
display: "inline-block",
|
|
95
95
|
backgroundColor: "#f3f0ff",
|
|
@@ -123,100 +123,37 @@ const w = x.define({
|
|
|
123
123
|
opacity: 0.7
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
|
-
function
|
|
126
|
+
function V(e) {
|
|
127
127
|
return [
|
|
128
|
-
w.of(
|
|
129
|
-
|
|
128
|
+
w.of(e.callbacks),
|
|
129
|
+
S.of(e.initialBlocks || []),
|
|
130
130
|
v,
|
|
131
|
-
|
|
131
|
+
j
|
|
132
132
|
];
|
|
133
133
|
}
|
|
134
|
-
function
|
|
135
|
-
const t = [],
|
|
136
|
-
return
|
|
137
|
-
const
|
|
138
|
-
|
|
134
|
+
function q(e) {
|
|
135
|
+
const t = [], o = e.state.field(v, !1);
|
|
136
|
+
return o && o.between(0, e.state.doc.length, (n, c, s) => {
|
|
137
|
+
const i = s.spec.widget;
|
|
138
|
+
i instanceof g && t.push({ pos: n, len: c - n, block: i.block });
|
|
139
139
|
}), t;
|
|
140
140
|
}
|
|
141
|
-
|
|
142
|
-
constructor(t) {
|
|
143
|
-
r(this, "editingBlock", { id: "", placeholder: "", presetText: "" });
|
|
144
|
-
this.callbacks = t;
|
|
145
|
-
}
|
|
146
|
-
show(t, e, i) {
|
|
147
|
-
this.editingBlock = { ...t };
|
|
148
|
-
const l = {
|
|
149
|
-
top: `${e.bottom - i.top + 10}px`,
|
|
150
|
-
left: `${e.left - i.left}px`
|
|
151
|
-
};
|
|
152
|
-
this.callbacks.onShow(this.editingBlock, l);
|
|
153
|
-
}
|
|
154
|
-
hide() {
|
|
155
|
-
this.callbacks.onHide();
|
|
156
|
-
}
|
|
157
|
-
updateEditingBlock(t) {
|
|
158
|
-
this.editingBlock = { ...this.editingBlock, ...t };
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
class at {
|
|
162
|
-
constructor(t) {
|
|
163
|
-
r(this, "isGenerating", !1);
|
|
164
|
-
r(this, "aiStreamTimer", null);
|
|
165
|
-
r(this, "currentResponse", "");
|
|
166
|
-
this.callbacks = t;
|
|
167
|
-
}
|
|
168
|
-
show(t, e, i) {
|
|
169
|
-
const l = {
|
|
170
|
-
top: `${e.bottom - i.top + 10}px`,
|
|
171
|
-
left: `${e.left - i.left}px`
|
|
172
|
-
};
|
|
173
|
-
this.callbacks.onShow(t, l);
|
|
174
|
-
}
|
|
175
|
-
hide() {
|
|
176
|
-
this.stopResponse(), this.callbacks.onHide();
|
|
177
|
-
}
|
|
178
|
-
sendQuestion(t) {
|
|
179
|
-
if (!t || this.isGenerating) return;
|
|
180
|
-
this.isGenerating = !0, this.callbacks.onLoading(!0), this.currentResponse = "", this.callbacks.onStream("");
|
|
181
|
-
const e = `你是一个资深旅游向导,积累了丰富的在地经验,擅长结合用户需求定制专属旅行方案,曾帮助1000+人解决旅行难题,被旅行者亲切称为"旅行百事通"。
|
|
182
|
-
|
|
183
|
-
## 核心性格与风格
|
|
184
|
-
- **性格特点**:热情开朗、专业耐心,擅长用轻松幽默的方式化解旅行焦虑(如:"别慌!机票改签我有3个小窍门,保准帮你搞定~"),遇到用户疑问会像朋友般细致拆解细节(如:"你担心的高原反应,我去年在西藏徒步时总结过4个缓解方法...")。
|
|
185
|
-
- **语言风格**:口语化且富有感染力,常用"宝藏地""小众玩法"等旅行圈`;
|
|
186
|
-
let i = 0;
|
|
187
|
-
this.aiStreamTimer = setInterval(() => {
|
|
188
|
-
this.callbacks.onLoading(!1), i < e.length ? (this.currentResponse += e[i], this.callbacks.onStream(this.currentResponse), i++) : this.finishGeneration();
|
|
189
|
-
}, 30);
|
|
190
|
-
}
|
|
191
|
-
stopResponse() {
|
|
192
|
-
this.aiStreamTimer && (clearInterval(this.aiStreamTimer), this.aiStreamTimer = null), this.isGenerating = !1, this.callbacks.onLoading(!1), this.callbacks.onStop();
|
|
193
|
-
}
|
|
194
|
-
finishGeneration() {
|
|
195
|
-
this.aiStreamTimer && (clearInterval(this.aiStreamTimer), this.aiStreamTimer = null), this.isGenerating = !1, this.callbacks.onLoading(!1), this.callbacks.onComplete();
|
|
196
|
-
}
|
|
197
|
-
getIsGenerating() {
|
|
198
|
-
return this.isGenerating;
|
|
199
|
-
}
|
|
200
|
-
destroy() {
|
|
201
|
-
this.stopResponse();
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
function V(o) {
|
|
141
|
+
function H(e) {
|
|
205
142
|
return [
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
143
|
+
K(e.onTriggerAIDialog),
|
|
144
|
+
G(e.onTriggerAIDialog),
|
|
145
|
+
U
|
|
209
146
|
];
|
|
210
147
|
}
|
|
211
|
-
function
|
|
212
|
-
return
|
|
213
|
-
t.docChanged && t.changes.iterChanges((
|
|
214
|
-
if (
|
|
215
|
-
|
|
148
|
+
function K(e) {
|
|
149
|
+
return h.updateListener.of((t) => {
|
|
150
|
+
t.docChanged && t.changes.iterChanges((o, n, c, s, i) => {
|
|
151
|
+
if (i.length !== 1) return;
|
|
152
|
+
i.sliceString(0) === "/" && e(o);
|
|
216
153
|
});
|
|
217
154
|
});
|
|
218
155
|
}
|
|
219
|
-
const
|
|
156
|
+
const U = h.theme({
|
|
220
157
|
".cm-ai-selection-trigger": {
|
|
221
158
|
position: "absolute",
|
|
222
159
|
zIndex: "10",
|
|
@@ -246,22 +183,22 @@ const K = u.theme({
|
|
|
246
183
|
borderRadius: "8px"
|
|
247
184
|
}
|
|
248
185
|
});
|
|
249
|
-
function
|
|
250
|
-
return
|
|
186
|
+
function G(e) {
|
|
187
|
+
return _.fromClass(class {
|
|
251
188
|
constructor(t) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
189
|
+
u(this, "dom");
|
|
190
|
+
u(this, "button");
|
|
191
|
+
u(this, "lastFrom", -1);
|
|
192
|
+
u(this, "lastTo", -1);
|
|
193
|
+
u(this, "measureScheduled", !1);
|
|
257
194
|
this.view = t, this.dom = document.createElement("div"), this.dom.className = "cm-ai-selection-trigger", this.button = document.createElement("button"), this.button.type = "button";
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}), this.button.addEventListener("click", (
|
|
262
|
-
|
|
263
|
-
const { from:
|
|
264
|
-
s || (
|
|
195
|
+
const o = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
196
|
+
o.setAttribute("width", "16"), o.setAttribute("height", "16"), o.setAttribute("viewBox", "0 0 24 24"), o.setAttribute("fill", "none"), o.setAttribute("stroke", "#111827"), o.setAttribute("stroke-width", "2"), o.setAttribute("stroke-linecap", "round"), o.setAttribute("stroke-linejoin", "round"), o.innerHTML = '<path d="M5 12l1.5.5L7 14l.5-1.5L9 12l-1.5-.5L7 10l-.5 1.5L5 12z"/><path d="M12 4l2 6 6 2-6 2-2 6-2-6-6-2 6-2 2-6z"/>', this.button.appendChild(o), this.dom.appendChild(this.button), this.view.dom.appendChild(this.dom), this.dom.addEventListener("mousedown", (n) => {
|
|
197
|
+
n.preventDefault(), n.stopPropagation();
|
|
198
|
+
}), this.button.addEventListener("click", (n) => {
|
|
199
|
+
n.preventDefault(), n.stopPropagation();
|
|
200
|
+
const { from: c, empty: s } = this.view.state.selection.main;
|
|
201
|
+
s || (e(c), this.hide());
|
|
265
202
|
}), this.scheduleMeasure(!0);
|
|
266
203
|
}
|
|
267
204
|
update(t) {
|
|
@@ -277,22 +214,22 @@ function U(o) {
|
|
|
277
214
|
this.dom.style.display = "flex";
|
|
278
215
|
}
|
|
279
216
|
scheduleMeasure(t) {
|
|
280
|
-
const { from:
|
|
281
|
-
if (
|
|
217
|
+
const { from: o, to: n, empty: c } = this.view.state.selection.main;
|
|
218
|
+
if (c || !this.view.hasFocus) {
|
|
282
219
|
this.hide();
|
|
283
220
|
return;
|
|
284
221
|
}
|
|
285
|
-
!t &&
|
|
222
|
+
!t && o === this.lastFrom && n === this.lastTo && this.dom.style.display !== "none" || (this.lastFrom = o, this.lastTo = n, !this.measureScheduled && (this.measureScheduled = !0, this.view.requestMeasure({
|
|
286
223
|
read: (s) => {
|
|
287
|
-
const
|
|
288
|
-
if (!
|
|
289
|
-
const
|
|
290
|
-
return { coords:
|
|
224
|
+
const i = s.coordsAtPos(o);
|
|
225
|
+
if (!i) return null;
|
|
226
|
+
const l = s.dom.getBoundingClientRect();
|
|
227
|
+
return { coords: i, editorRect: l };
|
|
291
228
|
},
|
|
292
229
|
write: (s) => {
|
|
293
230
|
this.measureScheduled = !1;
|
|
294
|
-
const { empty:
|
|
295
|
-
if (
|
|
231
|
+
const { empty: i } = this.view.state.selection.main;
|
|
232
|
+
if (i || !this.view.hasFocus) {
|
|
296
233
|
this.hide();
|
|
297
234
|
return;
|
|
298
235
|
}
|
|
@@ -300,10 +237,10 @@ function U(o) {
|
|
|
300
237
|
this.hide();
|
|
301
238
|
return;
|
|
302
239
|
}
|
|
303
|
-
const { coords:
|
|
304
|
-
Math.max(
|
|
305
|
-
Math.max(p,
|
|
306
|
-
), f = Math.max(
|
|
240
|
+
const { coords: l, editorRect: r } = s, d = 32, m = 32, p = 6, b = Math.min(
|
|
241
|
+
Math.max(l.left - r.left, p),
|
|
242
|
+
Math.max(p, r.width - d - p)
|
|
243
|
+
), f = Math.max(l.top - r.top - m - 10, p);
|
|
307
244
|
this.dom.style.left = `${b}px`, this.dom.style.top = `${f}px`, this.show();
|
|
308
245
|
}
|
|
309
246
|
})));
|
|
@@ -311,138 +248,112 @@ function U(o) {
|
|
|
311
248
|
});
|
|
312
249
|
}
|
|
313
250
|
const M = k.define();
|
|
314
|
-
class B extends
|
|
251
|
+
class B extends T {
|
|
315
252
|
constructor(t) {
|
|
316
253
|
super(), this.block = t;
|
|
317
254
|
}
|
|
318
255
|
toDOM() {
|
|
319
256
|
const t = document.createElement("span");
|
|
320
257
|
t.className = `cm-plugin-block cm-plugin-block-${this.block.type}`, t.setAttribute("data-block-id", this.block.id);
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
const
|
|
324
|
-
return t.appendChild(
|
|
258
|
+
const o = document.createElement("i");
|
|
259
|
+
o.className = this.block.type === "plugin" ? "icon-plugin" : "icon-workflow", t.appendChild(o);
|
|
260
|
+
const n = document.createTextNode(this.block.name);
|
|
261
|
+
return t.appendChild(n), t;
|
|
325
262
|
}
|
|
326
263
|
ignoreEvent() {
|
|
327
264
|
return !0;
|
|
328
265
|
}
|
|
329
266
|
}
|
|
330
|
-
const
|
|
331
|
-
combine: (
|
|
332
|
-
}),
|
|
333
|
-
create(
|
|
334
|
-
const t =
|
|
335
|
-
if (!t || t.length === 0) return
|
|
336
|
-
const
|
|
337
|
-
return
|
|
267
|
+
const F = y.define({
|
|
268
|
+
combine: (e) => e.length ? e[0] : []
|
|
269
|
+
}), E = x.define({
|
|
270
|
+
create(e) {
|
|
271
|
+
const t = e.facet(F);
|
|
272
|
+
if (!t || t.length === 0) return a.none;
|
|
273
|
+
const o = t.slice().sort((n, c) => n.pos - c.pos).map(({ pos: n, len: c, block: s }) => a.replace({ widget: new B(s) }).range(n, n + (c || 1)));
|
|
274
|
+
return a.set(o, !0);
|
|
338
275
|
},
|
|
339
|
-
update(
|
|
340
|
-
|
|
341
|
-
for (const
|
|
342
|
-
if (
|
|
343
|
-
const { pos:
|
|
344
|
-
widget: new B(
|
|
276
|
+
update(e, t) {
|
|
277
|
+
e = e.map(t.changes);
|
|
278
|
+
for (const o of t.effects)
|
|
279
|
+
if (o.is(M)) {
|
|
280
|
+
const { pos: n, block: c } = o.value, s = t.changes.mapPos(n), i = a.replace({
|
|
281
|
+
widget: new B(c)
|
|
345
282
|
}).range(s, s + 1);
|
|
346
|
-
|
|
283
|
+
e = e.update({ add: [i] });
|
|
347
284
|
}
|
|
348
|
-
return
|
|
285
|
+
return e;
|
|
349
286
|
},
|
|
350
|
-
provide: (
|
|
287
|
+
provide: (e) => h.decorations.from(e)
|
|
351
288
|
});
|
|
352
|
-
function
|
|
289
|
+
function J(e) {
|
|
353
290
|
return [
|
|
354
|
-
|
|
355
|
-
|
|
291
|
+
F.of(e.initialBlocks || []),
|
|
292
|
+
E
|
|
356
293
|
];
|
|
357
294
|
}
|
|
358
|
-
function
|
|
295
|
+
function Q(e) {
|
|
359
296
|
return [
|
|
360
|
-
|
|
361
|
-
t.docChanged && t.changes.iterChanges((
|
|
362
|
-
if (
|
|
363
|
-
|
|
297
|
+
h.updateListener.of((t) => {
|
|
298
|
+
t.docChanged && t.changes.iterChanges((o, n, c, s, i) => {
|
|
299
|
+
if (i.length !== 1) return;
|
|
300
|
+
i.sliceString(0) === "{" && e.onTriggerPluginPopup(o);
|
|
364
301
|
});
|
|
365
302
|
})
|
|
366
303
|
];
|
|
367
304
|
}
|
|
368
|
-
function X(
|
|
369
|
-
const t = [],
|
|
370
|
-
return
|
|
371
|
-
const
|
|
372
|
-
|
|
305
|
+
function X(e) {
|
|
306
|
+
const t = [], o = e.state.field(E, !1);
|
|
307
|
+
return o && o.between(0, e.state.doc.length, (n, c, s) => {
|
|
308
|
+
const i = s.spec.widget;
|
|
309
|
+
i instanceof B && t.push({ pos: n, len: c - n, block: i.block });
|
|
373
310
|
}), t;
|
|
374
311
|
}
|
|
375
|
-
function Y(
|
|
376
|
-
const t = [],
|
|
377
|
-
let
|
|
378
|
-
for (; (
|
|
312
|
+
function Y(e) {
|
|
313
|
+
const t = [], o = /\{\{(.+?)\}\}/g;
|
|
314
|
+
let n;
|
|
315
|
+
for (; (n = o.exec(e)) !== null; )
|
|
379
316
|
t.push({
|
|
380
|
-
pos:
|
|
381
|
-
len:
|
|
317
|
+
pos: n.index,
|
|
318
|
+
len: n[0].length,
|
|
382
319
|
block: {
|
|
383
|
-
id: `var-${
|
|
384
|
-
name:
|
|
320
|
+
id: `var-${n[1]}-${n.index}`,
|
|
321
|
+
name: n[1],
|
|
385
322
|
type: "plugin"
|
|
386
323
|
}
|
|
387
324
|
});
|
|
388
325
|
return t;
|
|
389
326
|
}
|
|
390
|
-
class
|
|
391
|
-
constructor(t) {
|
|
392
|
-
r(this, "plugins", [
|
|
393
|
-
{ id: "plugin-1", name: "LinkReaderPlugin", type: "plugin" }
|
|
394
|
-
]);
|
|
395
|
-
r(this, "workflows", [
|
|
396
|
-
{ id: "workflow-1", name: "condition_1_872", type: "workflow" }
|
|
397
|
-
]);
|
|
398
|
-
r(this, "triggerPos", 0);
|
|
399
|
-
this.callbacks = t;
|
|
400
|
-
}
|
|
401
|
-
show(t, e, i) {
|
|
402
|
-
this.triggerPos = t;
|
|
403
|
-
const l = {
|
|
404
|
-
top: `${e.bottom - i.top + 10}px`,
|
|
405
|
-
left: `${e.left - i.left}px`
|
|
406
|
-
};
|
|
407
|
-
this.callbacks.onShow(t, l);
|
|
408
|
-
}
|
|
409
|
-
hide() {
|
|
410
|
-
this.callbacks.onHide();
|
|
411
|
-
}
|
|
412
|
-
getTriggerPos() {
|
|
413
|
-
return this.triggerPos;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
class ht {
|
|
327
|
+
class rt {
|
|
417
328
|
constructor(t) {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
329
|
+
u(this, "view");
|
|
330
|
+
u(this, "allBlocks", /* @__PURE__ */ new Map());
|
|
331
|
+
u(this, "options");
|
|
421
332
|
this.options = t;
|
|
422
|
-
const
|
|
333
|
+
const o = Y(t.initialDoc), n = [
|
|
423
334
|
...t.initialBlocks || [],
|
|
424
|
-
...
|
|
335
|
+
...o
|
|
425
336
|
];
|
|
426
|
-
t.initialBlocks && t.initialBlocks.forEach((
|
|
427
|
-
"type" in
|
|
337
|
+
t.initialBlocks && t.initialBlocks.forEach((i) => {
|
|
338
|
+
"type" in i.block || this.allBlocks.set(i.block.id, i.block);
|
|
428
339
|
});
|
|
429
|
-
const
|
|
430
|
-
updateBlockText: (
|
|
431
|
-
const
|
|
432
|
-
|
|
340
|
+
const c = {
|
|
341
|
+
updateBlockText: (i, l) => {
|
|
342
|
+
const r = this.allBlocks.get(i);
|
|
343
|
+
r && (r.presetText = l, this.allBlocks.set(i, r), this.options.onBlockUpdated && this.options.onBlockUpdated(i, l));
|
|
433
344
|
},
|
|
434
|
-
openPopup: (
|
|
435
|
-
this.options.onOpenPopup(
|
|
345
|
+
openPopup: (i, l) => {
|
|
346
|
+
this.options.onOpenPopup(i, l);
|
|
436
347
|
},
|
|
437
|
-
deleteBlock: (
|
|
438
|
-
this.allBlocks.delete(
|
|
348
|
+
deleteBlock: (i) => {
|
|
349
|
+
this.allBlocks.delete(i), this.options.onBlockDeleted && this.options.onBlockDeleted(i);
|
|
439
350
|
}
|
|
440
|
-
}, s = ot(t.initialDoc,
|
|
441
|
-
this.view = new
|
|
351
|
+
}, s = ot(t.initialDoc, c, n);
|
|
352
|
+
this.view = new h({
|
|
442
353
|
state: s.update({
|
|
443
354
|
effects: k.appendConfig.of([
|
|
444
|
-
...
|
|
445
|
-
...
|
|
355
|
+
...Q({ onTriggerPluginPopup: (i) => this.options.onTriggerPluginPopup(i) }),
|
|
356
|
+
...H({ onTriggerAIDialog: (i) => this.options.onTriggerAIDialog(i) })
|
|
446
357
|
])
|
|
447
358
|
}).state,
|
|
448
359
|
parent: t.parent
|
|
@@ -455,23 +366,23 @@ class ht {
|
|
|
455
366
|
presetText: ""
|
|
456
367
|
};
|
|
457
368
|
this.allBlocks.set(t.id, t);
|
|
458
|
-
const { from:
|
|
369
|
+
const { from: o, to: n } = this.view.state.selection.main;
|
|
459
370
|
return this.view.dispatch({
|
|
460
|
-
changes: { from:
|
|
461
|
-
effects:
|
|
462
|
-
selection: { anchor:
|
|
371
|
+
changes: { from: o, to: n, insert: " " },
|
|
372
|
+
effects: A.of(t),
|
|
373
|
+
selection: { anchor: o + 1 }
|
|
463
374
|
}), this.view.focus(), t;
|
|
464
375
|
}
|
|
465
|
-
addPluginBlock(t,
|
|
376
|
+
addPluginBlock(t, o) {
|
|
466
377
|
return this.view.dispatch({
|
|
467
378
|
changes: { from: t, to: t + 1, insert: " " },
|
|
468
|
-
effects: M.of({ pos: t, block:
|
|
379
|
+
effects: M.of({ pos: t, block: o }),
|
|
469
380
|
selection: { anchor: t + 1 }
|
|
470
|
-
}), this.view.focus(),
|
|
381
|
+
}), this.view.focus(), o;
|
|
471
382
|
}
|
|
472
383
|
syncBlock(t) {
|
|
473
384
|
this.allBlocks.set(t.id, { ...t }), this.view.dispatch({
|
|
474
|
-
effects:
|
|
385
|
+
effects: D.of(t)
|
|
475
386
|
});
|
|
476
387
|
}
|
|
477
388
|
getBlock(t) {
|
|
@@ -481,109 +392,89 @@ class ht {
|
|
|
481
392
|
return this.view.coordsAtPos(t);
|
|
482
393
|
}
|
|
483
394
|
getData() {
|
|
484
|
-
return
|
|
395
|
+
return nt(this.view);
|
|
485
396
|
}
|
|
486
397
|
destroy() {
|
|
487
398
|
this.view.destroy();
|
|
488
399
|
}
|
|
489
400
|
}
|
|
490
|
-
const Z = (
|
|
491
|
-
const { from:
|
|
492
|
-
if (!
|
|
493
|
-
const
|
|
494
|
-
if (
|
|
495
|
-
let s = null,
|
|
496
|
-
const
|
|
497
|
-
|
|
401
|
+
const Z = (e, t) => {
|
|
402
|
+
const { from: o, empty: n } = e.state.selection.main;
|
|
403
|
+
if (!n) return !1;
|
|
404
|
+
const c = o;
|
|
405
|
+
if (c === 0) return !1;
|
|
406
|
+
let s = null, i = null, l = 1;
|
|
407
|
+
const r = (d) => {
|
|
408
|
+
d && d.between(c - 1, c, (m, p, b) => {
|
|
498
409
|
const f = b.spec.widget;
|
|
499
|
-
if (f && f.block && f.block.id && m <
|
|
500
|
-
return s = f.block.id,
|
|
410
|
+
if (f && f.block && f.block.id && m < c && p >= c)
|
|
411
|
+
return s = f.block.id, i = m, l = p - m, !1;
|
|
501
412
|
});
|
|
502
413
|
};
|
|
503
|
-
return
|
|
504
|
-
changes: { from:
|
|
505
|
-
selection: { anchor:
|
|
414
|
+
return r(e.state.field(v, !1)), s || r(e.state.field(E, !1)), s && i !== null ? (t.deleteBlock(s), e.dispatch({
|
|
415
|
+
changes: { from: i, to: i + l },
|
|
416
|
+
selection: { anchor: i }
|
|
506
417
|
}), !0) : !1;
|
|
507
|
-
}, tt =
|
|
418
|
+
}, tt = h.theme({
|
|
508
419
|
"&": { height: "100%", outline: "none", position: "relative" },
|
|
509
420
|
".cm-content": { padding: "20px", fontSize: "16px" },
|
|
510
421
|
".cm-line": { padding: "4px 0" },
|
|
511
422
|
".cm-header-1": { fontSize: "1.5em", color: "#008c99", fontWeight: "bold" },
|
|
512
423
|
".cm-bold": { fontWeight: "bold" }
|
|
513
|
-
}),
|
|
514
|
-
function P(
|
|
424
|
+
}), C = a.mark({ class: "cm-bold" });
|
|
425
|
+
function P(e) {
|
|
515
426
|
const t = [];
|
|
516
|
-
for (let
|
|
517
|
-
const
|
|
518
|
-
/^#+\s+/.test(
|
|
427
|
+
for (let o = 1; o <= e.lines; o++) {
|
|
428
|
+
const n = e.line(o), c = n.text;
|
|
429
|
+
/^#+\s+/.test(c) && t.push(C.range(n.from, n.to));
|
|
519
430
|
const s = /\*\*(.*?)\*\*/g;
|
|
520
|
-
let
|
|
521
|
-
for (; (
|
|
522
|
-
t.push(
|
|
431
|
+
let i;
|
|
432
|
+
for (; (i = s.exec(c)) !== null; )
|
|
433
|
+
t.push(C.range(n.from + i.index, n.from + i.index + i[0].length));
|
|
523
434
|
}
|
|
524
|
-
return
|
|
435
|
+
return a.set(t.sort((o, n) => o.from - n.from), !0);
|
|
525
436
|
}
|
|
526
|
-
const et =
|
|
527
|
-
create(
|
|
528
|
-
return P(
|
|
437
|
+
const et = x.define({
|
|
438
|
+
create(e) {
|
|
439
|
+
return P(e.doc);
|
|
529
440
|
},
|
|
530
|
-
update(
|
|
531
|
-
return t.docChanged ? P(t.state.doc) :
|
|
441
|
+
update(e, t) {
|
|
442
|
+
return t.docChanged ? P(t.state.doc) : e.map(t.changes);
|
|
532
443
|
},
|
|
533
|
-
provide: (
|
|
444
|
+
provide: (e) => h.decorations.from(e)
|
|
534
445
|
});
|
|
535
|
-
function ot(
|
|
536
|
-
const
|
|
537
|
-
|
|
538
|
-
|
|
446
|
+
function ot(e, t, o = []) {
|
|
447
|
+
const n = o.filter((l) => !("type" in l.block && "name" in l.block)), c = o.filter((l) => "type" in l.block && "name" in l.block), s = [
|
|
448
|
+
$(),
|
|
449
|
+
W.of([
|
|
539
450
|
{
|
|
540
451
|
key: "Backspace",
|
|
541
|
-
run: (
|
|
452
|
+
run: (l) => Z(l, t)
|
|
542
453
|
},
|
|
543
|
-
...
|
|
544
|
-
...
|
|
454
|
+
...z,
|
|
455
|
+
...O
|
|
545
456
|
]),
|
|
546
|
-
|
|
547
|
-
...
|
|
548
|
-
...
|
|
457
|
+
N(),
|
|
458
|
+
...V({ callbacks: t, initialBlocks: n }),
|
|
459
|
+
...J({ initialBlocks: c }),
|
|
549
460
|
et,
|
|
550
461
|
tt
|
|
551
462
|
];
|
|
552
463
|
return R.create({
|
|
553
|
-
doc:
|
|
464
|
+
doc: e,
|
|
554
465
|
extensions: s
|
|
555
466
|
});
|
|
556
467
|
}
|
|
557
|
-
function
|
|
558
|
-
var
|
|
559
|
-
const t =
|
|
468
|
+
function nt(e) {
|
|
469
|
+
var c;
|
|
470
|
+
const t = e.state.doc.toString(), o = q(e), n = X(e);
|
|
560
471
|
return {
|
|
561
472
|
content: t,
|
|
562
|
-
editorBlocks:
|
|
563
|
-
pluginBlocks:
|
|
564
|
-
html: ((
|
|
473
|
+
editorBlocks: o,
|
|
474
|
+
pluginBlocks: n,
|
|
475
|
+
html: ((c = e.dom.querySelector(".cm-content")) == null ? void 0 : c.innerHTML) || ""
|
|
565
476
|
};
|
|
566
477
|
}
|
|
567
478
|
export {
|
|
568
|
-
|
|
569
|
-
ht as CustomEditor,
|
|
570
|
-
rt as EditBlockPlugin,
|
|
571
|
-
dt as LibraryBlockPlugin,
|
|
572
|
-
C as addBlockEffect,
|
|
573
|
-
M as addPluginBlockEffect,
|
|
574
|
-
V as aiDialogExtensions,
|
|
575
|
-
ot as createEditorState,
|
|
576
|
-
O as editBlockExtensions,
|
|
577
|
-
v as editBlockField,
|
|
578
|
-
H as editBlockTheme,
|
|
579
|
-
tt as editorTheme,
|
|
580
|
-
j as getEditorBlocks,
|
|
581
|
-
it as getEditorData,
|
|
582
|
-
X as getPluginBlocks,
|
|
583
|
-
et as markdownStyleField,
|
|
584
|
-
Y as parseTemplateVariables,
|
|
585
|
-
Q as pluginBlockExtensions,
|
|
586
|
-
S as pluginBlockField,
|
|
587
|
-
J as pluginPopupTriggerExtensions,
|
|
588
|
-
A as updateBlockEffect
|
|
479
|
+
rt as CustomEditor
|
|
589
480
|
};
|
package/dist/editor.umd.cjs
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
(function(c,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/commands")):typeof define=="function"&&define.amd?define(["exports","@codemirror/state","@codemirror/view","@codemirror/commands"],d):(c=typeof globalThis<"u"?globalThis:c||self,d(c.AgentArtsEditor={},c.CMState,c.CMView,c.CMCommands))})(this,function(c,d,r,w){"use strict";var X=Object.defineProperty;var Y=(c,d,r)=>d in c?X(c,d,{enumerable:!0,configurable:!0,writable:!0,value:r}):c[d]=r;var h=(c,d,r)=>Y(c,typeof d!="symbol"?d+"":d,r);const y=d.StateEffect.define(),E=d.StateEffect.define();class g extends r.WidgetType{constructor(e,i){super(),this.block=e,this.callbacks=i}toDOM(e){const i=document.createElement("span");i.className="cm-inline-block",i.setAttribute("data-block-id",this.block.id);const t=document.createElement("input");t.type="text",t.className="block-input",t.value=this.block.presetText||"",t.placeholder=this.block.placeholder||"请输入...";const l=s=>{const n=document.createElement("span");n.style.visibility="hidden",n.style.position="absolute",n.style.whiteSpace="pre",n.style.font="inherit",n.textContent=s||t.placeholder,document.body.appendChild(n);const a=n.offsetWidth;return document.body.removeChild(n),a+10};return t.style.width=`${l(t.value)}px`,t.oninput=s=>{const n=s.target.value;t.style.width=`${l(n)}px`,this.callbacks.updateBlockText(this.block.id,n)},t.onfocus=()=>{const s=i.getBoundingClientRect();this.callbacks.openPopup(this.block.id,s)},t.onmousedown=s=>{s.stopPropagation()},t.onclick=s=>{s.stopPropagation();const n=i.getBoundingClientRect();this.callbacks.openPopup(this.block.id,n)},t.onkeydown=s=>{if(s.key==="Backspace"&&t.value===""){s.preventDefault();const n=e.posAtDOM(i);this.callbacks.deleteBlock(this.block.id),e.dispatch({changes:{from:n,to:n+1},selection:{anchor:n}})}},i.appendChild(t),i}ignoreEvent(){return!0}}const x=d.Facet.define({combine:o=>o[0]}),D=d.Facet.define({combine:o=>o.length?o[0]:[]}),b=d.StateField.define({create(o){const e=o.facet(x),i=o.facet(D);if(!i||i.length===0)return r.Decoration.none;const t=i.slice().sort((l,s)=>l.pos-s.pos).map(({pos:l,len:s,block:n})=>{const a=new g(n,e);return r.Decoration.replace({widget:a}).range(l,l+(s||1))});return r.Decoration.set(t,!0)},update(o,e){const i=e.state.facet(x);o=o.map(e.changes);for(const t of e.effects)if(t.is(y)){const l=e.state.selection.main.head-1,s=r.Decoration.replace({widget:new g(t.value,i)}).range(l,l+1);o=o.update({add:[s]})}else if(t.is(E)){const l=t.value;let s=null;o.between(0,e.state.doc.length,(n,a,u)=>{const f=u.spec.widget;f instanceof g&&f.block.id===l.id&&(s=n)}),s!==null&&(o=o.update({filter:(n,a,u)=>{const f=u.spec.widget;return!(f instanceof g&&f.block.id===l.id)},add:[r.Decoration.replace({widget:new g(l,i)}).range(s,s+1)]}))}return o},provide:o=>r.EditorView.decorations.from(o)}),C=r.EditorView.theme({".cm-inline-block":{display:"inline-block",backgroundColor:"#f3f0ff",color:"#8066ff",padding:"0 8px",margin:"0 4px",borderRadius:"4px",cursor:"pointer",border:"1px solid transparent",transition:"all 0.2s",fontSize:"15px",verticalAlign:"middle"},".cm-inline-block:hover":{backgroundColor:"#e9e4ff",borderColor:"#8066ff"},".block-input":{background:"transparent",border:"none",outline:"none",color:"inherit",font:"inherit",padding:"4px 0",width:"auto",minWidth:"20px",textAlign:"center"},".block-input::placeholder":{color:"#b2a1ff",opacity:.7}});function A(o){return[x.of(o.callbacks),D.of(o.initialBlocks||[]),b,C]}function F(o){const e=[],i=o.state.field(b,!1);return i&&i.between(0,o.state.doc.length,(t,l,s)=>{const n=s.spec.widget;n instanceof g&&e.push({pos:t,len:l-t,block:n.block})}),e}class j{constructor(e){h(this,"editingBlock",{id:"",placeholder:"",presetText:""});this.callbacks=e}show(e,i,t){this.editingBlock={...e};const l={top:`${i.bottom-t.top+10}px`,left:`${i.left-t.left}px`};this.callbacks.onShow(this.editingBlock,l)}hide(){this.callbacks.onHide()}updateEditingBlock(e){this.editingBlock={...this.editingBlock,...e}}}class q{constructor(e){h(this,"isGenerating",!1);h(this,"aiStreamTimer",null);h(this,"currentResponse","");this.callbacks=e}show(e,i,t){const l={top:`${i.bottom-t.top+10}px`,left:`${i.left-t.left}px`};this.callbacks.onShow(e,l)}hide(){this.stopResponse(),this.callbacks.onHide()}sendQuestion(e){if(!e||this.isGenerating)return;this.isGenerating=!0,this.callbacks.onLoading(!0),this.currentResponse="",this.callbacks.onStream("");const i=`你是一个资深旅游向导,积累了丰富的在地经验,擅长结合用户需求定制专属旅行方案,曾帮助1000+人解决旅行难题,被旅行者亲切称为"旅行百事通"。
|
|
2
|
-
|
|
3
|
-
## 核心性格与风格
|
|
4
|
-
- **性格特点**:热情开朗、专业耐心,擅长用轻松幽默的方式化解旅行焦虑(如:"别慌!机票改签我有3个小窍门,保准帮你搞定~"),遇到用户疑问会像朋友般细致拆解细节(如:"你担心的高原反应,我去年在西藏徒步时总结过4个缓解方法...")。
|
|
5
|
-
- **语言风格**:口语化且富有感染力,常用"宝藏地""小众玩法"等旅行圈`;let t=0;this.aiStreamTimer=setInterval(()=>{this.callbacks.onLoading(!1),t<i.length?(this.currentResponse+=i[t],this.callbacks.onStream(this.currentResponse),t++):this.finishGeneration()},30)}stopResponse(){this.aiStreamTimer&&(clearInterval(this.aiStreamTimer),this.aiStreamTimer=null),this.isGenerating=!1,this.callbacks.onLoading(!1),this.callbacks.onStop()}finishGeneration(){this.aiStreamTimer&&(clearInterval(this.aiStreamTimer),this.aiStreamTimer=null),this.isGenerating=!1,this.callbacks.onLoading(!1),this.callbacks.onComplete()}getIsGenerating(){return this.isGenerating}destroy(){this.stopResponse()}}function M(o){return[H(o.onTriggerAIDialog),K(o.onTriggerAIDialog),O]}function H(o){return r.EditorView.updateListener.of(e=>{e.docChanged&&e.changes.iterChanges((i,t,l,s,n)=>{if(n.length!==1)return;n.sliceString(0)==="/"&&o(i)})})}const O=r.EditorView.theme({".cm-ai-selection-trigger":{position:"absolute",zIndex:"10",display:"none",width:"32px",height:"32px",alignItems:"center",justifyContent:"center",borderRadius:"8px",backgroundColor:"#fff",boxShadow:"0 6px 24px rgba(0, 0, 0, 0.12)",border:"1px solid rgba(0, 0, 0, 0.06)"},".cm-ai-selection-trigger button":{width:"100%",height:"100%",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0"},".cm-ai-selection-trigger button:hover":{backgroundColor:"#f3f4f6",borderRadius:"8px"}});function K(o){return r.ViewPlugin.fromClass(class{constructor(e){h(this,"dom");h(this,"button");h(this,"lastFrom",-1);h(this,"lastTo",-1);h(this,"measureScheduled",!1);this.view=e,this.dom=document.createElement("div"),this.dom.className="cm-ai-selection-trigger",this.button=document.createElement("button"),this.button.type="button";const i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("width","16"),i.setAttribute("height","16"),i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("fill","none"),i.setAttribute("stroke","#111827"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),i.innerHTML='<path d="M5 12l1.5.5L7 14l.5-1.5L9 12l-1.5-.5L7 10l-.5 1.5L5 12z"/><path d="M12 4l2 6 6 2-6 2-2 6-2-6-6-2 6-2 2-6z"/>',this.button.appendChild(i),this.dom.appendChild(this.button),this.view.dom.appendChild(this.dom),this.dom.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation()}),this.button.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const{from:l,empty:s}=this.view.state.selection.main;s||(o(l),this.hide())}),this.scheduleMeasure(!0)}update(e){(e.selectionSet||e.viewportChanged||e.focusChanged||e.docChanged)&&this.scheduleMeasure(!1)}destroy(){this.dom.remove()}hide(){this.dom.style.display="none"}show(){this.dom.style.display="flex"}scheduleMeasure(e){const{from:i,to:t,empty:l}=this.view.state.selection.main;if(l||!this.view.hasFocus){this.hide();return}!e&&i===this.lastFrom&&t===this.lastTo&&this.dom.style.display!=="none"||(this.lastFrom=i,this.lastTo=t,!this.measureScheduled&&(this.measureScheduled=!0,this.view.requestMeasure({read:s=>{const n=s.coordsAtPos(i);if(!n)return null;const a=s.dom.getBoundingClientRect();return{coords:n,editorRect:a}},write:s=>{this.measureScheduled=!1;const{empty:n}=this.view.state.selection.main;if(n||!this.view.hasFocus){this.hide();return}if(!s){this.hide();return}const{coords:a,editorRect:u}=s,f=32,k=32,p=6,P=Math.min(Math.max(a.left-u.left,p),Math.max(p,u.width-f-p)),m=Math.max(a.top-u.top-k-10,p);this.dom.style.left=`${P}px`,this.dom.style.top=`${m}px`,this.show()}})))}})}const S=d.StateEffect.define();class T extends r.WidgetType{constructor(e){super(),this.block=e}toDOM(){const e=document.createElement("span");e.className=`cm-plugin-block cm-plugin-block-${this.block.type}`,e.setAttribute("data-block-id",this.block.id);const i=document.createElement("i");i.className=this.block.type==="plugin"?"icon-plugin":"icon-workflow",e.appendChild(i);const t=document.createTextNode(this.block.name);return e.appendChild(t),e}ignoreEvent(){return!0}}const v=d.Facet.define({combine:o=>o.length?o[0]:[]}),B=d.StateField.define({create(o){const e=o.facet(v);if(!e||e.length===0)return r.Decoration.none;const i=e.slice().sort((t,l)=>t.pos-l.pos).map(({pos:t,len:l,block:s})=>r.Decoration.replace({widget:new T(s)}).range(t,t+(l||1)));return r.Decoration.set(i,!0)},update(o,e){o=o.map(e.changes);for(const i of e.effects)if(i.is(S)){const{pos:t,block:l}=i.value,s=e.changes.mapPos(t),n=r.Decoration.replace({widget:new T(l)}).range(s,s+1);o=o.update({add:[n]})}return o},provide:o=>r.EditorView.decorations.from(o)});function L(o){return[v.of(o.initialBlocks||[]),B]}function I(o){return[r.EditorView.updateListener.of(e=>{e.docChanged&&e.changes.iterChanges((i,t,l,s,n)=>{if(n.length!==1)return;n.sliceString(0)==="{"&&o.onTriggerPluginPopup(i)})})]}function $(o){const e=[],i=o.state.field(B,!1);return i&&i.between(0,o.state.doc.length,(t,l,s)=>{const n=s.spec.widget;n instanceof T&&e.push({pos:t,len:l-t,block:n.block})}),e}function R(o){const e=[],i=/\{\{(.+?)\}\}/g;let t;for(;(t=i.exec(o))!==null;)e.push({pos:t.index,len:t[0].length,block:{id:`var-${t[1]}-${t.index}`,name:t[1],type:"plugin"}});return e}class U{constructor(e){h(this,"plugins",[{id:"plugin-1",name:"LinkReaderPlugin",type:"plugin"}]);h(this,"workflows",[{id:"workflow-1",name:"condition_1_872",type:"workflow"}]);h(this,"triggerPos",0);this.callbacks=e}show(e,i,t){this.triggerPos=e;const l={top:`${i.bottom-t.top+10}px`,left:`${i.left-t.left}px`};this.callbacks.onShow(e,l)}hide(){this.callbacks.onHide()}getTriggerPos(){return this.triggerPos}}class Q{constructor(e){h(this,"view");h(this,"allBlocks",new Map);h(this,"options");this.options=e;const i=R(e.initialDoc),t=[...e.initialBlocks||[],...i];e.initialBlocks&&e.initialBlocks.forEach(n=>{"type"in n.block||this.allBlocks.set(n.block.id,n.block)});const l={updateBlockText:(n,a)=>{const u=this.allBlocks.get(n);u&&(u.presetText=a,this.allBlocks.set(n,u),this.options.onBlockUpdated&&this.options.onBlockUpdated(n,a))},openPopup:(n,a)=>{this.options.onOpenPopup(n,a)},deleteBlock:n=>{this.allBlocks.delete(n),this.options.onBlockDeleted&&this.options.onBlockDeleted(n)}},s=N(e.initialDoc,l,t);this.view=new r.EditorView({state:s.update({effects:d.StateEffect.appendConfig.of([...I({onTriggerPluginPopup:n=>this.options.onTriggerPluginPopup(n)}),...M({onTriggerAIDialog:n=>this.options.onTriggerAIDialog(n)})])}).state,parent:e.parent})}addBlock(){const e={id:Math.random().toString(36).slice(2,11),placeholder:"请输入编辑块内容为空时的提示文案",presetText:""};this.allBlocks.set(e.id,e);const{from:i,to:t}=this.view.state.selection.main;return this.view.dispatch({changes:{from:i,to:t,insert:" "},effects:y.of(e),selection:{anchor:i+1}}),this.view.focus(),e}addPluginBlock(e,i){return this.view.dispatch({changes:{from:e,to:e+1,insert:" "},effects:S.of({pos:e,block:i}),selection:{anchor:e+1}}),this.view.focus(),i}syncBlock(e){this.allBlocks.set(e.id,{...e}),this.view.dispatch({effects:E.of(e)})}getBlock(e){return this.allBlocks.get(e)}coordsAtPos(e){return this.view.coordsAtPos(e)}getData(){return z(this.view)}destroy(){this.view.destroy()}}const J=(o,e)=>{const{from:i,empty:t}=o.state.selection.main;if(!t)return!1;const l=i;if(l===0)return!1;let s=null,n=null,a=1;const u=f=>{f&&f.between(l-1,l,(k,p,P)=>{const m=P.spec.widget;if(m&&m.block&&m.block.id&&k<l&&p>=l)return s=m.block.id,n=k,a=p-k,!1})};return u(o.state.field(b,!1)),s||u(o.state.field(B,!1)),s&&n!==null?(e.deleteBlock(s),o.dispatch({changes:{from:n,to:n+a},selection:{anchor:n}}),!0):!1},V=r.EditorView.theme({"&":{height:"100%",outline:"none",position:"relative"},".cm-content":{padding:"20px",fontSize:"16px"},".cm-line":{padding:"4px 0"},".cm-header-1":{fontSize:"1.5em",color:"#008c99",fontWeight:"bold"},".cm-bold":{fontWeight:"bold"}}),_=r.Decoration.mark({class:"cm-bold"});function G(o){const e=[];for(let i=1;i<=o.lines;i++){const t=o.line(i),l=t.text;/^#+\s+/.test(l)&&e.push(_.range(t.from,t.to));const s=/\*\*(.*?)\*\*/g;let n;for(;(n=s.exec(l))!==null;)e.push(_.range(t.from+n.index,t.from+n.index+n[0].length))}return r.Decoration.set(e.sort((i,t)=>i.from-t.from),!0)}const W=d.StateField.define({create(o){return G(o.doc)},update(o,e){return e.docChanged?G(e.state.doc):o.map(e.changes)},provide:o=>r.EditorView.decorations.from(o)});function N(o,e,i=[]){const t=i.filter(a=>!("type"in a.block&&"name"in a.block)),l=i.filter(a=>"type"in a.block&&"name"in a.block),s=[w.history(),r.keymap.of([{key:"Backspace",run:a=>J(a,e)},...w.defaultKeymap,...w.historyKeymap]),r.drawSelection(),...A({callbacks:e,initialBlocks:t}),...L({initialBlocks:l}),W,V];return d.EditorState.create({doc:o,extensions:s})}function z(o){var l;const e=o.state.doc.toString(),i=F(o),t=$(o);return{content:e,editorBlocks:i,pluginBlocks:t,html:((l=o.dom.querySelector(".cm-content"))==null?void 0:l.innerHTML)||""}}c.AIDialogPlugin=q,c.CustomEditor=Q,c.EditBlockPlugin=j,c.LibraryBlockPlugin=U,c.addBlockEffect=y,c.addPluginBlockEffect=S,c.aiDialogExtensions=M,c.createEditorState=N,c.editBlockExtensions=A,c.editBlockField=b,c.editBlockTheme=C,c.editorTheme=V,c.getEditorBlocks=F,c.getEditorData=z,c.getPluginBlocks=$,c.markdownStyleField=W,c.parseTemplateVariables=R,c.pluginBlockExtensions=L,c.pluginBlockField=B,c.pluginPopupTriggerExtensions=I,c.updateBlockEffect=E,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(d,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/commands")):typeof define=="function"&&define.amd?define(["exports","@codemirror/state","@codemirror/view","@codemirror/commands"],a):(d=typeof globalThis<"u"?globalThis:d||self,a(d.AgentArtsEditor={},d.CMState,d.CMView,d.CMCommands))})(this,function(d,a,r,b){"use strict";var G=Object.defineProperty;var J=(d,a,r)=>a in d?G(d,a,{enumerable:!0,configurable:!0,writable:!0,value:r}):d[a]=r;var p=(d,a,r)=>J(d,typeof a!="symbol"?a+"":a,r);const C=a.StateEffect.define(),D=a.StateEffect.define();class g extends r.WidgetType{constructor(e,n){super(),this.block=e,this.callbacks=n}toDOM(e){const n=document.createElement("span");n.className="cm-inline-block",n.setAttribute("data-block-id",this.block.id);const o=document.createElement("input");o.type="text",o.className="block-input",o.value=this.block.presetText||"",o.placeholder=this.block.placeholder||"请输入...";const c=s=>{const i=document.createElement("span");i.style.visibility="hidden",i.style.position="absolute",i.style.whiteSpace="pre",i.style.font="inherit",i.textContent=s||o.placeholder,document.body.appendChild(i);const l=i.offsetWidth;return document.body.removeChild(i),l+10};return o.style.width=`${c(o.value)}px`,o.oninput=s=>{const i=s.target.value;o.style.width=`${c(i)}px`,this.callbacks.updateBlockText(this.block.id,i)},o.onfocus=()=>{const s=n.getBoundingClientRect();this.callbacks.openPopup(this.block.id,s)},o.onmousedown=s=>{s.stopPropagation()},o.onclick=s=>{s.stopPropagation();const i=n.getBoundingClientRect();this.callbacks.openPopup(this.block.id,i)},o.onkeydown=s=>{if(s.key==="Backspace"&&o.value===""){s.preventDefault();const i=e.posAtDOM(n);this.callbacks.deleteBlock(this.block.id),e.dispatch({changes:{from:i,to:i+1},selection:{anchor:i}})}},n.appendChild(o),n}ignoreEvent(){return!0}}const B=a.Facet.define({combine:t=>t[0]}),S=a.Facet.define({combine:t=>t.length?t[0]:[]}),x=a.StateField.define({create(t){const e=t.facet(B),n=t.facet(S);if(!n||n.length===0)return r.Decoration.none;const o=n.slice().sort((c,s)=>c.pos-s.pos).map(({pos:c,len:s,block:i})=>{const l=new g(i,e);return r.Decoration.replace({widget:l}).range(c,c+(s||1))});return r.Decoration.set(o,!0)},update(t,e){const n=e.state.facet(B);t=t.map(e.changes);for(const o of e.effects)if(o.is(C)){const c=e.state.selection.main.head-1,s=r.Decoration.replace({widget:new g(o.value,n)}).range(c,c+1);t=t.update({add:[s]})}else if(o.is(D)){const c=o.value;let s=null;t.between(0,e.state.doc.length,(i,l,u)=>{const h=u.spec.widget;h instanceof g&&h.block.id===c.id&&(s=i)}),s!==null&&(t=t.update({filter:(i,l,u)=>{const h=u.spec.widget;return!(h instanceof g&&h.block.id===c.id)},add:[r.Decoration.replace({widget:new g(c,n)}).range(s,s+1)]}))}return t},provide:t=>r.EditorView.decorations.from(t)}),F=r.EditorView.theme({".cm-inline-block":{display:"inline-block",backgroundColor:"#f3f0ff",color:"#8066ff",padding:"0 8px",margin:"0 4px",borderRadius:"4px",cursor:"pointer",border:"1px solid transparent",transition:"all 0.2s",fontSize:"15px",verticalAlign:"middle"},".cm-inline-block:hover":{backgroundColor:"#e9e4ff",borderColor:"#8066ff"},".block-input":{background:"transparent",border:"none",outline:"none",color:"inherit",font:"inherit",padding:"4px 0",width:"auto",minWidth:"20px",textAlign:"center"},".block-input::placeholder":{color:"#b2a1ff",opacity:.7}});function v(t){return[B.of(t.callbacks),S.of(t.initialBlocks||[]),x,F]}function V(t){const e=[],n=t.state.field(x,!1);return n&&n.between(0,t.state.doc.length,(o,c,s)=>{const i=s.spec.widget;i instanceof g&&e.push({pos:o,len:c-o,block:i.block})}),e}function I(t){return[L(t.onTriggerAIDialog),R(t.onTriggerAIDialog),$]}function L(t){return r.EditorView.updateListener.of(e=>{e.docChanged&&e.changes.iterChanges((n,o,c,s,i)=>{if(i.length!==1)return;i.sliceString(0)==="/"&&t(n)})})}const $=r.EditorView.theme({".cm-ai-selection-trigger":{position:"absolute",zIndex:"10",display:"none",width:"32px",height:"32px",alignItems:"center",justifyContent:"center",borderRadius:"8px",backgroundColor:"#fff",boxShadow:"0 6px 24px rgba(0, 0, 0, 0.12)",border:"1px solid rgba(0, 0, 0, 0.06)"},".cm-ai-selection-trigger button":{width:"100%",height:"100%",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0"},".cm-ai-selection-trigger button:hover":{backgroundColor:"#f3f4f6",borderRadius:"8px"}});function R(t){return r.ViewPlugin.fromClass(class{constructor(e){p(this,"dom");p(this,"button");p(this,"lastFrom",-1);p(this,"lastTo",-1);p(this,"measureScheduled",!1);this.view=e,this.dom=document.createElement("div"),this.dom.className="cm-ai-selection-trigger",this.button=document.createElement("button"),this.button.type="button";const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","16"),n.setAttribute("height","16"),n.setAttribute("viewBox","0 0 24 24"),n.setAttribute("fill","none"),n.setAttribute("stroke","#111827"),n.setAttribute("stroke-width","2"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round"),n.innerHTML='<path d="M5 12l1.5.5L7 14l.5-1.5L9 12l-1.5-.5L7 10l-.5 1.5L5 12z"/><path d="M12 4l2 6 6 2-6 2-2 6-2-6-6-2 6-2 2-6z"/>',this.button.appendChild(n),this.dom.appendChild(this.button),this.view.dom.appendChild(this.dom),this.dom.addEventListener("mousedown",o=>{o.preventDefault(),o.stopPropagation()}),this.button.addEventListener("click",o=>{o.preventDefault(),o.stopPropagation();const{from:c,empty:s}=this.view.state.selection.main;s||(t(c),this.hide())}),this.scheduleMeasure(!0)}update(e){(e.selectionSet||e.viewportChanged||e.focusChanged||e.docChanged)&&this.scheduleMeasure(!1)}destroy(){this.dom.remove()}hide(){this.dom.style.display="none"}show(){this.dom.style.display="flex"}scheduleMeasure(e){const{from:n,to:o,empty:c}=this.view.state.selection.main;if(c||!this.view.hasFocus){this.hide();return}!e&&n===this.lastFrom&&o===this.lastTo&&this.dom.style.display!=="none"||(this.lastFrom=n,this.lastTo=o,!this.measureScheduled&&(this.measureScheduled=!0,this.view.requestMeasure({read:s=>{const i=s.coordsAtPos(n);if(!i)return null;const l=s.dom.getBoundingClientRect();return{coords:i,editorRect:l}},write:s=>{this.measureScheduled=!1;const{empty:i}=this.view.state.selection.main;if(i||!this.view.hasFocus){this.hide();return}if(!s){this.hide();return}const{coords:l,editorRect:u}=s,h=32,k=32,f=6,E=Math.min(Math.max(l.left-u.left,f),Math.max(f,u.width-h-f)),m=Math.max(l.top-u.top-k-10,f);this.dom.style.left=`${E}px`,this.dom.style.top=`${m}px`,this.show()}})))}})}const T=a.StateEffect.define();class w extends r.WidgetType{constructor(e){super(),this.block=e}toDOM(){const e=document.createElement("span");e.className=`cm-plugin-block cm-plugin-block-${this.block.type}`,e.setAttribute("data-block-id",this.block.id);const n=document.createElement("i");n.className=this.block.type==="plugin"?"icon-plugin":"icon-workflow",e.appendChild(n);const o=document.createTextNode(this.block.name);return e.appendChild(o),e}ignoreEvent(){return!0}}const P=a.Facet.define({combine:t=>t.length?t[0]:[]}),y=a.StateField.define({create(t){const e=t.facet(P);if(!e||e.length===0)return r.Decoration.none;const n=e.slice().sort((o,c)=>o.pos-c.pos).map(({pos:o,len:c,block:s})=>r.Decoration.replace({widget:new w(s)}).range(o,o+(c||1)));return r.Decoration.set(n,!0)},update(t,e){t=t.map(e.changes);for(const n of e.effects)if(n.is(T)){const{pos:o,block:c}=n.value,s=e.changes.mapPos(o),i=r.Decoration.replace({widget:new w(c)}).range(s,s+1);t=t.update({add:[i]})}return t},provide:t=>r.EditorView.decorations.from(t)});function W(t){return[P.of(t.initialBlocks||[]),y]}function _(t){return[r.EditorView.updateListener.of(e=>{e.docChanged&&e.changes.iterChanges((n,o,c,s,i)=>{if(i.length!==1)return;i.sliceString(0)==="{"&&t.onTriggerPluginPopup(n)})})]}function N(t){const e=[],n=t.state.field(y,!1);return n&&n.between(0,t.state.doc.length,(o,c,s)=>{const i=s.spec.widget;i instanceof w&&e.push({pos:o,len:c-o,block:i.block})}),e}function z(t){const e=[],n=/\{\{(.+?)\}\}/g;let o;for(;(o=n.exec(t))!==null;)e.push({pos:o.index,len:o[0].length,block:{id:`var-${o[1]}-${o.index}`,name:o[1],type:"plugin"}});return e}class j{constructor(e){p(this,"view");p(this,"allBlocks",new Map);p(this,"options");this.options=e;const n=z(e.initialDoc),o=[...e.initialBlocks||[],...n];e.initialBlocks&&e.initialBlocks.forEach(i=>{"type"in i.block||this.allBlocks.set(i.block.id,i.block)});const c={updateBlockText:(i,l)=>{const u=this.allBlocks.get(i);u&&(u.presetText=l,this.allBlocks.set(i,u),this.options.onBlockUpdated&&this.options.onBlockUpdated(i,l))},openPopup:(i,l)=>{this.options.onOpenPopup(i,l)},deleteBlock:i=>{this.allBlocks.delete(i),this.options.onBlockDeleted&&this.options.onBlockDeleted(i)}},s=K(e.initialDoc,c,o);this.view=new r.EditorView({state:s.update({effects:a.StateEffect.appendConfig.of([..._({onTriggerPluginPopup:i=>this.options.onTriggerPluginPopup(i)}),...I({onTriggerAIDialog:i=>this.options.onTriggerAIDialog(i)})])}).state,parent:e.parent})}addBlock(){const e={id:Math.random().toString(36).slice(2,11),placeholder:"请输入编辑块内容为空时的提示文案",presetText:""};this.allBlocks.set(e.id,e);const{from:n,to:o}=this.view.state.selection.main;return this.view.dispatch({changes:{from:n,to:o,insert:" "},effects:C.of(e),selection:{anchor:n+1}}),this.view.focus(),e}addPluginBlock(e,n){return this.view.dispatch({changes:{from:e,to:e+1,insert:" "},effects:T.of({pos:e,block:n}),selection:{anchor:e+1}}),this.view.focus(),n}syncBlock(e){this.allBlocks.set(e.id,{...e}),this.view.dispatch({effects:D.of(e)})}getBlock(e){return this.allBlocks.get(e)}coordsAtPos(e){return this.view.coordsAtPos(e)}getData(){return U(this.view)}destroy(){this.view.destroy()}}const q=(t,e)=>{const{from:n,empty:o}=t.state.selection.main;if(!o)return!1;const c=n;if(c===0)return!1;let s=null,i=null,l=1;const u=h=>{h&&h.between(c-1,c,(k,f,E)=>{const m=E.spec.widget;if(m&&m.block&&m.block.id&&k<c&&f>=c)return s=m.block.id,i=k,l=f-k,!1})};return u(t.state.field(x,!1)),s||u(t.state.field(y,!1)),s&&i!==null?(e.deleteBlock(s),t.dispatch({changes:{from:i,to:i+l},selection:{anchor:i}}),!0):!1},O=r.EditorView.theme({"&":{height:"100%",outline:"none",position:"relative"},".cm-content":{padding:"20px",fontSize:"16px"},".cm-line":{padding:"4px 0"},".cm-header-1":{fontSize:"1.5em",color:"#008c99",fontWeight:"bold"},".cm-bold":{fontWeight:"bold"}}),A=r.Decoration.mark({class:"cm-bold"});function M(t){const e=[];for(let n=1;n<=t.lines;n++){const o=t.line(n),c=o.text;/^#+\s+/.test(c)&&e.push(A.range(o.from,o.to));const s=/\*\*(.*?)\*\*/g;let i;for(;(i=s.exec(c))!==null;)e.push(A.range(o.from+i.index,o.from+i.index+i[0].length))}return r.Decoration.set(e.sort((n,o)=>n.from-o.from),!0)}const H=a.StateField.define({create(t){return M(t.doc)},update(t,e){return e.docChanged?M(e.state.doc):t.map(e.changes)},provide:t=>r.EditorView.decorations.from(t)});function K(t,e,n=[]){const o=n.filter(l=>!("type"in l.block&&"name"in l.block)),c=n.filter(l=>"type"in l.block&&"name"in l.block),s=[b.history(),r.keymap.of([{key:"Backspace",run:l=>q(l,e)},...b.defaultKeymap,...b.historyKeymap]),r.drawSelection(),...v({callbacks:e,initialBlocks:o}),...W({initialBlocks:c}),H,O];return a.EditorState.create({doc:t,extensions:s})}function U(t){var c;const e=t.state.doc.toString(),n=V(t),o=N(t);return{content:e,editorBlocks:n,pluginBlocks:o,html:((c=t.dom.querySelector(".cm-content"))==null?void 0:c.innerHTML)||""}}d.CustomEditor=j,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,66 +1,5 @@
|
|
|
1
|
-
import { DecorationSet } from '@codemirror/view';
|
|
2
|
-
import { EditorState } from '@codemirror/state';
|
|
3
1
|
import { EditorView } from '@codemirror/view';
|
|
4
|
-
import { Extension } from '@codemirror/state';
|
|
5
2
|
import { Rect } from '@codemirror/view';
|
|
6
|
-
import { StateEffectType } from '@codemirror/state';
|
|
7
|
-
import { StateField } from '@codemirror/state';
|
|
8
|
-
|
|
9
|
-
export declare const addBlockEffect: StateEffectType<EditorBlock>;
|
|
10
|
-
|
|
11
|
-
export declare const addPluginBlockEffect: StateEffectType< {
|
|
12
|
-
pos: number;
|
|
13
|
-
block: PluginBlock;
|
|
14
|
-
}>;
|
|
15
|
-
|
|
16
|
-
export declare function aiDialogExtensions(options: {
|
|
17
|
-
onTriggerAIDialog: (pos: number) => void;
|
|
18
|
-
}): Extension[];
|
|
19
|
-
|
|
20
|
-
export declare class AIDialogPlugin {
|
|
21
|
-
private callbacks;
|
|
22
|
-
private isGenerating;
|
|
23
|
-
private aiStreamTimer;
|
|
24
|
-
private currentResponse;
|
|
25
|
-
constructor(callbacks: AIResponseCallbacks);
|
|
26
|
-
show(pos: number, coords: {
|
|
27
|
-
bottom: number;
|
|
28
|
-
left: number;
|
|
29
|
-
}, editorRect: DOMRect): void;
|
|
30
|
-
hide(): void;
|
|
31
|
-
sendQuestion(question: string): void;
|
|
32
|
-
stopResponse(): void;
|
|
33
|
-
private finishGeneration;
|
|
34
|
-
getIsGenerating(): boolean;
|
|
35
|
-
destroy(): void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export declare interface AIResponseCallbacks {
|
|
39
|
-
onStream: (text: string) => void;
|
|
40
|
-
onLoading: (loading: boolean) => void;
|
|
41
|
-
onComplete: () => void;
|
|
42
|
-
onStop: () => void;
|
|
43
|
-
onShow: (pos: number, style: {
|
|
44
|
-
top: string;
|
|
45
|
-
left: string;
|
|
46
|
-
}) => void;
|
|
47
|
-
onHide: () => void;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export declare interface CodeMirrorCallbacks {
|
|
51
|
-
updateBlockText: (id: string, text: string) => void;
|
|
52
|
-
openPopup: (id: string, rect: DOMRect) => void;
|
|
53
|
-
deleteBlock: (id: string) => void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 创建编辑器状态
|
|
58
|
-
*/
|
|
59
|
-
export declare function createEditorState(initialDoc: string, callbacks: CodeMirrorCallbacks, initialBlocks?: {
|
|
60
|
-
pos: number;
|
|
61
|
-
len?: number;
|
|
62
|
-
block: EditorBlock | PluginBlock;
|
|
63
|
-
}[]): EditorState;
|
|
64
3
|
|
|
65
4
|
export declare class CustomEditor {
|
|
66
5
|
view: EditorView;
|
|
@@ -72,31 +11,14 @@ export declare class CustomEditor {
|
|
|
72
11
|
syncBlock(updatedBlock: EditorBlock): void;
|
|
73
12
|
getBlock(id: string): EditorBlock | undefined;
|
|
74
13
|
coordsAtPos(pos: number): Rect | null;
|
|
75
|
-
getData():
|
|
76
|
-
content: string;
|
|
77
|
-
editorBlocks: {
|
|
78
|
-
pos: number;
|
|
79
|
-
len?: number;
|
|
80
|
-
block: EditorBlock;
|
|
81
|
-
}[];
|
|
82
|
-
pluginBlocks: {
|
|
83
|
-
pos: number;
|
|
84
|
-
len?: number;
|
|
85
|
-
block: PluginBlock;
|
|
86
|
-
}[];
|
|
87
|
-
html: string;
|
|
88
|
-
};
|
|
14
|
+
getData(): EditorData;
|
|
89
15
|
destroy(): void;
|
|
90
16
|
}
|
|
91
17
|
|
|
92
18
|
export declare interface CustomEditorOptions {
|
|
93
19
|
parent: HTMLElement;
|
|
94
20
|
initialDoc: string;
|
|
95
|
-
initialBlocks?:
|
|
96
|
-
pos: number;
|
|
97
|
-
len?: number;
|
|
98
|
-
block: EditorBlock | PluginBlock;
|
|
99
|
-
}[];
|
|
21
|
+
initialBlocks?: InitialBlock[];
|
|
100
22
|
onOpenPopup: (id: string, rect: DOMRect) => void;
|
|
101
23
|
onTriggerPluginPopup: (pos: number) => void;
|
|
102
24
|
onTriggerAIDialog: (pos: number) => void;
|
|
@@ -104,54 +26,13 @@ export declare interface CustomEditorOptions {
|
|
|
104
26
|
onBlockUpdated?: (id: string, text: string) => void;
|
|
105
27
|
}
|
|
106
28
|
|
|
107
|
-
export declare interface EditBlockCallbacks {
|
|
108
|
-
onShow: (block: EditorBlock, style: {
|
|
109
|
-
top: string;
|
|
110
|
-
left: string;
|
|
111
|
-
}) => void;
|
|
112
|
-
onHide: () => void;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export declare function editBlockExtensions(options: {
|
|
116
|
-
callbacks: CodeMirrorCallbacks;
|
|
117
|
-
initialBlocks?: {
|
|
118
|
-
pos: number;
|
|
119
|
-
len?: number;
|
|
120
|
-
block: EditorBlock;
|
|
121
|
-
}[];
|
|
122
|
-
}): Extension[];
|
|
123
|
-
|
|
124
|
-
export declare const editBlockField: StateField<DecorationSet>;
|
|
125
|
-
|
|
126
|
-
export declare class EditBlockPlugin {
|
|
127
|
-
private callbacks;
|
|
128
|
-
editingBlock: EditorBlock;
|
|
129
|
-
constructor(callbacks: EditBlockCallbacks);
|
|
130
|
-
show(block: EditorBlock, rect: DOMRect, editorRect: DOMRect): void;
|
|
131
|
-
hide(): void;
|
|
132
|
-
updateEditingBlock(block: Partial<EditorBlock>): void;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export declare const editBlockTheme: Extension;
|
|
136
|
-
|
|
137
29
|
export declare interface EditorBlock {
|
|
138
30
|
id: string;
|
|
139
31
|
placeholder: string;
|
|
140
32
|
presetText: string;
|
|
141
33
|
}
|
|
142
34
|
|
|
143
|
-
export declare
|
|
144
|
-
|
|
145
|
-
export declare function getEditorBlocks(view: EditorView): {
|
|
146
|
-
pos: number;
|
|
147
|
-
len?: number;
|
|
148
|
-
block: EditorBlock;
|
|
149
|
-
}[];
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* 获取编辑器数据
|
|
153
|
-
*/
|
|
154
|
-
export declare function getEditorData(view: EditorView): {
|
|
35
|
+
export declare type EditorData = {
|
|
155
36
|
content: string;
|
|
156
37
|
editorBlocks: {
|
|
157
38
|
pos: number;
|
|
@@ -166,49 +47,11 @@ export declare function getEditorData(view: EditorView): {
|
|
|
166
47
|
html: string;
|
|
167
48
|
};
|
|
168
49
|
|
|
169
|
-
export declare
|
|
50
|
+
export declare type InitialBlock = {
|
|
170
51
|
pos: number;
|
|
171
52
|
len?: number;
|
|
172
|
-
block: PluginBlock;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export declare interface LibraryBlockCallbacks {
|
|
176
|
-
onShow: (pos: number, style: {
|
|
177
|
-
top: string;
|
|
178
|
-
left: string;
|
|
179
|
-
}) => void;
|
|
180
|
-
onHide: () => void;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export declare class LibraryBlockPlugin {
|
|
184
|
-
private callbacks;
|
|
185
|
-
plugins: {
|
|
186
|
-
id: string;
|
|
187
|
-
name: string;
|
|
188
|
-
type: "plugin";
|
|
189
|
-
}[];
|
|
190
|
-
workflows: {
|
|
191
|
-
id: string;
|
|
192
|
-
name: string;
|
|
193
|
-
type: "workflow";
|
|
194
|
-
}[];
|
|
195
|
-
private triggerPos;
|
|
196
|
-
constructor(callbacks: LibraryBlockCallbacks);
|
|
197
|
-
show(pos: number, coords: {
|
|
198
|
-
bottom: number;
|
|
199
|
-
left: number;
|
|
200
|
-
}, editorRect: DOMRect): void;
|
|
201
|
-
hide(): void;
|
|
202
|
-
getTriggerPos(): number;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export declare const markdownStyleField: StateField<DecorationSet>;
|
|
206
|
-
|
|
207
|
-
export declare function parseTemplateVariables(doc: string): {
|
|
208
|
-
pos: number;
|
|
209
|
-
len: number;
|
|
210
|
-
block: PluginBlock;
|
|
211
|
-
}[];
|
|
53
|
+
block: EditorBlock | PluginBlock;
|
|
54
|
+
};
|
|
212
55
|
|
|
213
56
|
export declare interface PluginBlock {
|
|
214
57
|
id: string;
|
|
@@ -216,20 +59,4 @@ export declare interface PluginBlock {
|
|
|
216
59
|
type: 'plugin' | 'workflow';
|
|
217
60
|
}
|
|
218
61
|
|
|
219
|
-
export declare function pluginBlockExtensions(options: {
|
|
220
|
-
initialBlocks?: {
|
|
221
|
-
pos: number;
|
|
222
|
-
len?: number;
|
|
223
|
-
block: PluginBlock;
|
|
224
|
-
}[];
|
|
225
|
-
}): Extension[];
|
|
226
|
-
|
|
227
|
-
export declare const pluginBlockField: StateField<DecorationSet>;
|
|
228
|
-
|
|
229
|
-
export declare function pluginPopupTriggerExtensions(options: {
|
|
230
|
-
onTriggerPluginPopup: (pos: number) => void;
|
|
231
|
-
}): Extension[];
|
|
232
|
-
|
|
233
|
-
export declare const updateBlockEffect: StateEffectType<EditorBlock>;
|
|
234
|
-
|
|
235
62
|
export { }
|