platejs 54.0.0-beta.2 → 54.0.0-beta.20

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.
Files changed (840) hide show
  1. package/README.md +1 -1
  2. package/THIRD_PARTY_NOTICES.md +36 -8
  3. package/dist/EditorStatic-BTyhgdYL.d.ts +792 -0
  4. package/dist/ai/index.d.ts +2 -2
  5. package/dist/ai/index.js +4 -2
  6. package/dist/ai/lib/aiDraftSession.js +1081 -0
  7. package/dist/ai/{react → lib}/aiOutputLanding.internal.js +90 -96
  8. package/dist/ai/lib/aiPolicy.internal.js +471 -0
  9. package/dist/ai/lib/editorAgent.js +3441 -0
  10. package/dist/ai/lib/editorAgentDispatcher.internal.js +205 -0
  11. package/dist/ai/lib/editorAgentPresence.internal.js +114 -0
  12. package/dist/ai/lib/editorAgentSync.internal.js +306 -0
  13. package/dist/ai/lib/inkRuntime.internal.js +8 -0
  14. package/dist/ai/lib/lockedContext.internal.js +144 -0
  15. package/dist/ai/lib/lockedContext.js +272 -0
  16. package/dist/ai/lib/registerEditorTools.js +311 -0
  17. package/dist/ai/lib/webmcpConfinement.internal.js +8 -0
  18. package/dist/ai/react/AIPlugin.js +246 -0
  19. package/dist/ai/react/CopilotPlugin.js +359 -191
  20. package/dist/ai/react/copilotInline.internal.js +359 -0
  21. package/dist/ai/react/index.d.ts +327 -1007
  22. package/dist/ai/react/index.js +3 -3
  23. package/dist/ai/react/useEditorAgent.js +514 -0
  24. package/dist/authored/AuthoredPlugin.js +35 -3
  25. package/dist/authored/index.d.ts +5 -4
  26. package/dist/authored/index.js +3 -2
  27. package/dist/authored/suggestionColorOf.js +20 -0
  28. package/dist/{index-hsC_sOn2.d.ts → authored-CYoZAxr--Ba0JwRbO.d.ts} +198 -87
  29. package/dist/clipboard-format-key-CMZ3jPZO-DEODtsVZ.d.ts +1 -0
  30. package/dist/code-block/codemirror/createCodeMirrorAdapter.js +236 -67
  31. package/dist/code-block/codemirror/index.d.ts +2 -1
  32. package/dist/comment-anchor.internal-DQfEtr1Z.d.ts +28 -0
  33. package/dist/compiler/index.d.ts +9 -3
  34. package/dist/compiler/index.js +3 -1
  35. package/dist/{core-BJG8l_mk.d.ts → core-ClO5Umhx.d.ts} +5480 -7255
  36. package/dist/core.js +3 -12
  37. package/dist/diff/index.d.ts +3 -30
  38. package/dist/docs/agents/mcp.md +131 -0
  39. package/dist/docs/agents/skills.md +71 -0
  40. package/dist/docs/agents.md +79 -0
  41. package/dist/docs/ai-agents.md +80 -0
  42. package/dist/docs/ai.md +622 -387
  43. package/dist/docs/annotations.md +41 -122
  44. package/dist/docs/api/anchor.md +17 -2
  45. package/dist/docs/api/core/plate-components.md +78 -196
  46. package/dist/docs/api/core/plate-controller.md +6 -4
  47. package/dist/docs/api/core/plate-editor.md +35 -132
  48. package/dist/docs/api/core/plate-plugin.md +429 -560
  49. package/dist/docs/api/core/plate-store.md +21 -20
  50. package/dist/docs/api/core.md +261 -441
  51. package/dist/docs/api/document-change.md +60 -28
  52. package/dist/docs/api/dom.md +82 -107
  53. package/dist/docs/api/editor-api.md +86 -51
  54. package/dist/docs/api/editor-transforms.md +52 -51
  55. package/dist/docs/api/element.md +3 -3
  56. package/dist/docs/api/location.md +7 -14
  57. package/dist/docs/api/node.md +6 -7
  58. package/dist/docs/api/path.md +3 -3
  59. package/dist/docs/api/plate.md +21 -13
  60. package/dist/docs/api/point.md +4 -3
  61. package/dist/docs/api/range.md +21 -2
  62. package/dist/docs/api/react-hooks.md +288 -188
  63. package/dist/docs/api/resizable.md +20 -42
  64. package/dist/docs/api/selection.md +12 -4
  65. package/dist/docs/api/text.md +3 -3
  66. package/dist/docs/api/utils.md +23 -25
  67. package/dist/docs/authored-changes.md +66 -51
  68. package/dist/docs/autoformat.md +24 -13
  69. package/dist/docs/basic-blocks.md +55 -59
  70. package/dist/docs/basic-marks.md +11 -48
  71. package/dist/docs/block-menu.md +26 -19
  72. package/dist/docs/block-placeholder.md +59 -64
  73. package/dist/docs/blockquote.md +31 -19
  74. package/dist/docs/board.md +187 -73
  75. package/dist/docs/bold.md +1 -9
  76. package/dist/docs/browser.md +6 -17
  77. package/dist/docs/business/compliance-pdf.md +54 -0
  78. package/dist/docs/business/security-kernel.md +57 -0
  79. package/dist/docs/business/security-proof.md +61 -0
  80. package/dist/docs/business/verify.md +78 -0
  81. package/dist/docs/business.md +143 -0
  82. package/dist/docs/callout.md +130 -52
  83. package/dist/docs/clear-formatting.md +5 -15
  84. package/dist/docs/clipboard.md +48 -28
  85. package/dist/docs/code-block.md +168 -68
  86. package/dist/docs/code.md +1 -7
  87. package/dist/docs/collaboration.md +127 -0
  88. package/dist/docs/column.md +36 -31
  89. package/dist/docs/combobox.md +65 -100
  90. package/dist/docs/comment.md +219 -158
  91. package/dist/docs/comparison.md +128 -0
  92. package/dist/docs/components/toolbar-buttons.md +38 -0
  93. package/dist/docs/controlled.md +36 -22
  94. package/dist/docs/copilot.md +215 -203
  95. package/dist/docs/date.md +20 -20
  96. package/dist/docs/debugging.md +5 -14
  97. package/dist/docs/deck.md +173 -0
  98. package/dist/docs/decorations.md +3 -4
  99. package/dist/docs/details.md +69 -17
  100. package/dist/docs/diff.md +109 -0
  101. package/dist/docs/discussion.md +45 -31
  102. package/dist/docs/dnd.md +66 -68
  103. package/dist/docs/document-meta.md +36 -30
  104. package/dist/docs/document-model.md +26 -13
  105. package/dist/docs/docx.md +211 -151
  106. package/dist/docs/dom-coverage.md +6 -1
  107. package/dist/docs/editing-behavior.md +5 -8
  108. package/dist/docs/editor-methods.md +50 -26
  109. package/dist/docs/editor.md +149 -158
  110. package/dist/docs/emoji.md +56 -52
  111. package/dist/docs/equation.md +48 -26
  112. package/dist/docs/examples/collaboration-example.md +21 -30
  113. package/dist/docs/examples/editable-voids.md +4 -3
  114. package/dist/docs/examples/export.md +56 -39
  115. package/dist/docs/examples/huge-document.md +8 -0
  116. package/dist/docs/examples/hundreds-editors.md +2 -0
  117. package/dist/docs/examples/merge.md +50 -0
  118. package/dist/docs/examples/preview-markdown.md +2 -0
  119. package/dist/docs/examples/version-history.md +35 -13
  120. package/dist/docs/exit-break.md +39 -74
  121. package/dist/docs/external-text.md +28 -13
  122. package/dist/docs/field.md +683 -0
  123. package/dist/docs/find.md +110 -97
  124. package/dist/docs/font.md +26 -42
  125. package/dist/docs/footnote.md +252 -242
  126. package/dist/docs/form.md +4 -2
  127. package/dist/docs/format-painter.md +6 -16
  128. package/dist/docs/heading.md +20 -11
  129. package/dist/docs/highlight.md +2 -8
  130. package/dist/docs/history.md +216 -76
  131. package/dist/docs/horizontal-rule.md +22 -34
  132. package/dist/docs/html.md +79 -37
  133. package/dist/docs/indent.md +41 -80
  134. package/dist/docs/index.md +47 -72
  135. package/dist/docs/ink.md +275 -0
  136. package/dist/docs/installation/manual.md +27 -36
  137. package/dist/docs/installation/next.md +23 -24
  138. package/dist/docs/installation/node.md +17 -17
  139. package/dist/docs/installation/plate-ui.md +90 -54
  140. package/dist/docs/installation/react.md +56 -20
  141. package/dist/docs/installation/rsc.md +9 -15
  142. package/dist/docs/installation.md +11 -32
  143. package/dist/docs/italic.md +1 -7
  144. package/dist/docs/kbd.md +1 -7
  145. package/dist/docs/license.md +59 -0
  146. package/dist/docs/line-height.md +2 -12
  147. package/dist/docs/link.md +120 -147
  148. package/dist/docs/lint.md +181 -132
  149. package/dist/docs/list.md +146 -50
  150. package/dist/docs/live-block.md +189 -0
  151. package/dist/docs/llms.txt +102 -80
  152. package/dist/docs/lock.md +298 -0
  153. package/dist/docs/markdown.md +299 -99
  154. package/dist/docs/media.md +240 -219
  155. package/dist/docs/mention.md +46 -44
  156. package/dist/docs/migration-v54.md +361 -0
  157. package/dist/docs/mobile.md +415 -0
  158. package/dist/docs/multi-select.md +30 -34
  159. package/dist/docs/navigation-feedback.md +23 -40
  160. package/dist/docs/pagination.md +151 -128
  161. package/dist/docs/performance.md +13 -17
  162. package/dist/docs/plugin-components.md +23 -20
  163. package/dist/docs/plugin-context.md +18 -13
  164. package/dist/docs/plugin-input-rules.md +169 -171
  165. package/dist/docs/plugin-methods.md +74 -28
  166. package/dist/docs/plugin-rules.md +23 -47
  167. package/dist/docs/plugin-shortcuts.md +70 -14
  168. package/dist/docs/plugin.md +59 -8
  169. package/dist/docs/prompt-editor.md +334 -0
  170. package/dist/docs/reference.md +192 -0
  171. package/dist/docs/releases.md +3 -1
  172. package/dist/docs/roots.md +157 -35
  173. package/dist/docs/rtl.md +8 -4
  174. package/dist/docs/schema.md +18 -7
  175. package/dist/docs/selection.md +17 -5
  176. package/dist/docs/serializing.md +102 -15
  177. package/dist/docs/single-block.md +1 -3
  178. package/dist/docs/slash-command.md +78 -35
  179. package/dist/docs/static.md +122 -54
  180. package/dist/docs/strikethrough.md +1 -7
  181. package/dist/docs/subscript.md +1 -7
  182. package/dist/docs/suggestion.md +96 -92
  183. package/dist/docs/superscript.md +1 -7
  184. package/dist/docs/sync.md +358 -0
  185. package/dist/docs/tabbable.md +56 -93
  186. package/dist/docs/table.md +166 -50
  187. package/dist/docs/text-align.md +8 -18
  188. package/dist/docs/toc.md +48 -72
  189. package/dist/docs/toolbar.md +102 -92
  190. package/dist/docs/trailing-block.md +19 -50
  191. package/dist/docs/transactions.md +2 -2
  192. package/dist/docs/troubleshooting.md +5 -5
  193. package/dist/docs/underline.md +3 -9
  194. package/dist/docs/unit-testing.md +37 -6
  195. package/dist/docs/upload.md +183 -58
  196. package/dist/docx/export/index.d.ts +212 -59
  197. package/dist/docx/export/index.js +2 -1
  198. package/dist/docx/export/lib/compileAst.js +2552 -0
  199. package/dist/docx/export/lib/docxComments.js +153 -0
  200. package/dist/docx/export/lib/exportDocx.js +585 -229
  201. package/dist/docx/export/lib/mathOmml.js +232 -0
  202. package/dist/docx/export/lib/ooxmlBuilder.js +2596 -0
  203. package/dist/docx/export/lib/outputSafety.js +241 -84
  204. package/dist/docx/export/lib/reviewProjection.js +332 -120
  205. package/dist/docx/export/lib/sourceEnvelopePatcher.js +1169 -0
  206. package/dist/docx/export/lib/sourcePreservation.js +233 -110
  207. package/dist/docx/export/lib/wordStyles.js +450 -0
  208. package/dist/docx/html/cleanWordHtml.internal.js +398 -115
  209. package/dist/docx/html/domParser.internal.js +4 -0
  210. package/dist/docx/import/index.d.ts +37 -5
  211. package/dist/docx/import/index.js +2 -1
  212. package/dist/docx/import/lib/docxComments.js +151 -0
  213. package/dist/docx/import/lib/importDocx.js +3516 -1082
  214. package/dist/docx/import/lib/opcRelationships.js +88 -0
  215. package/dist/docx/import/lib/readWordDocument.js +2534 -0
  216. package/dist/docx/import/lib/wordStyles.js +638 -0
  217. package/dist/docx/internal/abort.js +3 -3
  218. package/dist/docx/internal/colors.js +307 -0
  219. package/dist/docx/internal/diagnostics.js +68 -0
  220. package/dist/docx/internal/docxComments.js +34 -0
  221. package/dist/docx/internal/docxPackage.js +343 -71
  222. package/dist/docx/internal/packageParts.js +17 -18
  223. package/dist/docx/internal/pageLayout.js +313 -0
  224. package/dist/docx/internal/readDocxNumbering.js +79 -59
  225. package/dist/docx/internal/reviewPart.js +68 -37
  226. package/dist/docx/internal/source.js +1 -0
  227. package/dist/docx/internal/sourceEligibility.js +385 -60
  228. package/dist/docx/internal/sourceEnvelope.js +473 -0
  229. package/dist/docx/internal/tableBorders.js +79 -0
  230. package/dist/docx/internal/wordFields.js +40 -0
  231. package/dist/docx/internal/wordMath.js +136 -166
  232. package/dist/docx/internal/xmlTree.js +288 -0
  233. package/dist/docx/internal/xmlWriter.js +44 -0
  234. package/dist/docx/paste/index.d.ts +28 -6
  235. package/dist/docx/paste/lib/WordPastePlugin.js +78 -107
  236. package/dist/dom/index.d.ts +2 -7
  237. package/dist/dom/index.js +2 -2
  238. package/dist/dom/plite-dom.internal.js +2 -2
  239. package/dist/facade.js +3 -3
  240. package/dist/features/basic-nodes/lib/BaseBlockPlugins.js +170 -87
  241. package/dist/features/basic-nodes/lib/BaseHeadingPlugins.js +140 -27
  242. package/dist/features/basic-nodes/lib/BaseMarkPlugins.js +160 -82
  243. package/dist/features/basic-styles/lib/BaseFormattingPlugin.js +66 -30
  244. package/dist/features/basic-styles/lib/BaseStylePlugins.js +144 -89
  245. package/dist/features/board/index.d.ts +2 -2
  246. package/dist/features/board/index.js +4 -3
  247. package/dist/features/board/lib/BaseBoardArrowPlugin.js +90 -87
  248. package/dist/features/board/lib/BaseBoardFramePlugin.js +7 -7
  249. package/dist/features/board/lib/BaseBoardGeoPlugin.js +3 -2
  250. package/dist/features/board/lib/BaseBoardImagePlugin.js +9 -6
  251. package/dist/features/board/lib/BaseBoardNotePlugin.js +3 -2
  252. package/dist/features/board/lib/BaseBoardPlugin.js +473 -281
  253. package/dist/features/board/lib/BaseBoardStrokePlugin.js +9 -6
  254. package/dist/features/board/lib/BaseBoardTextPlugin.js +13 -0
  255. package/dist/features/board/lib/boardArrow.internal.js +7 -5
  256. package/dist/features/board/lib/boardCopy.internal.js +42 -36
  257. package/dist/features/board/lib/boardFrame.internal.js +5 -7
  258. package/dist/features/board/lib/boardGeometry.internal.js +127 -0
  259. package/dist/features/board/lib/boardHeights.internal.js +57 -0
  260. package/dist/features/board/lib/boardHtml.internal.js +51 -34
  261. package/dist/features/board/lib/boardMember.internal.js +10 -10
  262. package/dist/features/board/lib/boardShape.internal.js +10 -119
  263. package/dist/features/board/lib/boardStroke.internal.js +13 -1
  264. package/dist/features/board/lib/boardStyle.internal.js +11 -7
  265. package/dist/features/board/lib/boardTypes.internal.js +28 -0
  266. package/dist/features/callout/index.d.ts +2 -84
  267. package/dist/features/callout/lib/BaseCalloutPlugin.js +464 -18
  268. package/dist/features/code-block/lib/BaseCodeBlockPlugin.js +236 -194
  269. package/dist/features/code-block/lib/CodeBlockRules.js +133 -14
  270. package/dist/features/column/index.d.ts +2 -0
  271. package/dist/features/column/lib/BaseColumnPlugin.js +767 -0
  272. package/dist/features/comments/BaseCommentsPlugin.js +1832 -729
  273. package/dist/features/comments/comment-active-presentations.internal.js +86 -0
  274. package/dist/features/comments/comment-range-reader.internal.js +12 -0
  275. package/dist/features/comments/comment-thread-index.internal.js +869 -0
  276. package/dist/features/comments/comment-unresolved-index.internal.js +102 -0
  277. package/dist/features/comments/comment-validation.internal.js +136 -0
  278. package/dist/features/comments/fitCommentBody.js +338 -0
  279. package/dist/features/comments/index.d.ts +3 -2
  280. package/dist/features/comments/index.js +3 -2
  281. package/dist/features/date/index.d.ts +3 -2
  282. package/dist/features/date/lib/BaseDatePlugin.js +126 -33
  283. package/dist/features/details/index.d.ts +11 -4
  284. package/dist/features/details/lib/BaseDetailsPlugin.js +602 -217
  285. package/dist/features/field/index.d.ts +2 -0
  286. package/dist/features/field/index.js +4 -0
  287. package/dist/features/field/lib/BaseFieldPlugin.js +682 -0
  288. package/dist/features/field/lib/applyFieldValues.js +579 -0
  289. package/dist/features/field/lib/fieldCache.internal.js +67 -0
  290. package/dist/features/field/lib/fieldRules.internal.js +658 -0
  291. package/dist/features/find/index.d.ts +125 -40
  292. package/dist/features/find/lib/BaseFindPlugin.js +1952 -207
  293. package/dist/features/footnote/index.d.ts +429 -2
  294. package/dist/features/footnote/lib/BaseFootnotePlugin.js +512 -180
  295. package/dist/features/indent/lib/BaseIndentPlugin.js +226 -76
  296. package/dist/features/indent/lib/indentHtml.internal.js +35 -0
  297. package/dist/features/indent/lib/indentLevel.internal.js +3 -3
  298. package/dist/features/ink/index.d.ts +2 -2
  299. package/dist/features/ink/index.js +2 -2
  300. package/dist/features/ink/lib/BaseInkPlugin.js +891 -155
  301. package/dist/features/ink/lib/inkAnchor.internal.js +436 -0
  302. package/dist/features/ink/lib/inkCodec.internal.js +145 -0
  303. package/dist/features/ink/lib/inkMatch.internal.js +236 -71
  304. package/dist/features/ink/lib/inkPlaces.internal.js +219 -71
  305. package/dist/features/ink/lib/inkReflow.internal.js +406 -0
  306. package/dist/features/ink/lib/inkSvg.internal.js +419 -0
  307. package/dist/features/link/lib/BaseLinkPlugin.js +504 -193
  308. package/dist/features/lint/index.d.ts +57 -30
  309. package/dist/features/lint/lib/BaseLintPlugin.js +581 -186
  310. package/dist/features/list/lib/BaseListPlugin.js +105 -690
  311. package/dist/features/list/lib/listCommands.internal.js +161 -0
  312. package/dist/features/list/lib/listFamily.internal.js +68 -23
  313. package/dist/features/list/lib/listHtml.internal.js +185 -69
  314. package/dist/features/list/lib/listIndex.internal.js +54 -20
  315. package/dist/features/list/lib/listKeyboard.internal.js +181 -0
  316. package/dist/features/list/lib/listMarkdown.internal.js +123 -0
  317. package/dist/features/list/lib/listNumbering.internal.js +1 -1
  318. package/dist/features/list/lib/listRules.internal.js +125 -0
  319. package/dist/features/lock/index.d.ts +2 -0
  320. package/dist/features/lock/index.js +2 -0
  321. package/dist/features/lock/lib/BaseLockPlugin.js +761 -0
  322. package/dist/features/media/index.d.ts +2 -2
  323. package/dist/features/media/index.js +5 -5
  324. package/dist/features/media/lib/BaseMediaPlugin.js +120 -155
  325. package/dist/features/media/lib/image/BaseImagePlugin.js +128 -154
  326. package/dist/features/media/lib/media/parseMediaEmbedUrl.internal.js +326 -0
  327. package/dist/features/media/lib/media/parseMediaEmbedUrl.js +12 -0
  328. package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +68 -11
  329. package/dist/features/media/lib/mediaHtml.internal.js +2 -2
  330. package/dist/features/media/lib/mediaPasteRule.internal.js +89 -0
  331. package/dist/features/media/lib/mediaPlugin.internal.js +201 -0
  332. package/dist/features/mention/index.d.ts +2 -72
  333. package/dist/features/mention/lib/BaseMentionPlugin.js +97 -49
  334. package/dist/features/reference/index.d.ts +240 -0
  335. package/dist/features/reference/index.js +2 -0
  336. package/dist/features/reference/lib/BaseReferencePlugin.js +598 -0
  337. package/dist/features/table/index.d.ts +3 -2
  338. package/dist/features/table/lib/BaseTablePlugin.js +1312 -447
  339. package/dist/features/table/lib/internal/authoredProjection.js +172 -0
  340. package/dist/features/table/lib/internal/axisMove.js +244 -0
  341. package/dist/features/table/lib/internal/docxBorders.js +79 -0
  342. package/dist/features/table/lib/internal/grid.js +34 -1
  343. package/dist/features/table/lib/internal/mutation.js +53 -141
  344. package/dist/features/table/lib/internal/paste.js +66 -3
  345. package/dist/features/table/lib/internal/selection.js +120 -20
  346. package/dist/features/table/lib/internal/tableCellHtml.js +11 -2
  347. package/dist/features/table/lib/internal/tabularText.js +105 -3
  348. package/dist/features/table/lib/internal/widths.js +136 -0
  349. package/dist/features/toc/index.d.ts +2 -2
  350. package/dist/features/toc/index.js +2 -2
  351. package/dist/features/toc/lib/BaseTocPlugin.js +163 -22
  352. package/dist/features/upload/index.d.ts +2 -2
  353. package/dist/features/upload/index.js +3 -2
  354. package/dist/features/upload/lib/BaseUploadPlugin.js +644 -443
  355. package/dist/features/upload/lib/uploadRules.internal.js +259 -0
  356. package/dist/history/index.d.ts +2 -3
  357. package/dist/history/index.js +2 -1
  358. package/dist/html/index.d.ts +4 -3
  359. package/dist/html/server/index.d.ts +6 -2
  360. package/dist/html/server/index.js +8 -4
  361. package/dist/html/server/serverCssParser.internal.js +372 -0
  362. package/dist/html/server/serverCssStyle.internal.js +214 -0
  363. package/dist/{index-DC_MNGyu.d.ts → htmlConversion-CmUPi9rg.d.ts} +6 -3
  364. package/dist/{htmlTypes-DjeFG3P8.d.ts → htmlTypes-C3hHzpRh.d.ts} +33 -45
  365. package/dist/hyperscript/index.d.ts +1 -1
  366. package/dist/index-5j5BcvLz.d.ts +493 -0
  367. package/dist/{react/features/layout/index.d.ts → index-B7vlwvLQ.d.ts} +201 -193
  368. package/dist/{index-Bxfvicyy.d.ts → index-BFuz7j3F.d.ts} +292 -176
  369. package/dist/index-BKiW8Kte.d.ts +21 -0
  370. package/dist/index-BTGCF8li.d.ts +3146 -0
  371. package/dist/index-BnqTluVD-D50uRAnI.d.ts +348 -0
  372. package/dist/index-Bw3p8fsS.d.ts +258 -0
  373. package/dist/{index-D5W-p9bS.d.ts → index-BxJ1-Bk3.d.ts} +631 -320
  374. package/dist/index-Byf_lqL7.d.ts +84 -0
  375. package/dist/index-CEQXbShY.d.ts +1 -0
  376. package/dist/{index-DaM37gF6.d.ts → index-CW0A2w5s.d.ts} +166 -248
  377. package/dist/{index-DzD6BIFJ.d.ts → index-CXFQCw_T.d.ts} +474 -443
  378. package/dist/{index-CcZbqPqk.d.ts → index-Cv3NLcDO.d.ts} +213 -75
  379. package/dist/index-D17Cz7nd.d.ts +97 -0
  380. package/dist/index-D4gbdWPp.d.ts +208 -0
  381. package/dist/index-D7LkEoIA.d.ts +118 -0
  382. package/dist/index-DQAD-81H.d.ts +930 -0
  383. package/dist/{index-Bc2Yg_2j.d.ts → index-DgYHSQmu-DLvTjIM2.d.ts} +4 -4
  384. package/dist/index-DqsRyYXn.d.ts +3 -0
  385. package/dist/{index-DTgaSxKr.d.ts → index-DzXvKehR.d.ts} +130 -110
  386. package/dist/index-KVVMEzVq.d.ts +45 -0
  387. package/dist/index-OJ8B_v_P-D5yZA1mD.d.ts +254 -0
  388. package/dist/index-Q7hzYYQW.d.ts +1 -0
  389. package/dist/index-RrccNMAA.d.ts +69 -0
  390. package/dist/index-h-K-xgfs.d.ts +305 -0
  391. package/dist/index.d.ts +4 -4
  392. package/dist/index.js +6 -15
  393. package/dist/internal/comments/comment-anchor.internal.js +696 -0
  394. package/dist/internal/mergePlateRenderedAttributes.js +13 -16
  395. package/dist/{react/internal → internal}/penStroke.internal.js +29 -4
  396. package/dist/internal/plugin/OverridePlugin.js +251 -141
  397. package/dist/internal/plugin/blockInsertion.js +7 -5
  398. package/dist/internal/plugin/collectPlateNodeMappings.js +23 -9
  399. package/dist/internal/plugin/compilePlainTextMappings.js +68 -15
  400. package/dist/internal/plugin/compilePlateModel.js +180 -135
  401. package/dist/internal/plugin/compilePlateShortcuts.js +2 -1
  402. package/dist/internal/plugin/compilePluginInputMaps.js +126 -0
  403. package/dist/internal/plugin/conversionLaws.js +73 -0
  404. package/dist/internal/plugin/createPlateModelPublication.js +271 -0
  405. package/dist/internal/plugin/createPlateRuntimePlugins.js +277 -0
  406. package/dist/internal/plugin/defaultElementTag.js +17 -1
  407. package/dist/{react/utils/dom-attributes.internal.js → internal/plugin/domHandlers.js} +8 -2
  408. package/dist/internal/plugin/endMatterPartition.js +28 -0
  409. package/dist/internal/plugin/getPlateDecorationSources.js +2 -1
  410. package/dist/internal/plugin/getPluginRenderAttributes.js +4 -8
  411. package/dist/internal/plugin/indentShift.js +44 -0
  412. package/dist/internal/plugin/isEditOnlyDisabled.js +1 -1
  413. package/dist/internal/plugin/markdownClipboardUnwrap.js +10 -0
  414. package/dist/internal/plugin/markdownEscapes.js +20 -0
  415. package/dist/internal/plugin/markdownParagraph.js +23 -1
  416. package/dist/internal/plugin/markdownPreservedProperties.js +25 -0
  417. package/dist/internal/plugin/matchesPluginInject.internal.js +20 -0
  418. package/dist/internal/plugin/mergeNodeAttributes.internal.js +76 -0
  419. package/dist/internal/plugin/pastedUploadFiles.js +4 -0
  420. package/dist/internal/plugin/pipeInjectNodeProps.js +8 -13
  421. package/dist/internal/plugin/plateRuntime.js +11 -3
  422. package/dist/internal/plugin/pluginDescriptorSnapshot.js +172 -0
  423. package/dist/internal/plugin/pluginFormatOperation.js +8 -3
  424. package/dist/internal/plugin/pluginInjectNodeProps.js +49 -34
  425. package/dist/internal/plugin/pluginNodeClass.internal.js +6 -0
  426. package/dist/internal/plugin/pluginStore.js +81 -11
  427. package/dist/internal/plugin/resolvePlugin.js +45 -25
  428. package/dist/internal/plugin/resolvePluginGraph.js +352 -0
  429. package/dist/internal/plugin/resolvePlugins.js +20 -1133
  430. package/dist/internal/plugin/staticReuseKey.internal.js +15 -0
  431. package/dist/internal/plugin/uploadDrafts.js +11 -0
  432. package/dist/internal/utils/mergePlugins.js +7 -5
  433. package/dist/internal/utils/trustedContentSlice.js +1 -1
  434. package/dist/internal/utils/urlPolicy.js +37 -2
  435. package/dist/internal/utils/vscodeClipboard.js +11 -0
  436. package/dist/lib/editor/editorUser.internal.js +13 -5
  437. package/dist/lib/editor/withPlite.js +118 -61
  438. package/dist/lib/libs/zustand.js +31 -7
  439. package/dist/lib/plugin/basePluginFactory.internal.js +7 -0
  440. package/dist/lib/plugin/createPluginContext.internal.js +8 -27
  441. package/dist/lib/plugin/defineBasePlugin.internal.js +69 -9
  442. package/dist/lib/plugin/definePlugin.js +1 -1
  443. package/dist/lib/plugin/pluginFactoryRuntime.internal.js +40 -0
  444. package/dist/lib/plugins/affinity/AffinityPlugin.js +85 -52
  445. package/dist/lib/plugins/debug/DebugPlugin.js +1 -4
  446. package/dist/lib/plugins/dom/DOMPlugin.js +35 -15
  447. package/dist/lib/plugins/dom/clipboardFormatKey.internal.js +9 -0
  448. package/dist/lib/plugins/dom/isPlainTextPasteTarget.internal.js +13 -0
  449. package/dist/lib/plugins/getCorePlugins.internal.js +1 -3
  450. package/dist/lib/plugins/html/HtmlPlugin.js +49 -1745
  451. package/dist/lib/plugins/html/cssLexer.internal.js +409 -0
  452. package/dist/lib/plugins/html/cssSafety.internal.js +100 -0
  453. package/dist/lib/plugins/html/htmlAst.js +62 -18
  454. package/dist/lib/plugins/html/htmlConversion.js +25 -9
  455. package/dist/lib/plugins/html/htmlDecode.internal.js +808 -0
  456. package/dist/lib/plugins/html/htmlDom.js +3 -13
  457. package/dist/lib/plugins/html/htmlMatcher.internal.js +24 -1
  458. package/dist/lib/plugins/html/htmlRules.internal.js +417 -0
  459. package/dist/lib/plugins/html/htmlSafety.js +38 -24
  460. package/dist/lib/plugins/html/htmlSerialize.internal.js +495 -0
  461. package/dist/lib/plugins/html/htmlStyleInline.internal.js +688 -0
  462. package/dist/lib/plugins/html/htmlWhitespace.internal.js +137 -0
  463. package/dist/lib/plugins/input-rules/InputRulesPlugin.js +187 -54
  464. package/dist/lib/plugins/input-rules/createInputRules.js +65 -69
  465. package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +144 -0
  466. package/dist/lib/plugins/input-rules/inputRuleVeto.js +2 -2
  467. package/dist/lib/plugins/input-rules/inputRules.internal.js +20 -0
  468. package/dist/lib/plugins/input-rules/markInputRule.internal.js +64 -2
  469. package/dist/lib/plugins/paragraph/BaseParagraphPlugin.js +21 -8
  470. package/dist/lib/utils/getInjectMatch.js +6 -39
  471. package/dist/markdown/index.d.ts +2 -2
  472. package/dist/markdown/index.js +2 -1
  473. package/dist/markdown/lib/MarkdownPlugin.js +129 -84
  474. package/dist/markdown/lib/deserializer/convertNodesDeserialize.js +32 -8
  475. package/dist/markdown/lib/deserializer/mdastToSlate.js +11 -3
  476. package/dist/markdown/lib/internal/markdownAttributes.js +18 -8
  477. package/dist/markdown/lib/internal/markdownBareLinks.js +270 -0
  478. package/dist/markdown/lib/internal/markdownBreaks.js +191 -0
  479. package/dist/markdown/lib/internal/markdownDiagnostics.js +33 -16
  480. package/dist/markdown/lib/internal/markdownDocument.js +14 -33
  481. package/dist/markdown/lib/internal/markdownFootnoteWriter.js +35 -0
  482. package/dist/markdown/lib/internal/markdownFrontmatter.js +102 -0
  483. package/dist/markdown/lib/internal/markdownIntrinsics.js +88 -163
  484. package/dist/markdown/lib/internal/markdownLine.js +186 -145
  485. package/dist/markdown/lib/internal/markdownMappings.js +335 -107
  486. package/dist/markdown/lib/internal/markdownParse.js +596 -0
  487. package/dist/markdown/lib/internal/markdownReferences.js +12 -6
  488. package/dist/markdown/lib/internal/markdownRuntime.js +456 -0
  489. package/dist/markdown/lib/internal/markdownSafety.js +53 -1
  490. package/dist/markdown/lib/internal/markdownSerialize.js +197 -0
  491. package/dist/markdown/lib/internal/markdownStream.js +1006 -0
  492. package/dist/markdown/lib/internal/markdownTags.js +206 -76
  493. package/dist/markdown/lib/internal/markdownTailHeal.js +869 -0
  494. package/dist/markdown/lib/internal/walkMdast.js +34 -0
  495. package/dist/markdown/lib/serializer/convertNodesSerialize.js +33 -18
  496. package/dist/markdown/lib/serializer/convertPhrasingSerialize.js +322 -0
  497. package/dist/markdown/lib/serializer/listToMdastTree.js +34 -12
  498. package/dist/markdown/lib/serializer/reportOmittedProperties.js +5 -2
  499. package/dist/markdown/lib/utils/remarkPlugins.js +48 -23
  500. package/dist/math/index.d.ts +21 -384
  501. package/dist/math/lib/BaseEquationPlugin.js +111 -29
  502. package/dist/math/react/index.d.ts +10 -9
  503. package/dist/migrations/documentMigrationAuthored.internal.js +2 -1
  504. package/dist/migrations/documentMigrationSelection.internal.js +138 -2
  505. package/dist/migrations/documentMigrationTarget.internal.js +10 -2
  506. package/dist/migrations/documentMigrations.js +134 -143
  507. package/dist/migrations/index.d.ts +30 -44
  508. package/dist/migrations/index.js +1 -2
  509. package/dist/migrations/migratePlateV54.js +61 -52
  510. package/dist/migrations/migratePlateV54Ast.internal.js +201 -118
  511. package/dist/migrations/migratePlateV54BuiltIns.internal.js +18 -3
  512. package/dist/migrations/migratePlateV54Callout.internal.js +61 -0
  513. package/dist/migrations/migratePlateV54CodeBlocks.internal.js +68 -34
  514. package/dist/migrations/migratePlateV54Excalidraw.internal.js +534 -0
  515. package/dist/migrations/migratePlateV54ExcalidrawHelpers.internal.js +82 -0
  516. package/dist/migrations/migratePlateV54Inputs.internal.js +39 -32
  517. package/dist/migrations/migratePlateV54ListIdentity.internal.js +220 -0
  518. package/dist/migrations/migratePlateV54Profile.internal.js +54 -27
  519. package/dist/migrations/migratePlateV54RetiredMarks.internal.js +25 -10
  520. package/dist/migrations/migratePlateV54Stage.internal.js +127 -0
  521. package/dist/migrations/migratePlateV54Suggestions.internal.js +10 -3
  522. package/dist/migrations/migratePlateV54Toggle.internal.js +66 -0
  523. package/dist/migrations/migratePlateV54Urls.internal.js +149 -58
  524. package/dist/migrations/v53-manifest.internal.js +4 -0
  525. package/dist/pagination/index.d.ts +2 -167
  526. package/dist/pagination/index.js +26 -2
  527. package/dist/pagination/react/PaginationPlugin.js +271 -0
  528. package/dist/pagination/react/index.d.ts +168 -31
  529. package/dist/pagination/react/index.js +3 -5
  530. package/dist/plain-text.js +19 -15
  531. package/dist/protocol-o3jVSHir-Bouoin05.d.ts +103 -0
  532. package/dist/react/authored/AuthoredReactPlugin.js +127 -0
  533. package/dist/react/authored/index.d.ts +37 -0
  534. package/dist/react/authored/index.js +3 -0
  535. package/dist/react/authored/useAuthored.js +118 -0
  536. package/dist/react/components/EditorContentView.internal.js +100 -53
  537. package/dist/react/components/EditorProvider.js +26 -25
  538. package/dist/react/components/EditorRefEffect.internal.js +74 -0
  539. package/dist/react/components/EditorRefEffect.js +12 -56
  540. package/dist/react/components/NodeSelection.js +513 -485
  541. package/dist/react/components/Plate.js +259 -185
  542. package/dist/react/components/PlateContainer.js +110 -45
  543. package/dist/react/components/PlateContent.js +3 -3
  544. package/dist/react/components/PlateController.js +28 -16
  545. package/dist/react/components/PlateRoot.internal.js +3 -2
  546. package/dist/react/components/PlateView.js +34 -20
  547. package/dist/{static/internal/getPlainText.js → react/components/getPlainText.internal.js} +1 -4
  548. package/dist/react/components/plate-nodes.js +66 -87
  549. package/dist/{static/internal/writeStaticSelectionClipboardData.js → react/components/writeStaticSelectionClipboardData.internal.js} +11 -7
  550. package/dist/react/core.js +8 -17
  551. package/dist/react/editor/getPlateCorePlugins.internal.js +1 -1
  552. package/dist/react/editor/useCreateEditor.js +19 -17
  553. package/dist/react/editor/withPlate.js +11 -8
  554. package/dist/react/features/basic-styles/BasicStylePlugins.js +2 -3
  555. package/dist/react/features/board/BoardPlugin.js +8 -2
  556. package/dist/react/features/board/BoardShape.js +475 -169
  557. package/dist/react/features/board/BoardSurface.js +118 -89
  558. package/dist/react/features/board/boardCamera.internal.js +295 -0
  559. package/dist/react/features/board/boardClipboard.internal.js +41 -32
  560. package/dist/react/features/board/boardConnect.internal.js +2 -10
  561. package/dist/react/features/board/boardExport.internal.js +757 -0
  562. package/dist/react/features/board/boardGesture.internal.js +234 -65
  563. package/dist/react/features/board/boardIndex.internal.js +282 -46
  564. package/dist/react/features/board/boardInk.internal.js +2 -13
  565. package/dist/react/features/board/boardKeys.internal.js +76 -47
  566. package/dist/react/features/board/boardLanding.internal.js +147 -0
  567. package/dist/react/features/board/boardPick.internal.js +4 -3
  568. package/dist/react/features/board/boardPicking.internal.js +0 -17
  569. package/dist/react/features/board/boardPictureStyles.internal.js +415 -0
  570. package/dist/react/features/board/boardPictures.internal.js +19 -13
  571. package/dist/react/features/board/boardPreview.internal.js +74 -16
  572. package/dist/react/features/board/boardResize.internal.js +114 -47
  573. package/dist/react/features/board/boardSnap.internal.js +14 -9
  574. package/dist/react/features/board/boardStyleView.internal.js +123 -0
  575. package/dist/react/features/board/boardTextFit.internal.js +311 -0
  576. package/dist/react/features/board/boardView.internal.js +560 -552
  577. package/dist/react/features/board/boardVoice.internal.js +29 -17
  578. package/dist/react/features/board/boardWindow.internal.js +138 -0
  579. package/dist/react/features/board/index.d.ts +559 -156
  580. package/dist/react/features/board/index.js +3 -3
  581. package/dist/react/features/callout/index.d.ts +212 -39
  582. package/dist/react/features/{layout → column}/ColumnPlugin.js +4 -3
  583. package/dist/react/features/column/index.d.ts +808 -0
  584. package/dist/react/features/combobox/combobox.internal.js +119 -0
  585. package/dist/react/features/combobox/comboboxOwner.internal.js +76 -27
  586. package/dist/react/features/combobox/index.d.ts +51 -18
  587. package/dist/react/features/combobox/useCombobox.js +50 -13
  588. package/dist/react/features/comments/CommentsPlugin.js +2 -3
  589. package/dist/react/features/comments/index.d.ts +74 -342
  590. package/dist/react/features/comments/index.js +2 -1
  591. package/dist/react/features/comments/useCommentThreadIndex.js +243 -0
  592. package/dist/react/features/date/index.d.ts +4 -3
  593. package/dist/react/features/details/index.d.ts +126 -10
  594. package/dist/react/features/field/FieldPlugin.js +49 -0
  595. package/dist/react/features/field/index.d.ts +326 -0
  596. package/dist/react/features/field/index.js +2 -0
  597. package/dist/react/features/footnote/FootnotePlugin.js +13 -8
  598. package/dist/react/features/footnote/index.d.ts +373 -130
  599. package/dist/react/features/format-painter/FormatPainterPlugin.js +66 -27
  600. package/dist/react/features/format-painter/index.d.ts +13 -120
  601. package/dist/react/features/ink/InkContent.js +375 -0
  602. package/dist/react/features/ink/InkPlugin.js +102 -6
  603. package/dist/react/features/ink/index.d.ts +290 -260
  604. package/dist/react/features/ink/index.js +2 -3
  605. package/dist/react/features/ink/inkCapture.internal.js +338 -57
  606. package/dist/react/features/ink/inkImages.internal.js +304 -0
  607. package/dist/react/features/ink/inkInput.internal.js +43 -4
  608. package/dist/react/features/ink/inkLayout.internal.js +6 -3
  609. package/dist/react/features/ink/inkMeasure.internal.js +43 -17
  610. package/dist/react/features/ink/inkPaint.internal.js +134 -10
  611. package/dist/react/features/ink/inkPick.internal.js +323 -0
  612. package/dist/react/features/ink/inkPlacement.internal.js +420 -167
  613. package/dist/react/features/ink/inkWatch.internal.js +7 -36
  614. package/dist/react/features/list/ListPlugin.js +74 -38
  615. package/dist/react/features/lock/LockPlugin.js +138 -0
  616. package/dist/react/features/lock/index.d.ts +60 -0
  617. package/dist/react/features/lock/index.js +2 -0
  618. package/dist/react/features/media/index.d.ts +55 -35
  619. package/dist/react/features/mention/index.d.ts +13 -17
  620. package/dist/react/features/resizable/Resizable.js +9 -8
  621. package/dist/react/features/resizable/index.d.ts +7 -6
  622. package/dist/react/features/table/TablePlugin.js +251 -85
  623. package/dist/react/features/table/index.d.ts +1247 -2690
  624. package/dist/react/features/table/index.js +2 -1
  625. package/dist/react/features/table/measureTableColumnWidths.internal.js +48 -0
  626. package/dist/react/features/table/tableSelectionHostBinding.internal.js +4 -6
  627. package/dist/react/features/table/useTableControls.js +1170 -0
  628. package/dist/react/features/table/useTableResize.js +57 -16
  629. package/dist/react/features/toc/TocPlugin.js +1 -0
  630. package/dist/react/features/toc/index.d.ts +9 -11
  631. package/dist/react/features/upload/UploadPlugin.js +14 -5
  632. package/dist/react/features/upload/index.d.ts +25 -201
  633. package/dist/react/index.d.ts +7 -6
  634. package/dist/react/index.js +12 -21
  635. package/dist/react/internal/plate-context.js +472 -205
  636. package/dist/react/internal/plite-components.js +2 -2
  637. package/dist/react/internal/rendered-attributes.js +1 -1
  638. package/dist/react/internal/useDeepCompareMemo.js +36 -7
  639. package/dist/react/internal/usePlateModelRevision.js +13 -9
  640. package/dist/react/plite-react.js +2 -2
  641. package/dist/react/plugin/pluginFactory.internal.js +1 -37
  642. package/dist/react/plugin/toReactPlugin.js +40 -8
  643. package/dist/react/plugins/navigation-feedback/NavigationFeedbackPlugin.js +12 -10
  644. package/dist/react/plugins/paragraph/ParagraphPlugin.js +3 -3
  645. package/dist/react/stores/element/useElement.js +2 -2
  646. package/dist/react/stores/element/useElementSelector.js +4 -2
  647. package/dist/react/stores/element/useElementStore.js +142 -106
  648. package/dist/react/stores/element/useElementStoreSelector.internal.js +80 -24
  649. package/dist/react/stores/element/usePath.js +32 -32
  650. package/dist/react/stores/plate/pluginStoreSelector.internal.js +44 -0
  651. package/dist/react/stores/plate/useEditor.js +135 -71
  652. package/dist/react/stores/plate/useEditorHistory.js +55 -0
  653. package/dist/react/stores/plate/useEditorSelector.js +33 -22
  654. package/dist/react/stores/plate/usePluginStore.js +36 -43
  655. package/dist/react/stores/plate/useViewStore.js +38 -23
  656. package/dist/react/utils/BlockPlaceholderPlugin.js +41 -26
  657. package/dist/react/utils/dispatchPlateShortcut.internal.js +2 -1
  658. package/dist/react/utils/editableKeyDown.internal.js +1 -0
  659. package/dist/react/utils/getRenderNodeProps.internal.js +18 -19
  660. package/dist/react/utils/hardAffinityBoundary.internal.js +25 -0
  661. package/dist/react/utils/pipeHandler.internal.js +43 -17
  662. package/dist/react/utils/pipeRenderElement.internal.js +86 -70
  663. package/dist/react/utils/pipeRenderLeaf.internal.js +26 -45
  664. package/dist/react/utils/pipeRenderText.internal.js +44 -42
  665. package/dist/react/utils/pluginRenderElement.internal.js +9 -7
  666. package/dist/react/utils/pluginRenderLeaf.internal.js +6 -28
  667. package/dist/react/utils/pluginRenderText.internal.js +3 -15
  668. package/dist/react/utils/useSelectionFragment.js +8 -2
  669. package/dist/react/virtualized.d.ts +7 -6
  670. package/dist/react/virtualized.js +2 -2
  671. package/dist/refusal-hmMeqqsF-DEODtsVZ.d.ts +1 -0
  672. package/dist/registerEditorTools-CxU5qGen.d.ts +519 -0
  673. package/dist/root.js +6 -15
  674. package/dist/shared-room-D0Ch6_0l-DEODtsVZ.d.ts +1 -0
  675. package/dist/skills/plate/SKILL.md +49 -0
  676. package/dist/skills/plate/references/ai-and-agents.md +16 -0
  677. package/dist/skills/plate/references/plugins.md +22 -0
  678. package/dist/skills/plate/references/pricing.md +38 -0
  679. package/dist/skills/plate/references/report-a-bug.md +8 -0
  680. package/dist/skills/plate/references/setup.md +78 -0
  681. package/dist/skills/plate/references/testing.md +22 -0
  682. package/dist/skills/plate/references/ui-and-sync.md +25 -0
  683. package/dist/{source-CNKy99Th.d.ts → source-SWPrNfXp.d.ts} +32 -20
  684. package/dist/static/components/{PlateStatic.js → EditorStatic.js} +184 -42
  685. package/dist/static/components/plite-nodes.js +40 -17
  686. package/dist/static/index.d.ts +60 -38
  687. package/dist/static/index.js +1 -1
  688. package/dist/static/internal/loadStaticRenderer.js +4 -0
  689. package/dist/static/internal/staticDocumentView.js +219 -17
  690. package/dist/static/internal/staticPendingMedia.internal.js +147 -0
  691. package/dist/static/internal/staticPresentation.js +22 -25
  692. package/dist/static/internal/staticViewState.internal.js +47 -0
  693. package/dist/static/pipeRenderElementStatic.internal.js +3 -13
  694. package/dist/static/pluginRenderElementStatic.internal.js +32 -7
  695. package/dist/static/pluginRenderMarkStatic.internal.js +90 -0
  696. package/dist/static/renderStaticHtml.js +92 -6
  697. package/dist/static/utils/fallbackContentRoots.internal.js +15 -0
  698. package/dist/static/utils/getRenderNodeStaticProps.internal.js +12 -5
  699. package/dist/storage-BiSc0Cnj-BamxXwsJ.d.ts +250 -0
  700. package/dist/sync/SyncPlugin.js +16 -0
  701. package/dist/sync/cloudflare/index.d.ts +72 -0
  702. package/dist/sync/cloudflare/index.js +2 -0
  703. package/dist/sync/index.d.ts +5 -0
  704. package/dist/sync/index.js +3 -0
  705. package/dist/sync/postgres/index.d.ts +41 -0
  706. package/dist/sync/postgres/index.js +2 -0
  707. package/dist/sync/react/SyncReactPlugin.js +20 -0
  708. package/dist/sync/react/hooks.js +71 -0
  709. package/dist/sync/react/index.d.ts +87 -0
  710. package/dist/sync/react/index.js +3 -0
  711. package/dist/sync/server/index.d.ts +6 -0
  712. package/dist/sync/server/index.js +2 -0
  713. package/dist/tabbable/react/TabbableEffects.internal.js +96 -37
  714. package/dist/tabbable/react/TabbablePlugin.js +6 -1
  715. package/dist/tabbable/react/index.d.ts +63 -5
  716. package/dist/testing/index.d.ts +20 -10
  717. package/dist/transport-CWTT3vFK-_eytF0bO.d.ts +78 -0
  718. package/dist/{index-BU6k1Aev.d.ts → tx-only-CFSEh_pE-j0KGzcne.d.ts} +8226 -6860
  719. package/dist/utils/plate-keys.js +4 -9
  720. package/dist/utils/plugins/TrailingBlockPlugin.js +10 -7
  721. package/dist/utils/plugins/resolveTrailingBlockType.internal.js +8 -0
  722. package/dist/{index-xdmCBvlT.d.ts → widths-C1tAKF__.d.ts} +590 -140
  723. package/package.json +94 -148
  724. package/LICENSE +0 -24
  725. package/dist/AIChatRequestContext-BMVWhfPV.d.ts +0 -34
  726. package/dist/BaseSuggestionPlugin-DBl3fqnm.d.ts +0 -86
  727. package/dist/PlateStatic-DhNv2ejp.d.ts +0 -19
  728. package/dist/ai/lib/AIChatRequestContext.js +0 -16
  729. package/dist/ai/lib/findQuotedSpan.internal.js +0 -63
  730. package/dist/ai/react/AIChatPlugin.js +0 -1203
  731. package/dist/ai/react/useAIChat.js +0 -327
  732. package/dist/combobox-DkBGgyd3.d.ts +0 -22
  733. package/dist/comparison-types-CYnJ35qU.d.ts +0 -169
  734. package/dist/docs/excalidraw.md +0 -200
  735. package/dist/docs/installation/docs.md +0 -24
  736. package/dist/docs/installation/mcp.md +0 -147
  737. package/dist/docs/migration/plite-to-plate.md +0 -251
  738. package/dist/docs/yjs.md +0 -256
  739. package/dist/docx/export/lib/comments.js +0 -231
  740. package/dist/docx/export/lib/docxStaticComponents.js +0 -371
  741. package/dist/docx/export/lib/exportHtmlToDocx.internal.js +0 -70
  742. package/dist/docx/export/lib/generatedParts.js +0 -51
  743. package/dist/docx/export/lib/html-to-docx.internal.js +0 -40
  744. package/dist/docx/export/lib/internal/constants.js +0 -106
  745. package/dist/docx/export/lib/internal/docx-document.js +0 -652
  746. package/dist/docx/export/lib/internal/escape-xml.js +0 -4
  747. package/dist/docx/export/lib/internal/html-to-docx.js +0 -148
  748. package/dist/docx/export/lib/internal/list-item.js +0 -85
  749. package/dist/docx/export/lib/internal/list.js +0 -43
  750. package/dist/docx/export/lib/internal/math.js +0 -187
  751. package/dist/docx/export/lib/internal/namespaces.js +0 -40
  752. package/dist/docx/export/lib/internal/render-document-file.js +0 -403
  753. package/dist/docx/export/lib/internal/schemas/content-types.js +0 -25
  754. package/dist/docx/export/lib/internal/schemas/core.js +0 -26
  755. package/dist/docx/export/lib/internal/schemas/document-rels.js +0 -15
  756. package/dist/docx/export/lib/internal/schemas/document.template.js +0 -36
  757. package/dist/docx/export/lib/internal/schemas/font-table.js +0 -55
  758. package/dist/docx/export/lib/internal/schemas/generic-rels.js +0 -9
  759. package/dist/docx/export/lib/internal/schemas/numbering.js +0 -18
  760. package/dist/docx/export/lib/internal/schemas/rels.js +0 -12
  761. package/dist/docx/export/lib/internal/schemas/settings.js +0 -17
  762. package/dist/docx/export/lib/internal/schemas/styles.js +0 -142
  763. package/dist/docx/export/lib/internal/schemas/theme.js +0 -198
  764. package/dist/docx/export/lib/internal/schemas/web-settings.js +0 -10
  765. package/dist/docx/export/lib/internal/unit-conversion.js +0 -24
  766. package/dist/docx/export/lib/internal/vnode.js +0 -4
  767. package/dist/docx/export/lib/internal/word-styles.js +0 -123
  768. package/dist/docx/export/lib/internal/xml-builder.js +0 -1808
  769. package/dist/docx/export/lib/reviewPart.js +0 -234
  770. package/dist/docx/import/lib/wordFormatting.js +0 -608
  771. package/dist/docx/internal/domParser.js +0 -23
  772. package/dist/excalidraw/index.d.ts +0 -57
  773. package/dist/excalidraw/index.js +0 -2
  774. package/dist/excalidraw/lib/BaseExcalidrawPlugin.js +0 -15
  775. package/dist/excalidraw/react/ExcalidrawPlugin.js +0 -6
  776. package/dist/excalidraw/react/index.d.ts +0 -101
  777. package/dist/excalidraw/react/index.js +0 -3
  778. package/dist/excalidraw/react/useExcalidrawSync.js +0 -103
  779. package/dist/features/combobox/index.d.ts +0 -3
  780. package/dist/features/combobox/index.js +0 -2
  781. package/dist/features/combobox/lib/combobox.internal.js +0 -111
  782. package/dist/features/combobox/lib/filterWords.js +0 -23
  783. package/dist/features/comments/plite-comments.internal.js +0 -2
  784. package/dist/features/ink/lib/inkGone.internal.js +0 -107
  785. package/dist/features/layout/index.d.ts +0 -2
  786. package/dist/features/layout/lib/BaseColumnPlugin.js +0 -249
  787. package/dist/features/media/lib/media/parseMediaUrl.js +0 -151
  788. package/dist/features/suggestion/BaseSuggestionPlugin.js +0 -30
  789. package/dist/features/suggestion/index.d.ts +0 -9
  790. package/dist/features/suggestion/index.js +0 -3
  791. package/dist/features/suggestion/suggestionColorOf.js +0 -14
  792. package/dist/features/upload/lib/mimeTypes.internal.js +0 -3982
  793. package/dist/index-BBKGrsG3.d.ts +0 -8
  794. package/dist/index-BiQerPJS.d.ts +0 -46
  795. package/dist/index-BkR7-GLI.d.ts +0 -166
  796. package/dist/index-Bq3sdm3S.d.ts +0 -158
  797. package/dist/index-CT7miqQN.d.ts +0 -298
  798. package/dist/index-Cl77E9yr.d.ts +0 -184
  799. package/dist/index-D1CFXA-i.d.ts +0 -6187
  800. package/dist/index-DLA2DUR2.d.ts +0 -28
  801. package/dist/index-DdIRduDG.d.ts +0 -399
  802. package/dist/index-iaZOhA76.d.ts +0 -59
  803. package/dist/index-kLKMc-pI.d.ts +0 -36
  804. package/dist/internal/plugin/plateChangeHandlers.js +0 -74
  805. package/dist/lib/plugins/element-id/ElementIdPlugin.js +0 -47
  806. package/dist/lib/plugins/element-id/elementIdAdmission.internal.js +0 -34
  807. package/dist/lib/plugins/element-state/ElementStatePlugin.js +0 -14
  808. package/dist/lib/utils/applyDeepToNodes.js +0 -17
  809. package/dist/lib/utils/defaultsDeepToNodes.js +0 -12
  810. package/dist/lib/utils/hotkeys.js +0 -113
  811. package/dist/lib/utils/mergeDeepToNodes.js +0 -12
  812. package/dist/lib/utils/pluginNodeClass.js +0 -10
  813. package/dist/markdown/lib/internal/markdownConversion.js +0 -666
  814. package/dist/markdown/lib/internal/markdownSegments.js +0 -134
  815. package/dist/markdown/lib/serializer/convertTextsSerialize.js +0 -163
  816. package/dist/migrations/migrateListIdentity.js +0 -93
  817. package/dist/pagination/react/PagedEditorContent.js +0 -77
  818. package/dist/react/components/EditorSelectionView.js +0 -40
  819. package/dist/react/features/ink/InkCopyView.js +0 -203
  820. package/dist/react/features/ink/InkLayer.js +0 -218
  821. package/dist/react/features/suggestion/SuggestionPlugin.js +0 -24
  822. package/dist/react/features/suggestion/index.d.ts +0 -44
  823. package/dist/react/features/suggestion/index.js +0 -3
  824. package/dist/react/features/suggestion/suggestion-view.internal.js +0 -112
  825. package/dist/react/features/suggestion/useSuggestion.js +0 -135
  826. package/dist/react/internal/createPlateTargetScope.js +0 -62
  827. package/dist/react/libs/jotai.js +0 -3
  828. package/dist/static/internal/renderStaticHtmlWithOverrides.js +0 -33
  829. package/dist/static/pluginRenderLeafStatic.internal.js +0 -87
  830. package/dist/static/pluginRenderTextStatic.internal.js +0 -87
  831. package/dist/tabbable/index.d.ts +0 -2
  832. package/dist/tabbable/index.js +0 -0
  833. package/dist/utils/plugins/ExitBreakPlugin.js +0 -26
  834. package/dist/yjs/index.d.ts +0 -2
  835. package/dist/yjs/index.js +0 -1
  836. package/dist/yjs/react/YjsPlugin.js +0 -60
  837. package/dist/yjs/react/index.d.ts +0 -94
  838. package/dist/yjs/react/index.js +0 -3
  839. /package/dist/features/{layout → column}/index.js +0 -0
  840. /package/dist/react/features/{layout → column}/index.js +0 -0
