@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,4 +1,5 @@
|
|
|
1
1
|
import { isInTable as isInTableCell } from "../prosemirror/extensions/nodes/TableExtension.js";
|
|
2
|
+
import { NO_LIST_NUMBERING_MENU, listNumberingMenuState } from "../prosemirror/listNumbering.js";
|
|
2
3
|
import { Subscribable } from "./Subscribable.js";
|
|
3
4
|
//#region src/managers/ContextMenuManager.ts
|
|
4
5
|
const CLOSED_STATE = {
|
|
@@ -13,7 +14,8 @@ const CLOSED_STATE = {
|
|
|
13
14
|
to: 0
|
|
14
15
|
},
|
|
15
16
|
cursorInTable: false,
|
|
16
|
-
cursorInTrackedChange: false
|
|
17
|
+
cursorInTrackedChange: false,
|
|
18
|
+
listNumbering: NO_LIST_NUMBERING_MENU
|
|
17
19
|
};
|
|
18
20
|
var ContextMenuManager = class extends Subscribable {
|
|
19
21
|
constructor() {
|
|
@@ -36,7 +38,8 @@ var ContextMenuManager = class extends Subscribable {
|
|
|
36
38
|
to: selection.to
|
|
37
39
|
},
|
|
38
40
|
cursorInTable,
|
|
39
|
-
cursorInTrackedChange
|
|
41
|
+
cursorInTrackedChange,
|
|
42
|
+
listNumbering: state ? listNumberingMenuState(state) : NO_LIST_NUMBERING_MENU
|
|
40
43
|
});
|
|
41
44
|
}
|
|
42
45
|
/** Close the menu. */
|
package/dist/managers/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ListNumberingMenuState } from "../prosemirror/listNumbering.js";
|
|
1
2
|
//#region src/managers/types.d.ts
|
|
2
3
|
/** Cell coordinates in a table */
|
|
3
4
|
type CellCoordinates = {
|
|
@@ -21,6 +22,8 @@ type ContextMenuSnapshot = {
|
|
|
21
22
|
};
|
|
22
23
|
cursorInTable: boolean;
|
|
23
24
|
cursorInTrackedChange: boolean;
|
|
25
|
+
/** Restart / continue / set-value entries for the list item under the caret. */
|
|
26
|
+
listNumbering: ListNumberingMenuState;
|
|
24
27
|
};
|
|
25
28
|
/** Error severity levels */
|
|
26
29
|
type ErrorSeverity = "error" | "warning" | "info";
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Escape only characters that would change markdown structure mid-text:
|
|
10
|
-
* - backslash, backtick, asterisk, brackets (always)
|
|
11
|
-
* - underscore:
|
|
10
|
+
* - backslash, backtick, asterisk, brackets, tilde (always)
|
|
11
|
+
* - underscore: unless between two letters or digits (emphasis trigger)
|
|
12
12
|
* - angle brackets: only when they look like a tag/autolink
|
|
13
13
|
*
|
|
14
14
|
* Characters like `.` `-` `+` `#` `(` `)` `!` are only meaningful at line
|
package/dist/markdown/escape.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Escape only characters that would change markdown structure mid-text:
|
|
10
|
-
* - backslash, backtick, asterisk, brackets (always)
|
|
11
|
-
* - underscore:
|
|
10
|
+
* - backslash, backtick, asterisk, brackets, tilde (always)
|
|
11
|
+
* - underscore: unless between two letters or digits (emphasis trigger)
|
|
12
12
|
* - angle brackets: only when they look like a tag/autolink
|
|
13
13
|
*
|
|
14
14
|
* Characters like `.` `-` `+` `#` `(` `)` `!` are only meaningful at line
|
|
@@ -16,9 +16,8 @@
|
|
|
16
16
|
* when to escape those.
|
|
17
17
|
*/
|
|
18
18
|
function escapeInline(text) {
|
|
19
|
-
let out = text.replace(/(?<ch>[\\`*[\]])/gu, "\\$<ch>");
|
|
20
|
-
out = out.replace(/(
|
|
21
|
-
out = out.replace(/_(?<post>\s|$)/gu, "\\_$<post>");
|
|
19
|
+
let out = text.replace(/(?<ch>[\\`*[\]~])/gu, "\\$<ch>");
|
|
20
|
+
out = out.replace(/(?<![\p{L}\p{N}])_|_(?![\p{L}\p{N}])/gu, "\\_");
|
|
22
21
|
out = out.replace(/<(?<tag>\/?[A-Za-z][\w-]*)(?=[\s/>])/gu, "\\<$<tag>");
|
|
23
22
|
return out;
|
|
24
23
|
}
|
|
@@ -36,9 +36,10 @@ const applyMarkdownPageGeometry = (document) => {
|
|
|
36
36
|
*/
|
|
37
37
|
function fromMarkdown(markdown) {
|
|
38
38
|
const document = createEmptyDocument();
|
|
39
|
-
const { content, numbering } = compileMarkdownToContent(markdown);
|
|
39
|
+
const { content, numbering, warnings } = compileMarkdownToContent(markdown);
|
|
40
40
|
if (content.length > 0) document.package.document.content = content;
|
|
41
41
|
if (numbering) document.package.numbering = numbering;
|
|
42
|
+
if (warnings && warnings.length > 0) document.warnings = [...document.warnings ?? [], ...warnings];
|
|
42
43
|
applyMarkdownPageGeometry(document);
|
|
43
44
|
return document;
|
|
44
45
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
import { NoteReferenceKind } from "../utils/noteReferenceLabels.js";
|
|
2
3
|
import { MarkdownOptions, RenderContext } from "./types.js";
|
|
3
4
|
//#region src/markdown/internals.d.ts
|
|
4
5
|
/**
|
|
@@ -15,5 +16,14 @@ declare function newContext(opts?: MarkdownOptions, styles?: document_d_exports.
|
|
|
15
16
|
* recurring messages appear at most once.
|
|
16
17
|
*/
|
|
17
18
|
declare function pushWarning(ctx: RenderContext, message: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Number a footnote or endnote reference in reading order and record its
|
|
21
|
+
* note for the definitions trailer on the note's first reference. Returns the
|
|
22
|
+
* bare token (`1`, `e1`) and the inline marker (`[^1]`, `[^e1]`).
|
|
23
|
+
*/
|
|
24
|
+
declare function numberNoteReference(ctx: RenderContext, kind: NoteReferenceKind, refId: number): {
|
|
25
|
+
token: string;
|
|
26
|
+
marker: string;
|
|
27
|
+
};
|
|
18
28
|
//#endregion
|
|
19
|
-
export { newContext, pushWarning };
|
|
29
|
+
export { newContext, numberNoteReference, pushWarning };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { createBuiltInStyleIndex } from "../docx/builtInStyles.js";
|
|
2
|
+
import { createListLabelCounter } from "../prosemirror/listLabels.js";
|
|
3
|
+
import { createNoteReferenceNumbering, noteReferenceMarker, noteReferenceToken } from "../utils/noteReferenceLabels.js";
|
|
2
4
|
//#region src/markdown/internals.ts
|
|
3
5
|
/**
|
|
4
6
|
* Internal helpers shared by the markdown converter: context construction and
|
|
@@ -30,11 +32,12 @@ function newContext(opts = {}, styles) {
|
|
|
30
32
|
imagesByPath: /* @__PURE__ */ new Map(),
|
|
31
33
|
warnings: [],
|
|
32
34
|
footnoteRefs: [],
|
|
35
|
+
noteNumbering: createNoteReferenceNumbering(),
|
|
33
36
|
commentRefs: [],
|
|
34
37
|
hyperlinkRefs: [],
|
|
35
38
|
imageCounter: 0,
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
nextListLabel: createListLabelCounter(),
|
|
40
|
+
listIndentWidths: []
|
|
38
41
|
};
|
|
39
42
|
}
|
|
40
43
|
/**
|
|
@@ -44,5 +47,23 @@ function newContext(opts = {}, styles) {
|
|
|
44
47
|
function pushWarning(ctx, message) {
|
|
45
48
|
if (!ctx.warnings.includes(message)) ctx.warnings.push(message);
|
|
46
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Number a footnote or endnote reference in reading order and record its
|
|
52
|
+
* note for the definitions trailer on the note's first reference. Returns the
|
|
53
|
+
* bare token (`1`, `e1`) and the inline marker (`[^1]`, `[^e1]`).
|
|
54
|
+
*/
|
|
55
|
+
function numberNoteReference(ctx, kind, refId) {
|
|
56
|
+
const { displayNumber, first } = ctx.noteNumbering.next(kind, refId);
|
|
57
|
+
const marker = noteReferenceMarker(kind, displayNumber);
|
|
58
|
+
if (first) ctx.footnoteRefs.push({
|
|
59
|
+
refId,
|
|
60
|
+
marker,
|
|
61
|
+
kind
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
token: noteReferenceToken(kind, displayNumber),
|
|
65
|
+
marker
|
|
66
|
+
};
|
|
67
|
+
}
|
|
47
68
|
//#endregion
|
|
48
|
-
export { newContext, pushWarning };
|
|
69
|
+
export { newContext, numberNoteReference, pushWarning };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { ALT_CHUNK_READER_DIAGNOSTIC, isAltChunkMarkup } from "../docx/altChunk.js";
|
|
2
|
+
import { OPAQUE_REVISION_CARRIER_READER_DIAGNOSTIC, isOpaqueNestedRowMarkup, opaqueRevisionCarrierName } from "../docx/opaqueCarrier.js";
|
|
1
3
|
import { cloneParagraphWithoutPropertySource } from "../docx/paragraphPropertySource.js";
|
|
2
|
-
import {
|
|
4
|
+
import { renderParagraphBlock } from "./renderParagraph.js";
|
|
3
5
|
import { renderTable } from "./renderTable.js";
|
|
4
6
|
import { panic } from "better-result";
|
|
5
7
|
//#region src/markdown/renderBlock.ts
|
|
@@ -9,41 +11,130 @@ import { panic } from "better-result";
|
|
|
9
11
|
* of the same list. Ported from eigenpal/docx-editor PR #595.
|
|
10
12
|
*/
|
|
11
13
|
/**
|
|
12
|
-
* In `trackedChanges: "clean"` mode every change is accepted
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
14
|
+
* In `trackedChanges: "clean"` mode every change is accepted, as the editor's
|
|
15
|
+
* accept-all resolves the story (`internal/wholeStoryRevisionResolution.ts`).
|
|
16
|
+
*
|
|
17
|
+
* A paragraph whose mark is pending deletion loses its break on accept and
|
|
18
|
+
* runs on into the paragraph after it, which is the paragraph left: its mark
|
|
19
|
+
* ends the joined text, and a paragraph's properties (style, list) live on its
|
|
20
|
+
* mark. A run of consecutive deletions collapses into that last paragraph.
|
|
21
|
+
*
|
|
22
|
+
* With a table right after it, its words run on into the table's first cell
|
|
23
|
+
* and lead that cell's first paragraph (`prosemirror/tableRunIn.ts`), unless
|
|
24
|
+
* it ends a section, keeps nothing once accepted, or that cell is pending.
|
|
25
|
+
* Otherwise a paragraph that cannot join keeps its place, or goes when it
|
|
26
|
+
* keeps nothing and something follows it.
|
|
20
27
|
*/
|
|
21
28
|
function mergeAcceptedParagraphBreaks(blocks) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const reversed = [];
|
|
30
|
+
let survivor = null;
|
|
31
|
+
let tableFollows = false;
|
|
32
|
+
let followed = false;
|
|
33
|
+
const flush = () => {
|
|
34
|
+
if (survivor) reversed.push(survivor);
|
|
35
|
+
survivor = null;
|
|
36
|
+
};
|
|
37
|
+
for (let index = blocks.length - 1; index >= 0; index--) {
|
|
38
|
+
const block = blocks[index];
|
|
39
|
+
if (!block) continue;
|
|
40
|
+
if (block.type !== "paragraph") {
|
|
41
|
+
flush();
|
|
42
|
+
reversed.push(block);
|
|
43
|
+
tableFollows = block.type === "table";
|
|
44
|
+
followed ||= tableFollows;
|
|
33
45
|
continue;
|
|
34
46
|
}
|
|
35
|
-
|
|
47
|
+
const goes = block.pPrMark?.kind === "del" || block.pPrMark?.kind === "moveFrom";
|
|
48
|
+
if (goes && survivor) {
|
|
49
|
+
survivor = cloneParagraphWithoutPropertySource(survivor, { content: [...block.content, ...survivor.content] });
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const table = reversed.at(-1);
|
|
53
|
+
if (goes && tableFollows && table?.type === "table") {
|
|
54
|
+
const ranIn = tableWithParagraphRunIn(table, block);
|
|
55
|
+
if (ranIn) {
|
|
56
|
+
reversed[reversed.length - 1] = ranIn;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
flush();
|
|
61
|
+
tableFollows = false;
|
|
62
|
+
if (goes && holdsNothingOnAccept(block) && followed && index + reversed.length > 0) continue;
|
|
63
|
+
survivor = block;
|
|
64
|
+
followed = true;
|
|
36
65
|
}
|
|
37
|
-
|
|
66
|
+
flush();
|
|
67
|
+
return reversed.reverse();
|
|
38
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Whether the cell a paragraph's words would run into is itself pending (its
|
|
71
|
+
* row or the cell, through nested tables' first cells), as
|
|
72
|
+
* `prosemirror/tableRunIn.ts` reads it.
|
|
73
|
+
*/
|
|
74
|
+
const runInCellPending = (table) => {
|
|
75
|
+
const row = table.rows[0];
|
|
76
|
+
const cell = row?.cells[0];
|
|
77
|
+
if (!row || !cell) return false;
|
|
78
|
+
if (row.structuralChange !== void 0 || cell.structuralChange !== void 0) return true;
|
|
79
|
+
const first = cell.content[0];
|
|
80
|
+
return first?.type === "table" && runInCellPending(first);
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* `table` with `paragraph`'s words leading its first cell's first paragraph,
|
|
84
|
+
* descending into nested tables, or null when the paragraph keeps its place.
|
|
85
|
+
*/
|
|
86
|
+
const tableWithParagraphRunIn = (table, paragraph) => {
|
|
87
|
+
if (paragraph.sectionProperties !== void 0 || holdsNothingOnAccept(paragraph)) return null;
|
|
88
|
+
if (runInCellPending(table)) return null;
|
|
89
|
+
const runIn = (current) => {
|
|
90
|
+
const [row, ...rows] = current.rows;
|
|
91
|
+
const [cell, ...cells] = row?.cells ?? [];
|
|
92
|
+
const [first, ...rest] = cell?.content ?? [];
|
|
93
|
+
if (!row || !cell || !first) return null;
|
|
94
|
+
let led = null;
|
|
95
|
+
if (first.type === "paragraph") led = cloneParagraphWithoutPropertySource(first, { content: [...paragraph.content, ...first.content] });
|
|
96
|
+
else if (first.type === "table") led = runIn(first);
|
|
97
|
+
if (!led) return null;
|
|
98
|
+
return {
|
|
99
|
+
...current,
|
|
100
|
+
rows: [{
|
|
101
|
+
...row,
|
|
102
|
+
cells: [{
|
|
103
|
+
...cell,
|
|
104
|
+
content: [led, ...rest]
|
|
105
|
+
}, ...cells]
|
|
106
|
+
}, ...rows]
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
return runIn(table);
|
|
110
|
+
};
|
|
111
|
+
/** Paragraph content that shows nothing: range boundaries and anchors. */
|
|
112
|
+
const ZERO_WIDTH_CONTENT = /* @__PURE__ */ new Set([
|
|
113
|
+
"bookmarkStart",
|
|
114
|
+
"bookmarkEnd",
|
|
115
|
+
"commentRangeStart",
|
|
116
|
+
"commentRangeEnd",
|
|
117
|
+
"commentReference",
|
|
118
|
+
"moveFromRangeStart",
|
|
119
|
+
"moveFromRangeEnd",
|
|
120
|
+
"moveToRangeStart",
|
|
121
|
+
"moveToRangeEnd"
|
|
122
|
+
]);
|
|
123
|
+
/** Whether an item shows nothing once every change is accepted. */
|
|
124
|
+
const showsNothingOnAccept = (item) => {
|
|
125
|
+
if (item.type === "deletion" || item.type === "moveFrom" || ZERO_WIDTH_CONTENT.has(item.type)) return true;
|
|
126
|
+
if (item.type === "insertion" || item.type === "moveTo") return item.content.every(showsNothingOnAccept);
|
|
127
|
+
return item.type === "run" && item.content.every((content) => content.type === "renderedPageBreak");
|
|
128
|
+
};
|
|
129
|
+
/** Whether a paragraph keeps no visible content once every change is accepted. */
|
|
130
|
+
const holdsNothingOnAccept = (paragraph) => paragraph.content.every(showsNothingOnAccept);
|
|
39
131
|
function renderBlocks(ctx, pkg, blocks) {
|
|
40
132
|
const out = [];
|
|
41
133
|
let prevWasListItem = false;
|
|
42
134
|
const ordered = ctx.opts.trackedChanges === "clean" ? mergeAcceptedParagraphBreaks(blocks) : blocks;
|
|
43
135
|
for (const block of ordered) switch (block.type) {
|
|
44
136
|
case "paragraph": {
|
|
45
|
-
const isListItem =
|
|
46
|
-
const md = renderParagraph(ctx, pkg, block);
|
|
137
|
+
const { markdown: md, isListItem } = renderParagraphBlock(ctx, pkg, block);
|
|
47
138
|
if (!md) {
|
|
48
139
|
prevWasListItem = false;
|
|
49
140
|
continue;
|
|
@@ -63,7 +154,8 @@ function renderBlocks(ctx, pkg, blocks) {
|
|
|
63
154
|
prevWasListItem = false;
|
|
64
155
|
break;
|
|
65
156
|
}
|
|
66
|
-
case "blockSdt":
|
|
157
|
+
case "blockSdt":
|
|
158
|
+
case "blockCustomXml": {
|
|
67
159
|
const nested = renderBlocks(ctx, pkg, block.content);
|
|
68
160
|
if (nested) {
|
|
69
161
|
if (out.length) out.push("");
|
|
@@ -72,6 +164,10 @@ function renderBlocks(ctx, pkg, blocks) {
|
|
|
72
164
|
break;
|
|
73
165
|
}
|
|
74
166
|
case "preservedBlock":
|
|
167
|
+
if (isAltChunkMarkup(block.xml)) out.push(block.readerText === void 0 ? ALT_CHUNK_READER_DIAGNOSTIC : `${ALT_CHUNK_READER_DIAGNOSTIC}\n\n${block.readerText}`);
|
|
168
|
+
else if (opaqueRevisionCarrierName(block.xml) !== void 0) out.push(OPAQUE_REVISION_CARRIER_READER_DIAGNOSTIC);
|
|
169
|
+
else if (isOpaqueNestedRowMarkup(block.xml)) out.push("[Unsupported nested w:tr content]");
|
|
170
|
+
break;
|
|
75
171
|
case "bookmarkStart":
|
|
76
172
|
case "bookmarkEnd": break;
|
|
77
173
|
default: panic(`Unsupported block content in markdown: ${JSON.stringify(block)}`);
|
|
@@ -6,5 +6,17 @@ import { RenderContext } from "./types.js";
|
|
|
6
6
|
* caller joins blocks.
|
|
7
7
|
*/
|
|
8
8
|
declare function renderParagraph(ctx: RenderContext, pkg: document_d_exports.DocxPackage | undefined, para: document_d_exports.Paragraph): string;
|
|
9
|
+
/** A rendered paragraph, and whether it is a Markdown list item. */
|
|
10
|
+
type RenderedParagraph = {
|
|
11
|
+
markdown: string;
|
|
12
|
+
isListItem: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Render a paragraph. A list item is a paragraph that shows a marker, which is
|
|
16
|
+
* when the list counter gives it a label: a numbered heading renders as a
|
|
17
|
+
* heading, and a level that hides its marker (`w:vanish`) or that its list
|
|
18
|
+
* does not define as prose, as every other reader reads them.
|
|
19
|
+
*/
|
|
20
|
+
declare function renderParagraphBlock(ctx: RenderContext, pkg: document_d_exports.DocxPackage | undefined, para: document_d_exports.Paragraph): RenderedParagraph;
|
|
9
21
|
//#endregion
|
|
10
|
-
export { renderParagraph };
|
|
22
|
+
export { RenderedParagraph, renderParagraph, renderParagraphBlock };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isQuoteStyle, resolveHeadingLevel } from "../docx/builtInStyles.js";
|
|
2
|
-
import {
|
|
2
|
+
import { listLabelAttrsFromRendering } from "../prosemirror/listLabels.js";
|
|
3
3
|
import { renderParagraphInline } from "./renderRuns.js";
|
|
4
4
|
//#region src/markdown/renderParagraph.ts
|
|
5
5
|
/**
|
|
@@ -9,6 +9,8 @@ import { renderParagraphInline } from "./renderRuns.js";
|
|
|
9
9
|
* `IntenseQuote` styles become blockquotes. Ported from eigenpal/docx-editor
|
|
10
10
|
* PR #595.
|
|
11
11
|
*
|
|
12
|
+
* A numbered heading keeps its number after the hashes (`## 1. Scope`).
|
|
13
|
+
*
|
|
12
14
|
* Which paragraphs those are is `builtInStyles`' decision, not this file's: the
|
|
13
15
|
* id `Nadpis1` and the id `Heading1` are the same heading, and `ClauseHeading1`
|
|
14
16
|
* is not one at all.
|
|
@@ -20,19 +22,59 @@ const MAX_MARKDOWN_HEADING_LEVEL = 6;
|
|
|
20
22
|
* caller joins blocks.
|
|
21
23
|
*/
|
|
22
24
|
function renderParagraph(ctx, pkg, para) {
|
|
25
|
+
return renderParagraphBlock(ctx, pkg, para).markdown;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Render a paragraph. A list item is a paragraph that shows a marker, which is
|
|
29
|
+
* when the list counter gives it a label: a numbered heading renders as a
|
|
30
|
+
* heading, and a level that hides its marker (`w:vanish`) or that its list
|
|
31
|
+
* does not define as prose, as every other reader reads them.
|
|
32
|
+
*/
|
|
33
|
+
function renderParagraphBlock(ctx, pkg, para) {
|
|
34
|
+
const label = ctx.nextListLabel(listLabelAttrs(para));
|
|
23
35
|
const inline = renderParagraphInline(ctx, pkg, para.content, para.paraId);
|
|
24
36
|
const styleId = para.formatting?.styleId;
|
|
25
|
-
const headingLevel =
|
|
26
|
-
outlineLevel: para.formatting?.outlineLevel,
|
|
27
|
-
styleId
|
|
28
|
-
}, ctx.builtInStyles);
|
|
37
|
+
const headingLevel = markdownHeadingLevel(ctx, para);
|
|
29
38
|
if (headingLevel !== void 0) {
|
|
30
|
-
if (!inline) return
|
|
31
|
-
|
|
39
|
+
if (!inline) return {
|
|
40
|
+
markdown: "",
|
|
41
|
+
isListItem: false
|
|
42
|
+
};
|
|
43
|
+
const hashes = "#".repeat(Math.min(MAX_MARKDOWN_HEADING_LEVEL, headingLevel + 1));
|
|
44
|
+
return {
|
|
45
|
+
markdown: label ? `${hashes} ${label} ${inline}` : `${hashes} ${inline}`,
|
|
46
|
+
isListItem: false
|
|
47
|
+
};
|
|
32
48
|
}
|
|
33
|
-
if (para.listRendering &&
|
|
34
|
-
|
|
35
|
-
|
|
49
|
+
if (para.listRendering && label !== void 0) return {
|
|
50
|
+
markdown: renderListItem(ctx, para.listRendering, label, inline),
|
|
51
|
+
isListItem: true
|
|
52
|
+
};
|
|
53
|
+
if (isQuoteStyle(styleId, ctx.builtInStyles)) return {
|
|
54
|
+
markdown: inline.split("\n").map((line) => `> ${line}`).join("\n"),
|
|
55
|
+
isListItem: false
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
markdown: escapeLeadingBlockMarker(inline),
|
|
59
|
+
isListItem: false
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** The paragraph's 0-based heading level, as `builtInStyles` classifies it. */
|
|
63
|
+
function markdownHeadingLevel(ctx, para) {
|
|
64
|
+
return resolveHeadingLevel({
|
|
65
|
+
outlineLevel: para.formatting?.outlineLevel,
|
|
66
|
+
styleId: para.formatting?.styleId
|
|
67
|
+
}, ctx.builtInStyles);
|
|
68
|
+
}
|
|
69
|
+
const UNNUMBERED = Object.freeze({});
|
|
70
|
+
/**
|
|
71
|
+
* The attrs the page's list counter reads, projected from the paragraph the
|
|
72
|
+
* way the editor projects them (`toProseDoc`). A paragraph without a list
|
|
73
|
+
* rendering counts as unnumbered.
|
|
74
|
+
*/
|
|
75
|
+
function listLabelAttrs(para) {
|
|
76
|
+
const list = para.listRendering;
|
|
77
|
+
return list ? listLabelAttrsFromRendering(list, para.formatting?.numPrFromStyle) : UNNUMBERED;
|
|
36
78
|
}
|
|
37
79
|
/**
|
|
38
80
|
* A plain paragraph whose visible text begins with markdown block syntax (e.g.
|
|
@@ -43,36 +85,41 @@ function renderParagraph(ctx, pkg, para) {
|
|
|
43
85
|
function escapeLeadingBlockMarker(text) {
|
|
44
86
|
return text.replace(/^(?<ws>[ \t]*)(?<marker>[#>])/gmu, "$<ws>\\$<marker>").replace(/^(?<ws>[ \t]*)(?<marker>[-+*])(?<after>[ \t])/gmu, "$<ws>\\$<marker>$<after>").replace(/^(?<ws>[ \t]*)(?<num>\d{1,9})(?<marker>[.)])(?<after>[ \t])/gmu, "$<ws>$<num>\\$<marker>$<after>");
|
|
45
87
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
88
|
+
/**
|
|
89
|
+
* A markdown list marker's width when no ancestor at that level has rendered
|
|
90
|
+
* yet (e.g. a DOCX paragraph numbered at a level its list skipped over). Two
|
|
91
|
+
* spaces is the old fixed-indent behaviour, kept as a fallback rather than a
|
|
92
|
+
* guess of zero.
|
|
93
|
+
*/
|
|
94
|
+
const DEFAULT_LIST_INDENT_WIDTH = 2;
|
|
95
|
+
/**
|
|
96
|
+
* The indent a level's item needs: the combined marker width of every
|
|
97
|
+
* shallower level's most recently rendered item (see
|
|
98
|
+
* `RenderContext.listIndentWidths`), so a child sits inside its parent's
|
|
99
|
+
* content column per CommonMark's list-nesting rule, not a fixed guess.
|
|
100
|
+
*/
|
|
101
|
+
function listIndentWidth(ctx, level) {
|
|
102
|
+
let width = 0;
|
|
103
|
+
for (let ancestor = 0; ancestor < level; ancestor++) width += ctx.listIndentWidths[ancestor] ?? DEFAULT_LIST_INDENT_WIDTH;
|
|
104
|
+
return width;
|
|
50
105
|
}
|
|
51
106
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* the
|
|
107
|
+
* A list item line with the label the page shows (`1.`, `a)`, `i.`), counted
|
|
108
|
+
* in document order across the whole render, list items inside tables and
|
|
109
|
+
* block SDTs included. A bullet is Markdown's `-`.
|
|
110
|
+
*
|
|
111
|
+
* The indent before the marker is not a fixed two spaces: CommonMark keeps a
|
|
112
|
+
* child nested under its parent only when it starts at or past the column
|
|
113
|
+
* where the parent item's content begins, which is the width of the parent's
|
|
114
|
+
* marker plus its one trailing space (`1. ` is 3 columns, `10. ` is 4, `- ` is
|
|
115
|
+
* 2). `ctx.listIndentWidths` is updated with this item's own marker width so
|
|
116
|
+
* a following, deeper item can indent correctly under it.
|
|
57
117
|
*/
|
|
58
|
-
function
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
ctx.listSeenLevels.add(seenKey);
|
|
64
|
-
if (list.startOverride !== void 0) counters[level] = list.startOverride - 1;
|
|
65
|
-
}
|
|
66
|
-
counters[level] = (counters[level] ?? 0) + 1;
|
|
67
|
-
for (let i = level + 1; i < counters.length; i += 1) counters[i] = 0;
|
|
68
|
-
ctx.listCounters.set(list.numId, counters);
|
|
69
|
-
const levelFormats = list.levelNumFmts ?? (list.numFmt ? [list.numFmt] : void 0);
|
|
70
|
-
return resolveListTemplate({
|
|
71
|
-
template: list.marker,
|
|
72
|
-
counters,
|
|
73
|
-
levelFormats,
|
|
74
|
-
forceDecimal: list.isLegal
|
|
75
|
-
}).trim();
|
|
118
|
+
function renderListItem(ctx, list, label, inline) {
|
|
119
|
+
const indent = " ".repeat(listIndentWidth(ctx, list.level));
|
|
120
|
+
const marker = list.isBullet ? "- " : `${label} `;
|
|
121
|
+
ctx.listIndentWidths[list.level] = marker.length;
|
|
122
|
+
return `${indent}${marker}${inline}`.trimEnd();
|
|
76
123
|
}
|
|
77
124
|
//#endregion
|
|
78
|
-
export { renderParagraph };
|
|
125
|
+
export { renderParagraph, renderParagraphBlock };
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
2
|
import { RenderContext } from "./types.js";
|
|
3
3
|
//#region src/markdown/renderRuns.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The character beside a run's delimiters: `""` at the paragraph's edge,
|
|
6
|
+
* `undefined` when it cannot be told (read as a letter, the strictest case).
|
|
7
|
+
*/
|
|
8
|
+
type Neighbor = string | undefined;
|
|
9
|
+
type RunNeighbors = {
|
|
10
|
+
before: Neighbor;
|
|
11
|
+
after: Neighbor;
|
|
12
|
+
};
|
|
4
13
|
/**
|
|
5
14
|
* Render the full inline content of a paragraph, tracking comment-range
|
|
6
15
|
* boundaries to apply the configured wrapper.
|
|
7
16
|
*/
|
|
8
|
-
declare function renderParagraphInline(ctx: RenderContext, pkg: document_d_exports.DocxPackage | undefined, content: readonly document_d_exports.ParagraphContent[], paraId: string | undefined): string;
|
|
17
|
+
declare function renderParagraphInline(ctx: RenderContext, pkg: document_d_exports.DocxPackage | undefined, content: readonly document_d_exports.ParagraphContent[], paraId: string | undefined, edges?: RunNeighbors): string;
|
|
9
18
|
//#endregion
|
|
10
19
|
export { renderParagraphInline };
|