markloom 0.5.1 → 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.
Files changed (67) hide show
  1. package/PACKAGES.md +26 -0
  2. package/README.md +20 -2
  3. package/collab.md +42 -7
  4. package/dist/ai/index.cjs +4 -4
  5. package/dist/ai/index.d.cts +5 -4
  6. package/dist/ai/index.d.ts +5 -4
  7. package/dist/ai/index.js +3 -3
  8. package/dist/ai/theme.css +66 -102
  9. package/dist/{chunk-VXM7Q6P5.cjs → chunk-ACFYBYZJ.cjs} +2604 -966
  10. package/dist/chunk-CGYCJORO.js +759 -0
  11. package/dist/chunk-EADZKEU4.cjs +498 -0
  12. package/dist/chunk-EJSFZHGT.js +24 -0
  13. package/dist/{chunk-YIFOGP2D.cjs → chunk-I5VK4U7J.cjs} +103 -60
  14. package/dist/{chunk-ZMTLSFLO.js → chunk-KYZJIOOL.js} +2138 -500
  15. package/dist/chunk-QEVME6ZU.cjs +759 -0
  16. package/dist/{chunk-MFYF2A6U.js → chunk-SNFF6X45.js} +51 -1
  17. package/dist/{chunk-FCH7LZFI.js → chunk-TB2OY3D4.js} +50 -7
  18. package/dist/{chunk-4TMHVNL6.cjs → chunk-TWD5T4YC.cjs} +155 -105
  19. package/dist/{chunk-JS527FDV.cjs → chunk-U3JZDFL4.cjs} +49 -9
  20. package/dist/{chunk-RLTHVQNQ.js → chunk-VSBIMMI7.js} +45 -5
  21. package/dist/chunk-YBAT343I.js +498 -0
  22. package/dist/chunk-ZKQSQSSM.cjs +24 -0
  23. package/dist/{client-ZRZj2nkq.d.cts → client-CLYq17SW.d.ts} +63 -7
  24. package/dist/{client-6KiH4kGK.d.ts → client-DAth8pPq.d.cts} +63 -7
  25. package/dist/collab/index.cjs +16 -4
  26. package/dist/collab/index.d.cts +19 -6
  27. package/dist/collab/index.d.ts +19 -6
  28. package/dist/collab/index.js +18 -6
  29. package/dist/{controller-BNuuUM3E.d.ts → controller-6AJ36G52.d.ts} +99 -7
  30. package/dist/{controller-DQITsFhy.d.cts → controller-BIOO_XKJ.d.cts} +99 -7
  31. package/dist/index.cjs +57 -7
  32. package/dist/index.d.cts +18 -5
  33. package/dist/index.d.ts +18 -5
  34. package/dist/index.js +54 -4
  35. package/dist/io/index.cjs +1413 -0
  36. package/dist/io/index.d.cts +33 -0
  37. package/dist/io/index.d.ts +33 -0
  38. package/dist/io/index.js +1413 -0
  39. package/dist/react/index.cjs +8 -8
  40. package/dist/react/index.d.cts +5 -4
  41. package/dist/react/index.d.ts +5 -4
  42. package/dist/react/index.js +7 -7
  43. package/dist/{rebase-batch-8rL_aXEE.d.ts → rebase-batch-DlerAcFN.d.ts} +11 -9
  44. package/dist/{rebase-batch-bYnBJpRO.d.cts → rebase-batch-PjENQ742.d.cts} +11 -9
  45. package/dist/suggest-Bk4zLzuv.d.ts +120 -0
  46. package/dist/suggest-BkGGiPKA.d.cts +120 -0
  47. package/dist/types-COUweEav.d.cts +30 -0
  48. package/dist/types-COUweEav.d.ts +30 -0
  49. package/dist/versions-9mG1epfB.d.cts +51 -0
  50. package/dist/versions-Bubyo4pt.d.ts +51 -0
  51. package/dist/view/index.cjs +56 -12
  52. package/dist/view/index.d.cts +203 -11
  53. package/dist/view/index.d.ts +203 -11
  54. package/dist/view/index.js +52 -8
  55. package/dist/view/theme.css +1829 -1587
  56. package/io.md +38 -0
  57. package/package.json +21 -5
  58. package/dist/chunk-4JSJAHTB.js +0 -255
  59. package/dist/chunk-ALZ3A5CS.cjs +0 -255
  60. package/dist/chunk-GQ2HHRGI.cjs +0 -16
  61. package/dist/chunk-LA5SBCGQ.js +0 -16
  62. package/dist/chunk-LEYAQNJA.js +0 -220
  63. package/dist/chunk-YXQDCW4Y.cjs +0 -220
  64. package/dist/comments-DlExS6f-.d.cts +0 -43
  65. package/dist/comments-PhnR7Gkn.d.ts +0 -43
  66. package/dist/step-BrvHIK7O.d.cts +0 -65
  67. 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-LA5SBCGQ.js";
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-MFYF2A6U.js";
10
+ } from "./chunk-SNFF6X45.js";
9
11
  import {
12
+ isElement,
10
13
  isText
11
- } from "./chunk-LA5SBCGQ.js";
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 (!anchor || !head)
82
- return null;
83
- return { anchor, head };
103
+ if (anchor && head)
104
+ return { anchor, head };
105
+ if (rangeCoversSurface(sel, rootEl(root)))
106
+ return docExtent(doc);
107
+ return null;
84
108
  }
85
- function writeSelection(root, doc, selection) {
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
+ }
120
+ }
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: true });
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;
@@ -1069,6 +1110,8 @@ function createAiStream(cfg) {
1069
1110
 
1070
1111
  export {
1071
1112
  rootEl,
1113
+ docExtent,
1114
+ selectionCovers,
1072
1115
  pointToDom,
1073
1116
  domToPoint,
1074
1117
  readSelection,