@docyrus/ui-pro-ai-assistant 0.0.1
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/index.js +26161 -0
- package/dist/index.js.map +1 -0
- package/package.json +155 -0
- package/src/components/assistant-animations.tsx +29 -0
- package/src/components/assistant-dialogs.tsx +235 -0
- package/src/components/code-view.tsx +278 -0
- package/src/components/create-agent-task.tsx +104 -0
- package/src/components/create-new-work-version.tsx +30 -0
- package/src/components/extract-web.tsx +160 -0
- package/src/components/forward-to-agent.tsx +90 -0
- package/src/components/generate-chart.tsx +101 -0
- package/src/components/generative-action-button.tsx +122 -0
- package/src/components/generative-tool.tsx +685 -0
- package/src/components/generative-ui-object.tsx +210 -0
- package/src/components/input-area.tsx +1209 -0
- package/src/components/json-schema-layout.tsx +326 -0
- package/src/components/list-item-card.tsx +92 -0
- package/src/components/mermaid-diagram.tsx +192 -0
- package/src/components/preview-image.tsx +47 -0
- package/src/components/request-approval.tsx +48 -0
- package/src/components/request-user-input.tsx +270 -0
- package/src/components/search-web.tsx +319 -0
- package/src/components/sheet-command.tsx +88 -0
- package/src/components/shell-canvas.tsx +122 -0
- package/src/components/show-advanced-data-table.tsx +352 -0
- package/src/components/show-generated-content-options.tsx +93 -0
- package/src/components/show-people-cards.tsx +180 -0
- package/src/components/subagent-tool.tsx +180 -0
- package/src/components/text-editor-tool.tsx +328 -0
- package/src/components/work-canvas.tsx +88 -0
- package/src/components/work-card.tsx +42 -0
- package/src/declarations.d.ts +1 -0
- package/src/docy-assistant.tsx +1962 -0
- package/src/hooks/index.ts +7 -0
- package/src/hooks/use-assistant-api.ts +507 -0
- package/src/hooks/use-deployment-data.ts +162 -0
- package/src/hooks/use-project-state.ts +347 -0
- package/src/hooks/use-session-state.ts +207 -0
- package/src/hooks/use-speech-recognition.ts +137 -0
- package/src/hooks/use-ui-state.ts +185 -0
- package/src/hooks/use-works-state.ts +146 -0
- package/src/i18n/context.tsx +253 -0
- package/src/i18n/index.ts +19 -0
- package/src/i18n/locales/de.json +198 -0
- package/src/i18n/locales/el.json +198 -0
- package/src/i18n/locales/en.json +226 -0
- package/src/i18n/locales/es.json +198 -0
- package/src/i18n/locales/fr.json +198 -0
- package/src/i18n/locales/it.json +198 -0
- package/src/i18n/locales/pt.json +198 -0
- package/src/i18n/locales/sl.json +198 -0
- package/src/i18n/locales/tr.json +211 -0
- package/src/i18n/types.ts +23 -0
- package/src/i18n/use-translation.ts +17 -0
- package/src/index.ts +18 -0
- package/src/internal/plate-editor/editor/auth-context.ts +11 -0
- package/src/internal/plate-editor/editor/editor-base-kit.tsx +39 -0
- package/src/internal/plate-editor/editor/editor-kit.tsx +89 -0
- package/src/internal/plate-editor/editor/plate-editor.tsx +75 -0
- package/src/internal/plate-editor/editor/plate-types.ts +126 -0
- package/src/internal/plate-editor/editor/plugins/ai-kit.tsx +172 -0
- package/src/internal/plate-editor/editor/plugins/autoformat-kit.tsx +211 -0
- package/src/internal/plate-editor/editor/plugins/basic-blocks-base-kit.tsx +26 -0
- package/src/internal/plate-editor/editor/plugins/basic-blocks-kit.tsx +51 -0
- package/src/internal/plate-editor/editor/plugins/basic-marks-base-kit.tsx +24 -0
- package/src/internal/plate-editor/editor/plugins/basic-marks-kit.tsx +38 -0
- package/src/internal/plate-editor/editor/plugins/basic-nodes-kit.tsx +6 -0
- package/src/internal/plate-editor/editor/plugins/block-menu-kit.tsx +14 -0
- package/src/internal/plate-editor/editor/plugins/block-placeholder-kit.tsx +17 -0
- package/src/internal/plate-editor/editor/plugins/block-selection-kit.tsx +31 -0
- package/src/internal/plate-editor/editor/plugins/callout-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/callout-kit.tsx +7 -0
- package/src/internal/plate-editor/editor/plugins/code-block-base-kit.tsx +23 -0
- package/src/internal/plate-editor/editor/plugins/code-block-kit.tsx +26 -0
- package/src/internal/plate-editor/editor/plugins/column-base-kit.tsx +8 -0
- package/src/internal/plate-editor/editor/plugins/column-kit.tsx +7 -0
- package/src/internal/plate-editor/editor/plugins/comment-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/comment-kit.tsx +174 -0
- package/src/internal/plate-editor/editor/plugins/copilot-kit.tsx +68 -0
- package/src/internal/plate-editor/editor/plugins/cursor-overlay-kit.tsx +13 -0
- package/src/internal/plate-editor/editor/plugins/date-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/date-kit.tsx +7 -0
- package/src/internal/plate-editor/editor/plugins/discussion-kit.tsx +36 -0
- package/src/internal/plate-editor/editor/plugins/dnd-kit.tsx +27 -0
- package/src/internal/plate-editor/editor/plugins/docx-export-kit.tsx +43 -0
- package/src/internal/plate-editor/editor/plugins/docx-kit.tsx +6 -0
- package/src/internal/plate-editor/editor/plugins/emoji-kit.tsx +15 -0
- package/src/internal/plate-editor/editor/plugins/exit-break-kit.tsx +12 -0
- package/src/internal/plate-editor/editor/plugins/floating-toolbar-kit.tsx +19 -0
- package/src/internal/plate-editor/editor/plugins/font-base-kit.tsx +36 -0
- package/src/internal/plate-editor/editor/plugins/font-kit.tsx +47 -0
- package/src/internal/plate-editor/editor/plugins/indent-base-kit.tsx +19 -0
- package/src/internal/plate-editor/editor/plugins/indent-kit.tsx +22 -0
- package/src/internal/plate-editor/editor/plugins/link-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/link-kit.tsx +35 -0
- package/src/internal/plate-editor/editor/plugins/list-base-kit.tsx +24 -0
- package/src/internal/plate-editor/editor/plugins/list-kit.tsx +27 -0
- package/src/internal/plate-editor/editor/plugins/markdown-kit.tsx +18 -0
- package/src/internal/plate-editor/editor/plugins/math-base-kit.tsx +8 -0
- package/src/internal/plate-editor/editor/plugins/math-kit.tsx +10 -0
- package/src/internal/plate-editor/editor/plugins/media-base-kit.tsx +37 -0
- package/src/internal/plate-editor/editor/plugins/media-kit.tsx +53 -0
- package/src/internal/plate-editor/editor/plugins/mention-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/mention-kit.tsx +36 -0
- package/src/internal/plate-editor/editor/plugins/slash-kit.tsx +17 -0
- package/src/internal/plate-editor/editor/plugins/suggestion-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/suggestion-kit.tsx +95 -0
- package/src/internal/plate-editor/editor/plugins/table-base-kit.tsx +20 -0
- package/src/internal/plate-editor/editor/plugins/table-kit.tsx +22 -0
- package/src/internal/plate-editor/editor/plugins/toc-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/toc-kit.tsx +14 -0
- package/src/internal/plate-editor/editor/plugins/toggle-base-kit.tsx +5 -0
- package/src/internal/plate-editor/editor/plugins/toggle-kit.tsx +9 -0
- package/src/internal/plate-editor/editor/transforms.ts +165 -0
- package/src/internal/plate-editor/editor/use-chat.ts +152 -0
- package/src/internal/plate-editor/hooks/index.ts +3 -0
- package/src/internal/plate-editor/hooks/use-copy-to-clipboard.ts +31 -0
- package/src/internal/plate-editor/hooks/use-is-touch-device.ts +26 -0
- package/src/internal/plate-editor/hooks/use-lock-scroll.ts +21 -0
- package/src/internal/plate-editor/hooks/use-media-query.ts +44 -0
- package/src/internal/plate-editor/hooks/use-mounted.ts +18 -0
- package/src/internal/plate-editor/hooks/use-on-click-outside.ts +114 -0
- package/src/internal/plate-editor/hooks/use-upload-file.ts +81 -0
- package/src/internal/plate-editor/i18n/context.tsx +58 -0
- package/src/internal/plate-editor/i18n/index.ts +3 -0
- package/src/internal/plate-editor/i18n/locales/de.json +57 -0
- package/src/internal/plate-editor/i18n/locales/el.json +57 -0
- package/src/internal/plate-editor/i18n/locales/en.json +57 -0
- package/src/internal/plate-editor/i18n/locales/es.json +57 -0
- package/src/internal/plate-editor/i18n/locales/fr.json +57 -0
- package/src/internal/plate-editor/i18n/locales/it.json +57 -0
- package/src/internal/plate-editor/i18n/locales/pt.json +57 -0
- package/src/internal/plate-editor/i18n/locales/sl.json +57 -0
- package/src/internal/plate-editor/i18n/locales/tr.json +57 -0
- package/src/internal/plate-editor/i18n/types.ts +59 -0
- package/src/internal/plate-editor/i18n/use-translation.ts +22 -0
- package/src/internal/plate-editor/index.ts +39 -0
- package/src/internal/plate-editor/lib/ai-output-converter.ts +153 -0
- package/src/internal/plate-editor/lib/download-file.ts +17 -0
- package/src/internal/plate-editor/plate-ui/ai-chat-editor.tsx +26 -0
- package/src/internal/plate-editor/plate-ui/ai-menu.tsx +828 -0
- package/src/internal/plate-editor/plate-ui/ai-node.tsx +41 -0
- package/src/internal/plate-editor/plate-ui/ai-toolbar-button.tsx +27 -0
- package/src/internal/plate-editor/plate-ui/alert-dialog.tsx +147 -0
- package/src/internal/plate-editor/plate-ui/align-toolbar-button.tsx +90 -0
- package/src/internal/plate-editor/plate-ui/avatar.tsx +3 -0
- package/src/internal/plate-editor/plate-ui/block-context-menu.tsx +106 -0
- package/src/internal/plate-editor/plate-ui/block-discussion.tsx +364 -0
- package/src/internal/plate-editor/plate-ui/block-draggable.tsx +556 -0
- package/src/internal/plate-editor/plate-ui/block-list-static.tsx +78 -0
- package/src/internal/plate-editor/plate-ui/block-list.tsx +85 -0
- package/src/internal/plate-editor/plate-ui/block-menu.tsx +557 -0
- package/src/internal/plate-editor/plate-ui/block-selection.tsx +47 -0
- package/src/internal/plate-editor/plate-ui/block-suggestion.tsx +469 -0
- package/src/internal/plate-editor/plate-ui/blockquote-node-static.tsx +10 -0
- package/src/internal/plate-editor/plate-ui/blockquote-node.tsx +11 -0
- package/src/internal/plate-editor/plate-ui/button.tsx +190 -0
- package/src/internal/plate-editor/plate-ui/calendar.tsx +3 -0
- package/src/internal/plate-editor/plate-ui/callout-node-static.tsx +76 -0
- package/src/internal/plate-editor/plate-ui/callout-node.tsx +54 -0
- package/src/internal/plate-editor/plate-ui/caption.tsx +48 -0
- package/src/internal/plate-editor/plate-ui/checkbox.tsx +3 -0
- package/src/internal/plate-editor/plate-ui/code-block-node-static.tsx +172 -0
- package/src/internal/plate-editor/plate-ui/code-block-node.tsx +228 -0
- package/src/internal/plate-editor/plate-ui/code-node-static.tsx +11 -0
- package/src/internal/plate-editor/plate-ui/code-node.tsx +12 -0
- package/src/internal/plate-editor/plate-ui/column-node-static.tsx +65 -0
- package/src/internal/plate-editor/plate-ui/column-node.tsx +24 -0
- package/src/internal/plate-editor/plate-ui/command.tsx +204 -0
- package/src/internal/plate-editor/plate-ui/comment-node-static.tsx +12 -0
- package/src/internal/plate-editor/plate-ui/comment-node.tsx +45 -0
- package/src/internal/plate-editor/plate-ui/comment-toolbar-button.tsx +24 -0
- package/src/internal/plate-editor/plate-ui/comment.tsx +619 -0
- package/src/internal/plate-editor/plate-ui/cursor-overlay.tsx +85 -0
- package/src/internal/plate-editor/plate-ui/date-node-static.tsx +43 -0
- package/src/internal/plate-editor/plate-ui/date-node.tsx +56 -0
- package/src/internal/plate-editor/plate-ui/dialog.tsx +426 -0
- package/src/internal/plate-editor/plate-ui/dropdown-menu.tsx +266 -0
- package/src/internal/plate-editor/plate-ui/editor-static.tsx +40 -0
- package/src/internal/plate-editor/plate-ui/editor.tsx +148 -0
- package/src/internal/plate-editor/plate-ui/emoji-node.tsx +48 -0
- package/src/internal/plate-editor/plate-ui/emoji-toolbar-button.tsx +626 -0
- package/src/internal/plate-editor/plate-ui/equation-node-static.tsx +155 -0
- package/src/internal/plate-editor/plate-ui/equation-node.tsx +226 -0
- package/src/internal/plate-editor/plate-ui/equation-toolbar-button.tsx +26 -0
- package/src/internal/plate-editor/plate-ui/export-toolbar-button.tsx +208 -0
- package/src/internal/plate-editor/plate-ui/fixed-toolbar-buttons.tsx +157 -0
- package/src/internal/plate-editor/plate-ui/fixed-toolbar.tsx +27 -0
- package/src/internal/plate-editor/plate-ui/floating-discussion.tsx +1129 -0
- package/src/internal/plate-editor/plate-ui/floating-toolbar-buttons.tsx +129 -0
- package/src/internal/plate-editor/plate-ui/floating-toolbar.tsx +99 -0
- package/src/internal/plate-editor/plate-ui/font-color-toolbar-button.tsx +211 -0
- package/src/internal/plate-editor/plate-ui/font-size-toolbar-button.tsx +154 -0
- package/src/internal/plate-editor/plate-ui/ghost-text.tsx +20 -0
- package/src/internal/plate-editor/plate-ui/heading-node-static.tsx +52 -0
- package/src/internal/plate-editor/plate-ui/heading-node.tsx +56 -0
- package/src/internal/plate-editor/plate-ui/highlight-node-static.tsx +9 -0
- package/src/internal/plate-editor/plate-ui/highlight-node.tsx +11 -0
- package/src/internal/plate-editor/plate-ui/history-toolbar-button.tsx +52 -0
- package/src/internal/plate-editor/plate-ui/hover-card.tsx +7 -0
- package/src/internal/plate-editor/plate-ui/hr-node-static.tsx +18 -0
- package/src/internal/plate-editor/plate-ui/hr-node.tsx +28 -0
- package/src/internal/plate-editor/plate-ui/import-toolbar-button.tsx +124 -0
- package/src/internal/plate-editor/plate-ui/indent-toolbar-button.tsx +34 -0
- package/src/internal/plate-editor/plate-ui/inline-combobox.tsx +409 -0
- package/src/internal/plate-editor/plate-ui/input.tsx +39 -0
- package/src/internal/plate-editor/plate-ui/insert-toolbar-button.tsx +260 -0
- package/src/internal/plate-editor/plate-ui/label.tsx +1 -0
- package/src/internal/plate-editor/plate-ui/line-height-toolbar-button.tsx +71 -0
- package/src/internal/plate-editor/plate-ui/link-node-static.tsx +15 -0
- package/src/internal/plate-editor/plate-ui/link-node.tsx +33 -0
- package/src/internal/plate-editor/plate-ui/link-toolbar-button.tsx +30 -0
- package/src/internal/plate-editor/plate-ui/link-toolbar.tsx +149 -0
- package/src/internal/plate-editor/plate-ui/list-toolbar-button.tsx +179 -0
- package/src/internal/plate-editor/plate-ui/mark-toolbar-button.tsx +36 -0
- package/src/internal/plate-editor/plate-ui/media-audio-node-static.tsx +21 -0
- package/src/internal/plate-editor/plate-ui/media-audio-node.tsx +32 -0
- package/src/internal/plate-editor/plate-ui/media-embed-node.tsx +103 -0
- package/src/internal/plate-editor/plate-ui/media-file-node-static.tsx +30 -0
- package/src/internal/plate-editor/plate-ui/media-file-node.tsx +52 -0
- package/src/internal/plate-editor/plate-ui/media-image-node-static.tsx +37 -0
- package/src/internal/plate-editor/plate-ui/media-image-node.tsx +183 -0
- package/src/internal/plate-editor/plate-ui/media-placeholder-node.tsx +441 -0
- package/src/internal/plate-editor/plate-ui/media-preview-dialog.tsx +127 -0
- package/src/internal/plate-editor/plate-ui/media-toolbar-button.tsx +229 -0
- package/src/internal/plate-editor/plate-ui/media-toolbar.tsx +216 -0
- package/src/internal/plate-editor/plate-ui/media-upload-toast.tsx +73 -0
- package/src/internal/plate-editor/plate-ui/media-video-node-static.tsx +35 -0
- package/src/internal/plate-editor/plate-ui/media-video-node.tsx +119 -0
- package/src/internal/plate-editor/plate-ui/mention-node-static.tsx +46 -0
- package/src/internal/plate-editor/plate-ui/mention-node.tsx +79 -0
- package/src/internal/plate-editor/plate-ui/menu.tsx +532 -0
- package/src/internal/plate-editor/plate-ui/mode-toolbar-button.tsx +126 -0
- package/src/internal/plate-editor/plate-ui/more-toolbar-button.tsx +34 -0
- package/src/internal/plate-editor/plate-ui/paragraph-node-static.tsx +15 -0
- package/src/internal/plate-editor/plate-ui/paragraph-node.tsx +16 -0
- package/src/internal/plate-editor/plate-ui/popover.tsx +77 -0
- package/src/internal/plate-editor/plate-ui/progress.tsx +1 -0
- package/src/internal/plate-editor/plate-ui/remote-cursor-overlay.tsx +81 -0
- package/src/internal/plate-editor/plate-ui/resize-handle.tsx +88 -0
- package/src/internal/plate-editor/plate-ui/separator.tsx +43 -0
- package/src/internal/plate-editor/plate-ui/slash-node.tsx +435 -0
- package/src/internal/plate-editor/plate-ui/spinner.tsx +1 -0
- package/src/internal/plate-editor/plate-ui/suggestion-node-static.tsx +35 -0
- package/src/internal/plate-editor/plate-ui/suggestion-node.tsx +168 -0
- package/src/internal/plate-editor/plate-ui/suggestion-toolbar-button.tsx +24 -0
- package/src/internal/plate-editor/plate-ui/table-node-static.tsx +85 -0
- package/src/internal/plate-editor/plate-ui/table-node.tsx +285 -0
- package/src/internal/plate-editor/plate-ui/table-toolbar-button.tsx +254 -0
- package/src/internal/plate-editor/plate-ui/tabs.tsx +3 -0
- package/src/internal/plate-editor/plate-ui/textarea.tsx +58 -0
- package/src/internal/plate-editor/plate-ui/toc-node-static.tsx +142 -0
- package/src/internal/plate-editor/plate-ui/toc-node.tsx +57 -0
- package/src/internal/plate-editor/plate-ui/toc-sidebar.tsx +50 -0
- package/src/internal/plate-editor/plate-ui/toggle-node-static.tsx +18 -0
- package/src/internal/plate-editor/plate-ui/toggle-node.tsx +33 -0
- package/src/internal/plate-editor/plate-ui/toggle-toolbar-button.tsx +26 -0
- package/src/internal/plate-editor/plate-ui/toggle.tsx +3 -0
- package/src/internal/plate-editor/plate-ui/toolbar.tsx +380 -0
- package/src/internal/plate-editor/plate-ui/tooltip.tsx +149 -0
- package/src/internal/plate-editor/plate-ui/turn-into-toolbar-button.tsx +177 -0
- package/src/internal/plate-editor/types/index.ts +22 -0
- package/src/internal/plate-editor/vite.ts +284 -0
- package/src/internal/sheets/components/univer-sheets.tsx +1104 -0
- package/src/internal/sheets/i18n/context.tsx +183 -0
- package/src/internal/sheets/i18n/index.ts +19 -0
- package/src/internal/sheets/i18n/locales/de.json +21 -0
- package/src/internal/sheets/i18n/locales/el.json +21 -0
- package/src/internal/sheets/i18n/locales/en.json +21 -0
- package/src/internal/sheets/i18n/locales/es.json +21 -0
- package/src/internal/sheets/i18n/locales/fr.json +21 -0
- package/src/internal/sheets/i18n/locales/it.json +21 -0
- package/src/internal/sheets/i18n/locales/pt.json +21 -0
- package/src/internal/sheets/i18n/locales/sl.json +21 -0
- package/src/internal/sheets/i18n/locales/tr.json +21 -0
- package/src/internal/sheets/i18n/types.ts +23 -0
- package/src/internal/sheets/i18n/use-translation.ts +17 -0
- package/src/internal/sheets/index.ts +14 -0
- package/src/internal/sheets/types/css.d.ts +11 -0
- package/src/internal/sheets/types/index.ts +260 -0
- package/src/internal/sheets/xlsx.ts +1169 -0
- package/src/lib/api-client.ts +77 -0
- package/src/lib/assistant-api-actions.ts +549 -0
- package/src/lib/assistant-config.tsx +71 -0
- package/src/lib/class-utils.ts +40 -0
- package/src/lib/index.ts +7 -0
- package/src/lib/message-utils.ts +131 -0
- package/src/tools/tools-schema.json +512 -0
- package/src/types/index.ts +235 -0
- package/src/views/assistant-view.tsx +1137 -0
- package/src/views/canvas-app.tsx +839 -0
- package/src/views/canvas-code.tsx +93 -0
- package/src/views/canvas-deep-research.tsx +44 -0
- package/src/views/canvas-image.tsx +25 -0
- package/src/views/canvas-record-view.tsx +285 -0
- package/src/views/canvas-spreadsheet.tsx +125 -0
- package/src/views/canvas-text.tsx +52 -0
- package/src/views/canvas.tsx +274 -0
- package/src/views/chat-panel.tsx +149 -0
- package/src/views/index.ts +20 -0
- package/src/views/memories-panel.tsx +365 -0
- package/src/views/message-list.tsx +370 -0
- package/src/views/project-detail.tsx +257 -0
- package/src/views/projects-panel.tsx +131 -0
- package/src/views/sessions-list.tsx +98 -0
- package/src/views/sidebar-content.tsx +256 -0
- package/src/views/work-detail.tsx +98 -0
- package/src/vite.ts +284 -0
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useMemo, useState, type ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
|
|
7
|
+
import { AIChatPlugin } from '@platejs/ai/react';
|
|
8
|
+
import { showCaption } from '@platejs/caption/react';
|
|
9
|
+
import { getDraftCommentKey } from '@platejs/comment';
|
|
10
|
+
import {
|
|
11
|
+
BlockMenuPlugin,
|
|
12
|
+
BlockSelectionPlugin,
|
|
13
|
+
useBlockSelectionFragmentProp,
|
|
14
|
+
useBlockSelectionNodes
|
|
15
|
+
} from '@platejs/selection/react';
|
|
16
|
+
import {
|
|
17
|
+
AlignCenter,
|
|
18
|
+
AlignLeft,
|
|
19
|
+
AlignRight,
|
|
20
|
+
CaptionsIcon,
|
|
21
|
+
FilesIcon,
|
|
22
|
+
type LucideProps,
|
|
23
|
+
MessageSquareText,
|
|
24
|
+
PaintRoller,
|
|
25
|
+
RefreshCwIcon,
|
|
26
|
+
Trash2
|
|
27
|
+
} from 'lucide-react';
|
|
28
|
+
import { KEYS, type TElement } from 'platejs';
|
|
29
|
+
import { type PlateEditor, useEditorRef, useHotkeys } from 'platejs/react';
|
|
30
|
+
|
|
31
|
+
import { Input } from './input';
|
|
32
|
+
|
|
33
|
+
import {
|
|
34
|
+
type Action,
|
|
35
|
+
ComboboxContent,
|
|
36
|
+
ComboboxEmpty,
|
|
37
|
+
ComboboxInput,
|
|
38
|
+
ComboboxList,
|
|
39
|
+
filterMenuGroups,
|
|
40
|
+
filterMenuItems,
|
|
41
|
+
Menu,
|
|
42
|
+
MenuContent,
|
|
43
|
+
type MenuContentProps,
|
|
44
|
+
MenuGroup,
|
|
45
|
+
MenuItem,
|
|
46
|
+
type MenuProps,
|
|
47
|
+
MenuTrigger,
|
|
48
|
+
useComboboxValueState
|
|
49
|
+
} from './menu';
|
|
50
|
+
|
|
51
|
+
import { commentPlugin } from '../editor/plugins/comment-kit';
|
|
52
|
+
import {
|
|
53
|
+
getBlockType,
|
|
54
|
+
setBlockType
|
|
55
|
+
} from '../editor/transforms';
|
|
56
|
+
import {
|
|
57
|
+
backgroundColorItems,
|
|
58
|
+
ColorIcon,
|
|
59
|
+
textColorItems
|
|
60
|
+
} from './font-color-toolbar-button';
|
|
61
|
+
import { turnIntoItems } from './turn-into-toolbar-button';
|
|
62
|
+
|
|
63
|
+
export function BlockMenu({
|
|
64
|
+
id,
|
|
65
|
+
animateZoom,
|
|
66
|
+
children,
|
|
67
|
+
getAnchorRect,
|
|
68
|
+
open: openProp,
|
|
69
|
+
placement,
|
|
70
|
+
store
|
|
71
|
+
}: Pick<MenuProps, 'open' | 'placement' | 'store'>
|
|
72
|
+
& Pick<MenuContentProps, 'animateZoom' | 'getAnchorRect'> & {
|
|
73
|
+
id?: string;
|
|
74
|
+
children?: ReactNode;
|
|
75
|
+
}) {
|
|
76
|
+
const editor = useEditorRef();
|
|
77
|
+
const [open, setOpen] = useState(false);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<Menu
|
|
81
|
+
onOpenChange={(open) => {
|
|
82
|
+
setOpen(open);
|
|
83
|
+
|
|
84
|
+
if (!open) {
|
|
85
|
+
editor.getApi(BlockMenuPlugin).blockMenu.hide();
|
|
86
|
+
} else if (id) {
|
|
87
|
+
editor.getApi(BlockMenuPlugin).blockMenu.show(id);
|
|
88
|
+
}
|
|
89
|
+
}}
|
|
90
|
+
open={openProp ?? open}
|
|
91
|
+
placement={placement}
|
|
92
|
+
store={store}
|
|
93
|
+
trigger={children ? <MenuTrigger>{children}</MenuTrigger> : undefined}>
|
|
94
|
+
<MenuContent
|
|
95
|
+
animateZoom={animateZoom}
|
|
96
|
+
autoFocusOnHide={false}
|
|
97
|
+
getAnchorRect={getAnchorRect}
|
|
98
|
+
portal
|
|
99
|
+
preventBodyScroll={!children}>
|
|
100
|
+
<ComboboxContent>
|
|
101
|
+
<BlockMenuInput
|
|
102
|
+
onHide={() => {
|
|
103
|
+
setOpen(false);
|
|
104
|
+
editor.getApi(BlockMenuPlugin).blockMenu.hide();
|
|
105
|
+
}} />
|
|
106
|
+
</ComboboxContent>
|
|
107
|
+
|
|
108
|
+
<ComboboxList>
|
|
109
|
+
<ComboboxEmpty />
|
|
110
|
+
|
|
111
|
+
<BlockMenuItems />
|
|
112
|
+
</ComboboxList>
|
|
113
|
+
</MenuContent>
|
|
114
|
+
</Menu>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function BlockMenuInput({ onHide }: { onHide: () => void }) {
|
|
119
|
+
const editor = useEditorRef();
|
|
120
|
+
const blockSelectionTf
|
|
121
|
+
= editor.getTransforms(BlockSelectionPlugin).blockSelection;
|
|
122
|
+
const [value] = useComboboxValueState();
|
|
123
|
+
|
|
124
|
+
useHotkeys(
|
|
125
|
+
'backspace',
|
|
126
|
+
(e) => {
|
|
127
|
+
if (value.length === 0) {
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
blockSelectionTf.removeNodes();
|
|
130
|
+
onHide();
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
{ enableOnFormTags: true }
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
useHotkeys(
|
|
137
|
+
'meta+d',
|
|
138
|
+
(e) => {
|
|
139
|
+
if (value.length === 0) {
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
blockSelectionTf.duplicate();
|
|
142
|
+
onHide();
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
{ enableOnFormTags: true }
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
useHotkeys(
|
|
149
|
+
'meta+j',
|
|
150
|
+
() => {
|
|
151
|
+
onHide();
|
|
152
|
+
},
|
|
153
|
+
{ enableOnFormTags: true }
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<ComboboxInput>
|
|
158
|
+
<Input placeholder="Search actions..." />
|
|
159
|
+
</ComboboxInput>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function AIIcon(props: LucideProps) {
|
|
164
|
+
return (
|
|
165
|
+
<svg
|
|
166
|
+
fill="url(#myGradient)"
|
|
167
|
+
viewBox="0 0 512 512"
|
|
168
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
169
|
+
{...props}>
|
|
170
|
+
<defs>
|
|
171
|
+
<linearGradient id="myGradient" x1="0%" x2="100%" y1="0%" y2="100%">
|
|
172
|
+
<stop offset="0%" stopColor="#6EB6F2" />
|
|
173
|
+
<stop offset="15%" stopColor="#6EB6F2" />
|
|
174
|
+
<stop offset="40%" stopColor="#c084fc" />
|
|
175
|
+
<stop offset="60%" stopColor="#f87171" />
|
|
176
|
+
<stop offset="100%" stopColor="#fcd34d" />
|
|
177
|
+
</linearGradient>
|
|
178
|
+
</defs>
|
|
179
|
+
<path d="M161.15 362.26a40.902 40.902 0 0 0 23.78 7.52v-.11a40.989 40.989 0 0 0 37.75-24.8l17.43-53.02a81.642 81.642 0 0 1 51.68-51.53l50.57-16.44a41.051 41.051 0 0 0 20.11-15.31 40.964 40.964 0 0 0 7.32-24.19 41.077 41.077 0 0 0-8.23-23.89 41.051 41.051 0 0 0-20.68-14.54l-49.92-16.21a81.854 81.854 0 0 1-51.82-51.85L222.7 27.33A41.11 41.11 0 0 0 183.63.01c-8.54.07-16.86 2.8-23.78 7.81A41.152 41.152 0 0 0 145 27.97l-16.58 50.97c-4 11.73-10.61 22.39-19.33 31.19s-19.33 15.5-31.01 19.61l-50.54 16.24a41.131 41.131 0 0 0-15.89 10.14 41.059 41.059 0 0 0-9.69 16.17 41.144 41.144 0 0 0-1.44 18.8c.98 6.29 3.42 12.27 7.11 17.46a41.312 41.312 0 0 0 20.39 15.19l49.89 16.18a82.099 82.099 0 0 1 32.11 19.91c2.42 2.4 4.68 4.96 6.77 7.65a81.567 81.567 0 0 1 12.94 24.38l16.44 50.49a40.815 40.815 0 0 0 14.98 19.91zm218.06 143.57c-5.42-3.86-9.5-9.32-11.66-15.61l-9.33-28.64a37.283 37.283 0 0 0-8.9-14.48c-4.05-4.06-9-7.12-14.45-8.93l-28.19-9.19a32.655 32.655 0 0 1-16.24-12.06 32.062 32.062 0 0 1-5.97-18.74c.01-6.76 2.13-13.35 6.06-18.86 3.91-5.53 9.46-9.68 15.87-11.86l28.61-9.27a37.013 37.013 0 0 0 14.08-9.01c3.95-4.04 6.91-8.93 8.67-14.29l9.22-28.22a32.442 32.442 0 0 1 11.72-15.87 32.476 32.476 0 0 1 18.74-6.17c6.74-.07 13.33 1.96 18.86 5.81 5.53 3.84 9.74 9.31 12.03 15.64l9.36 28.84a36.832 36.832 0 0 0 8.94 14.34c4.05 4.03 8.97 7.06 14.39 8.87l28.22 9.19a32.44 32.44 0 0 1 16.29 11.52 32.465 32.465 0 0 1 6.47 18.87 32.458 32.458 0 0 1-21.65 31.19l-28.84 9.36a37.384 37.384 0 0 0-14.36 8.93c-4.05 4.06-7.1 9.01-8.9 14.45l-9.16 28.13A32.492 32.492 0 0 1 417 505.98a32.005 32.005 0 0 1-18.74 6.03 32.508 32.508 0 0 1-19.05-6.18z" />
|
|
180
|
+
</svg>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const GROUP = {
|
|
185
|
+
ALIGN: 'align',
|
|
186
|
+
BACKGROUND: 'background',
|
|
187
|
+
COLOR: 'color',
|
|
188
|
+
TURN_INTO: 'turn_into'
|
|
189
|
+
} as const;
|
|
190
|
+
|
|
191
|
+
export const blockMenuItems = {
|
|
192
|
+
askAI: {
|
|
193
|
+
focusEditor: false,
|
|
194
|
+
icon: <AIIcon />,
|
|
195
|
+
keywords: ['generate', 'help', 'chat'],
|
|
196
|
+
label: 'Ask AI',
|
|
197
|
+
shortcut: 'Cmd+J',
|
|
198
|
+
value: 'askAI',
|
|
199
|
+
onSelect: ({ editor }: { editor: PlateEditor }) => {
|
|
200
|
+
editor.getApi(AIChatPlugin).aiChat.show();
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
caption: {
|
|
204
|
+
icon: <CaptionsIcon />,
|
|
205
|
+
keywords: ['alt'],
|
|
206
|
+
label: 'Caption',
|
|
207
|
+
value: 'caption',
|
|
208
|
+
onSelect: ({ editor }: { editor: PlateEditor }) => {
|
|
209
|
+
const firstBlock = editor
|
|
210
|
+
.getApi(BlockSelectionPlugin)
|
|
211
|
+
.blockSelection.getNodes()[0];
|
|
212
|
+
|
|
213
|
+
showCaption(editor, firstBlock[0] as TElement);
|
|
214
|
+
editor.getApi(BlockSelectionPlugin).blockSelection.clear();
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
comment: {
|
|
218
|
+
icon: <MessageSquareText />,
|
|
219
|
+
keywords: ['note', 'feedback', 'annotation'],
|
|
220
|
+
label: 'Comment',
|
|
221
|
+
shortcut: 'Cmd+Shift+M',
|
|
222
|
+
value: 'comment',
|
|
223
|
+
onSelect: ({ editor }: { editor: PlateEditor }) => {
|
|
224
|
+
setTimeout(() => {
|
|
225
|
+
editor.getTransforms(BlockSelectionPlugin).blockSelection.select();
|
|
226
|
+
editor.getTransforms(commentPlugin).comment.setDraft();
|
|
227
|
+
editor.tf.collapse();
|
|
228
|
+
editor.setOption(commentPlugin, 'activeId', getDraftCommentKey());
|
|
229
|
+
editor.setOption(
|
|
230
|
+
commentPlugin,
|
|
231
|
+
'commentingBlock',
|
|
232
|
+
editor.selection?.focus.path.slice(0, 1) ?? null
|
|
233
|
+
);
|
|
234
|
+
}, 0);
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
delete: {
|
|
238
|
+
icon: <Trash2 />,
|
|
239
|
+
keywords: ['remove'],
|
|
240
|
+
label: 'Delete',
|
|
241
|
+
shortcut: 'Del or Ctrl+D',
|
|
242
|
+
value: 'delete',
|
|
243
|
+
onSelect: ({ editor }: { editor: PlateEditor }) => {
|
|
244
|
+
editor.getTransforms(BlockSelectionPlugin).blockSelection.removeNodes();
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
duplicate: {
|
|
248
|
+
focusEditor: false,
|
|
249
|
+
icon: <FilesIcon />,
|
|
250
|
+
keywords: ['copy'],
|
|
251
|
+
label: 'Duplicate',
|
|
252
|
+
shortcut: 'Cmd+D',
|
|
253
|
+
value: 'duplicate',
|
|
254
|
+
onSelect: ({ editor }: { editor: PlateEditor }) => {
|
|
255
|
+
editor
|
|
256
|
+
.getTransforms(BlockSelectionPlugin)
|
|
257
|
+
.blockSelection.duplicate();
|
|
258
|
+
|
|
259
|
+
editor.getApi(BlockSelectionPlugin).blockSelection.focus();
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
[GROUP.ALIGN]: {
|
|
263
|
+
component: AlignMenuItem,
|
|
264
|
+
filterItems: true,
|
|
265
|
+
icon: <AlignLeft />,
|
|
266
|
+
items: [{ icon: <AlignLeft />, label: 'Left', value: 'left' }, { icon: <AlignCenter />, label: 'Center', value: 'center' }, { icon: <AlignRight />, label: 'Right', value: 'right' }],
|
|
267
|
+
label: 'Align',
|
|
268
|
+
value: GROUP.ALIGN
|
|
269
|
+
},
|
|
270
|
+
[GROUP.COLOR]: {
|
|
271
|
+
component: ColorMenuItem,
|
|
272
|
+
filterItems: true,
|
|
273
|
+
icon: <PaintRoller />,
|
|
274
|
+
items: [
|
|
275
|
+
{ group: GROUP.COLOR, items: textColorItems, label: 'Text color' },
|
|
276
|
+
{
|
|
277
|
+
group: GROUP.BACKGROUND,
|
|
278
|
+
items: backgroundColorItems,
|
|
279
|
+
label: 'Background color'
|
|
280
|
+
}
|
|
281
|
+
],
|
|
282
|
+
keywords: ['highlight', 'background'],
|
|
283
|
+
label: 'Color',
|
|
284
|
+
value: GROUP.COLOR
|
|
285
|
+
},
|
|
286
|
+
[GROUP.TURN_INTO]: {
|
|
287
|
+
component: TurnIntoMenuItem,
|
|
288
|
+
filterItems: true,
|
|
289
|
+
icon: <RefreshCwIcon />,
|
|
290
|
+
items: turnIntoItems,
|
|
291
|
+
label: 'Turn into',
|
|
292
|
+
value: GROUP.TURN_INTO
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const orderedMenuItems = [
|
|
297
|
+
{
|
|
298
|
+
items: [blockMenuItems.comment]
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
items: [
|
|
302
|
+
blockMenuItems.askAI,
|
|
303
|
+
blockMenuItems.delete,
|
|
304
|
+
blockMenuItems.duplicate,
|
|
305
|
+
blockMenuItems[GROUP.TURN_INTO]
|
|
306
|
+
]
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
items: [blockMenuItems[GROUP.COLOR]]
|
|
310
|
+
}
|
|
311
|
+
];
|
|
312
|
+
|
|
313
|
+
const mediaMenuItems = [
|
|
314
|
+
{
|
|
315
|
+
items: [blockMenuItems.comment, blockMenuItems.caption]
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
items: [blockMenuItems[GROUP.ALIGN]]
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
items: [blockMenuItems.delete, blockMenuItems.duplicate]
|
|
322
|
+
}
|
|
323
|
+
];
|
|
324
|
+
|
|
325
|
+
function BlockMenuItems() {
|
|
326
|
+
const [searchValue] = useComboboxValueState();
|
|
327
|
+
const selectedBlocks = useBlockSelectionNodes();
|
|
328
|
+
const editor = useEditorRef();
|
|
329
|
+
|
|
330
|
+
const menuGroups = useMemo(() => {
|
|
331
|
+
const isMedia
|
|
332
|
+
= selectedBlocks.length === 1
|
|
333
|
+
&& selectedBlocks.some(item => [
|
|
334
|
+
KEYS.audio,
|
|
335
|
+
KEYS.file,
|
|
336
|
+
KEYS.img,
|
|
337
|
+
KEYS.mediaEmbed,
|
|
338
|
+
KEYS.video
|
|
339
|
+
].includes(
|
|
340
|
+
item[0].type as any
|
|
341
|
+
));
|
|
342
|
+
|
|
343
|
+
const items = isMedia ? mediaMenuItems : orderedMenuItems;
|
|
344
|
+
|
|
345
|
+
return filterMenuGroups(items, searchValue) || items;
|
|
346
|
+
}, [selectedBlocks, searchValue]);
|
|
347
|
+
|
|
348
|
+
return (
|
|
349
|
+
<>
|
|
350
|
+
{menuGroups.map((group, index) => (
|
|
351
|
+
<MenuGroup key={index} label={group.label}>
|
|
352
|
+
{group.items?.map((item: Action) => {
|
|
353
|
+
const menuItem = (blockMenuItems as any)[item.value!];
|
|
354
|
+
|
|
355
|
+
if (menuItem.component) {
|
|
356
|
+
const ItemComponent = menuItem.component;
|
|
357
|
+
|
|
358
|
+
return <ItemComponent key={item.value} />;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return (
|
|
362
|
+
<MenuItem
|
|
363
|
+
icon={menuItem.icon}
|
|
364
|
+
key={item.value}
|
|
365
|
+
label={menuItem.label}
|
|
366
|
+
onClick={() => {
|
|
367
|
+
menuItem.onSelect?.({ editor });
|
|
368
|
+
|
|
369
|
+
if (menuItem.focusEditor !== false) editor.tf.focus();
|
|
370
|
+
}}
|
|
371
|
+
shortcut={menuItem.shortcut} />
|
|
372
|
+
);
|
|
373
|
+
})}
|
|
374
|
+
</MenuGroup>
|
|
375
|
+
))}
|
|
376
|
+
</>
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function ColorMenuItem() {
|
|
381
|
+
const [searchValue] = useComboboxValueState();
|
|
382
|
+
const editor = useEditorRef();
|
|
383
|
+
|
|
384
|
+
const color = useBlockSelectionFragmentProp({
|
|
385
|
+
key: KEYS.color,
|
|
386
|
+
defaultValue: 'inherit',
|
|
387
|
+
mode: 'text'
|
|
388
|
+
});
|
|
389
|
+
const background = useBlockSelectionFragmentProp({
|
|
390
|
+
key: KEYS.backgroundColor,
|
|
391
|
+
defaultValue: 'transparent'
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
const handleColorChange = (group: string, value: string) => {
|
|
395
|
+
if (group === GROUP.COLOR) {
|
|
396
|
+
editor
|
|
397
|
+
.getTransforms(BlockSelectionPlugin)
|
|
398
|
+
.blockSelection.setNodes({ color: value });
|
|
399
|
+
} else if (group === GROUP.BACKGROUND) {
|
|
400
|
+
editor
|
|
401
|
+
.getTransforms(BlockSelectionPlugin)
|
|
402
|
+
.blockSelection.setNodes({ backgroundColor: value });
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
editor.getApi(BlockSelectionPlugin).blockSelection.focus();
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
const menuGroups = useMemo(
|
|
409
|
+
() => filterMenuGroups(blockMenuItems[GROUP.COLOR].items, searchValue),
|
|
410
|
+
[searchValue]
|
|
411
|
+
);
|
|
412
|
+
|
|
413
|
+
const content = (
|
|
414
|
+
<>
|
|
415
|
+
{menuGroups.map(menuGroup => (
|
|
416
|
+
<MenuGroup key={menuGroup.group} label={menuGroup.label}>
|
|
417
|
+
{menuGroup.items?.map((item, index) => (
|
|
418
|
+
<MenuItem
|
|
419
|
+
checked={menuGroup.group === GROUP.COLOR ? color === item.value : background === item.value}
|
|
420
|
+
icon={<ColorIcon group={menuGroup.group!} value={item.value!} />}
|
|
421
|
+
key={index}
|
|
422
|
+
label={item.label}
|
|
423
|
+
onClick={() => handleColorChange(menuGroup.group!, item.value!)} />
|
|
424
|
+
))}
|
|
425
|
+
</MenuGroup>
|
|
426
|
+
))}
|
|
427
|
+
</>
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
if (searchValue) return content;
|
|
431
|
+
|
|
432
|
+
return (
|
|
433
|
+
<Menu
|
|
434
|
+
placement="right"
|
|
435
|
+
trigger={
|
|
436
|
+
<MenuTrigger
|
|
437
|
+
icon={blockMenuItems[GROUP.COLOR].icon}
|
|
438
|
+
label={blockMenuItems[GROUP.COLOR].label} />
|
|
439
|
+
}>
|
|
440
|
+
<MenuContent portal>{content}</MenuContent>
|
|
441
|
+
</Menu>
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function AlignMenuItem() {
|
|
446
|
+
const [searchValue] = useComboboxValueState();
|
|
447
|
+
const editor = useEditorRef();
|
|
448
|
+
const value = useBlockSelectionFragmentProp({
|
|
449
|
+
key: 'align',
|
|
450
|
+
defaultValue: 'left'
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
const menuItems = useMemo(
|
|
454
|
+
() => filterMenuItems(blockMenuItems[GROUP.ALIGN], searchValue),
|
|
455
|
+
[searchValue]
|
|
456
|
+
);
|
|
457
|
+
|
|
458
|
+
const content = (
|
|
459
|
+
<>
|
|
460
|
+
{menuItems.map(item => (
|
|
461
|
+
<MenuItem
|
|
462
|
+
checked={value === item.value}
|
|
463
|
+
icon={item.icon}
|
|
464
|
+
key={item.value}
|
|
465
|
+
label={item.label}
|
|
466
|
+
onClick={() => {
|
|
467
|
+
editor
|
|
468
|
+
.getTransforms(BlockSelectionPlugin)
|
|
469
|
+
.blockSelection.setNodes({ align: item.value });
|
|
470
|
+
editor.tf.focus();
|
|
471
|
+
}} />
|
|
472
|
+
))}
|
|
473
|
+
</>
|
|
474
|
+
);
|
|
475
|
+
|
|
476
|
+
if (searchValue)
|
|
477
|
+
return (
|
|
478
|
+
<MenuGroup label={blockMenuItems[GROUP.ALIGN].label}>{content}</MenuGroup>
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
return (
|
|
482
|
+
<Menu
|
|
483
|
+
placement="right"
|
|
484
|
+
trigger={
|
|
485
|
+
<MenuTrigger
|
|
486
|
+
icon={blockMenuItems[GROUP.ALIGN].icon}
|
|
487
|
+
label={blockMenuItems[GROUP.ALIGN].label} />
|
|
488
|
+
}>
|
|
489
|
+
<MenuContent portal>
|
|
490
|
+
<MenuGroup>{content}</MenuGroup>
|
|
491
|
+
</MenuContent>
|
|
492
|
+
</Menu>
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function TurnIntoMenuItem() {
|
|
497
|
+
const editor = useEditorRef();
|
|
498
|
+
const [searchValue] = useComboboxValueState();
|
|
499
|
+
|
|
500
|
+
const value = useBlockSelectionFragmentProp({
|
|
501
|
+
defaultValue: KEYS.p,
|
|
502
|
+
getProp: node => getBlockType(node as any)
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
const handleTurnInto = (value: string) => {
|
|
506
|
+
editor
|
|
507
|
+
.getApi(BlockSelectionPlugin)
|
|
508
|
+
.blockSelection.getNodes()
|
|
509
|
+
.forEach(([, path]) => {
|
|
510
|
+
setBlockType(editor, value, { at: path });
|
|
511
|
+
});
|
|
512
|
+
editor.getApi(BlockSelectionPlugin).blockSelection.focus();
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
const menuItems = useMemo(
|
|
516
|
+
() => filterMenuItems(blockMenuItems[GROUP.TURN_INTO], searchValue),
|
|
517
|
+
[searchValue]
|
|
518
|
+
);
|
|
519
|
+
|
|
520
|
+
const content = (
|
|
521
|
+
<>
|
|
522
|
+
{menuItems.map(item => (
|
|
523
|
+
<MenuItem
|
|
524
|
+
checked={value === item.value}
|
|
525
|
+
icon={
|
|
526
|
+
<div className="flex size-5 items-center justify-center rounded-sm border border-foreground/15 bg-white p-0.5 text-subtle-foreground [&_svg]:size-3">
|
|
527
|
+
{item.icon}
|
|
528
|
+
</div>
|
|
529
|
+
}
|
|
530
|
+
key={item.value}
|
|
531
|
+
label={item.label}
|
|
532
|
+
onClick={() => handleTurnInto(item.value!)} />
|
|
533
|
+
))}
|
|
534
|
+
</>
|
|
535
|
+
);
|
|
536
|
+
|
|
537
|
+
if (searchValue)
|
|
538
|
+
return (
|
|
539
|
+
<MenuGroup label={blockMenuItems[GROUP.TURN_INTO].label}>
|
|
540
|
+
{content}
|
|
541
|
+
</MenuGroup>
|
|
542
|
+
);
|
|
543
|
+
|
|
544
|
+
return (
|
|
545
|
+
<Menu
|
|
546
|
+
placement="right"
|
|
547
|
+
trigger={
|
|
548
|
+
<MenuTrigger
|
|
549
|
+
icon={blockMenuItems[GROUP.TURN_INTO].icon}
|
|
550
|
+
label={blockMenuItems[GROUP.TURN_INTO].label} />
|
|
551
|
+
}>
|
|
552
|
+
<MenuContent portal>
|
|
553
|
+
<MenuGroup>{content}</MenuGroup>
|
|
554
|
+
</MenuContent>
|
|
555
|
+
</Menu>
|
|
556
|
+
);
|
|
557
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { DndPlugin } from '@platejs/dnd';
|
|
4
|
+
import { useBlockSelected } from '@platejs/selection/react';
|
|
5
|
+
import { cva } from 'class-variance-authority';
|
|
6
|
+
import { type PlateElementProps, usePluginOption } from 'platejs/react';
|
|
7
|
+
|
|
8
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
9
|
+
|
|
10
|
+
export const blockSelectionVariants = cva(
|
|
11
|
+
cn(
|
|
12
|
+
'before:pointer-events-none before:absolute before:inset-0 before:z-1 before:size-full before:rounded-[4px] before:content-[""]',
|
|
13
|
+
'before:bg-brand/15',
|
|
14
|
+
'before:transition-opacity before:duration-200'
|
|
15
|
+
),
|
|
16
|
+
{
|
|
17
|
+
defaultVariants: {
|
|
18
|
+
active: true
|
|
19
|
+
},
|
|
20
|
+
variants: {
|
|
21
|
+
active: {
|
|
22
|
+
false: 'before:opacity-0',
|
|
23
|
+
true: 'before:opacity-100'
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export function BlockSelection(props: PlateElementProps) {
|
|
30
|
+
const isBlockSelected = useBlockSelected();
|
|
31
|
+
const isDragging = usePluginOption(DndPlugin, 'isDragging');
|
|
32
|
+
|
|
33
|
+
if (
|
|
34
|
+
!isBlockSelected
|
|
35
|
+
|| props.plugin.key === 'tr'
|
|
36
|
+
|| props.plugin.key === 'table'
|
|
37
|
+
)
|
|
38
|
+
return null;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div
|
|
42
|
+
className={blockSelectionVariants({
|
|
43
|
+
active: isBlockSelected && !isDragging
|
|
44
|
+
})}
|
|
45
|
+
data-slot="block-selection" />
|
|
46
|
+
);
|
|
47
|
+
}
|