@stll/folio-core 0.52.0 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/ai-edits/apply.d.ts +26 -1
- package/dist/ai-edits/apply.js +1779 -141
- package/dist/ai-edits/batch-claims.d.ts +145 -0
- package/dist/ai-edits/batch-claims.js +275 -0
- package/dist/ai-edits/blockRange.js +9 -3
- package/dist/ai-edits/character-boundaries.d.ts +43 -0
- package/dist/ai-edits/character-boundaries.js +95 -0
- package/dist/ai-edits/clean-text.d.ts +33 -3
- package/dist/ai-edits/clean-text.js +52 -6
- package/dist/ai-edits/comment-lifecycle.d.ts +18 -0
- package/dist/ai-edits/comment-lifecycle.js +52 -0
- package/dist/ai-edits/headless.d.ts +91 -7
- package/dist/ai-edits/headless.js +520 -51
- package/dist/ai-edits/index.d.ts +2 -1
- package/dist/ai-edits/index.js +2 -1
- package/dist/ai-edits/minimal-replacement.d.ts +21 -6
- package/dist/ai-edits/minimal-replacement.js +134 -15
- package/dist/ai-edits/newListNumbering.d.ts +23 -0
- package/dist/ai-edits/newListNumbering.js +94 -0
- package/dist/ai-edits/note-references.d.ts +96 -0
- package/dist/ai-edits/note-references.js +139 -0
- package/dist/ai-edits/pending-suggestions.d.ts +79 -0
- package/dist/ai-edits/pending-suggestions.js +306 -0
- package/dist/ai-edits/read.d.ts +6 -4
- package/dist/ai-edits/read.js +113 -50
- package/dist/ai-edits/result-validation.d.ts +29 -0
- package/dist/ai-edits/result-validation.js +164 -0
- package/dist/ai-edits/revisionStretches.d.ts +17 -0
- package/dist/ai-edits/revisionStretches.js +80 -0
- package/dist/ai-edits/snapshot.d.ts +36 -3
- package/dist/ai-edits/snapshot.js +180 -25
- package/dist/ai-edits/table-cell-mutations.d.ts +4 -2
- package/dist/ai-edits/table-cell-mutations.js +6 -2
- package/dist/ai-edits/table-geometry.d.ts +1 -1
- package/dist/ai-edits/table-row-column-mutations.d.ts +44 -17
- package/dist/ai-edits/table-row-column-mutations.js +86 -34
- package/dist/ai-edits/types.d.ts +155 -16
- package/dist/compare/compare.d.ts +1 -1
- package/dist/compare/compare.js +65 -16
- package/dist/compare/content-alignment.d.ts +5 -1
- package/dist/compare/content-alignment.js +52 -34
- package/dist/compare/content-types.d.ts +7 -0
- package/dist/compare/content.d.ts +4 -1
- package/dist/compare/content.js +6 -1
- package/dist/compare/formatting.js +2 -1
- package/dist/compare/inline-atoms.d.ts +21 -4
- package/dist/compare/inline-atoms.js +138 -16
- package/dist/compare/inline-provenance.js +1 -1
- package/dist/compare/plan.js +10 -5
- package/dist/compare/scenario.js +14 -3
- package/dist/compare/section-boundary-properties.js +1 -1
- package/dist/compare/types.d.ts +4 -2
- package/dist/compare/types.js +2 -1
- package/dist/compare/verification.d.ts +1 -1
- package/dist/compare/verification.js +15 -3
- package/dist/controller/committedLayoutDiff.d.ts +25 -0
- package/dist/controller/committedLayoutDiff.js +71 -0
- package/dist/controller/contentControlWidgetController.d.ts +1 -1
- package/dist/controller/folioEditor.d.ts +1 -1
- package/dist/controller/fontReadiness.d.ts +70 -3
- package/dist/controller/fontReadiness.js +100 -10
- package/dist/controller/headerFooterEditorManager.js +6 -1
- package/dist/controller/layoutPipeline.d.ts +12 -10
- package/dist/controller/layoutPipeline.js +65 -11
- package/dist/controller/layoutRunOptions.d.ts +24 -0
- package/dist/controller/layoutRunOptions.js +17 -0
- package/dist/controller/layoutScheduler.d.ts +19 -14
- package/dist/controller/layoutScheduler.js +15 -12
- package/dist/controller/layoutSession.d.ts +26 -2
- package/dist/controller/layoutSession.js +1 -1
- package/dist/controller/noteEditorManager.js +8 -3
- package/dist/document-operations.d.ts +11 -2
- package/dist/document-operations.js +230 -21
- package/dist/docx/altChunk.d.ts +8 -0
- package/dist/docx/altChunk.js +17 -0
- package/dist/docx/archiveInflation.d.ts +127 -0
- package/dist/docx/archiveInflation.js +181 -0
- package/dist/docx/attributeRemainder.d.ts +1 -1
- package/dist/docx/blockContentParser.d.ts +64 -1
- package/dist/docx/blockContentParser.js +17 -4
- package/dist/docx/blockCustomXmlShell.d.ts +7 -0
- package/dist/docx/blockCustomXmlShell.js +14 -0
- package/dist/docx/blockPlainText.js +7 -0
- package/dist/docx/commentAnchorIndex.js +1 -1
- package/dist/docx/commentRangeIntegrity.js +8 -3
- package/dist/docx/commentReferenceNormalization.js +1 -1
- package/dist/docx/commentReplyMarkers.js +20 -1
- package/dist/docx/compatibility.d.ts +1 -1
- package/dist/docx/compatibility.js +34 -13
- package/dist/docx/containerChildren.gen.d.ts +1 -1
- package/dist/docx/containerChildren.gen.js +1 -0
- package/dist/docx/documentParser.js +12 -12
- package/dist/docx/drawingIdNormalization.d.ts +3 -1
- package/dist/docx/drawingIdNormalization.js +6 -1
- package/dist/docx/ensureParaIds.js +119 -97
- package/dist/docx/footnoteParser.js +8 -4
- package/dist/docx/headerFooterParser.js +3 -3
- package/dist/docx/headerFooterReferenceNormalization.d.ts +20 -1
- package/dist/docx/headerFooterReferenceNormalization.js +52 -27
- package/dist/docx/hyperlinkParser.d.ts +1 -1
- package/dist/docx/index.d.ts +1 -1
- package/dist/docx/listNumberingInstances.d.ts +59 -0
- package/dist/docx/listNumberingInstances.js +249 -0
- package/dist/docx/metadataPrivacy.js +24 -1
- package/dist/docx/normalizeBaseDirection.js +2 -1
- package/dist/docx/noteReferenceMark.d.ts +15 -0
- package/dist/docx/noteReferenceMark.js +48 -0
- package/dist/docx/opaqueCarrier.d.ts +7 -0
- package/dist/docx/opaqueCarrier.js +38 -0
- package/dist/docx/packageParts.js +4 -1
- package/dist/docx/paragraphParser.js +96 -27
- package/dist/docx/paragraphPropertySource.d.ts +4 -2
- package/dist/docx/paragraphPropertySource.js +10 -2
- package/dist/docx/paragraphTraversal.js +1 -0
- package/dist/docx/parseWarningMessage.js +4 -1
- package/dist/docx/parser.js +175 -22
- package/dist/docx/rezip.js +31 -7
- package/dist/docx/sdtProperties.js +1 -1
- package/dist/docx/sdtPropertiesPatch.js +3 -0
- package/dist/docx/selectiveSave.js +16 -9
- package/dist/docx/selectiveXmlPatch.d.ts +3 -1
- package/dist/docx/selectiveXmlPatch.js +186 -39
- package/dist/docx/serializer/blockCustomXmlSerializer.d.ts +5 -0
- package/dist/docx/serializer/blockCustomXmlSerializer.js +4 -0
- package/dist/docx/serializer/documentSerializer.js +2 -0
- package/dist/docx/serializer/headerFooterSerializer.js +2 -0
- package/dist/docx/serializer/noteSerializer.js +3 -1
- package/dist/docx/serializer/paragraphSerializer.js +33 -9
- package/dist/docx/serializer/tableSerializer.js +25 -38
- package/dist/docx/server/boundedArchive.d.ts +8 -13
- package/dist/docx/server/boundedArchive.js +70 -59
- package/dist/docx/server/createBilingualDocument.js +3 -3
- package/dist/docx/server/extractDocxText.d.ts +8 -2
- package/dist/docx/server/extractDocxText.js +2 -2
- package/dist/docx/server/validateDocxConformance.d.ts +1 -1
- package/dist/docx/server/validateDocxConformance.js +1 -0
- package/dist/docx/tableParser.d.ts +157 -1
- package/dist/docx/tableParser.js +89 -10
- package/dist/docx/textBoxParser.js +1 -1
- package/dist/docx/unzip.d.ts +20 -2
- package/dist/docx/unzip.js +136 -25
- package/dist/docx/wordprocessingPrefixes.d.ts +78 -0
- package/dist/docx/wordprocessingPrefixes.js +286 -0
- package/dist/fonts/embeddedFonts.js +1 -1
- package/dist/i18n/messages/catalogs.gen.d.ts +170 -34
- package/dist/i18n/messages/catalogs.gen.js +187 -51
- package/dist/i18n/messages/messages.gen.d.ts +10 -2
- package/dist/internal/compare/inline-presentation.d.ts +2 -1
- package/dist/internal/compare/inline-presentation.js +11 -10
- package/dist/internal/headlessRevisionResolutionGuard.d.ts +2 -8
- package/dist/internal/headlessRevisionResolutionGuard.js +2 -11
- package/dist/internal/indexedPositionMap.d.ts +11 -0
- package/dist/internal/indexedPositionMap.js +42 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +2 -1
- package/dist/internal/revisionResolutionEdits.d.ts +13 -0
- package/dist/internal/revisionResolutionEdits.js +19 -0
- package/dist/internal/revisionResolutionInline.d.ts +24 -0
- package/dist/internal/{headlessRevisionResolution.js → revisionResolutionInline.js} +61 -43
- package/dist/internal/revisionResolutionStep.d.ts +34 -0
- package/dist/internal/revisionResolutionStep.js +282 -0
- package/dist/internal/revisionResolutionTracking.d.ts +11 -0
- package/dist/internal/revisionResolutionTracking.js +124 -0
- package/dist/internal/wholeStoryRevisionResolution.d.ts +56 -0
- package/dist/internal/wholeStoryRevisionResolution.js +600 -0
- package/dist/layout-bridge/convert/markupViewFlow.d.ts +20 -0
- package/dist/layout-bridge/convert/markupViewFlow.js +123 -0
- package/dist/layout-bridge/convert/tableConversion.js +1 -1
- package/dist/layout-bridge/convert/toFlowBlocks.js +10 -1
- package/dist/layout-engine/layoutInstrumentation.d.ts +9 -1
- package/dist/layout-engine/layoutInstrumentation.js +4 -1
- package/dist/layout-engine/measure/cache.d.ts +18 -1
- package/dist/layout-engine/measure/cache.js +31 -1
- package/dist/layout-engine/measure/font-metrics.worker.js +3 -7
- package/dist/layout-engine/measure/measureContainer.js +7 -47
- package/dist/layout-engine/measure/measureHelpers.d.ts +6 -1
- package/dist/layout-engine/measure/measureHelpers.js +22 -2
- package/dist/layout-engine/measure/measureParagraph.js +2 -2
- package/dist/layout-engine/measure/measureWorker.js +2 -3
- package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +6 -7
- package/dist/layout-engine/measure/measureWorkerProtocol.js +1 -2
- package/dist/layout-engine/measure/paragraphMeasureShared.d.ts +12 -1
- package/dist/layout-engine/measure/paragraphMeasureShared.js +14 -1
- package/dist/layout-engine/types.d.ts +6 -0
- package/dist/layout-painter/renderPage.js +1 -0
- package/dist/layout-painter/renderParagraph.js +1 -1
- package/dist/managers/ContextMenuManager.js +5 -2
- package/dist/managers/types.d.ts +3 -0
- package/dist/markdown/escape.d.ts +2 -2
- package/dist/markdown/escape.js +4 -5
- package/dist/markdown/fromMarkdown.js +2 -1
- package/dist/markdown/internals.d.ts +11 -1
- package/dist/markdown/internals.js +24 -3
- package/dist/markdown/renderBlock.js +121 -25
- package/dist/markdown/renderParagraph.d.ts +13 -1
- package/dist/markdown/renderParagraph.js +85 -38
- package/dist/markdown/renderRuns.d.ts +10 -1
- package/dist/markdown/renderRuns.js +323 -69
- package/dist/markdown/renderTable.js +24 -12
- package/dist/markdown/trailers.js +2 -2
- package/dist/markdown/types.d.ts +29 -7
- package/dist/paged-layout/incrementalMeasure.d.ts +1 -2
- package/dist/paged-layout/incrementalMeasure.js +1 -9
- package/dist/paged-layout/transactionDirtyRange.d.ts +1 -3
- package/dist/paged-layout/transactionDirtyRange.js +29 -41
- package/dist/panel-layout.d.ts +83 -0
- package/dist/panel-layout.js +96 -0
- package/dist/prosemirror/anchoredTextBoxes.d.ts +37 -0
- package/dist/prosemirror/anchoredTextBoxes.js +156 -0
- package/dist/prosemirror/attrs/index.d.ts +6 -2
- package/dist/prosemirror/attrs/index.js +172 -1
- package/dist/prosemirror/clearRunColor.d.ts +6 -0
- package/dist/prosemirror/clearRunColor.js +46 -0
- package/dist/prosemirror/commands/comments.d.ts +7 -8
- package/dist/prosemirror/commands/comments.js +281 -212
- package/dist/prosemirror/commands/contentControls.d.ts +1 -1
- package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
- package/dist/prosemirror/commands/formatPainter.js +1 -1
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/hyperlink.js +2 -1
- package/dist/prosemirror/commands/index.d.ts +2 -2
- package/dist/prosemirror/commands/index.js +2 -2
- package/dist/prosemirror/commands/paragraph.d.ts +7 -1
- package/dist/prosemirror/commands/paragraph.js +9 -1
- package/dist/prosemirror/commands/paragraphBookmarkJoin.d.ts +13 -0
- package/dist/prosemirror/commands/paragraphBookmarkJoin.js +22 -0
- package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
- package/dist/prosemirror/commands/propertyChangeScope.d.ts +3 -2
- package/dist/prosemirror/commands/propertyChangeScope.js +24 -3
- package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +40 -0
- package/dist/prosemirror/commands/resolveAllTableChanges.js +620 -0
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +15 -0
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +46 -0
- package/dist/prosemirror/commands/resolveParagraphProperties.d.ts +16 -0
- package/dist/prosemirror/commands/resolveParagraphProperties.js +73 -0
- package/dist/prosemirror/commands/sectionBreak.js +2 -1
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +15 -2
- package/dist/prosemirror/commands/tableCellMergeResolution.js +23 -7
- package/dist/prosemirror/containerFinalParagraph.d.ts +11 -5
- package/dist/prosemirror/containerFinalParagraph.js +7 -6
- package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -13
- package/dist/prosemirror/conversion/fromProseDoc.js +177 -605
- package/dist/prosemirror/conversion/toProseDoc.d.ts +4 -11
- package/dist/prosemirror/conversion/toProseDoc.js +70 -154
- package/dist/prosemirror/documentSchema.d.ts +8 -0
- package/dist/prosemirror/documentSchema.js +18 -0
- package/dist/prosemirror/emptyFieldResultRuns.d.ts +18 -0
- package/dist/prosemirror/emptyFieldResultRuns.js +33 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
- package/dist/prosemirror/extensions/ExtensionManager.js +3 -1
- package/dist/prosemirror/extensions/StarterKit.js +5 -1
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +116 -63
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +4 -1
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +24 -3
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +20 -0
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.js +43 -0
- package/dist/prosemirror/extensions/features/ListExtension.js +167 -128
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +19 -2
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +33 -20
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +31 -2
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +270 -99
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +3 -2
- package/dist/prosemirror/extensions/features/pasteCleanup.js +2 -1
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
- package/dist/prosemirror/extensions/features/pastedHtmlLists.d.ts +12 -0
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +124 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +33 -11
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +8 -4
- package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +21 -18
- package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +37 -17
- package/dist/prosemirror/extensions/marks/StrikeExtension.js +2 -2
- package/dist/prosemirror/extensions/marks/SubscriptExtension.js +2 -2
- package/dist/prosemirror/extensions/marks/SuperscriptExtension.js +2 -2
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +4 -3
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +15 -8
- package/dist/prosemirror/extensions/marks/markUtils.js +25 -10
- package/dist/prosemirror/extensions/marks/noteReferenceDeletion.d.ts +12 -0
- package/dist/prosemirror/extensions/marks/noteReferenceDeletion.js +46 -0
- package/dist/prosemirror/extensions/nodes/BlockCustomXmlExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/nodes/BlockCustomXmlExtension.js +52 -0
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +2 -2
- package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +3 -3
- package/dist/prosemirror/extensions/nodes/FieldExtension.js +50 -15
- package/dist/prosemirror/extensions/nodes/HardBreakExtension.js +5 -3
- package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.js +4 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +121 -226
- package/dist/prosemirror/extensions/types.d.ts +11 -1
- package/dist/prosemirror/findReplaceSelection.js +1 -1
- package/dist/prosemirror/hyperlinkRemoval.d.ts +9 -0
- package/dist/prosemirror/hyperlinkRemoval.js +129 -0
- package/dist/prosemirror/index.d.ts +5 -3
- package/dist/prosemirror/index.js +5 -3
- package/dist/prosemirror/indexedNodeLookup.d.ts +17 -0
- package/dist/prosemirror/indexedNodeLookup.js +103 -0
- package/dist/prosemirror/listAutoformatMarkers.d.ts +19 -0
- package/dist/prosemirror/listAutoformatMarkers.js +98 -0
- package/dist/prosemirror/listInstanceReferences.d.ts +12 -0
- package/dist/prosemirror/listInstanceReferences.js +72 -0
- package/dist/prosemirror/listLabels.d.ts +24 -0
- package/dist/prosemirror/listLabels.js +111 -0
- package/dist/prosemirror/listNumbering.d.ts +92 -0
- package/dist/prosemirror/listNumbering.js +330 -0
- package/dist/prosemirror/listRendering.d.ts +27 -0
- package/dist/prosemirror/listRendering.js +27 -0
- package/dist/prosemirror/listRenderingAttrs.d.ts +11 -2
- package/dist/prosemirror/listRenderingAttrs.js +8 -1
- package/dist/prosemirror/markupViewNotes.d.ts +8 -0
- package/dist/prosemirror/markupViewNotes.js +49 -0
- package/dist/prosemirror/markupViewProjection.d.ts +97 -0
- package/dist/prosemirror/markupViewProjection.js +88 -0
- package/dist/prosemirror/noteReferenceReview.d.ts +77 -0
- package/dist/prosemirror/noteReferenceReview.js +332 -0
- package/dist/prosemirror/numberingAttr.d.ts +9 -1
- package/dist/prosemirror/numberingAttr.js +9 -1
- package/dist/prosemirror/outlineLevelAttr.js +1 -1
- package/dist/prosemirror/paragraphIndentation.d.ts +10 -1
- package/dist/prosemirror/paragraphIndentation.js +32 -7
- package/dist/prosemirror/paragraphMarkJoin.d.ts +21 -0
- package/dist/prosemirror/paragraphMarkJoin.js +26 -0
- package/dist/prosemirror/paragraphPropertyCarry.d.ts +64 -0
- package/dist/prosemirror/paragraphPropertyCarry.js +158 -0
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.d.ts +27 -1
- package/dist/prosemirror/plugins/documentNumbering.js +97 -11
- package/dist/prosemirror/plugins/documentStyleState.d.ts +26 -0
- package/dist/prosemirror/plugins/documentStyleState.js +32 -0
- package/dist/prosemirror/plugins/documentStyles.d.ts +3 -13
- package/dist/prosemirror/plugins/documentStyles.js +67 -17
- package/dist/prosemirror/plugins/index.d.ts +2 -1
- package/dist/prosemirror/plugins/index.js +2 -1
- package/dist/prosemirror/plugins/paragraphStyleResolution.d.ts +15 -0
- package/dist/prosemirror/plugins/paragraphStyleResolution.js +230 -0
- package/dist/prosemirror/plugins/suggestionMode.d.ts +27 -3
- package/dist/prosemirror/plugins/suggestionMode.js +490 -63
- package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
- package/dist/prosemirror/plugins/transactionInvariants.d.ts +32 -0
- package/dist/prosemirror/plugins/transactionInvariants.js +86 -0
- package/dist/prosemirror/positionSweep.d.ts +24 -0
- package/dist/prosemirror/positionSweep.js +222 -0
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +23 -3
- package/dist/prosemirror/rebaseParagraphRunFormatting.js +39 -13
- package/dist/prosemirror/rebaseParagraphRuns.d.ts +36 -0
- package/dist/prosemirror/rebaseParagraphRuns.js +99 -0
- package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.d.ts +33 -1
- package/dist/prosemirror/replacedAnnotations.js +170 -1
- package/dist/prosemirror/runFormattingFromMarks.d.ts +18 -0
- package/dist/prosemirror/runFormattingFromMarks.js +567 -0
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
- package/dist/prosemirror/runFormattingReconciliation.js +10 -9
- package/dist/prosemirror/schema/index.d.ts +2 -2
- package/dist/prosemirror/schema/index.js +3 -0
- package/dist/prosemirror/schema/nodes.d.ts +44 -11
- package/dist/prosemirror/sectionMarkEdits.d.ts +20 -0
- package/dist/prosemirror/sectionMarkEdits.js +59 -0
- package/dist/prosemirror/storyListNumbering.d.ts +17 -0
- package/dist/prosemirror/storyListNumbering.js +102 -0
- package/dist/prosemirror/styles/paragraphStyleCascade.d.ts +59 -0
- package/dist/prosemirror/styles/paragraphStyleCascade.js +145 -0
- package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +21 -2
- package/dist/prosemirror/styles/resolvedStyleAttrs.js +38 -1
- package/dist/prosemirror/styles/tableStyleRegions.d.ts +31 -0
- package/dist/prosemirror/styles/tableStyleRegions.js +55 -0
- package/dist/prosemirror/tableCellPaste.d.ts +74 -0
- package/dist/prosemirror/tableCellPaste.js +525 -0
- package/dist/prosemirror/tableGridMutation.d.ts +87 -2
- package/dist/prosemirror/tableGridMutation.js +255 -2
- package/dist/prosemirror/tableRunIn.d.ts +51 -0
- package/dist/prosemirror/tableRunIn.js +165 -0
- package/dist/prosemirror/textInput.js +11 -2
- package/dist/prosemirror/trackedRevisionPath.d.ts +17 -0
- package/dist/prosemirror/trackedRevisionPath.js +32 -0
- package/dist/prosemirror/validation.js +5 -1
- package/dist/redline.js +93 -9
- package/dist/render-dom/BodySelectionOverlay.d.ts +4 -1
- package/dist/render-dom/BodySelectionOverlay.js +3 -2
- package/dist/server.d.ts +2 -2
- package/dist/utils/findReplace.js +2 -2
- package/dist/utils/mergeDocumentContent.js +1 -1
- package/dist/utils/noteReferenceLabels.d.ts +36 -0
- package/dist/utils/noteReferenceLabels.js +32 -0
- package/dist/utils/replaceText.js +1 -1
- package/dist/version-comparison.d.ts +1 -0
- package/dist/version-comparison.js +1 -0
- package/package.json +6 -5
- package/dist/internal/headlessRevisionResolution.d.ts +0 -23
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { resolveWholeStory } from "../internal/wholeStoryRevisionResolution.js";
|
|
2
|
+
import { proseDocToBlocks } from "./conversion/fromProseDoc.js";
|
|
3
|
+
import { footnoteToProseDoc } from "./conversion/toProseDoc.js";
|
|
4
|
+
import { markupViewResolutionMode } from "./markupViewProjection.js";
|
|
5
|
+
import { getDocumentNumbering } from "./plugins/documentNumbering.js";
|
|
6
|
+
import { getDocumentStyleResolver } from "./plugins/documentStyleState.js";
|
|
7
|
+
//#region src/prosemirror/markupViewNotes.ts
|
|
8
|
+
const resolvedNotes = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
const resolvedNote = (note, mode, state, document) => {
|
|
10
|
+
const styleResolver = getDocumentStyleResolver(state);
|
|
11
|
+
const cached = resolvedNotes.get(note)?.get(mode);
|
|
12
|
+
if (cached?.styleResolver === styleResolver) return cached.note;
|
|
13
|
+
const { styles, theme } = document.package;
|
|
14
|
+
const doc = footnoteToProseDoc(note.content, {
|
|
15
|
+
...styles !== void 0 && { styles },
|
|
16
|
+
...theme !== void 0 && { theme }
|
|
17
|
+
});
|
|
18
|
+
const result = resolveWholeStory({
|
|
19
|
+
doc,
|
|
20
|
+
mode,
|
|
21
|
+
styleResolver,
|
|
22
|
+
numbering: getDocumentNumbering(state)
|
|
23
|
+
});
|
|
24
|
+
const resolved = result.failed || result.resolved.eq(doc) ? note : {
|
|
25
|
+
...note,
|
|
26
|
+
content: proseDocToBlocks(result.resolved, note.content, styles)
|
|
27
|
+
};
|
|
28
|
+
const byMode = resolvedNotes.get(note) ?? /* @__PURE__ */ new Map();
|
|
29
|
+
byMode.set(mode, {
|
|
30
|
+
styleResolver,
|
|
31
|
+
note: resolved
|
|
32
|
+
});
|
|
33
|
+
resolvedNotes.set(note, byMode);
|
|
34
|
+
return resolved;
|
|
35
|
+
};
|
|
36
|
+
/** The footnotes or endnotes as `view` shows them. */
|
|
37
|
+
const markupViewNotes = (notes, view, state, document) => {
|
|
38
|
+
const mode = markupViewResolutionMode(view);
|
|
39
|
+
if (!notes || !mode || !document) return notes;
|
|
40
|
+
let changed = false;
|
|
41
|
+
const shown = notes.map((note) => {
|
|
42
|
+
const resolved = resolvedNote(note, mode, state, document);
|
|
43
|
+
changed ||= resolved !== note;
|
|
44
|
+
return resolved;
|
|
45
|
+
});
|
|
46
|
+
return changed ? shown : notes;
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { markupViewNotes };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { DisplayMode } from "../managers/EditorModeManager.js";
|
|
2
|
+
import { RemovedSectionReference } from "../internal/sectionEndpointResolution.js";
|
|
3
|
+
import { indexedPositionMap } from "../internal/indexedPositionMap.js";
|
|
4
|
+
import { RevisionResolutionMode } from "../internal/revisionResolutionInline.js";
|
|
5
|
+
import { Node } from "prosemirror-model";
|
|
6
|
+
import { EditorState } from "prosemirror-state";
|
|
7
|
+
import { StepMap } from "prosemirror-transform";
|
|
8
|
+
//#region src/prosemirror/markupViewProjection.d.ts
|
|
9
|
+
/** Resolve every revision in the state's story with the state's own styles and numbering. */
|
|
10
|
+
declare const resolveStateStory: (state: EditorState, mode: RevisionResolutionMode) => {
|
|
11
|
+
resolved: Node;
|
|
12
|
+
mapping: import("prosemirror-transform").Mapping;
|
|
13
|
+
positionMap: StepMap;
|
|
14
|
+
steps: import("prosemirror-transform").Step[];
|
|
15
|
+
changedRanges: {
|
|
16
|
+
from: number;
|
|
17
|
+
to: number;
|
|
18
|
+
}[];
|
|
19
|
+
inlineMap: StepMap;
|
|
20
|
+
tableRanges: {
|
|
21
|
+
node: Node;
|
|
22
|
+
inputNode: Node;
|
|
23
|
+
sourceNodeSize: number;
|
|
24
|
+
position: number;
|
|
25
|
+
inputMap: StepMap;
|
|
26
|
+
positionMap: StepMap;
|
|
27
|
+
ranges: readonly {
|
|
28
|
+
from: number;
|
|
29
|
+
to: number;
|
|
30
|
+
}[];
|
|
31
|
+
paragraphOffsets: readonly {
|
|
32
|
+
source: number;
|
|
33
|
+
final: number;
|
|
34
|
+
}[];
|
|
35
|
+
}[];
|
|
36
|
+
transfers: {
|
|
37
|
+
displacedToken: string | null;
|
|
38
|
+
selectedToken: string | null;
|
|
39
|
+
}[];
|
|
40
|
+
structuralRanges: {
|
|
41
|
+
from: number;
|
|
42
|
+
to: number;
|
|
43
|
+
}[];
|
|
44
|
+
structuralMap: StepMap;
|
|
45
|
+
structural: boolean;
|
|
46
|
+
failed: boolean;
|
|
47
|
+
removedEndpointCount: number;
|
|
48
|
+
removedReferences: RemovedSectionReference[];
|
|
49
|
+
};
|
|
50
|
+
type PositionRange = {
|
|
51
|
+
from: number;
|
|
52
|
+
to: number;
|
|
53
|
+
};
|
|
54
|
+
type MarkupViewProjection =
|
|
55
|
+
/** The view lays the authored document out as it stands. */
|
|
56
|
+
{
|
|
57
|
+
type: "authored";
|
|
58
|
+
} | {
|
|
59
|
+
type: "resolved";
|
|
60
|
+
/** The document as the view reads it. */
|
|
61
|
+
doc: Node;
|
|
62
|
+
/** Authored (editor) positions to `doc` positions. */
|
|
63
|
+
positionMap: StepMap;
|
|
64
|
+
/** `positionMap`, indexed for lookups. */
|
|
65
|
+
toView: ReturnType<typeof indexedPositionMap>;
|
|
66
|
+
/** `positionMap` inverted and indexed: `doc` positions to editor positions. */
|
|
67
|
+
toEditor: ReturnType<typeof indexedPositionMap>;
|
|
68
|
+
/**
|
|
69
|
+
* Ranges of `doc` whose paragraphs carry a change indicator (Simple
|
|
70
|
+
* Markup's change bar); empty for a view without indicators.
|
|
71
|
+
*/
|
|
72
|
+
changeBarRanges: readonly PositionRange[];
|
|
73
|
+
/**
|
|
74
|
+
* Whether the resolver left part of the story as authored (a table
|
|
75
|
+
* revision it cannot resolve). The projection still shows every revision
|
|
76
|
+
* it could resolve; the caller reports the rest.
|
|
77
|
+
*/
|
|
78
|
+
completeness: "complete" | "partial";
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* The document a markup view lays out, for the state's current document.
|
|
82
|
+
* Cached per editor state: the resolver also reads its styles and numbering
|
|
83
|
+
* plugins, which may change while the document node stays the same.
|
|
84
|
+
*/
|
|
85
|
+
/** How a view resolves the revisions it reads, or null when it shows them inline. */
|
|
86
|
+
declare const markupViewResolutionMode: (view: DisplayMode) => RevisionResolutionMode | null;
|
|
87
|
+
declare const projectMarkupView: (state: EditorState, view: DisplayMode) => MarkupViewProjection;
|
|
88
|
+
/**
|
|
89
|
+
* Where a caret at editor `position` is painted in a view. A position the view
|
|
90
|
+
* shows is its own; one inside text the view does not show (a deletion in No
|
|
91
|
+
* Markup, an insertion in Original, typed there with tracking on) moves to the
|
|
92
|
+
* nearest place the view shows before it, the way the caret sits at the edge
|
|
93
|
+
* of text it cannot enter.
|
|
94
|
+
*/
|
|
95
|
+
declare const visibleCaretPosition: (projection: MarkupViewProjection, position: number) => number;
|
|
96
|
+
//#endregion
|
|
97
|
+
export { MarkupViewProjection, markupViewResolutionMode, projectMarkupView, resolveStateStory, visibleCaretPosition };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { indexedPositionMap } from "../internal/indexedPositionMap.js";
|
|
2
|
+
import { finalRevisionParagraphRanges } from "../internal/revisionResolutionTracking.js";
|
|
3
|
+
import { resolveWholeStory } from "../internal/wholeStoryRevisionResolution.js";
|
|
4
|
+
import { getDocumentNumbering } from "./plugins/documentNumbering.js";
|
|
5
|
+
import { getDocumentStyleResolver } from "./plugins/documentStyleState.js";
|
|
6
|
+
import { Selection } from "prosemirror-state";
|
|
7
|
+
//#region src/prosemirror/markupViewProjection.ts
|
|
8
|
+
/** Resolve every revision in the state's story with the state's own styles and numbering. */
|
|
9
|
+
const resolveStateStory = (state, mode) => resolveWholeStory({
|
|
10
|
+
doc: state.doc,
|
|
11
|
+
mode,
|
|
12
|
+
styleResolver: getDocumentStyleResolver(state),
|
|
13
|
+
numbering: getDocumentNumbering(state)
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Every view's reading of the document. Total over `DisplayMode`, so a new view
|
|
17
|
+
* cannot ship without a decision about what it lays out.
|
|
18
|
+
*/
|
|
19
|
+
const MARKUP_VIEW_RESOLUTIONS = {
|
|
20
|
+
"all-markup": { type: "authored" },
|
|
21
|
+
"simple-markup": {
|
|
22
|
+
type: "resolved",
|
|
23
|
+
mode: "accept",
|
|
24
|
+
indicators: "change-bars"
|
|
25
|
+
},
|
|
26
|
+
"no-markup": {
|
|
27
|
+
type: "resolved",
|
|
28
|
+
mode: "accept",
|
|
29
|
+
indicators: "none"
|
|
30
|
+
},
|
|
31
|
+
original: {
|
|
32
|
+
type: "resolved",
|
|
33
|
+
mode: "reject",
|
|
34
|
+
indicators: "none"
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const AUTHORED = { type: "authored" };
|
|
38
|
+
const projectionCache = /* @__PURE__ */ new WeakMap();
|
|
39
|
+
/**
|
|
40
|
+
* The document a markup view lays out, for the state's current document.
|
|
41
|
+
* Cached per editor state: the resolver also reads its styles and numbering
|
|
42
|
+
* plugins, which may change while the document node stays the same.
|
|
43
|
+
*/
|
|
44
|
+
/** How a view resolves the revisions it reads, or null when it shows them inline. */
|
|
45
|
+
const markupViewResolutionMode = (view) => {
|
|
46
|
+
const resolution = MARKUP_VIEW_RESOLUTIONS[view];
|
|
47
|
+
return resolution.type === "resolved" ? resolution.mode : null;
|
|
48
|
+
};
|
|
49
|
+
const projectMarkupView = (state, view) => {
|
|
50
|
+
const resolution = MARKUP_VIEW_RESOLUTIONS[view];
|
|
51
|
+
if (resolution.type === "authored") return AUTHORED;
|
|
52
|
+
let byView = projectionCache.get(state);
|
|
53
|
+
const cached = byView?.get(view);
|
|
54
|
+
if (cached) return cached;
|
|
55
|
+
const result = resolveStateStory(state, resolution.mode);
|
|
56
|
+
const projection = result.resolved.eq(state.doc) ? AUTHORED : {
|
|
57
|
+
type: "resolved",
|
|
58
|
+
doc: result.resolved,
|
|
59
|
+
positionMap: result.positionMap,
|
|
60
|
+
toView: indexedPositionMap(result.positionMap),
|
|
61
|
+
toEditor: indexedPositionMap(result.positionMap.invert()),
|
|
62
|
+
changeBarRanges: resolution.indicators === "change-bars" ? finalRevisionParagraphRanges(result) : [],
|
|
63
|
+
completeness: result.failed ? "partial" : "complete"
|
|
64
|
+
};
|
|
65
|
+
if (!byView) {
|
|
66
|
+
byView = /* @__PURE__ */ new Map();
|
|
67
|
+
projectionCache.set(state, byView);
|
|
68
|
+
}
|
|
69
|
+
byView.set(view, projection);
|
|
70
|
+
return projection;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Where a caret at editor `position` is painted in a view. A position the view
|
|
74
|
+
* shows is its own; one inside text the view does not show (a deletion in No
|
|
75
|
+
* Markup, an insertion in Original, typed there with tracking on) moves to the
|
|
76
|
+
* nearest place the view shows before it, the way the caret sits at the edge
|
|
77
|
+
* of text it cannot enter.
|
|
78
|
+
*/
|
|
79
|
+
const visibleCaretPosition = (projection, position) => {
|
|
80
|
+
if (projection.type === "authored") return position;
|
|
81
|
+
const { pos: viewPosition, deletedAcross } = projection.toView.mapResult(position, -1);
|
|
82
|
+
if (!deletedAcross) return position;
|
|
83
|
+
const bounded = Math.max(0, Math.min(viewPosition, projection.doc.content.size));
|
|
84
|
+
const near = Selection.near(projection.doc.resolve(bounded), -1);
|
|
85
|
+
return projection.toEditor(near.head, -1);
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
export { markupViewResolutionMode, projectMarkupView, resolveStateStory, visibleCaretPosition };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
import { Mark, Node } from "prosemirror-model";
|
|
3
|
+
import { Transform } from "prosemirror-transform";
|
|
4
|
+
//#region src/prosemirror/noteReferenceReview.d.ts
|
|
5
|
+
type NoteKind = "footnote" | "endnote";
|
|
6
|
+
/** `footnote:<id>` or `endnote:<id>`. */
|
|
7
|
+
type NoteKey = `${NoteKind}:${number}`;
|
|
8
|
+
/**
|
|
9
|
+
* The notes a story's text refers to, and whether each reference is pending
|
|
10
|
+
* deletion: a reference is deleted when every character of it is.
|
|
11
|
+
*/
|
|
12
|
+
declare const noteReferenceStates: (doc: Node) => Map<NoteKey, "live" | "deleted">;
|
|
13
|
+
/** The notes whose reference a change took from pending deletion back to live. */
|
|
14
|
+
declare const noteReferencesRestored: (before: Node, after: Node) => NoteKey[];
|
|
15
|
+
/**
|
|
16
|
+
* The revisions that deleted a note along with its reference: its text and
|
|
17
|
+
* its paragraph marks, deleted by the reference deletion's author at its
|
|
18
|
+
* date. A deletion in the note made some other time is a change of its own,
|
|
19
|
+
* which resolving the reference leaves alone.
|
|
20
|
+
*/
|
|
21
|
+
declare const noteDeletionRevisions: (doc: Node, reference: Mark) => number[];
|
|
22
|
+
/**
|
|
23
|
+
* The document with the named notes' deletions that went with their
|
|
24
|
+
* reference rejected: the notes whose reference's deletion was rejected get
|
|
25
|
+
* their text back. `before` is the body that still had those deletions.
|
|
26
|
+
*/
|
|
27
|
+
declare const restoreNotes: (document: document_d_exports.Document, keys: Iterable<NoteKey>, before: Node) => document_d_exports.Document;
|
|
28
|
+
/** The deletion each pending-deleted note reference carries. */
|
|
29
|
+
declare const referenceDeletions: (doc: Node) => Map<NoteKey, Mark>;
|
|
30
|
+
/**
|
|
31
|
+
* Delete a note's text and its paragraph marks along with its reference: by
|
|
32
|
+
* the reference deletion's author at its date, so resolving the reference
|
|
33
|
+
* resolves them too (see {@link noteDeletionRevisions}).
|
|
34
|
+
*/
|
|
35
|
+
declare const deleteNoteWithReference: <T extends Transform>(transform: T, reference: Mark) => T;
|
|
36
|
+
/**
|
|
37
|
+
* Keeps an editor's notes following their references across body edits. The
|
|
38
|
+
* editor reports the body as it was before the edits it has not yet written
|
|
39
|
+
* back, and reconciles the document it writes back:
|
|
40
|
+
*
|
|
41
|
+
* - a reference whose deletion is rejected gives its note back its text;
|
|
42
|
+
* - a reference deleted again, as undoing that reject does, takes the note's
|
|
43
|
+
* text with it: the note returns to what it was, or, when the note changed
|
|
44
|
+
* since, its text is deleted along with the reference.
|
|
45
|
+
*/
|
|
46
|
+
type NoteReferenceFollower = {
|
|
47
|
+
/** The body before the edits the next {@link reconcile} writes back. */
|
|
48
|
+
noteBase: (before: Node) => void;
|
|
49
|
+
/** The document to write back, its notes following the body's references. */
|
|
50
|
+
reconcile: (document: document_d_exports.Document, body: Node) => document_d_exports.Document;
|
|
51
|
+
/**
|
|
52
|
+
* `document` with the note changes an earlier {@link reconcile} wrote back
|
|
53
|
+
* and the editor's document has not taken in yet: a save reads the editor
|
|
54
|
+
* right after a write-back, before the host hands the result back.
|
|
55
|
+
*/
|
|
56
|
+
withPending: (document: document_d_exports.Document) => document_d_exports.Document;
|
|
57
|
+
/** Forget the pending base and what earlier restores replaced (a new document). */
|
|
58
|
+
reset: () => void;
|
|
59
|
+
};
|
|
60
|
+
declare const createNoteReferenceFollower: () => NoteReferenceFollower;
|
|
61
|
+
/** The notes model content refers to, live or pending deletion. */
|
|
62
|
+
declare const noteKeysReferencedIn: (content: unknown) => Set<NoteKey>;
|
|
63
|
+
/**
|
|
64
|
+
* The notes anything refers to, live or pending deletion: the main story, and
|
|
65
|
+
* the stories the body does not hold (headers, footers, comments, notes).
|
|
66
|
+
* References inside the `skipped` notes do not count: those notes are going.
|
|
67
|
+
*/
|
|
68
|
+
declare const referencedNotes: (document: document_d_exports.Document, skipped?: ReadonlySet<string>) => Set<NoteKey>;
|
|
69
|
+
/**
|
|
70
|
+
* The document without the notes nothing refers to any more: a note goes
|
|
71
|
+
* with its reference, so accepting the reference's deletion leaves a note no
|
|
72
|
+
* reader can reach, and saving drops it, with the comments anchored only in
|
|
73
|
+
* it. Separators stay.
|
|
74
|
+
*/
|
|
75
|
+
declare const withoutUnreferencedNotes: (document: document_d_exports.Document) => document_d_exports.Document;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { NoteKey, NoteReferenceFollower, createNoteReferenceFollower, deleteNoteWithReference, noteDeletionRevisions, noteKeysReferencedIn, noteReferenceStates, noteReferencesRestored, referenceDeletions, referencedNotes, restoreNotes, withoutUnreferencedNotes };
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { withoutLostCommentThreads } from "../ai-edits/comment-lifecycle.js";
|
|
2
|
+
import { visitCommentMarkers } from "../docx/commentAnchorIndex.js";
|
|
3
|
+
import { isSeparatorEndnote, isSeparatorFootnote } from "../docx/footnoteParser.js";
|
|
4
|
+
import { pluginsForHeadlessRevisionResolution } from "../internal/headlessRevisionResolutionGuard.js";
|
|
5
|
+
import { expectFootnoteRefMarkAttrs, expectParagraphAttrs } from "./attrs/index.js";
|
|
6
|
+
import { rejectAIEditRevision } from "./commands/comments.js";
|
|
7
|
+
import { proseDocToBlocks } from "./conversion/fromProseDoc.js";
|
|
8
|
+
import { footnoteToProseDoc } from "./conversion/toProseDoc.js";
|
|
9
|
+
import { createDocumentNumberingPlugin } from "./plugins/documentNumbering.js";
|
|
10
|
+
import { createDocumentStylesPlugin } from "./plugins/documentStyles.js";
|
|
11
|
+
import { mintRevisionId } from "./plugins/revisionIds.js";
|
|
12
|
+
import { schema, singletonManager } from "./schema/index.js";
|
|
13
|
+
import { Transform } from "prosemirror-transform";
|
|
14
|
+
import { EditorState } from "prosemirror-state";
|
|
15
|
+
//#region src/prosemirror/noteReferenceReview.ts
|
|
16
|
+
const noteKey = (kind, id) => `${kind}:${id}`;
|
|
17
|
+
/**
|
|
18
|
+
* The notes a story's text refers to, and whether each reference is pending
|
|
19
|
+
* deletion: a reference is deleted when every character of it is.
|
|
20
|
+
*/
|
|
21
|
+
const noteReferenceStates = (doc) => {
|
|
22
|
+
const states = /* @__PURE__ */ new Map();
|
|
23
|
+
doc.descendants((node) => {
|
|
24
|
+
if (!node.isText) return true;
|
|
25
|
+
const reference = node.marks.find((mark) => mark.type.name === "footnoteRef");
|
|
26
|
+
if (!reference) return false;
|
|
27
|
+
const { id, noteType } = expectFootnoteRefMarkAttrs(reference);
|
|
28
|
+
const key = noteKey(noteType === "endnote" ? "endnote" : "footnote", Number(id));
|
|
29
|
+
if (!node.marks.some((mark) => mark.type.name === "deletion") || states.get(key) === "live") states.set(key, "live");
|
|
30
|
+
else states.set(key, "deleted");
|
|
31
|
+
return false;
|
|
32
|
+
});
|
|
33
|
+
return states;
|
|
34
|
+
};
|
|
35
|
+
/** The notes whose reference a change took from pending deletion back to live. */
|
|
36
|
+
const noteReferencesRestored = (before, after) => {
|
|
37
|
+
const was = noteReferenceStates(before);
|
|
38
|
+
return [...noteReferenceStates(after)].flatMap(([key, state]) => state === "live" && was.get(key) === "deleted" ? [key] : []);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The revisions that deleted a note along with its reference: its text and
|
|
42
|
+
* its paragraph marks, deleted by the reference deletion's author at its
|
|
43
|
+
* date. A deletion in the note made some other time is a change of its own,
|
|
44
|
+
* which resolving the reference leaves alone.
|
|
45
|
+
*/
|
|
46
|
+
const noteDeletionRevisions = (doc, reference) => {
|
|
47
|
+
const author = String(reference.attrs["author"] ?? "");
|
|
48
|
+
const date = String(reference.attrs["date"] ?? "");
|
|
49
|
+
const ids = /* @__PURE__ */ new Set();
|
|
50
|
+
doc.descendants((node) => {
|
|
51
|
+
if (node.type.name === "paragraph") {
|
|
52
|
+
const mark = expectParagraphAttrs(node).pPrMark;
|
|
53
|
+
if (mark?.kind === "del" && mark.info.author === author && mark.info.date === date) ids.add(mark.info.id);
|
|
54
|
+
}
|
|
55
|
+
for (const mark of node.marks) if (mark.type.name === "deletion" && String(mark.attrs["author"] ?? "") === author && String(mark.attrs["date"] ?? "") === date) {
|
|
56
|
+
const id = mark.attrs["revisionId"];
|
|
57
|
+
if (typeof id === "number") ids.add(id);
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
});
|
|
61
|
+
return [...ids];
|
|
62
|
+
};
|
|
63
|
+
const restoredNote = (note, document, reference) => {
|
|
64
|
+
const { styles, theme, numbering } = document.package;
|
|
65
|
+
const doc = footnoteToProseDoc(note.content, {
|
|
66
|
+
...styles !== void 0 && { styles },
|
|
67
|
+
...theme !== void 0 && { theme }
|
|
68
|
+
});
|
|
69
|
+
const revisions = noteDeletionRevisions(doc, reference);
|
|
70
|
+
if (revisions.length === 0) return note;
|
|
71
|
+
let state = EditorState.create({
|
|
72
|
+
schema,
|
|
73
|
+
doc,
|
|
74
|
+
plugins: [
|
|
75
|
+
...pluginsForHeadlessRevisionResolution(singletonManager.getPlugins()),
|
|
76
|
+
createDocumentStylesPlugin(styles),
|
|
77
|
+
createDocumentNumberingPlugin(numbering)
|
|
78
|
+
]
|
|
79
|
+
});
|
|
80
|
+
rejectAIEditRevision(revisions)(state, (transaction) => {
|
|
81
|
+
state = state.apply(transaction);
|
|
82
|
+
});
|
|
83
|
+
if (state.doc.eq(doc)) return note;
|
|
84
|
+
return {
|
|
85
|
+
...note,
|
|
86
|
+
content: proseDocToBlocks(state.doc, note.content, styles)
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* The document with the named notes' deletions that went with their
|
|
91
|
+
* reference rejected: the notes whose reference's deletion was rejected get
|
|
92
|
+
* their text back. `before` is the body that still had those deletions.
|
|
93
|
+
*/
|
|
94
|
+
const restoreNotes = (document, keys, before) => {
|
|
95
|
+
const deletions = referenceDeletions(before);
|
|
96
|
+
const wanted = new Set([...keys].filter((key) => deletions.has(key)));
|
|
97
|
+
if (wanted.size === 0) return document;
|
|
98
|
+
const restore = (kind, notes) => {
|
|
99
|
+
if (!notes?.some((note) => wanted.has(noteKey(kind, note.id)))) return notes;
|
|
100
|
+
return notes.map((note) => {
|
|
101
|
+
const reference = deletions.get(noteKey(kind, note.id));
|
|
102
|
+
return reference ? restoredNote(note, document, reference) : note;
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
const footnotes = restore("footnote", document.package.footnotes);
|
|
106
|
+
const endnotes = restore("endnote", document.package.endnotes);
|
|
107
|
+
if (footnotes === document.package.footnotes && endnotes === document.package.endnotes) return document;
|
|
108
|
+
return {
|
|
109
|
+
...document,
|
|
110
|
+
package: {
|
|
111
|
+
...document.package,
|
|
112
|
+
...footnotes !== void 0 && { footnotes },
|
|
113
|
+
...endnotes !== void 0 && { endnotes }
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
/** The deletion each pending-deleted note reference carries. */
|
|
118
|
+
const referenceDeletions = (doc) => {
|
|
119
|
+
const deletions = /* @__PURE__ */ new Map();
|
|
120
|
+
doc.descendants((node) => {
|
|
121
|
+
if (!node.isText) return true;
|
|
122
|
+
const reference = node.marks.find((mark) => mark.type.name === "footnoteRef");
|
|
123
|
+
const deletion = node.marks.find((mark) => mark.type.name === "deletion");
|
|
124
|
+
if (reference && deletion) {
|
|
125
|
+
const { id, noteType } = expectFootnoteRefMarkAttrs(reference);
|
|
126
|
+
deletions.set(noteKey(noteType === "endnote" ? "endnote" : "footnote", Number(id)), deletion);
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
});
|
|
130
|
+
return deletions;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Delete a note's text and its paragraph marks along with its reference: by
|
|
134
|
+
* the reference deletion's author at its date, so resolving the reference
|
|
135
|
+
* resolves them too (see {@link noteDeletionRevisions}).
|
|
136
|
+
*/
|
|
137
|
+
const deleteNoteWithReference = (transform, reference) => {
|
|
138
|
+
const doc = transform.doc;
|
|
139
|
+
const markInfo = {
|
|
140
|
+
id: mintRevisionId(),
|
|
141
|
+
author: String(reference.attrs["author"] ?? ""),
|
|
142
|
+
date: String(reference.attrs["date"] ?? "")
|
|
143
|
+
};
|
|
144
|
+
const { utcDate, initials } = reference.attrs;
|
|
145
|
+
const deletion = (doc.type.schema.marks["deletion"] ?? reference.type).create({
|
|
146
|
+
revisionId: mintRevisionId(),
|
|
147
|
+
author: markInfo.author,
|
|
148
|
+
date: markInfo.date,
|
|
149
|
+
...utcDate != null && { utcDate },
|
|
150
|
+
...initials != null && { initials }
|
|
151
|
+
});
|
|
152
|
+
doc.descendants((node, position) => {
|
|
153
|
+
if (node.type.name === "paragraph" && expectParagraphAttrs(node).pPrMark == null) transform.setNodeAttribute(position, "pPrMark", {
|
|
154
|
+
kind: "del",
|
|
155
|
+
info: markInfo
|
|
156
|
+
});
|
|
157
|
+
if (node.isInline && !deletion.type.isInSet(node.marks)) transform.addMark(position, position + node.nodeSize, deletion);
|
|
158
|
+
return !node.isInline;
|
|
159
|
+
});
|
|
160
|
+
return transform;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* A note whose reference was deleted: its text and its paragraph marks are
|
|
164
|
+
* deleted too, by the reference's author at the reference's date.
|
|
165
|
+
*/
|
|
166
|
+
const deletedNote = (note, document, reference) => {
|
|
167
|
+
const { styles, theme } = document.package;
|
|
168
|
+
const doc = footnoteToProseDoc(note.content, {
|
|
169
|
+
...styles !== void 0 && { styles },
|
|
170
|
+
...theme !== void 0 && { theme }
|
|
171
|
+
});
|
|
172
|
+
const transform = deleteNoteWithReference(new Transform(doc), reference);
|
|
173
|
+
if (!transform.docChanged) return note;
|
|
174
|
+
return {
|
|
175
|
+
...note,
|
|
176
|
+
content: proseDocToBlocks(transform.doc, note.content, styles)
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
const editNotes = (document, edits) => {
|
|
180
|
+
if (edits.size === 0) return document;
|
|
181
|
+
const edit = (kind, notes) => {
|
|
182
|
+
if (!notes?.some((note) => edits.has(noteKey(kind, note.id)))) return notes;
|
|
183
|
+
return notes.map((note) => edits.get(noteKey(kind, note.id))?.(note) ?? note);
|
|
184
|
+
};
|
|
185
|
+
const footnotes = edit("footnote", document.package.footnotes);
|
|
186
|
+
const endnotes = edit("endnote", document.package.endnotes);
|
|
187
|
+
if (footnotes === document.package.footnotes && endnotes === document.package.endnotes) return document;
|
|
188
|
+
return {
|
|
189
|
+
...document,
|
|
190
|
+
package: {
|
|
191
|
+
...document.package,
|
|
192
|
+
...footnotes !== void 0 && { footnotes },
|
|
193
|
+
...endnotes !== void 0 && { endnotes }
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
const createNoteReferenceFollower = () => {
|
|
198
|
+
let base = null;
|
|
199
|
+
const replaced = /* @__PURE__ */ new Map();
|
|
200
|
+
const pending = /* @__PURE__ */ new Map();
|
|
201
|
+
const recorded = (key, edit) => (note) => {
|
|
202
|
+
const result = edit(note);
|
|
203
|
+
if (result !== note) pending.set(key, {
|
|
204
|
+
from: note,
|
|
205
|
+
to: result
|
|
206
|
+
});
|
|
207
|
+
return result;
|
|
208
|
+
};
|
|
209
|
+
return {
|
|
210
|
+
noteBase: (before) => {
|
|
211
|
+
base ??= before;
|
|
212
|
+
},
|
|
213
|
+
reconcile: (document, body) => {
|
|
214
|
+
const before = base;
|
|
215
|
+
base = null;
|
|
216
|
+
if (!before) return document;
|
|
217
|
+
const was = noteReferenceStates(before);
|
|
218
|
+
const now = noteReferenceStates(body);
|
|
219
|
+
const deletions = referenceDeletions(body);
|
|
220
|
+
const rejected = referenceDeletions(before);
|
|
221
|
+
const edits = /* @__PURE__ */ new Map();
|
|
222
|
+
for (const [key, state] of now) {
|
|
223
|
+
const previous = was.get(key);
|
|
224
|
+
const rejectedDeletion = rejected.get(key);
|
|
225
|
+
if (state === "live" && previous === "deleted" && rejectedDeletion) edits.set(key, recorded(key, (note) => {
|
|
226
|
+
const restored = restoredNote(note, document, rejectedDeletion);
|
|
227
|
+
if (restored !== note) replaced.set(key, {
|
|
228
|
+
restored,
|
|
229
|
+
previous: note
|
|
230
|
+
});
|
|
231
|
+
return restored;
|
|
232
|
+
}));
|
|
233
|
+
const reference = deletions.get(key);
|
|
234
|
+
if (state === "deleted" && previous === "live" && reference) edits.set(key, recorded(key, (note) => {
|
|
235
|
+
const earlier = replaced.get(key);
|
|
236
|
+
replaced.delete(key);
|
|
237
|
+
return earlier?.restored === note ? earlier.previous : deletedNote(note, document, reference);
|
|
238
|
+
}));
|
|
239
|
+
}
|
|
240
|
+
return editNotes(document, edits);
|
|
241
|
+
},
|
|
242
|
+
withPending: (document) => {
|
|
243
|
+
const edits = /* @__PURE__ */ new Map();
|
|
244
|
+
for (const [key, { from, to }] of pending) edits.set(key, (note) => {
|
|
245
|
+
if (note !== from) pending.delete(key);
|
|
246
|
+
return note === from ? to : note;
|
|
247
|
+
});
|
|
248
|
+
return editNotes(document, edits);
|
|
249
|
+
},
|
|
250
|
+
reset: () => {
|
|
251
|
+
base = null;
|
|
252
|
+
replaced.clear();
|
|
253
|
+
pending.clear();
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
/** The notes model content refers to, live or pending deletion. */
|
|
258
|
+
const noteKeysReferencedIn = (content) => {
|
|
259
|
+
const keys = /* @__PURE__ */ new Set();
|
|
260
|
+
const visit = (node) => {
|
|
261
|
+
if (Array.isArray(node)) {
|
|
262
|
+
for (const item of node) visit(item);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (node === null || typeof node !== "object") return;
|
|
266
|
+
const { type, id } = node;
|
|
267
|
+
if ((type === "footnoteRef" || type === "endnoteRef") && typeof id === "number") keys.add(noteKey(type === "footnoteRef" ? "footnote" : "endnote", id));
|
|
268
|
+
for (const value of Object.values(node)) visit(value);
|
|
269
|
+
};
|
|
270
|
+
visit(content);
|
|
271
|
+
return keys;
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* The notes anything refers to, live or pending deletion: the main story, and
|
|
275
|
+
* the stories the body does not hold (headers, footers, comments, notes).
|
|
276
|
+
* References inside the `skipped` notes do not count: those notes are going.
|
|
277
|
+
*/
|
|
278
|
+
const referencedNotes = (document, skipped = /* @__PURE__ */ new Set()) => {
|
|
279
|
+
const { headers, footers, footnotes, endnotes } = document.package;
|
|
280
|
+
const kept = (kind) => (note) => !skipped.has(noteKey(kind, note.id));
|
|
281
|
+
return noteKeysReferencedIn([
|
|
282
|
+
document.package.document.content,
|
|
283
|
+
[...headers?.values() ?? [], ...footers?.values() ?? []],
|
|
284
|
+
document.package.document.comments ?? [],
|
|
285
|
+
(footnotes ?? []).filter(kept("footnote")),
|
|
286
|
+
(endnotes ?? []).filter(kept("endnote"))
|
|
287
|
+
]);
|
|
288
|
+
};
|
|
289
|
+
/** Ids of the comments anchored anywhere in these stories. */
|
|
290
|
+
const anchoredComments = (stories) => {
|
|
291
|
+
const ids = /* @__PURE__ */ new Set();
|
|
292
|
+
for (const blocks of stories) visitCommentMarkers(blocks, ({ item }) => ids.add(item.id));
|
|
293
|
+
return ids;
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* The document without the notes nothing refers to any more: a note goes
|
|
297
|
+
* with its reference, so accepting the reference's deletion leaves a note no
|
|
298
|
+
* reader can reach, and saving drops it, with the comments anchored only in
|
|
299
|
+
* it. Separators stay.
|
|
300
|
+
*/
|
|
301
|
+
const withoutUnreferencedNotes = (document) => {
|
|
302
|
+
const referenced = referencedNotes(document);
|
|
303
|
+
const { footnotes, endnotes, headers, footers } = document.package;
|
|
304
|
+
const keeps = (kind) => (note) => (kind === "footnote" ? isSeparatorFootnote(note) : isSeparatorEndnote(note)) || referenced.has(noteKey(kind, note.id));
|
|
305
|
+
const keptFootnotes = footnotes?.filter(keeps("footnote"));
|
|
306
|
+
const keptEndnotes = endnotes?.filter(keeps("endnote"));
|
|
307
|
+
if (keptFootnotes?.length === footnotes?.length && keptEndnotes?.length === endnotes?.length) return document;
|
|
308
|
+
const removed = [...(footnotes ?? []).filter((note) => !keeps("footnote")(note)), ...(endnotes ?? []).filter((note) => !keeps("endnote")(note))];
|
|
309
|
+
const comments = document.package.document.comments;
|
|
310
|
+
const keptComments = comments ? withoutLostCommentThreads(comments, {
|
|
311
|
+
anchoredBefore: anchoredComments(removed.map((note) => note.content)),
|
|
312
|
+
anchoredNow: anchoredComments([
|
|
313
|
+
document.package.document.content,
|
|
314
|
+
...[...headers?.values() ?? [], ...footers?.values() ?? []].map((part) => part.content),
|
|
315
|
+
...[...keptFootnotes ?? [], ...keptEndnotes ?? []].map((note) => note.content)
|
|
316
|
+
])
|
|
317
|
+
}) : void 0;
|
|
318
|
+
return {
|
|
319
|
+
...document,
|
|
320
|
+
package: {
|
|
321
|
+
...document.package,
|
|
322
|
+
...keptFootnotes !== void 0 && { footnotes: keptFootnotes },
|
|
323
|
+
...keptEndnotes !== void 0 && { endnotes: keptEndnotes },
|
|
324
|
+
...keptComments !== void 0 && keptComments.length !== comments?.length && { document: {
|
|
325
|
+
...document.package.document,
|
|
326
|
+
comments: keptComments
|
|
327
|
+
} }
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
//#endregion
|
|
332
|
+
export { createNoteReferenceFollower, deleteNoteWithReference, noteDeletionRevisions, noteKeysReferencedIn, noteReferenceStates, noteReferencesRestored, referenceDeletions, referencedNotes, restoreNotes, withoutUnreferencedNotes };
|
|
@@ -22,6 +22,14 @@ type ParagraphNumberingAttr = ParagraphNumberingOverride & {
|
|
|
22
22
|
};
|
|
23
23
|
/** Mint the attr value for a stated override: the one model-to-attr crossing. */
|
|
24
24
|
declare const paragraphNumberingAttr: (numbering: ParagraphNumberingOverride) => ParagraphNumberingAttr;
|
|
25
|
+
/**
|
|
26
|
+
* The `numPr` that takes a paragraph out of its list. When its style supplies
|
|
27
|
+
* the numbering, the paragraph has to state the cancellation (`w:numId="0"`):
|
|
28
|
+
* clearing the attr would uncover the style tier, and the next save hands the
|
|
29
|
+
* numbering straight back. A cancellation states no level (17.9.18: there is
|
|
30
|
+
* no id left for a level to belong to).
|
|
31
|
+
*/
|
|
32
|
+
declare const removedNumberingAttr: (numPrFromStyle: ParagraphNumberingOverride | null | undefined) => ParagraphNumberingAttr | null;
|
|
25
33
|
/**
|
|
26
34
|
* The one shape check over a persisted `numPr` attr.
|
|
27
35
|
*
|
|
@@ -52,4 +60,4 @@ declare const paragraphNumberingFromAttrValue: (value: unknown) => ParagraphNumb
|
|
|
52
60
|
*/
|
|
53
61
|
declare const readParagraphNumberingAttr: (value: unknown) => ParagraphNumberingAttr | null;
|
|
54
62
|
//#endregion
|
|
55
|
-
export { ParagraphNumberingAttr, paragraphNumberingAttr, paragraphNumberingFromAttrValue, readParagraphNumberingAttr };
|
|
63
|
+
export { ParagraphNumberingAttr, paragraphNumberingAttr, paragraphNumberingFromAttrValue, readParagraphNumberingAttr, removedNumberingAttr };
|