@delali/web-editor 0.0.0-stage → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (477) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +201 -0
  3. package/README.md +167 -2
  4. package/dist/components/editor/chat-comment-effects.d.ts +2 -0
  5. package/dist/components/editor/chat-types.d.ts +20 -0
  6. package/dist/components/editor/collaboration/base-collaboration-plugin.d.ts +14 -0
  7. package/dist/components/editor/collaboration/collaboration-plugin.d.ts +6 -0
  8. package/dist/components/editor/collaboration/collaboration-session.d.ts +30 -0
  9. package/dist/components/editor/collaboration/collaboration-starter.d.ts +9 -0
  10. package/dist/components/editor/collaboration/editor-collaboration.d.ts +16 -0
  11. package/dist/components/editor/collaboration/editor-collaboration.js +293 -0
  12. package/dist/components/editor/collaboration/remote-cursor-overlay.d.ts +1 -0
  13. package/dist/components/editor/collaboration/shared-document.d.ts +18 -0
  14. package/dist/components/editor/create-editor-plugins.d.ts +3 -0
  15. package/dist/components/editor/create-editor-plugins.js +25243 -0
  16. package/dist/components/editor/create-viewer-plugins.d.ts +3 -0
  17. package/dist/components/editor/editor-base-kit.d.ts +329 -0
  18. package/dist/components/editor/editor-base-kit.js +3136 -0
  19. package/dist/components/editor/editor-config.d.ts +14 -0
  20. package/dist/components/editor/editor-config.js +145 -0
  21. package/dist/components/editor/editor-kit.d.ts +3978 -0
  22. package/dist/components/editor/editor-kit.js +18820 -0
  23. package/dist/components/editor/plate-types.d.ts +99 -0
  24. package/dist/components/editor/plugins/accordion-group-base-kit.d.ts +2 -0
  25. package/dist/components/editor/plugins/accordion-group-kit.d.ts +3 -0
  26. package/dist/components/editor/plugins/accordion-types.d.ts +14 -0
  27. package/dist/components/editor/plugins/ai-kit.d.ts +248 -0
  28. package/dist/components/editor/plugins/align-base-kit.d.ts +3 -0
  29. package/dist/components/editor/plugins/api-doc/expandable-base-kit.d.ts +24 -0
  30. package/dist/components/editor/plugins/api-doc/expandable-kit.d.ts +29 -0
  31. package/dist/components/editor/plugins/api-doc/expandable-types.d.ts +7 -0
  32. package/dist/components/editor/plugins/api-doc/panel-base-kit.d.ts +2 -0
  33. package/dist/components/editor/plugins/api-doc/panel-kit.d.ts +3 -0
  34. package/dist/components/editor/plugins/api-doc/panel-types.d.ts +7 -0
  35. package/dist/components/editor/plugins/api-doc/response-field-base-kit.d.ts +3 -0
  36. package/dist/components/editor/plugins/api-doc/response-field-kit.d.ts +4 -0
  37. package/dist/components/editor/plugins/api-doc/response-field-types.d.ts +17 -0
  38. package/dist/components/editor/plugins/autoformat-kit.d.ts +1 -0
  39. package/dist/components/editor/plugins/badge-base-kit.d.ts +2 -0
  40. package/dist/components/editor/plugins/badge-kit.d.ts +3 -0
  41. package/dist/components/editor/plugins/badge-types.d.ts +24 -0
  42. package/dist/components/editor/plugins/banner-base-kit.d.ts +2 -0
  43. package/dist/components/editor/plugins/banner-kit.d.ts +3 -0
  44. package/dist/components/editor/plugins/banner-types.d.ts +15 -0
  45. package/dist/components/editor/plugins/basic-blocks-base-kit.d.ts +5 -0
  46. package/dist/components/editor/plugins/basic-blocks-kit.d.ts +5 -0
  47. package/dist/components/editor/plugins/basic-marks-base-kit.d.ts +19 -0
  48. package/dist/components/editor/plugins/basic-marks-kit.d.ts +35 -0
  49. package/dist/components/editor/plugins/basic-nodes-kit.d.ts +21 -0
  50. package/dist/components/editor/plugins/block-menu-kit.d.ts +165 -0
  51. package/dist/components/editor/plugins/block-placeholder-kit.d.ts +14 -0
  52. package/dist/components/editor/plugins/block-selection-kit.d.ts +137 -0
  53. package/dist/components/editor/plugins/callout-base-kit.d.ts +20 -0
  54. package/dist/components/editor/plugins/callout-kit.d.ts +20 -0
  55. package/dist/components/editor/plugins/callout-types.d.ts +18 -0
  56. package/dist/components/editor/plugins/card-base-kit.d.ts +2 -0
  57. package/dist/components/editor/plugins/card-kit.d.ts +3 -0
  58. package/dist/components/editor/plugins/card-types.d.ts +14 -0
  59. package/dist/components/editor/plugins/caret-placement-kit.d.ts +8 -0
  60. package/dist/components/editor/plugins/code-block-base-kit.d.ts +7 -0
  61. package/dist/components/editor/plugins/code-block-input-rule-gate.d.ts +4 -0
  62. package/dist/components/editor/plugins/code-block-kit.d.ts +7 -0
  63. package/dist/components/editor/plugins/color-base-kit.d.ts +2 -0
  64. package/dist/components/editor/plugins/color-kit.d.ts +3 -0
  65. package/dist/components/editor/plugins/color-types.d.ts +18 -0
  66. package/dist/components/editor/plugins/column-base-kit.d.ts +1 -0
  67. package/dist/components/editor/plugins/column-kit.d.ts +1 -0
  68. package/dist/components/editor/plugins/comment-base-kit.d.ts +47 -0
  69. package/dist/components/editor/plugins/comment-kit.d.ts +71 -0
  70. package/dist/components/editor/plugins/copilot-kit.d.ts +72 -0
  71. package/dist/components/editor/plugins/cursor-overlay-kit.d.ts +11 -0
  72. package/dist/components/editor/plugins/date-base-kit.d.ts +19 -0
  73. package/dist/components/editor/plugins/date-kit.d.ts +19 -0
  74. package/dist/components/editor/plugins/discussion-kit.d.ts +31 -0
  75. package/dist/components/editor/plugins/dnd-kit.d.ts +20 -0
  76. package/dist/components/editor/plugins/docx-kit.d.ts +1 -0
  77. package/dist/components/editor/plugins/emoji-kit.d.ts +9 -0
  78. package/dist/components/editor/plugins/exit-break-kit.d.ts +4 -0
  79. package/dist/components/editor/plugins/floating-toolbar-kit.d.ts +1 -0
  80. package/dist/components/editor/plugins/font-base-kit.d.ts +9 -0
  81. package/dist/components/editor/plugins/font-kit.d.ts +9 -0
  82. package/dist/components/editor/plugins/fraction-input-rule.d.ts +12 -0
  83. package/dist/components/editor/plugins/frame-base-kit.d.ts +2 -0
  84. package/dist/components/editor/plugins/frame-kit.d.ts +3 -0
  85. package/dist/components/editor/plugins/frame-types.d.ts +10 -0
  86. package/dist/components/editor/plugins/icon-base-kit.d.ts +2 -0
  87. package/dist/components/editor/plugins/icon-kit.d.ts +3 -0
  88. package/dist/components/editor/plugins/icon-types.d.ts +15 -0
  89. package/dist/components/editor/plugins/indent-base-kit.d.ts +1 -0
  90. package/dist/components/editor/plugins/indent-kit.d.ts +5 -0
  91. package/dist/components/editor/plugins/input-rule-gate.d.ts +8 -0
  92. package/dist/components/editor/plugins/line-height-base-kit.d.ts +3 -0
  93. package/dist/components/editor/plugins/link-base-kit.d.ts +2 -0
  94. package/dist/components/editor/plugins/link-kit.d.ts +89 -0
  95. package/dist/components/editor/plugins/list-base-kit.d.ts +1 -0
  96. package/dist/components/editor/plugins/list-kit.d.ts +16 -0
  97. package/dist/components/editor/plugins/mark-input-rule-gate.d.ts +2 -0
  98. package/dist/components/editor/plugins/markdown-kit.d.ts +19 -0
  99. package/dist/components/editor/plugins/math-base-kit.d.ts +9 -0
  100. package/dist/components/editor/plugins/math-kit.d.ts +9 -0
  101. package/dist/components/editor/plugins/media-base-kit.d.ts +25 -0
  102. package/dist/components/editor/plugins/media-kit.d.ts +38 -0
  103. package/dist/components/editor/plugins/mention-base-kit.d.ts +11 -0
  104. package/dist/components/editor/plugins/mention-kit.d.ts +11 -0
  105. package/dist/components/editor/plugins/mermaid-base-kit.d.ts +2 -0
  106. package/dist/components/editor/plugins/mermaid-kit.d.ts +3 -0
  107. package/dist/components/editor/plugins/mermaid-types.d.ts +14 -0
  108. package/dist/components/editor/plugins/shared/color-selector.d.ts +9 -0
  109. package/dist/components/editor/plugins/shared/component-popover.d.ts +12 -0
  110. package/dist/components/editor/plugins/slash-kit.d.ts +1 -0
  111. package/dist/components/editor/plugins/steps-base-kit.d.ts +3 -0
  112. package/dist/components/editor/plugins/steps-kit.d.ts +4 -0
  113. package/dist/components/editor/plugins/steps-types.d.ts +18 -0
  114. package/dist/components/editor/plugins/suggestion-base-kit.d.ts +32 -0
  115. package/dist/components/editor/plugins/suggestion-kit.d.ts +53 -0
  116. package/dist/components/editor/plugins/tabbed-code-block-base-kit.d.ts +32 -0
  117. package/dist/components/editor/plugins/tabbed-code-block-kit.d.ts +33 -0
  118. package/dist/components/editor/plugins/tabbed-code-block-types.d.ts +29 -0
  119. package/dist/components/editor/plugins/table-base-kit.d.ts +94 -0
  120. package/dist/components/editor/plugins/table-kit.d.ts +162 -0
  121. package/dist/components/editor/plugins/tabs-base-kit.d.ts +2 -0
  122. package/dist/components/editor/plugins/tabs-kit.d.ts +3 -0
  123. package/dist/components/editor/plugins/tabs-types.d.ts +14 -0
  124. package/dist/components/editor/plugins/text-substitution-input-rule-gate.d.ts +4 -0
  125. package/dist/components/editor/plugins/tiles-base-kit.d.ts +3 -0
  126. package/dist/components/editor/plugins/tiles-kit.d.ts +4 -0
  127. package/dist/components/editor/plugins/tiles-types.d.ts +16 -0
  128. package/dist/components/editor/plugins/toc-base-kit.d.ts +1 -0
  129. package/dist/components/editor/plugins/toc-kit.d.ts +5 -0
  130. package/dist/components/editor/plugins/todo-to-bullet-kit.d.ts +7 -0
  131. package/dist/components/editor/plugins/toggle-base-kit.d.ts +12 -0
  132. package/dist/components/editor/plugins/toggle-kit.d.ts +16 -0
  133. package/dist/components/editor/plugins/tooltip-base-kit.d.ts +2 -0
  134. package/dist/components/editor/plugins/tooltip-html.d.ts +27 -0
  135. package/dist/components/editor/plugins/tooltip-kit.d.ts +3 -0
  136. package/dist/components/editor/plugins/tooltip-types.d.ts +10 -0
  137. package/dist/components/editor/plugins/tree-base-kit.d.ts +2 -0
  138. package/dist/components/editor/plugins/tree-kit.d.ts +3 -0
  139. package/dist/components/editor/plugins/tree-types.d.ts +26 -0
  140. package/dist/components/editor/plugins/typed-conversion-options.d.ts +13 -0
  141. package/dist/components/editor/plugins/update-base-kit.d.ts +1 -0
  142. package/dist/components/editor/plugins/update-kit.d.ts +4 -0
  143. package/dist/components/editor/plugins/update-types.d.ts +19 -0
  144. package/dist/components/editor/plugins/web-address-text.d.ts +1 -0
  145. package/dist/components/editor/transforms.d.ts +8 -0
  146. package/dist/components/editor/use-chat.d.ts +3 -0
  147. package/dist/components/editor/use-chat.js +3315 -0
  148. package/dist/components/editor/use-typed-conversion-options.d.ts +3 -0
  149. package/dist/components/editor/version-history/chunk-node.d.ts +7 -0
  150. package/dist/components/editor/version-history/chunk-plugin.d.ts +6 -0
  151. package/dist/components/editor/version-history/collapse-blocks-without-diff.d.ts +4 -0
  152. package/dist/components/editor/version-history/diff-node.d.ts +9 -0
  153. package/dist/components/editor/version-history/diff-plate.d.ts +7 -0
  154. package/dist/components/editor/version-history/diff-plugin.d.ts +8 -0
  155. package/dist/components/editor/version-history/index.d.ts +9 -0
  156. package/dist/components/editor/version-history/index.js +19218 -0
  157. package/dist/components/editor/version-history/use-object-version.d.ts +1 -0
  158. package/dist/components/editor/version-history/use-reset-editor-on-change.d.ts +7 -0
  159. package/dist/components/editor/version-history/version-plate.d.ts +7 -0
  160. package/dist/components/editor/web-editor.d.ts +6 -0
  161. package/dist/components/editor/web-editor.js +27334 -0
  162. package/dist/context/editor-adapter-context.d.ts +13 -0
  163. package/dist/context/editor-adapter-context.js +124 -0
  164. package/dist/context/editor-adapter.d.ts +262 -0
  165. package/dist/context/editor-toc-context.d.ts +16 -0
  166. package/dist/context/heading-slug-context.d.ts +11 -0
  167. package/dist/context/link-resolution-context.d.ts +24 -0
  168. package/dist/context/link-resolution-store.d.ts +20 -0
  169. package/dist/context/portal-container.d.ts +7 -0
  170. package/dist/hooks/use-copy-to-clipboard.d.ts +10 -0
  171. package/dist/hooks/use-dark-mode.d.ts +1 -0
  172. package/dist/hooks/use-debounce-callback.d.ts +108 -0
  173. package/dist/hooks/use-debounce.d.ts +1 -0
  174. package/dist/hooks/use-is-touch-device.d.ts +1 -0
  175. package/dist/hooks/use-lock-scroll.d.ts +1 -0
  176. package/dist/hooks/use-media-query.d.ts +2 -0
  177. package/dist/hooks/use-mounted.d.ts +6 -0
  178. package/dist/hooks/use-on-click-outside.d.ts +26 -0
  179. package/dist/hooks/use-return-focus-to-editor-on-input-removal.d.ts +3 -0
  180. package/dist/hooks/use-shield-input-selection-from-editor.d.ts +3 -0
  181. package/dist/hooks/use-upload-file.d.ts +25 -0
  182. package/dist/hooks/use-upload-file.js +129 -0
  183. package/dist/lib/accepted-file-types.d.ts +1 -0
  184. package/dist/lib/block-features.d.ts +11 -0
  185. package/dist/lib/comment-mark-strip.d.ts +24 -0
  186. package/dist/lib/comment-mark-strip.js +56 -0
  187. package/dist/lib/download-file.d.ts +1 -0
  188. package/dist/lib/editor-element-path.d.ts +8 -0
  189. package/dist/lib/extract-headings.d.ts +13 -0
  190. package/dist/lib/extract-headings.js +79 -0
  191. package/dist/lib/file-size-limit.d.ts +7 -0
  192. package/dist/lib/html-serialize-hast.d.ts +18 -0
  193. package/dist/lib/html-serialize-rules.d.ts +15 -0
  194. package/dist/lib/html-serialize-utils.d.ts +24 -0
  195. package/dist/lib/html-serialize-utils.js +392 -0
  196. package/dist/lib/line-marking-context.d.ts +13 -0
  197. package/dist/lib/line-marking.d.ts +47 -0
  198. package/dist/lib/list-html.d.ts +30 -0
  199. package/dist/lib/markdown-joiner-transform.d.ts +31 -0
  200. package/dist/lib/markdown-utils.d.ts +4 -0
  201. package/dist/lib/markdown-utils.js +25314 -0
  202. package/dist/lib/mdx/mdx-archetype-rules.d.ts +2 -0
  203. package/dist/lib/mdx/mdx-attribute-codec.d.ts +23 -0
  204. package/dist/lib/mdx/mdx-color-rules.d.ts +2 -0
  205. package/dist/lib/mdx/mdx-component-rules.d.ts +2 -0
  206. package/dist/lib/mdx/mdx-mermaid-rules.d.ts +10 -0
  207. package/dist/lib/mdx/mdx-reference-rules.d.ts +11 -0
  208. package/dist/lib/mdx/mdx-round-trip.d.ts +3 -0
  209. package/dist/lib/mdx/mdx-round-trip.js +1397 -0
  210. package/dist/lib/mdx/mdx-rule-builder.d.ts +45 -0
  211. package/dist/lib/mdx/mdx-server-plugins.d.ts +8 -0
  212. package/dist/lib/mdx/mdx-tabbed-code-rules.d.ts +2 -0
  213. package/dist/lib/mdx/mdx-tabs-rules.d.ts +2 -0
  214. package/dist/lib/mdx/mdx-toggle-rules.d.ts +9 -0
  215. package/dist/lib/mdx/mdx-tree-rules.d.ts +2 -0
  216. package/dist/lib/media-html.d.ts +121 -0
  217. package/dist/lib/paragraph-html.d.ts +26 -0
  218. package/dist/lib/server-plugins.d.ts +199 -0
  219. package/dist/lib/utils.d.ts +3 -0
  220. package/dist/lib/utils.js +25 -0
  221. package/dist/lib/video-embeds.d.ts +9 -0
  222. package/dist/styles.css +6726 -0
  223. package/dist/types/editor.d.ts +161 -0
  224. package/dist/types/editor.js +77 -0
  225. package/dist/ui/accordion-group-node-static.d.ts +11 -0
  226. package/dist/ui/accordion-group-node.d.ts +10 -0
  227. package/dist/ui/ai-chat-editor.d.ts +4 -0
  228. package/dist/ui/ai-menu.d.ts +2 -0
  229. package/dist/ui/ai-node.d.ts +3 -0
  230. package/dist/ui/ai-toolbar-button.d.ts +3 -0
  231. package/dist/ui/alert-dialog.d.ts +20 -0
  232. package/dist/ui/api-doc/expandable-node-static.d.ts +4 -0
  233. package/dist/ui/api-doc/expandable-node.d.ts +3 -0
  234. package/dist/ui/api-doc/expandable-settings.d.ts +17 -0
  235. package/dist/ui/api-doc/panel-node-static.d.ts +3 -0
  236. package/dist/ui/api-doc/panel-node.d.ts +3 -0
  237. package/dist/ui/api-doc/response-field-item-node-static.d.ts +3 -0
  238. package/dist/ui/api-doc/response-field-item-node.d.ts +3 -0
  239. package/dist/ui/api-doc/response-field-node-static.d.ts +9 -0
  240. package/dist/ui/api-doc/response-field-node.d.ts +9 -0
  241. package/dist/ui/avatar.d.ts +16 -0
  242. package/dist/ui/badge-node-static.d.ts +3 -0
  243. package/dist/ui/badge-node.d.ts +3 -0
  244. package/dist/ui/badge-settings-options.d.ts +24 -0
  245. package/dist/ui/badge-settings.d.ts +19 -0
  246. package/dist/ui/badge.d.ts +9 -0
  247. package/dist/ui/banner-node-static.d.ts +4 -0
  248. package/dist/ui/banner-node.d.ts +3 -0
  249. package/dist/ui/block-context-menu.d.ts +8 -0
  250. package/dist/ui/block-discussion.d.ts +3 -0
  251. package/dist/ui/block-draggable.d.ts +2 -0
  252. package/dist/ui/block-list-static.d.ts +2 -0
  253. package/dist/ui/block-list.d.ts +2 -0
  254. package/dist/ui/block-menu.d.ts +167 -0
  255. package/dist/ui/block-selection.d.ts +5 -0
  256. package/dist/ui/block-suggestion.d.ts +17 -0
  257. package/dist/ui/blockquote-node-static.d.ts +2 -0
  258. package/dist/ui/blockquote-node.d.ts +2 -0
  259. package/dist/ui/button.d.ts +81 -0
  260. package/dist/ui/calendar.d.ts +5 -0
  261. package/dist/ui/callout-detail-settings.d.ts +15 -0
  262. package/dist/ui/callout-icon.d.ts +9 -0
  263. package/dist/ui/callout-node-static.d.ts +2 -0
  264. package/dist/ui/callout-node.d.ts +3 -0
  265. package/dist/ui/callout-settings.d.ts +19 -0
  266. package/dist/ui/callout-type-button.d.ts +9 -0
  267. package/dist/ui/caption.d.ts +72 -0
  268. package/dist/ui/card-element-actions.d.ts +7 -0
  269. package/dist/ui/card-icon-settings.d.ts +11 -0
  270. package/dist/ui/card-node-static.d.ts +3 -0
  271. package/dist/ui/card-node.d.ts +3 -0
  272. package/dist/ui/card-settings.d.ts +24 -0
  273. package/dist/ui/card-title-row.d.ts +14 -0
  274. package/dist/ui/checkbox.d.ts +4 -0
  275. package/dist/ui/code-block-line-marking-form.d.ts +9 -0
  276. package/dist/ui/code-block-line-marking-input.d.ts +8 -0
  277. package/dist/ui/code-block-line-marking-popover.d.ts +12 -0
  278. package/dist/ui/code-block-line-marking-state.d.ts +11 -0
  279. package/dist/ui/code-block-node-static.d.ts +10 -0
  280. package/dist/ui/code-block-node.d.ts +5 -0
  281. package/dist/ui/code-line-selection-toolbar.d.ts +10 -0
  282. package/dist/ui/code-line-wrapper.d.ts +22 -0
  283. package/dist/ui/code-node-static.d.ts +2 -0
  284. package/dist/ui/code-node.d.ts +2 -0
  285. package/dist/ui/collapsible.d.ts +6 -0
  286. package/dist/ui/color-copy-icon.d.ts +9 -0
  287. package/dist/ui/color-element-actions.d.ts +7 -0
  288. package/dist/ui/color-item-settings.d.ts +11 -0
  289. package/dist/ui/color-node-static.d.ts +3 -0
  290. package/dist/ui/color-node.d.ts +3 -0
  291. package/dist/ui/color-settings.d.ts +18 -0
  292. package/dist/ui/color-swatch-editable.d.ts +12 -0
  293. package/dist/ui/color-table-row-editable.d.ts +10 -0
  294. package/dist/ui/column-node-static.d.ts +4 -0
  295. package/dist/ui/column-node.d.ts +3 -0
  296. package/dist/ui/command.d.ts +25 -0
  297. package/dist/ui/comment-node-static.d.ts +3 -0
  298. package/dist/ui/comment-node.d.ts +3 -0
  299. package/dist/ui/comment-toolbar-button.d.ts +1 -0
  300. package/dist/ui/comment.d.ts +45 -0
  301. package/dist/ui/cursor-overlay.d.ts +4 -0
  302. package/dist/ui/date-node-static.d.ts +2 -0
  303. package/dist/ui/date-node.d.ts +2 -0
  304. package/dist/ui/dialog.d.ts +90 -0
  305. package/dist/ui/dropdown-menu.d.ts +35 -0
  306. package/dist/ui/editor-inspector-panel.d.ts +6 -0
  307. package/dist/ui/editor-static.d.ts +8 -0
  308. package/dist/ui/editor.d.ts +15 -0
  309. package/dist/ui/emoji-node.d.ts +3 -0
  310. package/dist/ui/emoji-toolbar-button.d.ts +16 -0
  311. package/dist/ui/equation-node-static.d.ts +4 -0
  312. package/dist/ui/equation-node.d.ts +5 -0
  313. package/dist/ui/equation-toolbar-button.d.ts +2 -0
  314. package/dist/ui/floating-discussion.d.ts +8 -0
  315. package/dist/ui/floating-toolbar-buttons.d.ts +1 -0
  316. package/dist/ui/floating-toolbar.d.ts +6 -0
  317. package/dist/ui/font-color-toolbar-button.d.ts +15 -0
  318. package/dist/ui/frame-node-static.d.ts +3 -0
  319. package/dist/ui/frame-node.d.ts +3 -0
  320. package/dist/ui/frame-settings.d.ts +19 -0
  321. package/dist/ui/ghost-text.d.ts +1 -0
  322. package/dist/ui/heading-node-static.d.ts +10 -0
  323. package/dist/ui/heading-node.d.ts +14 -0
  324. package/dist/ui/highlight-node-static.d.ts +2 -0
  325. package/dist/ui/highlight-node.d.ts +2 -0
  326. package/dist/ui/hover-card.d.ts +6 -0
  327. package/dist/ui/hr-node-static.d.ts +2 -0
  328. package/dist/ui/hr-node.d.ts +2 -0
  329. package/dist/ui/icon-node-static.d.ts +3 -0
  330. package/dist/ui/icon-node.d.ts +3 -0
  331. package/dist/ui/icon-picker.d.ts +16 -0
  332. package/dist/ui/icon-settings.d.ts +17 -0
  333. package/dist/ui/inline-combobox.d.ts +38 -0
  334. package/dist/ui/input.d.ts +7 -0
  335. package/dist/ui/kbd-node-static.d.ts +2 -0
  336. package/dist/ui/kbd-node.d.ts +2 -0
  337. package/dist/ui/label.d.ts +8 -0
  338. package/dist/ui/link-node-static.d.ts +11 -0
  339. package/dist/ui/link-node.d.ts +11 -0
  340. package/dist/ui/link-reference.d.ts +39 -0
  341. package/dist/ui/link-reference.js +84 -0
  342. package/dist/ui/link-search-panel.d.ts +5 -0
  343. package/dist/ui/link-toolbar-button.d.ts +3 -0
  344. package/dist/ui/link-toolbar-edit-command.d.ts +7 -0
  345. package/dist/ui/link-toolbar-shared.d.ts +18 -0
  346. package/dist/ui/link-toolbar.d.ts +1 -0
  347. package/dist/ui/mark-toolbar-button.d.ts +6 -0
  348. package/dist/ui/media-align-button.d.ts +5 -0
  349. package/dist/ui/media-audio-node-static.d.ts +3 -0
  350. package/dist/ui/media-audio-node.d.ts +2 -0
  351. package/dist/ui/media-card.d.ts +11 -0
  352. package/dist/ui/media-embed-node-static.d.ts +6 -0
  353. package/dist/ui/media-embed-node.d.ts +2 -0
  354. package/dist/ui/media-file-display.d.ts +11 -0
  355. package/dist/ui/media-file-mode-dropdown.d.ts +10 -0
  356. package/dist/ui/media-file-node-static.d.ts +3 -0
  357. package/dist/ui/media-file-node.d.ts +2 -0
  358. package/dist/ui/media-hint-icon-picker.d.ts +5 -0
  359. package/dist/ui/media-hint-settings.d.ts +2 -0
  360. package/dist/ui/media-image-lightbox.d.ts +17 -0
  361. package/dist/ui/media-image-node-static.d.ts +6 -0
  362. package/dist/ui/media-image-node.d.ts +7 -0
  363. package/dist/ui/media-placeholder-node.d.ts +3 -0
  364. package/dist/ui/media-preview-dialog.d.ts +12 -0
  365. package/dist/ui/media-toolbar.d.ts +3 -0
  366. package/dist/ui/media-upload-toast.d.ts +1 -0
  367. package/dist/ui/media-video-node-static.d.ts +6 -0
  368. package/dist/ui/media-video-node.d.ts +2 -0
  369. package/dist/ui/member-profile-card.d.ts +17 -0
  370. package/dist/ui/mention-document-element.d.ts +5 -0
  371. package/dist/ui/mention-document-hover-card.d.ts +17 -0
  372. package/dist/ui/mention-document-link.d.ts +13 -0
  373. package/dist/ui/mention-element.d.ts +5 -0
  374. package/dist/ui/mention-input-element.d.ts +2 -0
  375. package/dist/ui/mention-node-static.d.ts +7 -0
  376. package/dist/ui/mention-page-combobox-group.d.ts +8 -0
  377. package/dist/ui/mention-people-combobox-group.d.ts +8 -0
  378. package/dist/ui/menu.d.ts +103 -0
  379. package/dist/ui/mermaid-node-static.d.ts +4 -0
  380. package/dist/ui/mermaid-node.d.ts +3 -0
  381. package/dist/ui/more-toolbar-button.d.ts +3 -0
  382. package/dist/ui/paragraph-node-static.d.ts +2 -0
  383. package/dist/ui/paragraph-node.d.ts +2 -0
  384. package/dist/ui/popover.d.ts +11 -0
  385. package/dist/ui/progress.d.ts +3 -0
  386. package/dist/ui/resize-handle.d.ts +15 -0
  387. package/dist/ui/select.d.ts +13 -0
  388. package/dist/ui/separator.d.ts +8 -0
  389. package/dist/ui/slash-node.d.ts +20 -0
  390. package/dist/ui/smart-link-clipboard.d.ts +1 -0
  391. package/dist/ui/smart-link-copy-button.d.ts +6 -0
  392. package/dist/ui/smart-link-mode-dropdown.d.ts +9 -0
  393. package/dist/ui/smart-link-toolbar.d.ts +17 -0
  394. package/dist/ui/smart-link-view.d.ts +23 -0
  395. package/dist/ui/smart-link.d.ts +43 -0
  396. package/dist/ui/spinner.d.ts +7 -0
  397. package/dist/ui/step-node-static.d.ts +3 -0
  398. package/dist/ui/step-node.d.ts +3 -0
  399. package/dist/ui/step-settings.d.ts +19 -0
  400. package/dist/ui/steps-node-static.d.ts +10 -0
  401. package/dist/ui/steps-node.d.ts +10 -0
  402. package/dist/ui/suggestion-node-static.d.ts +3 -0
  403. package/dist/ui/suggestion-node.d.ts +6 -0
  404. package/dist/ui/suggestion-toolbar-button.d.ts +1 -0
  405. package/dist/ui/switch.d.ts +4 -0
  406. package/dist/ui/tabbed-code-block-actions.d.ts +24 -0
  407. package/dist/ui/tabbed-code-block-header.d.ts +23 -0
  408. package/dist/ui/tabbed-code-block-language-selector.d.ts +7 -0
  409. package/dist/ui/tabbed-code-block-languages.d.ts +6 -0
  410. package/dist/ui/tabbed-code-block-node-static.d.ts +4 -0
  411. package/dist/ui/tabbed-code-block-node.d.ts +4 -0
  412. package/dist/ui/tabbed-code-block-settings.d.ts +18 -0
  413. package/dist/ui/tabbed-code-block-sync.d.ts +10 -0
  414. package/dist/ui/tabbed-code-block-tab-dropdown.d.ts +10 -0
  415. package/dist/ui/tabbed-code-block-tab-strip.d.ts +27 -0
  416. package/dist/ui/tabbed-code-block-tab-trigger.d.ts +14 -0
  417. package/dist/ui/tabbed-code-block-utils.d.ts +9 -0
  418. package/dist/ui/table-icons.d.ts +7 -0
  419. package/dist/ui/table-node-static.d.ts +9 -0
  420. package/dist/ui/table-node.d.ts +9 -0
  421. package/dist/ui/tabs-node-static.d.ts +4 -0
  422. package/dist/ui/tabs-node.d.ts +3 -0
  423. package/dist/ui/tabs.d.ts +10 -0
  424. package/dist/ui/textarea.d.ts +10 -0
  425. package/dist/ui/tile-node-static.d.ts +3 -0
  426. package/dist/ui/tile-node.d.ts +3 -0
  427. package/dist/ui/tile-settings.d.ts +18 -0
  428. package/dist/ui/tiles-node-static.d.ts +3 -0
  429. package/dist/ui/tiles-node.d.ts +3 -0
  430. package/dist/ui/toc-node-static.d.ts +2 -0
  431. package/dist/ui/toc-node.d.ts +2 -0
  432. package/dist/ui/toc-sidebar.d.ts +6 -0
  433. package/dist/ui/toc-state-sync.d.ts +5 -0
  434. package/dist/ui/toggle-node-static.d.ts +3 -0
  435. package/dist/ui/toggle-node-views.d.ts +35 -0
  436. package/dist/ui/toggle-node.d.ts +3 -0
  437. package/dist/ui/toggle-settings.d.ts +23 -0
  438. package/dist/ui/toggle.d.ts +8 -0
  439. package/dist/ui/toolbar.d.ts +37 -0
  440. package/dist/ui/tooltip-node-static.d.ts +3 -0
  441. package/dist/ui/tooltip-node.d.ts +3 -0
  442. package/dist/ui/tooltip-preview-content.d.ts +6 -0
  443. package/dist/ui/tooltip-settings.d.ts +21 -0
  444. package/dist/ui/tooltip-toolbar-button.d.ts +3 -0
  445. package/dist/ui/tooltip.d.ts +19 -0
  446. package/dist/ui/tree-context-value.d.ts +22 -0
  447. package/dist/ui/tree-context.d.ts +32 -0
  448. package/dist/ui/tree-file-node-static.d.ts +8 -0
  449. package/dist/ui/tree-file-node.d.ts +11 -0
  450. package/dist/ui/tree-folder-node-static.d.ts +9 -0
  451. package/dist/ui/tree-folder-node.d.ts +12 -0
  452. package/dist/ui/tree-item-utils.d.ts +11 -0
  453. package/dist/ui/tree-items-list.d.ts +11 -0
  454. package/dist/ui/tree-node-events.d.ts +19 -0
  455. package/dist/ui/tree-node-state.d.ts +14 -0
  456. package/dist/ui/tree-node-static.d.ts +12 -0
  457. package/dist/ui/tree-node.d.ts +5 -0
  458. package/dist/ui/tree-root-actions.d.ts +11 -0
  459. package/dist/ui/tree-settings.d.ts +18 -0
  460. package/dist/ui/turn-into-toolbar-button.d.ts +129 -0
  461. package/dist/ui/update-display-tags.d.ts +5 -0
  462. package/dist/ui/update-node-static.d.ts +2 -0
  463. package/dist/ui/update-node.d.ts +3 -0
  464. package/dist/ui/update-rss-settings.d.ts +9 -0
  465. package/dist/ui/update-settings.d.ts +21 -0
  466. package/dist/ui/update-tags-settings.d.ts +8 -0
  467. package/dist/ui/updates-node-static.d.ts +2 -0
  468. package/dist/ui/updates-node.d.ts +2 -0
  469. package/dist/ui/use-member-profile.d.ts +22 -0
  470. package/dist/ui/use-placeholder-max-file-size.d.ts +3 -0
  471. package/dist/vendor/slate-yjs-core.d.ts +1 -0
  472. package/dist/vendor/slate-yjs-core.js +2 -0
  473. package/dist/vendor/y-protocols-awareness.d.ts +1 -0
  474. package/dist/vendor/y-protocols-awareness.js +2 -0
  475. package/dist/vendor/yjs.d.ts +1 -0
  476. package/dist/vendor/yjs.js +2 -0
  477. package/package.json +255 -4
