@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DocScanState } from "./createDocScanPlugin.js";
|
|
2
|
-
import { EditorState, PluginKey } from "prosemirror-state";
|
|
3
2
|
import { Node } from "prosemirror-model";
|
|
3
|
+
import { EditorState, PluginKey } from "prosemirror-state";
|
|
4
4
|
import { DirectiveKind } from "@stll/template-conditions";
|
|
5
5
|
//#region src/prosemirror/plugins/templateDirectives.d.ts
|
|
6
6
|
type DirectiveRange = {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { EditorState, Plugin, Transaction } from "prosemirror-state";
|
|
2
|
+
//#region src/prosemirror/plugins/transactionInvariants.d.ts
|
|
3
|
+
type TransactionInvariantFlags = {
|
|
4
|
+
/** Install the invariant plugin in every extension-manager runtime. */
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare global {
|
|
8
|
+
var __folioTransactionInvariants: TransactionInvariantFlags | undefined;
|
|
9
|
+
}
|
|
10
|
+
/** Whether new extension-manager runtimes install the invariant plugin. */
|
|
11
|
+
declare const areTransactionInvariantsEnabled: () => boolean;
|
|
12
|
+
type TransactionInvariantIssue = {
|
|
13
|
+
path: string;
|
|
14
|
+
message: string;
|
|
15
|
+
/** Position of the node the issue sits on, when the check knows it. */
|
|
16
|
+
pos?: number;
|
|
17
|
+
};
|
|
18
|
+
declare class TransactionInvariantError extends Error {
|
|
19
|
+
readonly issues: readonly TransactionInvariantIssue[];
|
|
20
|
+
readonly steps: readonly unknown[];
|
|
21
|
+
constructor(issues: readonly TransactionInvariantIssue[], transactions: readonly Transaction[]);
|
|
22
|
+
}
|
|
23
|
+
/** Every invariant the state breaks; empty when it is sound. */
|
|
24
|
+
declare const checkEditorStateInvariants: (state: EditorState) => TransactionInvariantIssue[];
|
|
25
|
+
/**
|
|
26
|
+
* Throw a {@link TransactionInvariantError} naming the offending steps when a
|
|
27
|
+
* document-changing transaction leaves the state with an issue it did not
|
|
28
|
+
* have before.
|
|
29
|
+
*/
|
|
30
|
+
declare const createTransactionInvariantPlugin: () => Plugin;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { TransactionInvariantError, TransactionInvariantFlags, TransactionInvariantIssue, areTransactionInvariantsEnabled, checkEditorStateInvariants, createTransactionInvariantPlugin };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { paragraphNumberingReferenceId } from "../../docx/numberingReference.js";
|
|
2
|
+
import { validateProseMirrorDocument } from "../validation.js";
|
|
3
|
+
import { getDocumentNumbering, hasDocumentNumbering } from "./documentNumbering.js";
|
|
4
|
+
import { Plugin, PluginKey } from "prosemirror-state";
|
|
5
|
+
//#region src/prosemirror/plugins/transactionInvariants.ts
|
|
6
|
+
/** Whether new extension-manager runtimes install the invariant plugin. */
|
|
7
|
+
const areTransactionInvariantsEnabled = () => globalThis.__folioTransactionInvariants?.enabled === true;
|
|
8
|
+
const MAX_REPORTED_STEPS_LENGTH = 4e3;
|
|
9
|
+
const describeSteps = (transactions) => {
|
|
10
|
+
const steps = transactions.flatMap((transaction) => transaction.steps.map((step) => step.toJSON()));
|
|
11
|
+
const json = JSON.stringify(steps);
|
|
12
|
+
return json.length > MAX_REPORTED_STEPS_LENGTH ? `${json.slice(0, MAX_REPORTED_STEPS_LENGTH)}… (${json.length} characters)` : json;
|
|
13
|
+
};
|
|
14
|
+
var TransactionInvariantError = class extends Error {
|
|
15
|
+
issues;
|
|
16
|
+
steps;
|
|
17
|
+
constructor(issues, transactions) {
|
|
18
|
+
super(`A transaction left the editor document invalid:\n${issues.map((issue) => `- ${issue.path}: ${issue.message}`).join("\n")}\nSteps: ${describeSteps(transactions)}`);
|
|
19
|
+
this.name = "TransactionInvariantError";
|
|
20
|
+
this.issues = issues;
|
|
21
|
+
this.steps = transactions.flatMap((transaction) => transaction.steps.map((step) => step.toJSON()));
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const numberingReferenceIssues = (state) => {
|
|
25
|
+
if (!hasDocumentNumbering(state)) return [];
|
|
26
|
+
const numbering = getDocumentNumbering(state);
|
|
27
|
+
const issues = [];
|
|
28
|
+
state.doc.descendants((node, pos) => {
|
|
29
|
+
if (node.type.name !== "paragraph") return true;
|
|
30
|
+
const numId = paragraphNumberingReferenceId(node.attrs["numPr"]);
|
|
31
|
+
if (numId !== void 0 && !numbering?.hasNumbering(numId)) issues.push({
|
|
32
|
+
path: `paragraph at ${pos}.numPr.numId`,
|
|
33
|
+
message: `Numbering definition ${numId} is missing.`,
|
|
34
|
+
pos
|
|
35
|
+
});
|
|
36
|
+
return false;
|
|
37
|
+
});
|
|
38
|
+
return issues;
|
|
39
|
+
};
|
|
40
|
+
/** Every invariant the state breaks; empty when it is sound. */
|
|
41
|
+
const checkEditorStateInvariants = (state) => [...validateProseMirrorDocument(state.doc).issues, ...numberingReferenceIssues(state)];
|
|
42
|
+
/**
|
|
43
|
+
* The issues `after` has that `before` did not. A document can arrive broken
|
|
44
|
+
* (a malformed attribute the editor tolerates); only what a transaction adds
|
|
45
|
+
* is the transaction's fault. An issue that names its node persists only on
|
|
46
|
+
* that node, followed through the transactions' mappings, so moving a broken
|
|
47
|
+
* reference from one paragraph to another still counts as new. Issues without
|
|
48
|
+
* a position are matched by message, since their paths move with the edit.
|
|
49
|
+
*/
|
|
50
|
+
const introducedIssues = (before, after, transactions) => {
|
|
51
|
+
const mapPosition = (pos) => {
|
|
52
|
+
let mapped = pos;
|
|
53
|
+
for (const transaction of transactions) mapped = transaction.mapping.map(mapped, 1);
|
|
54
|
+
return mapped;
|
|
55
|
+
};
|
|
56
|
+
const persisting = /* @__PURE__ */ new Set();
|
|
57
|
+
const remaining = /* @__PURE__ */ new Map();
|
|
58
|
+
for (const issue of before) if (issue.pos === void 0) remaining.set(issue.message, (remaining.get(issue.message) ?? 0) + 1);
|
|
59
|
+
else persisting.add(`${mapPosition(issue.pos)}:${issue.message}`);
|
|
60
|
+
return after.filter((issue) => {
|
|
61
|
+
if (issue.pos !== void 0) return !persisting.has(`${issue.pos}:${issue.message}`);
|
|
62
|
+
const count = remaining.get(issue.message) ?? 0;
|
|
63
|
+
if (count === 0) return true;
|
|
64
|
+
remaining.set(issue.message, count - 1);
|
|
65
|
+
return false;
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
const transactionInvariantsKey = new PluginKey("transactionInvariants");
|
|
69
|
+
/**
|
|
70
|
+
* Throw a {@link TransactionInvariantError} naming the offending steps when a
|
|
71
|
+
* document-changing transaction leaves the state with an issue it did not
|
|
72
|
+
* have before.
|
|
73
|
+
*/
|
|
74
|
+
const createTransactionInvariantPlugin = () => new Plugin({
|
|
75
|
+
key: transactionInvariantsKey,
|
|
76
|
+
appendTransaction(transactions, oldState, newState) {
|
|
77
|
+
if (!transactions.some((transaction) => transaction.docChanged)) return null;
|
|
78
|
+
const issues = checkEditorStateInvariants(newState);
|
|
79
|
+
if (issues.length === 0) return null;
|
|
80
|
+
const introduced = introducedIssues(checkEditorStateInvariants(oldState), issues, transactions);
|
|
81
|
+
if (introduced.length > 0) throw new TransactionInvariantError(introduced, transactions);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
//#endregion
|
|
86
|
+
export { TransactionInvariantError, areTransactionInvariantsEnabled, checkEditorStateInvariants, createTransactionInvariantPlugin };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Mapping } from "prosemirror-transform";
|
|
2
|
+
//#region src/prosemirror/positionSweep.d.ts
|
|
3
|
+
type PositionQuery = {
|
|
4
|
+
pos: number;
|
|
5
|
+
assoc: -1 | 1;
|
|
6
|
+
/**
|
|
7
|
+
* Index of the first step map to apply, counting across every mapping
|
|
8
|
+
* passed in order: the position is in the document that step read.
|
|
9
|
+
*/
|
|
10
|
+
from: number;
|
|
11
|
+
};
|
|
12
|
+
type SweptPosition = {
|
|
13
|
+
pos: number;
|
|
14
|
+
deletedAcross: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Map every query through `mappings` (one per transaction, in order), each
|
|
18
|
+
* entering at its own step. O((positions + steps) x log positions) plus the
|
|
19
|
+
* positions a step's changed ranges actually cover, rather than
|
|
20
|
+
* O(positions x steps).
|
|
21
|
+
*/
|
|
22
|
+
declare const sweepPositions: (mappings: readonly Mapping[], queries: readonly PositionQuery[]) => SweptPosition[];
|
|
23
|
+
//#endregion
|
|
24
|
+
export { PositionQuery, SweptPosition, sweepPositions };
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
//#region src/prosemirror/positionSweep.ts
|
|
2
|
+
/** Positions kept per chunk before it splits; small enough to splice cheaply. */
|
|
3
|
+
const CHUNK_SIZE = 128;
|
|
4
|
+
const cursorBefore = (left, right) => left.chunk < right.chunk || left.chunk === right.chunk && left.index < right.index;
|
|
5
|
+
/** Positions sharing one `assoc`, sorted by their current value. */
|
|
6
|
+
var Lane = class {
|
|
7
|
+
chunks = [];
|
|
8
|
+
assoc;
|
|
9
|
+
constructor(assoc) {
|
|
10
|
+
this.assoc = assoc;
|
|
11
|
+
}
|
|
12
|
+
get isEmpty() {
|
|
13
|
+
return this.chunks.length === 0;
|
|
14
|
+
}
|
|
15
|
+
/** Replace an empty lane's contents with `entries`, sorted by value. */
|
|
16
|
+
load(entries) {
|
|
17
|
+
for (let start = 0; start < entries.length; start += CHUNK_SIZE) {
|
|
18
|
+
const slice = entries.slice(start, start + CHUNK_SIZE);
|
|
19
|
+
this.chunks.push({
|
|
20
|
+
shift: 0,
|
|
21
|
+
values: slice.map(([value]) => value),
|
|
22
|
+
ids: slice.map(([, id]) => id)
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
insert(value, id) {
|
|
27
|
+
if (!this.chunks.at(-1)) {
|
|
28
|
+
this.chunks.push({
|
|
29
|
+
shift: 0,
|
|
30
|
+
values: [value],
|
|
31
|
+
ids: [id]
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const cursor = this.bound(value, true);
|
|
36
|
+
const chunkIndex = Math.min(cursor.chunk, this.chunks.length - 1);
|
|
37
|
+
const chunk = this.chunks[chunkIndex];
|
|
38
|
+
const index = cursor.chunk === chunkIndex ? cursor.index : chunk.values.length;
|
|
39
|
+
chunk.values.splice(index, 0, value - chunk.shift);
|
|
40
|
+
chunk.ids.splice(index, 0, id);
|
|
41
|
+
if (chunk.values.length > 2 * CHUNK_SIZE) this.chunks.splice(chunkIndex + 1, 0, {
|
|
42
|
+
shift: chunk.shift,
|
|
43
|
+
values: chunk.values.splice(CHUNK_SIZE),
|
|
44
|
+
ids: chunk.ids.splice(CHUNK_SIZE)
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The first entry whose value is at least `value` (`strict`: greater than
|
|
49
|
+
* it), or the end of the lane.
|
|
50
|
+
*/
|
|
51
|
+
bound(value, strict) {
|
|
52
|
+
const passes = (candidate) => strict ? candidate > value : candidate >= value;
|
|
53
|
+
let low = 0;
|
|
54
|
+
let high = this.chunks.length;
|
|
55
|
+
while (low < high) {
|
|
56
|
+
const middle = low + high >>> 1;
|
|
57
|
+
const chunk = this.chunks[middle];
|
|
58
|
+
if (passes(chunk.values.at(-1) + chunk.shift)) high = middle;
|
|
59
|
+
else low = middle + 1;
|
|
60
|
+
}
|
|
61
|
+
const chunk = this.chunks[low];
|
|
62
|
+
if (!chunk) return {
|
|
63
|
+
chunk: this.chunks.length,
|
|
64
|
+
index: 0
|
|
65
|
+
};
|
|
66
|
+
let first = 0;
|
|
67
|
+
let last = chunk.values.length;
|
|
68
|
+
while (first < last) {
|
|
69
|
+
const middle = first + last >>> 1;
|
|
70
|
+
if (passes(chunk.values[middle] + chunk.shift)) last = middle;
|
|
71
|
+
else first = middle + 1;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
chunk: low,
|
|
75
|
+
index: first
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** Visit every entry from `start` up to, not including, `end`. */
|
|
79
|
+
forEachBetween(start, end, visit) {
|
|
80
|
+
for (let chunkIndex = start.chunk; chunkIndex <= end.chunk; chunkIndex++) {
|
|
81
|
+
const chunk = this.chunks[chunkIndex];
|
|
82
|
+
if (!chunk) return;
|
|
83
|
+
const first = chunkIndex === start.chunk ? start.index : 0;
|
|
84
|
+
const last = chunkIndex === end.chunk ? end.index : chunk.values.length;
|
|
85
|
+
for (let index = first; index < last; index++) visit(chunk, index);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** Add `delta` to every entry from `start` to the end of the lane. */
|
|
89
|
+
shiftFrom(start, end, delta) {
|
|
90
|
+
if (delta === 0) return;
|
|
91
|
+
const stop = end ?? {
|
|
92
|
+
chunk: this.chunks.length,
|
|
93
|
+
index: 0
|
|
94
|
+
};
|
|
95
|
+
for (let chunkIndex = start.chunk; chunkIndex <= stop.chunk; chunkIndex++) {
|
|
96
|
+
const chunk = this.chunks[chunkIndex];
|
|
97
|
+
if (!chunk) return;
|
|
98
|
+
const first = chunkIndex === start.chunk ? start.index : 0;
|
|
99
|
+
const last = chunkIndex === stop.chunk ? stop.index : chunk.values.length;
|
|
100
|
+
if (first === 0 && last === chunk.values.length) {
|
|
101
|
+
chunk.shift += delta;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
for (let index = first; index < last; index++) chunk.values[index] += delta;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
apply(map, deletedAcross) {
|
|
108
|
+
if (this.chunks.length === 0) return;
|
|
109
|
+
const ranges = [];
|
|
110
|
+
let previousEnd = {
|
|
111
|
+
chunk: 0,
|
|
112
|
+
index: 0
|
|
113
|
+
};
|
|
114
|
+
map.forEach((oldStart, oldEnd, newStart, newEnd) => {
|
|
115
|
+
const lower = this.bound(oldStart, false);
|
|
116
|
+
const start = cursorBefore(lower, previousEnd) ? previousEnd : lower;
|
|
117
|
+
const end = this.bound(oldEnd, true);
|
|
118
|
+
ranges.push({
|
|
119
|
+
start,
|
|
120
|
+
end,
|
|
121
|
+
delta: newEnd - newStart - (oldEnd - oldStart)
|
|
122
|
+
});
|
|
123
|
+
previousEnd = end;
|
|
124
|
+
});
|
|
125
|
+
let cursor = {
|
|
126
|
+
chunk: 0,
|
|
127
|
+
index: 0
|
|
128
|
+
};
|
|
129
|
+
let delta = 0;
|
|
130
|
+
for (const range of ranges) {
|
|
131
|
+
this.shiftFrom(cursor, range.start, delta);
|
|
132
|
+
this.forEachBetween(range.start, range.end, (chunk, index) => {
|
|
133
|
+
const result = map.mapResult(chunk.values[index] + chunk.shift, this.assoc);
|
|
134
|
+
chunk.values[index] = result.pos - chunk.shift;
|
|
135
|
+
if (result.deletedAcross) deletedAcross[chunk.ids[index]] = true;
|
|
136
|
+
});
|
|
137
|
+
delta += range.delta;
|
|
138
|
+
cursor = range.end;
|
|
139
|
+
}
|
|
140
|
+
this.shiftFrom(cursor, null, delta);
|
|
141
|
+
}
|
|
142
|
+
collect(positions) {
|
|
143
|
+
for (const chunk of this.chunks) for (let index = 0; index < chunk.values.length; index++) positions[chunk.ids[index]] = chunk.values[index] + chunk.shift;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const hasMirrors = (mapping) => {
|
|
147
|
+
for (let index = mapping.from; index < mapping.to; index++) if (mapping.getMirror(index) !== void 0) return true;
|
|
148
|
+
return false;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* The per-step walk, kept for mappings that carry mirror pairs (collaborative
|
|
152
|
+
* rebases): a mirrored map recovers a deleted position from its twin, which
|
|
153
|
+
* only a walk through every map can see.
|
|
154
|
+
*/
|
|
155
|
+
const mapPerStep = (mappings, queries) => queries.map(({ pos, assoc, from }) => {
|
|
156
|
+
let mapped = pos;
|
|
157
|
+
let deletedAcross = false;
|
|
158
|
+
let offset = 0;
|
|
159
|
+
for (const mapping of mappings) {
|
|
160
|
+
const length = mapping.to - mapping.from;
|
|
161
|
+
if (from < offset + length) {
|
|
162
|
+
const result = mapping.slice(mapping.from + Math.max(0, from - offset), mapping.to).mapResult(mapped, assoc);
|
|
163
|
+
mapped = result.pos;
|
|
164
|
+
deletedAcross ||= result.deletedAcross;
|
|
165
|
+
}
|
|
166
|
+
offset += length;
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
pos: mapped,
|
|
170
|
+
deletedAcross
|
|
171
|
+
};
|
|
172
|
+
});
|
|
173
|
+
/**
|
|
174
|
+
* Map every query through `mappings` (one per transaction, in order), each
|
|
175
|
+
* entering at its own step. O((positions + steps) x log positions) plus the
|
|
176
|
+
* positions a step's changed ranges actually cover, rather than
|
|
177
|
+
* O(positions x steps).
|
|
178
|
+
*/
|
|
179
|
+
const sweepPositions = (mappings, queries) => {
|
|
180
|
+
if (queries.length === 0) return [];
|
|
181
|
+
if (mappings.some(hasMirrors)) return mapPerStep(mappings, queries);
|
|
182
|
+
const maps = mappings.flatMap((mapping) => mapping.maps.slice(mapping.from, mapping.to));
|
|
183
|
+
const order = queries.map((query, id) => ({
|
|
184
|
+
id,
|
|
185
|
+
from: Math.min(Math.max(query.from, 0), maps.length)
|
|
186
|
+
})).sort((left, right) => left.from - right.from || left.id - right.id);
|
|
187
|
+
const backward = new Lane(-1);
|
|
188
|
+
const forward = new Lane(1);
|
|
189
|
+
const deletedAcross = queries.map(() => false);
|
|
190
|
+
let next = 0;
|
|
191
|
+
const enter = (step) => {
|
|
192
|
+
const entering = /* @__PURE__ */ new Map([[backward, []], [forward, []]]);
|
|
193
|
+
for (; next < order.length && order[next].from === step; next++) {
|
|
194
|
+
const { id } = order[next];
|
|
195
|
+
const query = queries[id];
|
|
196
|
+
entering.get(query.assoc < 0 ? backward : forward).push([query.pos, id]);
|
|
197
|
+
}
|
|
198
|
+
for (const [lane, entries] of entering) {
|
|
199
|
+
if (lane.isEmpty) {
|
|
200
|
+
lane.load(entries.sort((left, right) => left[0] - right[0]));
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
for (const [value, id] of entries) lane.insert(value, id);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
for (let step = 0; step < maps.length; step++) {
|
|
207
|
+
if (next < order.length && order[next].from === step) enter(step);
|
|
208
|
+
const map = maps[step];
|
|
209
|
+
backward.apply(map, deletedAcross);
|
|
210
|
+
forward.apply(map, deletedAcross);
|
|
211
|
+
}
|
|
212
|
+
if (next < order.length) enter(maps.length);
|
|
213
|
+
const positions = queries.map(({ pos }) => pos);
|
|
214
|
+
backward.collect(positions);
|
|
215
|
+
forward.collect(positions);
|
|
216
|
+
return positions.map((pos, id) => ({
|
|
217
|
+
pos,
|
|
218
|
+
deletedAcross: deletedAcross[id] ?? false
|
|
219
|
+
}));
|
|
220
|
+
};
|
|
221
|
+
//#endregion
|
|
222
|
+
export { sweepPositions };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { RunStyleResolver } from "./runStyleFormatting.js";
|
|
2
|
-
import { Transaction } from "prosemirror-state";
|
|
1
|
+
import { ParagraphRunStyleContext, RunStyleResolver } from "./runStyleFormatting.js";
|
|
3
2
|
import { Node } from "prosemirror-model";
|
|
3
|
+
import { Transaction } from "prosemirror-state";
|
|
4
|
+
import { Transform } from "prosemirror-transform";
|
|
4
5
|
//#region src/prosemirror/rebaseParagraphRunFormatting.d.ts
|
|
5
6
|
type RebaseParagraphRunFormattingOptions = {
|
|
6
7
|
nextAttrs: Record<string, unknown>;
|
|
@@ -9,10 +10,29 @@ type RebaseParagraphRunFormattingOptions = {
|
|
|
9
10
|
styleResolver: RunStyleResolver;
|
|
10
11
|
tr: Transaction;
|
|
11
12
|
};
|
|
13
|
+
type RebaseParagraphRunsOptions<T extends Transform> = {
|
|
14
|
+
/** The style context the runs' marks were resolved in. */
|
|
15
|
+
previousContext: ParagraphRunStyleContext;
|
|
16
|
+
paragraphPosition: number;
|
|
17
|
+
/** Content offsets inside the paragraph to rebase; all of it when omitted. */
|
|
18
|
+
range?: {
|
|
19
|
+
from: number;
|
|
20
|
+
to: number;
|
|
21
|
+
};
|
|
22
|
+
shouldRebase?: (node: Node) => boolean;
|
|
23
|
+
styleResolver: RunStyleResolver;
|
|
24
|
+
tr: T;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Re-resolve the inherited marks of runs resolved in `previousContext` in the
|
|
28
|
+
* paragraph's current style context: direct formatting stays direct, and what
|
|
29
|
+
* the old context lent the runs goes with it.
|
|
30
|
+
*/
|
|
31
|
+
declare const rebaseParagraphRuns: <T extends Transform>({ previousContext, paragraphPosition, range, shouldRebase, styleResolver, tr }: RebaseParagraphRunsOptions<T>) => T;
|
|
12
32
|
/**
|
|
13
33
|
* Change paragraph attrs and re-resolve inherited run marks in the new style
|
|
14
34
|
* context without turning the old rendered style into direct run formatting.
|
|
15
35
|
*/
|
|
16
36
|
declare const setParagraphAttrsWithRebasedRunFormatting: ({ nextAttrs, paragraphPosition, shouldRebase, styleResolver, tr }: RebaseParagraphRunFormattingOptions) => Transaction;
|
|
17
37
|
//#endregion
|
|
18
|
-
export { setParagraphAttrsWithRebasedRunFormatting };
|
|
38
|
+
export { rebaseParagraphRuns, setParagraphAttrsWithRebasedRunFormatting };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sameRunStyleContext } from "./rebaseParagraphRuns.js";
|
|
1
2
|
import { expandRunFormattingCarrier } from "./runFormattingInlineCarriers.js";
|
|
2
3
|
import { RUN_FORMATTING_MARK_NAMES } from "./runFormattingMarkNames.js";
|
|
3
4
|
import { readAuthoredRunFormatting, reconcileRunFormattingMarks } from "./runFormattingReconciliation.js";
|
|
@@ -5,18 +6,23 @@ import { paragraphRunStyleContext } from "./runStyleFormatting.js";
|
|
|
5
6
|
import { panic } from "better-result";
|
|
6
7
|
import { Mark } from "prosemirror-model";
|
|
7
8
|
//#region src/prosemirror/rebaseParagraphRunFormatting.ts
|
|
8
|
-
|
|
9
|
-
* Change paragraph attrs and re-resolve inherited run marks in the new style
|
|
10
|
-
* context without turning the old rendered style into direct run formatting.
|
|
11
|
-
*/
|
|
12
|
-
const setParagraphAttrsWithRebasedRunFormatting = ({ nextAttrs, paragraphPosition, shouldRebase, styleResolver, tr }) => {
|
|
9
|
+
const paragraphAt = (tr, paragraphPosition) => {
|
|
13
10
|
const paragraph = tr.doc.nodeAt(paragraphPosition);
|
|
14
11
|
if (!paragraph || paragraph.type.name !== "paragraph") return panic("Cannot rebase run formatting outside a paragraph", {
|
|
15
12
|
nodeType: paragraph?.type.name,
|
|
16
13
|
paragraphPosition
|
|
17
14
|
});
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
return paragraph;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Re-resolve the inherited marks of runs resolved in `previousContext` in the
|
|
19
|
+
* paragraph's current style context: direct formatting stays direct, and what
|
|
20
|
+
* the old context lent the runs goes with it.
|
|
21
|
+
*/
|
|
22
|
+
const rebaseParagraphRuns = ({ previousContext, paragraphPosition, range, shouldRebase, styleResolver, tr }) => {
|
|
23
|
+
const paragraph = paragraphAt(tr, paragraphPosition);
|
|
24
|
+
const nextContext = paragraphRunStyleContext(paragraph, styleResolver);
|
|
25
|
+
if (sameRunStyleContext(previousContext, nextContext)) return tr;
|
|
20
26
|
const changes = [];
|
|
21
27
|
const collectRebasedRepresentation = ({ node, position }) => {
|
|
22
28
|
if (shouldRebase && !shouldRebase(node)) return;
|
|
@@ -31,23 +37,28 @@ const setParagraphAttrsWithRebasedRunFormatting = ({ nextAttrs, paragraphPositio
|
|
|
31
37
|
styleResolver
|
|
32
38
|
});
|
|
33
39
|
if (Mark.sameSet(node.marks, nextMarks)) return;
|
|
40
|
+
const start = paragraphPosition + 1;
|
|
41
|
+
const from = node.isText && range ? Math.max(position, start + range.from) : position;
|
|
42
|
+
const to = node.isText && range ? Math.min(position + node.nodeSize, start + range.to) : position + node.nodeSize;
|
|
43
|
+
if (to <= from) return;
|
|
34
44
|
changes.push({
|
|
35
45
|
attrs: node.attrs,
|
|
36
46
|
currentFormattingMarks: node.marks.filter(({ type }) => RUN_FORMATTING_MARK_NAMES.has(type.name)),
|
|
37
|
-
from
|
|
47
|
+
from,
|
|
38
48
|
isText: node.isText,
|
|
39
49
|
marks: nextMarks,
|
|
40
|
-
to
|
|
50
|
+
to
|
|
41
51
|
});
|
|
42
52
|
};
|
|
43
|
-
|
|
53
|
+
const visit = (node, relativePosition) => {
|
|
44
54
|
if (!node.isInline) return true;
|
|
45
55
|
const carrier = expandRunFormattingCarrier(node, paragraphPosition + 1 + relativePosition);
|
|
46
56
|
if (!carrier) return !node.isAtom;
|
|
47
57
|
for (const representation of carrier.representations) collectRebasedRepresentation(representation);
|
|
48
58
|
return false;
|
|
49
|
-
}
|
|
50
|
-
|
|
59
|
+
};
|
|
60
|
+
if (range === void 0) paragraph.descendants(visit);
|
|
61
|
+
else paragraph.nodesBetween(range.from, range.to, visit);
|
|
51
62
|
for (const { attrs, currentFormattingMarks, from, isText, marks, to } of changes) {
|
|
52
63
|
if (!isText) {
|
|
53
64
|
tr = tr.setNodeMarkup(from, void 0, attrs, marks);
|
|
@@ -58,5 +69,20 @@ const setParagraphAttrsWithRebasedRunFormatting = ({ nextAttrs, paragraphPositio
|
|
|
58
69
|
}
|
|
59
70
|
return tr;
|
|
60
71
|
};
|
|
72
|
+
/**
|
|
73
|
+
* Change paragraph attrs and re-resolve inherited run marks in the new style
|
|
74
|
+
* context without turning the old rendered style into direct run formatting.
|
|
75
|
+
*/
|
|
76
|
+
const setParagraphAttrsWithRebasedRunFormatting = ({ nextAttrs, paragraphPosition, shouldRebase, styleResolver, tr }) => {
|
|
77
|
+
const previousContext = paragraphRunStyleContext(paragraphAt(tr, paragraphPosition), styleResolver);
|
|
78
|
+
tr = tr.setNodeMarkup(paragraphPosition, void 0, nextAttrs);
|
|
79
|
+
return rebaseParagraphRuns({
|
|
80
|
+
previousContext,
|
|
81
|
+
paragraphPosition,
|
|
82
|
+
...shouldRebase ? { shouldRebase } : {},
|
|
83
|
+
styleResolver,
|
|
84
|
+
tr
|
|
85
|
+
});
|
|
86
|
+
};
|
|
61
87
|
//#endregion
|
|
62
|
-
export { setParagraphAttrsWithRebasedRunFormatting };
|
|
88
|
+
export { rebaseParagraphRuns, setParagraphAttrsWithRebasedRunFormatting };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ParagraphRunStyleContext, RunStyleResolver } from "./runStyleFormatting.js";
|
|
2
|
+
import { Fragment, Mark, Node } from "prosemirror-model";
|
|
3
|
+
import { Transaction } from "prosemirror-state";
|
|
4
|
+
//#region src/prosemirror/rebaseParagraphRuns.d.ts
|
|
5
|
+
/** Two contexts that lend runs the same formatting: rebasing between them changes nothing. */
|
|
6
|
+
declare const sameRunStyleContext: (source: ParagraphRunStyleContext, target: ParagraphRunStyleContext) => boolean;
|
|
7
|
+
type RebaseParagraphRunsOptions = {
|
|
8
|
+
tr: Transaction;
|
|
9
|
+
position: number;
|
|
10
|
+
previous: Node;
|
|
11
|
+
target?: Node;
|
|
12
|
+
styleResolver: RunStyleResolver | null;
|
|
13
|
+
range?: {
|
|
14
|
+
from: number;
|
|
15
|
+
to: number;
|
|
16
|
+
};
|
|
17
|
+
storedMarks?: readonly Mark[] | null;
|
|
18
|
+
};
|
|
19
|
+
/** Rebuild rendered marks after the paragraph's style cascade changes. */
|
|
20
|
+
declare const rebaseParagraphRuns: ({ tr, position, previous, target, styleResolver, range, storedMarks: initialStoredMarks }: RebaseParagraphRunsOptions) => Transaction;
|
|
21
|
+
type RebasedRunFormatting = {
|
|
22
|
+
before: Node;
|
|
23
|
+
after: Node;
|
|
24
|
+
position: number;
|
|
25
|
+
};
|
|
26
|
+
type RebaseParagraphRunContentOptions = {
|
|
27
|
+
paragraph: Node;
|
|
28
|
+
target: Node;
|
|
29
|
+
position: number;
|
|
30
|
+
styleResolver: RunStyleResolver | null;
|
|
31
|
+
onRebased: (resolution: RebasedRunFormatting) => void;
|
|
32
|
+
};
|
|
33
|
+
/** Rebase an immutable paragraph chunk once, before assembling a resolved join chain. */
|
|
34
|
+
declare const rebaseParagraphRunContent: ({ paragraph, target, position, styleResolver, onRebased }: RebaseParagraphRunContentOptions) => Fragment;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { rebaseParagraphRunContent, rebaseParagraphRuns, sameRunStyleContext };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { recreateProseNodeWithParagraphPropertySource } from "../docx/paragraphPropertySource.js";
|
|
2
|
+
import { formattingEquals } from "../docx/runConsolidator.js";
|
|
3
|
+
import { applyMarksToRunFormattingRepresentation, selectRunFormattingCarrierRepresentations } from "./runFormattingInlineCarriers.js";
|
|
4
|
+
import { readAuthoredRunFormatting, reconcileRunFormattingMarks } from "./runFormattingReconciliation.js";
|
|
5
|
+
import { paragraphRunStyleContext } from "./runStyleFormatting.js";
|
|
6
|
+
import { Mark } from "prosemirror-model";
|
|
7
|
+
//#region src/prosemirror/rebaseParagraphRuns.ts
|
|
8
|
+
/** Two contexts that lend runs the same formatting: rebasing between them changes nothing. */
|
|
9
|
+
const sameRunStyleContext = (source, target) => source.paragraphMarkPrecedesStyle === target.paragraphMarkPrecedesStyle && formattingEquals(source.baseParagraphFormatting, target.baseParagraphFormatting) && formattingEquals(source.paragraphFormatting, target.paragraphFormatting) && formattingEquals(source.paragraphMarkFormatting, target.paragraphMarkFormatting);
|
|
10
|
+
/** Rebuild rendered marks after the paragraph's style cascade changes. */
|
|
11
|
+
const rebaseParagraphRuns = ({ tr, position, previous, target, styleResolver, range, storedMarks: initialStoredMarks }) => {
|
|
12
|
+
const paragraph = tr.doc.nodeAt(position);
|
|
13
|
+
if (!paragraph) return tr;
|
|
14
|
+
const storedMarks = initialStoredMarks ?? tr.storedMarks ?? tr.selection.$from.marks();
|
|
15
|
+
const sourceContext = paragraphRunStyleContext(previous, styleResolver);
|
|
16
|
+
const targetContext = paragraphRunStyleContext(target ?? paragraph, styleResolver);
|
|
17
|
+
const sameCascade = sameRunStyleContext(sourceContext, targetContext);
|
|
18
|
+
const representations = sameCascade ? [] : selectRunFormattingCarrierRepresentations({
|
|
19
|
+
doc: tr.doc,
|
|
20
|
+
from: range?.from ?? position + 1,
|
|
21
|
+
to: range?.to ?? position + paragraph.nodeSize - 1
|
|
22
|
+
});
|
|
23
|
+
for (const representation of representations) applyMarksToRunFormattingRepresentation({
|
|
24
|
+
tr,
|
|
25
|
+
representation,
|
|
26
|
+
marks: reconcileRunFormattingMarks({
|
|
27
|
+
authoredFormatting: readAuthoredRunFormatting({
|
|
28
|
+
context: sourceContext,
|
|
29
|
+
marks: representation.node.marks,
|
|
30
|
+
styleResolver
|
|
31
|
+
}),
|
|
32
|
+
context: targetContext,
|
|
33
|
+
node: representation.node,
|
|
34
|
+
styleResolver
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
if (target === void 0 && range === void 0 && tr.selection.empty && tr.selection.from > position && tr.selection.from < position + paragraph.nodeSize) {
|
|
38
|
+
const node = paragraph.type.schema.text(" ", storedMarks);
|
|
39
|
+
tr.setStoredMarks(sameCascade ? storedMarks : reconcileRunFormattingMarks({
|
|
40
|
+
authoredFormatting: readAuthoredRunFormatting({
|
|
41
|
+
context: sourceContext,
|
|
42
|
+
marks: node.marks,
|
|
43
|
+
styleResolver
|
|
44
|
+
}),
|
|
45
|
+
context: targetContext,
|
|
46
|
+
node,
|
|
47
|
+
styleResolver
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
return tr;
|
|
51
|
+
};
|
|
52
|
+
/** Rebase an immutable paragraph chunk once, before assembling a resolved join chain. */
|
|
53
|
+
const rebaseParagraphRunContent = ({ paragraph, target, position, styleResolver, onRebased }) => {
|
|
54
|
+
const sourceContext = paragraphRunStyleContext(paragraph, styleResolver);
|
|
55
|
+
const targetContext = paragraphRunStyleContext(target, styleResolver);
|
|
56
|
+
if (sameRunStyleContext(sourceContext, targetContext)) return paragraph.content;
|
|
57
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
58
|
+
const representations = selectRunFormattingCarrierRepresentations({
|
|
59
|
+
doc: paragraph,
|
|
60
|
+
from: 0,
|
|
61
|
+
to: paragraph.content.size
|
|
62
|
+
});
|
|
63
|
+
for (const representation of representations) {
|
|
64
|
+
const marks = reconcileRunFormattingMarks({
|
|
65
|
+
authoredFormatting: readAuthoredRunFormatting({
|
|
66
|
+
context: sourceContext,
|
|
67
|
+
marks: representation.node.marks,
|
|
68
|
+
styleResolver
|
|
69
|
+
}),
|
|
70
|
+
context: targetContext,
|
|
71
|
+
node: representation.node,
|
|
72
|
+
styleResolver
|
|
73
|
+
});
|
|
74
|
+
if (Mark.sameSet(marks, representation.node.marks)) continue;
|
|
75
|
+
const rebased = representation.node.mark(marks);
|
|
76
|
+
replacements.set(representation.node, rebased);
|
|
77
|
+
onRebased({
|
|
78
|
+
before: representation.node,
|
|
79
|
+
after: rebased,
|
|
80
|
+
position: position + 1 + representation.position
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (replacements.size === 0) return paragraph.content;
|
|
84
|
+
const rebuild = (node) => {
|
|
85
|
+
const replacement = replacements.get(node) ?? node;
|
|
86
|
+
if (node.isLeaf) return replacement;
|
|
87
|
+
const children = [];
|
|
88
|
+
let changed = false;
|
|
89
|
+
replacement.forEach((child) => {
|
|
90
|
+
const next = rebuild(child);
|
|
91
|
+
children.push(next);
|
|
92
|
+
changed ||= next !== child;
|
|
93
|
+
});
|
|
94
|
+
return changed ? recreateProseNodeWithParagraphPropertySource(replacement, { content: children }) : replacement;
|
|
95
|
+
};
|
|
96
|
+
return rebuild(paragraph).content;
|
|
97
|
+
};
|
|
98
|
+
//#endregion
|
|
99
|
+
export { rebaseParagraphRunContent, rebaseParagraphRuns, sameRunStyleContext };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ParagraphRunStyleContext, RunStyleResolver } from "./runStyleFormatting.js";
|
|
2
|
-
import { Transaction } from "prosemirror-state";
|
|
3
2
|
import { Mark, Node } from "prosemirror-model";
|
|
3
|
+
import { Transaction } from "prosemirror-state";
|
|
4
4
|
//#region src/prosemirror/rejoinRunCarriers.d.ts
|
|
5
5
|
type ContinuedRunMarksOptions = {
|
|
6
6
|
left: Node;
|