tiptap-extension-code-block-shiki 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,39 +1,39 @@
1
- import { Plugin as B, PluginKey as N, Selection as P, TextSelection as S, NodeSelection as ae } from "@tiptap/pm/state";
2
- import { DecorationSet as ge, Decoration as ke } from "@tiptap/pm/view";
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 F, Slice as ye, DOMParser as we } from "@tiptap/pm/model";
5
- import { liftTarget as xe, joinPoint as ce, canSplit as L, ReplaceStep as be, ReplaceAroundStep as Se, canJoin as le } from "@tiptap/pm/transform";
6
- import { createParagraphNear as Me, deleteSelection as Ae, exitCode as Te, joinUp as Ce, joinDown as ve, joinBackward as Ee, joinForward as Ie, joinTextblockBackward as $e, joinTextblockForward as Be, lift as Ne, liftEmptyBlock as Oe, newlineInCode as Pe, selectNodeBackward as je, selectNodeForward as Fe, selectParentNode as Le, selectTextblockEnd as Re, selectTextblockStart as ze, setBlockType as ee, wrapIn as De } from "@tiptap/pm/commands";
7
- import { liftListItem as We, sinkListItem as Ke, wrapInList as He } from "@tiptap/pm/schema-list";
8
- import { getHighlighter as Ve, bundledLanguages as _e, bundledThemes as Je } from "shiki";
9
- function de(t) {
10
- const { state: e, transaction: n } = t;
11
- let { selection: r } = n, { doc: o } = n, { storedMarks: s } = n;
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
- ...e,
14
- apply: e.apply.bind(e),
15
- applyTransaction: e.applyTransaction.bind(e),
16
- plugins: e.plugins,
17
- schema: e.schema,
18
- reconfigure: e.reconfigure.bind(e),
19
- toJSON: e.toJSON.bind(e),
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 r;
24
+ return o;
25
25
  },
26
26
  get doc() {
27
- return o;
27
+ return r;
28
28
  },
29
29
  get tr() {
30
- return r = n.selection, o = n.doc, s = n.storedMarks, n;
30
+ return o = n.selection, r = n.doc, s = n.storedMarks, n;
31
31
  }
32
32
  };
33
33
  }
