markloom 0.6.0 → 0.7.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 (59) hide show
  1. package/collab.md +25 -13
  2. package/dist/ai/index.cjs +5 -4
  3. package/dist/ai/index.d.cts +5 -5
  4. package/dist/ai/index.d.ts +5 -5
  5. package/dist/ai/index.js +4 -3
  6. package/dist/{chunk-KYZJIOOL.js → chunk-4Q7PAR2T.js} +3671 -904
  7. package/dist/chunk-75EJ4ARB.cjs +642 -0
  8. package/dist/{chunk-U3JZDFL4.cjs → chunk-BMPCVT3B.cjs} +2 -34
  9. package/dist/{chunk-VSBIMMI7.js → chunk-EFYT2223.js} +3 -35
  10. package/dist/chunk-HXABDVLZ.cjs +297 -0
  11. package/dist/{chunk-I5VK4U7J.cjs → chunk-I2LDEVLA.cjs} +434 -80
  12. package/dist/{chunk-YBAT343I.js → chunk-MQLRZQZL.js} +263 -119
  13. package/dist/chunk-OVHASRID.cjs +4279 -0
  14. package/dist/chunk-PCSVBPOR.cjs +40 -0
  15. package/dist/{chunk-TB2OY3D4.js → chunk-PSAXWBNM.js} +413 -59
  16. package/dist/{chunk-QEVME6ZU.cjs → chunk-PZRWTLLB.cjs} +260 -161
  17. package/dist/chunk-QO7JEZDB.js +4279 -0
  18. package/dist/{chunk-EJSFZHGT.js → chunk-WSJUXPAG.js} +18 -2
  19. package/dist/{chunk-ACFYBYZJ.cjs → chunk-Y4IXQFWL.cjs} +4212 -1445
  20. package/dist/{chunk-CGYCJORO.js → chunk-YLVSMDIO.js} +220 -121
  21. package/dist/chunk-ZL6WT6OY.js +297 -0
  22. package/dist/{client-CLYq17SW.d.ts → client-BvvyHjhh.d.ts} +57 -7
  23. package/dist/{client-DAth8pPq.d.cts → client-Ciy7Fa_k.d.cts} +57 -7
  24. package/dist/collab/index.cjs +5 -4
  25. package/dist/collab/index.d.cts +13 -15
  26. package/dist/collab/index.d.ts +13 -15
  27. package/dist/collab/index.js +4 -3
  28. package/dist/{controller-BIOO_XKJ.d.cts → controller-CHznEhAR.d.cts} +186 -27
  29. package/dist/{controller-6AJ36G52.d.ts → controller-DLqI8_jm.d.ts} +186 -27
  30. package/dist/index.cjs +69 -7
  31. package/dist/index.d.cts +127 -8
  32. package/dist/index.d.ts +127 -8
  33. package/dist/index.js +80 -18
  34. package/dist/io/index.cjs +58 -59
  35. package/dist/io/index.d.cts +1 -1
  36. package/dist/io/index.d.ts +1 -1
  37. package/dist/io/index.js +15 -16
  38. package/dist/react/index.cjs +9 -8
  39. package/dist/react/index.d.cts +5 -5
  40. package/dist/react/index.d.ts +5 -5
  41. package/dist/react/index.js +8 -7
  42. package/dist/{rebase-batch-DlerAcFN.d.ts → rebase-batch-CSnv8FKp.d.ts} +1 -1
  43. package/dist/{rebase-batch-PjENQ742.d.cts → rebase-batch-DO1ygkx9.d.cts} +1 -1
  44. package/dist/{types-COUweEav.d.cts → types-BkHlmUFL.d.cts} +5 -1
  45. package/dist/{types-COUweEav.d.ts → types-BkHlmUFL.d.ts} +5 -1
  46. package/dist/{versions-9mG1epfB.d.cts → versions-DNFf8zVz.d.cts} +1 -1
  47. package/dist/{versions-Bubyo4pt.d.ts → versions-DOkOyh2J.d.ts} +1 -1
  48. package/dist/view/index.cjs +215 -17
  49. package/dist/view/index.d.cts +82 -9
  50. package/dist/view/index.d.ts +82 -9
  51. package/dist/view/index.js +212 -14
  52. package/dist/view/theme.css +349 -75
  53. package/dist/{suggest-Bk4zLzuv.d.ts → word-count-BPw9G2Bg.d.ts} +15 -5
  54. package/dist/{suggest-BkGGiPKA.d.cts → word-count-DNLn1h_t.d.cts} +15 -5
  55. package/package.json +11 -6
  56. package/dist/chunk-EADZKEU4.cjs +0 -498
  57. package/dist/chunk-SNFF6X45.js +0 -2347
  58. package/dist/chunk-TWD5T4YC.cjs +0 -2347
  59. package/dist/chunk-ZKQSQSSM.cjs +0 -24
