platejs 54.0.0-beta.11 → 54.0.0-beta.12

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 (371) hide show
  1. package/dist/{EditorStatic-DHtnTXA7.d.ts → EditorStatic-DLn-Y0NA.d.ts} +27 -6
  2. package/dist/ai/index.d.ts +2 -2
  3. package/dist/ai/index.js +2 -3
  4. package/dist/ai/lib/aiDraftSession.js +227 -132
  5. package/dist/ai/lib/aiPolicy.internal.js +1 -2
  6. package/dist/ai/lib/editorAgent.js +831 -275
  7. package/dist/ai/lib/editorAgentPresence.internal.js +113 -0
  8. package/dist/ai/lib/lockedContext.js +1 -1
  9. package/dist/ai/lib/registerEditorTools.js +59 -4
  10. package/dist/ai/lib/webmcpConfinement.internal.js +8 -0
  11. package/dist/ai/react/AIPlugin.js +2 -2
  12. package/dist/ai/react/CopilotPlugin.js +25 -11
  13. package/dist/ai/react/index.d.ts +170 -809
  14. package/dist/ai/react/index.js +2 -2
  15. package/dist/ai/react/useEditorAgent.js +230 -42
  16. package/dist/authored/AuthoredPlugin.js +2 -2
  17. package/dist/authored/index.d.ts +5 -5
  18. package/dist/authored/suggestionColorOf.js +10 -5
  19. package/dist/{authored-C-fSCvgm-CYzDIRS3.d.ts → authored-D-sIdWDF-BO8GVDW5.d.ts} +51 -13
  20. package/dist/clipboard-format-key-C8pLG2_c-D8fWV8GB.d.ts +1 -0
  21. package/dist/code-block/codemirror/index.d.ts +2 -2
  22. package/dist/{comment-anchor.internal-XxZyEyAa.d.ts → comment-anchor.internal-Qv9thB9E.d.ts} +2 -2
  23. package/dist/compiler/index.d.ts +3 -3
  24. package/dist/{core-Dt0c81fL.d.ts → core-BWS1N1EV.d.ts} +4147 -6642
  25. package/dist/core.js +1 -4
  26. package/dist/diff/index.d.ts +3 -3
  27. package/dist/docs/agents/skills.md +1 -1
  28. package/dist/docs/agents.md +15 -25
  29. package/dist/docs/ai-agents.md +76 -0
  30. package/dist/docs/ai.md +87 -73
  31. package/dist/docs/api/anchor.md +2 -2
  32. package/dist/docs/api/core/plate-components.md +53 -174
  33. package/dist/docs/api/core/plate-controller.md +1 -1
  34. package/dist/docs/api/core/plate-editor.md +34 -131
  35. package/dist/docs/api/core/plate-plugin.md +401 -550
  36. package/dist/docs/api/core/plate-store.md +1 -1
  37. package/dist/docs/api/core.md +167 -335
  38. package/dist/docs/api/dom.md +1 -1
  39. package/dist/docs/api/editor-api.md +2 -2
  40. package/dist/docs/api/editor-transforms.md +2 -2
  41. package/dist/docs/api/element.md +3 -3
  42. package/dist/docs/api/location.md +2 -2
  43. package/dist/docs/api/node.md +6 -7
  44. package/dist/docs/api/path.md +3 -3
  45. package/dist/docs/api/plate.md +6 -6
  46. package/dist/docs/api/point.md +4 -3
  47. package/dist/docs/api/range.md +4 -2
  48. package/dist/docs/api/react-hooks.md +2 -2
  49. package/dist/docs/api/resizable.md +20 -42
  50. package/dist/docs/api/selection.md +2 -2
  51. package/dist/docs/api/text.md +3 -3
  52. package/dist/docs/api/utils.md +1 -2
  53. package/dist/docs/authored-changes.md +5 -3
  54. package/dist/docs/autoformat.md +0 -12
  55. package/dist/docs/basic-blocks.md +6 -24
  56. package/dist/docs/basic-marks.md +11 -47
  57. package/dist/docs/block-menu.md +22 -16
  58. package/dist/docs/block-placeholder.md +3 -13
  59. package/dist/docs/blockquote.md +1 -11
  60. package/dist/docs/board.md +4 -16
  61. package/dist/docs/bold.md +1 -7
  62. package/dist/docs/browser.md +6 -17
  63. package/dist/docs/callout.md +22 -46
  64. package/dist/docs/clear-formatting.md +1 -11
  65. package/dist/docs/clipboard.md +15 -6
  66. package/dist/docs/code-block.md +33 -33
  67. package/dist/docs/code.md +1 -7
  68. package/dist/docs/collaboration.md +122 -0
  69. package/dist/docs/column.md +8 -18
  70. package/dist/docs/combobox.md +45 -72
  71. package/dist/docs/comment.md +52 -28
  72. package/dist/docs/components/toolbar-buttons.md +38 -0
  73. package/dist/docs/controlled.md +11 -15
  74. package/dist/docs/copilot.md +36 -60
  75. package/dist/docs/date.md +3 -13
  76. package/dist/docs/details.md +16 -16
  77. package/dist/docs/diff.md +106 -0
  78. package/dist/docs/discussion.md +8 -4
  79. package/dist/docs/dnd.md +54 -61
  80. package/dist/docs/document-model.md +3 -3
  81. package/dist/docs/docx.md +40 -21
  82. package/dist/docs/dom-coverage.md +1 -1
  83. package/dist/docs/editing-behavior.md +5 -8
  84. package/dist/docs/editor.md +9 -11
  85. package/dist/docs/emoji.md +3 -13
  86. package/dist/docs/equation.md +4 -14
  87. package/dist/docs/examples/collaboration-example.md +5 -3
  88. package/dist/docs/examples/editable-voids.md +2 -0
  89. package/dist/docs/examples/export.md +4 -2
  90. package/dist/docs/examples/huge-document.md +8 -0
  91. package/dist/docs/examples/hundreds-editors.md +2 -0
  92. package/dist/docs/examples/merge.md +46 -0
  93. package/dist/docs/examples/preview-markdown.md +2 -0
  94. package/dist/docs/examples/version-history.md +27 -9
  95. package/dist/docs/exit-break.md +7 -15
  96. package/dist/docs/field.md +8 -12
  97. package/dist/docs/find.md +7 -7
  98. package/dist/docs/font.md +22 -40
  99. package/dist/docs/footnote.md +154 -200
  100. package/dist/docs/form.md +2 -2
  101. package/dist/docs/format-painter.md +1 -11
  102. package/dist/docs/heading.md +1 -3
  103. package/dist/docs/highlight.md +2 -8
  104. package/dist/docs/horizontal-rule.md +3 -13
  105. package/dist/docs/indent.md +26 -77
  106. package/dist/docs/index.md +40 -92
  107. package/dist/docs/ink.md +41 -42
  108. package/dist/docs/installation/manual.md +24 -28
  109. package/dist/docs/installation/next.md +21 -21
  110. package/dist/docs/installation/node.md +6 -10
  111. package/dist/docs/installation/plate-ui.md +9 -25
  112. package/dist/docs/installation/react.md +21 -21
  113. package/dist/docs/installation/rsc.md +7 -13
  114. package/dist/docs/installation.md +6 -32
  115. package/dist/docs/italic.md +1 -7
  116. package/dist/docs/kbd.md +1 -7
  117. package/dist/docs/line-height.md +1 -11
  118. package/dist/docs/link.md +47 -73
  119. package/dist/docs/lint.md +93 -136
  120. package/dist/docs/list.md +0 -8
  121. package/dist/docs/llms.txt +64 -60
  122. package/dist/docs/lock.md +17 -27
  123. package/dist/docs/markdown.md +25 -24
  124. package/dist/docs/media.md +59 -122
  125. package/dist/docs/mention.md +3 -13
  126. package/dist/docs/multi-select.md +20 -32
  127. package/dist/docs/navigation-feedback.md +23 -40
  128. package/dist/docs/pagination.md +2 -0
  129. package/dist/docs/performance.md +8 -14
  130. package/dist/docs/plugin-components.md +22 -22
  131. package/dist/docs/plugin-input-rules.md +16 -26
  132. package/dist/docs/plugin-methods.md +4 -6
  133. package/dist/docs/plugin-rules.md +4 -4
  134. package/dist/docs/plugin-shortcuts.md +5 -5
  135. package/dist/docs/plugin.md +6 -6
  136. package/dist/docs/prompt-editor.md +30 -67
  137. package/dist/docs/releases.md +3 -1
  138. package/dist/docs/rtl.md +2 -0
  139. package/dist/docs/selection.md +2 -0
  140. package/dist/docs/serializing.md +1 -1
  141. package/dist/docs/single-block.md +1 -3
  142. package/dist/docs/slash-command.md +8 -16
  143. package/dist/docs/static.md +70 -31
  144. package/dist/docs/strikethrough.md +1 -7
  145. package/dist/docs/subscript.md +1 -7
  146. package/dist/docs/suggestion.md +14 -12
  147. package/dist/docs/superscript.md +1 -7
  148. package/dist/docs/sync.md +41 -52
  149. package/dist/docs/tabbable.md +34 -54
  150. package/dist/docs/table.md +14 -30
  151. package/dist/docs/text-align.md +1 -11
  152. package/dist/docs/toc.md +33 -67
  153. package/dist/docs/toolbar.md +40 -56
  154. package/dist/docs/trailing-block.md +1 -5
  155. package/dist/docs/transactions.md +2 -2
  156. package/dist/docs/troubleshooting.md +5 -5
  157. package/dist/docs/underline.md +1 -7
  158. package/dist/docs/unit-testing.md +3 -5
  159. package/dist/docs/upload.md +7 -14
  160. package/dist/docx/export/index.d.ts +45 -8
  161. package/dist/docx/export/index.js +2 -1
  162. package/dist/docx/export/lib/compileAst.js +2 -0
  163. package/dist/docx/export/lib/docxComments.js +91 -0
  164. package/dist/docx/export/lib/exportDocx.js +14 -10
  165. package/dist/docx/export/lib/ooxmlBuilder.js +13 -3
  166. package/dist/docx/html/cleanWordHtml.internal.js +4 -4
  167. package/dist/docx/import/index.d.ts +30 -5
  168. package/dist/docx/import/index.js +2 -1
  169. package/dist/docx/import/lib/docxComments.js +130 -0
  170. package/dist/docx/import/lib/importDocx.js +31 -29
  171. package/dist/docx/import/lib/opcRelationships.js +0 -1
  172. package/dist/docx/internal/docxComments.js +34 -0
  173. package/dist/docx/internal/docxPackage.js +7 -17
  174. package/dist/docx/paste/index.d.ts +4 -4
  175. package/dist/dom/index.d.ts +1 -1
  176. package/dist/facade.js +2 -2
  177. package/dist/features/board/index.d.ts +1 -1
  178. package/dist/features/callout/index.d.ts +3 -3
  179. package/dist/features/callout/lib/BaseCalloutPlugin.js +28 -8
  180. package/dist/features/column/index.d.ts +1 -1
  181. package/dist/features/comments/BaseCommentsPlugin.js +912 -597
  182. package/dist/features/comments/comment-active-presentations.internal.js +86 -0
  183. package/dist/features/comments/comment-range-reader.internal.js +12 -0
  184. package/dist/features/comments/comment-thread-index.internal.js +49 -3
  185. package/dist/features/comments/comment-unresolved-index.internal.js +92 -0
  186. package/dist/features/comments/comment-validation.internal.js +129 -0
  187. package/dist/features/comments/index.d.ts +3 -3
  188. package/dist/features/comments/index.js +2 -2
  189. package/dist/features/date/index.d.ts +3 -3
  190. package/dist/features/details/index.d.ts +8 -5
  191. package/dist/features/details/lib/BaseDetailsPlugin.js +359 -151
  192. package/dist/features/field/index.d.ts +1 -1
  193. package/dist/features/find/index.d.ts +3 -3
  194. package/dist/features/footnote/index.d.ts +3 -3
  195. package/dist/features/ink/index.d.ts +2 -2
  196. package/dist/features/ink/index.js +2 -2
  197. package/dist/features/ink/lib/BaseInkPlugin.js +352 -24
  198. package/dist/features/ink/lib/inkPlaces.internal.js +2 -1
  199. package/dist/features/ink/lib/inkSvg.internal.js +419 -0
  200. package/dist/features/lint/index.d.ts +3 -3
  201. package/dist/features/lock/index.d.ts +1 -1
  202. package/dist/features/media/index.d.ts +1 -1
  203. package/dist/features/mention/index.d.ts +1 -1
  204. package/dist/features/table/index.d.ts +2 -2
  205. package/dist/features/table/lib/BaseTablePlugin.js +204 -44
  206. package/dist/features/table/lib/internal/paste.js +65 -3
  207. package/dist/features/table/lib/internal/selection.js +2 -15
  208. package/dist/features/toc/index.d.ts +1 -1
  209. package/dist/features/upload/index.d.ts +1 -1
  210. package/dist/features/upload/lib/BaseUploadPlugin.js +8 -6
  211. package/dist/features/upload/lib/uploadRules.internal.js +1 -1
  212. package/dist/history/index.d.ts +1 -1
  213. package/dist/html/index.d.ts +4 -4
  214. package/dist/html/server/index.d.ts +2 -2
  215. package/dist/{htmlConversion-BjWKSL9U.d.ts → htmlConversion-CSKHZpPj.d.ts} +2 -2
  216. package/dist/{htmlTypes-DhhCZ5de.d.ts → htmlTypes-BWVmZblT.d.ts} +3 -3
  217. package/dist/hyperscript/index.d.ts +1 -1
  218. package/dist/index-B3oYKAuz.d.ts +1 -0
  219. package/dist/{index-Hhh7UWtu.d.ts → index-BC79Ewsl.d.ts} +23 -126
  220. package/dist/index-BTjtVYbH.d.ts +1 -0
  221. package/dist/{index-NQXqGOd_.d.ts → index-BXvEAvgI.d.ts} +3 -5
  222. package/dist/{index-B9MSpRO4.d.ts → index-BYUrsInt.d.ts} +3 -3
  223. package/dist/{index-XBddGrs0.d.ts → index-BcyYN0cZ.d.ts} +61 -30
  224. package/dist/{index-CL1HDdJA.d.ts → index-BnxfTW_D.d.ts} +1 -1
  225. package/dist/{index-DxMNc53b-Bdy03WjR.d.ts → index-BufRKKbx-D3xRkmBz.d.ts} +1 -1
  226. package/dist/{index-DqZkcYSn.d.ts → index-Bwli-ZAF.d.ts} +169 -16
  227. package/dist/index-BwvwktHw-CcWHZqCi.d.ts +254 -0
  228. package/dist/{index-Cdd0v2xd.d.ts → index-C_c8FQDA.d.ts} +36 -18
  229. package/dist/{index-BT95dgbV.d.ts → index-Cnj81Ocd.d.ts} +7 -308
  230. package/dist/{index-xOaKk1Z-.d.ts → index-Cov2Zhgo.d.ts} +3 -3
  231. package/dist/{index-C-n83a4v.d.ts → index-CsmfJqlG.d.ts} +3 -3
  232. package/dist/{index-S9UTBCu_-CGKumalB.d.ts → index-D0hlRs2L-CIw3VG6r.d.ts} +76 -10
  233. package/dist/{index-CVn-5iB8.d.ts → index-DOdoRr4z.d.ts} +203 -2733
  234. package/dist/{index-BvShRH4t.d.ts → index-DgPZlAbx.d.ts} +3 -3
  235. package/dist/{index-CoqXuw4e.d.ts → index-Dsj3VBEr.d.ts} +1 -1
  236. package/dist/{index-CEJVYDwV.d.ts → index-QhGbk8ma.d.ts} +2 -2
  237. package/dist/{index-Bc7mANJA.d.ts → index-SOntT3DN.d.ts} +3 -3
  238. package/dist/{index-SXWqKqcr.d.ts → index-YycKj5Rf.d.ts} +17 -14
  239. package/dist/{index-CNVnEmz_.d.ts → index-hWp8X22M.d.ts} +3 -3
  240. package/dist/{index-Bm17RPgG.d.ts → index-nO2mlsRF.d.ts} +2 -2
  241. package/dist/index-z7QR7V33.d.ts +3 -0
  242. package/dist/index.d.ts +4 -4
  243. package/dist/index.js +1 -4
  244. package/dist/internal/comments/comment-anchor.internal.js +77 -21
  245. package/dist/internal/plugin/OverridePlugin.js +9 -37
  246. package/dist/internal/plugin/conversionLaws.js +45 -0
  247. package/dist/internal/plugin/markdownPreservedProperties.js +25 -0
  248. package/dist/lib/plugins/affinity/AffinityPlugin.js +17 -6
  249. package/dist/lib/plugins/html/HtmlPlugin.js +15 -8
  250. package/dist/lib/plugins/html/htmlAst.js +35 -24
  251. package/dist/lib/plugins/html/htmlConversion.js +16 -8
  252. package/dist/lib/plugins/html/htmlRules.internal.js +5 -9
  253. package/dist/markdown/index.d.ts +2 -2
  254. package/dist/markdown/lib/MarkdownPlugin.js +74 -10
  255. package/dist/markdown/lib/internal/markdownBareLinks.js +9 -4
  256. package/dist/markdown/lib/internal/markdownDiagnostics.js +4 -25
  257. package/dist/markdown/lib/internal/markdownMappings.js +8 -4
  258. package/dist/markdown/lib/internal/markdownParse.js +62 -28
  259. package/dist/markdown/lib/internal/markdownRuntime.js +142 -41
  260. package/dist/markdown/lib/internal/markdownSafety.js +7 -73
  261. package/dist/markdown/lib/internal/markdownSerialize.js +2 -2
  262. package/dist/markdown/lib/internal/markdownStream.js +160 -385
  263. package/dist/markdown/lib/internal/markdownTags.js +127 -6
  264. package/dist/markdown/lib/internal/markdownTailHeal.js +50 -21
  265. package/dist/markdown/lib/serializer/reportOmittedProperties.js +4 -2
  266. package/dist/markdown/lib/utils/remarkPlugins.js +13 -9
  267. package/dist/math/index.d.ts +10 -378
  268. package/dist/math/react/index.d.ts +4 -4
  269. package/dist/migrations/documentMigrationAuthored.internal.js +1 -1
  270. package/dist/migrations/documentMigrations.js +7 -7
  271. package/dist/migrations/index.d.ts +4 -4
  272. package/dist/migrations/migratePlateV54.js +7 -1
  273. package/dist/migrations/migratePlateV54Ast.internal.js +18 -58
  274. package/dist/migrations/migratePlateV54BuiltIns.internal.js +17 -2
  275. package/dist/migrations/migratePlateV54Callout.internal.js +61 -0
  276. package/dist/migrations/migratePlateV54Excalidraw.internal.js +534 -0
  277. package/dist/migrations/migratePlateV54ExcalidrawHelpers.internal.js +82 -0
  278. package/dist/migrations/migratePlateV54Profile.internal.js +3 -2
  279. package/dist/migrations/migratePlateV54Suggestions.internal.js +8 -1
  280. package/dist/pagination/index.d.ts +1 -1
  281. package/dist/pagination/react/index.d.ts +21 -34
  282. package/dist/plain-text.js +2 -1
  283. package/dist/{protocol-pJoaS7Lo-TtlxZ56u.d.ts → protocol-CikFZBQT-CkSt_wOg.d.ts} +18 -3
  284. package/dist/react/authored/index.d.ts +4 -4
  285. package/dist/react/components/EditorContentView.internal.js +2 -3
  286. package/dist/react/components/NodeSelection.js +21 -13
  287. package/dist/react/components/PlateView.js +25 -17
  288. package/dist/react/core.js +1 -4
  289. package/dist/react/features/board/index.d.ts +5 -5
  290. package/dist/react/features/callout/index.d.ts +4 -4
  291. package/dist/react/features/column/index.d.ts +92 -7
  292. package/dist/react/features/combobox/index.d.ts +4 -4
  293. package/dist/react/features/comments/index.d.ts +11 -346
  294. package/dist/react/features/comments/index.js +2 -2
  295. package/dist/react/features/comments/useCommentThreadIndex.js +22 -81
  296. package/dist/react/features/date/index.d.ts +4 -4
  297. package/dist/react/features/details/index.d.ts +123 -9
  298. package/dist/react/features/field/index.d.ts +5 -5
  299. package/dist/react/features/footnote/index.d.ts +48 -656
  300. package/dist/react/features/format-painter/index.d.ts +8 -116
  301. package/dist/react/features/ink/InkContent.js +53 -16
  302. package/dist/react/features/ink/InkPlugin.js +19 -8
  303. package/dist/react/features/ink/index.d.ts +79 -239
  304. package/dist/react/features/ink/inkCapture.internal.js +69 -3
  305. package/dist/react/features/ink/inkImages.internal.js +49 -8
  306. package/dist/react/features/ink/inkInput.internal.js +41 -3
  307. package/dist/react/features/ink/inkPaint.internal.js +26 -7
  308. package/dist/react/features/ink/inkPick.internal.js +108 -38
  309. package/dist/react/features/ink/inkPlacement.internal.js +1 -1
  310. package/dist/react/features/lock/index.d.ts +5 -5
  311. package/dist/react/features/media/index.d.ts +5 -5
  312. package/dist/react/features/mention/index.d.ts +4 -4
  313. package/dist/react/features/table/index.d.ts +868 -2674
  314. package/dist/react/features/toc/index.d.ts +2 -2
  315. package/dist/react/features/upload/index.d.ts +7 -127
  316. package/dist/react/index.d.ts +7 -7
  317. package/dist/react/index.js +1 -4
  318. package/dist/react/plugin/toReactPlugin.js +25 -4
  319. package/dist/react/utils/BlockPlaceholderPlugin.js +6 -4
  320. package/dist/react/utils/dispatchPlateShortcut.internal.js +2 -1
  321. package/dist/react/utils/pipeHandler.internal.js +3 -1
  322. package/dist/react/virtualized.d.ts +3 -3
  323. package/dist/refusal-C6nSOIMX-D8fWV8GB.d.ts +1 -0
  324. package/dist/{registerEditorTools-Bm3Hb9ia.d.ts → registerEditorTools-CyPL0VPh.d.ts} +77 -76
  325. package/dist/root.js +1 -4
  326. package/dist/shared-room-BxXvrWve-D8fWV8GB.d.ts +1 -0
  327. package/dist/skills/plate/SKILL.md +1 -1
  328. package/dist/skills/plate/references/ai-and-agents.md +1 -1
  329. package/dist/skills/plate/references/pricing.md +14 -0
  330. package/dist/{source-DXZpdayy.d.ts → source-pnhMdrj3.d.ts} +3 -3
  331. package/dist/static/components/EditorStatic.js +41 -18
  332. package/dist/static/index.d.ts +11 -7
  333. package/dist/static/internal/staticDocumentView.js +110 -29
  334. package/dist/static/internal/staticPendingMedia.internal.js +30 -3
  335. package/dist/static/internal/staticPresentation.js +9 -3
  336. package/dist/static/renderStaticHtml.js +7 -1
  337. package/dist/{storage-CtuDpaxQ-BUPEA63U.d.ts → storage-Be0SAaPi-CAmIGvmd.d.ts} +2 -2
  338. package/dist/sync/cloudflare/index.d.ts +5 -5
  339. package/dist/sync/index.d.ts +5 -5
  340. package/dist/sync/index.js +2 -2
  341. package/dist/sync/postgres/index.d.ts +1 -1
  342. package/dist/sync/react/hooks.js +9 -2
  343. package/dist/sync/react/index.d.ts +18 -31
  344. package/dist/sync/react/index.js +2 -3
  345. package/dist/sync/server/index.d.ts +6 -5
  346. package/dist/sync/server/index.js +2 -2
  347. package/dist/tabbable/react/index.d.ts +4 -4
  348. package/dist/testing/index.d.ts +17 -8
  349. package/dist/{transport-BW8_dCgM-CF4HYBwr.d.ts → transport-DhoWUkMZ-Dg4M_Ihs.d.ts} +20 -2
  350. package/dist/{tx-only-CJBYIp_b-DMnAZyix.d.ts → tx-only-mEsamESa-Bzy5hDat.d.ts} +36 -17
  351. package/dist/utils/plate-keys.js +1 -1
  352. package/dist/{widths-BjHOVqQM.d.ts → widths-Dlj60VjK.d.ts} +5 -5
  353. package/package.json +3 -21
  354. package/dist/clipboard-format-key-DvfmQCuJ-HYdLkAbO.d.ts +0 -1
  355. package/dist/docs/excalidraw.md +0 -203
  356. package/dist/excalidraw/index.d.ts +0 -60
  357. package/dist/excalidraw/index.js +0 -2
  358. package/dist/excalidraw/lib/BaseExcalidrawPlugin.js +0 -27
  359. package/dist/excalidraw/react/ExcalidrawPlugin.js +0 -6
  360. package/dist/excalidraw/react/index.d.ts +0 -107
  361. package/dist/excalidraw/react/index.js +0 -3
  362. package/dist/excalidraw/react/useExcalidrawSync.js +0 -227
  363. package/dist/index-B49W4Rdt-POMRw5lI.d.ts +0 -118
  364. package/dist/index-B7I8LIvp.d.ts +0 -3
  365. package/dist/index-Bmh2YAsK.d.ts +0 -1
  366. package/dist/index-ivTjNzIe.d.ts +0 -1
  367. package/dist/lib/utils/applyDeepToNodes.js +0 -17
  368. package/dist/lib/utils/defaultsDeepToNodes.js +0 -12
  369. package/dist/lib/utils/mergeDeepToNodes.js +0 -12
  370. package/dist/refusal-BSa4ShXv-HYdLkAbO.d.ts +0 -1
  371. package/dist/skills/plate/references/plus-and-pro.md +0 -12
