@fuma-content/studio 0.1.0

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 (413) hide show
  1. package/dist/bin.d.mts +1 -0
  2. package/dist/bin.mjs +90 -0
  3. package/dist/index.d.mts +13 -0
  4. package/dist/index.mjs +66 -0
  5. package/dist/mdx/actions.mjs +34 -0
  6. package/dist/mdx/client.mjs +167 -0
  7. package/dist/package.mjs +6 -0
  8. package/dist/src/components/code-editor/mdx.lazy.mjs +19 -0
  9. package/dist/src/components/code-editor/mdx.mjs +44 -0
  10. package/dist/src/components/code-editor/yaml.lazy.mjs +22 -0
  11. package/dist/src/components/code-editor/yaml.mjs +63 -0
  12. package/dist/src/components/editor/editor-base-kit.mjs +41 -0
  13. package/dist/src/components/editor/editor-kit.mjs +73 -0
  14. package/dist/src/components/editor/md.mjs +42 -0
  15. package/dist/src/components/editor/plugins/ai-kit.mjs +68 -0
  16. package/dist/src/components/editor/plugins/align-base-kit.mjs +28 -0
  17. package/dist/src/components/editor/plugins/align-kit.mjs +30 -0
  18. package/dist/src/components/editor/plugins/autoformat-kit.mjs +214 -0
  19. package/dist/src/components/editor/plugins/basic-blocks-base-kit.mjs +22 -0
  20. package/dist/src/components/editor/plugins/basic-blocks-kit.mjs +51 -0
  21. package/dist/src/components/editor/plugins/basic-marks-base-kit.mjs +20 -0
  22. package/dist/src/components/editor/plugins/basic-marks-kit.mjs +28 -0
  23. package/dist/src/components/editor/plugins/block-menu-kit.mjs +11 -0
  24. package/dist/src/components/editor/plugins/block-placeholder-kit.mjs +14 -0
  25. package/dist/src/components/editor/plugins/block-selection-kit.mjs +48 -0
  26. package/dist/src/components/editor/plugins/callout-base-kit.mjs +8 -0
  27. package/dist/src/components/editor/plugins/callout-kit.mjs +10 -0
  28. package/dist/src/components/editor/plugins/code-block-base-kit.mjs +16 -0
  29. package/dist/src/components/editor/plugins/code-block-kit.mjs +19 -0
  30. package/dist/src/components/editor/plugins/column-base-kit.mjs +8 -0
  31. package/dist/src/components/editor/plugins/column-kit.mjs +10 -0
  32. package/dist/src/components/editor/plugins/comment-base-kit.mjs +8 -0
  33. package/dist/src/components/editor/plugins/comment-kit.mjs +53 -0
  34. package/dist/src/components/editor/plugins/copilot-kit.mjs +49 -0
  35. package/dist/src/components/editor/plugins/cursor-overlay-kit.mjs +11 -0
  36. package/dist/src/components/editor/plugins/date-base-kit.mjs +8 -0
  37. package/dist/src/components/editor/plugins/date-kit.mjs +10 -0
  38. package/dist/src/components/editor/plugins/discussion-kit.mjs +94 -0
  39. package/dist/src/components/editor/plugins/dnd-kit.mjs +31 -0
  40. package/dist/src/components/editor/plugins/emoji-kit.mjs +11 -0
  41. package/dist/src/components/editor/plugins/exit-break-kit.mjs +12 -0
  42. package/dist/src/components/editor/plugins/fixed-toolbar-kit.mjs +15 -0
  43. package/dist/src/components/editor/plugins/floating-toolbar-kit.mjs +15 -0
  44. package/dist/src/components/editor/plugins/font-base-kit.mjs +14 -0
  45. package/dist/src/components/editor/plugins/font-kit.mjs +19 -0
  46. package/dist/src/components/editor/plugins/indent-base-kit.mjs +17 -0
  47. package/dist/src/components/editor/plugins/indent-kit.mjs +20 -0
  48. package/dist/src/components/editor/plugins/line-height-base-kit.mjs +20 -0
  49. package/dist/src/components/editor/plugins/line-height-kit.mjs +22 -0
  50. package/dist/src/components/editor/plugins/link-base-kit.mjs +8 -0
  51. package/dist/src/components/editor/plugins/link-kit.mjs +15 -0
  52. package/dist/src/components/editor/plugins/list-base-kit.mjs +19 -0
  53. package/dist/src/components/editor/plugins/list-kit.mjs +22 -0
  54. package/dist/src/components/editor/plugins/markdown-kit.mjs +17 -0
  55. package/dist/src/components/editor/plugins/math-base-kit.mjs +8 -0
  56. package/dist/src/components/editor/plugins/math-kit.mjs +10 -0
  57. package/dist/src/components/editor/plugins/media-base-kit.mjs +23 -0
  58. package/dist/src/components/editor/plugins/media-kit.mjs +37 -0
  59. package/dist/src/components/editor/plugins/slash-kit.mjs +11 -0
  60. package/dist/src/components/editor/plugins/suggestion-base-kit.mjs +8 -0
  61. package/dist/src/components/editor/plugins/suggestion-kit.mjs +50 -0
  62. package/dist/src/components/editor/plugins/table-base-kit.mjs +13 -0
  63. package/dist/src/components/editor/plugins/table-kit.mjs +15 -0
  64. package/dist/src/components/editor/transforms.mjs +125 -0
  65. package/dist/src/components/editor/ui/ai-chat-editor.mjs +21 -0
  66. package/dist/src/components/editor/ui/ai-menu.mjs +488 -0
  67. package/dist/src/components/editor/ui/ai-node.mjs +24 -0
  68. package/dist/src/components/editor/ui/ai-toolbar-button.mjs +23 -0
  69. package/dist/src/components/editor/ui/align-toolbar-button.mjs +71 -0
  70. package/dist/src/components/editor/ui/block-context-menu.mjs +130 -0
  71. package/dist/src/components/editor/ui/block-discussion.mjs +200 -0
  72. package/dist/src/components/editor/ui/block-draggable.mjs +265 -0
  73. package/dist/src/components/editor/ui/block-list-static.mjs +48 -0
  74. package/dist/src/components/editor/ui/block-list.mjs +47 -0
  75. package/dist/src/components/editor/ui/block-selection.mjs +28 -0
  76. package/dist/src/components/editor/ui/block-suggestion.mjs +319 -0
  77. package/dist/src/components/editor/ui/blockquote-node-static.mjs +14 -0
  78. package/dist/src/components/editor/ui/blockquote-node.mjs +16 -0
  79. package/dist/src/components/editor/ui/callout-node-static.mjs +29 -0
  80. package/dist/src/components/editor/ui/callout-node.mjs +50 -0
  81. package/dist/src/components/editor/ui/caption.mjs +39 -0
  82. package/dist/src/components/editor/ui/code-block-node-static.mjs +30 -0
  83. package/dist/src/components/editor/ui/code-block-node.mjs +121 -0
  84. package/dist/src/components/editor/ui/code-node-static.mjs +15 -0
  85. package/dist/src/components/editor/ui/code-node.mjs +17 -0
  86. package/dist/src/components/editor/ui/column-node-static.mjs +32 -0
  87. package/dist/src/components/editor/ui/column-node.mjs +229 -0
  88. package/dist/src/components/editor/ui/comment-node-static.mjs +14 -0
  89. package/dist/src/components/editor/ui/comment-node.mjs +33 -0
  90. package/dist/src/components/editor/ui/comment-toolbar-button.mjs +23 -0
  91. package/dist/src/components/editor/ui/comment.mjs +422 -0
  92. package/dist/src/components/editor/ui/cursor-overlay.mjs +36 -0
  93. package/dist/src/components/editor/ui/date-node-static.mjs +32 -0
  94. package/dist/src/components/editor/ui/date-node.mjs +60 -0
  95. package/dist/src/components/editor/ui/editor-static.mjs +31 -0
  96. package/dist/src/components/editor/ui/editor.mjs +60 -0
  97. package/dist/src/components/editor/ui/emoji-node.mjs +46 -0
  98. package/dist/src/components/editor/ui/emoji-toolbar-button.mjs +415 -0
  99. package/dist/src/components/editor/ui/equation-node-static.mjs +65 -0
  100. package/dist/src/components/editor/ui/equation-node.mjs +159 -0
  101. package/dist/src/components/editor/ui/equation-toolbar-button.mjs +23 -0
  102. package/dist/src/components/editor/ui/fixed-toolbar-buttons.mjs +109 -0
  103. package/dist/src/components/editor/ui/fixed-toolbar.mjs +16 -0
  104. package/dist/src/components/editor/ui/floating-toolbar-buttons.mjs +54 -0
  105. package/dist/src/components/editor/ui/floating-toolbar.mjs +51 -0
  106. package/dist/src/components/editor/ui/font-color-toolbar-button.mjs +637 -0
  107. package/dist/src/components/editor/ui/font-size-toolbar-button.mjs +83 -0
  108. package/dist/src/components/editor/ui/ghost-text.mjs +22 -0
  109. package/dist/src/components/editor/ui/heading-node-static.mjs +60 -0
  110. package/dist/src/components/editor/ui/heading-node.mjs +62 -0
  111. package/dist/src/components/editor/ui/highlight-node-static.mjs +15 -0
  112. package/dist/src/components/editor/ui/highlight-node.mjs +17 -0
  113. package/dist/src/components/editor/ui/history-toolbar-button.mjs +35 -0
  114. package/dist/src/components/editor/ui/hr-node-static.mjs +18 -0
  115. package/dist/src/components/editor/ui/hr-node.mjs +23 -0
  116. package/dist/src/components/editor/ui/indent-toolbar-button.mjs +29 -0
  117. package/dist/src/components/editor/ui/inline-combobox.mjs +148 -0
  118. package/dist/src/components/editor/ui/insert-toolbar-button.mjs +199 -0
  119. package/dist/src/components/editor/ui/kbd-node-static.mjs +15 -0
  120. package/dist/src/components/editor/ui/kbd-node.mjs +17 -0
  121. package/dist/src/components/editor/ui/line-height-toolbar-button.mjs +56 -0
  122. package/dist/src/components/editor/ui/link-node-static.mjs +20 -0
  123. package/dist/src/components/editor/ui/link-node.mjs +28 -0
  124. package/dist/src/components/editor/ui/link-toolbar-button.mjs +21 -0
  125. package/dist/src/components/editor/ui/link-toolbar.mjs +141 -0
  126. package/dist/src/components/editor/ui/list-toolbar-button.mjs +131 -0
  127. package/dist/src/components/editor/ui/mark-toolbar-button.mjs +20 -0
  128. package/dist/src/components/editor/ui/media-image-node-static.mjs +32 -0
  129. package/dist/src/components/editor/ui/media-image-node.mjs +64 -0
  130. package/dist/src/components/editor/ui/media-placeholder-node.mjs +184 -0
  131. package/dist/src/components/editor/ui/media-preview-dialog.mjs +113 -0
  132. package/dist/src/components/editor/ui/media-toolbar-button.mjs +156 -0
  133. package/dist/src/components/editor/ui/media-toolbar.mjs +80 -0
  134. package/dist/src/components/editor/ui/media-upload-toast.mjs +39 -0
  135. package/dist/src/components/editor/ui/media-video-node-static.mjs +27 -0
  136. package/dist/src/components/editor/ui/mode-toolbar-button.mjs +112 -0
  137. package/dist/src/components/editor/ui/paragraph-node-static.mjs +15 -0
  138. package/dist/src/components/editor/ui/paragraph-node.mjs +17 -0
  139. package/dist/src/components/editor/ui/resize-handle.mjs +43 -0
  140. package/dist/src/components/editor/ui/slash-node.mjs +228 -0
  141. package/dist/src/components/editor/ui/suggestion-node-static.mjs +24 -0
  142. package/dist/src/components/editor/ui/suggestion-node.mjs +111 -0
  143. package/dist/src/components/editor/ui/suggestion-toolbar-button.mjs +24 -0
  144. package/dist/src/components/editor/ui/table-icons.mjs +1310 -0
  145. package/dist/src/components/editor/ui/table-node-static.mjs +68 -0
  146. package/dist/src/components/editor/ui/table-node.mjs +375 -0
  147. package/dist/src/components/editor/ui/table-toolbar-button.mjs +190 -0
  148. package/dist/src/components/editor/ui/turn-into-toolbar-button.mjs +168 -0
  149. package/dist/src/components/editor/use-chat.mjs +80 -0
  150. package/dist/src/components/json-schema-editor/client.mjs +46 -0
  151. package/dist/src/components/json-schema-editor/components/inputs.mjs +438 -0
  152. package/dist/src/components/json-schema-editor/get-default-values.mjs +23 -0
  153. package/dist/src/components/json-schema-editor/schema.mjs +131 -0
  154. package/dist/src/components/json-schema-editor/utils/merge-schema.mjs +134 -0
  155. package/dist/src/components/json-schema-editor/utils/schema-to-string.mjs +53 -0
  156. package/dist/src/components/ui/alert-dialog.mjs +90 -0
  157. package/dist/src/components/ui/avatar.mjs +32 -0
  158. package/dist/src/components/ui/button.mjs +48 -0
  159. package/dist/src/components/ui/calendar.mjs +108 -0
  160. package/dist/src/components/ui/checkbox.mjs +23 -0
  161. package/dist/src/components/ui/combobox.mjs +53 -0
  162. package/dist/src/components/ui/command.mjs +42 -0
  163. package/dist/src/components/ui/context-menu.mjs +67 -0
  164. package/dist/src/components/ui/dialog.mjs +9 -0
  165. package/dist/src/components/ui/dropdown-menu.mjs +122 -0
  166. package/dist/src/components/ui/input-group.mjs +31 -0
  167. package/dist/src/components/ui/input.mjs +15 -0
  168. package/dist/src/components/ui/label.mjs +19 -0
  169. package/dist/src/components/ui/popover.mjs +37 -0
  170. package/dist/src/components/ui/select.mjs +80 -0
  171. package/dist/src/components/ui/separator.mjs +19 -0
  172. package/dist/src/components/ui/spinner.mjs +16 -0
  173. package/dist/src/components/ui/tabs.mjs +39 -0
  174. package/dist/src/components/ui/textarea.mjs +14 -0
  175. package/dist/src/components/ui/toolbar.mjs +183 -0
  176. package/dist/src/components/ui/tooltip.mjs +38 -0
  177. package/dist/src/hooks/editor/use-is-creator.mjs +19 -0
  178. package/dist/src/hooks/use-upload-file.mjs +73 -0
  179. package/dist/src/lib/config.mjs +38 -0
  180. package/dist/src/lib/data/store.d.mts +15 -0
  181. package/dist/src/lib/lowlight.mjs +7 -0
  182. package/dist/src/lib/utils/deep-equal.mjs +18 -0
  183. package/dist/src/lib/utils/remove-undefined.mjs +18 -0
  184. package/dist/src/lib/utils.mjs +10 -0
  185. package/dist/types.d.mts +50 -0
  186. package/next.config.ts +23 -0
  187. package/package.json +131 -0
  188. package/postcss.config.mjs +7 -0
  189. package/src/app/(dashboard)/collection/[name]/[...slug]/page.client.tsx +26 -0
  190. package/src/app/(dashboard)/collection/[name]/[...slug]/page.tsx +17 -0
  191. package/src/app/(dashboard)/collection/[name]/page.client.tsx +82 -0
  192. package/src/app/(dashboard)/collection/[name]/page.tsx +11 -0
  193. package/src/app/(dashboard)/layout.tsx +34 -0
  194. package/src/app/(dashboard)/page.tsx +38 -0
  195. package/src/app/api/ai/command/prompts.ts +313 -0
  196. package/src/app/api/ai/command/route.ts +203 -0
  197. package/src/app/api/ai/command/utils.ts +242 -0
  198. package/src/app/api/ai/copilot/route.ts +33 -0
  199. package/src/app/api/uploadthing/route.ts +5 -0
  200. package/src/app/codeblock/LICENSE +21 -0
  201. package/src/app/codeblock/styles.css +289 -0
  202. package/src/app/favicon.ico +0 -0
  203. package/src/app/globals.css +223 -0
  204. package/src/app/layout.client.tsx +15 -0
  205. package/src/app/layout.tsx +30 -0
  206. package/src/components/app-sidebar.tsx +162 -0
  207. package/src/components/code-editor/mdx.lazy.tsx +18 -0
  208. package/src/components/code-editor/mdx.tsx +48 -0
  209. package/src/components/code-editor/yaml.lazy.tsx +20 -0
  210. package/src/components/code-editor/yaml.tsx +71 -0
  211. package/src/components/collection/actions.tsx +41 -0
  212. package/src/components/collection/client.tsx +63 -0
  213. package/src/components/collection/context.tsx +24 -0
  214. package/src/components/collection/document/actions.tsx +83 -0
  215. package/src/components/editor/editor-base-kit.tsx +37 -0
  216. package/src/components/editor/editor-kit.tsx +87 -0
  217. package/src/components/editor/md.tsx +60 -0
  218. package/src/components/editor/plugins/ai-kit.tsx +102 -0
  219. package/src/components/editor/plugins/align-base-kit.tsx +16 -0
  220. package/src/components/editor/plugins/align-kit.tsx +18 -0
  221. package/src/components/editor/plugins/autoformat-kit.tsx +236 -0
  222. package/src/components/editor/plugins/basic-blocks-base-kit.tsx +34 -0
  223. package/src/components/editor/plugins/basic-blocks-kit.tsx +87 -0
  224. package/src/components/editor/plugins/basic-marks-base-kit.tsx +26 -0
  225. package/src/components/editor/plugins/basic-marks-kit.tsx +40 -0
  226. package/src/components/editor/plugins/basic-nodes-kit.tsx +6 -0
  227. package/src/components/editor/plugins/block-menu-kit.tsx +14 -0
  228. package/src/components/editor/plugins/block-placeholder-kit.tsx +17 -0
  229. package/src/components/editor/plugins/block-selection-kit.tsx +54 -0
  230. package/src/components/editor/plugins/callout-base-kit.tsx +5 -0
  231. package/src/components/editor/plugins/callout-kit.tsx +7 -0
  232. package/src/components/editor/plugins/code-block-base-kit.tsx +16 -0
  233. package/src/components/editor/plugins/code-block-kit.tsx +19 -0
  234. package/src/components/editor/plugins/column-base-kit.tsx +11 -0
  235. package/src/components/editor/plugins/column-kit.tsx +10 -0
  236. package/src/components/editor/plugins/comment-base-kit.tsx +5 -0
  237. package/src/components/editor/plugins/comment-kit.tsx +92 -0
  238. package/src/components/editor/plugins/copilot-kit.tsx +70 -0
  239. package/src/components/editor/plugins/cursor-overlay-kit.tsx +13 -0
  240. package/src/components/editor/plugins/date-base-kit.tsx +5 -0
  241. package/src/components/editor/plugins/date-kit.tsx +7 -0
  242. package/src/components/editor/plugins/discussion-kit.tsx +142 -0
  243. package/src/components/editor/plugins/dnd-kit.tsx +25 -0
  244. package/src/components/editor/plugins/emoji-kit.tsx +13 -0
  245. package/src/components/editor/plugins/exit-break-kit.tsx +12 -0
  246. package/src/components/editor/plugins/fixed-toolbar-kit.tsx +19 -0
  247. package/src/components/editor/plugins/floating-toolbar-kit.tsx +19 -0
  248. package/src/components/editor/plugins/font-base-kit.tsx +20 -0
  249. package/src/components/editor/plugins/font-kit.tsx +29 -0
  250. package/src/components/editor/plugins/indent-base-kit.tsx +13 -0
  251. package/src/components/editor/plugins/indent-kit.tsx +22 -0
  252. package/src/components/editor/plugins/line-height-base-kit.tsx +14 -0
  253. package/src/components/editor/plugins/line-height-kit.tsx +16 -0
  254. package/src/components/editor/plugins/link-base-kit.tsx +5 -0
  255. package/src/components/editor/plugins/link-kit.tsx +15 -0
  256. package/src/components/editor/plugins/list-base-kit.tsx +17 -0
  257. package/src/components/editor/plugins/list-kit.tsx +26 -0
  258. package/src/components/editor/plugins/markdown-kit.tsx +13 -0
  259. package/src/components/editor/plugins/math-base-kit.tsx +11 -0
  260. package/src/components/editor/plugins/math-kit.tsx +10 -0
  261. package/src/components/editor/plugins/media-base-kit.tsx +25 -0
  262. package/src/components/editor/plugins/media-kit.tsx +28 -0
  263. package/src/components/editor/plugins/slash-kit.tsx +18 -0
  264. package/src/components/editor/plugins/suggestion-base-kit.tsx +5 -0
  265. package/src/components/editor/plugins/suggestion-kit.tsx +83 -0
  266. package/src/components/editor/plugins/table-base-kit.tsx +20 -0
  267. package/src/components/editor/plugins/table-kit.tsx +22 -0
  268. package/src/components/editor/settings-dialog.tsx +418 -0
  269. package/src/components/editor/transforms.ts +193 -0
  270. package/src/components/editor/types.ts +149 -0
  271. package/src/components/editor/ui/ai-chat-editor.tsx +20 -0
  272. package/src/components/editor/ui/ai-menu.tsx +663 -0
  273. package/src/components/editor/ui/ai-node.tsx +40 -0
  274. package/src/components/editor/ui/ai-toolbar-button.tsx +23 -0
  275. package/src/components/editor/ui/align-toolbar-button.tsx +78 -0
  276. package/src/components/editor/ui/block-context-menu.tsx +154 -0
  277. package/src/components/editor/ui/block-discussion.tsx +318 -0
  278. package/src/components/editor/ui/block-draggable.tsx +464 -0
  279. package/src/components/editor/ui/block-list-static.tsx +75 -0
  280. package/src/components/editor/ui/block-list.tsx +72 -0
  281. package/src/components/editor/ui/block-selection.tsx +37 -0
  282. package/src/components/editor/ui/block-suggestion.tsx +438 -0
  283. package/src/components/editor/ui/blockquote-node-static.tsx +5 -0
  284. package/src/components/editor/ui/blockquote-node.tsx +7 -0
  285. package/src/components/editor/ui/callout-node-static.tsx +30 -0
  286. package/src/components/editor/ui/callout-node.tsx +64 -0
  287. package/src/components/editor/ui/caption.tsx +55 -0
  288. package/src/components/editor/ui/code-block-node-static.tsx +33 -0
  289. package/src/components/editor/ui/code-block-node.tsx +161 -0
  290. package/src/components/editor/ui/code-node-static.tsx +15 -0
  291. package/src/components/editor/ui/code-node.tsx +17 -0
  292. package/src/components/editor/ui/column-node-static.tsx +27 -0
  293. package/src/components/editor/ui/column-node.tsx +285 -0
  294. package/src/components/editor/ui/comment-node-static.tsx +12 -0
  295. package/src/components/editor/ui/comment-node.tsx +43 -0
  296. package/src/components/editor/ui/comment-toolbar-button.tsx +24 -0
  297. package/src/components/editor/ui/comment.tsx +577 -0
  298. package/src/components/editor/ui/cursor-overlay.tsx +66 -0
  299. package/src/components/editor/ui/date-node-static.tsx +45 -0
  300. package/src/components/editor/ui/date-node.tsx +86 -0
  301. package/src/components/editor/ui/editor-static.tsx +47 -0
  302. package/src/components/editor/ui/editor.tsx +120 -0
  303. package/src/components/editor/ui/emoji-node.tsx +65 -0
  304. package/src/components/editor/ui/emoji-toolbar-button.tsx +582 -0
  305. package/src/components/editor/ui/equation-node-static.tsx +94 -0
  306. package/src/components/editor/ui/equation-node.tsx +218 -0
  307. package/src/components/editor/ui/equation-toolbar-button.tsx +24 -0
  308. package/src/components/editor/ui/fixed-toolbar-buttons.tsx +135 -0
  309. package/src/components/editor/ui/fixed-toolbar.tsx +17 -0
  310. package/src/components/editor/ui/floating-toolbar-buttons.tsx +72 -0
  311. package/src/components/editor/ui/floating-toolbar.tsx +76 -0
  312. package/src/components/editor/ui/font-color-toolbar-button.tsx +804 -0
  313. package/src/components/editor/ui/font-size-toolbar-button.tsx +102 -0
  314. package/src/components/editor/ui/ghost-text.tsx +27 -0
  315. package/src/components/editor/ui/heading-node-static.tsx +54 -0
  316. package/src/components/editor/ui/heading-node.tsx +54 -0
  317. package/src/components/editor/ui/highlight-node-static.tsx +11 -0
  318. package/src/components/editor/ui/highlight-node.tsx +13 -0
  319. package/src/components/editor/ui/history-toolbar-button.tsx +41 -0
  320. package/src/components/editor/ui/hr-node-static.tsx +16 -0
  321. package/src/components/editor/ui/hr-node.tsx +28 -0
  322. package/src/components/editor/ui/indent-toolbar-button.tsx +27 -0
  323. package/src/components/editor/ui/inline-combobox.tsx +251 -0
  324. package/src/components/editor/ui/insert-toolbar-button.tsx +242 -0
  325. package/src/components/editor/ui/kbd-node-static.tsx +15 -0
  326. package/src/components/editor/ui/kbd-node.tsx +17 -0
  327. package/src/components/editor/ui/line-height-toolbar-button.tsx +66 -0
  328. package/src/components/editor/ui/link-node-static.tsx +21 -0
  329. package/src/components/editor/ui/link-node.tsx +37 -0
  330. package/src/components/editor/ui/link-toolbar-button.tsx +18 -0
  331. package/src/components/editor/ui/link-toolbar.tsx +196 -0
  332. package/src/components/editor/ui/list-toolbar-button.tsx +195 -0
  333. package/src/components/editor/ui/mark-toolbar-button.tsx +20 -0
  334. package/src/components/editor/ui/media-image-node-static.tsx +33 -0
  335. package/src/components/editor/ui/media-image-node.tsx +75 -0
  336. package/src/components/editor/ui/media-placeholder-node.tsx +235 -0
  337. package/src/components/editor/ui/media-preview-dialog.tsx +145 -0
  338. package/src/components/editor/ui/media-toolbar-button.tsx +202 -0
  339. package/src/components/editor/ui/media-toolbar.tsx +100 -0
  340. package/src/components/editor/ui/media-upload-toast.tsx +59 -0
  341. package/src/components/editor/ui/media-video-node-static.tsx +23 -0
  342. package/src/components/editor/ui/mode-toolbar-button.tsx +121 -0
  343. package/src/components/editor/ui/paragraph-node-static.tsx +13 -0
  344. package/src/components/editor/ui/paragraph-node.tsx +15 -0
  345. package/src/components/editor/ui/resize-handle.tsx +79 -0
  346. package/src/components/editor/ui/slash-node.tsx +274 -0
  347. package/src/components/editor/ui/suggestion-node-static.tsx +30 -0
  348. package/src/components/editor/ui/suggestion-node.tsx +157 -0
  349. package/src/components/editor/ui/suggestion-toolbar-button.tsx +25 -0
  350. package/src/components/editor/ui/table-icons.tsx +685 -0
  351. package/src/components/editor/ui/table-node-static.tsx +86 -0
  352. package/src/components/editor/ui/table-node.tsx +569 -0
  353. package/src/components/editor/ui/table-toolbar-button.tsx +260 -0
  354. package/src/components/editor/ui/turn-into-toolbar-button.tsx +176 -0
  355. package/src/components/editor/use-chat.ts +120 -0
  356. package/src/components/icons/logo.tsx +37 -0
  357. package/src/components/json-schema-editor/client.tsx +55 -0
  358. package/src/components/json-schema-editor/components/inputs.tsx +612 -0
  359. package/src/components/json-schema-editor/get-default-values.ts +29 -0
  360. package/src/components/json-schema-editor/schema.tsx +206 -0
  361. package/src/components/json-schema-editor/utils/merge-schema.ts +167 -0
  362. package/src/components/json-schema-editor/utils/schema-to-string.ts +87 -0
  363. package/src/components/nav-user.tsx +102 -0
  364. package/src/components/site-header.tsx +13 -0
  365. package/src/components/ui/alert-dialog.tsx +182 -0
  366. package/src/components/ui/avatar.tsx +96 -0
  367. package/src/components/ui/badge.tsx +46 -0
  368. package/src/components/ui/button.tsx +65 -0
  369. package/src/components/ui/calendar.tsx +186 -0
  370. package/src/components/ui/checkbox.tsx +29 -0
  371. package/src/components/ui/combobox.tsx +267 -0
  372. package/src/components/ui/command.tsx +180 -0
  373. package/src/components/ui/context-menu.tsx +161 -0
  374. package/src/components/ui/dialog.tsx +142 -0
  375. package/src/components/ui/drawer.tsx +120 -0
  376. package/src/components/ui/dropdown-menu.tsx +239 -0
  377. package/src/components/ui/field.tsx +224 -0
  378. package/src/components/ui/input-group.tsx +144 -0
  379. package/src/components/ui/input.tsx +19 -0
  380. package/src/components/ui/label.tsx +18 -0
  381. package/src/components/ui/popover.tsx +76 -0
  382. package/src/components/ui/select.tsx +182 -0
  383. package/src/components/ui/separator.tsx +28 -0
  384. package/src/components/ui/sheet.tsx +130 -0
  385. package/src/components/ui/sidebar.tsx +608 -0
  386. package/src/components/ui/sonner.tsx +45 -0
  387. package/src/components/ui/spinner.tsx +15 -0
  388. package/src/components/ui/table.tsx +89 -0
  389. package/src/components/ui/tabs.tsx +60 -0
  390. package/src/components/ui/textarea.tsx +18 -0
  391. package/src/components/ui/toggle-group.tsx +86 -0
  392. package/src/components/ui/toggle.tsx +45 -0
  393. package/src/components/ui/toolbar.tsx +365 -0
  394. package/src/components/ui/tooltip.tsx +57 -0
  395. package/src/hooks/editor/use-is-creator.ts +21 -0
  396. package/src/hooks/use-mobile.ts +19 -0
  397. package/src/hooks/use-mounted.ts +11 -0
  398. package/src/hooks/use-upload-file.ts +121 -0
  399. package/src/lib/ai/markdown-joiner-transform.ts +235 -0
  400. package/src/lib/config.ts +60 -0
  401. package/src/lib/data/actions.ts +51 -0
  402. package/src/lib/data/boundary.client.tsx +22 -0
  403. package/src/lib/data/boundary.tsx +22 -0
  404. package/src/lib/data/query.ts +9 -0
  405. package/src/lib/data/store.ts +52 -0
  406. package/src/lib/lowlight.ts +3 -0
  407. package/src/lib/uploadthing.ts +19 -0
  408. package/src/lib/utils/deep-equal.ts +37 -0
  409. package/src/lib/utils/remove-undefined.ts +21 -0
  410. package/src/lib/utils/urls.ts +6 -0
  411. package/src/lib/utils.ts +6 -0
  412. package/tsconfig.build.json +24 -0
  413. package/tsconfig.json +37 -0
