@docyrus/ui-pro-ai-assistant 0.0.2 → 0.0.5
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/components/assistant-animations.d.ts +3 -3
- package/dist/docy-assistant.d.ts +1 -1
- package/dist/index.js +74 -47
- package/dist/index.js.map +1 -1
- package/dist/styles.css +5137 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/views/assistant-view.d.ts +2 -2
- package/package.json +38 -36
- 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,52 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useMediaState } from '@platejs/media/react';
|
|
4
|
-
import { ResizableProvider } from '@platejs/resizable';
|
|
5
|
-
import { FileUpIcon } from 'lucide-react';
|
|
6
|
-
import {
|
|
7
|
-
PlateElement,
|
|
8
|
-
type PlateElementProps,
|
|
9
|
-
useReadOnly,
|
|
10
|
-
withHOC
|
|
11
|
-
} from 'platejs/react';
|
|
12
|
-
|
|
13
|
-
import { BlockActionButton } from './block-context-menu';
|
|
14
|
-
import { Caption, CaptionTextarea } from './caption';
|
|
15
|
-
|
|
16
|
-
export const MediaFileElement = withHOC(
|
|
17
|
-
ResizableProvider,
|
|
18
|
-
(props: PlateElementProps) => {
|
|
19
|
-
const readOnly = useReadOnly();
|
|
20
|
-
const { name, unsafeUrl } = useMediaState();
|
|
21
|
-
|
|
22
|
-
const onDownload = () => {
|
|
23
|
-
window.open(unsafeUrl);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<PlateElement className="my-px rounded-sm" {...props}>
|
|
28
|
-
<div
|
|
29
|
-
className="group relative m-0 flex cursor-pointer items-center rounded px-0.5 py-[3px] transition-bg-ease hover:bg-muted"
|
|
30
|
-
contentEditable={false}
|
|
31
|
-
onClick={onDownload}
|
|
32
|
-
role="button">
|
|
33
|
-
<div className="flex items-center gap-1 p-1">
|
|
34
|
-
<FileUpIcon className="size-5" />
|
|
35
|
-
<div>{name}</div>
|
|
36
|
-
</div>
|
|
37
|
-
|
|
38
|
-
<Caption align="left">
|
|
39
|
-
<CaptionTextarea
|
|
40
|
-
className="text-left"
|
|
41
|
-
placeholder="Write a caption..."
|
|
42
|
-
readOnly={readOnly} />
|
|
43
|
-
</Caption>
|
|
44
|
-
|
|
45
|
-
<BlockActionButton className="-translate-y-1/2 top-1/2" />
|
|
46
|
-
</div>
|
|
47
|
-
|
|
48
|
-
{props.children}
|
|
49
|
-
</PlateElement>
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
);
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
type TCaptionElement, type TImageElement, type TResizableProps, NodeApi
|
|
4
|
-
} from 'platejs';
|
|
5
|
-
|
|
6
|
-
import { SlateElement, type SlateElementProps } from 'platejs/static';
|
|
7
|
-
|
|
8
|
-
export function ImageElementStatic(
|
|
9
|
-
props: SlateElementProps<TImageElement & TCaptionElement & TResizableProps>
|
|
10
|
-
) {
|
|
11
|
-
const {
|
|
12
|
-
align = 'center', caption, url, width
|
|
13
|
-
} = props.element;
|
|
14
|
-
|
|
15
|
-
return (
|
|
16
|
-
<SlateElement className="py-2.5" {...props}>
|
|
17
|
-
<figure className="group relative m-0 inline-block">
|
|
18
|
-
<div
|
|
19
|
-
className="relative min-w-[92px] max-w-full"
|
|
20
|
-
style={{ textAlign: align }}>
|
|
21
|
-
<div className="inline-block" style={{ width }}>
|
|
22
|
-
<img
|
|
23
|
-
alt={(props.attributes as any).alt}
|
|
24
|
-
className="w-full max-w-full cursor-default rounded-sm object-cover px-0"
|
|
25
|
-
src={url} />
|
|
26
|
-
{caption && (
|
|
27
|
-
<figcaption className="mx-auto mt-2 h-[24px] max-w-full">
|
|
28
|
-
{NodeApi.string(caption[0])}
|
|
29
|
-
</figcaption>
|
|
30
|
-
)}
|
|
31
|
-
</div>
|
|
32
|
-
</div>
|
|
33
|
-
</figure>
|
|
34
|
-
{props.children}
|
|
35
|
-
</SlateElement>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
4
|
-
|
|
5
|
-
import { type TImageElement } from 'platejs';
|
|
6
|
-
|
|
7
|
-
import { useDraggable } from '@platejs/dnd';
|
|
8
|
-
import {
|
|
9
|
-
PlaceholderPlugin,
|
|
10
|
-
useImage,
|
|
11
|
-
useMediaState
|
|
12
|
-
} from '@platejs/media/react';
|
|
13
|
-
import { ResizableProvider, useResizableValue } from '@platejs/resizable';
|
|
14
|
-
import {
|
|
15
|
-
PlateElement,
|
|
16
|
-
type PlateElementProps,
|
|
17
|
-
useEditorPlugin,
|
|
18
|
-
withHOC
|
|
19
|
-
} from 'platejs/react';
|
|
20
|
-
|
|
21
|
-
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
22
|
-
|
|
23
|
-
import { blockSelectionVariants } from './block-selection';
|
|
24
|
-
import { Caption, CaptionTextarea } from './caption';
|
|
25
|
-
import { MediaToolbar } from './media-toolbar';
|
|
26
|
-
import {
|
|
27
|
-
mediaResizeHandleVariants,
|
|
28
|
-
Resizable,
|
|
29
|
-
ResizeHandle
|
|
30
|
-
} from './resize-handle';
|
|
31
|
-
|
|
32
|
-
export const ImageElement = withHOC(
|
|
33
|
-
ResizableProvider,
|
|
34
|
-
(props: PlateElementProps<TImageElement>) => {
|
|
35
|
-
const { api, editor } = useEditorPlugin(PlaceholderPlugin);
|
|
36
|
-
|
|
37
|
-
const print = editor.meta.mode === 'print';
|
|
38
|
-
|
|
39
|
-
const { element } = props;
|
|
40
|
-
|
|
41
|
-
const currentUploadingFile = useMemo(() => {
|
|
42
|
-
if (!element.placeholderId) return;
|
|
43
|
-
|
|
44
|
-
return api.placeholder.getUploadingFile(element.placeholderId);
|
|
45
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
46
|
-
}, [element.placeholderId]);
|
|
47
|
-
|
|
48
|
-
const {
|
|
49
|
-
align = 'center', focused, readOnly, selected
|
|
50
|
-
} = useMediaState();
|
|
51
|
-
|
|
52
|
-
const [loading, setLoading] = useState(true);
|
|
53
|
-
|
|
54
|
-
const width = useResizableValue('width');
|
|
55
|
-
|
|
56
|
-
const { props: imageProps } = useImage();
|
|
57
|
-
|
|
58
|
-
const height = useMemo<number | null>(() => {
|
|
59
|
-
if (print) return null;
|
|
60
|
-
if (!element.initialHeight || !element.initialWidth) {
|
|
61
|
-
// Embed image we don't have height and width using 200 by default
|
|
62
|
-
return loading ? 200 : null;
|
|
63
|
-
}
|
|
64
|
-
if (typeof width !== 'number' || width === 0)
|
|
65
|
-
return Number(element.initialHeight.toFixed(2));
|
|
66
|
-
|
|
67
|
-
const aspectRatio = Number(
|
|
68
|
-
(element.initialWidth! / element.initialHeight!).toFixed(2)
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
return Number((width / aspectRatio).toFixed(2));
|
|
72
|
-
}, [
|
|
73
|
-
element.initialHeight,
|
|
74
|
-
element.initialWidth,
|
|
75
|
-
loading,
|
|
76
|
-
print,
|
|
77
|
-
width
|
|
78
|
-
]);
|
|
79
|
-
|
|
80
|
-
const { isDragging, handleRef } = useDraggable({
|
|
81
|
-
element: props.element
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
<PlateElement className="my-1" {...props}>
|
|
86
|
-
<figure className="relative m-0" contentEditable={false}>
|
|
87
|
-
<Resizable
|
|
88
|
-
align={align}
|
|
89
|
-
options={{
|
|
90
|
-
align,
|
|
91
|
-
readOnly
|
|
92
|
-
}}>
|
|
93
|
-
<div className="group/media">
|
|
94
|
-
<ResizeHandle
|
|
95
|
-
className={mediaResizeHandleVariants({ direction: 'left' })}
|
|
96
|
-
options={{ direction: 'left' }} />
|
|
97
|
-
<ResizeHandle
|
|
98
|
-
className={mediaResizeHandleVariants({ direction: 'right' })}
|
|
99
|
-
options={{ direction: 'right' }} />
|
|
100
|
-
|
|
101
|
-
<div
|
|
102
|
-
className={cn(
|
|
103
|
-
'relative block w-full max-w-full cursor-pointer object-cover px-0',
|
|
104
|
-
blockSelectionVariants({ active: focused && selected }),
|
|
105
|
-
'group-has-data-[resizing=true]/media:before:opacity-0'
|
|
106
|
-
)}
|
|
107
|
-
style={{
|
|
108
|
-
height: height ? `${height}px` : 'auto'
|
|
109
|
-
}}>
|
|
110
|
-
{print ? (
|
|
111
|
-
<img
|
|
112
|
-
alt=""
|
|
113
|
-
className={cn('h-full rounded-xs')}
|
|
114
|
-
height="auto"
|
|
115
|
-
width="100%"
|
|
116
|
-
{...imageProps} />
|
|
117
|
-
) : (
|
|
118
|
-
<img
|
|
119
|
-
className={cn(
|
|
120
|
-
'h-full w-full rounded-xs opacity-100',
|
|
121
|
-
loading && 'opacity-0',
|
|
122
|
-
isDragging && 'opacity-50'
|
|
123
|
-
)}
|
|
124
|
-
height="auto"
|
|
125
|
-
onLoad={() => {
|
|
126
|
-
setLoading(false);
|
|
127
|
-
if (currentUploadingFile) {
|
|
128
|
-
api.placeholder.removeUploadingFile(
|
|
129
|
-
props.element.fromPlaceholderId as string
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
}}
|
|
133
|
-
width="100%"
|
|
134
|
-
ref={handleRef as any}
|
|
135
|
-
{...imageProps} />
|
|
136
|
-
)}
|
|
137
|
-
|
|
138
|
-
{loading && <ImagePlaceholder file={currentUploadingFile} />}
|
|
139
|
-
</div>
|
|
140
|
-
|
|
141
|
-
<MediaToolbar />
|
|
142
|
-
</div>
|
|
143
|
-
</Resizable>
|
|
144
|
-
|
|
145
|
-
<Caption align={align} style={{ width }}>
|
|
146
|
-
<CaptionTextarea
|
|
147
|
-
onFocus={(e) => {
|
|
148
|
-
e.preventDefault();
|
|
149
|
-
}}
|
|
150
|
-
placeholder="Write a caption..."
|
|
151
|
-
readOnly={readOnly} />
|
|
152
|
-
</Caption>
|
|
153
|
-
</figure>
|
|
154
|
-
|
|
155
|
-
{props.children}
|
|
156
|
-
</PlateElement>
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
const ImagePlaceholder = ({ file }: { file?: File }) => {
|
|
162
|
-
const objectUrl = useMemo(
|
|
163
|
-
() => (file ? URL.createObjectURL(file) : null),
|
|
164
|
-
[file]
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
useEffect(() => {
|
|
168
|
-
if (!objectUrl) return;
|
|
169
|
-
|
|
170
|
-
return () => URL.revokeObjectURL(objectUrl);
|
|
171
|
-
}, [objectUrl]);
|
|
172
|
-
|
|
173
|
-
return (
|
|
174
|
-
<div className="absolute inset-0 overflow-hidden bg-[rgb(247,246,245)] before:absolute before:inset-0 before:z-10 before:animate-shimmer before:bg-linear-to-r before:from-transparent before:via-gray-200/50 before:to-transparent">
|
|
175
|
-
{file && objectUrl && (
|
|
176
|
-
<img
|
|
177
|
-
alt={file.name}
|
|
178
|
-
className="h-auto w-full rounded-xs object-cover"
|
|
179
|
-
src={objectUrl} />
|
|
180
|
-
)}
|
|
181
|
-
</div>
|
|
182
|
-
);
|
|
183
|
-
};
|
|
@@ -1,441 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
useCallback, useEffect, useRef, useState, type ChangeEvent, type ReactNode, type RefObject
|
|
5
|
-
} from 'react';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
PlaceholderPlugin,
|
|
9
|
-
PlaceholderProvider,
|
|
10
|
-
usePlaceholderElementState,
|
|
11
|
-
usePlaceholderPopoverState
|
|
12
|
-
} from '@platejs/media/react';
|
|
13
|
-
import {
|
|
14
|
-
AudioLinesIcon, FileUpIcon, FilmIcon, ImageIcon
|
|
15
|
-
} from 'lucide-react';
|
|
16
|
-
import { KEYS, nanoid } from 'platejs';
|
|
17
|
-
import {
|
|
18
|
-
PlateElement,
|
|
19
|
-
type PlateElementProps,
|
|
20
|
-
useEditorPlugin,
|
|
21
|
-
withHOC
|
|
22
|
-
} from 'platejs/react';
|
|
23
|
-
|
|
24
|
-
import { setMediaNode } from '@platejs/media';
|
|
25
|
-
|
|
26
|
-
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
27
|
-
|
|
28
|
-
import { BlockActionButton } from './block-context-menu';
|
|
29
|
-
import { Button } from './button';
|
|
30
|
-
import { Input } from './input';
|
|
31
|
-
import { Popover, PopoverContent, PopoverTrigger } from './popover';
|
|
32
|
-
import { Spinner } from './spinner';
|
|
33
|
-
import {
|
|
34
|
-
Tabs, TabsContent, TabsList, TabsTrigger
|
|
35
|
-
} from './tabs';
|
|
36
|
-
|
|
37
|
-
import { useUploadFile } from '../hooks/use-upload-file';
|
|
38
|
-
|
|
39
|
-
const CONTENT: Record<
|
|
40
|
-
string,
|
|
41
|
-
{
|
|
42
|
-
content: ReactNode;
|
|
43
|
-
icon: ReactNode;
|
|
44
|
-
}
|
|
45
|
-
> = {
|
|
46
|
-
[KEYS.audio]: {
|
|
47
|
-
content: 'Add an audio file',
|
|
48
|
-
icon: <AudioLinesIcon />
|
|
49
|
-
},
|
|
50
|
-
[KEYS.file]: {
|
|
51
|
-
content: 'Add a file',
|
|
52
|
-
icon: <FileUpIcon />
|
|
53
|
-
},
|
|
54
|
-
[KEYS.img]: {
|
|
55
|
-
content: 'Add an image',
|
|
56
|
-
icon: <ImageIcon />
|
|
57
|
-
},
|
|
58
|
-
[KEYS.video]: {
|
|
59
|
-
content: 'Add a video',
|
|
60
|
-
icon: <FilmIcon />
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const PlaceholderElement = withHOC(
|
|
65
|
-
PlaceholderProvider,
|
|
66
|
-
(props: PlateElementProps) => {
|
|
67
|
-
const {
|
|
68
|
-
mediaType, progresses, progressing, setSize, updatedFiles
|
|
69
|
-
}
|
|
70
|
-
= usePlaceholderElementState();
|
|
71
|
-
|
|
72
|
-
const currentContent = CONTENT[mediaType];
|
|
73
|
-
|
|
74
|
-
const isImage = mediaType === KEYS.img;
|
|
75
|
-
|
|
76
|
-
const file: File | undefined = updatedFiles?.[0];
|
|
77
|
-
const progress = file ? progresses?.[file.name] : undefined;
|
|
78
|
-
|
|
79
|
-
const imageRef = useRef<HTMLImageElement>(null);
|
|
80
|
-
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
if (!imageRef.current) return;
|
|
83
|
-
|
|
84
|
-
const { height, width } = imageRef.current;
|
|
85
|
-
|
|
86
|
-
setSize?.({
|
|
87
|
-
height,
|
|
88
|
-
width
|
|
89
|
-
});
|
|
90
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
91
|
-
}, [imageRef.current]);
|
|
92
|
-
|
|
93
|
-
return (
|
|
94
|
-
<PlateElement className="my-1" {...props}>
|
|
95
|
-
<MediaPlaceholderPopover>
|
|
96
|
-
{(!progressing || !isImage) && (
|
|
97
|
-
<div
|
|
98
|
-
className={cn(
|
|
99
|
-
'flex cursor-pointer select-none items-center rounded-sm bg-muted p-3 pr-9 transition-bg-ease hover:bg-primary/10'
|
|
100
|
-
)}
|
|
101
|
-
contentEditable={false}
|
|
102
|
-
role="button">
|
|
103
|
-
<div className="relative mr-3 flex text-muted-foreground/80 [&_svg]:size-6">
|
|
104
|
-
{currentContent.icon}
|
|
105
|
-
</div>
|
|
106
|
-
<div className="whitespace-nowrap text-muted-foreground text-sm">
|
|
107
|
-
<div>{progressing ? file?.name : currentContent.content}</div>
|
|
108
|
-
|
|
109
|
-
{progressing && !isImage && (
|
|
110
|
-
<div className="mt-1 flex items-center gap-1.5">
|
|
111
|
-
<div>{formatBytes(file.size)}</div>
|
|
112
|
-
<div>-</div>
|
|
113
|
-
<div className="flex items-center">
|
|
114
|
-
<Spinner className="mr-1 size-3.5" />
|
|
115
|
-
{progress ?? 0}%
|
|
116
|
-
</div>
|
|
117
|
-
</div>
|
|
118
|
-
)}
|
|
119
|
-
</div>
|
|
120
|
-
</div>
|
|
121
|
-
)}
|
|
122
|
-
</MediaPlaceholderPopover>
|
|
123
|
-
|
|
124
|
-
{isImage && progressing && file && (
|
|
125
|
-
<ImageProgress file={file} imageRef={imageRef} progress={progress} />
|
|
126
|
-
)}
|
|
127
|
-
|
|
128
|
-
<BlockActionButton />
|
|
129
|
-
|
|
130
|
-
{props.children}
|
|
131
|
-
</PlateElement>
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
const MEDIA_CONFIG: Record<
|
|
137
|
-
string,
|
|
138
|
-
{
|
|
139
|
-
accept: string[];
|
|
140
|
-
buttonText: string;
|
|
141
|
-
embedText: string;
|
|
142
|
-
}
|
|
143
|
-
> = {
|
|
144
|
-
[KEYS.audio]: {
|
|
145
|
-
accept: ['audio/*'],
|
|
146
|
-
buttonText: 'Upload Audio',
|
|
147
|
-
embedText: 'Embed audio'
|
|
148
|
-
},
|
|
149
|
-
[KEYS.file]: {
|
|
150
|
-
accept: ['*'],
|
|
151
|
-
buttonText: 'Choose a file',
|
|
152
|
-
embedText: 'Embed file'
|
|
153
|
-
},
|
|
154
|
-
[KEYS.img]: {
|
|
155
|
-
accept: ['image/*'],
|
|
156
|
-
buttonText: 'Upload file',
|
|
157
|
-
embedText: 'Embed image'
|
|
158
|
-
},
|
|
159
|
-
[KEYS.video]: {
|
|
160
|
-
accept: ['video/*'],
|
|
161
|
-
buttonText: 'Upload video',
|
|
162
|
-
embedText: 'Embed video'
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
function MediaPlaceholderPopover({ children }: { children: ReactNode }) {
|
|
167
|
-
const {
|
|
168
|
-
api, editor, getOption, tf
|
|
169
|
-
} = useEditorPlugin(PlaceholderPlugin);
|
|
170
|
-
|
|
171
|
-
const {
|
|
172
|
-
id,
|
|
173
|
-
element,
|
|
174
|
-
mediaType,
|
|
175
|
-
readOnly,
|
|
176
|
-
selected,
|
|
177
|
-
setIsUploading,
|
|
178
|
-
setProgresses,
|
|
179
|
-
setUpdatedFiles,
|
|
180
|
-
size
|
|
181
|
-
} = usePlaceholderPopoverState();
|
|
182
|
-
const [open, setOpen] = useState(false);
|
|
183
|
-
|
|
184
|
-
const currentMedia = MEDIA_CONFIG[mediaType];
|
|
185
|
-
|
|
186
|
-
const multiple = getOption('multiple') ?? true;
|
|
187
|
-
|
|
188
|
-
const {
|
|
189
|
-
isUploading, progress, uploadedFile, uploadFile, uploadingFile
|
|
190
|
-
}
|
|
191
|
-
= useUploadFile({
|
|
192
|
-
onUploadComplete() {
|
|
193
|
-
// Replace with actual file creation logic
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
const replaceCurrentPlaceholder = useCallback(
|
|
198
|
-
(file: File) => {
|
|
199
|
-
setUpdatedFiles([file]);
|
|
200
|
-
void uploadFile(file);
|
|
201
|
-
api.placeholder.addUploadingFile(element.id as string, file);
|
|
202
|
-
},
|
|
203
|
-
[
|
|
204
|
-
element.id,
|
|
205
|
-
setUpdatedFiles,
|
|
206
|
-
uploadFile,
|
|
207
|
-
api.placeholder
|
|
208
|
-
]
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
/** Open file picker using native input */
|
|
212
|
-
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
213
|
-
|
|
214
|
-
const openFilePicker = useCallback(() => {
|
|
215
|
-
if (fileInputRef.current) {
|
|
216
|
-
fileInputRef.current.value = '';
|
|
217
|
-
fileInputRef.current.click();
|
|
218
|
-
}
|
|
219
|
-
}, []);
|
|
220
|
-
|
|
221
|
-
const handleFilesSelected = useCallback(
|
|
222
|
-
(e: ChangeEvent<HTMLInputElement>) => {
|
|
223
|
-
const updatedFiles: File[] = Array.from(e.target.files || []);
|
|
224
|
-
|
|
225
|
-
if (!updatedFiles.length) return;
|
|
226
|
-
|
|
227
|
-
const firstFile = updatedFiles[0];
|
|
228
|
-
const restFiles = updatedFiles.slice(1);
|
|
229
|
-
|
|
230
|
-
replaceCurrentPlaceholder(firstFile);
|
|
231
|
-
|
|
232
|
-
if (restFiles.length > 0) {
|
|
233
|
-
tf.insert.media(restFiles as unknown as FileList);
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
[replaceCurrentPlaceholder, tf.insert]
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
// React dev mode will call useEffect twice
|
|
240
|
-
const isReplaced = useRef(false);
|
|
241
|
-
|
|
242
|
-
/** Paste and drop */
|
|
243
|
-
useEffect(() => {
|
|
244
|
-
if (isReplaced.current) return;
|
|
245
|
-
|
|
246
|
-
isReplaced.current = true;
|
|
247
|
-
const currentFiles = api.placeholder.getUploadingFile(element.id as string);
|
|
248
|
-
|
|
249
|
-
if (!currentFiles) return;
|
|
250
|
-
|
|
251
|
-
replaceCurrentPlaceholder(currentFiles);
|
|
252
|
-
|
|
253
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
254
|
-
}, [isReplaced]);
|
|
255
|
-
|
|
256
|
-
useEffect(() => {
|
|
257
|
-
if (!uploadedFile) return;
|
|
258
|
-
|
|
259
|
-
const path = editor.api.findPath(element);
|
|
260
|
-
|
|
261
|
-
setMediaNode(
|
|
262
|
-
editor,
|
|
263
|
-
{
|
|
264
|
-
id: nanoid(),
|
|
265
|
-
initialHeight: size?.height,
|
|
266
|
-
initialWidth: size?.width,
|
|
267
|
-
isUpload: true,
|
|
268
|
-
name: mediaType === KEYS.file ? uploadedFile.name : '',
|
|
269
|
-
placeholderId: element.id as string,
|
|
270
|
-
type: mediaType!,
|
|
271
|
-
url: uploadedFile.url
|
|
272
|
-
},
|
|
273
|
-
{ at: path }
|
|
274
|
-
);
|
|
275
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
276
|
-
}, [uploadedFile, element.id, size]);
|
|
277
|
-
|
|
278
|
-
const [embedValue, setEmbedValue] = useState('');
|
|
279
|
-
|
|
280
|
-
const onEmbed = useCallback(
|
|
281
|
-
(value: string) => {
|
|
282
|
-
setMediaNode(editor, {
|
|
283
|
-
type: mediaType,
|
|
284
|
-
url: value
|
|
285
|
-
});
|
|
286
|
-
},
|
|
287
|
-
[editor, mediaType]
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
useEffect(() => {
|
|
291
|
-
setOpen(selected);
|
|
292
|
-
}, [selected, setOpen]);
|
|
293
|
-
|
|
294
|
-
useEffect(() => {
|
|
295
|
-
if (isUploading) {
|
|
296
|
-
setOpen(false);
|
|
297
|
-
}
|
|
298
|
-
}, [isUploading]);
|
|
299
|
-
|
|
300
|
-
useEffect(() => {
|
|
301
|
-
setProgresses({ [uploadingFile?.name ?? '']: progress });
|
|
302
|
-
setIsUploading(isUploading);
|
|
303
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
304
|
-
}, [
|
|
305
|
-
id,
|
|
306
|
-
progress,
|
|
307
|
-
isUploading,
|
|
308
|
-
uploadingFile
|
|
309
|
-
]);
|
|
310
|
-
|
|
311
|
-
if (readOnly) return <>{children}</>;
|
|
312
|
-
|
|
313
|
-
return (
|
|
314
|
-
<Popover modal={false} onOpenChange={setOpen} open={open}>
|
|
315
|
-
<input
|
|
316
|
-
ref={fileInputRef}
|
|
317
|
-
type="file"
|
|
318
|
-
accept={currentMedia.accept.join(',')}
|
|
319
|
-
multiple={multiple}
|
|
320
|
-
onChange={handleFilesSelected}
|
|
321
|
-
className="hidden" />
|
|
322
|
-
<PopoverTrigger asChild>{children}</PopoverTrigger>
|
|
323
|
-
|
|
324
|
-
<PopoverContent
|
|
325
|
-
className="flex flex-col"
|
|
326
|
-
onOpenAutoFocus={e => e.preventDefault()}
|
|
327
|
-
variant="media">
|
|
328
|
-
<Tabs className="w-full shrink-0" defaultValue="account">
|
|
329
|
-
<TabsList className="px-2" onMouseDown={e => e.preventDefault()}>
|
|
330
|
-
<TabsTrigger value="account">Upload</TabsTrigger>
|
|
331
|
-
<TabsTrigger value="password">Embed link</TabsTrigger>
|
|
332
|
-
</TabsList>
|
|
333
|
-
<TabsContent className="w-[300px] px-3 py-2" value="account">
|
|
334
|
-
<Button className="w-full" onClick={openFilePicker} variant="brand">
|
|
335
|
-
{currentMedia.buttonText}
|
|
336
|
-
</Button>
|
|
337
|
-
<div className="mt-3 text-muted-foreground text-xs">
|
|
338
|
-
The maximum size per file is 5MB
|
|
339
|
-
</div>
|
|
340
|
-
</TabsContent>
|
|
341
|
-
|
|
342
|
-
<TabsContent
|
|
343
|
-
className="w-[300px] px-3 pt-2 pb-3 text-center"
|
|
344
|
-
value="password">
|
|
345
|
-
<Input
|
|
346
|
-
onChange={e => setEmbedValue(e.target.value)}
|
|
347
|
-
placeholder="Paste the link..."
|
|
348
|
-
value={embedValue} />
|
|
349
|
-
|
|
350
|
-
<Button
|
|
351
|
-
className="mt-2 w-full max-w-[300px]"
|
|
352
|
-
onClick={() => onEmbed(embedValue)}
|
|
353
|
-
variant="brand">
|
|
354
|
-
{currentMedia.embedText}
|
|
355
|
-
</Button>
|
|
356
|
-
</TabsContent>
|
|
357
|
-
</Tabs>
|
|
358
|
-
</PopoverContent>
|
|
359
|
-
</Popover>
|
|
360
|
-
);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function ImageProgress({
|
|
364
|
-
className,
|
|
365
|
-
file,
|
|
366
|
-
imageRef,
|
|
367
|
-
progress = 0
|
|
368
|
-
}: {
|
|
369
|
-
file: File;
|
|
370
|
-
className?: string;
|
|
371
|
-
imageRef?: RefObject<HTMLImageElement | null>;
|
|
372
|
-
progress?: number;
|
|
373
|
-
}) {
|
|
374
|
-
const [objectUrl, setObjectUrl] = useState<string | null>(null);
|
|
375
|
-
|
|
376
|
-
// Create and manage Object URL lifecycle
|
|
377
|
-
useEffect(() => {
|
|
378
|
-
const url = URL.createObjectURL(file);
|
|
379
|
-
|
|
380
|
-
setObjectUrl(url);
|
|
381
|
-
|
|
382
|
-
return () => {
|
|
383
|
-
URL.revokeObjectURL(url);
|
|
384
|
-
};
|
|
385
|
-
}, [file]);
|
|
386
|
-
|
|
387
|
-
if (!objectUrl) {
|
|
388
|
-
return null;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
return (
|
|
392
|
-
<div className={cn('relative', className)} contentEditable={false}>
|
|
393
|
-
<img
|
|
394
|
-
alt={file.name}
|
|
395
|
-
className="h-auto w-full rounded-xs object-cover"
|
|
396
|
-
ref={imageRef}
|
|
397
|
-
src={objectUrl} />
|
|
398
|
-
{progress < 100 && (
|
|
399
|
-
<div className="absolute right-1 bottom-1 flex items-center space-x-2 rounded-full bg-black/50 px-1 py-0.5">
|
|
400
|
-
<Spinner />
|
|
401
|
-
<span className="font-medium text-white text-xs">
|
|
402
|
-
{Math.round(progress)}%
|
|
403
|
-
</span>
|
|
404
|
-
</div>
|
|
405
|
-
)}
|
|
406
|
-
</div>
|
|
407
|
-
);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
function formatBytes(
|
|
411
|
-
bytes: number,
|
|
412
|
-
opts: {
|
|
413
|
-
decimals?: number;
|
|
414
|
-
sizeType?: 'accurate' | 'normal';
|
|
415
|
-
} = {}
|
|
416
|
-
) {
|
|
417
|
-
const { decimals = 0, sizeType = 'normal' } = opts;
|
|
418
|
-
|
|
419
|
-
const sizes = [
|
|
420
|
-
'Bytes',
|
|
421
|
-
'KB',
|
|
422
|
-
'MB',
|
|
423
|
-
'GB',
|
|
424
|
-
'TB'
|
|
425
|
-
];
|
|
426
|
-
const accurateSizes = [
|
|
427
|
-
'Bytes',
|
|
428
|
-
'KiB',
|
|
429
|
-
'MiB',
|
|
430
|
-
'GiB',
|
|
431
|
-
'TiB'
|
|
432
|
-
];
|
|
433
|
-
|
|
434
|
-
if (bytes === 0) return '0 Byte';
|
|
435
|
-
|
|
436
|
-
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
437
|
-
|
|
438
|
-
return `${(bytes / 1024 ** i).toFixed(decimals)} ${
|
|
439
|
-
sizeType === 'accurate' ? (accurateSizes[i] ?? 'Bytest') : (sizes[i] ?? 'Bytes')
|
|
440
|
-
}`;
|
|
441
|
-
}
|