markloom 0.3.0 → 0.5.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 (52) hide show
  1. package/README.md +29 -16
  2. package/ai.md +160 -0
  3. package/collab.md +68 -0
  4. package/dist/ai/index.cjs +4 -3
  5. package/dist/ai/index.d.cts +4 -2
  6. package/dist/ai/index.d.ts +4 -2
  7. package/dist/ai/index.js +5 -4
  8. package/dist/ai/theme.css +63 -63
  9. package/dist/{chunk-VVFIQLVR.cjs → chunk-4TMHVNL6.cjs} +71 -79
  10. package/dist/chunk-6DCI7AL3.js +208 -0
  11. package/dist/chunk-AC5E42NH.cjs +208 -0
  12. package/dist/chunk-GQ2HHRGI.cjs +16 -0
  13. package/dist/{chunk-GUPMZI6Q.js → chunk-JMOJU5EU.js} +7 -5
  14. package/dist/chunk-JS527FDV.cjs +294 -0
  15. package/dist/chunk-LA5SBCGQ.js +16 -0
  16. package/dist/{chunk-ITVAR2UM.js → chunk-LEYAQNJA.js} +5 -3
  17. package/dist/{chunk-J3QWW6CN.js → chunk-MFYF2A6U.js} +5 -13
  18. package/dist/chunk-RLTHVQNQ.js +294 -0
  19. package/dist/{chunk-7Q6AXLF2.cjs → chunk-SLRD6FMP.cjs} +30 -28
  20. package/dist/{chunk-UCNEQGMY.js → chunk-WUHTCCAE.js} +391 -332
  21. package/dist/{chunk-2X6AF7XH.cjs → chunk-YJAWPRJW.cjs} +722 -663
  22. package/dist/{chunk-HA6XHJUD.cjs → chunk-YXQDCW4Y.cjs} +22 -20
  23. package/dist/client-A0ZQJnyR.d.ts +137 -0
  24. package/dist/client-BNams4wv.d.cts +137 -0
  25. package/dist/collab/index.cjs +19 -0
  26. package/dist/collab/index.d.cts +3 -0
  27. package/dist/collab/index.d.ts +3 -0
  28. package/dist/collab/index.js +19 -0
  29. package/dist/comments-DlExS6f-.d.cts +43 -0
  30. package/dist/comments-PhnR7Gkn.d.ts +43 -0
  31. package/dist/{controller-Dm4uLD3I.d.ts → controller-BkY1VPzc.d.ts} +24 -8
  32. package/dist/{controller-cE9iEYp3.d.cts → controller-CVIZI--A.d.cts} +24 -8
  33. package/dist/index.cjs +21 -243
  34. package/dist/index.d.cts +5 -7
  35. package/dist/index.d.ts +5 -7
  36. package/dist/index.js +22 -244
  37. package/dist/react/index.cjs +12 -9
  38. package/dist/react/index.d.cts +7 -5
  39. package/dist/react/index.d.ts +7 -5
  40. package/dist/react/index.js +12 -9
  41. package/dist/rebase-batch-8rL_aXEE.d.ts +38 -0
  42. package/dist/rebase-batch-bYnBJpRO.d.cts +38 -0
  43. package/dist/step-BrvHIK7O.d.cts +65 -0
  44. package/dist/step-BrvHIK7O.d.ts +65 -0
  45. package/dist/view/index.cjs +11 -8
  46. package/dist/view/index.d.cts +7 -5
  47. package/dist/view/index.d.ts +7 -5
  48. package/dist/view/index.js +9 -6
  49. package/dist/view/theme.css +507 -507
  50. package/package.json +10 -3
  51. package/dist/comments-USjT1wYN.d.cts +0 -105
  52. package/dist/comments-USjT1wYN.d.ts +0 -105
@@ -5,12 +5,14 @@
5
5
 
6
6
 
7
7
 
8
+ var _chunk4TMHVNL6cjs = require('./chunk-4TMHVNL6.cjs');
8
9
 
