@watalabs/lasee-mditor 0.0.0-stage → 0.2.0
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/README.md +252 -2
- package/dist/core.js +1 -0
- package/dist/html-BGPHBFj_.js +925 -0
- package/dist/index.js +4 -0
- package/dist/lasee-mditor.umd.js +177 -0
- package/dist/mditor-rUMGNL2Q.js +2847 -0
- package/dist/react.js +37 -0
- package/dist/rolldown-runtime-CGnMp29N.js +10 -0
- package/dist/style.css +990 -0
- package/dist/types/core/html.d.ts +15 -0
- package/dist/types/core/inline.d.ts +65 -0
- package/dist/types/core/parse.d.ts +32 -0
- package/dist/types/core/table.d.ts +10 -0
- package/dist/types/core/types.d.ts +74 -0
- package/dist/types/core/write.d.ts +12 -0
- package/dist/types/core.d.ts +6 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/pm/commands.d.ts +50 -0
- package/dist/types/pm/convert.d.ts +37 -0
- package/dist/types/pm/plugins.d.ts +83 -0
- package/dist/types/pm/schema.d.ts +15 -0
- package/dist/types/react.d.ts +32 -0
- package/dist/types/ui/dom.d.ts +30 -0
- package/dist/types/ui/icons.d.ts +5 -0
- package/dist/types/ui/mditor.d.ts +118 -0
- package/dist/types/ui/messages.d.ts +123 -0
- package/dist/types/ui/panels.d.ts +16 -0
- package/package.json +82 -4
|
@@ -0,0 +1,2847 @@
|
|
|
1
|
+
import { t as e } from "./rolldown-runtime-CGnMp29N.js";
|
|
2
|
+
import { A as t, C as n, I as r, L as i, N as a, O as o, P as s, R as c, S as l, T as u, V as d, a as f, c as p, g as m, j as h, k as g, m as _, p as v, v as ee, w as y, x as b, z as x } from "./html-BGPHBFj_.js";
|
|
3
|
+
import { Editor as te, Extension as S, InputRule as ne, Mark as C, Node as w, markInputRule as re, markPasteRule as ie, mergeAttributes as T } from "@tiptap/core";
|
|
4
|
+
import { Placeholder as ae } from "@tiptap/extensions";
|
|
5
|
+
import { Fragment as oe, Slice as se } from "@tiptap/pm/model";
|
|
6
|
+
import { Plugin as ce, PluginKey as le, TextSelection as ue } from "@tiptap/pm/state";
|
|
7
|
+
import { CellSelection as de, TableMap as fe, addRow as pe, mergeCells as me, selectedRect as he, tableEditingKey as ge } from "@tiptap/pm/tables";
|
|
8
|
+
import { Decoration as E, DecorationSet as D } from "@tiptap/pm/view";
|
|
9
|
+
import O from "@tiptap/extension-code";
|
|
10
|
+
import k from "@tiptap/extension-paragraph";
|
|
11
|
+
import { Table as _e, TableCell as ve, TableHeader as ye, TableRow as A } from "@tiptap/extension-table";
|
|
12
|
+
import be from "@tiptap/starter-kit";
|
|
13
|
+
// src/pm/commands.ts
|
|
14
|
+
var xe = /* @__PURE__ */ e({
|
|
15
|
+
addRowAbove: () => Ae,
|
|
16
|
+
addRowBelow: () => ke,
|
|
17
|
+
backspaceItem: () => F,
|
|
18
|
+
blockKind: () => Pe,
|
|
19
|
+
headRows: () => j,
|
|
20
|
+
insertPageBreak: () => Ve,
|
|
21
|
+
itemKind: () => Ie,
|
|
22
|
+
joinLists: () => Fe,
|
|
23
|
+
liftItem: () => Ne,
|
|
24
|
+
listKind: () => Le,
|
|
25
|
+
mergeSafe: () => we,
|
|
26
|
+
paragraphAlign: () => ze,
|
|
27
|
+
setBlockKind: () => I,
|
|
28
|
+
setColumnAlign: () => Ee,
|
|
29
|
+
setListKind: () => z,
|
|
30
|
+
setParagraphAlign: () => Be,
|
|
31
|
+
shiftItem: () => N,
|
|
32
|
+
splitItem: () => P,
|
|
33
|
+
toggleCellShade: () => De
|
|
34
|
+
}), Se = 3, Ce = [
|
|
35
|
+
"paragraph",
|
|
36
|
+
"docTitle",
|
|
37
|
+
"sectionHead",
|
|
38
|
+
"blockTitle",
|
|
39
|
+
"mdNote",
|
|
40
|
+
"codeBlock"
|
|
41
|
+
];
|
|
42
|
+
function j(e) {
|
|
43
|
+
let t = 0;
|
|
44
|
+
for (let n = 0; n < e.childCount; n++) {
|
|
45
|
+
let r = e.child(n), i = !0;
|
|
46
|
+
if (r.forEach((e) => {
|
|
47
|
+
e.type.name !== "tableHeader" && (i = !1);
|
|
48
|
+
}), !i) break;
|
|
49
|
+
t++;
|
|
50
|
+
}
|
|
51
|
+
return Math.max(1, t);
|
|
52
|
+
}
|
|
53
|
+
var we = (e, t) => {
|
|
54
|
+
if (!(e.selection instanceof de)) return !1;
|
|
55
|
+
let n = he(e), r = j(n.table);
|
|
56
|
+
return n.top < r && n.bottom > r ? !1 : me(e, t);
|
|
57
|
+
};
|
|
58
|
+
function Te(e) {
|
|
59
|
+
let t;
|
|
60
|
+
try {
|
|
61
|
+
t = he(e);
|
|
62
|
+
} catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
let n = /* @__PURE__ */ new Set(), r = [];
|
|
66
|
+
for (let e = 0; e < t.map.height; e++) for (let i = t.left; i < t.right; i++) {
|
|
67
|
+
let a = t.map.map[e * t.map.width + i];
|
|
68
|
+
if (n.has(a)) continue;
|
|
69
|
+
n.add(a);
|
|
70
|
+
let o = t.table.nodeAt(a);
|
|
71
|
+
o && r.push({
|
|
72
|
+
pos: t.tableStart + a,
|
|
73
|
+
node: o
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return r;
|
|
77
|
+
}
|
|
78
|
+
function Ee(e) {
|
|
79
|
+
return (t, n) => {
|
|
80
|
+
let r = Te(t);
|
|
81
|
+
if (!r?.length) return !1;
|
|
82
|
+
let i = r.every((t) => t.node.attrs.align === e) ? null : e;
|
|
83
|
+
if (n) {
|
|
84
|
+
let e = t.tr;
|
|
85
|
+
r.forEach((t) => e.setNodeMarkup(t.pos, void 0, {
|
|
86
|
+
...t.node.attrs,
|
|
87
|
+
align: i
|
|
88
|
+
})), n(e);
|
|
89
|
+
}
|
|
90
|
+
return !0;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
var De = (e, t) => {
|
|
94
|
+
let n = [], r = e.selection;
|
|
95
|
+
if (r instanceof de) r.forEachCell((e, t) => n.push({
|
|
96
|
+
pos: t,
|
|
97
|
+
node: e
|
|
98
|
+
}));
|
|
99
|
+
else {
|
|
100
|
+
let { $from: e } = r;
|
|
101
|
+
for (let t = e.depth; t > 0; t--) {
|
|
102
|
+
let r = e.node(t);
|
|
103
|
+
if (r.type.spec.tableRole === "cell" || r.type.spec.tableRole === "header_cell") {
|
|
104
|
+
n.push({
|
|
105
|
+
pos: e.before(t),
|
|
106
|
+
node: r
|
|
107
|
+
});
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!n.length) return !1;
|
|
113
|
+
let i = !n.every((e) => e.node.attrs.shade);
|
|
114
|
+
if (t) {
|
|
115
|
+
let r = e.tr;
|
|
116
|
+
n.forEach((e) => r.setNodeMarkup(e.pos, void 0, {
|
|
117
|
+
...e.node.attrs,
|
|
118
|
+
shade: i
|
|
119
|
+
})), t(r);
|
|
120
|
+
}
|
|
121
|
+
return !0;
|
|
122
|
+
};
|
|
123
|
+
function Oe(e) {
|
|
124
|
+
return (t, n) => {
|
|
125
|
+
let r;
|
|
126
|
+
try {
|
|
127
|
+
r = he(t);
|
|
128
|
+
} catch {
|
|
129
|
+
return !1;
|
|
130
|
+
}
|
|
131
|
+
if (n) {
|
|
132
|
+
let i = j(r.table), a = e === "below" ? r.bottom : r.top, o = pe(t.tr, r, a), s = o.doc.nodeAt(r.tableStart - 1);
|
|
133
|
+
if (s) {
|
|
134
|
+
let e = fe.get(s), n = t.schema.nodes.tableCell, c = Math.min(s.childCount - 1, a + (a + 1 < s.childCount ? 1 : -1)), l = /* @__PURE__ */ new Set();
|
|
135
|
+
for (let t = 0; t < e.width; t++) {
|
|
136
|
+
let u = e.map[a * e.width + t];
|
|
137
|
+
if (l.has(u)) continue;
|
|
138
|
+
l.add(u);
|
|
139
|
+
let d = s.nodeAt(u);
|
|
140
|
+
if (!d || e.findCell(u).top !== a) continue;
|
|
141
|
+
let f = c >= i && c !== a ? s.nodeAt(e.map[c * e.width + t]) : null, p = a >= i ? n : d.type;
|
|
142
|
+
o.setNodeMarkup(r.tableStart + u, p, {
|
|
143
|
+
...d.attrs,
|
|
144
|
+
align: f?.attrs.align ?? d.attrs.align
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
n(o);
|
|
149
|
+
}
|
|
150
|
+
return !0;
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
var ke = Oe("below"), Ae = Oe("above");
|
|
154
|
+
function je(e) {
|
|
155
|
+
let { $from: t } = e.selection;
|
|
156
|
+
if (t.parent.type.name !== "mdItem") return null;
|
|
157
|
+
let n = t.depth - 1;
|
|
158
|
+
return {
|
|
159
|
+
item: t.parent,
|
|
160
|
+
list: t.node(n),
|
|
161
|
+
listPos: t.before(n),
|
|
162
|
+
index: t.index(n),
|
|
163
|
+
offset: t.parentOffset
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function Me(e, t) {
|
|
167
|
+
let n = e.textBetween(0, e.content.size, " ", " ");
|
|
168
|
+
return n ? oe.from(t.text(n)) : oe.empty;
|
|
169
|
+
}
|
|
170
|
+
function M(e, t, n) {
|
|
171
|
+
return t.create(null, t.spec.marks === "" ? Me(e, n) : e.content);
|
|
172
|
+
}
|
|
173
|
+
function Ne(e = "paragraph") {
|
|
174
|
+
return (t, n) => {
|
|
175
|
+
let r = je(t);
|
|
176
|
+
if (!r) return !1;
|
|
177
|
+
let i = t.schema.nodes[e], a = [];
|
|
178
|
+
r.list.forEach((e) => a.push(e));
|
|
179
|
+
let o = a.slice(0, r.index), s = a.slice(r.index + 1), c = M(r.item, i, t.schema), l = [
|
|
180
|
+
...o.length ? [r.list.type.create(null, o)] : [],
|
|
181
|
+
c,
|
|
182
|
+
...s.length ? [r.list.type.create(null, s.map((e, t) => t === 0 ? e.type.create({
|
|
183
|
+
...e.attrs,
|
|
184
|
+
level: 0
|
|
185
|
+
}, e.content) : e))] : []
|
|
186
|
+
];
|
|
187
|
+
if (n) {
|
|
188
|
+
let e = t.tr.replaceWith(r.listPos, r.listPos + r.list.nodeSize, l), i = r.listPos + (o.length ? l[0].nodeSize : 0) + 1 + Math.min(r.offset, c.content.size);
|
|
189
|
+
n(e.setSelection(ue.create(e.doc, i)).scrollIntoView());
|
|
190
|
+
}
|
|
191
|
+
return !0;
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function N(e) {
|
|
195
|
+
return (t, n) => {
|
|
196
|
+
let r = je(t);
|
|
197
|
+
if (!r) return !1;
|
|
198
|
+
let { from: i, to: a } = t.selection;
|
|
199
|
+
if (n) {
|
|
200
|
+
let o = t.tr, s = r.listPos + 1, c = -1;
|
|
201
|
+
r.list.forEach((t) => {
|
|
202
|
+
let n = t.attrs.level;
|
|
203
|
+
s + t.nodeSize > i && s < a + 1 && (n = Math.max(0, Math.min(Se, n + e, c + 1)), n !== t.attrs.level && o.setNodeMarkup(s, void 0, {
|
|
204
|
+
...t.attrs,
|
|
205
|
+
level: n
|
|
206
|
+
})), c = n, s += t.nodeSize;
|
|
207
|
+
}), o.docChanged && n(o);
|
|
208
|
+
}
|
|
209
|
+
return !0;
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
var P = (e, t) => {
|
|
213
|
+
let { $from: n, $to: r, empty: i } = e.selection;
|
|
214
|
+
if (n.parent.type.name !== "mdItem" || !n.sameParent(r)) return !1;
|
|
215
|
+
let a = n.parent;
|
|
216
|
+
if (a.content.size === 0) return a.attrs.level > 0 ? N(-1)(e, t) : Ne()(e, t);
|
|
217
|
+
if (t) {
|
|
218
|
+
let r = e.tr;
|
|
219
|
+
i || r.deleteSelection();
|
|
220
|
+
let o = {
|
|
221
|
+
level: a.attrs.level,
|
|
222
|
+
ordered: a.attrs.ordered,
|
|
223
|
+
start: null,
|
|
224
|
+
checked: a.attrs.checked == null && null
|
|
225
|
+
};
|
|
226
|
+
r.split(r.mapping.map(n.pos), 1, [{
|
|
227
|
+
type: a.type,
|
|
228
|
+
attrs: o
|
|
229
|
+
}]), t(r.scrollIntoView());
|
|
230
|
+
}
|
|
231
|
+
return !0;
|
|
232
|
+
}, F = (e, t) => {
|
|
233
|
+
let n = je(e);
|
|
234
|
+
return !n || !e.selection.empty || n.offset !== 0 ? !1 : n.item.attrs.level > 0 ? N(-1)(e, t) : n.index === 0 && Ne()(e, t);
|
|
235
|
+
};
|
|
236
|
+
function Pe(e) {
|
|
237
|
+
let { $from: t } = e.selection;
|
|
238
|
+
if (t.depth === 0) return null;
|
|
239
|
+
let n = t.node(1);
|
|
240
|
+
return n.type.name === "mdList" ? "list" : Ce.includes(n.type.name) ? n.type.name : null;
|
|
241
|
+
}
|
|
242
|
+
function I(e) {
|
|
243
|
+
return (t, n) => {
|
|
244
|
+
let { $from: r, $to: i, from: a, to: o } = t.selection;
|
|
245
|
+
if (r.depth === 0 || i.depth === 0) return !1;
|
|
246
|
+
let { doc: s, schema: c } = t, l = r.index(0), u = i.index(0);
|
|
247
|
+
if (e === "docTitle" && (l !== 0 || u !== 0)) return !1;
|
|
248
|
+
let d = [], f = r.before(1), p = f;
|
|
249
|
+
for (let e = l; e <= u; e++) {
|
|
250
|
+
let t = s.child(e);
|
|
251
|
+
if (t.type.name === "mdList") {
|
|
252
|
+
let e = f + 1;
|
|
253
|
+
t.forEach((t) => {
|
|
254
|
+
d.push({
|
|
255
|
+
piece: {
|
|
256
|
+
item: !0,
|
|
257
|
+
node: t
|
|
258
|
+
},
|
|
259
|
+
selected: e + t.nodeSize > a && e < o + 1,
|
|
260
|
+
start: e
|
|
261
|
+
}), e += t.nodeSize;
|
|
262
|
+
});
|
|
263
|
+
} else d.push({
|
|
264
|
+
piece: {
|
|
265
|
+
item: !1,
|
|
266
|
+
node: t
|
|
267
|
+
},
|
|
268
|
+
selected: Ce.includes(t.type.name),
|
|
269
|
+
start: f
|
|
270
|
+
});
|
|
271
|
+
f += t.nodeSize;
|
|
272
|
+
}
|
|
273
|
+
let m = f, h = d.filter((e) => e.selected);
|
|
274
|
+
if (!h.length) return !1;
|
|
275
|
+
let g = h.every((t) => e === "list" ? t.piece.item : !t.piece.item && t.piece.node.type.name === e) ? "paragraph" : e, _ = c.nodes.mdItem, v = d.map((e) => e.selected ? g === "list" ? e.piece.item ? e.piece : {
|
|
276
|
+
item: !0,
|
|
277
|
+
node: _.create({ level: 0 }, e.piece.node.content)
|
|
278
|
+
} : {
|
|
279
|
+
item: !1,
|
|
280
|
+
node: M(e.piece.node, c.nodes[g], c)
|
|
281
|
+
} : e.piece), ee = [], y = [], b = [], x = p, te = () => {
|
|
282
|
+
if (!b.length) return;
|
|
283
|
+
let e = c.nodes.mdList.create(null, b);
|
|
284
|
+
ee.push(e), x += e.nodeSize, b = [];
|
|
285
|
+
};
|
|
286
|
+
for (let e of v) e.item ? (b.length || (x += 0), y.push(x + 1 + b.reduce((e, t) => e + t.nodeSize, 0) + 1), b.push(b.length ? e.node : e.node.type.create({
|
|
287
|
+
...e.node.attrs,
|
|
288
|
+
level: 0
|
|
289
|
+
}, e.node.content))) : (te(), y.push(x + 1), ee.push(e.node), x += e.node.nodeSize);
|
|
290
|
+
te();
|
|
291
|
+
let S;
|
|
292
|
+
try {
|
|
293
|
+
S = t.tr.replaceWith(p, m, ee), S.doc.check();
|
|
294
|
+
} catch {
|
|
295
|
+
return !1;
|
|
296
|
+
}
|
|
297
|
+
if (n) {
|
|
298
|
+
let e = (e, t) => {
|
|
299
|
+
let n = d.findIndex((t) => e >= t.start && e <= t.start + t.piece.node.nodeSize);
|
|
300
|
+
if (n < 0) return S.mapping.map(e, t);
|
|
301
|
+
let r = Math.max(0, e - d[n].start - 1);
|
|
302
|
+
return y[n] + Math.min(r, v[n].node.content.size);
|
|
303
|
+
}, t = e(a, -1), r = o === a ? t : e(o, 1);
|
|
304
|
+
try {
|
|
305
|
+
S.setSelection(ue.create(S.doc, Math.min(t, r), Math.max(t, r)));
|
|
306
|
+
} catch {
|
|
307
|
+
S.setSelection(ue.near(S.doc.resolve(Math.min(p + 1, S.doc.content.size))));
|
|
308
|
+
}
|
|
309
|
+
Fe(S), n(S.scrollIntoView());
|
|
310
|
+
}
|
|
311
|
+
return !0;
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
function Fe(e) {
|
|
315
|
+
for (;;) {
|
|
316
|
+
let t = -1, n = 0;
|
|
317
|
+
for (let r = 0; r < e.doc.childCount; r++) {
|
|
318
|
+
let i = e.doc.child(r);
|
|
319
|
+
if (r > 0 && i.type.name === "mdList" && e.doc.child(r - 1).type.name === "mdList") {
|
|
320
|
+
t = n;
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
n += i.nodeSize;
|
|
324
|
+
}
|
|
325
|
+
if (t < 0) return;
|
|
326
|
+
e.join(t);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
var L = {
|
|
330
|
+
bullet: (e) => ({
|
|
331
|
+
...e,
|
|
332
|
+
ordered: !1,
|
|
333
|
+
checked: null
|
|
334
|
+
}),
|
|
335
|
+
ordered: (e) => ({
|
|
336
|
+
...e,
|
|
337
|
+
ordered: !0,
|
|
338
|
+
checked: null
|
|
339
|
+
}),
|
|
340
|
+
task: (e) => ({
|
|
341
|
+
...e,
|
|
342
|
+
ordered: !1,
|
|
343
|
+
checked: e.checked ?? !1
|
|
344
|
+
})
|
|
345
|
+
};
|
|
346
|
+
function Ie(e) {
|
|
347
|
+
return e.attrs.checked == null ? e.attrs.ordered ? "ordered" : "bullet" : "task";
|
|
348
|
+
}
|
|
349
|
+
function R(e, t, n) {
|
|
350
|
+
let r = [];
|
|
351
|
+
return e.nodesBetween(t, n, (e, t) => e.type.name === "mdItem" ? (r.push({
|
|
352
|
+
pos: t,
|
|
353
|
+
node: e
|
|
354
|
+
}), !1) : e.type.name === "mdList" || e.type.name === "doc"), r;
|
|
355
|
+
}
|
|
356
|
+
function Le(e) {
|
|
357
|
+
let { $from: t } = e.selection;
|
|
358
|
+
return t.parent.type.name === "mdItem" ? Ie(t.parent) : null;
|
|
359
|
+
}
|
|
360
|
+
function z(e) {
|
|
361
|
+
return (t, n) => {
|
|
362
|
+
let { from: r, to: i } = t.selection, a = R(t.doc, r, i), o = a.length > 0;
|
|
363
|
+
if (t.doc.nodesBetween(r, i, (e) => (e.isTextblock && e.type.name !== "mdItem" && (o = !1), !e.isTextblock && e.type.name !== "table")), o && a.every((t) => Ie(t.node) === e)) return I("list")(t, n);
|
|
364
|
+
if (o) {
|
|
365
|
+
if (n) {
|
|
366
|
+
let r = t.tr;
|
|
367
|
+
a.forEach((t) => r.setNodeMarkup(t.pos, void 0, L[e](t.node.attrs))), n(r);
|
|
368
|
+
}
|
|
369
|
+
return !0;
|
|
370
|
+
}
|
|
371
|
+
let s = null;
|
|
372
|
+
if (!I("list")(t, (e) => s = e)) return !1;
|
|
373
|
+
if (n && s) {
|
|
374
|
+
let t = s;
|
|
375
|
+
R(t.doc, t.selection.from, t.selection.to).forEach((n) => t.setNodeMarkup(n.pos, void 0, L[e](n.node.attrs))), n(t);
|
|
376
|
+
}
|
|
377
|
+
return !0;
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
function Re(e) {
|
|
381
|
+
let t = [], { from: n, to: r } = e.selection;
|
|
382
|
+
return e.doc.nodesBetween(n, r, (e, n, r) => (e.type.name === "paragraph" && r?.type.name === "doc" && t.push({
|
|
383
|
+
pos: n,
|
|
384
|
+
node: e
|
|
385
|
+
}), r === null || e.type.name === "doc")), t;
|
|
386
|
+
}
|
|
387
|
+
function ze(e) {
|
|
388
|
+
let t = Re(e);
|
|
389
|
+
if (!t.length) return null;
|
|
390
|
+
let n = t[0].node.attrs.align ?? "left";
|
|
391
|
+
return t.every((e) => (e.node.attrs.align ?? "left") === n) ? n : null;
|
|
392
|
+
}
|
|
393
|
+
function Be(e) {
|
|
394
|
+
return (t, n) => {
|
|
395
|
+
let r = Re(t);
|
|
396
|
+
if (!r.length) return !1;
|
|
397
|
+
if (n) {
|
|
398
|
+
let i = t.tr, a = e === "left" ? null : e;
|
|
399
|
+
r.forEach((e) => i.setNodeMarkup(e.pos, void 0, {
|
|
400
|
+
...e.node.attrs,
|
|
401
|
+
align: a
|
|
402
|
+
})), n(i);
|
|
403
|
+
}
|
|
404
|
+
return !0;
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
var Ve = (e, t) => {
|
|
408
|
+
let n = e.schema.nodes.pageBreak;
|
|
409
|
+
if (!n) return !1;
|
|
410
|
+
let { $to: r } = e.selection, i = r.depth ? r.after(1) : r.pos;
|
|
411
|
+
if (t) {
|
|
412
|
+
let r = e.tr.insert(i, n.create()), a = i + 1;
|
|
413
|
+
(a >= r.doc.content.size || !r.doc.nodeAt(a)?.isTextblock) && r.insert(a, e.schema.nodes.paragraph.create()), r.setSelection(ue.near(r.doc.resolve(Math.min(a + 1, r.doc.content.size)))), t(r.scrollIntoView());
|
|
414
|
+
}
|
|
415
|
+
return !0;
|
|
416
|
+
};
|
|
417
|
+
// src/pm/convert.ts
|
|
418
|
+
function He(e) {
|
|
419
|
+
let t = [];
|
|
420
|
+
return e.link && t.push({
|
|
421
|
+
type: "link",
|
|
422
|
+
attrs: { href: e.link }
|
|
423
|
+
}), e.bold && t.push({ type: "bold" }), e.strike && t.push({ type: "strike" }), e.italic && t.push({ type: "italic" }), e.underline && t.push({ type: "underline" }), e.shade && t.push({ type: "mdShade" }), e.mark && t.push({ type: "mdHighlight" }), e.color && t.push({
|
|
424
|
+
type: "mdColor",
|
|
425
|
+
attrs: { name: e.color }
|
|
426
|
+
}), e.script === "sup" && t.push({ type: "superscript" }), e.script === "sub" && t.push({ type: "subscript" }), e.code && t.push({ type: "code" }), t.length ? t : void 0;
|
|
427
|
+
}
|
|
428
|
+
function B(e) {
|
|
429
|
+
let t = [];
|
|
430
|
+
for (let n of c(e)) {
|
|
431
|
+
let e = He(n);
|
|
432
|
+
n.text.split("\n").forEach((n, r) => {
|
|
433
|
+
r && t.push(e ? {
|
|
434
|
+
type: "hardBreak",
|
|
435
|
+
marks: e
|
|
436
|
+
} : { type: "hardBreak" }), n && t.push(e ? {
|
|
437
|
+
type: "text",
|
|
438
|
+
text: n,
|
|
439
|
+
marks: e
|
|
440
|
+
} : {
|
|
441
|
+
type: "text",
|
|
442
|
+
text: n
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
return t;
|
|
447
|
+
}
|
|
448
|
+
function V(e, t, n) {
|
|
449
|
+
let r = { type: e };
|
|
450
|
+
return n && (r.attrs = n), t.length && (r.content = t), r;
|
|
451
|
+
}
|
|
452
|
+
function Ue(e) {
|
|
453
|
+
let t = [];
|
|
454
|
+
for (let [n, r] of [[e.head, !0], [e.rows, !1]]) {
|
|
455
|
+
let i = b(n);
|
|
456
|
+
n.forEach((n, a) => {
|
|
457
|
+
let s = [];
|
|
458
|
+
n.forEach((t, n) => {
|
|
459
|
+
if (i[a][n].hidden) return;
|
|
460
|
+
let [c, l] = o(t);
|
|
461
|
+
s.push(V(r ? "tableHeader" : "tableCell", [V("paragraph", B(l))], {
|
|
462
|
+
colspan: i[a][n].colSpan,
|
|
463
|
+
rowspan: i[a][n].rowSpan,
|
|
464
|
+
shade: c,
|
|
465
|
+
align: e.align[n] ?? null
|
|
466
|
+
}));
|
|
467
|
+
}), t.push(V("tableRow", s));
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
return V("table", t, { align: e.align });
|
|
471
|
+
}
|
|
472
|
+
function We(e) {
|
|
473
|
+
switch (e.kind) {
|
|
474
|
+
case "text": return e.text ? V("paragraph", B(e.text), e.align ? { align: e.align } : void 0) : null;
|
|
475
|
+
case "list": return V("mdList", e.items.map((e) => V("mdItem", B(e.text), {
|
|
476
|
+
level: e.level,
|
|
477
|
+
ordered: !!e.ordered,
|
|
478
|
+
start: e.start ?? null,
|
|
479
|
+
checked: e.checked ?? null
|
|
480
|
+
})));
|
|
481
|
+
case "table": return Ue(e);
|
|
482
|
+
case "image": return V("mdImage", [], {
|
|
483
|
+
src: e.src,
|
|
484
|
+
caption: e.caption
|
|
485
|
+
});
|
|
486
|
+
case "code": return V("codeBlock", e.code ? [{
|
|
487
|
+
type: "text",
|
|
488
|
+
text: e.code
|
|
489
|
+
}] : [], { language: e.lang || null });
|
|
490
|
+
case "rule": return { type: "horizontalRule" };
|
|
491
|
+
case "pagebreak": return { type: "pageBreak" };
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function H(e) {
|
|
495
|
+
let t = [];
|
|
496
|
+
e.title && t.push(V("docTitle", B(e.title)));
|
|
497
|
+
let n = t.length;
|
|
498
|
+
return e.sections.forEach((e, n) => {
|
|
499
|
+
(e.title || n > 0) && t.push(V("sectionHead", B(e.title)));
|
|
500
|
+
for (let n of e.blocks) {
|
|
501
|
+
n.title && t.push(V("blockTitle", B(n.title)));
|
|
502
|
+
let e = We(n);
|
|
503
|
+
e && t.push(e);
|
|
504
|
+
for (let e of n.notes) t.push(V("mdNote", B(e)));
|
|
505
|
+
}
|
|
506
|
+
}), t.length === n && t.push({ type: "paragraph" }), {
|
|
507
|
+
type: "doc",
|
|
508
|
+
content: t
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
function Ge(e) {
|
|
512
|
+
let t = [];
|
|
513
|
+
for (let n of e ?? []) {
|
|
514
|
+
let e = { text: n.type === "hardBreak" ? "\n" : n.text ?? "" };
|
|
515
|
+
for (let t of n.marks ?? []) if (t.type === "link") {
|
|
516
|
+
let n = r(String(t.attrs?.href ?? ""));
|
|
517
|
+
n && (e.link = n);
|
|
518
|
+
} else t.type === "bold" ? e.bold = !0 : t.type === "strike" ? e.strike = !0 : t.type === "italic" ? e.italic = !0 : t.type === "underline" ? e.underline = !0 : t.type === "mdShade" ? e.shade = !0 : t.type === "mdHighlight" ? e.mark = !0 : t.type === "mdColor" ? e.color = String(t.attrs?.name ?? "빨강") : t.type === "superscript" ? e.script = "sup" : t.type === "subscript" ? e.script ??= "sub" : t.type === "code" && (e.code = !0);
|
|
519
|
+
t.push(e);
|
|
520
|
+
}
|
|
521
|
+
return t;
|
|
522
|
+
}
|
|
523
|
+
function U(e, t = null, n = "ko") {
|
|
524
|
+
return d(a(Ge(e)), t, n);
|
|
525
|
+
}
|
|
526
|
+
function Ke(e, t = "ko") {
|
|
527
|
+
return d(a(s(Ge(e))), null, t);
|
|
528
|
+
}
|
|
529
|
+
function qe(e, t = "ko") {
|
|
530
|
+
let n = x("음영", t), r = e.content ?? [], i = r.map(() => []), o = [], s = [];
|
|
531
|
+
r.forEach((e, c) => {
|
|
532
|
+
let l = e.content ?? [], u = c === 0 || s[c - 1];
|
|
533
|
+
s[c] = c === 0 || u && (!l.length || l.every((e) => e.type === "tableHeader"));
|
|
534
|
+
let f = 0;
|
|
535
|
+
for (let e of l) {
|
|
536
|
+
for (; i[c][f] !== void 0;) f++;
|
|
537
|
+
let l = Math.max(1, Number(e.attrs?.colspan ?? 1)), u = Math.max(1, Number(e.attrs?.rowspan ?? 1)), p = [];
|
|
538
|
+
(e.content ?? []).forEach((e, t) => {
|
|
539
|
+
t && p.push({ text: "\n" }), p.push(...Ge(e.content));
|
|
540
|
+
});
|
|
541
|
+
let m = d(a(p), "cell", t);
|
|
542
|
+
for (let t = 0; t < u && c + t < r.length; t++) for (let r = 0; r < l; r++) i[c + t][f + r] = t === 0 && r === 0 ? e.attrs?.shade ? `{${n}}${m}{/${n}}` : m : t === 0 ? "<" : "^";
|
|
543
|
+
!s[c] && l === 1 && (o[f] ??= []).push(e.attrs?.align ?? null), f += l;
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
let c = Math.max(1, ...i.map((e) => e.length)), l = s.filter(Boolean).length, u = i.map((e) => Array.from({ length: c }, (t, n) => e[n] ?? "")), f = e.attrs?.align ?? [], p = Array.from({ length: c }, (e, t) => {
|
|
547
|
+
let n = o[t];
|
|
548
|
+
if (!n?.length) return f[t] ?? null;
|
|
549
|
+
let r = /* @__PURE__ */ new Map();
|
|
550
|
+
n.forEach((e) => r.set(e, (r.get(e) ?? 0) + 1));
|
|
551
|
+
let i = n[0];
|
|
552
|
+
for (let [e, t] of r) t > (r.get(i) ?? 0) && (i = e);
|
|
553
|
+
return i;
|
|
554
|
+
});
|
|
555
|
+
return {
|
|
556
|
+
head: u.slice(0, l),
|
|
557
|
+
rows: u.slice(l),
|
|
558
|
+
align: p
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
function Je(e, t = "ko") {
|
|
562
|
+
let n = qe(e, t);
|
|
563
|
+
return p({
|
|
564
|
+
title: "",
|
|
565
|
+
sections: [{
|
|
566
|
+
key: "",
|
|
567
|
+
title: "",
|
|
568
|
+
blocks: [{
|
|
569
|
+
id: "",
|
|
570
|
+
kind: "table",
|
|
571
|
+
title: null,
|
|
572
|
+
notes: [],
|
|
573
|
+
...n
|
|
574
|
+
}]
|
|
575
|
+
}]
|
|
576
|
+
}, t).trimEnd().split("\n");
|
|
577
|
+
}
|
|
578
|
+
var Ye = /[`\s]/g;
|
|
579
|
+
function Xe(e, t = "ko", n) {
|
|
580
|
+
let i = "", a = 0, o = -1, s = (e = null) => ({
|
|
581
|
+
title: e,
|
|
582
|
+
block: null,
|
|
583
|
+
notes: [],
|
|
584
|
+
at: a,
|
|
585
|
+
itemAt: [],
|
|
586
|
+
tableAt: -1
|
|
587
|
+
}), c = [], l = "", d = [], f = null, p = 0, m = () => {
|
|
588
|
+
let e = f;
|
|
589
|
+
if (e) {
|
|
590
|
+
let t = e.block;
|
|
591
|
+
t?.kind === "list" && (t = {
|
|
592
|
+
...t,
|
|
593
|
+
items: v(e.items ?? [])
|
|
594
|
+
}), !t && (e.title || e.notes.length) && (t = {
|
|
595
|
+
kind: "text",
|
|
596
|
+
title: null,
|
|
597
|
+
text: "",
|
|
598
|
+
notes: []
|
|
599
|
+
}), t && (d.push({
|
|
600
|
+
...t,
|
|
601
|
+
id: `b${++p}`,
|
|
602
|
+
title: e.title,
|
|
603
|
+
notes: e.notes
|
|
604
|
+
}), n?.blocks.push({
|
|
605
|
+
node: e.at,
|
|
606
|
+
items: e.itemAt,
|
|
607
|
+
table: e.tableAt
|
|
608
|
+
}));
|
|
609
|
+
}
|
|
610
|
+
f = null;
|
|
611
|
+
}, h = () => {
|
|
612
|
+
m(), (l || d.length || c.length) && (c.push({
|
|
613
|
+
key: `s${c.length + 1}`,
|
|
614
|
+
title: l,
|
|
615
|
+
blocks: d
|
|
616
|
+
}), n?.sections.push(o)), d = [];
|
|
617
|
+
}, g = (e) => {
|
|
618
|
+
let t = f;
|
|
619
|
+
(!t || t.block || t.notes.length) && (m(), f = s());
|
|
620
|
+
let n = f;
|
|
621
|
+
return n.block = e, n;
|
|
622
|
+
};
|
|
623
|
+
return (e.content ?? []).forEach((e, n) => {
|
|
624
|
+
switch (a = n, e.type) {
|
|
625
|
+
case "docTitle":
|
|
626
|
+
n === 0 && (i = Ke(e.content, t));
|
|
627
|
+
break;
|
|
628
|
+
case "sectionHead":
|
|
629
|
+
h(), o = n, l = Ke(e.content, t);
|
|
630
|
+
break;
|
|
631
|
+
case "blockTitle":
|
|
632
|
+
m(), f = s(Ke(e.content, t) || null);
|
|
633
|
+
break;
|
|
634
|
+
case "paragraph": {
|
|
635
|
+
let n = U(e.content, "para", t), r = e.attrs?.align;
|
|
636
|
+
n && g({
|
|
637
|
+
kind: "text",
|
|
638
|
+
title: null,
|
|
639
|
+
text: n,
|
|
640
|
+
notes: [],
|
|
641
|
+
...r ? { align: r } : {}
|
|
642
|
+
});
|
|
643
|
+
break;
|
|
644
|
+
}
|
|
645
|
+
case "mdList":
|
|
646
|
+
(e.content ?? []).forEach((e, r) => {
|
|
647
|
+
let i = U(e.content, "item", t);
|
|
648
|
+
if (!i) return;
|
|
649
|
+
let a = f, o = a && a.block?.kind === "list" && !a.notes.length ? a : g({
|
|
650
|
+
kind: "list",
|
|
651
|
+
title: null,
|
|
652
|
+
items: [],
|
|
653
|
+
notes: []
|
|
654
|
+
});
|
|
655
|
+
(o.items ??= []).push({
|
|
656
|
+
text: i,
|
|
657
|
+
level: Math.min(3, Math.max(0, Number(e.attrs?.level ?? 0))),
|
|
658
|
+
ordered: !!e.attrs?.ordered,
|
|
659
|
+
num: e.attrs?.start == null ? 1 : Number(e.attrs.start),
|
|
660
|
+
checked: e.attrs?.checked == null ? null : !!e.attrs.checked
|
|
661
|
+
}), o.itemAt.push([n, r]);
|
|
662
|
+
});
|
|
663
|
+
break;
|
|
664
|
+
case "table":
|
|
665
|
+
g({
|
|
666
|
+
kind: "table",
|
|
667
|
+
title: null,
|
|
668
|
+
notes: [],
|
|
669
|
+
...qe(e, t)
|
|
670
|
+
}).tableAt = n;
|
|
671
|
+
break;
|
|
672
|
+
case "mdImage":
|
|
673
|
+
g({
|
|
674
|
+
kind: "image",
|
|
675
|
+
title: null,
|
|
676
|
+
notes: [],
|
|
677
|
+
src: r(String(e.attrs?.src ?? "")),
|
|
678
|
+
caption: _(e.attrs?.caption ?? "")
|
|
679
|
+
});
|
|
680
|
+
break;
|
|
681
|
+
case "codeBlock": {
|
|
682
|
+
let t = (e.content ?? []).map((e) => e.text ?? "").join("").split("\n");
|
|
683
|
+
for (; t.length && !r(t[t.length - 1]);) t.pop();
|
|
684
|
+
let n = r(String(e.attrs?.language ?? "")).split(u)[0]?.replace(Ye, "") ?? "";
|
|
685
|
+
g({
|
|
686
|
+
kind: "code",
|
|
687
|
+
title: null,
|
|
688
|
+
notes: [],
|
|
689
|
+
lang: n,
|
|
690
|
+
code: t.join("\n")
|
|
691
|
+
});
|
|
692
|
+
break;
|
|
693
|
+
}
|
|
694
|
+
case "horizontalRule":
|
|
695
|
+
g({
|
|
696
|
+
kind: "rule",
|
|
697
|
+
title: null,
|
|
698
|
+
notes: []
|
|
699
|
+
});
|
|
700
|
+
break;
|
|
701
|
+
case "pageBreak":
|
|
702
|
+
g({
|
|
703
|
+
kind: "pagebreak",
|
|
704
|
+
title: null,
|
|
705
|
+
notes: []
|
|
706
|
+
});
|
|
707
|
+
break;
|
|
708
|
+
case "mdNote": {
|
|
709
|
+
let n = U(e.content, null, t);
|
|
710
|
+
n && (f ??= s(), f.notes.push(n));
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}), h(), {
|
|
715
|
+
title: i,
|
|
716
|
+
sections: c,
|
|
717
|
+
dialect: t
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
function Ze(e, t = "ko") {
|
|
721
|
+
return p(Xe(e, t), t);
|
|
722
|
+
}
|
|
723
|
+
// src/pm/plugins.ts
|
|
724
|
+
function Qe(e) {
|
|
725
|
+
let t = /* @__PURE__ */ new Map(), n = [], r = -1;
|
|
726
|
+
return e.forEach((e, i) => {
|
|
727
|
+
if (e.type.name !== "mdList") {
|
|
728
|
+
n = [], r = -1;
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
let a = i + 1;
|
|
732
|
+
e.forEach((e) => {
|
|
733
|
+
let i = a;
|
|
734
|
+
if (a += e.nodeSize, !/\S/.test(e.textContent)) return;
|
|
735
|
+
let o = Math.max(0, Number(e.attrs.level) || 0), s = r < 0 ? 0 : Math.min(o, r + 1);
|
|
736
|
+
for (n = n.slice(0, s + 1); n.length < s + 1;) n.push(null);
|
|
737
|
+
if (e.attrs.ordered) {
|
|
738
|
+
let r = n[s], a = r === null ? Number(e.attrs.start ?? 1) : r + 1;
|
|
739
|
+
n[s] = a, t.set(i, a);
|
|
740
|
+
} else n[s] = null;
|
|
741
|
+
r = s;
|
|
742
|
+
});
|
|
743
|
+
}), t;
|
|
744
|
+
}
|
|
745
|
+
var W = new le("mdListNumbers"), $e = S.create({
|
|
746
|
+
name: "mdListNumbers",
|
|
747
|
+
addProseMirrorPlugins() {
|
|
748
|
+
let e = (e) => {
|
|
749
|
+
let t = [];
|
|
750
|
+
for (let [n, r] of Qe(e)) {
|
|
751
|
+
let i = e.nodeAt(n);
|
|
752
|
+
i && t.push(E.node(n, n + i.nodeSize, { "data-num": String(r) }));
|
|
753
|
+
}
|
|
754
|
+
return D.create(e, t);
|
|
755
|
+
};
|
|
756
|
+
return [new ce({
|
|
757
|
+
key: W,
|
|
758
|
+
state: {
|
|
759
|
+
init: (t, n) => e(n.doc),
|
|
760
|
+
apply: (t, n) => t.docChanged ? e(t.doc) : n
|
|
761
|
+
},
|
|
762
|
+
props: { decorations: (e) => W.getState(e) }
|
|
763
|
+
})];
|
|
764
|
+
}
|
|
765
|
+
}), G = new le("mdFind");
|
|
766
|
+
function K(e, t, n) {
|
|
767
|
+
let r = [];
|
|
768
|
+
if (!t) return r;
|
|
769
|
+
let i = n ? t : t.toLowerCase();
|
|
770
|
+
return e.descendants((e, t) => {
|
|
771
|
+
if (!e.isTextblock) return !0;
|
|
772
|
+
let a = "", o = [];
|
|
773
|
+
e.forEach((e, n) => {
|
|
774
|
+
if (e.isText) {
|
|
775
|
+
for (let r = 0; r < e.text.length; r++) o.push(t + 1 + n + r);
|
|
776
|
+
a += e.text;
|
|
777
|
+
} else o.push(-1), a += "\0";
|
|
778
|
+
});
|
|
779
|
+
let s = n ? a : a.toLowerCase(), c = s.indexOf(i);
|
|
780
|
+
for (; c >= 0;) {
|
|
781
|
+
let e = o[c], t = o[c + i.length - 1];
|
|
782
|
+
e >= 0 && t >= 0 && r.push({
|
|
783
|
+
from: e,
|
|
784
|
+
to: t + 1
|
|
785
|
+
}), c = s.indexOf(i, c + Math.max(1, i.length));
|
|
786
|
+
}
|
|
787
|
+
return !1;
|
|
788
|
+
}), r;
|
|
789
|
+
}
|
|
790
|
+
function et(e, t) {
|
|
791
|
+
let n = e.findIndex((e) => e.from >= t);
|
|
792
|
+
return n < 0 ? 0 : n;
|
|
793
|
+
}
|
|
794
|
+
var tt = S.create({
|
|
795
|
+
name: "mdFind",
|
|
796
|
+
addProseMirrorPlugins() {
|
|
797
|
+
return [new ce({
|
|
798
|
+
key: G,
|
|
799
|
+
state: {
|
|
800
|
+
init: () => ({
|
|
801
|
+
query: "",
|
|
802
|
+
caseSensitive: !1,
|
|
803
|
+
matches: [],
|
|
804
|
+
index: 0
|
|
805
|
+
}),
|
|
806
|
+
apply: (e, t, n, r) => {
|
|
807
|
+
let i = e.getMeta(G);
|
|
808
|
+
if (!i && !e.docChanged) return t;
|
|
809
|
+
let a = i?.query ?? t.query, o = i?.caseSensitive ?? t.caseSensitive, s = K(r.doc, a, o), c = i?.index ?? (i?.query === void 0 ? t.index : et(s, r.selection.from));
|
|
810
|
+
return c = s.length ? (c % s.length + s.length) % s.length : 0, {
|
|
811
|
+
query: a,
|
|
812
|
+
caseSensitive: o,
|
|
813
|
+
matches: s,
|
|
814
|
+
index: c
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
},
|
|
818
|
+
props: { decorations(e) {
|
|
819
|
+
let t = G.getState(e);
|
|
820
|
+
return t?.matches.length ? D.create(e.doc, t.matches.map((e, n) => E.inline(e.from, e.to, { class: n === t.index ? "mde-find-hit current" : "mde-find-hit" }))) : null;
|
|
821
|
+
} }
|
|
822
|
+
})];
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
function nt(e, t) {
|
|
826
|
+
return e.tr.setMeta(G, t).setMeta("addToHistory", !1);
|
|
827
|
+
}
|
|
828
|
+
function rt(e, t) {
|
|
829
|
+
let n = G.getState(e);
|
|
830
|
+
if (!n?.matches.length) return null;
|
|
831
|
+
let r = (n.index + t + n.matches.length) % n.matches.length, i = n.matches[r];
|
|
832
|
+
return e.tr.setMeta(G, { index: r }).setSelection(ue.create(e.doc, i.from, i.to)).scrollIntoView();
|
|
833
|
+
}
|
|
834
|
+
function it(e, t) {
|
|
835
|
+
let n = G.getState(e), r = n?.matches[n.index];
|
|
836
|
+
if (!r) return null;
|
|
837
|
+
let i = e.doc.resolve(r.from).marksAcross(e.doc.resolve(r.to)) ?? [], a = e.tr;
|
|
838
|
+
return t ? a.replaceWith(r.from, r.to, e.schema.text(t, i)) : a.delete(r.from, r.to), a.setMeta(G, { index: n.index }).scrollIntoView();
|
|
839
|
+
}
|
|
840
|
+
function at(e, t) {
|
|
841
|
+
let n = G.getState(e);
|
|
842
|
+
if (!n?.matches.length) return null;
|
|
843
|
+
let r = e.tr;
|
|
844
|
+
for (let i of [...n.matches].reverse()) {
|
|
845
|
+
let n = e.doc.resolve(i.from).marksAcross(e.doc.resolve(i.to)) ?? [];
|
|
846
|
+
t ? r.replaceWith(i.from, i.to, e.schema.text(t, n)) : r.delete(i.from, i.to);
|
|
847
|
+
}
|
|
848
|
+
return r.setMeta(G, { index: 0 });
|
|
849
|
+
}
|
|
850
|
+
function ot(e, t) {
|
|
851
|
+
let n = {
|
|
852
|
+
sections: [],
|
|
853
|
+
blocks: []
|
|
854
|
+
};
|
|
855
|
+
Xe(e.toJSON(), "ko", n);
|
|
856
|
+
let r = [];
|
|
857
|
+
e.forEach((e, t) => r.push(t));
|
|
858
|
+
let i = (t, n) => {
|
|
859
|
+
let i = e.child(t), a = r[t] + 1;
|
|
860
|
+
for (let e = 0; e < n && e < i.childCount; e++) a += i.child(e).nodeSize;
|
|
861
|
+
return a;
|
|
862
|
+
}, a = [];
|
|
863
|
+
for (let [e, i] of Object.entries(t.sections ?? {})) {
|
|
864
|
+
let t = n.sections[Number(e)];
|
|
865
|
+
t !== void 0 && t >= 0 && a.push({
|
|
866
|
+
pos: r[t],
|
|
867
|
+
page: i,
|
|
868
|
+
kind: "block",
|
|
869
|
+
width: 1
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
for (let [o, s] of Object.entries(t.blocks ?? {})) {
|
|
873
|
+
let t = n.blocks[Number(o)];
|
|
874
|
+
if (t) {
|
|
875
|
+
s.before && a.push({
|
|
876
|
+
pos: r[t.node],
|
|
877
|
+
page: s.before,
|
|
878
|
+
kind: "block",
|
|
879
|
+
width: 1
|
|
880
|
+
});
|
|
881
|
+
for (let [e, n] of Object.entries(s.items ?? {})) {
|
|
882
|
+
let r = t.items[Number(e)];
|
|
883
|
+
r && a.push({
|
|
884
|
+
pos: i(r[0], r[1]),
|
|
885
|
+
page: n,
|
|
886
|
+
kind: "item",
|
|
887
|
+
width: 1
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
if (t.table >= 0 && s.rows) {
|
|
891
|
+
let n = e.child(t.table), r = j(n), o = fe.get(n).width;
|
|
892
|
+
for (let [e, c] of Object.entries(s.rows)) {
|
|
893
|
+
let s = r + Number(e);
|
|
894
|
+
s < n.childCount && a.push({
|
|
895
|
+
pos: i(t.table, s),
|
|
896
|
+
page: c,
|
|
897
|
+
kind: "row",
|
|
898
|
+
width: o
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
return a.sort((e, t) => e.pos - t.pos || e.page - t.page);
|
|
905
|
+
}
|
|
906
|
+
var q = new le("mdPageMarks");
|
|
907
|
+
function st(e, t) {
|
|
908
|
+
let n = document.createElement("div");
|
|
909
|
+
n.className = "mde-pagemark", n.setAttribute("role", "separator"), n.setAttribute("aria-label", t(e.page)), n.dataset.page = String(e.page);
|
|
910
|
+
let r = document.createElement("span");
|
|
911
|
+
if (r.textContent = t(e.page), n.append(r), e.kind !== "row") return n;
|
|
912
|
+
let i = document.createElement("tr");
|
|
913
|
+
i.className = "mde-pagemark-row";
|
|
914
|
+
let a = document.createElement("td");
|
|
915
|
+
return a.colSpan = e.width, a.append(n), i.append(a), i;
|
|
916
|
+
}
|
|
917
|
+
var ct = S.create({
|
|
918
|
+
name: "mdPageMarks",
|
|
919
|
+
addOptions() {
|
|
920
|
+
return { label: (e) => String(e) };
|
|
921
|
+
},
|
|
922
|
+
addProseMirrorPlugins() {
|
|
923
|
+
let e = this.options.label, t = (t, n) => n.visible && n.marks ? D.create(t, ot(t, n.marks).map((t) => E.widget(t.pos, () => st(t, e), {
|
|
924
|
+
side: -1,
|
|
925
|
+
ignoreSelection: !0,
|
|
926
|
+
key: `page-${t.kind}-${t.page}-${t.width}`
|
|
927
|
+
}))) : D.empty;
|
|
928
|
+
return [new ce({
|
|
929
|
+
key: q,
|
|
930
|
+
state: {
|
|
931
|
+
init: () => ({
|
|
932
|
+
marks: null,
|
|
933
|
+
visible: !1,
|
|
934
|
+
deco: D.empty
|
|
935
|
+
}),
|
|
936
|
+
apply: (e, n, r, i) => {
|
|
937
|
+
let a = e.getMeta(q);
|
|
938
|
+
if (a) {
|
|
939
|
+
let e = {
|
|
940
|
+
...n,
|
|
941
|
+
...a
|
|
942
|
+
};
|
|
943
|
+
return {
|
|
944
|
+
...e,
|
|
945
|
+
deco: t(i.doc, e)
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
return e.docChanged ? {
|
|
949
|
+
...n,
|
|
950
|
+
deco: n.deco.map(e.mapping, e.doc)
|
|
951
|
+
} : n;
|
|
952
|
+
}
|
|
953
|
+
},
|
|
954
|
+
props: { decorations: (e) => q.getState(e)?.deco }
|
|
955
|
+
})];
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
function lt(e, t) {
|
|
959
|
+
return e.tr.setMeta(q, t).setMeta("addToHistory", !1);
|
|
960
|
+
}
|
|
961
|
+
var ut = S.create({
|
|
962
|
+
name: "mdCellSelectionGuard",
|
|
963
|
+
addProseMirrorPlugins() {
|
|
964
|
+
let e = 0;
|
|
965
|
+
return [new ce({
|
|
966
|
+
props: { handleDOMEvents: { mousedown: () => (e = 0, !1) } },
|
|
967
|
+
filterTransaction: (t, n) => n.selection instanceof de ? t.getMeta(ge) === -1 ? (e = Date.now(), !0) : !e || t.docChanged ? !0 : Date.now() - e > 300 ? (e = 0, !0) : !(t.getMeta("pointer") && t.selection.empty) : !0
|
|
968
|
+
})];
|
|
969
|
+
}
|
|
970
|
+
}), J = {
|
|
971
|
+
paragraph: "본문",
|
|
972
|
+
docTitle: "문서 제목",
|
|
973
|
+
sectionHead: "큰 제목",
|
|
974
|
+
blockTitle: "작은 제목",
|
|
975
|
+
list: "목록",
|
|
976
|
+
note: "비고",
|
|
977
|
+
codeBlock: "코드 블록",
|
|
978
|
+
tableOrImage: "표·그림",
|
|
979
|
+
blockKind: "블록 종류",
|
|
980
|
+
bold: "굵게",
|
|
981
|
+
italic: "기울임",
|
|
982
|
+
underline: "밑줄",
|
|
983
|
+
strike: "취소선",
|
|
984
|
+
code: "인라인 코드",
|
|
985
|
+
superscript: "위 첨자",
|
|
986
|
+
subscript: "아래 첨자",
|
|
987
|
+
highlight: "형광펜",
|
|
988
|
+
textColor: "글자 색 · 음영",
|
|
989
|
+
color: "글자 색",
|
|
990
|
+
defaultColor: "기본 색",
|
|
991
|
+
pickColor: "색 고르기",
|
|
992
|
+
colorCode: "색 코드",
|
|
993
|
+
apply: "입력",
|
|
994
|
+
shade: "음영",
|
|
995
|
+
removeFormat: "서식 지우기",
|
|
996
|
+
link: "링크",
|
|
997
|
+
linkUrl: "링크 주소",
|
|
998
|
+
linkText: "보일 글",
|
|
999
|
+
linkApply: "적용",
|
|
1000
|
+
linkRemove: "링크 빼기",
|
|
1001
|
+
linkOpen: "새 창에서 열기",
|
|
1002
|
+
linkInvalid: "http://, https://, mailto: 로 시작하는 주소나 상대 주소를 넣으세요.",
|
|
1003
|
+
bulletList: "글머리 목록",
|
|
1004
|
+
orderedList: "번호 목록",
|
|
1005
|
+
taskList: "할 일 목록",
|
|
1006
|
+
indent: "들여쓰기",
|
|
1007
|
+
outdent: "내어쓰기",
|
|
1008
|
+
align: "문단 정렬",
|
|
1009
|
+
alignLeft: "왼쪽 정렬",
|
|
1010
|
+
alignCenter: "가운데 정렬",
|
|
1011
|
+
alignRight: "오른쪽 정렬",
|
|
1012
|
+
alignJustify: "양쪽 정렬",
|
|
1013
|
+
insert: "넣기",
|
|
1014
|
+
table: "표",
|
|
1015
|
+
insertTable: "표 넣기",
|
|
1016
|
+
tableSize: "{rows} × {cols} 표",
|
|
1017
|
+
image: "이미지",
|
|
1018
|
+
insertImage: "이미지 넣기",
|
|
1019
|
+
imageUrl: "이미지 주소",
|
|
1020
|
+
imageUpload: "파일에서 고르기",
|
|
1021
|
+
imageCaption: "그림 설명",
|
|
1022
|
+
imageMissing: "그림 '{src}' 을 찾을 수 없습니다",
|
|
1023
|
+
horizontalRule: "가로줄",
|
|
1024
|
+
pageBreak: "쪽 나눔",
|
|
1025
|
+
specialChars: "특수 문자",
|
|
1026
|
+
codeLanguage: "언어",
|
|
1027
|
+
codeLanguageNone: "언어 없음",
|
|
1028
|
+
rowAbove: "위에 행",
|
|
1029
|
+
rowBelow: "아래에 행",
|
|
1030
|
+
colLeft: "왼쪽에 열",
|
|
1031
|
+
colRight: "오른쪽에 열",
|
|
1032
|
+
deleteRow: "행 지우기",
|
|
1033
|
+
deleteCol: "열 지우기",
|
|
1034
|
+
mergeCells: "칸 합치기",
|
|
1035
|
+
mergeHint: "칸을 끌어서 고른 뒤 누르세요",
|
|
1036
|
+
splitCell: "칸 나누기",
|
|
1037
|
+
cellShade: "칸 음영",
|
|
1038
|
+
colLeftAlign: "왼쪽",
|
|
1039
|
+
colCenterAlign: "가운데",
|
|
1040
|
+
colRightAlign: "오른쪽",
|
|
1041
|
+
colAlignTitle: "열 {side} 정렬",
|
|
1042
|
+
deleteTable: "표 지우기",
|
|
1043
|
+
find: "찾기",
|
|
1044
|
+
findReplace: "찾아 바꾸기",
|
|
1045
|
+
findPlaceholder: "찾을 글",
|
|
1046
|
+
replacePlaceholder: "바꿀 글",
|
|
1047
|
+
findPrev: "이전",
|
|
1048
|
+
findNext: "다음",
|
|
1049
|
+
replace: "바꾸기",
|
|
1050
|
+
replaceAll: "모두 바꾸기",
|
|
1051
|
+
matchCase: "대소문자 구분",
|
|
1052
|
+
findCount: "{n}개 중 {i}",
|
|
1053
|
+
findNone: "없음",
|
|
1054
|
+
close: "닫기",
|
|
1055
|
+
undo: "되돌리기",
|
|
1056
|
+
redo: "다시 하기",
|
|
1057
|
+
source: "MD 원문",
|
|
1058
|
+
sourceBack: "문서로 보기",
|
|
1059
|
+
preview: "미리보기",
|
|
1060
|
+
previewOn: "미리보기 켜기",
|
|
1061
|
+
previewOff: "미리보기 끄기",
|
|
1062
|
+
fullscreen: "전체 화면",
|
|
1063
|
+
pageMarks: "자동 쪽 나눔",
|
|
1064
|
+
pageLabel: "{n}쪽",
|
|
1065
|
+
pagesTotal: "전체 {n}쪽",
|
|
1066
|
+
fullscreenExit: "전체 화면 끝내기",
|
|
1067
|
+
more: "더 보기",
|
|
1068
|
+
toolbar: "문서 서식",
|
|
1069
|
+
tableToolbar: "표",
|
|
1070
|
+
editorLabel: "문서 편집",
|
|
1071
|
+
sourceLabel: "Markdown 원본",
|
|
1072
|
+
previewLabel: "미리보기",
|
|
1073
|
+
chars: "글자 {n}",
|
|
1074
|
+
words: "단어 {n}",
|
|
1075
|
+
sourceError: "MD 를 문서로 열 수 없습니다 — {line}번째 줄: {message}",
|
|
1076
|
+
sourceErrorNoLine: "MD 를 문서로 열 수 없습니다 — {message}",
|
|
1077
|
+
"table-no-delim": "표에 구분선(|---|) 줄이 없습니다. 머리글 줄 바로 아래에 넣으세요.",
|
|
1078
|
+
"table-no-head": "구분선(|---|) 위에 머리글 줄이 없습니다.",
|
|
1079
|
+
"table-too-wide": "표는 {max}칸까지 쓸 수 있습니다(지금 {width}칸).",
|
|
1080
|
+
"table-row-too-long": "이 줄은 {cells}칸인데 머리글은 {width}칸입니다.",
|
|
1081
|
+
placeholder: "",
|
|
1082
|
+
tooLong: "붙여 넣을 글이 너무 깁니다. 문서는 {max}자까지 쓸 수 있습니다(붙이면 {length}자).",
|
|
1083
|
+
pasteTooLong: "한 번에 붙여 넣을 수 있는 글은 {max}자까지입니다(지금 {length}자). 나눠서 붙여 넣으세요.",
|
|
1084
|
+
shortcut: "{label} ({key})"
|
|
1085
|
+
}, dt = {
|
|
1086
|
+
paragraph: "Body",
|
|
1087
|
+
docTitle: "Document title",
|
|
1088
|
+
sectionHead: "Heading",
|
|
1089
|
+
blockTitle: "Subheading",
|
|
1090
|
+
list: "List",
|
|
1091
|
+
note: "Note",
|
|
1092
|
+
codeBlock: "Code block",
|
|
1093
|
+
tableOrImage: "Table · image",
|
|
1094
|
+
blockKind: "Block type",
|
|
1095
|
+
bold: "Bold",
|
|
1096
|
+
italic: "Italic",
|
|
1097
|
+
underline: "Underline",
|
|
1098
|
+
strike: "Strikethrough",
|
|
1099
|
+
code: "Inline code",
|
|
1100
|
+
superscript: "Superscript",
|
|
1101
|
+
subscript: "Subscript",
|
|
1102
|
+
highlight: "Highlight",
|
|
1103
|
+
textColor: "Text color · shade",
|
|
1104
|
+
color: "Text color",
|
|
1105
|
+
defaultColor: "Default color",
|
|
1106
|
+
pickColor: "Pick a color",
|
|
1107
|
+
colorCode: "Color code",
|
|
1108
|
+
apply: "Apply",
|
|
1109
|
+
shade: "Shade",
|
|
1110
|
+
removeFormat: "Clear formatting",
|
|
1111
|
+
link: "Link",
|
|
1112
|
+
linkUrl: "Link address",
|
|
1113
|
+
linkText: "Text to show",
|
|
1114
|
+
linkApply: "Apply",
|
|
1115
|
+
linkRemove: "Remove link",
|
|
1116
|
+
linkOpen: "Open in new tab",
|
|
1117
|
+
linkInvalid: "Enter an address starting with http://, https://, mailto: or a relative path.",
|
|
1118
|
+
bulletList: "Bulleted list",
|
|
1119
|
+
orderedList: "Numbered list",
|
|
1120
|
+
taskList: "To-do list",
|
|
1121
|
+
indent: "Increase indent",
|
|
1122
|
+
outdent: "Decrease indent",
|
|
1123
|
+
align: "Paragraph alignment",
|
|
1124
|
+
alignLeft: "Align left",
|
|
1125
|
+
alignCenter: "Align center",
|
|
1126
|
+
alignRight: "Align right",
|
|
1127
|
+
alignJustify: "Justify",
|
|
1128
|
+
insert: "Insert",
|
|
1129
|
+
table: "Table",
|
|
1130
|
+
insertTable: "Insert table",
|
|
1131
|
+
tableSize: "{rows} × {cols} table",
|
|
1132
|
+
image: "Image",
|
|
1133
|
+
insertImage: "Insert image",
|
|
1134
|
+
imageUrl: "Image address",
|
|
1135
|
+
imageUpload: "Choose a file",
|
|
1136
|
+
imageCaption: "Caption",
|
|
1137
|
+
imageMissing: "Image '{src}' not found",
|
|
1138
|
+
horizontalRule: "Horizontal line",
|
|
1139
|
+
pageBreak: "Page break",
|
|
1140
|
+
specialChars: "Special characters",
|
|
1141
|
+
codeLanguage: "Language",
|
|
1142
|
+
codeLanguageNone: "No language",
|
|
1143
|
+
rowAbove: "Row above",
|
|
1144
|
+
rowBelow: "Row below",
|
|
1145
|
+
colLeft: "Column left",
|
|
1146
|
+
colRight: "Column right",
|
|
1147
|
+
deleteRow: "Delete row",
|
|
1148
|
+
deleteCol: "Delete column",
|
|
1149
|
+
mergeCells: "Merge cells",
|
|
1150
|
+
mergeHint: "Drag across cells, then click",
|
|
1151
|
+
splitCell: "Split cell",
|
|
1152
|
+
cellShade: "Cell shade",
|
|
1153
|
+
colLeftAlign: "Left",
|
|
1154
|
+
colCenterAlign: "Center",
|
|
1155
|
+
colRightAlign: "Right",
|
|
1156
|
+
colAlignTitle: "Align column {side}",
|
|
1157
|
+
deleteTable: "Delete table",
|
|
1158
|
+
find: "Find",
|
|
1159
|
+
findReplace: "Find and replace",
|
|
1160
|
+
findPlaceholder: "Find",
|
|
1161
|
+
replacePlaceholder: "Replace with",
|
|
1162
|
+
findPrev: "Previous",
|
|
1163
|
+
findNext: "Next",
|
|
1164
|
+
replace: "Replace",
|
|
1165
|
+
replaceAll: "Replace all",
|
|
1166
|
+
matchCase: "Match case",
|
|
1167
|
+
findCount: "{i} of {n}",
|
|
1168
|
+
findNone: "No results",
|
|
1169
|
+
close: "Close",
|
|
1170
|
+
undo: "Undo",
|
|
1171
|
+
redo: "Redo",
|
|
1172
|
+
source: "MD source",
|
|
1173
|
+
sourceBack: "Back to document",
|
|
1174
|
+
preview: "Preview",
|
|
1175
|
+
previewOn: "Show preview",
|
|
1176
|
+
previewOff: "Hide preview",
|
|
1177
|
+
fullscreen: "Full screen",
|
|
1178
|
+
pageMarks: "Automatic page breaks",
|
|
1179
|
+
pageLabel: "Page {n}",
|
|
1180
|
+
pagesTotal: "{n} pages",
|
|
1181
|
+
fullscreenExit: "Exit full screen",
|
|
1182
|
+
more: "More",
|
|
1183
|
+
toolbar: "Formatting",
|
|
1184
|
+
tableToolbar: "Table",
|
|
1185
|
+
editorLabel: "Document editor",
|
|
1186
|
+
sourceLabel: "Markdown source",
|
|
1187
|
+
previewLabel: "Preview",
|
|
1188
|
+
chars: "{n} characters",
|
|
1189
|
+
words: "{n} words",
|
|
1190
|
+
sourceError: "Can’t open the MD as a document — line {line}: {message}",
|
|
1191
|
+
sourceErrorNoLine: "Can’t open the MD as a document — {message}",
|
|
1192
|
+
"table-no-delim": "The table has no separator row (|---|). Put it right below the header row.",
|
|
1193
|
+
"table-no-head": "There is no header row above the separator row (|---|).",
|
|
1194
|
+
"table-too-wide": "Tables can have up to {max} columns (this one has {width}).",
|
|
1195
|
+
"table-row-too-long": "This row has {cells} cells but the header has {width}.",
|
|
1196
|
+
placeholder: "",
|
|
1197
|
+
tooLong: "That paste is too long. Documents can have up to {max} characters (it would be {length}).",
|
|
1198
|
+
pasteTooLong: "You can paste up to {max} characters at a time (this is {length}). Paste it in parts.",
|
|
1199
|
+
shortcut: "{label} ({key})"
|
|
1200
|
+
}, Y = {
|
|
1201
|
+
ko: J,
|
|
1202
|
+
en: dt
|
|
1203
|
+
};
|
|
1204
|
+
function X(e, t) {
|
|
1205
|
+
return t ? e.replace(/\{(\w+)\}/g, (e, n) => n in t ? String(t[n]) : e) : e;
|
|
1206
|
+
}
|
|
1207
|
+
function ft(e = "ko", t) {
|
|
1208
|
+
return {
|
|
1209
|
+
...Y[e] ?? J,
|
|
1210
|
+
...t ?? {}
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
var pt = w.create({
|
|
1214
|
+
name: "doc",
|
|
1215
|
+
topNode: !0,
|
|
1216
|
+
content: "docTitle? (paragraph | sectionHead | blockTitle | mdList | table | mdNote | mdImage | codeBlock | horizontalRule | pageBreak)+"
|
|
1217
|
+
});
|
|
1218
|
+
function Z(e, t) {
|
|
1219
|
+
return w.create({
|
|
1220
|
+
name: e,
|
|
1221
|
+
content: "text*",
|
|
1222
|
+
defining: !0,
|
|
1223
|
+
parseHTML() {
|
|
1224
|
+
return [{ tag: t }];
|
|
1225
|
+
},
|
|
1226
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
1227
|
+
return [
|
|
1228
|
+
t,
|
|
1229
|
+
T(e, { class: `md-${t}` }),
|
|
1230
|
+
0
|
|
1231
|
+
];
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
var mt = Z("docTitle", "h1"), ht = Z("sectionHead", "h2"), gt = w.create({
|
|
1236
|
+
name: "blockTitle",
|
|
1237
|
+
content: "text*",
|
|
1238
|
+
defining: !0,
|
|
1239
|
+
parseHTML() {
|
|
1240
|
+
return [
|
|
1241
|
+
{ tag: "h3" },
|
|
1242
|
+
{ tag: "h4" },
|
|
1243
|
+
{ tag: "h5" },
|
|
1244
|
+
{ tag: "h6" }
|
|
1245
|
+
];
|
|
1246
|
+
},
|
|
1247
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
1248
|
+
return [
|
|
1249
|
+
"h3",
|
|
1250
|
+
T(e, { class: "md-h3" }),
|
|
1251
|
+
0
|
|
1252
|
+
];
|
|
1253
|
+
}
|
|
1254
|
+
}), _t = [
|
|
1255
|
+
"center",
|
|
1256
|
+
"right",
|
|
1257
|
+
"justify"
|
|
1258
|
+
], vt = k.extend({ addAttributes() {
|
|
1259
|
+
return { align: {
|
|
1260
|
+
default: null,
|
|
1261
|
+
parseHTML: (e) => {
|
|
1262
|
+
let t = e.style.textAlign || e.getAttribute("align");
|
|
1263
|
+
return t && _t.includes(t) ? t : null;
|
|
1264
|
+
},
|
|
1265
|
+
renderHTML: (e) => e.align ? {
|
|
1266
|
+
style: `text-align:${e.align}`,
|
|
1267
|
+
"data-align": e.align
|
|
1268
|
+
} : {}
|
|
1269
|
+
} };
|
|
1270
|
+
} }), yt = w.create({
|
|
1271
|
+
name: "mdList",
|
|
1272
|
+
group: "block",
|
|
1273
|
+
content: "mdItem+",
|
|
1274
|
+
parseHTML() {
|
|
1275
|
+
return [{ tag: "ul" }, { tag: "ol" }];
|
|
1276
|
+
},
|
|
1277
|
+
renderHTML() {
|
|
1278
|
+
return [
|
|
1279
|
+
"ul",
|
|
1280
|
+
{ class: "md-list" },
|
|
1281
|
+
0
|
|
1282
|
+
];
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1285
|
+
function bt(e) {
|
|
1286
|
+
let t = e.getAttribute("data-level");
|
|
1287
|
+
if (t !== null) return Math.min(3, Math.max(0, Number(t) || 0));
|
|
1288
|
+
let n = -1;
|
|
1289
|
+
for (let t = e.parentElement; t; t = t.parentElement) (t.tagName === "UL" || t.tagName === "OL") && n++;
|
|
1290
|
+
return Math.min(3, Math.max(0, n));
|
|
1291
|
+
}
|
|
1292
|
+
function xt(e) {
|
|
1293
|
+
let t = e.getAttribute("data-checked");
|
|
1294
|
+
if (t !== null) return t === "true";
|
|
1295
|
+
let n = e.querySelector(":scope > input[type=checkbox], :scope > label > input[type=checkbox], :scope > p > input[type=checkbox]");
|
|
1296
|
+
return n ? n.checked || n.hasAttribute("checked") : null;
|
|
1297
|
+
}
|
|
1298
|
+
var St = w.create({
|
|
1299
|
+
name: "mdItem",
|
|
1300
|
+
content: "inline*",
|
|
1301
|
+
defining: !0,
|
|
1302
|
+
addOptions() {
|
|
1303
|
+
return { messages: J };
|
|
1304
|
+
},
|
|
1305
|
+
addAttributes() {
|
|
1306
|
+
return {
|
|
1307
|
+
level: {
|
|
1308
|
+
default: 0,
|
|
1309
|
+
parseHTML: (e) => bt(e),
|
|
1310
|
+
renderHTML: (e) => ({ "data-level": e.level })
|
|
1311
|
+
},
|
|
1312
|
+
ordered: {
|
|
1313
|
+
default: !1,
|
|
1314
|
+
parseHTML: (e) => e.getAttribute("data-ordered") === "true" || e.parentElement?.tagName === "OL",
|
|
1315
|
+
renderHTML: (e) => e.ordered ? { "data-ordered": "true" } : {}
|
|
1316
|
+
},
|
|
1317
|
+
start: {
|
|
1318
|
+
default: null,
|
|
1319
|
+
parseHTML: (e) => {
|
|
1320
|
+
let t = e.getAttribute("data-start");
|
|
1321
|
+
if (t) return Number(t) || null;
|
|
1322
|
+
let n = e.parentElement;
|
|
1323
|
+
return n?.tagName === "OL" && n.firstElementChild === e && n.hasAttribute("start") && Number(n.getAttribute("start")) || null;
|
|
1324
|
+
},
|
|
1325
|
+
renderHTML: (e) => e.start == null ? {} : { "data-start": e.start }
|
|
1326
|
+
},
|
|
1327
|
+
checked: {
|
|
1328
|
+
default: null,
|
|
1329
|
+
parseHTML: (e) => xt(e),
|
|
1330
|
+
renderHTML: (e) => e.checked == null ? {} : { "data-checked": e.checked ? "true" : "false" }
|
|
1331
|
+
}
|
|
1332
|
+
};
|
|
1333
|
+
},
|
|
1334
|
+
parseHTML() {
|
|
1335
|
+
return [{ tag: "li" }];
|
|
1336
|
+
},
|
|
1337
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
1338
|
+
return [
|
|
1339
|
+
"li",
|
|
1340
|
+
e,
|
|
1341
|
+
0
|
|
1342
|
+
];
|
|
1343
|
+
},
|
|
1344
|
+
addNodeView() {
|
|
1345
|
+
return ({ node: e, getPos: t, editor: n }) => {
|
|
1346
|
+
let r = e, i = document.createElement("li"), a = document.createElement("span");
|
|
1347
|
+
a.className = "md-check", a.contentEditable = "false", a.setAttribute("role", "checkbox");
|
|
1348
|
+
let o = document.createElement("div");
|
|
1349
|
+
o.className = "md-item-body", i.append(a, o);
|
|
1350
|
+
let s = () => {
|
|
1351
|
+
let e = r.attrs;
|
|
1352
|
+
i.setAttribute("data-level", String(e.level)), e.ordered ? i.setAttribute("data-ordered", "true") : i.removeAttribute("data-ordered"), e.checked == null ? (i.removeAttribute("data-checked"), a.hidden = !0) : (i.setAttribute("data-checked", e.checked ? "true" : "false"), a.hidden = !1, a.setAttribute("aria-checked", e.checked ? "true" : "false"));
|
|
1353
|
+
};
|
|
1354
|
+
return a.addEventListener("mousedown", (e) => {
|
|
1355
|
+
e.preventDefault();
|
|
1356
|
+
let i = typeof t == "function" ? t() : void 0;
|
|
1357
|
+
i !== void 0 && n.isEditable && n.view.dispatch(n.state.tr.setNodeMarkup(i, void 0, {
|
|
1358
|
+
...r.attrs,
|
|
1359
|
+
checked: !r.attrs.checked
|
|
1360
|
+
}));
|
|
1361
|
+
}), s(), {
|
|
1362
|
+
dom: i,
|
|
1363
|
+
contentDOM: o,
|
|
1364
|
+
update(e) {
|
|
1365
|
+
return e.type === r.type && (r = e, s(), !0);
|
|
1366
|
+
},
|
|
1367
|
+
ignoreMutation: (e) => e.type === "attributes" || e.target instanceof globalThis.Node && a.contains(e.target)
|
|
1368
|
+
};
|
|
1369
|
+
};
|
|
1370
|
+
},
|
|
1371
|
+
addKeyboardShortcuts() {
|
|
1372
|
+
let e = (e) => () => e(this.editor.state, this.editor.view.dispatch);
|
|
1373
|
+
return {
|
|
1374
|
+
Enter: e(P),
|
|
1375
|
+
Tab: e(N(1)),
|
|
1376
|
+
"Shift-Tab": e(N(-1)),
|
|
1377
|
+
Backspace: e(F)
|
|
1378
|
+
};
|
|
1379
|
+
}
|
|
1380
|
+
}), Ct = w.create({
|
|
1381
|
+
name: "mdNote",
|
|
1382
|
+
group: "block",
|
|
1383
|
+
content: "inline*",
|
|
1384
|
+
defining: !0,
|
|
1385
|
+
parseHTML() {
|
|
1386
|
+
return [
|
|
1387
|
+
{
|
|
1388
|
+
tag: "blockquote > p",
|
|
1389
|
+
priority: 60
|
|
1390
|
+
},
|
|
1391
|
+
{
|
|
1392
|
+
tag: "blockquote",
|
|
1393
|
+
getAttrs: (e) => !e.querySelector("p") && null
|
|
1394
|
+
},
|
|
1395
|
+
{
|
|
1396
|
+
tag: "blockquote",
|
|
1397
|
+
skip: !0
|
|
1398
|
+
}
|
|
1399
|
+
];
|
|
1400
|
+
},
|
|
1401
|
+
renderHTML() {
|
|
1402
|
+
return [
|
|
1403
|
+
"blockquote",
|
|
1404
|
+
{ class: "md-note" },
|
|
1405
|
+
0
|
|
1406
|
+
];
|
|
1407
|
+
},
|
|
1408
|
+
addKeyboardShortcuts() {
|
|
1409
|
+
return { Enter: () => {
|
|
1410
|
+
let { $from: e, empty: t } = this.editor.state.selection;
|
|
1411
|
+
return !t || e.parent.type.name !== "mdNote" || e.parent.content.size ? !1 : this.editor.commands.setNode("paragraph");
|
|
1412
|
+
} };
|
|
1413
|
+
}
|
|
1414
|
+
}), wt = w.create({
|
|
1415
|
+
name: "mdImage",
|
|
1416
|
+
group: "block",
|
|
1417
|
+
atom: !0,
|
|
1418
|
+
draggable: !0,
|
|
1419
|
+
addOptions() {
|
|
1420
|
+
return {
|
|
1421
|
+
resolve: () => void 0,
|
|
1422
|
+
messages: J
|
|
1423
|
+
};
|
|
1424
|
+
},
|
|
1425
|
+
addAttributes() {
|
|
1426
|
+
return {
|
|
1427
|
+
src: {
|
|
1428
|
+
default: "",
|
|
1429
|
+
parseHTML: (e) => e.getAttribute("data-src") ?? e.querySelector("img")?.getAttribute("src") ?? ""
|
|
1430
|
+
},
|
|
1431
|
+
caption: {
|
|
1432
|
+
default: "",
|
|
1433
|
+
parseHTML: (e) => e.getAttribute("data-caption") ?? e.querySelector("figcaption")?.textContent ?? e.querySelector("img")?.getAttribute("alt") ?? ""
|
|
1434
|
+
}
|
|
1435
|
+
};
|
|
1436
|
+
},
|
|
1437
|
+
parseHTML() {
|
|
1438
|
+
return [{ tag: "figure[data-src]" }, {
|
|
1439
|
+
tag: "figure",
|
|
1440
|
+
getAttrs: (e) => e.querySelector("img") ? null : !1
|
|
1441
|
+
}];
|
|
1442
|
+
},
|
|
1443
|
+
renderHTML({ node: e }) {
|
|
1444
|
+
return ["figure", {
|
|
1445
|
+
class: "md-image",
|
|
1446
|
+
"data-src": e.attrs.src,
|
|
1447
|
+
"data-caption": e.attrs.caption
|
|
1448
|
+
}];
|
|
1449
|
+
},
|
|
1450
|
+
addNodeView() {
|
|
1451
|
+
return ({ node: e, getPos: t, editor: n }) => {
|
|
1452
|
+
let r = this.options.messages, i = e, a = document.createElement("figure");
|
|
1453
|
+
a.className = "md-image";
|
|
1454
|
+
let o = document.createElement("img"), s = document.createElement("div");
|
|
1455
|
+
s.className = "md-image-missing";
|
|
1456
|
+
let c = document.createElement("input");
|
|
1457
|
+
c.className = "md-image-caption", c.placeholder = r.imageCaption, c.setAttribute("aria-label", r.imageCaption), a.append(o, s, c), o.addEventListener("error", () => {
|
|
1458
|
+
o.hidden = !0, s.hidden = !1;
|
|
1459
|
+
});
|
|
1460
|
+
let l = () => {
|
|
1461
|
+
let e = this.options.resolve(i.attrs.src);
|
|
1462
|
+
o.hidden = !e, s.hidden = !!e, e && (o.src = e), o.alt = i.attrs.caption, s.textContent = X(r.imageMissing, { src: i.attrs.src }), document.activeElement !== c && (c.value = i.attrs.caption), c.readOnly = !n.isEditable;
|
|
1463
|
+
};
|
|
1464
|
+
return c.addEventListener("input", () => {
|
|
1465
|
+
let e = typeof t == "function" ? t() : void 0;
|
|
1466
|
+
e !== void 0 && c.value !== i.attrs.caption && n.view.dispatch(n.state.tr.setNodeMarkup(e, void 0, {
|
|
1467
|
+
...i.attrs,
|
|
1468
|
+
caption: c.value
|
|
1469
|
+
}));
|
|
1470
|
+
}), c.addEventListener("keydown", (e) => {
|
|
1471
|
+
e.key === "Enter" && (e.preventDefault(), c.blur());
|
|
1472
|
+
}), l(), {
|
|
1473
|
+
dom: a,
|
|
1474
|
+
update(e) {
|
|
1475
|
+
return e.type === i.type && (i = e, l(), !0);
|
|
1476
|
+
},
|
|
1477
|
+
stopEvent: (e) => e.target === c,
|
|
1478
|
+
ignoreMutation: () => !0
|
|
1479
|
+
};
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
}), Tt = w.create({
|
|
1483
|
+
name: "pageBreak",
|
|
1484
|
+
group: "block",
|
|
1485
|
+
atom: !0,
|
|
1486
|
+
selectable: !0,
|
|
1487
|
+
addOptions() {
|
|
1488
|
+
return { messages: J };
|
|
1489
|
+
},
|
|
1490
|
+
parseHTML() {
|
|
1491
|
+
return [{ tag: "div[data-page-break]" }, {
|
|
1492
|
+
tag: "div",
|
|
1493
|
+
getAttrs: (e) => /page-break-(after|before)\s*:\s*always/i.test(e.getAttribute("style") ?? "") ? null : !1
|
|
1494
|
+
}];
|
|
1495
|
+
},
|
|
1496
|
+
renderHTML() {
|
|
1497
|
+
return ["div", {
|
|
1498
|
+
class: "md-pagebreak",
|
|
1499
|
+
"data-page-break": "",
|
|
1500
|
+
"data-label": this.options.messages.pageBreak,
|
|
1501
|
+
contenteditable: "false"
|
|
1502
|
+
}];
|
|
1503
|
+
}
|
|
1504
|
+
}), Et = C.create({
|
|
1505
|
+
name: "mdShade",
|
|
1506
|
+
parseHTML() {
|
|
1507
|
+
return [{ tag: "mark.md-shade" }, { tag: "mark[data-shade]" }];
|
|
1508
|
+
},
|
|
1509
|
+
renderHTML() {
|
|
1510
|
+
return [
|
|
1511
|
+
"mark",
|
|
1512
|
+
{ class: "md-shade" },
|
|
1513
|
+
0
|
|
1514
|
+
];
|
|
1515
|
+
}
|
|
1516
|
+
}), Dt = C.create({
|
|
1517
|
+
name: "mdHighlight",
|
|
1518
|
+
parseHTML() {
|
|
1519
|
+
return [{
|
|
1520
|
+
tag: "mark",
|
|
1521
|
+
getAttrs: (e) => e.classList.contains("md-shade") || e.hasAttribute("data-shade") ? !1 : null
|
|
1522
|
+
}, {
|
|
1523
|
+
tag: "span",
|
|
1524
|
+
getAttrs: (e) => /^(yellow|#ff0|#ffff00|rgb\(255,\s*255,\s*0\))$/i.test(e.style.backgroundColor.trim()) ? null : !1
|
|
1525
|
+
}];
|
|
1526
|
+
},
|
|
1527
|
+
renderHTML() {
|
|
1528
|
+
return [
|
|
1529
|
+
"mark",
|
|
1530
|
+
{
|
|
1531
|
+
class: "md-mark",
|
|
1532
|
+
style: `background:${n}`
|
|
1533
|
+
},
|
|
1534
|
+
0
|
|
1535
|
+
];
|
|
1536
|
+
},
|
|
1537
|
+
addInputRules() {
|
|
1538
|
+
return [re({
|
|
1539
|
+
find: /(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,
|
|
1540
|
+
type: this.type
|
|
1541
|
+
})];
|
|
1542
|
+
},
|
|
1543
|
+
addPasteRules() {
|
|
1544
|
+
return [ie({
|
|
1545
|
+
find: /(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,
|
|
1546
|
+
type: this.type
|
|
1547
|
+
})];
|
|
1548
|
+
},
|
|
1549
|
+
addKeyboardShortcuts() {
|
|
1550
|
+
return { "Mod-Shift-h": () => this.editor.commands.toggleMark(this.name) };
|
|
1551
|
+
}
|
|
1552
|
+
}), Ot = C.create({
|
|
1553
|
+
name: "superscript",
|
|
1554
|
+
excludes: "subscript",
|
|
1555
|
+
parseHTML() {
|
|
1556
|
+
return [{ tag: "sup" }, {
|
|
1557
|
+
style: "vertical-align",
|
|
1558
|
+
getAttrs: (e) => e === "super" && null
|
|
1559
|
+
}];
|
|
1560
|
+
},
|
|
1561
|
+
renderHTML() {
|
|
1562
|
+
return ["sup", 0];
|
|
1563
|
+
},
|
|
1564
|
+
addKeyboardShortcuts() {
|
|
1565
|
+
return { "Mod-.": () => this.editor.commands.toggleMark(this.name) };
|
|
1566
|
+
}
|
|
1567
|
+
}), kt = C.create({
|
|
1568
|
+
name: "subscript",
|
|
1569
|
+
excludes: "superscript",
|
|
1570
|
+
parseHTML() {
|
|
1571
|
+
return [{ tag: "sub" }, {
|
|
1572
|
+
style: "vertical-align",
|
|
1573
|
+
getAttrs: (e) => e === "sub" && null
|
|
1574
|
+
}];
|
|
1575
|
+
},
|
|
1576
|
+
renderHTML() {
|
|
1577
|
+
return ["sub", 0];
|
|
1578
|
+
},
|
|
1579
|
+
addKeyboardShortcuts() {
|
|
1580
|
+
return { "Mod-,": () => this.editor.commands.toggleMark(this.name) };
|
|
1581
|
+
}
|
|
1582
|
+
}), At = O.extend({ excludes: "" });
|
|
1583
|
+
function jt(e) {
|
|
1584
|
+
if (!e) return null;
|
|
1585
|
+
let t, n, r, i = e.trim().match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i), a = e.match(/rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/i);
|
|
1586
|
+
if (i) {
|
|
1587
|
+
let e = i[1].length === 3 ? i[1].replace(/./g, "$&$&") : i[1];
|
|
1588
|
+
[t, n, r] = [
|
|
1589
|
+
0,
|
|
1590
|
+
2,
|
|
1591
|
+
4
|
|
1592
|
+
].map((t) => parseInt(e.slice(t, t + 2), 16));
|
|
1593
|
+
} else if (a) [t, n, r] = [
|
|
1594
|
+
Number(a[1]),
|
|
1595
|
+
Number(a[2]),
|
|
1596
|
+
Number(a[3])
|
|
1597
|
+
];
|
|
1598
|
+
else if (/^red$/i.test(e.trim())) return "빨강";
|
|
1599
|
+
else if (/^blue$/i.test(e.trim())) return "파랑";
|
|
1600
|
+
else if (/^gr[ae]y$/i.test(e.trim())) return "회색";
|
|
1601
|
+
else return null;
|
|
1602
|
+
let o = Math.max(t, n, r), s = Math.min(t, n, r);
|
|
1603
|
+
return t >= 150 && n <= 100 && r <= 100 ? "빨강" : r >= 120 && t <= 110 && r - t >= 50 ? "파랑" : o - s <= 30 && o >= 90 && o <= 200 ? "회색" : null;
|
|
1604
|
+
}
|
|
1605
|
+
var Mt = C.create({
|
|
1606
|
+
name: "mdColor",
|
|
1607
|
+
addAttributes() {
|
|
1608
|
+
return { name: { default: "빨강" } };
|
|
1609
|
+
},
|
|
1610
|
+
parseHTML() {
|
|
1611
|
+
let e = (e) => {
|
|
1612
|
+
let t = e.getAttribute("data-color"), n = t && h(t) ? t : jt(e.style.color || e.getAttribute("color"));
|
|
1613
|
+
return n ? { name: n } : !1;
|
|
1614
|
+
};
|
|
1615
|
+
return [
|
|
1616
|
+
{
|
|
1617
|
+
tag: "span[data-color]",
|
|
1618
|
+
getAttrs: (t) => e(t)
|
|
1619
|
+
},
|
|
1620
|
+
{
|
|
1621
|
+
tag: "font[color]",
|
|
1622
|
+
getAttrs: (t) => e(t)
|
|
1623
|
+
},
|
|
1624
|
+
{
|
|
1625
|
+
style: "color",
|
|
1626
|
+
getAttrs: (e) => jt(String(e)) ? { name: jt(String(e)) } : !1
|
|
1627
|
+
}
|
|
1628
|
+
];
|
|
1629
|
+
},
|
|
1630
|
+
renderHTML({ mark: e }) {
|
|
1631
|
+
return [
|
|
1632
|
+
"span",
|
|
1633
|
+
{
|
|
1634
|
+
"data-color": e.attrs.name,
|
|
1635
|
+
style: h(e.attrs.name) ? `color:${g(e.attrs.name)}` : ""
|
|
1636
|
+
},
|
|
1637
|
+
0
|
|
1638
|
+
];
|
|
1639
|
+
}
|
|
1640
|
+
}), Nt = {
|
|
1641
|
+
shade: {
|
|
1642
|
+
default: !1,
|
|
1643
|
+
parseHTML: (e) => e.hasAttribute("data-shade"),
|
|
1644
|
+
renderHTML: (e) => e.shade ? {
|
|
1645
|
+
"data-shade": "",
|
|
1646
|
+
style: `background:${y}`
|
|
1647
|
+
} : {}
|
|
1648
|
+
},
|
|
1649
|
+
align: {
|
|
1650
|
+
default: null,
|
|
1651
|
+
parseHTML: (e) => {
|
|
1652
|
+
let t = e.getAttribute("data-align") || e.style.textAlign || e.getAttribute("align");
|
|
1653
|
+
return t === "left" || t === "center" || t === "right" ? t : null;
|
|
1654
|
+
},
|
|
1655
|
+
renderHTML: (e) => e.align ? {
|
|
1656
|
+
"data-align": e.align,
|
|
1657
|
+
style: `text-align:${e.align}`
|
|
1658
|
+
} : {}
|
|
1659
|
+
}
|
|
1660
|
+
}, Pt = ve.extend({
|
|
1661
|
+
content: "paragraph+",
|
|
1662
|
+
addAttributes() {
|
|
1663
|
+
return {
|
|
1664
|
+
...this.parent?.(),
|
|
1665
|
+
...Nt
|
|
1666
|
+
};
|
|
1667
|
+
}
|
|
1668
|
+
}), Ft = ye.extend({
|
|
1669
|
+
content: "paragraph+",
|
|
1670
|
+
addAttributes() {
|
|
1671
|
+
return {
|
|
1672
|
+
...this.parent?.(),
|
|
1673
|
+
...Nt
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
}), It = _e.extend({ addAttributes() {
|
|
1677
|
+
return {
|
|
1678
|
+
...this.parent?.(),
|
|
1679
|
+
align: {
|
|
1680
|
+
default: null,
|
|
1681
|
+
rendered: !1
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
} });
|
|
1685
|
+
function Lt(e = {}) {
|
|
1686
|
+
let t = e.messages ?? J;
|
|
1687
|
+
return [
|
|
1688
|
+
pt,
|
|
1689
|
+
be.configure({
|
|
1690
|
+
document: !1,
|
|
1691
|
+
paragraph: !1,
|
|
1692
|
+
heading: !1,
|
|
1693
|
+
bulletList: !1,
|
|
1694
|
+
orderedList: !1,
|
|
1695
|
+
listItem: !1,
|
|
1696
|
+
listKeymap: !1,
|
|
1697
|
+
blockquote: !1,
|
|
1698
|
+
code: !1,
|
|
1699
|
+
codeBlock: {
|
|
1700
|
+
languageClassPrefix: "language-",
|
|
1701
|
+
enableTabIndentation: !0,
|
|
1702
|
+
tabSize: 4,
|
|
1703
|
+
HTMLAttributes: { class: "md-code" }
|
|
1704
|
+
},
|
|
1705
|
+
horizontalRule: { HTMLAttributes: { class: "md-rule" } },
|
|
1706
|
+
link: {
|
|
1707
|
+
openOnClick: !1,
|
|
1708
|
+
autolink: !0,
|
|
1709
|
+
linkOnPaste: !0,
|
|
1710
|
+
defaultProtocol: "https",
|
|
1711
|
+
HTMLAttributes: {
|
|
1712
|
+
rel: "noopener noreferrer nofollow",
|
|
1713
|
+
target: "_blank"
|
|
1714
|
+
},
|
|
1715
|
+
isAllowedUri: (e) => i(e) !== null
|
|
1716
|
+
}
|
|
1717
|
+
}),
|
|
1718
|
+
vt,
|
|
1719
|
+
mt,
|
|
1720
|
+
ht,
|
|
1721
|
+
gt,
|
|
1722
|
+
yt,
|
|
1723
|
+
St.configure({ messages: t }),
|
|
1724
|
+
Ct,
|
|
1725
|
+
wt.configure({
|
|
1726
|
+
resolve: e.resolveImage ?? (() => void 0),
|
|
1727
|
+
messages: t
|
|
1728
|
+
}),
|
|
1729
|
+
Tt.configure({ messages: t }),
|
|
1730
|
+
Et,
|
|
1731
|
+
Dt,
|
|
1732
|
+
Mt,
|
|
1733
|
+
Ot,
|
|
1734
|
+
kt,
|
|
1735
|
+
At,
|
|
1736
|
+
It.configure({ resizable: !1 }),
|
|
1737
|
+
A,
|
|
1738
|
+
Ft,
|
|
1739
|
+
Pt,
|
|
1740
|
+
$e,
|
|
1741
|
+
ut
|
|
1742
|
+
];
|
|
1743
|
+
}
|
|
1744
|
+
// src/ui/dom.ts
|
|
1745
|
+
function Q(e, t = {}, ...n) {
|
|
1746
|
+
let r = document.createElement(e);
|
|
1747
|
+
t.className && (r.className = t.className), t.html !== void 0 && (r.innerHTML = t.html), t.text !== void 0 && (r.textContent = t.text), t.title && (r.title = t.title);
|
|
1748
|
+
for (let [e, n] of Object.entries(t.attrs ?? {})) n != null && n !== !1 && r.setAttribute(e, n === !0 ? "" : String(n));
|
|
1749
|
+
t.style && Object.assign(r.style, t.style);
|
|
1750
|
+
for (let [e, n] of Object.entries(t.on ?? {})) r.addEventListener(e, n);
|
|
1751
|
+
for (let e of n) e != null && e !== !1 && r.append(e);
|
|
1752
|
+
return r;
|
|
1753
|
+
}
|
|
1754
|
+
function Rt(e, t, n, r = "left") {
|
|
1755
|
+
let i = Q("span", { className: "mde-menu" }, t);
|
|
1756
|
+
t.setAttribute("aria-haspopup", "true"), t.setAttribute("aria-expanded", "false");
|
|
1757
|
+
let a = null, o = (e) => {
|
|
1758
|
+
i.contains(e.target) || c.close();
|
|
1759
|
+
}, s = (e) => {
|
|
1760
|
+
e.key === "Escape" && (e.stopPropagation(), c.close(), t.focus());
|
|
1761
|
+
}, c = {
|
|
1762
|
+
wrap: i,
|
|
1763
|
+
button: t,
|
|
1764
|
+
open() {
|
|
1765
|
+
a || (e.current && e.current !== c && e.current.close(), e.current = c, a = Q("div", {
|
|
1766
|
+
className: `mde-pop ${r === "right" ? "right" : ""}`,
|
|
1767
|
+
attrs: { role: "dialog" }
|
|
1768
|
+
}, n(() => c.close())), i.append(a), t.setAttribute("aria-expanded", "true"), document.addEventListener("mousedown", o, !0), i.addEventListener("keydown", s), a.getBoundingClientRect().right > window.innerWidth - 8 && a.classList.add("right"), a.querySelector("input[data-autofocus], [data-autofocus]")?.focus());
|
|
1769
|
+
},
|
|
1770
|
+
close() {
|
|
1771
|
+
a && (a.remove(), a = null, e.current === c && (e.current = null), t.setAttribute("aria-expanded", "false"), document.removeEventListener("mousedown", o, !0), i.removeEventListener("keydown", s));
|
|
1772
|
+
},
|
|
1773
|
+
isOpen: () => !!a
|
|
1774
|
+
};
|
|
1775
|
+
return t.addEventListener("click", () => a ? c.close() : c.open()), c;
|
|
1776
|
+
}
|
|
1777
|
+
// src/ui/icons.ts
|
|
1778
|
+
var zt = {
|
|
1779
|
+
undo: "<path d=\"M9 14 4 9l5-5\"/><path d=\"M4 9h10.5a5.5 5.5 0 0 1 0 11H11\"/>",
|
|
1780
|
+
redo: "<path d=\"m15 14 5-5-5-5\"/><path d=\"M20 9H9.5a5.5 5.5 0 0 0 0 11H13\"/>",
|
|
1781
|
+
link: "<path d=\"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71\"/><path d=\"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71\"/>",
|
|
1782
|
+
unlink: "<path d=\"m18.84 12.25 1.72-1.71a5 5 0 0 0-7.07-7.07l-1.72 1.71\"/><path d=\"m5.17 11.75-1.71 1.71a5 5 0 0 0 7.07 7.07l1.71-1.71\"/><line x1=\"8\" y1=\"2\" x2=\"8\" y2=\"5\"/><line x1=\"2\" y1=\"8\" x2=\"5\" y2=\"8\"/><line x1=\"16\" y1=\"19\" x2=\"16\" y2=\"22\"/><line x1=\"19\" y1=\"16\" x2=\"22\" y2=\"16\"/>",
|
|
1783
|
+
external: "<path d=\"M15 3h6v6\"/><path d=\"M10 14 21 3\"/><path d=\"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6\"/>",
|
|
1784
|
+
code: "<polyline points=\"16 18 22 12 16 6\"/><polyline points=\"8 6 2 12 8 18\"/>",
|
|
1785
|
+
highlight: "<path d=\"m9 11-6 6v3h9l3-3\"/><path d=\"m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4\"/>",
|
|
1786
|
+
removeFormat: "<path d=\"M4 7V4h16v3\"/><path d=\"M5 20h6\"/><path d=\"M13 4 8 20\"/><path d=\"m15 15 5 5\"/><path d=\"m20 15-5 5\"/>",
|
|
1787
|
+
bulletList: "<line x1=\"9\" y1=\"6\" x2=\"21\" y2=\"6\"/><line x1=\"9\" y1=\"12\" x2=\"21\" y2=\"12\"/><line x1=\"9\" y1=\"18\" x2=\"21\" y2=\"18\"/><circle cx=\"4\" cy=\"6\" r=\"1.2\"/><circle cx=\"4\" cy=\"12\" r=\"1.2\"/><circle cx=\"4\" cy=\"18\" r=\"1.2\"/>",
|
|
1788
|
+
orderedList: "<line x1=\"10\" y1=\"6\" x2=\"21\" y2=\"6\"/><line x1=\"10\" y1=\"12\" x2=\"21\" y2=\"12\"/><line x1=\"10\" y1=\"18\" x2=\"21\" y2=\"18\"/><path d=\"M4 6h1v4\"/><path d=\"M4 10h2\"/><path d=\"M6 18H4c0-1 2-2 2-3s-1-1.5-2-1\"/>",
|
|
1789
|
+
taskList: "<rect x=\"3\" y=\"5\" width=\"6\" height=\"6\" rx=\"1\"/><path d=\"m3 17 2 2 4-4\"/><path d=\"M13 6h8\"/><path d=\"M13 12h8\"/><path d=\"M13 18h8\"/>",
|
|
1790
|
+
outdent: "<polyline points=\"7 8 3 12 7 16\"/><line x1=\"21\" y1=\"12\" x2=\"11\" y2=\"12\"/><line x1=\"21\" y1=\"6\" x2=\"11\" y2=\"6\"/><line x1=\"21\" y1=\"18\" x2=\"11\" y2=\"18\"/>",
|
|
1791
|
+
indent: "<polyline points=\"3 8 7 12 3 16\"/><line x1=\"21\" y1=\"12\" x2=\"11\" y2=\"12\"/><line x1=\"21\" y1=\"6\" x2=\"11\" y2=\"6\"/><line x1=\"21\" y1=\"18\" x2=\"11\" y2=\"18\"/>",
|
|
1792
|
+
alignLeft: "<line x1=\"21\" y1=\"6\" x2=\"3\" y2=\"6\"/><line x1=\"15\" y1=\"12\" x2=\"3\" y2=\"12\"/><line x1=\"17\" y1=\"18\" x2=\"3\" y2=\"18\"/>",
|
|
1793
|
+
alignCenter: "<line x1=\"21\" y1=\"6\" x2=\"3\" y2=\"6\"/><line x1=\"17\" y1=\"12\" x2=\"7\" y2=\"12\"/><line x1=\"19\" y1=\"18\" x2=\"5\" y2=\"18\"/>",
|
|
1794
|
+
alignRight: "<line x1=\"21\" y1=\"6\" x2=\"3\" y2=\"6\"/><line x1=\"21\" y1=\"12\" x2=\"9\" y2=\"12\"/><line x1=\"21\" y1=\"18\" x2=\"7\" y2=\"18\"/>",
|
|
1795
|
+
alignJustify: "<line x1=\"3\" y1=\"6\" x2=\"21\" y2=\"6\"/><line x1=\"3\" y1=\"12\" x2=\"21\" y2=\"12\"/><line x1=\"3\" y1=\"18\" x2=\"21\" y2=\"18\"/>",
|
|
1796
|
+
table: "<rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"2\"/><path d=\"M3 9h18\"/><path d=\"M3 15h18\"/><path d=\"M9 3v18\"/><path d=\"M15 3v18\"/>",
|
|
1797
|
+
image: "<rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"2\"/><circle cx=\"8.5\" cy=\"8.5\" r=\"1.5\"/><path d=\"m21 15-5-5L5 21\"/>",
|
|
1798
|
+
codeBlock: "<rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"2\"/><path d=\"m10 9-3 3 3 3\"/><path d=\"m14 15 3-3-3-3\"/>",
|
|
1799
|
+
horizontalRule: "<line x1=\"3\" y1=\"12\" x2=\"21\" y2=\"12\"/><path d=\"M8 6h8\" opacity=\".35\"/><path d=\"M8 18h8\" opacity=\".35\"/>",
|
|
1800
|
+
pageBreak: "<path d=\"M5 3v5h14V3\"/><path d=\"M5 21v-5h14v5\"/><path d=\"M3 12h2\"/><path d=\"M8 12h3\"/><path d=\"M13 12h3\"/><path d=\"M19 12h2\"/>",
|
|
1801
|
+
pages: "<path d=\"M5 10V4a1.5 1.5 0 0 1 1.5-1.5H15l4 4V10\"/><path d=\"M5 17v3.5A1.5 1.5 0 0 0 6.5 22h11a1.5 1.5 0 0 0 1.5-1.5V17\"/><path d=\"M2 13.5h2\"/><path d=\"M7 13.5h3\"/><path d=\"M13 13.5h3\"/><path d=\"M19 13.5h3\"/>",
|
|
1802
|
+
find: "<circle cx=\"11\" cy=\"11\" r=\"7\"/><line x1=\"21\" y1=\"21\" x2=\"16.65\" y2=\"16.65\"/>",
|
|
1803
|
+
preview: "<path d=\"M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z\"/><circle cx=\"12\" cy=\"12\" r=\"3\"/>",
|
|
1804
|
+
fullscreen: "<path d=\"M8 3H5a2 2 0 0 0-2 2v3\"/><path d=\"M21 8V5a2 2 0 0 0-2-2h-3\"/><path d=\"M3 16v3a2 2 0 0 0 2 2h3\"/><path d=\"M16 21h3a2 2 0 0 0 2-2v-3\"/>",
|
|
1805
|
+
fullscreenExit: "<path d=\"M8 3v3a2 2 0 0 1-2 2H3\"/><path d=\"M21 8h-3a2 2 0 0 1-2-2V3\"/><path d=\"M3 16h3a2 2 0 0 1 2 2v3\"/><path d=\"M16 21v-3a2 2 0 0 1 2-2h3\"/>",
|
|
1806
|
+
chevronUp: "<polyline points=\"18 15 12 9 6 15\"/>",
|
|
1807
|
+
chevronDown: "<polyline points=\"6 9 12 15 18 9\"/>",
|
|
1808
|
+
close: "<line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\"/><line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\"/>"
|
|
1809
|
+
};
|
|
1810
|
+
function $(e, t = 17) {
|
|
1811
|
+
let n = zt[e];
|
|
1812
|
+
return n ? `<svg width="${t}" height="${t}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${n}</svg>` : "";
|
|
1813
|
+
}
|
|
1814
|
+
// src/ui/panels.ts
|
|
1815
|
+
var Bt = [
|
|
1816
|
+
[
|
|
1817
|
+
"",
|
|
1818
|
+
"#000000",
|
|
1819
|
+
"#404040",
|
|
1820
|
+
"#7f7f7f",
|
|
1821
|
+
"#a6a6a6",
|
|
1822
|
+
"#d0d0d0",
|
|
1823
|
+
"#ffffff"
|
|
1824
|
+
],
|
|
1825
|
+
[
|
|
1826
|
+
"#c00000",
|
|
1827
|
+
"#e36c09",
|
|
1828
|
+
"#c99a06",
|
|
1829
|
+
"#2e8b57",
|
|
1830
|
+
"#1f4e9b",
|
|
1831
|
+
"#7030a0",
|
|
1832
|
+
"#4f6b8a"
|
|
1833
|
+
],
|
|
1834
|
+
[
|
|
1835
|
+
"#f4b6b6",
|
|
1836
|
+
"#f9cfa8",
|
|
1837
|
+
"#f2e2a0",
|
|
1838
|
+
"#b5e3c8",
|
|
1839
|
+
"#b4cff0",
|
|
1840
|
+
"#d2c2ee",
|
|
1841
|
+
"#cbd5e1"
|
|
1842
|
+
],
|
|
1843
|
+
[
|
|
1844
|
+
"#e06666",
|
|
1845
|
+
"#f39c5a",
|
|
1846
|
+
"#d6b52a",
|
|
1847
|
+
"#6aa84f",
|
|
1848
|
+
"#3d85c6",
|
|
1849
|
+
"#8e7cc3",
|
|
1850
|
+
"#7f9cb5"
|
|
1851
|
+
],
|
|
1852
|
+
[
|
|
1853
|
+
"#7f1d1d",
|
|
1854
|
+
"#8a4b1f",
|
|
1855
|
+
"#6b5f12",
|
|
1856
|
+
"#275e2a",
|
|
1857
|
+
"#1c3d6e",
|
|
1858
|
+
"#4b2a85",
|
|
1859
|
+
"#334155"
|
|
1860
|
+
]
|
|
1861
|
+
], Vt = /^#?([0-9a-f]{6}|[0-9a-f]{3})$/i;
|
|
1862
|
+
function Ht(e) {
|
|
1863
|
+
let t = Vt.exec(e.trim());
|
|
1864
|
+
return t ? `#${(t[1].length === 3 ? t[1].replace(/./g, "$&$&") : t[1]).toLowerCase()}` : null;
|
|
1865
|
+
}
|
|
1866
|
+
function Ut(e) {
|
|
1867
|
+
return Object.entries(l).find(([, t]) => t === e)?.[0] ?? e;
|
|
1868
|
+
}
|
|
1869
|
+
function Wt(e, t, n) {
|
|
1870
|
+
let r = t ? g(t) : "currentColor";
|
|
1871
|
+
return `<span class="mde-color-glyph"${n ? ` style="background:${y}"` : ""}>${e}<i style="background:${r}"></i></span><span class="mde-caret" aria-hidden="true">▾</span>`;
|
|
1872
|
+
}
|
|
1873
|
+
function Gt(e, t, n, r, i, a) {
|
|
1874
|
+
let o = t ? g(t) : null, s = Q("div", {
|
|
1875
|
+
className: "mde-palette",
|
|
1876
|
+
attrs: {
|
|
1877
|
+
role: "group",
|
|
1878
|
+
"aria-label": e.color
|
|
1879
|
+
}
|
|
1880
|
+
});
|
|
1881
|
+
for (let t of Bt.flat()) {
|
|
1882
|
+
let n = Q("button", {
|
|
1883
|
+
className: `mde-swatch ${t === "#ffffff" ? "light" : ""} ${t ? "" : "none"}`,
|
|
1884
|
+
attrs: {
|
|
1885
|
+
type: "button",
|
|
1886
|
+
"data-color": t,
|
|
1887
|
+
"aria-label": t || e.defaultColor,
|
|
1888
|
+
title: t || e.defaultColor,
|
|
1889
|
+
"aria-pressed": t ? o === t : !o,
|
|
1890
|
+
disabled: !t && !r
|
|
1891
|
+
},
|
|
1892
|
+
style: t ? { background: t } : {},
|
|
1893
|
+
on: { click: () => i(t ? Ut(t) : null) }
|
|
1894
|
+
});
|
|
1895
|
+
s.append(n);
|
|
1896
|
+
}
|
|
1897
|
+
let c = Q("input", { attrs: {
|
|
1898
|
+
type: "color",
|
|
1899
|
+
"aria-label": e.pickColor,
|
|
1900
|
+
title: e.pickColor
|
|
1901
|
+
} }), l = Q("input", {
|
|
1902
|
+
className: "mde-hex",
|
|
1903
|
+
attrs: {
|
|
1904
|
+
type: "text",
|
|
1905
|
+
"aria-label": e.colorCode,
|
|
1906
|
+
maxlength: 7,
|
|
1907
|
+
spellcheck: "false"
|
|
1908
|
+
}
|
|
1909
|
+
}), u = Q("button", {
|
|
1910
|
+
className: "mde-btn word primary",
|
|
1911
|
+
text: e.apply,
|
|
1912
|
+
attrs: { type: "submit" }
|
|
1913
|
+
}), d = () => {
|
|
1914
|
+
let e = Ht(l.value);
|
|
1915
|
+
u.disabled = !e, e && (c.value = e);
|
|
1916
|
+
};
|
|
1917
|
+
l.value = o ?? "#333333", c.value = o ?? "#333333", c.addEventListener("input", () => (l.value = c.value, d())), l.addEventListener("input", d), l.addEventListener("focus", () => l.select());
|
|
1918
|
+
let f = Q("form", {
|
|
1919
|
+
className: "mde-hex-row",
|
|
1920
|
+
on: { submit: (e) => (e.preventDefault(), Ht(l.value) && i(Ut(Ht(l.value)))) }
|
|
1921
|
+
}, c, l, u), p = Q("button", {
|
|
1922
|
+
className: "mde-menu-item",
|
|
1923
|
+
attrs: {
|
|
1924
|
+
type: "button",
|
|
1925
|
+
role: "menuitemcheckbox",
|
|
1926
|
+
"aria-checked": n,
|
|
1927
|
+
"data-color": "음영"
|
|
1928
|
+
},
|
|
1929
|
+
on: { click: a }
|
|
1930
|
+
}, Q("span", { className: "mde-swatch-row" }, Q("span", {
|
|
1931
|
+
className: "mde-square",
|
|
1932
|
+
style: { background: y }
|
|
1933
|
+
}), Q("mark", {
|
|
1934
|
+
text: e.shade,
|
|
1935
|
+
style: {
|
|
1936
|
+
background: y,
|
|
1937
|
+
padding: "0 3px"
|
|
1938
|
+
}
|
|
1939
|
+
})), n ? Q("small", { text: "✓" }) : null);
|
|
1940
|
+
return Q("div", { className: "mde-color-panel" }, s, f, Q("div", { className: "mde-menu-sep" }), p);
|
|
1941
|
+
}
|
|
1942
|
+
function Kt(e, t, n, r, a) {
|
|
1943
|
+
let o = Q("input", {
|
|
1944
|
+
className: "mde-input",
|
|
1945
|
+
attrs: {
|
|
1946
|
+
type: "url",
|
|
1947
|
+
placeholder: "https://",
|
|
1948
|
+
"aria-label": e.linkUrl,
|
|
1949
|
+
"data-autofocus": !0,
|
|
1950
|
+
spellcheck: "false"
|
|
1951
|
+
}
|
|
1952
|
+
});
|
|
1953
|
+
o.value = t ?? "";
|
|
1954
|
+
let s = n ? Q("input", {
|
|
1955
|
+
className: "mde-input",
|
|
1956
|
+
attrs: {
|
|
1957
|
+
type: "text",
|
|
1958
|
+
placeholder: e.linkText,
|
|
1959
|
+
"aria-label": e.linkText
|
|
1960
|
+
}
|
|
1961
|
+
}) : null, c = Q("div", {
|
|
1962
|
+
className: "mde-field-error",
|
|
1963
|
+
attrs: { role: "alert" }
|
|
1964
|
+
});
|
|
1965
|
+
c.hidden = !0;
|
|
1966
|
+
let l = (t) => {
|
|
1967
|
+
t.preventDefault();
|
|
1968
|
+
let n = o.value.trim();
|
|
1969
|
+
n && (/^www\./i.test(n) && (n = `https://${n}`), i(n) ? r(n, s?.value.trim() ?? "") : (c.textContent = e.linkInvalid, c.hidden = !1));
|
|
1970
|
+
}, u = Q("div", { className: "mde-row" }, Q("button", {
|
|
1971
|
+
className: "mde-btn word primary",
|
|
1972
|
+
text: e.linkApply,
|
|
1973
|
+
attrs: { type: "submit" }
|
|
1974
|
+
}), a ? Q("button", {
|
|
1975
|
+
className: "mde-btn",
|
|
1976
|
+
html: $("unlink"),
|
|
1977
|
+
title: e.linkRemove,
|
|
1978
|
+
attrs: {
|
|
1979
|
+
type: "button",
|
|
1980
|
+
"aria-label": e.linkRemove
|
|
1981
|
+
},
|
|
1982
|
+
on: { click: a }
|
|
1983
|
+
}) : null, t && i(t) ? Q("a", {
|
|
1984
|
+
className: "mde-btn",
|
|
1985
|
+
html: $("external"),
|
|
1986
|
+
title: e.linkOpen,
|
|
1987
|
+
attrs: {
|
|
1988
|
+
href: i(t),
|
|
1989
|
+
target: "_blank",
|
|
1990
|
+
rel: "noopener noreferrer",
|
|
1991
|
+
"aria-label": e.linkOpen
|
|
1992
|
+
}
|
|
1993
|
+
}) : null);
|
|
1994
|
+
return Q("form", {
|
|
1995
|
+
className: "mde-link-panel",
|
|
1996
|
+
on: { submit: l }
|
|
1997
|
+
}, o, s, c, u);
|
|
1998
|
+
}
|
|
1999
|
+
function qt(e, t, n = [8, 10]) {
|
|
2000
|
+
let [r, i] = n, a = Q("div", {
|
|
2001
|
+
className: "mde-grid-label",
|
|
2002
|
+
text: X(e.tableSize, {
|
|
2003
|
+
rows: 3,
|
|
2004
|
+
cols: 3
|
|
2005
|
+
})
|
|
2006
|
+
}), o = Q("div", {
|
|
2007
|
+
className: "mde-grid",
|
|
2008
|
+
attrs: {
|
|
2009
|
+
role: "grid",
|
|
2010
|
+
"aria-label": e.insertTable
|
|
2011
|
+
}
|
|
2012
|
+
});
|
|
2013
|
+
o.style.gridTemplateColumns = `repeat(${i}, 16px)`;
|
|
2014
|
+
let s = [], c = (t, n) => {
|
|
2015
|
+
s.forEach((e) => e.classList.toggle("on", Number(e.dataset.r) <= t && Number(e.dataset.c) <= n)), a.textContent = X(e.tableSize, {
|
|
2016
|
+
rows: t,
|
|
2017
|
+
cols: n
|
|
2018
|
+
});
|
|
2019
|
+
};
|
|
2020
|
+
for (let n = 1; n <= r; n++) for (let r = 1; r <= i; r++) {
|
|
2021
|
+
let i = Q("button", {
|
|
2022
|
+
className: "mde-grid-cell",
|
|
2023
|
+
attrs: {
|
|
2024
|
+
type: "button",
|
|
2025
|
+
"data-r": n,
|
|
2026
|
+
"data-c": r,
|
|
2027
|
+
"aria-label": X(e.tableSize, {
|
|
2028
|
+
rows: n,
|
|
2029
|
+
cols: r
|
|
2030
|
+
})
|
|
2031
|
+
},
|
|
2032
|
+
on: {
|
|
2033
|
+
mouseenter: () => c(n, r),
|
|
2034
|
+
focus: () => c(n, r),
|
|
2035
|
+
click: () => t(n, r)
|
|
2036
|
+
}
|
|
2037
|
+
});
|
|
2038
|
+
s.push(i), o.append(i);
|
|
2039
|
+
}
|
|
2040
|
+
return c(3, 3), Q("div", { className: "mde-table-panel" }, o, a);
|
|
2041
|
+
}
|
|
2042
|
+
var Jt = [
|
|
2043
|
+
["기호", "©®™§¶†‡•·…‰′″‹›«»「」『』〈〉《》【】※"],
|
|
2044
|
+
["화살표", "←↑→↓↔↕⇐⇑⇒⇓⇔↗↘↙↖➔"],
|
|
2045
|
+
["수학", "±×÷≠≈≡≤≥∞√∑∏∫∂∆∇∈∉∩∪⊂⊃∧∨¬∀∃°µπΩαβγδθλσφω½⅓¼¾"],
|
|
2046
|
+
["통화", "₩$€£¥¢₹₽₿"],
|
|
2047
|
+
["단위", "℃℉㎜㎝㎞㎡㎥㎏㎖ℓ№㈜"],
|
|
2048
|
+
["도형", "○●◎◇◆□■△▲▽▼☆★♠♣♥♦✓✗"]
|
|
2049
|
+
];
|
|
2050
|
+
function Yt(e, t) {
|
|
2051
|
+
let n = Q("div", {
|
|
2052
|
+
className: "mde-chars",
|
|
2053
|
+
attrs: { "aria-label": e.specialChars }
|
|
2054
|
+
});
|
|
2055
|
+
for (let [, e] of Jt) {
|
|
2056
|
+
let r = Q("div", { className: "mde-chars-group" });
|
|
2057
|
+
for (let n of e) r.append(Q("button", {
|
|
2058
|
+
className: "mde-char",
|
|
2059
|
+
text: n,
|
|
2060
|
+
attrs: {
|
|
2061
|
+
type: "button",
|
|
2062
|
+
title: n,
|
|
2063
|
+
"aria-label": n
|
|
2064
|
+
},
|
|
2065
|
+
on: { click: () => t(n) }
|
|
2066
|
+
}));
|
|
2067
|
+
n.append(r);
|
|
2068
|
+
}
|
|
2069
|
+
return n;
|
|
2070
|
+
}
|
|
2071
|
+
function Xt(e, t, n) {
|
|
2072
|
+
let r = Q("input", {
|
|
2073
|
+
className: "mde-input",
|
|
2074
|
+
attrs: {
|
|
2075
|
+
type: "url",
|
|
2076
|
+
placeholder: "https://…/image.png",
|
|
2077
|
+
"aria-label": e.imageUrl,
|
|
2078
|
+
"data-autofocus": !0,
|
|
2079
|
+
spellcheck: "false"
|
|
2080
|
+
}
|
|
2081
|
+
}), i = Q("input", {
|
|
2082
|
+
className: "mde-input",
|
|
2083
|
+
attrs: {
|
|
2084
|
+
type: "text",
|
|
2085
|
+
placeholder: e.imageCaption,
|
|
2086
|
+
"aria-label": e.imageCaption
|
|
2087
|
+
}
|
|
2088
|
+
});
|
|
2089
|
+
return Q("form", {
|
|
2090
|
+
className: "mde-image-panel",
|
|
2091
|
+
on: { submit: (e) => {
|
|
2092
|
+
e.preventDefault();
|
|
2093
|
+
let n = r.value.trim();
|
|
2094
|
+
n && t(n, i.value.trim());
|
|
2095
|
+
} }
|
|
2096
|
+
}, n ? Q("button", {
|
|
2097
|
+
className: "mde-btn word wide",
|
|
2098
|
+
html: `${$("image")}<span>${e.imageUpload}</span>`,
|
|
2099
|
+
attrs: { type: "button" },
|
|
2100
|
+
on: { click: n }
|
|
2101
|
+
}) : null, r, i, Q("div", { className: "mde-row" }, Q("button", {
|
|
2102
|
+
className: "mde-btn word primary",
|
|
2103
|
+
text: e.insertImage,
|
|
2104
|
+
attrs: { type: "submit" }
|
|
2105
|
+
})));
|
|
2106
|
+
}
|
|
2107
|
+
var Zt = [
|
|
2108
|
+
["left", "alignLeft"],
|
|
2109
|
+
["center", "alignCenter"],
|
|
2110
|
+
["right", "alignRight"],
|
|
2111
|
+
["justify", "alignJustify"]
|
|
2112
|
+
];
|
|
2113
|
+
function Qt(e, t, n) {
|
|
2114
|
+
return Q("div", {
|
|
2115
|
+
className: "mde-align-panel",
|
|
2116
|
+
attrs: {
|
|
2117
|
+
role: "group",
|
|
2118
|
+
"aria-label": e.align
|
|
2119
|
+
}
|
|
2120
|
+
}, ...Zt.map(([r, i]) => Q("button", {
|
|
2121
|
+
className: "mde-btn",
|
|
2122
|
+
html: $(i),
|
|
2123
|
+
title: e[i],
|
|
2124
|
+
attrs: {
|
|
2125
|
+
type: "button",
|
|
2126
|
+
"aria-label": e[i],
|
|
2127
|
+
"aria-pressed": t === r,
|
|
2128
|
+
"data-align": r
|
|
2129
|
+
},
|
|
2130
|
+
on: { click: () => n(r) }
|
|
2131
|
+
})));
|
|
2132
|
+
}
|
|
2133
|
+
// src/ui/mditor.ts
|
|
2134
|
+
var $t = /* @__PURE__ */ "undo.redo.|.blockKind.|.bold.italic.underline.strike.color.highlight.|.link.code.superscript.subscript.removeFormat.|.bulletList.orderedList.taskList.outdent.indent.align.|.table.image.codeBlock.horizontalRule.pageBreak.specialChars.|.find.source.preview.fullscreen".split("."), en = typeof navigator < "u" && /Mac|iP(hone|ad|od)/.test(navigator.platform || navigator.userAgent), tn = (e) => en ? `⌘${e.replace("Shift+", "⇧").replace("Alt+", "⌥")}` : `Ctrl+${e}`, nn = /\n|^#{1,6}\s|^[-*+]\s|^\d{1,9}[.)]\s|^>|\*\*|~~|==|`|\[[^\]]*\]\([^)]*\)|\{\/?[^}\s]+\}|^\|/;
|
|
2135
|
+
function rn(e) {
|
|
2136
|
+
return e ? [...e.files].filter((e) => e.type.startsWith("image/")) : [];
|
|
2137
|
+
}
|
|
2138
|
+
function an(e) {
|
|
2139
|
+
return new Promise((t, n) => {
|
|
2140
|
+
let r = new FileReader();
|
|
2141
|
+
r.onload = () => t(String(r.result)), r.onerror = () => n(r.error), r.readAsDataURL(e);
|
|
2142
|
+
});
|
|
2143
|
+
}
|
|
2144
|
+
function on(e) {
|
|
2145
|
+
let n = ft(e.locale ?? "ko", e.messages), r = e.contentClass ?? "mde-doc", i = e.locale === "en" ? "en" : "ko", a = e.image ?? {}, o = e.dialect ?? e.doc?.dialect ?? (e.markdown ? t(e.markdown) : null) ?? i, s = !!e.dialect, c = "wysiwyg", l = !!e.preview, u = !1, d = !!e.pageMarks, p = null, h = { current: null }, g = {
|
|
2146
|
+
change: /* @__PURE__ */ new Set(),
|
|
2147
|
+
mode: /* @__PURE__ */ new Set(),
|
|
2148
|
+
preview: /* @__PURE__ */ new Set(),
|
|
2149
|
+
fullscreen: /* @__PURE__ */ new Set(),
|
|
2150
|
+
pagemarks: /* @__PURE__ */ new Set()
|
|
2151
|
+
}, _ = (e, ...t) => g[e].forEach((e) => e(...t)), v = Q("div", {
|
|
2152
|
+
className: "mde",
|
|
2153
|
+
attrs: { "data-mode": "wysiwyg" }
|
|
2154
|
+
}), y = Q("div", {
|
|
2155
|
+
className: "mde-toolbar",
|
|
2156
|
+
attrs: {
|
|
2157
|
+
role: "toolbar",
|
|
2158
|
+
"aria-label": n.toolbar
|
|
2159
|
+
}
|
|
2160
|
+
}), b = {
|
|
2161
|
+
start: Q("span", { className: "mde-slot start" }),
|
|
2162
|
+
end: Q("span", { className: "mde-slot end" })
|
|
2163
|
+
}, x = Q("div", {
|
|
2164
|
+
className: "mde-findbar",
|
|
2165
|
+
attrs: {
|
|
2166
|
+
role: "search",
|
|
2167
|
+
"aria-label": n.findReplace
|
|
2168
|
+
}
|
|
2169
|
+
});
|
|
2170
|
+
x.hidden = !0;
|
|
2171
|
+
let C = Q("div", { className: "mde-context" }), w = Q("div", {
|
|
2172
|
+
className: "mde-error",
|
|
2173
|
+
attrs: { role: "alert" }
|
|
2174
|
+
});
|
|
2175
|
+
w.hidden = !0;
|
|
2176
|
+
let re = Q("div", { className: "mde-mount" }), ie = Q("div", { className: "mde-scroll" }, re), T = Q("textarea", {
|
|
2177
|
+
className: "mde-source",
|
|
2178
|
+
attrs: {
|
|
2179
|
+
spellcheck: "false",
|
|
2180
|
+
"aria-label": n.sourceLabel
|
|
2181
|
+
}
|
|
2182
|
+
});
|
|
2183
|
+
T.hidden = !0;
|
|
2184
|
+
let oe = Q("div", { className: "mde-pane mde-edit" }, ie, T), ce = Q("article", {
|
|
2185
|
+
className: `mde-preview-doc ${r}`,
|
|
2186
|
+
attrs: { "aria-label": n.previewLabel }
|
|
2187
|
+
}), le = Q("div", { className: "mde-main" }, oe, Q("div", { className: "mde-pane mde-preview" }, Q("div", { className: "mde-scroll" }, ce))), ue = Q("div", {
|
|
2188
|
+
className: "mde-status",
|
|
2189
|
+
attrs: { "aria-live": "polite" }
|
|
2190
|
+
});
|
|
2191
|
+
e.toolbar !== !1 && v.append(y), v.append(x, C, w, le), e.statusbar !== !1 && v.append(ue), e.element.append(v);
|
|
2192
|
+
let de = (e) => a.resolve ? a.resolve(e) : e || void 0, fe = null, pe;
|
|
2193
|
+
if (e.doc) pe = H(e.doc);
|
|
2194
|
+
else try {
|
|
2195
|
+
pe = H(m(e.markdown ?? "", o));
|
|
2196
|
+
} catch (e) {
|
|
2197
|
+
if (!(e instanceof ee)) throw e;
|
|
2198
|
+
fe = e, pe = H({
|
|
2199
|
+
title: "",
|
|
2200
|
+
sections: []
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
2203
|
+
let me = 0, he = (t, r, i) => {
|
|
2204
|
+
let a = null;
|
|
2205
|
+
return e.maxPaste && t > e.maxPaste ? a = {
|
|
2206
|
+
kind: "paste",
|
|
2207
|
+
length: t,
|
|
2208
|
+
max: e.maxPaste
|
|
2209
|
+
} : e.maxLength && r > e.maxLength && r > i && (a = {
|
|
2210
|
+
kind: "document",
|
|
2211
|
+
length: r,
|
|
2212
|
+
max: e.maxLength
|
|
2213
|
+
}), a ? (e.onTooLong ? e.onTooLong(a) : (w.textContent = X(a.kind === "paste" ? n.pasteTooLong : n.tooLong, {
|
|
2214
|
+
max: a.max.toLocaleString(),
|
|
2215
|
+
length: a.length.toLocaleString()
|
|
2216
|
+
}), w.hidden = !1, window.clearTimeout(me), me = window.setTimeout(() => w.hidden = !0, 6e3)), !0) : !1;
|
|
2217
|
+
}, ge = (e) => e ? e.getData("text/plain") || e.getData("text/html").replace(/<[^>]*>/g, "") : "", E = Q("input", { attrs: {
|
|
2218
|
+
type: "file",
|
|
2219
|
+
accept: "image/png,image/jpeg,image/gif,image/webp,image/svg+xml",
|
|
2220
|
+
hidden: !0,
|
|
2221
|
+
multiple: !0
|
|
2222
|
+
} });
|
|
2223
|
+
v.append(E);
|
|
2224
|
+
let D = async (e) => {
|
|
2225
|
+
if (e.length) {
|
|
2226
|
+
if (a.onFiles) return a.onFiles(e);
|
|
2227
|
+
for (let t of e) {
|
|
2228
|
+
let e = a.upload ? await a.upload(t) : await an(t);
|
|
2229
|
+
Z.insertImage(e, "");
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
};
|
|
2233
|
+
E.addEventListener("change", () => {
|
|
2234
|
+
D([...E.files ?? []]), E.value = "";
|
|
2235
|
+
});
|
|
2236
|
+
let O, k = (e) => {
|
|
2237
|
+
let t = e(O.state, O.view.dispatch);
|
|
2238
|
+
return O.view.focus(), t;
|
|
2239
|
+
}, _e = S.create({
|
|
2240
|
+
name: "mdShortcuts",
|
|
2241
|
+
addInputRules() {
|
|
2242
|
+
let e = (e, t) => new ne({
|
|
2243
|
+
find: e,
|
|
2244
|
+
handler: ({ state: e, range: n, match: r, chain: i }) => {
|
|
2245
|
+
let { $from: a } = e.selection;
|
|
2246
|
+
if (a.depth !== 1 || a.parent.type.name !== "paragraph") return null;
|
|
2247
|
+
i().deleteRange(n).command(({ state: e, dispatch: n }) => t(r)(e, n)).run();
|
|
2248
|
+
}
|
|
2249
|
+
}), t = (e) => (t, n) => {
|
|
2250
|
+
let r = null;
|
|
2251
|
+
if (!z("ordered")(t, (e) => r = e) || !r) return !1;
|
|
2252
|
+
let i = Number(e[1]), a = r, { $from: o } = a.selection;
|
|
2253
|
+
return i !== 1 && o.parent.type.name === "mdItem" && a.setNodeMarkup(o.before(), void 0, {
|
|
2254
|
+
...o.parent.attrs,
|
|
2255
|
+
start: i
|
|
2256
|
+
}), n?.(a), !0;
|
|
2257
|
+
}, n = new ne({
|
|
2258
|
+
find: /^\[([ xX]?)\]\s$/,
|
|
2259
|
+
handler: ({ state: e, range: t, match: n, chain: r }) => {
|
|
2260
|
+
let { $from: i } = e.selection;
|
|
2261
|
+
if (i.parent.type.name !== "mdItem") return null;
|
|
2262
|
+
let a = i.before(), o = {
|
|
2263
|
+
...i.parent.attrs,
|
|
2264
|
+
checked: /x/i.test(n[1] ?? ""),
|
|
2265
|
+
ordered: !1
|
|
2266
|
+
};
|
|
2267
|
+
r().deleteRange(t).command(({ tr: e }) => (e.setNodeMarkup(a, void 0, o), !0)).run();
|
|
2268
|
+
}
|
|
2269
|
+
});
|
|
2270
|
+
return [
|
|
2271
|
+
e(/^[-*+]\s$/, () => z("bullet")),
|
|
2272
|
+
e(/^(\d{1,9})[.)]\s$/, t),
|
|
2273
|
+
e(/^\[([ xX]?)\]\s$/, (e) => (t, n) => {
|
|
2274
|
+
let r = null;
|
|
2275
|
+
if (!z("task")(t, (e) => r = e) || !r) return !1;
|
|
2276
|
+
let i = r, { $from: a } = i.selection;
|
|
2277
|
+
return /x/i.test(e[1] ?? "") && a.parent.type.name === "mdItem" && i.setNodeMarkup(a.before(), void 0, {
|
|
2278
|
+
...a.parent.attrs,
|
|
2279
|
+
checked: !0
|
|
2280
|
+
}), n?.(i), !0;
|
|
2281
|
+
}),
|
|
2282
|
+
n,
|
|
2283
|
+
e(/^##\s$/, () => I("sectionHead")),
|
|
2284
|
+
e(/^###\s$/, () => I("blockTitle")),
|
|
2285
|
+
e(/^>\s$/, () => I("mdNote"))
|
|
2286
|
+
];
|
|
2287
|
+
}
|
|
2288
|
+
}), ve = S.create({
|
|
2289
|
+
name: "mdKeys",
|
|
2290
|
+
addKeyboardShortcuts() {
|
|
2291
|
+
return {
|
|
2292
|
+
"Mod-k": () => (Re(), !0),
|
|
2293
|
+
"Mod-f": () => (Je(), !0),
|
|
2294
|
+
"Mod-Shift-7": () => k(z("ordered")),
|
|
2295
|
+
"Mod-Shift-8": () => k(z("bullet")),
|
|
2296
|
+
"Mod-Shift-9": () => k(z("task")),
|
|
2297
|
+
"Mod-Enter": () => k(Ve),
|
|
2298
|
+
"Mod-Alt-0": () => k(I("paragraph")),
|
|
2299
|
+
"Mod-Alt-2": () => k(I("sectionHead")),
|
|
2300
|
+
"Mod-Alt-3": () => k(I("blockTitle"))
|
|
2301
|
+
};
|
|
2302
|
+
}
|
|
2303
|
+
}), ye = (e, t, n, r) => {
|
|
2304
|
+
if (n || t.parent.type.spec.code || !nn.test(e)) return null;
|
|
2305
|
+
try {
|
|
2306
|
+
let t = (H(m(e, o)).content ?? []).map((e) => e.type === "docTitle" ? {
|
|
2307
|
+
...e,
|
|
2308
|
+
type: "sectionHead"
|
|
2309
|
+
} : e), n = r.state.schema.nodeFromJSON({
|
|
2310
|
+
type: "doc",
|
|
2311
|
+
content: t
|
|
2312
|
+
});
|
|
2313
|
+
return n.childCount === 1 && n.firstChild.type.name === "paragraph" ? new se(n.content, 1, 1) : se.maxOpen(n.content);
|
|
2314
|
+
} catch {
|
|
2315
|
+
return null;
|
|
2316
|
+
}
|
|
2317
|
+
};
|
|
2318
|
+
O = new te({
|
|
2319
|
+
element: re,
|
|
2320
|
+
extensions: [
|
|
2321
|
+
...Lt({
|
|
2322
|
+
resolveImage: de,
|
|
2323
|
+
messages: n
|
|
2324
|
+
}),
|
|
2325
|
+
_e,
|
|
2326
|
+
ve,
|
|
2327
|
+
tt,
|
|
2328
|
+
ct.configure({ label: (e) => X(n.pageLabel, { n: e }) }),
|
|
2329
|
+
...e.placeholder ? [ae.configure({ placeholder: e.placeholder })] : [],
|
|
2330
|
+
...e.extensions ?? []
|
|
2331
|
+
],
|
|
2332
|
+
content: pe,
|
|
2333
|
+
editable: e.editable ?? !0,
|
|
2334
|
+
editorProps: {
|
|
2335
|
+
attributes: {
|
|
2336
|
+
class: r,
|
|
2337
|
+
"aria-label": n.editorLabel,
|
|
2338
|
+
spellcheck: "false"
|
|
2339
|
+
},
|
|
2340
|
+
handlePaste: (t, n) => {
|
|
2341
|
+
if (e.maxLength || e.maxPaste) {
|
|
2342
|
+
let { from: e, to: r } = t.state.selection, i = ge(n.clipboardData).length, a = A.length - t.state.doc.textBetween(e, r, "\n").length + i;
|
|
2343
|
+
if (i && he(i, a, A.length)) return !0;
|
|
2344
|
+
}
|
|
2345
|
+
let r = rn(n.clipboardData);
|
|
2346
|
+
return r.length ? (D(r), !0) : !1;
|
|
2347
|
+
},
|
|
2348
|
+
handleDrop: (e, t, n, r) => {
|
|
2349
|
+
if (r) return !1;
|
|
2350
|
+
if (t.defaultPrevented) return !0;
|
|
2351
|
+
let i = rn(t.dataTransfer);
|
|
2352
|
+
if (!i.length) return !1;
|
|
2353
|
+
t.preventDefault();
|
|
2354
|
+
let a = e.posAtCoords({
|
|
2355
|
+
left: t.clientX,
|
|
2356
|
+
top: t.clientY
|
|
2357
|
+
});
|
|
2358
|
+
return a && O.commands.setTextSelection(a.pos), D(i), !0;
|
|
2359
|
+
},
|
|
2360
|
+
clipboardTextParser: ye
|
|
2361
|
+
},
|
|
2362
|
+
onUpdate: () => xe(),
|
|
2363
|
+
onTransaction: () => dt()
|
|
2364
|
+
});
|
|
2365
|
+
let A = fe ? e.markdown ?? "" : Ze(O.getJSON(), o), be = 0, xe = () => {
|
|
2366
|
+
A = Ze(O.getJSON(), o), _("change", A), e.onChange?.(A, Z), Ce(), j();
|
|
2367
|
+
}, Se = () => {
|
|
2368
|
+
if (l) try {
|
|
2369
|
+
let e = c === "source" ? m(A, o) : Xe(O.getJSON(), o);
|
|
2370
|
+
ce.innerHTML = f(e, { resolveImage: de });
|
|
2371
|
+
} catch (e) {
|
|
2372
|
+
ce.textContent = e instanceof ee ? Te(e) : String(e);
|
|
2373
|
+
}
|
|
2374
|
+
}, Ce = () => {
|
|
2375
|
+
l && (window.clearTimeout(be), be = window.setTimeout(Se, 120));
|
|
2376
|
+
}, j = () => {
|
|
2377
|
+
if (e.statusbar === !1) return;
|
|
2378
|
+
let t = c === "source" ? T.value : O.state.doc.textBetween(0, O.state.doc.content.size, "\n", "\n"), r = t.replace(/\n/g, "").length, i = (t.match(/\S+/g) ?? []).length, a = d && p && c === "wysiwyg" ? ` · ${X(n.pagesTotal, { n: p.total })}` : "";
|
|
2379
|
+
ue.textContent = `${X(n.chars, { n: r.toLocaleString() })} · ${X(n.words, { n: i.toLocaleString() })}${a}`;
|
|
2380
|
+
}, Te = (e) => {
|
|
2381
|
+
let t = X(n[e.code] ?? e.message, e.params);
|
|
2382
|
+
return e.line ? X(n.sourceError, {
|
|
2383
|
+
line: e.line,
|
|
2384
|
+
message: t
|
|
2385
|
+
}) : X(n.sourceErrorNoLine, { message: t });
|
|
2386
|
+
}, Oe = (e) => {
|
|
2387
|
+
w.hidden = !e, w.textContent = e ? Te(e) : "";
|
|
2388
|
+
}, je = () => {
|
|
2389
|
+
let e = O, t = e.state, n = t.selection.$from.parent;
|
|
2390
|
+
return {
|
|
2391
|
+
source: c === "source",
|
|
2392
|
+
editable: e.isEditable,
|
|
2393
|
+
kind: Pe(t),
|
|
2394
|
+
marks: n.type.allowsMarkType(t.schema.marks.bold),
|
|
2395
|
+
bold: e.isActive("bold"),
|
|
2396
|
+
italic: e.isActive("italic"),
|
|
2397
|
+
underline: e.isActive("underline"),
|
|
2398
|
+
strike: e.isActive("strike"),
|
|
2399
|
+
code: e.isActive("code"),
|
|
2400
|
+
sup: e.isActive("superscript"),
|
|
2401
|
+
sub: e.isActive("subscript"),
|
|
2402
|
+
highlight: e.isActive("mdHighlight"),
|
|
2403
|
+
shade: e.isActive("mdShade"),
|
|
2404
|
+
color: e.isActive("mdColor") ? e.getAttributes("mdColor").name ?? null : null,
|
|
2405
|
+
link: e.isActive("link") ? e.getAttributes("link").href ?? "" : null,
|
|
2406
|
+
list: Le(t),
|
|
2407
|
+
align: ze(t),
|
|
2408
|
+
inTable: e.isActive("table"),
|
|
2409
|
+
inCode: n.type.name === "codeBlock",
|
|
2410
|
+
canUndo: e.can().undo(),
|
|
2411
|
+
canRedo: e.can().redo()
|
|
2412
|
+
};
|
|
2413
|
+
}, Me = [], M = (e) => e.editable && !e.source, Ne = (e) => M(e) && e.marks;
|
|
2414
|
+
function P(e, t, r, i, a = {}) {
|
|
2415
|
+
let o = a.shortcut ? X(n.shortcut, {
|
|
2416
|
+
label: t,
|
|
2417
|
+
key: tn(a.shortcut)
|
|
2418
|
+
}) : t, s = Q("button", {
|
|
2419
|
+
className: `mde-btn${a.word ? " word" : ""}`,
|
|
2420
|
+
html: r,
|
|
2421
|
+
title: o,
|
|
2422
|
+
attrs: {
|
|
2423
|
+
type: "button",
|
|
2424
|
+
"data-name": e,
|
|
2425
|
+
"aria-label": t
|
|
2426
|
+
},
|
|
2427
|
+
on: { click: i }
|
|
2428
|
+
});
|
|
2429
|
+
return Me.push({ update: (e) => {
|
|
2430
|
+
s.disabled = !(a.enabled ?? M)(e), a.pressed && s.setAttribute("aria-pressed", String(a.pressed(e)));
|
|
2431
|
+
} }), s;
|
|
2432
|
+
}
|
|
2433
|
+
function F(e, t, r, i, a = {}) {
|
|
2434
|
+
let o = Q("button", {
|
|
2435
|
+
className: "mde-btn",
|
|
2436
|
+
title: a.shortcut ? X(n.shortcut, {
|
|
2437
|
+
label: t,
|
|
2438
|
+
key: tn(a.shortcut)
|
|
2439
|
+
}) : t,
|
|
2440
|
+
attrs: {
|
|
2441
|
+
type: "button",
|
|
2442
|
+
"data-name": e,
|
|
2443
|
+
"aria-label": t
|
|
2444
|
+
}
|
|
2445
|
+
}), s = Rt(h, o, i), c = "";
|
|
2446
|
+
return Me.push({ update: (e) => {
|
|
2447
|
+
let t = r(e);
|
|
2448
|
+
t !== c && (o.innerHTML = c = t), o.disabled = !(a.enabled ?? M)(e), a.pressed && o.setAttribute("aria-pressed", String(a.pressed(e))), o.disabled && s.close();
|
|
2449
|
+
} }), s;
|
|
2450
|
+
}
|
|
2451
|
+
let Fe = (e, t) => `<${t} class="mde-glyph">${e}</${t}>`, L = (e, t, n, r, i, a) => P(e, t, n, () => O.chain().focus().toggleMark(r).run(), {
|
|
2452
|
+
pressed: i,
|
|
2453
|
+
enabled: Ne,
|
|
2454
|
+
shortcut: a
|
|
2455
|
+
}), Ie = [
|
|
2456
|
+
["paragraph", "paragraph"],
|
|
2457
|
+
["sectionHead", "sectionHead"],
|
|
2458
|
+
["blockTitle", "blockTitle"],
|
|
2459
|
+
["list", "list"],
|
|
2460
|
+
["mdNote", "note"],
|
|
2461
|
+
["codeBlock", "codeBlock"],
|
|
2462
|
+
["docTitle", "docTitle"]
|
|
2463
|
+
], R = null;
|
|
2464
|
+
function Re() {
|
|
2465
|
+
R && !R.button.disabled && R.open();
|
|
2466
|
+
}
|
|
2467
|
+
let He = () => {
|
|
2468
|
+
let { state: e } = O, { from: t, to: n, empty: r } = e.selection, i = e.tr;
|
|
2469
|
+
for (let a of Object.values(e.schema.marks)) a.name !== "link" && (r || i.removeMark(t, n, a));
|
|
2470
|
+
i.setStoredMarks([]), O.view.dispatch(i), O.view.focus();
|
|
2471
|
+
}, B = {
|
|
2472
|
+
undo: () => P("undo", n.undo, $("undo"), () => O.chain().focus().undo().run(), {
|
|
2473
|
+
enabled: (e) => M(e) && e.canUndo,
|
|
2474
|
+
shortcut: "Z"
|
|
2475
|
+
}),
|
|
2476
|
+
redo: () => P("redo", n.redo, $("redo"), () => O.chain().focus().redo().run(), {
|
|
2477
|
+
enabled: (e) => M(e) && e.canRedo,
|
|
2478
|
+
shortcut: "Shift+Z"
|
|
2479
|
+
}),
|
|
2480
|
+
blockKind: () => {
|
|
2481
|
+
let e = Q("select", {
|
|
2482
|
+
className: "mde-select",
|
|
2483
|
+
attrs: {
|
|
2484
|
+
"aria-label": n.blockKind,
|
|
2485
|
+
"data-name": "blockKind"
|
|
2486
|
+
}
|
|
2487
|
+
}), t = Q("option", {
|
|
2488
|
+
text: n.tableOrImage,
|
|
2489
|
+
attrs: { value: "" }
|
|
2490
|
+
});
|
|
2491
|
+
return e.append(t, ...Ie.map(([e, t]) => Q("option", {
|
|
2492
|
+
text: n[t],
|
|
2493
|
+
attrs: { value: e }
|
|
2494
|
+
}))), e.addEventListener("change", () => {
|
|
2495
|
+
let t = e.value;
|
|
2496
|
+
t && Pe(O.state) !== t && I(t)(O.state, O.view.dispatch), O.view.focus();
|
|
2497
|
+
}), Me.push({ update: (n) => {
|
|
2498
|
+
t.hidden = !!n.kind, e.value = n.kind ?? "", e.disabled = !M(n) || !n.kind;
|
|
2499
|
+
} }), e;
|
|
2500
|
+
},
|
|
2501
|
+
bold: () => L("bold", n.bold, Fe("B", "b"), "bold", (e) => e.bold, "B"),
|
|
2502
|
+
italic: () => L("italic", n.italic, Fe("I", "i"), "italic", (e) => e.italic, "I"),
|
|
2503
|
+
underline: () => L("underline", n.underline, Fe("U", "u"), "underline", (e) => e.underline, "U"),
|
|
2504
|
+
strike: () => L("strike", n.strike, Fe("S", "s"), "strike", (e) => e.strike, "Shift+S"),
|
|
2505
|
+
code: () => L("code", n.code, $("code"), "code", (e) => e.code, "E"),
|
|
2506
|
+
superscript: () => L("superscript", n.superscript, "<span class=\"mde-glyph\">x<sup>2</sup></span>", "superscript", (e) => e.sup, "."),
|
|
2507
|
+
subscript: () => L("subscript", n.subscript, "<span class=\"mde-glyph\">x<sub>2</sub></span>", "subscript", (e) => e.sub, ","),
|
|
2508
|
+
highlight: () => L("highlight", n.highlight, $("highlight"), "mdHighlight", (e) => e.highlight, "Shift+H"),
|
|
2509
|
+
removeFormat: () => P("removeFormat", n.removeFormat, $("removeFormat"), He, { enabled: Ne }),
|
|
2510
|
+
color: () => F("color", n.textColor, (e) => Wt(i === "en" ? "A" : "가", e.color, e.shade), (e) => {
|
|
2511
|
+
let t = je();
|
|
2512
|
+
return Gt(n, t.color, t.shade, !0, (t) => (e(), t ? O.chain().focus().setMark("mdColor", { name: t }).run() : O.chain().focus().unsetMark("mdColor").run()), () => (e(), O.chain().focus().toggleMark("mdShade").run()));
|
|
2513
|
+
}, { enabled: Ne }).wrap,
|
|
2514
|
+
link: () => (R = F("link", n.link, () => $("link"), (e) => {
|
|
2515
|
+
let t = je(), r = O.state.selection.empty && t.link === null;
|
|
2516
|
+
return Kt(n, t.link, r, (t, n) => {
|
|
2517
|
+
if (e(), r) {
|
|
2518
|
+
let e = n || t;
|
|
2519
|
+
O.chain().focus().insertContent({
|
|
2520
|
+
type: "text",
|
|
2521
|
+
text: e,
|
|
2522
|
+
marks: [{
|
|
2523
|
+
type: "link",
|
|
2524
|
+
attrs: { href: t }
|
|
2525
|
+
}]
|
|
2526
|
+
}).run();
|
|
2527
|
+
} else O.chain().focus().extendMarkRange("link").setLink({ href: t }).run();
|
|
2528
|
+
}, t.link === null ? null : () => (e(), O.chain().focus().extendMarkRange("link").unsetLink().run()));
|
|
2529
|
+
}, {
|
|
2530
|
+
enabled: Ne,
|
|
2531
|
+
pressed: (e) => e.link !== null,
|
|
2532
|
+
shortcut: "K"
|
|
2533
|
+
}), R.wrap),
|
|
2534
|
+
bulletList: () => P("bulletList", n.bulletList, $("bulletList"), () => k(z("bullet")), {
|
|
2535
|
+
pressed: (e) => e.list === "bullet",
|
|
2536
|
+
shortcut: "Shift+8"
|
|
2537
|
+
}),
|
|
2538
|
+
orderedList: () => P("orderedList", n.orderedList, $("orderedList"), () => k(z("ordered")), {
|
|
2539
|
+
pressed: (e) => e.list === "ordered",
|
|
2540
|
+
shortcut: "Shift+7"
|
|
2541
|
+
}),
|
|
2542
|
+
taskList: () => P("taskList", n.taskList, $("taskList"), () => k(z("task")), {
|
|
2543
|
+
pressed: (e) => e.list === "task",
|
|
2544
|
+
shortcut: "Shift+9"
|
|
2545
|
+
}),
|
|
2546
|
+
outdent: () => P("outdent", n.outdent, $("outdent"), () => k(N(-1)), { enabled: (e) => M(e) && e.list !== null }),
|
|
2547
|
+
indent: () => P("indent", n.indent, $("indent"), () => k(N(1)), { enabled: (e) => M(e) && e.list !== null }),
|
|
2548
|
+
align: () => F("align", n.align, (e) => $(Zt.find(([t]) => t === (e.align ?? "left"))?.[1] ?? "alignLeft") + "<span class=\"mde-caret\" aria-hidden=\"true\">▾</span>", (e) => Qt(n, ze(O.state), (t) => (e(), k(Be(t)))), { enabled: (e) => M(e) && e.align !== null }).wrap,
|
|
2549
|
+
table: () => F("table", n.insertTable, () => $("table"), (e) => qt(n, (t, n) => (e(), O.chain().focus().insertTable({
|
|
2550
|
+
rows: t,
|
|
2551
|
+
cols: n,
|
|
2552
|
+
withHeaderRow: !0
|
|
2553
|
+
}).run())), { enabled: (e) => M(e) && !e.inTable && !e.inCode }).wrap,
|
|
2554
|
+
image: () => a.pick ? P("image", n.insertImage, $("image"), () => a.pick(), { enabled: (e) => M(e) && !e.inTable }) : F("image", n.insertImage, () => $("image"), (e) => Xt(n, (t, n) => (e(), Z.insertImage(t, n)), () => (e(), E.click())), { enabled: (e) => M(e) && !e.inTable }).wrap,
|
|
2555
|
+
codeBlock: () => P("codeBlock", n.codeBlock, $("codeBlock"), () => k(I("codeBlock")), {
|
|
2556
|
+
pressed: (e) => e.kind === "codeBlock",
|
|
2557
|
+
enabled: (e) => M(e) && !!e.kind,
|
|
2558
|
+
shortcut: "Alt+C"
|
|
2559
|
+
}),
|
|
2560
|
+
horizontalRule: () => P("horizontalRule", n.horizontalRule, $("horizontalRule"), () => O.chain().focus().setHorizontalRule().run(), { enabled: (e) => M(e) && !e.inTable }),
|
|
2561
|
+
pageBreak: () => P("pageBreak", n.pageBreak, $("pageBreak"), () => k(Ve), {
|
|
2562
|
+
enabled: (e) => M(e) && !e.inTable,
|
|
2563
|
+
shortcut: "Enter"
|
|
2564
|
+
}),
|
|
2565
|
+
specialChars: () => F("specialChars", n.specialChars, () => "<span class=\"mde-glyph\">Ω</span>", (e) => Yt(n, (t) => (e(), O.chain().focus().insertContent(t).run())), { enabled: (e) => M(e) }).wrap,
|
|
2566
|
+
find: () => P("find", n.findReplace, $("find"), () => x.hidden ? Je() : Ye(), {
|
|
2567
|
+
pressed: () => !x.hidden,
|
|
2568
|
+
shortcut: "F"
|
|
2569
|
+
}),
|
|
2570
|
+
source: () => P("source", n.source, "<span class=\"mde-glyph mde-md\">MD</span>", () => Z.setMode(c === "source" ? "wysiwyg" : "source"), {
|
|
2571
|
+
pressed: (e) => e.source,
|
|
2572
|
+
enabled: () => !0
|
|
2573
|
+
}),
|
|
2574
|
+
preview: () => P("preview", n.preview, $("preview"), () => Z.setPreview(!l), {
|
|
2575
|
+
pressed: () => l,
|
|
2576
|
+
enabled: () => !0
|
|
2577
|
+
}),
|
|
2578
|
+
pageMarks: () => P("pageMarks", n.pageMarks, $("pages"), () => Z.setPageMarksVisible(!d), {
|
|
2579
|
+
pressed: () => d,
|
|
2580
|
+
enabled: (e) => !e.source
|
|
2581
|
+
}),
|
|
2582
|
+
fullscreen: () => {
|
|
2583
|
+
let e = P("fullscreen", n.fullscreen, $("fullscreen"), () => Z.setFullscreen(!u), {
|
|
2584
|
+
pressed: () => u,
|
|
2585
|
+
enabled: () => !0
|
|
2586
|
+
});
|
|
2587
|
+
return Me.push({ update: () => {
|
|
2588
|
+
let t = u ? n.fullscreenExit : n.fullscreen;
|
|
2589
|
+
e.getAttribute("aria-label") !== t && (e.innerHTML = $(u ? "fullscreenExit" : "fullscreen"), e.title = t, e.setAttribute("aria-label", t));
|
|
2590
|
+
} }), e;
|
|
2591
|
+
}
|
|
2592
|
+
}, V = Q("input", {
|
|
2593
|
+
className: "mde-input",
|
|
2594
|
+
attrs: {
|
|
2595
|
+
type: "search",
|
|
2596
|
+
placeholder: n.findPlaceholder,
|
|
2597
|
+
"aria-label": n.find,
|
|
2598
|
+
spellcheck: "false"
|
|
2599
|
+
}
|
|
2600
|
+
}), Ue = Q("input", {
|
|
2601
|
+
className: "mde-input",
|
|
2602
|
+
attrs: {
|
|
2603
|
+
type: "text",
|
|
2604
|
+
placeholder: n.replacePlaceholder,
|
|
2605
|
+
"aria-label": n.replacePlaceholder,
|
|
2606
|
+
spellcheck: "false"
|
|
2607
|
+
}
|
|
2608
|
+
}), We = Q("span", { className: "mde-find-count" }), Ge = Q("input", { attrs: { type: "checkbox" } }), U = (e, t, n, r = !1) => Q("button", {
|
|
2609
|
+
className: `mde-btn${r ? " word" : ""}`,
|
|
2610
|
+
html: t,
|
|
2611
|
+
title: e,
|
|
2612
|
+
attrs: {
|
|
2613
|
+
type: "button",
|
|
2614
|
+
"aria-label": e
|
|
2615
|
+
},
|
|
2616
|
+
on: { click: n }
|
|
2617
|
+
}), Ke = (e) => {
|
|
2618
|
+
let t = rt(O.state, e);
|
|
2619
|
+
t && O.view.dispatch(t);
|
|
2620
|
+
};
|
|
2621
|
+
x.append(V, We, U(n.findPrev, $("chevronUp"), () => Ke(-1)), U(n.findNext, $("chevronDown"), () => Ke(1)), Q("label", { className: "mde-check-label" }, Ge, n.matchCase), Q("span", { className: "mde-sep" }), Ue, U(n.replace, n.replace, () => {
|
|
2622
|
+
let e = it(O.state, Ue.value);
|
|
2623
|
+
e && O.view.dispatch(e);
|
|
2624
|
+
}, !0), U(n.replaceAll, n.replaceAll, () => {
|
|
2625
|
+
let e = at(O.state, Ue.value);
|
|
2626
|
+
e && O.view.dispatch(e);
|
|
2627
|
+
}, !0), Q("span", { className: "mde-spacer" }), U(n.close, $("close"), () => Ye()));
|
|
2628
|
+
let qe = () => O.view.dispatch(nt(O.state, {
|
|
2629
|
+
query: V.value,
|
|
2630
|
+
caseSensitive: Ge.checked
|
|
2631
|
+
}));
|
|
2632
|
+
V.addEventListener("input", qe), Ge.addEventListener("change", qe), V.addEventListener("keydown", (e) => {
|
|
2633
|
+
e.key === "Enter" ? (e.preventDefault(), Ke(e.shiftKey ? -1 : 1)) : e.key === "Escape" && Ye();
|
|
2634
|
+
}), Ue.addEventListener("keydown", (e) => e.key === "Escape" && Ye());
|
|
2635
|
+
function Je() {
|
|
2636
|
+
if (c === "source") return;
|
|
2637
|
+
x.hidden = !1;
|
|
2638
|
+
let { from: e, to: t, empty: n } = O.state.selection;
|
|
2639
|
+
!n && t - e < 200 && (V.value = O.state.doc.textBetween(e, t, " "), qe()), V.focus(), V.select(), Y();
|
|
2640
|
+
}
|
|
2641
|
+
function Ye() {
|
|
2642
|
+
x.hidden = !0, O.view.dispatch(nt(O.state, { query: "" })), O.view.focus();
|
|
2643
|
+
}
|
|
2644
|
+
let Qe = () => {
|
|
2645
|
+
let e = G.getState(O.state);
|
|
2646
|
+
e?.query ? We.textContent = e.matches.length ? X(n.findCount, {
|
|
2647
|
+
i: e.index + 1,
|
|
2648
|
+
n: e.matches.length
|
|
2649
|
+
}) : n.findNone : We.textContent = "";
|
|
2650
|
+
}, W = (e, t, n) => Q("button", {
|
|
2651
|
+
className: "mde-btn word",
|
|
2652
|
+
text: e,
|
|
2653
|
+
title: n ?? e,
|
|
2654
|
+
attrs: { type: "button" },
|
|
2655
|
+
on: { click: t }
|
|
2656
|
+
}), $e = Q("div", {
|
|
2657
|
+
className: "mde-bar mde-table-bar",
|
|
2658
|
+
attrs: {
|
|
2659
|
+
role: "toolbar",
|
|
2660
|
+
"aria-label": n.tableToolbar
|
|
2661
|
+
}
|
|
2662
|
+
}, Q("span", {
|
|
2663
|
+
className: "mde-bar-label",
|
|
2664
|
+
text: n.table
|
|
2665
|
+
}), W(n.rowAbove, () => k(Ae)), W(n.rowBelow, () => k(ke)), W(n.colLeft, () => O.chain().focus().addColumnBefore().run()), W(n.colRight, () => O.chain().focus().addColumnAfter().run()), W(n.deleteRow, () => O.chain().focus().deleteRow().run()), W(n.deleteCol, () => O.chain().focus().deleteColumn().run()), Q("span", { className: "mde-sep" }), W(n.mergeCells, () => k(we), n.mergeHint), W(n.splitCell, () => O.chain().focus().splitCell().run()), W(n.cellShade, () => k(De)), Q("span", { className: "mde-sep" }), W(n.colLeftAlign, () => k(Ee("left")), X(n.colAlignTitle, { side: n.colLeftAlign })), W(n.colCenterAlign, () => k(Ee("center")), X(n.colAlignTitle, { side: n.colCenterAlign })), W(n.colRightAlign, () => k(Ee("right")), X(n.colAlignTitle, { side: n.colRightAlign })), Q("span", { className: "mde-sep" }), W(n.deleteTable, () => O.chain().focus().deleteTable().run())), K = Q("input", {
|
|
2666
|
+
className: "mde-input mde-lang",
|
|
2667
|
+
attrs: {
|
|
2668
|
+
type: "text",
|
|
2669
|
+
list: "mde-langs",
|
|
2670
|
+
placeholder: n.codeLanguageNone,
|
|
2671
|
+
"aria-label": n.codeLanguage,
|
|
2672
|
+
spellcheck: "false"
|
|
2673
|
+
}
|
|
2674
|
+
}), et = Q("datalist", { attrs: { id: "mde-langs" } }, ...(/* @__PURE__ */ "js.ts.jsx.tsx.json.html.css.py.java.kotlin.swift.go.rust.c.cpp.cs.php.ruby.sql.bash.sh.yaml.toml.xml.md.diff.text".split(".")).map((e) => Q("option", { attrs: { value: e } })));
|
|
2675
|
+
K.addEventListener("change", () => {
|
|
2676
|
+
let e = K.value.trim().split(/\s+/)[0]?.replace(/`/g, "") || null;
|
|
2677
|
+
O.chain().updateAttributes("codeBlock", { language: e }).run();
|
|
2678
|
+
}), K.addEventListener("keydown", (e) => {
|
|
2679
|
+
e.key === "Enter" && (e.preventDefault(), K.dispatchEvent(new Event("change")), O.view.focus());
|
|
2680
|
+
});
|
|
2681
|
+
let ot = Q("div", {
|
|
2682
|
+
className: "mde-bar mde-code-bar",
|
|
2683
|
+
attrs: {
|
|
2684
|
+
role: "toolbar",
|
|
2685
|
+
"aria-label": n.codeBlock
|
|
2686
|
+
}
|
|
2687
|
+
}, Q("span", {
|
|
2688
|
+
className: "mde-bar-label",
|
|
2689
|
+
text: n.codeBlock
|
|
2690
|
+
}), Q("label", { className: "mde-check-label" }, n.codeLanguage, K, et)), q = (e) => {
|
|
2691
|
+
let t = e.target;
|
|
2692
|
+
t.closest("button") && !t.closest(".mde-pop") && e.preventDefault();
|
|
2693
|
+
};
|
|
2694
|
+
y.addEventListener("mousedown", q), C.addEventListener("mousedown", q);
|
|
2695
|
+
let st = 0, ut = null, J = 0;
|
|
2696
|
+
function dt() {
|
|
2697
|
+
J ||= requestAnimationFrame(() => {
|
|
2698
|
+
J = 0, Y();
|
|
2699
|
+
});
|
|
2700
|
+
}
|
|
2701
|
+
function Y() {
|
|
2702
|
+
if (J &&= (cancelAnimationFrame(J), 0), !O || O.isDestroyed) return;
|
|
2703
|
+
let e = je();
|
|
2704
|
+
for (let t of Me) t.update(e);
|
|
2705
|
+
let t = e.source ? null : e.inTable ? $e : e.inCode ? ot : null;
|
|
2706
|
+
if (t !== ut) {
|
|
2707
|
+
C.replaceChildren(...t ? [t] : []), ut = t;
|
|
2708
|
+
let e = C.offsetHeight, n = e - st;
|
|
2709
|
+
st = e, n && (ie.scrollTop += n);
|
|
2710
|
+
}
|
|
2711
|
+
e.inCode && document.activeElement !== K && (K.value = String(O.state.selection.$from.parent.attrs.language ?? "")), Qe();
|
|
2712
|
+
}
|
|
2713
|
+
T.addEventListener("input", () => {
|
|
2714
|
+
A = T.value, _("change", A), e.onChange?.(A, Z), Ce(), j();
|
|
2715
|
+
}), T.addEventListener("paste", (t) => {
|
|
2716
|
+
if (!e.maxLength && !e.maxPaste) return;
|
|
2717
|
+
let n = ge(t.clipboardData).length, r = T.value.length - (T.selectionEnd - T.selectionStart) + n;
|
|
2718
|
+
n && he(n, r, T.value.length) && t.preventDefault();
|
|
2719
|
+
}), T.addEventListener("keydown", (e) => {
|
|
2720
|
+
e.key === "Tab" && !e.shiftKey && (e.preventDefault(), document.execCommand("insertText", !1, " "));
|
|
2721
|
+
});
|
|
2722
|
+
let pt = (e) => {
|
|
2723
|
+
c = e, v.dataset.mode = e, ie.hidden = e === "source", T.hidden = e !== "source", e === "source" && (x.hidden = !0), Y(), j(), Se(), _("mode", e);
|
|
2724
|
+
}, Z = {
|
|
2725
|
+
get tiptap() {
|
|
2726
|
+
return O;
|
|
2727
|
+
},
|
|
2728
|
+
element: v,
|
|
2729
|
+
messages: n,
|
|
2730
|
+
getMarkdown: () => A,
|
|
2731
|
+
setMarkdown(e) {
|
|
2732
|
+
s || (o = t(e) ?? o);
|
|
2733
|
+
let n = m(e, o);
|
|
2734
|
+
Oe(null), O.commands.setContent(H(n), { emitUpdate: !1 }), A = Ze(O.getJSON(), o), c === "source" && (T.value = e), Ce(), j();
|
|
2735
|
+
},
|
|
2736
|
+
getDoc: () => c === "source" ? m(A, o) : Xe(O.getJSON(), o),
|
|
2737
|
+
setDoc(e) {
|
|
2738
|
+
!s && e.dialect && (o = e.dialect), O.commands.setContent(H(e), { emitUpdate: !1 }), A = Ze(O.getJSON(), o), c === "source" && (T.value = A), Ce(), j();
|
|
2739
|
+
},
|
|
2740
|
+
getHTML: () => f(Z.getDoc(), { resolveImage: de }),
|
|
2741
|
+
insertImage(e, t = "") {
|
|
2742
|
+
if (c === "source") {
|
|
2743
|
+
let n = T.selectionEnd, r = ``;
|
|
2744
|
+
T.setRangeText(`\n\n${r}\n`, n, n, "end"), T.dispatchEvent(new Event("input"));
|
|
2745
|
+
} else O.chain().focus().insertContent({
|
|
2746
|
+
type: "mdImage",
|
|
2747
|
+
attrs: {
|
|
2748
|
+
src: e,
|
|
2749
|
+
caption: t
|
|
2750
|
+
}
|
|
2751
|
+
}).run();
|
|
2752
|
+
},
|
|
2753
|
+
replaceImage(e, t) {
|
|
2754
|
+
if (c === "source") {
|
|
2755
|
+
let n = t ? T.value.split(e).join(t) : T.value.split("\n").filter((t) => !t.includes(`](${e})`)).join("\n");
|
|
2756
|
+
n !== T.value && (T.value = n, T.dispatchEvent(new Event("input")));
|
|
2757
|
+
return;
|
|
2758
|
+
}
|
|
2759
|
+
let n = [];
|
|
2760
|
+
if (O.state.doc.descendants((t, r) => {
|
|
2761
|
+
t.type.name === "mdImage" && t.attrs.src === e && n.push({
|
|
2762
|
+
pos: r,
|
|
2763
|
+
size: t.nodeSize,
|
|
2764
|
+
attrs: t.attrs
|
|
2765
|
+
});
|
|
2766
|
+
}), !n.length) return;
|
|
2767
|
+
let r = O.state.tr;
|
|
2768
|
+
for (let e of n.reverse()) t ? r.setNodeMarkup(e.pos, void 0, {
|
|
2769
|
+
...e.attrs,
|
|
2770
|
+
src: t
|
|
2771
|
+
}) : r.delete(e.pos, e.pos + e.size);
|
|
2772
|
+
O.view.dispatch(r.setMeta("addToHistory", !1));
|
|
2773
|
+
},
|
|
2774
|
+
refreshImages() {
|
|
2775
|
+
let e = O.state.tr;
|
|
2776
|
+
O.state.doc.descendants((t, n) => {
|
|
2777
|
+
t.type.name === "mdImage" && e.setNodeMarkup(n, void 0, { ...t.attrs });
|
|
2778
|
+
}), e.steps.length && O.view.dispatch(e.setMeta("addToHistory", !1).setMeta("preventUpdate", !0)), Ce();
|
|
2779
|
+
},
|
|
2780
|
+
getMode: () => c,
|
|
2781
|
+
setMode(n) {
|
|
2782
|
+
if (n === c) return !0;
|
|
2783
|
+
if (h.current?.close(), n === "source") return T.value = A, pt("source"), T.focus(), !0;
|
|
2784
|
+
try {
|
|
2785
|
+
s || (o = t(T.value) ?? o);
|
|
2786
|
+
let e = m(T.value, o);
|
|
2787
|
+
O.commands.setContent(H(e), { emitUpdate: !1 });
|
|
2788
|
+
} catch (e) {
|
|
2789
|
+
if (e instanceof ee) return Oe(e), !1;
|
|
2790
|
+
throw e;
|
|
2791
|
+
}
|
|
2792
|
+
Oe(null);
|
|
2793
|
+
let r = A;
|
|
2794
|
+
return A = Ze(O.getJSON(), o), pt("wysiwyg"), A !== r && (_("change", A), e.onChange?.(A, Z)), O.commands.focus(), !0;
|
|
2795
|
+
},
|
|
2796
|
+
isPreview: () => l,
|
|
2797
|
+
setPreview(e) {
|
|
2798
|
+
l = e, v.dataset.preview = e ? "on" : "off", e && Se(), Y(), _("preview", e);
|
|
2799
|
+
},
|
|
2800
|
+
setPageMarks(e) {
|
|
2801
|
+
p = e, O.view.dispatch(lt(O.state, { marks: e })), j();
|
|
2802
|
+
},
|
|
2803
|
+
isPageMarksVisible: () => d,
|
|
2804
|
+
setPageMarksVisible(e) {
|
|
2805
|
+
e !== d && (d = e, v.dataset.pagemarks = e ? "on" : "off", O.view.dispatch(lt(O.state, { visible: e })), Y(), j(), _("pagemarks", e));
|
|
2806
|
+
},
|
|
2807
|
+
isFullscreen: () => u,
|
|
2808
|
+
setFullscreen(e) {
|
|
2809
|
+
u = e, v.classList.toggle("mde-fullscreen", e), document.documentElement.classList.toggle("mde-noscroll", e), Y(), _("fullscreen", e);
|
|
2810
|
+
},
|
|
2811
|
+
setEditable(e) {
|
|
2812
|
+
O.setEditable(e), T.readOnly = !e, Y();
|
|
2813
|
+
},
|
|
2814
|
+
setDialect(e) {
|
|
2815
|
+
e !== o && (o = e, c === "wysiwyg" && (A = Ze(O.getJSON(), o)));
|
|
2816
|
+
},
|
|
2817
|
+
slot: (e) => b[e],
|
|
2818
|
+
focus: () => c === "source" ? T.focus() : O.commands.focus(),
|
|
2819
|
+
on(e, t) {
|
|
2820
|
+
return g[e].add(t), () => g[e].delete(t);
|
|
2821
|
+
},
|
|
2822
|
+
destroy() {
|
|
2823
|
+
window.clearTimeout(be), window.clearTimeout(me), J && cancelAnimationFrame(J), h.current?.close(), document.removeEventListener("keydown", _t), document.documentElement.classList.remove("mde-noscroll"), O.destroy(), v.remove();
|
|
2824
|
+
}
|
|
2825
|
+
};
|
|
2826
|
+
y.append(b.start);
|
|
2827
|
+
let mt = e.toolbar === !1 ? [] : e.toolbar ?? $t, ht = Q("span", { className: "mde-group" }), gt = () => {
|
|
2828
|
+
ht.childNodes.length && y.append(ht), ht = Q("span", { className: "mde-group" });
|
|
2829
|
+
};
|
|
2830
|
+
for (let e of mt) {
|
|
2831
|
+
if (e === "|") {
|
|
2832
|
+
gt(), y.append(Q("span", {
|
|
2833
|
+
className: "mde-sep",
|
|
2834
|
+
attrs: { role: "separator" }
|
|
2835
|
+
}));
|
|
2836
|
+
continue;
|
|
2837
|
+
}
|
|
2838
|
+
let t = typeof e == "string" ? B[e]?.() : e.render(Z);
|
|
2839
|
+
t && ht.append(t);
|
|
2840
|
+
}
|
|
2841
|
+
gt(), y.append(b.end);
|
|
2842
|
+
let _t = (e) => {
|
|
2843
|
+
e.key === "Escape" && u && !h.current && Z.setFullscreen(!1);
|
|
2844
|
+
};
|
|
2845
|
+
return document.addEventListener("keydown", _t), v.dataset.preview = l ? "on" : "off", v.dataset.pagemarks = d ? "on" : "off", d && O.view.dispatch(lt(O.state, { visible: !0 })), fe ? (T.value = e.markdown ?? "", pt("source"), Oe(fe)) : e.mode === "source" ? (T.value = A, pt("source")) : (Y(), j(), Se()), Z;
|
|
2846
|
+
}
|
|
2847
|
+
export { xe as C, H as S, B as _, dt as a, Je as b, tt as c, G as d, Qe as f, U as g, Ze as h, Lt as i, $e as l, q as m, on as n, J as o, ot as p, jt as r, ft as s, $t as t, ct as u, Xe as v, Ke as x, qe as y };
|