@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,211 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type AutoformatRule,
|
|
5
|
+
AutoformatPlugin,
|
|
6
|
+
autoformatArrow,
|
|
7
|
+
autoformatLegal,
|
|
8
|
+
autoformatLegalHtml,
|
|
9
|
+
autoformatMath,
|
|
10
|
+
autoformatPunctuation,
|
|
11
|
+
autoformatSmartQuotes
|
|
12
|
+
} from '@platejs/autoformat';
|
|
13
|
+
|
|
14
|
+
import { insertEmptyCodeBlock } from '@platejs/code-block';
|
|
15
|
+
import { toggleList } from '@platejs/list';
|
|
16
|
+
import { openNextToggles } from '@platejs/toggle/react';
|
|
17
|
+
import { KEYS } from 'platejs';
|
|
18
|
+
|
|
19
|
+
const autoformatMarks: AutoformatRule[] = [
|
|
20
|
+
{
|
|
21
|
+
match: '***',
|
|
22
|
+
mode: 'mark',
|
|
23
|
+
type: [KEYS.bold, KEYS.italic]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
match: '__*',
|
|
27
|
+
mode: 'mark',
|
|
28
|
+
type: [KEYS.underline, KEYS.italic]
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
match: '__**',
|
|
32
|
+
mode: 'mark',
|
|
33
|
+
type: [KEYS.underline, KEYS.bold]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
match: '___***',
|
|
37
|
+
mode: 'mark',
|
|
38
|
+
type: [KEYS.underline, KEYS.bold, KEYS.italic]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
match: '**',
|
|
42
|
+
mode: 'mark',
|
|
43
|
+
type: KEYS.bold
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
match: '__',
|
|
47
|
+
mode: 'mark',
|
|
48
|
+
type: KEYS.underline
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
match: '*',
|
|
52
|
+
mode: 'mark',
|
|
53
|
+
type: KEYS.italic
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
match: '_',
|
|
57
|
+
mode: 'mark',
|
|
58
|
+
type: KEYS.italic
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
match: '~~',
|
|
62
|
+
mode: 'mark',
|
|
63
|
+
type: KEYS.strikethrough
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
match: '^',
|
|
67
|
+
mode: 'mark',
|
|
68
|
+
type: KEYS.sup
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
match: '~',
|
|
72
|
+
mode: 'mark',
|
|
73
|
+
type: KEYS.sub
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
match: '`',
|
|
77
|
+
mode: 'mark',
|
|
78
|
+
type: KEYS.code
|
|
79
|
+
}
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const autoformatBlocks: AutoformatRule[] = [
|
|
83
|
+
{
|
|
84
|
+
match: '# ',
|
|
85
|
+
mode: 'block',
|
|
86
|
+
type: KEYS.h1
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
match: '## ',
|
|
90
|
+
mode: 'block',
|
|
91
|
+
type: KEYS.h2
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
match: '### ',
|
|
95
|
+
mode: 'block',
|
|
96
|
+
type: KEYS.h3
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
match: '> ',
|
|
100
|
+
mode: 'block',
|
|
101
|
+
type: KEYS.blockquote
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
match: '```',
|
|
105
|
+
mode: 'block',
|
|
106
|
+
type: KEYS.codeBlock,
|
|
107
|
+
format: (editor) => {
|
|
108
|
+
insertEmptyCodeBlock(editor, {
|
|
109
|
+
defaultType: KEYS.p,
|
|
110
|
+
insertNodesOptions: { select: true }
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
match: '+ ',
|
|
116
|
+
mode: 'block',
|
|
117
|
+
preFormat: openNextToggles,
|
|
118
|
+
type: KEYS.toggle
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
match: ['---', '\u2014-', '___ '],
|
|
122
|
+
mode: 'block',
|
|
123
|
+
type: KEYS.hr,
|
|
124
|
+
format: (editor) => {
|
|
125
|
+
editor.tf.setNodes({ type: KEYS.hr });
|
|
126
|
+
editor.tf.insertNodes({
|
|
127
|
+
children: [{ text: '' }],
|
|
128
|
+
type: KEYS.p
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
const autoformatLists: AutoformatRule[] = [
|
|
135
|
+
{
|
|
136
|
+
match: ['* ', '- '],
|
|
137
|
+
mode: 'block',
|
|
138
|
+
type: 'list',
|
|
139
|
+
format: (editor) => {
|
|
140
|
+
toggleList(editor, {
|
|
141
|
+
listStyleType: KEYS.ul
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
match: [String.raw`^\d+\.$ `, String.raw`^\d+\)$ `],
|
|
147
|
+
matchByRegex: true,
|
|
148
|
+
mode: 'block',
|
|
149
|
+
type: 'list',
|
|
150
|
+
format: (editor, { matchString }) => {
|
|
151
|
+
toggleList(editor, {
|
|
152
|
+
listRestartPolite: Number(matchString) || 1,
|
|
153
|
+
listStyleType: KEYS.ol
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
match: ['[] '],
|
|
159
|
+
mode: 'block',
|
|
160
|
+
type: 'list',
|
|
161
|
+
format: (editor) => {
|
|
162
|
+
toggleList(editor, {
|
|
163
|
+
listStyleType: KEYS.listTodo
|
|
164
|
+
});
|
|
165
|
+
editor.tf.setNodes({
|
|
166
|
+
checked: false,
|
|
167
|
+
listStyleType: KEYS.listTodo
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
match: ['[x] '],
|
|
173
|
+
mode: 'block',
|
|
174
|
+
type: 'list',
|
|
175
|
+
format: (editor) => {
|
|
176
|
+
toggleList(editor, {
|
|
177
|
+
listStyleType: KEYS.listTodo
|
|
178
|
+
});
|
|
179
|
+
editor.tf.setNodes({
|
|
180
|
+
checked: true,
|
|
181
|
+
listStyleType: KEYS.listTodo
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
];
|
|
186
|
+
|
|
187
|
+
export const AutoformatKit = [
|
|
188
|
+
AutoformatPlugin.configure({
|
|
189
|
+
options: {
|
|
190
|
+
enableUndoOnDelete: true,
|
|
191
|
+
rules: [
|
|
192
|
+
...autoformatBlocks,
|
|
193
|
+
...autoformatMarks,
|
|
194
|
+
...autoformatSmartQuotes,
|
|
195
|
+
...autoformatPunctuation,
|
|
196
|
+
...autoformatLegal,
|
|
197
|
+
...autoformatLegalHtml,
|
|
198
|
+
...autoformatArrow,
|
|
199
|
+
...autoformatMath,
|
|
200
|
+
...autoformatLists
|
|
201
|
+
].map(
|
|
202
|
+
(rule): AutoformatRule => ({
|
|
203
|
+
...rule,
|
|
204
|
+
query: editor => !editor.api.some({
|
|
205
|
+
match: { type: editor.getType(KEYS.codeBlock) }
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseBlockquotePlugin,
|
|
3
|
+
BaseH1Plugin,
|
|
4
|
+
BaseH2Plugin,
|
|
5
|
+
BaseH3Plugin,
|
|
6
|
+
BaseHorizontalRulePlugin
|
|
7
|
+
} from '@platejs/basic-nodes';
|
|
8
|
+
import { BaseParagraphPlugin } from 'platejs';
|
|
9
|
+
|
|
10
|
+
import { BlockquoteElementStatic } from '../../plate-ui/blockquote-node-static';
|
|
11
|
+
import {
|
|
12
|
+
H1ElementStatic,
|
|
13
|
+
H2ElementStatic,
|
|
14
|
+
H3ElementStatic
|
|
15
|
+
} from '../../plate-ui/heading-node-static';
|
|
16
|
+
import { HrElementStatic } from '../../plate-ui/hr-node-static';
|
|
17
|
+
import { ParagraphElementStatic } from '../../plate-ui/paragraph-node-static';
|
|
18
|
+
|
|
19
|
+
export const BaseBasicBlocksKit = [
|
|
20
|
+
BaseParagraphPlugin.withComponent(ParagraphElementStatic),
|
|
21
|
+
BaseH1Plugin.withComponent(H1ElementStatic),
|
|
22
|
+
BaseH2Plugin.withComponent(H2ElementStatic),
|
|
23
|
+
BaseH3Plugin.withComponent(H3ElementStatic),
|
|
24
|
+
BaseBlockquotePlugin.withComponent(BlockquoteElementStatic),
|
|
25
|
+
BaseHorizontalRulePlugin.withComponent(HrElementStatic)
|
|
26
|
+
];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
BlockquotePlugin,
|
|
5
|
+
H1Plugin,
|
|
6
|
+
H2Plugin,
|
|
7
|
+
H3Plugin,
|
|
8
|
+
HorizontalRulePlugin
|
|
9
|
+
} from '@platejs/basic-nodes/react';
|
|
10
|
+
import { ParagraphPlugin } from 'platejs/react';
|
|
11
|
+
|
|
12
|
+
import { BlockquoteElement } from '../../plate-ui/blockquote-node';
|
|
13
|
+
import { H1Element, H2Element, H3Element } from '../../plate-ui/heading-node';
|
|
14
|
+
import { HrElement } from '../../plate-ui/hr-node';
|
|
15
|
+
import { ParagraphElement } from '../../plate-ui/paragraph-node';
|
|
16
|
+
|
|
17
|
+
export const BasicBlocksKit = [
|
|
18
|
+
ParagraphPlugin.withComponent(ParagraphElement),
|
|
19
|
+
H1Plugin.configure({
|
|
20
|
+
node: {
|
|
21
|
+
component: H1Element
|
|
22
|
+
},
|
|
23
|
+
rules: {
|
|
24
|
+
break: { empty: 'reset' }
|
|
25
|
+
},
|
|
26
|
+
shortcuts: { toggle: { keys: 'mod+alt+1' } }
|
|
27
|
+
}),
|
|
28
|
+
H2Plugin.configure({
|
|
29
|
+
node: {
|
|
30
|
+
component: H2Element
|
|
31
|
+
},
|
|
32
|
+
rules: {
|
|
33
|
+
break: { empty: 'reset' }
|
|
34
|
+
},
|
|
35
|
+
shortcuts: { toggle: { keys: 'mod+alt+2' } }
|
|
36
|
+
}),
|
|
37
|
+
H3Plugin.configure({
|
|
38
|
+
node: {
|
|
39
|
+
component: H3Element
|
|
40
|
+
},
|
|
41
|
+
rules: {
|
|
42
|
+
break: { empty: 'reset' }
|
|
43
|
+
},
|
|
44
|
+
shortcuts: { toggle: { keys: 'mod+alt+3' } }
|
|
45
|
+
}),
|
|
46
|
+
BlockquotePlugin.configure({
|
|
47
|
+
node: { component: BlockquoteElement },
|
|
48
|
+
shortcuts: { toggle: { keys: 'mod+shift+period' } }
|
|
49
|
+
}),
|
|
50
|
+
HorizontalRulePlugin.withComponent(HrElement)
|
|
51
|
+
];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseBoldPlugin,
|
|
3
|
+
BaseCodePlugin,
|
|
4
|
+
BaseHighlightPlugin,
|
|
5
|
+
BaseItalicPlugin,
|
|
6
|
+
BaseStrikethroughPlugin,
|
|
7
|
+
BaseSubscriptPlugin,
|
|
8
|
+
BaseSuperscriptPlugin,
|
|
9
|
+
BaseUnderlinePlugin
|
|
10
|
+
} from '@platejs/basic-nodes';
|
|
11
|
+
|
|
12
|
+
import { CodeLeafStatic } from '../../plate-ui/code-node-static';
|
|
13
|
+
import { HighlightLeafStatic } from '../../plate-ui/highlight-node-static';
|
|
14
|
+
|
|
15
|
+
export const BaseBasicMarksKit = [
|
|
16
|
+
BaseBoldPlugin,
|
|
17
|
+
BaseItalicPlugin,
|
|
18
|
+
BaseUnderlinePlugin,
|
|
19
|
+
BaseCodePlugin.withComponent(CodeLeafStatic),
|
|
20
|
+
BaseStrikethroughPlugin,
|
|
21
|
+
BaseSubscriptPlugin,
|
|
22
|
+
BaseSuperscriptPlugin,
|
|
23
|
+
BaseHighlightPlugin.withComponent(HighlightLeafStatic)
|
|
24
|
+
];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
BoldPlugin,
|
|
5
|
+
CodePlugin,
|
|
6
|
+
HighlightPlugin,
|
|
7
|
+
ItalicPlugin,
|
|
8
|
+
StrikethroughPlugin,
|
|
9
|
+
SubscriptPlugin,
|
|
10
|
+
SuperscriptPlugin,
|
|
11
|
+
UnderlinePlugin
|
|
12
|
+
} from '@platejs/basic-nodes/react';
|
|
13
|
+
|
|
14
|
+
import { CodeLeaf } from '../../plate-ui/code-node';
|
|
15
|
+
import { HighlightLeaf } from '../../plate-ui/highlight-node';
|
|
16
|
+
|
|
17
|
+
export const BasicMarksKit = [
|
|
18
|
+
BoldPlugin,
|
|
19
|
+
ItalicPlugin,
|
|
20
|
+
UnderlinePlugin,
|
|
21
|
+
CodePlugin.configure({
|
|
22
|
+
node: { component: CodeLeaf },
|
|
23
|
+
shortcuts: { toggle: { keys: 'mod+e' } }
|
|
24
|
+
}),
|
|
25
|
+
StrikethroughPlugin.configure({
|
|
26
|
+
shortcuts: { toggle: { keys: 'mod+shift+x' } }
|
|
27
|
+
}),
|
|
28
|
+
SubscriptPlugin.configure({
|
|
29
|
+
shortcuts: { toggle: { keys: 'mod+comma' } }
|
|
30
|
+
}),
|
|
31
|
+
SuperscriptPlugin.configure({
|
|
32
|
+
shortcuts: { toggle: { keys: 'mod+period' } }
|
|
33
|
+
}),
|
|
34
|
+
HighlightPlugin.configure({
|
|
35
|
+
node: { component: HighlightLeaf },
|
|
36
|
+
shortcuts: { toggle: { keys: 'mod+shift+h' } }
|
|
37
|
+
})
|
|
38
|
+
];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { BlockMenuPlugin } from '@platejs/selection/react';
|
|
4
|
+
|
|
5
|
+
import { BlockSelectionKit } from './block-selection-kit';
|
|
6
|
+
|
|
7
|
+
import { BlockContextMenu } from '../../plate-ui/block-context-menu';
|
|
8
|
+
|
|
9
|
+
export const BlockMenuKit = [
|
|
10
|
+
...BlockSelectionKit,
|
|
11
|
+
BlockMenuPlugin.configure({
|
|
12
|
+
render: { aboveSlate: BlockContextMenu }
|
|
13
|
+
})
|
|
14
|
+
];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { KEYS } from 'platejs';
|
|
4
|
+
import { BlockPlaceholderPlugin } from 'platejs/react';
|
|
5
|
+
|
|
6
|
+
export const BlockPlaceholderKit = [
|
|
7
|
+
BlockPlaceholderPlugin.configure({
|
|
8
|
+
options: {
|
|
9
|
+
className:
|
|
10
|
+
'before:absolute before:cursor-text before:text-muted-foreground/80 before:content-[attr(placeholder)]',
|
|
11
|
+
placeholders: {
|
|
12
|
+
[KEYS.p]: 'Type a paragraph'
|
|
13
|
+
},
|
|
14
|
+
query: ({ path }: { path: number[] }) => path.length === 1
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { AIChatPlugin } from '@platejs/ai/react';
|
|
4
|
+
import { BlockSelectionPlugin } from '@platejs/selection/react';
|
|
5
|
+
import { getPluginTypes, isHotkey, KEYS } from 'platejs';
|
|
6
|
+
|
|
7
|
+
import { BlockSelection } from '../../plate-ui/block-selection';
|
|
8
|
+
|
|
9
|
+
export const BlockSelectionKit = [
|
|
10
|
+
BlockSelectionPlugin.configure(({ editor }) => ({
|
|
11
|
+
options: {
|
|
12
|
+
enableContextMenu: true,
|
|
13
|
+
isSelectable: element => !getPluginTypes(editor, [KEYS.column, KEYS.codeLine, KEYS.td]).includes(
|
|
14
|
+
element.type
|
|
15
|
+
),
|
|
16
|
+
onKeyDownSelecting: (_editor, e) => {
|
|
17
|
+
if (isHotkey('mod+j')(e)) {
|
|
18
|
+
editor.getApi(AIChatPlugin).aiChat.show();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
render: {
|
|
23
|
+
belowRootNodes: (props) => {
|
|
24
|
+
if (!props.attributes.className?.includes('slate-selectable'))
|
|
25
|
+
return null;
|
|
26
|
+
|
|
27
|
+
return <BlockSelection {...(props as any)} />;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}))
|
|
31
|
+
];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseCodeBlockPlugin,
|
|
3
|
+
BaseCodeLinePlugin,
|
|
4
|
+
BaseCodeSyntaxPlugin
|
|
5
|
+
} from '@platejs/code-block';
|
|
6
|
+
import { all, createLowlight } from 'lowlight';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
CodeBlockElementStatic,
|
|
10
|
+
CodeLineElementStatic,
|
|
11
|
+
CodeSyntaxLeafStatic
|
|
12
|
+
} from '../../plate-ui/code-block-node-static';
|
|
13
|
+
|
|
14
|
+
const lowlight = createLowlight(all);
|
|
15
|
+
|
|
16
|
+
export const BaseCodeBlockKit = [
|
|
17
|
+
BaseCodeBlockPlugin.configure({
|
|
18
|
+
node: { component: CodeBlockElementStatic },
|
|
19
|
+
options: { lowlight }
|
|
20
|
+
}),
|
|
21
|
+
BaseCodeLinePlugin.withComponent(CodeLineElementStatic),
|
|
22
|
+
BaseCodeSyntaxPlugin.withComponent(CodeSyntaxLeafStatic)
|
|
23
|
+
];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
CodeBlockPlugin,
|
|
5
|
+
CodeLinePlugin,
|
|
6
|
+
CodeSyntaxPlugin
|
|
7
|
+
} from '@platejs/code-block/react';
|
|
8
|
+
import { all, createLowlight } from 'lowlight';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
CodeBlockElement,
|
|
12
|
+
CodeLineElement,
|
|
13
|
+
CodeSyntaxLeaf
|
|
14
|
+
} from '../../plate-ui/code-block-node';
|
|
15
|
+
|
|
16
|
+
const lowlight = createLowlight(all);
|
|
17
|
+
|
|
18
|
+
export const CodeBlockKit = [
|
|
19
|
+
CodeBlockPlugin.configure({
|
|
20
|
+
node: { component: CodeBlockElement },
|
|
21
|
+
options: { lowlight },
|
|
22
|
+
shortcuts: { toggle: { keys: 'mod+alt+8' } }
|
|
23
|
+
}),
|
|
24
|
+
CodeLinePlugin.withComponent(CodeLineElement),
|
|
25
|
+
CodeSyntaxPlugin.withComponent(CodeSyntaxLeaf)
|
|
26
|
+
];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseColumnItemPlugin, BaseColumnPlugin } from '@platejs/layout';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ColumnElementStatic,
|
|
5
|
+
ColumnGroupElementStatic
|
|
6
|
+
} from '../../plate-ui/column-node-static';
|
|
7
|
+
|
|
8
|
+
export const BaseColumnKit = [BaseColumnPlugin.withComponent(ColumnGroupElementStatic), BaseColumnItemPlugin.withComponent(ColumnElementStatic)];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { ColumnItemPlugin, ColumnPlugin } from '@platejs/layout/react';
|
|
4
|
+
|
|
5
|
+
import { ColumnElement, ColumnGroupElement } from '../../plate-ui/column-node';
|
|
6
|
+
|
|
7
|
+
export const ColumnKit = [ColumnPlugin.withComponent(ColumnGroupElement), ColumnItemPlugin.withComponent(ColumnElement)];
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type BaseCommentConfig,
|
|
7
|
+
BaseCommentPlugin,
|
|
8
|
+
getDraftCommentKey
|
|
9
|
+
} from '@platejs/comment';
|
|
10
|
+
import {
|
|
11
|
+
type ExtendConfig, type Path, isSlateElement, isSlateString
|
|
12
|
+
} from 'platejs';
|
|
13
|
+
import { toTPlatePlugin, useEditorContainerRef } from 'platejs/react';
|
|
14
|
+
|
|
15
|
+
import { CommentLeaf } from '../../plate-ui/comment-node';
|
|
16
|
+
// import { FloatingDiscussion } from '../../plate-ui/floating-discussion';
|
|
17
|
+
|
|
18
|
+
type CommentConfig = ExtendConfig<
|
|
19
|
+
BaseCommentConfig,
|
|
20
|
+
{
|
|
21
|
+
activeId: string | null;
|
|
22
|
+
commentingBlock: Path | null;
|
|
23
|
+
hoverId: string | null;
|
|
24
|
+
isOverlapWithEditor: boolean;
|
|
25
|
+
uniquePathMap: Map<string, Path>;
|
|
26
|
+
updateTimestamp: number | null;
|
|
27
|
+
}
|
|
28
|
+
>;
|
|
29
|
+
|
|
30
|
+
export const commentPlugin = toTPlatePlugin<CommentConfig>(BaseCommentPlugin, {
|
|
31
|
+
handlers: {
|
|
32
|
+
onClick: ({
|
|
33
|
+
api, event, setOption, type
|
|
34
|
+
}) => {
|
|
35
|
+
let leaf = event.target as HTMLElement;
|
|
36
|
+
let isSet = false;
|
|
37
|
+
|
|
38
|
+
const unsetActiveSuggestion = () => {
|
|
39
|
+
setOption('activeId', null);
|
|
40
|
+
isSet = true;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
if (!isSlateString(leaf)) unsetActiveSuggestion();
|
|
44
|
+
|
|
45
|
+
while (leaf.parentElement && !isSlateElement(leaf.parentElement)) {
|
|
46
|
+
if (leaf.classList.contains(`slate-${type}`)) {
|
|
47
|
+
const commentsEntry = api.comment!.node();
|
|
48
|
+
|
|
49
|
+
if (!commentsEntry) {
|
|
50
|
+
unsetActiveSuggestion();
|
|
51
|
+
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const id = api.comment!.nodeId(commentsEntry[0]) ?? null;
|
|
56
|
+
const isDraft = commentsEntry[0][getDraftCommentKey()];
|
|
57
|
+
|
|
58
|
+
setOption('activeId', isDraft ? getDraftCommentKey() : id);
|
|
59
|
+
isSet = true;
|
|
60
|
+
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
leaf = leaf.parentElement;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!isSet) unsetActiveSuggestion();
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
options: {
|
|
71
|
+
activeId: null,
|
|
72
|
+
commentingBlock: null,
|
|
73
|
+
hoverId: null,
|
|
74
|
+
isOverlapWithEditor: false,
|
|
75
|
+
uniquePathMap: new Map(),
|
|
76
|
+
updateTimestamp: null
|
|
77
|
+
},
|
|
78
|
+
useHooks: ({ editor, setOption }) => {
|
|
79
|
+
const editorContainerRef = useEditorContainerRef();
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (!editorContainerRef.current) return;
|
|
83
|
+
|
|
84
|
+
const editable = editor.api.toDOMNode(editor);
|
|
85
|
+
|
|
86
|
+
if (!editable) return;
|
|
87
|
+
|
|
88
|
+
const observer = new ResizeObserver((entries) => {
|
|
89
|
+
const { width } = entries[0].contentRect;
|
|
90
|
+
const isOverlap = width < 700;
|
|
91
|
+
|
|
92
|
+
setOption('isOverlapWithEditor', isOverlap);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
observer.observe(editable);
|
|
96
|
+
|
|
97
|
+
return () => {
|
|
98
|
+
observer.disconnect();
|
|
99
|
+
};
|
|
100
|
+
}, [editor, editorContainerRef, setOption]);
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
.extendTransforms(
|
|
104
|
+
({
|
|
105
|
+
editor,
|
|
106
|
+
setOption,
|
|
107
|
+
tf: {
|
|
108
|
+
comment: { setDraft }
|
|
109
|
+
}
|
|
110
|
+
}) => ({
|
|
111
|
+
setDraft: () => {
|
|
112
|
+
if (editor.api.isCollapsed()) {
|
|
113
|
+
editor.tf.select(editor.api.block()![1]);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
setDraft();
|
|
117
|
+
|
|
118
|
+
editor.tf.collapse();
|
|
119
|
+
setOption('activeId', getDraftCommentKey());
|
|
120
|
+
setOption('commentingBlock', editor.selection!.focus.path.slice(0, 1));
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
)
|
|
124
|
+
.overrideEditor(
|
|
125
|
+
({
|
|
126
|
+
editor, setOption, tf: { apply, insertBreak }, tf, type
|
|
127
|
+
}) => ({
|
|
128
|
+
transforms: {
|
|
129
|
+
apply(operation) {
|
|
130
|
+
if (
|
|
131
|
+
operation.type !== 'set_selection'
|
|
132
|
+
&& operation.type !== 'set_node'
|
|
133
|
+
&& operation.type !== 'split_node'
|
|
134
|
+
&& operation.type !== 'merge_node'
|
|
135
|
+
) {
|
|
136
|
+
const { newProperties, properties } = operation;
|
|
137
|
+
|
|
138
|
+
if (
|
|
139
|
+
(properties as any)?.[getDraftCommentKey()]
|
|
140
|
+
|| (newProperties as any)?.[getDraftCommentKey()]
|
|
141
|
+
) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
setOption('updateTimestamp', Date.now());
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
apply(operation);
|
|
149
|
+
},
|
|
150
|
+
insertBreak() {
|
|
151
|
+
setOption('updateTimestamp', Date.now());
|
|
152
|
+
|
|
153
|
+
tf.comment.removeMark();
|
|
154
|
+
insertBreak();
|
|
155
|
+
editor.tf.unsetNodes([type], {
|
|
156
|
+
at: editor.selection?.focus,
|
|
157
|
+
mode: 'lowest'
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
)
|
|
163
|
+
.extend({
|
|
164
|
+
shortcuts: {
|
|
165
|
+
setDraft: { keys: 'mod+shift+m' }
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
.configure({
|
|
169
|
+
render: {
|
|
170
|
+
node: CommentLeaf
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
export const CommentKit = [commentPlugin];
|