@blocknote/core 0.5.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocknote.js +1126 -1031
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +2 -2
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +2 -2
- package/src/BlockNoteEditor.ts +246 -4
- package/src/BlockNoteExtensions.ts +3 -2
- package/src/api/blockManipulation/__snapshots__/blockManipulation.test.ts.snap +35 -35
- package/src/api/formatConversions/__snapshots__/formatConversions.test.ts.snap +10 -10
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +10 -10
- package/src/api/nodeConversions/nodeConversions.ts +11 -10
- package/src/editor.module.css +11 -2
- package/src/extensions/Blocks/api/inlineContentTypes.ts +3 -2
- package/src/extensions/Blocks/api/selectionTypes.ts +5 -0
- package/src/extensions/Blocks/nodes/Block.module.css +20 -2
- package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +5 -6
- package/src/extensions/DraggableBlocks/DraggableBlocksExtension.ts +5 -2
- package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +76 -113
- package/src/extensions/FormattingToolbar/FormattingToolbarExtension.ts +6 -3
- package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +2 -34
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +39 -113
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +56 -39
- package/src/extensions/UniqueID/UniqueID.ts +1 -1
- package/src/index.ts +1 -0
- package/src/shared/plugins/suggestion/SuggestionPlugin.ts +14 -2
- package/types/src/BlockNoteEditor.d.ts +81 -1
- package/types/src/extensions/Blocks/api/inlineContentTypes.d.ts +3 -2
- package/types/src/extensions/Blocks/api/selectionTypes.d.ts +4 -0
- package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +4 -5
- package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +3 -1
- package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +14 -16
- package/types/src/extensions/FormattingToolbar/FormattingToolbarExtension.d.ts +2 -0
- package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +2 -25
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +9 -4
- package/types/src/index.d.ts +1 -0
- package/types/src/api/Editor.d.ts +0 -93
- package/types/src/extensions/SlashMenu/SlashMenuItem.d.ts +0 -24
- package/types/src/extensions/SlashMenu/defaultSlashCommands.d.ts +0 -5
package/dist/blocknote.js
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { Extension as
|
|
5
|
-
import { Slice as
|
|
6
|
-
import { Plugin as
|
|
7
|
-
import { v4 as
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import { unified as
|
|
1
|
+
var Et = Object.defineProperty;
|
|
2
|
+
var Ct = (o, t, e) => t in o ? Et(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
3
|
+
var u = (o, t, e) => (Ct(o, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
+
import { Extension as E, findChildren as $, combineTransactionSteps as Mt, getChangedRanges as Bt, findChildrenInRange as Tt, Mark as rt, Node as S, mergeAttributes as w, InputRule as W, findParentNode as wt, isTextSelection as St, isNodeSelection as xt, posToDOMRect as nt, getMarkRange as X, extensions as H, Editor as It } from "@tiptap/core";
|
|
5
|
+
import { Slice as P, Fragment as L, DOMSerializer as Pt, DOMParser as Lt } from "prosemirror-model";
|
|
6
|
+
import { Plugin as C, PluginKey as v, TextSelection as Q, Selection as G, NodeSelection as At } from "prosemirror-state";
|
|
7
|
+
import { v4 as Ht } from "uuid";
|
|
8
|
+
import it from "rehype-parse";
|
|
9
|
+
import Nt from "rehype-remark";
|
|
10
|
+
import st from "rehype-stringify";
|
|
11
|
+
import at from "remark-gfm";
|
|
12
|
+
import _t from "remark-parse";
|
|
13
|
+
import Ot from "remark-rehype";
|
|
14
|
+
import Dt from "remark-stringify";
|
|
15
|
+
import { unified as j } from "unified";
|
|
16
16
|
import { fromDom as Z } from "hast-util-from-dom";
|
|
17
|
-
import { Bold as
|
|
18
|
-
import { Code as
|
|
19
|
-
import { Dropcursor as
|
|
20
|
-
import { Gapcursor as
|
|
21
|
-
import { HardBreak as
|
|
22
|
-
import { History as $
|
|
23
|
-
import { Italic as
|
|
24
|
-
import { Link as
|
|
25
|
-
import { Strike as
|
|
26
|
-
import { Text as
|
|
27
|
-
import { Underline as
|
|
28
|
-
import * as
|
|
17
|
+
import { Bold as Ft } from "@tiptap/extension-bold";
|
|
18
|
+
import { Code as Rt } from "@tiptap/extension-code";
|
|
19
|
+
import { Dropcursor as zt } from "@tiptap/extension-dropcursor";
|
|
20
|
+
import { Gapcursor as Ut } from "@tiptap/extension-gapcursor";
|
|
21
|
+
import { HardBreak as Gt } from "@tiptap/extension-hard-break";
|
|
22
|
+
import { History as $t } from "@tiptap/extension-history";
|
|
23
|
+
import { Italic as qt } from "@tiptap/extension-italic";
|
|
24
|
+
import { Link as dt } from "@tiptap/extension-link";
|
|
25
|
+
import { Strike as Wt } from "@tiptap/extension-strike";
|
|
26
|
+
import { Text as jt } from "@tiptap/extension-text";
|
|
27
|
+
import { Underline as Yt } from "@tiptap/extension-underline";
|
|
28
|
+
import * as Kt from "prosemirror-view";
|
|
29
29
|
import { Decoration as D, DecorationSet as F } from "prosemirror-view";
|
|
30
|
-
const
|
|
30
|
+
const _ = [
|
|
31
31
|
"backgroundColor",
|
|
32
32
|
"textColor",
|
|
33
33
|
"textAlignment"
|
|
34
|
-
],
|
|
35
|
-
paragraph: /* @__PURE__ */ new Set([...
|
|
34
|
+
], tt = {
|
|
35
|
+
paragraph: /* @__PURE__ */ new Set([..._]),
|
|
36
36
|
heading: /* @__PURE__ */ new Set([
|
|
37
|
-
...
|
|
37
|
+
..._,
|
|
38
38
|
"level"
|
|
39
39
|
]),
|
|
40
40
|
numberedListItem: /* @__PURE__ */ new Set([
|
|
41
|
-
...
|
|
41
|
+
..._
|
|
42
42
|
]),
|
|
43
|
-
bulletListItem: /* @__PURE__ */ new Set([...
|
|
43
|
+
bulletListItem: /* @__PURE__ */ new Set([..._])
|
|
44
44
|
};
|
|
45
|
-
function
|
|
46
|
-
if (
|
|
45
|
+
function g(o, t) {
|
|
46
|
+
if (t < 0 || t > o.nodeSize)
|
|
47
47
|
return;
|
|
48
|
-
const
|
|
49
|
-
let
|
|
48
|
+
const e = o.resolve(t), r = e.depth;
|
|
49
|
+
let n = e.node(r), i = r;
|
|
50
50
|
for (; ; ) {
|
|
51
51
|
if (i < 0)
|
|
52
52
|
return;
|
|
53
|
-
if (
|
|
53
|
+
if (n.type.name === "blockContainer")
|
|
54
54
|
break;
|
|
55
|
-
i -= 1,
|
|
55
|
+
i -= 1, n = e.node(i);
|
|
56
56
|
}
|
|
57
|
-
const a =
|
|
57
|
+
const a = n.attrs.id, s = n.firstChild, d = s.type, l = n.childCount === 2 ? n.lastChild.childCount : 0, c = e.start(i), h = e.end(i);
|
|
58
58
|
return {
|
|
59
59
|
id: a,
|
|
60
|
-
node:
|
|
60
|
+
node: n,
|
|
61
61
|
contentNode: s,
|
|
62
62
|
contentType: d,
|
|
63
63
|
numChildBlocks: l,
|
|
64
64
|
startPos: c,
|
|
65
|
-
endPos:
|
|
65
|
+
endPos: h,
|
|
66
66
|
depth: i
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
|
-
function
|
|
70
|
-
const
|
|
71
|
-
return o.filter((
|
|
72
|
-
const
|
|
73
|
-
return Object.prototype.hasOwnProperty.call(
|
|
69
|
+
function Vt(o, t = JSON.stringify) {
|
|
70
|
+
const e = {};
|
|
71
|
+
return o.filter((r) => {
|
|
72
|
+
const n = t(r);
|
|
73
|
+
return Object.prototype.hasOwnProperty.call(e, n) ? !1 : e[n] = !0;
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
-
function
|
|
77
|
-
const
|
|
78
|
-
(
|
|
76
|
+
function Jt(o) {
|
|
77
|
+
const t = o.filter(
|
|
78
|
+
(r, n) => o.indexOf(r) !== n
|
|
79
79
|
);
|
|
80
|
-
return
|
|
80
|
+
return Vt(t);
|
|
81
81
|
}
|
|
82
|
-
const
|
|
82
|
+
const Y = E.create({
|
|
83
83
|
name: "uniqueID",
|
|
84
84
|
// we’ll set a very high priority to make sure this runs first
|
|
85
85
|
// and is compatible with `appendTransaction` hooks of other extensions
|
|
@@ -88,7 +88,7 @@ const j = C.create({
|
|
|
88
88
|
return {
|
|
89
89
|
attributeName: "id",
|
|
90
90
|
types: [],
|
|
91
|
-
generateID: () => window.__TEST_OPTIONS ? (window.__TEST_OPTIONS.mockID === void 0 ? window.__TEST_OPTIONS.mockID = 0 : window.__TEST_OPTIONS.mockID++,
|
|
91
|
+
generateID: () => window.__TEST_OPTIONS ? (window.__TEST_OPTIONS.mockID === void 0 ? window.__TEST_OPTIONS.mockID = 0 : window.__TEST_OPTIONS.mockID++, window.__TEST_OPTIONS.mockID.toString()) : Ht(),
|
|
92
92
|
filterTransaction: null
|
|
93
93
|
};
|
|
94
94
|
},
|
|
@@ -114,49 +114,49 @@ const j = C.create({
|
|
|
114
114
|
(d) => d.name === "collaboration"
|
|
115
115
|
))
|
|
116
116
|
return;
|
|
117
|
-
const { view: o, state:
|
|
118
|
-
$(
|
|
119
|
-
|
|
117
|
+
const { view: o, state: t } = this.editor, { tr: e, doc: r } = t, { types: n, attributeName: i, generateID: a } = this.options;
|
|
118
|
+
$(r, (d) => n.includes(d.type.name) && d.attrs[i] === null).forEach(({ node: d, pos: l }) => {
|
|
119
|
+
e.setNodeMarkup(l, void 0, {
|
|
120
120
|
...d.attrs,
|
|
121
121
|
[i]: a()
|
|
122
122
|
});
|
|
123
|
-
}),
|
|
123
|
+
}), e.setMeta("addToHistory", !1), o.dispatch(e);
|
|
124
124
|
},
|
|
125
125
|
addProseMirrorPlugins() {
|
|
126
|
-
let o = null,
|
|
126
|
+
let o = null, t = !1;
|
|
127
127
|
return [
|
|
128
|
-
new
|
|
128
|
+
new C({
|
|
129
129
|
key: new v("uniqueID"),
|
|
130
|
-
appendTransaction: (
|
|
131
|
-
const i =
|
|
132
|
-
var y,
|
|
133
|
-
return !(!((
|
|
130
|
+
appendTransaction: (e, r, n) => {
|
|
131
|
+
const i = e.some((m) => m.docChanged) && !r.doc.eq(n.doc), a = this.options.filterTransaction && e.some((m) => {
|
|
132
|
+
var y, k;
|
|
133
|
+
return !(!((k = (y = this.options).filterTransaction) === null || k === void 0) && k.call(y, m));
|
|
134
134
|
});
|
|
135
135
|
if (!i || a)
|
|
136
136
|
return;
|
|
137
|
-
const { tr: s } =
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
), { mapping: f } =
|
|
141
|
-
if (
|
|
142
|
-
const y =
|
|
143
|
-
|
|
137
|
+
const { tr: s } = n, { types: d, attributeName: l, generateID: c } = this.options, h = Mt(
|
|
138
|
+
r.doc,
|
|
139
|
+
e
|
|
140
|
+
), { mapping: f } = h;
|
|
141
|
+
if (Bt(h).forEach(({ newRange: m }) => {
|
|
142
|
+
const y = Tt(
|
|
143
|
+
n.doc,
|
|
144
144
|
m,
|
|
145
|
-
(
|
|
146
|
-
),
|
|
147
|
-
y.forEach(({ node:
|
|
145
|
+
(M) => d.includes(M.type.name)
|
|
146
|
+
), k = y.map(({ node: M }) => M.attrs[l]).filter((M) => M !== null), z = Jt(k);
|
|
147
|
+
y.forEach(({ node: M, pos: N }) => {
|
|
148
148
|
var U;
|
|
149
|
-
const J = (U = s.doc.nodeAt(
|
|
149
|
+
const J = (U = s.doc.nodeAt(N)) === null || U === void 0 ? void 0 : U.attrs[l];
|
|
150
150
|
if (J === null) {
|
|
151
|
-
s.setNodeMarkup(
|
|
152
|
-
...
|
|
151
|
+
s.setNodeMarkup(N, void 0, {
|
|
152
|
+
...M.attrs,
|
|
153
153
|
[l]: c()
|
|
154
154
|
});
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
|
-
const { deleted:
|
|
158
|
-
|
|
159
|
-
...
|
|
157
|
+
const { deleted: vt } = f.invert().mapResult(N);
|
|
158
|
+
vt && z.includes(J) && s.setNodeMarkup(N, void 0, {
|
|
159
|
+
...M.attrs,
|
|
160
160
|
[l]: c()
|
|
161
161
|
});
|
|
162
162
|
});
|
|
@@ -164,14 +164,14 @@ const j = C.create({
|
|
|
164
164
|
return s;
|
|
165
165
|
},
|
|
166
166
|
// we register a global drag handler to track the current drag source element
|
|
167
|
-
view(
|
|
168
|
-
const
|
|
167
|
+
view(e) {
|
|
168
|
+
const r = (n) => {
|
|
169
169
|
var i;
|
|
170
|
-
o = !((i =
|
|
170
|
+
o = !((i = e.dom.parentElement) === null || i === void 0) && i.contains(n.target) ? e.dom.parentElement : null;
|
|
171
171
|
};
|
|
172
|
-
return window.addEventListener("dragstart",
|
|
172
|
+
return window.addEventListener("dragstart", r), {
|
|
173
173
|
destroy() {
|
|
174
|
-
window.removeEventListener("dragstart",
|
|
174
|
+
window.removeEventListener("dragstart", r);
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
177
|
},
|
|
@@ -181,44 +181,44 @@ const j = C.create({
|
|
|
181
181
|
handleDOMEvents: {
|
|
182
182
|
// only create new ids for dropped content while holding `alt`
|
|
183
183
|
// or content is dragged from another editor
|
|
184
|
-
drop: (
|
|
185
|
-
var
|
|
186
|
-
return (o !==
|
|
184
|
+
drop: (e, r) => {
|
|
185
|
+
var n;
|
|
186
|
+
return (o !== e.dom.parentElement || ((n = r.dataTransfer) === null || n === void 0 ? void 0 : n.effectAllowed) === "copy") && (o = null, t = !0), !1;
|
|
187
187
|
},
|
|
188
188
|
// always create new ids on pasted content
|
|
189
|
-
paste: () => (
|
|
189
|
+
paste: () => (t = !0, !1)
|
|
190
190
|
},
|
|
191
191
|
// we’ll remove ids for every pasted node
|
|
192
192
|
// so we can create a new one within `appendTransaction`
|
|
193
|
-
transformPasted: (
|
|
194
|
-
if (!
|
|
195
|
-
return
|
|
196
|
-
const { types:
|
|
193
|
+
transformPasted: (e) => {
|
|
194
|
+
if (!t)
|
|
195
|
+
return e;
|
|
196
|
+
const { types: r, attributeName: n } = this.options, i = (a) => {
|
|
197
197
|
const s = [];
|
|
198
198
|
return a.forEach((d) => {
|
|
199
199
|
if (d.isText) {
|
|
200
200
|
s.push(d);
|
|
201
201
|
return;
|
|
202
202
|
}
|
|
203
|
-
if (!
|
|
203
|
+
if (!r.includes(d.type.name)) {
|
|
204
204
|
s.push(d.copy(i(d.content)));
|
|
205
205
|
return;
|
|
206
206
|
}
|
|
207
207
|
const l = d.type.create(
|
|
208
208
|
{
|
|
209
209
|
...d.attrs,
|
|
210
|
-
[
|
|
210
|
+
[n]: null
|
|
211
211
|
},
|
|
212
212
|
i(d.content),
|
|
213
213
|
d.marks
|
|
214
214
|
);
|
|
215
215
|
s.push(l);
|
|
216
|
-
}),
|
|
216
|
+
}), L.from(s);
|
|
217
217
|
};
|
|
218
|
-
return
|
|
219
|
-
i(
|
|
220
|
-
|
|
221
|
-
|
|
218
|
+
return t = !1, new P(
|
|
219
|
+
i(e.content),
|
|
220
|
+
e.openStart,
|
|
221
|
+
e.openEnd
|
|
222
222
|
);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
@@ -226,249 +226,250 @@ const j = C.create({
|
|
|
226
226
|
];
|
|
227
227
|
}
|
|
228
228
|
});
|
|
229
|
-
class
|
|
230
|
-
constructor(
|
|
231
|
-
super(`Unreachable case: ${
|
|
229
|
+
class Xt extends Error {
|
|
230
|
+
constructor(t) {
|
|
231
|
+
super(`Unreachable case: ${t}`);
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
|
-
const
|
|
234
|
+
const lt = /* @__PURE__ */ new Set([
|
|
235
235
|
"bold",
|
|
236
236
|
"italic",
|
|
237
237
|
"underline",
|
|
238
|
-
"strike"
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
238
|
+
"strike",
|
|
239
|
+
"code"
|
|
240
|
+
]), ct = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
|
|
241
|
+
function Qt(o, t) {
|
|
242
|
+
const e = [];
|
|
243
|
+
for (const [r, n] of Object.entries(o.styles))
|
|
244
|
+
lt.has(r) ? e.push(t.mark(r)) : ct.has(r) && e.push(t.mark(r, { color: n }));
|
|
245
|
+
return t.text(o.text, e);
|
|
245
246
|
}
|
|
246
|
-
function
|
|
247
|
-
const
|
|
247
|
+
function Zt(o, t) {
|
|
248
|
+
const e = t.marks.link.create({
|
|
248
249
|
href: o.href
|
|
249
250
|
});
|
|
250
|
-
return
|
|
251
|
+
return ut(o.content, t).map((r) => r.mark([...r.marks, e]));
|
|
251
252
|
}
|
|
252
|
-
function
|
|
253
|
-
let
|
|
253
|
+
function ut(o, t) {
|
|
254
|
+
let e = [];
|
|
254
255
|
if (typeof o == "string")
|
|
255
|
-
return
|
|
256
|
-
for (const
|
|
257
|
-
|
|
258
|
-
return
|
|
256
|
+
return e.push(t.text(o)), e;
|
|
257
|
+
for (const r of o)
|
|
258
|
+
e.push(Qt(r, t));
|
|
259
|
+
return e;
|
|
259
260
|
}
|
|
260
|
-
function
|
|
261
|
-
let
|
|
262
|
-
for (const
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
else if (
|
|
266
|
-
|
|
261
|
+
function ht(o, t) {
|
|
262
|
+
let e = [];
|
|
263
|
+
for (const r of o)
|
|
264
|
+
if (r.type === "link")
|
|
265
|
+
e.push(...Zt(r, t));
|
|
266
|
+
else if (r.type === "text")
|
|
267
|
+
e.push(...ut([r], t));
|
|
267
268
|
else
|
|
268
|
-
throw new
|
|
269
|
-
return
|
|
269
|
+
throw new Xt(r);
|
|
270
|
+
return e;
|
|
270
271
|
}
|
|
271
|
-
function R(o,
|
|
272
|
-
let
|
|
273
|
-
|
|
274
|
-
let
|
|
275
|
-
|
|
276
|
-
let
|
|
272
|
+
function R(o, t) {
|
|
273
|
+
let e = o.id;
|
|
274
|
+
e === void 0 && (e = Y.options.generateID());
|
|
275
|
+
let r = o.type;
|
|
276
|
+
r === void 0 && (r = "paragraph");
|
|
277
|
+
let n;
|
|
277
278
|
if (!o.content)
|
|
278
|
-
|
|
279
|
+
n = t.nodes[r].create(o.props);
|
|
279
280
|
else if (typeof o.content == "string")
|
|
280
|
-
|
|
281
|
+
n = t.nodes[r].create(
|
|
281
282
|
o.props,
|
|
282
|
-
|
|
283
|
+
t.text(o.content)
|
|
283
284
|
);
|
|
284
285
|
else {
|
|
285
|
-
const s =
|
|
286
|
-
|
|
286
|
+
const s = ht(o.content, t);
|
|
287
|
+
n = t.nodes[r].create(o.props, s);
|
|
287
288
|
}
|
|
288
289
|
const i = [];
|
|
289
290
|
if (o.children)
|
|
290
291
|
for (const s of o.children)
|
|
291
|
-
i.push(R(s,
|
|
292
|
-
const a =
|
|
293
|
-
return
|
|
292
|
+
i.push(R(s, t));
|
|
293
|
+
const a = t.nodes.blockGroup.create({}, i);
|
|
294
|
+
return t.nodes.blockContainer.create(
|
|
294
295
|
{
|
|
295
|
-
id:
|
|
296
|
+
id: e,
|
|
296
297
|
...o.props
|
|
297
298
|
},
|
|
298
|
-
i.length > 0 ? [
|
|
299
|
+
i.length > 0 ? [n, a] : n
|
|
299
300
|
);
|
|
300
301
|
}
|
|
301
|
-
function
|
|
302
|
-
const
|
|
303
|
-
let
|
|
304
|
-
return o.content.forEach((
|
|
305
|
-
const
|
|
302
|
+
function te(o) {
|
|
303
|
+
const t = [];
|
|
304
|
+
let e;
|
|
305
|
+
return o.content.forEach((r) => {
|
|
306
|
+
const n = {};
|
|
306
307
|
let i;
|
|
307
|
-
for (const a of
|
|
308
|
+
for (const a of r.marks)
|
|
308
309
|
if (a.type.name === "link")
|
|
309
310
|
i = a;
|
|
310
|
-
else if (
|
|
311
|
-
|
|
312
|
-
else if (
|
|
313
|
-
|
|
311
|
+
else if (lt.has(a.type.name))
|
|
312
|
+
n[a.type.name] = !0;
|
|
313
|
+
else if (ct.has(a.type.name))
|
|
314
|
+
n[a.type.name] = a.attrs.color;
|
|
314
315
|
else
|
|
315
316
|
throw Error("Mark is of an unrecognized type: " + a.type.name);
|
|
316
|
-
i &&
|
|
317
|
+
i && e && i.attrs.href === e.href ? e.content.push({
|
|
317
318
|
type: "text",
|
|
318
|
-
text:
|
|
319
|
-
styles:
|
|
320
|
-
}) : i ? (
|
|
319
|
+
text: r.textContent,
|
|
320
|
+
styles: n
|
|
321
|
+
}) : i ? (e = {
|
|
321
322
|
type: "link",
|
|
322
323
|
href: i.attrs.href,
|
|
323
324
|
content: [
|
|
324
325
|
{
|
|
325
326
|
type: "text",
|
|
326
|
-
text:
|
|
327
|
-
styles:
|
|
327
|
+
text: r.textContent,
|
|
328
|
+
styles: n
|
|
328
329
|
}
|
|
329
330
|
]
|
|
330
|
-
},
|
|
331
|
+
}, t.push(e)) : (t.push({
|
|
331
332
|
type: "text",
|
|
332
|
-
text:
|
|
333
|
-
styles:
|
|
334
|
-
}),
|
|
335
|
-
}),
|
|
333
|
+
text: r.textContent,
|
|
334
|
+
styles: n
|
|
335
|
+
}), e = void 0);
|
|
336
|
+
}), t;
|
|
336
337
|
}
|
|
337
|
-
function
|
|
338
|
+
function B(o, t) {
|
|
338
339
|
if (o.type.name !== "blockContainer")
|
|
339
340
|
throw Error(
|
|
340
341
|
"Node must be of type blockContainer, but is of type" + o.type.name + "."
|
|
341
342
|
);
|
|
342
|
-
const
|
|
343
|
-
if (
|
|
344
|
-
return
|
|
345
|
-
const
|
|
346
|
-
let
|
|
347
|
-
|
|
343
|
+
const e = t == null ? void 0 : t.get(o);
|
|
344
|
+
if (e)
|
|
345
|
+
return e;
|
|
346
|
+
const r = g(o, 0);
|
|
347
|
+
let n = r.id;
|
|
348
|
+
n === null && (n = Y.options.generateID());
|
|
348
349
|
const i = {};
|
|
349
350
|
for (const [l, c] of Object.entries({
|
|
350
|
-
...
|
|
351
|
-
...
|
|
351
|
+
...r.node.attrs,
|
|
352
|
+
...r.contentNode.attrs
|
|
352
353
|
})) {
|
|
353
|
-
if (!(
|
|
354
|
+
if (!(r.contentType.name in tt))
|
|
354
355
|
throw Error(
|
|
355
|
-
"Block is of an unrecognized type: " +
|
|
356
|
+
"Block is of an unrecognized type: " + r.contentType.name
|
|
356
357
|
);
|
|
357
|
-
|
|
358
|
+
tt[r.contentType.name].has(l) && (i[l] = c);
|
|
358
359
|
}
|
|
359
|
-
const a =
|
|
360
|
-
for (let l = 0; l <
|
|
361
|
-
s.push(
|
|
360
|
+
const a = te(r.contentNode), s = [];
|
|
361
|
+
for (let l = 0; l < r.numChildBlocks; l++)
|
|
362
|
+
s.push(B(r.node.lastChild.child(l)));
|
|
362
363
|
const d = {
|
|
363
|
-
id:
|
|
364
|
-
type:
|
|
364
|
+
id: n,
|
|
365
|
+
type: r.contentType.name,
|
|
365
366
|
props: i,
|
|
366
367
|
content: a,
|
|
367
368
|
children: s
|
|
368
369
|
};
|
|
369
|
-
return
|
|
370
|
+
return t == null || t.set(o, d), d;
|
|
370
371
|
}
|
|
371
|
-
function
|
|
372
|
-
let
|
|
373
|
-
if (
|
|
372
|
+
function K(o, t) {
|
|
373
|
+
let e, r;
|
|
374
|
+
if (t.firstChild.descendants((n, i) => e ? !1 : n.type.name !== "blockContainer" || n.attrs.id !== o ? !0 : (e = n, r = i + 1, !1)), e === void 0 || r === void 0)
|
|
374
375
|
throw Error("Could not find block in the editor with matching ID.");
|
|
375
376
|
return {
|
|
376
|
-
node:
|
|
377
|
-
posBeforeNode:
|
|
377
|
+
node: e,
|
|
378
|
+
posBeforeNode: r
|
|
378
379
|
};
|
|
379
380
|
}
|
|
380
|
-
function
|
|
381
|
-
const
|
|
381
|
+
function pt(o, t, e = "before", r) {
|
|
382
|
+
const n = typeof t == "string" ? t : t.id, i = [];
|
|
382
383
|
for (const l of o)
|
|
383
|
-
i.push(R(l,
|
|
384
|
+
i.push(R(l, r.schema));
|
|
384
385
|
let a = -1;
|
|
385
|
-
const { node: s, posBeforeNode: d } =
|
|
386
|
-
if (
|
|
386
|
+
const { node: s, posBeforeNode: d } = K(n, r.state.doc);
|
|
387
|
+
if (e === "before" && (a = d), e === "after" && (a = d + s.nodeSize), e === "nested") {
|
|
387
388
|
if (s.childCount < 2) {
|
|
388
389
|
a = d + s.firstChild.nodeSize + 1;
|
|
389
|
-
const l =
|
|
390
|
+
const l = r.state.schema.nodes.blockGroup.create(
|
|
390
391
|
{},
|
|
391
392
|
i
|
|
392
393
|
);
|
|
393
|
-
|
|
394
|
-
|
|
394
|
+
r.view.dispatch(
|
|
395
|
+
r.state.tr.insert(a, l)
|
|
395
396
|
);
|
|
396
397
|
return;
|
|
397
398
|
}
|
|
398
399
|
a = d + s.firstChild.nodeSize + 2;
|
|
399
400
|
}
|
|
400
|
-
|
|
401
|
+
r.view.dispatch(r.state.tr.insert(a, i));
|
|
401
402
|
}
|
|
402
|
-
function
|
|
403
|
-
const
|
|
404
|
-
|
|
403
|
+
function ee(o, t, e) {
|
|
404
|
+
const r = typeof o == "string" ? o : o.id, { posBeforeNode: n } = K(r, e.state.doc);
|
|
405
|
+
e.commands.BNUpdateBlock(n + 1, t);
|
|
405
406
|
}
|
|
406
|
-
function
|
|
407
|
-
const
|
|
407
|
+
function ft(o, t) {
|
|
408
|
+
const e = new Set(
|
|
408
409
|
o.map(
|
|
409
|
-
(
|
|
410
|
+
(n) => typeof n == "string" ? n : n.id
|
|
410
411
|
)
|
|
411
412
|
);
|
|
412
|
-
let
|
|
413
|
-
if (
|
|
414
|
-
if (
|
|
413
|
+
let r = 0;
|
|
414
|
+
if (t.state.doc.descendants((n, i) => {
|
|
415
|
+
if (e.size === 0)
|
|
415
416
|
return !1;
|
|
416
|
-
if (
|
|
417
|
+
if (n.type.name !== "blockContainer" || !e.has(n.attrs.id))
|
|
417
418
|
return !0;
|
|
418
|
-
|
|
419
|
-
const a =
|
|
420
|
-
|
|
421
|
-
const s =
|
|
422
|
-
return
|
|
423
|
-
}),
|
|
424
|
-
let
|
|
419
|
+
e.delete(n.attrs.id);
|
|
420
|
+
const a = t.state.doc.nodeSize;
|
|
421
|
+
t.commands.BNDeleteBlock(i - r + 1);
|
|
422
|
+
const s = t.state.doc.nodeSize;
|
|
423
|
+
return r += a - s, !1;
|
|
424
|
+
}), e.size > 0) {
|
|
425
|
+
let n = [...e].join(`
|
|
425
426
|
`);
|
|
426
427
|
throw Error(
|
|
427
|
-
"Blocks with the following IDs could not be found in the editor: " +
|
|
428
|
+
"Blocks with the following IDs could not be found in the editor: " + n
|
|
428
429
|
);
|
|
429
430
|
}
|
|
430
431
|
}
|
|
431
|
-
function
|
|
432
|
-
|
|
432
|
+
function oe(o, t, e) {
|
|
433
|
+
pt(t, o[0], "before", e), ft(o, e);
|
|
433
434
|
}
|
|
434
|
-
function
|
|
435
|
-
const o = (
|
|
436
|
-
let
|
|
437
|
-
for (let
|
|
438
|
-
const
|
|
439
|
-
if (
|
|
440
|
-
if (
|
|
441
|
-
|
|
442
|
-
const i =
|
|
443
|
-
|
|
435
|
+
function re() {
|
|
436
|
+
const o = (t) => {
|
|
437
|
+
let e = t.children.length;
|
|
438
|
+
for (let r = 0; r < e; r++) {
|
|
439
|
+
const n = t.children[r];
|
|
440
|
+
if (n.type === "element" && (o(n), n.tagName === "u"))
|
|
441
|
+
if (n.children.length > 0) {
|
|
442
|
+
t.children.splice(r, 1, ...n.children);
|
|
443
|
+
const i = n.children.length - 1;
|
|
444
|
+
e += i, r += i;
|
|
444
445
|
} else
|
|
445
|
-
|
|
446
|
+
t.children.splice(r, 1), e--, r--;
|
|
446
447
|
}
|
|
447
448
|
};
|
|
448
449
|
return o;
|
|
449
450
|
}
|
|
450
|
-
function
|
|
451
|
-
const
|
|
451
|
+
function ne(o) {
|
|
452
|
+
const t = /* @__PURE__ */ new Set([
|
|
452
453
|
...o.orderedListItemBlockTypes,
|
|
453
454
|
...o.unorderedListItemBlockTypes
|
|
454
|
-
]),
|
|
455
|
-
let
|
|
456
|
-
for (let a = 0; a <
|
|
457
|
-
const d =
|
|
455
|
+
]), e = (r) => {
|
|
456
|
+
let n = r.children.length, i;
|
|
457
|
+
for (let a = 0; a < n; a++) {
|
|
458
|
+
const d = r.children[a].children[0], l = d.children[0], c = d.children.length === 2 ? d.children[1] : null, h = t.has(
|
|
458
459
|
l.properties.dataContentType
|
|
459
|
-
), f =
|
|
460
|
+
), f = h ? o.orderedListItemBlockTypes.has(
|
|
460
461
|
l.properties.dataContentType
|
|
461
462
|
) ? "ol" : "ul" : null;
|
|
462
|
-
if (c !== null &&
|
|
463
|
-
|
|
463
|
+
if (c !== null && e(c), i && i.tagName !== f) {
|
|
464
|
+
r.children.splice(
|
|
464
465
|
a - i.children.length,
|
|
465
466
|
i.children.length,
|
|
466
467
|
i
|
|
467
468
|
);
|
|
468
469
|
const p = i.children.length - 1;
|
|
469
|
-
a -= p,
|
|
470
|
+
a -= p, n -= p, i = void 0;
|
|
470
471
|
}
|
|
471
|
-
if (
|
|
472
|
+
if (h) {
|
|
472
473
|
i || (i = Z(
|
|
473
474
|
document.createElement(f)
|
|
474
475
|
));
|
|
@@ -477,47 +478,47 @@ function rt(o) {
|
|
|
477
478
|
);
|
|
478
479
|
p.children.push(l.children[0]), c !== null && p.children.push(...c.children), i.children.push(p);
|
|
479
480
|
} else if (c !== null) {
|
|
480
|
-
|
|
481
|
+
r.children.splice(a + 1, 0, ...c.children), r.children[a] = l.children[0];
|
|
481
482
|
const p = c.children.length;
|
|
482
|
-
a += p,
|
|
483
|
+
a += p, n += p;
|
|
483
484
|
} else
|
|
484
|
-
|
|
485
|
+
r.children[a] = l.children[0];
|
|
485
486
|
}
|
|
486
|
-
i &&
|
|
487
|
-
|
|
487
|
+
i && r.children.splice(
|
|
488
|
+
n - i.children.length,
|
|
488
489
|
i.children.length,
|
|
489
490
|
i
|
|
490
491
|
);
|
|
491
492
|
};
|
|
492
|
-
return
|
|
493
|
+
return e;
|
|
493
494
|
}
|
|
494
|
-
async function
|
|
495
|
-
const
|
|
495
|
+
async function mt(o, t) {
|
|
496
|
+
const e = document.createElement("div"), r = Pt.fromSchema(t);
|
|
496
497
|
for (const i of o) {
|
|
497
|
-
const a = R(i,
|
|
498
|
-
|
|
498
|
+
const a = R(i, t), s = r.serializeNode(a);
|
|
499
|
+
e.appendChild(s);
|
|
499
500
|
}
|
|
500
|
-
return (await
|
|
501
|
+
return (await j().use(it, { fragment: !0 }).use(ne, {
|
|
501
502
|
orderedListItemBlockTypes: /* @__PURE__ */ new Set(["numberedListItem"]),
|
|
502
503
|
unorderedListItemBlockTypes: /* @__PURE__ */ new Set(["bulletListItem"])
|
|
503
|
-
}).use(
|
|
504
|
+
}).use(st).process(e.innerHTML)).value;
|
|
504
505
|
}
|
|
505
|
-
async function
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
const
|
|
509
|
-
for (let a = 0; a <
|
|
510
|
-
i.push(
|
|
506
|
+
async function gt(o, t) {
|
|
507
|
+
const e = document.createElement("div");
|
|
508
|
+
e.innerHTML = o.trim();
|
|
509
|
+
const n = Lt.fromSchema(t).parse(e), i = [];
|
|
510
|
+
for (let a = 0; a < n.firstChild.childCount; a++)
|
|
511
|
+
i.push(B(n.firstChild.child(a)));
|
|
511
512
|
return i;
|
|
512
513
|
}
|
|
513
|
-
async function
|
|
514
|
-
return (await
|
|
514
|
+
async function ie(o, t) {
|
|
515
|
+
return (await j().use(it, { fragment: !0 }).use(re).use(Nt).use(at).use(Dt).process(await mt(o, t))).value;
|
|
515
516
|
}
|
|
516
|
-
async function
|
|
517
|
-
const
|
|
518
|
-
return
|
|
517
|
+
async function se(o, t) {
|
|
518
|
+
const e = await j().use(_t).use(at).use(Ot).use(st).process(o);
|
|
519
|
+
return gt(e.value, t);
|
|
519
520
|
}
|
|
520
|
-
const
|
|
521
|
+
const ae = E.create({
|
|
521
522
|
name: "blockBackgroundColor",
|
|
522
523
|
addGlobalAttributes() {
|
|
523
524
|
return [
|
|
@@ -537,17 +538,17 @@ const at = C.create({
|
|
|
537
538
|
},
|
|
538
539
|
addCommands() {
|
|
539
540
|
return {
|
|
540
|
-
setBlockBackgroundColor: (o,
|
|
541
|
-
const
|
|
542
|
-
return
|
|
543
|
-
|
|
541
|
+
setBlockBackgroundColor: (o, t) => ({ state: e, view: r }) => {
|
|
542
|
+
const n = g(e.doc, o);
|
|
543
|
+
return n === void 0 ? !1 : (e.tr.setNodeAttribute(
|
|
544
|
+
n.startPos - 1,
|
|
544
545
|
"backgroundColor",
|
|
545
|
-
|
|
546
|
-
),
|
|
546
|
+
t
|
|
547
|
+
), r.focus(), !0);
|
|
547
548
|
}
|
|
548
549
|
};
|
|
549
550
|
}
|
|
550
|
-
}),
|
|
551
|
+
}), de = rt.create({
|
|
551
552
|
name: "backgroundColor",
|
|
552
553
|
addAttributes() {
|
|
553
554
|
return {
|
|
@@ -573,10 +574,10 @@ const at = C.create({
|
|
|
573
574
|
},
|
|
574
575
|
addCommands() {
|
|
575
576
|
return {
|
|
576
|
-
setBackgroundColor: (o) => ({ commands:
|
|
577
|
+
setBackgroundColor: (o) => ({ commands: t }) => o !== "default" ? t.setMark(this.name, { color: o }) : t.unsetMark(this.name)
|
|
577
578
|
};
|
|
578
579
|
}
|
|
579
|
-
}),
|
|
580
|
+
}), et = new v("previous-blocks"), le = {
|
|
580
581
|
// Numbered List Items
|
|
581
582
|
index: "index",
|
|
582
583
|
// Headings
|
|
@@ -585,17 +586,17 @@ const at = C.create({
|
|
|
585
586
|
type: "type",
|
|
586
587
|
depth: "depth",
|
|
587
588
|
"depth-change": "depth-change"
|
|
588
|
-
},
|
|
589
|
+
}, ce = () => {
|
|
589
590
|
let o;
|
|
590
|
-
return new
|
|
591
|
-
key:
|
|
592
|
-
view(
|
|
591
|
+
return new C({
|
|
592
|
+
key: et,
|
|
593
|
+
view(t) {
|
|
593
594
|
return {
|
|
594
|
-
update: async (
|
|
595
|
-
var
|
|
596
|
-
((
|
|
597
|
-
|
|
598
|
-
|
|
595
|
+
update: async (e, r) => {
|
|
596
|
+
var n;
|
|
597
|
+
((n = this.key) == null ? void 0 : n.getState(e.state).updatedBlocks.size) > 0 && (o = setTimeout(() => {
|
|
598
|
+
e.dispatch(
|
|
599
|
+
e.state.tr.setMeta(et, { clearUpdate: !0 })
|
|
599
600
|
);
|
|
600
601
|
}, 0));
|
|
601
602
|
},
|
|
@@ -615,68 +616,68 @@ const at = C.create({
|
|
|
615
616
|
updatedBlocks: /* @__PURE__ */ new Set()
|
|
616
617
|
};
|
|
617
618
|
},
|
|
618
|
-
apply(e,
|
|
619
|
-
if (
|
|
620
|
-
return
|
|
621
|
-
const i = {}, a = $(
|
|
619
|
+
apply(t, e, r, n) {
|
|
620
|
+
if (e.currentTransactionOldBlockAttrs = {}, e.updatedBlocks.clear(), !t.docChanged || r.doc.eq(n.doc))
|
|
621
|
+
return e;
|
|
622
|
+
const i = {}, a = $(r.doc, (l) => l.attrs.id), s = new Map(
|
|
622
623
|
a.map((l) => [l.node.attrs.id, l])
|
|
623
|
-
), d = $(
|
|
624
|
+
), d = $(n.doc, (l) => l.attrs.id);
|
|
624
625
|
for (let l of d) {
|
|
625
|
-
const c = s.get(l.node.attrs.id),
|
|
626
|
-
if (c &&
|
|
626
|
+
const c = s.get(l.node.attrs.id), h = c == null ? void 0 : c.node.firstChild, f = l.node.firstChild;
|
|
627
|
+
if (c && h && f) {
|
|
627
628
|
const p = {
|
|
628
629
|
index: f.attrs.index,
|
|
629
630
|
level: f.attrs.level,
|
|
630
631
|
type: f.type.name,
|
|
631
|
-
depth:
|
|
632
|
+
depth: n.doc.resolve(l.pos).depth
|
|
632
633
|
};
|
|
633
634
|
let m = {
|
|
634
|
-
index:
|
|
635
|
-
level:
|
|
636
|
-
type:
|
|
637
|
-
depth:
|
|
635
|
+
index: h.attrs.index,
|
|
636
|
+
level: h.attrs.level,
|
|
637
|
+
type: h.type.name,
|
|
638
|
+
depth: r.doc.resolve(c.pos).depth
|
|
638
639
|
};
|
|
639
|
-
i[l.node.attrs.id] = m,
|
|
640
|
+
i[l.node.attrs.id] = m, t.getMeta("numberedListIndexing") && (l.node.attrs.id in e.prevTransactionOldBlockAttrs && (m = e.prevTransactionOldBlockAttrs[l.node.attrs.id]), p.type === "numberedListItem" && (m.index = p.index)), e.currentTransactionOldBlockAttrs[l.node.attrs.id] = m, JSON.stringify(m) !== JSON.stringify(p) && (m["depth-change"] = m.depth - p.depth, e.updatedBlocks.add(l.node.attrs.id));
|
|
640
641
|
}
|
|
641
642
|
}
|
|
642
|
-
return
|
|
643
|
+
return e.prevTransactionOldBlockAttrs = i, e;
|
|
643
644
|
}
|
|
644
645
|
},
|
|
645
646
|
props: {
|
|
646
|
-
decorations(
|
|
647
|
-
const
|
|
648
|
-
if (
|
|
647
|
+
decorations(t) {
|
|
648
|
+
const e = this.getState(t);
|
|
649
|
+
if (e.updatedBlocks.size === 0)
|
|
649
650
|
return;
|
|
650
|
-
const
|
|
651
|
-
return
|
|
652
|
-
if (!
|
|
651
|
+
const r = [];
|
|
652
|
+
return t.doc.descendants((n, i) => {
|
|
653
|
+
if (!n.attrs.id || !e.updatedBlocks.has(n.attrs.id))
|
|
653
654
|
return;
|
|
654
|
-
const a =
|
|
655
|
+
const a = e.currentTransactionOldBlockAttrs[n.attrs.id], s = {};
|
|
655
656
|
for (let [l, c] of Object.entries(a))
|
|
656
|
-
s["data-prev-" +
|
|
657
|
-
const d = D.node(i, i +
|
|
657
|
+
s["data-prev-" + le[l]] = c || "none";
|
|
658
|
+
const d = D.node(i, i + n.nodeSize, {
|
|
658
659
|
...s
|
|
659
660
|
});
|
|
660
|
-
|
|
661
|
-
}), F.create(
|
|
661
|
+
r.push(d);
|
|
662
|
+
}), F.create(t.doc, r);
|
|
662
663
|
}
|
|
663
664
|
}
|
|
664
665
|
});
|
|
665
|
-
},
|
|
666
|
-
blockOuter:
|
|
667
|
-
blockContent:
|
|
668
|
-
blockGroup:
|
|
669
|
-
block:
|
|
670
|
-
isEmpty:
|
|
671
|
-
isFilter:
|
|
672
|
-
hasAnchor:
|
|
673
|
-
},
|
|
666
|
+
}, ue = "_blockOuter_63zqr_5", he = "_blockContent_63zqr_10", pe = "_blockGroup_63zqr_26", fe = "_block_63zqr_5", me = "_isEmpty_63zqr_224", ge = "_isFilter_63zqr_225", ke = "_hasAnchor_63zqr_247", b = {
|
|
667
|
+
blockOuter: ue,
|
|
668
|
+
blockContent: he,
|
|
669
|
+
blockGroup: pe,
|
|
670
|
+
block: fe,
|
|
671
|
+
isEmpty: me,
|
|
672
|
+
isFilter: ge,
|
|
673
|
+
hasAnchor: ke
|
|
674
|
+
}, ye = {
|
|
674
675
|
blockColor: "data-block-color",
|
|
675
676
|
blockStyle: "data-block-style",
|
|
676
677
|
id: "data-id",
|
|
677
678
|
depth: "data-depth",
|
|
678
679
|
depthChange: "data-depth-change"
|
|
679
|
-
},
|
|
680
|
+
}, be = S.create({
|
|
680
681
|
name: "blockContainer",
|
|
681
682
|
group: "blockContainer",
|
|
682
683
|
// A block always contains content, and optionally a blockGroup which contains nested blocks
|
|
@@ -696,10 +697,10 @@ const at = C.create({
|
|
|
696
697
|
getAttrs: (o) => {
|
|
697
698
|
if (typeof o == "string")
|
|
698
699
|
return !1;
|
|
699
|
-
const
|
|
700
|
-
for (let [
|
|
701
|
-
o.getAttribute(
|
|
702
|
-
return o.getAttribute("data-node-type") === "blockContainer" ?
|
|
700
|
+
const t = {};
|
|
701
|
+
for (let [e, r] of Object.entries(ye))
|
|
702
|
+
o.getAttribute(r) && (t[e] = o.getAttribute(r));
|
|
703
|
+
return o.getAttribute("data-node-type") === "blockContainer" ? t : !1;
|
|
703
704
|
}
|
|
704
705
|
}
|
|
705
706
|
];
|
|
@@ -707,13 +708,13 @@ const at = C.create({
|
|
|
707
708
|
renderHTML({ HTMLAttributes: o }) {
|
|
708
709
|
return [
|
|
709
710
|
"div",
|
|
710
|
-
|
|
711
|
+
w(o, {
|
|
711
712
|
class: b.blockOuter,
|
|
712
713
|
"data-node-type": "block-outer"
|
|
713
714
|
}),
|
|
714
715
|
[
|
|
715
716
|
"div",
|
|
716
|
-
|
|
717
|
+
w(o, {
|
|
717
718
|
// TODO: maybe remove html attributes from inner block
|
|
718
719
|
class: b.block,
|
|
719
720
|
"data-node-type": this.name
|
|
@@ -725,56 +726,56 @@ const at = C.create({
|
|
|
725
726
|
addCommands() {
|
|
726
727
|
return {
|
|
727
728
|
// Creates a new text block at a given position.
|
|
728
|
-
BNCreateBlock: (o) => ({ state:
|
|
729
|
-
const
|
|
730
|
-
return
|
|
729
|
+
BNCreateBlock: (o) => ({ state: t, dispatch: e }) => {
|
|
730
|
+
const r = t.schema.nodes.blockContainer.createAndFill();
|
|
731
|
+
return e && t.tr.insert(o, r), !0;
|
|
731
732
|
},
|
|
732
733
|
// Deletes a block at a given position.
|
|
733
|
-
BNDeleteBlock: (o) => ({ state:
|
|
734
|
-
const
|
|
735
|
-
if (
|
|
734
|
+
BNDeleteBlock: (o) => ({ state: t, dispatch: e }) => {
|
|
735
|
+
const r = g(t.doc, o);
|
|
736
|
+
if (r === void 0)
|
|
736
737
|
return !1;
|
|
737
|
-
const { startPos:
|
|
738
|
-
return
|
|
738
|
+
const { startPos: n, endPos: i } = r;
|
|
739
|
+
return e && t.tr.deleteRange(n, i), !0;
|
|
739
740
|
},
|
|
740
741
|
// Updates a block at a given position.
|
|
741
|
-
BNUpdateBlock: (o,
|
|
742
|
-
const
|
|
743
|
-
if (
|
|
742
|
+
BNUpdateBlock: (o, t) => ({ state: e, dispatch: r }) => {
|
|
743
|
+
const n = g(e.doc, o);
|
|
744
|
+
if (n === void 0)
|
|
744
745
|
return !1;
|
|
745
|
-
const { startPos: i, endPos: a, node: s, contentNode: d } =
|
|
746
|
-
if (
|
|
747
|
-
if (
|
|
746
|
+
const { startPos: i, endPos: a, node: s, contentNode: d } = n;
|
|
747
|
+
if (r) {
|
|
748
|
+
if (t.children !== void 0) {
|
|
748
749
|
const l = [];
|
|
749
|
-
for (const c of
|
|
750
|
-
l.push(R(c,
|
|
751
|
-
s.childCount === 2 ?
|
|
750
|
+
for (const c of t.children)
|
|
751
|
+
l.push(R(c, e.schema));
|
|
752
|
+
s.childCount === 2 ? e.tr.replace(
|
|
752
753
|
i + d.nodeSize + 1,
|
|
753
754
|
a - 1,
|
|
754
|
-
new
|
|
755
|
-
) :
|
|
755
|
+
new P(L.from(l), 0, 0)
|
|
756
|
+
) : e.tr.insert(
|
|
756
757
|
i + d.nodeSize,
|
|
757
|
-
|
|
758
|
+
e.schema.nodes.blockGroup.create({}, l)
|
|
758
759
|
);
|
|
759
760
|
}
|
|
760
|
-
if (
|
|
761
|
+
if (t.content !== void 0) {
|
|
761
762
|
let l = [];
|
|
762
|
-
typeof
|
|
763
|
+
typeof t.content == "string" ? l.push(e.schema.text(t.content)) : l = ht(t.content, e.schema), e.tr.replace(
|
|
763
764
|
i + 1,
|
|
764
765
|
i + d.nodeSize - 1,
|
|
765
|
-
new
|
|
766
|
+
new P(L.from(l), 0, 0)
|
|
766
767
|
);
|
|
767
768
|
}
|
|
768
|
-
|
|
769
|
+
e.tr.setNodeMarkup(
|
|
769
770
|
i,
|
|
770
|
-
|
|
771
|
+
t.type === void 0 ? void 0 : e.schema.nodes[t.type],
|
|
771
772
|
{
|
|
772
773
|
...d.attrs,
|
|
773
|
-
...
|
|
774
|
+
...t.props
|
|
774
775
|
}
|
|
775
|
-
),
|
|
776
|
+
), e.tr.setNodeMarkup(i - 1, void 0, {
|
|
776
777
|
...s.attrs,
|
|
777
|
-
...
|
|
778
|
+
...t.props
|
|
778
779
|
});
|
|
779
780
|
}
|
|
780
781
|
return !0;
|
|
@@ -796,55 +797,55 @@ const at = C.create({
|
|
|
796
797
|
// Block2Block3
|
|
797
798
|
// Block4
|
|
798
799
|
// Block5
|
|
799
|
-
BNMergeBlocks: (o) => ({ state:
|
|
800
|
-
const
|
|
801
|
-
if (!
|
|
800
|
+
BNMergeBlocks: (o) => ({ state: t, dispatch: e }) => {
|
|
801
|
+
const r = t.doc.resolve(o + 1).node().type.name === "blockContainer", n = t.doc.resolve(o - 1).node().type.name === "blockContainer";
|
|
802
|
+
if (!r || !n)
|
|
802
803
|
return !1;
|
|
803
|
-
const i =
|
|
804
|
-
|
|
804
|
+
const i = g(
|
|
805
|
+
t.doc,
|
|
805
806
|
o + 1
|
|
806
807
|
), { node: a, contentNode: s, startPos: d, endPos: l, depth: c } = i;
|
|
807
808
|
if (a.childCount === 2) {
|
|
808
|
-
const p =
|
|
809
|
+
const p = t.doc.resolve(
|
|
809
810
|
d + s.nodeSize + 1
|
|
810
|
-
), m =
|
|
811
|
-
|
|
811
|
+
), m = t.doc.resolve(l - 1), y = p.blockRange(m);
|
|
812
|
+
e && t.tr.lift(y, c - 1);
|
|
812
813
|
}
|
|
813
|
-
let
|
|
814
|
+
let h = o - 1, f = g(t.doc, h);
|
|
814
815
|
for (; f.numChildBlocks > 0; )
|
|
815
|
-
if (
|
|
816
|
+
if (h--, f = g(t.doc, h), f === void 0)
|
|
816
817
|
return !1;
|
|
817
|
-
return
|
|
818
|
-
new Q(
|
|
818
|
+
return e && (t.tr.deleteRange(d, d + s.nodeSize), t.tr.insertText(s.textContent, h - 1), t.tr.setSelection(
|
|
819
|
+
new Q(t.doc.resolve(h - 1))
|
|
819
820
|
)), !0;
|
|
820
821
|
},
|
|
821
822
|
// Splits a block at a given position. Content after the position is moved to a new block below, at the same
|
|
822
823
|
// nesting level.
|
|
823
|
-
BNSplitBlock: (o,
|
|
824
|
-
const
|
|
825
|
-
if (
|
|
824
|
+
BNSplitBlock: (o, t) => ({ state: e, dispatch: r }) => {
|
|
825
|
+
const n = g(e.doc, o);
|
|
826
|
+
if (n === void 0)
|
|
826
827
|
return !1;
|
|
827
|
-
const { contentNode: i, contentType: a, startPos: s, endPos: d, depth: l } =
|
|
828
|
-
return
|
|
828
|
+
const { contentNode: i, contentType: a, startPos: s, endPos: d, depth: l } = n, c = e.doc.cut(s + 1, o), h = e.doc.cut(o, d - 1), f = e.schema.nodes.blockContainer.createAndFill(), p = d + 1, m = p + 2;
|
|
829
|
+
return r && (e.tr.insert(p, f), e.tr.replace(
|
|
829
830
|
m,
|
|
830
831
|
m + 1,
|
|
831
|
-
|
|
832
|
-
|
|
832
|
+
h.content.size > 0 ? new P(
|
|
833
|
+
L.from(h),
|
|
833
834
|
l + 2,
|
|
834
835
|
l + 2
|
|
835
836
|
) : void 0
|
|
836
|
-
),
|
|
837
|
+
), t && e.tr.setBlockType(
|
|
837
838
|
m,
|
|
838
839
|
m,
|
|
839
|
-
|
|
840
|
+
e.schema.node(a).type,
|
|
840
841
|
i.attrs
|
|
841
|
-
),
|
|
842
|
-
new Q(
|
|
843
|
-
),
|
|
842
|
+
), e.tr.setSelection(
|
|
843
|
+
new Q(e.doc.resolve(m))
|
|
844
|
+
), e.tr.replace(
|
|
844
845
|
s + 1,
|
|
845
846
|
d - 1,
|
|
846
|
-
c.content.size > 0 ? new
|
|
847
|
-
|
|
847
|
+
c.content.size > 0 ? new P(
|
|
848
|
+
L.from(c),
|
|
848
849
|
l + 2,
|
|
849
850
|
l + 2
|
|
850
851
|
) : void 0
|
|
@@ -853,69 +854,69 @@ const at = C.create({
|
|
|
853
854
|
};
|
|
854
855
|
},
|
|
855
856
|
addProseMirrorPlugins() {
|
|
856
|
-
return [
|
|
857
|
+
return [ce()];
|
|
857
858
|
},
|
|
858
859
|
addKeyboardShortcuts() {
|
|
859
860
|
return {
|
|
860
|
-
Backspace: () => this.editor.commands.first(({ commands:
|
|
861
|
+
Backspace: () => this.editor.commands.first(({ commands: e }) => [
|
|
861
862
|
// Deletes the selection if it's not empty.
|
|
862
|
-
() =>
|
|
863
|
+
() => e.deleteSelection(),
|
|
863
864
|
// Undoes an input rule if one was triggered in the last editor state change.
|
|
864
|
-
() =>
|
|
865
|
+
() => e.undoInputRule(),
|
|
865
866
|
// Reverts block content type to a paragraph if the selection is at the start of the block.
|
|
866
|
-
() =>
|
|
867
|
-
const { contentType:
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
), i =
|
|
871
|
-
return i && !a ?
|
|
867
|
+
() => e.command(({ state: r }) => {
|
|
868
|
+
const { contentType: n } = g(
|
|
869
|
+
r.doc,
|
|
870
|
+
r.selection.from
|
|
871
|
+
), i = r.selection.$anchor.parentOffset === 0, a = n.name === "paragraph";
|
|
872
|
+
return i && !a ? e.BNUpdateBlock(r.selection.from, {
|
|
872
873
|
type: "paragraph",
|
|
873
874
|
props: {}
|
|
874
875
|
}) : !1;
|
|
875
876
|
}),
|
|
876
877
|
// Removes a level of nesting if the block is indented if the selection is at the start of the block.
|
|
877
|
-
() =>
|
|
878
|
+
() => e.command(({ state: r }) => r.selection.$anchor.parentOffset === 0 ? e.liftListItem("blockContainer") : !1),
|
|
878
879
|
// Merges block with the previous one if it isn't indented, isn't the first block in the doc, and the selection
|
|
879
880
|
// is at the start of the block.
|
|
880
|
-
() =>
|
|
881
|
-
const { depth:
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
), a =
|
|
885
|
-
return !d && a && s &&
|
|
881
|
+
() => e.command(({ state: r }) => {
|
|
882
|
+
const { depth: n, startPos: i } = g(
|
|
883
|
+
r.doc,
|
|
884
|
+
r.selection.from
|
|
885
|
+
), a = r.selection.$anchor.parentOffset === 0, s = r.selection.anchor === r.selection.head, d = i === 2, l = i - 1;
|
|
886
|
+
return !d && a && s && n === 2 ? e.BNMergeBlocks(l) : !1;
|
|
886
887
|
})
|
|
887
888
|
]),
|
|
888
|
-
Enter: () => this.editor.commands.first(({ commands:
|
|
889
|
+
Enter: () => this.editor.commands.first(({ commands: e }) => [
|
|
889
890
|
// Removes a level of nesting if the block is empty & indented, while the selection is also empty & at the start
|
|
890
891
|
// of the block.
|
|
891
|
-
() =>
|
|
892
|
-
const { node:
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
), a =
|
|
896
|
-
return a && s && d && l ?
|
|
892
|
+
() => e.command(({ state: r }) => {
|
|
893
|
+
const { node: n, depth: i } = g(
|
|
894
|
+
r.doc,
|
|
895
|
+
r.selection.from
|
|
896
|
+
), a = r.selection.$anchor.parentOffset === 0, s = r.selection.anchor === r.selection.head, d = n.textContent.length === 0, l = i > 2;
|
|
897
|
+
return a && s && d && l ? e.liftListItem("blockContainer") : !1;
|
|
897
898
|
}),
|
|
898
899
|
// Creates a new block and moves the selection to it if the current one is empty, while the selection is also
|
|
899
900
|
// empty & at the start of the block.
|
|
900
|
-
() =>
|
|
901
|
-
const { node: i, endPos: a } =
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
), s =
|
|
901
|
+
() => e.command(({ state: r, chain: n }) => {
|
|
902
|
+
const { node: i, endPos: a } = g(
|
|
903
|
+
r.doc,
|
|
904
|
+
r.selection.from
|
|
905
|
+
), s = r.selection.$anchor.parentOffset === 0, d = r.selection.anchor === r.selection.head, l = i.textContent.length === 0;
|
|
905
906
|
if (s && d && l) {
|
|
906
|
-
const c = a + 1,
|
|
907
|
-
return
|
|
907
|
+
const c = a + 1, h = c + 2;
|
|
908
|
+
return n().BNCreateBlock(c).setTextSelection(h).run(), !0;
|
|
908
909
|
}
|
|
909
910
|
return !1;
|
|
910
911
|
}),
|
|
911
912
|
// Splits the current block, moving content inside that's after the cursor to a new text block below. Also
|
|
912
913
|
// deletes the selection beforehand, if it's not empty.
|
|
913
|
-
() =>
|
|
914
|
-
const { node: i } =
|
|
915
|
-
|
|
916
|
-
|
|
914
|
+
() => e.command(({ state: r, chain: n }) => {
|
|
915
|
+
const { node: i } = g(
|
|
916
|
+
r.doc,
|
|
917
|
+
r.selection.from
|
|
917
918
|
);
|
|
918
|
-
return i.textContent.length === 0 ? !1 : (
|
|
919
|
+
return i.textContent.length === 0 ? !1 : (n().deleteSelection().BNSplitBlock(r.selection.from, !1).run(), !0);
|
|
919
920
|
})
|
|
920
921
|
]),
|
|
921
922
|
// Always returning true for tab key presses ensures they're not captured by the browser. Otherwise, they blur the
|
|
@@ -953,7 +954,7 @@ const at = C.create({
|
|
|
953
954
|
})
|
|
954
955
|
};
|
|
955
956
|
}
|
|
956
|
-
}),
|
|
957
|
+
}), ve = S.create({
|
|
957
958
|
name: "blockGroup",
|
|
958
959
|
group: "blockGroup",
|
|
959
960
|
content: "blockContainer+",
|
|
@@ -973,14 +974,14 @@ const at = C.create({
|
|
|
973
974
|
renderHTML({ HTMLAttributes: o }) {
|
|
974
975
|
return [
|
|
975
976
|
"div",
|
|
976
|
-
|
|
977
|
+
w(this.options.HTMLAttributes, o, {
|
|
977
978
|
class: b.blockGroup,
|
|
978
979
|
"data-node-type": "blockGroup"
|
|
979
980
|
}),
|
|
980
981
|
0
|
|
981
982
|
];
|
|
982
983
|
}
|
|
983
|
-
}),
|
|
984
|
+
}), Ee = S.create({
|
|
984
985
|
name: "paragraph",
|
|
985
986
|
group: "blockContent",
|
|
986
987
|
content: "inline*",
|
|
@@ -996,14 +997,14 @@ const at = C.create({
|
|
|
996
997
|
renderHTML({ HTMLAttributes: o }) {
|
|
997
998
|
return [
|
|
998
999
|
"div",
|
|
999
|
-
|
|
1000
|
+
w(o, {
|
|
1000
1001
|
class: b.blockContent,
|
|
1001
1002
|
"data-content-type": this.name
|
|
1002
1003
|
}),
|
|
1003
1004
|
["p", 0]
|
|
1004
1005
|
];
|
|
1005
1006
|
}
|
|
1006
|
-
}),
|
|
1007
|
+
}), Ce = S.create({
|
|
1007
1008
|
name: "heading",
|
|
1008
1009
|
group: "blockContent",
|
|
1009
1010
|
content: "inline*",
|
|
@@ -1021,15 +1022,15 @@ const at = C.create({
|
|
|
1021
1022
|
},
|
|
1022
1023
|
addInputRules() {
|
|
1023
1024
|
return [
|
|
1024
|
-
...["1", "2", "3"].map((o) => new
|
|
1025
|
+
...["1", "2", "3"].map((o) => new W({
|
|
1025
1026
|
find: new RegExp(`^(#{${parseInt(o)}})\\s$`),
|
|
1026
|
-
handler: ({ state:
|
|
1027
|
-
|
|
1027
|
+
handler: ({ state: t, chain: e, range: r }) => {
|
|
1028
|
+
e().BNUpdateBlock(t.selection.from, {
|
|
1028
1029
|
type: "heading",
|
|
1029
1030
|
props: {
|
|
1030
1031
|
level: o
|
|
1031
1032
|
}
|
|
1032
|
-
}).deleteRange({ from:
|
|
1033
|
+
}).deleteRange({ from: r.from, to: r.to });
|
|
1033
1034
|
}
|
|
1034
1035
|
}))
|
|
1035
1036
|
];
|
|
@@ -1053,25 +1054,25 @@ const at = C.create({
|
|
|
1053
1054
|
}
|
|
1054
1055
|
];
|
|
1055
1056
|
},
|
|
1056
|
-
renderHTML({ node: o, HTMLAttributes:
|
|
1057
|
+
renderHTML({ node: o, HTMLAttributes: t }) {
|
|
1057
1058
|
return [
|
|
1058
1059
|
"div",
|
|
1059
|
-
|
|
1060
|
+
w(t, {
|
|
1060
1061
|
class: b.blockContent,
|
|
1061
1062
|
"data-content-type": this.name
|
|
1062
1063
|
}),
|
|
1063
1064
|
["h" + o.attrs.level, 0]
|
|
1064
1065
|
];
|
|
1065
1066
|
}
|
|
1066
|
-
}),
|
|
1067
|
-
const { node:
|
|
1067
|
+
}), kt = (o) => {
|
|
1068
|
+
const { node: t, contentType: e } = g(
|
|
1068
1069
|
o.state.doc,
|
|
1069
1070
|
o.state.selection.from
|
|
1070
|
-
),
|
|
1071
|
-
return !
|
|
1071
|
+
), r = o.state.selection.anchor === o.state.selection.head;
|
|
1072
|
+
return !e.name.endsWith("ListItem") || !r ? !1 : o.commands.first(({ state: n, chain: i, commands: a }) => [
|
|
1072
1073
|
() => (
|
|
1073
1074
|
// Changes list item block to a text block if the content is empty.
|
|
1074
|
-
a.command(() =>
|
|
1075
|
+
a.command(() => t.textContent.length === 0 ? a.BNUpdateBlock(n.selection.from, {
|
|
1075
1076
|
type: "paragraph",
|
|
1076
1077
|
props: {}
|
|
1077
1078
|
}) : !1)
|
|
@@ -1079,30 +1080,30 @@ const at = C.create({
|
|
|
1079
1080
|
() => (
|
|
1080
1081
|
// Splits the current block, moving content inside that's after the cursor to a new block of the same type
|
|
1081
1082
|
// below.
|
|
1082
|
-
a.command(() =>
|
|
1083
|
+
a.command(() => t.textContent.length > 0 ? (i().deleteSelection().BNSplitBlock(n.selection.from, !0).run(), !0) : !1)
|
|
1083
1084
|
)
|
|
1084
1085
|
]);
|
|
1085
|
-
},
|
|
1086
|
+
}, Me = S.create({
|
|
1086
1087
|
name: "bulletListItem",
|
|
1087
1088
|
group: "blockContent",
|
|
1088
1089
|
content: "inline*",
|
|
1089
1090
|
addInputRules() {
|
|
1090
1091
|
return [
|
|
1091
1092
|
// Creates an unordered list when starting with "-", "+", or "*".
|
|
1092
|
-
new
|
|
1093
|
+
new W({
|
|
1093
1094
|
find: new RegExp("^[-+*]\\s$"),
|
|
1094
|
-
handler: ({ state: o, chain:
|
|
1095
|
-
|
|
1095
|
+
handler: ({ state: o, chain: t, range: e }) => {
|
|
1096
|
+
t().BNUpdateBlock(o.selection.from, {
|
|
1096
1097
|
type: "bulletListItem",
|
|
1097
1098
|
props: {}
|
|
1098
|
-
}).deleteRange({ from:
|
|
1099
|
+
}).deleteRange({ from: e.from, to: e.to });
|
|
1099
1100
|
}
|
|
1100
1101
|
})
|
|
1101
1102
|
];
|
|
1102
1103
|
},
|
|
1103
1104
|
addKeyboardShortcuts() {
|
|
1104
1105
|
return {
|
|
1105
|
-
Enter: () =>
|
|
1106
|
+
Enter: () => kt(this.editor)
|
|
1106
1107
|
};
|
|
1107
1108
|
},
|
|
1108
1109
|
parseHTML() {
|
|
@@ -1113,8 +1114,8 @@ const at = C.create({
|
|
|
1113
1114
|
getAttrs: (o) => {
|
|
1114
1115
|
if (typeof o == "string")
|
|
1115
1116
|
return !1;
|
|
1116
|
-
const
|
|
1117
|
-
return
|
|
1117
|
+
const t = o.parentElement;
|
|
1118
|
+
return t === null ? !1 : t.tagName === "UL" ? {} : !1;
|
|
1118
1119
|
},
|
|
1119
1120
|
node: "bulletListItem"
|
|
1120
1121
|
},
|
|
@@ -1124,8 +1125,8 @@ const at = C.create({
|
|
|
1124
1125
|
getAttrs: (o) => {
|
|
1125
1126
|
if (typeof o == "string")
|
|
1126
1127
|
return !1;
|
|
1127
|
-
const
|
|
1128
|
-
return
|
|
1128
|
+
const t = o.parentElement;
|
|
1129
|
+
return t === null ? !1 : t.getAttribute("data-content-type") === "bulletListItem" ? {} : !1;
|
|
1129
1130
|
},
|
|
1130
1131
|
priority: 300,
|
|
1131
1132
|
node: "bulletListItem"
|
|
@@ -1135,27 +1136,27 @@ const at = C.create({
|
|
|
1135
1136
|
renderHTML({ HTMLAttributes: o }) {
|
|
1136
1137
|
return [
|
|
1137
1138
|
"div",
|
|
1138
|
-
|
|
1139
|
+
w(o, {
|
|
1139
1140
|
class: b.blockContent,
|
|
1140
1141
|
"data-content-type": this.name
|
|
1141
1142
|
}),
|
|
1142
1143
|
["p", 0]
|
|
1143
1144
|
];
|
|
1144
1145
|
}
|
|
1145
|
-
}),
|
|
1146
|
-
key:
|
|
1147
|
-
appendTransaction: (o,
|
|
1148
|
-
const
|
|
1149
|
-
|
|
1150
|
-
let
|
|
1151
|
-
return
|
|
1146
|
+
}), Be = new v("numbered-list-indexing"), Te = () => new C({
|
|
1147
|
+
key: Be,
|
|
1148
|
+
appendTransaction: (o, t, e) => {
|
|
1149
|
+
const r = e.tr;
|
|
1150
|
+
r.setMeta("numberedListIndexing", !0);
|
|
1151
|
+
let n = !1;
|
|
1152
|
+
return e.doc.descendants((i, a) => {
|
|
1152
1153
|
if (i.type.name === "blockContainer" && i.firstChild.type.name === "numberedListItem") {
|
|
1153
1154
|
let s = "1";
|
|
1154
|
-
const d = a === 1, l =
|
|
1155
|
+
const d = a === 1, l = g(r.doc, a + 1);
|
|
1155
1156
|
if (l === void 0)
|
|
1156
1157
|
return;
|
|
1157
1158
|
if (!d) {
|
|
1158
|
-
const f =
|
|
1159
|
+
const f = g(r.doc, a - 2);
|
|
1159
1160
|
if (f === void 0)
|
|
1160
1161
|
return;
|
|
1161
1162
|
if (!(l.depth !== f.depth)) {
|
|
@@ -1166,13 +1167,13 @@ const at = C.create({
|
|
|
1166
1167
|
}
|
|
1167
1168
|
}
|
|
1168
1169
|
}
|
|
1169
|
-
l.contentNode.attrs.index !== s && (
|
|
1170
|
+
l.contentNode.attrs.index !== s && (n = !0, r.setNodeMarkup(a + 1, void 0, {
|
|
1170
1171
|
index: s
|
|
1171
1172
|
}));
|
|
1172
1173
|
}
|
|
1173
|
-
}),
|
|
1174
|
+
}), n ? r : null;
|
|
1174
1175
|
}
|
|
1175
|
-
}),
|
|
1176
|
+
}), we = S.create({
|
|
1176
1177
|
name: "numberedListItem",
|
|
1177
1178
|
group: "blockContent",
|
|
1178
1179
|
content: "inline*",
|
|
@@ -1190,24 +1191,24 @@ const at = C.create({
|
|
|
1190
1191
|
addInputRules() {
|
|
1191
1192
|
return [
|
|
1192
1193
|
// Creates an ordered list when starting with "1.".
|
|
1193
|
-
new
|
|
1194
|
+
new W({
|
|
1194
1195
|
find: new RegExp("^1\\.\\s$"),
|
|
1195
|
-
handler: ({ state: o, chain:
|
|
1196
|
-
|
|
1196
|
+
handler: ({ state: o, chain: t, range: e }) => {
|
|
1197
|
+
t().BNUpdateBlock(o.selection.from, {
|
|
1197
1198
|
type: "numberedListItem",
|
|
1198
1199
|
props: {}
|
|
1199
|
-
}).deleteRange({ from:
|
|
1200
|
+
}).deleteRange({ from: e.from, to: e.to });
|
|
1200
1201
|
}
|
|
1201
1202
|
})
|
|
1202
1203
|
];
|
|
1203
1204
|
},
|
|
1204
1205
|
addKeyboardShortcuts() {
|
|
1205
1206
|
return {
|
|
1206
|
-
Enter: () =>
|
|
1207
|
+
Enter: () => kt(this.editor)
|
|
1207
1208
|
};
|
|
1208
1209
|
},
|
|
1209
1210
|
addProseMirrorPlugins() {
|
|
1210
|
-
return [
|
|
1211
|
+
return [Te()];
|
|
1211
1212
|
},
|
|
1212
1213
|
parseHTML() {
|
|
1213
1214
|
return [
|
|
@@ -1218,8 +1219,8 @@ const at = C.create({
|
|
|
1218
1219
|
getAttrs: (o) => {
|
|
1219
1220
|
if (typeof o == "string")
|
|
1220
1221
|
return !1;
|
|
1221
|
-
const
|
|
1222
|
-
return
|
|
1222
|
+
const t = o.parentElement;
|
|
1223
|
+
return t === null ? !1 : t.tagName === "OL" ? {} : !1;
|
|
1223
1224
|
},
|
|
1224
1225
|
node: "numberedListItem"
|
|
1225
1226
|
},
|
|
@@ -1230,8 +1231,8 @@ const at = C.create({
|
|
|
1230
1231
|
getAttrs: (o) => {
|
|
1231
1232
|
if (typeof o == "string")
|
|
1232
1233
|
return !1;
|
|
1233
|
-
const
|
|
1234
|
-
return
|
|
1234
|
+
const t = o.parentElement;
|
|
1235
|
+
return t === null ? !1 : t.getAttribute("data-content-type") === "numberedListItem" ? {} : !1;
|
|
1235
1236
|
},
|
|
1236
1237
|
priority: 300,
|
|
1237
1238
|
node: "numberedListItem"
|
|
@@ -1241,7 +1242,7 @@ const at = C.create({
|
|
|
1241
1242
|
renderHTML({ HTMLAttributes: o }) {
|
|
1242
1243
|
return [
|
|
1243
1244
|
"div",
|
|
1244
|
-
|
|
1245
|
+
w(o, {
|
|
1245
1246
|
class: b.blockContent,
|
|
1246
1247
|
"data-content-type": this.name
|
|
1247
1248
|
}),
|
|
@@ -1250,24 +1251,24 @@ const at = C.create({
|
|
|
1250
1251
|
["p", 0]
|
|
1251
1252
|
];
|
|
1252
1253
|
}
|
|
1253
|
-
}),
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1254
|
+
}), Se = [
|
|
1255
|
+
Ee,
|
|
1256
|
+
Ce,
|
|
1257
|
+
Me,
|
|
1258
|
+
we,
|
|
1259
|
+
be,
|
|
1260
|
+
ve,
|
|
1261
|
+
S.create({
|
|
1261
1262
|
name: "doc",
|
|
1262
1263
|
topNode: !0,
|
|
1263
1264
|
content: "blockGroup"
|
|
1264
1265
|
})
|
|
1265
|
-
],
|
|
1266
|
-
bnEditor:
|
|
1267
|
-
bnRoot:
|
|
1268
|
-
defaultStyles:
|
|
1269
|
-
dragPreview:
|
|
1270
|
-
},
|
|
1266
|
+
], xe = "_bnEditor_dbz5y_3", Ie = "_bnRoot_dbz5y_20", Pe = "_defaultStyles_dbz5y_35", Le = "_dragPreview_dbz5y_66", O = {
|
|
1267
|
+
bnEditor: xe,
|
|
1268
|
+
bnRoot: Ie,
|
|
1269
|
+
defaultStyles: Pe,
|
|
1270
|
+
dragPreview: Le
|
|
1271
|
+
}, Ae = wt(
|
|
1271
1272
|
(o) => o.type.name === "blockContainer"
|
|
1272
1273
|
);
|
|
1273
1274
|
function q() {
|
|
@@ -1281,78 +1282,84 @@ function q() {
|
|
|
1281
1282
|
decorationId: void 0
|
|
1282
1283
|
};
|
|
1283
1284
|
}
|
|
1284
|
-
class
|
|
1285
|
+
class He {
|
|
1285
1286
|
constructor({
|
|
1286
|
-
editor:
|
|
1287
|
-
pluginKey:
|
|
1288
|
-
onSelectItem:
|
|
1287
|
+
editor: t,
|
|
1288
|
+
pluginKey: e,
|
|
1289
|
+
onSelectItem: r = () => {
|
|
1289
1290
|
},
|
|
1290
|
-
suggestionsMenuFactory:
|
|
1291
|
+
suggestionsMenuFactory: n
|
|
1291
1292
|
}) {
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
this
|
|
1298
|
-
|
|
1293
|
+
u(this, "editor");
|
|
1294
|
+
u(this, "pluginKey");
|
|
1295
|
+
u(this, "suggestionsMenu");
|
|
1296
|
+
u(this, "pluginState");
|
|
1297
|
+
u(this, "itemCallback");
|
|
1298
|
+
u(this, "handleScroll", () => {
|
|
1299
|
+
this.pluginKey.getState(this.editor._tiptapEditor.state).active && this.suggestionsMenu.render(this.getDynamicParams(), !1);
|
|
1300
|
+
});
|
|
1301
|
+
this.editor = t, this.pluginKey = e, this.pluginState = q(), this.itemCallback = (i) => {
|
|
1302
|
+
t._tiptapEditor.chain().focus().deleteRange({
|
|
1299
1303
|
from: this.pluginState.queryStartPos - this.pluginState.triggerCharacter.length,
|
|
1300
|
-
to:
|
|
1301
|
-
}).run(),
|
|
1304
|
+
to: t._tiptapEditor.state.selection.from
|
|
1305
|
+
}).run(), r({
|
|
1302
1306
|
item: i,
|
|
1303
|
-
editor:
|
|
1307
|
+
editor: t
|
|
1304
1308
|
});
|
|
1305
|
-
}, this.suggestionsMenu =
|
|
1309
|
+
}, this.suggestionsMenu = n(this.getStaticParams()), document.addEventListener("scroll", this.handleScroll);
|
|
1306
1310
|
}
|
|
1307
|
-
update(
|
|
1308
|
-
const
|
|
1309
|
-
!i && !s && !a || (this.pluginState = a ?
|
|
1311
|
+
update(t, e) {
|
|
1312
|
+
const r = this.pluginKey.getState(e), n = this.pluginKey.getState(t.state), i = !r.active && n.active, a = r.active && !n.active, s = r.active && n.active;
|
|
1313
|
+
!i && !s && !a || (this.pluginState = a ? r : n, (a || !this.editor.isEditable) && (this.suggestionsMenu.hide(), this.suggestionsMenu.element.removeEventListener(
|
|
1310
1314
|
"mousedown",
|
|
1311
1315
|
(d) => d.preventDefault()
|
|
1312
|
-
)), s && this.suggestionsMenu.render(this.getDynamicParams(), !1), i && (this.suggestionsMenu.render(this.getDynamicParams(), !0), this.suggestionsMenu.element.addEventListener(
|
|
1316
|
+
)), s && this.suggestionsMenu.render(this.getDynamicParams(), !1), i && this.editor.isEditable && (this.suggestionsMenu.render(this.getDynamicParams(), !0), this.suggestionsMenu.element.addEventListener(
|
|
1313
1317
|
"mousedown",
|
|
1314
1318
|
(d) => d.preventDefault()
|
|
1315
1319
|
)));
|
|
1316
1320
|
}
|
|
1321
|
+
destroy() {
|
|
1322
|
+
document.removeEventListener("scroll", this.handleScroll);
|
|
1323
|
+
}
|
|
1317
1324
|
getStaticParams() {
|
|
1318
1325
|
return {
|
|
1319
|
-
itemCallback: (
|
|
1326
|
+
itemCallback: (t) => this.itemCallback(t)
|
|
1320
1327
|
};
|
|
1321
1328
|
}
|
|
1322
1329
|
getDynamicParams() {
|
|
1323
|
-
const
|
|
1330
|
+
const t = document.querySelector(
|
|
1324
1331
|
`[data-decoration-id="${this.pluginState.decorationId}"]`
|
|
1325
1332
|
);
|
|
1326
1333
|
return {
|
|
1327
1334
|
items: this.pluginState.items,
|
|
1328
1335
|
keyboardHoveredItemIndex: this.pluginState.keyboardHoveredItemIndex,
|
|
1329
|
-
referenceRect:
|
|
1336
|
+
referenceRect: t.getBoundingClientRect()
|
|
1330
1337
|
};
|
|
1331
1338
|
}
|
|
1332
1339
|
}
|
|
1333
|
-
function
|
|
1340
|
+
function Ne({
|
|
1334
1341
|
pluginKey: o,
|
|
1335
|
-
editor:
|
|
1336
|
-
defaultTriggerCharacter:
|
|
1337
|
-
suggestionsMenuFactory:
|
|
1338
|
-
onSelectItem:
|
|
1342
|
+
editor: t,
|
|
1343
|
+
defaultTriggerCharacter: e,
|
|
1344
|
+
suggestionsMenuFactory: r,
|
|
1345
|
+
onSelectItem: n = () => {
|
|
1339
1346
|
},
|
|
1340
1347
|
items: i = () => []
|
|
1341
1348
|
}) {
|
|
1342
|
-
if (
|
|
1349
|
+
if (e.length !== 1)
|
|
1343
1350
|
throw new Error("'char' should be a single character");
|
|
1344
1351
|
const a = (s) => {
|
|
1345
1352
|
s.dispatch(s.state.tr.setMeta(o, { deactivate: !0 }));
|
|
1346
1353
|
};
|
|
1347
|
-
return new
|
|
1354
|
+
return new C({
|
|
1348
1355
|
key: o,
|
|
1349
|
-
view: (s) => new
|
|
1350
|
-
editor:
|
|
1356
|
+
view: (s) => new He({
|
|
1357
|
+
editor: t,
|
|
1351
1358
|
pluginKey: o,
|
|
1352
1359
|
onSelectItem: (d) => {
|
|
1353
|
-
a(s),
|
|
1360
|
+
a(s), n(d);
|
|
1354
1361
|
},
|
|
1355
|
-
suggestionsMenuFactory:
|
|
1362
|
+
suggestionsMenuFactory: r
|
|
1356
1363
|
}),
|
|
1357
1364
|
state: {
|
|
1358
1365
|
// Initialize the plugin's internal state.
|
|
@@ -1378,10 +1385,10 @@ function Ht({
|
|
|
1378
1385
|
};
|
|
1379
1386
|
if (!d.active)
|
|
1380
1387
|
return d;
|
|
1381
|
-
const
|
|
1382
|
-
if (
|
|
1388
|
+
const h = { ...d };
|
|
1389
|
+
if (h.items = i(
|
|
1383
1390
|
c.doc.textBetween(d.queryStartPos, c.selection.from)
|
|
1384
|
-
),
|
|
1391
|
+
), h.notFoundCount = 0, h.items.length === 0 && (h.notFoundCount = Math.max(
|
|
1385
1392
|
0,
|
|
1386
1393
|
d.notFoundCount + (c.selection.from - l.selection.from)
|
|
1387
1394
|
)), // Highlighting text should hide the menu.
|
|
@@ -1391,30 +1398,30 @@ function Ht({
|
|
|
1391
1398
|
s.getMeta("focus") || s.getMeta("blur") || s.getMeta("pointer") || // Moving the caret before the character which triggered the menu should hide it.
|
|
1392
1399
|
d.active && c.selection.from < d.queryStartPos || // Entering more than 3 characters, after the last query that matched with at least 1 menu item, should hide
|
|
1393
1400
|
// the menu.
|
|
1394
|
-
|
|
1401
|
+
h.notFoundCount > 3)
|
|
1395
1402
|
return q();
|
|
1396
1403
|
if (((y = s.getMeta(o)) == null ? void 0 : y.selectedItemIndexChanged) !== void 0) {
|
|
1397
|
-
let
|
|
1398
|
-
|
|
1404
|
+
let k = s.getMeta(o).selectedItemIndexChanged;
|
|
1405
|
+
k < 0 ? k = d.items.length - 1 : k >= d.items.length && (k = 0), h.keyboardHoveredItemIndex = k;
|
|
1399
1406
|
}
|
|
1400
|
-
return
|
|
1407
|
+
return h;
|
|
1401
1408
|
}
|
|
1402
1409
|
},
|
|
1403
1410
|
props: {
|
|
1404
1411
|
handleKeyDown(s, d) {
|
|
1405
1412
|
const l = this.getState(s.state).active;
|
|
1406
|
-
if (d.key ===
|
|
1413
|
+
if (d.key === e && !l)
|
|
1407
1414
|
return s.dispatch(
|
|
1408
|
-
s.state.tr.insertText(
|
|
1415
|
+
s.state.tr.insertText(e).scrollIntoView().setMeta(o, {
|
|
1409
1416
|
activate: !0,
|
|
1410
|
-
triggerCharacter:
|
|
1417
|
+
triggerCharacter: e
|
|
1411
1418
|
})
|
|
1412
1419
|
), !0;
|
|
1413
1420
|
if (!l)
|
|
1414
1421
|
return !1;
|
|
1415
1422
|
const {
|
|
1416
1423
|
triggerCharacter: c,
|
|
1417
|
-
queryStartPos:
|
|
1424
|
+
queryStartPos: h,
|
|
1418
1425
|
items: f,
|
|
1419
1426
|
keyboardHoveredItemIndex: p
|
|
1420
1427
|
} = o.getState(s.state);
|
|
@@ -1426,12 +1433,12 @@ function Ht({
|
|
|
1426
1433
|
s.state.tr.setMeta(o, {
|
|
1427
1434
|
selectedItemIndexChanged: p + 1
|
|
1428
1435
|
})
|
|
1429
|
-
), !0) : d.key === "Enter" ? (a(s),
|
|
1430
|
-
from:
|
|
1431
|
-
to:
|
|
1432
|
-
}).run(),
|
|
1436
|
+
), !0) : d.key === "Enter" ? (a(s), t._tiptapEditor.chain().focus().deleteRange({
|
|
1437
|
+
from: h - c.length,
|
|
1438
|
+
to: t._tiptapEditor.state.selection.from
|
|
1439
|
+
}).run(), n({
|
|
1433
1440
|
item: f[p],
|
|
1434
|
-
editor:
|
|
1441
|
+
editor: t
|
|
1435
1442
|
}), !0) : d.key === "Escape" ? (a(s), !0) : !1;
|
|
1436
1443
|
},
|
|
1437
1444
|
// Hides menu in cases where mouse click does not cause an editor state change.
|
|
@@ -1440,11 +1447,11 @@ function Ht({
|
|
|
1440
1447
|
},
|
|
1441
1448
|
// Setup decorator on the currently active suggestion.
|
|
1442
1449
|
decorations(s) {
|
|
1443
|
-
const { active: d, decorationId: l, queryStartPos: c, triggerCharacter:
|
|
1450
|
+
const { active: d, decorationId: l, queryStartPos: c, triggerCharacter: h } = this.getState(s);
|
|
1444
1451
|
if (!d)
|
|
1445
1452
|
return null;
|
|
1446
|
-
if (
|
|
1447
|
-
const f =
|
|
1453
|
+
if (h === "") {
|
|
1454
|
+
const f = Ae(s.selection);
|
|
1448
1455
|
if (f)
|
|
1449
1456
|
return F.create(s.doc, [
|
|
1450
1457
|
D.node(
|
|
@@ -1460,7 +1467,7 @@ function Ht({
|
|
|
1460
1467
|
}
|
|
1461
1468
|
return F.create(s.doc, [
|
|
1462
1469
|
D.inline(
|
|
1463
|
-
c -
|
|
1470
|
+
c - h.length,
|
|
1464
1471
|
c,
|
|
1465
1472
|
{
|
|
1466
1473
|
nodeName: "span",
|
|
@@ -1473,7 +1480,7 @@ function Ht({
|
|
|
1473
1480
|
}
|
|
1474
1481
|
});
|
|
1475
1482
|
}
|
|
1476
|
-
const
|
|
1483
|
+
const V = new v("suggestions-slash-commands"), _e = E.create({
|
|
1477
1484
|
name: "slash-command",
|
|
1478
1485
|
addOptions() {
|
|
1479
1486
|
return {
|
|
@@ -1487,162 +1494,172 @@ const K = new v("suggestions-slash-commands"), Ot = C.create({
|
|
|
1487
1494
|
throw new Error("required args not defined for SlashMenuExtension");
|
|
1488
1495
|
const o = this.options.commands;
|
|
1489
1496
|
return [
|
|
1490
|
-
|
|
1491
|
-
pluginKey:
|
|
1497
|
+
Ne({
|
|
1498
|
+
pluginKey: V,
|
|
1492
1499
|
editor: this.options.editor,
|
|
1493
1500
|
defaultTriggerCharacter: "/",
|
|
1494
1501
|
suggestionsMenuFactory: this.options.slashMenuFactory,
|
|
1495
|
-
items: (
|
|
1496
|
-
onSelectItem: ({ item:
|
|
1497
|
-
|
|
1502
|
+
items: (t) => o.filter((e) => e.match(t)),
|
|
1503
|
+
onSelectItem: ({ item: t, editor: e }) => {
|
|
1504
|
+
t.execute(e);
|
|
1498
1505
|
}
|
|
1499
1506
|
})
|
|
1500
1507
|
];
|
|
1501
1508
|
}
|
|
1502
1509
|
});
|
|
1503
|
-
class
|
|
1504
|
-
constructor(
|
|
1505
|
-
super(
|
|
1506
|
-
|
|
1507
|
-
const
|
|
1508
|
-
this.nodes = [],
|
|
1509
|
-
if (s !== null && s.eq(
|
|
1510
|
+
class A extends G {
|
|
1511
|
+
constructor(e, r) {
|
|
1512
|
+
super(e, r);
|
|
1513
|
+
u(this, "nodes");
|
|
1514
|
+
const n = e.node();
|
|
1515
|
+
this.nodes = [], e.doc.nodesBetween(e.pos, r.pos, (i, a, s) => {
|
|
1516
|
+
if (s !== null && s.eq(n))
|
|
1510
1517
|
return this.nodes.push(i), !1;
|
|
1511
1518
|
});
|
|
1512
1519
|
}
|
|
1513
|
-
static create(
|
|
1514
|
-
return new
|
|
1520
|
+
static create(e, r, n = r) {
|
|
1521
|
+
return new A(e.resolve(r), e.resolve(n));
|
|
1515
1522
|
}
|
|
1516
1523
|
content() {
|
|
1517
|
-
return new
|
|
1524
|
+
return new P(L.from(this.nodes), 0, 0);
|
|
1518
1525
|
}
|
|
1519
|
-
eq(
|
|
1520
|
-
if (!(
|
|
1526
|
+
eq(e) {
|
|
1527
|
+
if (!(e instanceof A) || this.nodes.length !== e.nodes.length || this.from !== e.from || this.to !== e.to)
|
|
1521
1528
|
return !1;
|
|
1522
|
-
for (let
|
|
1523
|
-
if (!this.nodes[
|
|
1529
|
+
for (let r = 0; r < this.nodes.length; r++)
|
|
1530
|
+
if (!this.nodes[r].eq(e.nodes[r]))
|
|
1524
1531
|
return !1;
|
|
1525
1532
|
return !0;
|
|
1526
1533
|
}
|
|
1527
|
-
map(
|
|
1528
|
-
let
|
|
1529
|
-
return i.deleted ? G.near(
|
|
1530
|
-
|
|
1531
|
-
|
|
1534
|
+
map(e, r) {
|
|
1535
|
+
let n = r.mapResult(this.from), i = r.mapResult(this.to);
|
|
1536
|
+
return i.deleted ? G.near(e.resolve(n.pos)) : n.deleted ? G.near(e.resolve(i.pos)) : new A(
|
|
1537
|
+
e.resolve(n.pos),
|
|
1538
|
+
e.resolve(i.pos)
|
|
1532
1539
|
);
|
|
1533
1540
|
}
|
|
1534
1541
|
toJSON() {
|
|
1535
1542
|
return { type: "node", anchor: this.anchor, head: this.head };
|
|
1536
1543
|
}
|
|
1537
1544
|
}
|
|
1538
|
-
const
|
|
1539
|
-
let
|
|
1540
|
-
function
|
|
1541
|
-
var
|
|
1542
|
-
if (!
|
|
1545
|
+
const Oe = Kt.__serializeForClipboard;
|
|
1546
|
+
let T;
|
|
1547
|
+
function yt(o, t) {
|
|
1548
|
+
var n;
|
|
1549
|
+
if (!t.dom.isConnected)
|
|
1543
1550
|
return;
|
|
1544
|
-
let
|
|
1545
|
-
if (!
|
|
1551
|
+
let e = t.posAtCoords(o);
|
|
1552
|
+
if (!e)
|
|
1546
1553
|
return;
|
|
1547
|
-
let
|
|
1548
|
-
if (
|
|
1549
|
-
for (;
|
|
1550
|
-
|
|
1551
|
-
if (
|
|
1552
|
-
return { node:
|
|
1554
|
+
let r = t.domAtPos(e.pos).node;
|
|
1555
|
+
if (r !== t.dom) {
|
|
1556
|
+
for (; r && r.parentNode && r.parentNode !== t.dom && !((n = r.hasAttribute) != null && n.call(r, "data-id")); )
|
|
1557
|
+
r = r.parentNode;
|
|
1558
|
+
if (r)
|
|
1559
|
+
return { node: r, id: r.getAttribute("data-id") };
|
|
1553
1560
|
}
|
|
1554
1561
|
}
|
|
1555
|
-
function
|
|
1556
|
-
let
|
|
1557
|
-
if (
|
|
1558
|
-
const
|
|
1559
|
-
let
|
|
1560
|
-
return !
|
|
1562
|
+
function De(o, t) {
|
|
1563
|
+
let e = yt(o, t);
|
|
1564
|
+
if (e && e.node.nodeType === 1) {
|
|
1565
|
+
const r = t.docView;
|
|
1566
|
+
let n = r.nearestDesc(e.node, !0);
|
|
1567
|
+
return !n || n === r ? null : n.posBefore;
|
|
1561
1568
|
}
|
|
1562
1569
|
return null;
|
|
1563
1570
|
}
|
|
1564
|
-
function
|
|
1565
|
-
let
|
|
1566
|
-
const
|
|
1567
|
-
if (
|
|
1571
|
+
function Fe(o, t) {
|
|
1572
|
+
let e, r;
|
|
1573
|
+
const n = t.resolve(o.from).node().type.spec.group === "blockContent", i = t.resolve(o.to).node().type.spec.group === "blockContent", a = Math.min(o.$anchor.depth, o.$head.depth);
|
|
1574
|
+
if (n && i) {
|
|
1568
1575
|
const s = o.$from.start(a - 1), d = o.$to.end(a - 1);
|
|
1569
|
-
|
|
1576
|
+
e = t.resolve(s - 1).pos, r = t.resolve(d + 1).pos;
|
|
1570
1577
|
} else
|
|
1571
|
-
|
|
1572
|
-
return { from:
|
|
1578
|
+
e = o.from, r = o.to;
|
|
1579
|
+
return { from: e, to: r };
|
|
1573
1580
|
}
|
|
1574
|
-
function
|
|
1575
|
-
|
|
1576
|
-
const
|
|
1577
|
-
|
|
1581
|
+
function ot(o, t, e = t) {
|
|
1582
|
+
t === e && (e += o.state.doc.resolve(t + 1).node().nodeSize);
|
|
1583
|
+
const r = o.domAtPos(t).node.cloneNode(!0), n = o.domAtPos(t).node, i = (c, h) => Array.prototype.indexOf.call(c.children, h), a = i(
|
|
1584
|
+
n,
|
|
1578
1585
|
// Expects from position to be just before the first selected block.
|
|
1579
|
-
o.domAtPos(
|
|
1586
|
+
o.domAtPos(t + 1).node.parentElement
|
|
1580
1587
|
), s = i(
|
|
1581
|
-
|
|
1588
|
+
n,
|
|
1582
1589
|
// Expects to position to be just after the last selected block.
|
|
1583
|
-
o.domAtPos(
|
|
1590
|
+
o.domAtPos(e - 1).node.parentElement
|
|
1584
1591
|
);
|
|
1585
|
-
for (let c =
|
|
1586
|
-
(c > s || c < a) &&
|
|
1587
|
-
|
|
1592
|
+
for (let c = n.childElementCount - 1; c >= 0; c--)
|
|
1593
|
+
(c > s || c < a) && r.removeChild(r.children[c]);
|
|
1594
|
+
bt(), T = r;
|
|
1588
1595
|
const l = o.dom.className.split(" ").filter(
|
|
1589
1596
|
(c) => !c.includes("bn") && !c.includes("ProseMirror") && !c.includes("editor")
|
|
1590
1597
|
).join(" ");
|
|
1591
|
-
|
|
1598
|
+
T.className = T.className + " " + O.dragPreview + " " + l, document.body.appendChild(T);
|
|
1592
1599
|
}
|
|
1593
|
-
function
|
|
1594
|
-
|
|
1600
|
+
function bt() {
|
|
1601
|
+
T !== void 0 && (document.body.removeChild(T), T = void 0);
|
|
1595
1602
|
}
|
|
1596
|
-
function
|
|
1603
|
+
function Re(o, t) {
|
|
1597
1604
|
if (!o.dataTransfer)
|
|
1598
1605
|
return;
|
|
1599
|
-
const
|
|
1600
|
-
let
|
|
1601
|
-
left:
|
|
1606
|
+
const e = t.dom.getBoundingClientRect();
|
|
1607
|
+
let r = {
|
|
1608
|
+
left: e.left + e.width / 2,
|
|
1602
1609
|
// take middle of editor
|
|
1603
1610
|
top: o.clientY
|
|
1604
|
-
},
|
|
1605
|
-
if (
|
|
1606
|
-
const i =
|
|
1607
|
-
l && c ? (
|
|
1608
|
-
|
|
1609
|
-
),
|
|
1610
|
-
|
|
1611
|
-
),
|
|
1612
|
-
let
|
|
1613
|
-
o.dataTransfer.clearData(), o.dataTransfer.setData("text/html", f.innerHTML), o.dataTransfer.setData("text/plain", p), o.dataTransfer.effectAllowed = "move", o.dataTransfer.setDragImage(
|
|
1611
|
+
}, n = De(r, t);
|
|
1612
|
+
if (n != null) {
|
|
1613
|
+
const i = t.state.selection, a = t.state.doc, { from: s, to: d } = Fe(i, a), l = s <= n && n < d, c = i.$anchor.node() !== i.$head.node() || i instanceof A;
|
|
1614
|
+
l && c ? (t.dispatch(
|
|
1615
|
+
t.state.tr.setSelection(A.create(a, s, d))
|
|
1616
|
+
), ot(t, s, d)) : (t.dispatch(
|
|
1617
|
+
t.state.tr.setSelection(At.create(t.state.doc, n))
|
|
1618
|
+
), ot(t, n));
|
|
1619
|
+
let h = t.state.selection.content(), { dom: f, text: p } = Oe(t, h);
|
|
1620
|
+
o.dataTransfer.clearData(), o.dataTransfer.setData("text/html", f.innerHTML), o.dataTransfer.setData("text/plain", p), o.dataTransfer.effectAllowed = "move", o.dataTransfer.setDragImage(T, 0, 0), t.dragging = { slice: h, move: !0 };
|
|
1614
1621
|
}
|
|
1615
1622
|
}
|
|
1616
|
-
class
|
|
1623
|
+
class ze {
|
|
1617
1624
|
constructor({
|
|
1625
|
+
tiptapEditor: t,
|
|
1618
1626
|
editor: e,
|
|
1619
|
-
blockMenuFactory:
|
|
1627
|
+
blockMenuFactory: r,
|
|
1620
1628
|
horizontalPosAnchoredAtRoot: n
|
|
1621
1629
|
}) {
|
|
1622
|
-
|
|
1630
|
+
u(this, "editor");
|
|
1631
|
+
u(this, "ttEditor");
|
|
1623
1632
|
// When true, the drag handle with be anchored at the same level as root elements
|
|
1624
1633
|
// When false, the drag handle with be just to the left of the element
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1634
|
+
u(this, "horizontalPosAnchoredAtRoot");
|
|
1635
|
+
u(this, "horizontalPosAnchor");
|
|
1636
|
+
u(this, "blockMenu");
|
|
1637
|
+
u(this, "hoveredBlock");
|
|
1638
|
+
// Used to check if currently dragged content comes from this editor instance.
|
|
1639
|
+
u(this, "isDragging", !1);
|
|
1640
|
+
u(this, "menuOpen", !1);
|
|
1641
|
+
u(this, "menuFrozen", !1);
|
|
1631
1642
|
/**
|
|
1632
|
-
*
|
|
1643
|
+
* Sets isDragging when dragging text.
|
|
1644
|
+
*/
|
|
1645
|
+
u(this, "onDragStart", () => {
|
|
1646
|
+
this.isDragging = !0;
|
|
1647
|
+
});
|
|
1648
|
+
/**
|
|
1649
|
+
* If the event is outside the editor contents,
|
|
1633
1650
|
* we dispatch a fake event, so that we can still drop the content
|
|
1634
1651
|
* when dragging / dropping to the side of the editor
|
|
1635
1652
|
*/
|
|
1636
|
-
|
|
1637
|
-
if (
|
|
1653
|
+
u(this, "onDrop", (t) => {
|
|
1654
|
+
if (t.synthetic || !this.isDragging)
|
|
1638
1655
|
return;
|
|
1639
|
-
let
|
|
1640
|
-
left:
|
|
1641
|
-
top:
|
|
1656
|
+
let e = this.ttEditor.view.posAtCoords({
|
|
1657
|
+
left: t.clientX,
|
|
1658
|
+
top: t.clientY
|
|
1642
1659
|
});
|
|
1643
|
-
if (!
|
|
1644
|
-
const
|
|
1645
|
-
|
|
1660
|
+
if (this.isDragging = !1, !e || e.inside === -1) {
|
|
1661
|
+
const r = new Event("drop", t), n = this.ttEditor.view.dom.firstChild.getBoundingClientRect();
|
|
1662
|
+
r.clientX = n.left + n.width / 2, r.clientY = t.clientY, r.dataTransfer = t.dataTransfer, r.preventDefault = () => t.preventDefault(), r.synthetic = !0, this.ttEditor.view.dom.dispatchEvent(r);
|
|
1646
1663
|
}
|
|
1647
1664
|
});
|
|
1648
1665
|
/**
|
|
@@ -1650,120 +1667,95 @@ class zt {
|
|
|
1650
1667
|
* we dispatch a fake event, so that we can still drop the content
|
|
1651
1668
|
* when dragging / dropping to the side of the editor
|
|
1652
1669
|
*/
|
|
1653
|
-
|
|
1654
|
-
if (
|
|
1670
|
+
u(this, "onDragOver", (t) => {
|
|
1671
|
+
if (t.synthetic || !this.isDragging)
|
|
1655
1672
|
return;
|
|
1656
|
-
let
|
|
1657
|
-
left:
|
|
1658
|
-
top:
|
|
1673
|
+
let e = this.ttEditor.view.posAtCoords({
|
|
1674
|
+
left: t.clientX,
|
|
1675
|
+
top: t.clientY
|
|
1659
1676
|
});
|
|
1660
|
-
if (!
|
|
1661
|
-
const
|
|
1662
|
-
|
|
1677
|
+
if (!e || e.inside === -1) {
|
|
1678
|
+
const r = new Event("dragover", t), n = this.ttEditor.view.dom.firstChild.getBoundingClientRect();
|
|
1679
|
+
r.clientX = n.left + n.width / 2, r.clientY = t.clientY, r.dataTransfer = t.dataTransfer, r.preventDefault = () => t.preventDefault(), r.synthetic = !0, this.ttEditor.view.dom.dispatchEvent(r);
|
|
1663
1680
|
}
|
|
1664
1681
|
});
|
|
1665
|
-
|
|
1682
|
+
u(this, "onKeyDown", (t) => {
|
|
1666
1683
|
this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide()), this.menuFrozen = !1;
|
|
1667
1684
|
});
|
|
1668
|
-
|
|
1669
|
-
var
|
|
1670
|
-
(
|
|
1685
|
+
u(this, "onMouseDown", (t) => {
|
|
1686
|
+
var e;
|
|
1687
|
+
(e = this.blockMenu.element) != null && e.contains(t.target) || (this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide()), this.menuFrozen = !1);
|
|
1671
1688
|
});
|
|
1672
|
-
|
|
1689
|
+
u(this, "onMouseMove", (t) => {
|
|
1673
1690
|
var a, s;
|
|
1674
1691
|
if (this.menuFrozen)
|
|
1675
1692
|
return;
|
|
1676
|
-
const
|
|
1677
|
-
this.horizontalPosAnchor =
|
|
1678
|
-
const
|
|
1679
|
-
left:
|
|
1693
|
+
const e = this.ttEditor.view.dom.firstChild.getBoundingClientRect();
|
|
1694
|
+
this.horizontalPosAnchor = e.x;
|
|
1695
|
+
const r = {
|
|
1696
|
+
left: e.left + e.width / 2,
|
|
1680
1697
|
// take middle of editor
|
|
1681
|
-
top:
|
|
1682
|
-
},
|
|
1683
|
-
if (!
|
|
1698
|
+
top: t.clientY
|
|
1699
|
+
}, n = yt(r, this.ttEditor.view);
|
|
1700
|
+
if (!n || !this.editor.isEditable) {
|
|
1684
1701
|
this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide());
|
|
1685
1702
|
return;
|
|
1686
1703
|
}
|
|
1687
|
-
|
|
1688
|
-
return;
|
|
1689
|
-
const i = r.node.firstChild;
|
|
1690
|
-
this.hoveredBlockContent = i, i && (this.menuOpen ? this.blockMenu.render(this.getDynamicParams(), !1) : (this.menuOpen = !0, this.blockMenu.render(this.getDynamicParams(), !0)));
|
|
1704
|
+
this.menuOpen && ((a = this.hoveredBlock) != null && a.hasAttribute("data-id")) && ((s = this.hoveredBlock) == null ? void 0 : s.getAttribute("data-id")) === n.id || (this.hoveredBlock = n.node, !n.node.firstChild) || this.editor.isEditable && (this.menuOpen ? this.blockMenu.render(this.getDynamicParams(), !1) : (this.menuOpen = !0, this.blockMenu.render(this.getDynamicParams(), !0)));
|
|
1691
1705
|
});
|
|
1692
|
-
|
|
1706
|
+
u(this, "onScroll", () => {
|
|
1707
|
+
this.menuOpen && this.blockMenu.render(this.getDynamicParams(), !1);
|
|
1708
|
+
});
|
|
1709
|
+
this.editor = e, this.ttEditor = t, this.horizontalPosAnchoredAtRoot = n, this.horizontalPosAnchor = this.ttEditor.view.dom.firstChild.getBoundingClientRect().x, this.blockMenu = r(this.getStaticParams()), document.body.addEventListener("drop", this.onDrop, !0), document.body.addEventListener("dragover", this.onDragOver), this.ttEditor.view.dom.addEventListener("dragstart", this.onDragStart), document.body.addEventListener("mousemove", this.onMouseMove, !0), document.addEventListener("scroll", this.onScroll), document.body.addEventListener("mousedown", this.onMouseDown, !0), document.body.addEventListener("keydown", this.onKeyDown, !0);
|
|
1693
1710
|
}
|
|
1694
1711
|
destroy() {
|
|
1695
|
-
this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide()), document.body.removeEventListener("mousemove", this.onMouseMove), document.body.removeEventListener("dragover", this.onDragOver), document.body.removeEventListener("drop", this.onDrop), document.body.removeEventListener("mousedown", this.onMouseDown), document.body.removeEventListener("keydown", this.onKeyDown);
|
|
1712
|
+
this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide()), document.body.removeEventListener("mousemove", this.onMouseMove), document.body.removeEventListener("dragover", this.onDragOver), this.ttEditor.view.dom.removeEventListener("dragstart", this.onDragStart), document.body.removeEventListener("drop", this.onDrop), document.body.removeEventListener("mousedown", this.onMouseDown), document.removeEventListener("scroll", this.onScroll), document.body.removeEventListener("keydown", this.onKeyDown);
|
|
1696
1713
|
}
|
|
1697
1714
|
addBlock() {
|
|
1698
1715
|
this.menuOpen = !1, this.menuFrozen = !0, this.blockMenu.hide();
|
|
1699
|
-
const e = this.
|
|
1716
|
+
const e = this.hoveredBlock.firstChild.getBoundingClientRect(), r = this.ttEditor.view.posAtCoords({
|
|
1700
1717
|
left: e.left + e.width / 2,
|
|
1701
1718
|
top: e.top + e.height / 2
|
|
1702
1719
|
});
|
|
1703
|
-
if (!
|
|
1720
|
+
if (!r)
|
|
1704
1721
|
return;
|
|
1705
|
-
const n =
|
|
1722
|
+
const n = g(this.ttEditor.state.doc, r.pos);
|
|
1706
1723
|
if (n === void 0)
|
|
1707
1724
|
return;
|
|
1708
|
-
const { contentNode:
|
|
1709
|
-
if (
|
|
1710
|
-
const
|
|
1711
|
-
this.
|
|
1725
|
+
const { contentNode: i, endPos: a } = n;
|
|
1726
|
+
if (i.textContent.length !== 0) {
|
|
1727
|
+
const s = a + 1, d = s + 2;
|
|
1728
|
+
this.ttEditor.chain().BNCreateBlock(s).BNUpdateBlock(d, { type: "paragraph", props: {} }).setTextSelection(d).run();
|
|
1712
1729
|
} else
|
|
1713
|
-
this.
|
|
1714
|
-
this.
|
|
1715
|
-
this.
|
|
1730
|
+
this.ttEditor.commands.setTextSelection(a);
|
|
1731
|
+
this.ttEditor.view.focus(), this.ttEditor.view.dispatch(
|
|
1732
|
+
this.ttEditor.view.state.tr.scrollIntoView().setMeta(V, {
|
|
1716
1733
|
// TODO import suggestion plugin key
|
|
1717
1734
|
activate: !0,
|
|
1718
1735
|
type: "drag"
|
|
1719
1736
|
})
|
|
1720
1737
|
);
|
|
1721
1738
|
}
|
|
1722
|
-
deleteBlock() {
|
|
1723
|
-
this.menuOpen = !1, this.blockMenu.hide();
|
|
1724
|
-
const e = this.hoveredBlockContent.getBoundingClientRect(), t = this.editor.view.posAtCoords({
|
|
1725
|
-
left: e.left + e.width / 2,
|
|
1726
|
-
top: e.top + e.height / 2
|
|
1727
|
-
});
|
|
1728
|
-
t && this.editor.commands.BNDeleteBlock(t.pos);
|
|
1729
|
-
}
|
|
1730
|
-
setBlockBackgroundColor(e) {
|
|
1731
|
-
this.menuOpen = !1, this.blockMenu.hide();
|
|
1732
|
-
const t = this.hoveredBlockContent.getBoundingClientRect(), n = this.editor.view.posAtCoords({
|
|
1733
|
-
left: t.left + t.width / 2,
|
|
1734
|
-
top: t.top + t.height / 2
|
|
1735
|
-
});
|
|
1736
|
-
n && this.editor.commands.setBlockBackgroundColor(n.pos, e);
|
|
1737
|
-
}
|
|
1738
|
-
setBlockTextColor(e) {
|
|
1739
|
-
this.menuOpen = !1, this.blockMenu.hide();
|
|
1740
|
-
const t = this.hoveredBlockContent.getBoundingClientRect(), n = this.editor.view.posAtCoords({
|
|
1741
|
-
left: t.left + t.width / 2,
|
|
1742
|
-
top: t.top + t.height / 2
|
|
1743
|
-
});
|
|
1744
|
-
n && this.editor.commands.setBlockTextColor(n.pos, e);
|
|
1745
|
-
}
|
|
1746
1739
|
getStaticParams() {
|
|
1747
1740
|
return {
|
|
1741
|
+
editor: this.editor,
|
|
1748
1742
|
addBlock: () => this.addBlock(),
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1743
|
+
blockDragStart: (t) => {
|
|
1744
|
+
this.isDragging = !0, Re(t, this.ttEditor.view);
|
|
1745
|
+
},
|
|
1746
|
+
blockDragEnd: () => bt(),
|
|
1752
1747
|
freezeMenu: () => {
|
|
1753
1748
|
this.menuFrozen = !0;
|
|
1754
1749
|
},
|
|
1755
1750
|
unfreezeMenu: () => {
|
|
1756
1751
|
this.menuFrozen = !1;
|
|
1757
|
-
}
|
|
1758
|
-
setBlockBackgroundColor: (e) => this.setBlockBackgroundColor(e),
|
|
1759
|
-
setBlockTextColor: (e) => this.setBlockTextColor(e)
|
|
1752
|
+
}
|
|
1760
1753
|
};
|
|
1761
1754
|
}
|
|
1762
1755
|
getDynamicParams() {
|
|
1763
|
-
const e = this.
|
|
1756
|
+
const e = this.hoveredBlock.firstChild.getBoundingClientRect();
|
|
1764
1757
|
return {
|
|
1765
|
-
|
|
1766
|
-
blockTextColor: this.editor.getAttributes("blockContainer").textColor,
|
|
1758
|
+
block: this.editor.getBlock(this.hoveredBlock.getAttribute("data-id")),
|
|
1767
1759
|
referenceRect: new DOMRect(
|
|
1768
1760
|
this.horizontalPosAnchoredAtRoot ? this.horizontalPosAnchor : e.x,
|
|
1769
1761
|
e.y,
|
|
@@ -1773,14 +1765,15 @@ class zt {
|
|
|
1773
1765
|
};
|
|
1774
1766
|
}
|
|
1775
1767
|
}
|
|
1776
|
-
const
|
|
1768
|
+
const Ue = (o) => new C({
|
|
1777
1769
|
key: new v("DraggableBlocksPlugin"),
|
|
1778
|
-
view: () => new
|
|
1770
|
+
view: () => new ze({
|
|
1771
|
+
tiptapEditor: o.tiptapEditor,
|
|
1779
1772
|
editor: o.editor,
|
|
1780
1773
|
blockMenuFactory: o.blockSideMenuFactory,
|
|
1781
1774
|
horizontalPosAnchoredAtRoot: !0
|
|
1782
1775
|
})
|
|
1783
|
-
}),
|
|
1776
|
+
}), Ge = E.create({
|
|
1784
1777
|
name: "DraggableBlocksExtension",
|
|
1785
1778
|
priority: 1e3,
|
|
1786
1779
|
// Need to be high, in order to hide menu when typing slash
|
|
@@ -1790,79 +1783,87 @@ const Ut = (o) => new B({
|
|
|
1790
1783
|
"UI Element factory not defined for DraggableBlocksExtension"
|
|
1791
1784
|
);
|
|
1792
1785
|
return [
|
|
1793
|
-
|
|
1794
|
-
|
|
1786
|
+
Ue({
|
|
1787
|
+
tiptapEditor: this.editor,
|
|
1788
|
+
editor: this.options.editor,
|
|
1795
1789
|
blockSideMenuFactory: this.options.blockSideMenuFactory
|
|
1796
1790
|
})
|
|
1797
1791
|
];
|
|
1798
1792
|
}
|
|
1799
1793
|
});
|
|
1800
|
-
class $
|
|
1794
|
+
class $e {
|
|
1801
1795
|
constructor({
|
|
1802
|
-
editor:
|
|
1803
|
-
|
|
1796
|
+
editor: t,
|
|
1797
|
+
tiptapEditor: e,
|
|
1798
|
+
formattingToolbarFactory: r,
|
|
1804
1799
|
view: n,
|
|
1805
|
-
shouldShow:
|
|
1800
|
+
shouldShow: i
|
|
1806
1801
|
}) {
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1802
|
+
u(this, "editor");
|
|
1803
|
+
u(this, "ttEditor");
|
|
1804
|
+
u(this, "view");
|
|
1805
|
+
u(this, "formattingToolbar");
|
|
1806
|
+
u(this, "preventHide", !1);
|
|
1807
|
+
u(this, "preventShow", !1);
|
|
1808
|
+
u(this, "toolbarIsOpen", !1);
|
|
1809
|
+
u(this, "prevWasEditable", null);
|
|
1810
|
+
u(this, "shouldShow", ({ view: t, state: e, from: r, to: n }) => {
|
|
1811
|
+
const { doc: i, selection: a } = e, { empty: s } = a, d = !i.textBetween(r, n).length && St(e.selection);
|
|
1812
|
+
return !(!t.hasFocus() || s || d);
|
|
1816
1813
|
});
|
|
1817
|
-
|
|
1814
|
+
u(this, "viewMousedownHandler", () => {
|
|
1818
1815
|
this.preventShow = !0;
|
|
1819
1816
|
});
|
|
1820
|
-
|
|
1821
|
-
this.preventShow = !1, setTimeout(() => this.update(this.
|
|
1817
|
+
u(this, "viewMouseupHandler", () => {
|
|
1818
|
+
this.preventShow = !1, setTimeout(() => this.update(this.ttEditor.view));
|
|
1822
1819
|
});
|
|
1823
|
-
|
|
1820
|
+
u(this, "dragstartHandler", () => {
|
|
1824
1821
|
this.formattingToolbar.hide(), this.toolbarIsOpen = !1;
|
|
1825
1822
|
});
|
|
1826
|
-
|
|
1827
|
-
setTimeout(() => this.update(this.
|
|
1823
|
+
u(this, "focusHandler", () => {
|
|
1824
|
+
setTimeout(() => this.update(this.ttEditor.view));
|
|
1828
1825
|
});
|
|
1829
|
-
|
|
1830
|
-
var
|
|
1826
|
+
u(this, "blurHandler", ({ event: t }) => {
|
|
1827
|
+
var e, r;
|
|
1831
1828
|
if (this.preventHide) {
|
|
1832
1829
|
this.preventHide = !1;
|
|
1833
1830
|
return;
|
|
1834
1831
|
}
|
|
1835
|
-
|
|
1836
|
-
|
|
1832
|
+
t != null && t.relatedTarget && ((r = (e = this.formattingToolbar.element) == null ? void 0 : e.parentNode) != null && r.contains(
|
|
1833
|
+
t.relatedTarget
|
|
1837
1834
|
)) || this.toolbarIsOpen && (this.formattingToolbar.hide(), this.toolbarIsOpen = !1);
|
|
1838
1835
|
});
|
|
1839
|
-
|
|
1836
|
+
u(this, "scrollHandler", () => {
|
|
1837
|
+
this.toolbarIsOpen && this.formattingToolbar.render(this.getDynamicParams(), !1);
|
|
1838
|
+
});
|
|
1839
|
+
this.editor = t, this.ttEditor = e, this.view = n, this.formattingToolbar = r(this.getStaticParams()), i && (this.shouldShow = i), this.view.dom.addEventListener("mousedown", this.viewMousedownHandler), this.view.dom.addEventListener("mouseup", this.viewMouseupHandler), this.view.dom.addEventListener("dragstart", this.dragstartHandler), this.ttEditor.on("focus", this.focusHandler), this.ttEditor.on("blur", this.blurHandler), document.addEventListener("scroll", this.scrollHandler);
|
|
1840
1840
|
}
|
|
1841
|
-
update(
|
|
1841
|
+
update(t, e) {
|
|
1842
1842
|
var f;
|
|
1843
|
-
const { state:
|
|
1844
|
-
if (
|
|
1843
|
+
const { state: r, composing: n } = t, { doc: i, selection: a } = r, s = e && e.doc.eq(i) && e.selection.eq(a);
|
|
1844
|
+
if ((this.prevWasEditable === null || this.prevWasEditable === this.editor.isEditable) && (n || s))
|
|
1845
1845
|
return;
|
|
1846
|
-
|
|
1846
|
+
this.prevWasEditable = this.editor.isEditable;
|
|
1847
|
+
const { ranges: d } = a, l = Math.min(...d.map((p) => p.$from.pos)), c = Math.max(...d.map((p) => p.$to.pos)), h = (f = this.shouldShow) == null ? void 0 : f.call(this, {
|
|
1847
1848
|
editor: this.editor,
|
|
1848
|
-
view:
|
|
1849
|
-
state:
|
|
1850
|
-
oldState:
|
|
1849
|
+
view: t,
|
|
1850
|
+
state: r,
|
|
1851
|
+
oldState: e,
|
|
1851
1852
|
from: l,
|
|
1852
1853
|
to: c
|
|
1853
1854
|
});
|
|
1854
|
-
if (!this.toolbarIsOpen && !this.preventShow && (
|
|
1855
|
+
if (this.editor.isEditable && !this.toolbarIsOpen && !this.preventShow && (h || this.preventHide)) {
|
|
1855
1856
|
this.formattingToolbar.render(this.getDynamicParams(), !0), this.toolbarIsOpen = !0, this.formattingToolbar.element.addEventListener(
|
|
1856
1857
|
"mousedown",
|
|
1857
1858
|
(p) => p.preventDefault()
|
|
1858
1859
|
);
|
|
1859
1860
|
return;
|
|
1860
1861
|
}
|
|
1861
|
-
if (this.toolbarIsOpen && !this.preventShow && (
|
|
1862
|
+
if (this.toolbarIsOpen && !this.preventShow && (h || this.preventHide)) {
|
|
1862
1863
|
this.formattingToolbar.render(this.getDynamicParams(), !1);
|
|
1863
1864
|
return;
|
|
1864
1865
|
}
|
|
1865
|
-
if (this.toolbarIsOpen && !this.preventHide && (!
|
|
1866
|
+
if (this.toolbarIsOpen && !this.preventHide && (!h || this.preventShow || !this.editor.isEditable)) {
|
|
1866
1867
|
this.formattingToolbar.hide(), this.toolbarIsOpen = !1, this.formattingToolbar.element.removeEventListener(
|
|
1867
1868
|
"mousedown",
|
|
1868
1869
|
(p) => p.preventDefault()
|
|
@@ -1871,154 +1872,92 @@ class $t {
|
|
|
1871
1872
|
}
|
|
1872
1873
|
}
|
|
1873
1874
|
destroy() {
|
|
1874
|
-
this.view.dom.removeEventListener("mousedown", this.viewMousedownHandler), this.view.dom.removeEventListener("mouseup", this.viewMouseupHandler), this.view.dom.removeEventListener("dragstart", this.dragstartHandler), this.
|
|
1875
|
+
this.view.dom.removeEventListener("mousedown", this.viewMousedownHandler), this.view.dom.removeEventListener("mouseup", this.viewMouseupHandler), this.view.dom.removeEventListener("dragstart", this.dragstartHandler), this.ttEditor.off("focus", this.focusHandler), this.ttEditor.off("blur", this.blurHandler), document.removeEventListener("scroll", this.scrollHandler);
|
|
1875
1876
|
}
|
|
1876
1877
|
getSelectionBoundingBox() {
|
|
1877
|
-
const { state:
|
|
1878
|
-
if (
|
|
1879
|
-
const a = this.
|
|
1878
|
+
const { state: t } = this.ttEditor.view, { selection: e } = t, { ranges: r } = e, n = Math.min(...r.map((a) => a.$from.pos)), i = Math.max(...r.map((a) => a.$to.pos));
|
|
1879
|
+
if (xt(e)) {
|
|
1880
|
+
const a = this.ttEditor.view.nodeDOM(n);
|
|
1880
1881
|
if (a)
|
|
1881
1882
|
return a.getBoundingClientRect();
|
|
1882
1883
|
}
|
|
1883
|
-
return
|
|
1884
|
+
return nt(this.ttEditor.view, n, i);
|
|
1884
1885
|
}
|
|
1885
1886
|
getStaticParams() {
|
|
1886
1887
|
return {
|
|
1887
|
-
|
|
1888
|
-
this.editor.view.focus(), this.editor.commands.toggleBold();
|
|
1889
|
-
},
|
|
1890
|
-
toggleItalic: () => {
|
|
1891
|
-
this.editor.view.focus(), this.editor.commands.toggleItalic();
|
|
1892
|
-
},
|
|
1893
|
-
toggleUnderline: () => {
|
|
1894
|
-
this.editor.view.focus(), this.editor.commands.toggleUnderline();
|
|
1895
|
-
},
|
|
1896
|
-
toggleStrike: () => {
|
|
1897
|
-
this.editor.view.focus(), this.editor.commands.toggleStrike();
|
|
1898
|
-
},
|
|
1899
|
-
setHyperlink: (e, t) => {
|
|
1900
|
-
if (e === "")
|
|
1901
|
-
return;
|
|
1902
|
-
let { from: n, to: r } = this.editor.state.selection;
|
|
1903
|
-
t || (t = this.editor.state.doc.textBetween(n, r));
|
|
1904
|
-
const i = this.editor.schema.mark("link", { href: e });
|
|
1905
|
-
this.editor.view.dispatch(
|
|
1906
|
-
this.editor.view.state.tr.insertText(t, n, r).addMark(n, n + t.length, i)
|
|
1907
|
-
), this.editor.view.focus();
|
|
1908
|
-
},
|
|
1909
|
-
setTextColor: (e) => {
|
|
1910
|
-
this.editor.view.focus(), this.editor.commands.setTextColor(e);
|
|
1911
|
-
},
|
|
1912
|
-
setBackgroundColor: (e) => {
|
|
1913
|
-
this.editor.view.focus(), this.editor.commands.setBackgroundColor(e);
|
|
1914
|
-
},
|
|
1915
|
-
setTextAlignment: (e) => {
|
|
1916
|
-
this.editor.view.focus(), this.editor.commands.setTextAlignment(e);
|
|
1917
|
-
},
|
|
1918
|
-
increaseBlockIndent: () => {
|
|
1919
|
-
this.editor.view.focus(), this.editor.commands.sinkListItem("blockContainer");
|
|
1920
|
-
},
|
|
1921
|
-
decreaseBlockIndent: () => {
|
|
1922
|
-
this.editor.view.focus(), this.editor.commands.liftListItem("blockContainer");
|
|
1923
|
-
},
|
|
1924
|
-
updateBlock: (e) => {
|
|
1925
|
-
this.editor.view.focus(), this.editor.commands.BNUpdateBlock(
|
|
1926
|
-
this.editor.state.selection.from,
|
|
1927
|
-
e
|
|
1928
|
-
);
|
|
1929
|
-
}
|
|
1888
|
+
editor: this.editor
|
|
1930
1889
|
};
|
|
1931
1890
|
}
|
|
1932
1891
|
getDynamicParams() {
|
|
1933
|
-
const e = k(
|
|
1934
|
-
this.editor.state.doc,
|
|
1935
|
-
this.editor.state.selection.from
|
|
1936
|
-
);
|
|
1937
1892
|
return {
|
|
1938
|
-
boldIsActive: this.editor.isActive("bold"),
|
|
1939
|
-
italicIsActive: this.editor.isActive("italic"),
|
|
1940
|
-
underlineIsActive: this.editor.isActive("underline"),
|
|
1941
|
-
strikeIsActive: this.editor.isActive("strike"),
|
|
1942
|
-
hyperlinkIsActive: this.editor.isActive("link"),
|
|
1943
|
-
activeHyperlinkUrl: this.editor.getAttributes("link").href || "",
|
|
1944
|
-
activeHyperlinkText: this.editor.state.doc.textBetween(
|
|
1945
|
-
this.editor.state.selection.from,
|
|
1946
|
-
this.editor.state.selection.to
|
|
1947
|
-
),
|
|
1948
|
-
textColor: this.editor.getAttributes("textColor").color || "default",
|
|
1949
|
-
backgroundColor: this.editor.getAttributes("backgroundColor").color || "default",
|
|
1950
|
-
textAlignment: this.editor.getAttributes(e.contentType).textAlignment || "left",
|
|
1951
|
-
canIncreaseBlockIndent: this.editor.state.doc.resolve(e.startPos).index(e.depth - 1) > 0,
|
|
1952
|
-
canDecreaseBlockIndent: e.depth > 2,
|
|
1953
|
-
// Needs type cast as there is no way to create a type that dynamically updates based on which extensions are
|
|
1954
|
-
// loaded by the editor.
|
|
1955
|
-
block: {
|
|
1956
|
-
type: e.contentType.name,
|
|
1957
|
-
props: e.contentNode.attrs
|
|
1958
|
-
},
|
|
1959
1893
|
referenceRect: this.getSelectionBoundingBox()
|
|
1960
1894
|
};
|
|
1961
1895
|
}
|
|
1962
1896
|
}
|
|
1963
|
-
const
|
|
1897
|
+
const qe = (o) => new C({
|
|
1964
1898
|
key: new v("FormattingToolbarPlugin"),
|
|
1965
|
-
view: (
|
|
1966
|
-
}),
|
|
1899
|
+
view: (t) => new $e({ view: t, ...o })
|
|
1900
|
+
}), We = E.create({
|
|
1967
1901
|
name: "FormattingToolbarExtension",
|
|
1968
1902
|
addProseMirrorPlugins() {
|
|
1969
|
-
if (!this.options.formattingToolbarFactory)
|
|
1903
|
+
if (!this.options.formattingToolbarFactory || !this.options.editor)
|
|
1970
1904
|
throw new Error(
|
|
1971
|
-
"
|
|
1905
|
+
"required args not defined for FormattingToolbarExtension"
|
|
1972
1906
|
);
|
|
1973
1907
|
return [
|
|
1974
|
-
|
|
1975
|
-
|
|
1908
|
+
qe({
|
|
1909
|
+
tiptapEditor: this.editor,
|
|
1910
|
+
editor: this.options.editor,
|
|
1976
1911
|
formattingToolbarFactory: this.options.formattingToolbarFactory,
|
|
1977
1912
|
pluginKey: new v("FormattingToolbarPlugin")
|
|
1978
1913
|
})
|
|
1979
1914
|
];
|
|
1980
1915
|
}
|
|
1981
|
-
}),
|
|
1982
|
-
class
|
|
1983
|
-
constructor({ editor:
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
this
|
|
1996
|
-
this.
|
|
1997
|
-
this.
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
this.mouseHoveredHyperlinkMark = d, this.mouseHoveredHyperlinkMarkRange = X(
|
|
2007
|
-
a,
|
|
2008
|
-
d.type,
|
|
2009
|
-
d.attrs
|
|
1916
|
+
}), je = new v("HyperlinkToolbarPlugin");
|
|
1917
|
+
class Ye {
|
|
1918
|
+
constructor({ editor: t, hyperlinkToolbarFactory: e }) {
|
|
1919
|
+
u(this, "editor");
|
|
1920
|
+
u(this, "hyperlinkToolbar");
|
|
1921
|
+
u(this, "menuUpdateTimer");
|
|
1922
|
+
u(this, "startMenuUpdateTimer");
|
|
1923
|
+
u(this, "stopMenuUpdateTimer");
|
|
1924
|
+
u(this, "mouseHoveredHyperlinkMark");
|
|
1925
|
+
u(this, "mouseHoveredHyperlinkMarkRange");
|
|
1926
|
+
u(this, "keyboardHoveredHyperlinkMark");
|
|
1927
|
+
u(this, "keyboardHoveredHyperlinkMarkRange");
|
|
1928
|
+
u(this, "hyperlinkMark");
|
|
1929
|
+
u(this, "hyperlinkMarkRange");
|
|
1930
|
+
u(this, "mouseOverHandler", (t) => {
|
|
1931
|
+
if (this.mouseHoveredHyperlinkMark = void 0, this.mouseHoveredHyperlinkMarkRange = void 0, this.stopMenuUpdateTimer(), t.target instanceof HTMLAnchorElement && t.target.nodeName === "A") {
|
|
1932
|
+
const e = t.target, r = this.editor.view.posAtDOM(e, 0) + 1, n = this.editor.state.doc.resolve(
|
|
1933
|
+
r
|
|
1934
|
+
), i = n.marks();
|
|
1935
|
+
for (const a of i)
|
|
1936
|
+
if (a.type.name === this.editor.schema.mark("link").type.name) {
|
|
1937
|
+
this.mouseHoveredHyperlinkMark = a, this.mouseHoveredHyperlinkMarkRange = X(
|
|
1938
|
+
n,
|
|
1939
|
+
a.type,
|
|
1940
|
+
a.attrs
|
|
2010
1941
|
) || void 0;
|
|
2011
1942
|
break;
|
|
2012
1943
|
}
|
|
2013
1944
|
}
|
|
2014
1945
|
return this.startMenuUpdateTimer(), !1;
|
|
2015
1946
|
});
|
|
1947
|
+
u(this, "scrollHandler", () => {
|
|
1948
|
+
this.hyperlinkMark !== void 0 && this.hyperlinkToolbar.render(this.getDynamicParams(), !1);
|
|
1949
|
+
});
|
|
1950
|
+
this.editor = t, this.hyperlinkToolbar = e(this.getStaticParams()), this.startMenuUpdateTimer = () => {
|
|
1951
|
+
this.menuUpdateTimer = setTimeout(() => {
|
|
1952
|
+
this.update();
|
|
1953
|
+
}, 250);
|
|
1954
|
+
}, this.stopMenuUpdateTimer = () => (this.menuUpdateTimer && (clearTimeout(this.menuUpdateTimer), this.menuUpdateTimer = void 0), !1), this.editor.view.dom.addEventListener("mouseover", this.mouseOverHandler), document.addEventListener("scroll", this.scrollHandler);
|
|
2016
1955
|
}
|
|
2017
1956
|
update() {
|
|
2018
|
-
var
|
|
1957
|
+
var e, r, n, i;
|
|
2019
1958
|
if (!this.editor.view.hasFocus())
|
|
2020
1959
|
return;
|
|
2021
|
-
const
|
|
1960
|
+
const t = this.hyperlinkMark;
|
|
2022
1961
|
if (this.hyperlinkMark = void 0, this.hyperlinkMarkRange = void 0, this.keyboardHoveredHyperlinkMark = void 0, this.keyboardHoveredHyperlinkMarkRange = void 0, this.editor.state.selection.empty) {
|
|
2023
1962
|
const a = this.editor.state.selection.$from.marks();
|
|
2024
1963
|
for (const s of a)
|
|
@@ -2031,12 +1970,12 @@ class jt {
|
|
|
2031
1970
|
break;
|
|
2032
1971
|
}
|
|
2033
1972
|
}
|
|
2034
|
-
if (this.mouseHoveredHyperlinkMark && (this.hyperlinkMark = this.mouseHoveredHyperlinkMark, this.hyperlinkMarkRange = this.mouseHoveredHyperlinkMarkRange), this.keyboardHoveredHyperlinkMark && (this.hyperlinkMark = this.keyboardHoveredHyperlinkMark, this.hyperlinkMarkRange = this.keyboardHoveredHyperlinkMarkRange), this.hyperlinkMark) {
|
|
2035
|
-
if (this.getDynamicParams(), !
|
|
2036
|
-
this.hyperlinkToolbar.render(this.getDynamicParams(), !0), (
|
|
1973
|
+
if (this.mouseHoveredHyperlinkMark && (this.hyperlinkMark = this.mouseHoveredHyperlinkMark, this.hyperlinkMarkRange = this.mouseHoveredHyperlinkMarkRange), this.keyboardHoveredHyperlinkMark && (this.hyperlinkMark = this.keyboardHoveredHyperlinkMark, this.hyperlinkMarkRange = this.keyboardHoveredHyperlinkMarkRange), this.hyperlinkMark && this.editor.isEditable) {
|
|
1974
|
+
if (this.getDynamicParams(), !t) {
|
|
1975
|
+
this.hyperlinkToolbar.render(this.getDynamicParams(), !0), (e = this.hyperlinkToolbar.element) == null || e.addEventListener(
|
|
2037
1976
|
"mouseleave",
|
|
2038
1977
|
this.startMenuUpdateTimer
|
|
2039
|
-
), (
|
|
1978
|
+
), (r = this.hyperlinkToolbar.element) == null || r.addEventListener(
|
|
2040
1979
|
"mouseenter",
|
|
2041
1980
|
this.stopMenuUpdateTimer
|
|
2042
1981
|
);
|
|
@@ -2045,8 +1984,8 @@ class jt {
|
|
|
2045
1984
|
this.hyperlinkToolbar.render(this.getDynamicParams(), !1);
|
|
2046
1985
|
return;
|
|
2047
1986
|
}
|
|
2048
|
-
if (!this.hyperlinkMark
|
|
2049
|
-
(
|
|
1987
|
+
if (t && (!this.hyperlinkMark || !this.editor.isEditable)) {
|
|
1988
|
+
(n = this.hyperlinkToolbar.element) == null || n.removeEventListener(
|
|
2050
1989
|
"mouseleave",
|
|
2051
1990
|
this.startMenuUpdateTimer
|
|
2052
1991
|
), (i = this.hyperlinkToolbar.element) == null || i.removeEventListener(
|
|
@@ -2056,19 +1995,25 @@ class jt {
|
|
|
2056
1995
|
return;
|
|
2057
1996
|
}
|
|
2058
1997
|
}
|
|
1998
|
+
destroy() {
|
|
1999
|
+
this.editor.view.dom.removeEventListener(
|
|
2000
|
+
"mouseover",
|
|
2001
|
+
this.mouseOverHandler
|
|
2002
|
+
), document.removeEventListener("scroll", this.scrollHandler);
|
|
2003
|
+
}
|
|
2059
2004
|
getStaticParams() {
|
|
2060
2005
|
return {
|
|
2061
|
-
editHyperlink: (
|
|
2062
|
-
const
|
|
2063
|
-
|
|
2006
|
+
editHyperlink: (t, e) => {
|
|
2007
|
+
const r = this.editor.view.state.tr.insertText(
|
|
2008
|
+
e,
|
|
2064
2009
|
this.hyperlinkMarkRange.from,
|
|
2065
2010
|
this.hyperlinkMarkRange.to
|
|
2066
2011
|
);
|
|
2067
|
-
|
|
2012
|
+
r.addMark(
|
|
2068
2013
|
this.hyperlinkMarkRange.from,
|
|
2069
|
-
this.hyperlinkMarkRange.from +
|
|
2070
|
-
this.editor.schema.mark("link", { href:
|
|
2071
|
-
), this.editor.view.dispatch(
|
|
2014
|
+
this.hyperlinkMarkRange.from + e.length,
|
|
2015
|
+
this.editor.schema.mark("link", { href: t })
|
|
2016
|
+
), this.editor.view.dispatch(r), this.editor.view.focus(), this.hyperlinkToolbar.hide();
|
|
2072
2017
|
},
|
|
2073
2018
|
deleteHyperlink: () => {
|
|
2074
2019
|
this.editor.view.dispatch(
|
|
@@ -2088,7 +2033,7 @@ class jt {
|
|
|
2088
2033
|
this.hyperlinkMarkRange.from,
|
|
2089
2034
|
this.hyperlinkMarkRange.to
|
|
2090
2035
|
),
|
|
2091
|
-
referenceRect:
|
|
2036
|
+
referenceRect: nt(
|
|
2092
2037
|
this.editor.view,
|
|
2093
2038
|
this.hyperlinkMarkRange.from,
|
|
2094
2039
|
this.hyperlinkMarkRange.to
|
|
@@ -2096,13 +2041,13 @@ class jt {
|
|
|
2096
2041
|
};
|
|
2097
2042
|
}
|
|
2098
2043
|
}
|
|
2099
|
-
const
|
|
2100
|
-
key:
|
|
2101
|
-
view: () => new
|
|
2044
|
+
const Ke = (o, t) => new C({
|
|
2045
|
+
key: je,
|
|
2046
|
+
view: () => new Ye({
|
|
2102
2047
|
editor: o,
|
|
2103
|
-
hyperlinkToolbarFactory:
|
|
2048
|
+
hyperlinkToolbarFactory: t.hyperlinkToolbarFactory
|
|
2104
2049
|
})
|
|
2105
|
-
}),
|
|
2050
|
+
}), Ve = dt.extend({
|
|
2106
2051
|
priority: 500,
|
|
2107
2052
|
addProseMirrorPlugins() {
|
|
2108
2053
|
var o;
|
|
@@ -2110,12 +2055,12 @@ const Vt = (o, e) => new B({
|
|
|
2110
2055
|
throw new Error("UI Element factory not defined for HyperlinkMark");
|
|
2111
2056
|
return [
|
|
2112
2057
|
...((o = this.parent) == null ? void 0 : o.call(this)) || [],
|
|
2113
|
-
|
|
2058
|
+
Ke(this.editor, {
|
|
2114
2059
|
hyperlinkToolbarFactory: this.options.hyperlinkToolbarFactory
|
|
2115
2060
|
})
|
|
2116
2061
|
];
|
|
2117
2062
|
}
|
|
2118
|
-
}),
|
|
2063
|
+
}), Je = new v("blocknote-placeholder"), Xe = E.create({
|
|
2119
2064
|
name: "placeholder",
|
|
2120
2065
|
addOptions() {
|
|
2121
2066
|
return {
|
|
@@ -2131,36 +2076,36 @@ const Vt = (o, e) => new B({
|
|
|
2131
2076
|
},
|
|
2132
2077
|
addProseMirrorPlugins() {
|
|
2133
2078
|
return [
|
|
2134
|
-
new
|
|
2135
|
-
key:
|
|
2079
|
+
new C({
|
|
2080
|
+
key: Je,
|
|
2136
2081
|
props: {
|
|
2137
2082
|
decorations: (o) => {
|
|
2138
|
-
const { doc:
|
|
2139
|
-
if (
|
|
2140
|
-
return
|
|
2083
|
+
const { doc: t, selection: e } = o, r = V.getState(o), n = this.editor.isEditable || !this.options.showOnlyWhenEditable, { anchor: i } = e, a = [];
|
|
2084
|
+
if (n)
|
|
2085
|
+
return t.descendants((s, d) => {
|
|
2141
2086
|
const l = i >= d && i <= d + s.nodeSize, c = !s.isLeaf && !s.childCount;
|
|
2142
2087
|
if ((l || !this.options.showOnlyCurrent) && c) {
|
|
2143
|
-
const
|
|
2144
|
-
this.editor.isEmpty &&
|
|
2088
|
+
const h = [this.options.emptyNodeClass];
|
|
2089
|
+
this.editor.isEmpty && h.push(this.options.emptyEditorClass), l && h.push(this.options.hasAnchorClass), (r == null ? void 0 : r.triggerCharacter) === "" && (r != null && r.active) && h.push(this.options.isFilterClass);
|
|
2145
2090
|
const f = D.node(d, d + s.nodeSize, {
|
|
2146
|
-
class:
|
|
2091
|
+
class: h.join(" ")
|
|
2147
2092
|
});
|
|
2148
2093
|
a.push(f);
|
|
2149
2094
|
}
|
|
2150
2095
|
return this.options.includeChildren;
|
|
2151
|
-
}), F.create(
|
|
2096
|
+
}), F.create(t, a);
|
|
2152
2097
|
}
|
|
2153
2098
|
}
|
|
2154
2099
|
})
|
|
2155
2100
|
];
|
|
2156
2101
|
}
|
|
2157
2102
|
});
|
|
2158
|
-
class
|
|
2159
|
-
constructor(
|
|
2160
|
-
this.name =
|
|
2103
|
+
class Qe {
|
|
2104
|
+
constructor(t, e) {
|
|
2105
|
+
this.name = t, this.match = e;
|
|
2161
2106
|
}
|
|
2162
2107
|
}
|
|
2163
|
-
class
|
|
2108
|
+
class x extends Qe {
|
|
2164
2109
|
/**
|
|
2165
2110
|
* Constructs a new slash-command.
|
|
2166
2111
|
*
|
|
@@ -2168,64 +2113,64 @@ class I extends Qt {
|
|
|
2168
2113
|
* @param execute The callback for creating a new node
|
|
2169
2114
|
* @param aliases Aliases for this command
|
|
2170
2115
|
*/
|
|
2171
|
-
constructor(
|
|
2172
|
-
super(
|
|
2173
|
-
(i) => i.toLowerCase().startsWith(
|
|
2174
|
-
).length !== 0), this.name =
|
|
2116
|
+
constructor(t, e, r = []) {
|
|
2117
|
+
super(t, (n) => this.name.toLowerCase().startsWith(n.toLowerCase()) || this.aliases.filter(
|
|
2118
|
+
(i) => i.toLowerCase().startsWith(n.toLowerCase())
|
|
2119
|
+
).length !== 0), this.name = t, this.execute = e, this.aliases = r;
|
|
2175
2120
|
}
|
|
2176
2121
|
}
|
|
2177
|
-
function
|
|
2178
|
-
const
|
|
2179
|
-
|
|
2122
|
+
function I(o, t) {
|
|
2123
|
+
const e = o.getTextCursorPosition().block;
|
|
2124
|
+
e.content.length === 1 && e.content[0].type === "text" && e.content[0].text === "/" || e.content.length === 0 ? o.updateBlock(e, t) : (o.insertBlocks([t], e, "after"), o.setTextCursorPosition(o.getTextCursorPosition().nextBlock));
|
|
2180
2125
|
}
|
|
2181
|
-
const
|
|
2126
|
+
const Ze = [
|
|
2182
2127
|
// Command for creating a level 1 heading
|
|
2183
|
-
new
|
|
2128
|
+
new x(
|
|
2184
2129
|
"Heading",
|
|
2185
|
-
(o) =>
|
|
2130
|
+
(o) => I(o, {
|
|
2186
2131
|
type: "heading",
|
|
2187
2132
|
props: { level: "1" }
|
|
2188
2133
|
}),
|
|
2189
2134
|
["h", "heading1", "h1"]
|
|
2190
2135
|
),
|
|
2191
2136
|
// Command for creating a level 2 heading
|
|
2192
|
-
new
|
|
2137
|
+
new x(
|
|
2193
2138
|
"Heading 2",
|
|
2194
|
-
(o) =>
|
|
2139
|
+
(o) => I(o, {
|
|
2195
2140
|
type: "heading",
|
|
2196
2141
|
props: { level: "2" }
|
|
2197
2142
|
}),
|
|
2198
2143
|
["h2", "heading2", "subheading"]
|
|
2199
2144
|
),
|
|
2200
2145
|
// Command for creating a level 3 heading
|
|
2201
|
-
new
|
|
2146
|
+
new x(
|
|
2202
2147
|
"Heading 3",
|
|
2203
|
-
(o) =>
|
|
2148
|
+
(o) => I(o, {
|
|
2204
2149
|
type: "heading",
|
|
2205
2150
|
props: { level: "3" }
|
|
2206
2151
|
}),
|
|
2207
2152
|
["h3", "heading3", "subheading"]
|
|
2208
2153
|
),
|
|
2209
2154
|
// Command for creating an ordered list
|
|
2210
|
-
new
|
|
2155
|
+
new x(
|
|
2211
2156
|
"Numbered List",
|
|
2212
|
-
(o) =>
|
|
2157
|
+
(o) => I(o, {
|
|
2213
2158
|
type: "numberedListItem"
|
|
2214
2159
|
}),
|
|
2215
2160
|
["li", "list", "numberedlist", "numbered list"]
|
|
2216
2161
|
),
|
|
2217
2162
|
// Command for creating a bullet list
|
|
2218
|
-
new
|
|
2163
|
+
new x(
|
|
2219
2164
|
"Bullet List",
|
|
2220
|
-
(o) =>
|
|
2165
|
+
(o) => I(o, {
|
|
2221
2166
|
type: "bulletListItem"
|
|
2222
2167
|
}),
|
|
2223
2168
|
["ul", "list", "bulletlist", "bullet list"]
|
|
2224
2169
|
),
|
|
2225
2170
|
// Command for creating a paragraph (pretty useless)
|
|
2226
|
-
new
|
|
2171
|
+
new x(
|
|
2227
2172
|
"Paragraph",
|
|
2228
|
-
(o) =>
|
|
2173
|
+
(o) => I(o, {
|
|
2229
2174
|
type: "paragraph"
|
|
2230
2175
|
}),
|
|
2231
2176
|
["p"]
|
|
@@ -2321,7 +2266,7 @@ const Zt = [
|
|
|
2321
2266
|
// TableIcon,
|
|
2322
2267
|
// "Used to create a simple table"
|
|
2323
2268
|
// ),
|
|
2324
|
-
],
|
|
2269
|
+
], to = E.create({
|
|
2325
2270
|
name: "textAlignment",
|
|
2326
2271
|
addGlobalAttributes() {
|
|
2327
2272
|
return [
|
|
@@ -2343,23 +2288,23 @@ const Zt = [
|
|
|
2343
2288
|
},
|
|
2344
2289
|
addCommands() {
|
|
2345
2290
|
return {
|
|
2346
|
-
setTextAlignment: (o) => ({ state:
|
|
2347
|
-
const
|
|
2348
|
-
|
|
2349
|
-
|
|
2291
|
+
setTextAlignment: (o) => ({ state: t }) => {
|
|
2292
|
+
const e = [], r = g(
|
|
2293
|
+
t.doc,
|
|
2294
|
+
t.selection.from
|
|
2350
2295
|
);
|
|
2351
|
-
if (
|
|
2296
|
+
if (r === void 0)
|
|
2352
2297
|
return !1;
|
|
2353
|
-
let
|
|
2354
|
-
for (;
|
|
2355
|
-
|
|
2356
|
-
for (const i of
|
|
2357
|
-
|
|
2298
|
+
let n = r.startPos;
|
|
2299
|
+
for (; n < t.selection.to; )
|
|
2300
|
+
t.doc.resolve(n).node().type.spec.group === "blockContent" ? (e.push(n - 1), n += t.doc.resolve(n).node().nodeSize - 1) : n += 1;
|
|
2301
|
+
for (const i of e)
|
|
2302
|
+
t.tr.setNodeAttribute(i, "textAlignment", o);
|
|
2358
2303
|
return !0;
|
|
2359
2304
|
}
|
|
2360
2305
|
};
|
|
2361
2306
|
}
|
|
2362
|
-
}),
|
|
2307
|
+
}), eo = E.create({
|
|
2363
2308
|
name: "blockTextColor",
|
|
2364
2309
|
addGlobalAttributes() {
|
|
2365
2310
|
return [
|
|
@@ -2379,13 +2324,13 @@ const Zt = [
|
|
|
2379
2324
|
},
|
|
2380
2325
|
addCommands() {
|
|
2381
2326
|
return {
|
|
2382
|
-
setBlockTextColor: (o,
|
|
2383
|
-
const
|
|
2384
|
-
return
|
|
2327
|
+
setBlockTextColor: (o, t) => ({ state: e, view: r }) => {
|
|
2328
|
+
const n = g(e.doc, o);
|
|
2329
|
+
return n === void 0 ? !1 : (e.tr.setNodeAttribute(n.startPos - 1, "textColor", t), r.focus(), !0);
|
|
2385
2330
|
}
|
|
2386
2331
|
};
|
|
2387
2332
|
}
|
|
2388
|
-
}), oo =
|
|
2333
|
+
}), oo = rt.create({
|
|
2389
2334
|
name: "textColor",
|
|
2390
2335
|
addAttributes() {
|
|
2391
2336
|
return {
|
|
@@ -2411,18 +2356,18 @@ const Zt = [
|
|
|
2411
2356
|
},
|
|
2412
2357
|
addCommands() {
|
|
2413
2358
|
return {
|
|
2414
|
-
setTextColor: (o) => ({ commands:
|
|
2359
|
+
setTextColor: (o) => ({ commands: t }) => o !== "default" ? t.setMark(this.name, { color: o }) : t.unsetMark(this.name)
|
|
2415
2360
|
};
|
|
2416
2361
|
}
|
|
2417
|
-
}),
|
|
2362
|
+
}), ro = E.create({
|
|
2418
2363
|
name: "trailingNode",
|
|
2419
2364
|
addProseMirrorPlugins() {
|
|
2420
2365
|
const o = new v(this.name);
|
|
2421
2366
|
return [
|
|
2422
|
-
new
|
|
2367
|
+
new C({
|
|
2423
2368
|
key: o,
|
|
2424
|
-
appendTransaction: (
|
|
2425
|
-
const { doc:
|
|
2369
|
+
appendTransaction: (t, e, r) => {
|
|
2370
|
+
const { doc: n, tr: i, schema: a } = r, s = o.getState(r), d = n.content.size - 2, l = a.nodes.blockContainer, c = a.nodes.paragraph;
|
|
2426
2371
|
if (s)
|
|
2427
2372
|
return i.insert(
|
|
2428
2373
|
d,
|
|
@@ -2430,105 +2375,107 @@ const Zt = [
|
|
|
2430
2375
|
);
|
|
2431
2376
|
},
|
|
2432
2377
|
state: {
|
|
2433
|
-
init: (
|
|
2378
|
+
init: (t, e) => {
|
|
2434
2379
|
},
|
|
2435
|
-
apply: (
|
|
2436
|
-
if (!
|
|
2437
|
-
return
|
|
2438
|
-
let
|
|
2439
|
-
if (!
|
|
2380
|
+
apply: (t, e) => {
|
|
2381
|
+
if (!t.docChanged)
|
|
2382
|
+
return e;
|
|
2383
|
+
let r = t.doc.lastChild;
|
|
2384
|
+
if (!r || r.type.name !== "blockGroup")
|
|
2440
2385
|
throw new Error("Expected blockGroup");
|
|
2441
|
-
if (
|
|
2386
|
+
if (r = r.lastChild, !r || r.type.name !== "blockContainer")
|
|
2442
2387
|
throw new Error("Expected blockContainer");
|
|
2443
|
-
return
|
|
2388
|
+
return r.nodeSize > 4;
|
|
2444
2389
|
}
|
|
2445
2390
|
}
|
|
2446
2391
|
})
|
|
2447
2392
|
];
|
|
2448
2393
|
}
|
|
2449
|
-
}),
|
|
2450
|
-
const
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2394
|
+
}), no = (o) => {
|
|
2395
|
+
const t = [
|
|
2396
|
+
H.ClipboardTextSerializer,
|
|
2397
|
+
H.Commands,
|
|
2398
|
+
H.Editable,
|
|
2399
|
+
H.FocusEvents,
|
|
2400
|
+
H.Tabindex,
|
|
2456
2401
|
// DevTools,
|
|
2457
|
-
|
|
2402
|
+
Ut,
|
|
2458
2403
|
// DropCursor,
|
|
2459
|
-
|
|
2404
|
+
Xe.configure({
|
|
2460
2405
|
emptyNodeClass: b.isEmpty,
|
|
2461
2406
|
hasAnchorClass: b.hasAnchor,
|
|
2462
2407
|
isFilterClass: b.isFilter,
|
|
2463
2408
|
includeChildren: !0,
|
|
2464
2409
|
showOnlyCurrent: !1
|
|
2465
2410
|
}),
|
|
2466
|
-
|
|
2411
|
+
Y.configure({
|
|
2467
2412
|
types: ["blockContainer"]
|
|
2468
2413
|
}),
|
|
2469
|
-
|
|
2414
|
+
Gt,
|
|
2470
2415
|
// Comments,
|
|
2471
2416
|
// basics:
|
|
2472
|
-
|
|
2417
|
+
jt,
|
|
2473
2418
|
// marks:
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2419
|
+
Ft,
|
|
2420
|
+
Rt,
|
|
2421
|
+
qt,
|
|
2422
|
+
Wt,
|
|
2423
|
+
Yt,
|
|
2479
2424
|
oo,
|
|
2480
|
-
to,
|
|
2481
|
-
dt,
|
|
2482
|
-
at,
|
|
2483
2425
|
eo,
|
|
2426
|
+
de,
|
|
2427
|
+
ae,
|
|
2428
|
+
to,
|
|
2484
2429
|
// custom blocks:
|
|
2485
|
-
...
|
|
2486
|
-
|
|
2487
|
-
$
|
|
2430
|
+
...Se,
|
|
2431
|
+
zt.configure({ width: 5, color: "#ddeeff" }),
|
|
2432
|
+
$t,
|
|
2488
2433
|
// This needs to be at the bottom of this list, because Key events (such as enter, when selecting a /command),
|
|
2489
2434
|
// should be handled before Enter handlers in other components like splitListItem
|
|
2490
|
-
|
|
2435
|
+
ro
|
|
2491
2436
|
];
|
|
2492
|
-
return o.uiFactories.blockSideMenuFactory &&
|
|
2493
|
-
|
|
2437
|
+
return o.uiFactories.blockSideMenuFactory && t.push(
|
|
2438
|
+
Ge.configure({
|
|
2439
|
+
editor: o.editor,
|
|
2494
2440
|
blockSideMenuFactory: o.uiFactories.blockSideMenuFactory
|
|
2495
2441
|
})
|
|
2496
|
-
), o.uiFactories.formattingToolbarFactory &&
|
|
2497
|
-
|
|
2442
|
+
), o.uiFactories.formattingToolbarFactory && t.push(
|
|
2443
|
+
We.configure({
|
|
2444
|
+
editor: o.editor,
|
|
2498
2445
|
formattingToolbarFactory: o.uiFactories.formattingToolbarFactory
|
|
2499
2446
|
})
|
|
2500
|
-
), o.uiFactories.hyperlinkToolbarFactory ?
|
|
2501
|
-
|
|
2447
|
+
), o.uiFactories.hyperlinkToolbarFactory ? t.push(
|
|
2448
|
+
Ve.configure({
|
|
2502
2449
|
hyperlinkToolbarFactory: o.uiFactories.hyperlinkToolbarFactory
|
|
2503
2450
|
})
|
|
2504
|
-
) :
|
|
2505
|
-
|
|
2451
|
+
) : t.push(dt), o.uiFactories.slashMenuFactory && t.push(
|
|
2452
|
+
_e.configure({
|
|
2506
2453
|
editor: o.editor,
|
|
2507
2454
|
commands: o.slashCommands,
|
|
2508
2455
|
slashMenuFactory: o.uiFactories.slashMenuFactory
|
|
2509
2456
|
})
|
|
2510
|
-
),
|
|
2457
|
+
), t;
|
|
2511
2458
|
}, io = {
|
|
2512
2459
|
enableInputRules: !0,
|
|
2513
2460
|
enablePasteRules: !0,
|
|
2514
2461
|
enableCoreExtensions: !1
|
|
2515
2462
|
};
|
|
2516
|
-
class
|
|
2517
|
-
constructor(
|
|
2518
|
-
|
|
2519
|
-
|
|
2463
|
+
class No {
|
|
2464
|
+
constructor(t = {}) {
|
|
2465
|
+
u(this, "_tiptapEditor");
|
|
2466
|
+
u(this, "blockCache", /* @__PURE__ */ new WeakMap());
|
|
2520
2467
|
var i, a, s;
|
|
2521
|
-
|
|
2468
|
+
t = {
|
|
2522
2469
|
defaultStyles: !0,
|
|
2523
|
-
...
|
|
2470
|
+
...t
|
|
2524
2471
|
};
|
|
2525
|
-
const
|
|
2472
|
+
const e = no({
|
|
2526
2473
|
editor: this,
|
|
2527
|
-
uiFactories:
|
|
2528
|
-
slashCommands:
|
|
2474
|
+
uiFactories: t.uiFactories || {},
|
|
2475
|
+
slashCommands: t.slashCommands || Ze
|
|
2529
2476
|
});
|
|
2530
|
-
let
|
|
2531
|
-
const
|
|
2477
|
+
let r = t.disableHistoryExtension ? e.filter((d) => d.name !== "history") : e;
|
|
2478
|
+
const n = {
|
|
2532
2479
|
// TODO: This approach to setting initial content is "cleaner" but requires the PM editor schema, which is only
|
|
2533
2480
|
// created after initializing the TipTap editor. Not sure it's feasible.
|
|
2534
2481
|
// content:
|
|
@@ -2537,91 +2484,96 @@ class Ho {
|
|
|
2537
2484
|
// blockToNode(block, this._tiptapEditor.schema).toJSON()
|
|
2538
2485
|
// ),
|
|
2539
2486
|
...io,
|
|
2540
|
-
...
|
|
2487
|
+
...t._tiptapOptions,
|
|
2541
2488
|
onCreate: () => {
|
|
2542
2489
|
var d;
|
|
2543
|
-
(d =
|
|
2490
|
+
(d = t.onEditorReady) == null || d.call(t, this), t.initialContent && this.replaceBlocks(this.topLevelBlocks, t.initialContent);
|
|
2544
2491
|
},
|
|
2545
2492
|
onUpdate: () => {
|
|
2546
2493
|
var d;
|
|
2547
|
-
(d =
|
|
2494
|
+
(d = t.onEditorContentChange) == null || d.call(t, this);
|
|
2548
2495
|
},
|
|
2549
2496
|
onSelectionUpdate: () => {
|
|
2550
2497
|
var d;
|
|
2551
|
-
(d =
|
|
2498
|
+
(d = t.onTextCursorPositionChange) == null || d.call(t, this);
|
|
2552
2499
|
},
|
|
2553
|
-
|
|
2500
|
+
editable: t.editable === void 0 ? !0 : t.editable,
|
|
2501
|
+
extensions: t.enableBlockNoteExtensions === !1 ? (i = t._tiptapOptions) == null ? void 0 : i.extensions : [...((a = t._tiptapOptions) == null ? void 0 : a.extensions) || [], ...r],
|
|
2554
2502
|
editorProps: {
|
|
2555
2503
|
attributes: {
|
|
2556
|
-
|
|
2504
|
+
"data-theme": t.theme || "light",
|
|
2505
|
+
...t.editorDOMAttributes || {},
|
|
2557
2506
|
class: [
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
((s =
|
|
2507
|
+
O.bnEditor,
|
|
2508
|
+
O.bnRoot,
|
|
2509
|
+
t.defaultStyles ? O.defaultStyles : "",
|
|
2510
|
+
((s = t.editorDOMAttributes) == null ? void 0 : s.class) || ""
|
|
2562
2511
|
].join(" ")
|
|
2563
2512
|
}
|
|
2564
2513
|
}
|
|
2565
2514
|
};
|
|
2566
|
-
|
|
2515
|
+
t.parentElement && (n.element = t.parentElement), this._tiptapEditor = new It(n);
|
|
2567
2516
|
}
|
|
2568
2517
|
get domElement() {
|
|
2569
2518
|
return this._tiptapEditor.view.dom;
|
|
2570
2519
|
}
|
|
2520
|
+
focus() {
|
|
2521
|
+
this._tiptapEditor.view.focus();
|
|
2522
|
+
}
|
|
2571
2523
|
/**
|
|
2572
2524
|
* Gets a snapshot of all top-level (non-nested) blocks in the editor.
|
|
2573
2525
|
* @returns A snapshot of all top-level (non-nested) blocks in the editor.
|
|
2574
2526
|
*/
|
|
2575
2527
|
get topLevelBlocks() {
|
|
2576
|
-
const
|
|
2577
|
-
return this._tiptapEditor.state.doc.firstChild.descendants((
|
|
2528
|
+
const t = [];
|
|
2529
|
+
return this._tiptapEditor.state.doc.firstChild.descendants((e) => (t.push(B(e, this.blockCache)), !1)), t;
|
|
2578
2530
|
}
|
|
2579
2531
|
/**
|
|
2580
2532
|
* Gets a snapshot of an existing block from the editor.
|
|
2581
2533
|
* @param blockIdentifier The identifier of an existing block that should be retrieved.
|
|
2582
2534
|
* @returns The block that matches the identifier, or `undefined` if no matching block was found.
|
|
2583
2535
|
*/
|
|
2584
|
-
getBlock(
|
|
2585
|
-
const
|
|
2586
|
-
let
|
|
2587
|
-
return this._tiptapEditor.state.doc.firstChild.descendants((
|
|
2536
|
+
getBlock(t) {
|
|
2537
|
+
const e = typeof t == "string" ? t : t.id;
|
|
2538
|
+
let r;
|
|
2539
|
+
return this._tiptapEditor.state.doc.firstChild.descendants((n) => typeof r < "u" ? !1 : n.type.name !== "blockContainer" || n.attrs.id !== e ? !0 : (r = B(n, this.blockCache), !1)), r;
|
|
2588
2540
|
}
|
|
2589
2541
|
/**
|
|
2590
2542
|
* Traverses all blocks in the editor depth-first, and executes a callback for each.
|
|
2591
2543
|
* @param callback The callback to execute for each block. Returning `false` stops the traversal.
|
|
2592
2544
|
* @param reverse Whether the blocks should be traversed in reverse order.
|
|
2593
2545
|
*/
|
|
2594
|
-
forEachBlock(
|
|
2595
|
-
const
|
|
2596
|
-
|
|
2597
|
-
function
|
|
2546
|
+
forEachBlock(t, e = !1) {
|
|
2547
|
+
const r = this.topLevelBlocks.slice();
|
|
2548
|
+
e && r.reverse();
|
|
2549
|
+
function n(i) {
|
|
2598
2550
|
for (const a of i) {
|
|
2599
|
-
if (
|
|
2551
|
+
if (!t(a))
|
|
2600
2552
|
return !1;
|
|
2601
|
-
const s =
|
|
2602
|
-
if (
|
|
2553
|
+
const s = e ? a.children.slice().reverse() : a.children;
|
|
2554
|
+
if (!n(s))
|
|
2603
2555
|
return !1;
|
|
2604
2556
|
}
|
|
2605
2557
|
return !0;
|
|
2606
2558
|
}
|
|
2607
|
-
r
|
|
2559
|
+
n(r);
|
|
2608
2560
|
}
|
|
2609
2561
|
/**
|
|
2610
2562
|
* Gets a snapshot of the current text cursor position.
|
|
2611
2563
|
* @returns A snapshot of the current text cursor position.
|
|
2612
2564
|
*/
|
|
2613
2565
|
getTextCursorPosition() {
|
|
2614
|
-
const { node:
|
|
2566
|
+
const { node: t, depth: e, startPos: r, endPos: n } = g(
|
|
2615
2567
|
this._tiptapEditor.state.doc,
|
|
2616
2568
|
this._tiptapEditor.state.selection.from
|
|
2617
|
-
), i = this._tiptapEditor.state.doc.resolve(
|
|
2569
|
+
), i = this._tiptapEditor.state.doc.resolve(n).index(e - 1), a = this._tiptapEditor.state.doc.resolve(n + 1).node().childCount;
|
|
2618
2570
|
let s;
|
|
2619
|
-
i > 0 && (s = this._tiptapEditor.state.doc.resolve(
|
|
2571
|
+
i > 0 && (s = this._tiptapEditor.state.doc.resolve(r - 2).node());
|
|
2620
2572
|
let d;
|
|
2621
|
-
return i < a - 1 && (d = this._tiptapEditor.state.doc.resolve(
|
|
2622
|
-
block:
|
|
2623
|
-
prevBlock: s === void 0 ? void 0 :
|
|
2624
|
-
nextBlock: d === void 0 ? void 0 :
|
|
2573
|
+
return i < a - 1 && (d = this._tiptapEditor.state.doc.resolve(n + 2).node()), {
|
|
2574
|
+
block: B(t, this.blockCache),
|
|
2575
|
+
prevBlock: s === void 0 ? void 0 : B(s, this.blockCache),
|
|
2576
|
+
nextBlock: d === void 0 ? void 0 : B(d, this.blockCache)
|
|
2625
2577
|
};
|
|
2626
2578
|
}
|
|
2627
2579
|
/**
|
|
@@ -2630,15 +2582,43 @@ class Ho {
|
|
|
2630
2582
|
* @param targetBlock The identifier of an existing block that the text cursor should be moved to.
|
|
2631
2583
|
* @param placement Whether the text cursor should be placed at the start or end of the block.
|
|
2632
2584
|
*/
|
|
2633
|
-
setTextCursorPosition(
|
|
2634
|
-
const
|
|
2585
|
+
setTextCursorPosition(t, e = "start") {
|
|
2586
|
+
const r = typeof t == "string" ? t : t.id, { posBeforeNode: n } = K(r, this._tiptapEditor.state.doc), { startPos: i, contentNode: a } = g(
|
|
2635
2587
|
this._tiptapEditor.state.doc,
|
|
2636
|
-
|
|
2588
|
+
n + 2
|
|
2637
2589
|
);
|
|
2638
|
-
|
|
2590
|
+
e === "start" ? this._tiptapEditor.commands.setTextSelection(i + 1) : this._tiptapEditor.commands.setTextSelection(
|
|
2639
2591
|
i + a.nodeSize - 1
|
|
2640
2592
|
);
|
|
2641
2593
|
}
|
|
2594
|
+
/**
|
|
2595
|
+
* Gets a snapshot of the current selection.
|
|
2596
|
+
*/
|
|
2597
|
+
getSelection() {
|
|
2598
|
+
if (this._tiptapEditor.state.selection.from === this._tiptapEditor.state.selection.to)
|
|
2599
|
+
return;
|
|
2600
|
+
const t = [];
|
|
2601
|
+
return this._tiptapEditor.state.doc.descendants((e, r) => e.type.spec.group !== "blockContent" || r + e.nodeSize < this._tiptapEditor.state.selection.from || r > this._tiptapEditor.state.selection.to ? !0 : (t.push(
|
|
2602
|
+
B(
|
|
2603
|
+
this._tiptapEditor.state.doc.resolve(r).node(),
|
|
2604
|
+
this.blockCache
|
|
2605
|
+
)
|
|
2606
|
+
), !1)), { blocks: t };
|
|
2607
|
+
}
|
|
2608
|
+
/**
|
|
2609
|
+
* Checks if the editor is currently editable, or if it's locked.
|
|
2610
|
+
* @returns True if the editor is editable, false otherwise.
|
|
2611
|
+
*/
|
|
2612
|
+
get isEditable() {
|
|
2613
|
+
return this._tiptapEditor.isEditable;
|
|
2614
|
+
}
|
|
2615
|
+
/**
|
|
2616
|
+
* Makes the editor editable or locks it, depending on the argument passed.
|
|
2617
|
+
* @param editable True to make the editor editable, or false to lock it.
|
|
2618
|
+
*/
|
|
2619
|
+
set isEditable(t) {
|
|
2620
|
+
this._tiptapEditor.setEditable(t);
|
|
2621
|
+
}
|
|
2642
2622
|
/**
|
|
2643
2623
|
* Inserts new blocks into the editor. If a block's `id` is undefined, BlockNote generates one automatically. Throws an
|
|
2644
2624
|
* error if the reference block could not be found.
|
|
@@ -2647,8 +2627,8 @@ class Ho {
|
|
|
2647
2627
|
* @param placement Whether the blocks should be inserted just before, just after, or nested inside the
|
|
2648
2628
|
* `referenceBlock`. Inserts the blocks at the start of the existing block's children if "nested" is used.
|
|
2649
2629
|
*/
|
|
2650
|
-
insertBlocks(
|
|
2651
|
-
|
|
2630
|
+
insertBlocks(t, e, r = "before") {
|
|
2631
|
+
pt(t, e, r, this._tiptapEditor);
|
|
2652
2632
|
}
|
|
2653
2633
|
/**
|
|
2654
2634
|
* Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
|
|
@@ -2657,15 +2637,15 @@ class Ho {
|
|
|
2657
2637
|
* @param blockToUpdate The block that should be updated.
|
|
2658
2638
|
* @param update A partial block which defines how the existing block should be changed.
|
|
2659
2639
|
*/
|
|
2660
|
-
updateBlock(
|
|
2661
|
-
|
|
2640
|
+
updateBlock(t, e) {
|
|
2641
|
+
ee(t, e, this._tiptapEditor);
|
|
2662
2642
|
}
|
|
2663
2643
|
/**
|
|
2664
2644
|
* Removes existing blocks from the editor. Throws an error if any of the blocks could not be found.
|
|
2665
2645
|
* @param blocksToRemove An array of identifiers for existing blocks that should be removed.
|
|
2666
2646
|
*/
|
|
2667
|
-
removeBlocks(
|
|
2668
|
-
|
|
2647
|
+
removeBlocks(t) {
|
|
2648
|
+
ft(t, this._tiptapEditor);
|
|
2669
2649
|
}
|
|
2670
2650
|
/**
|
|
2671
2651
|
* Replaces existing blocks in the editor with new blocks. If the blocks that should be removed are not adjacent or
|
|
@@ -2674,8 +2654,123 @@ class Ho {
|
|
|
2674
2654
|
* @param blocksToRemove An array of blocks that should be replaced.
|
|
2675
2655
|
* @param blocksToInsert An array of partial blocks to replace the old ones with.
|
|
2676
2656
|
*/
|
|
2677
|
-
replaceBlocks(
|
|
2678
|
-
|
|
2657
|
+
replaceBlocks(t, e) {
|
|
2658
|
+
oe(t, e, this._tiptapEditor);
|
|
2659
|
+
}
|
|
2660
|
+
/**
|
|
2661
|
+
* Gets the active text styles at the text cursor position or at the end of the current selection if it's active.
|
|
2662
|
+
*/
|
|
2663
|
+
getActiveStyles() {
|
|
2664
|
+
const t = {}, e = this._tiptapEditor.state.selection.$to.marks(), r = /* @__PURE__ */ new Set([
|
|
2665
|
+
"bold",
|
|
2666
|
+
"italic",
|
|
2667
|
+
"underline",
|
|
2668
|
+
"strike",
|
|
2669
|
+
"code"
|
|
2670
|
+
]), n = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
|
|
2671
|
+
for (const i of e)
|
|
2672
|
+
r.has(i.type.name) ? t[i.type.name] = !0 : n.has(i.type.name) && (t[i.type.name] = i.attrs.color);
|
|
2673
|
+
return t;
|
|
2674
|
+
}
|
|
2675
|
+
/**
|
|
2676
|
+
* Adds styles to the currently selected content.
|
|
2677
|
+
* @param styles The styles to add.
|
|
2678
|
+
*/
|
|
2679
|
+
addStyles(t) {
|
|
2680
|
+
const e = /* @__PURE__ */ new Set([
|
|
2681
|
+
"bold",
|
|
2682
|
+
"italic",
|
|
2683
|
+
"underline",
|
|
2684
|
+
"strike",
|
|
2685
|
+
"code"
|
|
2686
|
+
]), r = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
|
|
2687
|
+
for (const [n, i] of Object.entries(t))
|
|
2688
|
+
e.has(n) ? this._tiptapEditor.commands.setMark(n) : r.has(n) && this._tiptapEditor.commands.setMark(n, { color: i });
|
|
2689
|
+
}
|
|
2690
|
+
/**
|
|
2691
|
+
* Removes styles from the currently selected content.
|
|
2692
|
+
* @param styles The styles to remove.
|
|
2693
|
+
*/
|
|
2694
|
+
removeStyles(t) {
|
|
2695
|
+
for (const e of Object.keys(t))
|
|
2696
|
+
this._tiptapEditor.commands.unsetMark(e);
|
|
2697
|
+
}
|
|
2698
|
+
/**
|
|
2699
|
+
* Toggles styles on the currently selected content.
|
|
2700
|
+
* @param styles The styles to toggle.
|
|
2701
|
+
*/
|
|
2702
|
+
toggleStyles(t) {
|
|
2703
|
+
const e = /* @__PURE__ */ new Set([
|
|
2704
|
+
"bold",
|
|
2705
|
+
"italic",
|
|
2706
|
+
"underline",
|
|
2707
|
+
"strike",
|
|
2708
|
+
"code"
|
|
2709
|
+
]), r = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
|
|
2710
|
+
for (const [n, i] of Object.entries(t))
|
|
2711
|
+
e.has(n) ? this._tiptapEditor.commands.toggleMark(n) : r.has(n) && this._tiptapEditor.commands.toggleMark(n, { color: i });
|
|
2712
|
+
}
|
|
2713
|
+
/**
|
|
2714
|
+
* Gets the currently selected text.
|
|
2715
|
+
*/
|
|
2716
|
+
getSelectedText() {
|
|
2717
|
+
return this._tiptapEditor.state.doc.textBetween(
|
|
2718
|
+
this._tiptapEditor.state.selection.from,
|
|
2719
|
+
this._tiptapEditor.state.selection.to
|
|
2720
|
+
);
|
|
2721
|
+
}
|
|
2722
|
+
/**
|
|
2723
|
+
* Gets the URL of the last link in the current selection, or `undefined` if there are no links in the selection.
|
|
2724
|
+
*/
|
|
2725
|
+
getSelectedLinkUrl() {
|
|
2726
|
+
return this._tiptapEditor.getAttributes("link").href;
|
|
2727
|
+
}
|
|
2728
|
+
/**
|
|
2729
|
+
* Creates a new link to replace the selected content.
|
|
2730
|
+
* @param url The link URL.
|
|
2731
|
+
* @param text The text to display the link with.
|
|
2732
|
+
*/
|
|
2733
|
+
createLink(t, e) {
|
|
2734
|
+
if (t === "")
|
|
2735
|
+
return;
|
|
2736
|
+
let { from: r, to: n } = this._tiptapEditor.state.selection;
|
|
2737
|
+
e || (e = this._tiptapEditor.state.doc.textBetween(r, n));
|
|
2738
|
+
const i = this._tiptapEditor.schema.mark("link", { href: t });
|
|
2739
|
+
this._tiptapEditor.view.dispatch(
|
|
2740
|
+
this._tiptapEditor.view.state.tr.insertText(e, r, n).addMark(r, r + e.length, i)
|
|
2741
|
+
);
|
|
2742
|
+
}
|
|
2743
|
+
/**
|
|
2744
|
+
* Checks if the block containing the text cursor can be nested.
|
|
2745
|
+
*/
|
|
2746
|
+
canNestBlock() {
|
|
2747
|
+
const { startPos: t, depth: e } = g(
|
|
2748
|
+
this._tiptapEditor.state.doc,
|
|
2749
|
+
this._tiptapEditor.state.selection.from
|
|
2750
|
+
);
|
|
2751
|
+
return this._tiptapEditor.state.doc.resolve(t).index(e - 1) > 0;
|
|
2752
|
+
}
|
|
2753
|
+
/**
|
|
2754
|
+
* Nests the block containing the text cursor into the block above it.
|
|
2755
|
+
*/
|
|
2756
|
+
nestBlock() {
|
|
2757
|
+
this._tiptapEditor.commands.sinkListItem("blockContainer");
|
|
2758
|
+
}
|
|
2759
|
+
/**
|
|
2760
|
+
* Checks if the block containing the text cursor is nested.
|
|
2761
|
+
*/
|
|
2762
|
+
canUnnestBlock() {
|
|
2763
|
+
const { depth: t } = g(
|
|
2764
|
+
this._tiptapEditor.state.doc,
|
|
2765
|
+
this._tiptapEditor.state.selection.from
|
|
2766
|
+
);
|
|
2767
|
+
return t > 2;
|
|
2768
|
+
}
|
|
2769
|
+
/**
|
|
2770
|
+
* Lifts the block containing the text cursor out of its parent.
|
|
2771
|
+
*/
|
|
2772
|
+
unnestBlock() {
|
|
2773
|
+
this._tiptapEditor.commands.liftListItem("blockContainer");
|
|
2679
2774
|
}
|
|
2680
2775
|
/**
|
|
2681
2776
|
* Serializes blocks into an HTML string. To better conform to HTML standards, children of blocks which aren't list
|
|
@@ -2683,8 +2778,8 @@ class Ho {
|
|
|
2683
2778
|
* @param blocks An array of blocks that should be serialized into HTML.
|
|
2684
2779
|
* @returns The blocks, serialized as an HTML string.
|
|
2685
2780
|
*/
|
|
2686
|
-
async blocksToHTML(
|
|
2687
|
-
return
|
|
2781
|
+
async blocksToHTML(t) {
|
|
2782
|
+
return mt(t, this._tiptapEditor.schema);
|
|
2688
2783
|
}
|
|
2689
2784
|
/**
|
|
2690
2785
|
* Parses blocks from an HTML string. Tries to create `Block` objects out of any HTML block-level elements, and
|
|
@@ -2693,8 +2788,8 @@ class Ho {
|
|
|
2693
2788
|
* @param html The HTML string to parse blocks from.
|
|
2694
2789
|
* @returns The blocks parsed from the HTML string.
|
|
2695
2790
|
*/
|
|
2696
|
-
async HTMLToBlocks(
|
|
2697
|
-
return
|
|
2791
|
+
async HTMLToBlocks(t) {
|
|
2792
|
+
return gt(t, this._tiptapEditor.schema);
|
|
2698
2793
|
}
|
|
2699
2794
|
/**
|
|
2700
2795
|
* Serializes blocks into a Markdown string. The output is simplified as Markdown does not support all features of
|
|
@@ -2702,8 +2797,8 @@ class Ho {
|
|
|
2702
2797
|
* @param blocks An array of blocks that should be serialized into Markdown.
|
|
2703
2798
|
* @returns The blocks, serialized as a Markdown string.
|
|
2704
2799
|
*/
|
|
2705
|
-
async blocksToMarkdown(
|
|
2706
|
-
return
|
|
2800
|
+
async blocksToMarkdown(t) {
|
|
2801
|
+
return ie(t, this._tiptapEditor.schema);
|
|
2707
2802
|
}
|
|
2708
2803
|
/**
|
|
2709
2804
|
* Creates a list of blocks from a Markdown string. Tries to create `Block` and `InlineNode` objects based on
|
|
@@ -2712,16 +2807,16 @@ class Ho {
|
|
|
2712
2807
|
* @param markdown The Markdown string to parse blocks from.
|
|
2713
2808
|
* @returns The blocks parsed from the Markdown string.
|
|
2714
2809
|
*/
|
|
2715
|
-
async markdownToBlocks(
|
|
2716
|
-
return
|
|
2810
|
+
async markdownToBlocks(t) {
|
|
2811
|
+
return se(t, this._tiptapEditor.schema);
|
|
2717
2812
|
}
|
|
2718
2813
|
}
|
|
2719
2814
|
export {
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2815
|
+
x as BaseSlashMenuItem,
|
|
2816
|
+
No as BlockNoteEditor,
|
|
2817
|
+
tt as blockProps,
|
|
2818
|
+
Ze as defaultSlashMenuItems,
|
|
2819
|
+
no as getBlockNoteExtensions,
|
|
2820
|
+
_ as globalProps
|
|
2726
2821
|
};
|
|
2727
2822
|
//# sourceMappingURL=blocknote.js.map
|