markloom 0.5.0 → 0.6.0
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/PACKAGES.md +26 -0
- package/README.md +20 -2
- package/collab.md +44 -7
- package/dist/ai/index.cjs +4 -4
- package/dist/ai/index.d.cts +5 -4
- package/dist/ai/index.d.ts +5 -4
- package/dist/ai/index.js +3 -3
- package/dist/ai/theme.css +66 -102
- package/dist/{chunk-YJAWPRJW.cjs → chunk-ACFYBYZJ.cjs} +2817 -903
- package/dist/chunk-CGYCJORO.js +759 -0
- package/dist/chunk-EADZKEU4.cjs +498 -0
- package/dist/chunk-EJSFZHGT.js +24 -0
- package/dist/{chunk-SLRD6FMP.cjs → chunk-I5VK4U7J.cjs} +122 -73
- package/dist/{chunk-WUHTCCAE.js → chunk-KYZJIOOL.js} +2403 -489
- package/dist/chunk-QEVME6ZU.cjs +759 -0
- package/dist/{chunk-MFYF2A6U.js → chunk-SNFF6X45.js} +51 -1
- package/dist/{chunk-JMOJU5EU.js → chunk-TB2OY3D4.js} +69 -20
- package/dist/{chunk-4TMHVNL6.cjs → chunk-TWD5T4YC.cjs} +155 -105
- package/dist/{chunk-JS527FDV.cjs → chunk-U3JZDFL4.cjs} +49 -9
- package/dist/{chunk-RLTHVQNQ.js → chunk-VSBIMMI7.js} +45 -5
- package/dist/chunk-YBAT343I.js +498 -0
- package/dist/chunk-ZKQSQSSM.cjs +24 -0
- package/dist/{client-BNams4wv.d.cts → client-CLYq17SW.d.ts} +70 -7
- package/dist/{client-A0ZQJnyR.d.ts → client-DAth8pPq.d.cts} +70 -7
- package/dist/collab/index.cjs +22 -4
- package/dist/collab/index.d.cts +24 -3
- package/dist/collab/index.d.ts +24 -3
- package/dist/collab/index.js +24 -6
- package/dist/{controller-BkY1VPzc.d.ts → controller-6AJ36G52.d.ts} +108 -8
- package/dist/{controller-CVIZI--A.d.cts → controller-BIOO_XKJ.d.cts} +108 -8
- package/dist/index.cjs +57 -7
- package/dist/index.d.cts +18 -5
- package/dist/index.d.ts +18 -5
- package/dist/index.js +54 -4
- package/dist/io/index.cjs +1413 -0
- package/dist/io/index.d.cts +33 -0
- package/dist/io/index.d.ts +33 -0
- package/dist/io/index.js +1413 -0
- package/dist/react/index.cjs +8 -8
- package/dist/react/index.d.cts +5 -4
- package/dist/react/index.d.ts +5 -4
- package/dist/react/index.js +7 -7
- package/dist/{rebase-batch-8rL_aXEE.d.ts → rebase-batch-DlerAcFN.d.ts} +11 -9
- package/dist/{rebase-batch-bYnBJpRO.d.cts → rebase-batch-PjENQ742.d.cts} +11 -9
- package/dist/suggest-Bk4zLzuv.d.ts +120 -0
- package/dist/suggest-BkGGiPKA.d.cts +120 -0
- package/dist/types-COUweEav.d.cts +30 -0
- package/dist/types-COUweEav.d.ts +30 -0
- package/dist/versions-9mG1epfB.d.cts +51 -0
- package/dist/versions-Bubyo4pt.d.ts +51 -0
- package/dist/view/index.cjs +56 -12
- package/dist/view/index.d.cts +203 -11
- package/dist/view/index.d.ts +203 -11
- package/dist/view/index.js +52 -8
- package/dist/view/theme.css +1840 -1526
- package/io.md +38 -0
- package/package.json +21 -5
- package/dist/chunk-6DCI7AL3.js +0 -208
- package/dist/chunk-AC5E42NH.cjs +0 -208
- package/dist/chunk-GQ2HHRGI.cjs +0 -16
- package/dist/chunk-LA5SBCGQ.js +0 -16
- package/dist/chunk-LEYAQNJA.js +0 -220
- package/dist/chunk-YXQDCW4Y.cjs +0 -220
- package/dist/comments-DlExS6f-.d.cts +0 -43
- package/dist/comments-PhnR7Gkn.d.ts +0 -43
- package/dist/step-BrvHIK7O.d.cts +0 -65
- package/dist/step-BrvHIK7O.d.ts +0 -65
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
isElement,
|
|
3
3
|
isInlineAtom,
|
|
4
4
|
isText
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-EJSFZHGT.js";
|
|
6
6
|
|
|
7
7
|
// src/tree/addr.ts
|
|
8
8
|
function resolve(doc, path) {
|
|
@@ -1454,6 +1454,53 @@ function isRichHtmlBlocks(blocks) {
|
|
|
1454
1454
|
return true;
|
|
1455
1455
|
return b.children.some((c) => !isText(c) || (c.marks?.length ?? 0) > 0 || c.text.includes("\n"));
|
|
1456
1456
|
}
|
|
1457
|
+
function isPlainTransportHtml(blocks) {
|
|
1458
|
+
if (!blocks.length)
|
|
1459
|
+
return false;
|
|
1460
|
+
for (const b of blocks) {
|
|
1461
|
+
if (b.type === "code")
|
|
1462
|
+
continue;
|
|
1463
|
+
if (b.type === "raw")
|
|
1464
|
+
continue;
|
|
1465
|
+
if (b.type !== "paragraph")
|
|
1466
|
+
return false;
|
|
1467
|
+
if (paraHasRichInline(b))
|
|
1468
|
+
return false;
|
|
1469
|
+
}
|
|
1470
|
+
return true;
|
|
1471
|
+
}
|
|
1472
|
+
function paraHasRichInline(b) {
|
|
1473
|
+
for (const c of b.children) {
|
|
1474
|
+
if (isText(c)) {
|
|
1475
|
+
if ((c.marks?.length ?? 0) > 0)
|
|
1476
|
+
return true;
|
|
1477
|
+
continue;
|
|
1478
|
+
}
|
|
1479
|
+
if (!isElement(c))
|
|
1480
|
+
return true;
|
|
1481
|
+
if (c.type === "hard_break")
|
|
1482
|
+
continue;
|
|
1483
|
+
return true;
|
|
1484
|
+
}
|
|
1485
|
+
return false;
|
|
1486
|
+
}
|
|
1487
|
+
function mdStructureBeatsTransport(plain) {
|
|
1488
|
+
const blocks = mdToDoc(plain).children.filter((c) => isElement(c));
|
|
1489
|
+
if (!blocks.length)
|
|
1490
|
+
return false;
|
|
1491
|
+
for (const b of blocks) {
|
|
1492
|
+
if (b.type === "heading" || b.type === "list" || b.type === "blockquote" || b.type === "table" || b.type === "code" || b.type === "image" || b.type === "embed")
|
|
1493
|
+
return true;
|
|
1494
|
+
if (b.type === "paragraph" && paraHasRichInline(b))
|
|
1495
|
+
return true;
|
|
1496
|
+
if (b.type === "raw" && b.attrs?.mdType === "thematicBreak")
|
|
1497
|
+
return true;
|
|
1498
|
+
}
|
|
1499
|
+
return false;
|
|
1500
|
+
}
|
|
1501
|
+
function preferMarkdownPaste(plain, htmlBlocks) {
|
|
1502
|
+
return !!plain.trim() && isPlainTransportHtml(htmlBlocks) && mdStructureBeatsTransport(plain);
|
|
1503
|
+
}
|
|
1457
1504
|
var htmlOnlyMarks = /* @__PURE__ */ new Set(["underline", "highlight", "superscript", "subscript", "textStyle", "comment"]);
|
|
1458
1505
|
function textToPhrasing(leaf) {
|
|
1459
1506
|
if (leaf.marks?.some((m) => htmlOnlyMarks.has(m.name)))
|
|
@@ -2274,6 +2321,9 @@ export {
|
|
|
2274
2321
|
mdToDoc,
|
|
2275
2322
|
htmlToBlocks,
|
|
2276
2323
|
isRichHtmlBlocks,
|
|
2324
|
+
isPlainTransportHtml,
|
|
2325
|
+
mdStructureBeatsTransport,
|
|
2326
|
+
preferMarkdownPaste,
|
|
2277
2327
|
embedHtml,
|
|
2278
2328
|
tableHasExtras,
|
|
2279
2329
|
tableToHtml,
|
|
@@ -1,19 +1,41 @@
|
|
|
1
1
|
import {
|
|
2
2
|
appendText,
|
|
3
|
+
firstLeafPath,
|
|
3
4
|
insertAfter,
|
|
5
|
+
lastLeafEnd,
|
|
4
6
|
mdToDoc,
|
|
5
7
|
normalizeToLeaf,
|
|
6
8
|
pathOfId,
|
|
7
9
|
rewriteNode
|
|
8
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-SNFF6X45.js";
|
|
9
11
|
import {
|
|
12
|
+
isElement,
|
|
10
13
|
isText
|
|
11
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-EJSFZHGT.js";
|
|
12
15
|
|
|
13
16
|
// src/view/selection.ts
|
|
14
17
|
function rootEl(root) {
|
|
15
18
|
return root.querySelector(".markloom-doc") ?? root;
|
|
16
19
|
}
|
|
20
|
+
function docExtent(doc) {
|
|
21
|
+
const n = doc.children.length;
|
|
22
|
+
if (n === 0)
|
|
23
|
+
return null;
|
|
24
|
+
const first = doc.children[0];
|
|
25
|
+
const last = doc.children[n - 1];
|
|
26
|
+
if (!isElement(first) || !isElement(last))
|
|
27
|
+
return null;
|
|
28
|
+
return {
|
|
29
|
+
anchor: { path: normalizeToLeaf(doc, [0, ...firstLeafPath(first), 0]) },
|
|
30
|
+
head: { path: normalizeToLeaf(doc, [n - 1, ...lastLeafEnd(last)]) }
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function selectionCovers(sel, extent) {
|
|
34
|
+
return pathEq(sel.anchor.path, extent.anchor.path) && pathEq(sel.head.path, extent.head.path) || pathEq(sel.anchor.path, extent.head.path) && pathEq(sel.head.path, extent.anchor.path);
|
|
35
|
+
}
|
|
36
|
+
function pathEq(a, b) {
|
|
37
|
+
return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
38
|
+
}
|
|
17
39
|
function pointToDom(root, doc, pos) {
|
|
18
40
|
const path = pos.path;
|
|
19
41
|
if (path.length < 2)
|
|
@@ -78,11 +100,25 @@ function readSelection(root, doc) {
|
|
|
78
100
|
return null;
|
|
79
101
|
const anchor = domToPoint(root, doc, sel.anchorNode, sel.anchorOffset);
|
|
80
102
|
const head = domToPoint(root, doc, sel.focusNode, sel.focusOffset);
|
|
81
|
-
if (
|
|
82
|
-
return
|
|
83
|
-
|
|
103
|
+
if (anchor && head)
|
|
104
|
+
return { anchor, head };
|
|
105
|
+
if (rangeCoversSurface(sel, rootEl(root)))
|
|
106
|
+
return docExtent(doc);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
function rangeCoversSurface(sel, top) {
|
|
110
|
+
if (!sel.rangeCount)
|
|
111
|
+
return false;
|
|
112
|
+
try {
|
|
113
|
+
const r = sel.getRangeAt(0);
|
|
114
|
+
const tr = top.ownerDocument.createRange();
|
|
115
|
+
tr.selectNodeContents(top);
|
|
116
|
+
return r.compareBoundaryPoints(Range.START_TO_START, tr) <= 0 && r.compareBoundaryPoints(Range.END_TO_END, tr) >= 0;
|
|
117
|
+
} catch {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
84
120
|
}
|
|
85
|
-
function writeSelection(root, doc, selection) {
|
|
121
|
+
function writeSelection(root, doc, selection, opts) {
|
|
86
122
|
const a = pointToDom(root, doc, selection.anchor);
|
|
87
123
|
const hd = pointToDom(root, doc, selection.head);
|
|
88
124
|
if (!a || !hd)
|
|
@@ -92,12 +128,17 @@ function writeSelection(root, doc, selection) {
|
|
|
92
128
|
return;
|
|
93
129
|
const host = editableHost(a.node, root);
|
|
94
130
|
if (host && host !== root.ownerDocument.activeElement)
|
|
95
|
-
host.focus({ preventScroll:
|
|
131
|
+
host.focus({ preventScroll: !opts?.scroll });
|
|
96
132
|
const range = root.ownerDocument.createRange();
|
|
97
133
|
range.setStart(a.node, a.offset);
|
|
98
134
|
range.setEnd(hd.node, hd.offset);
|
|
99
135
|
sel.removeAllRanges();
|
|
100
136
|
sel.addRange(range);
|
|
137
|
+
if (opts?.scroll) {
|
|
138
|
+
const n = a.node;
|
|
139
|
+
const el = n.nodeType === 3 ? n.parentElement : n instanceof HTMLElement ? n : null;
|
|
140
|
+
el?.scrollIntoView?.({ block: "nearest", inline: "nearest" });
|
|
141
|
+
}
|
|
101
142
|
}
|
|
102
143
|
function editableHost(node, root) {
|
|
103
144
|
let el = node.nodeType === 3 ? node.parentElement : node;
|
|
@@ -660,7 +701,7 @@ var MarkloomAi = class {
|
|
|
660
701
|
this.txOpen = false;
|
|
661
702
|
this.txBlockId = null;
|
|
662
703
|
}
|
|
663
|
-
/** 整笔撤回事务(= undo) */
|
|
704
|
+
/** 整笔撤回事务(= undo);务必不留 aiDraft 孤儿段 */
|
|
664
705
|
discard(blockId) {
|
|
665
706
|
if (this.streamingId === blockId) {
|
|
666
707
|
this.abort?.abort();
|
|
@@ -672,16 +713,21 @@ var MarkloomAi = class {
|
|
|
672
713
|
}
|
|
673
714
|
if (this.txOpen && (this.txBlockId === blockId || !this.txBlockId)) {
|
|
674
715
|
this.rollback();
|
|
716
|
+
this.purgeDrafts(blockId);
|
|
675
717
|
return;
|
|
676
718
|
}
|
|
719
|
+
this.purgeDrafts(blockId, true);
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* 清掉 aiFrom=blockId 的顶层 draft;shell=true 时把 ai 壳也换成空段。
|
|
723
|
+
* discard / 异常恢复共用。
|
|
724
|
+
*/
|
|
725
|
+
purgeDrafts(blockId, shell = false) {
|
|
677
726
|
const ed = this.getEditor();
|
|
678
727
|
if (!ed)
|
|
679
728
|
return;
|
|
680
|
-
const found = this.findAi(ed, blockId);
|
|
681
|
-
if (!found)
|
|
682
|
-
return;
|
|
683
|
-
const steps = [];
|
|
684
729
|
const doc = ed.doc;
|
|
730
|
+
const steps = [];
|
|
685
731
|
const idxs = draftIndices(doc, blockId);
|
|
686
732
|
for (let i = idxs.length - 1; i >= 0; i--)
|
|
687
733
|
steps.push({ kind: "spliceChildren", path: [], at: idxs[i], remove: 1, insert: [] });
|
|
@@ -692,19 +738,20 @@ var MarkloomAi = class {
|
|
|
692
738
|
shift++;
|
|
693
739
|
}
|
|
694
740
|
aiIdx -= shift;
|
|
695
|
-
if (aiIdx >= 0) {
|
|
741
|
+
if (shell && aiIdx >= 0) {
|
|
696
742
|
steps.push({
|
|
697
743
|
kind: "replaceNode",
|
|
698
744
|
path: [aiIdx],
|
|
699
|
-
node: { type: "paragraph", id:
|
|
700
|
-
});
|
|
701
|
-
}
|
|
702
|
-
if (steps.length) {
|
|
703
|
-
ed.dispatch(steps, {
|
|
704
|
-
anchor: { path: [Math.max(0, aiIdx), 0, 0] },
|
|
705
|
-
head: { path: [Math.max(0, aiIdx), 0, 0] }
|
|
745
|
+
node: { type: "paragraph", id: blockId, children: [{ text: "" }] }
|
|
706
746
|
});
|
|
707
747
|
}
|
|
748
|
+
if (!steps.length)
|
|
749
|
+
return;
|
|
750
|
+
const caretAt = Math.max(0, aiIdx >= 0 ? aiIdx : idxs[0] ?? 0);
|
|
751
|
+
ed.dispatch(steps, {
|
|
752
|
+
anchor: { path: [caretAt, 0, 0] },
|
|
753
|
+
head: { path: [caretAt, 0, 0] }
|
|
754
|
+
});
|
|
708
755
|
}
|
|
709
756
|
act(blockId, action) {
|
|
710
757
|
if (action === "accept")
|
|
@@ -1063,6 +1110,8 @@ function createAiStream(cfg) {
|
|
|
1063
1110
|
|
|
1064
1111
|
export {
|
|
1065
1112
|
rootEl,
|
|
1113
|
+
docExtent,
|
|
1114
|
+
selectionCovers,
|
|
1066
1115
|
pointToDom,
|
|
1067
1116
|
domToPoint,
|
|
1068
1117
|
readSelection,
|