tiptap-extension-code-block-shiki 0.5.1 → 0.6.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.
@@ -1,12 +1,12 @@
|
|
1
|
-
import { Plugin as
|
2
|
-
import { DecorationSet as
|
1
|
+
import { Plugin as P, PluginKey as N, Selection as O, TextSelection as b, NodeSelection as ce } from "@tiptap/pm/state";
|
2
|
+
import { DecorationSet as Se, Decoration as ee } from "@tiptap/pm/view";
|
3
3
|
import "@tiptap/pm/keymap";
|
4
4
|
import { Fragment as L, Slice as be, DOMParser as Me } from "@tiptap/pm/model";
|
5
|
-
import { liftTarget as Ae, joinPoint as
|
6
|
-
import { createParagraphNear as Ee, deleteSelection as Be, exitCode as ve, joinUp as
|
5
|
+
import { liftTarget as Ae, joinPoint as le, canSplit as R, ReplaceStep as Te, ReplaceAroundStep as Ce, canJoin as de } from "@tiptap/pm/transform";
|
6
|
+
import { createParagraphNear as Ee, deleteSelection as Be, exitCode as ve, joinUp as $e, joinDown as Ie, joinBackward as Pe, joinForward as Ne, joinTextblockBackward as Oe, joinTextblockForward as je, lift as Fe, liftEmptyBlock as Le, newlineInCode as Re, selectNodeBackward as De, selectNodeForward as ze, selectParentNode as We, selectTextblockEnd as He, selectTextblockStart as Ke, setBlockType as te, wrapIn as Ve } from "@tiptap/pm/commands";
|
7
7
|
import { liftListItem as _e, sinkListItem as Je, wrapInList as Ue } from "@tiptap/pm/schema-list";
|
8
|
-
import { bundledThemes as
|
9
|
-
function
|
8
|
+
import { bundledThemes as ue, bundledLanguages as fe, createHighlighter as Ge } from "shiki";
|
9
|
+
function pe(e) {
|
10
10
|
const { state: t, transaction: n } = e;
|
11
11
|
let { selection: o } = n, { doc: r } = n, { storedMarks: s } = n;
|
12
12
|
return {
|
@@ -44,8 +44,8 @@ class qe {
|
|
44
44
|
get commands() {
|
45
45
|
const { rawCommands: t, editor: n, state: o } = this, { view: r } = n, { tr: s } = o, a = this.buildProps(s);
|
46
46
|
return Object.fromEntries(Object.entries(t).map(([i, c]) => [i, (...u) => {
|
47
|
-
const
|
48
|
-
return !s.getMeta("preventDispatch") && !this.hasCustomState && r.dispatch(s),
|
47
|
+
const l = c(...u)(a);
|
48
|
+
return !s.getMeta("preventDispatch") && !this.hasCustomState && r.dispatch(s), l;
|
49
49
|
}]));
|
50
50
|
}
|
51
51
|
get chain() {
|
@@ -55,19 +55,19 @@ class qe {
|
|
55
55
|
return () => this.createCan();
|
56
56
|
}
|
57
57
|
createChain(t, n = !0) {
|
58
|
-
const { rawCommands: o, editor: r, state: s } = this, { view: a } = r, i = [], c = !!t,
|
58
|
+
const { rawCommands: o, editor: r, state: s } = this, { view: a } = r, i = [], c = !!t, d = t || s.tr, u = () => (!c && n && !d.getMeta("preventDispatch") && !this.hasCustomState && a.dispatch(d), i.every((f) => f === !0)), l = {
|
59
59
|
...Object.fromEntries(Object.entries(o).map(([f, p]) => [f, (...h) => {
|
60
|
-
const g = this.buildProps(
|
61
|
-
return i.push(k),
|
60
|
+
const g = this.buildProps(d, n), k = p(...h)(g);
|
61
|
+
return i.push(k), l;
|
62
62
|
}])),
|
63
63
|
run: u
|
64
64
|
};
|
65
|
-
return
|
65
|
+
return l;
|
66
66
|
}
|
67
67
|
createCan(t) {
|
68
68
|
const { rawCommands: n, state: o } = this, r = !1, s = t || o.tr, a = this.buildProps(s, r);
|
69
69
|
return {
|
70
|
-
...Object.fromEntries(Object.entries(n).map(([c,
|
70
|
+
...Object.fromEntries(Object.entries(n).map(([c, d]) => [c, (...u) => d(...u)({ ...a, dispatch: void 0 })])),
|
71
71
|
chain: () => this.createChain(s, r)
|
72
72
|
};
|
73
73
|
}
|
@@ -76,7 +76,7 @@ class qe {
|
|
76
76
|
tr: t,
|
77
77
|
editor: r,
|
78
78
|
view: a,
|
79
|
-
state:
|
79
|
+
state: pe({
|
80
80
|
state: s,
|
81
81
|
transaction: t
|
82
82
|
}),
|
@@ -85,7 +85,7 @@ class qe {
|
|
85
85
|
chain: () => this.createChain(t, n),
|
86
86
|
can: () => this.createCan(t),
|
87
87
|
get commands() {
|
88
|
-
return Object.fromEntries(Object.entries(o).map(([c,
|
88
|
+
return Object.fromEntries(Object.entries(o).map(([c, d]) => [c, (...u) => d(...u)(i)]));
|
89
89
|
}
|
90
90
|
};
|
91
91
|
return i;
|
@@ -122,8 +122,8 @@ function Xe(...e) {
|
|
122
122
|
return;
|
123
123
|
}
|
124
124
|
if (r === "class") {
|
125
|
-
const i = s ? s.split(" ") : [], c = o[r] ? o[r].split(" ") : [],
|
126
|
-
o[r] = [...c, ...
|
125
|
+
const i = s ? s.split(" ") : [], c = o[r] ? o[r].split(" ") : [], d = i.filter((u) => !c.includes(u));
|
126
|
+
o[r] = [...c, ...d].join(" ");
|
127
127
|
} else
|
128
128
|
r === "style" ? o[r] = [o[r], s].join("; ") : o[r] = s;
|
129
129
|
}), o;
|
@@ -195,18 +195,18 @@ function nt(e, t, n) {
|
|
195
195
|
|
196
196
|
`, textSerializers: a = {} } = n || {};
|
197
197
|
let i = "", c = !0;
|
198
|
-
return e.nodesBetween(o, r, (
|
198
|
+
return e.nodesBetween(o, r, (d, u, l, f) => {
|
199
199
|
var p;
|
200
|
-
const m = a == null ? void 0 : a[
|
200
|
+
const m = a == null ? void 0 : a[d.type.name];
|
201
201
|
if (m)
|
202
|
-
return
|
203
|
-
node:
|
202
|
+
return d.isBlock && !c && (i += s, c = !0), l && (i += m({
|
203
|
+
node: d,
|
204
204
|
pos: u,
|
205
|
-
parent:
|
205
|
+
parent: l,
|
206
206
|
index: f,
|
207
207
|
range: t
|
208
208
|
})), !1;
|
209
|
-
|
209
|
+
d.isText ? (i += (p = d == null ? void 0 : d.text) === null || p === void 0 ? void 0 : p.slice(Math.max(o, u) - u, r - u), c = !1) : d.isBlock && !c && (i += s, c = !0);
|
210
210
|
}), i;
|
211
211
|
}
|
212
212
|
function ot(e) {
|
@@ -221,7 +221,7 @@ C.create({
|
|
221
221
|
},
|
222
222
|
addProseMirrorPlugins() {
|
223
223
|
return [
|
224
|
-
new
|
224
|
+
new P({
|
225
225
|
key: new N("clipboardTextSerializer"),
|
226
226
|
props: {
|
227
227
|
clipboardTextSerializer: () => {
|
@@ -245,12 +245,12 @@ const rt = () => ({ editor: e, view: t }) => (requestAnimationFrame(() => {
|
|
245
245
|
e.doc.nodesBetween(s.pos, a.pos, (i, c) => {
|
246
246
|
if (i.type.isText)
|
247
247
|
return;
|
248
|
-
const { doc:
|
248
|
+
const { doc: d, mapping: u } = t, l = d.resolve(u.map(c)), f = d.resolve(u.map(c + i.nodeSize)), p = l.blockRange(f);
|
249
249
|
if (!p)
|
250
250
|
return;
|
251
251
|
const m = Ae(p);
|
252
252
|
if (i.type.isTextblock) {
|
253
|
-
const { defaultType: h } =
|
253
|
+
const { defaultType: h } = l.parent.contentMatchAt(l.index());
|
254
254
|
t.setNodeMarkup(p.start, h);
|
255
255
|
}
|
256
256
|
(m || m === 0) && t.lift(p, m);
|
@@ -280,8 +280,8 @@ const rt = () => ({ editor: e, view: t }) => (requestAnimationFrame(() => {
|
|
280
280
|
for (let a = s.depth; a > 0; a -= 1)
|
281
281
|
if (s.node(a).type === r) {
|
282
282
|
if (o) {
|
283
|
-
const c = s.before(a),
|
284
|
-
t.delete(c,
|
283
|
+
const c = s.before(a), d = s.after(a);
|
284
|
+
t.delete(c, d).scrollIntoView();
|
285
285
|
}
|
286
286
|
return !0;
|
287
287
|
}
|
@@ -300,7 +300,7 @@ function q(e, t, n = {}) {
|
|
300
300
|
function gt(e, t, n = {}) {
|
301
301
|
return !!q(e, t, n);
|
302
302
|
}
|
303
|
-
function
|
303
|
+
function me(e, t, n = {}) {
|
304
304
|
if (!e || !t)
|
305
305
|
return;
|
306
306
|
let o = e.parent.childAfter(e.parentOffset);
|
@@ -319,7 +319,7 @@ function pe(e, t, n = {}) {
|
|
319
319
|
to: c
|
320
320
|
};
|
321
321
|
}
|
322
|
-
function
|
322
|
+
function $(e, t) {
|
323
323
|
if (typeof e == "string") {
|
324
324
|
if (!t.marks[e])
|
325
325
|
throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);
|
@@ -328,11 +328,11 @@ function I(e, t) {
|
|
328
328
|
return e;
|
329
329
|
}
|
330
330
|
const kt = (e, t = {}) => ({ tr: n, state: o, dispatch: r }) => {
|
331
|
-
const s =
|
331
|
+
const s = $(e, o.schema), { doc: a, selection: i } = n, { $from: c, from: d, to: u } = i;
|
332
332
|
if (r) {
|
333
|
-
const
|
334
|
-
if (
|
335
|
-
const f = b.create(a,
|
333
|
+
const l = me(c, s, t);
|
334
|
+
if (l && l.from <= d && l.to >= u) {
|
335
|
+
const f = b.create(a, l.from, l.to);
|
336
336
|
n.setSelection(f);
|
337
337
|
}
|
338
338
|
}
|
@@ -344,10 +344,10 @@ const kt = (e, t = {}) => ({ tr: n, state: o, dispatch: r }) => {
|
|
344
344
|
return !0;
|
345
345
|
return !1;
|
346
346
|
};
|
347
|
-
function
|
347
|
+
function he(e) {
|
348
348
|
return e instanceof b;
|
349
349
|
}
|
350
|
-
function
|
350
|
+
function I(e = 0, t = 0, n = 0) {
|
351
351
|
return Math.min(Math.max(e, t), n);
|
352
352
|
}
|
353
353
|
function wt(e, t = null) {
|
@@ -359,7 +359,7 @@ function wt(e, t = null) {
|
|
359
359
|
if (t === "end")
|
360
360
|
return o;
|
361
361
|
const r = n.from, s = o.to;
|
362
|
-
return t === "all" ? b.create(e,
|
362
|
+
return t === "all" ? b.create(e, I(0, r, s), I(e.content.size, r, s)) : b.create(e, I(t, r, s), I(t, r, s));
|
363
363
|
}
|
364
364
|
function X() {
|
365
365
|
return [
|
@@ -383,21 +383,21 @@ const xt = (e = null, t = {}) => ({ editor: n, view: o, tr: r, dispatch: s }) =>
|
|
383
383
|
};
|
384
384
|
if (o.hasFocus() && e === null || e === !1)
|
385
385
|
return !0;
|
386
|
-
if (s && e === null && !
|
386
|
+
if (s && e === null && !he(n.state.selection))
|
387
387
|
return a(), !0;
|
388
388
|
const i = wt(r.doc, e) || n.state.selection, c = n.state.selection.eq(i);
|
389
389
|
return s && (c || r.setSelection(i), c && r.storedMarks && r.setStoredMarks(r.storedMarks), a()), !0;
|
390
|
-
}, St = (e, t) => (n) => e.every((o, r) => t(o, { ...n, index: r })), bt = (e, t) => ({ tr: n, commands: o }) => o.insertContentAt({ from: n.selection.from, to: n.selection.to }, e, t),
|
390
|
+
}, St = (e, t) => (n) => e.every((o, r) => t(o, { ...n, index: r })), bt = (e, t) => ({ tr: n, commands: o }) => o.insertContentAt({ from: n.selection.from, to: n.selection.to }, e, t), ge = (e) => {
|
391
391
|
const t = e.childNodes;
|
392
392
|
for (let n = t.length - 1; n >= 0; n -= 1) {
|
393
393
|
const o = t[n];
|
394
|
-
o.nodeType === 3 && o.nodeValue && /^(\n\s\s|\n)$/.test(o.nodeValue) ? e.removeChild(o) : o.nodeType === 1 &&
|
394
|
+
o.nodeType === 3 && o.nodeValue && /^(\n\s\s|\n)$/.test(o.nodeValue) ? e.removeChild(o) : o.nodeType === 1 && ge(o);
|
395
395
|
}
|
396
396
|
return e;
|
397
397
|
};
|
398
|
-
function
|
398
|
+
function ne(e) {
|
399
399
|
const t = `<body>${e}</body>`, n = new window.DOMParser().parseFromString(t, "text/html").body;
|
400
|
-
return
|
400
|
+
return ge(n);
|
401
401
|
}
|
402
402
|
function W(e, t, n) {
|
403
403
|
if (n = {
|
@@ -412,7 +412,7 @@ function W(e, t, n) {
|
|
412
412
|
}
|
413
413
|
if (typeof e == "string") {
|
414
414
|
const o = Me.fromSchema(t);
|
415
|
-
return n.slice ? o.parseSlice(
|
415
|
+
return n.slice ? o.parseSlice(ne(e), n.parseOptions).content : o.parse(ne(e), n.parseOptions);
|
416
416
|
}
|
417
417
|
return W("", t, n);
|
418
418
|
}
|
@@ -425,7 +425,7 @@ function Mt(e, t, n) {
|
|
425
425
|
return;
|
426
426
|
const s = e.mapping.maps[o];
|
427
427
|
let a = 0;
|
428
|
-
s.forEach((i, c,
|
428
|
+
s.forEach((i, c, d, u) => {
|
429
429
|
a === 0 && (a = u);
|
430
430
|
}), e.setSelection(O.near(e.doc.resolve(a), n));
|
431
431
|
}
|
@@ -446,33 +446,33 @@ const At = (e) => e.toString().startsWith("<"), Tt = (e, t, n) => ({ tr: o, disp
|
|
446
446
|
});
|
447
447
|
if (a.toString() === "<>")
|
448
448
|
return !0;
|
449
|
-
let { from: i, to: c } = typeof e == "number" ? { from: e, to: e } : { from: e.from, to: e.to },
|
449
|
+
let { from: i, to: c } = typeof e == "number" ? { from: e, to: e } : { from: e.from, to: e.to }, d = !0, u = !0;
|
450
450
|
if ((At(a) ? a : [a]).forEach((p) => {
|
451
|
-
p.check(),
|
451
|
+
p.check(), d = d ? p.isText && p.marks.length === 0 : !1, u = u ? p.isBlock : !1;
|
452
452
|
}), i === c && u) {
|
453
453
|
const { parent: p } = o.doc.resolve(i);
|
454
454
|
p.isTextblock && !p.type.spec.code && !p.childCount && (i -= 1, c += 1);
|
455
455
|
}
|
456
456
|
let f;
|
457
|
-
|
457
|
+
d ? (Array.isArray(t) ? f = t.map((p) => p.text || "").join("") : typeof t == "object" && t && t.text ? f = t.text : f = t, o.insertText(f, i, c)) : (f = a, o.replaceWith(i, c, f)), n.updateSelection && Mt(o, o.steps.length - 1, -1), n.applyInputRules && o.setMeta("applyInputRules", { from: i, text: f }), n.applyPasteRules && o.setMeta("applyPasteRules", { from: i, text: f });
|
458
458
|
}
|
459
459
|
return !0;
|
460
|
-
}, Ct = () => ({ state: e, dispatch: t }) =>
|
460
|
+
}, Ct = () => ({ state: e, dispatch: t }) => $e(e, t), Et = () => ({ state: e, dispatch: t }) => Ie(e, t), Bt = () => ({ state: e, dispatch: t }) => Pe(e, t), vt = () => ({ state: e, dispatch: t }) => Ne(e, t), $t = () => ({ tr: e, state: t, dispatch: n }) => {
|
461
461
|
try {
|
462
|
-
const o =
|
462
|
+
const o = le(t.doc, t.selection.$from.pos, -1);
|
463
463
|
return o == null ? !1 : (e.join(o, 2), n && n(e), !0);
|
464
464
|
} catch {
|
465
465
|
return !1;
|
466
466
|
}
|
467
|
-
},
|
467
|
+
}, It = () => ({ state: e, dispatch: t, tr: n }) => {
|
468
468
|
try {
|
469
|
-
const o =
|
469
|
+
const o = le(e.doc, e.selection.$from.pos, 1);
|
470
470
|
return o == null ? !1 : (n.join(o, 2), t && t(n), !0);
|
471
471
|
} catch {
|
472
472
|
return !1;
|
473
473
|
}
|
474
|
-
},
|
475
|
-
function
|
474
|
+
}, Pt = () => ({ state: e, dispatch: t }) => Oe(e, t), Nt = () => ({ state: e, dispatch: t }) => je(e, t);
|
475
|
+
function ke() {
|
476
476
|
return typeof navigator < "u" ? /Mac/.test(navigator.platform) : !1;
|
477
477
|
}
|
478
478
|
function Ot(e) {
|
@@ -491,14 +491,14 @@ function Ot(e) {
|
|
491
491
|
else if (/^s(hift)?$/i.test(c))
|
492
492
|
s = !0;
|
493
493
|
else if (/^mod$/i.test(c))
|
494
|
-
X() ||
|
494
|
+
X() || ke() ? a = !0 : r = !0;
|
495
495
|
else
|
496
496
|
throw new Error(`Unrecognized modifier name: ${c}`);
|
497
497
|
}
|
498
498
|
return o && (n = `Alt-${n}`), r && (n = `Ctrl-${n}`), a && (n = `Meta-${n}`), s && (n = `Shift-${n}`), n;
|
499
499
|
}
|
500
500
|
const jt = (e) => ({ editor: t, view: n, tr: o, dispatch: r }) => {
|
501
|
-
const s = Ot(e).split(/-(?!$)/), a = s.find((
|
501
|
+
const s = Ot(e).split(/-(?!$)/), a = s.find((d) => !["Alt", "Ctrl", "Meta", "Shift"].includes(d)), i = new KeyboardEvent("keydown", {
|
502
502
|
key: a === "Space" ? " " : a,
|
503
503
|
altKey: s.includes("Alt"),
|
504
504
|
ctrlKey: s.includes("Ctrl"),
|
@@ -507,27 +507,27 @@ const jt = (e) => ({ editor: t, view: n, tr: o, dispatch: r }) => {
|
|
507
507
|
bubbles: !0,
|
508
508
|
cancelable: !0
|
509
509
|
}), c = t.captureTransaction(() => {
|
510
|
-
n.someProp("handleKeyDown", (
|
510
|
+
n.someProp("handleKeyDown", (d) => d(n, i));
|
511
511
|
});
|
512
|
-
return c == null || c.steps.forEach((
|
513
|
-
const u =
|
512
|
+
return c == null || c.steps.forEach((d) => {
|
513
|
+
const u = d.map(o.mapping);
|
514
514
|
u && r && o.maybeStep(u);
|
515
515
|
}), !0;
|
516
516
|
};
|
517
517
|
function Y(e, t, n = {}) {
|
518
518
|
const { from: o, to: r, empty: s } = e.selection, a = t ? y(t, e.schema) : null, i = [];
|
519
|
-
e.doc.nodesBetween(o, r, (
|
520
|
-
if (
|
519
|
+
e.doc.nodesBetween(o, r, (l, f) => {
|
520
|
+
if (l.isText)
|
521
521
|
return;
|
522
|
-
const p = Math.max(o, f), m = Math.min(r, f +
|
522
|
+
const p = Math.max(o, f), m = Math.min(r, f + l.nodeSize);
|
523
523
|
i.push({
|
524
|
-
node:
|
524
|
+
node: l,
|
525
525
|
from: p,
|
526
526
|
to: m
|
527
527
|
});
|
528
528
|
});
|
529
|
-
const c = r - o,
|
530
|
-
return s ? !!
|
529
|
+
const c = r - o, d = i.filter((l) => a ? a.name === l.node.type.name : !0).filter((l) => z(l.node.attrs, n, { strict: !1 }));
|
530
|
+
return s ? !!d.length : d.reduce((l, f) => l + f.to - f.from, 0) >= c;
|
531
531
|
}
|
532
532
|
const Ft = (e, t = {}) => ({ state: n, dispatch: o }) => {
|
533
533
|
const r = y(e, n.schema);
|
@@ -536,20 +536,20 @@ const Ft = (e, t = {}) => ({ state: n, dispatch: o }) => {
|
|
536
536
|
const o = y(e, t.schema);
|
537
537
|
return _e(o)(t, n);
|
538
538
|
}, Dt = () => ({ state: e, dispatch: t }) => Re(e, t);
|
539
|
-
function
|
539
|
+
function ye(e, t) {
|
540
540
|
return t.nodes[e] ? "node" : t.marks[e] ? "mark" : null;
|
541
541
|
}
|
542
|
-
function
|
542
|
+
function oe(e, t) {
|
543
543
|
const n = typeof t == "string" ? [t] : t;
|
544
544
|
return Object.keys(e).reduce((o, r) => (n.includes(r) || (o[r] = e[r]), o), {});
|
545
545
|
}
|
546
546
|
const zt = (e, t) => ({ tr: n, state: o, dispatch: r }) => {
|
547
547
|
let s = null, a = null;
|
548
|
-
const i =
|
549
|
-
return i ? (i === "node" && (s = y(e, o.schema)), i === "mark" && (a =
|
550
|
-
o.doc.nodesBetween(c.$from.pos, c.$to.pos, (
|
551
|
-
s && s ===
|
552
|
-
a ===
|
548
|
+
const i = ye(typeof e == "string" ? e : e.name, o.schema);
|
549
|
+
return i ? (i === "node" && (s = y(e, o.schema)), i === "mark" && (a = $(e, o.schema)), r && n.selection.ranges.forEach((c) => {
|
550
|
+
o.doc.nodesBetween(c.$from.pos, c.$to.pos, (d, u) => {
|
551
|
+
s && s === d.type && n.setNodeMarkup(u, void 0, oe(d.attrs, t)), a && d.marks.length && d.marks.forEach((l) => {
|
552
|
+
a === l.type && n.addMark(u, u + d.nodeSize, a.create(oe(l.attrs, t)));
|
553
553
|
});
|
554
554
|
});
|
555
555
|
}), !0) : !1;
|
@@ -565,7 +565,7 @@ const qt = (e, t = !1, n = {}) => ({ tr: o, editor: r, dispatch: s }) => {
|
|
565
565
|
return s && o.replaceWith(0, a.content.size, i).setMeta("preventUpdate", !t), !0;
|
566
566
|
};
|
567
567
|
function Qt(e, t) {
|
568
|
-
const n =
|
568
|
+
const n = $(t, e.schema), { from: o, to: r, empty: s } = e.selection, a = [];
|
569
569
|
s ? (e.storedMarks && a.push(...e.storedMarks), a.push(...e.selection.$head.marks())) : e.doc.nodesBetween(o, r, (c) => {
|
570
570
|
a.push(...c.marks);
|
571
571
|
});
|
@@ -611,13 +611,13 @@ function D(e, t, n) {
|
|
611
611
|
}));
|
612
612
|
}
|
613
613
|
function Zt(e, t, n = {}) {
|
614
|
-
const { empty: o, ranges: r } = e.selection, s = t ?
|
614
|
+
const { empty: o, ranges: r } = e.selection, s = t ? $(t, e.schema) : null;
|
615
615
|
if (o)
|
616
|
-
return !!(e.storedMarks || e.selection.$from.marks()).filter((
|
616
|
+
return !!(e.storedMarks || e.selection.$from.marks()).filter((l) => s ? s.name === l.type.name : !0).find((l) => z(l.attrs, n, { strict: !1 }));
|
617
617
|
let a = 0;
|
618
618
|
const i = [];
|
619
|
-
if (r.forEach(({ $from:
|
620
|
-
const p =
|
619
|
+
if (r.forEach(({ $from: l, $to: f }) => {
|
620
|
+
const p = l.pos, m = f.pos;
|
621
621
|
e.doc.nodesBetween(p, m, (h, g) => {
|
622
622
|
if (!h.isText && !h.marks.length)
|
623
623
|
return;
|
@@ -630,10 +630,10 @@ function Zt(e, t, n = {}) {
|
|
630
630
|
});
|
631
631
|
}), a === 0)
|
632
632
|
return !1;
|
633
|
-
const c = i.filter((
|
634
|
-
return (c > 0 ? c +
|
633
|
+
const c = i.filter((l) => s ? s.name === l.mark.type.name : !0).filter((l) => z(l.mark.attrs, n, { strict: !1 })).reduce((l, f) => l + f.to - f.from, 0), d = i.filter((l) => s ? l.mark.type !== s && l.mark.type.excludes(s) : !0).reduce((l, f) => l + f.to - f.from, 0);
|
634
|
+
return (c > 0 ? c + d : c) >= a;
|
635
635
|
}
|
636
|
-
function
|
636
|
+
function re(e, t) {
|
637
637
|
const { nodeExtensions: n } = Qe(t), o = n.find((a) => a.name === e);
|
638
638
|
if (!o)
|
639
639
|
return !1;
|
@@ -648,38 +648,38 @@ function en(e, t, n) {
|
|
648
648
|
var o;
|
649
649
|
const { selection: r } = t;
|
650
650
|
let s = null;
|
651
|
-
if (
|
651
|
+
if (he(r) && (s = r.$cursor), s) {
|
652
652
|
const i = (o = e.storedMarks) !== null && o !== void 0 ? o : s.marks();
|
653
653
|
return !!n.isInSet(i) || !i.some((c) => c.type.excludes(n));
|
654
654
|
}
|
655
655
|
const { ranges: a } = r;
|
656
656
|
return a.some(({ $from: i, $to: c }) => {
|
657
|
-
let
|
658
|
-
return e.doc.nodesBetween(i.pos, c.pos, (u,
|
659
|
-
if (
|
657
|
+
let d = i.depth === 0 ? e.doc.inlineContent && e.doc.type.allowsMarkType(n) : !1;
|
658
|
+
return e.doc.nodesBetween(i.pos, c.pos, (u, l, f) => {
|
659
|
+
if (d)
|
660
660
|
return !1;
|
661
661
|
if (u.isInline) {
|
662
662
|
const p = !f || f.type.allowsMarkType(n), m = !!n.isInSet(u.marks) || !u.marks.some((h) => h.type.excludes(n));
|
663
|
-
|
663
|
+
d = p && m;
|
664
664
|
}
|
665
|
-
return !
|
666
|
-
}),
|
665
|
+
return !d;
|
666
|
+
}), d;
|
667
667
|
});
|
668
668
|
}
|
669
669
|
const tn = (e, t = {}) => ({ tr: n, state: o, dispatch: r }) => {
|
670
|
-
const { selection: s } = n, { empty: a, ranges: i } = s, c =
|
670
|
+
const { selection: s } = n, { empty: a, ranges: i } = s, c = $(e, o.schema);
|
671
671
|
if (r)
|
672
672
|
if (a) {
|
673
|
-
const
|
673
|
+
const d = Qt(o, c);
|
674
674
|
n.addStoredMark(c.create({
|
675
|
-
...
|
675
|
+
...d,
|
676
676
|
...t
|
677
677
|
}));
|
678
678
|
} else
|
679
|
-
i.forEach((
|
680
|
-
const u =
|
681
|
-
o.doc.nodesBetween(u,
|
682
|
-
const m = Math.max(p, u), h = Math.min(p + f.nodeSize,
|
679
|
+
i.forEach((d) => {
|
680
|
+
const u = d.$from.pos, l = d.$to.pos;
|
681
|
+
o.doc.nodesBetween(u, l, (f, p) => {
|
682
|
+
const m = Math.max(p, u), h = Math.min(p + f.nodeSize, l);
|
683
683
|
f.marks.find((k) => k.type === c) ? f.marks.forEach((k) => {
|
684
684
|
c === k.type && n.addMark(m, h, c.create({
|
685
685
|
...k.attrs,
|
@@ -691,16 +691,16 @@ const tn = (e, t = {}) => ({ tr: n, state: o, dispatch: r }) => {
|
|
691
691
|
return en(o, n, c);
|
692
692
|
}, nn = (e, t) => ({ tr: n }) => (n.setMeta(e, t), !0), on = (e, t = {}) => ({ state: n, dispatch: o, chain: r }) => {
|
693
693
|
const s = y(e, n.schema);
|
694
|
-
return s.isTextblock ? r().command(({ commands: a }) =>
|
694
|
+
return s.isTextblock ? r().command(({ commands: a }) => te(s, t)(n) ? !0 : a.clearNodes()).command(({ state: a }) => te(s, t)(a, o)).run() : (console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'), !1);
|
695
695
|
}, rn = (e) => ({ tr: t, dispatch: n }) => {
|
696
696
|
if (n) {
|
697
|
-
const { doc: o } = t, r =
|
697
|
+
const { doc: o } = t, r = I(e, 0, o.content.size), s = ce.create(o, r);
|
698
698
|
t.setSelection(s);
|
699
699
|
}
|
700
700
|
return !0;
|
701
701
|
}, sn = (e) => ({ tr: t, dispatch: n }) => {
|
702
702
|
if (n) {
|
703
|
-
const { doc: o } = t, { from: r, to: s } = typeof e == "number" ? { from: e, to: e } : e, a = b.atStart(o).from, i = b.atEnd(o).to, c =
|
703
|
+
const { doc: o } = t, { from: r, to: s } = typeof e == "number" ? { from: e, to: e } : e, a = b.atStart(o).from, i = b.atEnd(o).to, c = I(r, a, i), d = I(s, a, i), u = b.create(o, c, d);
|
704
704
|
t.setSelection(u);
|
705
705
|
}
|
706
706
|
return !0;
|
@@ -708,7 +708,7 @@ const tn = (e, t = {}) => ({ tr: n, state: o, dispatch: r }) => {
|
|
708
708
|
const o = y(e, t.schema);
|
709
709
|
return Je(o)(t, n);
|
710
710
|
};
|
711
|
-
function
|
711
|
+
function se(e, t) {
|
712
712
|
const n = e.storedMarks || e.selection.$to.parentOffset && e.selection.$from.marks();
|
713
713
|
if (n) {
|
714
714
|
const o = n.filter((r) => t == null ? void 0 : t.includes(r.type.name));
|
@@ -716,16 +716,16 @@ function re(e, t) {
|
|
716
716
|
}
|
717
717
|
}
|
718
718
|
const cn = ({ keepMarks: e = !0 } = {}) => ({ tr: t, state: n, dispatch: o, editor: r }) => {
|
719
|
-
const { selection: s, doc: a } = t, { $from: i, $to: c } = s,
|
720
|
-
if (s instanceof
|
721
|
-
return !i.parentOffset || !R(a, i.pos) ? !1 : (o && (e &&
|
719
|
+
const { selection: s, doc: a } = t, { $from: i, $to: c } = s, d = r.extensionManager.attributes, u = D(d, i.node().type.name, i.node().attrs);
|
720
|
+
if (s instanceof ce && s.node.isBlock)
|
721
|
+
return !i.parentOffset || !R(a, i.pos) ? !1 : (o && (e && se(n, r.extensionManager.splittableMarks), t.split(i.pos).scrollIntoView()), !0);
|
722
722
|
if (!i.parent.isBlock)
|
723
723
|
return !1;
|
724
724
|
if (o) {
|
725
|
-
const
|
725
|
+
const l = c.parentOffset === c.parent.content.size;
|
726
726
|
s instanceof b && t.deleteSelection();
|
727
727
|
const f = i.depth === 0 ? void 0 : Xt(i.node(-1).contentMatchAt(i.indexAfter(-1)));
|
728
|
-
let p =
|
728
|
+
let p = l && f ? [
|
729
729
|
{
|
730
730
|
type: f,
|
731
731
|
attrs: u
|
@@ -736,22 +736,22 @@ const cn = ({ keepMarks: e = !0 } = {}) => ({ tr: t, state: n, dispatch: o, edit
|
|
736
736
|
type: f,
|
737
737
|
attrs: u
|
738
738
|
}
|
739
|
-
] : void 0), m && (t.split(t.mapping.map(i.pos), 1, p), f && !
|
739
|
+
] : void 0), m && (t.split(t.mapping.map(i.pos), 1, p), f && !l && !i.parentOffset && i.parent.type !== f)) {
|
740
740
|
const h = t.mapping.map(i.before()), g = t.doc.resolve(h);
|
741
741
|
i.node(-1).canReplaceWith(g.index(), g.index() + 1, f) && t.setNodeMarkup(t.mapping.map(i.before()), f);
|
742
742
|
}
|
743
|
-
e &&
|
743
|
+
e && se(n, r.extensionManager.splittableMarks), t.scrollIntoView();
|
744
744
|
}
|
745
745
|
return !0;
|
746
746
|
}, ln = (e) => ({ tr: t, state: n, dispatch: o, editor: r }) => {
|
747
747
|
var s;
|
748
|
-
const a = y(e, n.schema), { $from: i, $to: c } = n.selection,
|
749
|
-
if (
|
748
|
+
const a = y(e, n.schema), { $from: i, $to: c } = n.selection, d = n.selection.node;
|
749
|
+
if (d && d.isBlock || i.depth < 2 || !i.sameParent(c))
|
750
750
|
return !1;
|
751
751
|
const u = i.node(-1);
|
752
752
|
if (u.type !== a)
|
753
753
|
return !1;
|
754
|
-
const
|
754
|
+
const l = r.extensionManager.attributes;
|
755
755
|
if (i.parent.content.size === 0 && i.node(-1).childCount === i.indexAfter(-1)) {
|
756
756
|
if (i.depth === 2 || i.node(-3).type !== a || i.index(-2) !== i.node(-2).childCount - 1)
|
757
757
|
return !1;
|
@@ -760,7 +760,7 @@ const cn = ({ keepMarks: e = !0 } = {}) => ({ tr: t, state: n, dispatch: o, edit
|
|
760
760
|
const k = i.index(-1) ? 1 : i.index(-2) ? 2 : 3;
|
761
761
|
for (let v = i.depth - k; v >= i.depth - 3; v -= 1)
|
762
762
|
g = L.from(i.node(v).copy(g));
|
763
|
-
const E = i.indexAfter(-1) < i.node(-2).childCount ? 1 : i.indexAfter(-2) < i.node(-3).childCount ? 2 : 3, M = D(
|
763
|
+
const E = i.indexAfter(-1) < i.node(-2).childCount ? 1 : i.indexAfter(-2) < i.node(-3).childCount ? 2 : 3, M = D(l, i.node().type.name, i.node().attrs), B = ((s = a.contentMatch.defaultType) === null || s === void 0 ? void 0 : s.createAndFill(M)) || void 0;
|
764
764
|
g = g.append(L.from(a.createAndFill(null, B) || void 0));
|
765
765
|
const S = i.before(i.depth - (k - 1));
|
766
766
|
t.replace(S, i.after(-E), new be(g, 4 - k, 0));
|
@@ -773,7 +773,7 @@ const cn = ({ keepMarks: e = !0 } = {}) => ({ tr: t, state: n, dispatch: o, edit
|
|
773
773
|
}
|
774
774
|
return !0;
|
775
775
|
}
|
776
|
-
const f = c.pos === i.end() ? u.contentMatchAt(0).defaultType : null, p = D(
|
776
|
+
const f = c.pos === i.end() ? u.contentMatchAt(0).defaultType : null, p = D(l, u.type.name, u.attrs), m = D(l, i.node().type.name, i.node().attrs);
|
777
777
|
t.delete(i.pos, c.pos);
|
778
778
|
const h = f ? [
|
779
779
|
{ type: a, attrs: p },
|
@@ -797,7 +797,7 @@ const cn = ({ keepMarks: e = !0 } = {}) => ({ tr: t, state: n, dispatch: o, edit
|
|
797
797
|
if (o === void 0)
|
798
798
|
return !0;
|
799
799
|
const r = e.doc.nodeAt(o);
|
800
|
-
return n.node.type === (r == null ? void 0 : r.type) &&
|
800
|
+
return n.node.type === (r == null ? void 0 : r.type) && de(e.doc, n.pos) && e.join(n.pos), !0;
|
801
801
|
}, J = (e, t) => {
|
802
802
|
const n = Z((a) => a.type === t)(e.selection);
|
803
803
|
if (!n)
|
@@ -806,24 +806,24 @@ const cn = ({ keepMarks: e = !0 } = {}) => ({ tr: t, state: n, dispatch: o, edit
|
|
806
806
|
if (o === void 0)
|
807
807
|
return !0;
|
808
808
|
const r = e.doc.nodeAt(o);
|
809
|
-
return n.node.type === (r == null ? void 0 : r.type) &&
|
810
|
-
}, dn = (e, t, n, o = {}) => ({ editor: r, tr: s, state: a, dispatch: i, chain: c, commands:
|
811
|
-
const { extensions:
|
809
|
+
return n.node.type === (r == null ? void 0 : r.type) && de(e.doc, o) && e.join(o), !0;
|
810
|
+
}, dn = (e, t, n, o = {}) => ({ editor: r, tr: s, state: a, dispatch: i, chain: c, commands: d, can: u }) => {
|
811
|
+
const { extensions: l, splittableMarks: f } = r.extensionManager, p = y(e, a.schema), m = y(t, a.schema), { selection: h, storedMarks: g } = a, { $from: k, $to: E } = h, M = k.blockRange(E), B = g || h.$to.parentOffset && h.$from.marks();
|
812
812
|
if (!M)
|
813
813
|
return !1;
|
814
|
-
const S = Z((T) =>
|
814
|
+
const S = Z((T) => re(T.type.name, l))(h);
|
815
815
|
if (M.depth >= 1 && S && M.depth - S.depth <= 1) {
|
816
816
|
if (S.node.type === p)
|
817
|
-
return
|
818
|
-
if (
|
817
|
+
return d.liftListItem(m);
|
818
|
+
if (re(S.node.type.name, l) && p.validContent(S.node.content) && i)
|
819
819
|
return c().command(() => (s.setNodeMarkup(S.pos, p), !0)).command(() => _(s, p)).command(() => J(s, p)).run();
|
820
820
|
}
|
821
|
-
return !n || !B || !i ? c().command(() => u().wrapInList(p, o) ? !0 :
|
821
|
+
return !n || !B || !i ? c().command(() => u().wrapInList(p, o) ? !0 : d.clearNodes()).wrapInList(p, o).command(() => _(s, p)).command(() => J(s, p)).run() : c().command(() => {
|
822
822
|
const T = u().wrapInList(p, o), v = B.filter((K) => f.includes(K.type.name));
|
823
|
-
return s.ensureMarks(v), T ? !0 :
|
823
|
+
return s.ensureMarks(v), T ? !0 : d.clearNodes();
|
824
824
|
}).wrapInList(p, o).command(() => _(s, p)).command(() => J(s, p)).run();
|
825
825
|
}, un = (e, t = {}, n = {}) => ({ state: o, commands: r }) => {
|
826
|
-
const { extendEmptyMarkRange: s = !1 } = n, a =
|
826
|
+
const { extendEmptyMarkRange: s = !1 } = n, a = $(e, o.schema);
|
827
827
|
return Zt(o, a, t) ? r.unsetMark(a, { extendEmptyMarkRange: s }) : r.setMark(a, t);
|
828
828
|
}, fn = (e, t, n = {}) => ({ state: o, commands: r }) => {
|
829
829
|
const s = y(e, o.schema), a = y(t, o.schema);
|
@@ -858,30 +858,30 @@ const cn = ({ keepMarks: e = !0 } = {}) => ({ tr: t, state: n, dispatch: o, edit
|
|
858
858
|
}), !0;
|
859
859
|
}, gn = (e, t = {}) => ({ tr: n, state: o, dispatch: r }) => {
|
860
860
|
var s;
|
861
|
-
const { extendEmptyMarkRange: a = !1 } = t, { selection: i } = n, c =
|
861
|
+
const { extendEmptyMarkRange: a = !1 } = t, { selection: i } = n, c = $(e, o.schema), { $from: d, empty: u, ranges: l } = i;
|
862
862
|
if (!r)
|
863
863
|
return !0;
|
864
864
|
if (u && a) {
|
865
865
|
let { from: f, to: p } = i;
|
866
|
-
const m = (s =
|
866
|
+
const m = (s = d.marks().find((g) => g.type === c)) === null || s === void 0 ? void 0 : s.attrs, h = me(d, c, m);
|
867
867
|
h && (f = h.from, p = h.to), n.removeMark(f, p, c);
|
868
868
|
} else
|
869
|
-
|
869
|
+
l.forEach((f) => {
|
870
870
|
n.removeMark(f.$from.pos, f.$to.pos, c);
|
871
871
|
});
|
872
872
|
return n.removeStoredMark(c), !0;
|
873
873
|
}, kn = (e, t = {}) => ({ tr: n, state: o, dispatch: r }) => {
|
874
874
|
let s = null, a = null;
|
875
|
-
const i =
|
876
|
-
return i ? (i === "node" && (s = y(e, o.schema)), i === "mark" && (a =
|
877
|
-
const
|
878
|
-
o.doc.nodesBetween(
|
879
|
-
s && s ===
|
880
|
-
...
|
875
|
+
const i = ye(typeof e == "string" ? e : e.name, o.schema);
|
876
|
+
return i ? (i === "node" && (s = y(e, o.schema)), i === "mark" && (a = $(e, o.schema)), r && n.selection.ranges.forEach((c) => {
|
877
|
+
const d = c.$from.pos, u = c.$to.pos;
|
878
|
+
o.doc.nodesBetween(d, u, (l, f) => {
|
879
|
+
s && s === l.type && n.setNodeMarkup(f, void 0, {
|
880
|
+
...l.attrs,
|
881
881
|
...t
|
882
|
-
}), a &&
|
882
|
+
}), a && l.marks.length && l.marks.forEach((p) => {
|
883
883
|
if (a === p.type) {
|
884
|
-
const m = Math.max(f,
|
884
|
+
const m = Math.max(f, d), h = Math.min(f + l.nodeSize, u);
|
885
885
|
n.addMark(m, h, a.create({
|
886
886
|
...p.attrs,
|
887
887
|
...t
|
@@ -921,9 +921,9 @@ var xn = /* @__PURE__ */ Object.freeze({
|
|
921
921
|
joinDown: Et,
|
922
922
|
joinBackward: Bt,
|
923
923
|
joinForward: vt,
|
924
|
-
joinItemBackward:
|
925
|
-
joinItemForward:
|
926
|
-
joinTextblockBackward:
|
924
|
+
joinItemBackward: $t,
|
925
|
+
joinItemForward: It,
|
926
|
+
joinTextblockBackward: Pt,
|
927
927
|
joinTextblockForward: Nt,
|
928
928
|
keyboardShortcut: jt,
|
929
929
|
lift: Ft,
|
@@ -970,7 +970,7 @@ C.create({
|
|
970
970
|
name: "editable",
|
971
971
|
addProseMirrorPlugins() {
|
972
972
|
return [
|
973
|
-
new
|
973
|
+
new P({
|
974
974
|
key: new N("editable"),
|
975
975
|
props: {
|
976
976
|
editable: () => this.editor.options.editable
|
@@ -984,7 +984,7 @@ C.create({
|
|
984
984
|
addProseMirrorPlugins() {
|
985
985
|
const { editor: e } = this;
|
986
986
|
return [
|
987
|
-
new
|
987
|
+
new P({
|
988
988
|
key: new N("focusEvents"),
|
989
989
|
props: {
|
990
990
|
handleDOMEvents: {
|
@@ -1011,7 +1011,7 @@ C.create({
|
|
1011
1011
|
() => a.undoInputRule(),
|
1012
1012
|
// maybe convert first text block node to default node
|
1013
1013
|
() => a.command(({ tr: i }) => {
|
1014
|
-
const { selection: c, doc:
|
1014
|
+
const { selection: c, doc: d } = i, { empty: u, $anchor: l } = c, { pos: f, parent: p } = l, m = l.parent.isTextblock && f > 0 ? i.doc.resolve(f - 1) : l, h = m.parent.type.spec.isolating, g = l.pos - l.parentOffset, k = h && m.parent.childCount === 1 ? g === l.pos : O.atStart(d).from === f;
|
1015
1015
|
return !u || !k || !p.type.isTextblock || p.textContent.length ? !1 : a.clearNodes();
|
1016
1016
|
}),
|
1017
1017
|
() => a.deleteSelection(),
|
@@ -1049,7 +1049,7 @@ C.create({
|
|
1049
1049
|
"Ctrl-a": () => this.editor.commands.selectTextblockStart(),
|
1050
1050
|
"Ctrl-e": () => this.editor.commands.selectTextblockEnd()
|
1051
1051
|
};
|
1052
|
-
return X() ||
|
1052
|
+
return X() || ke() ? s : r;
|
1053
1053
|
},
|
1054
1054
|
addProseMirrorPlugins() {
|
1055
1055
|
return [
|
@@ -1058,7 +1058,7 @@ C.create({
|
|
1058
1058
|
// to a paragraph if necessary.
|
1059
1059
|
// This is an alternative to ProseMirror's `AllSelection`, which doesn’t work well
|
1060
1060
|
// with many other commands.
|
1061
|
-
new
|
1061
|
+
new P({
|
1062
1062
|
key: new N("clearDocument"),
|
1063
1063
|
appendTransaction: (e, t, n) => {
|
1064
1064
|
if (!(e.some((m) => m.docChanged) && !t.doc.eq(n.doc)))
|
@@ -1066,15 +1066,15 @@ C.create({
|
|
1066
1066
|
const { empty: r, from: s, to: a } = t.selection, i = O.atStart(t.doc).from, c = O.atEnd(t.doc).to;
|
1067
1067
|
if (r || !(s === i && a === c) || !(n.doc.textBetween(0, n.doc.content.size, " ", " ").length === 0))
|
1068
1068
|
return;
|
1069
|
-
const
|
1069
|
+
const l = n.tr, f = pe({
|
1070
1070
|
state: n,
|
1071
|
-
transaction:
|
1071
|
+
transaction: l
|
1072
1072
|
}), { commands: p } = new qe({
|
1073
1073
|
editor: this.editor,
|
1074
1074
|
state: f
|
1075
1075
|
});
|
1076
|
-
if (p.clearNodes(), !!
|
1077
|
-
return
|
1076
|
+
if (p.clearNodes(), !!l.steps.length)
|
1077
|
+
return l;
|
1078
1078
|
}
|
1079
1079
|
})
|
1080
1080
|
];
|
@@ -1084,7 +1084,7 @@ C.create({
|
|
1084
1084
|
name: "tabindex",
|
1085
1085
|
addProseMirrorPlugins() {
|
1086
1086
|
return [
|
1087
|
-
new
|
1087
|
+
new P({
|
1088
1088
|
key: new N("tabindex"),
|
1089
1089
|
props: {
|
1090
1090
|
attributes: this.editor.isEditable ? { tabindex: "0" } : {}
|
@@ -1093,7 +1093,7 @@ C.create({
|
|
1093
1093
|
];
|
1094
1094
|
}
|
1095
1095
|
});
|
1096
|
-
function
|
1096
|
+
function ie(e) {
|
1097
1097
|
return new et({
|
1098
1098
|
find: e.find,
|
1099
1099
|
handler: ({ state: t, range: n, match: o }) => {
|
@@ -1228,14 +1228,14 @@ const Sn = /^```([a-z]+)?[\s\n]$/, bn = /^~~~([a-z]+)?[\s\n]$/, Mn = H.create({
|
|
1228
1228
|
},
|
1229
1229
|
addInputRules() {
|
1230
1230
|
return [
|
1231
|
-
|
1231
|
+
ie({
|
1232
1232
|
find: Sn,
|
1233
1233
|
type: this.type,
|
1234
1234
|
getAttributes: (e) => ({
|
1235
1235
|
language: e[1]
|
1236
1236
|
})
|
1237
1237
|
}),
|
1238
|
-
|
1238
|
+
ie({
|
1239
1239
|
find: bn,
|
1240
1240
|
type: this.type,
|
1241
1241
|
getAttributes: (e) => ({
|
@@ -1248,7 +1248,7 @@ const Sn = /^```([a-z]+)?[\s\n]$/, bn = /^~~~([a-z]+)?[\s\n]$/, Mn = H.create({
|
|
1248
1248
|
return [
|
1249
1249
|
// this plugin creates a code block for pasted content from VS Code
|
1250
1250
|
// we can also detect the copied code language
|
1251
|
-
new
|
1251
|
+
new P({
|
1252
1252
|
key: new N("codeBlockVSCodeHandler"),
|
1253
1253
|
props: {
|
1254
1254
|
handlePaste: (e, t) => {
|
@@ -1274,9 +1274,9 @@ function An() {
|
|
1274
1274
|
function Tn(e) {
|
1275
1275
|
if (!A && !j) {
|
1276
1276
|
const t = e.themes.filter(
|
1277
|
-
(o) => !!o && o in de
|
1278
|
-
), n = e.languages.filter(
|
1279
1277
|
(o) => !!o && o in ue
|
1278
|
+
), n = e.languages.filter(
|
1279
|
+
(o) => !!o && o in fe
|
1280
1280
|
);
|
1281
1281
|
return j = Ge({ themes: t, langs: n }).then((o) => {
|
1282
1282
|
A = o;
|
@@ -1285,11 +1285,11 @@ function Tn(e) {
|
|
1285
1285
|
if (j)
|
1286
1286
|
return j;
|
1287
1287
|
}
|
1288
|
-
async function ye(e) {
|
1289
|
-
return A && !A.getLoadedThemes().includes(e) && !G.has(e) && e in de ? (G.add(e), await A.loadTheme(e), G.delete(e), !0) : !1;
|
1290
|
-
}
|
1291
1288
|
async function we(e) {
|
1292
|
-
return A && !A.
|
1289
|
+
return A && !A.getLoadedThemes().includes(e) && !G.has(e) && e in ue ? (G.add(e), await A.loadTheme(e), G.delete(e), !0) : !1;
|
1290
|
+
}
|
1291
|
+
async function xe(e) {
|
1292
|
+
return A && !A.getLoadedLanguages().includes(e) && !U.has(e) && e in fe ? (U.add(e), await A.loadLanguage(e), U.delete(e), !0) : !1;
|
1293
1293
|
}
|
1294
1294
|
async function Cn({
|
1295
1295
|
doc: e,
|
@@ -1305,11 +1305,11 @@ async function Cn({
|
|
1305
1305
|
o
|
1306
1306
|
];
|
1307
1307
|
A ? await Promise.all([
|
1308
|
-
...s.flatMap((i) =>
|
1309
|
-
...a.flatMap((i) => !!i &&
|
1308
|
+
...s.flatMap((i) => we(i)),
|
1309
|
+
...a.flatMap((i) => !!i && xe(i))
|
1310
1310
|
]) : await Tn({ languages: a, themes: s });
|
1311
1311
|
}
|
1312
|
-
function
|
1312
|
+
function ae({
|
1313
1313
|
doc: e,
|
1314
1314
|
name: t,
|
1315
1315
|
defaultTheme: n,
|
@@ -1317,32 +1317,38 @@ function ie({
|
|
1317
1317
|
}) {
|
1318
1318
|
const r = [];
|
1319
1319
|
return F(e, (a) => a.type.name === t).forEach((a) => {
|
1320
|
-
let i = a.pos + 1, c = a.node.attrs.language || o,
|
1320
|
+
let i = a.pos + 1, c = a.node.attrs.language || o, d = a.node.attrs.theme || n;
|
1321
1321
|
const u = An();
|
1322
1322
|
if (!u)
|
1323
1323
|
return;
|
1324
1324
|
u.getLoadedLanguages().includes(c) || (c = "plaintext");
|
1325
|
-
const
|
1325
|
+
const l = u.getLoadedThemes().includes(d) ? d : u.getLoadedThemes()[0], f = u.getTheme(l);
|
1326
|
+
r.push(
|
1327
|
+
ee.node(a.pos, a.pos + a.node.nodeSize, {
|
1328
|
+
style: `background-color: ${f.bg}`
|
1329
|
+
})
|
1330
|
+
);
|
1331
|
+
const p = u.codeToTokensBase(a.node.textContent, {
|
1326
1332
|
lang: c,
|
1327
|
-
theme:
|
1333
|
+
theme: l
|
1328
1334
|
});
|
1329
|
-
for (const
|
1330
|
-
for (const
|
1331
|
-
const
|
1332
|
-
style: `color: ${
|
1335
|
+
for (const m of p) {
|
1336
|
+
for (const h of m) {
|
1337
|
+
const g = i + h.content.length, k = ee.inline(i, g, {
|
1338
|
+
style: `color: ${h.color}`
|
1333
1339
|
});
|
1334
|
-
r.push(
|
1340
|
+
r.push(k), i = g;
|
1335
1341
|
}
|
1336
1342
|
i += 1;
|
1337
1343
|
}
|
1338
|
-
}),
|
1344
|
+
}), Se.create(e, r);
|
1339
1345
|
}
|
1340
1346
|
function En({
|
1341
1347
|
name: e,
|
1342
1348
|
defaultLanguage: t,
|
1343
1349
|
defaultTheme: n
|
1344
1350
|
}) {
|
1345
|
-
const o = new
|
1351
|
+
const o = new P({
|
1346
1352
|
key: new N("shiki"),
|
1347
1353
|
view(r) {
|
1348
1354
|
class s {
|
@@ -1370,8 +1376,8 @@ function En({
|
|
1370
1376
|
);
|
1371
1377
|
if ((await Promise.all(
|
1372
1378
|
i.flatMap((u) => [
|
1373
|
-
|
1374
|
-
|
1379
|
+
we(u.node.attrs.theme),
|
1380
|
+
xe(u.node.attrs.language)
|
1375
1381
|
])
|
1376
1382
|
)).includes(!0)) {
|
1377
1383
|
const u = r.state.tr.setMeta("shikiPluginForceDecoration", !0);
|
@@ -1382,23 +1388,23 @@ function En({
|
|
1382
1388
|
return new s();
|
1383
1389
|
},
|
1384
1390
|
state: {
|
1385
|
-
init: (r, { doc: s }) =>
|
1391
|
+
init: (r, { doc: s }) => ae({
|
1386
1392
|
doc: s,
|
1387
1393
|
name: e,
|
1388
1394
|
defaultLanguage: t,
|
1389
1395
|
defaultTheme: n
|
1390
1396
|
}),
|
1391
1397
|
apply: (r, s, a, i) => {
|
1392
|
-
const c = a.selection.$head.parent.type.name,
|
1398
|
+
const c = a.selection.$head.parent.type.name, d = i.selection.$head.parent.type.name, u = F(
|
1393
1399
|
a.doc,
|
1394
1400
|
(p) => p.type.name === e
|
1395
|
-
),
|
1401
|
+
), l = F(
|
1396
1402
|
i.doc,
|
1397
1403
|
(p) => p.type.name === e
|
1398
1404
|
), f = r.docChanged && // Apply decorations if:
|
1399
1405
|
// selection includes named node,
|
1400
|
-
([c,
|
1401
|
-
|
1406
|
+
([c, d].includes(e) || // OR transaction adds/removes named node,
|
1407
|
+
l.length !== u.length || // OR transaction has changes that completely encapsulte a node
|
1402
1408
|
// (for example, a transaction that affects the entire document).
|
1403
1409
|
// Such transactions can happen during collab syncing via y-prosemirror, for example.
|
1404
1410
|
r.steps.some((p) => (
|
@@ -1410,7 +1416,7 @@ function En({
|
|
1410
1416
|
m.pos + m.node.nodeSize <= p.to
|
1411
1417
|
))
|
1412
1418
|
)));
|
1413
|
-
return r.getMeta("shikiPluginForceDecoration") || f ?
|
1419
|
+
return r.getMeta("shikiPluginForceDecoration") || f ? ae({
|
1414
1420
|
doc: r.doc,
|
1415
1421
|
name: e,
|
1416
1422
|
defaultLanguage: t,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "tiptap-extension-code-block-shiki",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.6.0",
|
4
4
|
"description": "Use Shiki syntax highlighting for codeblocks in TipTap.",
|
5
5
|
"repository": "timomeh/tiptap-extension-code-block-shiki",
|
6
6
|
"author": {
|
@@ -28,9 +28,9 @@
|
|
28
28
|
"vitest": "^1.6.0"
|
29
29
|
},
|
30
30
|
"peerDependencies": {
|
31
|
-
"@tiptap/core": "^2.3.0",
|
32
|
-
"@tiptap/extension-code-block": "^2.3.0",
|
33
|
-
"@tiptap/pm": "^2.3.0",
|
31
|
+
"@tiptap/core": "^2.3.0 || ^3.0.0",
|
32
|
+
"@tiptap/extension-code-block": "^2.3.0 || ^3.0.0",
|
33
|
+
"@tiptap/pm": "^2.3.0 || ^3.0.0",
|
34
34
|
"shiki": "^3.0.0"
|
35
35
|
},
|
36
36
|
"keywords": [
|