@@ -0,0 +1,1081 @@
1
+ import { EditorRefusalError, createAuthoredEditorView, getCompiledEditorSchema, getEditorAuthoredDocumentCapability, hasNonWritableAt } from "../../facade.js";
2
+ import { BaseParagraphPlugin } from "../../lib/plugins/paragraph/BaseParagraphPlugin.js";
3
+ import { ContentSlice, ElementApi, NodeApi, PathApi, RangeApi, createEditorView } from "../../core.js";
4
+ import { isListItem } from "../../features/list/lib/listIndex.internal.js";
5
+ import { AuthoredPlugin } from "../../authored/AuthoredPlugin.js";
6
+ import { MarkdownPlugin } from "../../markdown/lib/MarkdownPlugin.js";
7
+ import { applyMinimalTextBlockEdits, fillEmptyListItem, landAIOutput, normalizeUnlockedListRun, suggestionBlocks } from "./aiOutputLanding.internal.js";
8
+ import { findDisallowedRemoteMediaUrlsInMarkdown, hasHiddenDescendant, isEditorVisibilityFilter, isPathVisible, isRangeVisible, pruneHiddenDescendants, resolveVisibilityFilter, sanitizeRemoteMediaNodes } from "./aiPolicy.internal.js";
9
+ import { areAIBlockTargetsContiguous, isAIPathNonWritable, resolveAISelectedBlocks } from "./lockedContext.internal.js";
10
+ import { LOCKED_BLOCK_PLACEHOLDER_TAG } from "./lockedContext.js";
11
+ import isEqual from "lodash/isEqual.js";
12
+ import cloneDeep from "lodash/cloneDeep.js";
13
+ //#region src/ai/lib/aiDraftSession.ts
14
+ const EMPTY_DRAFT_NODES = Object.freeze([]);
15
+ const AI_INTERNAL_REFUSAL_STALE = "ai-session-internal-stale";
16
+ const AI_INTERNAL_REFUSAL_HIDDEN = "ai-session-internal-hidden";
17
+ const AI_INTERNAL_REFUSAL_LOCKED = "ai-session-internal-locked";
18
+ const AI_INTERNAL_REFUSAL_WITHDRAW = "ai-session-internal-withdraw";
19
+ const isLockRefusalRecord = (record) => {
20
+ if (!record || typeof record !== "object") return false;
21
+ const { reason } = record;
22
+ return reason === "block-locked" || reason === "node-write-veto";
23
+ };
24
+ const readRefusalReason = (record) => record && typeof record === "object" && typeof record.reason === "string" ? record.reason : null;
25
+ const mapUpdateRefusal = (refusal, cellRef) => {
26
+ const reason = readRefusalReason(refusal);
27
+ if (reason === AI_INTERNAL_REFUSAL_STALE) return Object.freeze({ status: "stale" });
28
+ if (reason === AI_INTERNAL_REFUSAL_HIDDEN) return Object.freeze({
29
+ refusal: { reason: "hidden-content" },
30
+ status: "refused"
31
+ });
32
+ if (reason === AI_INTERNAL_REFUSAL_LOCKED) return Object.freeze({
33
+ refusal: { reason: "block-locked" },
34
+ status: "refused"
35
+ });
36
+ if (reason === AI_INTERNAL_REFUSAL_WITHDRAW) return Object.freeze({ status: "refused" });
37
+ if (isLockRefusalRecord(refusal) || refusal === void 0) return Object.freeze({
38
+ refusal: cellRef === void 0 ? { reason: "block-locked" } : {
39
+ reason: "block-locked",
40
+ ref: cellRef
41
+ },
42
+ status: "refused"
43
+ });
44
+ return Object.freeze({
45
+ refusal,
46
+ status: "refused"
47
+ });
48
+ };
49
+ const stripMarkdownSyntax = (input) => input.replaceAll(/<\/?[a-zA-Z][\w-]*(?:\s+[^>]*)?\/?>/g, "").replaceAll(/!\[([^\]]*)\]\([^)]*\)/g, "$1").replaceAll(/\[([^\]]+)\]\([^)]*\)/g, "$1").replaceAll(/^\s{0,3}(?:---+|\*\*\*+|___+)\s*$/gm, "").replaceAll(/^\s{0,3}(?:#{1,6}\s+|>\s+|[-*+]\s+|\d+\.\s+)/gm, "").replaceAll(/(\*\*|__|~~|`)/g, "").replaceAll(/(^|[^\w])\*([^*]+)\*(?=[^\w]|$)/g, "$1$2").replaceAll(/(^|[^\w])_([^_]+)_(?=[^\w]|$)/g, "$1$2");
50
+ const normalizeWithIndexMap = (text) => {
51
+ const chars = [];
52
+ const map = [];
53
+ let pendingSpace = false;
54
+ for (let index = 0; index < text.length; index += 1) {
55
+ const ch = text[index];
56
+ if (ch === void 0) continue;
57
+ if (/\s/.test(ch)) {
58
+ if (chars.length > 0) pendingSpace = true;
59
+ continue;
60
+ }
61
+ if (pendingSpace) {
62
+ chars.push(" ");
63
+ map.push(index);
64
+ pendingSpace = false;
65
+ }
66
+ chars.push(ch.toLowerCase());
67
+ map.push(index);
68
+ }
69
+ return {
70
+ map,
71
+ normalized: chars.join("")
72
+ };
73
+ };
74
+ const projectBlocksForRoot = (editor, root, entries) => {
75
+ if (!editor.plugin(AuthoredPlugin).installed) return entries.map(([node]) => node);
76
+ const capability = getEditorAuthoredDocumentCapability(editor);
77
+ if (!capability) return entries.map(([node]) => node);
78
+ const projected = capability.projectBlocks(editor.read.value(), "proposed", getCompiledEditorSchema(editor), root ?? "main", entries.map(([, path]) => path));
79
+ return (projected.ok ? projected.blocks : entries.map(([node]) => node)).filter((node) => ElementApi.isElement(node));
80
+ };
81
+ const toElementValue = (nodes) => nodes.filter((node) => ElementApi.isElement(node));
82
+ /**
83
+ * Create a headless inline AI draft session bound to the invoking editor root,
84
+ * selection, visibility filter, and remote-media policy.
85
+ */
86
+ const createAIDraftSession = (editor, options) => {
87
+ if (typeof options.authorId !== "string" || options.authorId.trim().length === 0) throw new TypeError("createAIDraftSession requires a non-empty authorId.");
88
+ if (!isEditorVisibilityFilter(options.filter)) throw new TypeError("createAIDraftSession requires filter to be \"allow-all\", a function, or { forDocument }.");
89
+ const { authorId } = options;
90
+ const { filter } = options;
91
+ const currentFilter = (target = editor) => resolveVisibilityFilter(target, filter);
92
+ const { mode } = options;
93
+ const pinnedRoot = editor.read.view.root();
94
+ const baselineRevision = editor.read.revision();
95
+ const currentSelection = editor.read.selection();
96
+ const capturedSelection = currentSelection ? cloneDeep(currentSelection) : null;
97
+ const resolvedSelection = resolveAISelectedBlocks(editor);
98
+ const initialRoots = editor.read.value().roots;
99
+ const initialFilter = currentFilter(editor);
100
+ const selectionContainsHiddenBlocks = resolvedSelection.entries.some(([node, path]) => !isPathVisible(editor, initialFilter, path, pinnedRoot) || hasHiddenDescendant(initialFilter, node, path, pinnedRoot, initialRoots));
101
+ const visibleEntries = resolvedSelection.entries.filter(([node, path]) => isPathVisible(editor, initialFilter, path, pinnedRoot) && pruneHiddenDescendants(initialFilter, node, path, pinnedRoot) !== null);
102
+ const selectionAnchor = capturedSelection && RangeApi.isExpanded(capturedSelection) ? editor.anchor(capturedSelection, {
103
+ association: "inward",
104
+ deletion: "drop"
105
+ }) : null;
106
+ const targetNodeKeys = [];
107
+ for (const [node] of visibleEntries) {
108
+ const key = editor.key(node);
109
+ if (key) targetNodeKeys.push(key);
110
+ }
111
+ if (targetNodeKeys.length === 0 && capturedSelection) {
112
+ const currentBlock = editor.read.nodes.block({ at: capturedSelection });
113
+ if (currentBlock && isPathVisible(editor, filter, currentBlock[1], pinnedRoot)) {
114
+ const key = editor.key(currentBlock[0]);
115
+ if (key) targetNodeKeys.push(key);
116
+ }
117
+ }
118
+ const lockedBlockKeys = /* @__PURE__ */ new Map();
119
+ const expectedLockedRefs = [];
120
+ for (const lockedRef of options.lockedBlocks ?? []) {
121
+ const entry = editor.read.nodes.get(lockedRef.path, { match: ElementApi.isElement });
122
+ const key = entry ? editor.key(entry[0]) : void 0;
123
+ if (key) {
124
+ lockedBlockKeys.set(lockedRef.ref, key);
125
+ expectedLockedRefs.push(lockedRef.ref);
126
+ }
127
+ }
128
+ const tableCellAllowlist = /* @__PURE__ */ new Map();
129
+ for (const cellRef of options.tableCells ?? []) {
130
+ if (!isPathVisible(editor, filter, cellRef.path, pinnedRoot)) continue;
131
+ const entry = editor.read.nodes.get(cellRef.path, { match: ElementApi.isElement });
132
+ const key = entry ? editor.key(entry[0]) : void 0;
133
+ if (key) tableCellAllowlist.set(cellRef.ref, key);
134
+ }
135
+ const anchorKey = targetNodeKeys.at(-1) ?? null;
136
+ let disposed = false;
137
+ let hasTableCellEdits = false;
138
+ let rawMarkdown = "";
139
+ let stream = null;
140
+ let cachedProposeView = null;
141
+ let cachedRootView = null;
142
+ let lastCommittedRevision = null;
143
+ let baselineSourceNodes = null;
144
+ let baselineLockedSourceRuns = null;
145
+ const readNodeAnchor = (view, key) => {
146
+ const entry = view.read.nodes.get(key, { match: ElementApi.isElement });
147
+ if (!entry) return null;
148
+ const [node, path] = entry;
149
+ const nodeId = typeof node.id === "string" && node.id.length > 0 ? node.id : null;
150
+ const revision = (nodeId !== null ? view.read.nodes.revision(nodeId) : null) ?? JSON.stringify(node);
151
+ const parentEntry = path.length > 1 ? view.read.nodes.get(PathApi.parent(path), { match: ElementApi.isElement }) : void 0;
152
+ return {
153
+ key,
154
+ parentKey: parentEntry ? view.key(parentEntry[0]) ?? null : null,
155
+ revision
156
+ };
157
+ };
158
+ const captureTargetAnchor = (view) => {
159
+ if (targetNodeKeys.length === 0) return null;
160
+ const entries = [];
161
+ for (const key of targetNodeKeys) {
162
+ const entry = view.read.nodes.get(key, { match: ElementApi.isElement });
163
+ if (!entry) return null;
164
+ entries.push([
165
+ entry[0],
166
+ entry[1],
167
+ key
168
+ ]);
169
+ }
170
+ entries.sort(([, left], [, right]) => PathApi.compare(left, right));
171
+ const anchors = [];
172
+ for (const entry of entries) {
173
+ const anchor = readNodeAnchor(view, entry[2]);
174
+ if (!anchor) return null;
175
+ anchors.push(anchor);
176
+ }
177
+ return anchors;
178
+ };
179
+ let targetAnchor = captureTargetAnchor(editor);
180
+ const cellAnchorRevisions = /* @__PURE__ */ new Map();
181
+ for (const key of tableCellAllowlist.values()) cellAnchorRevisions.set(key, readNodeAnchor(editor, key)?.revision ?? null);
182
+ const refreshAnchors = (refreshOptions) => {
183
+ lastCommittedRevision = editor.read.revision();
184
+ if (refreshOptions?.onlyCellKey !== void 0) {
185
+ const { onlyCellKey, refreshTargetAnchor } = refreshOptions;
186
+ cellAnchorRevisions.set(onlyCellKey, readNodeAnchor(getRootView(), onlyCellKey)?.revision ?? null);
187
+ if (refreshTargetAnchor) targetAnchor = captureTargetAnchor(getRootView());
188
+ return;
189
+ }
190
+ targetAnchor = captureTargetAnchor(getRootView());
191
+ for (const key of tableCellAllowlist.values()) cellAnchorRevisions.set(key, readNodeAnchor(getRootView(), key)?.revision ?? null);
192
+ };
193
+ let snapshot = Object.freeze({
194
+ anchorKey,
195
+ changeId: null,
196
+ draftNodes: EMPTY_DRAFT_NODES,
197
+ error: null,
198
+ mode,
199
+ root: pinnedRoot,
200
+ status: "streaming"
201
+ });
202
+ const listeners = /* @__PURE__ */ new Set();
203
+ const emit = (patch) => {
204
+ snapshot = Object.freeze({
205
+ ...snapshot,
206
+ ...patch
207
+ });
208
+ for (const listener of [...listeners]) listener(snapshot);
209
+ return snapshot;
210
+ };
211
+ const getRootView = () => {
212
+ if (!cachedRootView) cachedRootView = pinnedRoot !== void 0 ? createEditorView(editor, { root: pinnedRoot }) : editor;
213
+ return cachedRootView;
214
+ };
215
+ const getProposeView = () => {
216
+ if (!editor.plugin(AuthoredPlugin).installed) return null;
217
+ if (!cachedProposeView) cachedProposeView = createAuthoredEditorView(editor, {
218
+ authorId,
219
+ authored: { intent: "propose" },
220
+ writePolicy: "propose-only",
221
+ ...pinnedRoot !== void 0 ? { root: pinnedRoot } : {}
222
+ });
223
+ return cachedProposeView;
224
+ };
225
+ const ensureStream = () => {
226
+ const markdownPlugin = editor.plugin(MarkdownPlugin);
227
+ if (!markdownPlugin.installed) return null;
228
+ if (!stream) stream = markdownPlugin.api.stream({
229
+ lossPolicy: "allow",
230
+ mode: "blocks"
231
+ });
232
+ return stream;
233
+ };
234
+ const sanitizeDraftOutput = (nodes) => {
235
+ const sanitized = sanitizeRemoteMediaNodes(nodes, options.allowRemoteMediaUrl);
236
+ return {
237
+ nodes: toElementValue(sanitized.nodes),
238
+ removedUrls: sanitized.removedUrls
239
+ };
240
+ };
241
+ const updateStreamPreview = (nextNodes) => {
242
+ const sanitized = sanitizeDraftOutput(nextNodes);
243
+ return emit({
244
+ draftNodes: Object.freeze([...sanitized.nodes]),
245
+ error: null,
246
+ status: "streaming"
247
+ });
248
+ };
249
+ const resolveOrderedTargetsFromNodes = (nodesApi, view) => {
250
+ if (targetNodeKeys.length === 0) return null;
251
+ const entries = [];
252
+ for (const key of targetNodeKeys) {
253
+ const entry = nodesApi.get(key, { match: ElementApi.isElement });
254
+ if (!entry) return null;
255
+ if (!isPathVisible(view, filter, entry[1], pinnedRoot)) return null;
256
+ entries.push([entry[0], entry[1]]);
257
+ }
258
+ entries.sort(([, left], [, right]) => PathApi.compare(left, right));
259
+ return entries;
260
+ };
261
+ const resolveOrderedTargets = (view) => resolveOrderedTargetsFromNodes(view.read.nodes, view);
262
+ const isTargetAnchorCurrent = (view = getRootView()) => {
263
+ if (targetAnchor === null) return editor.read.revision() === (lastCommittedRevision ?? baselineRevision);
264
+ const entries = [];
265
+ for (const expected of targetAnchor) {
266
+ const current = readNodeAnchor(view, expected.key);
267
+ if (!current || current.revision !== expected.revision || current.parentKey !== expected.parentKey) return false;
268
+ const entry = view.read.nodes.get(expected.key, { match: ElementApi.isElement });
269
+ if (!entry) return false;
270
+ entries.push([entry[0], entry[1]]);
271
+ }
272
+ if (entries.length > 1 && !selectionContainsHiddenBlocks) {
273
+ for (let i = 1; i < entries.length; i += 1) {
274
+ const prev = entries[i - 1];
275
+ const curr = entries[i];
276
+ if (!prev || !curr) return false;
277
+ if (PathApi.compare(prev[1], curr[1]) >= 0) return false;
278
+ }
279
+ if (!areAIBlockTargetsContiguous(view, entries)) return false;
280
+ }
281
+ return true;
282
+ };
283
+ const isCellAnchorCurrent = (cellKey) => {
284
+ const expected = cellAnchorRevisions.get(cellKey);
285
+ if (expected === void 0 || expected === null) return false;
286
+ const current = readNodeAnchor(getRootView(), cellKey);
287
+ return current !== null && current.revision === expected;
288
+ };
289
+ const withdrawOwnedChangeGuarded = (proposeView, currentChangeId) => {
290
+ if (!isTargetAnchorCurrent(getRootView())) return "stale";
291
+ const previous = editor.plugin(AuthoredPlugin).read.change(currentChangeId);
292
+ if (!previous) return "stale";
293
+ const result = proposeView.update.result((tx) => tx.plugin(AuthoredPlugin).withdraw([previous]));
294
+ if (result.status !== "committed" || result.value.status !== "applied") return result.status === "committed" && result.value.status === "stale" ? "stale" : "refused";
295
+ refreshAnchors();
296
+ return "applied";
297
+ };
298
+ const push = (markdownDelta) => {
299
+ if (disposed) return snapshot;
300
+ rawMarkdown += markdownDelta;
301
+ if (expectedLockedRefs.length > 0) return emit({ status: "streaming" });
302
+ const activeStream = ensureStream();
303
+ if (!activeStream) {
304
+ const paragraphType = editor.plugin(BaseParagraphPlugin).installed ? editor.plugin(BaseParagraphPlugin).schema.type : "p";
305
+ return updateStreamPreview([{
306
+ children: [{ text: rawMarkdown }],
307
+ type: paragraphType
308
+ }]);
309
+ }
310
+ const streamSnapshot = activeStream.append(markdownDelta);
311
+ if (!streamSnapshot.ok) return emit({
312
+ error: streamSnapshot.diagnostics[0].message,
313
+ status: "streaming"
314
+ });
315
+ return updateStreamPreview(streamSnapshot.nodes);
316
+ };
317
+ const set = (accumulatedMarkdown) => {
318
+ if (disposed) return snapshot;
319
+ rawMarkdown = accumulatedMarkdown;
320
+ if (expectedLockedRefs.length > 0) return emit({ status: "streaming" });
321
+ const activeStream = ensureStream();
322
+ if (!activeStream) {
323
+ const paragraphType = editor.plugin(BaseParagraphPlugin).installed ? editor.plugin(BaseParagraphPlugin).schema.type : "p";
324
+ return updateStreamPreview([{
325
+ children: [{ text: rawMarkdown }],
326
+ type: paragraphType
327
+ }]);
328
+ }
329
+ const streamSnapshot = activeStream.set(accumulatedMarkdown);
330
+ if (!streamSnapshot.ok) return emit({
331
+ error: streamSnapshot.diagnostics[0].message,
332
+ status: "streaming"
333
+ });
334
+ return updateStreamPreview(streamSnapshot.nodes);
335
+ };
336
+ const hasHiddenEditableTarget = (entries) => {
337
+ const { roots } = editor.read.value();
338
+ return selectionContainsHiddenBlocks || entries.some(([node, path]) => hasHiddenDescendant(currentFilter(editor), node, path, pinnedRoot, roots));
339
+ };
340
+ const isRevisionCurrent = () => isTargetAnchorCurrent(getRootView());
341
+ const landLockedSuggestion = (proposeView, rawDisallowedUrls) => {
342
+ const markdownPlugin = editor.plugin(MarkdownPlugin);
343
+ if (!markdownPlugin.installed) return Object.freeze({
344
+ refusal: { reason: "markdown-not-installed" },
345
+ status: "refused"
346
+ });
347
+ if (!isRevisionCurrent()) return Object.freeze({ status: "stale" });
348
+ const parsedPlaceholders = markdownPlugin.api.parsePlaceholders(rawMarkdown, {
349
+ lossPolicy: "allow",
350
+ tag: LOCKED_BLOCK_PLACEHOLDER_TAG
351
+ });
352
+ if (!parsedPlaceholders.ok) return Object.freeze({
353
+ refusal: { reason: "invalid-locked-placeholders" },
354
+ status: "refused"
355
+ });
356
+ const actualRefs = parsedPlaceholders.segments.flatMap((segment) => segment.kind === "placeholder" ? [segment.ref] : []);
357
+ if (actualRefs.length !== expectedLockedRefs.length || actualRefs.some((ref, index) => ref !== expectedLockedRefs[index])) return Object.freeze({
358
+ refusal: { reason: "locked-placeholder-mismatch" },
359
+ status: "refused"
360
+ });
361
+ const answerRuns = Array.from({ length: expectedLockedRefs.length + 1 }, () => []);
362
+ const removedUrls = [...rawDisallowedUrls];
363
+ let slotEmptiedByRemoteMedia = false;
364
+ let slotIndex = 0;
365
+ for (const segment of parsedPlaceholders.segments) if (segment.kind === "placeholder") slotIndex += 1;
366
+ else {
367
+ const sanitized = sanitizeDraftOutput(segment.nodes);
368
+ removedUrls.push(...sanitized.removedUrls);
369
+ if (segment.nodes.length > 0 && sanitized.nodes.length === 0 && sanitized.removedUrls.length > 0) slotEmptiedByRemoteMedia = true;
370
+ answerRuns[slotIndex]?.push(...sanitized.nodes);
371
+ }
372
+ const uniqueRemovedUrls = [...new Set(removedUrls)];
373
+ if (slotEmptiedByRemoteMedia || uniqueRemovedUrls.length > 0 && answerRuns.every((run) => run.length === 0)) return Object.freeze({
374
+ refusal: {
375
+ reason: "remote-media-denied",
376
+ urls: uniqueRemovedUrls
377
+ },
378
+ status: "refused"
379
+ });
380
+ const resolveLockedLayout = (nodesApi = proposeView.read.nodes) => {
381
+ const ordered = resolveOrderedTargetsFromNodes(nodesApi, proposeView);
382
+ if (!ordered) return { kind: "stale" };
383
+ if (hasHiddenEditableTarget(ordered)) return { kind: "hidden" };
384
+ if (!areAIBlockTargetsContiguous(proposeView, ordered)) return { kind: "stale" };
385
+ const lockedEntries = [];
386
+ const lockedIndices = [];
387
+ for (const ref of expectedLockedRefs) {
388
+ const key = lockedBlockKeys.get(ref);
389
+ const index = key ? ordered.findIndex(([node]) => proposeView.key(node) === key) : -1;
390
+ const previousIndex = lockedIndices.at(-1) ?? -1;
391
+ const lockedEntry = index >= 0 ? ordered[index] : void 0;
392
+ if (!lockedEntry || index <= previousIndex) return { kind: "stale" };
393
+ lockedIndices.push(index);
394
+ lockedEntries.push(lockedEntry);
395
+ }
396
+ const sourceRuns = [];
397
+ let cursor = 0;
398
+ for (const lockedIndex of lockedIndices) {
399
+ sourceRuns.push(ordered.slice(cursor, lockedIndex));
400
+ cursor = lockedIndex + 1;
401
+ }
402
+ sourceRuns.push(ordered.slice(cursor));
403
+ for (const run of sourceRuns) for (const [, path] of run) if (isAIPathNonWritable(proposeView, path)) return { kind: "locked" };
404
+ return {
405
+ kind: "ok",
406
+ lockedEntries,
407
+ sourceRuns
408
+ };
409
+ };
410
+ const preLayout = resolveLockedLayout();
411
+ if (preLayout.kind === "stale") return Object.freeze({ status: "stale" });
412
+ if (preLayout.kind === "hidden") return Object.freeze({
413
+ refusal: { reason: "hidden-content" },
414
+ status: "refused"
415
+ });
416
+ if (preLayout.kind === "locked") return Object.freeze({
417
+ refusal: { reason: "block-locked" },
418
+ status: "refused"
419
+ });
420
+ if (uniqueRemovedUrls.length > 0 && answerRuns.some((run, index) => run.length === 0 && (preLayout.sourceRuns[index]?.length ?? 0) > 0)) return Object.freeze({
421
+ refusal: {
422
+ reason: "remote-media-denied",
423
+ urls: uniqueRemovedUrls
424
+ },
425
+ status: "refused"
426
+ });
427
+ const currentChangeId = snapshot.changeId;
428
+ const previousChange = currentChangeId ? editor.plugin(AuthoredPlugin).read.change(currentChangeId) : null;
429
+ if (currentChangeId && !previousChange) return Object.freeze({ status: "stale" });
430
+ const prepareLockedRuns = (sourceRuns) => sourceRuns.map((sourceRun, index) => {
431
+ const answerRun = answerRuns[index] ?? [];
432
+ if (sourceRun.length === 0 || answerRun.length === 0) return answerRun;
433
+ const sourceNodes = sourceRun.map(([node]) => node);
434
+ const serialized = markdownPlugin.api.serialize({
435
+ document: { children: sourceNodes },
436
+ lossPolicy: "allow"
437
+ });
438
+ const reparsed = serialized.ok ? markdownPlugin.api.parseSlice(serialized.data, { lossPolicy: "allow" }) : void 0;
439
+ const roundTrip = reparsed?.ok && ElementApi.isElementList(reparsed.slice.content) ? reparsed.slice.content : null;
440
+ return normalizeUnlockedListRun(sourceNodes, suggestionBlocks(editor, proposeView.read, {
441
+ answer: answerRun,
442
+ roundTrip,
443
+ source: sourceNodes
444
+ }));
445
+ });
446
+ const firstProjectedLockedRuns = !currentChangeId ? preLayout.sourceRuns.map((run) => projectBlocksForRoot(editor, pinnedRoot, run)) : null;
447
+ const prePreparedRuns = firstProjectedLockedRuns ? prepareLockedRuns(firstProjectedLockedRuns.map((nodes, runIndex) => {
448
+ const sourceRun = preLayout.sourceRuns[runIndex] ?? [];
449
+ return nodes.map((node, i) => [node, sourceRun[i]?.[1] ?? []]);
450
+ })) : null;
451
+ const updateResult = proposeView.update.result((tx) => {
452
+ if (previousChange) {
453
+ const withdrawOutcome = tx.plugin(AuthoredPlugin).withdraw([previousChange]);
454
+ if (withdrawOutcome.status !== "applied") throw new EditorRefusalError({ reason: withdrawOutcome.status === "stale" ? AI_INTERNAL_REFUSAL_STALE : AI_INTERNAL_REFUSAL_WITHDRAW }, "AI draft withdraw failed.");
455
+ }
456
+ const postLayout = currentChangeId ? resolveLockedLayout(tx.nodes) : preLayout;
457
+ if (postLayout.kind !== "ok") throw new EditorRefusalError({ reason: postLayout.kind === "stale" ? AI_INTERNAL_REFUSAL_STALE : postLayout.kind === "hidden" ? AI_INTERNAL_REFUSAL_HIDDEN : AI_INTERNAL_REFUSAL_LOCKED }, "AI locked layout invalid after withdraw.");
458
+ const { lockedEntries, sourceRuns } = postLayout;
459
+ const savedLockedBaseline = baselineLockedSourceRuns;
460
+ const canReuseProjectedBaseline = savedLockedBaseline !== null && savedLockedBaseline.length === sourceRuns.length;
461
+ const preparedRuns = prePreparedRuns ?? prepareLockedRuns(canReuseProjectedBaseline ? savedLockedBaseline.map((nodes, runIndex) => {
462
+ const sourceRun = sourceRuns[runIndex] ?? [];
463
+ return nodes.map((node, i) => [node, sourceRun[i]?.[1] ?? sourceRun.at(-1)?.[1] ?? []]);
464
+ }) : sourceRuns);
465
+ const changeId = tx.plugin(AuthoredPlugin).propose(currentChangeId ? { changeId: currentChangeId } : void 0);
466
+ for (let index = sourceRuns.length - 1; index >= 0; index -= 1) {
467
+ const sourceRun = sourceRuns[index] ?? [];
468
+ const nextRun = preparedRuns[index] ?? [];
469
+ const lockedAfter = lockedEntries[index];
470
+ const lastLocked = lockedEntries.at(-1);
471
+ if (sourceRun.length === 0) {
472
+ const insertAt = lockedAfter ? lockedAfter[1] : lastLocked ? PathApi.next(lastLocked[1]) : null;
473
+ if (nextRun.length > 0 && insertAt) tx.nodes.insert(cloneDeep(nextRun), { at: insertAt });
474
+ continue;
475
+ }
476
+ if (nextRun.length === 0) {
477
+ for (const [, path] of sourceRun.toReversed()) tx.nodes.remove({ at: path });
478
+ continue;
479
+ }
480
+ if (applyMinimalTextBlockEdits(tx, sourceRun.map(([node]) => node), sourceRun.map(([, path]) => path), nextRun) !== null) continue;
481
+ const first = sourceRun[0];
482
+ const last = sourceRun.at(-1);
483
+ if (!first || !last) continue;
484
+ const anchor = tx.points.start(first[1]);
485
+ const focus = tx.points.end(last[1]);
486
+ if (anchor && focus) tx.slice.replace(ContentSlice.fromJSON({
487
+ content: cloneDeep(nextRun),
488
+ openEnd: 0,
489
+ openStart: 0
490
+ }), { at: {
491
+ anchor,
492
+ focus
493
+ } });
494
+ }
495
+ return changeId;
496
+ });
497
+ if (updateResult.status === "refused") return mapUpdateRefusal(updateResult.refusal);
498
+ if (updateResult.status === "unchanged") {
499
+ baselineLockedSourceRuns = null;
500
+ emit({
501
+ changeId: null,
502
+ draftNodes: EMPTY_DRAFT_NODES,
503
+ status: "idle"
504
+ });
505
+ return Object.freeze({ status: "empty" });
506
+ }
507
+ if (firstProjectedLockedRuns) baselineLockedSourceRuns = cloneDeep(firstProjectedLockedRuns);
508
+ refreshAnchors();
509
+ emit({
510
+ changeId: updateResult.value,
511
+ draftNodes: EMPTY_DRAFT_NODES,
512
+ status: "reviewing"
513
+ });
514
+ return Object.freeze({
515
+ changeId: updateResult.value,
516
+ status: "applied"
517
+ });
518
+ };
519
+ const finalize = () => {
520
+ if (disposed) return Object.freeze({ status: "aborted" });
521
+ const rawDisallowedUrls = findDisallowedRemoteMediaUrlsInMarkdown(rawMarkdown, options.allowRemoteMediaUrl);
522
+ if (mode === "detached") {
523
+ const finalResult = stream ? stream.finish() : null;
524
+ const finalNodes = finalResult ? finalResult.ok ? finalResult.slice.content : [] : snapshot.draftNodes;
525
+ const sanitized = sanitizeDraftOutput(finalNodes);
526
+ const removedUrls = [.../* @__PURE__ */ new Set([...rawDisallowedUrls, ...sanitized.removedUrls])];
527
+ if (sanitized.nodes.length === 0) {
528
+ emit({
529
+ draftNodes: EMPTY_DRAFT_NODES,
530
+ ...finalResult && !finalResult.ok ? { error: finalResult.diagnostics[0].message } : {},
531
+ status: "idle"
532
+ });
533
+ if (removedUrls.length > 0) return Object.freeze({
534
+ refusal: {
535
+ reason: "remote-media-denied",
536
+ urls: removedUrls
537
+ },
538
+ status: "refused"
539
+ });
540
+ return Object.freeze({ status: "empty" });
541
+ }
542
+ emit({
543
+ draftNodes: Object.freeze([...sanitized.nodes]),
544
+ status: "reviewing"
545
+ });
546
+ return Object.freeze({ status: "applied" });
547
+ }
548
+ const proposeView = getProposeView();
549
+ if (!proposeView) return Object.freeze({
550
+ refusal: { reason: "authored-not-installed" },
551
+ status: "refused"
552
+ });
553
+ if (editor.read.view.isReadOnly()) return Object.freeze({
554
+ refusal: { reason: "read-only" },
555
+ status: "refused"
556
+ });
557
+ if (expectedLockedRefs.length > 0) return landLockedSuggestion(proposeView, rawDisallowedUrls);
558
+ if (hasTableCellEdits && rawMarkdown.length === 0 && snapshot.changeId) {
559
+ emit({ status: "reviewing" });
560
+ return Object.freeze({
561
+ changeId: snapshot.changeId,
562
+ status: "applied"
563
+ });
564
+ }
565
+ if (!isRevisionCurrent()) return Object.freeze({ status: "stale" });
566
+ const finalResult = stream ? stream.finish() : null;
567
+ const finalStreamNodes = finalResult ? finalResult.ok ? finalResult.slice.content : [] : snapshot.draftNodes;
568
+ const sanitized = sanitizeDraftOutput(finalStreamNodes);
569
+ const removedUrls = [.../* @__PURE__ */ new Set([...rawDisallowedUrls, ...sanitized.removedUrls])];
570
+ if (sanitized.nodes.length === 0) {
571
+ if (snapshot.changeId) {
572
+ const withdrawn = withdrawOwnedChangeGuarded(proposeView, snapshot.changeId);
573
+ if (withdrawn !== "applied") return Object.freeze({ status: withdrawn });
574
+ }
575
+ emit({
576
+ changeId: null,
577
+ draftNodes: EMPTY_DRAFT_NODES,
578
+ ...finalResult && !finalResult.ok ? { error: finalResult.diagnostics[0].message } : {},
579
+ status: "idle"
580
+ });
581
+ if (removedUrls.length > 0) return Object.freeze({
582
+ refusal: {
583
+ reason: "remote-media-denied",
584
+ urls: removedUrls
585
+ },
586
+ status: "refused"
587
+ });
588
+ return Object.freeze({ status: "empty" });
589
+ }
590
+ const ordered = resolveOrderedTargets(proposeView);
591
+ if (!ordered || ordered.length === 0) return Object.freeze({ status: "stale" });
592
+ if (hasHiddenEditableTarget(ordered)) return Object.freeze({
593
+ refusal: { reason: "hidden-content" },
594
+ status: "refused"
595
+ });
596
+ if (!areAIBlockTargetsContiguous(proposeView, ordered)) return Object.freeze({ status: "stale" });
597
+ for (const [, path] of ordered) if (isAIPathNonWritable(proposeView, path)) return Object.freeze({
598
+ refusal: { reason: "block-locked" },
599
+ status: "refused"
600
+ });
601
+ const currentChangeId = snapshot.changeId;
602
+ const sourceNodes = currentChangeId && baselineSourceNodes ? baselineSourceNodes : projectBlocksForRoot(editor, pinnedRoot, ordered);
603
+ const markdownPlugin = editor.plugin(MarkdownPlugin);
604
+ const serializedSource = markdownPlugin.installed ? markdownPlugin.api.serialize({
605
+ document: { children: sourceNodes },
606
+ lossPolicy: "allow"
607
+ }) : null;
608
+ const reparsed = serializedSource?.ok && markdownPlugin.installed ? markdownPlugin.api.parseSlice(serializedSource.data, { lossPolicy: "allow" }) : void 0;
609
+ const roundTrip = reparsed?.ok && ElementApi.isElementList(reparsed.slice.content) ? reparsed.slice.content : null;
610
+ const fitted = suggestionBlocks(editor, proposeView.read, {
611
+ answer: sanitized.nodes,
612
+ roundTrip,
613
+ source: sourceNodes
614
+ });
615
+ if (isEqual(sourceNodes, fitted)) {
616
+ if (currentChangeId) {
617
+ const withdrawn = withdrawOwnedChangeGuarded(proposeView, currentChangeId);
618
+ if (withdrawn !== "applied") return Object.freeze({ status: withdrawn });
619
+ }
620
+ baselineSourceNodes = null;
621
+ emit({
622
+ changeId: null,
623
+ draftNodes: EMPTY_DRAFT_NODES,
624
+ status: "idle"
625
+ });
626
+ return Object.freeze({ status: "empty" });
627
+ }
628
+ if (!currentChangeId) baselineSourceNodes = cloneDeep(sourceNodes);
629
+ const previousChange = currentChangeId ? editor.plugin(AuthoredPlugin).read.change(currentChangeId) : null;
630
+ if (currentChangeId && !previousChange) return Object.freeze({ status: "stale" });
631
+ const updateResult = proposeView.update.result((tx) => {
632
+ if (previousChange) {
633
+ const withdrawOutcome = tx.plugin(AuthoredPlugin).withdraw([previousChange]);
634
+ if (withdrawOutcome.status !== "applied") throw new EditorRefusalError({ reason: withdrawOutcome.status === "stale" ? AI_INTERNAL_REFUSAL_STALE : AI_INTERNAL_REFUSAL_WITHDRAW }, "AI draft withdraw failed.");
635
+ }
636
+ const targetEntries = resolveOrderedTargetsFromNodes(tx.nodes, proposeView);
637
+ if (!targetEntries || targetEntries.length === 0) throw new EditorRefusalError({ reason: AI_INTERNAL_REFUSAL_STALE }, "AI target blocks missing after withdraw.");
638
+ const first = targetEntries[0];
639
+ const last = targetEntries.at(-1);
640
+ if (!first || !last) throw new EditorRefusalError({ reason: AI_INTERNAL_REFUSAL_STALE }, "AI target range missing after withdraw.");
641
+ const startPoint = tx.points.start(first[1]);
642
+ const endPoint = tx.points.end(last[1]);
643
+ const changeId = tx.plugin(AuthoredPlugin).propose(currentChangeId ? { changeId: currentChangeId } : void 0);
644
+ if (applyMinimalTextBlockEdits(tx, targetEntries.map(([node]) => node), targetEntries.map(([, path]) => path), fitted) !== null) return changeId;
645
+ if (startPoint && endPoint) tx.slice.replace(ContentSlice.fromJSON({
646
+ content: cloneDeep(fitted),
647
+ openEnd: 0,
648
+ openStart: 0
649
+ }), { at: {
650
+ anchor: startPoint,
651
+ focus: endPoint
652
+ } });
653
+ return changeId;
654
+ });
655
+ if (updateResult.status === "refused") return mapUpdateRefusal(updateResult.refusal);
656
+ if (updateResult.status === "unchanged") {
657
+ baselineSourceNodes = null;
658
+ emit({
659
+ changeId: null,
660
+ draftNodes: EMPTY_DRAFT_NODES,
661
+ status: "idle"
662
+ });
663
+ return Object.freeze({ status: "empty" });
664
+ }
665
+ refreshAnchors();
666
+ emit({
667
+ changeId: updateResult.value,
668
+ draftNodes: EMPTY_DRAFT_NODES,
669
+ status: "reviewing"
670
+ });
671
+ return Object.freeze({
672
+ changeId: updateResult.value,
673
+ status: "applied"
674
+ });
675
+ };
676
+ const apply = (applyOptions) => {
677
+ if (disposed) return Object.freeze({ status: "aborted" });
678
+ const rootView = getRootView();
679
+ if (rootView.read.view.isReadOnly()) return Object.freeze({
680
+ refusal: { reason: "read-only" },
681
+ status: "refused"
682
+ });
683
+ const sanitized = sanitizeDraftOutput(snapshot.draftNodes);
684
+ if (sanitized.nodes.length === 0) return Object.freeze({ status: "empty" });
685
+ const applyMode = applyOptions?.mode ?? "insert-below";
686
+ if (applyMode === "replace") {
687
+ if (!isRevisionCurrent()) return Object.freeze({ status: "stale" });
688
+ const replaceTargets = resolveOrderedTargets(rootView);
689
+ if (!replaceTargets || replaceTargets.length === 0) return Object.freeze({ status: "stale" });
690
+ if (hasHiddenEditableTarget(replaceTargets)) return Object.freeze({
691
+ refusal: { reason: "hidden-content" },
692
+ status: "refused"
693
+ });
694
+ if (!areAIBlockTargetsContiguous(rootView, replaceTargets)) return Object.freeze({ status: "stale" });
695
+ if (replaceTargets.some(([, path]) => isAIPathNonWritable(rootView, path))) return Object.freeze({
696
+ refusal: { reason: "block-locked" },
697
+ status: "refused"
698
+ });
699
+ }
700
+ const anchorEntry = anchorKey ? rootView.read.nodes.get(anchorKey, { match: ElementApi.isElement }) : void 0;
701
+ if (anchorKey && !anchorEntry) return Object.freeze({ status: "stale" });
702
+ const paragraphPlugin = editor.plugin(BaseParagraphPlugin);
703
+ const paragraphType = paragraphPlugin.installed ? paragraphPlugin.schema.type : "p";
704
+ const updateResult = rootView.update.result((tx) => {
705
+ const selectEndOfInserted = (firstPath, count) => {
706
+ if (count <= 0) return;
707
+ const lastPath = [...firstPath.slice(0, -1), (firstPath.at(-1) ?? 0) + count - 1];
708
+ const endPoint = tx.points.end(lastPath) ?? tx.points.end(firstPath);
709
+ if (endPoint) tx.selection.set({
710
+ anchor: endPoint,
711
+ focus: endPoint
712
+ });
713
+ };
714
+ tx.history.newBatch();
715
+ if (applyMode === "replace") {
716
+ const targets = resolveOrderedTargets(rootView);
717
+ if (targets && targets.length > 0) {
718
+ const first = targets[0];
719
+ const last = targets.at(-1);
720
+ const anchor = first ? tx.points.start(first[1]) : null;
721
+ const focus = last ? tx.points.end(last[1]) : null;
722
+ if (first && anchor && focus) {
723
+ const landed = cloneDeep(landAIOutput(editor, tx, sanitized.nodes, {
724
+ block: first[0],
725
+ kind: "replaced"
726
+ }));
727
+ tx.slice.replace(ContentSlice.fromJSON({
728
+ content: landed,
729
+ openEnd: 0,
730
+ openStart: 0
731
+ }), { at: {
732
+ anchor,
733
+ focus
734
+ } });
735
+ selectEndOfInserted(first[1], landed.length);
736
+ return true;
737
+ }
738
+ }
739
+ }
740
+ if (anchorEntry) {
741
+ const [node, path] = anchorEntry;
742
+ if (node.type === paragraphType && tx.nodes.isEmpty(node) && !hasNonWritableAt(rootView, path)) {
743
+ const landed = cloneDeep(isListItem(node) ? landAIOutput(editor, tx, fillEmptyListItem(sanitized.nodes, node), {
744
+ block: node,
745
+ kind: "replaced"
746
+ }) : landAIOutput(editor, tx, sanitized.nodes, {
747
+ kind: "line",
748
+ line: anchorEntry
749
+ }));
750
+ tx.nodes.replace(landed, { at: path });
751
+ selectEndOfInserted(path, landed.length);
752
+ return true;
753
+ }
754
+ const landed = cloneDeep(landAIOutput(editor, tx, sanitized.nodes, {
755
+ block: node,
756
+ kind: "kept"
757
+ }));
758
+ const insertAt = PathApi.next(path);
759
+ tx.nodes.insert(landed, { at: insertAt });
760
+ selectEndOfInserted(insertAt, landed.length);
761
+ return true;
762
+ }
763
+ const insertAt = [rootView.read.children().length];
764
+ tx.nodes.insert(cloneDeep(sanitized.nodes), { at: insertAt });
765
+ selectEndOfInserted(insertAt, sanitized.nodes.length);
766
+ return true;
767
+ });
768
+ if (updateResult.status === "refused") return Object.freeze({
769
+ refusal: updateResult.refusal,
770
+ status: "refused"
771
+ });
772
+ if (updateResult.status === "unchanged") return Object.freeze({ status: "empty" });
773
+ stream?.reset();
774
+ rawMarkdown = "";
775
+ emit({
776
+ draftNodes: EMPTY_DRAFT_NODES,
777
+ status: "idle"
778
+ });
779
+ return Object.freeze({ status: "applied" });
780
+ };
781
+ const pushTableCell = (record) => {
782
+ if (disposed) return Object.freeze({ status: "aborted" });
783
+ const cellKey = tableCellAllowlist.get(record.ref);
784
+ if (!cellKey) return Object.freeze({
785
+ refusal: {
786
+ reason: "unknown-table-cell-ref",
787
+ ref: record.ref
788
+ },
789
+ status: "refused"
790
+ });
791
+ const proposeView = getProposeView();
792
+ if (!proposeView) return Object.freeze({
793
+ refusal: { reason: "authored-not-installed" },
794
+ status: "refused"
795
+ });
796
+ if (editor.read.view.isReadOnly()) return Object.freeze({
797
+ refusal: { reason: "read-only" },
798
+ status: "refused"
799
+ });
800
+ if (!isCellAnchorCurrent(cellKey)) return Object.freeze({ status: "stale" });
801
+ const wasTargetAnchorCurrent = isTargetAnchorCurrent();
802
+ const cellEntry = proposeView.read.nodes.get(cellKey, { match: ElementApi.isElement });
803
+ if (!cellEntry || !isPathVisible(proposeView, filter, cellEntry[1], pinnedRoot)) return Object.freeze({ status: "stale" });
804
+ if (hasHiddenDescendant(currentFilter(proposeView), cellEntry[0], cellEntry[1], pinnedRoot, editor.read.value().roots)) return Object.freeze({
805
+ refusal: {
806
+ reason: "hidden-content",
807
+ ref: record.ref
808
+ },
809
+ status: "refused"
810
+ });
811
+ if (isAIPathNonWritable(proposeView, cellEntry[1])) return Object.freeze({
812
+ refusal: {
813
+ reason: "block-locked",
814
+ ref: record.ref
815
+ },
816
+ status: "refused"
817
+ });
818
+ const markdownPlugin = editor.plugin(MarkdownPlugin);
819
+ if (!markdownPlugin.installed) return Object.freeze({
820
+ refusal: { reason: "markdown-not-installed" },
821
+ status: "refused"
822
+ });
823
+ const rawDisallowedUrls = findDisallowedRemoteMediaUrlsInMarkdown(record.markdown, options.allowRemoteMediaUrl);
824
+ const parsed = markdownPlugin.api.parseSlice(record.markdown, { lossPolicy: "allow" });
825
+ if (!parsed.ok) return Object.freeze({
826
+ refusal: { reason: "invalid-markdown" },
827
+ status: "refused"
828
+ });
829
+ const sanitized = sanitizeDraftOutput(parsed.slice.content);
830
+ const removedUrls = [.../* @__PURE__ */ new Set([...rawDisallowedUrls, ...sanitized.removedUrls])];
831
+ if (sanitized.nodes.length === 0) {
832
+ if (removedUrls.length > 0) return Object.freeze({
833
+ refusal: {
834
+ reason: "remote-media-denied",
835
+ urls: removedUrls
836
+ },
837
+ status: "refused"
838
+ });
839
+ return Object.freeze({ status: "empty" });
840
+ }
841
+ const firstExisting = cellEntry[0].children.find((item) => ElementApi.isElement(item));
842
+ const landed = landAIOutput(editor, proposeView.read, sanitized.nodes, {
843
+ block: firstExisting,
844
+ kind: "replaced"
845
+ });
846
+ const currentChangeId = snapshot.changeId;
847
+ const updateResult = proposeView.update.result((tx) => {
848
+ const changeId = tx.plugin(AuthoredPlugin).propose(currentChangeId ? { changeId: currentChangeId } : void 0);
849
+ tx.nodes.replaceChildren(cloneDeep(landed), { at: cellKey });
850
+ return changeId;
851
+ });
852
+ if (updateResult.status === "refused") return mapUpdateRefusal(updateResult.refusal, record.ref);
853
+ if (updateResult.status === "unchanged") return Object.freeze({ status: "empty" });
854
+ hasTableCellEdits = true;
855
+ refreshAnchors({
856
+ onlyCellKey: cellKey,
857
+ refreshTargetAnchor: wasTargetAnchorCurrent
858
+ });
859
+ emit({
860
+ changeId: updateResult.value,
861
+ status: "reviewing"
862
+ });
863
+ return Object.freeze({
864
+ changeId: updateResult.value,
865
+ status: "applied"
866
+ });
867
+ };
868
+ const decideSessionChange = (action) => {
869
+ if (disposed) return Object.freeze({ status: "aborted" });
870
+ const currentChangeId = snapshot.changeId;
871
+ if (!currentChangeId || !editor.plugin(AuthoredPlugin).installed) return Object.freeze({ status: "empty" });
872
+ const authored = editor.plugin(AuthoredPlugin);
873
+ const pending = authored.read.change(currentChangeId);
874
+ if (!pending) {
875
+ emit({
876
+ changeId: null,
877
+ status: "idle"
878
+ });
879
+ return Object.freeze({ status: "stale" });
880
+ }
881
+ const result = authored.update.decide({
882
+ action,
883
+ changes: [pending]
884
+ });
885
+ if (!result || result.status !== "applied") return Object.freeze({
886
+ refusal: result,
887
+ status: result?.status === "stale" ? "stale" : "refused"
888
+ });
889
+ baselineSourceNodes = null;
890
+ baselineLockedSourceRuns = null;
891
+ refreshAnchors();
892
+ emit({
893
+ changeId: null,
894
+ draftNodes: EMPTY_DRAFT_NODES,
895
+ status: "idle"
896
+ });
897
+ return Object.freeze({
898
+ changeId: currentChangeId,
899
+ status: "applied"
900
+ });
901
+ };
902
+ const findCommentRange = (match) => {
903
+ const query = match.content;
904
+ if (!query || query.trim().length === 0) return null;
905
+ const rootView = getRootView();
906
+ const segments = [];
907
+ let flat = "";
908
+ const appendBlockTexts = (node, blockPath, clipStart, clipEnd) => {
909
+ if (!pruneHiddenDescendants(currentFilter(rootView), node, blockPath, pinnedRoot)) return;
910
+ let addedAny = false;
911
+ for (const [textNode, relPath] of NodeApi.texts(node)) {
912
+ const leafPath = [...blockPath, ...relPath];
913
+ if (!isPathVisible(rootView, filter, leafPath, pinnedRoot)) continue;
914
+ if (clipStart && PathApi.compare(leafPath, clipStart.path) < 0) continue;
915
+ if (clipEnd && PathApi.compare(leafPath, clipEnd.path) > 0) continue;
916
+ const startOffset = clipStart && PathApi.equals(leafPath, clipStart.path) ? Math.min(clipStart.offset, textNode.text.length) : 0;
917
+ const endOffset = clipEnd && PathApi.equals(leafPath, clipEnd.path) ? Math.min(clipEnd.offset, textNode.text.length) : textNode.text.length;
918
+ if (endOffset < startOffset) continue;
919
+ const sliceText = textNode.text.slice(startOffset, endOffset);
920
+ if (!addedAny && flat.length > 0) flat += "\n";
921
+ addedAny = true;
922
+ segments.push({
923
+ baseOffset: startOffset,
924
+ path: leafPath,
925
+ startInFlat: flat.length,
926
+ text: sliceText
927
+ });
928
+ flat += sliceText;
929
+ }
930
+ };
931
+ if (match.blockRef) {
932
+ const pinnedKey = lockedBlockKeys.get(match.blockRef) ?? tableCellAllowlist.get(match.blockRef);
933
+ const activeRoot = rootView.read.view.root() ?? "main";
934
+ let entry;
935
+ if (pinnedKey) {
936
+ const byKey = rootView.read.nodes.get(pinnedKey, { match: ElementApi.isElement });
937
+ if (byKey && ElementApi.isElement(byKey[0])) entry = [byKey[0], byKey[1]];
938
+ } else {
939
+ const byId = rootView.read.nodes.byId(match.blockRef);
940
+ if (byId && ElementApi.isElement(byId.node) && (byId.root ?? "main") === activeRoot) entry = [byId.node, byId.path];
941
+ else for (const [node, path] of rootView.read.nodes.entries({
942
+ at: [],
943
+ match: ElementApi.isElement
944
+ })) if (rootView.key(node) === match.blockRef) {
945
+ entry = [node, path];
946
+ break;
947
+ }
948
+ }
949
+ if (entry && isPathVisible(rootView, filter, entry[1], pinnedRoot)) {
950
+ const startPath = entry[1];
951
+ const parentPath = startPath.slice(0, -1);
952
+ const startIndex = startPath.at(-1) ?? 0;
953
+ const parentEntry = parentPath.length === 0 ? null : rootView.read.nodes.get(parentPath, { match: ElementApi.isElement });
954
+ const siblings = parentEntry ? parentEntry[0].children : rootView.read.children();
955
+ for (let index = startIndex; index < siblings.length; index += 1) {
956
+ const sibling = siblings[index];
957
+ if (!ElementApi.isElement(sibling)) continue;
958
+ const siblingPath = [...parentPath, index];
959
+ if (!isPathVisible(rootView, filter, siblingPath, pinnedRoot)) continue;
960
+ appendBlockTexts(sibling, siblingPath);
961
+ }
962
+ }
963
+ } else if (selectionAnchor) {
964
+ const liveRange = selectionAnchor.resolve(rootView);
965
+ if (!liveRange || RangeApi.isCollapsed(liveRange)) return null;
966
+ const [clipStart, clipEnd] = RangeApi.edges(liveRange);
967
+ const blocks = [...rootView.read.nodes.blocks({ at: liveRange })];
968
+ for (const [node, path] of blocks) {
969
+ if (!isPathVisible(rootView, filter, path, pinnedRoot)) continue;
970
+ appendBlockTexts(node, path, clipStart, clipEnd);
971
+ }
972
+ } else {
973
+ const targets = resolveOrderedTargets(rootView) ?? [];
974
+ for (const [node, path] of targets) appendBlockTexts(node, path);
975
+ }
976
+ if (segments.length === 0 || flat.length === 0) return null;
977
+ let matchStart = flat.indexOf(query);
978
+ let matchEnd = matchStart !== -1 ? matchStart + query.length : -1;
979
+ if (matchStart === -1) {
980
+ const strippedQuery = stripMarkdownSyntax(query);
981
+ const normalizedQuery = normalizeWithIndexMap(strippedQuery).normalized;
982
+ if (normalizedQuery.length > 0) {
983
+ const normalizedFlat = normalizeWithIndexMap(flat);
984
+ const normIndex = normalizedFlat.normalized.indexOf(normalizedQuery);
985
+ if (normIndex !== -1) {
986
+ const startOriginal = normalizedFlat.map[normIndex];
987
+ const endOriginal = normalizedFlat.map[normIndex + normalizedQuery.length - 1];
988
+ if (startOriginal !== void 0 && endOriginal !== void 0) {
989
+ matchStart = startOriginal;
990
+ matchEnd = endOriginal + 1;
991
+ }
992
+ }
993
+ }
994
+ }
995
+ if (matchStart === -1 || matchEnd <= matchStart) return null;
996
+ const toPoint = (flatIndex, preferEnd) => {
997
+ for (const segment of segments) {
998
+ const segEnd = segment.startInFlat + segment.text.length;
999
+ if (preferEnd) {
1000
+ if (flatIndex >= segment.startInFlat && flatIndex <= segEnd) return {
1001
+ offset: segment.baseOffset + (flatIndex - segment.startInFlat),
1002
+ path: segment.path
1003
+ };
1004
+ } else if (flatIndex >= segment.startInFlat && flatIndex < segEnd) return {
1005
+ offset: segment.baseOffset + (flatIndex - segment.startInFlat),
1006
+ path: segment.path
1007
+ };
1008
+ }
1009
+ if (preferEnd) for (let index = segments.length - 1; index >= 0; index -= 1) {
1010
+ const segment = segments[index];
1011
+ if (!segment) continue;
1012
+ if (segment.startInFlat <= flatIndex) return {
1013
+ offset: segment.baseOffset + segment.text.length,
1014
+ path: segment.path
1015
+ };
1016
+ }
1017
+ else for (const segment of segments) if (segment.startInFlat >= flatIndex) return {
1018
+ offset: segment.baseOffset,
1019
+ path: segment.path
1020
+ };
1021
+ return null;
1022
+ };
1023
+ const anchor = toPoint(matchStart, false);
1024
+ const focus = toPoint(matchEnd, true);
1025
+ if (!anchor || !focus) return null;
1026
+ const candidateRange = {
1027
+ anchor,
1028
+ focus
1029
+ };
1030
+ if (!isRangeVisible(rootView, filter, candidateRange, pinnedRoot)) return null;
1031
+ return pinnedRoot !== void 0 ? {
1032
+ anchor: {
1033
+ ...anchor,
1034
+ root: pinnedRoot
1035
+ },
1036
+ focus: {
1037
+ ...focus,
1038
+ root: pinnedRoot
1039
+ }
1040
+ } : candidateRange;
1041
+ };
1042
+ const discard = () => {
1043
+ stream?.reset();
1044
+ rawMarkdown = "";
1045
+ emit({
1046
+ draftNodes: EMPTY_DRAFT_NODES,
1047
+ error: null,
1048
+ status: "idle"
1049
+ });
1050
+ };
1051
+ return Object.freeze({
1052
+ accept: () => decideSessionChange("accept"),
1053
+ apply,
1054
+ discard,
1055
+ dispose: () => {
1056
+ disposed = true;
1057
+ selectionAnchor?.release();
1058
+ stream?.reset();
1059
+ stream = null;
1060
+ cachedProposeView = null;
1061
+ cachedRootView = null;
1062
+ listeners.clear();
1063
+ },
1064
+ findCommentRange,
1065
+ finish: finalize,
1066
+ getSnapshot: () => snapshot,
1067
+ push,
1068
+ pushTableCell,
1069
+ reject: () => decideSessionChange("reject"),
1070
+ set,
1071
+ stop: finalize,
1072
+ subscribe: (listener) => {
1073
+ listeners.add(listener);
1074
+ return () => {
1075
+ listeners.delete(listener);
1076
+ };
1077
+ }
1078
+ });
1079
+ };
1080
+ //#endregion
1081
+ export { createAIDraftSession };