@mache-hangar/lunar-editor-react 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +65 -2
- package/THIRD_PARTY_NOTICES.md +58 -0
- package/dist/code-editor-Cq33u9jq.cjs +2 -0
- package/dist/code-editor-Cq33u9jq.cjs.map +1 -0
- package/dist/code-editor-um45ekRh.js +78 -0
- package/dist/code-editor-um45ekRh.js.map +1 -0
- package/dist/code-editor.cjs +2 -0
- package/dist/code-editor.cjs.map +1 -0
- package/dist/code-editor.js +8 -0
- package/dist/code-editor.js.map +1 -0
- package/dist/extensions/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Main-Bold.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Main-Italic.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Main-Regular.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Math-Italic.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Script-Regular.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- package/dist/extensions/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- package/dist/extensions/math/index.cjs +2 -0
- package/dist/extensions/math/index.cjs.map +1 -0
- package/dist/extensions/math/index.js +285 -0
- package/dist/extensions/math/index.js.map +1 -0
- package/dist/extensions/math.css +1 -0
- package/dist/extensions/table/index.cjs +2 -0
- package/dist/extensions/table/index.cjs.map +1 -0
- package/dist/extensions/table/index.js +356 -0
- package/dist/extensions/table/index.js.map +1 -0
- package/dist/extensions/table.css +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/rich-editor.cjs +2 -0
- package/dist/rich-editor.cjs.map +1 -0
- package/dist/rich-editor.js +67 -0
- package/dist/rich-editor.js.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/types/code-editor-types.d.ts +5 -0
- package/dist/types/code-editor.d.ts +6 -0
- package/dist/types/controller-hooks.d.ts +6 -0
- package/dist/types/extensions/math/index.d.ts +3 -0
- package/dist/types/extensions/math/math-input.d.ts +4 -0
- package/dist/types/extensions/math/math-node-view.d.ts +27 -0
- package/dist/types/extensions/math/nodes.d.ts +9 -0
- package/dist/types/extensions/table/column-layout.d.ts +9 -0
- package/dist/types/extensions/table/index.d.ts +2 -0
- package/dist/types/extensions/table/resize-transaction.d.ts +4 -0
- package/dist/types/extensions/table/table-node-view.d.ts +30 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/rich-editor.d.ts +25 -0
- package/package.json +77 -3
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { Fragment as x, closeHistory as N } from "@mache-hangar/lunar-editor-core/pm";
|
|
2
|
+
const L = 48;
|
|
3
|
+
function A(i) {
|
|
4
|
+
const t = Array.from(i.rows), e = [], s = [], n = i.ownerDocument.defaultView.getComputedStyle(i).direction === "rtl", u = n ? -1 : 1;
|
|
5
|
+
let a = 0;
|
|
6
|
+
const m = (h, d) => (s[h] ??= []).push(d), r = /* @__PURE__ */ new Map();
|
|
7
|
+
t.forEach((h, d) => r.set(h.parentElement, d + 1)), t.forEach((h, d) => {
|
|
8
|
+
let o = 0;
|
|
9
|
+
for (const c of Array.from(h.cells)) {
|
|
10
|
+
for (; e[d]?.[o]; ) o++;
|
|
11
|
+
const b = c.colSpan, M = r.get(h.parentElement), v = c.rowSpan || M - d;
|
|
12
|
+
for (let y = d; y < Math.min(d + v, M); y++)
|
|
13
|
+
for (let D = o; D < o + b; D++)
|
|
14
|
+
(e[y] ??= [])[D] = !0;
|
|
15
|
+
const w = c.getBoundingClientRect();
|
|
16
|
+
m(o, n ? w.right : w.left), m(o + b, n ? w.left : w.right), o += b, a = Math.max(a, o);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
let l = 0;
|
|
20
|
+
for (const h of Array.from(i.children).filter(
|
|
21
|
+
(d) => d.tagName === "COLGROUP"
|
|
22
|
+
)) {
|
|
23
|
+
const d = Array.from(h.children);
|
|
24
|
+
for (const o of d.length ? d : [h]) {
|
|
25
|
+
const c = o.getBoundingClientRect();
|
|
26
|
+
c.width > 0 && (m(l, n ? c.right : c.left), m(l + o.span, n ? c.left : c.right)), l += o.span;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (a = Math.max(a, l), a < 2 || i.getBoundingClientRect().width <= 0) return;
|
|
30
|
+
const g = i.getBoundingClientRect();
|
|
31
|
+
s[0] ??= [n ? g.right : g.left], s[a] ??= [n ? g.left : g.right];
|
|
32
|
+
const f = Array.from({ length: a + 1 }, (h, d) => {
|
|
33
|
+
const o = s[d];
|
|
34
|
+
return o ? o.reduce((c, b) => c + b, 0) / o.length : NaN;
|
|
35
|
+
});
|
|
36
|
+
let p = 0;
|
|
37
|
+
for (; p < a; ) {
|
|
38
|
+
let h = p + 1;
|
|
39
|
+
for (; h < a && !Number.isFinite(f[h]); ) h++;
|
|
40
|
+
for (let d = p + 1; d < h; d++)
|
|
41
|
+
f[d] = f[p] + (f[h] - f[p]) * (d - p) / (h - p);
|
|
42
|
+
p = h;
|
|
43
|
+
}
|
|
44
|
+
const E = f.slice(1).map((h, d) => Math.abs(h - f[d]));
|
|
45
|
+
return E.every((h) => Number.isFinite(h) && h > 0) ? { widths: E, boundaries: f, direction: u } : void 0;
|
|
46
|
+
}
|
|
47
|
+
function R(i, t, e) {
|
|
48
|
+
const s = [...i], n = Math.min(L, i[t]), u = Math.min(L, i[t + 1]), a = Math.max(
|
|
49
|
+
n - i[t],
|
|
50
|
+
Math.min(e, i[t + 1] - u)
|
|
51
|
+
);
|
|
52
|
+
return s[t] += a, s[t + 1] -= a, s;
|
|
53
|
+
}
|
|
54
|
+
function O(i, t, e, s = !1) {
|
|
55
|
+
const n = e.createElement("span").style;
|
|
56
|
+
return n.cssText = i || "", n.setProperty("width", `${Math.round(t * 100) / 100}px`), s && (n.setProperty("min-width", "0"), n.setProperty("max-width", "none"), n.setProperty("table-layout", "fixed")), n.cssText;
|
|
57
|
+
}
|
|
58
|
+
function P(i, t, e) {
|
|
59
|
+
const s = i.state.doc.nodeAt(t);
|
|
60
|
+
if (!i.editable || s?.type.name !== "table") return;
|
|
61
|
+
const n = i.dom.ownerDocument, u = [];
|
|
62
|
+
let a = t + 1;
|
|
63
|
+
s.forEach((o, c) => {
|
|
64
|
+
o.type.name === "caption" && (a = t + 1 + c + o.nodeSize), o.type.name === "colgroup" && u.push({ node: o, position: t + 1 + c });
|
|
65
|
+
});
|
|
66
|
+
const { col: m, colgroup: r } = i.state.schema.nodes, l = [];
|
|
67
|
+
let g = 0;
|
|
68
|
+
const f = (o, c = !1) => {
|
|
69
|
+
const {
|
|
70
|
+
span: b,
|
|
71
|
+
width: M,
|
|
72
|
+
...v
|
|
73
|
+
} = o?.attrs.htmlAttrs || {};
|
|
74
|
+
return c || delete v.id, m.create({
|
|
75
|
+
sourceKey: c ? o?.attrs.sourceKey : null,
|
|
76
|
+
htmlAttrs: {
|
|
77
|
+
...v,
|
|
78
|
+
style: O(v.style, e[g++], n)
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
for (const { node: o } of u) {
|
|
83
|
+
const c = [];
|
|
84
|
+
if (o.forEach((y) => {
|
|
85
|
+
const D = Math.min(
|
|
86
|
+
1e3,
|
|
87
|
+
Math.max(1, parseInt(y.attrs.htmlAttrs?.span, 10) || 1)
|
|
88
|
+
);
|
|
89
|
+
for (let C = 0; C < D && g < e.length; C++)
|
|
90
|
+
c.push(f(y, C === 0));
|
|
91
|
+
}), !o.childCount) {
|
|
92
|
+
const y = Math.min(
|
|
93
|
+
1e3,
|
|
94
|
+
Math.max(1, parseInt(o.attrs.htmlAttrs?.span, 10) || 1)
|
|
95
|
+
);
|
|
96
|
+
for (let D = 0; D < y && g < e.length; D++)
|
|
97
|
+
c.push(f());
|
|
98
|
+
}
|
|
99
|
+
const {
|
|
100
|
+
span: b,
|
|
101
|
+
width: M,
|
|
102
|
+
...v
|
|
103
|
+
} = o.attrs.htmlAttrs || {}, w = n.createElement("span").style;
|
|
104
|
+
w.cssText = v.style || "", w.removeProperty("width"), w.cssText ? v.style = w.cssText : delete v.style, l.push(
|
|
105
|
+
r.create({ ...o.attrs, htmlAttrs: v }, c)
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
if (g < e.length) {
|
|
109
|
+
const o = [];
|
|
110
|
+
for (; g < e.length; ) o.push(f());
|
|
111
|
+
if (l.length) {
|
|
112
|
+
const c = l[l.length - 1];
|
|
113
|
+
l[l.length - 1] = c.copy(
|
|
114
|
+
c.content.append(x.fromArray(o))
|
|
115
|
+
);
|
|
116
|
+
} else l.push(r.create(null, o));
|
|
117
|
+
}
|
|
118
|
+
const p = u[0]?.position ?? a, E = u[u.length - 1], h = E ? E.position + E.node.nodeSize : p, d = i.state.tr.replaceWith(
|
|
119
|
+
p,
|
|
120
|
+
h,
|
|
121
|
+
x.fromArray(l)
|
|
122
|
+
);
|
|
123
|
+
d.setNodeMarkup(t, void 0, {
|
|
124
|
+
...s.attrs,
|
|
125
|
+
htmlAttrs: {
|
|
126
|
+
...s.attrs.htmlAttrs,
|
|
127
|
+
style: O(
|
|
128
|
+
s.attrs.htmlAttrs?.style,
|
|
129
|
+
e.reduce((o, c) => o + c, 0),
|
|
130
|
+
n,
|
|
131
|
+
!0
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
}), i.dispatch(N(d)), i.dispatch(N(i.state.tr));
|
|
135
|
+
}
|
|
136
|
+
function S(i, t) {
|
|
137
|
+
Array.from(i.attributes).forEach((e) => {
|
|
138
|
+
e.name in t || i.removeAttribute(e.name);
|
|
139
|
+
}), Object.entries(t).forEach(([e, s]) => {
|
|
140
|
+
i.setAttribute(e, s);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
class k {
|
|
144
|
+
constructor(t, e, s) {
|
|
145
|
+
this.view = e, this.getPos = s;
|
|
146
|
+
const n = e.dom.ownerDocument;
|
|
147
|
+
this.node = t, this.dom = n.createElement("div"), this.dom.className = "lunar-table-scroll", this.contentDOM = n.createElement("table"), this.dom.appendChild(this.contentDOM), this.controls = n.createElement("div"), this.controls.className = "lunar-table-resize-controls", this.controls.contentEditable = "false", this.dom.append(this.controls), this.dom.addEventListener("pointerover", this.showControls), this.dom.addEventListener("pointerleave", this.hideControls), this.dom.addEventListener("focusin", this.showControls), this.dom.addEventListener("focusout", this.hideControls), this.dom.addEventListener("scroll", this.scheduleLayout), this.controls.addEventListener("pointerdown", this.startDrag), this.controls.addEventListener("keydown", this.onHandleKeyDown), this.update(t);
|
|
148
|
+
}
|
|
149
|
+
view;
|
|
150
|
+
getPos;
|
|
151
|
+
dom;
|
|
152
|
+
contentDOM;
|
|
153
|
+
controls;
|
|
154
|
+
node;
|
|
155
|
+
observer;
|
|
156
|
+
frame = 0;
|
|
157
|
+
previewNodes = /* @__PURE__ */ new WeakSet();
|
|
158
|
+
drag;
|
|
159
|
+
update(t) {
|
|
160
|
+
return t.type.name !== "table" ? !1 : (this.drag && (t !== this.node || !this.view.editable) && this.finishDrag(!1), this.node = t, this.drag || S(this.contentDOM, t.attrs.htmlAttrs || {}), this.dom.classList.toggle(
|
|
161
|
+
"lunar-table-scroll--fixed",
|
|
162
|
+
this.contentDOM.style.tableLayout === "fixed"
|
|
163
|
+
), this.controls.childElementCount && this.scheduleLayout(), !0);
|
|
164
|
+
}
|
|
165
|
+
showControls = (t) => {
|
|
166
|
+
if (!this.view.editable || this.drag || this.controls.childElementCount || t.target.closest?.(".lunar-table-scroll") !== this.dom) return;
|
|
167
|
+
this.refreshControls();
|
|
168
|
+
const s = this.dom.ownerDocument.defaultView?.ResizeObserver;
|
|
169
|
+
s && !this.observer && (this.observer = new s(this.scheduleLayout), this.observer.observe(this.contentDOM));
|
|
170
|
+
};
|
|
171
|
+
hideControls = (t) => {
|
|
172
|
+
if (this.drag) return;
|
|
173
|
+
const e = t.relatedTarget;
|
|
174
|
+
e && this.dom.contains(e) || t.type === "pointerleave" && this.controls.contains(this.dom.ownerDocument.activeElement) || (this.controls.replaceChildren(), this.observer?.disconnect(), this.observer = void 0);
|
|
175
|
+
};
|
|
176
|
+
scheduleLayout = () => {
|
|
177
|
+
this.frame || (this.frame = this.dom.ownerDocument.defaultView.requestAnimationFrame(
|
|
178
|
+
() => {
|
|
179
|
+
this.frame = 0, this.controls.childElementCount && this.refreshControls();
|
|
180
|
+
}
|
|
181
|
+
));
|
|
182
|
+
};
|
|
183
|
+
refreshControls() {
|
|
184
|
+
if (!this.view.editable) {
|
|
185
|
+
this.controls.replaceChildren();
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const t = this.contentDOM.getBoundingClientRect(), e = this.drag;
|
|
189
|
+
let s;
|
|
190
|
+
if (e) {
|
|
191
|
+
const m = [t.left + e.edgeOffset];
|
|
192
|
+
e.widths.forEach(
|
|
193
|
+
(r) => m.push(
|
|
194
|
+
m[m.length - 1] + r * e.layout.direction
|
|
195
|
+
)
|
|
196
|
+
), s = {
|
|
197
|
+
widths: e.widths,
|
|
198
|
+
boundaries: m,
|
|
199
|
+
direction: e.layout.direction
|
|
200
|
+
};
|
|
201
|
+
} else s = A(this.contentDOM);
|
|
202
|
+
if (!s) {
|
|
203
|
+
this.controls.replaceChildren();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const n = s.widths.length - 1;
|
|
207
|
+
if (this.controls.childElementCount !== n) {
|
|
208
|
+
this.controls.replaceChildren();
|
|
209
|
+
for (let m = 0; m < n; m++) {
|
|
210
|
+
const r = this.dom.ownerDocument.createElement("div");
|
|
211
|
+
r.className = "lunar-table-column-handle", r.dataset.column = String(m), r.setAttribute("role", "separator"), r.setAttribute("aria-orientation", "vertical"), r.setAttribute("aria-label", `Resize column ${m + 1}`), r.title = "Drag to resize column · Arrow keys to adjust · Esc to cancel", r.tabIndex = 0, this.controls.append(r);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const u = this.controls.getBoundingClientRect(), a = Math.max(
|
|
215
|
+
t.top,
|
|
216
|
+
this.contentDOM.rows[0]?.getBoundingClientRect().top ?? t.top
|
|
217
|
+
);
|
|
218
|
+
Array.from(this.controls.children).forEach((m, r) => {
|
|
219
|
+
const l = m;
|
|
220
|
+
l.style.left = `${s.boundaries[r + 1] - u.left}px`, l.style.top = `${a - u.top}px`, l.style.height = `${t.bottom - a}px`, l.setAttribute(
|
|
221
|
+
"aria-valuenow",
|
|
222
|
+
String(Math.round(s.widths[r]))
|
|
223
|
+
), l.setAttribute(
|
|
224
|
+
"aria-valuemin",
|
|
225
|
+
String(Math.min(L, Math.round(s.widths[r])))
|
|
226
|
+
), l.setAttribute(
|
|
227
|
+
"aria-valuemax",
|
|
228
|
+
String(
|
|
229
|
+
Math.round(
|
|
230
|
+
s.widths[r] + s.widths[r + 1] - Math.min(L, s.widths[r + 1])
|
|
231
|
+
)
|
|
232
|
+
)
|
|
233
|
+
);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
handleColumn(t) {
|
|
237
|
+
const e = t.target.closest(
|
|
238
|
+
".lunar-table-column-handle"
|
|
239
|
+
);
|
|
240
|
+
return e && this.controls.contains(e) ? Number(e.dataset.column) : void 0;
|
|
241
|
+
}
|
|
242
|
+
startDrag = (t) => {
|
|
243
|
+
const e = this.handleColumn(t), s = A(this.contentDOM);
|
|
244
|
+
if (!this.view.editable || t.button !== 0 || e === void 0 || !s || e >= s.widths.length - 1 || this.drag)
|
|
245
|
+
return;
|
|
246
|
+
t.preventDefault(), t.stopPropagation();
|
|
247
|
+
const n = this.dom.ownerDocument, u = n.createElement("colgroup");
|
|
248
|
+
this.previewNodes.add(u);
|
|
249
|
+
const a = Array.from(this.contentDOM.children).filter((r) => r.tagName === "COLGROUP").map((r) => ({ node: r, next: r.nextSibling }));
|
|
250
|
+
this.drag = {
|
|
251
|
+
column: e,
|
|
252
|
+
pointerId: t.pointerId,
|
|
253
|
+
startX: t.clientX,
|
|
254
|
+
layout: s,
|
|
255
|
+
edgeOffset: s.boundaries[0] - this.contentDOM.getBoundingClientRect().left,
|
|
256
|
+
widths: s.widths,
|
|
257
|
+
document: this.view.state.doc,
|
|
258
|
+
preview: u,
|
|
259
|
+
originals: a,
|
|
260
|
+
style: this.contentDOM.getAttribute("style")
|
|
261
|
+
};
|
|
262
|
+
for (const { node: r } of a)
|
|
263
|
+
this.previewNodes.add(r), r.remove();
|
|
264
|
+
s.widths.forEach((r) => {
|
|
265
|
+
const l = n.createElement("col");
|
|
266
|
+
l.style.width = `${r}px`, this.previewNodes.add(l), u.append(l);
|
|
267
|
+
});
|
|
268
|
+
const m = this.contentDOM.caption;
|
|
269
|
+
this.contentDOM.insertBefore(
|
|
270
|
+
u,
|
|
271
|
+
m ? m.nextSibling : this.contentDOM.firstChild
|
|
272
|
+
), this.contentDOM.style.cssText = O(
|
|
273
|
+
this.drag.style || "",
|
|
274
|
+
s.widths.reduce((r, l) => r + l, 0),
|
|
275
|
+
n,
|
|
276
|
+
!0
|
|
277
|
+
), this.dom.classList.add(
|
|
278
|
+
"lunar-table-scroll--fixed",
|
|
279
|
+
"lunar-table-scroll--resizing"
|
|
280
|
+
), this.controls.children[e]?.classList.add(
|
|
281
|
+
"lunar-table-column-handle--active"
|
|
282
|
+
), n.addEventListener("pointermove", this.moveDrag, !0), n.addEventListener("pointerup", this.endDrag, !0), n.addEventListener("pointercancel", this.cancelDrag, !0), n.addEventListener("keydown", this.onDragKeyDown, !0), n.defaultView?.addEventListener("blur", this.cancelDrag), this.scheduleLayout();
|
|
283
|
+
};
|
|
284
|
+
moveDrag = (t) => {
|
|
285
|
+
const e = this.drag;
|
|
286
|
+
if (!(!e || t.pointerId !== e.pointerId)) {
|
|
287
|
+
if (!this.view.editable || this.view.state.doc !== e.document) {
|
|
288
|
+
this.finishDrag(!1);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
t.preventDefault(), e.widths = R(
|
|
292
|
+
e.layout.widths,
|
|
293
|
+
e.column,
|
|
294
|
+
(t.clientX - e.startX) * e.layout.direction
|
|
295
|
+
);
|
|
296
|
+
for (const s of [e.column, e.column + 1])
|
|
297
|
+
e.preview.children[s].style.width = `${e.widths[s]}px`;
|
|
298
|
+
this.scheduleLayout();
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
endDrag = (t) => {
|
|
302
|
+
t.pointerId === this.drag?.pointerId && (this.moveDrag(t), this.finishDrag(!0));
|
|
303
|
+
};
|
|
304
|
+
cancelDrag = () => this.finishDrag(!1);
|
|
305
|
+
onDragKeyDown = (t) => {
|
|
306
|
+
t.key === "Escape" && (t.preventDefault(), t.stopPropagation(), this.finishDrag(!1));
|
|
307
|
+
};
|
|
308
|
+
finishDrag(t) {
|
|
309
|
+
const e = this.drag;
|
|
310
|
+
if (!e) return;
|
|
311
|
+
this.drag = void 0;
|
|
312
|
+
const s = this.dom.ownerDocument;
|
|
313
|
+
s.removeEventListener("pointermove", this.moveDrag, !0), s.removeEventListener("pointerup", this.endDrag, !0), s.removeEventListener("pointercancel", this.cancelDrag, !0), s.removeEventListener("keydown", this.onDragKeyDown, !0), s.defaultView?.removeEventListener("blur", this.cancelDrag), e.preview.remove(), [...e.originals].reverse().forEach(({ node: u, next: a }) => this.contentDOM.insertBefore(u, a)), e.style === null ? this.contentDOM.removeAttribute("style") : this.contentDOM.setAttribute("style", e.style), this.dom.classList.remove("lunar-table-scroll--resizing"), this.controls.children[e.column]?.classList.remove(
|
|
314
|
+
"lunar-table-column-handle--active"
|
|
315
|
+
), this.dom.classList.toggle(
|
|
316
|
+
"lunar-table-scroll--fixed",
|
|
317
|
+
this.contentDOM.style.tableLayout === "fixed"
|
|
318
|
+
);
|
|
319
|
+
const n = this.getPos();
|
|
320
|
+
t && this.view.editable && this.view.state.doc === e.document && n !== void 0 && e.widths.some(
|
|
321
|
+
(u, a) => Math.abs(u - e.layout.widths[a]) >= 0.5
|
|
322
|
+
) && P(this.view, n, e.widths), this.scheduleLayout();
|
|
323
|
+
}
|
|
324
|
+
onHandleKeyDown = (t) => {
|
|
325
|
+
const e = this.handleColumn(t), s = A(this.contentDOM), n = this.getPos();
|
|
326
|
+
if (!this.view.editable || e === void 0 || !s || e >= s.widths.length - 1 || n === void 0 || !["ArrowLeft", "ArrowRight"].includes(t.key))
|
|
327
|
+
return;
|
|
328
|
+
t.preventDefault();
|
|
329
|
+
const u = (t.key === "ArrowRight" ? 10 : -10) * s.direction, a = R(s.widths, e, u);
|
|
330
|
+
a[e] !== s.widths[e] && P(this.view, n, a), this.scheduleLayout();
|
|
331
|
+
};
|
|
332
|
+
stopEvent(t) {
|
|
333
|
+
return this.controls.contains(t.target);
|
|
334
|
+
}
|
|
335
|
+
ignoreMutation(t) {
|
|
336
|
+
return t.type === "selection" ? !1 : !this.contentDOM.contains(t.target) || t.type === "attributes" && t.target === this.contentDOM || this.previewNodes.has(t.target) ? !0 : t.type === "childList" && t.target === this.contentDOM && [
|
|
337
|
+
...Array.from(t.addedNodes),
|
|
338
|
+
...Array.from(t.removedNodes)
|
|
339
|
+
].every((e) => this.previewNodes.has(e));
|
|
340
|
+
}
|
|
341
|
+
destroy() {
|
|
342
|
+
this.finishDrag(!1), this.observer?.disconnect(), this.dom.ownerDocument.defaultView?.cancelAnimationFrame(this.frame), this.dom.removeEventListener("pointerover", this.showControls), this.dom.removeEventListener("pointerleave", this.hideControls), this.dom.removeEventListener("focusin", this.showControls), this.dom.removeEventListener("focusout", this.hideControls), this.dom.removeEventListener("scroll", this.scheduleLayout), this.controls.removeEventListener("pointerdown", this.startDrag), this.controls.removeEventListener("keydown", this.onHandleKeyDown);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function B() {
|
|
346
|
+
return {
|
|
347
|
+
name: "table-view",
|
|
348
|
+
nodeViews: {
|
|
349
|
+
table: (i, t, e) => new k(i, t, e)
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
export {
|
|
354
|
+
B as createTableExtension
|
|
355
|
+
};
|
|
356
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/extensions/table/column-layout.ts","../../../src/extensions/table/resize-transaction.ts","../../../src/extensions/table/table-node-view.ts","../../../src/extensions/table/index.ts"],"sourcesContent":["/** Measure logical columns, including cells spanning rows or columns. */\nexport type ColumnLayout = {\n widths: number[];\n boundaries: number[];\n direction: number;\n};\n\nexport const MIN_COLUMN_WIDTH = 48;\n\nexport function measureColumns(\n table: HTMLTableElement\n): ColumnLayout | undefined {\n const rows = Array.from(table.rows);\n const occupied: boolean[][] = [];\n const edges: number[][] = [];\n const rtl =\n table.ownerDocument.defaultView!.getComputedStyle(table).direction ===\n 'rtl';\n const direction = rtl ? -1 : 1;\n let count = 0;\n const addEdge = (index: number, x: number) => (edges[index] ??= []).push(x);\n const groupEnds = new Map<Element | null, number>();\n rows.forEach((row, index) => groupEnds.set(row.parentElement, index + 1));\n rows.forEach((row, rowIndex) => {\n let column = 0;\n for (const cell of Array.from(row.cells)) {\n while (occupied[rowIndex]?.[column]) column++;\n const colspan = cell.colSpan;\n const lastRow = groupEnds.get(row.parentElement)!;\n const rowspan = cell.rowSpan || lastRow - rowIndex;\n for (let r = rowIndex; r < Math.min(rowIndex + rowspan, lastRow); r++) {\n for (let c = column; c < column + colspan; c++)\n (occupied[r] ??= [])[c] = true;\n }\n const rect = cell.getBoundingClientRect();\n addEdge(column, rtl ? rect.right : rect.left);\n addEdge(column + colspan, rtl ? rect.left : rect.right);\n column += colspan;\n count = Math.max(count, column);\n }\n });\n let column = 0;\n // Explicit columns also expose boundaries hidden by merged cells in every row.\n for (const group of Array.from(table.children).filter(\n (child) => child.tagName === 'COLGROUP'\n )) {\n const cols = Array.from(group.children) as HTMLTableColElement[];\n for (const col of cols.length ? cols : [group as HTMLTableColElement]) {\n const rect = col.getBoundingClientRect();\n if (rect.width > 0) {\n addEdge(column, rtl ? rect.right : rect.left);\n addEdge(column + col.span, rtl ? rect.left : rect.right);\n }\n column += col.span;\n }\n }\n count = Math.max(count, column);\n if (count < 2 || table.getBoundingClientRect().width <= 0) return undefined;\n const tableRect = table.getBoundingClientRect();\n edges[0] ??= [rtl ? tableRect.right : tableRect.left];\n edges[count] ??= [rtl ? tableRect.left : tableRect.right];\n const boundaries = Array.from({ length: count + 1 }, (_, index) => {\n const values = edges[index];\n return values ? values.reduce((sum, x) => sum + x, 0) / values.length : NaN;\n });\n // A boundary hidden in every row by colspan has no DOM edge; interpolate it.\n let start = 0;\n while (start < count) {\n let end = start + 1;\n while (end < count && !Number.isFinite(boundaries[end])) end++;\n for (let index = start + 1; index < end; index++) {\n boundaries[index] =\n boundaries[start] +\n ((boundaries[end] - boundaries[start]) * (index - start)) /\n (end - start);\n }\n start = end;\n }\n const widths = boundaries\n .slice(1)\n .map((edge, index) => Math.abs(edge - boundaries[index]));\n return widths.every((width) => Number.isFinite(width) && width > 0)\n ? { widths, boundaries, direction }\n : undefined;\n}\n\nexport function resizeColumns(\n widths: readonly number[],\n column: number,\n delta: number\n) {\n const next = [...widths];\n // Preserve pre-existing narrow columns until the user increases their width.\n const minLeft = Math.min(MIN_COLUMN_WIDTH, widths[column]);\n const minRight = Math.min(MIN_COLUMN_WIDTH, widths[column + 1]);\n const change = Math.max(\n minLeft - widths[column],\n Math.min(delta, widths[column + 1] - minRight)\n );\n next[column] += change;\n next[column + 1] -= change;\n return next;\n}\n","import {\n Fragment,\n closeHistory,\n type EditorView,\n type Node as ProseMirrorNode,\n} from '@mache-hangar/lunar-editor-core/pm';\n\nexport function withWidth(\n style: string | undefined,\n width: number,\n document: Document,\n table = false\n) {\n const declaration = document.createElement('span').style;\n declaration.cssText = style || '';\n declaration.setProperty('width', `${Math.round(width * 100) / 100}px`);\n if (table) {\n declaration.setProperty('min-width', '0');\n declaration.setProperty('max-width', 'none');\n declaration.setProperty('table-layout', 'fixed');\n }\n return declaration.cssText;\n}\n\n/** Commit ordinary HTML col widths through the existing source-aware transaction. */\nexport function commitColumnWidths(\n view: EditorView,\n position: number,\n widths: readonly number[]\n) {\n const table = view.state.doc.nodeAt(position);\n if (!view.editable || table?.type.name !== 'table') return;\n const document = view.dom.ownerDocument;\n const groups: { node: ProseMirrorNode; position: number }[] = [];\n let insertAt = position + 1;\n table.forEach((node, offset) => {\n if (node.type.name === 'caption')\n insertAt = position + 1 + offset + node.nodeSize;\n if (node.type.name === 'colgroup')\n groups.push({ node, position: position + 1 + offset });\n });\n const { col, colgroup } = view.state.schema.nodes;\n const replacements: ProseMirrorNode[] = [];\n let column = 0;\n const makeColumn = (original?: ProseMirrorNode, reuseKey = false) => {\n const {\n span: _span,\n width: _width,\n ...attrs\n } = original?.attrs.htmlAttrs || {};\n if (!reuseKey) delete attrs.id;\n return col.create({\n sourceKey: reuseKey ? original?.attrs.sourceKey : null,\n htmlAttrs: {\n ...attrs,\n style: withWidth(attrs.style, widths[column++], document),\n },\n });\n };\n for (const { node: group } of groups) {\n const columns: ProseMirrorNode[] = [];\n group.forEach((node) => {\n const span = Math.min(\n 1000,\n Math.max(1, parseInt(node.attrs.htmlAttrs?.span, 10) || 1)\n );\n for (let index = 0; index < span && column < widths.length; index++) {\n columns.push(makeColumn(node, index === 0));\n }\n });\n if (!group.childCount) {\n const span = Math.min(\n 1000,\n Math.max(1, parseInt(group.attrs.htmlAttrs?.span, 10) || 1)\n );\n for (let index = 0; index < span && column < widths.length; index++)\n columns.push(makeColumn());\n }\n const {\n span: _span,\n width: _width,\n ...attrs\n } = group.attrs.htmlAttrs || {};\n const style = document.createElement('span').style;\n style.cssText = attrs.style || '';\n style.removeProperty('width');\n if (style.cssText) attrs.style = style.cssText;\n else delete attrs.style;\n replacements.push(\n colgroup.create({ ...group.attrs, htmlAttrs: attrs }, columns)\n );\n }\n if (column < widths.length) {\n const columns: ProseMirrorNode[] = [];\n while (column < widths.length) columns.push(makeColumn());\n if (replacements.length) {\n const last = replacements[replacements.length - 1];\n replacements[replacements.length - 1] = last.copy(\n last.content.append(Fragment.fromArray(columns))\n );\n } else replacements.push(colgroup.create(null, columns));\n }\n const from = groups[0]?.position ?? insertAt;\n const last = groups[groups.length - 1];\n const to = last ? last.position + last.node.nodeSize : from;\n const transaction = view.state.tr.replaceWith(\n from,\n to,\n Fragment.fromArray(replacements)\n );\n transaction.setNodeMarkup(position, undefined, {\n ...table.attrs,\n htmlAttrs: {\n ...table.attrs.htmlAttrs,\n style: withWidth(\n table.attrs.htmlAttrs?.style,\n widths.reduce((sum, width) => sum + width, 0),\n document,\n true\n ),\n },\n });\n view.dispatch(closeHistory(transaction));\n // Keep both the previous and next edit separate from this single drag.\n view.dispatch(closeHistory(view.state.tr));\n}\n","import type {\n Node as ProseMirrorNode,\n NodeView,\n EditorView,\n ViewMutationRecord,\n} from '@mache-hangar/lunar-editor-core/pm';\nimport {\n measureColumns,\n resizeColumns,\n MIN_COLUMN_WIDTH,\n type ColumnLayout,\n} from './column-layout';\nimport { commitColumnWidths, withWidth } from './resize-transaction';\n\ntype HtmlAttributes = Record<string, string>;\n\nfunction updateHtmlAttributes(\n element: HTMLElement,\n attributes: HtmlAttributes\n) {\n Array.from(element.attributes).forEach((attribute) => {\n if (!(attribute.name in attributes)) {\n element.removeAttribute(attribute.name);\n }\n });\n\n Object.entries(attributes).forEach(([name, value]) => {\n element.setAttribute(name, value);\n });\n}\n\nexport class TableNodeView implements NodeView {\n readonly dom: HTMLDivElement;\n readonly contentDOM: HTMLTableElement;\n private readonly controls: HTMLDivElement;\n private node: ProseMirrorNode;\n private observer?: ResizeObserver;\n private frame = 0;\n private readonly previewNodes = new WeakSet<Node>();\n private drag?: {\n pointerId: number;\n column: number;\n startX: number;\n layout: ColumnLayout;\n edgeOffset: number;\n widths: number[];\n document: ProseMirrorNode;\n preview: HTMLTableColElement;\n originals: { node: Element; next: ChildNode | null }[];\n style: string | null;\n };\n\n constructor(\n node: ProseMirrorNode,\n private readonly view: EditorView,\n private readonly getPos: () => number | undefined\n ) {\n const document = view.dom.ownerDocument;\n this.node = node;\n this.dom = document.createElement('div');\n this.dom.className = 'lunar-table-scroll';\n this.contentDOM = document.createElement('table');\n this.dom.appendChild(this.contentDOM);\n this.controls = document.createElement('div');\n this.controls.className = 'lunar-table-resize-controls';\n this.controls.contentEditable = 'false';\n this.dom.append(this.controls);\n this.dom.addEventListener('pointerover', this.showControls);\n this.dom.addEventListener('pointerleave', this.hideControls);\n this.dom.addEventListener('focusin', this.showControls);\n this.dom.addEventListener('focusout', this.hideControls);\n this.dom.addEventListener('scroll', this.scheduleLayout);\n this.controls.addEventListener('pointerdown', this.startDrag);\n this.controls.addEventListener('keydown', this.onHandleKeyDown);\n this.update(node);\n }\n\n update(node: ProseMirrorNode) {\n if (node.type.name !== 'table') {\n return false;\n }\n\n if (this.drag && (node !== this.node || !this.view.editable))\n this.finishDrag(false);\n this.node = node;\n if (!this.drag)\n updateHtmlAttributes(this.contentDOM, node.attrs.htmlAttrs || {});\n this.dom.classList.toggle(\n 'lunar-table-scroll--fixed',\n this.contentDOM.style.tableLayout === 'fixed'\n );\n if (this.controls.childElementCount) this.scheduleLayout();\n return true;\n }\n\n private showControls = (event: Event) => {\n if (!this.view.editable || this.drag || this.controls.childElementCount)\n return;\n const target = event.target as Element;\n if (target.closest?.('.lunar-table-scroll') !== this.dom) return;\n this.refreshControls();\n const Observer = this.dom.ownerDocument.defaultView?.ResizeObserver;\n if (Observer && !this.observer) {\n this.observer = new Observer(this.scheduleLayout);\n this.observer.observe(this.contentDOM);\n }\n };\n\n private hideControls = (event: Event) => {\n if (this.drag) return;\n const related = (event as FocusEvent).relatedTarget as Node | null;\n if (related && this.dom.contains(related)) return;\n if (\n event.type === 'pointerleave' &&\n this.controls.contains(this.dom.ownerDocument.activeElement)\n )\n return;\n this.controls.replaceChildren();\n this.observer?.disconnect();\n this.observer = undefined;\n };\n\n private scheduleLayout = () => {\n if (this.frame) return;\n this.frame = this.dom.ownerDocument.defaultView!.requestAnimationFrame(\n () => {\n this.frame = 0;\n if (this.controls.childElementCount) this.refreshControls();\n }\n );\n };\n\n private refreshControls() {\n if (!this.view.editable) {\n this.controls.replaceChildren();\n return;\n }\n const table = this.contentDOM.getBoundingClientRect();\n const drag = this.drag;\n let layout: ColumnLayout | undefined;\n if (drag) {\n // Column topology cannot change during a drag. Reuse it instead of\n // walking every row and measuring every cell on every animation frame.\n const boundaries = [table.left + drag.edgeOffset];\n drag.widths.forEach((width) =>\n boundaries.push(\n boundaries[boundaries.length - 1] + width * drag.layout.direction\n )\n );\n layout = {\n widths: drag.widths,\n boundaries,\n direction: drag.layout.direction,\n };\n } else layout = measureColumns(this.contentDOM);\n if (!layout) {\n this.controls.replaceChildren();\n return;\n }\n const count = layout.widths.length - 1;\n if (this.controls.childElementCount !== count) {\n this.controls.replaceChildren();\n for (let column = 0; column < count; column++) {\n const handle = this.dom.ownerDocument.createElement('div');\n handle.className = 'lunar-table-column-handle';\n handle.dataset.column = String(column);\n handle.setAttribute('role', 'separator');\n handle.setAttribute('aria-orientation', 'vertical');\n handle.setAttribute('aria-label', `Resize column ${column + 1}`);\n handle.title =\n 'Drag to resize column · Arrow keys to adjust · Esc to cancel';\n handle.tabIndex = 0;\n this.controls.append(handle);\n }\n }\n // Use the actual positioning layer as the origin. Its viewport rectangle\n // already includes container borders, indentation and horizontal scrolling.\n const controls = this.controls.getBoundingClientRect();\n const bodyTop = Math.max(\n table.top,\n this.contentDOM.rows[0]?.getBoundingClientRect().top ?? table.top\n );\n Array.from(this.controls.children).forEach((element, index) => {\n const handle = element as HTMLElement;\n handle.style.left = `${layout.boundaries[index + 1] - controls.left}px`;\n handle.style.top = `${bodyTop - controls.top}px`;\n handle.style.height = `${table.bottom - bodyTop}px`;\n handle.setAttribute(\n 'aria-valuenow',\n String(Math.round(layout.widths[index]))\n );\n handle.setAttribute(\n 'aria-valuemin',\n String(Math.min(MIN_COLUMN_WIDTH, Math.round(layout.widths[index])))\n );\n handle.setAttribute(\n 'aria-valuemax',\n String(\n Math.round(\n layout.widths[index] +\n layout.widths[index + 1] -\n Math.min(MIN_COLUMN_WIDTH, layout.widths[index + 1])\n )\n )\n );\n });\n }\n\n private handleColumn(event: Event) {\n const handle = (event.target as Element).closest<HTMLElement>(\n '.lunar-table-column-handle'\n );\n return handle && this.controls.contains(handle)\n ? Number(handle.dataset.column)\n : undefined;\n }\n\n private startDrag = (event: PointerEvent) => {\n const column = this.handleColumn(event);\n const layout = measureColumns(this.contentDOM);\n if (\n !this.view.editable ||\n event.button !== 0 ||\n column === undefined ||\n !layout ||\n column >= layout.widths.length - 1 ||\n this.drag\n )\n return;\n event.preventDefault();\n event.stopPropagation();\n const document = this.dom.ownerDocument;\n const preview = document.createElement('colgroup');\n this.previewNodes.add(preview);\n const originals = Array.from(this.contentDOM.children)\n .filter((child) => child.tagName === 'COLGROUP')\n .map((node) => ({ node, next: node.nextSibling }));\n this.drag = {\n column,\n pointerId: event.pointerId,\n startX: event.clientX,\n layout,\n edgeOffset:\n layout.boundaries[0] - this.contentDOM.getBoundingClientRect().left,\n widths: layout.widths,\n document: this.view.state.doc,\n preview,\n originals,\n style: this.contentDOM.getAttribute('style'),\n };\n for (const { node } of originals) {\n this.previewNodes.add(node);\n node.remove();\n }\n layout.widths.forEach((width) => {\n const col = document.createElement('col');\n col.style.width = `${width}px`;\n this.previewNodes.add(col);\n preview.append(col);\n });\n const caption = this.contentDOM.caption;\n this.contentDOM.insertBefore(\n preview,\n caption ? caption.nextSibling : this.contentDOM.firstChild\n );\n this.contentDOM.style.cssText = withWidth(\n this.drag.style || '',\n layout.widths.reduce((a, b) => a + b, 0),\n document,\n true\n );\n this.dom.classList.add(\n 'lunar-table-scroll--fixed',\n 'lunar-table-scroll--resizing'\n );\n this.controls.children[column]?.classList.add(\n 'lunar-table-column-handle--active'\n );\n document.addEventListener('pointermove', this.moveDrag, true);\n document.addEventListener('pointerup', this.endDrag, true);\n document.addEventListener('pointercancel', this.cancelDrag, true);\n document.addEventListener('keydown', this.onDragKeyDown, true);\n document.defaultView?.addEventListener('blur', this.cancelDrag);\n this.scheduleLayout();\n };\n\n private moveDrag = (event: PointerEvent) => {\n const drag = this.drag;\n if (!drag || event.pointerId !== drag.pointerId) return;\n if (!this.view.editable || this.view.state.doc !== drag.document) {\n this.finishDrag(false);\n return;\n }\n event.preventDefault();\n drag.widths = resizeColumns(\n drag.layout.widths,\n drag.column,\n (event.clientX - drag.startX) * drag.layout.direction\n );\n for (const index of [drag.column, drag.column + 1]) {\n (\n drag.preview.children[index] as HTMLElement\n ).style.width = `${drag.widths[index]}px`;\n }\n this.scheduleLayout();\n };\n\n private endDrag = (event: PointerEvent) => {\n if (event.pointerId !== this.drag?.pointerId) return;\n this.moveDrag(event);\n this.finishDrag(true);\n };\n\n private cancelDrag = () => this.finishDrag(false);\n private onDragKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n event.stopPropagation();\n this.finishDrag(false);\n }\n };\n\n private finishDrag(commit: boolean) {\n const drag = this.drag;\n if (!drag) return;\n this.drag = undefined;\n const document = this.dom.ownerDocument;\n document.removeEventListener('pointermove', this.moveDrag, true);\n document.removeEventListener('pointerup', this.endDrag, true);\n document.removeEventListener('pointercancel', this.cancelDrag, true);\n document.removeEventListener('keydown', this.onDragKeyDown, true);\n document.defaultView?.removeEventListener('blur', this.cancelDrag);\n drag.preview.remove();\n [...drag.originals]\n .reverse()\n .forEach(({ node, next }) => this.contentDOM.insertBefore(node, next));\n if (drag.style === null) this.contentDOM.removeAttribute('style');\n else this.contentDOM.setAttribute('style', drag.style);\n this.dom.classList.remove('lunar-table-scroll--resizing');\n this.controls.children[drag.column]?.classList.remove(\n 'lunar-table-column-handle--active'\n );\n this.dom.classList.toggle(\n 'lunar-table-scroll--fixed',\n this.contentDOM.style.tableLayout === 'fixed'\n );\n const position = this.getPos();\n if (\n commit &&\n this.view.editable &&\n this.view.state.doc === drag.document &&\n position !== undefined &&\n drag.widths.some(\n (width, index) => Math.abs(width - drag.layout.widths[index]) >= 0.5\n )\n ) {\n commitColumnWidths(this.view, position, drag.widths);\n }\n this.scheduleLayout();\n }\n\n private onHandleKeyDown = (event: KeyboardEvent) => {\n const column = this.handleColumn(event);\n const layout = measureColumns(this.contentDOM);\n const position = this.getPos();\n if (\n !this.view.editable ||\n column === undefined ||\n !layout ||\n column >= layout.widths.length - 1 ||\n position === undefined ||\n !['ArrowLeft', 'ArrowRight'].includes(event.key)\n )\n return;\n event.preventDefault();\n const delta = (event.key === 'ArrowRight' ? 10 : -10) * layout.direction;\n const widths = resizeColumns(layout.widths, column, delta);\n if (widths[column] !== layout.widths[column])\n commitColumnWidths(this.view, position, widths);\n this.scheduleLayout();\n };\n\n stopEvent(event: Event) {\n return this.controls.contains(event.target as Node);\n }\n\n ignoreMutation(mutation: ViewMutationRecord) {\n if (mutation.type === 'selection') return false;\n if (!this.contentDOM.contains(mutation.target)) return true;\n if (mutation.type === 'attributes' && mutation.target === this.contentDOM)\n return true;\n if (this.previewNodes.has(mutation.target)) return true;\n return (\n mutation.type === 'childList' &&\n mutation.target === this.contentDOM &&\n [\n ...Array.from(mutation.addedNodes),\n ...Array.from(mutation.removedNodes),\n ].every((node) => this.previewNodes.has(node))\n );\n }\n\n destroy() {\n this.finishDrag(false);\n this.observer?.disconnect();\n this.dom.ownerDocument.defaultView?.cancelAnimationFrame(this.frame);\n this.dom.removeEventListener('pointerover', this.showControls);\n this.dom.removeEventListener('pointerleave', this.hideControls);\n this.dom.removeEventListener('focusin', this.showControls);\n this.dom.removeEventListener('focusout', this.hideControls);\n this.dom.removeEventListener('scroll', this.scheduleLayout);\n this.controls.removeEventListener('pointerdown', this.startDrag);\n this.controls.removeEventListener('keydown', this.onHandleKeyDown);\n }\n}\n","import type { EditorExtension } from '@mache-hangar/lunar-editor-core/extensions';\nimport { TableNodeView } from './table-node-view';\nexport function createTableExtension(): EditorExtension {\n return {\n name: 'table-view',\n nodeViews: {\n table: (node, view, getPos) => new TableNodeView(node, view, getPos),\n },\n };\n}\n"],"names":["MIN_COLUMN_WIDTH","measureColumns","table","rows","occupied","edges","rtl","direction","count","addEdge","index","x","groupEnds","row","rowIndex","column","cell","colspan","lastRow","rowspan","r","c","rect","group","child","cols","col","tableRect","boundaries","_","values","sum","start","end","widths","edge","width","resizeColumns","delta","next","minLeft","minRight","change","withWidth","style","document","declaration","commitColumnWidths","view","position","groups","insertAt","node","offset","colgroup","replacements","makeColumn","original","reuseKey","_span","_width","attrs","columns","span","last","Fragment","from","to","transaction","closeHistory","updateHtmlAttributes","element","attributes","attribute","name","value","TableNodeView","getPos","event","Observer","related","drag","layout","handle","controls","bodyTop","preview","originals","caption","a","b","commit","mutation","createTableExtension"],"mappings":";AAOO,MAAMA,IAAmB;AAEzB,SAASC,EACdC,GAC0B;AAC1B,QAAMC,IAAO,MAAM,KAAKD,EAAM,IAAI,GAC5BE,IAAwB,CAAA,GACxBC,IAAoB,CAAA,GACpBC,IACJJ,EAAM,cAAc,YAAa,iBAAiBA,CAAK,EAAE,cACzD,OACIK,IAAYD,IAA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,eAAe,KAAK,YAAY,GAC7D,KAAK,IAAI,oBAAoB,gBAAgB,KAAK,YAAY,GAC9D,KAAK,IAAI,oBAAoB,WAAW,KAAK,YAAY,GACzD,KAAK,IAAI,oBAAoB,YAAY,KAAK,YAAY,GAC1D,KAAK,IAAI,oBAAoB,UAAU,KAAK,cAAc,GAC1D,KAAK,SAAS,oBAAoB,eAAe,KAAK,SAAS,GAC/D,KAAK,SAAS,oBAAoB,WAAW,KAAK,eAAe;AAAA,EACnE;AACF;AC5ZO,SAASyC,IAAwC;AACtD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,WAAW;AAAA,MACT,OAAO,CAACzC,GAAMJ,GAAM6B,MAAW,IAAID,EAAcxB,GAAMJ,GAAM6B,CAAM;AAAA,IAAA;AAAA,EACrE;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.lunar-editor__document .lunar-table-scroll{position:relative;box-sizing:border-box;width:100%;max-width:100%;overflow-x:auto;overflow-y:hidden}.lunar-editor__document .lunar-table-scroll--fixed>table>:is(thead,tbody,tfoot)>tr>:is(td,th),.lunar-editor__document .lunar-table-scroll--fixed>table>tr>:is(td,th){min-width:0;max-width:none}.lunar-editor__document .lunar-table-resize-controls{position:absolute;inset:0;pointer-events:none}.lunar-editor__document .lunar-table-scroll>.lunar-table-resize-controls,.lunar-editor__document .lunar-table-scroll>.lunar-table-resize-controls>.lunar-table-column-handle{box-sizing:border-box;margin:0;padding:0;border:0;min-width:0;min-height:0}.lunar-editor__document[contenteditable=false] .lunar-table-resize-controls{display:none}.lunar-editor__document .lunar-table-column-handle{position:absolute;z-index:3;width:10px;transform:translateX(-50%);cursor:col-resize;touch-action:none;pointer-events:auto;outline:none}.lunar-editor__document .lunar-table-column-handle::after{content:"";position:absolute;top:0;bottom:0;left:4px;width:2px;background:#7b83df;opacity:0}.lunar-editor__document .lunar-table-column-handle:hover::after,.lunar-editor__document .lunar-table-column-handle:focus-visible::after,.lunar-editor__document .lunar-table-column-handle--active::after{opacity:1;width:3px}.lunar-editor__document .lunar-table-scroll--resizing{cursor:col-resize;user-select:none}.lunar-editor__document .lunar-table-scroll--resizing .lunar-table-column-handle:not(.lunar-table-column-handle--active)::after{opacity:0}.lunar-editor__document div>.lunar-table-scroll{width:calc(100% - 24px)}.lunar-editor__document table{display:table;width:max-content;min-width:100%;max-width:none;box-sizing:border-box;margin:0;color:inherit;border:1px solid #c8cdd2;border-collapse:collapse;border-spacing:0;table-layout:auto}.lunar-editor__document table td,.lunar-editor__document table th{position:relative;min-width:120px;max-width:350px;box-sizing:border-box;padding:10px;color:inherit;border:1px solid #c8cdd2;line-height:1.7;overflow-wrap:anywhere;vertical-align:top;white-space:normal;word-break:normal}.lunar-editor__document table td>*,.lunar-editor__document table th>*{margin:0;padding:0;border:0;line-height:inherit;overflow-wrap:inherit;white-space:inherit}.lunar-editor__document table td p,.lunar-editor__document table th p{border-left:none}.lunar-editor__document table th{background:rgba(0,0,0,.05);font-weight:600;letter-spacing:.05em;text-align:left}.lunar-editor__document table td{border-bottom-color:#c8cdd2}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./code-editor-Cq33u9jq.cjs"),r=require("./rich-editor.cjs");exports.CodeEditor=o.CodeEditor;exports.useController=o.useController;exports.useControllerEvents=o.useControllerEvents;exports.useControllerProps=o.useControllerProps;exports.RichEditor=r.RichEditor;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { C as e, u as s, a as t, b as l } from "./code-editor-um45ekRh.js";
|
|
2
|
+
import { RichEditor as C } from "./rich-editor.js";
|
|
3
|
+
export {
|
|
4
|
+
e as CodeEditor,
|
|
5
|
+
C as RichEditor,
|
|
6
|
+
s as useController,
|
|
7
|
+
t as useControllerEvents,
|
|
8
|
+
l as useControllerProps
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),o=require("react"),i=require("@mache-hangar/lunar-editor-core/lunar-editor"),l=require("@mache-hangar/lunar-editor-core/history"),f=o.forwardRef(function(e,g){const a=o.useRef(null),n=o.useRef(void 0),t=o.useRef(e),u=o.useRef({content:e.content,generation:e.sourceGeneration,revision:e.sourceRevision});return o.useLayoutEffect(()=>{t.current=e}),o.useLayoutEffect(()=>{const r=t.current,s=i.createLunarEditor(a.current,{...r,html:r.content,editable:()=>!t.current.readonly,editorClass:()=>t.current.editorClass??"rich-editor__document",onDocChanged:()=>t.current.onDocChanged?.(),onHistoryStateChange:c=>t.current.onHistoryStateChange?.(c),onSelectionFormattingChange:c=>t.current.onSelectionFormattingChange?.(c),onSourceStateChange:c=>t.current.onSourceStateChange?.(c),onTransaction:(c,h,m)=>t.current.onTransaction?.(c,h,m)});return n.current=s,u.current={content:r.content,generation:r.sourceGeneration,revision:r.sourceRevision},()=>{s.destroy(),n.current=void 0}},[e.schema,e.extensions]),o.useLayoutEffect(()=>{if(!n.current)return;const r=u.current;(r.content!==e.content||r.generation!==e.sourceGeneration||r.revision!==e.sourceRevision)&&(i.setLunarEditorHtml(n.current,e.content,e.sourceRevision,e.sourceGeneration),u.current={content:e.content,generation:e.sourceGeneration,revision:e.sourceRevision}),n.current.setProps({editable:()=>!t.current.readonly})},[e.content,e.sourceGeneration,e.sourceRevision,e.readonly]),o.useImperativeHandle(g,()=>({getView:()=>n.current,getHtml:()=>i.getLunarEditorSourceHtml(n.current),getSourceState:()=>i.getLunarEditorSourceSnapshot(n.current),undo:()=>n.current?l.runLunarHistoryCommand(n.current,"undo"):!1,redo:()=>n.current?l.runLunarHistoryCommand(n.current,"redo"):!1}),[]),d.jsx("div",{className:`rich-editor-host ${e.className??""}`,children:d.jsx("div",{className:"rich-editor__mount",ref:a})})});exports.RichEditor=f;
|
|
2
|
+
//# sourceMappingURL=rich-editor.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rich-editor.cjs","sources":["../src/rich-editor.tsx"],"sourcesContent":["import {\n forwardRef,\n useImperativeHandle,\n useLayoutEffect,\n useRef,\n} from 'react';\nimport {\n createLunarEditor,\n setLunarEditorHtml,\n getLunarEditorSourceHtml,\n getLunarEditorSourceSnapshot,\n type CreateLunarEditorOptions,\n} from '@mache-hangar/lunar-editor-core/lunar-editor';\nimport { runLunarHistoryCommand } from '@mache-hangar/lunar-editor-core/history';\ntype EditorView = ReturnType<typeof createLunarEditor>;\n\nexport type RichEditorProps = Omit<\n CreateLunarEditorOptions,\n 'html' | 'editable' | 'editorClass' | 'onDocChanged'\n> & {\n content: string;\n readonly?: boolean;\n className?: string;\n editorClass?: string;\n onDocChanged?: () => void;\n};\nexport type RichEditorApi = {\n getView: () => EditorView | undefined;\n getHtml: () => string;\n getSourceState: () => ReturnType<typeof getLunarEditorSourceSnapshot>;\n undo: () => boolean;\n redo: () => boolean;\n};\n\n/** Generic React adapter. Product plugins are supplied by the caller. */\nexport const RichEditor = forwardRef<RichEditorApi, RichEditorProps>(\n function RichEditor(props, ref) {\n const mount = useRef<HTMLDivElement>(null);\n const view = useRef<EditorView | undefined>(undefined);\n const latest = useRef(props);\n const applied = useRef({\n content: props.content,\n generation: props.sourceGeneration,\n revision: props.sourceRevision,\n });\n useLayoutEffect(() => {\n latest.current = props;\n });\n useLayoutEffect(() => {\n const current = latest.current;\n const engine = createLunarEditor(mount.current!, {\n ...current,\n html: current.content,\n editable: () => !latest.current.readonly,\n editorClass: () =>\n latest.current.editorClass ?? 'rich-editor__document',\n onDocChanged: () => latest.current.onDocChanged?.(),\n onHistoryStateChange: (detail) =>\n latest.current.onHistoryStateChange?.(detail),\n onSelectionFormattingChange: (detail) =>\n latest.current.onSelectionFormattingChange?.(detail),\n onSourceStateChange: (detail) =>\n latest.current.onSourceStateChange?.(detail),\n onTransaction: (before, next, transaction) =>\n latest.current.onTransaction?.(before, next, transaction),\n });\n view.current = engine;\n applied.current = {\n content: current.content,\n generation: current.sourceGeneration,\n revision: current.sourceRevision,\n };\n return () => {\n engine.destroy();\n view.current = undefined;\n };\n }, [props.schema, props.extensions]);\n useLayoutEffect(() => {\n if (!view.current) return;\n const previous = applied.current;\n if (\n previous.content !== props.content ||\n previous.generation !== props.sourceGeneration ||\n previous.revision !== props.sourceRevision\n ) {\n setLunarEditorHtml(\n view.current,\n props.content,\n props.sourceRevision,\n props.sourceGeneration\n );\n applied.current = {\n content: props.content,\n generation: props.sourceGeneration,\n revision: props.sourceRevision,\n };\n }\n view.current.setProps({ editable: () => !latest.current.readonly });\n }, [\n props.content,\n props.sourceGeneration,\n props.sourceRevision,\n props.readonly,\n ]);\n useImperativeHandle(\n ref,\n () => ({\n getView: () => view.current,\n getHtml: () => getLunarEditorSourceHtml(view.current),\n getSourceState: () => getLunarEditorSourceSnapshot(view.current),\n undo: () =>\n view.current ? runLunarHistoryCommand(view.current, 'undo') : false,\n redo: () =>\n view.current ? runLunarHistoryCommand(view.current, 'redo') : false,\n }),\n []\n );\n return (\n <div className={`rich-editor-host ${props.className ?? ''}`}>\n <div className=\"rich-editor__mount\" ref={mount} />\n </div>\n );\n }\n);\n"],"names":["RichEditor","forwardRef","props","ref","mount","useRef","view","latest","applied","useLayoutEffect","current","engine","createLunarEditor","detail","before","next","transaction","previous","setLunarEditorHtml","useImperativeHandle","getLunarEditorSourceHtml","getLunarEditorSourceSnapshot","runLunarHistoryCommand","jsx"],"mappings":"uPAmCaA,EAAaC,EAAAA,WACxB,SAAoBC,EAAOC,EAAK,CAC9B,MAAMC,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Q,QAAU,CAChB,QAASN,EAAM,QACf,WAAYA,EAAM,iBAClB,SAAUA,EAAM,cAAA,GAGpBI,EAAK,QAAQ,SAAS,CAAE,SAAU,IAAM,CAACC,EAAO,QAAQ,SAAU,CACpE,EAAG,CACDL,EAAM,QACNA,EAAM,iBACNA,EAAM,eACNA,EAAM,QAAA,CACP,EACDiB,EAAAA,oBACEhB,EACA,KAAO,CACL,QAAS,IAAMG,EAAK,QACpB,QAAS,IAAMc,EAAAA,yBAAyBd,EAAK,OAAO,EACpD,eAAgB,IAAMe,EAAAA,6BAA6Bf,EAAK,OAAO,EAC/D,KAAM,IACJA,EAAK,QAAUgB,EAAAA,uBAAuBhB,EAAK,QAAS,MAAM,EAAI,GAChE,KAAM,IACJA,EAAK,QAAUgB,EAAAA,uBAAuBhB,EAAK,QAAS,MAAM,EAAI,EAAA,GAElE,CAAA,CAAC,EAGDiB,EAAAA,IAAC,MAAA,CAAI,UAAW,oBAAoBrB,EAAM,WAAa,EAAE,GACvD,SAAAqB,EAAAA,IAAC,MAAA,CAAI,UAAU,qBAAqB,IAAKnB,EAAO,EAClD,CAEJ,CACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as d } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as v, useRef as c, useLayoutEffect as u, useImperativeHandle as f } from "react";
|
|
3
|
+
import { createLunarEditor as S, setLunarEditorHtml as C, getLunarEditorSourceSnapshot as R, getLunarEditorSourceHtml as y } from "@mache-hangar/lunar-editor-core/lunar-editor";
|
|
4
|
+
import { runLunarHistoryCommand as l } from "@mache-hangar/lunar-editor-core/history";
|
|
5
|
+
const w = v(
|
|
6
|
+
function(e, m) {
|
|
7
|
+
const a = c(null), n = c(void 0), t = c(e), i = c({
|
|
8
|
+
content: e.content,
|
|
9
|
+
generation: e.sourceGeneration,
|
|
10
|
+
revision: e.sourceRevision
|
|
11
|
+
});
|
|
12
|
+
return u(() => {
|
|
13
|
+
t.current = e;
|
|
14
|
+
}), u(() => {
|
|
15
|
+
const r = t.current, s = S(a.current, {
|
|
16
|
+
...r,
|
|
17
|
+
html: r.content,
|
|
18
|
+
editable: () => !t.current.readonly,
|
|
19
|
+
editorClass: () => t.current.editorClass ?? "rich-editor__document",
|
|
20
|
+
onDocChanged: () => t.current.onDocChanged?.(),
|
|
21
|
+
onHistoryStateChange: (o) => t.current.onHistoryStateChange?.(o),
|
|
22
|
+
onSelectionFormattingChange: (o) => t.current.onSelectionFormattingChange?.(o),
|
|
23
|
+
onSourceStateChange: (o) => t.current.onSourceStateChange?.(o),
|
|
24
|
+
onTransaction: (o, g, h) => t.current.onTransaction?.(o, g, h)
|
|
25
|
+
});
|
|
26
|
+
return n.current = s, i.current = {
|
|
27
|
+
content: r.content,
|
|
28
|
+
generation: r.sourceGeneration,
|
|
29
|
+
revision: r.sourceRevision
|
|
30
|
+
}, () => {
|
|
31
|
+
s.destroy(), n.current = void 0;
|
|
32
|
+
};
|
|
33
|
+
}, [e.schema, e.extensions]), u(() => {
|
|
34
|
+
if (!n.current) return;
|
|
35
|
+
const r = i.current;
|
|
36
|
+
(r.content !== e.content || r.generation !== e.sourceGeneration || r.revision !== e.sourceRevision) && (C(
|
|
37
|
+
n.current,
|
|
38
|
+
e.content,
|
|
39
|
+
e.sourceRevision,
|
|
40
|
+
e.sourceGeneration
|
|
41
|
+
), i.current = {
|
|
42
|
+
content: e.content,
|
|
43
|
+
generation: e.sourceGeneration,
|
|
44
|
+
revision: e.sourceRevision
|
|
45
|
+
}), n.current.setProps({ editable: () => !t.current.readonly });
|
|
46
|
+
}, [
|
|
47
|
+
e.content,
|
|
48
|
+
e.sourceGeneration,
|
|
49
|
+
e.sourceRevision,
|
|
50
|
+
e.readonly
|
|
51
|
+
]), f(
|
|
52
|
+
m,
|
|
53
|
+
() => ({
|
|
54
|
+
getView: () => n.current,
|
|
55
|
+
getHtml: () => y(n.current),
|
|
56
|
+
getSourceState: () => R(n.current),
|
|
57
|
+
undo: () => n.current ? l(n.current, "undo") : !1,
|
|
58
|
+
redo: () => n.current ? l(n.current, "redo") : !1
|
|
59
|
+
}),
|
|
60
|
+
[]
|
|
61
|
+
), /* @__PURE__ */ d("div", { className: `rich-editor-host ${e.className ?? ""}`, children: /* @__PURE__ */ d("div", { className: "rich-editor__mount", ref: a }) });
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
export {
|
|
65
|
+
w as RichEditor
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=rich-editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rich-editor.js","sources":["../src/rich-editor.tsx"],"sourcesContent":["import {\n forwardRef,\n useImperativeHandle,\n useLayoutEffect,\n useRef,\n} from 'react';\nimport {\n createLunarEditor,\n setLunarEditorHtml,\n getLunarEditorSourceHtml,\n getLunarEditorSourceSnapshot,\n type CreateLunarEditorOptions,\n} from '@mache-hangar/lunar-editor-core/lunar-editor';\nimport { runLunarHistoryCommand } from '@mache-hangar/lunar-editor-core/history';\ntype EditorView = ReturnType<typeof createLunarEditor>;\n\nexport type RichEditorProps = Omit<\n CreateLunarEditorOptions,\n 'html' | 'editable' | 'editorClass' | 'onDocChanged'\n> & {\n content: string;\n readonly?: boolean;\n className?: string;\n editorClass?: string;\n onDocChanged?: () => void;\n};\nexport type RichEditorApi = {\n getView: () => EditorView | undefined;\n getHtml: () => string;\n getSourceState: () => ReturnType<typeof getLunarEditorSourceSnapshot>;\n undo: () => boolean;\n redo: () => boolean;\n};\n\n/** Generic React adapter. Product plugins are supplied by the caller. */\nexport const RichEditor = forwardRef<RichEditorApi, RichEditorProps>(\n function RichEditor(props, ref) {\n const mount = useRef<HTMLDivElement>(null);\n const view = useRef<EditorView | undefined>(undefined);\n const latest = useRef(props);\n const applied = useRef({\n content: props.content,\n generation: props.sourceGeneration,\n revision: props.sourceRevision,\n });\n useLayoutEffect(() => {\n latest.current = props;\n });\n useLayoutEffect(() => {\n const current = latest.current;\n const engine = createLunarEditor(mount.current!, {\n ...current,\n html: current.content,\n editable: () => !latest.current.readonly,\n editorClass: () =>\n latest.current.editorClass ?? 'rich-editor__document',\n onDocChanged: () => latest.current.onDocChanged?.(),\n onHistoryStateChange: (detail) =>\n latest.current.onHistoryStateChange?.(detail),\n onSelectionFormattingChange: (detail) =>\n latest.current.onSelectionFormattingChange?.(detail),\n onSourceStateChange: (detail) =>\n latest.current.onSourceStateChange?.(detail),\n onTransaction: (before, next, transaction) =>\n latest.current.onTransaction?.(before, next, transaction),\n });\n view.current = engine;\n applied.current = {\n content: current.content,\n generation: current.sourceGeneration,\n revision: current.sourceRevision,\n };\n return () => {\n engine.destroy();\n view.current = undefined;\n };\n }, [props.schema, props.extensions]);\n useLayoutEffect(() => {\n if (!view.current) return;\n const previous = applied.current;\n if (\n previous.content !== props.content ||\n previous.generation !== props.sourceGeneration ||\n previous.revision !== props.sourceRevision\n ) {\n setLunarEditorHtml(\n view.current,\n props.content,\n props.sourceRevision,\n props.sourceGeneration\n );\n applied.current = {\n content: props.content,\n generation: props.sourceGeneration,\n revision: props.sourceRevision,\n };\n }\n view.current.setProps({ editable: () => !latest.current.readonly });\n }, [\n props.content,\n props.sourceGeneration,\n props.sourceRevision,\n props.readonly,\n ]);\n useImperativeHandle(\n ref,\n () => ({\n getView: () => view.current,\n getHtml: () => getLunarEditorSourceHtml(view.current),\n getSourceState: () => getLunarEditorSourceSnapshot(view.current),\n undo: () =>\n view.current ? runLunarHistoryCommand(view.current, 'undo') : false,\n redo: () =>\n view.current ? runLunarHistoryCommand(view.current, 'redo') : false,\n }),\n []\n );\n return (\n <div className={`rich-editor-host ${props.className ?? ''}`}>\n <div className=\"rich-editor__mount\" ref={mount} />\n </div>\n );\n }\n);\n"],"names":["RichEditor","forwardRef","props","ref","mount","useRef","view","latest","applied","useLayoutEffect","current","engine","createLunarEditor","detail","before","next","transaction","previous","setLunarEditorHtml","useImperativeHandle","getLunarEditorSourceHtml","getLunarEditorSourceSnapshot","runLunarHistoryCommand","jsx"],"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,OACES,EAAS,YAAYf,EAAM,WAC3Be,EAAS,eAAef,EAAM,oBAC9Be,EAAS,aAAaf,EAAM,oBAE5BgB;AAAA,QACEZ,EAAK;AAAA,QACLJ,EAAM;AAAA,QACNA,EAAM;AAAA,QACNA,EAAM;AAAA,MAAA,GAERM,EAAQ,UAAU;AAAA,QAChB,SAASN,EAAM;AAAA,QACf,YAAYA,EAAM;AAAA,QAClB,UAAUA,EAAM;AAAA,MAAA,IAGpBI,EAAK,QAAQ,SAAS,EAAE,UAAU,MAAM,CAACC,EAAO,QAAQ,UAAU;AAAA,IACpE,GAAG;AAAA,MACDL,EAAM;AAAA,MACNA,EAAM;AAAA,MACNA,EAAM;AAAA,MACNA,EAAM;AAAA,IAAA,CACP,GACDiB;AAAA,MACEhB;AAAA,MACA,OAAO;AAAA,QACL,SAAS,MAAMG,EAAK;AAAA,QACpB,SAAS,MAAMc,EAAyBd,EAAK,OAAO;AAAA,QACpD,gBAAgB,MAAMe,EAA6Bf,EAAK,OAAO;AAAA,QAC/D,MAAM,MACJA,EAAK,UAAUgB,EAAuBhB,EAAK,SAAS,MAAM,IAAI;AAAA,QAChE,MAAM,MACJA,EAAK,UAAUgB,EAAuBhB,EAAK,SAAS,MAAM,IAAI;AAAA,MAAA;AAAA,MAElE,CAAA;AAAA,IAAC,GAGD,gBAAAiB,EAAC,OAAA,EAAI,WAAW,oBAAoBrB,EAAM,aAAa,EAAE,IACvD,UAAA,gBAAAqB,EAAC,OAAA,EAAI,WAAU,sBAAqB,KAAKnB,GAAO,GAClD;AAAA,EAEJ;AACF;"}
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.code-editor-host{display:block;width:100%;height:100%;min-height:0}.code-editor{position:relative;width:100%;height:100%;display:flex;flex-direction:column;min-height:0}.code-editor .editor-container{flex:1;width:100%;min-width:20vw;min-height:0;overflow:hidden;text-align:left}.code-editor .diff-container{width:100%;height:100%;min-width:20vw;min-height:20vh;text-align:left;position:absolute;left:0;top:0;visibility:hidden;opacity:0;z-index:1}.code-editor .diff-container .tool-bar{display:flex;justify-content:space-between}.code-editor .diff-container .cm-mergeView{height:100%;overflow:auto}.code-editor .diff-container .cm-mergeViewEditors{height:100%}.code-editor .diff-container .cm-editor{min-width:0}.code-editor .dialog-ani-rl{animation:dialog .3s cubic-bezier(0.36, 0.07, 0.19, 0.97) both}.code-editor .dialog-ani-lr{animation:dialog .3s cubic-bezier(0.36, 0.07, 0.19, 0.97) both reverse}@keyframes dialog{0%{visibility:hidden;opacity:0;transform:translateX(100%)}100%{visibility:visible;opacity:1;transform:translateX(0)}}.rich-editor-host{display:flex;position:relative;height:100%;min-height:0}.rich-editor__mount{display:flex;flex:1;min-width:0;min-height:0}.rich-editor__document{flex:1;min-width:0;overflow:auto;outline:none}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CodeEditorController } from '@mache-hangar/lunar-editor-core/controllers/code-editor-controller';
|
|
2
|
+
export type CodeEditorApi = Pick<CodeEditorController, 'getValue' | 'setValue' | 'layout' | 'revealTarget' | 'getCurrentRevealTarget' | 'getUserSelectionVersion' | 'isChanged' | 'markClean' | 'resetHistory' | 'formatDocument' | 'diff' | 'whenReady'>;
|
|
3
|
+
export type CodeEditorProps = Partial<Pick<CodeEditorController, 'content' | 'readonly' | 'isShowDiff' | 'format' | 'language'>> & {
|
|
4
|
+
className?: string;
|
|
5
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CodeEditorController } from '@mache-hangar/lunar-editor-core/controllers/code-editor-controller';
|
|
2
|
+
import type { CodeEditorApi } from './code-editor-types';
|
|
3
|
+
export type { CodeEditorApi, CodeEditorProps } from './code-editor-types';
|
|
4
|
+
export declare const CodeEditor: import("react").ForwardRefExoticComponent<Partial<Pick<CodeEditorController, "content" | "readonly" | "isShowDiff" | "format" | "language">> & {
|
|
5
|
+
className?: string;
|
|
6
|
+
} & import("react").RefAttributes<CodeEditorApi>>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type EditorController } from '@mache-hangar/lunar-editor-core/controllers/controller';
|
|
2
|
+
export declare function useController<T extends EditorController>(create: () => T): T;
|
|
3
|
+
export declare function useControllerProps<T>(controller: {
|
|
4
|
+
updateProps(props: T): Promise<void>;
|
|
5
|
+
}, props: T): void;
|
|
6
|
+
export declare function useControllerEvents(controller: object, props: object, events: readonly string[]): void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Plugin, type EditorView } from '@mache-hangar/lunar-editor-core/pm';
|
|
2
|
+
export declare function insertBlockMathFromDollarInput(view: EditorView, from: number, to: number, text: string): boolean;
|
|
3
|
+
export declare function insertInlineMathFromDotDollarInput(view: EditorView, from: number, to: number, text: string): boolean;
|
|
4
|
+
export declare function createMathInputPlugin(): Plugin<any>;
|