platejs 54.0.0-beta.1 → 54.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/THIRD_PARTY_NOTICES.md +113 -0
- package/dist/AIChatRequestContext-DY104TqL.d.ts +34 -0
- package/dist/BaseSuggestionPlugin-Deo6n6Fs.d.ts +90 -0
- package/dist/PlateStatic-CJX5bKuv.d.ts +19 -0
- package/dist/_virtual/_rolldown/runtime.js +28 -0
- package/dist/_virtual/builtin_esm-external-require-react.js +9 -0
- package/dist/ai/index.d.ts +2 -0
- package/dist/ai/index.js +2 -0
- package/dist/ai/lib/AIChatRequestContext.js +16 -0
- package/dist/ai/lib/findQuotedSpan.internal.js +63 -0
- package/dist/ai/react/AIChatPlugin.js +1238 -0
- package/dist/ai/react/CopilotPlugin.js +399 -0
- package/dist/ai/react/aiOutputLanding.internal.js +272 -0
- package/dist/ai/react/index.d.ts +1213 -0
- package/dist/ai/react/index.js +4 -0
- package/dist/ai/react/useAIChat.js +327 -0
- package/dist/authored/AuthoredPlugin.js +11 -0
- package/dist/authored/index.d.ts +4 -0
- package/dist/authored/index.js +3 -0
- package/dist/code-block/codemirror/createCodeMirrorAdapter.js +507 -0
- package/dist/code-block/codemirror/index.d.ts +18 -0
- package/dist/code-block/codemirror/index.js +2 -0
- package/dist/combobox-DAOYWuvC.d.ts +22 -0
- package/dist/comparison-types-Dt-unJZY-DCddmbSD.d.ts +177 -0
- package/dist/compiler/compileEditor.js +10 -0
- package/dist/compiler/index.d.ts +12 -0
- package/dist/compiler/index.js +2 -0
- package/dist/core-ClHasORr.d.ts +10862 -0
- package/dist/core.js +34 -0
- package/dist/diff/index.d.ts +30 -0
- package/dist/diff/index.js +1 -0
- package/dist/docs/ai.md +596 -0
- package/dist/docs/annotations.md +240 -0
- package/dist/docs/api/anchor.md +90 -0
- package/dist/docs/api/core/plate-components.md +582 -0
- package/dist/docs/api/core/plate-controller.md +81 -0
- package/dist/docs/api/core/plate-editor.md +310 -0
- package/dist/docs/api/core/plate-plugin.md +826 -0
- package/dist/docs/api/core/plate-store.md +106 -0
- package/dist/docs/api/core.md +735 -0
- package/dist/docs/api/document-change.md +225 -0
- package/dist/docs/api/dom.md +475 -0
- package/dist/docs/api/editor-api.md +569 -0
- package/dist/docs/api/editor-transforms.md +673 -0
- package/dist/docs/api/element.md +88 -0
- package/dist/docs/api/location.md +58 -0
- package/dist/docs/api/node.md +213 -0
- package/dist/docs/api/path.md +123 -0
- package/dist/docs/api/plate.md +99 -0
- package/dist/docs/api/point.md +59 -0
- package/dist/docs/api/range.md +88 -0
- package/dist/docs/api/react-hooks.md +636 -0
- package/dist/docs/api/resizable.md +121 -0
- package/dist/docs/api/selection.md +168 -0
- package/dist/docs/api/text.md +55 -0
- package/dist/docs/api/utils.md +149 -0
- package/dist/docs/authored-changes.md +452 -0
- package/dist/docs/autoformat.md +155 -0
- package/dist/docs/basic-blocks.md +205 -0
- package/dist/docs/basic-marks.md +187 -0
- package/dist/docs/block-menu.md +69 -0
- package/dist/docs/block-placeholder.md +164 -0
- package/dist/docs/blockquote.md +164 -0
- package/dist/docs/board.md +670 -0
- package/dist/docs/bold.md +142 -0
- package/dist/docs/browser.md +189 -0
- package/dist/docs/callout.md +148 -0
- package/dist/docs/clear-formatting.md +169 -0
- package/dist/docs/clipboard.md +500 -0
- package/dist/docs/code-block.md +530 -0
- package/dist/docs/code.md +134 -0
- package/dist/docs/column.md +173 -0
- package/dist/docs/combobox.md +247 -0
- package/dist/docs/comment.md +572 -0
- package/dist/docs/controlled.md +280 -0
- package/dist/docs/copilot.md +443 -0
- package/dist/docs/date.md +199 -0
- package/dist/docs/debugging.md +218 -0
- package/dist/docs/decorations.md +67 -0
- package/dist/docs/details.md +276 -0
- package/dist/docs/discussion.md +170 -0
- package/dist/docs/dnd.md +354 -0
- package/dist/docs/document-meta.md +233 -0
- package/dist/docs/document-model.md +383 -0
- package/dist/docs/docx.md +473 -0
- package/dist/docs/dom-coverage.md +101 -0
- package/dist/docs/editing-behavior.md +322 -0
- package/dist/docs/editor-methods.md +233 -0
- package/dist/docs/editor.md +940 -0
- package/dist/docs/emoji.md +209 -0
- package/dist/docs/equation.md +263 -0
- package/dist/docs/examples/collaboration-example.md +61 -0
- package/dist/docs/examples/editable-voids.md +58 -0
- package/dist/docs/examples/export.md +79 -0
- package/dist/docs/examples/huge-document.md +3 -0
- package/dist/docs/examples/hundreds-editors.md +41 -0
- package/dist/docs/examples/preview-markdown.md +43 -0
- package/dist/docs/examples/version-history.md +54 -0
- package/dist/docs/excalidraw.md +200 -0
- package/dist/docs/exit-break.md +267 -0
- package/dist/docs/external-text.md +145 -0
- package/dist/docs/feature-kits.md +147 -0
- package/dist/docs/field.md +370 -0
- package/dist/docs/find.md +175 -0
- package/dist/docs/font.md +186 -0
- package/dist/docs/footnote.md +530 -0
- package/dist/docs/form.md +441 -0
- package/dist/docs/format-painter.md +224 -0
- package/dist/docs/heading.md +99 -0
- package/dist/docs/highlight.md +135 -0
- package/dist/docs/history.md +408 -0
- package/dist/docs/horizontal-rule.md +181 -0
- package/dist/docs/html.md +379 -0
- package/dist/docs/indent.md +221 -0
- package/dist/docs/index.md +91 -0
- package/dist/docs/installation/docs.md +24 -0
- package/dist/docs/installation/manual.md +392 -0
- package/dist/docs/installation/mcp.md +147 -0
- package/dist/docs/installation/next.md +368 -0
- package/dist/docs/installation/node.md +148 -0
- package/dist/docs/installation/plate-ui.md +269 -0
- package/dist/docs/installation/react.md +347 -0
- package/dist/docs/installation/rsc.md +138 -0
- package/dist/docs/installation.md +93 -0
- package/dist/docs/italic.md +128 -0
- package/dist/docs/kbd.md +125 -0
- package/dist/docs/line-height.md +171 -0
- package/dist/docs/link.md +319 -0
- package/dist/docs/lint.md +408 -0
- package/dist/docs/list.md +213 -0
- package/dist/docs/llms.txt +147 -0
- package/dist/docs/locations.md +232 -0
- package/dist/docs/markdown.md +794 -0
- package/dist/docs/media.md +619 -0
- package/dist/docs/mention.md +187 -0
- package/dist/docs/migration/plite-to-plate.md +251 -0
- package/dist/docs/multi-select.md +97 -0
- package/dist/docs/navigation-feedback.md +196 -0
- package/dist/docs/pagination.md +164 -0
- package/dist/docs/performance.md +105 -0
- package/dist/docs/plugin-components.md +236 -0
- package/dist/docs/plugin-context.md +386 -0
- package/dist/docs/plugin-input-rules.md +974 -0
- package/dist/docs/plugin-methods.md +421 -0
- package/dist/docs/plugin-rules.md +904 -0
- package/dist/docs/plugin-shortcuts.md +387 -0
- package/dist/docs/plugin.md +560 -0
- package/dist/docs/prompt-editor.md +205 -0
- package/dist/docs/releases.md +3 -0
- package/dist/docs/roots.md +313 -0
- package/dist/docs/rtl.md +64 -0
- package/dist/docs/schema.md +148 -0
- package/dist/docs/selection.md +232 -0
- package/dist/docs/serializing.md +187 -0
- package/dist/docs/single-block.md +136 -0
- package/dist/docs/slash-command.md +144 -0
- package/dist/docs/static.md +438 -0
- package/dist/docs/strikethrough.md +131 -0
- package/dist/docs/subscript.md +113 -0
- package/dist/docs/suggestion.md +352 -0
- package/dist/docs/superscript.md +113 -0
- package/dist/docs/tabbable.md +238 -0
- package/dist/docs/table.md +303 -0
- package/dist/docs/text-align.md +161 -0
- package/dist/docs/toc.md +295 -0
- package/dist/docs/toolbar.md +291 -0
- package/dist/docs/trailing-block.md +138 -0
- package/dist/docs/transactions.md +300 -0
- package/dist/docs/troubleshooting.md +159 -0
- package/dist/docs/typescript.md +77 -0
- package/dist/docs/underline.md +125 -0
- package/dist/docs/unit-testing.md +340 -0
- package/dist/docs/upload.md +344 -0
- package/dist/docs/virtualized-rendering.md +75 -0
- package/dist/docs/yjs.md +256 -0
- package/dist/docx/export/index.d.ts +112 -0
- package/dist/docx/export/index.js +2 -0
- package/dist/docx/export/lib/comments.js +231 -0
- package/dist/docx/export/lib/docxStaticComponents.js +381 -0
- package/dist/docx/export/lib/exportDocx.js +379 -0
- package/dist/docx/export/lib/exportHtmlToDocx.internal.js +70 -0
- package/dist/docx/export/lib/generatedParts.js +51 -0
- package/dist/docx/export/lib/html-to-docx.internal.js +40 -0
- package/dist/docx/export/lib/internal/constants.js +106 -0
- package/dist/docx/export/lib/internal/docx-document.js +652 -0
- package/dist/docx/export/lib/internal/escape-xml.js +4 -0
- package/dist/docx/export/lib/internal/html-to-docx.js +148 -0
- package/dist/docx/export/lib/internal/list-item.js +85 -0
- package/dist/docx/export/lib/internal/list.js +43 -0
- package/dist/docx/export/lib/internal/math.js +187 -0
- package/dist/docx/export/lib/internal/namespaces.js +40 -0
- package/dist/docx/export/lib/internal/render-document-file.js +403 -0
- package/dist/docx/export/lib/internal/schemas/content-types.js +25 -0
- package/dist/docx/export/lib/internal/schemas/core.js +26 -0
- package/dist/docx/export/lib/internal/schemas/document-rels.js +15 -0
- package/dist/docx/export/lib/internal/schemas/document.template.js +36 -0
- package/dist/docx/export/lib/internal/schemas/font-table.js +55 -0
- package/dist/docx/export/lib/internal/schemas/generic-rels.js +9 -0
- package/dist/docx/export/lib/internal/schemas/numbering.js +18 -0
- package/dist/docx/export/lib/internal/schemas/rels.js +12 -0
- package/dist/docx/export/lib/internal/schemas/settings.js +17 -0
- package/dist/docx/export/lib/internal/schemas/styles.js +142 -0
- package/dist/docx/export/lib/internal/schemas/theme.js +198 -0
- package/dist/docx/export/lib/internal/schemas/web-settings.js +10 -0
- package/dist/docx/export/lib/internal/unit-conversion.js +24 -0
- package/dist/docx/export/lib/internal/vnode.js +4 -0
- package/dist/docx/export/lib/internal/word-styles.js +123 -0
- package/dist/docx/export/lib/internal/xml-builder.js +1808 -0
- package/dist/docx/export/lib/outputSafety.js +123 -0
- package/dist/docx/export/lib/reviewPart.js +234 -0
- package/dist/docx/export/lib/reviewProjection.js +163 -0
- package/dist/docx/export/lib/sourcePreservation.js +375 -0
- package/dist/docx/html/cleanWordHtml.internal.js +371 -0
- package/dist/docx/import/index.d.ts +44 -0
- package/dist/docx/import/index.js +3 -0
- package/dist/docx/import/lib/importDocx.js +1298 -0
- package/dist/docx/import/lib/wordFormatting.js +608 -0
- package/dist/docx/internal/abort.js +8 -0
- package/dist/docx/internal/docxPackage.js +322 -0
- package/dist/docx/internal/domParser.js +23 -0
- package/dist/docx/internal/packageParts.js +73 -0
- package/dist/docx/internal/readDocxNumbering.js +199 -0
- package/dist/docx/internal/reviewPart.js +249 -0
- package/dist/docx/internal/source.js +77 -0
- package/dist/docx/internal/sourceEligibility.js +349 -0
- package/dist/docx/internal/wordMath.js +375 -0
- package/dist/docx/internal/wordMathVocabulary.js +110 -0
- package/dist/docx/paste/index.d.ts +28 -0
- package/dist/docx/paste/index.js +2 -0
- package/dist/docx/paste/lib/WordPastePlugin.js +329 -0
- package/dist/dom/index.d.ts +2 -0
- package/dist/dom/index.js +2 -0
- package/dist/dom/plite-dom.internal.js +2 -0
- package/dist/excalidraw/index.d.ts +58 -0
- package/dist/excalidraw/index.js +2 -0
- package/dist/excalidraw/lib/BaseExcalidrawPlugin.js +15 -0
- package/dist/excalidraw/react/ExcalidrawPlugin.js +6 -0
- package/dist/excalidraw/react/index.d.ts +102 -0
- package/dist/excalidraw/react/index.js +3 -0
- package/dist/excalidraw/react/useExcalidrawSync.js +103 -0
- package/dist/facade.js +3 -0
- package/dist/features/basic-nodes/lib/BaseBlockPlugins.js +195 -0
- package/dist/features/basic-nodes/lib/BaseHeadingPlugins.js +126 -0
- package/dist/features/basic-nodes/lib/BaseMarkPlugins.js +326 -0
- package/dist/features/basic-styles/lib/BaseFormattingPlugin.js +391 -0
- package/dist/features/basic-styles/lib/BaseStylePlugins.js +261 -0
- package/dist/features/board/index.d.ts +2 -0
- package/dist/features/board/index.js +9 -0
- package/dist/features/board/lib/BaseBoardArrowPlugin.js +123 -0
- package/dist/features/board/lib/BaseBoardFramePlugin.js +84 -0
- package/dist/features/board/lib/BaseBoardGeoPlugin.js +12 -0
- package/dist/features/board/lib/BaseBoardImagePlugin.js +69 -0
- package/dist/features/board/lib/BaseBoardNotePlugin.js +11 -0
- package/dist/features/board/lib/BaseBoardPlugin.js +622 -0
- package/dist/features/board/lib/BaseBoardStrokePlugin.js +80 -0
- package/dist/features/board/lib/boardArrow.internal.js +193 -0
- package/dist/features/board/lib/boardCopy.internal.js +278 -0
- package/dist/features/board/lib/boardFrame.internal.js +125 -0
- package/dist/features/board/lib/boardHtml.internal.js +97 -0
- package/dist/features/board/lib/boardMember.internal.js +143 -0
- package/dist/features/board/lib/boardRatio.internal.js +21 -0
- package/dist/features/board/lib/boardShape.internal.js +193 -0
- package/dist/features/board/lib/boardStroke.internal.js +45 -0
- package/dist/features/board/lib/boardStyle.internal.js +126 -0
- package/dist/features/board/lib/boardTypes.internal.js +16 -0
- package/dist/features/callout/index.d.ts +85 -0
- package/dist/features/callout/index.js +2 -0
- package/dist/features/callout/lib/BaseCalloutPlugin.js +30 -0
- package/dist/features/code-block/lib/BaseCodeBlockPlugin.js +713 -0
- package/dist/features/code-block/lib/CodeBlockRules.js +21 -0
- package/dist/features/combobox/index.d.ts +3 -0
- package/dist/features/combobox/index.js +2 -0
- package/dist/features/combobox/lib/combobox.internal.js +111 -0
- package/dist/features/combobox/lib/filterWords.js +23 -0
- package/dist/features/comments/BaseCommentsPlugin.js +1237 -0
- package/dist/features/comments/index.d.ts +2 -0
- package/dist/features/comments/index.js +2 -0
- package/dist/features/comments/plite-comments.internal.js +2 -0
- package/dist/features/date/index.d.ts +42 -0
- package/dist/features/date/index.js +3 -0
- package/dist/features/date/lib/BaseDatePlugin.js +65 -0
- package/dist/features/date/lib/dateValue.js +17 -0
- package/dist/features/date/lib/legacyDateValue.internal.js +39 -0
- package/dist/features/details/index.d.ts +361 -0
- package/dist/features/details/index.js +2 -0
- package/dist/features/details/lib/BaseDetailsPlugin.js +438 -0
- package/dist/features/field/index.d.ts +2 -0
- package/dist/features/field/index.js +2 -0
- package/dist/features/field/lib/BaseFieldPlugin.js +414 -0
- package/dist/features/field/lib/fieldRules.internal.js +42 -0
- package/dist/features/find/index.d.ts +75 -0
- package/dist/features/find/index.js +2 -0
- package/dist/features/find/lib/BaseFindPlugin.js +301 -0
- package/dist/features/footnote/index.d.ts +2 -0
- package/dist/features/footnote/index.js +2 -0
- package/dist/features/footnote/lib/BaseFootnotePlugin.js +434 -0
- package/dist/features/footnote/lib/internal/getFootnoteTarget.js +31 -0
- package/dist/features/indent/lib/BaseIndentPlugin.js +164 -0
- package/dist/features/indent/lib/indentLevel.internal.js +9 -0
- package/dist/features/ink/index.d.ts +2 -0
- package/dist/features/ink/index.js +2 -0
- package/dist/features/ink/lib/BaseInkPlugin.js +406 -0
- package/dist/features/ink/lib/inkCodec.internal.js +130 -0
- package/dist/features/ink/lib/inkGone.internal.js +288 -0
- package/dist/features/ink/lib/inkMatch.internal.js +207 -0
- package/dist/features/ink/lib/inkPlaces.internal.js +556 -0
- package/dist/features/layout/index.d.ts +2 -0
- package/dist/features/layout/index.js +2 -0
- package/dist/features/layout/lib/BaseColumnPlugin.js +249 -0
- package/dist/features/link/lib/BaseLinkPlugin.js +470 -0
- package/dist/features/lint/index.d.ts +91 -0
- package/dist/features/lint/index.js +2 -0
- package/dist/features/lint/lib/BaseLintPlugin.js +639 -0
- package/dist/features/list/lib/BaseListPlugin.js +869 -0
- package/dist/features/list/lib/listConversion.internal.js +55 -0
- package/dist/features/list/lib/listFamily.internal.js +120 -0
- package/dist/features/list/lib/listHtml.internal.js +79 -0
- package/dist/features/list/lib/listIdentity.internal.js +455 -0
- package/dist/features/list/lib/listIndex.internal.js +342 -0
- package/dist/features/list/lib/listNumbering.internal.js +391 -0
- package/dist/features/list/lib/listPaste.internal.js +81 -0
- package/dist/features/media/index.d.ts +2 -0
- package/dist/features/media/index.js +5 -0
- package/dist/features/media/lib/BaseMediaPlugin.js +351 -0
- package/dist/features/media/lib/image/BaseImagePlugin.js +395 -0
- package/dist/features/media/lib/media/parseMediaUrl.js +161 -0
- package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +140 -0
- package/dist/features/media/lib/mediaHtml.internal.js +43 -0
- package/dist/features/mention/index.d.ts +73 -0
- package/dist/features/mention/index.js +2 -0
- package/dist/features/mention/lib/BaseMentionPlugin.js +120 -0
- package/dist/features/suggestion/BaseSuggestionPlugin.js +30 -0
- package/dist/features/suggestion/index.d.ts +9 -0
- package/dist/features/suggestion/index.js +3 -0
- package/dist/features/suggestion/suggestionColorOf.js +14 -0
- package/dist/features/table/index.d.ts +2 -0
- package/dist/features/table/index.js +2 -0
- package/dist/features/table/lib/BaseTablePlugin.js +1400 -0
- package/dist/features/table/lib/internal/context.js +58 -0
- package/dist/features/table/lib/internal/grid.js +193 -0
- package/dist/features/table/lib/internal/mutation.js +636 -0
- package/dist/features/table/lib/internal/paste.js +327 -0
- package/dist/features/table/lib/internal/selection.js +309 -0
- package/dist/features/table/lib/internal/tableCellHtml.js +280 -0
- package/dist/features/table/lib/internal/tabularText.js +50 -0
- package/dist/features/toc/index.d.ts +2 -0
- package/dist/features/toc/index.js +2 -0
- package/dist/features/toc/lib/BaseTocPlugin.js +41 -0
- package/dist/features/upload/index.d.ts +2 -0
- package/dist/features/upload/index.js +2 -0
- package/dist/features/upload/lib/BaseUploadPlugin.js +930 -0
- package/dist/features/upload/lib/mimeTypes.internal.js +3982 -0
- package/dist/history/index.d.ts +3 -0
- package/dist/history/index.js +1 -0
- package/dist/history/plite-history.internal.js +2 -0
- package/dist/html/index.d.ts +4 -0
- package/dist/html/index.js +3 -0
- package/dist/html/server/index.d.ts +3 -0
- package/dist/html/server/index.js +16 -0
- package/dist/htmlTypes-cg_cWsaN.d.ts +198 -0
- package/dist/hyperscript/index.d.ts +2 -0
- package/dist/hyperscript/index.js +1 -0
- package/dist/index-8WO2vI0U.d.ts +6519 -0
- package/dist/index-B5mYEawV.d.ts +750 -0
- package/dist/index-BZWFoUXt.d.ts +159 -0
- package/dist/index-C0POz7rg.d.ts +400 -0
- package/dist/index-C1_JIhL4.d.ts +526 -0
- package/dist/index-C35V_hj0.d.ts +6 -0
- package/dist/index-C6ql9pKw.d.ts +36 -0
- package/dist/index-C9DiGDVj.d.ts +558 -0
- package/dist/index-CLsEe3LY.d.ts +297 -0
- package/dist/index-CdOLsPaW.d.ts +318 -0
- package/dist/index-CktYvOgk.d.ts +29 -0
- package/dist/index-Cmuluh6f.d.ts +8 -0
- package/dist/index-CzLwBZpY.d.ts +46 -0
- package/dist/index-D3-2iM1b.d.ts +1084 -0
- package/dist/index-DKOFvteF.d.ts +184 -0
- package/dist/index-DPWyk3lG-DOYwohXO.d.ts +59 -0
- package/dist/index-DQnjqtQa.d.ts +678 -0
- package/dist/index-Do9pj1GK.d.ts +1218 -0
- package/dist/index-DpltOCot-A2b3p3Eb.d.ts +7644 -0
- package/dist/index-HPYawTae-BCUQLEWF.d.ts +111 -0
- package/dist/index-baQOK89E.d.ts +166 -0
- package/dist/index-oIJAZxc2.d.ts +2152 -0
- package/dist/index-r7yb77Wy.d.ts +2660 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +45 -7
- package/dist/internal/failInvariant.js +6 -0
- package/dist/internal/mergePlateRenderedAttributes.js +41 -0
- package/dist/internal/penStroke.internal.js +66 -0
- package/dist/internal/plugin/OverridePlugin.js +165 -0
- package/dist/internal/plugin/blockInsertion.js +67 -0
- package/dist/internal/plugin/blockRelease.js +60 -0
- package/dist/internal/plugin/collectPlateNodeMappings.js +62 -0
- package/dist/internal/plugin/compilePlainTextMappings.js +56 -0
- package/dist/internal/plugin/compilePlateFormats.js +127 -0
- package/dist/internal/plugin/compilePlateModel.js +780 -0
- package/dist/internal/plugin/compilePlateShortcuts.js +21 -0
- package/dist/internal/plugin/defaultElementTag.js +8 -0
- package/dist/internal/plugin/getPlateDecorationSources.js +47 -0
- package/dist/internal/plugin/getPluginRenderAttributes.js +20 -0
- package/dist/internal/plugin/imageLink.js +11 -0
- package/dist/internal/plugin/inlineInsertion.js +29 -0
- package/dist/internal/plugin/insertionAnchor.js +28 -0
- package/dist/internal/plugin/isEditOnlyDisabled.js +27 -0
- package/dist/internal/plugin/markdownParagraph.js +7 -0
- package/dist/internal/plugin/mergePluginCapabilities.js +90 -0
- package/dist/internal/plugin/pastedUploadFiles.js +4 -0
- package/dist/internal/plugin/pipeInjectNodeProps.js +30 -0
- package/dist/internal/plugin/plateChangeHandlers.js +74 -0
- package/dist/internal/plugin/plateRuntime.js +23 -0
- package/dist/internal/plugin/pluginFormatOperation.js +100 -0
- package/dist/internal/plugin/pluginInjectNodeProps.js +79 -0
- package/dist/internal/plugin/pluginStore.js +167 -0
- package/dist/internal/plugin/resolvePlugin.js +231 -0
- package/dist/internal/plugin/resolvePlugins.js +1173 -0
- package/dist/internal/plugin/uploadDrafts.js +6 -0
- package/dist/internal/utils/isFunction.js +6 -0
- package/dist/internal/utils/mergePlugins.js +219 -0
- package/dist/internal/utils/snapshotApiValue.js +29 -0
- package/dist/internal/utils/trustedContentSlice.js +9 -0
- package/dist/internal/utils/urlPolicy.js +110 -0
- package/dist/lib/editor/editorApplicationSchema.js +19 -0
- package/dist/lib/editor/editorUser.internal.js +39 -0
- package/dist/lib/editor/withPlite.js +480 -0
- package/dist/lib/libs/nanoid.js +2 -0
- package/dist/lib/libs/zustand.js +29 -0
- package/dist/lib/plugin/assertNoPrepareDocument.internal.js +7 -0
- package/dist/lib/plugin/createPluginContext.internal.js +363 -0
- package/dist/lib/plugin/defineBasePlugin.internal.js +203 -0
- package/dist/lib/plugin/definePlugin.js +11 -0
- package/dist/lib/plugin/pluginAuthoringContext.js +19 -0
- package/dist/lib/plugins/HistoryPlugin.js +15 -0
- package/dist/lib/plugins/TransferPlugin.js +7 -0
- package/dist/lib/plugins/affinity/AffinityPlugin.js +163 -0
- package/dist/lib/plugins/debug/DebugPlugin.js +65 -0
- package/dist/lib/plugins/dom/DOMPlugin.js +75 -0
- package/dist/lib/plugins/dom/plateDOMPlugin.internal.js +6 -0
- package/dist/lib/plugins/element-id/ElementIdPlugin.js +53 -0
- package/dist/lib/plugins/element-id/elementIdAdmission.internal.js +34 -0
- package/dist/lib/plugins/element-state/ElementStatePlugin.js +14 -0
- package/dist/lib/plugins/getCorePlugins.internal.js +25 -0
- package/dist/lib/plugins/html/HtmlPlugin.js +1970 -0
- package/dist/lib/plugins/html/htmlAst.js +314 -0
- package/dist/lib/plugins/html/htmlConversion.js +15 -0
- package/dist/lib/plugins/html/htmlDom.js +203 -0
- package/dist/lib/plugins/html/htmlMatcher.internal.js +85 -0
- package/dist/lib/plugins/html/htmlSafety.js +150 -0
- package/dist/lib/plugins/input-rules/InputRulesPlugin.js +327 -0
- package/dist/lib/plugins/input-rules/createInputRules.js +290 -0
- package/dist/lib/plugins/input-rules/defineInputRule.js +6 -0
- package/dist/lib/plugins/input-rules/inputRuleContinuation.internal.js +13 -0
- package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +16 -0
- package/dist/lib/plugins/input-rules/inputRuleVeto.js +9 -0
- package/dist/lib/plugins/input-rules/markInputRule.internal.js +44 -0
- package/dist/lib/plugins/paragraph/BaseParagraphPlugin.js +17 -0
- package/dist/lib/utils/applyDeepToNodes.js +17 -0
- package/dist/lib/utils/defaultsDeepToNodes.js +12 -0
- package/dist/lib/utils/environment.js +4 -0
- package/dist/lib/utils/getFragmentProp.js +27 -0
- package/dist/lib/utils/getInjectMatch.js +42 -0
- package/dist/lib/utils/hotkeys.js +113 -0
- package/dist/lib/utils/isDefined.js +5 -0
- package/dist/lib/utils/isUrl.js +27 -0
- package/dist/lib/utils/mergeDeepToNodes.js +12 -0
- package/dist/lib/utils/pluginNodeClass.js +10 -0
- package/dist/markdown/index.d.ts +2 -0
- package/dist/markdown/index.js +3 -0
- package/dist/markdown/lib/MarkdownPlugin.js +171 -0
- package/dist/markdown/lib/RawHtmlPlugin.js +24 -0
- package/dist/markdown/lib/deserializer/convertChildrenDeserialize.js +8 -0
- package/dist/markdown/lib/deserializer/convertNodesDeserialize.js +79 -0
- package/dist/markdown/lib/deserializer/mdastToSlate.js +28 -0
- package/dist/markdown/lib/internal/markdownAttributes.js +178 -0
- package/dist/markdown/lib/internal/markdownConversion.js +1365 -0
- package/dist/markdown/lib/internal/markdownDiagnostics.js +145 -0
- package/dist/markdown/lib/internal/markdownDocument.js +70 -0
- package/dist/markdown/lib/internal/markdownFrontmatter.js +102 -0
- package/dist/markdown/lib/internal/markdownIntrinsics.js +383 -0
- package/dist/markdown/lib/internal/markdownLine.js +550 -0
- package/dist/markdown/lib/internal/markdownMappings.js +677 -0
- package/dist/markdown/lib/internal/markdownOpenTail.js +381 -0
- package/dist/markdown/lib/internal/markdownRawHtml.js +314 -0
- package/dist/markdown/lib/internal/markdownReferences.js +70 -0
- package/dist/markdown/lib/internal/markdownSafety.js +57 -0
- package/dist/markdown/lib/internal/markdownSegments.js +143 -0
- package/dist/markdown/lib/internal/markdownTags.js +709 -0
- package/dist/markdown/lib/serializer/convertNodesSerialize.js +85 -0
- package/dist/markdown/lib/serializer/convertPhrasingSerialize.js +226 -0
- package/dist/markdown/lib/serializer/listToMdastTree.js +235 -0
- package/dist/markdown/lib/serializer/mdastContent.js +22 -0
- package/dist/markdown/lib/serializer/reportOmittedProperties.js +34 -0
- package/dist/markdown/lib/utils/remarkPlugins.js +34 -0
- package/dist/math/index.d.ts +519 -0
- package/dist/math/index.js +2 -0
- package/dist/math/lib/BaseEquationPlugin.js +345 -0
- package/dist/math/lib/mathmlTex.internal.js +1123 -0
- package/dist/math/lib/mathmlTexSymbols.internal.js +1852 -0
- package/dist/math/react/EquationPlugin.js +7 -0
- package/dist/math/react/index.d.ts +66 -0
- package/dist/math/react/index.js +2 -0
- package/dist/migrations/documentMigrationAuthored.internal.js +18 -0
- package/dist/migrations/documentMigrationSelection.internal.js +27 -0
- package/dist/migrations/documentMigrationTarget.internal.js +17 -0
- package/dist/migrations/documentMigrations.js +320 -0
- package/dist/migrations/extractLegacyCommentRanges.js +141 -0
- package/dist/migrations/index.d.ts +206 -0
- package/dist/migrations/index.js +5 -0
- package/dist/migrations/migrateListIdentity.js +93 -0
- package/dist/migrations/migratePlateV54.js +170 -0
- package/dist/migrations/migratePlateV54Ast.internal.js +381 -0
- package/dist/migrations/migratePlateV54BuiltIns.internal.js +87 -0
- package/dist/migrations/migratePlateV54CodeBlocks.internal.js +87 -0
- package/dist/migrations/migratePlateV54Inputs.internal.js +186 -0
- package/dist/migrations/migratePlateV54Ownership.internal.js +20 -0
- package/dist/migrations/migratePlateV54Profile.internal.js +367 -0
- package/dist/migrations/migratePlateV54RetiredMarks.internal.js +48 -0
- package/dist/migrations/migratePlateV54Suggestions.internal.js +236 -0
- package/dist/migrations/migratePlateV54Urls.internal.js +125 -0
- package/dist/migrations/v53-manifest.internal.js +271 -0
- package/dist/node_modules/.pnpm/use-sync-external-store@1.6.0_react@19.2.8/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.development.js +73 -0
- package/dist/node_modules/.pnpm/use-sync-external-store@1.6.0_react@19.2.8/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.js +75 -0
- package/dist/node_modules/.pnpm/use-sync-external-store@1.6.0_react@19.2.8/node_modules/use-sync-external-store/with-selector.js +11 -0
- package/dist/pagination/index.d.ts +167 -0
- package/dist/pagination/index.js +2 -0
- package/dist/pagination/react/PagedEditorContent.js +77 -0
- package/dist/pagination/react/index.d.ts +37 -0
- package/dist/pagination/react/index.js +5 -0
- package/dist/plain-text.js +38 -0
- package/dist/react/components/EditorContentView.internal.js +284 -0
- package/dist/react/components/EditorProvider.js +32 -0
- package/dist/react/components/EditorRefEffect.js +65 -0
- package/dist/react/components/NodeSelection.js +836 -0
- package/dist/react/components/Plate.js +244 -0
- package/dist/react/components/PlateContainer.js +103 -0
- package/dist/react/components/PlateContent.js +36 -0
- package/dist/react/components/PlateController.js +39 -0
- package/dist/react/components/PlateRoot.internal.js +89 -0
- package/dist/react/components/PlateView.js +43 -0
- package/dist/react/components/plate-nodes.js +146 -0
- package/dist/react/core.js +59 -0
- package/dist/react/editor/getPlateCorePlugins.internal.js +20 -0
- package/dist/react/editor/useCreateEditor.js +43 -0
- package/dist/react/editor/withPlate.js +22 -0
- package/dist/react/features/basic-nodes/BasicNodesPlugins.js +29 -0
- package/dist/react/features/basic-styles/BasicStylePlugins.js +15 -0
- package/dist/react/features/board/BoardPlugin.js +23 -0
- package/dist/react/features/board/BoardShape.js +272 -0
- package/dist/react/features/board/BoardSurface.js +315 -0
- package/dist/react/features/board/boardClipboard.internal.js +100 -0
- package/dist/react/features/board/boardConnect.internal.js +198 -0
- package/dist/react/features/board/boardGesture.internal.js +583 -0
- package/dist/react/features/board/boardIndex.internal.js +426 -0
- package/dist/react/features/board/boardInk.internal.js +41 -0
- package/dist/react/features/board/boardKeys.internal.js +484 -0
- package/dist/react/features/board/boardPick.internal.js +73 -0
- package/dist/react/features/board/boardPicking.internal.js +84 -0
- package/dist/react/features/board/boardPictures.internal.js +96 -0
- package/dist/react/features/board/boardPreview.internal.js +177 -0
- package/dist/react/features/board/boardResize.internal.js +153 -0
- package/dist/react/features/board/boardSnap.internal.js +267 -0
- package/dist/react/features/board/boardView.internal.js +1074 -0
- package/dist/react/features/board/boardVoice.internal.js +192 -0
- package/dist/react/features/board/index.d.ts +2140 -0
- package/dist/react/features/board/index.js +4 -0
- package/dist/react/features/callout/CalloutPlugin.js +6 -0
- package/dist/react/features/callout/index.d.ts +84 -0
- package/dist/react/features/callout/index.js +2 -0
- package/dist/react/features/code-block/CodeBlockPlugin.js +9 -0
- package/dist/react/features/combobox/comboboxOwner.internal.js +269 -0
- package/dist/react/features/combobox/index.d.ts +63 -0
- package/dist/react/features/combobox/index.js +2 -0
- package/dist/react/features/combobox/useCombobox.js +71 -0
- package/dist/react/features/comments/CommentsPlugin.js +34 -0
- package/dist/react/features/comments/index.d.ts +605 -0
- package/dist/react/features/comments/index.js +2 -0
- package/dist/react/features/date/DatePlugin.js +6 -0
- package/dist/react/features/date/index.d.ts +40 -0
- package/dist/react/features/date/index.js +2 -0
- package/dist/react/features/details/DetailsPlugin.js +8 -0
- package/dist/react/features/details/index.d.ts +500 -0
- package/dist/react/features/details/index.js +2 -0
- package/dist/react/features/field/FieldPlugin.js +34 -0
- package/dist/react/features/field/index.d.ts +312 -0
- package/dist/react/features/field/index.js +2 -0
- package/dist/react/features/footnote/FootnotePlugin.js +36 -0
- package/dist/react/features/footnote/index.d.ts +245 -0
- package/dist/react/features/footnote/index.js +2 -0
- package/dist/react/features/format-painter/FormatPainterPlugin.js +156 -0
- package/dist/react/features/format-painter/index.d.ts +205 -0
- package/dist/react/features/format-painter/index.js +2 -0
- package/dist/react/features/indent/IndentPlugin.js +6 -0
- package/dist/react/features/ink/InkContent.js +313 -0
- package/dist/react/features/ink/InkCopyView.js +203 -0
- package/dist/react/features/ink/InkPlugin.js +35 -0
- package/dist/react/features/ink/index.d.ts +354 -0
- package/dist/react/features/ink/index.js +4 -0
- package/dist/react/features/ink/inkCapture.internal.js +336 -0
- package/dist/react/features/ink/inkInput.internal.js +19 -0
- package/dist/react/features/ink/inkLayout.internal.js +29 -0
- package/dist/react/features/ink/inkMeasure.internal.js +242 -0
- package/dist/react/features/ink/inkPaint.internal.js +93 -0
- package/dist/react/features/ink/inkPlacement.internal.js +557 -0
- package/dist/react/features/ink/inkWatch.internal.js +288 -0
- package/dist/react/features/layout/ColumnPlugin.js +8 -0
- package/dist/react/features/layout/index.d.ts +543 -0
- package/dist/react/features/layout/index.js +2 -0
- package/dist/react/features/link/LinkPlugin.js +7 -0
- package/dist/react/features/list/ListPlugin.js +125 -0
- package/dist/react/features/media/index.d.ts +670 -0
- package/dist/react/features/media/index.js +2 -0
- package/dist/react/features/media/plugins.js +12 -0
- package/dist/react/features/mention/MentionPlugin.js +6 -0
- package/dist/react/features/mention/index.d.ts +63 -0
- package/dist/react/features/mention/index.js +2 -0
- package/dist/react/features/resizable/Resizable.js +201 -0
- package/dist/react/features/resizable/index.d.ts +27 -0
- package/dist/react/features/resizable/index.js +2 -0
- package/dist/react/features/resizable/resizeLength.internal.js +11 -0
- package/dist/react/features/suggestion/SuggestionPlugin.js +24 -0
- package/dist/react/features/suggestion/index.d.ts +45 -0
- package/dist/react/features/suggestion/index.js +3 -0
- package/dist/react/features/suggestion/suggestion-view.internal.js +112 -0
- package/dist/react/features/suggestion/useSuggestion.js +135 -0
- package/dist/react/features/table/TablePlugin.js +425 -0
- package/dist/react/features/table/index.d.ts +4707 -0
- package/dist/react/features/table/index.js +3 -0
- package/dist/react/features/table/tableSelectionHostBinding.internal.js +97 -0
- package/dist/react/features/table/useTableResize.js +88 -0
- package/dist/react/features/toc/TocPlugin.js +6 -0
- package/dist/react/features/toc/index.d.ts +20 -0
- package/dist/react/features/toc/index.js +2 -0
- package/dist/react/features/upload/UploadPlugin.js +41 -0
- package/dist/react/features/upload/index.d.ts +313 -0
- package/dist/react/features/upload/index.js +2 -0
- package/dist/react/index.d.ts +6 -4
- package/dist/react/index.js +76 -7
- package/dist/react/internal/block-redraws.js +83 -0
- package/dist/react/internal/getPlateEditorInstanceKey.js +13 -0
- package/dist/react/internal/plate-context.js +507 -0
- package/dist/react/internal/plite-components.js +12 -0
- package/dist/react/internal/react-helpers.js +19 -0
- package/dist/react/internal/rendered-attributes.js +190 -0
- package/dist/react/internal/useDeepCompareMemo.js +13 -0
- package/dist/react/internal/usePlateInstancesWarn.js +24 -0
- package/dist/react/internal/usePlateModelRevision.js +17 -0
- package/dist/react/internal/useZustandSelector.js +35 -0
- package/dist/react/libs/jotai.js +3 -0
- package/dist/react/plite-react.js +2 -0
- package/dist/react/plugin/createPluginContext.internal.js +7 -0
- package/dist/react/plugin/definePlugin.js +26 -0
- package/dist/react/plugin/pluginFactory.internal.js +43 -0
- package/dist/react/plugin/toReactPlugin.js +86 -0
- package/dist/react/plugins/navigation-feedback/NavigationFeedbackPlugin.js +109 -0
- package/dist/react/plugins/paragraph/ParagraphPlugin.js +14 -0
- package/dist/react/stores/element/useElement.js +11 -0
- package/dist/react/stores/element/useElementSelector.js +20 -0
- package/dist/react/stores/element/useElementStore.js +150 -0
- package/dist/react/stores/element/useElementStoreSelector.internal.js +69 -0
- package/dist/react/stores/element/usePath.js +57 -0
- package/dist/react/stores/plate/useEditor.js +136 -0
- package/dist/react/stores/plate/useEditorHistory.js +55 -0
- package/dist/react/stores/plate/useEditorSelector.js +70 -0
- package/dist/react/stores/plate/usePluginStore.js +56 -0
- package/dist/react/stores/plate/useViewStore.js +35 -0
- package/dist/react/stores/plate-controller/document-focus.internal.js +72 -0
- package/dist/react/stores/plate-controller/useFocusedLast.js +30 -0
- package/dist/react/utils/BlockPlaceholderPlugin.js +59 -0
- package/dist/react/utils/annotationPointer.internal.js +35 -0
- package/dist/react/utils/bindPointerSession.internal.js +35 -0
- package/dist/react/utils/dispatchPlateShortcut.internal.js +19 -0
- package/dist/react/utils/dom-attributes.internal.js +160 -0
- package/dist/react/utils/editableKeyDown.internal.js +11 -0
- package/dist/react/utils/getRenderNodeProps.internal.js +58 -0
- package/dist/react/utils/pipeHandler.internal.js +71 -0
- package/dist/react/utils/pipeRenderElement.internal.js +495 -0
- package/dist/react/utils/pipeRenderLeaf.internal.js +181 -0
- package/dist/react/utils/pipeRenderText.internal.js +138 -0
- package/dist/react/utils/pluginRenderElement.internal.js +163 -0
- package/dist/react/utils/pluginRenderLeaf.internal.js +89 -0
- package/dist/react/utils/pluginRenderText.internal.js +52 -0
- package/dist/react/utils/tapOrder.internal.js +106 -0
- package/dist/react/utils/useSelectionFragment.js +24 -0
- package/dist/react/virtualized.d.ts +13 -0
- package/dist/react/virtualized.js +48 -0
- package/dist/root.js +45 -0
- package/dist/source-aUwpNnAw.d.ts +144 -0
- package/dist/static/components/PlateStatic.js +389 -0
- package/dist/static/components/plite-nodes.js +43 -0
- package/dist/static/index.d.ts +129 -1
- package/dist/static/index.js +4 -1
- package/dist/static/internal/getPlainText.js +23 -0
- package/dist/static/internal/renderStaticHtmlWithOverrides.js +33 -0
- package/dist/static/internal/staticDocumentView.js +53 -0
- package/dist/static/internal/staticPresentation.js +67 -0
- package/dist/static/internal/writeStaticSelectionClipboardData.js +222 -0
- package/dist/static/pipeRenderElementStatic.internal.js +32 -0
- package/dist/static/pluginRenderElementStatic.internal.js +70 -0
- package/dist/static/pluginRenderLeafStatic.internal.js +87 -0
- package/dist/static/pluginRenderTextStatic.internal.js +87 -0
- package/dist/static/renderStaticHtml.js +9 -0
- package/dist/static/utils/getRenderNodeStaticProps.internal.js +31 -0
- package/dist/tabbable/index.d.ts +2 -0
- package/dist/tabbable/index.js +0 -0
- package/dist/tabbable/react/TabbableEffects.internal.js +186 -0
- package/dist/tabbable/react/TabbablePlugin.js +15 -0
- package/dist/tabbable/react/index.d.ts +16 -0
- package/dist/tabbable/react/index.js +2 -0
- package/dist/testing/index.d.ts +175 -0
- package/dist/testing/index.js +1 -0
- package/dist/utils/plate-keys.js +78 -0
- package/dist/utils/plugins/ExitBreakPlugin.js +26 -0
- package/dist/utils/plugins/SingleBlockPlugin.js +21 -0
- package/dist/utils/plugins/SingleLinePlugin.js +32 -0
- package/dist/utils/plugins/TrailingBlockPlugin.js +29 -0
- package/dist/utils/plugins/joinSingleRootBlock.internal.js +24 -0
- package/dist/yjs/index.d.ts +2 -0
- package/dist/yjs/index.js +1 -0
- package/dist/yjs/react/YjsPlugin.js +60 -0
- package/dist/yjs/react/index.d.ts +94 -0
- package/dist/yjs/react/index.js +3 -0
- package/package.json +684 -36
|
@@ -0,0 +1,1238 @@
|
|
|
1
|
+
import { canPlaceBlocksAtPath, getCompiledEditorSchema, getEditorAuthoredDocumentCapability, placeElementAt, projectEditorView } from "../../facade.js";
|
|
2
|
+
import { getCompiledPlatePlugin } from "../../internal/plugin/compilePlateModel.js";
|
|
3
|
+
import { resolveInsertionAnchor } from "../../internal/plugin/insertionAnchor.js";
|
|
4
|
+
import { HistoryPlugin } from "../../lib/plugins/HistoryPlugin.js";
|
|
5
|
+
import { isInputRuleVetoed } from "../../lib/plugins/input-rules/inputRuleVeto.internal.js";
|
|
6
|
+
import { BaseParagraphPlugin } from "../../lib/plugins/paragraph/BaseParagraphPlugin.js";
|
|
7
|
+
import { PLUGINS } from "../../utils/plate-keys.js";
|
|
8
|
+
import { ContentSlice, ElementApi, NodeApi, PathApi, PointApi, RangeApi, SelectionApi, TextApi, defineEffect, editorCommands } from "../../core.js";
|
|
9
|
+
import { isListItem } from "../../features/list/lib/listIndex.internal.js";
|
|
10
|
+
import { definePlugin } from "../../react/plugin/definePlugin.js";
|
|
11
|
+
import { AuthoredPlugin } from "../../authored/AuthoredPlugin.js";
|
|
12
|
+
import { BaseTableCellPlugin, BaseTablePlugin, BaseTableRowPlugin } from "../../features/table/lib/BaseTablePlugin.js";
|
|
13
|
+
import { MarkdownPlugin } from "../../markdown/lib/MarkdownPlugin.js";
|
|
14
|
+
import { findQuotedSpan } from "../lib/findQuotedSpan.internal.js";
|
|
15
|
+
import { captureTextRange, fillEmptyListItem, formatAIOutput, landAIOutput, suggestionBlocks, textEdits, wholeTextBlocks, withoutText } from "./aiOutputLanding.internal.js";
|
|
16
|
+
import isEqual from "lodash/isEqual.js";
|
|
17
|
+
import cloneDeep from "lodash/cloneDeep.js";
|
|
18
|
+
//#region src/ai/react/AIChatPlugin.ts
|
|
19
|
+
const aiChatShowEffect = defineEffect({
|
|
20
|
+
history: "skip",
|
|
21
|
+
key: "ai.chat.show"
|
|
22
|
+
});
|
|
23
|
+
const aiChatCommandEditors = /* @__PURE__ */ new WeakMap();
|
|
24
|
+
const getAIChatCommandEditor = (editor) => aiChatCommandEditors.get(editor) ?? editor;
|
|
25
|
+
const withoutReviewMarks = (node) => {
|
|
26
|
+
const { authored: _marks, ...plain } = node;
|
|
27
|
+
return ElementApi.isElement(plain) ? {
|
|
28
|
+
...plain,
|
|
29
|
+
children: plain.children.map(withoutReviewMarks)
|
|
30
|
+
} : plain;
|
|
31
|
+
};
|
|
32
|
+
const dependencies = [
|
|
33
|
+
...[MarkdownPlugin],
|
|
34
|
+
AuthoredPlugin,
|
|
35
|
+
HistoryPlugin
|
|
36
|
+
];
|
|
37
|
+
const AIChatPlugin = definePlugin(PLUGINS.aiChat, {
|
|
38
|
+
dependencies,
|
|
39
|
+
initialState: {
|
|
40
|
+
_blockKey: null,
|
|
41
|
+
_blockRefs: {},
|
|
42
|
+
_changeId: null,
|
|
43
|
+
_requestId: null,
|
|
44
|
+
_tableCellRefs: {},
|
|
45
|
+
authorId: null,
|
|
46
|
+
chat: null,
|
|
47
|
+
chatNodeMode: null,
|
|
48
|
+
chatNodes: [],
|
|
49
|
+
chatSelection: null,
|
|
50
|
+
mode: "insert",
|
|
51
|
+
open: false,
|
|
52
|
+
previewValue: [],
|
|
53
|
+
streaming: false,
|
|
54
|
+
toolName: null,
|
|
55
|
+
trigger: " ",
|
|
56
|
+
triggerQuery: null,
|
|
57
|
+
triggerPreviousCharPattern: /^\s?$/
|
|
58
|
+
}
|
|
59
|
+
}).extend((context) => {
|
|
60
|
+
const { editor } = context;
|
|
61
|
+
let previewAnchor = null;
|
|
62
|
+
let previewOwner = null;
|
|
63
|
+
let previewParse;
|
|
64
|
+
let suggestion = null;
|
|
65
|
+
let suggestionTarget = null;
|
|
66
|
+
const tableDraft = /* @__PURE__ */ new Map();
|
|
67
|
+
const captureSelection = (commandEditor, selection) => {
|
|
68
|
+
previewAnchor?.release();
|
|
69
|
+
previewAnchor = selection ? commandEditor.anchor(selection, {
|
|
70
|
+
association: "inward",
|
|
71
|
+
deletion: "drop"
|
|
72
|
+
}) : null;
|
|
73
|
+
};
|
|
74
|
+
const captureTarget = (commandEditor, target) => {
|
|
75
|
+
const viewSelection = target ? null : commandEditor.read.selection();
|
|
76
|
+
const current = target ?? viewSelection ?? editor.read.selection();
|
|
77
|
+
const nodeSource = (target ? [] : commandEditor.read.selection.nodes()).length ? commandEditor : editor;
|
|
78
|
+
const selectedNodes = target ? [] : nodeSource.read.selection.nodes();
|
|
79
|
+
const isNodeSelecting = selectedNodes.length > 0;
|
|
80
|
+
const root = current ? SelectionApi.root(current) : commandEditor.read.view.root();
|
|
81
|
+
const captureEditor = projectEditorView(commandEditor, root ? { root } : {});
|
|
82
|
+
const selection = current && !isNodeSelecting ? captureEditor.read((state) => captureTextRange(state, current)) : current;
|
|
83
|
+
if (viewSelection && selection && !RangeApi.equals(selection, viewSelection)) commandEditor.update.selection.set(selection);
|
|
84
|
+
const blocks = isNodeSelecting ? selectedNodes : captureEditor.read.nodes.blocks(selection ? { at: selection } : {});
|
|
85
|
+
const isEndpoint = (path, endpoint) => isNodeSelecting && !!endpoint && (PathApi.equals(path, endpoint) || PathApi.isAncestor(path, endpoint));
|
|
86
|
+
captureSelection(captureEditor, selection);
|
|
87
|
+
context.store.set({
|
|
88
|
+
chatNodeMode: isNodeSelecting ? nodeSource.read.selection.nodeMode() : null,
|
|
89
|
+
chatSelection: isNodeSelecting ? null : selection,
|
|
90
|
+
chatNodes: blocks.flatMap(([node, path]) => ElementApi.isElement(node) ? [{
|
|
91
|
+
node,
|
|
92
|
+
nodeKey: commandEditor.key(node),
|
|
93
|
+
...isEndpoint(path, selection?.anchor.path) ? { isSelectionAnchor: true } : {},
|
|
94
|
+
...isEndpoint(path, selection?.focus.path) ? { isSelectionFocus: true } : {}
|
|
95
|
+
}] : [])
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
const prepareTargetRestore = (commandEditor) => {
|
|
99
|
+
const { chatNodeMode, chatNodes, chatSelection } = context.store.get();
|
|
100
|
+
const actionEditor = getActionEditor(commandEditor);
|
|
101
|
+
if (!actionEditor) return null;
|
|
102
|
+
if (!chatSelection && chatNodes.length > 0) {
|
|
103
|
+
const anchor = chatNodes.find((node) => node.isSelectionAnchor);
|
|
104
|
+
const focus = chatNodes.find((node) => node.isSelectionFocus);
|
|
105
|
+
const entries = chatNodes.flatMap(({ nodeKey }) => {
|
|
106
|
+
const entry = actionEditor.read.nodes.get(nodeKey, { match: ElementApi.isElement });
|
|
107
|
+
return entry ? [entry] : [];
|
|
108
|
+
});
|
|
109
|
+
if (!anchor || !focus || entries.length !== chatNodes.length) return null;
|
|
110
|
+
const target = entries[0]?.[0];
|
|
111
|
+
const { schema } = actionEditor.read;
|
|
112
|
+
const mode = chatNodeMode === "object" && target && !schema.isVoid(target) && schema.isSelectable(target) && (schema.isObject(target) || schema.isAtom(target)) ? "object" : "block";
|
|
113
|
+
return () => actionEditor.update.selection.setNodes(entries.map(([node]) => node), {
|
|
114
|
+
anchor: anchor.nodeKey,
|
|
115
|
+
focus: focus.nodeKey,
|
|
116
|
+
mode
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const selection = previewAnchor?.resolve();
|
|
120
|
+
if (!selection) return null;
|
|
121
|
+
return () => actionEditor.update.selection.set(selection);
|
|
122
|
+
};
|
|
123
|
+
const resolveChatSelection = () => {
|
|
124
|
+
const stored = context.store.get("chatSelection");
|
|
125
|
+
return stored && previewAnchor ? previewAnchor.resolve() : stored;
|
|
126
|
+
};
|
|
127
|
+
const restoreTarget = (commandEditor) => {
|
|
128
|
+
const restore = prepareTargetRestore(commandEditor);
|
|
129
|
+
restore?.();
|
|
130
|
+
return !!restore;
|
|
131
|
+
};
|
|
132
|
+
const resolveTargetRoot = (commandEditor, key) => {
|
|
133
|
+
const point = commandEditor.read.points.start(key);
|
|
134
|
+
return point ? { root: point.root } : null;
|
|
135
|
+
};
|
|
136
|
+
const pendingChange = () => {
|
|
137
|
+
const changeId = context.store.get("_changeId");
|
|
138
|
+
return changeId ? editor.plugin(AuthoredPlugin).read.change(changeId) : null;
|
|
139
|
+
};
|
|
140
|
+
let responseAuthor = null;
|
|
141
|
+
const actionAuthor = () => pendingChange()?.authorId ?? (responseAuthor?.requestId === context.store.get("_requestId") ? responseAuthor.authorId : context.store.get("authorId") ?? void 0);
|
|
142
|
+
const getActionEditor = (commandEditor, targetKey) => {
|
|
143
|
+
const { _blockKey, chatNodes, chatSelection } = context.store.get();
|
|
144
|
+
const selection = suggestionTarget?.range ?? previewAnchor?.resolve() ?? chatSelection;
|
|
145
|
+
const key = targetKey ?? (suggestionTarget ? void 0 : _blockKey ?? chatNodes[0]?.nodeKey);
|
|
146
|
+
const target = key ? resolveTargetRoot(commandEditor, key) : { root: selection ? SelectionApi.root(selection) : commandEditor.read.view.root() };
|
|
147
|
+
if (!target) return null;
|
|
148
|
+
return projectEditorView(commandEditor, {
|
|
149
|
+
authorId: actionAuthor(),
|
|
150
|
+
root: target.root ?? void 0
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
const columnGroupDescriptor = getCompiledPlatePlugin(editor, PLUGINS.columnGroup);
|
|
154
|
+
const columnGroup = columnGroupDescriptor ? editor.plugin(columnGroupDescriptor) : void 0;
|
|
155
|
+
const paragraph = editor.plugin(BaseParagraphPlugin);
|
|
156
|
+
const tablePlugin = editor.plugin(BaseTablePlugin);
|
|
157
|
+
const currentBlockPath = (state) => {
|
|
158
|
+
const blockKey = context.store.get("_blockKey");
|
|
159
|
+
const generated = blockKey ? state.nodes.get(blockKey, { match: ElementApi.isElement }) : void 0;
|
|
160
|
+
const selection = state.selection();
|
|
161
|
+
const selectionPath = state.selection.nodes().at(-1)?.[1] ?? selection?.focus.path;
|
|
162
|
+
const path = generated?.[1] ?? selectionPath?.slice(0, 1) ?? [0];
|
|
163
|
+
const entry = state.nodes.get(path, { match: ElementApi.isElement });
|
|
164
|
+
const containerTypes = /* @__PURE__ */ new Set([...columnGroup ? [columnGroup.schema.type] : [], ...tablePlugin.installed ? [tablePlugin.schema.type] : []]);
|
|
165
|
+
return entry && containerTypes.has(entry[0].type) ? state.nodes.above()?.[1] ?? path : path;
|
|
166
|
+
};
|
|
167
|
+
const getInsertStart = (state) => {
|
|
168
|
+
const path = currentBlockPath(state);
|
|
169
|
+
const startBlock = state.nodes.get(path, { match: ElementApi.isElement })?.[0];
|
|
170
|
+
return {
|
|
171
|
+
path,
|
|
172
|
+
startBlock,
|
|
173
|
+
startInEmptyParagraph: !!startBlock && NodeApi.string(startBlock).length === 0 && startBlock.type === paragraph.schema.type
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
const stop = () => {
|
|
177
|
+
context.store.get().chat?.stop?.();
|
|
178
|
+
context.store.set({ streaming: false });
|
|
179
|
+
};
|
|
180
|
+
const cancel = () => {
|
|
181
|
+
context.store.set({
|
|
182
|
+
_requestId: null,
|
|
183
|
+
streaming: false
|
|
184
|
+
});
|
|
185
|
+
context.store.get().chat?.stop?.();
|
|
186
|
+
};
|
|
187
|
+
const reviewSucceeded = (result) => result?.status === "applied" || result?.status === "unchanged";
|
|
188
|
+
const decideCurrentChange = (action) => {
|
|
189
|
+
const changeId = context.store.get("_changeId");
|
|
190
|
+
if (!changeId) return null;
|
|
191
|
+
const change = pendingChange();
|
|
192
|
+
const authored = projectEditorView(editor, { authorId: change?.authorId }).plugin(AuthoredPlugin);
|
|
193
|
+
const result = (change ? action === "reject" ? authored.update.withdraw([change]) : authored.update.decide({
|
|
194
|
+
action,
|
|
195
|
+
changes: [change]
|
|
196
|
+
}) : {
|
|
197
|
+
ids: [changeId],
|
|
198
|
+
status: "unchanged"
|
|
199
|
+
}) ?? {
|
|
200
|
+
ids: [changeId],
|
|
201
|
+
status: "invalid"
|
|
202
|
+
};
|
|
203
|
+
if (reviewSucceeded(result)) {
|
|
204
|
+
context.store.set({ _changeId: null });
|
|
205
|
+
if (action === "reject" && change) retargetChatNodesAfterWithdraw();
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
};
|
|
209
|
+
const retargetChatNodesAfterWithdraw = () => {
|
|
210
|
+
if (suggestionTarget?.kind !== "blocks") return;
|
|
211
|
+
const root = SelectionApi.root(suggestionTarget.range);
|
|
212
|
+
const view = projectEditorView(editor, root ? { root } : {});
|
|
213
|
+
const { chatNodes } = context.store.get();
|
|
214
|
+
const restored = suggestionTarget.paths.map((path) => view.read.nodes.get(path, { match: ElementApi.isElement })?.[0]);
|
|
215
|
+
if (restored.length !== chatNodes.length || !restored.every((node, index) => node !== void 0 && node.type === chatNodes[index].node.type && NodeApi.string(node) === NodeApi.string(chatNodes[index].node))) return;
|
|
216
|
+
context.store.set({ chatNodes: chatNodes.map((chatNode, index) => ({
|
|
217
|
+
...chatNode,
|
|
218
|
+
nodeKey: view.key(restored[index])
|
|
219
|
+
})) });
|
|
220
|
+
};
|
|
221
|
+
const withReviewRecords = (blocks) => {
|
|
222
|
+
const { records } = editor.read.value();
|
|
223
|
+
return records ? {
|
|
224
|
+
children: [...blocks],
|
|
225
|
+
records
|
|
226
|
+
} : { children: [...blocks] };
|
|
227
|
+
};
|
|
228
|
+
const proposedBlocks = (view, root, entries) => {
|
|
229
|
+
const projected = "preview" in view.plugin(AuthoredPlugin).read.view() ? null : getEditorAuthoredDocumentCapability(editor)?.projectBlocks(editor.read.value(), "proposed", getCompiledEditorSchema(editor), root, entries.map(([, path]) => path));
|
|
230
|
+
return (projected?.ok ? projected.blocks : entries.map(([node]) => node)).filter((node) => ElementApi.isElement(node));
|
|
231
|
+
};
|
|
232
|
+
const resetOptions = () => {
|
|
233
|
+
const { chat } = context.store.get();
|
|
234
|
+
previewAnchor?.release();
|
|
235
|
+
previewAnchor = null;
|
|
236
|
+
previewOwner = null;
|
|
237
|
+
previewParse = void 0;
|
|
238
|
+
suggestion = null;
|
|
239
|
+
suggestionTarget = null;
|
|
240
|
+
tableDraft.clear();
|
|
241
|
+
aiChatCommandEditors.delete(editor);
|
|
242
|
+
responseAuthor = null;
|
|
243
|
+
context.store.set({
|
|
244
|
+
_blockKey: null,
|
|
245
|
+
_blockRefs: {},
|
|
246
|
+
_changeId: null,
|
|
247
|
+
_requestId: null,
|
|
248
|
+
_tableCellRefs: {},
|
|
249
|
+
chatNodeMode: null,
|
|
250
|
+
chatNodes: [],
|
|
251
|
+
chatSelection: null,
|
|
252
|
+
mode: "insert",
|
|
253
|
+
previewValue: [],
|
|
254
|
+
toolName: null
|
|
255
|
+
});
|
|
256
|
+
try {
|
|
257
|
+
cancel();
|
|
258
|
+
} finally {
|
|
259
|
+
if (chat?.messages.length) chat.clear();
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
const resetEditor = (commandEditor, { restoreSelection = true } = {}) => {
|
|
263
|
+
const result = decideCurrentChange("reject");
|
|
264
|
+
if (result && !reviewSucceeded(result)) return result;
|
|
265
|
+
const restore = prepareTargetRestore(commandEditor);
|
|
266
|
+
resetOptions();
|
|
267
|
+
if (restoreSelection && restore && !commandEditor.read.view.isReadOnly()) restore();
|
|
268
|
+
return result;
|
|
269
|
+
};
|
|
270
|
+
const hideOptions = () => {
|
|
271
|
+
context.store.set({ open: false });
|
|
272
|
+
};
|
|
273
|
+
const promptMarkdown = (options) => {
|
|
274
|
+
const result = editor.api.markdown.serialize({
|
|
275
|
+
...options,
|
|
276
|
+
lossPolicy: "allow"
|
|
277
|
+
});
|
|
278
|
+
if (result.ok) return result.data;
|
|
279
|
+
throw new Error(result.diagnostics.map(({ message }) => message).join("\n"));
|
|
280
|
+
};
|
|
281
|
+
const scopeBlocks = (view, scope) => (scope.length ? view.read.nodes.get(scope, { match: ElementApi.isElement })?.[0].children ?? [] : view.read.children()).filter((node) => ElementApi.isElement(node));
|
|
282
|
+
const admitsAsDocument = (view, blocks, removing) => blocks.length > 0 && view.read((state) => canPlaceBlocksAtPath(state.schema, [0], blocks, { removing }));
|
|
283
|
+
const shallowestDocumentScope = (view, selectedPaths, at) => {
|
|
284
|
+
const targetPaths = selectedPaths.length || !at ? selectedPaths : [at.anchor.path, at.focus.path].flatMap((path) => {
|
|
285
|
+
const block = view.read.nodes.block({
|
|
286
|
+
at: path,
|
|
287
|
+
mode: "lowest"
|
|
288
|
+
});
|
|
289
|
+
return block ? [block[1]] : [];
|
|
290
|
+
});
|
|
291
|
+
if (!targetPaths.length) return [];
|
|
292
|
+
const around = targetPaths.map((path) => PathApi.parent(path)).reduce(PathApi.common);
|
|
293
|
+
const documentIndexes = editor.read.children().map((_, index) => index);
|
|
294
|
+
for (let depth = 0; depth <= around.length; depth++) {
|
|
295
|
+
const scope = around.slice(0, depth);
|
|
296
|
+
if (admitsAsDocument(view, scopeBlocks(view, scope), documentIndexes)) return scope;
|
|
297
|
+
}
|
|
298
|
+
return [];
|
|
299
|
+
};
|
|
300
|
+
const serializeMarkdown = (view, state, { type }) => {
|
|
301
|
+
if (type === "editor") {
|
|
302
|
+
const root = state.view.root() ?? SelectionApi.root(state.selection());
|
|
303
|
+
if (root) {
|
|
304
|
+
const rootView = projectEditorView(view, { root });
|
|
305
|
+
const selection = rootView.read.selection();
|
|
306
|
+
const scope = shallowestDocumentScope(rootView, rootView.read.selection.nodes().map(([, path]) => path), selection);
|
|
307
|
+
return promptMarkdown({
|
|
308
|
+
document: withReviewRecords(scopeBlocks(rootView, scope)),
|
|
309
|
+
projection: "proposed"
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
const document = state.value();
|
|
313
|
+
return promptMarkdown({
|
|
314
|
+
document: {
|
|
315
|
+
children: document.children,
|
|
316
|
+
...document.records ? { records: document.records } : {},
|
|
317
|
+
...document.roots ? { roots: document.roots } : {}
|
|
318
|
+
},
|
|
319
|
+
projection: "proposed"
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
if (type === "block") {
|
|
323
|
+
const root = state.view.root() ?? SelectionApi.root(state.selection()) ?? "main";
|
|
324
|
+
const blocks = proposedBlocks(view, root, state.nodes.blocks());
|
|
325
|
+
if (blocks.length === 0) return "";
|
|
326
|
+
return promptMarkdown({ document: { children: blocks } });
|
|
327
|
+
}
|
|
328
|
+
if (type === "nodeSelection") {
|
|
329
|
+
const fragment = state.fragment();
|
|
330
|
+
const value = fragment.length === 1 && ElementApi.isElement(fragment[0]) ? [{
|
|
331
|
+
children: fragment[0].children,
|
|
332
|
+
type: paragraph.schema.type
|
|
333
|
+
}] : fragment.flatMap((node) => ElementApi.isElement(node) ? [node] : []);
|
|
334
|
+
if (value.length !== fragment.length) throw new Error("Node selections must contain block elements.");
|
|
335
|
+
return promptMarkdown({
|
|
336
|
+
document: withReviewRecords(value),
|
|
337
|
+
projection: "proposed"
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
if (type !== "tableCellWithRef") return "";
|
|
341
|
+
if (!tablePlugin.installed) return "";
|
|
342
|
+
const cells = tablePlugin.read.selection()?.cells ?? [];
|
|
343
|
+
if (cells.length === 0) return "";
|
|
344
|
+
const root = state.view.root() ?? SelectionApi.root(state.selection());
|
|
345
|
+
const tableView = root ? projectEditorView(editor, { root }) : null;
|
|
346
|
+
const tableNodes = tableView?.read.nodes ?? state.nodes;
|
|
347
|
+
const tableKey = (path) => tableView ? tableView.key(path) : state.key(path);
|
|
348
|
+
const selectedNodeKeys = new Set(cells.map(([, path]) => tableKey(path)));
|
|
349
|
+
const tableEntry = tableNodes.block({ match: (node) => ElementApi.isElement(node) && node.type === tablePlugin.schema.type });
|
|
350
|
+
if (!tableEntry) return "";
|
|
351
|
+
const [table, tablePath] = tableEntry;
|
|
352
|
+
const refs = {};
|
|
353
|
+
const selectedCells = [];
|
|
354
|
+
const rows = table.children.map((row, rowIndex) => {
|
|
355
|
+
if (!ElementApi.isElement(row) || row.type !== editor.plugin(BaseTableRowPlugin).schema.type) throw new Error("Tables must contain table rows.");
|
|
356
|
+
const values = row.children.map((cell, cellIndex) => {
|
|
357
|
+
if (!ElementApi.isElement(cell) || cell.type !== editor.plugin(BaseTableCellPlugin).schema.type) throw new Error("Table rows must contain table cells.");
|
|
358
|
+
const nodeKey = tableKey([
|
|
359
|
+
...tablePath,
|
|
360
|
+
rowIndex,
|
|
361
|
+
cellIndex
|
|
362
|
+
]);
|
|
363
|
+
if (nodeKey && selectedNodeKeys.has(nodeKey)) {
|
|
364
|
+
const ref = `c${selectedCells.length + 1}`;
|
|
365
|
+
refs[ref] = { key: nodeKey };
|
|
366
|
+
selectedCells.push({
|
|
367
|
+
cell,
|
|
368
|
+
ref
|
|
369
|
+
});
|
|
370
|
+
return `<CellRef ref="${ref}" />`;
|
|
371
|
+
}
|
|
372
|
+
return cell.children.map((child) => {
|
|
373
|
+
if (!ElementApi.isElement(child)) throw new Error("Table cells must contain block elements.");
|
|
374
|
+
return promptMarkdown({ document: { children: [child] } }).trim();
|
|
375
|
+
}).filter(Boolean).join("<br/>");
|
|
376
|
+
});
|
|
377
|
+
const markdown = `| ${values.join(" | ")} |`;
|
|
378
|
+
return rowIndex === 0 ? `${markdown}\n| ${values.map(() => "---").join(" | ")} |` : markdown;
|
|
379
|
+
});
|
|
380
|
+
const cellBlocks = selectedCells.map(({ cell, ref }) => {
|
|
381
|
+
if (!cell.children.every((node) => ElementApi.isElement(node))) throw new Error("Table cells must contain block elements.");
|
|
382
|
+
return `<Cell ref="${ref}">\n${promptMarkdown({ document: { children: cell.children } }).trim()}\n</Cell>`;
|
|
383
|
+
}).join("\n\n");
|
|
384
|
+
if (!context.store.get("_requestId")) context.store.set({ _tableCellRefs: refs });
|
|
385
|
+
return `${rows.join("\n")}\n\n${cellBlocks}`;
|
|
386
|
+
};
|
|
387
|
+
const getRequestContext = (commandEditor, at, selectedNodePaths) => {
|
|
388
|
+
const current = at ?? commandEditor.read.selection() ?? editor.read.selection();
|
|
389
|
+
const root = current ? SelectionApi.root(current) : commandEditor.read.view.root();
|
|
390
|
+
const requestEditor = projectEditorView(commandEditor, root ? { root } : {});
|
|
391
|
+
const viewAt = at ? {
|
|
392
|
+
...at,
|
|
393
|
+
anchor: {
|
|
394
|
+
offset: at.anchor.offset,
|
|
395
|
+
path: at.anchor.path
|
|
396
|
+
},
|
|
397
|
+
focus: {
|
|
398
|
+
offset: at.focus.offset,
|
|
399
|
+
path: at.focus.path
|
|
400
|
+
}
|
|
401
|
+
} : null;
|
|
402
|
+
const selectedPaths = selectedNodePaths ?? requestEditor.read.selection.nodes().map(([, path]) => [...path]);
|
|
403
|
+
const scope = root ? shallowestDocumentScope(requestEditor, selectedPaths, viewAt) : [];
|
|
404
|
+
const inScope = (path) => PathApi.relative(path, scope);
|
|
405
|
+
const requestAt = viewAt ? {
|
|
406
|
+
...viewAt,
|
|
407
|
+
anchor: {
|
|
408
|
+
...viewAt.anchor,
|
|
409
|
+
path: inScope(viewAt.anchor.path)
|
|
410
|
+
},
|
|
411
|
+
focus: {
|
|
412
|
+
...viewAt.focus,
|
|
413
|
+
path: inScope(viewAt.focus.path)
|
|
414
|
+
}
|
|
415
|
+
} : null;
|
|
416
|
+
const [firstSelectedNodePath, ...remainingSelectedNodePaths] = selectedPaths.map(inScope);
|
|
417
|
+
const isNodeSelecting = !!firstSelectedNodePath;
|
|
418
|
+
const nodeSelection = (() => {
|
|
419
|
+
if (!firstSelectedNodePath || !requestAt) return null;
|
|
420
|
+
const paths = [firstSelectedNodePath, ...remainingSelectedNodePaths];
|
|
421
|
+
const findEndpoint = (pointPath) => paths.find((path) => PathApi.equals(path, pointPath) || PathApi.isAncestor(path, pointPath));
|
|
422
|
+
const anchorPath = findEndpoint(requestAt.anchor.path);
|
|
423
|
+
const focusPath = findEndpoint(requestAt.focus.path);
|
|
424
|
+
if (!anchorPath || !focusPath) throw new Error("Node selection endpoints must resolve in the request.");
|
|
425
|
+
return {
|
|
426
|
+
anchorPath,
|
|
427
|
+
focusPath,
|
|
428
|
+
mode: requestEditor.read.selection.nodeMode() ?? "block",
|
|
429
|
+
paths
|
|
430
|
+
};
|
|
431
|
+
})();
|
|
432
|
+
const blockRefs = {};
|
|
433
|
+
const blocks = (isNodeSelecting ? requestEditor.read.nodes.blocks() : requestEditor.read.nodes.blocks({ at: viewAt && RangeApi.isExpanded(viewAt) ? viewAt : scope })).flatMap(([, path], index) => {
|
|
434
|
+
const key = requestEditor.key(path);
|
|
435
|
+
if (!key) return [];
|
|
436
|
+
const ref = `b${index + 1}`;
|
|
437
|
+
blockRefs[ref] = { key };
|
|
438
|
+
return [{
|
|
439
|
+
path: inScope(path),
|
|
440
|
+
ref
|
|
441
|
+
}];
|
|
442
|
+
});
|
|
443
|
+
const tableCellRefs = {};
|
|
444
|
+
const tableCells = tablePlugin.installed ? (requestEditor.plugin(BaseTablePlugin).read.selection({ at: viewAt ?? void 0 })?.cells ?? []).flatMap(([, path], index) => {
|
|
445
|
+
const key = requestEditor.key(path);
|
|
446
|
+
if (!key) return [];
|
|
447
|
+
const ref = `c${index + 1}`;
|
|
448
|
+
tableCellRefs[ref] = { key };
|
|
449
|
+
return [{
|
|
450
|
+
path: inScope(path),
|
|
451
|
+
ref
|
|
452
|
+
}];
|
|
453
|
+
}) : [];
|
|
454
|
+
context.store.set({
|
|
455
|
+
_blockRefs: blockRefs,
|
|
456
|
+
_tableCellRefs: tableCellRefs
|
|
457
|
+
});
|
|
458
|
+
return {
|
|
459
|
+
children: scopeBlocks(requestEditor, scope).map(withoutReviewMarks),
|
|
460
|
+
nodeSelection,
|
|
461
|
+
refs: {
|
|
462
|
+
blocks,
|
|
463
|
+
tableCells
|
|
464
|
+
},
|
|
465
|
+
selection: requestAt
|
|
466
|
+
};
|
|
467
|
+
};
|
|
468
|
+
const resolvePrompt = (prompt, params) => {
|
|
469
|
+
if (typeof prompt === "function") return prompt(params);
|
|
470
|
+
if (typeof prompt === "string") return prompt;
|
|
471
|
+
if (params.isNodeSelecting && prompt.nodeSelecting) return prompt.nodeSelecting;
|
|
472
|
+
if (params.isSelecting && prompt.selecting) return prompt.selecting;
|
|
473
|
+
return prompt.default;
|
|
474
|
+
};
|
|
475
|
+
const getPrompt = (state, { prompt = "" }) => resolvePrompt(prompt, {
|
|
476
|
+
editor,
|
|
477
|
+
isNodeSelecting: state.selection.nodes().length > 0,
|
|
478
|
+
isSelecting: state.selection.isExpanded()
|
|
479
|
+
});
|
|
480
|
+
const parseSuggestion = (answer, target) => {
|
|
481
|
+
let source = cloneDeep(context.store.get("chatNodes").map(({ node }) => node));
|
|
482
|
+
let tableCellSource = false;
|
|
483
|
+
const first = source[0];
|
|
484
|
+
if (source.length === 1 && ElementApi.isElement(first) && tablePlugin.installed && first.type === tablePlugin.schema.type && first.children.length === 1) {
|
|
485
|
+
const row = first.children[0];
|
|
486
|
+
const cell = ElementApi.isElement(row) && row.children.length === 1 ? row.children[0] : void 0;
|
|
487
|
+
const tableCell = editor.plugin(BaseTableCellPlugin);
|
|
488
|
+
if (tableCell.installed && ElementApi.isElement(cell) && cell.type === tableCell.schema.type) {
|
|
489
|
+
source = [...cell.children];
|
|
490
|
+
tableCellSource = true;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
if (!tableCellSource && ElementApi.isElementList(answer)) {
|
|
494
|
+
if (target.kind === "blocks") return suggestionBlocks(editor, editor.read, {
|
|
495
|
+
answer,
|
|
496
|
+
roundTrip: target.roundTrip,
|
|
497
|
+
source: target.source
|
|
498
|
+
});
|
|
499
|
+
const block = source[0];
|
|
500
|
+
return landAIOutput(editor, editor.read, answer, {
|
|
501
|
+
block: ElementApi.isElement(block) ? block : void 0,
|
|
502
|
+
kind: "kept"
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
return answer.map((node, index) => {
|
|
506
|
+
const sourceNode = source[index];
|
|
507
|
+
if (!ElementApi.isElement(node) || !ElementApi.isElement(sourceNode) || sourceNode.type !== node.type) return node;
|
|
508
|
+
return {
|
|
509
|
+
...NodeApi.extractProps(sourceNode),
|
|
510
|
+
...node,
|
|
511
|
+
children: node.children
|
|
512
|
+
};
|
|
513
|
+
});
|
|
514
|
+
};
|
|
515
|
+
const finishCompleteAction = () => {
|
|
516
|
+
try {
|
|
517
|
+
resetOptions();
|
|
518
|
+
} finally {
|
|
519
|
+
hideOptions();
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
const landAndClose = (actionEditor, land) => {
|
|
523
|
+
let closed = false;
|
|
524
|
+
if (actionEditor?.update((tx, { afterCommit }) => {
|
|
525
|
+
if (!land(tx)) return false;
|
|
526
|
+
afterCommit(() => {
|
|
527
|
+
closed = true;
|
|
528
|
+
finishCompleteAction();
|
|
529
|
+
});
|
|
530
|
+
return true;
|
|
531
|
+
}) && !closed) finishCompleteAction();
|
|
532
|
+
};
|
|
533
|
+
const getActionChatBlocks = (tx) => {
|
|
534
|
+
const chatNodes = context.store.get("chatNodes");
|
|
535
|
+
const entries = chatNodes.flatMap(({ nodeKey }) => {
|
|
536
|
+
const entry = tx.nodes.get(nodeKey, { match: ElementApi.isElement });
|
|
537
|
+
return entry ? [entry] : [];
|
|
538
|
+
});
|
|
539
|
+
if (entries.length !== chatNodes.length || new Set(entries.map(([node]) => tx.key(node))).size !== chatNodes.length) return [];
|
|
540
|
+
return entries.toSorted(([, a], [, b]) => PathApi.compare(a, b));
|
|
541
|
+
};
|
|
542
|
+
const selectActionEntries = (tx, entries) => {
|
|
543
|
+
tx.selection.setNodes(entries.map(([node]) => node));
|
|
544
|
+
};
|
|
545
|
+
const resolveActionBlocks = (tx, nodes) => {
|
|
546
|
+
const entries = nodes.flatMap((node) => {
|
|
547
|
+
const entry = tx.nodes.get(tx.key(node), { match: ElementApi.isElement });
|
|
548
|
+
return entry ? [entry] : [];
|
|
549
|
+
});
|
|
550
|
+
if (entries.length !== nodes.length) throw new Error("Inserted AI blocks must resolve exactly once.");
|
|
551
|
+
return entries;
|
|
552
|
+
};
|
|
553
|
+
const insertActionBlocks = (tx, source, format, target) => {
|
|
554
|
+
const anchor = resolveInsertionAnchor(editor, tx, target);
|
|
555
|
+
const blocks = formatAIOutput({
|
|
556
|
+
blocks: source,
|
|
557
|
+
format: anchor === target ? format : "none",
|
|
558
|
+
sourceBlock: target[0]
|
|
559
|
+
});
|
|
560
|
+
if (!blocks) return false;
|
|
561
|
+
tx.history.newBatch();
|
|
562
|
+
const nodes = placeActionBlocks(tx, landAIOutput(editor, tx, blocks, {
|
|
563
|
+
block: anchor[0],
|
|
564
|
+
kind: "kept"
|
|
565
|
+
}), PathApi.next(anchor[1]));
|
|
566
|
+
const inserted = nodes && tx.blocks.insert(nodes, { after: tx.key(anchor[0]) });
|
|
567
|
+
if (!inserted) return false;
|
|
568
|
+
tx.selection.setNodes(inserted);
|
|
569
|
+
return true;
|
|
570
|
+
};
|
|
571
|
+
const placeActionBlocks = (tx, nodes, first, removing) => {
|
|
572
|
+
const parentPath = PathApi.parent(first);
|
|
573
|
+
const index = first.at(-1) ?? 0;
|
|
574
|
+
const placed = [];
|
|
575
|
+
for (const [offset, node] of nodes.entries()) {
|
|
576
|
+
const block = placeElementAt(tx.schema, node, {
|
|
577
|
+
at: [...parentPath, index + offset],
|
|
578
|
+
root: tx.view.root()
|
|
579
|
+
});
|
|
580
|
+
if (!block) return null;
|
|
581
|
+
placed.push(block);
|
|
582
|
+
}
|
|
583
|
+
if (removing && !canPlaceBlocksAtPath(tx.schema, first, placed, {
|
|
584
|
+
removing,
|
|
585
|
+
root: tx.view.root()
|
|
586
|
+
})) return null;
|
|
587
|
+
return placed;
|
|
588
|
+
};
|
|
589
|
+
const replaceActionBlocks = (tx, nodes, entries) => {
|
|
590
|
+
const selectedKeys = entries.map(([node]) => tx.key(node));
|
|
591
|
+
const firstKey = selectedKeys[0];
|
|
592
|
+
const first = entries[0];
|
|
593
|
+
if (!firstKey || !first) return false;
|
|
594
|
+
const removing = entries.flatMap(([, path]) => PathApi.equals(PathApi.parent(path), PathApi.parent(first[1])) ? [path.at(-1) ?? 0] : []);
|
|
595
|
+
const replacingFirst = placeActionBlocks(tx, nodes, first[1], removing);
|
|
596
|
+
const keepingRequiredFirst = replacingFirst ? null : placeActionBlocks(tx, nodes, PathApi.next(first[1]));
|
|
597
|
+
const landed = replacingFirst ?? keepingRequiredFirst;
|
|
598
|
+
if (!landed) return false;
|
|
599
|
+
if (replacingFirst) tx.nodes.insert(replacingFirst, { at: firstKey });
|
|
600
|
+
else if (!tx.blocks.insert(landed, { after: firstKey })) return false;
|
|
601
|
+
selectActionEntries(tx, resolveActionBlocks(tx, landed));
|
|
602
|
+
for (const key of (replacingFirst ? selectedKeys : selectedKeys.slice(1)).toReversed()) tx.nodes.remove({ at: key });
|
|
603
|
+
return true;
|
|
604
|
+
};
|
|
605
|
+
const getActionPreviewSource = () => {
|
|
606
|
+
if (!previewOwner?.final || previewOwner.requestId !== context.store.get("_requestId")) return;
|
|
607
|
+
const source = [...context.store.get("previewValue")];
|
|
608
|
+
if (source.every((node) => editor.read.nodes.isEmpty(node))) return;
|
|
609
|
+
return source;
|
|
610
|
+
};
|
|
611
|
+
const writeSuggestion = (tx, target, nextNodes) => {
|
|
612
|
+
const paths = target.kind === "blocks" ? target.paths : [];
|
|
613
|
+
const sourceNodes = paths.flatMap((path) => {
|
|
614
|
+
const entry = tx.nodes.get(path, { match: ElementApi.isElement });
|
|
615
|
+
return entry ? [entry[0]] : [];
|
|
616
|
+
});
|
|
617
|
+
if (target.kind === "blocks" && sourceNodes.length === paths.length && isEqual(sourceNodes.map(withoutText), nextNodes.map(withoutText))) {
|
|
618
|
+
const edits = sourceNodes.flatMap((sourceNode, blockIndex) => {
|
|
619
|
+
const nextNode = nextNodes[blockIndex];
|
|
620
|
+
const blockPath = paths[blockIndex];
|
|
621
|
+
if (!nextNode || !blockPath) return [];
|
|
622
|
+
const afterTexts = [...NodeApi.texts(nextNode)];
|
|
623
|
+
return [...NodeApi.texts(sourceNode)].flatMap(([before, path], textIndex) => {
|
|
624
|
+
const after = afterTexts[textIndex]?.[0];
|
|
625
|
+
return after && before.text !== after.text ? textEdits(before.text, after.text).map((edit) => ({
|
|
626
|
+
...edit,
|
|
627
|
+
path: [...blockPath, ...path]
|
|
628
|
+
})) : [];
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
for (const { from, path, text, to } of edits.toSorted((left, right) => PathApi.compare(right.path, left.path) || right.from - left.from)) {
|
|
632
|
+
if (to > from) tx.text.delete({ at: {
|
|
633
|
+
anchor: {
|
|
634
|
+
offset: from,
|
|
635
|
+
path
|
|
636
|
+
},
|
|
637
|
+
focus: {
|
|
638
|
+
offset: to,
|
|
639
|
+
path
|
|
640
|
+
}
|
|
641
|
+
} });
|
|
642
|
+
if (text) tx.text.insert(text, { at: {
|
|
643
|
+
offset: from,
|
|
644
|
+
path
|
|
645
|
+
} });
|
|
646
|
+
}
|
|
647
|
+
return edits.length > 0;
|
|
648
|
+
}
|
|
649
|
+
return tx.slice.replace(ContentSlice.fromJSON({
|
|
650
|
+
content: nextNodes,
|
|
651
|
+
openEnd: 0,
|
|
652
|
+
openStart: 0
|
|
653
|
+
}), { at: target.range });
|
|
654
|
+
};
|
|
655
|
+
const applySuggestion = (commandEditor, content, { requestId } = {}) => {
|
|
656
|
+
const state = context.store.get();
|
|
657
|
+
if (requestId !== void 0 && requestId !== state._requestId) return false;
|
|
658
|
+
const actionEditor = getActionEditor(commandEditor);
|
|
659
|
+
if (!actionEditor || actionEditor.read.view.isReadOnly()) return false;
|
|
660
|
+
const sourceRoots = new Set(state.chatNodes.map(({ nodeKey }) => resolveTargetRoot(commandEditor, nodeKey)?.root));
|
|
661
|
+
const root = actionEditor.read.view.root();
|
|
662
|
+
if (!suggestionTarget && (sourceRoots.size !== 1 || !sourceRoots.has(root))) return false;
|
|
663
|
+
const capturedSelection = resolveChatSelection();
|
|
664
|
+
if (state.chatSelection && !capturedSelection) return false;
|
|
665
|
+
const currentChangeId = state._changeId;
|
|
666
|
+
const parsed = editor.api.markdown.parseSlice(content);
|
|
667
|
+
if (!parsed.ok) {
|
|
668
|
+
const result = decideCurrentChange("reject");
|
|
669
|
+
if (!result || reviewSucceeded(result)) {
|
|
670
|
+
suggestion = null;
|
|
671
|
+
suggestionTarget = null;
|
|
672
|
+
}
|
|
673
|
+
return false;
|
|
674
|
+
}
|
|
675
|
+
const targetKeys = state.chatNodes.map(({ nodeKey }) => nodeKey);
|
|
676
|
+
if (targetKeys.length === 0 || new Set(targetKeys).size !== targetKeys.length) return false;
|
|
677
|
+
let target = suggestionTarget;
|
|
678
|
+
if (!target) {
|
|
679
|
+
const entries = targetKeys.flatMap((key) => {
|
|
680
|
+
const entry = actionEditor.read.nodes.get(key, { match: ElementApi.isElement });
|
|
681
|
+
return entry ? [entry] : [];
|
|
682
|
+
});
|
|
683
|
+
if (entries.length !== targetKeys.length) return false;
|
|
684
|
+
const ordered = entries.toSorted(([, a], [, b]) => PathApi.compare(a, b));
|
|
685
|
+
const first = ordered[0];
|
|
686
|
+
const last = ordered.at(-1);
|
|
687
|
+
if (!first || !last) return false;
|
|
688
|
+
const anchor = actionEditor.read.points.start(first[1]);
|
|
689
|
+
const focus = actionEditor.read.points.end(last[1]);
|
|
690
|
+
const capturedEdges = capturedSelection ? RangeApi.edges(capturedSelection) : null;
|
|
691
|
+
const coversWholeBlocks = !capturedEdges || !!anchor && !!focus && PointApi.equals(capturedEdges[0], anchor) && PointApi.equals(capturedEdges[1], focus);
|
|
692
|
+
const range = capturedSelection ?? (anchor && focus ? {
|
|
693
|
+
anchor,
|
|
694
|
+
focus
|
|
695
|
+
} : actionEditor.read.ranges.fromEntries(ordered));
|
|
696
|
+
if (!range) return false;
|
|
697
|
+
if (coversWholeBlocks) {
|
|
698
|
+
const source = proposedBlocks(actionEditor, root ?? "main", ordered);
|
|
699
|
+
const serialized = source.length > 0 ? editor.api.markdown.serialize({ document: { children: source } }) : null;
|
|
700
|
+
const reparsed = serialized?.ok ? editor.api.markdown.parseSlice(serialized.data) : void 0;
|
|
701
|
+
target = {
|
|
702
|
+
kind: "blocks",
|
|
703
|
+
paths: ordered.map(([, path]) => path),
|
|
704
|
+
range,
|
|
705
|
+
roundTrip: reparsed?.ok && ElementApi.isElementList(reparsed.slice.content) ? reparsed.slice.content : null,
|
|
706
|
+
source
|
|
707
|
+
};
|
|
708
|
+
} else target = {
|
|
709
|
+
kind: "text",
|
|
710
|
+
range
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
const nextNodes = parseSuggestion(parsed.slice.content, target);
|
|
714
|
+
if (suggestion && actionEditor.read.children() !== suggestion.children) return false;
|
|
715
|
+
const previous = currentChangeId ? editor.plugin(AuthoredPlugin).read.change(currentChangeId) : null;
|
|
716
|
+
if (previous) {
|
|
717
|
+
let withdrawn = false;
|
|
718
|
+
actionEditor.update((tx, { afterCommit }) => {
|
|
719
|
+
tx.history.merge();
|
|
720
|
+
tx.plugin(AuthoredPlugin).withdraw([previous]);
|
|
721
|
+
afterCommit(({ snapshot }) => {
|
|
722
|
+
withdrawn = true;
|
|
723
|
+
suggestion &&= {
|
|
724
|
+
...suggestion,
|
|
725
|
+
children: snapshot.children
|
|
726
|
+
};
|
|
727
|
+
});
|
|
728
|
+
});
|
|
729
|
+
if (!withdrawn || suggestion && actionEditor.read.children() !== suggestion.children) return false;
|
|
730
|
+
}
|
|
731
|
+
const response = parsed.slice.content.filter((node) => ElementApi.isElement(node));
|
|
732
|
+
let publishedChangeId = null;
|
|
733
|
+
const publish = (changeId, children = actionEditor.read.children()) => {
|
|
734
|
+
publishedChangeId = changeId;
|
|
735
|
+
suggestion = {
|
|
736
|
+
children,
|
|
737
|
+
response
|
|
738
|
+
};
|
|
739
|
+
suggestionTarget = target;
|
|
740
|
+
context.store.set({
|
|
741
|
+
_changeId: changeId,
|
|
742
|
+
previewValue: []
|
|
743
|
+
});
|
|
744
|
+
const published = pendingChange();
|
|
745
|
+
if (published) responseAuthor = {
|
|
746
|
+
authorId: published.authorId,
|
|
747
|
+
requestId: context.store.get("_requestId")
|
|
748
|
+
};
|
|
749
|
+
};
|
|
750
|
+
if (actionEditor.update((tx, { afterCommit }) => {
|
|
751
|
+
const changeId = tx.plugin(AuthoredPlugin).propose(currentChangeId ? { changeId: currentChangeId } : void 0);
|
|
752
|
+
if (currentChangeId) tx.history.merge();
|
|
753
|
+
else tx.history.newBatch();
|
|
754
|
+
if (writeSuggestion(tx, target, nextNodes)) afterCommit(({ snapshot }) => publish(changeId, snapshot.children));
|
|
755
|
+
return true;
|
|
756
|
+
}) && publishedChangeId === null) publish(null);
|
|
757
|
+
return publishedChangeId !== null;
|
|
758
|
+
};
|
|
759
|
+
const acceptAIResponse = (commandEditor) => {
|
|
760
|
+
if (context.store.get("_changeId")) {
|
|
761
|
+
const result = decideCurrentChange("accept");
|
|
762
|
+
if (result && reviewSucceeded(result)) finishCompleteAction();
|
|
763
|
+
return result;
|
|
764
|
+
}
|
|
765
|
+
responseAuthor = null;
|
|
766
|
+
if (tableDraft.size > 0) {
|
|
767
|
+
landAndClose(getActionEditor(commandEditor), (tx) => {
|
|
768
|
+
const targets = [...tableDraft].map(([key, draft]) => ({
|
|
769
|
+
draft,
|
|
770
|
+
entry: resolveTargetRoot(commandEditor, key)?.root === tx.view.root() ? tx.nodes.get(key, { match: ElementApi.isElement }) : void 0
|
|
771
|
+
}));
|
|
772
|
+
if (targets.some(({ entry }) => !entry)) return false;
|
|
773
|
+
tx.history.newBatch();
|
|
774
|
+
for (const { draft, entry } of targets) if (entry) tx.nodes.replaceChildren(cloneDeep(draft.children), { at: tx.key(entry[0]) });
|
|
775
|
+
return true;
|
|
776
|
+
});
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
if (context.store.get("mode") === "chat") {
|
|
780
|
+
completeDetachedOutput(commandEditor, "replaceSelection", "single");
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
landAndClose(getActionEditor(commandEditor), (tx) => {
|
|
784
|
+
const output = getActionPreviewSource();
|
|
785
|
+
const blockKey = context.store.get("_blockKey");
|
|
786
|
+
const target = blockKey ? tx.nodes.get(blockKey, { match: ElementApi.isElement }) : void 0;
|
|
787
|
+
if (!target || !output) return false;
|
|
788
|
+
tx.history.newBatch();
|
|
789
|
+
const [node, path] = target;
|
|
790
|
+
const replace = node.type === paragraph.schema.type && tx.nodes.isEmpty(node);
|
|
791
|
+
const [anchor, anchorPath] = replace ? target : resolveInsertionAnchor(editor, tx, target);
|
|
792
|
+
const firstPath = replace ? path : PathApi.next(anchorPath);
|
|
793
|
+
const firstIndex = firstPath.at(-1);
|
|
794
|
+
if (firstIndex === void 0) return false;
|
|
795
|
+
const blocks = cloneDeep(replace ? isListItem(node) ? landAIOutput(editor, tx, fillEmptyListItem(output, node), {
|
|
796
|
+
block: node,
|
|
797
|
+
kind: "replaced"
|
|
798
|
+
}) : landAIOutput(editor, tx, output, {
|
|
799
|
+
kind: "line",
|
|
800
|
+
line: target
|
|
801
|
+
}) : landAIOutput(editor, tx, output, {
|
|
802
|
+
block: anchor,
|
|
803
|
+
kind: "kept"
|
|
804
|
+
}));
|
|
805
|
+
const placed = placeActionBlocks(tx, blocks, firstPath, replace ? [firstIndex] : void 0);
|
|
806
|
+
if (!placed) return false;
|
|
807
|
+
let last;
|
|
808
|
+
if (replace) {
|
|
809
|
+
if (!tx.nodes.replace(placed, { at: path })) return false;
|
|
810
|
+
last = [...firstPath.slice(0, -1), firstIndex + placed.length - 1];
|
|
811
|
+
} else {
|
|
812
|
+
last = tx.blocks.insert(placed, { after: anchorPath })?.at(-1);
|
|
813
|
+
if (!last) return false;
|
|
814
|
+
}
|
|
815
|
+
const end = tx.points.end(last);
|
|
816
|
+
if (end) tx.selection.set(end);
|
|
817
|
+
return true;
|
|
818
|
+
});
|
|
819
|
+
};
|
|
820
|
+
const completeDetachedOutput = (commandEditor, action, format, response) => {
|
|
821
|
+
const land = (tx) => {
|
|
822
|
+
const source = response ?? getActionPreviewSource();
|
|
823
|
+
if (!source) return false;
|
|
824
|
+
const chatSelection = resolveChatSelection();
|
|
825
|
+
if (context.store.get("chatSelection") && !chatSelection) return false;
|
|
826
|
+
if (chatSelection) {
|
|
827
|
+
const [start, end] = RangeApi.edges(chatSelection);
|
|
828
|
+
const block = tx.nodes.block({ at: action === "insertBelow" ? end : start });
|
|
829
|
+
if (!block) return false;
|
|
830
|
+
if (action === "insertBelow") return insertActionBlocks(tx, cloneDeep(source), format, block);
|
|
831
|
+
const blocks = formatAIOutput({
|
|
832
|
+
blocks: cloneDeep(source),
|
|
833
|
+
format,
|
|
834
|
+
sourceBlock: block[0]
|
|
835
|
+
});
|
|
836
|
+
if (!blocks) return false;
|
|
837
|
+
tx.history.newBatch();
|
|
838
|
+
const whole = wholeTextBlocks(tx, chatSelection, (first) => landAIOutput(editor, tx, blocks, {
|
|
839
|
+
block: first,
|
|
840
|
+
kind: "replaced"
|
|
841
|
+
}));
|
|
842
|
+
if (whole) return replaceActionBlocks(tx, whole.nodes, whole.blocks);
|
|
843
|
+
const landed = landAIOutput(editor, tx, blocks, {
|
|
844
|
+
block: block[0],
|
|
845
|
+
kind: "kept"
|
|
846
|
+
});
|
|
847
|
+
const openTextBlock = (node) => node && !tx.schema.isVoid(node) && node.children.every((child) => TextApi.isText(child) || tx.schema.isInline(child)) ? 1 : 0;
|
|
848
|
+
const [head, ...rest] = landed;
|
|
849
|
+
const tail = head && openTextBlock(head) ? placeActionBlocks(tx, rest, PathApi.next(block[1])) : rest;
|
|
850
|
+
if (!tail) return false;
|
|
851
|
+
const content = head ? [head, ...tail] : landed;
|
|
852
|
+
return tx.slice.replace(ContentSlice.fromJSON({
|
|
853
|
+
content,
|
|
854
|
+
openStart: openTextBlock(content[0]),
|
|
855
|
+
openEnd: openTextBlock(content.at(-1))
|
|
856
|
+
}), { at: chatSelection });
|
|
857
|
+
}
|
|
858
|
+
const selected = getActionChatBlocks(tx);
|
|
859
|
+
if (selected.length === 0) return false;
|
|
860
|
+
const sourceBlock = action === "insertBelow" ? selected.at(-1) : selected[0];
|
|
861
|
+
if (!sourceBlock) return false;
|
|
862
|
+
if (action === "insertBelow") return insertActionBlocks(tx, cloneDeep(source), format, sourceBlock);
|
|
863
|
+
const blocks = formatAIOutput({
|
|
864
|
+
blocks: cloneDeep(source),
|
|
865
|
+
format: format === "single" && selected.length > 1 ? "none" : format,
|
|
866
|
+
sourceBlock: sourceBlock[0]
|
|
867
|
+
});
|
|
868
|
+
if (!blocks) return false;
|
|
869
|
+
tx.history.newBatch();
|
|
870
|
+
return replaceActionBlocks(tx, landAIOutput(editor, tx, blocks, {
|
|
871
|
+
block: sourceBlock[0],
|
|
872
|
+
kind: "replaced"
|
|
873
|
+
}), selected);
|
|
874
|
+
};
|
|
875
|
+
landAndClose(getActionEditor(commandEditor), land);
|
|
876
|
+
};
|
|
877
|
+
const show = (commandEditor, target) => {
|
|
878
|
+
const result = resetEditor(commandEditor);
|
|
879
|
+
if (result && !reviewSucceeded(result)) return result;
|
|
880
|
+
if (!target && commandEditor.read.selection.nodes().length === 0 && commandEditor.read.selection.isCollapsed() && !commandEditor.read.selection.isAtBlockEnd()) {
|
|
881
|
+
const block = commandEditor.read.nodes.block();
|
|
882
|
+
if (block && !commandEditor.read.nodes.isEmpty(block[0])) commandEditor.update.selection.setNodes([block[1]]);
|
|
883
|
+
}
|
|
884
|
+
captureTarget(commandEditor, target);
|
|
885
|
+
aiChatCommandEditors.set(editor, commandEditor);
|
|
886
|
+
context.store.set({ toolName: null });
|
|
887
|
+
context.store.get().chat?.clear();
|
|
888
|
+
context.store.set({ open: true });
|
|
889
|
+
return result;
|
|
890
|
+
};
|
|
891
|
+
return {
|
|
892
|
+
commands: ({ handle }) => [handle(editorCommands.insertText, ({ input, state }) => {
|
|
893
|
+
const { trigger, triggerPreviousCharPattern, triggerQuery } = context.store.get();
|
|
894
|
+
const selection = state.selection();
|
|
895
|
+
const matches = trigger instanceof RegExp ? trigger.test(input.text) : Array.isArray(trigger) ? trigger.includes(input.text) : input.text === trigger;
|
|
896
|
+
if (!selection || !matches || triggerQuery && !triggerQuery(context.editor) || isInputRuleVetoed(context.editor, state)) return false;
|
|
897
|
+
const before = state.points.before(selection);
|
|
898
|
+
const previous = before ? state.text.string({
|
|
899
|
+
anchor: before,
|
|
900
|
+
focus: selection.anchor
|
|
901
|
+
}) : "";
|
|
902
|
+
const block = state.nodes.block({ mode: "highest" });
|
|
903
|
+
if (!triggerPreviousCharPattern?.test(previous) || !block || !state.nodes.isEmpty(block[0])) return false;
|
|
904
|
+
const key = state.key(block[1]);
|
|
905
|
+
if (!key) return false;
|
|
906
|
+
return state.transaction((tx) => {
|
|
907
|
+
tx.effects.emit(aiChatShowEffect, key);
|
|
908
|
+
});
|
|
909
|
+
})],
|
|
910
|
+
effectTypes: [aiChatShowEffect],
|
|
911
|
+
on: { commit({ commit }) {
|
|
912
|
+
const showEffect = commit.effects.find((effect) => effect.type === aiChatShowEffect);
|
|
913
|
+
if (showEffect) {
|
|
914
|
+
const start = editor.read.points.start(showEffect.value);
|
|
915
|
+
show(editor, start && {
|
|
916
|
+
anchor: start,
|
|
917
|
+
focus: start
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
} },
|
|
921
|
+
api: ({ editor: commandEditor }) => ({
|
|
922
|
+
/**
|
|
923
|
+
* Commit the final draft in one history batch. Refuses a partial or
|
|
924
|
+
* invalid draft and a target that no longer exists.
|
|
925
|
+
*/
|
|
926
|
+
accept: () => acceptAIResponse(commandEditor),
|
|
927
|
+
/** Close the session, cancel its request, and discard any unapplied draft. */
|
|
928
|
+
hide: ({ focus = true } = {}) => {
|
|
929
|
+
let result;
|
|
930
|
+
try {
|
|
931
|
+
result = resetEditor(commandEditor, { restoreSelection: focus });
|
|
932
|
+
} finally {
|
|
933
|
+
if (!result || reviewSucceeded(result)) hideOptions();
|
|
934
|
+
}
|
|
935
|
+
if (result && !reviewSucceeded(result)) return result;
|
|
936
|
+
if (focus) commandEditor.api.dom.focus();
|
|
937
|
+
return result;
|
|
938
|
+
},
|
|
939
|
+
insertBelow: ({ format = "single" } = {}) => {
|
|
940
|
+
const response = suggestion?.response;
|
|
941
|
+
if (response && context.store.get("_changeId") && (!pendingChange() || !reviewSucceeded(decideCurrentChange("reject")))) return;
|
|
942
|
+
completeDetachedOutput(commandEditor, "insertBelow", format, response);
|
|
943
|
+
},
|
|
944
|
+
/** Cancel the request, discard its draft, and request a new response. */
|
|
945
|
+
reload: () => {
|
|
946
|
+
const { chat, toolName } = context.store.get();
|
|
947
|
+
const result = decideCurrentChange("reject");
|
|
948
|
+
if (result && !reviewSucceeded(result)) return result;
|
|
949
|
+
cancel();
|
|
950
|
+
suggestion = null;
|
|
951
|
+
suggestionTarget = null;
|
|
952
|
+
previewOwner = null;
|
|
953
|
+
previewParse = void 0;
|
|
954
|
+
context.store.set({
|
|
955
|
+
_blockKey: null,
|
|
956
|
+
_requestId: null,
|
|
957
|
+
previewValue: []
|
|
958
|
+
});
|
|
959
|
+
tableDraft.clear();
|
|
960
|
+
if (!restoreTarget(commandEditor)) return void 0;
|
|
961
|
+
captureTarget(commandEditor);
|
|
962
|
+
aiChatCommandEditors.set(editor, commandEditor);
|
|
963
|
+
context.store.set({ _requestId: crypto.randomUUID() });
|
|
964
|
+
chat?.regenerate({ body: { ctx: {
|
|
965
|
+
...getRequestContext(commandEditor, commandEditor.read.selection() ?? editor.read.selection()),
|
|
966
|
+
toolName
|
|
967
|
+
} } });
|
|
968
|
+
return result;
|
|
969
|
+
},
|
|
970
|
+
replaceSelection: ({ format = "single" } = {}) => {
|
|
971
|
+
completeDetachedOutput(commandEditor, "replaceSelection", format);
|
|
972
|
+
},
|
|
973
|
+
/** Cancel the request and discard its draft without publishing it. */
|
|
974
|
+
reset: () => resetEditor(commandEditor),
|
|
975
|
+
/**
|
|
976
|
+
* Publish accumulated output to its request-owned review presentation.
|
|
977
|
+
* A `final` parse (the default) is strict; a response Markdown cannot
|
|
978
|
+
* represent clears the draft.
|
|
979
|
+
*/
|
|
980
|
+
setPreview: (content, { final = true, requestId } = {}) => {
|
|
981
|
+
const state = context.store.get();
|
|
982
|
+
if (requestId !== void 0 && requestId !== state._requestId) return;
|
|
983
|
+
if (state.toolName === "edit" && state.mode === "chat") return applySuggestion(commandEditor, content, { requestId });
|
|
984
|
+
const ownerRequestId = requestId ?? state._requestId;
|
|
985
|
+
const invalidatePreview = () => {
|
|
986
|
+
previewOwner = {
|
|
987
|
+
final: false,
|
|
988
|
+
requestId: ownerRequestId
|
|
989
|
+
};
|
|
990
|
+
previewParse = void 0;
|
|
991
|
+
context.store.set({ previewValue: [] });
|
|
992
|
+
};
|
|
993
|
+
let targetKey = state._blockKey;
|
|
994
|
+
if (!targetKey) {
|
|
995
|
+
const selection = previewAnchor ? previewAnchor.resolve() : state.chatSelection ?? commandEditor.read.selection();
|
|
996
|
+
const actionEditor = getActionEditor(commandEditor);
|
|
997
|
+
if (previewAnchor && !selection || !actionEditor) {
|
|
998
|
+
invalidatePreview();
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
const target = state.chatNodes.length > 0 && !state.chatSelection ? actionEditor.read.nodes.get(state.chatNodes[0].nodeKey, { match: ElementApi.isElement }) : actionEditor.read.nodes.block({ ...selection ? { at: RangeApi.start(selection) } : {} });
|
|
1002
|
+
if (!target) {
|
|
1003
|
+
invalidatePreview();
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
targetKey = actionEditor.key(target[0]);
|
|
1007
|
+
if (!previewAnchor && selection && (state.chatSelection || state.chatNodes.length === 0)) captureSelection(actionEditor, selection);
|
|
1008
|
+
}
|
|
1009
|
+
if (!commandEditor.read.nodes.get(targetKey)) {
|
|
1010
|
+
invalidatePreview();
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
const previous = previewParse;
|
|
1014
|
+
const parsed = content ? commandEditor.api.markdown.parseSlice(content, final ? { previous: previous?.result } : {
|
|
1015
|
+
lossPolicy: "allow",
|
|
1016
|
+
partial: true,
|
|
1017
|
+
previous: previous?.result
|
|
1018
|
+
}) : null;
|
|
1019
|
+
previewParse = void 0;
|
|
1020
|
+
if (parsed && !parsed.ok) {
|
|
1021
|
+
invalidatePreview();
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
const previewValue = parsed?.slice.content ?? [];
|
|
1025
|
+
if (!previewValue.every((node) => ElementApi.isElement(node))) {
|
|
1026
|
+
invalidatePreview();
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
const reused = previous?.result.ok ? previous.result.slice.content : [];
|
|
1030
|
+
previewOwner = {
|
|
1031
|
+
final,
|
|
1032
|
+
requestId: ownerRequestId
|
|
1033
|
+
};
|
|
1034
|
+
context.store.set({
|
|
1035
|
+
_blockKey: targetKey,
|
|
1036
|
+
previewValue: previewValue.map((node, index) => node === reused[index] ? previous?.stored[index] ?? node : node)
|
|
1037
|
+
});
|
|
1038
|
+
if (parsed && !final) previewParse = {
|
|
1039
|
+
result: parsed,
|
|
1040
|
+
stored: context.store.get("previewValue")
|
|
1041
|
+
};
|
|
1042
|
+
},
|
|
1043
|
+
/** Publish a complete cell response in the current table draft. */
|
|
1044
|
+
setTablePreview: ({ content, ref }, { requestId } = {}) => {
|
|
1045
|
+
if (requestId !== void 0 && requestId !== context.store.get("_requestId")) return;
|
|
1046
|
+
const refs = context.store.get("_tableCellRefs");
|
|
1047
|
+
const target = Object.hasOwn(refs, ref) ? refs[ref] : void 0;
|
|
1048
|
+
if (!target) return;
|
|
1049
|
+
const actionEditor = getActionEditor(commandEditor, target.key);
|
|
1050
|
+
if (!actionEditor || actionEditor.read.view.root() !== getActionEditor(commandEditor)?.read.view.root()) return;
|
|
1051
|
+
const cell = actionEditor.read.nodes.get(target.key, { match: ElementApi.isElement });
|
|
1052
|
+
if (!cell) return;
|
|
1053
|
+
const table = actionEditor.read.nodes.above({
|
|
1054
|
+
at: cell[1],
|
|
1055
|
+
match: (node) => ElementApi.isElement(node) && node.type === tablePlugin.schema.type
|
|
1056
|
+
});
|
|
1057
|
+
if (!table) return;
|
|
1058
|
+
const parsed = commandEditor.api.markdown.parseSlice(content);
|
|
1059
|
+
if (!parsed.ok) return;
|
|
1060
|
+
if (!parsed.slice.content.every((node) => ElementApi.isElement(node))) return;
|
|
1061
|
+
tableDraft.set(target.key, { children: landAIOutput(editor, actionEditor.read, parsed.slice.content, {
|
|
1062
|
+
block: cell[0].children.find((node) => ElementApi.isElement(node)),
|
|
1063
|
+
kind: "replaced"
|
|
1064
|
+
}) });
|
|
1065
|
+
const previewNode = (node, path) => {
|
|
1066
|
+
if (!ElementApi.isElement(node)) return node;
|
|
1067
|
+
const key = actionEditor.key(path);
|
|
1068
|
+
const draft = key ? tableDraft.get(key) : void 0;
|
|
1069
|
+
return {
|
|
1070
|
+
...node,
|
|
1071
|
+
children: draft?.children ?? node.children.map((child, index) => previewNode(child, [...path, index]))
|
|
1072
|
+
};
|
|
1073
|
+
};
|
|
1074
|
+
const preview = previewNode(table[0], table[1]);
|
|
1075
|
+
if (!ElementApi.isElement(preview)) return;
|
|
1076
|
+
context.store.set({
|
|
1077
|
+
_blockKey: actionEditor.key(table[0]),
|
|
1078
|
+
previewValue: [preview]
|
|
1079
|
+
});
|
|
1080
|
+
},
|
|
1081
|
+
show: () => show(commandEditor),
|
|
1082
|
+
/** Stop the request and publish its current response as the final draft. */
|
|
1083
|
+
stop,
|
|
1084
|
+
submit: (input, { mode, options, prompt, toolName: requestedToolName } = {}) => {
|
|
1085
|
+
const { chat, open: isOpen, toolName } = context.store.get();
|
|
1086
|
+
const nextToolName = requestedToolName ?? toolName ?? null;
|
|
1087
|
+
if (!prompt && input.length === 0) return void 0;
|
|
1088
|
+
const discarded = decideCurrentChange("reject");
|
|
1089
|
+
if (discarded && !reviewSucceeded(discarded)) return discarded;
|
|
1090
|
+
cancel();
|
|
1091
|
+
suggestion = null;
|
|
1092
|
+
suggestionTarget = null;
|
|
1093
|
+
previewOwner = null;
|
|
1094
|
+
previewParse = void 0;
|
|
1095
|
+
context.store.set({
|
|
1096
|
+
_blockKey: null,
|
|
1097
|
+
previewValue: []
|
|
1098
|
+
});
|
|
1099
|
+
tableDraft.clear();
|
|
1100
|
+
if (isOpen && !restoreTarget(commandEditor)) return discarded;
|
|
1101
|
+
aiChatCommandEditors.set(editor, commandEditor);
|
|
1102
|
+
captureTarget(commandEditor);
|
|
1103
|
+
const selection = commandEditor.read.selection() ?? editor.read.selection();
|
|
1104
|
+
const viewNodes = commandEditor.read.selection.nodes();
|
|
1105
|
+
const selectedNodePaths = (viewNodes.length ? viewNodes : editor.read.selection.nodes()).map(([, path]) => [...path]);
|
|
1106
|
+
const isNodeSelecting = selectedNodePaths.length > 0;
|
|
1107
|
+
const nextMode = mode ?? (isNodeSelecting || selection && RangeApi.isExpanded(selection) ? "chat" : "insert");
|
|
1108
|
+
context.store.set({
|
|
1109
|
+
mode: nextMode,
|
|
1110
|
+
toolName: nextToolName
|
|
1111
|
+
});
|
|
1112
|
+
const resolvedPrompt = resolvePrompt(prompt ?? input, {
|
|
1113
|
+
editor: commandEditor,
|
|
1114
|
+
isNodeSelecting,
|
|
1115
|
+
isSelecting: !!selection && RangeApi.isExpanded(selection)
|
|
1116
|
+
});
|
|
1117
|
+
const promptText = prompt === void 0 ? resolvedPrompt : commandEditor.plugin(AIChatPlugin).read.resolvePlaceholders(resolvedPrompt, { prompt: input });
|
|
1118
|
+
const requestContext = getRequestContext(commandEditor, selection ?? null, selectedNodePaths);
|
|
1119
|
+
context.store.set({ _requestId: crypto.randomUUID() });
|
|
1120
|
+
chat?.sendMessage(promptText, {
|
|
1121
|
+
body: { ctx: {
|
|
1122
|
+
...requestContext,
|
|
1123
|
+
toolName: nextToolName
|
|
1124
|
+
} },
|
|
1125
|
+
...options
|
|
1126
|
+
});
|
|
1127
|
+
return discarded;
|
|
1128
|
+
}
|
|
1129
|
+
}),
|
|
1130
|
+
read: ({ editor: commandEditor, state }) => ({
|
|
1131
|
+
commentRange: (comment) => {
|
|
1132
|
+
const blockRefs = context.store.get("_blockRefs");
|
|
1133
|
+
const blockRef = Object.hasOwn(blockRefs, comment.blockRef) ? blockRefs[comment.blockRef] : void 0;
|
|
1134
|
+
if (!blockRef) return void 0;
|
|
1135
|
+
const blockEditor = getActionEditor(commandEditor, blockRef.key);
|
|
1136
|
+
if (!blockEditor) return void 0;
|
|
1137
|
+
const root = blockEditor.read.view.root();
|
|
1138
|
+
const chatSelection = context.store.get("chatSelection");
|
|
1139
|
+
const isTextSelecting = !!chatSelection && RangeApi.isExpanded(chatSelection);
|
|
1140
|
+
const selection = isTextSelecting ? previewAnchor?.resolve(blockEditor) : null;
|
|
1141
|
+
if (isTextSelecting && !selection) return void 0;
|
|
1142
|
+
const refs = Object.values(blockRefs);
|
|
1143
|
+
const firstIndex = refs.indexOf(blockRef);
|
|
1144
|
+
const parsed = commandEditor.api.markdown.parseSlice(comment.content);
|
|
1145
|
+
if (!parsed.ok) return void 0;
|
|
1146
|
+
const nodes = parsed.slice.content;
|
|
1147
|
+
const ranges = [];
|
|
1148
|
+
let previousPath;
|
|
1149
|
+
for (const [index, node] of nodes.entries()) {
|
|
1150
|
+
const ref = refs[firstIndex + index];
|
|
1151
|
+
if (!ref || resolveTargetRoot(commandEditor, ref.key)?.root !== root) return;
|
|
1152
|
+
const block = blockEditor.read.nodes.get(ref.key, { match: ElementApi.isElement });
|
|
1153
|
+
if (!block) return void 0;
|
|
1154
|
+
if (previousPath) {
|
|
1155
|
+
const after = blockEditor.read.points.after(previousPath);
|
|
1156
|
+
const start = blockEditor.read.points.start(block[1]);
|
|
1157
|
+
if (!after || !start || !PointApi.equals(after, start)) return;
|
|
1158
|
+
}
|
|
1159
|
+
previousPath = block[1];
|
|
1160
|
+
const segments = [...NodeApi.texts(block[0])].flatMap(([leaf, path]) => {
|
|
1161
|
+
const anchor = {
|
|
1162
|
+
path: [...block[1], ...path],
|
|
1163
|
+
offset: 0,
|
|
1164
|
+
...root ? { root } : {}
|
|
1165
|
+
};
|
|
1166
|
+
const leafRange = {
|
|
1167
|
+
anchor,
|
|
1168
|
+
focus: {
|
|
1169
|
+
...anchor,
|
|
1170
|
+
offset: leaf.text.length
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
const selected = selection ? RangeApi.intersection(selection, leafRange) : leafRange;
|
|
1174
|
+
if (!selected || RangeApi.isCollapsed(selected)) return [];
|
|
1175
|
+
const [start, end] = RangeApi.edges(selected);
|
|
1176
|
+
return [{
|
|
1177
|
+
point: start,
|
|
1178
|
+
text: leaf.text.slice(start.offset, end.offset)
|
|
1179
|
+
}];
|
|
1180
|
+
});
|
|
1181
|
+
const span = findQuotedSpan(segments.map(({ text }) => text), NodeApi.string(node));
|
|
1182
|
+
if (!span) return void 0;
|
|
1183
|
+
const start = segments[span.start.segment].point;
|
|
1184
|
+
const end = segments[span.end.segment].point;
|
|
1185
|
+
ranges.push({
|
|
1186
|
+
anchor: {
|
|
1187
|
+
...start,
|
|
1188
|
+
offset: start.offset + span.start.offset
|
|
1189
|
+
},
|
|
1190
|
+
focus: {
|
|
1191
|
+
...end,
|
|
1192
|
+
offset: end.offset + span.end.offset
|
|
1193
|
+
}
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
const first = ranges[0];
|
|
1197
|
+
const last = ranges.at(-1);
|
|
1198
|
+
if (!first || !last) return void 0;
|
|
1199
|
+
return {
|
|
1200
|
+
anchor: first.anchor,
|
|
1201
|
+
focus: last.focus
|
|
1202
|
+
};
|
|
1203
|
+
},
|
|
1204
|
+
insertStart: getInsertStart.bind(null, state),
|
|
1205
|
+
markdown: serializeMarkdown.bind(null, commandEditor, state),
|
|
1206
|
+
node: (options = {}) => {
|
|
1207
|
+
const { streaming = false } = options;
|
|
1208
|
+
const blockKey = context.store.get("_blockKey");
|
|
1209
|
+
if (!blockKey || streaming && !context.store.get("streaming")) return;
|
|
1210
|
+
return state.nodes.get(blockKey, { match: ElementApi.isElement });
|
|
1211
|
+
},
|
|
1212
|
+
prompt: getPrompt.bind(null, state),
|
|
1213
|
+
resolvePlaceholders: (text, { prompt } = {}) => {
|
|
1214
|
+
let result = text.split("{prompt}").join(prompt ?? "");
|
|
1215
|
+
Object.entries({
|
|
1216
|
+
"{block}": "block",
|
|
1217
|
+
"{editor}": "editor",
|
|
1218
|
+
"{nodeSelection}": "nodeSelection",
|
|
1219
|
+
"{tableCellWithRef}": "tableCellWithRef"
|
|
1220
|
+
}).forEach(([placeholder, type]) => {
|
|
1221
|
+
if (result.includes(placeholder)) result = result.split(placeholder).join(serializeMarkdown(commandEditor, state, { type }));
|
|
1222
|
+
});
|
|
1223
|
+
return result;
|
|
1224
|
+
}
|
|
1225
|
+
}),
|
|
1226
|
+
selectors: { lastAssistantMessage: (state) => state.chat?.messages.findLast((message) => message.role === "assistant") },
|
|
1227
|
+
activate: ({ onCleanup }) => {
|
|
1228
|
+
onCleanup(() => {
|
|
1229
|
+
previewAnchor?.release();
|
|
1230
|
+
previewAnchor = null;
|
|
1231
|
+
previewParse = void 0;
|
|
1232
|
+
tableDraft.clear();
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
};
|
|
1236
|
+
});
|
|
1237
|
+
//#endregion
|
|
1238
|
+
export { AIChatPlugin, getAIChatCommandEditor };
|