@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,435 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
|
|
7
|
+
import { AIChatPlugin } from '@platejs/ai/react';
|
|
8
|
+
import { BlockSelectionPlugin } from '@platejs/selection/react';
|
|
9
|
+
import {
|
|
10
|
+
AudioLinesIcon,
|
|
11
|
+
CalendarIcon,
|
|
12
|
+
ChevronDownIcon,
|
|
13
|
+
Code2Icon,
|
|
14
|
+
FileUpIcon,
|
|
15
|
+
FilmIcon,
|
|
16
|
+
Heading1Icon,
|
|
17
|
+
Heading2Icon,
|
|
18
|
+
Heading3Icon,
|
|
19
|
+
ImageIcon,
|
|
20
|
+
LightbulbIcon,
|
|
21
|
+
ListIcon,
|
|
22
|
+
ListOrderedIcon,
|
|
23
|
+
type LucideProps,
|
|
24
|
+
PilcrowIcon,
|
|
25
|
+
QuoteIcon,
|
|
26
|
+
RadicalIcon,
|
|
27
|
+
RectangleVerticalIcon,
|
|
28
|
+
SquareIcon,
|
|
29
|
+
TableIcon,
|
|
30
|
+
TableOfContentsIcon
|
|
31
|
+
} from 'lucide-react';
|
|
32
|
+
import { KEYS } from 'platejs';
|
|
33
|
+
import {
|
|
34
|
+
PlateElement,
|
|
35
|
+
type PlateEditor,
|
|
36
|
+
type PlateElementProps
|
|
37
|
+
} from 'platejs/react';
|
|
38
|
+
|
|
39
|
+
import {
|
|
40
|
+
insertBlock,
|
|
41
|
+
insertInlineElement,
|
|
42
|
+
setBlockType
|
|
43
|
+
} from '../editor/transforms';
|
|
44
|
+
import { blockMenuItems } from './block-menu';
|
|
45
|
+
import {
|
|
46
|
+
backgroundColorItems,
|
|
47
|
+
ColorIcon,
|
|
48
|
+
textColorItems
|
|
49
|
+
} from './font-color-toolbar-button';
|
|
50
|
+
import {
|
|
51
|
+
InlineCombobox,
|
|
52
|
+
InlineComboboxContent,
|
|
53
|
+
InlineComboboxEmpty,
|
|
54
|
+
InlineComboboxGroup,
|
|
55
|
+
InlineComboboxGroupLabel,
|
|
56
|
+
InlineComboboxInput,
|
|
57
|
+
InlineComboboxItem
|
|
58
|
+
} from './inline-combobox';
|
|
59
|
+
import { turnIntoItems } from './turn-into-toolbar-button';
|
|
60
|
+
|
|
61
|
+
type Group = {
|
|
62
|
+
group: string;
|
|
63
|
+
items: {
|
|
64
|
+
icon: ReactNode;
|
|
65
|
+
value: string;
|
|
66
|
+
onSelect: (editor: PlateEditor, value: string) => void;
|
|
67
|
+
description?: string;
|
|
68
|
+
focusEditor?: boolean;
|
|
69
|
+
keywords?: string[];
|
|
70
|
+
label?: string;
|
|
71
|
+
}[];
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
function AIIcon(props: LucideProps) {
|
|
75
|
+
return (
|
|
76
|
+
<svg
|
|
77
|
+
fill="url(#myGradient)"
|
|
78
|
+
viewBox="0 0 512 512"
|
|
79
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
80
|
+
{...props}>
|
|
81
|
+
<defs>
|
|
82
|
+
<linearGradient id="myGradient" x1="0%" x2="100%" y1="0%" y2="100%">
|
|
83
|
+
<stop offset="0%" stopColor="#6EB6F2" />
|
|
84
|
+
<stop offset="15%" stopColor="#6EB6F2" />
|
|
85
|
+
<stop offset="40%" stopColor="#c084fc" />
|
|
86
|
+
<stop offset="60%" stopColor="#f87171" />
|
|
87
|
+
<stop offset="100%" stopColor="#fcd34d" />
|
|
88
|
+
</linearGradient>
|
|
89
|
+
</defs>
|
|
90
|
+
<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" />
|
|
91
|
+
</svg>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const groups: Group[] = [
|
|
96
|
+
{
|
|
97
|
+
group: 'AI',
|
|
98
|
+
items: [
|
|
99
|
+
{
|
|
100
|
+
description: 'Use AI to generate content.',
|
|
101
|
+
focusEditor: false,
|
|
102
|
+
icon: <AIIcon />,
|
|
103
|
+
keywords: [
|
|
104
|
+
'ai',
|
|
105
|
+
'generate',
|
|
106
|
+
'help',
|
|
107
|
+
'chat'
|
|
108
|
+
],
|
|
109
|
+
label: 'AI',
|
|
110
|
+
value: 'AI',
|
|
111
|
+
onSelect: (editor) => {
|
|
112
|
+
editor.getApi(AIChatPlugin).aiChat.show();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
group: 'Basic blocks',
|
|
119
|
+
items: [
|
|
120
|
+
{
|
|
121
|
+
description: 'Insert a paragraph.',
|
|
122
|
+
icon: <PilcrowIcon />,
|
|
123
|
+
keywords: ['paragraph'],
|
|
124
|
+
label: 'Text',
|
|
125
|
+
value: KEYS.p
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
description: 'Insert a large heading.',
|
|
129
|
+
icon: <Heading1Icon />,
|
|
130
|
+
keywords: ['title', 'h1'],
|
|
131
|
+
label: 'Heading 1',
|
|
132
|
+
value: KEYS.h1
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
description: 'Insert a medium heading.',
|
|
136
|
+
icon: <Heading2Icon />,
|
|
137
|
+
keywords: ['subtitle', 'h2'],
|
|
138
|
+
label: 'Heading 2',
|
|
139
|
+
value: KEYS.h2
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
description: 'Insert a small heading.',
|
|
143
|
+
icon: <Heading3Icon />,
|
|
144
|
+
keywords: ['subtitle', 'h3'],
|
|
145
|
+
label: 'Heading 3',
|
|
146
|
+
value: KEYS.h3
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
description: 'Insert a to-do list.',
|
|
150
|
+
icon: <SquareIcon />,
|
|
151
|
+
keywords: [
|
|
152
|
+
'checklist',
|
|
153
|
+
'task',
|
|
154
|
+
'checkbox',
|
|
155
|
+
'[]'
|
|
156
|
+
],
|
|
157
|
+
label: 'To-do list',
|
|
158
|
+
value: KEYS.listTodo
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
description: 'Insert a bulleted list.',
|
|
162
|
+
icon: <ListIcon />,
|
|
163
|
+
keywords: ['unordered', 'ul', '-'],
|
|
164
|
+
label: 'Bulleted list',
|
|
165
|
+
value: KEYS.ul
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
description: 'Insert a numbered list.',
|
|
169
|
+
icon: <ListOrderedIcon />,
|
|
170
|
+
keywords: ['ordered', 'ol', '1'],
|
|
171
|
+
label: 'Numbered list',
|
|
172
|
+
value: KEYS.ol
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
description: 'Insert a toggleable section.',
|
|
176
|
+
icon: <ChevronDownIcon />,
|
|
177
|
+
keywords: ['collapsible', 'expandable'],
|
|
178
|
+
label: 'Toggle',
|
|
179
|
+
value: KEYS.toggle
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
description: 'Insert a block for code.',
|
|
183
|
+
icon: <Code2Icon />,
|
|
184
|
+
keywords: ['```'],
|
|
185
|
+
label: 'Code Block',
|
|
186
|
+
value: KEYS.codeBlock
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
description: 'Create a table for data.',
|
|
190
|
+
icon: <TableIcon />,
|
|
191
|
+
label: 'Table',
|
|
192
|
+
value: KEYS.table
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
description: 'Insert a quote for emphasis.',
|
|
196
|
+
icon: <QuoteIcon />,
|
|
197
|
+
keywords: [
|
|
198
|
+
'citation',
|
|
199
|
+
'blockquote',
|
|
200
|
+
'quote',
|
|
201
|
+
'>'
|
|
202
|
+
],
|
|
203
|
+
label: 'Blockquote',
|
|
204
|
+
value: KEYS.blockquote
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
description: 'Insert a highlighted block.',
|
|
208
|
+
icon: <LightbulbIcon />,
|
|
209
|
+
keywords: ['note'],
|
|
210
|
+
label: 'Callout',
|
|
211
|
+
value: KEYS.callout
|
|
212
|
+
}
|
|
213
|
+
].map(item => ({
|
|
214
|
+
...item,
|
|
215
|
+
onSelect: (editor: PlateEditor, value: string) => {
|
|
216
|
+
insertBlock(editor, value);
|
|
217
|
+
}
|
|
218
|
+
}))
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
group: 'Media',
|
|
222
|
+
items: [
|
|
223
|
+
{
|
|
224
|
+
description: 'Upload or embed an image.',
|
|
225
|
+
icon: <ImageIcon />,
|
|
226
|
+
keywords: [
|
|
227
|
+
'media',
|
|
228
|
+
'img',
|
|
229
|
+
'picture',
|
|
230
|
+
'photo'
|
|
231
|
+
],
|
|
232
|
+
label: 'Image',
|
|
233
|
+
value: KEYS.img
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
description: 'Upload or embed a video.',
|
|
237
|
+
icon: <FilmIcon />,
|
|
238
|
+
keywords: ['media', 'video', 'movie'],
|
|
239
|
+
label: 'Video',
|
|
240
|
+
value: KEYS.video
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
description: 'Upload or embed audio.',
|
|
244
|
+
icon: <AudioLinesIcon />,
|
|
245
|
+
keywords: ['media', 'audio', 'sound'],
|
|
246
|
+
label: 'Audio',
|
|
247
|
+
value: KEYS.audio
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
description: 'Upload or link any file type.',
|
|
251
|
+
icon: <FileUpIcon />,
|
|
252
|
+
keywords: [
|
|
253
|
+
'media',
|
|
254
|
+
'file',
|
|
255
|
+
'document',
|
|
256
|
+
'attachment'
|
|
257
|
+
],
|
|
258
|
+
label: 'File',
|
|
259
|
+
value: KEYS.file
|
|
260
|
+
}
|
|
261
|
+
].map(item => ({
|
|
262
|
+
...item,
|
|
263
|
+
focusEditor: false,
|
|
264
|
+
onSelect: (editor: PlateEditor, value: string) => {
|
|
265
|
+
insertBlock(editor, value);
|
|
266
|
+
}
|
|
267
|
+
}))
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
group: 'Advanced blocks',
|
|
271
|
+
items: [
|
|
272
|
+
{
|
|
273
|
+
description: 'Generate a table of contents.',
|
|
274
|
+
icon: <TableOfContentsIcon />,
|
|
275
|
+
keywords: ['toc'],
|
|
276
|
+
label: 'Table of content',
|
|
277
|
+
value: KEYS.toc
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
description: 'Insert a block for equations.',
|
|
281
|
+
focusEditor: false,
|
|
282
|
+
icon: <RadicalIcon />,
|
|
283
|
+
keywords: ['math', 'formula'],
|
|
284
|
+
label: 'Equation',
|
|
285
|
+
value: KEYS.equation
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
description: 'Create 3 columns of blocks.',
|
|
289
|
+
icon: <RectangleVerticalIcon />,
|
|
290
|
+
label: '3 columns',
|
|
291
|
+
value: 'action_three_columns'
|
|
292
|
+
}
|
|
293
|
+
].map(item => ({
|
|
294
|
+
...item,
|
|
295
|
+
onSelect: (editor: PlateEditor, value: string) => {
|
|
296
|
+
insertBlock(editor, value);
|
|
297
|
+
}
|
|
298
|
+
}))
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
group: 'Inline',
|
|
302
|
+
items: [
|
|
303
|
+
{
|
|
304
|
+
description: 'Insert an inline math equation.',
|
|
305
|
+
focusEditor: false,
|
|
306
|
+
icon: <RadicalIcon />,
|
|
307
|
+
keywords: ['math', 'inline', 'formula'],
|
|
308
|
+
label: 'Inline Equation',
|
|
309
|
+
value: KEYS.inlineEquation
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
description: 'Insert current or custom date.',
|
|
313
|
+
focusEditor: true,
|
|
314
|
+
icon: <CalendarIcon />,
|
|
315
|
+
keywords: ['time'],
|
|
316
|
+
label: 'Date',
|
|
317
|
+
value: KEYS.date
|
|
318
|
+
}
|
|
319
|
+
].map(item => ({
|
|
320
|
+
...item,
|
|
321
|
+
onSelect: (editor: PlateEditor, value: string) => {
|
|
322
|
+
insertInlineElement(editor, value);
|
|
323
|
+
}
|
|
324
|
+
}))
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
group: 'Turn into',
|
|
328
|
+
items: turnIntoItems.map(item => ({
|
|
329
|
+
...item,
|
|
330
|
+
onSelect: (editor: PlateEditor) => {
|
|
331
|
+
setBlockType(editor, item.value);
|
|
332
|
+
}
|
|
333
|
+
}))
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
group: 'Actions',
|
|
337
|
+
items: [
|
|
338
|
+
{
|
|
339
|
+
...blockMenuItems.delete,
|
|
340
|
+
onSelect: (editor: PlateEditor) => {
|
|
341
|
+
editor.tf.removeNodes();
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
...blockMenuItems.duplicate,
|
|
346
|
+
onSelect: (editor: PlateEditor) => {
|
|
347
|
+
editor.getTransforms(BlockSelectionPlugin).blockSelection.duplicate();
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
]
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
group: 'Text color',
|
|
354
|
+
items: textColorItems.map(item => ({
|
|
355
|
+
...item,
|
|
356
|
+
icon: <ColorIcon group="color" value={item.value} />,
|
|
357
|
+
onSelect: (editor: PlateEditor) => {
|
|
358
|
+
editor.tf.setNodes(
|
|
359
|
+
{ color: item.value },
|
|
360
|
+
{ at: editor.api.block()![1], mode: 'lowest' }
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
}))
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
group: 'Background color',
|
|
367
|
+
items: backgroundColorItems.map(item => ({
|
|
368
|
+
...item,
|
|
369
|
+
icon: <ColorIcon group="background" value={item.value} />,
|
|
370
|
+
onSelect: (editor: PlateEditor) => {
|
|
371
|
+
editor.tf.setNodes(
|
|
372
|
+
{ backgroundColor: item.value },
|
|
373
|
+
{ at: editor.api.block()![1] }
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
}))
|
|
377
|
+
}
|
|
378
|
+
];
|
|
379
|
+
|
|
380
|
+
export function SlashInputElement(props: PlateElementProps) {
|
|
381
|
+
const { children, editor, element } = props;
|
|
382
|
+
|
|
383
|
+
return (
|
|
384
|
+
<PlateElement {...props} as="span">
|
|
385
|
+
<InlineCombobox element={element} trigger="/">
|
|
386
|
+
<InlineComboboxInput />
|
|
387
|
+
|
|
388
|
+
<InlineComboboxContent variant="slash">
|
|
389
|
+
<InlineComboboxEmpty>No results</InlineComboboxEmpty>
|
|
390
|
+
|
|
391
|
+
{groups.map(({ group, items }) => (
|
|
392
|
+
<InlineComboboxGroup key={group}>
|
|
393
|
+
<InlineComboboxGroupLabel>{group}</InlineComboboxGroupLabel>
|
|
394
|
+
{items.map(
|
|
395
|
+
item => (
|
|
396
|
+
<InlineComboboxItem
|
|
397
|
+
focusEditor={(item as any).focusEditor}
|
|
398
|
+
group={group}
|
|
399
|
+
key={item.value}
|
|
400
|
+
keywords={item.keywords}
|
|
401
|
+
label={item.label}
|
|
402
|
+
onClick={() => item.onSelect(editor, item.value)}
|
|
403
|
+
value={item.value}>
|
|
404
|
+
{item.description ? (
|
|
405
|
+
<>
|
|
406
|
+
<div className="flex size-11 items-center justify-center rounded border border-foreground/15 bg-white [&_svg]:size-5 [&_svg]:text-subtle-foreground">
|
|
407
|
+
{item.icon}
|
|
408
|
+
</div>
|
|
409
|
+
<div className="ml-3 flex flex-1 flex-col truncate">
|
|
410
|
+
<span>{item.label ?? item.value}</span>
|
|
411
|
+
<span className="truncate text-muted-foreground text-xs">
|
|
412
|
+
{item.description}
|
|
413
|
+
</span>
|
|
414
|
+
</div>
|
|
415
|
+
</>
|
|
416
|
+
) : (
|
|
417
|
+
<>
|
|
418
|
+
<div className="mr-2 text-subtle-foreground">
|
|
419
|
+
{item.icon}
|
|
420
|
+
</div>
|
|
421
|
+
{item.label ?? item.value}
|
|
422
|
+
</>
|
|
423
|
+
)}
|
|
424
|
+
</InlineComboboxItem>
|
|
425
|
+
)
|
|
426
|
+
)}
|
|
427
|
+
</InlineComboboxGroup>
|
|
428
|
+
))}
|
|
429
|
+
</InlineComboboxContent>
|
|
430
|
+
</InlineCombobox>
|
|
431
|
+
|
|
432
|
+
{children}
|
|
433
|
+
</PlateElement>
|
|
434
|
+
);
|
|
435
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Spinner } from '@docyrus/ui-pro-shared/spinner';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
import { type TSuggestionText } from 'platejs';
|
|
3
|
+
|
|
4
|
+
import { BaseSuggestionPlugin } from '@platejs/suggestion';
|
|
5
|
+
|
|
6
|
+
import { SlateLeaf, type SlateLeafProps } from 'platejs/static';
|
|
7
|
+
|
|
8
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
9
|
+
|
|
10
|
+
export function SuggestionLeafStatic(props: SlateLeafProps<TSuggestionText>) {
|
|
11
|
+
const { editor, leaf } = props;
|
|
12
|
+
|
|
13
|
+
const dataList = editor
|
|
14
|
+
.getApi(BaseSuggestionPlugin)
|
|
15
|
+
.suggestion.dataList(leaf);
|
|
16
|
+
const hasRemove = dataList.some(data => data.type === 'remove');
|
|
17
|
+
const diffOperation = { type: hasRemove ? 'delete' : 'insert' } as const;
|
|
18
|
+
|
|
19
|
+
const Component = ({ delete: 'del', insert: 'ins', update: 'span' } as const)[
|
|
20
|
+
diffOperation.type
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<SlateLeaf
|
|
25
|
+
{...props}
|
|
26
|
+
as={Component}
|
|
27
|
+
className={cn(
|
|
28
|
+
'border-b-2 border-b-brand/[.24] bg-brand/8 text-brand/80 no-underline transition-colors duration-200',
|
|
29
|
+
hasRemove
|
|
30
|
+
&& 'border-b-gray-300 bg-gray-300/25 text-gray-400 line-through'
|
|
31
|
+
)}>
|
|
32
|
+
{props.children}
|
|
33
|
+
</SlateLeaf>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useRef, type ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
|
|
7
|
+
import { type TSuggestionData, type TSuggestionText } from 'platejs';
|
|
8
|
+
|
|
9
|
+
import { cva } from 'class-variance-authority';
|
|
10
|
+
import { CornerDownLeftIcon } from 'lucide-react';
|
|
11
|
+
import {
|
|
12
|
+
PlateLeaf,
|
|
13
|
+
type PlateLeafProps,
|
|
14
|
+
type RenderNodeWrapper,
|
|
15
|
+
useEditorPlugin,
|
|
16
|
+
usePluginOption
|
|
17
|
+
} from 'platejs/react';
|
|
18
|
+
|
|
19
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
20
|
+
|
|
21
|
+
import { type SuggestionConfig, suggestionPlugin } from '../editor/plugins/suggestion-kit';
|
|
22
|
+
|
|
23
|
+
const suggestionVariants = cva(
|
|
24
|
+
cn(
|
|
25
|
+
'bg-emerald-100 text-emerald-700 no-underline transition-colors duration-200'
|
|
26
|
+
),
|
|
27
|
+
{
|
|
28
|
+
defaultVariants: {
|
|
29
|
+
insertActive: false,
|
|
30
|
+
remove: false,
|
|
31
|
+
removeActive: false
|
|
32
|
+
},
|
|
33
|
+
variants: {
|
|
34
|
+
insertActive: {
|
|
35
|
+
false: '',
|
|
36
|
+
true: 'bg-emerald-200/80'
|
|
37
|
+
},
|
|
38
|
+
remove: {
|
|
39
|
+
false: '',
|
|
40
|
+
true: 'bg-red-100 text-red-700'
|
|
41
|
+
},
|
|
42
|
+
removeActive: {
|
|
43
|
+
false: '',
|
|
44
|
+
true: 'bg-red-200/80 no-underline'
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export function SuggestionLeaf(props: PlateLeafProps<TSuggestionText>) {
|
|
51
|
+
const { api, setOption } = useEditorPlugin(suggestionPlugin);
|
|
52
|
+
|
|
53
|
+
const leafId: string = api.suggestion.nodeId(props.leaf) ?? '';
|
|
54
|
+
const activeSuggestionId = usePluginOption(suggestionPlugin, 'activeId');
|
|
55
|
+
const hoverSuggestionId = usePluginOption(suggestionPlugin, 'hoverId');
|
|
56
|
+
const dataList = api.suggestion.dataList(props.leaf);
|
|
57
|
+
|
|
58
|
+
const hasRemove = dataList.some(data => data.type === 'remove');
|
|
59
|
+
const hasActive = dataList.some(data => data.id === activeSuggestionId);
|
|
60
|
+
const hasHover = dataList.some(data => data.id === hoverSuggestionId);
|
|
61
|
+
|
|
62
|
+
const diffOperation = {
|
|
63
|
+
type: hasRemove ? 'delete' : 'insert'
|
|
64
|
+
} as const;
|
|
65
|
+
|
|
66
|
+
const Component = (
|
|
67
|
+
{
|
|
68
|
+
delete: 'del',
|
|
69
|
+
insert: 'ins',
|
|
70
|
+
update: 'span'
|
|
71
|
+
} as const
|
|
72
|
+
)[diffOperation.type];
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<PlateLeaf
|
|
76
|
+
{...props}
|
|
77
|
+
as={Component}
|
|
78
|
+
attributes={{
|
|
79
|
+
...props.attributes,
|
|
80
|
+
onMouseEnter: () => setOption('hoverId', leafId),
|
|
81
|
+
onMouseLeave: () => setOption('hoverId', null)
|
|
82
|
+
}}
|
|
83
|
+
className={suggestionVariants({
|
|
84
|
+
insertActive: hasActive || hasHover,
|
|
85
|
+
remove: hasRemove,
|
|
86
|
+
removeActive: (hasActive || hasHover) && hasRemove
|
|
87
|
+
})} />
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const SuggestionLineBreak: RenderNodeWrapper<SuggestionConfig> = ({
|
|
92
|
+
api,
|
|
93
|
+
element
|
|
94
|
+
}) => {
|
|
95
|
+
if (!api.suggestion.isBlockSuggestion(element)) return;
|
|
96
|
+
|
|
97
|
+
const suggestionData = element.suggestion;
|
|
98
|
+
|
|
99
|
+
return function Component({ children }: { children: ReactNode }) {
|
|
100
|
+
return (
|
|
101
|
+
<SuggestionLineBreakContent suggestionData={suggestionData}>
|
|
102
|
+
{children}
|
|
103
|
+
</SuggestionLineBreakContent>
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
function SuggestionLineBreakContent({
|
|
109
|
+
children,
|
|
110
|
+
suggestionData
|
|
111
|
+
}: {
|
|
112
|
+
children: ReactNode;
|
|
113
|
+
suggestionData: TSuggestionData;
|
|
114
|
+
}) {
|
|
115
|
+
const { isLineBreak, type } = suggestionData;
|
|
116
|
+
const isRemove = type === 'remove';
|
|
117
|
+
const isInsert = type === 'insert';
|
|
118
|
+
|
|
119
|
+
const activeSuggestionId = usePluginOption(suggestionPlugin, 'activeId');
|
|
120
|
+
const hoverSuggestionId = usePluginOption(suggestionPlugin, 'hoverId');
|
|
121
|
+
|
|
122
|
+
const isActive = activeSuggestionId === suggestionData.id;
|
|
123
|
+
const isHover = hoverSuggestionId === suggestionData.id;
|
|
124
|
+
|
|
125
|
+
const spanRef = useRef<HTMLSpanElement>(null);
|
|
126
|
+
const { setOption } = useEditorPlugin(suggestionPlugin);
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<>
|
|
130
|
+
{isLineBreak ? (
|
|
131
|
+
<>
|
|
132
|
+
{children}
|
|
133
|
+
<span
|
|
134
|
+
className={cn(
|
|
135
|
+
'absolute text-justify',
|
|
136
|
+
suggestionVariants({
|
|
137
|
+
insertActive: isInsert && (isActive || isHover),
|
|
138
|
+
remove: isRemove,
|
|
139
|
+
removeActive: (isActive || isHover) && isRemove
|
|
140
|
+
})
|
|
141
|
+
)}
|
|
142
|
+
contentEditable={false}
|
|
143
|
+
ref={spanRef}
|
|
144
|
+
style={{
|
|
145
|
+
bottom: 3.5,
|
|
146
|
+
height: 21
|
|
147
|
+
}}>
|
|
148
|
+
<CornerDownLeftIcon className="mt-0.5 size-4" />
|
|
149
|
+
</span>
|
|
150
|
+
</>
|
|
151
|
+
) : (
|
|
152
|
+
<div
|
|
153
|
+
className={cn(
|
|
154
|
+
suggestionVariants({
|
|
155
|
+
insertActive: isInsert && (isActive || isHover),
|
|
156
|
+
remove: isRemove,
|
|
157
|
+
removeActive: (isActive || isHover) && isRemove
|
|
158
|
+
})
|
|
159
|
+
)}
|
|
160
|
+
data-block-suggestion="true"
|
|
161
|
+
onMouseEnter={() => setOption('hoverId', suggestionData.id)}
|
|
162
|
+
onMouseLeave={() => setOption('hoverId', null)}>
|
|
163
|
+
{children}
|
|
164
|
+
</div>
|
|
165
|
+
)}
|
|
166
|
+
</>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { SuggestionPlugin } from '@platejs/suggestion/react';
|
|
4
|
+
import { PencilLineIcon } from 'lucide-react';
|
|
5
|
+
import { useEditorPlugin, usePluginOption } from 'platejs/react';
|
|
6
|
+
|
|
7
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
8
|
+
|
|
9
|
+
import { ToolbarButton } from './toolbar';
|
|
10
|
+
|
|
11
|
+
export function SuggestionToolbarButton() {
|
|
12
|
+
const { setOption } = useEditorPlugin(SuggestionPlugin);
|
|
13
|
+
const isSuggesting = usePluginOption(SuggestionPlugin, 'isSuggesting');
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<ToolbarButton
|
|
17
|
+
className={cn(isSuggesting && 'text-brand/80 hover:text-brand/80')}
|
|
18
|
+
onClick={() => setOption('isSuggesting', !isSuggesting)}
|
|
19
|
+
onMouseDown={e => e.preventDefault()}
|
|
20
|
+
tooltip={isSuggesting ? 'Turn off suggesting' : 'Suggestion edits'}>
|
|
21
|
+
<PencilLineIcon />
|
|
22
|
+
</ToolbarButton>
|
|
23
|
+
);
|
|
24
|
+
}
|