@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.
- package/dist/bin.d.mts +1 -0
- package/dist/bin.mjs +90 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.mjs +66 -0
- package/dist/mdx/actions.mjs +34 -0
- package/dist/mdx/client.mjs +167 -0
- package/dist/package.mjs +6 -0
- package/dist/src/components/code-editor/mdx.lazy.mjs +19 -0
- package/dist/src/components/code-editor/mdx.mjs +44 -0
- package/dist/src/components/code-editor/yaml.lazy.mjs +22 -0
- package/dist/src/components/code-editor/yaml.mjs +63 -0
- package/dist/src/components/editor/editor-base-kit.mjs +41 -0
- package/dist/src/components/editor/editor-kit.mjs +73 -0
- package/dist/src/components/editor/md.mjs +42 -0
- package/dist/src/components/editor/plugins/ai-kit.mjs +68 -0
- package/dist/src/components/editor/plugins/align-base-kit.mjs +28 -0
- package/dist/src/components/editor/plugins/align-kit.mjs +30 -0
- package/dist/src/components/editor/plugins/autoformat-kit.mjs +214 -0
- package/dist/src/components/editor/plugins/basic-blocks-base-kit.mjs +22 -0
- package/dist/src/components/editor/plugins/basic-blocks-kit.mjs +51 -0
- package/dist/src/components/editor/plugins/basic-marks-base-kit.mjs +20 -0
- package/dist/src/components/editor/plugins/basic-marks-kit.mjs +28 -0
- package/dist/src/components/editor/plugins/block-menu-kit.mjs +11 -0
- package/dist/src/components/editor/plugins/block-placeholder-kit.mjs +14 -0
- package/dist/src/components/editor/plugins/block-selection-kit.mjs +48 -0
- package/dist/src/components/editor/plugins/callout-base-kit.mjs +8 -0
- package/dist/src/components/editor/plugins/callout-kit.mjs +10 -0
- package/dist/src/components/editor/plugins/code-block-base-kit.mjs +16 -0
- package/dist/src/components/editor/plugins/code-block-kit.mjs +19 -0
- package/dist/src/components/editor/plugins/column-base-kit.mjs +8 -0
- package/dist/src/components/editor/plugins/column-kit.mjs +10 -0
- package/dist/src/components/editor/plugins/comment-base-kit.mjs +8 -0
- package/dist/src/components/editor/plugins/comment-kit.mjs +53 -0
- package/dist/src/components/editor/plugins/copilot-kit.mjs +49 -0
- package/dist/src/components/editor/plugins/cursor-overlay-kit.mjs +11 -0
- package/dist/src/components/editor/plugins/date-base-kit.mjs +8 -0
- package/dist/src/components/editor/plugins/date-kit.mjs +10 -0
- package/dist/src/components/editor/plugins/discussion-kit.mjs +94 -0
- package/dist/src/components/editor/plugins/dnd-kit.mjs +31 -0
- package/dist/src/components/editor/plugins/emoji-kit.mjs +11 -0
- package/dist/src/components/editor/plugins/exit-break-kit.mjs +12 -0
- package/dist/src/components/editor/plugins/fixed-toolbar-kit.mjs +15 -0
- package/dist/src/components/editor/plugins/floating-toolbar-kit.mjs +15 -0
- package/dist/src/components/editor/plugins/font-base-kit.mjs +14 -0
- package/dist/src/components/editor/plugins/font-kit.mjs +19 -0
- package/dist/src/components/editor/plugins/indent-base-kit.mjs +17 -0
- package/dist/src/components/editor/plugins/indent-kit.mjs +20 -0
- package/dist/src/components/editor/plugins/line-height-base-kit.mjs +20 -0
- package/dist/src/components/editor/plugins/line-height-kit.mjs +22 -0
- package/dist/src/components/editor/plugins/link-base-kit.mjs +8 -0
- package/dist/src/components/editor/plugins/link-kit.mjs +15 -0
- package/dist/src/components/editor/plugins/list-base-kit.mjs +19 -0
- package/dist/src/components/editor/plugins/list-kit.mjs +22 -0
- package/dist/src/components/editor/plugins/markdown-kit.mjs +17 -0
- package/dist/src/components/editor/plugins/math-base-kit.mjs +8 -0
- package/dist/src/components/editor/plugins/math-kit.mjs +10 -0
- package/dist/src/components/editor/plugins/media-base-kit.mjs +23 -0
- package/dist/src/components/editor/plugins/media-kit.mjs +37 -0
- package/dist/src/components/editor/plugins/slash-kit.mjs +11 -0
- package/dist/src/components/editor/plugins/suggestion-base-kit.mjs +8 -0
- package/dist/src/components/editor/plugins/suggestion-kit.mjs +50 -0
- package/dist/src/components/editor/plugins/table-base-kit.mjs +13 -0
- package/dist/src/components/editor/plugins/table-kit.mjs +15 -0
- package/dist/src/components/editor/transforms.mjs +125 -0
- package/dist/src/components/editor/ui/ai-chat-editor.mjs +21 -0
- package/dist/src/components/editor/ui/ai-menu.mjs +488 -0
- package/dist/src/components/editor/ui/ai-node.mjs +24 -0
- package/dist/src/components/editor/ui/ai-toolbar-button.mjs +23 -0
- package/dist/src/components/editor/ui/align-toolbar-button.mjs +71 -0
- package/dist/src/components/editor/ui/block-context-menu.mjs +130 -0
- package/dist/src/components/editor/ui/block-discussion.mjs +200 -0
- package/dist/src/components/editor/ui/block-draggable.mjs +265 -0
- package/dist/src/components/editor/ui/block-list-static.mjs +48 -0
- package/dist/src/components/editor/ui/block-list.mjs +47 -0
- package/dist/src/components/editor/ui/block-selection.mjs +28 -0
- package/dist/src/components/editor/ui/block-suggestion.mjs +319 -0
- package/dist/src/components/editor/ui/blockquote-node-static.mjs +14 -0
- package/dist/src/components/editor/ui/blockquote-node.mjs +16 -0
- package/dist/src/components/editor/ui/callout-node-static.mjs +29 -0
- package/dist/src/components/editor/ui/callout-node.mjs +50 -0
- package/dist/src/components/editor/ui/caption.mjs +39 -0
- package/dist/src/components/editor/ui/code-block-node-static.mjs +30 -0
- package/dist/src/components/editor/ui/code-block-node.mjs +121 -0
- package/dist/src/components/editor/ui/code-node-static.mjs +15 -0
- package/dist/src/components/editor/ui/code-node.mjs +17 -0
- package/dist/src/components/editor/ui/column-node-static.mjs +32 -0
- package/dist/src/components/editor/ui/column-node.mjs +229 -0
- package/dist/src/components/editor/ui/comment-node-static.mjs +14 -0
- package/dist/src/components/editor/ui/comment-node.mjs +33 -0
- package/dist/src/components/editor/ui/comment-toolbar-button.mjs +23 -0
- package/dist/src/components/editor/ui/comment.mjs +422 -0
- package/dist/src/components/editor/ui/cursor-overlay.mjs +36 -0
- package/dist/src/components/editor/ui/date-node-static.mjs +32 -0
- package/dist/src/components/editor/ui/date-node.mjs +60 -0
- package/dist/src/components/editor/ui/editor-static.mjs +31 -0
- package/dist/src/components/editor/ui/editor.mjs +60 -0
- package/dist/src/components/editor/ui/emoji-node.mjs +46 -0
- package/dist/src/components/editor/ui/emoji-toolbar-button.mjs +415 -0
- package/dist/src/components/editor/ui/equation-node-static.mjs +65 -0
- package/dist/src/components/editor/ui/equation-node.mjs +159 -0
- package/dist/src/components/editor/ui/equation-toolbar-button.mjs +23 -0
- package/dist/src/components/editor/ui/fixed-toolbar-buttons.mjs +109 -0
- package/dist/src/components/editor/ui/fixed-toolbar.mjs +16 -0
- package/dist/src/components/editor/ui/floating-toolbar-buttons.mjs +54 -0
- package/dist/src/components/editor/ui/floating-toolbar.mjs +51 -0
- package/dist/src/components/editor/ui/font-color-toolbar-button.mjs +637 -0
- package/dist/src/components/editor/ui/font-size-toolbar-button.mjs +83 -0
- package/dist/src/components/editor/ui/ghost-text.mjs +22 -0
- package/dist/src/components/editor/ui/heading-node-static.mjs +60 -0
- package/dist/src/components/editor/ui/heading-node.mjs +62 -0
- package/dist/src/components/editor/ui/highlight-node-static.mjs +15 -0
- package/dist/src/components/editor/ui/highlight-node.mjs +17 -0
- package/dist/src/components/editor/ui/history-toolbar-button.mjs +35 -0
- package/dist/src/components/editor/ui/hr-node-static.mjs +18 -0
- package/dist/src/components/editor/ui/hr-node.mjs +23 -0
- package/dist/src/components/editor/ui/indent-toolbar-button.mjs +29 -0
- package/dist/src/components/editor/ui/inline-combobox.mjs +148 -0
- package/dist/src/components/editor/ui/insert-toolbar-button.mjs +199 -0
- package/dist/src/components/editor/ui/kbd-node-static.mjs +15 -0
- package/dist/src/components/editor/ui/kbd-node.mjs +17 -0
- package/dist/src/components/editor/ui/line-height-toolbar-button.mjs +56 -0
- package/dist/src/components/editor/ui/link-node-static.mjs +20 -0
- package/dist/src/components/editor/ui/link-node.mjs +28 -0
- package/dist/src/components/editor/ui/link-toolbar-button.mjs +21 -0
- package/dist/src/components/editor/ui/link-toolbar.mjs +141 -0
- package/dist/src/components/editor/ui/list-toolbar-button.mjs +131 -0
- package/dist/src/components/editor/ui/mark-toolbar-button.mjs +20 -0
- package/dist/src/components/editor/ui/media-image-node-static.mjs +32 -0
- package/dist/src/components/editor/ui/media-image-node.mjs +64 -0
- package/dist/src/components/editor/ui/media-placeholder-node.mjs +184 -0
- package/dist/src/components/editor/ui/media-preview-dialog.mjs +113 -0
- package/dist/src/components/editor/ui/media-toolbar-button.mjs +156 -0
- package/dist/src/components/editor/ui/media-toolbar.mjs +80 -0
- package/dist/src/components/editor/ui/media-upload-toast.mjs +39 -0
- package/dist/src/components/editor/ui/media-video-node-static.mjs +27 -0
- package/dist/src/components/editor/ui/mode-toolbar-button.mjs +112 -0
- package/dist/src/components/editor/ui/paragraph-node-static.mjs +15 -0
- package/dist/src/components/editor/ui/paragraph-node.mjs +17 -0
- package/dist/src/components/editor/ui/resize-handle.mjs +43 -0
- package/dist/src/components/editor/ui/slash-node.mjs +228 -0
- package/dist/src/components/editor/ui/suggestion-node-static.mjs +24 -0
- package/dist/src/components/editor/ui/suggestion-node.mjs +111 -0
- package/dist/src/components/editor/ui/suggestion-toolbar-button.mjs +24 -0
- package/dist/src/components/editor/ui/table-icons.mjs +1310 -0
- package/dist/src/components/editor/ui/table-node-static.mjs +68 -0
- package/dist/src/components/editor/ui/table-node.mjs +375 -0
- package/dist/src/components/editor/ui/table-toolbar-button.mjs +190 -0
- package/dist/src/components/editor/ui/turn-into-toolbar-button.mjs +168 -0
- package/dist/src/components/editor/use-chat.mjs +80 -0
- package/dist/src/components/json-schema-editor/client.mjs +46 -0
- package/dist/src/components/json-schema-editor/components/inputs.mjs +438 -0
- package/dist/src/components/json-schema-editor/get-default-values.mjs +23 -0
- package/dist/src/components/json-schema-editor/schema.mjs +131 -0
- package/dist/src/components/json-schema-editor/utils/merge-schema.mjs +134 -0
- package/dist/src/components/json-schema-editor/utils/schema-to-string.mjs +53 -0
- package/dist/src/components/ui/alert-dialog.mjs +90 -0
- package/dist/src/components/ui/avatar.mjs +32 -0
- package/dist/src/components/ui/button.mjs +48 -0
- package/dist/src/components/ui/calendar.mjs +108 -0
- package/dist/src/components/ui/checkbox.mjs +23 -0
- package/dist/src/components/ui/combobox.mjs +53 -0
- package/dist/src/components/ui/command.mjs +42 -0
- package/dist/src/components/ui/context-menu.mjs +67 -0
- package/dist/src/components/ui/dialog.mjs +9 -0
- package/dist/src/components/ui/dropdown-menu.mjs +122 -0
- package/dist/src/components/ui/input-group.mjs +31 -0
- package/dist/src/components/ui/input.mjs +15 -0
- package/dist/src/components/ui/label.mjs +19 -0
- package/dist/src/components/ui/popover.mjs +37 -0
- package/dist/src/components/ui/select.mjs +80 -0
- package/dist/src/components/ui/separator.mjs +19 -0
- package/dist/src/components/ui/spinner.mjs +16 -0
- package/dist/src/components/ui/tabs.mjs +39 -0
- package/dist/src/components/ui/textarea.mjs +14 -0
- package/dist/src/components/ui/toolbar.mjs +183 -0
- package/dist/src/components/ui/tooltip.mjs +38 -0
- package/dist/src/hooks/editor/use-is-creator.mjs +19 -0
- package/dist/src/hooks/use-upload-file.mjs +73 -0
- package/dist/src/lib/config.mjs +38 -0
- package/dist/src/lib/data/store.d.mts +15 -0
- package/dist/src/lib/lowlight.mjs +7 -0
- package/dist/src/lib/utils/deep-equal.mjs +18 -0
- package/dist/src/lib/utils/remove-undefined.mjs +18 -0
- package/dist/src/lib/utils.mjs +10 -0
- package/dist/types.d.mts +50 -0
- package/next.config.ts +23 -0
- package/package.json +131 -0
- package/postcss.config.mjs +7 -0
- package/src/app/(dashboard)/collection/[name]/[...slug]/page.client.tsx +26 -0
- package/src/app/(dashboard)/collection/[name]/[...slug]/page.tsx +17 -0
- package/src/app/(dashboard)/collection/[name]/page.client.tsx +82 -0
- package/src/app/(dashboard)/collection/[name]/page.tsx +11 -0
- package/src/app/(dashboard)/layout.tsx +34 -0
- package/src/app/(dashboard)/page.tsx +38 -0
- package/src/app/api/ai/command/prompts.ts +313 -0
- package/src/app/api/ai/command/route.ts +203 -0
- package/src/app/api/ai/command/utils.ts +242 -0
- package/src/app/api/ai/copilot/route.ts +33 -0
- package/src/app/api/uploadthing/route.ts +5 -0
- package/src/app/codeblock/LICENSE +21 -0
- package/src/app/codeblock/styles.css +289 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +223 -0
- package/src/app/layout.client.tsx +15 -0
- package/src/app/layout.tsx +30 -0
- package/src/components/app-sidebar.tsx +162 -0
- package/src/components/code-editor/mdx.lazy.tsx +18 -0
- package/src/components/code-editor/mdx.tsx +48 -0
- package/src/components/code-editor/yaml.lazy.tsx +20 -0
- package/src/components/code-editor/yaml.tsx +71 -0
- package/src/components/collection/actions.tsx +41 -0
- package/src/components/collection/client.tsx +63 -0
- package/src/components/collection/context.tsx +24 -0
- package/src/components/collection/document/actions.tsx +83 -0
- package/src/components/editor/editor-base-kit.tsx +37 -0
- package/src/components/editor/editor-kit.tsx +87 -0
- package/src/components/editor/md.tsx +60 -0
- package/src/components/editor/plugins/ai-kit.tsx +102 -0
- package/src/components/editor/plugins/align-base-kit.tsx +16 -0
- package/src/components/editor/plugins/align-kit.tsx +18 -0
- package/src/components/editor/plugins/autoformat-kit.tsx +236 -0
- package/src/components/editor/plugins/basic-blocks-base-kit.tsx +34 -0
- package/src/components/editor/plugins/basic-blocks-kit.tsx +87 -0
- package/src/components/editor/plugins/basic-marks-base-kit.tsx +26 -0
- package/src/components/editor/plugins/basic-marks-kit.tsx +40 -0
- package/src/components/editor/plugins/basic-nodes-kit.tsx +6 -0
- package/src/components/editor/plugins/block-menu-kit.tsx +14 -0
- package/src/components/editor/plugins/block-placeholder-kit.tsx +17 -0
- package/src/components/editor/plugins/block-selection-kit.tsx +54 -0
- package/src/components/editor/plugins/callout-base-kit.tsx +5 -0
- package/src/components/editor/plugins/callout-kit.tsx +7 -0
- package/src/components/editor/plugins/code-block-base-kit.tsx +16 -0
- package/src/components/editor/plugins/code-block-kit.tsx +19 -0
- package/src/components/editor/plugins/column-base-kit.tsx +11 -0
- package/src/components/editor/plugins/column-kit.tsx +10 -0
- package/src/components/editor/plugins/comment-base-kit.tsx +5 -0
- package/src/components/editor/plugins/comment-kit.tsx +92 -0
- package/src/components/editor/plugins/copilot-kit.tsx +70 -0
- package/src/components/editor/plugins/cursor-overlay-kit.tsx +13 -0
- package/src/components/editor/plugins/date-base-kit.tsx +5 -0
- package/src/components/editor/plugins/date-kit.tsx +7 -0
- package/src/components/editor/plugins/discussion-kit.tsx +142 -0
- package/src/components/editor/plugins/dnd-kit.tsx +25 -0
- package/src/components/editor/plugins/emoji-kit.tsx +13 -0
- package/src/components/editor/plugins/exit-break-kit.tsx +12 -0
- package/src/components/editor/plugins/fixed-toolbar-kit.tsx +19 -0
- package/src/components/editor/plugins/floating-toolbar-kit.tsx +19 -0
- package/src/components/editor/plugins/font-base-kit.tsx +20 -0
- package/src/components/editor/plugins/font-kit.tsx +29 -0
- package/src/components/editor/plugins/indent-base-kit.tsx +13 -0
- package/src/components/editor/plugins/indent-kit.tsx +22 -0
- package/src/components/editor/plugins/line-height-base-kit.tsx +14 -0
- package/src/components/editor/plugins/line-height-kit.tsx +16 -0
- package/src/components/editor/plugins/link-base-kit.tsx +5 -0
- package/src/components/editor/plugins/link-kit.tsx +15 -0
- package/src/components/editor/plugins/list-base-kit.tsx +17 -0
- package/src/components/editor/plugins/list-kit.tsx +26 -0
- package/src/components/editor/plugins/markdown-kit.tsx +13 -0
- package/src/components/editor/plugins/math-base-kit.tsx +11 -0
- package/src/components/editor/plugins/math-kit.tsx +10 -0
- package/src/components/editor/plugins/media-base-kit.tsx +25 -0
- package/src/components/editor/plugins/media-kit.tsx +28 -0
- package/src/components/editor/plugins/slash-kit.tsx +18 -0
- package/src/components/editor/plugins/suggestion-base-kit.tsx +5 -0
- package/src/components/editor/plugins/suggestion-kit.tsx +83 -0
- package/src/components/editor/plugins/table-base-kit.tsx +20 -0
- package/src/components/editor/plugins/table-kit.tsx +22 -0
- package/src/components/editor/settings-dialog.tsx +418 -0
- package/src/components/editor/transforms.ts +193 -0
- package/src/components/editor/types.ts +149 -0
- package/src/components/editor/ui/ai-chat-editor.tsx +20 -0
- package/src/components/editor/ui/ai-menu.tsx +663 -0
- package/src/components/editor/ui/ai-node.tsx +40 -0
- package/src/components/editor/ui/ai-toolbar-button.tsx +23 -0
- package/src/components/editor/ui/align-toolbar-button.tsx +78 -0
- package/src/components/editor/ui/block-context-menu.tsx +154 -0
- package/src/components/editor/ui/block-discussion.tsx +318 -0
- package/src/components/editor/ui/block-draggable.tsx +464 -0
- package/src/components/editor/ui/block-list-static.tsx +75 -0
- package/src/components/editor/ui/block-list.tsx +72 -0
- package/src/components/editor/ui/block-selection.tsx +37 -0
- package/src/components/editor/ui/block-suggestion.tsx +438 -0
- package/src/components/editor/ui/blockquote-node-static.tsx +5 -0
- package/src/components/editor/ui/blockquote-node.tsx +7 -0
- package/src/components/editor/ui/callout-node-static.tsx +30 -0
- package/src/components/editor/ui/callout-node.tsx +64 -0
- package/src/components/editor/ui/caption.tsx +55 -0
- package/src/components/editor/ui/code-block-node-static.tsx +33 -0
- package/src/components/editor/ui/code-block-node.tsx +161 -0
- package/src/components/editor/ui/code-node-static.tsx +15 -0
- package/src/components/editor/ui/code-node.tsx +17 -0
- package/src/components/editor/ui/column-node-static.tsx +27 -0
- package/src/components/editor/ui/column-node.tsx +285 -0
- package/src/components/editor/ui/comment-node-static.tsx +12 -0
- package/src/components/editor/ui/comment-node.tsx +43 -0
- package/src/components/editor/ui/comment-toolbar-button.tsx +24 -0
- package/src/components/editor/ui/comment.tsx +577 -0
- package/src/components/editor/ui/cursor-overlay.tsx +66 -0
- package/src/components/editor/ui/date-node-static.tsx +45 -0
- package/src/components/editor/ui/date-node.tsx +86 -0
- package/src/components/editor/ui/editor-static.tsx +47 -0
- package/src/components/editor/ui/editor.tsx +120 -0
- package/src/components/editor/ui/emoji-node.tsx +65 -0
- package/src/components/editor/ui/emoji-toolbar-button.tsx +582 -0
- package/src/components/editor/ui/equation-node-static.tsx +94 -0
- package/src/components/editor/ui/equation-node.tsx +218 -0
- package/src/components/editor/ui/equation-toolbar-button.tsx +24 -0
- package/src/components/editor/ui/fixed-toolbar-buttons.tsx +135 -0
- package/src/components/editor/ui/fixed-toolbar.tsx +17 -0
- package/src/components/editor/ui/floating-toolbar-buttons.tsx +72 -0
- package/src/components/editor/ui/floating-toolbar.tsx +76 -0
- package/src/components/editor/ui/font-color-toolbar-button.tsx +804 -0
- package/src/components/editor/ui/font-size-toolbar-button.tsx +102 -0
- package/src/components/editor/ui/ghost-text.tsx +27 -0
- package/src/components/editor/ui/heading-node-static.tsx +54 -0
- package/src/components/editor/ui/heading-node.tsx +54 -0
- package/src/components/editor/ui/highlight-node-static.tsx +11 -0
- package/src/components/editor/ui/highlight-node.tsx +13 -0
- package/src/components/editor/ui/history-toolbar-button.tsx +41 -0
- package/src/components/editor/ui/hr-node-static.tsx +16 -0
- package/src/components/editor/ui/hr-node.tsx +28 -0
- package/src/components/editor/ui/indent-toolbar-button.tsx +27 -0
- package/src/components/editor/ui/inline-combobox.tsx +251 -0
- package/src/components/editor/ui/insert-toolbar-button.tsx +242 -0
- package/src/components/editor/ui/kbd-node-static.tsx +15 -0
- package/src/components/editor/ui/kbd-node.tsx +17 -0
- package/src/components/editor/ui/line-height-toolbar-button.tsx +66 -0
- package/src/components/editor/ui/link-node-static.tsx +21 -0
- package/src/components/editor/ui/link-node.tsx +37 -0
- package/src/components/editor/ui/link-toolbar-button.tsx +18 -0
- package/src/components/editor/ui/link-toolbar.tsx +196 -0
- package/src/components/editor/ui/list-toolbar-button.tsx +195 -0
- package/src/components/editor/ui/mark-toolbar-button.tsx +20 -0
- package/src/components/editor/ui/media-image-node-static.tsx +33 -0
- package/src/components/editor/ui/media-image-node.tsx +75 -0
- package/src/components/editor/ui/media-placeholder-node.tsx +235 -0
- package/src/components/editor/ui/media-preview-dialog.tsx +145 -0
- package/src/components/editor/ui/media-toolbar-button.tsx +202 -0
- package/src/components/editor/ui/media-toolbar.tsx +100 -0
- package/src/components/editor/ui/media-upload-toast.tsx +59 -0
- package/src/components/editor/ui/media-video-node-static.tsx +23 -0
- package/src/components/editor/ui/mode-toolbar-button.tsx +121 -0
- package/src/components/editor/ui/paragraph-node-static.tsx +13 -0
- package/src/components/editor/ui/paragraph-node.tsx +15 -0
- package/src/components/editor/ui/resize-handle.tsx +79 -0
- package/src/components/editor/ui/slash-node.tsx +274 -0
- package/src/components/editor/ui/suggestion-node-static.tsx +30 -0
- package/src/components/editor/ui/suggestion-node.tsx +157 -0
- package/src/components/editor/ui/suggestion-toolbar-button.tsx +25 -0
- package/src/components/editor/ui/table-icons.tsx +685 -0
- package/src/components/editor/ui/table-node-static.tsx +86 -0
- package/src/components/editor/ui/table-node.tsx +569 -0
- package/src/components/editor/ui/table-toolbar-button.tsx +260 -0
- package/src/components/editor/ui/turn-into-toolbar-button.tsx +176 -0
- package/src/components/editor/use-chat.ts +120 -0
- package/src/components/icons/logo.tsx +37 -0
- package/src/components/json-schema-editor/client.tsx +55 -0
- package/src/components/json-schema-editor/components/inputs.tsx +612 -0
- package/src/components/json-schema-editor/get-default-values.ts +29 -0
- package/src/components/json-schema-editor/schema.tsx +206 -0
- package/src/components/json-schema-editor/utils/merge-schema.ts +167 -0
- package/src/components/json-schema-editor/utils/schema-to-string.ts +87 -0
- package/src/components/nav-user.tsx +102 -0
- package/src/components/site-header.tsx +13 -0
- package/src/components/ui/alert-dialog.tsx +182 -0
- package/src/components/ui/avatar.tsx +96 -0
- package/src/components/ui/badge.tsx +46 -0
- package/src/components/ui/button.tsx +65 -0
- package/src/components/ui/calendar.tsx +186 -0
- package/src/components/ui/checkbox.tsx +29 -0
- package/src/components/ui/combobox.tsx +267 -0
- package/src/components/ui/command.tsx +180 -0
- package/src/components/ui/context-menu.tsx +161 -0
- package/src/components/ui/dialog.tsx +142 -0
- package/src/components/ui/drawer.tsx +120 -0
- package/src/components/ui/dropdown-menu.tsx +239 -0
- package/src/components/ui/field.tsx +224 -0
- package/src/components/ui/input-group.tsx +144 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/label.tsx +18 -0
- package/src/components/ui/popover.tsx +76 -0
- package/src/components/ui/select.tsx +182 -0
- package/src/components/ui/separator.tsx +28 -0
- package/src/components/ui/sheet.tsx +130 -0
- package/src/components/ui/sidebar.tsx +608 -0
- package/src/components/ui/sonner.tsx +45 -0
- package/src/components/ui/spinner.tsx +15 -0
- package/src/components/ui/table.tsx +89 -0
- package/src/components/ui/tabs.tsx +60 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/ui/toggle-group.tsx +86 -0
- package/src/components/ui/toggle.tsx +45 -0
- package/src/components/ui/toolbar.tsx +365 -0
- package/src/components/ui/tooltip.tsx +57 -0
- package/src/hooks/editor/use-is-creator.ts +21 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/hooks/use-mounted.ts +11 -0
- package/src/hooks/use-upload-file.ts +121 -0
- package/src/lib/ai/markdown-joiner-transform.ts +235 -0
- package/src/lib/config.ts +60 -0
- package/src/lib/data/actions.ts +51 -0
- package/src/lib/data/boundary.client.tsx +22 -0
- package/src/lib/data/boundary.tsx +22 -0
- package/src/lib/data/query.ts +9 -0
- package/src/lib/data/store.ts +52 -0
- package/src/lib/lowlight.ts +3 -0
- package/src/lib/uploadthing.ts +19 -0
- package/src/lib/utils/deep-equal.ts +37 -0
- package/src/lib/utils/remove-undefined.ts +21 -0
- package/src/lib/utils/urls.ts +6 -0
- package/src/lib/utils.ts +6 -0
- package/tsconfig.build.json +24 -0
- package/tsconfig.json +37 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { toUnitLess } from "@platejs/basic-styles";
|
|
4
|
+
import { FontSizePlugin } from "@platejs/basic-styles/react";
|
|
5
|
+
import { Minus, Plus } from "lucide-react";
|
|
6
|
+
import type { TElement } from "platejs";
|
|
7
|
+
import { KEYS } from "platejs";
|
|
8
|
+
import { useEditorPlugin, useEditorSelector } from "platejs/react";
|
|
9
|
+
import * as React from "react";
|
|
10
|
+
|
|
11
|
+
import { cn } from "@/lib/utils";
|
|
12
|
+
|
|
13
|
+
import { ToolbarButton } from "../../ui/toolbar";
|
|
14
|
+
|
|
15
|
+
const DEFAULT_FONT_SIZE = "16";
|
|
16
|
+
|
|
17
|
+
const FONT_SIZE_MAP = {
|
|
18
|
+
h1: "36",
|
|
19
|
+
h2: "24",
|
|
20
|
+
h3: "20",
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
export function FontSizeToolbarButton() {
|
|
24
|
+
const [inputValue, setInputValue] = React.useState(DEFAULT_FONT_SIZE);
|
|
25
|
+
const [isFocused, setIsFocused] = React.useState(false);
|
|
26
|
+
const { editor, tf } = useEditorPlugin(FontSizePlugin);
|
|
27
|
+
|
|
28
|
+
const cursorFontSize = useEditorSelector((editor) => {
|
|
29
|
+
const fontSize = editor.api.marks()?.[KEYS.fontSize];
|
|
30
|
+
|
|
31
|
+
if (fontSize) {
|
|
32
|
+
return toUnitLess(fontSize as string);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const [block] = editor.api.block<TElement>() || [];
|
|
36
|
+
|
|
37
|
+
if (!block?.type) return DEFAULT_FONT_SIZE;
|
|
38
|
+
|
|
39
|
+
return block.type in FONT_SIZE_MAP
|
|
40
|
+
? FONT_SIZE_MAP[block.type as keyof typeof FONT_SIZE_MAP]
|
|
41
|
+
: DEFAULT_FONT_SIZE;
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
const handleInputChange = () => {
|
|
45
|
+
const newSize = toUnitLess(inputValue);
|
|
46
|
+
|
|
47
|
+
if (Number.parseInt(newSize, 10) < 1 || Number.parseInt(newSize, 10) > 100) {
|
|
48
|
+
editor.tf.focus();
|
|
49
|
+
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (newSize !== toUnitLess(cursorFontSize)) {
|
|
53
|
+
tf.fontSize.addMark(`${newSize}px`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
editor.tf.focus();
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const handleFontSizeChange = (delta: number) => {
|
|
60
|
+
const newSize = Number(displayValue) + delta;
|
|
61
|
+
tf.fontSize.addMark(`${newSize}px`);
|
|
62
|
+
editor.tf.focus();
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const displayValue = isFocused ? inputValue : cursorFontSize;
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div className="flex h-7 items-center gap-1 rounded-md bg-muted/60 p-0">
|
|
69
|
+
<ToolbarButton onClick={() => handleFontSizeChange(-1)}>
|
|
70
|
+
<Minus />
|
|
71
|
+
</ToolbarButton>
|
|
72
|
+
|
|
73
|
+
<input
|
|
74
|
+
className={cn(
|
|
75
|
+
"h-full w-10 shrink-0 bg-transparent px-1 text-center text-sm hover:bg-muted",
|
|
76
|
+
)}
|
|
77
|
+
value={displayValue}
|
|
78
|
+
onBlur={() => {
|
|
79
|
+
setIsFocused(false);
|
|
80
|
+
handleInputChange();
|
|
81
|
+
}}
|
|
82
|
+
onChange={(e) => setInputValue(e.target.value)}
|
|
83
|
+
onFocus={() => {
|
|
84
|
+
setIsFocused(true);
|
|
85
|
+
setInputValue(toUnitLess(cursorFontSize));
|
|
86
|
+
}}
|
|
87
|
+
onKeyDown={(e) => {
|
|
88
|
+
if (e.key === "Enter") {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
handleInputChange();
|
|
91
|
+
}
|
|
92
|
+
}}
|
|
93
|
+
data-plate-focus="true"
|
|
94
|
+
type="text"
|
|
95
|
+
/>
|
|
96
|
+
|
|
97
|
+
<ToolbarButton onClick={() => handleFontSizeChange(1)}>
|
|
98
|
+
<Plus />
|
|
99
|
+
</ToolbarButton>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { CopilotPlugin } from "@platejs/ai/react";
|
|
4
|
+
import { useElement, usePluginOption } from "platejs/react";
|
|
5
|
+
|
|
6
|
+
export function GhostText() {
|
|
7
|
+
const element = useElement();
|
|
8
|
+
|
|
9
|
+
const isSuggested = usePluginOption(CopilotPlugin, "isSuggested", element.id as string);
|
|
10
|
+
|
|
11
|
+
if (!isSuggested) return null;
|
|
12
|
+
|
|
13
|
+
return <GhostTextContent />;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function GhostTextContent() {
|
|
17
|
+
const suggestionText = usePluginOption(CopilotPlugin, "suggestionText");
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<span
|
|
21
|
+
className="pointer-events-none text-muted-foreground/70 max-sm:hidden"
|
|
22
|
+
contentEditable={false}
|
|
23
|
+
>
|
|
24
|
+
{suggestionText && suggestionText}
|
|
25
|
+
</span>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
|
|
3
|
+
import type { SlateElementProps } from "platejs/static";
|
|
4
|
+
|
|
5
|
+
import { type VariantProps, cva } from "class-variance-authority";
|
|
6
|
+
import { SlateElement } from "platejs/static";
|
|
7
|
+
|
|
8
|
+
const headingVariants = cva("relative mb-1", {
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
h1: "mt-[1.6em] pb-1 font-bold font-heading text-4xl",
|
|
12
|
+
h2: "mt-[1.4em] pb-px font-heading font-semibold text-2xl tracking-tight",
|
|
13
|
+
h3: "mt-[1em] pb-px font-heading font-semibold text-xl tracking-tight",
|
|
14
|
+
h4: "mt-[0.75em] font-heading font-semibold text-lg tracking-tight",
|
|
15
|
+
h5: "mt-[0.75em] font-semibold text-lg tracking-tight",
|
|
16
|
+
h6: "mt-[0.75em] font-semibold text-base tracking-tight",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export function HeadingElementStatic({
|
|
22
|
+
variant = "h1",
|
|
23
|
+
...props
|
|
24
|
+
}: SlateElementProps & VariantProps<typeof headingVariants>) {
|
|
25
|
+
return (
|
|
26
|
+
<SlateElement as={variant!} className={headingVariants({ variant })} {...props}>
|
|
27
|
+
{props.children}
|
|
28
|
+
</SlateElement>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function H1ElementStatic(props: SlateElementProps) {
|
|
33
|
+
return <HeadingElementStatic variant="h1" {...props} />;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function H2ElementStatic(props: React.ComponentProps<typeof HeadingElementStatic>) {
|
|
37
|
+
return <HeadingElementStatic variant="h2" {...props} />;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function H3ElementStatic(props: React.ComponentProps<typeof HeadingElementStatic>) {
|
|
41
|
+
return <HeadingElementStatic variant="h3" {...props} />;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function H4ElementStatic(props: React.ComponentProps<typeof HeadingElementStatic>) {
|
|
45
|
+
return <HeadingElementStatic variant="h4" {...props} />;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function H5ElementStatic(props: React.ComponentProps<typeof HeadingElementStatic>) {
|
|
49
|
+
return <HeadingElementStatic variant="h5" {...props} />;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function H6ElementStatic(props: React.ComponentProps<typeof HeadingElementStatic>) {
|
|
53
|
+
return <HeadingElementStatic variant="h6" {...props} />;
|
|
54
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { PlateElementProps } from "platejs/react";
|
|
4
|
+
|
|
5
|
+
import { type VariantProps, cva } from "class-variance-authority";
|
|
6
|
+
import { PlateElement } from "platejs/react";
|
|
7
|
+
|
|
8
|
+
const headingVariants = cva("relative mb-1", {
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
h1: "mt-[1.6em] pb-1 font-bold font-heading text-4xl",
|
|
12
|
+
h2: "mt-[1.4em] pb-px font-heading font-semibold text-2xl tracking-tight",
|
|
13
|
+
h3: "mt-[1em] pb-px font-heading font-semibold text-xl tracking-tight",
|
|
14
|
+
h4: "mt-[0.75em] font-heading font-semibold text-lg tracking-tight",
|
|
15
|
+
h5: "mt-[0.75em] font-semibold text-lg tracking-tight",
|
|
16
|
+
h6: "mt-[0.75em] font-semibold text-base tracking-tight",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export function HeadingElement({
|
|
22
|
+
variant = "h1",
|
|
23
|
+
...props
|
|
24
|
+
}: PlateElementProps & VariantProps<typeof headingVariants>) {
|
|
25
|
+
return (
|
|
26
|
+
<PlateElement as={variant!} className={headingVariants({ variant })} {...props}>
|
|
27
|
+
{props.children}
|
|
28
|
+
</PlateElement>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function H1Element(props: PlateElementProps) {
|
|
33
|
+
return <HeadingElement variant="h1" {...props} />;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function H2Element(props: PlateElementProps) {
|
|
37
|
+
return <HeadingElement variant="h2" {...props} />;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function H3Element(props: PlateElementProps) {
|
|
41
|
+
return <HeadingElement variant="h3" {...props} />;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function H4Element(props: PlateElementProps) {
|
|
45
|
+
return <HeadingElement variant="h4" {...props} />;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function H5Element(props: PlateElementProps) {
|
|
49
|
+
return <HeadingElement variant="h5" {...props} />;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function H6Element(props: PlateElementProps) {
|
|
53
|
+
return <HeadingElement variant="h6" {...props} />;
|
|
54
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SlateLeafProps } from "platejs/static";
|
|
2
|
+
|
|
3
|
+
import { SlateLeaf } from "platejs/static";
|
|
4
|
+
|
|
5
|
+
export function HighlightLeafStatic(props: SlateLeafProps) {
|
|
6
|
+
return (
|
|
7
|
+
<SlateLeaf {...props} as="mark" className="bg-highlight/30 text-inherit">
|
|
8
|
+
{props.children}
|
|
9
|
+
</SlateLeaf>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { PlateLeafProps } from "platejs/react";
|
|
4
|
+
|
|
5
|
+
import { PlateLeaf } from "platejs/react";
|
|
6
|
+
|
|
7
|
+
export function HighlightLeaf(props: PlateLeafProps) {
|
|
8
|
+
return (
|
|
9
|
+
<PlateLeaf {...props} as="mark" className="bg-highlight/30 text-inherit">
|
|
10
|
+
{props.children}
|
|
11
|
+
</PlateLeaf>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Redo2Icon, Undo2Icon } from "lucide-react";
|
|
4
|
+
import { useEditorRef, useEditorSelector } from "platejs/react";
|
|
5
|
+
import type * as React from "react";
|
|
6
|
+
|
|
7
|
+
import { ToolbarButton } from "../../ui/toolbar";
|
|
8
|
+
|
|
9
|
+
export function RedoToolbarButton(props: React.ComponentProps<typeof ToolbarButton>) {
|
|
10
|
+
const editor = useEditorRef();
|
|
11
|
+
const disabled = useEditorSelector((editor) => editor.history.redos.length === 0, []);
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<ToolbarButton
|
|
15
|
+
{...props}
|
|
16
|
+
disabled={disabled}
|
|
17
|
+
onClick={() => editor.redo()}
|
|
18
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
19
|
+
tooltip="Redo"
|
|
20
|
+
>
|
|
21
|
+
<Redo2Icon />
|
|
22
|
+
</ToolbarButton>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function UndoToolbarButton(props: React.ComponentProps<typeof ToolbarButton>) {
|
|
27
|
+
const editor = useEditorRef();
|
|
28
|
+
const disabled = useEditorSelector((editor) => editor.history.undos.length === 0, []);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<ToolbarButton
|
|
32
|
+
{...props}
|
|
33
|
+
disabled={disabled}
|
|
34
|
+
onClick={() => editor.undo()}
|
|
35
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
36
|
+
tooltip="Undo"
|
|
37
|
+
>
|
|
38
|
+
<Undo2Icon />
|
|
39
|
+
</ToolbarButton>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SlateElementProps } from "platejs/static";
|
|
2
|
+
|
|
3
|
+
import { SlateElement } from "platejs/static";
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils";
|
|
6
|
+
|
|
7
|
+
export function HrElementStatic(props: SlateElementProps) {
|
|
8
|
+
return (
|
|
9
|
+
<SlateElement {...props}>
|
|
10
|
+
<div className="cursor-text py-6" contentEditable={false}>
|
|
11
|
+
<hr className={cn("h-0.5 rounded-sm border-none bg-muted bg-clip-content")} />
|
|
12
|
+
</div>
|
|
13
|
+
{props.children}
|
|
14
|
+
</SlateElement>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { PlateElementProps } from "platejs/react";
|
|
4
|
+
|
|
5
|
+
import { PlateElement, useFocused, useReadOnly, useSelected } from "platejs/react";
|
|
6
|
+
|
|
7
|
+
import { cn } from "@/lib/utils";
|
|
8
|
+
|
|
9
|
+
export function HrElement(props: PlateElementProps) {
|
|
10
|
+
const readOnly = useReadOnly();
|
|
11
|
+
const selected = useSelected();
|
|
12
|
+
const focused = useFocused();
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<PlateElement {...props}>
|
|
16
|
+
<div className="py-6" contentEditable={false}>
|
|
17
|
+
<hr
|
|
18
|
+
className={cn(
|
|
19
|
+
"h-0.5 rounded-sm border-none bg-muted bg-clip-content",
|
|
20
|
+
selected && focused && "ring-2 ring-ring ring-offset-2",
|
|
21
|
+
!readOnly && "cursor-pointer",
|
|
22
|
+
)}
|
|
23
|
+
/>
|
|
24
|
+
</div>
|
|
25
|
+
{props.children}
|
|
26
|
+
</PlateElement>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useIndentButton, useOutdentButton } from "@platejs/indent/react";
|
|
4
|
+
import { IndentIcon, OutdentIcon } from "lucide-react";
|
|
5
|
+
import type * as React from "react";
|
|
6
|
+
|
|
7
|
+
import { ToolbarButton } from "../../ui/toolbar";
|
|
8
|
+
|
|
9
|
+
export function IndentToolbarButton(props: React.ComponentProps<typeof ToolbarButton>) {
|
|
10
|
+
const { props: buttonProps } = useIndentButton();
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<ToolbarButton {...props} {...buttonProps} tooltip="Indent">
|
|
14
|
+
<IndentIcon />
|
|
15
|
+
</ToolbarButton>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function OutdentToolbarButton(props: React.ComponentProps<typeof ToolbarButton>) {
|
|
20
|
+
const { props: buttonProps } = useOutdentButton();
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<ToolbarButton {...props} {...buttonProps} tooltip="Outdent">
|
|
24
|
+
<OutdentIcon />
|
|
25
|
+
</ToolbarButton>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Combobox } from "@base-ui/react";
|
|
4
|
+
import { useControlled } from "@base-ui/utils/useControlled";
|
|
5
|
+
import { useStableCallback } from "@base-ui/utils/useStableCallback";
|
|
6
|
+
import { useComboboxInput, useHTMLInputCursorState } from "@platejs/combobox/react";
|
|
7
|
+
import { cva } from "class-variance-authority";
|
|
8
|
+
import type { Point, TElement } from "platejs";
|
|
9
|
+
import { useComposedRef, useEditorRef } from "platejs/react";
|
|
10
|
+
import * as React from "react";
|
|
11
|
+
import { useIsCreator } from "@/hooks/editor/use-is-creator";
|
|
12
|
+
import { cn } from "@/lib/utils";
|
|
13
|
+
|
|
14
|
+
interface InlineComboboxContextValue {
|
|
15
|
+
showTrigger: boolean;
|
|
16
|
+
trigger: string;
|
|
17
|
+
removeInput: (focus: boolean) => void;
|
|
18
|
+
|
|
19
|
+
inputRef: React.RefObject<HTMLInputElement | null>;
|
|
20
|
+
inputOnBlur: React.FocusEventHandler<HTMLElement>;
|
|
21
|
+
inputOnKeyDown: React.KeyboardEventHandler<HTMLElement>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const InlineComboboxContext = React.createContext<InlineComboboxContextValue>(
|
|
25
|
+
null as unknown as InlineComboboxContextValue,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
interface InlineComboboxProps extends React.ComponentProps<typeof Combobox.Root> {
|
|
29
|
+
element: TElement;
|
|
30
|
+
trigger: string;
|
|
31
|
+
hideWhenNoValue?: boolean;
|
|
32
|
+
showTrigger?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function InlineCombobox({
|
|
36
|
+
children,
|
|
37
|
+
element,
|
|
38
|
+
hideWhenNoValue = false,
|
|
39
|
+
showTrigger = true,
|
|
40
|
+
trigger,
|
|
41
|
+
inputValue: inputValueProp,
|
|
42
|
+
onInputValueChange: onInputValueChangeProp,
|
|
43
|
+
defaultInputValue = "",
|
|
44
|
+
...rest
|
|
45
|
+
}: InlineComboboxProps) {
|
|
46
|
+
const editor = useEditorRef();
|
|
47
|
+
const inputRef = React.useRef<HTMLInputElement>(null);
|
|
48
|
+
const cursorState = useHTMLInputCursorState(inputRef);
|
|
49
|
+
const isCreator = useIsCreator(element);
|
|
50
|
+
const [inputValue, setInputValueUnwrapped] = useControlled({
|
|
51
|
+
name: "InlineCombobox",
|
|
52
|
+
controlled: inputValueProp,
|
|
53
|
+
default: defaultInputValue,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Track the point just before the input element so we know where to
|
|
58
|
+
* insertText if the combobox closes due to a selection change.
|
|
59
|
+
*/
|
|
60
|
+
const insertPoint = React.useRef<Point | null>(null);
|
|
61
|
+
|
|
62
|
+
React.useEffect(() => {
|
|
63
|
+
const path = editor.api.findPath(element);
|
|
64
|
+
if (!path) return;
|
|
65
|
+
|
|
66
|
+
const point = editor.api.before(path);
|
|
67
|
+
if (!point) return;
|
|
68
|
+
|
|
69
|
+
const pointRef = editor.api.pointRef(point);
|
|
70
|
+
insertPoint.current = pointRef.current;
|
|
71
|
+
|
|
72
|
+
return () => {
|
|
73
|
+
pointRef.unref();
|
|
74
|
+
};
|
|
75
|
+
}, [editor, element]);
|
|
76
|
+
|
|
77
|
+
const { props: inputProps, removeInput } = useComboboxInput({
|
|
78
|
+
cancelInputOnBlur: true,
|
|
79
|
+
cursorState,
|
|
80
|
+
autoFocus: isCreator,
|
|
81
|
+
ref: inputRef,
|
|
82
|
+
onCancelInput: (cause) => {
|
|
83
|
+
if (cause !== "backspace") {
|
|
84
|
+
editor.tf.insertText(trigger + inputValue, {
|
|
85
|
+
at: insertPoint?.current ?? undefined,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (cause === "arrowLeft" || cause === "arrowRight") {
|
|
89
|
+
editor.tf.move({
|
|
90
|
+
distance: 1,
|
|
91
|
+
reverse: cause === "arrowLeft",
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
const onKeyDown = useStableCallback(inputProps.onKeyDown);
|
|
97
|
+
const onBlur = useStableCallback(inputProps.onBlur);
|
|
98
|
+
const contextValue: InlineComboboxContextValue = React.useMemo(
|
|
99
|
+
() => ({
|
|
100
|
+
showTrigger,
|
|
101
|
+
trigger,
|
|
102
|
+
inputProps,
|
|
103
|
+
inputRef,
|
|
104
|
+
removeInput,
|
|
105
|
+
inputOnBlur: onBlur,
|
|
106
|
+
inputOnKeyDown: onKeyDown,
|
|
107
|
+
}),
|
|
108
|
+
[trigger, showTrigger, onBlur, onKeyDown],
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<span contentEditable={false}>
|
|
113
|
+
<InlineComboboxContext.Provider value={contextValue}>
|
|
114
|
+
<Combobox.Root
|
|
115
|
+
open
|
|
116
|
+
inputValue={inputValue}
|
|
117
|
+
onInputValueChange={(v, e) => {
|
|
118
|
+
setInputValueUnwrapped(v);
|
|
119
|
+
return onInputValueChangeProp?.(v, e);
|
|
120
|
+
}}
|
|
121
|
+
{...rest}
|
|
122
|
+
>
|
|
123
|
+
{children}
|
|
124
|
+
</Combobox.Root>
|
|
125
|
+
</InlineComboboxContext.Provider>
|
|
126
|
+
</span>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function InlineComboboxInput({ ref, className, ...props }: React.ComponentProps<"input">) {
|
|
131
|
+
const { showTrigger, trigger, inputOnBlur, inputOnKeyDown, inputRef } =
|
|
132
|
+
React.useContext(InlineComboboxContext);
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<>
|
|
136
|
+
{showTrigger && trigger}
|
|
137
|
+
<Combobox.Input
|
|
138
|
+
ref={useComposedRef(inputRef, ref)}
|
|
139
|
+
className={cn("bg-transparent outline-none", className)}
|
|
140
|
+
onBlur={inputOnBlur}
|
|
141
|
+
onKeyDown={inputOnKeyDown}
|
|
142
|
+
{...props}
|
|
143
|
+
/>
|
|
144
|
+
</>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function InlineComboboxContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
149
|
+
return (
|
|
150
|
+
<Combobox.Portal>
|
|
151
|
+
<Combobox.Positioner className="z-50">
|
|
152
|
+
<Combobox.Popup
|
|
153
|
+
className={cn(
|
|
154
|
+
"max-h-[288px] w-[300px] overflow-y-auto rounded-md bg-popover text-popover-foreground shadow-lg border",
|
|
155
|
+
className,
|
|
156
|
+
)}
|
|
157
|
+
{...props}
|
|
158
|
+
/>
|
|
159
|
+
</Combobox.Positioner>
|
|
160
|
+
</Combobox.Portal>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const comboboxItemVariants = cva(
|
|
165
|
+
"relative mx-1 flex h-[28px] select-none items-center rounded-sm px-2 text-foreground text-sm outline-none [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
|
166
|
+
{
|
|
167
|
+
variants: {
|
|
168
|
+
interactive: {
|
|
169
|
+
false: "",
|
|
170
|
+
true: "cursor-pointer transition-colors hover:bg-accent hover:text-accent-foreground data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
defaultVariants: {
|
|
174
|
+
interactive: true,
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
function InlineComboboxItem({
|
|
180
|
+
className,
|
|
181
|
+
focusEditor = true,
|
|
182
|
+
onClick,
|
|
183
|
+
...props
|
|
184
|
+
}: React.ComponentProps<typeof Combobox.Item> & {
|
|
185
|
+
focusEditor?: boolean;
|
|
186
|
+
}) {
|
|
187
|
+
const { removeInput } = React.useContext(InlineComboboxContext);
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<Combobox.Item
|
|
191
|
+
className={cn(comboboxItemVariants(), className)}
|
|
192
|
+
onClick={(event) => {
|
|
193
|
+
// Focus editor if needed
|
|
194
|
+
removeInput(focusEditor);
|
|
195
|
+
onClick?.(event);
|
|
196
|
+
}}
|
|
197
|
+
{...props}
|
|
198
|
+
/>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function InlineComboboxEmpty({
|
|
203
|
+
children,
|
|
204
|
+
className,
|
|
205
|
+
...props
|
|
206
|
+
}: React.ComponentProps<typeof Combobox.Empty>) {
|
|
207
|
+
return (
|
|
208
|
+
<Combobox.Empty
|
|
209
|
+
className={cn("p-4 text-muted-foreground text-sm empty:hidden", className)}
|
|
210
|
+
{...props}
|
|
211
|
+
>
|
|
212
|
+
{children}
|
|
213
|
+
</Combobox.Empty>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const InlineComboboxList = Combobox.List;
|
|
218
|
+
const InlineComboboxCollection = Combobox.Collection;
|
|
219
|
+
|
|
220
|
+
function InlineComboboxGroup({ className, ...props }: React.ComponentProps<typeof Combobox.Group>) {
|
|
221
|
+
return (
|
|
222
|
+
<Combobox.Group
|
|
223
|
+
{...props}
|
|
224
|
+
className={cn("hidden not-last:border-b py-1.5 [&:has([role=option])]:block", className)}
|
|
225
|
+
/>
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function InlineComboboxGroupLabel({
|
|
230
|
+
className,
|
|
231
|
+
...props
|
|
232
|
+
}: React.ComponentProps<typeof Combobox.GroupLabel>) {
|
|
233
|
+
return (
|
|
234
|
+
<Combobox.GroupLabel
|
|
235
|
+
{...props}
|
|
236
|
+
className={cn("mt-1.5 mb-2 px-3 font-medium text-muted-foreground text-xs", className)}
|
|
237
|
+
/>
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export {
|
|
242
|
+
InlineCombobox,
|
|
243
|
+
InlineComboboxContent,
|
|
244
|
+
InlineComboboxEmpty,
|
|
245
|
+
InlineComboboxGroup,
|
|
246
|
+
InlineComboboxGroupLabel,
|
|
247
|
+
InlineComboboxInput,
|
|
248
|
+
InlineComboboxItem,
|
|
249
|
+
InlineComboboxList,
|
|
250
|
+
InlineComboboxCollection,
|
|
251
|
+
};
|