@wingleeio/ori-react 0.1.2 → 0.2.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/dist/index.cjs +201 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +201 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/styles.css +8 -10
package/dist/index.cjs
CHANGED
|
@@ -36,8 +36,129 @@ function useActiveMarks(editor) {
|
|
|
36
36
|
return editor.getActiveMarks();
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// src/ce/
|
|
39
|
+
// src/ce/clipboard.ts
|
|
40
|
+
var ORI_MIME = "application/x-ori-inline";
|
|
41
|
+
function atomPlain(it) {
|
|
42
|
+
const d = it.atom?.data ?? {};
|
|
43
|
+
const label = d.label ?? d.text ?? d.name;
|
|
44
|
+
return label != null ? `@${String(label)}` : "";
|
|
45
|
+
}
|
|
46
|
+
function blockPlain(items) {
|
|
47
|
+
return items.map((it) => it.atom ? atomPlain(it) : it.text).join("");
|
|
48
|
+
}
|
|
49
|
+
var MARK_TAGS = [
|
|
50
|
+
["bold", "strong"],
|
|
51
|
+
["italic", "em"],
|
|
52
|
+
["underline", "u"],
|
|
53
|
+
["strike", "s"],
|
|
54
|
+
["code", "code"]
|
|
55
|
+
];
|
|
40
56
|
function esc(s) {
|
|
57
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
58
|
+
}
|
|
59
|
+
function runHtml(it) {
|
|
60
|
+
if (it.atom) return `<span>${esc(atomPlain(it))}</span>`;
|
|
61
|
+
let html = esc(it.text);
|
|
62
|
+
const m = it.marks ?? {};
|
|
63
|
+
for (const [k, tag] of MARK_TAGS) if (m[k]) html = `<${tag}>${html}</${tag}>`;
|
|
64
|
+
if (m.link) html = `<a href="${esc(m.link)}">${html}</a>`;
|
|
65
|
+
return html;
|
|
66
|
+
}
|
|
67
|
+
function serializeSelection(blocks) {
|
|
68
|
+
const text = blocks.map(blockPlain).join("\n");
|
|
69
|
+
const html = blocks.map((items) => `<p>${items.map(runHtml).join("") || "<br>"}</p>`).join("");
|
|
70
|
+
const json = JSON.stringify({
|
|
71
|
+
v: 1,
|
|
72
|
+
blocks: blocks.map(
|
|
73
|
+
(items) => items.map(
|
|
74
|
+
(it) => it.atom ? { embed: it.atom.data ?? { type: it.atom.type } } : { text: it.text, marks: it.marks }
|
|
75
|
+
)
|
|
76
|
+
)
|
|
77
|
+
});
|
|
78
|
+
return { text, html, json };
|
|
79
|
+
}
|
|
80
|
+
function deserializeOri(json) {
|
|
81
|
+
try {
|
|
82
|
+
const data = JSON.parse(json);
|
|
83
|
+
if (!Array.isArray(data.blocks)) return null;
|
|
84
|
+
return data.blocks.map(
|
|
85
|
+
(items) => items.map(
|
|
86
|
+
(it) => it.embed ? { text: "", start: 0, atom: { type: String(it.embed.type ?? ""), width: 0, data: it.embed } } : { text: it.text ?? "", start: 0, marks: it.marks }
|
|
87
|
+
)
|
|
88
|
+
);
|
|
89
|
+
} catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function textToBlocks(text) {
|
|
94
|
+
return text.replace(/\r\n?/g, "\n").split("\n").map((line) => line ? [{ text: line, start: 0 }] : []);
|
|
95
|
+
}
|
|
96
|
+
function htmlToBlocks(html) {
|
|
97
|
+
if (typeof DOMParser === "undefined") return [];
|
|
98
|
+
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
99
|
+
const blocks = [];
|
|
100
|
+
let cur = [];
|
|
101
|
+
const flush = () => {
|
|
102
|
+
blocks.push(cur);
|
|
103
|
+
cur = [];
|
|
104
|
+
};
|
|
105
|
+
const push = (text, marks) => {
|
|
106
|
+
if (!text) return;
|
|
107
|
+
cur.push({ text, start: 0, marks: Object.keys(marks).length ? { ...marks } : void 0 });
|
|
108
|
+
};
|
|
109
|
+
const BLOCK = /* @__PURE__ */ new Set([
|
|
110
|
+
"P",
|
|
111
|
+
"DIV",
|
|
112
|
+
"H1",
|
|
113
|
+
"H2",
|
|
114
|
+
"H3",
|
|
115
|
+
"H4",
|
|
116
|
+
"H5",
|
|
117
|
+
"H6",
|
|
118
|
+
"LI",
|
|
119
|
+
"BLOCKQUOTE",
|
|
120
|
+
"PRE",
|
|
121
|
+
"SECTION",
|
|
122
|
+
"ARTICLE",
|
|
123
|
+
"UL",
|
|
124
|
+
"OL"
|
|
125
|
+
]);
|
|
126
|
+
const walk = (node, marks) => {
|
|
127
|
+
for (const child of Array.from(node.childNodes)) {
|
|
128
|
+
if (child.nodeType === Node.TEXT_NODE) {
|
|
129
|
+
push((child.textContent ?? "").replace(/\s+/g, " "), marks);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (child.nodeType !== Node.ELEMENT_NODE) continue;
|
|
133
|
+
const el = child;
|
|
134
|
+
const tag = el.tagName;
|
|
135
|
+
if (tag === "BR") {
|
|
136
|
+
if (cur.length) flush();
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const m = { ...marks };
|
|
140
|
+
if (tag === "STRONG" || tag === "B") m.bold = true;
|
|
141
|
+
if (tag === "EM" || tag === "I") m.italic = true;
|
|
142
|
+
if (tag === "U" || tag === "INS") m.underline = true;
|
|
143
|
+
if (tag === "S" || tag === "STRIKE" || tag === "DEL") m.strike = true;
|
|
144
|
+
if (tag === "CODE" || tag === "KBD" || tag === "TT") m.code = true;
|
|
145
|
+
const href = tag === "A" ? el.getAttribute("href") : null;
|
|
146
|
+
if (href) m.link = href;
|
|
147
|
+
const isBlock = BLOCK.has(tag);
|
|
148
|
+
if (isBlock && cur.length) flush();
|
|
149
|
+
walk(el, m);
|
|
150
|
+
if (isBlock) flush();
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
walk(doc.body, {});
|
|
154
|
+
if (cur.length) flush();
|
|
155
|
+
while (blocks.length && blocks[0].length === 0) blocks.shift();
|
|
156
|
+
while (blocks.length && blocks[blocks.length - 1].length === 0) blocks.pop();
|
|
157
|
+
return blocks;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/ce/dom.ts
|
|
161
|
+
function esc2(s) {
|
|
41
162
|
return typeof CSS !== "undefined" && CSS.escape ? CSS.escape(s) : s.replace(/["\\]/g, "\\$&");
|
|
42
163
|
}
|
|
43
164
|
function blockElOf(node, root) {
|
|
@@ -82,7 +203,7 @@ function spanLen(span) {
|
|
|
82
203
|
return span.dataset.len != null ? Number(span.dataset.len) : (span.textContent ?? "").length;
|
|
83
204
|
}
|
|
84
205
|
function modelToDom(root, blockId, offset) {
|
|
85
|
-
const blockEl = root.querySelector(`[data-block-id="${
|
|
206
|
+
const blockEl = root.querySelector(`[data-block-id="${esc2(blockId)}"]`);
|
|
86
207
|
if (!blockEl) return null;
|
|
87
208
|
const spans = Array.from(blockEl.querySelectorAll("[data-off]"));
|
|
88
209
|
if (spans.length === 0) {
|
|
@@ -92,7 +213,7 @@ function modelToDom(root, blockId, offset) {
|
|
|
92
213
|
const start = Number(span.dataset.off);
|
|
93
214
|
const len = spanLen(span);
|
|
94
215
|
if (offset <= start + len) {
|
|
95
|
-
if (span.dataset.atom != null) {
|
|
216
|
+
if (span.dataset.atom != null || span.dataset.break != null) {
|
|
96
217
|
const idx = Array.prototype.indexOf.call(blockEl.childNodes, span);
|
|
97
218
|
return { node: blockEl, offset: offset <= start ? idx : idx + 1 };
|
|
98
219
|
}
|
|
@@ -166,6 +287,9 @@ var EditorView = class {
|
|
|
166
287
|
this.composing = false;
|
|
167
288
|
this.onInput();
|
|
168
289
|
});
|
|
290
|
+
on("copy", (e) => this.onClipboard(e, false));
|
|
291
|
+
on("cut", (e) => this.onClipboard(e, true));
|
|
292
|
+
on("paste", (e) => this.onPaste(e));
|
|
169
293
|
const onSelChange = () => {
|
|
170
294
|
if (this.applyingModel || this.composing) return;
|
|
171
295
|
const sel = this.readSelection();
|
|
@@ -257,7 +381,7 @@ var EditorView = class {
|
|
|
257
381
|
const bot = this.root.lastElementChild;
|
|
258
382
|
if (bot && bot.style.height !== `${botH}px`) bot.style.height = `${botH}px`;
|
|
259
383
|
for (const vb of vis) {
|
|
260
|
-
const el = this.root.querySelector(`[data-block-id="${
|
|
384
|
+
const el = this.root.querySelector(`[data-block-id="${esc2(vb.id)}"]`);
|
|
261
385
|
if (!el) continue;
|
|
262
386
|
const sig = this.sig(vb.id);
|
|
263
387
|
if (el.dataset.sig !== sig) {
|
|
@@ -317,11 +441,31 @@ var EditorView = class {
|
|
|
317
441
|
r.render(renderer({ editor: this.editor, atom: item.atom }));
|
|
318
442
|
this.roots.set(span, r);
|
|
319
443
|
}
|
|
444
|
+
} else if (item.text.includes("\n")) {
|
|
445
|
+
let off = item.start;
|
|
446
|
+
const parts = item.text.split("\n");
|
|
447
|
+
parts.forEach((part, i) => {
|
|
448
|
+
if (i > 0) {
|
|
449
|
+
el.appendChild(this.makeBreak(off));
|
|
450
|
+
off += 1;
|
|
451
|
+
}
|
|
452
|
+
if (part) {
|
|
453
|
+
el.appendChild(buildRun({ text: part, start: off, marks: item.marks }));
|
|
454
|
+
off += part.length;
|
|
455
|
+
}
|
|
456
|
+
});
|
|
320
457
|
} else {
|
|
321
458
|
el.appendChild(buildRun(item));
|
|
322
459
|
}
|
|
323
460
|
}
|
|
324
461
|
}
|
|
462
|
+
makeBreak(off) {
|
|
463
|
+
const br = document.createElement("br");
|
|
464
|
+
br.dataset.off = String(off);
|
|
465
|
+
br.dataset.len = "1";
|
|
466
|
+
br.dataset.break = "true";
|
|
467
|
+
return br;
|
|
468
|
+
}
|
|
325
469
|
unmountRootsIn(el) {
|
|
326
470
|
for (const [node, root] of this.roots) {
|
|
327
471
|
if (el === node || el.contains(node)) {
|
|
@@ -366,6 +510,8 @@ var EditorView = class {
|
|
|
366
510
|
for (const child of Array.from(el.childNodes)) {
|
|
367
511
|
if (child instanceof HTMLElement && child.dataset.atom != null) {
|
|
368
512
|
out += PLACEHOLDER;
|
|
513
|
+
} else if (child instanceof HTMLElement && child.dataset.break != null) {
|
|
514
|
+
out += "\n";
|
|
369
515
|
} else {
|
|
370
516
|
out += child.textContent ?? "";
|
|
371
517
|
}
|
|
@@ -419,13 +565,14 @@ var EditorView = class {
|
|
|
419
565
|
e.preventDefault();
|
|
420
566
|
if (t === "deleteContentForward") ed.deleteForward();
|
|
421
567
|
else ed.deleteBackward();
|
|
422
|
-
} else if (t === "insertText" || t === "insertReplacementText"
|
|
568
|
+
} else if (t === "insertText" || t === "insertReplacementText") {
|
|
423
569
|
e.preventDefault();
|
|
424
|
-
|
|
570
|
+
if (!collapsed) ed.deleteBackward();
|
|
571
|
+
const text = e.data ?? "";
|
|
425
572
|
if (text) ed.insertText(text);
|
|
426
573
|
} else if (t === "insertLineBreak") {
|
|
427
574
|
e.preventDefault();
|
|
428
|
-
ed.
|
|
575
|
+
ed.insertParagraphBreak();
|
|
429
576
|
} else {
|
|
430
577
|
return;
|
|
431
578
|
}
|
|
@@ -463,11 +610,50 @@ var EditorView = class {
|
|
|
463
610
|
for (const child of Array.from(el.children)) {
|
|
464
611
|
if (child.dataset.off == null) continue;
|
|
465
612
|
child.dataset.off = String(off);
|
|
466
|
-
const len = child.dataset.atom != null ? 1 : (child.textContent ?? "").length;
|
|
613
|
+
const len = child.dataset.atom != null || child.dataset.break != null ? 1 : (child.textContent ?? "").length;
|
|
467
614
|
child.dataset.len = String(len);
|
|
468
615
|
off += len;
|
|
469
616
|
}
|
|
470
617
|
}
|
|
618
|
+
// --- clipboard ---------------------------------------------------------
|
|
619
|
+
/** Copy/cut: put plain, HTML and a private (mark-preserving) payload on the clipboard. */
|
|
620
|
+
onClipboard(e, isCut) {
|
|
621
|
+
const blocks = this.editor.getSelectionInline();
|
|
622
|
+
if (!blocks.length || !e.clipboardData) return;
|
|
623
|
+
e.preventDefault();
|
|
624
|
+
const { text, html, json } = serializeSelection(blocks);
|
|
625
|
+
e.clipboardData.setData("text/plain", text);
|
|
626
|
+
e.clipboardData.setData("text/html", html);
|
|
627
|
+
e.clipboardData.setData(ORI_MIME, json);
|
|
628
|
+
if (isCut && !this.opts.readOnly) {
|
|
629
|
+
this.editor.deleteBackward();
|
|
630
|
+
this.commit();
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
/** Paste: restore marks from our payload, else parse external HTML, else plain text. */
|
|
634
|
+
onPaste(e) {
|
|
635
|
+
if (this.opts.readOnly || !e.clipboardData) return;
|
|
636
|
+
e.preventDefault();
|
|
637
|
+
const sel = this.readSelection();
|
|
638
|
+
if (sel) {
|
|
639
|
+
this.editor.setSelection(sel);
|
|
640
|
+
if (!oriCore.isCollapsed(sel)) this.editor.deleteBackward();
|
|
641
|
+
}
|
|
642
|
+
const cd = e.clipboardData;
|
|
643
|
+
const ori = cd.getData(ORI_MIME);
|
|
644
|
+
const html = cd.getData("text/html");
|
|
645
|
+
let blocks = ori ? deserializeOri(ori) : null;
|
|
646
|
+
if (!blocks?.length && html) blocks = htmlToBlocks(html);
|
|
647
|
+
if (!blocks?.length) blocks = textToBlocks(cd.getData("text/plain"));
|
|
648
|
+
this.pasteBlocks(blocks);
|
|
649
|
+
this.commit();
|
|
650
|
+
}
|
|
651
|
+
pasteBlocks(blocks) {
|
|
652
|
+
blocks.forEach((items, i) => {
|
|
653
|
+
if (i > 0) this.editor.insertParagraphBreak();
|
|
654
|
+
if (items.length) this.editor.insertInline(items);
|
|
655
|
+
});
|
|
656
|
+
}
|
|
471
657
|
};
|
|
472
658
|
function caretClientRect() {
|
|
473
659
|
const s = window.getSelection();
|
|
@@ -479,6 +665,13 @@ function caretClientRect() {
|
|
|
479
665
|
const b = r.getBoundingClientRect();
|
|
480
666
|
if (b.height || b.width) return b;
|
|
481
667
|
const node = r.startContainer;
|
|
668
|
+
if (node.nodeType === Node.ELEMENT_NODE && r.startOffset > 0) {
|
|
669
|
+
const prev = node.childNodes[r.startOffset - 1];
|
|
670
|
+
if (prev instanceof HTMLElement && prev.dataset.atom != null) {
|
|
671
|
+
const pb = prev.getBoundingClientRect();
|
|
672
|
+
if (pb.height || pb.width) return new DOMRect(pb.right, pb.top, 0, pb.height || 18);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
482
675
|
const el = (node.nodeType === Node.TEXT_NODE ? node.parentElement : node) ?? null;
|
|
483
676
|
if (!el) return null;
|
|
484
677
|
const eb = el.getBoundingClientRect();
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useEditor.ts","../src/hooks.ts","../src/ce/dom.ts","../src/ce/view.ts","../src/NoteEditor.tsx","../src/renderers.tsx"],"names":["useRef","EditorController","createCanvasMeasurer","useEffect","useSyncExternalStore","textNode","isCollapsed","createRoot","forwardRef","NoteEditor","useState","useImperativeHandle","useLayoutEffect","jsx","jsxs","createContext","useContext"],"mappings":";;;;;;;;;;AA8BO,SAAS,SAAA,CAAU,OAAA,GAA4B,EAAC,EAAqB;AAC1E,EAAA,MAAM,GAAA,GAAMA,aAAgC,IAAI,CAAA;AAChD,EAAA,IAAI,GAAA,CAAI,YAAY,IAAA,EAAM;AACxB,IAAA,GAAA,CAAI,OAAA,GAAU,IAAIC,wBAAA,CAAiB;AAAA,MACjC,KAAK,OAAA,CAAQ,GAAA;AAAA,MACb,QAAA,EAAU,OAAA,CAAQ,QAAA,IAAYC,4BAAA,EAAqB;AAAA,MACnD,YAAY,OAAA,CAAQ,UAAA;AAAA,MACpB,UAAU,OAAA,CAAQ,QAAA;AAAA,MAClB,cAAc,OAAA,CAAQ,YAAA;AAAA,MACtB,QAAQ,OAAA,CAAQ;AAAA,KACjB,CAAA;AAAA,EACH;AACA,EAAAC,eAAA,CAAU,MAAM;AACd,IAAA,MAAM,SAAS,GAAA,CAAI,OAAA;AACnB,IAAA,MAAA,EAAQ,OAAA,EAAQ;AAChB,IAAA,OAAO,MAAM,QAAQ,UAAA,EAAW;AAAA,EAClC,CAAA,EAAG,EAAE,CAAA;AACL,EAAA,OAAO,GAAA,CAAI,OAAA;AACb;AC5CO,SAAS,kBAAkB,MAAA,EAA0C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AAA,EAAI,WAAU,iBAAA,EAAkB,aAAA,EAAW,IAAA,EACzC,QAAA,EAAA,WAAA,EACH,CAAA,GACE;AAAA,GAAA,EACN,GACF,CAAA,EACF,CAAA;AAEJ,CAAC;ACpOD,IAAM,QAAmB,EAAE,MAAA,EAAQ,EAAC,EAAG,KAAA,EAAO,EAAC,EAAE;AAEjD,IAAM,gBAAA,GAAmBE,oBAAyB,KAAK,CAAA;AACtB,gBAAA,CAAiB;AAC3C,IAAM,YAAA,GAAe,MAAiBC,gBAAA,CAAW,gBAAgB","file":"index.cjs","sourcesContent":["import {\n EditorController,\n createCanvasMeasurer,\n type EditorSchema,\n type Measurer,\n type Typography,\n} from \"@wingleeio/ori-core\";\nimport { useEffect, useRef } from \"react\";\nimport type * as Y from \"yjs\";\n\nexport interface UseEditorOptions {\n /** Existing note `Y.Doc`. When switching notes, remount via `key` instead. */\n doc?: Y.Doc;\n typography?: Typography;\n measurer?: Measurer;\n overscan?: number;\n blockSpacing?: number;\n /** Custom block/atom nodes, merged over the built-ins. */\n schema?: Partial<EditorSchema>;\n}\n\n/**\n * Create (once) and own an {@link EditorController} for the lifetime of the\n * component. To switch documents, give the hosting component a `key` so it\n * remounts with a fresh controller.\n *\n * The controller is reconnected on mount and disconnected on unmount rather than\n * destroyed, so React StrictMode's dev mount → unmount → remount cycle reuses the\n * same controller (with all its state) instead of leaving a torn-down one behind.\n */\nexport function useEditor(options: UseEditorOptions = {}): EditorController {\n const ref = useRef<EditorController | null>(null);\n if (ref.current === null) {\n ref.current = new EditorController({\n doc: options.doc,\n measurer: options.measurer ?? createCanvasMeasurer(),\n typography: options.typography,\n overscan: options.overscan,\n blockSpacing: options.blockSpacing,\n schema: options.schema,\n });\n }\n useEffect(() => {\n const editor = ref.current;\n editor?.connect();\n return () => editor?.disconnect();\n }, []);\n return ref.current;\n}\n","import type { EditorController, EditorSnapshot, Marks } from \"@wingleeio/ori-core\";\nimport { useSyncExternalStore } from \"react\";\n\n/** Subscribe a component to the controller's snapshot stream. */\nexport function useEditorSnapshot(editor: EditorController): EditorSnapshot {\n return useSyncExternalStore(editor.subscribe, editor.getSnapshot, editor.getSnapshot);\n}\n\n/**\n * The marks active at the current selection. Recomputed whenever the editor\n * notifies (selection move, edit, or pending-mark toggle), so toolbars stay in\n * sync without their own subscription.\n */\nexport function useActiveMarks(editor: EditorController): Marks {\n const snapshot = useEditorSnapshot(editor);\n // `revision` changes on every notify; reading it ties this to the store.\n void snapshot.revision;\n return editor.getActiveMarks();\n}\n","import type { InlineItem } from \"@wingleeio/ori-core\";\n\n/** CSS.escape with a fallback (jsdom lacks it). */\nexport function esc(s: string): string {\n return typeof CSS !== \"undefined\" && CSS.escape ? CSS.escape(s) : s.replace(/[\"\\\\]/g, \"\\\\$&\");\n}\n\n/**\n * Imperative DOM helpers for the contentEditable view. Each block is a\n * block-level element carrying `data-block-id`; its inline runs are spans\n * carrying `data-off` (their start offset in the block) so DOM positions map\n * back to {blockId, offset} and vice-versa.\n */\n\nexport const BLOCK_SEL = \"[data-block-id]\";\n\nexport function blockElOf(node: Node | null, root: HTMLElement): HTMLElement | null {\n let n: Node | null = node;\n while (n && n !== root) {\n if (n instanceof HTMLElement && n.dataset.blockId) return n;\n n = n.parentNode;\n }\n return null;\n}\n\nfunction spanOf(node: Node | null): HTMLElement | null {\n let n: Node | null = node;\n while (n) {\n if (n instanceof HTMLElement && n.dataset.off != null) return n;\n n = n.parentNode;\n }\n return null;\n}\n\n/** Map a DOM (node, offset) to a {blockId, offset} model position. */\nexport function domToModel(\n root: HTMLElement,\n node: Node | null,\n offset: number,\n): { blockId: string; offset: number } | null {\n const blockEl = blockElOf(node, root);\n if (!blockEl) return null;\n const blockId = blockEl.dataset.blockId as string;\n\n if (node && node.nodeType === Node.TEXT_NODE) {\n const span = spanOf(node);\n const base = span ? Number(span.dataset.off) : 0;\n return { blockId, offset: base + offset };\n }\n\n // node is an element; `offset` is a child index. Resolve via the child spans.\n const el = node as HTMLElement;\n if (el.dataset?.off != null) {\n // selection landed on a span boundary\n return { blockId, offset: Number(el.dataset.off) + (offset > 0 ? spanLen(el) : 0) };\n }\n const kids = Array.from(el.childNodes);\n for (let i = offset; i < kids.length; i++) {\n const k = kids[i];\n if (k instanceof HTMLElement && k.dataset.off != null) return { blockId, offset: Number(k.dataset.off) };\n }\n // past the last span → block end\n let end = 0;\n for (const k of kids) if (k instanceof HTMLElement && k.dataset.off != null) end = Math.max(end, Number(k.dataset.off) + spanLen(k));\n return { blockId, offset: end };\n}\n\nfunction spanLen(span: HTMLElement): number {\n return span.dataset.len != null ? Number(span.dataset.len) : (span.textContent ?? \"\").length;\n}\n\n/** Find the DOM (node, offset) for a {blockId, offset} model position. */\nexport function modelToDom(\n root: HTMLElement,\n blockId: string,\n offset: number,\n): { node: Node; offset: number } | null {\n const blockEl = root.querySelector(`[data-block-id=\"${esc(blockId)}\"]`) as HTMLElement | null;\n if (!blockEl) return null;\n const spans = Array.from(blockEl.querySelectorAll(\"[data-off]\")) as HTMLElement[];\n if (spans.length === 0) {\n return { node: blockEl, offset: 0 }; // empty block\n }\n for (const span of spans) {\n const start = Number(span.dataset.off);\n const len = spanLen(span);\n if (offset <= start + len) {\n if (span.dataset.atom != null) {\n // atom: place before or after it (offset is start or start+1)\n const idx = Array.prototype.indexOf.call(blockEl.childNodes, span);\n return { node: blockEl, offset: offset <= start ? idx : idx + 1 };\n }\n const textNode = span.firstChild ?? span;\n return { node: textNode, offset: Math.max(0, Math.min(offset - start, (textNode.textContent ?? \"\").length)) };\n }\n }\n // past everything → after the last span\n const last = spans[spans.length - 1];\n const textNode = last.firstChild ?? last;\n return { node: textNode, offset: (textNode.textContent ?? \"\").length };\n}\n\nfunction markClass(marks: InlineItem[\"marks\"]): string {\n const m = marks ?? {};\n const cls = [\"ori-frag\"];\n if (m.bold) cls.push(\"ori-m-bold\");\n if (m.italic) cls.push(\"ori-m-italic\");\n if (m.underline) cls.push(\"ori-m-underline\");\n if (m.strike) cls.push(\"ori-m-strike\");\n if (m.code) cls.push(\"ori-frag-code\");\n if (m.link) cls.push(\"ori-frag-link\");\n return cls.join(\" \");\n}\n\n/** Build the inline run DOM for a block (text spans only; atoms handled by the view). */\nexport function buildRun(item: InlineItem): HTMLElement {\n const span = document.createElement(\"span\");\n span.className = markClass(item.marks);\n span.dataset.off = String(item.start);\n span.dataset.len = String(item.text.length);\n span.textContent = item.text;\n return span;\n}\n","import type { EditorController } from \"@wingleeio/ori-core\";\nimport { isCollapsed } from \"@wingleeio/ori-core\";\nimport type { ReactNode } from \"react\";\nimport { createRoot, type Root } from \"react-dom/client\";\nimport type { AtomRenderer, BlockRenderer } from \"../renderers\";\nimport { blockElOf, buildRun, domToModel, esc, modelToDom } from \"./dom\";\n\nconst PLACEHOLDER = \"\";\n\nexport interface ViewOptions {\n readOnly?: boolean;\n renderAtom: (type: string) => AtomRenderer | undefined;\n renderBlock: (type: string) => BlockRenderer | undefined;\n}\n\n/**\n * Imperative contentEditable view over an {@link EditorController}. The browser\n * owns caret / selection / trackpad / menus / IME on the live text; we intercept\n * structural + cross-block edits (beforeinput) and route them through the\n * controller, let smooth in-block typing flow natively and read it back, and\n * keep the DOM selection and the controller selection in lock-step.\n */\nexport class EditorView {\n private roots = new Map<HTMLElement, Root>();\n private composing = false;\n private applyingModel = false;\n private detachers: Array<() => void> = [];\n /** The model revision the DOM currently reflects (so external changes — remote\n * edits, app commands — re-render, but our own edits don't clobber the caret). */\n private lastRevision = -1;\n\n constructor(\n private root: HTMLElement,\n private editor: EditorController,\n private opts: ViewOptions,\n ) {\n root.setAttribute(\"contenteditable\", opts.readOnly ? \"false\" : \"true\");\n root.setAttribute(\"spellcheck\", opts.readOnly ? \"false\" : \"true\");\n root.setAttribute(\"role\", \"textbox\");\n root.setAttribute(\"aria-multiline\", \"true\");\n this.renderBlocks();\n this.lastRevision = this.rev();\n\n const on = <K extends keyof HTMLElementEventMap>(\n t: K,\n h: (e: HTMLElementEventMap[K]) => void,\n o?: AddEventListenerOptions,\n ) => {\n root.addEventListener(t, h as EventListener, o);\n this.detachers.push(() => root.removeEventListener(t, h as EventListener, o));\n };\n on(\"beforeinput\", (e) => this.onBeforeInput(e as InputEvent));\n on(\"input\", () => this.onInput());\n on(\"keydown\", (e) => this.onKeyDown(e as KeyboardEvent));\n on(\"blur\", () => {\n // Clicking outside the editor drops the selection (so a selection toolbar\n // hides). Defer so we can ignore a window/tab blur and focus-preserving\n // clicks (e.g. toolbar buttons that re-focus the editor).\n setTimeout(() => {\n if (document.activeElement === this.root || !document.hasFocus()) return;\n const sel = this.editor.getSelection();\n if (sel && !isCollapsed(sel)) {\n this.editor.collapse(sel.focus);\n this.lastRevision = this.rev();\n }\n }, 0);\n });\n on(\"compositionstart\", () => (this.composing = true));\n on(\"compositionend\", () => {\n this.composing = false;\n this.onInput();\n });\n\n const onSelChange = () => {\n if (this.applyingModel || this.composing) return;\n const sel = this.readSelection();\n if (!sel) return;\n this.editor.setSelection(sel);\n // DOM is already the source of truth here — record the revision so the\n // resulting React sync() doesn't write the selection back and collapse it.\n this.lastRevision = this.rev();\n };\n document.addEventListener(\"selectionchange\", onSelChange);\n this.detachers.push(() => document.removeEventListener(\"selectionchange\", onSelChange));\n }\n\n destroy() {\n this.detachers.forEach((d) => d());\n this.roots.forEach((r) => r.unmount());\n this.roots.clear();\n }\n\n focus() {\n this.root.focus();\n }\n\n // --- rendering ---------------------------------------------------------\n\n private rev(): number {\n return this.editor.getSnapshot().revision;\n }\n\n /**\n * Called by React on every model change. Only re-renders when the model moved\n * ahead of what we last drew (an *external* change — app command, undo, remote);\n * our own edits already updated the DOM and must not be clobbered.\n */\n sync() {\n const rev = this.rev();\n if (rev === this.lastRevision) return;\n // Only restore the DOM selection when the *content* changed (app command,\n // undo, remote). A selection-only change is already correct in the DOM, and\n // writing it back would fight (and collapse) the user's native selection.\n const changed = this.renderBlocks();\n if (changed) this.writeSelection();\n this.lastRevision = rev;\n }\n\n /** After a controlled (preventDefault'd) edit: re-render + restore the caret. */\n private commit() {\n this.renderBlocks();\n this.writeSelection();\n this.lastRevision = this.rev();\n }\n\n /** A content signature for a block, so unchanged blocks aren't re-rendered. */\n private sig(id: string): string {\n return this.editor.getBlockType(id) + \"|\" + JSON.stringify(this.editor.getInline(id));\n }\n\n /**\n * Reconcile the DOM to the *visible window* of blocks (virtualization): a top\n * spacer, the windowed blocks, then a bottom spacer — heights from the\n * controller's offscreen measurement. On-screen blocks are reused by id so a\n * caret inside one survives a scroll. Returns true if the DOM was mutated.\n */\n private renderBlocks(): boolean {\n let changed = false;\n const snap = this.editor.getSnapshot();\n const vis = snap.visible;\n const topH = vis.length ? vis[0].top : 0;\n const botH = vis.length\n ? Math.max(0, snap.totalHeight - (vis[vis.length - 1].top + vis[vis.length - 1].height))\n : Math.max(0, snap.totalHeight);\n\n const TOP = \"\u0000top\";\n const BOTTOM = \"\u0000bottom\";\n const want = [TOP, ...vis.map((v) => v.id), BOTTOM];\n const keyOf = (el: Element) => {\n const e = el as HTMLElement;\n return e.dataset.spacer ? \"\u0000\" + e.dataset.spacer : (e.dataset.blockId ?? \"\");\n };\n const have = new Map<string, HTMLElement>();\n for (const c of Array.from(this.root.children)) have.set(keyOf(c), c as HTMLElement);\n\n let prev: HTMLElement | null = null;\n for (const k of want) {\n let el: HTMLElement | undefined = have.get(k);\n if (el) {\n have.delete(k);\n } else {\n el = k === TOP || k === BOTTOM ? this.makeSpacer(k.slice(1)) : this.makeBlock(k);\n changed = true;\n }\n const anchor: ChildNode | null = prev ? prev.nextSibling : this.root.firstChild;\n if (anchor !== el) {\n this.root.insertBefore(el, anchor);\n changed = true;\n }\n prev = el;\n }\n for (const el of have.values()) {\n if (el.dataset.blockId) this.unmountRootsIn(el);\n el.remove();\n changed = true;\n }\n\n const top = this.root.firstElementChild as HTMLElement | null;\n if (top && top.style.height !== `${topH}px`) top.style.height = `${topH}px`;\n const bot = this.root.lastElementChild as HTMLElement | null;\n if (bot && bot.style.height !== `${botH}px`) bot.style.height = `${botH}px`;\n\n for (const vb of vis) {\n const el = this.root.querySelector(`[data-block-id=\"${esc(vb.id)}\"]`) as HTMLElement | null;\n if (!el) continue;\n const sig = this.sig(vb.id);\n if (el.dataset.sig !== sig) {\n el.dataset.sig = sig;\n this.renderBlockInner(el, vb.id);\n changed = true;\n }\n }\n return changed;\n }\n\n private makeBlock(id: string): HTMLElement {\n const el = document.createElement(\"div\");\n el.dataset.blockId = id;\n return el;\n }\n\n private makeSpacer(which: string): HTMLElement {\n const el = document.createElement(\"div\");\n el.dataset.spacer = which;\n el.setAttribute(\"contenteditable\", \"false\");\n el.setAttribute(\"aria-hidden\", \"true\");\n el.style.userSelect = \"none\";\n el.style.pointerEvents = \"none\";\n return el;\n }\n\n private renderBlockInner(el: HTMLElement, id: string) {\n this.unmountRootsIn(el);\n const type = this.editor.getBlockType(id);\n el.className = `ori-block ori-block-${type}`;\n\n const blockRenderer = this.opts.renderBlock(type);\n if (blockRenderer) {\n el.contentEditable = \"false\";\n el.textContent = \"\";\n const root = createRoot(el);\n root.render(blockRenderer({ editor: this.editor, block: { id, type, index: 0, top: 0, height: 0 }, layout: this.editor.getLayout(id)! }) as ReactNode);\n this.roots.set(el, root);\n return;\n }\n el.contentEditable = \"inherit\";\n el.textContent = \"\";\n const items = this.editor.getInline(id);\n if (items.length === 0) {\n el.appendChild(document.createElement(\"br\")); // keep an empty block selectable\n return;\n }\n for (const item of items) {\n if (item.atom) {\n const span = document.createElement(\"span\");\n span.className = \"ori-atom\";\n span.contentEditable = \"false\";\n span.dataset.atom = \"true\";\n span.dataset.off = String(item.start);\n span.dataset.len = \"1\";\n el.appendChild(span);\n const renderer = this.opts.renderAtom(item.atom.type);\n if (renderer) {\n const r = createRoot(span);\n r.render(renderer({ editor: this.editor, atom: item.atom }) as ReactNode);\n this.roots.set(span, r);\n }\n } else {\n el.appendChild(buildRun(item));\n }\n }\n }\n\n private unmountRootsIn(el: HTMLElement) {\n for (const [node, root] of this.roots) {\n if (el === node || el.contains(node)) {\n root.unmount();\n this.roots.delete(node);\n }\n }\n }\n\n // --- selection ---------------------------------------------------------\n\n private readSelection() {\n const s = window.getSelection();\n if (!s || s.rangeCount === 0 || !this.root.contains(s.anchorNode)) return null;\n const a = domToModel(this.root, s.anchorNode, s.anchorOffset);\n const f = domToModel(this.root, s.focusNode, s.focusOffset);\n if (!a || !f) return null;\n return { anchor: { blockId: a.blockId, offset: a.offset }, focus: { blockId: f.blockId, offset: f.offset } };\n }\n\n /** Push the controller's selection back into the DOM (after a model op). */\n private writeSelection() {\n const sel = this.editor.getSelection();\n if (!sel) return;\n const a = modelToDom(this.root, sel.anchor.blockId, sel.anchor.offset);\n const f = modelToDom(this.root, sel.focus.blockId, sel.focus.offset);\n if (!a || !f) return;\n const r = document.createRange();\n const s = window.getSelection();\n if (!s) return;\n this.applyingModel = true;\n try {\n r.setStart(a.node, a.offset);\n s.removeAllRanges();\n s.addRange(r);\n s.extend(f.node, f.offset);\n } catch {\n /* node detached mid-reconcile */\n } finally {\n this.applyingModel = false;\n }\n }\n\n /** The block text as the model sees it (atoms collapse to one placeholder). */\n private domBlockText(el: HTMLElement): string {\n let out = \"\";\n for (const child of Array.from(el.childNodes)) {\n if (child instanceof HTMLElement && child.dataset.atom != null) {\n out += PLACEHOLDER;\n } else {\n out += child.textContent ?? \"\";\n }\n }\n return out;\n }\n\n // --- input -------------------------------------------------------------\n\n /** Formatting + history shortcuts (the browser fires these as keydown). */\n private onKeyDown(e: KeyboardEvent) {\n if (this.opts.readOnly) return;\n const mod = e.metaKey || e.ctrlKey;\n if (!mod || e.altKey) return;\n const k = e.key.toLowerCase();\n const mark = ({ b: \"bold\", i: \"italic\", u: \"underline\", e: \"code\" } as const)[k];\n if (mark) {\n e.preventDefault();\n const sel = this.readSelection();\n if (sel) this.editor.setSelection(sel);\n this.editor.toggleMark(mark);\n this.commit();\n } else if (k === \"z\") {\n e.preventDefault();\n if (e.shiftKey) this.editor.redo();\n else this.editor.undo();\n this.commit();\n } else if (k === \"y\") {\n e.preventDefault();\n this.editor.redo();\n this.commit();\n }\n }\n\n private onBeforeInput(e: InputEvent) {\n if (this.opts.readOnly) {\n e.preventDefault();\n return;\n }\n const sel = this.readSelection();\n if (!sel) return;\n this.editor.setSelection(sel);\n const collapsed = isCollapsed(sel);\n const startOffset = this.editor.orderedSelection()?.start.offset ?? sel.focus.offset;\n const t = e.inputType;\n\n // Native fast path: collapsed in-block typing / deletion. The browser mutates\n // a single text node; onInput reads it back. Keeps autocorrect/IME native.\n if (collapsed && (t === \"insertText\" || t === \"insertCompositionText\" || t === \"insertReplacementText\")) return;\n if (collapsed && t === \"deleteContentForward\") return;\n if (collapsed && t === \"deleteContentBackward\" && startOffset > 0) return;\n\n // Everything else (structural + cross-block) is handled through the controller.\n const ed = this.editor;\n if (t === \"insertParagraph\") {\n e.preventDefault();\n ed.insertParagraphBreak();\n } else if (t.startsWith(\"delete\")) {\n e.preventDefault();\n if (t === \"deleteContentForward\") ed.deleteForward();\n else ed.deleteBackward();\n } else if (t === \"insertText\" || t === \"insertReplacementText\" || t === \"insertFromPaste\") {\n e.preventDefault();\n const text = e.data ?? e.dataTransfer?.getData(\"text/plain\") ?? \"\";\n if (text) ed.insertText(text);\n } else if (t === \"insertLineBreak\") {\n e.preventDefault();\n ed.insertText(\"\\n\");\n } else {\n return; // let the browser handle anything we don't model\n }\n this.commit();\n }\n\n private onInput() {\n if (this.composing || this.opts.readOnly) return;\n const blockEl = blockElOf(window.getSelection()?.anchorNode ?? null, this.root);\n if (!blockEl) {\n // structure changed under us (browser merged blocks) → full resync\n this.renderBlocks();\n this.lastRevision = this.rev();\n return;\n }\n const id = blockEl.dataset.blockId as string;\n const next = this.domBlockText(blockEl);\n const cur = this.editor.getBlockText(id);\n if (next === cur) return;\n\n // diff → splice through the controller (which infers marks at the caret)\n const max = Math.min(cur.length, next.length);\n let p = 0;\n while (p < max && cur[p] === next[p]) p++;\n let s = 0;\n while (s < max - p && cur[cur.length - 1 - s] === next[next.length - 1 - s]) s++;\n const from = p;\n const to = cur.length - s;\n const insert = next.slice(p, next.length - s);\n this.editor.setSelection({ anchor: { blockId: id, offset: from }, focus: { blockId: id, offset: to } });\n if (to > from) this.editor.deleteBackward();\n if (insert) this.editor.insertText(insert);\n // The browser already painted the text; just realign the run offsets.\n this.reindex(blockEl);\n this.lastRevision = this.rev();\n }\n\n /** Re-derive data-off / data-len after a native edit (no node replacement). */\n private reindex(el: HTMLElement) {\n let off = 0;\n for (const child of Array.from(el.children) as HTMLElement[]) {\n if (child.dataset.off == null) continue;\n child.dataset.off = String(off);\n const len = child.dataset.atom != null ? 1 : (child.textContent ?? \"\").length;\n child.dataset.len = String(len);\n off += len;\n }\n }\n}\n","import type { EditorController } from \"@wingleeio/ori-core\";\nimport {\n forwardRef,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useRef,\n useState,\n type CSSProperties,\n type PointerEvent as ReactPointerEvent,\n} from \"react\";\nimport { EditorView } from \"./ce/view\";\nimport { useEditorSnapshot } from \"./hooks\";\nimport type { AtomRenderer, BlockRenderer } from \"./renderers\";\n\nexport interface NoteEditorProps {\n editor: EditorController;\n className?: string;\n style?: CSSProperties;\n /** Max width of the centered content column, in px. */\n maxWidth?: number;\n placeholder?: string;\n autoFocus?: boolean;\n readOnly?: boolean;\n /** Renderers for custom (atomic) block node types. */\n blockRenderers?: Record<string, BlockRenderer>;\n /** Renderers for custom inline atom types. */\n atomRenderers?: Record<string, AtomRenderer>;\n}\n\n/** A viewport-space rectangle (client coordinates). */\nexport interface ViewportRect {\n top: number;\n left: number;\n right: number;\n bottom: number;\n width: number;\n height: number;\n}\n\n/** Imperative handle for building floating UI (slash / selection menus). */\nexport interface NoteEditorHandle {\n focus(): void;\n /** Caret position in viewport coordinates, or null if unavailable. */\n getCaretRect(): { x: number; y: number; height: number } | null;\n /** Bounding box of the current selection in viewport coordinates, or null. */\n getSelectionRect(): ViewportRect | null;\n /** The scrolling element, for scroll-aware positioning. */\n getScrollElement(): HTMLElement | null;\n /**\n * The content overlay element (a positioned layer that scrolls *with* the\n * text). Render floating UI into this with `position: absolute` and\n * content-relative coordinates so it rides the scroll natively instead of\n * trailing it (which causes a fixed-position toolbar to shake on scroll).\n */\n getOverlayElement(): HTMLElement | null;\n}\n\nfunction caretClientRect(): DOMRect | null {\n const s = window.getSelection();\n if (!s || s.rangeCount === 0) return null;\n const r = s.getRangeAt(0).cloneRange();\n r.collapse(s.focusNode === r.endContainer && s.focusOffset === r.endOffset ? false : true);\n const rects = r.getClientRects();\n if (rects.length) return rects[rects.length - 1];\n const b = r.getBoundingClientRect();\n if (b.height || b.width) return b;\n // Empty block (`<br>` only): a collapsed range there has no client rects, so\n // synthesize the caret from the block box + its line metrics. Without this the\n // custom caret would vanish on empty lines (the native caret is hidden).\n const node = r.startContainer;\n const el = (node.nodeType === Node.TEXT_NODE ? node.parentElement : (node as HTMLElement)) ?? null;\n if (!el) return null;\n const eb = el.getBoundingClientRect();\n const cs = getComputedStyle(el);\n const lh = parseFloat(cs.lineHeight) || parseFloat(cs.fontSize) * 1.4 || 18;\n const padL = parseFloat(cs.paddingLeft) || 0;\n const padT = parseFloat(cs.paddingTop) || 0;\n return new DOMRect(eb.left + padL, eb.top + padT, 0, lh);\n}\n\n/**\n * A contentEditable note editor: the browser owns caret, selection, trackpad,\n * native menus and IME on the live text, while edits are routed through the\n * {@link EditorController} (Y.Doc). A custom caret is drawn on top so it can be\n * branded/animated independently of the (hidden) native one.\n */\nexport const NoteEditor = forwardRef<NoteEditorHandle, NoteEditorProps>(function NoteEditor(\n { editor, className, style, maxWidth = 720, placeholder, autoFocus, readOnly, blockRenderers, atomRenderers },\n ref,\n) {\n const snapshot = useEditorSnapshot(editor);\n const scrollerRef = useRef<HTMLDivElement>(null);\n const overlayRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const viewRef = useRef<EditorView | null>(null);\n const [focused, setFocused] = useState(false);\n const [caret, setCaret] = useState<{ x: number; y: number; h: number } | null>(null);\n\n // Keep the latest renderers reachable without recreating the view.\n const renderersRef = useRef({ blockRenderers, atomRenderers });\n renderersRef.current = { blockRenderers, atomRenderers };\n\n useImperativeHandle(\n ref,\n (): NoteEditorHandle => ({\n focus: () => contentRef.current?.focus(),\n getCaretRect: () => {\n const r = caretClientRect();\n return r ? { x: r.left, y: r.top, height: r.height || 16 } : null;\n },\n getSelectionRect: () => {\n const s = window.getSelection();\n if (!s || s.rangeCount === 0 || s.isCollapsed) return null;\n const b = s.getRangeAt(0).getBoundingClientRect();\n if (!b.width && !b.height) return null;\n return { top: b.top, left: b.left, right: b.right, bottom: b.bottom, width: b.width, height: b.height };\n },\n getScrollElement: () => scrollerRef.current,\n getOverlayElement: () => overlayRef.current,\n }),\n [],\n );\n\n // Create the imperative contentEditable view once.\n useEffect(() => {\n const el = contentRef.current;\n if (!el) return;\n const view = new EditorView(el, editor, {\n readOnly,\n renderAtom: (t) => renderersRef.current.atomRenderers?.[t],\n renderBlock: (t) => renderersRef.current.blockRenderers?.[t],\n });\n viewRef.current = view;\n return () => {\n view.destroy();\n viewRef.current = null;\n };\n }, [editor, readOnly]);\n\n // Reconcile the view when the model changes externally (app commands, undo,\n // remote). The view ignores revisions it produced itself (native typing).\n useEffect(() => {\n viewRef.current?.sync();\n }, [snapshot.revision]);\n\n useEffect(() => {\n if (autoFocus) contentRef.current?.focus();\n }, [autoFocus]);\n\n // Position the custom caret from the live DOM selection.\n useEffect(() => {\n const update = () => {\n const content = contentRef.current;\n const s = window.getSelection();\n if (!content || !s || s.rangeCount === 0 || !s.isCollapsed || !content.contains(s.anchorNode)) {\n setCaret(null);\n return;\n }\n const r = caretClientRect();\n const box = content.getBoundingClientRect();\n if (r) setCaret({ x: r.left - box.left, y: r.top - box.top, h: r.height || 18 });\n };\n document.addEventListener(\"selectionchange\", update);\n const ro = new ResizeObserver(update);\n if (contentRef.current) ro.observe(contentRef.current);\n update();\n return () => {\n document.removeEventListener(\"selectionchange\", update);\n ro.disconnect();\n };\n }, []);\n\n // Drive virtualization: keep the controller's width + viewport in sync.\n useLayoutEffect(() => {\n const sc = scrollerRef.current;\n const content = contentRef.current;\n if (!sc || !content) return;\n const sync = () => {\n editor.setWidth(content.clientWidth);\n editor.setViewport(sc.scrollTop, sc.clientHeight);\n };\n sync();\n const ro = new ResizeObserver(sync);\n ro.observe(sc);\n ro.observe(content);\n return () => ro.disconnect();\n }, [editor]);\n\n const onScroll = () => {\n const sc = scrollerRef.current;\n if (sc) editor.setViewport(sc.scrollTop, sc.clientHeight);\n };\n\n // Clicking the empty region below the content should focus the editor and put\n // the caret at the document end (the usual \"click to keep writing\" affordance).\n const onPointerDown = (e: ReactPointerEvent<HTMLDivElement>) => {\n if (readOnly) return;\n // Only act on the editor's own empty surface — not on blocks (the browser\n // places the caret) and not on floating UI (menus) layered into the overlay.\n const t = e.target as HTMLElement;\n const onSurface =\n t === scrollerRef.current ||\n t === overlayRef.current ||\n t.classList.contains(\"ori-ce\") ||\n t.dataset.spacer != null;\n if (!onSurface) return;\n const content = contentRef.current;\n const blocks = content?.querySelectorAll(\"[data-block-id]\");\n const last = blocks && (blocks[blocks.length - 1] as HTMLElement | undefined);\n if (!content || !last) return;\n if (e.clientY <= last.getBoundingClientRect().bottom) return; // beside text, not below\n e.preventDefault();\n content.focus();\n const sel = window.getSelection();\n if (!sel) return;\n const range = document.createRange();\n range.selectNodeContents(last);\n range.collapse(false);\n sel.removeAllRanges();\n sel.addRange(range);\n };\n\n const showCaret = focused && !!caret && !readOnly;\n\n return (\n <div className={`ori-root${className ? ` ${className}` : \"\"}`} style={style}>\n <div className=\"ori-scroller\" ref={scrollerRef} onScroll={onScroll} onPointerDown={onPointerDown}>\n <div className=\"ori-content\" ref={overlayRef} style={{ maxWidth, marginInline: \"auto\", position: \"relative\" }}>\n <div\n className=\"ori-canvas ori-ce\"\n ref={contentRef}\n onFocus={() => setFocused(true)}\n onBlur={() => setFocused(false)}\n suppressContentEditableWarning\n />\n {showCaret && caret ? (\n <div\n className=\"ori-caret\"\n style={{ position: \"absolute\", left: caret.x, top: caret.y, height: caret.h, pointerEvents: \"none\" }}\n aria-hidden\n />\n ) : null}\n {snapshot.empty && placeholder ? (\n <div className=\"ori-placeholder\" aria-hidden>\n {placeholder}\n </div>\n ) : null}\n </div>\n </div>\n </div>\n );\n});\n","import type { BlockLayout, EditorController, InlineAtom, VisibleBlock } from \"@wingleeio/ori-core\";\nimport { createContext, useContext, type ReactNode } from \"react\";\n\n/** Props for a custom block renderer (atomic nodes: divider, image, …). */\nexport interface BlockRendererProps {\n editor: EditorController;\n block: VisibleBlock;\n /** The block's synthetic layout (atomic blocks: one line, no fragments). */\n layout: BlockLayout;\n}\nexport type BlockRenderer = (props: BlockRendererProps) => ReactNode;\n\n/** Props for a custom inline-atom renderer (mention chip, inline math, …). */\nexport interface AtomRendererProps {\n editor: EditorController;\n atom: InlineAtom;\n}\nexport type AtomRenderer = (props: AtomRendererProps) => ReactNode;\n\nexport interface Renderers {\n blocks: Record<string, BlockRenderer>;\n atoms: Record<string, AtomRenderer>;\n}\n\nconst EMPTY: Renderers = { blocks: {}, atoms: {} };\n\nconst RenderersContext = createContext<Renderers>(EMPTY);\nexport const RenderersProvider = RenderersContext.Provider;\nexport const useRenderers = (): Renderers => useContext(RenderersContext);\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/useEditor.ts","../src/hooks.ts","../src/ce/clipboard.ts","../src/ce/dom.ts","../src/ce/view.ts","../src/NoteEditor.tsx","../src/renderers.tsx"],"names":["useRef","EditorController","createCanvasMeasurer","useEffect","useSyncExternalStore","esc","textNode","isCollapsed","createRoot","forwardRef","NoteEditor","useState","useImperativeHandle","useLayoutEffect","jsx","jsxs","createContext","useContext"],"mappings":";;;;;;;;;;AA8BO,SAAS,SAAA,CAAU,OAAA,GAA4B,EAAC,EAAqB;AAC1E,EAAA,MAAM,GAAA,GAAMA,aAAgC,IAAI,CAAA;AAChD,EAAA,IAAI,GAAA,CAAI,YAAY,IAAA,EAAM;AACxB,IAAA,GAAA,CAAI,OAAA,GAAU,IA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easurer,\n type EditorSchema,\n type Measurer,\n type Typography,\n} from \"@wingleeio/ori-core\";\nimport { useEffect, useRef } from \"react\";\nimport type * as Y from \"yjs\";\n\nexport interface UseEditorOptions {\n /** Existing note `Y.Doc`. When switching notes, remount via `key` instead. */\n doc?: Y.Doc;\n typography?: Typography;\n measurer?: Measurer;\n overscan?: number;\n blockSpacing?: number;\n /** Custom block/atom nodes, merged over the built-ins. */\n schema?: Partial<EditorSchema>;\n}\n\n/**\n * Create (once) and own an {@link EditorController} for the lifetime of the\n * component. To switch documents, give the hosting component a `key` so it\n * remounts with a fresh controller.\n *\n * The controller is reconnected on mount and disconnected on unmount rather than\n * destroyed, so React StrictMode's dev mount → unmount → remount cycle reuses the\n * same controller (with all its state) instead of leaving a torn-down one behind.\n */\nexport function useEditor(options: UseEditorOptions = {}): EditorController {\n const ref = useRef<EditorController | null>(null);\n if (ref.current === null) {\n ref.current = new EditorController({\n doc: options.doc,\n measurer: options.measurer ?? createCanvasMeasurer(),\n typography: options.typography,\n overscan: options.overscan,\n blockSpacing: options.blockSpacing,\n schema: options.schema,\n });\n }\n useEffect(() => {\n const editor = ref.current;\n editor?.connect();\n return () => editor?.disconnect();\n }, []);\n return ref.current;\n}\n","import type { EditorController, EditorSnapshot, Marks } from \"@wingleeio/ori-core\";\nimport { useSyncExternalStore } from \"react\";\n\n/** Subscribe a component to the controller's snapshot stream. */\nexport function useEditorSnapshot(editor: EditorController): EditorSnapshot {\n return useSyncExternalStore(editor.subscribe, editor.getSnapshot, editor.getSnapshot);\n}\n\n/**\n * The marks active at the current selection. Recomputed whenever the editor\n * notifies (selection move, edit, or pending-mark toggle), so toolbars stay in\n * sync without their own subscription.\n */\nexport function useActiveMarks(editor: EditorController): Marks {\n const snapshot = useEditorSnapshot(editor);\n // `revision` changes on every notify; reading it ties this to the store.\n void snapshot.revision;\n return editor.getActiveMarks();\n}\n","import type { InlineItem, Marks } from \"@wingleeio/ori-core\";\n\n/**\n * Clipboard (de)serialization for the contentEditable view. Copy writes three\n * payloads — `text/plain`, `text/html` (for other apps), and a private JSON MIME\n * that round-trips marks/atoms exactly — and paste prefers the private MIME, then\n * falls back to parsing external HTML, then plain text. Content is grouped one\n * array of inline runs per block so block boundaries survive a multi-block copy.\n */\nexport const ORI_MIME = \"application/x-ori-inline\";\n\nfunction atomPlain(it: InlineItem): string {\n const d = (it.atom?.data ?? {}) as Record<string, unknown>;\n const label = d.label ?? d.text ?? d.name;\n return label != null ? `@${String(label)}` : \"\";\n}\n\nfunction blockPlain(items: InlineItem[]): string {\n return items.map((it) => (it.atom ? atomPlain(it) : it.text)).join(\"\");\n}\n\nconst MARK_TAGS: Array<[keyof Marks, string]> = [\n [\"bold\", \"strong\"],\n [\"italic\", \"em\"],\n [\"underline\", \"u\"],\n [\"strike\", \"s\"],\n [\"code\", \"code\"],\n];\n\nfunction esc(s: string): string {\n return s.replace(/&/g, \"&\").replace(/</g, \"<\").replace(/>/g, \">\");\n}\n\nfunction runHtml(it: InlineItem): string {\n if (it.atom) return `<span>${esc(atomPlain(it))}</span>`;\n let html = esc(it.text);\n const m = it.marks ?? {};\n for (const [k, tag] of MARK_TAGS) if (m[k]) html = `<${tag}>${html}</${tag}>`;\n if (m.link) html = `<a href=\"${esc(m.link)}\">${html}</a>`;\n return html;\n}\n\n/** Build the three clipboard payloads for a block-grouped selection. */\nexport function serializeSelection(blocks: InlineItem[][]): { text: string; html: string; json: string } {\n const text = blocks.map(blockPlain).join(\"\\n\");\n const html = blocks.map((items) => `<p>${items.map(runHtml).join(\"\") || \"<br>\"}</p>`).join(\"\");\n const json = JSON.stringify({\n v: 1,\n blocks: blocks.map((items) =>\n items.map((it) =>\n it.atom ? { embed: it.atom.data ?? { type: it.atom.type } } : { text: it.text, marks: it.marks },\n ),\n ),\n });\n return { text, html, json };\n}\n\ninterface SerItem {\n text?: string;\n marks?: Marks;\n embed?: Record<string, unknown>;\n}\n\n/** Parse our own clipboard JSON back into block-grouped inline items. */\nexport function deserializeOri(json: string): InlineItem[][] | null {\n try {\n const data = JSON.parse(json) as { v?: number; blocks?: SerItem[][] };\n if (!Array.isArray(data.blocks)) return null;\n return data.blocks.map((items) =>\n items.map((it) =>\n it.embed\n ? { text: \"\", start: 0, atom: { type: String(it.embed.type ?? \"\"), width: 0, data: it.embed } }\n : { text: it.text ?? \"\", start: 0, marks: it.marks },\n ),\n );\n } catch {\n return null;\n }\n}\n\n/** Plain text → one block per line. */\nexport function textToBlocks(text: string): InlineItem[][] {\n return text\n .replace(/\\r\\n?/g, \"\\n\")\n .split(\"\\n\")\n .map((line) => (line ? [{ text: line, start: 0 } as InlineItem] : []));\n}\n\n/** Parse external HTML into block-grouped inline items (best-effort marks). */\nexport function htmlToBlocks(html: string): InlineItem[][] {\n if (typeof DOMParser === \"undefined\") return [];\n const doc = new DOMParser().parseFromString(html, \"text/html\");\n const blocks: InlineItem[][] = [];\n let cur: InlineItem[] = [];\n const flush = () => {\n blocks.push(cur);\n cur = [];\n };\n const push = (text: string, marks: Marks) => {\n if (!text) return;\n cur.push({ text, start: 0, marks: Object.keys(marks).length ? { ...marks } : undefined });\n };\n const BLOCK = new Set([\n \"P\", \"DIV\", \"H1\", \"H2\", \"H3\", \"H4\", \"H5\", \"H6\", \"LI\", \"BLOCKQUOTE\", \"PRE\", \"SECTION\", \"ARTICLE\", \"UL\", \"OL\",\n ]);\n const walk = (node: Node, marks: Marks) => {\n for (const child of Array.from(node.childNodes)) {\n if (child.nodeType === Node.TEXT_NODE) {\n push((child.textContent ?? \"\").replace(/\\s+/g, \" \"), marks);\n continue;\n }\n if (child.nodeType !== Node.ELEMENT_NODE) continue;\n const el = child as HTMLElement;\n const tag = el.tagName;\n if (tag === \"BR\") {\n if (cur.length) flush();\n continue;\n }\n const m: Marks = { ...marks };\n if (tag === \"STRONG\" || tag === \"B\") m.bold = true;\n if (tag === \"EM\" || tag === \"I\") m.italic = true;\n if (tag === \"U\" || tag === \"INS\") m.underline = true;\n if (tag === \"S\" || tag === \"STRIKE\" || tag === \"DEL\") m.strike = true;\n if (tag === \"CODE\" || tag === \"KBD\" || tag === \"TT\") m.code = true;\n const href = tag === \"A\" ? el.getAttribute(\"href\") : null;\n if (href) m.link = href;\n const isBlock = BLOCK.has(tag);\n if (isBlock && cur.length) flush();\n walk(el, m);\n if (isBlock) flush();\n }\n };\n walk(doc.body, {});\n if (cur.length) flush();\n // Trim leading/trailing empty blocks left by formatting whitespace.\n while (blocks.length && blocks[0].length === 0) blocks.shift();\n while (blocks.length && blocks[blocks.length - 1].length === 0) blocks.pop();\n return blocks;\n}\n","import type { InlineItem } from \"@wingleeio/ori-core\";\n\n/** CSS.escape with a fallback (jsdom lacks it). */\nexport function esc(s: string): string {\n return typeof CSS !== \"undefined\" && CSS.escape ? CSS.escape(s) : s.replace(/[\"\\\\]/g, \"\\\\$&\");\n}\n\n/**\n * Imperative DOM helpers for the contentEditable view. Each block is a\n * block-level element carrying `data-block-id`; its inline runs are spans\n * carrying `data-off` (their start offset in the block) so DOM positions map\n * back to {blockId, offset} and vice-versa.\n */\n\nexport const BLOCK_SEL = \"[data-block-id]\";\n\nexport function blockElOf(node: Node | null, root: HTMLElement): HTMLElement | null {\n let n: Node | null = node;\n while (n && n !== root) {\n if (n instanceof HTMLElement && n.dataset.blockId) return n;\n n = n.parentNode;\n }\n return null;\n}\n\nfunction spanOf(node: Node | null): HTMLElement | null {\n let n: Node | null = node;\n while (n) {\n if (n instanceof HTMLElement && n.dataset.off != null) return n;\n n = n.parentNode;\n }\n return null;\n}\n\n/** Map a DOM (node, offset) to a {blockId, offset} model position. */\nexport function domToModel(\n root: HTMLElement,\n node: Node | null,\n offset: number,\n): { blockId: string; offset: number } | null {\n const blockEl = blockElOf(node, root);\n if (!blockEl) return null;\n const blockId = blockEl.dataset.blockId as string;\n\n if (node && node.nodeType === Node.TEXT_NODE) {\n const span = spanOf(node);\n const base = span ? Number(span.dataset.off) : 0;\n return { blockId, offset: base + offset };\n }\n\n // node is an element; `offset` is a child index. Resolve via the child spans.\n const el = node as HTMLElement;\n if (el.dataset?.off != null) {\n // selection landed on a span boundary\n return { blockId, offset: Number(el.dataset.off) + (offset > 0 ? spanLen(el) : 0) };\n }\n const kids = Array.from(el.childNodes);\n for (let i = offset; i < kids.length; i++) {\n const k = kids[i];\n if (k instanceof HTMLElement && k.dataset.off != null) return { blockId, offset: Number(k.dataset.off) };\n }\n // past the last span → block end\n let end = 0;\n for (const k of kids) if (k instanceof HTMLElement && k.dataset.off != null) end = Math.max(end, Number(k.dataset.off) + spanLen(k));\n return { blockId, offset: end };\n}\n\nfunction spanLen(span: HTMLElement): number {\n return span.dataset.len != null ? Number(span.dataset.len) : (span.textContent ?? \"\").length;\n}\n\n/** Find the DOM (node, offset) for a {blockId, offset} model position. */\nexport function modelToDom(\n root: HTMLElement,\n blockId: string,\n offset: number,\n): { node: Node; offset: number } | null {\n const blockEl = root.querySelector(`[data-block-id=\"${esc(blockId)}\"]`) as HTMLElement | null;\n if (!blockEl) return null;\n const spans = Array.from(blockEl.querySelectorAll(\"[data-off]\")) as HTMLElement[];\n if (spans.length === 0) {\n return { node: blockEl, offset: 0 }; // empty block\n }\n for (const span of spans) {\n const start = Number(span.dataset.off);\n const len = spanLen(span);\n if (offset <= start + len) {\n if (span.dataset.atom != null || span.dataset.break != null) {\n // atom or hard break (<br>): place before or after it by child index\n const idx = Array.prototype.indexOf.call(blockEl.childNodes, span);\n return { node: blockEl, offset: offset <= start ? idx : idx + 1 };\n }\n const textNode = span.firstChild ?? span;\n return { node: textNode, offset: Math.max(0, Math.min(offset - start, (textNode.textContent ?? \"\").length)) };\n }\n }\n // past everything → after the last span\n const last = spans[spans.length - 1];\n const textNode = last.firstChild ?? last;\n return { node: textNode, offset: (textNode.textContent ?? \"\").length };\n}\n\nfunction markClass(marks: InlineItem[\"marks\"]): string {\n const m = marks ?? {};\n const cls = [\"ori-frag\"];\n if (m.bold) cls.push(\"ori-m-bold\");\n if (m.italic) cls.push(\"ori-m-italic\");\n if (m.underline) cls.push(\"ori-m-underline\");\n if (m.strike) cls.push(\"ori-m-strike\");\n if (m.code) cls.push(\"ori-frag-code\");\n if (m.link) cls.push(\"ori-frag-link\");\n return cls.join(\" \");\n}\n\n/** Build the inline run DOM for a block (text spans only; atoms handled by the view). */\nexport function buildRun(item: InlineItem): HTMLElement {\n const span = document.createElement(\"span\");\n span.className = markClass(item.marks);\n span.dataset.off = String(item.start);\n span.dataset.len = String(item.text.length);\n span.textContent = item.text;\n return span;\n}\n","import type { EditorController, InlineItem } from \"@wingleeio/ori-core\";\nimport { isCollapsed } from \"@wingleeio/ori-core\";\nimport type { ReactNode } from \"react\";\nimport { createRoot, type Root } from \"react-dom/client\";\nimport type { AtomRenderer, BlockRenderer } from \"../renderers\";\nimport { ORI_MIME, deserializeOri, htmlToBlocks, serializeSelection, textToBlocks } from \"./clipboard\";\nimport { blockElOf, buildRun, domToModel, esc, modelToDom } from \"./dom\";\n\nconst PLACEHOLDER = \"\";\n\nexport interface ViewOptions {\n readOnly?: boolean;\n renderAtom: (type: string) => AtomRenderer | undefined;\n renderBlock: (type: string) => BlockRenderer | undefined;\n}\n\n/**\n * Imperative contentEditable view over an {@link EditorController}. The browser\n * owns caret / selection / trackpad / menus / IME on the live text; we intercept\n * structural + cross-block edits (beforeinput) and route them through the\n * controller, let smooth in-block typing flow natively and read it back, and\n * keep the DOM selection and the controller selection in lock-step.\n */\nexport class EditorView {\n private roots = new Map<HTMLElement, Root>();\n private composing = false;\n private applyingModel = false;\n private detachers: Array<() => void> = [];\n /** The model revision the DOM currently reflects (so external changes — remote\n * edits, app commands — re-render, but our own edits don't clobber the caret). */\n private lastRevision = -1;\n\n constructor(\n private root: HTMLElement,\n private editor: EditorController,\n private opts: ViewOptions,\n ) {\n root.setAttribute(\"contenteditable\", opts.readOnly ? \"false\" : \"true\");\n root.setAttribute(\"spellcheck\", opts.readOnly ? \"false\" : \"true\");\n root.setAttribute(\"role\", \"textbox\");\n root.setAttribute(\"aria-multiline\", \"true\");\n this.renderBlocks();\n this.lastRevision = this.rev();\n\n const on = <K extends keyof HTMLElementEventMap>(\n t: K,\n h: (e: HTMLElementEventMap[K]) => void,\n o?: AddEventListenerOptions,\n ) => {\n root.addEventListener(t, h as EventListener, o);\n this.detachers.push(() => root.removeEventListener(t, h as EventListener, o));\n };\n on(\"beforeinput\", (e) => this.onBeforeInput(e as InputEvent));\n on(\"input\", () => this.onInput());\n on(\"keydown\", (e) => this.onKeyDown(e as KeyboardEvent));\n on(\"blur\", () => {\n // Clicking outside the editor drops the selection (so a selection toolbar\n // hides). Defer so we can ignore a window/tab blur and focus-preserving\n // clicks (e.g. toolbar buttons that re-focus the editor).\n setTimeout(() => {\n if (document.activeElement === this.root || !document.hasFocus()) return;\n const sel = this.editor.getSelection();\n if (sel && !isCollapsed(sel)) {\n this.editor.collapse(sel.focus);\n this.lastRevision = this.rev();\n }\n }, 0);\n });\n on(\"compositionstart\", () => (this.composing = true));\n on(\"compositionend\", () => {\n this.composing = false;\n this.onInput();\n });\n on(\"copy\", (e) => this.onClipboard(e as ClipboardEvent, false));\n on(\"cut\", (e) => this.onClipboard(e as ClipboardEvent, true));\n on(\"paste\", (e) => this.onPaste(e as ClipboardEvent));\n\n const onSelChange = () => {\n if (this.applyingModel || this.composing) return;\n const sel = this.readSelection();\n if (!sel) return;\n this.editor.setSelection(sel);\n // DOM is already the source of truth here — record the revision so the\n // resulting React sync() doesn't write the selection back and collapse it.\n this.lastRevision = this.rev();\n };\n document.addEventListener(\"selectionchange\", onSelChange);\n this.detachers.push(() => document.removeEventListener(\"selectionchange\", onSelChange));\n }\n\n destroy() {\n this.detachers.forEach((d) => d());\n this.roots.forEach((r) => r.unmount());\n this.roots.clear();\n }\n\n focus() {\n this.root.focus();\n }\n\n // --- rendering ---------------------------------------------------------\n\n private rev(): number {\n return this.editor.getSnapshot().revision;\n }\n\n /**\n * Called by React on every model change. Only re-renders when the model moved\n * ahead of what we last drew (an *external* change — app command, undo, remote);\n * our own edits already updated the DOM and must not be clobbered.\n */\n sync() {\n const rev = this.rev();\n if (rev === this.lastRevision) return;\n // Only restore the DOM selection when the *content* changed (app command,\n // undo, remote). A selection-only change is already correct in the DOM, and\n // writing it back would fight (and collapse) the user's native selection.\n const changed = this.renderBlocks();\n if (changed) this.writeSelection();\n this.lastRevision = rev;\n }\n\n /** After a controlled (preventDefault'd) edit: re-render + restore the caret. */\n private commit() {\n this.renderBlocks();\n this.writeSelection();\n this.lastRevision = this.rev();\n }\n\n /** A content signature for a block, so unchanged blocks aren't re-rendered. */\n private sig(id: string): string {\n return this.editor.getBlockType(id) + \"|\" + JSON.stringify(this.editor.getInline(id));\n }\n\n /**\n * Reconcile the DOM to the *visible window* of blocks (virtualization): a top\n * spacer, the windowed blocks, then a bottom spacer — heights from the\n * controller's offscreen measurement. On-screen blocks are reused by id so a\n * caret inside one survives a scroll. Returns true if the DOM was mutated.\n */\n private renderBlocks(): boolean {\n let changed = false;\n const snap = this.editor.getSnapshot();\n const vis = snap.visible;\n const topH = vis.length ? vis[0].top : 0;\n const botH = vis.length\n ? Math.max(0, snap.totalHeight - (vis[vis.length - 1].top + vis[vis.length - 1].height))\n : Math.max(0, snap.totalHeight);\n\n const TOP = \"\u0000top\";\n const BOTTOM = \"\u0000bottom\";\n const want = [TOP, ...vis.map((v) => v.id), BOTTOM];\n const keyOf = (el: Element) => {\n const e = el as HTMLElement;\n return e.dataset.spacer ? \"\u0000\" + e.dataset.spacer : (e.dataset.blockId ?? \"\");\n };\n const have = new Map<string, HTMLElement>();\n for (const c of Array.from(this.root.children)) have.set(keyOf(c), c as HTMLElement);\n\n let prev: HTMLElement | null = null;\n for (const k of want) {\n let el: HTMLElement | undefined = have.get(k);\n if (el) {\n have.delete(k);\n } else {\n el = k === TOP || k === BOTTOM ? this.makeSpacer(k.slice(1)) : this.makeBlock(k);\n changed = true;\n }\n const anchor: ChildNode | null = prev ? prev.nextSibling : this.root.firstChild;\n if (anchor !== el) {\n this.root.insertBefore(el, anchor);\n changed = true;\n }\n prev = el;\n }\n for (const el of have.values()) {\n if (el.dataset.blockId) this.unmountRootsIn(el);\n el.remove();\n changed = true;\n }\n\n const top = this.root.firstElementChild as HTMLElement | null;\n if (top && top.style.height !== `${topH}px`) top.style.height = `${topH}px`;\n const bot = this.root.lastElementChild as HTMLElement | null;\n if (bot && bot.style.height !== `${botH}px`) bot.style.height = `${botH}px`;\n\n for (const vb of vis) {\n const el = this.root.querySelector(`[data-block-id=\"${esc(vb.id)}\"]`) as HTMLElement | null;\n if (!el) continue;\n const sig = this.sig(vb.id);\n if (el.dataset.sig !== sig) {\n el.dataset.sig = sig;\n this.renderBlockInner(el, vb.id);\n changed = true;\n }\n }\n return changed;\n }\n\n private makeBlock(id: string): HTMLElement {\n const el = document.createElement(\"div\");\n el.dataset.blockId = id;\n return el;\n }\n\n private makeSpacer(which: string): HTMLElement {\n const el = document.createElement(\"div\");\n el.dataset.spacer = which;\n el.setAttribute(\"contenteditable\", \"false\");\n el.setAttribute(\"aria-hidden\", \"true\");\n el.style.userSelect = \"none\";\n el.style.pointerEvents = \"none\";\n return el;\n }\n\n private renderBlockInner(el: HTMLElement, id: string) {\n this.unmountRootsIn(el);\n const type = this.editor.getBlockType(id);\n el.className = `ori-block ori-block-${type}`;\n\n const blockRenderer = this.opts.renderBlock(type);\n if (blockRenderer) {\n el.contentEditable = \"false\";\n el.textContent = \"\";\n const root = createRoot(el);\n root.render(blockRenderer({ editor: this.editor, block: { id, type, index: 0, top: 0, height: 0 }, layout: this.editor.getLayout(id)! }) as ReactNode);\n this.roots.set(el, root);\n return;\n }\n el.contentEditable = \"inherit\";\n el.textContent = \"\";\n const items = this.editor.getInline(id);\n if (items.length === 0) {\n el.appendChild(document.createElement(\"br\")); // keep an empty block selectable\n return;\n }\n for (const item of items) {\n if (item.atom) {\n const span = document.createElement(\"span\");\n span.className = \"ori-atom\";\n span.contentEditable = \"false\";\n span.dataset.atom = \"true\";\n span.dataset.off = String(item.start);\n span.dataset.len = \"1\";\n el.appendChild(span);\n const renderer = this.opts.renderAtom(item.atom.type);\n if (renderer) {\n const r = createRoot(span);\n r.render(renderer({ editor: this.editor, atom: item.atom }) as ReactNode);\n this.roots.set(span, r);\n }\n } else if (item.text.includes(\"\\n\")) {\n // Render hard breaks as <br> (not raw \\n in a text node, which the\n // browser won't give a caret on the new line — the Shift+Enter bug).\n let off = item.start;\n const parts = item.text.split(\"\\n\");\n parts.forEach((part, i) => {\n if (i > 0) {\n el.appendChild(this.makeBreak(off));\n off += 1;\n }\n if (part) {\n el.appendChild(buildRun({ text: part, start: off, marks: item.marks }));\n off += part.length;\n }\n });\n } else {\n el.appendChild(buildRun(item));\n }\n }\n }\n\n private makeBreak(off: number): HTMLElement {\n const br = document.createElement(\"br\");\n br.dataset.off = String(off);\n br.dataset.len = \"1\";\n br.dataset.break = \"true\";\n return br;\n }\n\n private unmountRootsIn(el: HTMLElement) {\n for (const [node, root] of this.roots) {\n if (el === node || el.contains(node)) {\n root.unmount();\n this.roots.delete(node);\n }\n }\n }\n\n // --- selection ---------------------------------------------------------\n\n private readSelection() {\n const s = window.getSelection();\n if (!s || s.rangeCount === 0 || !this.root.contains(s.anchorNode)) return null;\n const a = domToModel(this.root, s.anchorNode, s.anchorOffset);\n const f = domToModel(this.root, s.focusNode, s.focusOffset);\n if (!a || !f) return null;\n return { anchor: { blockId: a.blockId, offset: a.offset }, focus: { blockId: f.blockId, offset: f.offset } };\n }\n\n /** Push the controller's selection back into the DOM (after a model op). */\n private writeSelection() {\n const sel = this.editor.getSelection();\n if (!sel) return;\n const a = modelToDom(this.root, sel.anchor.blockId, sel.anchor.offset);\n const f = modelToDom(this.root, sel.focus.blockId, sel.focus.offset);\n if (!a || !f) return;\n const r = document.createRange();\n const s = window.getSelection();\n if (!s) return;\n this.applyingModel = true;\n try {\n r.setStart(a.node, a.offset);\n s.removeAllRanges();\n s.addRange(r);\n s.extend(f.node, f.offset);\n } catch {\n /* node detached mid-reconcile */\n } finally {\n this.applyingModel = false;\n }\n }\n\n /** The block text as the model sees it (atoms collapse to one placeholder). */\n private domBlockText(el: HTMLElement): string {\n let out = \"\";\n for (const child of Array.from(el.childNodes)) {\n if (child instanceof HTMLElement && child.dataset.atom != null) {\n out += PLACEHOLDER;\n } else if (child instanceof HTMLElement && child.dataset.break != null) {\n out += \"\\n\";\n } else {\n out += child.textContent ?? \"\";\n }\n }\n return out;\n }\n\n // --- input -------------------------------------------------------------\n\n /** Formatting + history shortcuts (the browser fires these as keydown). */\n private onKeyDown(e: KeyboardEvent) {\n if (this.opts.readOnly) return;\n const mod = e.metaKey || e.ctrlKey;\n if (!mod || e.altKey) return;\n const k = e.key.toLowerCase();\n const mark = ({ b: \"bold\", i: \"italic\", u: \"underline\", e: \"code\" } as const)[k];\n if (mark) {\n e.preventDefault();\n const sel = this.readSelection();\n if (sel) this.editor.setSelection(sel);\n this.editor.toggleMark(mark);\n this.commit();\n } else if (k === \"z\") {\n e.preventDefault();\n if (e.shiftKey) this.editor.redo();\n else this.editor.undo();\n this.commit();\n } else if (k === \"y\") {\n e.preventDefault();\n this.editor.redo();\n this.commit();\n }\n }\n\n private onBeforeInput(e: InputEvent) {\n if (this.opts.readOnly) {\n e.preventDefault();\n return;\n }\n const sel = this.readSelection();\n if (!sel) return;\n this.editor.setSelection(sel);\n const collapsed = isCollapsed(sel);\n const startOffset = this.editor.orderedSelection()?.start.offset ?? sel.focus.offset;\n const t = e.inputType;\n\n // Native fast path: collapsed in-block typing / deletion. The browser mutates\n // a single text node; onInput reads it back. Keeps autocorrect/IME native.\n if (collapsed && (t === \"insertText\" || t === \"insertCompositionText\" || t === \"insertReplacementText\")) return;\n if (collapsed && t === \"deleteContentForward\") return;\n if (collapsed && t === \"deleteContentBackward\" && startOffset > 0) return;\n\n // Everything else (structural + cross-block) is handled through the controller.\n const ed = this.editor;\n if (t === \"insertParagraph\") {\n e.preventDefault();\n ed.insertParagraphBreak();\n } else if (t.startsWith(\"delete\")) {\n e.preventDefault();\n if (t === \"deleteContentForward\") ed.deleteForward();\n else ed.deleteBackward();\n } else if (t === \"insertText\" || t === \"insertReplacementText\") {\n // Non-collapsed (e.g. autocorrect replacement, or typing over a selection):\n // replace the range. Paste has its own handler (onPaste).\n e.preventDefault();\n if (!collapsed) ed.deleteBackward();\n const text = e.data ?? \"\";\n if (text) ed.insertText(text);\n } else if (t === \"insertLineBreak\") {\n // Shift+Enter. A soft break (\"\\n\" in a block) is unreliable in\n // contentEditable (the browser types before/after a trailing <br>\n // inconsistently), so in this block model it starts a new block — a clean\n // new line with a correctly-placed caret.\n e.preventDefault();\n ed.insertParagraphBreak();\n } else {\n return; // let the browser handle anything we don't model\n }\n this.commit();\n }\n\n private onInput() {\n if (this.composing || this.opts.readOnly) return;\n const blockEl = blockElOf(window.getSelection()?.anchorNode ?? null, this.root);\n if (!blockEl) {\n // structure changed under us (browser merged blocks) → full resync\n this.renderBlocks();\n this.lastRevision = this.rev();\n return;\n }\n const id = blockEl.dataset.blockId as string;\n const next = this.domBlockText(blockEl);\n const cur = this.editor.getBlockText(id);\n if (next === cur) return;\n\n // diff → splice through the controller (which infers marks at the caret)\n const max = Math.min(cur.length, next.length);\n let p = 0;\n while (p < max && cur[p] === next[p]) p++;\n let s = 0;\n while (s < max - p && cur[cur.length - 1 - s] === next[next.length - 1 - s]) s++;\n const from = p;\n const to = cur.length - s;\n const insert = next.slice(p, next.length - s);\n this.editor.setSelection({ anchor: { blockId: id, offset: from }, focus: { blockId: id, offset: to } });\n if (to > from) this.editor.deleteBackward();\n if (insert) this.editor.insertText(insert);\n // The browser already painted the text; just realign the run offsets.\n this.reindex(blockEl);\n this.lastRevision = this.rev();\n }\n\n /** Re-derive data-off / data-len after a native edit (no node replacement). */\n private reindex(el: HTMLElement) {\n let off = 0;\n for (const child of Array.from(el.children) as HTMLElement[]) {\n if (child.dataset.off == null) continue;\n child.dataset.off = String(off);\n const len =\n child.dataset.atom != null || child.dataset.break != null ? 1 : (child.textContent ?? \"\").length;\n child.dataset.len = String(len);\n off += len;\n }\n }\n\n // --- clipboard ---------------------------------------------------------\n\n /** Copy/cut: put plain, HTML and a private (mark-preserving) payload on the clipboard. */\n private onClipboard(e: ClipboardEvent, isCut: boolean) {\n const blocks = this.editor.getSelectionInline();\n if (!blocks.length || !e.clipboardData) return;\n e.preventDefault();\n const { text, html, json } = serializeSelection(blocks);\n e.clipboardData.setData(\"text/plain\", text);\n e.clipboardData.setData(\"text/html\", html);\n e.clipboardData.setData(ORI_MIME, json);\n if (isCut && !this.opts.readOnly) {\n this.editor.deleteBackward();\n this.commit();\n }\n }\n\n /** Paste: restore marks from our payload, else parse external HTML, else plain text. */\n private onPaste(e: ClipboardEvent) {\n if (this.opts.readOnly || !e.clipboardData) return;\n e.preventDefault();\n const sel = this.readSelection();\n if (sel) {\n this.editor.setSelection(sel);\n if (!isCollapsed(sel)) this.editor.deleteBackward();\n }\n const cd = e.clipboardData;\n const ori = cd.getData(ORI_MIME);\n const html = cd.getData(\"text/html\");\n let blocks = ori ? deserializeOri(ori) : null;\n if (!blocks?.length && html) blocks = htmlToBlocks(html);\n if (!blocks?.length) blocks = textToBlocks(cd.getData(\"text/plain\"));\n this.pasteBlocks(blocks);\n this.commit();\n }\n\n private pasteBlocks(blocks: InlineItem[][]) {\n blocks.forEach((items, i) => {\n if (i > 0) this.editor.insertParagraphBreak();\n if (items.length) this.editor.insertInline(items);\n });\n }\n}\n","import type { EditorController } from \"@wingleeio/ori-core\";\nimport {\n forwardRef,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useRef,\n useState,\n type CSSProperties,\n type PointerEvent as ReactPointerEvent,\n} from \"react\";\nimport { EditorView } from \"./ce/view\";\nimport { useEditorSnapshot } from \"./hooks\";\nimport type { AtomRenderer, BlockRenderer } from \"./renderers\";\n\nexport interface NoteEditorProps {\n editor: EditorController;\n className?: string;\n style?: CSSProperties;\n /** Max width of the centered content column, in px. */\n maxWidth?: number;\n placeholder?: string;\n autoFocus?: boolean;\n readOnly?: boolean;\n /** Renderers for custom (atomic) block node types. */\n blockRenderers?: Record<string, BlockRenderer>;\n /** Renderers for custom inline atom types. */\n atomRenderers?: Record<string, AtomRenderer>;\n}\n\n/** A viewport-space rectangle (client coordinates). */\nexport interface ViewportRect {\n top: number;\n left: number;\n right: number;\n bottom: number;\n width: number;\n height: number;\n}\n\n/** Imperative handle for building floating UI (slash / selection menus). */\nexport interface NoteEditorHandle {\n focus(): void;\n /** Caret position in viewport coordinates, or null if unavailable. */\n getCaretRect(): { x: number; y: number; height: number } | null;\n /** Bounding box of the current selection in viewport coordinates, or null. */\n getSelectionRect(): ViewportRect | null;\n /** The scrolling element, for scroll-aware positioning. */\n getScrollElement(): HTMLElement | null;\n /**\n * The content overlay element (a positioned layer that scrolls *with* the\n * text). Render floating UI into this with `position: absolute` and\n * content-relative coordinates so it rides the scroll natively instead of\n * trailing it (which causes a fixed-position toolbar to shake on scroll).\n */\n getOverlayElement(): HTMLElement | null;\n}\n\nfunction caretClientRect(): DOMRect | null {\n const s = window.getSelection();\n if (!s || s.rangeCount === 0) return null;\n const r = s.getRangeAt(0).cloneRange();\n r.collapse(s.focusNode === r.endContainer && s.focusOffset === r.endOffset ? false : true);\n const rects = r.getClientRects();\n if (rects.length) return rects[rects.length - 1];\n const b = r.getBoundingClientRect();\n if (b.height || b.width) return b;\n const node = r.startContainer;\n // Caret sits just after an inline atom (a contentEditable=false chip) with no\n // text to measure: anchor it to the atom's right edge so it stays visible.\n if (node.nodeType === Node.ELEMENT_NODE && r.startOffset > 0) {\n const prev = (node as HTMLElement).childNodes[r.startOffset - 1];\n if (prev instanceof HTMLElement && prev.dataset.atom != null) {\n const pb = prev.getBoundingClientRect();\n if (pb.height || pb.width) return new DOMRect(pb.right, pb.top, 0, pb.height || 18);\n }\n }\n // Empty block (`<br>` only): a collapsed range there has no client rects, so\n // synthesize the caret from the block box + its line metrics. Without this the\n // custom caret would vanish on empty lines (the native caret is hidden).\n const el = (node.nodeType === Node.TEXT_NODE ? node.parentElement : (node as HTMLElement)) ?? null;\n if (!el) return null;\n const eb = el.getBoundingClientRect();\n const cs = getComputedStyle(el);\n const lh = parseFloat(cs.lineHeight) || parseFloat(cs.fontSize) * 1.4 || 18;\n const padL = parseFloat(cs.paddingLeft) || 0;\n const padT = parseFloat(cs.paddingTop) || 0;\n return new DOMRect(eb.left + padL, eb.top + padT, 0, lh);\n}\n\n/**\n * A contentEditable note editor: the browser owns caret, selection, trackpad,\n * native menus and IME on the live text, while edits are routed through the\n * {@link EditorController} (Y.Doc). A custom caret is drawn on top so it can be\n * branded/animated independently of the (hidden) native one.\n */\nexport const NoteEditor = forwardRef<NoteEditorHandle, NoteEditorProps>(function NoteEditor(\n { editor, className, style, maxWidth = 720, placeholder, autoFocus, readOnly, blockRenderers, atomRenderers },\n ref,\n) {\n const snapshot = useEditorSnapshot(editor);\n const scrollerRef = useRef<HTMLDivElement>(null);\n const overlayRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const viewRef = useRef<EditorView | null>(null);\n const [focused, setFocused] = useState(false);\n const [caret, setCaret] = useState<{ x: number; y: number; h: number } | null>(null);\n\n // Keep the latest renderers reachable without recreating the view.\n const renderersRef = useRef({ blockRenderers, atomRenderers });\n renderersRef.current = { blockRenderers, atomRenderers };\n\n useImperativeHandle(\n ref,\n (): NoteEditorHandle => ({\n focus: () => contentRef.current?.focus(),\n getCaretRect: () => {\n const r = caretClientRect();\n return r ? { x: r.left, y: r.top, height: r.height || 16 } : null;\n },\n getSelectionRect: () => {\n const s = window.getSelection();\n if (!s || s.rangeCount === 0 || s.isCollapsed) return null;\n const b = s.getRangeAt(0).getBoundingClientRect();\n if (!b.width && !b.height) return null;\n return { top: b.top, left: b.left, right: b.right, bottom: b.bottom, width: b.width, height: b.height };\n },\n getScrollElement: () => scrollerRef.current,\n getOverlayElement: () => overlayRef.current,\n }),\n [],\n );\n\n // Create the imperative contentEditable view once.\n useEffect(() => {\n const el = contentRef.current;\n if (!el) return;\n const view = new EditorView(el, editor, {\n readOnly,\n renderAtom: (t) => renderersRef.current.atomRenderers?.[t],\n renderBlock: (t) => renderersRef.current.blockRenderers?.[t],\n });\n viewRef.current = view;\n return () => {\n view.destroy();\n viewRef.current = null;\n };\n }, [editor, readOnly]);\n\n // Reconcile the view when the model changes externally (app commands, undo,\n // remote). The view ignores revisions it produced itself (native typing).\n useEffect(() => {\n viewRef.current?.sync();\n }, [snapshot.revision]);\n\n useEffect(() => {\n if (autoFocus) contentRef.current?.focus();\n }, [autoFocus]);\n\n // Position the custom caret from the live DOM selection.\n useEffect(() => {\n const update = () => {\n const content = contentRef.current;\n const s = window.getSelection();\n if (!content || !s || s.rangeCount === 0 || !s.isCollapsed || !content.contains(s.anchorNode)) {\n setCaret(null);\n return;\n }\n const r = caretClientRect();\n const box = content.getBoundingClientRect();\n if (r) setCaret({ x: r.left - box.left, y: r.top - box.top, h: r.height || 18 });\n };\n document.addEventListener(\"selectionchange\", update);\n const ro = new ResizeObserver(update);\n if (contentRef.current) ro.observe(contentRef.current);\n update();\n return () => {\n document.removeEventListener(\"selectionchange\", update);\n ro.disconnect();\n };\n }, []);\n\n // Drive virtualization: keep the controller's width + viewport in sync.\n useLayoutEffect(() => {\n const sc = scrollerRef.current;\n const content = contentRef.current;\n if (!sc || !content) return;\n const sync = () => {\n editor.setWidth(content.clientWidth);\n editor.setViewport(sc.scrollTop, sc.clientHeight);\n };\n sync();\n const ro = new ResizeObserver(sync);\n ro.observe(sc);\n ro.observe(content);\n return () => ro.disconnect();\n }, [editor]);\n\n const onScroll = () => {\n const sc = scrollerRef.current;\n if (sc) editor.setViewport(sc.scrollTop, sc.clientHeight);\n };\n\n // Clicking the empty region below the content should focus the editor and put\n // the caret at the document end (the usual \"click to keep writing\" affordance).\n const onPointerDown = (e: ReactPointerEvent<HTMLDivElement>) => {\n if (readOnly) return;\n // Only act on the editor's own empty surface — not on blocks (the browser\n // places the caret) and not on floating UI (menus) layered into the overlay.\n const t = e.target as HTMLElement;\n const onSurface =\n t === scrollerRef.current ||\n t === overlayRef.current ||\n t.classList.contains(\"ori-ce\") ||\n t.dataset.spacer != null;\n if (!onSurface) return;\n const content = contentRef.current;\n const blocks = content?.querySelectorAll(\"[data-block-id]\");\n const last = blocks && (blocks[blocks.length - 1] as HTMLElement | undefined);\n if (!content || !last) return;\n if (e.clientY <= last.getBoundingClientRect().bottom) return; // beside text, not below\n e.preventDefault();\n content.focus();\n const sel = window.getSelection();\n if (!sel) return;\n const range = document.createRange();\n range.selectNodeContents(last);\n range.collapse(false);\n sel.removeAllRanges();\n sel.addRange(range);\n };\n\n const showCaret = focused && !!caret && !readOnly;\n\n return (\n <div className={`ori-root${className ? ` ${className}` : \"\"}`} style={style}>\n <div className=\"ori-scroller\" ref={scrollerRef} onScroll={onScroll} onPointerDown={onPointerDown}>\n <div className=\"ori-content\" ref={overlayRef} style={{ maxWidth, marginInline: \"auto\", position: \"relative\" }}>\n <div\n className=\"ori-canvas ori-ce\"\n ref={contentRef}\n onFocus={() => setFocused(true)}\n onBlur={() => setFocused(false)}\n suppressContentEditableWarning\n />\n {showCaret && caret ? (\n <div\n className=\"ori-caret\"\n style={{ position: \"absolute\", left: caret.x, top: caret.y, height: caret.h, pointerEvents: \"none\" }}\n aria-hidden\n />\n ) : null}\n {snapshot.empty && placeholder ? (\n <div className=\"ori-placeholder\" aria-hidden>\n {placeholder}\n </div>\n ) : null}\n </div>\n </div>\n </div>\n );\n});\n","import type { BlockLayout, EditorController, InlineAtom, VisibleBlock } from \"@wingleeio/ori-core\";\nimport { createContext, useContext, type ReactNode } from \"react\";\n\n/** Props for a custom block renderer (atomic nodes: divider, image, …). */\nexport interface BlockRendererProps {\n editor: EditorController;\n block: VisibleBlock;\n /** The block's synthetic layout (atomic blocks: one line, no fragments). */\n layout: BlockLayout;\n}\nexport type BlockRenderer = (props: BlockRendererProps) => ReactNode;\n\n/** Props for a custom inline-atom renderer (mention chip, inline math, …). */\nexport interface AtomRendererProps {\n editor: EditorController;\n atom: InlineAtom;\n}\nexport type AtomRenderer = (props: AtomRendererProps) => ReactNode;\n\nexport interface Renderers {\n blocks: Record<string, BlockRenderer>;\n atoms: Record<string, AtomRenderer>;\n}\n\nconst EMPTY: Renderers = { blocks: {}, atoms: {} };\n\nconst RenderersContext = createContext<Renderers>(EMPTY);\nexport const RenderersProvider = RenderersContext.Provider;\nexport const useRenderers = (): Renderers => useContext(RenderersContext);\n"]}
|