625 lines
18 KiB
JavaScript
625 lines
18 KiB
JavaScript
/*
|
|
* Extracted from browser-delivered Turbopack chunk: 2a4e4dccbc3fdacb.bc4b655d5c.js
|
|
* Module id: 445794
|
|
* For reading/searching only; this factory depends on the original Turbopack runtime.
|
|
*/
|
|
|
|
const moduleFactory = (e) => {
|
|
"use strict";
|
|
var t = e.i(545773),
|
|
n = e.i(47091),
|
|
r = e.i(111092);
|
|
let i = (e, t) =>
|
|
!e.selection.empty &&
|
|
(t && t(e.tr.deleteSelection().scrollIntoView()), !0);
|
|
function o(e, t) {
|
|
let { $cursor: n } = e.selection;
|
|
return n && (t ? t.endOfTextblock("backward", e) : !(n.parentOffset > 0))
|
|
? n
|
|
: null;
|
|
}
|
|
let s = (e, i, s) => {
|
|
let l = o(e, s);
|
|
if (!l) return !1;
|
|
let a = p(l);
|
|
if (!a) {
|
|
let n = l.blockRange(),
|
|
r = n && (0, t.liftTarget)(n);
|
|
return null != r && (i && i(e.tr.lift(n, r).scrollIntoView()), !0);
|
|
}
|
|
let d = a.nodeBefore;
|
|
if (T(e, a, i, -1)) return !0;
|
|
if (
|
|
0 == l.parent.content.size &&
|
|
(c(d, "end") || r.NodeSelection.isSelectable(d))
|
|
)
|
|
for (let o = l.depth; ; o--) {
|
|
let s = (0, t.replaceStep)(
|
|
e.doc,
|
|
l.before(o),
|
|
l.after(o),
|
|
n.Slice.empty,
|
|
);
|
|
if (s && s.slice.size < s.to - s.from) {
|
|
if (i) {
|
|
let t = e.tr.step(s);
|
|
t.setSelection(
|
|
c(d, "end")
|
|
? r.Selection.findFrom(
|
|
t.doc.resolve(t.mapping.map(a.pos, -1)),
|
|
-1,
|
|
)
|
|
: r.NodeSelection.create(t.doc, a.pos - d.nodeSize),
|
|
),
|
|
i(t.scrollIntoView());
|
|
}
|
|
return !0;
|
|
}
|
|
if (1 == o || l.node(o - 1).childCount > 1) break;
|
|
}
|
|
return (
|
|
!!d.isAtom &&
|
|
a.depth == l.depth - 1 &&
|
|
(i && i(e.tr.delete(a.pos - d.nodeSize, a.pos).scrollIntoView()), !0)
|
|
);
|
|
},
|
|
l = (e, t, n) => {
|
|
let r = o(e, n);
|
|
if (!r) return !1;
|
|
let i = p(r);
|
|
return !!i && d(e, i, t);
|
|
},
|
|
a = (e, t, n) => {
|
|
let r = u(e, n);
|
|
if (!r) return !1;
|
|
let i = g(r);
|
|
return !!i && d(e, i, t);
|
|
};
|
|
function d(e, i, o) {
|
|
let s = i.nodeBefore,
|
|
l = i.pos - 1;
|
|
for (; !s.isTextblock; l--) {
|
|
if (s.type.spec.isolating) return !1;
|
|
let e = s.lastChild;
|
|
if (!e) return !1;
|
|
s = e;
|
|
}
|
|
let a = i.nodeAfter,
|
|
d = i.pos + 1;
|
|
for (; !a.isTextblock; d++) {
|
|
if (a.type.spec.isolating) return !1;
|
|
let e = a.firstChild;
|
|
if (!e) return !1;
|
|
a = e;
|
|
}
|
|
let c = (0, t.replaceStep)(e.doc, l, d, n.Slice.empty);
|
|
if (
|
|
!c ||
|
|
c.from != l ||
|
|
(c instanceof t.ReplaceStep && c.slice.size >= d - l)
|
|
)
|
|
return !1;
|
|
if (o) {
|
|
let t = e.tr.step(c);
|
|
t.setSelection(r.TextSelection.create(t.doc, l)), o(t.scrollIntoView());
|
|
}
|
|
return !0;
|
|
}
|
|
function c(e, t, n = !1) {
|
|
for (let r = e; r; r = "start" == t ? r.firstChild : r.lastChild) {
|
|
if (r.isTextblock) return !0;
|
|
if (n && 1 != r.childCount) break;
|
|
}
|
|
return !1;
|
|
}
|
|
let h = (e, t, n) => {
|
|
let { $head: i, empty: o } = e.selection,
|
|
s = i;
|
|
if (!o) return !1;
|
|
if (i.parent.isTextblock) {
|
|
if (n ? !n.endOfTextblock("backward", e) : i.parentOffset > 0)
|
|
return !1;
|
|
s = p(i);
|
|
}
|
|
let l = s && s.nodeBefore;
|
|
return (
|
|
!!l &&
|
|
!!r.NodeSelection.isSelectable(l) &&
|
|
(t &&
|
|
t(
|
|
e.tr
|
|
.setSelection(r.NodeSelection.create(e.doc, s.pos - l.nodeSize))
|
|
.scrollIntoView(),
|
|
),
|
|
!0)
|
|
);
|
|
};
|
|
function p(e) {
|
|
if (!e.parent.type.spec.isolating)
|
|
for (let t = e.depth - 1; t >= 0; t--) {
|
|
if (e.index(t) > 0) return e.doc.resolve(e.before(t + 1));
|
|
if (e.node(t).type.spec.isolating) break;
|
|
}
|
|
return null;
|
|
}
|
|
function u(e, t) {
|
|
let { $cursor: n } = e.selection;
|
|
return n &&
|
|
(t
|
|
? t.endOfTextblock("forward", e)
|
|
: !(n.parentOffset < n.parent.content.size))
|
|
? n
|
|
: null;
|
|
}
|
|
let f = (e, i, o) => {
|
|
let s = u(e, o);
|
|
if (!s) return !1;
|
|
let l = g(s);
|
|
if (!l) return !1;
|
|
let a = l.nodeAfter;
|
|
if (T(e, l, i, 1)) return !0;
|
|
if (
|
|
0 == s.parent.content.size &&
|
|
(c(a, "start") || r.NodeSelection.isSelectable(a))
|
|
) {
|
|
let o = (0, t.replaceStep)(
|
|
e.doc,
|
|
s.before(),
|
|
s.after(),
|
|
n.Slice.empty,
|
|
);
|
|
if (o && o.slice.size < o.to - o.from) {
|
|
if (i) {
|
|
let t = e.tr.step(o);
|
|
t.setSelection(
|
|
c(a, "start")
|
|
? r.Selection.findFrom(t.doc.resolve(t.mapping.map(l.pos)), 1)
|
|
: r.NodeSelection.create(t.doc, t.mapping.map(l.pos)),
|
|
),
|
|
i(t.scrollIntoView());
|
|
}
|
|
return !0;
|
|
}
|
|
}
|
|
return (
|
|
!!a.isAtom &&
|
|
l.depth == s.depth - 1 &&
|
|
(i && i(e.tr.delete(l.pos, l.pos + a.nodeSize).scrollIntoView()), !0)
|
|
);
|
|
},
|
|
m = (e, t, n) => {
|
|
let { $head: i, empty: o } = e.selection,
|
|
s = i;
|
|
if (!o) return !1;
|
|
if (i.parent.isTextblock) {
|
|
if (
|
|
n
|
|
? !n.endOfTextblock("forward", e)
|
|
: i.parentOffset < i.parent.content.size
|
|
)
|
|
return !1;
|
|
s = g(i);
|
|
}
|
|
let l = s && s.nodeAfter;
|
|
return (
|
|
!!l &&
|
|
!!r.NodeSelection.isSelectable(l) &&
|
|
(t &&
|
|
t(
|
|
e.tr
|
|
.setSelection(r.NodeSelection.create(e.doc, s.pos))
|
|
.scrollIntoView(),
|
|
),
|
|
!0)
|
|
);
|
|
};
|
|
function g(e) {
|
|
if (!e.parent.type.spec.isolating)
|
|
for (let t = e.depth - 1; t >= 0; t--) {
|
|
let n = e.node(t);
|
|
if (e.index(t) + 1 < n.childCount)
|
|
return e.doc.resolve(e.after(t + 1));
|
|
if (n.type.spec.isolating) break;
|
|
}
|
|
return null;
|
|
}
|
|
let y = (e, n) => {
|
|
let i = e.selection,
|
|
o = i instanceof r.NodeSelection,
|
|
s;
|
|
if (o) {
|
|
if (i.node.isTextblock || !(0, t.canJoin)(e.doc, i.from)) return !1;
|
|
s = i.from;
|
|
} else if (null == (s = (0, t.joinPoint)(e.doc, i.from, -1))) return !1;
|
|
if (n) {
|
|
let t = e.tr.join(s);
|
|
o &&
|
|
t.setSelection(
|
|
r.NodeSelection.create(
|
|
t.doc,
|
|
s - e.doc.resolve(s).nodeBefore.nodeSize,
|
|
),
|
|
),
|
|
n(t.scrollIntoView());
|
|
}
|
|
return !0;
|
|
},
|
|
b = (e, n) => {
|
|
let i = e.selection,
|
|
o;
|
|
if (i instanceof r.NodeSelection) {
|
|
if (i.node.isTextblock || !(0, t.canJoin)(e.doc, i.to)) return !1;
|
|
o = i.to;
|
|
} else if (null == (o = (0, t.joinPoint)(e.doc, i.to, 1))) return !1;
|
|
return n && n(e.tr.join(o).scrollIntoView()), !0;
|
|
},
|
|
k = (e, n) => {
|
|
let { $from: r, $to: i } = e.selection,
|
|
o = r.blockRange(i),
|
|
s = o && (0, t.liftTarget)(o);
|
|
return null != s && (n && n(e.tr.lift(o, s).scrollIntoView()), !0);
|
|
},
|
|
v = (e, t) => {
|
|
let { $head: n, $anchor: r } = e.selection;
|
|
return (
|
|
!!n.parent.type.spec.code &&
|
|
!!n.sameParent(r) &&
|
|
(t && t(e.tr.insertText("\n").scrollIntoView()), !0)
|
|
);
|
|
};
|
|
function w(e) {
|
|
for (let t = 0; t < e.edgeCount; t++) {
|
|
let { type: n } = e.edge(t);
|
|
if (n.isTextblock && !n.hasRequiredAttrs()) return n;
|
|
}
|
|
return null;
|
|
}
|
|
let S = (e, t) => {
|
|
let { $head: n, $anchor: i } = e.selection;
|
|
if (!n.parent.type.spec.code || !n.sameParent(i)) return !1;
|
|
let o = n.node(-1),
|
|
s = n.indexAfter(-1),
|
|
l = w(o.contentMatchAt(s));
|
|
if (!l || !o.canReplaceWith(s, s, l)) return !1;
|
|
if (t) {
|
|
let i = n.after(),
|
|
o = e.tr.replaceWith(i, i, l.createAndFill());
|
|
o.setSelection(r.Selection.near(o.doc.resolve(i), 1)),
|
|
t(o.scrollIntoView());
|
|
}
|
|
return !0;
|
|
},
|
|
x = (e, t) => {
|
|
let n = e.selection,
|
|
{ $from: i, $to: o } = n;
|
|
if (
|
|
n instanceof r.AllSelection ||
|
|
i.parent.inlineContent ||
|
|
o.parent.inlineContent
|
|
)
|
|
return !1;
|
|
let s = w(o.parent.contentMatchAt(o.indexAfter()));
|
|
if (!s || !s.isTextblock) return !1;
|
|
if (t) {
|
|
let n = (!i.parentOffset && o.index() < o.parent.childCount ? i : o)
|
|
.pos,
|
|
l = e.tr.insert(n, s.createAndFill());
|
|
l.setSelection(r.TextSelection.create(l.doc, n + 1)),
|
|
t(l.scrollIntoView());
|
|
}
|
|
return !0;
|
|
},
|
|
M = (e, n) => {
|
|
let { $cursor: r } = e.selection;
|
|
if (!r || r.parent.content.size) return !1;
|
|
if (r.depth > 1 && r.after() != r.end(-1)) {
|
|
let i = r.before();
|
|
if ((0, t.canSplit)(e.doc, i))
|
|
return n && n(e.tr.split(i).scrollIntoView()), !0;
|
|
}
|
|
let i = r.blockRange(),
|
|
o = i && (0, t.liftTarget)(i);
|
|
return null != o && (n && n(e.tr.lift(i, o).scrollIntoView()), !0);
|
|
},
|
|
C = (e, t) => {
|
|
let { $from: n, to: i } = e.selection,
|
|
o,
|
|
s = n.sharedDepth(i);
|
|
return (
|
|
0 != s &&
|
|
((o = n.before(s)),
|
|
t && t(e.tr.setSelection(r.NodeSelection.create(e.doc, o))),
|
|
!0)
|
|
);
|
|
};
|
|
function T(e, i, o, s) {
|
|
let l,
|
|
a,
|
|
d,
|
|
h = i.nodeBefore,
|
|
p = i.nodeAfter,
|
|
u,
|
|
f,
|
|
m = h.type.spec.isolating || p.type.spec.isolating;
|
|
if (
|
|
!m &&
|
|
((l = i.nodeBefore),
|
|
(a = i.nodeAfter),
|
|
(d = i.index()),
|
|
l &&
|
|
a &&
|
|
l.type.compatibleContent(a.type) &&
|
|
(!l.content.size && i.parent.canReplace(d - 1, d)
|
|
? (o && o(e.tr.delete(i.pos - l.nodeSize, i.pos).scrollIntoView()),
|
|
!0)
|
|
: !!i.parent.canReplace(d, d + 1) &&
|
|
!!(a.isTextblock || (0, t.canJoin)(e.doc, i.pos)) &&
|
|
(o && o(e.tr.join(i.pos).scrollIntoView()), !0)))
|
|
)
|
|
return !0;
|
|
let g = !m && i.parent.canReplace(i.index(), i.index() + 1);
|
|
if (
|
|
g &&
|
|
(u = (f = h.contentMatchAt(h.childCount)).findWrapping(p.type)) &&
|
|
f.matchType(u[0] || p.type).validEnd
|
|
) {
|
|
if (o) {
|
|
let r = i.pos + p.nodeSize,
|
|
s = n.Fragment.empty;
|
|
for (let e = u.length - 1; e >= 0; e--)
|
|
s = n.Fragment.from(u[e].create(null, s));
|
|
s = n.Fragment.from(h.copy(s));
|
|
let l = e.tr.step(
|
|
new t.ReplaceAroundStep(
|
|
i.pos - 1,
|
|
r,
|
|
i.pos,
|
|
r,
|
|
new n.Slice(s, 1, 0),
|
|
u.length,
|
|
!0,
|
|
),
|
|
),
|
|
a = l.doc.resolve(r + 2 * u.length);
|
|
a.nodeAfter &&
|
|
a.nodeAfter.type == h.type &&
|
|
(0, t.canJoin)(l.doc, a.pos) &&
|
|
l.join(a.pos),
|
|
o(l.scrollIntoView());
|
|
}
|
|
return !0;
|
|
}
|
|
let y =
|
|
p.type.spec.isolating || (s > 0 && m)
|
|
? null
|
|
: r.Selection.findFrom(i, 1),
|
|
b = y && y.$from.blockRange(y.$to),
|
|
k = b && (0, t.liftTarget)(b);
|
|
if (null != k && k >= i.depth)
|
|
return o && o(e.tr.lift(b, k).scrollIntoView()), !0;
|
|
if (g && c(p, "start", !0) && c(h, "end")) {
|
|
let r = h,
|
|
s = [];
|
|
for (; s.push(r), !r.isTextblock; ) r = r.lastChild;
|
|
let l = p,
|
|
a = 1;
|
|
for (; !l.isTextblock; l = l.firstChild) a++;
|
|
if (r.canReplace(r.childCount, r.childCount, l.content)) {
|
|
if (o) {
|
|
let r = n.Fragment.empty;
|
|
for (let e = s.length - 1; e >= 0; e--)
|
|
r = n.Fragment.from(s[e].copy(r));
|
|
o(
|
|
e.tr
|
|
.step(
|
|
new t.ReplaceAroundStep(
|
|
i.pos - s.length,
|
|
i.pos + p.nodeSize,
|
|
i.pos + a,
|
|
i.pos + p.nodeSize - a,
|
|
new n.Slice(r, s.length, 0),
|
|
0,
|
|
!0,
|
|
),
|
|
)
|
|
.scrollIntoView(),
|
|
);
|
|
}
|
|
return !0;
|
|
}
|
|
}
|
|
return !1;
|
|
}
|
|
function N(e) {
|
|
return function (t, n) {
|
|
let i = t.selection,
|
|
o = e < 0 ? i.$from : i.$to,
|
|
s = o.depth;
|
|
for (; o.node(s).isInline; ) {
|
|
if (!s) return !1;
|
|
s--;
|
|
}
|
|
return (
|
|
!!o.node(s).isTextblock &&
|
|
(n &&
|
|
n(
|
|
t.tr.setSelection(
|
|
r.TextSelection.create(t.doc, e < 0 ? o.start(s) : o.end(s)),
|
|
),
|
|
),
|
|
!0)
|
|
);
|
|
};
|
|
}
|
|
let E = N(-1),
|
|
O = N(1);
|
|
function A(e, n = null) {
|
|
return function (r, i) {
|
|
let { $from: o, $to: s } = r.selection,
|
|
l = o.blockRange(s),
|
|
a = l && (0, t.findWrapping)(l, e, n);
|
|
return !!a && (i && i(r.tr.wrap(l, a).scrollIntoView()), !0);
|
|
};
|
|
}
|
|
function D(e, t = null) {
|
|
return function (n, r) {
|
|
let i = !1;
|
|
for (let r = 0; r < n.selection.ranges.length && !i; r++) {
|
|
let {
|
|
$from: { pos: o },
|
|
$to: { pos: s },
|
|
} = n.selection.ranges[r];
|
|
n.doc.nodesBetween(o, s, (r, o) => {
|
|
if (i) return !1;
|
|
if (!(!r.isTextblock || r.hasMarkup(e, t)))
|
|
if (r.type == e) i = !0;
|
|
else {
|
|
let t = n.doc.resolve(o),
|
|
r = t.index();
|
|
i = t.parent.canReplaceWith(r, r + 1, e);
|
|
}
|
|
});
|
|
}
|
|
if (!i) return !1;
|
|
if (r) {
|
|
let i = n.tr;
|
|
for (let r = 0; r < n.selection.ranges.length; r++) {
|
|
let {
|
|
$from: { pos: o },
|
|
$to: { pos: s },
|
|
} = n.selection.ranges[r];
|
|
i.setBlockType(o, s, e, t);
|
|
}
|
|
r(i.scrollIntoView());
|
|
}
|
|
return !0;
|
|
};
|
|
}
|
|
function R(...e) {
|
|
return function (t, n, r) {
|
|
for (let i = 0; i < e.length; i++) if (e[i](t, n, r)) return !0;
|
|
return !1;
|
|
};
|
|
}
|
|
let I = R(i, s, h),
|
|
P = R(i, f, m),
|
|
L = {
|
|
Enter: R(v, x, M, (e, n) => {
|
|
let { $from: i, $to: o } = e.selection;
|
|
if (
|
|
e.selection instanceof r.NodeSelection &&
|
|
e.selection.node.isBlock
|
|
)
|
|
return (
|
|
!!i.parentOffset &&
|
|
!!(0, t.canSplit)(e.doc, i.pos) &&
|
|
(n && n(e.tr.split(i.pos).scrollIntoView()), !0)
|
|
);
|
|
if (!i.depth) return !1;
|
|
let s = [],
|
|
l,
|
|
a,
|
|
d = !1,
|
|
c = !1;
|
|
for (let e = i.depth; ; e--) {
|
|
if (i.node(e).isBlock) {
|
|
let t;
|
|
(d = i.end(e) == i.pos + (i.depth - e)),
|
|
(c = i.start(e) == i.pos - (i.depth - e)),
|
|
(a = w(i.node(e - 1).contentMatchAt(i.indexAfter(e - 1))));
|
|
s.unshift(t || (d && a ? { type: a } : null)), (l = e);
|
|
break;
|
|
}
|
|
if (1 == e) return !1;
|
|
s.unshift(null);
|
|
}
|
|
let h = e.tr;
|
|
(e.selection instanceof r.TextSelection ||
|
|
e.selection instanceof r.AllSelection) &&
|
|
h.deleteSelection();
|
|
let p = h.mapping.map(i.pos),
|
|
u = (0, t.canSplit)(h.doc, p, s.length, s);
|
|
if (
|
|
(u ||
|
|
((s[0] = a ? { type: a } : null),
|
|
(u = (0, t.canSplit)(h.doc, p, s.length, s))),
|
|
!u)
|
|
)
|
|
return !1;
|
|
if ((h.split(p, s.length, s), !d && c && i.node(l).type != a)) {
|
|
let e = h.mapping.map(i.before(l)),
|
|
t = h.doc.resolve(e);
|
|
a &&
|
|
i.node(l - 1).canReplaceWith(t.index(), t.index() + 1, a) &&
|
|
h.setNodeMarkup(h.mapping.map(i.before(l)), a);
|
|
}
|
|
return n && n(h.scrollIntoView()), !0;
|
|
}),
|
|
"Mod-Enter": S,
|
|
Backspace: I,
|
|
"Mod-Backspace": I,
|
|
"Shift-Backspace": I,
|
|
Delete: P,
|
|
"Mod-Delete": P,
|
|
"Mod-a": (e, t) => (
|
|
t && t(e.tr.setSelection(new r.AllSelection(e.doc))), !0
|
|
),
|
|
},
|
|
z = {
|
|
"Ctrl-h": L.Backspace,
|
|
"Alt-Backspace": L["Mod-Backspace"],
|
|
"Ctrl-d": L.Delete,
|
|
"Ctrl-Alt-Backspace": L["Mod-Delete"],
|
|
"Alt-Delete": L["Mod-Delete"],
|
|
"Alt-d": L["Mod-Delete"],
|
|
"Ctrl-a": E,
|
|
"Ctrl-e": O,
|
|
};
|
|
for (let e in L) z[e] = L[e];
|
|
"u" > typeof navigator
|
|
? /Mac|iP(hone|[oa]d)/.test(navigator.platform)
|
|
: "u" > typeof os && os.platform && os.platform(),
|
|
e.s([
|
|
"createParagraphNear",
|
|
() => x,
|
|
"deleteSelection",
|
|
() => i,
|
|
"exitCode",
|
|
() => S,
|
|
"joinBackward",
|
|
() => s,
|
|
"joinDown",
|
|
() => b,
|
|
"joinForward",
|
|
() => f,
|
|
"joinTextblockBackward",
|
|
() => l,
|
|
"joinTextblockForward",
|
|
() => a,
|
|
"joinUp",
|
|
() => y,
|
|
"lift",
|
|
() => k,
|
|
"liftEmptyBlock",
|
|
() => M,
|
|
"newlineInCode",
|
|
() => v,
|
|
"selectNodeBackward",
|
|
() => h,
|
|
"selectNodeForward",
|
|
() => m,
|
|
"selectParentNode",
|
|
() => C,
|
|
"selectTextblockEnd",
|
|
() => O,
|
|
"selectTextblockStart",
|
|
() => E,
|
|
"setBlockType",
|
|
() => D,
|
|
"wrapIn",
|
|
() => A,
|
|
]);
|
|
};
|
|
|
|
export default moduleFactory;
|