@docyrus/ui-pro-ai-assistant 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -3
- package/src/components/assistant-animations.tsx +0 -29
- package/src/components/assistant-dialogs.tsx +0 -235
- package/src/components/code-view.tsx +0 -278
- package/src/components/create-agent-task.tsx +0 -104
- package/src/components/create-new-work-version.tsx +0 -30
- package/src/components/extract-web.tsx +0 -160
- package/src/components/forward-to-agent.tsx +0 -90
- package/src/components/generate-chart.tsx +0 -101
- package/src/components/generative-action-button.tsx +0 -122
- package/src/components/generative-tool.tsx +0 -685
- package/src/components/generative-ui-object.tsx +0 -210
- package/src/components/input-area.tsx +0 -1209
- package/src/components/json-schema-layout.tsx +0 -326
- package/src/components/list-item-card.tsx +0 -92
- package/src/components/mermaid-diagram.tsx +0 -192
- package/src/components/preview-image.tsx +0 -47
- package/src/components/request-approval.tsx +0 -48
- package/src/components/request-user-input.tsx +0 -270
- package/src/components/search-web.tsx +0 -319
- package/src/components/sheet-command.tsx +0 -88
- package/src/components/shell-canvas.tsx +0 -122
- package/src/components/show-advanced-data-table.tsx +0 -352
- package/src/components/show-generated-content-options.tsx +0 -93
- package/src/components/show-people-cards.tsx +0 -180
- package/src/components/subagent-tool.tsx +0 -180
- package/src/components/text-editor-tool.tsx +0 -328
- package/src/components/work-canvas.tsx +0 -88
- package/src/components/work-card.tsx +0 -42
- package/src/declarations.d.ts +0 -1
- package/src/docy-assistant.tsx +0 -1962
- package/src/hooks/index.ts +0 -7
- package/src/hooks/use-assistant-api.ts +0 -507
- package/src/hooks/use-deployment-data.ts +0 -162
- package/src/hooks/use-project-state.ts +0 -347
- package/src/hooks/use-session-state.ts +0 -207
- package/src/hooks/use-speech-recognition.ts +0 -137
- package/src/hooks/use-ui-state.ts +0 -185
- package/src/hooks/use-works-state.ts +0 -146
- package/src/i18n/context.tsx +0 -253
- package/src/i18n/index.ts +0 -19
- package/src/i18n/locales/de.json +0 -198
- package/src/i18n/locales/el.json +0 -198
- package/src/i18n/locales/en.json +0 -226
- package/src/i18n/locales/es.json +0 -198
- package/src/i18n/locales/fr.json +0 -198
- package/src/i18n/locales/it.json +0 -198
- package/src/i18n/locales/pt.json +0 -198
- package/src/i18n/locales/sl.json +0 -198
- package/src/i18n/locales/tr.json +0 -211
- package/src/i18n/types.ts +0 -23
- package/src/i18n/use-translation.ts +0 -17
- package/src/index.ts +0 -18
- package/src/internal/plate-editor/editor/auth-context.ts +0 -11
- package/src/internal/plate-editor/editor/editor-base-kit.tsx +0 -39
- package/src/internal/plate-editor/editor/editor-kit.tsx +0 -89
- package/src/internal/plate-editor/editor/plate-editor.tsx +0 -75
- package/src/internal/plate-editor/editor/plate-types.ts +0 -126
- package/src/internal/plate-editor/editor/plugins/ai-kit.tsx +0 -172
- package/src/internal/plate-editor/editor/plugins/autoformat-kit.tsx +0 -211
- package/src/internal/plate-editor/editor/plugins/basic-blocks-base-kit.tsx +0 -26
- package/src/internal/plate-editor/editor/plugins/basic-blocks-kit.tsx +0 -51
- package/src/internal/plate-editor/editor/plugins/basic-marks-base-kit.tsx +0 -24
- package/src/internal/plate-editor/editor/plugins/basic-marks-kit.tsx +0 -38
- package/src/internal/plate-editor/editor/plugins/basic-nodes-kit.tsx +0 -6
- package/src/internal/plate-editor/editor/plugins/block-menu-kit.tsx +0 -14
- package/src/internal/plate-editor/editor/plugins/block-placeholder-kit.tsx +0 -17
- package/src/internal/plate-editor/editor/plugins/block-selection-kit.tsx +0 -31
- package/src/internal/plate-editor/editor/plugins/callout-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/callout-kit.tsx +0 -7
- package/src/internal/plate-editor/editor/plugins/code-block-base-kit.tsx +0 -23
- package/src/internal/plate-editor/editor/plugins/code-block-kit.tsx +0 -26
- package/src/internal/plate-editor/editor/plugins/column-base-kit.tsx +0 -8
- package/src/internal/plate-editor/editor/plugins/column-kit.tsx +0 -7
- package/src/internal/plate-editor/editor/plugins/comment-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/comment-kit.tsx +0 -174
- package/src/internal/plate-editor/editor/plugins/copilot-kit.tsx +0 -68
- package/src/internal/plate-editor/editor/plugins/cursor-overlay-kit.tsx +0 -13
- package/src/internal/plate-editor/editor/plugins/date-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/date-kit.tsx +0 -7
- package/src/internal/plate-editor/editor/plugins/discussion-kit.tsx +0 -36
- package/src/internal/plate-editor/editor/plugins/dnd-kit.tsx +0 -27
- package/src/internal/plate-editor/editor/plugins/docx-export-kit.tsx +0 -43
- package/src/internal/plate-editor/editor/plugins/docx-kit.tsx +0 -6
- package/src/internal/plate-editor/editor/plugins/emoji-kit.tsx +0 -15
- package/src/internal/plate-editor/editor/plugins/exit-break-kit.tsx +0 -12
- package/src/internal/plate-editor/editor/plugins/floating-toolbar-kit.tsx +0 -19
- package/src/internal/plate-editor/editor/plugins/font-base-kit.tsx +0 -36
- package/src/internal/plate-editor/editor/plugins/font-kit.tsx +0 -47
- package/src/internal/plate-editor/editor/plugins/indent-base-kit.tsx +0 -19
- package/src/internal/plate-editor/editor/plugins/indent-kit.tsx +0 -22
- package/src/internal/plate-editor/editor/plugins/link-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/link-kit.tsx +0 -35
- package/src/internal/plate-editor/editor/plugins/list-base-kit.tsx +0 -24
- package/src/internal/plate-editor/editor/plugins/list-kit.tsx +0 -27
- package/src/internal/plate-editor/editor/plugins/markdown-kit.tsx +0 -18
- package/src/internal/plate-editor/editor/plugins/math-base-kit.tsx +0 -8
- package/src/internal/plate-editor/editor/plugins/math-kit.tsx +0 -10
- package/src/internal/plate-editor/editor/plugins/media-base-kit.tsx +0 -37
- package/src/internal/plate-editor/editor/plugins/media-kit.tsx +0 -53
- package/src/internal/plate-editor/editor/plugins/mention-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/mention-kit.tsx +0 -36
- package/src/internal/plate-editor/editor/plugins/slash-kit.tsx +0 -17
- package/src/internal/plate-editor/editor/plugins/suggestion-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/suggestion-kit.tsx +0 -95
- package/src/internal/plate-editor/editor/plugins/table-base-kit.tsx +0 -20
- package/src/internal/plate-editor/editor/plugins/table-kit.tsx +0 -22
- package/src/internal/plate-editor/editor/plugins/toc-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/toc-kit.tsx +0 -14
- package/src/internal/plate-editor/editor/plugins/toggle-base-kit.tsx +0 -5
- package/src/internal/plate-editor/editor/plugins/toggle-kit.tsx +0 -9
- package/src/internal/plate-editor/editor/transforms.ts +0 -165
- package/src/internal/plate-editor/editor/use-chat.ts +0 -152
- package/src/internal/plate-editor/hooks/index.ts +0 -3
- package/src/internal/plate-editor/hooks/use-copy-to-clipboard.ts +0 -31
- package/src/internal/plate-editor/hooks/use-is-touch-device.ts +0 -26
- package/src/internal/plate-editor/hooks/use-lock-scroll.ts +0 -21
- package/src/internal/plate-editor/hooks/use-media-query.ts +0 -44
- package/src/internal/plate-editor/hooks/use-mounted.ts +0 -18
- package/src/internal/plate-editor/hooks/use-on-click-outside.ts +0 -114
- package/src/internal/plate-editor/hooks/use-upload-file.ts +0 -81
- package/src/internal/plate-editor/i18n/context.tsx +0 -58
- package/src/internal/plate-editor/i18n/index.ts +0 -3
- package/src/internal/plate-editor/i18n/locales/de.json +0 -57
- package/src/internal/plate-editor/i18n/locales/el.json +0 -57
- package/src/internal/plate-editor/i18n/locales/en.json +0 -57
- package/src/internal/plate-editor/i18n/locales/es.json +0 -57
- package/src/internal/plate-editor/i18n/locales/fr.json +0 -57
- package/src/internal/plate-editor/i18n/locales/it.json +0 -57
- package/src/internal/plate-editor/i18n/locales/pt.json +0 -57
- package/src/internal/plate-editor/i18n/locales/sl.json +0 -57
- package/src/internal/plate-editor/i18n/locales/tr.json +0 -57
- package/src/internal/plate-editor/i18n/types.ts +0 -59
- package/src/internal/plate-editor/i18n/use-translation.ts +0 -22
- package/src/internal/plate-editor/index.ts +0 -39
- package/src/internal/plate-editor/lib/ai-output-converter.ts +0 -153
- package/src/internal/plate-editor/lib/download-file.ts +0 -17
- package/src/internal/plate-editor/plate-ui/ai-chat-editor.tsx +0 -24
- package/src/internal/plate-editor/plate-ui/ai-menu.tsx +0 -828
- package/src/internal/plate-editor/plate-ui/ai-node.tsx +0 -41
- package/src/internal/plate-editor/plate-ui/ai-toolbar-button.tsx +0 -25
- package/src/internal/plate-editor/plate-ui/alert-dialog.tsx +0 -145
- package/src/internal/plate-editor/plate-ui/align-toolbar-button.tsx +0 -88
- package/src/internal/plate-editor/plate-ui/avatar.tsx +0 -3
- package/src/internal/plate-editor/plate-ui/block-context-menu.tsx +0 -104
- package/src/internal/plate-editor/plate-ui/block-discussion.tsx +0 -364
- package/src/internal/plate-editor/plate-ui/block-draggable.tsx +0 -557
- package/src/internal/plate-editor/plate-ui/block-list-static.tsx +0 -77
- package/src/internal/plate-editor/plate-ui/block-list.tsx +0 -85
- package/src/internal/plate-editor/plate-ui/block-menu.tsx +0 -555
- package/src/internal/plate-editor/plate-ui/block-selection.tsx +0 -47
- package/src/internal/plate-editor/plate-ui/block-suggestion.tsx +0 -469
- package/src/internal/plate-editor/plate-ui/blockquote-node-static.tsx +0 -10
- package/src/internal/plate-editor/plate-ui/blockquote-node.tsx +0 -11
- package/src/internal/plate-editor/plate-ui/button.tsx +0 -201
- package/src/internal/plate-editor/plate-ui/calendar.tsx +0 -3
- package/src/internal/plate-editor/plate-ui/callout-node-static.tsx +0 -76
- package/src/internal/plate-editor/plate-ui/callout-node.tsx +0 -54
- package/src/internal/plate-editor/plate-ui/caption.tsx +0 -47
- package/src/internal/plate-editor/plate-ui/checkbox.tsx +0 -3
- package/src/internal/plate-editor/plate-ui/code-block-node-static.tsx +0 -172
- package/src/internal/plate-editor/plate-ui/code-block-node.tsx +0 -226
- package/src/internal/plate-editor/plate-ui/code-node-static.tsx +0 -11
- package/src/internal/plate-editor/plate-ui/code-node.tsx +0 -12
- package/src/internal/plate-editor/plate-ui/column-node-static.tsx +0 -65
- package/src/internal/plate-editor/plate-ui/column-node.tsx +0 -24
- package/src/internal/plate-editor/plate-ui/command.tsx +0 -202
- package/src/internal/plate-editor/plate-ui/comment-node-static.tsx +0 -12
- package/src/internal/plate-editor/plate-ui/comment-node.tsx +0 -45
- package/src/internal/plate-editor/plate-ui/comment-toolbar-button.tsx +0 -24
- package/src/internal/plate-editor/plate-ui/comment.tsx +0 -619
- package/src/internal/plate-editor/plate-ui/cursor-overlay.tsx +0 -85
- package/src/internal/plate-editor/plate-ui/date-node-static.tsx +0 -43
- package/src/internal/plate-editor/plate-ui/date-node.tsx +0 -54
- package/src/internal/plate-editor/plate-ui/dialog.tsx +0 -445
- package/src/internal/plate-editor/plate-ui/dropdown-menu.tsx +0 -264
- package/src/internal/plate-editor/plate-ui/editor-static.tsx +0 -40
- package/src/internal/plate-editor/plate-ui/editor.tsx +0 -146
- package/src/internal/plate-editor/plate-ui/emoji-node.tsx +0 -48
- package/src/internal/plate-editor/plate-ui/emoji-toolbar-button.tsx +0 -626
- package/src/internal/plate-editor/plate-ui/equation-node-static.tsx +0 -155
- package/src/internal/plate-editor/plate-ui/equation-node.tsx +0 -226
- package/src/internal/plate-editor/plate-ui/equation-toolbar-button.tsx +0 -26
- package/src/internal/plate-editor/plate-ui/export-toolbar-button.tsx +0 -206
- package/src/internal/plate-editor/plate-ui/fixed-toolbar-buttons.tsx +0 -157
- package/src/internal/plate-editor/plate-ui/fixed-toolbar.tsx +0 -25
- package/src/internal/plate-editor/plate-ui/floating-discussion.tsx +0 -1129
- package/src/internal/plate-editor/plate-ui/floating-toolbar-buttons.tsx +0 -129
- package/src/internal/plate-editor/plate-ui/floating-toolbar.tsx +0 -97
- package/src/internal/plate-editor/plate-ui/font-color-toolbar-button.tsx +0 -209
- package/src/internal/plate-editor/plate-ui/font-size-toolbar-button.tsx +0 -152
- package/src/internal/plate-editor/plate-ui/ghost-text.tsx +0 -20
- package/src/internal/plate-editor/plate-ui/heading-node-static.tsx +0 -52
- package/src/internal/plate-editor/plate-ui/heading-node.tsx +0 -56
- package/src/internal/plate-editor/plate-ui/highlight-node-static.tsx +0 -9
- package/src/internal/plate-editor/plate-ui/highlight-node.tsx +0 -11
- package/src/internal/plate-editor/plate-ui/history-toolbar-button.tsx +0 -50
- package/src/internal/plate-editor/plate-ui/hover-card.tsx +0 -7
- package/src/internal/plate-editor/plate-ui/hr-node-static.tsx +0 -18
- package/src/internal/plate-editor/plate-ui/hr-node.tsx +0 -28
- package/src/internal/plate-editor/plate-ui/import-toolbar-button.tsx +0 -122
- package/src/internal/plate-editor/plate-ui/indent-toolbar-button.tsx +0 -32
- package/src/internal/plate-editor/plate-ui/inline-combobox.tsx +0 -409
- package/src/internal/plate-editor/plate-ui/input.tsx +0 -37
- package/src/internal/plate-editor/plate-ui/insert-toolbar-button.tsx +0 -258
- package/src/internal/plate-editor/plate-ui/label.tsx +0 -1
- package/src/internal/plate-editor/plate-ui/line-height-toolbar-button.tsx +0 -69
- package/src/internal/plate-editor/plate-ui/link-node-static.tsx +0 -15
- package/src/internal/plate-editor/plate-ui/link-node.tsx +0 -33
- package/src/internal/plate-editor/plate-ui/link-toolbar-button.tsx +0 -28
- package/src/internal/plate-editor/plate-ui/link-toolbar.tsx +0 -147
- package/src/internal/plate-editor/plate-ui/list-toolbar-button.tsx +0 -177
- package/src/internal/plate-editor/plate-ui/mark-toolbar-button.tsx +0 -34
- package/src/internal/plate-editor/plate-ui/media-audio-node-static.tsx +0 -21
- package/src/internal/plate-editor/plate-ui/media-audio-node.tsx +0 -32
- package/src/internal/plate-editor/plate-ui/media-embed-node.tsx +0 -103
- package/src/internal/plate-editor/plate-ui/media-file-node-static.tsx +0 -30
- package/src/internal/plate-editor/plate-ui/media-file-node.tsx +0 -52
- package/src/internal/plate-editor/plate-ui/media-image-node-static.tsx +0 -37
- package/src/internal/plate-editor/plate-ui/media-image-node.tsx +0 -183
- package/src/internal/plate-editor/plate-ui/media-placeholder-node.tsx +0 -441
- package/src/internal/plate-editor/plate-ui/media-preview-dialog.tsx +0 -127
- package/src/internal/plate-editor/plate-ui/media-toolbar-button.tsx +0 -227
- package/src/internal/plate-editor/plate-ui/media-toolbar.tsx +0 -214
- package/src/internal/plate-editor/plate-ui/media-upload-toast.tsx +0 -73
- package/src/internal/plate-editor/plate-ui/media-video-node-static.tsx +0 -35
- package/src/internal/plate-editor/plate-ui/media-video-node.tsx +0 -119
- package/src/internal/plate-editor/plate-ui/mention-node-static.tsx +0 -46
- package/src/internal/plate-editor/plate-ui/mention-node.tsx +0 -79
- package/src/internal/plate-editor/plate-ui/menu.tsx +0 -539
- package/src/internal/plate-editor/plate-ui/mode-toolbar-button.tsx +0 -124
- package/src/internal/plate-editor/plate-ui/more-toolbar-button.tsx +0 -34
- package/src/internal/plate-editor/plate-ui/paragraph-node-static.tsx +0 -15
- package/src/internal/plate-editor/plate-ui/paragraph-node.tsx +0 -16
- package/src/internal/plate-editor/plate-ui/popover.tsx +0 -75
- package/src/internal/plate-editor/plate-ui/progress.tsx +0 -1
- package/src/internal/plate-editor/plate-ui/remote-cursor-overlay.tsx +0 -79
- package/src/internal/plate-editor/plate-ui/resize-handle.tsx +0 -86
- package/src/internal/plate-editor/plate-ui/separator.tsx +0 -41
- package/src/internal/plate-editor/plate-ui/slash-node.tsx +0 -433
- package/src/internal/plate-editor/plate-ui/spinner.tsx +0 -1
- package/src/internal/plate-editor/plate-ui/suggestion-node-static.tsx +0 -35
- package/src/internal/plate-editor/plate-ui/suggestion-node.tsx +0 -166
- package/src/internal/plate-editor/plate-ui/suggestion-toolbar-button.tsx +0 -24
- package/src/internal/plate-editor/plate-ui/table-node-static.tsx +0 -84
- package/src/internal/plate-editor/plate-ui/table-node.tsx +0 -283
- package/src/internal/plate-editor/plate-ui/table-toolbar-button.tsx +0 -252
- package/src/internal/plate-editor/plate-ui/tabs.tsx +0 -3
- package/src/internal/plate-editor/plate-ui/textarea.tsx +0 -57
- package/src/internal/plate-editor/plate-ui/toc-node-static.tsx +0 -142
- package/src/internal/plate-editor/plate-ui/toc-node.tsx +0 -57
- package/src/internal/plate-editor/plate-ui/toc-sidebar.tsx +0 -48
- package/src/internal/plate-editor/plate-ui/toggle-node-static.tsx +0 -18
- package/src/internal/plate-editor/plate-ui/toggle-node.tsx +0 -33
- package/src/internal/plate-editor/plate-ui/toggle-toolbar-button.tsx +0 -24
- package/src/internal/plate-editor/plate-ui/toggle.tsx +0 -3
- package/src/internal/plate-editor/plate-ui/toolbar.tsx +0 -378
- package/src/internal/plate-editor/plate-ui/tooltip.tsx +0 -148
- package/src/internal/plate-editor/plate-ui/turn-into-toolbar-button.tsx +0 -175
- package/src/internal/plate-editor/types/index.ts +0 -22
- package/src/internal/plate-editor/vite.ts +0 -284
- package/src/internal/sheets/components/univer-sheets.tsx +0 -1104
- package/src/internal/sheets/i18n/context.tsx +0 -183
- package/src/internal/sheets/i18n/index.ts +0 -19
- package/src/internal/sheets/i18n/locales/de.json +0 -21
- package/src/internal/sheets/i18n/locales/el.json +0 -21
- package/src/internal/sheets/i18n/locales/en.json +0 -21
- package/src/internal/sheets/i18n/locales/es.json +0 -21
- package/src/internal/sheets/i18n/locales/fr.json +0 -21
- package/src/internal/sheets/i18n/locales/it.json +0 -21
- package/src/internal/sheets/i18n/locales/pt.json +0 -21
- package/src/internal/sheets/i18n/locales/sl.json +0 -21
- package/src/internal/sheets/i18n/locales/tr.json +0 -21
- package/src/internal/sheets/i18n/types.ts +0 -23
- package/src/internal/sheets/i18n/use-translation.ts +0 -17
- package/src/internal/sheets/index.ts +0 -14
- package/src/internal/sheets/types/css.d.ts +0 -11
- package/src/internal/sheets/types/index.ts +0 -260
- package/src/internal/sheets/xlsx.ts +0 -1169
- package/src/lib/api-client.ts +0 -77
- package/src/lib/assistant-api-actions.ts +0 -549
- package/src/lib/assistant-config.tsx +0 -75
- package/src/lib/class-utils.ts +0 -40
- package/src/lib/index.ts +0 -7
- package/src/lib/message-utils.ts +0 -131
- package/src/tools/tools-schema.json +0 -512
- package/src/types/index.ts +0 -235
- package/src/views/assistant-view.tsx +0 -1137
- package/src/views/canvas-app.tsx +0 -839
- package/src/views/canvas-code.tsx +0 -93
- package/src/views/canvas-deep-research.tsx +0 -44
- package/src/views/canvas-image.tsx +0 -25
- package/src/views/canvas-record-view.tsx +0 -285
- package/src/views/canvas-spreadsheet.tsx +0 -125
- package/src/views/canvas-text.tsx +0 -52
- package/src/views/canvas.tsx +0 -274
- package/src/views/chat-panel.tsx +0 -149
- package/src/views/index.ts +0 -20
- package/src/views/memories-panel.tsx +0 -365
- package/src/views/message-list.tsx +0 -370
- package/src/views/project-detail.tsx +0 -257
- package/src/views/projects-panel.tsx +0 -131
- package/src/views/sessions-list.tsx +0 -98
- package/src/views/sidebar-content.tsx +0 -256
- package/src/views/work-detail.tsx +0 -98
- package/src/vite.ts +0 -64
- package/src/worker.ts +0 -203
|
@@ -1,555 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useMemo, useState, type ReactNode } from 'react';
|
|
4
|
-
|
|
5
|
-
import { AIChatPlugin } from '@platejs/ai/react';
|
|
6
|
-
import { showCaption } from '@platejs/caption/react';
|
|
7
|
-
import { getDraftCommentKey } from '@platejs/comment';
|
|
8
|
-
import {
|
|
9
|
-
BlockMenuPlugin,
|
|
10
|
-
BlockSelectionPlugin,
|
|
11
|
-
useBlockSelectionFragmentProp,
|
|
12
|
-
useBlockSelectionNodes
|
|
13
|
-
} from '@platejs/selection/react';
|
|
14
|
-
import {
|
|
15
|
-
AlignCenter,
|
|
16
|
-
AlignLeft,
|
|
17
|
-
AlignRight,
|
|
18
|
-
CaptionsIcon,
|
|
19
|
-
FilesIcon,
|
|
20
|
-
type LucideProps,
|
|
21
|
-
MessageSquareText,
|
|
22
|
-
PaintRoller,
|
|
23
|
-
RefreshCwIcon,
|
|
24
|
-
Trash2
|
|
25
|
-
} from 'lucide-react';
|
|
26
|
-
import { KEYS, type NodeEntry, type TElement } from 'platejs';
|
|
27
|
-
import { type PlateEditor, useEditorRef, useHotkeys } from 'platejs/react';
|
|
28
|
-
|
|
29
|
-
import { Input } from './input';
|
|
30
|
-
|
|
31
|
-
import {
|
|
32
|
-
type Action,
|
|
33
|
-
ComboboxContent,
|
|
34
|
-
ComboboxEmpty,
|
|
35
|
-
ComboboxInput,
|
|
36
|
-
ComboboxList,
|
|
37
|
-
filterMenuGroups,
|
|
38
|
-
filterMenuItems,
|
|
39
|
-
Menu,
|
|
40
|
-
MenuContent,
|
|
41
|
-
type MenuContentProps,
|
|
42
|
-
MenuGroup,
|
|
43
|
-
MenuItem,
|
|
44
|
-
type MenuProps,
|
|
45
|
-
MenuTrigger,
|
|
46
|
-
useComboboxValueState
|
|
47
|
-
} from './menu';
|
|
48
|
-
|
|
49
|
-
import { commentPlugin } from '../editor/plugins/comment-kit';
|
|
50
|
-
import {
|
|
51
|
-
getBlockType,
|
|
52
|
-
setBlockType
|
|
53
|
-
} from '../editor/transforms';
|
|
54
|
-
import {
|
|
55
|
-
backgroundColorItems,
|
|
56
|
-
ColorIcon,
|
|
57
|
-
textColorItems
|
|
58
|
-
} from './font-color-toolbar-button';
|
|
59
|
-
import { turnIntoItems } from './turn-into-toolbar-button';
|
|
60
|
-
|
|
61
|
-
export function BlockMenu({
|
|
62
|
-
id,
|
|
63
|
-
animateZoom,
|
|
64
|
-
children,
|
|
65
|
-
getAnchorRect,
|
|
66
|
-
open: openProp,
|
|
67
|
-
placement,
|
|
68
|
-
store
|
|
69
|
-
}: Pick<MenuProps, 'open' | 'placement' | 'store'>
|
|
70
|
-
& Pick<MenuContentProps, 'animateZoom' | 'getAnchorRect'> & {
|
|
71
|
-
id?: string;
|
|
72
|
-
children?: ReactNode;
|
|
73
|
-
}) {
|
|
74
|
-
const editor = useEditorRef();
|
|
75
|
-
const [open, setOpen] = useState(false);
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<Menu
|
|
79
|
-
onOpenChange={(open) => {
|
|
80
|
-
setOpen(open);
|
|
81
|
-
|
|
82
|
-
if (!open) {
|
|
83
|
-
editor.getApi(BlockMenuPlugin).blockMenu.hide();
|
|
84
|
-
} else if (id) {
|
|
85
|
-
editor.getApi(BlockMenuPlugin).blockMenu.show(id);
|
|
86
|
-
}
|
|
87
|
-
}}
|
|
88
|
-
open={openProp ?? open}
|
|
89
|
-
placement={placement}
|
|
90
|
-
store={store}
|
|
91
|
-
trigger={children ? <MenuTrigger>{children}</MenuTrigger> : undefined}>
|
|
92
|
-
<MenuContent
|
|
93
|
-
animateZoom={animateZoom}
|
|
94
|
-
autoFocusOnHide={false}
|
|
95
|
-
getAnchorRect={getAnchorRect}
|
|
96
|
-
portal
|
|
97
|
-
preventBodyScroll={!children}>
|
|
98
|
-
<ComboboxContent>
|
|
99
|
-
<BlockMenuInput
|
|
100
|
-
onHide={() => {
|
|
101
|
-
setOpen(false);
|
|
102
|
-
editor.getApi(BlockMenuPlugin).blockMenu.hide();
|
|
103
|
-
}} />
|
|
104
|
-
</ComboboxContent>
|
|
105
|
-
|
|
106
|
-
<ComboboxList>
|
|
107
|
-
<ComboboxEmpty />
|
|
108
|
-
|
|
109
|
-
<BlockMenuItems />
|
|
110
|
-
</ComboboxList>
|
|
111
|
-
</MenuContent>
|
|
112
|
-
</Menu>
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function BlockMenuInput({ onHide }: { onHide: () => void }) {
|
|
117
|
-
const editor = useEditorRef();
|
|
118
|
-
const blockSelectionTf
|
|
119
|
-
= editor.getTransforms(BlockSelectionPlugin).blockSelection;
|
|
120
|
-
const [value] = useComboboxValueState();
|
|
121
|
-
|
|
122
|
-
useHotkeys(
|
|
123
|
-
'backspace',
|
|
124
|
-
(e) => {
|
|
125
|
-
if (value.length === 0) {
|
|
126
|
-
e.preventDefault();
|
|
127
|
-
blockSelectionTf.removeNodes();
|
|
128
|
-
onHide();
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
{ enableOnFormTags: true }
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
useHotkeys(
|
|
135
|
-
'meta+d',
|
|
136
|
-
(e) => {
|
|
137
|
-
if (value.length === 0) {
|
|
138
|
-
e.preventDefault();
|
|
139
|
-
blockSelectionTf.duplicate();
|
|
140
|
-
onHide();
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
{ enableOnFormTags: true }
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
useHotkeys(
|
|
147
|
-
'meta+j',
|
|
148
|
-
() => {
|
|
149
|
-
onHide();
|
|
150
|
-
},
|
|
151
|
-
{ enableOnFormTags: true }
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
return (
|
|
155
|
-
<ComboboxInput>
|
|
156
|
-
<Input placeholder="Search actions..." />
|
|
157
|
-
</ComboboxInput>
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function AIIcon(props: LucideProps) {
|
|
162
|
-
return (
|
|
163
|
-
<svg
|
|
164
|
-
fill="url(#myGradient)"
|
|
165
|
-
viewBox="0 0 512 512"
|
|
166
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
167
|
-
{...props}>
|
|
168
|
-
<defs>
|
|
169
|
-
<linearGradient id="myGradient" x1="0%" x2="100%" y1="0%" y2="100%">
|
|
170
|
-
<stop offset="0%" stopColor="#6EB6F2" />
|
|
171
|
-
<stop offset="15%" stopColor="#6EB6F2" />
|
|
172
|
-
<stop offset="40%" stopColor="#c084fc" />
|
|
173
|
-
<stop offset="60%" stopColor="#f87171" />
|
|
174
|
-
<stop offset="100%" stopColor="#fcd34d" />
|
|
175
|
-
</linearGradient>
|
|
176
|
-
</defs>
|
|
177
|
-
<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" />
|
|
178
|
-
</svg>
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const GROUP = {
|
|
183
|
-
ALIGN: 'align',
|
|
184
|
-
BACKGROUND: 'background',
|
|
185
|
-
COLOR: 'color',
|
|
186
|
-
TURN_INTO: 'turn_into'
|
|
187
|
-
} as const;
|
|
188
|
-
|
|
189
|
-
export const blockMenuItems = {
|
|
190
|
-
askAI: {
|
|
191
|
-
focusEditor: false,
|
|
192
|
-
icon: <AIIcon />,
|
|
193
|
-
keywords: ['generate', 'help', 'chat'],
|
|
194
|
-
label: 'Ask AI',
|
|
195
|
-
shortcut: 'Cmd+J',
|
|
196
|
-
value: 'askAI',
|
|
197
|
-
onSelect: ({ editor }: { editor: PlateEditor }) => {
|
|
198
|
-
editor.getApi(AIChatPlugin).aiChat.show();
|
|
199
|
-
}
|
|
200
|
-
},
|
|
201
|
-
caption: {
|
|
202
|
-
icon: <CaptionsIcon />,
|
|
203
|
-
keywords: ['alt'],
|
|
204
|
-
label: 'Caption',
|
|
205
|
-
value: 'caption',
|
|
206
|
-
onSelect: ({ editor }: { editor: PlateEditor }) => {
|
|
207
|
-
const firstBlock = editor
|
|
208
|
-
.getApi(BlockSelectionPlugin)
|
|
209
|
-
.blockSelection.getNodes()[0];
|
|
210
|
-
|
|
211
|
-
showCaption(editor, firstBlock[0] as TElement);
|
|
212
|
-
editor.getApi(BlockSelectionPlugin).blockSelection.clear();
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
comment: {
|
|
216
|
-
icon: <MessageSquareText />,
|
|
217
|
-
keywords: ['note', 'feedback', 'annotation'],
|
|
218
|
-
label: 'Comment',
|
|
219
|
-
shortcut: 'Cmd+Shift+M',
|
|
220
|
-
value: 'comment',
|
|
221
|
-
onSelect: ({ editor }: { editor: PlateEditor }) => {
|
|
222
|
-
setTimeout(() => {
|
|
223
|
-
editor.getTransforms(BlockSelectionPlugin).blockSelection.select();
|
|
224
|
-
editor.getTransforms(commentPlugin).comment.setDraft();
|
|
225
|
-
editor.tf.collapse();
|
|
226
|
-
editor.setOption(commentPlugin, 'activeId', getDraftCommentKey());
|
|
227
|
-
editor.setOption(
|
|
228
|
-
commentPlugin,
|
|
229
|
-
'commentingBlock',
|
|
230
|
-
editor.selection?.focus.path.slice(0, 1) ?? null
|
|
231
|
-
);
|
|
232
|
-
}, 0);
|
|
233
|
-
}
|
|
234
|
-
},
|
|
235
|
-
delete: {
|
|
236
|
-
icon: <Trash2 />,
|
|
237
|
-
keywords: ['remove'],
|
|
238
|
-
label: 'Delete',
|
|
239
|
-
shortcut: 'Del or Ctrl+D',
|
|
240
|
-
value: 'delete',
|
|
241
|
-
onSelect: ({ editor }: { editor: PlateEditor }) => {
|
|
242
|
-
editor.getTransforms(BlockSelectionPlugin).blockSelection.removeNodes();
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
duplicate: {
|
|
246
|
-
focusEditor: false,
|
|
247
|
-
icon: <FilesIcon />,
|
|
248
|
-
keywords: ['copy'],
|
|
249
|
-
label: 'Duplicate',
|
|
250
|
-
shortcut: 'Cmd+D',
|
|
251
|
-
value: 'duplicate',
|
|
252
|
-
onSelect: ({ editor }: { editor: PlateEditor }) => {
|
|
253
|
-
editor
|
|
254
|
-
.getTransforms(BlockSelectionPlugin)
|
|
255
|
-
.blockSelection.duplicate();
|
|
256
|
-
|
|
257
|
-
editor.getApi(BlockSelectionPlugin).blockSelection.focus();
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
[GROUP.ALIGN]: {
|
|
261
|
-
component: AlignMenuItem,
|
|
262
|
-
filterItems: true,
|
|
263
|
-
icon: <AlignLeft />,
|
|
264
|
-
items: [{ icon: <AlignLeft />, label: 'Left', value: 'left' }, { icon: <AlignCenter />, label: 'Center', value: 'center' }, { icon: <AlignRight />, label: 'Right', value: 'right' }],
|
|
265
|
-
label: 'Align',
|
|
266
|
-
value: GROUP.ALIGN
|
|
267
|
-
},
|
|
268
|
-
[GROUP.COLOR]: {
|
|
269
|
-
component: ColorMenuItem,
|
|
270
|
-
filterItems: true,
|
|
271
|
-
icon: <PaintRoller />,
|
|
272
|
-
items: [
|
|
273
|
-
{ group: GROUP.COLOR, items: textColorItems, label: 'Text color' },
|
|
274
|
-
{
|
|
275
|
-
group: GROUP.BACKGROUND,
|
|
276
|
-
items: backgroundColorItems,
|
|
277
|
-
label: 'Background color'
|
|
278
|
-
}
|
|
279
|
-
],
|
|
280
|
-
keywords: ['highlight', 'background'],
|
|
281
|
-
label: 'Color',
|
|
282
|
-
value: GROUP.COLOR
|
|
283
|
-
},
|
|
284
|
-
[GROUP.TURN_INTO]: {
|
|
285
|
-
component: TurnIntoMenuItem,
|
|
286
|
-
filterItems: true,
|
|
287
|
-
icon: <RefreshCwIcon />,
|
|
288
|
-
items: turnIntoItems,
|
|
289
|
-
label: 'Turn into',
|
|
290
|
-
value: GROUP.TURN_INTO
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
const orderedMenuItems = [
|
|
295
|
-
{
|
|
296
|
-
items: [blockMenuItems.comment]
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
items: [
|
|
300
|
-
blockMenuItems.askAI,
|
|
301
|
-
blockMenuItems.delete,
|
|
302
|
-
blockMenuItems.duplicate,
|
|
303
|
-
blockMenuItems[GROUP.TURN_INTO]
|
|
304
|
-
]
|
|
305
|
-
},
|
|
306
|
-
{
|
|
307
|
-
items: [blockMenuItems[GROUP.COLOR]]
|
|
308
|
-
}
|
|
309
|
-
];
|
|
310
|
-
|
|
311
|
-
const mediaMenuItems = [
|
|
312
|
-
{
|
|
313
|
-
items: [blockMenuItems.comment, blockMenuItems.caption]
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
items: [blockMenuItems[GROUP.ALIGN]]
|
|
317
|
-
},
|
|
318
|
-
{
|
|
319
|
-
items: [blockMenuItems.delete, blockMenuItems.duplicate]
|
|
320
|
-
}
|
|
321
|
-
];
|
|
322
|
-
|
|
323
|
-
function BlockMenuItems() {
|
|
324
|
-
const [searchValue] = useComboboxValueState();
|
|
325
|
-
const selectedBlocks = useBlockSelectionNodes();
|
|
326
|
-
const editor = useEditorRef();
|
|
327
|
-
|
|
328
|
-
const menuGroups = useMemo(() => {
|
|
329
|
-
const isMedia
|
|
330
|
-
= selectedBlocks.length === 1
|
|
331
|
-
&& selectedBlocks.some(item => [
|
|
332
|
-
KEYS.audio,
|
|
333
|
-
KEYS.file,
|
|
334
|
-
KEYS.img,
|
|
335
|
-
KEYS.mediaEmbed,
|
|
336
|
-
KEYS.video
|
|
337
|
-
].includes(
|
|
338
|
-
item[0].type as any
|
|
339
|
-
));
|
|
340
|
-
|
|
341
|
-
const items = isMedia ? mediaMenuItems : orderedMenuItems;
|
|
342
|
-
|
|
343
|
-
return filterMenuGroups(items, searchValue) || items;
|
|
344
|
-
}, [selectedBlocks, searchValue]);
|
|
345
|
-
|
|
346
|
-
return (
|
|
347
|
-
<>
|
|
348
|
-
{menuGroups.map((group, index) => (
|
|
349
|
-
<MenuGroup key={index} label={group.label}>
|
|
350
|
-
{group.items?.map((item: Action) => {
|
|
351
|
-
const menuItem = (blockMenuItems as any)[item.value!];
|
|
352
|
-
|
|
353
|
-
if (menuItem.component) {
|
|
354
|
-
const ItemComponent = menuItem.component;
|
|
355
|
-
|
|
356
|
-
return <ItemComponent key={item.value} />;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
return (
|
|
360
|
-
<MenuItem
|
|
361
|
-
icon={menuItem.icon}
|
|
362
|
-
key={item.value}
|
|
363
|
-
label={menuItem.label}
|
|
364
|
-
onClick={() => {
|
|
365
|
-
menuItem.onSelect?.({ editor });
|
|
366
|
-
|
|
367
|
-
if (menuItem.focusEditor !== false) editor.tf.focus();
|
|
368
|
-
}}
|
|
369
|
-
shortcut={menuItem.shortcut} />
|
|
370
|
-
);
|
|
371
|
-
})}
|
|
372
|
-
</MenuGroup>
|
|
373
|
-
))}
|
|
374
|
-
</>
|
|
375
|
-
);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
function ColorMenuItem() {
|
|
379
|
-
const [searchValue] = useComboboxValueState();
|
|
380
|
-
const editor = useEditorRef();
|
|
381
|
-
|
|
382
|
-
const color = useBlockSelectionFragmentProp({
|
|
383
|
-
key: KEYS.color,
|
|
384
|
-
defaultValue: 'inherit',
|
|
385
|
-
mode: 'text'
|
|
386
|
-
});
|
|
387
|
-
const background = useBlockSelectionFragmentProp({
|
|
388
|
-
key: KEYS.backgroundColor,
|
|
389
|
-
defaultValue: 'transparent'
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
const handleColorChange = (group: string, value: string) => {
|
|
393
|
-
if (group === GROUP.COLOR) {
|
|
394
|
-
editor
|
|
395
|
-
.getTransforms(BlockSelectionPlugin)
|
|
396
|
-
.blockSelection.setNodes({ color: value });
|
|
397
|
-
} else if (group === GROUP.BACKGROUND) {
|
|
398
|
-
editor
|
|
399
|
-
.getTransforms(BlockSelectionPlugin)
|
|
400
|
-
.blockSelection.setNodes({ backgroundColor: value });
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
editor.getApi(BlockSelectionPlugin).blockSelection.focus();
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
const menuGroups = useMemo(
|
|
407
|
-
() => filterMenuGroups(blockMenuItems[GROUP.COLOR].items, searchValue),
|
|
408
|
-
[searchValue]
|
|
409
|
-
);
|
|
410
|
-
|
|
411
|
-
const content = (
|
|
412
|
-
<>
|
|
413
|
-
{menuGroups.map(menuGroup => (
|
|
414
|
-
<MenuGroup key={menuGroup.group} label={menuGroup.label}>
|
|
415
|
-
{menuGroup.items?.map((item, index) => (
|
|
416
|
-
<MenuItem
|
|
417
|
-
checked={menuGroup.group === GROUP.COLOR ? color === item.value : background === item.value}
|
|
418
|
-
icon={<ColorIcon group={menuGroup.group!} value={item.value!} />}
|
|
419
|
-
key={index}
|
|
420
|
-
label={item.label}
|
|
421
|
-
onClick={() => handleColorChange(menuGroup.group!, item.value!)} />
|
|
422
|
-
))}
|
|
423
|
-
</MenuGroup>
|
|
424
|
-
))}
|
|
425
|
-
</>
|
|
426
|
-
);
|
|
427
|
-
|
|
428
|
-
if (searchValue) return content;
|
|
429
|
-
|
|
430
|
-
return (
|
|
431
|
-
<Menu
|
|
432
|
-
placement="right"
|
|
433
|
-
trigger={
|
|
434
|
-
<MenuTrigger
|
|
435
|
-
icon={blockMenuItems[GROUP.COLOR].icon}
|
|
436
|
-
label={blockMenuItems[GROUP.COLOR].label} />
|
|
437
|
-
}>
|
|
438
|
-
<MenuContent portal>{content}</MenuContent>
|
|
439
|
-
</Menu>
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
function AlignMenuItem() {
|
|
444
|
-
const [searchValue] = useComboboxValueState();
|
|
445
|
-
const editor = useEditorRef();
|
|
446
|
-
const value = useBlockSelectionFragmentProp({
|
|
447
|
-
key: 'align',
|
|
448
|
-
defaultValue: 'left'
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
const menuItems = useMemo(
|
|
452
|
-
() => filterMenuItems(blockMenuItems[GROUP.ALIGN], searchValue),
|
|
453
|
-
[searchValue]
|
|
454
|
-
);
|
|
455
|
-
|
|
456
|
-
const content = (
|
|
457
|
-
<>
|
|
458
|
-
{menuItems.map(item => (
|
|
459
|
-
<MenuItem
|
|
460
|
-
checked={value === item.value}
|
|
461
|
-
icon={item.icon}
|
|
462
|
-
key={item.value}
|
|
463
|
-
label={item.label}
|
|
464
|
-
onClick={() => {
|
|
465
|
-
editor
|
|
466
|
-
.getTransforms(BlockSelectionPlugin)
|
|
467
|
-
.blockSelection.setNodes({ align: item.value });
|
|
468
|
-
editor.tf.focus();
|
|
469
|
-
}} />
|
|
470
|
-
))}
|
|
471
|
-
</>
|
|
472
|
-
);
|
|
473
|
-
|
|
474
|
-
if (searchValue)
|
|
475
|
-
return (
|
|
476
|
-
<MenuGroup label={blockMenuItems[GROUP.ALIGN].label}>{content}</MenuGroup>
|
|
477
|
-
);
|
|
478
|
-
|
|
479
|
-
return (
|
|
480
|
-
<Menu
|
|
481
|
-
placement="right"
|
|
482
|
-
trigger={
|
|
483
|
-
<MenuTrigger
|
|
484
|
-
icon={blockMenuItems[GROUP.ALIGN].icon}
|
|
485
|
-
label={blockMenuItems[GROUP.ALIGN].label} />
|
|
486
|
-
}>
|
|
487
|
-
<MenuContent portal>
|
|
488
|
-
<MenuGroup>{content}</MenuGroup>
|
|
489
|
-
</MenuContent>
|
|
490
|
-
</Menu>
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
function TurnIntoMenuItem() {
|
|
495
|
-
const editor = useEditorRef();
|
|
496
|
-
const [searchValue] = useComboboxValueState();
|
|
497
|
-
|
|
498
|
-
const value = useBlockSelectionFragmentProp({
|
|
499
|
-
defaultValue: KEYS.p,
|
|
500
|
-
getProp: node => getBlockType(node as any)
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
const handleTurnInto = (value: string) => {
|
|
504
|
-
editor
|
|
505
|
-
.getApi(BlockSelectionPlugin)
|
|
506
|
-
.blockSelection.getNodes()
|
|
507
|
-
.forEach((entry: NodeEntry<TElement>) => {
|
|
508
|
-
setBlockType(editor, value, { at: entry[1] });
|
|
509
|
-
});
|
|
510
|
-
editor.getApi(BlockSelectionPlugin).blockSelection.focus();
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
const menuItems = useMemo(
|
|
514
|
-
() => filterMenuItems(blockMenuItems[GROUP.TURN_INTO], searchValue),
|
|
515
|
-
[searchValue]
|
|
516
|
-
);
|
|
517
|
-
|
|
518
|
-
const content = (
|
|
519
|
-
<>
|
|
520
|
-
{menuItems.map(item => (
|
|
521
|
-
<MenuItem
|
|
522
|
-
checked={value === item.value}
|
|
523
|
-
icon={
|
|
524
|
-
<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">
|
|
525
|
-
{item.icon}
|
|
526
|
-
</div>
|
|
527
|
-
}
|
|
528
|
-
key={item.value}
|
|
529
|
-
label={item.label}
|
|
530
|
-
onClick={() => handleTurnInto(item.value!)} />
|
|
531
|
-
))}
|
|
532
|
-
</>
|
|
533
|
-
);
|
|
534
|
-
|
|
535
|
-
if (searchValue)
|
|
536
|
-
return (
|
|
537
|
-
<MenuGroup label={blockMenuItems[GROUP.TURN_INTO].label}>
|
|
538
|
-
{content}
|
|
539
|
-
</MenuGroup>
|
|
540
|
-
);
|
|
541
|
-
|
|
542
|
-
return (
|
|
543
|
-
<Menu
|
|
544
|
-
placement="right"
|
|
545
|
-
trigger={
|
|
546
|
-
<MenuTrigger
|
|
547
|
-
icon={blockMenuItems[GROUP.TURN_INTO].icon}
|
|
548
|
-
label={blockMenuItems[GROUP.TURN_INTO].label} />
|
|
549
|
-
}>
|
|
550
|
-
<MenuContent portal>
|
|
551
|
-
<MenuGroup>{content}</MenuGroup>
|
|
552
|
-
</MenuContent>
|
|
553
|
-
</Menu>
|
|
554
|
-
);
|
|
555
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
}
|