@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,229 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback, useState, type ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
|
|
7
|
+
import { PlaceholderPlugin } from '@platejs/media/react';
|
|
8
|
+
import {
|
|
9
|
+
AudioLinesIcon,
|
|
10
|
+
FileUpIcon,
|
|
11
|
+
FilmIcon,
|
|
12
|
+
ImageIcon,
|
|
13
|
+
LinkIcon
|
|
14
|
+
} from 'lucide-react';
|
|
15
|
+
import { isUrl, KEYS } from 'platejs';
|
|
16
|
+
import { useEditorRef } from 'platejs/react';
|
|
17
|
+
import { toast } from 'sonner';
|
|
18
|
+
import { useFilePicker } from 'use-file-picker';
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
AlertDialog,
|
|
22
|
+
AlertDialogAction,
|
|
23
|
+
AlertDialogCancel,
|
|
24
|
+
AlertDialogContent,
|
|
25
|
+
AlertDialogDescription,
|
|
26
|
+
AlertDialogFooter,
|
|
27
|
+
AlertDialogHeader,
|
|
28
|
+
AlertDialogTitle
|
|
29
|
+
} from './alert-dialog';
|
|
30
|
+
import {
|
|
31
|
+
DropdownMenu,
|
|
32
|
+
DropdownMenuContent,
|
|
33
|
+
DropdownMenuGroup,
|
|
34
|
+
DropdownMenuItem,
|
|
35
|
+
DropdownMenuPortal,
|
|
36
|
+
DropdownMenuTrigger,
|
|
37
|
+
type DropdownMenuProps
|
|
38
|
+
} from './dropdown-menu';
|
|
39
|
+
import { Input } from './input';
|
|
40
|
+
|
|
41
|
+
import {
|
|
42
|
+
ToolbarSplitButton,
|
|
43
|
+
ToolbarSplitButtonPrimary,
|
|
44
|
+
ToolbarSplitButtonSecondary
|
|
45
|
+
} from './toolbar';
|
|
46
|
+
|
|
47
|
+
const MEDIA_CONFIG: Record<
|
|
48
|
+
string,
|
|
49
|
+
{
|
|
50
|
+
accept: string[];
|
|
51
|
+
icon: ReactNode;
|
|
52
|
+
title: string;
|
|
53
|
+
tooltip: string;
|
|
54
|
+
}
|
|
55
|
+
> = {
|
|
56
|
+
[KEYS.audio]: {
|
|
57
|
+
accept: ['audio/*'],
|
|
58
|
+
icon: <AudioLinesIcon className="size-4" />,
|
|
59
|
+
title: 'Insert Audio',
|
|
60
|
+
tooltip: 'Audio'
|
|
61
|
+
},
|
|
62
|
+
[KEYS.file]: {
|
|
63
|
+
accept: ['*'],
|
|
64
|
+
icon: <FileUpIcon className="size-4" />,
|
|
65
|
+
title: 'Insert File',
|
|
66
|
+
tooltip: 'File'
|
|
67
|
+
},
|
|
68
|
+
[KEYS.img]: {
|
|
69
|
+
accept: ['image/*'],
|
|
70
|
+
icon: <ImageIcon className="size-4" />,
|
|
71
|
+
title: 'Insert Image',
|
|
72
|
+
tooltip: 'Image'
|
|
73
|
+
},
|
|
74
|
+
[KEYS.video]: {
|
|
75
|
+
accept: ['video/*'],
|
|
76
|
+
icon: <FilmIcon className="size-4" />,
|
|
77
|
+
title: 'Insert Video',
|
|
78
|
+
tooltip: 'Video'
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export function MediaToolbarButton({
|
|
83
|
+
nodeType,
|
|
84
|
+
...props
|
|
85
|
+
}: DropdownMenuProps & { nodeType: string }) {
|
|
86
|
+
const currentConfig = MEDIA_CONFIG[nodeType];
|
|
87
|
+
|
|
88
|
+
const editor = useEditorRef();
|
|
89
|
+
const [open, setOpen] = useState(false);
|
|
90
|
+
const [dialogOpen, setDialogOpen] = useState(false);
|
|
91
|
+
|
|
92
|
+
const { openFilePicker } = useFilePicker({
|
|
93
|
+
accept: currentConfig.accept,
|
|
94
|
+
multiple: true,
|
|
95
|
+
onFilesSelected: (data: { plainFiles?: File[] }) => {
|
|
96
|
+
if (!data.plainFiles || data.plainFiles.length === 0) return;
|
|
97
|
+
editor.getTransforms(PlaceholderPlugin).insert.media(data.plainFiles as unknown as FileList);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<>
|
|
103
|
+
<ToolbarSplitButton
|
|
104
|
+
onClick={() => {
|
|
105
|
+
openFilePicker();
|
|
106
|
+
}}
|
|
107
|
+
onKeyDown={(e) => {
|
|
108
|
+
if (e.key === 'ArrowDown') {
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
setOpen(true);
|
|
111
|
+
}
|
|
112
|
+
}}
|
|
113
|
+
pressed={open}>
|
|
114
|
+
<ToolbarSplitButtonPrimary>
|
|
115
|
+
{currentConfig.icon}
|
|
116
|
+
</ToolbarSplitButtonPrimary>
|
|
117
|
+
|
|
118
|
+
<DropdownMenu
|
|
119
|
+
open={open}
|
|
120
|
+
onOpenChange={setOpen}
|
|
121
|
+
modal={false}
|
|
122
|
+
{...props}>
|
|
123
|
+
<DropdownMenuTrigger asChild>
|
|
124
|
+
<ToolbarSplitButtonSecondary />
|
|
125
|
+
</DropdownMenuTrigger>
|
|
126
|
+
|
|
127
|
+
<DropdownMenuPortal>
|
|
128
|
+
<DropdownMenuContent
|
|
129
|
+
onClick={e => e.stopPropagation()}
|
|
130
|
+
align="start"
|
|
131
|
+
alignOffset={-32}>
|
|
132
|
+
<DropdownMenuGroup>
|
|
133
|
+
<DropdownMenuItem onSelect={() => openFilePicker()}>
|
|
134
|
+
{currentConfig.icon}
|
|
135
|
+
Upload from computer
|
|
136
|
+
</DropdownMenuItem>
|
|
137
|
+
<DropdownMenuItem onSelect={() => setDialogOpen(true)}>
|
|
138
|
+
<LinkIcon />
|
|
139
|
+
Insert via URL
|
|
140
|
+
</DropdownMenuItem>
|
|
141
|
+
</DropdownMenuGroup>
|
|
142
|
+
</DropdownMenuContent>
|
|
143
|
+
</DropdownMenuPortal>
|
|
144
|
+
</DropdownMenu>
|
|
145
|
+
</ToolbarSplitButton>
|
|
146
|
+
|
|
147
|
+
<AlertDialog
|
|
148
|
+
open={dialogOpen}
|
|
149
|
+
onOpenChange={(value) => {
|
|
150
|
+
setDialogOpen(value);
|
|
151
|
+
}}>
|
|
152
|
+
<AlertDialogContent className="gap-6">
|
|
153
|
+
<MediaUrlDialogContent
|
|
154
|
+
currentConfig={currentConfig}
|
|
155
|
+
nodeType={nodeType}
|
|
156
|
+
setOpen={setDialogOpen} />
|
|
157
|
+
</AlertDialogContent>
|
|
158
|
+
</AlertDialog>
|
|
159
|
+
</>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function MediaUrlDialogContent({
|
|
164
|
+
currentConfig,
|
|
165
|
+
nodeType,
|
|
166
|
+
setOpen
|
|
167
|
+
}: {
|
|
168
|
+
currentConfig: (typeof MEDIA_CONFIG)[string];
|
|
169
|
+
nodeType: string;
|
|
170
|
+
setOpen: (value: boolean) => void;
|
|
171
|
+
}) {
|
|
172
|
+
const editor = useEditorRef();
|
|
173
|
+
const [url, setUrl] = useState('');
|
|
174
|
+
|
|
175
|
+
const embedMedia = useCallback(() => {
|
|
176
|
+
if (!isUrl(url)) return toast.error('Invalid URL');
|
|
177
|
+
|
|
178
|
+
setOpen(false);
|
|
179
|
+
editor.tf.insertNodes({
|
|
180
|
+
children: [{ text: '' }],
|
|
181
|
+
name: nodeType === KEYS.file ? url.split('/').pop() : undefined,
|
|
182
|
+
type: nodeType,
|
|
183
|
+
url
|
|
184
|
+
});
|
|
185
|
+
}, [
|
|
186
|
+
url,
|
|
187
|
+
editor,
|
|
188
|
+
nodeType,
|
|
189
|
+
setOpen
|
|
190
|
+
]);
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<>
|
|
194
|
+
<AlertDialogHeader>
|
|
195
|
+
<AlertDialogTitle>{currentConfig.title}</AlertDialogTitle>
|
|
196
|
+
</AlertDialogHeader>
|
|
197
|
+
|
|
198
|
+
<AlertDialogDescription className="group relative w-full">
|
|
199
|
+
<label
|
|
200
|
+
className="-translate-y-1/2 absolute top-1/2 block cursor-text px-1 text-muted-foreground/70 text-sm transition-all group-focus-within:pointer-events-none group-focus-within:top-0 group-focus-within:cursor-default group-focus-within:font-medium group-focus-within:text-foreground group-focus-within:text-xs has-[+input:not(:placeholder-shown)]:pointer-events-none has-[+input:not(:placeholder-shown)]:top-0 has-[+input:not(:placeholder-shown)]:cursor-default has-[+input:not(:placeholder-shown)]:font-medium has-[+input:not(:placeholder-shown)]:text-foreground has-[+input:not(:placeholder-shown)]:text-xs"
|
|
201
|
+
htmlFor="url">
|
|
202
|
+
<span className="inline-flex bg-background px-2">URL</span>
|
|
203
|
+
</label>
|
|
204
|
+
<Input
|
|
205
|
+
id="url"
|
|
206
|
+
className="w-full"
|
|
207
|
+
value={url}
|
|
208
|
+
onChange={e => setUrl(e.target.value)}
|
|
209
|
+
onKeyDown={(e) => {
|
|
210
|
+
if (e.key === 'Enter') embedMedia();
|
|
211
|
+
}}
|
|
212
|
+
placeholder=""
|
|
213
|
+
type="url"
|
|
214
|
+
autoFocus />
|
|
215
|
+
</AlertDialogDescription>
|
|
216
|
+
|
|
217
|
+
<AlertDialogFooter>
|
|
218
|
+
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
219
|
+
<AlertDialogAction
|
|
220
|
+
onClick={(e) => {
|
|
221
|
+
e.preventDefault();
|
|
222
|
+
embedMedia();
|
|
223
|
+
}}>
|
|
224
|
+
Accept
|
|
225
|
+
</AlertDialogAction>
|
|
226
|
+
</AlertDialogFooter>
|
|
227
|
+
</>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type ComponentProps, type Dispatch, type SetStateAction } from 'react';
|
|
4
|
+
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
|
|
7
|
+
import { type TMediaElement, type TTextAlignProps, KEYS } from 'platejs';
|
|
8
|
+
|
|
9
|
+
import { showCaption } from '@platejs/caption/react';
|
|
10
|
+
import {
|
|
11
|
+
openImagePreview,
|
|
12
|
+
useMediaController,
|
|
13
|
+
useMediaControllerDropDownMenu,
|
|
14
|
+
useMediaControllerState
|
|
15
|
+
} from '@platejs/media/react';
|
|
16
|
+
import { BlockMenuPlugin } from '@platejs/selection/react';
|
|
17
|
+
import {
|
|
18
|
+
AlignCenter,
|
|
19
|
+
AlignLeft,
|
|
20
|
+
AlignRight,
|
|
21
|
+
CaptionsIcon,
|
|
22
|
+
CircleArrowDownIcon,
|
|
23
|
+
MoreHorizontalIcon,
|
|
24
|
+
MoveUpRightIcon,
|
|
25
|
+
ZoomInIcon
|
|
26
|
+
} from 'lucide-react';
|
|
27
|
+
import { useEditorRef, useElement } from 'platejs/react';
|
|
28
|
+
|
|
29
|
+
import { toast } from 'sonner';
|
|
30
|
+
|
|
31
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
32
|
+
|
|
33
|
+
import {
|
|
34
|
+
DropdownMenu,
|
|
35
|
+
DropdownMenuContent,
|
|
36
|
+
type DropdownMenuProps,
|
|
37
|
+
DropdownMenuRadioGroup,
|
|
38
|
+
DropdownMenuRadioItem,
|
|
39
|
+
DropdownMenuTrigger,
|
|
40
|
+
useOpenState
|
|
41
|
+
} from './dropdown-menu';
|
|
42
|
+
|
|
43
|
+
import { Toolbar, ToolbarButton, toolbarButtonVariants } from './toolbar';
|
|
44
|
+
|
|
45
|
+
import { downloadFile } from '../lib/download-file';
|
|
46
|
+
|
|
47
|
+
export function MediaToolbar({
|
|
48
|
+
className: _className,
|
|
49
|
+
...props
|
|
50
|
+
}: ComponentProps<typeof Toolbar>) {
|
|
51
|
+
return (
|
|
52
|
+
<Toolbar
|
|
53
|
+
className={cn(
|
|
54
|
+
'group-data-[readonly=true]/editor:hidden',
|
|
55
|
+
'top-1 right-1 opacity-0 group-hover/media:opacity-100',
|
|
56
|
+
'group-has-data-[resizing=true]/media:opacity-0 group-has-data-[state=open]/media:opacity-100 group-data-[state=open]/context-menu:opacity-0'
|
|
57
|
+
)}
|
|
58
|
+
{...props}>
|
|
59
|
+
<MediaToolbarButtons />
|
|
60
|
+
</Toolbar>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const alignItems = [
|
|
65
|
+
{
|
|
66
|
+
icon: AlignLeft,
|
|
67
|
+
value: 'left'
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
icon: AlignCenter,
|
|
71
|
+
value: 'center'
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
icon: AlignRight,
|
|
75
|
+
value: 'right'
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
function MediaToolbarButtons() {
|
|
80
|
+
const editor = useEditorRef();
|
|
81
|
+
const element = useElement<TMediaElement>();
|
|
82
|
+
const state = useMediaControllerState();
|
|
83
|
+
const { MediaControllerDropDownMenuProps: mediaToolbarDropDownMenuProps }
|
|
84
|
+
= useMediaController(state);
|
|
85
|
+
|
|
86
|
+
const handleDownload = () => {
|
|
87
|
+
toast.promise(downloadFile(element.url, element.id || 'file'), {
|
|
88
|
+
error: 'Download failed. Please try again.',
|
|
89
|
+
loading: 'Downloading...'
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<>
|
|
95
|
+
<MediaAlignButton {...mediaToolbarDropDownMenuProps} />
|
|
96
|
+
<ToolbarButton
|
|
97
|
+
onClick={() => showCaption(editor, element)}
|
|
98
|
+
size="none"
|
|
99
|
+
tooltip="Caption"
|
|
100
|
+
variant="media">
|
|
101
|
+
<CaptionsIcon />
|
|
102
|
+
</ToolbarButton>
|
|
103
|
+
{element.type === KEYS.img && (
|
|
104
|
+
<ToolbarButton
|
|
105
|
+
onClick={() => {
|
|
106
|
+
openImagePreview(editor, element);
|
|
107
|
+
}}
|
|
108
|
+
size="none"
|
|
109
|
+
tooltip="Expand"
|
|
110
|
+
variant="media">
|
|
111
|
+
<ZoomInIcon />
|
|
112
|
+
</ToolbarButton>
|
|
113
|
+
)}
|
|
114
|
+
|
|
115
|
+
{element.type === KEYS.img && (
|
|
116
|
+
<ToolbarButton
|
|
117
|
+
onClick={handleDownload}
|
|
118
|
+
size="none"
|
|
119
|
+
tooltip="Download"
|
|
120
|
+
variant="media">
|
|
121
|
+
<CircleArrowDownIcon />
|
|
122
|
+
</ToolbarButton>
|
|
123
|
+
)}
|
|
124
|
+
|
|
125
|
+
{element.type !== KEYS.img && (
|
|
126
|
+
<ToolbarButton
|
|
127
|
+
onClick={() => {
|
|
128
|
+
window.open(element.url, '_blank');
|
|
129
|
+
}}
|
|
130
|
+
size="none"
|
|
131
|
+
tooltip="Original"
|
|
132
|
+
variant="media">
|
|
133
|
+
<MoveUpRightIcon />
|
|
134
|
+
</ToolbarButton>
|
|
135
|
+
)}
|
|
136
|
+
|
|
137
|
+
<ToolbarButton
|
|
138
|
+
onClick={(e) => {
|
|
139
|
+
editor
|
|
140
|
+
.getApi(BlockMenuPlugin)
|
|
141
|
+
.blockMenu.showContextMenu(element.id as string, {
|
|
142
|
+
x: e.clientX,
|
|
143
|
+
y: e.clientY
|
|
144
|
+
});
|
|
145
|
+
}}
|
|
146
|
+
size="none"
|
|
147
|
+
tooltip="More actions"
|
|
148
|
+
variant="media">
|
|
149
|
+
<MoreHorizontalIcon />
|
|
150
|
+
</ToolbarButton>
|
|
151
|
+
</>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function MediaAlignButton({
|
|
156
|
+
children: _children,
|
|
157
|
+
...props
|
|
158
|
+
}: {
|
|
159
|
+
setAlignOpen: Dispatch<SetStateAction<boolean>>;
|
|
160
|
+
} & DropdownMenuProps) {
|
|
161
|
+
const editor = useEditorRef();
|
|
162
|
+
const element = useElement<TMediaElement & TTextAlignProps>();
|
|
163
|
+
const openState = useOpenState();
|
|
164
|
+
|
|
165
|
+
const value = element.align ?? 'left';
|
|
166
|
+
|
|
167
|
+
const IconValue
|
|
168
|
+
= alignItems.find(item => item.value === value)?.icon ?? AlignLeft;
|
|
169
|
+
|
|
170
|
+
useMediaControllerDropDownMenu({
|
|
171
|
+
openState,
|
|
172
|
+
setAlignOpen: props.setAlignOpen
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<DropdownMenu modal={false} {...openState} {...props}>
|
|
177
|
+
<DropdownMenuTrigger asChild>
|
|
178
|
+
<ToolbarButton
|
|
179
|
+
data-state={openState.open ? 'open' : 'closed'}
|
|
180
|
+
size="none"
|
|
181
|
+
tooltip="Align"
|
|
182
|
+
variant="media">
|
|
183
|
+
<IconValue className="size-4" />
|
|
184
|
+
</ToolbarButton>
|
|
185
|
+
</DropdownMenuTrigger>
|
|
186
|
+
|
|
187
|
+
<DropdownMenuContent
|
|
188
|
+
align="start"
|
|
189
|
+
className="min-w-0 rounded-md border-none bg-black/60 p-0 shadow-none"
|
|
190
|
+
portal={false}>
|
|
191
|
+
<DropdownMenuRadioGroup
|
|
192
|
+
className="flex hover:bg-transparent"
|
|
193
|
+
onValueChange={(value) => {
|
|
194
|
+
editor.tf.setNodes({ align: value as any }, { at: element });
|
|
195
|
+
}}
|
|
196
|
+
value={value}>
|
|
197
|
+
{alignItems.map(({ icon: Icon, value: itemValue }) => (
|
|
198
|
+
<DropdownMenuRadioItem
|
|
199
|
+
className={cn(
|
|
200
|
+
toolbarButtonVariants({
|
|
201
|
+
size: 'none',
|
|
202
|
+
variant: 'media'
|
|
203
|
+
}),
|
|
204
|
+
'size-[26px] opacity-60 hover:opacity-100 data-[state=checked]:bg-black/5 data-[state=checked]:opacity-100'
|
|
205
|
+
)}
|
|
206
|
+
hideIcon
|
|
207
|
+
key={itemValue}
|
|
208
|
+
value={itemValue}>
|
|
209
|
+
<Icon className="size-4" />
|
|
210
|
+
</DropdownMenuRadioItem>
|
|
211
|
+
))}
|
|
212
|
+
</DropdownMenuRadioGroup>
|
|
213
|
+
</DropdownMenuContent>
|
|
214
|
+
</DropdownMenu>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
|
|
5
|
+
import { PlaceholderPlugin, UploadErrorCode } from '@platejs/media/react';
|
|
6
|
+
import { usePluginOption } from 'platejs/react';
|
|
7
|
+
import { toast } from 'sonner';
|
|
8
|
+
|
|
9
|
+
export function MediaUploadToast() {
|
|
10
|
+
useUploadErrorToast();
|
|
11
|
+
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const useUploadErrorToast = () => {
|
|
16
|
+
const uploadError = usePluginOption(PlaceholderPlugin, 'error');
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!uploadError) return;
|
|
20
|
+
|
|
21
|
+
const { code, data } = uploadError;
|
|
22
|
+
|
|
23
|
+
switch (code) {
|
|
24
|
+
case UploadErrorCode.INVALID_FILE_SIZE: {
|
|
25
|
+
toast.error(
|
|
26
|
+
`The size of files ${data.files
|
|
27
|
+
.map(f => f.name)
|
|
28
|
+
.join(', ')} is invalid`
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
case UploadErrorCode.INVALID_FILE_TYPE: {
|
|
35
|
+
toast.error(
|
|
36
|
+
`The type of files ${data.files
|
|
37
|
+
.map(f => f.name)
|
|
38
|
+
.join(', ')} is invalid`
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
case UploadErrorCode.TOO_LARGE: {
|
|
45
|
+
toast.error(
|
|
46
|
+
`The size of files ${data.files
|
|
47
|
+
.map(f => f.name)
|
|
48
|
+
.join(', ')} is too large than ${data.maxFileSize}`
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
case UploadErrorCode.TOO_LESS_FILES: {
|
|
55
|
+
toast.error(
|
|
56
|
+
`The mini um number of files is ${data.minFileCount} for ${data.fileType}`
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
case UploadErrorCode.TOO_MANY_FILES: {
|
|
63
|
+
toast.error(
|
|
64
|
+
`The maximum number of files is ${data.maxFileCount} ${
|
|
65
|
+
data.fileType ? `for ${data.fileType}` : ''
|
|
66
|
+
}`
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, [uploadError]);
|
|
73
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
NodeApi,
|
|
4
|
+
type TCaptionElement,
|
|
5
|
+
type TResizableProps,
|
|
6
|
+
type TVideoElement
|
|
7
|
+
} from 'platejs';
|
|
8
|
+
import { SlateElement, type SlateElementProps } from 'platejs/static';
|
|
9
|
+
|
|
10
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
11
|
+
|
|
12
|
+
export function MediaVideoElementStatic(
|
|
13
|
+
props: SlateElementProps<TVideoElement & TCaptionElement & TResizableProps>
|
|
14
|
+
) {
|
|
15
|
+
const {
|
|
16
|
+
align = 'center', caption, url, width
|
|
17
|
+
} = props.element;
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<SlateElement className="py-2.5" {...props}>
|
|
21
|
+
<div style={{ textAlign: align }}>
|
|
22
|
+
<figure
|
|
23
|
+
className="group relative m-0 inline-block cursor-default"
|
|
24
|
+
style={{ width }}>
|
|
25
|
+
<video
|
|
26
|
+
className={cn('w-full max-w-full object-cover px-0', 'rounded-sm')}
|
|
27
|
+
controls
|
|
28
|
+
src={url} />
|
|
29
|
+
{caption && <figcaption>{NodeApi.string(caption[0])}</figcaption>}
|
|
30
|
+
</figure>
|
|
31
|
+
</div>
|
|
32
|
+
{props.children}
|
|
33
|
+
</SlateElement>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useDraggable } from '@platejs/dnd';
|
|
4
|
+
import { parseTwitterUrl, parseVideoUrl } from '@platejs/media';
|
|
5
|
+
import { useMediaState } from '@platejs/media/react';
|
|
6
|
+
import { ResizableProvider, useResizableValue } from '@platejs/resizable';
|
|
7
|
+
import {
|
|
8
|
+
PlateElement,
|
|
9
|
+
type PlateElementProps,
|
|
10
|
+
useEditorMounted,
|
|
11
|
+
withHOC
|
|
12
|
+
} from 'platejs/react';
|
|
13
|
+
import LiteYouTubeEmbed from 'react-lite-youtube-embed';
|
|
14
|
+
import ReactPlayer from 'react-player';
|
|
15
|
+
|
|
16
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
17
|
+
|
|
18
|
+
import { Caption, CaptionTextarea } from './caption';
|
|
19
|
+
import { MediaToolbar } from './media-toolbar';
|
|
20
|
+
import {
|
|
21
|
+
mediaResizeHandleVariants,
|
|
22
|
+
Resizable,
|
|
23
|
+
ResizeHandle
|
|
24
|
+
} from './resize-handle';
|
|
25
|
+
|
|
26
|
+
export const MediaVideoElement = withHOC(
|
|
27
|
+
ResizableProvider,
|
|
28
|
+
(props: PlateElementProps) => {
|
|
29
|
+
const {
|
|
30
|
+
align = 'center',
|
|
31
|
+
embed,
|
|
32
|
+
isUpload,
|
|
33
|
+
isYoutube,
|
|
34
|
+
readOnly,
|
|
35
|
+
unsafeUrl
|
|
36
|
+
} = useMediaState({
|
|
37
|
+
urlParsers: [parseTwitterUrl, parseVideoUrl]
|
|
38
|
+
});
|
|
39
|
+
const width = useResizableValue('width');
|
|
40
|
+
|
|
41
|
+
const isEditorMounted = useEditorMounted();
|
|
42
|
+
|
|
43
|
+
const isTweet = true;
|
|
44
|
+
|
|
45
|
+
const { isDragging, handleRef } = useDraggable({
|
|
46
|
+
element: props.element
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<PlateElement className="py-2.5" {...props}>
|
|
51
|
+
<figure className="relative m-0 cursor-default" contentEditable={false}>
|
|
52
|
+
<Resizable
|
|
53
|
+
align={align}
|
|
54
|
+
className={cn(isDragging && 'opacity-50')}
|
|
55
|
+
options={{
|
|
56
|
+
align,
|
|
57
|
+
maxWidth: isTweet ? 550 : '100%',
|
|
58
|
+
minWidth: isTweet ? 300 : 100,
|
|
59
|
+
readOnly
|
|
60
|
+
}}>
|
|
61
|
+
<div className="group/media">
|
|
62
|
+
<ResizeHandle
|
|
63
|
+
className={mediaResizeHandleVariants({ direction: 'left' })}
|
|
64
|
+
options={{ direction: 'left' }} />
|
|
65
|
+
|
|
66
|
+
<ResizeHandle
|
|
67
|
+
className={mediaResizeHandleVariants({ direction: 'right' })}
|
|
68
|
+
options={{ direction: 'right' }} />
|
|
69
|
+
|
|
70
|
+
{!isUpload && isYoutube && (
|
|
71
|
+
<div ref={handleRef}>
|
|
72
|
+
<LiteYouTubeEmbed
|
|
73
|
+
id={embed!.id!}
|
|
74
|
+
title="youtube"
|
|
75
|
+
wrapperClass={cn(
|
|
76
|
+
'aspect-video rounded-sm',
|
|
77
|
+
'relative block cursor-pointer bg-black bg-center bg-cover [contain:content]',
|
|
78
|
+
'[&.lyt-activated]:before:absolute [&.lyt-activated]:before:top-0 [&.lyt-activated]:before:h-[60px] [&.lyt-activated]:before:w-full [&.lyt-activated]:before:bg-top [&.lyt-activated]:before:bg-repeat-x [&.lyt-activated]:before:pb-[50px] [&.lyt-activated]:before:[transition:all_0.2s_cubic-bezier(0,_0,_0.2,_1)]',
|
|
79
|
+
'[&.lyt-activated]:before:bg-[url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAADGCAYAAAAT+OqFAAAAdklEQVQoz42QQQ7AIAgEF/T/D+kbq/RWAlnQyyazA4aoAB4FsBSA/bFjuF1EOL7VbrIrBuusmrt4ZZORfb6ehbWdnRHEIiITaEUKa5EJqUakRSaEYBJSCY2dEstQY7AuxahwXFrvZmWl2rh4JZ07z9dLtesfNj5q0FU3A5ObbwAAAABJRU5ErkJggg==)]',
|
|
80
|
+
'after:block after:pb-[var(--aspect-ratio)] after:content-[""]',
|
|
81
|
+
'[&_>_iframe]:absolute [&_>_iframe]:top-0 [&_>_iframe]:left-0 [&_>_iframe]:size-full',
|
|
82
|
+
'[&_>_.lty-playbtn]:z-1 [&_>_.lty-playbtn]:h-[46px] [&_>_.lty-playbtn]:w-[70px] [&_>_.lty-playbtn]:rounded-[14%] [&_>_.lty-playbtn]:bg-[#212121] [&_>_.lty-playbtn]:opacity-80 [&_>_.lty-playbtn]:[transition:all_0.2s_cubic-bezier(0,_0,_0.2,_1)]',
|
|
83
|
+
'[&:hover_>_.lty-playbtn]:bg-[red] [&:hover_>_.lty-playbtn]:opacity-100',
|
|
84
|
+
'[&_>_.lty-playbtn]:before:border-[transparent_transparent_transparent_#fff] [&_>_.lty-playbtn]:before:border-y-[11px] [&_>_.lty-playbtn]:before:border-r-0 [&_>_.lty-playbtn]:before:border-l-[19px] [&_>_.lty-playbtn]:before:content-[""]',
|
|
85
|
+
'[&_>_.lty-playbtn]:absolute [&_>_.lty-playbtn]:top-1/2 [&_>_.lty-playbtn]:left-1/2 [&_>_.lty-playbtn]:[transform:translate3d(-50%,-50%,0)]',
|
|
86
|
+
'[&_>_.lty-playbtn]:before:absolute [&_>_.lty-playbtn]:before:top-1/2 [&_>_.lty-playbtn]:before:left-1/2 [&_>_.lty-playbtn]:before:[transform:translate3d(-50%,-50%,0)]',
|
|
87
|
+
'[&.lyt-activated]:cursor-[unset]',
|
|
88
|
+
'[&.lyt-activated]:before:pointer-events-none [&.lyt-activated]:before:opacity-0',
|
|
89
|
+
'[&.lyt-activated_>_.lty-playbtn]:pointer-events-none [&.lyt-activated_>_.lty-playbtn]:opacity-0!'
|
|
90
|
+
)} />
|
|
91
|
+
</div>
|
|
92
|
+
)}
|
|
93
|
+
|
|
94
|
+
{/* TODO: Lazy load */}
|
|
95
|
+
{isUpload && isEditorMounted && (
|
|
96
|
+
<div ref={handleRef}>
|
|
97
|
+
<ReactPlayer
|
|
98
|
+
controls
|
|
99
|
+
height="100%"
|
|
100
|
+
src={unsafeUrl}
|
|
101
|
+
width="100%" />
|
|
102
|
+
</div>
|
|
103
|
+
)}
|
|
104
|
+
|
|
105
|
+
<MediaToolbar />
|
|
106
|
+
</div>
|
|
107
|
+
</Resizable>
|
|
108
|
+
|
|
109
|
+
<Caption align={align} style={{ width }}>
|
|
110
|
+
<CaptionTextarea
|
|
111
|
+
placeholder="Write a caption..."
|
|
112
|
+
readOnly={readOnly} />
|
|
113
|
+
</Caption>
|
|
114
|
+
</figure>
|
|
115
|
+
{props.children}
|
|
116
|
+
</PlateElement>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
);
|