@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,556 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
memo, useCallback, useEffect, useMemo, useState, type ComponentProps, type RefObject
|
|
5
|
+
} from 'react';
|
|
6
|
+
|
|
7
|
+
import { DndPlugin, useDraggable, useDropLine } from '@platejs/dnd';
|
|
8
|
+
import { expandListItemsWithChildren } from '@platejs/list';
|
|
9
|
+
import { BlockSelectionPlugin } from '@platejs/selection/react';
|
|
10
|
+
import { GripVertical, PlusIcon } from 'lucide-react';
|
|
11
|
+
import {
|
|
12
|
+
getPluginByType,
|
|
13
|
+
isType,
|
|
14
|
+
KEYS,
|
|
15
|
+
type Path,
|
|
16
|
+
PathApi,
|
|
17
|
+
type TElement
|
|
18
|
+
} from 'platejs';
|
|
19
|
+
import {
|
|
20
|
+
MemoizedChildren,
|
|
21
|
+
type PlateEditor,
|
|
22
|
+
type PlateElementProps,
|
|
23
|
+
type RenderNodeWrapper,
|
|
24
|
+
useEditorRef,
|
|
25
|
+
useElement,
|
|
26
|
+
usePluginOption,
|
|
27
|
+
useSelected
|
|
28
|
+
} from 'platejs/react';
|
|
29
|
+
|
|
30
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
31
|
+
|
|
32
|
+
import { BlockMenu } from './block-menu';
|
|
33
|
+
import { Button } from './button';
|
|
34
|
+
|
|
35
|
+
const UNDRAGGABLE_KEYS = [KEYS.column, KEYS.tr, KEYS.td];
|
|
36
|
+
|
|
37
|
+
export const BlockDraggable: RenderNodeWrapper = (props) => {
|
|
38
|
+
const { editor, element, path } = props;
|
|
39
|
+
|
|
40
|
+
const enabled = useMemo(() => {
|
|
41
|
+
if (editor.dom.readOnly) return false;
|
|
42
|
+
if (path.length === 1 && !isType(editor, element, UNDRAGGABLE_KEYS)) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (path.length === 3 && !isType(editor, element, UNDRAGGABLE_KEYS)) {
|
|
46
|
+
const block = editor.api.some({
|
|
47
|
+
at: path,
|
|
48
|
+
match: { type: editor.getType(KEYS.column) }
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (block) return true;
|
|
52
|
+
}
|
|
53
|
+
if (path.length === 4 && !isType(editor, element, UNDRAGGABLE_KEYS)) {
|
|
54
|
+
const block = editor.api.some({
|
|
55
|
+
at: path,
|
|
56
|
+
match: { type: editor.getType(KEYS.table) }
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (block) return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return false;
|
|
63
|
+
}, [editor, element, path]);
|
|
64
|
+
|
|
65
|
+
if (!enabled) return;
|
|
66
|
+
|
|
67
|
+
return renderProps => <Draggable {...renderProps} />;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
function Draggable(props: PlateElementProps) {
|
|
71
|
+
const {
|
|
72
|
+
children, editor, element, path
|
|
73
|
+
} = props;
|
|
74
|
+
const blockSelectionApi = editor.getApi(BlockSelectionPlugin).blockSelection;
|
|
75
|
+
|
|
76
|
+
const {
|
|
77
|
+
isAboutToDrag, isDragging, nodeRef, previewRef, handleRef
|
|
78
|
+
}
|
|
79
|
+
= useDraggable({
|
|
80
|
+
element,
|
|
81
|
+
onDropHandler: (_, { dragItem }) => {
|
|
82
|
+
const { id } = dragItem as { id: string[] | string };
|
|
83
|
+
|
|
84
|
+
if (blockSelectionApi) {
|
|
85
|
+
blockSelectionApi.add(id);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
resetPreview();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const isInColumn = path.length === 3;
|
|
93
|
+
const isInTable = path.length === 4;
|
|
94
|
+
|
|
95
|
+
const [previewTop, setPreviewTop] = useState(0);
|
|
96
|
+
|
|
97
|
+
const resetPreview = useCallback(() => {
|
|
98
|
+
if (previewRef.current) {
|
|
99
|
+
previewRef.current.replaceChildren();
|
|
100
|
+
previewRef.current?.classList.add('hidden');
|
|
101
|
+
}
|
|
102
|
+
}, [previewRef]);
|
|
103
|
+
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!isDragging) {
|
|
106
|
+
resetPreview();
|
|
107
|
+
}
|
|
108
|
+
}, [isDragging, resetPreview]);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (isAboutToDrag) {
|
|
112
|
+
previewRef.current?.classList.remove('opacity-0');
|
|
113
|
+
}
|
|
114
|
+
}, [isAboutToDrag, previewRef]);
|
|
115
|
+
|
|
116
|
+
const [dragButtonTop, setDragButtonTop] = useState(0);
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<div
|
|
120
|
+
className={cn(
|
|
121
|
+
'relative',
|
|
122
|
+
isDragging && 'opacity-50',
|
|
123
|
+
getPluginByType(editor, element.type)?.node.isContainer ? 'group/container' : 'group'
|
|
124
|
+
)}
|
|
125
|
+
onMouseEnter={() => {
|
|
126
|
+
if (isDragging) return;
|
|
127
|
+
|
|
128
|
+
setDragButtonTop(calcDragButtonTop(editor, element));
|
|
129
|
+
}}>
|
|
130
|
+
{!isInTable && (
|
|
131
|
+
<Gutter>
|
|
132
|
+
<div
|
|
133
|
+
className={cn(
|
|
134
|
+
'slate-blockToolbarWrapper',
|
|
135
|
+
'flex h-[1.5em]',
|
|
136
|
+
isInColumn && 'h-4',
|
|
137
|
+
isInTable && 'mt-1 size-4'
|
|
138
|
+
)}>
|
|
139
|
+
<div
|
|
140
|
+
className={cn(
|
|
141
|
+
'slate-blockToolbar relative w-13',
|
|
142
|
+
'pointer-events-auto mr-1 flex items-center',
|
|
143
|
+
isInColumn && 'mr-1.5'
|
|
144
|
+
)}>
|
|
145
|
+
<Button
|
|
146
|
+
className="absolute right-0 h-6 w-6 p-0"
|
|
147
|
+
data-plate-prevent-deselect
|
|
148
|
+
ref={handleRef}
|
|
149
|
+
style={{ top: `${dragButtonTop + 3}px` }}
|
|
150
|
+
tooltip={
|
|
151
|
+
<div className="text-center">
|
|
152
|
+
Drag <span className="text-gray-400">to move</span>
|
|
153
|
+
<br />
|
|
154
|
+
Click <span className="text-gray-400">to open menu</span>
|
|
155
|
+
</div>
|
|
156
|
+
}
|
|
157
|
+
tooltipContentProps={{
|
|
158
|
+
side: 'bottom'
|
|
159
|
+
}}
|
|
160
|
+
variant="ghost">
|
|
161
|
+
<DragHandle
|
|
162
|
+
isDragging={isDragging}
|
|
163
|
+
previewRef={previewRef}
|
|
164
|
+
resetPreview={resetPreview}
|
|
165
|
+
setPreviewTop={setPreviewTop} />
|
|
166
|
+
</Button>
|
|
167
|
+
|
|
168
|
+
{!isInColumn && !isInTable && (
|
|
169
|
+
<div
|
|
170
|
+
className="absolute left-0 h-6"
|
|
171
|
+
style={{ top: `${dragButtonTop + 3}px` }}>
|
|
172
|
+
<DraggableInsertHandle />
|
|
173
|
+
</div>
|
|
174
|
+
)}
|
|
175
|
+
</div>
|
|
176
|
+
</div>
|
|
177
|
+
</Gutter>
|
|
178
|
+
)}
|
|
179
|
+
|
|
180
|
+
<div
|
|
181
|
+
className={cn('-left-0 absolute hidden w-full')}
|
|
182
|
+
contentEditable={false}
|
|
183
|
+
ref={previewRef}
|
|
184
|
+
style={{ top: `${-previewTop}px` }} />
|
|
185
|
+
|
|
186
|
+
<div
|
|
187
|
+
className="slate-blockWrapper my-px flow-root"
|
|
188
|
+
onContextMenu={event => editor
|
|
189
|
+
.getApi(BlockSelectionPlugin)
|
|
190
|
+
.blockSelection.addOnContextMenu({ element, event })}
|
|
191
|
+
ref={nodeRef}>
|
|
192
|
+
<MemoizedChildren>{children}</MemoizedChildren>
|
|
193
|
+
<DropLine />
|
|
194
|
+
</div>
|
|
195
|
+
</div>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function Gutter({
|
|
200
|
+
children,
|
|
201
|
+
className,
|
|
202
|
+
...props
|
|
203
|
+
}: ComponentProps<'div'>) {
|
|
204
|
+
const editor = useEditorRef();
|
|
205
|
+
const element = useElement();
|
|
206
|
+
const isSelectionAreaVisible = usePluginOption(
|
|
207
|
+
BlockSelectionPlugin,
|
|
208
|
+
'isSelectionAreaVisible'
|
|
209
|
+
);
|
|
210
|
+
const selected = useSelected();
|
|
211
|
+
|
|
212
|
+
return (
|
|
213
|
+
<div
|
|
214
|
+
{...props}
|
|
215
|
+
className={cn(
|
|
216
|
+
'slate-gutterLeft',
|
|
217
|
+
'-translate-x-full absolute top-0 z-50 flex h-full cursor-text hover:opacity-100 sm:opacity-0',
|
|
218
|
+
getPluginByType(editor, element.type)?.node.isContainer ? 'group-hover/container:opacity-100' : 'group-hover:opacity-100',
|
|
219
|
+
isSelectionAreaVisible && 'hidden',
|
|
220
|
+
!selected && 'opacity-0',
|
|
221
|
+
className
|
|
222
|
+
)}
|
|
223
|
+
contentEditable={false}>
|
|
224
|
+
{children}
|
|
225
|
+
</div>
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const DragHandle = memo(({
|
|
230
|
+
isDragging,
|
|
231
|
+
previewRef,
|
|
232
|
+
resetPreview,
|
|
233
|
+
setPreviewTop
|
|
234
|
+
}: {
|
|
235
|
+
isDragging: boolean;
|
|
236
|
+
previewRef: RefObject<HTMLDivElement | null>;
|
|
237
|
+
resetPreview: () => void;
|
|
238
|
+
setPreviewTop: (top: number) => void;
|
|
239
|
+
}) => {
|
|
240
|
+
const editor = useEditorRef();
|
|
241
|
+
const element = useElement();
|
|
242
|
+
|
|
243
|
+
return (
|
|
244
|
+
<BlockMenu animateZoom id={element.id as string} placement="left">
|
|
245
|
+
<div
|
|
246
|
+
className="flex size-full items-center justify-center"
|
|
247
|
+
data-plate-prevent-deselect
|
|
248
|
+
onMouseDown={(e) => {
|
|
249
|
+
resetPreview();
|
|
250
|
+
|
|
251
|
+
if (e.button !== 0 || e.shiftKey) return;
|
|
252
|
+
|
|
253
|
+
const blockSelection = editor
|
|
254
|
+
.getApi(BlockSelectionPlugin)
|
|
255
|
+
.blockSelection.getNodes({ sort: true });
|
|
256
|
+
|
|
257
|
+
let selectionNodes
|
|
258
|
+
= blockSelection.length > 0 ? blockSelection : editor.api.blocks({ mode: 'highest' });
|
|
259
|
+
|
|
260
|
+
if (!selectionNodes.some(([node]) => node.id === element.id)) {
|
|
261
|
+
selectionNodes = [[element, editor.api.findPath(element)!]];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const blocks = expandListItemsWithChildren(
|
|
265
|
+
editor,
|
|
266
|
+
selectionNodes
|
|
267
|
+
).map(([node]) => node);
|
|
268
|
+
|
|
269
|
+
if (blockSelection.length === 0) {
|
|
270
|
+
editor.tf.blur();
|
|
271
|
+
editor.tf.collapse();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const elements = createDragPreviewElements(editor, blocks);
|
|
275
|
+
|
|
276
|
+
previewRef.current?.append(...elements);
|
|
277
|
+
previewRef.current?.classList.remove('hidden');
|
|
278
|
+
previewRef.current?.classList.add('opacity-0');
|
|
279
|
+
editor.setOption(DndPlugin, 'multiplePreviewRef', previewRef);
|
|
280
|
+
|
|
281
|
+
editor
|
|
282
|
+
.getApi(BlockSelectionPlugin)
|
|
283
|
+
.blockSelection.add(blocks.map(block => block.id as string));
|
|
284
|
+
}}
|
|
285
|
+
onMouseEnter={() => {
|
|
286
|
+
if (isDragging) return;
|
|
287
|
+
|
|
288
|
+
const blockSelection = editor
|
|
289
|
+
.getApi(BlockSelectionPlugin)
|
|
290
|
+
.blockSelection.getNodes({ sort: true });
|
|
291
|
+
|
|
292
|
+
let selectedBlocks
|
|
293
|
+
= blockSelection.length > 0 ? blockSelection : editor.api.blocks({ mode: 'highest' });
|
|
294
|
+
|
|
295
|
+
if (!selectedBlocks.some(([node]) => node.id === element.id)) {
|
|
296
|
+
selectedBlocks = [[element, editor.api.findPath(element)!]];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const processedBlocks = expandListItemsWithChildren(
|
|
300
|
+
editor,
|
|
301
|
+
selectedBlocks
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
const ids = processedBlocks.map(block => block[0].id as string);
|
|
305
|
+
|
|
306
|
+
if (ids.length > 1 && ids.includes(element.id as string)) {
|
|
307
|
+
const _previewTop = calculatePreviewTop(editor, {
|
|
308
|
+
blocks: processedBlocks.map(block => block[0]),
|
|
309
|
+
element
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
setPreviewTop(_previewTop);
|
|
313
|
+
} else {
|
|
314
|
+
setPreviewTop(0);
|
|
315
|
+
}
|
|
316
|
+
}}
|
|
317
|
+
onMouseUp={() => {
|
|
318
|
+
resetPreview();
|
|
319
|
+
}}
|
|
320
|
+
role="button">
|
|
321
|
+
<GripVertical className="text-muted-foreground" />
|
|
322
|
+
</div>
|
|
323
|
+
</BlockMenu>
|
|
324
|
+
);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
const DropLineComponent = memo(({
|
|
328
|
+
className,
|
|
329
|
+
...props
|
|
330
|
+
}: ComponentProps<'div'>) => {
|
|
331
|
+
const { dropLine } = useDropLine();
|
|
332
|
+
|
|
333
|
+
if (!dropLine) return null;
|
|
334
|
+
|
|
335
|
+
return (
|
|
336
|
+
<div
|
|
337
|
+
{...props}
|
|
338
|
+
className={cn(
|
|
339
|
+
'slate-dropLine',
|
|
340
|
+
'absolute inset-x-0 h-0.5 opacity-100 transition-opacity',
|
|
341
|
+
'bg-brand/50',
|
|
342
|
+
dropLine === 'top' && '-top-px',
|
|
343
|
+
dropLine === 'bottom' && '-bottom-px',
|
|
344
|
+
className
|
|
345
|
+
)} />
|
|
346
|
+
);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// Re-export for internal use
|
|
350
|
+
const DropLine = DropLineComponent;
|
|
351
|
+
|
|
352
|
+
const DraggableInsertHandle = () => {
|
|
353
|
+
const editor = useEditorRef();
|
|
354
|
+
const element = useElement();
|
|
355
|
+
|
|
356
|
+
return (
|
|
357
|
+
<Button
|
|
358
|
+
className="size-6 shrink-0 p-1"
|
|
359
|
+
onClick={(event) => {
|
|
360
|
+
event.stopPropagation();
|
|
361
|
+
event.preventDefault();
|
|
362
|
+
|
|
363
|
+
const at = editor.api.findPath(element);
|
|
364
|
+
|
|
365
|
+
triggerComboboxNextBlock(editor, '/', at, event.altKey);
|
|
366
|
+
}}
|
|
367
|
+
onMouseDown={() => {
|
|
368
|
+
editor.tf.focus();
|
|
369
|
+
editor.getApi(BlockSelectionPlugin).blockSelection.clear();
|
|
370
|
+
}}
|
|
371
|
+
tabIndex={-1}
|
|
372
|
+
tooltip={
|
|
373
|
+
<div className="text-center">
|
|
374
|
+
Click <span className="text-gray-400">to add below</span>
|
|
375
|
+
<br />
|
|
376
|
+
Option-click <span className="text-gray-400">to add above</span>
|
|
377
|
+
</div>
|
|
378
|
+
}
|
|
379
|
+
tooltipContentProps={{
|
|
380
|
+
side: 'bottom'
|
|
381
|
+
}}
|
|
382
|
+
variant="ghost">
|
|
383
|
+
<PlusIcon className="size-6 text-muted-foreground/70" />
|
|
384
|
+
</Button>
|
|
385
|
+
);
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
const triggerComboboxNextBlock = (
|
|
389
|
+
editor: PlateEditor,
|
|
390
|
+
triggerText: string,
|
|
391
|
+
at?: Path,
|
|
392
|
+
insertAbove = false
|
|
393
|
+
) => {
|
|
394
|
+
let _at: Path | undefined;
|
|
395
|
+
|
|
396
|
+
if (at) {
|
|
397
|
+
const slicedPath = at.slice(0, 1);
|
|
398
|
+
|
|
399
|
+
_at = insertAbove ? slicedPath : PathApi.next(slicedPath);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
editor.tf.insertNodes(editor.api.create.block(), {
|
|
403
|
+
at: _at,
|
|
404
|
+
select: true
|
|
405
|
+
});
|
|
406
|
+
editor.tf.insertText(triggerText);
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
const createDragPreviewElements = (
|
|
410
|
+
editor: PlateEditor,
|
|
411
|
+
blocks: TElement[]
|
|
412
|
+
): HTMLElement[] => {
|
|
413
|
+
const elements: HTMLElement[] = [];
|
|
414
|
+
const ids: string[] = [];
|
|
415
|
+
|
|
416
|
+
const removeDataAttributes = (el: HTMLElement) => {
|
|
417
|
+
Array.from(el.attributes).forEach((attr) => {
|
|
418
|
+
if (
|
|
419
|
+
attr.name.startsWith('data-slate')
|
|
420
|
+
|| attr.name.startsWith('data-block-id')
|
|
421
|
+
) {
|
|
422
|
+
el.removeAttribute(attr.name);
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
Array.from(el.children).forEach((child) => {
|
|
427
|
+
removeDataAttributes(child as HTMLElement);
|
|
428
|
+
});
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
const resolveElement = (node: TElement, index: number) => {
|
|
432
|
+
const domNode = editor.api.toDOMNode(node)!;
|
|
433
|
+
const newDomNode = domNode.cloneNode(true) as HTMLElement;
|
|
434
|
+
|
|
435
|
+
const applyScrollCompensation = (
|
|
436
|
+
original: Element,
|
|
437
|
+
cloned: HTMLElement
|
|
438
|
+
) => {
|
|
439
|
+
const { scrollLeft } = original;
|
|
440
|
+
|
|
441
|
+
if (scrollLeft > 0) {
|
|
442
|
+
const scrollWrapper = document.createElement('div');
|
|
443
|
+
|
|
444
|
+
scrollWrapper.style.overflow = 'hidden';
|
|
445
|
+
scrollWrapper.style.width = `${original.clientWidth}px`;
|
|
446
|
+
|
|
447
|
+
const innerContainer = document.createElement('div');
|
|
448
|
+
|
|
449
|
+
innerContainer.style.transform = `translateX(-${scrollLeft}px)`;
|
|
450
|
+
innerContainer.style.width = `${original.scrollWidth}px`;
|
|
451
|
+
|
|
452
|
+
while (cloned.firstChild) {
|
|
453
|
+
innerContainer.append(cloned.firstChild);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const originalStyles = window.getComputedStyle(original);
|
|
457
|
+
|
|
458
|
+
cloned.style.padding = '0';
|
|
459
|
+
innerContainer.style.padding = originalStyles.padding;
|
|
460
|
+
|
|
461
|
+
scrollWrapper.append(innerContainer);
|
|
462
|
+
cloned.append(scrollWrapper);
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
applyScrollCompensation(domNode, newDomNode);
|
|
467
|
+
|
|
468
|
+
ids.push(node.id as string);
|
|
469
|
+
const wrapper = document.createElement('div');
|
|
470
|
+
|
|
471
|
+
wrapper.append(newDomNode);
|
|
472
|
+
wrapper.style.display = 'flow-root';
|
|
473
|
+
|
|
474
|
+
const lastDomNode = blocks[index - 1];
|
|
475
|
+
|
|
476
|
+
if (lastDomNode) {
|
|
477
|
+
const lastDomNodeRect = editor.api
|
|
478
|
+
.toDOMNode(lastDomNode)!
|
|
479
|
+
.parentElement!.getBoundingClientRect();
|
|
480
|
+
|
|
481
|
+
const domNodeRect = domNode.parentElement!.getBoundingClientRect();
|
|
482
|
+
|
|
483
|
+
const distance = domNodeRect.top - lastDomNodeRect.bottom;
|
|
484
|
+
|
|
485
|
+
if (distance > 15) {
|
|
486
|
+
wrapper.style.marginTop = `${distance}px`;
|
|
487
|
+
} else {
|
|
488
|
+
wrapper.style.marginTop = '1px';
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
removeDataAttributes(newDomNode);
|
|
493
|
+
elements.push(wrapper);
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
for (let index = 0; index < blocks.length; index++) {
|
|
497
|
+
resolveElement(blocks[index], index);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
editor.setOption(DndPlugin, 'draggingId', ids);
|
|
501
|
+
|
|
502
|
+
return elements;
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
const calculatePreviewTop = (
|
|
506
|
+
editor: PlateEditor,
|
|
507
|
+
{
|
|
508
|
+
blocks,
|
|
509
|
+
element
|
|
510
|
+
}: {
|
|
511
|
+
blocks: TElement[];
|
|
512
|
+
element: TElement;
|
|
513
|
+
}
|
|
514
|
+
): number => {
|
|
515
|
+
const child = editor.api.toDOMNode(element)!;
|
|
516
|
+
const editable = editor.api.toDOMNode(editor)!;
|
|
517
|
+
const firstSelectedChild = blocks[0];
|
|
518
|
+
|
|
519
|
+
const firstDomNode = editor.api.toDOMNode(firstSelectedChild)!;
|
|
520
|
+
const editorPaddingTop = Number(
|
|
521
|
+
window.getComputedStyle(editable).paddingTop.replace('px', '')
|
|
522
|
+
);
|
|
523
|
+
|
|
524
|
+
const firstNodeToEditorDistance
|
|
525
|
+
= firstDomNode.getBoundingClientRect().top
|
|
526
|
+
- editable.getBoundingClientRect().top
|
|
527
|
+
- editorPaddingTop;
|
|
528
|
+
|
|
529
|
+
const firstMarginTopString = window.getComputedStyle(firstDomNode).marginTop;
|
|
530
|
+
const marginTop = Number(firstMarginTopString.replace('px', ''));
|
|
531
|
+
|
|
532
|
+
const currentToEditorDistance
|
|
533
|
+
= child.getBoundingClientRect().top
|
|
534
|
+
- editable.getBoundingClientRect().top
|
|
535
|
+
- editorPaddingTop;
|
|
536
|
+
|
|
537
|
+
const currentMarginTopString = window.getComputedStyle(child).marginTop;
|
|
538
|
+
const currentMarginTop = Number(currentMarginTopString.replace('px', ''));
|
|
539
|
+
|
|
540
|
+
const previewElementsTopDistance
|
|
541
|
+
= currentToEditorDistance
|
|
542
|
+
- firstNodeToEditorDistance
|
|
543
|
+
+ marginTop
|
|
544
|
+
- currentMarginTop;
|
|
545
|
+
|
|
546
|
+
return previewElementsTopDistance;
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
const calcDragButtonTop = (editor: PlateEditor, element: TElement): number => {
|
|
550
|
+
const child = editor.api.toDOMNode(element)!;
|
|
551
|
+
|
|
552
|
+
const currentMarginTopString = window.getComputedStyle(child).marginTop;
|
|
553
|
+
const currentMarginTop = Number(currentMarginTopString.replace('px', ''));
|
|
554
|
+
|
|
555
|
+
return currentMarginTop;
|
|
556
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type FC } from 'react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
import { type RenderStaticNodeWrapper, type TListElement } from 'platejs';
|
|
5
|
+
|
|
6
|
+
import { isOrderedList } from '@platejs/list';
|
|
7
|
+
import { CheckIcon } from 'lucide-react';
|
|
8
|
+
import { type SlateRenderElementProps } from 'platejs/static';
|
|
9
|
+
|
|
10
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
11
|
+
|
|
12
|
+
const config: Record<
|
|
13
|
+
string,
|
|
14
|
+
{
|
|
15
|
+
Li: FC<SlateRenderElementProps>;
|
|
16
|
+
Marker: FC<SlateRenderElementProps>;
|
|
17
|
+
}
|
|
18
|
+
> = {
|
|
19
|
+
todo: {
|
|
20
|
+
Li: TodoLiStatic,
|
|
21
|
+
Marker: TodoMarkerStatic
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const BlockListStatic: RenderStaticNodeWrapper = (props) => {
|
|
26
|
+
if (!props.element.listStyleType) return;
|
|
27
|
+
|
|
28
|
+
return props => <List {...props} />;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function List(props: SlateRenderElementProps) {
|
|
32
|
+
const { listStart, listStyleType } = props.element as TListElement;
|
|
33
|
+
const { Li, Marker } = config[listStyleType] ?? {};
|
|
34
|
+
const List = isOrderedList(props.element) ? 'ol' : 'ul';
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<List
|
|
38
|
+
className="relative m-0 p-0"
|
|
39
|
+
start={listStart}
|
|
40
|
+
style={{ listStyleType }}>
|
|
41
|
+
{Marker && <Marker {...props} />}
|
|
42
|
+
{Li ? <Li {...props} /> : <li>{props.children}</li>}
|
|
43
|
+
</List>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function TodoMarkerStatic(props: SlateRenderElementProps) {
|
|
48
|
+
const checked = props.element.checked as boolean;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div contentEditable={false}>
|
|
52
|
+
<button
|
|
53
|
+
className={cn(
|
|
54
|
+
'peer -left-6 pointer-events-none absolute top-1 size-4 shrink-0 rounded-sm border border-primary bg-background ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground',
|
|
55
|
+
props.className
|
|
56
|
+
)}
|
|
57
|
+
data-state={checked ? 'checked' : 'unchecked'}
|
|
58
|
+
type="button">
|
|
59
|
+
<div className={cn('flex items-center justify-center text-current')}>
|
|
60
|
+
{checked && <CheckIcon className="size-4" />}
|
|
61
|
+
</div>
|
|
62
|
+
</button>
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function TodoLiStatic(props: SlateRenderElementProps) {
|
|
68
|
+
return (
|
|
69
|
+
<li
|
|
70
|
+
className={cn(
|
|
71
|
+
'list-none',
|
|
72
|
+
(props.element.checked as boolean)
|
|
73
|
+
&& 'text-muted-foreground line-through'
|
|
74
|
+
)}>
|
|
75
|
+
{props.children}
|
|
76
|
+
</li>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type FC } from 'react';
|
|
4
|
+
|
|
5
|
+
import { type TListElement } from 'platejs';
|
|
6
|
+
|
|
7
|
+
import { isOrderedList } from '@platejs/list';
|
|
8
|
+
import {
|
|
9
|
+
useTodoListElement,
|
|
10
|
+
useTodoListElementState
|
|
11
|
+
} from '@platejs/list/react';
|
|
12
|
+
import {
|
|
13
|
+
type PlateElementProps,
|
|
14
|
+
type RenderNodeWrapper,
|
|
15
|
+
useReadOnly
|
|
16
|
+
} from 'platejs/react';
|
|
17
|
+
|
|
18
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
19
|
+
|
|
20
|
+
import { Checkbox } from './checkbox';
|
|
21
|
+
|
|
22
|
+
const config: Record<
|
|
23
|
+
string,
|
|
24
|
+
{
|
|
25
|
+
Li: FC<PlateElementProps>;
|
|
26
|
+
Marker: FC<PlateElementProps>;
|
|
27
|
+
}
|
|
28
|
+
> = {
|
|
29
|
+
todo: {
|
|
30
|
+
Li: TodoLi,
|
|
31
|
+
Marker: TodoMarker
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const BlockList: RenderNodeWrapper = (props) => {
|
|
36
|
+
if (!props.element.listStyleType) return;
|
|
37
|
+
|
|
38
|
+
return props => <List {...props} />;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function List(props: PlateElementProps) {
|
|
42
|
+
const { listStart, listStyleType } = props.element as TListElement;
|
|
43
|
+
const { Li, Marker } = config[listStyleType] ?? {};
|
|
44
|
+
const ListTag = isOrderedList(props.element) ? 'ol' : 'ul';
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<ListTag
|
|
48
|
+
className="relative m-0 p-0"
|
|
49
|
+
start={listStart}
|
|
50
|
+
style={{ listStyleType }}>
|
|
51
|
+
{Marker && <Marker {...props} />}
|
|
52
|
+
{Li ? <Li {...props} /> : <li>{props.children}</li>}
|
|
53
|
+
</ListTag>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function TodoMarker(props: PlateElementProps) {
|
|
58
|
+
const state = useTodoListElementState({ element: props.element });
|
|
59
|
+
const { checkboxProps } = useTodoListElement(state);
|
|
60
|
+
const readOnly = useReadOnly();
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<div contentEditable={false}>
|
|
64
|
+
<Checkbox
|
|
65
|
+
className={cn(
|
|
66
|
+
'-left-6 absolute top-1',
|
|
67
|
+
readOnly && 'pointer-events-none'
|
|
68
|
+
)}
|
|
69
|
+
{...checkboxProps} />
|
|
70
|
+
</div>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function TodoLi(props: PlateElementProps) {
|
|
75
|
+
return (
|
|
76
|
+
<li
|
|
77
|
+
className={cn(
|
|
78
|
+
'list-none',
|
|
79
|
+
(props.element.checked as boolean)
|
|
80
|
+
&& 'text-muted-foreground line-through'
|
|
81
|
+
)}>
|
|
82
|
+
{props.children}
|
|
83
|
+
</li>
|
|
84
|
+
);
|
|
85
|
+
}
|