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.
- package/collab.md +25 -13
- package/dist/ai/index.cjs +5 -4
- package/dist/ai/index.d.cts +5 -5
- package/dist/ai/index.d.ts +5 -5
- package/dist/ai/index.js +4 -3
- package/dist/{chunk-KYZJIOOL.js → chunk-4Q7PAR2T.js} +3671 -904
- package/dist/chunk-75EJ4ARB.cjs +642 -0
- package/dist/{chunk-U3JZDFL4.cjs → chunk-BMPCVT3B.cjs} +2 -34
- package/dist/{chunk-VSBIMMI7.js → chunk-EFYT2223.js} +3 -35
- package/dist/chunk-HXABDVLZ.cjs +297 -0
- package/dist/{chunk-I5VK4U7J.cjs → chunk-I2LDEVLA.cjs} +434 -80
- package/dist/{chunk-YBAT343I.js → chunk-MQLRZQZL.js} +263 -119
- package/dist/chunk-OVHASRID.cjs +4279 -0
- package/dist/chunk-PCSVBPOR.cjs +40 -0
- package/dist/{chunk-TB2OY3D4.js → chunk-PSAXWBNM.js} +413 -59
- package/dist/{chunk-QEVME6ZU.cjs → chunk-PZRWTLLB.cjs} +260 -161
- package/dist/chunk-QO7JEZDB.js +4279 -0
- package/dist/{chunk-EJSFZHGT.js → chunk-WSJUXPAG.js} +18 -2
- package/dist/{chunk-ACFYBYZJ.cjs → chunk-Y4IXQFWL.cjs} +4212 -1445
- package/dist/{chunk-CGYCJORO.js → chunk-YLVSMDIO.js} +220 -121
- package/dist/chunk-ZL6WT6OY.js +297 -0
- package/dist/{client-CLYq17SW.d.ts → client-BvvyHjhh.d.ts} +57 -7
- package/dist/{client-DAth8pPq.d.cts → client-Ciy7Fa_k.d.cts} +57 -7
- package/dist/collab/index.cjs +5 -4
- package/dist/collab/index.d.cts +13 -15
- package/dist/collab/index.d.ts +13 -15
- package/dist/collab/index.js +4 -3
- package/dist/{controller-BIOO_XKJ.d.cts → controller-CHznEhAR.d.cts} +186 -27
- package/dist/{controller-6AJ36G52.d.ts → controller-DLqI8_jm.d.ts} +186 -27
- package/dist/index.cjs +69 -7
- package/dist/index.d.cts +127 -8
- package/dist/index.d.ts +127 -8
- package/dist/index.js +80 -18
- package/dist/io/index.cjs +58 -59
- package/dist/io/index.d.cts +1 -1
- package/dist/io/index.d.ts +1 -1
- package/dist/io/index.js +15 -16
- package/dist/react/index.cjs +9 -8
- package/dist/react/index.d.cts +5 -5
- package/dist/react/index.d.ts +5 -5
- package/dist/react/index.js +8 -7
- package/dist/{rebase-batch-DlerAcFN.d.ts → rebase-batch-CSnv8FKp.d.ts} +1 -1
- package/dist/{rebase-batch-PjENQ742.d.cts → rebase-batch-DO1ygkx9.d.cts} +1 -1
- package/dist/{types-COUweEav.d.cts → types-BkHlmUFL.d.cts} +5 -1
- package/dist/{types-COUweEav.d.ts → types-BkHlmUFL.d.ts} +5 -1
- package/dist/{versions-9mG1epfB.d.cts → versions-DNFf8zVz.d.cts} +1 -1
- package/dist/{versions-Bubyo4pt.d.ts → versions-DOkOyh2J.d.ts} +1 -1
- package/dist/view/index.cjs +215 -17
- package/dist/view/index.d.cts +82 -9
- package/dist/view/index.d.ts +82 -9
- package/dist/view/index.js +212 -14
- package/dist/view/theme.css +349 -75
- package/dist/{suggest-Bk4zLzuv.d.ts → word-count-BPw9G2Bg.d.ts} +15 -5
- package/dist/{suggest-BkGGiPKA.d.cts → word-count-DNLn1h_t.d.cts} +15 -5
- package/package.json +11 -6
- package/dist/chunk-EADZKEU4.cjs +0 -498
- package/dist/chunk-SNFF6X45.js +0 -2347
- package/dist/chunk-TWD5T4YC.cjs +0 -2347
- package/dist/chunk-ZKQSQSSM.cjs +0 -24
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
apply,
|
|
3
|
-
applyAll,
|
|
4
2
|
checkTable,
|
|
5
|
-
invertAll,
|
|
6
|
-
nodeAt,
|
|
7
3
|
validateAll
|
|
8
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-QO7JEZDB.js";
|
|
9
5
|
import {
|
|
10
6
|
mapSelectionThrough,
|
|
11
7
|
rebaseStepsThrough
|
|
12
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-EFYT2223.js";
|
|
9
|
+
import {
|
|
10
|
+
apply,
|
|
11
|
+
applyAll,
|
|
12
|
+
invertAll,
|
|
13
|
+
nodeAt
|
|
14
|
+
} from "./chunk-ZL6WT6OY.js";
|
|
13
15
|
import {
|
|
16
|
+
footnoteKey,
|
|
14
17
|
isElement,
|
|
18
|
+
isFootnoteDef,
|
|
15
19
|
isInlineAtom,
|
|
16
20
|
isText
|
|
17
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-WSJUXPAG.js";
|
|
18
22
|
|
|
19
23
|
// src/tree/history.ts
|
|
20
24
|
function init(doc, validate) {
|
|
@@ -26,6 +30,8 @@ function gate(h, next) {
|
|
|
26
30
|
throw new Error(`[invariant] \u63D0\u4EA4\u4EA7\u751F\u975E\u6CD5 doc: ${v}`);
|
|
27
31
|
}
|
|
28
32
|
function commit(h, steps, before, after) {
|
|
33
|
+
if (steps.length === 0)
|
|
34
|
+
return h;
|
|
29
35
|
const inverse = invertAll(h.doc, steps);
|
|
30
36
|
const next = applyAll(h.doc, steps);
|
|
31
37
|
gate(h, next);
|
|
@@ -69,10 +75,9 @@ function amend(h, more, after, before) {
|
|
|
69
75
|
if (h.past.length === 0)
|
|
70
76
|
return commit(h, more, before, after);
|
|
71
77
|
const last = h.past[h.past.length - 1];
|
|
72
|
-
const docBefore = applyAll(h.doc, last.inverse);
|
|
73
78
|
const steps = last.steps.concat(more);
|
|
74
|
-
const inverse = invertAll(
|
|
75
|
-
const next = applyAll(
|
|
79
|
+
const inverse = invertAll(h.doc, more).concat(last.inverse);
|
|
80
|
+
const next = applyAll(h.doc, more);
|
|
76
81
|
gate(h, next);
|
|
77
82
|
const entry = { steps, inverse };
|
|
78
83
|
if (last.before)
|
|
@@ -113,6 +118,7 @@ function invariants(schema, doc) {
|
|
|
113
118
|
walk(doc, [], schema, out, ids);
|
|
114
119
|
return out;
|
|
115
120
|
}
|
|
121
|
+
var INTERNAL_MARKS = ["html", "image"];
|
|
116
122
|
function walk(node, path, schema, out, ids) {
|
|
117
123
|
if (isText(node)) {
|
|
118
124
|
return;
|
|
@@ -135,6 +141,11 @@ function walk(node, path, schema, out, ids) {
|
|
|
135
141
|
out.push({ path, reason: `[mention] \u7F3A id` });
|
|
136
142
|
return;
|
|
137
143
|
}
|
|
144
|
+
if (node.type === "footnote_ref") {
|
|
145
|
+
if (typeof node.attrs?.label !== "string" || !node.attrs.label)
|
|
146
|
+
out.push({ path, reason: `[footnote_ref] \u7F3A label` });
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
138
149
|
if (node.type === "math") {
|
|
139
150
|
if (typeof node.attrs?.latex !== "string")
|
|
140
151
|
out.push({ path, reason: `[math] \u7F3A latex` });
|
|
@@ -152,6 +163,16 @@ function walk(node, path, schema, out, ids) {
|
|
|
152
163
|
}
|
|
153
164
|
return;
|
|
154
165
|
}
|
|
166
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
167
|
+
const child = node.children[i];
|
|
168
|
+
if (isText(child) && child.marks) {
|
|
169
|
+
for (const m of child.marks) {
|
|
170
|
+
if (!schema.marks.includes(m.name) && !INTERNAL_MARKS.includes(m.name)) {
|
|
171
|
+
out.push({ path: path.concat(i), reason: `\u672A\u77E5 mark "${m.name}"` });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
155
176
|
if (spec?.marks) {
|
|
156
177
|
for (let i = 0; i < node.children.length; i++) {
|
|
157
178
|
const child = node.children[i];
|
|
@@ -176,6 +197,61 @@ function firstViolation(vs) {
|
|
|
176
197
|
return `${v.path.join(",")}: ${v.reason}`;
|
|
177
198
|
}
|
|
178
199
|
|
|
200
|
+
// src/tree/word-count.ts
|
|
201
|
+
function isCjk(c) {
|
|
202
|
+
return c >= 19968 && c <= 40959 || c >= 13312 && c <= 19903 || c >= 131072 && c <= 195103 || c >= 63744 && c <= 64255 || c >= 12352 && c <= 12543 || c >= 44032 && c <= 55215;
|
|
203
|
+
}
|
|
204
|
+
var WORD_CHAR = /[\p{L}\p{N}\p{M}]/u;
|
|
205
|
+
var JOINER = /* @__PURE__ */ new Set(["'", "\u2019", "-", "_"]);
|
|
206
|
+
var SPACE = /\s/u;
|
|
207
|
+
function scan(text, acc) {
|
|
208
|
+
let inWord = false;
|
|
209
|
+
for (const ch of text) {
|
|
210
|
+
if (ch === "\n" || ch === "\r")
|
|
211
|
+
inWord = false;
|
|
212
|
+
else
|
|
213
|
+
acc.chars++;
|
|
214
|
+
if (SPACE.test(ch)) {
|
|
215
|
+
inWord = false;
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
acc.charsNoSpace++;
|
|
219
|
+
if (isCjk(ch.codePointAt(0))) {
|
|
220
|
+
acc.words++;
|
|
221
|
+
inWord = false;
|
|
222
|
+
} else if (WORD_CHAR.test(ch)) {
|
|
223
|
+
if (!inWord)
|
|
224
|
+
acc.words++;
|
|
225
|
+
inWord = true;
|
|
226
|
+
} else if (!(inWord && JOINER.has(ch))) {
|
|
227
|
+
inWord = false;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function leafText(n) {
|
|
232
|
+
return n.children.map((c) => isText(c) ? c.text : "\n").join("");
|
|
233
|
+
}
|
|
234
|
+
function walk2(n, acc) {
|
|
235
|
+
if (n.type === "raw")
|
|
236
|
+
return;
|
|
237
|
+
if (n.children.some(isText)) {
|
|
238
|
+
const text = leafText(n);
|
|
239
|
+
if ((n.type === "paragraph" || n.type === "heading") && text.trim() !== "")
|
|
240
|
+
acc.paragraphs++;
|
|
241
|
+
scan(text, acc);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
for (const c of n.children) {
|
|
245
|
+
if (!isText(c))
|
|
246
|
+
walk2(c, acc);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function wordCount(doc) {
|
|
250
|
+
const acc = { words: 0, chars: 0, charsNoSpace: 0, paragraphs: 0 };
|
|
251
|
+
walk2(doc, acc);
|
|
252
|
+
return acc;
|
|
253
|
+
}
|
|
254
|
+
|
|
179
255
|
// src/tree/toc.ts
|
|
180
256
|
function headingText(node) {
|
|
181
257
|
let out = "";
|
|
@@ -187,7 +263,7 @@ function headingText(node) {
|
|
|
187
263
|
}
|
|
188
264
|
function outline(doc) {
|
|
189
265
|
const out = [];
|
|
190
|
-
const
|
|
266
|
+
const walk4 = (node, path) => {
|
|
191
267
|
if (isText(node))
|
|
192
268
|
return;
|
|
193
269
|
if (node.type === "heading") {
|
|
@@ -196,60 +272,87 @@ function outline(doc) {
|
|
|
196
272
|
return;
|
|
197
273
|
}
|
|
198
274
|
for (let i = 0; i < node.children.length; i++)
|
|
199
|
-
|
|
275
|
+
walk4(node.children[i], path.concat(i));
|
|
200
276
|
};
|
|
201
|
-
|
|
277
|
+
walk4(doc, []);
|
|
202
278
|
return out;
|
|
203
279
|
}
|
|
204
280
|
|
|
205
|
-
// src/tree/
|
|
206
|
-
function
|
|
281
|
+
// src/tree/annotate.ts
|
|
282
|
+
function markIdsInDoc(doc, name) {
|
|
207
283
|
const ids = /* @__PURE__ */ new Set();
|
|
208
|
-
const
|
|
284
|
+
const walk4 = (n) => {
|
|
209
285
|
if (isText(n)) {
|
|
210
286
|
for (const m of n.marks ?? []) {
|
|
211
|
-
if (m.name ===
|
|
287
|
+
if (m.name === name && m.attrs?.id != null)
|
|
212
288
|
ids.add(String(m.attrs.id));
|
|
213
289
|
}
|
|
214
290
|
return;
|
|
215
291
|
}
|
|
216
292
|
if (isElement(n))
|
|
217
293
|
for (const c of n.children)
|
|
218
|
-
|
|
294
|
+
walk4(c);
|
|
219
295
|
};
|
|
220
|
-
|
|
296
|
+
walk4(doc);
|
|
221
297
|
return ids;
|
|
222
298
|
}
|
|
223
|
-
function
|
|
224
|
-
const rest = (leaf.marks ?? []).filter((m) => !(m.name === "comment" && String(m.attrs?.id) === id));
|
|
225
|
-
return rest.length ? { ...leaf, marks: rest } : { text: leaf.text };
|
|
226
|
-
}
|
|
227
|
-
function stripCommentMarks(doc, id) {
|
|
299
|
+
function mapLeafBlocks(doc, fn) {
|
|
228
300
|
const steps = [];
|
|
229
|
-
const
|
|
301
|
+
const walk4 = (node, path) => {
|
|
230
302
|
if (node.children.every((c) => isText(c) || isInlineAtom(c))) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return c;
|
|
235
|
-
changed = true;
|
|
236
|
-
return stripLeaf(c, id);
|
|
237
|
-
});
|
|
238
|
-
if (changed)
|
|
239
|
-
steps.push({ kind: "replaceNode", path, node: { ...node, children } });
|
|
303
|
+
const next = fn(node, path);
|
|
304
|
+
if (next)
|
|
305
|
+
steps.push({ kind: "replaceNode", path, node: next });
|
|
240
306
|
return;
|
|
241
307
|
}
|
|
242
308
|
node.children.forEach((c, i) => {
|
|
243
309
|
if (isElement(c))
|
|
244
|
-
|
|
310
|
+
walk4(c, path.concat(i));
|
|
245
311
|
});
|
|
246
312
|
};
|
|
247
313
|
doc.children.forEach((c, i) => {
|
|
248
314
|
if (isElement(c))
|
|
249
|
-
|
|
315
|
+
walk4(c, [i]);
|
|
250
316
|
});
|
|
251
317
|
return steps;
|
|
252
318
|
}
|
|
319
|
+
function stripMarks(doc, pred) {
|
|
320
|
+
return mapLeafBlocks(doc, (node) => {
|
|
321
|
+
let changed = false;
|
|
322
|
+
const children = node.children.map((c) => {
|
|
323
|
+
if (!isText(c) || !c.marks?.some(pred))
|
|
324
|
+
return c;
|
|
325
|
+
changed = true;
|
|
326
|
+
const rest = (c.marks ?? []).filter((m) => !pred(m));
|
|
327
|
+
return rest.length ? { ...c, marks: rest } : { text: c.text };
|
|
328
|
+
});
|
|
329
|
+
return changed ? { ...node, children } : null;
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
function dropMarkedLeaves(doc, pred) {
|
|
333
|
+
return mapLeafBlocks(doc, (node) => {
|
|
334
|
+
let changed = false;
|
|
335
|
+
const children = [];
|
|
336
|
+
for (const c of node.children) {
|
|
337
|
+
if (isText(c) && pred(c)) {
|
|
338
|
+
changed = true;
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
children.push(c);
|
|
342
|
+
}
|
|
343
|
+
if (!changed)
|
|
344
|
+
return null;
|
|
345
|
+
return { ...node, children: children.length ? children : [{ text: "" }] };
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// src/tree/comments.ts
|
|
350
|
+
function commentIdsInDoc(doc) {
|
|
351
|
+
return markIdsInDoc(doc, "comment");
|
|
352
|
+
}
|
|
353
|
+
function stripCommentMarks(doc, id) {
|
|
354
|
+
return stripMarks(doc, (m) => m.name === "comment" && String(m.attrs?.id) === id);
|
|
355
|
+
}
|
|
253
356
|
|
|
254
357
|
// src/tree/search.ts
|
|
255
358
|
var DEFAULT_SKIP = ["code"];
|
|
@@ -260,7 +363,7 @@ function findText(doc, query, opts = {}) {
|
|
|
260
363
|
const cs = opts.caseSensitive === true;
|
|
261
364
|
const needle = cs ? query : query.toLowerCase();
|
|
262
365
|
const out = [];
|
|
263
|
-
|
|
366
|
+
walk3(doc, [], skip, (path, text) => {
|
|
264
367
|
const hay = cs ? text : text.toLowerCase();
|
|
265
368
|
let from = 0;
|
|
266
369
|
while (from <= hay.length - needle.length) {
|
|
@@ -299,7 +402,7 @@ function replaceAll(doc, query, replacement, opts = {}) {
|
|
|
299
402
|
const cs = opts.caseSensitive === true;
|
|
300
403
|
const steps = [];
|
|
301
404
|
let count = 0;
|
|
302
|
-
|
|
405
|
+
walk3(doc, [], skip, (path, text, leaf) => {
|
|
303
406
|
const { text: next, n } = replaceInString(text, query, replacement, cs);
|
|
304
407
|
if (n === 0)
|
|
305
408
|
return;
|
|
@@ -345,7 +448,7 @@ function replaceInString(text, query, replacement, caseSensitive) {
|
|
|
345
448
|
}
|
|
346
449
|
return { text: out, n };
|
|
347
450
|
}
|
|
348
|
-
function
|
|
451
|
+
function walk3(node, path, skip, onLeaf) {
|
|
349
452
|
if (isText(node)) {
|
|
350
453
|
onLeaf(path, node.text, node);
|
|
351
454
|
return;
|
|
@@ -355,7 +458,7 @@ function walk2(node, path, skip, onLeaf) {
|
|
|
355
458
|
if (skip.has(node.type))
|
|
356
459
|
return;
|
|
357
460
|
for (let i = 0; i < node.children.length; i++)
|
|
358
|
-
|
|
461
|
+
walk3(node.children[i], path.concat(i), skip, onLeaf);
|
|
359
462
|
}
|
|
360
463
|
|
|
361
464
|
// src/tree/versions.ts
|
|
@@ -415,26 +518,12 @@ function isSuggestMark(m, id) {
|
|
|
415
518
|
return String(m.attrs?.id ?? "") === id;
|
|
416
519
|
}
|
|
417
520
|
function suggestIdsInDoc(doc) {
|
|
418
|
-
|
|
419
|
-
const walk3 = (n) => {
|
|
420
|
-
if (isText(n)) {
|
|
421
|
-
for (const m of n.marks ?? []) {
|
|
422
|
-
if (m.name === "suggest" && m.attrs?.id != null)
|
|
423
|
-
ids.add(String(m.attrs.id));
|
|
424
|
-
}
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
if (isElement(n))
|
|
428
|
-
for (const c of n.children)
|
|
429
|
-
walk3(c);
|
|
430
|
-
};
|
|
431
|
-
walk3(doc);
|
|
432
|
-
return ids;
|
|
521
|
+
return markIdsInDoc(doc, "suggest");
|
|
433
522
|
}
|
|
434
523
|
function listSuggestions(doc) {
|
|
435
524
|
const order = [];
|
|
436
525
|
const map = /* @__PURE__ */ new Map();
|
|
437
|
-
const
|
|
526
|
+
const walk4 = (n) => {
|
|
438
527
|
if (isText(n)) {
|
|
439
528
|
for (const m of n.marks ?? []) {
|
|
440
529
|
if (m.name !== "suggest" || m.attrs?.id == null)
|
|
@@ -459,15 +548,11 @@ function listSuggestions(doc) {
|
|
|
459
548
|
}
|
|
460
549
|
if (isElement(n))
|
|
461
550
|
for (const c of n.children)
|
|
462
|
-
|
|
551
|
+
walk4(c);
|
|
463
552
|
};
|
|
464
|
-
|
|
553
|
+
walk4(doc);
|
|
465
554
|
return order.map((id) => map.get(id));
|
|
466
555
|
}
|
|
467
|
-
function stripLeaf2(leaf, id) {
|
|
468
|
-
const rest = (leaf.marks ?? []).filter((m) => !isSuggestMark(m, id));
|
|
469
|
-
return rest.length ? { ...leaf, marks: rest } : { text: leaf.text };
|
|
470
|
-
}
|
|
471
556
|
function leafHasSuggest(leaf, id) {
|
|
472
557
|
return (leaf.marks ?? []).some((m) => isSuggestMark(m, id));
|
|
473
558
|
}
|
|
@@ -478,64 +563,14 @@ function leafSuggestKind(leaf, id) {
|
|
|
478
563
|
return m.attrs?.kind === "delete" ? "delete" : "insert";
|
|
479
564
|
}
|
|
480
565
|
function stripSuggestMarks(doc, id) {
|
|
481
|
-
|
|
482
|
-
const walk3 = (node, path) => {
|
|
483
|
-
if (node.children.every((c) => isText(c) || isInlineAtom(c))) {
|
|
484
|
-
let changed = false;
|
|
485
|
-
const children = node.children.map((c) => {
|
|
486
|
-
if (!isText(c) || !leafHasSuggest(c, id))
|
|
487
|
-
return c;
|
|
488
|
-
changed = true;
|
|
489
|
-
return stripLeaf2(c, id);
|
|
490
|
-
});
|
|
491
|
-
if (changed)
|
|
492
|
-
steps.push({ kind: "replaceNode", path, node: { ...node, children } });
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
node.children.forEach((c, i) => {
|
|
496
|
-
if (isElement(c))
|
|
497
|
-
walk3(c, path.concat(i));
|
|
498
|
-
});
|
|
499
|
-
};
|
|
500
|
-
doc.children.forEach((c, i) => {
|
|
501
|
-
if (isElement(c))
|
|
502
|
-
walk3(c, [i]);
|
|
503
|
-
});
|
|
504
|
-
return steps;
|
|
566
|
+
return stripMarks(doc, (m) => isSuggestMark(m, id));
|
|
505
567
|
}
|
|
506
568
|
function dropSuggestText(doc, id) {
|
|
507
|
-
|
|
508
|
-
const walk3 = (node, path) => {
|
|
509
|
-
if (node.children.every((c) => isText(c) || isInlineAtom(c))) {
|
|
510
|
-
let changed = false;
|
|
511
|
-
const children = [];
|
|
512
|
-
for (const c of node.children) {
|
|
513
|
-
if (isText(c) && leafHasSuggest(c, id)) {
|
|
514
|
-
changed = true;
|
|
515
|
-
continue;
|
|
516
|
-
}
|
|
517
|
-
children.push(c);
|
|
518
|
-
}
|
|
519
|
-
if (changed) {
|
|
520
|
-
const next = children.length ? children : [{ text: "" }];
|
|
521
|
-
steps.push({ kind: "replaceNode", path, node: { ...node, children: next } });
|
|
522
|
-
}
|
|
523
|
-
return;
|
|
524
|
-
}
|
|
525
|
-
node.children.forEach((c, i) => {
|
|
526
|
-
if (isElement(c))
|
|
527
|
-
walk3(c, path.concat(i));
|
|
528
|
-
});
|
|
529
|
-
};
|
|
530
|
-
doc.children.forEach((c, i) => {
|
|
531
|
-
if (isElement(c))
|
|
532
|
-
walk3(c, [i]);
|
|
533
|
-
});
|
|
534
|
-
return steps;
|
|
569
|
+
return dropMarkedLeaves(doc, (leaf) => leafHasSuggest(leaf, id));
|
|
535
570
|
}
|
|
536
571
|
function kindOfId(doc, id) {
|
|
537
572
|
let kind = "insert";
|
|
538
|
-
const
|
|
573
|
+
const walk4 = (n) => {
|
|
539
574
|
if (isText(n)) {
|
|
540
575
|
const k = leafSuggestKind(n, id);
|
|
541
576
|
if (k) {
|
|
@@ -546,13 +581,13 @@ function kindOfId(doc, id) {
|
|
|
546
581
|
}
|
|
547
582
|
if (isElement(n)) {
|
|
548
583
|
for (const c of n.children) {
|
|
549
|
-
if (
|
|
584
|
+
if (walk4(c))
|
|
550
585
|
return true;
|
|
551
586
|
}
|
|
552
587
|
}
|
|
553
588
|
return false;
|
|
554
589
|
};
|
|
555
|
-
|
|
590
|
+
walk4(doc);
|
|
556
591
|
return kind;
|
|
557
592
|
}
|
|
558
593
|
function acceptSuggestion(doc, id) {
|
|
@@ -581,15 +616,15 @@ function totalChars(children) {
|
|
|
581
616
|
}
|
|
582
617
|
function leafBlocksBetween(doc, fromBlock, toBlock) {
|
|
583
618
|
const all = [];
|
|
584
|
-
const
|
|
619
|
+
const walk4 = (node, path) => {
|
|
585
620
|
if (!isElement(node))
|
|
586
621
|
return;
|
|
587
622
|
if (node.children.every((c) => isText(c) || isInlineAtom(c)))
|
|
588
623
|
all.push({ path, node });
|
|
589
624
|
else
|
|
590
|
-
node.children.forEach((c, i) =>
|
|
625
|
+
node.children.forEach((c, i) => walk4(c, path.concat(i)));
|
|
591
626
|
};
|
|
592
|
-
doc.children.forEach((c, i) =>
|
|
627
|
+
doc.children.forEach((c, i) => walk4(c, [i]));
|
|
593
628
|
const fi = all.findIndex((b) => cmpPath(b.path, fromBlock) === 0);
|
|
594
629
|
const ti = all.findIndex((b) => cmpPath(b.path, toBlock) === 0);
|
|
595
630
|
return fi < 0 || ti < 0 ? [] : all.slice(fi, ti + 1);
|
|
@@ -725,6 +760,62 @@ function markSuggestRange(doc, sel, kind, id, author) {
|
|
|
725
760
|
return steps;
|
|
726
761
|
}
|
|
727
762
|
|
|
763
|
+
// src/tree/footnote.ts
|
|
764
|
+
function footnoteIndex(doc) {
|
|
765
|
+
const order = [];
|
|
766
|
+
const defs = /* @__PURE__ */ new Map();
|
|
767
|
+
const refs = /* @__PURE__ */ new Map();
|
|
768
|
+
const walk4 = (n) => {
|
|
769
|
+
if (isText(n))
|
|
770
|
+
return;
|
|
771
|
+
if (n.type === "footnote_ref") {
|
|
772
|
+
const k = footnoteKey(String(n.attrs?.label ?? ""));
|
|
773
|
+
if (!refs.has(k))
|
|
774
|
+
order.push(k);
|
|
775
|
+
refs.set(k, (refs.get(k) ?? 0) + 1);
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
if (isFootnoteDef(n)) {
|
|
779
|
+
const k = footnoteKey(String(n.attrs?.footnote ?? ""));
|
|
780
|
+
if (!defs.has(k))
|
|
781
|
+
defs.set(k, n);
|
|
782
|
+
}
|
|
783
|
+
for (const c of n.children)
|
|
784
|
+
walk4(c);
|
|
785
|
+
};
|
|
786
|
+
walk4(doc);
|
|
787
|
+
return { order, defs, refs };
|
|
788
|
+
}
|
|
789
|
+
function footnoteText(def) {
|
|
790
|
+
const lines = [];
|
|
791
|
+
const walk4 = (n, acc) => {
|
|
792
|
+
if (isText(n)) {
|
|
793
|
+
acc.push(n.text);
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
if (n.type === "footnote_ref") {
|
|
797
|
+
acc.push(`[${String(n.attrs?.label ?? "")}]`);
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
if (isElement(n) && n.children.length && n.children.every((c) => isText(c) || isElement(c) && c.children.length === 0)) {
|
|
801
|
+
const line = [];
|
|
802
|
+
for (const c of n.children)
|
|
803
|
+
walk4(c, line);
|
|
804
|
+
lines.push(line.join(""));
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
for (const c of n.children)
|
|
808
|
+
walk4(c, acc);
|
|
809
|
+
};
|
|
810
|
+
for (const c of def.children)
|
|
811
|
+
walk4(c, lines);
|
|
812
|
+
return lines.join("\n").trim();
|
|
813
|
+
}
|
|
814
|
+
function hasFootnotes(doc) {
|
|
815
|
+
const walk4 = (n) => !isText(n) && (n.type === "footnote_ref" || isFootnoteDef(n) || n.children.some(walk4));
|
|
816
|
+
return walk4(doc);
|
|
817
|
+
}
|
|
818
|
+
|
|
728
819
|
export {
|
|
729
820
|
init,
|
|
730
821
|
commit,
|
|
@@ -734,7 +825,12 @@ export {
|
|
|
734
825
|
redo,
|
|
735
826
|
invariants,
|
|
736
827
|
firstViolation,
|
|
828
|
+
wordCount,
|
|
737
829
|
outline,
|
|
830
|
+
markIdsInDoc,
|
|
831
|
+
mapLeafBlocks,
|
|
832
|
+
stripMarks,
|
|
833
|
+
dropMarkedLeaves,
|
|
738
834
|
commentIdsInDoc,
|
|
739
835
|
stripCommentMarks,
|
|
740
836
|
findText,
|
|
@@ -755,5 +851,8 @@ export {
|
|
|
755
851
|
rejectSuggestion,
|
|
756
852
|
rangeForDelete,
|
|
757
853
|
rangeIsSuggestInsert,
|
|
758
|
-
markSuggestRange
|
|
854
|
+
markSuggestRange,
|
|
855
|
+
footnoteIndex,
|
|
856
|
+
footnoteText,
|
|
857
|
+
hasFootnotes
|
|
759
858
|
};
|