@w100n/documents 0.18.1 → 0.19.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/dist/{SheetView-F4CBWEOS.js → SheetView-PUSRW7W2.js} +3 -3
- package/dist/{TextEditor-ZY4B7YIF.js → TextEditor-Z4KSBLBV.js} +3 -3
- package/dist/{chunk-2G34AIPU.js → chunk-JSJEB2CO.js} +192 -60
- package/dist/chunk-JSJEB2CO.js.map +1 -0
- package/dist/{chunk-TSB2QS56.js → chunk-ZQYSBWLK.js} +2 -2
- package/dist/collab.cjs +326 -187
- package/dist/collab.cjs.map +1 -1
- package/dist/collab.d.cts +27 -1
- package/dist/collab.d.ts +27 -1
- package/dist/collab.js +9 -1
- package/dist/index.cjs +364 -389
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +123 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +366 -395
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-2G34AIPU.js.map +0 -1
- /package/dist/{SheetView-F4CBWEOS.js.map → SheetView-PUSRW7W2.js.map} +0 -0
- /package/dist/{TextEditor-ZY4B7YIF.js.map → TextEditor-Z4KSBLBV.js.map} +0 -0
- /package/dist/{chunk-TSB2QS56.js.map → chunk-ZQYSBWLK.js.map} +0 -0
package/dist/collab.cjs
CHANGED
|
@@ -32,10 +32,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
var collab_exports = {};
|
|
33
33
|
__export(collab_exports, {
|
|
34
34
|
Refusal: () => Refusal,
|
|
35
|
+
appendRows: () => appendRows,
|
|
35
36
|
applyCells: () => applyCells,
|
|
37
|
+
applySteps: () => applySteps,
|
|
36
38
|
applyText: () => applyText,
|
|
39
|
+
clashes: () => clashes,
|
|
40
|
+
compute: () => compute,
|
|
37
41
|
edits: () => edits,
|
|
38
|
-
filled: () =>
|
|
42
|
+
filled: () => filled2,
|
|
39
43
|
follow: () => follow,
|
|
40
44
|
ours: () => ours,
|
|
41
45
|
parse: () => parse3,
|
|
@@ -47,10 +51,10 @@ module.exports = __toCommonJS(collab_exports);
|
|
|
47
51
|
var import_core3 = require("@tiptap/core");
|
|
48
52
|
var import_transform2 = require("@tiptap/pm/transform");
|
|
49
53
|
var import_y_tiptap2 = require("@tiptap/y-tiptap");
|
|
50
|
-
var
|
|
54
|
+
var Y3 = __toESM(require("yjs"), 1);
|
|
51
55
|
|
|
52
56
|
// package.json
|
|
53
|
-
var version = "0.
|
|
57
|
+
var version = "0.19.0";
|
|
54
58
|
|
|
55
59
|
// src/docx/xml.ts
|
|
56
60
|
function parse(s) {
|
|
@@ -187,35 +191,35 @@ function unzip(buf) {
|
|
|
187
191
|
while (eocd >= 0 && view.getUint32(eocd, true) !== 101010256) eocd--;
|
|
188
192
|
if (eocd < 0) throw new Error("Not a DOCX file");
|
|
189
193
|
const count = view.getUint16(eocd + 10, true);
|
|
190
|
-
let
|
|
191
|
-
if (count === 65535 ||
|
|
194
|
+
let at3 = view.getUint32(eocd + 16, true);
|
|
195
|
+
if (count === 65535 || at3 === 4294967295) throw new Error("ZIP64 DOCX files are not supported");
|
|
192
196
|
const names = new TextDecoder();
|
|
193
197
|
const out = [];
|
|
194
198
|
for (let n = 0; n < count; n++) {
|
|
195
|
-
if (view.getUint32(
|
|
196
|
-
const length = view.getUint16(
|
|
197
|
-
const extra = view.getUint16(
|
|
198
|
-
const note = view.getUint16(
|
|
199
|
-
const local = view.getUint32(
|
|
200
|
-
const csize = view.getUint32(
|
|
201
|
-
const path = buf.subarray(
|
|
199
|
+
if (view.getUint32(at3, true) !== 33639248) throw new Error("Broken DOCX file");
|
|
200
|
+
const length = view.getUint16(at3 + 28, true);
|
|
201
|
+
const extra = view.getUint16(at3 + 30, true);
|
|
202
|
+
const note = view.getUint16(at3 + 32, true);
|
|
203
|
+
const local = view.getUint32(at3 + 42, true);
|
|
204
|
+
const csize = view.getUint32(at3 + 20, true);
|
|
205
|
+
const path = buf.subarray(at3 + 46, at3 + 46 + length);
|
|
202
206
|
const begin = local + 30 + view.getUint16(local + 26, true) + view.getUint16(local + 28, true);
|
|
203
207
|
out.push({
|
|
204
208
|
name: names.decode(path),
|
|
205
209
|
path,
|
|
206
|
-
made: view.getUint16(
|
|
207
|
-
version: view.getUint16(
|
|
208
|
-
flags: view.getUint16(
|
|
209
|
-
method: view.getUint16(
|
|
210
|
-
time: view.getUint16(
|
|
211
|
-
date: view.getUint16(
|
|
212
|
-
crc: view.getUint32(
|
|
213
|
-
size: view.getUint32(
|
|
214
|
-
inner: view.getUint16(
|
|
215
|
-
outer: view.getUint32(
|
|
210
|
+
made: view.getUint16(at3 + 4, true),
|
|
211
|
+
version: view.getUint16(at3 + 6, true),
|
|
212
|
+
flags: view.getUint16(at3 + 8, true),
|
|
213
|
+
method: view.getUint16(at3 + 10, true),
|
|
214
|
+
time: view.getUint16(at3 + 12, true),
|
|
215
|
+
date: view.getUint16(at3 + 14, true),
|
|
216
|
+
crc: view.getUint32(at3 + 16, true),
|
|
217
|
+
size: view.getUint32(at3 + 24, true),
|
|
218
|
+
inner: view.getUint16(at3 + 36, true),
|
|
219
|
+
outer: view.getUint32(at3 + 38, true),
|
|
216
220
|
raw: buf.subarray(begin, begin + csize)
|
|
217
221
|
});
|
|
218
|
-
|
|
222
|
+
at3 += 46 + length + extra + note;
|
|
219
223
|
}
|
|
220
224
|
return out;
|
|
221
225
|
}
|
|
@@ -248,49 +252,49 @@ function zip(entries2) {
|
|
|
248
252
|
const buf = new Uint8Array(total);
|
|
249
253
|
const view = new DataView(buf.buffer);
|
|
250
254
|
const offsets = [];
|
|
251
|
-
let
|
|
255
|
+
let at3 = 0;
|
|
252
256
|
for (const e of entries2) {
|
|
253
|
-
offsets.push(
|
|
254
|
-
view.setUint32(
|
|
255
|
-
view.setUint16(
|
|
256
|
-
view.setUint16(
|
|
257
|
-
view.setUint16(
|
|
258
|
-
view.setUint16(
|
|
259
|
-
view.setUint16(
|
|
260
|
-
view.setUint32(
|
|
261
|
-
view.setUint32(
|
|
262
|
-
view.setUint32(
|
|
263
|
-
view.setUint16(
|
|
264
|
-
view.setUint16(
|
|
265
|
-
buf.set(e.path,
|
|
266
|
-
buf.set(e.raw,
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
const start =
|
|
257
|
+
offsets.push(at3);
|
|
258
|
+
view.setUint32(at3, 67324752, true);
|
|
259
|
+
view.setUint16(at3 + 4, e.version, true);
|
|
260
|
+
view.setUint16(at3 + 6, e.flags & ~8, true);
|
|
261
|
+
view.setUint16(at3 + 8, e.method, true);
|
|
262
|
+
view.setUint16(at3 + 10, e.time, true);
|
|
263
|
+
view.setUint16(at3 + 12, e.date, true);
|
|
264
|
+
view.setUint32(at3 + 14, e.crc, true);
|
|
265
|
+
view.setUint32(at3 + 18, e.raw.length, true);
|
|
266
|
+
view.setUint32(at3 + 22, e.size, true);
|
|
267
|
+
view.setUint16(at3 + 26, e.path.length, true);
|
|
268
|
+
view.setUint16(at3 + 28, 0, true);
|
|
269
|
+
buf.set(e.path, at3 + 30);
|
|
270
|
+
buf.set(e.raw, at3 + 30 + e.path.length);
|
|
271
|
+
at3 += 30 + e.path.length + e.raw.length;
|
|
272
|
+
}
|
|
273
|
+
const start = at3;
|
|
270
274
|
entries2.forEach((e, n) => {
|
|
271
|
-
view.setUint32(
|
|
272
|
-
view.setUint16(
|
|
273
|
-
view.setUint16(
|
|
274
|
-
view.setUint16(
|
|
275
|
-
view.setUint16(
|
|
276
|
-
view.setUint16(
|
|
277
|
-
view.setUint16(
|
|
278
|
-
view.setUint32(
|
|
279
|
-
view.setUint32(
|
|
280
|
-
view.setUint32(
|
|
281
|
-
view.setUint16(
|
|
282
|
-
view.setUint16(
|
|
283
|
-
view.setUint32(
|
|
284
|
-
view.setUint32(
|
|
285
|
-
buf.set(e.path,
|
|
286
|
-
|
|
275
|
+
view.setUint32(at3, 33639248, true);
|
|
276
|
+
view.setUint16(at3 + 4, e.made, true);
|
|
277
|
+
view.setUint16(at3 + 6, e.version, true);
|
|
278
|
+
view.setUint16(at3 + 8, e.flags & ~8, true);
|
|
279
|
+
view.setUint16(at3 + 10, e.method, true);
|
|
280
|
+
view.setUint16(at3 + 12, e.time, true);
|
|
281
|
+
view.setUint16(at3 + 14, e.date, true);
|
|
282
|
+
view.setUint32(at3 + 16, e.crc, true);
|
|
283
|
+
view.setUint32(at3 + 20, e.raw.length, true);
|
|
284
|
+
view.setUint32(at3 + 24, e.size, true);
|
|
285
|
+
view.setUint16(at3 + 28, e.path.length, true);
|
|
286
|
+
view.setUint16(at3 + 36, e.inner, true);
|
|
287
|
+
view.setUint32(at3 + 38, e.outer, true);
|
|
288
|
+
view.setUint32(at3 + 42, offsets[n], true);
|
|
289
|
+
buf.set(e.path, at3 + 46);
|
|
290
|
+
at3 += 46 + e.path.length;
|
|
287
291
|
});
|
|
288
|
-
view.setUint32(
|
|
289
|
-
view.setUint16(
|
|
290
|
-
view.setUint16(
|
|
291
|
-
view.setUint32(
|
|
292
|
-
view.setUint32(
|
|
293
|
-
return buf.subarray(0,
|
|
292
|
+
view.setUint32(at3, 101010256, true);
|
|
293
|
+
view.setUint16(at3 + 8, entries2.length, true);
|
|
294
|
+
view.setUint16(at3 + 10, entries2.length, true);
|
|
295
|
+
view.setUint32(at3 + 12, at3 - start, true);
|
|
296
|
+
view.setUint32(at3 + 16, start, true);
|
|
297
|
+
return buf.subarray(0, at3 + 22);
|
|
294
298
|
}
|
|
295
299
|
|
|
296
300
|
// src/docx/pkg.ts
|
|
@@ -1168,13 +1172,13 @@ var Reader = class {
|
|
|
1168
1172
|
}
|
|
1169
1173
|
}
|
|
1170
1174
|
span(xml, inside, out, ctx, link) {
|
|
1171
|
-
const
|
|
1172
|
-
if (!
|
|
1175
|
+
const shown2 = inside.filter((p) => p.text !== null);
|
|
1176
|
+
if (!shown2.length) {
|
|
1173
1177
|
out.push({ text: null, raw: xml, run: null, ctx, span: null });
|
|
1174
1178
|
return;
|
|
1175
1179
|
}
|
|
1176
1180
|
const span2 = { xml, link };
|
|
1177
|
-
for (const p of
|
|
1181
|
+
for (const p of shown2) out.push({ ...p, span: span2 });
|
|
1178
1182
|
}
|
|
1179
1183
|
run(k, ctx, parent, out, st) {
|
|
1180
1184
|
const s = this.s;
|
|
@@ -1280,7 +1284,7 @@ var Reader = class {
|
|
|
1280
1284
|
let last = i;
|
|
1281
1285
|
while (last + 1 < pieces2.length && pieces2[last + 1].run === z) last++;
|
|
1282
1286
|
out.length -= begin - first;
|
|
1283
|
-
const
|
|
1287
|
+
const shown2 = [];
|
|
1284
1288
|
const code = [];
|
|
1285
1289
|
let hidden = 0;
|
|
1286
1290
|
let instr = "";
|
|
@@ -1295,9 +1299,9 @@ var Reader = class {
|
|
|
1295
1299
|
} else if (q.fld === "end") {
|
|
1296
1300
|
if (code.pop()) hidden--;
|
|
1297
1301
|
} else if (q.instr && code.length === 1) instr += q.instr;
|
|
1298
|
-
else if (q.text !== null && hidden === 0)
|
|
1302
|
+
else if (q.text !== null && hidden === 0) shown2.push(q);
|
|
1299
1303
|
}
|
|
1300
|
-
this.span(this.s.slice(a.el.start, z.el.end),
|
|
1304
|
+
this.span(this.s.slice(a.el.start, z.el.end), shown2, out, pieces2[first].ctx, hyperlink(instr));
|
|
1301
1305
|
i = last;
|
|
1302
1306
|
} else if (depth === 0) out.push(p);
|
|
1303
1307
|
}
|
|
@@ -1311,8 +1315,8 @@ var Reader = class {
|
|
|
1311
1315
|
const pr = kid(el, "w:tblPr");
|
|
1312
1316
|
const jc = pr && kid(pr, "w:jc");
|
|
1313
1317
|
const bd = pr && kid(pr, "w:tblBorders");
|
|
1314
|
-
const
|
|
1315
|
-
const node = { type: "table", attrs: { align: align(jc ? attr(s, jc, "w:val") : null), indent: 0, borders:
|
|
1318
|
+
const bare2 = !!bd && bd.kids.length > 0 && bd.kids.every((k) => /^(none|nil)$/.test(attr(s, k, "w:val") ?? ""));
|
|
1319
|
+
const node = { type: "table", attrs: { align: align(jc ? attr(s, jc, "w:val") : null), indent: 0, borders: bare2 ? "none" : null, ref }, content: [] };
|
|
1316
1320
|
const b = this.block("tbl", el, node, ref);
|
|
1317
1321
|
const grid2 = kid(el, "w:tblGrid");
|
|
1318
1322
|
b.cols = grid2 ? grid2.kids.filter((k) => k.name === "w:gridCol").length : 0;
|
|
@@ -1389,10 +1393,10 @@ function contents(xml, styles) {
|
|
|
1389
1393
|
const level = Number(/^toc ?(\d)$/i.exec(styles.name(id).trim())?.[1] ?? /^TOC(\d)$/i.exec(id)?.[1] ?? 0);
|
|
1390
1394
|
begun || (begun = level > 0 || /w:fldCharType="begin"/.test(p));
|
|
1391
1395
|
const text = (p.replace(/<w:instrText\b[\s\S]*?<\/w:instrText>/g, "").match(/<w:t(?:\s[^>]*)?>[^<]*<\/w:t>|<w:tab\/>/g) ?? []).map((m) => m === "<w:tab/>" ? " " : unescape(m.replace(/<[^>]*>/g, ""))).join("");
|
|
1392
|
-
const
|
|
1393
|
-
if (!
|
|
1394
|
-
if (begun) entries2.push([level || 1,
|
|
1395
|
-
else title ?? (title =
|
|
1396
|
+
const shown2 = (text.includes(" ") ? text.slice(0, text.lastIndexOf(" ")) : text).trim();
|
|
1397
|
+
if (!shown2) continue;
|
|
1398
|
+
if (begun) entries2.push([level || 1, shown2]);
|
|
1399
|
+
else title ?? (title = shown2);
|
|
1396
1400
|
}
|
|
1397
1401
|
return { entries: entries2, title };
|
|
1398
1402
|
}
|
|
@@ -1542,10 +1546,10 @@ function diff(a, b) {
|
|
|
1542
1546
|
if (x >= n && y >= m) {
|
|
1543
1547
|
for (let e = d; e > 0; e--) {
|
|
1544
1548
|
const t = trace[e];
|
|
1545
|
-
const
|
|
1546
|
-
const down2 = k === -e || k !== e &&
|
|
1549
|
+
const at3 = (j) => t[j + e + 1];
|
|
1550
|
+
const down2 = k === -e || k !== e && at3(k - 1) < at3(k + 1);
|
|
1547
1551
|
const pk = down2 ? k + 1 : k - 1;
|
|
1548
|
-
const px2 =
|
|
1552
|
+
const px2 = at3(pk);
|
|
1549
1553
|
const py = px2 - pk;
|
|
1550
1554
|
while (x > px2 && y > py) map[p + --y] = p + --x;
|
|
1551
1555
|
x = px2;
|
|
@@ -1712,10 +1716,10 @@ function checked(xml, on2) {
|
|
|
1712
1716
|
const no = /w14:uncheckedState\b[^>]*w14:val="([0-9A-Fa-f]+)"/.exec(xml)?.[1] ?? "2610";
|
|
1713
1717
|
const [from, to] = on2 ? [no, yes] : [yes, no];
|
|
1714
1718
|
let out = /<w14:checked\b/.test(xml) ? xml.replace(/(<w14:checked\b[^>]*w14:val=")[^"]*"/, `$1${on2 ? 1 : 0}"`) : xml.replace(/(<w14:checkbox\b[^>]*>)/, `$1<w14:checked w14:val="${on2 ? 1 : 0}"/>`);
|
|
1715
|
-
const
|
|
1716
|
-
if (
|
|
1717
|
-
const tail = out.slice(
|
|
1718
|
-
out = out.slice(0,
|
|
1719
|
+
const at3 = out.indexOf("<w:sdtContent");
|
|
1720
|
+
if (at3 === -1) return out;
|
|
1721
|
+
const tail = out.slice(at3).replace(new RegExp(`w:char="${from}"`, "i"), `w:char="${to}"`).replace(`>${String.fromCharCode(parseInt(from, 16))}<`, `>${String.fromCharCode(parseInt(to, 16))}<`);
|
|
1722
|
+
out = out.slice(0, at3) + tail;
|
|
1719
1723
|
return out;
|
|
1720
1724
|
}
|
|
1721
1725
|
var Writer = class {
|
|
@@ -1781,9 +1785,9 @@ var Writer = class {
|
|
|
1781
1785
|
<w:numbering xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"></w:numbering>`;
|
|
1782
1786
|
this.types.add(`<Override PartName="/${path}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"/>`);
|
|
1783
1787
|
}
|
|
1784
|
-
const
|
|
1788
|
+
const at3 = n.search(/<w:num\b[\s>]/);
|
|
1785
1789
|
const abs = this.numbering.abs.join("");
|
|
1786
|
-
n =
|
|
1790
|
+
n = at3 === -1 ? n.replace(/(<w:numIdMacAtCleanup\b|<\/w:numbering>)/, abs + "$1") : n.slice(0, at3) + abs + n.slice(at3);
|
|
1787
1791
|
n = n.replace(/(<w:numIdMacAtCleanup\b|<\/w:numbering>)/, this.numbering.nums.join("") + "$1");
|
|
1788
1792
|
changed2.set(path, n);
|
|
1789
1793
|
if (!rel) {
|
|
@@ -1796,8 +1800,8 @@ var Writer = class {
|
|
|
1796
1800
|
const settings = this.tocs && this.pkg.byType("/settings");
|
|
1797
1801
|
const listed2 = settings && this.pkg.text(settings.target);
|
|
1798
1802
|
if (settings && listed2 && !/<w:updateFields\b/.test(listed2)) {
|
|
1799
|
-
const
|
|
1800
|
-
changed2.set(settings.target, listed2.slice(0,
|
|
1803
|
+
const at3 = listed2.search(/<(?:w:hdrShapeDefaults|w:footnotePr|w:endnotePr|w:compat|w:docVars|w:rsids|m:mathPr|w:attachedSchema|w:themeFontLang|w:clrSchemeMapping|w:doNotIncludeSubdocsInStats|w:doNotAutoCompressPictures|w:forceUpgrade|w:captions|w:readModeInkLockDown|w:smartTagType|sl:schemaLibrary|w:shapeDefaults|w:doNotEmbedSmartTags|w:decimalSymbol|w:listSeparator)\b|<\/w:settings>/);
|
|
1804
|
+
changed2.set(settings.target, listed2.slice(0, at3) + '<w:updateFields w:val="true"/>' + listed2.slice(at3));
|
|
1801
1805
|
}
|
|
1802
1806
|
if (this.styleXml.length) {
|
|
1803
1807
|
const rel = this.pkg.byType("/styles");
|
|
@@ -1909,11 +1913,11 @@ var Writer = class {
|
|
|
1909
1913
|
const path = rel ? rel.target : "word/footnotes.xml";
|
|
1910
1914
|
let xml = old ?? `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
1911
1915
|
<w:footnotes xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="${REL}"><w:footnote w:type="separator" w:id="-1"><w:p><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr><w:r><w:separator/></w:r></w:p></w:footnote><w:footnote w:type="continuationSeparator" w:id="0"><w:p><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr><w:r><w:continuationSeparator/></w:r></w:p></w:footnote></w:footnotes>`;
|
|
1912
|
-
const
|
|
1916
|
+
const fresh2 = (id, words2) => `<w:footnote w:id="${id}"><w:p><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr><w:r><w:rPr><w:vertAlign w:val="superscript"/></w:rPr><w:footnoteRef/></w:r><w:r><w:rPr><w:sz w:val="20"/></w:rPr><w:t xml:space="preserve"> ${escape(words2)}</w:t></w:r></w:p></w:footnote>`;
|
|
1913
1917
|
for (const n of notes3) {
|
|
1914
1918
|
const found = new RegExp(`<w:footnote\\b[^>]*\\bw:id="${n.id}"[^>]*>([\\s\\S]*?)</w:footnote>`).exec(xml);
|
|
1915
1919
|
if (found && noteText(found[1]) === n.text) continue;
|
|
1916
|
-
xml = found ? xml.replace(found[0],
|
|
1920
|
+
xml = found ? xml.replace(found[0], fresh2(n.id, n.text)) : xml.replace(/<\/w:footnotes>\s*$/, fresh2(n.id, n.text) + "</w:footnotes>");
|
|
1917
1921
|
}
|
|
1918
1922
|
if (xml === old) return;
|
|
1919
1923
|
changed2.set(path, xml);
|
|
@@ -1957,8 +1961,8 @@ var Writer = class {
|
|
|
1957
1961
|
sec = sec.replace(re, xml);
|
|
1958
1962
|
return;
|
|
1959
1963
|
}
|
|
1960
|
-
const
|
|
1961
|
-
const i =
|
|
1964
|
+
const at3 = before.map((b) => sec.search(new RegExp(`<${b}[\\s>/]`))).filter((i2) => i2 >= 0);
|
|
1965
|
+
const i = at3.length ? Math.min(...at3) : sec.lastIndexOf("</w:sectPr>");
|
|
1962
1966
|
sec = sec.slice(0, i) + xml + sec.slice(i);
|
|
1963
1967
|
};
|
|
1964
1968
|
const tw = (px2) => Math.round(px2 * 15);
|
|
@@ -2223,11 +2227,11 @@ var Writer = class {
|
|
|
2223
2227
|
}
|
|
2224
2228
|
const slot = new Int32Array(A.length + 1);
|
|
2225
2229
|
for (let k = 1; k <= A.length; k++) slot[k] = back[k - 1] >= 0 ? back[k - 1] + 1 : slot[k - 1];
|
|
2226
|
-
const
|
|
2230
|
+
const at3 = Array.from({ length: B.length + 1 }, () => []);
|
|
2227
2231
|
let chars = 0;
|
|
2228
2232
|
for (const u of units) {
|
|
2229
2233
|
if (u.ch !== null) chars++;
|
|
2230
|
-
else if (!u.box || o.task !== null)
|
|
2234
|
+
else if (!u.box || o.task !== null) at3[slot[chars]].push(u);
|
|
2231
2235
|
}
|
|
2232
2236
|
const paraBase = b ? this.markRun(b) : this.firstRun(src);
|
|
2233
2237
|
const out = [];
|
|
@@ -2241,7 +2245,7 @@ var Writer = class {
|
|
|
2241
2245
|
const next = new Int32Array(B.length + 1).fill(-1);
|
|
2242
2246
|
for (let k = B.length - 1; k >= 0; k--) next[k] = map[k] >= 0 ? map[k] : next[k + 1];
|
|
2243
2247
|
for (let j = 0; j <= B.length; j++) {
|
|
2244
|
-
for (const u of
|
|
2248
|
+
for (const u of at3[j]) out.push({ ch: null, raw: u.box && !u.run && b && b.task !== o.task ? checked(u.raw, !!o.task) : u.raw, run: u.run, ctx: u.ctx, u, fmt: u.fmt });
|
|
2245
2249
|
if (j === B.length) break;
|
|
2246
2250
|
const i = map[j];
|
|
2247
2251
|
const want = B[j];
|
|
@@ -2342,8 +2346,8 @@ var Writer = class {
|
|
|
2342
2346
|
wrap = { open: tag, close: "</w:hyperlink>", link, ins: false };
|
|
2343
2347
|
this.wraps.set(link, wrap);
|
|
2344
2348
|
}
|
|
2345
|
-
const
|
|
2346
|
-
return
|
|
2349
|
+
const at3 = out.findIndex((w) => w.ins);
|
|
2350
|
+
return at3 === -1 ? [...out, wrap] : [...out.slice(0, at3), wrap, ...out.slice(at3)];
|
|
2347
2351
|
}
|
|
2348
2352
|
revised(ctx, rev) {
|
|
2349
2353
|
const out = ctx.filter((w) => !w.rev || w.rev === rev);
|
|
@@ -2899,14 +2903,14 @@ var lookup = (doc, query, matchCase) => {
|
|
|
2899
2903
|
doc.descendants((node, pos) => {
|
|
2900
2904
|
if (!node.isTextblock) return true;
|
|
2901
2905
|
let text = "";
|
|
2902
|
-
const
|
|
2906
|
+
const at3 = [];
|
|
2903
2907
|
node.forEach((child, offset) => {
|
|
2904
2908
|
const part = child.isText ? child.text : "\uFFFC";
|
|
2905
|
-
for (let i = 0; i < part.length; i++)
|
|
2909
|
+
for (let i = 0; i < part.length; i++) at3.push(pos + 1 + offset + i);
|
|
2906
2910
|
text += part;
|
|
2907
2911
|
});
|
|
2908
2912
|
const hay = matchCase ? text : text.toLowerCase();
|
|
2909
|
-
for (let i = hay.indexOf(needle); i >= 0; i = hay.indexOf(needle, i + needle.length)) hits.push({ from:
|
|
2913
|
+
for (let i = hay.indexOf(needle); i >= 0; i = hay.indexOf(needle, i + needle.length)) hits.push({ from: at3[i], to: at3[i + needle.length - 1] + 1 });
|
|
2910
2914
|
return false;
|
|
2911
2915
|
});
|
|
2912
2916
|
return hits;
|
|
@@ -2922,8 +2926,8 @@ var Search = import_core2.Extension.create({
|
|
|
2922
2926
|
if (!meta2 && !tr.docChanged) return value3;
|
|
2923
2927
|
const next = { ...value3, ...meta2 };
|
|
2924
2928
|
const hits = lookup(tr.doc, next.query, next.matchCase);
|
|
2925
|
-
const
|
|
2926
|
-
return { ...next, hits, at:
|
|
2929
|
+
const at3 = hits.length ? (next.at % hits.length + hits.length) % hits.length : 0;
|
|
2930
|
+
return { ...next, hits, at: at3, set: import_view2.DecorationSet.create(tr.doc, hits.map((h, i) => import_view2.Decoration.inline(h.from, h.to, { class: i === at3 ? "w100n-found is-current" : "w100n-found" }))) };
|
|
2927
2931
|
}
|
|
2928
2932
|
},
|
|
2929
2933
|
props: { decorations: (state) => searching.getState(state).set }
|
|
@@ -2968,12 +2972,12 @@ var Blocks = import_core2.Extension.create({
|
|
|
2968
2972
|
for (let i = start; i < end; i++) {
|
|
2969
2973
|
const top = state.doc.child(i);
|
|
2970
2974
|
visit(top, pos);
|
|
2971
|
-
top.descendants((node,
|
|
2975
|
+
top.descendants((node, at3) => visit(node, pos + 1 + at3));
|
|
2972
2976
|
pos += top.nodeSize;
|
|
2973
2977
|
}
|
|
2974
2978
|
if (!drop.length) return null;
|
|
2975
2979
|
const tr = state.tr;
|
|
2976
|
-
for (const
|
|
2980
|
+
for (const at3 of drop) tr.setNodeAttribute(at3, "ref", null);
|
|
2977
2981
|
return tr;
|
|
2978
2982
|
}
|
|
2979
2983
|
})]
|
|
@@ -3089,7 +3093,7 @@ var Reveal = import_core2.Extension.create({
|
|
|
3089
3093
|
const found = [];
|
|
3090
3094
|
const start = $from.start();
|
|
3091
3095
|
if ($from.parent.type.name === "heading") found.push(syntax(`${"#".repeat($from.parent.attrs.level)} `, start, -1));
|
|
3092
|
-
const
|
|
3096
|
+
const at3 = $from.parentOffset;
|
|
3093
3097
|
for (const [name, sign] of Object.entries(signs)) {
|
|
3094
3098
|
let from = -1;
|
|
3095
3099
|
let offset = 0;
|
|
@@ -3097,7 +3101,7 @@ var Reveal = import_core2.Extension.create({
|
|
|
3097
3101
|
const end = offset + child.nodeSize;
|
|
3098
3102
|
if (child.marks.some((m) => m.type.name === name)) {
|
|
3099
3103
|
if (from < 0) from = offset;
|
|
3100
|
-
if (from <=
|
|
3104
|
+
if (from <= at3 && at3 <= end && (end === $from.parent.content.size || !$from.parent.childAfter(end).node?.marks.some((m) => m.type.name === name))) {
|
|
3101
3105
|
found.push(syntax(sign, start + from, -1), syntax(sign, start + end, 1));
|
|
3102
3106
|
}
|
|
3103
3107
|
} else from = -1;
|
|
@@ -3164,8 +3168,8 @@ var Toc = import_core2.Node.create({
|
|
|
3164
3168
|
dom.className = "w100n-text-toc";
|
|
3165
3169
|
dom.contentEditable = "false";
|
|
3166
3170
|
const paint2 = () => {
|
|
3167
|
-
const
|
|
3168
|
-
const list = entries(editor.state.doc, this.options.relative,
|
|
3171
|
+
const at3 = getPos() ?? 0;
|
|
3172
|
+
const list = entries(editor.state.doc, this.options.relative, at3);
|
|
3169
3173
|
const head = document.createElement("b");
|
|
3170
3174
|
head.textContent = this.options.label;
|
|
3171
3175
|
const items = list.map(([level, text], i) => {
|
|
@@ -3200,15 +3204,15 @@ var Toc = import_core2.Node.create({
|
|
|
3200
3204
|
return [new import_state2.Plugin({
|
|
3201
3205
|
appendTransaction(trs, _old, state) {
|
|
3202
3206
|
if (!trs.some((tr2) => tr2.docChanged && !tr2.getMeta(import_y_tiptap.ySyncPluginKey))) return null;
|
|
3203
|
-
const
|
|
3207
|
+
const at3 = [];
|
|
3204
3208
|
state.doc.forEach((node, pos) => {
|
|
3205
|
-
if (node.type.name === "toc")
|
|
3209
|
+
if (node.type.name === "toc") at3.push(pos);
|
|
3206
3210
|
});
|
|
3207
|
-
if (!
|
|
3211
|
+
if (!at3.length) return null;
|
|
3208
3212
|
const tr = state.tr;
|
|
3209
|
-
for (const pos of
|
|
3210
|
-
const
|
|
3211
|
-
if (state.doc.nodeAt(pos).attrs.entries !==
|
|
3213
|
+
for (const pos of at3) {
|
|
3214
|
+
const fresh2 = JSON.stringify(entries(state.doc, relative2, pos));
|
|
3215
|
+
if (state.doc.nodeAt(pos).attrs.entries !== fresh2) tr.setNodeAttribute(pos, "entries", fresh2);
|
|
3212
3216
|
}
|
|
3213
3217
|
return tr.docChanged ? tr : null;
|
|
3214
3218
|
}
|
|
@@ -3249,10 +3253,10 @@ var Suggest = import_core2.Extension.create({
|
|
|
3249
3253
|
const { state } = view;
|
|
3250
3254
|
const tr = state.tr;
|
|
3251
3255
|
if (to > from) strike(tr, state, from, to);
|
|
3252
|
-
const
|
|
3256
|
+
const at3 = tr.mapping.map(to);
|
|
3253
3257
|
const kept = (state.storedMarks ?? state.doc.resolve(from).marks()).filter((m) => m.type.name !== "insertion" && m.type.name !== "deletion");
|
|
3254
|
-
tr.insert(
|
|
3255
|
-
tr.setSelection(import_state2.TextSelection.create(tr.doc,
|
|
3258
|
+
tr.insert(at3, state.schema.text(text, [...kept, stamp(state, "insertion", from, to)]));
|
|
3259
|
+
tr.setSelection(import_state2.TextSelection.create(tr.doc, at3 + text.length));
|
|
3256
3260
|
view.dispatch(tr.scrollIntoView());
|
|
3257
3261
|
return true;
|
|
3258
3262
|
};
|
|
@@ -3276,16 +3280,16 @@ var Suggest = import_core2.Extension.create({
|
|
|
3276
3280
|
if (!suggesting.getState(state).on || event.key !== "Backspace" && event.key !== "Delete" || event.metaKey || event.ctrlKey || event.altKey) return false;
|
|
3277
3281
|
const { from, to, empty, $from } = state.selection;
|
|
3278
3282
|
const back = event.key === "Backspace";
|
|
3279
|
-
let
|
|
3283
|
+
let at3 = from;
|
|
3280
3284
|
if (empty) {
|
|
3281
3285
|
const skip2 = (pos) => state.doc.resolve(pos)[back ? "nodeBefore" : "nodeAfter"]?.marks.some((m) => m.type.name === "deletion");
|
|
3282
|
-
while (skip2(
|
|
3283
|
-
if (back ?
|
|
3286
|
+
while (skip2(at3)) at3 += back ? -1 : 1;
|
|
3287
|
+
if (back ? at3 <= $from.start() : at3 >= $from.end()) return false;
|
|
3284
3288
|
}
|
|
3285
3289
|
const tr = state.tr;
|
|
3286
|
-
if (empty) strike(tr, state, back ?
|
|
3290
|
+
if (empty) strike(tr, state, back ? at3 - 1 : at3, back ? at3 : at3 + 1);
|
|
3287
3291
|
else strike(tr, state, from, to);
|
|
3288
|
-
const caret = empty ? tr.mapping.map(back ?
|
|
3292
|
+
const caret = empty ? tr.mapping.map(back ? at3 - 1 : at3 + 1, back ? -1 : 1) : tr.mapping.map(back ? from : to);
|
|
3289
3293
|
tr.setSelection(import_state2.TextSelection.create(tr.doc, caret));
|
|
3290
3294
|
view.dispatch(tr.scrollIntoView());
|
|
3291
3295
|
return true;
|
|
@@ -3326,7 +3330,7 @@ var Locks = import_core2.Extension.create({
|
|
|
3326
3330
|
},
|
|
3327
3331
|
apply(tr, value3) {
|
|
3328
3332
|
if (!tr.docChanged) return value3;
|
|
3329
|
-
const
|
|
3333
|
+
const fresh2 = tr.steps.some((step) => {
|
|
3330
3334
|
let found = false;
|
|
3331
3335
|
step.slice?.content.descendants((node) => {
|
|
3332
3336
|
found || (found = locked(node));
|
|
@@ -3334,7 +3338,7 @@ var Locks = import_core2.Extension.create({
|
|
|
3334
3338
|
});
|
|
3335
3339
|
return found;
|
|
3336
3340
|
});
|
|
3337
|
-
const spans =
|
|
3341
|
+
const spans = fresh2 ? scan(tr.doc) : value3.spans.map((s) => ({ from: tr.mapping.map(s.from, 1), to: tr.mapping.map(s.to, -1) })).filter((s) => s.to > s.from);
|
|
3338
3342
|
return { spans, set: spans.length ? shade(tr.doc, spans) : import_view2.DecorationSet.empty };
|
|
3339
3343
|
}
|
|
3340
3344
|
},
|
|
@@ -3357,10 +3361,10 @@ var Locks = import_core2.Extension.create({
|
|
|
3357
3361
|
const { $from, empty } = view.state.selection;
|
|
3358
3362
|
if (!back && event.key !== "Delete" || !empty || $from.depth < 1) return false;
|
|
3359
3363
|
if (back ? $from.parentOffset !== 0 : $from.parentOffset !== $from.parent.content.size) return false;
|
|
3360
|
-
const
|
|
3361
|
-
const node = back ? view.state.doc.resolve(
|
|
3364
|
+
const at3 = back ? $from.before() : $from.after();
|
|
3365
|
+
const node = back ? view.state.doc.resolve(at3).nodeBefore : view.state.doc.resolve(at3).nodeAfter;
|
|
3362
3366
|
if (!node || !locked(node)) return false;
|
|
3363
|
-
view.dispatch(view.state.tr.delete(back ?
|
|
3367
|
+
view.dispatch(view.state.tr.delete(back ? at3 - node.nodeSize : at3, back ? at3 : at3 + node.nodeSize));
|
|
3364
3368
|
return true;
|
|
3365
3369
|
}
|
|
3366
3370
|
}
|
|
@@ -3893,8 +3897,8 @@ ${base.tail.replace(/^\n+/, "")}` : "");
|
|
|
3893
3897
|
const extra = fix(lost) + [...now].filter(([id]) => !seen.has(id)).map(([id, note]) => `[^${id}]: ${note.replace(/\n/g, "\n ")}
|
|
3894
3898
|
`).join("");
|
|
3895
3899
|
if (extra) out = `${out.replace(/\n*$/, "\n\n")}${extra}`;
|
|
3896
|
-
const
|
|
3897
|
-
const raws =
|
|
3900
|
+
const at3 = starts.map((s) => Math.min(s, cut));
|
|
3901
|
+
const raws = at3.map((s, i) => out.slice(s, i + 1 < at3.length ? at3[i + 1] : cut));
|
|
3898
3902
|
const text = base.crlf ? out.replace(/\n/g, "\r\n") : out;
|
|
3899
3903
|
return { text: base.bom ? `\uFEFF${text}` : text, base: { ...base, nodes, raws, tail: out.slice(cut) } };
|
|
3900
3904
|
}
|
|
@@ -3907,6 +3911,8 @@ var SheetRefusal = class extends Error {
|
|
|
3907
3911
|
this.sheet = sheet;
|
|
3908
3912
|
}
|
|
3909
3913
|
};
|
|
3914
|
+
var counter = 0;
|
|
3915
|
+
var fresh = (prefix) => `${prefix}${Date.now().toString(36)}${(counter++).toString(36)}${Math.random().toString(36).slice(2, 6)}`;
|
|
3910
3916
|
var numbered = (prefix, count) => Array.from({ length: count }, (_, i) => `${prefix}${i}`);
|
|
3911
3917
|
|
|
3912
3918
|
// src/sheets/csv.ts
|
|
@@ -3945,12 +3951,12 @@ function encode(text, encoding, bom) {
|
|
|
3945
3951
|
if (encoding === "utf-16le" || encoding === "utf-16be") {
|
|
3946
3952
|
const out2 = new Uint8Array(text.length * 2 + (bom ? 2 : 0));
|
|
3947
3953
|
const view = new DataView(out2.buffer);
|
|
3948
|
-
let
|
|
3954
|
+
let at3 = 0;
|
|
3949
3955
|
if (bom) {
|
|
3950
3956
|
view.setUint16(0, 65279, encoding === "utf-16le");
|
|
3951
|
-
|
|
3957
|
+
at3 = 2;
|
|
3952
3958
|
}
|
|
3953
|
-
for (let i = 0; i < text.length; i++) view.setUint16(
|
|
3959
|
+
for (let i = 0; i < text.length; i++) view.setUint16(at3 + i * 2, text.charCodeAt(i), encoding === "utf-16le");
|
|
3954
3960
|
return out2;
|
|
3955
3961
|
}
|
|
3956
3962
|
const table2 = /* @__PURE__ */ new Map();
|
|
@@ -4086,8 +4092,8 @@ function writeCsv(original, model) {
|
|
|
4086
4092
|
const r0 = rowFrom.get(lines2.rows[r]) ?? -1;
|
|
4087
4093
|
const was = r0 >= 0 ? old[r0] : void 0;
|
|
4088
4094
|
const line = cells[r] ?? {};
|
|
4089
|
-
const
|
|
4090
|
-
let count =
|
|
4095
|
+
const filled3 = Object.keys(line).map(Number).filter((c) => show(value2(line[c])) !== "");
|
|
4096
|
+
let count = filled3.length ? Math.max(...filled3) + 1 : 0;
|
|
4091
4097
|
if (was) for (let c0 = 0; c0 < was.length; c0++) count = Math.max(count, lines2.cols.indexOf(origin.cols[c0]) + 1);
|
|
4092
4098
|
const fields = [];
|
|
4093
4099
|
for (let c = 0; c < count; c++) {
|
|
@@ -4656,8 +4662,8 @@ var Styles2 = class {
|
|
|
4656
4662
|
return index;
|
|
4657
4663
|
}
|
|
4658
4664
|
add(list, xml) {
|
|
4659
|
-
const
|
|
4660
|
-
if (
|
|
4665
|
+
const at3 = this[list].indexOf(xml);
|
|
4666
|
+
if (at3 >= 0) return at3;
|
|
4661
4667
|
this[list].push(xml);
|
|
4662
4668
|
this.added = true;
|
|
4663
4669
|
return this[list].length - 1;
|
|
@@ -4736,8 +4742,8 @@ var Styles2 = class {
|
|
|
4736
4742
|
edits2.push([el.start, el.end, `${open} count="${lists[name].length}">${lists[name].join("")}</${el.name}>`]);
|
|
4737
4743
|
} else {
|
|
4738
4744
|
const after = root.kids.find((k) => order2.indexOf(this.bare(k.name)) > order2.indexOf(name));
|
|
4739
|
-
const
|
|
4740
|
-
edits2.push([
|
|
4745
|
+
const at3 = after ? after.start : root.close;
|
|
4746
|
+
edits2.push([at3, at3, `<${p}${name} count="${lists[name].length}">${lists[name].join("")}</${p}${name}>`]);
|
|
4741
4747
|
}
|
|
4742
4748
|
}
|
|
4743
4749
|
edits2.sort((x, y) => y[0] - x[0]);
|
|
@@ -4839,7 +4845,7 @@ function load(bytes) {
|
|
|
4839
4845
|
if (state === "hidden") sheet.hidden = 1;
|
|
4840
4846
|
if (state === "veryHidden") sheet.hidden = 2;
|
|
4841
4847
|
const open = element(sxml, `${p}sheetData`);
|
|
4842
|
-
const
|
|
4848
|
+
const bounds2 = open ? [open.start, open.open, open.close, open.end] : [sxml.length, sxml.length, sxml.length, sxml.length];
|
|
4843
4849
|
const head = open ? sxml.slice(0, open.start) : sxml;
|
|
4844
4850
|
const tail = open ? sxml.slice(open.end) : "";
|
|
4845
4851
|
const format = /<(?:\w+:)?sheetFormatPr\b[^>]*>/.exec(head)?.[0];
|
|
@@ -4879,13 +4885,13 @@ function load(bytes) {
|
|
|
4879
4885
|
let maxRow = -1, maxCol = -1;
|
|
4880
4886
|
if (open && open.close > open.open) {
|
|
4881
4887
|
const end = open.close;
|
|
4882
|
-
let
|
|
4883
|
-
while (
|
|
4884
|
-
const lt = sxml.indexOf("<",
|
|
4888
|
+
let at3 = open.open, row2 = -1, col = -1;
|
|
4889
|
+
while (at3 < end) {
|
|
4890
|
+
const lt = sxml.indexOf("<", at3);
|
|
4885
4891
|
if (lt < 0 || lt >= end) break;
|
|
4886
4892
|
const gt = sxml.indexOf(">", lt);
|
|
4887
4893
|
if (sxml.charCodeAt(lt + 1) === 47) {
|
|
4888
|
-
|
|
4894
|
+
at3 = gt + 1;
|
|
4889
4895
|
continue;
|
|
4890
4896
|
}
|
|
4891
4897
|
let j = lt + 1;
|
|
@@ -4913,11 +4919,11 @@ function load(bytes) {
|
|
|
4913
4919
|
}
|
|
4914
4920
|
if (Object.keys(rd).length) rowData[row2] = rd;
|
|
4915
4921
|
if (rd.h !== void 0 || rd.hd || rd.s) maxRow = Math.max(maxRow, row2);
|
|
4916
|
-
|
|
4922
|
+
at3 = gt + 1;
|
|
4917
4923
|
continue;
|
|
4918
4924
|
}
|
|
4919
4925
|
if (name !== "c") {
|
|
4920
|
-
|
|
4926
|
+
at3 = gt + 1;
|
|
4921
4927
|
continue;
|
|
4922
4928
|
}
|
|
4923
4929
|
const ref = attr2(tag, "r");
|
|
@@ -4981,7 +4987,7 @@ function load(bytes) {
|
|
|
4981
4987
|
}
|
|
4982
4988
|
}
|
|
4983
4989
|
cells.set(key(row2, col), { start: lt, end: stop, shared });
|
|
4984
|
-
|
|
4990
|
+
at3 = stop;
|
|
4985
4991
|
}
|
|
4986
4992
|
}
|
|
4987
4993
|
for (const [r, c, si] of children) {
|
|
@@ -5062,7 +5068,7 @@ function load(bytes) {
|
|
|
5062
5068
|
xml: sxml,
|
|
5063
5069
|
p,
|
|
5064
5070
|
rels: srels,
|
|
5065
|
-
bounds,
|
|
5071
|
+
bounds: bounds2,
|
|
5066
5072
|
rows,
|
|
5067
5073
|
cells,
|
|
5068
5074
|
cols,
|
|
@@ -5089,8 +5095,8 @@ function load(bytes) {
|
|
|
5089
5095
|
if (Object.keys(notes3).length) resources.push({ name: "SHEET_NOTE_PLUGIN", data: JSON.stringify(notes3) });
|
|
5090
5096
|
if (Object.keys(validations).length) resources.push({ name: "SHEET_DATA_VALIDATION_PLUGIN", data: JSON.stringify(validations) });
|
|
5091
5097
|
if (Object.keys(filters).length) resources.push({ name: "SHEET_FILTER_PLUGIN", data: JSON.stringify(filters) });
|
|
5092
|
-
const
|
|
5093
|
-
if (
|
|
5098
|
+
const shown2 = entries2[active];
|
|
5099
|
+
if (shown2?.sheet && book.sheetOrder.includes(`s${shown2.sheetId}`)) model.active = `s${shown2.sheetId}`;
|
|
5094
5100
|
return { model, book: { pack, part, xml, rels, styles, stylesPart: stylesPart ?? null, sheets, entries: entries2 } };
|
|
5095
5101
|
}
|
|
5096
5102
|
var kinds = { whole: "whole", decimal: "decimal", list: "list", textLength: "textLength", custom: "custom" };
|
|
@@ -5258,14 +5264,14 @@ function place(xml, name, value3) {
|
|
|
5258
5264
|
if (found) return xml.slice(0, found.start) + (value3 ?? "") + xml.slice(found.end);
|
|
5259
5265
|
if (value3 === null) return xml;
|
|
5260
5266
|
const rank = order.indexOf(name);
|
|
5261
|
-
let
|
|
5267
|
+
let at3 = -1;
|
|
5262
5268
|
for (const later of order.slice(rank + 1)) {
|
|
5263
5269
|
const f = find2(xml, later);
|
|
5264
|
-
if (f && (
|
|
5270
|
+
if (f && (at3 < 0 || f.start < at3)) at3 = f.start;
|
|
5265
5271
|
}
|
|
5266
|
-
if (
|
|
5267
|
-
if (
|
|
5268
|
-
return xml.slice(0,
|
|
5272
|
+
if (at3 < 0) at3 = xml.search(/<\/(?:\w+:)?worksheet>\s*$/);
|
|
5273
|
+
if (at3 < 0) at3 = xml.length;
|
|
5274
|
+
return xml.slice(0, at3) + value3 + xml.slice(at3);
|
|
5269
5275
|
}
|
|
5270
5276
|
function remapZone(xml, mine, rows, cols) {
|
|
5271
5277
|
const ranges = (sqref) => boxes(sqref).map((b) => squeeze(b, rows.map, cols.map)).filter((b) => b !== null).map(span).join(" ");
|
|
@@ -5334,7 +5340,7 @@ function writeXlsx(original, model) {
|
|
|
5334
5340
|
let nextSheetId = Math.max(0, ...book.entries.map((e) => e.sheetId)) + 1;
|
|
5335
5341
|
let nextRid = Math.max(0, ...book.rels.map((r) => Number(/\d+$/.exec(r.id)?.[0] ?? 0))) + 1;
|
|
5336
5342
|
const used = new Set(pack.names.keys());
|
|
5337
|
-
const
|
|
5343
|
+
const fresh2 = (pattern) => {
|
|
5338
5344
|
let n = 1;
|
|
5339
5345
|
while (used.has(pattern(n)) || pack.changed.has(pattern(n))) n++;
|
|
5340
5346
|
used.add(pattern(n));
|
|
@@ -5351,7 +5357,7 @@ function writeXlsx(original, model) {
|
|
|
5351
5357
|
sheetParts.push({ sid, rec, part: rec.part, rid: book.entries.find((e) => e.sheetId === rec.sheetId).rid, sheetId: rec.sheetId });
|
|
5352
5358
|
if (cur.sheets[sid].name !== rec.name) names.set(rec.name, cur.sheets[sid].name);
|
|
5353
5359
|
} else {
|
|
5354
|
-
const part =
|
|
5360
|
+
const part = fresh2((n) => `xl/worksheets/sheet${n}.xml`);
|
|
5355
5361
|
sheetParts.push({ sid, rec: null, part, rid: `rId${nextRid++}`, sheetId: nextSheetId++ });
|
|
5356
5362
|
types.push([`/${part}`, "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"]);
|
|
5357
5363
|
}
|
|
@@ -5499,8 +5505,8 @@ function writeXlsx(original, model) {
|
|
|
5499
5505
|
if (curRules && !same(rules.map(canonRule), oldRules.map(canonRule))) {
|
|
5500
5506
|
changed2 = true;
|
|
5501
5507
|
const known = new Map((rec?.validations ?? []).map((v, i) => [`dv${i}`, v]));
|
|
5502
|
-
const
|
|
5503
|
-
const hiddenRules = [...known].filter(([uid, v]) => !
|
|
5508
|
+
const shown2 = new Set(rules.map((r) => r.uid));
|
|
5509
|
+
const hiddenRules = [...known].filter(([uid, v]) => !shown2.has(uid) && !(rec && baseRules[rec.sid]?.some((r) => r.uid === uid)) && v).map(([, v]) => rows.moved || cols.moved ? remapZone(v, mine, rows, cols) : v);
|
|
5504
5510
|
const list = [...hiddenRules, ...rules.map((r) => validationXml(p, r, known.get(r.uid)))].filter(Boolean);
|
|
5505
5511
|
tail = place(tail, "dataValidations", list.length ? `<${p}dataValidations count="${list.length}">${list.join("")}</${p}dataValidations>` : null);
|
|
5506
5512
|
}
|
|
@@ -5521,7 +5527,7 @@ function writeXlsx(original, model) {
|
|
|
5521
5527
|
const nowNotes = notes3.map((n) => ({ ref: a1(n.row, n.col), text: n.note })).sort((a, b) => a.ref.localeCompare(b.ref));
|
|
5522
5528
|
if (curNotes && !same(nowNotes, [...oldNotes].sort((a, b) => a.ref.localeCompare(b.ref)))) {
|
|
5523
5529
|
changed2 = true;
|
|
5524
|
-
tail = writeNotes(book, entry2, tail, p, notes3, rows, cols, types, defaultsNeeded,
|
|
5530
|
+
tail = writeNotes(book, entry2, tail, p, notes3, rows, cols, types, defaultsNeeded, fresh2);
|
|
5525
5531
|
}
|
|
5526
5532
|
const rename = (s) => names.size ? s.replace(/<(xm:f|(?:\w+:)?formula\d?)>([\s\S]*?)<\/\1>/g, (_, n, f) => `<${n}>${escape([...names].reduce((g, [from, to]) => renamed(g, from, to), unescape(f)))}</${n}>`) : s;
|
|
5527
5533
|
if (!changed2) {
|
|
@@ -5611,9 +5617,9 @@ function writeXlsx(original, model) {
|
|
|
5611
5617
|
listed2.push({ xml: tag, sheetId: s.sheetId, oldIndex: s.rec ? indexOf.get(s.sheetId) : -1 });
|
|
5612
5618
|
}
|
|
5613
5619
|
for (const { e, i } of nonSheets) {
|
|
5614
|
-
let
|
|
5615
|
-
if (
|
|
5616
|
-
listed2.splice(
|
|
5620
|
+
let at3 = listed2.findIndex((x) => x.oldIndex > i);
|
|
5621
|
+
if (at3 < 0) at3 = listed2.length;
|
|
5622
|
+
listed2.splice(at3, 0, { xml: e.xml, sheetId: e.sheetId, oldIndex: i });
|
|
5617
5623
|
}
|
|
5618
5624
|
wb = wb.replace(/(<(?:\w+:)?sheets\b[^>]*>)[\s\S]*?(<\/(?:\w+:)?sheets>)/, (_, a, b) => a + listed2.map((x) => x.xml).join("") + b);
|
|
5619
5625
|
const newIndex = new Map(listed2.map((x, i) => [x.oldIndex, i]));
|
|
@@ -5639,9 +5645,9 @@ function writeXlsx(original, model) {
|
|
|
5639
5645
|
for (const [from, to] of names) f = renamed(f, from, to);
|
|
5640
5646
|
return `${tag}${escape(f)}</${p}definedName>`;
|
|
5641
5647
|
});
|
|
5642
|
-
for (const [
|
|
5648
|
+
for (const [sheetId2, f] of filterNames) {
|
|
5643
5649
|
if (!f) continue;
|
|
5644
|
-
const def2 = `<${wp}definedName name="_xlnm._FilterDatabase" localSheetId="${sheetIndex.get(
|
|
5650
|
+
const def2 = `<${wp}definedName name="_xlnm._FilterDatabase" localSheetId="${sheetIndex.get(sheetId2)}" hidden="1">${escape(f)}</${wp}definedName>`;
|
|
5645
5651
|
wb = /<(?:\w+:)?definedNames\b/.test(wb) ? wb.replace(/<\/(?:\w+:)?definedNames>/, (end) => def2 + end) : wb.replace(/<\/(?:\w+:)?sheets>/, (end) => `${end}<${wp}definedNames>${def2}</${wp}definedNames>`);
|
|
5646
5652
|
}
|
|
5647
5653
|
wb = wb.replace(/<((?:\w+:)?)definedNames>\s*<\/\1definedNames>/, "");
|
|
@@ -5831,7 +5837,7 @@ function filterXml(p, ref, columns2) {
|
|
|
5831
5837
|
}).join("");
|
|
5832
5838
|
return body ? `<${p}autoFilter ref="${span(ref)}">${body}</${p}autoFilter>` : `<${p}autoFilter ref="${span(ref)}"/>`;
|
|
5833
5839
|
}
|
|
5834
|
-
function writeNotes(book, entry2, tail, p, notes3, rows, cols, types, defaults,
|
|
5840
|
+
function writeNotes(book, entry2, tail, p, notes3, rows, cols, types, defaults, fresh2) {
|
|
5835
5841
|
const { pack } = book;
|
|
5836
5842
|
const rec = entry2.rec;
|
|
5837
5843
|
const relsPart = relsOf(entry2.part);
|
|
@@ -5840,12 +5846,12 @@ function writeNotes(book, entry2, tail, p, notes3, rows, cols, types, defaults,
|
|
|
5840
5846
|
let commentsPart = rec?.comments ?? null;
|
|
5841
5847
|
let vmlPart = rec?.vml ?? null;
|
|
5842
5848
|
if (!commentsPart) {
|
|
5843
|
-
commentsPart =
|
|
5849
|
+
commentsPart = fresh2((n) => `xl/comments${n}.xml`);
|
|
5844
5850
|
rels = rels.replace("</Relationships>", () => `<Relationship Id="rId${nextRid++}" Type="${REL2}/comments" Target="${relative(entry2.part, commentsPart)}"/></Relationships>`);
|
|
5845
5851
|
types.push([`/${commentsPart}`, "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"]);
|
|
5846
5852
|
}
|
|
5847
5853
|
if (!vmlPart) {
|
|
5848
|
-
vmlPart =
|
|
5854
|
+
vmlPart = fresh2((n) => `xl/drawings/vmlDrawing${n}.vml`);
|
|
5849
5855
|
const rid = `rId${nextRid++}`;
|
|
5850
5856
|
rels = rels.replace("</Relationships>", () => `<Relationship Id="${rid}" Type="${REL2}/vmlDrawing" Target="${relative(entry2.part, vmlPart)}"/></Relationships>`);
|
|
5851
5857
|
defaults.add("vml");
|
|
@@ -5902,6 +5908,7 @@ function writeSheet(original, model, kind) {
|
|
|
5902
5908
|
var Y = __toESM(require("yjs"), 1);
|
|
5903
5909
|
var props2 = ["name", "hidden", "tabColor", "freeze", "showGridlines", "rightToLeft"];
|
|
5904
5910
|
var spot = (row2, col) => `${row2}:${col}`;
|
|
5911
|
+
var canon = (x) => x === null || typeof x !== "object" ? JSON.stringify(x ?? null) : Array.isArray(x) ? `[${x.map(canon).join(",")}]` : `{${Object.keys(x).filter((k) => x[k] !== void 0).sort().map((k) => `${JSON.stringify(k)}:${canon(x[k])}`).join(",")}}`;
|
|
5905
5912
|
var strip = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== void 0 && v !== null));
|
|
5906
5913
|
var fnv = (bytes, h = 2166136261) => {
|
|
5907
5914
|
for (const b of bytes) h = Math.imul(h ^ b, 16777619) >>> 0;
|
|
@@ -5957,18 +5964,18 @@ function fill2(doc, model) {
|
|
|
5957
5964
|
const { cells, rowData, colData, merges, notes: kept } = pieces(sheets.get(sid));
|
|
5958
5965
|
for (const [r, line] of Object.entries(sheet.cellData ?? {})) for (const [c, x] of Object.entries(line ?? {})) {
|
|
5959
5966
|
if (!x) continue;
|
|
5960
|
-
const
|
|
5967
|
+
const at3 = spot(l.rows[+r], l.cols[+c]);
|
|
5961
5968
|
const out = {};
|
|
5962
5969
|
if (x.f) {
|
|
5963
5970
|
out.f = x.f;
|
|
5964
|
-
values.set(`${sid}:${
|
|
5971
|
+
values.set(`${sid}:${at3}`, { v: x.v ?? null, t: x.t ?? null });
|
|
5965
5972
|
} else {
|
|
5966
5973
|
if (x.v !== void 0 && x.v !== null) out.v = x.v;
|
|
5967
5974
|
if (x.t) out.t = x.t;
|
|
5968
5975
|
}
|
|
5969
5976
|
if (x.p) out.p = x.p;
|
|
5970
5977
|
if (typeof x.s === "string") out.s = x.s;
|
|
5971
|
-
cells.set(
|
|
5978
|
+
cells.set(at3, out);
|
|
5972
5979
|
}
|
|
5973
5980
|
for (const [r, rd] of Object.entries(sheet.rowData ?? {})) if (rd) rowData.set(l.rows[+r], strip({ h: rd.h, hd: rd.hd, ia: rd.ia, s: typeof rd.s === "string" ? rd.s : void 0 }));
|
|
5974
5981
|
for (const [c, cd] of Object.entries(sheet.columnData ?? {})) if (cd) colData.set(l.cols[+c], strip({ w: cd.w, hd: cd.hd, s: typeof cd.s === "string" ? cd.s : void 0 }));
|
|
@@ -5983,11 +5990,11 @@ function sheetOf(doc, sid, l) {
|
|
|
5983
5990
|
const { cells, rowData, colData, merges } = pieces(m);
|
|
5984
5991
|
const rows = new Map(l.rows.map((id, i) => [id, i])), cols = new Map(l.cols.map((id, i) => [id, i]));
|
|
5985
5992
|
const cellData = {};
|
|
5986
|
-
for (const [
|
|
5987
|
-
const [row2, col] =
|
|
5993
|
+
for (const [at3, x] of cells) {
|
|
5994
|
+
const [row2, col] = at3.split(":");
|
|
5988
5995
|
const r = rows.get(row2), c = cols.get(col);
|
|
5989
5996
|
if (r === void 0 || c === void 0) continue;
|
|
5990
|
-
const kept = x.f ? values.get(`${sid}:${
|
|
5997
|
+
const kept = x.f ? values.get(`${sid}:${at3}`) : void 0;
|
|
5991
5998
|
(cellData[r] ?? (cellData[r] = {}))[c] = kept ? { ...x, v: kept.v, t: kept.t } : { ...x };
|
|
5992
5999
|
}
|
|
5993
6000
|
const rowsOut = {}, colsOut = {};
|
|
@@ -6000,7 +6007,7 @@ function sheetOf(doc, sid, l) {
|
|
|
6000
6007
|
}
|
|
6001
6008
|
var notesOf = (m, l) => {
|
|
6002
6009
|
const rows = new Map(l.rows.map((id, i) => [id, i])), cols = new Map(l.cols.map((id, i) => [id, i]));
|
|
6003
|
-
return [...pieces(m).notes].map(([
|
|
6010
|
+
return [...pieces(m).notes].map(([at3, n]) => ({ ...n, row: rows.get(at3.split(":")[0]), col: cols.get(at3.split(":")[1]) })).filter((n) => n.row !== void 0 && n.col !== void 0);
|
|
6004
6011
|
};
|
|
6005
6012
|
function build(doc) {
|
|
6006
6013
|
const { book, order: order2, sheets, styles, origin } = parts(doc);
|
|
@@ -6049,17 +6056,19 @@ function applyCells(doc, list, origin) {
|
|
|
6049
6056
|
const [r, c] = cell(x.ref);
|
|
6050
6057
|
if (!sid || r < 0) continue;
|
|
6051
6058
|
const { rows, cols, cells } = pieces(sheets.get(sid));
|
|
6052
|
-
if (r >= rows.length || c >= cols.length) continue;
|
|
6053
|
-
|
|
6059
|
+
if (r >= rows.length + 1e4 || c >= cols.length + 1e3) continue;
|
|
6060
|
+
if (r >= rows.length) rows.push(Array.from({ length: r + 1 - rows.length }, () => fresh("n")));
|
|
6061
|
+
if (c >= cols.length) cols.push(Array.from({ length: c + 1 - cols.length }, () => fresh("n")));
|
|
6062
|
+
const at3 = spot(rows.get(r), cols.get(c));
|
|
6054
6063
|
const next = {};
|
|
6055
6064
|
if (x.formula !== void 0) next.f = x.formula.startsWith("=") ? x.formula : `=${x.formula}`;
|
|
6056
6065
|
else if (typeof x.value === "boolean") Object.assign(next, { v: x.value ? 1 : 0, t: 3 });
|
|
6057
6066
|
else if (x.value !== void 0 && x.value !== null && x.value !== "") Object.assign(next, { v: x.value, t: typeof x.value === "number" ? 2 : 1 });
|
|
6058
|
-
const s = cells.get(
|
|
6067
|
+
const s = cells.get(at3)?.s;
|
|
6059
6068
|
if (s) next.s = s;
|
|
6060
|
-
values.delete(`${sid}:${
|
|
6061
|
-
if (Object.keys(next).length) cells.set(
|
|
6062
|
-
else cells.delete(
|
|
6069
|
+
values.delete(`${sid}:${at3}`);
|
|
6070
|
+
if (Object.keys(next).length) cells.set(at3, next);
|
|
6071
|
+
else cells.delete(at3);
|
|
6063
6072
|
done++;
|
|
6064
6073
|
}
|
|
6065
6074
|
}, origin);
|
|
@@ -7446,25 +7455,107 @@ var uk2 = {
|
|
|
7446
7455
|
};
|
|
7447
7456
|
var texts = { en: en2, pl: pl2, uk: uk2 };
|
|
7448
7457
|
|
|
7458
|
+
// src/sheets/agent.ts
|
|
7459
|
+
var Y2 = __toESM(require("yjs"), 1);
|
|
7460
|
+
var sheetId = (doc, name) => {
|
|
7461
|
+
const { order: order2, sheets } = parts(doc);
|
|
7462
|
+
return order2.toArray().find((id) => sheets.get(id)?.get("name") === name);
|
|
7463
|
+
};
|
|
7464
|
+
function at2(doc, x) {
|
|
7465
|
+
const sid = sheetId(doc, x.sheet);
|
|
7466
|
+
const [r, c] = cell(x.ref);
|
|
7467
|
+
if (!sid || r < 0) return void 0;
|
|
7468
|
+
const { rows, cols, cells } = pieces(parts(doc).sheets.get(sid));
|
|
7469
|
+
return r < rows.length && c < cols.length ? cells.get(spot(rows.get(r), cols.get(c))) : void 0;
|
|
7470
|
+
}
|
|
7471
|
+
var filled = (x) => !!x?.f || x?.v !== void 0 && x.v !== null && x.v !== "";
|
|
7472
|
+
var bare = (x) => x?.f ? `=${x.f}` : filled(x) ? canon([x.v, x.t ?? null]) : "";
|
|
7473
|
+
var shown = (x) => x?.f ?? (filled(x) ? String(x.v) : "");
|
|
7474
|
+
function clashes(doc, kind, seen, list) {
|
|
7475
|
+
const old = new Y2.Doc();
|
|
7476
|
+
fill2(old, readSheet(seen, kind));
|
|
7477
|
+
const out = list.filter((x) => sheetId(old, x.sheet) && bare(at2(old, x)) !== bare(at2(doc, x))).map((x) => ({ sheet: x.sheet, ref: x.ref, now: shown(at2(doc, x)) }));
|
|
7478
|
+
old.destroy();
|
|
7479
|
+
return out;
|
|
7480
|
+
}
|
|
7481
|
+
function appendRows(doc, sheet, lines2, origin) {
|
|
7482
|
+
const sid = sheetId(doc, sheet);
|
|
7483
|
+
if (!sid || !lines2.length) return null;
|
|
7484
|
+
const { rows, cells } = pieces(parts(doc).sheets.get(sid));
|
|
7485
|
+
const index = new Map(rows.toArray().map((id, i) => [id, i]));
|
|
7486
|
+
let last = -1;
|
|
7487
|
+
for (const [key2, x] of cells) if (filled(x)) last = Math.max(last, index.get(key2.split(":")[0]) ?? -1);
|
|
7488
|
+
const writes = lines2.flatMap((line, i) => line.map((x, c) => ({ sheet, ref: a1(last + 1 + i, c), ...typeof x === "string" && x.startsWith("=") ? { formula: x } : { value: x } })));
|
|
7489
|
+
applyCells(doc, writes.filter((w) => "formula" in w || w.value !== null && w.value !== ""), origin);
|
|
7490
|
+
return `${a1(last + 1, 0)}:${a1(last + lines2.length, Math.max(1, ...lines2.map((l) => l.length)) - 1)}`;
|
|
7491
|
+
}
|
|
7492
|
+
async function compute(doc, origin) {
|
|
7493
|
+
const { sheets, values } = parts(doc);
|
|
7494
|
+
const model = build(doc);
|
|
7495
|
+
const formulas2 = [];
|
|
7496
|
+
for (const sid of model.book.sheetOrder) {
|
|
7497
|
+
const l = model.lines[sid];
|
|
7498
|
+
const rows = new Map(l.rows.map((id, i) => [id, i])), cols = new Map(l.cols.map((id, i) => [id, i]));
|
|
7499
|
+
for (const [key2, x] of pieces(sheets.get(sid)).cells) {
|
|
7500
|
+
const [r, c] = key2.split(":");
|
|
7501
|
+
if (x.f && rows.has(r) && cols.has(c)) formulas2.push([sid, key2, rows.get(r), cols.get(c)]);
|
|
7502
|
+
}
|
|
7503
|
+
}
|
|
7504
|
+
if (!formulas2.length) return 0;
|
|
7505
|
+
const [{ LocaleType, LogLevel, Univer }, { FUniver }, { UniverFormulaEnginePlugin }, { UniverSheetsPlugin }, { UniverSheetsFormulaPlugin }] = await Promise.all([
|
|
7506
|
+
import("@univerjs/core"),
|
|
7507
|
+
import("@univerjs/core/facade"),
|
|
7508
|
+
import("@univerjs/engine-formula"),
|
|
7509
|
+
import("@univerjs/sheets"),
|
|
7510
|
+
import("@univerjs/sheets-formula"),
|
|
7511
|
+
import("@univerjs/engine-formula/facade"),
|
|
7512
|
+
import("@univerjs/sheets/facade")
|
|
7513
|
+
]);
|
|
7514
|
+
const univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: {} }, logLevel: LogLevel.ERROR });
|
|
7515
|
+
univer.registerPlugin(UniverFormulaEnginePlugin);
|
|
7516
|
+
univer.registerPlugin(UniverSheetsPlugin);
|
|
7517
|
+
univer.registerPlugin(UniverSheetsFormulaPlugin);
|
|
7518
|
+
try {
|
|
7519
|
+
const api = FUniver.newAPI(univer);
|
|
7520
|
+
const wb = api.createWorkbook(structuredClone(model.book));
|
|
7521
|
+
const applied = api.getFormula().onCalculationResultApplied(1e4);
|
|
7522
|
+
api.getFormula().executeCalculation();
|
|
7523
|
+
await applied;
|
|
7524
|
+
let changed2 = 0;
|
|
7525
|
+
doc.transact(() => {
|
|
7526
|
+
for (const [sid, key2, r, c] of formulas2) {
|
|
7527
|
+
const got = wb.getSheetBySheetId(sid)?.getRange(r, c).getCellData();
|
|
7528
|
+
const next = { v: got?.v ?? null, t: got?.t ?? null };
|
|
7529
|
+
if (canon(values.get(`${sid}:${key2}`)) === canon(next)) continue;
|
|
7530
|
+
values.set(`${sid}:${key2}`, next);
|
|
7531
|
+
changed2++;
|
|
7532
|
+
}
|
|
7533
|
+
}, origin);
|
|
7534
|
+
return changed2;
|
|
7535
|
+
} finally {
|
|
7536
|
+
univer.dispose();
|
|
7537
|
+
}
|
|
7538
|
+
}
|
|
7539
|
+
|
|
7449
7540
|
// src/collab.ts
|
|
7450
7541
|
var ours = "w100n-collab";
|
|
7451
7542
|
var schemas = /* @__PURE__ */ new Map();
|
|
7452
7543
|
var schemaOf = (kind) => schemas.get(kind) ?? schemas.set(kind, (0, import_core3.getSchema)(kit(kind, texts.en))).get(kind);
|
|
7453
7544
|
var parse3 = async (kind, bytes) => kind === "docx" ? (await readDocx(bytes)).doc : fromMarkdown(new TextDecoder().decode(bytes)).doc;
|
|
7454
7545
|
var edits = (tr) => tr.changedParentTypes.has(tr.doc.get("default")) || tr.changedParentTypes.has(tr.doc.get("book")) || tr.changedParentTypes.has(tr.doc.get("setup"));
|
|
7455
|
-
var
|
|
7546
|
+
var filled2 = (doc) => doc.getXmlFragment("default").length > 0 || doc.getMap("book").size > 0;
|
|
7456
7547
|
function seed(doc, kind, bytes, json) {
|
|
7457
|
-
if (
|
|
7458
|
-
const fixed = new
|
|
7548
|
+
if (filled2(doc)) return false;
|
|
7549
|
+
const fixed = new Y3.Doc();
|
|
7459
7550
|
fixed.clientID = fnv(new Uint8Array(bytes), fnv(new TextEncoder().encode(`${version}:${kind}`)));
|
|
7460
7551
|
if (kind === "xlsx" || kind === "csv") fill2(fixed, readSheet(bytes, kind));
|
|
7461
7552
|
else (0, import_y_tiptap2.prosemirrorJSONToYXmlFragment)(schemaOf(kind), json, fixed.getXmlFragment("default"));
|
|
7462
|
-
|
|
7553
|
+
Y3.applyUpdate(doc, Y3.encodeStateAsUpdate(fixed), ours);
|
|
7463
7554
|
return true;
|
|
7464
7555
|
}
|
|
7465
7556
|
function follow(doc, author) {
|
|
7466
7557
|
const editors = doc.getMap("editors");
|
|
7467
|
-
const before = (tr) => tr.meta.set("fresh", !
|
|
7558
|
+
const before = (tr) => tr.meta.set("fresh", !filled2(doc));
|
|
7468
7559
|
const after = (tr) => {
|
|
7469
7560
|
const who = !tr.meta.get("fresh") && edits(tr) ? author(tr.origin) : null;
|
|
7470
7561
|
if (who && !editors.has(who.id)) doc.transact(() => editors.set(who.id, who), ours);
|
|
@@ -7492,13 +7583,57 @@ function applyText(doc, kind, changes, origin) {
|
|
|
7492
7583
|
return false;
|
|
7493
7584
|
});
|
|
7494
7585
|
if (hits.length !== 1) throw new Refusal(`${hits.length ? "more than once" : "not"} in the document: ${c.find.slice(0, 80)}`);
|
|
7495
|
-
const [
|
|
7496
|
-
if (c.replace) step.replaceWith(
|
|
7497
|
-
else step.delete(
|
|
7586
|
+
const [at3] = hits;
|
|
7587
|
+
if (c.replace) step.replaceWith(at3, at3 + c.find.length, schema.text(c.replace, step.doc.resolve(at3 + 1).marks()));
|
|
7588
|
+
else step.delete(at3, at3 + c.find.length);
|
|
7498
7589
|
}
|
|
7499
7590
|
(0, import_y_tiptap2.updateYFragment)({ transact: (run2) => doc.transact(run2, origin) }, fragment, step.doc, { mapping: /* @__PURE__ */ new Map(), isOMark: /* @__PURE__ */ new Map() });
|
|
7500
7591
|
return changes.length;
|
|
7501
7592
|
}
|
|
7593
|
+
var bounds = (doc, heading) => {
|
|
7594
|
+
const want = heading.trim().replace(/^#+\s*/, "").toLowerCase();
|
|
7595
|
+
let at3 = -1, level = 0, end = doc.content.size, pos = 0;
|
|
7596
|
+
doc.forEach((node, offset) => {
|
|
7597
|
+
if (end !== doc.content.size) return;
|
|
7598
|
+
if (at3 < 0 && node.type.name === "heading" && node.textContent.trim().toLowerCase() === want) [at3, level, pos] = [offset, node.attrs.level, offset + node.nodeSize];
|
|
7599
|
+
else if (at3 >= 0 && node.type.name === "heading" && node.attrs.level <= level) end = offset;
|
|
7600
|
+
});
|
|
7601
|
+
if (at3 < 0) throw new Refusal(`no heading ${heading.slice(0, 80)} in the document`);
|
|
7602
|
+
return { from: pos, to: end };
|
|
7603
|
+
};
|
|
7604
|
+
function applySteps(doc, kind, steps, seen, origin) {
|
|
7605
|
+
const schema = schemaOf(kind);
|
|
7606
|
+
const fragment = doc.getXmlFragment("default");
|
|
7607
|
+
const step = new import_transform2.Transform((0, import_y_tiptap2.yXmlFragmentToProseMirrorRootNode)(fragment, schema));
|
|
7608
|
+
const old = seen && schema.nodeFromJSON(seen);
|
|
7609
|
+
const clashes2 = [];
|
|
7610
|
+
let done = 0, span2 = null;
|
|
7611
|
+
for (const s of steps) {
|
|
7612
|
+
const blocks3 = schema.nodeFromJSON(fromMarkdown(s.text).doc).content;
|
|
7613
|
+
const range = s.op === "append" ? { from: step.doc.content.size, to: step.doc.content.size } : s.op === "all" ? { from: 0, to: step.doc.content.size } : bounds(step.doc, s.heading ?? "");
|
|
7614
|
+
const was = !old || s.op === "append" ? null : s.op === "all" ? { from: 0, to: old.content.size } : (() => {
|
|
7615
|
+
try {
|
|
7616
|
+
return bounds(old, s.heading ?? "");
|
|
7617
|
+
} catch {
|
|
7618
|
+
return null;
|
|
7619
|
+
}
|
|
7620
|
+
})();
|
|
7621
|
+
if (old && was) {
|
|
7622
|
+
const now = step.doc.textBetween(range.from, range.to, "\n\n");
|
|
7623
|
+
if (old.textBetween(was.from, was.to, "\n\n") !== now) {
|
|
7624
|
+
clashes2.push({ section: s.op === "all" ? "" : s.heading ?? "", now });
|
|
7625
|
+
continue;
|
|
7626
|
+
}
|
|
7627
|
+
}
|
|
7628
|
+
const from = s.op === "after" ? range.to : range.from;
|
|
7629
|
+
if (s.op === "after") step.insert(range.to, blocks3);
|
|
7630
|
+
else step.replaceWith(range.from, range.to, blocks3);
|
|
7631
|
+
span2 = [step.doc.resolve(from).index(0), step.doc.resolve(Math.min(from + blocks3.size, step.doc.content.size)).index(0)];
|
|
7632
|
+
done++;
|
|
7633
|
+
}
|
|
7634
|
+
if (done) (0, import_y_tiptap2.updateYFragment)({ transact: (run2) => doc.transact(run2, origin) }, fragment, step.doc, { mapping: /* @__PURE__ */ new Map(), isOMark: /* @__PURE__ */ new Map() });
|
|
7635
|
+
return { done, clashes: clashes2, span: span2 };
|
|
7636
|
+
}
|
|
7502
7637
|
async function write2(kind, base, node, load2, setup) {
|
|
7503
7638
|
if (kind === "docx") return writeDocx(base, node.toJSON(), load2, setup);
|
|
7504
7639
|
const parsed = fromMarkdown(new TextDecoder().decode(base));
|
|
@@ -7507,7 +7642,7 @@ async function write2(kind, base, node, load2, setup) {
|
|
|
7507
7642
|
var blocks2 = (fragment, schema) => {
|
|
7508
7643
|
const out = [];
|
|
7509
7644
|
const walk = (parent) => parent.toArray().forEach((child) => {
|
|
7510
|
-
if (!(child instanceof
|
|
7645
|
+
if (!(child instanceof Y3.XmlElement) || !schema.nodes[child.nodeName]?.isBlock) return;
|
|
7511
7646
|
out.push(child);
|
|
7512
7647
|
walk(child);
|
|
7513
7648
|
});
|
|
@@ -7584,8 +7719,12 @@ async function workbook(doc, kind, base, put, who, note) {
|
|
|
7584
7719
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7585
7720
|
0 && (module.exports = {
|
|
7586
7721
|
Refusal,
|
|
7722
|
+
appendRows,
|
|
7587
7723
|
applyCells,
|
|
7724
|
+
applySteps,
|
|
7588
7725
|
applyText,
|
|
7726
|
+
clashes,
|
|
7727
|
+
compute,
|
|
7589
7728
|
edits,
|
|
7590
7729
|
filled,
|
|
7591
7730
|
follow,
|