@stll/folio-core 0.0.1-placeholder.0 → 0.1.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/LICENSE +202 -0
- package/NOTICE.md +29 -0
- package/README.md +41 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/ai-edits/apply.d.ts +35 -0
- package/dist/ai-edits/apply.js +683 -0
- package/dist/ai-edits/clean-text.d.ts +28 -0
- package/dist/ai-edits/clean-text.js +23 -0
- package/dist/ai-edits/headless.d.ts +225 -0
- package/dist/ai-edits/headless.js +513 -0
- package/dist/ai-edits/index.d.ts +6 -0
- package/dist/ai-edits/index.js +5 -0
- package/dist/ai-edits/inline-emphasis.d.ts +38 -0
- package/dist/ai-edits/inline-emphasis.js +78 -0
- package/dist/ai-edits/snapshot.d.ts +9 -0
- package/dist/ai-edits/snapshot.js +195 -0
- package/dist/ai-edits/types.d.ts +156 -0
- package/dist/ai-edits/types.js +0 -0
- package/dist/ai-edits/word-diff.d.ts +20 -0
- package/dist/ai-edits/word-diff.js +77 -0
- package/dist/ai-suggestions/apply.d.ts +17 -0
- package/dist/ai-suggestions/apply.js +64 -0
- package/dist/ai-suggestions/conflict.d.ts +22 -0
- package/dist/ai-suggestions/conflict.js +67 -0
- package/dist/ai-suggestions/text-positions.d.ts +21 -0
- package/dist/ai-suggestions/text-positions.js +48 -0
- package/dist/ai-suggestions/types.d.ts +199 -0
- package/dist/ai-suggestions/types.js +59 -0
- package/dist/content-controls/errors.d.ts +52 -0
- package/dist/content-controls/errors.js +36 -0
- package/dist/content-controls/findContentControls.d.ts +55 -0
- package/dist/content-controls/findContentControls.js +75 -0
- package/dist/content-controls/index.d.ts +4 -0
- package/dist/content-controls/index.js +4 -0
- package/dist/content-controls/mutateContentControls.d.ts +51 -0
- package/dist/content-controls/mutateContentControls.js +377 -0
- package/dist/controller/folioEditor.d.ts +21 -0
- package/dist/controller/folioEditor.js +29 -0
- package/dist/controller/folioEditorEvents.d.ts +23 -0
- package/dist/controller/folioEditorEvents.js +24 -0
- package/dist/controller/hiddenEditorApi.d.ts +35 -0
- package/dist/controller/hiddenEditorApi.js +112 -0
- package/dist/controller/hiddenEditorManager.d.ts +93 -0
- package/dist/controller/hiddenEditorManager.js +308 -0
- package/dist/controller/layoutPipeline.d.ts +63 -0
- package/dist/controller/layoutPipeline.js +406 -0
- package/dist/controller/layoutScheduler.d.ts +41 -0
- package/dist/controller/layoutScheduler.js +59 -0
- package/dist/controller/layoutSession.d.ts +24 -0
- package/dist/controller/layoutSession.js +13 -0
- package/dist/docx/blockContentParser.d.ts +13 -0
- package/dist/docx/blockContentParser.js +289 -0
- package/dist/docx/bookmarkParser.d.ts +178 -0
- package/dist/docx/bookmarkParser.js +246 -0
- package/dist/docx/bookmarkPlacement.d.ts +10 -0
- package/dist/docx/bookmarkPlacement.js +50 -0
- package/dist/docx/bulletMarkers.d.ts +4 -0
- package/dist/docx/bulletMarkers.js +42 -0
- package/dist/docx/commentParser.d.ts +34 -0
- package/dist/docx/commentParser.js +127 -0
- package/dist/docx/commentReferenceNormalization.d.ts +25 -0
- package/dist/docx/commentReferenceNormalization.js +97 -0
- package/dist/docx/commentReplyMarkers.d.ts +20 -0
- package/dist/docx/commentReplyMarkers.js +123 -0
- package/dist/docx/compatibility.d.ts +12 -0
- package/dist/docx/compatibility.js +77 -0
- package/dist/docx/documentParser.d.ts +65 -0
- package/dist/docx/documentParser.js +209 -0
- package/dist/docx/drawingUtils.d.ts +56 -0
- package/dist/docx/drawingUtils.js +305 -0
- package/dist/docx/fieldParser.d.ts +228 -0
- package/dist/docx/fieldParser.js +559 -0
- package/dist/docx/footnoteParser.d.ts +109 -0
- package/dist/docx/footnoteParser.js +270 -0
- package/dist/docx/headerFooterParser.d.ts +119 -0
- package/dist/docx/headerFooterParser.js +266 -0
- package/dist/docx/headerFooterRefParser.d.ts +22 -0
- package/dist/docx/headerFooterRefParser.js +52 -0
- package/dist/docx/headerFooterReferenceNormalization.d.ts +19 -0
- package/dist/docx/headerFooterReferenceNormalization.js +64 -0
- package/dist/docx/hyperlinkParser.d.ts +108 -0
- package/dist/docx/hyperlinkParser.js +230 -0
- package/dist/docx/imageParser.d.ts +93 -0
- package/dist/docx/imageParser.js +522 -0
- package/dist/docx/mathToMathml.d.ts +15 -0
- package/dist/docx/mathToMathml.js +357 -0
- package/dist/docx/modelValidation.d.ts +13 -0
- package/dist/docx/modelValidation.js +21 -0
- package/dist/docx/normalizeBaseDirection.d.ts +12 -0
- package/dist/docx/normalizeBaseDirection.js +81 -0
- package/dist/docx/notePropertiesParser.d.ts +16 -0
- package/dist/docx/notePropertiesParser.js +99 -0
- package/dist/docx/numberingParser.d.ts +86 -0
- package/dist/docx/numberingParser.js +735 -0
- package/dist/docx/numberingReferenceNormalization.d.ts +25 -0
- package/dist/docx/numberingReferenceNormalization.js +22 -0
- package/dist/docx/paragraphParser.d.ts +86 -0
- package/dist/docx/paragraphParser.js +1132 -0
- package/dist/docx/paragraphTraversal.d.ts +19 -0
- package/dist/docx/paragraphTraversal.js +76 -0
- package/dist/docx/parser.d.ts +67 -0
- package/dist/docx/parser.js +391 -0
- package/dist/docx/parserEnums.d.ts +45 -0
- package/dist/docx/parserEnums.js +70 -0
- package/dist/docx/relsParser.d.ts +160 -0
- package/dist/docx/relsParser.js +235 -0
- package/dist/docx/replyToComment.d.ts +29 -0
- package/dist/docx/replyToComment.js +73 -0
- package/dist/docx/rezip.d.ts +166 -0
- package/dist/docx/rezip.js +1194 -0
- package/dist/docx/runConsolidator.d.ts +57 -0
- package/dist/docx/runConsolidator.js +224 -0
- package/dist/docx/runParser.d.ts +78 -0
- package/dist/docx/runParser.js +661 -0
- package/dist/docx/sdtProperties.d.ts +15 -0
- package/dist/docx/sdtProperties.js +290 -0
- package/dist/docx/sdtPropertiesPatch.d.ts +16 -0
- package/dist/docx/sdtPropertiesPatch.js +144 -0
- package/dist/docx/sectionParser.d.ts +95 -0
- package/dist/docx/sectionParser.js +534 -0
- package/dist/docx/selectiveSave.d.ts +25 -0
- package/dist/docx/selectiveSave.js +247 -0
- package/dist/docx/selectiveSaveFlags.d.ts +33 -0
- package/dist/docx/selectiveSaveFlags.js +11 -0
- package/dist/docx/selectiveSaveTripwire.d.ts +33 -0
- package/dist/docx/selectiveSaveTripwire.js +79 -0
- package/dist/docx/selectiveXmlPatch.d.ts +103 -0
- package/dist/docx/selectiveXmlPatch.js +493 -0
- package/dist/docx/serializer/blockSdtSerializer.d.ts +6 -0
- package/dist/docx/serializer/blockSdtSerializer.js +88 -0
- package/dist/docx/serializer/borderSerializer.d.ts +25 -0
- package/dist/docx/serializer/borderSerializer.js +44 -0
- package/dist/docx/serializer/commentSerializer.d.ts +31 -0
- package/dist/docx/serializer/commentSerializer.js +184 -0
- package/dist/docx/serializer/documentSerializer.d.ts +65 -0
- package/dist/docx/serializer/documentSerializer.js +199 -0
- package/dist/docx/serializer/headerFooterSerializer.d.ts +12 -0
- package/dist/docx/serializer/headerFooterSerializer.js +84 -0
- package/dist/docx/serializer/noteSerializer.d.ts +19 -0
- package/dist/docx/serializer/noteSerializer.js +70 -0
- package/dist/docx/serializer/numberingSerializer.d.ts +12 -0
- package/dist/docx/serializer/numberingSerializer.js +93 -0
- package/dist/docx/serializer/paragraphSerializer.d.ts +48 -0
- package/dist/docx/serializer/paragraphSerializer.js +559 -0
- package/dist/docx/serializer/runSerializer.d.ts +56 -0
- package/dist/docx/serializer/runSerializer.js +621 -0
- package/dist/docx/serializer/sectionPropertiesSerializer.d.ts +6 -0
- package/dist/docx/serializer/sectionPropertiesSerializer.js +187 -0
- package/dist/docx/serializer/tableSerializer.d.ts +79 -0
- package/dist/docx/serializer/tableSerializer.js +422 -0
- package/dist/docx/serializer/xmlUtils.d.ts +20 -0
- package/dist/docx/serializer/xmlUtils.js +25 -0
- package/dist/docx/settingsParser.d.ts +8 -0
- package/dist/docx/settingsParser.js +36 -0
- package/dist/docx/shapeParser.d.ts +20 -0
- package/dist/docx/shapeParser.js +272 -0
- package/dist/docx/styleParser.d.ts +50 -0
- package/dist/docx/styleParser.js +905 -0
- package/dist/docx/tableParser.d.ts +202 -0
- package/dist/docx/tableParser.js +811 -0
- package/dist/docx/textBoxParser.d.ts +117 -0
- package/dist/docx/textBoxParser.js +262 -0
- package/dist/docx/themeParser.d.ts +77 -0
- package/dist/docx/themeParser.js +330 -0
- package/dist/docx/trackedMoveRangeNormalization.d.ts +22 -0
- package/dist/docx/trackedMoveRangeNormalization.js +100 -0
- package/dist/docx/unzip.d.ts +118 -0
- package/dist/docx/unzip.js +383 -0
- package/dist/docx/vmlImageParser.d.ts +16 -0
- package/dist/docx/vmlImageParser.js +100 -0
- package/dist/docx/watermarkParser.d.ts +45 -0
- package/dist/docx/watermarkParser.js +348 -0
- package/dist/docx/wrapTypes.d.ts +29 -0
- package/dist/docx/wrapTypes.js +48 -0
- package/dist/docx/xmlParser.d.ts +297 -0
- package/dist/docx/xmlParser.js +527 -0
- package/dist/fields/bookmarkPages.d.ts +13 -0
- package/dist/fields/bookmarkPages.js +66 -0
- package/dist/fields/bookmarkText.d.ts +16 -0
- package/dist/fields/bookmarkText.js +61 -0
- package/dist/fields/evaluateField.d.ts +23 -0
- package/dist/fields/evaluateField.js +77 -0
- package/dist/fields/fieldContext.d.ts +21 -0
- package/dist/fields/fieldContext.js +0 -0
- package/dist/fields/resolveFieldValues.d.ts +44 -0
- package/dist/fields/resolveFieldValues.js +204 -0
- package/dist/fields/sectionPageCounts.d.ts +11 -0
- package/dist/fields/sectionPageCounts.js +16 -0
- package/dist/fields/seqValues.d.ts +14 -0
- package/dist/fields/seqValues.js +36 -0
- package/dist/fonts/embeddedFontTable.d.ts +42 -0
- package/dist/fonts/embeddedFontTable.js +80 -0
- package/dist/fonts/embeddedFonts.d.ts +46 -0
- package/dist/fonts/embeddedFonts.js +112 -0
- package/dist/fonts/fontDeobfuscation.d.ts +30 -0
- package/dist/fonts/fontDeobfuscation.js +57 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +23 -0
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +57 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +316 -0
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +74 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +432 -0
- package/dist/layout-bridge/convert/templatePreviewFlow.d.ts +36 -0
- package/dist/layout-bridge/convert/templatePreviewFlow.js +176 -0
- package/dist/layout-bridge/convert/toFlowBlocks.d.ts +65 -0
- package/dist/layout-bridge/convert/toFlowBlocks.js +1309 -0
- package/dist/layout-bridge/convert/wrapEditorViewAsSurface.d.ts +17 -0
- package/dist/layout-bridge/convert/wrapEditorViewAsSurface.js +36 -0
- package/dist/layout-bridge/dom/clickToPositionDom.d.ts +66 -0
- package/dist/layout-bridge/dom/clickToPositionDom.js +304 -0
- package/dist/layout-bridge/dom/findBodyPmSpans.d.ts +7 -0
- package/dist/layout-bridge/dom/findBodyPmSpans.js +17 -0
- package/dist/layout-bridge/dom/findHfPmSpans.d.ts +62 -0
- package/dist/layout-bridge/dom/findHfPmSpans.js +197 -0
- package/dist/layout-bridge/engine/clickToPosition.d.ts +66 -0
- package/dist/layout-bridge/engine/clickToPosition.js +403 -0
- package/dist/layout-bridge/engine/hitTest.d.ts +135 -0
- package/dist/layout-bridge/engine/hitTest.js +375 -0
- package/dist/layout-bridge/engine/measuring/index.d.ts +10 -0
- package/dist/layout-bridge/engine/measuring/index.js +9 -0
- package/dist/layout-bridge/engine/selectionRects.d.ts +59 -0
- package/dist/layout-bridge/engine/selectionRects.js +485 -0
- package/dist/layout-bridge/engine/tableWidthUtils.d.ts +7 -0
- package/dist/layout-bridge/engine/tableWidthUtils.js +25 -0
- package/dist/layout-engine/index.d.ts +44 -0
- package/dist/layout-engine/index.js +691 -0
- package/dist/layout-engine/keep-together.d.ts +43 -0
- package/dist/layout-engine/keep-together.js +98 -0
- package/dist/layout-engine/layoutInstrumentation.d.ts +50 -0
- package/dist/layout-engine/layoutInstrumentation.js +43 -0
- package/dist/layout-engine/lineFlow.d.ts +8 -0
- package/dist/layout-engine/lineFlow.js +17 -0
- package/dist/layout-engine/measure/cache.d.ts +93 -0
- package/dist/layout-engine/measure/cache.js +245 -0
- package/dist/layout-engine/measure/clampFloatingWrapMargins.d.ts +20 -0
- package/dist/layout-engine/measure/clampFloatingWrapMargins.js +29 -0
- package/dist/layout-engine/measure/featureFlags.d.ts +44 -0
- package/dist/layout-engine/measure/featureFlags.js +19 -0
- package/dist/layout-engine/measure/floatingZones.d.ts +89 -0
- package/dist/layout-engine/measure/floatingZones.js +152 -0
- package/dist/layout-engine/measure/font-metrics.worker.d.ts +17 -0
- package/dist/layout-engine/measure/font-metrics.worker.js +104 -0
- package/dist/layout-engine/measure/index.d.ts +9 -0
- package/dist/layout-engine/measure/index.js +8 -0
- package/dist/layout-engine/measure/listMarkerWidth.d.ts +40 -0
- package/dist/layout-engine/measure/listMarkerWidth.js +76 -0
- package/dist/layout-engine/measure/measureBlocks.d.ts +25 -0
- package/dist/layout-engine/measure/measureBlocks.js +450 -0
- package/dist/layout-engine/measure/measureContainer.d.ts +24 -0
- package/dist/layout-engine/measure/measureContainer.js +280 -0
- package/dist/layout-engine/measure/measureHelpers.d.ts +82 -0
- package/dist/layout-engine/measure/measureHelpers.js +156 -0
- package/dist/layout-engine/measure/measureParagraph.d.ts +61 -0
- package/dist/layout-engine/measure/measureParagraph.js +724 -0
- package/dist/layout-engine/measure/measureProvider.d.ts +23 -0
- package/dist/layout-engine/measure/measureProvider.js +35 -0
- package/dist/layout-engine/measure/measureTypes.d.ts +61 -0
- package/dist/layout-engine/measure/measureTypes.js +0 -0
- package/dist/layout-engine/measure/measureWorker.d.ts +54 -0
- package/dist/layout-engine/measure/measureWorker.js +249 -0
- package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +88 -0
- package/dist/layout-engine/measure/measureWorkerProtocol.js +20 -0
- package/dist/layout-engine/measure/tableCellFloating.d.ts +26 -0
- package/dist/layout-engine/measure/tableCellFloating.js +99 -0
- package/dist/layout-engine/paginator.d.ts +84 -0
- package/dist/layout-engine/paginator.js +348 -0
- package/dist/layout-engine/paragraphFragmentRange.d.ts +9 -0
- package/dist/layout-engine/paragraphFragmentRange.js +40 -0
- package/dist/layout-engine/section-breaks.d.ts +78 -0
- package/dist/layout-engine/section-breaks.js +182 -0
- package/dist/layout-engine/tableRowBreak.d.ts +23 -0
- package/dist/layout-engine/tableRowBreak.js +147 -0
- package/dist/layout-engine/textBoxFlow.d.ts +50 -0
- package/dist/layout-engine/textBoxFlow.js +160 -0
- package/dist/layout-engine/types.d.ts +1031 -0
- package/dist/layout-engine/types.js +100 -0
- package/dist/layout-painter/documentColors.d.ts +4 -0
- package/dist/layout-painter/documentColors.js +40 -0
- package/dist/layout-painter/index.d.ts +110 -0
- package/dist/layout-painter/index.js +182 -0
- package/dist/layout-painter/registry/modules/image.d.ts +6 -0
- package/dist/layout-painter/registry/modules/image.js +17 -0
- package/dist/layout-painter/registry/modules/paragraph.d.ts +6 -0
- package/dist/layout-painter/registry/modules/paragraph.js +18 -0
- package/dist/layout-painter/registry/modules/table.d.ts +6 -0
- package/dist/layout-painter/registry/modules/table.js +16 -0
- package/dist/layout-painter/registry/modules/textBox.d.ts +6 -0
- package/dist/layout-painter/registry/modules/textBox.js +13 -0
- package/dist/layout-painter/registry/modules.d.ts +6 -0
- package/dist/layout-painter/registry/modules.js +26 -0
- package/dist/layout-painter/registry/registry.d.ts +24 -0
- package/dist/layout-painter/registry/registry.js +53 -0
- package/dist/layout-painter/registry/types.d.ts +61 -0
- package/dist/layout-painter/registry/types.js +0 -0
- package/dist/layout-painter/renderFragment.d.ts +32 -0
- package/dist/layout-painter/renderFragment.js +114 -0
- package/dist/layout-painter/renderImage.d.ts +88 -0
- package/dist/layout-painter/renderImage.js +130 -0
- package/dist/layout-painter/renderPage.d.ts +264 -0
- package/dist/layout-painter/renderPage.js +1795 -0
- package/dist/layout-painter/renderParagraph.d.ts +93 -0
- package/dist/layout-painter/renderParagraph.js +1300 -0
- package/dist/layout-painter/renderTable.d.ts +36 -0
- package/dist/layout-painter/renderTable.js +432 -0
- package/dist/layout-painter/renderTextBox.d.ts +22 -0
- package/dist/layout-painter/renderTextBox.js +67 -0
- package/dist/layout-painter/renderUtils.d.ts +42 -0
- package/dist/layout-painter/renderUtils.js +30 -0
- package/dist/layout-painter/renderWatermark.d.ts +16 -0
- package/dist/layout-painter/renderWatermark.js +61 -0
- package/dist/layout-painter/sdtBoundary.d.ts +6 -0
- package/dist/layout-painter/sdtBoundary.js +28 -0
- package/dist/managers/ContextMenuManager.d.ts +28 -0
- package/dist/managers/ContextMenuManager.js +48 -0
- package/dist/managers/DocumentLoaderManager.d.ts +47 -0
- package/dist/managers/DocumentLoaderManager.js +69 -0
- package/dist/managers/EditorModeManager.d.ts +28 -0
- package/dist/managers/EditorModeManager.js +50 -0
- package/dist/managers/ErrorManager.d.ts +26 -0
- package/dist/managers/ErrorManager.js +85 -0
- package/dist/managers/FindReplaceManager.d.ts +54 -0
- package/dist/managers/FindReplaceManager.js +104 -0
- package/dist/managers/HistoryManager.d.ts +92 -0
- package/dist/managers/HistoryManager.js +193 -0
- package/dist/managers/Subscribable.d.ts +34 -0
- package/dist/managers/Subscribable.js +46 -0
- package/dist/managers/TableSelectionManager.d.ts +74 -0
- package/dist/managers/TableSelectionManager.js +225 -0
- package/dist/managers/editorShortcuts.d.ts +42 -0
- package/dist/managers/editorShortcuts.js +60 -0
- package/dist/managers/types.d.ts +41 -0
- package/dist/managers/types.js +0 -0
- package/dist/markdown/annotations.d.ts +14 -0
- package/dist/markdown/annotations.js +42 -0
- package/dist/markdown/escape.d.ts +36 -0
- package/dist/markdown/escape.js +59 -0
- package/dist/markdown/fromMarkdown.d.ts +11 -0
- package/dist/markdown/fromMarkdown.js +223 -0
- package/dist/markdown/headings.d.ts +13 -0
- package/dist/markdown/headings.js +20 -0
- package/dist/markdown/images.d.ts +13 -0
- package/dist/markdown/images.js +63 -0
- package/dist/markdown/index.d.ts +18 -0
- package/dist/markdown/index.js +33 -0
- package/dist/markdown/internals.d.ts +15 -0
- package/dist/markdown/internals.js +35 -0
- package/dist/markdown/renderBlock.d.ts +7 -0
- package/dist/markdown/renderBlock.js +68 -0
- package/dist/markdown/renderParagraph.d.ts +11 -0
- package/dist/markdown/renderParagraph.js +64 -0
- package/dist/markdown/renderRuns.d.ts +11 -0
- package/dist/markdown/renderRuns.js +265 -0
- package/dist/markdown/renderTable.d.ts +8 -0
- package/dist/markdown/renderTable.js +229 -0
- package/dist/markdown/trailers.d.ts +13 -0
- package/dist/markdown/trailers.js +54 -0
- package/dist/markdown/types.d.ts +118 -0
- package/dist/markdown/types.js +0 -0
- package/dist/model.d.ts +13 -0
- package/dist/model.js +4 -0
- package/dist/paged-layout/LayoutSelectionGate.d.ts +80 -0
- package/dist/paged-layout/LayoutSelectionGate.js +131 -0
- package/dist/paged-layout/headerFooterMargins.d.ts +73 -0
- package/dist/paged-layout/headerFooterMargins.js +120 -0
- package/dist/paged-layout/hiddenEditorScroll.d.ts +4 -0
- package/dist/paged-layout/hiddenEditorScroll.js +4 -0
- package/dist/paged-layout/incrementalMeasure.d.ts +33 -0
- package/dist/paged-layout/incrementalMeasure.js +56 -0
- package/dist/paged-layout/rangeProjection.d.ts +51 -0
- package/dist/paged-layout/rangeProjection.js +153 -0
- package/dist/paged-layout/readOnlyEditAttempt.d.ts +5 -0
- package/dist/paged-layout/readOnlyEditAttempt.js +22 -0
- package/dist/paged-layout/scrollNavigation.d.ts +23 -0
- package/dist/paged-layout/scrollNavigation.js +31 -0
- package/dist/paged-layout/scrollPageInfo.d.ts +41 -0
- package/dist/paged-layout/scrollPageInfo.js +34 -0
- package/dist/paged-layout/scrollToPmPosition.d.ts +17 -0
- package/dist/paged-layout/scrollToPmPosition.js +95 -0
- package/dist/paged-layout/sectionBlockWidths.d.ts +35 -0
- package/dist/paged-layout/sectionBlockWidths.js +52 -0
- package/dist/paged-layout/sectionGeometry.d.ts +21 -0
- package/dist/paged-layout/sectionGeometry.js +36 -0
- package/dist/paged-layout/selectionViewportRect.d.ts +29 -0
- package/dist/paged-layout/selectionViewportRect.js +55 -0
- package/dist/paged-layout/tableColumnResize.d.ts +19 -0
- package/dist/paged-layout/tableColumnResize.js +28 -0
- package/dist/paged-layout/tableInsertButtonGeometry.d.ts +15 -0
- package/dist/paged-layout/tableInsertButtonGeometry.js +15 -0
- package/dist/paged-layout/transactionDirtyRange.d.ts +7 -0
- package/dist/paged-layout/transactionDirtyRange.js +27 -0
- package/dist/paged-layout/zoomScrollAnchor.d.ts +40 -0
- package/dist/paged-layout/zoomScrollAnchor.js +25 -0
- package/dist/prosemirror/attrs/index.d.ts +80 -0
- package/dist/prosemirror/attrs/index.js +1218 -0
- package/dist/prosemirror/autospacingBase.d.ts +11 -0
- package/dist/prosemirror/autospacingBase.js +16 -0
- package/dist/prosemirror/commands/comments.d.ts +93 -0
- package/dist/prosemirror/commands/comments.js +435 -0
- package/dist/prosemirror/commands/contentControls.d.ts +45 -0
- package/dist/prosemirror/commands/contentControls.js +294 -0
- package/dist/prosemirror/commands/contentControlsBlockFill.d.ts +15 -0
- package/dist/prosemirror/commands/contentControlsBlockFill.js +19 -0
- package/dist/prosemirror/commands/formatPainter.d.ts +31 -0
- package/dist/prosemirror/commands/formatPainter.js +130 -0
- package/dist/prosemirror/commands/formatting.d.ts +32 -0
- package/dist/prosemirror/commands/formatting.js +45 -0
- package/dist/prosemirror/commands/hyperlink.d.ts +31 -0
- package/dist/prosemirror/commands/hyperlink.js +79 -0
- package/dist/prosemirror/commands/image.d.ts +59 -0
- package/dist/prosemirror/commands/image.js +219 -0
- package/dist/prosemirror/commands/index.d.ts +13 -0
- package/dist/prosemirror/commands/index.js +13 -0
- package/dist/prosemirror/commands/pageBreak.d.ts +10 -0
- package/dist/prosemirror/commands/pageBreak.js +47 -0
- package/dist/prosemirror/commands/paragraph.d.ts +39 -0
- package/dist/prosemirror/commands/paragraph.js +64 -0
- package/dist/prosemirror/commands/pastePlainText.d.ts +39 -0
- package/dist/prosemirror/commands/pastePlainText.js +67 -0
- package/dist/prosemirror/commands/table.d.ts +83 -0
- package/dist/prosemirror/commands/table.js +105 -0
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +27 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +1550 -0
- package/dist/prosemirror/conversion/index.d.ts +4 -0
- package/dist/prosemirror/conversion/index.js +4 -0
- package/dist/prosemirror/conversion/runShadingMark.d.ts +16 -0
- package/dist/prosemirror/conversion/runShadingMark.js +39 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +39 -0
- package/dist/prosemirror/conversion/toProseDoc.js +1404 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +43 -0
- package/dist/prosemirror/extensions/ExtensionManager.js +86 -0
- package/dist/prosemirror/extensions/StarterKit.d.ts +16 -0
- package/dist/prosemirror/extensions/StarterKit.js +132 -0
- package/dist/prosemirror/extensions/core/DocExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/core/DocExtension.js +12 -0
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/core/HistoryExtension.js +28 -0
- package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +25 -0
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +619 -0
- package/dist/prosemirror/extensions/core/TextExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/core/TextExtension.js +12 -0
- package/dist/prosemirror/extensions/create.d.ts +17 -0
- package/dist/prosemirror/extensions/create.js +129 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +106 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.d.ts +8 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +172 -0
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.d.ts +16 -0
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +38 -0
- package/dist/prosemirror/extensions/features/ContentControlWidgetsExtension.d.ts +16 -0
- package/dist/prosemirror/extensions/features/ContentControlWidgetsExtension.js +21 -0
- package/dist/prosemirror/extensions/features/DropCursorExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/features/DropCursorExtension.js +20 -0
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.d.ts +8 -0
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +44 -0
- package/dist/prosemirror/extensions/features/GapCursorExtension.d.ts +19 -0
- package/dist/prosemirror/extensions/features/GapCursorExtension.js +24 -0
- package/dist/prosemirror/extensions/features/ImageDragExtension.d.ts +15 -0
- package/dist/prosemirror/extensions/features/ImageDragExtension.js +66 -0
- package/dist/prosemirror/extensions/features/ImagePasteExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +91 -0
- package/dist/prosemirror/extensions/features/ListExtension.d.ts +14 -0
- package/dist/prosemirror/extensions/features/ListExtension.js +340 -0
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +60 -0
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +35 -0
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +188 -0
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +20 -0
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +34 -0
- package/dist/prosemirror/extensions/features/PasteStyleInlinerExtension.d.ts +20 -0
- package/dist/prosemirror/extensions/features/PasteStyleInlinerExtension.js +145 -0
- package/dist/prosemirror/extensions/features/SelectionTrackerExtension.d.ts +10 -0
- package/dist/prosemirror/extensions/features/SelectionTrackerExtension.js +17 -0
- package/dist/prosemirror/extensions/features/bidiShortcutController.d.ts +31 -0
- package/dist/prosemirror/extensions/features/bidiShortcutController.js +27 -0
- package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +31 -0
- package/dist/prosemirror/extensions/features/pasteCleanup.js +159 -0
- package/dist/prosemirror/extensions/marks/AllCapsExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/AllCapsExtension.js +24 -0
- package/dist/prosemirror/extensions/marks/BoldExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/BoldExtension.js +41 -0
- package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.d.ts +14 -0
- package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.js +64 -0
- package/dist/prosemirror/extensions/marks/CharacterStyleExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/marks/CharacterStyleExtension.js +47 -0
- package/dist/prosemirror/extensions/marks/CommentExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/marks/CommentExtension.js +38 -0
- package/dist/prosemirror/extensions/marks/FontFamilyExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/FontFamilyExtension.js +55 -0
- package/dist/prosemirror/extensions/marks/FontSizeExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/FontSizeExtension.js +47 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.d.ts +11 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +92 -0
- package/dist/prosemirror/extensions/marks/HiddenTextExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/marks/HiddenTextExtension.js +35 -0
- package/dist/prosemirror/extensions/marks/HighlightExtension.d.ts +10 -0
- package/dist/prosemirror/extensions/marks/HighlightExtension.js +115 -0
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +146 -0
- package/dist/prosemirror/extensions/marks/ItalicExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/ItalicExtension.js +34 -0
- package/dist/prosemirror/extensions/marks/RtlExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/RtlExtension.js +21 -0
- package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.d.ts +11 -0
- package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.js +75 -0
- package/dist/prosemirror/extensions/marks/RunShadingExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/RunShadingExtension.js +38 -0
- package/dist/prosemirror/extensions/marks/SmallCapsExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SmallCapsExtension.js +24 -0
- package/dist/prosemirror/extensions/marks/StrikeExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/StrikeExtension.js +33 -0
- package/dist/prosemirror/extensions/marks/SubscriptExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SubscriptExtension.js +25 -0
- package/dist/prosemirror/extensions/marks/SuperscriptExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SuperscriptExtension.js +25 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +50 -0
- package/dist/prosemirror/extensions/marks/TextEffectExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/TextEffectExtension.js +35 -0
- package/dist/prosemirror/extensions/marks/TextEffectsExtensions.d.ts +31 -0
- package/dist/prosemirror/extensions/marks/TextEffectsExtensions.js +134 -0
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.d.ts +22 -0
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +113 -0
- package/dist/prosemirror/extensions/marks/UnderlineExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/UnderlineExtension.js +60 -0
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +34 -0
- package/dist/prosemirror/extensions/marks/markUtils.js +233 -0
- package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +22 -0
- package/dist/prosemirror/extensions/nodes/BlockSdtExtension.js +122 -0
- package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/nodes/FieldExtension.js +87 -0
- package/dist/prosemirror/extensions/nodes/HardBreakExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/HardBreakExtension.js +38 -0
- package/dist/prosemirror/extensions/nodes/HorizontalRuleExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/HorizontalRuleExtension.js +18 -0
- package/dist/prosemirror/extensions/nodes/ImageExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +132 -0
- package/dist/prosemirror/extensions/nodes/MathExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/nodes/MathExtension.js +56 -0
- package/dist/prosemirror/extensions/nodes/PageBreakExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/PageBreakExtension.js +20 -0
- package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/nodes/SdtExtension.js +107 -0
- package/dist/prosemirror/extensions/nodes/ShapeExtension.d.ts +30 -0
- package/dist/prosemirror/extensions/nodes/ShapeExtension.js +502 -0
- package/dist/prosemirror/extensions/nodes/TabExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/TabExtension.js +27 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +34 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.js +1972 -0
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.d.ts +34 -0
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +150 -0
- package/dist/prosemirror/extensions/types.d.ts +101 -0
- package/dist/prosemirror/extensions/types.js +10 -0
- package/dist/prosemirror/findReplaceSelection.d.ts +23 -0
- package/dist/prosemirror/findReplaceSelection.js +86 -0
- package/dist/prosemirror/index.d.ts +25 -0
- package/dist/prosemirror/index.js +23 -0
- package/dist/prosemirror/insertOperations.d.ts +12 -0
- package/dist/prosemirror/insertOperations.js +19 -0
- package/dist/prosemirror/paragraphDirection.d.ts +42 -0
- package/dist/prosemirror/paragraphDirection.js +33 -0
- package/dist/prosemirror/plugins/aiCitationDecorations.d.ts +40 -0
- package/dist/prosemirror/plugins/aiCitationDecorations.js +90 -0
- package/dist/prosemirror/plugins/aiSuggestionDecorations.d.ts +42 -0
- package/dist/prosemirror/plugins/aiSuggestionDecorations.js +135 -0
- package/dist/prosemirror/plugins/anonymizationDecorations.d.ts +60 -0
- package/dist/prosemirror/plugins/anonymizationDecorations.js +120 -0
- package/dist/prosemirror/plugins/autocompleteSuggestion.d.ts +123 -0
- package/dist/prosemirror/plugins/autocompleteSuggestion.js +283 -0
- package/dist/prosemirror/plugins/contentControlWidgets.d.ts +56 -0
- package/dist/prosemirror/plugins/contentControlWidgets.js +192 -0
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +37 -0
- package/dist/prosemirror/plugins/createDocScanPlugin.js +55 -0
- package/dist/prosemirror/plugins/documentStyles.d.ts +18 -0
- package/dist/prosemirror/plugins/documentStyles.js +46 -0
- package/dist/prosemirror/plugins/index.d.ts +3 -0
- package/dist/prosemirror/plugins/index.js +3 -0
- package/dist/prosemirror/plugins/pmTextScan.d.ts +19 -0
- package/dist/prosemirror/plugins/pmTextScan.js +39 -0
- package/dist/prosemirror/plugins/selectionTracker.d.ts +43 -0
- package/dist/prosemirror/plugins/selectionTracker.js +179 -0
- package/dist/prosemirror/plugins/suggestionMode.d.ts +70 -0
- package/dist/prosemirror/plugins/suggestionMode.js +489 -0
- package/dist/prosemirror/plugins/templateDirectives.d.ts +25 -0
- package/dist/prosemirror/plugins/templateDirectives.js +67 -0
- package/dist/prosemirror/plugins/templatePreviewValues.d.ts +49 -0
- package/dist/prosemirror/plugins/templatePreviewValues.js +117 -0
- package/dist/prosemirror/plugins/templateSlashMenu.d.ts +57 -0
- package/dist/prosemirror/plugins/templateSlashMenu.js +184 -0
- package/dist/prosemirror/schema/index.d.ts +15 -0
- package/dist/prosemirror/schema/index.js +20 -0
- package/dist/prosemirror/schema/marks.d.ts +118 -0
- package/dist/prosemirror/schema/marks.js +0 -0
- package/dist/prosemirror/schema/nodes.d.ts +389 -0
- package/dist/prosemirror/schema/nodes.js +0 -0
- package/dist/prosemirror/selectionState.d.ts +23 -0
- package/dist/prosemirror/selectionState.js +111 -0
- package/dist/prosemirror/styles/index.d.ts +2 -0
- package/dist/prosemirror/styles/index.js +2 -0
- package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +32 -0
- package/dist/prosemirror/styles/resolvedStyleAttrs.js +108 -0
- package/dist/prosemirror/styles/styleResolver.d.ts +94 -0
- package/dist/prosemirror/styles/styleResolver.js +200 -0
- package/dist/prosemirror/utils/findParagraphByParaId.d.ts +26 -0
- package/dist/prosemirror/utils/findParagraphByParaId.js +37 -0
- package/dist/prosemirror/utils/tabCalculator.d.ts +110 -0
- package/dist/prosemirror/utils/tabCalculator.js +137 -0
- package/dist/prosemirror/validation.d.ts +20 -0
- package/dist/prosemirror/validation.js +177 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +6 -0
- package/dist/style-engine/index.d.ts +3 -0
- package/dist/style-engine/index.js +2 -0
- package/dist/style-engine/styleEngine.d.ts +67 -0
- package/dist/style-engine/styleEngine.js +70 -0
- package/dist/types/block-id.d.ts +58 -0
- package/dist/types/block-id.js +61 -0
- package/dist/types/colors.d.ts +2 -0
- package/dist/types/colors.js +0 -0
- package/dist/types/content.d.ts +2 -0
- package/dist/types/content.js +0 -0
- package/dist/types/document.d.ts +7 -0
- package/dist/types/document.js +0 -0
- package/dist/types/documentEnumValues.d.ts +89 -0
- package/dist/types/documentEnumValues.js +693 -0
- package/dist/types/formatting.d.ts +2 -0
- package/dist/types/formatting.js +0 -0
- package/dist/types/index.d.ts +107 -0
- package/dist/types/index.js +0 -0
- package/dist/utils/authorColors.d.ts +16 -0
- package/dist/utils/authorColors.js +30 -0
- package/dist/utils/baseDirection.d.ts +23 -0
- package/dist/utils/baseDirection.js +34 -0
- package/dist/utils/clipboard.d.ts +126 -0
- package/dist/utils/clipboard.js +622 -0
- package/dist/utils/colorResolver.d.ts +158 -0
- package/dist/utils/colorResolver.js +557 -0
- package/dist/utils/createDocument.d.ts +50 -0
- package/dist/utils/createDocument.js +262 -0
- package/dist/utils/documentLoaderBehavior.d.ts +22 -0
- package/dist/utils/documentLoaderBehavior.js +14 -0
- package/dist/utils/docxInput.d.ts +22 -0
- package/dist/utils/docxInput.js +16 -0
- package/dist/utils/domGuards.d.ts +59 -0
- package/dist/utils/domGuards.js +82 -0
- package/dist/utils/fontFamilyMerge.d.ts +7 -0
- package/dist/utils/fontFamilyMerge.js +31 -0
- package/dist/utils/fontLoader.d.ts +50 -0
- package/dist/utils/fontLoader.js +177 -0
- package/dist/utils/fontResolver.d.ts +61 -0
- package/dist/utils/fontResolver.js +651 -0
- package/dist/utils/fontWeights.d.ts +4 -0
- package/dist/utils/fontWeights.js +4 -0
- package/dist/utils/formatToStyle.d.ts +103 -0
- package/dist/utils/formatToStyle.js +289 -0
- package/dist/utils/headerFooter.d.ts +74 -0
- package/dist/utils/headerFooter.js +257 -0
- package/dist/utils/headingCollector.d.ts +22 -0
- package/dist/utils/headingCollector.js +36 -0
- package/dist/utils/hexId.d.ts +33 -0
- package/dist/utils/hexId.js +37 -0
- package/dist/utils/imageValidation.d.ts +5 -0
- package/dist/utils/imageValidation.js +31 -0
- package/dist/utils/paragraphFormattingMerge.d.ts +14 -0
- package/dist/utils/paragraphFormattingMerge.js +68 -0
- package/dist/utils/replaceText.d.ts +17 -0
- package/dist/utils/replaceText.js +161 -0
- package/dist/utils/rotationBoundingBox.d.ts +12 -0
- package/dist/utils/rotationBoundingBox.js +36 -0
- package/dist/utils/scriptSegments.d.ts +36 -0
- package/dist/utils/scriptSegments.js +52 -0
- package/dist/utils/tableOperations.d.ts +87 -0
- package/dist/utils/tableOperations.js +259 -0
- package/dist/utils/textFormattingMerge.d.ts +6 -0
- package/dist/utils/textFormattingMerge.js +31 -0
- package/dist/utils/tiffConverter.d.ts +18 -0
- package/dist/utils/tiffConverter.js +83 -0
- package/dist/utils/units.d.ts +99 -0
- package/dist/utils/units.js +139 -0
- package/dist/utils/urlSecurity.d.ts +7 -0
- package/dist/utils/urlSecurity.js +65 -0
- package/dist/watermark/index.d.ts +39 -0
- package/dist/watermark/index.js +149 -0
- package/package.json +122 -2
|
@@ -0,0 +1,683 @@
|
|
|
1
|
+
import { getFolioParaIdFromBlockId } from "../types/block-id.js";
|
|
2
|
+
import { buildCleanBlockText } from "./clean-text.js";
|
|
3
|
+
import { hasInlineEmphasis, parseInlineEmphasisRuns, stripInlineEmphasisMarkers } from "./inline-emphasis.js";
|
|
4
|
+
import { hashFolioAIBlockText, normalizeFolioAIBlockText } from "./snapshot.js";
|
|
5
|
+
import { diffWordSegments } from "./word-diff.js";
|
|
6
|
+
//#region src/ai-edits/apply.ts
|
|
7
|
+
/**
|
|
8
|
+
* Block attrs that identify a block instance (Word's
|
|
9
|
+
* `w14:paraId` / `w14:textId`, future tracked-change identifiers).
|
|
10
|
+
* Reuse during inheritFormatting would create duplicate IDs, so
|
|
11
|
+
* we strip them when synthesising a sibling.
|
|
12
|
+
*/
|
|
13
|
+
const IDENTITY_BLOCK_ATTRS = /* @__PURE__ */ new Set(["paraId", "textId"]);
|
|
14
|
+
const stripIdentityAttrs = (attrs) => {
|
|
15
|
+
const next = {};
|
|
16
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
17
|
+
if (IDENTITY_BLOCK_ATTRS.has(key)) {
|
|
18
|
+
next[key] = null;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
next[key] = value;
|
|
22
|
+
}
|
|
23
|
+
return next;
|
|
24
|
+
};
|
|
25
|
+
const applyReplaceBlockStyleId = ({ item, tr }) => {
|
|
26
|
+
if (item.operation.type !== "replaceBlock" || item.operation.styleId === void 0) return tr;
|
|
27
|
+
const block = tr.doc.nodeAt(item.blockFrom);
|
|
28
|
+
if (!block) return tr;
|
|
29
|
+
return tr.setNodeMarkup(item.blockFrom, void 0, {
|
|
30
|
+
...block.attrs,
|
|
31
|
+
styleId: item.operation.styleId
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Module-scoped monotonic counter for tracked-change revision ids.
|
|
36
|
+
* Seeded once from `Date.now()` so ids are roughly time-ordered for
|
|
37
|
+
* humans reading raw DOCX, then incremented per allocation. A bare
|
|
38
|
+
* `Date.now()` seed per applyAIEditOperations call would collide
|
|
39
|
+
* across batches that fire within the same millisecond (the panel's
|
|
40
|
+
* Accept-all loop does exactly that — multiple calls in tight
|
|
41
|
+
* succession). Reserving a contiguous range up front guarantees
|
|
42
|
+
* uniqueness across overlapping calls in the same JS realm.
|
|
43
|
+
*/
|
|
44
|
+
let revisionIdCursor = Date.now() * 1e3;
|
|
45
|
+
const nextRevisionSeed = (count) => {
|
|
46
|
+
const start = revisionIdCursor;
|
|
47
|
+
revisionIdCursor += Math.max(count, 1) * 4;
|
|
48
|
+
return start;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Walk the live doc once and bucket every textblock by its
|
|
52
|
+
* normalised text hash. Resolution then maps each snapshot anchor
|
|
53
|
+
* to the live block at the same ordinal among same-hash siblings —
|
|
54
|
+
* unrelated edits that shift absolute positions no longer break
|
|
55
|
+
* the lookup, and a sibling sharing text content with the target
|
|
56
|
+
* doesn't trigger a false "changed" skip either.
|
|
57
|
+
*/
|
|
58
|
+
const collectLiveBlocksByHash = (doc) => {
|
|
59
|
+
const byHash = /* @__PURE__ */ new Map();
|
|
60
|
+
doc.descendants((node, pos) => {
|
|
61
|
+
if (!node.isTextblock) return;
|
|
62
|
+
const cleanText = buildCleanBlockText(node, pos).text;
|
|
63
|
+
const hash = hashFolioAIBlockText(normalizeFolioAIBlockText(cleanText));
|
|
64
|
+
const bucket = byHash.get(hash) ?? [];
|
|
65
|
+
bucket.push({
|
|
66
|
+
from: pos,
|
|
67
|
+
to: pos + node.nodeSize,
|
|
68
|
+
node
|
|
69
|
+
});
|
|
70
|
+
byHash.set(hash, bucket);
|
|
71
|
+
});
|
|
72
|
+
return byHash;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Index live textblocks by their `w14:paraId`. Used by the resolver
|
|
76
|
+
* to prefer a paraId-anchored lookup when the snapshot id encodes
|
|
77
|
+
* one. Direct lookup avoids
|
|
78
|
+
* the hash+ordinal failure mode where an earlier-in-document
|
|
79
|
+
* duplicate of the same text gets picked instead of the actual
|
|
80
|
+
* referenced paragraph.
|
|
81
|
+
*/
|
|
82
|
+
const collectLiveBlocksByParaId = (doc) => {
|
|
83
|
+
const byParaId = /* @__PURE__ */ new Map();
|
|
84
|
+
doc.descendants((node, pos) => {
|
|
85
|
+
if (!node.isTextblock) return;
|
|
86
|
+
const paraId = node.attrs["paraId"];
|
|
87
|
+
if (typeof paraId !== "string" || paraId.length === 0) return;
|
|
88
|
+
if (!byParaId.has(paraId)) byParaId.set(paraId, {
|
|
89
|
+
from: pos,
|
|
90
|
+
to: pos + node.nodeSize,
|
|
91
|
+
node
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
return byParaId;
|
|
95
|
+
};
|
|
96
|
+
const findEnclosingTableBoundary = (doc, blockFrom) => {
|
|
97
|
+
const resolved = doc.resolve(blockFrom);
|
|
98
|
+
for (let depth = resolved.depth; depth > 0; depth--) if (resolved.node(depth).type.name === "table") return {
|
|
99
|
+
before: resolved.before(depth),
|
|
100
|
+
after: resolved.after(depth)
|
|
101
|
+
};
|
|
102
|
+
return null;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* The snapshot recorded an `hashOccurrenceCount` per anchor but
|
|
106
|
+
* not which ordinal within that bucket the block was — recompute
|
|
107
|
+
* on demand from the snapshot's anchor map. Stable iteration
|
|
108
|
+
* (object insertion order) means anchors with the same hash come
|
|
109
|
+
* out in document order, which is what we want.
|
|
110
|
+
*/
|
|
111
|
+
const ordinalAmongSameHash = (snapshot, blockId) => {
|
|
112
|
+
const target = snapshot.anchors[blockId];
|
|
113
|
+
if (!target) return -1;
|
|
114
|
+
let ordinal = 0;
|
|
115
|
+
for (const anchor of Object.values(snapshot.anchors)) {
|
|
116
|
+
if (anchor.id === blockId) return ordinal;
|
|
117
|
+
if (anchor.textHash === target.textHash) ordinal += 1;
|
|
118
|
+
}
|
|
119
|
+
return -1;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Length of the underscore signature rule. Mirrors the constant
|
|
123
|
+
* in `docx-core/legal-source/compile.ts` so the on-screen signature
|
|
124
|
+
* line matches what `create-document` produces.
|
|
125
|
+
*/
|
|
126
|
+
const SIGNATURE_LINE = "_".repeat(28);
|
|
127
|
+
/**
|
|
128
|
+
* Build a borderless PM table mirroring docx-core's
|
|
129
|
+
* `signatureTable` helper: one row, one cell per party, each cell
|
|
130
|
+
* containing party name (bold), two spacer paragraphs, a signature
|
|
131
|
+
* rule, then optional signatory and italic title lines.
|
|
132
|
+
*
|
|
133
|
+
* Returns `null` when the editor schema is missing one of the
|
|
134
|
+
* required node types — callers should surface the op as a skip
|
|
135
|
+
* rather than crashing.
|
|
136
|
+
*/
|
|
137
|
+
const buildSignatureTableNode = ({ schema, parties }) => {
|
|
138
|
+
const paragraphType = schema.nodes["paragraph"];
|
|
139
|
+
const cellType = schema.nodes["tableCell"];
|
|
140
|
+
const rowType = schema.nodes["tableRow"];
|
|
141
|
+
const tableType = schema.nodes["table"];
|
|
142
|
+
if (!paragraphType || !cellType || !rowType || !tableType) return null;
|
|
143
|
+
const boldType = schema.marks["bold"];
|
|
144
|
+
const italicType = schema.marks["italic"];
|
|
145
|
+
const buildParagraph = (text, options) => {
|
|
146
|
+
const marks = [];
|
|
147
|
+
if (options.bold && boldType) marks.push(boldType.create());
|
|
148
|
+
if (options.italic && italicType) marks.push(italicType.create());
|
|
149
|
+
const content = text.length > 0 ? schema.text(text, marks) : null;
|
|
150
|
+
return paragraphType.create({ styleId: options.styleId }, content);
|
|
151
|
+
};
|
|
152
|
+
const buildCell = (party) => {
|
|
153
|
+
const cellContent = [
|
|
154
|
+
buildParagraph(party.name, {
|
|
155
|
+
styleId: "SignatureParty",
|
|
156
|
+
bold: true
|
|
157
|
+
}),
|
|
158
|
+
buildParagraph("", { styleId: "SignatureSpacer" }),
|
|
159
|
+
buildParagraph("", { styleId: "SignatureSpacer" }),
|
|
160
|
+
buildParagraph(SIGNATURE_LINE, { styleId: "SignatureRule" })
|
|
161
|
+
];
|
|
162
|
+
if (party.signatory && party.signatory.length > 0) cellContent.push(buildParagraph(party.signatory, { styleId: "SignatureField" }));
|
|
163
|
+
if (party.title && party.title.length > 0) cellContent.push(buildParagraph(party.title, {
|
|
164
|
+
styleId: "SignatureField",
|
|
165
|
+
italic: true
|
|
166
|
+
}));
|
|
167
|
+
return cellType.create({}, cellContent);
|
|
168
|
+
};
|
|
169
|
+
const cells = parties.map(buildCell);
|
|
170
|
+
const row = rowType.create({}, cells);
|
|
171
|
+
return tableType.create({}, row);
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Build the inline content for an inserted or replaced block, promoting the
|
|
175
|
+
* model's `**bold**` / `***bold italic***` markdown into real Word marks (the
|
|
176
|
+
* edit-tool schema has no inline-format channel, so the model improvises with
|
|
177
|
+
* markdown that would otherwise land as literal asterisks). Falls back to a
|
|
178
|
+
* single verbatim text node when no emphasis is present, so plain prose is
|
|
179
|
+
* never reshaped. `baseMarks` (insertion / comment) ride on every run.
|
|
180
|
+
*/
|
|
181
|
+
const buildEmphasisInlineContent = (schema, text, baseMarks) => {
|
|
182
|
+
const runs = parseInlineEmphasisRuns(text);
|
|
183
|
+
if (!runs.some((run) => run.bold || run.italic)) return [schema.text(text, [...baseMarks])];
|
|
184
|
+
const boldType = schema.marks["bold"];
|
|
185
|
+
const italicType = schema.marks["italic"];
|
|
186
|
+
const nodes = [];
|
|
187
|
+
for (const run of runs) {
|
|
188
|
+
if (run.text.length === 0) continue;
|
|
189
|
+
const marks = [...baseMarks];
|
|
190
|
+
if (run.bold && boldType) marks.push(boldType.create());
|
|
191
|
+
if (run.italic && italicType) marks.push(italicType.create());
|
|
192
|
+
nodes.push(schema.text(run.text, marks));
|
|
193
|
+
}
|
|
194
|
+
return nodes.length > 0 ? nodes : [schema.text(text, [...baseMarks])];
|
|
195
|
+
};
|
|
196
|
+
const applyFolioAIEditOperations = ({ view, snapshot, operations, mode = "tracked-changes", author = "AI", createCommentId }) => {
|
|
197
|
+
const applied = [];
|
|
198
|
+
const skipped = [];
|
|
199
|
+
const resolved = [];
|
|
200
|
+
const insertionType = view.state.schema.marks["insertion"];
|
|
201
|
+
const deletionType = view.state.schema.marks["deletion"];
|
|
202
|
+
const commentType = view.state.schema.marks["comment"];
|
|
203
|
+
if (mode === "tracked-changes" && (!insertionType || !deletionType)) return {
|
|
204
|
+
applied,
|
|
205
|
+
skipped: operations.map((operation) => ({
|
|
206
|
+
id: operation.id,
|
|
207
|
+
reason: "unsupportedBlock"
|
|
208
|
+
}))
|
|
209
|
+
};
|
|
210
|
+
const liveBlocks = collectLiveBlocksByHash(view.state.doc);
|
|
211
|
+
const liveBlocksByParaId = collectLiveBlocksByParaId(view.state.doc);
|
|
212
|
+
for (const [index, operation] of operations.entries()) {
|
|
213
|
+
const commentText = getOperationCommentText(operation);
|
|
214
|
+
if (commentText !== void 0 && (!commentType || createCommentId === void 0)) {
|
|
215
|
+
skipped.push({
|
|
216
|
+
id: operation.id,
|
|
217
|
+
reason: "unsupportedBlock"
|
|
218
|
+
});
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const resolution = resolveOperation({
|
|
222
|
+
snapshot,
|
|
223
|
+
operation,
|
|
224
|
+
liveBlocks,
|
|
225
|
+
liveBlocksByParaId,
|
|
226
|
+
doc: view.state.doc
|
|
227
|
+
});
|
|
228
|
+
if (resolution.type === "skip") {
|
|
229
|
+
skipped.push({
|
|
230
|
+
id: operation.id,
|
|
231
|
+
reason: resolution.reason
|
|
232
|
+
});
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const commentId = commentText !== void 0 ? createCommentId?.(commentText) : void 0;
|
|
236
|
+
resolved.push({
|
|
237
|
+
...resolution.operation,
|
|
238
|
+
originalIndex: index,
|
|
239
|
+
...commentId !== void 0 && { commentId }
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
if (resolved.length === 0) return {
|
|
243
|
+
applied,
|
|
244
|
+
skipped
|
|
245
|
+
};
|
|
246
|
+
let tr = view.state.tr;
|
|
247
|
+
let revisionSeed = nextRevisionSeed(resolved.length);
|
|
248
|
+
const date = (/* @__PURE__ */ new Date()).toISOString();
|
|
249
|
+
for (const item of resolved.toSorted((left, right) => {
|
|
250
|
+
if (left.from !== right.from) return right.from - left.from;
|
|
251
|
+
return right.originalIndex - left.originalIndex;
|
|
252
|
+
})) {
|
|
253
|
+
const commentMark = item.commentId !== void 0 && commentType ? commentType.create({ commentId: item.commentId }) : null;
|
|
254
|
+
const stepsBefore = tr.steps.length;
|
|
255
|
+
let appliedRevisionIds;
|
|
256
|
+
switch (item.operation.type) {
|
|
257
|
+
case "replaceInBlock": {
|
|
258
|
+
const revisionIdDelete = revisionSeed++;
|
|
259
|
+
const revisionIdInsert = revisionSeed++;
|
|
260
|
+
tr = applyTextReplacement({
|
|
261
|
+
tr,
|
|
262
|
+
item,
|
|
263
|
+
mode,
|
|
264
|
+
author,
|
|
265
|
+
date,
|
|
266
|
+
revisionIdDelete,
|
|
267
|
+
revisionIdInsert,
|
|
268
|
+
commentMark
|
|
269
|
+
});
|
|
270
|
+
if (mode === "tracked-changes") appliedRevisionIds = [revisionIdDelete, revisionIdInsert];
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
case "replaceBlock": {
|
|
274
|
+
const revisionIdDelete = revisionSeed++;
|
|
275
|
+
const revisionIdInsert = revisionSeed++;
|
|
276
|
+
if (item.operation.preserveFormatting === false && mode === "direct") {
|
|
277
|
+
const replacement = item.operation.text;
|
|
278
|
+
const paragraphType = view.state.schema.nodes["paragraph"];
|
|
279
|
+
if (paragraphType) {
|
|
280
|
+
const replaceAttrs = item.operation.styleId !== void 0 ? { styleId: item.operation.styleId } : null;
|
|
281
|
+
const node = paragraphType.create(replaceAttrs, replacement.length === 0 ? null : buildEmphasisInlineContent(view.state.schema, replacement, []));
|
|
282
|
+
tr = tr.replaceWith(item.blockFrom, item.blockTo, node);
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (mode === "direct" && hasInlineEmphasis(item.operation.text)) {
|
|
287
|
+
const attrs = item.operation.styleId !== void 0 ? {
|
|
288
|
+
...item.blockNode.attrs,
|
|
289
|
+
styleId: item.operation.styleId
|
|
290
|
+
} : { ...item.blockNode.attrs };
|
|
291
|
+
const node = item.blockNode.type.create(attrs, buildEmphasisInlineContent(view.state.schema, item.operation.text, commentMark ? [commentMark] : []));
|
|
292
|
+
tr = tr.replaceWith(item.blockFrom, item.blockTo, node);
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
tr = applyTextReplacement({
|
|
296
|
+
tr,
|
|
297
|
+
item,
|
|
298
|
+
mode,
|
|
299
|
+
author,
|
|
300
|
+
date,
|
|
301
|
+
revisionIdDelete,
|
|
302
|
+
revisionIdInsert,
|
|
303
|
+
commentMark
|
|
304
|
+
});
|
|
305
|
+
tr = applyReplaceBlockStyleId({
|
|
306
|
+
item,
|
|
307
|
+
tr
|
|
308
|
+
});
|
|
309
|
+
if (mode === "tracked-changes") appliedRevisionIds = [revisionIdDelete, revisionIdInsert];
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
case "insertAfterBlock":
|
|
313
|
+
case "insertBeforeBlock": {
|
|
314
|
+
if (mode === "tracked-changes" && item.operation.pageBreakBefore === true && (!item.insertText || item.insertText.length === 0)) {
|
|
315
|
+
skipped.push({
|
|
316
|
+
id: item.operation.id,
|
|
317
|
+
reason: "unsupportedBlock"
|
|
318
|
+
});
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
const marks = [];
|
|
322
|
+
if (mode === "tracked-changes" && insertionType) {
|
|
323
|
+
const revisionId = revisionSeed++;
|
|
324
|
+
marks.push(insertionType.create({
|
|
325
|
+
revisionId,
|
|
326
|
+
author,
|
|
327
|
+
date
|
|
328
|
+
}));
|
|
329
|
+
appliedRevisionIds = [revisionId];
|
|
330
|
+
}
|
|
331
|
+
if (commentMark) marks.push(commentMark);
|
|
332
|
+
const content = item.insertText && item.insertText.length > 0 ? buildEmphasisInlineContent(view.state.schema, item.insertText, marks) : null;
|
|
333
|
+
const attrs = { ...item.operation.inheritFormatting === false ? {} : stripIdentityAttrs(item.blockNode.attrs) };
|
|
334
|
+
if (item.operation.pageBreakBefore === true) attrs["pageBreakBefore"] = true;
|
|
335
|
+
if (item.operation.styleId !== void 0) {
|
|
336
|
+
attrs["styleId"] = item.operation.styleId;
|
|
337
|
+
if (item.operation.inheritFormatting !== false) {
|
|
338
|
+
attrs["listMarker"] = null;
|
|
339
|
+
attrs["listMarkerHidden"] = null;
|
|
340
|
+
attrs["listLevelNumFmts"] = null;
|
|
341
|
+
attrs["listAbstractNumId"] = null;
|
|
342
|
+
attrs["listStartOverride"] = null;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const node = item.blockNode.type.create(attrs, content);
|
|
346
|
+
tr = tr.insert(item.from, node);
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
case "insertSignatureTable": {
|
|
350
|
+
if (mode === "tracked-changes") {
|
|
351
|
+
skipped.push({
|
|
352
|
+
id: item.operation.id,
|
|
353
|
+
reason: "unsupportedBlock"
|
|
354
|
+
});
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
const node = buildSignatureTableNode({
|
|
358
|
+
schema: view.state.schema,
|
|
359
|
+
parties: item.operation.parties
|
|
360
|
+
});
|
|
361
|
+
if (!node) {
|
|
362
|
+
skipped.push({
|
|
363
|
+
id: item.operation.id,
|
|
364
|
+
reason: "unsupportedBlock"
|
|
365
|
+
});
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
tr = tr.insert(item.from, node);
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
case "deleteBlock":
|
|
372
|
+
if (mode === "direct") {
|
|
373
|
+
tr = tr.delete(item.blockFrom, item.blockTo);
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
if (deletionType) {
|
|
377
|
+
const revisionId = revisionSeed++;
|
|
378
|
+
tr = tr.addMark(item.from, item.to, deletionType.create({
|
|
379
|
+
revisionId,
|
|
380
|
+
author,
|
|
381
|
+
date
|
|
382
|
+
}));
|
|
383
|
+
appliedRevisionIds = [revisionId];
|
|
384
|
+
}
|
|
385
|
+
if (commentMark) tr = tr.addMark(item.from, item.to, commentMark);
|
|
386
|
+
break;
|
|
387
|
+
case "commentOnBlock":
|
|
388
|
+
if (commentMark) tr = tr.addMark(item.from, item.to, commentMark);
|
|
389
|
+
break;
|
|
390
|
+
default: break;
|
|
391
|
+
}
|
|
392
|
+
if (tr.steps.length === stepsBefore) {
|
|
393
|
+
skipped.push({
|
|
394
|
+
id: item.operation.id,
|
|
395
|
+
reason: "noopOperation"
|
|
396
|
+
});
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
applied.push({
|
|
400
|
+
id: item.operation.id,
|
|
401
|
+
...item.commentId !== void 0 && { commentId: item.commentId },
|
|
402
|
+
...appliedRevisionIds !== void 0 && appliedRevisionIds[0] !== void 0 && {
|
|
403
|
+
revisionId: appliedRevisionIds[0],
|
|
404
|
+
revisionIds: appliedRevisionIds
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
if (tr.docChanged) view.dispatch(tr);
|
|
409
|
+
return {
|
|
410
|
+
applied,
|
|
411
|
+
skipped
|
|
412
|
+
};
|
|
413
|
+
};
|
|
414
|
+
const applyTextReplacement = ({ tr, item, mode, author, date, revisionIdDelete, revisionIdInsert, commentMark }) => {
|
|
415
|
+
let nextTr = tr;
|
|
416
|
+
const replacement = stripInlineEmphasisMarkers((() => {
|
|
417
|
+
if (item.operation.type === "replaceInBlock") return item.operation.replace;
|
|
418
|
+
if (item.operation.type === "replaceBlock") return item.operation.text;
|
|
419
|
+
return "";
|
|
420
|
+
})());
|
|
421
|
+
if (mode === "direct") {
|
|
422
|
+
if (item.operation.type === "replaceInBlock" && hasInlineEmphasis(item.operation.replace)) {
|
|
423
|
+
const content = buildEmphasisInlineContent(nextTr.doc.type.schema, item.operation.replace, commentMark ? [commentMark] : []);
|
|
424
|
+
return nextTr.replaceWith(item.from, item.to, content);
|
|
425
|
+
}
|
|
426
|
+
nextTr = nextTr.insertText(replacement, item.from, item.to);
|
|
427
|
+
if (commentMark && replacement.length > 0) nextTr = nextTr.addMark(item.from, item.from + replacement.length, commentMark);
|
|
428
|
+
return nextTr;
|
|
429
|
+
}
|
|
430
|
+
const insertionType = nextTr.doc.type.schema.marks["insertion"];
|
|
431
|
+
const deletionType = nextTr.doc.type.schema.marks["deletion"];
|
|
432
|
+
const delAttrs = {
|
|
433
|
+
revisionId: revisionIdDelete,
|
|
434
|
+
author,
|
|
435
|
+
date
|
|
436
|
+
};
|
|
437
|
+
const insAttrs = {
|
|
438
|
+
revisionId: revisionIdInsert,
|
|
439
|
+
author,
|
|
440
|
+
date
|
|
441
|
+
};
|
|
442
|
+
const cleanBlock = item.blockNode.content.size === item.blockNode.textContent.length ? buildCleanBlockText(item.blockNode, item.blockFrom) : null;
|
|
443
|
+
let sourceText = null;
|
|
444
|
+
let sourceCleanStart = 0;
|
|
445
|
+
if (cleanBlock !== null) {
|
|
446
|
+
if (item.operation.type === "replaceInBlock") {
|
|
447
|
+
sourceText = item.operation.find;
|
|
448
|
+
sourceCleanStart = cleanBlock.text.indexOf(item.operation.find);
|
|
449
|
+
if (sourceCleanStart === -1) sourceText = null;
|
|
450
|
+
} else if (item.operation.type === "replaceBlock") {
|
|
451
|
+
sourceText = cleanBlock.text;
|
|
452
|
+
sourceCleanStart = 0;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (sourceText !== null && cleanBlock !== null) {
|
|
456
|
+
const segments = diffWordSegments(sourceText, replacement);
|
|
457
|
+
const offsets = cleanBlock.offsets;
|
|
458
|
+
const offsetAt = (cleanOffset) => offsets[cleanOffset] ?? null;
|
|
459
|
+
const steps = [];
|
|
460
|
+
let cursor = 0;
|
|
461
|
+
let allPositionsResolved = true;
|
|
462
|
+
for (const seg of segments) {
|
|
463
|
+
if (seg.type === "equal") {
|
|
464
|
+
cursor += seg.text.length;
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
if (seg.type === "del") {
|
|
468
|
+
const pmFrom = offsetAt(sourceCleanStart + cursor);
|
|
469
|
+
const pmTo = offsetAt(sourceCleanStart + cursor + seg.text.length);
|
|
470
|
+
if (pmFrom === null || pmTo === null) {
|
|
471
|
+
allPositionsResolved = false;
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
steps.push({
|
|
475
|
+
kind: "del",
|
|
476
|
+
from: pmFrom,
|
|
477
|
+
to: pmTo
|
|
478
|
+
});
|
|
479
|
+
cursor += seg.text.length;
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
const pmAt = offsetAt(sourceCleanStart + cursor);
|
|
483
|
+
if (pmAt === null) {
|
|
484
|
+
allPositionsResolved = false;
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
steps.push({
|
|
488
|
+
kind: "ins",
|
|
489
|
+
at: pmAt,
|
|
490
|
+
text: seg.text
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
if (allPositionsResolved) {
|
|
494
|
+
for (const step of steps.toReversed()) {
|
|
495
|
+
if (step.kind === "del" && deletionType) {
|
|
496
|
+
nextTr = nextTr.addMark(step.from, step.to, deletionType.create(delAttrs));
|
|
497
|
+
if (commentMark) nextTr = nextTr.addMark(step.from, step.to, commentMark);
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
if (step.kind === "ins" && insertionType) {
|
|
501
|
+
nextTr = nextTr.insertText(step.text, step.at, step.at);
|
|
502
|
+
nextTr = nextTr.addMark(step.at, step.at + step.text.length, insertionType.create(insAttrs));
|
|
503
|
+
if (commentMark) nextTr = nextTr.addMark(step.at, step.at + step.text.length, commentMark);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return nextTr;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
if (replacement.length > 0 && insertionType) {
|
|
510
|
+
nextTr = nextTr.insertText(replacement, item.to, item.to);
|
|
511
|
+
nextTr = nextTr.addMark(item.to, item.to + replacement.length, insertionType.create(insAttrs));
|
|
512
|
+
if (commentMark) nextTr = nextTr.addMark(item.to, item.to + replacement.length, commentMark);
|
|
513
|
+
}
|
|
514
|
+
if (item.to > item.from && deletionType) {
|
|
515
|
+
nextTr = nextTr.addMark(item.from, item.to, deletionType.create(delAttrs));
|
|
516
|
+
if (commentMark && replacement.length === 0) nextTr = nextTr.addMark(item.from, item.to, commentMark);
|
|
517
|
+
}
|
|
518
|
+
return nextTr;
|
|
519
|
+
};
|
|
520
|
+
const resolveOperation = ({ snapshot, operation, liveBlocks, liveBlocksByParaId, doc }) => {
|
|
521
|
+
const anchor = snapshot.anchors[operation.blockId];
|
|
522
|
+
if (!anchor) return {
|
|
523
|
+
type: "skip",
|
|
524
|
+
reason: "missingBlock"
|
|
525
|
+
};
|
|
526
|
+
const encodedParaId = getFolioParaIdFromBlockId(operation.blockId);
|
|
527
|
+
let live;
|
|
528
|
+
if (encodedParaId !== null) {
|
|
529
|
+
live = liveBlocksByParaId.get(encodedParaId);
|
|
530
|
+
if (!live) return {
|
|
531
|
+
type: "skip",
|
|
532
|
+
reason: "missingBlock"
|
|
533
|
+
};
|
|
534
|
+
} else {
|
|
535
|
+
const ordinal = ordinalAmongSameHash(snapshot, operation.blockId);
|
|
536
|
+
if (ordinal < 0) return {
|
|
537
|
+
type: "skip",
|
|
538
|
+
reason: "missingBlock"
|
|
539
|
+
};
|
|
540
|
+
live = liveBlocks.get(anchor.textHash)?.[ordinal];
|
|
541
|
+
}
|
|
542
|
+
if (!live || !live.node.isTextblock) return {
|
|
543
|
+
type: "skip",
|
|
544
|
+
reason: "changedBlock"
|
|
545
|
+
};
|
|
546
|
+
const blockNode = live.node;
|
|
547
|
+
const blockFrom = live.from;
|
|
548
|
+
const blockTo = live.to;
|
|
549
|
+
const cleanBlock = buildCleanBlockText(blockNode, blockFrom);
|
|
550
|
+
const currentText = cleanBlock.text;
|
|
551
|
+
if (hashFolioAIBlockText(normalizeFolioAIBlockText(currentText)) !== anchor.textHash) return {
|
|
552
|
+
type: "skip",
|
|
553
|
+
reason: "changedBlock"
|
|
554
|
+
};
|
|
555
|
+
if (operation.type === "insertAfterBlock" || operation.type === "insertBeforeBlock") {
|
|
556
|
+
if (operation.text.length === 0 && operation.pageBreakBefore !== true) return {
|
|
557
|
+
type: "skip",
|
|
558
|
+
reason: "emptyOperation"
|
|
559
|
+
};
|
|
560
|
+
const tableBoundary = findEnclosingTableBoundary(doc, blockFrom);
|
|
561
|
+
const isInsertAfter = operation.type === "insertAfterBlock";
|
|
562
|
+
let insertFrom;
|
|
563
|
+
if (tableBoundary) insertFrom = isInsertAfter ? tableBoundary.after : tableBoundary.before;
|
|
564
|
+
else insertFrom = isInsertAfter ? blockTo : blockFrom;
|
|
565
|
+
return {
|
|
566
|
+
type: "resolved",
|
|
567
|
+
operation: {
|
|
568
|
+
operation,
|
|
569
|
+
from: insertFrom,
|
|
570
|
+
to: insertFrom,
|
|
571
|
+
blockFrom,
|
|
572
|
+
blockTo,
|
|
573
|
+
blockNode,
|
|
574
|
+
insertText: operation.text
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
if (operation.type === "insertSignatureTable") {
|
|
579
|
+
if (operation.parties.length === 0) return {
|
|
580
|
+
type: "skip",
|
|
581
|
+
reason: "emptyOperation"
|
|
582
|
+
};
|
|
583
|
+
const position = operation.position ?? "after";
|
|
584
|
+
const tableBoundary = findEnclosingTableBoundary(doc, blockFrom);
|
|
585
|
+
let insertFrom;
|
|
586
|
+
if (tableBoundary) insertFrom = position === "after" ? tableBoundary.after : tableBoundary.before;
|
|
587
|
+
else insertFrom = position === "after" ? blockTo : blockFrom;
|
|
588
|
+
return {
|
|
589
|
+
type: "resolved",
|
|
590
|
+
operation: {
|
|
591
|
+
operation,
|
|
592
|
+
from: insertFrom,
|
|
593
|
+
to: insertFrom,
|
|
594
|
+
blockFrom,
|
|
595
|
+
blockTo,
|
|
596
|
+
blockNode
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
if (operation.type === "deleteBlock" || operation.type === "replaceBlock") {
|
|
601
|
+
const range = getTextRangeFromCleanBlock(cleanBlock);
|
|
602
|
+
if (!range) return {
|
|
603
|
+
type: "skip",
|
|
604
|
+
reason: "unsupportedBlock"
|
|
605
|
+
};
|
|
606
|
+
if (operation.type === "replaceBlock" && operation.text === currentText) return {
|
|
607
|
+
type: "skip",
|
|
608
|
+
reason: "noopOperation"
|
|
609
|
+
};
|
|
610
|
+
return {
|
|
611
|
+
type: "resolved",
|
|
612
|
+
operation: {
|
|
613
|
+
operation,
|
|
614
|
+
from: range.from,
|
|
615
|
+
to: range.to,
|
|
616
|
+
blockFrom,
|
|
617
|
+
blockTo,
|
|
618
|
+
blockNode
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
if (operation.type === "replaceInBlock" && operation.find === operation.replace) return {
|
|
623
|
+
type: "skip",
|
|
624
|
+
reason: "noopOperation"
|
|
625
|
+
};
|
|
626
|
+
const range = resolveTextInCleanBlock(cleanBlock, getOperationQuote(operation) || currentText);
|
|
627
|
+
if (range.type !== "resolved") return range;
|
|
628
|
+
return {
|
|
629
|
+
type: "resolved",
|
|
630
|
+
operation: {
|
|
631
|
+
operation,
|
|
632
|
+
from: range.from,
|
|
633
|
+
to: range.to,
|
|
634
|
+
blockFrom,
|
|
635
|
+
blockTo,
|
|
636
|
+
blockNode
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
};
|
|
640
|
+
const resolveTextInCleanBlock = (cleanBlock, find) => {
|
|
641
|
+
if (find.length === 0) return {
|
|
642
|
+
type: "skip",
|
|
643
|
+
reason: "emptyOperation"
|
|
644
|
+
};
|
|
645
|
+
const { text, offsets } = cleanBlock;
|
|
646
|
+
const firstIndex = text.indexOf(find);
|
|
647
|
+
if (firstIndex === -1) return {
|
|
648
|
+
type: "skip",
|
|
649
|
+
reason: "missingFind"
|
|
650
|
+
};
|
|
651
|
+
if (text.includes(find, firstIndex + 1)) return {
|
|
652
|
+
type: "skip",
|
|
653
|
+
reason: "ambiguousFind"
|
|
654
|
+
};
|
|
655
|
+
const from = offsets[firstIndex];
|
|
656
|
+
const to = offsets[firstIndex + find.length];
|
|
657
|
+
if (from === void 0 || to === void 0) return {
|
|
658
|
+
type: "skip",
|
|
659
|
+
reason: "unsupportedBlock"
|
|
660
|
+
};
|
|
661
|
+
return {
|
|
662
|
+
type: "resolved",
|
|
663
|
+
from,
|
|
664
|
+
to
|
|
665
|
+
};
|
|
666
|
+
};
|
|
667
|
+
const getTextRangeFromCleanBlock = (cleanBlock) => {
|
|
668
|
+
if (cleanBlock.text.length === 0) return null;
|
|
669
|
+
const from = cleanBlock.offsets[0];
|
|
670
|
+
const to = cleanBlock.offsets[cleanBlock.text.length];
|
|
671
|
+
if (from === void 0 || to === void 0) return null;
|
|
672
|
+
return {
|
|
673
|
+
from,
|
|
674
|
+
to
|
|
675
|
+
};
|
|
676
|
+
};
|
|
677
|
+
const getOperationCommentText = (operation) => operation.comment?.text;
|
|
678
|
+
const getOperationQuote = (operation) => {
|
|
679
|
+
if (operation.type === "replaceInBlock") return operation.find;
|
|
680
|
+
if (operation.type === "commentOnBlock") return operation.quote;
|
|
681
|
+
};
|
|
682
|
+
//#endregion
|
|
683
|
+
export { applyFolioAIEditOperations };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
2
|
+
|
|
3
|
+
//#region src/ai-edits/clean-text.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* "Post-tracked-changes" view of a textblock: the string the user
|
|
6
|
+
* would see if every existing tracked change were accepted.
|
|
7
|
+
* `deletion`-marked text is skipped, `insertion`-marked text is
|
|
8
|
+
* included as plain text, everything else is included as-is.
|
|
9
|
+
*
|
|
10
|
+
* `offsets[i]` is the absolute ProseMirror position to use when you
|
|
11
|
+
* want to anchor at the character at clean-offset `i`. `offsets`
|
|
12
|
+
* has length `text.length + 1` so callers can ask for the position
|
|
13
|
+
* immediately after the last character, which is the right anchor
|
|
14
|
+
* for an insertion at end-of-block.
|
|
15
|
+
*
|
|
16
|
+
* This is the view the AI should reason against (so it doesn't see
|
|
17
|
+
* `"shallmust"` smashed together) and the view the apply engine's
|
|
18
|
+
* find-string lookup should run against (so the same offsets it
|
|
19
|
+
* sent us still resolve to the right PM positions on a doc with
|
|
20
|
+
* pending tracked changes).
|
|
21
|
+
*/
|
|
22
|
+
type CleanBlockText = {
|
|
23
|
+
text: string;
|
|
24
|
+
offsets: number[];
|
|
25
|
+
};
|
|
26
|
+
declare const buildCleanBlockText: (blockNode: Node, blockFrom: number) => CleanBlockText;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { CleanBlockText, buildCleanBlockText };
|