@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,30 @@
|
|
|
1
|
+
|
|
2
|
+
import { type TFileElement } from 'platejs';
|
|
3
|
+
|
|
4
|
+
import { FileUp } from 'lucide-react';
|
|
5
|
+
|
|
6
|
+
import { SlateElement, type SlateElementProps } from 'platejs/static';
|
|
7
|
+
|
|
8
|
+
export function MediaFileElementStatic(props: SlateElementProps<TFileElement>) {
|
|
9
|
+
const { name, url } = props.element;
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<SlateElement className="my-px rounded-sm" {...props}>
|
|
13
|
+
<a
|
|
14
|
+
className="group relative m-0 flex cursor-pointer items-center rounded px-0.5 py-[3px] hover:bg-muted"
|
|
15
|
+
contentEditable={false}
|
|
16
|
+
download={name}
|
|
17
|
+
href={url}
|
|
18
|
+
rel="noopener noreferrer"
|
|
19
|
+
role="button"
|
|
20
|
+
target="_blank">
|
|
21
|
+
<div className="flex items-center gap-1 p-1">
|
|
22
|
+
<FileUp className="size-5" />
|
|
23
|
+
<div>{name}</div>
|
|
24
|
+
</div>
|
|
25
|
+
</a>
|
|
26
|
+
|
|
27
|
+
{props.children}
|
|
28
|
+
</SlateElement>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
);
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
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
|
+
};
|