tiptap-extension-code-block-shiki 0.1.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.
@@ -0,0 +1,1393 @@
|
|
1
|
+
import { Plugin as B, PluginKey as N, Selection as P, TextSelection as S, NodeSelection as ae } from "@tiptap/pm/state";
|
2
|
+
import { DecorationSet as ge, Decoration as ke } from "@tiptap/pm/view";
|
3
|
+
import "@tiptap/pm/keymap";
|
4
|
+
import { Fragment as F, Slice as ye, DOMParser as we } from "@tiptap/pm/model";
|
5
|
+
import { liftTarget as xe, joinPoint as ce, canSplit as L, ReplaceStep as be, ReplaceAroundStep as Se, canJoin as le } from "@tiptap/pm/transform";
|
6
|
+
import { createParagraphNear as Me, deleteSelection as Ae, exitCode as Te, joinUp as Ce, joinDown as ve, joinBackward as Ee, joinForward as Ie, joinTextblockBackward as $e, joinTextblockForward as Be, lift as Ne, liftEmptyBlock as Oe, newlineInCode as Pe, selectNodeBackward as je, selectNodeForward as Fe, selectParentNode as Le, selectTextblockEnd as Re, selectTextblockStart as ze, setBlockType as ee, wrapIn as De } from "@tiptap/pm/commands";
|
7
|
+
import { liftListItem as We, sinkListItem as Ke, wrapInList as He } from "@tiptap/pm/schema-list";
|
8
|
+
import { getHighlighter as Ve, bundledLanguages as _e, bundledThemes as Je } from "shiki";
|
9
|
+
function de(t) {
|
10
|
+
const { state: e, transaction: n } = t;
|
11
|
+
let { selection: r } = n, { doc: o } = n, { storedMarks: s } = n;
|
12
|
+
return {
|
13
|
+
...e,
|
14
|
+
apply: e.apply.bind(e),
|
15
|
+
applyTransaction: e.applyTransaction.bind(e),
|
16
|
+
plugins: e.plugins,
|
17
|
+
schema: e.schema,
|
18
|
+
reconfigure: e.reconfigure.bind(e),
|
19
|
+
toJSON: e.toJSON.bind(e),
|
20
|
+
get storedMarks() {
|
21
|
+
return s;
|
22
|
+
},
|
23
|
+
get selection() {
|
24
|
+
return r;
|
25
|
+
},
|
26
|
+
get doc() {
|
27
|
+
return o;
|
28
|
+
},
|
29
|
+
get tr() {
|
30
|
+
return r = n.selection, o = n.doc, s = n.storedMarks, n;
|
31
|
+
}
|
32
|
+
};
|
33
|
+
}
|
34
|
+
class Ge {
|
35
|
+
constructor(e) {
|
36
|
+
this.editor = e.editor, this.rawCommands = this.editor.extensionManager.commands, this.customState = e.state;
|
37
|
+
}
|
38
|
+
get hasCustomState() {
|
39
|
+
return !!this.customState;
|
40
|
+
}
|
41
|
+
get state() {
|
42
|
+
return this.customState || this.editor.state;
|
43
|
+
}
|
44
|
+
get commands() {
|
45
|
+
const { rawCommands: e, editor: n, state: r } = this, { view: o } = n, { tr: s } = r, i = this.buildProps(s);
|
46
|
+
return Object.fromEntries(Object.entries(e).map(([a, c]) => [a, (...f) => {
|
47
|
+
const l = c(...f)(i);
|
48
|
+
return !s.getMeta("preventDispatch") && !this.hasCustomState && o.dispatch(s), l;
|
49
|
+
}]));
|
50
|
+
}
|
51
|
+
get chain() {
|
52
|
+
return () => this.createChain();
|
53
|
+
}
|
54
|
+
get can() {
|
55
|
+
return () => this.createCan();
|
56
|
+
}
|
57
|
+
createChain(e, n = !0) {
|
58
|
+
const { rawCommands: r, editor: o, state: s } = this, { view: i } = o, a = [], c = !!e, d = e || s.tr, f = () => (!c && n && !d.getMeta("preventDispatch") && !this.hasCustomState && i.dispatch(d), a.every((u) => u === !0)), l = {
|
59
|
+
...Object.fromEntries(Object.entries(r).map(([u, p]) => [u, (...h) => {
|
60
|
+
const g = this.buildProps(d, n), k = p(...h)(g);
|
61
|
+
return a.push(k), l;
|
62
|
+
}])),
|
63
|
+
run: f
|
64
|
+
};
|
65
|
+
return l;
|
66
|
+
}
|
67
|
+
createCan(e) {
|
68
|
+
const { rawCommands: n, state: r } = this, o = !1, s = e || r.tr, i = this.buildProps(s, o);
|
69
|
+
return {
|
70
|
+
...Object.fromEntries(Object.entries(n).map(([c, d]) => [c, (...f) => d(...f)({ ...i, dispatch: void 0 })])),
|
71
|
+
chain: () => this.createChain(s, o)
|
72
|
+
};
|
73
|
+
}
|
74
|
+
buildProps(e, n = !0) {
|
75
|
+
const { rawCommands: r, editor: o, state: s } = this, { view: i } = o, a = {
|
76
|
+
tr: e,
|
77
|
+
editor: o,
|
78
|
+
view: i,
|
79
|
+
state: de({
|
80
|
+
state: s,
|
81
|
+
transaction: e
|
82
|
+
}),
|
83
|
+
dispatch: n ? () => {
|
84
|
+
} : void 0,
|
85
|
+
chain: () => this.createChain(e, n),
|
86
|
+
can: () => this.createCan(e),
|
87
|
+
get commands() {
|
88
|
+
return Object.fromEntries(Object.entries(r).map(([c, d]) => [c, (...f) => d(...f)(a)]));
|
89
|
+
}
|
90
|
+
};
|
91
|
+
return a;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
function w(t, e, n) {
|
95
|
+
return t.config[e] === void 0 && t.parent ? w(t.parent, e, n) : typeof t.config[e] == "function" ? t.config[e].bind({
|
96
|
+
...n,
|
97
|
+
parent: t.parent ? w(t.parent, e, n) : null
|
98
|
+
}) : t.config[e];
|
99
|
+
}
|
100
|
+
function Ue(t) {
|
101
|
+
const e = t.filter((o) => o.type === "extension"), n = t.filter((o) => o.type === "node"), r = t.filter((o) => o.type === "mark");
|
102
|
+
return {
|
103
|
+
baseExtensions: e,
|
104
|
+
nodeExtensions: n,
|
105
|
+
markExtensions: r
|
106
|
+
};
|
107
|
+
}
|
108
|
+
function y(t, e) {
|
109
|
+
if (typeof t == "string") {
|
110
|
+
if (!e.nodes[t])
|
111
|
+
throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);
|
112
|
+
return e.nodes[t];
|
113
|
+
}
|
114
|
+
return t;
|
115
|
+
}
|
116
|
+
function qe(...t) {
|
117
|
+
return t.filter((e) => !!e).reduce((e, n) => {
|
118
|
+
const r = { ...e };
|
119
|
+
return Object.entries(n).forEach(([o, s]) => {
|
120
|
+
if (!r[o]) {
|
121
|
+
r[o] = s;
|
122
|
+
return;
|
123
|
+
}
|
124
|
+
if (o === "class") {
|
125
|
+
const a = s ? s.split(" ") : [], c = r[o] ? r[o].split(" ") : [], d = a.filter((f) => !c.includes(f));
|
126
|
+
r[o] = [...c, ...d].join(" ");
|
127
|
+
} else
|
128
|
+
o === "style" ? r[o] = [r[o], s].join("; ") : r[o] = s;
|
129
|
+
}), r;
|
130
|
+
}, {});
|
131
|
+
}
|
132
|
+
function Qe(t) {
|
133
|
+
return typeof t == "function";
|
134
|
+
}
|
135
|
+
function x(t, e = void 0, ...n) {
|
136
|
+
return Qe(t) ? e ? t.bind(e)(...n) : t(...n) : t;
|
137
|
+
}
|
138
|
+
function Xe(t) {
|
139
|
+
return Object.prototype.toString.call(t) === "[object RegExp]";
|
140
|
+
}
|
141
|
+
class Ye {
|
142
|
+
constructor(e) {
|
143
|
+
this.find = e.find, this.handler = e.handler;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
function Ze(t) {
|
147
|
+
return Object.prototype.toString.call(t).slice(8, -1);
|
148
|
+
}
|
149
|
+
function H(t) {
|
150
|
+
return Ze(t) !== "Object" ? !1 : t.constructor === Object && Object.getPrototypeOf(t) === Object.prototype;
|
151
|
+
}
|
152
|
+
function Q(t, e) {
|
153
|
+
const n = { ...t };
|
154
|
+
return H(t) && H(e) && Object.keys(e).forEach((r) => {
|
155
|
+
H(e[r]) ? r in t ? n[r] = Q(t[r], e[r]) : Object.assign(n, { [r]: e[r] }) : Object.assign(n, { [r]: e[r] });
|
156
|
+
}), n;
|
157
|
+
}
|
158
|
+
class T {
|
159
|
+
constructor(e = {}) {
|
160
|
+
this.type = "extension", this.name = "extension", this.parent = null, this.child = null, this.config = {
|
161
|
+
name: this.name,
|
162
|
+
defaultOptions: {}
|
163
|
+
}, this.config = {
|
164
|
+
...this.config,
|
165
|
+
...e
|
166
|
+
}, this.name = this.config.name, e.defaultOptions && Object.keys(e.defaultOptions).length > 0 && console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`), this.options = this.config.defaultOptions, this.config.addOptions && (this.options = x(w(this, "addOptions", {
|
167
|
+
name: this.name
|
168
|
+
}))), this.storage = x(w(this, "addStorage", {
|
169
|
+
name: this.name,
|
170
|
+
options: this.options
|
171
|
+
})) || {};
|
172
|
+
}
|
173
|
+
static create(e = {}) {
|
174
|
+
return new T(e);
|
175
|
+
}
|
176
|
+
configure(e = {}) {
|
177
|
+
const n = this.extend();
|
178
|
+
return n.options = Q(this.options, e), n.storage = x(w(n, "addStorage", {
|
179
|
+
name: n.name,
|
180
|
+
options: n.options
|
181
|
+
})), n;
|
182
|
+
}
|
183
|
+
extend(e = {}) {
|
184
|
+
const n = new T({ ...this.config, ...e });
|
185
|
+
return n.parent = this, this.child = n, n.name = e.name ? e.name : n.parent.name, e.defaultOptions && console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`), n.options = x(w(n, "addOptions", {
|
186
|
+
name: n.name
|
187
|
+
})), n.storage = x(w(n, "addStorage", {
|
188
|
+
name: n.name,
|
189
|
+
options: n.options
|
190
|
+
})), n;
|
191
|
+
}
|
192
|
+
}
|
193
|
+
function et(t, e, n) {
|
194
|
+
const { from: r, to: o } = e, { blockSeparator: s = `
|
195
|
+
|
196
|
+
`, textSerializers: i = {} } = n || {};
|
197
|
+
let a = "", c = !0;
|
198
|
+
return t.nodesBetween(r, o, (d, f, l, u) => {
|
199
|
+
var p;
|
200
|
+
const m = i == null ? void 0 : i[d.type.name];
|
201
|
+
if (m)
|
202
|
+
return d.isBlock && !c && (a += s, c = !0), l && (a += m({
|
203
|
+
node: d,
|
204
|
+
pos: f,
|
205
|
+
parent: l,
|
206
|
+
index: u,
|
207
|
+
range: e
|
208
|
+
})), !1;
|
209
|
+
d.isText ? (a += (p = d == null ? void 0 : d.text) === null || p === void 0 ? void 0 : p.slice(Math.max(r, f) - f, o - f), c = !1) : d.isBlock && !c && (a += s, c = !0);
|
210
|
+
}), a;
|
211
|
+
}
|
212
|
+
function tt(t) {
|
213
|
+
return Object.fromEntries(Object.entries(t.nodes).filter(([, e]) => e.spec.toText).map(([e, n]) => [e, n.spec.toText]));
|
214
|
+
}
|
215
|
+
T.create({
|
216
|
+
name: "clipboardTextSerializer",
|
217
|
+
addOptions() {
|
218
|
+
return {
|
219
|
+
blockSeparator: void 0
|
220
|
+
};
|
221
|
+
},
|
222
|
+
addProseMirrorPlugins() {
|
223
|
+
return [
|
224
|
+
new B({
|
225
|
+
key: new N("clipboardTextSerializer"),
|
226
|
+
props: {
|
227
|
+
clipboardTextSerializer: () => {
|
228
|
+
const { editor: t } = this, { state: e, schema: n } = t, { doc: r, selection: o } = e, { ranges: s } = o, i = Math.min(...s.map((f) => f.$from.pos)), a = Math.max(...s.map((f) => f.$to.pos)), c = tt(n);
|
229
|
+
return et(r, { from: i, to: a }, {
|
230
|
+
...this.options.blockSeparator !== void 0 ? { blockSeparator: this.options.blockSeparator } : {},
|
231
|
+
textSerializers: c
|
232
|
+
});
|
233
|
+
}
|
234
|
+
}
|
235
|
+
})
|
236
|
+
];
|
237
|
+
}
|
238
|
+
});
|
239
|
+
const nt = () => ({ editor: t, view: e }) => (requestAnimationFrame(() => {
|
240
|
+
var n;
|
241
|
+
t.isDestroyed || (e.dom.blur(), (n = window == null ? void 0 : window.getSelection()) === null || n === void 0 || n.removeAllRanges());
|
242
|
+
}), !0), rt = (t = !1) => ({ commands: e }) => e.setContent("", t), ot = () => ({ state: t, tr: e, dispatch: n }) => {
|
243
|
+
const { selection: r } = e, { ranges: o } = r;
|
244
|
+
return n && o.forEach(({ $from: s, $to: i }) => {
|
245
|
+
t.doc.nodesBetween(s.pos, i.pos, (a, c) => {
|
246
|
+
if (a.type.isText)
|
247
|
+
return;
|
248
|
+
const { doc: d, mapping: f } = e, l = d.resolve(f.map(c)), u = d.resolve(f.map(c + a.nodeSize)), p = l.blockRange(u);
|
249
|
+
if (!p)
|
250
|
+
return;
|
251
|
+
const m = xe(p);
|
252
|
+
if (a.type.isTextblock) {
|
253
|
+
const { defaultType: h } = l.parent.contentMatchAt(l.index());
|
254
|
+
e.setNodeMarkup(p.start, h);
|
255
|
+
}
|
256
|
+
(m || m === 0) && e.lift(p, m);
|
257
|
+
});
|
258
|
+
}), !0;
|
259
|
+
}, st = (t) => (e) => t(e), it = () => ({ state: t, dispatch: e }) => Me(t, e), at = (t, e) => ({ editor: n, tr: r }) => {
|
260
|
+
const { state: o } = n, s = o.doc.slice(t.from, t.to);
|
261
|
+
r.deleteRange(t.from, t.to);
|
262
|
+
const i = r.mapping.map(e);
|
263
|
+
return r.insert(i, s.content), r.setSelection(new S(r.doc.resolve(i - 1))), !0;
|
264
|
+
}, ct = () => ({ tr: t, dispatch: e }) => {
|
265
|
+
const { selection: n } = t, r = n.$anchor.node();
|
266
|
+
if (r.content.size > 0)
|
267
|
+
return !1;
|
268
|
+
const o = t.selection.$anchor;
|
269
|
+
for (let s = o.depth; s > 0; s -= 1)
|
270
|
+
if (o.node(s).type === r.type) {
|
271
|
+
if (e) {
|
272
|
+
const a = o.before(s), c = o.after(s);
|
273
|
+
t.delete(a, c).scrollIntoView();
|
274
|
+
}
|
275
|
+
return !0;
|
276
|
+
}
|
277
|
+
return !1;
|
278
|
+
}, lt = (t) => ({ tr: e, state: n, dispatch: r }) => {
|
279
|
+
const o = y(t, n.schema), s = e.selection.$anchor;
|
280
|
+
for (let i = s.depth; i > 0; i -= 1)
|
281
|
+
if (s.node(i).type === o) {
|
282
|
+
if (r) {
|
283
|
+
const c = s.before(i), d = s.after(i);
|
284
|
+
e.delete(c, d).scrollIntoView();
|
285
|
+
}
|
286
|
+
return !0;
|
287
|
+
}
|
288
|
+
return !1;
|
289
|
+
}, dt = (t) => ({ tr: e, dispatch: n }) => {
|
290
|
+
const { from: r, to: o } = t;
|
291
|
+
return n && e.delete(r, o), !0;
|
292
|
+
}, ut = () => ({ state: t, dispatch: e }) => Ae(t, e), ft = () => ({ commands: t }) => t.keyboardShortcut("Enter"), pt = () => ({ state: t, dispatch: e }) => Te(t, e);
|
293
|
+
function z(t, e, n = { strict: !0 }) {
|
294
|
+
const r = Object.keys(e);
|
295
|
+
return r.length ? r.every((o) => n.strict ? e[o] === t[o] : Xe(e[o]) ? e[o].test(t[o]) : e[o] === t[o]) : !0;
|
296
|
+
}
|
297
|
+
function G(t, e, n = {}) {
|
298
|
+
return t.find((r) => r.type === e && z(r.attrs, n));
|
299
|
+
}
|
300
|
+
function mt(t, e, n = {}) {
|
301
|
+
return !!G(t, e, n);
|
302
|
+
}
|
303
|
+
function ue(t, e, n = {}) {
|
304
|
+
if (!t || !e)
|
305
|
+
return;
|
306
|
+
let r = t.parent.childAfter(t.parentOffset);
|
307
|
+
if (t.parentOffset === r.offset && r.offset !== 0 && (r = t.parent.childBefore(t.parentOffset)), !r.node)
|
308
|
+
return;
|
309
|
+
const o = G([...r.node.marks], e, n);
|
310
|
+
if (!o)
|
311
|
+
return;
|
312
|
+
let s = r.index, i = t.start() + r.offset, a = s + 1, c = i + r.node.nodeSize;
|
313
|
+
for (G([...r.node.marks], e, n); s > 0 && o.isInSet(t.parent.child(s - 1).marks); )
|
314
|
+
s -= 1, i -= t.parent.child(s).nodeSize;
|
315
|
+
for (; a < t.parent.childCount && mt([...t.parent.child(a).marks], e, n); )
|
316
|
+
c += t.parent.child(a).nodeSize, a += 1;
|
317
|
+
return {
|
318
|
+
from: i,
|
319
|
+
to: c
|
320
|
+
};
|
321
|
+
}
|
322
|
+
function I(t, e) {
|
323
|
+
if (typeof t == "string") {
|
324
|
+
if (!e.marks[t])
|
325
|
+
throw Error(`There is no mark type named '${t}'. Maybe you forgot to add the extension?`);
|
326
|
+
return e.marks[t];
|
327
|
+
}
|
328
|
+
return t;
|
329
|
+
}
|
330
|
+
const ht = (t, e = {}) => ({ tr: n, state: r, dispatch: o }) => {
|
331
|
+
const s = I(t, r.schema), { doc: i, selection: a } = n, { $from: c, from: d, to: f } = a;
|
332
|
+
if (o) {
|
333
|
+
const l = ue(c, s, e);
|
334
|
+
if (l && l.from <= d && l.to >= f) {
|
335
|
+
const u = S.create(i, l.from, l.to);
|
336
|
+
n.setSelection(u);
|
337
|
+
}
|
338
|
+
}
|
339
|
+
return !0;
|
340
|
+
}, gt = (t) => (e) => {
|
341
|
+
const n = typeof t == "function" ? t(e) : t;
|
342
|
+
for (let r = 0; r < n.length; r += 1)
|
343
|
+
if (n[r](e))
|
344
|
+
return !0;
|
345
|
+
return !1;
|
346
|
+
};
|
347
|
+
function fe(t) {
|
348
|
+
return t instanceof S;
|
349
|
+
}
|
350
|
+
function $(t = 0, e = 0, n = 0) {
|
351
|
+
return Math.min(Math.max(t, e), n);
|
352
|
+
}
|
353
|
+
function kt(t, e = null) {
|
354
|
+
if (!e)
|
355
|
+
return null;
|
356
|
+
const n = P.atStart(t), r = P.atEnd(t);
|
357
|
+
if (e === "start" || e === !0)
|
358
|
+
return n;
|
359
|
+
if (e === "end")
|
360
|
+
return r;
|
361
|
+
const o = n.from, s = r.to;
|
362
|
+
return e === "all" ? S.create(t, $(0, o, s), $(t.content.size, o, s)) : S.create(t, $(e, o, s), $(e, o, s));
|
363
|
+
}
|
364
|
+
function X() {
|
365
|
+
return [
|
366
|
+
"iPad Simulator",
|
367
|
+
"iPhone Simulator",
|
368
|
+
"iPod Simulator",
|
369
|
+
"iPad",
|
370
|
+
"iPhone",
|
371
|
+
"iPod"
|
372
|
+
].includes(navigator.platform) || navigator.userAgent.includes("Mac") && "ontouchend" in document;
|
373
|
+
}
|
374
|
+
const yt = (t = null, e = {}) => ({ editor: n, view: r, tr: o, dispatch: s }) => {
|
375
|
+
e = {
|
376
|
+
scrollIntoView: !0,
|
377
|
+
...e
|
378
|
+
};
|
379
|
+
const i = () => {
|
380
|
+
X() && r.dom.focus(), requestAnimationFrame(() => {
|
381
|
+
n.isDestroyed || (r.focus(), e != null && e.scrollIntoView && n.commands.scrollIntoView());
|
382
|
+
});
|
383
|
+
};
|
384
|
+
if (r.hasFocus() && t === null || t === !1)
|
385
|
+
return !0;
|
386
|
+
if (s && t === null && !fe(n.state.selection))
|
387
|
+
return i(), !0;
|
388
|
+
const a = kt(o.doc, t) || n.state.selection, c = n.state.selection.eq(a);
|
389
|
+
return s && (c || o.setSelection(a), c && o.storedMarks && o.setStoredMarks(o.storedMarks), i()), !0;
|
390
|
+
}, wt = (t, e) => (n) => t.every((r, o) => e(r, { ...n, index: o })), xt = (t, e) => ({ tr: n, commands: r }) => r.insertContentAt({ from: n.selection.from, to: n.selection.to }, t, e), pe = (t) => {
|
391
|
+
const e = t.childNodes;
|
392
|
+
for (let n = e.length - 1; n >= 0; n -= 1) {
|
393
|
+
const r = e[n];
|
394
|
+
r.nodeType === 3 && r.nodeValue && /^(\n\s\s|\n)$/.test(r.nodeValue) ? t.removeChild(r) : r.nodeType === 1 && pe(r);
|
395
|
+
}
|
396
|
+
return t;
|
397
|
+
};
|
398
|
+
function te(t) {
|
399
|
+
const e = `<body>${t}</body>`, n = new window.DOMParser().parseFromString(e, "text/html").body;
|
400
|
+
return pe(n);
|
401
|
+
}
|
402
|
+
function D(t, e, n) {
|
403
|
+
if (n = {
|
404
|
+
slice: !0,
|
405
|
+
parseOptions: {},
|
406
|
+
...n
|
407
|
+
}, typeof t == "object" && t !== null)
|
408
|
+
try {
|
409
|
+
return Array.isArray(t) && t.length > 0 ? F.fromArray(t.map((r) => e.nodeFromJSON(r))) : e.nodeFromJSON(t);
|
410
|
+
} catch (r) {
|
411
|
+
return console.warn("[tiptap warn]: Invalid content.", "Passed value:", t, "Error:", r), D("", e, n);
|
412
|
+
}
|
413
|
+
if (typeof t == "string") {
|
414
|
+
const r = we.fromSchema(e);
|
415
|
+
return n.slice ? r.parseSlice(te(t), n.parseOptions).content : r.parse(te(t), n.parseOptions);
|
416
|
+
}
|
417
|
+
return D("", e, n);
|
418
|
+
}
|
419
|
+
function bt(t, e, n) {
|
420
|
+
const r = t.steps.length - 1;
|
421
|
+
if (r < e)
|
422
|
+
return;
|
423
|
+
const o = t.steps[r];
|
424
|
+
if (!(o instanceof be || o instanceof Se))
|
425
|
+
return;
|
426
|
+
const s = t.mapping.maps[r];
|
427
|
+
let i = 0;
|
428
|
+
s.forEach((a, c, d, f) => {
|
429
|
+
i === 0 && (i = f);
|
430
|
+
}), t.setSelection(P.near(t.doc.resolve(i), n));
|
431
|
+
}
|
432
|
+
const St = (t) => t.toString().startsWith("<"), Mt = (t, e, n) => ({ tr: r, dispatch: o, editor: s }) => {
|
433
|
+
if (o) {
|
434
|
+
n = {
|
435
|
+
parseOptions: {},
|
436
|
+
updateSelection: !0,
|
437
|
+
applyInputRules: !1,
|
438
|
+
applyPasteRules: !1,
|
439
|
+
...n
|
440
|
+
};
|
441
|
+
const i = D(e, s.schema, {
|
442
|
+
parseOptions: {
|
443
|
+
preserveWhitespace: "full",
|
444
|
+
...n.parseOptions
|
445
|
+
}
|
446
|
+
});
|
447
|
+
if (i.toString() === "<>")
|
448
|
+
return !0;
|
449
|
+
let { from: a, to: c } = typeof t == "number" ? { from: t, to: t } : { from: t.from, to: t.to }, d = !0, f = !0;
|
450
|
+
if ((St(i) ? i : [i]).forEach((p) => {
|
451
|
+
p.check(), d = d ? p.isText && p.marks.length === 0 : !1, f = f ? p.isBlock : !1;
|
452
|
+
}), a === c && f) {
|
453
|
+
const { parent: p } = r.doc.resolve(a);
|
454
|
+
p.isTextblock && !p.type.spec.code && !p.childCount && (a -= 1, c += 1);
|
455
|
+
}
|
456
|
+
let u;
|
457
|
+
d ? (Array.isArray(e) ? u = e.map((p) => p.text || "").join("") : typeof e == "object" && e && e.text ? u = e.text : u = e, r.insertText(u, a, c)) : (u = i, r.replaceWith(a, c, u)), n.updateSelection && bt(r, r.steps.length - 1, -1), n.applyInputRules && r.setMeta("applyInputRules", { from: a, text: u }), n.applyPasteRules && r.setMeta("applyPasteRules", { from: a, text: u });
|
458
|
+
}
|
459
|
+
return !0;
|
460
|
+
}, At = () => ({ state: t, dispatch: e }) => Ce(t, e), Tt = () => ({ state: t, dispatch: e }) => ve(t, e), Ct = () => ({ state: t, dispatch: e }) => Ee(t, e), vt = () => ({ state: t, dispatch: e }) => Ie(t, e), Et = () => ({ tr: t, state: e, dispatch: n }) => {
|
461
|
+
try {
|
462
|
+
const r = ce(e.doc, e.selection.$from.pos, -1);
|
463
|
+
return r == null ? !1 : (t.join(r, 2), n && n(t), !0);
|
464
|
+
} catch {
|
465
|
+
return !1;
|
466
|
+
}
|
467
|
+
}, It = () => ({ state: t, dispatch: e, tr: n }) => {
|
468
|
+
try {
|
469
|
+
const r = ce(t.doc, t.selection.$from.pos, 1);
|
470
|
+
return r == null ? !1 : (n.join(r, 2), e && e(n), !0);
|
471
|
+
} catch {
|
472
|
+
return !1;
|
473
|
+
}
|
474
|
+
}, $t = () => ({ state: t, dispatch: e }) => $e(t, e), Bt = () => ({ state: t, dispatch: e }) => Be(t, e);
|
475
|
+
function me() {
|
476
|
+
return typeof navigator < "u" ? /Mac/.test(navigator.platform) : !1;
|
477
|
+
}
|
478
|
+
function Nt(t) {
|
479
|
+
const e = t.split(/-(?!$)/);
|
480
|
+
let n = e[e.length - 1];
|
481
|
+
n === "Space" && (n = " ");
|
482
|
+
let r, o, s, i;
|
483
|
+
for (let a = 0; a < e.length - 1; a += 1) {
|
484
|
+
const c = e[a];
|
485
|
+
if (/^(cmd|meta|m)$/i.test(c))
|
486
|
+
i = !0;
|
487
|
+
else if (/^a(lt)?$/i.test(c))
|
488
|
+
r = !0;
|
489
|
+
else if (/^(c|ctrl|control)$/i.test(c))
|
490
|
+
o = !0;
|
491
|
+
else if (/^s(hift)?$/i.test(c))
|
492
|
+
s = !0;
|
493
|
+
else if (/^mod$/i.test(c))
|
494
|
+
X() || me() ? i = !0 : o = !0;
|
495
|
+
else
|
496
|
+
throw new Error(`Unrecognized modifier name: ${c}`);
|
497
|
+
}
|
498
|
+
return r && (n = `Alt-${n}`), o && (n = `Ctrl-${n}`), i && (n = `Meta-${n}`), s && (n = `Shift-${n}`), n;
|
499
|
+
}
|
500
|
+
const Ot = (t) => ({ editor: e, view: n, tr: r, dispatch: o }) => {
|
501
|
+
const s = Nt(t).split(/-(?!$)/), i = s.find((d) => !["Alt", "Ctrl", "Meta", "Shift"].includes(d)), a = new KeyboardEvent("keydown", {
|
502
|
+
key: i === "Space" ? " " : i,
|
503
|
+
altKey: s.includes("Alt"),
|
504
|
+
ctrlKey: s.includes("Ctrl"),
|
505
|
+
metaKey: s.includes("Meta"),
|
506
|
+
shiftKey: s.includes("Shift"),
|
507
|
+
bubbles: !0,
|
508
|
+
cancelable: !0
|
509
|
+
}), c = e.captureTransaction(() => {
|
510
|
+
n.someProp("handleKeyDown", (d) => d(n, a));
|
511
|
+
});
|
512
|
+
return c == null || c.steps.forEach((d) => {
|
513
|
+
const f = d.map(r.mapping);
|
514
|
+
f && o && r.maybeStep(f);
|
515
|
+
}), !0;
|
516
|
+
};
|
517
|
+
function Y(t, e, n = {}) {
|
518
|
+
const { from: r, to: o, empty: s } = t.selection, i = e ? y(e, t.schema) : null, a = [];
|
519
|
+
t.doc.nodesBetween(r, o, (l, u) => {
|
520
|
+
if (l.isText)
|
521
|
+
return;
|
522
|
+
const p = Math.max(r, u), m = Math.min(o, u + l.nodeSize);
|
523
|
+
a.push({
|
524
|
+
node: l,
|
525
|
+
from: p,
|
526
|
+
to: m
|
527
|
+
});
|
528
|
+
});
|
529
|
+
const c = o - r, d = a.filter((l) => i ? i.name === l.node.type.name : !0).filter((l) => z(l.node.attrs, n, { strict: !1 }));
|
530
|
+
return s ? !!d.length : d.reduce((l, u) => l + u.to - u.from, 0) >= c;
|
531
|
+
}
|
532
|
+
const Pt = (t, e = {}) => ({ state: n, dispatch: r }) => {
|
533
|
+
const o = y(t, n.schema);
|
534
|
+
return Y(n, o, e) ? Ne(n, r) : !1;
|
535
|
+
}, jt = () => ({ state: t, dispatch: e }) => Oe(t, e), Ft = (t) => ({ state: e, dispatch: n }) => {
|
536
|
+
const r = y(t, e.schema);
|
537
|
+
return We(r)(e, n);
|
538
|
+
}, Lt = () => ({ state: t, dispatch: e }) => Pe(t, e);
|
539
|
+
function he(t, e) {
|
540
|
+
return e.nodes[t] ? "node" : e.marks[t] ? "mark" : null;
|
541
|
+
}
|
542
|
+
function ne(t, e) {
|
543
|
+
const n = typeof e == "string" ? [e] : e;
|
544
|
+
return Object.keys(t).reduce((r, o) => (n.includes(o) || (r[o] = t[o]), r), {});
|
545
|
+
}
|
546
|
+
const Rt = (t, e) => ({ tr: n, state: r, dispatch: o }) => {
|
547
|
+
let s = null, i = null;
|
548
|
+
const a = he(typeof t == "string" ? t : t.name, r.schema);
|
549
|
+
return a ? (a === "node" && (s = y(t, r.schema)), a === "mark" && (i = I(t, r.schema)), o && n.selection.ranges.forEach((c) => {
|
550
|
+
r.doc.nodesBetween(c.$from.pos, c.$to.pos, (d, f) => {
|
551
|
+
s && s === d.type && n.setNodeMarkup(f, void 0, ne(d.attrs, e)), i && d.marks.length && d.marks.forEach((l) => {
|
552
|
+
i === l.type && n.addMark(f, f + d.nodeSize, i.create(ne(l.attrs, e)));
|
553
|
+
});
|
554
|
+
});
|
555
|
+
}), !0) : !1;
|
556
|
+
}, zt = () => ({ tr: t, dispatch: e }) => (e && t.scrollIntoView(), !0), Dt = () => ({ tr: t, commands: e }) => e.setTextSelection({
|
557
|
+
from: 0,
|
558
|
+
to: t.doc.content.size
|
559
|
+
}), Wt = () => ({ state: t, dispatch: e }) => je(t, e), Kt = () => ({ state: t, dispatch: e }) => Fe(t, e), Ht = () => ({ state: t, dispatch: e }) => Le(t, e), Vt = () => ({ state: t, dispatch: e }) => Re(t, e), _t = () => ({ state: t, dispatch: e }) => ze(t, e);
|
560
|
+
function Jt(t, e, n = {}) {
|
561
|
+
return D(t, e, { slice: !1, parseOptions: n });
|
562
|
+
}
|
563
|
+
const Gt = (t, e = !1, n = {}) => ({ tr: r, editor: o, dispatch: s }) => {
|
564
|
+
const { doc: i } = r, a = Jt(t, o.schema, n);
|
565
|
+
return s && r.replaceWith(0, i.content.size, a).setMeta("preventUpdate", !e), !0;
|
566
|
+
};
|
567
|
+
function Ut(t, e) {
|
568
|
+
const n = I(e, t.schema), { from: r, to: o, empty: s } = t.selection, i = [];
|
569
|
+
s ? (t.storedMarks && i.push(...t.storedMarks), i.push(...t.selection.$head.marks())) : t.doc.nodesBetween(r, o, (c) => {
|
570
|
+
i.push(...c.marks);
|
571
|
+
});
|
572
|
+
const a = i.find((c) => c.type.name === n.name);
|
573
|
+
return a ? { ...a.attrs } : {};
|
574
|
+
}
|
575
|
+
function qt(t) {
|
576
|
+
for (let e = 0; e < t.edgeCount; e += 1) {
|
577
|
+
const { type: n } = t.edge(e);
|
578
|
+
if (n.isTextblock && !n.hasRequiredAttrs())
|
579
|
+
return n;
|
580
|
+
}
|
581
|
+
return null;
|
582
|
+
}
|
583
|
+
function U(t, e) {
|
584
|
+
const n = [];
|
585
|
+
return t.descendants((r, o) => {
|
586
|
+
e(r) && n.push({
|
587
|
+
node: r,
|
588
|
+
pos: o
|
589
|
+
});
|
590
|
+
}), n;
|
591
|
+
}
|
592
|
+
function Qt(t, e) {
|
593
|
+
for (let n = t.depth; n > 0; n -= 1) {
|
594
|
+
const r = t.node(n);
|
595
|
+
if (e(r))
|
596
|
+
return {
|
597
|
+
pos: n > 0 ? t.before(n) : 0,
|
598
|
+
start: t.start(n),
|
599
|
+
depth: n,
|
600
|
+
node: r
|
601
|
+
};
|
602
|
+
}
|
603
|
+
}
|
604
|
+
function Z(t) {
|
605
|
+
return (e) => Qt(e.$from, t);
|
606
|
+
}
|
607
|
+
function R(t, e, n) {
|
608
|
+
return Object.fromEntries(Object.entries(n).filter(([r]) => {
|
609
|
+
const o = t.find((s) => s.type === e && s.name === r);
|
610
|
+
return o ? o.attribute.keepOnSplit : !1;
|
611
|
+
}));
|
612
|
+
}
|
613
|
+
function Xt(t, e, n = {}) {
|
614
|
+
const { empty: r, ranges: o } = t.selection, s = e ? I(e, t.schema) : null;
|
615
|
+
if (r)
|
616
|
+
return !!(t.storedMarks || t.selection.$from.marks()).filter((l) => s ? s.name === l.type.name : !0).find((l) => z(l.attrs, n, { strict: !1 }));
|
617
|
+
let i = 0;
|
618
|
+
const a = [];
|
619
|
+
if (o.forEach(({ $from: l, $to: u }) => {
|
620
|
+
const p = l.pos, m = u.pos;
|
621
|
+
t.doc.nodesBetween(p, m, (h, g) => {
|
622
|
+
if (!h.isText && !h.marks.length)
|
623
|
+
return;
|
624
|
+
const k = Math.max(p, g), C = Math.min(m, g + h.nodeSize), M = C - k;
|
625
|
+
i += M, a.push(...h.marks.map((v) => ({
|
626
|
+
mark: v,
|
627
|
+
from: k,
|
628
|
+
to: C
|
629
|
+
})));
|
630
|
+
});
|
631
|
+
}), i === 0)
|
632
|
+
return !1;
|
633
|
+
const c = a.filter((l) => s ? s.name === l.mark.type.name : !0).filter((l) => z(l.mark.attrs, n, { strict: !1 })).reduce((l, u) => l + u.to - u.from, 0), d = a.filter((l) => s ? l.mark.type !== s && l.mark.type.excludes(s) : !0).reduce((l, u) => l + u.to - u.from, 0);
|
634
|
+
return (c > 0 ? c + d : c) >= i;
|
635
|
+
}
|
636
|
+
function re(t, e) {
|
637
|
+
const { nodeExtensions: n } = Ue(e), r = n.find((i) => i.name === t);
|
638
|
+
if (!r)
|
639
|
+
return !1;
|
640
|
+
const o = {
|
641
|
+
name: r.name,
|
642
|
+
options: r.options,
|
643
|
+
storage: r.storage
|
644
|
+
}, s = x(w(r, "group", o));
|
645
|
+
return typeof s != "string" ? !1 : s.split(" ").includes("list");
|
646
|
+
}
|
647
|
+
function Yt(t, e, n) {
|
648
|
+
var r;
|
649
|
+
const { selection: o } = e;
|
650
|
+
let s = null;
|
651
|
+
if (fe(o) && (s = o.$cursor), s) {
|
652
|
+
const a = (r = t.storedMarks) !== null && r !== void 0 ? r : s.marks();
|
653
|
+
return !!n.isInSet(a) || !a.some((c) => c.type.excludes(n));
|
654
|
+
}
|
655
|
+
const { ranges: i } = o;
|
656
|
+
return i.some(({ $from: a, $to: c }) => {
|
657
|
+
let d = a.depth === 0 ? t.doc.inlineContent && t.doc.type.allowsMarkType(n) : !1;
|
658
|
+
return t.doc.nodesBetween(a.pos, c.pos, (f, l, u) => {
|
659
|
+
if (d)
|
660
|
+
return !1;
|
661
|
+
if (f.isInline) {
|
662
|
+
const p = !u || u.type.allowsMarkType(n), m = !!n.isInSet(f.marks) || !f.marks.some((h) => h.type.excludes(n));
|
663
|
+
d = p && m;
|
664
|
+
}
|
665
|
+
return !d;
|
666
|
+
}), d;
|
667
|
+
});
|
668
|
+
}
|
669
|
+
const Zt = (t, e = {}) => ({ tr: n, state: r, dispatch: o }) => {
|
670
|
+
const { selection: s } = n, { empty: i, ranges: a } = s, c = I(t, r.schema);
|
671
|
+
if (o)
|
672
|
+
if (i) {
|
673
|
+
const d = Ut(r, c);
|
674
|
+
n.addStoredMark(c.create({
|
675
|
+
...d,
|
676
|
+
...e
|
677
|
+
}));
|
678
|
+
} else
|
679
|
+
a.forEach((d) => {
|
680
|
+
const f = d.$from.pos, l = d.$to.pos;
|
681
|
+
r.doc.nodesBetween(f, l, (u, p) => {
|
682
|
+
const m = Math.max(p, f), h = Math.min(p + u.nodeSize, l);
|
683
|
+
u.marks.find((k) => k.type === c) ? u.marks.forEach((k) => {
|
684
|
+
c === k.type && n.addMark(m, h, c.create({
|
685
|
+
...k.attrs,
|
686
|
+
...e
|
687
|
+
}));
|
688
|
+
}) : n.addMark(m, h, c.create(e));
|
689
|
+
});
|
690
|
+
});
|
691
|
+
return Yt(r, n, c);
|
692
|
+
}, en = (t, e) => ({ tr: n }) => (n.setMeta(t, e), !0), tn = (t, e = {}) => ({ state: n, dispatch: r, chain: o }) => {
|
693
|
+
const s = y(t, n.schema);
|
694
|
+
return s.isTextblock ? o().command(({ commands: i }) => ee(s, e)(n) ? !0 : i.clearNodes()).command(({ state: i }) => ee(s, e)(i, r)).run() : (console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'), !1);
|
695
|
+
}, nn = (t) => ({ tr: e, dispatch: n }) => {
|
696
|
+
if (n) {
|
697
|
+
const { doc: r } = e, o = $(t, 0, r.content.size), s = ae.create(r, o);
|
698
|
+
e.setSelection(s);
|
699
|
+
}
|
700
|
+
return !0;
|
701
|
+
}, rn = (t) => ({ tr: e, dispatch: n }) => {
|
702
|
+
if (n) {
|
703
|
+
const { doc: r } = e, { from: o, to: s } = typeof t == "number" ? { from: t, to: t } : t, i = S.atStart(r).from, a = S.atEnd(r).to, c = $(o, i, a), d = $(s, i, a), f = S.create(r, c, d);
|
704
|
+
e.setSelection(f);
|
705
|
+
}
|
706
|
+
return !0;
|
707
|
+
}, on = (t) => ({ state: e, dispatch: n }) => {
|
708
|
+
const r = y(t, e.schema);
|
709
|
+
return Ke(r)(e, n);
|
710
|
+
};
|
711
|
+
function oe(t, e) {
|
712
|
+
const n = t.storedMarks || t.selection.$to.parentOffset && t.selection.$from.marks();
|
713
|
+
if (n) {
|
714
|
+
const r = n.filter((o) => e == null ? void 0 : e.includes(o.type.name));
|
715
|
+
t.tr.ensureMarks(r);
|
716
|
+
}
|
717
|
+
}
|
718
|
+
const sn = ({ keepMarks: t = !0 } = {}) => ({ tr: e, state: n, dispatch: r, editor: o }) => {
|
719
|
+
const { selection: s, doc: i } = e, { $from: a, $to: c } = s, d = o.extensionManager.attributes, f = R(d, a.node().type.name, a.node().attrs);
|
720
|
+
if (s instanceof ae && s.node.isBlock)
|
721
|
+
return !a.parentOffset || !L(i, a.pos) ? !1 : (r && (t && oe(n, o.extensionManager.splittableMarks), e.split(a.pos).scrollIntoView()), !0);
|
722
|
+
if (!a.parent.isBlock)
|
723
|
+
return !1;
|
724
|
+
if (r) {
|
725
|
+
const l = c.parentOffset === c.parent.content.size;
|
726
|
+
s instanceof S && e.deleteSelection();
|
727
|
+
const u = a.depth === 0 ? void 0 : qt(a.node(-1).contentMatchAt(a.indexAfter(-1)));
|
728
|
+
let p = l && u ? [
|
729
|
+
{
|
730
|
+
type: u,
|
731
|
+
attrs: f
|
732
|
+
}
|
733
|
+
] : void 0, m = L(e.doc, e.mapping.map(a.pos), 1, p);
|
734
|
+
if (!p && !m && L(e.doc, e.mapping.map(a.pos), 1, u ? [{ type: u }] : void 0) && (m = !0, p = u ? [
|
735
|
+
{
|
736
|
+
type: u,
|
737
|
+
attrs: f
|
738
|
+
}
|
739
|
+
] : void 0), m && (e.split(e.mapping.map(a.pos), 1, p), u && !l && !a.parentOffset && a.parent.type !== u)) {
|
740
|
+
const h = e.mapping.map(a.before()), g = e.doc.resolve(h);
|
741
|
+
a.node(-1).canReplaceWith(g.index(), g.index() + 1, u) && e.setNodeMarkup(e.mapping.map(a.before()), u);
|
742
|
+
}
|
743
|
+
t && oe(n, o.extensionManager.splittableMarks), e.scrollIntoView();
|
744
|
+
}
|
745
|
+
return !0;
|
746
|
+
}, an = (t) => ({ tr: e, state: n, dispatch: r, editor: o }) => {
|
747
|
+
var s;
|
748
|
+
const i = y(t, n.schema), { $from: a, $to: c } = n.selection, d = n.selection.node;
|
749
|
+
if (d && d.isBlock || a.depth < 2 || !a.sameParent(c))
|
750
|
+
return !1;
|
751
|
+
const f = a.node(-1);
|
752
|
+
if (f.type !== i)
|
753
|
+
return !1;
|
754
|
+
const l = o.extensionManager.attributes;
|
755
|
+
if (a.parent.content.size === 0 && a.node(-1).childCount === a.indexAfter(-1)) {
|
756
|
+
if (a.depth === 2 || a.node(-3).type !== i || a.index(-2) !== a.node(-2).childCount - 1)
|
757
|
+
return !1;
|
758
|
+
if (r) {
|
759
|
+
let g = F.empty;
|
760
|
+
const k = a.index(-1) ? 1 : a.index(-2) ? 2 : 3;
|
761
|
+
for (let E = a.depth - k; E >= a.depth - 3; E -= 1)
|
762
|
+
g = F.from(a.node(E).copy(g));
|
763
|
+
const C = a.indexAfter(-1) < a.node(-2).childCount ? 1 : a.indexAfter(-2) < a.node(-3).childCount ? 2 : 3, M = R(l, a.node().type.name, a.node().attrs), v = ((s = i.contentMatch.defaultType) === null || s === void 0 ? void 0 : s.createAndFill(M)) || void 0;
|
764
|
+
g = g.append(F.from(i.createAndFill(null, v) || void 0));
|
765
|
+
const b = a.before(a.depth - (k - 1));
|
766
|
+
e.replace(b, a.after(-C), new ye(g, 4 - k, 0));
|
767
|
+
let A = -1;
|
768
|
+
e.doc.nodesBetween(b, e.doc.content.size, (E, K) => {
|
769
|
+
if (A > -1)
|
770
|
+
return !1;
|
771
|
+
E.isTextblock && E.content.size === 0 && (A = K + 1);
|
772
|
+
}), A > -1 && e.setSelection(S.near(e.doc.resolve(A))), e.scrollIntoView();
|
773
|
+
}
|
774
|
+
return !0;
|
775
|
+
}
|
776
|
+
const u = c.pos === a.end() ? f.contentMatchAt(0).defaultType : null, p = R(l, f.type.name, f.attrs), m = R(l, a.node().type.name, a.node().attrs);
|
777
|
+
e.delete(a.pos, c.pos);
|
778
|
+
const h = u ? [
|
779
|
+
{ type: i, attrs: p },
|
780
|
+
{ type: u, attrs: m }
|
781
|
+
] : [{ type: i, attrs: p }];
|
782
|
+
if (!L(e.doc, a.pos, 2))
|
783
|
+
return !1;
|
784
|
+
if (r) {
|
785
|
+
const { selection: g, storedMarks: k } = n, { splittableMarks: C } = o.extensionManager, M = k || g.$to.parentOffset && g.$from.marks();
|
786
|
+
if (e.split(a.pos, 2, h).scrollIntoView(), !M || !r)
|
787
|
+
return !0;
|
788
|
+
const v = M.filter((b) => C.includes(b.type.name));
|
789
|
+
e.ensureMarks(v);
|
790
|
+
}
|
791
|
+
return !0;
|
792
|
+
}, V = (t, e) => {
|
793
|
+
const n = Z((i) => i.type === e)(t.selection);
|
794
|
+
if (!n)
|
795
|
+
return !0;
|
796
|
+
const r = t.doc.resolve(Math.max(0, n.pos - 1)).before(n.depth);
|
797
|
+
if (r === void 0)
|
798
|
+
return !0;
|
799
|
+
const o = t.doc.nodeAt(r);
|
800
|
+
return n.node.type === (o == null ? void 0 : o.type) && le(t.doc, n.pos) && t.join(n.pos), !0;
|
801
|
+
}, _ = (t, e) => {
|
802
|
+
const n = Z((i) => i.type === e)(t.selection);
|
803
|
+
if (!n)
|
804
|
+
return !0;
|
805
|
+
const r = t.doc.resolve(n.start).after(n.depth);
|
806
|
+
if (r === void 0)
|
807
|
+
return !0;
|
808
|
+
const o = t.doc.nodeAt(r);
|
809
|
+
return n.node.type === (o == null ? void 0 : o.type) && le(t.doc, r) && t.join(r), !0;
|
810
|
+
}, cn = (t, e, n, r = {}) => ({ editor: o, tr: s, state: i, dispatch: a, chain: c, commands: d, can: f }) => {
|
811
|
+
const { extensions: l, splittableMarks: u } = o.extensionManager, p = y(t, i.schema), m = y(e, i.schema), { selection: h, storedMarks: g } = i, { $from: k, $to: C } = h, M = k.blockRange(C), v = g || h.$to.parentOffset && h.$from.marks();
|
812
|
+
if (!M)
|
813
|
+
return !1;
|
814
|
+
const b = Z((A) => re(A.type.name, l))(h);
|
815
|
+
if (M.depth >= 1 && b && M.depth - b.depth <= 1) {
|
816
|
+
if (b.node.type === p)
|
817
|
+
return d.liftListItem(m);
|
818
|
+
if (re(b.node.type.name, l) && p.validContent(b.node.content) && a)
|
819
|
+
return c().command(() => (s.setNodeMarkup(b.pos, p), !0)).command(() => V(s, p)).command(() => _(s, p)).run();
|
820
|
+
}
|
821
|
+
return !n || !v || !a ? c().command(() => f().wrapInList(p, r) ? !0 : d.clearNodes()).wrapInList(p, r).command(() => V(s, p)).command(() => _(s, p)).run() : c().command(() => {
|
822
|
+
const A = f().wrapInList(p, r), E = v.filter((K) => u.includes(K.type.name));
|
823
|
+
return s.ensureMarks(E), A ? !0 : d.clearNodes();
|
824
|
+
}).wrapInList(p, r).command(() => V(s, p)).command(() => _(s, p)).run();
|
825
|
+
}, ln = (t, e = {}, n = {}) => ({ state: r, commands: o }) => {
|
826
|
+
const { extendEmptyMarkRange: s = !1 } = n, i = I(t, r.schema);
|
827
|
+
return Xt(r, i, e) ? o.unsetMark(i, { extendEmptyMarkRange: s }) : o.setMark(i, e);
|
828
|
+
}, dn = (t, e, n = {}) => ({ state: r, commands: o }) => {
|
829
|
+
const s = y(t, r.schema), i = y(e, r.schema);
|
830
|
+
return Y(r, s, n) ? o.setNode(i) : o.setNode(s, n);
|
831
|
+
}, un = (t, e = {}) => ({ state: n, commands: r }) => {
|
832
|
+
const o = y(t, n.schema);
|
833
|
+
return Y(n, o, e) ? r.lift(o) : r.wrapIn(o, e);
|
834
|
+
}, fn = () => ({ state: t, dispatch: e }) => {
|
835
|
+
const n = t.plugins;
|
836
|
+
for (let r = 0; r < n.length; r += 1) {
|
837
|
+
const o = n[r];
|
838
|
+
let s;
|
839
|
+
if (o.spec.isInputRules && (s = o.getState(t))) {
|
840
|
+
if (e) {
|
841
|
+
const i = t.tr, a = s.transform;
|
842
|
+
for (let c = a.steps.length - 1; c >= 0; c -= 1)
|
843
|
+
i.step(a.steps[c].invert(a.docs[c]));
|
844
|
+
if (s.text) {
|
845
|
+
const c = i.doc.resolve(s.from).marks();
|
846
|
+
i.replaceWith(s.from, s.to, t.schema.text(s.text, c));
|
847
|
+
} else
|
848
|
+
i.delete(s.from, s.to);
|
849
|
+
}
|
850
|
+
return !0;
|
851
|
+
}
|
852
|
+
}
|
853
|
+
return !1;
|
854
|
+
}, pn = () => ({ tr: t, dispatch: e }) => {
|
855
|
+
const { selection: n } = t, { empty: r, ranges: o } = n;
|
856
|
+
return r || e && o.forEach((s) => {
|
857
|
+
t.removeMark(s.$from.pos, s.$to.pos);
|
858
|
+
}), !0;
|
859
|
+
}, mn = (t, e = {}) => ({ tr: n, state: r, dispatch: o }) => {
|
860
|
+
var s;
|
861
|
+
const { extendEmptyMarkRange: i = !1 } = e, { selection: a } = n, c = I(t, r.schema), { $from: d, empty: f, ranges: l } = a;
|
862
|
+
if (!o)
|
863
|
+
return !0;
|
864
|
+
if (f && i) {
|
865
|
+
let { from: u, to: p } = a;
|
866
|
+
const m = (s = d.marks().find((g) => g.type === c)) === null || s === void 0 ? void 0 : s.attrs, h = ue(d, c, m);
|
867
|
+
h && (u = h.from, p = h.to), n.removeMark(u, p, c);
|
868
|
+
} else
|
869
|
+
l.forEach((u) => {
|
870
|
+
n.removeMark(u.$from.pos, u.$to.pos, c);
|
871
|
+
});
|
872
|
+
return n.removeStoredMark(c), !0;
|
873
|
+
}, hn = (t, e = {}) => ({ tr: n, state: r, dispatch: o }) => {
|
874
|
+
let s = null, i = null;
|
875
|
+
const a = he(typeof t == "string" ? t : t.name, r.schema);
|
876
|
+
return a ? (a === "node" && (s = y(t, r.schema)), a === "mark" && (i = I(t, r.schema)), o && n.selection.ranges.forEach((c) => {
|
877
|
+
const d = c.$from.pos, f = c.$to.pos;
|
878
|
+
r.doc.nodesBetween(d, f, (l, u) => {
|
879
|
+
s && s === l.type && n.setNodeMarkup(u, void 0, {
|
880
|
+
...l.attrs,
|
881
|
+
...e
|
882
|
+
}), i && l.marks.length && l.marks.forEach((p) => {
|
883
|
+
if (i === p.type) {
|
884
|
+
const m = Math.max(u, d), h = Math.min(u + l.nodeSize, f);
|
885
|
+
n.addMark(m, h, i.create({
|
886
|
+
...p.attrs,
|
887
|
+
...e
|
888
|
+
}));
|
889
|
+
}
|
890
|
+
});
|
891
|
+
});
|
892
|
+
}), !0) : !1;
|
893
|
+
}, gn = (t, e = {}) => ({ state: n, dispatch: r }) => {
|
894
|
+
const o = y(t, n.schema);
|
895
|
+
return De(o, e)(n, r);
|
896
|
+
}, kn = (t, e = {}) => ({ state: n, dispatch: r }) => {
|
897
|
+
const o = y(t, n.schema);
|
898
|
+
return He(o, e)(n, r);
|
899
|
+
};
|
900
|
+
var yn = /* @__PURE__ */ Object.freeze({
|
901
|
+
__proto__: null,
|
902
|
+
blur: nt,
|
903
|
+
clearContent: rt,
|
904
|
+
clearNodes: ot,
|
905
|
+
command: st,
|
906
|
+
createParagraphNear: it,
|
907
|
+
cut: at,
|
908
|
+
deleteCurrentNode: ct,
|
909
|
+
deleteNode: lt,
|
910
|
+
deleteRange: dt,
|
911
|
+
deleteSelection: ut,
|
912
|
+
enter: ft,
|
913
|
+
exitCode: pt,
|
914
|
+
extendMarkRange: ht,
|
915
|
+
first: gt,
|
916
|
+
focus: yt,
|
917
|
+
forEach: wt,
|
918
|
+
insertContent: xt,
|
919
|
+
insertContentAt: Mt,
|
920
|
+
joinUp: At,
|
921
|
+
joinDown: Tt,
|
922
|
+
joinBackward: Ct,
|
923
|
+
joinForward: vt,
|
924
|
+
joinItemBackward: Et,
|
925
|
+
joinItemForward: It,
|
926
|
+
joinTextblockBackward: $t,
|
927
|
+
joinTextblockForward: Bt,
|
928
|
+
keyboardShortcut: Ot,
|
929
|
+
lift: Pt,
|
930
|
+
liftEmptyBlock: jt,
|
931
|
+
liftListItem: Ft,
|
932
|
+
newlineInCode: Lt,
|
933
|
+
resetAttributes: Rt,
|
934
|
+
scrollIntoView: zt,
|
935
|
+
selectAll: Dt,
|
936
|
+
selectNodeBackward: Wt,
|
937
|
+
selectNodeForward: Kt,
|
938
|
+
selectParentNode: Ht,
|
939
|
+
selectTextblockEnd: Vt,
|
940
|
+
selectTextblockStart: _t,
|
941
|
+
setContent: Gt,
|
942
|
+
setMark: Zt,
|
943
|
+
setMeta: en,
|
944
|
+
setNode: tn,
|
945
|
+
setNodeSelection: nn,
|
946
|
+
setTextSelection: rn,
|
947
|
+
sinkListItem: on,
|
948
|
+
splitBlock: sn,
|
949
|
+
splitListItem: an,
|
950
|
+
toggleList: cn,
|
951
|
+
toggleMark: ln,
|
952
|
+
toggleNode: dn,
|
953
|
+
toggleWrap: un,
|
954
|
+
undoInputRule: fn,
|
955
|
+
unsetAllMarks: pn,
|
956
|
+
unsetMark: mn,
|
957
|
+
updateAttributes: hn,
|
958
|
+
wrapIn: gn,
|
959
|
+
wrapInList: kn
|
960
|
+
});
|
961
|
+
T.create({
|
962
|
+
name: "commands",
|
963
|
+
addCommands() {
|
964
|
+
return {
|
965
|
+
...yn
|
966
|
+
};
|
967
|
+
}
|
968
|
+
});
|
969
|
+
T.create({
|
970
|
+
name: "editable",
|
971
|
+
addProseMirrorPlugins() {
|
972
|
+
return [
|
973
|
+
new B({
|
974
|
+
key: new N("editable"),
|
975
|
+
props: {
|
976
|
+
editable: () => this.editor.options.editable
|
977
|
+
}
|
978
|
+
})
|
979
|
+
];
|
980
|
+
}
|
981
|
+
});
|
982
|
+
T.create({
|
983
|
+
name: "focusEvents",
|
984
|
+
addProseMirrorPlugins() {
|
985
|
+
const { editor: t } = this;
|
986
|
+
return [
|
987
|
+
new B({
|
988
|
+
key: new N("focusEvents"),
|
989
|
+
props: {
|
990
|
+
handleDOMEvents: {
|
991
|
+
focus: (e, n) => {
|
992
|
+
t.isFocused = !0;
|
993
|
+
const r = t.state.tr.setMeta("focus", { event: n }).setMeta("addToHistory", !1);
|
994
|
+
return e.dispatch(r), !1;
|
995
|
+
},
|
996
|
+
blur: (e, n) => {
|
997
|
+
t.isFocused = !1;
|
998
|
+
const r = t.state.tr.setMeta("blur", { event: n }).setMeta("addToHistory", !1);
|
999
|
+
return e.dispatch(r), !1;
|
1000
|
+
}
|
1001
|
+
}
|
1002
|
+
}
|
1003
|
+
})
|
1004
|
+
];
|
1005
|
+
}
|
1006
|
+
});
|
1007
|
+
T.create({
|
1008
|
+
name: "keymap",
|
1009
|
+
addKeyboardShortcuts() {
|
1010
|
+
const t = () => this.editor.commands.first(({ commands: i }) => [
|
1011
|
+
() => i.undoInputRule(),
|
1012
|
+
// maybe convert first text block node to default node
|
1013
|
+
() => i.command(({ tr: a }) => {
|
1014
|
+
const { selection: c, doc: d } = a, { empty: f, $anchor: l } = c, { pos: u, parent: p } = l, m = l.parent.isTextblock && u > 0 ? a.doc.resolve(u - 1) : l, h = m.parent.type.spec.isolating, g = l.pos - l.parentOffset, k = h && m.parent.childCount === 1 ? g === l.pos : P.atStart(d).from === u;
|
1015
|
+
return !f || !k || !p.type.isTextblock || p.textContent.length ? !1 : i.clearNodes();
|
1016
|
+
}),
|
1017
|
+
() => i.deleteSelection(),
|
1018
|
+
() => i.joinBackward(),
|
1019
|
+
() => i.selectNodeBackward()
|
1020
|
+
]), e = () => this.editor.commands.first(({ commands: i }) => [
|
1021
|
+
() => i.deleteSelection(),
|
1022
|
+
() => i.deleteCurrentNode(),
|
1023
|
+
() => i.joinForward(),
|
1024
|
+
() => i.selectNodeForward()
|
1025
|
+
]), r = {
|
1026
|
+
Enter: () => this.editor.commands.first(({ commands: i }) => [
|
1027
|
+
() => i.newlineInCode(),
|
1028
|
+
() => i.createParagraphNear(),
|
1029
|
+
() => i.liftEmptyBlock(),
|
1030
|
+
() => i.splitBlock()
|
1031
|
+
]),
|
1032
|
+
"Mod-Enter": () => this.editor.commands.exitCode(),
|
1033
|
+
Backspace: t,
|
1034
|
+
"Mod-Backspace": t,
|
1035
|
+
"Shift-Backspace": t,
|
1036
|
+
Delete: e,
|
1037
|
+
"Mod-Delete": e,
|
1038
|
+
"Mod-a": () => this.editor.commands.selectAll()
|
1039
|
+
}, o = {
|
1040
|
+
...r
|
1041
|
+
}, s = {
|
1042
|
+
...r,
|
1043
|
+
"Ctrl-h": t,
|
1044
|
+
"Alt-Backspace": t,
|
1045
|
+
"Ctrl-d": e,
|
1046
|
+
"Ctrl-Alt-Backspace": e,
|
1047
|
+
"Alt-Delete": e,
|
1048
|
+
"Alt-d": e,
|
1049
|
+
"Ctrl-a": () => this.editor.commands.selectTextblockStart(),
|
1050
|
+
"Ctrl-e": () => this.editor.commands.selectTextblockEnd()
|
1051
|
+
};
|
1052
|
+
return X() || me() ? s : o;
|
1053
|
+
},
|
1054
|
+
addProseMirrorPlugins() {
|
1055
|
+
return [
|
1056
|
+
// With this plugin we check if the whole document was selected and deleted.
|
1057
|
+
// In this case we will additionally call `clearNodes()` to convert e.g. a heading
|
1058
|
+
// to a paragraph if necessary.
|
1059
|
+
// This is an alternative to ProseMirror's `AllSelection`, which doesn’t work well
|
1060
|
+
// with many other commands.
|
1061
|
+
new B({
|
1062
|
+
key: new N("clearDocument"),
|
1063
|
+
appendTransaction: (t, e, n) => {
|
1064
|
+
if (!(t.some((m) => m.docChanged) && !e.doc.eq(n.doc)))
|
1065
|
+
return;
|
1066
|
+
const { empty: o, from: s, to: i } = e.selection, a = P.atStart(e.doc).from, c = P.atEnd(e.doc).to;
|
1067
|
+
if (o || !(s === a && i === c) || !(n.doc.textBetween(0, n.doc.content.size, " ", " ").length === 0))
|
1068
|
+
return;
|
1069
|
+
const l = n.tr, u = de({
|
1070
|
+
state: n,
|
1071
|
+
transaction: l
|
1072
|
+
}), { commands: p } = new Ge({
|
1073
|
+
editor: this.editor,
|
1074
|
+
state: u
|
1075
|
+
});
|
1076
|
+
if (p.clearNodes(), !!l.steps.length)
|
1077
|
+
return l;
|
1078
|
+
}
|
1079
|
+
})
|
1080
|
+
];
|
1081
|
+
}
|
1082
|
+
});
|
1083
|
+
T.create({
|
1084
|
+
name: "tabindex",
|
1085
|
+
addProseMirrorPlugins() {
|
1086
|
+
return [
|
1087
|
+
new B({
|
1088
|
+
key: new N("tabindex"),
|
1089
|
+
props: {
|
1090
|
+
attributes: this.editor.isEditable ? { tabindex: "0" } : {}
|
1091
|
+
}
|
1092
|
+
})
|
1093
|
+
];
|
1094
|
+
}
|
1095
|
+
});
|
1096
|
+
function se(t) {
|
1097
|
+
return new Ye({
|
1098
|
+
find: t.find,
|
1099
|
+
handler: ({ state: e, range: n, match: r }) => {
|
1100
|
+
const o = e.doc.resolve(n.from), s = x(t.getAttributes, void 0, r) || {};
|
1101
|
+
if (!o.node(-1).canReplaceWith(o.index(-1), o.indexAfter(-1), t.type))
|
1102
|
+
return null;
|
1103
|
+
e.tr.delete(n.from, n.to).setBlockType(n.from, n.from, t.type, s);
|
1104
|
+
}
|
1105
|
+
});
|
1106
|
+
}
|
1107
|
+
class W {
|
1108
|
+
constructor(e = {}) {
|
1109
|
+
this.type = "node", this.name = "node", this.parent = null, this.child = null, this.config = {
|
1110
|
+
name: this.name,
|
1111
|
+
defaultOptions: {}
|
1112
|
+
}, this.config = {
|
1113
|
+
...this.config,
|
1114
|
+
...e
|
1115
|
+
}, this.name = this.config.name, e.defaultOptions && Object.keys(e.defaultOptions).length > 0 && console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`), this.options = this.config.defaultOptions, this.config.addOptions && (this.options = x(w(this, "addOptions", {
|
1116
|
+
name: this.name
|
1117
|
+
}))), this.storage = x(w(this, "addStorage", {
|
1118
|
+
name: this.name,
|
1119
|
+
options: this.options
|
1120
|
+
})) || {};
|
1121
|
+
}
|
1122
|
+
static create(e = {}) {
|
1123
|
+
return new W(e);
|
1124
|
+
}
|
1125
|
+
configure(e = {}) {
|
1126
|
+
const n = this.extend();
|
1127
|
+
return n.options = Q(this.options, e), n.storage = x(w(n, "addStorage", {
|
1128
|
+
name: n.name,
|
1129
|
+
options: n.options
|
1130
|
+
})), n;
|
1131
|
+
}
|
1132
|
+
extend(e = {}) {
|
1133
|
+
const n = new W({ ...this.config, ...e });
|
1134
|
+
return n.parent = this, this.child = n, n.name = e.name ? e.name : n.parent.name, e.defaultOptions && console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`), n.options = x(w(n, "addOptions", {
|
1135
|
+
name: n.name
|
1136
|
+
})), n.storage = x(w(n, "addStorage", {
|
1137
|
+
name: n.name,
|
1138
|
+
options: n.options
|
1139
|
+
})), n;
|
1140
|
+
}
|
1141
|
+
}
|
1142
|
+
const wn = /^```([a-z]+)?[\s\n]$/, xn = /^~~~([a-z]+)?[\s\n]$/, bn = W.create({
|
1143
|
+
name: "codeBlock",
|
1144
|
+
addOptions() {
|
1145
|
+
return {
|
1146
|
+
languageClassPrefix: "language-",
|
1147
|
+
exitOnTripleEnter: !0,
|
1148
|
+
exitOnArrowDown: !0,
|
1149
|
+
HTMLAttributes: {}
|
1150
|
+
};
|
1151
|
+
},
|
1152
|
+
content: "text*",
|
1153
|
+
marks: "",
|
1154
|
+
group: "block",
|
1155
|
+
code: !0,
|
1156
|
+
defining: !0,
|
1157
|
+
addAttributes() {
|
1158
|
+
return {
|
1159
|
+
language: {
|
1160
|
+
default: null,
|
1161
|
+
parseHTML: (t) => {
|
1162
|
+
var e;
|
1163
|
+
const { languageClassPrefix: n } = this.options, s = [...((e = t.firstElementChild) === null || e === void 0 ? void 0 : e.classList) || []].filter((i) => i.startsWith(n)).map((i) => i.replace(n, ""))[0];
|
1164
|
+
return s || null;
|
1165
|
+
},
|
1166
|
+
rendered: !1
|
1167
|
+
}
|
1168
|
+
};
|
1169
|
+
},
|
1170
|
+
parseHTML() {
|
1171
|
+
return [
|
1172
|
+
{
|
1173
|
+
tag: "pre",
|
1174
|
+
preserveWhitespace: "full"
|
1175
|
+
}
|
1176
|
+
];
|
1177
|
+
},
|
1178
|
+
renderHTML({ node: t, HTMLAttributes: e }) {
|
1179
|
+
return [
|
1180
|
+
"pre",
|
1181
|
+
qe(this.options.HTMLAttributes, e),
|
1182
|
+
[
|
1183
|
+
"code",
|
1184
|
+
{
|
1185
|
+
class: t.attrs.language ? this.options.languageClassPrefix + t.attrs.language : null
|
1186
|
+
},
|
1187
|
+
0
|
1188
|
+
]
|
1189
|
+
];
|
1190
|
+
},
|
1191
|
+
addCommands() {
|
1192
|
+
return {
|
1193
|
+
setCodeBlock: (t) => ({ commands: e }) => e.setNode(this.name, t),
|
1194
|
+
toggleCodeBlock: (t) => ({ commands: e }) => e.toggleNode(this.name, "paragraph", t)
|
1195
|
+
};
|
1196
|
+
},
|
1197
|
+
addKeyboardShortcuts() {
|
1198
|
+
return {
|
1199
|
+
"Mod-Alt-c": () => this.editor.commands.toggleCodeBlock(),
|
1200
|
+
// remove code block when at start of document or code block is empty
|
1201
|
+
Backspace: () => {
|
1202
|
+
const { empty: t, $anchor: e } = this.editor.state.selection, n = e.pos === 1;
|
1203
|
+
return !t || e.parent.type.name !== this.name ? !1 : n || !e.parent.textContent.length ? this.editor.commands.clearNodes() : !1;
|
1204
|
+
},
|
1205
|
+
// exit node on triple enter
|
1206
|
+
Enter: ({ editor: t }) => {
|
1207
|
+
if (!this.options.exitOnTripleEnter)
|
1208
|
+
return !1;
|
1209
|
+
const { state: e } = t, { selection: n } = e, { $from: r, empty: o } = n;
|
1210
|
+
if (!o || r.parent.type !== this.type)
|
1211
|
+
return !1;
|
1212
|
+
const s = r.parentOffset === r.parent.nodeSize - 2, i = r.parent.textContent.endsWith(`
|
1213
|
+
|
1214
|
+
`);
|
1215
|
+
return !s || !i ? !1 : t.chain().command(({ tr: a }) => (a.delete(r.pos - 2, r.pos), !0)).exitCode().run();
|
1216
|
+
},
|
1217
|
+
// exit node on arrow down
|
1218
|
+
ArrowDown: ({ editor: t }) => {
|
1219
|
+
if (!this.options.exitOnArrowDown)
|
1220
|
+
return !1;
|
1221
|
+
const { state: e } = t, { selection: n, doc: r } = e, { $from: o, empty: s } = n;
|
1222
|
+
if (!s || o.parent.type !== this.type || !(o.parentOffset === o.parent.nodeSize - 2))
|
1223
|
+
return !1;
|
1224
|
+
const a = o.after();
|
1225
|
+
return a === void 0 || r.nodeAt(a) ? !1 : t.commands.exitCode();
|
1226
|
+
}
|
1227
|
+
};
|
1228
|
+
},
|
1229
|
+
addInputRules() {
|
1230
|
+
return [
|
1231
|
+
se({
|
1232
|
+
find: wn,
|
1233
|
+
type: this.type,
|
1234
|
+
getAttributes: (t) => ({
|
1235
|
+
language: t[1]
|
1236
|
+
})
|
1237
|
+
}),
|
1238
|
+
se({
|
1239
|
+
find: xn,
|
1240
|
+
type: this.type,
|
1241
|
+
getAttributes: (t) => ({
|
1242
|
+
language: t[1]
|
1243
|
+
})
|
1244
|
+
})
|
1245
|
+
];
|
1246
|
+
},
|
1247
|
+
addProseMirrorPlugins() {
|
1248
|
+
return [
|
1249
|
+
// this plugin creates a code block for pasted content from VS Code
|
1250
|
+
// we can also detect the copied code language
|
1251
|
+
new B({
|
1252
|
+
key: new N("codeBlockVSCodeHandler"),
|
1253
|
+
props: {
|
1254
|
+
handlePaste: (t, e) => {
|
1255
|
+
if (!e.clipboardData || this.editor.isActive(this.type.name))
|
1256
|
+
return !1;
|
1257
|
+
const n = e.clipboardData.getData("text/plain"), r = e.clipboardData.getData("vscode-editor-data"), o = r ? JSON.parse(r) : void 0, s = o == null ? void 0 : o.mode;
|
1258
|
+
if (!n || !s)
|
1259
|
+
return !1;
|
1260
|
+
const { tr: i } = t.state;
|
1261
|
+
return i.replaceSelectionWith(this.type.create({ language: s })), i.setSelection(S.near(i.doc.resolve(Math.max(0, i.selection.from - 2)))), i.insertText(n.replace(/\r\n?/g, `
|
1262
|
+
`)), i.setMeta("paste", !0), t.dispatch(i), !0;
|
1263
|
+
}
|
1264
|
+
}
|
1265
|
+
})
|
1266
|
+
];
|
1267
|
+
}
|
1268
|
+
});
|
1269
|
+
let j, O;
|
1270
|
+
const q = /* @__PURE__ */ new Set(), J = /* @__PURE__ */ new Set(), Sn = (t) => {
|
1271
|
+
if (!j)
|
1272
|
+
return j = Ve({
|
1273
|
+
themes: [t.defaultTheme],
|
1274
|
+
langs: []
|
1275
|
+
}).then((r) => {
|
1276
|
+
J.add(t.defaultTheme), O = r;
|
1277
|
+
}), j;
|
1278
|
+
if (!O)
|
1279
|
+
return j;
|
1280
|
+
const e = t.language;
|
1281
|
+
if (e && !q.has(e) && e in _e)
|
1282
|
+
return O.loadLanguage(e).then(() => {
|
1283
|
+
q.add(e);
|
1284
|
+
});
|
1285
|
+
const n = t.theme;
|
1286
|
+
if (n && !J.has(n) && n in Je)
|
1287
|
+
return O.loadTheme(n).then(() => {
|
1288
|
+
J.add(n);
|
1289
|
+
});
|
1290
|
+
};
|
1291
|
+
function ie({
|
1292
|
+
doc: t,
|
1293
|
+
name: e,
|
1294
|
+
defaultLanguage: n,
|
1295
|
+
defaultTheme: r
|
1296
|
+
}) {
|
1297
|
+
const o = [];
|
1298
|
+
return U(t, (s) => s.type.name === e).forEach((s) => {
|
1299
|
+
let i = s.pos + 1, a = s.node.attrs.language || n, c = s.node.attrs.theme || r;
|
1300
|
+
if (Sn({ language: a, theme: c, defaultTheme: r }), q.has(a) || (a = "plaintext"), !O)
|
1301
|
+
return s.node;
|
1302
|
+
const d = O.codeToTokensBase(s.node.textContent, {
|
1303
|
+
lang: a,
|
1304
|
+
theme: c
|
1305
|
+
});
|
1306
|
+
for (const f of d) {
|
1307
|
+
for (const l of f) {
|
1308
|
+
const u = i + l.content.length, p = ke.inline(i, u, {
|
1309
|
+
style: `color: ${l.color}`
|
1310
|
+
});
|
1311
|
+
o.push(p), i = u;
|
1312
|
+
}
|
1313
|
+
i += 1;
|
1314
|
+
}
|
1315
|
+
}), ge.create(t, o);
|
1316
|
+
}
|
1317
|
+
function Mn({
|
1318
|
+
name: t,
|
1319
|
+
defaultLanguage: e,
|
1320
|
+
defaultTheme: n
|
1321
|
+
}) {
|
1322
|
+
const r = new B({
|
1323
|
+
key: new N("shiki"),
|
1324
|
+
state: {
|
1325
|
+
init: (o, { doc: s }) => ie({
|
1326
|
+
doc: s,
|
1327
|
+
name: t,
|
1328
|
+
defaultLanguage: e,
|
1329
|
+
defaultTheme: n
|
1330
|
+
}),
|
1331
|
+
apply: (o, s, i, a) => {
|
1332
|
+
const c = i.selection.$head.parent.type.name, d = a.selection.$head.parent.type.name, f = U(
|
1333
|
+
i.doc,
|
1334
|
+
(u) => u.type.name === t
|
1335
|
+
), l = U(
|
1336
|
+
a.doc,
|
1337
|
+
(u) => u.type.name === t
|
1338
|
+
);
|
1339
|
+
return o.docChanged && // Apply decorations if:
|
1340
|
+
// selection includes named node,
|
1341
|
+
([c, d].includes(t) || // OR transaction adds/removes named node,
|
1342
|
+
l.length !== f.length || // OR transaction has changes that completely encapsulte a node
|
1343
|
+
// (for example, a transaction that affects the entire document).
|
1344
|
+
// Such transactions can happen during collab syncing via y-prosemirror, for example.
|
1345
|
+
o.steps.some((u) => (
|
1346
|
+
// @ts-ignore
|
1347
|
+
u.from !== void 0 && // @ts-ignore
|
1348
|
+
u.to !== void 0 && f.some((p) => (
|
1349
|
+
// @ts-ignore
|
1350
|
+
p.pos >= u.from && // @ts-ignore
|
1351
|
+
p.pos + p.node.nodeSize <= u.to
|
1352
|
+
))
|
1353
|
+
))) ? ie({
|
1354
|
+
doc: o.doc,
|
1355
|
+
name: t,
|
1356
|
+
defaultLanguage: e,
|
1357
|
+
defaultTheme: n
|
1358
|
+
}) : s.map(o.mapping, o.doc);
|
1359
|
+
}
|
1360
|
+
},
|
1361
|
+
props: {
|
1362
|
+
decorations(o) {
|
1363
|
+
return r.getState(o);
|
1364
|
+
}
|
1365
|
+
}
|
1366
|
+
});
|
1367
|
+
return r;
|
1368
|
+
}
|
1369
|
+
const Nn = bn.extend({
|
1370
|
+
addOptions() {
|
1371
|
+
var t;
|
1372
|
+
return {
|
1373
|
+
...(t = this.parent) == null ? void 0 : t.call(this),
|
1374
|
+
defaultLanguage: null,
|
1375
|
+
defaultTheme: "github-dark"
|
1376
|
+
};
|
1377
|
+
},
|
1378
|
+
addProseMirrorPlugins() {
|
1379
|
+
var t;
|
1380
|
+
return [
|
1381
|
+
...((t = this.parent) == null ? void 0 : t.call(this)) || [],
|
1382
|
+
Mn({
|
1383
|
+
name: this.name,
|
1384
|
+
defaultLanguage: this.options.defaultLanguage,
|
1385
|
+
defaultTheme: this.options.defaultTheme
|
1386
|
+
})
|
1387
|
+
];
|
1388
|
+
}
|
1389
|
+
});
|
1390
|
+
export {
|
1391
|
+
Nn as CodeBlockShiki,
|
1392
|
+
Nn as default
|
1393
|
+
};
|