tiptap-extension-code-block-shiki 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +60 -3
- package/dist/tiptap-extension-code-block-shiki.d.ts +4 -0
- package/dist/tiptap-extension-code-block-shiki.js +532 -477
- package/package.json +19 -12
@@ -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 C, NodeSelection as de } from "@tiptap/pm/state";
|
2
|
+
import { DecorationSet as be, Decoration as _ } from "@tiptap/pm/view";
|
3
3
|
import "@tiptap/pm/keymap";
|
4
|
-
import { Fragment as L, Slice as
|
5
|
-
import { liftTarget as Ae, joinPoint as
|
6
|
-
import { createParagraphNear as
|
7
|
-
import { liftListItem as
|
8
|
-
import { bundledThemes as
|
9
|
-
function
|
4
|
+
import { Fragment as L, Slice as Me, DOMParser as Te } from "@tiptap/pm/model";
|
5
|
+
import { liftTarget as Ae, joinPoint as ue, canSplit as R, ReplaceStep as Ce, ReplaceAroundStep as Ee, canJoin as fe } from "@tiptap/pm/transform";
|
6
|
+
import { createParagraphNear as Be, deleteSelection as ve, exitCode as $e, joinUp as Ie, joinDown as Pe, joinBackward as Ne, joinForward as Oe, joinTextblockBackward as je, joinTextblockForward as Fe, lift as Le, liftEmptyBlock as Re, newlineInCode as ze, selectNodeBackward as De, selectNodeForward as We, selectParentNode as He, selectTextblockEnd as Ke, selectTextblockStart as Ve, setBlockType as ne, wrapIn as _e } from "@tiptap/pm/commands";
|
7
|
+
import { liftListItem as Je, sinkListItem as Ue, wrapInList as Ge } from "@tiptap/pm/schema-list";
|
8
|
+
import { bundledThemes as pe, bundledLanguages as me, createHighlighter as qe } from "shiki";
|
9
|
+
function he(e) {
|
10
10
|
const { state: t, transaction: n } = e;
|
11
11
|
let { selection: o } = n, { doc: r } = n, { storedMarks: s } = n;
|
12
12
|
return {
|
@@ -31,7 +31,7 @@ function fe(e) {
|
|
31
31
|
}
|
32
32
|
};
|
33
33
|
}
|
34
|
-
class
|
34
|
+
class Qe {
|
35
35
|
constructor(t) {
|
36
36
|
this.editor = t.editor, this.rawCommands = this.editor.extensionManager.commands, this.customState = t.state;
|
37
37
|
}
|
@@ -43,8 +43,8 @@ class qe {
|
|
43
43
|
}
|
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
|
-
return Object.fromEntries(Object.entries(t).map(([i, c]) => [i, (...
|
47
|
-
const d = c(...
|
46
|
+
return Object.fromEntries(Object.entries(t).map(([i, c]) => [i, (...p) => {
|
47
|
+
const d = c(...p)(a);
|
48
48
|
return !s.getMeta("preventDispatch") && !this.hasCustomState && r.dispatch(s), d;
|
49
49
|
}]));
|
50
50
|
}
|
@@ -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, l = t || s.tr,
|
59
|
-
...Object.fromEntries(Object.entries(o).map(([
|
60
|
-
const g = this.buildProps(l, n), k =
|
58
|
+
const { rawCommands: o, editor: r, state: s } = this, { view: a } = r, i = [], c = !!t, l = t || s.tr, p = () => (!c && n && !l.getMeta("preventDispatch") && !this.hasCustomState && a.dispatch(l), i.every((u) => u === !0)), d = {
|
59
|
+
...Object.fromEntries(Object.entries(o).map(([u, f]) => [u, (...h) => {
|
60
|
+
const g = this.buildProps(l, n), k = f(...h)(g);
|
61
61
|
return i.push(k), d;
|
62
62
|
}])),
|
63
|
-
run:
|
63
|
+
run: p
|
64
64
|
};
|
65
65
|
return d;
|
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, l]) => [c, (...
|
70
|
+
...Object.fromEntries(Object.entries(n).map(([c, l]) => [c, (...p) => l(...p)({ ...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: he({
|
80
80
|
state: s,
|
81
81
|
transaction: t
|
82
82
|
}),
|
@@ -85,19 +85,19 @@ 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, l]) => [c, (...
|
88
|
+
return Object.fromEntries(Object.entries(o).map(([c, l]) => [c, (...p) => l(...p)(i)]));
|
89
89
|
}
|
90
90
|
};
|
91
91
|
return i;
|
92
92
|
}
|
93
93
|
}
|
94
|
-
function
|
95
|
-
return e.config[t] === void 0 && e.parent ?
|
94
|
+
function b(e, t, n) {
|
95
|
+
return e.config[t] === void 0 && e.parent ? b(e.parent, t, n) : typeof e.config[t] == "function" ? e.config[t].bind({
|
96
96
|
...n,
|
97
|
-
parent: e.parent ?
|
97
|
+
parent: e.parent ? b(e.parent, t, n) : null
|
98
98
|
}) : e.config[t];
|
99
99
|
}
|
100
|
-
function
|
100
|
+
function Xe(e) {
|
101
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
103
|
baseExtensions: t,
|
@@ -105,7 +105,7 @@ function Qe(e) {
|
|
105
105
|
markExtensions: o
|
106
106
|
};
|
107
107
|
}
|
108
|
-
function
|
108
|
+
function x(e, t) {
|
109
109
|
if (typeof e == "string") {
|
110
110
|
if (!t.nodes[e])
|
111
111
|
throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);
|
@@ -113,7 +113,7 @@ function y(e, t) {
|
|
113
113
|
}
|
114
114
|
return e;
|
115
115
|
}
|
116
|
-
function
|
116
|
+
function Ye(...e) {
|
117
117
|
return e.filter((t) => !!t).reduce((t, n) => {
|
118
118
|
const o = { ...t };
|
119
119
|
return Object.entries(n).forEach(([r, s]) => {
|
@@ -122,40 +122,40 @@ 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(" ") : [], l = i.filter((
|
125
|
+
const i = s ? s.split(" ") : [], c = o[r] ? o[r].split(" ") : [], l = i.filter((p) => !c.includes(p));
|
126
126
|
o[r] = [...c, ...l].join(" ");
|
127
127
|
} else
|
128
128
|
r === "style" ? o[r] = [o[r], s].join("; ") : o[r] = s;
|
129
129
|
}), o;
|
130
130
|
}, {});
|
131
131
|
}
|
132
|
-
function
|
132
|
+
function Ze(e) {
|
133
133
|
return typeof e == "function";
|
134
134
|
}
|
135
|
-
function
|
136
|
-
return
|
135
|
+
function M(e, t = void 0, ...n) {
|
136
|
+
return Ze(e) ? t ? e.bind(t)(...n) : e(...n) : e;
|
137
137
|
}
|
138
|
-
function
|
138
|
+
function et(e) {
|
139
139
|
return Object.prototype.toString.call(e) === "[object RegExp]";
|
140
140
|
}
|
141
|
-
class
|
141
|
+
class tt {
|
142
142
|
constructor(t) {
|
143
143
|
this.find = t.find, this.handler = t.handler;
|
144
144
|
}
|
145
145
|
}
|
146
|
-
function
|
146
|
+
function nt(e) {
|
147
147
|
return Object.prototype.toString.call(e).slice(8, -1);
|
148
148
|
}
|
149
|
-
function
|
150
|
-
return
|
149
|
+
function J(e) {
|
150
|
+
return nt(e) !== "Object" ? !1 : e.constructor === Object && Object.getPrototypeOf(e) === Object.prototype;
|
151
151
|
}
|
152
|
-
function
|
152
|
+
function Y(e, t) {
|
153
153
|
const n = { ...e };
|
154
|
-
return
|
155
|
-
|
154
|
+
return J(e) && J(t) && Object.keys(t).forEach((o) => {
|
155
|
+
J(t[o]) ? o in e ? n[o] = Y(e[o], t[o]) : Object.assign(n, { [o]: t[o] }) : Object.assign(n, { [o]: t[o] });
|
156
156
|
}), n;
|
157
157
|
}
|
158
|
-
class
|
158
|
+
class B {
|
159
159
|
constructor(t = {}) {
|
160
160
|
this.type = "extension", this.name = "extension", this.parent = null, this.child = null, this.config = {
|
161
161
|
name: this.name,
|
@@ -163,56 +163,56 @@ class C {
|
|
163
163
|
}, this.config = {
|
164
164
|
...this.config,
|
165
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 =
|
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 = M(b(this, "addOptions", {
|
167
167
|
name: this.name
|
168
|
-
}))), this.storage =
|
168
|
+
}))), this.storage = M(b(this, "addStorage", {
|
169
169
|
name: this.name,
|
170
170
|
options: this.options
|
171
171
|
})) || {};
|
172
172
|
}
|
173
173
|
static create(t = {}) {
|
174
|
-
return new
|
174
|
+
return new B(t);
|
175
175
|
}
|
176
176
|
configure(t = {}) {
|
177
177
|
const n = this.extend();
|
178
|
-
return n.options =
|
178
|
+
return n.options = Y(this.options, t), n.storage = M(b(n, "addStorage", {
|
179
179
|
name: n.name,
|
180
180
|
options: n.options
|
181
181
|
})), n;
|
182
182
|
}
|
183
183
|
extend(t = {}) {
|
184
|
-
const n = new
|
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 =
|
184
|
+
const n = new B({ ...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 = M(b(n, "addOptions", {
|
186
186
|
name: n.name
|
187
|
-
})), n.storage =
|
187
|
+
})), n.storage = M(b(n, "addStorage", {
|
188
188
|
name: n.name,
|
189
189
|
options: n.options
|
190
190
|
})), n;
|
191
191
|
}
|
192
192
|
}
|
193
|
-
function
|
193
|
+
function ot(e, t, n) {
|
194
194
|
const { from: o, to: r } = t, { blockSeparator: s = `
|
195
195
|
|
196
196
|
`, textSerializers: a = {} } = n || {};
|
197
197
|
let i = "", c = !0;
|
198
|
-
return e.nodesBetween(o, r, (l,
|
199
|
-
var
|
198
|
+
return e.nodesBetween(o, r, (l, p, d, u) => {
|
199
|
+
var f;
|
200
200
|
const m = a == null ? void 0 : a[l.type.name];
|
201
201
|
if (m)
|
202
202
|
return l.isBlock && !c && (i += s, c = !0), d && (i += m({
|
203
203
|
node: l,
|
204
|
-
pos:
|
204
|
+
pos: p,
|
205
205
|
parent: d,
|
206
|
-
index:
|
206
|
+
index: u,
|
207
207
|
range: t
|
208
208
|
})), !1;
|
209
|
-
l.isText ? (i += (
|
209
|
+
l.isText ? (i += (f = l == null ? void 0 : l.text) === null || f === void 0 ? void 0 : f.slice(Math.max(o, p) - p, r - p), c = !1) : l.isBlock && !c && (i += s, c = !0);
|
210
210
|
}), i;
|
211
211
|
}
|
212
|
-
function
|
212
|
+
function rt(e) {
|
213
213
|
return Object.fromEntries(Object.entries(e.nodes).filter(([, t]) => t.spec.toText).map(([t, n]) => [t, n.spec.toText]));
|
214
214
|
}
|
215
|
-
|
215
|
+
B.create({
|
216
216
|
name: "clipboardTextSerializer",
|
217
217
|
addOptions() {
|
218
218
|
return {
|
@@ -221,12 +221,12 @@ 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: () => {
|
228
|
-
const { editor: e } = this, { state: t, schema: n } = e, { doc: o, selection: r } = t, { ranges: s } = r, a = Math.min(...s.map((
|
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((p) => p.$from.pos)), i = Math.max(...s.map((p) => p.$to.pos)), c = rt(n);
|
229
|
+
return ot(o, { from: a, to: i }, {
|
230
230
|
...this.options.blockSeparator !== void 0 ? { blockSeparator: this.options.blockSeparator } : {},
|
231
231
|
textSerializers: c
|
232
232
|
});
|
@@ -236,32 +236,32 @@ C.create({
|
|
236
236
|
];
|
237
237
|
}
|
238
238
|
});
|
239
|
-
const
|
239
|
+
const st = () => ({ editor: e, view: t }) => (requestAnimationFrame(() => {
|
240
240
|
var n;
|
241
241
|
e.isDestroyed || (t.dom.blur(), (n = window == null ? void 0 : window.getSelection()) === null || n === void 0 || n.removeAllRanges());
|
242
|
-
}), !0),
|
242
|
+
}), !0), it = (e = !1) => ({ commands: t }) => t.setContent("", e), at = () => ({ state: e, tr: t, dispatch: n }) => {
|
243
243
|
const { selection: o } = t, { ranges: r } = o;
|
244
244
|
return n && r.forEach(({ $from: s, $to: a }) => {
|
245
245
|
e.doc.nodesBetween(s.pos, a.pos, (i, c) => {
|
246
246
|
if (i.type.isText)
|
247
247
|
return;
|
248
|
-
const { doc: l, mapping:
|
249
|
-
if (!
|
248
|
+
const { doc: l, mapping: p } = t, d = l.resolve(p.map(c)), u = l.resolve(p.map(c + i.nodeSize)), f = d.blockRange(u);
|
249
|
+
if (!f)
|
250
250
|
return;
|
251
|
-
const m = Ae(
|
251
|
+
const m = Ae(f);
|
252
252
|
if (i.type.isTextblock) {
|
253
253
|
const { defaultType: h } = d.parent.contentMatchAt(d.index());
|
254
|
-
t.setNodeMarkup(
|
254
|
+
t.setNodeMarkup(f.start, h);
|
255
255
|
}
|
256
|
-
(m || m === 0) && t.lift(
|
256
|
+
(m || m === 0) && t.lift(f, m);
|
257
257
|
});
|
258
258
|
}), !0;
|
259
|
-
},
|
259
|
+
}, ct = (e) => (t) => e(t), lt = () => ({ state: e, dispatch: t }) => Be(e, t), dt = (e, t) => ({ editor: n, tr: o }) => {
|
260
260
|
const { state: r } = n, s = r.doc.slice(e.from, e.to);
|
261
261
|
o.deleteRange(e.from, e.to);
|
262
262
|
const a = o.mapping.map(t);
|
263
|
-
return o.insert(a, s.content), o.setSelection(new
|
264
|
-
},
|
263
|
+
return o.insert(a, s.content), o.setSelection(new C(o.doc.resolve(a - 1))), !0;
|
264
|
+
}, ut = () => ({ tr: e, dispatch: t }) => {
|
265
265
|
const { selection: n } = e, o = n.$anchor.node();
|
266
266
|
if (o.content.size > 0)
|
267
267
|
return !1;
|
@@ -275,8 +275,8 @@ const rt = () => ({ editor: e, view: t }) => (requestAnimationFrame(() => {
|
|
275
275
|
return !0;
|
276
276
|
}
|
277
277
|
return !1;
|
278
|
-
},
|
279
|
-
const r =
|
278
|
+
}, ft = (e) => ({ tr: t, state: n, dispatch: o }) => {
|
279
|
+
const r = x(e, n.schema), s = t.selection.$anchor;
|
280
280
|
for (let a = s.depth; a > 0; a -= 1)
|
281
281
|
if (s.node(a).type === r) {
|
282
282
|
if (o) {
|
@@ -286,40 +286,40 @@ const rt = () => ({ editor: e, view: t }) => (requestAnimationFrame(() => {
|
|
286
286
|
return !0;
|
287
287
|
}
|
288
288
|
return !1;
|
289
|
-
},
|
289
|
+
}, pt = (e) => ({ tr: t, dispatch: n }) => {
|
290
290
|
const { from: o, to: r } = e;
|
291
291
|
return n && t.delete(o, r), !0;
|
292
|
-
},
|
293
|
-
function
|
292
|
+
}, mt = () => ({ state: e, dispatch: t }) => ve(e, t), ht = () => ({ commands: e }) => e.keyboardShortcut("Enter"), gt = () => ({ state: e, dispatch: t }) => $e(e, t);
|
293
|
+
function W(e, t, n = { strict: !0 }) {
|
294
294
|
const o = Object.keys(t);
|
295
|
-
return o.length ? o.every((r) => n.strict ? t[r] === e[r] :
|
295
|
+
return o.length ? o.every((r) => n.strict ? t[r] === e[r] : et(t[r]) ? t[r].test(e[r]) : t[r] === e[r]) : !0;
|
296
296
|
}
|
297
|
-
function
|
298
|
-
return e.find((o) => o.type === t &&
|
297
|
+
function X(e, t, n = {}) {
|
298
|
+
return e.find((o) => o.type === t && W(o.attrs, n));
|
299
299
|
}
|
300
|
-
function
|
301
|
-
return !!
|
300
|
+
function kt(e, t, n = {}) {
|
301
|
+
return !!X(e, t, n);
|
302
302
|
}
|
303
|
-
function
|
303
|
+
function ge(e, t, n = {}) {
|
304
304
|
if (!e || !t)
|
305
305
|
return;
|
306
306
|
let o = e.parent.childAfter(e.parentOffset);
|
307
307
|
if (e.parentOffset === o.offset && o.offset !== 0 && (o = e.parent.childBefore(e.parentOffset)), !o.node)
|
308
308
|
return;
|
309
|
-
const r =
|
309
|
+
const r = X([...o.node.marks], t, n);
|
310
310
|
if (!r)
|
311
311
|
return;
|
312
312
|
let s = o.index, a = e.start() + o.offset, i = s + 1, c = a + o.node.nodeSize;
|
313
|
-
for (
|
313
|
+
for (X([...o.node.marks], t, n); s > 0 && r.isInSet(e.parent.child(s - 1).marks); )
|
314
314
|
s -= 1, a -= e.parent.child(s).nodeSize;
|
315
|
-
for (; i < e.parent.childCount &&
|
315
|
+
for (; i < e.parent.childCount && kt([...e.parent.child(i).marks], t, n); )
|
316
316
|
c += e.parent.child(i).nodeSize, i += 1;
|
317
317
|
return {
|
318
318
|
from: a,
|
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?`);
|
@@ -327,30 +327,30 @@ function I(e, t) {
|
|
327
327
|
}
|
328
328
|
return e;
|
329
329
|
}
|
330
|
-
const
|
331
|
-
const s =
|
330
|
+
const yt = (e, t = {}) => ({ tr: n, state: o, dispatch: r }) => {
|
331
|
+
const s = $(e, o.schema), { doc: a, selection: i } = n, { $from: c, from: l, to: p } = i;
|
332
332
|
if (r) {
|
333
|
-
const d =
|
334
|
-
if (d && d.from <= l && d.to >=
|
335
|
-
const
|
336
|
-
n.setSelection(
|
333
|
+
const d = ge(c, s, t);
|
334
|
+
if (d && d.from <= l && d.to >= p) {
|
335
|
+
const u = C.create(a, d.from, d.to);
|
336
|
+
n.setSelection(u);
|
337
337
|
}
|
338
338
|
}
|
339
339
|
return !0;
|
340
|
-
},
|
340
|
+
}, wt = (e) => (t) => {
|
341
341
|
const n = typeof e == "function" ? e(t) : e;
|
342
342
|
for (let o = 0; o < n.length; o += 1)
|
343
343
|
if (n[o](t))
|
344
344
|
return !0;
|
345
345
|
return !1;
|
346
346
|
};
|
347
|
-
function
|
348
|
-
return e instanceof
|
347
|
+
function ke(e) {
|
348
|
+
return e instanceof C;
|
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
|
-
function
|
353
|
+
function xt(e, t = null) {
|
354
354
|
if (!t)
|
355
355
|
return null;
|
356
356
|
const n = O.atStart(e), o = O.atEnd(e);
|
@@ -359,9 +359,9 @@ 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" ?
|
362
|
+
return t === "all" ? C.create(e, I(0, r, s), I(e.content.size, r, s)) : C.create(e, I(t, r, s), I(t, r, s));
|
363
363
|
}
|
364
|
-
function
|
364
|
+
function Z() {
|
365
365
|
return [
|
366
366
|
"iPad Simulator",
|
367
367
|
"iPhone Simulator",
|
@@ -371,35 +371,35 @@ function X() {
|
|
371
371
|
"iPod"
|
372
372
|
].includes(navigator.platform) || navigator.userAgent.includes("Mac") && "ontouchend" in document;
|
373
373
|
}
|
374
|
-
const
|
374
|
+
const St = (e = null, t = {}) => ({ editor: n, view: o, tr: r, dispatch: s }) => {
|
375
375
|
t = {
|
376
376
|
scrollIntoView: !0,
|
377
377
|
...t
|
378
378
|
};
|
379
379
|
const a = () => {
|
380
|
-
|
380
|
+
Z() && o.dom.focus(), requestAnimationFrame(() => {
|
381
381
|
n.isDestroyed || (o.focus(), t != null && t.scrollIntoView && n.commands.scrollIntoView());
|
382
382
|
});
|
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 && !ke(n.state.selection))
|
387
387
|
return a(), !0;
|
388
|
-
const i =
|
388
|
+
const i = xt(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
|
-
},
|
390
|
+
}, bt = (e, t) => (n) => e.every((o, r) => t(o, { ...n, index: r })), Mt = (e, t) => ({ tr: n, commands: o }) => o.insertContentAt({ from: n.selection.from, to: n.selection.to }, e, t), ye = (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 && ye(o);
|
395
395
|
}
|
396
396
|
return e;
|
397
397
|
};
|
398
|
-
function
|
398
|
+
function oe(e) {
|
399
399
|
const t = `<body>${e}</body>`, n = new window.DOMParser().parseFromString(t, "text/html").body;
|
400
|
-
return
|
400
|
+
return ye(n);
|
401
401
|
}
|
402
|
-
function
|
402
|
+
function H(e, t, n) {
|
403
403
|
if (n = {
|
404
404
|
slice: !0,
|
405
405
|
parseOptions: {},
|
@@ -408,28 +408,28 @@ function W(e, t, n) {
|
|
408
408
|
try {
|
409
409
|
return Array.isArray(e) && e.length > 0 ? L.fromArray(e.map((o) => t.nodeFromJSON(o))) : t.nodeFromJSON(e);
|
410
410
|
} catch (o) {
|
411
|
-
return console.warn("[tiptap warn]: Invalid content.", "Passed value:", e, "Error:", o),
|
411
|
+
return console.warn("[tiptap warn]: Invalid content.", "Passed value:", e, "Error:", o), H("", t, n);
|
412
412
|
}
|
413
413
|
if (typeof e == "string") {
|
414
|
-
const o =
|
415
|
-
return n.slice ? o.parseSlice(
|
414
|
+
const o = Te.fromSchema(t);
|
415
|
+
return n.slice ? o.parseSlice(oe(e), n.parseOptions).content : o.parse(oe(e), n.parseOptions);
|
416
416
|
}
|
417
|
-
return
|
417
|
+
return H("", t, n);
|
418
418
|
}
|
419
|
-
function
|
419
|
+
function Tt(e, t, n) {
|
420
420
|
const o = e.steps.length - 1;
|
421
421
|
if (o < t)
|
422
422
|
return;
|
423
423
|
const r = e.steps[o];
|
424
|
-
if (!(r instanceof
|
424
|
+
if (!(r instanceof Ce || r instanceof Ee))
|
425
425
|
return;
|
426
426
|
const s = e.mapping.maps[o];
|
427
427
|
let a = 0;
|
428
|
-
s.forEach((i, c, l,
|
429
|
-
a === 0 && (a =
|
428
|
+
s.forEach((i, c, l, p) => {
|
429
|
+
a === 0 && (a = p);
|
430
430
|
}), e.setSelection(O.near(e.doc.resolve(a), n));
|
431
431
|
}
|
432
|
-
const At = (e) => e.toString().startsWith("<"),
|
432
|
+
const At = (e) => e.toString().startsWith("<"), Ct = (e, t, n) => ({ tr: o, dispatch: r, editor: s }) => {
|
433
433
|
if (r) {
|
434
434
|
n = {
|
435
435
|
parseOptions: {},
|
@@ -438,7 +438,7 @@ const At = (e) => e.toString().startsWith("<"), Tt = (e, t, n) => ({ tr: o, disp
|
|
438
438
|
applyPasteRules: !1,
|
439
439
|
...n
|
440
440
|
};
|
441
|
-
const a =
|
441
|
+
const a = H(t, s.schema, {
|
442
442
|
parseOptions: {
|
443
443
|
preserveWhitespace: "full",
|
444
444
|
...n.parseOptions
|
@@ -446,36 +446,36 @@ 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 }, l = !0,
|
450
|
-
if ((At(a) ? a : [a]).forEach((
|
451
|
-
|
452
|
-
}), i === c &&
|
453
|
-
const { parent:
|
454
|
-
|
449
|
+
let { from: i, to: c } = typeof e == "number" ? { from: e, to: e } : { from: e.from, to: e.to }, l = !0, p = !0;
|
450
|
+
if ((At(a) ? a : [a]).forEach((f) => {
|
451
|
+
f.check(), l = l ? f.isText && f.marks.length === 0 : !1, p = p ? f.isBlock : !1;
|
452
|
+
}), i === c && p) {
|
453
|
+
const { parent: f } = o.doc.resolve(i);
|
454
|
+
f.isTextblock && !f.type.spec.code && !f.childCount && (i -= 1, c += 1);
|
455
455
|
}
|
456
|
-
let
|
457
|
-
l ? (Array.isArray(t) ?
|
456
|
+
let u;
|
457
|
+
l ? (Array.isArray(t) ? u = t.map((f) => f.text || "").join("") : typeof t == "object" && t && t.text ? u = t.text : u = t, o.insertText(u, i, c)) : (u = a, o.replaceWith(i, c, u)), n.updateSelection && Tt(o, o.steps.length - 1, -1), n.applyInputRules && o.setMeta("applyInputRules", { from: i, text: u }), n.applyPasteRules && o.setMeta("applyPasteRules", { from: i, text: u });
|
458
458
|
}
|
459
459
|
return !0;
|
460
|
-
},
|
460
|
+
}, 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 = () => ({ state: e, dispatch: t }) => Oe(e, t), It = () => ({ tr: e, state: t, dispatch: n }) => {
|
461
461
|
try {
|
462
|
-
const o =
|
462
|
+
const o = ue(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
|
}, Pt = () => ({ state: e, dispatch: t, tr: n }) => {
|
468
468
|
try {
|
469
|
-
const o =
|
469
|
+
const o = ue(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
|
+
}, Nt = () => ({ state: e, dispatch: t }) => je(e, t), Ot = () => ({ state: e, dispatch: t }) => Fe(e, t);
|
475
|
+
function we() {
|
476
476
|
return typeof navigator < "u" ? /Mac/.test(navigator.platform) : !1;
|
477
477
|
}
|
478
|
-
function
|
478
|
+
function jt(e) {
|
479
479
|
const t = e.split(/-(?!$)/);
|
480
480
|
let n = t[t.length - 1];
|
481
481
|
n === "Space" && (n = " ");
|
@@ -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
|
-
|
494
|
+
Z() || we() ? 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
|
-
const
|
501
|
-
const s =
|
500
|
+
const Ft = (e) => ({ editor: t, view: n, tr: o, dispatch: r }) => {
|
501
|
+
const s = jt(e).split(/-(?!$)/), a = s.find((l) => !["Alt", "Ctrl", "Meta", "Shift"].includes(l)), i = new KeyboardEvent("keydown", {
|
502
502
|
key: a === "Space" ? " " : a,
|
503
503
|
altKey: s.includes("Alt"),
|
504
504
|
ctrlKey: s.includes("Ctrl"),
|
@@ -510,69 +510,69 @@ const jt = (e) => ({ editor: t, view: n, tr: o, dispatch: r }) => {
|
|
510
510
|
n.someProp("handleKeyDown", (l) => l(n, i));
|
511
511
|
});
|
512
512
|
return c == null || c.steps.forEach((l) => {
|
513
|
-
const
|
514
|
-
|
513
|
+
const p = l.map(o.mapping);
|
514
|
+
p && r && o.maybeStep(p);
|
515
515
|
}), !0;
|
516
516
|
};
|
517
|
-
function
|
518
|
-
const { from: o, to: r, empty: s } = e.selection, a = t ?
|
519
|
-
e.doc.nodesBetween(o, r, (d,
|
517
|
+
function ee(e, t, n = {}) {
|
518
|
+
const { from: o, to: r, empty: s } = e.selection, a = t ? x(t, e.schema) : null, i = [];
|
519
|
+
e.doc.nodesBetween(o, r, (d, u) => {
|
520
520
|
if (d.isText)
|
521
521
|
return;
|
522
|
-
const
|
522
|
+
const f = Math.max(o, u), m = Math.min(r, u + d.nodeSize);
|
523
523
|
i.push({
|
524
524
|
node: d,
|
525
|
-
from:
|
525
|
+
from: f,
|
526
526
|
to: m
|
527
527
|
});
|
528
528
|
});
|
529
|
-
const c = r - o, l = i.filter((d) => a ? a.name === d.node.type.name : !0).filter((d) =>
|
530
|
-
return s ? !!l.length : l.reduce((d,
|
529
|
+
const c = r - o, l = i.filter((d) => a ? a.name === d.node.type.name : !0).filter((d) => W(d.node.attrs, n, { strict: !1 }));
|
530
|
+
return s ? !!l.length : l.reduce((d, u) => d + u.to - u.from, 0) >= c;
|
531
531
|
}
|
532
|
-
const
|
533
|
-
const r =
|
534
|
-
return
|
535
|
-
},
|
536
|
-
const o =
|
537
|
-
return
|
538
|
-
}, Dt = () => ({ state: e, dispatch: t }) =>
|
539
|
-
function
|
532
|
+
const Lt = (e, t = {}) => ({ state: n, dispatch: o }) => {
|
533
|
+
const r = x(e, n.schema);
|
534
|
+
return ee(n, r, t) ? Le(n, o) : !1;
|
535
|
+
}, Rt = () => ({ state: e, dispatch: t }) => Re(e, t), zt = (e) => ({ state: t, dispatch: n }) => {
|
536
|
+
const o = x(e, t.schema);
|
537
|
+
return Je(o)(t, n);
|
538
|
+
}, Dt = () => ({ state: e, dispatch: t }) => ze(e, t);
|
539
|
+
function xe(e, t) {
|
540
540
|
return t.nodes[e] ? "node" : t.marks[e] ? "mark" : null;
|
541
541
|
}
|
542
|
-
function
|
542
|
+
function re(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
|
-
const
|
546
|
+
const Wt = (e, t) => ({ tr: n, state: o, dispatch: r }) => {
|
547
547
|
let s = null, a = null;
|
548
|
-
const i =
|
549
|
-
return i ? (i === "node" && (s =
|
550
|
-
o.doc.nodesBetween(c.$from.pos, c.$to.pos, (l,
|
551
|
-
s && s === l.type && n.setNodeMarkup(
|
552
|
-
a === d.type && n.addMark(
|
548
|
+
const i = xe(typeof e == "string" ? e : e.name, o.schema);
|
549
|
+
return i ? (i === "node" && (s = x(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, (l, p) => {
|
551
|
+
s && s === l.type && n.setNodeMarkup(p, void 0, re(l.attrs, t)), a && l.marks.length && l.marks.forEach((d) => {
|
552
|
+
a === d.type && n.addMark(p, p + l.nodeSize, a.create(re(d.attrs, t)));
|
553
553
|
});
|
554
554
|
});
|
555
555
|
}), !0) : !1;
|
556
|
-
},
|
556
|
+
}, Ht = () => ({ tr: e, dispatch: t }) => (t && e.scrollIntoView(), !0), Kt = () => ({ tr: e, commands: t }) => t.setTextSelection({
|
557
557
|
from: 0,
|
558
558
|
to: e.doc.content.size
|
559
|
-
}),
|
560
|
-
function
|
561
|
-
return
|
559
|
+
}), Vt = () => ({ state: e, dispatch: t }) => De(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), Gt = () => ({ state: e, dispatch: t }) => Ve(e, t);
|
560
|
+
function qt(e, t, n = {}) {
|
561
|
+
return H(e, t, { slice: !1, parseOptions: n });
|
562
562
|
}
|
563
|
-
const
|
564
|
-
const { doc: a } = o, i =
|
563
|
+
const Qt = (e, t = !1, n = {}) => ({ tr: o, editor: r, dispatch: s }) => {
|
564
|
+
const { doc: a } = o, i = qt(e, r.schema, n);
|
565
565
|
return s && o.replaceWith(0, a.content.size, i).setMeta("preventUpdate", !t), !0;
|
566
566
|
};
|
567
|
-
function
|
568
|
-
const n =
|
567
|
+
function Xt(e, t) {
|
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
|
});
|
572
572
|
const i = a.find((c) => c.type.name === n.name);
|
573
573
|
return i ? { ...i.attrs } : {};
|
574
574
|
}
|
575
|
-
function
|
575
|
+
function Yt(e) {
|
576
576
|
for (let t = 0; t < e.edgeCount; t += 1) {
|
577
577
|
const { type: n } = e.edge(t);
|
578
578
|
if (n.isTextblock && !n.hasRequiredAttrs())
|
@@ -589,7 +589,7 @@ function F(e, t) {
|
|
589
589
|
});
|
590
590
|
}), n;
|
591
591
|
}
|
592
|
-
function
|
592
|
+
function Zt(e, t) {
|
593
593
|
for (let n = e.depth; n > 0; n -= 1) {
|
594
594
|
const o = e.node(n);
|
595
595
|
if (t(o))
|
@@ -601,86 +601,86 @@ function Yt(e, t) {
|
|
601
601
|
};
|
602
602
|
}
|
603
603
|
}
|
604
|
-
function
|
605
|
-
return (t) =>
|
604
|
+
function te(e) {
|
605
|
+
return (t) => Zt(t.$from, e);
|
606
606
|
}
|
607
|
-
function
|
607
|
+
function z(e, t, n) {
|
608
608
|
return Object.fromEntries(Object.entries(n).filter(([o]) => {
|
609
609
|
const r = e.find((s) => s.type === t && s.name === o);
|
610
610
|
return r ? r.attribute.keepOnSplit : !1;
|
611
611
|
}));
|
612
612
|
}
|
613
|
-
function
|
614
|
-
const { empty: o, ranges: r } = e.selection, s = t ?
|
613
|
+
function en(e, t, n = {}) {
|
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((d) => s ? s.name === d.type.name : !0).find((d) =>
|
616
|
+
return !!(e.storedMarks || e.selection.$from.marks()).filter((d) => s ? s.name === d.type.name : !0).find((d) => W(d.attrs, n, { strict: !1 }));
|
617
617
|
let a = 0;
|
618
618
|
const i = [];
|
619
|
-
if (r.forEach(({ $from: d, $to:
|
620
|
-
const
|
621
|
-
e.doc.nodesBetween(
|
619
|
+
if (r.forEach(({ $from: d, $to: u }) => {
|
620
|
+
const f = d.pos, m = u.pos;
|
621
|
+
e.doc.nodesBetween(f, m, (h, g) => {
|
622
622
|
if (!h.isText && !h.marks.length)
|
623
623
|
return;
|
624
|
-
const k = Math.max(
|
625
|
-
a +=
|
626
|
-
mark:
|
624
|
+
const k = Math.max(f, g), y = Math.min(m, g + h.nodeSize), w = y - k;
|
625
|
+
a += w, i.push(...h.marks.map((T) => ({
|
626
|
+
mark: T,
|
627
627
|
from: k,
|
628
|
-
to:
|
628
|
+
to: y
|
629
629
|
})));
|
630
630
|
});
|
631
631
|
}), a === 0)
|
632
632
|
return !1;
|
633
|
-
const c = i.filter((d) => s ? s.name === d.mark.type.name : !0).filter((d) =>
|
633
|
+
const c = i.filter((d) => s ? s.name === d.mark.type.name : !0).filter((d) => W(d.mark.attrs, n, { strict: !1 })).reduce((d, u) => d + u.to - u.from, 0), l = i.filter((d) => s ? d.mark.type !== s && d.mark.type.excludes(s) : !0).reduce((d, u) => d + u.to - u.from, 0);
|
634
634
|
return (c > 0 ? c + l : c) >= a;
|
635
635
|
}
|
636
|
-
function
|
637
|
-
const { nodeExtensions: n } =
|
636
|
+
function se(e, t) {
|
637
|
+
const { nodeExtensions: n } = Xe(t), o = n.find((a) => a.name === e);
|
638
638
|
if (!o)
|
639
639
|
return !1;
|
640
640
|
const r = {
|
641
641
|
name: o.name,
|
642
642
|
options: o.options,
|
643
643
|
storage: o.storage
|
644
|
-
}, s =
|
644
|
+
}, s = M(b(o, "group", r));
|
645
645
|
return typeof s != "string" ? !1 : s.split(" ").includes("list");
|
646
646
|
}
|
647
|
-
function
|
647
|
+
function tn(e, t, n) {
|
648
648
|
var o;
|
649
649
|
const { selection: r } = t;
|
650
650
|
let s = null;
|
651
|
-
if (
|
651
|
+
if (ke(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
657
|
let l = i.depth === 0 ? e.doc.inlineContent && e.doc.type.allowsMarkType(n) : !1;
|
658
|
-
return e.doc.nodesBetween(i.pos, c.pos, (
|
658
|
+
return e.doc.nodesBetween(i.pos, c.pos, (p, d, u) => {
|
659
659
|
if (l)
|
660
660
|
return !1;
|
661
|
-
if (
|
662
|
-
const
|
663
|
-
l =
|
661
|
+
if (p.isInline) {
|
662
|
+
const f = !u || u.type.allowsMarkType(n), m = !!n.isInSet(p.marks) || !p.marks.some((h) => h.type.excludes(n));
|
663
|
+
l = f && m;
|
664
664
|
}
|
665
665
|
return !l;
|
666
666
|
}), l;
|
667
667
|
});
|
668
668
|
}
|
669
|
-
const
|
670
|
-
const { selection: s } = n, { empty: a, ranges: i } = s, c =
|
669
|
+
const nn = (e, t = {}) => ({ tr: n, state: o, dispatch: r }) => {
|
670
|
+
const { selection: s } = n, { empty: a, ranges: i } = s, c = $(e, o.schema);
|
671
671
|
if (r)
|
672
672
|
if (a) {
|
673
|
-
const l =
|
673
|
+
const l = Xt(o, c);
|
674
674
|
n.addStoredMark(c.create({
|
675
675
|
...l,
|
676
676
|
...t
|
677
677
|
}));
|
678
678
|
} else
|
679
679
|
i.forEach((l) => {
|
680
|
-
const
|
681
|
-
o.doc.nodesBetween(
|
682
|
-
const m = Math.max(
|
683
|
-
|
680
|
+
const p = l.$from.pos, d = l.$to.pos;
|
681
|
+
o.doc.nodesBetween(p, d, (u, f) => {
|
682
|
+
const m = Math.max(f, p), h = Math.min(f + u.nodeSize, d);
|
683
|
+
u.marks.find((k) => k.type === c) ? u.marks.forEach((k) => {
|
684
684
|
c === k.type && n.addMark(m, h, c.create({
|
685
685
|
...k.attrs,
|
686
686
|
...t
|
@@ -688,68 +688,68 @@ const tn = (e, t = {}) => ({ tr: n, state: o, dispatch: r }) => {
|
|
688
688
|
}) : n.addMark(m, h, c.create(t));
|
689
689
|
});
|
690
690
|
});
|
691
|
-
return
|
692
|
-
},
|
693
|
-
const s =
|
694
|
-
return s.isTextblock ? r().command(({ commands: a }) =>
|
695
|
-
},
|
691
|
+
return tn(o, n, c);
|
692
|
+
}, on = (e, t) => ({ tr: n }) => (n.setMeta(e, t), !0), rn = (e, t = {}) => ({ state: n, dispatch: o, chain: r }) => {
|
693
|
+
const s = x(e, n.schema);
|
694
|
+
return s.isTextblock ? r().command(({ commands: a }) => ne(s, t)(n) ? !0 : a.clearNodes()).command(({ state: a }) => ne(s, t)(a, o)).run() : (console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'), !1);
|
695
|
+
}, sn = (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 = de.create(o, r);
|
698
698
|
t.setSelection(s);
|
699
699
|
}
|
700
700
|
return !0;
|
701
|
-
},
|
701
|
+
}, an = (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 =
|
704
|
-
t.setSelection(
|
703
|
+
const { doc: o } = t, { from: r, to: s } = typeof e == "number" ? { from: e, to: e } : e, a = C.atStart(o).from, i = C.atEnd(o).to, c = I(r, a, i), l = I(s, a, i), p = C.create(o, c, l);
|
704
|
+
t.setSelection(p);
|
705
705
|
}
|
706
706
|
return !0;
|
707
|
-
},
|
708
|
-
const o =
|
709
|
-
return
|
707
|
+
}, cn = (e) => ({ state: t, dispatch: n }) => {
|
708
|
+
const o = x(e, t.schema);
|
709
|
+
return Ue(o)(t, n);
|
710
710
|
};
|
711
|
-
function
|
711
|
+
function ie(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));
|
715
715
|
e.tr.ensureMarks(o);
|
716
716
|
}
|
717
717
|
}
|
718
|
-
const
|
719
|
-
const { selection: s, doc: a } = t, { $from: i, $to: c } = s, l = r.extensionManager.attributes,
|
720
|
-
if (s instanceof
|
721
|
-
return !i.parentOffset || !R(a, i.pos) ? !1 : (o && (e &&
|
718
|
+
const ln = ({ 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, p = z(l, i.node().type.name, i.node().attrs);
|
720
|
+
if (s instanceof de && s.node.isBlock)
|
721
|
+
return !i.parentOffset || !R(a, i.pos) ? !1 : (o && (e && ie(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
725
|
const d = c.parentOffset === c.parent.content.size;
|
726
|
-
s instanceof
|
727
|
-
const
|
728
|
-
let
|
726
|
+
s instanceof C && t.deleteSelection();
|
727
|
+
const u = i.depth === 0 ? void 0 : Yt(i.node(-1).contentMatchAt(i.indexAfter(-1)));
|
728
|
+
let f = d && u ? [
|
729
729
|
{
|
730
|
-
type:
|
731
|
-
attrs:
|
730
|
+
type: u,
|
731
|
+
attrs: p
|
732
732
|
}
|
733
|
-
] : void 0, m = R(t.doc, t.mapping.map(i.pos), 1,
|
734
|
-
if (!
|
733
|
+
] : void 0, m = R(t.doc, t.mapping.map(i.pos), 1, f);
|
734
|
+
if (!f && !m && R(t.doc, t.mapping.map(i.pos), 1, u ? [{ type: u }] : void 0) && (m = !0, f = u ? [
|
735
735
|
{
|
736
|
-
type:
|
737
|
-
attrs:
|
736
|
+
type: u,
|
737
|
+
attrs: p
|
738
738
|
}
|
739
|
-
] : void 0), m && (t.split(t.mapping.map(i.pos), 1,
|
739
|
+
] : void 0), m && (t.split(t.mapping.map(i.pos), 1, f), u && !d && !i.parentOffset && i.parent.type !== u)) {
|
740
740
|
const h = t.mapping.map(i.before()), g = t.doc.resolve(h);
|
741
|
-
i.node(-1).canReplaceWith(g.index(), g.index() + 1,
|
741
|
+
i.node(-1).canReplaceWith(g.index(), g.index() + 1, u) && t.setNodeMarkup(t.mapping.map(i.before()), u);
|
742
742
|
}
|
743
|
-
e &&
|
743
|
+
e && ie(n, r.extensionManager.splittableMarks), t.scrollIntoView();
|
744
744
|
}
|
745
745
|
return !0;
|
746
|
-
},
|
746
|
+
}, dn = (e) => ({ tr: t, state: n, dispatch: o, editor: r }) => {
|
747
747
|
var s;
|
748
|
-
const a =
|
748
|
+
const a = x(e, n.schema), { $from: i, $to: c } = n.selection, l = n.selection.node;
|
749
749
|
if (l && l.isBlock || i.depth < 2 || !i.sameParent(c))
|
750
750
|
return !1;
|
751
|
-
const
|
752
|
-
if (
|
751
|
+
const p = i.node(-1);
|
752
|
+
if (p.type !== a)
|
753
753
|
return !1;
|
754
754
|
const d = r.extensionManager.attributes;
|
755
755
|
if (i.parent.content.size === 0 && i.node(-1).childCount === i.indexAfter(-1)) {
|
@@ -760,78 +760,78 @@ 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
|
764
|
-
g = g.append(L.from(a.createAndFill(null,
|
763
|
+
const y = i.indexAfter(-1) < i.node(-2).childCount ? 1 : i.indexAfter(-2) < i.node(-3).childCount ? 2 : 3, w = z(d, i.node().type.name, i.node().attrs), T = ((s = a.contentMatch.defaultType) === null || s === void 0 ? void 0 : s.createAndFill(w)) || void 0;
|
764
|
+
g = g.append(L.from(a.createAndFill(null, T) || void 0));
|
765
765
|
const S = i.before(i.depth - (k - 1));
|
766
|
-
t.replace(S, i.after(-
|
767
|
-
let
|
768
|
-
t.doc.nodesBetween(S, t.doc.content.size, (v,
|
769
|
-
if (
|
766
|
+
t.replace(S, i.after(-y), new Me(g, 4 - k, 0));
|
767
|
+
let A = -1;
|
768
|
+
t.doc.nodesBetween(S, t.doc.content.size, (v, V) => {
|
769
|
+
if (A > -1)
|
770
770
|
return !1;
|
771
|
-
v.isTextblock && v.content.size === 0 && (
|
772
|
-
}),
|
771
|
+
v.isTextblock && v.content.size === 0 && (A = V + 1);
|
772
|
+
}), A > -1 && t.setSelection(C.near(t.doc.resolve(A))), t.scrollIntoView();
|
773
773
|
}
|
774
774
|
return !0;
|
775
775
|
}
|
776
|
-
const
|
776
|
+
const u = c.pos === i.end() ? p.contentMatchAt(0).defaultType : null, f = z(d, p.type.name, p.attrs), m = z(d, i.node().type.name, i.node().attrs);
|
777
777
|
t.delete(i.pos, c.pos);
|
778
|
-
const h =
|
779
|
-
{ type: a, attrs:
|
780
|
-
{ type:
|
781
|
-
] : [{ type: a, attrs:
|
778
|
+
const h = u ? [
|
779
|
+
{ type: a, attrs: f },
|
780
|
+
{ type: u, attrs: m }
|
781
|
+
] : [{ type: a, attrs: f }];
|
782
782
|
if (!R(t.doc, i.pos, 2))
|
783
783
|
return !1;
|
784
784
|
if (o) {
|
785
|
-
const { selection: g, storedMarks: k } = n, { splittableMarks:
|
786
|
-
if (t.split(i.pos, 2, h).scrollIntoView(), !
|
785
|
+
const { selection: g, storedMarks: k } = n, { splittableMarks: y } = r.extensionManager, w = k || g.$to.parentOffset && g.$from.marks();
|
786
|
+
if (t.split(i.pos, 2, h).scrollIntoView(), !w || !o)
|
787
787
|
return !0;
|
788
|
-
const
|
789
|
-
t.ensureMarks(
|
788
|
+
const T = w.filter((S) => y.includes(S.type.name));
|
789
|
+
t.ensureMarks(T);
|
790
790
|
}
|
791
791
|
return !0;
|
792
|
-
},
|
793
|
-
const n =
|
792
|
+
}, U = (e, t) => {
|
793
|
+
const n = te((a) => a.type === t)(e.selection);
|
794
794
|
if (!n)
|
795
795
|
return !0;
|
796
796
|
const o = e.doc.resolve(Math.max(0, n.pos - 1)).before(n.depth);
|
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) &&
|
801
|
-
},
|
802
|
-
const n =
|
800
|
+
return n.node.type === (r == null ? void 0 : r.type) && fe(e.doc, n.pos) && e.join(n.pos), !0;
|
801
|
+
}, G = (e, t) => {
|
802
|
+
const n = te((a) => a.type === t)(e.selection);
|
803
803
|
if (!n)
|
804
804
|
return !0;
|
805
805
|
const o = e.doc.resolve(n.start).after(n.depth);
|
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
|
-
},
|
811
|
-
const { extensions: d, splittableMarks:
|
812
|
-
if (!
|
809
|
+
return n.node.type === (r == null ? void 0 : r.type) && fe(e.doc, o) && e.join(o), !0;
|
810
|
+
}, un = (e, t, n, o = {}) => ({ editor: r, tr: s, state: a, dispatch: i, chain: c, commands: l, can: p }) => {
|
811
|
+
const { extensions: d, splittableMarks: u } = r.extensionManager, f = x(e, a.schema), m = x(t, a.schema), { selection: h, storedMarks: g } = a, { $from: k, $to: y } = h, w = k.blockRange(y), T = g || h.$to.parentOffset && h.$from.marks();
|
812
|
+
if (!w)
|
813
813
|
return !1;
|
814
|
-
const S =
|
815
|
-
if (
|
816
|
-
if (S.node.type ===
|
814
|
+
const S = te((A) => se(A.type.name, d))(h);
|
815
|
+
if (w.depth >= 1 && S && w.depth - S.depth <= 1) {
|
816
|
+
if (S.node.type === f)
|
817
817
|
return l.liftListItem(m);
|
818
|
-
if (
|
819
|
-
return c().command(() => (s.setNodeMarkup(S.pos,
|
818
|
+
if (se(S.node.type.name, d) && f.validContent(S.node.content) && i)
|
819
|
+
return c().command(() => (s.setNodeMarkup(S.pos, f), !0)).command(() => U(s, f)).command(() => G(s, f)).run();
|
820
820
|
}
|
821
|
-
return !n || !
|
822
|
-
const
|
823
|
-
return s.ensureMarks(v),
|
824
|
-
}).wrapInList(
|
825
|
-
},
|
826
|
-
const { extendEmptyMarkRange: s = !1 } = n, a =
|
827
|
-
return
|
828
|
-
},
|
829
|
-
const s =
|
830
|
-
return
|
831
|
-
},
|
832
|
-
const r =
|
833
|
-
return
|
834
|
-
},
|
821
|
+
return !n || !T || !i ? c().command(() => p().wrapInList(f, o) ? !0 : l.clearNodes()).wrapInList(f, o).command(() => U(s, f)).command(() => G(s, f)).run() : c().command(() => {
|
822
|
+
const A = p().wrapInList(f, o), v = T.filter((V) => u.includes(V.type.name));
|
823
|
+
return s.ensureMarks(v), A ? !0 : l.clearNodes();
|
824
|
+
}).wrapInList(f, o).command(() => U(s, f)).command(() => G(s, f)).run();
|
825
|
+
}, fn = (e, t = {}, n = {}) => ({ state: o, commands: r }) => {
|
826
|
+
const { extendEmptyMarkRange: s = !1 } = n, a = $(e, o.schema);
|
827
|
+
return en(o, a, t) ? r.unsetMark(a, { extendEmptyMarkRange: s }) : r.setMark(a, t);
|
828
|
+
}, pn = (e, t, n = {}) => ({ state: o, commands: r }) => {
|
829
|
+
const s = x(e, o.schema), a = x(t, o.schema);
|
830
|
+
return ee(o, s, n) ? r.setNode(a) : r.setNode(s, n);
|
831
|
+
}, mn = (e, t = {}) => ({ state: n, commands: o }) => {
|
832
|
+
const r = x(e, n.schema);
|
833
|
+
return ee(n, r, t) ? o.lift(r) : o.wrapIn(r, t);
|
834
|
+
}, hn = () => ({ state: e, dispatch: t }) => {
|
835
835
|
const n = e.plugins;
|
836
836
|
for (let o = 0; o < n.length; o += 1) {
|
837
837
|
const r = n[o];
|
@@ -851,126 +851,126 @@ const cn = ({ keepMarks: e = !0 } = {}) => ({ tr: t, state: n, dispatch: o, edit
|
|
851
851
|
}
|
852
852
|
}
|
853
853
|
return !1;
|
854
|
-
},
|
854
|
+
}, gn = () => ({ tr: e, dispatch: t }) => {
|
855
855
|
const { selection: n } = e, { empty: o, ranges: r } = n;
|
856
856
|
return o || t && r.forEach((s) => {
|
857
857
|
e.removeMark(s.$from.pos, s.$to.pos);
|
858
858
|
}), !0;
|
859
|
-
},
|
859
|
+
}, kn = (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: l, empty: p, ranges: d } = i;
|
862
862
|
if (!r)
|
863
863
|
return !0;
|
864
|
-
if (
|
865
|
-
let { from:
|
866
|
-
const m = (s = l.marks().find((g) => g.type === c)) === null || s === void 0 ? void 0 : s.attrs, h =
|
867
|
-
h && (
|
864
|
+
if (p && a) {
|
865
|
+
let { from: u, to: f } = i;
|
866
|
+
const m = (s = l.marks().find((g) => g.type === c)) === null || s === void 0 ? void 0 : s.attrs, h = ge(l, c, m);
|
867
|
+
h && (u = h.from, f = h.to), n.removeMark(u, f, c);
|
868
868
|
} else
|
869
|
-
d.forEach((
|
870
|
-
n.removeMark(
|
869
|
+
d.forEach((u) => {
|
870
|
+
n.removeMark(u.$from.pos, u.$to.pos, c);
|
871
871
|
});
|
872
872
|
return n.removeStoredMark(c), !0;
|
873
|
-
},
|
873
|
+
}, yn = (e, t = {}) => ({ tr: n, state: o, dispatch: r }) => {
|
874
874
|
let s = null, a = null;
|
875
|
-
const i =
|
876
|
-
return i ? (i === "node" && (s =
|
877
|
-
const l = c.$from.pos,
|
878
|
-
o.doc.nodesBetween(l,
|
879
|
-
s && s === d.type && n.setNodeMarkup(
|
875
|
+
const i = xe(typeof e == "string" ? e : e.name, o.schema);
|
876
|
+
return i ? (i === "node" && (s = x(e, o.schema)), i === "mark" && (a = $(e, o.schema)), r && n.selection.ranges.forEach((c) => {
|
877
|
+
const l = c.$from.pos, p = c.$to.pos;
|
878
|
+
o.doc.nodesBetween(l, p, (d, u) => {
|
879
|
+
s && s === d.type && n.setNodeMarkup(u, void 0, {
|
880
880
|
...d.attrs,
|
881
881
|
...t
|
882
|
-
}), a && d.marks.length && d.marks.forEach((
|
883
|
-
if (a ===
|
884
|
-
const m = Math.max(
|
882
|
+
}), a && d.marks.length && d.marks.forEach((f) => {
|
883
|
+
if (a === f.type) {
|
884
|
+
const m = Math.max(u, l), h = Math.min(u + d.nodeSize, p);
|
885
885
|
n.addMark(m, h, a.create({
|
886
|
-
...
|
886
|
+
...f.attrs,
|
887
887
|
...t
|
888
888
|
}));
|
889
889
|
}
|
890
890
|
});
|
891
891
|
});
|
892
892
|
}), !0) : !1;
|
893
|
-
}, yn = (e, t = {}) => ({ state: n, dispatch: o }) => {
|
894
|
-
const r = y(e, n.schema);
|
895
|
-
return Ve(r, t)(n, o);
|
896
893
|
}, wn = (e, t = {}) => ({ state: n, dispatch: o }) => {
|
897
|
-
const r =
|
898
|
-
return
|
894
|
+
const r = x(e, n.schema);
|
895
|
+
return _e(r, t)(n, o);
|
896
|
+
}, xn = (e, t = {}) => ({ state: n, dispatch: o }) => {
|
897
|
+
const r = x(e, n.schema);
|
898
|
+
return Ge(r, t)(n, o);
|
899
899
|
};
|
900
|
-
var
|
900
|
+
var Sn = /* @__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:
|
923
|
-
joinForward:
|
902
|
+
blur: st,
|
903
|
+
clearContent: it,
|
904
|
+
clearNodes: at,
|
905
|
+
command: ct,
|
906
|
+
createParagraphNear: lt,
|
907
|
+
cut: dt,
|
908
|
+
deleteCurrentNode: ut,
|
909
|
+
deleteNode: ft,
|
910
|
+
deleteRange: pt,
|
911
|
+
deleteSelection: mt,
|
912
|
+
enter: ht,
|
913
|
+
exitCode: gt,
|
914
|
+
extendMarkRange: yt,
|
915
|
+
first: wt,
|
916
|
+
focus: St,
|
917
|
+
forEach: bt,
|
918
|
+
insertContent: Mt,
|
919
|
+
insertContentAt: Ct,
|
920
|
+
joinUp: Et,
|
921
|
+
joinDown: Bt,
|
922
|
+
joinBackward: vt,
|
923
|
+
joinForward: $t,
|
924
924
|
joinItemBackward: It,
|
925
925
|
joinItemForward: Pt,
|
926
|
-
joinTextblockBackward:
|
927
|
-
joinTextblockForward:
|
928
|
-
keyboardShortcut:
|
929
|
-
lift:
|
930
|
-
liftEmptyBlock:
|
931
|
-
liftListItem:
|
926
|
+
joinTextblockBackward: Nt,
|
927
|
+
joinTextblockForward: Ot,
|
928
|
+
keyboardShortcut: Ft,
|
929
|
+
lift: Lt,
|
930
|
+
liftEmptyBlock: Rt,
|
931
|
+
liftListItem: zt,
|
932
932
|
newlineInCode: Dt,
|
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:
|
933
|
+
resetAttributes: Wt,
|
934
|
+
scrollIntoView: Ht,
|
935
|
+
selectAll: Kt,
|
936
|
+
selectNodeBackward: Vt,
|
937
|
+
selectNodeForward: _t,
|
938
|
+
selectParentNode: Jt,
|
939
|
+
selectTextblockEnd: Ut,
|
940
|
+
selectTextblockStart: Gt,
|
941
|
+
setContent: Qt,
|
942
|
+
setMark: nn,
|
943
|
+
setMeta: on,
|
944
|
+
setNode: rn,
|
945
|
+
setNodeSelection: sn,
|
946
|
+
setTextSelection: an,
|
947
|
+
sinkListItem: cn,
|
948
|
+
splitBlock: ln,
|
949
|
+
splitListItem: dn,
|
950
|
+
toggleList: un,
|
951
|
+
toggleMark: fn,
|
952
|
+
toggleNode: pn,
|
953
|
+
toggleWrap: mn,
|
954
|
+
undoInputRule: hn,
|
955
|
+
unsetAllMarks: gn,
|
956
|
+
unsetMark: kn,
|
957
|
+
updateAttributes: yn,
|
958
|
+
wrapIn: wn,
|
959
|
+
wrapInList: xn
|
960
960
|
});
|
961
|
-
|
961
|
+
B.create({
|
962
962
|
name: "commands",
|
963
963
|
addCommands() {
|
964
964
|
return {
|
965
|
-
...
|
965
|
+
...Sn
|
966
966
|
};
|
967
967
|
}
|
968
968
|
});
|
969
|
-
|
969
|
+
B.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
|
@@ -979,12 +979,12 @@ C.create({
|
|
979
979
|
];
|
980
980
|
}
|
981
981
|
});
|
982
|
-
|
982
|
+
B.create({
|
983
983
|
name: "focusEvents",
|
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: {
|
@@ -1004,15 +1004,15 @@ C.create({
|
|
1004
1004
|
];
|
1005
1005
|
}
|
1006
1006
|
});
|
1007
|
-
|
1007
|
+
B.create({
|
1008
1008
|
name: "keymap",
|
1009
1009
|
addKeyboardShortcuts() {
|
1010
1010
|
const e = () => this.editor.commands.first(({ commands: a }) => [
|
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: l } = i, { empty:
|
1015
|
-
return !
|
1014
|
+
const { selection: c, doc: l } = i, { empty: p, $anchor: d } = c, { pos: u, parent: f } = d, m = d.parent.isTextblock && u > 0 ? i.doc.resolve(u - 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 === u;
|
1015
|
+
return !p || !k || !f.type.isTextblock || f.textContent.length ? !1 : a.clearNodes();
|
1016
1016
|
}),
|
1017
1017
|
() => a.deleteSelection(),
|
1018
1018
|
() => a.joinBackward(),
|
@@ -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
|
1052
|
+
return Z() || we() ? 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,25 +1066,25 @@ 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 d = n.tr,
|
1069
|
+
const d = n.tr, u = he({
|
1070
1070
|
state: n,
|
1071
1071
|
transaction: d
|
1072
|
-
}), { commands:
|
1072
|
+
}), { commands: f } = new Qe({
|
1073
1073
|
editor: this.editor,
|
1074
|
-
state:
|
1074
|
+
state: u
|
1075
1075
|
});
|
1076
|
-
if (
|
1076
|
+
if (f.clearNodes(), !!d.steps.length)
|
1077
1077
|
return d;
|
1078
1078
|
}
|
1079
1079
|
})
|
1080
1080
|
];
|
1081
1081
|
}
|
1082
1082
|
});
|
1083
|
-
|
1083
|
+
B.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,18 +1093,18 @@ C.create({
|
|
1093
1093
|
];
|
1094
1094
|
}
|
1095
1095
|
});
|
1096
|
-
function
|
1097
|
-
return new
|
1096
|
+
function ae(e) {
|
1097
|
+
return new tt({
|
1098
1098
|
find: e.find,
|
1099
1099
|
handler: ({ state: t, range: n, match: o }) => {
|
1100
|
-
const r = t.doc.resolve(n.from), s =
|
1100
|
+
const r = t.doc.resolve(n.from), s = M(e.getAttributes, void 0, o) || {};
|
1101
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
|
1107
|
+
class K {
|
1108
1108
|
constructor(t = {}) {
|
1109
1109
|
this.type = "node", this.name = "node", this.parent = null, this.child = null, this.config = {
|
1110
1110
|
name: this.name,
|
@@ -1112,34 +1112,34 @@ class H {
|
|
1112
1112
|
}, this.config = {
|
1113
1113
|
...this.config,
|
1114
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 =
|
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 = M(b(this, "addOptions", {
|
1116
1116
|
name: this.name
|
1117
|
-
}))), this.storage =
|
1117
|
+
}))), this.storage = M(b(this, "addStorage", {
|
1118
1118
|
name: this.name,
|
1119
1119
|
options: this.options
|
1120
1120
|
})) || {};
|
1121
1121
|
}
|
1122
1122
|
static create(t = {}) {
|
1123
|
-
return new
|
1123
|
+
return new K(t);
|
1124
1124
|
}
|
1125
1125
|
configure(t = {}) {
|
1126
1126
|
const n = this.extend();
|
1127
|
-
return n.options =
|
1127
|
+
return n.options = Y(this.options, t), n.storage = M(b(n, "addStorage", {
|
1128
1128
|
name: n.name,
|
1129
1129
|
options: n.options
|
1130
1130
|
})), n;
|
1131
1131
|
}
|
1132
1132
|
extend(t = {}) {
|
1133
|
-
const n = new
|
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 =
|
1133
|
+
const n = new K({ ...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 = M(b(n, "addOptions", {
|
1135
1135
|
name: n.name
|
1136
|
-
})), n.storage =
|
1136
|
+
})), n.storage = M(b(n, "addStorage", {
|
1137
1137
|
name: n.name,
|
1138
1138
|
options: n.options
|
1139
1139
|
})), n;
|
1140
1140
|
}
|
1141
1141
|
}
|
1142
|
-
const
|
1142
|
+
const bn = /^```([a-z]+)?[\s\n]$/, Mn = /^~~~([a-z]+)?[\s\n]$/, Tn = K.create({
|
1143
1143
|
name: "codeBlock",
|
1144
1144
|
addOptions() {
|
1145
1145
|
return {
|
@@ -1178,7 +1178,7 @@ const Sn = /^```([a-z]+)?[\s\n]$/, bn = /^~~~([a-z]+)?[\s\n]$/, Mn = H.create({
|
|
1178
1178
|
renderHTML({ node: e, HTMLAttributes: t }) {
|
1179
1179
|
return [
|
1180
1180
|
"pre",
|
1181
|
-
|
1181
|
+
Ye(this.options.HTMLAttributes, t),
|
1182
1182
|
[
|
1183
1183
|
"code",
|
1184
1184
|
{
|
@@ -1228,15 +1228,15 @@ const Sn = /^```([a-z]+)?[\s\n]$/, bn = /^~~~([a-z]+)?[\s\n]$/, Mn = H.create({
|
|
1228
1228
|
},
|
1229
1229
|
addInputRules() {
|
1230
1230
|
return [
|
1231
|
-
|
1232
|
-
find:
|
1231
|
+
ae({
|
1232
|
+
find: bn,
|
1233
1233
|
type: this.type,
|
1234
1234
|
getAttributes: (e) => ({
|
1235
1235
|
language: e[1]
|
1236
1236
|
})
|
1237
1237
|
}),
|
1238
|
-
|
1239
|
-
find:
|
1238
|
+
ae({
|
1239
|
+
find: Mn,
|
1240
1240
|
type: this.type,
|
1241
1241
|
getAttributes: (e) => ({
|
1242
1242
|
language: e[1]
|
@@ -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) => {
|
@@ -1258,7 +1258,7 @@ const Sn = /^```([a-z]+)?[\s\n]$/, bn = /^~~~([a-z]+)?[\s\n]$/, Mn = H.create({
|
|
1258
1258
|
if (!n || !s)
|
1259
1259
|
return !1;
|
1260
1260
|
const { tr: a } = e.state;
|
1261
|
-
return a.replaceSelectionWith(this.type.create({ language: s })), a.setSelection(
|
1261
|
+
return a.replaceSelectionWith(this.type.create({ language: s })), a.setSelection(C.near(a.doc.resolve(Math.max(0, a.selection.from - 2)))), a.insertText(n.replace(/\r\n?/g, `
|
1262
1262
|
`)), a.setMeta("paste", !0), e.dispatch(a), !0;
|
1263
1263
|
}
|
1264
1264
|
}
|
@@ -1266,86 +1266,129 @@ const Sn = /^```([a-z]+)?[\s\n]$/, bn = /^~~~([a-z]+)?[\s\n]$/, Mn = H.create({
|
|
1266
1266
|
];
|
1267
1267
|
}
|
1268
1268
|
});
|
1269
|
-
let
|
1270
|
-
const
|
1269
|
+
let E, j;
|
1270
|
+
const q = /* @__PURE__ */ new Set(), Q = /* @__PURE__ */ new Set();
|
1271
1271
|
function An() {
|
1272
|
-
return
|
1272
|
+
return E;
|
1273
1273
|
}
|
1274
|
-
function
|
1275
|
-
if (!
|
1274
|
+
function Cn(e) {
|
1275
|
+
if (!E && !j) {
|
1276
1276
|
const t = e.themes.filter(
|
1277
|
-
(o) => !!o && o in
|
1277
|
+
(o) => !!o && o in pe
|
1278
1278
|
), n = e.languages.filter(
|
1279
|
-
(o) => !!o && o in
|
1279
|
+
(o) => !!o && o in me
|
1280
1280
|
);
|
1281
|
-
return j =
|
1282
|
-
|
1281
|
+
return j = qe({ themes: t, langs: n }).then((o) => {
|
1282
|
+
E = o;
|
1283
1283
|
}), j;
|
1284
1284
|
}
|
1285
1285
|
if (j)
|
1286
1286
|
return j;
|
1287
1287
|
}
|
1288
|
-
async function
|
1289
|
-
return
|
1288
|
+
async function D(e) {
|
1289
|
+
return E && !E.getLoadedThemes().includes(e) && !Q.has(e) && e in pe ? (Q.add(e), await E.loadTheme(e), Q.delete(e), !0) : !1;
|
1290
1290
|
}
|
1291
|
-
async function
|
1292
|
-
return
|
1291
|
+
async function Se(e) {
|
1292
|
+
return E && !E.getLoadedLanguages().includes(e) && !q.has(e) && e in me ? (q.add(e), await E.loadLanguage(e), q.delete(e), !0) : !1;
|
1293
1293
|
}
|
1294
|
-
async function
|
1294
|
+
async function En({
|
1295
1295
|
doc: e,
|
1296
1296
|
name: t,
|
1297
1297
|
defaultTheme: n,
|
1298
|
-
defaultLanguage: o
|
1298
|
+
defaultLanguage: o,
|
1299
|
+
themeModes: r
|
1299
1300
|
}) {
|
1300
|
-
const
|
1301
|
-
...
|
1301
|
+
const s = F(e, (c) => c.type.name === t), a = [
|
1302
|
+
...s.map((c) => c.node.attrs.theme),
|
1302
1303
|
n
|
1303
|
-
],
|
1304
|
-
...
|
1304
|
+
], i = [
|
1305
|
+
...s.map((c) => c.node.attrs.language),
|
1305
1306
|
o
|
1306
1307
|
];
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1308
|
+
if (E)
|
1309
|
+
await Promise.all([
|
1310
|
+
...a.flatMap((c) => D(c)),
|
1311
|
+
...i.flatMap((c) => !!c && Se(c))
|
1312
|
+
]);
|
1313
|
+
else {
|
1314
|
+
const c = [...a];
|
1315
|
+
r && (r.light && !c.includes(r.light) && c.push(r.light), r.dark && !c.includes(r.dark) && c.push(r.dark)), await Cn({
|
1316
|
+
languages: i,
|
1317
|
+
themes: c
|
1318
|
+
});
|
1319
|
+
}
|
1320
|
+
}
|
1321
|
+
function ce(e) {
|
1322
|
+
return Object.entries(e || {}).map(([t, n]) => `${t}:${n}`).join(";");
|
1311
1323
|
}
|
1312
|
-
function
|
1324
|
+
function le({
|
1313
1325
|
doc: e,
|
1314
1326
|
name: t,
|
1315
1327
|
defaultTheme: n,
|
1316
|
-
defaultLanguage: o
|
1328
|
+
defaultLanguage: o,
|
1329
|
+
themes: r
|
1317
1330
|
}) {
|
1318
|
-
const
|
1319
|
-
return F(e, (
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1331
|
+
const s = [];
|
1332
|
+
return F(e, (i) => i.type.name === t).forEach((i) => {
|
1333
|
+
var g, k;
|
1334
|
+
let c = i.pos + 1, l = i.node.attrs.language || o, p = i.node.attrs.theme || n, d = ((g = i.node.attrs.themes) == null ? void 0 : g.light) || (r == null ? void 0 : r.light), u = ((k = i.node.attrs.themes) == null ? void 0 : k.dark) || (r == null ? void 0 : r.dark);
|
1335
|
+
const f = An();
|
1336
|
+
if (!f)
|
1323
1337
|
return;
|
1324
|
-
|
1325
|
-
const
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1338
|
+
f.getLoadedLanguages().includes(l) || (l = "plaintext");
|
1339
|
+
const m = (y) => f.getLoadedThemes().includes(y) ? y : f.getLoadedThemes()[0];
|
1340
|
+
let h;
|
1341
|
+
if (r) {
|
1342
|
+
h = f.codeToTokens(i.node.textContent, {
|
1343
|
+
lang: l,
|
1344
|
+
themes: {
|
1345
|
+
light: m(d),
|
1346
|
+
dark: m(u)
|
1347
|
+
}
|
1348
|
+
});
|
1349
|
+
const y = {};
|
1350
|
+
h.bg && (y["background-color"] = h.bg), h.fg && (y.color = h.fg), s.push(
|
1351
|
+
_.node(i.pos, i.pos + i.node.nodeSize, {
|
1352
|
+
style: ce(y),
|
1353
|
+
class: "shiki"
|
1354
|
+
})
|
1355
|
+
);
|
1356
|
+
} else {
|
1357
|
+
h = f.codeToTokens(i.node.textContent, {
|
1358
|
+
lang: l,
|
1359
|
+
theme: m(p)
|
1360
|
+
});
|
1361
|
+
const y = f.getLoadedThemes().includes(p) ? p : f.getLoadedThemes()[0], w = f.getTheme(y);
|
1362
|
+
s.push(
|
1363
|
+
_.node(i.pos, i.pos + i.node.nodeSize, {
|
1364
|
+
style: `background-color: ${w.bg}`
|
1365
|
+
})
|
1366
|
+
);
|
1367
|
+
}
|
1368
|
+
for (const y of h.tokens) {
|
1369
|
+
for (const w of y) {
|
1370
|
+
const T = c + w.content.length;
|
1371
|
+
let S = "";
|
1372
|
+
r ? S = ce(w.htmlStyle || {}) : S = `color: ${w.color}`;
|
1373
|
+
const A = _.inline(c, T, {
|
1374
|
+
style: S
|
1333
1375
|
});
|
1334
|
-
|
1376
|
+
s.push(A), c = T;
|
1335
1377
|
}
|
1336
|
-
|
1378
|
+
c += 1;
|
1337
1379
|
}
|
1338
|
-
}),
|
1380
|
+
}), be.create(e, s);
|
1339
1381
|
}
|
1340
|
-
function
|
1382
|
+
function Bn({
|
1341
1383
|
name: e,
|
1342
1384
|
defaultLanguage: t,
|
1343
|
-
defaultTheme: n
|
1385
|
+
defaultTheme: n,
|
1386
|
+
themes: o
|
1344
1387
|
}) {
|
1345
|
-
const
|
1388
|
+
const r = new P({
|
1346
1389
|
key: new N("shiki"),
|
1347
|
-
view(
|
1348
|
-
class
|
1390
|
+
view(s) {
|
1391
|
+
class a {
|
1349
1392
|
constructor() {
|
1350
1393
|
this.initDecorations();
|
1351
1394
|
}
|
@@ -1356,77 +1399,88 @@ function En({
|
|
1356
1399
|
}
|
1357
1400
|
// Initialize shiki async, and then highlight initial document
|
1358
1401
|
async initDecorations() {
|
1359
|
-
const
|
1360
|
-
await
|
1361
|
-
|
1362
|
-
|
1402
|
+
const c = s.state.doc;
|
1403
|
+
await En({
|
1404
|
+
doc: c,
|
1405
|
+
name: e,
|
1406
|
+
defaultLanguage: t,
|
1407
|
+
defaultTheme: n,
|
1408
|
+
themeModes: o
|
1409
|
+
});
|
1410
|
+
const l = s.state.tr.setMeta("shikiPluginForceDecoration", !0);
|
1411
|
+
s.dispatch(l);
|
1363
1412
|
}
|
1364
1413
|
// When new codeblocks were added and they have missing themes or
|
1365
1414
|
// languages, load those and then add code decorations once again.
|
1366
1415
|
async checkUndecoratedBlocks() {
|
1367
|
-
const
|
1368
|
-
|
1416
|
+
const c = F(
|
1417
|
+
s.state.doc,
|
1369
1418
|
(u) => u.type.name === e
|
1370
|
-
)
|
1419
|
+
), l = (u) => {
|
1420
|
+
var m, h;
|
1421
|
+
const f = [Se(u.node.attrs.language)];
|
1422
|
+
return o ? (f.push(
|
1423
|
+
D(((m = u.node.attrs.themes) == null ? void 0 : m.light) || o.light)
|
1424
|
+
), f.push(D(((h = u.node.attrs.themes) == null ? void 0 : h.dark) || o.dark))) : f.push(D(u.node.attrs.theme)), f;
|
1425
|
+
};
|
1371
1426
|
if ((await Promise.all(
|
1372
|
-
|
1373
|
-
ye(u.node.attrs.theme),
|
1374
|
-
we(u.node.attrs.language)
|
1375
|
-
])
|
1427
|
+
c.flatMap((u) => l(u))
|
1376
1428
|
)).includes(!0)) {
|
1377
|
-
const u =
|
1378
|
-
|
1429
|
+
const u = s.state.tr.setMeta("shikiPluginForceDecoration", !0);
|
1430
|
+
s.dispatch(u);
|
1379
1431
|
}
|
1380
1432
|
}
|
1381
1433
|
}
|
1382
|
-
return new
|
1434
|
+
return new a();
|
1383
1435
|
},
|
1384
1436
|
state: {
|
1385
|
-
init: (
|
1386
|
-
doc:
|
1437
|
+
init: (s, { doc: a }) => le({
|
1438
|
+
doc: a,
|
1387
1439
|
name: e,
|
1388
1440
|
defaultLanguage: t,
|
1389
|
-
defaultTheme: n
|
1441
|
+
defaultTheme: n,
|
1442
|
+
themes: o
|
1390
1443
|
}),
|
1391
|
-
apply: (
|
1392
|
-
const
|
1393
|
-
a.doc,
|
1394
|
-
(p) => p.type.name === e
|
1395
|
-
), d = F(
|
1444
|
+
apply: (s, a, i, c) => {
|
1445
|
+
const l = i.selection.$head.parent.type.name, p = c.selection.$head.parent.type.name, d = F(
|
1396
1446
|
i.doc,
|
1397
|
-
(
|
1398
|
-
),
|
1447
|
+
(m) => m.type.name === e
|
1448
|
+
), u = F(
|
1449
|
+
c.doc,
|
1450
|
+
(m) => m.type.name === e
|
1451
|
+
), f = s.docChanged && // Apply decorations if:
|
1399
1452
|
// selection includes named node,
|
1400
|
-
([
|
1401
|
-
|
1453
|
+
([l, p].includes(e) || // OR transaction adds/removes named node,
|
1454
|
+
u.length !== d.length || // OR transaction has changes that completely encapsulte a node
|
1402
1455
|
// (for example, a transaction that affects the entire document).
|
1403
1456
|
// Such transactions can happen during collab syncing via y-prosemirror, for example.
|
1404
|
-
|
1457
|
+
s.steps.some((m) => (
|
1405
1458
|
// @ts-ignore
|
1406
|
-
|
1407
|
-
|
1459
|
+
m.from !== void 0 && // @ts-ignore
|
1460
|
+
m.to !== void 0 && d.some((h) => (
|
1408
1461
|
// @ts-ignore
|
1409
|
-
|
1410
|
-
|
1462
|
+
h.pos >= m.from && // @ts-ignore
|
1463
|
+
h.pos + h.node.nodeSize <= m.to
|
1411
1464
|
))
|
1412
1465
|
)));
|
1413
|
-
return
|
1414
|
-
doc:
|
1466
|
+
return s.getMeta("shikiPluginForceDecoration") || f ? le({
|
1467
|
+
doc: s.doc,
|
1415
1468
|
name: e,
|
1416
1469
|
defaultLanguage: t,
|
1417
|
-
defaultTheme: n
|
1418
|
-
|
1470
|
+
defaultTheme: n,
|
1471
|
+
themes: o
|
1472
|
+
}) : a.map(s.mapping, s.doc);
|
1419
1473
|
}
|
1420
1474
|
},
|
1421
1475
|
props: {
|
1422
|
-
decorations(
|
1423
|
-
return
|
1476
|
+
decorations(s) {
|
1477
|
+
return r.getState(s);
|
1424
1478
|
}
|
1425
1479
|
}
|
1426
1480
|
});
|
1427
|
-
return
|
1481
|
+
return r;
|
1428
1482
|
}
|
1429
|
-
const
|
1483
|
+
const Ln = Tn.extend({
|
1430
1484
|
addOptions() {
|
1431
1485
|
var e;
|
1432
1486
|
return {
|
@@ -1439,15 +1493,16 @@ const Fn = Mn.extend({
|
|
1439
1493
|
var e;
|
1440
1494
|
return [
|
1441
1495
|
...((e = this.parent) == null ? void 0 : e.call(this)) || [],
|
1442
|
-
|
1496
|
+
Bn({
|
1443
1497
|
name: this.name,
|
1444
1498
|
defaultLanguage: this.options.defaultLanguage,
|
1445
|
-
defaultTheme: this.options.defaultTheme
|
1499
|
+
defaultTheme: this.options.defaultTheme,
|
1500
|
+
themes: this.options.themes
|
1446
1501
|
})
|
1447
1502
|
];
|
1448
1503
|
}
|
1449
1504
|
});
|
1450
1505
|
export {
|
1451
|
-
|
1452
|
-
|
1506
|
+
Ln as CodeBlockShiki,
|
1507
|
+
Ln as default
|
1453
1508
|
};
|