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