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