@agent-arts/editor 0.0.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/LICENSE +21 -0
- package/dist/core.d.ts +73 -0
- package/dist/editor.js +245 -0
- package/dist/editor.umd.cjs +1 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
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 { }
|
package/dist/editor.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
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";
|
|
9
|
+
class j {
|
|
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));
|
|
19
|
+
},
|
|
20
|
+
openPopup: (o, c) => {
|
|
21
|
+
this.options.onOpenPopup(o, c);
|
|
22
|
+
},
|
|
23
|
+
deleteBlock: (o) => {
|
|
24
|
+
this.allBlocks.delete(o), this.options.onBlockDeleted && this.options.onBlockDeleted(o);
|
|
25
|
+
}
|
|
26
|
+
}, n = z(e.initialDoc, i, e.initialBlocks || []);
|
|
27
|
+
this.view = new h({
|
|
28
|
+
state: n,
|
|
29
|
+
parent: e.parent
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
addBlock() {
|
|
33
|
+
const e = {
|
|
34
|
+
id: Math.random().toString(36).substr(2, 9),
|
|
35
|
+
placeholder: "请输入编辑块内容为空时的提示文案",
|
|
36
|
+
presetText: ""
|
|
37
|
+
};
|
|
38
|
+
this.allBlocks.set(e.id, e);
|
|
39
|
+
const { from: i, to: n } = this.view.state.selection.main;
|
|
40
|
+
return this.view.dispatch({
|
|
41
|
+
changes: { from: i, to: n, insert: " " },
|
|
42
|
+
effects: g.of(e),
|
|
43
|
+
selection: { anchor: i + 1 }
|
|
44
|
+
}), this.view.focus(), e;
|
|
45
|
+
}
|
|
46
|
+
syncBlock(e) {
|
|
47
|
+
this.allBlocks.set(e.id, { ...e }), this.view.dispatch({
|
|
48
|
+
effects: w.of(e)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
getBlock(e) {
|
|
52
|
+
return this.allBlocks.get(e);
|
|
53
|
+
}
|
|
54
|
+
getData() {
|
|
55
|
+
return R(this.view, this.allBlocks);
|
|
56
|
+
}
|
|
57
|
+
destroy() {
|
|
58
|
+
this.view.destroy();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
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;
|
|
65
|
+
}
|
|
66
|
+
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;
|
|
76
|
+
};
|
|
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 }
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
}, i.appendChild(n), i;
|
|
101
|
+
}
|
|
102
|
+
ignoreEvent(e) {
|
|
103
|
+
return !0;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
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);
|
|
118
|
+
},
|
|
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);
|
|
138
|
+
},
|
|
139
|
+
add: [p.replace({
|
|
140
|
+
widget: new d(o, i)
|
|
141
|
+
}).range(c, c + 1)]
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
return t;
|
|
145
|
+
},
|
|
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 }
|
|
158
|
+
}), !0) : !1;
|
|
159
|
+
}, M = h.theme({
|
|
160
|
+
"&": { height: "100%", outline: "none" },
|
|
161
|
+
".cm-content": { padding: "20px", fontSize: "16px" },
|
|
162
|
+
".cm-line": { padding: "4px 0" },
|
|
163
|
+
".cm-inline-block": {
|
|
164
|
+
display: "inline-block",
|
|
165
|
+
backgroundColor: "#f3f0ff",
|
|
166
|
+
color: "#8066ff",
|
|
167
|
+
padding: "0 8px",
|
|
168
|
+
margin: "0 4px",
|
|
169
|
+
borderRadius: "4px",
|
|
170
|
+
cursor: "pointer",
|
|
171
|
+
border: "1px solid transparent",
|
|
172
|
+
transition: "all 0.2s",
|
|
173
|
+
fontSize: "15px",
|
|
174
|
+
verticalAlign: "middle"
|
|
175
|
+
},
|
|
176
|
+
".cm-inline-block:hover": {
|
|
177
|
+
backgroundColor: "#e9e4ff",
|
|
178
|
+
borderColor: "#8066ff"
|
|
179
|
+
},
|
|
180
|
+
".block-input": {
|
|
181
|
+
background: "transparent",
|
|
182
|
+
border: "none",
|
|
183
|
+
outline: "none",
|
|
184
|
+
color: "inherit",
|
|
185
|
+
font: "inherit",
|
|
186
|
+
padding: "4px 0",
|
|
187
|
+
width: "auto",
|
|
188
|
+
minWidth: "20px",
|
|
189
|
+
textAlign: "center"
|
|
190
|
+
},
|
|
191
|
+
".block-input::placeholder": {
|
|
192
|
+
color: "#b2a1ff",
|
|
193
|
+
opacity: 0.7
|
|
194
|
+
},
|
|
195
|
+
".cm-header-1": { fontSize: "1.5em", color: "#008c99", fontWeight: "bold" }
|
|
196
|
+
});
|
|
197
|
+
function z(t, e, i = []) {
|
|
198
|
+
const n = [
|
|
199
|
+
D(),
|
|
200
|
+
C.of([
|
|
201
|
+
...T,
|
|
202
|
+
...P,
|
|
203
|
+
{
|
|
204
|
+
key: "Backspace",
|
|
205
|
+
run: (c) => L(c, e)
|
|
206
|
+
}
|
|
207
|
+
]),
|
|
208
|
+
W({ base: F, codeLanguages: A }),
|
|
209
|
+
u.of(e),
|
|
210
|
+
B.of(i),
|
|
211
|
+
k,
|
|
212
|
+
M
|
|
213
|
+
];
|
|
214
|
+
return E.create({
|
|
215
|
+
doc: t,
|
|
216
|
+
extensions: n
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function q(t, e) {
|
|
220
|
+
return new h({
|
|
221
|
+
state: e,
|
|
222
|
+
parent: t
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function R(t, e) {
|
|
226
|
+
var o;
|
|
227
|
+
const i = t.state.doc.toString(), n = Array.from(e.values());
|
|
228
|
+
return {
|
|
229
|
+
json: {
|
|
230
|
+
content: i,
|
|
231
|
+
blocks: n
|
|
232
|
+
},
|
|
233
|
+
html: ((o = t.dom.querySelector(".cm-content")) == null ? void 0 : o.innerHTML) || ""
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
export {
|
|
237
|
+
j as CustomEditor,
|
|
238
|
+
g as addBlockEffect,
|
|
239
|
+
k as blockField,
|
|
240
|
+
z as createEditorState,
|
|
241
|
+
q as createEditorView,
|
|
242
|
+
M as editorTheme,
|
|
243
|
+
R as getEditorData,
|
|
244
|
+
w as updateBlockEffect
|
|
245
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
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"})});
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agent-arts/editor",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/editor.umd.cjs",
|
|
6
|
+
"module": "./dist/editor.js",
|
|
7
|
+
"types": "./dist/core.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/core.d.ts",
|
|
11
|
+
"import": "./dist/editor.js",
|
|
12
|
+
"require": "./dist/editor.umd.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"dev": "vite",
|
|
20
|
+
"build": "vite build",
|
|
21
|
+
"preview": "vite preview"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@codemirror/commands": "^6.3.3",
|
|
25
|
+
"@codemirror/lang-markdown": "^6.2.3",
|
|
26
|
+
"@codemirror/language-data": "^6.3.1",
|
|
27
|
+
"@codemirror/state": "^6.4.0",
|
|
28
|
+
"@codemirror/view": "^6.23.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"typescript": "^5.2.2",
|
|
32
|
+
"@types/node": "^20.11.0",
|
|
33
|
+
"vite": "^5.0.8",
|
|
34
|
+
"vite-plugin-dts": "^3.7.0"
|
|
35
|
+
}
|
|
36
|
+
}
|