@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,469 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Fragment, useMemo, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
type TResolvedSuggestion,
|
|
9
|
+
acceptSuggestion,
|
|
10
|
+
getSuggestionKey,
|
|
11
|
+
keyId2SuggestionId,
|
|
12
|
+
rejectSuggestion
|
|
13
|
+
} from '@platejs/suggestion';
|
|
14
|
+
|
|
15
|
+
import { SuggestionPlugin } from '@platejs/suggestion/react';
|
|
16
|
+
import { CheckIcon, XIcon } from 'lucide-react';
|
|
17
|
+
import {
|
|
18
|
+
type NodeEntry,
|
|
19
|
+
type Path,
|
|
20
|
+
type TElement,
|
|
21
|
+
type TSuggestionText,
|
|
22
|
+
ElementApi,
|
|
23
|
+
KEYS,
|
|
24
|
+
PathApi,
|
|
25
|
+
TextApi
|
|
26
|
+
} from 'platejs';
|
|
27
|
+
import { useEditorPlugin, usePluginOption } from 'platejs/react';
|
|
28
|
+
|
|
29
|
+
import { Avatar, AvatarFallback, AvatarImage } from '@docyrus/ui-pro-shared/avatar';
|
|
30
|
+
|
|
31
|
+
import { Button } from './button';
|
|
32
|
+
|
|
33
|
+
import {
|
|
34
|
+
Comment,
|
|
35
|
+
CommentCreateForm,
|
|
36
|
+
formatCommentDate,
|
|
37
|
+
type TComment
|
|
38
|
+
} from './comment';
|
|
39
|
+
|
|
40
|
+
import {
|
|
41
|
+
discussionPlugin,
|
|
42
|
+
type TDiscussion
|
|
43
|
+
} from '../editor/plugins/discussion-kit';
|
|
44
|
+
import { suggestionPlugin } from '../editor/plugins/suggestion-kit';
|
|
45
|
+
|
|
46
|
+
export interface ResolvedSuggestion extends TResolvedSuggestion {
|
|
47
|
+
comments: TComment[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const BLOCK_SUGGESTION = '__block__';
|
|
51
|
+
|
|
52
|
+
export const TYPE_TEXT_MAP: Record<string, (node?: TElement) => string> = {
|
|
53
|
+
[KEYS.audio]: () => 'Audio',
|
|
54
|
+
[KEYS.blockquote]: () => 'Blockquote',
|
|
55
|
+
[KEYS.callout]: () => 'Callout',
|
|
56
|
+
[KEYS.codeBlock]: () => 'Code Block',
|
|
57
|
+
[KEYS.column]: () => 'Column',
|
|
58
|
+
[KEYS.equation]: () => 'Equation',
|
|
59
|
+
[KEYS.file]: () => 'File',
|
|
60
|
+
[KEYS.h1]: () => 'Heading 1',
|
|
61
|
+
[KEYS.h2]: () => 'Heading 2',
|
|
62
|
+
[KEYS.h3]: () => 'Heading 3',
|
|
63
|
+
[KEYS.h4]: () => 'Heading 4',
|
|
64
|
+
[KEYS.h5]: () => 'Heading 5',
|
|
65
|
+
[KEYS.h6]: () => 'Heading 6',
|
|
66
|
+
[KEYS.hr]: () => 'Horizontal Rule',
|
|
67
|
+
[KEYS.img]: () => 'Image',
|
|
68
|
+
[KEYS.mediaEmbed]: () => 'Media',
|
|
69
|
+
[KEYS.p]: (node) => {
|
|
70
|
+
if (node?.[KEYS.listType] === KEYS.listTodo) return 'Todo List';
|
|
71
|
+
if (node?.[KEYS.listType] === KEYS.ol) return 'Ordered List';
|
|
72
|
+
if (node?.[KEYS.listType] === KEYS.ul) return 'List';
|
|
73
|
+
|
|
74
|
+
return 'Paragraph';
|
|
75
|
+
},
|
|
76
|
+
[KEYS.table]: () => 'Table',
|
|
77
|
+
[KEYS.toc]: () => 'Table of Contents',
|
|
78
|
+
[KEYS.toggle]: () => 'Toggle',
|
|
79
|
+
[KEYS.video]: () => 'Video'
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export function BlockSuggestionCard({
|
|
83
|
+
idx,
|
|
84
|
+
isLast,
|
|
85
|
+
suggestion
|
|
86
|
+
}: {
|
|
87
|
+
idx: number;
|
|
88
|
+
isLast: boolean;
|
|
89
|
+
suggestion: ResolvedSuggestion;
|
|
90
|
+
}) {
|
|
91
|
+
const { api, editor } = useEditorPlugin(SuggestionPlugin);
|
|
92
|
+
|
|
93
|
+
const userInfo = usePluginOption(discussionPlugin, 'user', suggestion.userId);
|
|
94
|
+
|
|
95
|
+
const accept = (suggestion: ResolvedSuggestion) => {
|
|
96
|
+
api.suggestion.withoutSuggestions(() => {
|
|
97
|
+
acceptSuggestion(editor, suggestion);
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const reject = (suggestion: ResolvedSuggestion) => {
|
|
102
|
+
api.suggestion.withoutSuggestions(() => {
|
|
103
|
+
rejectSuggestion(editor, suggestion);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const [hovering, setHovering] = useState(false);
|
|
108
|
+
|
|
109
|
+
const suggestionText2Array = (text: string) => {
|
|
110
|
+
if (text === BLOCK_SUGGESTION) return ['line breaks'];
|
|
111
|
+
|
|
112
|
+
return text.split(BLOCK_SUGGESTION).filter(Boolean);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const [editingId, setEditingId] = useState<string | null>(null);
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<div
|
|
119
|
+
key={`${suggestion.suggestionId}-${idx}`}
|
|
120
|
+
className="relative"
|
|
121
|
+
onMouseEnter={() => setHovering(true)}
|
|
122
|
+
onMouseLeave={() => setHovering(false)}>
|
|
123
|
+
<div className="flex flex-col p-4">
|
|
124
|
+
<div className="relative flex items-center">
|
|
125
|
+
{/* Replace to your own backend or refer to potion */}
|
|
126
|
+
<Avatar className="size-5">
|
|
127
|
+
<AvatarImage alt={userInfo?.name} src={userInfo?.avatarUrl} />
|
|
128
|
+
<AvatarFallback>{userInfo?.name?.[0]}</AvatarFallback>
|
|
129
|
+
</Avatar>
|
|
130
|
+
<h4 className="mx-2 font-semibold text-sm leading-none">
|
|
131
|
+
{userInfo?.name}
|
|
132
|
+
</h4>
|
|
133
|
+
<div className="text-muted-foreground/80 text-xs leading-none">
|
|
134
|
+
<span className="mr-1">
|
|
135
|
+
{formatCommentDate(new Date(suggestion.createdAt))}
|
|
136
|
+
</span>
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
<div className="relative mt-1 mb-4 pl-[32px]">
|
|
141
|
+
<div className="flex flex-col gap-2">
|
|
142
|
+
{suggestion.type === 'remove'
|
|
143
|
+
&& suggestionText2Array(suggestion.text!).map((text, index) => (
|
|
144
|
+
<div key={index} className="flex items-center gap-2">
|
|
145
|
+
<span className="text-muted-foreground text-sm">Delete:</span>
|
|
146
|
+
|
|
147
|
+
<span key={index} className="text-sm">
|
|
148
|
+
{text}
|
|
149
|
+
</span>
|
|
150
|
+
</div>
|
|
151
|
+
))}
|
|
152
|
+
|
|
153
|
+
{suggestion.type === 'insert'
|
|
154
|
+
&& suggestionText2Array(suggestion.newText!).map((text, index) => (
|
|
155
|
+
<div key={index} className="flex items-center gap-2">
|
|
156
|
+
<span className="text-muted-foreground text-sm">Add:</span>
|
|
157
|
+
|
|
158
|
+
<span key={index} className="text-sm">
|
|
159
|
+
{text || 'line breaks'}
|
|
160
|
+
</span>
|
|
161
|
+
</div>
|
|
162
|
+
))}
|
|
163
|
+
|
|
164
|
+
{suggestion.type === 'replace' && (
|
|
165
|
+
<div className="flex flex-col gap-2">
|
|
166
|
+
{suggestionText2Array(suggestion.newText!).map(
|
|
167
|
+
(text, index) => (
|
|
168
|
+
<Fragment key={index}>
|
|
169
|
+
<div
|
|
170
|
+
key={index}
|
|
171
|
+
className="flex items-start gap-2 text-brand/80">
|
|
172
|
+
<span className="text-sm">with:</span>
|
|
173
|
+
<span className="text-sm">{text || 'line breaks'}</span>
|
|
174
|
+
</div>
|
|
175
|
+
</Fragment>
|
|
176
|
+
)
|
|
177
|
+
)}
|
|
178
|
+
|
|
179
|
+
{suggestionText2Array(suggestion.text!).map((text, index) => (
|
|
180
|
+
<Fragment key={index}>
|
|
181
|
+
<div key={index} className="flex items-start gap-2">
|
|
182
|
+
<span className="text-muted-foreground text-sm">
|
|
183
|
+
{index === 0 ? 'Replace:' : 'Delete:'}
|
|
184
|
+
</span>
|
|
185
|
+
<span className="text-sm">{text || 'line breaks'}</span>
|
|
186
|
+
</div>
|
|
187
|
+
</Fragment>
|
|
188
|
+
))}
|
|
189
|
+
</div>
|
|
190
|
+
)}
|
|
191
|
+
|
|
192
|
+
{suggestion.type === 'update' && (
|
|
193
|
+
<div className="flex items-center gap-2">
|
|
194
|
+
<span className="text-muted-foreground text-sm">
|
|
195
|
+
{Object.keys(suggestion.properties).map(key => (
|
|
196
|
+
<span key={key}>Un{key}</span>
|
|
197
|
+
))}
|
|
198
|
+
|
|
199
|
+
{Object.keys(suggestion.newProperties).map(key => (
|
|
200
|
+
<span key={key}>
|
|
201
|
+
{key.charAt(0).toUpperCase() + key.slice(1)}
|
|
202
|
+
</span>
|
|
203
|
+
))}
|
|
204
|
+
</span>
|
|
205
|
+
<span className="text-sm">{suggestion.newText}</span>
|
|
206
|
+
</div>
|
|
207
|
+
)}
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
|
|
211
|
+
{suggestion.comments.map((comment, index) => (
|
|
212
|
+
<Comment
|
|
213
|
+
key={comment.id ?? index}
|
|
214
|
+
comment={comment}
|
|
215
|
+
discussionLength={suggestion.comments.length}
|
|
216
|
+
documentContent="__suggestion__"
|
|
217
|
+
editingId={editingId}
|
|
218
|
+
index={index}
|
|
219
|
+
setEditingId={setEditingId} />
|
|
220
|
+
))}
|
|
221
|
+
|
|
222
|
+
{hovering && (
|
|
223
|
+
<div className="absolute top-4 right-4 flex gap-2">
|
|
224
|
+
<Button
|
|
225
|
+
variant="ghost"
|
|
226
|
+
className="size-6 p-1 text-muted-foreground"
|
|
227
|
+
onClick={() => accept(suggestion)}>
|
|
228
|
+
<CheckIcon className="size-4" />
|
|
229
|
+
</Button>
|
|
230
|
+
|
|
231
|
+
<Button
|
|
232
|
+
variant="ghost"
|
|
233
|
+
className="size-6 p-1 text-muted-foreground"
|
|
234
|
+
onClick={() => reject(suggestion)}>
|
|
235
|
+
<XIcon className="size-4" />
|
|
236
|
+
</Button>
|
|
237
|
+
</div>
|
|
238
|
+
)}
|
|
239
|
+
|
|
240
|
+
<CommentCreateForm discussionId={suggestion.suggestionId} />
|
|
241
|
+
</div>
|
|
242
|
+
|
|
243
|
+
{!isLast && <div className="h-px w-full bg-muted" />}
|
|
244
|
+
</div>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export const useResolveSuggestion = (
|
|
249
|
+
suggestionNodes: NodeEntry<TElement | TSuggestionText>[],
|
|
250
|
+
blockPath: Path
|
|
251
|
+
) => {
|
|
252
|
+
const discussions = usePluginOption(discussionPlugin, 'discussions');
|
|
253
|
+
|
|
254
|
+
const {
|
|
255
|
+
api, editor, getOption, setOption
|
|
256
|
+
}
|
|
257
|
+
= useEditorPlugin(suggestionPlugin);
|
|
258
|
+
|
|
259
|
+
suggestionNodes.forEach(([node]) => {
|
|
260
|
+
const id = api.suggestion.nodeId(node);
|
|
261
|
+
const map = getOption('uniquePathMap');
|
|
262
|
+
|
|
263
|
+
if (!id) return;
|
|
264
|
+
|
|
265
|
+
const previousPath = map.get(id);
|
|
266
|
+
|
|
267
|
+
// If there are no suggestion nodes in the corresponding path in the map, then update it.
|
|
268
|
+
if (PathApi.isPath(previousPath)) {
|
|
269
|
+
const nodes = api.suggestion.node({ id, at: previousPath, isText: true });
|
|
270
|
+
const parentNode = api.node(previousPath);
|
|
271
|
+
let lineBreakId: string | null = null;
|
|
272
|
+
|
|
273
|
+
if (parentNode && ElementApi.isElement(parentNode[0])) {
|
|
274
|
+
lineBreakId = api.suggestion.nodeId(parentNode[0]) ?? null;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (!nodes && lineBreakId !== id) {
|
|
278
|
+
setOption('uniquePathMap', new Map(map).set(id, blockPath));
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
setOption('uniquePathMap', new Map(map).set(id, blockPath));
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
const resolvedSuggestion: ResolvedSuggestion[] = useMemo(() => {
|
|
286
|
+
const map = getOption('uniquePathMap');
|
|
287
|
+
|
|
288
|
+
if (suggestionNodes.length === 0) return [];
|
|
289
|
+
|
|
290
|
+
const suggestionIds = new Set(
|
|
291
|
+
suggestionNodes
|
|
292
|
+
.flatMap(([node]) => {
|
|
293
|
+
if (TextApi.isText(node)) {
|
|
294
|
+
const dataList = api.suggestion.dataList(node);
|
|
295
|
+
const includeUpdate = dataList.some(
|
|
296
|
+
data => data.type === 'update'
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
if (!includeUpdate) {
|
|
300
|
+
return api.suggestion.nodeId(node) ?? [];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return dataList
|
|
304
|
+
.filter(data => data.type === 'update')
|
|
305
|
+
.map(d => d.id);
|
|
306
|
+
}
|
|
307
|
+
if (ElementApi.isElement(node)) {
|
|
308
|
+
return api.suggestion.nodeId(node) ?? [];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return [];
|
|
312
|
+
})
|
|
313
|
+
.filter(Boolean)
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
const res: ResolvedSuggestion[] = [];
|
|
317
|
+
|
|
318
|
+
suggestionIds.forEach((id) => {
|
|
319
|
+
if (!id) return;
|
|
320
|
+
|
|
321
|
+
const path = map.get(id);
|
|
322
|
+
|
|
323
|
+
if (!path || !PathApi.isPath(path)) return;
|
|
324
|
+
if (!PathApi.equals(path, blockPath)) return;
|
|
325
|
+
|
|
326
|
+
const entries = [
|
|
327
|
+
...editor.api.nodes<TElement | TSuggestionText>({
|
|
328
|
+
at: [],
|
|
329
|
+
mode: 'all',
|
|
330
|
+
match: n => (n[KEYS.suggestion] && n[getSuggestionKey(id)])
|
|
331
|
+
|| api.suggestion.nodeId(n as TElement) === id
|
|
332
|
+
})
|
|
333
|
+
];
|
|
334
|
+
|
|
335
|
+
// move line break to the end
|
|
336
|
+
entries.sort(([, path1], [, path2]) => PathApi.isChild(path1, path2) ? -1 : 1);
|
|
337
|
+
|
|
338
|
+
let newText = '';
|
|
339
|
+
let text = '';
|
|
340
|
+
let properties: any = {};
|
|
341
|
+
let newProperties: any = {};
|
|
342
|
+
|
|
343
|
+
// overlapping suggestion
|
|
344
|
+
entries.forEach(([node]) => {
|
|
345
|
+
if (TextApi.isText(node)) {
|
|
346
|
+
const dataList = api.suggestion.dataList(node);
|
|
347
|
+
|
|
348
|
+
dataList.forEach((data) => {
|
|
349
|
+
if (data.id === id) {
|
|
350
|
+
switch (data.type) {
|
|
351
|
+
case 'insert': {
|
|
352
|
+
newText += node.text;
|
|
353
|
+
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
case 'remove': {
|
|
358
|
+
text += node.text;
|
|
359
|
+
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
case 'update': {
|
|
364
|
+
properties = {
|
|
365
|
+
...properties,
|
|
366
|
+
...data.properties
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
newProperties = {
|
|
370
|
+
...newProperties,
|
|
371
|
+
...data.newProperties
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
newText += node.text;
|
|
375
|
+
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
// No default
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
} else {
|
|
383
|
+
const lineBreakData = api.suggestion.isBlockSuggestion(node) ? node.suggestion : undefined;
|
|
384
|
+
|
|
385
|
+
if (lineBreakData?.id === keyId2SuggestionId(id)) {
|
|
386
|
+
if (lineBreakData.type === 'insert') {
|
|
387
|
+
newText += lineBreakData.isLineBreak ? BLOCK_SUGGESTION : BLOCK_SUGGESTION + TYPE_TEXT_MAP[node.type](node);
|
|
388
|
+
} else if (lineBreakData.type === 'remove') {
|
|
389
|
+
text += lineBreakData.isLineBreak ? BLOCK_SUGGESTION : BLOCK_SUGGESTION + TYPE_TEXT_MAP[node.type](node);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
if (entries.length === 0) return;
|
|
396
|
+
|
|
397
|
+
const nodeData = api.suggestion.suggestionData(entries[0][0]);
|
|
398
|
+
|
|
399
|
+
if (!nodeData) return;
|
|
400
|
+
|
|
401
|
+
// const comments = data?.discussions.find((d) => d.id === id)?.comments;
|
|
402
|
+
const comments
|
|
403
|
+
= discussions.find((s: TDiscussion) => s.id === id)?.comments || [];
|
|
404
|
+
const createdAt = new Date(nodeData.createdAt);
|
|
405
|
+
|
|
406
|
+
const keyId = getSuggestionKey(id);
|
|
407
|
+
|
|
408
|
+
if (nodeData.type === 'update') {
|
|
409
|
+
res.push({
|
|
410
|
+
comments,
|
|
411
|
+
createdAt,
|
|
412
|
+
keyId,
|
|
413
|
+
newProperties,
|
|
414
|
+
newText,
|
|
415
|
+
properties,
|
|
416
|
+
suggestionId: keyId2SuggestionId(id),
|
|
417
|
+
type: 'update',
|
|
418
|
+
userId: nodeData.userId
|
|
419
|
+
});
|
|
420
|
+
} else if (newText.length > 0 && text.length > 0) {
|
|
421
|
+
res.push({
|
|
422
|
+
comments,
|
|
423
|
+
createdAt,
|
|
424
|
+
keyId,
|
|
425
|
+
newText,
|
|
426
|
+
suggestionId: keyId2SuggestionId(id),
|
|
427
|
+
text,
|
|
428
|
+
type: 'replace',
|
|
429
|
+
userId: nodeData.userId
|
|
430
|
+
});
|
|
431
|
+
} else if (newText.length > 0) {
|
|
432
|
+
res.push({
|
|
433
|
+
comments,
|
|
434
|
+
createdAt,
|
|
435
|
+
keyId,
|
|
436
|
+
newText,
|
|
437
|
+
suggestionId: keyId2SuggestionId(id),
|
|
438
|
+
type: 'insert',
|
|
439
|
+
userId: nodeData.userId
|
|
440
|
+
});
|
|
441
|
+
} else if (text.length > 0) {
|
|
442
|
+
res.push({
|
|
443
|
+
comments,
|
|
444
|
+
createdAt,
|
|
445
|
+
keyId,
|
|
446
|
+
suggestionId: keyId2SuggestionId(id),
|
|
447
|
+
text,
|
|
448
|
+
type: 'remove',
|
|
449
|
+
userId: nodeData.userId
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
return res;
|
|
455
|
+
}, [
|
|
456
|
+
api.suggestion,
|
|
457
|
+
blockPath,
|
|
458
|
+
discussions,
|
|
459
|
+
editor.api,
|
|
460
|
+
getOption,
|
|
461
|
+
suggestionNodes
|
|
462
|
+
]);
|
|
463
|
+
|
|
464
|
+
return resolvedSuggestion;
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
export const isResolvedSuggestion = (
|
|
468
|
+
suggestion: ResolvedSuggestion | TDiscussion
|
|
469
|
+
): suggestion is ResolvedSuggestion => 'suggestionId' in suggestion;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
import { SlateElement, type SlateElementProps } from 'platejs/static';
|
|
3
|
+
|
|
4
|
+
export function BlockquoteElementStatic(props: SlateElementProps) {
|
|
5
|
+
return (
|
|
6
|
+
<SlateElement as="blockquote" className="my-1 px-0.5 py-[3px]" {...props}>
|
|
7
|
+
<div className="border-primary border-l-[3px] px-4">{props.children}</div>
|
|
8
|
+
</SlateElement>
|
|
9
|
+
);
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { PlateElement, type PlateElementProps } from 'platejs/react';
|
|
4
|
+
|
|
5
|
+
export function BlockquoteElement(props: PlateElementProps) {
|
|
6
|
+
return (
|
|
7
|
+
<PlateElement as="blockquote" className="my-1 px-0.5 py-[3px]" {...props}>
|
|
8
|
+
<div className="border-primary border-l-[3px] px-4">{props.children}</div>
|
|
9
|
+
</PlateElement>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type ComponentProps, type ReactNode } from 'react';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
|
|
6
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
7
|
+
import { Slot } from 'radix-ui';
|
|
8
|
+
|
|
9
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
10
|
+
|
|
11
|
+
import { Spinner } from './spinner';
|
|
12
|
+
import { withTooltip } from './tooltip';
|
|
13
|
+
|
|
14
|
+
const SlotRoot = Slot.Root;
|
|
15
|
+
|
|
16
|
+
export const buttonVariants = cva(
|
|
17
|
+
'focus-ring inline-flex w-fit cursor-pointer select-none items-center justify-center gap-2 rounded-md text-sm ring-offset-background transition-bg-ease disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0',
|
|
18
|
+
{
|
|
19
|
+
defaultVariants: {
|
|
20
|
+
size: 'default',
|
|
21
|
+
truncate: true,
|
|
22
|
+
variant: 'default'
|
|
23
|
+
},
|
|
24
|
+
variants: {
|
|
25
|
+
active: {
|
|
26
|
+
false: '',
|
|
27
|
+
true: 'border-2 border-primary'
|
|
28
|
+
},
|
|
29
|
+
disabled: {
|
|
30
|
+
true: 'pointer-events-none opacity-50'
|
|
31
|
+
},
|
|
32
|
+
focused: {
|
|
33
|
+
true: 'ring-2 ring-ring ring-offset-2'
|
|
34
|
+
},
|
|
35
|
+
isMenu: {
|
|
36
|
+
true: 'h-auto w-full cursor-pointer justify-start'
|
|
37
|
+
},
|
|
38
|
+
size: {
|
|
39
|
+
blockAction: 'size-[26px] gap-1 px-1.5 text-xs',
|
|
40
|
+
default: 'h-[28px] gap-1.5 px-2',
|
|
41
|
+
icon: 'size-[28px] w-[33px] [&_svg]:size-5',
|
|
42
|
+
iconSm: 'size-[28px]',
|
|
43
|
+
lg: 'h-11 px-4 text-lg',
|
|
44
|
+
md: 'h-8 px-3',
|
|
45
|
+
menuAction: 'size-6',
|
|
46
|
+
navAction: 'size-5',
|
|
47
|
+
none: '',
|
|
48
|
+
xs: 'h-[26px] px-1.5 py-1 text-xs'
|
|
49
|
+
},
|
|
50
|
+
truncate: {
|
|
51
|
+
true: 'truncate whitespace-nowrap'
|
|
52
|
+
},
|
|
53
|
+
variant: {
|
|
54
|
+
blockAction:
|
|
55
|
+
'rounded-sm hover:bg-primary/6 [&_svg]:text-muted-foreground',
|
|
56
|
+
blockActionSecondary:
|
|
57
|
+
'rounded-sm bg-primary/6 [&_svg]:text-muted-foreground',
|
|
58
|
+
brand:
|
|
59
|
+
'bg-brand font-medium text-white hover:bg-brand/80 active:bg-brand-active',
|
|
60
|
+
default:
|
|
61
|
+
'bg-primary font-medium text-primary-foreground hover:bg-primary/90 [&_svg]:text-primary-foreground',
|
|
62
|
+
destructive:
|
|
63
|
+
'bg-destructive text-destructive-foreground hover:bg-destructive/90 [&_svg]:text-destructive-foreground',
|
|
64
|
+
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
|
65
|
+
ghost2: 'text-muted-foreground hover:bg-accent',
|
|
66
|
+
ghost3: 'text-muted-foreground/80 hover:bg-accent',
|
|
67
|
+
ghostActive: 'bg-accent hover:bg-accent hover:text-accent-foreground',
|
|
68
|
+
menuAction: 'text-muted-foreground/80 hover:bg-primary/6',
|
|
69
|
+
nav: 'rounded-sm text-muted-foreground transition hover:bg-primary/4',
|
|
70
|
+
navAction:
|
|
71
|
+
'rounded-sm text-muted-foreground/80 opacity-0 transition hover:bg-primary/6 group-hover:opacity-100',
|
|
72
|
+
none: '',
|
|
73
|
+
outline:
|
|
74
|
+
'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
|
|
75
|
+
primaryOutline:
|
|
76
|
+
'border border-primary-foreground text-primary-foreground hover:bg-accent/15 [&_svg]:text-primary-foreground',
|
|
77
|
+
radio: 'border-2 border-input hover:border-primary',
|
|
78
|
+
secondary:
|
|
79
|
+
'bg-secondary text-secondary-foreground hover:bg-secondary/80'
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
export type ButtonExtendedProps = {
|
|
86
|
+
active?: boolean;
|
|
87
|
+
asChild?: boolean;
|
|
88
|
+
icon?: ReactNode;
|
|
89
|
+
iconPlacement?: 'left' | 'right';
|
|
90
|
+
isPending?: boolean;
|
|
91
|
+
loading?: boolean;
|
|
92
|
+
loadingClassName?: string;
|
|
93
|
+
onToggleClick?: () => void;
|
|
94
|
+
} & {
|
|
95
|
+
children?: ReactNode;
|
|
96
|
+
label?: string;
|
|
97
|
+
} & VariantProps<typeof buttonVariants>;
|
|
98
|
+
|
|
99
|
+
export type ButtonProps = ComponentProps<typeof Button>;
|
|
100
|
+
|
|
101
|
+
export const Button = withTooltip(({
|
|
102
|
+
active,
|
|
103
|
+
asChild = false,
|
|
104
|
+
children,
|
|
105
|
+
className,
|
|
106
|
+
focused,
|
|
107
|
+
icon,
|
|
108
|
+
iconPlacement = 'left',
|
|
109
|
+
isMenu,
|
|
110
|
+
isPending: _isPending,
|
|
111
|
+
label,
|
|
112
|
+
loading,
|
|
113
|
+
loadingClassName,
|
|
114
|
+
size,
|
|
115
|
+
truncate,
|
|
116
|
+
variant,
|
|
117
|
+
onToggleClick: _onToggleClick,
|
|
118
|
+
...props
|
|
119
|
+
}: ButtonExtendedProps & ComponentProps<'button'>) => {
|
|
120
|
+
const Comp = asChild ? SlotRoot : 'button';
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<Comp
|
|
124
|
+
aria-label={label && label.length > 0 ? label : undefined}
|
|
125
|
+
className={cn(
|
|
126
|
+
buttonVariants({
|
|
127
|
+
disabled: props.disabled,
|
|
128
|
+
focused,
|
|
129
|
+
isMenu,
|
|
130
|
+
size,
|
|
131
|
+
truncate,
|
|
132
|
+
variant
|
|
133
|
+
}),
|
|
134
|
+
active && 'border-2 border-primary',
|
|
135
|
+
className
|
|
136
|
+
)}
|
|
137
|
+
type={Comp === 'button' ? 'button' : undefined}
|
|
138
|
+
{...props}>
|
|
139
|
+
{icon && iconPlacement === 'left' && icon}
|
|
140
|
+
{loading && <Spinner className={loadingClassName} />}
|
|
141
|
+
{children}
|
|
142
|
+
{icon && iconPlacement === 'right' && icon}
|
|
143
|
+
</Comp>
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
export type LinkButtonProps = ComponentProps<typeof LinkButton>;
|
|
148
|
+
|
|
149
|
+
export const LinkButton = withTooltip(({
|
|
150
|
+
active,
|
|
151
|
+
children,
|
|
152
|
+
className,
|
|
153
|
+
focused,
|
|
154
|
+
icon,
|
|
155
|
+
iconPlacement = 'left',
|
|
156
|
+
isMenu,
|
|
157
|
+
label,
|
|
158
|
+
loading,
|
|
159
|
+
loadingClassName,
|
|
160
|
+
size,
|
|
161
|
+
truncate,
|
|
162
|
+
variant = 'ghost',
|
|
163
|
+
...props
|
|
164
|
+
}: ButtonExtendedProps & ComponentProps<'a'>) => {
|
|
165
|
+
return (
|
|
166
|
+
<a
|
|
167
|
+
aria-label={label && label.length > 0 ? label : undefined}
|
|
168
|
+
className={cn(
|
|
169
|
+
buttonVariants({
|
|
170
|
+
disabled: props.disabled,
|
|
171
|
+
focused,
|
|
172
|
+
isMenu,
|
|
173
|
+
size,
|
|
174
|
+
truncate,
|
|
175
|
+
variant
|
|
176
|
+
}),
|
|
177
|
+
active && 'border-2 border-primary',
|
|
178
|
+
className
|
|
179
|
+
)}
|
|
180
|
+
role="button"
|
|
181
|
+
{...props}>
|
|
182
|
+
{icon && iconPlacement === 'left' && (
|
|
183
|
+
<div className="shrink-0">{icon}</div>
|
|
184
|
+
)}
|
|
185
|
+
{loading && <Spinner className={loadingClassName} />}
|
|
186
|
+
{children}
|
|
187
|
+
{icon && iconPlacement === 'right' && icon}
|
|
188
|
+
</a>
|
|
189
|
+
);
|
|
190
|
+
});
|