9
- var _chunkVVFIQLVRcjs = require('./chunk-VVFIQLVR.cjs');
10
+
11
+ var _chunkGQ2HHRGIcjs = require('./chunk-GQ2HHRGI.cjs');
10
12
 
11
13
  // src/view/selection.ts
12
14
  function rootEl(root) {
13
- return _nullishCoalesce(root.querySelector(".loom-doc"), () => ( root));
15
+ return _nullishCoalesce(root.querySelector(".markloom-doc"), () => ( root));
14
16
  }
15
17
  function pointToDom(root, doc, pos) {
16
18
  const path = pos.path;
@@ -68,7 +70,7 @@ function domToPoint(root, doc, container, domOffset) {
68
70
  }
69
71
  if (segs.length === 0)
70
72
  return null;
71
- return { path: _chunkVVFIQLVRcjs.normalizeToLeaf.call(void 0, doc, segs.concat(charOffset)) };
73
+ return { path: _chunk4TMHVNL6cjs.normalizeToLeaf.call(void 0, doc, segs.concat(charOffset)) };
72
74
  }
73
75
  function readSelection(root, doc) {
74
76
  const sel = root.ownerDocument.getSelection();
@@ -216,18 +218,18 @@ function focusBlockId(ed) {
216
218
  const sel = readSelection(ed.root, ed.doc);
217
219
  const idx = _nullishCoalesce(_optionalChain([sel, 'optionalAccess', _8 => _8.head, 'access', _9 => _9.path, 'access', _10 => _10[0]]), () => ( Math.max(0, ed.doc.children.length - 1)));
218
220
  const b = ed.doc.children[idx];
219
- if (!b || _chunkVVFIQLVRcjs.isText.call(void 0, b) || !b.id)
221
+ if (!b || _chunkGQ2HHRGIcjs.isText.call(void 0, b) || !b.id)
220
222
  return null;
221
223
  return b.id;
222
224
  }
223
225
  function blockPlainText(doc, blockId) {
224
- const b = doc.children.find((c) => !_chunkVVFIQLVRcjs.isText.call(void 0, c) && c.id === blockId);
226
+ const b = doc.children.find((c) => !_chunkGQ2HHRGIcjs.isText.call(void 0, c) && c.id === blockId);
225
227
  if (!b)
226
228
  return "";
227
229
  return collectText(b);
228
230
  }
229
231
  function collectText(n) {
230
- if (_chunkVVFIQLVRcjs.isText.call(void 0, n))
232
+ if (_chunkGQ2HHRGIcjs.isText.call(void 0, n))
231
233
  return n.text;
232
234
  return n.children.map(collectText).join("");
233
235
  }
@@ -247,11 +249,11 @@ function emptyLike(block) {
247
249
  return { type: "paragraph", id: block.id, attrs: block.attrs ? { ...block.attrs } : void 0, children: [{ text: "" }] };
248
250
  }
249
251
  function streamTargetId(doc, blockId) {
250
- const b = doc.children.find((c) => !_chunkVVFIQLVRcjs.isText.call(void 0, c) && c.id === blockId);
252
+ const b = doc.children.find((c) => !_chunkGQ2HHRGIcjs.isText.call(void 0, c) && c.id === blockId);
251
253
  if (!b)
252
254
  return blockId;
253
255
  if (b.type === "quote" || b.type === "callout") {
254
- const inner = b.children.find((c) => !_chunkVVFIQLVRcjs.isText.call(void 0, c) && c.type === "paragraph");
256
+ const inner = b.children.find((c) => !_chunkGQ2HHRGIcjs.isText.call(void 0, c) && c.type === "paragraph");
255
257
  if (_optionalChain([inner, 'optionalAccess', _11 => _11.id]))
256
258
  return inner.id;
257
259
  }
@@ -273,16 +275,16 @@ function startAiWrite(ed, mode, blockId) {
273
275
  if (mode === "continue") {
274
276
  const id = newId();
275
277
  const empty = { type: "paragraph", id, children: [{ text: "" }] };
276
- ed.dispatch([_chunkVVFIQLVRcjs.insertAfter.call(void 0, doc, focus, [empty])]);
278
+ ed.dispatch([_chunk4TMHVNL6cjs.insertAfter.call(void 0, doc, focus, [empty])]);
277
279
  targetId = id;
278
280
  } else {
279
- const block = doc.children.find((c) => !_chunkVVFIQLVRcjs.isText.call(void 0, c) && c.id === focus);
281
+ const block = doc.children.find((c) => !_chunkGQ2HHRGIcjs.isText.call(void 0, c) && c.id === focus);
280
282
  if (!block)
281
283
  throw new Error(`block not found: ${focus}`);
282
284
  if (block.type === "table" || block.type === "image" || block.type === "embed" || block.type === "raw")
283
285
  throw new Error(`cannot rewrite ${block.type}`);
284
286
  const cleared = emptyLike(block);
285
- ed.dispatch([_chunkVVFIQLVRcjs.rewriteNode.call(void 0, doc, focus, cleared)]);
287
+ ed.dispatch([_chunk4TMHVNL6cjs.rewriteNode.call(void 0, doc, focus, cleared)]);
286
288
  targetId = streamTargetId(ed.doc, focus);
287
289
  }
288
290
  opened = true;
@@ -291,7 +293,7 @@ function startAiWrite(ed, mode, blockId) {
291
293
  if (!alive || !text)
292
294
  return;
293
295
  setup();
294
- const step = _chunkVVFIQLVRcjs.appendText.call(void 0, ed.doc, targetId, text);
296
+ const step = _chunk4TMHVNL6cjs.appendText.call(void 0, ed.doc, targetId, text);
295
297
  ed.dispatchStream([step]);
296
298
  };
297
299
  const finish = () => {
@@ -316,7 +318,7 @@ function precedingPlainText(doc, blockIdx) {
316
318
  const parts = [];
317
319
  for (let i = 0; i < blockIdx && i < doc.children.length; i++) {
318
320
  const b = doc.children[i];
319
- if (_chunkVVFIQLVRcjs.isText.call(void 0, b) || !b.id)
321
+ if (_chunkGQ2HHRGIcjs.isText.call(void 0, b) || !b.id)
320
322
  continue;
321
323
  if (b.type === "image" || b.type === "table" || b.type === "embed" || b.type === "raw" || b.type === "ai")
322
324
  continue;
@@ -337,7 +339,7 @@ function aiInstructionFromQuery(query) {
337
339
  var newAiId = () => _nullishCoalesce(_optionalChain([crypto, 'access', _14 => _14.randomUUID, 'optionalCall', _15 => _15()]), () => ( `ai${Math.random().toString(36).slice(2)}`));
338
340
 
339
341
  // src/ai/controller.ts
340
- var LoomAi = (_class = class {
342
+ var MarkloomAi = (_class = class {
341
343
 
342
344
 
343
345
  __init() {this.abort = null}
@@ -409,7 +411,7 @@ var LoomAi = (_class = class {
409
411
  return;
410
412
  }
411
413
  const doc = ed.doc;
412
- const idx = doc.children.findIndex((c) => !_chunkVVFIQLVRcjs.isText.call(void 0, c) && c.id === bid);
414
+ const idx = doc.children.findIndex((c) => !_chunkGQ2HHRGIcjs.isText.call(void 0, c) && c.id === bid);
413
415
  if (idx < 0)
414
416
  return;
415
417
  const cur = doc.children[idx];
@@ -618,7 +620,7 @@ var LoomAi = (_class = class {
618
620
  const steps = [];
619
621
  for (let i = 0; i < doc.children.length; i++) {
620
622
  const c = doc.children[i];
621
- if (_chunkVVFIQLVRcjs.isText.call(void 0, c) || _optionalChain([c, 'access', _57 => _57.attrs, 'optionalAccess', _58 => _58.aiFrom]) !== blockId)
623
+ if (_chunkGQ2HHRGIcjs.isText.call(void 0, c) || _optionalChain([c, 'access', _57 => _57.attrs, 'optionalAccess', _58 => _58.aiFrom]) !== blockId)
622
624
  continue;
623
625
  const attrs = { ..._nullishCoalesce(c.attrs, () => ( {})) };
624
626
  delete attrs.aiDraft;
@@ -634,12 +636,12 @@ var LoomAi = (_class = class {
634
636
  next.attrs = clean;
635
637
  steps.push({ kind: "replaceNode", path: [i], node: next });
636
638
  }
637
- const aiIdx0 = doc.children.findIndex((c) => !_chunkVVFIQLVRcjs.isText.call(void 0, c) && c.id === blockId);
639
+ const aiIdx0 = doc.children.findIndex((c) => !_chunkGQ2HHRGIcjs.isText.call(void 0, c) && c.id === blockId);
638
640
  if (aiIdx0 >= 0)
639
641
  steps.push({ kind: "spliceChildren", path: [], at: aiIdx0, remove: 1, insert: [] });
640
642
  if (!steps.length)
641
643
  return;
642
- const firstDraft = doc.children.findIndex((c) => !_chunkVVFIQLVRcjs.isText.call(void 0, c) && _optionalChain([c, 'access', _59 => _59.attrs, 'optionalAccess', _60 => _60.aiFrom]) === blockId);
644
+ const firstDraft = doc.children.findIndex((c) => !_chunkGQ2HHRGIcjs.isText.call(void 0, c) && _optionalChain([c, 'access', _59 => _59.attrs, 'optionalAccess', _60 => _60.aiFrom]) === blockId);
643
645
  let caretAt = firstDraft >= 0 ? firstDraft : Math.max(0, aiIdx0);
644
646
  if (firstDraft > aiIdx0)
645
647
  caretAt = firstDraft - 1;
@@ -683,7 +685,7 @@ var LoomAi = (_class = class {
683
685
  const idxs = draftIndices(doc, blockId);
684
686
  for (let i = idxs.length - 1; i >= 0; i--)
685
687
  steps.push({ kind: "spliceChildren", path: [], at: idxs[i], remove: 1, insert: [] });
686
- let aiIdx = doc.children.findIndex((c) => !_chunkVVFIQLVRcjs.isText.call(void 0, c) && c.id === blockId);
688
+ let aiIdx = doc.children.findIndex((c) => !_chunkGQ2HHRGIcjs.isText.call(void 0, c) && c.id === blockId);
687
689
  let shift = 0;
688
690
  for (const i of idxs) {
689
691
  if (i < aiIdx)
@@ -722,11 +724,11 @@ var LoomAi = (_class = class {
722
724
  this.txBlockId = null;
723
725
  }
724
726
  findAi(ed, blockId) {
725
- const path = _chunkVVFIQLVRcjs.pathOfId.call(void 0, ed.doc, blockId);
727
+ const path = _chunk4TMHVNL6cjs.pathOfId.call(void 0, ed.doc, blockId);
726
728
  if (!path)
727
729
  return null;
728
730
  const node = path.reduce((n, i) => n.children[i], ed.doc);
729
- if (!node || _chunkVVFIQLVRcjs.isText.call(void 0, node) || node.type !== "ai")
731
+ if (!node || _chunkGQ2HHRGIcjs.isText.call(void 0, node) || node.type !== "ai")
730
732
  return null;
731
733
  return { path, node };
732
734
  }
@@ -750,7 +752,7 @@ var LoomAi = (_class = class {
750
752
  paintMd(ed, blockId, md, streaming) {
751
753
  const doc = ed.doc;
752
754
  const idxs = draftIndices(doc, blockId);
753
- const aiIdx = doc.children.findIndex((c) => !_chunkVVFIQLVRcjs.isText.call(void 0, c) && c.id === blockId);
755
+ const aiIdx = doc.children.findIndex((c) => !_chunkGQ2HHRGIcjs.isText.call(void 0, c) && c.id === blockId);
754
756
  const at = idxs.length ? idxs[0] : aiIdx >= 0 ? aiIdx + 1 : -1;
755
757
  if (at < 0)
756
758
  return;
@@ -780,7 +782,7 @@ var LoomAi = (_class = class {
780
782
  const src = streaming ? softCloseMd(raw) : raw;
781
783
  let blocks;
782
784
  try {
783
- const tops = _chunkVVFIQLVRcjs.mdToDoc.call(void 0, src).children.filter((c) => !_chunkVVFIQLVRcjs.isText.call(void 0, c));
785
+ const tops = _chunk4TMHVNL6cjs.mdToDoc.call(void 0, src).children.filter((c) => !_chunkGQ2HHRGIcjs.isText.call(void 0, c));
784
786
  blocks = tops.map((c, i) => stampDraft(c, blockId, `${blockId}_d${i}`, streaming && i === tops.length - 1));
785
787
  } catch (e2) {
786
788
  blocks = [{
@@ -869,7 +871,7 @@ function softCloseMd(md) {
869
871
  }
870
872
  function stampDraft(node, aiFrom, id, streamTail = false) {
871
873
  const kids = node.children.map((c, i) => {
872
- if (_chunkVVFIQLVRcjs.isText.call(void 0, c))
874
+ if (_chunkGQ2HHRGIcjs.isText.call(void 0, c))
873
875
  return c;
874
876
  return stampInner(c, `${id}_${i}`);
875
877
  });
@@ -880,7 +882,7 @@ function stampDraft(node, aiFrom, id, streamTail = false) {
880
882
  }
881
883
  function stampInner(node, id) {
882
884
  const kids = node.children.map((c, i) => {
883
- if (_chunkVVFIQLVRcjs.isText.call(void 0, c))
885
+ if (_chunkGQ2HHRGIcjs.isText.call(void 0, c))
884
886
  return c;
885
887
  return stampInner(c, `${id}_${i}`);
886
888
  });
@@ -895,7 +897,7 @@ function draftIndices(doc, aiId) {
895
897
  const out = [];
896
898
  for (let i = 0; i < doc.children.length; i++) {
897
899
  const c = doc.children[i];
898
- if (!_chunkVVFIQLVRcjs.isText.call(void 0, c) && _optionalChain([c, 'access', _67 => _67.attrs, 'optionalAccess', _68 => _68.aiFrom]) === aiId)
900
+ if (!_chunkGQ2HHRGIcjs.isText.call(void 0, c) && _optionalChain([c, 'access', _67 => _67.attrs, 'optionalAccess', _68 => _68.aiFrom]) === aiId)
899
901
  out.push(i);
900
902
  }
901
903
  return out;
@@ -905,7 +907,7 @@ function promptText(ai) {
905
907
  return p ? collectText2(p) : "";
906
908
  }
907
909
  function collectText2(n) {
908
- if (_chunkVVFIQLVRcjs.isText.call(void 0, n))
910
+ if (_chunkGQ2HHRGIcjs.isText.call(void 0, n))
909
911
  return n.text;
910
912
  return n.children.map(collectText2).join("");
911
913
  }
@@ -1073,4 +1075,4 @@ function createAiStream(cfg) {
1073
1075
 
1074
1076
 
1075
1077
 
1076
- exports.rootEl = rootEl; exports.pointToDom = pointToDom; exports.domToPoint = domToPoint; exports.readSelection = readSelection; exports.writeSelection = writeSelection; exports.elementChildren = elementChildren; exports.focusBlockId = focusBlockId; exports.blockPlainText = blockPlainText; exports.startAiWrite = startAiWrite; exports.precedingPlainText = precedingPlainText; exports.aiInstructionFromQuery = aiInstructionFromQuery; exports.LoomAi = LoomAi; exports.createAiStream = createAiStream;
1078
+ exports.rootEl = rootEl; exports.pointToDom = pointToDom; exports.domToPoint = domToPoint; exports.readSelection = readSelection; exports.writeSelection = writeSelection; exports.elementChildren = elementChildren; exports.focusBlockId = focusBlockId; exports.blockPlainText = blockPlainText; exports.startAiWrite = startAiWrite; exports.precedingPlainText = precedingPlainText; exports.aiInstructionFromQuery = aiInstructionFromQuery; exports.MarkloomAi = MarkloomAi; exports.createAiStream = createAiStream;