@stll/folio-core 0.67.0 → 0.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-edits/apply.d.ts +9 -1
- package/dist/ai-edits/apply.js +94 -8
- package/dist/ai-edits/headless.d.ts +36 -21
- package/dist/ai-edits/headless.js +104 -34
- package/dist/ai-edits/index.d.ts +2 -2
- package/dist/ai-edits/note-references.d.ts +6 -0
- package/dist/ai-edits/note-references.js +7 -1
- package/dist/ai-edits/read.d.ts +19 -0
- package/dist/ai-edits/snapshot.d.ts +6 -0
- package/dist/ai-edits/snapshot.js +8 -3
- package/dist/ai-edits/types.d.ts +9 -1
- package/dist/ai-suggestions/apply.js +13 -4
- package/dist/compare/compare.js +2 -1
- package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
- package/dist/compare/inserted-resource-snapshot.js +7 -3
- package/dist/controller/canonicalClipboard.js +29 -12
- package/dist/controller/canonicalComposition.js +1 -1
- package/dist/controller/canonicalInlineProjection.d.ts +35 -10
- package/dist/controller/canonicalInlineProjection.js +192 -28
- package/dist/controller/canonicalInput.d.ts +2 -1
- package/dist/controller/canonicalInput.js +28 -1
- package/dist/controller/canonicalListRendering.d.ts +2 -1
- package/dist/controller/canonicalListRendering.js +1 -1
- package/dist/controller/canonicalLockGuard.d.ts +8 -0
- package/dist/controller/canonicalLockGuard.js +88 -0
- package/dist/controller/canonicalPublicOperations.d.ts +12 -4
- package/dist/controller/canonicalPublicOperations.js +274 -20
- package/dist/controller/canonicalSession.d.ts +87 -7
- package/dist/controller/canonicalSession.js +327 -73
- package/dist/controller/canonicalStoryEditor.d.ts +3 -2
- package/dist/controller/canonicalStoryEditor.js +4 -3
- package/dist/controller/canonicalStructure.d.ts +2 -1
- package/dist/controller/canonicalStructure.js +129 -7
- package/dist/controller/contentControlWidgetController.d.ts +5 -0
- package/dist/controller/contentControlWidgetController.js +13 -1
- package/dist/controller/folioEditor.js +1 -0
- package/dist/controller/headerFooterEditorManager.d.ts +2 -2
- package/dist/controller/headerFooterEditorManager.js +5 -5
- package/dist/controller/hiddenEditorApi.d.ts +6 -0
- package/dist/controller/hiddenEditorApi.js +1 -0
- package/dist/controller/hiddenEditorManager.d.ts +4 -3
- package/dist/controller/hiddenEditorManager.js +91 -37
- package/dist/controller/layoutPipeline.js +48 -15
- package/dist/controller/noteEditorManager.d.ts +2 -2
- package/dist/controller/noteEditorManager.js +5 -5
- package/dist/display-list/build/pageFurniture.js +41 -19
- package/dist/display-list/build/tablePrimitives.js +23 -4
- package/dist/display-list/dom/renderDisplayListToDom.js +4 -4
- package/dist/document-operations.d.ts +8 -0
- package/dist/document-operations.js +4 -3
- package/dist/docx/blockContentParser.d.ts +7 -3
- package/dist/docx/blockContentParser.js +2 -3
- package/dist/docx/blockPlainText.js +2 -0
- package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
- package/dist/docx/bookmarkRangeJoin.js +43 -0
- package/dist/docx/canonicalSave.js +5 -1
- package/dist/docx/canonicalSessionInput.d.ts +5 -1
- package/dist/docx/canonicalSessionInput.js +7 -2
- package/dist/docx/commentAnchorIndex.d.ts +21 -5
- package/dist/docx/commentAnchorIndex.js +39 -11
- package/dist/docx/commentRangeIntegrity.js +30 -24
- package/dist/docx/commentRangeJoin.d.ts +4 -0
- package/dist/docx/commentRangeJoin.js +26 -12
- package/dist/docx/commentReferenceCompletion.js +5 -4
- package/dist/docx/commentReferenceNormalization.js +40 -18
- package/dist/docx/compatibility.js +9 -2
- package/dist/docx/containerChildren.js +22 -1
- package/dist/docx/encryption/compoundFile.js +9 -1
- package/dist/docx/encryption/encryptionInfo.js +16 -2
- package/dist/docx/ensureParaIds.js +46 -7
- package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
- package/dist/docx/ensureUniqueControlIds.js +110 -0
- package/dist/docx/headerFooterVerbatim.d.ts +7 -0
- package/dist/docx/headerFooterVerbatim.js +13 -2
- package/dist/docx/hostCommentThreads.d.ts +17 -0
- package/dist/docx/hostCommentThreads.js +49 -0
- package/dist/docx/hyperlinkParser.js +9 -2
- package/dist/docx/inlineWrapperContent.d.ts +8 -1
- package/dist/docx/inlineWrapperContent.js +9 -2
- package/dist/docx/listMarkerComputation.d.ts +35 -1
- package/dist/docx/listMarkerComputation.js +39 -1
- package/dist/docx/listModelNormalization.d.ts +44 -1
- package/dist/docx/listModelNormalization.js +227 -96
- package/dist/docx/markupRangeMarker.d.ts +14 -0
- package/dist/docx/markupRangeMarker.js +15 -1
- package/dist/docx/metadataPrivacy.js +43 -22
- package/dist/docx/normalizeBaseDirection.js +3 -1
- package/dist/docx/paragraphParser.js +159 -48
- package/dist/docx/paragraphPropertySource.d.ts +7 -0
- package/dist/docx/paragraphPropertySource.js +22 -1
- package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
- package/dist/docx/paragraphTraversal.js +2 -0
- package/dist/docx/parseWarningMessage.js +2 -1
- package/dist/docx/parser.js +6 -0
- package/dist/docx/renderedPageBreakNormalization.js +1 -1
- package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
- package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
- package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
- package/dist/docx/reviewResolutionProvenance.js +110 -25
- package/dist/docx/rezip.d.ts +6 -0
- package/dist/docx/rezip.js +38 -21
- package/dist/docx/selectiveSave.js +6 -10
- package/dist/docx/selectiveXmlPatch.d.ts +5 -4
- package/dist/docx/selectiveXmlPatch.js +11 -7
- package/dist/docx/serializer/documentSerializer.js +3 -1
- package/dist/docx/serializer/headerFooterSerializer.js +3 -1
- package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
- package/dist/docx/serializer/markupRangeAttributes.js +6 -1
- package/dist/docx/serializer/noteSerializer.d.ts +17 -4
- package/dist/docx/serializer/noteSerializer.js +23 -16
- package/dist/docx/serializer/paragraphSerializer.js +56 -12
- package/dist/docx/serializer/runSerializer.d.ts +1 -3
- package/dist/docx/serializer/runSerializer.js +2 -2
- package/dist/docx/serializer/tableSerializer.d.ts +4 -0
- package/dist/docx/serializer/tableSerializer.js +4 -2
- package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
- package/dist/docx/server/createBilingualDocument.js +27 -5
- package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
- package/dist/docx/sessionListPruning.d.ts +2 -0
- package/dist/docx/sessionListPruning.js +50 -0
- package/dist/docx/splitRevisionPieces.d.ts +10 -0
- package/dist/docx/splitRevisionPieces.js +14 -0
- package/dist/docx/storyBlockReplay.js +4 -0
- package/dist/docx/structuralXmlPatch.js +19 -7
- package/dist/docx/tableParser.d.ts +6 -2
- package/dist/docx/tableParser.js +2 -3
- package/dist/docx/textBoxContentParser.d.ts +11 -0
- package/dist/docx/textBoxContentParser.js +51 -0
- package/dist/docx/textBoxParser.d.ts +0 -5
- package/dist/docx/textBoxParser.js +1 -23
- package/dist/docx/verticalMergeProjection.js +1 -1
- package/dist/fonts/fontsourceFaces.d.ts +2 -8
- package/dist/fonts/fontsourceFaces.js +1 -7
- package/dist/i18n/messages/ar.gen.js +2 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +34 -0
- package/dist/i18n/messages/catalogs.gen.js +34 -0
- package/dist/i18n/messages/cs.gen.js +2 -0
- package/dist/i18n/messages/de.gen.js +2 -0
- package/dist/i18n/messages/en.gen.js +2 -0
- package/dist/i18n/messages/es.gen.js +2 -0
- package/dist/i18n/messages/et.gen.js +2 -0
- package/dist/i18n/messages/fr.gen.js +2 -0
- package/dist/i18n/messages/he.gen.js +2 -0
- package/dist/i18n/messages/hi.gen.js +2 -0
- package/dist/i18n/messages/hu.gen.js +2 -0
- package/dist/i18n/messages/lt.gen.js +2 -0
- package/dist/i18n/messages/lv.gen.js +2 -0
- package/dist/i18n/messages/messages.gen.d.ts +2 -0
- package/dist/i18n/messages/pl.gen.js +2 -0
- package/dist/i18n/messages/pt-BR.gen.js +2 -0
- package/dist/i18n/messages/sk.gen.js +2 -0
- package/dist/i18n/messages/tr.gen.js +2 -0
- package/dist/i18n/messages/zh-CN.gen.js +2 -0
- package/dist/internal/acceptedBlockProjection.js +2 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
- package/dist/internal/revisionResolutionInline.js +1 -2
- package/dist/layout-bridge/convert/tableConversion.js +19 -8
- package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
- package/dist/layout-bridge/engine/blockIndex.js +12 -0
- package/dist/layout-bridge/engine/hitTest.js +9 -10
- package/dist/layout-bridge/engine/selectionRects.js +6 -6
- package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
- package/dist/layout-engine/footnoteContinuation.js +210 -0
- package/dist/layout-engine/index.d.ts +2 -2
- package/dist/layout-engine/index.js +7 -2
- package/dist/layout-engine/measure/cache.js +10 -5
- package/dist/layout-engine/measure/measureParagraph.js +1 -1
- package/dist/layout-engine/tableLayout.js +29 -5
- package/dist/layout-engine/tableRowBreak.d.ts +36 -0
- package/dist/layout-engine/tableRowBreak.js +43 -1
- package/dist/layout-engine/types.d.ts +36 -1
- package/dist/layout-painter/renderPage.d.ts +4 -4
- package/dist/layout-painter/renderPage.js +46 -17
- package/dist/layout-painter/renderTable.js +7 -4
- package/dist/managers/AutoSaveManager.d.ts +5 -1
- package/dist/managers/FindReplaceManager.js +3 -10
- package/dist/markdown/escape.d.ts +20 -1
- package/dist/markdown/escape.js +43 -1
- package/dist/markdown/renderBlock.js +4 -1
- package/dist/markdown/renderParagraph.js +13 -27
- package/dist/markdown/renderTable.js +6 -2
- package/dist/markdown/trailers.js +1 -0
- package/dist/pdf/images.d.ts +17 -1
- package/dist/pdf/images.js +22 -4
- package/dist/pdf/writePdf.js +4 -2
- package/dist/prosemirror/attrs/index.js +1 -0
- package/dist/prosemirror/canonicalCommands.d.ts +39 -1
- package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
- package/dist/prosemirror/canonicalTableCommands.js +362 -0
- package/dist/prosemirror/commands/comments.d.ts +25 -0
- package/dist/prosemirror/commands/comments.js +102 -11
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/index.d.ts +1 -1
- package/dist/prosemirror/commentIdAllocator.js +2 -2
- package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
- package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
- package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +76 -31
- package/dist/prosemirror/conversion/index.d.ts +1 -1
- package/dist/prosemirror/conversion/toProseDoc.d.ts +128 -1
- package/dist/prosemirror/conversion/toProseDoc.js +319 -51
- package/dist/prosemirror/extensions/StarterKit.js +2 -0
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
- package/dist/prosemirror/extensions/marks/CommentExtension.js +6 -3
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
- package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
- package/dist/prosemirror/index.d.ts +2 -2
- package/dist/prosemirror/listLabels.js +3 -2
- package/dist/prosemirror/listNumbering.d.ts +6 -0
- package/dist/prosemirror/listNumbering.js +12 -9
- package/dist/prosemirror/lockedControls.d.ts +13 -0
- package/dist/prosemirror/lockedControls.js +106 -0
- package/dist/prosemirror/markupViewProjection.js +1 -1
- package/dist/prosemirror/noteReferenceReview.js +2 -2
- package/dist/prosemirror/plugins/documentNumbering.js +4 -1
- package/dist/prosemirror/plugins/suggestionMode.js +20 -9
- package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
- package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
- package/dist/prosemirror/replacedAnnotations.js +1 -0
- package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
- package/dist/prosemirror/runFormattingFromMarks.js +2 -4
- package/dist/prosemirror/runFormattingReconciliation.js +2 -2
- package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
- package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
- package/dist/prosemirror/runStyleFormatting.js +16 -13
- package/dist/prosemirror/schema/marks.d.ts +6 -0
- package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
- package/dist/prosemirror/validation.js +1 -0
- package/dist/redline.js +23 -9
- package/dist/server.d.ts +2 -2
- package/dist/style-sets/extract.js +2 -2
- package/dist/types/canonicalCapabilities.d.ts +29 -8
- package/dist/types/canonicalCapabilities.js +13 -9
- package/dist/utils/cssString.d.ts +7 -0
- package/dist/utils/cssString.js +9 -0
- package/dist/utils/fontResolver.js +4 -1
- package/dist/utils/replaceText.d.ts +11 -0
- package/dist/utils/replaceText.js +39 -7
- package/dist/version-comparison.d.ts +9 -1
- package/dist/version-comparison.js +11 -5
- package/package.json +2 -2
|
@@ -36,7 +36,7 @@ const strokeFor = (border, context, label) => {
|
|
|
36
36
|
if (unresolvedColor !== void 0) context.unsupported.report(UNSUPPORTED_CONSTRUCT.unresolvedColor, context.pageIndex, `${label} colour ${unresolvedColor}`);
|
|
37
37
|
return stroke;
|
|
38
38
|
};
|
|
39
|
-
const paintCell = ({ composer, cell, cellMeasure, box, context, paintTextBox, visibleBand, sides }) => {
|
|
39
|
+
const paintCell = ({ composer, cell, cellMeasure, box, context, paintTextBox, visibleBand, contentBandPx, sides }) => {
|
|
40
40
|
const primitives = [];
|
|
41
41
|
if (cell.background) {
|
|
42
42
|
const fill = parseDisplayColor(cell.background);
|
|
@@ -111,8 +111,9 @@ const paintCell = ({ composer, cell, cellMeasure, box, context, paintTextBox, vi
|
|
|
111
111
|
if (cellTextRotationDegrees(cell.textDirection) !== 0) context.unsupported.report(UNSUPPORTED_CONSTRUCT.verticalCellText, context.pageIndex, `w:textDirection ${cell.textDirection} paints horizontally`);
|
|
112
112
|
composer.push(primitives);
|
|
113
113
|
primitives.length = 0;
|
|
114
|
+
const contentComposer = contentBandPx ? createPageComposer() : composer;
|
|
114
115
|
paintCellBlocks({
|
|
115
|
-
composer,
|
|
116
|
+
composer: contentComposer,
|
|
116
117
|
blocks: cell.blocks,
|
|
117
118
|
measures: cellMeasure.blocks,
|
|
118
119
|
xPx: contentXPx,
|
|
@@ -123,6 +124,17 @@ const paintCell = ({ composer, cell, cellMeasure, box, context, paintTextBox, vi
|
|
|
123
124
|
paintTextBox,
|
|
124
125
|
visibleBand
|
|
125
126
|
});
|
|
127
|
+
if (contentBandPx) composer.push([{
|
|
128
|
+
kind: "clipGroup",
|
|
129
|
+
rect: {
|
|
130
|
+
xPx: box.xPx,
|
|
131
|
+
yPx: contentBandPx.top,
|
|
132
|
+
widthPx: box.widthPx,
|
|
133
|
+
heightPx: Math.max(0, contentBandPx.bottom - contentBandPx.top)
|
|
134
|
+
},
|
|
135
|
+
children: [...contentComposer.primitives()],
|
|
136
|
+
regions: [...contentComposer.regions()]
|
|
137
|
+
}]);
|
|
126
138
|
const diagonals = [{
|
|
127
139
|
border: borders?.topLeftToBottomRight,
|
|
128
140
|
from: "topLeft"
|
|
@@ -265,7 +277,7 @@ const paintCellBlocks = ({ composer, blocks, measures, xPx, yPx, widthPx, inline
|
|
|
265
277
|
}
|
|
266
278
|
};
|
|
267
279
|
const rowIsPainted = (row) => row !== void 0 && row.hidden !== true;
|
|
268
|
-
const paintTableBody = ({ composer, block, measure, xPx, yPx, fromRow, toRow, headerRowCount, context, paintTextBox, visibleBand }) => {
|
|
280
|
+
const paintTableBody = ({ composer, block, measure, xPx, yPx, fromRow, toRow, headerRowCount, context, paintTextBox, visibleBand, cellLineBand }) => {
|
|
269
281
|
const grid = buildTableCellGrid(block.rows, measure.columnWidths.length);
|
|
270
282
|
const placements = buildTableCellPlacements({
|
|
271
283
|
grid,
|
|
@@ -299,10 +311,12 @@ const paintTableBody = ({ composer, block, measure, xPx, yPx, fromRow, toRow, he
|
|
|
299
311
|
};
|
|
300
312
|
const paintRowCells = (row, rowMeasure, rowIndex, rowYPx) => {
|
|
301
313
|
const opensContinuation = visibleBand !== void 0 && rowIndex === firstShownRow && rowYPx >= visibleBand.top;
|
|
314
|
+
const cellBands = rowIndex === fromRow ? cellLineBand?.cells : void 0;
|
|
302
315
|
for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex += 1) {
|
|
303
316
|
const cell = row.cells[cellIndex];
|
|
304
317
|
const cellMeasure = rowMeasure.cells[cellIndex];
|
|
305
318
|
if (!cell || !cellMeasure) continue;
|
|
319
|
+
const cellBand = cellBands?.[cellIndex];
|
|
306
320
|
const placement = placements.get(cell);
|
|
307
321
|
if (!placement) continue;
|
|
308
322
|
const rowSpan = Math.max(1, Math.trunc(cell.rowSpan ?? 1));
|
|
@@ -338,6 +352,10 @@ const paintTableBody = ({ composer, block, measure, xPx, yPx, fromRow, toRow, he
|
|
|
338
352
|
context,
|
|
339
353
|
paintTextBox,
|
|
340
354
|
visibleBand,
|
|
355
|
+
...cellBand ? { contentBandPx: {
|
|
356
|
+
top: rowYPx + cellBand.top,
|
|
357
|
+
bottom: rowYPx + cellBand.bottom
|
|
358
|
+
} } : {},
|
|
341
359
|
sides: {
|
|
342
360
|
top: bordersSeparated || rowIndex === fromRow || opensContinuation || !hasVisibleBorder(aboveCell?.borders?.bottom),
|
|
343
361
|
bottom: true,
|
|
@@ -436,7 +454,8 @@ const paintTableFragment = ({ composer, fragment, block, measure, context, paint
|
|
|
436
454
|
headerRowCount: 0,
|
|
437
455
|
context,
|
|
438
456
|
paintTextBox,
|
|
439
|
-
visibleBand
|
|
457
|
+
visibleBand,
|
|
458
|
+
...fragment.cellLineBand ? { cellLineBand: fragment.cellLineBand } : {}
|
|
440
459
|
});
|
|
441
460
|
};
|
|
442
461
|
if (fragment.topClip === void 0 && fragment.bottomClip === void 0) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { writeCommentAnchorIds } from "../../render-dom/commentAnchorAttributes.js";
|
|
2
2
|
import { bytesToDataUrl } from "../../utils/base64.js";
|
|
3
|
+
import { cssString } from "../../utils/cssString.js";
|
|
3
4
|
import { imageLuminanceFilter } from "../../utils/imageLuminance.js";
|
|
4
5
|
import { applyTextAdvanceGaps } from "../../utils/textAdvanceGapsDom.js";
|
|
5
6
|
import { anchorTargetAttrs } from "../../utils/urlSecurity.js";
|
|
@@ -78,7 +79,6 @@ const px = (value) => `${value}px`;
|
|
|
78
79
|
* the PDF backend's colour dump.
|
|
79
80
|
*/
|
|
80
81
|
const cssColor = ({ r, g, b, a }) => a === 1 ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
81
|
-
const quoteFontFamily = (family) => `"${family.replaceAll("\"", "\\\"")}"`;
|
|
82
82
|
/**
|
|
83
83
|
* An embedded face wins over any installed face of the same name by being
|
|
84
84
|
* named first, under the id its `@font-face` rule was registered with.
|
|
@@ -91,8 +91,8 @@ const quoteFontFamily = (family) => `"${family.replaceAll("\"", "\\\"")}"`;
|
|
|
91
91
|
* any host missing the first one.
|
|
92
92
|
*/
|
|
93
93
|
const fontFamilyStack = ({ family, fallbacks, generic, embedded }) => {
|
|
94
|
-
const resolved = `${[family, ...fallbacks].map(
|
|
95
|
-
return embedded === void 0 ? resolved : `${
|
|
94
|
+
const resolved = `${[family, ...fallbacks].map(cssString).join(", ")}, ${generic}`;
|
|
95
|
+
return embedded === void 0 ? resolved : `${cssString(embedded.id)}, ${resolved}`;
|
|
96
96
|
};
|
|
97
97
|
const resolveFont = (ref, fonts) => {
|
|
98
98
|
const face = ref < 0 ? void 0 : fonts.at(ref);
|
|
@@ -110,7 +110,7 @@ const binarySrc = (bytes, mimeType, urls) => {
|
|
|
110
110
|
if (urls === "objectUrl" && isBlobPart(bytes) && typeof Blob === "function" && typeof URL !== "undefined" && typeof URL.createObjectURL === "function") return URL.createObjectURL(new Blob([bytes], { type: mimeType }));
|
|
111
111
|
return bytesToDataUrl(bytes, mimeType);
|
|
112
112
|
};
|
|
113
|
-
const fontFaceRule = (face, embedded, src) => `@font-face { font-family: ${
|
|
113
|
+
const fontFaceRule = (face, embedded, src) => `@font-face { font-family: ${cssString(embedded.id)}; src: url("${src}"); font-weight: ${face.weight}; font-style: ${face.italic ? "italic" : "normal"}; }`;
|
|
114
114
|
/**
|
|
115
115
|
* `@font-face` rules for the faces whose bytes travel with the list. Resolved
|
|
116
116
|
* once per render and shared by every page: an id maps to one blob, so the
|
|
@@ -314,6 +314,14 @@ export type ApplyFolioDocumentOperationsOptions = {
|
|
|
314
314
|
*/
|
|
315
315
|
restagesSuggestions?: boolean;
|
|
316
316
|
};
|
|
317
|
+
/**
|
|
318
|
+
* A suggested operation without a `suggestionId` is its own suggestion, named
|
|
319
|
+
* by its id. An id a still pending suggestion already carries would fold the
|
|
320
|
+
* two into one (accepted, rejected and exported together), so such an
|
|
321
|
+
* operation gets a distinct id, and an operation of the batch grouping with it
|
|
322
|
+
* by that id follows it.
|
|
323
|
+
*/
|
|
324
|
+
export declare const withDistinctSuggestionIds: (batch: FolioDocumentOperationBatch, pending: ReadonlySet<string>) => FolioDocumentOperationBatch;
|
|
317
325
|
export declare const applyFolioDocumentOperations: (input: ApplyFolioDocumentOperationsOptions) => FolioDocumentOperationResult;
|
|
318
326
|
/**
|
|
319
327
|
* Options of a caller that holds every story of the package: the numbering
|
|
@@ -1081,7 +1081,8 @@ const recoveryByReason = {
|
|
|
1081
1081
|
missingNumbering: "refreshDocument",
|
|
1082
1082
|
invalidResult: "refreshDocument",
|
|
1083
1083
|
pendingDeletion: "resolveTrackedChange",
|
|
1084
|
-
pendingParagraphMarkDeletion: "resolveTrackedChange"
|
|
1084
|
+
pendingParagraphMarkDeletion: "resolveTrackedChange",
|
|
1085
|
+
contentControlLock: "changeTarget"
|
|
1085
1086
|
};
|
|
1086
1087
|
const getFolioDocumentOperationIssues = (operations, skipped) => {
|
|
1087
1088
|
const indexById = /* @__PURE__ */ new Map();
|
|
@@ -1095,7 +1096,7 @@ const getFolioDocumentOperationIssues = (operations, skipped) => {
|
|
|
1095
1096
|
operationIndex,
|
|
1096
1097
|
path: `$.operations[${operationIndex}]`,
|
|
1097
1098
|
code: reason,
|
|
1098
|
-
retryable: reason !== "emptyOperation" && reason !== "noopOperation" && reason !== "pendingParagraphPropertyChange" && reason !== "pendingRunPropertyChange" && reason !== "pendingDeletion" && reason !== "pendingParagraphMarkDeletion" && reason !== "payloadDoesNotFit" && reason !== "protectedReference" && reason !== "invalidResult",
|
|
1099
|
+
retryable: reason !== "emptyOperation" && reason !== "noopOperation" && reason !== "pendingParagraphPropertyChange" && reason !== "pendingRunPropertyChange" && reason !== "pendingDeletion" && reason !== "pendingParagraphMarkDeletion" && reason !== "contentControlLock" && reason !== "payloadDoesNotFit" && reason !== "protectedReference" && reason !== "invalidResult",
|
|
1099
1100
|
recovery: recoveryByReason[reason],
|
|
1100
1101
|
...canonicalRefusal === void 0 ? {} : { canonicalRefusal },
|
|
1101
1102
|
...message !== void 0 && { message }
|
|
@@ -1517,4 +1518,4 @@ const applyFolioDocumentOperationsInPackage = ({ view, snapshot, batch, story =
|
|
|
1517
1518
|
undoHandle: result.applied.length > 0 && createUndoHandle !== void 0 ? createUndoHandle() : null
|
|
1518
1519
|
};
|
|
1519
1520
|
};
|
|
1520
|
-
export { FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_BATCH_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_KEYS_BY_TYPE, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FOLIO_LINE_SPACING_RULE_VALUES, FOLIO_PAGE_BREAK_CLEAR_VALUES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, applyFolioDocumentOperations, applyFolioDocumentOperationsInPackage, assertSupportedFolioDocumentOperationVersion, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioDocumentOperationReceiptsForStory, isFolioDocumentOperationModeSupported, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch };
|
|
1521
|
+
export { FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_BATCH_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_KEYS_BY_TYPE, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FOLIO_LINE_SPACING_RULE_VALUES, FOLIO_PAGE_BREAK_CLEAR_VALUES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, applyFolioDocumentOperations, applyFolioDocumentOperationsInPackage, assertSupportedFolioDocumentOperationVersion, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioDocumentOperationReceiptsForStory, isFolioDocumentOperationModeSupported, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch, withDistinctSuggestionIds };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
2
|
import { NumberingMap } from "./numberingParser.js";
|
|
3
|
+
import { PreviousListState } from "./listMarkerComputation.js";
|
|
3
4
|
import { ParseContext } from "./parseContext.js";
|
|
4
5
|
import { XmlElement } from "./xmlParser.js";
|
|
5
6
|
import { OwnedElsewhere } from "./containerChildren.js";
|
|
6
|
-
import { PreviousListState } from "./listMarkerComputation.js";
|
|
7
7
|
import { PreviewLedger } from "./previewBudget.js";
|
|
8
8
|
import { StyleMap } from "./styleParser.js";
|
|
9
9
|
type ParseBlockContentOptions = {
|
|
@@ -40,8 +40,12 @@ type BlockContentWalk = {
|
|
|
40
40
|
};
|
|
41
41
|
export declare const BLOCK_CONTENT_HANDLERS: {
|
|
42
42
|
readonly altChunk: "capture";
|
|
43
|
-
readonly commentRangeEnd:
|
|
44
|
-
|
|
43
|
+
readonly commentRangeEnd: (child: XmlElement, walk: {
|
|
44
|
+
modelled: document_d_exports.BlockContent[];
|
|
45
|
+
}) => void;
|
|
46
|
+
readonly commentRangeStart: (child: XmlElement, walk: {
|
|
47
|
+
modelled: document_d_exports.BlockContent[];
|
|
48
|
+
}) => void;
|
|
45
49
|
readonly customXmlDelRangeEnd: "capture";
|
|
46
50
|
readonly customXmlDelRangeStart: "capture";
|
|
47
51
|
readonly customXmlInsRangeEnd: "capture";
|
|
@@ -2,7 +2,7 @@ import { blockCustomXmlShell } from "./blockCustomXmlShell.js";
|
|
|
2
2
|
import { parseBookmarkEnd, parseBookmarkStart } from "./bookmarkParser.js";
|
|
3
3
|
import { CAPTURE, dispatchChildrenWithContext, ownedElsewhere, withPreservedChildren } from "./containerChildren.js";
|
|
4
4
|
import { computeListMarker } from "./listMarkerComputation.js";
|
|
5
|
-
import { BLOCK_MOVE_RANGE_MARKER_HANDLERS } from "./markupRangeMarker.js";
|
|
5
|
+
import { BLOCK_COMMENT_RANGE_MARKER_HANDLERS, BLOCK_MOVE_RANGE_MARKER_HANDLERS } from "./markupRangeMarker.js";
|
|
6
6
|
import { parseParagraph } from "./paragraphParser.js";
|
|
7
7
|
import { enrichParagraphTextBoxes } from "./paragraphTextBoxEnrichment.js";
|
|
8
8
|
import { standalonePreviewLedger } from "./previewBudget.js";
|
|
@@ -104,10 +104,9 @@ const BLOCK_CONTENT_HANDLERS = {
|
|
|
104
104
|
modelled.push(parseBookmarkEnd(child));
|
|
105
105
|
},
|
|
106
106
|
...BLOCK_MOVE_RANGE_MARKER_HANDLERS,
|
|
107
|
+
...BLOCK_COMMENT_RANGE_MARKER_HANDLERS,
|
|
107
108
|
...BLOCK_CHILD_OWNERS,
|
|
108
109
|
altChunk: CAPTURE,
|
|
109
|
-
commentRangeEnd: CAPTURE,
|
|
110
|
-
commentRangeStart: CAPTURE,
|
|
111
110
|
customXmlDelRangeEnd: CAPTURE,
|
|
112
111
|
customXmlDelRangeStart: CAPTURE,
|
|
113
112
|
customXmlInsRangeEnd: CAPTURE,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
/**
|
|
3
|
+
* Collapse each bookmark's markers in paragraphs to its first start and its
|
|
4
|
+
* last end. Answers how many markers were dropped.
|
|
5
|
+
*/
|
|
6
|
+
export declare const joinBookmarkRangesAcrossParagraphs: (blocks: readonly document_d_exports.BlockContent[]) => number;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { InlineContentRemovals } from "./inlineContentRemovals.js";
|
|
2
|
+
import { visitInlineContentSlots } from "./paragraphTraversal.js";
|
|
3
|
+
// src/docx/bookmarkRangeJoin.ts
|
|
4
|
+
const visitBookmarkMarkers = (blocks, visit) => {
|
|
5
|
+
for (const block of blocks) switch (block.type) {
|
|
6
|
+
case "paragraph":
|
|
7
|
+
visitInlineContentSlots(block, ({ content, index, item }) => {
|
|
8
|
+
if (item.type === "bookmarkStart") visit({
|
|
9
|
+
content,
|
|
10
|
+
index
|
|
11
|
+
}, "start", item.id);
|
|
12
|
+
else if (item.type === "bookmarkEnd") visit({
|
|
13
|
+
content,
|
|
14
|
+
index
|
|
15
|
+
}, "end", item.id);
|
|
16
|
+
});
|
|
17
|
+
break;
|
|
18
|
+
case "table":
|
|
19
|
+
for (const row of block.rows) for (const cell of row.cells) visitBookmarkMarkers(cell.content, visit);
|
|
20
|
+
break;
|
|
21
|
+
case "blockSdt":
|
|
22
|
+
case "blockCustomXml": visitBookmarkMarkers(block.content, visit);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Collapse each bookmark's markers in paragraphs to its first start and its
|
|
27
|
+
* last end. Answers how many markers were dropped.
|
|
28
|
+
*/
|
|
29
|
+
const joinBookmarkRangesAcrossParagraphs = (blocks) => {
|
|
30
|
+
const starts = /* @__PURE__ */ new Map();
|
|
31
|
+
const ends = /* @__PURE__ */ new Map();
|
|
32
|
+
visitBookmarkMarkers(blocks, (slot, type, id) => {
|
|
33
|
+
const byId = type === "start" ? starts : ends;
|
|
34
|
+
const slots = byId.get(id);
|
|
35
|
+
if (slots) slots.push(slot);
|
|
36
|
+
else byId.set(id, [slot]);
|
|
37
|
+
});
|
|
38
|
+
const removals = new InlineContentRemovals();
|
|
39
|
+
for (const slots of starts.values()) for (const slot of slots.slice(1)) removals.mark(slot);
|
|
40
|
+
for (const slots of ends.values()) for (const slot of slots.slice(0, -1)) removals.mark(slot);
|
|
41
|
+
return removals.apply();
|
|
42
|
+
};
|
|
43
|
+
export { joinBookmarkRangesAcrossParagraphs };
|
|
@@ -5,14 +5,18 @@ import { CanonicalResourceSaveRefusalError, canonicalResourceReplacementOf } fro
|
|
|
5
5
|
import { repackWithCanonicalStoryRemovals } from "./canonicalStoryRepack.js";
|
|
6
6
|
import { getDocumentSourceBaseline } from "./headerFooterVerbatim.js";
|
|
7
7
|
import { resolveSelectiveSaveFlags } from "./selectiveSaveFlags.js";
|
|
8
|
+
import { withoutUnusedSessionLists } from "./sessionListPruning.js";
|
|
8
9
|
import { Result, TaggedError } from "better-result";
|
|
10
|
+
import { withoutPendingSuggestions } from "@stll/docx-core/ops";
|
|
9
11
|
// src/docx/canonicalSave.ts
|
|
10
12
|
const CanonicalSaveDiagnosticErrorBase = TaggedError("CanonicalSaveDiagnosticError");
|
|
11
13
|
/** Forward a fidelity fallback through the adapters' existing error channel. */
|
|
12
14
|
var CanonicalSaveDiagnosticError = class extends CanonicalSaveDiagnosticErrorBase {};
|
|
13
15
|
/** Model and change signals come from one committed snapshot, never from PM. */
|
|
14
16
|
const serializeCanonicalSave = async ({ snapshot, options, featureFlags }) => {
|
|
15
|
-
const
|
|
17
|
+
const withoutSuggestions = withoutPendingSuggestions(snapshot.document);
|
|
18
|
+
if (withoutSuggestions.isErr()) throw withoutSuggestions.error;
|
|
19
|
+
const document = withoutUnusedSessionLists(withoutUnreferencedNotes(withoutSuggestions.value));
|
|
16
20
|
const replacementPart = snapshot.structure === "changed" ? canonicalResourceReplacementOf(document) : void 0;
|
|
17
21
|
if (replacementPart) {
|
|
18
22
|
const diagnostic = {
|
|
@@ -5,6 +5,10 @@ export declare class CanonicalDocxInputError extends CanonicalDocxInputErrorBase
|
|
|
5
5
|
message: string;
|
|
6
6
|
cause?: unknown;
|
|
7
7
|
}> {}
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Canonical seeding supports plaintext packages; refuse encryption before ZIP
|
|
10
|
+
* normalization. A package that repeats a paragraph or content control id is
|
|
11
|
+
* given unique ones, every paragraph and control kept.
|
|
12
|
+
*/
|
|
9
13
|
export declare const prepareCanonicalDocxInput: (input: DocxInput) => Promise<Err<ArrayBuffer, CanonicalDocxInputError> | Ok<Uint8Array<ArrayBufferLike>, CanonicalDocxInputError>>;
|
|
10
14
|
export {};
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { toArrayBuffer } from "../utils/docxInput.js";
|
|
2
2
|
import { DOCX_CONTAINER_TYPES, detectDocxContainerType } from "./encryption/containerFormat.js";
|
|
3
3
|
import { ensureParaIds } from "./ensureParaIds.js";
|
|
4
|
+
import { ensureUniqueControlIds } from "./ensureUniqueControlIds.js";
|
|
4
5
|
import { Result, TaggedError } from "better-result";
|
|
5
6
|
// src/docx/canonicalSessionInput.ts
|
|
6
7
|
const CanonicalDocxInputErrorBase = TaggedError("CanonicalDocxInputError");
|
|
7
8
|
var CanonicalDocxInputError = class extends CanonicalDocxInputErrorBase {};
|
|
8
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Canonical seeding supports plaintext packages; refuse encryption before ZIP
|
|
11
|
+
* normalization. A package that repeats a paragraph or content control id is
|
|
12
|
+
* given unique ones, every paragraph and control kept.
|
|
13
|
+
*/
|
|
9
14
|
const prepareCanonicalDocxInput = async (input) => {
|
|
10
15
|
const bytes = await Result.tryPromise({
|
|
11
16
|
try: () => toArrayBuffer(input),
|
|
@@ -17,7 +22,7 @@ const prepareCanonicalDocxInput = async (input) => {
|
|
|
17
22
|
if (bytes.isErr()) return bytes;
|
|
18
23
|
if (detectDocxContainerType(bytes.value) === DOCX_CONTAINER_TYPES.CFB) return Result.err(new CanonicalDocxInputError({ message: "Password-protected documents are unavailable in the experimental canonical session." }));
|
|
19
24
|
return Result.tryPromise({
|
|
20
|
-
try: async () => (await ensureParaIds(bytes.value)).docx,
|
|
25
|
+
try: async () => (await ensureUniqueControlIds((await ensureParaIds(bytes.value)).docx)).docx,
|
|
21
26
|
catch: (cause) => new CanonicalDocxInputError({
|
|
22
27
|
message: cause instanceof Error ? cause.message : "Canonical document normalization failed.",
|
|
23
28
|
cause
|
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
|
-
|
|
2
|
+
type CommentMarker = Extract<document_d_exports.ParagraphContent, {
|
|
3
|
+
type: "commentRangeStart";
|
|
4
|
+
} | {
|
|
5
|
+
type: "commentRangeEnd";
|
|
6
|
+
} | {
|
|
7
|
+
type: "commentReference";
|
|
8
|
+
}>;
|
|
9
|
+
/** A marker inside a paragraph, in the inline-content array it sits in. */
|
|
10
|
+
export type InlineCommentMarkerSlot = {
|
|
11
|
+
level: "inline";
|
|
3
12
|
/** The inline-content array the marker sits in, so a caller can splice it. */
|
|
4
13
|
content: document_d_exports.ParagraphContent[];
|
|
5
14
|
index: number;
|
|
6
|
-
item:
|
|
15
|
+
item: CommentMarker;
|
|
16
|
+
};
|
|
17
|
+
/** A range marker between blocks, in the block array it sits in. */
|
|
18
|
+
export type BlockCommentMarkerSlot = {
|
|
19
|
+
level: "block";
|
|
20
|
+
content: document_d_exports.BlockContent[];
|
|
21
|
+
index: number;
|
|
22
|
+
item: Extract<document_d_exports.BlockContent, {
|
|
7
23
|
type: "commentRangeStart";
|
|
8
24
|
} | {
|
|
9
25
|
type: "commentRangeEnd";
|
|
10
|
-
} | {
|
|
11
|
-
type: "commentReference";
|
|
12
26
|
}>;
|
|
13
27
|
};
|
|
28
|
+
export type CommentMarkerSlot = InlineCommentMarkerSlot | BlockCommentMarkerSlot;
|
|
14
29
|
export declare const visitCommentMarkers: (blocks: readonly document_d_exports.BlockContent[], visit: (slot: CommentMarkerSlot) => void) => void;
|
|
15
30
|
/** Remove every serialized anchor record for comments whose definitions are retired. */
|
|
16
31
|
export declare const removeCommentMarkers: (blocks: readonly document_d_exports.BlockContent[], commentIds: ReadonlySet<number>) => document_d_exports.BlockContent[];
|
|
@@ -26,4 +41,5 @@ export declare const removeCommentMarkers: (blocks: readonly document_d_exports.
|
|
|
26
41
|
* whole story: a reference that trails the end of a range three paragraphs back
|
|
27
42
|
* is still not a point comment.
|
|
28
43
|
*/
|
|
29
|
-
export declare const rangedCommentIds: (blocks: readonly document_d_exports.BlockContent[]) => ReadonlySet<number>;
|
|
44
|
+
export declare const rangedCommentIds: (blocks: readonly document_d_exports.BlockContent[]) => ReadonlySet<number>;
|
|
45
|
+
export {};
|
|
@@ -5,6 +5,7 @@ const visitCommentMarkers = (blocks, visit) => {
|
|
|
5
5
|
const visitParagraph = (paragraph) => {
|
|
6
6
|
visitInlineContentSlots(paragraph, ({ content, index, item }) => {
|
|
7
7
|
if (item.type === "commentRangeStart" || item.type === "commentRangeEnd" || item.type === "commentReference") visit({
|
|
8
|
+
level: "inline",
|
|
8
9
|
content,
|
|
9
10
|
index,
|
|
10
11
|
item
|
|
@@ -12,19 +13,42 @@ const visitCommentMarkers = (blocks, visit) => {
|
|
|
12
13
|
});
|
|
13
14
|
};
|
|
14
15
|
const visitBlock = (block) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
switch (block.type) {
|
|
17
|
+
case "paragraph":
|
|
18
|
+
visitParagraph(block);
|
|
19
|
+
return;
|
|
20
|
+
case "table":
|
|
21
|
+
for (const row of block.rows) for (const cell of row.cells) visitBlocks(cell.content);
|
|
22
|
+
return;
|
|
23
|
+
case "blockSdt":
|
|
24
|
+
case "blockCustomXml":
|
|
25
|
+
visitBlocks(block.content);
|
|
26
|
+
return;
|
|
27
|
+
case "commentRangeStart":
|
|
28
|
+
case "commentRangeEnd": return;
|
|
29
|
+
case "preservedBlock":
|
|
30
|
+
case "bookmarkStart":
|
|
31
|
+
case "bookmarkEnd":
|
|
32
|
+
case "moveFromRangeStart":
|
|
33
|
+
case "moveFromRangeEnd":
|
|
34
|
+
case "moveToRangeStart":
|
|
35
|
+
case "moveToRangeEnd": return;
|
|
36
|
+
default: return block;
|
|
22
37
|
}
|
|
23
|
-
if (block.type !== "blockSdt" && block.type !== "blockCustomXml") return;
|
|
24
|
-
visitBlocks(block.content);
|
|
25
38
|
};
|
|
26
39
|
const visitBlocks = (nested) => {
|
|
27
|
-
for (const block of nested)
|
|
40
|
+
for (const [index, block] of nested.entries()) {
|
|
41
|
+
if (block.type === "commentRangeStart" || block.type === "commentRangeEnd") {
|
|
42
|
+
visit({
|
|
43
|
+
level: "block",
|
|
44
|
+
content: nested,
|
|
45
|
+
index,
|
|
46
|
+
item: block
|
|
47
|
+
});
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
visitBlock(block);
|
|
51
|
+
}
|
|
28
52
|
};
|
|
29
53
|
visitBlocks(blocks);
|
|
30
54
|
};
|
|
@@ -209,6 +233,7 @@ const removeCommentMarkers = (blocks, commentIds) => {
|
|
|
209
233
|
case "moveFromRangeEnd":
|
|
210
234
|
case "moveToRangeStart":
|
|
211
235
|
case "moveToRangeEnd":
|
|
236
|
+
case "complexField":
|
|
212
237
|
case "preservedInline": return item;
|
|
213
238
|
}
|
|
214
239
|
};
|
|
@@ -253,6 +278,8 @@ const removeCommentMarkers = (blocks, commentIds) => {
|
|
|
253
278
|
case "preservedBlock":
|
|
254
279
|
case "bookmarkStart":
|
|
255
280
|
case "bookmarkEnd":
|
|
281
|
+
case "commentRangeStart":
|
|
282
|
+
case "commentRangeEnd":
|
|
256
283
|
case "moveFromRangeStart":
|
|
257
284
|
case "moveFromRangeEnd":
|
|
258
285
|
case "moveToRangeStart":
|
|
@@ -260,7 +287,8 @@ const removeCommentMarkers = (blocks, commentIds) => {
|
|
|
260
287
|
}
|
|
261
288
|
};
|
|
262
289
|
const rebuildBlocks = (content) => rebuildArray(content, rebuildBlock);
|
|
263
|
-
|
|
290
|
+
const rebuilt = rebuildBlocks(blocks);
|
|
291
|
+
return rebuilt === blocks ? blocks.slice() : rebuilt;
|
|
264
292
|
};
|
|
265
293
|
/**
|
|
266
294
|
* Comments that open a range anywhere in these blocks.
|
|
@@ -161,20 +161,38 @@ const withoutOrphanBlockMarkers = (blocks, validCommentIds) => {
|
|
|
161
161
|
for (const block of blocks) {
|
|
162
162
|
const nextBlock = withoutOrphanBlockMarker(block, validCommentIds);
|
|
163
163
|
if (nextBlock !== block) changed = true;
|
|
164
|
-
next.push(nextBlock);
|
|
164
|
+
if (nextBlock !== null) next.push(nextBlock);
|
|
165
165
|
}
|
|
166
166
|
return changed ? next : null;
|
|
167
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* A block with its orphaned comment markers gone, or `null` when the block is
|
|
170
|
+
* itself one: a comment range marker between blocks for a comment the save no
|
|
171
|
+
* longer holds.
|
|
172
|
+
*/
|
|
168
173
|
const withoutOrphanBlockMarker = (block, validCommentIds) => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
switch (block.type) {
|
|
175
|
+
case "paragraph": return withoutOrphanParagraphMarkers(block, validCommentIds);
|
|
176
|
+
case "table": return withoutOrphanTableMarkers(block, validCommentIds);
|
|
177
|
+
case "blockSdt":
|
|
178
|
+
case "blockCustomXml": {
|
|
179
|
+
const content = withoutOrphanBlockMarkers(block.content, validCommentIds);
|
|
180
|
+
return content ? {
|
|
181
|
+
...block,
|
|
182
|
+
content
|
|
183
|
+
} : block;
|
|
184
|
+
}
|
|
185
|
+
case "commentRangeStart":
|
|
186
|
+
case "commentRangeEnd": return validCommentIds.has(block.id) ? block : null;
|
|
187
|
+
case "preservedBlock":
|
|
188
|
+
case "bookmarkStart":
|
|
189
|
+
case "bookmarkEnd":
|
|
190
|
+
case "moveFromRangeStart":
|
|
191
|
+
case "moveFromRangeEnd":
|
|
192
|
+
case "moveToRangeStart":
|
|
193
|
+
case "moveToRangeEnd": return block;
|
|
194
|
+
default: return block;
|
|
195
|
+
}
|
|
178
196
|
};
|
|
179
197
|
const withoutOrphanTableMarkers = (table, validCommentIds) => {
|
|
180
198
|
let changed = false;
|
|
@@ -216,24 +234,12 @@ const withoutOrphanTableCellBlockMarkers = (blocks, validCommentIds) => {
|
|
|
216
234
|
let changed = false;
|
|
217
235
|
const next = [];
|
|
218
236
|
for (const block of blocks) {
|
|
219
|
-
const nextBlock =
|
|
237
|
+
const nextBlock = withoutOrphanBlockMarker(block, validCommentIds);
|
|
220
238
|
if (nextBlock !== block) changed = true;
|
|
221
|
-
next.push(nextBlock);
|
|
239
|
+
if (nextBlock !== null) next.push(nextBlock);
|
|
222
240
|
}
|
|
223
241
|
return changed ? next : null;
|
|
224
242
|
};
|
|
225
|
-
const withoutOrphanTableCellBlockMarker = (block, validCommentIds) => {
|
|
226
|
-
if (block.type === "paragraph") return withoutOrphanParagraphMarkers(block, validCommentIds);
|
|
227
|
-
if (block.type === "table") return withoutOrphanTableMarkers(block, validCommentIds);
|
|
228
|
-
if (block.type === "blockSdt" || block.type === "blockCustomXml") {
|
|
229
|
-
const content = withoutOrphanTableCellBlockMarkers(block.content, validCommentIds);
|
|
230
|
-
return content ? {
|
|
231
|
-
...block,
|
|
232
|
-
content
|
|
233
|
-
} : block;
|
|
234
|
-
}
|
|
235
|
-
return block;
|
|
236
|
-
};
|
|
237
243
|
const withoutOrphanParagraphMarkers = (paragraph, validCommentIds) => {
|
|
238
244
|
let changed = false;
|
|
239
245
|
const content = [];
|
|
@@ -2,5 +2,9 @@ import { document_d_exports } from "../types/document.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Collapse each comment's range markers to its first start and its last end.
|
|
4
4
|
* Answers how many markers were dropped.
|
|
5
|
+
*
|
|
6
|
+
* A start or an end between blocks counts as one of the range's markers, so a
|
|
7
|
+
* range that opens beside a content control keeps that start and loses the
|
|
8
|
+
* one its mark wrote at the front of the first paragraph.
|
|
5
9
|
*/
|
|
6
10
|
export declare const joinCommentRangesAcrossParagraphs: (blocks: readonly document_d_exports.BlockContent[]) => number;
|
|
@@ -4,29 +4,43 @@ import { InlineContentRemovals } from "./inlineContentRemovals.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* Collapse each comment's range markers to its first start and its last end.
|
|
6
6
|
* Answers how many markers were dropped.
|
|
7
|
+
*
|
|
8
|
+
* A start or an end between blocks counts as one of the range's markers, so a
|
|
9
|
+
* range that opens beside a content control keeps that start and loses the
|
|
10
|
+
* one its mark wrote at the front of the first paragraph.
|
|
7
11
|
*/
|
|
8
12
|
const joinCommentRangesAcrossParagraphs = (blocks) => {
|
|
9
13
|
const startsById = /* @__PURE__ */ new Map();
|
|
10
14
|
const endsById = /* @__PURE__ */ new Map();
|
|
11
|
-
visitCommentMarkers(blocks, (
|
|
15
|
+
visitCommentMarkers(blocks, (slot) => {
|
|
16
|
+
const { item } = slot;
|
|
12
17
|
if (item.type === "commentReference") return;
|
|
13
18
|
const slotsById = item.type === "commentRangeStart" ? startsById : endsById;
|
|
14
19
|
const slots = slotsById.get(item.id);
|
|
15
20
|
if (slots) {
|
|
16
|
-
slots.push(
|
|
17
|
-
content,
|
|
18
|
-
index
|
|
19
|
-
});
|
|
21
|
+
slots.push(slot);
|
|
20
22
|
return;
|
|
21
23
|
}
|
|
22
|
-
slotsById.set(item.id, [
|
|
23
|
-
content,
|
|
24
|
-
index
|
|
25
|
-
}]);
|
|
24
|
+
slotsById.set(item.id, [slot]);
|
|
26
25
|
});
|
|
27
26
|
const removals = new InlineContentRemovals();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const blockRemovals = /* @__PURE__ */ new Map();
|
|
28
|
+
const remove = (slot) => {
|
|
29
|
+
if (slot.level === "inline") {
|
|
30
|
+
removals.mark(slot);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const indexes = blockRemovals.get(slot.content) ?? [];
|
|
34
|
+
indexes.push(slot.index);
|
|
35
|
+
blockRemovals.set(slot.content, indexes);
|
|
36
|
+
};
|
|
37
|
+
for (const slots of startsById.values()) for (const slot of slots.slice(1)) remove(slot);
|
|
38
|
+
for (const slots of endsById.values()) for (const slot of slots.slice(0, -1)) remove(slot);
|
|
39
|
+
let dropped = removals.apply();
|
|
40
|
+
for (const [content, indexes] of blockRemovals) for (const index of indexes.toSorted((first, second) => second - first)) {
|
|
41
|
+
content.splice(index, 1);
|
|
42
|
+
dropped += 1;
|
|
43
|
+
}
|
|
44
|
+
return dropped;
|
|
31
45
|
};
|
|
32
46
|
export { joinCommentRangesAcrossParagraphs };
|
|
@@ -7,14 +7,15 @@ import { visitCommentMarkers } from "./commentAnchorIndex.js";
|
|
|
7
7
|
const completeCommentReferences = (blocks) => {
|
|
8
8
|
const lastRangeEnds = /* @__PURE__ */ new Map();
|
|
9
9
|
const referencedIds = /* @__PURE__ */ new Set();
|
|
10
|
-
visitCommentMarkers(blocks, (
|
|
10
|
+
visitCommentMarkers(blocks, (slot) => {
|
|
11
|
+
const { item } = slot;
|
|
11
12
|
if (item.type === "commentReference") {
|
|
12
13
|
referencedIds.add(item.id);
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
15
|
-
if (item.type === "commentRangeEnd") lastRangeEnds.set(item.id, {
|
|
16
|
-
content,
|
|
17
|
-
index
|
|
16
|
+
if (item.type === "commentRangeEnd" && slot.level === "inline") lastRangeEnds.set(item.id, {
|
|
17
|
+
content: slot.content,
|
|
18
|
+
index: slot.index
|
|
18
19
|
});
|
|
19
20
|
});
|
|
20
21
|
const insertionsByContent = /* @__PURE__ */ new Map();
|