@@ -1,7 +1,7 @@
1
- import { $a as Plugin, Ga as Path, Hc as StateFieldValueInput, Hl as Value, Jc as Text, Ma as NodeTarget, O as DecorationAttributes, Ol as TransferPlugin, Xi as NamedRootKey, _i as Element$1, _l as TransferCheck, _t as EditorDocumentValue, bl as TransferInput, d as AnyEditor, es as Range, gl as TransferApi, ha as NodeKey, ho as PluginDependencyReferenceFor, ki as HistoryOutcome, ni as EditorUpdatePolicy, po as PluginDependencyContractReference, ps as RootKey, tr as EditorSelectorDependencies, wl as TransferOutcome, xl as TransferIntent } from "./tx-only-CJBYIp_b-DMnAZyix.js";
2
- import "./htmlTypes-DhhCZ5de.js";
3
- import { N as DataTransferDiagnostic, S as DOMEditor, V as ViewportRect, c as DOMApi, d as DOMCoverageCopyPolicy, f as DOMCoverageMaterializeRangeRole, h as DOMCoverageSelectionPolicy, l as DOMClipboardApi, m as DOMCoverageReason, n as DOMPluginTypes, p as DOMCoverageMaterializeReason, r as DropIndicator, t as DOMPlugin, u as DOMCoverageBoundary } from "./index-BvShRH4t.js";
4
- import { s as Editor$2 } from "./core-Dt0c81fL.js";
1
+ import { $o as Range, Hc as StateFieldValueInput, Hl as Value, Jc as Text, O as DecorationAttributes, Oi as HistoryOutcome, Ol as TransferPlugin, Qa as Plugin, Wa as Path, Yi as NamedRootKey, _l as TransferCheck, _t as EditorDocumentValue, bl as TransferInput, d as AnyEditor, fo as PluginDependencyContractReference, fs as RootKey, gi as Element$1, gl as TransferApi, ja as NodeTarget, ma as NodeKey, mo as PluginDependencyReferenceFor, ti as EditorUpdatePolicy, tr as EditorSelectorDependencies, wl as TransferOutcome, xl as TransferIntent } from "./tx-only-mEsamESa-Bzy5hDat.js";
2
+ import "./htmlTypes-BWVmZblT.js";
3
+ import { N as DataTransferDiagnostic, S as DOMEditor, V as ViewportRect, c as DOMApi, d as DOMCoverageCopyPolicy, f as DOMCoverageMaterializeRangeRole, h as DOMCoverageSelectionPolicy, l as DOMClipboardApi, m as DOMCoverageReason, n as DOMPluginTypes, p as DOMCoverageMaterializeReason, r as DropIndicator, t as DOMPlugin, u as DOMCoverageBoundary } from "./index-DgPZlAbx.js";
4
+ import { o as Editor$2, st as BasePluginInput } from "./core-BWS1N1EV.js";
5
5
  import React$1, { CSSProperties, KeyboardEvent as KeyboardEvent$1, MouseEventHandler, ReactNode, Ref, RefObject, TextareaHTMLAttributes } from "react";
