markloom 0.3.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 +125 -0
- package/dist/ai/index.cjs +19 -0
- package/dist/ai/index.d.cts +10 -0
- package/dist/ai/index.d.ts +10 -0
- package/dist/ai/index.js +19 -0
- package/dist/ai/theme.css +304 -0
- package/dist/chunk-2X6AF7XH.cjs +9030 -0
- package/dist/chunk-7Q6AXLF2.cjs +1076 -0
- package/dist/chunk-GUPMZI6Q.js +1076 -0
- package/dist/chunk-HA6XHJUD.cjs +218 -0
- package/dist/chunk-ITVAR2UM.js +218 -0
- package/dist/chunk-J3QWW6CN.js +2305 -0
- package/dist/chunk-UCNEQGMY.js +9030 -0
- package/dist/chunk-VVFIQLVR.cjs +2305 -0
- package/dist/comments-USjT1wYN.d.cts +105 -0
- package/dist/comments-USjT1wYN.d.ts +105 -0
- package/dist/controller-Dm4uLD3I.d.ts +507 -0
- package/dist/controller-cE9iEYp3.d.cts +507 -0
- package/dist/index.cjs +424 -0
- package/dist/index.d.cts +184 -0
- package/dist/index.d.ts +184 -0
- package/dist/index.js +424 -0
- package/dist/react/index.cjs +45 -0
- package/dist/react/index.d.cts +22 -0
- package/dist/react/index.d.ts +22 -0
- package/dist/react/index.js +45 -0
- package/dist/view/index.cjs +368 -0
- package/dist/view/index.d.cts +155 -0
- package/dist/view/index.d.ts +155 -0
- package/dist/view/index.js +368 -0
- package/dist/view/theme.css +2627 -0
- package/package.json +89 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkVVFIQLVRcjs = require('./chunk-VVFIQLVR.cjs');
|
|
10
|
+
|
|
11
|
+
// src/tree/history.ts
|
|
12
|
+
function init(doc, validate) {
|
|
13
|
+
return { doc, past: [], future: [], validate };
|
|
14
|
+
}
|
|
15
|
+
function gate(h, next) {
|
|
16
|
+
const v = _optionalChain([h, 'access', _ => _.validate, 'optionalCall', _2 => _2(next)]);
|
|
17
|
+
if (v)
|
|
18
|
+
throw new Error(`[invariant] \u63D0\u4EA4\u4EA7\u751F\u975E\u6CD5 doc: ${v}`);
|
|
19
|
+
}
|
|
20
|
+
function commit(h, steps) {
|
|
21
|
+
const inverse = _chunkVVFIQLVRcjs.invertAll.call(void 0, h.doc, steps);
|
|
22
|
+
const next = _chunkVVFIQLVRcjs.applyAll.call(void 0, h.doc, steps);
|
|
23
|
+
gate(h, next);
|
|
24
|
+
return { ...h, doc: next, past: h.past.concat({ steps, inverse }), future: [] };
|
|
25
|
+
}
|
|
26
|
+
function amend(h, more) {
|
|
27
|
+
if (more.length === 0)
|
|
28
|
+
return h;
|
|
29
|
+
if (h.past.length === 0)
|
|
30
|
+
return commit(h, more);
|
|
31
|
+
const last = h.past[h.past.length - 1];
|
|
32
|
+
const before = _chunkVVFIQLVRcjs.applyAll.call(void 0, h.doc, last.inverse);
|
|
33
|
+
const steps = last.steps.concat(more);
|
|
34
|
+
const inverse = _chunkVVFIQLVRcjs.invertAll.call(void 0, before, steps);
|
|
35
|
+
const next = _chunkVVFIQLVRcjs.applyAll.call(void 0, before, steps);
|
|
36
|
+
gate(h, next);
|
|
37
|
+
return {
|
|
38
|
+
...h,
|
|
39
|
+
doc: next,
|
|
40
|
+
past: h.past.slice(0, -1).concat({ steps, inverse }),
|
|
41
|
+
future: []
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function undo(h) {
|
|
45
|
+
const last = h.past[h.past.length - 1];
|
|
46
|
+
if (!last)
|
|
47
|
+
return h;
|
|
48
|
+
const next = _chunkVVFIQLVRcjs.applyAll.call(void 0, h.doc, last.inverse);
|
|
49
|
+
gate(h, next);
|
|
50
|
+
return { ...h, doc: next, past: h.past.slice(0, -1), future: [last, ...h.future] };
|
|
51
|
+
}
|
|
52
|
+
function redo(h) {
|
|
53
|
+
const next = h.future[0];
|
|
54
|
+
if (!next)
|
|
55
|
+
return h;
|
|
56
|
+
const doc = _chunkVVFIQLVRcjs.applyAll.call(void 0, h.doc, next.steps);
|
|
57
|
+
gate(h, doc);
|
|
58
|
+
return { ...h, doc, past: h.past.concat(next), future: h.future.slice(1) };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/tree/invariants.ts
|
|
62
|
+
function invariants(schema, doc) {
|
|
63
|
+
const out = [];
|
|
64
|
+
out.push(..._chunkVVFIQLVRcjs.validateAll.call(void 0, schema, doc));
|
|
65
|
+
const ids = /* @__PURE__ */ new Map();
|
|
66
|
+
walk(doc, [], schema, out, ids);
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
function walk(node, path, schema, out, ids) {
|
|
70
|
+
if (_chunkVVFIQLVRcjs.isText.call(void 0, node)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (node.id !== void 0) {
|
|
74
|
+
ids.set(node.id, (_nullishCoalesce(ids.get(node.id), () => ( 0))) + 1);
|
|
75
|
+
if (ids.get(node.id) === 2) {
|
|
76
|
+
out.push({ path, reason: `\u91CD\u590D id "${node.id}"` });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const spec = schema.nodes[node.type];
|
|
80
|
+
if (_optionalChain([spec, 'optionalAccess', _3 => _3.atom])) {
|
|
81
|
+
if (node.type === "image") {
|
|
82
|
+
if (!_optionalChain([node, 'access', _4 => _4.attrs, 'optionalAccess', _5 => _5.url]))
|
|
83
|
+
out.push({ path, reason: `[image] \u7F3A url` });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (node.type === "mention") {
|
|
87
|
+
if (!_optionalChain([node, 'access', _6 => _6.attrs, 'optionalAccess', _7 => _7.id]))
|
|
88
|
+
out.push({ path, reason: `[mention] \u7F3A id` });
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (node.type === "math") {
|
|
92
|
+
if (typeof _optionalChain([node, 'access', _8 => _8.attrs, 'optionalAccess', _9 => _9.latex]) !== "string")
|
|
93
|
+
out.push({ path, reason: `[math] \u7F3A latex` });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (node.type === "embed") {
|
|
97
|
+
if (!_optionalChain([node, 'access', _10 => _10.attrs, 'optionalAccess', _11 => _11.kind]))
|
|
98
|
+
out.push({ path, reason: `[embed] \u7F3A kind` });
|
|
99
|
+
if (!_optionalChain([node, 'access', _12 => _12.attrs, 'optionalAccess', _13 => _13.src]))
|
|
100
|
+
out.push({ path, reason: `[embed] \u7F3A src` });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
for (const reason of _chunkVVFIQLVRcjs.checkTable.call(void 0, node)) {
|
|
104
|
+
out.push({ path, reason: `[table] ${reason}` });
|
|
105
|
+
}
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (_optionalChain([spec, 'optionalAccess', _14 => _14.marks])) {
|
|
109
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
110
|
+
const child = node.children[i];
|
|
111
|
+
if (_chunkVVFIQLVRcjs.isText.call(void 0, child) && child.marks) {
|
|
112
|
+
for (const m of child.marks) {
|
|
113
|
+
if (!spec.marks.includes(m.name)) {
|
|
114
|
+
out.push({ path: path.concat(i), reason: `${node.type} \u4E0D\u5141\u8BB8 mark "${m.name}"` });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
121
|
+
walk(node.children[i], path.concat(i), schema, out, ids);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function firstViolation(vs) {
|
|
125
|
+
if (vs.length === 0) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
const v = vs[0];
|
|
129
|
+
return `${v.path.join(",")}: ${v.reason}`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/tree/toc.ts
|
|
133
|
+
function headingText(node) {
|
|
134
|
+
let out = "";
|
|
135
|
+
for (const c of node.children) {
|
|
136
|
+
if (_chunkVVFIQLVRcjs.isText.call(void 0, c))
|
|
137
|
+
out += c.text;
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
function outline(doc) {
|
|
142
|
+
const out = [];
|
|
143
|
+
const walk2 = (node, path) => {
|
|
144
|
+
if (_chunkVVFIQLVRcjs.isText.call(void 0, node))
|
|
145
|
+
return;
|
|
146
|
+
if (node.type === "heading") {
|
|
147
|
+
const level = Math.min(Math.max(Number(_nullishCoalesce(_optionalChain([node, 'access', _15 => _15.attrs, 'optionalAccess', _16 => _16.depth]), () => ( 1))), 1), 6);
|
|
148
|
+
out.push({ level, text: headingText(node), path, id: node.id });
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
for (let i = 0; i < node.children.length; i++)
|
|
152
|
+
walk2(node.children[i], path.concat(i));
|
|
153
|
+
};
|
|
154
|
+
walk2(doc, []);
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/tree/comments.ts
|
|
159
|
+
function commentIdsInDoc(doc) {
|
|
160
|
+
const ids = /* @__PURE__ */ new Set();
|
|
161
|
+
const walk2 = (n) => {
|
|
162
|
+
if (_chunkVVFIQLVRcjs.isText.call(void 0, n)) {
|
|
163
|
+
for (const m of _nullishCoalesce(n.marks, () => ( []))) {
|
|
164
|
+
if (m.name === "comment" && _optionalChain([m, 'access', _17 => _17.attrs, 'optionalAccess', _18 => _18.id]) != null)
|
|
165
|
+
ids.add(String(m.attrs.id));
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (_chunkVVFIQLVRcjs.isElement.call(void 0, n))
|
|
170
|
+
for (const c of n.children)
|
|
171
|
+
walk2(c);
|
|
172
|
+
};
|
|
173
|
+
walk2(doc);
|
|
174
|
+
return ids;
|
|
175
|
+
}
|
|
176
|
+
function stripLeaf(leaf, id) {
|
|
177
|
+
const rest = (_nullishCoalesce(leaf.marks, () => ( []))).filter((m) => !(m.name === "comment" && String(_optionalChain([m, 'access', _19 => _19.attrs, 'optionalAccess', _20 => _20.id])) === id));
|
|
178
|
+
return rest.length ? { ...leaf, marks: rest } : { text: leaf.text };
|
|
179
|
+
}
|
|
180
|
+
function stripCommentMarks(doc, id) {
|
|
181
|
+
const steps = [];
|
|
182
|
+
const walk2 = (node, path) => {
|
|
183
|
+
if (node.children.every((c) => _chunkVVFIQLVRcjs.isText.call(void 0, c) || _chunkVVFIQLVRcjs.isInlineAtom.call(void 0, c))) {
|
|
184
|
+
let changed = false;
|
|
185
|
+
const children = node.children.map((c) => {
|
|
186
|
+
if (!_chunkVVFIQLVRcjs.isText.call(void 0, c) || !_optionalChain([c, 'access', _21 => _21.marks, 'optionalAccess', _22 => _22.some, 'call', _23 => _23((m) => m.name === "comment" && String(_optionalChain([m, 'access', _24 => _24.attrs, 'optionalAccess', _25 => _25.id])) === id)]))
|
|
187
|
+
return c;
|
|
188
|
+
changed = true;
|
|
189
|
+
return stripLeaf(c, id);
|
|
190
|
+
});
|
|
191
|
+
if (changed)
|
|
192
|
+
steps.push({ kind: "replaceNode", path, node: { ...node, children } });
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
node.children.forEach((c, i) => {
|
|
196
|
+
if (_chunkVVFIQLVRcjs.isElement.call(void 0, c))
|
|
197
|
+
walk2(c, path.concat(i));
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
doc.children.forEach((c, i) => {
|
|
201
|
+
if (_chunkVVFIQLVRcjs.isElement.call(void 0, c))
|
|
202
|
+
walk2(c, [i]);
|
|
203
|
+
});
|
|
204
|
+
return steps;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
exports.init = init; exports.commit = commit; exports.amend = amend; exports.undo = undo; exports.redo = redo; exports.invariants = invariants; exports.firstViolation = firstViolation; exports.outline = outline; exports.commentIdsInDoc = commentIdsInDoc; exports.stripCommentMarks = stripCommentMarks;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyAll,
|
|
3
|
+
checkTable,
|
|
4
|
+
invertAll,
|
|
5
|
+
isElement,
|
|
6
|
+
isInlineAtom,
|
|
7
|
+
isText,
|
|
8
|
+
validateAll
|
|
9
|
+
} from "./chunk-J3QWW6CN.js";
|
|
10
|
+
|
|
11
|
+
// src/tree/history.ts
|
|
12
|
+
function init(doc, validate) {
|
|
13
|
+
return { doc, past: [], future: [], validate };
|
|
14
|
+
}
|
|
15
|
+
function gate(h, next) {
|
|
16
|
+
const v = h.validate?.(next);
|
|
17
|
+
if (v)
|
|
18
|
+
throw new Error(`[invariant] \u63D0\u4EA4\u4EA7\u751F\u975E\u6CD5 doc: ${v}`);
|
|
19
|
+
}
|
|
20
|
+
function commit(h, steps) {
|
|
21
|
+
const inverse = invertAll(h.doc, steps);
|
|
22
|
+
const next = applyAll(h.doc, steps);
|
|
23
|
+
gate(h, next);
|
|
24
|
+
return { ...h, doc: next, past: h.past.concat({ steps, inverse }), future: [] };
|
|
25
|
+
}
|
|
26
|
+
function amend(h, more) {
|
|
27
|
+
if (more.length === 0)
|
|
28
|
+
return h;
|
|
29
|
+
if (h.past.length === 0)
|
|
30
|
+
return commit(h, more);
|
|
31
|
+
const last = h.past[h.past.length - 1];
|
|
32
|
+
const before = applyAll(h.doc, last.inverse);
|
|
33
|
+
const steps = last.steps.concat(more);
|
|
34
|
+
const inverse = invertAll(before, steps);
|
|
35
|
+
const next = applyAll(before, steps);
|
|
36
|
+
gate(h, next);
|
|
37
|
+
return {
|
|
38
|
+
...h,
|
|
39
|
+
doc: next,
|
|
40
|
+
past: h.past.slice(0, -1).concat({ steps, inverse }),
|
|
41
|
+
future: []
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function undo(h) {
|
|
45
|
+
const last = h.past[h.past.length - 1];
|
|
46
|
+
if (!last)
|
|
47
|
+
return h;
|
|
48
|
+
const next = applyAll(h.doc, last.inverse);
|
|
49
|
+
gate(h, next);
|
|
50
|
+
return { ...h, doc: next, past: h.past.slice(0, -1), future: [last, ...h.future] };
|
|
51
|
+
}
|
|
52
|
+
function redo(h) {
|
|
53
|
+
const next = h.future[0];
|
|
54
|
+
if (!next)
|
|
55
|
+
return h;
|
|
56
|
+
const doc = applyAll(h.doc, next.steps);
|
|
57
|
+
gate(h, doc);
|
|
58
|
+
return { ...h, doc, past: h.past.concat(next), future: h.future.slice(1) };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/tree/invariants.ts
|
|
62
|
+
function invariants(schema, doc) {
|
|
63
|
+
const out = [];
|
|
64
|
+
out.push(...validateAll(schema, doc));
|
|
65
|
+
const ids = /* @__PURE__ */ new Map();
|
|
66
|
+
walk(doc, [], schema, out, ids);
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
function walk(node, path, schema, out, ids) {
|
|
70
|
+
if (isText(node)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (node.id !== void 0) {
|
|
74
|
+
ids.set(node.id, (ids.get(node.id) ?? 0) + 1);
|
|
75
|
+
if (ids.get(node.id) === 2) {
|
|
76
|
+
out.push({ path, reason: `\u91CD\u590D id "${node.id}"` });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const spec = schema.nodes[node.type];
|
|
80
|
+
if (spec?.atom) {
|
|
81
|
+
if (node.type === "image") {
|
|
82
|
+
if (!node.attrs?.url)
|
|
83
|
+
out.push({ path, reason: `[image] \u7F3A url` });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (node.type === "mention") {
|
|
87
|
+
if (!node.attrs?.id)
|
|
88
|
+
out.push({ path, reason: `[mention] \u7F3A id` });
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (node.type === "math") {
|
|
92
|
+
if (typeof node.attrs?.latex !== "string")
|
|
93
|
+
out.push({ path, reason: `[math] \u7F3A latex` });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (node.type === "embed") {
|
|
97
|
+
if (!node.attrs?.kind)
|
|
98
|
+
out.push({ path, reason: `[embed] \u7F3A kind` });
|
|
99
|
+
if (!node.attrs?.src)
|
|
100
|
+
out.push({ path, reason: `[embed] \u7F3A src` });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
for (const reason of checkTable(node)) {
|
|
104
|
+
out.push({ path, reason: `[table] ${reason}` });
|
|
105
|
+
}
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (spec?.marks) {
|
|
109
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
110
|
+
const child = node.children[i];
|
|
111
|
+
if (isText(child) && child.marks) {
|
|
112
|
+
for (const m of child.marks) {
|
|
113
|
+
if (!spec.marks.includes(m.name)) {
|
|
114
|
+
out.push({ path: path.concat(i), reason: `${node.type} \u4E0D\u5141\u8BB8 mark "${m.name}"` });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
121
|
+
walk(node.children[i], path.concat(i), schema, out, ids);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function firstViolation(vs) {
|
|
125
|
+
if (vs.length === 0) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
const v = vs[0];
|
|
129
|
+
return `${v.path.join(",")}: ${v.reason}`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/tree/toc.ts
|
|
133
|
+
function headingText(node) {
|
|
134
|
+
let out = "";
|
|
135
|
+
for (const c of node.children) {
|
|
136
|
+
if (isText(c))
|
|
137
|
+
out += c.text;
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
function outline(doc) {
|
|
142
|
+
const out = [];
|
|
143
|
+
const walk2 = (node, path) => {
|
|
144
|
+
if (isText(node))
|
|
145
|
+
return;
|
|
146
|
+
if (node.type === "heading") {
|
|
147
|
+
const level = Math.min(Math.max(Number(node.attrs?.depth ?? 1), 1), 6);
|
|
148
|
+
out.push({ level, text: headingText(node), path, id: node.id });
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
for (let i = 0; i < node.children.length; i++)
|
|
152
|
+
walk2(node.children[i], path.concat(i));
|
|
153
|
+
};
|
|
154
|
+
walk2(doc, []);
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/tree/comments.ts
|
|
159
|
+
function commentIdsInDoc(doc) {
|
|
160
|
+
const ids = /* @__PURE__ */ new Set();
|
|
161
|
+
const walk2 = (n) => {
|
|
162
|
+
if (isText(n)) {
|
|
163
|
+
for (const m of n.marks ?? []) {
|
|
164
|
+
if (m.name === "comment" && m.attrs?.id != null)
|
|
165
|
+
ids.add(String(m.attrs.id));
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (isElement(n))
|
|
170
|
+
for (const c of n.children)
|
|
171
|
+
walk2(c);
|
|
172
|
+
};
|
|
173
|
+
walk2(doc);
|
|
174
|
+
return ids;
|
|
175
|
+
}
|
|
176
|
+
function stripLeaf(leaf, id) {
|
|
177
|
+
const rest = (leaf.marks ?? []).filter((m) => !(m.name === "comment" && String(m.attrs?.id) === id));
|
|
178
|
+
return rest.length ? { ...leaf, marks: rest } : { text: leaf.text };
|
|
179
|
+
}
|
|
180
|
+
function stripCommentMarks(doc, id) {
|
|
181
|
+
const steps = [];
|
|
182
|
+
const walk2 = (node, path) => {
|
|
183
|
+
if (node.children.every((c) => isText(c) || isInlineAtom(c))) {
|
|
184
|
+
let changed = false;
|
|
185
|
+
const children = node.children.map((c) => {
|
|
186
|
+
if (!isText(c) || !c.marks?.some((m) => m.name === "comment" && String(m.attrs?.id) === id))
|
|
187
|
+
return c;
|
|
188
|
+
changed = true;
|
|
189
|
+
return stripLeaf(c, id);
|
|
190
|
+
});
|
|
191
|
+
if (changed)
|
|
192
|
+
steps.push({ kind: "replaceNode", path, node: { ...node, children } });
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
node.children.forEach((c, i) => {
|
|
196
|
+
if (isElement(c))
|
|
197
|
+
walk2(c, path.concat(i));
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
doc.children.forEach((c, i) => {
|
|
201
|
+
if (isElement(c))
|
|
202
|
+
walk2(c, [i]);
|
|
203
|
+
});
|
|
204
|
+
return steps;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export {
|
|
208
|
+
init,
|
|
209
|
+
commit,
|
|
210
|
+
amend,
|
|
211
|
+
undo,
|
|
212
|
+
redo,
|
|
213
|
+
invariants,
|
|
214
|
+
firstViolation,
|
|
215
|
+
outline,
|
|
216
|
+
commentIdsInDoc,
|
|
217
|
+
stripCommentMarks
|
|
218
|
+
};
|