682 lines
20 KiB
JavaScript
682 lines
20 KiB
JavaScript
/*
|
|
* Extracted from browser-delivered Turbopack chunk: 2a4e4dccbc3fdacb.bc4b655d5c.js
|
|
* Module id: 111092
|
|
* For reading/searching only; this factory depends on the original Turbopack runtime.
|
|
*/
|
|
|
|
const moduleFactory = (e) => {
|
|
"use strict";
|
|
var t = e.i(47091),
|
|
n = e.i(545773);
|
|
let r = Object.create(null);
|
|
class i {
|
|
constructor(e, t, n) {
|
|
(this.$anchor = e),
|
|
(this.$head = t),
|
|
(this.ranges = n || [new o(e.min(t), e.max(t))]);
|
|
}
|
|
get anchor() {
|
|
return this.$anchor.pos;
|
|
}
|
|
get head() {
|
|
return this.$head.pos;
|
|
}
|
|
get from() {
|
|
return this.$from.pos;
|
|
}
|
|
get to() {
|
|
return this.$to.pos;
|
|
}
|
|
get $from() {
|
|
return this.ranges[0].$from;
|
|
}
|
|
get $to() {
|
|
return this.ranges[0].$to;
|
|
}
|
|
get empty() {
|
|
let e = this.ranges;
|
|
for (let t = 0; t < e.length; t++)
|
|
if (e[t].$from.pos != e[t].$to.pos) return !1;
|
|
return !0;
|
|
}
|
|
content() {
|
|
return this.$from.doc.slice(this.from, this.to, !0);
|
|
}
|
|
replace(e, n = t.Slice.empty) {
|
|
let r = n.content.lastChild,
|
|
i = null;
|
|
for (let e = 0; e < n.openEnd; e++) (i = r), (r = r.lastChild);
|
|
let o = e.steps.length,
|
|
s = this.ranges;
|
|
for (let l = 0; l < s.length; l++) {
|
|
let { $from: a, $to: d } = s[l],
|
|
c = e.mapping.slice(o);
|
|
e.replaceRange(c.map(a.pos), c.map(d.pos), l ? t.Slice.empty : n),
|
|
0 == l && m(e, o, (r ? r.isInline : i && i.isTextblock) ? -1 : 1);
|
|
}
|
|
}
|
|
replaceWith(e, t) {
|
|
let n = e.steps.length,
|
|
r = this.ranges;
|
|
for (let i = 0; i < r.length; i++) {
|
|
let { $from: o, $to: s } = r[i],
|
|
l = e.mapping.slice(n),
|
|
a = l.map(o.pos),
|
|
d = l.map(s.pos);
|
|
i
|
|
? e.deleteRange(a, d)
|
|
: (e.replaceRangeWith(a, d, t), m(e, n, t.isInline ? -1 : 1));
|
|
}
|
|
}
|
|
static findFrom(e, t, n = !1) {
|
|
let r = e.parent.inlineContent
|
|
? new a(e)
|
|
: f(e.node(0), e.parent, e.pos, e.index(), t, n);
|
|
if (r) return r;
|
|
for (let r = e.depth - 1; r >= 0; r--) {
|
|
let i =
|
|
t < 0
|
|
? f(e.node(0), e.node(r), e.before(r + 1), e.index(r), t, n)
|
|
: f(e.node(0), e.node(r), e.after(r + 1), e.index(r) + 1, t, n);
|
|
if (i) return i;
|
|
}
|
|
return null;
|
|
}
|
|
static near(e, t = 1) {
|
|
return this.findFrom(e, t) || this.findFrom(e, -t) || new p(e.node(0));
|
|
}
|
|
static atStart(e) {
|
|
return f(e, e, 0, 0, 1) || new p(e);
|
|
}
|
|
static atEnd(e) {
|
|
return f(e, e, e.content.size, e.childCount, -1) || new p(e);
|
|
}
|
|
static fromJSON(e, t) {
|
|
if (!t || !t.type)
|
|
throw RangeError("Invalid input for Selection.fromJSON");
|
|
let n = r[t.type];
|
|
if (!n) throw RangeError(`No selection type ${t.type} defined`);
|
|
return n.fromJSON(e, t);
|
|
}
|
|
static jsonID(e, t) {
|
|
if (e in r) throw RangeError("Duplicate use of selection JSON ID " + e);
|
|
return (r[e] = t), (t.prototype.jsonID = e), t;
|
|
}
|
|
getBookmark() {
|
|
return a.between(this.$anchor, this.$head).getBookmark();
|
|
}
|
|
}
|
|
i.prototype.visible = !0;
|
|
class o {
|
|
constructor(e, t) {
|
|
(this.$from = e), (this.$to = t);
|
|
}
|
|
}
|
|
let s = !1;
|
|
function l(e) {
|
|
s ||
|
|
e.parent.inlineContent ||
|
|
((s = !0),
|
|
console.warn(
|
|
"TextSelection endpoint not pointing into a node with inline content (" +
|
|
e.parent.type.name +
|
|
")",
|
|
));
|
|
}
|
|
class a extends i {
|
|
constructor(e, t = e) {
|
|
l(e), l(t), super(e, t);
|
|
}
|
|
get $cursor() {
|
|
return this.$anchor.pos == this.$head.pos ? this.$head : null;
|
|
}
|
|
map(e, t) {
|
|
let n = e.resolve(t.map(this.head));
|
|
if (!n.parent.inlineContent) return i.near(n);
|
|
let r = e.resolve(t.map(this.anchor));
|
|
return new a(r.parent.inlineContent ? r : n, n);
|
|
}
|
|
replace(e, n = t.Slice.empty) {
|
|
if ((super.replace(e, n), n == t.Slice.empty)) {
|
|
let t = this.$from.marksAcross(this.$to);
|
|
t && e.ensureMarks(t);
|
|
}
|
|
}
|
|
eq(e) {
|
|
return e instanceof a && e.anchor == this.anchor && e.head == this.head;
|
|
}
|
|
getBookmark() {
|
|
return new d(this.anchor, this.head);
|
|
}
|
|
toJSON() {
|
|
return { type: "text", anchor: this.anchor, head: this.head };
|
|
}
|
|
static fromJSON(e, t) {
|
|
if ("number" != typeof t.anchor || "number" != typeof t.head)
|
|
throw RangeError("Invalid input for TextSelection.fromJSON");
|
|
return new a(e.resolve(t.anchor), e.resolve(t.head));
|
|
}
|
|
static create(e, t, n = t) {
|
|
let r = e.resolve(t);
|
|
return new this(r, n == t ? r : e.resolve(n));
|
|
}
|
|
static between(e, t, n) {
|
|
let r = e.pos - t.pos;
|
|
if (((!n || r) && (n = r >= 0 ? 1 : -1), !t.parent.inlineContent)) {
|
|
let e = i.findFrom(t, n, !0) || i.findFrom(t, -n, !0);
|
|
if (!e) return i.near(t, n);
|
|
t = e.$head;
|
|
}
|
|
return (
|
|
e.parent.inlineContent ||
|
|
(0 == r
|
|
? (e = t)
|
|
: (e = (i.findFrom(e, -n, !0) || i.findFrom(e, n, !0)).$anchor)
|
|
.pos <
|
|
t.pos !=
|
|
r < 0 && (e = t)),
|
|
new a(e, t)
|
|
);
|
|
}
|
|
}
|
|
i.jsonID("text", a);
|
|
class d {
|
|
constructor(e, t) {
|
|
(this.anchor = e), (this.head = t);
|
|
}
|
|
map(e) {
|
|
return new d(e.map(this.anchor), e.map(this.head));
|
|
}
|
|
resolve(e) {
|
|
return a.between(e.resolve(this.anchor), e.resolve(this.head));
|
|
}
|
|
}
|
|
class c extends i {
|
|
constructor(e) {
|
|
let t = e.nodeAfter,
|
|
n = e.node(0).resolve(e.pos + t.nodeSize);
|
|
super(e, n), (this.node = t);
|
|
}
|
|
map(e, t) {
|
|
let { deleted: n, pos: r } = t.mapResult(this.anchor),
|
|
o = e.resolve(r);
|
|
return n ? i.near(o) : new c(o);
|
|
}
|
|
content() {
|
|
return new t.Slice(t.Fragment.from(this.node), 0, 0);
|
|
}
|
|
eq(e) {
|
|
return e instanceof c && e.anchor == this.anchor;
|
|
}
|
|
toJSON() {
|
|
return { type: "node", anchor: this.anchor };
|
|
}
|
|
getBookmark() {
|
|
return new h(this.anchor);
|
|
}
|
|
static fromJSON(e, t) {
|
|
if ("number" != typeof t.anchor)
|
|
throw RangeError("Invalid input for NodeSelection.fromJSON");
|
|
return new c(e.resolve(t.anchor));
|
|
}
|
|
static create(e, t) {
|
|
return new c(e.resolve(t));
|
|
}
|
|
static isSelectable(e) {
|
|
return !e.isText && !1 !== e.type.spec.selectable;
|
|
}
|
|
}
|
|
(c.prototype.visible = !1), i.jsonID("node", c);
|
|
class h {
|
|
constructor(e) {
|
|
this.anchor = e;
|
|
}
|
|
map(e) {
|
|
let { deleted: t, pos: n } = e.mapResult(this.anchor);
|
|
return t ? new d(n, n) : new h(n);
|
|
}
|
|
resolve(e) {
|
|
let t = e.resolve(this.anchor),
|
|
n = t.nodeAfter;
|
|
return n && c.isSelectable(n) ? new c(t) : i.near(t);
|
|
}
|
|
}
|
|
class p extends i {
|
|
constructor(e) {
|
|
super(e.resolve(0), e.resolve(e.content.size));
|
|
}
|
|
replace(e, n = t.Slice.empty) {
|
|
if (n == t.Slice.empty) {
|
|
e.delete(0, e.doc.content.size);
|
|
let t = i.atStart(e.doc);
|
|
t.eq(e.selection) || e.setSelection(t);
|
|
} else super.replace(e, n);
|
|
}
|
|
toJSON() {
|
|
return { type: "all" };
|
|
}
|
|
static fromJSON(e) {
|
|
return new p(e);
|
|
}
|
|
map(e) {
|
|
return new p(e);
|
|
}
|
|
eq(e) {
|
|
return e instanceof p;
|
|
}
|
|
getBookmark() {
|
|
return u;
|
|
}
|
|
}
|
|
i.jsonID("all", p);
|
|
let u = {
|
|
map() {
|
|
return this;
|
|
},
|
|
resolve: (e) => new p(e),
|
|
};
|
|
function f(e, t, n, r, i, o = !1) {
|
|
if (t.inlineContent) return a.create(e, n);
|
|
for (
|
|
let s = r - (i > 0 ? 0 : 1);
|
|
i > 0 ? s < t.childCount : s >= 0;
|
|
s += i
|
|
) {
|
|
let r = t.child(s);
|
|
if (r.isAtom) {
|
|
if (!o && c.isSelectable(r))
|
|
return c.create(e, n - (i < 0 ? r.nodeSize : 0));
|
|
} else {
|
|
let t = f(e, r, n + i, i < 0 ? r.childCount : 0, i, o);
|
|
if (t) return t;
|
|
}
|
|
n += r.nodeSize * i;
|
|
}
|
|
return null;
|
|
}
|
|
function m(e, t, r) {
|
|
let o,
|
|
s = e.steps.length - 1;
|
|
if (s < t) return;
|
|
let l = e.steps[s];
|
|
(l instanceof n.ReplaceStep || l instanceof n.ReplaceAroundStep) &&
|
|
(e.mapping.maps[s].forEach((e, t, n, r) => {
|
|
null == o && (o = r);
|
|
}),
|
|
e.setSelection(i.near(e.doc.resolve(o), r)));
|
|
}
|
|
class g extends n.Transform {
|
|
constructor(e) {
|
|
super(e.doc),
|
|
(this.curSelectionFor = 0),
|
|
(this.updated = 0),
|
|
(this.meta = Object.create(null)),
|
|
(this.time = Date.now()),
|
|
(this.curSelection = e.selection),
|
|
(this.storedMarks = e.storedMarks);
|
|
}
|
|
get selection() {
|
|
return (
|
|
this.curSelectionFor < this.steps.length &&
|
|
((this.curSelection = this.curSelection.map(
|
|
this.doc,
|
|
this.mapping.slice(this.curSelectionFor),
|
|
)),
|
|
(this.curSelectionFor = this.steps.length)),
|
|
this.curSelection
|
|
);
|
|
}
|
|
setSelection(e) {
|
|
if (e.$from.doc != this.doc)
|
|
throw RangeError(
|
|
"Selection passed to setSelection must point at the current document",
|
|
);
|
|
return (
|
|
(this.curSelection = e),
|
|
(this.curSelectionFor = this.steps.length),
|
|
(this.updated = (1 | this.updated) & -3),
|
|
(this.storedMarks = null),
|
|
this
|
|
);
|
|
}
|
|
get selectionSet() {
|
|
return (1 & this.updated) > 0;
|
|
}
|
|
setStoredMarks(e) {
|
|
return (this.storedMarks = e), (this.updated |= 2), this;
|
|
}
|
|
ensureMarks(e) {
|
|
return (
|
|
t.Mark.sameSet(this.storedMarks || this.selection.$from.marks(), e) ||
|
|
this.setStoredMarks(e),
|
|
this
|
|
);
|
|
}
|
|
addStoredMark(e) {
|
|
return this.ensureMarks(
|
|
e.addToSet(this.storedMarks || this.selection.$head.marks()),
|
|
);
|
|
}
|
|
removeStoredMark(e) {
|
|
return this.ensureMarks(
|
|
e.removeFromSet(this.storedMarks || this.selection.$head.marks()),
|
|
);
|
|
}
|
|
get storedMarksSet() {
|
|
return (2 & this.updated) > 0;
|
|
}
|
|
addStep(e, t) {
|
|
super.addStep(e, t),
|
|
(this.updated = -3 & this.updated),
|
|
(this.storedMarks = null);
|
|
}
|
|
setTime(e) {
|
|
return (this.time = e), this;
|
|
}
|
|
replaceSelection(e) {
|
|
return this.selection.replace(this, e), this;
|
|
}
|
|
replaceSelectionWith(e, n = !0) {
|
|
let r = this.selection;
|
|
return (
|
|
n &&
|
|
(e = e.mark(
|
|
this.storedMarks ||
|
|
(r.empty
|
|
? r.$from.marks()
|
|
: r.$from.marksAcross(r.$to) || t.Mark.none),
|
|
)),
|
|
r.replaceWith(this, e),
|
|
this
|
|
);
|
|
}
|
|
deleteSelection() {
|
|
return this.selection.replace(this), this;
|
|
}
|
|
insertText(e, t, n) {
|
|
let r = this.doc.type.schema;
|
|
if (null == t)
|
|
return e
|
|
? this.replaceSelectionWith(r.text(e), !0)
|
|
: this.deleteSelection();
|
|
{
|
|
if ((null == n && (n = t), !e)) return this.deleteRange(t, n);
|
|
let o = this.storedMarks;
|
|
if (!o) {
|
|
let e = this.doc.resolve(t);
|
|
o = n == t ? e.marks() : e.marksAcross(this.doc.resolve(n));
|
|
}
|
|
return (
|
|
this.replaceRangeWith(t, n, r.text(e, o)),
|
|
this.selection.empty ||
|
|
this.selection.to != t + e.length ||
|
|
this.setSelection(i.near(this.selection.$to)),
|
|
this
|
|
);
|
|
}
|
|
}
|
|
setMeta(e, t) {
|
|
return (this.meta["string" == typeof e ? e : e.key] = t), this;
|
|
}
|
|
getMeta(e) {
|
|
return this.meta["string" == typeof e ? e : e.key];
|
|
}
|
|
get isGeneric() {
|
|
for (let e in this.meta) return !1;
|
|
return !0;
|
|
}
|
|
scrollIntoView() {
|
|
return (this.updated |= 4), this;
|
|
}
|
|
get scrolledIntoView() {
|
|
return (4 & this.updated) > 0;
|
|
}
|
|
}
|
|
function y(e, t) {
|
|
return t && e ? e.bind(t) : e;
|
|
}
|
|
class b {
|
|
constructor(e, t, n) {
|
|
(this.name = e),
|
|
(this.init = y(t.init, n)),
|
|
(this.apply = y(t.apply, n));
|
|
}
|
|
}
|
|
let k = [
|
|
new b("doc", {
|
|
init: (e) => e.doc || e.schema.topNodeType.createAndFill(),
|
|
apply: (e) => e.doc,
|
|
}),
|
|
new b("selection", {
|
|
init: (e, t) => e.selection || i.atStart(t.doc),
|
|
apply: (e) => e.selection,
|
|
}),
|
|
new b("storedMarks", {
|
|
init: (e) => e.storedMarks || null,
|
|
apply: (e, t, n, r) => (r.selection.$cursor ? e.storedMarks : null),
|
|
}),
|
|
new b("scrollToSelection", {
|
|
init: () => 0,
|
|
apply: (e, t) => (e.scrolledIntoView ? t + 1 : t),
|
|
}),
|
|
];
|
|
class v {
|
|
constructor(e, t) {
|
|
(this.schema = e),
|
|
(this.plugins = []),
|
|
(this.pluginsByKey = Object.create(null)),
|
|
(this.fields = k.slice()),
|
|
t &&
|
|
t.forEach((e) => {
|
|
if (this.pluginsByKey[e.key])
|
|
throw RangeError(
|
|
"Adding different instances of a keyed plugin (" +
|
|
e.key +
|
|
")",
|
|
);
|
|
this.plugins.push(e),
|
|
(this.pluginsByKey[e.key] = e),
|
|
e.spec.state && this.fields.push(new b(e.key, e.spec.state, e));
|
|
});
|
|
}
|
|
}
|
|
class w {
|
|
constructor(e) {
|
|
this.config = e;
|
|
}
|
|
get schema() {
|
|
return this.config.schema;
|
|
}
|
|
get plugins() {
|
|
return this.config.plugins;
|
|
}
|
|
apply(e) {
|
|
return this.applyTransaction(e).state;
|
|
}
|
|
filterTransaction(e, t = -1) {
|
|
for (let n = 0; n < this.config.plugins.length; n++)
|
|
if (n != t) {
|
|
let t = this.config.plugins[n];
|
|
if (
|
|
t.spec.filterTransaction &&
|
|
!t.spec.filterTransaction.call(t, e, this)
|
|
)
|
|
return !1;
|
|
}
|
|
return !0;
|
|
}
|
|
applyTransaction(e) {
|
|
if (!this.filterTransaction(e))
|
|
return { state: this, transactions: [] };
|
|
let t = [e],
|
|
n = this.applyInner(e),
|
|
r = null;
|
|
for (;;) {
|
|
let i = !1;
|
|
for (let o = 0; o < this.config.plugins.length; o++) {
|
|
let s = this.config.plugins[o];
|
|
if (s.spec.appendTransaction) {
|
|
let l = r ? r[o].n : 0,
|
|
a = r ? r[o].state : this,
|
|
d =
|
|
l < t.length &&
|
|
s.spec.appendTransaction.call(s, l ? t.slice(l) : t, a, n);
|
|
if (d && n.filterTransaction(d, o)) {
|
|
if ((d.setMeta("appendedTransaction", e), !r)) {
|
|
r = [];
|
|
for (let e = 0; e < this.config.plugins.length; e++)
|
|
r.push(
|
|
e < o ? { state: n, n: t.length } : { state: this, n: 0 },
|
|
);
|
|
}
|
|
t.push(d), (n = n.applyInner(d)), (i = !0);
|
|
}
|
|
r && (r[o] = { state: n, n: t.length });
|
|
}
|
|
}
|
|
if (!i) return { state: n, transactions: t };
|
|
}
|
|
}
|
|
applyInner(e) {
|
|
if (!e.before.eq(this.doc))
|
|
throw RangeError("Applying a mismatched transaction");
|
|
let t = new w(this.config),
|
|
n = this.config.fields;
|
|
for (let r = 0; r < n.length; r++) {
|
|
let i = n[r];
|
|
t[i.name] = i.apply(e, this[i.name], this, t);
|
|
}
|
|
return t;
|
|
}
|
|
get tr() {
|
|
return new g(this);
|
|
}
|
|
static create(e) {
|
|
let t = new v(e.doc ? e.doc.type.schema : e.schema, e.plugins),
|
|
n = new w(t);
|
|
for (let r = 0; r < t.fields.length; r++)
|
|
n[t.fields[r].name] = t.fields[r].init(e, n);
|
|
return n;
|
|
}
|
|
reconfigure(e) {
|
|
let t = new v(this.schema, e.plugins),
|
|
n = t.fields,
|
|
r = new w(t);
|
|
for (let t = 0; t < n.length; t++) {
|
|
let i = n[t].name;
|
|
r[i] = this.hasOwnProperty(i) ? this[i] : n[t].init(e, r);
|
|
}
|
|
return r;
|
|
}
|
|
toJSON(e) {
|
|
let t = { doc: this.doc.toJSON(), selection: this.selection.toJSON() };
|
|
if (
|
|
(this.storedMarks &&
|
|
(t.storedMarks = this.storedMarks.map((e) => e.toJSON())),
|
|
e && "object" == typeof e)
|
|
)
|
|
for (let n in e) {
|
|
if ("doc" == n || "selection" == n)
|
|
throw RangeError(
|
|
"The JSON fields `doc` and `selection` are reserved",
|
|
);
|
|
let r = e[n],
|
|
i = r.spec.state;
|
|
i && i.toJSON && (t[n] = i.toJSON.call(r, this[r.key]));
|
|
}
|
|
return t;
|
|
}
|
|
static fromJSON(e, n, r) {
|
|
if (!n) throw RangeError("Invalid input for EditorState.fromJSON");
|
|
if (!e.schema)
|
|
throw RangeError("Required config field 'schema' missing");
|
|
let o = new v(e.schema, e.plugins),
|
|
s = new w(o);
|
|
return (
|
|
o.fields.forEach((o) => {
|
|
if ("doc" == o.name) s.doc = t.Node.fromJSON(e.schema, n.doc);
|
|
else if ("selection" == o.name)
|
|
s.selection = i.fromJSON(s.doc, n.selection);
|
|
else if ("storedMarks" == o.name)
|
|
n.storedMarks &&
|
|
(s.storedMarks = n.storedMarks.map(e.schema.markFromJSON));
|
|
else {
|
|
if (r)
|
|
for (let t in r) {
|
|
let i = r[t],
|
|
l = i.spec.state;
|
|
if (
|
|
i.key == o.name &&
|
|
l &&
|
|
l.fromJSON &&
|
|
Object.prototype.hasOwnProperty.call(n, t)
|
|
) {
|
|
s[o.name] = l.fromJSON.call(i, e, n[t], s);
|
|
return;
|
|
}
|
|
}
|
|
s[o.name] = o.init(e, s);
|
|
}
|
|
}),
|
|
s
|
|
);
|
|
}
|
|
}
|
|
class S {
|
|
constructor(e) {
|
|
(this.spec = e),
|
|
(this.props = {}),
|
|
e.props &&
|
|
(function e(t, n, r) {
|
|
for (let i in t) {
|
|
let o = t[i];
|
|
o instanceof Function
|
|
? (o = o.bind(n))
|
|
: "handleDOMEvents" == i && (o = e(o, n, {})),
|
|
(r[i] = o);
|
|
}
|
|
return r;
|
|
})(e.props, this, this.props),
|
|
(this.key = e.key ? e.key.key : M("plugin"));
|
|
}
|
|
getState(e) {
|
|
return e[this.key];
|
|
}
|
|
}
|
|
let x = Object.create(null);
|
|
function M(e) {
|
|
return e in x ? e + "$" + ++x[e] : ((x[e] = 0), e + "$");
|
|
}
|
|
class C {
|
|
constructor(e = "key") {
|
|
this.key = M(e);
|
|
}
|
|
get(e) {
|
|
return e.config.pluginsByKey[this.key];
|
|
}
|
|
getState(e) {
|
|
return e[this.key];
|
|
}
|
|
}
|
|
e.s([
|
|
"AllSelection",
|
|
() => p,
|
|
"EditorState",
|
|
() => w,
|
|
"NodeSelection",
|
|
() => c,
|
|
"Plugin",
|
|
() => S,
|
|
"PluginKey",
|
|
() => C,
|
|
"Selection",
|
|
() => i,
|
|
"SelectionRange",
|
|
() => o,
|
|
"TextSelection",
|
|
() => a,
|
|
]);
|
|
};
|
|
|
|
export default moduleFactory;
|