6
6
  type DecorationSlice = Readonly<{
7
7
  attributes: DecorationAttributes;
@@ -641,7 +641,7 @@ declare function useEditorRootAreas<TEditor extends AnyEditor = AnyEditor>(edito
641
641
  * Selection match mode for `useElementSelected`:
642
642
  *
643
643
  * - `intersects`: any selection reaches the element.
644
- * - `collapsed`: a collapsed selection reaches the element.
644
+ * - `collapsed`: a collapsed text selection reaches the element; any node selection is false.
645
645
  * - `text`: a text selection reaches the element; any node selection is false.
646
646
  * - `node`: a node selection holds the element.
647
647
  * - `object`: an object node selection holds the element itself.
@@ -759,11 +759,32 @@ type EditorStaticProps<E = Editor$2> = {
759
759
  * preview. The editor supplies the plugins and is not edited. Pass the same
760
760
  * object again to reuse its validated view. Reads, plugin reads and plugin
761
761
  * APIs on the rendered editor see the document; an editor captured when a
762
- * plugin was created still holds its own value.
762
+ * plugin was created still holds its own value. Mutually exclusive with
763
+ * `fragment`.
763
764
  */
764
765
  document?: EditorDocumentValue;
765
766
  /** Editor instance. */
766
767
  editor: E;
768
+ /**
769
+ * Block fragment to render instead of the editor's document (for example a
770
+ * streamed AI draft). Validated against the editor's element, property, and
771
+ * mark schema via `assertFragment` without enforcing root-prefix rules.
772
+ * Mutually exclusive with `document`.
773
+ */
774
+ fragment?: Value;
775
+ /**
776
+ * Marks rendered element attributes with `data-editor-inert-media` so static
777
+ * media renderers keep remote URLs inert during untrusted draft previews.
778
+ */
779
+ inertRemoteMedia?: boolean;
780
+ /**
781
+ * Static plugins that draw the render when `editor` is a live editor, such as
782
+ * the app's static kit. The editor keeps the document, schema, and plugin
783
+ * settings; matched plugin names supply element components, mark components,
784
+ * function wrapper slots, `render.readsDocument`, and static decoration peer
785
+ * filtering. Unmatched editing components render plainly. Pass a stable array.
786
+ */
787
+ presentation?: readonly BasePluginInput[];
767
788
  style?: React$1.CSSProperties;
768
789
  } & React$1.HTMLAttributes<HTMLDivElement>;
769
790
  declare function EditorStatic<E = Editor$2>(props: EditorStaticProps<E>): React$1.JSX.Element;
@@ -1,2 +1,2 @@
1
- import { $ as createSyncServerAgent, A as EditorIdempotencyStore, B as EditorToolDefinition, C as EditorAgentExecuteOptions, D as EditorDebugResult, E as EditorCommentsListResult, F as EditorReadResult, G as EditorWriteReceipt, H as EditorToolErrorResult, I as EditorReadSelection, J as SyncServerAgentHost, K as GetEditorToolsOptions, L as EditorSuggestionsListResult, M as EditorInkPassageImage, N as EditorReadBlock, O as EditorFindResult, P as EditorReadInkResult, Q as createEditorAgent, R as EditorToolAnnotation, S as EditorAgent, T as EditorCommentEntry, U as EditorToolResult, V as EditorToolErrorCode, W as EditorVisibilityFilter, X as SyncServerAgentReceipt, Y as SyncServerAgentOptions, Z as SyncServerAgentRunResult, _ as SerializeAISelectionMarkdownOptions, a as AIDraftCommentMatch, b as serializeAIEditContext, c as AIDraftSessionOptions, d as AIPluginStatus, et as getEditorTools, f as createAIDraftSession, g as SerializeAIEditContextOptions, h as LOCKED_BLOCK_PLACEHOLDER_TAG, i as AIDraftActionResult, j as EditorInkPassage, k as EditorIdempotencyEntry, l as AIDraftSnapshot, m as HasEditableAISelectionRefs, n as WebMCPProducerContext, o as AIDraftMode, p as AILockedBlockRef, q as SyncServerAgentGrant, r as registerEditorTools, s as AIDraftSession, t as RegisterEditorToolsOptions, u as AIDraftTableCellRecord, v as SerializedAIEditContext, w as EditorAgentOptions, x as serializeAISelectionMarkdown, y as hasEditableAISelection, z as EditorToolCall } from "../registerEditorTools-Bm3Hb9ia.js";
2
- export { AIDraftActionResult, AIDraftCommentMatch, AIDraftMode, AIDraftSession, AIDraftSessionOptions, AIDraftSnapshot, AIDraftTableCellRecord, AILockedBlockRef, AIPluginStatus, EditorAgent, EditorAgentExecuteOptions, EditorAgentOptions, EditorCommentEntry, EditorCommentsListResult, EditorDebugResult, EditorFindResult, EditorIdempotencyEntry, EditorIdempotencyStore, EditorInkPassage, EditorInkPassageImage, EditorReadBlock, EditorReadInkResult, EditorReadResult, EditorReadSelection, EditorSuggestionsListResult, EditorToolAnnotation, EditorToolCall, EditorToolDefinition, EditorToolErrorCode, EditorToolErrorResult, EditorToolResult, EditorVisibilityFilter, EditorWriteReceipt, GetEditorToolsOptions, HasEditableAISelectionRefs, LOCKED_BLOCK_PLACEHOLDER_TAG, RegisterEditorToolsOptions, SerializeAIEditContextOptions, SerializeAISelectionMarkdownOptions, SerializedAIEditContext, SyncServerAgentGrant, SyncServerAgentHost, SyncServerAgentOptions, SyncServerAgentReceipt, SyncServerAgentRunResult, WebMCPProducerContext, createAIDraftSession, createEditorAgent, createSyncServerAgent, getEditorTools, hasEditableAISelection, registerEditorTools, serializeAIEditContext, serializeAISelectionMarkdown };
1
+ import { A as EditorReadSelection, B as GetEditorToolsOptions, C as EditorIdempotencyEntry, D as EditorReadBlock, E as EditorInkPassageImage, F as EditorToolErrorCode, G as SyncServerAgentPresenceOptions, H as SyncServerAgentHost, I as EditorToolErrorResult, J as SyncServerAgentReceipt, K as SyncServerAgentPresencePoint, L as EditorToolResult, M as EditorToolAnnotation, N as EditorToolCall, O as EditorReadInkResult, P as EditorToolDefinition, Q as getEditorTools, R as EditorVisibilityFilter, S as EditorFindResult, T as EditorInkPassage, U as SyncServerAgentOptions, V as SyncServerAgentGrant, W as SyncServerAgentPresenceInput, X as createEditorAgent, Y as SyncServerAgentRunResult, Z as createSyncServerAgent, _ as EditorAgentPresence, a as HasEditableAISelectionRefs, b as EditorCommentsListResult, c as SerializeAISelectionMarkdownOptions, d as serializeAIEditContext, f as serializeAISelectionMarkdown, g as EditorAgentOptions, h as EditorAgentExecuteOptions, i as AILockedBlockRef, j as EditorSuggestionsListResult, k as EditorReadResult, l as SerializedAIEditContext, m as EditorAgentAccess, n as WebMCPProducerContext, o as LOCKED_BLOCK_PLACEHOLDER_TAG, p as EditorAgent, q as SyncServerAgentPresenceSelection, r as registerEditorTools, s as SerializeAIEditContextOptions, t as RegisterEditorToolsOptions, u as hasEditableAISelection, v as EditorAgentPresenceState, w as EditorIdempotencyStore, x as EditorDebugResult, y as EditorCommentEntry, z as EditorWriteReceipt } from "../registerEditorTools-CyPL0VPh.js";
2
+ export { AILockedBlockRef, EditorAgent, EditorAgentAccess, EditorAgentExecuteOptions, EditorAgentOptions, EditorAgentPresence, EditorAgentPresenceState, EditorCommentEntry, EditorCommentsListResult, EditorDebugResult, EditorFindResult, EditorIdempotencyEntry, EditorIdempotencyStore, EditorInkPassage, EditorInkPassageImage, EditorReadBlock, EditorReadInkResult, EditorReadResult, EditorReadSelection, EditorSuggestionsListResult, EditorToolAnnotation, EditorToolCall, EditorToolDefinition, EditorToolErrorCode, EditorToolErrorResult, EditorToolResult, EditorVisibilityFilter, EditorWriteReceipt, GetEditorToolsOptions, HasEditableAISelectionRefs, LOCKED_BLOCK_PLACEHOLDER_TAG, RegisterEditorToolsOptions, SerializeAIEditContextOptions, SerializeAISelectionMarkdownOptions, SerializedAIEditContext, SyncServerAgentGrant, SyncServerAgentHost, SyncServerAgentOptions, SyncServerAgentPresenceInput, SyncServerAgentPresenceOptions, SyncServerAgentPresencePoint, SyncServerAgentPresenceSelection, SyncServerAgentReceipt, SyncServerAgentRunResult, WebMCPProducerContext, createEditorAgent, createSyncServerAgent, getEditorTools, hasEditableAISelection, registerEditorTools, serializeAIEditContext, serializeAISelectionMarkdown };
package/dist/ai/index.js CHANGED
@@ -1,5 +1,4 @@
1
- import { LOCKED_BLOCK_PLACEHOLDER_TAG, hasEditableAISelection, serializeAIEditContext, serializeAISelectionMarkdown } from "./lib/lockedContext.js";
2
- import { createAIDraftSession } from "./lib/aiDraftSession.js";
3
1
  import { createEditorAgent, createSyncServerAgent, getEditorTools } from "./lib/editorAgent.js";
2
+ import { LOCKED_BLOCK_PLACEHOLDER_TAG, hasEditableAISelection, serializeAIEditContext, serializeAISelectionMarkdown } from "./lib/lockedContext.js";
4
3
  import { registerEditorTools } from "./lib/registerEditorTools.js";
5
- export { LOCKED_BLOCK_PLACEHOLDER_TAG, createAIDraftSession, createEditorAgent, createSyncServerAgent, getEditorTools, hasEditableAISelection, registerEditorTools, serializeAIEditContext, serializeAISelectionMarkdown };
4
+ export { LOCKED_BLOCK_PLACEHOLDER_TAG, createEditorAgent, createSyncServerAgent, getEditorTools, hasEditableAISelection, registerEditorTools, serializeAIEditContext, serializeAISelectionMarkdown };
@@ -1,4 +1,4 @@
1
- import { createAuthoredEditorView, getCompiledEditorSchema, getEditorAuthoredDocumentCapability, hasNonWritableAt, subscribeEditorRefusals } from "../../facade.js";
1
+ import { EditorRefusalError, createAuthoredEditorView, getCompiledEditorSchema, getEditorAuthoredDocumentCapability, hasNonWritableAt } from "../../facade.js";
2
2
  import { BaseParagraphPlugin } from "../../lib/plugins/paragraph/BaseParagraphPlugin.js";
3
3
  import { ContentSlice, ElementApi, NodeApi, PathApi, RangeApi, createEditorView } from "../../core.js";
4
4
  import { isListItem } from "../../features/list/lib/listIndex.internal.js";
@@ -12,11 +12,40 @@ import isEqual from "lodash/isEqual.js";
12
12
  import cloneDeep from "lodash/cloneDeep.js";
13
13
  //#region src/ai/lib/aiDraftSession.ts
14
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";
15
19
  const isLockRefusalRecord = (record) => {
16
20
  if (!record || typeof record !== "object") return false;
17
21
  const { reason } = record;
18
22
  return reason === "block-locked" || reason === "node-write-veto";
19
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
+ };
20
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");
21
50
  const normalizeWithIndexMap = (text) => {
22
51
  const chars = [];
@@ -110,6 +139,55 @@ const createAIDraftSession = (editor, options) => {
110
139
  let cachedRootView = null;
111
140
  let lastCommittedRevision = null;
112
141
  let baselineSourceNodes = null;
142
+ let baselineLockedSourceRuns = null;
143
+ const readNodeAnchor = (view, key) => {
144
+ const entry = view.read.nodes.get(key, { match: ElementApi.isElement });
145
+ if (!entry) return null;
146
+ const [node, path] = entry;
147
+ const nodeId = typeof node.id === "string" && node.id.length > 0 ? node.id : null;
148
+ const revision = (nodeId !== null ? view.read.nodes.revision(nodeId) : null) ?? JSON.stringify(node);
149
+ const parentEntry = path.length > 1 ? view.read.nodes.get(PathApi.parent(path), { match: ElementApi.isElement }) : void 0;
150
+ return {
151
+ key,
152
+ parentKey: parentEntry ? view.key(parentEntry[0]) ?? null : null,
153
+ revision
154
+ };
155
+ };
156
+ const captureTargetAnchor = (view) => {
157
+ if (targetNodeKeys.length === 0) return null;
158
+ const entries = [];
159
+ for (const key of targetNodeKeys) {
160
+ const entry = view.read.nodes.get(key, { match: ElementApi.isElement });
161
+ if (!entry) return null;
162
+ entries.push([
163
+ entry[0],
164
+ entry[1],
165
+ key
166
+ ]);
167
+ }
168
+ entries.sort(([, left], [, right]) => PathApi.compare(left, right));
169
+ const anchors = [];
170
+ for (const entry of entries) {
171
+ const anchor = readNodeAnchor(view, entry[2]);
172
+ if (!anchor) return null;
173
+ anchors.push(anchor);
174
+ }
175
+ return anchors;
176
+ };
177
+ let targetAnchor = captureTargetAnchor(editor);
178
+ const cellAnchorRevisions = /* @__PURE__ */ new Map();
179
+ for (const key of tableCellAllowlist.values()) cellAnchorRevisions.set(key, readNodeAnchor(editor, key)?.revision ?? null);
180
+ const refreshAnchors = (refreshOptions) => {
181
+ lastCommittedRevision = editor.read.revision();
182
+ if (refreshOptions?.onlyCellKey !== void 0) {
183
+ const { onlyCellKey, refreshTargetAnchor } = refreshOptions;
184
+ cellAnchorRevisions.set(onlyCellKey, readNodeAnchor(getRootView(), onlyCellKey)?.revision ?? null);
185
+ if (refreshTargetAnchor) targetAnchor = captureTargetAnchor(getRootView());
186
+ return;
187
+ }
188
+ targetAnchor = captureTargetAnchor(getRootView());
189
+ for (const key of tableCellAllowlist.values()) cellAnchorRevisions.set(key, readNodeAnchor(getRootView(), key)?.revision ?? null);
190
+ };
113
191
  let snapshot = Object.freeze({
114
192
  anchorKey,
115
193
  changeId: null,
@@ -166,11 +244,11 @@ const createAIDraftSession = (editor, options) => {
166
244
  status: "streaming"
167
245
  });
168
246
  };
169
- const resolveOrderedTargets = (view) => {
247
+ const resolveOrderedTargetsFromNodes = (nodesApi, view) => {
170
248
  if (targetNodeKeys.length === 0) return null;
171
249
  const entries = [];
172
250
  for (const key of targetNodeKeys) {
173
- const entry = view.read.nodes.get(key, { match: ElementApi.isElement });
251
+ const entry = nodesApi.get(key, { match: ElementApi.isElement });
174
252
  if (!entry) return null;
175
253
  if (!isPathVisible(view, filter, entry[1], pinnedRoot)) return null;
176
254
  entries.push([entry[0], entry[1]]);
@@ -178,13 +256,41 @@ const createAIDraftSession = (editor, options) => {
178
256
  entries.sort(([, left], [, right]) => PathApi.compare(left, right));
179
257
  return entries;
180
258
  };
259
+ const resolveOrderedTargets = (view) => resolveOrderedTargetsFromNodes(view.read.nodes, view);
260
+ const isTargetAnchorCurrent = (view = getRootView()) => {
261
+ if (targetAnchor === null) return editor.read.revision() === (lastCommittedRevision ?? baselineRevision);
262
+ const entries = [];
263
+ for (const expected of targetAnchor) {
264
+ const current = readNodeAnchor(view, expected.key);
265
+ if (!current || current.revision !== expected.revision || current.parentKey !== expected.parentKey) return false;
266
+ const entry = view.read.nodes.get(expected.key, { match: ElementApi.isElement });
267
+ if (!entry) return false;
268
+ entries.push([entry[0], entry[1]]);
269
+ }
270
+ if (entries.length > 1 && !selectionContainsHiddenBlocks) {
271
+ for (let i = 1; i < entries.length; i += 1) {
272
+ const prev = entries[i - 1];
273
+ const curr = entries[i];
274
+ if (!prev || !curr) return false;
275
+ if (PathApi.compare(prev[1], curr[1]) >= 0) return false;
276
+ }
277
+ if (!areAIBlockTargetsContiguous(view, entries)) return false;
278
+ }
279
+ return true;
280
+ };
281
+ const isCellAnchorCurrent = (cellKey) => {
282
+ const expected = cellAnchorRevisions.get(cellKey);
283
+ if (expected === void 0 || expected === null) return false;
284
+ const current = readNodeAnchor(getRootView(), cellKey);
285
+ return current !== null && current.revision === expected;
286
+ };
181
287
  const withdrawOwnedChangeGuarded = (proposeView, currentChangeId) => {
182
- if (lastCommittedRevision !== null && editor.read.revision() !== lastCommittedRevision) return "stale";
288
+ if (!isTargetAnchorCurrent(getRootView())) return "stale";
183
289
  const previous = editor.plugin(AuthoredPlugin).read.change(currentChangeId);
184
290
  if (!previous) return "stale";
185
291
  const result = proposeView.update.result((tx) => tx.plugin(AuthoredPlugin).withdraw([previous]));
186
292
  if (result.status !== "committed" || result.value.status !== "applied") return result.status === "committed" && result.value.status === "stale" ? "stale" : "refused";
187
- lastCommittedRevision = editor.read.revision();
293
+ refreshAnchors();
188
294
  return "applied";
189
295
  };
190
296
  const push = (markdownDelta) => {
@@ -200,6 +306,10 @@ const createAIDraftSession = (editor, options) => {
200
306
  }]);
201
307
  }
202
308
  const streamSnapshot = activeStream.append(markdownDelta);
309
+ if (!streamSnapshot.ok) return emit({
310
+ error: streamSnapshot.diagnostics[0].message,
311
+ status: "streaming"
312
+ });
203
313
  return updateStreamPreview(streamSnapshot.nodes);
204
314
  };
205
315
  const set = (accumulatedMarkdown) => {
@@ -215,13 +325,17 @@ const createAIDraftSession = (editor, options) => {
215
325
  }]);
216
326
  }
217
327
  const streamSnapshot = activeStream.set(accumulatedMarkdown);
328
+ if (!streamSnapshot.ok) return emit({
329
+ error: streamSnapshot.diagnostics[0].message,
330
+ status: "streaming"
331
+ });
218
332
  return updateStreamPreview(streamSnapshot.nodes);
219
333
  };
220
334
  const hasHiddenEditableTarget = (entries) => {
221
335
  const { roots } = editor.read.value();
222
336
  return selectionContainsHiddenBlocks || entries.some(([node, path]) => hasHiddenDescendant(filter, node, path, pinnedRoot, roots));
223
337
  };
224
- const isRevisionCurrent = () => editor.read.revision() === (lastCommittedRevision ?? baselineRevision);
338
+ const isRevisionCurrent = () => isTargetAnchorCurrent(getRootView());
225
339
  const landLockedSuggestion = (proposeView, rawDisallowedUrls) => {
226
340
  const markdownPlugin = editor.plugin(MarkdownPlugin);
227
341
  if (!markdownPlugin.installed) return Object.freeze({
@@ -261,8 +375,8 @@ const createAIDraftSession = (editor, options) => {
261
375
  },
262
376
  status: "refused"
263
377
  });
264
- const resolveLockedLayout = () => {
265
- const ordered = resolveOrderedTargets(proposeView);
378
+ const resolveLockedLayout = (nodesApi = proposeView.read.nodes) => {
379
+ const ordered = resolveOrderedTargetsFromNodes(nodesApi, proposeView);
266
380
  if (!ordered) return { kind: "stale" };
267
381
  if (hasHiddenEditableTarget(ordered)) return { kind: "hidden" };
268
382
  if (!areAIBlockTargetsContiguous(proposeView, ordered)) return { kind: "stale" };
@@ -309,25 +423,12 @@ const createAIDraftSession = (editor, options) => {
309
423
  status: "refused"
310
424
  });
311
425
  const currentChangeId = snapshot.changeId;
312
- if (currentChangeId) {
313
- const withdrawn = withdrawOwnedChangeGuarded(proposeView, currentChangeId);
314
- if (withdrawn !== "applied") return Object.freeze({ status: withdrawn });
315
- }
316
- const postLayout = currentChangeId ? resolveLockedLayout() : preLayout;
317
- if (postLayout.kind === "stale") return Object.freeze({ status: "stale" });
318
- if (postLayout.kind === "hidden") return Object.freeze({
319
- refusal: { reason: "hidden-content" },
320
- status: "refused"
321
- });
322
- if (postLayout.kind === "locked") return Object.freeze({
323
- refusal: { reason: "block-locked" },
324
- status: "refused"
325
- });
326
- const { lockedEntries, sourceRuns } = postLayout;
327
- const preparedRuns = sourceRuns.map((sourceRun, index) => {
426
+ const previousChange = currentChangeId ? editor.plugin(AuthoredPlugin).read.change(currentChangeId) : null;
427
+ if (currentChangeId && !previousChange) return Object.freeze({ status: "stale" });
428
+ const prepareLockedRuns = (sourceRuns) => sourceRuns.map((sourceRun, index) => {
328
429
  const answerRun = answerRuns[index] ?? [];
329
430
  if (sourceRun.length === 0 || answerRun.length === 0) return answerRun;
330
- const sourceNodes = projectBlocksForRoot(editor, pinnedRoot, sourceRun);
431
+ const sourceNodes = sourceRun.map(([node]) => node);
331
432
  const serialized = markdownPlugin.api.serialize({
332
433
  document: { children: sourceNodes },
333
434
  lossPolicy: "allow"
@@ -340,53 +441,60 @@ const createAIDraftSession = (editor, options) => {
340
441
  source: sourceNodes
341
442
  }));
342
443
  });
343
- let lockedRefusal = false;
344
- const unsubscribe = subscribeEditorRefusals(proposeView, (record) => {
345
- if (isLockRefusalRecord(record)) lockedRefusal = true;
346
- });
347
- let updateResult;
348
- try {
349
- updateResult = proposeView.update.result((tx) => {
350
- const changeId = tx.plugin(AuthoredPlugin).propose(currentChangeId ? { changeId: currentChangeId } : void 0);
351
- for (let index = sourceRuns.length - 1; index >= 0; index -= 1) {
352
- const sourceRun = sourceRuns[index] ?? [];
353
- const nextRun = preparedRuns[index] ?? [];
354
- const lockedAfter = lockedEntries[index];
355
- const lastLocked = lockedEntries.at(-1);
356
- if (sourceRun.length === 0) {
357
- const insertAt = lockedAfter ? lockedAfter[1] : lastLocked ? PathApi.next(lastLocked[1]) : null;
358
- if (nextRun.length > 0 && insertAt) tx.nodes.insert(cloneDeep(nextRun), { at: insertAt });
359
- continue;
360
- }
361
- if (nextRun.length === 0) {
362
- for (const [, path] of sourceRun.toReversed()) tx.nodes.remove({ at: path });
363
- continue;
364
- }
365
- if (applyMinimalTextBlockEdits(tx, sourceRun.map(([node]) => node), sourceRun.map(([, path]) => path), nextRun) !== null) continue;
366
- const first = sourceRun[0];
367
- const last = sourceRun.at(-1);
368
- if (!first || !last) continue;
369
- const anchor = tx.points.start(first[1]);
370
- const focus = tx.points.end(last[1]);
371
- if (anchor && focus) tx.slice.replace(ContentSlice.fromJSON({
372
- content: cloneDeep(nextRun),
373
- openEnd: 0,
374
- openStart: 0
375
- }), { at: {
376
- anchor,
377
- focus
378
- } });
444
+ const firstProjectedLockedRuns = !currentChangeId ? preLayout.sourceRuns.map((run) => projectBlocksForRoot(editor, pinnedRoot, run)) : null;
445
+ const prePreparedRuns = firstProjectedLockedRuns ? prepareLockedRuns(firstProjectedLockedRuns.map((nodes, runIndex) => {
446
+ const sourceRun = preLayout.sourceRuns[runIndex] ?? [];
447
+ return nodes.map((node, i) => [node, sourceRun[i]?.[1] ?? []]);
448
+ })) : null;
449
+ const updateResult = proposeView.update.result((tx) => {
450
+ if (previousChange) {
451
+ const withdrawOutcome = tx.plugin(AuthoredPlugin).withdraw([previousChange]);
452
+ if (withdrawOutcome.status !== "applied") throw new EditorRefusalError({ reason: withdrawOutcome.status === "stale" ? AI_INTERNAL_REFUSAL_STALE : AI_INTERNAL_REFUSAL_WITHDRAW }, "AI draft withdraw failed.");
453
+ }
454
+ const postLayout = currentChangeId ? resolveLockedLayout(tx.nodes) : preLayout;
455
+ 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.");
456
+ const { lockedEntries, sourceRuns } = postLayout;
457
+ const savedLockedBaseline = baselineLockedSourceRuns;
458
+ const canReuseProjectedBaseline = savedLockedBaseline !== null && savedLockedBaseline.length === sourceRuns.length;
459
+ const preparedRuns = prePreparedRuns ?? prepareLockedRuns(canReuseProjectedBaseline ? savedLockedBaseline.map((nodes, runIndex) => {
460
+ const sourceRun = sourceRuns[runIndex] ?? [];
461
+ return nodes.map((node, i) => [node, sourceRun[i]?.[1] ?? sourceRun.at(-1)?.[1] ?? []]);
462
+ }) : sourceRuns);
463
+ const changeId = tx.plugin(AuthoredPlugin).propose(currentChangeId ? { changeId: currentChangeId } : void 0);
464
+ for (let index = sourceRuns.length - 1; index >= 0; index -= 1) {
465
+ const sourceRun = sourceRuns[index] ?? [];
466
+ const nextRun = preparedRuns[index] ?? [];
467
+ const lockedAfter = lockedEntries[index];
468
+ const lastLocked = lockedEntries.at(-1);
469
+ if (sourceRun.length === 0) {
470
+ const insertAt = lockedAfter ? lockedAfter[1] : lastLocked ? PathApi.next(lastLocked[1]) : null;
471
+ if (nextRun.length > 0 && insertAt) tx.nodes.insert(cloneDeep(nextRun), { at: insertAt });
472
+ continue;
379
473
  }
380
- return changeId;
381
- });
382
- } finally {
383
- unsubscribe();
384
- }
385
- if (lockedRefusal || updateResult.status === "refused") return Object.freeze({
386
- refusal: { reason: "block-locked" },
387
- status: "refused"
474
+ if (nextRun.length === 0) {
475
+ for (const [, path] of sourceRun.toReversed()) tx.nodes.remove({ at: path });
476
+ continue;
477
+ }
478
+ if (applyMinimalTextBlockEdits(tx, sourceRun.map(([node]) => node), sourceRun.map(([, path]) => path), nextRun) !== null) continue;
479
+ const first = sourceRun[0];
480
+ const last = sourceRun.at(-1);
481
+ if (!first || !last) continue;
482
+ const anchor = tx.points.start(first[1]);
483
+ const focus = tx.points.end(last[1]);
484
+ if (anchor && focus) tx.slice.replace(ContentSlice.fromJSON({
485
+ content: cloneDeep(nextRun),
486
+ openEnd: 0,
487
+ openStart: 0
488
+ }), { at: {
489
+ anchor,
490
+ focus
491
+ } });
492
+ }
493
+ return changeId;
388
494
  });
495
+ if (updateResult.status === "refused") return mapUpdateRefusal(updateResult.refusal);
389
496
  if (updateResult.status === "unchanged") {
497
+ baselineLockedSourceRuns = null;
390
498
  emit({
391
499
  changeId: null,
392
500
  draftNodes: EMPTY_DRAFT_NODES,
@@ -394,7 +502,8 @@ const createAIDraftSession = (editor, options) => {
394
502
  });
395
503
  return Object.freeze({ status: "empty" });
396
504
  }
397
- lastCommittedRevision = editor.read.revision();
505
+ if (firstProjectedLockedRuns) baselineLockedSourceRuns = cloneDeep(firstProjectedLockedRuns);
506
+ refreshAnchors();
398
507
  emit({
399
508
  changeId: updateResult.value,
400
509
  draftNodes: EMPTY_DRAFT_NODES,
@@ -409,12 +518,14 @@ const createAIDraftSession = (editor, options) => {
409
518
  if (disposed) return Object.freeze({ status: "aborted" });
410
519
  const rawDisallowedUrls = findDisallowedRemoteMediaUrlsInMarkdown(rawMarkdown, options.allowRemoteMediaUrl);
411
520
  if (mode === "detached") {
412
- const finalNodes = stream ? stream.finish().nodes : snapshot.draftNodes;
521
+ const finalResult = stream ? stream.finish() : null;
522
+ const finalNodes = finalResult ? finalResult.ok ? finalResult.slice.content : [] : snapshot.draftNodes;
413
523
  const sanitized = sanitizeDraftOutput(finalNodes);
414
524
  const removedUrls = [.../* @__PURE__ */ new Set([...rawDisallowedUrls, ...sanitized.removedUrls])];
415
525
  if (sanitized.nodes.length === 0) {
416
526
  emit({
417
527
  draftNodes: EMPTY_DRAFT_NODES,
528
+ ...finalResult && !finalResult.ok ? { error: finalResult.diagnostics[0].message } : {},
418
529
  status: "idle"
419
530
  });
420
531
  if (removedUrls.length > 0) return Object.freeze({
@@ -450,7 +561,8 @@ const createAIDraftSession = (editor, options) => {
450
561
  });
451
562
  }
452
563
  if (!isRevisionCurrent()) return Object.freeze({ status: "stale" });
453
- const finalStreamNodes = stream ? stream.finish().nodes : snapshot.draftNodes;
564
+ const finalResult = stream ? stream.finish() : null;
565
+ const finalStreamNodes = finalResult ? finalResult.ok ? finalResult.slice.content : [] : snapshot.draftNodes;
454
566
  const sanitized = sanitizeDraftOutput(finalStreamNodes);
455
567
  const removedUrls = [.../* @__PURE__ */ new Set([...rawDisallowedUrls, ...sanitized.removedUrls])];
456
568
  if (sanitized.nodes.length === 0) {
@@ -461,6 +573,7 @@ const createAIDraftSession = (editor, options) => {
461
573
  emit({
462
574
  changeId: null,
463
575
  draftNodes: EMPTY_DRAFT_NODES,
576
+ ...finalResult && !finalResult.ok ? { error: finalResult.diagnostics[0].message } : {},
464
577
  status: "idle"
465
578
  });
466
579
  if (removedUrls.length > 0) return Object.freeze({
@@ -511,44 +624,35 @@ const createAIDraftSession = (editor, options) => {
511
624
  return Object.freeze({ status: "empty" });
512
625
  }
513
626
  if (!currentChangeId) baselineSourceNodes = cloneDeep(sourceNodes);
514
- if (currentChangeId) {
515
- const withdrawn = withdrawOwnedChangeGuarded(proposeView, currentChangeId);
516
- if (withdrawn !== "applied") return Object.freeze({ status: withdrawn });
517
- }
518
- const targetEntries = resolveOrderedTargets(proposeView);
519
- if (!targetEntries || targetEntries.length === 0) return Object.freeze({ status: "stale" });
520
- const first = targetEntries[0];
521
- const last = targetEntries.at(-1);
522
- if (!first || !last) return Object.freeze({ status: "stale" });
523
- const startPoint = proposeView.read.points.start(first[1]);
524
- const endPoint = proposeView.read.points.end(last[1]);
525
- let lockedRefusal = false;
526
- const unsubscribe = subscribeEditorRefusals(proposeView, (record) => {
527
- if (isLockRefusalRecord(record)) lockedRefusal = true;
528
- });
529
- let updateResult;
530
- try {
531
- updateResult = proposeView.update.result((tx) => {
532
- const changeId = tx.plugin(AuthoredPlugin).propose(currentChangeId ? { changeId: currentChangeId } : void 0);
533
- if (applyMinimalTextBlockEdits(tx, targetEntries.map(([node]) => node), targetEntries.map(([, path]) => path), fitted) !== null) return changeId;
534
- if (startPoint && endPoint) tx.slice.replace(ContentSlice.fromJSON({
535
- content: cloneDeep(fitted),
536
- openEnd: 0,
537
- openStart: 0
538
- }), { at: {
539
- anchor: startPoint,
540
- focus: endPoint
541
- } });
542
- return changeId;
543
- });
544
- } finally {
545
- unsubscribe();
546
- }
547
- if (lockedRefusal || updateResult.status === "refused") return Object.freeze({
548
- refusal: { reason: "block-locked" },
549
- status: "refused"
627
+ const previousChange = currentChangeId ? editor.plugin(AuthoredPlugin).read.change(currentChangeId) : null;
628
+ if (currentChangeId && !previousChange) return Object.freeze({ status: "stale" });
629
+ const updateResult = proposeView.update.result((tx) => {
630
+ if (previousChange) {
631
+ const withdrawOutcome = tx.plugin(AuthoredPlugin).withdraw([previousChange]);
632
+ if (withdrawOutcome.status !== "applied") throw new EditorRefusalError({ reason: withdrawOutcome.status === "stale" ? AI_INTERNAL_REFUSAL_STALE : AI_INTERNAL_REFUSAL_WITHDRAW }, "AI draft withdraw failed.");
633
+ }
634
+ const targetEntries = resolveOrderedTargetsFromNodes(tx.nodes, proposeView);
635
+ if (!targetEntries || targetEntries.length === 0) throw new EditorRefusalError({ reason: AI_INTERNAL_REFUSAL_STALE }, "AI target blocks missing after withdraw.");
636
+ const first = targetEntries[0];
637
+ const last = targetEntries.at(-1);
638
+ if (!first || !last) throw new EditorRefusalError({ reason: AI_INTERNAL_REFUSAL_STALE }, "AI target range missing after withdraw.");
639
+ const startPoint = tx.points.start(first[1]);
640
+ const endPoint = tx.points.end(last[1]);
641
+ const changeId = tx.plugin(AuthoredPlugin).propose(currentChangeId ? { changeId: currentChangeId } : void 0);
642
+ if (applyMinimalTextBlockEdits(tx, targetEntries.map(([node]) => node), targetEntries.map(([, path]) => path), fitted) !== null) return changeId;
643
+ if (startPoint && endPoint) tx.slice.replace(ContentSlice.fromJSON({
644
+ content: cloneDeep(fitted),
645
+ openEnd: 0,
646
+ openStart: 0
647
+ }), { at: {
648
+ anchor: startPoint,
649
+ focus: endPoint
650
+ } });
651
+ return changeId;
550
652
  });
653
+ if (updateResult.status === "refused") return mapUpdateRefusal(updateResult.refusal);
551
654
  if (updateResult.status === "unchanged") {
655
+ baselineSourceNodes = null;
552
656
  emit({
553
657
  changeId: null,
554
658
  draftNodes: EMPTY_DRAFT_NODES,
@@ -556,7 +660,7 @@ const createAIDraftSession = (editor, options) => {
556
660
  });
557
661
  return Object.freeze({ status: "empty" });
558
662
  }
559
- lastCommittedRevision = editor.read.revision();
663
+ refreshAnchors();
560
664
  emit({
561
665
  changeId: updateResult.value,
562
666
  draftNodes: EMPTY_DRAFT_NODES,
@@ -691,7 +795,8 @@ const createAIDraftSession = (editor, options) => {
691
795
  refusal: { reason: "read-only" },
692
796
  status: "refused"
693
797
  });
694
- if (!isRevisionCurrent()) return Object.freeze({ status: "stale" });
798
+ if (!isCellAnchorCurrent(cellKey)) return Object.freeze({ status: "stale" });
799
+ const wasTargetAnchorCurrent = isTargetAnchorCurrent();
695
800
  const cellEntry = proposeView.read.nodes.get(cellKey, { match: ElementApi.isElement });
696
801
  if (!cellEntry || !isPathVisible(proposeView, filter, cellEntry[1], pinnedRoot)) return Object.freeze({ status: "stale" });
697
802
  if (hasHiddenDescendant(filter, cellEntry[0], cellEntry[1], pinnedRoot, editor.read.value().roots)) return Object.freeze({
@@ -736,31 +841,19 @@ const createAIDraftSession = (editor, options) => {
736
841
  block: firstExisting,
737
842
  kind: "replaced"
738
843
  });
739
- let lockedRefusal = false;
740
- const unsubscribe = subscribeEditorRefusals(proposeView, (refusalRecord) => {
741
- if (isLockRefusalRecord(refusalRecord)) lockedRefusal = true;
742
- });
743
844
  const currentChangeId = snapshot.changeId;
744
- let updateResult;
745
- try {
746
- updateResult = proposeView.update.result((tx) => {
747
- const changeId = tx.plugin(AuthoredPlugin).propose(currentChangeId ? { changeId: currentChangeId } : void 0);
748
- tx.nodes.replaceChildren(cloneDeep(landed), { at: cellKey });
749
- return changeId;
750
- });
751
- } finally {
752
- unsubscribe();
753
- }
754
- if (lockedRefusal || updateResult.status === "refused") return Object.freeze({
755
- refusal: {
756
- reason: "block-locked",
757
- ref: record.ref
758
- },
759
- status: "refused"
845
+ const updateResult = proposeView.update.result((tx) => {
846
+ const changeId = tx.plugin(AuthoredPlugin).propose(currentChangeId ? { changeId: currentChangeId } : void 0);
847
+ tx.nodes.replaceChildren(cloneDeep(landed), { at: cellKey });
848
+ return changeId;
760
849
  });
850
+ if (updateResult.status === "refused") return mapUpdateRefusal(updateResult.refusal, record.ref);
761
851
  if (updateResult.status === "unchanged") return Object.freeze({ status: "empty" });
762
852
  hasTableCellEdits = true;
763
- lastCommittedRevision = editor.read.revision();
853
+ refreshAnchors({
854
+ onlyCellKey: cellKey,
855
+ refreshTargetAnchor: wasTargetAnchorCurrent
856
+ });
764
857
  emit({
765
858
  changeId: updateResult.value,
766
859
  status: "reviewing"
@@ -791,7 +884,9 @@ const createAIDraftSession = (editor, options) => {
791
884
  refusal: result,
792
885
  status: result?.status === "stale" ? "stale" : "refused"
793
886
  });
794
- lastCommittedRevision = editor.read.revision();
887
+ baselineSourceNodes = null;
888
+ baselineLockedSourceRuns = null;
889
+ refreshAnchors();
795
890
  emit({
796
891
  changeId: null,
797
892
  draftNodes: EMPTY_DRAFT_NODES,
@@ -20,12 +20,11 @@ const HTML_MEDIA_TAG_URL_RE = /<(?:audio|embed|iframe|img|source|video)\b[^>]*?\
20
20
  const LINK_ELEMENT_TYPES = /* @__PURE__ */ new Set([PLUGINS.link, "a"]);
21
21
  const MEDIA_ELEMENT_TYPES = /* @__PURE__ */ new Set([
22
22
  PLUGINS.audio,
23
- PLUGINS.excalidraw,
23
+ PLUGINS.board,
24
24
  PLUGINS.file,
25
25
  PLUGINS.image,
26
26
  PLUGINS.mediaEmbed,
27
27
  PLUGINS.video,
28
- "board",
29
28
  "img",
30
29
  "media_embed"
31
30
  ]);