@agent-arts/editor 0.0.1 → 0.0.3
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/README.md +94 -0
- package/dist/editor.js +268 -137
- package/dist/editor.umd.cjs +5 -1
- package/dist/index.d.ts +166 -0
- package/package.json +27 -3
- package/LICENSE +0 -21
- package/dist/core.d.ts +0 -73
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @agent-arts/editor
|
|
2
|
+
|
|
3
|
+
一个基于 CodeMirror 6 的提示词编辑器,框架无关,支持 Vue.js、Angular、React。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 编辑块 edit-block:可编辑
|
|
8
|
+
- 插件块 plugin-block:不可编辑,通过大括号 `{` 呼起,用户插入插件、工作流、变量等
|
|
9
|
+
- AI 对话 ai-dialog:通过斜线 `/` 或拖选内容呼起,通过 AI 生成和优化提示词
|
|
10
|
+
|
|
11
|
+
## 演示动画
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
## 使用
|
|
16
|
+
|
|
17
|
+
### 安装
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @agent-arts/editor
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### 快速上手
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { CustomEditor, CustomEditorOptions } from '@agent-arts/editor';
|
|
27
|
+
|
|
28
|
+
const options: CustomEditorOptions = {
|
|
29
|
+
parent: document.querySelector('#editor')!,
|
|
30
|
+
initialDoc: '# 欢迎使用 AgentArts Editor',
|
|
31
|
+
onOpenPopup: (id, rect) => {
|
|
32
|
+
// 处理编辑块弹窗
|
|
33
|
+
},
|
|
34
|
+
onTriggerPluginPopup: (pos) => {
|
|
35
|
+
// 输入 '{' 时触发
|
|
36
|
+
},
|
|
37
|
+
onTriggerAIDialog: (pos) => {
|
|
38
|
+
// 输入 '/' 时触发
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const editor = new CustomEditor(options);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 插件配置
|
|
46
|
+
|
|
47
|
+
#### AI 对话插件 (AIDialogPlugin)
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { AIDialogPlugin } from '@agent-arts/editor';
|
|
51
|
+
|
|
52
|
+
const aiPlugin = new AIDialogPlugin({
|
|
53
|
+
onStream: (text) => { /* 处理流式输出 */ },
|
|
54
|
+
onLoading: (loading) => { /* 处理加载状态 */ },
|
|
55
|
+
onShow: (pos, style) => { /* 显示 AI 浮框 */ },
|
|
56
|
+
onHide: () => { /* 隐藏 AI 浮框 */ }
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### 插件库浮框 (LibraryBlockPlugin)
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { LibraryBlockPlugin } from '@agent-arts/editor';
|
|
64
|
+
|
|
65
|
+
const libraryPlugin = new LibraryBlockPlugin({
|
|
66
|
+
onShow: (pos, style) => { /* 显示插件列表浮框 */ },
|
|
67
|
+
onHide: () => { /* 隐藏插件列表浮框 */ }
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// 插入选中的插件块
|
|
71
|
+
editor.addPluginBlock(libraryPlugin.getTriggerPos(), {
|
|
72
|
+
id: 'plugin-id',
|
|
73
|
+
name: '插件名称',
|
|
74
|
+
type: 'plugin'
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### 编辑块插件 (EditBlockPlugin)
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { EditBlockPlugin } from '@agent-arts/editor';
|
|
82
|
+
|
|
83
|
+
const editPlugin = new EditBlockPlugin({
|
|
84
|
+
onShow: (block, style) => { /* 显示编辑块配置浮框 */ },
|
|
85
|
+
onHide: () => { /* 隐藏浮框 */ }
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 核心 API
|
|
90
|
+
|
|
91
|
+
- `editor.addBlock()`: 手动添加一个新的编辑块。
|
|
92
|
+
- `editor.syncBlock(block)`: 同步外部状态到编辑器内部的块。
|
|
93
|
+
- `editor.getData()`: 获取编辑器的 JSON 数据和 HTML 内容。
|
|
94
|
+
- `editor.destroy()`: 销毁编辑器实例。
|
package/dist/editor.js
CHANGED
|
@@ -1,31 +1,38 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { StateEffect as
|
|
5
|
-
import { EditorView as
|
|
6
|
-
import { history as
|
|
7
|
-
import { markdown as
|
|
8
|
-
import { languages as
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.options = e, e.initialBlocks && e.initialBlocks.forEach((
|
|
15
|
-
const
|
|
16
|
-
updateBlockText: (
|
|
17
|
-
const
|
|
18
|
-
|
|
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: (
|
|
21
|
-
this.options.onOpenPopup(
|
|
20
|
+
openPopup: (i, s) => {
|
|
21
|
+
this.options.onOpenPopup(i, s);
|
|
22
22
|
},
|
|
23
|
-
deleteBlock: (
|
|
24
|
-
this.allBlocks.delete(
|
|
23
|
+
deleteBlock: (i) => {
|
|
24
|
+
this.allBlocks.delete(i), this.options.onBlockDeleted && this.options.onBlockDeleted(i);
|
|
25
25
|
}
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
|
|
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:
|
|
46
|
+
const { from: t, to: o } = this.view.state.selection.main;
|
|
40
47
|
return this.view.dispatch({
|
|
41
|
-
changes: { from:
|
|
42
|
-
effects:
|
|
43
|
-
selection: { anchor:
|
|
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:
|
|
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
|
|
72
|
+
return H(this.view, this.allBlocks);
|
|
56
73
|
}
|
|
57
74
|
destroy() {
|
|
58
75
|
this.view.destroy();
|
|
59
76
|
}
|
|
60
77
|
}
|
|
61
|
-
const
|
|
62
|
-
class
|
|
63
|
-
constructor(e,
|
|
64
|
-
super(), this.block = e, this.callbacks =
|
|
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
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
return document.body.removeChild(
|
|
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
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
},
|
|
81
|
-
const
|
|
82
|
-
this.callbacks.openPopup(this.block.id,
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
this.callbacks.openPopup(this.block.id,
|
|
89
|
-
},
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
let
|
|
93
|
-
e.state.field(k).between(0, e.state.doc.length, (
|
|
94
|
-
|
|
95
|
-
}),
|
|
96
|
-
changes: { from:
|
|
97
|
-
selection: { anchor:
|
|
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
|
-
},
|
|
117
|
+
}, t.appendChild(o), t;
|
|
101
118
|
}
|
|
102
119
|
ignoreEvent(e) {
|
|
103
120
|
return !0;
|
|
104
121
|
}
|
|
105
122
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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(
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
for (let
|
|
123
|
-
if (
|
|
124
|
-
const
|
|
125
|
-
widget: new
|
|
126
|
-
}).range(
|
|
127
|
-
|
|
128
|
-
} else if (
|
|
129
|
-
const
|
|
130
|
-
let
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
}),
|
|
135
|
-
filter: (
|
|
136
|
-
const
|
|
137
|
-
return !(
|
|
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
|
|
141
|
-
}).range(
|
|
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
|
|
182
|
+
return n;
|
|
145
183
|
},
|
|
146
|
-
provide: (
|
|
147
|
-
}),
|
|
148
|
-
const
|
|
149
|
-
if (
|
|
150
|
-
let
|
|
151
|
-
const
|
|
152
|
-
return
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
}),
|
|
156
|
-
changes: { from:
|
|
157
|
-
selection: { anchor:
|
|
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 =
|
|
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
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
...
|
|
202
|
-
...
|
|
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: (
|
|
243
|
+
run: (i) => F(i, e)
|
|
206
244
|
}
|
|
207
245
|
]),
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
246
|
+
R({ base: $, codeLanguages: I }),
|
|
247
|
+
g.of(e),
|
|
248
|
+
S.of(t),
|
|
211
249
|
k,
|
|
212
250
|
M
|
|
213
251
|
];
|
|
214
|
-
return
|
|
215
|
-
doc:
|
|
216
|
-
extensions:
|
|
252
|
+
return C.create({
|
|
253
|
+
doc: n,
|
|
254
|
+
extensions: o
|
|
217
255
|
});
|
|
218
256
|
}
|
|
219
|
-
function q(
|
|
220
|
-
return new
|
|
257
|
+
function q(n, e) {
|
|
258
|
+
return new f({
|
|
221
259
|
state: e,
|
|
222
|
-
parent:
|
|
260
|
+
parent: n
|
|
223
261
|
});
|
|
224
262
|
}
|
|
225
|
-
function
|
|
226
|
-
var
|
|
227
|
-
const
|
|
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:
|
|
231
|
-
blocks:
|
|
268
|
+
content: t,
|
|
269
|
+
blocks: o
|
|
232
270
|
},
|
|
233
|
-
html: ((
|
|
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
|
-
|
|
366
|
+
X as EditBlockPlugin,
|
|
367
|
+
J as LibraryBlockPlugin,
|
|
368
|
+
y as addBlockEffect,
|
|
369
|
+
v as addPluginBlockEffect,
|
|
239
370
|
k as blockField,
|
|
240
|
-
|
|
371
|
+
N as createEditorState,
|
|
241
372
|
q as createEditorView,
|
|
242
373
|
M as editorTheme,
|
|
243
|
-
|
|
244
|
-
|
|
374
|
+
H as getEditorData,
|
|
375
|
+
x as updateBlockEffect
|
|
245
376
|
};
|
package/dist/editor.umd.cjs
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
(function(
|
|
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"})});
|
package/dist/index.d.ts
ADDED
|
@@ -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,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-arts/editor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "A prompt editor based on CodeMirror 6, support Vue.js 3 and Angular.",
|
|
5
|
+
"author": "AgentArts Team",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://agent-arts.github.io/editor/",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git@github.com:agent-arts/editor.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/agent-arts/editor"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"prompt",
|
|
17
|
+
"editor",
|
|
18
|
+
"codemirror",
|
|
19
|
+
"agent-arts",
|
|
20
|
+
"typescript",
|
|
21
|
+
"ai",
|
|
22
|
+
"ai-agent"
|
|
23
|
+
],
|
|
4
24
|
"type": "module",
|
|
5
25
|
"main": "./dist/editor.umd.cjs",
|
|
6
26
|
"module": "./dist/editor.js",
|
|
7
|
-
"types": "./dist/
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
8
28
|
"exports": {
|
|
9
29
|
".": {
|
|
10
|
-
"types": "./dist/
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
11
31
|
"import": "./dist/editor.js",
|
|
12
32
|
"require": "./dist/editor.umd.cjs"
|
|
13
33
|
}
|
|
@@ -15,6 +35,10 @@
|
|
|
15
35
|
"files": [
|
|
16
36
|
"dist"
|
|
17
37
|
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"registry": "https://registry.npmjs.org/"
|
|
41
|
+
},
|
|
18
42
|
"scripts": {
|
|
19
43
|
"dev": "vite",
|
|
20
44
|
"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 { }
|