34
- class Ge {
35
- constructor(e) {
36
- this.editor = e.editor, this.rawCommands = this.editor.extensionManager.commands, this.customState = e.state;
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: e, editor: n, state: r } = this, { view: o } = n, { tr: s } = r, i = this.buildProps(s);
46
- return Object.fromEntries(Object.entries(e).map(([a, c]) => [a, (...f) => {
47
- const l = c(...f)(i);
48
- return !s.getMeta("preventDispatch") && !this.hasCustomState && o.dispatch(s), l;
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(e, n = !0) {
58
- const { rawCommands: r, editor: o, state: s } = this, { view: i } = o, a = [], c = !!e, d = e || s.tr, f = () => (!c && n && !d.getMeta("preventDispatch") && !this.hasCustomState && i.dispatch(d), a.every((u) => u === !0)), l = {
59
- ...Object.fromEntries(Object.entries(r).map(([u, p]) => [u, (...h) => {
60
- const g = this.buildProps(d, n), k = p(...h)(g);
61
- return a.push(k), l;
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: f
63
+ run: u
64
64
  };
65
- return l;
65
+ return d;
66
66
  }
67
- createCan(e) {
68
- const { rawCommands: n, state: r } = this, o = !1, s = e || r.tr, i = this.buildProps(s, o);
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, d]) => [c, (...f) => d(...f)({ ...i, dispatch: void 0 })])),
71
- chain: () => this.createChain(s, o)
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(e, n = !0) {
75
- const { rawCommands: r, editor: o, state: s } = this, { view: i } = o, a = {
76
- tr: e,
77
- editor: o,
78
- view: i,
79
- state: de({
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: e
81
+ transaction: t
82
82
  }),
83
83
  dispatch: n ? () => {
84
84
  } : void 0,
85
- chain: () => this.createChain(e, n),
86
- can: () => this.createCan(e),
85
+ chain: () => this.createChain(t, n),
86
+ can: () => this.createCan(t),
87
87
  get commands() {
88
- return Object.fromEntries(Object.entries(r).map(([c, d]) => [c, (...f) => d(...f)(a)]));
88
+ return Object.fromEntries(Object.entries(o).map(([c, l]) => [c, (...u) => l(...u)(i)]));
89
89
  }
90
90
  };
91
- return a;
91
+ return i;
92
92
  }
93
93
  }
94
- function w(t, e, n) {
95
- return t.config[e] === void 0 && t.parent ? w(t.parent, e, n) : typeof t.config[e] == "function" ? t.config[e].bind({
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: t.parent ? w(t.parent, e, n) : null
98
- }) : t.config[e];
97
+ parent: e.parent ? w(e.parent, t, n) : null
98
+ }) : e.config[t];
99
99
  }
100
- function Ue(t) {
101
- const e = t.filter((o) => o.type === "extension"), n = t.filter((o) => o.type === "node"), r = t.filter((o) => o.type === "mark");
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: e,
103
+ baseExtensions: t,
104
104
  nodeExtensions: n,
105
- markExtensions: r
105
+ markExtensions: o
106
106
  };
107
107
  }
108
- function y(t, e) {
109
- if (typeof t == "string") {
110
- if (!e.nodes[t])
111
- throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);
112
- return e.nodes[t];
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 t;
114
+ return e;
115
115
  }
116
- function qe(...t) {
117
- return t.filter((e) => !!e).reduce((e, n) => {
118
- const r = { ...e };
119
- return Object.entries(n).forEach(([o, s]) => {
120
- if (!r[o]) {
121
- r[o] = s;
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 (o === "class") {
125
- const a = s ? s.split(" ") : [], c = r[o] ? r[o].split(" ") : [], d = a.filter((f) => !c.includes(f));
126
- r[o] = [...c, ...d].join(" ");
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
- o === "style" ? r[o] = [r[o], s].join("; ") : r[o] = s;
129
- }), r;
128
+ r === "style" ? o[r] = [o[r], s].join("; ") : o[r] = s;
129
+ }), o;
130
130
  }, {});
131
131
  }
132
- function Qe(t) {
133
- return typeof t == "function";
132
+ function Ye(e) {
133
+ return typeof e == "function";
134
134
  }
135
- function x(t, e = void 0, ...n) {
136
- return Qe(t) ? e ? t.bind(e)(...n) : t(...n) : t;
135
+ function x(e, t = void 0, ...n) {
136
+ return Ye(e) ? t ? e.bind(t)(...n) : e(...n) : e;
137
137
  }
138
- function Xe(t) {
139
- return Object.prototype.toString.call(t) === "[object RegExp]";
138
+ function Ze(e) {
139
+ return Object.prototype.toString.call(e) === "[object RegExp]";
140
140
  }
141
- class Ye {
142
- constructor(e) {
143
- this.find = e.find, this.handler = e.handler;
141
+ class et {
142
+ constructor(t) {
143
+ this.find = t.find, this.handler = t.handler;
144
144
  }
145
145
  }
146
- function Ze(t) {
147
- return Object.prototype.toString.call(t).slice(8, -1);
146
+ function tt(e) {
147
+ return Object.prototype.toString.call(e).slice(8, -1);
148
148
  }
149
- function H(t) {
150
- return Ze(t) !== "Object" ? !1 : t.constructor === Object && Object.getPrototypeOf(t) === Object.prototype;
149
+ function V(e) {
150
+ return tt(e) !== "Object" ? !1 : e.constructor === Object && Object.getPrototypeOf(e) === Object.prototype;
151
151
  }
152
- function Q(t, e) {
153
- const n = { ...t };
154
- return H(t) && H(e) && Object.keys(e).forEach((r) => {
155
- H(e[r]) ? r in t ? n[r] = Q(t[r], e[r]) : Object.assign(n, { [r]: e[r] }) : Object.assign(n, { [r]: e[r] });
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 T {
159
- constructor(e = {}) {
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
- ...e
166
- }, this.name = this.config.name, e.defaultOptions && Object.keys(e.defaultOptions).length > 0 && console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`), this.options = this.config.defaultOptions, this.config.addOptions && (this.options = x(w(this, "addOptions", {
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(e = {}) {
174
- return new T(e);
173
+ static create(t = {}) {
174
+ return new C(t);
175
175
  }
176
- configure(e = {}) {
176
+ configure(t = {}) {
177
177
  const n = this.extend();
178
- return n.options = Q(this.options, e), n.storage = x(w(n, "addStorage", {
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(e = {}) {
184
- const n = new T({ ...this.config, ...e });
185
- return n.parent = this, this.child = n, n.name = e.name ? e.name : n.parent.name, e.defaultOptions && console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`), n.options = x(w(n, "addOptions", {
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 et(t, e, n) {
194
- const { from: r, to: o } = e, { blockSeparator: s = `
193
+ function nt(e, t, n) {
194
+ const { from: o, to: r } = t, { blockSeparator: s = `
195
195
 
196
- `, textSerializers: i = {} } = n || {};
197
- let a = "", c = !0;
198
- return t.nodesBetween(r, o, (d, f, l, u) => {
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 = i == null ? void 0 : i[d.type.name];
200
+ const m = a == null ? void 0 : a[l.type.name];
201
201
  if (m)
202
- return d.isBlock && !c && (a += s, c = !0), l && (a += m({
203
- node: d,
204
- pos: f,
205
- parent: l,
206
- index: u,
207
- range: e
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
- d.isText ? (a += (p = d == null ? void 0 : d.text) === null || p === void 0 ? void 0 : p.slice(Math.max(r, f) - f, o - f), c = !1) : d.isBlock && !c && (a += s, c = !0);
210
- }), a;
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 tt(t) {
213
- return Object.fromEntries(Object.entries(t.nodes).filter(([, e]) => e.spec.toText).map(([e, n]) => [e, n.spec.toText]));
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
- T.create({
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 B({
224
+ new $({
225
225
  key: new N("clipboardTextSerializer"),
226
226
  props: {
227
227
  clipboardTextSerializer: () => {
228
- const { editor: t } = this, { state: e, schema: n } = t, { doc: r, selection: o } = e, { ranges: s } = o, i = Math.min(...s.map((f) => f.$from.pos)), a = Math.max(...s.map((f) => f.$to.pos)), c = tt(n);
229
- return et(r, { from: i, to: a }, {
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 nt = () => ({ editor: t, view: e }) => (requestAnimationFrame(() => {
239
+ const rt = () => ({ editor: e, view: t }) => (requestAnimationFrame(() => {
240
240
  var n;
241
- t.isDestroyed || (e.dom.blur(), (n = window == null ? void 0 : window.getSelection()) === null || n === void 0 || n.removeAllRanges());
242
- }), !0), rt = (t = !1) => ({ commands: e }) => e.setContent("", t), ot = () => ({ state: t, tr: e, dispatch: n }) => {
243
- const { selection: r } = e, { ranges: o } = r;
244
- return n && o.forEach(({ $from: s, $to: i }) => {
245
- t.doc.nodesBetween(s.pos, i.pos, (a, c) => {
246
- if (a.type.isText)
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: d, mapping: f } = e, l = d.resolve(f.map(c)), u = d.resolve(f.map(c + a.nodeSize)), p = l.blockRange(u);
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 = xe(p);
252
- if (a.type.isTextblock) {
253
- const { defaultType: h } = l.parent.contentMatchAt(l.index());
254
- e.setNodeMarkup(p.start, h);
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) && e.lift(p, m);
256
+ (m || m === 0) && t.lift(p, m);
257
257
  });
258
258
  }), !0;
259
- }, st = (t) => (e) => t(e), it = () => ({ state: t, dispatch: e }) => Me(t, e), at = (t, e) => ({ editor: n, tr: r }) => {
260
- const { state: o } = n, s = o.doc.slice(t.from, t.to);
261
- r.deleteRange(t.from, t.to);
262
- const i = r.mapping.map(e);
263
- return r.insert(i, s.content), r.setSelection(new S(r.doc.resolve(i - 1))), !0;
264
- }, ct = () => ({ tr: t, dispatch: e }) => {
265
- const { selection: n } = t, r = n.$anchor.node();
266
- if (r.content.size > 0)
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 o = t.selection.$anchor;
269
- for (let s = o.depth; s > 0; s -= 1)
270
- if (o.node(s).type === r.type) {
271
- if (e) {
272
- const a = o.before(s), c = o.after(s);
273
- t.delete(a, c).scrollIntoView();
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
- }, lt = (t) => ({ tr: e, state: n, dispatch: r }) => {
279
- const o = y(t, n.schema), s = e.selection.$anchor;
280
- for (let i = s.depth; i > 0; i -= 1)
281
- if (s.node(i).type === o) {
282
- if (r) {
283
- const c = s.before(i), d = s.after(i);
284
- e.delete(c, d).scrollIntoView();
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
- }, dt = (t) => ({ tr: e, dispatch: n }) => {
290
- const { from: r, to: o } = t;
291
- return n && e.delete(r, o), !0;
292
- }, ut = () => ({ state: t, dispatch: e }) => Ae(t, e), ft = () => ({ commands: t }) => t.keyboardShortcut("Enter"), pt = () => ({ state: t, dispatch: e }) => Te(t, e);
293
- function z(t, e, n = { strict: !0 }) {
294
- const r = Object.keys(e);
295
- return r.length ? r.every((o) => n.strict ? e[o] === t[o] : Xe(e[o]) ? e[o].test(t[o]) : e[o] === t[o]) : !0;
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 G(t, e, n = {}) {
298
- return t.find((r) => r.type === e && z(r.attrs, n));
297
+ function q(e, t, n = {}) {
298
+ return e.find((o) => o.type === t && z(o.attrs, n));
299
299
  }
300
- function mt(t, e, n = {}) {
301
- return !!G(t, e, n);
300
+ function gt(e, t, n = {}) {
301
+ return !!q(e, t, n);
302
302
  }
303
- function ue(t, e, n = {}) {
304
- if (!t || !e)
303
+ function pe(e, t, n = {}) {
304
+ if (!e || !t)
305
305
  return;
306
- let r = t.parent.childAfter(t.parentOffset);
307
- if (t.parentOffset === r.offset && r.offset !== 0 && (r = t.parent.childBefore(t.parentOffset)), !r.node)
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 o = G([...r.node.marks], e, n);
310
- if (!o)
309
+ const r = q([...o.node.marks], t, n);
310
+ if (!r)
311
311
  return;
312
- let s = r.index, i = t.start() + r.offset, a = s + 1, c = i + r.node.nodeSize;
313
- for (G([...r.node.marks], e, n); s > 0 && o.isInSet(t.parent.child(s - 1).marks); )
314
- s -= 1, i -= t.parent.child(s).nodeSize;
315
- for (; a < t.parent.childCount && mt([...t.parent.child(a).marks], e, n); )
316
- c += t.parent.child(a).nodeSize, a += 1;
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: i,
318
+ from: a,
319
319
  to: c
320
320
  };
321
321
  }
322
- function I(t, e) {
323
- if (typeof t == "string") {
324
- if (!e.marks[t])
325
- throw Error(`There is no mark type named '${t}'. Maybe you forgot to add the extension?`);
326
- return e.marks[t];
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 t;
328
+ return e;
329
329
  }
330
- const ht = (t, e = {}) => ({ tr: n, state: r, dispatch: o }) => {
331
- const s = I(t, r.schema), { doc: i, selection: a } = n, { $from: c, from: d, to: f } = a;
332
- if (o) {
333
- const l = ue(c, s, e);
334
- if (l && l.from <= d && l.to >= f) {
335
- const u = S.create(i, l.from, l.to);
336
- n.setSelection(u);
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
- }, gt = (t) => (e) => {
341
- const n = typeof t == "function" ? t(e) : t;
342
- for (let r = 0; r < n.length; r += 1)
343
- if (n[r](e))
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 fe(t) {
348
- return t instanceof S;
347
+ function me(e) {
348
+ return e instanceof b;
349
349
  }
350
- function $(t = 0, e = 0, n = 0) {
351
- return Math.min(Math.max(t, e), n);
350
+ function P(e = 0, t = 0, n = 0) {
351
+ return Math.min(Math.max(e, t), n);
352
352
  }
353
- function kt(t, e = null) {
354
- if (!e)
353
+ function wt(e, t = null) {
354
+ if (!t)
355
355
  return null;
356
- const n = P.atStart(t), r = P.atEnd(t);
357
- if (e === "start" || e === !0)
356
+ const n = O.atStart(e), o = O.atEnd(e);
357
+ if (t === "start" || t === !0)
358
358
  return n;
359
- if (e === "end")
360
- return r;
361
- const o = n.from, s = r.to;
362
- return e === "all" ? S.create(t, $(0, o, s), $(t.content.size, o, s)) : S.create(t, $(e, o, s), $(e, o, s));
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 yt = (t = null, e = {}) => ({ editor: n, view: r, tr: o, dispatch: s }) => {
375
- e = {
374
+ const xt = (e = null, t = {}) => ({ editor: n, view: o, tr: r, dispatch: s }) => {
375
+ t = {
376
376
  scrollIntoView: !0,
377
- ...e
377
+ ...t
378
378
  };
379
- const i = () => {
380
- X() && r.dom.focus(), requestAnimationFrame(() => {
381
- n.isDestroyed || (r.focus(), e != null && e.scrollIntoView && n.commands.scrollIntoView());
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 (r.hasFocus() && t === null || t === !1)
384
+ if (o.hasFocus() && e === null || e === !1)
385
385
  return !0;
386
- if (s && t === null && !fe(n.state.selection))
387
- return i(), !0;
388
- const a = kt(o.doc, t) || n.state.selection, c = n.state.selection.eq(a);
389
- return s && (c || o.setSelection(a), c && o.storedMarks && o.setStoredMarks(o.storedMarks), i()), !0;
390
- }, wt = (t, e) => (n) => t.every((r, o) => e(r, { ...n, index: o })), xt = (t, e) => ({ tr: n, commands: r }) => r.insertContentAt({ from: n.selection.from, to: n.selection.to }, t, e), pe = (t) => {
391
- const e = t.childNodes;
392
- for (let n = e.length - 1; n >= 0; n -= 1) {
393
- const r = e[n];
394
- r.nodeType === 3 && r.nodeValue && /^(\n\s\s|\n)$/.test(r.nodeValue) ? t.removeChild(r) : r.nodeType === 1 && pe(r);
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 t;
396
+ return e;
397
397
  };
398
- function te(t) {
399
- const e = `<body>${t}</body>`, n = new window.DOMParser().parseFromString(e, "text/html").body;
400
- return pe(n);
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 D(t, e, n) {
402
+ function W(e, t, n) {
403
403
  if (n = {
404
404
  slice: !0,
405
405
  parseOptions: {},
406
406
  ...n
407
- }, typeof t == "object" && t !== null)
407
+ }, typeof e == "object" && e !== null)
408
408
  try {
409
- return Array.isArray(t) && t.length > 0 ? F.fromArray(t.map((r) => e.nodeFromJSON(r))) : e.nodeFromJSON(t);
410
- } catch (r) {
411
- return console.warn("[tiptap warn]: Invalid content.", "Passed value:", t, "Error:", r), D("", e, n);
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 t == "string") {
414
- const r = we.fromSchema(e);
415
- return n.slice ? r.parseSlice(te(t), n.parseOptions).content : r.parse(te(t), n.parseOptions);
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 D("", e, n);
417
+ return W("", t, n);
418
418
  }
419
- function bt(t, e, n) {
420
- const r = t.steps.length - 1;
421
- if (r < e)
419
+ function Mt(e, t, n) {
420
+ const o = e.steps.length - 1;
421
+ if (o < t)
422
422
  return;
423
- const o = t.steps[r];
424
- if (!(o instanceof be || o instanceof Se))
423
+ const r = e.steps[o];
424
+ if (!(r instanceof Te || r instanceof Ce))
425
425
  return;
426
- const s = t.mapping.maps[r];
427
- let i = 0;
428
- s.forEach((a, c, d, f) => {
429
- i === 0 && (i = f);
430
- }), t.setSelection(P.near(t.doc.resolve(i), n));
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 St = (t) => t.toString().startsWith("<"), Mt = (t, e, n) => ({ tr: r, dispatch: o, editor: s }) => {
433
- if (o) {
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 i = D(e, s.schema, {
441
+ const a = W(t, s.schema, {
442
442
  parseOptions: {
443
443
  preserveWhitespace: "full",
444
444
  ...n.parseOptions
445
445
  }
446
446
  });
447
- if (i.toString() === "<>")
447
+ if (a.toString() === "<>")
448
448
  return !0;
449
- let { from: a, to: c } = typeof t == "number" ? { from: t, to: t } : { from: t.from, to: t.to }, d = !0, f = !0;
450
- if ((St(i) ? i : [i]).forEach((p) => {
451
- p.check(), d = d ? p.isText && p.marks.length === 0 : !1, f = f ? p.isBlock : !1;
452
- }), a === c && f) {
453
- const { parent: p } = r.doc.resolve(a);
454
- p.isTextblock && !p.type.spec.code && !p.childCount && (a -= 1, c += 1);
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 u;
457
- d ? (Array.isArray(e) ? u = e.map((p) => p.text || "").join("") : typeof e == "object" && e && e.text ? u = e.text : u = e, r.insertText(u, a, c)) : (u = i, r.replaceWith(a, c, u)), n.updateSelection && bt(r, r.steps.length - 1, -1), n.applyInputRules && r.setMeta("applyInputRules", { from: a, text: u }), n.applyPasteRules && r.setMeta("applyPasteRules", { from: a, text: u });
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
- }, At = () => ({ state: t, dispatch: e }) => Ce(t, e), Tt = () => ({ state: t, dispatch: e }) => ve(t, e), Ct = () => ({ state: t, dispatch: e }) => Ee(t, e), vt = () => ({ state: t, dispatch: e }) => Ie(t, e), Et = () => ({ tr: t, state: e, dispatch: n }) => {
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 r = ce(e.doc, e.selection.$from.pos, -1);
463
- return r == null ? !1 : (t.join(r, 2), n && n(t), !0);
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
- }, It = () => ({ state: t, dispatch: e, tr: n }) => {
467
+ }, Pt = () => ({ state: e, dispatch: t, tr: n }) => {
468
468
  try {
469
- const r = ce(t.doc, t.selection.$from.pos, 1);
470
- return r == null ? !1 : (n.join(r, 2), e && e(n), !0);
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: t, dispatch: e }) => $e(t, e), Bt = () => ({ state: t, dispatch: e }) => Be(t, e);
475
- function me() {
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 Nt(t) {
479
- const e = t.split(/-(?!$)/);
480
- let n = e[e.length - 1];
478
+ function Ot(e) {
479
+ const t = e.split(/-(?!$)/);
480
+ let n = t[t.length - 1];
481
481
  n === "Space" && (n = " ");
482
- let r, o, s, i;
483
- for (let a = 0; a < e.length - 1; a += 1) {
484
- const c = e[a];
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
- i = !0;
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() || me() ? i = !0 : o = !0;
494
+ X() || ge() ? a = !0 : r = !0;
495
495
  else
496
496
  throw new Error(`Unrecognized modifier name: ${c}`);
497
497
  }
498
- return r && (n = `Alt-${n}`), o && (n = `Ctrl-${n}`), i && (n = `Meta-${n}`), s && (n = `Shift-${n}`), n;
498
+ return o && (n = `Alt-${n}`), r && (n = `Ctrl-${n}`), a && (n = `Meta-${n}`), s && (n = `Shift-${n}`), n;
499
499
  }
500
- const Ot = (t) => ({ editor: e, view: n, tr: r, dispatch: o }) => {
501
- const s = Nt(t).split(/-(?!$)/), i = s.find((d) => !["Alt", "Ctrl", "Meta", "Shift"].includes(d)), a = new KeyboardEvent("keydown", {
502
- key: i === "Space" ? " " : i,
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 = e.captureTransaction(() => {
510
- n.someProp("handleKeyDown", (d) => d(n, a));
509
+ }), c = t.captureTransaction(() => {
510
+ n.someProp("handleKeyDown", (l) => l(n, i));
511
511
  });
512
- return c == null || c.steps.forEach((d) => {
513
- const f = d.map(r.mapping);
514
- f && o && r.maybeStep(f);
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(t, e, n = {}) {
518
- const { from: r, to: o, empty: s } = t.selection, i = e ? y(e, t.schema) : null, a = [];
519
- t.doc.nodesBetween(r, o, (l, u) => {
520
- if (l.isText)
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(r, u), m = Math.min(o, u + l.nodeSize);
523
- a.push({
524
- node: l,
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 = o - r, d = a.filter((l) => i ? i.name === l.node.type.name : !0).filter((l) => z(l.node.attrs, n, { strict: !1 }));
530
- return s ? !!d.length : d.reduce((l, u) => l + u.to - u.from, 0) >= c;
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 Pt = (t, e = {}) => ({ state: n, dispatch: r }) => {
533
- const o = y(t, n.schema);
534
- return Y(n, o, e) ? Ne(n, r) : !1;
535
- }, jt = () => ({ state: t, dispatch: e }) => Oe(t, e), Ft = (t) => ({ state: e, dispatch: n }) => {
536
- const r = y(t, e.schema);
537
- return We(r)(e, n);
538
- }, Lt = () => ({ state: t, dispatch: e }) => Pe(t, e);
539
- function he(t, e) {
540
- return e.nodes[t] ? "node" : e.marks[t] ? "mark" : null;
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(t, e) {
543
- const n = typeof e == "string" ? [e] : e;
544
- return Object.keys(t).reduce((r, o) => (n.includes(o) || (r[o] = t[o]), r), {});
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 Rt = (t, e) => ({ tr: n, state: r, dispatch: o }) => {
547
- let s = null, i = null;
548
- const a = he(typeof t == "string" ? t : t.name, r.schema);
549
- return a ? (a === "node" && (s = y(t, r.schema)), a === "mark" && (i = I(t, r.schema)), o && n.selection.ranges.forEach((c) => {
550
- r.doc.nodesBetween(c.$from.pos, c.$to.pos, (d, f) => {
551
- s && s === d.type && n.setNodeMarkup(f, void 0, ne(d.attrs, e)), i && d.marks.length && d.marks.forEach((l) => {
552
- i === l.type && n.addMark(f, f + d.nodeSize, i.create(ne(l.attrs, e)));
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
- }, zt = () => ({ tr: t, dispatch: e }) => (e && t.scrollIntoView(), !0), Dt = () => ({ tr: t, commands: e }) => e.setTextSelection({
556
+ }, Wt = () => ({ tr: e, dispatch: t }) => (t && e.scrollIntoView(), !0), Ht = () => ({ tr: e, commands: t }) => t.setTextSelection({
557
557
  from: 0,
558
- to: t.doc.content.size
559
- }), Wt = () => ({ state: t, dispatch: e }) => je(t, e), Kt = () => ({ state: t, dispatch: e }) => Fe(t, e), Ht = () => ({ state: t, dispatch: e }) => Le(t, e), Vt = () => ({ state: t, dispatch: e }) => Re(t, e), _t = () => ({ state: t, dispatch: e }) => ze(t, e);
560
- function Jt(t, e, n = {}) {
561
- return D(t, e, { slice: !1, parseOptions: n });
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 Gt = (t, e = !1, n = {}) => ({ tr: r, editor: o, dispatch: s }) => {
564
- const { doc: i } = r, a = Jt(t, o.schema, n);
565
- return s && r.replaceWith(0, i.content.size, a).setMeta("preventUpdate", !e), !0;
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 Ut(t, e) {
568
- const n = I(e, t.schema), { from: r, to: o, empty: s } = t.selection, i = [];
569
- s ? (t.storedMarks && i.push(...t.storedMarks), i.push(...t.selection.$head.marks())) : t.doc.nodesBetween(r, o, (c) => {
570
- i.push(...c.marks);
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 a = i.find((c) => c.type.name === n.name);
573
- return a ? { ...a.attrs } : {};
572
+ const i = a.find((c) => c.type.name === n.name);
573
+ return i ? { ...i.attrs } : {};
574
574
  }
575
- function qt(t) {
576
- for (let e = 0; e < t.edgeCount; e += 1) {
577
- const { type: n } = t.edge(e);
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 U(t, e) {
583
+ function F(e, t) {
584
584
  const n = [];
585
- return t.descendants((r, o) => {
586
- e(r) && n.push({
587
- node: r,
588
- pos: o
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 Qt(t, e) {
593
- for (let n = t.depth; n > 0; n -= 1) {
594
- const r = t.node(n);
595
- if (e(r))
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 ? t.before(n) : 0,
598
- start: t.start(n),
597
+ pos: n > 0 ? e.before(n) : 0,
598
+ start: e.start(n),
599
599
  depth: n,
600
- node: r
600
+ node: o
601
601
  };
602
602
  }
603
603
  }
604
- function Z(t) {
605
- return (e) => Qt(e.$from, t);
604
+ function Z(e) {
605
+ return (t) => Yt(t.$from, e);
606
606
  }
607
- function R(t, e, n) {
608
- return Object.fromEntries(Object.entries(n).filter(([r]) => {
609
- const o = t.find((s) => s.type === e && s.name === r);
610
- return o ? o.attribute.keepOnSplit : !1;
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 Xt(t, e, n = {}) {
614
- const { empty: r, ranges: o } = t.selection, s = e ? I(e, t.schema) : null;
615
- if (r)
616
- return !!(t.storedMarks || t.selection.$from.marks()).filter((l) => s ? s.name === l.type.name : !0).find((l) => z(l.attrs, n, { strict: !1 }));
617
- let i = 0;
618
- const a = [];
619
- if (o.forEach(({ $from: l, $to: u }) => {
620
- const p = l.pos, m = u.pos;
621
- t.doc.nodesBetween(p, m, (h, g) => {
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), C = Math.min(m, g + h.nodeSize), M = C - k;
625
- i += M, a.push(...h.marks.map((v) => ({
626
- mark: v,
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: C
628
+ to: E
629
629
  })));
630
630
  });
631
- }), i === 0)
631
+ }), a === 0)
632
632
  return !1;
633
- const c = a.filter((l) => s ? s.name === l.mark.type.name : !0).filter((l) => z(l.mark.attrs, n, { strict: !1 })).reduce((l, u) => l + u.to - u.from, 0), d = a.filter((l) => s ? l.mark.type !== s && l.mark.type.excludes(s) : !0).reduce((l, u) => l + u.to - u.from, 0);
634
- return (c > 0 ? c + d : c) >= i;
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 re(t, e) {
637
- const { nodeExtensions: n } = Ue(e), r = n.find((i) => i.name === t);
638
- if (!r)
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 o = {
641
- name: r.name,
642
- options: r.options,
643
- storage: r.storage
644
- }, s = x(w(r, "group", o));
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 Yt(t, e, n) {
648
- var r;
649
- const { selection: o } = e;
647
+ function en(e, t, n) {
648
+ var o;
649
+ const { selection: r } = t;
650
650
  let s = null;
651
- if (fe(o) && (s = o.$cursor), s) {
652
- const a = (r = t.storedMarks) !== null && r !== void 0 ? r : s.marks();
653
- return !!n.isInSet(a) || !a.some((c) => c.type.excludes(n));
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: i } = o;
656
- return i.some(({ $from: a, $to: c }) => {
657
- let d = a.depth === 0 ? t.doc.inlineContent && t.doc.type.allowsMarkType(n) : !1;
658
- return t.doc.nodesBetween(a.pos, c.pos, (f, l, u) => {
659
- if (d)
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 (f.isInline) {
662
- const p = !u || u.type.allowsMarkType(n), m = !!n.isInSet(f.marks) || !f.marks.some((h) => h.type.excludes(n));
663
- d = p && m;
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 !d;
666
- }), d;
665
+ return !l;
666
+ }), l;
667
667
  });
668
668
  }
669
- const Zt = (t, e = {}) => ({ tr: n, state: r, dispatch: o }) => {
670
- const { selection: s } = n, { empty: i, ranges: a } = s, c = I(t, r.schema);
671
- if (o)
672
- if (i) {
673
- const d = Ut(r, c);
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
- ...d,
676
- ...e
675
+ ...l,
676
+ ...t
677
677
  }));
678
678
  } else
679
- a.forEach((d) => {
680
- const f = d.$from.pos, l = d.$to.pos;
681
- r.doc.nodesBetween(f, l, (u, p) => {
682
- const m = Math.max(p, f), h = Math.min(p + u.nodeSize, l);
683
- u.marks.find((k) => k.type === c) ? u.marks.forEach((k) => {
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
- ...e
686
+ ...t
687
687
  }));
688
- }) : n.addMark(m, h, c.create(e));
688
+ }) : n.addMark(m, h, c.create(t));
689
689
  });
690
690
  });
691
- return Yt(r, n, c);
692
- }, en = (t, e) => ({ tr: n }) => (n.setMeta(t, e), !0), tn = (t, e = {}) => ({ state: n, dispatch: r, chain: o }) => {
693
- const s = y(t, n.schema);
694
- return s.isTextblock ? o().command(({ commands: i }) => ee(s, e)(n) ? !0 : i.clearNodes()).command(({ state: i }) => ee(s, e)(i, r)).run() : (console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'), !1);
695
- }, nn = (t) => ({ tr: e, dispatch: n }) => {
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: r } = e, o = $(t, 0, r.content.size), s = ae.create(r, o);
698
- e.setSelection(s);
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
- }, rn = (t) => ({ tr: e, dispatch: n }) => {
701
+ }, sn = (e) => ({ tr: t, dispatch: n }) => {
702
702
  if (n) {
703
- const { doc: r } = e, { from: o, to: s } = typeof t == "number" ? { from: t, to: t } : t, i = S.atStart(r).from, a = S.atEnd(r).to, c = $(o, i, a), d = $(s, i, a), f = S.create(r, c, d);
704
- e.setSelection(f);
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
- }, on = (t) => ({ state: e, dispatch: n }) => {
708
- const r = y(t, e.schema);
709
- return Ke(r)(e, n);
707
+ }, an = (e) => ({ state: t, dispatch: n }) => {
708
+ const o = y(e, t.schema);
709
+ return Je(o)(t, n);
710
710
  };
711
- function oe(t, e) {
712
- const n = t.storedMarks || t.selection.$to.parentOffset && t.selection.$from.marks();
711
+ function re(e, t) {
712
+ const n = e.storedMarks || e.selection.$to.parentOffset && e.selection.$from.marks();
713
713
  if (n) {
714
- const r = n.filter((o) => e == null ? void 0 : e.includes(o.type.name));
715
- t.tr.ensureMarks(r);
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 sn = ({ keepMarks: t = !0 } = {}) => ({ tr: e, state: n, dispatch: r, editor: o }) => {
719
- const { selection: s, doc: i } = e, { $from: a, $to: c } = s, d = o.extensionManager.attributes, f = R(d, a.node().type.name, a.node().attrs);
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 !a.parentOffset || !L(i, a.pos) ? !1 : (r && (t && oe(n, o.extensionManager.splittableMarks), e.split(a.pos).scrollIntoView()), !0);
722
- if (!a.parent.isBlock)
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 (r) {
725
- const l = c.parentOffset === c.parent.content.size;
726
- s instanceof S && e.deleteSelection();
727
- const u = a.depth === 0 ? void 0 : qt(a.node(-1).contentMatchAt(a.indexAfter(-1)));
728
- let p = l && u ? [
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: u,
731
- attrs: f
730
+ type: f,
731
+ attrs: u
732
732
  }
733
- ] : void 0, m = L(e.doc, e.mapping.map(a.pos), 1, p);
734
- if (!p && !m && L(e.doc, e.mapping.map(a.pos), 1, u ? [{ type: u }] : void 0) && (m = !0, p = u ? [
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: u,
737
- attrs: f
736
+ type: f,
737
+ attrs: u
738
738
  }
739
- ] : void 0), m && (e.split(e.mapping.map(a.pos), 1, p), u && !l && !a.parentOffset && a.parent.type !== u)) {
740
- const h = e.mapping.map(a.before()), g = e.doc.resolve(h);
741
- a.node(-1).canReplaceWith(g.index(), g.index() + 1, u) && e.setNodeMarkup(e.mapping.map(a.before()), u);
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
- t && oe(n, o.extensionManager.splittableMarks), e.scrollIntoView();
743
+ e && re(n, r.extensionManager.splittableMarks), t.scrollIntoView();
744
744
  }
745
745
  return !0;
746
- }, an = (t) => ({ tr: e, state: n, dispatch: r, editor: o }) => {
746
+ }, ln = (e) => ({ tr: t, state: n, dispatch: o, editor: r }) => {
747
747
  var s;
748
- const i = y(t, n.schema), { $from: a, $to: c } = n.selection, d = n.selection.node;
749
- if (d && d.isBlock || a.depth < 2 || !a.sameParent(c))
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 f = a.node(-1);
752
- if (f.type !== i)
751
+ const u = i.node(-1);
752
+ if (u.type !== a)
753
753
  return !1;
754
- const l = o.extensionManager.attributes;
755
- if (a.parent.content.size === 0 && a.node(-1).childCount === a.indexAfter(-1)) {
756
- if (a.depth === 2 || a.node(-3).type !== i || a.index(-2) !== a.node(-2).childCount - 1)
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 (r) {
759
- let g = F.empty;
760
- const k = a.index(-1) ? 1 : a.index(-2) ? 2 : 3;
761
- for (let E = a.depth - k; E >= a.depth - 3; E -= 1)
762
- g = F.from(a.node(E).copy(g));
763
- const C = a.indexAfter(-1) < a.node(-2).childCount ? 1 : a.indexAfter(-2) < a.node(-3).childCount ? 2 : 3, M = R(l, a.node().type.name, a.node().attrs), v = ((s = i.contentMatch.defaultType) === null || s === void 0 ? void 0 : s.createAndFill(M)) || void 0;
764
- g = g.append(F.from(i.createAndFill(null, v) || void 0));
765
- const b = a.before(a.depth - (k - 1));
766
- e.replace(b, a.after(-C), new ye(g, 4 - k, 0));
767
- let A = -1;
768
- e.doc.nodesBetween(b, e.doc.content.size, (E, K) => {
769
- if (A > -1)
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
- E.isTextblock && E.content.size === 0 && (A = K + 1);
772
- }), A > -1 && e.setSelection(S.near(e.doc.resolve(A))), e.scrollIntoView();
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 u = c.pos === a.end() ? f.contentMatchAt(0).defaultType : null, p = R(l, f.type.name, f.attrs), m = R(l, a.node().type.name, a.node().attrs);
777
- e.delete(a.pos, c.pos);
778
- const h = u ? [
779
- { type: i, attrs: p },
780
- { type: u, attrs: m }
781
- ] : [{ type: i, attrs: p }];
782
- if (!L(e.doc, a.pos, 2))
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 (r) {
785
- const { selection: g, storedMarks: k } = n, { splittableMarks: C } = o.extensionManager, M = k || g.$to.parentOffset && g.$from.marks();
786
- if (e.split(a.pos, 2, h).scrollIntoView(), !M || !r)
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 v = M.filter((b) => C.includes(b.type.name));
789
- e.ensureMarks(v);
788
+ const B = M.filter((S) => E.includes(S.type.name));
789
+ t.ensureMarks(B);
790
790
  }
791
791
  return !0;
792
- }, V = (t, e) => {
793
- const n = Z((i) => i.type === e)(t.selection);
792
+ }, _ = (e, t) => {
793
+ const n = Z((a) => a.type === t)(e.selection);
794
794
  if (!n)
795
795
  return !0;
796
- const r = t.doc.resolve(Math.max(0, n.pos - 1)).before(n.depth);
797
- if (r === void 0)
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 o = t.doc.nodeAt(r);
800
- return n.node.type === (o == null ? void 0 : o.type) && le(t.doc, n.pos) && t.join(n.pos), !0;
801
- }, _ = (t, e) => {
802
- const n = Z((i) => i.type === e)(t.selection);
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 r = t.doc.resolve(n.start).after(n.depth);
806
- if (r === void 0)
805
+ const o = e.doc.resolve(n.start).after(n.depth);
806
+ if (o === void 0)
807
807
  return !0;
808
- const o = t.doc.nodeAt(r);
809
- return n.node.type === (o == null ? void 0 : o.type) && le(t.doc, r) && t.join(r), !0;
810
- }, cn = (t, e, n, r = {}) => ({ editor: o, tr: s, state: i, dispatch: a, chain: c, commands: d, can: f }) => {
811
- const { extensions: l, splittableMarks: u } = o.extensionManager, p = y(t, i.schema), m = y(e, i.schema), { selection: h, storedMarks: g } = i, { $from: k, $to: C } = h, M = k.blockRange(C), v = g || h.$to.parentOffset && h.$from.marks();
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 b = Z((A) => re(A.type.name, l))(h);
815
- if (M.depth >= 1 && b && M.depth - b.depth <= 1) {
816
- if (b.node.type === p)
817
- return d.liftListItem(m);
818
- if (re(b.node.type.name, l) && p.validContent(b.node.content) && a)
819
- return c().command(() => (s.setNodeMarkup(b.pos, p), !0)).command(() => V(s, p)).command(() => _(s, p)).run();
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 || !v || !a ? c().command(() => f().wrapInList(p, r) ? !0 : d.clearNodes()).wrapInList(p, r).command(() => V(s, p)).command(() => _(s, p)).run() : c().command(() => {
822
- const A = f().wrapInList(p, r), E = v.filter((K) => u.includes(K.type.name));
823
- return s.ensureMarks(E), A ? !0 : d.clearNodes();
824
- }).wrapInList(p, r).command(() => V(s, p)).command(() => _(s, p)).run();
825
- }, ln = (t, e = {}, n = {}) => ({ state: r, commands: o }) => {
826
- const { extendEmptyMarkRange: s = !1 } = n, i = I(t, r.schema);
827
- return Xt(r, i, e) ? o.unsetMark(i, { extendEmptyMarkRange: s }) : o.setMark(i, e);
828
- }, dn = (t, e, n = {}) => ({ state: r, commands: o }) => {
829
- const s = y(t, r.schema), i = y(e, r.schema);
830
- return Y(r, s, n) ? o.setNode(i) : o.setNode(s, n);
831
- }, un = (t, e = {}) => ({ state: n, commands: r }) => {
832
- const o = y(t, n.schema);
833
- return Y(n, o, e) ? r.lift(o) : r.wrapIn(o, e);
834
- }, fn = () => ({ state: t, dispatch: e }) => {
835
- const n = t.plugins;
836
- for (let r = 0; r < n.length; r += 1) {
837
- const o = n[r];
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 (o.spec.isInputRules && (s = o.getState(t))) {
840
- if (e) {
841
- const i = t.tr, a = s.transform;
842
- for (let c = a.steps.length - 1; c >= 0; c -= 1)
843
- i.step(a.steps[c].invert(a.docs[c]));
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 = i.doc.resolve(s.from).marks();
846
- i.replaceWith(s.from, s.to, t.schema.text(s.text, c));
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
- i.delete(s.from, s.to);
848
+ a.delete(s.from, s.to);
849
849
  }
850
850
  return !0;
851
851
  }
852
852
  }
853
853
  return !1;
854
- }, pn = () => ({ tr: t, dispatch: e }) => {
855
- const { selection: n } = t, { empty: r, ranges: o } = n;
856
- return r || e && o.forEach((s) => {
857
- t.removeMark(s.$from.pos, s.$to.pos);
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
- }, mn = (t, e = {}) => ({ tr: n, state: r, dispatch: o }) => {
859
+ }, gn = (e, t = {}) => ({ tr: n, state: o, dispatch: r }) => {
860
860
  var s;
861
- const { extendEmptyMarkRange: i = !1 } = e, { selection: a } = n, c = I(t, r.schema), { $from: d, empty: f, ranges: l } = a;
862
- if (!o)
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 (f && i) {
865
- let { from: u, to: p } = a;
866
- const m = (s = d.marks().find((g) => g.type === c)) === null || s === void 0 ? void 0 : s.attrs, h = ue(d, c, m);
867
- h && (u = h.from, p = h.to), n.removeMark(u, p, c);
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
- l.forEach((u) => {
870
- n.removeMark(u.$from.pos, u.$to.pos, c);
869
+ d.forEach((f) => {
870
+ n.removeMark(f.$from.pos, f.$to.pos, c);
871
871
  });
872
872
  return n.removeStoredMark(c), !0;
873
- }, hn = (t, e = {}) => ({ tr: n, state: r, dispatch: o }) => {
874
- let s = null, i = null;
875
- const a = he(typeof t == "string" ? t : t.name, r.schema);
876
- return a ? (a === "node" && (s = y(t, r.schema)), a === "mark" && (i = I(t, r.schema)), o && n.selection.ranges.forEach((c) => {
877
- const d = c.$from.pos, f = c.$to.pos;
878
- r.doc.nodesBetween(d, f, (l, u) => {
879
- s && s === l.type && n.setNodeMarkup(u, void 0, {
880
- ...l.attrs,
881
- ...e
882
- }), i && l.marks.length && l.marks.forEach((p) => {
883
- if (i === p.type) {
884
- const m = Math.max(u, d), h = Math.min(u + l.nodeSize, f);
885
- n.addMark(m, h, i.create({
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
- ...e
887
+ ...t
888
888
  }));
889
889
  }
890
890
  });
891
891
  });
892
892
  }), !0) : !1;
893
- }, gn = (t, e = {}) => ({ state: n, dispatch: r }) => {
894
- const o = y(t, n.schema);
895
- return De(o, e)(n, r);
896
- }, kn = (t, e = {}) => ({ state: n, dispatch: r }) => {
897
- const o = y(t, n.schema);
898
- return He(o, e)(n, r);
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 yn = /* @__PURE__ */ Object.freeze({
900
+ var xn = /* @__PURE__ */ Object.freeze({
901
901
  __proto__: null,
902
- blur: nt,
903
- clearContent: rt,
904
- clearNodes: ot,
905
- command: st,
906
- createParagraphNear: it,
907
- cut: at,
908
- deleteCurrentNode: ct,
909
- deleteNode: lt,
910
- deleteRange: dt,
911
- deleteSelection: ut,
912
- enter: ft,
913
- exitCode: pt,
914
- extendMarkRange: ht,
915
- first: gt,
916
- focus: yt,
917
- forEach: wt,
918
- insertContent: xt,
919
- insertContentAt: Mt,
920
- joinUp: At,
921
- joinDown: Tt,
922
- joinBackward: Ct,
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: Et,
925
- joinItemForward: It,
924
+ joinItemBackward: It,
925
+ joinItemForward: Pt,
926
926
  joinTextblockBackward: $t,
927
- joinTextblockForward: Bt,
928
- keyboardShortcut: Ot,
929
- lift: Pt,
930
- liftEmptyBlock: jt,
931
- liftListItem: Ft,
932
- newlineInCode: Lt,
933
- resetAttributes: Rt,
934
- scrollIntoView: zt,
935
- selectAll: Dt,
936
- selectNodeBackward: Wt,
937
- selectNodeForward: Kt,
938
- selectParentNode: Ht,
939
- selectTextblockEnd: Vt,
940
- selectTextblockStart: _t,
941
- setContent: Gt,
942
- setMark: Zt,
943
- setMeta: en,
944
- setNode: tn,
945
- setNodeSelection: nn,
946
- setTextSelection: rn,
947
- sinkListItem: on,
948
- splitBlock: sn,
949
- splitListItem: an,
950
- toggleList: cn,
951
- toggleMark: ln,
952
- toggleNode: dn,
953
- toggleWrap: un,
954
- undoInputRule: fn,
955
- unsetAllMarks: pn,
956
- unsetMark: mn,
957
- updateAttributes: hn,
958
- wrapIn: gn,
959
- wrapInList: kn
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
- T.create({
961
+ C.create({
962
962
  name: "commands",
963
963
  addCommands() {
964
964
  return {
965
- ...yn
965
+ ...xn
966
966
  };
967
967
  }
968
968
  });
969
- T.create({
969
+ C.create({
970
970
  name: "editable",
971
971
  addProseMirrorPlugins() {
972
972
  return [
973
- new B({
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
- T.create({
982
+ C.create({
983
983
  name: "focusEvents",
984
984
  addProseMirrorPlugins() {
985
- const { editor: t } = this;
985
+ const { editor: e } = this;
986
986
  return [
987
- new B({
987
+ new $({
988
988
  key: new N("focusEvents"),
989
989
  props: {
990
990
  handleDOMEvents: {
991
- focus: (e, n) => {
992
- t.isFocused = !0;
993
- const r = t.state.tr.setMeta("focus", { event: n }).setMeta("addToHistory", !1);
994
- return e.dispatch(r), !1;
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: (e, n) => {
997
- t.isFocused = !1;
998
- const r = t.state.tr.setMeta("blur", { event: n }).setMeta("addToHistory", !1);
999
- return e.dispatch(r), !1;
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
- T.create({
1007
+ C.create({
1008
1008
  name: "keymap",
1009
1009
  addKeyboardShortcuts() {
1010
- const t = () => this.editor.commands.first(({ commands: i }) => [
1011
- () => i.undoInputRule(),
1010
+ const e = () => this.editor.commands.first(({ commands: a }) => [
1011
+ () => a.undoInputRule(),
1012
1012
  // maybe convert first text block node to default node
1013
- () => i.command(({ tr: a }) => {
1014
- const { selection: c, doc: d } = a, { empty: f, $anchor: l } = c, { pos: u, parent: p } = l, m = l.parent.isTextblock && u > 0 ? a.doc.resolve(u - 1) : l, h = m.parent.type.spec.isolating, g = l.pos - l.parentOffset, k = h && m.parent.childCount === 1 ? g === l.pos : P.atStart(d).from === u;
1015
- return !f || !k || !p.type.isTextblock || p.textContent.length ? !1 : i.clearNodes();
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
- () => i.deleteSelection(),
1018
- () => i.joinBackward(),
1019
- () => i.selectNodeBackward()
1020
- ]), e = () => this.editor.commands.first(({ commands: i }) => [
1021
- () => i.deleteSelection(),
1022
- () => i.deleteCurrentNode(),
1023
- () => i.joinForward(),
1024
- () => i.selectNodeForward()
1025
- ]), r = {
1026
- Enter: () => this.editor.commands.first(({ commands: i }) => [
1027
- () => i.newlineInCode(),
1028
- () => i.createParagraphNear(),
1029
- () => i.liftEmptyBlock(),
1030
- () => i.splitBlock()
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: t,
1034
- "Mod-Backspace": t,
1035
- "Shift-Backspace": t,
1036
- Delete: e,
1037
- "Mod-Delete": e,
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
- }, o = {
1040
- ...r
1039
+ }, r = {
1040
+ ...o
1041
1041
  }, s = {
1042
- ...r,
1043
- "Ctrl-h": t,
1044
- "Alt-Backspace": t,
1045
- "Ctrl-d": e,
1046
- "Ctrl-Alt-Backspace": e,
1047
- "Alt-Delete": e,
1048
- "Alt-d": e,
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() || me() ? s : o;
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 B({
1061
+ new $({
1062
1062
  key: new N("clearDocument"),
1063
- appendTransaction: (t, e, n) => {
1064
- if (!(t.some((m) => m.docChanged) && !e.doc.eq(n.doc)))
1063
+ appendTransaction: (e, t, n) => {
1064
+ if (!(e.some((m) => m.docChanged) && !t.doc.eq(n.doc)))
1065
1065
  return;
1066
- const { empty: o, from: s, to: i } = e.selection, a = P.atStart(e.doc).from, c = P.atEnd(e.doc).to;
1067
- if (o || !(s === a && i === c) || !(n.doc.textBetween(0, n.doc.content.size, " ", " ").length === 0))
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 l = n.tr, u = de({
1069
+ const d = n.tr, f = fe({
1070
1070
  state: n,
1071
- transaction: l
1072
- }), { commands: p } = new Ge({
1071
+ transaction: d
1072
+ }), { commands: p } = new qe({
1073
1073
  editor: this.editor,
1074
- state: u
1074
+ state: f
1075
1075
  });
1076
- if (p.clearNodes(), !!l.steps.length)
1077
- return l;
1076
+ if (p.clearNodes(), !!d.steps.length)
1077
+ return d;
1078
1078
  }
1079
1079
  })
1080
1080
  ];
1081
1081
  }
1082
1082
  });
1083
- T.create({
1083
+ C.create({
1084
1084
  name: "tabindex",
1085
1085
  addProseMirrorPlugins() {
1086
1086
  return [
1087
- new B({
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(t) {
1097
- return new Ye({
1098
- find: t.find,
1099
- handler: ({ state: e, range: n, match: r }) => {
1100
- const o = e.doc.resolve(n.from), s = x(t.getAttributes, void 0, r) || {};
1101
- if (!o.node(-1).canReplaceWith(o.index(-1), o.indexAfter(-1), t.type))
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
- e.tr.delete(n.from, n.to).setBlockType(n.from, n.from, t.type, s);
1103
+ t.tr.delete(n.from, n.to).setBlockType(n.from, n.from, e.type, s);
1104
1104
  }
1105
1105
  });
1106
1106
  }
1107
- class W {
1108
- constructor(e = {}) {
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
- ...e
1115
- }, this.name = this.config.name, e.defaultOptions && Object.keys(e.defaultOptions).length > 0 && console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`), this.options = this.config.defaultOptions, this.config.addOptions && (this.options = x(w(this, "addOptions", {
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(e = {}) {
1123
- return new W(e);
1122
+ static create(t = {}) {
1123
+ return new H(t);
1124
1124
  }
1125
- configure(e = {}) {
1125
+ configure(t = {}) {
1126
1126
  const n = this.extend();
1127
- return n.options = Q(this.options, e), n.storage = x(w(n, "addStorage", {
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(e = {}) {
1133
- const n = new W({ ...this.config, ...e });
1134
- return n.parent = this, this.child = n, n.name = e.name ? e.name : n.parent.name, e.defaultOptions && console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`), n.options = x(w(n, "addOptions", {
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 wn = /^```([a-z]+)?[\s\n]$/, xn = /^~~~([a-z]+)?[\s\n]$/, bn = W.create({
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: (t) => {
1162
- var e;
1163
- const { languageClassPrefix: n } = this.options, s = [...((e = t.firstElementChild) === null || e === void 0 ? void 0 : e.classList) || []].filter((i) => i.startsWith(n)).map((i) => i.replace(n, ""))[0];
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: t, HTMLAttributes: e }) {
1178
+ renderHTML({ node: e, HTMLAttributes: t }) {
1179
1179
  return [
1180
1180
  "pre",
1181
- qe(this.options.HTMLAttributes, e),
1181
+ Xe(this.options.HTMLAttributes, t),
1182
1182
  [
1183
1183
  "code",
1184
1184
  {
1185
- class: t.attrs.language ? this.options.languageClassPrefix + t.attrs.language : null
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: (t) => ({ commands: e }) => e.setNode(this.name, t),
1194
- toggleCodeBlock: (t) => ({ commands: e }) => e.toggleNode(this.name, "paragraph", t)
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: t, $anchor: e } = this.editor.state.selection, n = e.pos === 1;
1203
- return !t || e.parent.type.name !== this.name ? !1 : n || !e.parent.textContent.length ? this.editor.commands.clearNodes() : !1;
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: t }) => {
1206
+ Enter: ({ editor: e }) => {
1207
1207
  if (!this.options.exitOnTripleEnter)
1208
1208
  return !1;
1209
- const { state: e } = t, { selection: n } = e, { $from: r, empty: o } = n;
1210
- if (!o || r.parent.type !== this.type)
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 = r.parentOffset === r.parent.nodeSize - 2, i = r.parent.textContent.endsWith(`
1212
+ const s = o.parentOffset === o.parent.nodeSize - 2, a = o.parent.textContent.endsWith(`
1213
1213
 
1214
1214
  `);
1215
- return !s || !i ? !1 : t.chain().command(({ tr: a }) => (a.delete(r.pos - 2, r.pos), !0)).exitCode().run();
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: t }) => {
1218
+ ArrowDown: ({ editor: e }) => {
1219
1219
  if (!this.options.exitOnArrowDown)
1220
1220
  return !1;
1221
- const { state: e } = t, { selection: n, doc: r } = e, { $from: o, empty: s } = n;
1222
- if (!s || o.parent.type !== this.type || !(o.parentOffset === o.parent.nodeSize - 2))
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 a = o.after();
1225
- return a === void 0 || r.nodeAt(a) ? !1 : t.commands.exitCode();
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: wn,
1232
+ find: Sn,
1233
1233
  type: this.type,
1234
- getAttributes: (t) => ({
1235
- language: t[1]
1234
+ getAttributes: (e) => ({
1235
+ language: e[1]
1236
1236
  })
1237
1237
  }),
1238
1238
  se({
1239
- find: xn,
1239
+ find: bn,
1240
1240
  type: this.type,
1241
- getAttributes: (t) => ({
1242
- language: t[1]
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 B({
1251
+ new $({
1252
1252
  key: new N("codeBlockVSCodeHandler"),
1253
1253
  props: {
1254
- handlePaste: (t, e) => {
1255
- if (!e.clipboardData || this.editor.isActive(this.type.name))
1254
+ handlePaste: (e, t) => {
1255
+ if (!t.clipboardData || this.editor.isActive(this.type.name))
1256
1256
  return !1;
1257
- const n = e.clipboardData.getData("text/plain"), r = e.clipboardData.getData("vscode-editor-data"), o = r ? JSON.parse(r) : void 0, s = o == null ? void 0 : o.mode;
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: i } = t.state;
1261
- return i.replaceSelectionWith(this.type.create({ language: s })), i.setSelection(S.near(i.doc.resolve(Math.max(0, i.selection.from - 2)))), i.insertText(n.replace(/\r\n?/g, `
1262
- `)), i.setMeta("paste", !0), t.dispatch(i), !0;
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 j, O;
1270
- const q = /* @__PURE__ */ new Set(), J = /* @__PURE__ */ new Set(), Sn = (t) => {
1271
- if (!j)
1272
- return j = Ve({
1273
- themes: [t.defaultTheme],
1274
- langs: []
1275
- }).then((r) => {
1276
- J.add(t.defaultTheme), O = r;
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
- if (!O)
1284
+ }
1285
+ if (j)
1279
1286
  return j;
1280
- const e = t.language;
1281
- if (e && !q.has(e) && e in _e)
1282
- return O.loadLanguage(e).then(() => {
1283
- q.add(e);
1284
- });
1285
- const n = t.theme;
1286
- if (n && !J.has(n) && n in Je)
1287
- return O.loadTheme(n).then(() => {
1288
- J.add(n);
1289
- });
1290
- };
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.forEach((i) => ye(i)),
1309
+ a.forEach((i) => !!i && we(i))
1310
+ ]) : await Tn({ languages: a, themes: s });
1311
+ }
1291
1312
  function ie({
1292
- doc: t,
1293
- name: e,
1294
- defaultLanguage: n,
1295
- defaultTheme: r
1313
+ doc: e,
1314
+ name: t,
1315
+ defaultTheme: n,
1316
+ defaultLanguage: o
1296
1317
  }) {
1297
- const o = [];
1298
- return U(t, (s) => s.type.name === e).forEach((s) => {
1299
- let i = s.pos + 1, a = s.node.attrs.language || n, c = s.node.attrs.theme || r;
1300
- if (Sn({ language: a, theme: c, defaultTheme: r }), q.has(a) || (a = "plaintext"), !O)
1301
- return s.node;
1302
- const d = O.codeToTokensBase(s.node.textContent, {
1303
- lang: a,
1304
- theme: c
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 f of d) {
1307
- for (const l of f) {
1308
- const u = i + l.content.length, p = ke.inline(i, u, {
1309
- style: `color: ${l.color}`
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
- o.push(p), i = u;
1334
+ r.push(g), i = h;
1312
1335
  }
1313
1336
  i += 1;
1314
1337
  }
1315
- }), ge.create(t, o);
1338
+ }), xe.create(e, r);
1316
1339
  }
1317
- function Mn({
1318
- name: t,
1319
- defaultLanguage: e,
1340
+ function En({
1341
+ name: e,
1342
+ defaultLanguage: t,
1320
1343
  defaultTheme: n
1321
1344
  }) {
1322
- const r = new B({
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: (o, { doc: s }) => ie({
1385
+ init: (r, { doc: s }) => ie({
1326
1386
  doc: s,
1327
- name: t,
1328
- defaultLanguage: e,
1387
+ name: e,
1388
+ defaultLanguage: t,
1329
1389
  defaultTheme: n
1330
1390
  }),
1331
- apply: (o, s, i, a) => {
1332
- const c = i.selection.$head.parent.type.name, d = a.selection.$head.parent.type.name, f = U(
1333
- i.doc,
1334
- (u) => u.type.name === t
1335
- ), l = U(
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
- (u) => u.type.name === t
1338
- );
1339
- return o.docChanged && // Apply decorations if:
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, d].includes(t) || // OR transaction adds/removes named node,
1342
- l.length !== f.length || // OR transaction has changes that completely encapsulte a node
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
- o.steps.some((u) => (
1404
+ r.steps.some((p) => (
1346
1405
  // @ts-ignore
1347
- u.from !== void 0 && // @ts-ignore
1348
- u.to !== void 0 && f.some((p) => (
1406
+ p.from !== void 0 && // @ts-ignore
1407
+ p.to !== void 0 && u.some((m) => (
1349
1408
  // @ts-ignore
1350
- p.pos >= u.from && // @ts-ignore
1351
- p.pos + p.node.nodeSize <= u.to
1409
+ m.pos >= p.from && // @ts-ignore
1410
+ m.pos + m.node.nodeSize <= p.to
1352
1411
  ))
1353
- ))) ? ie({
1354
- doc: o.doc,
1355
- name: t,
1356
- defaultLanguage: e,
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(o.mapping, o.doc);
1418
+ }) : s.map(r.mapping, r.doc);
1359
1419
  }
1360
1420
  },
1361
1421
  props: {
1362
- decorations(o) {
1363
- return r.getState(o);
1422
+ decorations(r) {
1423
+ return o.getState(r);
1364
1424
  }
1365
1425
  }
1366
1426
  });
1367
- return r;
1427
+ return o;
1368
1428
  }
1369
- const Nn = bn.extend({
1429
+ const Fn = Mn.extend({
1370
1430
  addOptions() {
1371
- var t;
1431
+ var e;
1372
1432
  return {
1373
- ...(t = this.parent) == null ? void 0 : t.call(this),
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 t;
1439
+ var e;
1380
1440
  return [
1381
- ...((t = this.parent) == null ? void 0 : t.call(this)) || [],
1382
- Mn({
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
- Nn as CodeBlockShiki,
1392
- Nn as default
1451
+ Fn as CodeBlockShiki,
1452
+ Fn as default
1393
1453
  };