@@ -1,7 +1,6 @@
1
1
  import {
2
- isElement,
3
- isText
4
- } from "./chunk-EJSFZHGT.js";
2
+ normalizeToLeaf
3
+ } from "./chunk-ZL6WT6OY.js";
5
4
 
6
5
  // src/tree/map.ts
7
6
  function mapPosition(step, pos) {
@@ -89,38 +88,7 @@ function underPrefix(a, b) {
89
88
  return b.length > a.length && isPrefix(a, b);
90
89
  }
91
90
  function normalizePosition(doc, pos) {
92
- let cur = doc;
93
- for (let i = 0; i < pos.path.length - 1; i++) {
94
- if (!isElement(cur))
95
- break;
96
- const next = cur.children[pos.path[i]];
97
- if (!next)
98
- return pos;
99
- cur = next;
100
- }
101
- if (isText(cur))
102
- return pos;
103
- const at = pos.path[pos.path.length - 1] ?? 0;
104
- const prefix = pos.path.slice(0, -1);
105
- return withPath(descendToText(cur, at, prefix), pos);
106
- }
107
- function descendToText(parent, at, prefix) {
108
- const kids = parent.children;
109
- if (kids.length === 0)
110
- return prefix.concat(0);
111
- const leftIdx = at > 0 ? at - 1 : 0;
112
- const toEnd = at > 0;
113
- let path = prefix.concat(leftIdx);
114
- let node = kids[Math.min(leftIdx, kids.length - 1)];
115
- while (isElement(node)) {
116
- const cs = node.children;
117
- if (cs.length === 0)
118
- return path.concat(0);
119
- const idx = toEnd ? cs.length - 1 : 0;
120
- path = path.concat(idx);
121
- node = cs[idx];
122
- }
123
- return path.concat(toEnd ? node.text.length : 0);
91
+ return withPath(normalizeToLeaf(doc, pos.path), pos);
124
92
  }
125
93
 
126
94
  // src/tree/rebase.ts
@@ -0,0 +1,297 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+
4
+
5
+ var _chunkPCSVBPORcjs = require('./chunk-PCSVBPOR.cjs');
6
+
7
+ // src/tree/addr.ts
8
+ function resolve(doc, path) {
9
+ if (path.length === 0)
10
+ return { node: doc, offset: 0, parents: [], indexInParent: [] };
11
+ const parents = [];
12
+ const indexInParent = [];
13
+ let cur = doc;
14
+ for (let i = 0; i < path.length - 1; i++) {
15
+ if (!_chunkPCSVBPORcjs.isElement.call(void 0, cur))
16
+ throw new Error(`path \u8D8A\u8FC7\u6587\u672C\u53F6: ${path.join(",")} \u5728\u7B2C ${i} \u6BB5`);
17
+ parents.push(cur);
18
+ indexInParent.push(path[i]);
19
+ const child = cur.children[path[i]];
20
+ if (!child)
21
+ throw new Error(`path \u8D8A\u754C: ${path.join(",")} \u5728\u7B2C ${i} \u6BB5\u65E0 child ${path[i]}`);
22
+ cur = child;
23
+ }
24
+ const last = path[path.length - 1];
25
+ return { node: cur, offset: last, parents, indexInParent };
26
+ }
27
+ function firstLeafPath(block) {
28
+ for (let i = 0; i < block.children.length; i++) {
29
+ const c = block.children[i];
30
+ if (_chunkPCSVBPORcjs.isInlineAtom.call(void 0, c))
31
+ continue;
32
+ if (_chunkPCSVBPORcjs.isText.call(void 0, c))
33
+ return [i];
34
+ return [i, ...firstLeafPath(c)];
35
+ }
36
+ return [0];
37
+ }
38
+ function absorbsAfter(n) {
39
+ if (_chunkPCSVBPORcjs.isText.call(void 0, n))
40
+ return false;
41
+ if (n.type === "mention")
42
+ return false;
43
+ return n.children.length === 0 || !hasTextLeaf(n);
44
+ }
45
+ function gapToTextPath(parent, at, prefix = []) {
46
+ const kids = parent.children;
47
+ if (kids.length === 0)
48
+ return prefix.concat(0);
49
+ const clampAt = Math.max(0, Math.min(at, kids.length));
50
+ const tryEnd = (idx) => {
51
+ const n = kids[idx];
52
+ if (!n || _chunkPCSVBPORcjs.isText.call(void 0, n))
53
+ return n && _chunkPCSVBPORcjs.isText.call(void 0, n) ? prefix.concat(idx, n.text.length) : null;
54
+ if (n.children.length === 0 || !hasTextLeaf(n))
55
+ return null;
56
+ return prefix.concat(idx, ...lastLeafEnd(n));
57
+ };
58
+ const tryStart = (idx) => {
59
+ const n = kids[idx];
60
+ if (!n || _chunkPCSVBPORcjs.isText.call(void 0, n))
61
+ return n && _chunkPCSVBPORcjs.isText.call(void 0, n) ? prefix.concat(idx, 0) : null;
62
+ if (n.children.length === 0 || !hasTextLeaf(n))
63
+ return null;
64
+ return prefix.concat(idx, ...firstLeafPath(n), 0);
65
+ };
66
+ let i = clampAt;
67
+ while (i < kids.length && absorbsAfter(kids[i]))
68
+ i++;
69
+ if (i !== clampAt) {
70
+ const skipped = tryStart(i);
71
+ if (skipped)
72
+ return skipped;
73
+ } else if (clampAt > 0) {
74
+ const left = tryEnd(clampAt - 1);
75
+ if (left)
76
+ return left;
77
+ const right = tryStart(clampAt);
78
+ if (right)
79
+ return right;
80
+ } else {
81
+ const right = tryStart(0);
82
+ if (right)
83
+ return right;
84
+ }
85
+ for (let j = Math.min(i, kids.length) - 1; j >= 0; j--) {
86
+ const p = tryEnd(j);
87
+ if (p)
88
+ return p;
89
+ }
90
+ for (let j = i; j < kids.length; j++) {
91
+ const p = tryStart(j);
92
+ if (p)
93
+ return p;
94
+ }
95
+ return prefix.concat(0);
96
+ }
97
+ function hasTextLeaf(n) {
98
+ for (const c of n.children) {
99
+ if (_chunkPCSVBPORcjs.isText.call(void 0, c))
100
+ return true;
101
+ if (_chunkPCSVBPORcjs.isElement.call(void 0, c) && !_chunkPCSVBPORcjs.isInlineAtom.call(void 0, c) && hasTextLeaf(c))
102
+ return true;
103
+ }
104
+ return false;
105
+ }
106
+ function normalizeToLeaf(doc, path) {
107
+ if (path.length === 0)
108
+ return gapToTextPath(doc, 0, []);
109
+ const prefix = [];
110
+ let cur = doc;
111
+ for (let i = 0; i < path.length; i++) {
112
+ if (_chunkPCSVBPORcjs.isText.call(void 0, cur)) {
113
+ return prefix.concat(Math.max(0, path[i]));
114
+ }
115
+ if (i === path.length - 1) {
116
+ if (_chunkPCSVBPORcjs.isElement.call(void 0, cur) && cur.children.length === 0 && prefix.length >= 1) {
117
+ const idx = prefix[prefix.length - 1];
118
+ const parentPath = prefix.slice(0, -1);
119
+ const parent = parentPath.length ? nodeAt(doc, parentPath) : doc;
120
+ return gapToTextPath(parent, absorbsAfter(cur) ? idx + 1 : idx, parentPath);
121
+ }
122
+ return gapToTextPath(cur, path[i], prefix);
123
+ }
124
+ const child = cur.children[path[i]];
125
+ if (!child) {
126
+ if (_chunkPCSVBPORcjs.isElement.call(void 0, cur) && cur.children.length === 0 && prefix.length >= 1) {
127
+ const idx = prefix[prefix.length - 1];
128
+ const parentPath = prefix.slice(0, -1);
129
+ const parent = parentPath.length ? nodeAt(doc, parentPath) : doc;
130
+ return gapToTextPath(parent, absorbsAfter(cur) ? idx + 1 : idx, parentPath);
131
+ }
132
+ return gapToTextPath(cur, _nullishCoalesce(path[i], () => ( 0)), prefix);
133
+ }
134
+ prefix.push(path[i]);
135
+ cur = child;
136
+ }
137
+ if (_chunkPCSVBPORcjs.isText.call(void 0, cur))
138
+ return prefix.concat(0);
139
+ if (_chunkPCSVBPORcjs.isInlineAtom.call(void 0, cur) && prefix.length >= 1) {
140
+ const parent = nodeAt(doc, prefix.slice(0, -1));
141
+ const idx = prefix[prefix.length - 1];
142
+ return gapToTextPath(parent, absorbsAfter(cur) ? idx + 1 : idx, prefix.slice(0, -1));
143
+ }
144
+ if (_chunkPCSVBPORcjs.isElement.call(void 0, cur) && cur.children.length === 0 && prefix.length >= 1) {
145
+ const parent = nodeAt(doc, prefix.slice(0, -1));
146
+ const idx = prefix[prefix.length - 1];
147
+ return gapToTextPath(parent, idx + 1, prefix.slice(0, -1));
148
+ }
149
+ if (_chunkPCSVBPORcjs.isElement.call(void 0, cur))
150
+ return gapToTextPath(cur, 0, prefix);
151
+ return prefix.concat(0);
152
+ }
153
+ function lastLeafEnd(block) {
154
+ for (let i = block.children.length - 1; i >= 0; i--) {
155
+ const last = block.children[i];
156
+ if (_chunkPCSVBPORcjs.isInlineAtom.call(void 0, last))
157
+ continue;
158
+ if (_chunkPCSVBPORcjs.isText.call(void 0, last))
159
+ return [i, last.text.length];
160
+ return [i, ...lastLeafEnd(last)];
161
+ }
162
+ return [0, 0];
163
+ }
164
+ function nodeAt(doc, path) {
165
+ let cur = doc;
166
+ for (const seg of path) {
167
+ if (!_chunkPCSVBPORcjs.isElement.call(void 0, cur))
168
+ throw new Error(`nodeAt \u8D8A\u8FC7\u6587\u672C\u53F6: ${path.join(",")}`);
169
+ const child = cur.children[seg];
170
+ if (!child)
171
+ throw new Error(`nodeAt \u8D8A\u754C: ${path.join(",")} \u65E0 child ${seg}`);
172
+ cur = child;
173
+ }
174
+ return cur;
175
+ }
176
+ function replaceAt(doc, path, next) {
177
+ if (path.length === 0) {
178
+ if (_chunkPCSVBPORcjs.isText.call(void 0, next))
179
+ throw new Error("\u6839\u4E0D\u80FD\u662F\u6587\u672C\u53F6");
180
+ return next;
181
+ }
182
+ return update(doc, path, 0, () => next);
183
+ }
184
+ function spliceAt(doc, path, at, remove, insert) {
185
+ return update(doc, path, 0, (node) => {
186
+ if (!_chunkPCSVBPORcjs.isElement.call(void 0, node))
187
+ throw new Error("spliceAt \u76EE\u6807\u4E0D\u662F\u5143\u7D20");
188
+ const children = node.children.slice();
189
+ children.splice(at, remove, ...insert);
190
+ return { ...node, children };
191
+ });
192
+ }
193
+ function update(node, path, depth, fn) {
194
+ if (depth === path.length) {
195
+ const r = fn(node);
196
+ if (_chunkPCSVBPORcjs.isText.call(void 0, r))
197
+ throw new Error("update \u4E0D\u80FD\u628A\u5143\u7D20\u6362\u6210\u6587\u672C\u53F6");
198
+ return r;
199
+ }
200
+ if (!_chunkPCSVBPORcjs.isElement.call(void 0, node))
201
+ throw new Error(`update \u8D8A\u8FC7\u6587\u672C\u53F6: ${path.join(",")}`);
202
+ const idx = path[depth];
203
+ const children = node.children.slice();
204
+ children[idx] = updateChild(children[idx], path, depth + 1, fn);
205
+ return { ...node, children };
206
+ }
207
+ function updateChild(node, path, depth, fn) {
208
+ if (depth === path.length)
209
+ return fn(node);
210
+ if (!_chunkPCSVBPORcjs.isElement.call(void 0, node))
211
+ throw new Error(`update \u8D8A\u8FC7\u6587\u672C\u53F6: ${path.join(",")}`);
212
+ const idx = path[depth];
213
+ const children = node.children.slice();
214
+ children[idx] = updateChild(children[idx], path, depth + 1, fn);
215
+ return { ...node, children };
216
+ }
217
+
218
+ // src/tree/step.ts
219
+ function apply(doc, step) {
220
+ switch (step.kind) {
221
+ case "insertText": {
222
+ const leaf = nodeAt(doc, step.path);
223
+ if (!_chunkPCSVBPORcjs.isText.call(void 0, leaf))
224
+ throw new Error("insertText \u76EE\u6807\u4E0D\u662F\u6587\u672C\u53F6");
225
+ const text = leaf.text.slice(0, step.offset) + step.text + leaf.text.slice(step.offset);
226
+ return replaceAt(doc, step.path, { ...leaf, text });
227
+ }
228
+ case "deleteText": {
229
+ const leaf = nodeAt(doc, step.path);
230
+ if (!_chunkPCSVBPORcjs.isText.call(void 0, leaf))
231
+ throw new Error("deleteText \u76EE\u6807\u4E0D\u662F\u6587\u672C\u53F6");
232
+ const text = leaf.text.slice(0, step.offset) + leaf.text.slice(step.offset + step.length);
233
+ return replaceAt(doc, step.path, { ...leaf, text });
234
+ }
235
+ case "replaceNode":
236
+ return replaceAt(doc, step.path, step.node);
237
+ case "spliceChildren":
238
+ return spliceAt(doc, step.path, step.at, step.remove, step.insert);
239
+ }
240
+ }
241
+ function invert(doc, step) {
242
+ switch (step.kind) {
243
+ case "insertText":
244
+ return { kind: "deleteText", path: step.path, offset: step.offset, length: step.text.length };
245
+ case "deleteText": {
246
+ const leaf = nodeAt(doc, step.path);
247
+ const removed = leaf.text.slice(step.offset, step.offset + step.length);
248
+ const marks = leaf.marks;
249
+ return { kind: "insertText", path: step.path, offset: step.offset, text: removed, marks };
250
+ }
251
+ case "replaceNode":
252
+ return { kind: "replaceNode", path: step.path, node: nodeAt(doc, step.path) };
253
+ case "spliceChildren": {
254
+ const parent = nodeAt(doc, step.path);
255
+ const removed = parent.children.slice(step.at, step.at + step.remove);
256
+ return { kind: "spliceChildren", path: step.path, at: step.at, remove: step.insert.length, insert: removed };
257
+ }
258
+ }
259
+ }
260
+ function applyAll(doc, steps) {
261
+ return steps.reduce(apply, doc);
262
+ }
263
+ function moveBlock(doc, fromIdx, toGap) {
264
+ if (toGap === fromIdx || toGap === fromIdx + 1)
265
+ return [];
266
+ const block = doc.children[fromIdx];
267
+ const insertAt = toGap > fromIdx ? toGap - 1 : toGap;
268
+ return [
269
+ { kind: "spliceChildren", path: [], at: fromIdx, remove: 1, insert: [] },
270
+ { kind: "spliceChildren", path: [], at: insertAt, remove: 0, insert: [block] }
271
+ ];
272
+ }
273
+ function invertAll(doc, steps) {
274
+ const inverses = [];
275
+ let cur = doc;
276
+ for (const step of steps) {
277
+ inverses.push(invert(cur, step));
278
+ cur = apply(cur, step);
279
+ }
280
+ return inverses.reverse();
281
+ }
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+ exports.resolve = resolve; exports.firstLeafPath = firstLeafPath; exports.gapToTextPath = gapToTextPath; exports.normalizeToLeaf = normalizeToLeaf; exports.lastLeafEnd = lastLeafEnd; exports.nodeAt = nodeAt; exports.replaceAt = replaceAt; exports.spliceAt = spliceAt; exports.apply = apply; exports.invert = invert; exports.applyAll = applyAll; exports.moveBlock = moveBlock; exports.invertAll = invertAll;