@agent-arts/editor 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/editor.js CHANGED
@@ -1,31 +1,38 @@
1
- var y = Object.defineProperty;
2
- var x = (t, e, i) => e in t ? y(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
3
- var f = (t, e, i) => x(t, typeof e != "symbol" ? e + "" : e, i);
4
- import { StateEffect as m, Facet as b, StateField as v, EditorState as E } from "@codemirror/state";
5
- import { EditorView as h, Decoration as p, WidgetType as S, keymap as C } from "@codemirror/view";
6
- import { history as D, defaultKeymap as T, historyKeymap as P } from "@codemirror/commands";
7
- import { markdown as W, markdownLanguage as F } from "@codemirror/lang-markdown";
8
- import { languages as A } from "@codemirror/language-data";
1
+ var P = Object.defineProperty;
2
+ var T = (n, e, t) => e in n ? P(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var r = (n, e, t) => T(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { StateEffect as u, Facet as w, StateField as E, EditorState as C } from "@codemirror/state";
5
+ import { EditorView as f, Decoration as p, WidgetType as B, keymap as D } from "@codemirror/view";
6
+ import { history as L, defaultKeymap as A, historyKeymap as G } from "@codemirror/commands";
7
+ import { markdown as R, markdownLanguage as $ } from "@codemirror/lang-markdown";
8
+ import { languages as I } from "@codemirror/language-data";
9
9
  class j {
10
10
  constructor(e) {
11
- f(this, "view");
12
- f(this, "allBlocks", /* @__PURE__ */ new Map());
13
- f(this, "options");
14
- this.options = e, e.initialBlocks && e.initialBlocks.forEach((o) => this.allBlocks.set(o.block.id, o.block));
15
- const i = {
16
- updateBlockText: (o, c) => {
17
- const l = this.allBlocks.get(o);
18
- l && (l.presetText = c, this.allBlocks.set(o, l), this.options.onBlockUpdated && this.options.onBlockUpdated(o, c));
11
+ r(this, "view");
12
+ r(this, "allBlocks", /* @__PURE__ */ new Map());
13
+ r(this, "options");
14
+ this.options = e, e.initialBlocks && e.initialBlocks.forEach((i) => this.allBlocks.set(i.block.id, i.block));
15
+ const t = {
16
+ updateBlockText: (i, s) => {
17
+ const c = this.allBlocks.get(i);
18
+ c && (c.presetText = s, this.allBlocks.set(i, c), this.options.onBlockUpdated && this.options.onBlockUpdated(i, s));
19
19
  },
20
- openPopup: (o, c) => {
21
- this.options.onOpenPopup(o, c);
20
+ openPopup: (i, s) => {
21
+ this.options.onOpenPopup(i, s);
22
22
  },
23
- deleteBlock: (o) => {
24
- this.allBlocks.delete(o), this.options.onBlockDeleted && this.options.onBlockDeleted(o);
23
+ deleteBlock: (i) => {
24
+ this.allBlocks.delete(i), this.options.onBlockDeleted && this.options.onBlockDeleted(i);
25
25
  }
26
- }, n = z(e.initialDoc, i, e.initialBlocks || []);
27
- this.view = new h({
28
- state: n,
26
+ }, o = N(e.initialDoc, t, e.initialBlocks || []), l = f.updateListener.of((i) => {
27
+ i.docChanged && i.changes.iterChanges((s, c, d, a, m) => {
28
+ const b = m.sliceString(0);
29
+ m.length === 1 && (b === "{" ? this.options.onTriggerPluginPopup(s) : b === "/" && this.options.onTriggerAIDialog(s));
30
+ });
31
+ });
32
+ this.view = new f({
33
+ state: o.update({
34
+ effects: u.appendConfig.of(l)
35
+ }).state,
29
36
  parent: e.parent
30
37
  });
31
38
  }
@@ -36,127 +43,158 @@ class j {
36
43
  presetText: ""
37
44
  };
38
45
  this.allBlocks.set(e.id, e);
39
- const { from: i, to: n } = this.view.state.selection.main;
46
+ const { from: t, to: o } = this.view.state.selection.main;
40
47
  return this.view.dispatch({
41
- changes: { from: i, to: n, insert: " " },
42
- effects: g.of(e),
43
- selection: { anchor: i + 1 }
48
+ changes: { from: t, to: o, insert: " " },
49
+ effects: y.of(e),
50
+ selection: { anchor: t + 1 }
44
51
  }), this.view.focus(), e;
45
52
  }
53
+ addPluginBlock(e, t) {
54
+ return this.view.dispatch({
55
+ changes: { from: e, to: e + 1, insert: " " },
56
+ effects: v.of({ pos: e, block: t }),
57
+ selection: { anchor: e + 1 }
58
+ }), this.view.focus(), t;
59
+ }
46
60
  syncBlock(e) {
47
61
  this.allBlocks.set(e.id, { ...e }), this.view.dispatch({
48
- effects: w.of(e)
62
+ effects: x.of(e)
49
63
  });
50
64
  }
51
65
  getBlock(e) {
52
66
  return this.allBlocks.get(e);
53
67
  }
68
+ coordsAtPos(e) {
69
+ return this.view.coordsAtPos(e);
70
+ }
54
71
  getData() {
55
- return R(this.view, this.allBlocks);
72
+ return H(this.view, this.allBlocks);
56
73
  }
57
74
  destroy() {
58
75
  this.view.destroy();
59
76
  }
60
77
  }
61
- const g = m.define(), w = m.define();
62
- class d extends S {
63
- constructor(e, i) {
64
- super(), this.block = e, this.callbacks = i;
78
+ const y = u.define(), x = u.define(), v = u.define();
79
+ class h extends B {
80
+ constructor(e, t) {
81
+ super(), this.block = e, this.callbacks = t;
65
82
  }
66
83
  toDOM(e) {
67
- const i = document.createElement("span");
68
- i.className = "cm-inline-block", i.setAttribute("data-block-id", this.block.id);
69
- const n = document.createElement("input");
70
- n.type = "text", n.className = "block-input", n.value = this.block.presetText || "", n.placeholder = this.block.placeholder || "请输入...";
71
- const o = (c) => {
72
- const l = document.createElement("span");
73
- l.style.visibility = "hidden", l.style.position = "absolute", l.style.whiteSpace = "pre", l.style.font = "inherit", l.textContent = c || n.placeholder, document.body.appendChild(l);
74
- const a = l.offsetWidth;
75
- return document.body.removeChild(l), a + 10;
84
+ const t = document.createElement("span");
85
+ t.className = "cm-inline-block", t.setAttribute("data-block-id", this.block.id);
86
+ const o = document.createElement("input");
87
+ o.type = "text", o.className = "block-input", o.value = this.block.presetText || "", o.placeholder = this.block.placeholder || "请输入...";
88
+ const l = (i) => {
89
+ const s = document.createElement("span");
90
+ s.style.visibility = "hidden", s.style.position = "absolute", s.style.whiteSpace = "pre", s.style.font = "inherit", s.textContent = i || o.placeholder, document.body.appendChild(s);
91
+ const c = s.offsetWidth;
92
+ return document.body.removeChild(s), c + 10;
76
93
  };
77
- return n.style.width = `${o(n.value)}px`, n.oninput = (c) => {
78
- const l = c.target.value;
79
- n.style.width = `${o(l)}px`, this.callbacks.updateBlockText(this.block.id, l);
80
- }, n.onfocus = (c) => {
81
- const l = i.getBoundingClientRect();
82
- this.callbacks.openPopup(this.block.id, l);
83
- }, n.onmousedown = (c) => {
84
- c.stopPropagation();
85
- }, n.onclick = (c) => {
86
- c.stopPropagation();
87
- const l = i.getBoundingClientRect();
88
- this.callbacks.openPopup(this.block.id, l);
89
- }, n.onkeydown = (c) => {
90
- if (c.key === "Backspace" && n.value === "") {
91
- c.preventDefault();
92
- let l = null;
93
- e.state.field(k).between(0, e.state.doc.length, (a, r, s) => {
94
- s.spec.widget === this && (l = a);
95
- }), l !== null && (this.callbacks.deleteBlock(this.block.id), e.dispatch({
96
- changes: { from: l, to: l + 1 },
97
- selection: { anchor: l }
94
+ return o.style.width = `${l(o.value)}px`, o.oninput = (i) => {
95
+ const s = i.target.value;
96
+ o.style.width = `${l(s)}px`, this.callbacks.updateBlockText(this.block.id, s);
97
+ }, o.onfocus = (i) => {
98
+ const s = t.getBoundingClientRect();
99
+ this.callbacks.openPopup(this.block.id, s);
100
+ }, o.onmousedown = (i) => {
101
+ i.stopPropagation();
102
+ }, o.onclick = (i) => {
103
+ i.stopPropagation();
104
+ const s = t.getBoundingClientRect();
105
+ this.callbacks.openPopup(this.block.id, s);
106
+ }, o.onkeydown = (i) => {
107
+ if (i.key === "Backspace" && o.value === "") {
108
+ i.preventDefault();
109
+ let s = null;
110
+ e.state.field(k).between(0, e.state.doc.length, (c, d, a) => {
111
+ a.spec.widget === this && (s = c);
112
+ }), s !== null && (this.callbacks.deleteBlock(this.block.id), e.dispatch({
113
+ changes: { from: s, to: s + 1 },
114
+ selection: { anchor: s }
98
115
  }));
99
116
  }
100
- }, i.appendChild(n), i;
117
+ }, t.appendChild(o), t;
101
118
  }
102
119
  ignoreEvent(e) {
103
120
  return !0;
104
121
  }
105
122
  }
106
- const u = b.define({
107
- combine: (t) => t[0]
108
- }), B = b.define({
109
- combine: (t) => t.length ? t[0] : []
110
- }), k = v.define({
111
- create(t) {
112
- const e = t.facet(u), i = t.facet(B);
113
- if (!i || i.length === 0) return p.none;
114
- const n = i.slice().sort((o, c) => o.pos - c.pos).map(({ pos: o, block: c }) => p.replace({
115
- widget: new d(c, e)
116
- }).range(o, o + 1));
117
- return p.set(n, !0);
123
+ class W extends B {
124
+ constructor(e) {
125
+ super(), this.block = e;
126
+ }
127
+ toDOM() {
128
+ const e = document.createElement("span");
129
+ e.className = `cm-plugin-block cm-plugin-block-${this.block.type}`, e.setAttribute("data-block-id", this.block.id);
130
+ const t = document.createElement("i");
131
+ t.className = this.block.type === "plugin" ? "icon-plugin" : "icon-workflow", e.appendChild(t);
132
+ const o = document.createTextNode(this.block.name);
133
+ return e.appendChild(o), e;
134
+ }
135
+ ignoreEvent(e) {
136
+ return !0;
137
+ }
138
+ }
139
+ const g = w.define({
140
+ combine: (n) => n[0]
141
+ }), S = w.define({
142
+ combine: (n) => n.length ? n[0] : []
143
+ }), k = E.define({
144
+ create(n) {
145
+ const e = n.facet(g), t = n.facet(S);
146
+ if (!t || t.length === 0) return p.none;
147
+ const o = t.slice().sort((l, i) => l.pos - i.pos).map(({ pos: l, block: i }) => p.replace({
148
+ widget: new h(i, e)
149
+ }).range(l, l + 1));
150
+ return p.set(o, !0);
118
151
  },
119
- update(t, e) {
120
- const i = e.state.facet(u);
121
- t = t.map(e.changes);
122
- for (let n of e.effects)
123
- if (n.is(g)) {
124
- const o = e.state.selection.main.head - 1, c = p.replace({
125
- widget: new d(n.value, i)
126
- }).range(o, o + 1);
127
- t = t.update({ add: [c] });
128
- } else if (n.is(w)) {
129
- const o = n.value;
130
- let c = null;
131
- t.between(0, e.state.doc.length, (l, a, r) => {
132
- const s = r.spec.widget;
133
- s instanceof d && s.block.id === o.id && (c = l);
134
- }), c !== null && (t = t.update({
135
- filter: (l, a, r) => {
136
- const s = r.spec.widget;
137
- return !(s instanceof d && s.block.id === o.id);
152
+ update(n, e) {
153
+ const t = e.state.facet(g);
154
+ n = n.map(e.changes);
155
+ for (let o of e.effects)
156
+ if (o.is(y)) {
157
+ const l = e.state.selection.main.head - 1, i = p.replace({
158
+ widget: new h(o.value, t)
159
+ }).range(l, l + 1);
160
+ n = n.update({ add: [i] });
161
+ } else if (o.is(x)) {
162
+ const l = o.value;
163
+ let i = null;
164
+ n.between(0, e.state.doc.length, (s, c, d) => {
165
+ const a = d.spec.widget;
166
+ a instanceof h && a.block.id === l.id && (i = s);
167
+ }), i !== null && (n = n.update({
168
+ filter: (s, c, d) => {
169
+ const a = d.spec.widget;
170
+ return !(a instanceof h && a.block.id === l.id);
138
171
  },
139
172
  add: [p.replace({
140
- widget: new d(o, i)
141
- }).range(c, c + 1)]
173
+ widget: new h(l, t)
174
+ }).range(i, i + 1)]
142
175
  }));
176
+ } else if (o.is(v)) {
177
+ const { pos: l, block: i } = o.value, s = e.changes.mapPos(l), c = p.replace({
178
+ widget: new W(i)
179
+ }).range(s, s + 1);
180
+ n = n.update({ add: [c] });
143
181
  }
144
- return t;
182
+ return n;
145
183
  },
146
- provide: (t) => h.decorations.from(t)
147
- }), L = (t, e) => {
148
- const i = t.state.selection.main.head;
149
- if (i === 0) return !1;
150
- let n = null, o = null;
151
- const c = t.state.field(k, !1);
152
- return c && c.between(i - 1, i, (l, a, r) => {
153
- const s = r.spec.widget;
154
- s instanceof d && (n = s.block.id, o = l);
155
- }), n && o !== null ? (e.deleteBlock(n), t.dispatch({
156
- changes: { from: o, to: o + 1 },
157
- selection: { anchor: o }
184
+ provide: (n) => f.decorations.from(n)
185
+ }), F = (n, e) => {
186
+ const t = n.state.selection.main.head;
187
+ if (t === 0) return !1;
188
+ let o = null, l = null;
189
+ const i = n.state.field(k, !1);
190
+ return i && i.between(t - 1, t, (s, c, d) => {
191
+ const a = d.spec.widget;
192
+ a instanceof h && (o = a.block.id, l = s);
193
+ }), o && l !== null ? (e.deleteBlock(o), n.dispatch({
194
+ changes: { from: l, to: l + 1 },
195
+ selection: { anchor: l }
158
196
  }), !0) : !1;
159
- }, M = h.theme({
197
+ }, M = f.theme({
160
198
  "&": { height: "100%", outline: "none" },
161
199
  ".cm-content": { padding: "20px", fontSize: "16px" },
162
200
  ".cm-line": { padding: "4px 0" },
@@ -194,52 +232,145 @@ const u = b.define({
194
232
  },
195
233
  ".cm-header-1": { fontSize: "1.5em", color: "#008c99", fontWeight: "bold" }
196
234
  });
197
- function z(t, e, i = []) {
198
- const n = [
199
- D(),
200
- C.of([
201
- ...T,
202
- ...P,
235
+ function N(n, e, t = []) {
236
+ const o = [
237
+ L(),
238
+ D.of([
239
+ ...A,
240
+ ...G,
203
241
  {
204
242
  key: "Backspace",
205
- run: (c) => L(c, e)
243
+ run: (i) => F(i, e)
206
244
  }
207
245
  ]),
208
- W({ base: F, codeLanguages: A }),
209
- u.of(e),
210
- B.of(i),
246
+ R({ base: $, codeLanguages: I }),
247
+ g.of(e),
248
+ S.of(t),
211
249
  k,
212
250
  M
213
251
  ];
214
- return E.create({
215
- doc: t,
216
- extensions: n
252
+ return C.create({
253
+ doc: n,
254
+ extensions: o
217
255
  });
218
256
  }
219
- function q(t, e) {
220
- return new h({
257
+ function q(n, e) {
258
+ return new f({
221
259
  state: e,
222
- parent: t
260
+ parent: n
223
261
  });
224
262
  }
225
- function R(t, e) {
226
- var o;
227
- const i = t.state.doc.toString(), n = Array.from(e.values());
263
+ function H(n, e) {
264
+ var l;
265
+ const t = n.state.doc.toString(), o = Array.from(e.values());
228
266
  return {
229
267
  json: {
230
- content: i,
231
- blocks: n
268
+ content: t,
269
+ blocks: o
232
270
  },
233
- html: ((o = t.dom.querySelector(".cm-content")) == null ? void 0 : o.innerHTML) || ""
271
+ html: ((l = n.dom.querySelector(".cm-content")) == null ? void 0 : l.innerHTML) || ""
234
272
  };
235
273
  }
274
+ class Q {
275
+ constructor(e) {
276
+ r(this, "isGenerating", !1);
277
+ r(this, "aiStreamTimer", null);
278
+ r(this, "currentResponse", "");
279
+ this.callbacks = e;
280
+ }
281
+ show(e, t, o) {
282
+ const l = {
283
+ top: `${t.bottom - o.top + 10}px`,
284
+ left: `${t.left - o.left}px`
285
+ };
286
+ this.callbacks.onShow(e, l);
287
+ }
288
+ hide() {
289
+ this.stopResponse(), this.callbacks.onHide();
290
+ }
291
+ sendQuestion(e) {
292
+ if (!e || this.isGenerating) return;
293
+ this.isGenerating = !0, this.callbacks.onLoading(!0), this.currentResponse = "", this.callbacks.onStream("");
294
+ const t = `洲、美洲积累了丰富的在地经验,擅长结合用户需求定制专属旅行方案,曾帮助1000+人解决旅行难题,被旅行者亲切称为"旅行百事通"。
295
+
296
+ ## 核心性格与风格
297
+ - **性格特点**:热情开朗、专业耐心,擅长用轻松幽默的方式化解旅行焦虑(如:"别慌!机票改签我有3个小窍门,保准帮你搞定~"),遇到用户疑问会像朋友般细致拆解细节(如:"你担心的高原反应,我去年在西藏徒步时总结过4个缓解方法...")。
298
+ - **语言风格**:口语化且富有感染力,常用"宝藏地""小众玩法"等旅行圈`;
299
+ let o = 0;
300
+ this.aiStreamTimer = setInterval(() => {
301
+ this.callbacks.onLoading(!1), o < t.length ? (this.currentResponse += t[o], this.callbacks.onStream(this.currentResponse), o++) : this.finishGeneration();
302
+ }, 30);
303
+ }
304
+ stopResponse() {
305
+ this.aiStreamTimer && (clearInterval(this.aiStreamTimer), this.aiStreamTimer = null), this.isGenerating = !1, this.callbacks.onLoading(!1), this.callbacks.onStop();
306
+ }
307
+ finishGeneration() {
308
+ this.aiStreamTimer && (clearInterval(this.aiStreamTimer), this.aiStreamTimer = null), this.isGenerating = !1, this.callbacks.onLoading(!1), this.callbacks.onComplete();
309
+ }
310
+ getIsGenerating() {
311
+ return this.isGenerating;
312
+ }
313
+ destroy() {
314
+ this.stopResponse();
315
+ }
316
+ }
317
+ class J {
318
+ constructor(e) {
319
+ r(this, "plugins", [
320
+ { id: "plugin-1", name: "LinkReaderPlugin", type: "plugin" }
321
+ ]);
322
+ r(this, "workflows", [
323
+ { id: "workflow-1", name: "condition_1_872", type: "workflow" }
324
+ ]);
325
+ r(this, "triggerPos", 0);
326
+ this.callbacks = e;
327
+ }
328
+ show(e, t, o) {
329
+ this.triggerPos = e;
330
+ const l = {
331
+ top: `${t.bottom - o.top + 10}px`,
332
+ left: `${t.left - o.left}px`
333
+ };
334
+ this.callbacks.onShow(e, l);
335
+ }
336
+ hide() {
337
+ this.callbacks.onHide();
338
+ }
339
+ getTriggerPos() {
340
+ return this.triggerPos;
341
+ }
342
+ }
343
+ class X {
344
+ constructor(e) {
345
+ r(this, "editingBlock", { id: "", placeholder: "", presetText: "" });
346
+ this.callbacks = e;
347
+ }
348
+ show(e, t, o) {
349
+ this.editingBlock = { ...e };
350
+ const l = {
351
+ top: `${t.bottom - o.top + 10}px`,
352
+ left: `${t.left - o.left}px`
353
+ };
354
+ this.callbacks.onShow(this.editingBlock, l);
355
+ }
356
+ hide() {
357
+ this.callbacks.onHide();
358
+ }
359
+ updateEditingBlock(e) {
360
+ this.editingBlock = { ...this.editingBlock, ...e };
361
+ }
362
+ }
236
363
  export {
364
+ Q as AIDialogPlugin,
237
365
  j as CustomEditor,
238
- g as addBlockEffect,
366
+ X as EditBlockPlugin,
367
+ J as LibraryBlockPlugin,
368
+ y as addBlockEffect,
369
+ v as addPluginBlockEffect,
239
370
  k as blockField,
240
- z as createEditorState,
371
+ N as createEditorState,
241
372
  q as createEditorView,
242
373
  M as editorTheme,
243
- R as getEditorData,
244
- w as updateBlockEffect
374
+ H as getEditorData,
375
+ x as updateBlockEffect
245
376
  };
@@ -1 +1,5 @@
1
- (function(s,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/commands"),require("@codemirror/lang-markdown"),require("@codemirror/language-data")):typeof define=="function"&&define.amd?define(["exports","@codemirror/state","@codemirror/view","@codemirror/commands","@codemirror/lang-markdown","@codemirror/language-data"],a):(s=typeof globalThis<"u"?globalThis:s||self,a(s.AgentArtsEditor={},s.CMState,s.CMView,s.CMCommands,s.CMLangMarkdown,s.CMLangData))})(this,function(s,a,r,m,w,S){"use strict";var M=Object.defineProperty;var P=(s,a,r)=>a in s?M(s,a,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[a]=r;var k=(s,a,r)=>P(s,typeof a!="symbol"?a+"":a,r);class D{constructor(e){k(this,"view");k(this,"allBlocks",new Map);k(this,"options");this.options=e,e.initialBlocks&&e.initialBlocks.forEach(t=>this.allBlocks.set(t.block.id,t.block));const l={updateBlockText:(t,n)=>{const c=this.allBlocks.get(t);c&&(c.presetText=n,this.allBlocks.set(t,c),this.options.onBlockUpdated&&this.options.onBlockUpdated(t,n))},openPopup:(t,n)=>{this.options.onOpenPopup(t,n)},deleteBlock:t=>{this.allBlocks.delete(t),this.options.onBlockDeleted&&this.options.onBlockDeleted(t)}},o=C(e.initialDoc,l,e.initialBlocks||[]);this.view=new r.EditorView({state:o,parent:e.parent})}addBlock(){const e={id:Math.random().toString(36).substr(2,9),placeholder:"请输入编辑块内容为空时的提示文案",presetText:""};this.allBlocks.set(e.id,e);const{from:l,to:o}=this.view.state.selection.main;return this.view.dispatch({changes:{from:l,to:o,insert:" "},effects:g.of(e),selection:{anchor:l+1}}),this.view.focus(),e}syncBlock(e){this.allBlocks.set(e.id,{...e}),this.view.dispatch({effects:b.of(e)})}getBlock(e){return this.allBlocks.get(e)}getData(){return x(this.view,this.allBlocks)}destroy(){this.view.destroy()}}const g=a.StateEffect.define(),b=a.StateEffect.define();class f extends r.WidgetType{constructor(e,l){super(),this.block=e,this.callbacks=l}toDOM(e){const l=document.createElement("span");l.className="cm-inline-block",l.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 t=n=>{const c=document.createElement("span");c.style.visibility="hidden",c.style.position="absolute",c.style.whiteSpace="pre",c.style.font="inherit",c.textContent=n||o.placeholder,document.body.appendChild(c);const p=c.offsetWidth;return document.body.removeChild(c),p+10};return o.style.width=`${t(o.value)}px`,o.oninput=n=>{const c=n.target.value;o.style.width=`${t(c)}px`,this.callbacks.updateBlockText(this.block.id,c)},o.onfocus=n=>{const c=l.getBoundingClientRect();this.callbacks.openPopup(this.block.id,c)},o.onmousedown=n=>{n.stopPropagation()},o.onclick=n=>{n.stopPropagation();const c=l.getBoundingClientRect();this.callbacks.openPopup(this.block.id,c)},o.onkeydown=n=>{if(n.key==="Backspace"&&o.value===""){n.preventDefault();let c=null;e.state.field(h).between(0,e.state.doc.length,(p,u,d)=>{d.spec.widget===this&&(c=p)}),c!==null&&(this.callbacks.deleteBlock(this.block.id),e.dispatch({changes:{from:c,to:c+1},selection:{anchor:c}}))}},l.appendChild(o),l}ignoreEvent(e){return!0}}const B=a.Facet.define({combine:i=>i[0]}),y=a.Facet.define({combine:i=>i.length?i[0]:[]}),h=a.StateField.define({create(i){const e=i.facet(B),l=i.facet(y);if(!l||l.length===0)return r.Decoration.none;const o=l.slice().sort((t,n)=>t.pos-n.pos).map(({pos:t,block:n})=>r.Decoration.replace({widget:new f(n,e)}).range(t,t+1));return r.Decoration.set(o,!0)},update(i,e){const l=e.state.facet(B);i=i.map(e.changes);for(let o of e.effects)if(o.is(g)){const t=e.state.selection.main.head-1,n=r.Decoration.replace({widget:new f(o.value,l)}).range(t,t+1);i=i.update({add:[n]})}else if(o.is(b)){const t=o.value;let n=null;i.between(0,e.state.doc.length,(c,p,u)=>{const d=u.spec.widget;d instanceof f&&d.block.id===t.id&&(n=c)}),n!==null&&(i=i.update({filter:(c,p,u)=>{const d=u.spec.widget;return!(d instanceof f&&d.block.id===t.id)},add:[r.Decoration.replace({widget:new f(t,l)}).range(n,n+1)]}))}return i},provide:i=>r.EditorView.decorations.from(i)}),T=(i,e)=>{const l=i.state.selection.main.head;if(l===0)return!1;let o=null,t=null;const n=i.state.field(h,!1);return n&&n.between(l-1,l,(c,p,u)=>{const d=u.spec.widget;d instanceof f&&(o=d.block.id,t=c)}),o&&t!==null?(e.deleteBlock(o),i.dispatch({changes:{from:t,to:t+1},selection:{anchor:t}}),!0):!1},E=r.EditorView.theme({"&":{height:"100%",outline:"none"},".cm-content":{padding:"20px",fontSize:"16px"},".cm-line":{padding:"4px 0"},".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},".cm-header-1":{fontSize:"1.5em",color:"#008c99",fontWeight:"bold"}});function C(i,e,l=[]){const o=[m.history(),r.keymap.of([...m.defaultKeymap,...m.historyKeymap,{key:"Backspace",run:n=>T(n,e)}]),w.markdown({base:w.markdownLanguage,codeLanguages:S.languages}),B.of(e),y.of(l),h,E];return a.EditorState.create({doc:i,extensions:o})}function v(i,e){return new r.EditorView({state:e,parent:i})}function x(i,e){var t;const l=i.state.doc.toString(),o=Array.from(e.values());return{json:{content:l,blocks:o},html:((t=i.dom.querySelector(".cm-content"))==null?void 0:t.innerHTML)||""}}s.CustomEditor=D,s.addBlockEffect=g,s.blockField=h,s.createEditorState=C,s.createEditorView=v,s.editorTheme=E,s.getEditorData=x,s.updateBlockEffect=b,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(l,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/commands"),require("@codemirror/lang-markdown"),require("@codemirror/language-data")):typeof define=="function"&&define.amd?define(["exports","@codemirror/state","@codemirror/view","@codemirror/commands","@codemirror/lang-markdown","@codemirror/language-data"],a):(l=typeof globalThis<"u"?globalThis:l||self,a(l.AgentArtsEditor={},l.CMState,l.CMView,l.CMCommands,l.CMLangMarkdown,l.CMLangData))})(this,function(l,a,r,k,y,D){"use strict";var I=Object.defineProperty;var V=(l,a,r)=>a in l?I(l,a,{enumerable:!0,configurable:!0,writable:!0,value:r}):l[a]=r;var p=(l,a,r)=>V(l,typeof a!="symbol"?a+"":a,r);class v{constructor(e){p(this,"view");p(this,"allBlocks",new Map);p(this,"options");this.options=e,e.initialBlocks&&e.initialBlocks.forEach(i=>this.allBlocks.set(i.block.id,i.block));const o={updateBlockText:(i,s)=>{const d=this.allBlocks.get(i);d&&(d.presetText=s,this.allBlocks.set(i,d),this.options.onBlockUpdated&&this.options.onBlockUpdated(i,s))},openPopup:(i,s)=>{this.options.onOpenPopup(i,s)},deleteBlock:i=>{this.allBlocks.delete(i),this.options.onBlockDeleted&&this.options.onBlockDeleted(i)}},t=P(e.initialDoc,o,e.initialBlocks||[]),c=r.EditorView.updateListener.of(i=>{i.docChanged&&i.changes.iterChanges((s,d,u,h,x)=>{const C=x.sliceString(0);x.length===1&&(C==="{"?this.options.onTriggerPluginPopup(s):C==="/"&&this.options.onTriggerAIDialog(s))})});this.view=new r.EditorView({state:t.update({effects:a.StateEffect.appendConfig.of(c)}).state,parent:e.parent})}addBlock(){const e={id:Math.random().toString(36).substr(2,9),placeholder:"请输入编辑块内容为空时的提示文案",presetText:""};this.allBlocks.set(e.id,e);const{from:o,to:t}=this.view.state.selection.main;return this.view.dispatch({changes:{from:o,to:t,insert:" "},effects:m.of(e),selection:{anchor:o+1}}),this.view.focus(),e}addPluginBlock(e,o){return this.view.dispatch({changes:{from:e,to:e+1,insert:" "},effects:w.of({pos:e,block:o}),selection:{anchor:e+1}}),this.view.focus(),o}syncBlock(e){this.allBlocks.set(e.id,{...e}),this.view.dispatch({effects:b.of(e)})}getBlock(e){return this.allBlocks.get(e)}coordsAtPos(e){return this.view.coordsAtPos(e)}getData(){return T(this.view,this.allBlocks)}destroy(){this.view.destroy()}}const m=a.StateEffect.define(),b=a.StateEffect.define(),w=a.StateEffect.define();class f extends r.WidgetType{constructor(e,o){super(),this.block=e,this.callbacks=o}toDOM(e){const o=document.createElement("span");o.className="cm-inline-block",o.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 c=i=>{const s=document.createElement("span");s.style.visibility="hidden",s.style.position="absolute",s.style.whiteSpace="pre",s.style.font="inherit",s.textContent=i||t.placeholder,document.body.appendChild(s);const d=s.offsetWidth;return document.body.removeChild(s),d+10};return t.style.width=`${c(t.value)}px`,t.oninput=i=>{const s=i.target.value;t.style.width=`${c(s)}px`,this.callbacks.updateBlockText(this.block.id,s)},t.onfocus=i=>{const s=o.getBoundingClientRect();this.callbacks.openPopup(this.block.id,s)},t.onmousedown=i=>{i.stopPropagation()},t.onclick=i=>{i.stopPropagation();const s=o.getBoundingClientRect();this.callbacks.openPopup(this.block.id,s)},t.onkeydown=i=>{if(i.key==="Backspace"&&t.value===""){i.preventDefault();let s=null;e.state.field(g).between(0,e.state.doc.length,(d,u,h)=>{h.spec.widget===this&&(s=d)}),s!==null&&(this.callbacks.deleteBlock(this.block.id),e.dispatch({changes:{from:s,to:s+1},selection:{anchor:s}}))}},o.appendChild(t),o}ignoreEvent(e){return!0}}class L 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 o=document.createElement("i");o.className=this.block.type==="plugin"?"icon-plugin":"icon-workflow",e.appendChild(o);const t=document.createTextNode(this.block.name);return e.appendChild(t),e}ignoreEvent(e){return!0}}const B=a.Facet.define({combine:n=>n[0]}),E=a.Facet.define({combine:n=>n.length?n[0]:[]}),g=a.StateField.define({create(n){const e=n.facet(B),o=n.facet(E);if(!o||o.length===0)return r.Decoration.none;const t=o.slice().sort((c,i)=>c.pos-i.pos).map(({pos:c,block:i})=>r.Decoration.replace({widget:new f(i,e)}).range(c,c+1));return r.Decoration.set(t,!0)},update(n,e){const o=e.state.facet(B);n=n.map(e.changes);for(let t of e.effects)if(t.is(m)){const c=e.state.selection.main.head-1,i=r.Decoration.replace({widget:new f(t.value,o)}).range(c,c+1);n=n.update({add:[i]})}else if(t.is(b)){const c=t.value;let i=null;n.between(0,e.state.doc.length,(s,d,u)=>{const h=u.spec.widget;h instanceof f&&h.block.id===c.id&&(i=s)}),i!==null&&(n=n.update({filter:(s,d,u)=>{const h=u.spec.widget;return!(h instanceof f&&h.block.id===c.id)},add:[r.Decoration.replace({widget:new f(c,o)}).range(i,i+1)]}))}else if(t.is(w)){const{pos:c,block:i}=t.value,s=e.changes.mapPos(c),d=r.Decoration.replace({widget:new L(i)}).range(s,s+1);n=n.update({add:[d]})}return n},provide:n=>r.EditorView.decorations.from(n)}),A=(n,e)=>{const o=n.state.selection.main.head;if(o===0)return!1;let t=null,c=null;const i=n.state.field(g,!1);return i&&i.between(o-1,o,(s,d,u)=>{const h=u.spec.widget;h instanceof f&&(t=h.block.id,c=s)}),t&&c!==null?(e.deleteBlock(t),n.dispatch({changes:{from:c,to:c+1},selection:{anchor:c}}),!0):!1},S=r.EditorView.theme({"&":{height:"100%",outline:"none"},".cm-content":{padding:"20px",fontSize:"16px"},".cm-line":{padding:"4px 0"},".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},".cm-header-1":{fontSize:"1.5em",color:"#008c99",fontWeight:"bold"}});function P(n,e,o=[]){const t=[k.history(),r.keymap.of([...k.defaultKeymap,...k.historyKeymap,{key:"Backspace",run:i=>A(i,e)}]),y.markdown({base:y.markdownLanguage,codeLanguages:D.languages}),B.of(e),E.of(o),g,S];return a.EditorState.create({doc:n,extensions:t})}function $(n,e){return new r.EditorView({state:e,parent:n})}function T(n,e){var c;const o=n.state.doc.toString(),t=Array.from(e.values());return{json:{content:o,blocks:t},html:((c=n.dom.querySelector(".cm-content"))==null?void 0:c.innerHTML)||""}}class M{constructor(e){p(this,"isGenerating",!1);p(this,"aiStreamTimer",null);p(this,"currentResponse","");this.callbacks=e}show(e,o,t){const c={top:`${o.bottom-t.top+10}px`,left:`${o.left-t.left}px`};this.callbacks.onShow(e,c)}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 o=`洲、美洲积累了丰富的在地经验,擅长结合用户需求定制专属旅行方案,曾帮助1000+人解决旅行难题,被旅行者亲切称为"旅行百事通"。
2
+
3
+ ## 核心性格与风格
4
+ - **性格特点**:热情开朗、专业耐心,擅长用轻松幽默的方式化解旅行焦虑(如:"别慌!机票改签我有3个小窍门,保准帮你搞定~"),遇到用户疑问会像朋友般细致拆解细节(如:"你担心的高原反应,我去年在西藏徒步时总结过4个缓解方法...")。
5
+ - **语言风格**:口语化且富有感染力,常用"宝藏地""小众玩法"等旅行圈`;let t=0;this.aiStreamTimer=setInterval(()=>{this.callbacks.onLoading(!1),t<o.length?(this.currentResponse+=o[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()}}class G{constructor(e){p(this,"plugins",[{id:"plugin-1",name:"LinkReaderPlugin",type:"plugin"}]);p(this,"workflows",[{id:"workflow-1",name:"condition_1_872",type:"workflow"}]);p(this,"triggerPos",0);this.callbacks=e}show(e,o,t){this.triggerPos=e;const c={top:`${o.bottom-t.top+10}px`,left:`${o.left-t.left}px`};this.callbacks.onShow(e,c)}hide(){this.callbacks.onHide()}getTriggerPos(){return this.triggerPos}}class R{constructor(e){p(this,"editingBlock",{id:"",placeholder:"",presetText:""});this.callbacks=e}show(e,o,t){this.editingBlock={...e};const c={top:`${o.bottom-t.top+10}px`,left:`${o.left-t.left}px`};this.callbacks.onShow(this.editingBlock,c)}hide(){this.callbacks.onHide()}updateEditingBlock(e){this.editingBlock={...this.editingBlock,...e}}}l.AIDialogPlugin=M,l.CustomEditor=v,l.EditBlockPlugin=R,l.LibraryBlockPlugin=G,l.addBlockEffect=m,l.addPluginBlockEffect=w,l.blockField=g,l.createEditorState=P,l.createEditorView=$,l.editorTheme=S,l.getEditorData=T,l.updateBlockEffect=b,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,166 @@
1
+ import { DecorationSet } from '@codemirror/view';
2
+ import { EditorState } from '@codemirror/state';
3
+ import { EditorView } from '@codemirror/view';
4
+ import { Extension } from '@codemirror/state';
5
+ 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 class AIDialogPlugin {
17
+ private callbacks;
18
+ private isGenerating;
19
+ private aiStreamTimer;
20
+ private currentResponse;
21
+ constructor(callbacks: AIResponseCallbacks);
22
+ show(pos: number, coords: {
23
+ bottom: number;
24
+ left: number;
25
+ }, editorRect: DOMRect): void;
26
+ hide(): void;
27
+ sendQuestion(question: string): void;
28
+ stopResponse(): void;
29
+ private finishGeneration;
30
+ getIsGenerating(): boolean;
31
+ destroy(): void;
32
+ }
33
+
34
+ export declare interface AIResponseCallbacks {
35
+ onStream: (text: string) => void;
36
+ onLoading: (loading: boolean) => void;
37
+ onComplete: () => void;
38
+ onStop: () => void;
39
+ onShow: (pos: number, style: {
40
+ top: string;
41
+ left: string;
42
+ }) => void;
43
+ onHide: () => void;
44
+ }
45
+
46
+ export declare const blockField: StateField<DecorationSet>;
47
+
48
+ export declare interface CodeMirrorCallbacks {
49
+ updateBlockText: (id: string, text: string) => void;
50
+ openPopup: (id: string, rect: DOMRect) => void;
51
+ deleteBlock: (id: string) => void;
52
+ }
53
+
54
+ export declare function createEditorState(initialDoc: string, callbacks: CodeMirrorCallbacks, initialBlocks?: {
55
+ pos: number;
56
+ block: EditorBlock;
57
+ }[]): EditorState;
58
+
59
+ export declare function createEditorView(parent: HTMLElement, state: EditorState): EditorView;
60
+
61
+ export declare class CustomEditor {
62
+ view: EditorView;
63
+ allBlocks: Map<string, EditorBlock>;
64
+ private options;
65
+ constructor(options: CustomEditorOptions);
66
+ addBlock(): EditorBlock;
67
+ addPluginBlock(pos: number, block: PluginBlock): PluginBlock;
68
+ syncBlock(updatedBlock: EditorBlock): void;
69
+ getBlock(id: string): EditorBlock | undefined;
70
+ coordsAtPos(pos: number): Rect | null;
71
+ getData(): {
72
+ json: {
73
+ content: string;
74
+ blocks: EditorBlock[];
75
+ };
76
+ html: string;
77
+ };
78
+ destroy(): void;
79
+ }
80
+
81
+ export declare interface CustomEditorOptions {
82
+ parent: HTMLElement;
83
+ initialDoc: string;
84
+ initialBlocks?: {
85
+ pos: number;
86
+ block: EditorBlock;
87
+ }[];
88
+ onOpenPopup: (id: string, rect: DOMRect) => void;
89
+ onTriggerPluginPopup: (pos: number) => void;
90
+ onTriggerAIDialog: (pos: number) => void;
91
+ onBlockDeleted?: (id: string) => void;
92
+ onBlockUpdated?: (id: string, text: string) => void;
93
+ }
94
+
95
+ export declare interface EditBlockCallbacks {
96
+ onShow: (block: EditorBlock, style: {
97
+ top: string;
98
+ left: string;
99
+ }) => void;
100
+ onHide: () => void;
101
+ }
102
+
103
+ export declare class EditBlockPlugin {
104
+ private callbacks;
105
+ editingBlock: EditorBlock;
106
+ constructor(callbacks: EditBlockCallbacks);
107
+ show(block: EditorBlock, rect: DOMRect, editorRect: DOMRect): void;
108
+ hide(): void;
109
+ updateEditingBlock(block: Partial<EditorBlock>): void;
110
+ }
111
+
112
+ export declare interface EditorBlock {
113
+ id: string;
114
+ placeholder: string;
115
+ presetText: string;
116
+ }
117
+
118
+ export declare const editorTheme: Extension;
119
+
120
+ export declare function getEditorData(view: EditorView, blocks: Map<string, EditorBlock>): {
121
+ json: {
122
+ content: string;
123
+ blocks: EditorBlock[];
124
+ };
125
+ html: string;
126
+ };
127
+
128
+ export declare interface LibraryBlockCallbacks {
129
+ onShow: (pos: number, style: {
130
+ top: string;
131
+ left: string;
132
+ }) => void;
133
+ onHide: () => void;
134
+ }
135
+
136
+ export declare class LibraryBlockPlugin {
137
+ private callbacks;
138
+ plugins: {
139
+ id: string;
140
+ name: string;
141
+ type: "plugin";
142
+ }[];
143
+ workflows: {
144
+ id: string;
145
+ name: string;
146
+ type: "workflow";
147
+ }[];
148
+ private triggerPos;
149
+ constructor(callbacks: LibraryBlockCallbacks);
150
+ show(pos: number, coords: {
151
+ bottom: number;
152
+ left: number;
153
+ }, editorRect: DOMRect): void;
154
+ hide(): void;
155
+ getTriggerPos(): number;
156
+ }
157
+
158
+ export declare interface PluginBlock {
159
+ id: string;
160
+ name: string;
161
+ type: 'plugin' | 'workflow';
162
+ }
163
+
164
+ export declare const updateBlockEffect: StateEffectType<EditorBlock>;
165
+
166
+ export { }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@agent-arts/editor",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "main": "./dist/editor.umd.cjs",
6
6
  "module": "./dist/editor.js",
7
- "types": "./dist/core.d.ts",
7
+ "types": "./dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/core.d.ts",
10
+ "types": "./dist/index.d.ts",
11
11
  "import": "./dist/editor.js",
12
12
  "require": "./dist/editor.umd.cjs"
13
13
  }
@@ -15,6 +15,10 @@
15
15
  "files": [
16
16
  "dist"
17
17
  ],
18
+ "publishConfig": {
19
+ "access": "public",
20
+ "registry": "https://registry.npmjs.org/"
21
+ },
18
22
  "scripts": {
19
23
  "dev": "vite",
20
24
  "build": "vite build",
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 agent-arts
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/dist/core.d.ts DELETED
@@ -1,73 +0,0 @@
1
- import { DecorationSet } from '@codemirror/view';
2
- import { EditorState } from '@codemirror/state';
3
- import { EditorView } from '@codemirror/view';
4
- import { Extension } from '@codemirror/state';
5
- import { StateEffectType } from '@codemirror/state';
6
- import { StateField } from '@codemirror/state';
7
-
8
- export declare const addBlockEffect: StateEffectType<EditorBlock>;
9
-
10
- export declare const blockField: StateField<DecorationSet>;
11
-
12
- export declare interface CodeMirrorCallbacks {
13
- updateBlockText: (id: string, text: string) => void;
14
- openPopup: (id: string, rect: DOMRect) => void;
15
- deleteBlock: (id: string) => void;
16
- }
17
-
18
- export declare function createEditorState(initialDoc: string, callbacks: CodeMirrorCallbacks, initialBlocks?: {
19
- pos: number;
20
- block: EditorBlock;
21
- }[]): EditorState;
22
-
23
- export declare function createEditorView(parent: HTMLElement, state: EditorState): EditorView;
24
-
25
- export declare class CustomEditor {
26
- view: EditorView;
27
- allBlocks: Map<string, EditorBlock>;
28
- private options;
29
- constructor(options: CustomEditorOptions);
30
- addBlock(): EditorBlock;
31
- syncBlock(updatedBlock: EditorBlock): void;
32
- getBlock(id: string): EditorBlock | undefined;
33
- getData(): {
34
- json: {
35
- content: string;
36
- blocks: EditorBlock[];
37
- };
38
- html: string;
39
- };
40
- destroy(): void;
41
- }
42
-
43
- export declare interface CustomEditorOptions {
44
- parent: HTMLElement;
45
- initialDoc: string;
46
- initialBlocks?: {
47
- pos: number;
48
- block: EditorBlock;
49
- }[];
50
- onOpenPopup: (id: string, rect: DOMRect) => void;
51
- onBlockDeleted?: (id: string) => void;
52
- onBlockUpdated?: (id: string, text: string) => void;
53
- }
54
-
55
- export declare interface EditorBlock {
56
- id: string;
57
- placeholder: string;
58
- presetText: string;
59
- }
60
-
61
- export declare const editorTheme: Extension;
62
-
63
- export declare function getEditorData(view: EditorView, blocks: Map<string, EditorBlock>): {
64
- json: {
65
- content: string;
66
- blocks: EditorBlock[];
67
- };
68
- html: string;
69
- };
70
-
71
- export declare const updateBlockEffect: StateEffectType<EditorBlock>;
72
-
73
- export { }