@mache-hangar/lunar-editor-react 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fragment as
|
|
1
|
+
import { Fragment as C, closeHistory as k, PluginKey as Y, TextSelection as E, NodeSelection as Q, Plugin as Z, DecorationSet as tt, Decoration as et } from "@mache-hangar/lunar-editor-core/pm";
|
|
2
2
|
import { compileLunarSourceTransaction as ot } from "@mache-hangar/lunar-editor-core/source/compile-transaction";
|
|
3
3
|
import { getLunarSourceState as z } from "@mache-hangar/lunar-editor-core/source/source-map-plugin";
|
|
4
4
|
import { getSourceMutationSteps as st } from "@mache-hangar/lunar-editor-core/source/source-mutation-step";
|
|
@@ -114,14 +114,14 @@ function X(s, t, e) {
|
|
|
114
114
|
if (d.length) {
|
|
115
115
|
const c = d[d.length - 1];
|
|
116
116
|
d[d.length - 1] = c.copy(
|
|
117
|
-
c.content.append(
|
|
117
|
+
c.content.append(C.fromArray(a))
|
|
118
118
|
);
|
|
119
119
|
} else d.push(i.create(null, a));
|
|
120
120
|
}
|
|
121
121
|
const y = r[0]?.position ?? l, A = r[r.length - 1], m = A ? A.position + A.node.nodeSize : y, g = s.state.tr.replaceWith(
|
|
122
122
|
y,
|
|
123
123
|
m,
|
|
124
|
-
|
|
124
|
+
C.fromArray(d)
|
|
125
125
|
);
|
|
126
126
|
g.setNodeMarkup(t, void 0, {
|
|
127
127
|
...o.attrs,
|
|
@@ -419,7 +419,7 @@ function at(s, t, e, o) {
|
|
|
419
419
|
const i = e.filter((u) => u.row === h).sort((u, f) => u.col - f.col).map((u) => {
|
|
420
420
|
const f = { ...u.node.attrs.htmlAttrs };
|
|
421
421
|
return u.rows > 1 ? f.rowspan = String(u.rows) : delete f.rowspan, u.cols > 1 ? f.colspan = String(u.cols) : delete f.colspan, JSON.stringify(f) === JSON.stringify(u.node.attrs.htmlAttrs || {}) ? u.node : u.node.type.create({ ...u.node.attrs, htmlAttrs: f }, u.node.content);
|
|
422
|
-
}), d =
|
|
422
|
+
}), d = C.fromArray(i);
|
|
423
423
|
return l.node.content.eq(d) ? l.node : l.node.copy(d);
|
|
424
424
|
}), r = [];
|
|
425
425
|
return s.node.forEach((l, h, i) => {
|
|
@@ -433,9 +433,9 @@ function at(s, t, e, o) {
|
|
|
433
433
|
);
|
|
434
434
|
} else if (["table_head", "table_body", "table_foot"].includes(l.type.name)) {
|
|
435
435
|
const d = n.filter((u, f) => t[f].section === i);
|
|
436
|
-
d.length && r.push(l.copy(
|
|
436
|
+
d.length && r.push(l.copy(C.fromArray(d)));
|
|
437
437
|
} else l.type.name !== "table_row" && r.push(l);
|
|
438
|
-
}), r.push(...n.filter((l, h) => t[h].section === -1)), s.node.copy(
|
|
438
|
+
}), r.push(...n.filter((l, h) => t[h].section === -1)), s.node.copy(C.fromArray(r));
|
|
439
439
|
}
|
|
440
440
|
function q(s, t, e, o) {
|
|
441
441
|
const n = [];
|
|
@@ -514,7 +514,7 @@ function V(s, t) {
|
|
|
514
514
|
return e && !st(o.steps).length ? !1 : (s.dispatch(o.scrollIntoView()), s.dispatch(k(s.state.tr)), s.focus(), !0);
|
|
515
515
|
}
|
|
516
516
|
function P(s, t, e) {
|
|
517
|
-
const o = s.state.doc.resolve(e), n = o.parent.canReplace(o.index(), o.index() + 1) ?
|
|
517
|
+
const o = s.state.doc.resolve(e), n = o.parent.canReplace(o.index(), o.index() + 1) ? C.empty : C.from(s.state.schema.nodes.paragraph.createAndFill());
|
|
518
518
|
return V(s, s.state.tr.replaceWith(e, e + t.nodeSize, n));
|
|
519
519
|
}
|
|
520
520
|
function G(s, t, e) {
|
|
@@ -555,7 +555,7 @@ function $(s, t, e) {
|
|
|
555
555
|
let v = -1;
|
|
556
556
|
return D.doc.descendants((x, S) => {
|
|
557
557
|
v < 0 && x === w && (v = S);
|
|
558
|
-
}), v >= 0 && D.setSelection(
|
|
558
|
+
}), v >= 0 && D.setSelection(E.near(D.doc.resolve(v + 4))), V(s, D);
|
|
559
559
|
}
|
|
560
560
|
const o = _(s.state);
|
|
561
561
|
if (!o) return !1;
|
|
@@ -591,7 +591,7 @@ function $(s, t, e) {
|
|
|
591
591
|
}), i = q(n, r.left, a, !0);
|
|
592
592
|
} else if (t.action === "merge") {
|
|
593
593
|
if (!O(s).canMerge) return !1;
|
|
594
|
-
const a = l.filter(f), c = a[0], p = a.reduce((b, w) => b.append(w.node.content),
|
|
594
|
+
const a = l.filter(f), c = a[0], p = a.reduce((b, w) => b.append(w.node.content), C.empty);
|
|
595
595
|
c.node = c.node.copy(p), c.rows = r.bottom - r.top, c.cols = r.right - r.left, l = l.filter((b) => b === c || !a.includes(b));
|
|
596
596
|
} else if (t.action === "split")
|
|
597
597
|
for (const a of [...l].filter(f)) {
|
|
@@ -612,7 +612,7 @@ function $(s, t, e) {
|
|
|
612
612
|
} else if (t.action === "clear_cells") {
|
|
613
613
|
let a = !0;
|
|
614
614
|
for (const c of l.filter(f))
|
|
615
|
-
c.node = c.node.copy(
|
|
615
|
+
c.node = c.node.copy(C.from(s.state.schema.nodes.paragraph.create(null, a && e ? s.state.schema.text(e) : void 0))), a = !1;
|
|
616
616
|
} else if (t.action === "cell_style") {
|
|
617
617
|
const a = {};
|
|
618
618
|
if (t.textAlign && ["left", "center", "right", "justify"].includes(t.textAlign) && (a["text-align"] = t.textAlign), t.verticalAlign && ["top", "middle", "bottom"].includes(t.verticalAlign) && (a["vertical-align"] = t.verticalAlign), t.backgroundColor && /^(#[\da-f]{6}|transparent)$/i.test(t.backgroundColor) && (a["background-color"] = t.backgroundColor), !Object.keys(a).length) return !1;
|
|
@@ -623,7 +623,7 @@ function $(s, t, e) {
|
|
|
623
623
|
const a = [];
|
|
624
624
|
y.forEach((c) => {
|
|
625
625
|
c.type.name !== "caption" && a.push(c);
|
|
626
|
-
}), O(s).caption || a.unshift(s.state.schema.nodes.caption.createAndFill(null, s.state.schema.nodes.paragraph.create(null, s.state.schema.text("Table caption")))), y = y.copy(
|
|
626
|
+
}), O(s).caption || a.unshift(s.state.schema.nodes.caption.createAndFill(null, s.state.schema.nodes.paragraph.create(null, s.state.schema.text("Table caption")))), y = y.copy(C.fromArray(a));
|
|
627
627
|
} else if (t.action === "table_style") {
|
|
628
628
|
const a = {};
|
|
629
629
|
if (t.align && ["left", "center", "right"].includes(t.align) && (a["margin-left"] = t.align === "left" ? "0" : "auto", a["margin-right"] = t.align === "right" ? "0" : "auto", a.float = "none"), t.width && ["25%", "50%", "75%", "100%"].includes(t.width) && (a.width = t.width), !Object.keys(a).length) return !1;
|
|
@@ -633,7 +633,7 @@ function $(s, t, e) {
|
|
|
633
633
|
const A = s.state.tr.replaceWith(n.pos, n.pos + n.node.nodeSize, y), m = W(y, n.pos);
|
|
634
634
|
if (!m) return !1;
|
|
635
635
|
const g = m?.matrix[Math.min(d, m.rows.length - 1)]?.[Math.min(u, m.width - 1)];
|
|
636
|
-
if (g && A.setSelection(
|
|
636
|
+
if (g && A.setSelection(E.near(A.doc.resolve(g.pos + 1))), o.cells.length > 1 && ["cell_style", "table_style", "header_row", "header_column", "caption"].includes(t.action)) {
|
|
637
637
|
const a = m.matrix[r.top][r.left], c = m.matrix[r.bottom - 1][r.right - 1];
|
|
638
638
|
A.setMeta(M, { anchor: a.pos + 1, head: c.pos + 1 });
|
|
639
639
|
}
|
|
@@ -648,9 +648,18 @@ function J(s, t) {
|
|
|
648
648
|
const o = s.posAtDOM(e, 0), n = T(s.state.doc.resolve(o)), r = n && W(n.node, n.pos), l = r && L(r, o), h = e.closest("table");
|
|
649
649
|
return r && l && h ? { grid: r, cell: l, tableElement: h } : void 0;
|
|
650
650
|
}
|
|
651
|
-
function ht(s, t
|
|
651
|
+
function ht(s, t) {
|
|
652
|
+
let e;
|
|
653
|
+
return s.node.descendants((o, n) => {
|
|
654
|
+
if (o.isAtom) return !1;
|
|
655
|
+
if (!o.inlineContent) return;
|
|
656
|
+
const r = s.pos + n + 2, l = Math.max(r, Math.min(t, r + o.content.size));
|
|
657
|
+
return (e === void 0 || Math.abs(l - t) < Math.abs(e - t) || Math.abs(l - t) === Math.abs(e - t) && l > e) && (e = l), !1;
|
|
658
|
+
}), e;
|
|
659
|
+
}
|
|
660
|
+
function dt(s, t, e) {
|
|
652
661
|
const o = s.state.doc.resolve(t);
|
|
653
|
-
if (e >= 3 && o.parent.inlineContent) return
|
|
662
|
+
if (e >= 3 && o.parent.inlineContent) return E.create(s.state.doc, o.start(), o.end());
|
|
654
663
|
if (e === 2 && o.parent.inlineContent) {
|
|
655
664
|
const n = o.parent.textBetween(0, o.parent.content.size, "", ""), r = o.parent.textBetween(0, o.parentOffset, "", "").length, l = [...new Intl.Segmenter(void 0, { granularity: "word" }).segment(n)].find((h) => r >= h.index && r < h.index + h.segment.length);
|
|
656
665
|
if (l) {
|
|
@@ -661,12 +670,12 @@ function ht(s, t, e) {
|
|
|
661
670
|
i === void 0 && l.index < h + y && (i = o.start() + f + Math.max(0, l.index - h));
|
|
662
671
|
const A = l.index + l.segment.length;
|
|
663
672
|
d === void 0 && A <= h + y && (d = o.start() + f + Math.max(0, A - h)), h += y;
|
|
664
|
-
}), i !== void 0 && d !== void 0) return
|
|
673
|
+
}), i !== void 0 && d !== void 0) return E.create(s.state.doc, i, d);
|
|
665
674
|
}
|
|
666
675
|
}
|
|
667
|
-
return
|
|
676
|
+
return E.create(s.state.doc, t);
|
|
668
677
|
}
|
|
669
|
-
class
|
|
678
|
+
class ut {
|
|
670
679
|
drag;
|
|
671
680
|
get active() {
|
|
672
681
|
return !!this.drag?.view.editable;
|
|
@@ -675,7 +684,9 @@ class dt {
|
|
|
675
684
|
if (this.cancel(), !t.editable || e.button !== 0 || e.shiftKey || e.ctrlKey || e.metaKey || e.altKey) return !1;
|
|
676
685
|
const o = J(t, e.target);
|
|
677
686
|
if (!o) return !1;
|
|
678
|
-
const n = t.posAtCoords({ left: e.clientX, top: e.clientY })?.pos, r = n !== void 0 && L(o.grid, n)?.pos === o.cell.pos ? n : o.cell.pos + 1
|
|
687
|
+
const n = t.posAtCoords({ left: e.clientX, top: e.clientY })?.pos, r = ht(o.cell, n !== void 0 && L(o.grid, n)?.pos === o.cell.pos ? n : o.cell.pos + 1);
|
|
688
|
+
if (r === void 0) return !1;
|
|
689
|
+
const l = dt(t, r, e.detail);
|
|
679
690
|
this.drag = { view: t, doc: t.state.doc, ...o, anchor: o.cell, head: o.cell, selecting: !1, textFrom: l.from, textTo: l.to }, e.preventDefault(), t.dispatch(t.state.tr.setSelection(l).setMeta(M, { anchor: o.cell.pos + 1, head: o.cell.pos + 1, dragging: !0 })), t.focus();
|
|
680
691
|
const h = t.dom.ownerDocument;
|
|
681
692
|
return h.addEventListener("mousemove", this.move, !0), h.addEventListener("mouseup", this.end, !0), h.defaultView?.addEventListener("blur", this.cancel), !0;
|
|
@@ -710,14 +721,14 @@ class dt {
|
|
|
710
721
|
let d;
|
|
711
722
|
if (e.selecting) {
|
|
712
723
|
const f = i.pos <= l.cell.pos;
|
|
713
|
-
d =
|
|
724
|
+
d = E.between(
|
|
714
725
|
h.state.doc.resolve(i.pos + (f ? 1 : i.node.nodeSize - 1)),
|
|
715
726
|
h.state.doc.resolve(l.cell.pos + (f ? l.cell.node.nodeSize - 1 : 1))
|
|
716
727
|
);
|
|
717
728
|
} else {
|
|
718
729
|
const f = h.posAtCoords(o)?.pos;
|
|
719
730
|
if (f === void 0 || L(e.grid, f)?.pos !== i.pos) return;
|
|
720
|
-
d =
|
|
731
|
+
d = E.between(h.state.doc.resolve(f < e.textFrom ? e.textTo : e.textFrom), h.state.doc.resolve(f));
|
|
721
732
|
}
|
|
722
733
|
const u = M.getState(h.state);
|
|
723
734
|
d.eq(h.state.selection) && u?.head === l.cell.pos + 1 || h.dispatch(h.state.tr.setSelection(d).setMeta(M, { anchor: i.pos + 1, head: l.cell.pos + 1, dragging: !0 }));
|
|
@@ -738,10 +749,10 @@ class dt {
|
|
|
738
749
|
};
|
|
739
750
|
}
|
|
740
751
|
function U(s, t) {
|
|
741
|
-
s.dispatch(s.state.tr.setSelection(
|
|
752
|
+
s.dispatch(s.state.tr.setSelection(E.near(s.state.doc.resolve(t + 1)))), s.focus();
|
|
742
753
|
}
|
|
743
|
-
function
|
|
744
|
-
const t = new
|
|
754
|
+
function ft(s) {
|
|
755
|
+
const t = new ut();
|
|
745
756
|
return new Z({
|
|
746
757
|
key: M,
|
|
747
758
|
state: {
|
|
@@ -766,7 +777,7 @@ function ut(s) {
|
|
|
766
777
|
handleDOMEvents: {
|
|
767
778
|
keydown(e, o) {
|
|
768
779
|
t.cancel();
|
|
769
|
-
const n =
|
|
780
|
+
const n = pt(e, o);
|
|
770
781
|
return n && o.preventDefault(), n;
|
|
771
782
|
},
|
|
772
783
|
mousedown(e, o) {
|
|
@@ -802,12 +813,12 @@ function ut(s) {
|
|
|
802
813
|
}
|
|
803
814
|
});
|
|
804
815
|
}
|
|
805
|
-
function
|
|
816
|
+
function pt(s, t) {
|
|
806
817
|
if (!s.editable) return !1;
|
|
807
818
|
const e = _(s.state);
|
|
808
819
|
if (!e?.grid || !e.rect) return !1;
|
|
809
820
|
if (t.key === "Escape" && (M.getState(s.state) || e.cells.length > 1))
|
|
810
|
-
return s.dispatch(s.state.tr.setSelection(
|
|
821
|
+
return s.dispatch(s.state.tr.setSelection(E.near(s.state.selection.$head)).setMeta(M, null)), !0;
|
|
811
822
|
if (t.ctrlKey || t.metaKey || t.altKey) return !1;
|
|
812
823
|
if (["Backspace", "Delete"].includes(t.key) && e.cells.length > 1)
|
|
813
824
|
return $(s, { action: "clear_cells" });
|
|
@@ -822,16 +833,16 @@ function ft(s, t) {
|
|
|
822
833
|
const l = _(s.state)?.grid, h = l?.matrix[l.rows.length - 1]?.[0];
|
|
823
834
|
return h && U(s, h.pos), !0;
|
|
824
835
|
}
|
|
825
|
-
function
|
|
836
|
+
function wt(s = {}) {
|
|
826
837
|
return {
|
|
827
838
|
name: "table-view",
|
|
828
|
-
plugins: () => [
|
|
839
|
+
plugins: () => [ft(s)],
|
|
829
840
|
nodeViews: { table: (t, e, o) => new rt(t, e, o) }
|
|
830
841
|
};
|
|
831
842
|
}
|
|
832
843
|
export {
|
|
833
844
|
B as EMPTY_TABLE_STATE,
|
|
834
|
-
|
|
845
|
+
wt as createTableExtension,
|
|
835
846
|
O as getTableState,
|
|
836
847
|
$ as runTableCommand
|
|
837
848
|
};
|