@w100n/documents 0.15.1 → 0.16.1
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/Compare-M57FG4R3.js +96 -0
- package/dist/Compare-M57FG4R3.js.map +1 -0
- package/dist/{SheetView-RPQS43XY.js → SheetView-FVLKQR7J.js} +6 -4
- package/dist/{SheetView-RPQS43XY.js.map → SheetView-FVLKQR7J.js.map} +1 -1
- package/dist/{TextEditor-D6QH2B7O.js → TextEditor-BF6HCNHL.js} +500 -369
- package/dist/TextEditor-BF6HCNHL.js.map +1 -0
- package/dist/chunk-EQLBYW42.js +458 -0
- package/dist/chunk-EQLBYW42.js.map +1 -0
- package/dist/{chunk-BGH36LAR.js → chunk-GN3ZOD36.js} +87 -411
- package/dist/chunk-GN3ZOD36.js.map +1 -0
- package/dist/chunk-LZYITB56.js +1032 -0
- package/dist/chunk-LZYITB56.js.map +1 -0
- package/dist/{chunk-XR42B3F5.js → chunk-NPVH2YDI.js} +2 -2
- package/dist/{chunk-CAPICJ6B.js → chunk-ZAVXCH7V.js} +51 -1032
- package/dist/chunk-ZAVXCH7V.js.map +1 -0
- package/dist/collab.cjs +367 -200
- package/dist/collab.cjs.map +1 -1
- package/dist/collab.d.cts +1 -1
- package/dist/collab.d.ts +1 -1
- package/dist/collab.js +4 -2
- package/dist/index.cjs +1680 -1230
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +187 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +70 -15
- package/dist/index.js.map +1 -1
- package/dist/kinds.d.cts +1 -1
- package/dist/kinds.d.ts +1 -1
- package/dist/memory.cjs +25 -2
- package/dist/memory.cjs.map +1 -1
- package/dist/memory.d.cts +3 -2
- package/dist/memory.d.ts +3 -2
- package/dist/memory.js +25 -2
- package/dist/memory.js.map +1 -1
- package/dist/{types-BTsVooZw.d.cts → types-DNcaU6SK.d.cts} +9 -0
- package/dist/{types-BTsVooZw.d.ts → types-DNcaU6SK.d.ts} +9 -0
- package/package.json +1 -1
- package/dist/TextEditor-D6QH2B7O.js.map +0 -1
- package/dist/chunk-BGH36LAR.js.map +0 -1
- package/dist/chunk-CAPICJ6B.js.map +0 -1
- /package/dist/{chunk-XR42B3F5.js.map → chunk-NPVH2YDI.js.map} +0 -0
package/dist/collab.cjs
CHANGED
|
@@ -50,7 +50,7 @@ var import_y_tiptap2 = require("@tiptap/y-tiptap");
|
|
|
50
50
|
var Y2 = __toESM(require("yjs"), 1);
|
|
51
51
|
|
|
52
52
|
// package.json
|
|
53
|
-
var version = "0.
|
|
53
|
+
var version = "0.16.1";
|
|
54
54
|
|
|
55
55
|
// src/docx/xml.ts
|
|
56
56
|
function parse(s) {
|
|
@@ -187,35 +187,35 @@ function unzip(buf) {
|
|
|
187
187
|
while (eocd >= 0 && view.getUint32(eocd, true) !== 101010256) eocd--;
|
|
188
188
|
if (eocd < 0) throw new Error("Not a DOCX file");
|
|
189
189
|
const count = view.getUint16(eocd + 10, true);
|
|
190
|
-
let
|
|
191
|
-
if (count === 65535 ||
|
|
190
|
+
let at2 = view.getUint32(eocd + 16, true);
|
|
191
|
+
if (count === 65535 || at2 === 4294967295) throw new Error("ZIP64 DOCX files are not supported");
|
|
192
192
|
const names = new TextDecoder();
|
|
193
193
|
const out = [];
|
|
194
194
|
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(
|
|
195
|
+
if (view.getUint32(at2, true) !== 33639248) throw new Error("Broken DOCX file");
|
|
196
|
+
const length = view.getUint16(at2 + 28, true);
|
|
197
|
+
const extra = view.getUint16(at2 + 30, true);
|
|
198
|
+
const note = view.getUint16(at2 + 32, true);
|
|
199
|
+
const local = view.getUint32(at2 + 42, true);
|
|
200
|
+
const csize = view.getUint32(at2 + 20, true);
|
|
201
|
+
const path = buf.subarray(at2 + 46, at2 + 46 + length);
|
|
202
202
|
const begin = local + 30 + view.getUint16(local + 26, true) + view.getUint16(local + 28, true);
|
|
203
203
|
out.push({
|
|
204
204
|
name: names.decode(path),
|
|
205
205
|
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(
|
|
206
|
+
made: view.getUint16(at2 + 4, true),
|
|
207
|
+
version: view.getUint16(at2 + 6, true),
|
|
208
|
+
flags: view.getUint16(at2 + 8, true),
|
|
209
|
+
method: view.getUint16(at2 + 10, true),
|
|
210
|
+
time: view.getUint16(at2 + 12, true),
|
|
211
|
+
date: view.getUint16(at2 + 14, true),
|
|
212
|
+
crc: view.getUint32(at2 + 16, true),
|
|
213
|
+
size: view.getUint32(at2 + 24, true),
|
|
214
|
+
inner: view.getUint16(at2 + 36, true),
|
|
215
|
+
outer: view.getUint32(at2 + 38, true),
|
|
216
216
|
raw: buf.subarray(begin, begin + csize)
|
|
217
217
|
});
|
|
218
|
-
|
|
218
|
+
at2 += 46 + length + extra + note;
|
|
219
219
|
}
|
|
220
220
|
return out;
|
|
221
221
|
}
|
|
@@ -248,49 +248,49 @@ function zip(entries2) {
|
|
|
248
248
|
const buf = new Uint8Array(total);
|
|
249
249
|
const view = new DataView(buf.buffer);
|
|
250
250
|
const offsets = [];
|
|
251
|
-
let
|
|
251
|
+
let at2 = 0;
|
|
252
252
|
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 =
|
|
253
|
+
offsets.push(at2);
|
|
254
|
+
view.setUint32(at2, 67324752, true);
|
|
255
|
+
view.setUint16(at2 + 4, e.version, true);
|
|
256
|
+
view.setUint16(at2 + 6, e.flags & ~8, true);
|
|
257
|
+
view.setUint16(at2 + 8, e.method, true);
|
|
258
|
+
view.setUint16(at2 + 10, e.time, true);
|
|
259
|
+
view.setUint16(at2 + 12, e.date, true);
|
|
260
|
+
view.setUint32(at2 + 14, e.crc, true);
|
|
261
|
+
view.setUint32(at2 + 18, e.raw.length, true);
|
|
262
|
+
view.setUint32(at2 + 22, e.size, true);
|
|
263
|
+
view.setUint16(at2 + 26, e.path.length, true);
|
|
264
|
+
view.setUint16(at2 + 28, 0, true);
|
|
265
|
+
buf.set(e.path, at2 + 30);
|
|
266
|
+
buf.set(e.raw, at2 + 30 + e.path.length);
|
|
267
|
+
at2 += 30 + e.path.length + e.raw.length;
|
|
268
|
+
}
|
|
269
|
+
const start = at2;
|
|
270
270
|
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
|
-
|
|
271
|
+
view.setUint32(at2, 33639248, true);
|
|
272
|
+
view.setUint16(at2 + 4, e.made, true);
|
|
273
|
+
view.setUint16(at2 + 6, e.version, true);
|
|
274
|
+
view.setUint16(at2 + 8, e.flags & ~8, true);
|
|
275
|
+
view.setUint16(at2 + 10, e.method, true);
|
|
276
|
+
view.setUint16(at2 + 12, e.time, true);
|
|
277
|
+
view.setUint16(at2 + 14, e.date, true);
|
|
278
|
+
view.setUint32(at2 + 16, e.crc, true);
|
|
279
|
+
view.setUint32(at2 + 20, e.raw.length, true);
|
|
280
|
+
view.setUint32(at2 + 24, e.size, true);
|
|
281
|
+
view.setUint16(at2 + 28, e.path.length, true);
|
|
282
|
+
view.setUint16(at2 + 36, e.inner, true);
|
|
283
|
+
view.setUint32(at2 + 38, e.outer, true);
|
|
284
|
+
view.setUint32(at2 + 42, offsets[n], true);
|
|
285
|
+
buf.set(e.path, at2 + 46);
|
|
286
|
+
at2 += 46 + e.path.length;
|
|
287
287
|
});
|
|
288
|
-
view.setUint32(
|
|
289
|
-
view.setUint16(
|
|
290
|
-
view.setUint16(
|
|
291
|
-
view.setUint32(
|
|
292
|
-
view.setUint32(
|
|
293
|
-
return buf.subarray(0,
|
|
288
|
+
view.setUint32(at2, 101010256, true);
|
|
289
|
+
view.setUint16(at2 + 8, entries2.length, true);
|
|
290
|
+
view.setUint16(at2 + 10, entries2.length, true);
|
|
291
|
+
view.setUint32(at2 + 12, at2 - start, true);
|
|
292
|
+
view.setUint32(at2 + 16, start, true);
|
|
293
|
+
return buf.subarray(0, at2 + 22);
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
// src/docx/pkg.ts
|
|
@@ -1542,10 +1542,10 @@ function diff(a, b) {
|
|
|
1542
1542
|
if (x >= n && y >= m) {
|
|
1543
1543
|
for (let e = d; e > 0; e--) {
|
|
1544
1544
|
const t = trace[e];
|
|
1545
|
-
const
|
|
1546
|
-
const down2 = k === -e || k !== e &&
|
|
1545
|
+
const at2 = (j) => t[j + e + 1];
|
|
1546
|
+
const down2 = k === -e || k !== e && at2(k - 1) < at2(k + 1);
|
|
1547
1547
|
const pk = down2 ? k + 1 : k - 1;
|
|
1548
|
-
const px2 =
|
|
1548
|
+
const px2 = at2(pk);
|
|
1549
1549
|
const py = px2 - pk;
|
|
1550
1550
|
while (x > px2 && y > py) map[p + --y] = p + --x;
|
|
1551
1551
|
x = px2;
|
|
@@ -1712,10 +1712,10 @@ function checked(xml, on2) {
|
|
|
1712
1712
|
const no = /w14:uncheckedState\b[^>]*w14:val="([0-9A-Fa-f]+)"/.exec(xml)?.[1] ?? "2610";
|
|
1713
1713
|
const [from, to] = on2 ? [no, yes] : [yes, no];
|
|
1714
1714
|
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,
|
|
1715
|
+
const at2 = out.indexOf("<w:sdtContent");
|
|
1716
|
+
if (at2 === -1) return out;
|
|
1717
|
+
const tail = out.slice(at2).replace(new RegExp(`w:char="${from}"`, "i"), `w:char="${to}"`).replace(`>${String.fromCharCode(parseInt(from, 16))}<`, `>${String.fromCharCode(parseInt(to, 16))}<`);
|
|
1718
|
+
out = out.slice(0, at2) + tail;
|
|
1719
1719
|
return out;
|
|
1720
1720
|
}
|
|
1721
1721
|
var Writer = class {
|
|
@@ -1781,9 +1781,9 @@ var Writer = class {
|
|
|
1781
1781
|
<w:numbering xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"></w:numbering>`;
|
|
1782
1782
|
this.types.add(`<Override PartName="/${path}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"/>`);
|
|
1783
1783
|
}
|
|
1784
|
-
const
|
|
1784
|
+
const at2 = n.search(/<w:num\b[\s>]/);
|
|
1785
1785
|
const abs = this.numbering.abs.join("");
|
|
1786
|
-
n =
|
|
1786
|
+
n = at2 === -1 ? n.replace(/(<w:numIdMacAtCleanup\b|<\/w:numbering>)/, abs + "$1") : n.slice(0, at2) + abs + n.slice(at2);
|
|
1787
1787
|
n = n.replace(/(<w:numIdMacAtCleanup\b|<\/w:numbering>)/, this.numbering.nums.join("") + "$1");
|
|
1788
1788
|
changed2.set(path, n);
|
|
1789
1789
|
if (!rel) {
|
|
@@ -1796,8 +1796,8 @@ var Writer = class {
|
|
|
1796
1796
|
const settings = this.tocs && this.pkg.byType("/settings");
|
|
1797
1797
|
const listed2 = settings && this.pkg.text(settings.target);
|
|
1798
1798
|
if (settings && listed2 && !/<w:updateFields\b/.test(listed2)) {
|
|
1799
|
-
const
|
|
1800
|
-
changed2.set(settings.target, listed2.slice(0,
|
|
1799
|
+
const at2 = 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>/);
|
|
1800
|
+
changed2.set(settings.target, listed2.slice(0, at2) + '<w:updateFields w:val="true"/>' + listed2.slice(at2));
|
|
1801
1801
|
}
|
|
1802
1802
|
if (this.styleXml.length) {
|
|
1803
1803
|
const rel = this.pkg.byType("/styles");
|
|
@@ -1897,20 +1897,20 @@ var Writer = class {
|
|
|
1897
1897
|
return ++this.lastNote;
|
|
1898
1898
|
}
|
|
1899
1899
|
footnotes(doc, changed2) {
|
|
1900
|
-
const
|
|
1900
|
+
const notes3 = [];
|
|
1901
1901
|
const walk = (n) => {
|
|
1902
|
-
if (n.type === "footnote" && n.attrs?.id)
|
|
1902
|
+
if (n.type === "footnote" && n.attrs?.id) notes3.push({ id: String(n.attrs.id), text: String(n.attrs.text ?? "") });
|
|
1903
1903
|
n.content?.forEach(walk);
|
|
1904
1904
|
};
|
|
1905
1905
|
walk(doc);
|
|
1906
1906
|
const rel = this.pkg.byType("/footnotes");
|
|
1907
1907
|
const old = rel ? this.pkg.text(rel.target) : null;
|
|
1908
|
-
if (!
|
|
1908
|
+
if (!notes3.length) return;
|
|
1909
1909
|
const path = rel ? rel.target : "word/footnotes.xml";
|
|
1910
1910
|
let xml = old ?? `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
1911
1911
|
<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
1912
|
const fresh = (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
|
-
for (const n of
|
|
1913
|
+
for (const n of notes3) {
|
|
1914
1914
|
const found = new RegExp(`<w:footnote\\b[^>]*\\bw:id="${n.id}"[^>]*>([\\s\\S]*?)</w:footnote>`).exec(xml);
|
|
1915
1915
|
if (found && noteText(found[1]) === n.text) continue;
|
|
1916
1916
|
xml = found ? xml.replace(found[0], fresh(n.id, n.text)) : xml.replace(/<\/w:footnotes>\s*$/, fresh(n.id, n.text) + "</w:footnotes>");
|
|
@@ -1957,8 +1957,8 @@ var Writer = class {
|
|
|
1957
1957
|
sec = sec.replace(re, xml);
|
|
1958
1958
|
return;
|
|
1959
1959
|
}
|
|
1960
|
-
const
|
|
1961
|
-
const i =
|
|
1960
|
+
const at2 = before.map((b) => sec.search(new RegExp(`<${b}[\\s>/]`))).filter((i2) => i2 >= 0);
|
|
1961
|
+
const i = at2.length ? Math.min(...at2) : sec.lastIndexOf("</w:sectPr>");
|
|
1962
1962
|
sec = sec.slice(0, i) + xml + sec.slice(i);
|
|
1963
1963
|
};
|
|
1964
1964
|
const tw = (px2) => Math.round(px2 * 15);
|
|
@@ -2223,11 +2223,11 @@ var Writer = class {
|
|
|
2223
2223
|
}
|
|
2224
2224
|
const slot = new Int32Array(A.length + 1);
|
|
2225
2225
|
for (let k = 1; k <= A.length; k++) slot[k] = back[k - 1] >= 0 ? back[k - 1] + 1 : slot[k - 1];
|
|
2226
|
-
const
|
|
2226
|
+
const at2 = Array.from({ length: B.length + 1 }, () => []);
|
|
2227
2227
|
let chars = 0;
|
|
2228
2228
|
for (const u of units) {
|
|
2229
2229
|
if (u.ch !== null) chars++;
|
|
2230
|
-
else if (!u.box || o.task !== null)
|
|
2230
|
+
else if (!u.box || o.task !== null) at2[slot[chars]].push(u);
|
|
2231
2231
|
}
|
|
2232
2232
|
const paraBase = b ? this.markRun(b) : this.firstRun(src);
|
|
2233
2233
|
const out = [];
|
|
@@ -2241,7 +2241,7 @@ var Writer = class {
|
|
|
2241
2241
|
const next = new Int32Array(B.length + 1).fill(-1);
|
|
2242
2242
|
for (let k = B.length - 1; k >= 0; k--) next[k] = map[k] >= 0 ? map[k] : next[k + 1];
|
|
2243
2243
|
for (let j = 0; j <= B.length; j++) {
|
|
2244
|
-
for (const u of
|
|
2244
|
+
for (const u of at2[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
2245
|
if (j === B.length) break;
|
|
2246
2246
|
const i = map[j];
|
|
2247
2247
|
const want = B[j];
|
|
@@ -2342,8 +2342,8 @@ var Writer = class {
|
|
|
2342
2342
|
wrap = { open: tag, close: "</w:hyperlink>", link, ins: false };
|
|
2343
2343
|
this.wraps.set(link, wrap);
|
|
2344
2344
|
}
|
|
2345
|
-
const
|
|
2346
|
-
return
|
|
2345
|
+
const at2 = out.findIndex((w) => w.ins);
|
|
2346
|
+
return at2 === -1 ? [...out, wrap] : [...out.slice(0, at2), wrap, ...out.slice(at2)];
|
|
2347
2347
|
}
|
|
2348
2348
|
revised(ctx, rev) {
|
|
2349
2349
|
const out = ctx.filter((w) => !w.rev || w.rev === rev);
|
|
@@ -2730,7 +2730,7 @@ function measure(view) {
|
|
|
2730
2730
|
const gaps = [];
|
|
2731
2731
|
const line = page.width - page.margins[1] - page.margins[3];
|
|
2732
2732
|
const area = (list) => list.length ? 14 + list.reduce((h, text) => h + 15 * Math.max(1, Math.ceil(text.length * 5.6 / line)), 0) : 0;
|
|
2733
|
-
let
|
|
2733
|
+
let notes3 = [];
|
|
2734
2734
|
let count = 0;
|
|
2735
2735
|
let i = 0;
|
|
2736
2736
|
let shift = 0;
|
|
@@ -2750,20 +2750,20 @@ function measure(view) {
|
|
|
2750
2750
|
if (d.type.name === "footnote") mine.push(`${count + mine.length + 1} ${d.attrs.text}`);
|
|
2751
2751
|
});
|
|
2752
2752
|
if (node.type.name === "pageBreak") {
|
|
2753
|
-
gaps.push({ pos: offset + node.nodeSize, height: start + room - end + bottom + 24 + top, page: gaps.length + 1, notes:
|
|
2754
|
-
|
|
2753
|
+
gaps.push({ pos: offset + node.nodeSize, height: start + room - end + bottom + 24 + top, page: gaps.length + 1, notes: notes3 });
|
|
2754
|
+
notes3 = [];
|
|
2755
2755
|
start = end;
|
|
2756
|
-
} else if (end > start + room - area([...
|
|
2757
|
-
gaps.push({ pos: offset, height: start + room - y + bottom + 24 + top, page: gaps.length + 1, notes:
|
|
2758
|
-
|
|
2756
|
+
} else if (end > start + room - area([...notes3, ...mine]) && y > start) {
|
|
2757
|
+
gaps.push({ pos: offset, height: start + room - y + bottom + 24 + top, page: gaps.length + 1, notes: notes3 });
|
|
2758
|
+
notes3 = [];
|
|
2759
2759
|
start = y;
|
|
2760
2760
|
}
|
|
2761
|
-
|
|
2761
|
+
notes3.push(...mine);
|
|
2762
2762
|
count += mine.length;
|
|
2763
2763
|
while (end > start + room) start += room;
|
|
2764
2764
|
last = end;
|
|
2765
2765
|
});
|
|
2766
|
-
gaps.push({ pos: view.state.doc.content.size, height: Math.max(0, start + room - last), page: gaps.length + 1, end: true, notes:
|
|
2766
|
+
gaps.push({ pos: view.state.doc.content.size, height: Math.max(0, start + room - last), page: gaps.length + 1, end: true, notes: notes3 });
|
|
2767
2767
|
return gaps.map((g) => ({ ...g, height: Math.max(0, Math.round(g.height)) }));
|
|
2768
2768
|
}
|
|
2769
2769
|
var Pager = import_core.Extension.create({
|
|
@@ -2771,10 +2771,10 @@ var Pager = import_core.Extension.create({
|
|
|
2771
2771
|
addProseMirrorPlugins: () => [new import_state.Plugin({
|
|
2772
2772
|
key: paging,
|
|
2773
2773
|
state: {
|
|
2774
|
-
init: () => ({ set: import_view.DecorationSet.empty, page: a4, marks: { header: "", footer: "" } }),
|
|
2774
|
+
init: () => ({ set: import_view.DecorationSet.empty, page: a4, marks: { header: "", footer: "" }, flow: false }),
|
|
2775
2775
|
apply(tr, value3) {
|
|
2776
2776
|
const next = tr.getMeta(paging);
|
|
2777
|
-
return { set: next?.set ?? value3.set.map(tr.mapping, tr.doc), page: next?.page ?? value3.page, marks: next?.marks ?? value3.marks };
|
|
2777
|
+
return { set: next?.set ?? value3.set.map(tr.mapping, tr.doc), page: next?.page ?? value3.page, marks: next?.marks ?? value3.marks, flow: next?.flow ?? value3.flow };
|
|
2778
2778
|
}
|
|
2779
2779
|
},
|
|
2780
2780
|
props: { decorations: (state) => paging.getState(state).set },
|
|
@@ -2783,8 +2783,13 @@ var Pager = import_core.Extension.create({
|
|
|
2783
2783
|
let sig2 = "";
|
|
2784
2784
|
const run2 = () => {
|
|
2785
2785
|
if (!view.dom.isConnected) return;
|
|
2786
|
+
const { marks, flow } = paging.getState(view.state);
|
|
2787
|
+
if (flow) {
|
|
2788
|
+
if (sig2 !== "flow") view.dispatch(view.state.tr.setMeta(paging, { set: import_view.DecorationSet.empty }).setMeta("addToHistory", false));
|
|
2789
|
+
sig2 = "flow";
|
|
2790
|
+
return;
|
|
2791
|
+
}
|
|
2786
2792
|
const gaps = measure(view);
|
|
2787
|
-
const { marks } = paging.getState(view.state);
|
|
2788
2793
|
const next = gaps.map((g) => `${g.pos}:${g.height}:${g.notes.join("\n")}`).join() + `|${marks.header}|${marks.footer}`;
|
|
2789
2794
|
if (next === sig2) return;
|
|
2790
2795
|
sig2 = next;
|
|
@@ -2835,7 +2840,8 @@ var Pager = import_core.Extension.create({
|
|
|
2835
2840
|
later(0);
|
|
2836
2841
|
return {
|
|
2837
2842
|
update: (next, prev) => {
|
|
2838
|
-
|
|
2843
|
+
const now = paging.getState(next.state), was = paging.getState(prev);
|
|
2844
|
+
if (now.page !== was.page || now.marks !== was.marks || now.flow !== was.flow) later(0);
|
|
2839
2845
|
else if (next.state.doc !== prev.doc) later(400);
|
|
2840
2846
|
},
|
|
2841
2847
|
destroy: () => {
|
|
@@ -2893,14 +2899,14 @@ var lookup = (doc, query, matchCase) => {
|
|
|
2893
2899
|
doc.descendants((node, pos) => {
|
|
2894
2900
|
if (!node.isTextblock) return true;
|
|
2895
2901
|
let text = "";
|
|
2896
|
-
const
|
|
2902
|
+
const at2 = [];
|
|
2897
2903
|
node.forEach((child, offset) => {
|
|
2898
2904
|
const part = child.isText ? child.text : "\uFFFC";
|
|
2899
|
-
for (let i = 0; i < part.length; i++)
|
|
2905
|
+
for (let i = 0; i < part.length; i++) at2.push(pos + 1 + offset + i);
|
|
2900
2906
|
text += part;
|
|
2901
2907
|
});
|
|
2902
2908
|
const hay = matchCase ? text : text.toLowerCase();
|
|
2903
|
-
for (let i = hay.indexOf(needle); i >= 0; i = hay.indexOf(needle, i + needle.length)) hits.push({ from:
|
|
2909
|
+
for (let i = hay.indexOf(needle); i >= 0; i = hay.indexOf(needle, i + needle.length)) hits.push({ from: at2[i], to: at2[i + needle.length - 1] + 1 });
|
|
2904
2910
|
return false;
|
|
2905
2911
|
});
|
|
2906
2912
|
return hits;
|
|
@@ -2916,8 +2922,8 @@ var Search = import_core2.Extension.create({
|
|
|
2916
2922
|
if (!meta2 && !tr.docChanged) return value3;
|
|
2917
2923
|
const next = { ...value3, ...meta2 };
|
|
2918
2924
|
const hits = lookup(tr.doc, next.query, next.matchCase);
|
|
2919
|
-
const
|
|
2920
|
-
return { ...next, hits, at, set: import_view2.DecorationSet.create(tr.doc, hits.map((h, i) => import_view2.Decoration.inline(h.from, h.to, { class: i ===
|
|
2925
|
+
const at2 = hits.length ? (next.at % hits.length + hits.length) % hits.length : 0;
|
|
2926
|
+
return { ...next, hits, at: at2, set: import_view2.DecorationSet.create(tr.doc, hits.map((h, i) => import_view2.Decoration.inline(h.from, h.to, { class: i === at2 ? "w100n-found is-current" : "w100n-found" }))) };
|
|
2921
2927
|
}
|
|
2922
2928
|
},
|
|
2923
2929
|
props: { decorations: (state) => searching.getState(state).set }
|
|
@@ -2962,12 +2968,12 @@ var Blocks = import_core2.Extension.create({
|
|
|
2962
2968
|
for (let i = start; i < end; i++) {
|
|
2963
2969
|
const top = state.doc.child(i);
|
|
2964
2970
|
visit(top, pos);
|
|
2965
|
-
top.descendants((node,
|
|
2971
|
+
top.descendants((node, at2) => visit(node, pos + 1 + at2));
|
|
2966
2972
|
pos += top.nodeSize;
|
|
2967
2973
|
}
|
|
2968
2974
|
if (!drop.length) return null;
|
|
2969
2975
|
const tr = state.tr;
|
|
2970
|
-
for (const
|
|
2976
|
+
for (const at2 of drop) tr.setNodeAttribute(at2, "ref", null);
|
|
2971
2977
|
return tr;
|
|
2972
2978
|
}
|
|
2973
2979
|
})]
|
|
@@ -3014,6 +3020,31 @@ var Footnote = import_core2.Node.create({
|
|
|
3014
3020
|
parseHTML: () => [{ tag: "sup[data-footnote]" }],
|
|
3015
3021
|
renderHTML: ({ node }) => ["sup", { "data-footnote": "", "data-note-id": node.attrs.id ?? void 0, title: node.attrs.text, class: "w100n-fn", contenteditable: "false" }]
|
|
3016
3022
|
});
|
|
3023
|
+
var EndNotes = import_core2.Extension.create({
|
|
3024
|
+
name: "endNotes",
|
|
3025
|
+
addProseMirrorPlugins: () => [new import_state2.Plugin({
|
|
3026
|
+
props: {
|
|
3027
|
+
decorations(state) {
|
|
3028
|
+
const notes3 = [];
|
|
3029
|
+
state.doc.descendants((n) => {
|
|
3030
|
+
if (n.type.name === "footnote") notes3.push(n.attrs.text);
|
|
3031
|
+
});
|
|
3032
|
+
if (!notes3.length) return null;
|
|
3033
|
+
return import_view2.DecorationSet.create(state.doc, [import_view2.Decoration.widget(state.doc.content.size, () => {
|
|
3034
|
+
const list = document.createElement("div");
|
|
3035
|
+
list.className = "w100n-text-endnotes";
|
|
3036
|
+
list.contentEditable = "false";
|
|
3037
|
+
notes3.forEach((text, i) => {
|
|
3038
|
+
const p = list.appendChild(document.createElement("p"));
|
|
3039
|
+
p.appendChild(document.createElement("sup")).textContent = String(i + 1);
|
|
3040
|
+
p.append(text);
|
|
3041
|
+
});
|
|
3042
|
+
return list;
|
|
3043
|
+
}, { key: notes3.join("\n"), side: 1, ignoreSelection: true })]);
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
})]
|
|
3047
|
+
});
|
|
3017
3048
|
var headings = (doc, after) => {
|
|
3018
3049
|
const found = [];
|
|
3019
3050
|
doc.descendants((node, pos) => {
|
|
@@ -3044,8 +3075,8 @@ var Toc = import_core2.Node.create({
|
|
|
3044
3075
|
dom.className = "w100n-text-toc";
|
|
3045
3076
|
dom.contentEditable = "false";
|
|
3046
3077
|
const paint2 = () => {
|
|
3047
|
-
const
|
|
3048
|
-
const list = entries(editor.state.doc, this.options.relative,
|
|
3078
|
+
const at2 = getPos() ?? 0;
|
|
3079
|
+
const list = entries(editor.state.doc, this.options.relative, at2);
|
|
3049
3080
|
const head = document.createElement("b");
|
|
3050
3081
|
head.textContent = this.options.label;
|
|
3051
3082
|
const items = list.map(([level, text], i) => {
|
|
@@ -3080,13 +3111,13 @@ var Toc = import_core2.Node.create({
|
|
|
3080
3111
|
return [new import_state2.Plugin({
|
|
3081
3112
|
appendTransaction(trs, _old, state) {
|
|
3082
3113
|
if (!trs.some((tr2) => tr2.docChanged && !tr2.getMeta(import_y_tiptap.ySyncPluginKey))) return null;
|
|
3083
|
-
const
|
|
3114
|
+
const at2 = [];
|
|
3084
3115
|
state.doc.forEach((node, pos) => {
|
|
3085
|
-
if (node.type.name === "toc")
|
|
3116
|
+
if (node.type.name === "toc") at2.push(pos);
|
|
3086
3117
|
});
|
|
3087
|
-
if (!
|
|
3118
|
+
if (!at2.length) return null;
|
|
3088
3119
|
const tr = state.tr;
|
|
3089
|
-
for (const pos of
|
|
3120
|
+
for (const pos of at2) {
|
|
3090
3121
|
const fresh = JSON.stringify(entries(state.doc, relative2, pos));
|
|
3091
3122
|
if (state.doc.nodeAt(pos).attrs.entries !== fresh) tr.setNodeAttribute(pos, "entries", fresh);
|
|
3092
3123
|
}
|
|
@@ -3129,10 +3160,10 @@ var Suggest = import_core2.Extension.create({
|
|
|
3129
3160
|
const { state } = view;
|
|
3130
3161
|
const tr = state.tr;
|
|
3131
3162
|
if (to > from) strike(tr, state, from, to);
|
|
3132
|
-
const
|
|
3163
|
+
const at2 = tr.mapping.map(to);
|
|
3133
3164
|
const kept = (state.storedMarks ?? state.doc.resolve(from).marks()).filter((m) => m.type.name !== "insertion" && m.type.name !== "deletion");
|
|
3134
|
-
tr.insert(
|
|
3135
|
-
tr.setSelection(import_state2.TextSelection.create(tr.doc,
|
|
3165
|
+
tr.insert(at2, state.schema.text(text, [...kept, stamp(state, "insertion", from, to)]));
|
|
3166
|
+
tr.setSelection(import_state2.TextSelection.create(tr.doc, at2 + text.length));
|
|
3136
3167
|
view.dispatch(tr.scrollIntoView());
|
|
3137
3168
|
return true;
|
|
3138
3169
|
};
|
|
@@ -3156,16 +3187,16 @@ var Suggest = import_core2.Extension.create({
|
|
|
3156
3187
|
if (!suggesting.getState(state).on || event.key !== "Backspace" && event.key !== "Delete" || event.metaKey || event.ctrlKey || event.altKey) return false;
|
|
3157
3188
|
const { from, to, empty, $from } = state.selection;
|
|
3158
3189
|
const back = event.key === "Backspace";
|
|
3159
|
-
let
|
|
3190
|
+
let at2 = from;
|
|
3160
3191
|
if (empty) {
|
|
3161
3192
|
const skip2 = (pos) => state.doc.resolve(pos)[back ? "nodeBefore" : "nodeAfter"]?.marks.some((m) => m.type.name === "deletion");
|
|
3162
|
-
while (skip2(
|
|
3163
|
-
if (back ?
|
|
3193
|
+
while (skip2(at2)) at2 += back ? -1 : 1;
|
|
3194
|
+
if (back ? at2 <= $from.start() : at2 >= $from.end()) return false;
|
|
3164
3195
|
}
|
|
3165
3196
|
const tr = state.tr;
|
|
3166
|
-
if (empty) strike(tr, state, back ?
|
|
3197
|
+
if (empty) strike(tr, state, back ? at2 - 1 : at2, back ? at2 : at2 + 1);
|
|
3167
3198
|
else strike(tr, state, from, to);
|
|
3168
|
-
const caret = empty ? tr.mapping.map(back ?
|
|
3199
|
+
const caret = empty ? tr.mapping.map(back ? at2 - 1 : at2 + 1, back ? -1 : 1) : tr.mapping.map(back ? from : to);
|
|
3169
3200
|
tr.setSelection(import_state2.TextSelection.create(tr.doc, caret));
|
|
3170
3201
|
view.dispatch(tr.scrollIntoView());
|
|
3171
3202
|
return true;
|
|
@@ -3237,10 +3268,10 @@ var Locks = import_core2.Extension.create({
|
|
|
3237
3268
|
const { $from, empty } = view.state.selection;
|
|
3238
3269
|
if (!back && event.key !== "Delete" || !empty || $from.depth < 1) return false;
|
|
3239
3270
|
if (back ? $from.parentOffset !== 0 : $from.parentOffset !== $from.parent.content.size) return false;
|
|
3240
|
-
const
|
|
3241
|
-
const node = back ? view.state.doc.resolve(
|
|
3271
|
+
const at2 = back ? $from.before() : $from.after();
|
|
3272
|
+
const node = back ? view.state.doc.resolve(at2).nodeBefore : view.state.doc.resolve(at2).nodeAfter;
|
|
3242
3273
|
if (!node || !locked(node)) return false;
|
|
3243
|
-
view.dispatch(view.state.tr.delete(back ?
|
|
3274
|
+
view.dispatch(view.state.tr.delete(back ? at2 - node.nodeSize : at2, back ? at2 : at2 + node.nodeSize));
|
|
3244
3275
|
return true;
|
|
3245
3276
|
}
|
|
3246
3277
|
}
|
|
@@ -3311,7 +3342,10 @@ function kit(kind, t, live) {
|
|
|
3311
3342
|
Toc.configure({ relative: kind === "markdown", label: t.toc, empty: t.tocEmpty }),
|
|
3312
3343
|
Note,
|
|
3313
3344
|
Notes,
|
|
3314
|
-
|
|
3345
|
+
Formula,
|
|
3346
|
+
Footnote,
|
|
3347
|
+
EndNotes,
|
|
3348
|
+
...kind === "docx" ? [Pager, Locks.configure({ label: t.locked }), revision("insertion", "ins"), revision("deletion", "del"), Suggest] : [],
|
|
3315
3349
|
...live ? [import_extension_collaboration.default.configure({ document: live.doc }), import_extension_collaboration_caret.default.configure({ provider: live.link, user: live.user })] : []
|
|
3316
3350
|
];
|
|
3317
3351
|
}
|
|
@@ -3319,6 +3353,28 @@ function kit(kind, t, live) {
|
|
|
3319
3353
|
// src/editor/markdown.ts
|
|
3320
3354
|
var import_marked = require("marked");
|
|
3321
3355
|
var import_prosemirror_markdown = require("prosemirror-markdown");
|
|
3356
|
+
var def = /^\[\^([^\]\s]+)\]:[ \t]*([^\n]*(?:\n {4}[^\n]*)*)(?:\n|$)/;
|
|
3357
|
+
var defs = new RegExp(def.source.slice(1), "gm");
|
|
3358
|
+
var noteOf = (text) => text.replace(/\n {4}/g, "\n").trim();
|
|
3359
|
+
var at = (src, find3) => {
|
|
3360
|
+
const i = src.search(find3);
|
|
3361
|
+
return i < 0 ? void 0 : i;
|
|
3362
|
+
};
|
|
3363
|
+
var marked = new import_marked.Marked({ extensions: [
|
|
3364
|
+
{ name: "footnoteDef", level: "block", start: (src) => at(src, /^\[\^/m), tokenizer(src) {
|
|
3365
|
+
const m = def.exec(src);
|
|
3366
|
+
return m ? { type: "footnoteDef", raw: m[0], id: m[1], text: noteOf(m[2]) } : void 0;
|
|
3367
|
+
} },
|
|
3368
|
+
{ name: "footnoteRef", level: "inline", start: (src) => at(src, /\[\^/), tokenizer(src) {
|
|
3369
|
+
const m = /^\[\^([^\]\s]+)\]/.exec(src);
|
|
3370
|
+
return m ? { type: "footnoteRef", raw: m[0], id: m[1] } : void 0;
|
|
3371
|
+
} },
|
|
3372
|
+
{ name: "math", level: "inline", start: (src) => at(src, /\$/), tokenizer(src) {
|
|
3373
|
+
const m = /^\$\$([^$]+?)\$\$|^\$(?![\s$])((?:\\.|[^$\\\n])*?[^\s\\])\$(?!\d)/.exec(src);
|
|
3374
|
+
return m ? { type: "math", raw: m[0], text: (m[1] ?? m[2]).trim() } : void 0;
|
|
3375
|
+
} }
|
|
3376
|
+
] });
|
|
3377
|
+
var notes2 = /* @__PURE__ */ new Map();
|
|
3322
3378
|
var tags = { u: "underline", ins: "underline", mark: "highlight", s: "strike", del: "strike", b: "bold", strong: "bold", i: "italic", em: "italic" };
|
|
3323
3379
|
var decode = (text) => text.includes("&") ? new DOMParser().parseFromString(`<p>${text.replace(/</g, "<")}</p>`, "text/html").body.textContent ?? text : text;
|
|
3324
3380
|
var unique = (marks) => [...new Map(marks.map((m) => [m.type, m])).values()];
|
|
@@ -3342,6 +3398,8 @@ function inline2(tokens = [], outer = []) {
|
|
|
3342
3398
|
else if (token2.type === "del") wrap(token2.tokens, { type: "strike" });
|
|
3343
3399
|
else if (token2.type === "codespan") text(token2.text, [{ type: "code" }]);
|
|
3344
3400
|
else if (token2.type === "br") out.push({ type: "hardBreak" });
|
|
3401
|
+
else if (token2.type === "math") out.push({ type: "math", attrs: { latex: token2.text } });
|
|
3402
|
+
else if (token2.type === "footnoteRef") out.push({ type: "footnote", attrs: { id: token2.id, text: notes2.get(token2.id) ?? "" } });
|
|
3345
3403
|
else if (token2.type === "link") wrap(token2.tokens, { type: "link", attrs: { href: token2.href } });
|
|
3346
3404
|
else if (token2.type === "image") out.push({ type: "image", attrs: { src: token2.href, alt: token2.text || null, title: token2.title || null }, ...marks().length ? { marks: marks() } : {} });
|
|
3347
3405
|
else if (token2.type === "html") {
|
|
@@ -3365,7 +3423,15 @@ function block(token2, hints) {
|
|
|
3365
3423
|
case "space":
|
|
3366
3424
|
case "def":
|
|
3367
3425
|
case "checkbox":
|
|
3426
|
+
case "footnoteDef":
|
|
3368
3427
|
return [];
|
|
3428
|
+
case "html": {
|
|
3429
|
+
const m = /^\s*<(p|h[1-6])\s+align="(center|right|justify)"\s*>([\s\S]*?)<\/\1>\s*$/i.exec(token2.raw);
|
|
3430
|
+
if (!m) return [{ type: "codeBlock", attrs: { language: "html" }, content: [{ type: "text", text: token2.raw.replace(/\n+$/, "") }] }];
|
|
3431
|
+
const content = inline2(marked.Lexer.lexInline(m[3].trim(), marked.defaults));
|
|
3432
|
+
const level = Number(m[1][1]);
|
|
3433
|
+
return [level ? { type: "heading", attrs: { level, align: m[2] }, content } : { type: "paragraph", attrs: { align: m[2] }, content }];
|
|
3434
|
+
}
|
|
3369
3435
|
case "heading":
|
|
3370
3436
|
return [{ type: "heading", attrs: { level: token2.depth }, content: inline2(token2.tokens) }];
|
|
3371
3437
|
case "paragraph":
|
|
@@ -3377,8 +3443,6 @@ function block(token2, hints) {
|
|
|
3377
3443
|
const fence = /^ {0,3}(`{3,}|~{3,})/.exec(token2.raw)?.[1][0];
|
|
3378
3444
|
return [{ type: "codeBlock", attrs: { language: token2.lang || null, ref: fence ? ref({ fence: fence.repeat(3) }) : null }, content: token2.text ? [{ type: "text", text: token2.text }] : [] }];
|
|
3379
3445
|
}
|
|
3380
|
-
case "html":
|
|
3381
|
-
return [{ type: "codeBlock", attrs: { language: "html" }, content: [{ type: "text", text: token2.raw.replace(/\n+$/, "") }] }];
|
|
3382
3446
|
case "hr":
|
|
3383
3447
|
return [{ type: "horizontalRule" }];
|
|
3384
3448
|
case "list": {
|
|
@@ -3411,6 +3475,21 @@ function block(token2, hints) {
|
|
|
3411
3475
|
var opens = /^\s*<!--\s*toc\s*-->\s*$/i;
|
|
3412
3476
|
var shuts = /^\s*<!--\s*\/toc\s*-->\s*$/i;
|
|
3413
3477
|
var row = /^(\s*)[-*+]\s+\[((?:\\.|[^\]\\])*)\]\(#[^)\s]*\)\s*$/;
|
|
3478
|
+
function aligned(tokens, i, hints) {
|
|
3479
|
+
const m = tokens[i].type === "html" ? /^\s*<div\s+align="(center|right|justify)"\s*>\s*$/i.exec(tokens[i].raw) : null;
|
|
3480
|
+
if (!m) return null;
|
|
3481
|
+
let j = i + 1;
|
|
3482
|
+
const skip2 = () => {
|
|
3483
|
+
while (tokens[j]?.type === "space") j++;
|
|
3484
|
+
};
|
|
3485
|
+
skip2();
|
|
3486
|
+
const inner2 = tokens[j]?.type === "paragraph" || tokens[j]?.type === "heading" ? tokens[j++] : null;
|
|
3487
|
+
skip2();
|
|
3488
|
+
if (!inner2 || tokens[j]?.type !== "html" || !/^\s*<\/div>\s*$/i.test(tokens[j].raw)) return null;
|
|
3489
|
+
const made2 = block(inner2, hints);
|
|
3490
|
+
made2[0].attrs = { ...made2[0].attrs, align: m[1] };
|
|
3491
|
+
return { end: j, made: made2 };
|
|
3492
|
+
}
|
|
3414
3493
|
function contents2(tokens, i) {
|
|
3415
3494
|
if (tokens[i].type !== "html" || !opens.test(tokens[i].raw)) return null;
|
|
3416
3495
|
let j = i + 1;
|
|
@@ -3441,7 +3520,7 @@ function sniff(tokens) {
|
|
|
3441
3520
|
style[key2] = value3;
|
|
3442
3521
|
};
|
|
3443
3522
|
let loose = 0;
|
|
3444
|
-
|
|
3523
|
+
marked.walkTokens(tokens, (token2) => {
|
|
3445
3524
|
if (token2.type === "list") {
|
|
3446
3525
|
const marker = /^\s*(?:([-*+])|\d+([.)]))/.exec(token2.raw);
|
|
3447
3526
|
if (token2.ordered) note("delim", marker?.[2] ?? ".");
|
|
@@ -3458,7 +3537,11 @@ function sniff(tokens) {
|
|
|
3458
3537
|
function fromMarkdown(source) {
|
|
3459
3538
|
const bom = source.startsWith("\uFEFF");
|
|
3460
3539
|
const crlf = source.includes("\r\n");
|
|
3461
|
-
const tokens =
|
|
3540
|
+
const tokens = marked.lexer(source.slice(bom ? 1 : 0).replace(/\r\n?/g, "\n"));
|
|
3541
|
+
notes2 = /* @__PURE__ */ new Map();
|
|
3542
|
+
marked.walkTokens(tokens, (token2) => {
|
|
3543
|
+
if (token2.type === "footnoteDef") notes2.set(token2.id, token2.text);
|
|
3544
|
+
});
|
|
3462
3545
|
const hints = {};
|
|
3463
3546
|
const content = [];
|
|
3464
3547
|
const raws = [];
|
|
@@ -3466,8 +3549,8 @@ function fromMarkdown(source) {
|
|
|
3466
3549
|
let gap = "";
|
|
3467
3550
|
for (let i = 0; i < tokens.length; i++) {
|
|
3468
3551
|
const token2 = tokens[i];
|
|
3469
|
-
const toc = contents2(tokens, i);
|
|
3470
|
-
const made2 = toc ? [{ type: "toc", attrs: { entries: JSON.stringify(toc.entries) } }] : block(token2, hints);
|
|
3552
|
+
const toc = contents2(tokens, i) ?? aligned(tokens, i, hints);
|
|
3553
|
+
const made2 = toc ? "made" in toc ? toc.made : [{ type: "toc", attrs: { entries: JSON.stringify(toc.entries) } }] : block(token2, hints);
|
|
3471
3554
|
if (!made2.length) {
|
|
3472
3555
|
gap += token2.raw;
|
|
3473
3556
|
continue;
|
|
@@ -3527,17 +3610,36 @@ function serializer(style, hints, before, cell2 = false) {
|
|
|
3527
3610
|
const bullet = hint(node).bullet ?? (run2(parent, index, ["bulletList", "taskList"]) ? style.bullet === "-" ? "*" : "-" : style.bullet);
|
|
3528
3611
|
tight(state, node, () => state.renderList(node, " ", () => `${bullet} `));
|
|
3529
3612
|
};
|
|
3613
|
+
const aligned2 = (state, node, render) => {
|
|
3614
|
+
const side2 = cell2 ? null : node.attrs.align;
|
|
3615
|
+
if (side2 && side2 !== "left") {
|
|
3616
|
+
state.write(`<div align="${side2}">`);
|
|
3617
|
+
state.closeBlock(node);
|
|
3618
|
+
}
|
|
3619
|
+
render();
|
|
3620
|
+
state.closeBlock(node);
|
|
3621
|
+
if (side2 && side2 !== "left") {
|
|
3622
|
+
state.write("</div>");
|
|
3623
|
+
state.closeBlock(node);
|
|
3624
|
+
}
|
|
3625
|
+
};
|
|
3530
3626
|
const blank3 = { open: "", close: "", mixable: true };
|
|
3531
3627
|
const wrap = (open, close = open) => ({ open, close, mixable: true, expelEnclosingWhitespace: true });
|
|
3532
3628
|
return new import_prosemirror_markdown.MarkdownSerializer({
|
|
3533
3629
|
paragraph(state, node) {
|
|
3534
|
-
state.renderInline(node);
|
|
3535
|
-
state.closeBlock(node);
|
|
3630
|
+
aligned2(state, node, () => state.renderInline(node));
|
|
3536
3631
|
},
|
|
3537
3632
|
heading(state, node) {
|
|
3538
|
-
state
|
|
3539
|
-
|
|
3540
|
-
|
|
3633
|
+
aligned2(state, node, () => {
|
|
3634
|
+
state.write(`${"#".repeat(node.attrs.level)} `);
|
|
3635
|
+
state.renderInline(node, false);
|
|
3636
|
+
});
|
|
3637
|
+
},
|
|
3638
|
+
math(state, node, parent) {
|
|
3639
|
+
state.write(parent.childCount === 1 ? `$$${node.attrs.latex}$$` : `$${node.attrs.latex}$`);
|
|
3640
|
+
},
|
|
3641
|
+
footnote(state, node) {
|
|
3642
|
+
state.write(`[^${node.attrs.id}]`);
|
|
3541
3643
|
},
|
|
3542
3644
|
blockquote(state, node) {
|
|
3543
3645
|
state.wrapBlock("> ", null, node, () => state.renderContent(node));
|
|
@@ -3647,6 +3749,13 @@ ${lines2.join("")}<!-- /toc -->`);
|
|
|
3647
3749
|
}, { hardBreakNodeName: "hardBreak", strict: false, escapeExtraCharacters: /<(?=[A-Za-z/!?])/g });
|
|
3648
3750
|
}
|
|
3649
3751
|
var one = (node, before, base) => serializer(base.style, base.hints, before).serialize(node.type.schema.topNodeType.create(null, node)).replace(/\n+$/, "");
|
|
3752
|
+
var refs = (nodes) => {
|
|
3753
|
+
const found = /* @__PURE__ */ new Map();
|
|
3754
|
+
nodes.forEach((n) => n.descendants((d) => {
|
|
3755
|
+
if (d.type.name === "footnote" && d.attrs.id) found.set(d.attrs.id, d.attrs.text);
|
|
3756
|
+
}));
|
|
3757
|
+
return found;
|
|
3758
|
+
};
|
|
3650
3759
|
function toMarkdown(doc, base) {
|
|
3651
3760
|
const nodes = [];
|
|
3652
3761
|
const found = [];
|
|
@@ -3658,22 +3767,35 @@ function toMarkdown(doc, base) {
|
|
|
3658
3767
|
nodes.push(node);
|
|
3659
3768
|
found.push(k);
|
|
3660
3769
|
});
|
|
3661
|
-
|
|
3770
|
+
const now = refs(nodes), was = refs(base.nodes);
|
|
3771
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3772
|
+
const fix = (text2) => now.size || was.size ? text2.replace(defs, (all, id, note) => {
|
|
3773
|
+
if (!now.has(id)) return was.has(id) ? "" : all;
|
|
3774
|
+
seen.add(id);
|
|
3775
|
+
return noteOf(note) === now.get(id) ? all : `[^${id}]: ${now.get(id).replace(/\n/g, "\n ")}
|
|
3776
|
+
`;
|
|
3777
|
+
}) : text2;
|
|
3778
|
+
const kept = new Set(found);
|
|
3779
|
+
const lost = base.raws.filter((_, m) => !kept.has(m)).flatMap((raw) => marked.lexer(raw).filter((t) => t.type === "def" || t.type === "footnoteDef").map((t) => t.raw.replace(/\n*$/, "\n"))).join("");
|
|
3780
|
+
let out = fix(base.head);
|
|
3662
3781
|
const starts = [];
|
|
3663
3782
|
nodes.forEach((node, i) => {
|
|
3664
3783
|
const k = found[i];
|
|
3665
3784
|
if (i && !(k >= 0 && found[i - 1] === k - 1)) out = out.replace(/\n*$/, "\n\n");
|
|
3666
3785
|
starts.push(out.length);
|
|
3667
|
-
out += k >= 0 ? base.raws[k] : one(node, i ? nodes[i - 1] : null, base);
|
|
3786
|
+
out += k >= 0 ? fix(base.raws[k]) : one(node, i ? nodes[i - 1] : null, base);
|
|
3668
3787
|
});
|
|
3669
3788
|
const last = found[found.length - 1];
|
|
3670
3789
|
const end = last >= 0 && last === base.nodes.length - 1;
|
|
3671
3790
|
if (!end) out = out.replace(/\n*$/, "\n");
|
|
3672
3791
|
const cut = out.length;
|
|
3673
|
-
out += end ? base.tail : base.tail.trim() ? `
|
|
3674
|
-
${base.tail.replace(/^\n+/, "")}` : "";
|
|
3675
|
-
const
|
|
3676
|
-
|
|
3792
|
+
out += fix(end ? base.tail : base.tail.trim() ? `
|
|
3793
|
+
${base.tail.replace(/^\n+/, "")}` : "");
|
|
3794
|
+
const extra = fix(lost) + [...now].filter(([id]) => !seen.has(id)).map(([id, note]) => `[^${id}]: ${note.replace(/\n/g, "\n ")}
|
|
3795
|
+
`).join("");
|
|
3796
|
+
if (extra) out = `${out.replace(/\n*$/, "\n\n")}${extra}`;
|
|
3797
|
+
const at2 = starts.map((s) => Math.min(s, cut));
|
|
3798
|
+
const raws = at2.map((s, i) => out.slice(s, i + 1 < at2.length ? at2[i + 1] : cut));
|
|
3677
3799
|
const text = base.crlf ? out.replace(/\n/g, "\r\n") : out;
|
|
3678
3800
|
return { text: base.bom ? `\uFEFF${text}` : text, base: { ...base, nodes, raws, tail: out.slice(cut) } };
|
|
3679
3801
|
}
|
|
@@ -3724,12 +3846,12 @@ function encode(text, encoding, bom) {
|
|
|
3724
3846
|
if (encoding === "utf-16le" || encoding === "utf-16be") {
|
|
3725
3847
|
const out2 = new Uint8Array(text.length * 2 + (bom ? 2 : 0));
|
|
3726
3848
|
const view = new DataView(out2.buffer);
|
|
3727
|
-
let
|
|
3849
|
+
let at2 = 0;
|
|
3728
3850
|
if (bom) {
|
|
3729
3851
|
view.setUint16(0, 65279, encoding === "utf-16le");
|
|
3730
|
-
|
|
3852
|
+
at2 = 2;
|
|
3731
3853
|
}
|
|
3732
|
-
for (let i = 0; i < text.length; i++) view.setUint16(
|
|
3854
|
+
for (let i = 0; i < text.length; i++) view.setUint16(at2 + i * 2, text.charCodeAt(i), encoding === "utf-16le");
|
|
3733
3855
|
return out2;
|
|
3734
3856
|
}
|
|
3735
3857
|
const table2 = /* @__PURE__ */ new Map();
|
|
@@ -4006,7 +4128,7 @@ function squeeze(b, rows, cols) {
|
|
|
4006
4128
|
return r && c ? { startRow: r[0], endRow: r[1], startColumn: c[0], endColumn: c[1] } : null;
|
|
4007
4129
|
}
|
|
4008
4130
|
var token = /("(?:[^"]|"")*")|('(?:[^']|'')+'|[A-Za-z_À-][\w.À-]*)!|(\[(?:[^[\]]|\[[^\]]*\])*\])|(\$?[A-Za-z]{1,3}\$?\d+(?::\$?[A-Za-z]{1,3}\$?\d+)?|\$?[A-Za-z]{1,3}:\$?[A-Za-z]{1,3}|\$?\d+:\$?\d+)(?![\w(.!À-])/g;
|
|
4009
|
-
function
|
|
4131
|
+
function refs2(formula, visit) {
|
|
4010
4132
|
let sheet = null;
|
|
4011
4133
|
let outside = false;
|
|
4012
4134
|
let last = 0;
|
|
@@ -4038,7 +4160,7 @@ function refs(formula, visit) {
|
|
|
4038
4160
|
return out + formula.slice(last);
|
|
4039
4161
|
}
|
|
4040
4162
|
function shifted(formula, dr, dc) {
|
|
4041
|
-
return
|
|
4163
|
+
return refs2(formula, (p) => {
|
|
4042
4164
|
const ends = p.text.split(":").map(side);
|
|
4043
4165
|
if (ends.some((e) => !e)) return p.text;
|
|
4044
4166
|
for (const e of ends) {
|
|
@@ -4050,7 +4172,7 @@ function shifted(formula, dr, dc) {
|
|
|
4050
4172
|
});
|
|
4051
4173
|
}
|
|
4052
4174
|
function remapped(formula, mine, rows, cols) {
|
|
4053
|
-
return
|
|
4175
|
+
return refs2(formula, (p) => {
|
|
4054
4176
|
if (!mine(p.sheet)) return p.text;
|
|
4055
4177
|
const b = box(p.text);
|
|
4056
4178
|
const ends = p.text.split(":").map(side);
|
|
@@ -4435,8 +4557,8 @@ var Styles2 = class {
|
|
|
4435
4557
|
return index;
|
|
4436
4558
|
}
|
|
4437
4559
|
add(list, xml) {
|
|
4438
|
-
const
|
|
4439
|
-
if (
|
|
4560
|
+
const at2 = this[list].indexOf(xml);
|
|
4561
|
+
if (at2 >= 0) return at2;
|
|
4440
4562
|
this[list].push(xml);
|
|
4441
4563
|
this.added = true;
|
|
4442
4564
|
return this[list].length - 1;
|
|
@@ -4515,8 +4637,8 @@ var Styles2 = class {
|
|
|
4515
4637
|
edits2.push([el.start, el.end, `${open} count="${lists[name].length}">${lists[name].join("")}</${el.name}>`]);
|
|
4516
4638
|
} else {
|
|
4517
4639
|
const after = root.kids.find((k) => order2.indexOf(this.bare(k.name)) > order2.indexOf(name));
|
|
4518
|
-
const
|
|
4519
|
-
edits2.push([
|
|
4640
|
+
const at2 = after ? after.start : root.close;
|
|
4641
|
+
edits2.push([at2, at2, `<${p}${name} count="${lists[name].length}">${lists[name].join("")}</${p}${name}>`]);
|
|
4520
4642
|
}
|
|
4521
4643
|
}
|
|
4522
4644
|
edits2.sort((x, y) => y[0] - x[0]);
|
|
@@ -4594,7 +4716,7 @@ function load(bytes) {
|
|
|
4594
4716
|
defaultStyle: styles.looks[0]
|
|
4595
4717
|
};
|
|
4596
4718
|
if (date1904) book.dateSystem = "date1904";
|
|
4597
|
-
const
|
|
4719
|
+
const notes3 = {};
|
|
4598
4720
|
const validations = {};
|
|
4599
4721
|
const filters = {};
|
|
4600
4722
|
const model = { book, lines: {}, origin: { sheets: {}, lines: {} } };
|
|
@@ -4658,13 +4780,13 @@ function load(bytes) {
|
|
|
4658
4780
|
let maxRow = -1, maxCol = -1;
|
|
4659
4781
|
if (open && open.close > open.open) {
|
|
4660
4782
|
const end = open.close;
|
|
4661
|
-
let
|
|
4662
|
-
while (
|
|
4663
|
-
const lt = sxml.indexOf("<",
|
|
4783
|
+
let at2 = open.open, row2 = -1, col = -1;
|
|
4784
|
+
while (at2 < end) {
|
|
4785
|
+
const lt = sxml.indexOf("<", at2);
|
|
4664
4786
|
if (lt < 0 || lt >= end) break;
|
|
4665
4787
|
const gt = sxml.indexOf(">", lt);
|
|
4666
4788
|
if (sxml.charCodeAt(lt + 1) === 47) {
|
|
4667
|
-
|
|
4789
|
+
at2 = gt + 1;
|
|
4668
4790
|
continue;
|
|
4669
4791
|
}
|
|
4670
4792
|
let j = lt + 1;
|
|
@@ -4692,11 +4814,11 @@ function load(bytes) {
|
|
|
4692
4814
|
}
|
|
4693
4815
|
if (Object.keys(rd).length) rowData[row2] = rd;
|
|
4694
4816
|
if (rd.h !== void 0 || rd.hd || rd.s) maxRow = Math.max(maxRow, row2);
|
|
4695
|
-
|
|
4817
|
+
at2 = gt + 1;
|
|
4696
4818
|
continue;
|
|
4697
4819
|
}
|
|
4698
4820
|
if (name !== "c") {
|
|
4699
|
-
|
|
4821
|
+
at2 = gt + 1;
|
|
4700
4822
|
continue;
|
|
4701
4823
|
}
|
|
4702
4824
|
const ref = attr2(tag, "r");
|
|
@@ -4760,7 +4882,7 @@ function load(bytes) {
|
|
|
4760
4882
|
}
|
|
4761
4883
|
}
|
|
4762
4884
|
cells.set(key(row2, col), { start: lt, end: stop, shared });
|
|
4763
|
-
|
|
4885
|
+
at2 = stop;
|
|
4764
4886
|
}
|
|
4765
4887
|
}
|
|
4766
4888
|
for (const [r, c, si] of children) {
|
|
@@ -4808,7 +4930,7 @@ function load(bytes) {
|
|
|
4808
4930
|
sheetNotes.push(note);
|
|
4809
4931
|
const [r, c] = cell(ref);
|
|
4810
4932
|
if (r < 0) continue;
|
|
4811
|
-
((_b =
|
|
4933
|
+
((_b = notes3[sid] ?? (notes3[sid] = {}))[r] ?? (_b[r] = {}))[c] = { note: note.text, width: 160, height: 72, show: false, id: `n${sheetNotes.length - 1}`, row: r, col: c };
|
|
4812
4934
|
maxRow = Math.max(maxRow, r);
|
|
4813
4935
|
maxCol = Math.max(maxCol, c);
|
|
4814
4936
|
}
|
|
@@ -4865,7 +4987,7 @@ function load(bytes) {
|
|
|
4865
4987
|
}
|
|
4866
4988
|
const resources = book.resources;
|
|
4867
4989
|
if (Object.keys(names).length) resources.push({ name: "SHEET_DEFINED_NAME_PLUGIN", data: JSON.stringify(names) });
|
|
4868
|
-
if (Object.keys(
|
|
4990
|
+
if (Object.keys(notes3).length) resources.push({ name: "SHEET_NOTE_PLUGIN", data: JSON.stringify(notes3) });
|
|
4869
4991
|
if (Object.keys(validations).length) resources.push({ name: "SHEET_DATA_VALIDATION_PLUGIN", data: JSON.stringify(validations) });
|
|
4870
4992
|
if (Object.keys(filters).length) resources.push({ name: "SHEET_FILTER_PLUGIN", data: JSON.stringify(filters) });
|
|
4871
4993
|
const shown = entries2[active];
|
|
@@ -5037,14 +5159,14 @@ function place(xml, name, value3) {
|
|
|
5037
5159
|
if (found) return xml.slice(0, found.start) + (value3 ?? "") + xml.slice(found.end);
|
|
5038
5160
|
if (value3 === null) return xml;
|
|
5039
5161
|
const rank = order.indexOf(name);
|
|
5040
|
-
let
|
|
5162
|
+
let at2 = -1;
|
|
5041
5163
|
for (const later of order.slice(rank + 1)) {
|
|
5042
5164
|
const f = find2(xml, later);
|
|
5043
|
-
if (f && (
|
|
5165
|
+
if (f && (at2 < 0 || f.start < at2)) at2 = f.start;
|
|
5044
5166
|
}
|
|
5045
|
-
if (
|
|
5046
|
-
if (
|
|
5047
|
-
return xml.slice(0,
|
|
5167
|
+
if (at2 < 0) at2 = xml.search(/<\/(?:\w+:)?worksheet>\s*$/);
|
|
5168
|
+
if (at2 < 0) at2 = xml.length;
|
|
5169
|
+
return xml.slice(0, at2) + value3 + xml.slice(at2);
|
|
5048
5170
|
}
|
|
5049
5171
|
function remapZone(xml, mine, rows, cols) {
|
|
5050
5172
|
const ranges = (sqref) => boxes(sqref).map((b) => squeeze(b, rows.map, cols.map)).filter((b) => b !== null).map(span).join(" ");
|
|
@@ -5295,12 +5417,12 @@ function writeXlsx(original, model) {
|
|
|
5295
5417
|
tail = place(tail, "autoFilter", filter?.ref ? filterXml(p, filter.ref, filter.filterColumns ?? []) : null);
|
|
5296
5418
|
filterNames.set(entry2.sheetId, filter?.ref ? `${quoted(sheet.name)}!${span(filter.ref).split(":").map((s) => s.replace(/([A-Z]+)(\d+)/, "$$$1$$$2")).join(":")}` : null);
|
|
5297
5419
|
}
|
|
5298
|
-
const
|
|
5420
|
+
const notes3 = Object.values(curNotes?.[sid] ?? {}).flatMap((line) => Object.values(line ?? {})).filter((n) => n && !blank2(n.note));
|
|
5299
5421
|
const oldNotes = (rec?.notes ?? []).map((n) => ({ ref: n.ref, text: n.text }));
|
|
5300
|
-
const nowNotes =
|
|
5422
|
+
const nowNotes = notes3.map((n) => ({ ref: a1(n.row, n.col), text: n.note })).sort((a, b) => a.ref.localeCompare(b.ref));
|
|
5301
5423
|
if (curNotes && !same(nowNotes, [...oldNotes].sort((a, b) => a.ref.localeCompare(b.ref)))) {
|
|
5302
5424
|
changed2 = true;
|
|
5303
|
-
tail = writeNotes(book, entry2, tail, p,
|
|
5425
|
+
tail = writeNotes(book, entry2, tail, p, notes3, rows, cols, types, defaultsNeeded, fresh);
|
|
5304
5426
|
}
|
|
5305
5427
|
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;
|
|
5306
5428
|
if (!changed2) {
|
|
@@ -5390,9 +5512,9 @@ function writeXlsx(original, model) {
|
|
|
5390
5512
|
listed2.push({ xml: tag, sheetId: s.sheetId, oldIndex: s.rec ? indexOf.get(s.sheetId) : -1 });
|
|
5391
5513
|
}
|
|
5392
5514
|
for (const { e, i } of nonSheets) {
|
|
5393
|
-
let
|
|
5394
|
-
if (
|
|
5395
|
-
listed2.splice(
|
|
5515
|
+
let at2 = listed2.findIndex((x) => x.oldIndex > i);
|
|
5516
|
+
if (at2 < 0) at2 = listed2.length;
|
|
5517
|
+
listed2.splice(at2, 0, { xml: e.xml, sheetId: e.sheetId, oldIndex: i });
|
|
5396
5518
|
}
|
|
5397
5519
|
wb = wb.replace(/(<(?:\w+:)?sheets\b[^>]*>)[\s\S]*?(<\/(?:\w+:)?sheets>)/, (_, a, b) => a + listed2.map((x) => x.xml).join("") + b);
|
|
5398
5520
|
const newIndex = new Map(listed2.map((x, i) => [x.oldIndex, i]));
|
|
@@ -5420,8 +5542,8 @@ function writeXlsx(original, model) {
|
|
|
5420
5542
|
});
|
|
5421
5543
|
for (const [sheetId, f] of filterNames) {
|
|
5422
5544
|
if (!f) continue;
|
|
5423
|
-
const
|
|
5424
|
-
wb = /<(?:\w+:)?definedNames\b/.test(wb) ? wb.replace(/<\/(?:\w+:)?definedNames>/, (end) =>
|
|
5545
|
+
const def2 = `<${wp}definedName name="_xlnm._FilterDatabase" localSheetId="${sheetIndex.get(sheetId)}" hidden="1">${escape(f)}</${wp}definedName>`;
|
|
5546
|
+
wb = /<(?:\w+:)?definedNames\b/.test(wb) ? wb.replace(/<\/(?:\w+:)?definedNames>/, (end) => def2 + end) : wb.replace(/<\/(?:\w+:)?sheets>/, (end) => `${end}<${wp}definedNames>${def2}</${wp}definedNames>`);
|
|
5425
5547
|
}
|
|
5426
5548
|
wb = wb.replace(/<((?:\w+:)?)definedNames>\s*<\/\1definedNames>/, "");
|
|
5427
5549
|
wb = wb.replace(/<(?:\w+:)?workbookView\b[^>]*>/g, (tag) => {
|
|
@@ -5610,7 +5732,7 @@ function filterXml(p, ref, columns2) {
|
|
|
5610
5732
|
}).join("");
|
|
5611
5733
|
return body ? `<${p}autoFilter ref="${span(ref)}">${body}</${p}autoFilter>` : `<${p}autoFilter ref="${span(ref)}"/>`;
|
|
5612
5734
|
}
|
|
5613
|
-
function writeNotes(book, entry2, tail, p,
|
|
5735
|
+
function writeNotes(book, entry2, tail, p, notes3, rows, cols, types, defaults, fresh) {
|
|
5614
5736
|
const { pack } = book;
|
|
5615
5737
|
const rec = entry2.rec;
|
|
5616
5738
|
const relsPart = relsOf(entry2.part);
|
|
@@ -5637,7 +5759,7 @@ function writeNotes(book, entry2, tail, p, notes2, rows, cols, types, defaults,
|
|
|
5637
5759
|
const [r, c] = cell(n.ref);
|
|
5638
5760
|
return [a1(rows.map(r), cols.map(c)), n];
|
|
5639
5761
|
}));
|
|
5640
|
-
const list = [...
|
|
5762
|
+
const list = [...notes3].sort((a, b) => a.row - b.row || a.col - b.col).map((n) => {
|
|
5641
5763
|
const ref = a1(n.row, n.col);
|
|
5642
5764
|
const was = byOld.get(ref);
|
|
5643
5765
|
if (was && was.text === n.note) return setAttr(was.xml.slice(0, was.xml.indexOf(">") + 1), "ref", ref) + was.xml.slice(was.xml.indexOf(">") + 1);
|
|
@@ -5658,7 +5780,7 @@ function writeNotes(book, entry2, tail, p, notes2, rows, cols, types, defaults,
|
|
|
5658
5780
|
return "";
|
|
5659
5781
|
});
|
|
5660
5782
|
let id = Math.max(1024, ...[...vml2.matchAll(/_x0000_s(\d+)/g)].map((m) => Number(m[1])));
|
|
5661
|
-
const out =
|
|
5783
|
+
const out = notes3.map((n) => {
|
|
5662
5784
|
const ref = a1(n.row, n.col);
|
|
5663
5785
|
const was = shapes.get(ref);
|
|
5664
5786
|
if (was) return was.replace(/<x:Row>\d+<\/x:Row>/, `<x:Row>${n.row}</x:Row>`).replace(/<x:Column>\d+<\/x:Column>/, `<x:Column>${n.col}</x:Column>`).replace(/<x:Anchor>([^<]*)<\/x:Anchor>/, `<x:Anchor>${n.col + 1}, 15, ${n.row}, 2, ${n.col + 3}, 15, ${n.row + 4}, 16</x:Anchor>`);
|
|
@@ -5718,7 +5840,7 @@ function made(config, lines2) {
|
|
|
5718
5840
|
function fill2(doc, model) {
|
|
5719
5841
|
const { book: wb, lines: lines2 } = model;
|
|
5720
5842
|
const book = doc.getMap("book");
|
|
5721
|
-
const
|
|
5843
|
+
const notes3 = JSON.parse(wb.resources?.find((r) => r.name === "SHEET_NOTE_PLUGIN")?.data ?? "{}");
|
|
5722
5844
|
doc.transact(() => {
|
|
5723
5845
|
book.set("head", strip({ id: wb.id, name: wb.name, appVersion: wb.appVersion, locale: wb.locale, defaultStyle: wb.defaultStyle, dateSystem: wb.dateSystem }));
|
|
5724
5846
|
book.set("extras", (wb.resources ?? []).filter((r) => r.name !== "SHEET_NOTE_PLUGIN"));
|
|
@@ -5736,23 +5858,23 @@ function fill2(doc, model) {
|
|
|
5736
5858
|
const { cells, rowData, colData, merges, notes: kept } = pieces(sheets.get(sid));
|
|
5737
5859
|
for (const [r, line] of Object.entries(sheet.cellData ?? {})) for (const [c, x] of Object.entries(line ?? {})) {
|
|
5738
5860
|
if (!x) continue;
|
|
5739
|
-
const
|
|
5861
|
+
const at2 = spot(l.rows[+r], l.cols[+c]);
|
|
5740
5862
|
const out = {};
|
|
5741
5863
|
if (x.f) {
|
|
5742
5864
|
out.f = x.f;
|
|
5743
|
-
values.set(`${sid}:${
|
|
5865
|
+
values.set(`${sid}:${at2}`, { v: x.v ?? null, t: x.t ?? null });
|
|
5744
5866
|
} else {
|
|
5745
5867
|
if (x.v !== void 0 && x.v !== null) out.v = x.v;
|
|
5746
5868
|
if (x.t) out.t = x.t;
|
|
5747
5869
|
}
|
|
5748
5870
|
if (x.p) out.p = x.p;
|
|
5749
5871
|
if (typeof x.s === "string") out.s = x.s;
|
|
5750
|
-
cells.set(
|
|
5872
|
+
cells.set(at2, out);
|
|
5751
5873
|
}
|
|
5752
5874
|
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 }));
|
|
5753
5875
|
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 }));
|
|
5754
5876
|
for (const b of sheet.mergeData ?? []) merges.set([l.rows[b.startRow], l.cols[b.startColumn], l.rows[b.endRow], l.cols[b.endColumn]].join(":"), 1);
|
|
5755
|
-
for (const [r, line] of Object.entries(
|
|
5877
|
+
for (const [r, line] of Object.entries(notes3[sid] ?? {})) for (const [c, n] of Object.entries(line)) kept.set(spot(l.rows[+r], l.cols[+c]), { note: n.note, width: n.width, height: n.height });
|
|
5756
5878
|
}
|
|
5757
5879
|
});
|
|
5758
5880
|
}
|
|
@@ -5762,11 +5884,11 @@ function sheetOf(doc, sid, l) {
|
|
|
5762
5884
|
const { cells, rowData, colData, merges } = pieces(m);
|
|
5763
5885
|
const rows = new Map(l.rows.map((id, i) => [id, i])), cols = new Map(l.cols.map((id, i) => [id, i]));
|
|
5764
5886
|
const cellData = {};
|
|
5765
|
-
for (const [
|
|
5766
|
-
const [row2, col] =
|
|
5887
|
+
for (const [at2, x] of cells) {
|
|
5888
|
+
const [row2, col] = at2.split(":");
|
|
5767
5889
|
const r = rows.get(row2), c = cols.get(col);
|
|
5768
5890
|
if (r === void 0 || c === void 0) continue;
|
|
5769
|
-
const kept = x.f ? values.get(`${sid}:${
|
|
5891
|
+
const kept = x.f ? values.get(`${sid}:${at2}`) : void 0;
|
|
5770
5892
|
(cellData[r] ?? (cellData[r] = {}))[c] = kept ? { ...x, v: kept.v, t: kept.t } : { ...x };
|
|
5771
5893
|
}
|
|
5772
5894
|
const rowsOut = {}, colsOut = {};
|
|
@@ -5779,14 +5901,14 @@ function sheetOf(doc, sid, l) {
|
|
|
5779
5901
|
}
|
|
5780
5902
|
var notesOf = (m, l) => {
|
|
5781
5903
|
const rows = new Map(l.rows.map((id, i) => [id, i])), cols = new Map(l.cols.map((id, i) => [id, i]));
|
|
5782
|
-
return [...pieces(m).notes].map(([
|
|
5904
|
+
return [...pieces(m).notes].map(([at2, n]) => ({ ...n, row: rows.get(at2.split(":")[0]), col: cols.get(at2.split(":")[1]) })).filter((n) => n.row !== void 0 && n.col !== void 0);
|
|
5783
5905
|
};
|
|
5784
5906
|
function build(doc) {
|
|
5785
5907
|
const { book, order: order2, sheets, styles, origin } = parts(doc);
|
|
5786
5908
|
const sheetOrder = [...new Set(order2.toArray())].filter((sid) => sheets.has(sid));
|
|
5787
5909
|
const wb = { ...book.get("head"), styles: styles.toJSON(), sheetOrder, sheets: {}, resources: [] };
|
|
5788
5910
|
const model = { book: wb, lines: {}, origin: { sheets: {}, lines: {} } };
|
|
5789
|
-
const
|
|
5911
|
+
const notes3 = {};
|
|
5790
5912
|
for (const sid of sheetOrder) {
|
|
5791
5913
|
const { rows, cols } = pieces(sheets.get(sid));
|
|
5792
5914
|
const l = { rows: rows.toArray(), cols: cols.toArray() };
|
|
@@ -5794,14 +5916,14 @@ function build(doc) {
|
|
|
5794
5916
|
wb.sheets[sid] = sheetOf(doc, sid, l);
|
|
5795
5917
|
notesOf(sheets.get(sid), l).forEach((n, i) => {
|
|
5796
5918
|
var _a, _b;
|
|
5797
|
-
((_a =
|
|
5919
|
+
((_a = notes3[sid] ?? (notes3[sid] = {}))[_b = n.row] ?? (_a[_b] = {}))[n.col] = { ...n, show: false, id: `n${i}` };
|
|
5798
5920
|
});
|
|
5799
5921
|
const o = origin.get(sid);
|
|
5800
5922
|
if (!o) continue;
|
|
5801
5923
|
model.origin.sheets[sid] = o.id;
|
|
5802
5924
|
model.origin.lines[sid] = { rows: typeof o.rows === "number" ? numbered("r", o.rows) : o.rows, cols: typeof o.cols === "number" ? numbered("c", o.cols) : o.cols };
|
|
5803
5925
|
}
|
|
5804
|
-
wb.resources.push({ name: "SHEET_NOTE_PLUGIN", data: JSON.stringify(
|
|
5926
|
+
wb.resources.push({ name: "SHEET_NOTE_PLUGIN", data: JSON.stringify(notes3) });
|
|
5805
5927
|
const active = book.get("active");
|
|
5806
5928
|
if (active && sheetOrder.includes(active)) model.active = active;
|
|
5807
5929
|
return model;
|
|
@@ -5829,16 +5951,16 @@ function applyCells(doc, list, origin) {
|
|
|
5829
5951
|
if (!sid || r < 0) continue;
|
|
5830
5952
|
const { rows, cols, cells } = pieces(sheets.get(sid));
|
|
5831
5953
|
if (r >= rows.length || c >= cols.length) continue;
|
|
5832
|
-
const
|
|
5954
|
+
const at2 = spot(rows.get(r), cols.get(c));
|
|
5833
5955
|
const next = {};
|
|
5834
5956
|
if (x.formula !== void 0) next.f = x.formula.startsWith("=") ? x.formula : `=${x.formula}`;
|
|
5835
5957
|
else if (typeof x.value === "boolean") Object.assign(next, { v: x.value ? 1 : 0, t: 3 });
|
|
5836
5958
|
else if (x.value !== void 0 && x.value !== null && x.value !== "") Object.assign(next, { v: x.value, t: typeof x.value === "number" ? 2 : 1 });
|
|
5837
|
-
const s = cells.get(
|
|
5959
|
+
const s = cells.get(at2)?.s;
|
|
5838
5960
|
if (s) next.s = s;
|
|
5839
|
-
values.delete(`${sid}:${
|
|
5840
|
-
if (Object.keys(next).length) cells.set(
|
|
5841
|
-
else cells.delete(
|
|
5961
|
+
values.delete(`${sid}:${at2}`);
|
|
5962
|
+
if (Object.keys(next).length) cells.set(at2, next);
|
|
5963
|
+
else cells.delete(at2);
|
|
5842
5964
|
done++;
|
|
5843
5965
|
}
|
|
5844
5966
|
}, origin);
|
|
@@ -6100,8 +6222,24 @@ var en2 = {
|
|
|
6100
6222
|
retry: "Try again",
|
|
6101
6223
|
loading: "Loading",
|
|
6102
6224
|
unsupported: "This file cannot be shown yet",
|
|
6225
|
+
teamTemplates: "Team templates",
|
|
6226
|
+
saveTemplate: "Save as template",
|
|
6227
|
+
templateSaved: "Saved to Templates",
|
|
6228
|
+
templateFailed: "Could not save the template",
|
|
6229
|
+
assignTo: "Assign to {name}",
|
|
6230
|
+
assignedTo: "Assigned to {name}",
|
|
6231
|
+
assignedYou: "Assigned to you",
|
|
6232
|
+
printLayout: "Print layout",
|
|
6233
|
+
cut: "Cut",
|
|
6234
|
+
paste: "Paste",
|
|
6235
|
+
spellCheck: "Spell check",
|
|
6236
|
+
spellHint: "Spelling: right-click again",
|
|
6103
6237
|
restore: "Restore this version",
|
|
6104
6238
|
restoreFailed: "Could not restore",
|
|
6239
|
+
showChanges: "What changed",
|
|
6240
|
+
hideChanges: "Back to the version",
|
|
6241
|
+
noChanges: "Same text as now",
|
|
6242
|
+
changeCount: "Since this version, paragraphs: {added} added, {edited} changed, {removed} removed",
|
|
6105
6243
|
allProjects: "All projects",
|
|
6106
6244
|
closePanel: "Hide the panel",
|
|
6107
6245
|
openPanel: "Show the panel",
|
|
@@ -6206,7 +6344,6 @@ var en2 = {
|
|
|
6206
6344
|
footnote: "Footnote",
|
|
6207
6345
|
footnoteText: "Footnote text",
|
|
6208
6346
|
formula: "Formula",
|
|
6209
|
-
formulaHint: "Saved as a Word equation",
|
|
6210
6347
|
symbols: "Special characters",
|
|
6211
6348
|
symbolSearch: "Search, for example arrow",
|
|
6212
6349
|
update: "Update",
|
|
@@ -6426,8 +6563,24 @@ var pl2 = {
|
|
|
6426
6563
|
retry: "Spr\xF3buj ponownie",
|
|
6427
6564
|
loading: "Wczytywanie",
|
|
6428
6565
|
unsupported: "Tego pliku nie da si\u0119 jeszcze pokaza\u0107",
|
|
6566
|
+
teamTemplates: "Szablony zespo\u0142u",
|
|
6567
|
+
saveTemplate: "Zapisz jako szablon",
|
|
6568
|
+
templateSaved: "Zapisano w Szablonach",
|
|
6569
|
+
templateFailed: "Nie uda\u0142o si\u0119 zapisa\u0107 szablonu",
|
|
6570
|
+
assignTo: "Przypisz do: {name}",
|
|
6571
|
+
assignedTo: "Przypisane: {name}",
|
|
6572
|
+
assignedYou: "Przypisane do Ciebie",
|
|
6573
|
+
printLayout: "Uk\u0142ad wydruku",
|
|
6574
|
+
cut: "Wytnij",
|
|
6575
|
+
paste: "Wklej",
|
|
6576
|
+
spellCheck: "Sprawdzanie pisowni",
|
|
6577
|
+
spellHint: "Pisownia: kliknij prawym jeszcze raz",
|
|
6429
6578
|
restore: "Przywr\xF3\u0107 t\u0119 wersj\u0119",
|
|
6430
6579
|
restoreFailed: "Nie uda\u0142o si\u0119 przywr\xF3ci\u0107",
|
|
6580
|
+
showChanges: "Co si\u0119 zmieni\u0142o",
|
|
6581
|
+
hideChanges: "Wr\xF3\u0107 do wersji",
|
|
6582
|
+
noChanges: "Tekst taki sam jak teraz",
|
|
6583
|
+
changeCount: "Od tej wersji, akapity: {added} dodane, {edited} zmienione, {removed} usuni\u0119te",
|
|
6431
6584
|
allProjects: "Wszystkie projekty",
|
|
6432
6585
|
closePanel: "Ukryj panel",
|
|
6433
6586
|
openPanel: "Poka\u017C panel",
|
|
@@ -6532,7 +6685,6 @@ var pl2 = {
|
|
|
6532
6685
|
footnote: "Przypis",
|
|
6533
6686
|
footnoteText: "Tekst przypisu",
|
|
6534
6687
|
formula: "Wz\xF3r",
|
|
6535
|
-
formulaHint: "Zapisany jako r\xF3wnanie Word",
|
|
6536
6688
|
symbols: "Znaki specjalne",
|
|
6537
6689
|
symbolSearch: "Szukaj, na przyk\u0142ad strza\u0142ka",
|
|
6538
6690
|
update: "Zmie\u0144",
|
|
@@ -6752,8 +6904,24 @@ var uk2 = {
|
|
|
6752
6904
|
retry: "\u0421\u043F\u0440\u043E\u0431\u0443\u0432\u0430\u0442\u0438 \u0449\u0435",
|
|
6753
6905
|
loading: "\u0417\u0430\u0432\u0430\u043D\u0442\u0430\u0436\u0435\u043D\u043D\u044F",
|
|
6754
6906
|
unsupported: "\u0426\u0435\u0439 \u0444\u0430\u0439\u043B \u043F\u043E\u043A\u0438 \u043D\u0435 \u043C\u043E\u0436\u043D\u0430 \u043F\u043E\u043A\u0430\u0437\u0430\u0442\u0438",
|
|
6907
|
+
teamTemplates: "\u0428\u0430\u0431\u043B\u043E\u043D\u0438 \u043A\u043E\u043C\u0430\u043D\u0434\u0438",
|
|
6908
|
+
saveTemplate: "\u0417\u0431\u0435\u0440\u0435\u0433\u0442\u0438 \u044F\u043A \u0448\u0430\u0431\u043B\u043E\u043D",
|
|
6909
|
+
templateSaved: "\u0417\u0431\u0435\u0440\u0435\u0436\u0435\u043D\u043E \u0432 Templates",
|
|
6910
|
+
templateFailed: "\u041D\u0435 \u0432\u0434\u0430\u043B\u043E\u0441\u044F \u0437\u0431\u0435\u0440\u0435\u0433\u0442\u0438 \u0448\u0430\u0431\u043B\u043E\u043D",
|
|
6911
|
+
assignTo: "\u0414\u043E\u0440\u0443\u0447\u0438\u0442\u0438: {name}",
|
|
6912
|
+
assignedTo: "\u0414\u043E\u0440\u0443\u0447\u0435\u043D\u043E: {name}",
|
|
6913
|
+
assignedYou: "\u0414\u043E\u0440\u0443\u0447\u0435\u043D\u043E \u0432\u0430\u043C",
|
|
6914
|
+
printLayout: "\u0420\u043E\u0437\u043C\u0456\u0442\u043A\u0430 \u0441\u0442\u043E\u0440\u0456\u043D\u043A\u0438",
|
|
6915
|
+
cut: "\u0412\u0438\u0440\u0456\u0437\u0430\u0442\u0438",
|
|
6916
|
+
paste: "\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u0438",
|
|
6917
|
+
spellCheck: "\u041F\u0435\u0440\u0435\u0432\u0456\u0440\u043A\u0430 \u043F\u0440\u0430\u0432\u043E\u043F\u0438\u0441\u0443",
|
|
6918
|
+
spellHint: "\u041F\u0440\u0430\u0432\u043E\u043F\u0438\u0441: \u043A\u043B\u0430\u0446\u043D\u0456\u0442\u044C \u043F\u0440\u0430\u0432\u043E\u044E \u0449\u0435 \u0440\u0430\u0437",
|
|
6755
6919
|
restore: "\u0412\u0456\u0434\u043D\u043E\u0432\u0438\u0442\u0438 \u0446\u044E \u0432\u0435\u0440\u0441\u0456\u044E",
|
|
6756
6920
|
restoreFailed: "\u041D\u0435 \u0432\u0434\u0430\u043B\u043E\u0441\u044F \u0432\u0456\u0434\u043D\u043E\u0432\u0438\u0442\u0438",
|
|
6921
|
+
showChanges: "\u0429\u043E \u0437\u043C\u0456\u043D\u0438\u043B\u043E\u0441\u044C",
|
|
6922
|
+
hideChanges: "\u041D\u0430\u0437\u0430\u0434 \u0434\u043E \u0432\u0435\u0440\u0441\u0456\u0457",
|
|
6923
|
+
noChanges: "\u0422\u0435\u043A\u0441\u0442 \u0442\u0430\u043A\u0438\u0439 \u0441\u0430\u043C\u0438\u0439, \u044F\u043A \u0437\u0430\u0440\u0430\u0437",
|
|
6924
|
+
changeCount: "\u0412\u0456\u0434\u0442\u043E\u0434\u0456 \u0430\u0431\u0437\u0430\u0446\u0456\u0432: {added} \u0434\u043E\u0434\u0430\u043D\u043E, {edited} \u0437\u043C\u0456\u043D\u0435\u043D\u043E, {removed} \u0432\u0438\u0434\u0430\u043B\u0435\u043D\u043E",
|
|
6757
6925
|
allProjects: "\u0423\u0441\u0456 \u043F\u0440\u043E\u0454\u043A\u0442\u0438",
|
|
6758
6926
|
closePanel: "\u0421\u0445\u043E\u0432\u0430\u0442\u0438 \u043F\u0430\u043D\u0435\u043B\u044C",
|
|
6759
6927
|
openPanel: "\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u0438 \u043F\u0430\u043D\u0435\u043B\u044C",
|
|
@@ -6857,7 +7025,6 @@ var uk2 = {
|
|
|
6857
7025
|
footnote: "\u0412\u0438\u043D\u043E\u0441\u043A\u0430",
|
|
6858
7026
|
footnoteText: "\u0422\u0435\u043A\u0441\u0442 \u0432\u0438\u043D\u043E\u0441\u043A\u0438",
|
|
6859
7027
|
formula: "\u0424\u043E\u0440\u043C\u0443\u043B\u0430",
|
|
6860
|
-
formulaHint: "\u0417\u0431\u0435\u0440\u0456\u0433\u0430\u0454\u0442\u044C\u0441\u044F \u044F\u043A \u0440\u0456\u0432\u043D\u044F\u043D\u043D\u044F Word",
|
|
6861
7028
|
symbols: "\u0421\u043F\u0435\u0446\u0441\u0438\u043C\u0432\u043E\u043B\u0438",
|
|
6862
7029
|
symbolSearch: "\u041F\u043E\u0448\u0443\u043A, \u043D\u0430\u043F\u0440\u0438\u043A\u043B\u0430\u0434 \u0441\u0442\u0440\u0456\u043B\u043A\u0430",
|
|
6863
7030
|
update: "\u0417\u043C\u0456\u043D\u0438\u0442\u0438",
|
|
@@ -7094,9 +7261,9 @@ function applyText(doc, kind, changes, origin) {
|
|
|
7094
7261
|
return false;
|
|
7095
7262
|
});
|
|
7096
7263
|
if (hits.length !== 1) throw new Refusal(`${hits.length ? "more than once" : "not"} in the document: ${c.find.slice(0, 80)}`);
|
|
7097
|
-
const [
|
|
7098
|
-
if (c.replace) step.replaceWith(
|
|
7099
|
-
else step.delete(
|
|
7264
|
+
const [at2] = hits;
|
|
7265
|
+
if (c.replace) step.replaceWith(at2, at2 + c.find.length, schema.text(c.replace, step.doc.resolve(at2 + 1).marks()));
|
|
7266
|
+
else step.delete(at2, at2 + c.find.length);
|
|
7100
7267
|
}
|
|
7101
7268
|
(0, import_y_tiptap2.updateYFragment)({ transact: (run2) => doc.transact(run2, origin) }, fragment, step.doc, { mapping: /* @__PURE__ */ new Map(), isOMark: /* @__PURE__ */ new Map() });
|
|
7102
7269
|
return changes.length;
|
|
@@ -7142,13 +7309,13 @@ async function save(doc, kind, base, put, load2, note) {
|
|
|
7142
7309
|
const bytes = await write2(kind, base, node, load2, doc.getMap("setup").size ? doc.getMap("setup").toJSON() : void 0);
|
|
7143
7310
|
const changed2 = !same2(bytes, base);
|
|
7144
7311
|
const id = changed2 ? await put(bytes, note ?? named2((texts[who[0].language] ?? texts.en).editedNote, who)) : null;
|
|
7145
|
-
const
|
|
7312
|
+
const refs3 = [];
|
|
7146
7313
|
if (changed2) schema.nodeFromJSON(await parse3(kind, bytes)).descendants((n) => {
|
|
7147
|
-
if (n.isBlock)
|
|
7314
|
+
if (n.isBlock) refs3.push([n.type.name, n.attrs.ref ?? null]);
|
|
7148
7315
|
});
|
|
7149
7316
|
doc.transact(() => {
|
|
7150
|
-
if (
|
|
7151
|
-
const ref =
|
|
7317
|
+
if (refs3.length === list.length && list.every((el, i) => el.nodeName === refs3[i][0])) list.forEach((el, i) => {
|
|
7318
|
+
const ref = refs3[i][1];
|
|
7152
7319
|
if ((el.getAttribute("ref") ?? null) === ref) return;
|
|
7153
7320
|
if (ref === null) el.removeAttribute("ref");
|
|
7154
7321
|
else el.setAttribute("ref", ref);
|