@@ -0,0 +1,3315 @@
1
+ "use client";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
+ var __objRest = (source, exclude) => {
23
+ var target = {};
24
+ for (var prop in source)
25
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
26
+ target[prop] = source[prop];
27
+ if (source != null && __getOwnPropSymbols)
28
+ for (var prop of __getOwnPropSymbols(source)) {
29
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
30
+ target[prop] = source[prop];
31
+ }
32
+ return target;
33
+ };
34
+
35
+ // src/components/editor/use-chat.ts
36
+ import { useChat as useBaseChat } from "@ai-sdk/react";
37
+ import { AIChatPlugin } from "@platejs/ai/react";
38
+ import { DefaultChatTransport } from "ai";
39
+ import { useEditorRef as useEditorRef6 } from "platejs/react";
40
+ import { useEffect as useEffect8, useMemo as useMemo3 } from "react";
41
+
42
+ // src/context/editor-adapter-context.tsx
43
+ import { createContext, useContext } from "react";
44
+ import { jsx } from "react/jsx-runtime";
45
+ var EMPTY_ARRAY = [];
46
+ var NullEditorAdapter = {
47
+ identity: { id: "anonymous", name: "Guest" },
48
+ permissions: {
49
+ canMention: false,
50
+ canLinkPage: false,
51
+ canUseAI: false,
52
+ canMutate: false
53
+ },
54
+ mentions: {
55
+ searchMembers: async () => EMPTY_ARRAY
56
+ },
57
+ pageLinks: {
58
+ searchPages: async () => EMPTY_ARRAY,
59
+ resolvePage: async () => null
60
+ },
61
+ ai: null,
62
+ upload: null,
63
+ collab: null,
64
+ comments: null,
65
+ inspector: null
66
+ };
67
+ var EditorAdapterContext = createContext(NullEditorAdapter);
68
+ var useEditorAdapter = () => useContext(EditorAdapterContext);
69
+
70
+ // src/components/editor/chat-comment-effects.ts
71
+ import { aiCommentToRange, findTextRangeInBlock } from "@platejs/ai/react";
72
+ import { getCommentKey as getCommentKey2 } from "@platejs/comment";
73
+ import { NodeApi as NodeApi3, nanoid as nanoid2, TextApi as TextApi4 } from "platejs";
74
+ import { useEditorRef as useEditorRef5 } from "platejs/react";
75
+ import { useEffect as useEffect7, useRef as useRef5 } from "react";
76
+
77
+ // src/components/editor/plugins/discussion-kit.tsx
78
+ import { createPlatePlugin } from "platejs/react";
79
+
80
+ // src/ui/block-discussion.tsx
81
+ import { getDraftCommentKey as getDraftCommentKey4 } from "@platejs/comment";
82
+ import { CommentPlugin as CommentPlugin2 } from "@platejs/comment/react";
83
+ import { getTransientSuggestionKey as getTransientSuggestionKey2 } from "@platejs/suggestion";
84
+ import { SuggestionPlugin as SuggestionPlugin2 } from "@platejs/suggestion/react";
85
+ import { MessageSquareTextIcon, MessagesSquareIcon, PencilLineIcon as PencilLineIcon2 } from "lucide-react";
86
+ import {
87
+ PathApi as PathApi3,
88
+ TextApi as TextApi3
89
+ } from "platejs";
90
+ import { useEditorPlugin as useEditorPlugin6, useEditorRef as useEditorRef4, usePluginOption as usePluginOption6 } from "platejs/react";
91
+ import React6, { useEffect as useEffect6 } from "react";
92
+
93
+ // src/components/editor/plugins/comment-kit.tsx
94
+ import { BaseCommentPlugin, getDraftCommentKey as getDraftCommentKey3 } from "@platejs/comment";
95
+ import { isSlateElement, isSlateString as isSlateString2 } from "platejs";
96
+ import { toTPlatePlugin as toTPlatePlugin2, useEditorContainerRef as useEditorContainerRef2 } from "platejs/react";
97
+ import { useEffect as useEffect5 } from "react";
98
+
99
+ // src/ui/comment-node.tsx
100
+ import { getCommentCount } from "@platejs/comment";
101
+ import { PlateLeaf, useEditorPlugin, usePluginOption } from "platejs/react";
102
+
103
+ // src/lib/utils.ts
104
+ import { clsx } from "clsx";
105
+ import { twMerge } from "tailwind-merge";
106
+ var cn = (...inputs) => {
107
+ return twMerge(clsx(inputs));
108
+ };
109
+
110
+ // src/ui/comment-node.tsx
111
+ import { jsx as jsx2 } from "react/jsx-runtime";
112
+ function CommentLeaf(props) {
113
+ const { api, setOption } = useEditorPlugin(commentPlugin);
114
+ const hoverId = usePluginOption(commentPlugin, "hoverId");
115
+ const activeId = usePluginOption(commentPlugin, "activeId");
116
+ const isOverlapping = getCommentCount(props.leaf) > 1;
117
+ const currentId = api.comment.nodeId(props.leaf);
118
+ const isActive = activeId === currentId;
119
+ const isHover = hoverId === currentId;
120
+ return /* @__PURE__ */ jsx2(
121
+ PlateLeaf,
122
+ __spreadProps(__spreadValues({}, props), {
123
+ attributes: __spreadProps(__spreadValues({}, props.attributes), {
124
+ onClick: () => setOption("activeId", currentId != null ? currentId : null),
125
+ onMouseEnter: () => setOption("hoverId", currentId != null ? currentId : null),
126
+ onMouseLeave: () => setOption("hoverId", null)
127
+ }),
128
+ className: cn(
129
+ "border-b-2 border-b-highlight/[.36] bg-highlight/[.13] transition-colors duration-200",
130
+ (isHover || isActive) && "border-b-highlight bg-highlight/25",
131
+ isOverlapping && "border-b-2 border-b-highlight/[.7] bg-highlight/25",
132
+ (isHover || isActive) && isOverlapping && "border-b-highlight bg-highlight/45"
133
+ )
134
+ })
135
+ );
136
+ }
137
+
138
+ // src/ui/floating-discussion.tsx
139
+ import { getDraftCommentKey as getDraftCommentKey2 } from "@platejs/comment";
140
+ import { BlockSelectionPlugin } from "@platejs/selection/react";
141
+ import {
142
+ acceptSuggestion as acceptSuggestion2,
143
+ getSuggestionKey as getSuggestionKey2,
144
+ getTransientSuggestionKey,
145
+ keyId2SuggestionId as keyId2SuggestionId2,
146
+ rejectSuggestion as rejectSuggestion2
147
+ } from "@platejs/suggestion";
148
+ import { CheckIcon as CheckIcon4, PencilLineIcon, XIcon as XIcon3 } from "lucide-react";
149
+ import {
150
+ ElementApi as ElementApi2,
151
+ KEYS as KEYS4,
152
+ NodeApi as NodeApi2,
153
+ PathApi as PathApi2,
154
+ TextApi as TextApi2
155
+ } from "platejs";
156
+ import {
157
+ useEditorContainerRef,
158
+ useEditorMounted,
159
+ useEditorPlugin as useEditorPlugin5,
160
+ useEditorRef as useEditorRef3,
161
+ useEditorSelector,
162
+ useEditorVersion,
163
+ usePluginOption as usePluginOption5,
164
+ usePluginOptions
165
+ } from "platejs/react";
166
+ import React5, { useEffect as useEffect4, useReducer, useRef as useRef4, useState as useState3 } from "react";
167
+
168
+ // src/components/editor/plugins/suggestion-kit.tsx
169
+ import { BaseSuggestionPlugin } from "@platejs/suggestion";
170
+ import { isSlateEditor, isSlateString } from "platejs";
171
+ import { toTPlatePlugin } from "platejs/react";
172
+
173
+ // src/ui/suggestion-node.tsx
174
+ import { cva } from "class-variance-authority";
175
+ import { CornerDownLeftIcon } from "lucide-react";
176
+ import { PlateLeaf as PlateLeaf2, useEditorPlugin as useEditorPlugin2, usePluginOption as usePluginOption2 } from "platejs/react";
177
+ import * as React from "react";
178
+ import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
179
+ var suggestionVariants = cva(
180
+ cn("border-b-2 border-b-brand/[.24] bg-brand/8 text-brand/80 no-underline transition-colors duration-200"),
181
+ {
182
+ defaultVariants: {
183
+ insertActive: false,
184
+ remove: false,
185
+ removeActive: false
186
+ },
187
+ variants: {
188
+ insertActive: {
189
+ false: "",
190
+ true: "border-b-brand/[.60] bg-brand/[.13]"
191
+ },
192
+ remove: {
193
+ false: "",
194
+ true: "border-b-gray-300 bg-gray-300/25 text-gray-400 line-through"
195
+ },
196
+ removeActive: {
197
+ false: "",
198
+ true: "border-b-gray-500 bg-gray-400/25 text-gray-500 no-underline"
199
+ }
200
+ }
201
+ }
202
+ );
203
+ function SuggestionLeaf(props) {
204
+ var _a;
205
+ const { api, setOption } = useEditorPlugin2(suggestionPlugin);
206
+ const leafId = (_a = api.suggestion.nodeId(props.leaf)) != null ? _a : "";
207
+ const activeSuggestionId = usePluginOption2(suggestionPlugin, "activeId");
208
+ const hoverSuggestionId = usePluginOption2(suggestionPlugin, "hoverId");
209
+ const dataList = api.suggestion.dataList(props.leaf);
210
+ const hasRemove = dataList.some((data) => data.type === "remove");
211
+ const hasActive = dataList.some((data) => data.id === activeSuggestionId);
212
+ const hasHover = dataList.some((data) => data.id === hoverSuggestionId);
213
+ const diffOperation = {
214
+ type: hasRemove ? "delete" : "insert"
215
+ };
216
+ const Component = {
217
+ delete: "del",
218
+ insert: "ins",
219
+ update: "span"
220
+ }[diffOperation.type];
221
+ return /* @__PURE__ */ jsx3(
222
+ PlateLeaf2,
223
+ __spreadProps(__spreadValues({}, props), {
224
+ as: Component,
225
+ attributes: __spreadProps(__spreadValues({}, props.attributes), {
226
+ onMouseEnter: () => setOption("hoverId", leafId),
227
+ onMouseLeave: () => setOption("hoverId", null)
228
+ }),
229
+ className: suggestionVariants({
230
+ insertActive: hasActive || hasHover,
231
+ remove: hasRemove,
232
+ removeActive: (hasActive || hasHover) && hasRemove
233
+ })
234
+ })
235
+ );
236
+ }
237
+ var SuggestionLineBreak = ({ api, element }) => {
238
+ if (!api.suggestion.isBlockSuggestion(element)) return;
239
+ const suggestionData = element.suggestion;
240
+ return function Component({ children }) {
241
+ return /* @__PURE__ */ jsx3(SuggestionLineBreakContent, { suggestionData, children });
242
+ };
243
+ };
244
+ function SuggestionLineBreakContent({
245
+ children,
246
+ suggestionData
247
+ }) {
248
+ const { isLineBreak, type } = suggestionData;
249
+ const isRemove = type === "remove";
250
+ const isInsert = type === "insert";
251
+ const activeSuggestionId = usePluginOption2(suggestionPlugin, "activeId");
252
+ const hoverSuggestionId = usePluginOption2(suggestionPlugin, "hoverId");
253
+ const isActive = activeSuggestionId === suggestionData.id;
254
+ const isHover = hoverSuggestionId === suggestionData.id;
255
+ const spanRef = React.useRef(null);
256
+ const { setOption } = useEditorPlugin2(suggestionPlugin);
257
+ return /* @__PURE__ */ jsx3(Fragment, { children: isLineBreak ? /* @__PURE__ */ jsxs(Fragment, { children: [
258
+ children,
259
+ /* @__PURE__ */ jsx3(
260
+ "span",
261
+ {
262
+ className: cn(
263
+ "absolute border-b-2 border-b-brand/24 bg-brand/8 text-justify text-brand/80 no-underline transition-colors duration-200",
264
+ isInsert && (isActive || isHover) && "border-b-brand/60 bg-brand/13",
265
+ isRemove && "border-b-gray-300 bg-gray-300/25 text-gray-400 line-through",
266
+ isRemove && (isActive || isHover) && "border-b-gray-500 bg-gray-400/25 text-gray-500 no-underline"
267
+ ),
268
+ contentEditable: false,
269
+ ref: spanRef,
270
+ style: {
271
+ bottom: 3.5,
272
+ height: 21
273
+ },
274
+ children: /* @__PURE__ */ jsx3(CornerDownLeftIcon, { className: "mt-0.5 size-4" })
275
+ }
276
+ )
277
+ ] }) : /* @__PURE__ */ jsx3(
278
+ "span",
279
+ {
280
+ className: cn(
281
+ suggestionVariants({
282
+ insertActive: isInsert && (isActive || isHover),
283
+ remove: isRemove,
284
+ removeActive: (isActive || isHover) && isRemove
285
+ })
286
+ ),
287
+ "data-block-suggestion": "true",
288
+ onMouseEnter: () => setOption("hoverId", suggestionData.id),
289
+ onMouseLeave: () => setOption("hoverId", null),
290
+ role: "presentation",
291
+ children
292
+ }
293
+ ) });
294
+ }
295
+
296
+ // src/components/editor/plugins/suggestion-kit.tsx
297
+ var suggestionPlugin = toTPlatePlugin(BaseSuggestionPlugin, ({ editor }) => ({
298
+ handlers: {
299
+ // unset active suggestion when clicking outside of suggestion
300
+ onClick: ({ api, event, setOption, type }) => {
301
+ var _a, _b;
302
+ let leaf = event.target;
303
+ let isSet = false;
304
+ const isBlockLeaf = leaf.dataset.blockSuggestion === "true";
305
+ const unsetActiveSuggestion = () => {
306
+ setOption("activeId", null);
307
+ isSet = true;
308
+ };
309
+ if (!isSlateString(leaf) && !isBlockLeaf) {
310
+ unsetActiveSuggestion();
311
+ }
312
+ while (leaf.parentElement && !isSlateEditor(leaf.parentElement)) {
313
+ const isBlockSuggestion = leaf.dataset.blockSuggestion === "true";
314
+ if (leaf.classList.contains(`slate-${type}`) || isBlockSuggestion) {
315
+ const suggestionEntry = (_a = api.suggestion) == null ? void 0 : _a.node({
316
+ isText: !isBlockSuggestion
317
+ });
318
+ if (!suggestionEntry) {
319
+ unsetActiveSuggestion();
320
+ break;
321
+ }
322
+ const id = (_b = api.suggestion) == null ? void 0 : _b.nodeId(suggestionEntry[0]);
323
+ setOption("activeId", id != null ? id : null);
324
+ isSet = true;
325
+ break;
326
+ }
327
+ leaf = leaf.parentElement;
328
+ }
329
+ if (!isSet) unsetActiveSuggestion();
330
+ }
331
+ },
332
+ options: {
333
+ activeId: null,
334
+ currentUserId: editor.getOption(discussionPlugin, "currentUserId"),
335
+ hoverId: null,
336
+ uniquePathMap: /* @__PURE__ */ new Map()
337
+ }
338
+ })).extend({
339
+ render: {
340
+ belowNodes: SuggestionLineBreak,
341
+ node: SuggestionLeaf
342
+ }
343
+ });
344
+
345
+ // src/hooks/use-debounce-callback.ts
346
+ import { useEffect, useMemo, useRef as useRef2 } from "react";
347
+ function useDebouncedCallback(func, wait, options) {
348
+ const lastCallTime = useRef2(null);
349
+ const lastInvokeTime = useRef2(0);
350
+ const timerId = useRef2(null);
351
+ const lastArgs = useRef2([]);
352
+ const lastThis = useRef2(void 0);
353
+ const result = useRef2(void 0);
354
+ const funcRef = useRef2(func);
355
+ const mounted = useRef2(true);
356
+ funcRef.current = func;
357
+ const isClientSize = typeof window !== "undefined";
358
+ const useRAF = !wait && wait !== 0 && isClientSize;
359
+ if (typeof func !== "function") {
360
+ throw new TypeError("Expected a function");
361
+ }
362
+ const actualWait = wait || 0;
363
+ const actualOptions = options || {};
364
+ const leading = !!actualOptions.leading;
365
+ const trailing = "trailing" in actualOptions ? !!actualOptions.trailing : true;
366
+ const maxing = "maxWait" in actualOptions;
367
+ const debounceOnServer = "debounceOnServer" in actualOptions ? !!actualOptions.debounceOnServer : false;
368
+ const maxWait = maxing ? Math.max(actualOptions.maxWait || 0, actualWait) : null;
369
+ useEffect(() => {
370
+ mounted.current = true;
371
+ return () => {
372
+ mounted.current = false;
373
+ };
374
+ }, []);
375
+ const debounced = useMemo(() => {
376
+ const invokeFunc = (time) => {
377
+ const args = lastArgs.current;
378
+ const thisArg = lastThis.current;
379
+ lastArgs.current = lastThis.current = null;
380
+ lastInvokeTime.current = time;
381
+ result.current = funcRef.current.apply(thisArg, args);
382
+ return result.current;
383
+ };
384
+ const startTimer = (pendingFunc, wait2) => {
385
+ if (useRAF) cancelAnimationFrame(timerId.current);
386
+ timerId.current = useRAF ? requestAnimationFrame(pendingFunc) : setTimeout(pendingFunc, wait2);
387
+ };
388
+ const shouldInvoke = (time) => {
389
+ var _a;
390
+ if (!mounted.current) return false;
391
+ const timeSinceLastCall = time - ((_a = lastCallTime.current) != null ? _a : 0);
392
+ const timeSinceLastInvoke = time - lastInvokeTime.current;
393
+ return !lastCallTime.current || timeSinceLastCall >= actualWait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= (maxWait != null ? maxWait : 0);
394
+ };
395
+ const trailingEdge = (time) => {
396
+ timerId.current = null;
397
+ if (trailing && lastArgs.current) {
398
+ return invokeFunc(time);
399
+ }
400
+ lastArgs.current = lastThis.current = null;
401
+ return result.current;
402
+ };
403
+ const timerExpired = () => {
404
+ var _a;
405
+ const time = Date.now();
406
+ if (shouldInvoke(time)) {
407
+ return trailingEdge(time);
408
+ }
409
+ if (!mounted.current) {
410
+ return;
411
+ }
412
+ const timeSinceLastCall = time - ((_a = lastCallTime.current) != null ? _a : 0);
413
+ const timeSinceLastInvoke = time - lastInvokeTime.current;
414
+ const timeWaiting = actualWait - timeSinceLastCall;
415
+ const remainingWait = maxing ? Math.min(timeWaiting, (maxWait != null ? maxWait : 0) - timeSinceLastInvoke) : timeWaiting;
416
+ startTimer(timerExpired, remainingWait);
417
+ };
418
+ const func2 = (...args) => {
419
+ if (!isClientSize && !debounceOnServer) {
420
+ return void 0;
421
+ }
422
+ const time = Date.now();
423
+ const isInvoking = shouldInvoke(time);
424
+ lastArgs.current = args;
425
+ lastThis.current = void 0;
426
+ lastCallTime.current = time;
427
+ if (isInvoking) {
428
+ if (!timerId.current && mounted.current) {
429
+ lastInvokeTime.current = lastCallTime.current;
430
+ startTimer(timerExpired, actualWait);
431
+ return leading ? invokeFunc(lastCallTime.current) : result.current;
432
+ }
433
+ if (maxing) {
434
+ startTimer(timerExpired, actualWait);
435
+ return invokeFunc(lastCallTime.current);
436
+ }
437
+ }
438
+ if (!timerId.current) {
439
+ startTimer(timerExpired, actualWait);
440
+ }
441
+ return result.current;
442
+ };
443
+ func2.cancel = () => {
444
+ if (timerId.current) {
445
+ if (useRAF) {
446
+ cancelAnimationFrame(timerId.current);
447
+ } else {
448
+ clearTimeout(timerId.current);
449
+ }
450
+ }
451
+ lastInvokeTime.current = 0;
452
+ lastArgs.current = lastCallTime.current = lastThis.current = timerId.current = null;
453
+ };
454
+ func2.isPending = () => !!timerId.current;
455
+ func2.flush = () => timerId.current ? trailingEdge(Date.now()) : result.current;
456
+ return func2;
457
+ }, [leading, maxing, actualWait, maxWait, trailing, useRAF, isClientSize, debounceOnServer]);
458
+ return debounced;
459
+ }
460
+
461
+ // src/ui/avatar.tsx
462
+ import { cva as cva2 } from "class-variance-authority";
463
+ import { Avatar as AvatarPrimitive } from "radix-ui";
464
+ import { jsx as jsx4 } from "react/jsx-runtime";
465
+ var avatarVariants = cva2("relative flex shrink-0 overflow-hidden", {
466
+ defaultVariants: {
467
+ size: "default",
468
+ variant: "default"
469
+ },
470
+ variants: {
471
+ size: {
472
+ default: "size-10",
473
+ lg: "size-12",
474
+ profile: "size-20",
475
+ settings: "size-20 md:size-28",
476
+ sm: "size-6"
477
+ },
478
+ variant: {
479
+ default: "rounded-full"
480
+ }
481
+ }
482
+ });
483
+ function Avatar(_a) {
484
+ var _b = _a, { className, size, variant } = _b, props = __objRest(_b, ["className", "size", "variant"]);
485
+ return /* @__PURE__ */ jsx4(AvatarPrimitive.Root, __spreadValues({ className: cn(avatarVariants({ size, variant }), className), "data-slot": "avatar" }, props));
486
+ }
487
+ function AvatarImage(_a) {
488
+ var _b = _a, {
489
+ className,
490
+ onLoadingStatusChange
491
+ } = _b, props = __objRest(_b, [
492
+ "className",
493
+ "onLoadingStatusChange"
494
+ ]);
495
+ return /* @__PURE__ */ jsx4(
496
+ AvatarPrimitive.Image,
497
+ {
498
+ asChild: true,
499
+ "data-slot": "avatar-image",
500
+ onLoadingStatusChange,
501
+ src: props.src,
502
+ children: /* @__PURE__ */ jsx4(
503
+ "img",
504
+ __spreadProps(__spreadValues({
505
+ className: cn("aspect-square size-full select-none object-cover", className),
506
+ fill: "true"
507
+ }, props), {
508
+ alt: ""
509
+ })
510
+ )
511
+ }
512
+ );
513
+ }
514
+ var avatarFallbackVariants = cva2("box-content flex size-full items-center justify-center", {
515
+ defaultVariants: {
516
+ variant: "default"
517
+ },
518
+ variants: {
519
+ variant: {
520
+ default: "rounded-full bg-muted"
521
+ }
522
+ }
523
+ });
524
+ function AvatarFallback(_a) {
525
+ var _b = _a, { className, variant } = _b, props = __objRest(_b, ["className", "variant"]);
526
+ return /* @__PURE__ */ jsx4(
527
+ AvatarPrimitive.Fallback,
528
+ __spreadValues({
529
+ className: cn(avatarFallbackVariants({ variant }), className),
530
+ "data-slot": "avatar-fallback"
531
+ }, props)
532
+ );
533
+ }
534
+
535
+ // src/ui/block-suggestion.tsx
536
+ import { acceptSuggestion, getSuggestionKey, keyId2SuggestionId, rejectSuggestion } from "@platejs/suggestion";
537
+ import { SuggestionPlugin } from "@platejs/suggestion/react";
538
+ import { CheckIcon as CheckIcon3, XIcon as XIcon2 } from "lucide-react";
539
+ import {
540
+ ElementApi,
541
+ KEYS as KEYS3,
542
+ PathApi,
543
+ TextApi
544
+ } from "platejs";
545
+ import { useEditorPlugin as useEditorPlugin4, usePluginOption as usePluginOption4 } from "platejs/react";
546
+ import React4, { useEffect as useEffect3 } from "react";
547
+
548
+ // src/ui/button.tsx
549
+ import { Slot } from "radix-ui";
550
+ import { cva as cva4 } from "class-variance-authority";
551
+
552
+ // src/ui/spinner.tsx
553
+ import { cva as cva3 } from "class-variance-authority";
554
+ import { Loader2Icon } from "lucide-react";
555
+ import { jsx as jsx5 } from "react/jsx-runtime";
556
+ var spinnerVariants = cva3("animate-spin text-muted-foreground", {
557
+ defaultVariants: {
558
+ size: "default"
559
+ },
560
+ variants: {
561
+ size: {
562
+ default: "size-4",
563
+ icon: "size-10",
564
+ lg: "size-6",
565
+ sm: "size-2"
566
+ }
567
+ }
568
+ });
569
+ function Spinner(_a) {
570
+ var _b = _a, { className, size } = _b, props = __objRest(_b, ["className", "size"]);
571
+ return /* @__PURE__ */ jsx5(Loader2Icon, __spreadValues({ className: cn(spinnerVariants({ size }), className) }, props));
572
+ }
573
+
574
+ // src/ui/tooltip.tsx
575
+ import { Tooltip as TooltipPrimitive } from "radix-ui";
576
+
577
+ // src/context/portal-container.tsx
578
+ import { createContext as createContext2, useContext as useContext2, useRef as useRef3 } from "react";
579
+ import { jsx as jsx6 } from "react/jsx-runtime";
580
+ var PortalContainerContext = createContext2(null);
581
+ function usePortalContainer() {
582
+ var _a;
583
+ const context = useContext2(PortalContainerContext);
584
+ return (_a = context == null ? void 0 : context.container.current) != null ? _a : null;
585
+ }
586
+
587
+ // src/hooks/use-mounted.ts
588
+ import { useSyncExternalStore } from "react";
589
+ var useMounted = () => {
590
+ return useSyncExternalStore(
591
+ subscribe,
592
+ // subscribe: no-op, never changes
593
+ () => true,
594
+ // getSnapshot (client): always true
595
+ () => false
596
+ // getServerSnapshot (SSR): always false
597
+ );
598
+ };
599
+ var subscribe = () => () => {
600
+ };
601
+
602
+ // src/ui/tooltip.tsx
603
+ import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
604
+ function TooltipProvider(_a) {
605
+ var _b = _a, {
606
+ delayDuration = 200,
607
+ disableHoverableContent = true,
608
+ skipDelayDuration = 0
609
+ } = _b, props = __objRest(_b, [
610
+ "delayDuration",
611
+ "disableHoverableContent",
612
+ "skipDelayDuration"
613
+ ]);
614
+ return /* @__PURE__ */ jsx7(
615
+ TooltipPrimitive.Provider,
616
+ __spreadValues({
617
+ delayDuration,
618
+ disableHoverableContent,
619
+ skipDelayDuration
620
+ }, props)
621
+ );
622
+ }
623
+ var Tooltip = TooltipPrimitive.Root;
624
+ var TooltipTrigger = TooltipPrimitive.Trigger;
625
+ function TooltipPortal(props) {
626
+ const container = usePortalContainer();
627
+ return /* @__PURE__ */ jsx7(TooltipPrimitive.Portal, __spreadValues({ container }, props));
628
+ }
629
+ function TooltipContent(_a) {
630
+ var _b = _a, {
631
+ className,
632
+ sideOffset = 4
633
+ } = _b, props = __objRest(_b, [
634
+ "className",
635
+ "sideOffset"
636
+ ]);
637
+ return /* @__PURE__ */ jsx7(
638
+ TooltipPrimitive.Content,
639
+ __spreadValues({
640
+ className: cn(
641
+ "z-9999 overflow-hidden rounded-md bg-primary px-2 py-1.5 font-semibold text-primary-foreground text-xs shadow-md",
642
+ className
643
+ ),
644
+ sideOffset
645
+ }, props)
646
+ );
647
+ }
648
+ function withTooltip(Component) {
649
+ return function ExtendComponent(_a) {
650
+ var _b = _a, {
651
+ shortcut,
652
+ tooltip,
653
+ tooltipContentProps,
654
+ tooltipProps,
655
+ tooltipTriggerProps
656
+ } = _b, props = __objRest(_b, [
657
+ "shortcut",
658
+ "tooltip",
659
+ "tooltipContentProps",
660
+ "tooltipProps",
661
+ "tooltipTriggerProps"
662
+ ]);
663
+ const isMounted = useMounted();
664
+ const component = /* @__PURE__ */ jsx7(Component, __spreadValues({}, props));
665
+ if (tooltip && isMounted) {
666
+ return /* @__PURE__ */ jsx7(TooltipProvider, { children: /* @__PURE__ */ jsxs2(Tooltip, __spreadProps(__spreadValues({}, tooltipProps), { children: [
667
+ /* @__PURE__ */ jsx7(TooltipTrigger, __spreadProps(__spreadValues({ asChild: true }, tooltipTriggerProps), { children: component })),
668
+ /* @__PURE__ */ jsx7(TooltipPortal, { children: /* @__PURE__ */ jsxs2(TooltipContent, __spreadProps(__spreadValues({}, tooltipContentProps), { children: [
669
+ tooltip,
670
+ shortcut && /* @__PURE__ */ jsx7("div", { className: "mt-px text-primary-foreground/70", children: shortcut })
671
+ ] })) })
672
+ ] })) });
673
+ }
674
+ return component;
675
+ };
676
+ }
677
+
678
+ // src/ui/button.tsx
679
+ import { jsx as jsx8, jsxs as jsxs3 } from "react/jsx-runtime";
680
+ var SlotRoot = Slot.Root;
681
+ var buttonVariants = cva4(
682
+ "focus-ring inline-flex w-fit cursor-pointer select-none items-center justify-center gap-2 rounded-md text-sm ring-offset-background transition-bg-ease disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
683
+ {
684
+ defaultVariants: {
685
+ size: "default",
686
+ truncate: true,
687
+ variant: "default"
688
+ },
689
+ variants: {
690
+ active: {
691
+ false: "",
692
+ true: "border-2 border-primary"
693
+ },
694
+ disabled: {
695
+ true: "pointer-events-none opacity-50"
696
+ },
697
+ focused: {
698
+ true: "ring-2 ring-ring ring-offset-2"
699
+ },
700
+ isMenu: {
701
+ true: "h-auto w-full cursor-pointer justify-start"
702
+ },
703
+ size: {
704
+ blockAction: "size-6.5 gap-1 px-1.5 text-xs",
705
+ default: "h-7 gap-1.5 px-2",
706
+ icon: "size-7 w-8.25 [&_svg]:size-5",
707
+ iconSm: "size-7",
708
+ iconXs: "size-5.5",
709
+ lg: "h-11 px-4 text-lg",
710
+ md: "h-8 px-3",
711
+ menuAction: "size-6",
712
+ navAction: "size-5",
713
+ none: "",
714
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
715
+ xs: "h-6.5 px-1.5 py-1 text-xs"
716
+ },
717
+ truncate: {
718
+ true: "truncate whitespace-nowrap"
719
+ },
720
+ variant: {
721
+ blockAction: "rounded-sm hover:bg-primary/6 [&_svg]:text-muted-foreground",
722
+ blockActionSecondary: "rounded-sm bg-primary/6 [&_svg]:text-muted-foreground",
723
+ brand: "bg-brand font-medium text-white hover:bg-brand/80 active:bg-brand-active",
724
+ default: "bg-primary font-medium text-primary-foreground hover:bg-primary/90 [&_svg]:text-primary-foreground",
725
+ destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90 [&_svg]:text-destructive-foreground",
726
+ ghost: "hover:bg-accent hover:text-accent-foreground",
727
+ ghost2: "text-muted-foreground hover:bg-accent",
728
+ ghost3: "text-muted-foreground/80 hover:bg-accent",
729
+ ghostActive: "bg-accent hover:bg-accent hover:text-accent-foreground",
730
+ menuAction: "text-muted-foreground/80 hover:bg-primary/6",
731
+ nav: "rounded-sm text-muted-foreground transition hover:bg-primary/4",
732
+ navAction: "rounded-sm text-muted-foreground/80 opacity-0 transition hover:bg-primary/6 group-hover:opacity-100",
733
+ none: "",
734
+ outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
735
+ primaryOutline: "border border-primary-foreground text-primary-foreground hover:bg-accent/15 [&_svg]:text-primary-foreground",
736
+ radio: "border-2 border-input hover:border-primary",
737
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80"
738
+ }
739
+ }
740
+ }
741
+ );
742
+ var Button = withTooltip(function Button2(_a) {
743
+ var _b = _a, {
744
+ active,
745
+ asChild = false,
746
+ children,
747
+ className,
748
+ focused,
749
+ icon,
750
+ iconPlacement = "left",
751
+ isMenu,
752
+ isPending,
753
+ label,
754
+ loading,
755
+ loadingClassName,
756
+ size,
757
+ truncate,
758
+ variant,
759
+ onToggleClick
760
+ } = _b, props = __objRest(_b, [
761
+ "active",
762
+ "asChild",
763
+ "children",
764
+ "className",
765
+ "focused",
766
+ "icon",
767
+ "iconPlacement",
768
+ "isMenu",
769
+ "isPending",
770
+ "label",
771
+ "loading",
772
+ "loadingClassName",
773
+ "size",
774
+ "truncate",
775
+ "variant",
776
+ "onToggleClick"
777
+ ]);
778
+ const Comp = asChild ? SlotRoot : "button";
779
+ return /* @__PURE__ */ jsxs3(
780
+ Comp,
781
+ __spreadProps(__spreadValues({
782
+ "aria-label": label && label.length > 0 ? label : void 0,
783
+ className: cn(
784
+ buttonVariants({
785
+ disabled: props.disabled,
786
+ focused,
787
+ isMenu,
788
+ size,
789
+ truncate,
790
+ variant
791
+ }),
792
+ active && "border-2 border-primary",
793
+ className
794
+ ),
795
+ type: Comp === "button" ? "button" : void 0
796
+ }, props), {
797
+ children: [
798
+ icon && iconPlacement === "left" && icon,
799
+ loading && /* @__PURE__ */ jsx8(Spinner, { className: loadingClassName }),
800
+ children,
801
+ icon && iconPlacement === "right" && icon
802
+ ]
803
+ })
804
+ );
805
+ });
806
+ var LinkButton = withTooltip(function LinkButton2(_a) {
807
+ var _b = _a, {
808
+ active,
809
+ children,
810
+ className,
811
+ focused,
812
+ icon,
813
+ iconPlacement = "left",
814
+ isMenu,
815
+ label,
816
+ loading,
817
+ loadingClassName,
818
+ size,
819
+ truncate,
820
+ variant = "ghost"
821
+ } = _b, props = __objRest(_b, [
822
+ "active",
823
+ "children",
824
+ "className",
825
+ "focused",
826
+ "icon",
827
+ "iconPlacement",
828
+ "isMenu",
829
+ "label",
830
+ "loading",
831
+ "loadingClassName",
832
+ "size",
833
+ "truncate",
834
+ "variant"
835
+ ]);
836
+ return /* @__PURE__ */ jsxs3(
837
+ "a",
838
+ __spreadProps(__spreadValues({
839
+ className: cn(
840
+ buttonVariants({
841
+ disabled: props.disabled,
842
+ focused,
843
+ isMenu,
844
+ size,
845
+ truncate,
846
+ variant
847
+ }),
848
+ active && "border-2 border-primary",
849
+ className
850
+ ),
851
+ title: label && label.length > 0 ? label : void 0
852
+ }, props), {
853
+ children: [
854
+ icon && iconPlacement === "left" && /* @__PURE__ */ jsx8("div", { className: "shrink-0", children: icon }),
855
+ loading && /* @__PURE__ */ jsx8(Spinner, { className: loadingClassName }),
856
+ children,
857
+ icon && iconPlacement === "right" && icon
858
+ ]
859
+ })
860
+ );
861
+ });
862
+
863
+ // src/ui/comment.tsx
864
+ import { getCommentKey, getDraftCommentKey } from "@platejs/comment";
865
+ import { CommentPlugin, useCommentId } from "@platejs/comment/react";
866
+ import { differenceInDays, differenceInHours, differenceInMinutes, format } from "date-fns";
867
+ import { ArrowUpIcon, CheckIcon as CheckIcon2, MoreHorizontalIcon, PencilIcon, TrashIcon, XIcon } from "lucide-react";
868
+ import { NodeApi, nanoid } from "platejs";
869
+ import {
870
+ Plate,
871
+ useEditorPlugin as useEditorPlugin3,
872
+ useEditorRef as useEditorRef2,
873
+ usePlateEditor,
874
+ usePluginOption as usePluginOption3
875
+ } from "platejs/react";
876
+ import React3, { useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
877
+
878
+ // src/components/editor/plugins/basic-marks-kit.tsx
879
+ import {
880
+ BoldRules,
881
+ CodeRules,
882
+ ItalicRules,
883
+ StrikethroughRules,
884
+ SubscriptRules,
885
+ SuperscriptRules,
886
+ UnderlineRules
887
+ } from "@platejs/basic-nodes";
888
+ import {
889
+ BoldPlugin,
890
+ CodePlugin,
891
+ ItalicPlugin,
892
+ KbdPlugin,
893
+ StrikethroughPlugin,
894
+ SubscriptPlugin,
895
+ SuperscriptPlugin,
896
+ UnderlinePlugin
897
+ } from "@platejs/basic-nodes/react";
898
+ import { createMarkInputRule, KEYS as KEYS2 } from "platejs";
899
+
900
+ // src/types/editor.ts
901
+ var MarkShortcuts = [
902
+ "bold",
903
+ "italic",
904
+ "underline",
905
+ "code",
906
+ "strikethrough",
907
+ "subscript",
908
+ "superscript"
909
+ ];
910
+
911
+ // src/ui/code-node.tsx
912
+ import { PlateLeaf as PlateLeaf3 } from "platejs/react";
913
+ import { jsx as jsx9 } from "react/jsx-runtime";
914
+ function CodeLeaf(props) {
915
+ return /* @__PURE__ */ jsx9(
916
+ PlateLeaf3,
917
+ __spreadProps(__spreadValues({}, props), {
918
+ as: "code",
919
+ className: "whitespace-pre-wrap rounded-md bg-muted px-[0.3em] py-[0.2em] font-mono text-sm"
920
+ })
921
+ );
922
+ }
923
+
924
+ // src/ui/kbd-node.tsx
925
+ import { PlateLeaf as PlateLeaf4 } from "platejs/react";
926
+ import { jsx as jsx10 } from "react/jsx-runtime";
927
+ function KbdLeaf(props) {
928
+ return /* @__PURE__ */ jsx10(
929
+ PlateLeaf4,
930
+ __spreadProps(__spreadValues({}, props), {
931
+ as: "kbd",
932
+ className: "rounded border border-border bg-muted px-1.5 py-0.5 font-mono text-sm shadow-[rgba(255,255,255,0.1)_0px_0.5px_0px_0px_inset,rgb(248,249,250)_0px_1px_5px_0px_inset,rgb(193,200,205)_0px_0px_0px_0.5px,rgb(193,200,205)_0px_2px_1px_-1px,rgb(193,200,205)_0px_1px_0px_0px] dark:shadow-[rgba(255,255,255,0.1)_0px_0.5px_0px_0px_inset,rgb(26,29,30)_0px_1px_5px_0px_inset,rgb(76,81,85)_0px_0px_0px_0.5px,rgb(76,81,85)_0px_2px_1px_-1px,rgb(76,81,85)_0px_1px_0px_0px]",
933
+ children: props.children
934
+ })
935
+ );
936
+ }
937
+
938
+ // src/components/editor/plugins/input-rule-gate.ts
939
+ var addInputRuleGate = (rule, gate) => {
940
+ const existingGate = rule.enabled;
941
+ return __spreadProps(__spreadValues({}, rule), {
942
+ enabled: (context) => gate(context) && (existingGate ? existingGate(context) : true)
943
+ });
944
+ };
945
+
946
+ // src/components/editor/plugins/code-block-input-rule-gate.ts
947
+ import { KEYS } from "platejs";
948
+ var isSelectionOutsideCodeBlock = (editor) => !editor.api.some({ match: { type: [editor.getType(KEYS.codeBlock)] } });
949
+ var outsideCodeBlock = (rule) => addInputRuleGate(rule, (context) => isSelectionOutsideCodeBlock(context.editor));
950
+
951
+ // src/components/editor/plugins/web-address-text.ts
952
+ var SCHEME_SEPARATOR = "://";
953
+ var SCHEMELESS_ADDRESS_PREFIXES = ["www.", "mailto:", "tel:", "//"];
954
+ var ADDRESS_OPENING_PUNCTUATION = /* @__PURE__ */ new Set(["(", "[", "{", "<", '"', "'", "\u201C", "\u2018", "*", "_", "~", "^", "`"]);
955
+ var WHITESPACE_PATTERN = /\s/;
956
+ var HOST_LABEL_PATTERN = /^[\p{L}\p{M}\p{N}-]+$/u;
957
+ var TOP_LEVEL_DOMAIN_PATTERN = /^[\p{L}\p{M}][\p{L}\p{M}\p{N}-]{1,62}$/u;
958
+ var IPV4_OCTET_PATTERN = /^\d{1,3}$/;
959
+ var IPV6_HOST_PATTERN = /^\[[a-f\d:.]+\]$/i;
960
+ var PORT_PATTERN = /^\d{1,5}$/;
961
+ var HOST_WITH_PORT_CHARACTER_PATTERN = /[\p{L}\p{M}\p{N}.:\]-]/u;
962
+ var HOST_TERMINATORS = /* @__PURE__ */ new Set(["/", "?", "#"]);
963
+ var LOCAL_HOST_NAME = "localhost";
964
+ var MAX_DNS_HOST_NAME_LENGTH = 253;
965
+ var MAX_HOST_WITH_PORT_LENGTH = MAX_DNS_HOST_NAME_LENGTH + ":65535".length;
966
+ var EMAIL_LOCAL_PART_CHARACTER_PATTERN = /[\p{L}\p{N}._%+-]/u;
967
+ var EMAIL_DOMAIN_IN_PROGRESS_PATTERN = /^[\p{L}\p{M}\p{N}.-]*$/u;
968
+ var getLastWord = (text) => {
969
+ let wordStart = text.length;
970
+ while (wordStart > 0 && !WHITESPACE_PATTERN.test(text.charAt(wordStart - 1))) {
971
+ wordStart -= 1;
972
+ }
973
+ return text.slice(wordStart);
974
+ };
975
+ var hasSchemelessPrefixAt = (word, start) => SCHEMELESS_ADDRESS_PREFIXES.some((prefix) => word.slice(start, start + prefix.length).toLowerCase() === prefix);
976
+ var isHostName = (host) => {
977
+ if (host.toLowerCase() === LOCAL_HOST_NAME || IPV6_HOST_PATTERN.test(host)) return true;
978
+ const labels = host.split(".");
979
+ const topLevelDomain = labels.at(-1);
980
+ if (labels.length === 4 && labels.every((label) => IPV4_OCTET_PATTERN.test(label) && Number(label) <= 255)) {
981
+ return true;
982
+ }
983
+ if (labels.length < 2 || topLevelDomain === void 0 || !TOP_LEVEL_DOMAIN_PATTERN.test(topLevelDomain)) {
984
+ return false;
985
+ }
986
+ return labels.every((label) => HOST_LABEL_PATTERN.test(label));
987
+ };
988
+ var hasHostAt = (word, start) => {
989
+ const searchEnd = Math.min(word.length, start + MAX_HOST_WITH_PORT_LENGTH + 1);
990
+ let hostEnd = start;
991
+ let hasTerminator = false;
992
+ for (let index = start; index < searchEnd; index += 1) {
993
+ const character = word.charAt(index);
994
+ if (HOST_TERMINATORS.has(character)) {
995
+ hasTerminator = true;
996
+ break;
997
+ }
998
+ if (!(index === start && character === "[") && !HOST_WITH_PORT_CHARACTER_PATTERN.test(character)) return false;
999
+ hostEnd = index + 1;
1000
+ }
1001
+ if (!hasTerminator || hostEnd <= start) return false;
1002
+ const hostWithPort = word.slice(start, hostEnd);
1003
+ const portSeparator = hostWithPort.startsWith("[") ? hostWithPort.indexOf(":", hostWithPort.indexOf("]") + 1) : hostWithPort.indexOf(":");
1004
+ const host = portSeparator === -1 ? hostWithPort : hostWithPort.slice(0, portSeparator);
1005
+ const port = portSeparator === -1 ? void 0 : hostWithPort.slice(portSeparator + 1);
1006
+ if (port !== void 0 && !PORT_PATTERN.test(port)) return false;
1007
+ return isHostName(host);
1008
+ };
1009
+ var isTypingEmailDomain = (word) => {
1010
+ const atIndex = word.lastIndexOf("@");
1011
+ if (atIndex < 1 || !EMAIL_LOCAL_PART_CHARACTER_PATTERN.test(word.charAt(atIndex - 1))) return false;
1012
+ return EMAIL_DOMAIN_IN_PROGRESS_PATTERN.test(word.slice(atIndex + 1));
1013
+ };
1014
+ var endsInWebAddress = (text) => {
1015
+ const word = getLastWord(text);
1016
+ if (word.includes(SCHEME_SEPARATOR) || isTypingEmailDomain(word)) return true;
1017
+ for (let start = 0; start < word.length; start += 1) {
1018
+ if (start > 0 && !ADDRESS_OPENING_PUNCTUATION.has(word.charAt(start - 1))) continue;
1019
+ if (hasSchemelessPrefixAt(word, start) || hasHostAt(word, start)) return true;
1020
+ }
1021
+ return false;
1022
+ };
1023
+
1024
+ // src/components/editor/plugins/mark-input-rule-gate.ts
1025
+ var whereMarkShortcutApplies = (rule) => outsideCodeBlock(
1026
+ addInputRuleGate(
1027
+ rule,
1028
+ (context) => !endsInWebAddress(context.getBlockTextBeforeSelection())
1029
+ )
1030
+ );
1031
+
1032
+ // src/components/editor/plugins/typed-conversion-options.ts
1033
+ import { createSlatePlugin } from "platejs";
1034
+ var isMarkShortcut = (value) => MarkShortcuts.some((markShortcut) => markShortcut === value);
1035
+ var normalizeMarkShortcuts = (value) => Array.isArray(value) ? [...new Set(value.filter(isMarkShortcut))] : MarkShortcuts;
1036
+ var resolveTypedConversionOptions = (features) => ({
1037
+ textSubstitutions: features.textSubstitutions !== false,
1038
+ markShortcuts: normalizeMarkShortcuts(features.markShortcuts)
1039
+ });
1040
+ var TypedConversionPlugin = createSlatePlugin({
1041
+ key: "typedConversions",
1042
+ options: resolveTypedConversionOptions({})
1043
+ });
1044
+ var canApplyMarkShortcut = (editor, marks, fallback) => {
1045
+ const allowedMarks = editor.plugins[TypedConversionPlugin.key] ? editor.getOption(TypedConversionPlugin, "markShortcuts") : fallback;
1046
+ return marks.every((mark) => allowedMarks.includes(mark));
1047
+ };
1048
+
1049
+ // src/components/editor/plugins/basic-marks-kit.tsx
1050
+ var createCombinedMarkRule = (start, marks) => {
1051
+ const closingDelimiter = [...start].reverse().join("");
1052
+ return whereMarkShortcutApplies(
1053
+ createMarkInputRule({
1054
+ start,
1055
+ end: closingDelimiter.slice(0, -1),
1056
+ trigger: closingDelimiter.slice(-1),
1057
+ marks
1058
+ })
1059
+ );
1060
+ };
1061
+ var createMarkShortcutRules = (allowedMarks) => {
1062
+ const ruleFor = (marks, rule) => addInputRuleGate(rule, ({ editor }) => canApplyMarkShortcut(editor, marks, allowedMarks));
1063
+ return {
1064
+ bold: [
1065
+ ruleFor(["bold", "italic"], createCombinedMarkRule("***", [KEYS2.bold, KEYS2.italic])),
1066
+ ruleFor(
1067
+ ["underline", "bold", "italic"],
1068
+ createCombinedMarkRule("___***", [KEYS2.underline, KEYS2.bold, KEYS2.italic])
1069
+ ),
1070
+ ruleFor(["underline", "bold"], createCombinedMarkRule("__**", [KEYS2.underline, KEYS2.bold])),
1071
+ ruleFor(["underline", "italic"], createCombinedMarkRule("__*", [KEYS2.underline, KEYS2.italic])),
1072
+ ruleFor(["bold"], whereMarkShortcutApplies(BoldRules.markdown({ variant: "*" })))
1073
+ ],
1074
+ italic: [
1075
+ ruleFor(["italic"], whereMarkShortcutApplies(ItalicRules.markdown({ variant: "*" }))),
1076
+ ruleFor(["italic"], whereMarkShortcutApplies(ItalicRules.markdown({ variant: "_" })))
1077
+ ],
1078
+ underline: [ruleFor(["underline"], whereMarkShortcutApplies(UnderlineRules.markdown()))],
1079
+ code: [ruleFor(["code"], whereMarkShortcutApplies(CodeRules.markdown()))],
1080
+ strikethrough: [ruleFor(["strikethrough"], whereMarkShortcutApplies(StrikethroughRules.markdown()))],
1081
+ subscript: [ruleFor(["subscript"], whereMarkShortcutApplies(SubscriptRules.markdown()))],
1082
+ superscript: [ruleFor(["superscript"], whereMarkShortcutApplies(SuperscriptRules.markdown()))]
1083
+ };
1084
+ };
1085
+ var createBasicMarksKit = (markShortcuts = MarkShortcuts) => {
1086
+ const inputRules = createMarkShortcutRules(normalizeMarkShortcuts(markShortcuts));
1087
+ return [
1088
+ BoldPlugin.configure({ inputRules: inputRules.bold }),
1089
+ ItalicPlugin.configure({ inputRules: inputRules.italic }),
1090
+ UnderlinePlugin.configure({ inputRules: inputRules.underline }),
1091
+ CodePlugin.configure({
1092
+ inputRules: inputRules.code,
1093
+ node: { component: CodeLeaf },
1094
+ shortcuts: { toggle: { keys: "mod+e" } }
1095
+ }),
1096
+ StrikethroughPlugin.configure({
1097
+ inputRules: inputRules.strikethrough,
1098
+ shortcuts: { toggle: { keys: "mod+shift+x" } }
1099
+ }),
1100
+ SubscriptPlugin.configure({
1101
+ inputRules: inputRules.subscript,
1102
+ shortcuts: { toggle: { keys: "mod+comma" } }
1103
+ }),
1104
+ SuperscriptPlugin.configure({
1105
+ inputRules: inputRules.superscript,
1106
+ shortcuts: { toggle: { keys: "mod+period" } }
1107
+ }),
1108
+ KbdPlugin.withComponent(KbdLeaf)
1109
+ ];
1110
+ };
1111
+ var BasicMarksKit = createBasicMarksKit();
1112
+
1113
+ // src/ui/dropdown-menu.tsx
1114
+ import { cva as cva5 } from "class-variance-authority";
1115
+ import { CheckIcon, ChevronRightIcon } from "lucide-react";
1116
+ import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
1117
+ import * as React2 from "react";
1118
+ import { jsx as jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
1119
+ var dropdownMenuItemVariants = cva5(
1120
+ cn(
1121
+ "no-focus-ring relative flex cursor-pointer select-none items-center gap-2 rounded-md align-middle text-sm transition-bg-ease data-disabled:pointer-events-none data-disabled:opacity-50",
1122
+ "[&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-subtle-foreground",
1123
+ "text-accent-foreground hover:bg-accent hover:highlight-edge focus:bg-accent focus:text-accent-foreground focus:highlight-edge"
1124
+ ),
1125
+ {
1126
+ defaultVariants: {
1127
+ size: "default",
1128
+ variant: "default"
1129
+ },
1130
+ variants: {
1131
+ size: {
1132
+ default: "mx-1 h-7 w-[calc(100%-8px)] px-2.5",
1133
+ none: ""
1134
+ },
1135
+ variant: {
1136
+ default: "focus:bg-accent focus:text-accent-foreground",
1137
+ none: ""
1138
+ }
1139
+ }
1140
+ }
1141
+ );
1142
+ var dropdownMenuLabelVariants = cva5(
1143
+ cn("mt-1.5 mb-2 cursor-default select-none px-3.5 font-medium text-muted-foreground text-xs"),
1144
+ {
1145
+ variants: {
1146
+ inset: {
1147
+ true: "pl-8"
1148
+ }
1149
+ }
1150
+ }
1151
+ );
1152
+ function DropdownMenu(props) {
1153
+ return /* @__PURE__ */ jsx11(DropdownMenuPrimitive.Root, __spreadValues({}, props));
1154
+ }
1155
+ function DropdownMenuTrigger(props) {
1156
+ return /* @__PURE__ */ jsx11(DropdownMenuPrimitive.Trigger, __spreadValues({}, props));
1157
+ }
1158
+ function DropdownMenuGroup(props) {
1159
+ return /* @__PURE__ */ jsx11(DropdownMenuPrimitive.Group, __spreadValues({ className: "py-1.5" }, props));
1160
+ }
1161
+ function DropdownMenuContent(_a) {
1162
+ var _b = _a, {
1163
+ className,
1164
+ portal
1165
+ } = _b, props = __objRest(_b, [
1166
+ "className",
1167
+ "portal"
1168
+ ]);
1169
+ const container = usePortalContainer();
1170
+ const content = /* @__PURE__ */ jsx11(
1171
+ DropdownMenuPrimitive.Content,
1172
+ __spreadValues({
1173
+ className: cn(
1174
+ "no-focus-ring z-50 min-w-32 max-w-screen overflow-hidden rounded-lg border border-border bg-popover p-0 text-popover-foreground text-sm shadow-floating",
1175
+ "data-[state=closed]:hidden data-[side=bottom]:origin-top data-[side=left]:origin-right data-[side=right]:origin-left data-[side=top]:origin-bottom data-[state=open]:animate-zoom",
1176
+ className
1177
+ ),
1178
+ sideOffset: 4
1179
+ }, props)
1180
+ );
1181
+ if (portal) {
1182
+ return /* @__PURE__ */ jsx11(DropdownMenuPrimitive.Portal, { container, children: content });
1183
+ }
1184
+ return content;
1185
+ }
1186
+ function DropdownMenuItem(_a) {
1187
+ var _b = _a, {
1188
+ className
1189
+ } = _b, props = __objRest(_b, [
1190
+ "className"
1191
+ ]);
1192
+ return /* @__PURE__ */ jsx11(DropdownMenuPrimitive.Item, __spreadValues({ className: cn(dropdownMenuItemVariants(), className) }, props));
1193
+ }
1194
+
1195
+ // src/ui/editor.tsx
1196
+ import { cva as cva6 } from "class-variance-authority";
1197
+ import { PlateContainer, PlateContent, useEditorRef } from "platejs/react";
1198
+ import { jsx as jsx12 } from "react/jsx-runtime";
1199
+ var editorContainerVariants = cva6(
1200
+ 'relative w-full cursor-text !overflow-visible font-[ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe_UI_Variable_Display","Segoe_UI",Helvetica,"Apple_Color_Emoji",Arial,sans-serif,"Segoe_UI_Emoji","Segoe_UI_Symbol"] caret-primary selection:bg-brand/25 focus-visible:outline-hidden [&_.slate-selection-area]:bg-brand/15',
1201
+ {
1202
+ defaultVariants: {
1203
+ variant: "default"
1204
+ },
1205
+ variants: {
1206
+ variant: {
1207
+ comment: cn(
1208
+ "flex flex-wrap justify-between gap-1 px-1 py-0.5 text-sm",
1209
+ "rounded-md border-[1.5px] border-transparent bg-transparent",
1210
+ "has-[[data-slate-editor]:focus]:border-brand/50 has-[[data-slate-editor]:focus]:ring-2 has-[[data-slate-editor]:focus]:ring-brand/30",
1211
+ "has-aria-disabled:border-input has-aria-disabled:bg-muted"
1212
+ ),
1213
+ default: "h-full",
1214
+ demo: "h-162.5 overflow-y-auto",
1215
+ select: cn(
1216
+ "group rounded-md border border-input ring-offset-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
1217
+ "has-data-readonly:w-fit has-data-readonly:cursor-default has-data-readonly:border-transparent has-data-readonly:focus-within:[box-shadow:none]"
1218
+ )
1219
+ }
1220
+ }
1221
+ }
1222
+ );
1223
+ function EditorContainer(_a) {
1224
+ var _b = _a, {
1225
+ className,
1226
+ variant
1227
+ } = _b, props = __objRest(_b, [
1228
+ "className",
1229
+ "variant"
1230
+ ]);
1231
+ const editor = useEditorRef();
1232
+ return /* @__PURE__ */ jsx12(
1233
+ PlateContainer,
1234
+ __spreadValues({
1235
+ className: cn("ignore-click-outside/toolbar", editorContainerVariants({ variant }), className),
1236
+ onClick: (e) => {
1237
+ if (variant === "comment") {
1238
+ e.preventDefault();
1239
+ editor.tf.focus({ edge: "endEditor" });
1240
+ }
1241
+ },
1242
+ onMouseDown: (e) => {
1243
+ if (variant === "comment") {
1244
+ e.stopPropagation();
1245
+ e.preventDefault();
1246
+ }
1247
+ }
1248
+ }, props)
1249
+ );
1250
+ }
1251
+ var editorVariants = cva6(
1252
+ cn(
1253
+ "group/editor pt-4",
1254
+ "relative w-full !overflow-visible whitespace-pre-wrap break-words",
1255
+ "rounded-md ring-offset-background placeholder:text-muted-foreground/80 focus-visible:outline-hidden",
1256
+ "**:data-slate-placeholder:!top-1/2 **:data-slate-placeholder:-translate-y-1/2 **:data-slate-placeholder:text-muted-foreground/80 **:data-slate-placeholder:opacity-100!",
1257
+ "[&_strong]:font-bold"
1258
+ ),
1259
+ {
1260
+ defaultVariants: {
1261
+ variant: "default"
1262
+ },
1263
+ variants: {
1264
+ disabled: {
1265
+ true: "cursor-not-allowed opacity-50"
1266
+ },
1267
+ focused: {
1268
+ true: "ring-2 ring-ring ring-offset-2"
1269
+ },
1270
+ variant: {
1271
+ ai: "px-0 text-base md:text-sm",
1272
+ aiChat: "max-h-[min(70vh,320px)] max-w-175 overflow-y-auto px-3 py-2 text-base md:text-sm",
1273
+ comment: cn("rounded-none border-none bg-transparent text-sm"),
1274
+ default: "min-h-full px-25 pb-72 text-base sm:px-[max(100px,calc(50%-350px))]",
1275
+ demo: "h-full px-25 pt-4 pb-72 text-base sm:px-[max(100px,calc(50%-350px))]",
1276
+ fullWidth: "min-h-full px-25 pb-72 text-base",
1277
+ select: "px-3 py-2 text-base data-readonly:w-fit",
1278
+ update: "px-0 text-sm",
1279
+ versionHistory: "px-0 pb-[30vh] text-base font-[inherit]",
1280
+ viewer: "px-0 text-base font-[inherit]"
1281
+ }
1282
+ }
1283
+ }
1284
+ );
1285
+ function Editor(_a) {
1286
+ var _b = _a, {
1287
+ className,
1288
+ disabled,
1289
+ focused,
1290
+ variant,
1291
+ onClick,
1292
+ onMouseDown
1293
+ } = _b, props = __objRest(_b, [
1294
+ "className",
1295
+ "disabled",
1296
+ "focused",
1297
+ "variant",
1298
+ "onClick",
1299
+ "onMouseDown"
1300
+ ]);
1301
+ return /* @__PURE__ */ jsx12(
1302
+ PlateContent,
1303
+ __spreadValues({
1304
+ className: cn(
1305
+ editorVariants({
1306
+ disabled,
1307
+ focused,
1308
+ variant
1309
+ }),
1310
+ className
1311
+ ),
1312
+ disableDefaultStyles: true,
1313
+ onClick: (e) => {
1314
+ if (variant === "comment") {
1315
+ e.stopPropagation();
1316
+ }
1317
+ onClick == null ? void 0 : onClick(e);
1318
+ },
1319
+ onMouseDown: (e) => {
1320
+ if (variant === "comment") {
1321
+ e.stopPropagation();
1322
+ }
1323
+ onMouseDown == null ? void 0 : onMouseDown(e);
1324
+ }
1325
+ }, props)
1326
+ );
1327
+ }
1328
+
1329
+ // src/ui/comment.tsx
1330
+ import { jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
1331
+ function Comment(props) {
1332
+ var _a;
1333
+ const {
1334
+ comment,
1335
+ discussionLength,
1336
+ documentContent,
1337
+ editingId,
1338
+ index,
1339
+ setEditingId,
1340
+ showDocumentContent = false,
1341
+ onEditorClick
1342
+ } = props;
1343
+ const editor = useEditorRef2();
1344
+ const discussions = usePluginOption3(discussionPlugin, "discussions");
1345
+ const userInfo = usePluginOption3(discussionPlugin, "user", comment.userId);
1346
+ const currentUserId = usePluginOption3(discussionPlugin, "currentUserId");
1347
+ const resolveDiscussion = (id) => {
1348
+ const updatedDiscussions = discussions.map((discussion) => {
1349
+ if (discussion.id === id) {
1350
+ return __spreadProps(__spreadValues({}, discussion), { isResolved: true });
1351
+ }
1352
+ return discussion;
1353
+ });
1354
+ editor.setOption(discussionPlugin, "discussions", updatedDiscussions);
1355
+ };
1356
+ const removeDiscussion = (id) => {
1357
+ const updatedDiscussions = discussions.filter((discussion) => discussion.id !== id);
1358
+ editor.setOption(discussionPlugin, "discussions", updatedDiscussions);
1359
+ };
1360
+ const updateComment = (input) => {
1361
+ const updatedDiscussions = discussions.map((discussion) => {
1362
+ if (discussion.id === input.discussionId) {
1363
+ const updatedComments = discussion.comments.map((comment2) => {
1364
+ if (comment2.id === input.id) {
1365
+ return __spreadProps(__spreadValues({}, comment2), {
1366
+ contentRich: input.contentRich,
1367
+ isEdited: true,
1368
+ updatedAt: /* @__PURE__ */ new Date()
1369
+ });
1370
+ }
1371
+ return comment2;
1372
+ });
1373
+ return __spreadProps(__spreadValues({}, discussion), { comments: updatedComments });
1374
+ }
1375
+ return discussion;
1376
+ });
1377
+ editor.setOption(discussionPlugin, "discussions", updatedDiscussions);
1378
+ };
1379
+ const { tf } = useEditorPlugin3(CommentPlugin);
1380
+ const isMyComment = currentUserId === comment.userId;
1381
+ const initialValue = comment.contentRich;
1382
+ const commentEditor = useCommentEditor(
1383
+ {
1384
+ id: comment.id,
1385
+ value: initialValue
1386
+ },
1387
+ [initialValue]
1388
+ );
1389
+ const onCancel = () => {
1390
+ setEditingId(null);
1391
+ commentEditor.tf.replaceNodes(initialValue, {
1392
+ at: [],
1393
+ children: true
1394
+ });
1395
+ };
1396
+ const onSave = () => {
1397
+ void updateComment({
1398
+ id: comment.id,
1399
+ contentRich: commentEditor.children,
1400
+ discussionId: comment.discussionId,
1401
+ isEdited: true
1402
+ });
1403
+ setEditingId(null);
1404
+ };
1405
+ const onResolveComment = () => {
1406
+ void resolveDiscussion(comment.discussionId);
1407
+ tf.comment.unsetMark({ id: comment.discussionId });
1408
+ };
1409
+ const isFirst = index === 0;
1410
+ const isLast = index === discussionLength - 1;
1411
+ const isEditing = editingId && editingId === comment.id;
1412
+ const [hovering, setHovering] = useState2(false);
1413
+ const [dropdownOpen, setDropdownOpen] = useState2(false);
1414
+ const truncatedDocumentContent = useMemo2(
1415
+ () => documentContent ? truncateSnippet(documentContent) : "",
1416
+ [documentContent]
1417
+ );
1418
+ return /* @__PURE__ */ jsxs5("div", { onMouseEnter: () => setHovering(true), onMouseLeave: () => setHovering(false), role: "presentation", children: [
1419
+ /* @__PURE__ */ jsxs5("div", { className: "relative flex items-center", children: [
1420
+ userInfo && /* @__PURE__ */ jsxs5(Avatar, { className: "size-6", children: [
1421
+ /* @__PURE__ */ jsx13(AvatarImage, { alt: userInfo.name, src: userInfo.avatarUrl }),
1422
+ /* @__PURE__ */ jsx13(AvatarFallback, { children: (_a = userInfo.name) == null ? void 0 : _a[0] })
1423
+ ] }),
1424
+ /* @__PURE__ */ jsx13("h4", { className: "mx-2 font-semibold text-sm leading-none", children: userInfo == null ? void 0 : userInfo.name }),
1425
+ /* @__PURE__ */ jsxs5("div", { className: "text-muted-foreground/80 text-xs leading-none", children: [
1426
+ /* @__PURE__ */ jsx13("span", { className: "mr-1", children: formatCommentDate(new Date(comment.createdAt)) }),
1427
+ comment.isEdited && /* @__PURE__ */ jsx13("span", { children: "(edited)" })
1428
+ ] }),
1429
+ isMyComment && (hovering || dropdownOpen) && /* @__PURE__ */ jsxs5("div", { className: "absolute top-0 right-0 flex space-x-1", children: [
1430
+ index === 0 && /* @__PURE__ */ jsx13(
1431
+ Button,
1432
+ {
1433
+ className: "h-6 p-1 text-muted-foreground",
1434
+ onClick: onResolveComment,
1435
+ type: "button",
1436
+ variant: "ghost",
1437
+ children: /* @__PURE__ */ jsx13(CheckIcon2, { className: "size-4" })
1438
+ }
1439
+ ),
1440
+ /* @__PURE__ */ jsx13(
1441
+ CommentMoreDropdown,
1442
+ {
1443
+ comment,
1444
+ dropdownOpen,
1445
+ onCloseAutoFocus: () => {
1446
+ setTimeout(() => {
1447
+ commentEditor.tf.focus({ edge: "endEditor" });
1448
+ }, 0);
1449
+ },
1450
+ onRemoveComment: () => {
1451
+ if (discussionLength === 1) {
1452
+ tf.comment.unsetMark({ id: comment.discussionId });
1453
+ void removeDiscussion(comment.discussionId);
1454
+ }
1455
+ },
1456
+ setDropdownOpen,
1457
+ setEditingId
1458
+ }
1459
+ )
1460
+ ] })
1461
+ ] }),
1462
+ isFirst && showDocumentContent && /* @__PURE__ */ jsxs5("div", { className: "relative mt-1 flex pl-8 text-sm text-subtle-foreground", children: [
1463
+ discussionLength > 1 && /* @__PURE__ */ jsx13("div", { className: "absolute top-1.25 left-3 h-full w-0.5 shrink-0 bg-muted" }),
1464
+ /* @__PURE__ */ jsx13("div", { className: "my-px w-0.5 shrink-0 bg-highlight" }),
1465
+ truncatedDocumentContent && /* @__PURE__ */ jsx13("div", { className: "ml-2", children: truncatedDocumentContent })
1466
+ ] }),
1467
+ /* @__PURE__ */ jsxs5("div", { className: "relative my-1 pl-6.5", children: [
1468
+ !isLast && /* @__PURE__ */ jsx13("div", { className: "absolute top-0 left-3 h-full w-0.5 shrink-0 bg-muted" }),
1469
+ /* @__PURE__ */ jsx13(Plate, { editor: commentEditor, readOnly: !isEditing, children: /* @__PURE__ */ jsxs5(EditorContainer, { variant: "comment", children: [
1470
+ /* @__PURE__ */ jsx13(Editor, { className: "w-auto grow", onClick: () => onEditorClick == null ? void 0 : onEditorClick(), variant: "comment" }),
1471
+ isEditing && /* @__PURE__ */ jsxs5("div", { className: "ml-auto flex shrink-0 gap-1", children: [
1472
+ /* @__PURE__ */ jsx13(
1473
+ Button,
1474
+ {
1475
+ className: "size-7",
1476
+ onClick: (e) => {
1477
+ e.stopPropagation();
1478
+ void onCancel();
1479
+ },
1480
+ size: "icon",
1481
+ variant: "ghost",
1482
+ children: /* @__PURE__ */ jsx13("div", { className: "flex size-5 shrink-0 items-center justify-center rounded-[50%] bg-primary/40", children: /* @__PURE__ */ jsx13(XIcon, { className: "size-3! stroke-[3px] text-background" }) })
1483
+ }
1484
+ ),
1485
+ /* @__PURE__ */ jsx13(
1486
+ Button,
1487
+ {
1488
+ onClick: (e) => {
1489
+ e.stopPropagation();
1490
+ void onSave();
1491
+ },
1492
+ size: "icon",
1493
+ variant: "ghost",
1494
+ children: /* @__PURE__ */ jsx13("div", { className: "flex size-5 shrink-0 items-center justify-center rounded-[50%] bg-brand", children: /* @__PURE__ */ jsx13(CheckIcon2, { className: "size-3! stroke-[3px] text-background" }) })
1495
+ }
1496
+ )
1497
+ ] })
1498
+ ] }) })
1499
+ ] })
1500
+ ] });
1501
+ }
1502
+ function CommentMoreDropdown(props) {
1503
+ const { comment, dropdownOpen, setDropdownOpen, setEditingId, onCloseAutoFocus, onRemoveComment } = props;
1504
+ const discussions = usePluginOption3(discussionPlugin, "discussions");
1505
+ const editor = useEditorRef2();
1506
+ const selectedEditCommentRef = React3.useRef(false);
1507
+ const onDeleteComment = React3.useCallback(() => {
1508
+ if (!comment.id) return alert("You are operating too quickly, please try again later.");
1509
+ const updatedDiscussions = discussions.map((discussion) => {
1510
+ if (discussion.id !== comment.discussionId) {
1511
+ return discussion;
1512
+ }
1513
+ const commentIndex = discussion.comments.findIndex((c) => c.id === comment.id);
1514
+ if (commentIndex === -1) {
1515
+ return discussion;
1516
+ }
1517
+ return __spreadProps(__spreadValues({}, discussion), {
1518
+ comments: [...discussion.comments.slice(0, commentIndex), ...discussion.comments.slice(commentIndex + 1)]
1519
+ });
1520
+ });
1521
+ editor.setOption(discussionPlugin, "discussions", updatedDiscussions);
1522
+ onRemoveComment == null ? void 0 : onRemoveComment();
1523
+ }, [comment.discussionId, comment.id, discussions, editor, onRemoveComment]);
1524
+ const onEditComment = React3.useCallback(() => {
1525
+ selectedEditCommentRef.current = true;
1526
+ if (!comment.id) return alert("You are operating too quickly, please try again later.");
1527
+ setEditingId(comment.id);
1528
+ }, [comment.id, setEditingId]);
1529
+ return /* @__PURE__ */ jsxs5(DropdownMenu, { modal: false, onOpenChange: setDropdownOpen, open: dropdownOpen, children: [
1530
+ /* @__PURE__ */ jsx13(DropdownMenuTrigger, { asChild: true, onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsx13(Button, { className: cn("h-6 p-1 text-muted-foreground"), variant: "ghost", children: /* @__PURE__ */ jsx13(MoreHorizontalIcon, { className: "size-4" }) }) }),
1531
+ /* @__PURE__ */ jsx13(
1532
+ DropdownMenuContent,
1533
+ {
1534
+ className: "w-48",
1535
+ onCloseAutoFocus: (e) => {
1536
+ if (selectedEditCommentRef.current) {
1537
+ onCloseAutoFocus == null ? void 0 : onCloseAutoFocus();
1538
+ selectedEditCommentRef.current = false;
1539
+ }
1540
+ return e.preventDefault();
1541
+ },
1542
+ children: /* @__PURE__ */ jsxs5(DropdownMenuGroup, { children: [
1543
+ /* @__PURE__ */ jsxs5(DropdownMenuItem, { onClick: onEditComment, children: [
1544
+ /* @__PURE__ */ jsx13(PencilIcon, { className: "size-4" }),
1545
+ "Edit comment"
1546
+ ] }),
1547
+ /* @__PURE__ */ jsxs5(DropdownMenuItem, { onClick: onDeleteComment, children: [
1548
+ /* @__PURE__ */ jsx13(TrashIcon, { className: "size-4" }),
1549
+ "Delete comment"
1550
+ ] })
1551
+ ] })
1552
+ }
1553
+ )
1554
+ ] });
1555
+ }
1556
+ var useCommentEditor = (options = {}, deps = []) => {
1557
+ const commentEditor = usePlateEditor(
1558
+ __spreadValues({
1559
+ id: "comment",
1560
+ plugins: BasicMarksKit,
1561
+ value: []
1562
+ }, options),
1563
+ deps
1564
+ );
1565
+ return commentEditor;
1566
+ };
1567
+ function CommentCreateForm({
1568
+ autoFocus = false,
1569
+ className,
1570
+ discussionId: discussionIdProp,
1571
+ focusOnMount = false
1572
+ }) {
1573
+ var _a;
1574
+ const discussions = usePluginOption3(discussionPlugin, "discussions");
1575
+ const editor = useEditorRef2();
1576
+ const commentId = useCommentId();
1577
+ const discussionId = discussionIdProp != null ? discussionIdProp : commentId;
1578
+ const userInfo = usePluginOption3(discussionPlugin, "currentUser");
1579
+ const [commentValue, setCommentValue] = React3.useState();
1580
+ const commentContent = useMemo2(
1581
+ () => commentValue ? NodeApi.string({ children: commentValue, type: "p" }) : "",
1582
+ [commentValue]
1583
+ );
1584
+ const commentEditor = useCommentEditor();
1585
+ useEffect2(() => {
1586
+ if (commentEditor && focusOnMount) {
1587
+ commentEditor.tf.focus();
1588
+ }
1589
+ }, [commentEditor, focusOnMount]);
1590
+ const onAddComment = React3.useCallback(() => {
1591
+ if (!commentValue) return;
1592
+ commentEditor.tf.reset();
1593
+ if (discussionId) {
1594
+ const discussion = discussions.find((d) => d.id === discussionId);
1595
+ if (!discussion) {
1596
+ const newDiscussion2 = {
1597
+ id: discussionId,
1598
+ comments: [
1599
+ {
1600
+ id: nanoid(),
1601
+ contentRich: commentValue,
1602
+ createdAt: /* @__PURE__ */ new Date(),
1603
+ discussionId,
1604
+ isEdited: false,
1605
+ userId: editor.getOption(discussionPlugin, "currentUserId")
1606
+ }
1607
+ ],
1608
+ createdAt: /* @__PURE__ */ new Date(),
1609
+ isResolved: false,
1610
+ userId: editor.getOption(discussionPlugin, "currentUserId")
1611
+ };
1612
+ editor.setOption(discussionPlugin, "discussions", [...discussions, newDiscussion2]);
1613
+ return;
1614
+ }
1615
+ const comment = {
1616
+ id: nanoid(),
1617
+ contentRich: commentValue,
1618
+ createdAt: /* @__PURE__ */ new Date(),
1619
+ discussionId,
1620
+ isEdited: false,
1621
+ userId: editor.getOption(discussionPlugin, "currentUserId")
1622
+ };
1623
+ const updatedDiscussion = __spreadProps(__spreadValues({}, discussion), {
1624
+ comments: [...discussion.comments, comment]
1625
+ });
1626
+ const updatedDiscussions = discussions.filter((d) => d.id !== discussionId).concat(updatedDiscussion);
1627
+ editor.setOption(discussionPlugin, "discussions", updatedDiscussions);
1628
+ return;
1629
+ }
1630
+ const commentsNodeEntry = editor.getApi(CommentPlugin).comment.nodes({ at: [], isDraft: true });
1631
+ if (commentsNodeEntry.length === 0) return;
1632
+ const documentContent = commentsNodeEntry.map(([node]) => node.text).join("");
1633
+ const _discussionId = nanoid();
1634
+ const newDiscussion = {
1635
+ id: _discussionId,
1636
+ comments: [
1637
+ {
1638
+ id: nanoid(),
1639
+ contentRich: commentValue,
1640
+ createdAt: /* @__PURE__ */ new Date(),
1641
+ discussionId: _discussionId,
1642
+ isEdited: false,
1643
+ userId: editor.getOption(discussionPlugin, "currentUserId")
1644
+ }
1645
+ ],
1646
+ createdAt: /* @__PURE__ */ new Date(),
1647
+ documentContent,
1648
+ isResolved: false,
1649
+ userId: editor.getOption(discussionPlugin, "currentUserId")
1650
+ };
1651
+ editor.setOption(discussionPlugin, "discussions", [...discussions, newDiscussion]);
1652
+ const id = newDiscussion.id;
1653
+ commentsNodeEntry.forEach(([_, path]) => {
1654
+ editor.tf.setNodes(
1655
+ {
1656
+ [getCommentKey(id)]: true
1657
+ },
1658
+ { at: path, split: true }
1659
+ );
1660
+ editor.tf.unsetNodes([getDraftCommentKey()], { at: path });
1661
+ });
1662
+ }, [commentValue, commentEditor.tf, discussionId, editor, discussions]);
1663
+ return /* @__PURE__ */ jsxs5("div", { className: cn("flex w-full", className), children: [
1664
+ /* @__PURE__ */ jsx13("div", { className: "mt-1 mr-1 shrink-0", children: /* @__PURE__ */ jsxs5(Avatar, { className: "size-5", children: [
1665
+ /* @__PURE__ */ jsx13(AvatarImage, { alt: userInfo == null ? void 0 : userInfo.name, src: userInfo == null ? void 0 : userInfo.avatarUrl }),
1666
+ /* @__PURE__ */ jsx13(AvatarFallback, { children: (_a = userInfo == null ? void 0 : userInfo.name) == null ? void 0 : _a[0] })
1667
+ ] }) }),
1668
+ /* @__PURE__ */ jsx13("div", { className: "relative flex grow gap-2", children: /* @__PURE__ */ jsx13(
1669
+ Plate,
1670
+ {
1671
+ editor: commentEditor,
1672
+ onChange: ({ value }) => {
1673
+ setCommentValue(value);
1674
+ },
1675
+ children: /* @__PURE__ */ jsxs5(EditorContainer, { variant: "comment", children: [
1676
+ /* @__PURE__ */ jsx13(
1677
+ Editor,
1678
+ {
1679
+ autoComplete: "off",
1680
+ autoFocus,
1681
+ className: "min-h-6.25 grow pt-0.5 pr-8",
1682
+ onKeyDown: (e) => {
1683
+ if (e.key === "Enter" && !e.shiftKey) {
1684
+ e.preventDefault();
1685
+ void onAddComment();
1686
+ }
1687
+ },
1688
+ placeholder: "Reply...",
1689
+ variant: "comment"
1690
+ }
1691
+ ),
1692
+ /* @__PURE__ */ jsx13(
1693
+ Button,
1694
+ {
1695
+ className: "absolute right-0 bottom-0 ml-auto shrink-0",
1696
+ disabled: commentContent.trim().length === 0,
1697
+ onClick: (e) => {
1698
+ e.stopPropagation();
1699
+ void onAddComment();
1700
+ },
1701
+ size: "icon",
1702
+ variant: "ghost",
1703
+ children: /* @__PURE__ */ jsx13("div", { className: "flex size-6 items-center justify-center rounded-full", children: /* @__PURE__ */ jsx13(ArrowUpIcon, {}) })
1704
+ }
1705
+ )
1706
+ ] })
1707
+ }
1708
+ ) })
1709
+ ] });
1710
+ }
1711
+ var SNIPPET_MAX_CHARS = 140;
1712
+ var SNIPPET_ELLIPSIS = "\u2026";
1713
+ var SNIPPET_WHITESPACE_RE = /\s+/g;
1714
+ var truncateSnippet = (input) => {
1715
+ const normalized = input.replace(SNIPPET_WHITESPACE_RE, " ").trim();
1716
+ if (normalized.length <= SNIPPET_MAX_CHARS) return normalized;
1717
+ const slice = normalized.slice(0, SNIPPET_MAX_CHARS);
1718
+ const lastSpace = slice.lastIndexOf(" ");
1719
+ const boundary = lastSpace > SNIPPET_MAX_CHARS * 0.6 ? lastSpace : slice.length;
1720
+ return `${slice.slice(0, boundary).trimEnd()}${SNIPPET_ELLIPSIS}`;
1721
+ };
1722
+ var formatCommentDate = (date) => {
1723
+ const now = /* @__PURE__ */ new Date();
1724
+ const diffMinutes = differenceInMinutes(now, date);
1725
+ const diffHours = differenceInHours(now, date);
1726
+ const diffDays = differenceInDays(now, date);
1727
+ if (diffMinutes < 60) {
1728
+ return `${diffMinutes}m`;
1729
+ }
1730
+ if (diffHours < 24) {
1731
+ return `${diffHours}h`;
1732
+ }
1733
+ if (diffDays < 2) {
1734
+ return `${diffDays}d`;
1735
+ }
1736
+ return format(date, "MM/dd/yyyy");
1737
+ };
1738
+
1739
+ // src/ui/block-suggestion.tsx
1740
+ import { jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
1741
+ var BLOCK_SUGGESTION = "__block__";
1742
+ var TYPE_TEXT_MAP = {
1743
+ [KEYS3.audio]: () => "Audio",
1744
+ [KEYS3.blockquote]: () => "Blockquote",
1745
+ [KEYS3.callout]: () => "Callout",
1746
+ [KEYS3.codeBlock]: () => "Code Block",
1747
+ [KEYS3.column]: () => "Column",
1748
+ [KEYS3.equation]: () => "Equation",
1749
+ [KEYS3.file]: () => "File",
1750
+ [KEYS3.h1]: () => "Heading 1",
1751
+ [KEYS3.h2]: () => "Heading 2",
1752
+ [KEYS3.h3]: () => "Heading 3",
1753
+ [KEYS3.h4]: () => "Heading 4",
1754
+ [KEYS3.h5]: () => "Heading 5",
1755
+ [KEYS3.h6]: () => "Heading 6",
1756
+ [KEYS3.hr]: () => "Horizontal Rule",
1757
+ [KEYS3.img]: () => "Image",
1758
+ [KEYS3.mediaEmbed]: () => "Media",
1759
+ [KEYS3.p]: (node) => {
1760
+ if ((node == null ? void 0 : node[KEYS3.listType]) === KEYS3.listTodo) return "Todo List";
1761
+ if ((node == null ? void 0 : node[KEYS3.listType]) === KEYS3.ol) return "Ordered List";
1762
+ if ((node == null ? void 0 : node[KEYS3.listType]) === KEYS3.ul) return "List";
1763
+ return "Paragraph";
1764
+ },
1765
+ [KEYS3.table]: () => "Table",
1766
+ [KEYS3.toc]: () => "Table of Contents",
1767
+ [KEYS3.toggle]: () => "Toggle",
1768
+ [KEYS3.video]: () => "Video"
1769
+ };
1770
+ function BlockSuggestionCard({
1771
+ idx,
1772
+ isLast,
1773
+ suggestion
1774
+ }) {
1775
+ var _a, _b, _c, _d, _e;
1776
+ const { api, editor } = useEditorPlugin4(SuggestionPlugin);
1777
+ const userInfo = usePluginOption4(discussionPlugin, "user", suggestion.userId);
1778
+ const accept = (suggestion2) => {
1779
+ api.suggestion.withoutSuggestions(() => {
1780
+ acceptSuggestion(editor, suggestion2);
1781
+ });
1782
+ };
1783
+ const reject = (suggestion2) => {
1784
+ api.suggestion.withoutSuggestions(() => {
1785
+ rejectSuggestion(editor, suggestion2);
1786
+ });
1787
+ };
1788
+ const [hovering, setHovering] = React4.useState(false);
1789
+ const suggestionText2Array = (text) => {
1790
+ if (text === BLOCK_SUGGESTION) return ["line breaks"];
1791
+ return text.split(BLOCK_SUGGESTION).filter(Boolean);
1792
+ };
1793
+ const [editingId, setEditingId] = React4.useState(null);
1794
+ return /* @__PURE__ */ jsxs6(
1795
+ "div",
1796
+ {
1797
+ className: "relative",
1798
+ onMouseEnter: () => setHovering(true),
1799
+ onMouseLeave: () => setHovering(false),
1800
+ role: "presentation",
1801
+ children: [
1802
+ /* @__PURE__ */ jsxs6("div", { className: "flex flex-col p-4", children: [
1803
+ /* @__PURE__ */ jsxs6("div", { className: "relative flex items-center", children: [
1804
+ userInfo && /* @__PURE__ */ jsxs6(Avatar, { className: "size-6", children: [
1805
+ /* @__PURE__ */ jsx14(AvatarImage, { alt: userInfo.name, src: userInfo.avatarUrl }),
1806
+ /* @__PURE__ */ jsx14(AvatarFallback, { children: (_a = userInfo.name) == null ? void 0 : _a[0] })
1807
+ ] }),
1808
+ /* @__PURE__ */ jsx14("h4", { className: "mx-2 font-semibold text-sm leading-none", children: userInfo == null ? void 0 : userInfo.name }),
1809
+ /* @__PURE__ */ jsx14("div", { className: "text-muted-foreground/80 text-xs leading-none", children: /* @__PURE__ */ jsx14("span", { className: "mr-1", children: formatCommentDate(new Date(suggestion.createdAt)) }) })
1810
+ ] }),
1811
+ /* @__PURE__ */ jsx14("div", { className: "relative mt-1 mb-4 pl-8", children: /* @__PURE__ */ jsxs6("div", { className: "flex flex-col gap-2", children: [
1812
+ suggestion.type === "remove" && suggestionText2Array((_b = suggestion.text) != null ? _b : "").map((text, i) => /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-2", children: [
1813
+ /* @__PURE__ */ jsx14("span", { className: "text-muted-foreground text-sm", children: "Delete:" }),
1814
+ /* @__PURE__ */ jsx14("span", { className: "text-sm", children: text })
1815
+ ] }, `${suggestion.suggestionId}-remove-${i}`)),
1816
+ suggestion.type === "insert" && suggestionText2Array((_c = suggestion.newText) != null ? _c : "").map((text, i) => /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-2", children: [
1817
+ /* @__PURE__ */ jsx14("span", { className: "text-muted-foreground text-sm", children: "Add:" }),
1818
+ /* @__PURE__ */ jsx14("span", { className: "text-sm", children: text || "line breaks" })
1819
+ ] }, `${suggestion.suggestionId}-insert-${i}`)),
1820
+ suggestion.type === "replace" && /* @__PURE__ */ jsxs6("div", { className: "flex flex-col gap-2", children: [
1821
+ suggestionText2Array((_d = suggestion.newText) != null ? _d : "").map((text, i) => /* @__PURE__ */ jsxs6("div", { className: "flex items-center text-brand/80", children: [
1822
+ /* @__PURE__ */ jsx14("span", { className: "text-sm", children: "With:" }),
1823
+ /* @__PURE__ */ jsxs6("span", { className: "text-sm", children: [
1824
+ '"',
1825
+ text || "line breaks",
1826
+ '"'
1827
+ ] })
1828
+ ] }, `${suggestion.suggestionId}-replace-new-${i}`)),
1829
+ suggestionText2Array((_e = suggestion.text) != null ? _e : "").map((text, i) => /* @__PURE__ */ jsxs6("div", { className: "flex items-center", children: [
1830
+ /* @__PURE__ */ jsx14("span", { className: "text-muted-foreground text-sm", children: i === 0 ? "Replace:" : "Delete:" }),
1831
+ /* @__PURE__ */ jsxs6("span", { className: "text-sm", children: [
1832
+ '"',
1833
+ text || "line breaks",
1834
+ '"'
1835
+ ] })
1836
+ ] }, `${suggestion.suggestionId}-replace-old-${i}`))
1837
+ ] }),
1838
+ suggestion.type === "update" && /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-2", children: [
1839
+ /* @__PURE__ */ jsxs6("span", { className: "text-muted-foreground text-sm", children: [
1840
+ Object.keys(suggestion.properties).map((key) => /* @__PURE__ */ jsxs6("span", { children: [
1841
+ "Un",
1842
+ key
1843
+ ] }, key)),
1844
+ Object.keys(suggestion.newProperties).map((key) => /* @__PURE__ */ jsx14("span", { children: key.charAt(0).toUpperCase() + key.slice(1) }, key))
1845
+ ] }),
1846
+ /* @__PURE__ */ jsxs6("span", { className: "text-sm", children: [
1847
+ '"',
1848
+ suggestion.newText,
1849
+ '"'
1850
+ ] })
1851
+ ] })
1852
+ ] }) }),
1853
+ suggestion.comments.map((comment, index) => {
1854
+ var _a2;
1855
+ return /* @__PURE__ */ jsx14(
1856
+ Comment,
1857
+ {
1858
+ comment,
1859
+ discussionLength: suggestion.comments.length,
1860
+ documentContent: "__suggestion__",
1861
+ editingId,
1862
+ index,
1863
+ setEditingId
1864
+ },
1865
+ (_a2 = comment.id) != null ? _a2 : index
1866
+ );
1867
+ }),
1868
+ hovering && /* @__PURE__ */ jsxs6("div", { className: "absolute top-4 right-4 flex gap-2", children: [
1869
+ /* @__PURE__ */ jsx14(Button, { className: "h-6 p-1 text-muted-foreground", onClick: () => accept(suggestion), variant: "ghost", children: /* @__PURE__ */ jsx14(CheckIcon3, { className: "size-4" }) }),
1870
+ /* @__PURE__ */ jsx14(Button, { className: "h-6 p-1 text-muted-foreground", onClick: () => reject(suggestion), variant: "ghost", children: /* @__PURE__ */ jsx14(XIcon2, { className: "size-4" }) })
1871
+ ] }),
1872
+ /* @__PURE__ */ jsx14(CommentCreateForm, { discussionId: suggestion.suggestionId })
1873
+ ] }),
1874
+ !isLast && /* @__PURE__ */ jsx14("div", { className: "h-px w-full bg-muted" })
1875
+ ]
1876
+ },
1877
+ `${suggestion.suggestionId}-${idx}`
1878
+ );
1879
+ }
1880
+ var useResolveSuggestion = (suggestionNodes, blockPath) => {
1881
+ const discussions = usePluginOption4(discussionPlugin, "discussions");
1882
+ const { api, editor, getOption, setOption } = useEditorPlugin4(suggestionPlugin);
1883
+ useEffect3(() => {
1884
+ suggestionNodes.forEach(([node]) => {
1885
+ var _a;
1886
+ const id = api.suggestion.nodeId(node);
1887
+ const map = getOption("uniquePathMap");
1888
+ if (!id) return;
1889
+ const previousPath = map.get(id);
1890
+ if (PathApi.isPath(previousPath)) {
1891
+ const nodes = api.suggestion.node({
1892
+ id,
1893
+ at: previousPath,
1894
+ isText: true
1895
+ });
1896
+ const parentNode = api.node(previousPath);
1897
+ let lineBreakId = null;
1898
+ if (parentNode && ElementApi.isElement(parentNode[0])) {
1899
+ lineBreakId = (_a = api.suggestion.nodeId(parentNode[0])) != null ? _a : null;
1900
+ }
1901
+ if (!nodes && lineBreakId !== id) {
1902
+ setOption("uniquePathMap", new Map(map).set(id, blockPath));
1903
+ return;
1904
+ }
1905
+ return;
1906
+ }
1907
+ setOption("uniquePathMap", new Map(map).set(id, blockPath));
1908
+ });
1909
+ }, [api, blockPath, getOption, setOption, suggestionNodes]);
1910
+ return React4.useMemo(() => {
1911
+ const map = getOption("uniquePathMap");
1912
+ if (suggestionNodes.length === 0) return [];
1913
+ const suggestionIds = new Set(
1914
+ suggestionNodes.flatMap(([node]) => {
1915
+ if (TextApi.isText(node)) {
1916
+ const dataList = api.suggestion.dataList(node);
1917
+ const includeUpdate = dataList.some((data) => data.type === "update");
1918
+ if (!includeUpdate) return api.suggestion.nodeId(node);
1919
+ return dataList.filter((data) => data.type === "update").map((d) => d.id);
1920
+ }
1921
+ if (ElementApi.isElement(node)) {
1922
+ return api.suggestion.nodeId(node);
1923
+ }
1924
+ return null;
1925
+ }).filter(Boolean)
1926
+ );
1927
+ const res = [];
1928
+ suggestionIds.forEach((id) => {
1929
+ var _a;
1930
+ if (!id) return;
1931
+ const path = map.get(id);
1932
+ if (!path || !PathApi.isPath(path)) return;
1933
+ if (!PathApi.equals(path, blockPath)) return;
1934
+ const entries = [
1935
+ ...editor.api.nodes({
1936
+ at: [],
1937
+ mode: "all",
1938
+ match: (n) => n[KEYS3.suggestion] && n[getSuggestionKey(id)] || api.suggestion.nodeId(n) === id
1939
+ })
1940
+ ];
1941
+ entries.sort(([, path1], [, path2]) => PathApi.isChild(path1, path2) ? -1 : 1);
1942
+ let newText = "";
1943
+ let text = "";
1944
+ let properties = {};
1945
+ let newProperties = {};
1946
+ entries.forEach(([node]) => {
1947
+ if (TextApi.isText(node)) {
1948
+ const dataList = api.suggestion.dataList(node);
1949
+ dataList.forEach((data) => {
1950
+ if (data.id !== id) return;
1951
+ switch (data.type) {
1952
+ case "insert": {
1953
+ newText += node.text;
1954
+ break;
1955
+ }
1956
+ case "remove": {
1957
+ text += node.text;
1958
+ break;
1959
+ }
1960
+ case "update": {
1961
+ properties = __spreadValues(__spreadValues({}, properties), data.properties);
1962
+ newProperties = __spreadValues(__spreadValues({}, newProperties), data.newProperties);
1963
+ newText += node.text;
1964
+ break;
1965
+ }
1966
+ }
1967
+ });
1968
+ } else {
1969
+ const lineBreakData = api.suggestion.isBlockSuggestion(node) ? node.suggestion : void 0;
1970
+ if ((lineBreakData == null ? void 0 : lineBreakData.id) !== keyId2SuggestionId(id)) return;
1971
+ if (lineBreakData.type === "insert") {
1972
+ newText += lineBreakData.isLineBreak ? BLOCK_SUGGESTION : BLOCK_SUGGESTION + TYPE_TEXT_MAP[node.type](node);
1973
+ } else if (lineBreakData.type === "remove") {
1974
+ text += lineBreakData.isLineBreak ? BLOCK_SUGGESTION : BLOCK_SUGGESTION + TYPE_TEXT_MAP[node.type](node);
1975
+ }
1976
+ }
1977
+ });
1978
+ if (entries.length === 0) return;
1979
+ const nodeData = api.suggestion.suggestionData(entries[0][0]);
1980
+ if (!nodeData) return;
1981
+ const comments = ((_a = discussions.find((s) => s.id === id)) == null ? void 0 : _a.comments) || [];
1982
+ const createdAt = new Date(nodeData.createdAt);
1983
+ const keyId = getSuggestionKey(id);
1984
+ if (nodeData.type === "update") {
1985
+ res.push({
1986
+ comments,
1987
+ createdAt,
1988
+ keyId,
1989
+ newProperties,
1990
+ newText,
1991
+ properties,
1992
+ suggestionId: keyId2SuggestionId(id),
1993
+ type: "update",
1994
+ userId: nodeData.userId
1995
+ });
1996
+ return;
1997
+ }
1998
+ if (newText.length > 0 && text.length > 0) {
1999
+ res.push({
2000
+ comments,
2001
+ createdAt,
2002
+ keyId,
2003
+ newText,
2004
+ suggestionId: keyId2SuggestionId(id),
2005
+ text,
2006
+ type: "replace",
2007
+ userId: nodeData.userId
2008
+ });
2009
+ return;
2010
+ }
2011
+ if (newText.length > 0) {
2012
+ res.push({
2013
+ comments,
2014
+ createdAt,
2015
+ keyId,
2016
+ newText,
2017
+ suggestionId: keyId2SuggestionId(id),
2018
+ type: "insert",
2019
+ userId: nodeData.userId
2020
+ });
2021
+ return;
2022
+ }
2023
+ if (text.length > 0) {
2024
+ res.push({
2025
+ comments,
2026
+ createdAt,
2027
+ keyId,
2028
+ suggestionId: keyId2SuggestionId(id),
2029
+ text,
2030
+ type: "remove",
2031
+ userId: nodeData.userId
2032
+ });
2033
+ }
2034
+ });
2035
+ return res;
2036
+ }, [api.suggestion, blockPath, discussions, editor.api, getOption, suggestionNodes]);
2037
+ };
2038
+ var isResolvedSuggestion = (suggestion) => "suggestionId" in suggestion;
2039
+
2040
+ // src/ui/floating-discussion.tsx
2041
+ import { Fragment as Fragment2, jsx as jsx15, jsxs as jsxs7 } from "react/jsx-runtime";
2042
+ function FloatingDiscussion() {
2043
+ const mounted = useEditorMounted();
2044
+ const isOverlapWithEditor = usePluginOption5(commentPlugin, "isOverlapWithEditor");
2045
+ const adapter = useEditorAdapter();
2046
+ if (!mounted || isOverlapWithEditor) return null;
2047
+ if (adapter.comments !== null) return null;
2048
+ return /* @__PURE__ */ jsx15(FloatingDiscussionContent, {});
2049
+ }
2050
+ var getCommentTop = (editor, {
2051
+ node,
2052
+ relativeElement,
2053
+ topOffset = 30
2054
+ }) => {
2055
+ const commentLeafDomNode = editor.api.toDOMNode(node);
2056
+ if (!commentLeafDomNode) return 0;
2057
+ const relativeElementRect = relativeElement.getBoundingClientRect();
2058
+ const scrollTop = relativeElement.scrollTop;
2059
+ const commentLeafRect = commentLeafDomNode.getBoundingClientRect();
2060
+ const top = commentLeafRect.top - relativeElementRect.top + scrollTop;
2061
+ return top > topOffset ? top - topOffset : 0;
2062
+ };
2063
+ var updateActiveBelow = (topMap, domMap, activeId) => {
2064
+ var _a, _b;
2065
+ const discussionArray = Object.entries(topMap).map(([id, top]) => ({ id, top })).sort((a, b) => a.top - b.top);
2066
+ const activeIndex = discussionArray.findIndex(({ id }) => id === activeId);
2067
+ if (activeIndex === -1 || activeIndex === discussionArray.length - 1) return topMap;
2068
+ const activeElement = discussionArray[activeIndex];
2069
+ const start = activeElement.top;
2070
+ const end = start + ((_b = (_a = domMap[activeId]) == null ? void 0 : _a.clientHeight) != null ? _b : 100);
2071
+ const nextElement = discussionArray[activeIndex + 1];
2072
+ const nextStart = nextElement.top;
2073
+ if (nextStart <= end) {
2074
+ const offset = end - nextStart + 10;
2075
+ for (let i = activeIndex + 1; i < discussionArray.length; i++) {
2076
+ discussionArray[i].top += offset;
2077
+ }
2078
+ return Object.fromEntries(discussionArray.map((d) => [d.id, d.top]));
2079
+ }
2080
+ return topMap;
2081
+ };
2082
+ var updateActiveTop = (topMap, domMap, activeId, targetTop) => {
2083
+ var _a, _b, _c, _d, _e, _f;
2084
+ const discussionArray = Object.entries(topMap).map(([id, top]) => ({ id, top })).sort((a, b) => a.top - b.top);
2085
+ const index = discussionArray.findIndex(({ id }) => id === activeId);
2086
+ if (index === -1) return topMap;
2087
+ const currentTop = discussionArray[index].top;
2088
+ const diff = targetTop - currentTop;
2089
+ discussionArray[index].top = targetTop;
2090
+ if (diff < 0) {
2091
+ for (let i = index - 1; i >= 0; i--) {
2092
+ const currentElement = discussionArray[i];
2093
+ const nextElement = discussionArray[i + 1];
2094
+ const elementHeight = (_b = (_a = domMap[currentElement.id]) == null ? void 0 : _a.clientHeight) != null ? _b : 100;
2095
+ if (currentElement.top + elementHeight + 10 > nextElement.top) {
2096
+ currentElement.top = nextElement.top - elementHeight - 10;
2097
+ } else {
2098
+ break;
2099
+ }
2100
+ }
2101
+ } else {
2102
+ const activeHeight = (_d = (_c = domMap[activeId]) == null ? void 0 : _c.clientHeight) != null ? _d : 100;
2103
+ let activeBottom = targetTop + activeHeight + 10;
2104
+ for (let i = index + 1; i < discussionArray.length; i++) {
2105
+ if (discussionArray[i].top < activeBottom) {
2106
+ discussionArray[i].top = activeBottom;
2107
+ activeBottom = discussionArray[i].top + ((_f = (_e = domMap[discussionArray[i].id]) == null ? void 0 : _e.clientHeight) != null ? _f : 100) + 10;
2108
+ } else {
2109
+ break;
2110
+ }
2111
+ }
2112
+ }
2113
+ return Object.fromEntries(discussionArray.map((d) => [d.id, d.top]));
2114
+ };
2115
+ var updateTopCommenting = (topMap, domMap) => {
2116
+ var _a, _b, _c, _d, _e, _f;
2117
+ const discussionArray = Object.entries(topMap).map(([id, topDistance]) => ({ id, topDistance })).sort((a, b) => a.topDistance - b.topDistance);
2118
+ const index = discussionArray.findIndex(({ id }) => id === getDraftCommentKey2());
2119
+ if (index === -1) return topMap;
2120
+ const targetTopDistance = discussionArray[index].topDistance;
2121
+ let moveDistance = 0;
2122
+ for (let i = 0; i < discussionArray.length; i++) {
2123
+ const current = discussionArray[i];
2124
+ const currentHeight2 = (_b = (_a = domMap[current.id]) == null ? void 0 : _a.clientHeight) != null ? _b : 100;
2125
+ if (i < index) {
2126
+ const minRequiredSpace = targetTopDistance - (currentHeight2 + 10);
2127
+ if (current.topDistance > minRequiredSpace) {
2128
+ const distance = current.topDistance - minRequiredSpace;
2129
+ moveDistance = Math.max(moveDistance, distance);
2130
+ }
2131
+ }
2132
+ }
2133
+ if (moveDistance > 0) {
2134
+ for (let i = 0; i < index; i++) {
2135
+ discussionArray[i].topDistance -= moveDistance;
2136
+ }
2137
+ }
2138
+ const currentHeight = (_d = (_c = domMap[discussionArray[index].id]) == null ? void 0 : _c.clientHeight) != null ? _d : 100;
2139
+ const currentBottom = targetTopDistance + currentHeight + 10;
2140
+ if (index + 1 < discussionArray.length) {
2141
+ const nextElement = discussionArray[index + 1];
2142
+ if (nextElement.topDistance < currentBottom) {
2143
+ let currentTop = currentBottom;
2144
+ for (let i = index + 1; i < discussionArray.length; i++) {
2145
+ const element = discussionArray[i];
2146
+ if (element.topDistance < currentTop) {
2147
+ element.topDistance = currentTop;
2148
+ const elementHeight = (_f = (_e = domMap[element.id]) == null ? void 0 : _e.clientHeight) != null ? _f : 100;
2149
+ currentTop += elementHeight + 10;
2150
+ } else {
2151
+ break;
2152
+ }
2153
+ }
2154
+ }
2155
+ }
2156
+ return Object.fromEntries(discussionArray.map((d) => [d.id, d.topDistance]));
2157
+ };
2158
+ var resolveOverlappingTop = (topMap, domMap) => {
2159
+ const discussionArray = Object.entries(topMap).map(([id, topDistance]) => ({ id, topDistance })).sort((a, b) => a.topDistance - b.topDistance);
2160
+ for (let i = 1; i < discussionArray.length; i++) {
2161
+ const currentDiscussion = discussionArray[i];
2162
+ const currentElement = domMap[currentDiscussion.id];
2163
+ if (!currentElement) continue;
2164
+ const currentStart = currentDiscussion.topDistance;
2165
+ const currentEnd = currentStart + currentElement.clientHeight;
2166
+ for (let j = 0; j < i; j++) {
2167
+ const previousDiscussion = discussionArray[j];
2168
+ const previousElement = domMap[previousDiscussion.id];
2169
+ if (!previousElement) continue;
2170
+ const previousStart = previousDiscussion.topDistance;
2171
+ const previousEnd = previousStart + previousElement.clientHeight;
2172
+ if (currentStart <= previousEnd && currentEnd >= previousStart || previousStart <= currentEnd && previousEnd >= currentStart) {
2173
+ currentDiscussion.topDistance = previousEnd + 10;
2174
+ i--;
2175
+ break;
2176
+ }
2177
+ }
2178
+ }
2179
+ return Object.fromEntries(discussionArray.map((d) => [d.id, d.topDistance]));
2180
+ };
2181
+ var useCommentingNode = () => useEditorSelector((editor) => {
2182
+ var _a;
2183
+ if (!editor.selection || editor.api.isExpanded()) return;
2184
+ return (_a = editor.api.node({
2185
+ match: (n) => TextApi2.isText(n) && n[KEYS4.comment] && n[getDraftCommentKey2()]
2186
+ })) == null ? void 0 : _a[0];
2187
+ }, []);
2188
+ function FloatingDiscussionContent() {
2189
+ var _a;
2190
+ const editorContainerRef = useEditorContainerRef();
2191
+ const editor = useEditorRef3();
2192
+ const commentApi = editor.getApi(commentPlugin);
2193
+ const suggestionApi = editor.getApi(suggestionPlugin);
2194
+ const activeCommentId = usePluginOption5(commentPlugin, "activeId");
2195
+ const activeSuggestionId = usePluginOption5(suggestionPlugin, "activeId");
2196
+ const activeId = activeCommentId != null ? activeCommentId : activeSuggestionId;
2197
+ const isOverlapWithEditor = usePluginOption5(commentPlugin, "isOverlapWithEditor");
2198
+ const updateTimestamp = usePluginOption5(commentPlugin, "updateTimestamp");
2199
+ const discussions = usePluginOption5(discussionPlugin, "discussions");
2200
+ const domRef = React5.useRef({});
2201
+ const topRef = React5.useRef({});
2202
+ const [, forceUpdate] = useReducer((x) => x + 1, 0);
2203
+ const commentingNode = useCommentingNode();
2204
+ const version = useEditorVersion();
2205
+ const wasCommentingRef = useRef4(false);
2206
+ useEffect4(() => {
2207
+ const isCommenting = activeCommentId === getDraftCommentKey2();
2208
+ if (wasCommentingRef.current && !isCommenting) {
2209
+ editor.tf.unsetNodes(getDraftCommentKey2(), {
2210
+ at: [],
2211
+ mode: "lowest",
2212
+ match: (node) => node[getDraftCommentKey2()] === true
2213
+ });
2214
+ }
2215
+ wasCommentingRef.current = isCommenting;
2216
+ }, [activeCommentId, editor]);
2217
+ useEffect4(() => {
2218
+ return () => {
2219
+ if (!wasCommentingRef.current) return;
2220
+ editor.tf.unsetNodes(getDraftCommentKey2(), {
2221
+ at: [],
2222
+ mode: "lowest",
2223
+ match: (node) => node[getDraftCommentKey2()] === true
2224
+ });
2225
+ wasCommentingRef.current = false;
2226
+ };
2227
+ }, [editor]);
2228
+ const suggestionEntriesMap = useRef4({});
2229
+ useEffect4(() => {
2230
+ suggestionEntriesMap.current = {};
2231
+ const allSuggestionNodes = suggestionApi.suggestion.nodes({ at: [] }).filter(([node]) => !node[getTransientSuggestionKey()]);
2232
+ const suggestionIds = new Set(
2233
+ allSuggestionNodes.flatMap(([node]) => {
2234
+ if (TextApi2.isText(node)) {
2235
+ const dataList = suggestionApi.suggestion.dataList(node);
2236
+ const includeUpdate = dataList.some((data) => data.type === "update");
2237
+ if (!includeUpdate) return suggestionApi.suggestion.nodeId(node);
2238
+ return dataList.filter((data) => data.type === "update").map((d) => d.id);
2239
+ }
2240
+ if (ElementApi2.isElement(node)) {
2241
+ return suggestionApi.suggestion.nodeId(node);
2242
+ }
2243
+ return null;
2244
+ }).filter(Boolean)
2245
+ );
2246
+ suggestionIds.forEach((id) => {
2247
+ if (!id) return;
2248
+ const entries = [
2249
+ ...editor.api.nodes({
2250
+ at: [],
2251
+ mode: "all",
2252
+ match: (n) => n[KEYS4.suggestion] && n[getSuggestionKey2(id)] || suggestionApi.suggestion.nodeId(n) === id
2253
+ })
2254
+ ];
2255
+ suggestionEntriesMap.current[id] = entries;
2256
+ });
2257
+ }, [editor, suggestionApi.suggestion, version]);
2258
+ const suggestionList = Object.entries(suggestionEntriesMap.current).map(([id, entries]) => ({
2259
+ id,
2260
+ entries
2261
+ }));
2262
+ const renderFloatingDiscussion = React5.useCallback(() => {
2263
+ if (isOverlapWithEditor) return;
2264
+ topRef.current = {};
2265
+ discussions.forEach((discussion) => {
2266
+ if (discussion.isResolved || !commentApi.comment.has({ id: discussion.id })) return;
2267
+ const commentLeafEntry = commentApi.comment.node({
2268
+ id: discussion.id,
2269
+ at: []
2270
+ });
2271
+ if (!commentLeafEntry) return;
2272
+ const commentLeaf = commentLeafEntry[0];
2273
+ if (!editorContainerRef.current) return;
2274
+ const topDistance = getCommentTop(editor, {
2275
+ node: commentLeaf,
2276
+ relativeElement: editorContainerRef.current
2277
+ });
2278
+ topRef.current[discussion.id] = topDistance;
2279
+ });
2280
+ suggestionList.forEach(({ id, entries }) => {
2281
+ if (!id || !editorContainerRef.current) return;
2282
+ const topDistance = getCommentTop(editor, {
2283
+ node: entries[0][0],
2284
+ relativeElement: editorContainerRef.current
2285
+ });
2286
+ topRef.current[id] = topDistance;
2287
+ });
2288
+ topRef.current = resolveOverlappingTop(topRef.current, domRef.current);
2289
+ forceUpdate();
2290
+ }, [discussions.length, suggestionList.length, editorContainerRef, isOverlapWithEditor]);
2291
+ const renderFloatingCreateForm = React5.useCallback(() => {
2292
+ if (!commentingNode || activeId !== getDraftCommentKey2() || !editorContainerRef.current) return;
2293
+ const topDistance = getCommentTop(editor, {
2294
+ node: commentingNode,
2295
+ relativeElement: editorContainerRef.current
2296
+ });
2297
+ topRef.current[getDraftCommentKey2()] = topDistance;
2298
+ topRef.current = updateTopCommenting(topRef.current, domRef.current);
2299
+ forceUpdate();
2300
+ }, [activeId, commentingNode, editor, editorContainerRef]);
2301
+ const debouncedUpdateFloat = useDebouncedCallback(renderFloatingDiscussion, 500);
2302
+ useEffect4(() => {
2303
+ if (updateTimestamp) {
2304
+ debouncedUpdateFloat();
2305
+ }
2306
+ }, [debouncedUpdateFloat, updateTimestamp]);
2307
+ useEffect4(() => {
2308
+ if (!discussions) return;
2309
+ setTimeout(() => {
2310
+ renderFloatingDiscussion();
2311
+ }, 0);
2312
+ }, [discussions, renderFloatingDiscussion]);
2313
+ useEffect4(() => {
2314
+ if (!activeId || !domRef.current[activeId]) return;
2315
+ const resizeObserver = new ResizeObserver(() => {
2316
+ topRef.current = updateActiveBelow(topRef.current, domRef.current, activeId);
2317
+ forceUpdate();
2318
+ });
2319
+ resizeObserver.observe(domRef.current[activeId]);
2320
+ return () => {
2321
+ resizeObserver.disconnect();
2322
+ };
2323
+ }, [activeId]);
2324
+ useEffect4(() => {
2325
+ var _a2;
2326
+ if (!activeId) {
2327
+ return renderFloatingDiscussion();
2328
+ }
2329
+ const activeNode = commentApi.comment.node({ id: activeId, at: [] });
2330
+ const activeSuggestionNode = suggestionApi.suggestion.node({
2331
+ id: activeId,
2332
+ at: [],
2333
+ isText: true
2334
+ });
2335
+ if (!activeNode && !activeSuggestionNode || !editorContainerRef.current) return;
2336
+ const activeNodeValue = (_a2 = activeNode == null ? void 0 : activeNode[0]) != null ? _a2 : activeSuggestionNode == null ? void 0 : activeSuggestionNode[0];
2337
+ if (!activeNodeValue) return;
2338
+ topRef.current = updateActiveTop(
2339
+ topRef.current,
2340
+ domRef.current,
2341
+ activeId,
2342
+ getCommentTop(editor, {
2343
+ node: activeNodeValue,
2344
+ relativeElement: editorContainerRef.current
2345
+ })
2346
+ );
2347
+ forceUpdate();
2348
+ }, [
2349
+ activeId,
2350
+ editor,
2351
+ commentingNode,
2352
+ editorContainerRef,
2353
+ renderFloatingDiscussion,
2354
+ commentApi.comment,
2355
+ suggestionApi.suggestion
2356
+ ]);
2357
+ useEffect4(() => {
2358
+ if (!commentingNode || !domRef.current[getDraftCommentKey2()]) {
2359
+ return;
2360
+ }
2361
+ const draftElement = domRef.current[getDraftCommentKey2()];
2362
+ if (!draftElement) return;
2363
+ const resizeObserver = new ResizeObserver(() => {
2364
+ renderFloatingCreateForm();
2365
+ });
2366
+ resizeObserver.observe(draftElement);
2367
+ return () => {
2368
+ resizeObserver.disconnect();
2369
+ };
2370
+ }, [commentingNode, editor, editorContainerRef, renderFloatingCreateForm, renderFloatingDiscussion]);
2371
+ useEffect4(() => {
2372
+ if (!isOverlapWithEditor) {
2373
+ renderFloatingDiscussion();
2374
+ }
2375
+ }, [isOverlapWithEditor, renderFloatingDiscussion]);
2376
+ return /* @__PURE__ */ jsxs7(Fragment2, { children: [
2377
+ commentingNode && /* @__PURE__ */ jsx15(
2378
+ "div",
2379
+ {
2380
+ className: "absolute right-20 w-72 cursor-pointer rounded-lg border bg-popover p-3 transition-transform duration-200",
2381
+ ref: (el) => {
2382
+ domRef.current[getDraftCommentKey2()] = el;
2383
+ },
2384
+ style: {
2385
+ top: (_a = topRef.current[getDraftCommentKey2()]) != null ? _a : -9999
2386
+ },
2387
+ children: /* @__PURE__ */ jsx15(CommentCreateForm, { focusOnMount: true })
2388
+ }
2389
+ ),
2390
+ discussions.map(
2391
+ (discussion) => {
2392
+ var _a2;
2393
+ return !discussion.isResolved && commentApi.comment.has({ id: discussion.id }) && /* @__PURE__ */ jsx15(
2394
+ FloatingCommentsContent,
2395
+ {
2396
+ discussion,
2397
+ domRef,
2398
+ ref: (el) => {
2399
+ domRef.current[discussion.id] = el;
2400
+ },
2401
+ top: (_a2 = topRef.current[discussion.id]) != null ? _a2 : 0
2402
+ },
2403
+ discussion.id
2404
+ );
2405
+ }
2406
+ ),
2407
+ suggestionList.map(
2408
+ ({ id, entries }) => {
2409
+ var _a2;
2410
+ return id && /* @__PURE__ */ jsx15(
2411
+ FloatingSuggestionContent,
2412
+ {
2413
+ entries,
2414
+ id,
2415
+ ref: (el) => {
2416
+ domRef.current[id] = el;
2417
+ },
2418
+ top: (_a2 = topRef.current[id]) != null ? _a2 : 0
2419
+ },
2420
+ id
2421
+ );
2422
+ }
2423
+ )
2424
+ ] });
2425
+ }
2426
+ function FloatingCommentsContent({ discussion, ref, top }) {
2427
+ const editor = useEditorRef3();
2428
+ const { activeId, hoverId } = usePluginOptions(commentPlugin, ({ activeId: activeId2, hoverId: hoverId2 }) => ({
2429
+ activeId: activeId2,
2430
+ hoverId: hoverId2
2431
+ }));
2432
+ const [editingId, setEditingId] = React5.useState(null);
2433
+ const setHoverId = (id) => {
2434
+ var _a;
2435
+ if ((_a = document.activeElement) == null ? void 0 : _a.closest("[data-radix-menu-content]")) return;
2436
+ editor.setOption(commentPlugin, "hoverId", id);
2437
+ };
2438
+ const highlightDiscussion = (editor2, id) => {
2439
+ editor2.setOption(commentPlugin, "activeId", id);
2440
+ editor2.setOption(suggestionPlugin, "activeId", null);
2441
+ const leaf = editor2.api.node({
2442
+ at: [],
2443
+ match: (n) => TextApi2.isText(n) && n[KEYS4.comment] && editor2.getApi(commentPlugin).comment.nodeId(n) === id
2444
+ });
2445
+ if (!leaf) return;
2446
+ const parent = NodeApi2.get(editor2, leaf[1].slice(0, 1));
2447
+ if (parent) {
2448
+ editor2.getApi(BlockSelectionPlugin).blockSelection.addSelectedRow(parent.id, {
2449
+ clear: false,
2450
+ delay: 1e3
2451
+ });
2452
+ }
2453
+ };
2454
+ const lastComment = discussion.comments.at(-1);
2455
+ return /* @__PURE__ */ jsxs7(
2456
+ "div",
2457
+ {
2458
+ className: cn(
2459
+ "absolute right-20 z-10 w-72 animate-fade-in cursor-pointer rounded-lg border bg-popover p-3 transition-transform duration-200",
2460
+ "data-[hover=true]:data-[active=false]:-translate-x-2 data-[hover=true]:data-[active=false]:bg-muted",
2461
+ "data-[active=true]:-translate-x-2"
2462
+ ),
2463
+ "data-active": activeId === discussion.id,
2464
+ "data-discussion-id": discussion.id,
2465
+ "data-hover": hoverId === discussion.id,
2466
+ onClick: () => highlightDiscussion(editor, discussion.id),
2467
+ onMouseEnter: () => setHoverId(discussion.id),
2468
+ onMouseLeave: () => setHoverId(null),
2469
+ ref,
2470
+ role: "presentation",
2471
+ style: {
2472
+ top
2473
+ },
2474
+ children: [
2475
+ discussion.comments.length >= 3 && activeId !== discussion.id ? /* @__PURE__ */ jsxs7(Fragment2, { children: [
2476
+ /* @__PURE__ */ jsx15(
2477
+ Comment,
2478
+ {
2479
+ comment: discussion.comments[0],
2480
+ discussionLength: discussion.comments.length,
2481
+ documentContent: discussion == null ? void 0 : discussion.documentContent,
2482
+ editingId,
2483
+ index: 0,
2484
+ onEditorClick: () => highlightDiscussion(editor, discussion.id),
2485
+ setEditingId
2486
+ },
2487
+ discussion.comments[0].id
2488
+ ),
2489
+ /* @__PURE__ */ jsxs7("div", { className: "relative mb-1 ml-6.5 flex h-7 items-center rounded-md pl-1.5 text-muted-foreground text-sm hover:bg-muted", children: [
2490
+ /* @__PURE__ */ jsx15("div", { className: "absolute -top-1.25 -left-3.5 h-full w-0.5 shrink-0 bg-muted" }),
2491
+ /* @__PURE__ */ jsxs7("div", { className: "ml-2", children: [
2492
+ "Show ",
2493
+ discussion.comments.length - 2,
2494
+ " replies"
2495
+ ] })
2496
+ ] }),
2497
+ lastComment && /* @__PURE__ */ jsx15(
2498
+ Comment,
2499
+ {
2500
+ comment: lastComment,
2501
+ discussionLength: discussion.comments.length,
2502
+ documentContent: discussion == null ? void 0 : discussion.documentContent,
2503
+ editingId,
2504
+ index: discussion.comments.length - 1,
2505
+ onEditorClick: () => highlightDiscussion(editor, discussion.id),
2506
+ setEditingId
2507
+ },
2508
+ lastComment.id
2509
+ )
2510
+ ] }) : discussion.comments.map((comment, index) => {
2511
+ var _a;
2512
+ return /* @__PURE__ */ jsx15(
2513
+ Comment,
2514
+ {
2515
+ comment,
2516
+ discussionLength: discussion.comments.length,
2517
+ documentContent: discussion == null ? void 0 : discussion.documentContent,
2518
+ editingId,
2519
+ index,
2520
+ onEditorClick: () => highlightDiscussion(editor, discussion.id),
2521
+ setEditingId
2522
+ },
2523
+ (_a = comment.id) != null ? _a : index
2524
+ );
2525
+ }),
2526
+ activeId === discussion.id && /* @__PURE__ */ jsx15(CommentCreateForm, { discussionId: discussion.id })
2527
+ ]
2528
+ }
2529
+ );
2530
+ }
2531
+ var FloatingSuggestionContent = ({
2532
+ id,
2533
+ entries,
2534
+ ref,
2535
+ top
2536
+ }) => {
2537
+ var _a, _b, _c, _d, _e, _f;
2538
+ const { api, editor, setOption } = useEditorPlugin5(suggestionPlugin);
2539
+ const nodeData = api.suggestion.suggestionData(entries[0][0]);
2540
+ const { activeId, hoverId } = usePluginOptions(suggestionPlugin, ({ activeId: activeId2, hoverId: hoverId2 }) => ({
2541
+ activeId: activeId2,
2542
+ hoverId: hoverId2
2543
+ }));
2544
+ const userId = usePluginOption5(discussionPlugin, "currentUserId");
2545
+ const userData = usePluginOption5(discussionPlugin, "user", userId);
2546
+ const discussions = usePluginOption5(discussionPlugin, "discussions");
2547
+ const [editingId, setEditingId] = useState3(null);
2548
+ if (entries.length === 0) return null;
2549
+ entries.sort(([, path1], [, path2]) => PathApi2.isChild(path1, path2) ? -1 : 1);
2550
+ let newText = "";
2551
+ let text = "";
2552
+ let properties = {};
2553
+ let newProperties = {};
2554
+ entries.forEach(([node]) => {
2555
+ if (TextApi2.isText(node)) {
2556
+ const dataList = api.suggestion.dataList(node);
2557
+ dataList.forEach((data) => {
2558
+ if (data.id !== id) return;
2559
+ switch (data.type) {
2560
+ case "insert": {
2561
+ newText += node.text;
2562
+ break;
2563
+ }
2564
+ case "remove": {
2565
+ text += node.text;
2566
+ break;
2567
+ }
2568
+ case "update": {
2569
+ properties = __spreadValues(__spreadValues({}, properties), data.properties);
2570
+ newProperties = __spreadValues(__spreadValues({}, newProperties), data.newProperties);
2571
+ newText += node.text;
2572
+ break;
2573
+ }
2574
+ }
2575
+ });
2576
+ } else {
2577
+ const lineBreakData = api.suggestion.isBlockSuggestion(node) ? node.suggestion : void 0;
2578
+ if ((lineBreakData == null ? void 0 : lineBreakData.id) !== keyId2SuggestionId2(id)) return;
2579
+ if (lineBreakData.type === "insert") {
2580
+ newText += lineBreakData.isLineBreak ? BLOCK_SUGGESTION : BLOCK_SUGGESTION + TYPE_TEXT_MAP[node.type](node);
2581
+ } else if (lineBreakData.type === "remove") {
2582
+ text += lineBreakData.isLineBreak ? BLOCK_SUGGESTION : BLOCK_SUGGESTION + TYPE_TEXT_MAP[node.type](node);
2583
+ }
2584
+ }
2585
+ });
2586
+ if (!nodeData) return null;
2587
+ const comments = ((_a = discussions.find((d) => d.id === id)) == null ? void 0 : _a.comments) || [];
2588
+ const createdAt = new Date(nodeData.createdAt);
2589
+ const keyId = getSuggestionKey2(id);
2590
+ const suggestionText2Array = (text2) => {
2591
+ if (text2 === BLOCK_SUGGESTION) return ["line breaks"];
2592
+ return text2.split(BLOCK_SUGGESTION).filter(Boolean);
2593
+ };
2594
+ const accept = (suggestion2) => {
2595
+ api.suggestion.withoutSuggestions(() => {
2596
+ acceptSuggestion2(editor, suggestion2);
2597
+ });
2598
+ };
2599
+ const reject = (suggestion2) => {
2600
+ api.suggestion.withoutSuggestions(() => {
2601
+ rejectSuggestion2(editor, suggestion2);
2602
+ });
2603
+ };
2604
+ let suggestion;
2605
+ if (nodeData.type === "update") {
2606
+ suggestion = {
2607
+ comments,
2608
+ createdAt,
2609
+ keyId,
2610
+ newProperties,
2611
+ newText,
2612
+ properties,
2613
+ suggestionId: keyId2SuggestionId2(id),
2614
+ type: "update",
2615
+ userId: nodeData.userId
2616
+ };
2617
+ } else if (newText.length > 0 && text.length > 0) {
2618
+ suggestion = {
2619
+ comments,
2620
+ createdAt,
2621
+ keyId,
2622
+ newText,
2623
+ suggestionId: keyId2SuggestionId2(id),
2624
+ text,
2625
+ type: "replace",
2626
+ userId: nodeData.userId
2627
+ };
2628
+ } else if (newText.length > 0) {
2629
+ suggestion = {
2630
+ comments,
2631
+ createdAt,
2632
+ keyId,
2633
+ newText,
2634
+ suggestionId: keyId2SuggestionId2(id),
2635
+ type: "insert",
2636
+ userId: nodeData.userId
2637
+ };
2638
+ } else if (text.length > 0) {
2639
+ suggestion = {
2640
+ comments,
2641
+ createdAt,
2642
+ keyId,
2643
+ suggestionId: keyId2SuggestionId2(id),
2644
+ text,
2645
+ type: "remove",
2646
+ userId: nodeData.userId
2647
+ };
2648
+ } else {
2649
+ return null;
2650
+ }
2651
+ const highlightSuggestion = (editor2, id2) => {
2652
+ editor2.setOption(suggestionPlugin, "activeId", id2);
2653
+ editor2.setOption(commentPlugin, "activeId", null);
2654
+ const leaf = editor2.api.node({
2655
+ at: [],
2656
+ match: (n) => n[KEYS4.suggestion] && editor2.getApi(suggestionPlugin).suggestion.nodeId(n) === id2
2657
+ });
2658
+ if (!leaf) return;
2659
+ const parent = NodeApi2.get(editor2, leaf[1].slice(0, 1));
2660
+ if (parent) {
2661
+ editor2.getApi(BlockSelectionPlugin).blockSelection.addSelectedRow(parent.id, {
2662
+ clear: false,
2663
+ delay: 1e3
2664
+ });
2665
+ }
2666
+ };
2667
+ return /* @__PURE__ */ jsx15(
2668
+ "div",
2669
+ {
2670
+ className: cn(
2671
+ "absolute right-20 z-10 w-72 animate-fade-in cursor-pointer rounded-lg border bg-popover p-3 transition-transform duration-200",
2672
+ "data-[hover=true]:data-[active=false]:-translate-x-2 data-[hover=true]:data-[active=false]:bg-muted",
2673
+ "data-[active=true]:-translate-x-2"
2674
+ ),
2675
+ "data-active": activeId === id,
2676
+ "data-discussion-id": id,
2677
+ "data-hover": hoverId === id,
2678
+ onClick: () => highlightSuggestion(editor, id),
2679
+ onMouseEnter: () => setOption("hoverId", id),
2680
+ onMouseLeave: () => setOption("hoverId", null),
2681
+ ref,
2682
+ role: "presentation",
2683
+ style: { top },
2684
+ children: /* @__PURE__ */ jsxs7("div", { className: "flex flex-col", children: [
2685
+ /* @__PURE__ */ jsxs7("div", { className: "relative flex items-center", children: [
2686
+ userData && /* @__PURE__ */ jsxs7(Fragment2, { children: [
2687
+ /* @__PURE__ */ jsxs7(Avatar, { className: "relative mr-2 size-6", children: [
2688
+ /* @__PURE__ */ jsx15(AvatarImage, { alt: userData.name, src: userData.avatarUrl }),
2689
+ /* @__PURE__ */ jsx15(AvatarFallback, { children: (_b = userData.name) == null ? void 0 : _b[0] })
2690
+ ] }),
2691
+ /* @__PURE__ */ jsx15(PencilLineIcon, { className: "-bottom-2 absolute left-4 size-4 rounded-[50%] bg-brand-foreground p-0.5 text-brand/80" })
2692
+ ] }),
2693
+ /* @__PURE__ */ jsx15("h4", { className: "font-semibold text-sm leading-none", children: userData == null ? void 0 : userData.name }),
2694
+ /* @__PURE__ */ jsx15("div", { className: "ml-1.5 text-muted-foreground/80 text-xs leading-none", children: /* @__PURE__ */ jsx15("span", { className: "mr-1", children: formatCommentDate(suggestion.createdAt) }) })
2695
+ ] }),
2696
+ /* @__PURE__ */ jsx15("div", { className: "relative mt-1 mb-4 pl-8", children: /* @__PURE__ */ jsxs7("div", { className: "flex flex-col gap-2", children: [
2697
+ suggestion.type === "remove" && suggestionText2Array((_c = suggestion.text) != null ? _c : "").map((text2, i) => /* @__PURE__ */ jsxs7("div", { className: "flex items-center gap-2", children: [
2698
+ /* @__PURE__ */ jsx15("span", { className: "text-muted-foreground text-sm", children: "Delete:" }),
2699
+ /* @__PURE__ */ jsx15("span", { className: "text-sm", children: text2 })
2700
+ ] }, `${id}-remove-${i}`)),
2701
+ suggestion.type === "insert" && suggestionText2Array((_d = suggestion.newText) != null ? _d : "").map((text2, i) => /* @__PURE__ */ jsxs7("div", { className: "flex items-center gap-2", children: [
2702
+ /* @__PURE__ */ jsx15("span", { className: "text-muted-foreground text-sm", children: "Add:" }),
2703
+ /* @__PURE__ */ jsxs7("span", { className: "text-sm", children: [
2704
+ '"',
2705
+ text2 || "line breaks",
2706
+ '"'
2707
+ ] })
2708
+ ] }, `${id}-insert-${i}`)),
2709
+ suggestion.type === "replace" && /* @__PURE__ */ jsxs7("div", { className: "flex flex-col gap-2", children: [
2710
+ suggestionText2Array((_e = suggestion.newText) != null ? _e : "").map((text2, i) => /* @__PURE__ */ jsxs7("div", { className: "flex items-center text-brand/80", children: [
2711
+ /* @__PURE__ */ jsx15("span", { className: "text-sm", children: "With:" }),
2712
+ /* @__PURE__ */ jsxs7("span", { className: "text-sm", children: [
2713
+ '"',
2714
+ text2 || "line breaks",
2715
+ '"'
2716
+ ] })
2717
+ ] }, `${id}-replace-new-${i}`)),
2718
+ suggestionText2Array((_f = suggestion.text) != null ? _f : "").map((text2, i) => /* @__PURE__ */ jsxs7("div", { className: "flex items-center", children: [
2719
+ /* @__PURE__ */ jsx15("span", { className: "text-muted-foreground text-sm", children: i === 0 ? "Replace:" : "Delete:" }),
2720
+ /* @__PURE__ */ jsxs7("span", { className: "text-sm", children: [
2721
+ '"',
2722
+ text2 || "line breaks",
2723
+ '"'
2724
+ ] })
2725
+ ] }, `${id}-replace-old-${i}`))
2726
+ ] }),
2727
+ suggestion.type === "update" && /* @__PURE__ */ jsxs7("div", { className: "flex items-center gap-2", children: [
2728
+ /* @__PURE__ */ jsxs7("span", { className: "text-muted-foreground text-sm", children: [
2729
+ Object.keys(suggestion.properties).map((key) => /* @__PURE__ */ jsxs7("span", { children: [
2730
+ "Un",
2731
+ key
2732
+ ] }, key)),
2733
+ Object.keys(suggestion.newProperties).map((key) => /* @__PURE__ */ jsx15("span", { children: key.charAt(0).toUpperCase() + key.slice(1) }, key))
2734
+ ] }),
2735
+ /* @__PURE__ */ jsxs7("span", { className: "text-sm", children: [
2736
+ '"',
2737
+ suggestion.newText,
2738
+ '"'
2739
+ ] })
2740
+ ] })
2741
+ ] }) }),
2742
+ suggestion.comments.length >= 3 && activeId !== id ? /* @__PURE__ */ jsxs7(Fragment2, { children: [
2743
+ /* @__PURE__ */ jsx15(
2744
+ Comment,
2745
+ {
2746
+ comment: suggestion.comments[0],
2747
+ discussionLength: suggestion.comments.length,
2748
+ documentContent: "__suggestion__",
2749
+ editingId,
2750
+ index: 0,
2751
+ setEditingId
2752
+ },
2753
+ suggestion.comments[0].id
2754
+ ),
2755
+ /* @__PURE__ */ jsxs7("div", { className: "relative mb-1 ml-6.5 flex h-7 items-center rounded-md pl-1.5 text-muted-foreground text-sm hover:bg-muted", children: [
2756
+ /* @__PURE__ */ jsx15("div", { className: "absolute -top-1.25 -left-3.5 h-full w-0.5 shrink-0 bg-muted" }),
2757
+ /* @__PURE__ */ jsxs7("div", { className: "ml-2", children: [
2758
+ "Show ",
2759
+ suggestion.comments.length - 2,
2760
+ " replies"
2761
+ ] })
2762
+ ] }),
2763
+ (() => {
2764
+ const lastComment = suggestion.comments.at(-1);
2765
+ if (!lastComment) return null;
2766
+ return /* @__PURE__ */ jsx15(
2767
+ Comment,
2768
+ {
2769
+ comment: lastComment,
2770
+ discussionLength: suggestion.comments.length,
2771
+ documentContent: "__suggestion__",
2772
+ editingId,
2773
+ index: suggestion.comments.length - 1,
2774
+ setEditingId
2775
+ },
2776
+ lastComment.id
2777
+ );
2778
+ })()
2779
+ ] }) : suggestion.comments.map((comment, index) => {
2780
+ var _a2;
2781
+ return /* @__PURE__ */ jsx15(
2782
+ Comment,
2783
+ {
2784
+ comment,
2785
+ discussionLength: suggestion.comments.length,
2786
+ documentContent: "__suggestion__",
2787
+ editingId,
2788
+ index,
2789
+ setEditingId
2790
+ },
2791
+ (_a2 = comment.id) != null ? _a2 : index
2792
+ );
2793
+ }),
2794
+ hoverId === id && /* @__PURE__ */ jsxs7("div", { className: "absolute top-4 right-4 flex gap-2", children: [
2795
+ /* @__PURE__ */ jsx15(Button, { className: "h-6 p-1 text-muted-foreground", onClick: () => accept(suggestion), variant: "ghost", children: /* @__PURE__ */ jsx15(CheckIcon4, { className: "size-4" }) }),
2796
+ /* @__PURE__ */ jsx15(Button, { className: "h-6 p-1 text-muted-foreground", onClick: () => reject(suggestion), variant: "ghost", children: /* @__PURE__ */ jsx15(XIcon3, { className: "size-4" }) })
2797
+ ] }),
2798
+ activeId === id && /* @__PURE__ */ jsx15(CommentCreateForm, { discussionId: suggestion.suggestionId })
2799
+ ] })
2800
+ }
2801
+ );
2802
+ };
2803
+
2804
+ // src/components/editor/plugins/comment-kit.tsx
2805
+ var commentPlugin = toTPlatePlugin2(BaseCommentPlugin, {
2806
+ handlers: {
2807
+ onClick: ({ api, event, setOption, type }) => {
2808
+ var _a, _b, _c;
2809
+ let leaf = event.target;
2810
+ let isSet = false;
2811
+ const unsetActiveSuggestion = () => {
2812
+ setOption("activeId", null);
2813
+ isSet = true;
2814
+ };
2815
+ if (!isSlateString2(leaf)) unsetActiveSuggestion();
2816
+ while (leaf.parentElement && !isSlateElement(leaf.parentElement)) {
2817
+ if (leaf.classList.contains(`slate-${type}`)) {
2818
+ const commentsEntry = (_a = api.comment) == null ? void 0 : _a.node();
2819
+ if (!commentsEntry) {
2820
+ unsetActiveSuggestion();
2821
+ break;
2822
+ }
2823
+ const id = (_c = (_b = api.comment) == null ? void 0 : _b.nodeId(commentsEntry[0])) != null ? _c : null;
2824
+ const isDraft = commentsEntry[0][getDraftCommentKey3()];
2825
+ setOption("activeId", isDraft ? getDraftCommentKey3() : id);
2826
+ isSet = true;
2827
+ break;
2828
+ }
2829
+ leaf = leaf.parentElement;
2830
+ }
2831
+ if (!isSet) unsetActiveSuggestion();
2832
+ }
2833
+ },
2834
+ options: {
2835
+ activeId: null,
2836
+ commentingBlock: null,
2837
+ hoverId: null,
2838
+ isOverlapWithEditor: false,
2839
+ uniquePathMap: /* @__PURE__ */ new Map(),
2840
+ updateTimestamp: null
2841
+ },
2842
+ useHooks: ({ editor, setOption }) => {
2843
+ const editorContainerRef = useEditorContainerRef2();
2844
+ useEffect5(() => {
2845
+ if (!editorContainerRef.current) return;
2846
+ const editable = editor.api.toDOMNode(editor);
2847
+ if (!editable) return;
2848
+ const observer = new ResizeObserver((entries) => {
2849
+ const width = entries[0].contentRect.width;
2850
+ const isOverlap = width < 700;
2851
+ setOption("isOverlapWithEditor", isOverlap);
2852
+ });
2853
+ observer.observe(editable);
2854
+ return () => {
2855
+ observer.disconnect();
2856
+ };
2857
+ }, [editor, editorContainerRef, setOption]);
2858
+ }
2859
+ }).extendTransforms(
2860
+ ({
2861
+ editor,
2862
+ setOption,
2863
+ tf: {
2864
+ comment: { setDraft }
2865
+ }
2866
+ }) => ({
2867
+ setDraft: () => {
2868
+ var _a, _b;
2869
+ if (editor.api.isCollapsed()) {
2870
+ const block = editor.api.block();
2871
+ if (block) {
2872
+ editor.tf.select(block[1]);
2873
+ }
2874
+ }
2875
+ setDraft();
2876
+ editor.tf.collapse();
2877
+ setOption("activeId", getDraftCommentKey3());
2878
+ setOption("commentingBlock", (_b = (_a = editor.selection) == null ? void 0 : _a.focus.path.slice(0, 1)) != null ? _b : null);
2879
+ }
2880
+ })
2881
+ ).overrideEditor(({ editor, setOption, tf: { apply, insertBreak }, tf, type }) => ({
2882
+ transforms: {
2883
+ apply(operation) {
2884
+ if (operation.type !== "set_selection" && operation.type !== "set_node" && operation.type !== "split_node" && operation.type !== "merge_node") {
2885
+ const { newProperties, properties } = operation;
2886
+ if ((properties == null ? void 0 : properties[getDraftCommentKey3()]) || (newProperties == null ? void 0 : newProperties[getDraftCommentKey3()])) {
2887
+ return;
2888
+ }
2889
+ setOption("updateTimestamp", Date.now());
2890
+ }
2891
+ apply(operation);
2892
+ },
2893
+ insertBreak() {
2894
+ var _a;
2895
+ setOption("updateTimestamp", Date.now());
2896
+ tf.comment.removeMark();
2897
+ insertBreak();
2898
+ editor.tf.unsetNodes([type], {
2899
+ at: (_a = editor.selection) == null ? void 0 : _a.focus,
2900
+ mode: "lowest"
2901
+ });
2902
+ }
2903
+ }
2904
+ })).extend({
2905
+ shortcuts: {
2906
+ setDraft: { keys: "mod+shift+m" }
2907
+ }
2908
+ }).configure({
2909
+ render: {
2910
+ afterEditable: FloatingDiscussion,
2911
+ node: CommentLeaf
2912
+ }
2913
+ });
2914
+
2915
+ // src/ui/popover.tsx
2916
+ import { cva as cva7 } from "class-variance-authority";
2917
+ import { Popover as PopoverPrimitive } from "radix-ui";
2918
+ import { jsx as jsx16 } from "react/jsx-runtime";
2919
+ var popoverVariants = cva7(
2920
+ cn(
2921
+ "group/popover",
2922
+ "z-50 max-w-[calc(100vw-24px)] animate-popover overflow-hidden rounded-md border border-border bg-popover text-popover-foreground shadow-floating outline-hidden"
2923
+ ),
2924
+ {
2925
+ defaultVariants: {
2926
+ variant: "default"
2927
+ },
2928
+ variants: {
2929
+ variant: {
2930
+ combobox: "",
2931
+ default: "w-72",
2932
+ equation: "w-100 rounded-lg px-2.5 py-2",
2933
+ equationInline: "w-100 rounded-lg px-2.5 py-2",
2934
+ media: "max-h-[70vh] min-w-45 rounded-lg"
2935
+ }
2936
+ }
2937
+ }
2938
+ );
2939
+ function Popover(_a) {
2940
+ var props = __objRest(_a, []);
2941
+ return /* @__PURE__ */ jsx16(PopoverPrimitive.Root, __spreadValues({ "data-slot": "popover" }, props));
2942
+ }
2943
+ function PopoverTrigger(_a) {
2944
+ var props = __objRest(_a, []);
2945
+ return /* @__PURE__ */ jsx16(PopoverPrimitive.Trigger, __spreadValues({ "data-slot": "popover-trigger" }, props));
2946
+ }
2947
+ function PopoverAnchor(_a) {
2948
+ var props = __objRest(_a, []);
2949
+ return /* @__PURE__ */ jsx16(PopoverPrimitive.Anchor, __spreadValues({ "data-slot": "popover-anchor" }, props));
2950
+ }
2951
+ function PopoverContent(_a) {
2952
+ var _b = _a, {
2953
+ align = "center",
2954
+ className,
2955
+ sideOffset = 4,
2956
+ variant
2957
+ } = _b, props = __objRest(_b, [
2958
+ "align",
2959
+ "className",
2960
+ "sideOffset",
2961
+ "variant"
2962
+ ]);
2963
+ const container = usePortalContainer();
2964
+ return /* @__PURE__ */ jsx16(PopoverPrimitive.Portal, { container, children: /* @__PURE__ */ jsx16(
2965
+ PopoverPrimitive.Content,
2966
+ __spreadValues({
2967
+ align,
2968
+ className: cn(popoverVariants({ variant }), className),
2969
+ "data-slot": "popover-content",
2970
+ sideOffset
2971
+ }, props)
2972
+ ) });
2973
+ }
2974
+
2975
+ // src/ui/block-discussion.tsx
2976
+ import { Fragment as Fragment3, jsx as jsx17, jsxs as jsxs8 } from "react/jsx-runtime";
2977
+ var BlockDiscussion = (props) => {
2978
+ const isOverlapWithEditor = usePluginOption6(commentPlugin, "isOverlapWithEditor");
2979
+ const adapter = useEditorAdapter();
2980
+ if (adapter.comments !== null) return;
2981
+ if (!isOverlapWithEditor) return;
2982
+ const { api, editor, element } = props;
2983
+ const blockPath = editor.api.findPath(element);
2984
+ if (!blockPath || blockPath.length > 1) return;
2985
+ const draftCommentNode = api.comment.node({ at: blockPath, isDraft: true });
2986
+ const commentNodes = [...api.comment.nodes({ at: blockPath })];
2987
+ const suggestionApi = editor.getApi(SuggestionPlugin2).suggestion;
2988
+ const suggestionNodes = suggestionApi ? [...suggestionApi.nodes({ at: blockPath })].filter(([node]) => !node[getTransientSuggestionKey2()]) : [];
2989
+ if (commentNodes.length === 0 && suggestionNodes.length === 0 && !draftCommentNode) {
2990
+ return;
2991
+ }
2992
+ return (props2) => /* @__PURE__ */ jsx17(
2993
+ BlockCommentsContent,
2994
+ __spreadValues({
2995
+ blockPath,
2996
+ commentNodes,
2997
+ draftCommentNode,
2998
+ suggestionNodes
2999
+ }, props2)
3000
+ );
3001
+ };
3002
+ var BlockCommentsContent = ({
3003
+ blockPath,
3004
+ children,
3005
+ commentNodes,
3006
+ draftCommentNode,
3007
+ suggestionNodes
3008
+ }) => {
3009
+ const editor = useEditorRef4();
3010
+ const resolvedSuggestion = useResolveSuggestion(suggestionNodes, blockPath);
3011
+ const resolvedDiscussions = useResolvedDiscussion(commentNodes, blockPath);
3012
+ const suggestionsCount = resolvedSuggestion.length;
3013
+ const discussionsCount = resolvedDiscussions.length;
3014
+ const totalCount = suggestionsCount + discussionsCount;
3015
+ const activeSuggestionId = usePluginOption6(suggestionPlugin, "activeId");
3016
+ const activeSuggestion = activeSuggestionId && resolvedSuggestion.find((s) => s.suggestionId === activeSuggestionId);
3017
+ const commentingBlock = usePluginOption6(commentPlugin, "commentingBlock");
3018
+ const activeCommentId = usePluginOption6(commentPlugin, "activeId");
3019
+ const isCommenting = activeCommentId === getDraftCommentKey4();
3020
+ const activeDiscussion = activeCommentId && resolvedDiscussions.find((d) => d.id === activeCommentId);
3021
+ const noneActive = !activeSuggestion && !activeDiscussion;
3022
+ const sortedMergedData = [...resolvedDiscussions, ...resolvedSuggestion].sort(
3023
+ (a, b) => a.createdAt.getTime() - b.createdAt.getTime()
3024
+ );
3025
+ const selected = resolvedDiscussions.some((d) => d.id === activeCommentId) || resolvedSuggestion.some((s) => s.suggestionId === activeSuggestionId);
3026
+ const [_open, setOpen] = React6.useState(selected);
3027
+ const commentingCurrent = !!commentingBlock && PathApi3.equals(blockPath, commentingBlock);
3028
+ const open = _open || selected || isCommenting && !!draftCommentNode && commentingCurrent;
3029
+ const anchorElement = React6.useMemo(() => {
3030
+ var _a;
3031
+ let activeNode;
3032
+ if (activeSuggestion) {
3033
+ activeNode = suggestionNodes.find(
3034
+ ([node]) => TextApi3.isText(node) && editor.getApi(SuggestionPlugin2).suggestion.nodeId(node) === activeSuggestion.suggestionId
3035
+ );
3036
+ }
3037
+ if (activeCommentId) {
3038
+ if (activeCommentId === getDraftCommentKey4()) {
3039
+ activeNode = draftCommentNode;
3040
+ } else {
3041
+ activeNode = commentNodes.find(
3042
+ ([node]) => editor.getApi(CommentPlugin2).comment.nodeId(node) === activeCommentId
3043
+ );
3044
+ }
3045
+ }
3046
+ if (!activeNode) return null;
3047
+ return (_a = editor.api.toDOMNode(activeNode[0])) != null ? _a : null;
3048
+ }, [open, activeSuggestion, activeCommentId, editor.api, suggestionNodes, draftCommentNode, commentNodes]);
3049
+ if (suggestionsCount + resolvedDiscussions.length === 0 && !draftCommentNode)
3050
+ return /* @__PURE__ */ jsx17("div", { className: "w-full", children });
3051
+ return /* @__PURE__ */ jsx17("div", { className: "flex w-full justify-between", children: /* @__PURE__ */ jsxs8(
3052
+ Popover,
3053
+ {
3054
+ onOpenChange: (_open_) => {
3055
+ if (!_open_ && isCommenting && draftCommentNode) {
3056
+ editor.tf.unsetNodes(getDraftCommentKey4(), {
3057
+ at: [],
3058
+ mode: "lowest",
3059
+ match: (n) => n[getDraftCommentKey4()]
3060
+ });
3061
+ }
3062
+ setOpen(_open_);
3063
+ },
3064
+ open,
3065
+ children: [
3066
+ /* @__PURE__ */ jsx17("div", { className: "w-full", children }),
3067
+ anchorElement && /* @__PURE__ */ jsx17(PopoverAnchor, { asChild: true, className: "w-full", virtualRef: { current: anchorElement } }),
3068
+ /* @__PURE__ */ jsx17(
3069
+ PopoverContent,
3070
+ {
3071
+ align: "center",
3072
+ className: "max-h-[min(50dvh,calc(-24px+var(--radix-popper-available-height)))] w-95 min-w-32.5 max-w-[calc(100vw-24px)] overflow-y-auto p-0 data-[state=closed]:opacity-0",
3073
+ onCloseAutoFocus: (e) => e.preventDefault(),
3074
+ onOpenAutoFocus: (e) => e.preventDefault(),
3075
+ side: "bottom",
3076
+ children: isCommenting ? /* @__PURE__ */ jsx17(CommentCreateForm, { className: "p-4", focusOnMount: true }) : noneActive ? sortedMergedData.map(
3077
+ (item, index) => isResolvedSuggestion(item) ? /* @__PURE__ */ jsx17(
3078
+ BlockSuggestionCard,
3079
+ {
3080
+ idx: index,
3081
+ isLast: index === sortedMergedData.length - 1,
3082
+ suggestion: item
3083
+ },
3084
+ item.suggestionId
3085
+ ) : /* @__PURE__ */ jsx17(BlockComment, { discussion: item, isLast: index === sortedMergedData.length - 1 }, item.id)
3086
+ ) : /* @__PURE__ */ jsxs8(Fragment3, { children: [
3087
+ activeSuggestion && /* @__PURE__ */ jsx17(
3088
+ BlockSuggestionCard,
3089
+ {
3090
+ idx: 0,
3091
+ isLast: true,
3092
+ suggestion: activeSuggestion
3093
+ },
3094
+ activeSuggestion.suggestionId
3095
+ ),
3096
+ activeDiscussion && /* @__PURE__ */ jsx17(BlockComment, { discussion: activeDiscussion, isLast: true })
3097
+ ] })
3098
+ }
3099
+ ),
3100
+ totalCount > 0 && /* @__PURE__ */ jsx17("div", { className: "relative left-0 size-0 select-none", children: /* @__PURE__ */ jsx17(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs8(
3101
+ Button,
3102
+ {
3103
+ className: "mt-1 ml-1 flex h-6 gap-1 px-1.5 py-0 text-muted-foreground/80 hover:text-muted-foreground/80 data-[active=true]:bg-muted",
3104
+ contentEditable: false,
3105
+ "data-active": open,
3106
+ variant: "ghost",
3107
+ children: [
3108
+ suggestionsCount > 0 && discussionsCount === 0 && /* @__PURE__ */ jsx17(PencilLineIcon2, { className: "size-4 shrink-0" }),
3109
+ suggestionsCount === 0 && discussionsCount > 0 && /* @__PURE__ */ jsx17(MessageSquareTextIcon, { className: "size-4 shrink-0" }),
3110
+ suggestionsCount > 0 && discussionsCount > 0 && /* @__PURE__ */ jsx17(MessagesSquareIcon, { className: "size-4 shrink-0" }),
3111
+ /* @__PURE__ */ jsx17("span", { className: "font-semibold text-xs", children: totalCount })
3112
+ ]
3113
+ }
3114
+ ) }) })
3115
+ ]
3116
+ }
3117
+ ) });
3118
+ };
3119
+ function BlockComment({ discussion, isLast }) {
3120
+ const [editingId, setEditingId] = React6.useState(null);
3121
+ return /* @__PURE__ */ jsxs8(React6.Fragment, { children: [
3122
+ /* @__PURE__ */ jsxs8("div", { className: "p-4", children: [
3123
+ discussion.comments.map((comment, index) => {
3124
+ var _a;
3125
+ return /* @__PURE__ */ jsx17(
3126
+ Comment,
3127
+ {
3128
+ comment,
3129
+ discussionLength: discussion.comments.length,
3130
+ documentContent: discussion == null ? void 0 : discussion.documentContent,
3131
+ editingId,
3132
+ index,
3133
+ setEditingId,
3134
+ showDocumentContent: true
3135
+ },
3136
+ (_a = comment.id) != null ? _a : index
3137
+ );
3138
+ }),
3139
+ /* @__PURE__ */ jsx17(CommentCreateForm, { discussionId: discussion.id })
3140
+ ] }),
3141
+ !isLast && /* @__PURE__ */ jsx17("div", { className: "h-px w-full bg-muted" })
3142
+ ] }, discussion.id);
3143
+ }
3144
+ var useResolvedDiscussion = (commentNodes, blockPath) => {
3145
+ const { api, getOption, setOption } = useEditorPlugin6(commentPlugin);
3146
+ const discussions = usePluginOption6(discussionPlugin, "discussions");
3147
+ useEffect6(() => {
3148
+ commentNodes.forEach(([node]) => {
3149
+ const id = api.comment.nodeId(node);
3150
+ const map = getOption("uniquePathMap");
3151
+ if (!id) return;
3152
+ const previousPath = map.get(id);
3153
+ if (PathApi3.isPath(previousPath)) {
3154
+ const nodes = api.comment.node({ id, at: previousPath });
3155
+ if (!nodes) {
3156
+ setOption("uniquePathMap", new Map(map).set(id, blockPath));
3157
+ return;
3158
+ }
3159
+ return;
3160
+ }
3161
+ setOption("uniquePathMap", new Map(map).set(id, blockPath));
3162
+ });
3163
+ }, [api, blockPath, commentNodes, getOption, setOption]);
3164
+ const commentsIds = new Set(commentNodes.map(([node]) => api.comment.nodeId(node)).filter(Boolean));
3165
+ return discussions.map((d) => __spreadProps(__spreadValues({}, d), {
3166
+ createdAt: new Date(d.createdAt)
3167
+ })).filter((item) => {
3168
+ const commentsPathMap = getOption("uniquePathMap");
3169
+ const firstBlockPath = commentsPathMap.get(item.id);
3170
+ if (!firstBlockPath) return false;
3171
+ if (!PathApi3.equals(firstBlockPath, blockPath)) return false;
3172
+ return api.comment.has({ id: item.id }) && commentsIds.has(item.id) && !item.isResolved;
3173
+ });
3174
+ };
3175
+
3176
+ // src/components/editor/plugins/discussion-kit.tsx
3177
+ var ANONYMOUS_USER_ID = "anonymous";
3178
+ var initialUsers = {
3179
+ [ANONYMOUS_USER_ID]: {
3180
+ id: ANONYMOUS_USER_ID,
3181
+ name: "Guest"
3182
+ }
3183
+ };
3184
+ var discussionPlugin = createPlatePlugin({
3185
+ key: "discussion",
3186
+ options: {
3187
+ currentUserId: ANONYMOUS_USER_ID,
3188
+ discussions: [],
3189
+ users: initialUsers
3190
+ }
3191
+ }).configure({
3192
+ render: { aboveNodes: BlockDiscussion }
3193
+ }).extendSelectors(({ getOption }) => ({
3194
+ currentUser: () => getOption("users")[getOption("currentUserId")],
3195
+ user: (id) => getOption("users")[id]
3196
+ }));
3197
+
3198
+ // src/components/editor/chat-comment-effects.ts
3199
+ var isStructuredComment = (value) => {
3200
+ if (typeof value !== "object" || value === null) return false;
3201
+ const candidate = value;
3202
+ return typeof candidate.quote === "string" && typeof candidate.comment === "string";
3203
+ };
3204
+ var isCommentDataPart = (part) => {
3205
+ return part.type === "data-comment" && isStructuredComment(part.data);
3206
+ };
3207
+ var resolveStructuredComment = (editor, structured) => {
3208
+ const blocks = Array.from(editor.api.blocks({ at: [], mode: "highest" }));
3209
+ for (const entry of blocks) {
3210
+ const [node] = entry;
3211
+ const blockId = node.id;
3212
+ if (!blockId) continue;
3213
+ const range = findTextRangeInBlock({ block: entry, findText: structured.quote });
3214
+ if (!range) continue;
3215
+ return {
3216
+ blockId,
3217
+ comment: structured.comment,
3218
+ content: NodeApi3.string(node)
3219
+ };
3220
+ }
3221
+ return null;
3222
+ };
3223
+ var useApplyChatCommentResult = (messages) => {
3224
+ const editor = useEditorRef5();
3225
+ const appliedKeys = useRef5(/* @__PURE__ */ new Set());
3226
+ useEffect7(() => {
3227
+ const lastMessage = messages.at(-1);
3228
+ if (!lastMessage || lastMessage.role !== "assistant") return;
3229
+ lastMessage.parts.forEach((part, index) => {
3230
+ var _a;
3231
+ if (!isCommentDataPart(part)) return;
3232
+ const key = `${lastMessage.id}:${(_a = part.id) != null ? _a : index}`;
3233
+ if (appliedKeys.current.has(key)) return;
3234
+ const aiComment = resolveStructuredComment(editor, part.data);
3235
+ if (!aiComment) {
3236
+ appliedKeys.current.add(key);
3237
+ return;
3238
+ }
3239
+ applyAIComment(editor, aiComment);
3240
+ appliedKeys.current.add(key);
3241
+ });
3242
+ }, [editor, messages]);
3243
+ };
3244
+ var applyAIComment = (editor, aiComment) => {
3245
+ const range = aiCommentToRange(editor, aiComment);
3246
+ if (!range) return;
3247
+ const discussions = editor.getOption(discussionPlugin, "discussions") || [];
3248
+ const discussionId = nanoid2();
3249
+ const newComment = {
3250
+ id: nanoid2(),
3251
+ contentRich: [{ children: [{ text: aiComment.comment }], type: "p" }],
3252
+ createdAt: /* @__PURE__ */ new Date(),
3253
+ discussionId,
3254
+ isEdited: false,
3255
+ userId: "ai"
3256
+ };
3257
+ const newDiscussion = {
3258
+ id: discussionId,
3259
+ comments: [newComment],
3260
+ createdAt: /* @__PURE__ */ new Date(),
3261
+ isResolved: false,
3262
+ userId: "ai"
3263
+ };
3264
+ editor.setOption(discussionPlugin, "discussions", [...discussions, newDiscussion]);
3265
+ editor.tf.setNodes({ [getCommentKey2(discussionId)]: true }, { at: range, match: TextApi4.isText, split: true });
3266
+ };
3267
+
3268
+ // src/components/editor/use-chat.ts
3269
+ var TOOL_NAMES = ["comment", "edit", "generate"];
3270
+ var resolveMode = (rawToolName) => {
3271
+ if (typeof rawToolName === "string" && TOOL_NAMES.includes(rawToolName)) {
3272
+ return rawToolName;
3273
+ }
3274
+ return "generate";
3275
+ };
3276
+ var useChat = () => {
3277
+ const editor = useEditorRef6();
3278
+ const adapter = useEditorAdapter();
3279
+ const ai = adapter.ai;
3280
+ const canUseAI = adapter.permissions.canUseAI;
3281
+ const aiHeaders = ai == null ? void 0 : ai.headers;
3282
+ const aiContextBody = ai == null ? void 0 : ai.contextBody;
3283
+ const aiEndpoint = ai == null ? void 0 : ai.endpoint;
3284
+ const transport = useMemo3(() => {
3285
+ if (!aiEndpoint) return void 0;
3286
+ return new DefaultChatTransport({
3287
+ api: aiEndpoint,
3288
+ headers: aiHeaders,
3289
+ prepareSendMessagesRequest: ({ messages, body }) => {
3290
+ const perCallCtx = body == null ? void 0 : body.ctx;
3291
+ return {
3292
+ body: {
3293
+ mode: resolveMode(perCallCtx == null ? void 0 : perCallCtx.toolName),
3294
+ surfaceContext: aiContextBody,
3295
+ messages
3296
+ }
3297
+ };
3298
+ }
3299
+ });
3300
+ }, [aiEndpoint, aiHeaders, aiContextBody]);
3301
+ const baseChat = useBaseChat({
3302
+ id: "editor",
3303
+ transport
3304
+ });
3305
+ useApplyChatCommentResult(baseChat.messages);
3306
+ const isEnabled = canUseAI && ai !== null && transport !== void 0;
3307
+ useEffect8(() => {
3308
+ if (!isEnabled) return;
3309
+ editor.setOption(AIChatPlugin, "chat", baseChat);
3310
+ }, [baseChat, editor, isEnabled]);
3311
+ return baseChat;
3312
+ };
3313
+ export {
3314
+ useChat
3315
+ };