@yudaocode/univer-docs 1.6.214 → 1.6.216
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/WORD_TEMPLATE_PROTOCOL.md +25 -8
- package/fixtures/word-template-protocol-v1.json +27287 -0
- package/lib/cjs/facade/index.js +29 -8
- package/lib/cjs/facade/index.js.map +1 -1
- package/lib/cjs/index.js +935 -90
- package/lib/cjs/index.js.map +1 -1
- package/lib/es/facade/index.js +31 -8
- package/lib/es/facade/index.js.map +1 -1
- package/lib/es/index.js +1344 -504
- package/lib/es/index.js.map +1 -1
- package/lib/types/facade/index.d.ts +8 -1
- package/lib/types/index.d.ts +108 -33
- package/package.json +1 -1
package/lib/es/index.js
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
IResourceManagerService,
|
|
20
20
|
IUniverInstanceService as IUniverInstanceService2,
|
|
21
21
|
JSONX as JSONX2,
|
|
22
|
-
Tools as
|
|
22
|
+
Tools as Tools19,
|
|
23
23
|
UniverInstanceType as UniverInstanceType2
|
|
24
24
|
} from "@univerjs/core";
|
|
25
25
|
import { DocSelectionManagerService as DocSelectionManagerService3, RichTextEditingMutation as RichTextEditingMutation2 } from "@univerjs/docs";
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
Disposable as Disposable2,
|
|
31
31
|
generateRandomId as generateRandomId12,
|
|
32
32
|
IUniverInstanceService,
|
|
33
|
-
Tools as
|
|
33
|
+
Tools as Tools13,
|
|
34
34
|
UniverInstanceType
|
|
35
35
|
} from "@univerjs/core";
|
|
36
36
|
import { BehaviorSubject, Subject } from "rxjs";
|
|
@@ -45,12 +45,21 @@ import {
|
|
|
45
45
|
TableAlignmentType as TableAlignmentType2,
|
|
46
46
|
TableRowHeightRule as TableRowHeightRule4,
|
|
47
47
|
TableTextWrapType as TableTextWrapType2,
|
|
48
|
-
Tools as
|
|
48
|
+
Tools as Tools12
|
|
49
49
|
} from "@univerjs/core";
|
|
50
50
|
|
|
51
51
|
// src/types/doc-sdt.ts
|
|
52
52
|
var YUDAO_DOCS_TEMPLATE_RESOURCE = "YUDAO_DOCS_TEMPLATE_RESOURCE";
|
|
53
53
|
var DOC_DRAWING_PLUGIN_RESOURCE = "DOC_DRAWING_PLUGIN";
|
|
54
|
+
var DocTemplateProtocolError = class extends Error {
|
|
55
|
+
constructor(code, message, details) {
|
|
56
|
+
super(message);
|
|
57
|
+
this.name = "DocTemplateProtocolError";
|
|
58
|
+
this.code = code;
|
|
59
|
+
this.tableId = details?.tableId;
|
|
60
|
+
this.rowIndex = details?.rowIndex;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
54
63
|
|
|
55
64
|
// src/utils/doc-medical-and-blocks.ts
|
|
56
65
|
import {
|
|
@@ -1020,7 +1029,7 @@ import {
|
|
|
1020
1029
|
CustomRangeType as CustomRangeType10,
|
|
1021
1030
|
DataStreamTreeTokenType as DataStreamTreeTokenType12,
|
|
1022
1031
|
generateRandomId as generateRandomId10,
|
|
1023
|
-
Tools as
|
|
1032
|
+
Tools as Tools11
|
|
1024
1033
|
} from "@univerjs/core";
|
|
1025
1034
|
|
|
1026
1035
|
// src/utils/doc-layout-and-typography.ts
|
|
@@ -1028,7 +1037,7 @@ import {
|
|
|
1028
1037
|
CustomRangeType as CustomRangeType9,
|
|
1029
1038
|
DataStreamTreeTokenType as DataStreamTreeTokenType11,
|
|
1030
1039
|
generateRandomId as generateRandomId9,
|
|
1031
|
-
Tools as
|
|
1040
|
+
Tools as Tools10
|
|
1032
1041
|
} from "@univerjs/core";
|
|
1033
1042
|
|
|
1034
1043
|
// src/utils/doc-areas-and-badges.ts
|
|
@@ -1036,7 +1045,7 @@ import {
|
|
|
1036
1045
|
CustomRangeType as CustomRangeType8,
|
|
1037
1046
|
DataStreamTreeTokenType as DataStreamTreeTokenType10,
|
|
1038
1047
|
generateRandomId as generateRandomId8,
|
|
1039
|
-
Tools as
|
|
1048
|
+
Tools as Tools9
|
|
1040
1049
|
} from "@univerjs/core";
|
|
1041
1050
|
|
|
1042
1051
|
// src/utils/doc-v204-enhancements.ts
|
|
@@ -1049,7 +1058,7 @@ import {
|
|
|
1049
1058
|
TableAlignmentType,
|
|
1050
1059
|
TableRowHeightRule as TableRowHeightRule3,
|
|
1051
1060
|
TableTextWrapType,
|
|
1052
|
-
Tools as
|
|
1061
|
+
Tools as Tools8
|
|
1053
1062
|
} from "@univerjs/core";
|
|
1054
1063
|
|
|
1055
1064
|
// src/utils/doc-charts-and-shapes.ts
|
|
@@ -2137,7 +2146,7 @@ import {
|
|
|
2137
2146
|
generateRandomId as generateRandomId6,
|
|
2138
2147
|
NumberUnitType as NumberUnitType3,
|
|
2139
2148
|
TableRowHeightRule as TableRowHeightRule2,
|
|
2140
|
-
Tools as
|
|
2149
|
+
Tools as Tools7
|
|
2141
2150
|
} from "@univerjs/core";
|
|
2142
2151
|
|
|
2143
2152
|
// src/exporter/doc-pdf-exporter.ts
|
|
@@ -2145,7 +2154,8 @@ import {
|
|
|
2145
2154
|
BooleanNumber,
|
|
2146
2155
|
CustomRangeType as CustomRangeType4,
|
|
2147
2156
|
DataStreamTreeTokenType as DataStreamTreeTokenType6,
|
|
2148
|
-
TextDecoration
|
|
2157
|
+
TextDecoration,
|
|
2158
|
+
Tools as Tools5
|
|
2149
2159
|
} from "@univerjs/core";
|
|
2150
2160
|
|
|
2151
2161
|
// src/exporter/doc-legacy-compat.ts
|
|
@@ -8133,9 +8143,9 @@ function paginateSingleDocToPdfPages(rawSnapshot, options, imageNamePrefix = "Im
|
|
|
8133
8143
|
);
|
|
8134
8144
|
ops.push("Q");
|
|
8135
8145
|
};
|
|
8136
|
-
const renderTokensRowAt = (ops, tokens, startX, baselineY) => {
|
|
8146
|
+
const renderTokensRowAt = (ops, tokens, startX, baselineY, explicitPageIndex) => {
|
|
8137
8147
|
let tokX = startX;
|
|
8138
|
-
const curPageIndex = pageStreams.length - 1;
|
|
8148
|
+
const curPageIndex = explicitPageIndex ?? pageStreams.length - 1;
|
|
8139
8149
|
for (const tok of tokens) {
|
|
8140
8150
|
if (tok.bookmarkNames?.length) {
|
|
8141
8151
|
for (const bmName of tok.bookmarkNames) {
|
|
@@ -8151,7 +8161,7 @@ function paginateSingleDocToPdfPages(rawSnapshot, options, imageNamePrefix = "Im
|
|
|
8151
8161
|
continue;
|
|
8152
8162
|
}
|
|
8153
8163
|
}
|
|
8154
|
-
if (tok.noteRefEntry && tok.noteRefEntry.noteType === "footnote") {
|
|
8164
|
+
if (explicitPageIndex === void 0 && tok.noteRefEntry && tok.noteRefEntry.noteType === "footnote") {
|
|
8155
8165
|
if (!emittedFootnoteIds.has(tok.noteRefEntry.id)) {
|
|
8156
8166
|
emittedFootnoteIds.add(tok.noteRefEntry.id);
|
|
8157
8167
|
currentPageFootnotes.push(tok.noteRefEntry);
|
|
@@ -9219,7 +9229,285 @@ function paginateSingleDocToPdfPages(rawSnapshot, options, imageNamePrefix = "Im
|
|
|
9219
9229
|
}
|
|
9220
9230
|
return String(num);
|
|
9221
9231
|
};
|
|
9232
|
+
const toRomanPageNumber = (num, upper) => {
|
|
9233
|
+
if (num <= 0 || num >= 4e3) return String(num);
|
|
9234
|
+
const pairs = [
|
|
9235
|
+
[1e3, "M"],
|
|
9236
|
+
[900, "CM"],
|
|
9237
|
+
[500, "D"],
|
|
9238
|
+
[400, "CD"],
|
|
9239
|
+
[100, "C"],
|
|
9240
|
+
[90, "XC"],
|
|
9241
|
+
[50, "L"],
|
|
9242
|
+
[40, "XL"],
|
|
9243
|
+
[10, "X"],
|
|
9244
|
+
[9, "IX"],
|
|
9245
|
+
[5, "V"],
|
|
9246
|
+
[4, "IV"],
|
|
9247
|
+
[1, "I"]
|
|
9248
|
+
];
|
|
9249
|
+
let rem = Math.floor(num);
|
|
9250
|
+
let out = "";
|
|
9251
|
+
for (const [val, sym] of pairs) {
|
|
9252
|
+
while (rem >= val) {
|
|
9253
|
+
out += sym;
|
|
9254
|
+
rem -= val;
|
|
9255
|
+
}
|
|
9256
|
+
}
|
|
9257
|
+
return upper ? out : out.toLowerCase();
|
|
9258
|
+
};
|
|
9222
9259
|
const fmtPgToken = (num) => pageNumberType === "chinese" ? toChinesePageNumber(num) : String(num);
|
|
9260
|
+
const formatDynamicFieldPageNumber = (num, rawInstr) => {
|
|
9261
|
+
if (/\\?\*\s*ROMAN\b/.test(rawInstr)) return toRomanPageNumber(num, true);
|
|
9262
|
+
if (/\\?\*\s*roman\b/.test(rawInstr)) return toRomanPageNumber(num, false);
|
|
9263
|
+
if (/\\?\*\s*CHINESENUM/i.test(rawInstr)) return toChinesePageNumber(num);
|
|
9264
|
+
if (/\\?\*\s*ARABIC\b/i.test(rawInstr)) return String(num);
|
|
9265
|
+
return fmtPgToken(num);
|
|
9266
|
+
};
|
|
9267
|
+
const docStyle = snapshot.documentStyle ?? {};
|
|
9268
|
+
const useFirstPageHf = docStyle.useFirstPageHeaderFooter === BooleanNumber.TRUE;
|
|
9269
|
+
const useEvenOddHf = docStyle.evenAndOddHeaders === BooleanNumber.TRUE;
|
|
9270
|
+
const resolvePageHeaderBody = (pageIndex) => {
|
|
9271
|
+
const hdrs = snapshot.headers;
|
|
9272
|
+
if (!hdrs) return void 0;
|
|
9273
|
+
if (pageIndex === 0 && useFirstPageHf) {
|
|
9274
|
+
const firstId = docStyle.firstPageHeaderId;
|
|
9275
|
+
return (firstId ? hdrs[firstId]?.body : void 0) ?? hdrs.firstPageHeader?.body;
|
|
9276
|
+
}
|
|
9277
|
+
if (useEvenOddHf && (pageIndex + 1) % 2 === 0) {
|
|
9278
|
+
const evenId = docStyle.evenPageHeaderId;
|
|
9279
|
+
const evenBody = (evenId ? hdrs[evenId]?.body : void 0) ?? hdrs.evenPageHeader?.body;
|
|
9280
|
+
if (evenBody) return evenBody;
|
|
9281
|
+
}
|
|
9282
|
+
const defId = docStyle.defaultHeaderId;
|
|
9283
|
+
if (defId && hdrs[defId]?.body) return hdrs[defId].body;
|
|
9284
|
+
if (hdrs.defaultHeader?.body) return hdrs.defaultHeader.body;
|
|
9285
|
+
const fallbackKey = Object.keys(hdrs).find(
|
|
9286
|
+
(k) => k !== "firstPageHeader" && k !== "evenPageHeader"
|
|
9287
|
+
);
|
|
9288
|
+
return fallbackKey ? hdrs[fallbackKey]?.body : Object.values(hdrs)[0]?.body;
|
|
9289
|
+
};
|
|
9290
|
+
const resolvePageFooterBody = (pageIndex) => {
|
|
9291
|
+
const ftrs = snapshot.footers;
|
|
9292
|
+
if (!ftrs) return void 0;
|
|
9293
|
+
if (pageIndex === 0 && useFirstPageHf) {
|
|
9294
|
+
const firstId = docStyle.firstPageFooterId;
|
|
9295
|
+
return (firstId ? ftrs[firstId]?.body : void 0) ?? ftrs.firstPageFooter?.body;
|
|
9296
|
+
}
|
|
9297
|
+
if (useEvenOddHf && (pageIndex + 1) % 2 === 0) {
|
|
9298
|
+
const evenId = docStyle.evenPageFooterId;
|
|
9299
|
+
const evenBody = (evenId ? ftrs[evenId]?.body : void 0) ?? ftrs.evenPageFooter?.body;
|
|
9300
|
+
if (evenBody) return evenBody;
|
|
9301
|
+
}
|
|
9302
|
+
const defId = docStyle.defaultFooterId;
|
|
9303
|
+
if (defId && ftrs[defId]?.body) return ftrs[defId].body;
|
|
9304
|
+
if (ftrs.defaultFooter?.body) return ftrs.defaultFooter.body;
|
|
9305
|
+
const fallbackKey = Object.keys(ftrs).find(
|
|
9306
|
+
(k) => k !== "firstPageFooter" && k !== "evenPageFooter"
|
|
9307
|
+
);
|
|
9308
|
+
return fallbackKey ? ftrs[fallbackKey]?.body : Object.values(ftrs)[0]?.body;
|
|
9309
|
+
};
|
|
9310
|
+
const materializeHeaderFooterPageFields = (rawStoryBody, logicalPageNo, totalPageCount) => {
|
|
9311
|
+
let nextBody = Tools5.deepClone(rawStoryBody);
|
|
9312
|
+
const dynamicRanges = [...nextBody.customRanges ?? []].map((r) => ({ range: r, instr: extractDocFieldInstruction(r) })).filter((item) => {
|
|
9313
|
+
if (!item.instr) return false;
|
|
9314
|
+
const firstTok = (item.instr.trim().replace(/^\\+/, "").split(/[\s\\]+/)[0] || "").toUpperCase();
|
|
9315
|
+
return firstTok === "PAGE" || firstTok === "NUMPAGES" || firstTok === "SECTIONPAGES";
|
|
9316
|
+
}).sort((a, b) => b.range.startIndex - a.range.startIndex);
|
|
9317
|
+
for (const { range, instr } of dynamicRanges) {
|
|
9318
|
+
const firstTok = (instr.trim().replace(/^\\+/, "").split(/[\s\\]+/)[0] || "").toUpperCase();
|
|
9319
|
+
const evaluated = firstTok === "PAGE" ? formatDynamicFieldPageNumber(logicalPageNo, instr) : formatDynamicFieldPageNumber(totalPageCount, instr);
|
|
9320
|
+
const existingTs = findBodyRunStyle(nextBody, range.startIndex);
|
|
9321
|
+
const isEditorFieldHighlight = existingTs?.bg?.rgb?.toLowerCase() === "#f3f5ff" && existingTs?.cl?.rgb?.toLowerCase() === "#2c53f1" && !range.properties?.field?.preserveStyle;
|
|
9322
|
+
const cleanStyle = isEditorFieldHighlight ? {
|
|
9323
|
+
...existingTs,
|
|
9324
|
+
cl: void 0,
|
|
9325
|
+
bg: void 0
|
|
9326
|
+
} : existingTs;
|
|
9327
|
+
nextBody = spliceDocumentBodySpan(nextBody, range.startIndex, range.endIndex, evaluated, {
|
|
9328
|
+
targetRangeId: range.rangeId,
|
|
9329
|
+
updatedRangeProperties: range.properties,
|
|
9330
|
+
...cleanStyle ? { textStyle: cleanStyle } : {}
|
|
9331
|
+
});
|
|
9332
|
+
}
|
|
9333
|
+
return nextBody;
|
|
9334
|
+
};
|
|
9335
|
+
const renderStorySegmentIntoMarginOps = (targetOps, rawStoryBody, role, pageIndex, pgW, pgH, logicalPageNo, totalPageCount) => {
|
|
9336
|
+
const resolvedStory = materializeHeaderFooterPageFields(
|
|
9337
|
+
rawStoryBody,
|
|
9338
|
+
logicalPageNo,
|
|
9339
|
+
totalPageCount
|
|
9340
|
+
);
|
|
9341
|
+
const storyStream = resolvedStory.dataStream || "";
|
|
9342
|
+
const hasVisibleText = storyStream.replace(/[\r\n\u0000-\u001F]/g, "").trim().length > 0;
|
|
9343
|
+
const hasInlineBlocks = (resolvedStory.customBlocks ?? []).length > 0;
|
|
9344
|
+
if (!hasVisibleText && !hasInlineBlocks) return false;
|
|
9345
|
+
const availW = Math.max(120, pgW - marginLeft - marginRight);
|
|
9346
|
+
const hfCtx = {
|
|
9347
|
+
...spanCtxBase,
|
|
9348
|
+
dynamicFieldSpans: [],
|
|
9349
|
+
bookmarks: [],
|
|
9350
|
+
comments: [],
|
|
9351
|
+
includeComments: false
|
|
9352
|
+
};
|
|
9353
|
+
const collectedRows = [];
|
|
9354
|
+
const storyTables = [...resolvedStory.tables ?? []].sort(
|
|
9355
|
+
(a, b) => a.startIndex - b.startIndex
|
|
9356
|
+
);
|
|
9357
|
+
const isOffsetInStoryTable = (offset) => storyTables.some((t) => offset >= t.startIndex && offset < t.endIndex);
|
|
9358
|
+
const storyParas = [...resolvedStory.paragraphs ?? []].sort(
|
|
9359
|
+
(a, b) => a.startIndex - b.startIndex
|
|
9360
|
+
);
|
|
9361
|
+
const storyItems = [];
|
|
9362
|
+
for (const tbl of storyTables) {
|
|
9363
|
+
storyItems.push({ kind: "table", pos: tbl.startIndex, tbl });
|
|
9364
|
+
}
|
|
9365
|
+
for (let pi = 0; pi < storyParas.length; pi++) {
|
|
9366
|
+
const para = storyParas[pi];
|
|
9367
|
+
const pEnd = para.startIndex;
|
|
9368
|
+
if (isOffsetInStoryTable(pEnd)) continue;
|
|
9369
|
+
let pStart = pi === 0 ? 0 : storyParas[pi - 1].startIndex + 1;
|
|
9370
|
+
for (const tbl of storyTables) {
|
|
9371
|
+
if (tbl.endIndex > pStart && tbl.endIndex <= pEnd) {
|
|
9372
|
+
pStart = tbl.endIndex;
|
|
9373
|
+
}
|
|
9374
|
+
}
|
|
9375
|
+
if (pEnd < pStart) continue;
|
|
9376
|
+
storyItems.push({ kind: "para", pos: pStart, pStart, pEnd, para });
|
|
9377
|
+
}
|
|
9378
|
+
storyItems.sort((a, b) => a.pos - b.pos);
|
|
9379
|
+
const normalizeHfSegments = (segs) => segs.filter((it) => "text" in it).map((s) => {
|
|
9380
|
+
const isDefaultDark = Math.abs(s.color.r - 0.06) < 0.01 && Math.abs(s.color.g - 0.09) < 0.01 && Math.abs(s.color.b - 0.16) < 0.01;
|
|
9381
|
+
return isDefaultDark ? { ...s, color: { r: 0.35, g: 0.41, b: 0.49 } } : s;
|
|
9382
|
+
});
|
|
9383
|
+
for (const item of storyItems) {
|
|
9384
|
+
if (item.kind === "table") {
|
|
9385
|
+
const parsedRows = parseTableRowsInStream(
|
|
9386
|
+
storyStream,
|
|
9387
|
+
item.tbl.startIndex,
|
|
9388
|
+
item.tbl.endIndex
|
|
9389
|
+
);
|
|
9390
|
+
const tblDef = snapshot.tableSource?.[item.tbl.tableId];
|
|
9391
|
+
for (const rSpan of parsedRows) {
|
|
9392
|
+
if (rSpan.cells.length === 0) continue;
|
|
9393
|
+
const rawColWidths = rSpan.cells.map(
|
|
9394
|
+
(_, ci) => Math.max(24, Number(tblDef?.tableColumns?.[ci]?.size?.width?.v ?? availW / rSpan.cells.length))
|
|
9395
|
+
);
|
|
9396
|
+
const sumW = rawColWidths.reduce((a, b) => a + b, 0) || 1;
|
|
9397
|
+
let curCellX = marginLeft;
|
|
9398
|
+
const rowCells = [];
|
|
9399
|
+
let maxLh = 12;
|
|
9400
|
+
let maxFs = 9;
|
|
9401
|
+
rSpan.cells.forEach((cell, ci) => {
|
|
9402
|
+
const cw = rawColWidths[ci] / sumW * availW;
|
|
9403
|
+
const cellParas = storyParas.filter(
|
|
9404
|
+
(cp) => cp.startIndex >= cell.contentStart && cp.startIndex < cell.cellEndInclusive
|
|
9405
|
+
);
|
|
9406
|
+
const hAlign = cellParas[0]?.paragraphStyle?.horizontalAlign;
|
|
9407
|
+
const cellAlign = hAlign === 2 ? "center" : hAlign === 3 ? "right" : "left";
|
|
9408
|
+
const segs = normalizeHfSegments(
|
|
9409
|
+
buildStyledSegmentsForSpan(resolvedStory, cell.contentStart, cell.textEndExclusive, 9, hfCtx)
|
|
9410
|
+
);
|
|
9411
|
+
const wrapped = wrapSegmentsToLines(segs, Math.max(24, cw - 4), cellAlign, autoHyphenation);
|
|
9412
|
+
const firstLine = wrapped[0];
|
|
9413
|
+
maxLh = Math.max(maxLh, Math.min(20, firstLine.lineHeightPt * 0.78));
|
|
9414
|
+
maxFs = Math.max(maxFs, firstLine.maxFontSize);
|
|
9415
|
+
rowCells.push({ line: firstLine, xBase: curCellX, width: cw });
|
|
9416
|
+
curCellX += cw;
|
|
9417
|
+
});
|
|
9418
|
+
collectedRows.push({
|
|
9419
|
+
kind: "columns",
|
|
9420
|
+
cells: rowCells,
|
|
9421
|
+
lineHeightPt: maxLh,
|
|
9422
|
+
maxFontSize: maxFs
|
|
9423
|
+
});
|
|
9424
|
+
}
|
|
9425
|
+
} else {
|
|
9426
|
+
const rawSlice = storyStream.slice(item.pStart, item.pEnd);
|
|
9427
|
+
if (rawSlice.replace(/[\r\n\u0000-\u001F]/g, "").trim().length === 0 && !rawSlice.includes(DataStreamTreeTokenType6.CUSTOM_BLOCK)) {
|
|
9428
|
+
continue;
|
|
9429
|
+
}
|
|
9430
|
+
const hAlign = item.para?.paragraphStyle?.horizontalAlign;
|
|
9431
|
+
const align = hAlign === 2 ? "center" : hAlign === 3 ? "right" : "left";
|
|
9432
|
+
if (rawSlice.includes(" ")) {
|
|
9433
|
+
const tabRanges = [];
|
|
9434
|
+
let segSt = item.pStart;
|
|
9435
|
+
for (let pos = item.pStart; pos < item.pEnd; pos++) {
|
|
9436
|
+
if (storyStream[pos] === " ") {
|
|
9437
|
+
tabRanges.push({ start: segSt, end: pos });
|
|
9438
|
+
segSt = pos + 1;
|
|
9439
|
+
}
|
|
9440
|
+
}
|
|
9441
|
+
tabRanges.push({ start: segSt, end: item.pEnd });
|
|
9442
|
+
const zoneCount = tabRanges.length;
|
|
9443
|
+
const zoneCells = [];
|
|
9444
|
+
let maxFs = 9;
|
|
9445
|
+
tabRanges.forEach((rg, zIdx) => {
|
|
9446
|
+
const zAlign = zoneCount === 2 ? zIdx === 0 ? "left" : "right" : zIdx === 0 ? "left" : zIdx === zoneCount - 1 ? "right" : "center";
|
|
9447
|
+
const segs = normalizeHfSegments(
|
|
9448
|
+
buildStyledSegmentsForSpan(resolvedStory, rg.start, rg.end, 9, hfCtx)
|
|
9449
|
+
);
|
|
9450
|
+
const ln = wrapSegmentsToLines(segs, availW, zAlign, autoHyphenation)[0];
|
|
9451
|
+
maxFs = Math.max(maxFs, ln.maxFontSize);
|
|
9452
|
+
zoneCells.push({ line: ln, xBase: marginLeft, width: availW });
|
|
9453
|
+
});
|
|
9454
|
+
collectedRows.push({
|
|
9455
|
+
kind: "columns",
|
|
9456
|
+
cells: zoneCells,
|
|
9457
|
+
lineHeightPt: Math.max(12, Math.round(maxFs * 1.35)),
|
|
9458
|
+
maxFontSize: maxFs
|
|
9459
|
+
});
|
|
9460
|
+
} else {
|
|
9461
|
+
const segs = normalizeHfSegments(
|
|
9462
|
+
buildStyledSegmentsForSpan(resolvedStory, item.pStart, item.pEnd, 9, hfCtx)
|
|
9463
|
+
);
|
|
9464
|
+
const wrappedLines = wrapSegmentsToLines(segs, availW, align, autoHyphenation);
|
|
9465
|
+
for (const ln of wrappedLines) {
|
|
9466
|
+
if (ln.tokens.length === 0) continue;
|
|
9467
|
+
collectedRows.push({
|
|
9468
|
+
kind: "single",
|
|
9469
|
+
line: ln,
|
|
9470
|
+
xBase: marginLeft,
|
|
9471
|
+
width: availW
|
|
9472
|
+
});
|
|
9473
|
+
}
|
|
9474
|
+
}
|
|
9475
|
+
}
|
|
9476
|
+
}
|
|
9477
|
+
if (collectedRows.length === 0) return false;
|
|
9478
|
+
targetOps.push("q");
|
|
9479
|
+
targetOps.push(`% DocStory:${role}:page=${pageIndex + 1}`);
|
|
9480
|
+
const marginDist = role === "header" ? Math.max(16, Math.min(42, Number(docStyle.marginHeader ?? 24) || 24)) : Math.max(18, Math.min(40, Number(docStyle.marginFooter ?? 24) || 24));
|
|
9481
|
+
let rowY = role === "header" ? pgH - marginDist - 9 : marginDist + (collectedRows.length - 1) * 12;
|
|
9482
|
+
for (const row of collectedRows) {
|
|
9483
|
+
if (row.kind === "single") {
|
|
9484
|
+
const ln = row.line;
|
|
9485
|
+
let lx = row.xBase;
|
|
9486
|
+
if (ln.align === "center") {
|
|
9487
|
+
lx = row.xBase + Math.max(0, (row.width - ln.totalWidthPt) / 2);
|
|
9488
|
+
} else if (ln.align === "right") {
|
|
9489
|
+
lx = row.xBase + Math.max(0, row.width - ln.totalWidthPt);
|
|
9490
|
+
}
|
|
9491
|
+
renderTokensRowAt(targetOps, ln.tokens, lx, rowY, pageIndex);
|
|
9492
|
+
rowY -= Math.max(12, Math.min(18, ln.lineHeightPt * 0.78));
|
|
9493
|
+
} else {
|
|
9494
|
+
for (const cell of row.cells) {
|
|
9495
|
+
const ln = cell.line;
|
|
9496
|
+
if (ln.tokens.length === 0) continue;
|
|
9497
|
+
let lx = cell.xBase;
|
|
9498
|
+
if (ln.align === "center") {
|
|
9499
|
+
lx = cell.xBase + Math.max(0, (cell.width - ln.totalWidthPt) / 2);
|
|
9500
|
+
} else if (ln.align === "right") {
|
|
9501
|
+
lx = cell.xBase + Math.max(0, cell.width - ln.totalWidthPt);
|
|
9502
|
+
}
|
|
9503
|
+
renderTokensRowAt(targetOps, ln.tokens, lx, rowY, pageIndex);
|
|
9504
|
+
}
|
|
9505
|
+
rowY -= row.lineHeightPt;
|
|
9506
|
+
}
|
|
9507
|
+
}
|
|
9508
|
+
targetOps.push("Q");
|
|
9509
|
+
return true;
|
|
9510
|
+
};
|
|
9223
9511
|
const totalPages = pageStreams.length;
|
|
9224
9512
|
const effectiveTotalNumbered = Math.max(1, totalPages - (fromPageNo - 1) + (startPageNo - 1));
|
|
9225
9513
|
for (let pageIdx = 0; pageIdx < totalPages; pageIdx++) {
|
|
@@ -9413,17 +9701,48 @@ function paginateSingleDocToPdfPages(rawSnapshot, options, imageNamePrefix = "Im
|
|
|
9413
9701
|
}
|
|
9414
9702
|
postOps.push("Q");
|
|
9415
9703
|
}
|
|
9416
|
-
|
|
9704
|
+
let renderedExplicitDocFooter = false;
|
|
9705
|
+
if (!fieldsOnly && !pagelessMode) {
|
|
9706
|
+
const pageHdrBody = resolvePageHeaderBody(pageIdx);
|
|
9707
|
+
if (pageHdrBody) {
|
|
9708
|
+
renderStorySegmentIntoMarginOps(
|
|
9709
|
+
postOps,
|
|
9710
|
+
pageHdrBody,
|
|
9711
|
+
"header",
|
|
9712
|
+
pageIdx,
|
|
9713
|
+
pgW,
|
|
9714
|
+
pgH,
|
|
9715
|
+
logicalPageNo,
|
|
9716
|
+
totalPages
|
|
9717
|
+
);
|
|
9718
|
+
}
|
|
9719
|
+
const pageFtrBody = resolvePageFooterBody(pageIdx);
|
|
9720
|
+
if (pageFtrBody) {
|
|
9721
|
+
renderedExplicitDocFooter = renderStorySegmentIntoMarginOps(
|
|
9722
|
+
postOps,
|
|
9723
|
+
pageFtrBody,
|
|
9724
|
+
"footer",
|
|
9725
|
+
pageIdx,
|
|
9726
|
+
pgW,
|
|
9727
|
+
pgH,
|
|
9728
|
+
logicalPageNo,
|
|
9729
|
+
totalPages
|
|
9730
|
+
);
|
|
9731
|
+
}
|
|
9732
|
+
}
|
|
9733
|
+
const hasExplicitOptionPageFormat = Boolean(options?.pageNumberFormat);
|
|
9734
|
+
const shouldShowFooter = (!renderedExplicitDocFooter || hasExplicitOptionPageFormat) && (fieldsOnly ? options?.showPageFooter === true : !pagelessMode && options?.showPageFooter !== false) && pageIdx + 1 >= fromPageNo;
|
|
9417
9735
|
if (shouldShowFooter) {
|
|
9418
9736
|
const fmtTemplate = pageNumberFormat || "Page {pageNo} / {pageCount}";
|
|
9419
9737
|
const footerLabel = fmtTemplate.replace(/\{pageNo\}/g, fmtPgToken(logicalPageNo)).replace(/\{pageCount\}/g, fmtPgToken(effectiveTotalNumbered));
|
|
9420
9738
|
const fw = measureTextWidthPt(footerLabel, 9);
|
|
9421
9739
|
const fx = pageNumberAlign === "left" ? marginLeft : pageNumberAlign === "right" ? pgW - marginRight - fw : (pgW - fw) / 2;
|
|
9740
|
+
const syntheticFooterY = renderedExplicitDocFooter ? 12 : 26;
|
|
9422
9741
|
emitPdfMixedTextOps(
|
|
9423
9742
|
postOps,
|
|
9424
9743
|
footerLabel,
|
|
9425
9744
|
fx,
|
|
9426
|
-
|
|
9745
|
+
syntheticFooterY,
|
|
9427
9746
|
9,
|
|
9428
9747
|
false,
|
|
9429
9748
|
{ r: 0.45, g: 0.51, b: 0.59 }
|
|
@@ -9652,6 +9971,85 @@ function exportBatchDocPdfBytes(templateSnapshot, records, options) {
|
|
|
9652
9971
|
`${templateSnapshot.title || "Batch Mail-Merge"} (${effectiveRecords.length})`
|
|
9653
9972
|
);
|
|
9654
9973
|
}
|
|
9974
|
+
function unescapePdfAsciiLiteral(raw) {
|
|
9975
|
+
let out = "";
|
|
9976
|
+
for (let i = 0; i < raw.length; i++) {
|
|
9977
|
+
if (raw[i] === "\\" && i + 1 < raw.length) {
|
|
9978
|
+
const next = raw[++i];
|
|
9979
|
+
if (next === "n") out += "\n";
|
|
9980
|
+
else if (next === "r") out += "\r";
|
|
9981
|
+
else if (next === "t") out += " ";
|
|
9982
|
+
else out += next;
|
|
9983
|
+
} else {
|
|
9984
|
+
out += raw[i];
|
|
9985
|
+
}
|
|
9986
|
+
}
|
|
9987
|
+
return out;
|
|
9988
|
+
}
|
|
9989
|
+
function decodePdfHexUtf16Be(hexRaw) {
|
|
9990
|
+
const clean = hexRaw.replace(/\s+/g, "");
|
|
9991
|
+
const start = clean.toUpperCase().startsWith("FEFF") ? 4 : 0;
|
|
9992
|
+
let out = "";
|
|
9993
|
+
for (let i = start; i + 3 < clean.length; i += 4) {
|
|
9994
|
+
const code = parseInt(clean.slice(i, i + 4), 16);
|
|
9995
|
+
if (!Number.isNaN(code)) {
|
|
9996
|
+
out += String.fromCharCode(code);
|
|
9997
|
+
}
|
|
9998
|
+
}
|
|
9999
|
+
return out;
|
|
10000
|
+
}
|
|
10001
|
+
function extractNativeTextSpansFromPdfBytes(pdfBytes) {
|
|
10002
|
+
const rawPdf = new TextDecoder("latin1").decode(pdfBytes);
|
|
10003
|
+
const objects = /* @__PURE__ */ new Map();
|
|
10004
|
+
const objRe = /(\d+)\s+0\s+obj\r?\n([\s\S]*?)\r?\nendobj/g;
|
|
10005
|
+
let om;
|
|
10006
|
+
while ((om = objRe.exec(rawPdf)) !== null) {
|
|
10007
|
+
objects.set(Number(om[1]), om[2]);
|
|
10008
|
+
}
|
|
10009
|
+
let pageObjIds = [];
|
|
10010
|
+
for (const bodyStr of objects.values()) {
|
|
10011
|
+
if (/\/Type\s*\/Pages\b/.test(bodyStr)) {
|
|
10012
|
+
const kidsMatch = bodyStr.match(/\/Kids\s*\[([^\]]*)\]/);
|
|
10013
|
+
if (kidsMatch) {
|
|
10014
|
+
pageObjIds = Array.from(kidsMatch[1].matchAll(/(\d+)\s+0\s+R/g)).map(
|
|
10015
|
+
(m) => Number(m[1])
|
|
10016
|
+
);
|
|
10017
|
+
break;
|
|
10018
|
+
}
|
|
10019
|
+
}
|
|
10020
|
+
}
|
|
10021
|
+
if (pageObjIds.length === 0) {
|
|
10022
|
+
for (const [id, bodyStr] of objects.entries()) {
|
|
10023
|
+
if (/\/Type\s*\/Page\b/.test(bodyStr)) {
|
|
10024
|
+
pageObjIds.push(id);
|
|
10025
|
+
}
|
|
10026
|
+
}
|
|
10027
|
+
pageObjIds.sort((a, b) => a - b);
|
|
10028
|
+
}
|
|
10029
|
+
return pageObjIds.map((pageObjId, pageIndex) => {
|
|
10030
|
+
const pageDict = objects.get(pageObjId) || "";
|
|
10031
|
+
const contentsId = Number(pageDict.match(/\/Contents\s+(\d+)\s+0\s+R/)?.[1] ?? 0);
|
|
10032
|
+
const streamObj = objects.get(contentsId) || "";
|
|
10033
|
+
const streamMatch = streamObj.match(/stream\r?\n([\s\S]*?)\r?\nendstream/);
|
|
10034
|
+
const streamBody = streamMatch ? streamMatch[1] : "";
|
|
10035
|
+
const spans = [];
|
|
10036
|
+
const tjRe = /\(((?:\\.|[^\\)])*)\)\s*Tj|<([0-9A-Fa-f\s]+)>\s*Tj/g;
|
|
10037
|
+
let tm;
|
|
10038
|
+
while ((tm = tjRe.exec(streamBody)) !== null) {
|
|
10039
|
+
if (tm[1] !== void 0) {
|
|
10040
|
+
spans.push(unescapePdfAsciiLiteral(tm[1]));
|
|
10041
|
+
} else if (tm[2] !== void 0) {
|
|
10042
|
+
spans.push(decodePdfHexUtf16Be(tm[2]));
|
|
10043
|
+
}
|
|
10044
|
+
}
|
|
10045
|
+
return {
|
|
10046
|
+
pageIndex,
|
|
10047
|
+
pageNumber: pageIndex + 1,
|
|
10048
|
+
spans,
|
|
10049
|
+
text: spans.join("")
|
|
10050
|
+
};
|
|
10051
|
+
});
|
|
10052
|
+
}
|
|
9655
10053
|
|
|
9656
10054
|
// src/exporter/docx-exporter.ts
|
|
9657
10055
|
import {
|
|
@@ -9673,7 +10071,7 @@ import {
|
|
|
9673
10071
|
TableRowHeightRule,
|
|
9674
10072
|
TableSizeType,
|
|
9675
10073
|
TextDecoration as TextDecoration2,
|
|
9676
|
-
Tools as
|
|
10074
|
+
Tools as Tools6,
|
|
9677
10075
|
VerticalAlignmentType,
|
|
9678
10076
|
WrapTextType
|
|
9679
10077
|
} from "@univerjs/core";
|
|
@@ -10415,7 +10813,7 @@ function serializeSpanToRunsAndSdtXml(body, spanStart, spanEndExclusive, exportC
|
|
|
10415
10813
|
(r) => r.rangeType === CustomRangeType5.HYPERLINK && r.startIndex >= spanStart && r.endIndex < spanEndExclusive && !exportCtx?.excludeRangeIds?.has(r.rangeId)
|
|
10416
10814
|
);
|
|
10417
10815
|
const docFieldRanges = (body.customRanges ?? []).filter(
|
|
10418
|
-
(r) => r.properties?.yudaoBlockKind === "docField" && r.startIndex >= spanStart && r.endIndex < spanEndExclusive
|
|
10816
|
+
(r) => (r.properties?.yudaoBlockKind === "docField" || typeof r.properties?.fieldInstr === "string") && r.startIndex >= spanStart && r.endIndex < spanEndExclusive
|
|
10419
10817
|
);
|
|
10420
10818
|
const noteRanges = (body.customRanges ?? []).filter(
|
|
10421
10819
|
(r) => (r.rangeType === CustomRangeType5.FOOTNOTE || r.rangeType === CustomRangeType5.ENDNOTE) && r.startIndex >= spanStart && r.endIndex < spanEndExclusive
|
|
@@ -10508,11 +10906,14 @@ function serializeSpanToRunsAndSdtXml(body, spanStart, spanEndExclusive, exportC
|
|
|
10508
10906
|
}
|
|
10509
10907
|
const fieldAtCursor = docFieldRanges.find((r) => r.startIndex === cursor);
|
|
10510
10908
|
if (fieldAtCursor) {
|
|
10511
|
-
const
|
|
10512
|
-
const
|
|
10909
|
+
const fProps = fieldAtCursor.properties ?? {};
|
|
10910
|
+
const fldObj = fProps.field;
|
|
10911
|
+
const instrText = String(
|
|
10912
|
+
fProps.fieldInstr || fldObj?.instrText || fldObj?.fieldType || "PAGE"
|
|
10913
|
+
).trim();
|
|
10513
10914
|
const fldValText = stream.slice(fieldAtCursor.startIndex, fieldAtCursor.endIndex + 1).replace(/[\r\n\u0000-\u001F]/g, "");
|
|
10514
10915
|
const fldStyle = findStyleAtBody(body, fieldAtCursor.startIndex);
|
|
10515
|
-
if (fldObj?.sourceKind === "complex") {
|
|
10916
|
+
if (fldObj?.sourceKind === "complex" || fProps.fieldSimple === false) {
|
|
10516
10917
|
const rPr = buildRunPrXml(fldStyle);
|
|
10517
10918
|
const valRuns = buildRunXmlWithBreaks(fldValText, fldStyle);
|
|
10518
10919
|
innerXml.push(
|
|
@@ -15684,7 +16085,7 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
|
|
|
15684
16085
|
const drw = collectedDrawings[blkId];
|
|
15685
16086
|
if (drw) {
|
|
15686
16087
|
drw.isMultiTransform = BooleanNumber2.TRUE;
|
|
15687
|
-
drw.transforms = Array.isArray(drw.transforms) && drw.transforms.length > 0 ? drw.transforms : drw.transform ? [
|
|
16088
|
+
drw.transforms = Array.isArray(drw.transforms) && drw.transforms.length > 0 ? drw.transforms : drw.transform ? [Tools6.deepClone(drw.transform)] : [];
|
|
15688
16089
|
}
|
|
15689
16090
|
}
|
|
15690
16091
|
}
|
|
@@ -16367,12 +16768,12 @@ function updateDocImageTransformInSnapshot(sourceSnapshot, drawingId, spec) {
|
|
|
16367
16768
|
const existingDrw = sourceSnapshot.drawings?.[drawingId];
|
|
16368
16769
|
const hasBlock = (sourceSnapshot.body?.customBlocks ?? []).some((b) => b.blockId === drawingId);
|
|
16369
16770
|
if (!existingDrw && !hasBlock) return null;
|
|
16370
|
-
const nextSnapshot =
|
|
16771
|
+
const nextSnapshot = Tools7.deepClone(sourceSnapshot);
|
|
16371
16772
|
const meta = readDocTemplateMetadataFromSnapshot(nextSnapshot);
|
|
16372
16773
|
const prevTransform = meta.imageTransforms?.[drawingId] ?? existingDrw?.yudaoTransform ?? {};
|
|
16373
16774
|
const mergedTransform = {
|
|
16374
|
-
...
|
|
16375
|
-
...
|
|
16775
|
+
...Tools7.deepClone(prevTransform),
|
|
16776
|
+
...Tools7.deepClone(spec),
|
|
16376
16777
|
...spec.crop ? {
|
|
16377
16778
|
crop: {
|
|
16378
16779
|
left: Number(spec.crop.left) || 0,
|
|
@@ -16380,7 +16781,7 @@ function updateDocImageTransformInSnapshot(sourceSnapshot, drawingId, spec) {
|
|
|
16380
16781
|
right: Number(spec.crop.right) || 0,
|
|
16381
16782
|
bottom: Number(spec.crop.bottom) || 0
|
|
16382
16783
|
}
|
|
16383
|
-
} : prevTransform.crop ? { crop:
|
|
16784
|
+
} : prevTransform.crop ? { crop: Tools7.deepClone(prevTransform.crop) } : {}
|
|
16384
16785
|
};
|
|
16385
16786
|
if (!nextSnapshot.drawings) {
|
|
16386
16787
|
nextSnapshot.drawings = {};
|
|
@@ -16394,7 +16795,7 @@ function updateDocImageTransformInSnapshot(sourceSnapshot, drawingId, spec) {
|
|
|
16394
16795
|
};
|
|
16395
16796
|
}
|
|
16396
16797
|
const drw = drwMap[drawingId];
|
|
16397
|
-
drw.yudaoTransform =
|
|
16798
|
+
drw.yudaoTransform = Tools7.deepClone(mergedTransform);
|
|
16398
16799
|
if (typeof mergedTransform.rotationDeg === "number") {
|
|
16399
16800
|
drw.docTransform = {
|
|
16400
16801
|
...drw.docTransform ?? {},
|
|
@@ -16421,11 +16822,11 @@ function updateDocImageTransformInSnapshot(sourceSnapshot, drawingId, spec) {
|
|
|
16421
16822
|
function getDocImageTransformFromSnapshot(snapshot, drawingId) {
|
|
16422
16823
|
const meta = readDocTemplateMetadataFromSnapshot(snapshot);
|
|
16423
16824
|
if (meta.imageTransforms?.[drawingId]) {
|
|
16424
|
-
return
|
|
16825
|
+
return Tools7.deepClone(meta.imageTransforms[drawingId]);
|
|
16425
16826
|
}
|
|
16426
16827
|
const drw = snapshot?.drawings?.[drawingId];
|
|
16427
16828
|
if (drw?.yudaoTransform) {
|
|
16428
|
-
return
|
|
16829
|
+
return Tools7.deepClone(drw.yudaoTransform);
|
|
16429
16830
|
}
|
|
16430
16831
|
return void 0;
|
|
16431
16832
|
}
|
|
@@ -16682,7 +17083,7 @@ function attachSmartArtMetaRangeOnBody(body, blockId, insertOffset, spec) {
|
|
|
16682
17083
|
properties: {
|
|
16683
17084
|
yudaoBlockKind: "smartArt",
|
|
16684
17085
|
blockId,
|
|
16685
|
-
spec:
|
|
17086
|
+
spec: Tools7.deepClone(spec)
|
|
16686
17087
|
}
|
|
16687
17088
|
});
|
|
16688
17089
|
body.customRanges.sort((a, b) => a.startIndex - b.startIndex || a.endIndex - b.endIndex);
|
|
@@ -16691,7 +17092,7 @@ function insertSmartArtIntoSnapshot(sourceSnapshot, spec, offset) {
|
|
|
16691
17092
|
if (!sourceSnapshot.body) return null;
|
|
16692
17093
|
const id = spec.id || `smartart_${generateRandomId6(6)}`;
|
|
16693
17094
|
const fullSpec = {
|
|
16694
|
-
...
|
|
17095
|
+
...Tools7.deepClone(spec),
|
|
16695
17096
|
id,
|
|
16696
17097
|
layout: spec.layout ?? "process",
|
|
16697
17098
|
nodes: spec.nodes ?? []
|
|
@@ -16729,11 +17130,11 @@ function updateSmartArtInSnapshot(sourceSnapshot, id, patch) {
|
|
|
16729
17130
|
if (!existing && !blk) return null;
|
|
16730
17131
|
const merged = {
|
|
16731
17132
|
...existing ?? { id, layout: "process", nodes: [] },
|
|
16732
|
-
...
|
|
17133
|
+
...Tools7.deepClone(patch),
|
|
16733
17134
|
id
|
|
16734
17135
|
};
|
|
16735
17136
|
const rendered = renderSmartArtToSvgDataUri(merged);
|
|
16736
|
-
const nextSnapshot =
|
|
17137
|
+
const nextSnapshot = Tools7.deepClone(sourceSnapshot);
|
|
16737
17138
|
const drw = nextSnapshot.drawings?.[id];
|
|
16738
17139
|
if (drw) {
|
|
16739
17140
|
drw.source = rendered.dataUri;
|
|
@@ -16771,7 +17172,7 @@ function listLiveSmartArts(snapshot) {
|
|
|
16771
17172
|
if (liveBlockIds.has(props.blockId)) {
|
|
16772
17173
|
fromRanges.set(props.blockId, {
|
|
16773
17174
|
order: r.startIndex,
|
|
16774
|
-
spec: { ...
|
|
17175
|
+
spec: { ...Tools7.deepClone(props.spec), id: props.blockId }
|
|
16775
17176
|
});
|
|
16776
17177
|
}
|
|
16777
17178
|
}
|
|
@@ -16780,7 +17181,7 @@ function listLiveSmartArts(snapshot) {
|
|
|
16780
17181
|
for (const [id, spec] of Object.entries(meta.smartArts ?? {})) {
|
|
16781
17182
|
if (!fromRanges.has(id) && (liveBlockIds.size === 0 || liveBlockIds.has(id))) {
|
|
16782
17183
|
const blk = (body?.customBlocks ?? []).find((b) => b.blockId === id);
|
|
16783
|
-
fromRanges.set(id, { order: blk?.startIndex ?? 999999, spec: { ...
|
|
17184
|
+
fromRanges.set(id, { order: blk?.startIndex ?? 999999, spec: { ...Tools7.deepClone(spec), id } });
|
|
16784
17185
|
}
|
|
16785
17186
|
}
|
|
16786
17187
|
return Array.from(fromRanges.values()).sort((a, b) => a.order - b.order).map((x) => x.spec);
|
|
@@ -16863,7 +17264,7 @@ function insertDocTableRowInSnapshot(sourceSnapshot, tableIndex, rowIndex, posit
|
|
|
16863
17264
|
const targetSpan = parsedRows[clampedRow];
|
|
16864
17265
|
const insertAt = position === "above" ? targetSpan.rowStart : targetSpan.rowEndInclusive + 1;
|
|
16865
17266
|
const targetRowIdx = position === "above" ? clampedRow : clampedRow + 1;
|
|
16866
|
-
const nextSnapshot =
|
|
17267
|
+
const nextSnapshot = Tools7.deepClone(sourceSnapshot);
|
|
16867
17268
|
const nextBody = nextSnapshot.body;
|
|
16868
17269
|
const tblDef = nextSnapshot.tableSource?.[tblRef.tableId];
|
|
16869
17270
|
const colCount = Math.max(
|
|
@@ -16911,7 +17312,7 @@ function deleteDocTableRowInSnapshot(sourceSnapshot, tableIndex, rowIndex) {
|
|
|
16911
17312
|
if (!body || !tblRef) return null;
|
|
16912
17313
|
const parsedRows = parseTableRowsInStream(body.dataStream, tblRef.startIndex, tblRef.endIndex);
|
|
16913
17314
|
if (rowIndex < 0 || rowIndex >= parsedRows.length) return null;
|
|
16914
|
-
const nextSnapshot =
|
|
17315
|
+
const nextSnapshot = Tools7.deepClone(sourceSnapshot);
|
|
16915
17316
|
const nextBody = nextSnapshot.body;
|
|
16916
17317
|
if (parsedRows.length === 1) {
|
|
16917
17318
|
const rmStart2 = tblRef.startIndex;
|
|
@@ -16948,7 +17349,7 @@ function insertDocTableColumnInSnapshot(sourceSnapshot, tableIndex, colIndex, po
|
|
|
16948
17349
|
const curColCount = Math.max(1, ...parsedRows.map((r) => r.cells.length));
|
|
16949
17350
|
const clampedCol = Math.max(0, Math.min(colIndex, curColCount - 1));
|
|
16950
17351
|
const insertColIdx = position === "left" ? clampedCol : clampedCol + 1;
|
|
16951
|
-
const nextSnapshot =
|
|
17352
|
+
const nextSnapshot = Tools7.deepClone(sourceSnapshot);
|
|
16952
17353
|
const nextBody = nextSnapshot.body;
|
|
16953
17354
|
for (let rIdx = parsedRows.length - 1; rIdx >= 0; rIdx--) {
|
|
16954
17355
|
const rSpan = parsedRows[rIdx];
|
|
@@ -16997,7 +17398,7 @@ function deleteDocTableColumnInSnapshot(sourceSnapshot, tableIndex, colIndex) {
|
|
|
16997
17398
|
if (parsedRows.length === 0) return null;
|
|
16998
17399
|
const curColCount = Math.max(1, ...parsedRows.map((r) => r.cells.length));
|
|
16999
17400
|
if (colIndex < 0 || colIndex >= curColCount) return null;
|
|
17000
|
-
const nextSnapshot =
|
|
17401
|
+
const nextSnapshot = Tools7.deepClone(sourceSnapshot);
|
|
17001
17402
|
const nextBody = nextSnapshot.body;
|
|
17002
17403
|
if (curColCount === 1) {
|
|
17003
17404
|
const rmStart = tblRef.startIndex;
|
|
@@ -17062,7 +17463,7 @@ function mergeDocTableCellsInSnapshot(sourceSnapshot, tableIndex, startRow, star
|
|
|
17062
17463
|
const r2 = Math.min(parsedRows.length - 1, Math.max(startRow, endRow));
|
|
17063
17464
|
const c1 = Math.max(0, Math.min(startCol, endCol));
|
|
17064
17465
|
const c2 = Math.min(colCount - 1, Math.max(startCol, endCol));
|
|
17065
|
-
if (r1 === r2 && c1 === c2) return
|
|
17466
|
+
if (r1 === r2 && c1 === c2) return Tools7.deepClone(sourceSnapshot);
|
|
17066
17467
|
const rowSpan = r2 - r1 + 1;
|
|
17067
17468
|
const colSpan = c2 - c1 + 1;
|
|
17068
17469
|
const mergedTexts = [];
|
|
@@ -17073,7 +17474,7 @@ function mergeDocTableCellsInSnapshot(sourceSnapshot, tableIndex, startRow, star
|
|
|
17073
17474
|
}
|
|
17074
17475
|
}
|
|
17075
17476
|
const combinedText = mergedTexts.join(" ");
|
|
17076
|
-
const nextSnapshot =
|
|
17477
|
+
const nextSnapshot = Tools7.deepClone(sourceSnapshot);
|
|
17077
17478
|
let workingBody = nextSnapshot.body;
|
|
17078
17479
|
for (let r = r2; r >= r1; r--) {
|
|
17079
17480
|
for (let c = c2; c >= c1; c--) {
|
|
@@ -17146,7 +17547,7 @@ function splitDocTableCellInSnapshot(sourceSnapshot, tableIndex, row, col) {
|
|
|
17146
17547
|
const tblDef = sourceSnapshot.tableSource?.[tblRef.tableId];
|
|
17147
17548
|
const master = findMergedMasterInTableRows(tblDef?.tableRows, row, col);
|
|
17148
17549
|
if (!master) return null;
|
|
17149
|
-
const nextSnapshot =
|
|
17550
|
+
const nextSnapshot = Tools7.deepClone(sourceSnapshot);
|
|
17150
17551
|
const nextTblDef = nextSnapshot.tableSource?.[tblRef.tableId];
|
|
17151
17552
|
if (!nextTblDef?.tableRows) return null;
|
|
17152
17553
|
for (let r = master.row; r < master.row + master.rowSpan; r++) {
|
|
@@ -17282,7 +17683,7 @@ function evaluateSingleFieldValue(snapshot, fieldType, instructionArgs, seqCount
|
|
|
17282
17683
|
function insertDocFieldIntoSnapshot(sourceSnapshot, fieldType, instructionArgs, offset, context) {
|
|
17283
17684
|
const body = sourceSnapshot.body;
|
|
17284
17685
|
if (!body) return null;
|
|
17285
|
-
const nextSnapshot =
|
|
17686
|
+
const nextSnapshot = Tools7.deepClone(sourceSnapshot);
|
|
17286
17687
|
const nextBody = nextSnapshot.body;
|
|
17287
17688
|
const id = `fld_${generateRandomId6(6)}`;
|
|
17288
17689
|
const cleanArgs = instructionArgs?.trim();
|
|
@@ -17325,7 +17726,9 @@ function insertDocFieldIntoSnapshot(sourceSnapshot, fieldType, instructionArgs,
|
|
|
17325
17726
|
endIndex: entry.endIndex,
|
|
17326
17727
|
properties: {
|
|
17327
17728
|
yudaoBlockKind: "docField",
|
|
17328
|
-
|
|
17729
|
+
fieldInstr: entry.instrText,
|
|
17730
|
+
fieldSimple: true,
|
|
17731
|
+
field: Tools7.deepClone(entry)
|
|
17329
17732
|
}
|
|
17330
17733
|
});
|
|
17331
17734
|
spliced.customRanges.sort((a, b) => a.startIndex - b.startIndex || a.endIndex - b.endIndex);
|
|
@@ -17345,7 +17748,7 @@ function insertDocFieldIntoSnapshot(sourceSnapshot, fieldType, instructionArgs,
|
|
|
17345
17748
|
};
|
|
17346
17749
|
}
|
|
17347
17750
|
function setDocCustomPropertiesInSnapshot(sourceSnapshot, customProperties, company) {
|
|
17348
|
-
const nextSnapshot =
|
|
17751
|
+
const nextSnapshot = Tools7.deepClone(sourceSnapshot);
|
|
17349
17752
|
const meta = readDocTemplateMetadataFromSnapshot(nextSnapshot);
|
|
17350
17753
|
const nextCustom = {
|
|
17351
17754
|
...meta.customProperties ?? {},
|
|
@@ -17378,13 +17781,28 @@ function listDocFields(snapshot) {
|
|
|
17378
17781
|
const f = props.field;
|
|
17379
17782
|
const liveVal = stream.slice(r.startIndex, r.endIndex + 1).replace(/[\r\n\u0000-\u001F]/g, "");
|
|
17380
17783
|
items.push({
|
|
17381
|
-
...
|
|
17784
|
+
...Tools7.deepClone(f),
|
|
17382
17785
|
id: r.rangeId,
|
|
17786
|
+
instrText: String(props.fieldInstr || f.instrText || f.fieldType),
|
|
17383
17787
|
value: liveVal || f.value,
|
|
17384
17788
|
...segmentId ? { segmentId } : {},
|
|
17385
17789
|
startIndex: r.startIndex,
|
|
17386
17790
|
endIndex: r.endIndex
|
|
17387
17791
|
});
|
|
17792
|
+
} else if (typeof props?.fieldInstr === "string" && props.fieldInstr.trim()) {
|
|
17793
|
+
const parsedInstr = parseFieldInstrString(props.fieldInstr);
|
|
17794
|
+
const liveVal = stream.slice(r.startIndex, r.endIndex + 1).replace(/[\r\n\u0000-\u001F]/g, "");
|
|
17795
|
+
items.push({
|
|
17796
|
+
id: r.rangeId,
|
|
17797
|
+
fieldType: parsedInstr.fieldType,
|
|
17798
|
+
...parsedInstr.instructionArgs ? { instructionArgs: parsedInstr.instructionArgs } : {},
|
|
17799
|
+
instrText: props.fieldInstr.trim(),
|
|
17800
|
+
value: liveVal || "1",
|
|
17801
|
+
sourceKind: props.fieldSimple === false ? "complex" : "simple",
|
|
17802
|
+
...segmentId ? { segmentId } : {},
|
|
17803
|
+
startIndex: r.startIndex,
|
|
17804
|
+
endIndex: r.endIndex
|
|
17805
|
+
});
|
|
17388
17806
|
}
|
|
17389
17807
|
}
|
|
17390
17808
|
items.sort((a, b) => (a.startIndex ?? 0) - (b.startIndex ?? 0));
|
|
@@ -17410,7 +17828,7 @@ function updateAllDocFieldsInSnapshot(snapshot, context) {
|
|
|
17410
17828
|
const liveBody = resolveSegmentBodyInSnapshot(snapshot, fld.segmentId);
|
|
17411
17829
|
if (!liveBody) continue;
|
|
17412
17830
|
const range = (liveBody.customRanges ?? []).find(
|
|
17413
|
-
(r) => r.rangeId === fld.id && r.properties?.yudaoBlockKind === "docField"
|
|
17831
|
+
(r) => r.rangeId === fld.id && (r.properties?.yudaoBlockKind === "docField" || typeof r.properties?.fieldInstr === "string")
|
|
17414
17832
|
);
|
|
17415
17833
|
if (!range) continue;
|
|
17416
17834
|
const nextVal = evaluateSingleFieldValue(
|
|
@@ -17437,7 +17855,9 @@ function updateAllDocFieldsInSnapshot(snapshot, context) {
|
|
|
17437
17855
|
targetRangeId: fld.id,
|
|
17438
17856
|
updatedRangeProperties: {
|
|
17439
17857
|
yudaoBlockKind: "docField",
|
|
17440
|
-
|
|
17858
|
+
fieldInstr: updatedEntry.instrText,
|
|
17859
|
+
...updatedEntry.sourceKind ? { fieldSimple: updatedEntry.sourceKind === "simple" } : {},
|
|
17860
|
+
field: Tools7.deepClone(updatedEntry)
|
|
17441
17861
|
},
|
|
17442
17862
|
textStyle: fld.preserveStyle ? void 0 : { cl: { rgb: "#2C53F1" }, bg: { rgb: "#F3F5FF" } }
|
|
17443
17863
|
}
|
|
@@ -17459,7 +17879,7 @@ function updateAllDocFieldsInSnapshot(snapshot, context) {
|
|
|
17459
17879
|
const liveBody = resolveSegmentBodyInSnapshot(snapshot, fld.segmentId);
|
|
17460
17880
|
if (!liveBody) continue;
|
|
17461
17881
|
const range = (liveBody.customRanges ?? []).find(
|
|
17462
|
-
(r) => r.rangeId === fld.id && r.properties?.yudaoBlockKind === "docField"
|
|
17882
|
+
(r) => r.rangeId === fld.id && (r.properties?.yudaoBlockKind === "docField" || typeof r.properties?.fieldInstr === "string")
|
|
17463
17883
|
);
|
|
17464
17884
|
if (!range) continue;
|
|
17465
17885
|
const nextVal = evaluateSingleFieldValue(
|
|
@@ -17486,7 +17906,9 @@ function updateAllDocFieldsInSnapshot(snapshot, context) {
|
|
|
17486
17906
|
targetRangeId: fld.id,
|
|
17487
17907
|
updatedRangeProperties: {
|
|
17488
17908
|
yudaoBlockKind: "docField",
|
|
17489
|
-
|
|
17909
|
+
fieldInstr: updatedEntry.instrText,
|
|
17910
|
+
...updatedEntry.sourceKind ? { fieldSimple: updatedEntry.sourceKind === "simple" } : {},
|
|
17911
|
+
field: Tools7.deepClone(updatedEntry)
|
|
17490
17912
|
},
|
|
17491
17913
|
textStyle: fld.preserveStyle ? void 0 : { cl: { rgb: "#2C53F1" }, bg: { rgb: "#F3F5FF" } }
|
|
17492
17914
|
}
|
|
@@ -17510,7 +17932,7 @@ function updateAllDocFieldsInSnapshot(snapshot, context) {
|
|
|
17510
17932
|
function insertCaptionIntoSnapshot(sourceSnapshot, category, title, offset) {
|
|
17511
17933
|
const body = sourceSnapshot.body;
|
|
17512
17934
|
if (!body) return null;
|
|
17513
|
-
const nextSnapshot =
|
|
17935
|
+
const nextSnapshot = Tools7.deepClone(sourceSnapshot);
|
|
17514
17936
|
const nextBody = nextSnapshot.body;
|
|
17515
17937
|
const insertAt = clampSafeInsertOffset(nextBody, offset);
|
|
17516
17938
|
const sortedParas = [...nextBody.paragraphs ?? []].sort((a, b) => a.startIndex - b.startIndex);
|
|
@@ -17583,7 +18005,7 @@ function insertCaptionIntoSnapshot(sourceSnapshot, category, title, offset) {
|
|
|
17583
18005
|
endIndex: numEndInclusive,
|
|
17584
18006
|
properties: {
|
|
17585
18007
|
yudaoBlockKind: "docField",
|
|
17586
|
-
field:
|
|
18008
|
+
field: Tools7.deepClone(fieldEntry)
|
|
17587
18009
|
}
|
|
17588
18010
|
},
|
|
17589
18011
|
{
|
|
@@ -17593,7 +18015,7 @@ function insertCaptionIntoSnapshot(sourceSnapshot, category, title, offset) {
|
|
|
17593
18015
|
endIndex: lineEndInclusive,
|
|
17594
18016
|
properties: {
|
|
17595
18017
|
yudaoBlockKind: "caption",
|
|
17596
|
-
caption:
|
|
18018
|
+
caption: Tools7.deepClone(captionEntry)
|
|
17597
18019
|
}
|
|
17598
18020
|
},
|
|
17599
18021
|
{
|
|
@@ -17639,7 +18061,7 @@ function listDocCaptions(snapshot) {
|
|
|
17639
18061
|
const liveNum = linkedField ? Number(linkedField.value) || cap.number : cap.number;
|
|
17640
18062
|
const liveText = stream.slice(r.startIndex, r.endIndex + 1).replace(/[\r\n\u0000-\u001F]/g, "");
|
|
17641
18063
|
out.push({
|
|
17642
|
-
...
|
|
18064
|
+
...Tools7.deepClone(cap),
|
|
17643
18065
|
id: r.rangeId,
|
|
17644
18066
|
number: liveNum,
|
|
17645
18067
|
fullText: liveText || `${cap.category} ${liveNum}${cap.title ? `\uFF1A${cap.title}` : ""}`,
|
|
@@ -17662,14 +18084,14 @@ function insertCrossReferenceIntoSnapshot(sourceSnapshot, targetBookmarkOrCaptio
|
|
|
17662
18084
|
function insertCitationIntoSnapshot(sourceSnapshot, source, offset) {
|
|
17663
18085
|
const body = sourceSnapshot.body;
|
|
17664
18086
|
if (!body || !source?.id) return null;
|
|
17665
|
-
const nextSnapshot =
|
|
18087
|
+
const nextSnapshot = Tools7.deepClone(sourceSnapshot);
|
|
17666
18088
|
const meta = readDocTemplateMetadataFromSnapshot(nextSnapshot);
|
|
17667
18089
|
const existingSources = [...meta.citationSources ?? []];
|
|
17668
18090
|
let idx = existingSources.findIndex((s) => s.id === source.id);
|
|
17669
18091
|
if (idx >= 0) {
|
|
17670
|
-
existingSources[idx] =
|
|
18092
|
+
existingSources[idx] = Tools7.deepClone(source);
|
|
17671
18093
|
} else {
|
|
17672
|
-
existingSources.push(
|
|
18094
|
+
existingSources.push(Tools7.deepClone(source));
|
|
17673
18095
|
idx = existingSources.length - 1;
|
|
17674
18096
|
}
|
|
17675
18097
|
const citationNumber = idx + 1;
|
|
@@ -17709,12 +18131,12 @@ function insertCitationIntoSnapshot(sourceSnapshot, source, offset) {
|
|
|
17709
18131
|
}
|
|
17710
18132
|
function listDocCitations(snapshot) {
|
|
17711
18133
|
const meta = readDocTemplateMetadataFromSnapshot(snapshot);
|
|
17712
|
-
return
|
|
18134
|
+
return Tools7.deepClone(meta.citationSources ?? []);
|
|
17713
18135
|
}
|
|
17714
18136
|
function insertBibliographyIntoSnapshot(sourceSnapshot, offset, title) {
|
|
17715
18137
|
const body = sourceSnapshot.body;
|
|
17716
18138
|
if (!body) return null;
|
|
17717
|
-
const nextSnapshot =
|
|
18139
|
+
const nextSnapshot = Tools7.deepClone(sourceSnapshot);
|
|
17718
18140
|
const nextBody = nextSnapshot.body;
|
|
17719
18141
|
const sources = listDocCitations(nextSnapshot);
|
|
17720
18142
|
const lines = [title?.trim() || "\u53C2\u8003\u6587\u732E"];
|
|
@@ -17784,7 +18206,7 @@ function insertBibliographyIntoSnapshot(sourceSnapshot, offset, title) {
|
|
|
17784
18206
|
function insertBuildingBlockIntoSnapshot(sourceSnapshot, block, offset) {
|
|
17785
18207
|
const body = sourceSnapshot.body;
|
|
17786
18208
|
if (!body || !block) return null;
|
|
17787
|
-
const nextSnapshot =
|
|
18209
|
+
const nextSnapshot = Tools7.deepClone(sourceSnapshot);
|
|
17788
18210
|
let workingBody = nextSnapshot.body;
|
|
17789
18211
|
const insertAt = clampSafeInsertOffset(workingBody, offset);
|
|
17790
18212
|
const normalizedText = (block.content ?? "").replace(/\r\n/g, "\n").replace(/\n/g, DataStreamTreeTokenType8.PARAGRAPH);
|
|
@@ -17793,7 +18215,7 @@ function insertBuildingBlockIntoSnapshot(sourceSnapshot, block, offset) {
|
|
|
17793
18215
|
if (Array.isArray(block.sdtSpecs) && block.sdtSpecs.length > 0) {
|
|
17794
18216
|
for (const sdtSpec of block.sdtSpecs) {
|
|
17795
18217
|
const inserted = insertSdtControlIntoBody(workingBody, cursor, {
|
|
17796
|
-
...
|
|
18218
|
+
...Tools7.deepClone(sdtSpec),
|
|
17797
18219
|
id: `sdt_${generateRandomId6(6)}`
|
|
17798
18220
|
});
|
|
17799
18221
|
workingBody = inserted.body;
|
|
@@ -17811,7 +18233,7 @@ async function runMailMergeBatchOnSnapshot(templateSnapshot, records, format) {
|
|
|
17811
18233
|
const results = [];
|
|
17812
18234
|
for (let index = 0; index < effectiveRecords.length; index++) {
|
|
17813
18235
|
const record = effectiveRecords[index];
|
|
17814
|
-
const cloned =
|
|
18236
|
+
const cloned = Tools7.deepClone(templateSnapshot);
|
|
17815
18237
|
const filled = fillDatasetIntoDocSnapshot(cloned, record);
|
|
17816
18238
|
evaluateComputedSdtControlsInPlace(filled, record);
|
|
17817
18239
|
recalculateInlineFormulasInPlace(filled, record);
|
|
@@ -17848,7 +18270,7 @@ function spliceMultiParagraphBodySpan(sourceBody, start, endInclusive, replaceme
|
|
|
17848
18270
|
const oldLen = endInclusive >= start ? endInclusive - start + 1 : 0;
|
|
17849
18271
|
const newLen = replacementStream.length;
|
|
17850
18272
|
const delta = newLen - oldLen;
|
|
17851
|
-
const body =
|
|
18273
|
+
const body = Tools8.deepClone(sourceBody);
|
|
17852
18274
|
body.dataStream = body.dataStream.slice(0, start) + replacementStream + body.dataStream.slice(start + oldLen);
|
|
17853
18275
|
const insertedParas = [];
|
|
17854
18276
|
for (let i = 0; i < replacementStream.length; i++) {
|
|
@@ -17856,7 +18278,7 @@ function spliceMultiParagraphBodySpan(sourceBody, start, endInclusive, replaceme
|
|
|
17856
18278
|
insertedParas.push({
|
|
17857
18279
|
startIndex: start + i,
|
|
17858
18280
|
paragraphId: `p_mp_${generateRandomId7(6)}`,
|
|
17859
|
-
...options?.paragraphStyle ? { paragraphStyle:
|
|
18281
|
+
...options?.paragraphStyle ? { paragraphStyle: Tools8.deepClone(options.paragraphStyle) } : {}
|
|
17860
18282
|
});
|
|
17861
18283
|
}
|
|
17862
18284
|
}
|
|
@@ -17947,7 +18369,7 @@ function spliceMultiParagraphBodySpan(sourceBody, start, endInclusive, replaceme
|
|
|
17947
18369
|
shiftedRuns.push({
|
|
17948
18370
|
st: start + segStart,
|
|
17949
18371
|
ed: start + i,
|
|
17950
|
-
ts:
|
|
18372
|
+
ts: Tools8.deepClone(options.textStyle)
|
|
17951
18373
|
});
|
|
17952
18374
|
}
|
|
17953
18375
|
segStart = i + 1;
|
|
@@ -17979,7 +18401,7 @@ function insertStandaloneBlockParagraph(sourceBody, rawOffset, displayText, rang
|
|
|
17979
18401
|
...p,
|
|
17980
18402
|
paragraphStyle: {
|
|
17981
18403
|
...p.paragraphStyle ?? {},
|
|
17982
|
-
...
|
|
18404
|
+
...Tools8.deepClone(paragraphStyle)
|
|
17983
18405
|
}
|
|
17984
18406
|
} : p
|
|
17985
18407
|
);
|
|
@@ -17987,7 +18409,7 @@ function insertStandaloneBlockParagraph(sourceBody, rawOffset, displayText, rang
|
|
|
17987
18409
|
if (needsLeadingBreak && hostPara && body.paragraphs) {
|
|
17988
18410
|
const prevStyle = hostPara.paragraphStyle;
|
|
17989
18411
|
body.paragraphs = body.paragraphs.map(
|
|
17990
|
-
(p) => p.startIndex === insertAt && prevStyle ? { ...p, paragraphStyle:
|
|
18412
|
+
(p) => p.startIndex === insertAt && prevStyle ? { ...p, paragraphStyle: Tools8.deepClone(prevStyle) } : p
|
|
17991
18413
|
);
|
|
17992
18414
|
}
|
|
17993
18415
|
if (!body.customRanges) body.customRanges = [];
|
|
@@ -17996,7 +18418,7 @@ function insertStandaloneBlockParagraph(sourceBody, rawOffset, displayText, rang
|
|
|
17996
18418
|
rangeType,
|
|
17997
18419
|
startIndex: textStart,
|
|
17998
18420
|
endIndex: textEndInclusive,
|
|
17999
|
-
properties:
|
|
18421
|
+
properties: Tools8.deepClone(rangeProperties)
|
|
18000
18422
|
});
|
|
18001
18423
|
body.customRanges.sort((a, b) => a.startIndex - b.startIndex || a.endIndex - b.endIndex);
|
|
18002
18424
|
return {
|
|
@@ -18049,7 +18471,7 @@ function formatCalloutDisplayText(block) {
|
|
|
18049
18471
|
return prefix ? `${prefix} ${bodyText}` : bodyText || prefix || "[\u63D0\u793A]";
|
|
18050
18472
|
}
|
|
18051
18473
|
function insertCalloutIntoSnapshot(sourceSnapshot, spec, offset) {
|
|
18052
|
-
const nextSnapshot =
|
|
18474
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
18053
18475
|
const id = spec.id || `callout_${generateRandomId7(6)}`;
|
|
18054
18476
|
const preset = spec.preset ?? "info";
|
|
18055
18477
|
const theme = resolveCalloutPresetTheme(preset, spec);
|
|
@@ -18071,7 +18493,7 @@ function insertCalloutIntoSnapshot(sourceSnapshot, spec, offset) {
|
|
|
18071
18493
|
CustomRangeType7.CUSTOM,
|
|
18072
18494
|
{
|
|
18073
18495
|
yudaoBlockKind: "callout",
|
|
18074
|
-
callout:
|
|
18496
|
+
callout: Tools8.deepClone(callout)
|
|
18075
18497
|
},
|
|
18076
18498
|
{
|
|
18077
18499
|
cl: { rgb: theme.textColor },
|
|
@@ -18101,7 +18523,7 @@ function insertCalloutIntoSnapshot(sourceSnapshot, spec, offset) {
|
|
|
18101
18523
|
};
|
|
18102
18524
|
}
|
|
18103
18525
|
function updateCalloutInSnapshot(sourceSnapshot, id, patch) {
|
|
18104
|
-
const nextSnapshot =
|
|
18526
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
18105
18527
|
const body = nextSnapshot.body;
|
|
18106
18528
|
if (!body) return null;
|
|
18107
18529
|
const currentList = listDocCallouts(nextSnapshot);
|
|
@@ -18143,7 +18565,7 @@ function updateCalloutInSnapshot(sourceSnapshot, id, patch) {
|
|
|
18143
18565
|
targetRangeId: id,
|
|
18144
18566
|
updatedRangeProperties: {
|
|
18145
18567
|
yudaoBlockKind: "callout",
|
|
18146
|
-
callout:
|
|
18568
|
+
callout: Tools8.deepClone(updated)
|
|
18147
18569
|
},
|
|
18148
18570
|
textStyle: {
|
|
18149
18571
|
cl: { rgb: updated.textColor },
|
|
@@ -18161,7 +18583,7 @@ function updateCalloutInSnapshot(sourceSnapshot, id, patch) {
|
|
|
18161
18583
|
return { snapshot: nextSnapshot, callout: updated };
|
|
18162
18584
|
}
|
|
18163
18585
|
function removeCalloutFromSnapshot(sourceSnapshot, id) {
|
|
18164
|
-
const nextSnapshot =
|
|
18586
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
18165
18587
|
const body = nextSnapshot.body;
|
|
18166
18588
|
if (!body) return null;
|
|
18167
18589
|
const existing = listDocCallouts(nextSnapshot).find((c) => c.id === id);
|
|
@@ -18184,7 +18606,7 @@ function listDocCallouts(snapshot) {
|
|
|
18184
18606
|
const props = r.properties;
|
|
18185
18607
|
if (props?.yudaoBlockKind === "callout" && props.callout) {
|
|
18186
18608
|
fromRanges.push({
|
|
18187
|
-
...
|
|
18609
|
+
...Tools8.deepClone(props.callout),
|
|
18188
18610
|
id: r.rangeId,
|
|
18189
18611
|
startIndex: r.startIndex,
|
|
18190
18612
|
endIndex: r.endIndex
|
|
@@ -18203,7 +18625,7 @@ function formatQuoteDisplayText(quote) {
|
|
|
18203
18625
|
return cleanCit ? `${cleanText} \u2014 ${cleanCit}` : cleanText || "\u5F15\u7528\u5185\u5BB9";
|
|
18204
18626
|
}
|
|
18205
18627
|
function insertQuoteIntoSnapshot(sourceSnapshot, spec, offset) {
|
|
18206
|
-
const nextSnapshot =
|
|
18628
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
18207
18629
|
const id = spec.id || `quote_${generateRandomId7(6)}`;
|
|
18208
18630
|
const lineColor = spec.lineColor || "#2C53F1";
|
|
18209
18631
|
const textColor = spec.textColor || "#4E5565";
|
|
@@ -18223,7 +18645,7 @@ function insertQuoteIntoSnapshot(sourceSnapshot, spec, offset) {
|
|
|
18223
18645
|
CustomRangeType7.CUSTOM,
|
|
18224
18646
|
{
|
|
18225
18647
|
yudaoBlockKind: "quote",
|
|
18226
|
-
quote:
|
|
18648
|
+
quote: Tools8.deepClone(quote)
|
|
18227
18649
|
},
|
|
18228
18650
|
{
|
|
18229
18651
|
cl: { rgb: textColor },
|
|
@@ -18252,7 +18674,7 @@ function insertQuoteIntoSnapshot(sourceSnapshot, spec, offset) {
|
|
|
18252
18674
|
};
|
|
18253
18675
|
}
|
|
18254
18676
|
function updateQuoteInSnapshot(sourceSnapshot, id, patch) {
|
|
18255
|
-
const nextSnapshot =
|
|
18677
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
18256
18678
|
const body = nextSnapshot.body;
|
|
18257
18679
|
if (!body) return null;
|
|
18258
18680
|
const currentList = listDocQuotes(nextSnapshot);
|
|
@@ -18279,7 +18701,7 @@ function updateQuoteInSnapshot(sourceSnapshot, id, patch) {
|
|
|
18279
18701
|
targetRangeId: id,
|
|
18280
18702
|
updatedRangeProperties: {
|
|
18281
18703
|
yudaoBlockKind: "quote",
|
|
18282
|
-
quote:
|
|
18704
|
+
quote: Tools8.deepClone(updated)
|
|
18283
18705
|
},
|
|
18284
18706
|
textStyle: {
|
|
18285
18707
|
cl: { rgb: updated.textColor },
|
|
@@ -18297,7 +18719,7 @@ function updateQuoteInSnapshot(sourceSnapshot, id, patch) {
|
|
|
18297
18719
|
return { snapshot: nextSnapshot, quote: updated };
|
|
18298
18720
|
}
|
|
18299
18721
|
function removeQuoteFromSnapshot(sourceSnapshot, id) {
|
|
18300
|
-
const nextSnapshot =
|
|
18722
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
18301
18723
|
const body = nextSnapshot.body;
|
|
18302
18724
|
if (!body) return null;
|
|
18303
18725
|
const existing = listDocQuotes(nextSnapshot).find((q) => q.id === id);
|
|
@@ -18320,7 +18742,7 @@ function listDocQuotes(snapshot) {
|
|
|
18320
18742
|
const props = r.properties;
|
|
18321
18743
|
if (props?.yudaoBlockKind === "quote" && props.quote) {
|
|
18322
18744
|
fromRanges.push({
|
|
18323
|
-
...
|
|
18745
|
+
...Tools8.deepClone(props.quote),
|
|
18324
18746
|
id: r.rangeId,
|
|
18325
18747
|
startIndex: r.startIndex,
|
|
18326
18748
|
endIndex: r.endIndex
|
|
@@ -18346,7 +18768,7 @@ function attachDrawingMetaRangeOnBody(body, blockId, insertOffset, blockKind, sp
|
|
|
18346
18768
|
properties: {
|
|
18347
18769
|
yudaoBlockKind: blockKind,
|
|
18348
18770
|
blockId,
|
|
18349
|
-
spec:
|
|
18771
|
+
spec: Tools8.deepClone(spec)
|
|
18350
18772
|
}
|
|
18351
18773
|
});
|
|
18352
18774
|
body.customRanges.sort((a, b) => a.startIndex - b.startIndex || a.endIndex - b.endIndex);
|
|
@@ -18355,7 +18777,7 @@ function removeInlineDrawingBlockFromBody(sourceBody, blockId) {
|
|
|
18355
18777
|
const blk = (sourceBody.customBlocks ?? []).find((b) => b.blockId === blockId);
|
|
18356
18778
|
if (!blk) return null;
|
|
18357
18779
|
const pos = blk.startIndex;
|
|
18358
|
-
const nextBody =
|
|
18780
|
+
const nextBody = Tools8.deepClone(sourceBody);
|
|
18359
18781
|
nextBody.dataStream = nextBody.dataStream.slice(0, pos) + nextBody.dataStream.slice(pos + 1);
|
|
18360
18782
|
if (nextBody.paragraphs) {
|
|
18361
18783
|
nextBody.paragraphs = nextBody.paragraphs.map((p) => ({
|
|
@@ -18408,7 +18830,7 @@ function listLiveLatexFormulas(snapshot) {
|
|
|
18408
18830
|
if (liveBlockIds.has(props.blockId)) {
|
|
18409
18831
|
fromRanges.set(props.blockId, {
|
|
18410
18832
|
order: r.startIndex,
|
|
18411
|
-
spec:
|
|
18833
|
+
spec: Tools8.deepClone(props.spec)
|
|
18412
18834
|
});
|
|
18413
18835
|
}
|
|
18414
18836
|
}
|
|
@@ -18417,7 +18839,7 @@ function listLiveLatexFormulas(snapshot) {
|
|
|
18417
18839
|
for (const [id, spec] of Object.entries(meta.latexFormulas ?? {})) {
|
|
18418
18840
|
if (!fromRanges.has(id) && (liveBlockIds.size === 0 || liveBlockIds.has(id))) {
|
|
18419
18841
|
const blk = (body?.customBlocks ?? []).find((b) => b.blockId === id);
|
|
18420
|
-
fromRanges.set(id, { order: blk?.startIndex ?? 999999, spec:
|
|
18842
|
+
fromRanges.set(id, { order: blk?.startIndex ?? 999999, spec: Tools8.deepClone(spec) });
|
|
18421
18843
|
}
|
|
18422
18844
|
}
|
|
18423
18845
|
return Array.from(fromRanges.values()).sort((a, b) => a.order - b.order).map((x) => x.spec);
|
|
@@ -18432,7 +18854,7 @@ function listLiveDocCharts(snapshot) {
|
|
|
18432
18854
|
if (liveBlockIds.has(props.blockId)) {
|
|
18433
18855
|
fromRanges.set(props.blockId, {
|
|
18434
18856
|
order: r.startIndex,
|
|
18435
|
-
spec: { ...
|
|
18857
|
+
spec: { ...Tools8.deepClone(props.spec), id: props.blockId }
|
|
18436
18858
|
});
|
|
18437
18859
|
}
|
|
18438
18860
|
}
|
|
@@ -18441,7 +18863,7 @@ function listLiveDocCharts(snapshot) {
|
|
|
18441
18863
|
for (const [id, spec] of Object.entries(meta.docCharts ?? {})) {
|
|
18442
18864
|
if (!fromRanges.has(id) && (liveBlockIds.size === 0 || liveBlockIds.has(id))) {
|
|
18443
18865
|
const blk = (body?.customBlocks ?? []).find((b) => b.blockId === id);
|
|
18444
|
-
fromRanges.set(id, { order: blk?.startIndex ?? 999999, spec: { ...
|
|
18866
|
+
fromRanges.set(id, { order: blk?.startIndex ?? 999999, spec: { ...Tools8.deepClone(spec), id } });
|
|
18445
18867
|
}
|
|
18446
18868
|
}
|
|
18447
18869
|
return Array.from(fromRanges.values()).sort((a, b) => a.order - b.order).map((x) => x.spec);
|
|
@@ -18456,7 +18878,7 @@ function listLiveDocShapes(snapshot) {
|
|
|
18456
18878
|
if (liveBlockIds.has(props.blockId)) {
|
|
18457
18879
|
fromRanges.set(props.blockId, {
|
|
18458
18880
|
order: r.startIndex,
|
|
18459
|
-
spec: { ...
|
|
18881
|
+
spec: { ...Tools8.deepClone(props.spec), id: props.blockId }
|
|
18460
18882
|
});
|
|
18461
18883
|
}
|
|
18462
18884
|
}
|
|
@@ -18465,7 +18887,7 @@ function listLiveDocShapes(snapshot) {
|
|
|
18465
18887
|
for (const [id, spec] of Object.entries(meta.docShapes ?? {})) {
|
|
18466
18888
|
if (!fromRanges.has(id) && (liveBlockIds.size === 0 || liveBlockIds.has(id))) {
|
|
18467
18889
|
const blk = (body?.customBlocks ?? []).find((b) => b.blockId === id);
|
|
18468
|
-
fromRanges.set(id, { order: blk?.startIndex ?? 999999, spec: { ...
|
|
18890
|
+
fromRanges.set(id, { order: blk?.startIndex ?? 999999, spec: { ...Tools8.deepClone(spec), id } });
|
|
18469
18891
|
}
|
|
18470
18892
|
}
|
|
18471
18893
|
return Array.from(fromRanges.values()).sort((a, b) => a.order - b.order).map((x) => x.spec);
|
|
@@ -18473,8 +18895,8 @@ function listLiveDocShapes(snapshot) {
|
|
|
18473
18895
|
function buildInlineFormulaEvalContext(snapshot, extraVars) {
|
|
18474
18896
|
const meta = readDocTemplateMetadataFromSnapshot(snapshot);
|
|
18475
18897
|
const ctx = {
|
|
18476
|
-
...meta.sampleData ?
|
|
18477
|
-
...extraVars ?
|
|
18898
|
+
...meta.sampleData ? Tools8.deepClone(meta.sampleData) : {},
|
|
18899
|
+
...extraVars ? Tools8.deepClone(extraVars) : {}
|
|
18478
18900
|
};
|
|
18479
18901
|
const assignNested = (path, val) => {
|
|
18480
18902
|
ctx[path] = val;
|
|
@@ -18528,7 +18950,7 @@ function formatInlineFormulaResult(rawEval, format, decimals) {
|
|
|
18528
18950
|
return rawEval;
|
|
18529
18951
|
}
|
|
18530
18952
|
function insertInlineFormulaIntoSnapshot(sourceSnapshot, spec, offset, extraVars) {
|
|
18531
|
-
const nextSnapshot =
|
|
18953
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
18532
18954
|
const body = nextSnapshot.body;
|
|
18533
18955
|
const id = spec.id || `ifml_${generateRandomId7(6)}`;
|
|
18534
18956
|
const normalizedFormula = spec.formula.trim().startsWith("=") ? spec.formula.trim() : `=${spec.formula.trim()}`;
|
|
@@ -18560,7 +18982,7 @@ function insertInlineFormulaIntoSnapshot(sourceSnapshot, spec, offset, extraVars
|
|
|
18560
18982
|
endIndex: entry.endIndex,
|
|
18561
18983
|
properties: {
|
|
18562
18984
|
yudaoBlockKind: "inlineFormula",
|
|
18563
|
-
spec:
|
|
18985
|
+
spec: Tools8.deepClone(entry)
|
|
18564
18986
|
}
|
|
18565
18987
|
});
|
|
18566
18988
|
nextBody.customRanges.sort((a, b) => a.startIndex - b.startIndex || a.endIndex - b.endIndex);
|
|
@@ -18613,7 +19035,7 @@ function recalculateInlineFormulasInPlace(snapshot, extraVars) {
|
|
|
18613
19035
|
targetRangeId: fml.id,
|
|
18614
19036
|
updatedRangeProperties: {
|
|
18615
19037
|
yudaoBlockKind: "inlineFormula",
|
|
18616
|
-
spec:
|
|
19038
|
+
spec: Tools8.deepClone(updatedEntry)
|
|
18617
19039
|
},
|
|
18618
19040
|
textStyle: {
|
|
18619
19041
|
cl: { rgb: "#2C53F1" },
|
|
@@ -18650,7 +19072,7 @@ function listDocInlineFormulas(snapshot) {
|
|
|
18650
19072
|
const spec = props.spec;
|
|
18651
19073
|
const liveText = stream.slice(r.startIndex, r.endIndex + 1).replace(/[\r\n\u0000-\u001F]/g, "");
|
|
18652
19074
|
out.push({
|
|
18653
|
-
...
|
|
19075
|
+
...Tools8.deepClone(spec),
|
|
18654
19076
|
id: r.rangeId,
|
|
18655
19077
|
value: liveText || spec.value,
|
|
18656
19078
|
startIndex: r.startIndex,
|
|
@@ -18712,7 +19134,7 @@ function sortDocTableByColumnInSnapshot(sourceSnapshot, tableIndex, columnIndex,
|
|
|
18712
19134
|
const parsedRows = parseTableRowsInStream(body.dataStream, tblRef.startIndex, tblRef.endIndex);
|
|
18713
19135
|
const hdrCount = Math.max(0, Math.min(headerRowCount, parsedRows.length));
|
|
18714
19136
|
if (parsedRows.length - hdrCount <= 1) {
|
|
18715
|
-
return
|
|
19137
|
+
return Tools8.deepClone(sourceSnapshot);
|
|
18716
19138
|
}
|
|
18717
19139
|
const bodyRowIndices = Array.from(
|
|
18718
19140
|
{ length: parsedRows.length - hdrCount },
|
|
@@ -18725,9 +19147,9 @@ function sortDocTableByColumnInSnapshot(sourceSnapshot, tableIndex, columnIndex,
|
|
|
18725
19147
|
return cmp !== 0 ? cmp : idxA - idxB;
|
|
18726
19148
|
});
|
|
18727
19149
|
if (sortedIndices.every((val, k) => val === bodyRowIndices[k])) {
|
|
18728
|
-
return
|
|
19150
|
+
return Tools8.deepClone(sourceSnapshot);
|
|
18729
19151
|
}
|
|
18730
|
-
const nextSnapshot =
|
|
19152
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
18731
19153
|
const nextBody = nextSnapshot.body;
|
|
18732
19154
|
const stream = body.dataStream;
|
|
18733
19155
|
const regionStart = parsedRows[hdrCount].rowStart;
|
|
@@ -18782,25 +19204,25 @@ function sortDocTableByColumnInSnapshot(sourceSnapshot, tableIndex, columnIndex,
|
|
|
18782
19204
|
const nextRuns = [];
|
|
18783
19205
|
for (const tr of body.textRuns ?? []) {
|
|
18784
19206
|
if (tr.ed <= regionStart || tr.st > regionEndInclusive) {
|
|
18785
|
-
nextRuns.push(
|
|
19207
|
+
nextRuns.push(Tools8.deepClone(tr));
|
|
18786
19208
|
continue;
|
|
18787
19209
|
}
|
|
18788
19210
|
if (tr.st < regionStart) {
|
|
18789
|
-
nextRuns.push({ ...
|
|
19211
|
+
nextRuns.push({ ...Tools8.deepClone(tr), ed: regionStart });
|
|
18790
19212
|
}
|
|
18791
19213
|
for (const pl of rowPlacements) {
|
|
18792
19214
|
const ovSt = Math.max(tr.st, pl.oldStart);
|
|
18793
19215
|
const ovEd = Math.min(tr.ed, pl.oldEndInclusive + 1);
|
|
18794
19216
|
if (ovEd > ovSt) {
|
|
18795
19217
|
nextRuns.push({
|
|
18796
|
-
...
|
|
19218
|
+
...Tools8.deepClone(tr),
|
|
18797
19219
|
st: ovSt + pl.shift,
|
|
18798
19220
|
ed: ovEd + pl.shift
|
|
18799
19221
|
});
|
|
18800
19222
|
}
|
|
18801
19223
|
}
|
|
18802
19224
|
if (tr.ed > regionEndInclusive + 1) {
|
|
18803
|
-
nextRuns.push({ ...
|
|
19225
|
+
nextRuns.push({ ...Tools8.deepClone(tr), st: regionEndInclusive + 1 });
|
|
18804
19226
|
}
|
|
18805
19227
|
}
|
|
18806
19228
|
nextRuns.sort((a, b) => a.st - b.st || a.ed - b.ed);
|
|
@@ -18810,7 +19232,7 @@ function sortDocTableByColumnInSnapshot(sourceSnapshot, tableIndex, columnIndex,
|
|
|
18810
19232
|
if (tblDef?.tableRows && tblDef.tableRows.length >= parsedRows.length) {
|
|
18811
19233
|
const headerDefs = tblDef.tableRows.slice(0, hdrCount);
|
|
18812
19234
|
const sortedDefs = sortedIndices.map((oldIdx) => {
|
|
18813
|
-
const cloned =
|
|
19235
|
+
const cloned = Tools8.deepClone(tblDef.tableRows[oldIdx]);
|
|
18814
19236
|
cloned.isFirstRow = BooleanNumber4.FALSE;
|
|
18815
19237
|
cloned.repeatHeaderRow = BooleanNumber4.FALSE;
|
|
18816
19238
|
return cloned;
|
|
@@ -18823,7 +19245,7 @@ function setDocTableRepeatHeaderInSnapshot(sourceSnapshot, tableIndex, headerRow
|
|
|
18823
19245
|
const body = sourceSnapshot.body;
|
|
18824
19246
|
const tblRef = body?.tables?.[tableIndex];
|
|
18825
19247
|
if (!body || !tblRef) return null;
|
|
18826
|
-
const nextSnapshot =
|
|
19248
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
18827
19249
|
const clampedCount = Math.max(0, Math.floor(headerRowCount));
|
|
18828
19250
|
const tblDef = nextSnapshot.tableSource?.[tblRef.tableId];
|
|
18829
19251
|
if (tblDef?.tableRows) {
|
|
@@ -18877,7 +19299,7 @@ function convertTextToDocTableInSnapshot(sourceSnapshot, text, delimiter, offset
|
|
|
18877
19299
|
const paddedRows = matrix.map(
|
|
18878
19300
|
(r) => Array.from({ length: colCount }, (_, c) => r[c] ?? "")
|
|
18879
19301
|
);
|
|
18880
|
-
const nextSnapshot =
|
|
19302
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
18881
19303
|
const nextBody = nextSnapshot.body;
|
|
18882
19304
|
const insertAt = clampSafeInsertOffset(nextBody, offset);
|
|
18883
19305
|
const tableId = `tbl_${generateRandomId7(6)}`;
|
|
@@ -19083,7 +19505,7 @@ function expandRepeatingSectionTemplate(templateText, bindingPath, items, rootDa
|
|
|
19083
19505
|
function insertBookmarkIntoSnapshot(sourceSnapshot, spec) {
|
|
19084
19506
|
const body = sourceSnapshot.body;
|
|
19085
19507
|
if (!body || !spec.name?.trim()) return null;
|
|
19086
|
-
const nextSnapshot =
|
|
19508
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
19087
19509
|
const nextBody = nextSnapshot.body;
|
|
19088
19510
|
const maxBodyOffset = Math.max(0, nextBody.dataStream.length - 2);
|
|
19089
19511
|
const startOffset = Math.min(Math.max(0, spec.startOffset), maxBodyOffset);
|
|
@@ -19132,7 +19554,7 @@ function removeBookmarkFromSnapshot(sourceSnapshot, nameOrId) {
|
|
|
19132
19554
|
(b) => b.id === nameOrId || b.name === nameOrId
|
|
19133
19555
|
);
|
|
19134
19556
|
if (!existing) return null;
|
|
19135
|
-
const nextSnapshot =
|
|
19557
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
19136
19558
|
const nextBody = nextSnapshot.body;
|
|
19137
19559
|
nextBody.customRanges = (nextBody.customRanges ?? []).filter(
|
|
19138
19560
|
(r) => !(r.rangeType === CustomRangeType7.BOOKMARK && (r.rangeId === existing.id || r.properties?.bookmarkName === existing.name))
|
|
@@ -19326,7 +19748,7 @@ function buildTocBlockLines(snapshot, title, maxLevel, excludeRange, options) {
|
|
|
19326
19748
|
return lines;
|
|
19327
19749
|
}
|
|
19328
19750
|
function insertTableOfContentsIntoSnapshot(sourceSnapshot, spec, offset) {
|
|
19329
|
-
const nextSnapshot =
|
|
19751
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
19330
19752
|
const body = nextSnapshot.body;
|
|
19331
19753
|
const tocTitle = spec?.title?.trim() || "\u76EE\u5F55";
|
|
19332
19754
|
const maxLevel = Math.max(1, Math.min(6, spec?.maxLevel ?? 3));
|
|
@@ -19406,7 +19828,7 @@ function insertTableOfContentsIntoSnapshot(sourceSnapshot, spec, offset) {
|
|
|
19406
19828
|
endIndex: tocEndInclusive,
|
|
19407
19829
|
properties: {
|
|
19408
19830
|
yudaoBlockKind: "toc",
|
|
19409
|
-
toc:
|
|
19831
|
+
toc: Tools8.deepClone(tocEntry)
|
|
19410
19832
|
}
|
|
19411
19833
|
});
|
|
19412
19834
|
updatedBody.customRanges.sort((a, b) => a.startIndex - b.startIndex || a.endIndex - b.endIndex);
|
|
@@ -19423,7 +19845,7 @@ function insertTableOfContentsIntoSnapshot(sourceSnapshot, spec, offset) {
|
|
|
19423
19845
|
};
|
|
19424
19846
|
}
|
|
19425
19847
|
function refreshTableOfContentsInSnapshot(sourceSnapshot, overrideSpec) {
|
|
19426
|
-
const nextSnapshot =
|
|
19848
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
19427
19849
|
const body = nextSnapshot.body;
|
|
19428
19850
|
if (!body) return null;
|
|
19429
19851
|
const tocRange = (body.customRanges ?? []).find(
|
|
@@ -19486,7 +19908,7 @@ function refreshTableOfContentsInSnapshot(sourceSnapshot, overrideSpec) {
|
|
|
19486
19908
|
targetRangeId: tocRange.rangeId,
|
|
19487
19909
|
updatedRangeProperties: {
|
|
19488
19910
|
yudaoBlockKind: "toc",
|
|
19489
|
-
toc:
|
|
19911
|
+
toc: Tools8.deepClone(tocEntry)
|
|
19490
19912
|
},
|
|
19491
19913
|
textStyle: {
|
|
19492
19914
|
cl: { rgb: "#31363F" },
|
|
@@ -19530,7 +19952,7 @@ function refreshTableOfContentsInSnapshot(sourceSnapshot, overrideSpec) {
|
|
|
19530
19952
|
};
|
|
19531
19953
|
}
|
|
19532
19954
|
function removeTableOfContentsFromSnapshot(sourceSnapshot) {
|
|
19533
|
-
const nextSnapshot =
|
|
19955
|
+
const nextSnapshot = Tools8.deepClone(sourceSnapshot);
|
|
19534
19956
|
const body = nextSnapshot.body;
|
|
19535
19957
|
if (!body) return { snapshot: nextSnapshot, removed: false };
|
|
19536
19958
|
const tocRange = (body.customRanges ?? []).find(
|
|
@@ -19553,7 +19975,7 @@ function removeTableOfContentsFromSnapshot(sourceSnapshot) {
|
|
|
19553
19975
|
return { snapshot: nextSnapshot, removed: true };
|
|
19554
19976
|
}
|
|
19555
19977
|
function reconcileTemplateMetadataWithLiveSnapshot(snapshot, baseMeta) {
|
|
19556
|
-
const nextMeta =
|
|
19978
|
+
const nextMeta = Tools8.deepClone(baseMeta);
|
|
19557
19979
|
const body = snapshot.body;
|
|
19558
19980
|
if (!body) return nextMeta;
|
|
19559
19981
|
nextMeta.callouts = listDocCallouts(snapshot);
|
|
@@ -19575,7 +19997,7 @@ function reconcileTemplateMetadataWithLiveSnapshot(snapshot, baseMeta) {
|
|
|
19575
19997
|
const blockId = String(props.blockId);
|
|
19576
19998
|
if (props.yudaoBlockKind === "latexFormula" && props.spec) {
|
|
19577
19999
|
const spec = props.spec;
|
|
19578
|
-
nextLatex[blockId] =
|
|
20000
|
+
nextLatex[blockId] = Tools8.deepClone(spec);
|
|
19579
20001
|
const drw = snapshot.drawings?.[blockId];
|
|
19580
20002
|
if (drw) {
|
|
19581
20003
|
const rendered = layoutLatexFormulaWidget(spec.latex, {
|
|
@@ -19591,7 +20013,7 @@ function reconcileTemplateMetadataWithLiveSnapshot(snapshot, baseMeta) {
|
|
|
19591
20013
|
}
|
|
19592
20014
|
} else if (props.yudaoBlockKind === "docChart" && props.spec) {
|
|
19593
20015
|
const spec = { ...props.spec, id: blockId };
|
|
19594
|
-
nextCharts[blockId] =
|
|
20016
|
+
nextCharts[blockId] = Tools8.deepClone(spec);
|
|
19595
20017
|
const drw = snapshot.drawings?.[blockId];
|
|
19596
20018
|
if (drw) {
|
|
19597
20019
|
const rendered = renderDocChartToSvgDataUri(spec);
|
|
@@ -19607,7 +20029,7 @@ function reconcileTemplateMetadataWithLiveSnapshot(snapshot, baseMeta) {
|
|
|
19607
20029
|
id: blockId,
|
|
19608
20030
|
shapeType: props.spec.shapeType ?? props.spec.kind ?? "roundRect"
|
|
19609
20031
|
};
|
|
19610
|
-
nextShapes[blockId] =
|
|
20032
|
+
nextShapes[blockId] = Tools8.deepClone(spec);
|
|
19611
20033
|
const drw = snapshot.drawings?.[blockId];
|
|
19612
20034
|
if (drw) {
|
|
19613
20035
|
const rendered = renderDocShapeToSvgDataUri(spec);
|
|
@@ -19622,7 +20044,7 @@ function reconcileTemplateMetadataWithLiveSnapshot(snapshot, baseMeta) {
|
|
|
19622
20044
|
...props.spec,
|
|
19623
20045
|
id: blockId
|
|
19624
20046
|
};
|
|
19625
|
-
nextSmartArts[blockId] =
|
|
20047
|
+
nextSmartArts[blockId] = Tools8.deepClone(spec);
|
|
19626
20048
|
const drw = snapshot.drawings?.[blockId];
|
|
19627
20049
|
if (drw) {
|
|
19628
20050
|
const rendered = renderSmartArtToSvgDataUri(spec);
|
|
@@ -19634,13 +20056,13 @@ function reconcileTemplateMetadataWithLiveSnapshot(snapshot, baseMeta) {
|
|
|
19634
20056
|
}
|
|
19635
20057
|
} else if (props.yudaoBlockKind === "labelBadge" && props.spec) {
|
|
19636
20058
|
if (!nextMeta.labelBadges) nextMeta.labelBadges = {};
|
|
19637
|
-
nextMeta.labelBadges[blockId] =
|
|
20059
|
+
nextMeta.labelBadges[blockId] = Tools8.deepClone(props.spec);
|
|
19638
20060
|
} else if (props.yudaoBlockKind === "styledSeparator" && props.spec) {
|
|
19639
20061
|
if (!nextMeta.styledSeparators) nextMeta.styledSeparators = {};
|
|
19640
|
-
nextMeta.styledSeparators[blockId] =
|
|
20062
|
+
nextMeta.styledSeparators[blockId] = Tools8.deepClone(props.spec);
|
|
19641
20063
|
} else if (props.yudaoBlockKind === "embedBlock" && props.spec) {
|
|
19642
20064
|
if (!nextMeta.embedBlocks) nextMeta.embedBlocks = {};
|
|
19643
|
-
nextMeta.embedBlocks[blockId] =
|
|
20065
|
+
nextMeta.embedBlocks[blockId] = Tools8.deepClone(props.spec);
|
|
19644
20066
|
}
|
|
19645
20067
|
}
|
|
19646
20068
|
if (nextMeta.labelBadges) {
|
|
@@ -19743,7 +20165,7 @@ function resolveLiveDocAreaSpan(snapshot, area) {
|
|
|
19743
20165
|
if (!body?.paragraphs?.length) return null;
|
|
19744
20166
|
if (area.hide) {
|
|
19745
20167
|
return {
|
|
19746
|
-
area:
|
|
20168
|
+
area: Tools9.deepClone(area),
|
|
19747
20169
|
charStart: area.startIndex ?? 0,
|
|
19748
20170
|
charEndInclusive: area.endIndex ?? -1,
|
|
19749
20171
|
contentEndExclusive: area.startIndex ?? 0
|
|
@@ -19776,7 +20198,7 @@ function resolveLiveDocAreaSpan(snapshot, area) {
|
|
|
19776
20198
|
const charStart = startParaIdx === 0 ? 0 : sortedParas[startParaIdx - 1].startIndex + 1;
|
|
19777
20199
|
const charEndInclusive = sortedParas[endParaIdx].startIndex;
|
|
19778
20200
|
const resolvedArea = {
|
|
19779
|
-
...
|
|
20201
|
+
...Tools9.deepClone(area),
|
|
19780
20202
|
startParagraphIndex: startParaIdx,
|
|
19781
20203
|
endParagraphIndex: endParaIdx,
|
|
19782
20204
|
startParagraphId: sortedParas[startParaIdx].paragraphId,
|
|
@@ -19797,16 +20219,16 @@ function getDocAreasFromSnapshot(snapshot) {
|
|
|
19797
20219
|
if (rawAreas.length === 0) return [];
|
|
19798
20220
|
return rawAreas.map((area) => {
|
|
19799
20221
|
if (area.hide) {
|
|
19800
|
-
return
|
|
20222
|
+
return Tools9.deepClone(area);
|
|
19801
20223
|
}
|
|
19802
20224
|
const resolved = resolveLiveDocAreaSpan(snapshot, area);
|
|
19803
|
-
return resolved ? resolved.area :
|
|
20225
|
+
return resolved ? resolved.area : Tools9.deepClone(area);
|
|
19804
20226
|
});
|
|
19805
20227
|
}
|
|
19806
20228
|
function insertDocAreaInSnapshot(sourceSnapshot, spec, offset) {
|
|
19807
20229
|
const body = sourceSnapshot.body;
|
|
19808
20230
|
if (!body) return null;
|
|
19809
|
-
const nextSnapshot =
|
|
20231
|
+
const nextSnapshot = Tools9.deepClone(sourceSnapshot);
|
|
19810
20232
|
const nextBody = nextSnapshot.body;
|
|
19811
20233
|
const areaId = spec.id?.trim() || `area_${generateRandomId8(6)}`;
|
|
19812
20234
|
const name = spec.name?.trim() || "\u547D\u540D\u5B50\u533A\u57DF";
|
|
@@ -19852,7 +20274,7 @@ function insertDocAreaInSnapshot(sourceSnapshot, spec, offset) {
|
|
|
19852
20274
|
if (needsLeadingBreak && hostPara && spliced.paragraphs) {
|
|
19853
20275
|
const prevStyle = hostPara.paragraphStyle;
|
|
19854
20276
|
spliced.paragraphs = spliced.paragraphs.map(
|
|
19855
|
-
(p) => p.startIndex === spliceAt && prevStyle ? { ...p, paragraphStyle:
|
|
20277
|
+
(p) => p.startIndex === spliceAt && prevStyle ? { ...p, paragraphStyle: Tools9.deepClone(prevStyle) } : p
|
|
19856
20278
|
);
|
|
19857
20279
|
}
|
|
19858
20280
|
const areaCharStart = needsLeadingBreak ? spliceAt + 1 : spliceAt;
|
|
@@ -19874,7 +20296,7 @@ function insertDocAreaInSnapshot(sourceSnapshot, spec, offset) {
|
|
|
19874
20296
|
...p.paragraphStyle ?? {},
|
|
19875
20297
|
yudaoAreaId: areaId,
|
|
19876
20298
|
yudaoAreaMode: mode,
|
|
19877
|
-
yudaoBorderShading:
|
|
20299
|
+
yudaoBorderShading: Tools9.deepClone(bdrShading)
|
|
19878
20300
|
}
|
|
19879
20301
|
};
|
|
19880
20302
|
});
|
|
@@ -19922,7 +20344,7 @@ function insertDocAreaInSnapshot(sourceSnapshot, spec, offset) {
|
|
|
19922
20344
|
const nextParaBorders = { ...meta.paragraphBorders ?? {} };
|
|
19923
20345
|
for (const p of spliced.paragraphs) {
|
|
19924
20346
|
if (p.paragraphStyle?.yudaoAreaId === areaId && p.paragraphId) {
|
|
19925
|
-
nextParaBorders[p.paragraphId] =
|
|
20347
|
+
nextParaBorders[p.paragraphId] = Tools9.deepClone(bdrShading);
|
|
19926
20348
|
}
|
|
19927
20349
|
}
|
|
19928
20350
|
writeDocTemplateMetadataToSnapshot(nextSnapshot, {
|
|
@@ -19950,15 +20372,15 @@ function getDocAreaValueFromSnapshot(snapshot, areaId) {
|
|
|
19950
20372
|
id: "area_slice_tmp",
|
|
19951
20373
|
body: {
|
|
19952
20374
|
dataStream: `${slice.dataStream}${DataStreamTreeTokenType10.SECTION_BREAK}`,
|
|
19953
|
-
paragraphs:
|
|
20375
|
+
paragraphs: Tools9.deepClone(slice.paragraphs),
|
|
19954
20376
|
sectionBreaks: [
|
|
19955
|
-
...
|
|
20377
|
+
...Tools9.deepClone(slice.sectionBreaks),
|
|
19956
20378
|
{ startIndex: slice.dataStream.length, sectionId: "s_tmp" }
|
|
19957
20379
|
],
|
|
19958
|
-
tables:
|
|
19959
|
-
customRanges:
|
|
19960
|
-
customBlocks:
|
|
19961
|
-
textRuns:
|
|
20380
|
+
tables: Tools9.deepClone(slice.tables),
|
|
20381
|
+
customRanges: Tools9.deepClone(slice.customRanges),
|
|
20382
|
+
customBlocks: Tools9.deepClone(slice.customBlocks),
|
|
20383
|
+
textRuns: Tools9.deepClone(slice.textRuns)
|
|
19962
20384
|
},
|
|
19963
20385
|
documentStyle: {}
|
|
19964
20386
|
};
|
|
@@ -20020,13 +20442,13 @@ function setDocAreaValueInSnapshot(sourceSnapshot, areaId, newText) {
|
|
|
20020
20442
|
if (!replaced) return null;
|
|
20021
20443
|
return setDocAreaPropertiesInSnapshot(replaced.snapshot, areaId, { hide: true });
|
|
20022
20444
|
}
|
|
20023
|
-
const nextSnapshot =
|
|
20445
|
+
const nextSnapshot = Tools9.deepClone(sourceSnapshot);
|
|
20024
20446
|
const resolved = resolveLiveDocAreaSpan(nextSnapshot, current);
|
|
20025
20447
|
if (!resolved) return null;
|
|
20026
20448
|
const { charStart, charEndInclusive } = resolved;
|
|
20027
20449
|
const oldStartParaIdx = resolved.area.startParagraphIndex;
|
|
20028
20450
|
const oldEndParaIdx = resolved.area.endParagraphIndex;
|
|
20029
|
-
const preBody =
|
|
20451
|
+
const preBody = Tools9.deepClone(nextSnapshot.body);
|
|
20030
20452
|
const oldParaCount = getSortedParagraphs(preBody).filter(
|
|
20031
20453
|
(p) => p.startIndex >= charStart && p.startIndex <= charEndInclusive
|
|
20032
20454
|
).length;
|
|
@@ -20099,7 +20521,7 @@ function setDocAreaValueInSnapshot(sourceSnapshot, areaId, newText) {
|
|
|
20099
20521
|
...p.paragraphStyle ?? {},
|
|
20100
20522
|
yudaoAreaId: areaId,
|
|
20101
20523
|
yudaoAreaMode: current.mode,
|
|
20102
|
-
yudaoBorderShading:
|
|
20524
|
+
yudaoBorderShading: Tools9.deepClone(bdrShading)
|
|
20103
20525
|
}
|
|
20104
20526
|
};
|
|
20105
20527
|
});
|
|
@@ -20147,7 +20569,7 @@ function setDocAreaValueInSnapshot(sourceSnapshot, areaId, newText) {
|
|
|
20147
20569
|
const nextParaBorders = { ...meta.paragraphBorders ?? {} };
|
|
20148
20570
|
for (const p of spliced.paragraphs) {
|
|
20149
20571
|
if (p.paragraphStyle?.yudaoAreaId === areaId && p.paragraphId) {
|
|
20150
|
-
nextParaBorders[p.paragraphId] =
|
|
20572
|
+
nextParaBorders[p.paragraphId] = Tools9.deepClone(bdrShading);
|
|
20151
20573
|
}
|
|
20152
20574
|
}
|
|
20153
20575
|
writeDocTemplateMetadataToSnapshot(nextSnapshot, {
|
|
@@ -20162,7 +20584,7 @@ function setDocAreaValueInSnapshot(sourceSnapshot, areaId, newText) {
|
|
|
20162
20584
|
};
|
|
20163
20585
|
}
|
|
20164
20586
|
function hideDocAreaSliceInSnapshot(sourceSnapshot, targetArea) {
|
|
20165
|
-
const nextSnapshot =
|
|
20587
|
+
const nextSnapshot = Tools9.deepClone(sourceSnapshot);
|
|
20166
20588
|
const resolved = resolveLiveDocAreaSpan(nextSnapshot, targetArea);
|
|
20167
20589
|
if (!resolved || !nextSnapshot.body) return null;
|
|
20168
20590
|
const nextBody = nextSnapshot.body;
|
|
@@ -20173,21 +20595,21 @@ function hideDocAreaSliceInSnapshot(sourceSnapshot, targetArea) {
|
|
|
20173
20595
|
const beforeParagraphId = oldStartParaIdx > 0 ? sortedParas[oldStartParaIdx - 1]?.paragraphId : void 0;
|
|
20174
20596
|
const sliceLen = charEndInclusive - charStart + 1;
|
|
20175
20597
|
const sliceParas = sortedParas.filter((p) => p.startIndex >= charStart && p.startIndex <= charEndInclusive).map((p) => ({
|
|
20176
|
-
...
|
|
20598
|
+
...Tools9.deepClone(p),
|
|
20177
20599
|
startIndex: p.startIndex - charStart
|
|
20178
20600
|
}));
|
|
20179
20601
|
const removedParaCount = sliceParas.length;
|
|
20180
20602
|
const sliceSections = (nextBody.sectionBreaks ?? []).filter((s) => s.startIndex >= charStart && s.startIndex <= charEndInclusive).map((s) => ({
|
|
20181
|
-
...
|
|
20603
|
+
...Tools9.deepClone(s),
|
|
20182
20604
|
startIndex: s.startIndex - charStart
|
|
20183
20605
|
}));
|
|
20184
20606
|
const tableSourceEntries = {};
|
|
20185
20607
|
const sliceTables = (nextBody.tables ?? []).filter((t) => t.startIndex >= charStart && t.endIndex <= charEndInclusive + 1).map((t) => {
|
|
20186
20608
|
if (nextSnapshot.tableSource?.[t.tableId]) {
|
|
20187
|
-
tableSourceEntries[t.tableId] =
|
|
20609
|
+
tableSourceEntries[t.tableId] = Tools9.deepClone(nextSnapshot.tableSource[t.tableId]);
|
|
20188
20610
|
}
|
|
20189
20611
|
return {
|
|
20190
|
-
...
|
|
20612
|
+
...Tools9.deepClone(t),
|
|
20191
20613
|
startIndex: t.startIndex - charStart,
|
|
20192
20614
|
endIndex: t.endIndex - charStart
|
|
20193
20615
|
};
|
|
@@ -20195,14 +20617,14 @@ function hideDocAreaSliceInSnapshot(sourceSnapshot, targetArea) {
|
|
|
20195
20617
|
const drawingEntries = {};
|
|
20196
20618
|
const sliceBlocks = (nextBody.customBlocks ?? []).filter((b) => b.startIndex >= charStart && b.startIndex <= charEndInclusive).map((b) => {
|
|
20197
20619
|
const drw = nextSnapshot.drawings?.[b.blockId];
|
|
20198
|
-
if (drw) drawingEntries[b.blockId] =
|
|
20620
|
+
if (drw) drawingEntries[b.blockId] = Tools9.deepClone(drw);
|
|
20199
20621
|
return {
|
|
20200
|
-
...
|
|
20622
|
+
...Tools9.deepClone(b),
|
|
20201
20623
|
startIndex: b.startIndex - charStart
|
|
20202
20624
|
};
|
|
20203
20625
|
});
|
|
20204
20626
|
const sliceRanges = (nextBody.customRanges ?? []).filter((r) => r.startIndex >= charStart && r.endIndex <= charEndInclusive).map((r) => ({
|
|
20205
|
-
...
|
|
20627
|
+
...Tools9.deepClone(r),
|
|
20206
20628
|
startIndex: r.startIndex - charStart,
|
|
20207
20629
|
endIndex: r.endIndex - charStart
|
|
20208
20630
|
}));
|
|
@@ -20212,7 +20634,7 @@ function hideDocAreaSliceInSnapshot(sourceSnapshot, targetArea) {
|
|
|
20212
20634
|
const st = Math.max(r.st, charStart) - charStart;
|
|
20213
20635
|
const ed = Math.min(r.ed, charEndInclusive + 1) - charStart;
|
|
20214
20636
|
if (ed > st) {
|
|
20215
|
-
sliceRuns.push({ ...
|
|
20637
|
+
sliceRuns.push({ ...Tools9.deepClone(r), st, ed });
|
|
20216
20638
|
}
|
|
20217
20639
|
}
|
|
20218
20640
|
const remainingParasCount = sortedParas.length - removedParaCount;
|
|
@@ -20297,7 +20719,7 @@ function hideDocAreaSliceInSnapshot(sourceSnapshot, targetArea) {
|
|
|
20297
20719
|
function restoreHiddenDocAreaSliceInSnapshot(sourceSnapshot, targetArea) {
|
|
20298
20720
|
const slice = targetArea.cachedHiddenSlice;
|
|
20299
20721
|
if (!slice || !sourceSnapshot.body) return null;
|
|
20300
|
-
const nextSnapshot =
|
|
20722
|
+
const nextSnapshot = Tools9.deepClone(sourceSnapshot);
|
|
20301
20723
|
const nextBody = nextSnapshot.body;
|
|
20302
20724
|
let sortedParas = getSortedParagraphs(nextBody);
|
|
20303
20725
|
let consumedTempAnchor = false;
|
|
@@ -20341,14 +20763,14 @@ function restoreHiddenDocAreaSliceInSnapshot(sourceSnapshot, targetArea) {
|
|
|
20341
20763
|
(t) => p.startIndex >= t.startIndex && p.startIndex < t.endIndex
|
|
20342
20764
|
);
|
|
20343
20765
|
return {
|
|
20344
|
-
...
|
|
20766
|
+
...Tools9.deepClone(p),
|
|
20345
20767
|
startIndex: p.startIndex + insertPos,
|
|
20346
20768
|
...isCellPara ? {} : {
|
|
20347
20769
|
paragraphStyle: {
|
|
20348
20770
|
...p.paragraphStyle ?? {},
|
|
20349
20771
|
yudaoAreaId: targetArea.id,
|
|
20350
20772
|
yudaoAreaMode: targetArea.mode,
|
|
20351
|
-
yudaoBorderShading:
|
|
20773
|
+
yudaoBorderShading: Tools9.deepClone(bdrShading)
|
|
20352
20774
|
}
|
|
20353
20775
|
}
|
|
20354
20776
|
};
|
|
@@ -20361,7 +20783,7 @@ function restoreHiddenDocAreaSliceInSnapshot(sourceSnapshot, targetArea) {
|
|
|
20361
20783
|
nextBody.sectionBreaks = [
|
|
20362
20784
|
...(nextBody.sectionBreaks ?? []).filter((s) => s.startIndex < insertPos),
|
|
20363
20785
|
...slice.sectionBreaks.map((s) => ({
|
|
20364
|
-
...
|
|
20786
|
+
...Tools9.deepClone(s),
|
|
20365
20787
|
startIndex: s.startIndex + insertPos
|
|
20366
20788
|
})),
|
|
20367
20789
|
...(nextBody.sectionBreaks ?? []).filter((s) => s.startIndex >= insertPos + removedOldLen).map((s) => ({ ...s, startIndex: s.startIndex + deltaChars }))
|
|
@@ -20369,7 +20791,7 @@ function restoreHiddenDocAreaSliceInSnapshot(sourceSnapshot, targetArea) {
|
|
|
20369
20791
|
nextBody.tables = [
|
|
20370
20792
|
...(nextBody.tables ?? []).filter((t) => t.endIndex <= insertPos),
|
|
20371
20793
|
...slice.tables.map((t) => ({
|
|
20372
|
-
...
|
|
20794
|
+
...Tools9.deepClone(t),
|
|
20373
20795
|
startIndex: t.startIndex + insertPos,
|
|
20374
20796
|
endIndex: t.endIndex + insertPos
|
|
20375
20797
|
})),
|
|
@@ -20382,13 +20804,13 @@ function restoreHiddenDocAreaSliceInSnapshot(sourceSnapshot, targetArea) {
|
|
|
20382
20804
|
if (slice.tableSourceEntries) {
|
|
20383
20805
|
nextSnapshot.tableSource = {
|
|
20384
20806
|
...nextSnapshot.tableSource ?? {},
|
|
20385
|
-
...
|
|
20807
|
+
...Tools9.deepClone(slice.tableSourceEntries)
|
|
20386
20808
|
};
|
|
20387
20809
|
}
|
|
20388
20810
|
nextBody.customBlocks = [
|
|
20389
20811
|
...(nextBody.customBlocks ?? []).filter((b) => b.startIndex < insertPos),
|
|
20390
20812
|
...slice.customBlocks.map((b) => ({
|
|
20391
|
-
...
|
|
20813
|
+
...Tools9.deepClone(b),
|
|
20392
20814
|
startIndex: b.startIndex + insertPos
|
|
20393
20815
|
})),
|
|
20394
20816
|
...(nextBody.customBlocks ?? []).filter((b) => b.startIndex >= insertPos + removedOldLen).map((b) => ({ ...b, startIndex: b.startIndex + deltaChars }))
|
|
@@ -20396,7 +20818,7 @@ function restoreHiddenDocAreaSliceInSnapshot(sourceSnapshot, targetArea) {
|
|
|
20396
20818
|
if (slice.drawingEntries) {
|
|
20397
20819
|
nextSnapshot.drawings = {
|
|
20398
20820
|
...nextSnapshot.drawings ?? {},
|
|
20399
|
-
...
|
|
20821
|
+
...Tools9.deepClone(slice.drawingEntries)
|
|
20400
20822
|
};
|
|
20401
20823
|
const existingOrder = new Set(nextSnapshot.drawingsOrder ?? []);
|
|
20402
20824
|
for (const dId of Object.keys(slice.drawingEntries)) {
|
|
@@ -20407,7 +20829,7 @@ function restoreHiddenDocAreaSliceInSnapshot(sourceSnapshot, targetArea) {
|
|
|
20407
20829
|
nextBody.customRanges = [
|
|
20408
20830
|
...(nextBody.customRanges ?? []).filter((r) => r.endIndex < insertPos),
|
|
20409
20831
|
...slice.customRanges.map((r) => ({
|
|
20410
|
-
...
|
|
20832
|
+
...Tools9.deepClone(r),
|
|
20411
20833
|
startIndex: r.startIndex + insertPos,
|
|
20412
20834
|
endIndex: r.endIndex + insertPos
|
|
20413
20835
|
})),
|
|
@@ -20436,7 +20858,7 @@ function restoreHiddenDocAreaSliceInSnapshot(sourceSnapshot, targetArea) {
|
|
|
20436
20858
|
}
|
|
20437
20859
|
for (const sr of slice.textRuns) {
|
|
20438
20860
|
restoredRuns.push({
|
|
20439
|
-
...
|
|
20861
|
+
...Tools9.deepClone(sr),
|
|
20440
20862
|
st: sr.st + insertPos,
|
|
20441
20863
|
ed: sr.ed + insertPos
|
|
20442
20864
|
});
|
|
@@ -20446,7 +20868,7 @@ function restoreHiddenDocAreaSliceInSnapshot(sourceSnapshot, targetArea) {
|
|
|
20446
20868
|
sortedParas = getSortedParagraphs(nextBody);
|
|
20447
20869
|
const newEndParaIdx = restoreParaIdx + slice.paragraphCount - 1;
|
|
20448
20870
|
const unhiddenArea = {
|
|
20449
|
-
...
|
|
20871
|
+
...Tools9.deepClone(targetArea),
|
|
20450
20872
|
hide: false,
|
|
20451
20873
|
startParagraphIndex: restoreParaIdx,
|
|
20452
20874
|
endParagraphIndex: newEndParaIdx,
|
|
@@ -20482,7 +20904,7 @@ function setDocAreaPropertiesInSnapshot(sourceSnapshot, areaId, patch) {
|
|
|
20482
20904
|
const areas = getDocAreasFromSnapshot(sourceSnapshot);
|
|
20483
20905
|
const existing = areas.find((a) => a.id === areaId);
|
|
20484
20906
|
if (!existing) return null;
|
|
20485
|
-
let workingSnapshot =
|
|
20907
|
+
let workingSnapshot = Tools9.deepClone(sourceSnapshot);
|
|
20486
20908
|
let mergedArea = {
|
|
20487
20909
|
...existing,
|
|
20488
20910
|
...patch.name !== void 0 ? { name: patch.name } : {},
|
|
@@ -20507,7 +20929,7 @@ function setDocAreaPropertiesInSnapshot(sourceSnapshot, areaId, patch) {
|
|
|
20507
20929
|
workingSnapshot.body.paragraphs = workingSnapshot.body.paragraphs.map((p) => {
|
|
20508
20930
|
if (p.paragraphStyle?.yudaoAreaId !== areaId) return p;
|
|
20509
20931
|
if (p.paragraphId) {
|
|
20510
|
-
nextParaBorders[p.paragraphId] =
|
|
20932
|
+
nextParaBorders[p.paragraphId] = Tools9.deepClone(bdrShading);
|
|
20511
20933
|
}
|
|
20512
20934
|
return {
|
|
20513
20935
|
...p,
|
|
@@ -20515,7 +20937,7 @@ function setDocAreaPropertiesInSnapshot(sourceSnapshot, areaId, patch) {
|
|
|
20515
20937
|
...p.paragraphStyle ?? {},
|
|
20516
20938
|
yudaoAreaId: areaId,
|
|
20517
20939
|
yudaoAreaMode: mergedArea.mode,
|
|
20518
|
-
yudaoBorderShading:
|
|
20940
|
+
yudaoBorderShading: Tools9.deepClone(bdrShading)
|
|
20519
20941
|
}
|
|
20520
20942
|
};
|
|
20521
20943
|
});
|
|
@@ -20546,7 +20968,7 @@ function deleteDocAreaFromSnapshot(sourceSnapshot, areaId, options) {
|
|
|
20546
20968
|
return null;
|
|
20547
20969
|
}
|
|
20548
20970
|
if (existing.hide) {
|
|
20549
|
-
const nextSnapshot =
|
|
20971
|
+
const nextSnapshot = Tools9.deepClone(sourceSnapshot);
|
|
20550
20972
|
const meta2 = readDocTemplateMetadataFromSnapshot(nextSnapshot);
|
|
20551
20973
|
writeDocTemplateMetadataToSnapshot(nextSnapshot, {
|
|
20552
20974
|
...meta2,
|
|
@@ -20555,7 +20977,7 @@ function deleteDocAreaFromSnapshot(sourceSnapshot, areaId, options) {
|
|
|
20555
20977
|
return nextSnapshot;
|
|
20556
20978
|
}
|
|
20557
20979
|
if (options?.keepContent) {
|
|
20558
|
-
const nextSnapshot =
|
|
20980
|
+
const nextSnapshot = Tools9.deepClone(sourceSnapshot);
|
|
20559
20981
|
if (nextSnapshot.body?.paragraphs) {
|
|
20560
20982
|
nextSnapshot.body.paragraphs = nextSnapshot.body.paragraphs.map((p) => {
|
|
20561
20983
|
if (p.paragraphStyle?.yudaoAreaId !== areaId) return p;
|
|
@@ -20614,11 +21036,11 @@ function isOffsetReadonlyByArea(snapshot, offset, globalMode = "design") {
|
|
|
20614
21036
|
return false;
|
|
20615
21037
|
}
|
|
20616
21038
|
function setDocMainBadgeInSnapshot(sourceSnapshot, badge) {
|
|
20617
|
-
const nextSnapshot =
|
|
21039
|
+
const nextSnapshot = Tools9.deepClone(sourceSnapshot);
|
|
20618
21040
|
const meta = readDocTemplateMetadataFromSnapshot(nextSnapshot);
|
|
20619
21041
|
const nextMeta = { ...meta };
|
|
20620
21042
|
if (badge) {
|
|
20621
|
-
nextMeta.mainBadge =
|
|
21043
|
+
nextMeta.mainBadge = Tools9.deepClone(badge);
|
|
20622
21044
|
} else {
|
|
20623
21045
|
delete nextMeta.mainBadge;
|
|
20624
21046
|
}
|
|
@@ -20627,17 +21049,17 @@ function setDocMainBadgeInSnapshot(sourceSnapshot, badge) {
|
|
|
20627
21049
|
}
|
|
20628
21050
|
function getDocMainBadgeFromSnapshot(snapshot) {
|
|
20629
21051
|
const meta = readDocTemplateMetadataFromSnapshot(snapshot);
|
|
20630
|
-
return meta.mainBadge ?
|
|
21052
|
+
return meta.mainBadge ? Tools9.deepClone(meta.mainBadge) : null;
|
|
20631
21053
|
}
|
|
20632
21054
|
function setDocAreaBadgeInSnapshot(sourceSnapshot, areaId, badge) {
|
|
20633
21055
|
const outcome = setDocAreaPropertiesInSnapshot(sourceSnapshot, areaId, {
|
|
20634
|
-
badge: badge ?
|
|
21056
|
+
badge: badge ? Tools9.deepClone(badge) : null
|
|
20635
21057
|
});
|
|
20636
21058
|
return outcome ? outcome.snapshot : null;
|
|
20637
21059
|
}
|
|
20638
21060
|
function getDocAreaBadgeFromSnapshot(snapshot, areaId) {
|
|
20639
21061
|
const hit = getDocAreasFromSnapshot(snapshot).find((a) => a.id === areaId);
|
|
20640
|
-
return hit?.badge ?
|
|
21062
|
+
return hit?.badge ? Tools9.deepClone(hit.badge) : null;
|
|
20641
21063
|
}
|
|
20642
21064
|
function resolveLabelBadgePalette(tone = "primary", colorOverride, bgOverride) {
|
|
20643
21065
|
const map = {
|
|
@@ -20738,19 +21160,19 @@ function getDocLabelBadgesFromSnapshot(snapshot) {
|
|
|
20738
21160
|
for (const r of body.customRanges ?? []) {
|
|
20739
21161
|
const props = r.properties;
|
|
20740
21162
|
if (props?.yudaoBlockKind === "labelBadge" && props.blockId && liveBlockIds.has(props.blockId)) {
|
|
20741
|
-
byId.set(String(props.blockId),
|
|
21163
|
+
byId.set(String(props.blockId), Tools9.deepClone(props.spec));
|
|
20742
21164
|
}
|
|
20743
21165
|
}
|
|
20744
21166
|
for (const [id, b] of Object.entries(metaMap)) {
|
|
20745
21167
|
if (liveBlockIds.has(id) && !byId.has(id)) {
|
|
20746
|
-
byId.set(id,
|
|
21168
|
+
byId.set(id, Tools9.deepClone(b));
|
|
20747
21169
|
}
|
|
20748
21170
|
}
|
|
20749
21171
|
return [...body.customBlocks].sort((a, b) => a.startIndex - b.startIndex).map((blk) => byId.get(blk.blockId)).filter((b) => Boolean(b));
|
|
20750
21172
|
}
|
|
20751
21173
|
function removeDocLabelBadgeFromSnapshot(sourceSnapshot, id) {
|
|
20752
21174
|
if (!sourceSnapshot.body || !id) return null;
|
|
20753
|
-
const nextSnapshot =
|
|
21175
|
+
const nextSnapshot = Tools9.deepClone(sourceSnapshot);
|
|
20754
21176
|
const nextBody = removeInlineDrawingBlockFromBody(nextSnapshot.body, id);
|
|
20755
21177
|
if (!nextBody) return null;
|
|
20756
21178
|
nextSnapshot.body = nextBody;
|
|
@@ -20801,7 +21223,7 @@ function setParagraphBorderAndShadingInSnapshot(sourceSnapshot, paragraphIndex,
|
|
|
20801
21223
|
if (!body?.paragraphs?.length) return null;
|
|
20802
21224
|
const sorted = getSortedTopLevelOrAllParagraphs(body);
|
|
20803
21225
|
if (paragraphIndex < 0 || paragraphIndex >= sorted.length) return null;
|
|
20804
|
-
const nextSnapshot =
|
|
21226
|
+
const nextSnapshot = Tools10.deepClone(sourceSnapshot);
|
|
20805
21227
|
const nextBody = nextSnapshot.body;
|
|
20806
21228
|
const targetStart = sorted[paragraphIndex].startIndex;
|
|
20807
21229
|
let paraId = sorted[paragraphIndex].paragraphId || `p_${paragraphIndex}`;
|
|
@@ -20813,7 +21235,7 @@ function setParagraphBorderAndShadingInSnapshot(sourceSnapshot, paragraphIndex,
|
|
|
20813
21235
|
paragraphId: paraId,
|
|
20814
21236
|
paragraphStyle: {
|
|
20815
21237
|
...p.paragraphStyle ?? {},
|
|
20816
|
-
yudaoBorderShading:
|
|
21238
|
+
yudaoBorderShading: Tools10.deepClone(spec)
|
|
20817
21239
|
}
|
|
20818
21240
|
};
|
|
20819
21241
|
});
|
|
@@ -20822,7 +21244,7 @@ function setParagraphBorderAndShadingInSnapshot(sourceSnapshot, paragraphIndex,
|
|
|
20822
21244
|
...meta,
|
|
20823
21245
|
paragraphBorders: {
|
|
20824
21246
|
...meta.paragraphBorders ?? {},
|
|
20825
|
-
[paraId]:
|
|
21247
|
+
[paraId]: Tools10.deepClone(spec)
|
|
20826
21248
|
}
|
|
20827
21249
|
});
|
|
20828
21250
|
return nextSnapshot;
|
|
@@ -20834,17 +21256,17 @@ function getParagraphBorderAndShading(snapshot, paragraphIndex) {
|
|
|
20834
21256
|
const p = sorted[paragraphIndex];
|
|
20835
21257
|
if (!p) return void 0;
|
|
20836
21258
|
const fromStyle = p.paragraphStyle?.yudaoBorderShading;
|
|
20837
|
-
if (fromStyle) return
|
|
21259
|
+
if (fromStyle) return Tools10.deepClone(fromStyle);
|
|
20838
21260
|
const meta = readDocTemplateMetadataFromSnapshot(snapshot);
|
|
20839
21261
|
if (p.paragraphId && meta.paragraphBorders?.[p.paragraphId]) {
|
|
20840
|
-
return
|
|
21262
|
+
return Tools10.deepClone(meta.paragraphBorders[p.paragraphId]);
|
|
20841
21263
|
}
|
|
20842
21264
|
return void 0;
|
|
20843
21265
|
}
|
|
20844
21266
|
function insertHorizontalDividerInSnapshot(sourceSnapshot, style = "single", offset) {
|
|
20845
21267
|
const body = sourceSnapshot.body;
|
|
20846
21268
|
if (!body) return null;
|
|
20847
|
-
const nextSnapshot =
|
|
21269
|
+
const nextSnapshot = Tools10.deepClone(sourceSnapshot);
|
|
20848
21270
|
const nextBody = nextSnapshot.body;
|
|
20849
21271
|
const dividerId = `hr_${generateRandomId9(6)}`;
|
|
20850
21272
|
const insertAt = clampSafeInsertOffset(nextBody, offset);
|
|
@@ -20919,7 +21341,7 @@ function setParagraphTabStopsInSnapshot(sourceSnapshot, paragraphIndex, tabStops
|
|
|
20919
21341
|
alignment: t.alignment ?? "left",
|
|
20920
21342
|
leader: t.leader ?? "none"
|
|
20921
21343
|
})).sort((a, b) => a.positionPt - b.positionPt);
|
|
20922
|
-
const nextSnapshot =
|
|
21344
|
+
const nextSnapshot = Tools10.deepClone(sourceSnapshot);
|
|
20923
21345
|
const nextBody = nextSnapshot.body;
|
|
20924
21346
|
const targetStart = sorted[paragraphIndex].startIndex;
|
|
20925
21347
|
let paraId = sorted[paragraphIndex].paragraphId || `p_${paragraphIndex}`;
|
|
@@ -20931,7 +21353,7 @@ function setParagraphTabStopsInSnapshot(sourceSnapshot, paragraphIndex, tabStops
|
|
|
20931
21353
|
paragraphId: paraId,
|
|
20932
21354
|
paragraphStyle: {
|
|
20933
21355
|
...p.paragraphStyle ?? {},
|
|
20934
|
-
yudaoTabStops:
|
|
21356
|
+
yudaoTabStops: Tools10.deepClone(normalized)
|
|
20935
21357
|
}
|
|
20936
21358
|
};
|
|
20937
21359
|
});
|
|
@@ -20940,7 +21362,7 @@ function setParagraphTabStopsInSnapshot(sourceSnapshot, paragraphIndex, tabStops
|
|
|
20940
21362
|
...meta,
|
|
20941
21363
|
paragraphTabStops: {
|
|
20942
21364
|
...meta.paragraphTabStops ?? {},
|
|
20943
|
-
[paraId]:
|
|
21365
|
+
[paraId]: Tools10.deepClone(normalized)
|
|
20944
21366
|
}
|
|
20945
21367
|
});
|
|
20946
21368
|
return nextSnapshot;
|
|
@@ -20952,10 +21374,10 @@ function getParagraphTabStops(snapshot, paragraphIndex) {
|
|
|
20952
21374
|
const p = sorted[paragraphIndex];
|
|
20953
21375
|
if (!p) return [];
|
|
20954
21376
|
const fromStyle = p.paragraphStyle?.yudaoTabStops;
|
|
20955
|
-
if (Array.isArray(fromStyle)) return
|
|
21377
|
+
if (Array.isArray(fromStyle)) return Tools10.deepClone(fromStyle);
|
|
20956
21378
|
const meta = readDocTemplateMetadataFromSnapshot(snapshot);
|
|
20957
21379
|
if (p.paragraphId && Array.isArray(meta.paragraphTabStops?.[p.paragraphId])) {
|
|
20958
|
-
return
|
|
21380
|
+
return Tools10.deepClone(meta.paragraphTabStops[p.paragraphId]);
|
|
20959
21381
|
}
|
|
20960
21382
|
return [];
|
|
20961
21383
|
}
|
|
@@ -20995,7 +21417,7 @@ function getCollapsedHeadingsFromSnapshot(snapshot) {
|
|
|
20995
21417
|
const meta = readDocTemplateMetadataFromSnapshot(snapshot);
|
|
20996
21418
|
const body = snapshot?.body;
|
|
20997
21419
|
const list = meta.collapsedHeadings ?? [];
|
|
20998
|
-
if (!body?.paragraphs?.length) return
|
|
21420
|
+
if (!body?.paragraphs?.length) return Tools10.deepClone(list);
|
|
20999
21421
|
const sorted = getSortedTopLevelOrAllParagraphs(body);
|
|
21000
21422
|
return list.map((entry) => {
|
|
21001
21423
|
const liveIdx = sorted.findIndex(
|
|
@@ -21003,7 +21425,7 @@ function getCollapsedHeadingsFromSnapshot(snapshot) {
|
|
|
21003
21425
|
);
|
|
21004
21426
|
if (liveIdx < 0) return null;
|
|
21005
21427
|
return {
|
|
21006
|
-
...
|
|
21428
|
+
...Tools10.deepClone(entry),
|
|
21007
21429
|
paragraphIndex: liveIdx
|
|
21008
21430
|
};
|
|
21009
21431
|
}).filter((e) => e !== null);
|
|
@@ -21020,7 +21442,7 @@ function toggleHeadingCollapseInSnapshot(sourceSnapshot, headingParagraphIndex)
|
|
|
21020
21442
|
const existingEntryIdx = existingList.findIndex(
|
|
21021
21443
|
(e) => e.paragraphId && e.paragraphId === paraId || targetPara.paragraphStyle?.yudaoCollapsedHeadingId === e.id || e.paragraphIndex === headingParagraphIndex
|
|
21022
21444
|
);
|
|
21023
|
-
const nextSnapshot =
|
|
21445
|
+
const nextSnapshot = Tools10.deepClone(sourceSnapshot);
|
|
21024
21446
|
const nextBody = nextSnapshot.body;
|
|
21025
21447
|
if (existingEntryIdx >= 0) {
|
|
21026
21448
|
const entry = existingList[existingEntryIdx];
|
|
@@ -21035,18 +21457,18 @@ function toggleHeadingCollapseInSnapshot(sourceSnapshot, headingParagraphIndex)
|
|
|
21035
21457
|
delete nextStyle.yudaoCollapsedHeadingId;
|
|
21036
21458
|
return { ...p, paragraphId: paraId, paragraphStyle: nextStyle };
|
|
21037
21459
|
}),
|
|
21038
|
-
...slice.paragraphs.map((p) => ({ ...
|
|
21460
|
+
...slice.paragraphs.map((p) => ({ ...Tools10.deepClone(p), startIndex: p.startIndex + insertPos })),
|
|
21039
21461
|
...(nextBody.paragraphs ?? []).filter((p) => p.startIndex >= insertPos).map((p) => ({ ...p, startIndex: p.startIndex + delta }))
|
|
21040
21462
|
].sort((a, b) => a.startIndex - b.startIndex);
|
|
21041
21463
|
nextBody.sectionBreaks = [
|
|
21042
21464
|
...(nextBody.sectionBreaks ?? []).filter((s) => s.startIndex < insertPos),
|
|
21043
|
-
...slice.sectionBreaks.map((s) => ({ ...
|
|
21465
|
+
...slice.sectionBreaks.map((s) => ({ ...Tools10.deepClone(s), startIndex: s.startIndex + insertPos })),
|
|
21044
21466
|
...(nextBody.sectionBreaks ?? []).filter((s) => s.startIndex >= insertPos).map((s) => ({ ...s, startIndex: s.startIndex + delta }))
|
|
21045
21467
|
].sort((a, b) => a.startIndex - b.startIndex);
|
|
21046
21468
|
nextBody.tables = [
|
|
21047
21469
|
...(nextBody.tables ?? []).filter((t) => t.endIndex <= insertPos),
|
|
21048
21470
|
...slice.tables.map((t) => ({
|
|
21049
|
-
...
|
|
21471
|
+
...Tools10.deepClone(t),
|
|
21050
21472
|
startIndex: t.startIndex + insertPos,
|
|
21051
21473
|
endIndex: t.endIndex + insertPos
|
|
21052
21474
|
})),
|
|
@@ -21054,13 +21476,13 @@ function toggleHeadingCollapseInSnapshot(sourceSnapshot, headingParagraphIndex)
|
|
|
21054
21476
|
].sort((a, b) => a.startIndex - b.startIndex);
|
|
21055
21477
|
nextBody.customBlocks = [
|
|
21056
21478
|
...(nextBody.customBlocks ?? []).filter((b) => b.startIndex < insertPos),
|
|
21057
|
-
...slice.customBlocks.map((b) => ({ ...
|
|
21479
|
+
...slice.customBlocks.map((b) => ({ ...Tools10.deepClone(b), startIndex: b.startIndex + insertPos })),
|
|
21058
21480
|
...(nextBody.customBlocks ?? []).filter((b) => b.startIndex >= insertPos).map((b) => ({ ...b, startIndex: b.startIndex + delta }))
|
|
21059
21481
|
].sort((a, b) => a.startIndex - b.startIndex);
|
|
21060
21482
|
nextBody.customRanges = [
|
|
21061
21483
|
...(nextBody.customRanges ?? []).filter((r) => r.endIndex < insertPos),
|
|
21062
21484
|
...slice.customRanges.map((r) => ({
|
|
21063
|
-
...
|
|
21485
|
+
...Tools10.deepClone(r),
|
|
21064
21486
|
startIndex: r.startIndex + insertPos,
|
|
21065
21487
|
endIndex: r.endIndex + insertPos
|
|
21066
21488
|
})),
|
|
@@ -21073,7 +21495,7 @@ function toggleHeadingCollapseInSnapshot(sourceSnapshot, headingParagraphIndex)
|
|
|
21073
21495
|
{ ...tr, st: insertPos + delta, ed: tr.ed + delta }
|
|
21074
21496
|
]),
|
|
21075
21497
|
...slice.textRuns.map((tr) => ({
|
|
21076
|
-
...
|
|
21498
|
+
...Tools10.deepClone(tr),
|
|
21077
21499
|
st: tr.st + insertPos,
|
|
21078
21500
|
ed: tr.ed + insertPos
|
|
21079
21501
|
})),
|
|
@@ -21083,7 +21505,7 @@ function toggleHeadingCollapseInSnapshot(sourceSnapshot, headingParagraphIndex)
|
|
|
21083
21505
|
if (slice.tableSourceEntries && Object.keys(slice.tableSourceEntries).length > 0) {
|
|
21084
21506
|
nextSnapshot.tableSource = {
|
|
21085
21507
|
...nextSnapshot.tableSource ?? {},
|
|
21086
|
-
...
|
|
21508
|
+
...Tools10.deepClone(slice.tableSourceEntries)
|
|
21087
21509
|
};
|
|
21088
21510
|
}
|
|
21089
21511
|
writeDocTemplateMetadataToSnapshot(nextSnapshot, {
|
|
@@ -21110,29 +21532,29 @@ function toggleHeadingCollapseInSnapshot(sourceSnapshot, headingParagraphIndex)
|
|
|
21110
21532
|
const removedLen = Math.max(0, sliceEndExclusive - sliceStart);
|
|
21111
21533
|
const collapseId = `chd_${generateRandomId9(6)}`;
|
|
21112
21534
|
const sliceTables = (body.tables ?? []).filter((t) => t.startIndex >= sliceStart && t.endIndex <= sliceEndExclusive).map((t) => ({
|
|
21113
|
-
...
|
|
21535
|
+
...Tools10.deepClone(t),
|
|
21114
21536
|
startIndex: t.startIndex - sliceStart,
|
|
21115
21537
|
endIndex: t.endIndex - sliceStart
|
|
21116
21538
|
}));
|
|
21117
21539
|
const tableSourceEntries = {};
|
|
21118
21540
|
for (const t of sliceTables) {
|
|
21119
21541
|
if (sourceSnapshot.tableSource?.[t.tableId]) {
|
|
21120
|
-
tableSourceEntries[t.tableId] =
|
|
21542
|
+
tableSourceEntries[t.tableId] = Tools10.deepClone(sourceSnapshot.tableSource[t.tableId]);
|
|
21121
21543
|
}
|
|
21122
21544
|
}
|
|
21123
21545
|
const cachedSlice = {
|
|
21124
21546
|
dataStream: body.dataStream.slice(sliceStart, sliceEndExclusive),
|
|
21125
|
-
paragraphs: (body.paragraphs ?? []).filter((p) => p.startIndex >= sliceStart && p.startIndex < sliceEndExclusive).map((p) => ({ ...
|
|
21126
|
-
sectionBreaks: (body.sectionBreaks ?? []).filter((s) => s.startIndex >= sliceStart && s.startIndex < sliceEndExclusive).map((s) => ({ ...
|
|
21547
|
+
paragraphs: (body.paragraphs ?? []).filter((p) => p.startIndex >= sliceStart && p.startIndex < sliceEndExclusive).map((p) => ({ ...Tools10.deepClone(p), startIndex: p.startIndex - sliceStart })),
|
|
21548
|
+
sectionBreaks: (body.sectionBreaks ?? []).filter((s) => s.startIndex >= sliceStart && s.startIndex < sliceEndExclusive).map((s) => ({ ...Tools10.deepClone(s), startIndex: s.startIndex - sliceStart })),
|
|
21127
21549
|
tables: sliceTables,
|
|
21128
|
-
customBlocks: (body.customBlocks ?? []).filter((b) => b.startIndex >= sliceStart && b.startIndex < sliceEndExclusive).map((b) => ({ ...
|
|
21550
|
+
customBlocks: (body.customBlocks ?? []).filter((b) => b.startIndex >= sliceStart && b.startIndex < sliceEndExclusive).map((b) => ({ ...Tools10.deepClone(b), startIndex: b.startIndex - sliceStart })),
|
|
21129
21551
|
customRanges: (body.customRanges ?? []).filter((r) => r.startIndex >= sliceStart && r.endIndex < sliceEndExclusive).map((r) => ({
|
|
21130
|
-
...
|
|
21552
|
+
...Tools10.deepClone(r),
|
|
21131
21553
|
startIndex: r.startIndex - sliceStart,
|
|
21132
21554
|
endIndex: r.endIndex - sliceStart
|
|
21133
21555
|
})),
|
|
21134
21556
|
textRuns: (body.textRuns ?? []).filter((tr) => tr.ed > sliceStart && tr.st < sliceEndExclusive).map((tr) => ({
|
|
21135
|
-
...
|
|
21557
|
+
...Tools10.deepClone(tr),
|
|
21136
21558
|
st: Math.max(0, tr.st - sliceStart),
|
|
21137
21559
|
ed: Math.min(removedLen, tr.ed - sliceStart)
|
|
21138
21560
|
})).filter((tr) => tr.ed > tr.st),
|
|
@@ -21196,7 +21618,7 @@ function escapeRegexLiteral(raw) {
|
|
|
21196
21618
|
}
|
|
21197
21619
|
function findAndReplaceDocTextInSnapshot(sourceSnapshot, query, replacement, options) {
|
|
21198
21620
|
if (!query || !sourceSnapshot.body?.dataStream) {
|
|
21199
|
-
return { snapshot:
|
|
21621
|
+
return { snapshot: Tools10.deepClone(sourceSnapshot), count: 0 };
|
|
21200
21622
|
}
|
|
21201
21623
|
let patternSource = options?.useRegex ? query : escapeRegexLiteral(query);
|
|
21202
21624
|
if (options?.wholeWord) {
|
|
@@ -21207,7 +21629,7 @@ function findAndReplaceDocTextInSnapshot(sourceSnapshot, query, replacement, opt
|
|
|
21207
21629
|
try {
|
|
21208
21630
|
regex = new RegExp(patternSource, flags);
|
|
21209
21631
|
} catch {
|
|
21210
|
-
return { snapshot:
|
|
21632
|
+
return { snapshot: Tools10.deepClone(sourceSnapshot), count: 0 };
|
|
21211
21633
|
}
|
|
21212
21634
|
const stream = sourceSnapshot.body.dataStream;
|
|
21213
21635
|
const controlBoundaryRe = /[^\r\n\u0000-\u001F]+/g;
|
|
@@ -21233,7 +21655,7 @@ function findAndReplaceDocTextInSnapshot(sourceSnapshot, query, replacement, opt
|
|
|
21233
21655
|
}
|
|
21234
21656
|
}
|
|
21235
21657
|
if (matches.length === 0) {
|
|
21236
|
-
return { snapshot:
|
|
21658
|
+
return { snapshot: Tools10.deepClone(sourceSnapshot), count: 0 };
|
|
21237
21659
|
}
|
|
21238
21660
|
let eligibleMatches = matches;
|
|
21239
21661
|
if (options?.respectLocks) {
|
|
@@ -21267,9 +21689,9 @@ function findAndReplaceDocTextInSnapshot(sourceSnapshot, query, replacement, opt
|
|
|
21267
21689
|
eligibleMatches = idx >= 0 && idx < eligibleMatches.length ? [eligibleMatches[idx]] : [];
|
|
21268
21690
|
}
|
|
21269
21691
|
if (eligibleMatches.length === 0) {
|
|
21270
|
-
return { snapshot:
|
|
21692
|
+
return { snapshot: Tools10.deepClone(sourceSnapshot), count: 0 };
|
|
21271
21693
|
}
|
|
21272
|
-
const nextSnapshot =
|
|
21694
|
+
const nextSnapshot = Tools10.deepClone(sourceSnapshot);
|
|
21273
21695
|
let workingBody = nextSnapshot.body;
|
|
21274
21696
|
let meta = readDocTemplateMetadataFromSnapshot(nextSnapshot);
|
|
21275
21697
|
const trackEnabled = Boolean(meta.trackChangesEnabled);
|
|
@@ -21451,7 +21873,7 @@ function checkDocumentSpellingAndTerms(snapshot, customGlossary) {
|
|
|
21451
21873
|
function insertPageBreakInSnapshot(sourceSnapshot, offset) {
|
|
21452
21874
|
const body = sourceSnapshot.body;
|
|
21453
21875
|
if (!body) return null;
|
|
21454
|
-
const nextSnapshot =
|
|
21876
|
+
const nextSnapshot = Tools10.deepClone(sourceSnapshot);
|
|
21455
21877
|
const insertAt = clampSafeInsertOffset(nextSnapshot.body, offset);
|
|
21456
21878
|
nextSnapshot.body = spliceDocumentBodySpan(
|
|
21457
21879
|
nextSnapshot.body,
|
|
@@ -21464,7 +21886,7 @@ function insertPageBreakInSnapshot(sourceSnapshot, offset) {
|
|
|
21464
21886
|
function insertSectionBreakInSnapshot(sourceSnapshot, type = "nextPage", offset, orientation) {
|
|
21465
21887
|
const body = sourceSnapshot.body;
|
|
21466
21888
|
if (!body) return null;
|
|
21467
|
-
const nextSnapshot =
|
|
21889
|
+
const nextSnapshot = Tools10.deepClone(sourceSnapshot);
|
|
21468
21890
|
const nextBody = nextSnapshot.body;
|
|
21469
21891
|
const insertAt = clampSafeInsertOffset(nextBody, offset);
|
|
21470
21892
|
const sectionId = `sec_${generateRandomId9(6)}`;
|
|
@@ -21510,7 +21932,7 @@ function insertSectionBreakInSnapshot(sourceSnapshot, type = "nextPage", offset,
|
|
|
21510
21932
|
};
|
|
21511
21933
|
}
|
|
21512
21934
|
function setSectionOrientationInSnapshot(sourceSnapshot, orientation, sectionKeyOrOffset) {
|
|
21513
|
-
const nextSnapshot =
|
|
21935
|
+
const nextSnapshot = Tools10.deepClone(sourceSnapshot);
|
|
21514
21936
|
const meta = readDocTemplateMetadataFromSnapshot(nextSnapshot);
|
|
21515
21937
|
const orientations = { ...meta.sectionOrientations ?? {} };
|
|
21516
21938
|
let resolvedKey = "__trailing__";
|
|
@@ -21574,7 +21996,7 @@ function insertColumnGroupInSnapshot(sourceSnapshot, columnCount, options) {
|
|
|
21574
21996
|
equalWidth,
|
|
21575
21997
|
separatorLine
|
|
21576
21998
|
};
|
|
21577
|
-
const nextSnapshot =
|
|
21999
|
+
const nextSnapshot = Tools10.deepClone(sourceSnapshot);
|
|
21578
22000
|
const nextBody = nextSnapshot.body;
|
|
21579
22001
|
const pageW = nextSnapshot.documentStyle?.pageSize?.width ?? 595.28;
|
|
21580
22002
|
const marL = nextSnapshot.documentStyle?.marginLeft ?? 64;
|
|
@@ -21606,7 +22028,7 @@ function insertColumnGroupInSnapshot(sourceSnapshot, columnCount, options) {
|
|
|
21606
22028
|
function getColumnGroupConfigFromSnapshot(snapshot) {
|
|
21607
22029
|
const meta = readDocTemplateMetadataFromSnapshot(snapshot);
|
|
21608
22030
|
if (meta.columnGroupConfig) {
|
|
21609
|
-
return
|
|
22031
|
+
return Tools10.deepClone(meta.columnGroupConfig);
|
|
21610
22032
|
}
|
|
21611
22033
|
const cg = snapshot?.body?.columnGroups?.[0];
|
|
21612
22034
|
if (cg && cg.columns && cg.columns.length >= 2) {
|
|
@@ -21649,7 +22071,7 @@ function updateColumnGroupInSnapshot(sourceSnapshot, patch) {
|
|
|
21649
22071
|
});
|
|
21650
22072
|
}
|
|
21651
22073
|
function deleteColumnGroupFromSnapshot(sourceSnapshot) {
|
|
21652
|
-
const nextSnapshot =
|
|
22074
|
+
const nextSnapshot = Tools10.deepClone(sourceSnapshot);
|
|
21653
22075
|
const existing = getColumnGroupConfigFromSnapshot(nextSnapshot);
|
|
21654
22076
|
if (!existing) {
|
|
21655
22077
|
return { snapshot: nextSnapshot, deleted: false };
|
|
@@ -21680,7 +22102,7 @@ function setParagraphPaginationInSnapshot(sourceSnapshot, paragraphIndex, spec)
|
|
|
21680
22102
|
if (!body?.paragraphs?.length) return null;
|
|
21681
22103
|
const sorted = getSortedTopLevelOrAllParagraphs(body);
|
|
21682
22104
|
if (paragraphIndex < 0 || paragraphIndex >= sorted.length) return null;
|
|
21683
|
-
const nextSnapshot =
|
|
22105
|
+
const nextSnapshot = Tools10.deepClone(sourceSnapshot);
|
|
21684
22106
|
const nextBody = nextSnapshot.body;
|
|
21685
22107
|
const targetStart = sorted[paragraphIndex].startIndex;
|
|
21686
22108
|
let paraId = sorted[paragraphIndex].paragraphId || `p_${paragraphIndex}`;
|
|
@@ -21726,11 +22148,11 @@ function getParagraphPagination(snapshot, paragraphIndex) {
|
|
|
21726
22148
|
if (!p) return {};
|
|
21727
22149
|
const pStyle = p.paragraphStyle ?? {};
|
|
21728
22150
|
if (pStyle.yudaoPagination) {
|
|
21729
|
-
return
|
|
22151
|
+
return Tools10.deepClone(pStyle.yudaoPagination);
|
|
21730
22152
|
}
|
|
21731
22153
|
const meta = readDocTemplateMetadataFromSnapshot(snapshot);
|
|
21732
22154
|
if (p.paragraphId && meta.paragraphPagination?.[p.paragraphId]) {
|
|
21733
|
-
return
|
|
22155
|
+
return Tools10.deepClone(meta.paragraphPagination[p.paragraphId]);
|
|
21734
22156
|
}
|
|
21735
22157
|
const out = {};
|
|
21736
22158
|
if (pStyle.keepLines !== void 0) out.keepLines = Boolean(pStyle.keepLines);
|
|
@@ -21740,11 +22162,11 @@ function getParagraphPagination(snapshot, paragraphIndex) {
|
|
|
21740
22162
|
return out;
|
|
21741
22163
|
}
|
|
21742
22164
|
function setDocPrintConfigInSnapshot(sourceSnapshot, patch) {
|
|
21743
|
-
const nextSnapshot =
|
|
22165
|
+
const nextSnapshot = Tools10.deepClone(sourceSnapshot);
|
|
21744
22166
|
const meta = readDocTemplateMetadataFromSnapshot(nextSnapshot);
|
|
21745
22167
|
const merged = {
|
|
21746
22168
|
...meta.printConfig ?? {},
|
|
21747
|
-
...
|
|
22169
|
+
...Tools10.deepClone(patch)
|
|
21748
22170
|
};
|
|
21749
22171
|
writeDocTemplateMetadataToSnapshot(nextSnapshot, {
|
|
21750
22172
|
...meta,
|
|
@@ -21754,7 +22176,7 @@ function setDocPrintConfigInSnapshot(sourceSnapshot, patch) {
|
|
|
21754
22176
|
}
|
|
21755
22177
|
function getDocPrintConfigFromSnapshot(snapshot) {
|
|
21756
22178
|
const meta = readDocTemplateMetadataFromSnapshot(snapshot);
|
|
21757
|
-
return
|
|
22179
|
+
return Tools10.deepClone(meta.printConfig ?? {});
|
|
21758
22180
|
}
|
|
21759
22181
|
|
|
21760
22182
|
// src/utils/doc-cascade-and-particles.ts
|
|
@@ -22213,10 +22635,10 @@ function evaluateDocCascadeRulesInPlace(snapshot, extraData) {
|
|
|
22213
22635
|
}
|
|
22214
22636
|
const initialMeta = readDocTemplateMetadataFromSnapshot(snapshot);
|
|
22215
22637
|
const rules = initialMeta.cascadeRules ?? [];
|
|
22216
|
-
const baselines =
|
|
22638
|
+
const baselines = Tools11.deepClone(
|
|
22217
22639
|
initialMeta.cascadeBaselines ?? {}
|
|
22218
22640
|
);
|
|
22219
|
-
const headingBaselines =
|
|
22641
|
+
const headingBaselines = Tools11.deepClone(
|
|
22220
22642
|
initialMeta.cascadeHeadingBaselines ?? {}
|
|
22221
22643
|
);
|
|
22222
22644
|
if (rules.length === 0 && Object.keys(baselines).length === 0 && Object.keys(headingBaselines).length === 0) {
|
|
@@ -22534,7 +22956,7 @@ function evaluateDocCascadeRulesInPlace(snapshot, extraData) {
|
|
|
22534
22956
|
};
|
|
22535
22957
|
}
|
|
22536
22958
|
function evaluateDocCascadeRules(sourceSnapshot, extraData) {
|
|
22537
|
-
const nextSnapshot =
|
|
22959
|
+
const nextSnapshot = Tools11.deepClone(sourceSnapshot);
|
|
22538
22960
|
const res = evaluateDocCascadeRulesInPlace(nextSnapshot, extraData);
|
|
22539
22961
|
return {
|
|
22540
22962
|
snapshot: nextSnapshot,
|
|
@@ -22543,14 +22965,14 @@ function evaluateDocCascadeRules(sourceSnapshot, extraData) {
|
|
|
22543
22965
|
}
|
|
22544
22966
|
function getDocCascadeRulesFromSnapshot(snapshot) {
|
|
22545
22967
|
const meta = readDocTemplateMetadataFromSnapshot(snapshot);
|
|
22546
|
-
return
|
|
22968
|
+
return Tools11.deepClone(meta.cascadeRules ?? []);
|
|
22547
22969
|
}
|
|
22548
22970
|
function setDocCascadeRulesInSnapshot(sourceSnapshot, rules, evaluateImmediately = true) {
|
|
22549
|
-
const nextSnapshot =
|
|
22971
|
+
const nextSnapshot = Tools11.deepClone(sourceSnapshot);
|
|
22550
22972
|
const meta = readDocTemplateMetadataFromSnapshot(nextSnapshot);
|
|
22551
22973
|
writeDocTemplateMetadataToSnapshot(nextSnapshot, {
|
|
22552
22974
|
...meta,
|
|
22553
|
-
cascadeRules:
|
|
22975
|
+
cascadeRules: Tools11.deepClone(rules ?? [])
|
|
22554
22976
|
});
|
|
22555
22977
|
if (!evaluateImmediately) {
|
|
22556
22978
|
return {
|
|
@@ -22567,7 +22989,7 @@ function addDocCascadeRuleInSnapshot(sourceSnapshot, rule, evaluateImmediately =
|
|
|
22567
22989
|
const existing = getDocCascadeRulesFromSnapshot(sourceSnapshot).filter((r) => r.id !== rule.id);
|
|
22568
22990
|
return setDocCascadeRulesInSnapshot(
|
|
22569
22991
|
sourceSnapshot,
|
|
22570
|
-
[...existing,
|
|
22992
|
+
[...existing, Tools11.deepClone(rule)],
|
|
22571
22993
|
evaluateImmediately
|
|
22572
22994
|
);
|
|
22573
22995
|
}
|
|
@@ -22639,7 +23061,7 @@ function insertStyledSeparatorInSnapshot(sourceSnapshot, dashStyle = "single", c
|
|
|
22639
23061
|
const id = `sep_${generateRandomId10(6)}`;
|
|
22640
23062
|
const safeColor = color?.trim() || "#7D8698";
|
|
22641
23063
|
const rendered = renderStyledSeparatorSvg(dashStyle, safeColor, widthPt);
|
|
22642
|
-
const nextSnapshot =
|
|
23064
|
+
const nextSnapshot = Tools11.deepClone(sourceSnapshot);
|
|
22643
23065
|
const body = nextSnapshot.body;
|
|
22644
23066
|
const sortedParas = [...body.paragraphs ?? []].sort((a, b) => a.startIndex - b.startIndex);
|
|
22645
23067
|
const insertAt = clampSafeInsertOffset(body, offset);
|
|
@@ -22659,7 +23081,7 @@ function insertStyledSeparatorInSnapshot(sourceSnapshot, dashStyle = "single", c
|
|
|
22659
23081
|
if (needsLeadingBreak && hostPara && withLine.paragraphs) {
|
|
22660
23082
|
const prevStyle = hostPara.paragraphStyle;
|
|
22661
23083
|
withLine.paragraphs = withLine.paragraphs.map(
|
|
22662
|
-
(p) => p.startIndex === spliceAt && prevStyle ? { ...p, paragraphStyle:
|
|
23084
|
+
(p) => p.startIndex === spliceAt && prevStyle ? { ...p, paragraphStyle: Tools11.deepClone(prevStyle) } : p
|
|
22663
23085
|
);
|
|
22664
23086
|
}
|
|
22665
23087
|
nextSnapshot.body = withLine;
|
|
@@ -22694,7 +23116,7 @@ function insertStyledSeparatorInSnapshot(sourceSnapshot, dashStyle = "single", c
|
|
|
22694
23116
|
...p.paragraphStyle ?? {},
|
|
22695
23117
|
spaceAbove: { v: 3 },
|
|
22696
23118
|
spaceBelow: { v: 3 },
|
|
22697
|
-
yudaoStyledSeparator:
|
|
23119
|
+
yudaoStyledSeparator: Tools11.deepClone(entry)
|
|
22698
23120
|
}
|
|
22699
23121
|
};
|
|
22700
23122
|
});
|
|
@@ -22734,14 +23156,14 @@ function getStyledSeparatorsFromSnapshot(snapshot) {
|
|
|
22734
23156
|
const sep = p.paragraphStyle?.yudaoStyledSeparator;
|
|
22735
23157
|
if (sep && !seen.has(sep.id)) {
|
|
22736
23158
|
seen.add(sep.id);
|
|
22737
|
-
result.push(
|
|
23159
|
+
result.push(Tools11.deepClone(sep));
|
|
22738
23160
|
}
|
|
22739
23161
|
}
|
|
22740
23162
|
const liveBlockIds = new Set((body.customBlocks ?? []).map((b) => b.blockId));
|
|
22741
23163
|
for (const [id, sep] of Object.entries(meta.styledSeparators ?? {})) {
|
|
22742
23164
|
if (!seen.has(id) && liveBlockIds.has(id)) {
|
|
22743
23165
|
seen.add(id);
|
|
22744
|
-
result.push(
|
|
23166
|
+
result.push(Tools11.deepClone(sep));
|
|
22745
23167
|
}
|
|
22746
23168
|
}
|
|
22747
23169
|
return result;
|
|
@@ -22795,7 +23217,7 @@ function insertDocEmbedBlockInSnapshot(sourceSnapshot, spec, offset) {
|
|
|
22795
23217
|
heightPt,
|
|
22796
23218
|
...spec.posterDataUrl ? { posterDataUrl: spec.posterDataUrl } : {}
|
|
22797
23219
|
};
|
|
22798
|
-
const workingSnapshot =
|
|
23220
|
+
const workingSnapshot = Tools11.deepClone(sourceSnapshot);
|
|
22799
23221
|
const body = workingSnapshot.body;
|
|
22800
23222
|
const sortedParas = [...body.paragraphs ?? []].sort((a, b) => a.startIndex - b.startIndex);
|
|
22801
23223
|
const insertAt = clampSafeInsertOffset(body, offset);
|
|
@@ -22820,7 +23242,7 @@ function insertDocEmbedBlockInSnapshot(sourceSnapshot, spec, offset) {
|
|
|
22820
23242
|
if (needsLeadingBreak && hostPara.paragraphStyle && withLine.paragraphs) {
|
|
22821
23243
|
const prevStyle = hostPara.paragraphStyle;
|
|
22822
23244
|
withLine.paragraphs = withLine.paragraphs.map(
|
|
22823
|
-
(p) => p.startIndex === spliceAt ? { ...p, paragraphStyle:
|
|
23245
|
+
(p) => p.startIndex === spliceAt ? { ...p, paragraphStyle: Tools11.deepClone(prevStyle) } : p
|
|
22824
23246
|
);
|
|
22825
23247
|
}
|
|
22826
23248
|
workingSnapshot.body = withLine;
|
|
@@ -22869,19 +23291,19 @@ function getDocEmbedBlocksFromSnapshot(snapshot) {
|
|
|
22869
23291
|
for (const r of body.customRanges ?? []) {
|
|
22870
23292
|
const props = r.properties;
|
|
22871
23293
|
if (props?.yudaoBlockKind === "embedBlock" && props.blockId && liveBlockIds.has(props.blockId)) {
|
|
22872
|
-
byId.set(String(props.blockId),
|
|
23294
|
+
byId.set(String(props.blockId), Tools11.deepClone(props.spec));
|
|
22873
23295
|
}
|
|
22874
23296
|
}
|
|
22875
23297
|
for (const [id, blk] of Object.entries(metaMap)) {
|
|
22876
23298
|
if (liveBlockIds.has(id) && !byId.has(id)) {
|
|
22877
|
-
byId.set(id,
|
|
23299
|
+
byId.set(id, Tools11.deepClone(blk));
|
|
22878
23300
|
}
|
|
22879
23301
|
}
|
|
22880
23302
|
return [...body.customBlocks].sort((a, b) => a.startIndex - b.startIndex).map((b) => byId.get(b.blockId)).filter((e) => Boolean(e));
|
|
22881
23303
|
}
|
|
22882
23304
|
function removeDocEmbedBlockFromSnapshot(sourceSnapshot, id) {
|
|
22883
23305
|
if (!sourceSnapshot.body || !id) return null;
|
|
22884
|
-
const nextSnapshot =
|
|
23306
|
+
const nextSnapshot = Tools11.deepClone(sourceSnapshot);
|
|
22885
23307
|
const nextBody = removeInlineDrawingBlockFromBody(nextSnapshot.body, id);
|
|
22886
23308
|
if (!nextBody) return null;
|
|
22887
23309
|
nextSnapshot.body = nextBody;
|
|
@@ -22951,7 +23373,7 @@ function getRegisteredDocMacros(unitId) {
|
|
|
22951
23373
|
}
|
|
22952
23374
|
var MACRO_TOKEN_RE = /\{\{\s*([\p{L}\p{N}_.-]+)\s*\}\}/gu;
|
|
22953
23375
|
function applyDocMacrosInSnapshot(sourceSnapshot, options) {
|
|
22954
|
-
const nextSnapshot =
|
|
23376
|
+
const nextSnapshot = Tools11.deepClone(sourceSnapshot);
|
|
22955
23377
|
if (!nextSnapshot.body) {
|
|
22956
23378
|
return { snapshot: nextSnapshot, replacedCount: 0, resolvedValues: {} };
|
|
22957
23379
|
}
|
|
@@ -23038,7 +23460,7 @@ function applyDocMacrosInSnapshot(sourceSnapshot, options) {
|
|
|
23038
23460
|
}
|
|
23039
23461
|
function addDocGraffitiStrokeInSnapshot(sourceSnapshot, spec) {
|
|
23040
23462
|
if (!Array.isArray(spec?.points) || spec.points.length === 0) return null;
|
|
23041
|
-
const nextSnapshot =
|
|
23463
|
+
const nextSnapshot = Tools11.deepClone(sourceSnapshot);
|
|
23042
23464
|
const stroke = {
|
|
23043
23465
|
id: spec.id?.trim() || `grf_${generateRandomId10(6)}`,
|
|
23044
23466
|
pageIndex: Math.max(0, Math.floor(Number(spec.pageIndex) || 0)),
|
|
@@ -23062,14 +23484,14 @@ function addDocGraffitiStrokeInSnapshot(sourceSnapshot, spec) {
|
|
|
23062
23484
|
}
|
|
23063
23485
|
function getDocGraffitiStrokesFromSnapshot(snapshot, pageIndex) {
|
|
23064
23486
|
const meta = readDocTemplateMetadataFromSnapshot(snapshot);
|
|
23065
|
-
const strokes =
|
|
23487
|
+
const strokes = Tools11.deepClone(meta.graffitiStrokes ?? []);
|
|
23066
23488
|
if (typeof pageIndex === "number") {
|
|
23067
23489
|
return strokes.filter((s) => s.pageIndex === pageIndex);
|
|
23068
23490
|
}
|
|
23069
23491
|
return strokes;
|
|
23070
23492
|
}
|
|
23071
23493
|
function clearDocGraffitiStrokesInSnapshot(sourceSnapshot, pageIndex) {
|
|
23072
|
-
const nextSnapshot =
|
|
23494
|
+
const nextSnapshot = Tools11.deepClone(sourceSnapshot);
|
|
23073
23495
|
const meta = readDocTemplateMetadataFromSnapshot(nextSnapshot);
|
|
23074
23496
|
const remaining = typeof pageIndex === "number" ? (meta.graffitiStrokes ?? []).filter((s) => s.pageIndex !== pageIndex) : [];
|
|
23075
23497
|
const nextMeta = { ...meta };
|
|
@@ -23089,19 +23511,88 @@ var PATH_PART = "[\\p{L}\\p{N}_.\\[\\]-]+";
|
|
|
23089
23511
|
var EXPLICIT_LIST_TOKEN_RE = new RegExp(`(?:\\$|#)\\{#(${IDENT_PART})\\.(${PATH_PART})\\}`, "gu");
|
|
23090
23512
|
var EXPLICIT_NESTED_LIST_TOKEN_RE = new RegExp(`(?:\\$|#)\\{#(${PATH_PART})\\}`, "gu");
|
|
23091
23513
|
var ANY_CELL_TOKEN_RE = new RegExp(`(?:\\$|#)\\{(#?)(${PATH_PART})\\}`, "gu");
|
|
23092
|
-
var INLINE_VALUE_TOKEN_RE = new RegExp(`(?:\\$|#)\\{(
|
|
23514
|
+
var INLINE_VALUE_TOKEN_RE = new RegExp(`(?:\\$|#)\\{(#?${PATH_PART})\\}`, "gu");
|
|
23515
|
+
function parseDocBindingKey(rawKey) {
|
|
23516
|
+
const trimmed = typeof rawKey === "string" ? rawKey.trim() : "";
|
|
23517
|
+
let inner = trimmed;
|
|
23518
|
+
const wrappedMatch = inner.match(/^(?:\$|#)\{([\s\S]*)\}$/);
|
|
23519
|
+
if (wrappedMatch) {
|
|
23520
|
+
inner = wrappedMatch[1].trim();
|
|
23521
|
+
}
|
|
23522
|
+
inner = inner.replace(/^#/, "").trim();
|
|
23523
|
+
const dotIdx = inner.indexOf(".");
|
|
23524
|
+
if (dotIdx > 0 && dotIdx < inner.length - 1) {
|
|
23525
|
+
const datasetCode = inner.slice(0, dotIdx).replace(/\[\d+\]$/, "").trim();
|
|
23526
|
+
const fieldPath = inner.slice(dotIdx + 1).trim();
|
|
23527
|
+
return {
|
|
23528
|
+
rawKey: trimmed,
|
|
23529
|
+
...datasetCode ? { datasetCode } : {},
|
|
23530
|
+
fieldPath
|
|
23531
|
+
};
|
|
23532
|
+
}
|
|
23533
|
+
return {
|
|
23534
|
+
rawKey: trimmed,
|
|
23535
|
+
fieldPath: inner
|
|
23536
|
+
};
|
|
23537
|
+
}
|
|
23538
|
+
function extractDocInlinePlaceholders(text, syntax = "both") {
|
|
23539
|
+
if (typeof text !== "string" || text.length === 0) return [];
|
|
23540
|
+
const sigilGroup = syntax === "dollar" ? "(\\$)" : syntax === "hash" ? "(#)" : "(\\$|#)";
|
|
23541
|
+
const re = new RegExp(`${sigilGroup}\\{(#?${PATH_PART})\\}`, "gu");
|
|
23542
|
+
const matches = [];
|
|
23543
|
+
let m;
|
|
23544
|
+
while ((m = re.exec(text)) !== null) {
|
|
23545
|
+
const sigil = m[1] === "#" ? "hash" : "dollar";
|
|
23546
|
+
const rawKey = m[2];
|
|
23547
|
+
const parsed = parseDocBindingKey(rawKey);
|
|
23548
|
+
matches.push({
|
|
23549
|
+
token: m[0],
|
|
23550
|
+
rawKey,
|
|
23551
|
+
syntax: sigil,
|
|
23552
|
+
index: m.index,
|
|
23553
|
+
...parsed.datasetCode ? { datasetCode: parsed.datasetCode } : {},
|
|
23554
|
+
fieldPath: parsed.fieldPath
|
|
23555
|
+
});
|
|
23556
|
+
}
|
|
23557
|
+
return matches;
|
|
23558
|
+
}
|
|
23559
|
+
function extractDocFieldInstruction(range) {
|
|
23560
|
+
const props = range?.properties ?? void 0;
|
|
23561
|
+
if (!props) return void 0;
|
|
23562
|
+
if (typeof props.fieldInstr === "string" && props.fieldInstr.trim().length > 0) {
|
|
23563
|
+
return props.fieldInstr.trim();
|
|
23564
|
+
}
|
|
23565
|
+
if (props.yudaoBlockKind === "docField" || props.field != null) {
|
|
23566
|
+
const fallback = props.instrText ?? props.field?.instrText ?? props.field?.fieldType;
|
|
23567
|
+
if (typeof fallback === "string" && fallback.trim().length > 0) {
|
|
23568
|
+
return fallback.trim();
|
|
23569
|
+
}
|
|
23570
|
+
}
|
|
23571
|
+
return void 0;
|
|
23572
|
+
}
|
|
23573
|
+
function isDynamicPageFieldInstruction(instr) {
|
|
23574
|
+
if (!instr || typeof instr !== "string") return false;
|
|
23575
|
+
const firstToken = (instr.trim().replace(/^\\+/, "").split(/[\s\\]+/)[0] || "").toUpperCase();
|
|
23576
|
+
return firstToken === "PAGE" || firstToken === "NUMPAGES" || firstToken === "SECTIONPAGES" || firstToken === "PAGEREF";
|
|
23577
|
+
}
|
|
23093
23578
|
function resolvePathValue(source, path) {
|
|
23094
23579
|
if (!source || !path) return void 0;
|
|
23095
|
-
if (
|
|
23096
|
-
return source[path];
|
|
23580
|
+
if (!path.includes(".") && !path.includes("[")) {
|
|
23581
|
+
return Object.prototype.hasOwnProperty.call(source, path) ? source[path] : void 0;
|
|
23097
23582
|
}
|
|
23098
23583
|
const parts = path.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
|
|
23099
23584
|
let cur = source;
|
|
23100
23585
|
for (const key of parts) {
|
|
23101
|
-
if (cur == null || typeof cur !== "object")
|
|
23586
|
+
if (cur == null || typeof cur !== "object") {
|
|
23587
|
+
cur = void 0;
|
|
23588
|
+
break;
|
|
23589
|
+
}
|
|
23102
23590
|
cur = cur[key];
|
|
23103
23591
|
}
|
|
23104
|
-
|
|
23592
|
+
if (cur !== void 0) {
|
|
23593
|
+
return cur;
|
|
23594
|
+
}
|
|
23595
|
+
return Object.prototype.hasOwnProperty.call(source, path) ? source[path] : void 0;
|
|
23105
23596
|
}
|
|
23106
23597
|
function readDocTemplateMetadataFromSnapshot(snapshot) {
|
|
23107
23598
|
const entry = (snapshot?.resources ?? []).find((r) => r.name === YUDAO_DOCS_TEMPLATE_RESOURCE);
|
|
@@ -23143,11 +23634,11 @@ function normalizeDocDrawingsAndPluginResource(snapshot) {
|
|
|
23143
23634
|
const tid = tbl?.tableId;
|
|
23144
23635
|
if (!tid) continue;
|
|
23145
23636
|
if (snapshot.tableSource?.[tid] && !seg.tableSource?.[tid]) {
|
|
23146
|
-
seg.tableSource = { ...seg.tableSource ?? {}, [tid]:
|
|
23637
|
+
seg.tableSource = { ...seg.tableSource ?? {}, [tid]: Tools12.deepClone(snapshot.tableSource[tid]) };
|
|
23147
23638
|
} else if (seg.tableSource?.[tid] && !snapshot.tableSource?.[tid]) {
|
|
23148
23639
|
snapshot.tableSource = {
|
|
23149
23640
|
...snapshot.tableSource ?? {},
|
|
23150
|
-
[tid]:
|
|
23641
|
+
[tid]: Tools12.deepClone(seg.tableSource[tid])
|
|
23151
23642
|
};
|
|
23152
23643
|
}
|
|
23153
23644
|
}
|
|
@@ -23176,7 +23667,7 @@ function normalizeDocDrawingsAndPluginResource(snapshot) {
|
|
|
23176
23667
|
}
|
|
23177
23668
|
return snapshot;
|
|
23178
23669
|
}
|
|
23179
|
-
const mergedDrawings = snapKeys.length > 0 ? { ...
|
|
23670
|
+
const mergedDrawings = snapKeys.length > 0 ? { ...Tools12.deepClone(pluginData), ...Tools12.deepClone(snapDrawings) } : Tools12.deepClone(pluginData);
|
|
23180
23671
|
const hfBlockIds = /* @__PURE__ */ new Set();
|
|
23181
23672
|
for (const hdr of Object.values(snapshot.headers ?? {})) {
|
|
23182
23673
|
for (const blk of hdr?.body?.customBlocks ?? []) {
|
|
@@ -23204,7 +23695,7 @@ function normalizeDocDrawingsAndPluginResource(snapshot) {
|
|
|
23204
23695
|
}
|
|
23205
23696
|
if (hfBlockIds.has(drawingId)) {
|
|
23206
23697
|
drw.isMultiTransform = BooleanNumber5.TRUE;
|
|
23207
|
-
drw.transforms = Array.isArray(drw.transforms) && drw.transforms.length > 0 ? drw.transforms : drw.transform ? [
|
|
23698
|
+
drw.transforms = Array.isArray(drw.transforms) && drw.transforms.length > 0 ? drw.transforms : drw.transform ? [Tools12.deepClone(drw.transform)] : [];
|
|
23208
23699
|
}
|
|
23209
23700
|
}
|
|
23210
23701
|
snapshot.drawings = mergedDrawings;
|
|
@@ -23334,8 +23825,8 @@ var SDT_CHROME_BG_COLORS = /* @__PURE__ */ new Set(["#f3f5ff", "#eeeff1"]);
|
|
|
23334
23825
|
function sanitizeLoopCellRunStyle(ts, anchorTypo) {
|
|
23335
23826
|
if (!ts && !anchorTypo) return void 0;
|
|
23336
23827
|
const out = {
|
|
23337
|
-
...ts ?
|
|
23338
|
-
...anchorTypo ?
|
|
23828
|
+
...ts ? Tools12.deepClone(ts) : {},
|
|
23829
|
+
...anchorTypo ? Tools12.deepClone(anchorTypo) : {}
|
|
23339
23830
|
};
|
|
23340
23831
|
const bgRgb = out.bg?.rgb?.trim().toLowerCase();
|
|
23341
23832
|
if (bgRgb && SDT_CHROME_BG_COLORS.has(bgRgb)) {
|
|
@@ -23351,7 +23842,7 @@ function sanitizeLoopCellRunStyle(ts, anchorTypo) {
|
|
|
23351
23842
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
23352
23843
|
}
|
|
23353
23844
|
function stripDocEditorChromeForView(snapshot) {
|
|
23354
|
-
const cloned =
|
|
23845
|
+
const cloned = Tools12.deepClone(snapshot);
|
|
23355
23846
|
const cleanBody = (body) => {
|
|
23356
23847
|
if (!body?.customRanges?.length || !body.textRuns?.length) return;
|
|
23357
23848
|
for (const r of body.customRanges) {
|
|
@@ -23396,7 +23887,7 @@ function extractAnchorTypography(ts) {
|
|
|
23396
23887
|
has = true;
|
|
23397
23888
|
}
|
|
23398
23889
|
if (ts.yudaoRFonts !== void 0) {
|
|
23399
|
-
out.yudaoRFonts =
|
|
23890
|
+
out.yudaoRFonts = Tools12.deepClone(
|
|
23400
23891
|
ts.yudaoRFonts
|
|
23401
23892
|
);
|
|
23402
23893
|
has = true;
|
|
@@ -23414,11 +23905,11 @@ function extractAnchorTypography(ts) {
|
|
|
23414
23905
|
has = true;
|
|
23415
23906
|
}
|
|
23416
23907
|
if (ts.ul !== void 0) {
|
|
23417
|
-
out.ul =
|
|
23908
|
+
out.ul = Tools12.deepClone(ts.ul);
|
|
23418
23909
|
has = true;
|
|
23419
23910
|
}
|
|
23420
23911
|
if (ts.st !== void 0) {
|
|
23421
|
-
out.st =
|
|
23912
|
+
out.st = Tools12.deepClone(ts.st);
|
|
23422
23913
|
has = true;
|
|
23423
23914
|
}
|
|
23424
23915
|
if (ts.va !== void 0) {
|
|
@@ -23471,7 +23962,7 @@ function matchSdtHighlightRule(rules, textOrValue) {
|
|
|
23471
23962
|
}
|
|
23472
23963
|
function computeSdtVisualStyle(kind, lock, showingPlaceholder, hasBinding, matchedHighlight, visualChrome, anchorTypography, options) {
|
|
23473
23964
|
void hasBinding;
|
|
23474
|
-
const baseTypo = anchorTypography ?
|
|
23965
|
+
const baseTypo = anchorTypography ? Tools12.deepClone(anchorTypography) : {};
|
|
23475
23966
|
if (options?.invalidHighlight) {
|
|
23476
23967
|
return {
|
|
23477
23968
|
...baseTypo,
|
|
@@ -23865,9 +24356,9 @@ function buildSdtPropertiesFromSpec(spec, showingPlaceholder, normalizedValue) {
|
|
|
23865
24356
|
sdtValue: normalizedValue,
|
|
23866
24357
|
...spec.conceptId ? { conceptId: spec.conceptId } : {},
|
|
23867
24358
|
...spec.deletable !== void 0 ? { deletable: spec.deletable } : {},
|
|
23868
|
-
...spec.cascaderOptions?.length ? { cascaderOptions:
|
|
24359
|
+
...spec.cascaderOptions?.length ? { cascaderOptions: Tools12.deepClone(spec.cascaderOptions) } : {},
|
|
23869
24360
|
...spec.cascaderSeparator !== void 0 ? { cascaderSeparator: spec.cascaderSeparator } : {},
|
|
23870
|
-
...spec.highlightRules?.length ? { highlightRules:
|
|
24361
|
+
...spec.highlightRules?.length ? { highlightRules: Tools12.deepClone(spec.highlightRules) } : {},
|
|
23871
24362
|
...spec.visibleIf ? { visibleIf: spec.visibleIf } : {},
|
|
23872
24363
|
...spec.computedExpr ? { computedExpr: spec.computedExpr } : {},
|
|
23873
24364
|
...typeof spec.min === "number" ? { min: spec.min } : {},
|
|
@@ -23885,7 +24376,7 @@ function buildSdtPropertiesFromSpec(spec, showingPlaceholder, normalizedValue) {
|
|
|
23885
24376
|
...spec.calculatorEnabled !== void 0 ? { calculatorEnabled: spec.calculatorEnabled } : {},
|
|
23886
24377
|
...spec.checkboxMarkType ? { checkboxMarkType: spec.checkboxMarkType } : {},
|
|
23887
24378
|
...spec.layoutDirection ? { layoutDirection: spec.layoutDirection } : {},
|
|
23888
|
-
...spec.options?.length ? { options:
|
|
24379
|
+
...spec.options?.length ? { options: Tools12.deepClone(spec.options) } : {},
|
|
23889
24380
|
...typeof spec.minLength === "number" ? { minLength: spec.minLength } : {},
|
|
23890
24381
|
...typeof spec.maxLength === "number" ? { maxLength: spec.maxLength } : {},
|
|
23891
24382
|
...spec.integer !== void 0 ? { integer: spec.integer } : {},
|
|
@@ -23897,7 +24388,7 @@ function buildSdtPropertiesFromSpec(spec, showingPlaceholder, normalizedValue) {
|
|
|
23897
24388
|
...typeof spec.widthPt === "number" ? { widthPt: spec.widthPt } : {},
|
|
23898
24389
|
...typeof spec.heightPt === "number" ? { heightPt: spec.heightPt } : {},
|
|
23899
24390
|
...spec.invalidHighlight !== void 0 ? { invalidHighlight: spec.invalidHighlight } : {},
|
|
23900
|
-
...spec.anchorTextStyle ? { anchorTextStyle:
|
|
24391
|
+
...spec.anchorTextStyle ? { anchorTextStyle: Tools12.deepClone(spec.anchorTextStyle) } : {},
|
|
23901
24392
|
...spec.drawingBlockId ? { drawingBlockId: spec.drawingBlockId } : {},
|
|
23902
24393
|
...spec.validatorPreset ? { validatorPreset: spec.validatorPreset } : {},
|
|
23903
24394
|
...spec.validatorPattern ? { validatorPattern: spec.validatorPattern } : {},
|
|
@@ -23913,7 +24404,7 @@ function buildSdtPropertiesFromSpec(spec, showingPlaceholder, normalizedValue) {
|
|
|
23913
24404
|
}
|
|
23914
24405
|
if (kind === "checkbox") {
|
|
23915
24406
|
if (resolvedListItems && resolvedListItems.length > 0) {
|
|
23916
|
-
props.listItems =
|
|
24407
|
+
props.listItems = Tools12.deepClone(resolvedListItems);
|
|
23917
24408
|
props.checkbox = {
|
|
23918
24409
|
checked: typeof normalizedValue === "string" ? normalizedValue.length > 0 : Boolean(normalizedValue)
|
|
23919
24410
|
};
|
|
@@ -23929,7 +24420,7 @@ function buildSdtPropertiesFromSpec(spec, showingPlaceholder, normalizedValue) {
|
|
|
23929
24420
|
};
|
|
23930
24421
|
} else if (kind === "cascader") {
|
|
23931
24422
|
const resolvedOpts = spec.cascaderOptions && spec.cascaderOptions.length > 0 ? spec.cascaderOptions : DEFAULT_CASCADER_OPTIONS;
|
|
23932
|
-
props.cascaderOptions =
|
|
24423
|
+
props.cascaderOptions = Tools12.deepClone(resolvedOpts);
|
|
23933
24424
|
props.listItems = flattenCascaderLeafItems(resolvedOpts, spec.cascaderSeparator ?? " / ");
|
|
23934
24425
|
} else if (kind === "dropDownList" || kind === "comboBox" || kind === "radio" || kind === "multiSelect") {
|
|
23935
24426
|
props.listItems = resolvedListItems && resolvedListItems.length > 0 ? resolvedListItems : [
|
|
@@ -23957,7 +24448,7 @@ function parseSdtRangeToResolved(body, range, segmentId) {
|
|
|
23957
24448
|
const validatorPattern = typeof props.validatorPattern === "string" ? props.validatorPattern : void 0;
|
|
23958
24449
|
const validatorMessage = typeof props.validatorMessage === "string" ? props.validatorMessage : void 0;
|
|
23959
24450
|
const editableRoles = Array.isArray(props.editableRoles) ? props.editableRoles.filter((r) => typeof r === "string" && r.trim().length > 0) : void 0;
|
|
23960
|
-
const options = Array.isArray(props.options) ?
|
|
24451
|
+
const options = Array.isArray(props.options) ? Tools12.deepClone(props.options) : void 0;
|
|
23961
24452
|
const resolvedListItems = normalizeSdtListItems({ listItems: props.listItems, options });
|
|
23962
24453
|
const displayText = body.dataStream.slice(range.startIndex, range.endIndex + 1).replace(/[\r\n\u0000-\u001F]/g, "");
|
|
23963
24454
|
const coreDisplayText = stripSdtAffixes(displayText, {
|
|
@@ -24040,7 +24531,7 @@ function parseSdtRangeToResolved(body, range, segmentId) {
|
|
|
24040
24531
|
tag,
|
|
24041
24532
|
...typeof props.conceptId === "string" && props.conceptId ? { conceptId: props.conceptId } : {},
|
|
24042
24533
|
...typeof props.deletable === "boolean" ? { deletable: props.deletable } : {},
|
|
24043
|
-
...Array.isArray(props.cascaderOptions) ? { cascaderOptions:
|
|
24534
|
+
...Array.isArray(props.cascaderOptions) ? { cascaderOptions: Tools12.deepClone(props.cascaderOptions) } : {},
|
|
24044
24535
|
...typeof props.cascaderSeparator === "string" ? { cascaderSeparator: props.cascaderSeparator } : {},
|
|
24045
24536
|
placeholder: props.placeholder,
|
|
24046
24537
|
bindingPath,
|
|
@@ -24385,7 +24876,7 @@ function validateDocForm(snapshot) {
|
|
|
24385
24876
|
};
|
|
24386
24877
|
}
|
|
24387
24878
|
function spliceDocumentBodySpan(sourceBody, start, endInclusive, replacementText, options) {
|
|
24388
|
-
const body =
|
|
24879
|
+
const body = Tools12.deepClone(sourceBody);
|
|
24389
24880
|
const oldLen = endInclusive >= start ? endInclusive - start + 1 : 0;
|
|
24390
24881
|
const newLen = replacementText.length;
|
|
24391
24882
|
const delta = newLen - oldLen;
|
|
@@ -24508,7 +24999,7 @@ function insertSdtControlIntoBody(sourceBody, rawOffset, spec, initialValue, opt
|
|
|
24508
24999
|
const lock = spec.lock ?? (kind === "group" ? "contentLocked" : "sdtLocked");
|
|
24509
25000
|
const inheritedTypo = spec.anchorTextStyle ?? resolveBodyOffsetTypography(sourceBody, insertAt);
|
|
24510
25001
|
if (kind === "group" && hasSelectionWrap && wrapEndExclusive > insertAt) {
|
|
24511
|
-
const nextBody2 =
|
|
25002
|
+
const nextBody2 = Tools12.deepClone(sourceBody);
|
|
24512
25003
|
const wrappedPlain = nextBody2.dataStream.slice(insertAt, wrapEndExclusive).replace(/[\r\n\u0000-\u001F]/g, "");
|
|
24513
25004
|
const properties2 = buildSdtPropertiesFromSpec(
|
|
24514
25005
|
{ ...spec, id: controlId, kind, alias, lock, anchorTextStyle: inheritedTypo },
|
|
@@ -24638,7 +25129,7 @@ function applyPictureOrSignatureSdtValueInSnapshot(snapshot, ctrl, rawImageValue
|
|
|
24638
25129
|
inheritedTypo,
|
|
24639
25130
|
{ underlineBlank: ctrl.underlineBlank, minWidthPt: ctrl.minWidthPt }
|
|
24640
25131
|
);
|
|
24641
|
-
const cleanedBody =
|
|
25132
|
+
const cleanedBody = Tools12.deepClone(body);
|
|
24642
25133
|
if (prevBlockId && cleanedBody.customBlocks) {
|
|
24643
25134
|
cleanedBody.customBlocks = cleanedBody.customBlocks.filter((b) => b.blockId !== prevBlockId);
|
|
24644
25135
|
}
|
|
@@ -24667,7 +25158,7 @@ function applyPictureOrSignatureSdtValueInSnapshot(snapshot, ctrl, rawImageValue
|
|
|
24667
25158
|
false,
|
|
24668
25159
|
dataUri
|
|
24669
25160
|
);
|
|
24670
|
-
const preCleaned =
|
|
25161
|
+
const preCleaned = Tools12.deepClone(body);
|
|
24671
25162
|
if (preCleaned.customBlocks) {
|
|
24672
25163
|
preCleaned.customBlocks = preCleaned.customBlocks.filter(
|
|
24673
25164
|
(b) => b.blockId !== blockId && (b.startIndex < range.startIndex || b.startIndex > range.endIndex)
|
|
@@ -24876,8 +25367,9 @@ function replaceRowCellTokens(rawCellText, listKey, itemObj, rowSeqIndex, rootDa
|
|
|
24876
25367
|
if (rootVal !== void 0 && rootVal !== null && typeof rootVal !== "object") {
|
|
24877
25368
|
return String(rootVal);
|
|
24878
25369
|
}
|
|
25370
|
+
return "";
|
|
24879
25371
|
}
|
|
24880
|
-
return
|
|
25372
|
+
return "";
|
|
24881
25373
|
});
|
|
24882
25374
|
}
|
|
24883
25375
|
function renderLoopCellContent(body, cell, cellSdts, detectedListKey, itemObj, rowSeqIndex, rootData, hasExplicitListKey) {
|
|
@@ -24985,6 +25477,43 @@ function renderLoopCellContent(body, cell, cellSdts, detectedListKey, itemObj, r
|
|
|
24985
25477
|
}
|
|
24986
25478
|
return out;
|
|
24987
25479
|
}
|
|
25480
|
+
function assertRowLoopStructureSupported(body, tableId, tableIndex, rowSpan, rowIndex, tblSource) {
|
|
25481
|
+
const rowSlice = body.dataStream.slice(rowSpan.rowStart, rowSpan.rowEndInclusive + 1);
|
|
25482
|
+
const hasNestedStreamToken = rowSlice.includes(DataStreamTreeTokenType13.TABLE_START) || rowSlice.includes(DataStreamTreeTokenType13.TABLE_END);
|
|
25483
|
+
const hasNestedTableRange = (body.tables ?? []).some(
|
|
25484
|
+
(otherTbl, otherIdx) => otherIdx !== tableIndex && otherTbl.startIndex >= rowSpan.rowStart && otherTbl.startIndex <= rowSpan.rowEndInclusive
|
|
25485
|
+
);
|
|
25486
|
+
if (hasNestedStreamToken || hasNestedTableRange) {
|
|
25487
|
+
throw new DocTemplateProtocolError(
|
|
25488
|
+
"UNSUPPORTED_ROW_LOOP_STRUCTURE",
|
|
25489
|
+
`Detail loop row ${rowIndex} in table "${tableId}" contains a nested table, which is unsupported by single-level tableRowLoops.`,
|
|
25490
|
+
{ tableId, rowIndex }
|
|
25491
|
+
);
|
|
25492
|
+
}
|
|
25493
|
+
const rowCells = tblSource?.tableRows?.[rowIndex]?.tableCells ?? [];
|
|
25494
|
+
const hasDirectVerticalMerge = rowCells.some((cell) => {
|
|
25495
|
+
if (!cell) return false;
|
|
25496
|
+
const anyCell = cell;
|
|
25497
|
+
return typeof cell.rowSpan === "number" && (cell.rowSpan > 1 || cell.rowSpan === 0) || anyCell.vMerge !== void 0;
|
|
25498
|
+
});
|
|
25499
|
+
let coveredByUpperVerticalMerge = false;
|
|
25500
|
+
if (!hasDirectVerticalMerge && tblSource?.tableRows) {
|
|
25501
|
+
for (let prevR = 0; prevR < rowIndex && prevR < tblSource.tableRows.length; prevR++) {
|
|
25502
|
+
const prevCells = tblSource.tableRows[prevR]?.tableCells ?? [];
|
|
25503
|
+
if (prevCells.some((c) => typeof c?.rowSpan === "number" && c.rowSpan > rowIndex - prevR)) {
|
|
25504
|
+
coveredByUpperVerticalMerge = true;
|
|
25505
|
+
break;
|
|
25506
|
+
}
|
|
25507
|
+
}
|
|
25508
|
+
}
|
|
25509
|
+
if (hasDirectVerticalMerge || coveredByUpperVerticalMerge) {
|
|
25510
|
+
throw new DocTemplateProtocolError(
|
|
25511
|
+
"UNSUPPORTED_ROW_LOOP_STRUCTURE",
|
|
25512
|
+
`Detail loop row ${rowIndex} in table "${tableId}" participates in a vertical cell merge (vMerge / rowSpan), which is unsupported by single-level tableRowLoops.`,
|
|
25513
|
+
{ tableId, rowIndex }
|
|
25514
|
+
);
|
|
25515
|
+
}
|
|
25516
|
+
}
|
|
24988
25517
|
function expandDocTableRowLoopsInPlace(nextSnapshot, data, explicitLoops) {
|
|
24989
25518
|
const body = nextSnapshot.body;
|
|
24990
25519
|
if (!body?.tables?.length) return;
|
|
@@ -25001,7 +25530,8 @@ function expandDocTableRowLoopsInPlace(nextSnapshot, data, explicitLoops) {
|
|
|
25001
25530
|
if (parsedRows.length === 0) continue;
|
|
25002
25531
|
const tblSource = nextSnapshot.tableSource?.[tblRef.tableId];
|
|
25003
25532
|
let remainingRowCount = parsedRows.length;
|
|
25004
|
-
|
|
25533
|
+
const detectedRowLoops = /* @__PURE__ */ new Map();
|
|
25534
|
+
for (let rIdx = 0; rIdx < parsedRows.length; rIdx++) {
|
|
25005
25535
|
const rowSpan = parsedRows[rIdx];
|
|
25006
25536
|
const loopKey = `${tblRef.tableId}:${rIdx}`;
|
|
25007
25537
|
const explicitCfg = loopMap[loopKey];
|
|
@@ -25057,35 +25587,54 @@ function expandDocTableRowLoopsInPlace(nextSnapshot, data, explicitLoops) {
|
|
|
25057
25587
|
}
|
|
25058
25588
|
}
|
|
25059
25589
|
}
|
|
25590
|
+
if (explicitCfg || detectedListKey) {
|
|
25591
|
+
assertRowLoopStructureSupported(body, tblRef.tableId, tIdx, rowSpan, rIdx, tblSource);
|
|
25592
|
+
}
|
|
25060
25593
|
if (!detectedListKey) continue;
|
|
25061
|
-
|
|
25062
|
-
|
|
25063
|
-
|
|
25064
|
-
|
|
25065
|
-
|
|
25066
|
-
|
|
25067
|
-
|
|
25068
|
-
|
|
25069
|
-
|
|
25070
|
-
|
|
25071
|
-
|
|
25072
|
-
|
|
25073
|
-
|
|
25074
|
-
|
|
25075
|
-
|
|
25076
|
-
|
|
25077
|
-
delete snapMeta.tableRepeatHeaders[tblRef.tableId];
|
|
25078
|
-
metaChanged = true;
|
|
25079
|
-
}
|
|
25080
|
-
} else if (repeatHeader && rIdx > 0 && tblSource?.tableRows) {
|
|
25081
|
-
for (let h = 0; h < rIdx && h < tblSource.tableRows.length; h++) {
|
|
25594
|
+
detectedRowLoops.set(rIdx, {
|
|
25595
|
+
loopKey,
|
|
25596
|
+
explicitCfg,
|
|
25597
|
+
hasExplicitListKey,
|
|
25598
|
+
detectedListKey,
|
|
25599
|
+
rowCellSdts
|
|
25600
|
+
});
|
|
25601
|
+
}
|
|
25602
|
+
if (detectedRowLoops.size === 0) continue;
|
|
25603
|
+
const firstLoopRowIdx = Math.min(...detectedRowLoops.keys());
|
|
25604
|
+
const firstLoopMeta = detectedRowLoops.get(firstLoopRowIdx);
|
|
25605
|
+
const firstRepeatHeader = firstLoopMeta.explicitCfg?.repeatHeaderRow ?? true;
|
|
25606
|
+
if (firstLoopMeta.explicitCfg?.repeatHeaderRow === false) {
|
|
25607
|
+
if (tblSource?.tableRows) {
|
|
25608
|
+
const upper = Math.max(1, firstLoopRowIdx);
|
|
25609
|
+
for (let h = 0; h < upper && h < tblSource.tableRows.length; h++) {
|
|
25082
25610
|
tblSource.tableRows[h] = {
|
|
25083
25611
|
...tblSource.tableRows[h],
|
|
25084
|
-
|
|
25085
|
-
repeatHeaderRow: BooleanNumber5.TRUE
|
|
25612
|
+
repeatHeaderRow: BooleanNumber5.FALSE
|
|
25086
25613
|
};
|
|
25087
25614
|
}
|
|
25088
25615
|
}
|
|
25616
|
+
if (snapMeta.tableRepeatHeaders && tblRef.tableId in snapMeta.tableRepeatHeaders) {
|
|
25617
|
+
delete snapMeta.tableRepeatHeaders[tblRef.tableId];
|
|
25618
|
+
metaChanged = true;
|
|
25619
|
+
}
|
|
25620
|
+
} else if (firstRepeatHeader && firstLoopRowIdx > 0 && tblSource?.tableRows) {
|
|
25621
|
+
for (let h = 0; h < firstLoopRowIdx && h < tblSource.tableRows.length; h++) {
|
|
25622
|
+
tblSource.tableRows[h] = {
|
|
25623
|
+
...tblSource.tableRows[h],
|
|
25624
|
+
...h === 0 ? { isFirstRow: BooleanNumber5.TRUE } : {},
|
|
25625
|
+
repeatHeaderRow: BooleanNumber5.TRUE
|
|
25626
|
+
};
|
|
25627
|
+
}
|
|
25628
|
+
}
|
|
25629
|
+
for (let rIdx = parsedRows.length - 1; rIdx >= 0; rIdx--) {
|
|
25630
|
+
const detectedEntry = detectedRowLoops.get(rIdx);
|
|
25631
|
+
if (!detectedEntry) continue;
|
|
25632
|
+
const rowSpan = parsedRows[rIdx];
|
|
25633
|
+
const { loopKey, explicitCfg, hasExplicitListKey, detectedListKey, rowCellSdts } = detectedEntry;
|
|
25634
|
+
consumedLoopKeys.add(loopKey);
|
|
25635
|
+
const rawItems = resolvePathValue(data, detectedListKey) ?? data?.[detectedListKey];
|
|
25636
|
+
const items = Array.isArray(rawItems) ? rawItems : [];
|
|
25637
|
+
const emptyStrategy = explicitCfg?.emptyStrategy ?? "keep-blank";
|
|
25089
25638
|
if (items.length === 0 && emptyStrategy === "remove" && remainingRowCount > 1) {
|
|
25090
25639
|
remainingRowCount--;
|
|
25091
25640
|
const removeStart = rowSpan.rowStart;
|
|
@@ -25249,7 +25798,7 @@ function expandDocTableRowLoopsInPlace(nextSnapshot, data, explicitLoops) {
|
|
|
25249
25798
|
builtRuns.push({
|
|
25250
25799
|
st: lineStart,
|
|
25251
25800
|
ed: lineEnd,
|
|
25252
|
-
ts:
|
|
25801
|
+
ts: Tools12.deepClone(cellStyles[cIdx])
|
|
25253
25802
|
});
|
|
25254
25803
|
}
|
|
25255
25804
|
const pOffset = baseInsertOffset + builtStream.length;
|
|
@@ -25258,7 +25807,7 @@ function expandDocTableRowLoopsInPlace(nextSnapshot, data, explicitLoops) {
|
|
|
25258
25807
|
const isFinalLine = lineIdx === cellLines.length - 1;
|
|
25259
25808
|
const deterministicParaId = cloneIdx === 0 && tplParasInCell[lineIdx]?.paragraphId ? tplParasInCell[lineIdx].paragraphId : cloneIdx === 0 && isFinalLine && fallbackTplPara?.paragraphId && cellLines.length === 1 ? fallbackTplPara.paragraphId : isFinalLine && cellLines.length === 1 ? `p_loop_${tblRef.tableId}_r${rIdx}_${cloneIdx}_c${cIdx}` : `p_loop_${tblRef.tableId}_r${rIdx}_${cloneIdx}_c${cIdx}_m${lineIdx}`;
|
|
25260
25809
|
builtParas.push({
|
|
25261
|
-
...tplPara ?
|
|
25810
|
+
...tplPara ? Tools12.deepClone(tplPara) : {},
|
|
25262
25811
|
paragraphId: deterministicParaId,
|
|
25263
25812
|
startIndex: pOffset
|
|
25264
25813
|
});
|
|
@@ -25267,7 +25816,7 @@ function expandDocTableRowLoopsInPlace(nextSnapshot, data, explicitLoops) {
|
|
|
25267
25816
|
builtStream += DataStreamTreeTokenType13.SECTION_BREAK;
|
|
25268
25817
|
const tplSec = templateCellSections[cIdx];
|
|
25269
25818
|
builtSections.push({
|
|
25270
|
-
...tplSec ?
|
|
25819
|
+
...tplSec ? Tools12.deepClone(tplSec) : {},
|
|
25271
25820
|
sectionId: cloneIdx === 0 && tplSec?.sectionId ? tplSec.sectionId : `s_loop_${tblRef.tableId}_r${rIdx}_${cloneIdx}_c${cIdx}`,
|
|
25272
25821
|
startIndex: sOffset
|
|
25273
25822
|
});
|
|
@@ -25346,7 +25895,7 @@ function expandDocTableRowLoopsInPlace(nextSnapshot, data, explicitLoops) {
|
|
|
25346
25895
|
if (tblSource?.tableRows?.[rIdx]) {
|
|
25347
25896
|
const tplRow = tblSource.tableRows[rIdx];
|
|
25348
25897
|
const clonedRowDefs = effectiveRows.map((_, cloneIdx) => {
|
|
25349
|
-
const cloned =
|
|
25898
|
+
const cloned = Tools12.deepClone(tplRow);
|
|
25350
25899
|
cloned.isFirstRow = rIdx === 0 && cloneIdx === 0 ? BooleanNumber5.TRUE : BooleanNumber5.FALSE;
|
|
25351
25900
|
cloned.repeatHeaderRow = BooleanNumber5.FALSE;
|
|
25352
25901
|
return cloned;
|
|
@@ -25389,7 +25938,7 @@ function expandDocTableRowLoopsInPlace(nextSnapshot, data, explicitLoops) {
|
|
|
25389
25938
|
}
|
|
25390
25939
|
for (let cloneIdx = 0; cloneIdx < effectiveRows.length; cloneIdx++) {
|
|
25391
25940
|
for (const { colPart, prop } of tplRowCellProps) {
|
|
25392
|
-
shiftedCellProps[`${tblPrefix}${rIdx + cloneIdx}:${colPart}`] =
|
|
25941
|
+
shiftedCellProps[`${tblPrefix}${rIdx + cloneIdx}:${colPart}`] = Tools12.deepClone(prop);
|
|
25393
25942
|
}
|
|
25394
25943
|
}
|
|
25395
25944
|
snapMeta.tableCellProperties = shiftedCellProps;
|
|
@@ -25500,7 +26049,7 @@ function evaluateVisibleIfCondition(expr, data) {
|
|
|
25500
26049
|
return Boolean(v && v !== "false" && v !== "0");
|
|
25501
26050
|
}
|
|
25502
26051
|
function fillDatasetIntoDocSnapshot(snapshot, data, options) {
|
|
25503
|
-
const nextSnapshot =
|
|
26052
|
+
const nextSnapshot = Tools12.deepClone(snapshot);
|
|
25504
26053
|
if (!nextSnapshot.body) return nextSnapshot;
|
|
25505
26054
|
const cleanFilledChrome = options?.cleanFilledChrome !== false;
|
|
25506
26055
|
expandDocTableRowLoopsInPlace(nextSnapshot, data, options?.tableRowLoops);
|
|
@@ -25659,7 +26208,7 @@ function fillDatasetIntoDocSnapshot(snapshot, data, options) {
|
|
|
25659
26208
|
expandedLines.forEach((line, k) => {
|
|
25660
26209
|
const crPos = cursor + line.length;
|
|
25661
26210
|
newParaEntries.push({
|
|
25662
|
-
...
|
|
26211
|
+
...Tools12.deepClone(templatePara),
|
|
25663
26212
|
paragraphId: k === 0 ? templatePara.paragraphId : `${templatePara.paragraphId || `p_${matchedParaIdx}`}_loop_${k}`,
|
|
25664
26213
|
startIndex: crPos
|
|
25665
26214
|
});
|
|
@@ -25670,20 +26219,29 @@ function fillDatasetIntoDocSnapshot(snapshot, data, options) {
|
|
|
25670
26219
|
}
|
|
25671
26220
|
const dynamicBodySpans = [];
|
|
25672
26221
|
const replaceInlineTokensInBody = (targetBody, trackSpans = false) => {
|
|
25673
|
-
|
|
26222
|
+
const protectedRepeatingRanges = (targetBody.customRanges ?? []).filter(
|
|
26223
|
+
(r) => r.rangeType === CustomRangeType11.SDT && (r.properties?.yudaoKind === "repeatingSection" || r.properties?.kind === "repeatingSection")
|
|
26224
|
+
);
|
|
26225
|
+
const tokenRe = new RegExp(INLINE_VALUE_TOKEN_RE.source, INLINE_VALUE_TOKEN_RE.flags);
|
|
25674
26226
|
let match;
|
|
25675
26227
|
const replacements = [];
|
|
25676
|
-
while ((match =
|
|
26228
|
+
while ((match = tokenRe.exec(targetBody.dataStream)) !== null) {
|
|
25677
26229
|
const expr = match[1];
|
|
25678
26230
|
if (expr.startsWith("#")) continue;
|
|
25679
|
-
const
|
|
25680
|
-
|
|
25681
|
-
|
|
25682
|
-
|
|
25683
|
-
|
|
25684
|
-
|
|
25685
|
-
});
|
|
26231
|
+
const matchStart = match.index;
|
|
26232
|
+
const matchEndInclusive = match.index + match[0].length - 1;
|
|
26233
|
+
if (protectedRepeatingRanges.some(
|
|
26234
|
+
(r) => matchStart >= r.startIndex && matchEndInclusive <= r.endIndex
|
|
26235
|
+
)) {
|
|
26236
|
+
continue;
|
|
25686
26237
|
}
|
|
26238
|
+
const val = resolvePathValue(data, expr);
|
|
26239
|
+
const resolvedText = val !== void 0 && val !== null && typeof val !== "object" ? String(val) : "";
|
|
26240
|
+
replacements.push({
|
|
26241
|
+
start: matchStart,
|
|
26242
|
+
endInclusive: matchEndInclusive,
|
|
26243
|
+
text: resolvedText
|
|
26244
|
+
});
|
|
25687
26245
|
}
|
|
25688
26246
|
let updated = targetBody;
|
|
25689
26247
|
for (let i = replacements.length - 1; i >= 0; i--) {
|
|
@@ -25825,7 +26383,7 @@ function buildStructuredDocData(params) {
|
|
|
25825
26383
|
textRuns.push({
|
|
25826
26384
|
st,
|
|
25827
26385
|
ed,
|
|
25828
|
-
ts:
|
|
26386
|
+
ts: Tools12.deepClone(seg.docField.style)
|
|
25829
26387
|
});
|
|
25830
26388
|
}
|
|
25831
26389
|
} else {
|
|
@@ -25842,7 +26400,9 @@ function buildStructuredDocData(params) {
|
|
|
25842
26400
|
endIndex: ed - 1,
|
|
25843
26401
|
properties: {
|
|
25844
26402
|
yudaoBlockKind: "docField",
|
|
25845
|
-
|
|
26403
|
+
fieldInstr: entry.instrText,
|
|
26404
|
+
...seg.docField.sourceKind ? { fieldSimple: seg.docField.sourceKind === "simple" } : {},
|
|
26405
|
+
field: Tools12.deepClone(entry)
|
|
25846
26406
|
}
|
|
25847
26407
|
});
|
|
25848
26408
|
builtDocFields[fldId] = entry;
|
|
@@ -25900,7 +26460,7 @@ function buildStructuredDocData(params) {
|
|
|
25900
26460
|
initials: seg.commentStart.initials || computeAuthorInitials(author),
|
|
25901
26461
|
content: seg.commentStart.content ?? "",
|
|
25902
26462
|
resolved: Boolean(seg.commentStart.resolved),
|
|
25903
|
-
replies: seg.commentStart.replies ?
|
|
26463
|
+
replies: seg.commentStart.replies ? Tools12.deepClone(seg.commentStart.replies) : [],
|
|
25904
26464
|
startOffset: dataStream.length
|
|
25905
26465
|
});
|
|
25906
26466
|
} else if ("commentEnd" in seg) {
|
|
@@ -25923,7 +26483,7 @@ function buildStructuredDocData(params) {
|
|
|
25923
26483
|
initials: opened.initials,
|
|
25924
26484
|
content: opened.content,
|
|
25925
26485
|
resolved: opened.resolved,
|
|
25926
|
-
replies:
|
|
26486
|
+
replies: Tools12.deepClone(opened.replies)
|
|
25927
26487
|
}
|
|
25928
26488
|
});
|
|
25929
26489
|
builtComments.push({
|
|
@@ -25936,7 +26496,7 @@ function buildStructuredDocData(params) {
|
|
|
25936
26496
|
resolved: opened.resolved,
|
|
25937
26497
|
startIndex: startIdx,
|
|
25938
26498
|
endIndex: endIdx,
|
|
25939
|
-
replies:
|
|
26499
|
+
replies: Tools12.deepClone(opened.replies)
|
|
25940
26500
|
});
|
|
25941
26501
|
}
|
|
25942
26502
|
} else if ("bookmarkStart" in seg) {
|
|
@@ -26122,7 +26682,7 @@ function buildStructuredDocData(params) {
|
|
|
26122
26682
|
endIndex: pIdx - 1,
|
|
26123
26683
|
properties: {
|
|
26124
26684
|
yudaoBlockKind: "callout",
|
|
26125
|
-
callout:
|
|
26685
|
+
callout: Tools12.deepClone(cBlock)
|
|
26126
26686
|
}
|
|
26127
26687
|
});
|
|
26128
26688
|
builtCallouts.push(cBlock);
|
|
@@ -26139,7 +26699,7 @@ function buildStructuredDocData(params) {
|
|
|
26139
26699
|
endIndex: pIdx - 1,
|
|
26140
26700
|
properties: {
|
|
26141
26701
|
yudaoBlockKind: "quote",
|
|
26142
|
-
quote:
|
|
26702
|
+
quote: Tools12.deepClone(qBlock)
|
|
26143
26703
|
}
|
|
26144
26704
|
});
|
|
26145
26705
|
builtQuotes.push(qBlock);
|
|
@@ -26206,12 +26766,12 @@ function buildStructuredDocData(params) {
|
|
|
26206
26766
|
if (cellObj.borders && !block.fromDocxImport) {
|
|
26207
26767
|
builtTableCellProps[`${tableId}:${rIdx}:${cIdx}`] = {
|
|
26208
26768
|
...builtTableCellProps[`${tableId}:${rIdx}:${cIdx}`] ?? {},
|
|
26209
|
-
borders:
|
|
26769
|
+
borders: Tools12.deepClone(cellObj.borders)
|
|
26210
26770
|
};
|
|
26211
26771
|
} else if (cellObj.explicitBorders && Object.keys(cellObj.explicitBorders).length > 0) {
|
|
26212
26772
|
builtTableCellProps[`${tableId}:${rIdx}:${cIdx}`] = {
|
|
26213
26773
|
...builtTableCellProps[`${tableId}:${rIdx}:${cIdx}`] ?? {},
|
|
26214
|
-
borders:
|
|
26774
|
+
borders: Tools12.deepClone(cellObj.explicitBorders)
|
|
26215
26775
|
};
|
|
26216
26776
|
}
|
|
26217
26777
|
const resolvedCellMarginPt = cellObj.marginPt ?? block.tableCellMarginPt;
|
|
@@ -26233,7 +26793,7 @@ function buildStructuredDocData(params) {
|
|
|
26233
26793
|
columnSpan: cellObj.colSpan ?? 1,
|
|
26234
26794
|
...cellObj.vAlign !== void 0 ? { vAlign: cellObj.vAlign } : {},
|
|
26235
26795
|
...cellObj.tcWidthType ? { tcWidthType: cellObj.tcWidthType } : {},
|
|
26236
|
-
...cellObj.cellSize ? { size:
|
|
26796
|
+
...cellObj.cellSize ? { size: Tools12.deepClone(cellObj.cellSize) } : {},
|
|
26237
26797
|
...cellObj.yudaoTcWidthPct !== void 0 ? { yudaoTcWidthPct: cellObj.yudaoTcWidthPct } : {},
|
|
26238
26798
|
...cellObj.backgroundRgb ? { backgroundColor: { rgb: cellObj.backgroundRgb } } : {},
|
|
26239
26799
|
...block.fromDocxImport ? {
|
|
@@ -26265,7 +26825,7 @@ function buildStructuredDocData(params) {
|
|
|
26265
26825
|
bottom: { v: rMeta.cellMarginPt.bottom, u: NumberUnitType6.POINT }
|
|
26266
26826
|
}
|
|
26267
26827
|
} : {},
|
|
26268
|
-
trHeight: rMeta?.trHeight ?
|
|
26828
|
+
trHeight: rMeta?.trHeight ? Tools12.deepClone(rMeta.trHeight) : {
|
|
26269
26829
|
val: { v: 24, u: NumberUnitType6.POINT },
|
|
26270
26830
|
hRule: TableRowHeightRule4.AT_LEAST
|
|
26271
26831
|
},
|
|
@@ -26295,7 +26855,7 @@ function buildStructuredDocData(params) {
|
|
|
26295
26855
|
positionV: { relativeFrom: 0, posOffset: 0 }
|
|
26296
26856
|
},
|
|
26297
26857
|
dist: { distT: 0, distB: 0, distL: 0, distR: 0 },
|
|
26298
|
-
size: block.tableSize ?
|
|
26858
|
+
size: block.tableSize ? Tools12.deepClone(block.tableSize) : {
|
|
26299
26859
|
width: {
|
|
26300
26860
|
v: colWidths.reduce((a, b) => a + b, 0),
|
|
26301
26861
|
u: NumberUnitType6.POINT
|
|
@@ -26311,7 +26871,7 @@ function buildStructuredDocData(params) {
|
|
|
26311
26871
|
bottom: { v: block.tableCellMarginPt.bottom, u: NumberUnitType6.POINT }
|
|
26312
26872
|
}
|
|
26313
26873
|
} : {},
|
|
26314
|
-
...block.tableBorderDefaults ? { borderDefaults:
|
|
26874
|
+
...block.tableBorderDefaults ? { borderDefaults: Tools12.deepClone(block.tableBorderDefaults) } : {},
|
|
26315
26875
|
...block.tableLayout !== void 0 ? { layout: block.tableLayout } : {},
|
|
26316
26876
|
...block.yudaoTblWidthType ? { yudaoTblWidthType: block.yudaoTblWidthType } : {},
|
|
26317
26877
|
...block.yudaoTblWidthDxa !== void 0 ? { yudaoTblWidthDxa: block.yudaoTblWidthDxa } : {},
|
|
@@ -26705,7 +27265,7 @@ function evaluateDocTableFormulasInPlace(snapshot) {
|
|
|
26705
27265
|
return mutated;
|
|
26706
27266
|
}
|
|
26707
27267
|
function evaluateDocTableFormulas(snapshot) {
|
|
26708
|
-
const cloned =
|
|
27268
|
+
const cloned = Tools12.deepClone(snapshot);
|
|
26709
27269
|
evaluateDocTableFormulasInPlace(cloned);
|
|
26710
27270
|
return cloned;
|
|
26711
27271
|
}
|
|
@@ -26720,7 +27280,7 @@ var DOC_TRACK_DELETE_STYLE = {
|
|
|
26720
27280
|
bg: { rgb: "#ffe4e6" }
|
|
26721
27281
|
};
|
|
26722
27282
|
function applyTextStyleToBodySpan(sourceBody, start, endExclusive, nextStyle) {
|
|
26723
|
-
const body =
|
|
27283
|
+
const body = Tools12.deepClone(sourceBody);
|
|
26724
27284
|
if (endExclusive <= start) return body;
|
|
26725
27285
|
const updatedRuns = [];
|
|
26726
27286
|
for (const run of body.textRuns ?? []) {
|
|
@@ -26745,7 +27305,7 @@ function applyTextStyleToBodySpan(sourceBody, start, endExclusive, nextStyle) {
|
|
|
26745
27305
|
updatedRuns.push({
|
|
26746
27306
|
st: start,
|
|
26747
27307
|
ed: endExclusive,
|
|
26748
|
-
ts:
|
|
27308
|
+
ts: Tools12.deepClone(nextStyle)
|
|
26749
27309
|
});
|
|
26750
27310
|
}
|
|
26751
27311
|
updatedRuns.sort((a, b) => a.st - b.st || a.ed - b.ed);
|
|
@@ -26783,8 +27343,8 @@ function shiftTrackRevisions(revisions, start, removedLen, insertedLen, excludeR
|
|
|
26783
27343
|
});
|
|
26784
27344
|
}
|
|
26785
27345
|
function recordDocTrackRevisionOnSnapshot(snapshot, params, metadataOverride) {
|
|
26786
|
-
const nextSnapshot =
|
|
26787
|
-
const prevMeta =
|
|
27346
|
+
const nextSnapshot = Tools12.deepClone(snapshot);
|
|
27347
|
+
const prevMeta = Tools12.deepClone(metadataOverride ?? readDocTemplateMetadataFromSnapshot(nextSnapshot));
|
|
26788
27348
|
if (!nextSnapshot.body) {
|
|
26789
27349
|
return { snapshot: nextSnapshot, metadata: prevMeta, revision: null };
|
|
26790
27350
|
}
|
|
@@ -26880,8 +27440,8 @@ function recordDocTrackRevisionOnSnapshot(snapshot, params, metadataOverride) {
|
|
|
26880
27440
|
return { snapshot: nextSnapshot, metadata: nextMeta, revision: rev };
|
|
26881
27441
|
}
|
|
26882
27442
|
function resolveDocTrackRevisionOnSnapshot(snapshot, params, metadataOverride) {
|
|
26883
|
-
const nextSnapshot =
|
|
26884
|
-
const prevMeta =
|
|
27443
|
+
const nextSnapshot = Tools12.deepClone(snapshot);
|
|
27444
|
+
const prevMeta = Tools12.deepClone(metadataOverride ?? readDocTemplateMetadataFromSnapshot(nextSnapshot));
|
|
26885
27445
|
if (!nextSnapshot.body) {
|
|
26886
27446
|
return { snapshot: nextSnapshot, metadata: prevMeta, resolvedCount: 0 };
|
|
26887
27447
|
}
|
|
@@ -27173,7 +27733,7 @@ function buildLiveDocFormContext(snapshot, extraData) {
|
|
|
27173
27733
|
const controls = listDocSdtControls(snapshot);
|
|
27174
27734
|
const displayMap = {};
|
|
27175
27735
|
const ctx = {
|
|
27176
|
-
...extraData ?
|
|
27736
|
+
...extraData ? Tools12.deepClone(extraData) : {}
|
|
27177
27737
|
};
|
|
27178
27738
|
const assignDotted = (target, path, val) => {
|
|
27179
27739
|
target[path] = val;
|
|
@@ -27291,7 +27851,7 @@ function evaluateComputedSdtControlsInPlace(snapshot, extraData, cleanFilledChro
|
|
|
27291
27851
|
return anyMutated;
|
|
27292
27852
|
}
|
|
27293
27853
|
function evaluateComputedSdtControls(snapshot, extraData) {
|
|
27294
|
-
const cloned =
|
|
27854
|
+
const cloned = Tools12.deepClone(snapshot);
|
|
27295
27855
|
evaluateComputedSdtControlsInPlace(cloned, extraData);
|
|
27296
27856
|
return cloned;
|
|
27297
27857
|
}
|
|
@@ -27303,7 +27863,7 @@ function toControlSpecSnapshot(ctrl) {
|
|
|
27303
27863
|
tag: ctrl.tag,
|
|
27304
27864
|
...ctrl.conceptId ? { conceptId: ctrl.conceptId } : {},
|
|
27305
27865
|
...ctrl.deletable !== void 0 ? { deletable: ctrl.deletable } : {},
|
|
27306
|
-
...ctrl.cascaderOptions?.length ? { cascaderOptions:
|
|
27866
|
+
...ctrl.cascaderOptions?.length ? { cascaderOptions: Tools12.deepClone(ctrl.cascaderOptions) } : {},
|
|
27307
27867
|
...ctrl.cascaderSeparator !== void 0 ? { cascaderSeparator: ctrl.cascaderSeparator } : {},
|
|
27308
27868
|
placeholder: ctrl.placeholder,
|
|
27309
27869
|
bindingPath: ctrl.bindingPath,
|
|
@@ -27311,11 +27871,11 @@ function toControlSpecSnapshot(ctrl) {
|
|
|
27311
27871
|
lock: ctrl.lock,
|
|
27312
27872
|
checked: ctrl.checked,
|
|
27313
27873
|
dateFormat: ctrl.dateFormat,
|
|
27314
|
-
listItems: ctrl.listItems ?
|
|
27315
|
-
...ctrl.options ? { options:
|
|
27874
|
+
listItems: ctrl.listItems ? Tools12.deepClone(ctrl.listItems) : void 0,
|
|
27875
|
+
...ctrl.options ? { options: Tools12.deepClone(ctrl.options) } : {},
|
|
27316
27876
|
...ctrl.checkboxMarkType ? { checkboxMarkType: ctrl.checkboxMarkType } : {},
|
|
27317
27877
|
...ctrl.layoutDirection ? { layoutDirection: ctrl.layoutDirection } : {},
|
|
27318
|
-
highlightRules: ctrl.highlightRules ?
|
|
27878
|
+
highlightRules: ctrl.highlightRules ? Tools12.deepClone(ctrl.highlightRules) : void 0,
|
|
27319
27879
|
visibleIf: ctrl.visibleIf,
|
|
27320
27880
|
computedExpr: ctrl.computedExpr,
|
|
27321
27881
|
min: ctrl.min,
|
|
@@ -27349,8 +27909,8 @@ function toControlSpecSnapshot(ctrl) {
|
|
|
27349
27909
|
};
|
|
27350
27910
|
}
|
|
27351
27911
|
function evaluateLiveVisibilityClauses(snapshot, metadataOverride) {
|
|
27352
|
-
const nextSnapshot =
|
|
27353
|
-
const meta =
|
|
27912
|
+
const nextSnapshot = Tools12.deepClone(snapshot);
|
|
27913
|
+
const meta = Tools12.deepClone(metadataOverride ?? readDocTemplateMetadataFromSnapshot(nextSnapshot));
|
|
27354
27914
|
if (!nextSnapshot.body) {
|
|
27355
27915
|
return { snapshot: nextSnapshot, metadata: meta, changed: false };
|
|
27356
27916
|
}
|
|
@@ -27628,6 +28188,89 @@ function diffDocSnapshots(beforeSnapshot, afterSnapshot) {
|
|
|
27628
28188
|
removedLength
|
|
27629
28189
|
};
|
|
27630
28190
|
}
|
|
28191
|
+
function summarizeDocTemplate(snapshot) {
|
|
28192
|
+
const bindings = [];
|
|
28193
|
+
const datasetCodeSet = /* @__PURE__ */ new Set();
|
|
28194
|
+
let sdtCount = 0;
|
|
28195
|
+
let placeholderCount = 0;
|
|
28196
|
+
let hasDynamicPageFields = false;
|
|
28197
|
+
const scanStory = (storyBody, scope, segmentId) => {
|
|
28198
|
+
if (!storyBody) return;
|
|
28199
|
+
const customRanges = storyBody.customRanges ?? [];
|
|
28200
|
+
for (const r of customRanges) {
|
|
28201
|
+
const fldInstr = extractDocFieldInstruction(r);
|
|
28202
|
+
if (fldInstr && isDynamicPageFieldInstruction(fldInstr)) {
|
|
28203
|
+
hasDynamicPageFields = true;
|
|
28204
|
+
}
|
|
28205
|
+
if (r.rangeType !== CustomRangeType11.SDT) continue;
|
|
28206
|
+
const resolved = parseSdtRangeToResolved(storyBody, r, segmentId);
|
|
28207
|
+
if (!resolved) continue;
|
|
28208
|
+
sdtCount++;
|
|
28209
|
+
if (resolved.kind === "group" && !resolved.bindingPath) continue;
|
|
28210
|
+
const rawKey = (resolved.bindingPath || resolved.tag || "").trim();
|
|
28211
|
+
if (!rawKey) continue;
|
|
28212
|
+
const parsed = parseDocBindingKey(rawKey);
|
|
28213
|
+
if (parsed.datasetCode) {
|
|
28214
|
+
datasetCodeSet.add(parsed.datasetCode);
|
|
28215
|
+
}
|
|
28216
|
+
bindings.push({
|
|
28217
|
+
source: "sdt",
|
|
28218
|
+
scope,
|
|
28219
|
+
...segmentId ? { segmentId } : {},
|
|
28220
|
+
rawKey: parsed.rawKey,
|
|
28221
|
+
...parsed.datasetCode ? { datasetCode: parsed.datasetCode } : {},
|
|
28222
|
+
fieldPath: parsed.fieldPath,
|
|
28223
|
+
controlId: resolved.id,
|
|
28224
|
+
controlType: resolved.kind
|
|
28225
|
+
});
|
|
28226
|
+
}
|
|
28227
|
+
const placeholders = extractDocInlinePlaceholders(storyBody.dataStream ?? "", "both");
|
|
28228
|
+
for (const ph of placeholders) {
|
|
28229
|
+
placeholderCount++;
|
|
28230
|
+
if (ph.datasetCode) {
|
|
28231
|
+
datasetCodeSet.add(ph.datasetCode);
|
|
28232
|
+
}
|
|
28233
|
+
bindings.push({
|
|
28234
|
+
source: "placeholder",
|
|
28235
|
+
scope,
|
|
28236
|
+
...segmentId ? { segmentId } : {},
|
|
28237
|
+
rawKey: ph.rawKey,
|
|
28238
|
+
...ph.datasetCode ? { datasetCode: ph.datasetCode } : {},
|
|
28239
|
+
fieldPath: ph.fieldPath
|
|
28240
|
+
});
|
|
28241
|
+
}
|
|
28242
|
+
};
|
|
28243
|
+
scanStory(snapshot?.body, "body");
|
|
28244
|
+
for (const [segId, hdr] of Object.entries(snapshot?.headers ?? {})) {
|
|
28245
|
+
scanStory(hdr?.body, "header", segId);
|
|
28246
|
+
}
|
|
28247
|
+
for (const [segId, ftr] of Object.entries(snapshot?.footers ?? {})) {
|
|
28248
|
+
scanStory(ftr?.body, "footer", segId);
|
|
28249
|
+
}
|
|
28250
|
+
const meta = readDocTemplateMetadataFromSnapshot(snapshot);
|
|
28251
|
+
const tableRowLoops = Object.values(meta.tableRowLoops ?? {}).map(
|
|
28252
|
+
(cfg) => Tools12.deepClone(cfg)
|
|
28253
|
+
);
|
|
28254
|
+
for (const loop of tableRowLoops) {
|
|
28255
|
+
if (loop.listKey?.trim()) {
|
|
28256
|
+
const parsedLoop = parseDocBindingKey(loop.listKey);
|
|
28257
|
+
const code = parsedLoop.datasetCode || parsedLoop.fieldPath;
|
|
28258
|
+
if (code) datasetCodeSet.add(code);
|
|
28259
|
+
}
|
|
28260
|
+
}
|
|
28261
|
+
const metadataKeys = Object.keys(meta).filter(
|
|
28262
|
+
(k) => meta[k] !== void 0
|
|
28263
|
+
);
|
|
28264
|
+
return {
|
|
28265
|
+
datasetCodes: Array.from(datasetCodeSet),
|
|
28266
|
+
bindings,
|
|
28267
|
+
tableRowLoops,
|
|
28268
|
+
metadataKeys,
|
|
28269
|
+
sdtCount,
|
|
28270
|
+
placeholderCount,
|
|
28271
|
+
hasDynamicPageFields
|
|
28272
|
+
};
|
|
28273
|
+
}
|
|
27631
28274
|
|
|
27632
28275
|
// src/services/doc-sdt.service.ts
|
|
27633
28276
|
var IDocSdtService = createIdentifier2("yudao.univer-docs.sdt.service");
|
|
@@ -27831,7 +28474,7 @@ var DocSdtService = class extends Disposable2 {
|
|
|
27831
28474
|
saveVersionSnapshot(unitId, label) {
|
|
27832
28475
|
const docModel = this._getDocModel(unitId);
|
|
27833
28476
|
if (!docModel) return null;
|
|
27834
|
-
const snap =
|
|
28477
|
+
const snap = Tools13.deepClone(docModel.getSnapshot());
|
|
27835
28478
|
const list = [...this._versionsByUnit.get(unitId) ?? []];
|
|
27836
28479
|
const ctrlCount = listDocSdtControls(snap).length;
|
|
27837
28480
|
const tblCount = snap.body?.tables?.length ?? 0;
|
|
@@ -27857,7 +28500,7 @@ var DocSdtService = class extends Disposable2 {
|
|
|
27857
28500
|
saveBuildingBlock(unitId, spec) {
|
|
27858
28501
|
const id = spec.id?.trim() || `bb_${generateRandomId12(6)}`;
|
|
27859
28502
|
const entry = {
|
|
27860
|
-
...
|
|
28503
|
+
...Tools13.deepClone(spec),
|
|
27861
28504
|
id,
|
|
27862
28505
|
name: spec.name.trim() || "\u672A\u547D\u540D\u6784\u5EFA\u5757",
|
|
27863
28506
|
category: spec.category.trim() || "\u901A\u7528\u6761\u6B3E",
|
|
@@ -27877,12 +28520,12 @@ var DocSdtService = class extends Disposable2 {
|
|
|
27877
28520
|
getBuildingBlocks(unitId) {
|
|
27878
28521
|
const merged = /* @__PURE__ */ new Map();
|
|
27879
28522
|
for (const [id, blk] of this._buildingBlocks.entries()) {
|
|
27880
|
-
merged.set(id,
|
|
28523
|
+
merged.set(id, Tools13.deepClone(blk));
|
|
27881
28524
|
}
|
|
27882
28525
|
const resolvedUnit = unitId || this._getDocModel()?.getUnitId();
|
|
27883
28526
|
if (resolvedUnit) {
|
|
27884
28527
|
for (const blk of this.getTemplateMetadata(resolvedUnit).buildingBlocks ?? []) {
|
|
27885
|
-
merged.set(blk.id,
|
|
28528
|
+
merged.set(blk.id, Tools13.deepClone(blk));
|
|
27886
28529
|
}
|
|
27887
28530
|
}
|
|
27888
28531
|
return Array.from(merged.values());
|
|
@@ -27918,7 +28561,7 @@ import {
|
|
|
27918
28561
|
IUndoRedoService as IUndoRedoService2,
|
|
27919
28562
|
JSONX,
|
|
27920
28563
|
RedoCommand,
|
|
27921
|
-
Tools as
|
|
28564
|
+
Tools as Tools15,
|
|
27922
28565
|
UndoCommand
|
|
27923
28566
|
} from "@univerjs/core";
|
|
27924
28567
|
import { RichTextEditingMutation } from "@univerjs/docs";
|
|
@@ -27929,7 +28572,7 @@ import {
|
|
|
27929
28572
|
generateRandomId as generateRandomId13,
|
|
27930
28573
|
ICommandService as ICommandService2,
|
|
27931
28574
|
IUndoRedoService,
|
|
27932
|
-
Tools as
|
|
28575
|
+
Tools as Tools14
|
|
27933
28576
|
} from "@univerjs/core";
|
|
27934
28577
|
var SyncDocAuxStateMutation = {
|
|
27935
28578
|
id: "yudao-docs.mutation.sync-aux-state",
|
|
@@ -27939,28 +28582,28 @@ var SyncDocAuxStateMutation = {
|
|
|
27939
28582
|
if (!docModel) return false;
|
|
27940
28583
|
const snap = docModel.getSnapshot();
|
|
27941
28584
|
if (params.tableSource !== void 0) {
|
|
27942
|
-
snap.tableSource =
|
|
28585
|
+
snap.tableSource = Tools14.deepClone(params.tableSource);
|
|
27943
28586
|
}
|
|
27944
28587
|
if (params.drawings !== void 0) {
|
|
27945
|
-
snap.drawings =
|
|
28588
|
+
snap.drawings = Tools14.deepClone(params.drawings);
|
|
27946
28589
|
}
|
|
27947
28590
|
if (params.drawingsOrder !== void 0) {
|
|
27948
|
-
snap.drawingsOrder =
|
|
28591
|
+
snap.drawingsOrder = Tools14.deepClone(params.drawingsOrder);
|
|
27949
28592
|
}
|
|
27950
28593
|
if (params.documentStyle !== void 0) {
|
|
27951
|
-
snap.documentStyle =
|
|
28594
|
+
snap.documentStyle = Tools14.deepClone(params.documentStyle);
|
|
27952
28595
|
}
|
|
27953
28596
|
if (params.headers !== void 0) {
|
|
27954
|
-
snap.headers =
|
|
28597
|
+
snap.headers = Tools14.deepClone(params.headers);
|
|
27955
28598
|
}
|
|
27956
28599
|
if (params.footers !== void 0) {
|
|
27957
|
-
snap.footers =
|
|
28600
|
+
snap.footers = Tools14.deepClone(params.footers);
|
|
27958
28601
|
}
|
|
27959
28602
|
if (params.headers !== void 0 || params.footers !== void 0) {
|
|
27960
28603
|
reinitializeDocHeaderFooterModels(docModel);
|
|
27961
28604
|
}
|
|
27962
28605
|
if (params.metadata !== void 0) {
|
|
27963
|
-
const nextMeta =
|
|
28606
|
+
const nextMeta = Tools14.deepClone(params.metadata);
|
|
27964
28607
|
accessor.get(IDocSdtService).setTemplateMetadata(docModel.getUnitId(), nextMeta);
|
|
27965
28608
|
writeDocTemplateMetadataToSnapshot(snap, nextMeta);
|
|
27966
28609
|
}
|
|
@@ -27982,7 +28625,7 @@ var InsertDocCalloutCommand = {
|
|
|
27982
28625
|
const sdtService = accessor.get(IDocSdtService);
|
|
27983
28626
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
27984
28627
|
const offset = resolveActiveInsertOffset(accessor, prevBody, params.offset);
|
|
27985
|
-
const workingSnap =
|
|
28628
|
+
const workingSnap = Tools14.deepClone(docModel.getSnapshot());
|
|
27986
28629
|
writeDocTemplateMetadataToSnapshot(workingSnap, sdtService.getTemplateMetadata(unitId));
|
|
27987
28630
|
const inserted = insertCalloutIntoSnapshot(workingSnap, params.spec, offset);
|
|
27988
28631
|
const nextMeta = readDocTemplateMetadataFromSnapshot(inserted.snapshot);
|
|
@@ -28006,7 +28649,7 @@ var UpdateDocCalloutCommand = {
|
|
|
28006
28649
|
const unitId = docModel.getUnitId();
|
|
28007
28650
|
const sdtService = accessor.get(IDocSdtService);
|
|
28008
28651
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28009
|
-
const workingSnap =
|
|
28652
|
+
const workingSnap = Tools14.deepClone(docModel.getSnapshot());
|
|
28010
28653
|
writeDocTemplateMetadataToSnapshot(workingSnap, sdtService.getTemplateMetadata(unitId));
|
|
28011
28654
|
const outcome = updateCalloutInSnapshot(workingSnap, params.id, params.patch);
|
|
28012
28655
|
if (!outcome) return false;
|
|
@@ -28030,7 +28673,7 @@ var RemoveDocCalloutCommand = {
|
|
|
28030
28673
|
const unitId = docModel.getUnitId();
|
|
28031
28674
|
const sdtService = accessor.get(IDocSdtService);
|
|
28032
28675
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28033
|
-
const workingSnap =
|
|
28676
|
+
const workingSnap = Tools14.deepClone(docModel.getSnapshot());
|
|
28034
28677
|
writeDocTemplateMetadataToSnapshot(workingSnap, sdtService.getTemplateMetadata(unitId));
|
|
28035
28678
|
const removed = removeCalloutFromSnapshot(workingSnap, params.id);
|
|
28036
28679
|
if (!removed) return false;
|
|
@@ -28050,7 +28693,7 @@ var InsertDocQuoteCommand = {
|
|
|
28050
28693
|
const sdtService = accessor.get(IDocSdtService);
|
|
28051
28694
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28052
28695
|
const offset = resolveActiveInsertOffset(accessor, prevBody, params.offset);
|
|
28053
|
-
const workingSnap =
|
|
28696
|
+
const workingSnap = Tools14.deepClone(docModel.getSnapshot());
|
|
28054
28697
|
writeDocTemplateMetadataToSnapshot(workingSnap, sdtService.getTemplateMetadata(unitId));
|
|
28055
28698
|
const inserted = insertQuoteIntoSnapshot(workingSnap, params.spec, offset);
|
|
28056
28699
|
sdtService.setTemplateMetadata(unitId, readDocTemplateMetadataFromSnapshot(inserted.snapshot));
|
|
@@ -28073,7 +28716,7 @@ var UpdateDocQuoteCommand = {
|
|
|
28073
28716
|
const unitId = docModel.getUnitId();
|
|
28074
28717
|
const sdtService = accessor.get(IDocSdtService);
|
|
28075
28718
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28076
|
-
const workingSnap =
|
|
28719
|
+
const workingSnap = Tools14.deepClone(docModel.getSnapshot());
|
|
28077
28720
|
writeDocTemplateMetadataToSnapshot(workingSnap, sdtService.getTemplateMetadata(unitId));
|
|
28078
28721
|
const outcome = updateQuoteInSnapshot(workingSnap, params.id, params.patch);
|
|
28079
28722
|
if (!outcome) return false;
|
|
@@ -28097,7 +28740,7 @@ var RemoveDocQuoteCommand = {
|
|
|
28097
28740
|
const unitId = docModel.getUnitId();
|
|
28098
28741
|
const sdtService = accessor.get(IDocSdtService);
|
|
28099
28742
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28100
|
-
const workingSnap =
|
|
28743
|
+
const workingSnap = Tools14.deepClone(docModel.getSnapshot());
|
|
28101
28744
|
writeDocTemplateMetadataToSnapshot(workingSnap, sdtService.getTemplateMetadata(unitId));
|
|
28102
28745
|
const removed = removeQuoteFromSnapshot(workingSnap, params.id);
|
|
28103
28746
|
if (!removed) return false;
|
|
@@ -28147,7 +28790,7 @@ var InsertDocLatexFormulaCommand = {
|
|
|
28147
28790
|
"latexFormula",
|
|
28148
28791
|
fullSpec
|
|
28149
28792
|
);
|
|
28150
|
-
const prevMeta =
|
|
28793
|
+
const prevMeta = Tools14.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
28151
28794
|
if (prevMeta.revisions?.length) {
|
|
28152
28795
|
prevMeta.revisions = shiftTrackRevisions(prevMeta.revisions, inserted.insertOffset, 0, 1);
|
|
28153
28796
|
}
|
|
@@ -28181,7 +28824,7 @@ var UpdateDocLatexFormulaCommand = {
|
|
|
28181
28824
|
const unitId = docModel.getUnitId();
|
|
28182
28825
|
const sdtService = accessor.get(IDocSdtService);
|
|
28183
28826
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28184
|
-
const prevMeta =
|
|
28827
|
+
const prevMeta = Tools14.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
28185
28828
|
const existing = prevMeta.latexFormulas?.[params.id];
|
|
28186
28829
|
const blk = (prevBody.customBlocks ?? []).find((b) => b.blockId === params.id);
|
|
28187
28830
|
if (!existing && !blk) return false;
|
|
@@ -28211,7 +28854,7 @@ var UpdateDocLatexFormulaCommand = {
|
|
|
28211
28854
|
size: { width: rendered.widthPt, height: rendered.heightPt }
|
|
28212
28855
|
};
|
|
28213
28856
|
}
|
|
28214
|
-
const nextBody =
|
|
28857
|
+
const nextBody = Tools14.deepClone(prevBody);
|
|
28215
28858
|
if (blk) {
|
|
28216
28859
|
attachDrawingMetaRangeOnBody(nextBody, params.id, blk.startIndex, "latexFormula", merged);
|
|
28217
28860
|
}
|
|
@@ -28239,7 +28882,7 @@ var RemoveDocLatexFormulaCommand = {
|
|
|
28239
28882
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28240
28883
|
const nextBody = removeInlineDrawingBlockFromBody(prevBody, params.id);
|
|
28241
28884
|
if (!nextBody) return false;
|
|
28242
|
-
const prevMeta =
|
|
28885
|
+
const prevMeta = Tools14.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
28243
28886
|
const nextMap = { ...prevMeta.latexFormulas ?? {} };
|
|
28244
28887
|
delete nextMap[params.id];
|
|
28245
28888
|
sdtService.setTemplateMetadata(unitId, {
|
|
@@ -28261,7 +28904,7 @@ var InsertDocInlineFormulaCommand = {
|
|
|
28261
28904
|
const sdtService = accessor.get(IDocSdtService);
|
|
28262
28905
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28263
28906
|
const offset = resolveActiveInsertOffset(accessor, prevBody, params.offset);
|
|
28264
|
-
const workingSnap =
|
|
28907
|
+
const workingSnap = Tools14.deepClone(docModel.getSnapshot());
|
|
28265
28908
|
writeDocTemplateMetadataToSnapshot(workingSnap, sdtService.getTemplateMetadata(unitId));
|
|
28266
28909
|
const inserted = insertInlineFormulaIntoSnapshot(workingSnap, params.spec, offset, params.extraVars);
|
|
28267
28910
|
sdtService.setTemplateMetadata(unitId, readDocTemplateMetadataFromSnapshot(inserted.snapshot));
|
|
@@ -28283,7 +28926,7 @@ var RecalculateDocInlineFormulasCommand = {
|
|
|
28283
28926
|
const unitId = docModel.getUnitId();
|
|
28284
28927
|
const sdtService = accessor.get(IDocSdtService);
|
|
28285
28928
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28286
|
-
const workingSnap =
|
|
28929
|
+
const workingSnap = Tools14.deepClone(docModel.getSnapshot());
|
|
28287
28930
|
writeDocTemplateMetadataToSnapshot(workingSnap, sdtService.getTemplateMetadata(unitId));
|
|
28288
28931
|
recalculateInlineFormulasInPlace(workingSnap, params?.extraVars);
|
|
28289
28932
|
sdtService.setTemplateMetadata(unitId, readDocTemplateMetadataFromSnapshot(workingSnap));
|
|
@@ -28309,7 +28952,7 @@ var InsertDocChartCommand = {
|
|
|
28309
28952
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28310
28953
|
const id = params.spec.id || `chart_${generateRandomId13(6)}`;
|
|
28311
28954
|
const fullSpec = {
|
|
28312
|
-
...
|
|
28955
|
+
...Tools14.deepClone(params.spec),
|
|
28313
28956
|
id
|
|
28314
28957
|
};
|
|
28315
28958
|
const rendered = renderDocChartToSvgDataUri(fullSpec);
|
|
@@ -28329,7 +28972,7 @@ var InsertDocChartCommand = {
|
|
|
28329
28972
|
"docChart",
|
|
28330
28973
|
fullSpec
|
|
28331
28974
|
);
|
|
28332
|
-
const prevMeta =
|
|
28975
|
+
const prevMeta = Tools14.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
28333
28976
|
const nextMeta = {
|
|
28334
28977
|
...prevMeta,
|
|
28335
28978
|
docCharts: {
|
|
@@ -28360,7 +29003,7 @@ var UpdateDocChartCommand = {
|
|
|
28360
29003
|
const unitId = docModel.getUnitId();
|
|
28361
29004
|
const sdtService = accessor.get(IDocSdtService);
|
|
28362
29005
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28363
|
-
const prevMeta =
|
|
29006
|
+
const prevMeta = Tools14.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
28364
29007
|
const existing = prevMeta.docCharts?.[params.id];
|
|
28365
29008
|
const blk = (prevBody.customBlocks ?? []).find((b) => b.blockId === params.id);
|
|
28366
29009
|
if (!existing && !blk) return false;
|
|
@@ -28372,7 +29015,7 @@ var UpdateDocChartCommand = {
|
|
|
28372
29015
|
categories: [],
|
|
28373
29016
|
series: []
|
|
28374
29017
|
},
|
|
28375
|
-
...
|
|
29018
|
+
...Tools14.deepClone(params.patch),
|
|
28376
29019
|
id: params.id
|
|
28377
29020
|
};
|
|
28378
29021
|
const rendered = renderDocChartToSvgDataUri(merged);
|
|
@@ -28386,7 +29029,7 @@ var UpdateDocChartCommand = {
|
|
|
28386
29029
|
size: { width: rendered.widthPt, height: rendered.heightPt }
|
|
28387
29030
|
};
|
|
28388
29031
|
}
|
|
28389
|
-
const nextBody =
|
|
29032
|
+
const nextBody = Tools14.deepClone(prevBody);
|
|
28390
29033
|
if (blk) {
|
|
28391
29034
|
attachDrawingMetaRangeOnBody(nextBody, params.id, blk.startIndex, "docChart", merged);
|
|
28392
29035
|
}
|
|
@@ -28414,7 +29057,7 @@ var RemoveDocChartCommand = {
|
|
|
28414
29057
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28415
29058
|
const nextBody = removeInlineDrawingBlockFromBody(prevBody, params.id);
|
|
28416
29059
|
if (!nextBody) return false;
|
|
28417
|
-
const prevMeta =
|
|
29060
|
+
const prevMeta = Tools14.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
28418
29061
|
const nextMap = { ...prevMeta.docCharts ?? {} };
|
|
28419
29062
|
delete nextMap[params.id];
|
|
28420
29063
|
sdtService.setTemplateMetadata(unitId, {
|
|
@@ -28438,7 +29081,7 @@ var InsertDocShapeCommand = {
|
|
|
28438
29081
|
const id = params.spec.id || `shape_${generateRandomId13(6)}`;
|
|
28439
29082
|
const resolvedKind = params.spec.shapeType ?? params.spec.kind ?? "roundRect";
|
|
28440
29083
|
const fullSpec = {
|
|
28441
|
-
...
|
|
29084
|
+
...Tools14.deepClone(params.spec),
|
|
28442
29085
|
id,
|
|
28443
29086
|
shapeType: resolvedKind,
|
|
28444
29087
|
kind: resolvedKind
|
|
@@ -28460,7 +29103,7 @@ var InsertDocShapeCommand = {
|
|
|
28460
29103
|
"docShape",
|
|
28461
29104
|
fullSpec
|
|
28462
29105
|
);
|
|
28463
|
-
const prevMeta =
|
|
29106
|
+
const prevMeta = Tools14.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
28464
29107
|
const nextMeta = {
|
|
28465
29108
|
...prevMeta,
|
|
28466
29109
|
docShapes: {
|
|
@@ -28491,14 +29134,14 @@ var UpdateDocShapeCommand = {
|
|
|
28491
29134
|
const unitId = docModel.getUnitId();
|
|
28492
29135
|
const sdtService = accessor.get(IDocSdtService);
|
|
28493
29136
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28494
|
-
const prevMeta =
|
|
29137
|
+
const prevMeta = Tools14.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
28495
29138
|
const existing = prevMeta.docShapes?.[params.id];
|
|
28496
29139
|
const blk = (prevBody.customBlocks ?? []).find((b) => b.blockId === params.id);
|
|
28497
29140
|
if (!existing && !blk) return false;
|
|
28498
29141
|
const resolvedKind = params.patch.shapeType ?? params.patch.kind ?? existing?.shapeType ?? existing?.kind ?? "roundRect";
|
|
28499
29142
|
const merged = {
|
|
28500
29143
|
...existing ?? { id: params.id },
|
|
28501
|
-
...
|
|
29144
|
+
...Tools14.deepClone(params.patch),
|
|
28502
29145
|
id: params.id,
|
|
28503
29146
|
shapeType: resolvedKind,
|
|
28504
29147
|
kind: resolvedKind
|
|
@@ -28514,7 +29157,7 @@ var UpdateDocShapeCommand = {
|
|
|
28514
29157
|
size: { width: rendered.widthPt, height: rendered.heightPt }
|
|
28515
29158
|
};
|
|
28516
29159
|
}
|
|
28517
|
-
const nextBody =
|
|
29160
|
+
const nextBody = Tools14.deepClone(prevBody);
|
|
28518
29161
|
if (blk) {
|
|
28519
29162
|
attachDrawingMetaRangeOnBody(nextBody, params.id, blk.startIndex, "docShape", merged);
|
|
28520
29163
|
}
|
|
@@ -28542,7 +29185,7 @@ var RemoveDocShapeCommand = {
|
|
|
28542
29185
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28543
29186
|
const nextBody = removeInlineDrawingBlockFromBody(prevBody, params.id);
|
|
28544
29187
|
if (!nextBody) return false;
|
|
28545
|
-
const prevMeta =
|
|
29188
|
+
const prevMeta = Tools14.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
28546
29189
|
const nextMap = { ...prevMeta.docShapes ?? {} };
|
|
28547
29190
|
delete nextMap[params.id];
|
|
28548
29191
|
sdtService.setTemplateMetadata(unitId, {
|
|
@@ -28587,8 +29230,8 @@ var SetDocTableRepeatHeaderCommand = {
|
|
|
28587
29230
|
const unitId = docModel.getUnitId();
|
|
28588
29231
|
const sdtService = accessor.get(IDocSdtService);
|
|
28589
29232
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28590
|
-
const prevSnap =
|
|
28591
|
-
const prevMeta =
|
|
29233
|
+
const prevSnap = Tools14.deepClone(docModel.getSnapshot());
|
|
29234
|
+
const prevMeta = Tools14.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
28592
29235
|
writeDocTemplateMetadataToSnapshot(prevSnap, prevMeta);
|
|
28593
29236
|
const updated = setDocTableRepeatHeaderInSnapshot(
|
|
28594
29237
|
prevSnap,
|
|
@@ -28688,13 +29331,13 @@ var InsertDocRepeatingSectionCommand = {
|
|
|
28688
29331
|
},
|
|
28689
29332
|
params.spec.templateText
|
|
28690
29333
|
);
|
|
28691
|
-
const prevMeta =
|
|
29334
|
+
const prevMeta = Tools14.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
28692
29335
|
const nextMeta = {
|
|
28693
29336
|
...prevMeta,
|
|
28694
29337
|
repeatingSections: {
|
|
28695
29338
|
...prevMeta.repeatingSections ?? {},
|
|
28696
29339
|
[id]: {
|
|
28697
|
-
...
|
|
29340
|
+
...Tools14.deepClone(params.spec),
|
|
28698
29341
|
id,
|
|
28699
29342
|
tag
|
|
28700
29343
|
}
|
|
@@ -28724,7 +29367,7 @@ var InsertDocBookmarkCommand = {
|
|
|
28724
29367
|
const unitId = docModel.getUnitId();
|
|
28725
29368
|
const sdtService = accessor.get(IDocSdtService);
|
|
28726
29369
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28727
|
-
const workingSnap =
|
|
29370
|
+
const workingSnap = Tools14.deepClone(docModel.getSnapshot());
|
|
28728
29371
|
writeDocTemplateMetadataToSnapshot(workingSnap, sdtService.getTemplateMetadata(unitId));
|
|
28729
29372
|
const inserted = insertBookmarkIntoSnapshot(workingSnap, params.spec);
|
|
28730
29373
|
if (!inserted) return false;
|
|
@@ -28748,7 +29391,7 @@ var RemoveDocBookmarkCommand = {
|
|
|
28748
29391
|
const unitId = docModel.getUnitId();
|
|
28749
29392
|
const sdtService = accessor.get(IDocSdtService);
|
|
28750
29393
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28751
|
-
const workingSnap =
|
|
29394
|
+
const workingSnap = Tools14.deepClone(docModel.getSnapshot());
|
|
28752
29395
|
writeDocTemplateMetadataToSnapshot(workingSnap, sdtService.getTemplateMetadata(unitId));
|
|
28753
29396
|
const removed = removeBookmarkFromSnapshot(workingSnap, params.nameOrId);
|
|
28754
29397
|
if (!removed) return false;
|
|
@@ -28766,7 +29409,7 @@ var InsertDocTableOfContentsCommand = {
|
|
|
28766
29409
|
const unitId = docModel.getUnitId();
|
|
28767
29410
|
const sdtService = accessor.get(IDocSdtService);
|
|
28768
29411
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28769
|
-
const workingSnap =
|
|
29412
|
+
const workingSnap = Tools14.deepClone(docModel.getSnapshot());
|
|
28770
29413
|
writeDocTemplateMetadataToSnapshot(workingSnap, sdtService.getTemplateMetadata(unitId));
|
|
28771
29414
|
const inserted = insertTableOfContentsIntoSnapshot(workingSnap, params?.spec, params?.offset);
|
|
28772
29415
|
sdtService.setTemplateMetadata(unitId, readDocTemplateMetadataFromSnapshot(inserted.snapshot));
|
|
@@ -28788,7 +29431,7 @@ var RefreshDocTableOfContentsCommand = {
|
|
|
28788
29431
|
const unitId = docModel.getUnitId();
|
|
28789
29432
|
const sdtService = accessor.get(IDocSdtService);
|
|
28790
29433
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
28791
|
-
const workingSnap =
|
|
29434
|
+
const workingSnap = Tools14.deepClone(docModel.getSnapshot());
|
|
28792
29435
|
writeDocTemplateMetadataToSnapshot(workingSnap, sdtService.getTemplateMetadata(unitId));
|
|
28793
29436
|
const refreshed = refreshTableOfContentsInSnapshot(workingSnap, params?.spec);
|
|
28794
29437
|
if (!refreshed) return false;
|
|
@@ -28807,13 +29450,13 @@ var RefreshDocTableOfContentsCommand = {
|
|
|
28807
29450
|
function buildAuxParams(unitId, snap, metadata) {
|
|
28808
29451
|
return {
|
|
28809
29452
|
unitId,
|
|
28810
|
-
tableSource:
|
|
28811
|
-
drawings:
|
|
28812
|
-
drawingsOrder:
|
|
28813
|
-
documentStyle:
|
|
28814
|
-
headers:
|
|
28815
|
-
footers:
|
|
28816
|
-
metadata:
|
|
29453
|
+
tableSource: Tools15.deepClone(snap.tableSource ?? {}),
|
|
29454
|
+
drawings: Tools15.deepClone(snap.drawings ?? {}),
|
|
29455
|
+
drawingsOrder: Tools15.deepClone(snap.drawingsOrder ?? []),
|
|
29456
|
+
documentStyle: Tools15.deepClone(snap.documentStyle ?? {}),
|
|
29457
|
+
headers: Tools15.deepClone(snap.headers ?? {}),
|
|
29458
|
+
footers: Tools15.deepClone(snap.footers ?? {}),
|
|
29459
|
+
metadata: Tools15.deepClone(metadata)
|
|
28817
29460
|
};
|
|
28818
29461
|
}
|
|
28819
29462
|
function executeWave2SnapshotUpdateWithUndoRedo(accessor, docModel, prevSnapshotClone, prevMetaClone, nextSnapshot, cursorOffset) {
|
|
@@ -28828,7 +29471,7 @@ function executeWave2SnapshotUpdateWithUndoRedo(accessor, docModel, prevSnapshot
|
|
|
28828
29471
|
const prevAux = buildAuxParams(unitId, prevSnapshotClone, prevMetaClone);
|
|
28829
29472
|
const nextAux = buildAuxParams(unitId, nextSnapshot, nextMeta);
|
|
28830
29473
|
commandService.syncExecuteCommand(SyncDocAuxStateMutation.id, nextAux);
|
|
28831
|
-
const bodyUnchanged =
|
|
29474
|
+
const bodyUnchanged = Tools15.diffValue(prevBody, nextBody);
|
|
28832
29475
|
const undoMutations = [{ id: SyncDocAuxStateMutation.id, params: prevAux }];
|
|
28833
29476
|
const redoMutations = [{ id: SyncDocAuxStateMutation.id, params: nextAux }];
|
|
28834
29477
|
if (!bodyUnchanged) {
|
|
@@ -28837,7 +29480,7 @@ function executeWave2SnapshotUpdateWithUndoRedo(accessor, docModel, prevSnapshot
|
|
|
28837
29480
|
);
|
|
28838
29481
|
if (hasLockedSdt) {
|
|
28839
29482
|
const livePrevBody = docModel.getSnapshot().body;
|
|
28840
|
-
const unlockedBody =
|
|
29483
|
+
const unlockedBody = Tools15.deepClone(livePrevBody);
|
|
28841
29484
|
unlockedBody.customRanges = (unlockedBody.customRanges ?? []).map(
|
|
28842
29485
|
(r) => r.rangeType === CustomRangeType12.SDT ? { ...r, properties: { ...r.properties, lock: "unlocked" } } : r
|
|
28843
29486
|
);
|
|
@@ -28904,9 +29547,9 @@ function prepareWorkingSnapshot(accessor, unitId) {
|
|
|
28904
29547
|
const resolvedUnitId = docModel.getUnitId();
|
|
28905
29548
|
const sdtService = accessor.get(IDocSdtService);
|
|
28906
29549
|
if (sdtService.getDocMode(resolvedUnitId) === "view") return null;
|
|
28907
|
-
const prevSnap =
|
|
28908
|
-
const prevMeta =
|
|
28909
|
-
const workingSnap =
|
|
29550
|
+
const prevSnap = Tools15.deepClone(docModel.getSnapshot());
|
|
29551
|
+
const prevMeta = Tools15.deepClone(sdtService.getTemplateMetadata(resolvedUnitId));
|
|
29552
|
+
const workingSnap = Tools15.deepClone(prevSnap);
|
|
28910
29553
|
writeDocTemplateMetadataToSnapshot(workingSnap, prevMeta);
|
|
28911
29554
|
return { docModel, unitId: resolvedUnitId, prevSnap, prevMeta, workingSnap };
|
|
28912
29555
|
}
|
|
@@ -29197,7 +29840,7 @@ var RemoveDocSmartArtCommand = {
|
|
|
29197
29840
|
if (!ctx) return false;
|
|
29198
29841
|
const nextBody = removeInlineDrawingBlockFromBody(ctx.workingSnap.body, params.id);
|
|
29199
29842
|
if (!nextBody) return false;
|
|
29200
|
-
const nextSnap =
|
|
29843
|
+
const nextSnap = Tools15.deepClone(ctx.workingSnap);
|
|
29201
29844
|
nextSnap.body = nextBody;
|
|
29202
29845
|
if (nextSnap.drawings) {
|
|
29203
29846
|
delete nextSnap.drawings[params.id];
|
|
@@ -29386,7 +30029,7 @@ var UpdateAllDocFieldsCommand = {
|
|
|
29386
30029
|
handler: (accessor, params) => {
|
|
29387
30030
|
const ctx = prepareWorkingSnapshot(accessor, params?.unitId);
|
|
29388
30031
|
if (!ctx) return false;
|
|
29389
|
-
const nextSnap =
|
|
30032
|
+
const nextSnap = Tools15.deepClone(ctx.workingSnap);
|
|
29390
30033
|
updateAllDocFieldsInSnapshot(nextSnap, params?.context);
|
|
29391
30034
|
return executeWave2SnapshotUpdateWithUndoRedo(
|
|
29392
30035
|
accessor,
|
|
@@ -29544,7 +30187,7 @@ var ALL_DOC_WAVE2_COMMANDS = [
|
|
|
29544
30187
|
// src/commands/doc-batch3.command.ts
|
|
29545
30188
|
import {
|
|
29546
30189
|
CommandType as CommandType3,
|
|
29547
|
-
Tools as
|
|
30190
|
+
Tools as Tools16
|
|
29548
30191
|
} from "@univerjs/core";
|
|
29549
30192
|
function prepareBatch3Snapshot(accessor, unitId) {
|
|
29550
30193
|
const docModel = getTargetDocModel(accessor, unitId);
|
|
@@ -29552,9 +30195,9 @@ function prepareBatch3Snapshot(accessor, unitId) {
|
|
|
29552
30195
|
const resolvedUnitId = docModel.getUnitId();
|
|
29553
30196
|
const sdtService = accessor.get(IDocSdtService);
|
|
29554
30197
|
if (sdtService.getDocMode(resolvedUnitId) === "view") return null;
|
|
29555
|
-
const prevSnap =
|
|
29556
|
-
const prevMeta =
|
|
29557
|
-
const workingSnap =
|
|
30198
|
+
const prevSnap = Tools16.deepClone(docModel.getSnapshot());
|
|
30199
|
+
const prevMeta = Tools16.deepClone(sdtService.getTemplateMetadata(resolvedUnitId));
|
|
30200
|
+
const workingSnap = Tools16.deepClone(prevSnap);
|
|
29558
30201
|
writeDocTemplateMetadataToSnapshot(workingSnap, prevMeta);
|
|
29559
30202
|
return { docModel, unitId: resolvedUnitId, prevSnap, prevMeta, workingSnap };
|
|
29560
30203
|
}
|
|
@@ -29943,7 +30586,7 @@ var ALL_DOC_BATCH3_COMMANDS = [
|
|
|
29943
30586
|
import {
|
|
29944
30587
|
CommandType as CommandType4,
|
|
29945
30588
|
CustomRangeType as CustomRangeType13,
|
|
29946
|
-
Tools as
|
|
30589
|
+
Tools as Tools17
|
|
29947
30590
|
} from "@univerjs/core";
|
|
29948
30591
|
import { DocSelectionManagerService } from "@univerjs/docs";
|
|
29949
30592
|
function prepareMutableSnapshot(accessor, unitId) {
|
|
@@ -29953,8 +30596,8 @@ function prepareMutableSnapshot(accessor, unitId) {
|
|
|
29953
30596
|
const resolvedUnitId = docModel.getUnitId();
|
|
29954
30597
|
const sdtService = accessor.get(IDocSdtService);
|
|
29955
30598
|
if (sdtService.getDocMode(resolvedUnitId) === "view") return null;
|
|
29956
|
-
const prevSnap =
|
|
29957
|
-
const prevMeta =
|
|
30599
|
+
const prevSnap = Tools17.deepClone(docModel.getSnapshot());
|
|
30600
|
+
const prevMeta = Tools17.deepClone(sdtService.getTemplateMetadata(resolvedUnitId));
|
|
29958
30601
|
writeDocTemplateMetadataToSnapshot(prevSnap, prevMeta);
|
|
29959
30602
|
return { docModel, unitId: resolvedUnitId, sdtService, workingSnap: prevSnap };
|
|
29960
30603
|
}
|
|
@@ -29974,7 +30617,7 @@ function commitUpdatedSnapshot(accessor, ctx, nextSnap, cursorOffset) {
|
|
|
29974
30617
|
syncSnapshotAuxFields(ctx.docModel, nextSnap);
|
|
29975
30618
|
ctx.sdtService.setTemplateMetadata(ctx.unitId, readDocTemplateMetadataFromSnapshot(nextSnap));
|
|
29976
30619
|
const prevBody = ctx.docModel.getSnapshot().body;
|
|
29977
|
-
if (
|
|
30620
|
+
if (Tools17.diffValue(prevBody, nextSnap.body)) {
|
|
29978
30621
|
ctx.sdtService.bumpRevision();
|
|
29979
30622
|
return true;
|
|
29980
30623
|
}
|
|
@@ -29994,7 +30637,7 @@ var HighlightInvalidDocSdtCommand = {
|
|
|
29994
30637
|
if (!ctx) return false;
|
|
29995
30638
|
const validation = params?.clear ? { valid: true, issues: [] } : validateDocForm(ctx.workingSnap);
|
|
29996
30639
|
const invalidIds = new Set(validation.issues.map((e) => e.controlId));
|
|
29997
|
-
const nextBody =
|
|
30640
|
+
const nextBody = Tools17.deepClone(ctx.workingSnap.body);
|
|
29998
30641
|
for (const rng of nextBody.customRanges ?? []) {
|
|
29999
30642
|
if (rng.rangeType !== CustomRangeType13.SDT) continue;
|
|
30000
30643
|
const resolved = parseSdtRangeToResolved(nextBody, rng);
|
|
@@ -30477,7 +31120,7 @@ var ALL_DOC_ROUND1_COMMANDS = [
|
|
|
30477
31120
|
// src/commands/doc-round3.command.ts
|
|
30478
31121
|
import {
|
|
30479
31122
|
CommandType as CommandType5,
|
|
30480
|
-
Tools as
|
|
31123
|
+
Tools as Tools18
|
|
30481
31124
|
} from "@univerjs/core";
|
|
30482
31125
|
import { DocSelectionManagerService as DocSelectionManagerService2 } from "@univerjs/docs";
|
|
30483
31126
|
function prepareRound3MutableSnapshot(accessor, unitId) {
|
|
@@ -30487,8 +31130,8 @@ function prepareRound3MutableSnapshot(accessor, unitId) {
|
|
|
30487
31130
|
const resolvedUnitId = docModel.getUnitId();
|
|
30488
31131
|
const sdtService = accessor.get(IDocSdtService);
|
|
30489
31132
|
if (sdtService.getDocMode(resolvedUnitId) === "view") return null;
|
|
30490
|
-
const prevSnap =
|
|
30491
|
-
const prevMeta =
|
|
31133
|
+
const prevSnap = Tools18.deepClone(docModel.getSnapshot());
|
|
31134
|
+
const prevMeta = Tools18.deepClone(sdtService.getTemplateMetadata(resolvedUnitId));
|
|
30492
31135
|
writeDocTemplateMetadataToSnapshot(prevSnap, prevMeta);
|
|
30493
31136
|
return { docModel, unitId: resolvedUnitId, sdtService, workingSnap: prevSnap };
|
|
30494
31137
|
}
|
|
@@ -30510,7 +31153,7 @@ function commitRound3Snapshot(accessor, ctx, nextSnap, cursorOffset) {
|
|
|
30510
31153
|
syncSnapshotAuxFields(ctx.docModel, nextSnap);
|
|
30511
31154
|
ctx.sdtService.setTemplateMetadata(ctx.unitId, readDocTemplateMetadataFromSnapshot(nextSnap));
|
|
30512
31155
|
const prevBody = ctx.docModel.getSnapshot().body;
|
|
30513
|
-
if (
|
|
31156
|
+
if (Tools18.diffValue(prevBody, nextSnap.body)) {
|
|
30514
31157
|
ctx.sdtService.bumpRevision(ctx.unitId);
|
|
30515
31158
|
return true;
|
|
30516
31159
|
}
|
|
@@ -30759,16 +31402,16 @@ function syncDocDrawingsToUniverServices(injector, unitId, snapshot) {
|
|
|
30759
31402
|
normalizeDocDrawingsAndPluginResource(snapshot);
|
|
30760
31403
|
const accessor = injector;
|
|
30761
31404
|
const docModel = getTargetDocModel(accessor, unitId);
|
|
30762
|
-
const nextDrawings =
|
|
30763
|
-
const nextOrder =
|
|
31405
|
+
const nextDrawings = Tools19.deepClone(snapshot.drawings ?? {});
|
|
31406
|
+
const nextOrder = Tools19.deepClone(snapshot.drawingsOrder ?? []);
|
|
30764
31407
|
if (docModel) {
|
|
30765
31408
|
const liveSnap = docModel.getSnapshot();
|
|
30766
|
-
liveSnap.drawings =
|
|
30767
|
-
liveSnap.drawingsOrder =
|
|
31409
|
+
liveSnap.drawings = Tools19.deepClone(nextDrawings);
|
|
31410
|
+
liveSnap.drawingsOrder = Tools19.deepClone(nextOrder);
|
|
30768
31411
|
if (snapshot.resources !== void 0) {
|
|
30769
|
-
liveSnap.resources =
|
|
31412
|
+
liveSnap.resources = Tools19.deepClone(snapshot.resources);
|
|
30770
31413
|
}
|
|
30771
|
-
docModel.resetDrawing?.(
|
|
31414
|
+
docModel.resetDrawing?.(Tools19.deepClone(nextDrawings), Tools19.deepClone(nextOrder));
|
|
30772
31415
|
}
|
|
30773
31416
|
try {
|
|
30774
31417
|
const resourceManagerService = accessor.get(IResourceManagerService);
|
|
@@ -30776,8 +31419,8 @@ function syncDocDrawingsToUniverServices(injector, unitId, snapshot) {
|
|
|
30776
31419
|
if (hook) {
|
|
30777
31420
|
if (Object.keys(nextDrawings).length > 0) {
|
|
30778
31421
|
hook.onLoad(unitId, {
|
|
30779
|
-
data:
|
|
30780
|
-
order:
|
|
31422
|
+
data: Tools19.deepClone(nextDrawings),
|
|
31423
|
+
order: Tools19.deepClone(nextOrder)
|
|
30781
31424
|
});
|
|
30782
31425
|
} else {
|
|
30783
31426
|
hook.onUnLoad?.(unitId);
|
|
@@ -30789,43 +31432,43 @@ function syncDocDrawingsToUniverServices(injector, unitId, snapshot) {
|
|
|
30789
31432
|
function syncSnapshotAuxFields(docModel, nextSnapshot) {
|
|
30790
31433
|
const liveSnap = docModel.getSnapshot();
|
|
30791
31434
|
if (nextSnapshot.tableSource !== void 0) {
|
|
30792
|
-
liveSnap.tableSource =
|
|
31435
|
+
liveSnap.tableSource = Tools19.deepClone(nextSnapshot.tableSource);
|
|
30793
31436
|
}
|
|
30794
31437
|
if (nextSnapshot.headers !== void 0) {
|
|
30795
|
-
liveSnap.headers =
|
|
31438
|
+
liveSnap.headers = Tools19.deepClone(nextSnapshot.headers);
|
|
30796
31439
|
}
|
|
30797
31440
|
if (nextSnapshot.footers !== void 0) {
|
|
30798
|
-
liveSnap.footers =
|
|
31441
|
+
liveSnap.footers = Tools19.deepClone(nextSnapshot.footers);
|
|
30799
31442
|
}
|
|
30800
31443
|
if (nextSnapshot.notes !== void 0) {
|
|
30801
|
-
liveSnap.notes =
|
|
31444
|
+
liveSnap.notes = Tools19.deepClone(nextSnapshot.notes);
|
|
30802
31445
|
}
|
|
30803
31446
|
if (nextSnapshot.noteSettings !== void 0) {
|
|
30804
|
-
liveSnap.noteSettings =
|
|
31447
|
+
liveSnap.noteSettings = Tools19.deepClone(nextSnapshot.noteSettings);
|
|
30805
31448
|
}
|
|
30806
31449
|
if (nextSnapshot.footnotes !== void 0) {
|
|
30807
|
-
liveSnap.footnotes =
|
|
31450
|
+
liveSnap.footnotes = Tools19.deepClone(nextSnapshot.footnotes);
|
|
30808
31451
|
}
|
|
30809
31452
|
if (nextSnapshot.endnotes !== void 0) {
|
|
30810
|
-
liveSnap.endnotes =
|
|
31453
|
+
liveSnap.endnotes = Tools19.deepClone(nextSnapshot.endnotes);
|
|
30811
31454
|
}
|
|
30812
31455
|
if (nextSnapshot.drawings !== void 0) {
|
|
30813
|
-
liveSnap.drawings =
|
|
31456
|
+
liveSnap.drawings = Tools19.deepClone(nextSnapshot.drawings);
|
|
30814
31457
|
}
|
|
30815
31458
|
if (nextSnapshot.drawingsOrder !== void 0) {
|
|
30816
|
-
liveSnap.drawingsOrder =
|
|
31459
|
+
liveSnap.drawingsOrder = Tools19.deepClone(nextSnapshot.drawingsOrder);
|
|
30817
31460
|
}
|
|
30818
31461
|
if (nextSnapshot.lists !== void 0) {
|
|
30819
|
-
liveSnap.lists =
|
|
31462
|
+
liveSnap.lists = Tools19.deepClone(nextSnapshot.lists);
|
|
30820
31463
|
}
|
|
30821
31464
|
if (nextSnapshot.styles !== void 0) {
|
|
30822
|
-
liveSnap.styles =
|
|
31465
|
+
liveSnap.styles = Tools19.deepClone(nextSnapshot.styles);
|
|
30823
31466
|
}
|
|
30824
31467
|
if (nextSnapshot.resources !== void 0) {
|
|
30825
|
-
liveSnap.resources =
|
|
31468
|
+
liveSnap.resources = Tools19.deepClone(nextSnapshot.resources);
|
|
30826
31469
|
}
|
|
30827
31470
|
if (nextSnapshot.documentStyle) {
|
|
30828
|
-
liveSnap.documentStyle =
|
|
31471
|
+
liveSnap.documentStyle = Tools19.deepClone(nextSnapshot.documentStyle);
|
|
30829
31472
|
}
|
|
30830
31473
|
if (nextSnapshot.headers !== void 0 || nextSnapshot.footers !== void 0) {
|
|
30831
31474
|
reinitializeDocHeaderFooterModels(docModel);
|
|
@@ -30841,7 +31484,7 @@ function executeBodyUpdateViaRichTextMutation(accessor, docModel, nextBody, curs
|
|
|
30841
31484
|
const prevSnap = docModel.getSnapshot();
|
|
30842
31485
|
const prevBody = prevSnap.body;
|
|
30843
31486
|
if (!prevBody) return false;
|
|
30844
|
-
const bodyEqual =
|
|
31487
|
+
const bodyEqual = Tools19.diffValue(prevBody, nextBody);
|
|
30845
31488
|
if (bodyEqual && !forceRecalculate) return true;
|
|
30846
31489
|
const wasDisabled = Boolean(prevSnap.disabled);
|
|
30847
31490
|
if (allowInViewMode && wasDisabled) {
|
|
@@ -30850,7 +31493,7 @@ function executeBodyUpdateViaRichTextMutation(accessor, docModel, nextBody, curs
|
|
|
30850
31493
|
try {
|
|
30851
31494
|
if (bodyEqual && forceRecalculate) {
|
|
30852
31495
|
const tempBody = {
|
|
30853
|
-
...
|
|
31496
|
+
...Tools19.deepClone(prevBody),
|
|
30854
31497
|
payloads: { ...prevBody.payloads ?? {}, __recalc: generateRandomId15(4) }
|
|
30855
31498
|
};
|
|
30856
31499
|
const recalcUnlockOp = buildBodyReplaceEditOp(prevBody, tempBody);
|
|
@@ -30868,7 +31511,7 @@ function executeBodyUpdateViaRichTextMutation(accessor, docModel, nextBody, curs
|
|
|
30868
31511
|
(r) => r.rangeType === CustomRangeType14.SDT && r.properties?.lock && r.properties.lock !== "unlocked"
|
|
30869
31512
|
);
|
|
30870
31513
|
if (hasLockedSdt) {
|
|
30871
|
-
const unlockedBody =
|
|
31514
|
+
const unlockedBody = Tools19.deepClone(liveBeforeLockCheck);
|
|
30872
31515
|
unlockedBody.customRanges = (unlockedBody.customRanges ?? []).map(
|
|
30873
31516
|
(r) => r.rangeType === CustomRangeType14.SDT ? {
|
|
30874
31517
|
...r,
|
|
@@ -30979,7 +31622,7 @@ var InsertDocSdtCommand = {
|
|
|
30979
31622
|
typeof wrapEndOffset === "number" && wrapEndOffset > insertOffset ? { wrapEndOffset } : void 0
|
|
30980
31623
|
);
|
|
30981
31624
|
if (targetSegmentId && targetBody !== liveSnap.body) {
|
|
30982
|
-
const clonedSnap =
|
|
31625
|
+
const clonedSnap = Tools19.deepClone(liveSnap);
|
|
30983
31626
|
writeSegmentBodyInSnapshot(clonedSnap, insertedBody, targetSegmentId);
|
|
30984
31627
|
if (isImgInitial) {
|
|
30985
31628
|
const insertedRange = insertedBody.customRanges?.find((r) => r.rangeId === controlId);
|
|
@@ -31001,7 +31644,7 @@ var InsertDocSdtCommand = {
|
|
|
31001
31644
|
let finalBody = insertedBody;
|
|
31002
31645
|
let finalCursor = endOffset;
|
|
31003
31646
|
if (isImgInitial) {
|
|
31004
|
-
const clonedSnap = { ...
|
|
31647
|
+
const clonedSnap = { ...Tools19.deepClone(liveSnap), body: insertedBody };
|
|
31005
31648
|
const insertedRange = insertedBody.customRanges?.find((r) => r.rangeId === controlId);
|
|
31006
31649
|
const resolved = insertedRange ? parseSdtRangeToResolved(insertedBody, insertedRange) : null;
|
|
31007
31650
|
if (resolved && applyPictureOrSignatureSdtValueInSnapshot(clonedSnap, resolved, String(params.initialValue))) {
|
|
@@ -31046,7 +31689,7 @@ var UpdateDocSdtValueCommand = {
|
|
|
31046
31689
|
return false;
|
|
31047
31690
|
}
|
|
31048
31691
|
if (hitSegmentId && prevBody !== liveSnap.body) {
|
|
31049
|
-
const clonedSnap =
|
|
31692
|
+
const clonedSnap = Tools19.deepClone(liveSnap);
|
|
31050
31693
|
if (resolved.kind === "picture" || resolved.kind === "signature") {
|
|
31051
31694
|
applyPictureOrSignatureSdtValueInSnapshot(
|
|
31052
31695
|
clonedSnap,
|
|
@@ -31104,8 +31747,8 @@ var UpdateDocSdtValueCommand = {
|
|
|
31104
31747
|
});
|
|
31105
31748
|
return true;
|
|
31106
31749
|
}
|
|
31107
|
-
const baseMeta =
|
|
31108
|
-
const workingSnap =
|
|
31750
|
+
const baseMeta = Tools19.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
31751
|
+
const workingSnap = Tools19.deepClone(liveSnap);
|
|
31109
31752
|
let approxNewLen = 1;
|
|
31110
31753
|
if (resolved.kind === "picture" || resolved.kind === "signature") {
|
|
31111
31754
|
applyPictureOrSignatureSdtValueInSnapshot(
|
|
@@ -31222,7 +31865,7 @@ var UpdateDocSdtPropertiesCommand = {
|
|
|
31222
31865
|
};
|
|
31223
31866
|
const hasEmbeddedBlock = prevBody.dataStream.slice(targetRange.startIndex, targetRange.endIndex + 1).includes("\b");
|
|
31224
31867
|
if (mergedSpec.kind === "group" || (mergedSpec.kind === "picture" || mergedSpec.kind === "signature") && hasEmbeddedBlock) {
|
|
31225
|
-
const nextBody2 =
|
|
31868
|
+
const nextBody2 = Tools19.deepClone(prevBody);
|
|
31226
31869
|
const nextProps2 = buildSdtPropertiesFromSpec(
|
|
31227
31870
|
mergedSpec,
|
|
31228
31871
|
current.showingPlaceholder,
|
|
@@ -31232,7 +31875,7 @@ var UpdateDocSdtPropertiesCommand = {
|
|
|
31232
31875
|
(r) => r.rangeId === current.id ? { ...r, properties: nextProps2 } : r
|
|
31233
31876
|
);
|
|
31234
31877
|
if (hitSegmentId && prevBody !== liveSnap.body) {
|
|
31235
|
-
const clonedSnap =
|
|
31878
|
+
const clonedSnap = Tools19.deepClone(liveSnap);
|
|
31236
31879
|
writeSegmentBodyInSnapshot(clonedSnap, nextBody2, hitSegmentId);
|
|
31237
31880
|
syncSnapshotAuxFields(docModel, clonedSnap);
|
|
31238
31881
|
sdtService.bumpRevision();
|
|
@@ -31279,15 +31922,15 @@ var UpdateDocSdtPropertiesCommand = {
|
|
|
31279
31922
|
}
|
|
31280
31923
|
);
|
|
31281
31924
|
if (hitSegmentId && prevBody !== liveSnap.body) {
|
|
31282
|
-
const clonedSnap =
|
|
31925
|
+
const clonedSnap = Tools19.deepClone(liveSnap);
|
|
31283
31926
|
writeSegmentBodyInSnapshot(clonedSnap, nextBody, hitSegmentId);
|
|
31284
31927
|
syncSnapshotAuxFields(docModel, clonedSnap);
|
|
31285
31928
|
sdtService.bumpRevision();
|
|
31286
31929
|
return true;
|
|
31287
31930
|
}
|
|
31288
|
-
const baseMeta =
|
|
31931
|
+
const baseMeta = Tools19.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
31289
31932
|
const workingSnap = {
|
|
31290
|
-
...
|
|
31933
|
+
...Tools19.deepClone(liveSnap),
|
|
31291
31934
|
body: nextBody
|
|
31292
31935
|
};
|
|
31293
31936
|
writeDocTemplateMetadataToSnapshot(workingSnap, baseMeta);
|
|
@@ -31323,10 +31966,10 @@ var DeleteDocSdtCommand = {
|
|
|
31323
31966
|
return false;
|
|
31324
31967
|
}
|
|
31325
31968
|
if (hitSegmentId && prevBody !== liveSnap.body) {
|
|
31326
|
-
const clonedSnap =
|
|
31969
|
+
const clonedSnap = Tools19.deepClone(liveSnap);
|
|
31327
31970
|
let nextSegBody;
|
|
31328
31971
|
if (params.keepText) {
|
|
31329
|
-
nextSegBody =
|
|
31972
|
+
nextSegBody = Tools19.deepClone(prevBody);
|
|
31330
31973
|
nextSegBody.customRanges = (nextSegBody.customRanges ?? []).filter(
|
|
31331
31974
|
(r) => r.rangeId !== params.controlId
|
|
31332
31975
|
);
|
|
@@ -31344,11 +31987,11 @@ var DeleteDocSdtCommand = {
|
|
|
31344
31987
|
sdtService.bumpRevision();
|
|
31345
31988
|
return true;
|
|
31346
31989
|
}
|
|
31347
|
-
const unlockedPrev =
|
|
31990
|
+
const unlockedPrev = Tools19.deepClone(prevBody);
|
|
31348
31991
|
unlockedPrev.customRanges = (unlockedPrev.customRanges ?? []).map(
|
|
31349
31992
|
(r) => r.rangeId === params.controlId ? { ...r, properties: { ...r.properties, lock: "unlocked" } } : r
|
|
31350
31993
|
);
|
|
31351
|
-
if (!
|
|
31994
|
+
if (!Tools19.diffValue(prevBody, unlockedPrev)) {
|
|
31352
31995
|
const unlockOp = buildBodyReplaceEditOp(prevBody, unlockedPrev);
|
|
31353
31996
|
accessor.get(ICommandService4).syncExecuteCommand(RichTextEditingMutation2.id, {
|
|
31354
31997
|
unitId: docModel.getUnitId(),
|
|
@@ -31360,7 +32003,7 @@ var DeleteDocSdtCommand = {
|
|
|
31360
32003
|
const baseBody = docModel.getSnapshot().body;
|
|
31361
32004
|
let nextBody;
|
|
31362
32005
|
if (params.keepText) {
|
|
31363
|
-
nextBody =
|
|
32006
|
+
nextBody = Tools19.deepClone(baseBody);
|
|
31364
32007
|
nextBody.customRanges = (nextBody.customRanges ?? []).filter((r) => r.rangeId !== params.controlId);
|
|
31365
32008
|
} else {
|
|
31366
32009
|
nextBody = spliceDocumentBodySpan(baseBody, targetRange.startIndex, targetRange.endIndex, "");
|
|
@@ -31383,9 +32026,9 @@ var FillDocDatasetCommand = {
|
|
|
31383
32026
|
const sdtService = accessor.get(IDocSdtService);
|
|
31384
32027
|
if (sdtService.getDocMode(docModel.getUnitId()) === "view") return false;
|
|
31385
32028
|
const unitId = docModel.getUnitId();
|
|
31386
|
-
const prevMeta =
|
|
31387
|
-
const prevSnap =
|
|
31388
|
-
const baseSnap =
|
|
32029
|
+
const prevMeta = Tools19.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
32030
|
+
const prevSnap = Tools19.deepClone(docModel.getSnapshot());
|
|
32031
|
+
const baseSnap = Tools19.deepClone(prevSnap);
|
|
31389
32032
|
writeDocTemplateMetadataToSnapshot(baseSnap, prevMeta);
|
|
31390
32033
|
const filledSnapshot = fillDatasetIntoDocSnapshot(baseSnap, params.data, {
|
|
31391
32034
|
tableRowLoops: prevMeta.tableRowLoops
|
|
@@ -31400,37 +32043,109 @@ var FillDocDatasetCommand = {
|
|
|
31400
32043
|
);
|
|
31401
32044
|
}
|
|
31402
32045
|
};
|
|
32046
|
+
function isValidReplacementDocSnapshot(snapshot) {
|
|
32047
|
+
if (!snapshot || typeof snapshot !== "object") return false;
|
|
32048
|
+
const candidate = snapshot;
|
|
32049
|
+
const body = candidate.body;
|
|
32050
|
+
if (!body || typeof body !== "object") return false;
|
|
32051
|
+
if (typeof body.dataStream !== "string" || body.dataStream.length < 2) return false;
|
|
32052
|
+
if (!body.dataStream.endsWith("\r\n")) return false;
|
|
32053
|
+
if (body.paragraphs !== void 0 && !Array.isArray(body.paragraphs)) return false;
|
|
32054
|
+
if (body.sectionBreaks !== void 0 && !Array.isArray(body.sectionBreaks)) return false;
|
|
32055
|
+
if (body.tables !== void 0 && !Array.isArray(body.tables)) return false;
|
|
32056
|
+
if (body.customRanges !== void 0 && !Array.isArray(body.customRanges)) return false;
|
|
32057
|
+
if (body.textRuns !== void 0 && !Array.isArray(body.textRuns)) return false;
|
|
32058
|
+
return true;
|
|
32059
|
+
}
|
|
32060
|
+
function restoreDocUnitStateOnFailure(accessor, docModel, unitId, prevSnapClone, prevMetaClone) {
|
|
32061
|
+
const commandService = accessor.get(ICommandService4);
|
|
32062
|
+
const sdtService = accessor.get(IDocSdtService);
|
|
32063
|
+
try {
|
|
32064
|
+
const curBody = docModel.getSnapshot().body;
|
|
32065
|
+
if (curBody && prevSnapClone.body && !Tools19.diffValue(curBody, prevSnapClone.body)) {
|
|
32066
|
+
const revertActions = buildBodyReplaceEditOp(curBody, Tools19.deepClone(prevSnapClone.body));
|
|
32067
|
+
if (revertActions) {
|
|
32068
|
+
const liveRef = docModel.getSnapshot();
|
|
32069
|
+
const wasDisabled = Boolean(liveRef.disabled);
|
|
32070
|
+
if (wasDisabled) liveRef.disabled = false;
|
|
32071
|
+
try {
|
|
32072
|
+
commandService.syncExecuteCommand(RichTextEditingMutation2.id, {
|
|
32073
|
+
unitId,
|
|
32074
|
+
actions: revertActions,
|
|
32075
|
+
noHistory: true,
|
|
32076
|
+
noNeedSetTextRange: true
|
|
32077
|
+
});
|
|
32078
|
+
} finally {
|
|
32079
|
+
if (wasDisabled) liveRef.disabled = true;
|
|
32080
|
+
}
|
|
32081
|
+
}
|
|
32082
|
+
}
|
|
32083
|
+
} catch {
|
|
32084
|
+
}
|
|
32085
|
+
try {
|
|
32086
|
+
syncDocDrawingsToUniverServices(accessor, unitId, Tools19.deepClone(prevSnapClone));
|
|
32087
|
+
} catch {
|
|
32088
|
+
}
|
|
32089
|
+
sdtService.setTemplateMetadata(unitId, Tools19.deepClone(prevMetaClone));
|
|
32090
|
+
const liveSnap = docModel.getSnapshot();
|
|
32091
|
+
const exactPrev = Tools19.deepClone(prevSnapClone);
|
|
32092
|
+
for (const key of Object.keys(liveSnap)) {
|
|
32093
|
+
if (!(key in exactPrev)) {
|
|
32094
|
+
delete liveSnap[key];
|
|
32095
|
+
}
|
|
32096
|
+
}
|
|
32097
|
+
Object.assign(liveSnap, exactPrev);
|
|
32098
|
+
reinitializeDocHeaderFooterModels(docModel);
|
|
32099
|
+
}
|
|
31403
32100
|
var ReplaceDocUnitSnapshotCommand = {
|
|
31404
32101
|
id: "yudao-docs.command.replace-snapshot",
|
|
31405
32102
|
type: CommandType6.COMMAND,
|
|
31406
32103
|
handler: (accessor, params) => {
|
|
31407
|
-
if (!params?.snapshot
|
|
32104
|
+
if (!isValidReplacementDocSnapshot(params?.snapshot)) return false;
|
|
31408
32105
|
const docModel = getTargetDocModel(accessor, params.unitId);
|
|
31409
32106
|
if (!docModel) return false;
|
|
31410
32107
|
const unitId = docModel.getUnitId();
|
|
31411
|
-
const normalizedSnap = Tools18.deepClone(params.snapshot);
|
|
31412
|
-
if (!normalizedSnap.id) {
|
|
31413
|
-
normalizedSnap.id = unitId;
|
|
31414
|
-
}
|
|
31415
|
-
normalizeDocDrawingsAndPluginResource(normalizedSnap);
|
|
31416
|
-
const prevSnap = docModel.getSnapshot();
|
|
31417
|
-
const auxChanged = normalizedSnap.headers !== void 0 && !Tools18.diffValue(prevSnap.headers ?? {}, normalizedSnap.headers ?? {}) || normalizedSnap.footers !== void 0 && !Tools18.diffValue(prevSnap.footers ?? {}, normalizedSnap.footers ?? {}) || normalizedSnap.drawings !== void 0 && !Tools18.diffValue(prevSnap.drawings ?? {}, normalizedSnap.drawings ?? {}) || normalizedSnap.drawingsOrder !== void 0 && !Tools18.diffValue(prevSnap.drawingsOrder ?? [], normalizedSnap.drawingsOrder ?? []) || normalizedSnap.documentStyle !== void 0 && !Tools18.diffValue(prevSnap.documentStyle ?? {}, normalizedSnap.documentStyle ?? {}) || normalizedSnap.styles !== void 0 && !Tools18.diffValue(prevSnap.styles ?? {}, normalizedSnap.styles ?? {}) || normalizedSnap.tableSource !== void 0 && !Tools18.diffValue(prevSnap.tableSource ?? {}, normalizedSnap.tableSource ?? {});
|
|
31418
|
-
syncSnapshotAuxFields(docModel, normalizedSnap);
|
|
31419
|
-
reinitializeDocHeaderFooterModels(docModel);
|
|
31420
|
-
syncDocDrawingsToUniverServices(accessor, unitId, normalizedSnap);
|
|
31421
|
-
const snapMeta = readDocTemplateMetadataFromSnapshot(normalizedSnap);
|
|
31422
32108
|
const sdtService = accessor.get(IDocSdtService);
|
|
31423
|
-
|
|
31424
|
-
sdtService.
|
|
31425
|
-
|
|
31426
|
-
|
|
31427
|
-
|
|
31428
|
-
|
|
31429
|
-
|
|
31430
|
-
|
|
31431
|
-
|
|
31432
|
-
|
|
31433
|
-
|
|
32109
|
+
const allowInViewMode = Boolean(params.allowInViewMode);
|
|
32110
|
+
if (!allowInViewMode && sdtService.getDocMode(unitId) === "view") {
|
|
32111
|
+
return false;
|
|
32112
|
+
}
|
|
32113
|
+
const prevSnapClone = Tools19.deepClone(docModel.getSnapshot());
|
|
32114
|
+
const prevMetaClone = Tools19.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
32115
|
+
try {
|
|
32116
|
+
const normalizedSnap = Tools19.deepClone(params.snapshot);
|
|
32117
|
+
if (!normalizedSnap.id) {
|
|
32118
|
+
normalizedSnap.id = unitId;
|
|
32119
|
+
}
|
|
32120
|
+
normalizeDocDrawingsAndPluginResource(normalizedSnap);
|
|
32121
|
+
if (!isValidReplacementDocSnapshot(normalizedSnap)) {
|
|
32122
|
+
return false;
|
|
32123
|
+
}
|
|
32124
|
+
const auxChanged = normalizedSnap.headers !== void 0 && !Tools19.diffValue(prevSnapClone.headers ?? {}, normalizedSnap.headers ?? {}) || normalizedSnap.footers !== void 0 && !Tools19.diffValue(prevSnapClone.footers ?? {}, normalizedSnap.footers ?? {}) || normalizedSnap.drawings !== void 0 && !Tools19.diffValue(prevSnapClone.drawings ?? {}, normalizedSnap.drawings ?? {}) || normalizedSnap.drawingsOrder !== void 0 && !Tools19.diffValue(prevSnapClone.drawingsOrder ?? [], normalizedSnap.drawingsOrder ?? []) || normalizedSnap.documentStyle !== void 0 && !Tools19.diffValue(prevSnapClone.documentStyle ?? {}, normalizedSnap.documentStyle ?? {}) || normalizedSnap.styles !== void 0 && !Tools19.diffValue(prevSnapClone.styles ?? {}, normalizedSnap.styles ?? {}) || normalizedSnap.tableSource !== void 0 && !Tools19.diffValue(prevSnapClone.tableSource ?? {}, normalizedSnap.tableSource ?? {});
|
|
32125
|
+
syncSnapshotAuxFields(docModel, normalizedSnap);
|
|
32126
|
+
reinitializeDocHeaderFooterModels(docModel);
|
|
32127
|
+
syncDocDrawingsToUniverServices(accessor, unitId, normalizedSnap);
|
|
32128
|
+
const snapMeta = readDocTemplateMetadataFromSnapshot(normalizedSnap);
|
|
32129
|
+
sdtService.setTemplateMetadata(unitId, snapMeta);
|
|
32130
|
+
const ok = executeBodyUpdateViaRichTextMutation(
|
|
32131
|
+
accessor,
|
|
32132
|
+
docModel,
|
|
32133
|
+
normalizedSnap.body,
|
|
32134
|
+
0,
|
|
32135
|
+
true,
|
|
32136
|
+
allowInViewMode,
|
|
32137
|
+
auxChanged
|
|
32138
|
+
);
|
|
32139
|
+
if (!ok) {
|
|
32140
|
+
restoreDocUnitStateOnFailure(accessor, docModel, unitId, prevSnapClone, prevMetaClone);
|
|
32141
|
+
return false;
|
|
32142
|
+
}
|
|
32143
|
+
sdtService.bumpRevision(unitId);
|
|
32144
|
+
return true;
|
|
32145
|
+
} catch {
|
|
32146
|
+
restoreDocUnitStateOnFailure(accessor, docModel, unitId, prevSnapClone, prevMetaClone);
|
|
32147
|
+
return false;
|
|
32148
|
+
}
|
|
31434
32149
|
}
|
|
31435
32150
|
};
|
|
31436
32151
|
var SetDocModeCommand = {
|
|
@@ -31630,7 +32345,7 @@ var InsertDocMedicalFormulaCommand = {
|
|
|
31630
32345
|
const sdtService = accessor.get(IDocSdtService);
|
|
31631
32346
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
31632
32347
|
const layout = layoutMedicalFormulaWidget(params.spec);
|
|
31633
|
-
const prevMeta =
|
|
32348
|
+
const prevMeta = Tools19.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
31634
32349
|
const liveSnap = docModel.getSnapshot();
|
|
31635
32350
|
if (params.blockId && liveSnap.drawings?.[params.blockId]) {
|
|
31636
32351
|
const drw = liveSnap.drawings[params.blockId];
|
|
@@ -31650,7 +32365,7 @@ var InsertDocMedicalFormulaCommand = {
|
|
|
31650
32365
|
...prevMeta.medicalFormulas ?? {},
|
|
31651
32366
|
[params.blockId]: {
|
|
31652
32367
|
blockId: params.blockId,
|
|
31653
|
-
spec:
|
|
32368
|
+
spec: Tools19.deepClone(params.spec),
|
|
31654
32369
|
widthPt: layout.widthPt,
|
|
31655
32370
|
heightPt: layout.heightPt,
|
|
31656
32371
|
plainSummary: layout.plainSummary
|
|
@@ -31683,7 +32398,7 @@ var InsertDocMedicalFormulaCommand = {
|
|
|
31683
32398
|
...prevMeta.medicalFormulas ?? {},
|
|
31684
32399
|
[inserted.blockId]: {
|
|
31685
32400
|
blockId: inserted.blockId,
|
|
31686
|
-
spec:
|
|
32401
|
+
spec: Tools19.deepClone(params.spec),
|
|
31687
32402
|
widthPt: layout.widthPt,
|
|
31688
32403
|
heightPt: layout.heightPt,
|
|
31689
32404
|
plainSummary: layout.plainSummary
|
|
@@ -31724,7 +32439,7 @@ var InsertDocCodeBlockCommand = {
|
|
|
31724
32439
|
offset
|
|
31725
32440
|
);
|
|
31726
32441
|
const insertedLen = inserted.entry.endIndex - inserted.entry.startIndex;
|
|
31727
|
-
const prevMeta =
|
|
32442
|
+
const prevMeta = Tools19.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
31728
32443
|
if (prevMeta.revisions?.length && insertedLen > 0) {
|
|
31729
32444
|
prevMeta.revisions = shiftTrackRevisions(
|
|
31730
32445
|
prevMeta.revisions,
|
|
@@ -31761,7 +32476,7 @@ var InsertDocQrOrBarcodeBlockCommand = {
|
|
|
31761
32476
|
const unitId = docModel.getUnitId();
|
|
31762
32477
|
const sdtService = accessor.get(IDocSdtService);
|
|
31763
32478
|
if (sdtService.getDocMode(unitId) === "view") return false;
|
|
31764
|
-
const prevMeta =
|
|
32479
|
+
const prevMeta = Tools19.deepClone(sdtService.getTemplateMetadata(unitId));
|
|
31765
32480
|
const widthPt = params.spec.widthPt ?? (params.spec.kind === "barcode" ? 140 : 68);
|
|
31766
32481
|
const heightPt = params.spec.heightPt ?? (params.spec.kind === "barcode" ? 44 : 68);
|
|
31767
32482
|
const dataUri = buildQrOrBarcodeDataUri(params.spec, prevMeta.sampleData);
|
|
@@ -31788,7 +32503,7 @@ var InsertDocQrOrBarcodeBlockCommand = {
|
|
|
31788
32503
|
...prevMeta.barcodeBlocks ?? {},
|
|
31789
32504
|
[inserted.blockId]: {
|
|
31790
32505
|
blockId: inserted.blockId,
|
|
31791
|
-
spec:
|
|
32506
|
+
spec: Tools19.deepClone(params.spec),
|
|
31792
32507
|
widthPt,
|
|
31793
32508
|
heightPt
|
|
31794
32509
|
}
|
|
@@ -31816,7 +32531,7 @@ import {
|
|
|
31816
32531
|
TableAlignmentType as TableAlignmentType3,
|
|
31817
32532
|
TableRowHeightRule as TableRowHeightRule5,
|
|
31818
32533
|
TableTextWrapType as TableTextWrapType3,
|
|
31819
|
-
Tools as
|
|
32534
|
+
Tools as Tools20
|
|
31820
32535
|
} from "@univerjs/core";
|
|
31821
32536
|
var GFM_CALLOUT_PRESETS = {
|
|
31822
32537
|
NOTE: { preset: "info", bg: "#F3F5FF", border: "#2C53F1", text: "#1B1C1F" },
|
|
@@ -32007,7 +32722,7 @@ function emitMarkdownInlineSegments(rawLine, baseStyle, ctx) {
|
|
|
32007
32722
|
properties: {
|
|
32008
32723
|
yudaoBlockKind: "latexFormula",
|
|
32009
32724
|
blockId: id,
|
|
32010
|
-
spec:
|
|
32725
|
+
spec: Tools20.deepClone(spec)
|
|
32011
32726
|
}
|
|
32012
32727
|
});
|
|
32013
32728
|
i = closeIdx + delim.length;
|
|
@@ -32365,7 +33080,7 @@ function importMarkdownToDocData(markdown, title = "Markdown Document") {
|
|
|
32365
33080
|
properties: {
|
|
32366
33081
|
yudaoBlockKind: "callout",
|
|
32367
33082
|
gfmType: gfmKind,
|
|
32368
|
-
callout:
|
|
33083
|
+
callout: Tools20.deepClone(entry)
|
|
32369
33084
|
}
|
|
32370
33085
|
});
|
|
32371
33086
|
calloutsMeta.push(entry);
|
|
@@ -32398,7 +33113,7 @@ function importMarkdownToDocData(markdown, title = "Markdown Document") {
|
|
|
32398
33113
|
endIndex: qEnd,
|
|
32399
33114
|
properties: {
|
|
32400
33115
|
yudaoBlockKind: "quote",
|
|
32401
|
-
quote:
|
|
33116
|
+
quote: Tools20.deepClone(qEntry)
|
|
32402
33117
|
}
|
|
32403
33118
|
});
|
|
32404
33119
|
quotesMeta.push(qEntry);
|
|
@@ -32857,11 +33572,11 @@ import {
|
|
|
32857
33572
|
ICommandService as ICommandService5,
|
|
32858
33573
|
Inject,
|
|
32859
33574
|
Injector,
|
|
32860
|
-
IUniverInstanceService as
|
|
33575
|
+
IUniverInstanceService as IUniverInstanceService4,
|
|
32861
33576
|
Plugin,
|
|
32862
33577
|
RedoCommand as RedoCommand2,
|
|
32863
33578
|
UndoCommand as UndoCommand2,
|
|
32864
|
-
UniverInstanceType as
|
|
33579
|
+
UniverInstanceType as UniverInstanceType4
|
|
32865
33580
|
} from "@univerjs/core";
|
|
32866
33581
|
import { DocSelectionManagerService as DocSelectionManagerService4, RichTextEditingMutation as RichTextEditingMutation3 } from "@univerjs/docs";
|
|
32867
33582
|
|
|
@@ -33287,7 +34002,10 @@ var DocExtensionRegistryService = class extends Disposable4 {
|
|
|
33287
34002
|
// src/services/doc-io.service.ts
|
|
33288
34003
|
import {
|
|
33289
34004
|
createIdentifier as createIdentifier5,
|
|
33290
|
-
Disposable as Disposable5
|
|
34005
|
+
Disposable as Disposable5,
|
|
34006
|
+
IUniverInstanceService as IUniverInstanceService3,
|
|
34007
|
+
Optional,
|
|
34008
|
+
UniverInstanceType as UniverInstanceType3
|
|
33291
34009
|
} from "@univerjs/core";
|
|
33292
34010
|
import { BehaviorSubject as BehaviorSubject4, Subject as Subject2 } from "rxjs";
|
|
33293
34011
|
var DOC_IO_CAPABILITY_FORMATS = [
|
|
@@ -33311,6 +34029,47 @@ var DocIoTargetError = class extends Error {
|
|
|
33311
34029
|
}
|
|
33312
34030
|
};
|
|
33313
34031
|
var IDocIoService = createIdentifier5("yudao.univer-docs.io.service");
|
|
34032
|
+
function createDocAbortError(signal) {
|
|
34033
|
+
const reason = signal?.reason;
|
|
34034
|
+
if (reason instanceof Error && reason.name === "AbortError") {
|
|
34035
|
+
return reason;
|
|
34036
|
+
}
|
|
34037
|
+
if (typeof DOMException !== "undefined") {
|
|
34038
|
+
return new DOMException("The operation was aborted.", "AbortError");
|
|
34039
|
+
}
|
|
34040
|
+
const err = new Error("The operation was aborted.");
|
|
34041
|
+
err.name = "AbortError";
|
|
34042
|
+
return err;
|
|
34043
|
+
}
|
|
34044
|
+
function throwIfDocIoAborted(signal) {
|
|
34045
|
+
if (signal?.aborted) {
|
|
34046
|
+
throw createDocAbortError(signal);
|
|
34047
|
+
}
|
|
34048
|
+
}
|
|
34049
|
+
async function runWithAbortSignal(executor, signal) {
|
|
34050
|
+
throwIfDocIoAborted(signal);
|
|
34051
|
+
if (!signal) {
|
|
34052
|
+
return executor();
|
|
34053
|
+
}
|
|
34054
|
+
let onAbort;
|
|
34055
|
+
const abortPromise = new Promise((_, reject) => {
|
|
34056
|
+
onAbort = () => reject(createDocAbortError(signal));
|
|
34057
|
+
if (signal.aborted) {
|
|
34058
|
+
onAbort();
|
|
34059
|
+
return;
|
|
34060
|
+
}
|
|
34061
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
34062
|
+
});
|
|
34063
|
+
try {
|
|
34064
|
+
const result = await Promise.race([executor(), abortPromise]);
|
|
34065
|
+
throwIfDocIoAborted(signal);
|
|
34066
|
+
return result;
|
|
34067
|
+
} finally {
|
|
34068
|
+
if (onAbort) {
|
|
34069
|
+
signal.removeEventListener("abort", onAbort);
|
|
34070
|
+
}
|
|
34071
|
+
}
|
|
34072
|
+
}
|
|
33314
34073
|
async function normalizeToUint8Array(raw) {
|
|
33315
34074
|
if (raw instanceof Uint8Array) return raw;
|
|
33316
34075
|
if (raw instanceof ArrayBuffer) return new Uint8Array(raw);
|
|
@@ -33384,8 +34143,9 @@ function unwrapAdapterImportResult(rawResult) {
|
|
|
33384
34143
|
return { documentData: doc, warnings };
|
|
33385
34144
|
}
|
|
33386
34145
|
var DocIoService = class extends Disposable5 {
|
|
33387
|
-
constructor() {
|
|
34146
|
+
constructor(_univerInstanceService) {
|
|
33388
34147
|
super();
|
|
34148
|
+
this._univerInstanceService = _univerInstanceService;
|
|
33389
34149
|
this._adapter$ = new BehaviorSubject4({ name: "frontend-default" });
|
|
33390
34150
|
this._saved$ = new Subject2();
|
|
33391
34151
|
this._nextHookId = 1;
|
|
@@ -33506,8 +34266,11 @@ var DocIoService = class extends Disposable5 {
|
|
|
33506
34266
|
return hasHook ? "server" : "browser";
|
|
33507
34267
|
}
|
|
33508
34268
|
async importDocWithReport(file, options) {
|
|
34269
|
+
const signal = options?.signal;
|
|
34270
|
+
throwIfDocIoAborted(signal);
|
|
33509
34271
|
let browserWarnings = [];
|
|
33510
34272
|
const defaultImport = async (f) => {
|
|
34273
|
+
throwIfDocIoAborted(signal);
|
|
33511
34274
|
const lower = f.name.toLowerCase();
|
|
33512
34275
|
const fmtKey2 = inferFormatFromFileName(f.name);
|
|
33513
34276
|
const caps = this.getIoCapabilities();
|
|
@@ -33517,15 +34280,19 @@ var DocIoService = class extends Disposable5 {
|
|
|
33517
34280
|
const baseTitle = f.name.replace(/\.[^.]+$/, "") || "\u672A\u547D\u540D\u6587\u6863";
|
|
33518
34281
|
if (lower.endsWith(".docx")) {
|
|
33519
34282
|
const ab = await f.arrayBuffer();
|
|
34283
|
+
throwIfDocIoAborted(signal);
|
|
33520
34284
|
const report = await parseDocxBytesWithReport(new Uint8Array(ab), baseTitle);
|
|
34285
|
+
throwIfDocIoAborted(signal);
|
|
33521
34286
|
browserWarnings = report.warnings;
|
|
33522
34287
|
return report.documentData;
|
|
33523
34288
|
}
|
|
33524
34289
|
if (lower.endsWith(".rtf") || lower.endsWith(".odt") || lower.endsWith(".doc") || lower.endsWith(".xml")) {
|
|
33525
34290
|
const ab = await f.arrayBuffer();
|
|
34291
|
+
throwIfDocIoAborted(signal);
|
|
33526
34292
|
return importLegacyDocBytes(new Uint8Array(ab), baseTitle);
|
|
33527
34293
|
}
|
|
33528
34294
|
const text = await f.text();
|
|
34295
|
+
throwIfDocIoAborted(signal);
|
|
33529
34296
|
if (lower.endsWith(".json")) {
|
|
33530
34297
|
return JSON.parse(text);
|
|
33531
34298
|
}
|
|
@@ -33551,10 +34318,14 @@ var DocIoService = class extends Disposable5 {
|
|
|
33551
34318
|
);
|
|
33552
34319
|
}
|
|
33553
34320
|
try {
|
|
33554
|
-
const rawOutcome = await
|
|
33555
|
-
|
|
33556
|
-
|
|
33557
|
-
|
|
34321
|
+
const rawOutcome = await runWithAbortSignal(
|
|
34322
|
+
() => adapter.importDoc(file, {
|
|
34323
|
+
unitId: options?.unitId,
|
|
34324
|
+
signal,
|
|
34325
|
+
defaultImport
|
|
34326
|
+
}),
|
|
34327
|
+
signal
|
|
34328
|
+
);
|
|
33558
34329
|
const unwrapped = unwrapAdapterImportResult(rawOutcome);
|
|
33559
34330
|
return {
|
|
33560
34331
|
snapshot: unwrapped.documentData,
|
|
@@ -33564,6 +34335,9 @@ var DocIoService = class extends Disposable5 {
|
|
|
33564
34335
|
fileName: file.name
|
|
33565
34336
|
};
|
|
33566
34337
|
} catch (err) {
|
|
34338
|
+
if (err?.name === "AbortError") {
|
|
34339
|
+
throw err;
|
|
34340
|
+
}
|
|
33567
34341
|
if (err && typeof err === "object" && !err.suggestedFallback) {
|
|
33568
34342
|
err.suggestedFallback = "browser";
|
|
33569
34343
|
}
|
|
@@ -33571,7 +34345,7 @@ var DocIoService = class extends Disposable5 {
|
|
|
33571
34345
|
}
|
|
33572
34346
|
}
|
|
33573
34347
|
try {
|
|
33574
|
-
const documentData = await defaultImport(file);
|
|
34348
|
+
const documentData = await runWithAbortSignal(() => defaultImport(file), signal);
|
|
33575
34349
|
return {
|
|
33576
34350
|
snapshot: documentData,
|
|
33577
34351
|
documentData,
|
|
@@ -33580,6 +34354,9 @@ var DocIoService = class extends Disposable5 {
|
|
|
33580
34354
|
fileName: file.name
|
|
33581
34355
|
};
|
|
33582
34356
|
} catch (err) {
|
|
34357
|
+
if (err?.name === "AbortError") {
|
|
34358
|
+
throw err;
|
|
34359
|
+
}
|
|
33583
34360
|
if (err && typeof err === "object") {
|
|
33584
34361
|
err.suggestedFallback = "server";
|
|
33585
34362
|
}
|
|
@@ -33587,12 +34364,19 @@ var DocIoService = class extends Disposable5 {
|
|
|
33587
34364
|
}
|
|
33588
34365
|
}
|
|
33589
34366
|
async importDoc(file, unitId, options) {
|
|
33590
|
-
const res = await this.importDocWithReport(file, {
|
|
34367
|
+
const res = await this.importDocWithReport(file, {
|
|
34368
|
+
unitId,
|
|
34369
|
+
target: options?.target,
|
|
34370
|
+
signal: options?.signal
|
|
34371
|
+
});
|
|
33591
34372
|
return res.documentData;
|
|
33592
34373
|
}
|
|
33593
34374
|
async exportDoc(params) {
|
|
34375
|
+
const signal = params.signal;
|
|
34376
|
+
throwIfDocIoAborted(signal);
|
|
33594
34377
|
const format = params.format ?? "docx";
|
|
33595
34378
|
const defaultExport = async () => {
|
|
34379
|
+
throwIfDocIoAborted(signal);
|
|
33596
34380
|
const caps = this.getIoCapabilities();
|
|
33597
34381
|
if (format in caps.formats.export && !caps.formats.export[format].browser) {
|
|
33598
34382
|
throw new Error(`\u5F53\u524D\u6D4F\u89C8\u5668\u672C\u5730\u5F15\u64CE\u672A\u542F\u7528 .${format} \u683C\u5F0F\u5BFC\u51FA`);
|
|
@@ -33679,16 +34463,25 @@ var DocIoService = class extends Disposable5 {
|
|
|
33679
34463
|
);
|
|
33680
34464
|
}
|
|
33681
34465
|
try {
|
|
33682
|
-
const raw = await
|
|
33683
|
-
|
|
33684
|
-
|
|
33685
|
-
|
|
33686
|
-
|
|
33687
|
-
|
|
33688
|
-
|
|
33689
|
-
|
|
33690
|
-
|
|
34466
|
+
const raw = await runWithAbortSignal(
|
|
34467
|
+
() => adapter.exportDoc({
|
|
34468
|
+
unitId: params.unitId,
|
|
34469
|
+
snapshot: params.snapshot,
|
|
34470
|
+
format,
|
|
34471
|
+
data: params.data,
|
|
34472
|
+
pdfOptions: params.pdfOptions,
|
|
34473
|
+
signal,
|
|
34474
|
+
defaultExport
|
|
34475
|
+
}),
|
|
34476
|
+
signal
|
|
34477
|
+
);
|
|
34478
|
+
const bytes = await normalizeToUint8Array(raw);
|
|
34479
|
+
throwIfDocIoAborted(signal);
|
|
34480
|
+
return bytes;
|
|
33691
34481
|
} catch (err) {
|
|
34482
|
+
if (err?.name === "AbortError") {
|
|
34483
|
+
throw err;
|
|
34484
|
+
}
|
|
33692
34485
|
if (err && typeof err === "object" && !err.suggestedFallback) {
|
|
33693
34486
|
err.suggestedFallback = "browser";
|
|
33694
34487
|
}
|
|
@@ -33696,14 +34489,49 @@ var DocIoService = class extends Disposable5 {
|
|
|
33696
34489
|
}
|
|
33697
34490
|
}
|
|
33698
34491
|
try {
|
|
33699
|
-
return await defaultExport();
|
|
34492
|
+
return await runWithAbortSignal(() => defaultExport(), signal);
|
|
33700
34493
|
} catch (err) {
|
|
34494
|
+
if (err?.name === "AbortError") {
|
|
34495
|
+
throw err;
|
|
34496
|
+
}
|
|
33701
34497
|
if (err && typeof err === "object") {
|
|
33702
34498
|
err.suggestedFallback = "server";
|
|
33703
34499
|
}
|
|
33704
34500
|
throw err;
|
|
33705
34501
|
}
|
|
33706
34502
|
}
|
|
34503
|
+
async exportDocFromUnit(unitIdOrParams, options) {
|
|
34504
|
+
const normalized = typeof unitIdOrParams === "string" || unitIdOrParams === void 0 ? { ...options ?? {}, ...unitIdOrParams !== void 0 ? { unitId: unitIdOrParams } : {} } : unitIdOrParams;
|
|
34505
|
+
throwIfDocIoAborted(normalized.signal);
|
|
34506
|
+
let resolvedSnapshot = normalized.snapshot;
|
|
34507
|
+
let resolvedUnitId = normalized.unitId || "";
|
|
34508
|
+
if (!resolvedSnapshot && this._univerInstanceService) {
|
|
34509
|
+
const docModel = normalized.unitId ? this._univerInstanceService.getUnit(
|
|
34510
|
+
normalized.unitId,
|
|
34511
|
+
UniverInstanceType3.UNIVER_DOC
|
|
34512
|
+
) : this._univerInstanceService.getCurrentUnitOfType(
|
|
34513
|
+
UniverInstanceType3.UNIVER_DOC
|
|
34514
|
+
);
|
|
34515
|
+
if (docModel) {
|
|
34516
|
+
resolvedUnitId = docModel.getUnitId();
|
|
34517
|
+
resolvedSnapshot = docModel.getSnapshot();
|
|
34518
|
+
}
|
|
34519
|
+
}
|
|
34520
|
+
if (!resolvedSnapshot) {
|
|
34521
|
+
throw new Error(
|
|
34522
|
+
`\u65E0\u6CD5\u5BFC\u51FA\u6587\u6863\uFF1A\u672A\u627E\u5230\u6587\u6863\u5B9E\u4F8B${resolvedUnitId ? ` (${resolvedUnitId})` : ""}`
|
|
34523
|
+
);
|
|
34524
|
+
}
|
|
34525
|
+
return this.exportDoc({
|
|
34526
|
+
unitId: resolvedUnitId || resolvedSnapshot.id || "doc",
|
|
34527
|
+
snapshot: resolvedSnapshot,
|
|
34528
|
+
format: normalized.format,
|
|
34529
|
+
data: normalized.data,
|
|
34530
|
+
pdfOptions: normalized.pdfOptions,
|
|
34531
|
+
target: normalized.target,
|
|
34532
|
+
signal: normalized.signal
|
|
34533
|
+
});
|
|
34534
|
+
}
|
|
33707
34535
|
async saveToHost(context) {
|
|
33708
34536
|
let canceled = false;
|
|
33709
34537
|
const beforeEv = {
|
|
@@ -33742,6 +34570,9 @@ var DocIoService = class extends Disposable5 {
|
|
|
33742
34570
|
return true;
|
|
33743
34571
|
}
|
|
33744
34572
|
};
|
|
34573
|
+
DocIoService = __decorateClass([
|
|
34574
|
+
__decorateParam(0, Optional(IUniverInstanceService3))
|
|
34575
|
+
], DocIoService);
|
|
33745
34576
|
|
|
33746
34577
|
// src/plugin.ts
|
|
33747
34578
|
var VIEW_MODE_BLOCKED_PREFIXES = [
|
|
@@ -33836,7 +34667,7 @@ var UniverDocsExtPlugin = class extends Plugin {
|
|
|
33836
34667
|
const sdtService = this._injector.get(IDocSdtService);
|
|
33837
34668
|
const initialMode = this._config.mode ?? "design";
|
|
33838
34669
|
sdtService.setDefaultMode(initialMode);
|
|
33839
|
-
const unitSub = this._univerInstanceService.getCurrentTypeOfUnit$(
|
|
34670
|
+
const unitSub = this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType4.UNIVER_DOC).subscribe((unit) => {
|
|
33840
34671
|
if (!unit) return;
|
|
33841
34672
|
const unitId = unit.getUnitId();
|
|
33842
34673
|
if (sdtService.getDocMode(unitId) === "view") {
|
|
@@ -33856,7 +34687,7 @@ var UniverDocsExtPlugin = class extends Plugin {
|
|
|
33856
34687
|
if (commandInfo.id === SetDocModeCommand.id) return;
|
|
33857
34688
|
if (commandInfo.id === ReplaceDocUnitSnapshotCommand.id) {
|
|
33858
34689
|
if (params.allowInViewMode) return;
|
|
33859
|
-
const targetUnit = params.unitId || this._univerInstanceService.getCurrentUnitOfType(
|
|
34690
|
+
const targetUnit = params.unitId || this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType4.UNIVER_DOC)?.getUnitId();
|
|
33860
34691
|
if (targetUnit && sdtService.getDocMode(targetUnit) === "view") {
|
|
33861
34692
|
throw new CanceledError();
|
|
33862
34693
|
}
|
|
@@ -33864,7 +34695,7 @@ var UniverDocsExtPlugin = class extends Plugin {
|
|
|
33864
34695
|
}
|
|
33865
34696
|
const isBlockedCmd = VIEW_MODE_BLOCKED_IDS.has(commandInfo.id) || VIEW_MODE_BLOCKED_PREFIXES.some((prefix) => commandInfo.id.startsWith(prefix));
|
|
33866
34697
|
if (!isBlockedCmd) return;
|
|
33867
|
-
const targetUnitId = params.unitId || this._univerInstanceService.getCurrentUnitOfType(
|
|
34698
|
+
const targetUnitId = params.unitId || this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType4.UNIVER_DOC)?.getUnitId();
|
|
33868
34699
|
if (targetUnitId && sdtService.getDocMode(targetUnitId) === "view") {
|
|
33869
34700
|
throw new CanceledError();
|
|
33870
34701
|
}
|
|
@@ -33872,7 +34703,7 @@ var UniverDocsExtPlugin = class extends Plugin {
|
|
|
33872
34703
|
try {
|
|
33873
34704
|
const docUnit = this._univerInstanceService.getUnit(
|
|
33874
34705
|
targetUnitId,
|
|
33875
|
-
|
|
34706
|
+
UniverInstanceType4.UNIVER_DOC
|
|
33876
34707
|
);
|
|
33877
34708
|
const selService = this._injector.get(DocSelectionManagerService4);
|
|
33878
34709
|
const activeRange = selService.getActiveTextRange() ?? selService.getTextRanges({ unitId: targetUnitId, subUnitId: targetUnitId })?.[0];
|
|
@@ -33955,7 +34786,7 @@ var UniverDocsExtPlugin = class extends Plugin {
|
|
|
33955
34786
|
}
|
|
33956
34787
|
if (commandInfo.id !== UndoCommand2.id && commandInfo.id !== RedoCommand2.id) return;
|
|
33957
34788
|
const unit = this._univerInstanceService.getCurrentUnitOfType(
|
|
33958
|
-
|
|
34789
|
+
UniverInstanceType4.UNIVER_DOC
|
|
33959
34790
|
);
|
|
33960
34791
|
if (!unit) return;
|
|
33961
34792
|
const unitId = unit.getUnitId();
|
|
@@ -33970,7 +34801,7 @@ var UniverDocsExtPlugin = class extends Plugin {
|
|
|
33970
34801
|
};
|
|
33971
34802
|
UniverDocsExtPlugin = __decorateClass([
|
|
33972
34803
|
__decorateParam(1, Inject(Injector)),
|
|
33973
|
-
__decorateParam(2,
|
|
34804
|
+
__decorateParam(2, IUniverInstanceService4),
|
|
33974
34805
|
__decorateParam(3, ICommandService5)
|
|
33975
34806
|
], UniverDocsExtPlugin);
|
|
33976
34807
|
export {
|
|
@@ -34010,6 +34841,7 @@ export {
|
|
|
34010
34841
|
DocIoService,
|
|
34011
34842
|
DocIoTargetError,
|
|
34012
34843
|
DocSdtService,
|
|
34844
|
+
DocTemplateProtocolError,
|
|
34013
34845
|
DocxImportError,
|
|
34014
34846
|
EvaluateDocCascadeRulesCommand,
|
|
34015
34847
|
EvaluateDocTableFormulasCommand,
|
|
@@ -34021,6 +34853,7 @@ export {
|
|
|
34021
34853
|
IDocExtensionRegistryService,
|
|
34022
34854
|
IDocIoService,
|
|
34023
34855
|
IDocSdtService,
|
|
34856
|
+
INLINE_VALUE_TOKEN_RE,
|
|
34024
34857
|
InsertDocAreaCommand,
|
|
34025
34858
|
InsertDocBibliographyCommand,
|
|
34026
34859
|
InsertDocBookmarkCommand,
|
|
@@ -34167,6 +35000,7 @@ export {
|
|
|
34167
35000
|
computeToggledMultiOptionValue,
|
|
34168
35001
|
convertDocTableToText,
|
|
34169
35002
|
convertTextToDocTableInSnapshot,
|
|
35003
|
+
createDocAbortError,
|
|
34170
35004
|
decodeImageDataUrlForPdf,
|
|
34171
35005
|
deleteColumnGroupFromSnapshot,
|
|
34172
35006
|
deleteDocAreaFromSnapshot as deleteDocArea,
|
|
@@ -34208,7 +35042,10 @@ export {
|
|
|
34208
35042
|
extractAnchorTypography,
|
|
34209
35043
|
extractDocCatalog,
|
|
34210
35044
|
extractDocCatalogTree,
|
|
35045
|
+
extractDocFieldInstruction,
|
|
34211
35046
|
extractDocFormValues,
|
|
35047
|
+
extractDocInlinePlaceholders,
|
|
35048
|
+
extractNativeTextSpansFromPdfBytes,
|
|
34212
35049
|
fillDatasetIntoDocSnapshot,
|
|
34213
35050
|
findAndReplaceDocTextInSnapshot,
|
|
34214
35051
|
findMergedMasterInTableRows,
|
|
@@ -34300,6 +35137,7 @@ export {
|
|
|
34300
35137
|
insertSyntaxCodeBlockIntoSnapshot,
|
|
34301
35138
|
insertTableOfContentsIntoSnapshot,
|
|
34302
35139
|
inspectDocxExportCapabilities,
|
|
35140
|
+
isDynamicPageFieldInstruction,
|
|
34303
35141
|
isEditBlockedByTitleLock,
|
|
34304
35142
|
isOffsetInLockedTableCell,
|
|
34305
35143
|
isOffsetLockedByGroupSdt,
|
|
@@ -34330,6 +35168,7 @@ export {
|
|
|
34330
35168
|
normalizeSdtListItems,
|
|
34331
35169
|
numberToChineseUpperMoney,
|
|
34332
35170
|
parseDateRangePair,
|
|
35171
|
+
parseDocBindingKey,
|
|
34333
35172
|
parseDocxBytesToDocData,
|
|
34334
35173
|
parseDocxBytesWithReport,
|
|
34335
35174
|
parseFieldInstrString,
|
|
@@ -34423,6 +35262,7 @@ export {
|
|
|
34423
35262
|
splitDocTableCellInSnapshot,
|
|
34424
35263
|
stripDocEditorChromeForView,
|
|
34425
35264
|
stripSdtAffixes,
|
|
35265
|
+
summarizeDocTemplate,
|
|
34426
35266
|
syncDocDrawingsToUniverServices,
|
|
34427
35267
|
syncSnapshotAuxFields,
|
|
34428
35268
|
toControlSpecSnapshot,
|