@@ -0,0 +1,663 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ import { AIChatPlugin, AIPlugin, useEditorChat, useLastAssistantMessage } from "@platejs/ai/react";
6
+ import { getTransientCommentKey } from "@platejs/comment";
7
+ import { BlockSelectionPlugin, useIsSelecting } from "@platejs/selection/react";
8
+ import { getTransientSuggestionKey } from "@platejs/suggestion";
9
+ import { Command as CommandPrimitive } from "cmdk";
10
+ import {
11
+ Album,
12
+ BadgeHelp,
13
+ BookOpenCheck,
14
+ Check,
15
+ CornerUpLeft,
16
+ FeatherIcon,
17
+ ListEnd,
18
+ ListMinus,
19
+ ListPlus,
20
+ Loader2Icon,
21
+ PauseIcon,
22
+ PenLine,
23
+ SmileIcon,
24
+ Wand,
25
+ X,
26
+ } from "lucide-react";
27
+ import { type NodeEntry, type SlateEditor, isHotkey, KEYS, NodeApi, TextApi } from "platejs";
28
+ import { useEditorPlugin, useFocusedLast, useHotkeys, usePluginOption } from "platejs/react";
29
+ import { type PlateEditor, useEditorRef } from "platejs/react";
30
+
31
+ import { Button } from "@/components/ui/button";
32
+ import { Command, CommandGroup, CommandItem, CommandList } from "@/components/ui/command";
33
+ import { Popover, PopoverAnchor, PopoverContent } from "@/components/ui/popover";
34
+ import { cn } from "@/lib/utils";
35
+ import { commentPlugin } from "@/components/editor/plugins/comment-kit";
36
+
37
+ import { AIChatEditor } from "./ai-chat-editor";
38
+
39
+ export function AIMenu() {
40
+ const { api, editor } = useEditorPlugin(AIChatPlugin);
41
+ const mode = usePluginOption(AIChatPlugin, "mode");
42
+ const toolName = usePluginOption(AIChatPlugin, "toolName");
43
+
44
+ const streaming = usePluginOption(AIChatPlugin, "streaming");
45
+ const isSelecting = useIsSelecting();
46
+ const isFocusedLast = useFocusedLast();
47
+ const open = usePluginOption(AIChatPlugin, "open") && isFocusedLast;
48
+ const [value, setValue] = React.useState("");
49
+
50
+ const [input, setInput] = React.useState("");
51
+
52
+ const chat = usePluginOption(AIChatPlugin, "chat");
53
+
54
+ const { messages, status } = chat;
55
+ const [anchorElement, setAnchorElement] = React.useState<HTMLElement | null>(null);
56
+
57
+ const content = useLastAssistantMessage()?.parts.find((part) => part.type === "text")?.text;
58
+
59
+ React.useEffect(() => {
60
+ if (streaming) {
61
+ const anchor = api.aiChat.node({ anchor: true });
62
+ if (!anchor) return;
63
+
64
+ setTimeout(() => {
65
+ const anchorDom = editor.api.toDOMNode(anchor[0])!;
66
+ setAnchorElement(anchorDom);
67
+ }, 0);
68
+ }
69
+ // eslint-disable-next-line react-hooks/exhaustive-deps
70
+ }, [streaming]);
71
+
72
+ const setOpen = (open: boolean) => {
73
+ if (open) {
74
+ api.aiChat.show();
75
+ } else {
76
+ api.aiChat.hide();
77
+ }
78
+ };
79
+
80
+ const show = (anchorElement: HTMLElement) => {
81
+ setAnchorElement(anchorElement);
82
+ setOpen(true);
83
+ };
84
+
85
+ useEditorChat({
86
+ onOpenBlockSelection: (blocks: NodeEntry[]) => {
87
+ if (blocks.length > 0 && blocks[blocks.length - 1].length > 0)
88
+ show(editor.api.toDOMNode(blocks[blocks.length - 1][0])!);
89
+ },
90
+ onOpenChange: (open) => {
91
+ if (!open) {
92
+ setAnchorElement(null);
93
+ setInput("");
94
+ }
95
+ },
96
+ onOpenCursor: () => {
97
+ const [ancestor] = editor.api.block({ highest: true })!;
98
+
99
+ if (!editor.api.isAt({ end: true }) && !editor.api.isEmpty(ancestor)) {
100
+ editor.getApi(BlockSelectionPlugin).blockSelection.set(ancestor.id as string);
101
+ }
102
+
103
+ show(editor.api.toDOMNode(ancestor)!);
104
+ },
105
+ onOpenSelection: () => {
106
+ const blocks = editor.api.blocks();
107
+ if (blocks.length > 0 && blocks[blocks.length - 1].length > 0)
108
+ show(editor.api.toDOMNode(blocks[blocks.length - 1][0])!);
109
+ },
110
+ });
111
+
112
+ useHotkeys("esc", () => {
113
+ api.aiChat.stop();
114
+ });
115
+
116
+ const isLoading = status === "streaming" || status === "submitted";
117
+
118
+ React.useEffect(() => {
119
+ if (toolName === "edit" && mode === "chat" && !isLoading) {
120
+ let anchorNode = editor.api.node({
121
+ at: [],
122
+ reverse: true,
123
+ match: (n) => !!n[KEYS.suggestion] && !!n[getTransientSuggestionKey()],
124
+ });
125
+
126
+ if (!anchorNode) {
127
+ anchorNode = editor
128
+ .getApi(BlockSelectionPlugin)
129
+ .blockSelection.getNodes({ selectionFallback: true, sort: true })
130
+ .at(-1);
131
+ }
132
+
133
+ if (!anchorNode) return;
134
+
135
+ const block = editor.api.block({ at: anchorNode[1] });
136
+ if (block) setAnchorElement(editor.api.toDOMNode(block[0])!);
137
+ }
138
+ // eslint-disable-next-line react-hooks/exhaustive-deps
139
+ }, [isLoading]);
140
+
141
+ if (isLoading && mode === "insert") return null;
142
+
143
+ if (toolName === "comment") return null;
144
+
145
+ if (toolName === "edit" && mode === "chat" && isLoading) return null;
146
+
147
+ return (
148
+ <Popover open={open} onOpenChange={setOpen} modal={false}>
149
+ <PopoverAnchor virtualRef={{ current: anchorElement! }} />
150
+
151
+ <PopoverContent
152
+ className="border-none bg-transparent p-0 shadow-none"
153
+ style={{
154
+ width: anchorElement?.offsetWidth,
155
+ }}
156
+ onEscapeKeyDown={(e) => {
157
+ e.preventDefault();
158
+
159
+ api.aiChat.hide();
160
+ }}
161
+ align="center"
162
+ side="bottom"
163
+ >
164
+ <Command
165
+ className="w-full rounded-lg border shadow-md"
166
+ value={value}
167
+ onValueChange={setValue}
168
+ >
169
+ {mode === "chat" && isSelecting && content && toolName === "generate" && (
170
+ <AIChatEditor content={content} />
171
+ )}
172
+
173
+ {isLoading ? (
174
+ <div className="flex grow select-none items-center gap-2 p-2 text-muted-foreground text-sm">
175
+ <Loader2Icon className="size-4 animate-spin" />
176
+ {messages.length > 1 ? "Editing..." : "Thinking..."}
177
+ </div>
178
+ ) : (
179
+ <CommandPrimitive.Input
180
+ className={cn(
181
+ "flex h-9 w-full min-w-0 border-input bg-transparent px-3 py-1 text-base outline-none transition-[color,box-shadow] placeholder:text-muted-foreground md:text-sm dark:bg-input/30",
182
+ "aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40",
183
+ "border-b focus-visible:ring-transparent",
184
+ )}
185
+ value={input}
186
+ onKeyDown={(e) => {
187
+ if (isHotkey("backspace")(e) && input.length === 0) {
188
+ e.preventDefault();
189
+ api.aiChat.hide();
190
+ }
191
+ if (isHotkey("enter")(e) && !e.shiftKey && !value) {
192
+ e.preventDefault();
193
+ void api.aiChat.submit(input);
194
+ setInput("");
195
+ }
196
+ }}
197
+ onValueChange={setInput}
198
+ placeholder="Ask AI anything..."
199
+ data-plate-focus
200
+ autoFocus
201
+ />
202
+ )}
203
+
204
+ {!isLoading && (
205
+ <CommandList>
206
+ <AIMenuItems input={input} setInput={setInput} setValue={setValue} />
207
+ </CommandList>
208
+ )}
209
+ </Command>
210
+ </PopoverContent>
211
+ </Popover>
212
+ );
213
+ }
214
+
215
+ type EditorChatState =
216
+ | "cursorCommand"
217
+ | "cursorSuggestion"
218
+ | "selectionCommand"
219
+ | "selectionSuggestion";
220
+
221
+ const AICommentIcon = () => (
222
+ <svg
223
+ fill="none"
224
+ height="24"
225
+ stroke="currentColor"
226
+ strokeLinecap="round"
227
+ strokeLinejoin="round"
228
+ strokeWidth="2"
229
+ viewBox="0 0 24 24"
230
+ width="24"
231
+ xmlns="http://www.w3.org/2000/svg"
232
+ >
233
+ <path d="M0 0h24v24H0z" fill="none" stroke="none" />
234
+ <path d="M8 9h8" />
235
+ <path d="M8 13h4.5" />
236
+ <path d="M10 19l-1 -1h-3a3 3 0 0 1 -3 -3v-8a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v4.5" />
237
+ <path d="M17.8 20.817l-2.172 1.138a.392 .392 0 0 1 -.568 -.41l.415 -2.411l-1.757 -1.707a.389 .389 0 0 1 .217 -.665l2.428 -.352l1.086 -2.193a.392 .392 0 0 1 .702 0l1.086 2.193l2.428 .352a.39 .39 0 0 1 .217 .665l-1.757 1.707l.414 2.41a.39 .39 0 0 1 -.567 .411l-2.172 -1.138z" />
238
+ </svg>
239
+ );
240
+
241
+ const aiChatItems = {
242
+ accept: {
243
+ icon: <Check />,
244
+ label: "Accept",
245
+ value: "accept",
246
+ onSelect: ({ aiEditor, editor }) => {
247
+ const { mode, toolName } = editor.getOptions(AIChatPlugin);
248
+
249
+ if (mode === "chat" && toolName === "generate") {
250
+ return editor.getTransforms(AIChatPlugin).aiChat.replaceSelection(aiEditor);
251
+ }
252
+
253
+ editor.getTransforms(AIChatPlugin).aiChat.accept();
254
+ editor.tf.focus({ edge: "end" });
255
+ },
256
+ },
257
+ comment: {
258
+ icon: <AICommentIcon />,
259
+ label: "Comment",
260
+ value: "comment",
261
+ onSelect: ({ editor, input }) => {
262
+ editor.getApi(AIChatPlugin).aiChat.submit(input, {
263
+ mode: "insert",
264
+ prompt:
265
+ "Please comment on the following content and provide reasonable and meaningful feedback.",
266
+ toolName: "comment",
267
+ });
268
+ },
269
+ },
270
+ continueWrite: {
271
+ icon: <PenLine />,
272
+ label: "Continue writing",
273
+ value: "continueWrite",
274
+ onSelect: ({ editor, input }) => {
275
+ const ancestorNode = editor.api.block({ highest: true });
276
+
277
+ if (!ancestorNode) return;
278
+
279
+ const isEmpty = NodeApi.string(ancestorNode[0]).trim().length === 0;
280
+
281
+ void editor.getApi(AIChatPlugin).aiChat.submit(input, {
282
+ mode: "insert",
283
+ prompt: isEmpty
284
+ ? `<Document>
285
+ {editor}
286
+ </Document>
287
+ Start writing a new paragraph AFTER <Document> ONLY ONE SENTENCE`
288
+ : "Continue writing AFTER <Block> ONLY ONE SENTENCE. DONT REPEAT THE TEXT.",
289
+ toolName: "generate",
290
+ });
291
+ },
292
+ },
293
+ discard: {
294
+ icon: <X />,
295
+ label: "Discard",
296
+ shortcut: "Escape",
297
+ value: "discard",
298
+ onSelect: ({ editor }) => {
299
+ editor.getTransforms(AIPlugin).ai.undo();
300
+ editor.getApi(AIChatPlugin).aiChat.hide();
301
+ },
302
+ },
303
+ emojify: {
304
+ icon: <SmileIcon />,
305
+ label: "Emojify",
306
+ value: "emojify",
307
+ onSelect: ({ editor, input }) => {
308
+ void editor.getApi(AIChatPlugin).aiChat.submit(input, {
309
+ prompt: "Emojify",
310
+ toolName: "edit",
311
+ });
312
+ },
313
+ },
314
+ explain: {
315
+ icon: <BadgeHelp />,
316
+ label: "Explain",
317
+ value: "explain",
318
+ onSelect: ({ editor, input }) => {
319
+ void editor.getApi(AIChatPlugin).aiChat.submit(input, {
320
+ prompt: {
321
+ default: "Explain {editor}",
322
+ selecting: "Explain",
323
+ },
324
+ toolName: "generate",
325
+ });
326
+ },
327
+ },
328
+ fixSpelling: {
329
+ icon: <Check />,
330
+ label: "Fix spelling & grammar",
331
+ value: "fixSpelling",
332
+ onSelect: ({ editor, input }) => {
333
+ void editor.getApi(AIChatPlugin).aiChat.submit(input, {
334
+ prompt: "Fix spelling and grammar",
335
+ toolName: "edit",
336
+ });
337
+ },
338
+ },
339
+ generateMarkdownSample: {
340
+ icon: <BookOpenCheck />,
341
+ label: "Generate Markdown sample",
342
+ value: "generateMarkdownSample",
343
+ onSelect: ({ editor, input }) => {
344
+ void editor.getApi(AIChatPlugin).aiChat.submit(input, {
345
+ prompt: "Generate a markdown sample",
346
+ toolName: "generate",
347
+ });
348
+ },
349
+ },
350
+ generateMdxSample: {
351
+ icon: <BookOpenCheck />,
352
+ label: "Generate MDX sample",
353
+ value: "generateMdxSample",
354
+ onSelect: ({ editor, input }) => {
355
+ void editor.getApi(AIChatPlugin).aiChat.submit(input, {
356
+ prompt: "Generate a mdx sample",
357
+ toolName: "generate",
358
+ });
359
+ },
360
+ },
361
+ improveWriting: {
362
+ icon: <Wand />,
363
+ label: "Improve writing",
364
+ value: "improveWriting",
365
+ onSelect: ({ editor, input }) => {
366
+ void editor.getApi(AIChatPlugin).aiChat.submit(input, {
367
+ prompt: "Improve the writing",
368
+ toolName: "edit",
369
+ });
370
+ },
371
+ },
372
+ insertBelow: {
373
+ icon: <ListEnd />,
374
+ label: "Insert below",
375
+ value: "insertBelow",
376
+ onSelect: ({ aiEditor, editor }) => {
377
+ /** Format: 'none' Fix insert table */
378
+ void editor.getTransforms(AIChatPlugin).aiChat.insertBelow(aiEditor, { format: "none" });
379
+ },
380
+ },
381
+ makeLonger: {
382
+ icon: <ListPlus />,
383
+ label: "Make longer",
384
+ value: "makeLonger",
385
+ onSelect: ({ editor, input }) => {
386
+ void editor.getApi(AIChatPlugin).aiChat.submit(input, {
387
+ prompt: "Make longer",
388
+ toolName: "edit",
389
+ });
390
+ },
391
+ },
392
+ makeShorter: {
393
+ icon: <ListMinus />,
394
+ label: "Make shorter",
395
+ value: "makeShorter",
396
+ onSelect: ({ editor, input }) => {
397
+ void editor.getApi(AIChatPlugin).aiChat.submit(input, {
398
+ prompt: "Make shorter",
399
+ toolName: "edit",
400
+ });
401
+ },
402
+ },
403
+ replace: {
404
+ icon: <Check />,
405
+ label: "Replace selection",
406
+ value: "replace",
407
+ onSelect: ({ aiEditor, editor }) => {
408
+ void editor.getTransforms(AIChatPlugin).aiChat.replaceSelection(aiEditor);
409
+ },
410
+ },
411
+ simplifyLanguage: {
412
+ icon: <FeatherIcon />,
413
+ label: "Simplify language",
414
+ value: "simplifyLanguage",
415
+ onSelect: ({ editor, input }) => {
416
+ void editor.getApi(AIChatPlugin).aiChat.submit(input, {
417
+ prompt: "Simplify the language",
418
+ toolName: "edit",
419
+ });
420
+ },
421
+ },
422
+ summarize: {
423
+ icon: <Album />,
424
+ label: "Add a summary",
425
+ value: "summarize",
426
+ onSelect: ({ editor, input }) => {
427
+ void editor.getApi(AIChatPlugin).aiChat.submit(input, {
428
+ mode: "insert",
429
+ prompt: {
430
+ default: "Summarize {editor}",
431
+ selecting: "Summarize",
432
+ },
433
+ toolName: "generate",
434
+ });
435
+ },
436
+ },
437
+ tryAgain: {
438
+ icon: <CornerUpLeft />,
439
+ label: "Try again",
440
+ value: "tryAgain",
441
+ onSelect: ({ editor }) => {
442
+ void editor.getApi(AIChatPlugin).aiChat.reload();
443
+ },
444
+ },
445
+ } satisfies Record<
446
+ string,
447
+ {
448
+ icon: React.ReactNode;
449
+ label: string;
450
+ value: string;
451
+ component?: React.ComponentType<{ menuState: EditorChatState }>;
452
+ filterItems?: boolean;
453
+ items?: { label: string; value: string }[];
454
+ shortcut?: string;
455
+ onSelect?: ({
456
+ aiEditor,
457
+ editor,
458
+ input,
459
+ }: {
460
+ aiEditor: SlateEditor;
461
+ editor: PlateEditor;
462
+ input: string;
463
+ }) => void;
464
+ }
465
+ >;
466
+
467
+ const menuStateItems: Record<
468
+ EditorChatState,
469
+ {
470
+ items: (typeof aiChatItems)[keyof typeof aiChatItems][];
471
+ heading?: string;
472
+ }[]
473
+ > = {
474
+ cursorCommand: [
475
+ {
476
+ items: [
477
+ aiChatItems.comment,
478
+ aiChatItems.generateMdxSample,
479
+ aiChatItems.generateMarkdownSample,
480
+ aiChatItems.continueWrite,
481
+ aiChatItems.summarize,
482
+ aiChatItems.explain,
483
+ ],
484
+ },
485
+ ],
486
+ cursorSuggestion: [
487
+ {
488
+ items: [aiChatItems.accept, aiChatItems.discard, aiChatItems.tryAgain],
489
+ },
490
+ ],
491
+ selectionCommand: [
492
+ {
493
+ items: [
494
+ aiChatItems.improveWriting,
495
+ aiChatItems.comment,
496
+ aiChatItems.emojify,
497
+ aiChatItems.makeLonger,
498
+ aiChatItems.makeShorter,
499
+ aiChatItems.fixSpelling,
500
+ aiChatItems.simplifyLanguage,
501
+ ],
502
+ },
503
+ ],
504
+ selectionSuggestion: [
505
+ {
506
+ items: [
507
+ aiChatItems.accept,
508
+ aiChatItems.discard,
509
+ aiChatItems.insertBelow,
510
+ aiChatItems.tryAgain,
511
+ ],
512
+ },
513
+ ],
514
+ };
515
+
516
+ export const AIMenuItems = ({
517
+ input,
518
+ setInput,
519
+ setValue,
520
+ }: {
521
+ input: string;
522
+ setInput: (value: string) => void;
523
+ setValue: (value: string) => void;
524
+ }) => {
525
+ const editor = useEditorRef();
526
+ const { messages } = usePluginOption(AIChatPlugin, "chat");
527
+ const aiEditor = usePluginOption(AIChatPlugin, "aiEditor")!;
528
+ const isSelecting = useIsSelecting();
529
+
530
+ const menuState = React.useMemo(() => {
531
+ if (messages && messages.length > 0) {
532
+ return isSelecting ? "selectionSuggestion" : "cursorSuggestion";
533
+ }
534
+
535
+ return isSelecting ? "selectionCommand" : "cursorCommand";
536
+ }, [isSelecting, messages]);
537
+
538
+ const menuGroups = React.useMemo(() => {
539
+ const items = menuStateItems[menuState];
540
+
541
+ return items;
542
+ }, [menuState]);
543
+
544
+ React.useEffect(() => {
545
+ if (menuGroups.length > 0 && menuGroups[0].items.length > 0) {
546
+ setValue(menuGroups[0].items[0].value);
547
+ }
548
+ }, [menuGroups, setValue]);
549
+
550
+ return (
551
+ <>
552
+ {menuGroups.map((group, index) => (
553
+ <CommandGroup key={index} heading={group.heading}>
554
+ {group.items.map((menuItem) => (
555
+ <CommandItem
556
+ key={menuItem.value}
557
+ className="[&_svg]:text-muted-foreground"
558
+ value={menuItem.value}
559
+ onSelect={() => {
560
+ menuItem.onSelect?.({
561
+ aiEditor,
562
+ editor,
563
+ input,
564
+ });
565
+ setInput("");
566
+ }}
567
+ >
568
+ {menuItem.icon}
569
+ <span>{menuItem.label}</span>
570
+ </CommandItem>
571
+ ))}
572
+ </CommandGroup>
573
+ ))}
574
+ </>
575
+ );
576
+ };
577
+
578
+ export function AILoadingBar() {
579
+ const editor = useEditorRef();
580
+
581
+ const toolName = usePluginOption(AIChatPlugin, "toolName");
582
+ const chat = usePluginOption(AIChatPlugin, "chat");
583
+ const mode = usePluginOption(AIChatPlugin, "mode");
584
+
585
+ const { status } = chat;
586
+
587
+ const { api } = useEditorPlugin(AIChatPlugin);
588
+
589
+ const isLoading = status === "streaming" || status === "submitted";
590
+
591
+ const handleComments = (type: "accept" | "reject") => {
592
+ if (type === "accept") {
593
+ editor.tf.unsetNodes([getTransientCommentKey()], {
594
+ at: [],
595
+ match: (n) => TextApi.isText(n) && !!n[KEYS.comment],
596
+ });
597
+ }
598
+
599
+ if (type === "reject") {
600
+ editor.getTransforms(commentPlugin).comment.unsetMark({ transient: true });
601
+ }
602
+
603
+ api.aiChat.hide();
604
+ };
605
+
606
+ useHotkeys("esc", () => {
607
+ api.aiChat.stop();
608
+ });
609
+
610
+ if (
611
+ isLoading &&
612
+ (mode === "insert" || toolName === "comment" || (toolName === "edit" && mode === "chat"))
613
+ ) {
614
+ return (
615
+ <div
616
+ className={cn(
617
+ "-translate-x-1/2 absolute bottom-4 left-1/2 z-20 flex items-center gap-3 rounded-md border border-border bg-muted px-3 py-1.5 text-muted-foreground text-sm shadow-md transition-all duration-300",
618
+ )}
619
+ >
620
+ <span className="h-4 w-4 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent" />
621
+ <span>{status === "submitted" ? "Thinking..." : "Writing..."}</span>
622
+ <Button
623
+ size="sm"
624
+ variant="ghost"
625
+ className="flex items-center gap-1 text-xs"
626
+ onClick={() => api.aiChat.stop()}
627
+ >
628
+ <PauseIcon className="h-4 w-4" />
629
+ Stop
630
+ <kbd className="ml-1 rounded bg-border px-1 font-mono text-[10px] text-muted-foreground shadow-sm">
631
+ Esc
632
+ </kbd>
633
+ </Button>
634
+ </div>
635
+ );
636
+ }
637
+
638
+ if (toolName === "comment" && status === "ready") {
639
+ return (
640
+ <div
641
+ className={cn(
642
+ "-translate-x-1/2 absolute bottom-4 left-1/2 z-50 flex flex-col items-center gap-0 rounded-xl border border-border/50 bg-popover p-1 text-muted-foreground text-sm shadow-xl backdrop-blur-sm",
643
+ "p-3",
644
+ )}
645
+ >
646
+ {/* Header with controls */}
647
+ <div className="flex w-full items-center justify-between gap-3">
648
+ <div className="flex items-center gap-5">
649
+ <Button size="sm" disabled={isLoading} onClick={() => handleComments("accept")}>
650
+ Accept
651
+ </Button>
652
+
653
+ <Button size="sm" disabled={isLoading} onClick={() => handleComments("reject")}>
654
+ Reject
655
+ </Button>
656
+ </div>
657
+ </div>
658
+ </div>
659
+ );
660
+ }
661
+
662
+ return null;
663
+ }
@@ -0,0 +1,40 @@
1
+ "use client";
2
+
3
+ import { AIChatPlugin } from "@platejs/ai/react";
4
+ import {
5
+ type PlateElementProps,
6
+ type PlateTextProps,
7
+ PlateElement,
8
+ PlateText,
9
+ usePluginOption,
10
+ } from "platejs/react";
11
+
12
+ import { cn } from "@/lib/utils";
13
+
14
+ export function AILeaf(props: PlateTextProps) {
15
+ const streaming = usePluginOption(AIChatPlugin, "streaming");
16
+ const streamingLeaf = props.editor.getApi(AIChatPlugin).aiChat.node({ streaming: true });
17
+
18
+ const isLast = streamingLeaf?.[0] === props.text;
19
+
20
+ return (
21
+ <PlateText
22
+ className={cn(
23
+ "border-b-2 border-b-purple-100 bg-purple-50 text-purple-800",
24
+ "transition-all duration-200 ease-in-out",
25
+ isLast &&
26
+ streaming &&
27
+ 'after:ml-1.5 after:inline-block after:h-3 after:w-3 after:rounded-full after:bg-primary after:align-middle after:content-[""]',
28
+ )}
29
+ {...props}
30
+ />
31
+ );
32
+ }
33
+
34
+ export function AIAnchorElement(props: PlateElementProps) {
35
+ return (
36
+ <PlateElement {...props}>
37
+ <div className="h-[0.1px]" />
38
+ </PlateElement>
39
+ );
40
+ }