4880 lines
156 KiB
JavaScript
4880 lines
156 KiB
JavaScript
/*
|
||
* Extracted from browser-delivered Turbopack chunk: 2a4e4dccbc3fdacb.bc4b655d5c.js
|
||
* Module id: 673654
|
||
* For reading/searching only; this factory depends on the original Turbopack runtime.
|
||
*/
|
||
|
||
const moduleFactory = (e) => {
|
||
"use strict";
|
||
e.i(569372);
|
||
var t = e.i(545773);
|
||
e.i(118859);
|
||
var n = e.i(445794);
|
||
e.i(608469);
|
||
var r = e.i(111092);
|
||
e.i(894176);
|
||
var i = e.i(47091);
|
||
e.i(275849);
|
||
var o = e.i(929126);
|
||
e.i(979748);
|
||
var s = e.i(675993);
|
||
e.i(993489);
|
||
var l = e.i(202008),
|
||
a = Object.defineProperty,
|
||
d = (e, t) => {
|
||
for (var n in t) a(e, n, { get: t[n], enumerable: !0 });
|
||
};
|
||
function c(e) {
|
||
let { state: t, transaction: n } = e,
|
||
{ selection: r } = n,
|
||
{ doc: i } = n,
|
||
{ storedMarks: o } = n;
|
||
return {
|
||
...t,
|
||
apply: t.apply.bind(t),
|
||
applyTransaction: t.applyTransaction.bind(t),
|
||
plugins: t.plugins,
|
||
schema: t.schema,
|
||
reconfigure: t.reconfigure.bind(t),
|
||
toJSON: t.toJSON.bind(t),
|
||
get storedMarks() {
|
||
return o;
|
||
},
|
||
get selection() {
|
||
return r;
|
||
},
|
||
get doc() {
|
||
return i;
|
||
},
|
||
get tr() {
|
||
return (r = n.selection), (i = n.doc), (o = n.storedMarks), n;
|
||
},
|
||
};
|
||
}
|
||
var h = class {
|
||
constructor(e) {
|
||
(this.editor = e.editor),
|
||
(this.rawCommands = this.editor.extensionManager.commands),
|
||
(this.customState = e.state);
|
||
}
|
||
get hasCustomState() {
|
||
return !!this.customState;
|
||
}
|
||
get state() {
|
||
return this.customState || this.editor.state;
|
||
}
|
||
get commands() {
|
||
let { rawCommands: e, editor: t, state: n } = this,
|
||
{ view: r } = t,
|
||
{ tr: i } = n,
|
||
o = this.buildProps(i);
|
||
return Object.fromEntries(
|
||
Object.entries(e).map(([e, t]) => [
|
||
e,
|
||
(...e) => {
|
||
let n = t(...e)(o);
|
||
return (
|
||
i.getMeta("preventDispatch") ||
|
||
this.hasCustomState ||
|
||
r.dispatch(i),
|
||
n
|
||
);
|
||
},
|
||
]),
|
||
);
|
||
}
|
||
get chain() {
|
||
return () => this.createChain();
|
||
}
|
||
get can() {
|
||
return () => this.createCan();
|
||
}
|
||
createChain(e, t = !0) {
|
||
let { rawCommands: n, editor: r, state: i } = this,
|
||
{ view: o } = r,
|
||
s = [],
|
||
l = !!e,
|
||
a = e || i.tr,
|
||
d = () => (
|
||
l ||
|
||
!t ||
|
||
a.getMeta("preventDispatch") ||
|
||
this.hasCustomState ||
|
||
o.dispatch(a),
|
||
s.every((e) => !0 === e)
|
||
),
|
||
c = {
|
||
...Object.fromEntries(
|
||
Object.entries(n).map(([e, n]) => [
|
||
e,
|
||
(...e) => {
|
||
let r = this.buildProps(a, t),
|
||
i = n(...e)(r);
|
||
return s.push(i), c;
|
||
},
|
||
]),
|
||
),
|
||
run: d,
|
||
};
|
||
return c;
|
||
}
|
||
createCan(e) {
|
||
let { rawCommands: t, state: n } = this,
|
||
r = e || n.tr,
|
||
i = this.buildProps(r, !1);
|
||
return {
|
||
...Object.fromEntries(
|
||
Object.entries(t).map(([e, t]) => [
|
||
e,
|
||
(...e) => t(...e)({ ...i, dispatch: void 0 }),
|
||
]),
|
||
),
|
||
chain: () => this.createChain(r, !1),
|
||
};
|
||
}
|
||
buildProps(e, t = !0) {
|
||
let { rawCommands: n, editor: r, state: i } = this,
|
||
{ view: o } = r,
|
||
s = {
|
||
tr: e,
|
||
editor: r,
|
||
view: o,
|
||
state: c({ state: i, transaction: e }),
|
||
dispatch: t ? () => void 0 : void 0,
|
||
chain: () => this.createChain(e, t),
|
||
can: () => this.createCan(e),
|
||
get commands() {
|
||
return Object.fromEntries(
|
||
Object.entries(n).map(([e, t]) => [e, (...e) => t(...e)(s)]),
|
||
);
|
||
},
|
||
};
|
||
return s;
|
||
}
|
||
},
|
||
p = {};
|
||
d(p, {
|
||
blur: () => u,
|
||
clearContent: () => f,
|
||
clearNodes: () => m,
|
||
command: () => g,
|
||
createParagraphNear: () => y,
|
||
cut: () => b,
|
||
deleteCurrentNode: () => k,
|
||
deleteNode: () => w,
|
||
deleteRange: () => S,
|
||
deleteSelection: () => x,
|
||
enter: () => M,
|
||
exitCode: () => C,
|
||
extendMarkRange: () => R,
|
||
first: () => I,
|
||
focus: () => j,
|
||
forEach: () => F,
|
||
insertContent: () => V,
|
||
insertContentAt: () => q,
|
||
joinBackward: () => J,
|
||
joinDown: () => U,
|
||
joinForward: () => G,
|
||
joinItemBackward: () => Y,
|
||
joinItemForward: () => Q,
|
||
joinTextblockBackward: () => X,
|
||
joinTextblockForward: () => Z,
|
||
joinUp: () => K,
|
||
keyboardShortcut: () => et,
|
||
lift: () => er,
|
||
liftEmptyBlock: () => ei,
|
||
liftListItem: () => eo,
|
||
newlineInCode: () => es,
|
||
resetAttributes: () => ed,
|
||
scrollIntoView: () => ec,
|
||
selectAll: () => eh,
|
||
selectNodeBackward: () => ep,
|
||
selectNodeForward: () => eu,
|
||
selectParentNode: () => ef,
|
||
selectTextblockEnd: () => em,
|
||
selectTextblockStart: () => eg,
|
||
setContent: () => eb,
|
||
setMark: () => e1,
|
||
setMeta: () => e2,
|
||
setNode: () => e3,
|
||
setNodeSelection: () => e4,
|
||
setTextDirection: () => e5,
|
||
setTextSelection: () => e6,
|
||
sinkListItem: () => e9,
|
||
splitBlock: () => e8,
|
||
splitListItem: () => te,
|
||
toggleList: () => tr,
|
||
toggleMark: () => ti,
|
||
toggleNode: () => to,
|
||
toggleWrap: () => ts,
|
||
undoInputRule: () => tl,
|
||
unsetAllMarks: () => ta,
|
||
unsetMark: () => td,
|
||
unsetTextDirection: () => tc,
|
||
updateAttributes: () => th,
|
||
wrapIn: () => tp,
|
||
wrapInList: () => tu,
|
||
});
|
||
var u =
|
||
() =>
|
||
({ editor: e, view: t }) => (
|
||
requestAnimationFrame(() => {
|
||
var n;
|
||
e.isDestroyed ||
|
||
(t.dom.blur(),
|
||
null == (n = null == window ? void 0 : window.getSelection()) ||
|
||
n.removeAllRanges());
|
||
}),
|
||
!0
|
||
),
|
||
f =
|
||
(e = !0) =>
|
||
({ commands: t }) =>
|
||
t.setContent("", { emitUpdate: e }),
|
||
m =
|
||
() =>
|
||
({ state: e, tr: n, dispatch: r }) => {
|
||
let { selection: i } = n,
|
||
{ ranges: o } = i;
|
||
return (
|
||
!r ||
|
||
(o.forEach(({ $from: r, $to: i }) => {
|
||
e.doc.nodesBetween(r.pos, i.pos, (e, r) => {
|
||
if (e.type.isText) return;
|
||
let { doc: i, mapping: o } = n,
|
||
s = i.resolve(o.map(r)),
|
||
l = i.resolve(o.map(r + e.nodeSize)),
|
||
a = s.blockRange(l);
|
||
if (!a) return;
|
||
let d = (0, t.liftTarget)(a);
|
||
if (e.type.isTextblock) {
|
||
let { defaultType: e } = s.parent.contentMatchAt(s.index());
|
||
n.setNodeMarkup(a.start, e);
|
||
}
|
||
(d || 0 === d) && n.lift(a, d);
|
||
});
|
||
}),
|
||
!0)
|
||
);
|
||
},
|
||
g = (e) => (t) => e(t),
|
||
y =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.createParagraphNear)(e, t),
|
||
b =
|
||
(e, t) =>
|
||
({ editor: n, tr: i }) => {
|
||
let { state: o } = n,
|
||
s = o.doc.slice(e.from, e.to);
|
||
i.deleteRange(e.from, e.to);
|
||
let l = i.mapping.map(t);
|
||
return (
|
||
i.insert(l, s.content),
|
||
i.setSelection(
|
||
new r.TextSelection(i.doc.resolve(Math.max(l - 1, 0))),
|
||
),
|
||
!0
|
||
);
|
||
},
|
||
k =
|
||
() =>
|
||
({ tr: e, dispatch: t }) => {
|
||
let { selection: n } = e,
|
||
r = n.$anchor.node();
|
||
if (r.content.size > 0) return !1;
|
||
let i = e.selection.$anchor;
|
||
for (let n = i.depth; n > 0; n -= 1)
|
||
if (i.node(n).type === r.type) {
|
||
if (t) {
|
||
let t = i.before(n),
|
||
r = i.after(n);
|
||
e.delete(t, r).scrollIntoView();
|
||
}
|
||
return !0;
|
||
}
|
||
return !1;
|
||
};
|
||
function v(e, t) {
|
||
if ("string" == typeof e) {
|
||
if (!t.nodes[e])
|
||
throw Error(
|
||
`There is no node type named '${e}'. Maybe you forgot to add the extension?`,
|
||
);
|
||
return t.nodes[e];
|
||
}
|
||
return e;
|
||
}
|
||
var w =
|
||
(e) =>
|
||
({ tr: t, state: n, dispatch: r }) => {
|
||
let i = v(e, n.schema),
|
||
o = t.selection.$anchor;
|
||
for (let e = o.depth; e > 0; e -= 1)
|
||
if (o.node(e).type === i) {
|
||
if (r) {
|
||
let n = o.before(e),
|
||
r = o.after(e);
|
||
t.delete(n, r).scrollIntoView();
|
||
}
|
||
return !0;
|
||
}
|
||
return !1;
|
||
},
|
||
S =
|
||
(e) =>
|
||
({ tr: t, dispatch: n }) => {
|
||
let { from: r, to: i } = e;
|
||
return n && t.delete(r, i), !0;
|
||
},
|
||
x =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.deleteSelection)(e, t),
|
||
M =
|
||
() =>
|
||
({ commands: e }) =>
|
||
e.keyboardShortcut("Enter"),
|
||
C =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.exitCode)(e, t);
|
||
function T(e) {
|
||
return "[object RegExp]" === Object.prototype.toString.call(e);
|
||
}
|
||
function N(e, t, n = { strict: !0 }) {
|
||
let r = Object.keys(t);
|
||
return (
|
||
!r.length ||
|
||
r.every((r) =>
|
||
n.strict ? t[r] === e[r] : T(t[r]) ? t[r].test(e[r]) : t[r] === e[r],
|
||
)
|
||
);
|
||
}
|
||
function E(e, t, n = {}) {
|
||
return e.find(
|
||
(e) =>
|
||
e.type === t &&
|
||
N(Object.fromEntries(Object.keys(n).map((t) => [t, e.attrs[t]])), n),
|
||
);
|
||
}
|
||
function O(e, t, n = {}) {
|
||
return !!E(e, t, n);
|
||
}
|
||
function A(e, t, n) {
|
||
var r;
|
||
if (!e || !t) return;
|
||
let i = e.parent.childAfter(e.parentOffset);
|
||
if (
|
||
((i.node && i.node.marks.some((e) => e.type === t)) ||
|
||
(i = e.parent.childBefore(e.parentOffset)),
|
||
!i.node ||
|
||
!i.node.marks.some((e) => e.type === t) ||
|
||
((n = n || (null == (r = i.node.marks[0]) ? void 0 : r.attrs)),
|
||
!E([...i.node.marks], t, n)))
|
||
)
|
||
return;
|
||
let o = i.index,
|
||
s = e.start() + i.offset,
|
||
l = o + 1,
|
||
a = s + i.node.nodeSize;
|
||
for (; o > 0 && O([...e.parent.child(o - 1).marks], t, n); )
|
||
(o -= 1), (s -= e.parent.child(o).nodeSize);
|
||
for (; l < e.parent.childCount && O([...e.parent.child(l).marks], t, n); )
|
||
(a += e.parent.child(l).nodeSize), (l += 1);
|
||
return { from: s, to: a };
|
||
}
|
||
function D(e, t) {
|
||
if ("string" == typeof e) {
|
||
if (!t.marks[e])
|
||
throw Error(
|
||
`There is no mark type named '${e}'. Maybe you forgot to add the extension?`,
|
||
);
|
||
return t.marks[e];
|
||
}
|
||
return e;
|
||
}
|
||
var R =
|
||
(e, t = {}) =>
|
||
({ tr: n, state: i, dispatch: o }) => {
|
||
let s = D(e, i.schema),
|
||
{ doc: l, selection: a } = n,
|
||
{ $from: d, from: c, to: h } = a;
|
||
if (o) {
|
||
let e = A(d, s, t);
|
||
if (e && e.from <= c && e.to >= h) {
|
||
let t = r.TextSelection.create(l, e.from, e.to);
|
||
n.setSelection(t);
|
||
}
|
||
}
|
||
return !0;
|
||
},
|
||
I = (e) => (t) => {
|
||
let n = "function" == typeof e ? e(t) : e;
|
||
for (let e = 0; e < n.length; e += 1) if (n[e](t)) return !0;
|
||
return !1;
|
||
};
|
||
function P(e) {
|
||
return e instanceof r.TextSelection;
|
||
}
|
||
function L(e = 0, t = 0, n = 0) {
|
||
return Math.min(Math.max(e, t), n);
|
||
}
|
||
function z(e, t = null) {
|
||
if (!t) return null;
|
||
let n = r.Selection.atStart(e),
|
||
i = r.Selection.atEnd(e);
|
||
if ("start" === t || !0 === t) return n;
|
||
if ("end" === t) return i;
|
||
let o = n.from,
|
||
s = i.to;
|
||
return "all" === t
|
||
? r.TextSelection.create(e, L(0, o, s), L(e.content.size, o, s))
|
||
: r.TextSelection.create(e, L(t, o, s), L(t, o, s));
|
||
}
|
||
function B() {
|
||
return (
|
||
"Android" === navigator.platform || /android/i.test(navigator.userAgent)
|
||
);
|
||
}
|
||
function $() {
|
||
return (
|
||
[
|
||
"iPad Simulator",
|
||
"iPhone Simulator",
|
||
"iPod Simulator",
|
||
"iPad",
|
||
"iPhone",
|
||
"iPod",
|
||
].includes(navigator.platform) ||
|
||
(navigator.userAgent.includes("Mac") && "ontouchend" in document)
|
||
);
|
||
}
|
||
var j =
|
||
(e = null, t = {}) =>
|
||
({ editor: n, view: r, tr: i, dispatch: o }) => {
|
||
t = { scrollIntoView: !0, ...t };
|
||
let s = () => {
|
||
($() || B()) && r.dom.focus(),
|
||
"u" > typeof navigator &&
|
||
/^((?!chrome|android).)*safari/i.test(navigator.userAgent) &&
|
||
!$() &&
|
||
!B() &&
|
||
r.dom.focus({ preventScroll: !0 }),
|
||
requestAnimationFrame(() => {
|
||
!n.isDestroyed &&
|
||
(r.focus(),
|
||
(null == t ? void 0 : t.scrollIntoView) &&
|
||
n.commands.scrollIntoView());
|
||
});
|
||
};
|
||
try {
|
||
if ((r.hasFocus() && null === e) || !1 === e) return !0;
|
||
} catch {
|
||
return !1;
|
||
}
|
||
if (o && null === e && !P(n.state.selection)) return s(), !0;
|
||
let l = z(i.doc, e) || n.state.selection,
|
||
a = n.state.selection.eq(l);
|
||
return (
|
||
o &&
|
||
(a || i.setSelection(l),
|
||
a && i.storedMarks && i.setStoredMarks(i.storedMarks),
|
||
s()),
|
||
!0
|
||
);
|
||
},
|
||
F = (e, t) => (n) => e.every((e, r) => t(e, { ...n, index: r })),
|
||
V =
|
||
(e, t) =>
|
||
({ tr: n, commands: r }) =>
|
||
r.insertContentAt(
|
||
{ from: n.selection.from, to: n.selection.to },
|
||
e,
|
||
t,
|
||
),
|
||
H = (e) => {
|
||
let t = e.childNodes;
|
||
for (let n = t.length - 1; n >= 0; n -= 1) {
|
||
let r = t[n];
|
||
3 === r.nodeType && r.nodeValue && /^(\n\s\s|\n)$/.test(r.nodeValue)
|
||
? e.removeChild(r)
|
||
: 1 === r.nodeType && H(r);
|
||
}
|
||
return e;
|
||
};
|
||
function W(e) {
|
||
if ("u" < typeof window)
|
||
throw Error(
|
||
"[tiptap error]: there is no window object available, so this function cannot be used",
|
||
);
|
||
let t = `<body>${e}</body>`;
|
||
return H(new window.DOMParser().parseFromString(t, "text/html").body);
|
||
}
|
||
function _(e, t, n) {
|
||
if (e instanceof i.Node || e instanceof i.Fragment) return e;
|
||
n = { slice: !0, parseOptions: {}, ...n };
|
||
let r = "object" == typeof e && null !== e,
|
||
o = "string" == typeof e;
|
||
if (r)
|
||
try {
|
||
if (Array.isArray(e) && e.length > 0)
|
||
return i.Fragment.fromArray(e.map((e) => t.nodeFromJSON(e)));
|
||
let r = t.nodeFromJSON(e);
|
||
return n.errorOnInvalidContent && r.check(), r;
|
||
} catch (r) {
|
||
if (n.errorOnInvalidContent)
|
||
throw Error("[tiptap error]: Invalid JSON content", { cause: r });
|
||
return (
|
||
console.warn(
|
||
"[tiptap warn]: Invalid content.",
|
||
"Passed value:",
|
||
e,
|
||
"Error:",
|
||
r,
|
||
),
|
||
_("", t, n)
|
||
);
|
||
}
|
||
if (o) {
|
||
if (n.errorOnInvalidContent) {
|
||
let r = !1,
|
||
o = "",
|
||
s = new i.Schema({
|
||
topNode: t.spec.topNode,
|
||
marks: t.spec.marks,
|
||
nodes: t.spec.nodes.append({
|
||
__tiptap__private__unknown__catch__all__node: {
|
||
content: "inline*",
|
||
group: "block",
|
||
parseDOM: [
|
||
{
|
||
tag: "*",
|
||
getAttrs: (e) => (
|
||
(r = !0),
|
||
(o = "string" == typeof e ? e : e.outerHTML),
|
||
null
|
||
),
|
||
},
|
||
],
|
||
},
|
||
}),
|
||
});
|
||
if (
|
||
(n.slice
|
||
? i.DOMParser.fromSchema(s).parseSlice(W(e), n.parseOptions)
|
||
: i.DOMParser.fromSchema(s).parse(W(e), n.parseOptions),
|
||
n.errorOnInvalidContent && r)
|
||
)
|
||
throw Error("[tiptap error]: Invalid HTML content", {
|
||
cause: Error(`Invalid element found: ${o}`),
|
||
});
|
||
}
|
||
let r = i.DOMParser.fromSchema(t);
|
||
return n.slice
|
||
? r.parseSlice(W(e), n.parseOptions).content
|
||
: r.parse(W(e), n.parseOptions);
|
||
}
|
||
return _("", t, n);
|
||
}
|
||
var q =
|
||
(e, n, o) =>
|
||
({ tr: s, dispatch: l, editor: a }) => {
|
||
var d;
|
||
if (l) {
|
||
let l, c;
|
||
o = {
|
||
parseOptions: a.options.parseOptions,
|
||
updateSelection: !0,
|
||
applyInputRules: !1,
|
||
applyPasteRules: !1,
|
||
...o,
|
||
};
|
||
let h = (e) => {
|
||
a.emit("contentError", {
|
||
editor: a,
|
||
error: e,
|
||
disableCollaboration: () => {
|
||
"collaboration" in a.storage &&
|
||
"object" == typeof a.storage.collaboration &&
|
||
a.storage.collaboration &&
|
||
(a.storage.collaboration.isDisabled = !0);
|
||
},
|
||
});
|
||
},
|
||
p = { preserveWhitespace: "full", ...o.parseOptions };
|
||
if (
|
||
!o.errorOnInvalidContent &&
|
||
!a.options.enableContentCheck &&
|
||
a.options.emitContentError
|
||
)
|
||
try {
|
||
_(n, a.schema, { parseOptions: p, errorOnInvalidContent: !0 });
|
||
} catch (e) {
|
||
h(e);
|
||
}
|
||
try {
|
||
l = _(n, a.schema, {
|
||
parseOptions: p,
|
||
errorOnInvalidContent:
|
||
null != (d = o.errorOnInvalidContent)
|
||
? d
|
||
: a.options.enableContentCheck,
|
||
});
|
||
} catch (e) {
|
||
return h(e), !1;
|
||
}
|
||
let { from: u, to: f } =
|
||
"number" == typeof e
|
||
? { from: e, to: e }
|
||
: { from: e.from, to: e.to },
|
||
m = !0,
|
||
g = !0;
|
||
if (
|
||
((!("type" in l) ? l : [l]).forEach((e) => {
|
||
e.check(),
|
||
(m = !!m && e.isText && 0 === e.marks.length),
|
||
(g = !!g && e.isBlock);
|
||
}),
|
||
u === f && g)
|
||
) {
|
||
let { parent: e } = s.doc.resolve(u);
|
||
!e.isTextblock ||
|
||
e.type.spec.code ||
|
||
e.childCount ||
|
||
((u -= 1), (f += 1));
|
||
}
|
||
if (m) {
|
||
if (Array.isArray(n)) c = n.map((e) => e.text || "").join("");
|
||
else if (n instanceof i.Fragment) {
|
||
let e = "";
|
||
n.forEach((t) => {
|
||
t.text && (e += t.text);
|
||
}),
|
||
(c = e);
|
||
} else c = "object" == typeof n && n && n.text ? n.text : n;
|
||
s.insertText(c, u, f);
|
||
} else {
|
||
c = l;
|
||
let e = s.doc.resolve(u),
|
||
t = e.node(),
|
||
n = 0 === e.parentOffset,
|
||
r = t.isText || t.isTextblock,
|
||
i = t.content.size > 0;
|
||
n && r && i && (u = Math.max(0, u - 1)), s.replaceWith(u, f, c);
|
||
}
|
||
o.updateSelection &&
|
||
(function (e, n, i) {
|
||
let o = e.steps.length - 1;
|
||
if (o < n) return;
|
||
let s = e.steps[o];
|
||
if (
|
||
!(
|
||
s instanceof t.ReplaceStep ||
|
||
s instanceof t.ReplaceAroundStep
|
||
)
|
||
)
|
||
return;
|
||
let l = e.mapping.maps[o],
|
||
a = 0;
|
||
l.forEach((e, t, n, r) => {
|
||
0 === a && (a = r);
|
||
}),
|
||
e.setSelection(r.Selection.near(e.doc.resolve(a), -1));
|
||
})(s, s.steps.length - 1, 0),
|
||
o.applyInputRules &&
|
||
s.setMeta("applyInputRules", { from: u, text: c }),
|
||
o.applyPasteRules &&
|
||
s.setMeta("applyPasteRules", { from: u, text: c });
|
||
}
|
||
return !0;
|
||
},
|
||
K =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.joinUp)(e, t),
|
||
U =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.joinDown)(e, t),
|
||
J =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.joinBackward)(e, t),
|
||
G =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.joinForward)(e, t),
|
||
Y =
|
||
() =>
|
||
({ state: e, dispatch: n, tr: r }) => {
|
||
try {
|
||
let i = (0, t.joinPoint)(e.doc, e.selection.$from.pos, -1);
|
||
if (null == i) return !1;
|
||
return r.join(i, 2), n && n(r), !0;
|
||
} catch {
|
||
return !1;
|
||
}
|
||
},
|
||
Q =
|
||
() =>
|
||
({ state: e, dispatch: n, tr: r }) => {
|
||
try {
|
||
let i = (0, t.joinPoint)(e.doc, e.selection.$from.pos, 1);
|
||
if (null == i) return !1;
|
||
return r.join(i, 2), n && n(r), !0;
|
||
} catch {
|
||
return !1;
|
||
}
|
||
},
|
||
X =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.joinTextblockBackward)(e, t),
|
||
Z =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.joinTextblockForward)(e, t);
|
||
function ee() {
|
||
return "u" > typeof navigator && /Mac/.test(navigator.platform);
|
||
}
|
||
var et =
|
||
(e) =>
|
||
({ editor: t, view: n, tr: r, dispatch: i }) => {
|
||
let o = (function (e) {
|
||
let t,
|
||
n,
|
||
r,
|
||
i,
|
||
o = e.split(/-(?!$)/),
|
||
s = o[o.length - 1];
|
||
"Space" === s && (s = " ");
|
||
for (let e = 0; e < o.length - 1; e += 1) {
|
||
let s = o[e];
|
||
if (/^(cmd|meta|m)$/i.test(s)) i = !0;
|
||
else if (/^a(lt)?$/i.test(s)) t = !0;
|
||
else if (/^(c|ctrl|control)$/i.test(s)) n = !0;
|
||
else if (/^s(hift)?$/i.test(s)) r = !0;
|
||
else if (/^mod$/i.test(s)) $() || ee() ? (i = !0) : (n = !0);
|
||
else throw Error(`Unrecognized modifier name: ${s}`);
|
||
}
|
||
return (
|
||
t && (s = `Alt-${s}`),
|
||
n && (s = `Ctrl-${s}`),
|
||
i && (s = `Meta-${s}`),
|
||
r && (s = `Shift-${s}`),
|
||
s
|
||
);
|
||
})(e).split(/-(?!$)/),
|
||
s = o.find((e) => !["Alt", "Ctrl", "Meta", "Shift"].includes(e)),
|
||
l = new KeyboardEvent("keydown", {
|
||
key: "Space" === s ? " " : s,
|
||
altKey: o.includes("Alt"),
|
||
ctrlKey: o.includes("Ctrl"),
|
||
metaKey: o.includes("Meta"),
|
||
shiftKey: o.includes("Shift"),
|
||
bubbles: !0,
|
||
cancelable: !0,
|
||
}),
|
||
a = t.captureTransaction(() => {
|
||
n.someProp("handleKeyDown", (e) => e(n, l));
|
||
});
|
||
return (
|
||
null == a ||
|
||
a.steps.forEach((e) => {
|
||
let t = e.map(r.mapping);
|
||
t && i && r.maybeStep(t);
|
||
}),
|
||
!0
|
||
);
|
||
};
|
||
function en(e, t, n = {}) {
|
||
let { from: r, to: i, empty: o } = e.selection,
|
||
s = t ? v(t, e.schema) : null,
|
||
l = [];
|
||
e.doc.nodesBetween(r, i, (e, t) => {
|
||
if (e.isText) return;
|
||
let n = Math.max(r, t),
|
||
o = Math.min(i, t + e.nodeSize);
|
||
l.push({ node: e, from: n, to: o });
|
||
});
|
||
let a = i - r,
|
||
d = l
|
||
.filter((e) => !s || s.name === e.node.type.name)
|
||
.filter((e) => N(e.node.attrs, n, { strict: !1 }));
|
||
return o ? !!d.length : d.reduce((e, t) => e + t.to - t.from, 0) >= a;
|
||
}
|
||
var er =
|
||
(e, t = {}) =>
|
||
({ state: r, dispatch: i }) => {
|
||
let o = v(e, r.schema);
|
||
return !!en(r, o, t) && (0, n.lift)(r, i);
|
||
},
|
||
ei =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.liftEmptyBlock)(e, t),
|
||
eo =
|
||
(e) =>
|
||
({ state: t, dispatch: n }) => {
|
||
let r = v(e, t.schema);
|
||
return (0, o.liftListItem)(r)(t, n);
|
||
},
|
||
es =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.newlineInCode)(e, t);
|
||
function el(e, t) {
|
||
return t.nodes[e] ? "node" : t.marks[e] ? "mark" : null;
|
||
}
|
||
function ea(e, t) {
|
||
let n = "string" == typeof t ? [t] : t;
|
||
return Object.keys(e).reduce(
|
||
(t, r) => (n.includes(r) || (t[r] = e[r]), t),
|
||
{},
|
||
);
|
||
}
|
||
var ed =
|
||
(e, t) =>
|
||
({ tr: n, state: r, dispatch: i }) => {
|
||
let o = null,
|
||
s = null,
|
||
l = el("string" == typeof e ? e : e.name, r.schema);
|
||
if (!l) return !1;
|
||
"node" === l && (o = v(e, r.schema)),
|
||
"mark" === l && (s = D(e, r.schema));
|
||
let a = !1;
|
||
return (
|
||
n.selection.ranges.forEach((e) => {
|
||
r.doc.nodesBetween(e.$from.pos, e.$to.pos, (e, r) => {
|
||
o &&
|
||
o === e.type &&
|
||
((a = !0), i && n.setNodeMarkup(r, void 0, ea(e.attrs, t))),
|
||
s &&
|
||
e.marks.length &&
|
||
e.marks.forEach((o) => {
|
||
s === o.type &&
|
||
((a = !0),
|
||
i &&
|
||
n.addMark(
|
||
r,
|
||
r + e.nodeSize,
|
||
s.create(ea(o.attrs, t)),
|
||
));
|
||
});
|
||
});
|
||
}),
|
||
a
|
||
);
|
||
},
|
||
ec =
|
||
() =>
|
||
({ tr: e, dispatch: t }) => (t && e.scrollIntoView(), !0),
|
||
eh =
|
||
() =>
|
||
({ tr: e, dispatch: t }) => {
|
||
if (t) {
|
||
let t = new r.AllSelection(e.doc);
|
||
e.setSelection(t);
|
||
}
|
||
return !0;
|
||
},
|
||
ep =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.selectNodeBackward)(e, t),
|
||
eu =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.selectNodeForward)(e, t),
|
||
ef =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.selectParentNode)(e, t),
|
||
em =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.selectTextblockEnd)(e, t),
|
||
eg =
|
||
() =>
|
||
({ state: e, dispatch: t }) =>
|
||
(0, n.selectTextblockStart)(e, t);
|
||
function ey(e, t, n = {}, r = {}) {
|
||
return _(e, t, {
|
||
slice: !1,
|
||
parseOptions: n,
|
||
errorOnInvalidContent: r.errorOnInvalidContent,
|
||
});
|
||
}
|
||
var eb =
|
||
(
|
||
e,
|
||
{
|
||
errorOnInvalidContent: t,
|
||
emitUpdate: n = !0,
|
||
parseOptions: r = {},
|
||
} = {},
|
||
) =>
|
||
({ editor: i, tr: o, dispatch: s, commands: l }) => {
|
||
let { doc: a } = o;
|
||
if ("full" !== r.preserveWhitespace) {
|
||
let l = ey(e, i.schema, r, {
|
||
errorOnInvalidContent: null != t ? t : i.options.enableContentCheck,
|
||
});
|
||
return (
|
||
s &&
|
||
o.replaceWith(0, a.content.size, l).setMeta("preventUpdate", !n),
|
||
!0
|
||
);
|
||
}
|
||
return (
|
||
s && o.setMeta("preventUpdate", !n),
|
||
l.insertContentAt({ from: 0, to: a.content.size }, e, {
|
||
parseOptions: r,
|
||
errorOnInvalidContent: null != t ? t : i.options.enableContentCheck,
|
||
})
|
||
);
|
||
};
|
||
function ek(e, t) {
|
||
let n = D(t, e.schema),
|
||
{ from: r, to: i, empty: o } = e.selection,
|
||
s = [];
|
||
o
|
||
? (e.storedMarks && s.push(...e.storedMarks),
|
||
s.push(...e.selection.$head.marks()))
|
||
: e.doc.nodesBetween(r, i, (e) => {
|
||
s.push(...e.marks);
|
||
});
|
||
let l = s.find((e) => e.type.name === n.name);
|
||
return l ? { ...l.attrs } : {};
|
||
}
|
||
function ev(e, n) {
|
||
let r = new t.Transform(e);
|
||
return (
|
||
n.forEach((e) => {
|
||
e.steps.forEach((e) => {
|
||
r.step(e);
|
||
});
|
||
}),
|
||
r
|
||
);
|
||
}
|
||
function ew(e, t, n) {
|
||
let r = [];
|
||
return (
|
||
e.nodesBetween(t.from, t.to, (e, t) => {
|
||
n(e) && r.push({ node: e, pos: t });
|
||
}),
|
||
r
|
||
);
|
||
}
|
||
function eS(e) {
|
||
return (t) =>
|
||
(function (e, t) {
|
||
for (let n = e.depth; n > 0; n -= 1) {
|
||
let r = e.node(n);
|
||
if (t(r))
|
||
return {
|
||
pos: n > 0 ? e.before(n) : 0,
|
||
start: e.start(n),
|
||
depth: n,
|
||
node: r,
|
||
};
|
||
}
|
||
})(t.$from, e);
|
||
}
|
||
function ex(e, t, n) {
|
||
return void 0 === e.config[t] && e.parent
|
||
? ex(e.parent, t, n)
|
||
: "function" == typeof e.config[t]
|
||
? e.config[t].bind({
|
||
...n,
|
||
parent: e.parent ? ex(e.parent, t, n) : null,
|
||
})
|
||
: e.config[t];
|
||
}
|
||
function eM(e) {
|
||
return e
|
||
.map((e) => {
|
||
let t = { name: e.name, options: e.options, storage: e.storage },
|
||
n = ex(e, "addExtensions", t);
|
||
return n ? [e, ...eM(n())] : e;
|
||
})
|
||
.flat(10);
|
||
}
|
||
function eC(e, t) {
|
||
let n = i.DOMSerializer.fromSchema(t).serializeFragment(e),
|
||
r = document.implementation.createHTMLDocument().createElement("div");
|
||
return r.appendChild(n), r.innerHTML;
|
||
}
|
||
function eT(e) {
|
||
return "function" == typeof e;
|
||
}
|
||
function eN(e, t, ...n) {
|
||
return eT(e) ? (t ? e.bind(t)(...n) : e(...n)) : e;
|
||
}
|
||
function eE(e) {
|
||
let t = e.filter((e) => "extension" === e.type);
|
||
return {
|
||
baseExtensions: t,
|
||
nodeExtensions: e.filter((e) => "node" === e.type),
|
||
markExtensions: e.filter((e) => "mark" === e.type),
|
||
};
|
||
}
|
||
function eO(e) {
|
||
let t = [],
|
||
{ nodeExtensions: n, markExtensions: r } = eE(e),
|
||
i = [...n, ...r],
|
||
o = {
|
||
default: null,
|
||
validate: void 0,
|
||
rendered: !0,
|
||
renderHTML: null,
|
||
parseHTML: null,
|
||
keepOnSplit: !0,
|
||
isRequired: !1,
|
||
},
|
||
s = n.filter((e) => "text" !== e.name).map((e) => e.name),
|
||
l = r.map((e) => e.name),
|
||
a = [...s, ...l];
|
||
return (
|
||
e.forEach((e) => {
|
||
let n = {
|
||
name: e.name,
|
||
options: e.options,
|
||
storage: e.storage,
|
||
extensions: i,
|
||
},
|
||
r = ex(e, "addGlobalAttributes", n);
|
||
r &&
|
||
r().forEach((e) => {
|
||
(Array.isArray(e.types)
|
||
? e.types
|
||
: "*" === e.types
|
||
? a
|
||
: "nodes" === e.types
|
||
? s
|
||
: "marks" === e.types
|
||
? l
|
||
: []
|
||
).forEach((n) => {
|
||
Object.entries(e.attributes).forEach(([e, r]) => {
|
||
t.push({ type: n, name: e, attribute: { ...o, ...r } });
|
||
});
|
||
});
|
||
});
|
||
}),
|
||
i.forEach((e) => {
|
||
let n = { name: e.name, options: e.options, storage: e.storage },
|
||
r = ex(e, "addAttributes", n);
|
||
r &&
|
||
Object.entries(r()).forEach(([n, r]) => {
|
||
let i = { ...o, ...r };
|
||
"function" == typeof (null == i ? void 0 : i.default) &&
|
||
(i.default = i.default()),
|
||
(null == i ? void 0 : i.isRequired) &&
|
||
(null == i ? void 0 : i.default) === void 0 &&
|
||
delete i.default,
|
||
t.push({ type: e.name, name: n, attribute: i });
|
||
});
|
||
}),
|
||
t
|
||
);
|
||
}
|
||
function eA(...e) {
|
||
return e
|
||
.filter((e) => !!e)
|
||
.reduce((e, t) => {
|
||
let n = { ...e };
|
||
return (
|
||
Object.entries(t).forEach(([e, t]) => {
|
||
if (!n[e]) {
|
||
n[e] = t;
|
||
return;
|
||
}
|
||
if ("class" === e) {
|
||
let r = t ? String(t).split(" ") : [],
|
||
i = n[e] ? n[e].split(" ") : [],
|
||
o = r.filter((e) => !i.includes(e));
|
||
n[e] = [...i, ...o].join(" ");
|
||
} else if ("style" === e) {
|
||
let r = t
|
||
? t
|
||
.split(";")
|
||
.map((e) => e.trim())
|
||
.filter(Boolean)
|
||
: [],
|
||
i = n[e]
|
||
? n[e]
|
||
.split(";")
|
||
.map((e) => e.trim())
|
||
.filter(Boolean)
|
||
: [],
|
||
o = new Map();
|
||
i.forEach((e) => {
|
||
let [t, n] = e.split(":").map((e) => e.trim());
|
||
o.set(t, n);
|
||
}),
|
||
r.forEach((e) => {
|
||
let [t, n] = e.split(":").map((e) => e.trim());
|
||
o.set(t, n);
|
||
}),
|
||
(n[e] = Array.from(o.entries())
|
||
.map(([e, t]) => `${e}: ${t}`)
|
||
.join("; "));
|
||
} else n[e] = t;
|
||
}),
|
||
n
|
||
);
|
||
}, {});
|
||
}
|
||
function eD(e, t) {
|
||
return t
|
||
.filter((t) => t.type === e.type.name)
|
||
.filter((e) => e.attribute.rendered)
|
||
.map((t) =>
|
||
t.attribute.renderHTML
|
||
? t.attribute.renderHTML(e.attrs) || {}
|
||
: { [t.name]: e.attrs[t.name] },
|
||
)
|
||
.reduce((e, t) => eA(e, t), {});
|
||
}
|
||
function eR(e, t) {
|
||
return "style" in e
|
||
? e
|
||
: {
|
||
...e,
|
||
getAttrs: (n) => {
|
||
let r = e.getAttrs ? e.getAttrs(n) : e.attrs;
|
||
if (!1 === r) return !1;
|
||
let i = t.reduce((e, t) => {
|
||
var r;
|
||
let i = t.attribute.parseHTML
|
||
? t.attribute.parseHTML(n)
|
||
: "string" != typeof (r = n.getAttribute(t.name))
|
||
? r
|
||
: r.match(/^[+-]?(?:\d*\.)?\d+$/)
|
||
? Number(r)
|
||
: "true" === r || ("false" !== r && r);
|
||
return null == i ? e : { ...e, [t.name]: i };
|
||
}, {});
|
||
return { ...r, ...i };
|
||
},
|
||
};
|
||
}
|
||
function eI(e) {
|
||
return Object.fromEntries(
|
||
Object.entries(e).filter(
|
||
([e, t]) =>
|
||
!(
|
||
"attrs" === e &&
|
||
(function (e = {}) {
|
||
return 0 === Object.keys(e).length && e.constructor === Object;
|
||
})(t)
|
||
) && null != t,
|
||
),
|
||
);
|
||
}
|
||
function eP(e) {
|
||
var t, n;
|
||
let r = {};
|
||
return (
|
||
!(null == (t = null == e ? void 0 : e.attribute)
|
||
? void 0
|
||
: t.isRequired) &&
|
||
"default" in ((null == e ? void 0 : e.attribute) || {}) &&
|
||
(r.default = e.attribute.default),
|
||
(null == (n = null == e ? void 0 : e.attribute)
|
||
? void 0
|
||
: n.validate) !== void 0 && (r.validate = e.attribute.validate),
|
||
[e.name, r]
|
||
);
|
||
}
|
||
function eL(e) {
|
||
return e.sort((e, t) => {
|
||
let n = ex(e, "priority") || 100,
|
||
r = ex(t, "priority") || 100;
|
||
return n > r ? -1 : +(n < r);
|
||
});
|
||
}
|
||
function ez(e) {
|
||
var t;
|
||
let n = eL(eM(e)),
|
||
r = Array.from(
|
||
new Set(
|
||
(t = n.map((e) => e.name)).filter((e, n) => t.indexOf(e) !== n),
|
||
),
|
||
);
|
||
return (
|
||
r.length &&
|
||
console.warn(
|
||
`[tiptap warn]: Duplicate extension names found: [${r.map((e) => `'${e}'`).join(", ")}]. This can lead to issues.`,
|
||
),
|
||
n
|
||
);
|
||
}
|
||
function eB(e, t, n) {
|
||
let { from: r, to: i } = t,
|
||
{ blockSeparator: o = "\n\n", textSerializers: s = {} } = n || {},
|
||
l = "";
|
||
return (
|
||
e.nodesBetween(r, i, (e, n, a, d) => {
|
||
var c;
|
||
e.isBlock && n > r && (l += o);
|
||
let h = null == s ? void 0 : s[e.type.name];
|
||
if (h)
|
||
return (
|
||
a && (l += h({ node: e, pos: n, parent: a, index: d, range: t })),
|
||
!1
|
||
);
|
||
e.isText &&
|
||
(l +=
|
||
null == (c = null == e ? void 0 : e.text)
|
||
? void 0
|
||
: c.slice(Math.max(r, n) - n, i - n));
|
||
}),
|
||
l
|
||
);
|
||
}
|
||
function e$(e) {
|
||
return Object.fromEntries(
|
||
Object.entries(e.nodes)
|
||
.filter(([, e]) => e.spec.toText)
|
||
.map(([e, t]) => [e, t.spec.toText]),
|
||
);
|
||
}
|
||
function ej(e, t) {
|
||
let n = el("string" == typeof t ? t : t.name, e.schema);
|
||
return "node" === n
|
||
? (function (e, t) {
|
||
let n = v(t, e.schema),
|
||
{ from: r, to: i } = e.selection,
|
||
o = [];
|
||
e.doc.nodesBetween(r, i, (e) => {
|
||
o.push(e);
|
||
});
|
||
let s = o.reverse().find((e) => e.type.name === n.name);
|
||
return s ? { ...s.attrs } : {};
|
||
})(e, t)
|
||
: "mark" === n
|
||
? ek(e, t)
|
||
: {};
|
||
}
|
||
function eF(e) {
|
||
let t,
|
||
{ mapping: n, steps: r } = e,
|
||
i = [];
|
||
return (
|
||
n.maps.forEach((e, t) => {
|
||
let o = [];
|
||
if (e.ranges.length)
|
||
e.forEach((e, t) => {
|
||
o.push({ from: e, to: t });
|
||
});
|
||
else {
|
||
let { from: e, to: n } = r[t];
|
||
if (void 0 === e || void 0 === n) return;
|
||
o.push({ from: e, to: n });
|
||
}
|
||
o.forEach(({ from: e, to: r }) => {
|
||
let o = n.slice(t).map(e, -1),
|
||
s = n.slice(t).map(r),
|
||
l = n.invert().map(o, -1),
|
||
a = n.invert().map(s);
|
||
i.push({
|
||
oldRange: { from: l, to: a },
|
||
newRange: { from: o, to: s },
|
||
});
|
||
});
|
||
}),
|
||
1 ===
|
||
(t = (function (e, t = JSON.stringify) {
|
||
let n = {};
|
||
return e.filter((e) => {
|
||
let r = t(e);
|
||
return !Object.prototype.hasOwnProperty.call(n, r) && (n[r] = !0);
|
||
});
|
||
})(i)).length
|
||
? t
|
||
: t.filter(
|
||
(e, n) =>
|
||
!t
|
||
.filter((e, t) => t !== n)
|
||
.some(
|
||
(t) =>
|
||
e.oldRange.from >= t.oldRange.from &&
|
||
e.oldRange.to <= t.oldRange.to &&
|
||
e.newRange.from >= t.newRange.from &&
|
||
e.newRange.to <= t.newRange.to,
|
||
),
|
||
)
|
||
);
|
||
}
|
||
function eV(e, t, n) {
|
||
let r = [];
|
||
return (
|
||
e === t
|
||
? n
|
||
.resolve(e)
|
||
.marks()
|
||
.forEach((t) => {
|
||
let i = A(n.resolve(e), t.type);
|
||
i && r.push({ mark: t, ...i });
|
||
})
|
||
: n.nodesBetween(e, t, (e, t) => {
|
||
e &&
|
||
(null == e ? void 0 : e.nodeSize) !== void 0 &&
|
||
r.push(
|
||
...e.marks.map((n) => ({
|
||
from: t,
|
||
to: t + e.nodeSize,
|
||
mark: n,
|
||
})),
|
||
);
|
||
}),
|
||
r
|
||
);
|
||
}
|
||
var eH = (e, t, n, r = 20) => {
|
||
let i = e.doc.resolve(n),
|
||
o = r,
|
||
s = null;
|
||
for (; o > 0 && null === s; ) {
|
||
let e = i.node(o);
|
||
(null == e ? void 0 : e.type.name) === t ? (s = e) : (o -= 1);
|
||
}
|
||
return [s, o];
|
||
};
|
||
function eW(e, t) {
|
||
return t.nodes[e] || t.marks[e] || null;
|
||
}
|
||
function e_(e, t, n) {
|
||
return Object.fromEntries(
|
||
Object.entries(n).filter(([n]) => {
|
||
let r = e.find((e) => e.type === t && e.name === n);
|
||
return !!r && r.attribute.keepOnSplit;
|
||
}),
|
||
);
|
||
}
|
||
function eq(e, t, n = {}) {
|
||
let { empty: r, ranges: i } = e.selection,
|
||
o = t ? D(t, e.schema) : null;
|
||
if (r)
|
||
return !!(e.storedMarks || e.selection.$from.marks())
|
||
.filter((e) => !o || o.name === e.type.name)
|
||
.find((e) => N(e.attrs, n, { strict: !1 }));
|
||
let s = 0,
|
||
l = [];
|
||
if (
|
||
(i.forEach(({ $from: t, $to: n }) => {
|
||
let r = t.pos,
|
||
i = n.pos;
|
||
e.doc.nodesBetween(r, i, (e, t) => {
|
||
if (o && e.inlineContent && !e.type.allowsMarkType(o)) return !1;
|
||
if (!e.isText && !e.marks.length) return;
|
||
let n = Math.max(r, t),
|
||
a = Math.min(i, t + e.nodeSize);
|
||
(s += a - n),
|
||
l.push(...e.marks.map((e) => ({ mark: e, from: n, to: a })));
|
||
});
|
||
}),
|
||
0 === s)
|
||
)
|
||
return !1;
|
||
let a = l
|
||
.filter((e) => !o || o.name === e.mark.type.name)
|
||
.filter((e) => N(e.mark.attrs, n, { strict: !1 }))
|
||
.reduce((e, t) => e + t.to - t.from, 0),
|
||
d = l
|
||
.filter((e) => !o || (e.mark.type !== o && e.mark.type.excludes(o)))
|
||
.reduce((e, t) => e + t.to - t.from, 0);
|
||
return (a > 0 ? a + d : a) >= s;
|
||
}
|
||
var eK = (e, t) => {
|
||
let { $from: n, $to: r, $anchor: i } = e.selection;
|
||
if (t) {
|
||
let n = eS((e) => e.type.name === t)(e.selection);
|
||
if (!n) return !1;
|
||
let r = e.doc.resolve(n.pos + 1);
|
||
return i.pos + 1 === r.end();
|
||
}
|
||
return !(r.parentOffset < r.parent.nodeSize - 2) && n.pos === r.pos;
|
||
},
|
||
eU = (e) => {
|
||
let { $from: t, $to: n } = e.selection;
|
||
return !(t.parentOffset > 0) && t.pos === n.pos;
|
||
};
|
||
function eJ(e, t) {
|
||
return Array.isArray(t)
|
||
? t.some((t) => ("string" == typeof t ? t : t.name) === e.name)
|
||
: t;
|
||
}
|
||
function eG(e, t) {
|
||
let { nodeExtensions: n } = eE(t),
|
||
r = n.find((t) => t.name === e);
|
||
if (!r) return !1;
|
||
let i = { name: r.name, options: r.options, storage: r.storage },
|
||
o = eN(ex(r, "group", i));
|
||
return "string" == typeof o && o.split(" ").includes("list");
|
||
}
|
||
function eY(e, { checkChildren: t = !0, ignoreWhitespace: n = !1 } = {}) {
|
||
var r;
|
||
if (n) {
|
||
if ("hardBreak" === e.type.name) return !0;
|
||
if (e.isText) return /^\s*$/m.test(null != (r = e.text) ? r : "");
|
||
}
|
||
if (e.isText) return !e.text;
|
||
if (e.isAtom || e.isLeaf) return !1;
|
||
if (0 === e.content.childCount) return !0;
|
||
if (t) {
|
||
let r = !0;
|
||
return (
|
||
e.content.forEach((e) => {
|
||
!1 !== r &&
|
||
(eY(e, { ignoreWhitespace: n, checkChildren: t }) || (r = !1));
|
||
}),
|
||
r
|
||
);
|
||
}
|
||
return !1;
|
||
}
|
||
function eQ(e) {
|
||
return e instanceof r.NodeSelection;
|
||
}
|
||
var eX = class e {
|
||
constructor(e) {
|
||
this.position = e;
|
||
}
|
||
static fromJSON(t) {
|
||
return new e(t.position);
|
||
}
|
||
toJSON() {
|
||
return { position: this.position };
|
||
}
|
||
};
|
||
function eZ(e, t) {
|
||
let n = t.mapping.mapResult(e.position);
|
||
return { position: new eX(n.pos), mapResult: n };
|
||
}
|
||
function e0(e) {
|
||
return new eX(e);
|
||
}
|
||
var e1 =
|
||
(e, t = {}) =>
|
||
({ tr: n, state: r, dispatch: i }) => {
|
||
let { selection: o } = n,
|
||
{ empty: s, ranges: l } = o,
|
||
a = D(e, r.schema);
|
||
if (i)
|
||
if (s) {
|
||
let e = ek(r, a);
|
||
n.addStoredMark(a.create({ ...e, ...t }));
|
||
} else
|
||
l.forEach((e) => {
|
||
let i = e.$from.pos,
|
||
o = e.$to.pos;
|
||
r.doc.nodesBetween(i, o, (e, r) => {
|
||
let s = Math.max(r, i),
|
||
l = Math.min(r + e.nodeSize, o);
|
||
e.marks.find((e) => e.type === a)
|
||
? e.marks.forEach((e) => {
|
||
a === e.type &&
|
||
n.addMark(s, l, a.create({ ...e.attrs, ...t }));
|
||
})
|
||
: n.addMark(s, l, a.create(t));
|
||
});
|
||
});
|
||
return (function (e, t, n) {
|
||
var r;
|
||
let { selection: i } = t,
|
||
o = null;
|
||
if ((P(i) && (o = i.$cursor), o)) {
|
||
let t = null != (r = e.storedMarks) ? r : o.marks();
|
||
return (
|
||
o.parent.type.allowsMarkType(n) &&
|
||
(!!n.isInSet(t) || !t.some((e) => e.type.excludes(n)))
|
||
);
|
||
}
|
||
let { ranges: s } = i;
|
||
return s.some(({ $from: t, $to: r }) => {
|
||
let i =
|
||
0 === t.depth &&
|
||
e.doc.inlineContent &&
|
||
e.doc.type.allowsMarkType(n);
|
||
return (
|
||
e.doc.nodesBetween(t.pos, r.pos, (e, t, r) => {
|
||
if (i) return !1;
|
||
if (e.isInline) {
|
||
let t = !r || r.type.allowsMarkType(n),
|
||
o =
|
||
!!n.isInSet(e.marks) ||
|
||
!e.marks.some((e) => e.type.excludes(n));
|
||
i = t && o;
|
||
}
|
||
return !i;
|
||
}),
|
||
i
|
||
);
|
||
});
|
||
})(r, n, a);
|
||
},
|
||
e2 =
|
||
(e, t) =>
|
||
({ tr: n }) => (n.setMeta(e, t), !0),
|
||
e3 =
|
||
(e, t = {}) =>
|
||
({ state: r, dispatch: i, chain: o }) => {
|
||
let s,
|
||
l = v(e, r.schema);
|
||
return (r.selection.$anchor.sameParent(r.selection.$head) &&
|
||
(s = r.selection.$anchor.parent.attrs),
|
||
l.isTextblock)
|
||
? o()
|
||
.command(
|
||
({ commands: e }) =>
|
||
!!(0, n.setBlockType)(l, { ...s, ...t })(r) ||
|
||
e.clearNodes(),
|
||
)
|
||
.command(({ state: e }) =>
|
||
(0, n.setBlockType)(l, { ...s, ...t })(e, i),
|
||
)
|
||
.run()
|
||
: (console.warn(
|
||
'[tiptap warn]: Currently "setNode()" only supports text block nodes.',
|
||
),
|
||
!1);
|
||
},
|
||
e4 =
|
||
(e) =>
|
||
({ tr: t, dispatch: n }) => {
|
||
if (n) {
|
||
let { doc: n } = t,
|
||
i = L(e, 0, n.content.size),
|
||
o = r.NodeSelection.create(n, i);
|
||
t.setSelection(o);
|
||
}
|
||
return !0;
|
||
},
|
||
e5 =
|
||
(e, t) =>
|
||
({ tr: n, state: r, dispatch: i }) => {
|
||
let o,
|
||
s,
|
||
{ selection: l } = r;
|
||
return (
|
||
"number" == typeof t
|
||
? ((o = t), (s = t))
|
||
: t && "from" in t && "to" in t
|
||
? ((o = t.from), (s = t.to))
|
||
: ((o = l.from), (s = l.to)),
|
||
i &&
|
||
n.doc.nodesBetween(o, s, (t, r) => {
|
||
t.isText || n.setNodeMarkup(r, void 0, { ...t.attrs, dir: e });
|
||
}),
|
||
!0
|
||
);
|
||
},
|
||
e6 =
|
||
(e) =>
|
||
({ tr: t, dispatch: n }) => {
|
||
if (n) {
|
||
let { doc: n } = t,
|
||
{ from: i, to: o } =
|
||
"number" == typeof e ? { from: e, to: e } : e,
|
||
s = r.TextSelection.atStart(n).from,
|
||
l = r.TextSelection.atEnd(n).to,
|
||
a = L(i, s, l),
|
||
d = L(o, s, l),
|
||
c = r.TextSelection.create(n, a, d);
|
||
t.setSelection(c);
|
||
}
|
||
return !0;
|
||
},
|
||
e9 =
|
||
(e) =>
|
||
({ state: t, dispatch: n }) => {
|
||
let r = v(e, t.schema);
|
||
return (0, o.sinkListItem)(r)(t, n);
|
||
};
|
||
function e7(e, t) {
|
||
let n =
|
||
e.storedMarks ||
|
||
(e.selection.$to.parentOffset && e.selection.$from.marks());
|
||
if (n) {
|
||
let r = n.filter((e) => (null == t ? void 0 : t.includes(e.type.name)));
|
||
e.tr.ensureMarks(r);
|
||
}
|
||
}
|
||
var e8 =
|
||
({ keepMarks: e = !0 } = {}) =>
|
||
({ tr: n, state: i, dispatch: o, editor: s }) => {
|
||
let { selection: l, doc: a } = n,
|
||
{ $from: d, $to: c } = l,
|
||
h = e_(
|
||
s.extensionManager.attributes,
|
||
d.node().type.name,
|
||
d.node().attrs,
|
||
);
|
||
if (l instanceof r.NodeSelection && l.node.isBlock)
|
||
return (
|
||
!!d.parentOffset &&
|
||
!!(0, t.canSplit)(a, d.pos) &&
|
||
(o &&
|
||
(e && e7(i, s.extensionManager.splittableMarks),
|
||
n.split(d.pos).scrollIntoView()),
|
||
!0)
|
||
);
|
||
if (!d.parent.isBlock) return !1;
|
||
let p = c.parentOffset === c.parent.content.size,
|
||
u =
|
||
0 === d.depth
|
||
? void 0
|
||
: (function (e) {
|
||
for (let t = 0; t < e.edgeCount; t += 1) {
|
||
let { type: n } = e.edge(t);
|
||
if (n.isTextblock && !n.hasRequiredAttrs()) return n;
|
||
}
|
||
return null;
|
||
})(d.node(-1).contentMatchAt(d.indexAfter(-1))),
|
||
f = p && u ? [{ type: u, attrs: h }] : void 0,
|
||
m = (0, t.canSplit)(n.doc, n.mapping.map(d.pos), 1, f);
|
||
if (
|
||
(!f &&
|
||
!m &&
|
||
(0, t.canSplit)(
|
||
n.doc,
|
||
n.mapping.map(d.pos),
|
||
1,
|
||
u ? [{ type: u }] : void 0,
|
||
) &&
|
||
((m = !0), (f = u ? [{ type: u, attrs: h }] : void 0)),
|
||
o)
|
||
) {
|
||
if (
|
||
m &&
|
||
(l instanceof r.TextSelection && n.deleteSelection(),
|
||
n.split(n.mapping.map(d.pos), 1, f),
|
||
u && !p && !d.parentOffset && d.parent.type !== u)
|
||
) {
|
||
let e = n.mapping.map(d.before()),
|
||
t = n.doc.resolve(e);
|
||
d.node(-1).canReplaceWith(t.index(), t.index() + 1, u) &&
|
||
n.setNodeMarkup(n.mapping.map(d.before()), u);
|
||
}
|
||
e && e7(i, s.extensionManager.splittableMarks), n.scrollIntoView();
|
||
}
|
||
return m;
|
||
},
|
||
te =
|
||
(e, n = {}) =>
|
||
({ tr: o, state: s, dispatch: l, editor: a }) => {
|
||
var d;
|
||
let c = v(e, s.schema),
|
||
{ $from: h, $to: p } = s.selection,
|
||
u = s.selection.node;
|
||
if ((u && u.isBlock) || h.depth < 2 || !h.sameParent(p)) return !1;
|
||
let f = h.node(-1);
|
||
if (f.type !== c) return !1;
|
||
let m = a.extensionManager.attributes;
|
||
if (
|
||
0 === h.parent.content.size &&
|
||
h.node(-1).childCount === h.indexAfter(-1)
|
||
) {
|
||
if (
|
||
2 === h.depth ||
|
||
h.node(-3).type !== c ||
|
||
h.index(-2) !== h.node(-2).childCount - 1
|
||
)
|
||
return !1;
|
||
if (l) {
|
||
let e = i.Fragment.empty,
|
||
t = h.index(-1) ? 1 : h.index(-2) ? 2 : 3;
|
||
for (let n = h.depth - t; n >= h.depth - 3; n -= 1)
|
||
e = i.Fragment.from(h.node(n).copy(e));
|
||
let s =
|
||
h.indexAfter(-1) < h.node(-2).childCount
|
||
? 1
|
||
: h.indexAfter(-2) < h.node(-3).childCount
|
||
? 2
|
||
: 3,
|
||
l = { ...e_(m, h.node().type.name, h.node().attrs), ...n },
|
||
a =
|
||
(null == (d = c.contentMatch.defaultType)
|
||
? void 0
|
||
: d.createAndFill(l)) || void 0;
|
||
e = e.append(i.Fragment.from(c.createAndFill(null, a) || void 0));
|
||
let p = h.before(h.depth - (t - 1));
|
||
o.replace(p, h.after(-s), new i.Slice(e, 4 - t, 0));
|
||
let u = -1;
|
||
o.doc.nodesBetween(p, o.doc.content.size, (e, t) => {
|
||
if (u > -1) return !1;
|
||
e.isTextblock && 0 === e.content.size && (u = t + 1);
|
||
}),
|
||
u > -1 &&
|
||
o.setSelection(r.TextSelection.near(o.doc.resolve(u))),
|
||
o.scrollIntoView();
|
||
}
|
||
return !0;
|
||
}
|
||
let g = p.pos === h.end() ? f.contentMatchAt(0).defaultType : null,
|
||
y = { ...e_(m, f.type.name, f.attrs), ...n },
|
||
b = { ...e_(m, h.node().type.name, h.node().attrs), ...n };
|
||
o.delete(h.pos, p.pos);
|
||
let k = g
|
||
? [
|
||
{ type: c, attrs: y },
|
||
{ type: g, attrs: b },
|
||
]
|
||
: [{ type: c, attrs: y }];
|
||
if (!(0, t.canSplit)(o.doc, h.pos, 2)) return !1;
|
||
if (l) {
|
||
let { selection: e, storedMarks: t } = s,
|
||
{ splittableMarks: n } = a.extensionManager,
|
||
r = t || (e.$to.parentOffset && e.$from.marks());
|
||
if ((o.split(h.pos, 2, k).scrollIntoView(), !r || !l)) return !0;
|
||
let i = r.filter((e) => n.includes(e.type.name));
|
||
o.ensureMarks(i);
|
||
}
|
||
return !0;
|
||
},
|
||
tt = (e, n) => {
|
||
let r = eS((e) => e.type === n)(e.selection);
|
||
if (!r) return !0;
|
||
let i = e.doc.resolve(Math.max(0, r.pos - 1)).before(r.depth);
|
||
if (void 0 === i) return !0;
|
||
let o = e.doc.nodeAt(i);
|
||
return (
|
||
!(
|
||
r.node.type === (null == o ? void 0 : o.type) &&
|
||
(0, t.canJoin)(e.doc, r.pos)
|
||
) || (e.join(r.pos), !0)
|
||
);
|
||
},
|
||
tn = (e, n) => {
|
||
let r = eS((e) => e.type === n)(e.selection);
|
||
if (!r) return !0;
|
||
let i = e.doc.resolve(r.start).after(r.depth);
|
||
if (void 0 === i) return !0;
|
||
let o = e.doc.nodeAt(i);
|
||
return (
|
||
!(
|
||
r.node.type === (null == o ? void 0 : o.type) &&
|
||
(0, t.canJoin)(e.doc, i)
|
||
) || (e.join(i), !0)
|
||
);
|
||
},
|
||
tr =
|
||
(e, t, n, r = {}) =>
|
||
({
|
||
editor: i,
|
||
tr: o,
|
||
state: s,
|
||
dispatch: l,
|
||
chain: a,
|
||
commands: d,
|
||
can: c,
|
||
}) => {
|
||
let { extensions: h, splittableMarks: p } = i.extensionManager,
|
||
u = v(e, s.schema),
|
||
f = v(t, s.schema),
|
||
{ selection: m, storedMarks: g } = s,
|
||
{ $from: y, $to: b } = m,
|
||
k = y.blockRange(b),
|
||
w = g || (m.$to.parentOffset && m.$from.marks());
|
||
if (!k) return !1;
|
||
let S = eS((e) => eG(e.type.name, h))(m);
|
||
if (k.depth >= 1 && S && k.depth - S.depth <= 1) {
|
||
if (S.node.type === u) return d.liftListItem(f);
|
||
if (eG(S.node.type.name, h) && u.validContent(S.node.content) && l)
|
||
return a()
|
||
.command(() => (o.setNodeMarkup(S.pos, u), !0))
|
||
.command(() => tt(o, u))
|
||
.command(() => tn(o, u))
|
||
.run();
|
||
}
|
||
return n && w && l
|
||
? a()
|
||
.command(() => {
|
||
let e = c().wrapInList(u, r),
|
||
t = w.filter((e) => p.includes(e.type.name));
|
||
return o.ensureMarks(t), !!e || d.clearNodes();
|
||
})
|
||
.wrapInList(u, r)
|
||
.command(() => tt(o, u))
|
||
.command(() => tn(o, u))
|
||
.run()
|
||
: a()
|
||
.command(() => !!c().wrapInList(u, r) || d.clearNodes())
|
||
.wrapInList(u, r)
|
||
.command(() => tt(o, u))
|
||
.command(() => tn(o, u))
|
||
.run();
|
||
},
|
||
ti =
|
||
(e, t = {}, n = {}) =>
|
||
({ state: r, commands: i }) => {
|
||
let { extendEmptyMarkRange: o = !1 } = n,
|
||
s = D(e, r.schema);
|
||
return eq(r, s, t)
|
||
? i.unsetMark(s, { extendEmptyMarkRange: o })
|
||
: i.setMark(s, t);
|
||
},
|
||
to =
|
||
(e, t, n = {}) =>
|
||
({ state: r, commands: i }) => {
|
||
let o,
|
||
s = v(e, r.schema),
|
||
l = v(t, r.schema),
|
||
a = en(r, s, n);
|
||
return (r.selection.$anchor.sameParent(r.selection.$head) &&
|
||
(o = r.selection.$anchor.parent.attrs),
|
||
a)
|
||
? i.setNode(l, o)
|
||
: i.setNode(s, { ...o, ...n });
|
||
},
|
||
ts =
|
||
(e, t = {}) =>
|
||
({ state: n, commands: r }) => {
|
||
let i = v(e, n.schema);
|
||
return en(n, i, t) ? r.lift(i) : r.wrapIn(i, t);
|
||
},
|
||
tl =
|
||
() =>
|
||
({ state: e, dispatch: t }) => {
|
||
let n = e.plugins;
|
||
for (let r = 0; r < n.length; r += 1) {
|
||
let i,
|
||
o = n[r];
|
||
if (o.spec.isInputRules && (i = o.getState(e))) {
|
||
if (t) {
|
||
let t = e.tr,
|
||
n = i.transform;
|
||
for (let e = n.steps.length - 1; e >= 0; e -= 1)
|
||
t.step(n.steps[e].invert(n.docs[e]));
|
||
if (i.text) {
|
||
let n = t.doc.resolve(i.from).marks();
|
||
t.replaceWith(i.from, i.to, e.schema.text(i.text, n));
|
||
} else t.delete(i.from, i.to);
|
||
}
|
||
return !0;
|
||
}
|
||
}
|
||
return !1;
|
||
},
|
||
ta =
|
||
() =>
|
||
({ tr: e, dispatch: t }) => {
|
||
let { selection: n } = e,
|
||
{ empty: r, ranges: i } = n;
|
||
return (
|
||
!!r ||
|
||
(t &&
|
||
i.forEach((t) => {
|
||
e.removeMark(t.$from.pos, t.$to.pos);
|
||
}),
|
||
!0)
|
||
);
|
||
},
|
||
td =
|
||
(e, t = {}) =>
|
||
({ tr: n, state: r, dispatch: i }) => {
|
||
var o;
|
||
let { extendEmptyMarkRange: s = !1 } = t,
|
||
{ selection: l } = n,
|
||
a = D(e, r.schema),
|
||
{ $from: d, empty: c, ranges: h } = l;
|
||
if (!i) return !0;
|
||
if (c && s) {
|
||
let { from: e, to: t } = l,
|
||
r =
|
||
null == (o = d.marks().find((e) => e.type === a))
|
||
? void 0
|
||
: o.attrs,
|
||
i = A(d, a, r);
|
||
i && ((e = i.from), (t = i.to)), n.removeMark(e, t, a);
|
||
} else
|
||
h.forEach((e) => {
|
||
n.removeMark(e.$from.pos, e.$to.pos, a);
|
||
});
|
||
return n.removeStoredMark(a), !0;
|
||
},
|
||
tc =
|
||
(e) =>
|
||
({ tr: t, state: n, dispatch: r }) => {
|
||
let i,
|
||
o,
|
||
{ selection: s } = n;
|
||
return (
|
||
"number" == typeof e
|
||
? ((i = e), (o = e))
|
||
: e && "from" in e && "to" in e
|
||
? ((i = e.from), (o = e.to))
|
||
: ((i = s.from), (o = s.to)),
|
||
r &&
|
||
t.doc.nodesBetween(i, o, (e, n) => {
|
||
if (e.isText) return;
|
||
let r = { ...e.attrs };
|
||
delete r.dir, t.setNodeMarkup(n, void 0, r);
|
||
}),
|
||
!0
|
||
);
|
||
},
|
||
th =
|
||
(e, t = {}) =>
|
||
({ tr: n, state: r, dispatch: i }) => {
|
||
let o = null,
|
||
s = null,
|
||
l = el("string" == typeof e ? e : e.name, r.schema);
|
||
if (!l) return !1;
|
||
"node" === l && (o = v(e, r.schema)),
|
||
"mark" === l && (s = D(e, r.schema));
|
||
let a = !1;
|
||
return (
|
||
n.selection.ranges.forEach((e) => {
|
||
let l,
|
||
d,
|
||
c,
|
||
h,
|
||
p = e.$from.pos,
|
||
u = e.$to.pos;
|
||
n.selection.empty
|
||
? r.doc.nodesBetween(p, u, (e, t) => {
|
||
o &&
|
||
o === e.type &&
|
||
((a = !0),
|
||
(c = Math.max(t, p)),
|
||
(h = Math.min(t + e.nodeSize, u)),
|
||
(l = t),
|
||
(d = e));
|
||
})
|
||
: r.doc.nodesBetween(p, u, (e, r) => {
|
||
r < p &&
|
||
o &&
|
||
o === e.type &&
|
||
((a = !0),
|
||
(c = Math.max(r, p)),
|
||
(h = Math.min(r + e.nodeSize, u)),
|
||
(l = r),
|
||
(d = e)),
|
||
r >= p &&
|
||
r <= u &&
|
||
(o &&
|
||
o === e.type &&
|
||
((a = !0),
|
||
i &&
|
||
n.setNodeMarkup(r, void 0, { ...e.attrs, ...t })),
|
||
s &&
|
||
e.marks.length &&
|
||
e.marks.forEach((o) => {
|
||
if (s === o.type && ((a = !0), i)) {
|
||
let i = Math.max(r, p),
|
||
l = Math.min(r + e.nodeSize, u);
|
||
n.addMark(i, l, s.create({ ...o.attrs, ...t }));
|
||
}
|
||
}));
|
||
}),
|
||
d &&
|
||
(void 0 !== l &&
|
||
i &&
|
||
n.setNodeMarkup(l, void 0, { ...d.attrs, ...t }),
|
||
s &&
|
||
d.marks.length &&
|
||
d.marks.forEach((e) => {
|
||
s === e.type &&
|
||
i &&
|
||
n.addMark(c, h, s.create({ ...e.attrs, ...t }));
|
||
}));
|
||
}),
|
||
a
|
||
);
|
||
},
|
||
tp =
|
||
(e, t = {}) =>
|
||
({ state: r, dispatch: i }) => {
|
||
let o = v(e, r.schema);
|
||
return (0, n.wrapIn)(o, t)(r, i);
|
||
},
|
||
tu =
|
||
(e, t = {}) =>
|
||
({ state: n, dispatch: r }) => {
|
||
let i = v(e, n.schema);
|
||
return (0, o.wrapInList)(i, t)(n, r);
|
||
},
|
||
tf = class {
|
||
constructor() {
|
||
this.callbacks = {};
|
||
}
|
||
on(e, t) {
|
||
return (
|
||
this.callbacks[e] || (this.callbacks[e] = []),
|
||
this.callbacks[e].push(t),
|
||
this
|
||
);
|
||
}
|
||
emit(e, ...t) {
|
||
let n = this.callbacks[e];
|
||
return n && n.forEach((e) => e.apply(this, t)), this;
|
||
}
|
||
off(e, t) {
|
||
let n = this.callbacks[e];
|
||
return (
|
||
n &&
|
||
(t
|
||
? (this.callbacks[e] = n.filter((e) => e !== t))
|
||
: delete this.callbacks[e]),
|
||
this
|
||
);
|
||
}
|
||
once(e, t) {
|
||
let n = (...r) => {
|
||
this.off(e, n), t.apply(this, r);
|
||
};
|
||
return this.on(e, n);
|
||
}
|
||
removeAllListeners() {
|
||
this.callbacks = {};
|
||
}
|
||
},
|
||
tm = class {
|
||
constructor(e) {
|
||
var t;
|
||
(this.find = e.find),
|
||
(this.handler = e.handler),
|
||
(this.undoable = null == (t = e.undoable) || t);
|
||
}
|
||
};
|
||
function tg(e) {
|
||
var t;
|
||
let { editor: n, from: r, to: i, text: o, rules: s, plugin: l } = e,
|
||
{ view: a } = n;
|
||
if (a.composing) return !1;
|
||
let d = a.state.doc.resolve(r);
|
||
if (
|
||
d.parent.type.spec.code ||
|
||
(null == (t = d.nodeBefore || d.nodeAfter)
|
||
? void 0
|
||
: t.marks.find((e) => e.type.spec.code))
|
||
)
|
||
return !1;
|
||
let p = !1,
|
||
u =
|
||
((e, t = 500) => {
|
||
let n = "",
|
||
r = e.parentOffset;
|
||
return (
|
||
e.parent.nodesBetween(Math.max(0, r - t), r, (e, t, i, o) => {
|
||
var s, l;
|
||
let a =
|
||
(null == (l = (s = e.type.spec).toText)
|
||
? void 0
|
||
: l.call(s, { node: e, pos: t, parent: i, index: o })) ||
|
||
e.textContent ||
|
||
"%leaf%";
|
||
n += e.isAtom && !e.isText ? a : a.slice(0, Math.max(0, r - t));
|
||
}),
|
||
n
|
||
);
|
||
})(d) + o;
|
||
return (
|
||
s.forEach((e) => {
|
||
if (p) return;
|
||
let t = ((e, t) => {
|
||
if (T(t)) return t.exec(e);
|
||
let n = t(e);
|
||
if (!n) return null;
|
||
let r = [n.text];
|
||
return (
|
||
(r.index = n.index),
|
||
(r.input = e),
|
||
(r.data = n.data),
|
||
n.replaceWith &&
|
||
(n.text.includes(n.replaceWith) ||
|
||
console.warn(
|
||
'[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".',
|
||
),
|
||
r.push(n.replaceWith)),
|
||
r
|
||
);
|
||
})(u, e.find);
|
||
if (!t) return;
|
||
let s = a.state.tr,
|
||
d = c({ state: a.state, transaction: s }),
|
||
f = { from: r - (t[0].length - o.length), to: i },
|
||
{ commands: m, chain: g, can: y } = new h({ editor: n, state: d });
|
||
null !==
|
||
e.handler({
|
||
state: d,
|
||
range: f,
|
||
match: t,
|
||
commands: m,
|
||
chain: g,
|
||
can: y,
|
||
}) &&
|
||
s.steps.length &&
|
||
(e.undoable &&
|
||
s.setMeta(l, { transform: s, from: r, to: i, text: o }),
|
||
a.dispatch(s),
|
||
(p = !0));
|
||
}),
|
||
p
|
||
);
|
||
}
|
||
function ty(e) {
|
||
return (
|
||
"Object" === Object.prototype.toString.call(e).slice(8, -1) &&
|
||
e.constructor === Object &&
|
||
Object.getPrototypeOf(e) === Object.prototype
|
||
);
|
||
}
|
||
var tb = class {
|
||
constructor(e = {}) {
|
||
(this.type = "extendable"),
|
||
(this.parent = null),
|
||
(this.child = null),
|
||
(this.name = ""),
|
||
(this.config = { name: this.name }),
|
||
(this.config = { ...this.config, ...e }),
|
||
(this.name = this.config.name);
|
||
}
|
||
get options() {
|
||
return { ...(eN(ex(this, "addOptions", { name: this.name })) || {}) };
|
||
}
|
||
get storage() {
|
||
return {
|
||
...(eN(
|
||
ex(this, "addStorage", {
|
||
name: this.name,
|
||
options: this.options,
|
||
}),
|
||
) || {}),
|
||
};
|
||
}
|
||
configure(e = {}) {
|
||
let t = this.extend({
|
||
...this.config,
|
||
addOptions: () =>
|
||
(function e(t, n) {
|
||
let r = { ...t };
|
||
return (
|
||
ty(t) &&
|
||
ty(n) &&
|
||
Object.keys(n).forEach((i) => {
|
||
ty(n[i]) && ty(t[i])
|
||
? (r[i] = e(t[i], n[i]))
|
||
: (r[i] = n[i]);
|
||
}),
|
||
r
|
||
);
|
||
})(this.options, e),
|
||
});
|
||
return (t.name = this.name), (t.parent = this.parent), t;
|
||
}
|
||
extend(e = {}) {
|
||
let t = new this.constructor({ ...this.config, ...e });
|
||
return (
|
||
(t.parent = this),
|
||
(this.child = t),
|
||
(t.name = "name" in e ? e.name : t.parent.name),
|
||
t
|
||
);
|
||
}
|
||
},
|
||
tk = class e extends tb {
|
||
constructor() {
|
||
super(...arguments), (this.type = "mark");
|
||
}
|
||
static create(t = {}) {
|
||
return new e("function" == typeof t ? t() : t);
|
||
}
|
||
static handleExit({ editor: e, mark: t }) {
|
||
let { tr: n } = e.state,
|
||
r = e.state.selection.$from;
|
||
if (r.pos === r.end()) {
|
||
let i = r.marks();
|
||
if (!i.find((e) => (null == e ? void 0 : e.type.name) === t.name))
|
||
return !1;
|
||
let o = i.find(
|
||
(e) => (null == e ? void 0 : e.type.name) === t.name,
|
||
);
|
||
return (
|
||
o && n.removeStoredMark(o),
|
||
n.insertText(" ", r.pos),
|
||
e.view.dispatch(n),
|
||
!0
|
||
);
|
||
}
|
||
return !1;
|
||
}
|
||
configure(e) {
|
||
return super.configure(e);
|
||
}
|
||
extend(e) {
|
||
let t = "function" == typeof e ? e() : e;
|
||
return super.extend(t);
|
||
}
|
||
},
|
||
tv = class {
|
||
constructor(e) {
|
||
(this.find = e.find), (this.handler = e.handler);
|
||
}
|
||
},
|
||
tw = null,
|
||
tS = class {
|
||
constructor(e, t) {
|
||
(this.splittableMarks = []),
|
||
(this.editor = t),
|
||
(this.baseExtensions = e),
|
||
(this.extensions = ez(e)),
|
||
(this.schema = (function (e, t) {
|
||
var n;
|
||
let r = eO(e),
|
||
{ nodeExtensions: o, markExtensions: s } = eE(e),
|
||
l =
|
||
null == (n = o.find((e) => ex(e, "topNode")))
|
||
? void 0
|
||
: n.name,
|
||
a = Object.fromEntries(
|
||
o.map((n) => {
|
||
let i = r.filter((e) => e.type === n.name),
|
||
o = {
|
||
name: n.name,
|
||
options: n.options,
|
||
storage: n.storage,
|
||
editor: t,
|
||
},
|
||
s = eI({
|
||
...e.reduce((e, t) => {
|
||
let r = ex(t, "extendNodeSchema", o);
|
||
return { ...e, ...(r ? r(n) : {}) };
|
||
}, {}),
|
||
content: eN(ex(n, "content", o)),
|
||
marks: eN(ex(n, "marks", o)),
|
||
group: eN(ex(n, "group", o)),
|
||
inline: eN(ex(n, "inline", o)),
|
||
atom: eN(ex(n, "atom", o)),
|
||
selectable: eN(ex(n, "selectable", o)),
|
||
draggable: eN(ex(n, "draggable", o)),
|
||
code: eN(ex(n, "code", o)),
|
||
whitespace: eN(ex(n, "whitespace", o)),
|
||
linebreakReplacement: eN(
|
||
ex(n, "linebreakReplacement", o),
|
||
),
|
||
defining: eN(ex(n, "defining", o)),
|
||
isolating: eN(ex(n, "isolating", o)),
|
||
attrs: Object.fromEntries(i.map(eP)),
|
||
}),
|
||
l = eN(ex(n, "parseHTML", o));
|
||
l && (s.parseDOM = l.map((e) => eR(e, i)));
|
||
let a = ex(n, "renderHTML", o);
|
||
a &&
|
||
(s.toDOM = (e) =>
|
||
a({ node: e, HTMLAttributes: eD(e, i) }));
|
||
let d = ex(n, "renderText", o);
|
||
return d && (s.toText = d), [n.name, s];
|
||
}),
|
||
),
|
||
d = Object.fromEntries(
|
||
s.map((n) => {
|
||
let i = r.filter((e) => e.type === n.name),
|
||
o = {
|
||
name: n.name,
|
||
options: n.options,
|
||
storage: n.storage,
|
||
editor: t,
|
||
},
|
||
s = eI({
|
||
...e.reduce((e, t) => {
|
||
let r = ex(t, "extendMarkSchema", o);
|
||
return { ...e, ...(r ? r(n) : {}) };
|
||
}, {}),
|
||
inclusive: eN(ex(n, "inclusive", o)),
|
||
excludes: eN(ex(n, "excludes", o)),
|
||
group: eN(ex(n, "group", o)),
|
||
spanning: eN(ex(n, "spanning", o)),
|
||
code: eN(ex(n, "code", o)),
|
||
attrs: Object.fromEntries(i.map(eP)),
|
||
}),
|
||
l = eN(ex(n, "parseHTML", o));
|
||
l && (s.parseDOM = l.map((e) => eR(e, i)));
|
||
let a = ex(n, "renderHTML", o);
|
||
return (
|
||
a &&
|
||
(s.toDOM = (e) =>
|
||
a({ mark: e, HTMLAttributes: eD(e, i) })),
|
||
[n.name, s]
|
||
);
|
||
}),
|
||
);
|
||
return new i.Schema({ topNode: l, nodes: a, marks: d });
|
||
})(this.extensions, t)),
|
||
this.setupExtensions();
|
||
}
|
||
get commands() {
|
||
return this.extensions.reduce((e, t) => {
|
||
let n = {
|
||
name: t.name,
|
||
options: t.options,
|
||
storage: this.editor.extensionStorage[t.name],
|
||
editor: this.editor,
|
||
type: eW(t.name, this.schema),
|
||
},
|
||
r = ex(t, "addCommands", n);
|
||
return r ? { ...e, ...r() } : e;
|
||
}, {});
|
||
}
|
||
get plugins() {
|
||
let { editor: e } = this;
|
||
return eL([...this.extensions].reverse()).flatMap((t) => {
|
||
let n = {
|
||
name: t.name,
|
||
options: t.options,
|
||
storage: this.editor.extensionStorage[t.name],
|
||
editor: e,
|
||
type: eW(t.name, this.schema),
|
||
},
|
||
o = [],
|
||
s = ex(t, "addKeyboardShortcuts", n),
|
||
a = {};
|
||
if (
|
||
("mark" === t.type &&
|
||
ex(t, "exitable", n) &&
|
||
(a.ArrowRight = () => tk.handleExit({ editor: e, mark: t })),
|
||
s)
|
||
) {
|
||
let t = Object.fromEntries(
|
||
Object.entries(s()).map(([t, n]) => [
|
||
t,
|
||
() => n({ editor: e }),
|
||
]),
|
||
);
|
||
a = { ...a, ...t };
|
||
}
|
||
let d = (0, l.keymap)(a);
|
||
o.push(d);
|
||
let p = ex(t, "addInputRules", n);
|
||
if (eJ(t, e.options.enableInputRules) && p) {
|
||
let t = p();
|
||
if (t && t.length) {
|
||
let n = (function (e) {
|
||
let { editor: t, rules: n } = e,
|
||
o = new r.Plugin({
|
||
state: {
|
||
init: () => null,
|
||
apply(e, r, s) {
|
||
let l = e.getMeta(o);
|
||
if (l) return l;
|
||
let a = e.getMeta("applyInputRules");
|
||
return (
|
||
a &&
|
||
setTimeout(() => {
|
||
let { text: e } = a;
|
||
"string" == typeof e ||
|
||
(e = eC(i.Fragment.from(e), s.schema));
|
||
let { from: r } = a,
|
||
l = r + e.length;
|
||
tg({
|
||
editor: t,
|
||
from: r,
|
||
to: l,
|
||
text: e,
|
||
rules: n,
|
||
plugin: o,
|
||
});
|
||
}),
|
||
e.selectionSet || e.docChanged ? null : r
|
||
);
|
||
},
|
||
},
|
||
props: {
|
||
handleTextInput: (e, r, i, s) =>
|
||
tg({
|
||
editor: t,
|
||
from: r,
|
||
to: i,
|
||
text: s,
|
||
rules: n,
|
||
plugin: o,
|
||
}),
|
||
handleDOMEvents: {
|
||
compositionend: (e) => (
|
||
setTimeout(() => {
|
||
let { $cursor: r } = e.state.selection;
|
||
r &&
|
||
tg({
|
||
editor: t,
|
||
from: r.pos,
|
||
to: r.pos,
|
||
text: "",
|
||
rules: n,
|
||
plugin: o,
|
||
});
|
||
}),
|
||
!1
|
||
),
|
||
},
|
||
handleKeyDown(e, r) {
|
||
if ("Enter" !== r.key) return !1;
|
||
let { $cursor: i } = e.state.selection;
|
||
return (
|
||
!!i &&
|
||
tg({
|
||
editor: t,
|
||
from: i.pos,
|
||
to: i.pos,
|
||
text: "\n",
|
||
rules: n,
|
||
plugin: o,
|
||
})
|
||
);
|
||
},
|
||
},
|
||
isInputRules: !0,
|
||
});
|
||
return o;
|
||
})({ editor: e, rules: t }),
|
||
s = Array.isArray(n) ? n : [n];
|
||
o.push(...s);
|
||
}
|
||
}
|
||
let u = ex(t, "addPasteRules", n);
|
||
if (eJ(t, e.options.enablePasteRules) && u) {
|
||
let t = u();
|
||
if (t && t.length) {
|
||
let n = (function (e) {
|
||
let t,
|
||
{ editor: n, rules: o } = e,
|
||
s = null,
|
||
l = !1,
|
||
a = !1,
|
||
d =
|
||
"u" > typeof ClipboardEvent
|
||
? new ClipboardEvent("paste")
|
||
: null;
|
||
try {
|
||
t = "u" > typeof DragEvent ? new DragEvent("drop") : null;
|
||
} catch {
|
||
t = null;
|
||
}
|
||
let p = ({
|
||
state: e,
|
||
from: r,
|
||
to: i,
|
||
rule: o,
|
||
pasteEvt: s,
|
||
}) => {
|
||
let l = e.tr;
|
||
if (
|
||
(function (e) {
|
||
let {
|
||
editor: t,
|
||
state: n,
|
||
from: r,
|
||
to: i,
|
||
rule: o,
|
||
pasteEvent: s,
|
||
dropEvent: l,
|
||
} = e,
|
||
{
|
||
commands: a,
|
||
chain: d,
|
||
can: c,
|
||
} = new h({ editor: t, state: n }),
|
||
p = [];
|
||
return (
|
||
n.doc.nodesBetween(r, i, (e, t) => {
|
||
var h, u, f, m, g;
|
||
if (
|
||
(null ==
|
||
(u = null == (h = e.type) ? void 0 : h.spec)
|
||
? void 0
|
||
: u.code) ||
|
||
!(e.isText || e.isTextblock || e.isInline)
|
||
)
|
||
return;
|
||
let y =
|
||
null !=
|
||
(g =
|
||
null !=
|
||
(m =
|
||
null == (f = e.content) ? void 0 : f.size)
|
||
? m
|
||
: e.nodeSize)
|
||
? g
|
||
: 0,
|
||
b = Math.max(r, t),
|
||
k = Math.min(i, t + y);
|
||
b >= k ||
|
||
((e, t, n) => {
|
||
if (T(t)) return [...e.matchAll(t)];
|
||
let r = t(e, n);
|
||
return r
|
||
? r.map((t) => {
|
||
let n = [t.text];
|
||
return (
|
||
(n.index = t.index),
|
||
(n.input = e),
|
||
(n.data = t.data),
|
||
t.replaceWith &&
|
||
(t.text.includes(t.replaceWith) ||
|
||
console.warn(
|
||
'[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".',
|
||
),
|
||
n.push(t.replaceWith)),
|
||
n
|
||
);
|
||
})
|
||
: [];
|
||
})(
|
||
e.isText
|
||
? e.text || ""
|
||
: e.textBetween(b - t, k - t, void 0, ""),
|
||
o.find,
|
||
s,
|
||
).forEach((e) => {
|
||
if (void 0 === e.index) return;
|
||
let t = b + e.index + 1,
|
||
r = t + e[0].length,
|
||
i = {
|
||
from: n.tr.mapping.map(t),
|
||
to: n.tr.mapping.map(r),
|
||
},
|
||
h = o.handler({
|
||
state: n,
|
||
range: i,
|
||
match: e,
|
||
commands: a,
|
||
chain: d,
|
||
can: c,
|
||
pasteEvent: s,
|
||
dropEvent: l,
|
||
});
|
||
p.push(h);
|
||
});
|
||
}),
|
||
p.every((e) => null !== e)
|
||
);
|
||
})({
|
||
editor: n,
|
||
state: c({ state: e, transaction: l }),
|
||
from: Math.max(r - 1, 0),
|
||
to: i.b - 1,
|
||
rule: o,
|
||
pasteEvent: s,
|
||
dropEvent: t,
|
||
}) &&
|
||
l.steps.length
|
||
) {
|
||
try {
|
||
t =
|
||
"u" > typeof DragEvent ? new DragEvent("drop") : null;
|
||
} catch {
|
||
t = null;
|
||
}
|
||
return (
|
||
(d =
|
||
"u" > typeof ClipboardEvent
|
||
? new ClipboardEvent("paste")
|
||
: null),
|
||
l
|
||
);
|
||
}
|
||
};
|
||
return o.map(
|
||
(e) =>
|
||
new r.Plugin({
|
||
view(e) {
|
||
let t = (t) => {
|
||
var r;
|
||
(s = (
|
||
null == (r = e.dom.parentElement)
|
||
? void 0
|
||
: r.contains(t.target)
|
||
)
|
||
? e.dom.parentElement
|
||
: null) && (tw = n);
|
||
},
|
||
r = () => {
|
||
tw && (tw = null);
|
||
};
|
||
return (
|
||
window.addEventListener("dragstart", t),
|
||
window.addEventListener("dragend", r),
|
||
{
|
||
destroy() {
|
||
window.removeEventListener("dragstart", t),
|
||
window.removeEventListener("dragend", r);
|
||
},
|
||
}
|
||
);
|
||
},
|
||
props: {
|
||
handleDOMEvents: {
|
||
drop: (e, n) => {
|
||
if (
|
||
((a = s === e.dom.parentElement), (t = n), !a)
|
||
) {
|
||
let e = tw;
|
||
(null == e ? void 0 : e.isEditable) &&
|
||
setTimeout(() => {
|
||
let t = e.state.selection;
|
||
t &&
|
||
e.commands.deleteRange({
|
||
from: t.from,
|
||
to: t.to,
|
||
});
|
||
}, 10);
|
||
}
|
||
return !1;
|
||
},
|
||
paste: (e, t) => {
|
||
var n;
|
||
let r =
|
||
null == (n = t.clipboardData)
|
||
? void 0
|
||
: n.getData("text/html");
|
||
return (
|
||
(d = t),
|
||
(l = !!(null == r
|
||
? void 0
|
||
: r.includes("data-pm-slice"))),
|
||
!1
|
||
);
|
||
},
|
||
},
|
||
},
|
||
appendTransaction: (t, n, r) => {
|
||
let o = t[0],
|
||
s = "paste" === o.getMeta("uiEvent") && !l,
|
||
c = "drop" === o.getMeta("uiEvent") && !a,
|
||
h = o.getMeta("applyPasteRules"),
|
||
u = !!h;
|
||
if (!s && !c && !u) return;
|
||
if (u) {
|
||
var f, m;
|
||
let t,
|
||
{ text: n } = h;
|
||
"string" == typeof n ||
|
||
(n = eC(i.Fragment.from(n), r.schema));
|
||
let { from: o } = h,
|
||
s = o + n.length;
|
||
return p({
|
||
rule: e,
|
||
state: r,
|
||
from: o,
|
||
to: { b: s },
|
||
pasteEvt:
|
||
((f = n),
|
||
null ==
|
||
(m = (t = new ClipboardEvent("paste", {
|
||
clipboardData: new DataTransfer(),
|
||
})).clipboardData) ||
|
||
m.setData("text/html", f),
|
||
t),
|
||
});
|
||
}
|
||
let g = n.doc.content.findDiffStart(r.doc.content),
|
||
y = n.doc.content.findDiffEnd(r.doc.content);
|
||
if ("number" == typeof g && y && g !== y.b)
|
||
return p({
|
||
rule: e,
|
||
state: r,
|
||
from: g,
|
||
to: y,
|
||
pasteEvt: d,
|
||
});
|
||
},
|
||
}),
|
||
);
|
||
})({ editor: e, rules: t });
|
||
o.push(...n);
|
||
}
|
||
}
|
||
let f = ex(t, "addProseMirrorPlugins", n);
|
||
if (f) {
|
||
let e = f();
|
||
o.push(...e);
|
||
}
|
||
return o;
|
||
});
|
||
}
|
||
get attributes() {
|
||
return eO(this.extensions);
|
||
}
|
||
get nodeViews() {
|
||
let { editor: e } = this,
|
||
{ nodeExtensions: t } = eE(this.extensions);
|
||
return Object.fromEntries(
|
||
t
|
||
.filter((e) => !!ex(e, "addNodeView"))
|
||
.map((t) => {
|
||
let n = this.attributes.filter((e) => e.type === t.name),
|
||
r = {
|
||
name: t.name,
|
||
options: t.options,
|
||
storage: this.editor.extensionStorage[t.name],
|
||
editor: e,
|
||
type: v(t.name, this.schema),
|
||
},
|
||
i = ex(t, "addNodeView", r);
|
||
if (!i) return [];
|
||
let o = i();
|
||
return o
|
||
? [
|
||
t.name,
|
||
(r, i, s, l, a) => {
|
||
let d = eD(r, n);
|
||
return o({
|
||
node: r,
|
||
view: i,
|
||
getPos: s,
|
||
decorations: l,
|
||
innerDecorations: a,
|
||
editor: e,
|
||
extension: t,
|
||
HTMLAttributes: d,
|
||
});
|
||
},
|
||
]
|
||
: [];
|
||
}),
|
||
);
|
||
}
|
||
dispatchTransaction(e) {
|
||
let { editor: t } = this;
|
||
return eL([...this.extensions].reverse()).reduceRight((e, n) => {
|
||
let r = {
|
||
name: n.name,
|
||
options: n.options,
|
||
storage: this.editor.extensionStorage[n.name],
|
||
editor: t,
|
||
type: eW(n.name, this.schema),
|
||
},
|
||
i = ex(n, "dispatchTransaction", r);
|
||
return i
|
||
? (t) => {
|
||
i.call(r, { transaction: t, next: e });
|
||
}
|
||
: e;
|
||
}, e);
|
||
}
|
||
transformPastedHTML(e) {
|
||
let { editor: t } = this;
|
||
return eL([...this.extensions]).reduce(
|
||
(e, n) => {
|
||
let r = {
|
||
name: n.name,
|
||
options: n.options,
|
||
storage: this.editor.extensionStorage[n.name],
|
||
editor: t,
|
||
type: eW(n.name, this.schema),
|
||
},
|
||
i = ex(n, "transformPastedHTML", r);
|
||
return i
|
||
? (t, n) => {
|
||
let o = e(t, n);
|
||
return i.call(r, o);
|
||
}
|
||
: e;
|
||
},
|
||
e || ((e) => e),
|
||
);
|
||
}
|
||
get markViews() {
|
||
let { editor: e } = this,
|
||
{ markExtensions: t } = eE(this.extensions);
|
||
return Object.fromEntries(
|
||
t
|
||
.filter((e) => !!ex(e, "addMarkView"))
|
||
.map((t) => {
|
||
let n = this.attributes.filter((e) => e.type === t.name),
|
||
r = {
|
||
name: t.name,
|
||
options: t.options,
|
||
storage: this.editor.extensionStorage[t.name],
|
||
editor: e,
|
||
type: D(t.name, this.schema),
|
||
},
|
||
i = ex(t, "addMarkView", r);
|
||
return i
|
||
? [
|
||
t.name,
|
||
(r, o, s) => {
|
||
let l = eD(r, n);
|
||
return i()({
|
||
mark: r,
|
||
view: o,
|
||
inline: s,
|
||
editor: e,
|
||
extension: t,
|
||
HTMLAttributes: l,
|
||
updateAttributes: (t) => {
|
||
t0(r, e, t);
|
||
},
|
||
});
|
||
},
|
||
]
|
||
: [];
|
||
}),
|
||
);
|
||
}
|
||
setupExtensions() {
|
||
let e = this.extensions;
|
||
(this.editor.extensionStorage = Object.fromEntries(
|
||
e.map((e) => [e.name, e.storage]),
|
||
)),
|
||
e.forEach((e) => {
|
||
var t;
|
||
let n = {
|
||
name: e.name,
|
||
options: e.options,
|
||
storage: this.editor.extensionStorage[e.name],
|
||
editor: this.editor,
|
||
type: eW(e.name, this.schema),
|
||
};
|
||
"mark" === e.type &&
|
||
(null == (t = eN(ex(e, "keepOnSplit", n))) || t) &&
|
||
this.splittableMarks.push(e.name);
|
||
let r = ex(e, "onBeforeCreate", n),
|
||
i = ex(e, "onCreate", n),
|
||
o = ex(e, "onUpdate", n),
|
||
s = ex(e, "onSelectionUpdate", n),
|
||
l = ex(e, "onTransaction", n),
|
||
a = ex(e, "onFocus", n),
|
||
d = ex(e, "onBlur", n),
|
||
c = ex(e, "onDestroy", n);
|
||
r && this.editor.on("beforeCreate", r),
|
||
i && this.editor.on("create", i),
|
||
o && this.editor.on("update", o),
|
||
s && this.editor.on("selectionUpdate", s),
|
||
l && this.editor.on("transaction", l),
|
||
a && this.editor.on("focus", a),
|
||
d && this.editor.on("blur", d),
|
||
c && this.editor.on("destroy", c);
|
||
});
|
||
}
|
||
};
|
||
(tS.resolve = ez), (tS.sort = eL), (tS.flatten = eM);
|
||
var tx = {};
|
||
d(tx, {
|
||
ClipboardTextSerializer: () => tC,
|
||
Commands: () => tT,
|
||
Delete: () => tN,
|
||
Drop: () => tE,
|
||
Editable: () => tO,
|
||
FocusEvents: () => tD,
|
||
Keymap: () => tR,
|
||
Paste: () => tI,
|
||
Tabindex: () => tP,
|
||
TextDirection: () => tL,
|
||
focusEventsPluginKey: () => tA,
|
||
});
|
||
var tM = class e extends tb {
|
||
constructor() {
|
||
super(...arguments), (this.type = "extension");
|
||
}
|
||
static create(t = {}) {
|
||
return new e("function" == typeof t ? t() : t);
|
||
}
|
||
configure(e) {
|
||
return super.configure(e);
|
||
}
|
||
extend(e) {
|
||
let t = "function" == typeof e ? e() : e;
|
||
return super.extend(t);
|
||
}
|
||
},
|
||
tC = tM.create({
|
||
name: "clipboardTextSerializer",
|
||
addOptions: () => ({ blockSeparator: void 0 }),
|
||
addProseMirrorPlugins() {
|
||
return [
|
||
new r.Plugin({
|
||
key: new r.PluginKey("clipboardTextSerializer"),
|
||
props: {
|
||
clipboardTextSerializer: () => {
|
||
let { editor: e } = this,
|
||
{ state: t, schema: n } = e,
|
||
{ doc: r, selection: i } = t,
|
||
{ ranges: o } = i,
|
||
s = Math.min(...o.map((e) => e.$from.pos)),
|
||
l = Math.max(...o.map((e) => e.$to.pos)),
|
||
a = e$(n);
|
||
return eB(
|
||
r,
|
||
{ from: s, to: l },
|
||
{
|
||
...(void 0 !== this.options.blockSeparator
|
||
? { blockSeparator: this.options.blockSeparator }
|
||
: {}),
|
||
textSerializers: a,
|
||
},
|
||
);
|
||
},
|
||
},
|
||
}),
|
||
];
|
||
},
|
||
}),
|
||
tT = tM.create({ name: "commands", addCommands: () => ({ ...p }) }),
|
||
tN = tM.create({
|
||
name: "delete",
|
||
onUpdate({ transaction: e, appendedTransactions: n }) {
|
||
var r, i, o;
|
||
let s = () => {
|
||
var r, i, o, s;
|
||
if (
|
||
null !=
|
||
(s =
|
||
null ==
|
||
(o =
|
||
null ==
|
||
(i =
|
||
null == (r = this.editor.options.coreExtensionOptions)
|
||
? void 0
|
||
: r.delete)
|
||
? void 0
|
||
: i.filterTransaction)
|
||
? void 0
|
||
: o.call(i, e))
|
||
? s
|
||
: e.getMeta("y-sync$")
|
||
)
|
||
return;
|
||
let l = ev(e.before, [e, ...n]);
|
||
eF(l).forEach((t) => {
|
||
l.mapping.mapResult(t.oldRange.from).deletedAfter &&
|
||
l.mapping.mapResult(t.oldRange.to).deletedBefore &&
|
||
l.before.nodesBetween(
|
||
t.oldRange.from,
|
||
t.oldRange.to,
|
||
(n, r) => {
|
||
let i = r + n.nodeSize - 2,
|
||
o = t.oldRange.from <= r && i <= t.oldRange.to;
|
||
this.editor.emit("delete", {
|
||
type: "node",
|
||
node: n,
|
||
from: r,
|
||
to: i,
|
||
newFrom: l.mapping.map(r),
|
||
newTo: l.mapping.map(i),
|
||
deletedRange: t.oldRange,
|
||
newRange: t.newRange,
|
||
partial: !o,
|
||
editor: this.editor,
|
||
transaction: e,
|
||
combinedTransform: l,
|
||
});
|
||
},
|
||
);
|
||
});
|
||
let a = l.mapping;
|
||
l.steps.forEach((n, r) => {
|
||
var i, o;
|
||
if (n instanceof t.RemoveMarkStep) {
|
||
let t = a.slice(r).map(n.from, -1),
|
||
s = a.slice(r).map(n.to),
|
||
d = a.invert().map(t, -1),
|
||
c = a.invert().map(s),
|
||
h =
|
||
null == (i = l.doc.nodeAt(t - 1))
|
||
? void 0
|
||
: i.marks.some((e) => e.eq(n.mark)),
|
||
p =
|
||
null == (o = l.doc.nodeAt(s))
|
||
? void 0
|
||
: o.marks.some((e) => e.eq(n.mark));
|
||
this.editor.emit("delete", {
|
||
type: "mark",
|
||
mark: n.mark,
|
||
from: n.from,
|
||
to: n.to,
|
||
deletedRange: { from: d, to: c },
|
||
newRange: { from: t, to: s },
|
||
partial: !!(p || h),
|
||
editor: this.editor,
|
||
transaction: e,
|
||
combinedTransform: l,
|
||
});
|
||
}
|
||
});
|
||
};
|
||
null ==
|
||
(o =
|
||
null ==
|
||
(i =
|
||
null == (r = this.editor.options.coreExtensionOptions)
|
||
? void 0
|
||
: r.delete)
|
||
? void 0
|
||
: i.async) || o
|
||
? setTimeout(s, 0)
|
||
: s();
|
||
},
|
||
}),
|
||
tE = tM.create({
|
||
name: "drop",
|
||
addProseMirrorPlugins() {
|
||
return [
|
||
new r.Plugin({
|
||
key: new r.PluginKey("tiptapDrop"),
|
||
props: {
|
||
handleDrop: (e, t, n, r) => {
|
||
this.editor.emit("drop", {
|
||
editor: this.editor,
|
||
event: t,
|
||
slice: n,
|
||
moved: r,
|
||
});
|
||
},
|
||
},
|
||
}),
|
||
];
|
||
},
|
||
}),
|
||
tO = tM.create({
|
||
name: "editable",
|
||
addProseMirrorPlugins() {
|
||
return [
|
||
new r.Plugin({
|
||
key: new r.PluginKey("editable"),
|
||
props: { editable: () => this.editor.options.editable },
|
||
}),
|
||
];
|
||
},
|
||
}),
|
||
tA = new r.PluginKey("focusEvents"),
|
||
tD = tM.create({
|
||
name: "focusEvents",
|
||
addProseMirrorPlugins() {
|
||
let { editor: e } = this;
|
||
return [
|
||
new r.Plugin({
|
||
key: tA,
|
||
props: {
|
||
handleDOMEvents: {
|
||
focus: (t, n) => {
|
||
e.isFocused = !0;
|
||
let r = e.state.tr
|
||
.setMeta("focus", { event: n })
|
||
.setMeta("addToHistory", !1);
|
||
return t.dispatch(r), !1;
|
||
},
|
||
blur: (t, n) => {
|
||
e.isFocused = !1;
|
||
let r = e.state.tr
|
||
.setMeta("blur", { event: n })
|
||
.setMeta("addToHistory", !1);
|
||
return t.dispatch(r), !1;
|
||
},
|
||
},
|
||
},
|
||
}),
|
||
];
|
||
},
|
||
}),
|
||
tR = tM.create({
|
||
name: "keymap",
|
||
addKeyboardShortcuts() {
|
||
let e = () =>
|
||
this.editor.commands.first(({ commands: e }) => [
|
||
() => e.undoInputRule(),
|
||
() =>
|
||
e.command(({ tr: t }) => {
|
||
let { selection: n, doc: i } = t,
|
||
{ empty: o, $anchor: s } = n,
|
||
{ pos: l, parent: a } = s,
|
||
d =
|
||
s.parent.isTextblock && l > 0
|
||
? t.doc.resolve(l - 1)
|
||
: s,
|
||
c = d.parent.type.spec.isolating,
|
||
h = s.pos - s.parentOffset,
|
||
p =
|
||
c && 1 === d.parent.childCount
|
||
? h === s.pos
|
||
: r.Selection.atStart(i).from === l;
|
||
return (
|
||
!!o &&
|
||
!!a.type.isTextblock &&
|
||
!a.textContent.length &&
|
||
!!p &&
|
||
(!p || "paragraph" !== s.parent.type.name) &&
|
||
e.clearNodes()
|
||
);
|
||
}),
|
||
() => e.deleteSelection(),
|
||
() => e.joinBackward(),
|
||
() => e.selectNodeBackward(),
|
||
]),
|
||
t = () =>
|
||
this.editor.commands.first(({ commands: e }) => [
|
||
() => e.deleteSelection(),
|
||
() => e.deleteCurrentNode(),
|
||
() => e.joinForward(),
|
||
() => e.selectNodeForward(),
|
||
]),
|
||
n = {
|
||
Enter: () =>
|
||
this.editor.commands.first(({ commands: e }) => [
|
||
() => e.newlineInCode(),
|
||
() => e.createParagraphNear(),
|
||
() => e.liftEmptyBlock(),
|
||
() => e.splitBlock(),
|
||
]),
|
||
"Mod-Enter": () => this.editor.commands.exitCode(),
|
||
Backspace: e,
|
||
"Mod-Backspace": e,
|
||
"Shift-Backspace": e,
|
||
Delete: t,
|
||
"Mod-Delete": t,
|
||
"Mod-a": () => this.editor.commands.selectAll(),
|
||
},
|
||
i = { ...n },
|
||
o = {
|
||
...n,
|
||
"Ctrl-h": e,
|
||
"Alt-Backspace": e,
|
||
"Ctrl-d": t,
|
||
"Ctrl-Alt-Backspace": t,
|
||
"Alt-Delete": t,
|
||
"Alt-d": t,
|
||
"Ctrl-a": () => this.editor.commands.selectTextblockStart(),
|
||
"Ctrl-e": () => this.editor.commands.selectTextblockEnd(),
|
||
};
|
||
return $() || ee() ? o : i;
|
||
},
|
||
addProseMirrorPlugins() {
|
||
return [
|
||
new r.Plugin({
|
||
key: new r.PluginKey("clearDocument"),
|
||
appendTransaction: (e, t, n) => {
|
||
if (e.some((e) => e.getMeta("composition"))) return;
|
||
let i = e.some((e) => e.docChanged) && !t.doc.eq(n.doc),
|
||
o = e.some((e) => e.getMeta("preventClearDocument"));
|
||
if (!i || o) return;
|
||
let { empty: s, from: l, to: a } = t.selection,
|
||
d = r.Selection.atStart(t.doc).from,
|
||
p = r.Selection.atEnd(t.doc).to;
|
||
if (s || l !== d || a !== p || !eY(n.doc)) return;
|
||
let u = n.tr,
|
||
f = c({ state: n, transaction: u }),
|
||
{ commands: m } = new h({ editor: this.editor, state: f });
|
||
if ((m.clearNodes(), u.steps.length)) return u;
|
||
},
|
||
}),
|
||
];
|
||
},
|
||
}),
|
||
tI = tM.create({
|
||
name: "paste",
|
||
addProseMirrorPlugins() {
|
||
return [
|
||
new r.Plugin({
|
||
key: new r.PluginKey("tiptapPaste"),
|
||
props: {
|
||
handlePaste: (e, t, n) => {
|
||
this.editor.emit("paste", {
|
||
editor: this.editor,
|
||
event: t,
|
||
slice: n,
|
||
});
|
||
},
|
||
},
|
||
}),
|
||
];
|
||
},
|
||
}),
|
||
tP = tM.create({
|
||
name: "tabindex",
|
||
addProseMirrorPlugins() {
|
||
return [
|
||
new r.Plugin({
|
||
key: new r.PluginKey("tabindex"),
|
||
props: {
|
||
attributes: () =>
|
||
this.editor.isEditable ? { tabindex: "0" } : {},
|
||
},
|
||
}),
|
||
];
|
||
},
|
||
}),
|
||
tL = tM.create({
|
||
name: "textDirection",
|
||
addOptions: () => ({ direction: void 0 }),
|
||
addGlobalAttributes() {
|
||
if (!this.options.direction) return [];
|
||
let { nodeExtensions: e } = eE(this.extensions);
|
||
return [
|
||
{
|
||
types: e.filter((e) => "text" !== e.name).map((e) => e.name),
|
||
attributes: {
|
||
dir: {
|
||
default: this.options.direction,
|
||
parseHTML: (e) => {
|
||
let t = e.getAttribute("dir");
|
||
return t && ("ltr" === t || "rtl" === t || "auto" === t)
|
||
? t
|
||
: this.options.direction;
|
||
},
|
||
renderHTML: (e) => (e.dir ? { dir: e.dir } : {}),
|
||
},
|
||
},
|
||
},
|
||
];
|
||
},
|
||
addProseMirrorPlugins() {
|
||
return [
|
||
new r.Plugin({
|
||
key: new r.PluginKey("textDirection"),
|
||
props: {
|
||
attributes: () => {
|
||
let e = this.options.direction;
|
||
return e ? { dir: e } : {};
|
||
},
|
||
},
|
||
}),
|
||
];
|
||
},
|
||
}),
|
||
tz = class e {
|
||
constructor(e, t, n = !1, r = null) {
|
||
(this.currentNode = null),
|
||
(this.actualDepth = null),
|
||
(this.isBlock = n),
|
||
(this.resolvedPos = e),
|
||
(this.editor = t),
|
||
(this.currentNode = r);
|
||
}
|
||
get name() {
|
||
return this.node.type.name;
|
||
}
|
||
get node() {
|
||
return this.currentNode || this.resolvedPos.node();
|
||
}
|
||
get element() {
|
||
return this.editor.view.domAtPos(this.pos).node;
|
||
}
|
||
get depth() {
|
||
var e;
|
||
return null != (e = this.actualDepth) ? e : this.resolvedPos.depth;
|
||
}
|
||
get pos() {
|
||
return this.resolvedPos.pos;
|
||
}
|
||
get content() {
|
||
return this.node.content;
|
||
}
|
||
set content(e) {
|
||
let t = this.from,
|
||
n = this.to;
|
||
if (this.isBlock) {
|
||
if (0 === this.content.size)
|
||
return void console.error(
|
||
`You can\u2019t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`,
|
||
);
|
||
(t = this.from + 1), (n = this.to - 1);
|
||
}
|
||
this.editor.commands.insertContentAt({ from: t, to: n }, e);
|
||
}
|
||
get attributes() {
|
||
return this.node.attrs;
|
||
}
|
||
get textContent() {
|
||
return this.node.textContent;
|
||
}
|
||
get size() {
|
||
return this.node.nodeSize;
|
||
}
|
||
get from() {
|
||
return this.isBlock
|
||
? this.pos
|
||
: this.resolvedPos.start(this.resolvedPos.depth);
|
||
}
|
||
get range() {
|
||
return { from: this.from, to: this.to };
|
||
}
|
||
get to() {
|
||
return this.isBlock
|
||
? this.pos + this.size
|
||
: this.resolvedPos.end(this.resolvedPos.depth) + +!this.node.isText;
|
||
}
|
||
get parent() {
|
||
if (0 === this.depth) return null;
|
||
let t = this.resolvedPos.start(this.resolvedPos.depth - 1);
|
||
return new e(this.resolvedPos.doc.resolve(t), this.editor);
|
||
}
|
||
get before() {
|
||
let t = this.resolvedPos.doc.resolve(
|
||
this.from - (this.isBlock ? 1 : 2),
|
||
);
|
||
return (
|
||
t.depth !== this.depth &&
|
||
(t = this.resolvedPos.doc.resolve(this.from - 3)),
|
||
new e(t, this.editor)
|
||
);
|
||
}
|
||
get after() {
|
||
let t = this.resolvedPos.doc.resolve(
|
||
this.to + (this.isBlock ? 2 : 1),
|
||
);
|
||
return (
|
||
t.depth !== this.depth &&
|
||
(t = this.resolvedPos.doc.resolve(this.to + 3)),
|
||
new e(t, this.editor)
|
||
);
|
||
}
|
||
get children() {
|
||
let t = [];
|
||
return (
|
||
this.node.content.forEach((n, r) => {
|
||
let i = n.isBlock && !n.isTextblock,
|
||
o = n.isAtom && !n.isText,
|
||
s = n.isInline,
|
||
l = this.pos + r + +!o;
|
||
if (l < 0 || l > this.resolvedPos.doc.nodeSize - 2) return;
|
||
let a = this.resolvedPos.doc.resolve(l);
|
||
if (!i && !s && a.depth <= this.depth) return;
|
||
let d = new e(a, this.editor, i, i || s ? n : null);
|
||
i && (d.actualDepth = this.depth + 1), t.push(d);
|
||
}),
|
||
t
|
||
);
|
||
}
|
||
get firstChild() {
|
||
return this.children[0] || null;
|
||
}
|
||
get lastChild() {
|
||
let e = this.children;
|
||
return e[e.length - 1] || null;
|
||
}
|
||
closest(e, t = {}) {
|
||
let n = null,
|
||
r = this.parent;
|
||
for (; r && !n; ) {
|
||
if (r.node.type.name === e)
|
||
if (Object.keys(t).length > 0) {
|
||
let e = r.node.attrs,
|
||
n = Object.keys(t);
|
||
for (let r = 0; r < n.length; r += 1) {
|
||
let i = n[r];
|
||
if (e[i] !== t[i]) break;
|
||
}
|
||
} else n = r;
|
||
r = r.parent;
|
||
}
|
||
return n;
|
||
}
|
||
querySelector(e, t = {}) {
|
||
return this.querySelectorAll(e, t, !0)[0] || null;
|
||
}
|
||
querySelectorAll(e, t = {}, n = !1) {
|
||
let r = [];
|
||
if (!this.children || 0 === this.children.length) return r;
|
||
let i = Object.keys(t);
|
||
return (
|
||
this.children.forEach((o) => {
|
||
(n && r.length > 0) ||
|
||
(o.node.type.name === e &&
|
||
i.every((e) => t[e] === o.node.attrs[e]) &&
|
||
r.push(o),
|
||
(n && r.length > 0) ||
|
||
(r = r.concat(o.querySelectorAll(e, t, n))));
|
||
}),
|
||
r
|
||
);
|
||
}
|
||
setAttribute(e) {
|
||
let { tr: t } = this.editor.state;
|
||
t.setNodeMarkup(this.from, void 0, { ...this.node.attrs, ...e }),
|
||
this.editor.view.dispatch(t);
|
||
}
|
||
},
|
||
tB = `.ProseMirror {
|
||
position: relative;
|
||
}
|
||
|
||
.ProseMirror {
|
||
word-wrap: break-word;
|
||
white-space: pre-wrap;
|
||
white-space: break-spaces;
|
||
-webkit-font-variant-ligatures: none;
|
||
font-variant-ligatures: none;
|
||
font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */
|
||
}
|
||
|
||
.ProseMirror [contenteditable="false"] {
|
||
white-space: normal;
|
||
}
|
||
|
||
.ProseMirror [contenteditable="false"] [contenteditable="true"] {
|
||
white-space: pre-wrap;
|
||
}
|
||
|
||
.ProseMirror pre {
|
||
white-space: pre-wrap;
|
||
}
|
||
|
||
img.ProseMirror-separator {
|
||
display: inline !important;
|
||
border: none !important;
|
||
margin: 0 !important;
|
||
width: 0 !important;
|
||
height: 0 !important;
|
||
}
|
||
|
||
.ProseMirror-gapcursor {
|
||
display: none;
|
||
pointer-events: none;
|
||
position: absolute;
|
||
margin: 0;
|
||
}
|
||
|
||
.ProseMirror-gapcursor:after {
|
||
content: "";
|
||
display: block;
|
||
position: absolute;
|
||
top: -2px;
|
||
width: 20px;
|
||
border-top: 1px solid black;
|
||
animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
|
||
}
|
||
|
||
@keyframes ProseMirror-cursor-blink {
|
||
to {
|
||
visibility: hidden;
|
||
}
|
||
}
|
||
|
||
.ProseMirror-hideselection *::selection {
|
||
background: transparent;
|
||
}
|
||
|
||
.ProseMirror-hideselection *::-moz-selection {
|
||
background: transparent;
|
||
}
|
||
|
||
.ProseMirror-hideselection * {
|
||
caret-color: transparent;
|
||
}
|
||
|
||
.ProseMirror-focused .ProseMirror-gapcursor {
|
||
display: block;
|
||
}`,
|
||
t$ = class extends tf {
|
||
constructor(e = {}) {
|
||
super(),
|
||
(this.css = null),
|
||
(this.className = "tiptap"),
|
||
(this.editorView = null),
|
||
(this.isFocused = !1),
|
||
(this.isInitialized = !1),
|
||
(this.extensionStorage = {}),
|
||
(this.instanceId = Math.random().toString(36).slice(2, 9)),
|
||
(this.options = {
|
||
element:
|
||
"u" > typeof document ? document.createElement("div") : null,
|
||
content: "",
|
||
injectCSS: !0,
|
||
injectNonce: void 0,
|
||
extensions: [],
|
||
autofocus: !1,
|
||
editable: !0,
|
||
textDirection: void 0,
|
||
editorProps: {},
|
||
parseOptions: {},
|
||
coreExtensionOptions: {},
|
||
enableInputRules: !0,
|
||
enablePasteRules: !0,
|
||
enableCoreExtensions: !0,
|
||
enableContentCheck: !1,
|
||
emitContentError: !1,
|
||
onBeforeCreate: () => null,
|
||
onCreate: () => null,
|
||
onMount: () => null,
|
||
onUnmount: () => null,
|
||
onUpdate: () => null,
|
||
onSelectionUpdate: () => null,
|
||
onTransaction: () => null,
|
||
onFocus: () => null,
|
||
onBlur: () => null,
|
||
onDestroy: () => null,
|
||
onContentError: ({ error: e }) => {
|
||
throw e;
|
||
},
|
||
onPaste: () => null,
|
||
onDrop: () => null,
|
||
onDelete: () => null,
|
||
enableExtensionDispatchTransaction: !0,
|
||
}),
|
||
(this.isCapturingTransaction = !1),
|
||
(this.capturedTransaction = null),
|
||
(this.utils = {
|
||
getUpdatedPosition: eZ,
|
||
createMappablePosition: e0,
|
||
}),
|
||
this.setOptions(e),
|
||
this.createExtensionManager(),
|
||
this.createCommandManager(),
|
||
this.createSchema(),
|
||
this.on("beforeCreate", this.options.onBeforeCreate),
|
||
this.emit("beforeCreate", { editor: this }),
|
||
this.on("mount", this.options.onMount),
|
||
this.on("unmount", this.options.onUnmount),
|
||
this.on("contentError", this.options.onContentError),
|
||
this.on("create", this.options.onCreate),
|
||
this.on("update", this.options.onUpdate),
|
||
this.on("selectionUpdate", this.options.onSelectionUpdate),
|
||
this.on("transaction", this.options.onTransaction),
|
||
this.on("focus", this.options.onFocus),
|
||
this.on("blur", this.options.onBlur),
|
||
this.on("destroy", this.options.onDestroy),
|
||
this.on("drop", ({ event: e, slice: t, moved: n }) =>
|
||
this.options.onDrop(e, t, n),
|
||
),
|
||
this.on("paste", ({ event: e, slice: t }) =>
|
||
this.options.onPaste(e, t),
|
||
),
|
||
this.on("delete", this.options.onDelete);
|
||
const t = this.createDoc(),
|
||
n = z(t, this.options.autofocus);
|
||
(this.editorState = r.EditorState.create({
|
||
doc: t,
|
||
schema: this.schema,
|
||
selection: n || void 0,
|
||
})),
|
||
this.options.element && this.mount(this.options.element);
|
||
}
|
||
mount(e) {
|
||
if ("u" < typeof document)
|
||
throw Error(
|
||
"[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.",
|
||
);
|
||
this.createView(e),
|
||
this.emit("mount", { editor: this }),
|
||
this.css &&
|
||
!document.head.contains(this.css) &&
|
||
document.head.appendChild(this.css),
|
||
window.setTimeout(() => {
|
||
this.isDestroyed ||
|
||
(!1 !== this.options.autofocus &&
|
||
null !== this.options.autofocus &&
|
||
this.commands.focus(this.options.autofocus),
|
||
this.emit("create", { editor: this }),
|
||
(this.isInitialized = !0));
|
||
}, 0);
|
||
}
|
||
unmount() {
|
||
if (this.editorView) {
|
||
let e = this.editorView.dom;
|
||
(null == e ? void 0 : e.editor) && delete e.editor,
|
||
this.editorView.destroy();
|
||
}
|
||
if (
|
||
((this.editorView = null),
|
||
(this.isInitialized = !1),
|
||
this.css && !document.querySelectorAll(`.${this.className}`).length)
|
||
)
|
||
try {
|
||
"function" == typeof this.css.remove
|
||
? this.css.remove()
|
||
: this.css.parentNode &&
|
||
this.css.parentNode.removeChild(this.css);
|
||
} catch (e) {
|
||
console.warn("Failed to remove CSS element:", e);
|
||
}
|
||
(this.css = null), this.emit("unmount", { editor: this });
|
||
}
|
||
get storage() {
|
||
return this.extensionStorage;
|
||
}
|
||
get commands() {
|
||
return this.commandManager.commands;
|
||
}
|
||
chain() {
|
||
return this.commandManager.chain();
|
||
}
|
||
can() {
|
||
return this.commandManager.can();
|
||
}
|
||
injectCSS() {
|
||
this.options.injectCSS &&
|
||
"u" > typeof document &&
|
||
(this.css = (function (e, t, n) {
|
||
let r = document.querySelector("style[data-tiptap-style]");
|
||
if (null !== r) return r;
|
||
let i = document.createElement("style");
|
||
return (
|
||
t && i.setAttribute("nonce", t),
|
||
i.setAttribute("data-tiptap-style", ""),
|
||
(i.innerHTML = e),
|
||
document.getElementsByTagName("head")[0].appendChild(i),
|
||
i
|
||
);
|
||
})(tB, this.options.injectNonce));
|
||
}
|
||
setOptions(e = {}) {
|
||
(this.options = { ...this.options, ...e }),
|
||
this.editorView &&
|
||
this.state &&
|
||
!this.isDestroyed &&
|
||
(this.options.editorProps &&
|
||
this.view.setProps(this.options.editorProps),
|
||
this.view.updateState(this.state));
|
||
}
|
||
setEditable(e, t = !0) {
|
||
this.setOptions({ editable: e }),
|
||
t &&
|
||
this.emit("update", {
|
||
editor: this,
|
||
transaction: this.state.tr,
|
||
appendedTransactions: [],
|
||
});
|
||
}
|
||
get isEditable() {
|
||
return this.options.editable && this.view && this.view.editable;
|
||
}
|
||
get view() {
|
||
return this.editorView
|
||
? this.editorView
|
||
: new Proxy(
|
||
{
|
||
state: this.editorState,
|
||
updateState: (e) => {
|
||
this.editorState = e;
|
||
},
|
||
dispatch: (e) => {
|
||
this.dispatchTransaction(e);
|
||
},
|
||
composing: !1,
|
||
dragging: null,
|
||
editable: !0,
|
||
isDestroyed: !1,
|
||
},
|
||
{
|
||
get: (e, t) => {
|
||
if (this.editorView) return this.editorView[t];
|
||
if ("state" === t) return this.editorState;
|
||
if (t in e) return Reflect.get(e, t);
|
||
throw Error(
|
||
`[tiptap error]: The editor view is not available. Cannot access view['${t}']. The editor may not be mounted yet.`,
|
||
);
|
||
},
|
||
},
|
||
);
|
||
}
|
||
get state() {
|
||
return (
|
||
this.editorView && (this.editorState = this.view.state),
|
||
this.editorState
|
||
);
|
||
}
|
||
registerPlugin(e, t) {
|
||
let n = eT(t)
|
||
? t(e, [...this.state.plugins])
|
||
: [...this.state.plugins, e],
|
||
r = this.state.reconfigure({ plugins: n });
|
||
return this.view.updateState(r), r;
|
||
}
|
||
unregisterPlugin(e) {
|
||
if (this.isDestroyed) return;
|
||
let t = this.state.plugins,
|
||
n = t;
|
||
if (
|
||
([].concat(e).forEach((e) => {
|
||
let t = "string" == typeof e ? `${e}$` : e.key;
|
||
n = n.filter((e) => !e.key.startsWith(t));
|
||
}),
|
||
t.length === n.length)
|
||
)
|
||
return;
|
||
let r = this.state.reconfigure({ plugins: n });
|
||
return this.view.updateState(r), r;
|
||
}
|
||
createExtensionManager() {
|
||
var e, t;
|
||
let n = [
|
||
...(this.options.enableCoreExtensions
|
||
? [
|
||
tO,
|
||
tC.configure({
|
||
blockSeparator:
|
||
null ==
|
||
(t =
|
||
null == (e = this.options.coreExtensionOptions)
|
||
? void 0
|
||
: e.clipboardTextSerializer)
|
||
? void 0
|
||
: t.blockSeparator,
|
||
}),
|
||
tT,
|
||
tD,
|
||
tR,
|
||
tP,
|
||
tE,
|
||
tI,
|
||
tN,
|
||
tL.configure({ direction: this.options.textDirection }),
|
||
].filter(
|
||
(e) =>
|
||
"object" != typeof this.options.enableCoreExtensions ||
|
||
!1 !== this.options.enableCoreExtensions[e.name],
|
||
)
|
||
: []),
|
||
...this.options.extensions,
|
||
].filter((e) =>
|
||
["extension", "node", "mark"].includes(null == e ? void 0 : e.type),
|
||
);
|
||
this.extensionManager = new tS(n, this);
|
||
}
|
||
createCommandManager() {
|
||
this.commandManager = new h({ editor: this });
|
||
}
|
||
createSchema() {
|
||
this.schema = this.extensionManager.schema;
|
||
}
|
||
createDoc() {
|
||
let e;
|
||
try {
|
||
e = ey(
|
||
this.options.content,
|
||
this.schema,
|
||
this.options.parseOptions,
|
||
{ errorOnInvalidContent: this.options.enableContentCheck },
|
||
);
|
||
} catch (t) {
|
||
if (
|
||
!(t instanceof Error) ||
|
||
![
|
||
"[tiptap error]: Invalid JSON content",
|
||
"[tiptap error]: Invalid HTML content",
|
||
].includes(t.message)
|
||
)
|
||
throw t;
|
||
this.emit("contentError", {
|
||
editor: this,
|
||
error: t,
|
||
disableCollaboration: () => {
|
||
"collaboration" in this.storage &&
|
||
"object" == typeof this.storage.collaboration &&
|
||
this.storage.collaboration &&
|
||
(this.storage.collaboration.isDisabled = !0),
|
||
(this.options.extensions = this.options.extensions.filter(
|
||
(e) => "collaboration" !== e.name,
|
||
)),
|
||
this.createExtensionManager();
|
||
},
|
||
}),
|
||
(e = ey(
|
||
this.options.content,
|
||
this.schema,
|
||
this.options.parseOptions,
|
||
{ errorOnInvalidContent: !1 },
|
||
));
|
||
}
|
||
return e;
|
||
}
|
||
createView(e) {
|
||
let { editorProps: t, enableExtensionDispatchTransaction: n } =
|
||
this.options,
|
||
r = t.dispatchTransaction || this.dispatchTransaction.bind(this),
|
||
i = n ? this.extensionManager.dispatchTransaction(r) : r,
|
||
o = t.transformPastedHTML,
|
||
l = this.extensionManager.transformPastedHTML(o);
|
||
this.editorView = new s.EditorView(e, {
|
||
...t,
|
||
attributes: {
|
||
role: "textbox",
|
||
...(null == t ? void 0 : t.attributes),
|
||
},
|
||
dispatchTransaction: i,
|
||
transformPastedHTML: l,
|
||
state: this.editorState,
|
||
markViews: this.extensionManager.markViews,
|
||
nodeViews: this.extensionManager.nodeViews,
|
||
});
|
||
let a = this.state.reconfigure({
|
||
plugins: this.extensionManager.plugins,
|
||
});
|
||
this.view.updateState(a),
|
||
this.prependClass(),
|
||
this.injectCSS(),
|
||
(this.view.dom.editor = this);
|
||
}
|
||
createNodeViews() {
|
||
this.view.isDestroyed ||
|
||
this.view.setProps({
|
||
markViews: this.extensionManager.markViews,
|
||
nodeViews: this.extensionManager.nodeViews,
|
||
});
|
||
}
|
||
prependClass() {
|
||
this.view.dom.className = `${this.className} ${this.view.dom.className}`;
|
||
}
|
||
captureTransaction(e) {
|
||
(this.isCapturingTransaction = !0),
|
||
e(),
|
||
(this.isCapturingTransaction = !1);
|
||
let t = this.capturedTransaction;
|
||
return (this.capturedTransaction = null), t;
|
||
}
|
||
dispatchTransaction(e) {
|
||
if (this.view.isDestroyed) return;
|
||
if (this.isCapturingTransaction) {
|
||
if (!this.capturedTransaction) {
|
||
this.capturedTransaction = e;
|
||
return;
|
||
}
|
||
e.steps.forEach((e) => {
|
||
var t;
|
||
return null == (t = this.capturedTransaction)
|
||
? void 0
|
||
: t.step(e);
|
||
});
|
||
return;
|
||
}
|
||
let { state: t, transactions: n } = this.state.applyTransaction(e),
|
||
r = !this.state.selection.eq(t.selection),
|
||
i = n.includes(e),
|
||
o = this.state;
|
||
if (
|
||
(this.emit("beforeTransaction", {
|
||
editor: this,
|
||
transaction: e,
|
||
nextState: t,
|
||
}),
|
||
!i)
|
||
)
|
||
return;
|
||
this.view.updateState(t),
|
||
this.emit("transaction", {
|
||
editor: this,
|
||
transaction: e,
|
||
appendedTransactions: n.slice(1),
|
||
}),
|
||
r && this.emit("selectionUpdate", { editor: this, transaction: e });
|
||
let s = n.findLast((e) => e.getMeta("focus") || e.getMeta("blur")),
|
||
l = null == s ? void 0 : s.getMeta("focus"),
|
||
a = null == s ? void 0 : s.getMeta("blur");
|
||
l &&
|
||
this.emit("focus", {
|
||
editor: this,
|
||
event: l.event,
|
||
transaction: s,
|
||
}),
|
||
a &&
|
||
this.emit("blur", {
|
||
editor: this,
|
||
event: a.event,
|
||
transaction: s,
|
||
}),
|
||
e.getMeta("preventUpdate") ||
|
||
!n.some((e) => e.docChanged) ||
|
||
o.doc.eq(t.doc) ||
|
||
this.emit("update", {
|
||
editor: this,
|
||
transaction: e,
|
||
appendedTransactions: n.slice(1),
|
||
});
|
||
}
|
||
getAttributes(e) {
|
||
return ej(this.state, e);
|
||
}
|
||
isActive(e, t) {
|
||
let n = "string" == typeof e ? e : null,
|
||
r = "string" == typeof e ? t : e;
|
||
return (function (e, t, n = {}) {
|
||
if (!t) return en(e, null, n) || eq(e, null, n);
|
||
let r = el(t, e.schema);
|
||
return "node" === r ? en(e, t, n) : "mark" === r && eq(e, t, n);
|
||
})(this.state, n, r);
|
||
}
|
||
getJSON() {
|
||
return this.state.doc.toJSON();
|
||
}
|
||
getHTML() {
|
||
return eC(this.state.doc.content, this.schema);
|
||
}
|
||
getText(e) {
|
||
var t, n;
|
||
let r,
|
||
{ blockSeparator: i = "\n\n", textSerializers: o = {} } = e || {};
|
||
return (
|
||
(t = this.state.doc),
|
||
(n = {
|
||
blockSeparator: i,
|
||
textSerializers: { ...e$(this.schema), ...o },
|
||
}),
|
||
(r = { from: 0, to: t.content.size }),
|
||
eB(t, r, n)
|
||
);
|
||
}
|
||
get isEmpty() {
|
||
return eY(this.state.doc);
|
||
}
|
||
destroy() {
|
||
this.emit("destroy"), this.unmount(), this.removeAllListeners();
|
||
}
|
||
get isDestroyed() {
|
||
var e, t;
|
||
return (
|
||
null ==
|
||
(t = null == (e = this.editorView) ? void 0 : e.isDestroyed) || t
|
||
);
|
||
}
|
||
$node(e, t) {
|
||
var n;
|
||
return (
|
||
(null == (n = this.$doc) ? void 0 : n.querySelector(e, t)) || null
|
||
);
|
||
}
|
||
$nodes(e, t) {
|
||
var n;
|
||
return (
|
||
(null == (n = this.$doc) ? void 0 : n.querySelectorAll(e, t)) ||
|
||
null
|
||
);
|
||
}
|
||
$pos(e) {
|
||
return new tz(this.state.doc.resolve(e), this);
|
||
}
|
||
get $doc() {
|
||
return this.$pos(0);
|
||
}
|
||
};
|
||
function tj(e) {
|
||
return new tm({
|
||
find: e.find,
|
||
handler: ({ state: t, range: n, match: r }) => {
|
||
let i = eN(e.getAttributes, void 0, r);
|
||
if (!1 === i || null === i) return null;
|
||
let { tr: o } = t,
|
||
s = r[r.length - 1],
|
||
l = r[0];
|
||
if (s) {
|
||
let r = l.search(/\S/),
|
||
a = n.from + l.indexOf(s),
|
||
d = a + s.length;
|
||
if (
|
||
eV(n.from, n.to, t.doc)
|
||
.filter((t) =>
|
||
t.mark.type.excluded.find(
|
||
(n) => n === e.type && n !== t.mark.type,
|
||
),
|
||
)
|
||
.filter((e) => e.to > a).length
|
||
)
|
||
return null;
|
||
d < n.to && o.delete(d, n.to),
|
||
a > n.from && o.delete(n.from + r, a);
|
||
let c = n.from + r + s.length;
|
||
o.addMark(n.from + r, c, e.type.create(i || {})),
|
||
o.removeStoredMark(e.type);
|
||
}
|
||
},
|
||
undoable: e.undoable,
|
||
});
|
||
}
|
||
function tF(e) {
|
||
return new tm({
|
||
find: e.find,
|
||
handler: ({ state: t, range: n, match: r }) => {
|
||
let i = eN(e.getAttributes, void 0, r) || {},
|
||
{ tr: o } = t,
|
||
s = n.from,
|
||
l = n.to,
|
||
a = e.type.create(i);
|
||
if (r[1]) {
|
||
let e = s + r[0].lastIndexOf(r[1]);
|
||
e > l ? (e = l) : (l = e + r[1].length);
|
||
let t = r[0][r[0].length - 1];
|
||
o.insertText(t, s + r[0].length - 1), o.replaceWith(e, l, a);
|
||
} else if (r[0]) {
|
||
let t = e.type.isInline ? s : s - 1;
|
||
o.insert(t, e.type.create(i)).delete(
|
||
o.mapping.map(s),
|
||
o.mapping.map(l),
|
||
);
|
||
}
|
||
o.scrollIntoView();
|
||
},
|
||
undoable: e.undoable,
|
||
});
|
||
}
|
||
function tV(e) {
|
||
return new tm({
|
||
find: e.find,
|
||
handler: ({ state: t, range: n, match: r }) => {
|
||
let i = t.doc.resolve(n.from),
|
||
o = eN(e.getAttributes, void 0, r) || {};
|
||
if (!i.node(-1).canReplaceWith(i.index(-1), i.indexAfter(-1), e.type))
|
||
return null;
|
||
t.tr.delete(n.from, n.to).setBlockType(n.from, n.from, e.type, o);
|
||
},
|
||
undoable: e.undoable,
|
||
});
|
||
}
|
||
function tH(e) {
|
||
return new tm({
|
||
find: e.find,
|
||
handler: ({ state: n, range: r, match: i, chain: o }) => {
|
||
let s = eN(e.getAttributes, void 0, i) || {},
|
||
l = n.tr.delete(r.from, r.to),
|
||
a = l.doc.resolve(r.from).blockRange(),
|
||
d = a && (0, t.findWrapping)(a, e.type, s);
|
||
if (!d) return null;
|
||
if ((l.wrap(a, d), e.keepMarks && e.editor)) {
|
||
let { selection: t, storedMarks: r } = n,
|
||
{ splittableMarks: i } = e.editor.extensionManager,
|
||
o = r || (t.$to.parentOffset && t.$from.marks());
|
||
if (o) {
|
||
let e = o.filter((e) => i.includes(e.type.name));
|
||
l.ensureMarks(e);
|
||
}
|
||
}
|
||
if (e.keepAttributes) {
|
||
let t =
|
||
"bulletList" === e.type.name || "orderedList" === e.type.name
|
||
? "listItem"
|
||
: "taskList";
|
||
o().updateAttributes(t, s).run();
|
||
}
|
||
let c = l.doc.resolve(r.from - 1).nodeBefore;
|
||
c &&
|
||
c.type === e.type &&
|
||
(0, t.canJoin)(l.doc, r.from - 1) &&
|
||
(!e.joinPredicate || e.joinPredicate(i, c)) &&
|
||
l.join(r.from - 1);
|
||
},
|
||
undoable: e.undoable,
|
||
});
|
||
}
|
||
function tW(e, t) {
|
||
let { selection: n } = e,
|
||
{ $from: i } = n;
|
||
if (n instanceof r.NodeSelection) {
|
||
let e = i.index();
|
||
return i.parent.canReplaceWith(e, e + 1, t);
|
||
}
|
||
let o = i.depth;
|
||
for (; o >= 0; ) {
|
||
let e = i.index(o);
|
||
if (i.node(o).contentMatchAt(e).matchType(t)) return !0;
|
||
o -= 1;
|
||
}
|
||
return !1;
|
||
}
|
||
function t_(e) {
|
||
return e.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
||
}
|
||
function tq(e) {
|
||
if (!(null == e ? void 0 : e.trim())) return {};
|
||
let t = {},
|
||
n = [],
|
||
r = e.replace(
|
||
/["']([^"']*)["']/g,
|
||
(e) => (n.push(e), `__QUOTED_${n.length - 1}__`),
|
||
),
|
||
i = r.match(/(?:^|\s)\.([a-zA-Z][\w-]*)/g);
|
||
i && (t.class = i.map((e) => e.trim().slice(1)).join(" "));
|
||
let o = r.match(/(?:^|\s)#([a-zA-Z][\w-]*)/);
|
||
o && (t.id = o[1]),
|
||
Array.from(
|
||
r.matchAll(/([a-zA-Z][\w-]*)\s*=\s*(__QUOTED_\d+__)/g),
|
||
).forEach(([, e, r]) => {
|
||
var i;
|
||
let o =
|
||
n[
|
||
parseInt(
|
||
(null == (i = r.match(/__QUOTED_(\d+)__/)) ? void 0 : i[1]) ||
|
||
"0",
|
||
10,
|
||
)
|
||
];
|
||
o && (t[e] = o.slice(1, -1));
|
||
});
|
||
let s = r
|
||
.replace(/(?:^|\s)\.([a-zA-Z][\w-]*)/g, "")
|
||
.replace(/(?:^|\s)#([a-zA-Z][\w-]*)/g, "")
|
||
.replace(/([a-zA-Z][\w-]*)\s*=\s*__QUOTED_\d+__/g, "")
|
||
.trim();
|
||
return (
|
||
s &&
|
||
s
|
||
.split(/\s+/)
|
||
.filter(Boolean)
|
||
.forEach((e) => {
|
||
e.match(/^[a-zA-Z][\w-]*$/) && (t[e] = !0);
|
||
}),
|
||
t
|
||
);
|
||
}
|
||
function tK(e) {
|
||
if (!e || 0 === Object.keys(e).length) return "";
|
||
let t = [];
|
||
return (
|
||
e.class &&
|
||
String(e.class)
|
||
.split(/\s+/)
|
||
.filter(Boolean)
|
||
.forEach((e) => t.push(`.${e}`)),
|
||
e.id && t.push(`#${e.id}`),
|
||
Object.entries(e).forEach(([e, n]) => {
|
||
"class" !== e &&
|
||
"id" !== e &&
|
||
(!0 === n
|
||
? t.push(e)
|
||
: !1 !== n && null != n && t.push(`${e}="${String(n)}"`));
|
||
}),
|
||
t.join(" ")
|
||
);
|
||
}
|
||
function tU(e) {
|
||
let {
|
||
nodeName: t,
|
||
name: n,
|
||
parseAttributes: r = tq,
|
||
serializeAttributes: i = tK,
|
||
defaultAttributes: o = {},
|
||
requiredAttributes: s = [],
|
||
allowedAttributes: l,
|
||
} = e,
|
||
a = n || t;
|
||
return {
|
||
parseMarkdown: (e, n) => {
|
||
let r = { ...o, ...e.attributes };
|
||
return n.createNode(t, r, []);
|
||
},
|
||
markdownTokenizer: {
|
||
name: t,
|
||
level: "block",
|
||
start(e) {
|
||
var t;
|
||
let n = RegExp(`^:::${a}(?:\\s|$)`, "m"),
|
||
r = null == (t = e.match(n)) ? void 0 : t.index;
|
||
return void 0 !== r ? r : -1;
|
||
},
|
||
tokenize(e, n, i) {
|
||
let o = RegExp(`^:::${a}(?:\\s+\\{([^}]*)\\})?\\s*:::(?:\\n|$)`),
|
||
l = e.match(o);
|
||
if (!l) return;
|
||
let d = r(l[1] || "");
|
||
if (!s.find((e) => !(e in d)))
|
||
return { type: t, raw: l[0], attributes: d };
|
||
},
|
||
},
|
||
renderMarkdown: (e) => {
|
||
let t = i(
|
||
((e) => {
|
||
if (!l) return e;
|
||
let t = {};
|
||
return (
|
||
l.forEach((n) => {
|
||
n in e && (t[n] = e[n]);
|
||
}),
|
||
t
|
||
);
|
||
})(e.attrs || {}),
|
||
),
|
||
n = t ? ` {${t}}` : "";
|
||
return `:::${a}${n} :::`;
|
||
},
|
||
};
|
||
}
|
||
function tJ(e) {
|
||
let {
|
||
nodeName: t,
|
||
name: n,
|
||
getContent: r,
|
||
parseAttributes: i = tq,
|
||
serializeAttributes: o = tK,
|
||
defaultAttributes: s = {},
|
||
content: l = "block",
|
||
allowedAttributes: a,
|
||
} = e,
|
||
d = n || t;
|
||
return {
|
||
parseMarkdown: (e, n) => {
|
||
let i;
|
||
if (r) {
|
||
let t = r(e);
|
||
i = "string" == typeof t ? [{ type: "text", text: t }] : t;
|
||
} else
|
||
i =
|
||
"block" === l
|
||
? n.parseChildren(e.tokens || [])
|
||
: n.parseInline(e.tokens || []);
|
||
let o = { ...s, ...e.attributes };
|
||
return n.createNode(t, o, i);
|
||
},
|
||
markdownTokenizer: {
|
||
name: t,
|
||
level: "block",
|
||
start(e) {
|
||
var t;
|
||
let n = RegExp(`^:::${d}`, "m"),
|
||
r = null == (t = e.match(n)) ? void 0 : t.index;
|
||
return void 0 !== r ? r : -1;
|
||
},
|
||
tokenize(e, n, r) {
|
||
var o;
|
||
let s = RegExp(`^:::${d}(?:\\s+\\{([^}]*)\\})?\\s*\\n`),
|
||
a = e.match(s);
|
||
if (!a) return;
|
||
let [c, h = ""] = a,
|
||
p = i(h),
|
||
u = 1,
|
||
f = c.length,
|
||
m = "",
|
||
g = /^:::([\w-]*)(\s.*)?/gm,
|
||
y = e.slice(f);
|
||
for (g.lastIndex = 0; ; ) {
|
||
let n = g.exec(y);
|
||
if (null === n) break;
|
||
let i = n.index,
|
||
s = n[1];
|
||
if (null == (o = n[2]) || !o.endsWith(":::")) {
|
||
if (s) u += 1;
|
||
else if (0 == (u -= 1)) {
|
||
let o = y.slice(0, i);
|
||
m = o.trim();
|
||
let s = e.slice(0, f + i + n[0].length),
|
||
a = [];
|
||
if (m)
|
||
if ("block" === l)
|
||
for (
|
||
(a = r.blockTokens(o)).forEach((e) => {
|
||
e.text &&
|
||
(!e.tokens || 0 === e.tokens.length) &&
|
||
(e.tokens = r.inlineTokens(e.text));
|
||
});
|
||
a.length > 0;
|
||
|
||
) {
|
||
let e = a[a.length - 1];
|
||
if (
|
||
"paragraph" !== e.type ||
|
||
(e.text && "" !== e.text.trim())
|
||
)
|
||
break;
|
||
a.pop();
|
||
}
|
||
else a = r.inlineTokens(m);
|
||
return {
|
||
type: t,
|
||
raw: s,
|
||
attributes: p,
|
||
content: m,
|
||
tokens: a,
|
||
};
|
||
}
|
||
}
|
||
}
|
||
},
|
||
},
|
||
renderMarkdown: (e, t) => {
|
||
let n = o(
|
||
((e) => {
|
||
if (!a) return e;
|
||
let t = {};
|
||
return (
|
||
a.forEach((n) => {
|
||
n in e && (t[n] = e[n]);
|
||
}),
|
||
t
|
||
);
|
||
})(e.attrs || {}),
|
||
),
|
||
r = n ? ` {${n}}` : "",
|
||
i = t.renderChildren(e.content || [], "\n\n");
|
||
return `:::${d}${r}
|
||
|
||
${i}
|
||
|
||
:::`;
|
||
},
|
||
};
|
||
}
|
||
function tG(e) {
|
||
if (!e.trim()) return {};
|
||
let t = {},
|
||
n = /(\w+)=(?:"([^"]*)"|'([^']*)')/g,
|
||
r = n.exec(e);
|
||
for (; null !== r; ) {
|
||
let [, i, o, s] = r;
|
||
(t[i] = o || s), (r = n.exec(e));
|
||
}
|
||
return t;
|
||
}
|
||
function tY(e) {
|
||
return Object.entries(e)
|
||
.filter(([, e]) => null != e)
|
||
.map(([e, t]) => `${e}="${t}"`)
|
||
.join(" ");
|
||
}
|
||
function tQ(e) {
|
||
let {
|
||
nodeName: t,
|
||
name: n,
|
||
getContent: r,
|
||
parseAttributes: i = tG,
|
||
serializeAttributes: o = tY,
|
||
defaultAttributes: s = {},
|
||
selfClosing: l = !1,
|
||
allowedAttributes: a,
|
||
} = e,
|
||
d = n || t,
|
||
c = d.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||
return {
|
||
parseMarkdown: (e, n) => {
|
||
let i = { ...s, ...e.attributes };
|
||
if (l) return n.createNode(t, i);
|
||
let o = r ? r(e) : e.content || "";
|
||
return o
|
||
? n.createNode(t, i, [n.createTextNode(o)])
|
||
: n.createNode(t, i, []);
|
||
},
|
||
markdownTokenizer: {
|
||
name: t,
|
||
level: "inline",
|
||
start(e) {
|
||
let t = l
|
||
? RegExp(`\\[${c}\\s*[^\\]]*\\]`)
|
||
: RegExp(`\\[${c}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${c}\\]`),
|
||
n = e.match(t),
|
||
r = null == n ? void 0 : n.index;
|
||
return void 0 !== r ? r : -1;
|
||
},
|
||
tokenize(e, n, r) {
|
||
let o = l
|
||
? RegExp(`^\\[${c}\\s*([^\\]]*)\\]`)
|
||
: RegExp(`^\\[${c}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${c}\\]`),
|
||
s = e.match(o);
|
||
if (!s) return;
|
||
let a = "",
|
||
d = "";
|
||
if (l) {
|
||
let [, e] = s;
|
||
d = e;
|
||
} else {
|
||
let [, e, t] = s;
|
||
(d = e), (a = t || "");
|
||
}
|
||
let h = i(d.trim());
|
||
return { type: t, raw: s[0], content: a.trim(), attributes: h };
|
||
},
|
||
},
|
||
renderMarkdown: (e) => {
|
||
let t = "";
|
||
r
|
||
? (t = r(e))
|
||
: e.content &&
|
||
e.content.length > 0 &&
|
||
(t = e.content
|
||
.filter((e) => "text" === e.type)
|
||
.map((e) => e.text)
|
||
.join(""));
|
||
let n = o(
|
||
((e) => {
|
||
if (!a) return e;
|
||
let t = {};
|
||
return (
|
||
a.forEach((n) => {
|
||
let r = "string" == typeof n ? n : n.name,
|
||
i = "string" == typeof n ? void 0 : n.skipIfDefault;
|
||
if (r in e) {
|
||
let n = e[r];
|
||
if (void 0 !== i && n === i) return;
|
||
t[r] = n;
|
||
}
|
||
}),
|
||
t
|
||
);
|
||
})(e.attrs || {}),
|
||
),
|
||
i = n ? ` ${n}` : "";
|
||
return l ? `[${d}${i}]` : `[${d}${i}]${t}[/${d}]`;
|
||
},
|
||
};
|
||
}
|
||
function tX(e, t, n) {
|
||
var r, i, o, s;
|
||
let l = e.split("\n"),
|
||
a = [],
|
||
d = "",
|
||
c = 0,
|
||
h = t.baseIndentSize || 2;
|
||
for (; c < l.length; ) {
|
||
let e,
|
||
p = l[c],
|
||
u = p.match(t.itemPattern);
|
||
if (!u)
|
||
if (a.length > 0) break;
|
||
else {
|
||
if ("" !== p.trim()) return;
|
||
(c += 1),
|
||
(d = `${d}${p}
|
||
`);
|
||
continue;
|
||
}
|
||
let f = t.extractItemData(u),
|
||
{ indentLevel: m, mainContent: g } = f;
|
||
d = `${d}${p}
|
||
`;
|
||
let y = [g];
|
||
for (c += 1; c < l.length; ) {
|
||
let e = l[c];
|
||
if ("" === e.trim()) {
|
||
let t = l.slice(c + 1).findIndex((e) => "" !== e.trim());
|
||
if (-1 === t) break;
|
||
if (
|
||
((null ==
|
||
(i = null == (r = l[c + 1 + t].match(/^(\s*)/)) ? void 0 : r[1])
|
||
? void 0
|
||
: i.length) || 0) > m
|
||
) {
|
||
y.push(e),
|
||
(d = `${d}${e}
|
||
`),
|
||
(c += 1);
|
||
continue;
|
||
}
|
||
break;
|
||
}
|
||
if (
|
||
((null == (s = null == (o = e.match(/^(\s*)/)) ? void 0 : o[1])
|
||
? void 0
|
||
: s.length) || 0) > m
|
||
)
|
||
y.push(e),
|
||
(d = `${d}${e}
|
||
`),
|
||
(c += 1);
|
||
else break;
|
||
}
|
||
let b = y.slice(1);
|
||
if (b.length > 0) {
|
||
let r = b.map((e) => e.slice(m + h)).join("\n");
|
||
r.trim() &&
|
||
(e = t.customNestedParser
|
||
? t.customNestedParser(r)
|
||
: n.blockTokens(r));
|
||
}
|
||
let k = t.createToken(f, e);
|
||
a.push(k);
|
||
}
|
||
if (0 !== a.length) return { items: a, raw: d };
|
||
}
|
||
function tZ(e, t, n, r) {
|
||
if (!e || !Array.isArray(e.content)) return "";
|
||
let i = "function" == typeof n ? n(r) : n,
|
||
[o, ...s] = e.content,
|
||
l = t.renderChildren([o]),
|
||
a = [`${i}${l}`];
|
||
return (
|
||
s &&
|
||
s.length > 0 &&
|
||
s.forEach((e) => {
|
||
let n = t.renderChildren([e]);
|
||
if (n) {
|
||
let e = n
|
||
.split("\n")
|
||
.map((e) => (e ? t.indent(e) : ""))
|
||
.join("\n");
|
||
a.push(e);
|
||
}
|
||
}),
|
||
a.join("\n")
|
||
);
|
||
}
|
||
function t0(e, t, n = {}) {
|
||
let { state: r } = t,
|
||
{ doc: i, tr: o } = r;
|
||
i.descendants((t, r) => {
|
||
let i = o.mapping.map(r),
|
||
s = o.mapping.map(r) + t.nodeSize,
|
||
l = null;
|
||
if (
|
||
(t.marks.forEach((t) => {
|
||
if (t !== e) return !1;
|
||
l = t;
|
||
}),
|
||
!l)
|
||
)
|
||
return;
|
||
let a = !1;
|
||
if (
|
||
(Object.keys(n).forEach((e) => {
|
||
n[e] !== l.attrs[e] && (a = !0);
|
||
}),
|
||
a)
|
||
) {
|
||
let t = e.type.create({ ...e.attrs, ...n });
|
||
o.removeMark(i, s, e.type), o.addMark(i, s, t);
|
||
}
|
||
}),
|
||
o.docChanged && t.view.dispatch(o);
|
||
}
|
||
d(
|
||
{},
|
||
{
|
||
createAtomBlockMarkdownSpec: () => tU,
|
||
createBlockMarkdownSpec: () => tJ,
|
||
createInlineMarkdownSpec: () => tQ,
|
||
parseAttributes: () => tq,
|
||
parseIndentedBlocks: () => tX,
|
||
renderNestedMarkdownContent: () => tZ,
|
||
serializeAttributes: () => tK,
|
||
},
|
||
);
|
||
var t1 = class {
|
||
constructor(e, t, n) {
|
||
(this.component = e),
|
||
(this.editor = t.editor),
|
||
(this.options = { ...n }),
|
||
(this.mark = t.mark),
|
||
(this.HTMLAttributes = t.HTMLAttributes);
|
||
}
|
||
get dom() {
|
||
return this.editor.view.dom;
|
||
}
|
||
get contentDOM() {
|
||
return null;
|
||
}
|
||
updateAttributes(e, t) {
|
||
t0(t || this.mark, this.editor, e);
|
||
}
|
||
ignoreMutation(e) {
|
||
return (
|
||
!this.dom ||
|
||
!this.contentDOM ||
|
||
("function" == typeof this.options.ignoreMutation
|
||
? this.options.ignoreMutation({ mutation: e })
|
||
: !(
|
||
"selection" === e.type ||
|
||
(this.dom.contains(e.target) &&
|
||
"childList" === e.type &&
|
||
($() || B()) &&
|
||
this.editor.isFocused &&
|
||
[
|
||
...Array.from(e.addedNodes),
|
||
...Array.from(e.removedNodes),
|
||
].every((e) => e.isContentEditable))
|
||
) &&
|
||
((this.contentDOM === e.target && "attributes" === e.type) ||
|
||
!this.contentDOM.contains(e.target)))
|
||
);
|
||
}
|
||
},
|
||
t2 = class e extends tb {
|
||
constructor() {
|
||
super(...arguments), (this.type = "node");
|
||
}
|
||
static create(t = {}) {
|
||
return new e("function" == typeof t ? t() : t);
|
||
}
|
||
configure(e) {
|
||
return super.configure(e);
|
||
}
|
||
extend(e) {
|
||
let t = "function" == typeof e ? e() : e;
|
||
return super.extend(t);
|
||
}
|
||
},
|
||
t3 = class {
|
||
constructor(e, t, n) {
|
||
(this.isDragging = !1),
|
||
(this.component = e),
|
||
(this.editor = t.editor),
|
||
(this.options = { stopEvent: null, ignoreMutation: null, ...n }),
|
||
(this.extension = t.extension),
|
||
(this.node = t.node),
|
||
(this.decorations = t.decorations),
|
||
(this.innerDecorations = t.innerDecorations),
|
||
(this.view = t.view),
|
||
(this.HTMLAttributes = t.HTMLAttributes),
|
||
(this.getPos = t.getPos),
|
||
this.mount();
|
||
}
|
||
mount() {}
|
||
get dom() {
|
||
return this.editor.view.dom;
|
||
}
|
||
get contentDOM() {
|
||
return null;
|
||
}
|
||
onDragStart(e) {
|
||
var t, n, i, o, s, l, a;
|
||
let { view: d } = this.editor,
|
||
c = e.target,
|
||
h =
|
||
3 === c.nodeType
|
||
? null == (t = c.parentElement)
|
||
? void 0
|
||
: t.closest("[data-drag-handle]")
|
||
: c.closest("[data-drag-handle]");
|
||
if (
|
||
!this.dom ||
|
||
(null == (n = this.contentDOM) ? void 0 : n.contains(c)) ||
|
||
!h
|
||
)
|
||
return;
|
||
let p = 0,
|
||
u = 0;
|
||
if (this.dom !== h) {
|
||
let t = this.dom.getBoundingClientRect(),
|
||
n = h.getBoundingClientRect(),
|
||
r =
|
||
null != (o = e.offsetX)
|
||
? o
|
||
: null == (i = e.nativeEvent)
|
||
? void 0
|
||
: i.offsetX,
|
||
a =
|
||
null != (l = e.offsetY)
|
||
? l
|
||
: null == (s = e.nativeEvent)
|
||
? void 0
|
||
: s.offsetY;
|
||
(p = n.x - t.x + r), (u = n.y - t.y + a);
|
||
}
|
||
let f = this.dom.cloneNode(!0);
|
||
try {
|
||
let e = this.dom.getBoundingClientRect();
|
||
(f.style.width = `${Math.round(e.width)}px`),
|
||
(f.style.height = `${Math.round(e.height)}px`),
|
||
(f.style.boxSizing = "border-box"),
|
||
(f.style.pointerEvents = "none");
|
||
} catch {}
|
||
let m = null;
|
||
try {
|
||
((m = document.createElement("div")).style.position = "absolute"),
|
||
(m.style.top = "-9999px"),
|
||
(m.style.left = "-9999px"),
|
||
(m.style.pointerEvents = "none"),
|
||
m.appendChild(f),
|
||
document.body.appendChild(m),
|
||
null == (a = e.dataTransfer) || a.setDragImage(f, p, u);
|
||
} finally {
|
||
m &&
|
||
setTimeout(() => {
|
||
try {
|
||
null == m || m.remove();
|
||
} catch {}
|
||
}, 0);
|
||
}
|
||
let g = this.getPos();
|
||
if ("number" != typeof g) return;
|
||
let y = r.NodeSelection.create(d.state.doc, g),
|
||
b = d.state.tr.setSelection(y);
|
||
d.dispatch(b);
|
||
}
|
||
stopEvent(e) {
|
||
var t;
|
||
if (!this.dom) return !1;
|
||
if ("function" == typeof this.options.stopEvent)
|
||
return this.options.stopEvent({ event: e });
|
||
let n = e.target;
|
||
if (
|
||
!(
|
||
this.dom.contains(n) &&
|
||
!(null == (t = this.contentDOM) ? void 0 : t.contains(n))
|
||
)
|
||
)
|
||
return !1;
|
||
let i = e.type.startsWith("drag"),
|
||
o = "drop" === e.type;
|
||
if (
|
||
(["INPUT", "BUTTON", "SELECT", "TEXTAREA"].includes(n.tagName) ||
|
||
n.isContentEditable) &&
|
||
!o &&
|
||
!i
|
||
)
|
||
return !0;
|
||
let { isEditable: s } = this.editor,
|
||
{ isDragging: l } = this,
|
||
a = !!this.node.type.spec.draggable,
|
||
d = r.NodeSelection.isSelectable(this.node),
|
||
c = "copy" === e.type,
|
||
h = "paste" === e.type,
|
||
p = "cut" === e.type,
|
||
u = "mousedown" === e.type;
|
||
if (
|
||
(!a && d && i && e.target === this.dom && e.preventDefault(),
|
||
a && i && !l && e.target === this.dom)
|
||
)
|
||
return e.preventDefault(), !1;
|
||
if (a && s && !l && u) {
|
||
let e = n.closest("[data-drag-handle]");
|
||
e &&
|
||
(this.dom === e || this.dom.contains(e)) &&
|
||
((this.isDragging = !0),
|
||
document.addEventListener(
|
||
"dragend",
|
||
() => {
|
||
this.isDragging = !1;
|
||
},
|
||
{ once: !0 },
|
||
),
|
||
document.addEventListener(
|
||
"drop",
|
||
() => {
|
||
this.isDragging = !1;
|
||
},
|
||
{ once: !0 },
|
||
),
|
||
document.addEventListener(
|
||
"mouseup",
|
||
() => {
|
||
this.isDragging = !1;
|
||
},
|
||
{ once: !0 },
|
||
));
|
||
}
|
||
return !l && !o && !c && !h && !p && (!u || !d);
|
||
}
|
||
ignoreMutation(e) {
|
||
return (
|
||
!this.dom ||
|
||
!this.contentDOM ||
|
||
("function" == typeof this.options.ignoreMutation
|
||
? this.options.ignoreMutation({ mutation: e })
|
||
: !!this.node.isLeaf ||
|
||
!!this.node.isAtom ||
|
||
(!(
|
||
"selection" === e.type ||
|
||
(this.dom.contains(e.target) &&
|
||
"childList" === e.type &&
|
||
($() || B()) &&
|
||
this.editor.isFocused &&
|
||
[
|
||
...Array.from(e.addedNodes),
|
||
...Array.from(e.removedNodes),
|
||
].every((e) => e.isContentEditable))
|
||
) &&
|
||
((this.contentDOM === e.target && "attributes" === e.type) ||
|
||
!this.contentDOM.contains(e.target))))
|
||
);
|
||
}
|
||
updateAttributes(e) {
|
||
this.editor.commands.command(({ tr: t }) => {
|
||
let n = this.getPos();
|
||
return (
|
||
"number" == typeof n &&
|
||
(t.setNodeMarkup(n, void 0, { ...this.node.attrs, ...e }), !0)
|
||
);
|
||
});
|
||
}
|
||
deleteNode() {
|
||
let e = this.getPos();
|
||
if ("number" != typeof e) return;
|
||
let t = e + this.node.nodeSize;
|
||
this.editor.commands.deleteRange({ from: e, to: t });
|
||
}
|
||
};
|
||
function t4(e) {
|
||
return new tv({
|
||
find: e.find,
|
||
handler: ({ state: t, range: n, match: r, pasteEvent: i }) => {
|
||
let o = eN(e.getAttributes, void 0, r, i);
|
||
if (!1 === o || null === o) return null;
|
||
let { tr: s } = t,
|
||
l = r[r.length - 1],
|
||
a = r[0],
|
||
d = n.to;
|
||
if (l) {
|
||
let r = a.search(/\S/),
|
||
i = n.from + a.indexOf(l),
|
||
c = i + l.length;
|
||
if (
|
||
eV(n.from, n.to, t.doc)
|
||
.filter((t) =>
|
||
t.mark.type.excluded.find(
|
||
(n) => n === e.type && n !== t.mark.type,
|
||
),
|
||
)
|
||
.filter((e) => e.to > i).length
|
||
)
|
||
return null;
|
||
c < n.to && s.delete(c, n.to),
|
||
i > n.from && s.delete(n.from + r, i),
|
||
(d = n.from + r + l.length),
|
||
s.addMark(n.from + r, d, e.type.create(o || {})),
|
||
s.removeStoredMark(e.type);
|
||
}
|
||
},
|
||
});
|
||
}
|
||
e.s([
|
||
"Editor",
|
||
() => t$,
|
||
"Extension",
|
||
() => tM,
|
||
"Mark",
|
||
() => tk,
|
||
"MarkView",
|
||
() => t1,
|
||
"Node",
|
||
() => t2,
|
||
"NodeView",
|
||
() => t3,
|
||
"callOrReturn",
|
||
() => eN,
|
||
"canInsertNode",
|
||
() => tW,
|
||
"combineTransactionSteps",
|
||
() => ev,
|
||
"createInlineMarkdownSpec",
|
||
() => tQ,
|
||
"escapeForRegEx",
|
||
() => t_,
|
||
"extensions",
|
||
() => tx,
|
||
"findChildrenInRange",
|
||
() => ew,
|
||
"getAttributes",
|
||
() => ej,
|
||
"getChangedRanges",
|
||
() => eF,
|
||
"getExtensionField",
|
||
() => ex,
|
||
"getHTMLFromFragment",
|
||
() => eC,
|
||
"getMarksBetween",
|
||
() => eV,
|
||
"getNodeAtPosition",
|
||
() => eH,
|
||
"getNodeType",
|
||
() => v,
|
||
"getRenderedAttributes",
|
||
() => eD,
|
||
"isAtEndOfNode",
|
||
() => eK,
|
||
"isAtStartOfNode",
|
||
() => eU,
|
||
"isNodeActive",
|
||
() => en,
|
||
"isNodeEmpty",
|
||
() => eY,
|
||
"isNodeSelection",
|
||
() => eQ,
|
||
"markInputRule",
|
||
() => tj,
|
||
"markPasteRule",
|
||
() => t4,
|
||
"mergeAttributes",
|
||
() => eA,
|
||
"nodeInputRule",
|
||
() => tF,
|
||
"parseIndentedBlocks",
|
||
() => tX,
|
||
"renderNestedMarkdownContent",
|
||
() => tZ,
|
||
"textblockTypeInputRule",
|
||
() => tV,
|
||
"wrappingInputRule",
|
||
() => tH,
|
||
]);
|
||
};
|
||
|
||
export default moduleFactory;
|