platejs 54.0.0-beta.7 → 54.0.0-beta.9
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/THIRD_PARTY_NOTICES.md +0 -28
- package/dist/EditorStatic-BKBBZZn8.d.ts +771 -0
- package/dist/ai/index.d.ts +2 -2
- package/dist/ai/index.js +5 -2
- package/dist/ai/lib/aiDraftSession.js +984 -0
- package/dist/ai/{react → lib}/aiOutputLanding.internal.js +90 -96
- package/dist/ai/lib/aiPolicy.internal.js +403 -0
- package/dist/ai/lib/editorAgent.js +1696 -0
- package/dist/ai/lib/lockedContext.internal.js +130 -0
- package/dist/ai/lib/lockedContext.js +271 -0
- package/dist/ai/lib/registerEditorTools.js +235 -0
- package/dist/ai/react/AIPlugin.js +246 -0
- package/dist/ai/react/CopilotPlugin.js +327 -178
- package/dist/ai/react/copilotInline.internal.js +358 -0
- package/dist/ai/react/index.d.ts +200 -788
- package/dist/ai/react/index.js +3 -3
- package/dist/ai/react/useEditorAgent.js +193 -0
- package/dist/authored/AuthoredPlugin.js +34 -2
- package/dist/authored/index.d.ts +5 -4
- package/dist/authored/index.js +3 -2
- package/dist/{features/suggestion → authored}/suggestionColorOf.js +4 -4
- package/dist/{index-CLNem74G.d.ts → authored-BQAGqGhS-DN3sw1OP.d.ts} +101 -75
- package/dist/clipboard-format-key-CWuwPPe2-BJGVrNlz.d.ts +1 -0
- package/dist/code-block/codemirror/createCodeMirrorAdapter.js +224 -58
- package/dist/code-block/codemirror/index.d.ts +2 -1
- package/dist/comment-anchor.internal-L2GsNCIh.d.ts +28 -0
- package/dist/compiler/index.d.ts +9 -3
- package/dist/compiler/index.js +3 -1
- package/dist/{core-Cqc_KzpG.d.ts → core-N8rIvQxS.d.ts} +2451 -2213
- package/dist/core.js +4 -8
- package/dist/diff/index.d.ts +3 -30
- package/dist/docs/ai.md +475 -387
- package/dist/docs/api/anchor.md +1 -1
- package/dist/docs/api/core/plate-components.md +12 -3
- package/dist/docs/api/core/plate-editor.md +1 -1
- package/dist/docs/api/core/plate-plugin.md +40 -27
- package/dist/docs/api/core/plate-store.md +14 -13
- package/dist/docs/api/core.md +68 -92
- package/dist/docs/api/document-change.md +39 -28
- package/dist/docs/api/dom.md +66 -102
- package/dist/docs/api/editor-api.md +74 -42
- package/dist/docs/api/editor-transforms.md +17 -39
- package/dist/docs/api/location.md +5 -12
- package/dist/docs/api/plate.md +2 -2
- package/dist/docs/api/react-hooks.md +119 -54
- package/dist/docs/api/selection.md +10 -2
- package/dist/docs/api/utils.md +14 -14
- package/dist/docs/authored-changes.md +38 -33
- package/dist/docs/autoformat.md +4 -1
- package/dist/docs/basic-marks.md +0 -1
- package/dist/docs/block-menu.md +2 -3
- package/dist/docs/block-placeholder.md +2 -3
- package/dist/docs/board.md +28 -24
- package/dist/docs/bold.md +0 -2
- package/dist/docs/clear-formatting.md +4 -4
- package/dist/docs/clipboard.md +25 -18
- package/dist/docs/code-block.md +62 -40
- package/dist/docs/column.md +28 -15
- package/dist/docs/combobox.md +36 -51
- package/dist/docs/comment.md +171 -141
- package/dist/docs/controlled.md +5 -7
- package/dist/docs/copilot.md +183 -148
- package/dist/docs/debugging.md +5 -14
- package/dist/docs/discussion.md +34 -28
- package/dist/docs/dnd.md +7 -6
- package/dist/docs/document-meta.md +27 -28
- package/dist/docs/document-model.md +12 -11
- package/dist/docs/docx.md +102 -111
- package/dist/docs/editor-methods.md +3 -3
- package/dist/docs/editor.md +59 -95
- package/dist/docs/emoji.md +4 -5
- package/dist/docs/equation.md +4 -4
- package/dist/docs/examples/collaboration-example.md +15 -30
- package/dist/docs/examples/export.md +10 -9
- package/dist/docs/examples/version-history.md +7 -6
- package/dist/docs/exit-break.md +32 -59
- package/dist/docs/external-text.md +28 -15
- package/dist/docs/field.md +3 -3
- package/dist/docs/find.md +70 -102
- package/dist/docs/footnote.md +104 -92
- package/dist/docs/format-painter.md +1 -1
- package/dist/docs/history.md +49 -63
- package/dist/docs/html.md +69 -33
- package/dist/docs/indent.md +46 -34
- package/dist/docs/ink.md +46 -31
- package/dist/docs/installation/docs.md +10 -0
- package/dist/docs/installation/node.md +12 -8
- package/dist/docs/installation/plate-ui.md +12 -7
- package/dist/docs/line-height.md +1 -1
- package/dist/docs/link.md +95 -98
- package/dist/docs/list.md +75 -47
- package/dist/docs/llms.txt +14 -11
- package/dist/docs/lock.md +271 -0
- package/dist/docs/markdown.md +124 -209
- package/dist/docs/media.md +31 -31
- package/dist/docs/mention.md +6 -9
- package/dist/docs/multi-select.md +17 -9
- package/dist/docs/pagination.md +144 -127
- package/dist/docs/performance.md +2 -2
- package/dist/docs/plugin-context.md +18 -13
- package/dist/docs/plugin-input-rules.md +84 -125
- package/dist/docs/plugin-methods.md +11 -9
- package/dist/docs/plugin-rules.md +11 -35
- package/dist/docs/plugin-shortcuts.md +1 -1
- package/dist/docs/plugin.md +53 -2
- package/dist/docs/prompt-editor.md +0 -1
- package/dist/docs/roots.md +2 -3
- package/dist/docs/schema.md +12 -3
- package/dist/docs/selection.md +3 -1
- package/dist/docs/serializing.md +34 -10
- package/dist/docs/slash-command.md +4 -4
- package/dist/docs/static.md +30 -10
- package/dist/docs/suggestion.md +51 -71
- package/dist/docs/sync.md +256 -0
- package/dist/docs/table.md +35 -20
- package/dist/docs/text-align.md +4 -4
- package/dist/docs/toolbar.md +26 -5
- package/dist/docs/trailing-block.md +18 -45
- package/dist/docs/underline.md +2 -2
- package/dist/docs/unit-testing.md +1 -1
- package/dist/docs/upload.md +71 -36
- package/dist/docx/export/index.d.ts +152 -56
- package/dist/docx/export/lib/colors.js +268 -0
- package/dist/docx/export/lib/compileAst.js +1825 -0
- package/dist/docx/export/lib/exportDocx.js +57 -113
- package/dist/docx/export/lib/mathOmml.js +233 -0
- package/dist/docx/export/lib/ooxmlBuilder.js +1759 -0
- package/dist/docx/export/lib/outputSafety.js +155 -82
- package/dist/docx/export/lib/reviewProjection.js +31 -202
- package/dist/docx/export/lib/sourcePreservation.js +133 -73
- package/dist/docx/export/lib/wordStyles.js +399 -0
- package/dist/docx/import/index.d.ts +4 -4
- package/dist/docx/import/lib/importDocx.js +1401 -1062
- package/dist/docx/import/lib/opcRelationships.js +77 -0
- package/dist/docx/import/lib/readWordDocument.js +990 -0
- package/dist/docx/import/lib/wordStyles.js +534 -0
- package/dist/docx/internal/diagnostics.js +67 -0
- package/dist/docx/internal/docxPackage.js +20 -44
- package/dist/docx/internal/domParser.js +2 -21
- package/dist/docx/internal/packageParts.js +15 -16
- package/dist/docx/internal/readDocxNumbering.js +35 -38
- package/dist/docx/internal/reviewPart.js +22 -21
- package/dist/docx/internal/sourceEligibility.js +87 -30
- package/dist/docx/internal/wordMath.js +102 -137
- package/dist/docx/internal/xmlTree.js +262 -0
- package/dist/docx/internal/xmlWriter.js +44 -0
- package/dist/docx/paste/index.d.ts +4 -4
- package/dist/docx/paste/lib/WordPastePlugin.js +12 -11
- package/dist/dom/index.d.ts +2 -2
- package/dist/dom/index.js +2 -2
- package/dist/dom/plite-dom.internal.js +2 -2
- package/dist/excalidraw/index.d.ts +6 -4
- package/dist/excalidraw/lib/BaseExcalidrawPlugin.js +19 -7
- package/dist/excalidraw/react/index.d.ts +6 -4
- package/dist/facade.js +3 -3
- package/dist/features/basic-nodes/lib/BaseBlockPlugins.js +32 -12
- package/dist/features/basic-nodes/lib/BaseHeadingPlugins.js +46 -7
- package/dist/features/basic-nodes/lib/BaseMarkPlugins.js +159 -81
- package/dist/features/basic-styles/lib/BaseStylePlugins.js +79 -82
- package/dist/features/board/index.d.ts +2 -2
- package/dist/features/board/index.js +2 -2
- package/dist/features/board/lib/BaseBoardArrowPlugin.js +90 -87
- package/dist/features/board/lib/BaseBoardFramePlugin.js +7 -7
- package/dist/features/board/lib/BaseBoardGeoPlugin.js +3 -2
- package/dist/features/board/lib/BaseBoardImagePlugin.js +9 -6
- package/dist/features/board/lib/BaseBoardNotePlugin.js +3 -2
- package/dist/features/board/lib/BaseBoardPlugin.js +368 -283
- package/dist/features/board/lib/BaseBoardStrokePlugin.js +8 -5
- package/dist/features/board/lib/BaseBoardTextPlugin.js +3 -2
- package/dist/features/board/lib/boardArrow.internal.js +2 -2
- package/dist/features/board/lib/boardCopy.internal.js +42 -36
- package/dist/features/board/lib/boardFrame.internal.js +5 -7
- package/dist/features/board/lib/boardGeometry.internal.js +124 -0
- package/dist/features/board/lib/boardHtml.internal.js +36 -36
- package/dist/features/board/lib/boardMember.internal.js +8 -8
- package/dist/features/board/lib/boardShape.internal.js +10 -124
- package/dist/features/board/lib/boardStyle.internal.js +6 -6
- package/dist/features/board/lib/boardTypes.internal.js +9 -0
- package/dist/features/callout/index.d.ts +3 -3
- package/dist/features/callout/lib/BaseCalloutPlugin.js +43 -2
- package/dist/features/code-block/lib/BaseCodeBlockPlugin.js +208 -181
- package/dist/features/code-block/lib/CodeBlockRules.js +133 -14
- package/dist/features/column/index.d.ts +2 -0
- package/dist/features/column/lib/BaseColumnPlugin.js +693 -0
- package/dist/features/comments/BaseCommentsPlugin.js +1315 -408
- package/dist/features/comments/comment-thread-index.internal.js +5 -4
- package/dist/features/comments/index.d.ts +3 -2
- package/dist/features/date/index.d.ts +3 -3
- package/dist/features/date/lib/BaseDatePlugin.js +72 -31
- package/dist/features/details/index.d.ts +4 -3
- package/dist/features/details/lib/BaseDetailsPlugin.js +226 -122
- package/dist/features/field/index.d.ts +1 -1
- package/dist/features/field/lib/BaseFieldPlugin.js +64 -48
- package/dist/features/field/lib/fieldRules.internal.js +6 -6
- package/dist/features/find/index.d.ts +98 -34
- package/dist/features/find/lib/BaseFindPlugin.js +939 -370
- package/dist/features/footnote/index.d.ts +428 -2
- package/dist/features/footnote/lib/BaseFootnotePlugin.js +437 -160
- package/dist/features/indent/lib/BaseIndentPlugin.js +222 -75
- package/dist/features/indent/lib/indentHtml.internal.js +9 -0
- package/dist/features/indent/lib/indentLevel.internal.js +3 -3
- package/dist/features/ink/index.d.ts +2 -2
- package/dist/features/ink/lib/BaseInkPlugin.js +122 -85
- package/dist/features/ink/lib/inkMatch.internal.js +79 -78
- package/dist/features/ink/lib/inkPlaces.internal.js +167 -536
- package/dist/features/link/lib/BaseLinkPlugin.js +504 -188
- package/dist/features/lint/index.d.ts +5 -5
- package/dist/features/lint/lib/BaseLintPlugin.js +3 -1
- package/dist/features/list/lib/BaseListPlugin.js +100 -691
- package/dist/features/list/lib/listCommands.internal.js +161 -0
- package/dist/features/list/lib/listFamily.internal.js +68 -23
- package/dist/features/list/lib/listHtml.internal.js +185 -69
- package/dist/features/list/lib/listIndex.internal.js +50 -20
- package/dist/features/list/lib/listKeyboard.internal.js +176 -0
- package/dist/features/list/lib/listMarkdown.internal.js +127 -0
- package/dist/features/list/lib/listRules.internal.js +125 -0
- package/dist/features/lock/index.d.ts +2 -0
- package/dist/features/lock/index.js +2 -0
- package/dist/features/lock/lib/BaseLockPlugin.js +626 -0
- package/dist/features/media/index.d.ts +1 -1
- package/dist/features/media/lib/BaseMediaPlugin.js +117 -4
- package/dist/features/media/lib/image/BaseImagePlugin.js +46 -10
- package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +26 -8
- package/dist/features/media/lib/mediaHtml.internal.js +2 -2
- package/dist/features/mention/index.d.ts +4 -11
- package/dist/features/mention/lib/BaseMentionPlugin.js +12 -16
- package/dist/features/table/index.d.ts +2 -2
- package/dist/features/table/lib/BaseTablePlugin.js +711 -410
- package/dist/features/table/lib/internal/authoredProjection.js +172 -0
- package/dist/features/table/lib/internal/axisMove.js +152 -0
- package/dist/features/table/lib/internal/docxBorders.js +39 -0
- package/dist/features/table/lib/internal/grid.js +34 -1
- package/dist/features/table/lib/internal/mutation.js +18 -121
- package/dist/features/table/lib/internal/selection.js +114 -3
- package/dist/features/table/lib/internal/tabularText.js +2 -1
- package/dist/features/table/lib/internal/widths.js +118 -0
- package/dist/features/toc/index.d.ts +1 -1
- package/dist/features/toc/lib/BaseTocPlugin.js +42 -2
- package/dist/features/upload/index.d.ts +2 -2
- package/dist/features/upload/index.js +3 -2
- package/dist/features/upload/lib/BaseUploadPlugin.js +262 -298
- package/dist/features/upload/lib/uploadRules.internal.js +259 -0
- package/dist/history/index.d.ts +2 -3
- package/dist/html/index.d.ts +4 -3
- package/dist/html/server/index.d.ts +6 -2
- package/dist/html/server/index.js +7 -3
- package/dist/html/server/serverCssParser.internal.js +500 -0
- package/dist/html/server/serverCssStyle.internal.js +208 -0
- package/dist/{index-BI0NS7kx.d.ts → htmlConversion-DkPBUAhF.d.ts} +6 -3
- package/dist/{htmlTypes-i_FBCMf2.d.ts → htmlTypes-BtbQ2kEr.d.ts} +24 -14
- package/dist/hyperscript/index.d.ts +1 -1
- package/dist/{index-KteL56rA.d.ts → index-1OVDeYPV.d.ts} +4 -3
- package/dist/{index-Cc2ajXAd.d.ts → index-B32tPEDz.d.ts} +152 -83
- package/dist/index-BG8rVWFU.d.ts +21 -0
- package/dist/{index-B4ZhSQdk.d.ts → index-BTr77Bx4.d.ts} +65 -79
- package/dist/{index-1rcWTB-o.d.ts → index-Bjidr3Bh.d.ts} +89 -38
- package/dist/index-BrH9LjUL.d.ts +1 -0
- package/dist/index-C5UBSjnN.d.ts +3 -0
- package/dist/{index-CrJ9Km8W.d.ts → index-C9NdczaJ.d.ts} +9 -12
- package/dist/{index-1PlYsibA.d.ts → index-CQIZktRx.d.ts} +144 -55
- package/dist/{index-uVbqCpDa.d.ts → index-CXykQDCy.d.ts} +172 -115
- package/dist/{comparison-types-CsmDG5r2-z1s4gX06.d.ts → index-CkM6HC0j-Dl58Hah-.d.ts} +19 -57
- package/dist/{index-By7BkzIN.d.ts → index-CpPTPirx.d.ts} +2 -2
- package/dist/index-DFTcRJUh.d.ts +97 -0
- package/dist/index-DUPlSPvg.d.ts +81 -0
- package/dist/{index-CxG1Atvg.d.ts → index-DayqETUb.d.ts} +243 -241
- package/dist/{index-DNXr_SN-.d.ts → index-DlfamnX-.d.ts} +128 -230
- package/dist/index-DlmWL_1-.d.ts +116 -0
- package/dist/index-Dqd1rrEG-BSmp1a8x.d.ts +316 -0
- package/dist/{index-CTTjpWgb-Fdrn8NP4.d.ts → index-Du3tBg6V-CtvB7eak.d.ts} +3 -3
- package/dist/{index-CmISVYmz.d.ts → index-MQmrgI2L.d.ts} +20 -50
- package/dist/{index-Bv13FX9o.d.ts → index-SKTw56CW.d.ts} +9 -9
- package/dist/{index-DfkFmApH.d.ts → index-drvpTZ3S.d.ts} +743 -1532
- package/dist/index-vP4xFieu.d.ts +184 -0
- package/dist/index-zK527a0f.d.ts +57 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +7 -11
- package/dist/internal/comments/comment-anchor.internal.js +636 -0
- package/dist/internal/plugin/OverridePlugin.js +155 -53
- package/dist/internal/plugin/blockInsertion.js +4 -4
- package/dist/internal/plugin/collectPlateNodeMappings.js +18 -8
- package/dist/internal/plugin/compilePlainTextMappings.js +68 -15
- package/dist/internal/plugin/compilePlateModel.js +56 -17
- package/dist/internal/plugin/compilePlateShortcuts.js +2 -1
- package/dist/internal/plugin/compilePluginInputMaps.js +126 -0
- package/dist/internal/plugin/createPlateModelPublication.js +261 -0
- package/dist/internal/plugin/createPlateRuntimePlugins.js +263 -0
- package/dist/internal/plugin/getPlateDecorationSources.js +2 -1
- package/dist/internal/plugin/indentShift.js +44 -0
- package/dist/internal/plugin/markdownParagraph.js +23 -1
- package/dist/internal/plugin/plateRuntime.js +9 -3
- package/dist/internal/plugin/pluginDescriptorSnapshot.js +178 -0
- package/dist/internal/plugin/pluginFormatOperation.js +8 -3
- package/dist/internal/plugin/pluginStore.js +4 -7
- package/dist/internal/plugin/resolvePlugin.js +32 -14
- package/dist/internal/plugin/resolvePluginGraph.js +354 -0
- package/dist/internal/plugin/resolvePlugins.js +19 -1135
- package/dist/internal/plugin/staticReuseKey.internal.js +15 -0
- package/dist/internal/plugin/uploadDrafts.js +6 -1
- package/dist/internal/utils/mergePlugins.js +6 -5
- package/dist/internal/utils/trustedContentSlice.js +1 -1
- package/dist/internal/utils/urlPolicy.js +19 -1
- package/dist/lib/editor/editorUser.internal.js +13 -5
- package/dist/lib/editor/withPlite.js +55 -44
- package/dist/lib/libs/zustand.js +31 -7
- package/dist/lib/plugin/basePluginFactory.internal.js +7 -0
- package/dist/lib/plugin/createPluginContext.internal.js +6 -24
- package/dist/lib/plugin/defineBasePlugin.internal.js +69 -9
- package/dist/lib/plugin/definePlugin.js +1 -1
- package/dist/lib/plugin/pluginFactoryRuntime.internal.js +40 -0
- package/dist/lib/plugins/affinity/AffinityPlugin.js +9 -8
- package/dist/lib/plugins/debug/DebugPlugin.js +1 -4
- package/dist/lib/plugins/dom/DOMPlugin.js +20 -7
- package/dist/lib/plugins/dom/clipboardFormatKey.internal.js +9 -0
- package/dist/lib/plugins/dom/isPlainTextPasteTarget.internal.js +13 -0
- package/dist/lib/plugins/getCorePlugins.internal.js +1 -3
- package/dist/lib/plugins/html/HtmlPlugin.js +30 -1747
- package/dist/lib/plugins/html/htmlAst.js +10 -5
- package/dist/lib/plugins/html/htmlConversion.js +4 -0
- package/dist/lib/plugins/html/htmlDecode.internal.js +891 -0
- package/dist/lib/plugins/html/htmlDom.js +1 -10
- package/dist/lib/plugins/html/htmlMatcher.internal.js +24 -1
- package/dist/lib/plugins/html/htmlRules.internal.js +490 -0
- package/dist/lib/plugins/html/htmlSerialize.internal.js +462 -0
- package/dist/lib/plugins/html/htmlWhitespace.internal.js +137 -0
- package/dist/lib/plugins/input-rules/InputRulesPlugin.js +114 -30
- package/dist/lib/plugins/input-rules/createInputRules.js +64 -68
- package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +111 -9
- package/dist/lib/plugins/input-rules/inputRuleVeto.js +2 -2
- package/dist/lib/plugins/input-rules/inputRules.internal.js +20 -0
- package/dist/lib/plugins/input-rules/markInputRule.internal.js +64 -2
- package/dist/lib/plugins/paragraph/BaseParagraphPlugin.js +21 -8
- package/dist/lib/utils/pluginNodeClass.js +1 -5
- package/dist/markdown/index.d.ts +2 -2
- package/dist/markdown/index.js +1 -2
- package/dist/markdown/lib/MarkdownPlugin.js +40 -49
- package/dist/markdown/lib/deserializer/convertNodesDeserialize.js +30 -6
- package/dist/markdown/lib/deserializer/mdastToSlate.js +2 -4
- package/dist/markdown/lib/internal/markdownBareLinks.js +265 -0
- package/dist/markdown/lib/internal/markdownBreaks.js +191 -0
- package/dist/markdown/lib/internal/markdownDiagnostics.js +2 -2
- package/dist/markdown/lib/internal/markdownDocument.js +13 -32
- package/dist/markdown/lib/internal/markdownIntrinsics.js +68 -228
- package/dist/markdown/lib/internal/markdownLine.js +134 -118
- package/dist/markdown/lib/internal/markdownMappings.js +178 -88
- package/dist/markdown/lib/internal/markdownParse.js +601 -0
- package/dist/markdown/lib/internal/markdownReferences.js +9 -3
- package/dist/markdown/lib/internal/markdownRuntime.js +353 -0
- package/dist/markdown/lib/internal/markdownSafety.js +101 -1
- package/dist/markdown/lib/internal/markdownSerialize.js +197 -0
- package/dist/markdown/lib/internal/markdownStream.js +1239 -0
- package/dist/markdown/lib/internal/markdownTags.js +52 -63
- package/dist/markdown/lib/internal/markdownTailHeal.js +813 -0
- package/dist/markdown/lib/serializer/convertNodesSerialize.js +18 -5
- package/dist/markdown/lib/serializer/convertPhrasingSerialize.js +134 -53
- package/dist/markdown/lib/serializer/listToMdastTree.js +23 -4
- package/dist/markdown/lib/serializer/reportOmittedProperties.js +1 -0
- package/dist/markdown/lib/utils/remarkPlugins.js +44 -23
- package/dist/math/index.d.ts +11 -11
- package/dist/math/lib/BaseEquationPlugin.js +99 -20
- package/dist/math/react/index.d.ts +4 -4
- package/dist/migrations/documentMigrationAuthored.internal.js +2 -1
- package/dist/migrations/documentMigrationSelection.internal.js +138 -2
- package/dist/migrations/documentMigrationTarget.internal.js +10 -2
- package/dist/migrations/documentMigrations.js +113 -140
- package/dist/migrations/index.d.ts +30 -44
- package/dist/migrations/index.js +1 -2
- package/dist/migrations/migratePlateV54.js +50 -45
- package/dist/migrations/migratePlateV54Ast.internal.js +180 -119
- package/dist/migrations/migratePlateV54BuiltIns.internal.js +2 -2
- package/dist/migrations/migratePlateV54CodeBlocks.internal.js +68 -34
- package/dist/migrations/migratePlateV54Inputs.internal.js +39 -32
- package/dist/migrations/migratePlateV54ListIdentity.internal.js +220 -0
- package/dist/migrations/migratePlateV54Profile.internal.js +52 -22
- package/dist/migrations/migratePlateV54RetiredMarks.internal.js +2 -2
- package/dist/migrations/migratePlateV54Stage.internal.js +127 -0
- package/dist/migrations/migratePlateV54Toggle.internal.js +66 -0
- package/dist/migrations/migratePlateV54Urls.internal.js +86 -57
- package/dist/pagination/index.d.ts +2 -167
- package/dist/pagination/index.js +2 -2
- package/dist/pagination/react/PaginationPlugin.js +278 -0
- package/dist/pagination/react/index.d.ts +94 -34
- package/dist/pagination/react/index.js +3 -5
- package/dist/plain-text.js +9 -12
- package/dist/react/authored/AuthoredReactPlugin.js +126 -0
- package/dist/react/authored/index.d.ts +34 -0
- package/dist/react/authored/index.js +3 -0
- package/dist/react/authored/useAuthored.js +82 -0
- package/dist/react/components/EditorContentView.internal.js +64 -45
- package/dist/react/components/EditorProvider.js +25 -24
- package/dist/react/components/EditorRefEffect.internal.js +56 -0
- package/dist/react/components/EditorRefEffect.js +12 -56
- package/dist/react/components/NodeSelection.js +435 -486
- package/dist/react/components/Plate.js +215 -168
- package/dist/react/components/PlateContainer.js +96 -43
- package/dist/react/components/PlateView.js +2 -2
- package/dist/{static/internal/getPlainText.js → react/components/getPlainText.internal.js} +1 -4
- package/dist/react/components/plate-nodes.js +49 -42
- package/dist/{static/internal/writeStaticSelectionClipboardData.js → react/components/writeStaticSelectionClipboardData.internal.js} +4 -5
- package/dist/react/core.js +7 -11
- package/dist/react/editor/useCreateEditor.js +19 -17
- package/dist/react/editor/withPlate.js +10 -13
- package/dist/react/features/basic-styles/BasicStylePlugins.js +2 -3
- package/dist/react/features/board/BoardPlugin.js +1 -1
- package/dist/react/features/board/BoardShape.js +51 -26
- package/dist/react/features/board/BoardSurface.js +1 -1
- package/dist/react/features/board/boardCamera.internal.js +295 -0
- package/dist/react/features/board/boardClipboard.internal.js +20 -20
- package/dist/react/features/board/boardConnect.internal.js +2 -10
- package/dist/react/features/board/boardExport.internal.js +5 -4
- package/dist/react/features/board/boardGesture.internal.js +44 -38
- package/dist/react/features/board/boardIndex.internal.js +1 -1
- package/dist/react/features/board/boardKeys.internal.js +68 -43
- package/dist/react/features/board/boardLanding.internal.js +147 -0
- package/dist/react/features/board/boardPick.internal.js +2 -2
- package/dist/react/features/board/boardPicking.internal.js +0 -17
- package/dist/react/features/board/boardPreview.internal.js +16 -2
- package/dist/react/features/board/boardResize.internal.js +17 -32
- package/dist/react/features/board/boardStyleView.internal.js +123 -0
- package/dist/react/features/board/boardTextFit.internal.js +311 -0
- package/dist/react/features/board/boardView.internal.js +333 -909
- package/dist/react/features/board/boardVoice.internal.js +19 -7
- package/dist/react/features/board/boardWindow.internal.js +138 -0
- package/dist/react/features/board/index.d.ts +97 -89
- package/dist/react/features/callout/index.d.ts +3 -3
- package/dist/react/features/{layout → column}/ColumnPlugin.js +4 -3
- package/dist/react/features/{layout → column}/index.d.ts +61 -44
- package/dist/react/features/combobox/combobox.internal.js +106 -0
- package/dist/react/features/combobox/comboboxOwner.internal.js +28 -26
- package/dist/react/features/combobox/index.d.ts +47 -16
- package/dist/react/features/combobox/useCombobox.js +50 -13
- package/dist/react/features/comments/CommentsPlugin.js +3 -3
- package/dist/react/features/comments/index.d.ts +142 -75
- package/dist/react/features/comments/index.js +2 -1
- package/dist/react/features/comments/useCommentThreadIndex.js +288 -0
- package/dist/react/features/date/index.d.ts +4 -4
- package/dist/react/features/details/index.d.ts +5 -5
- package/dist/react/features/field/index.d.ts +6 -5
- package/dist/react/features/footnote/FootnotePlugin.js +13 -8
- package/dist/react/features/footnote/index.d.ts +952 -105
- package/dist/react/features/format-painter/index.d.ts +6 -6
- package/dist/react/features/ink/InkContent.js +28 -100
- package/dist/react/features/ink/InkPlugin.js +12 -23
- package/dist/react/features/ink/index.d.ts +53 -106
- package/dist/react/features/ink/index.js +1 -2
- package/dist/react/features/ink/inkCapture.internal.js +107 -65
- package/dist/react/features/ink/inkImages.internal.js +20 -5
- package/dist/react/features/ink/inkMeasure.internal.js +35 -22
- package/dist/react/features/ink/inkPlacement.internal.js +78 -203
- package/dist/react/features/ink/inkWatch.internal.js +1 -32
- package/dist/react/features/list/ListPlugin.js +68 -36
- package/dist/react/features/lock/LockPlugin.js +105 -0
- package/dist/react/features/lock/index.d.ts +58 -0
- package/dist/react/features/lock/index.js +2 -0
- package/dist/react/features/media/index.d.ts +10 -10
- package/dist/react/features/mention/index.d.ts +4 -11
- package/dist/react/features/table/TablePlugin.js +215 -61
- package/dist/react/features/table/index.d.ts +158 -59
- package/dist/react/features/table/index.js +2 -1
- package/dist/react/features/table/measureTableColumnWidths.internal.js +44 -0
- package/dist/react/features/table/useTableControls.js +897 -0
- package/dist/react/features/table/useTableResize.js +33 -16
- package/dist/react/features/toc/index.d.ts +8 -11
- package/dist/react/features/upload/UploadPlugin.js +12 -3
- package/dist/react/features/upload/index.d.ts +36 -97
- package/dist/react/index.d.ts +7 -5
- package/dist/react/index.js +11 -15
- package/dist/react/internal/plate-context.js +118 -68
- package/dist/react/internal/useDeepCompareMemo.js +36 -7
- package/dist/react/internal/usePlateModelRevision.js +12 -7
- package/dist/react/plite-react.js +2 -2
- package/dist/react/plugin/pluginFactory.internal.js +1 -37
- package/dist/react/plugin/toReactPlugin.js +15 -4
- package/dist/react/plugins/navigation-feedback/NavigationFeedbackPlugin.js +2 -2
- package/dist/react/stores/element/useElement.js +2 -2
- package/dist/react/stores/element/useElementSelector.js +4 -2
- package/dist/react/stores/element/useElementStore.js +96 -86
- package/dist/react/stores/element/useElementStoreSelector.internal.js +80 -24
- package/dist/react/stores/element/usePath.js +32 -32
- package/dist/react/stores/plate/pluginStoreSelector.internal.js +44 -0
- package/dist/react/stores/plate/useEditor.js +62 -89
- package/dist/react/stores/plate/useEditorSelector.js +17 -204
- package/dist/react/stores/plate/usePluginStore.js +36 -43
- package/dist/react/stores/plate/useViewStore.js +38 -23
- package/dist/react/utils/BlockPlaceholderPlugin.js +13 -4
- package/dist/react/utils/pipeHandler.internal.js +20 -7
- package/dist/react/utils/pipeRenderElement.internal.js +32 -30
- package/dist/react/utils/pipeRenderLeaf.internal.js +1 -2
- package/dist/react/utils/pipeRenderText.internal.js +1 -1
- package/dist/react/utils/useSelectionFragment.js +8 -2
- package/dist/react/virtualized.d.ts +6 -5
- package/dist/refusal-CBecclcb-BJGVrNlz.d.ts +1 -0
- package/dist/registerEditorTools-dPLJZ0PP.d.ts +386 -0
- package/dist/root.js +7 -11
- package/dist/skills/plate/SKILL.md +43 -0
- package/dist/{source-Dcgqj5Mf.d.ts → source-BnYE-ryK.d.ts} +14 -14
- package/dist/static/components/{PlateStatic.js → EditorStatic.js} +86 -31
- package/dist/static/components/plite-nodes.js +32 -12
- package/dist/static/index.d.ts +24 -20
- package/dist/static/index.js +1 -1
- package/dist/static/internal/loadStaticRenderer.js +4 -0
- package/dist/static/internal/staticDocumentView.js +8 -5
- package/dist/static/internal/staticPendingMedia.internal.js +136 -0
- package/dist/static/internal/staticPresentation.js +12 -12
- package/dist/static/pipeRenderElementStatic.internal.js +2 -10
- package/dist/static/pluginRenderElementStatic.internal.js +28 -5
- package/dist/static/pluginRenderLeafStatic.internal.js +4 -3
- package/dist/static/pluginRenderTextStatic.internal.js +3 -1
- package/dist/static/renderStaticHtml.js +31 -2
- package/dist/static/utils/getRenderNodeStaticProps.internal.js +8 -3
- package/dist/sync/SyncPlugin.js +16 -0
- package/dist/sync/cloudflare/index.d.ts +56 -0
- package/dist/sync/cloudflare/index.js +2 -0
- package/dist/sync/index.d.ts +3 -0
- package/dist/sync/index.js +3 -0
- package/dist/sync/react/SyncReactPlugin.js +20 -0
- package/dist/sync/react/hooks.js +64 -0
- package/dist/{yjs → sync}/react/index.d.ts +74 -68
- package/dist/sync/react/index.js +4 -0
- package/dist/sync/server/index.d.ts +3 -0
- package/dist/sync/server/index.js +2 -0
- package/dist/tabbable/index.d.ts +1 -1
- package/dist/tabbable/react/TabbableEffects.internal.js +5 -5
- package/dist/tabbable/react/index.d.ts +3 -3
- package/dist/testing/index.d.ts +7 -6
- package/dist/transport-CRrArpJZ-Bm6uVAsa.d.ts +115 -0
- package/dist/{tx-only-1FM45FSj-D40jacZv.d.ts → tx-only-DXWFNuXJ-DuOaZk8U.d.ts} +2818 -2677
- package/dist/utils/plate-keys.js +2 -8
- package/dist/utils/plugins/TrailingBlockPlugin.js +10 -7
- package/dist/utils/plugins/resolveTrailingBlockType.internal.js +8 -0
- package/package.json +61 -115
- package/dist/AIChatRequestContext-DVGOeWhQ.d.ts +0 -34
- package/dist/BaseSuggestionPlugin-BRFMMyEo.d.ts +0 -91
- package/dist/PlateStatic-DIwBAVqF.d.ts +0 -19
- package/dist/ai/lib/AIChatRequestContext.js +0 -16
- package/dist/ai/lib/findQuotedSpan.internal.js +0 -63
- package/dist/ai/react/AIChatPlugin.js +0 -1244
- package/dist/ai/react/useAIChat.js +0 -332
- package/dist/combobox-CfCJYKT0.d.ts +0 -22
- package/dist/docs/yjs.md +0 -256
- package/dist/docx/export/lib/comments.js +0 -311
- package/dist/docx/export/lib/docxStaticComponents.js +0 -381
- package/dist/docx/export/lib/exportHtmlToDocx.internal.js +0 -70
- package/dist/docx/export/lib/generatedParts.js +0 -51
- package/dist/docx/export/lib/hostIndex.js +0 -92
- package/dist/docx/export/lib/html-to-docx.internal.js +0 -40
- package/dist/docx/export/lib/internal/constants.js +0 -106
- package/dist/docx/export/lib/internal/docx-document.js +0 -652
- package/dist/docx/export/lib/internal/escape-xml.js +0 -4
- package/dist/docx/export/lib/internal/html-to-docx.js +0 -148
- package/dist/docx/export/lib/internal/list-item.js +0 -85
- package/dist/docx/export/lib/internal/list.js +0 -43
- package/dist/docx/export/lib/internal/math.js +0 -187
- package/dist/docx/export/lib/internal/namespaces.js +0 -40
- package/dist/docx/export/lib/internal/render-document-file.js +0 -403
- package/dist/docx/export/lib/internal/schemas/content-types.js +0 -25
- package/dist/docx/export/lib/internal/schemas/core.js +0 -26
- package/dist/docx/export/lib/internal/schemas/document-rels.js +0 -15
- package/dist/docx/export/lib/internal/schemas/document.template.js +0 -36
- package/dist/docx/export/lib/internal/schemas/font-table.js +0 -55
- package/dist/docx/export/lib/internal/schemas/generic-rels.js +0 -9
- package/dist/docx/export/lib/internal/schemas/numbering.js +0 -18
- package/dist/docx/export/lib/internal/schemas/rels.js +0 -12
- package/dist/docx/export/lib/internal/schemas/settings.js +0 -17
- package/dist/docx/export/lib/internal/schemas/styles.js +0 -142
- package/dist/docx/export/lib/internal/schemas/theme.js +0 -198
- package/dist/docx/export/lib/internal/schemas/web-settings.js +0 -10
- package/dist/docx/export/lib/internal/unit-conversion.js +0 -24
- package/dist/docx/export/lib/internal/vnode.js +0 -4
- package/dist/docx/export/lib/internal/word-styles.js +0 -123
- package/dist/docx/export/lib/internal/xml-builder.js +0 -1803
- package/dist/docx/export/lib/reviewPart.js +0 -234
- package/dist/docx/import/lib/wordFormatting.js +0 -608
- package/dist/features/combobox/index.d.ts +0 -3
- package/dist/features/combobox/index.js +0 -2
- package/dist/features/combobox/lib/combobox.internal.js +0 -111
- package/dist/features/combobox/lib/filterWords.js +0 -23
- package/dist/features/ink/lib/inkGone.internal.js +0 -290
- package/dist/features/layout/index.d.ts +0 -2
- package/dist/features/layout/lib/BaseColumnPlugin.js +0 -249
- package/dist/features/suggestion/BaseSuggestionPlugin.js +0 -31
- package/dist/features/suggestion/index.d.ts +0 -10
- package/dist/features/suggestion/index.js +0 -3
- package/dist/features/upload/lib/mimeTypes.internal.js +0 -3982
- package/dist/index-BWCC4DCP.d.ts +0 -156
- package/dist/index-CJGkjkH6.d.ts +0 -8
- package/dist/index-CS4G_W_R.d.ts +0 -184
- package/dist/index-CVAHIQ3p.d.ts +0 -29
- package/dist/index-OMa7dlcS.d.ts +0 -161
- package/dist/lib/plugins/element-state/ElementStatePlugin.js +0 -14
- package/dist/lib/utils/hotkeys.js +0 -113
- package/dist/markdown/lib/RawHtmlPlugin.js +0 -26
- package/dist/markdown/lib/internal/markdownConversion.js +0 -1358
- package/dist/markdown/lib/internal/markdownOpenTail.js +0 -381
- package/dist/markdown/lib/internal/markdownRawHtml.js +0 -353
- package/dist/markdown/lib/internal/markdownSegments.js +0 -143
- package/dist/migrations/migrateListIdentity.js +0 -93
- package/dist/pagination/react/PagedEditorContent.js +0 -77
- package/dist/react/features/ink/InkCopyView.js +0 -214
- package/dist/react/features/suggestion/SuggestionPlugin.js +0 -24
- package/dist/react/features/suggestion/index.d.ts +0 -45
- package/dist/react/features/suggestion/index.js +0 -3
- package/dist/react/features/suggestion/suggestion-view.internal.js +0 -114
- package/dist/react/features/suggestion/useSuggestion.js +0 -138
- package/dist/static/internal/renderStaticHtmlWithOverrides.js +0 -33
- package/dist/utils/plugins/ExitBreakPlugin.js +0 -26
- package/dist/yjs/index.d.ts +0 -2
- package/dist/yjs/index.js +0 -1
- package/dist/yjs/react/YjsPlugin.js +0 -60
- package/dist/yjs/react/index.js +0 -3
- /package/dist/features/{layout → column}/index.js +0 -0
- /package/dist/react/features/{layout → column}/index.js +0 -0
|
@@ -0,0 +1,1825 @@
|
|
|
1
|
+
import { MAIN_ROOT_KEY, getReaderRange, projectEditorView, readNamedRootChildren, withDocumentViewRead } from "../../../facade.js";
|
|
2
|
+
import { getPlateRuntimeOwner } from "../../../internal/plugin/plateRuntime.js";
|
|
3
|
+
import { getCompiledPlateModel, getPlateRuntime } from "../../../internal/plugin/compilePlateModel.js";
|
|
4
|
+
import { createPluginFormatModelView, createPluginFormatOperationContext } from "../../../internal/plugin/pluginFormatOperation.js";
|
|
5
|
+
import { getPlateNodeMappingContributions } from "../../../internal/plugin/collectPlateNodeMappings.js";
|
|
6
|
+
import { ElementApi, RangeApi } from "../../../core.js";
|
|
7
|
+
import { BaseListPlugin } from "../../../features/list/lib/BaseListPlugin.js";
|
|
8
|
+
import { getPlateDecorationSources } from "../../../internal/plugin/getPlateDecorationSources.js";
|
|
9
|
+
import { throwIfDocxAborted } from "../../internal/abort.js";
|
|
10
|
+
import { docxLossyContent, docxPropertyDropped, docxResourceOmitted, docxUnsupportedContent } from "../../internal/diagnostics.js";
|
|
11
|
+
import { renderLatexToOmml } from "./mathOmml.js";
|
|
12
|
+
import { resolveDocxImage, resolveDocxLinkUrl } from "./outputSafety.js";
|
|
13
|
+
import { reviewTargetKey } from "./reviewProjection.js";
|
|
14
|
+
//#region src/docx/export/lib/compileAst.ts
|
|
15
|
+
const FRAGMENT_PAYLOADS = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
const createFragment = (payload) => {
|
|
17
|
+
const handle = Object.freeze({});
|
|
18
|
+
FRAGMENT_PAYLOADS.set(handle, payload);
|
|
19
|
+
return handle;
|
|
20
|
+
};
|
|
21
|
+
const readFragment = (value) => typeof value === "object" && value !== null ? FRAGMENT_PAYLOADS.get(value) : void 0;
|
|
22
|
+
const ELEMENT_DROPPED_FIELDS = /* @__PURE__ */ new Set(["dropped", "text"]);
|
|
23
|
+
const ELEMENT_ENCODE_FIELDS = /* @__PURE__ */ new Set([
|
|
24
|
+
"decode",
|
|
25
|
+
"encode",
|
|
26
|
+
"node"
|
|
27
|
+
]);
|
|
28
|
+
const MARK_DROPPED_FIELDS = /* @__PURE__ */ new Set(["dropped"]);
|
|
29
|
+
const MARK_ENCODE_FIELDS = /* @__PURE__ */ new Set([
|
|
30
|
+
"decode",
|
|
31
|
+
"encode",
|
|
32
|
+
"mark"
|
|
33
|
+
]);
|
|
34
|
+
const PROPERTY_DROPPED_FIELDS = /* @__PURE__ */ new Set(["dropped", "property"]);
|
|
35
|
+
const PROPERTY_ENCODE_FIELDS = /* @__PURE__ */ new Set([
|
|
36
|
+
"decode",
|
|
37
|
+
"encode",
|
|
38
|
+
"property"
|
|
39
|
+
]);
|
|
40
|
+
const assertAllowedFields = (owner, kind, declaration, allowed) => {
|
|
41
|
+
for (const field of Object.keys(declaration)) if (!allowed.has(field)) throw new Error(`DOCX node mapping "${owner}" has unknown ${kind} field "${field}".`);
|
|
42
|
+
};
|
|
43
|
+
const DOCX_FORMATS_CACHE = /* @__PURE__ */ new WeakMap();
|
|
44
|
+
const collectDocxFormats = (editor) => {
|
|
45
|
+
const runtimeOwner = getPlateRuntimeOwner(editor);
|
|
46
|
+
const model = getCompiledPlateModel(runtimeOwner);
|
|
47
|
+
const cached = DOCX_FORMATS_CACHE.get(model.revision);
|
|
48
|
+
if (cached) return cached;
|
|
49
|
+
const elementEncoders = /* @__PURE__ */ new Map();
|
|
50
|
+
const elementTextFormats = /* @__PURE__ */ new Map();
|
|
51
|
+
const markEncoders = /* @__PURE__ */ new Map();
|
|
52
|
+
const markDropped = /* @__PURE__ */ new Map();
|
|
53
|
+
const propertyEncoders = /* @__PURE__ */ new Map();
|
|
54
|
+
const propertyDropped = [];
|
|
55
|
+
const seenElementTargets = /* @__PURE__ */ new Map();
|
|
56
|
+
const seenMarkTargets = /* @__PURE__ */ new Map();
|
|
57
|
+
const seenPropertyTargets = /* @__PURE__ */ new Map();
|
|
58
|
+
for (const { declaration, ownedPropertyKeys, owner, schema, targetKey, targetKind, targetPlugin, targetType } of getPlateNodeMappingContributions(runtimeOwner, "docx")) {
|
|
59
|
+
const hasEncode = declaration.encode !== void 0;
|
|
60
|
+
const hasDecode = declaration.decode !== void 0;
|
|
61
|
+
const hasDropped = declaration.dropped !== void 0;
|
|
62
|
+
if (hasEncode && hasDropped) throw new Error(`DOCX node mapping "${owner}" cannot define both encode and dropped.`);
|
|
63
|
+
if (!hasEncode && !hasDropped && !hasDecode) throw new Error(`DOCX node mapping "${owner}" must define encode, decode, or dropped.`);
|
|
64
|
+
if (hasEncode && typeof declaration.encode !== "function") throw new Error(`DOCX node mapping "${owner}" encode must be a function.`);
|
|
65
|
+
if (hasDecode && typeof declaration.decode !== "function") throw new Error(`DOCX node mapping "${owner}" decode must be a function.`);
|
|
66
|
+
if (hasDropped && typeof declaration.dropped !== "string") throw new Error(`DOCX node mapping "${owner}" must define a dropped warning message.`);
|
|
67
|
+
if (!hasEncode && !hasDropped) continue;
|
|
68
|
+
if (targetType !== null) {
|
|
69
|
+
const prior = seenElementTargets.get(targetType);
|
|
70
|
+
if (prior && prior !== owner) throw new Error(`DOCX node mappings "${prior}" and "${owner}" both target element "${targetPlugin}".`);
|
|
71
|
+
seenElementTargets.set(targetType, owner);
|
|
72
|
+
elementEncoders.delete(targetType);
|
|
73
|
+
elementTextFormats.delete(targetType);
|
|
74
|
+
if (hasEncode) {
|
|
75
|
+
assertAllowedFields(owner, "element", declaration, ELEMENT_ENCODE_FIELDS);
|
|
76
|
+
elementTextFormats.delete(targetType);
|
|
77
|
+
elementEncoders.set(targetType, {
|
|
78
|
+
encode: declaration.encode,
|
|
79
|
+
owner,
|
|
80
|
+
plugin: targetPlugin,
|
|
81
|
+
schema
|
|
82
|
+
});
|
|
83
|
+
} else {
|
|
84
|
+
assertAllowedFields(owner, "element", declaration, ELEMENT_DROPPED_FIELDS);
|
|
85
|
+
if (typeof declaration.text !== "function") throw new Error(`DOCX node mapping "${owner}" must define dropped and text for an element.`);
|
|
86
|
+
elementEncoders.delete(targetType);
|
|
87
|
+
elementTextFormats.set(targetType, {
|
|
88
|
+
dropped: declaration.dropped,
|
|
89
|
+
plugin: targetPlugin,
|
|
90
|
+
text: declaration.text,
|
|
91
|
+
type: targetType
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const hasTextProperty = targetKind === "mark" || Object.values(schema.properties ?? {}).some((handle) => handle?.placement === "text");
|
|
97
|
+
const isElementPropertyMapping = ownedPropertyKeys.length > 0 && (!hasTextProperty || declaration.property !== void 0);
|
|
98
|
+
if (!isElementPropertyMapping && hasTextProperty && targetKey) {
|
|
99
|
+
const prior = seenMarkTargets.get(targetPlugin);
|
|
100
|
+
if (prior && prior !== owner) throw new Error(`DOCX node mappings "${prior}" and "${owner}" both target mark "${targetPlugin}".`);
|
|
101
|
+
seenMarkTargets.set(targetPlugin, owner);
|
|
102
|
+
markEncoders.delete(targetKey);
|
|
103
|
+
markDropped.delete(targetKey);
|
|
104
|
+
if (hasEncode) {
|
|
105
|
+
assertAllowedFields(owner, "mark", declaration, MARK_ENCODE_FIELDS);
|
|
106
|
+
markDropped.delete(targetKey);
|
|
107
|
+
markEncoders.set(targetKey, {
|
|
108
|
+
encode: declaration.encode,
|
|
109
|
+
key: targetKey,
|
|
110
|
+
owner,
|
|
111
|
+
plugin: targetPlugin,
|
|
112
|
+
schema
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
assertAllowedFields(owner, "mark", declaration, MARK_DROPPED_FIELDS);
|
|
116
|
+
markEncoders.delete(targetKey);
|
|
117
|
+
markDropped.set(targetKey, {
|
|
118
|
+
dropped: declaration.dropped,
|
|
119
|
+
key: targetKey,
|
|
120
|
+
plugin: targetPlugin
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (!isElementPropertyMapping) throw new Error(`DOCX node mapping "${owner}" must target an element type, text mark, or element property.`);
|
|
126
|
+
if (declaration.property !== void 0 && typeof declaration.property !== "string") throw new Error(`DOCX node mapping "${owner}" property must be a string.`);
|
|
127
|
+
const property = typeof declaration.property === "string" ? declaration.property : targetKey;
|
|
128
|
+
if (!property || !ownedPropertyKeys.includes(property)) throw new Error(`DOCX node mapping "${owner}" must name an element property owned by "${targetPlugin}".`);
|
|
129
|
+
const propertyKey = `${targetPlugin}:${property}`;
|
|
130
|
+
const prior = seenPropertyTargets.get(propertyKey);
|
|
131
|
+
if (prior && prior !== owner) throw new Error(`DOCX node mappings "${prior}" and "${owner}" both target property "${property}" of "${targetPlugin}".`);
|
|
132
|
+
seenPropertyTargets.set(propertyKey, owner);
|
|
133
|
+
if (hasEncode) {
|
|
134
|
+
assertAllowedFields(owner, "property", declaration, PROPERTY_ENCODE_FIELDS);
|
|
135
|
+
const droppedIndex = propertyDropped.findIndex((entry) => entry.plugin === targetPlugin && entry.property === property);
|
|
136
|
+
if (droppedIndex !== -1) propertyDropped.splice(droppedIndex, 1);
|
|
137
|
+
const list = propertyEncoders.get(property) ?? [];
|
|
138
|
+
const existingIndex = list.findIndex((entry) => entry.plugin === targetPlugin);
|
|
139
|
+
const nextEntry = {
|
|
140
|
+
encode: declaration.encode,
|
|
141
|
+
owner,
|
|
142
|
+
plugin: targetPlugin,
|
|
143
|
+
property,
|
|
144
|
+
schema
|
|
145
|
+
};
|
|
146
|
+
if (existingIndex === -1) list.push(nextEntry);
|
|
147
|
+
else list[existingIndex] = nextEntry;
|
|
148
|
+
propertyEncoders.set(property, list);
|
|
149
|
+
} else {
|
|
150
|
+
assertAllowedFields(owner, "property", declaration, PROPERTY_DROPPED_FIELDS);
|
|
151
|
+
const list = propertyEncoders.get(property);
|
|
152
|
+
if (list) {
|
|
153
|
+
const existingIndex = list.findIndex((entry) => entry.plugin === targetPlugin);
|
|
154
|
+
if (existingIndex !== -1) {
|
|
155
|
+
list.splice(existingIndex, 1);
|
|
156
|
+
if (list.length === 0) propertyEncoders.delete(property);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const droppedIndex = propertyDropped.findIndex((entry) => entry.plugin === targetPlugin && entry.property === property);
|
|
160
|
+
const nextDropped = {
|
|
161
|
+
dropped: declaration.dropped,
|
|
162
|
+
plugin: targetPlugin,
|
|
163
|
+
property
|
|
164
|
+
};
|
|
165
|
+
if (droppedIndex === -1) propertyDropped.push(nextDropped);
|
|
166
|
+
else propertyDropped[droppedIndex] = nextDropped;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const schemaMarks = /* @__PURE__ */ new Map();
|
|
170
|
+
const runtime = getPlateRuntime(runtimeOwner);
|
|
171
|
+
for (const binding of model.bindings) {
|
|
172
|
+
if (binding.kind !== "mark" || !binding.propertyKey) continue;
|
|
173
|
+
if (runtime.plugins[binding.name]?.enabled === false) continue;
|
|
174
|
+
schemaMarks.set(binding.propertyKey, binding.name);
|
|
175
|
+
}
|
|
176
|
+
const compiled = Object.freeze({
|
|
177
|
+
elementEncoders,
|
|
178
|
+
elementTextFormats,
|
|
179
|
+
markDropped,
|
|
180
|
+
markEncoders,
|
|
181
|
+
propertyDropped,
|
|
182
|
+
propertyEncoders,
|
|
183
|
+
schemaMarks
|
|
184
|
+
});
|
|
185
|
+
DOCX_FORMATS_CACHE.set(model.revision, compiled);
|
|
186
|
+
return compiled;
|
|
187
|
+
};
|
|
188
|
+
const resolveSyntaxStyle = (className, syntax) => {
|
|
189
|
+
if (!syntax) return void 0;
|
|
190
|
+
const rawTokens = className.split(/\s+/u).map((token) => token.trim()).filter((token) => token.length > 0);
|
|
191
|
+
if (rawTokens.length === 0) return void 0;
|
|
192
|
+
const stripped = rawTokens.map((token) => token.startsWith("hljs-") ? token.slice(5) : token);
|
|
193
|
+
const candidates = [];
|
|
194
|
+
if (stripped.length > 1) {
|
|
195
|
+
candidates.push(stripped.join("."));
|
|
196
|
+
candidates.push(rawTokens.join("."));
|
|
197
|
+
for (let i = 0; i < stripped.length - 1; i += 1) candidates.push(`${stripped[i]}.${stripped[i + 1]}`);
|
|
198
|
+
}
|
|
199
|
+
for (let i = stripped.length - 1; i >= 0; i -= 1) {
|
|
200
|
+
candidates.push(stripped[i]);
|
|
201
|
+
if (rawTokens[i] !== stripped[i]) candidates.push(rawTokens[i]);
|
|
202
|
+
}
|
|
203
|
+
for (const key of candidates) {
|
|
204
|
+
const style = syntax[key];
|
|
205
|
+
if (style) return style;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const listItemOf = (view, element, path, list) => {
|
|
209
|
+
if (!view.plugin(BaseListPlugin).installed) return void 0;
|
|
210
|
+
const listElement = element;
|
|
211
|
+
const base = {
|
|
212
|
+
level: Math.max(0, (listElement.indent ?? 1) - 1),
|
|
213
|
+
levels: listElement.listLevels,
|
|
214
|
+
list
|
|
215
|
+
};
|
|
216
|
+
switch (listElement.listType) {
|
|
217
|
+
case "bulleted": return {
|
|
218
|
+
...base,
|
|
219
|
+
marker: {
|
|
220
|
+
kind: "bulleted",
|
|
221
|
+
style: listElement.listStyle ?? "disc"
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
case "numbered": return {
|
|
225
|
+
...base,
|
|
226
|
+
marker: {
|
|
227
|
+
kind: "numbered",
|
|
228
|
+
number: view.plugin(BaseListPlugin).read.ordinal(path) ?? 1,
|
|
229
|
+
restart: listElement.listRestart !== void 0,
|
|
230
|
+
style: listElement.listStyle ?? "decimal"
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
case "task": return {
|
|
234
|
+
...base,
|
|
235
|
+
marker: {
|
|
236
|
+
checked: listElement.checked === true,
|
|
237
|
+
kind: "task"
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
default: return;
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
const mergeMarks = (base, extra) => {
|
|
244
|
+
if (!base) return extra;
|
|
245
|
+
if (!extra) return base;
|
|
246
|
+
return {
|
|
247
|
+
...base,
|
|
248
|
+
...extra
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
const mergeBlockProps = (target, extra) => {
|
|
252
|
+
if (!extra) return target;
|
|
253
|
+
return {
|
|
254
|
+
...target,
|
|
255
|
+
...extra.align !== void 0 ? { align: extra.align } : {},
|
|
256
|
+
...extra.indentPx !== void 0 ? { indentPx: extra.indentPx } : {},
|
|
257
|
+
...extra.lineHeight !== void 0 ? { lineHeight: extra.lineHeight } : {}
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
const mergeInlineMarks = (inlines, marks) => inlines.map((inline) => {
|
|
261
|
+
if (inline.kind === "text") return {
|
|
262
|
+
...inline,
|
|
263
|
+
marks: mergeMarks(marks, inline.marks)
|
|
264
|
+
};
|
|
265
|
+
if (inline.kind === "link") return {
|
|
266
|
+
...inline,
|
|
267
|
+
children: mergeInlineMarks(inline.children, marks)
|
|
268
|
+
};
|
|
269
|
+
return inline;
|
|
270
|
+
});
|
|
271
|
+
const attachReviewRunToInlines = (inlines, reviewRun) => inlines.map((inline) => {
|
|
272
|
+
if (inline.kind === "text" || inline.kind === "inlineEquation" || inline.kind === "lineBreak" || inline.kind === "inlineImage" || inline.kind === "footnoteReference") return inline.reviewRun ? inline : {
|
|
273
|
+
...inline,
|
|
274
|
+
reviewRun
|
|
275
|
+
};
|
|
276
|
+
if (inline.kind === "link") return {
|
|
277
|
+
...inline,
|
|
278
|
+
children: attachReviewRunToInlines(inline.children, reviewRun)
|
|
279
|
+
};
|
|
280
|
+
return inline;
|
|
281
|
+
});
|
|
282
|
+
const indexStoryTree = (nodes, root, parentPath, nodeLocations, childrenLocations) => {
|
|
283
|
+
childrenLocations.set(nodes, {
|
|
284
|
+
parentPath,
|
|
285
|
+
root
|
|
286
|
+
});
|
|
287
|
+
nodes.forEach((node, index) => {
|
|
288
|
+
const path = [...parentPath, index];
|
|
289
|
+
nodeLocations.set(node, {
|
|
290
|
+
path,
|
|
291
|
+
root
|
|
292
|
+
});
|
|
293
|
+
if (ElementApi.isElement(node)) indexStoryTree(node.children, root, path, nodeLocations, childrenLocations);
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
const compileStorySync = (editor, storyDocument, storyName, formats, styles, review, diagnostics) => {
|
|
297
|
+
const baseView = projectEditorView(editor, { document: storyDocument });
|
|
298
|
+
const rootViews = /* @__PURE__ */ new Map([[MAIN_ROOT_KEY, baseView]]);
|
|
299
|
+
const getRootView = (root) => {
|
|
300
|
+
let view = rootViews.get(root);
|
|
301
|
+
if (!view) {
|
|
302
|
+
view = projectEditorView(baseView, { root });
|
|
303
|
+
rootViews.set(root, view);
|
|
304
|
+
}
|
|
305
|
+
return view;
|
|
306
|
+
};
|
|
307
|
+
const nodeLocations = /* @__PURE__ */ new WeakMap();
|
|
308
|
+
const childrenLocations = /* @__PURE__ */ new WeakMap();
|
|
309
|
+
indexStoryTree(storyDocument.children, MAIN_ROOT_KEY, [], nodeLocations, childrenLocations);
|
|
310
|
+
if (storyDocument.roots) for (const [rootKey, rootNodes] of Object.entries(storyDocument.roots)) indexStoryTree(rootNodes, rootKey, [], nodeLocations, childrenLocations);
|
|
311
|
+
const decorationSources = getPlateDecorationSources(baseView);
|
|
312
|
+
const occurrenceCounter = /* @__PURE__ */ new Map();
|
|
313
|
+
let orderCounter = 0;
|
|
314
|
+
const textSpans = [];
|
|
315
|
+
const renderedRoots = /* @__PURE__ */ new Set();
|
|
316
|
+
const reportedMissingMarks = /* @__PURE__ */ new Set();
|
|
317
|
+
const droppedTextCounts = /* @__PURE__ */ new Map();
|
|
318
|
+
const droppedMarkCounts = /* @__PURE__ */ new Map();
|
|
319
|
+
const droppedPropertyCounts = /* @__PURE__ */ new Map();
|
|
320
|
+
const mainBlockRecords = /* @__PURE__ */ new Map();
|
|
321
|
+
const bumpDropped = (map, key, plugin, dropped) => {
|
|
322
|
+
const existing = map.get(key);
|
|
323
|
+
if (existing) existing.count += 1;
|
|
324
|
+
else map.set(key, {
|
|
325
|
+
count: 1,
|
|
326
|
+
dropped,
|
|
327
|
+
plugin
|
|
328
|
+
});
|
|
329
|
+
};
|
|
330
|
+
const nextOccurrence = (root) => {
|
|
331
|
+
const current = (occurrenceCounter.get(root) ?? 0) + 1;
|
|
332
|
+
occurrenceCounter.set(root, current);
|
|
333
|
+
return current;
|
|
334
|
+
};
|
|
335
|
+
const runtime = getPlateRuntime(baseView);
|
|
336
|
+
const getOperationContext = createPluginFormatOperationContext(baseView, getCompiledPlateModel(baseView), runtime.pluginList);
|
|
337
|
+
const operationKey = {};
|
|
338
|
+
const formatContextCache = /* @__PURE__ */ new Map();
|
|
339
|
+
const readFormatContext = (view, ownerName) => {
|
|
340
|
+
let byOwner = formatContextCache.get(view);
|
|
341
|
+
if (!byOwner) {
|
|
342
|
+
byOwner = /* @__PURE__ */ new Map();
|
|
343
|
+
formatContextCache.set(view, byOwner);
|
|
344
|
+
}
|
|
345
|
+
const cached = byOwner.get(ownerName);
|
|
346
|
+
if (cached) return cached;
|
|
347
|
+
const ownerPlugin = runtime.plugins[ownerName];
|
|
348
|
+
if (!ownerPlugin) throw new Error(`DOCX format owner "${ownerName}" is not installed.`);
|
|
349
|
+
const resolved = withDocumentViewRead(view, () => view.read((state) => getOperationContext(ownerPlugin, state, operationKey)));
|
|
350
|
+
byOwner.set(ownerName, resolved);
|
|
351
|
+
return resolved;
|
|
352
|
+
};
|
|
353
|
+
const readBlockDecorations = (view, root, node, path) => {
|
|
354
|
+
if (decorationSources.length === 0 || !styles?.codeBlock?.syntax) return [];
|
|
355
|
+
const result = [];
|
|
356
|
+
for (const source of decorationSources) {
|
|
357
|
+
const output = source.read({
|
|
358
|
+
editor: view,
|
|
359
|
+
entry: [node, path]
|
|
360
|
+
});
|
|
361
|
+
for (const decoration of output) {
|
|
362
|
+
const className = typeof decoration.attributes?.className === "string" ? decoration.attributes.className : void 0;
|
|
363
|
+
if (!className) continue;
|
|
364
|
+
const range = getReaderRange(decoration.range, root);
|
|
365
|
+
if (!range) continue;
|
|
366
|
+
const [start, end] = RangeApi.edges(range);
|
|
367
|
+
if (start.path.join(",") === end.path.join(",") && end.offset > start.offset) result.push({
|
|
368
|
+
className,
|
|
369
|
+
end: end.offset,
|
|
370
|
+
pathKey: start.path.join(","),
|
|
371
|
+
start: start.offset
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return result;
|
|
376
|
+
};
|
|
377
|
+
const compileTextLeaf = (textNode, root, path, occurrence, view, decorations, rootsUsed) => {
|
|
378
|
+
rootsUsed.add(root);
|
|
379
|
+
const pathKey = path.join(",");
|
|
380
|
+
orderCounter += 1;
|
|
381
|
+
const order = orderCounter;
|
|
382
|
+
const provenance = {
|
|
383
|
+
length: textNode.text.length,
|
|
384
|
+
occurrence,
|
|
385
|
+
order,
|
|
386
|
+
path,
|
|
387
|
+
pathKey,
|
|
388
|
+
root
|
|
389
|
+
};
|
|
390
|
+
const marks = {};
|
|
391
|
+
for (const [key, value] of Object.entries(textNode)) {
|
|
392
|
+
if (key === "text" || key === "authored") continue;
|
|
393
|
+
if (value === void 0 || value === false) continue;
|
|
394
|
+
const markEncoder = formats.markEncoders.get(key);
|
|
395
|
+
if (markEncoder) {
|
|
396
|
+
const formatContext = readFormatContext(view, markEncoder.owner);
|
|
397
|
+
const encoded = markEncoder.encode({
|
|
398
|
+
...formatContext,
|
|
399
|
+
node: textNode,
|
|
400
|
+
report: (input) => pushFormatDiagnostic(input, root, path),
|
|
401
|
+
value
|
|
402
|
+
});
|
|
403
|
+
if (encoded) Object.assign(marks, encoded);
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
const droppedMark = formats.markDropped.get(key);
|
|
407
|
+
if (droppedMark) {
|
|
408
|
+
bumpDropped(droppedMarkCounts, key, droppedMark.plugin, droppedMark.dropped);
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
const ownerPlugin = formats.schemaMarks.get(key);
|
|
412
|
+
if (ownerPlugin && !reportedMissingMarks.has(`${storyName}:${ownerPlugin}`)) {
|
|
413
|
+
reportedMissingMarks.add(`${storyName}:${ownerPlugin}`);
|
|
414
|
+
diagnostics.push(docxUnsupportedContent({
|
|
415
|
+
action: "dropped",
|
|
416
|
+
feature: ownerPlugin,
|
|
417
|
+
impact: "lossy",
|
|
418
|
+
message: `Plugin "${ownerPlugin}" has no DOCX mark mapping, so its formatting was dropped.`,
|
|
419
|
+
path,
|
|
420
|
+
root
|
|
421
|
+
}));
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
const resolvedMarks = Object.keys(marks).length > 0 ? marks : void 0;
|
|
425
|
+
const reviewRun = review?.runsByTarget.get(reviewTargetKey(root, "text", path));
|
|
426
|
+
const leafDecorations = decorations.filter((d) => d.pathKey === pathKey);
|
|
427
|
+
if (leafDecorations.length === 0 || textNode.text.length === 0) return [{
|
|
428
|
+
kind: "text",
|
|
429
|
+
...resolvedMarks ? { marks: resolvedMarks } : {},
|
|
430
|
+
provenance,
|
|
431
|
+
...reviewRun ? { reviewRun } : {},
|
|
432
|
+
sliceEnd: textNode.text.length,
|
|
433
|
+
sliceStart: 0,
|
|
434
|
+
text: textNode.text
|
|
435
|
+
}];
|
|
436
|
+
const boundaries = /* @__PURE__ */ new Set([0, textNode.text.length]);
|
|
437
|
+
for (const decoration of leafDecorations) {
|
|
438
|
+
boundaries.add(Math.max(0, Math.min(textNode.text.length, decoration.start)));
|
|
439
|
+
boundaries.add(Math.max(0, Math.min(textNode.text.length, decoration.end)));
|
|
440
|
+
}
|
|
441
|
+
const sorted = [...boundaries].sort((a, b) => a - b);
|
|
442
|
+
const runs = [];
|
|
443
|
+
for (let i = 0; i < sorted.length - 1; i += 1) {
|
|
444
|
+
const start = sorted[i];
|
|
445
|
+
const end = sorted[i + 1];
|
|
446
|
+
if (start === end) continue;
|
|
447
|
+
let lookMarks;
|
|
448
|
+
for (const decoration of leafDecorations) if (decoration.start < end && decoration.end > start) {
|
|
449
|
+
const matched = resolveSyntaxStyle(decoration.className, styles?.codeBlock?.syntax);
|
|
450
|
+
if (matched) lookMarks = lookMarks ? {
|
|
451
|
+
...lookMarks,
|
|
452
|
+
...matched
|
|
453
|
+
} : matched;
|
|
454
|
+
}
|
|
455
|
+
runs.push({
|
|
456
|
+
kind: "text",
|
|
457
|
+
...lookMarks ? { lookMarks } : {},
|
|
458
|
+
...resolvedMarks ? { marks: resolvedMarks } : {},
|
|
459
|
+
provenance,
|
|
460
|
+
...reviewRun ? { reviewRun } : {},
|
|
461
|
+
sliceEnd: end,
|
|
462
|
+
sliceStart: start,
|
|
463
|
+
text: textNode.text.slice(start, end)
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
return runs;
|
|
467
|
+
};
|
|
468
|
+
const pushFormatDiagnostic = (input, root, path) => {
|
|
469
|
+
switch (input.code) {
|
|
470
|
+
case "lossy-content":
|
|
471
|
+
diagnostics.push(docxLossyContent({
|
|
472
|
+
feature: input.feature,
|
|
473
|
+
message: input.message,
|
|
474
|
+
path,
|
|
475
|
+
root
|
|
476
|
+
}));
|
|
477
|
+
break;
|
|
478
|
+
case "property-dropped":
|
|
479
|
+
diagnostics.push(docxPropertyDropped({
|
|
480
|
+
count: 1,
|
|
481
|
+
feature: input.feature ?? "property",
|
|
482
|
+
message: input.message
|
|
483
|
+
}));
|
|
484
|
+
break;
|
|
485
|
+
case "resource-omitted":
|
|
486
|
+
diagnostics.push(docxResourceOmitted({
|
|
487
|
+
feature: input.feature,
|
|
488
|
+
impact: input.impact ?? "lossy",
|
|
489
|
+
message: input.message,
|
|
490
|
+
path,
|
|
491
|
+
root
|
|
492
|
+
}));
|
|
493
|
+
break;
|
|
494
|
+
case "unsupported-content":
|
|
495
|
+
diagnostics.push(docxUnsupportedContent({
|
|
496
|
+
action: input.action ?? "dropped",
|
|
497
|
+
feature: input.feature,
|
|
498
|
+
impact: input.impact ?? "lossy",
|
|
499
|
+
message: input.message,
|
|
500
|
+
path,
|
|
501
|
+
root
|
|
502
|
+
}));
|
|
503
|
+
break;
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
const collectElementProperties = (element, root, path, view) => {
|
|
507
|
+
let props = {};
|
|
508
|
+
for (const [property, encoders] of formats.propertyEncoders) {
|
|
509
|
+
const value = element[property];
|
|
510
|
+
if (value === void 0 || value === false) continue;
|
|
511
|
+
for (const entry of encoders) {
|
|
512
|
+
const formatContext = readFormatContext(view, entry.owner);
|
|
513
|
+
const encoded = entry.encode({
|
|
514
|
+
...formatContext,
|
|
515
|
+
key: property,
|
|
516
|
+
node: element,
|
|
517
|
+
report: (input) => pushFormatDiagnostic(input, root, path),
|
|
518
|
+
value
|
|
519
|
+
});
|
|
520
|
+
props = mergeBlockProps(props, encoded);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
for (const dropped of formats.propertyDropped) {
|
|
524
|
+
const value = element[dropped.property];
|
|
525
|
+
if (value !== void 0 && value !== false) bumpDropped(droppedPropertyCounts, `${dropped.plugin}:${dropped.property}`, dropped.plugin, dropped.dropped);
|
|
526
|
+
}
|
|
527
|
+
return props;
|
|
528
|
+
};
|
|
529
|
+
const lowerInlines = (items, rootsUsed, inheritedMarks) => {
|
|
530
|
+
const out = [];
|
|
531
|
+
for (const item of items) {
|
|
532
|
+
const fragment = readFragment(item);
|
|
533
|
+
if (fragment) {
|
|
534
|
+
for (const r of fragment.rootsUsed) rootsUsed.add(r);
|
|
535
|
+
if (fragment.kind === "inlines") out.push(...inheritedMarks ? mergeInlineMarks(fragment.inlines, inheritedMarks) : fragment.inlines);
|
|
536
|
+
else for (const block of fragment.blocks) if (block.kind === "paragraph") out.push(...inheritedMarks ? mergeInlineMarks(block.children, inheritedMarks) : block.children);
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
const inline = item;
|
|
540
|
+
switch (inline.kind) {
|
|
541
|
+
case "text": {
|
|
542
|
+
const merged = mergeMarks(inheritedMarks, inline.marks);
|
|
543
|
+
out.push({
|
|
544
|
+
kind: "text",
|
|
545
|
+
...merged ? { marks: merged } : {},
|
|
546
|
+
...inline.placeholder !== void 0 ? { placeholder: inline.placeholder } : {},
|
|
547
|
+
text: inline.text
|
|
548
|
+
});
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
case "link":
|
|
552
|
+
out.push({
|
|
553
|
+
children: lowerInlines(inline.children, rootsUsed, inheritedMarks),
|
|
554
|
+
kind: "link",
|
|
555
|
+
url: inline.url
|
|
556
|
+
});
|
|
557
|
+
break;
|
|
558
|
+
case "inlineEquation":
|
|
559
|
+
out.push({
|
|
560
|
+
kind: "inlineEquation",
|
|
561
|
+
latex: inline.latex
|
|
562
|
+
});
|
|
563
|
+
break;
|
|
564
|
+
case "lineBreak":
|
|
565
|
+
out.push({ kind: "lineBreak" });
|
|
566
|
+
break;
|
|
567
|
+
case "inlineImage":
|
|
568
|
+
out.push({
|
|
569
|
+
...inline.alt !== void 0 ? { alt: inline.alt } : {},
|
|
570
|
+
...inline.heightPx !== void 0 ? { heightPx: inline.heightPx } : {},
|
|
571
|
+
kind: "inlineImage",
|
|
572
|
+
url: inline.url,
|
|
573
|
+
...inline.widthPx !== void 0 ? { widthPx: inline.widthPx } : {}
|
|
574
|
+
});
|
|
575
|
+
break;
|
|
576
|
+
case "inlineGroup":
|
|
577
|
+
out.push(...lowerInlines(inline.children, rootsUsed, mergeMarks(inheritedMarks, inline.marks)));
|
|
578
|
+
break;
|
|
579
|
+
case "footnoteReference":
|
|
580
|
+
out.push({
|
|
581
|
+
kind: "footnoteReference",
|
|
582
|
+
ref: inline.ref
|
|
583
|
+
});
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return out;
|
|
588
|
+
};
|
|
589
|
+
const lowerBlocks = (items, rootsUsed, defaultRoot) => {
|
|
590
|
+
const out = [];
|
|
591
|
+
for (const item of items) {
|
|
592
|
+
const fragment = readFragment(item);
|
|
593
|
+
if (fragment) {
|
|
594
|
+
for (const r of fragment.rootsUsed) rootsUsed.add(r);
|
|
595
|
+
if (fragment.kind === "blocks") out.push(...fragment.blocks);
|
|
596
|
+
else if (fragment.inlines.length > 0) out.push({
|
|
597
|
+
children: fragment.inlines,
|
|
598
|
+
kind: "paragraph",
|
|
599
|
+
roots: new Set(fragment.rootsUsed)
|
|
600
|
+
});
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
const block = item;
|
|
604
|
+
const blockRoots = /* @__PURE__ */ new Set([defaultRoot]);
|
|
605
|
+
switch (block.kind) {
|
|
606
|
+
case "paragraph": {
|
|
607
|
+
const children = lowerInlines(block.children, blockRoots);
|
|
608
|
+
for (const r of blockRoots) rootsUsed.add(r);
|
|
609
|
+
out.push({
|
|
610
|
+
...block.align !== void 0 ? { align: block.align } : {},
|
|
611
|
+
...block.bookmark !== void 0 ? { bookmark: block.bookmark } : {},
|
|
612
|
+
children,
|
|
613
|
+
...block.codeLanguage !== void 0 ? { codeLanguage: block.codeLanguage } : {},
|
|
614
|
+
...block.indentPx !== void 0 ? { indentPx: block.indentPx } : {},
|
|
615
|
+
...block.isCodeBlock ? { isCodeBlock: true } : {},
|
|
616
|
+
kind: "paragraph",
|
|
617
|
+
...block.lineHeight !== void 0 ? { lineHeight: block.lineHeight } : {},
|
|
618
|
+
...block.preserveWhitespace ? { preserveWhitespace: true } : {},
|
|
619
|
+
roots: blockRoots,
|
|
620
|
+
...block.style !== void 0 ? { style: block.style } : {}
|
|
621
|
+
});
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
case "callout": {
|
|
625
|
+
const bodyBlocks = lowerBlocks(block.children, blockRoots, defaultRoot);
|
|
626
|
+
for (const r of blockRoots) rootsUsed.add(r);
|
|
627
|
+
out.push({
|
|
628
|
+
borders: "none",
|
|
629
|
+
columnWidthsPx: [30, 594],
|
|
630
|
+
isCallout: true,
|
|
631
|
+
kind: "table",
|
|
632
|
+
roots: blockRoots,
|
|
633
|
+
rows: [{ cells: [{
|
|
634
|
+
...block.backgroundColor ? { backgroundColor: block.backgroundColor } : {},
|
|
635
|
+
children: [{
|
|
636
|
+
children: [{
|
|
637
|
+
kind: "text",
|
|
638
|
+
text: block.icon
|
|
639
|
+
}],
|
|
640
|
+
kind: "paragraph",
|
|
641
|
+
roots: /* @__PURE__ */ new Set([defaultRoot])
|
|
642
|
+
}],
|
|
643
|
+
isCalloutIcon: true,
|
|
644
|
+
widthPx: 30
|
|
645
|
+
}, {
|
|
646
|
+
...block.backgroundColor ? { backgroundColor: block.backgroundColor } : {},
|
|
647
|
+
children: bodyBlocks.length > 0 ? bodyBlocks : [{
|
|
648
|
+
children: [],
|
|
649
|
+
kind: "paragraph",
|
|
650
|
+
roots: /* @__PURE__ */ new Set([defaultRoot])
|
|
651
|
+
}]
|
|
652
|
+
}] }]
|
|
653
|
+
});
|
|
654
|
+
break;
|
|
655
|
+
}
|
|
656
|
+
case "table": {
|
|
657
|
+
const rows = block.rows.map((row) => ({
|
|
658
|
+
cells: row.cells.map((cell) => {
|
|
659
|
+
const cellRoots = /* @__PURE__ */ new Set([defaultRoot]);
|
|
660
|
+
const cellChildren = lowerBlocks(cell.children, cellRoots, defaultRoot);
|
|
661
|
+
for (const r of cellRoots) blockRoots.add(r);
|
|
662
|
+
return {
|
|
663
|
+
...cell.backgroundColor !== void 0 ? { backgroundColor: cell.backgroundColor } : {},
|
|
664
|
+
...cell.borders !== void 0 ? { borders: cell.borders } : {},
|
|
665
|
+
children: cellChildren,
|
|
666
|
+
...cell.colSpan !== void 0 ? { colSpan: cell.colSpan } : {},
|
|
667
|
+
...cell.header ? { header: true } : {},
|
|
668
|
+
...cell.rowSpan !== void 0 ? { rowSpan: cell.rowSpan } : {},
|
|
669
|
+
...cell.verticalAlign !== void 0 ? { verticalAlign: cell.verticalAlign } : {},
|
|
670
|
+
...cell.widthPct !== void 0 ? { widthPct: cell.widthPct } : {},
|
|
671
|
+
...cell.widthPx !== void 0 ? { widthPx: cell.widthPx } : {}
|
|
672
|
+
};
|
|
673
|
+
}),
|
|
674
|
+
...row.header ? { header: true } : {},
|
|
675
|
+
...row.minHeightPx !== void 0 ? { minHeightPx: row.minHeightPx } : {}
|
|
676
|
+
}));
|
|
677
|
+
for (const r of blockRoots) rootsUsed.add(r);
|
|
678
|
+
out.push({
|
|
679
|
+
...block.borders !== void 0 ? { borders: block.borders } : {},
|
|
680
|
+
...block.columnWidthsPx !== void 0 ? { columnWidthsPx: block.columnWidthsPx } : {},
|
|
681
|
+
kind: "table",
|
|
682
|
+
...block.marginLeftPx !== void 0 ? { marginLeftPx: block.marginLeftPx } : {},
|
|
683
|
+
roots: blockRoots,
|
|
684
|
+
rows
|
|
685
|
+
});
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
case "blockImage": {
|
|
689
|
+
const caption = block.caption ? lowerInlines(block.caption, blockRoots) : void 0;
|
|
690
|
+
for (const r of blockRoots) rootsUsed.add(r);
|
|
691
|
+
out.push({
|
|
692
|
+
...block.alt !== void 0 ? { alt: block.alt } : {},
|
|
693
|
+
...caption ? { caption } : {},
|
|
694
|
+
...block.heightPx !== void 0 ? { heightPx: block.heightPx } : {},
|
|
695
|
+
kind: "blockImage",
|
|
696
|
+
roots: blockRoots,
|
|
697
|
+
url: block.url,
|
|
698
|
+
...block.widthPx !== void 0 ? { widthPx: block.widthPx } : {}
|
|
699
|
+
});
|
|
700
|
+
break;
|
|
701
|
+
}
|
|
702
|
+
case "blockEquation":
|
|
703
|
+
for (const r of blockRoots) rootsUsed.add(r);
|
|
704
|
+
out.push({
|
|
705
|
+
kind: "blockEquation",
|
|
706
|
+
latex: block.latex,
|
|
707
|
+
roots: blockRoots
|
|
708
|
+
});
|
|
709
|
+
break;
|
|
710
|
+
case "horizontalRule":
|
|
711
|
+
for (const r of blockRoots) rootsUsed.add(r);
|
|
712
|
+
out.push({
|
|
713
|
+
kind: "horizontalRule",
|
|
714
|
+
roots: blockRoots
|
|
715
|
+
});
|
|
716
|
+
break;
|
|
717
|
+
case "pageBreak":
|
|
718
|
+
for (const r of blockRoots) rootsUsed.add(r);
|
|
719
|
+
out.push({
|
|
720
|
+
kind: "pageBreak",
|
|
721
|
+
roots: blockRoots
|
|
722
|
+
});
|
|
723
|
+
break;
|
|
724
|
+
case "blockquote": {
|
|
725
|
+
const children = lowerBlocks(block.children, blockRoots, defaultRoot);
|
|
726
|
+
for (const r of blockRoots) rootsUsed.add(r);
|
|
727
|
+
out.push({
|
|
728
|
+
children,
|
|
729
|
+
kind: "blockquote",
|
|
730
|
+
roots: blockRoots
|
|
731
|
+
});
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
case "group": {
|
|
735
|
+
const children = lowerBlocks(block.children, blockRoots, defaultRoot);
|
|
736
|
+
for (const r of blockRoots) rootsUsed.add(r);
|
|
737
|
+
out.push(...children);
|
|
738
|
+
break;
|
|
739
|
+
}
|
|
740
|
+
case "footnoteDefinition": {
|
|
741
|
+
const children = lowerBlocks(block.children, blockRoots, defaultRoot);
|
|
742
|
+
for (const r of blockRoots) rootsUsed.add(r);
|
|
743
|
+
out.push({
|
|
744
|
+
children,
|
|
745
|
+
kind: "footnoteDefinition",
|
|
746
|
+
ref: block.ref,
|
|
747
|
+
roots: blockRoots
|
|
748
|
+
});
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return out;
|
|
754
|
+
};
|
|
755
|
+
const applyElementBlockProps = (blocks, props, listItem, structureRevision) => {
|
|
756
|
+
for (const block of blocks) if (block.kind === "paragraph") {
|
|
757
|
+
if (props.align !== void 0 && block.align === void 0) block.align = props.align;
|
|
758
|
+
if (props.indentPx !== void 0 && block.indentPx === void 0) block.indentPx = props.indentPx;
|
|
759
|
+
if (props.lineHeight !== void 0 && block.lineHeight === void 0) block.lineHeight = props.lineHeight;
|
|
760
|
+
if (structureRevision && !block.structureRevision) block.structureRevision = structureRevision;
|
|
761
|
+
} else if (block.kind === "blockquote") applyElementBlockProps(block.children, props, void 0, structureRevision);
|
|
762
|
+
if (listItem && blocks.length > 0) {
|
|
763
|
+
blocks[0].listItem = listItem;
|
|
764
|
+
const isCheckedTask = listItem.marker.kind === "task" && listItem.marker.checked;
|
|
765
|
+
if (blocks.length > 1) for (let i = 1; i < blocks.length; i += 1) {
|
|
766
|
+
const b = blocks[i];
|
|
767
|
+
if (isCheckedTask) b.isCheckedTaskContinuation = true;
|
|
768
|
+
if (b.kind === "paragraph" && b.indentPx === void 0) b.indentPx = (listItem.level + 1) * 24;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
const voidCoveredReviewRuns = /* @__PURE__ */ new Set();
|
|
773
|
+
const coverVoidBlockReviewRuns = (element, root, path) => {
|
|
774
|
+
if (!review) return;
|
|
775
|
+
const visit = (nodes, parentPath) => {
|
|
776
|
+
nodes.forEach((child, index) => {
|
|
777
|
+
const childPath = [...parentPath, index];
|
|
778
|
+
if (ElementApi.isElement(child)) visit(child.children, childPath);
|
|
779
|
+
else {
|
|
780
|
+
const run = review.runsByTarget.get(reviewTargetKey(root, "text", childPath));
|
|
781
|
+
if (run) voidCoveredReviewRuns.add(run);
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
};
|
|
785
|
+
visit(element.children, path);
|
|
786
|
+
};
|
|
787
|
+
const compileVoidTextAnchors = (element, root, path, occurrence, rootsUsed) => {
|
|
788
|
+
const anchors = [];
|
|
789
|
+
const visit = (nodes, parentPath) => {
|
|
790
|
+
nodes.forEach((child, index) => {
|
|
791
|
+
const childPath = [...parentPath, index];
|
|
792
|
+
if (ElementApi.isElement(child)) visit(child.children, childPath);
|
|
793
|
+
else {
|
|
794
|
+
rootsUsed.add(root);
|
|
795
|
+
orderCounter += 1;
|
|
796
|
+
const order = orderCounter;
|
|
797
|
+
anchors.push({
|
|
798
|
+
kind: "voidAnchor",
|
|
799
|
+
provenance: {
|
|
800
|
+
length: child.text.length,
|
|
801
|
+
occurrence,
|
|
802
|
+
order,
|
|
803
|
+
path: childPath,
|
|
804
|
+
pathKey: childPath.join(","),
|
|
805
|
+
root
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
};
|
|
811
|
+
visit(element.children, path);
|
|
812
|
+
return anchors;
|
|
813
|
+
};
|
|
814
|
+
const createEncodeContext = (element, root, path, occurrence, rootStack, view, encoder, decorations) => {
|
|
815
|
+
const readSchema = view.read.schema;
|
|
816
|
+
const resolveChildrenLocation = (children) => {
|
|
817
|
+
const targetNodes = children ?? element.children;
|
|
818
|
+
const loc = childrenLocations.get(targetNodes);
|
|
819
|
+
if (loc) {
|
|
820
|
+
const targetRoot = loc.root;
|
|
821
|
+
const isNewRoot = targetRoot !== root;
|
|
822
|
+
return {
|
|
823
|
+
nodes: targetNodes,
|
|
824
|
+
occ: isNewRoot ? nextOccurrence(targetRoot) : occurrence,
|
|
825
|
+
parentPath: loc.parentPath,
|
|
826
|
+
root: targetRoot,
|
|
827
|
+
stack: isNewRoot ? [...rootStack, targetRoot] : rootStack,
|
|
828
|
+
view: isNewRoot ? getRootView(targetRoot) : view
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
if (targetNodes.length > 0) {
|
|
832
|
+
const firstLoc = nodeLocations.get(targetNodes[0]);
|
|
833
|
+
if (firstLoc) {
|
|
834
|
+
const targetRoot = firstLoc.root;
|
|
835
|
+
const isNewRoot = targetRoot !== root;
|
|
836
|
+
return {
|
|
837
|
+
nodes: targetNodes,
|
|
838
|
+
occ: isNewRoot ? nextOccurrence(targetRoot) : occurrence,
|
|
839
|
+
parentPath: firstLoc.path.slice(0, -1),
|
|
840
|
+
root: targetRoot,
|
|
841
|
+
stack: isNewRoot ? [...rootStack, targetRoot] : rootStack,
|
|
842
|
+
view: isNewRoot ? getRootView(targetRoot) : view
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
return {
|
|
847
|
+
nodes: targetNodes,
|
|
848
|
+
occ: occurrence,
|
|
849
|
+
parentPath: path,
|
|
850
|
+
root,
|
|
851
|
+
stack: rootStack,
|
|
852
|
+
view
|
|
853
|
+
};
|
|
854
|
+
};
|
|
855
|
+
const formatContext = readFormatContext(view, encoder.owner);
|
|
856
|
+
const modelView = createPluginFormatModelView(storyDocument, element, path, root);
|
|
857
|
+
return {
|
|
858
|
+
...formatContext,
|
|
859
|
+
...modelView,
|
|
860
|
+
contentRoot: (slot) => {
|
|
861
|
+
const targetRoot = readSchema.getElementContentRoots(element)[slot];
|
|
862
|
+
if (!targetRoot) throw new Error(`Element "${element.type}" does not own content root slot "${slot}".`);
|
|
863
|
+
if (rootStack.includes(targetRoot)) throw new Error(`Content root "${targetRoot}" cannot recursively render itself.`);
|
|
864
|
+
const rootNodes = readNamedRootChildren(storyDocument.roots, targetRoot);
|
|
865
|
+
if (!rootNodes) return [];
|
|
866
|
+
if (!childrenLocations.has(rootNodes)) indexStoryTree(rootNodes, targetRoot, [], nodeLocations, childrenLocations);
|
|
867
|
+
return rootNodes;
|
|
868
|
+
},
|
|
869
|
+
encodeBlocks: (children) => {
|
|
870
|
+
const resolved = resolveChildrenLocation(children);
|
|
871
|
+
const rootsUsed = /* @__PURE__ */ new Set();
|
|
872
|
+
const blocks = compileBlockList(resolved.nodes, resolved.root, resolved.parentPath, resolved.occ, resolved.stack, resolved.view, rootsUsed);
|
|
873
|
+
return blocks.length > 0 ? [createFragment({
|
|
874
|
+
blocks,
|
|
875
|
+
kind: "blocks",
|
|
876
|
+
rootsUsed
|
|
877
|
+
})] : [];
|
|
878
|
+
},
|
|
879
|
+
encodeInlines: (children) => {
|
|
880
|
+
const resolved = resolveChildrenLocation(children);
|
|
881
|
+
const rootsUsed = /* @__PURE__ */ new Set();
|
|
882
|
+
const inlines = compileInlineList(resolved.nodes, resolved.root, resolved.parentPath, resolved.occ, resolved.stack, resolved.view, decorations, rootsUsed);
|
|
883
|
+
return inlines.length > 0 ? [createFragment({
|
|
884
|
+
inlines,
|
|
885
|
+
kind: "inlines",
|
|
886
|
+
rootsUsed
|
|
887
|
+
})] : [];
|
|
888
|
+
},
|
|
889
|
+
key: () => {
|
|
890
|
+
try {
|
|
891
|
+
return withDocumentViewRead(view, () => view.read((state) => state.key(element)));
|
|
892
|
+
} catch {
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
},
|
|
896
|
+
node: element,
|
|
897
|
+
readPlugin: ((plugin) => {
|
|
898
|
+
const target = plugin ?? runtime.plugins[encoder.plugin];
|
|
899
|
+
return withDocumentViewRead(view, () => {
|
|
900
|
+
if (!target) return void 0;
|
|
901
|
+
const handle = view.plugin(target);
|
|
902
|
+
return handle.installed ? handle.read : void 0;
|
|
903
|
+
});
|
|
904
|
+
}),
|
|
905
|
+
report: (input) => pushFormatDiagnostic(input, root, path)
|
|
906
|
+
};
|
|
907
|
+
};
|
|
908
|
+
const compileInlineElement = (element, root, path, occurrence, rootStack, view, decorations, rootsUsed) => {
|
|
909
|
+
rootsUsed.add(root);
|
|
910
|
+
const isVoid = view.read.schema.isVoid(element);
|
|
911
|
+
const reviewRun = isVoid ? review?.runsByTarget.get(reviewTargetKey(root, "element", path)) : void 0;
|
|
912
|
+
const voidAnchors = isVoid ? compileVoidTextAnchors(element, root, path, occurrence, rootsUsed) : [];
|
|
913
|
+
const textFormat = formats.elementTextFormats.get(element.type);
|
|
914
|
+
if (textFormat) {
|
|
915
|
+
bumpDropped(droppedTextCounts, element.type, textFormat.plugin, textFormat.dropped);
|
|
916
|
+
const renderedText = textFormat.text({ node: element });
|
|
917
|
+
const base = [...voidAnchors, ...renderedText ? [{
|
|
918
|
+
kind: "text",
|
|
919
|
+
text: renderedText
|
|
920
|
+
}] : []];
|
|
921
|
+
return reviewRun ? attachReviewRunToInlines(base, reviewRun) : base;
|
|
922
|
+
}
|
|
923
|
+
const encoder = formats.elementEncoders.get(element.type);
|
|
924
|
+
if (encoder) {
|
|
925
|
+
if (isVoid) coverVoidBlockReviewRuns(element, root, path);
|
|
926
|
+
const ctx = createEncodeContext(element, root, path, occurrence, rootStack, view, encoder, decorations);
|
|
927
|
+
const rawResult = withDocumentViewRead(view, () => encoder.encode(ctx));
|
|
928
|
+
if (rawResult === null || rawResult === void 0) return voidAnchors;
|
|
929
|
+
const lowered = lowerInlines(Array.isArray(rawResult) ? rawResult : [rawResult], rootsUsed);
|
|
930
|
+
const combined = [...voidAnchors, ...lowered];
|
|
931
|
+
return reviewRun ? attachReviewRunToInlines(combined, reviewRun) : combined;
|
|
932
|
+
}
|
|
933
|
+
diagnostics.push(docxUnsupportedContent({
|
|
934
|
+
action: isVoid ? "dropped" : "unwrapped",
|
|
935
|
+
feature: element.type,
|
|
936
|
+
impact: "lossy",
|
|
937
|
+
message: `Element "${element.type}" has no DOCX mapping, so it was ${isVoid ? "dropped" : "unwrapped"}.`,
|
|
938
|
+
path,
|
|
939
|
+
root
|
|
940
|
+
}));
|
|
941
|
+
if (isVoid) return voidAnchors;
|
|
942
|
+
return compileInlineList(element.children, root, path, occurrence, rootStack, view, decorations, rootsUsed);
|
|
943
|
+
};
|
|
944
|
+
const compileInlineList = (nodes, root, parentPath, occurrence, rootStack, view, decorations, rootsUsed) => {
|
|
945
|
+
const out = [];
|
|
946
|
+
nodes.forEach((child, index) => {
|
|
947
|
+
const loc = nodeLocations.get(child);
|
|
948
|
+
const childPath = loc && loc.root === root ? loc.path : [...parentPath, index];
|
|
949
|
+
if (ElementApi.isElement(child)) out.push(...compileInlineElement(child, root, childPath, occurrence, rootStack, view, decorations, rootsUsed));
|
|
950
|
+
else out.push(...compileTextLeaf(child, root, childPath, occurrence, view, decorations, rootsUsed));
|
|
951
|
+
});
|
|
952
|
+
return out;
|
|
953
|
+
};
|
|
954
|
+
const compileBlockElement = (element, root, path, occurrence, rootStack, view, rootsUsed) => {
|
|
955
|
+
rootsUsed.add(root);
|
|
956
|
+
const readSchema = view.read.schema;
|
|
957
|
+
const isVoid = readSchema.isVoid(element);
|
|
958
|
+
const blockProps = collectElementProperties(element, root, path, view);
|
|
959
|
+
const listItem = listItemOf(view, element, path, {
|
|
960
|
+
id: typeof element.listId === "string" ? element.listId : "",
|
|
961
|
+
root,
|
|
962
|
+
story: storyName
|
|
963
|
+
});
|
|
964
|
+
const structureRevision = review?.structuresByTarget.get(reviewTargetKey(root, "element", path));
|
|
965
|
+
const blockDecorations = readBlockDecorations(view, root, element, path);
|
|
966
|
+
const textFormat = formats.elementTextFormats.get(element.type);
|
|
967
|
+
if (textFormat) {
|
|
968
|
+
bumpDropped(droppedTextCounts, element.type, textFormat.plugin, textFormat.dropped);
|
|
969
|
+
const voidAnchors = isVoid ? compileVoidTextAnchors(element, root, path, occurrence, rootsUsed) : [];
|
|
970
|
+
const renderedText = textFormat.text({ node: element });
|
|
971
|
+
const blocks = [{
|
|
972
|
+
children: [...voidAnchors, ...renderedText ? [{
|
|
973
|
+
kind: "text",
|
|
974
|
+
text: renderedText
|
|
975
|
+
}] : []],
|
|
976
|
+
kind: "paragraph",
|
|
977
|
+
roots: /* @__PURE__ */ new Set([root])
|
|
978
|
+
}];
|
|
979
|
+
applyElementBlockProps(blocks, blockProps, listItem, structureRevision);
|
|
980
|
+
return blocks;
|
|
981
|
+
}
|
|
982
|
+
const encoder = formats.elementEncoders.get(element.type);
|
|
983
|
+
if (encoder) {
|
|
984
|
+
if (isVoid) coverVoidBlockReviewRuns(element, root, path);
|
|
985
|
+
const ctx = createEncodeContext(element, root, path, occurrence, rootStack, view, encoder, blockDecorations);
|
|
986
|
+
const rawResult = withDocumentViewRead(view, () => encoder.encode(ctx));
|
|
987
|
+
if (rawResult === null || rawResult === void 0) return [];
|
|
988
|
+
const blocks = lowerBlocks(Array.isArray(rawResult) ? rawResult : [rawResult], rootsUsed, root);
|
|
989
|
+
if (isVoid && blocks.length > 0) {
|
|
990
|
+
const voidAnchors = compileVoidTextAnchors(element, root, path, occurrence, rootsUsed);
|
|
991
|
+
if (voidAnchors.length > 0 && blocks[0].kind === "paragraph") blocks[0].children.unshift(...voidAnchors);
|
|
992
|
+
}
|
|
993
|
+
applyElementBlockProps(blocks, blockProps, listItem, structureRevision);
|
|
994
|
+
return blocks;
|
|
995
|
+
}
|
|
996
|
+
diagnostics.push(docxUnsupportedContent({
|
|
997
|
+
action: isVoid ? "dropped" : "unwrapped",
|
|
998
|
+
feature: element.type,
|
|
999
|
+
impact: "lossy",
|
|
1000
|
+
message: `Element "${element.type}" has no DOCX mapping, so it was ${isVoid ? "dropped" : "unwrapped"}.`,
|
|
1001
|
+
path,
|
|
1002
|
+
root
|
|
1003
|
+
}));
|
|
1004
|
+
if (isVoid) return [];
|
|
1005
|
+
if (element.children.some((child) => ElementApi.isElement(child) && !readSchema.isInline(child))) {
|
|
1006
|
+
const blocks = compileBlockList(element.children, root, path, occurrence, rootStack, view, rootsUsed);
|
|
1007
|
+
applyElementBlockProps(blocks, blockProps, listItem, structureRevision);
|
|
1008
|
+
return blocks;
|
|
1009
|
+
}
|
|
1010
|
+
const blocks = [{
|
|
1011
|
+
children: compileInlineList(element.children, root, path, occurrence, rootStack, view, blockDecorations, rootsUsed),
|
|
1012
|
+
kind: "paragraph",
|
|
1013
|
+
roots: /* @__PURE__ */ new Set([root])
|
|
1014
|
+
}];
|
|
1015
|
+
applyElementBlockProps(blocks, blockProps, listItem, structureRevision);
|
|
1016
|
+
return blocks;
|
|
1017
|
+
};
|
|
1018
|
+
const compileBlockList = (nodes, root, parentPath, occurrence, rootStack, view, rootsUsed) => {
|
|
1019
|
+
const out = [];
|
|
1020
|
+
nodes.forEach((child, index) => {
|
|
1021
|
+
const loc = nodeLocations.get(child);
|
|
1022
|
+
const childPath = loc && loc.root === root ? loc.path : [...parentPath, index];
|
|
1023
|
+
if (ElementApi.isElement(child)) {
|
|
1024
|
+
const compiled = compileBlockElement(child, root, childPath, occurrence, rootStack, view, rootsUsed);
|
|
1025
|
+
if (root === MAIN_ROOT_KEY && parentPath.length === 0) {
|
|
1026
|
+
for (const block of compiled) if (block.mainBlockIndex === void 0) block.mainBlockIndex = childPath[0];
|
|
1027
|
+
}
|
|
1028
|
+
out.push(...compiled);
|
|
1029
|
+
} else {
|
|
1030
|
+
const inlines = compileTextLeaf(child, root, childPath, occurrence, view, [], rootsUsed);
|
|
1031
|
+
if (inlines.length > 0) out.push({
|
|
1032
|
+
children: inlines,
|
|
1033
|
+
kind: "paragraph",
|
|
1034
|
+
roots: /* @__PURE__ */ new Set([root])
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
return out;
|
|
1039
|
+
};
|
|
1040
|
+
const topRoots = /* @__PURE__ */ new Set();
|
|
1041
|
+
const mainOccurrence = nextOccurrence(MAIN_ROOT_KEY);
|
|
1042
|
+
const rawBlocks = compileBlockList(storyDocument.children, MAIN_ROOT_KEY, [], mainOccurrence, [MAIN_ROOT_KEY], baseView, topRoots);
|
|
1043
|
+
const extractedFootnotes = storyName === "body" ? extractMainStoryFootnotes(rawBlocks, diagnostics) : {
|
|
1044
|
+
blocks: rawBlocks,
|
|
1045
|
+
footnotes: []
|
|
1046
|
+
};
|
|
1047
|
+
const { blocks } = extractedFootnotes;
|
|
1048
|
+
const emittedReviewRuns = /* @__PURE__ */ new Set();
|
|
1049
|
+
const recordFootnoteReviewRuns = (items) => {
|
|
1050
|
+
const walkInlines = (inlines) => {
|
|
1051
|
+
for (const inline of inlines) if ((inline.kind === "text" || inline.kind === "inlineEquation" || inline.kind === "lineBreak" || inline.kind === "inlineImage" || inline.kind === "footnoteReference") && inline.reviewRun) emittedReviewRuns.add(inline.reviewRun);
|
|
1052
|
+
else if (inline.kind === "link") walkInlines(inline.children);
|
|
1053
|
+
};
|
|
1054
|
+
for (const block of items) {
|
|
1055
|
+
for (const r of block.roots) if (r !== MAIN_ROOT_KEY) renderedRoots.add(r);
|
|
1056
|
+
if (block.kind === "paragraph") walkInlines(block.children);
|
|
1057
|
+
else if (block.kind === "blockImage" && block.caption) walkInlines(block.caption);
|
|
1058
|
+
else if (block.kind === "blockquote") recordFootnoteReviewRuns(block.children);
|
|
1059
|
+
else if (block.kind === "table") for (const row of block.rows) for (const cell of row.cells) recordFootnoteReviewRuns(cell.children);
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
for (const fn of extractedFootnotes.footnotes) recordFootnoteReviewRuns(fn.blocks);
|
|
1063
|
+
const collectEmitted = (blockList, enclosingMainBlock, containerRoots) => {
|
|
1064
|
+
for (const block of blockList) {
|
|
1065
|
+
if (block.kind === "footnoteDefinition") {
|
|
1066
|
+
for (const r of block.roots) if (r !== MAIN_ROOT_KEY) renderedRoots.add(r);
|
|
1067
|
+
recordFootnoteReviewRuns(block.children);
|
|
1068
|
+
continue;
|
|
1069
|
+
}
|
|
1070
|
+
const activeMain = block.mainBlockIndex ?? enclosingMainBlock;
|
|
1071
|
+
const mergedRoots = /* @__PURE__ */ new Set([...containerRoots, ...block.roots]);
|
|
1072
|
+
for (const r of block.roots) if (r !== MAIN_ROOT_KEY) renderedRoots.add(r);
|
|
1073
|
+
if (activeMain !== void 0) {
|
|
1074
|
+
let record = mainBlockRecords.get(activeMain);
|
|
1075
|
+
if (!record) {
|
|
1076
|
+
record = {
|
|
1077
|
+
count: 0,
|
|
1078
|
+
duplicateTextPath: false,
|
|
1079
|
+
hasForeignRoot: false,
|
|
1080
|
+
hasSiblingMainBlock: false,
|
|
1081
|
+
seenTextPaths: /* @__PURE__ */ new Set()
|
|
1082
|
+
};
|
|
1083
|
+
mainBlockRecords.set(activeMain, record);
|
|
1084
|
+
}
|
|
1085
|
+
if (enclosingMainBlock === void 0) {
|
|
1086
|
+
record.count += 1;
|
|
1087
|
+
record.firstBlock ??= block;
|
|
1088
|
+
record.lastBlock = block;
|
|
1089
|
+
}
|
|
1090
|
+
for (const r of block.roots) if (r !== MAIN_ROOT_KEY) record.hasForeignRoot = true;
|
|
1091
|
+
if (block.mainBlockIndex !== void 0 && enclosingMainBlock !== void 0 && block.mainBlockIndex !== enclosingMainBlock) record.hasSiblingMainBlock = true;
|
|
1092
|
+
}
|
|
1093
|
+
const recordInlines = (inlines) => {
|
|
1094
|
+
for (const inline of inlines) {
|
|
1095
|
+
if ((inline.kind === "text" || inline.kind === "inlineEquation" || inline.kind === "lineBreak" || inline.kind === "inlineImage" || inline.kind === "footnoteReference") && inline.reviewRun) emittedReviewRuns.add(inline.reviewRun);
|
|
1096
|
+
if (inline.kind === "text" && inline.provenance) {
|
|
1097
|
+
const p = inline.provenance;
|
|
1098
|
+
if (p.root !== MAIN_ROOT_KEY) renderedRoots.add(p.root);
|
|
1099
|
+
if (textSpans.at(-1)?.root !== p.root || textSpans.at(-1)?.pathKey !== p.pathKey || textSpans.at(-1)?.occurrence !== p.occurrence) {
|
|
1100
|
+
textSpans.push({
|
|
1101
|
+
containerRoots: mergedRoots,
|
|
1102
|
+
length: p.length,
|
|
1103
|
+
occurrence: p.occurrence,
|
|
1104
|
+
order: p.order,
|
|
1105
|
+
path: p.path,
|
|
1106
|
+
pathKey: p.pathKey,
|
|
1107
|
+
root: p.root
|
|
1108
|
+
});
|
|
1109
|
+
if (activeMain !== void 0 && p.root === MAIN_ROOT_KEY) {
|
|
1110
|
+
const record = mainBlockRecords.get(activeMain);
|
|
1111
|
+
if (record) {
|
|
1112
|
+
if (record.seenTextPaths.has(p.pathKey)) record.duplicateTextPath = true;
|
|
1113
|
+
else record.seenTextPaths.add(p.pathKey);
|
|
1114
|
+
const blockOfPath = p.path[0];
|
|
1115
|
+
if (blockOfPath !== void 0 && blockOfPath !== activeMain) record.hasSiblingMainBlock = true;
|
|
1116
|
+
}
|
|
1117
|
+
} else if (activeMain !== void 0 && p.root !== MAIN_ROOT_KEY) {
|
|
1118
|
+
const record = mainBlockRecords.get(activeMain);
|
|
1119
|
+
if (record) record.hasForeignRoot = true;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
} else if (inline.kind === "voidAnchor") {
|
|
1123
|
+
const p = inline.provenance;
|
|
1124
|
+
if (p.root !== MAIN_ROOT_KEY) renderedRoots.add(p.root);
|
|
1125
|
+
textSpans.push({
|
|
1126
|
+
containerRoots: mergedRoots,
|
|
1127
|
+
length: p.length,
|
|
1128
|
+
occurrence: p.occurrence,
|
|
1129
|
+
order: p.order,
|
|
1130
|
+
path: p.path,
|
|
1131
|
+
pathKey: p.pathKey,
|
|
1132
|
+
root: p.root
|
|
1133
|
+
});
|
|
1134
|
+
} else if (inline.kind === "link") recordInlines(inline.children);
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
if (block.kind === "paragraph") recordInlines(block.children);
|
|
1138
|
+
else if (block.kind === "blockImage" && block.caption) recordInlines(block.caption);
|
|
1139
|
+
else if (block.kind === "blockquote") collectEmitted(block.children, activeMain, mergedRoots);
|
|
1140
|
+
else if (block.kind === "table") for (const row of block.rows) for (const cell of row.cells) collectEmitted(cell.children, activeMain, mergedRoots);
|
|
1141
|
+
}
|
|
1142
|
+
};
|
|
1143
|
+
collectEmitted(blocks, void 0, /* @__PURE__ */ new Set());
|
|
1144
|
+
if (review) for (const entry of review.runs) {
|
|
1145
|
+
if (entry.root !== MAIN_ROOT_KEY && !renderedRoots.has(entry.root)) continue;
|
|
1146
|
+
if (!emittedReviewRuns.has(entry.run) && !voidCoveredReviewRuns.has(entry.run)) diagnostics.push(docxUnsupportedContent({
|
|
1147
|
+
action: "dropped",
|
|
1148
|
+
feature: "review-text-wrapper",
|
|
1149
|
+
impact: "lossy",
|
|
1150
|
+
message: "A review run could not be attached because its custom DOCX encoder omitted text provenance.",
|
|
1151
|
+
path: entry.path,
|
|
1152
|
+
root: entry.root
|
|
1153
|
+
}));
|
|
1154
|
+
}
|
|
1155
|
+
for (const entry of droppedTextCounts.values()) diagnostics.push(docxPropertyDropped({
|
|
1156
|
+
count: entry.count,
|
|
1157
|
+
feature: entry.plugin,
|
|
1158
|
+
message: entry.dropped
|
|
1159
|
+
}));
|
|
1160
|
+
for (const entry of droppedMarkCounts.values()) diagnostics.push(docxPropertyDropped({
|
|
1161
|
+
count: entry.count,
|
|
1162
|
+
feature: entry.plugin,
|
|
1163
|
+
message: entry.dropped
|
|
1164
|
+
}));
|
|
1165
|
+
for (const entry of droppedPropertyCounts.values()) diagnostics.push(docxPropertyDropped({
|
|
1166
|
+
count: entry.count,
|
|
1167
|
+
feature: entry.plugin,
|
|
1168
|
+
message: entry.dropped
|
|
1169
|
+
}));
|
|
1170
|
+
return {
|
|
1171
|
+
blocks,
|
|
1172
|
+
diagnostics,
|
|
1173
|
+
footnotes: extractedFootnotes.footnotes,
|
|
1174
|
+
mainBlockRecords,
|
|
1175
|
+
renderedRoots,
|
|
1176
|
+
textSpans
|
|
1177
|
+
};
|
|
1178
|
+
};
|
|
1179
|
+
const spanKey = (root, pathKey, occurrence) => `${root}\0${pathKey}\0${occurrence}`;
|
|
1180
|
+
const anchorCommentsOnAst = (blocks, textSpans, comments, diagnostics) => {
|
|
1181
|
+
if (comments.length === 0) return [];
|
|
1182
|
+
const spansByRootAndPath = /* @__PURE__ */ new Map();
|
|
1183
|
+
for (const span of textSpans) {
|
|
1184
|
+
const key = `${span.root}\0${span.pathKey}`;
|
|
1185
|
+
const list = spansByRootAndPath.get(key) ?? [];
|
|
1186
|
+
list.push(span);
|
|
1187
|
+
spansByRootAndPath.set(key, list);
|
|
1188
|
+
}
|
|
1189
|
+
const hasUnownedSpanBetween = (startSpan, endSpan, root) => {
|
|
1190
|
+
if (root === MAIN_ROOT_KEY) return false;
|
|
1191
|
+
for (const span of textSpans) if (span.order > startSpan.order && span.order < endSpan.order && span.root !== root) return true;
|
|
1192
|
+
return false;
|
|
1193
|
+
};
|
|
1194
|
+
const resolveEndpoints = (start, end) => {
|
|
1195
|
+
const startRoot = start.root ?? MAIN_ROOT_KEY;
|
|
1196
|
+
const endRoot = end.root ?? MAIN_ROOT_KEY;
|
|
1197
|
+
const startPath = start.path.join(",");
|
|
1198
|
+
const endPath = end.path.join(",");
|
|
1199
|
+
const startSpans = spansByRootAndPath.get(`${startRoot}\0${startPath}`) ?? [];
|
|
1200
|
+
if (startSpans.length === 0) return null;
|
|
1201
|
+
if (startRoot === endRoot && startPath === endPath) return [startSpans[0], startSpans[0]];
|
|
1202
|
+
const endSpans = spansByRootAndPath.get(`${endRoot}\0${endPath}`) ?? [];
|
|
1203
|
+
for (const startSpan of startSpans) {
|
|
1204
|
+
const endSpan = endSpans.find((candidate) => candidate.occurrence === startSpan.occurrence && candidate.order > startSpan.order && !hasUnownedSpanBetween(startSpan, candidate, startRoot));
|
|
1205
|
+
if (endSpan) return [startSpan, endSpan];
|
|
1206
|
+
}
|
|
1207
|
+
return null;
|
|
1208
|
+
};
|
|
1209
|
+
const markersBySpan = /* @__PURE__ */ new Map();
|
|
1210
|
+
const groupAt = (span, offset) => {
|
|
1211
|
+
const key = spanKey(span.root, span.pathKey, span.occurrence);
|
|
1212
|
+
let byOffset = markersBySpan.get(key);
|
|
1213
|
+
if (!byOffset) {
|
|
1214
|
+
byOffset = /* @__PURE__ */ new Map();
|
|
1215
|
+
markersBySpan.set(key, byOffset);
|
|
1216
|
+
}
|
|
1217
|
+
let group = byOffset.get(offset);
|
|
1218
|
+
if (!group) {
|
|
1219
|
+
group = {
|
|
1220
|
+
collapsed: [],
|
|
1221
|
+
ends: [],
|
|
1222
|
+
starts: []
|
|
1223
|
+
};
|
|
1224
|
+
byOffset.set(offset, group);
|
|
1225
|
+
}
|
|
1226
|
+
return group;
|
|
1227
|
+
};
|
|
1228
|
+
const prepared = [];
|
|
1229
|
+
for (const comment of comments) {
|
|
1230
|
+
if (!comment.target) {
|
|
1231
|
+
diagnostics.push(docxLossyContent({
|
|
1232
|
+
feature: "comment-range",
|
|
1233
|
+
message: `Comment ${comment.id} has no exportable range.`,
|
|
1234
|
+
sourceId: comment.id
|
|
1235
|
+
}));
|
|
1236
|
+
continue;
|
|
1237
|
+
}
|
|
1238
|
+
const start = RangeApi.start(comment.target.range);
|
|
1239
|
+
const end = RangeApi.end(comment.target.range);
|
|
1240
|
+
const endpoints = resolveEndpoints(start, end);
|
|
1241
|
+
if (!endpoints) {
|
|
1242
|
+
diagnostics.push(docxLossyContent({
|
|
1243
|
+
feature: "comment-range",
|
|
1244
|
+
message: `Comment ${comment.id} addresses content outside the selected DOCX projection.`,
|
|
1245
|
+
sourceId: comment.id
|
|
1246
|
+
}));
|
|
1247
|
+
continue;
|
|
1248
|
+
}
|
|
1249
|
+
const [startSpan, endSpan] = endpoints;
|
|
1250
|
+
const validStart = Number.isSafeInteger(start.offset) && start.offset >= 0 && start.offset <= startSpan.length;
|
|
1251
|
+
const validEnd = Number.isSafeInteger(end.offset) && end.offset >= 0 && end.offset <= endSpan.length;
|
|
1252
|
+
if (!validStart || !validEnd || startSpan === endSpan && start.offset > end.offset) {
|
|
1253
|
+
diagnostics.push(docxLossyContent({
|
|
1254
|
+
feature: "comment-range",
|
|
1255
|
+
message: `Comment ${comment.id} has an invalid text offset.`,
|
|
1256
|
+
sourceId: comment.id
|
|
1257
|
+
}));
|
|
1258
|
+
continue;
|
|
1259
|
+
}
|
|
1260
|
+
const id = prepared.length;
|
|
1261
|
+
const paragraphId = (id + 1).toString(16).padStart(8, "0");
|
|
1262
|
+
const startMarker = {
|
|
1263
|
+
id,
|
|
1264
|
+
kind: "commentRangeStart"
|
|
1265
|
+
};
|
|
1266
|
+
const endMarker = {
|
|
1267
|
+
id,
|
|
1268
|
+
kind: "commentRangeEnd"
|
|
1269
|
+
};
|
|
1270
|
+
if (startSpan === endSpan && start.offset === end.offset) groupAt(startSpan, start.offset).collapsed.push(startMarker, endMarker);
|
|
1271
|
+
else {
|
|
1272
|
+
groupAt(endSpan, end.offset).ends.push(endMarker);
|
|
1273
|
+
groupAt(startSpan, start.offset).starts.push(startMarker);
|
|
1274
|
+
}
|
|
1275
|
+
prepared.push({
|
|
1276
|
+
comment,
|
|
1277
|
+
id,
|
|
1278
|
+
paragraphId
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
if (markersBySpan.size === 0) return prepared;
|
|
1282
|
+
const spliceInlines = (inlines) => {
|
|
1283
|
+
const out = [];
|
|
1284
|
+
for (const inline of inlines) {
|
|
1285
|
+
if (inline.kind === "link") {
|
|
1286
|
+
out.push({
|
|
1287
|
+
...inline,
|
|
1288
|
+
children: spliceInlines(inline.children)
|
|
1289
|
+
});
|
|
1290
|
+
continue;
|
|
1291
|
+
}
|
|
1292
|
+
if (inline.kind === "voidAnchor") {
|
|
1293
|
+
const key = spanKey(inline.provenance.root, inline.provenance.pathKey, inline.provenance.occurrence);
|
|
1294
|
+
const byOffset = markersBySpan.get(key);
|
|
1295
|
+
if (byOffset) {
|
|
1296
|
+
const group = byOffset.get(0);
|
|
1297
|
+
if (group) {
|
|
1298
|
+
out.push(...group.ends, ...group.collapsed, ...group.starts);
|
|
1299
|
+
byOffset.delete(0);
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
continue;
|
|
1303
|
+
}
|
|
1304
|
+
if (inline.kind === "text" && inline.provenance) {
|
|
1305
|
+
const key = spanKey(inline.provenance.root, inline.provenance.pathKey, inline.provenance.occurrence);
|
|
1306
|
+
const byOffset = markersBySpan.get(key);
|
|
1307
|
+
if (!byOffset || byOffset.size === 0) {
|
|
1308
|
+
out.push(inline);
|
|
1309
|
+
continue;
|
|
1310
|
+
}
|
|
1311
|
+
const sliceStart = inline.sliceStart ?? 0;
|
|
1312
|
+
const sliceEnd = inline.sliceEnd ?? inline.text.length;
|
|
1313
|
+
const relevantOffsets = [...byOffset.keys()].filter((offset) => offset >= sliceStart && offset <= sliceEnd).sort((a, b) => a - b);
|
|
1314
|
+
if (relevantOffsets.length === 0) {
|
|
1315
|
+
out.push(inline);
|
|
1316
|
+
continue;
|
|
1317
|
+
}
|
|
1318
|
+
let cursor = sliceStart;
|
|
1319
|
+
for (const offset of relevantOffsets) {
|
|
1320
|
+
if (offset > cursor) {
|
|
1321
|
+
out.push({
|
|
1322
|
+
...inline,
|
|
1323
|
+
sliceEnd: offset,
|
|
1324
|
+
sliceStart: cursor,
|
|
1325
|
+
text: inline.text.slice(cursor - sliceStart, offset - sliceStart)
|
|
1326
|
+
});
|
|
1327
|
+
cursor = offset;
|
|
1328
|
+
}
|
|
1329
|
+
const group = byOffset.get(offset);
|
|
1330
|
+
if (group) {
|
|
1331
|
+
out.push(...group.ends, ...group.collapsed, ...group.starts);
|
|
1332
|
+
byOffset.delete(offset);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
if (cursor < sliceEnd || sliceStart === sliceEnd && inline.text === "") {
|
|
1336
|
+
const remaining = inline.text.slice(cursor - sliceStart);
|
|
1337
|
+
if (remaining.length > 0 || sliceStart === sliceEnd && inline.text === "") out.push({
|
|
1338
|
+
...inline,
|
|
1339
|
+
sliceEnd,
|
|
1340
|
+
sliceStart: cursor,
|
|
1341
|
+
text: remaining
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
continue;
|
|
1345
|
+
}
|
|
1346
|
+
out.push(inline);
|
|
1347
|
+
}
|
|
1348
|
+
return out;
|
|
1349
|
+
};
|
|
1350
|
+
const spliceBlocks = (list) => {
|
|
1351
|
+
for (const block of list) if (block.kind === "paragraph") block.children = spliceInlines(block.children);
|
|
1352
|
+
else if (block.kind === "blockImage" && block.caption) block.caption = spliceInlines(block.caption);
|
|
1353
|
+
else if (block.kind === "blockquote") spliceBlocks(block.children);
|
|
1354
|
+
else if (block.kind === "table") for (const row of block.rows) for (const cell of row.cells) spliceBlocks(cell.children);
|
|
1355
|
+
};
|
|
1356
|
+
spliceBlocks(blocks);
|
|
1357
|
+
return prepared;
|
|
1358
|
+
};
|
|
1359
|
+
const attachReviewBindings = (review, mainBlockRecords, diagnostics) => {
|
|
1360
|
+
if (!review) return [];
|
|
1361
|
+
const bindings = [];
|
|
1362
|
+
for (const blockIndex of review.bound) {
|
|
1363
|
+
const record = mainBlockRecords.get(blockIndex);
|
|
1364
|
+
if (!record || !record.firstBlock || !record.lastBlock) {
|
|
1365
|
+
diagnostics.push(docxLossyContent({
|
|
1366
|
+
feature: "authored-review",
|
|
1367
|
+
message: `The review marks of block ${blockIndex} have no rendered host to bind them to.`,
|
|
1368
|
+
path: [blockIndex]
|
|
1369
|
+
}));
|
|
1370
|
+
continue;
|
|
1371
|
+
}
|
|
1372
|
+
if (record.count > 1 || record.duplicateTextPath || record.hasForeignRoot || record.hasSiblingMainBlock) continue;
|
|
1373
|
+
const name = `_ReviewBlock${bindings.length + 1}`;
|
|
1374
|
+
record.firstBlock.reviewBlockStart = [...record.firstBlock.reviewBlockStart ?? [], name];
|
|
1375
|
+
record.lastBlock.reviewBlockEnd = [...record.lastBlock.reviewBlockEnd ?? [], name];
|
|
1376
|
+
bindings.push({
|
|
1377
|
+
name,
|
|
1378
|
+
nodes: [review.stored.children[blockIndex]]
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
return bindings;
|
|
1382
|
+
};
|
|
1383
|
+
const splitNewlinesInText = (inline) => {
|
|
1384
|
+
const { lookMarks, marks, placeholder, reviewRun, text } = inline;
|
|
1385
|
+
if (!text.includes("\n")) return [{
|
|
1386
|
+
kind: "text",
|
|
1387
|
+
...lookMarks ? { lookMarks } : {},
|
|
1388
|
+
...marks ? { marks } : {},
|
|
1389
|
+
...placeholder !== void 0 ? { placeholder } : {},
|
|
1390
|
+
...reviewRun ? { reviewRun } : {},
|
|
1391
|
+
text
|
|
1392
|
+
}];
|
|
1393
|
+
const parts = text.split("\n");
|
|
1394
|
+
const out = [];
|
|
1395
|
+
parts.forEach((part, index) => {
|
|
1396
|
+
if (part.length > 0 || parts.length === 1) out.push({
|
|
1397
|
+
kind: "text",
|
|
1398
|
+
...lookMarks ? { lookMarks } : {},
|
|
1399
|
+
...marks ? { marks } : {},
|
|
1400
|
+
...placeholder !== void 0 ? { placeholder } : {},
|
|
1401
|
+
...reviewRun ? { reviewRun } : {},
|
|
1402
|
+
text: part
|
|
1403
|
+
});
|
|
1404
|
+
if (index < parts.length - 1) out.push({
|
|
1405
|
+
kind: "lineBreak",
|
|
1406
|
+
...reviewRun ? { reviewRun } : {}
|
|
1407
|
+
});
|
|
1408
|
+
});
|
|
1409
|
+
return out;
|
|
1410
|
+
};
|
|
1411
|
+
const hasPlainText = (inlines) => inlines.some((inline) => {
|
|
1412
|
+
if (inline.kind === "text") return inline.text.trim().length > 0;
|
|
1413
|
+
if (inline.kind === "link") return hasPlainText(inline.children);
|
|
1414
|
+
return false;
|
|
1415
|
+
});
|
|
1416
|
+
const resolveInlinesAsync = async (inlines, options, diagnostics) => {
|
|
1417
|
+
const out = [];
|
|
1418
|
+
for (const inline of inlines) {
|
|
1419
|
+
throwIfDocxAborted(options.signal);
|
|
1420
|
+
switch (inline.kind) {
|
|
1421
|
+
case "voidAnchor": break;
|
|
1422
|
+
case "text":
|
|
1423
|
+
out.push(...splitNewlinesInText(inline));
|
|
1424
|
+
break;
|
|
1425
|
+
case "footnoteReference":
|
|
1426
|
+
if (inline.id !== void 0) out.push({
|
|
1427
|
+
id: inline.id,
|
|
1428
|
+
kind: "footnoteReference",
|
|
1429
|
+
ref: inline.ref,
|
|
1430
|
+
...inline.reviewRun ? { reviewRun: inline.reviewRun } : {}
|
|
1431
|
+
});
|
|
1432
|
+
else {
|
|
1433
|
+
diagnostics.push(docxLossyContent({
|
|
1434
|
+
feature: "footnote",
|
|
1435
|
+
message: `Footnote reference "${inline.ref}" has no matching definition in the document body and was exported as plain text.`
|
|
1436
|
+
}));
|
|
1437
|
+
out.push({
|
|
1438
|
+
kind: "text",
|
|
1439
|
+
marks: { script: "sup" },
|
|
1440
|
+
...inline.reviewRun ? { reviewRun: inline.reviewRun } : {},
|
|
1441
|
+
text: `[${inline.ref}]`
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
break;
|
|
1445
|
+
case "lineBreak":
|
|
1446
|
+
out.push({
|
|
1447
|
+
kind: "lineBreak",
|
|
1448
|
+
...inline.reviewRun ? { reviewRun: inline.reviewRun } : {}
|
|
1449
|
+
});
|
|
1450
|
+
break;
|
|
1451
|
+
case "commentRangeStart":
|
|
1452
|
+
case "commentRangeEnd":
|
|
1453
|
+
case "bookmarkStart":
|
|
1454
|
+
case "bookmarkEnd":
|
|
1455
|
+
out.push(inline);
|
|
1456
|
+
break;
|
|
1457
|
+
case "link": {
|
|
1458
|
+
const resolvedChildren = await resolveInlinesAsync(inline.children, options, diagnostics);
|
|
1459
|
+
const link = resolveDocxLinkUrl(inline.url);
|
|
1460
|
+
if (link.kind === "unwrapped") {
|
|
1461
|
+
if (link.diagnostic) diagnostics.push(link.diagnostic);
|
|
1462
|
+
out.push(...resolvedChildren);
|
|
1463
|
+
} else out.push({
|
|
1464
|
+
children: resolvedChildren,
|
|
1465
|
+
kind: "link",
|
|
1466
|
+
target: link.target,
|
|
1467
|
+
targetKind: link.kind
|
|
1468
|
+
});
|
|
1469
|
+
break;
|
|
1470
|
+
}
|
|
1471
|
+
case "inlineEquation": {
|
|
1472
|
+
const { omml } = await renderLatexToOmml(inline.latex, "inline");
|
|
1473
|
+
throwIfDocxAborted(options.signal);
|
|
1474
|
+
out.push({
|
|
1475
|
+
kind: "inlineEquation",
|
|
1476
|
+
latex: inline.latex,
|
|
1477
|
+
omml,
|
|
1478
|
+
...inline.reviewRun ? { reviewRun: inline.reviewRun } : {}
|
|
1479
|
+
});
|
|
1480
|
+
break;
|
|
1481
|
+
}
|
|
1482
|
+
case "inlineImage": {
|
|
1483
|
+
const resolution = await resolveDocxImage(inline.url, options);
|
|
1484
|
+
if (resolution.ok) out.push({
|
|
1485
|
+
...inline.alt !== void 0 ? { alt: inline.alt } : {},
|
|
1486
|
+
...inline.heightPx !== void 0 ? { heightPx: inline.heightPx } : {},
|
|
1487
|
+
image: resolution.image,
|
|
1488
|
+
kind: "inlineImage",
|
|
1489
|
+
...inline.reviewRun ? { reviewRun: inline.reviewRun } : {},
|
|
1490
|
+
...inline.widthPx !== void 0 ? { widthPx: inline.widthPx } : {}
|
|
1491
|
+
});
|
|
1492
|
+
else {
|
|
1493
|
+
const alt = inline.alt?.trim() ?? "";
|
|
1494
|
+
diagnostics.push(docxResourceOmitted({
|
|
1495
|
+
feature: "image",
|
|
1496
|
+
impact: resolution.unsafeScript && alt.length > 0 ? "lossless" : "lossy",
|
|
1497
|
+
message: `An image was omitted because ${resolution.reason}.`
|
|
1498
|
+
}));
|
|
1499
|
+
if (alt.length > 0) out.push({
|
|
1500
|
+
kind: "text",
|
|
1501
|
+
...inline.reviewRun ? { reviewRun: inline.reviewRun } : {},
|
|
1502
|
+
text: alt
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
break;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
return out;
|
|
1510
|
+
};
|
|
1511
|
+
const resolveBlocksAsync = async (blocks, options, diagnostics) => {
|
|
1512
|
+
const out = [];
|
|
1513
|
+
for (const block of blocks) {
|
|
1514
|
+
throwIfDocxAborted(options.signal);
|
|
1515
|
+
const common = {
|
|
1516
|
+
...block.isCheckedTaskContinuation ? { isCheckedTaskContinuation: true } : {},
|
|
1517
|
+
...block.listItem ? { listItem: block.listItem } : {},
|
|
1518
|
+
...block.reviewBlockStart ? { reviewBlockStart: block.reviewBlockStart } : {},
|
|
1519
|
+
...block.reviewBlockEnd ? { reviewBlockEnd: block.reviewBlockEnd } : {}
|
|
1520
|
+
};
|
|
1521
|
+
switch (block.kind) {
|
|
1522
|
+
case "paragraph": {
|
|
1523
|
+
const children = await resolveInlinesAsync(block.children, options, diagnostics);
|
|
1524
|
+
out.push({
|
|
1525
|
+
...common,
|
|
1526
|
+
...block.align !== void 0 ? { align: block.align } : {},
|
|
1527
|
+
...block.bookmark !== void 0 ? { bookmark: block.bookmark } : {},
|
|
1528
|
+
children,
|
|
1529
|
+
...block.codeLanguage !== void 0 ? { codeLanguage: block.codeLanguage } : {},
|
|
1530
|
+
...block.indentPx !== void 0 ? { indentPx: block.indentPx } : {},
|
|
1531
|
+
...block.isCodeBlock ? { isCodeBlock: true } : {},
|
|
1532
|
+
kind: "paragraph",
|
|
1533
|
+
...block.lineHeight !== void 0 ? { lineHeight: block.lineHeight } : {},
|
|
1534
|
+
...block.preserveWhitespace ? { preserveWhitespace: true } : {},
|
|
1535
|
+
...block.structureRevision ? { structureRevision: block.structureRevision } : {},
|
|
1536
|
+
...block.style !== void 0 ? { style: block.style } : {}
|
|
1537
|
+
});
|
|
1538
|
+
break;
|
|
1539
|
+
}
|
|
1540
|
+
case "horizontalRule":
|
|
1541
|
+
out.push({
|
|
1542
|
+
...common,
|
|
1543
|
+
kind: "horizontalRule"
|
|
1544
|
+
});
|
|
1545
|
+
break;
|
|
1546
|
+
case "pageBreak":
|
|
1547
|
+
out.push({
|
|
1548
|
+
...common,
|
|
1549
|
+
kind: "pageBreak"
|
|
1550
|
+
});
|
|
1551
|
+
break;
|
|
1552
|
+
case "blockquote": {
|
|
1553
|
+
const children = await resolveBlocksAsync(block.children, options, diagnostics);
|
|
1554
|
+
out.push({
|
|
1555
|
+
...common,
|
|
1556
|
+
children,
|
|
1557
|
+
kind: "blockquote"
|
|
1558
|
+
});
|
|
1559
|
+
break;
|
|
1560
|
+
}
|
|
1561
|
+
case "footnoteDefinition": {
|
|
1562
|
+
diagnostics.push(docxLossyContent({
|
|
1563
|
+
feature: "footnote",
|
|
1564
|
+
message: `Unreferenced footnote definition "${block.ref}" was flattened into body paragraphs.`
|
|
1565
|
+
}));
|
|
1566
|
+
const children = await resolveBlocksAsync(block.children, options, diagnostics);
|
|
1567
|
+
out.push({
|
|
1568
|
+
...common,
|
|
1569
|
+
children: [{
|
|
1570
|
+
kind: "text",
|
|
1571
|
+
text: block.ref
|
|
1572
|
+
}],
|
|
1573
|
+
kind: "paragraph"
|
|
1574
|
+
}, ...children);
|
|
1575
|
+
break;
|
|
1576
|
+
}
|
|
1577
|
+
case "blockEquation": {
|
|
1578
|
+
const { omml } = await renderLatexToOmml(block.latex, "block");
|
|
1579
|
+
throwIfDocxAborted(options.signal);
|
|
1580
|
+
out.push({
|
|
1581
|
+
...common,
|
|
1582
|
+
kind: "blockEquation",
|
|
1583
|
+
latex: block.latex,
|
|
1584
|
+
omml
|
|
1585
|
+
});
|
|
1586
|
+
break;
|
|
1587
|
+
}
|
|
1588
|
+
case "blockImage": {
|
|
1589
|
+
const caption = block.caption ? await resolveInlinesAsync(block.caption, options, diagnostics) : void 0;
|
|
1590
|
+
const resolution = await resolveDocxImage(block.url, options);
|
|
1591
|
+
if (resolution.ok) out.push({
|
|
1592
|
+
...common,
|
|
1593
|
+
...block.alt !== void 0 ? { alt: block.alt } : {},
|
|
1594
|
+
...caption && caption.length > 0 ? { caption } : {},
|
|
1595
|
+
...block.heightPx !== void 0 ? { heightPx: block.heightPx } : {},
|
|
1596
|
+
image: resolution.image,
|
|
1597
|
+
kind: "blockImage",
|
|
1598
|
+
...block.widthPx !== void 0 ? { widthPx: block.widthPx } : {}
|
|
1599
|
+
});
|
|
1600
|
+
else {
|
|
1601
|
+
const alt = block.alt?.trim() ?? "";
|
|
1602
|
+
const hasSurvivingText = caption !== void 0 && hasPlainText(caption) || alt.length > 0;
|
|
1603
|
+
diagnostics.push(docxResourceOmitted({
|
|
1604
|
+
feature: "image",
|
|
1605
|
+
impact: resolution.unsafeScript && hasSurvivingText ? "lossless" : "lossy",
|
|
1606
|
+
message: `An image was omitted because ${resolution.reason}.`
|
|
1607
|
+
}));
|
|
1608
|
+
const fallbackBlocks = [];
|
|
1609
|
+
if (alt.length > 0) fallbackBlocks.push({
|
|
1610
|
+
children: [{
|
|
1611
|
+
kind: "text",
|
|
1612
|
+
text: alt
|
|
1613
|
+
}],
|
|
1614
|
+
kind: "paragraph"
|
|
1615
|
+
});
|
|
1616
|
+
if (caption && caption.length > 0) fallbackBlocks.push({
|
|
1617
|
+
children: caption,
|
|
1618
|
+
kind: "paragraph"
|
|
1619
|
+
});
|
|
1620
|
+
const first = fallbackBlocks[0];
|
|
1621
|
+
const last = fallbackBlocks.at(-1);
|
|
1622
|
+
if (first && last) {
|
|
1623
|
+
fallbackBlocks[0] = {
|
|
1624
|
+
...first,
|
|
1625
|
+
...common.listItem ? { listItem: common.listItem } : {},
|
|
1626
|
+
...common.reviewBlockStart ? { reviewBlockStart: common.reviewBlockStart } : {}
|
|
1627
|
+
};
|
|
1628
|
+
fallbackBlocks[fallbackBlocks.length - 1] = {
|
|
1629
|
+
...last,
|
|
1630
|
+
...common.reviewBlockEnd ? { reviewBlockEnd: common.reviewBlockEnd } : {}
|
|
1631
|
+
};
|
|
1632
|
+
out.push(...fallbackBlocks);
|
|
1633
|
+
} else if (common.listItem || common.reviewBlockStart || common.reviewBlockEnd) out.push({
|
|
1634
|
+
...common,
|
|
1635
|
+
children: [],
|
|
1636
|
+
kind: "paragraph"
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
break;
|
|
1640
|
+
}
|
|
1641
|
+
case "table": {
|
|
1642
|
+
const rows = [];
|
|
1643
|
+
for (const row of block.rows) {
|
|
1644
|
+
const cells = [];
|
|
1645
|
+
for (const cell of row.cells) {
|
|
1646
|
+
const children = await resolveBlocksAsync(cell.children, options, diagnostics);
|
|
1647
|
+
cells.push({
|
|
1648
|
+
...cell.backgroundColor !== void 0 ? { backgroundColor: cell.backgroundColor } : {},
|
|
1649
|
+
...cell.borders !== void 0 ? { borders: cell.borders } : {},
|
|
1650
|
+
children,
|
|
1651
|
+
...cell.colSpan !== void 0 ? { colSpan: cell.colSpan } : {},
|
|
1652
|
+
...cell.header ? { header: true } : {},
|
|
1653
|
+
...cell.isCalloutIcon ? { isCalloutIcon: true } : {},
|
|
1654
|
+
...cell.rowSpan !== void 0 ? { rowSpan: cell.rowSpan } : {},
|
|
1655
|
+
...cell.verticalAlign !== void 0 ? { verticalAlign: cell.verticalAlign } : {},
|
|
1656
|
+
...cell.widthPct !== void 0 ? { widthPct: cell.widthPct } : {},
|
|
1657
|
+
...cell.widthPx !== void 0 ? { widthPx: cell.widthPx } : {}
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
rows.push({
|
|
1661
|
+
cells,
|
|
1662
|
+
...row.header ? { header: true } : {},
|
|
1663
|
+
...row.minHeightPx !== void 0 ? { minHeightPx: row.minHeightPx } : {}
|
|
1664
|
+
});
|
|
1665
|
+
}
|
|
1666
|
+
out.push({
|
|
1667
|
+
...common,
|
|
1668
|
+
...block.borders !== void 0 ? { borders: block.borders } : {},
|
|
1669
|
+
...block.columnWidthsPx !== void 0 ? { columnWidthsPx: block.columnWidthsPx } : {},
|
|
1670
|
+
...block.isCallout ? { isCallout: true } : {},
|
|
1671
|
+
kind: "table",
|
|
1672
|
+
...block.marginLeftPx !== void 0 ? { marginLeftPx: block.marginLeftPx } : {},
|
|
1673
|
+
rows
|
|
1674
|
+
});
|
|
1675
|
+
break;
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
return out;
|
|
1680
|
+
};
|
|
1681
|
+
const POSITIVE_INT_REF_RE = /^[1-9]\d*$/;
|
|
1682
|
+
const extractMainStoryFootnotes = (blocks, diagnostics) => {
|
|
1683
|
+
const defByRef = /* @__PURE__ */ new Map();
|
|
1684
|
+
const collectDefinitions = (items) => {
|
|
1685
|
+
for (const block of items) if (block.kind === "footnoteDefinition") {
|
|
1686
|
+
if (block.ref && !defByRef.has(block.ref)) defByRef.set(block.ref, block);
|
|
1687
|
+
} else if (block.kind === "blockquote") collectDefinitions(block.children);
|
|
1688
|
+
else if (block.kind === "table") for (const row of block.rows) for (const cell of row.cells) collectDefinitions(cell.children);
|
|
1689
|
+
};
|
|
1690
|
+
collectDefinitions(blocks);
|
|
1691
|
+
if (defByRef.size === 0) return {
|
|
1692
|
+
blocks: [...blocks],
|
|
1693
|
+
footnotes: []
|
|
1694
|
+
};
|
|
1695
|
+
const usedIds = /* @__PURE__ */ new Set();
|
|
1696
|
+
const referencedDefs = /* @__PURE__ */ new Set();
|
|
1697
|
+
const refCounts = /* @__PURE__ */ new Map();
|
|
1698
|
+
const footnotes = [];
|
|
1699
|
+
const allocateId = (ref) => {
|
|
1700
|
+
if (POSITIVE_INT_REF_RE.test(ref)) {
|
|
1701
|
+
const parsed = Number.parseInt(ref, 10);
|
|
1702
|
+
if (Number.isSafeInteger(parsed) && parsed > 0 && !usedIds.has(parsed)) {
|
|
1703
|
+
usedIds.add(parsed);
|
|
1704
|
+
return parsed;
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
let candidate = 1;
|
|
1708
|
+
while (usedIds.has(candidate)) candidate += 1;
|
|
1709
|
+
usedIds.add(candidate);
|
|
1710
|
+
return candidate;
|
|
1711
|
+
};
|
|
1712
|
+
const bindInlines = (inlines) => {
|
|
1713
|
+
for (const inline of inlines) if (inline.kind === "footnoteReference") {
|
|
1714
|
+
const def = defByRef.get(inline.ref);
|
|
1715
|
+
if (def) {
|
|
1716
|
+
const priorCount = refCounts.get(inline.ref) ?? 0;
|
|
1717
|
+
refCounts.set(inline.ref, priorCount + 1);
|
|
1718
|
+
if (priorCount === 1) diagnostics.push(docxLossyContent({
|
|
1719
|
+
feature: "footnote",
|
|
1720
|
+
message: `Footnote "${inline.ref}" was referenced multiple times and exported as separate Word footnotes.`
|
|
1721
|
+
}));
|
|
1722
|
+
const id = allocateId(inline.ref);
|
|
1723
|
+
inline.id = id;
|
|
1724
|
+
referencedDefs.add(def);
|
|
1725
|
+
footnotes.push({
|
|
1726
|
+
blocks: def.children,
|
|
1727
|
+
id,
|
|
1728
|
+
ref: inline.ref
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
} else if (inline.kind === "link") bindInlines(inline.children);
|
|
1732
|
+
};
|
|
1733
|
+
const bindBlocks = (items) => {
|
|
1734
|
+
const out = [];
|
|
1735
|
+
for (const block of items) {
|
|
1736
|
+
if (block.kind === "footnoteDefinition") {
|
|
1737
|
+
out.push(block);
|
|
1738
|
+
continue;
|
|
1739
|
+
}
|
|
1740
|
+
if (block.kind === "paragraph") bindInlines(block.children);
|
|
1741
|
+
else if (block.kind === "blockImage" && block.caption) bindInlines(block.caption);
|
|
1742
|
+
else if (block.kind === "blockquote") block.children = bindBlocks(block.children);
|
|
1743
|
+
else if (block.kind === "table") for (const row of block.rows) for (const cell of row.cells) cell.children = bindBlocks(cell.children);
|
|
1744
|
+
out.push(block);
|
|
1745
|
+
}
|
|
1746
|
+
return out;
|
|
1747
|
+
};
|
|
1748
|
+
const pruneReferencedDefs = (items) => {
|
|
1749
|
+
const out = [];
|
|
1750
|
+
for (const block of items) {
|
|
1751
|
+
if (block.kind === "footnoteDefinition") {
|
|
1752
|
+
if (referencedDefs.has(block)) continue;
|
|
1753
|
+
out.push(block);
|
|
1754
|
+
continue;
|
|
1755
|
+
}
|
|
1756
|
+
if (block.kind === "blockquote") block.children = pruneReferencedDefs(block.children);
|
|
1757
|
+
else if (block.kind === "table") for (const row of block.rows) for (const cell of row.cells) cell.children = pruneReferencedDefs(cell.children);
|
|
1758
|
+
out.push(block);
|
|
1759
|
+
}
|
|
1760
|
+
return out;
|
|
1761
|
+
};
|
|
1762
|
+
return {
|
|
1763
|
+
blocks: pruneReferencedDefs(bindBlocks(blocks)),
|
|
1764
|
+
footnotes
|
|
1765
|
+
};
|
|
1766
|
+
};
|
|
1767
|
+
/**
|
|
1768
|
+
* Compile one captured editor document and its comment bodies synchronously
|
|
1769
|
+
* through plugin `formats.docx` encoders, then resolve async resources
|
|
1770
|
+
* (images and KaTeX OMML equations) into a `CompiledDocxDocument`.
|
|
1771
|
+
*/
|
|
1772
|
+
const compileDocxDocument = async (editor, { allowRemoteImages = false, comments, document, review, signal, styles }) => {
|
|
1773
|
+
const formats = collectDocxFormats(editor);
|
|
1774
|
+
const diagnostics = [...review?.diagnostics ?? []];
|
|
1775
|
+
const mainStory = compileStorySync(editor, document, "body", formats, styles, review, diagnostics);
|
|
1776
|
+
const anchoredComments = anchorCommentsOnAst(mainStory.blocks, mainStory.textSpans, comments, diagnostics);
|
|
1777
|
+
const reviewBindings = attachReviewBindings(review, mainStory.mainBlockRecords, diagnostics);
|
|
1778
|
+
const pendingCommentStories = anchoredComments.map((entry) => ({
|
|
1779
|
+
...entry,
|
|
1780
|
+
story: compileStorySync(editor, { children: entry.comment.body }, `comment:${entry.comment.id}`, formats, styles, void 0, diagnostics)
|
|
1781
|
+
}));
|
|
1782
|
+
throwIfDocxAborted(signal);
|
|
1783
|
+
const resolveOptions = {
|
|
1784
|
+
allowRemoteImages,
|
|
1785
|
+
signal
|
|
1786
|
+
};
|
|
1787
|
+
const resolvedBlocks = await resolveBlocksAsync(mainStory.blocks, resolveOptions, diagnostics);
|
|
1788
|
+
const resolvedFootnotes = [];
|
|
1789
|
+
for (const entry of mainStory.footnotes) {
|
|
1790
|
+
const blocks = await resolveBlocksAsync(entry.blocks, resolveOptions, diagnostics);
|
|
1791
|
+
resolvedFootnotes.push({
|
|
1792
|
+
blocks: blocks.length > 0 ? blocks : [{
|
|
1793
|
+
children: [],
|
|
1794
|
+
kind: "paragraph"
|
|
1795
|
+
}],
|
|
1796
|
+
id: entry.id,
|
|
1797
|
+
ref: entry.ref
|
|
1798
|
+
});
|
|
1799
|
+
}
|
|
1800
|
+
const resolvedComments = [];
|
|
1801
|
+
for (const entry of pendingCommentStories) {
|
|
1802
|
+
const blocks = await resolveBlocksAsync(entry.story.blocks, resolveOptions, diagnostics);
|
|
1803
|
+
resolvedComments.push({
|
|
1804
|
+
blocks: blocks.length > 0 ? blocks : [{
|
|
1805
|
+
children: [],
|
|
1806
|
+
kind: "paragraph"
|
|
1807
|
+
}],
|
|
1808
|
+
comment: entry.comment,
|
|
1809
|
+
id: entry.id,
|
|
1810
|
+
paragraphId: entry.paragraphId
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
throwIfDocxAborted(signal);
|
|
1814
|
+
return Object.freeze({
|
|
1815
|
+
blocks: resolvedBlocks,
|
|
1816
|
+
comments: resolvedComments,
|
|
1817
|
+
diagnostics,
|
|
1818
|
+
footnotes: resolvedFootnotes,
|
|
1819
|
+
renderedRoots: mainStory.renderedRoots,
|
|
1820
|
+
reviewBindings,
|
|
1821
|
+
reviewRecords: review?.stored.records
|
|
1822
|
+
});
|
|
1823
|
+
};
|
|
1824
|
+
//#endregion
|
|
1825
|
+
export { collectDocxFormats, compileDocxDocument };
|