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.
- package/README.md +29 -16
- package/ai.md +160 -0
- package/collab.md +68 -0
- package/dist/ai/index.cjs +4 -3
- package/dist/ai/index.d.cts +4 -2
- package/dist/ai/index.d.ts +4 -2
- package/dist/ai/index.js +5 -4
- package/dist/ai/theme.css +63 -63
- package/dist/{chunk-VVFIQLVR.cjs → chunk-4TMHVNL6.cjs} +71 -79
- package/dist/chunk-6DCI7AL3.js +208 -0
- package/dist/chunk-AC5E42NH.cjs +208 -0
- package/dist/chunk-GQ2HHRGI.cjs +16 -0
- package/dist/{chunk-GUPMZI6Q.js → chunk-JMOJU5EU.js} +7 -5
- package/dist/chunk-JS527FDV.cjs +294 -0
- package/dist/chunk-LA5SBCGQ.js +16 -0
- package/dist/{chunk-ITVAR2UM.js → chunk-LEYAQNJA.js} +5 -3
- package/dist/{chunk-J3QWW6CN.js → chunk-MFYF2A6U.js} +5 -13
- package/dist/chunk-RLTHVQNQ.js +294 -0
- package/dist/{chunk-7Q6AXLF2.cjs → chunk-SLRD6FMP.cjs} +30 -28
- package/dist/{chunk-UCNEQGMY.js → chunk-WUHTCCAE.js} +391 -332
- package/dist/{chunk-2X6AF7XH.cjs → chunk-YJAWPRJW.cjs} +722 -663
- package/dist/{chunk-HA6XHJUD.cjs → chunk-YXQDCW4Y.cjs} +22 -20
- package/dist/client-A0ZQJnyR.d.ts +137 -0
- package/dist/client-BNams4wv.d.cts +137 -0
- package/dist/collab/index.cjs +19 -0
- package/dist/collab/index.d.cts +3 -0
- package/dist/collab/index.d.ts +3 -0
- package/dist/collab/index.js +19 -0
- package/dist/comments-DlExS6f-.d.cts +43 -0
- package/dist/comments-PhnR7Gkn.d.ts +43 -0
- package/dist/{controller-Dm4uLD3I.d.ts → controller-BkY1VPzc.d.ts} +24 -8
- package/dist/{controller-cE9iEYp3.d.cts → controller-CVIZI--A.d.cts} +24 -8
- package/dist/index.cjs +21 -243
- package/dist/index.d.cts +5 -7
- package/dist/index.d.ts +5 -7
- package/dist/index.js +22 -244
- package/dist/react/index.cjs +12 -9
- package/dist/react/index.d.cts +7 -5
- package/dist/react/index.d.ts +7 -5
- package/dist/react/index.js +12 -9
- package/dist/rebase-batch-8rL_aXEE.d.ts +38 -0
- package/dist/rebase-batch-bYnBJpRO.d.cts +38 -0
- package/dist/step-BrvHIK7O.d.cts +65 -0
- package/dist/step-BrvHIK7O.d.ts +65 -0
- package/dist/view/index.cjs +11 -8
- package/dist/view/index.d.cts +7 -5
- package/dist/view/index.d.ts +7 -5
- package/dist/view/index.js +9 -6
- package/dist/view/theme.css +507 -507
- package/package.json +10 -3
- package/dist/comments-USjT1wYN.d.cts +0 -105
- 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
|
-
|
|
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(".
|
|
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:
|
|
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 ||
|
|
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) => !
|
|
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 (
|
|
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) => !
|
|
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) => !
|
|
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([
|
|
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) => !
|
|
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([
|
|
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 =
|
|
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 (
|
|
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
|
|
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) => !
|
|
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 (
|
|
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) => !
|
|
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) => !
|
|
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) => !
|
|
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 =
|
|
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 ||
|
|
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) => !
|
|
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 =
|
|
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 (
|
|
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 (
|
|
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 (!
|
|
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 (
|
|
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.
|
|
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;
|