@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,88 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
|
|
5
|
+
import { FileSpreadsheet, Loader2 } from 'lucide-react';
|
|
6
|
+
import { Card } from '@docyrus/ui-pro-shared/components/card';
|
|
7
|
+
|
|
8
|
+
interface SheetCommandProps {
|
|
9
|
+
commands?: any[];
|
|
10
|
+
state?: string;
|
|
11
|
+
toolCallId?: string;
|
|
12
|
+
workId?: string;
|
|
13
|
+
onAutoRespond?: (commands: any[]) => void;
|
|
14
|
+
onSendSpreadsheetCommands?: (commands: any[]) => void;
|
|
15
|
+
openCanvasView?: (options: any) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function SheetCommand({
|
|
19
|
+
commands,
|
|
20
|
+
state,
|
|
21
|
+
toolCallId,
|
|
22
|
+
workId,
|
|
23
|
+
onAutoRespond,
|
|
24
|
+
onSendSpreadsheetCommands: _onSendSpreadsheetCommands,
|
|
25
|
+
openCanvasView
|
|
26
|
+
}: SheetCommandProps) {
|
|
27
|
+
const hasRespondedRef = useRef(false);
|
|
28
|
+
const commandCount = commands?.length ?? 0;
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (
|
|
32
|
+
state === 'input-available'
|
|
33
|
+
&& commands && commands.length > 0
|
|
34
|
+
&& toolCallId
|
|
35
|
+
&& !hasRespondedRef.current
|
|
36
|
+
) {
|
|
37
|
+
hasRespondedRef.current = true;
|
|
38
|
+
|
|
39
|
+
// Execute commands on the already-open UniverSheets via postMessage
|
|
40
|
+
for (const cmd of commands) {
|
|
41
|
+
window.postMessage(
|
|
42
|
+
{ type: 'event', eventName: 'api:call', payload: cmd },
|
|
43
|
+
'*'
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Keep canvas visible
|
|
48
|
+
openCanvasView?.({
|
|
49
|
+
type: 'xlsx',
|
|
50
|
+
id: workId,
|
|
51
|
+
workId,
|
|
52
|
+
title: 'Spreadsheet',
|
|
53
|
+
commands
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
onAutoRespond?.(commands);
|
|
57
|
+
}
|
|
58
|
+
}, [
|
|
59
|
+
state,
|
|
60
|
+
commands,
|
|
61
|
+
toolCallId,
|
|
62
|
+
workId,
|
|
63
|
+
openCanvasView,
|
|
64
|
+
onAutoRespond
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div className="flex flex-row items-center space-x-4">
|
|
69
|
+
<Card className="p-4 flex flex-col space-y-2 w-fit min-w-80 max-w-96 shadow-sm">
|
|
70
|
+
<div className="flex items-start space-x-2">
|
|
71
|
+
<div className="flex-none p-2 bg-slate-50 rounded">
|
|
72
|
+
<FileSpreadsheet className="size-8 text-muted-foreground" />
|
|
73
|
+
</div>
|
|
74
|
+
<div className="grow space-y-1 min-w-0">
|
|
75
|
+
<div className="font-medium text-base">Spreadsheet Commands</div>
|
|
76
|
+
<p className="text-sm text-muted-foreground">
|
|
77
|
+
{commandCount} command{commandCount !== 1 ? 's' : ''} to execute
|
|
78
|
+
</p>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
</Card>
|
|
82
|
+
|
|
83
|
+
{(state === 'input-streaming' || state === 'input-available') && (
|
|
84
|
+
<Loader2 className="size-8 animate-spin text-primary flex-none" />
|
|
85
|
+
)}
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
|
|
5
|
+
import { useApiClient } from '../lib/api-client';
|
|
6
|
+
|
|
7
|
+
const ALLOWED_ORIGINS = ['https://shell.docy.work', 'https://shell-docyrus.web.app'];
|
|
8
|
+
|
|
9
|
+
interface ShellCanvasUser {
|
|
10
|
+
id?: string;
|
|
11
|
+
email?: string;
|
|
12
|
+
firstname?: string;
|
|
13
|
+
lastname?: string;
|
|
14
|
+
photo?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface ShellCanvasProps {
|
|
18
|
+
workId: string;
|
|
19
|
+
versionId?: string | null;
|
|
20
|
+
title?: string;
|
|
21
|
+
user?: ShellCanvasUser;
|
|
22
|
+
onSendToChat?: (message: string) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function ShellCanvas({
|
|
26
|
+
workId, versionId, title, user, onSendToChat
|
|
27
|
+
}: ShellCanvasProps) {
|
|
28
|
+
const src = `https://shell.docy.work?work=${workId}${versionId ? `&versionId=${versionId}` : ''}`;
|
|
29
|
+
const apiClient = useApiClient();
|
|
30
|
+
const onSendToChatRef = useRef(onSendToChat);
|
|
31
|
+
|
|
32
|
+
onSendToChatRef.current = onSendToChat;
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const api: Record<string, (...args: any[]) => unknown> = {
|
|
36
|
+
getUser: () => user ?? {},
|
|
37
|
+
getTenant: () => ({}),
|
|
38
|
+
getRecord: async (appSlug: string, dataSourceSlug: string, recordId: string, options: any = {}) => {
|
|
39
|
+
const params: Record<string, unknown> = {};
|
|
40
|
+
|
|
41
|
+
if (options.columns) params.columns = options.columns;
|
|
42
|
+
|
|
43
|
+
return apiClient.get(`apps/${appSlug}/data-sources/${dataSourceSlug}/items/${recordId}`, params);
|
|
44
|
+
},
|
|
45
|
+
getRecords: async (appSlug: string, dataSourceSlug: string, options: any = {}) => {
|
|
46
|
+
const params: Record<string, unknown> = {};
|
|
47
|
+
|
|
48
|
+
[
|
|
49
|
+
'columns',
|
|
50
|
+
'limit',
|
|
51
|
+
'offset',
|
|
52
|
+
'orderBy',
|
|
53
|
+
'orderByDirection',
|
|
54
|
+
'filters',
|
|
55
|
+
'pivot'
|
|
56
|
+
].forEach((k) => {
|
|
57
|
+
if (options[k] !== undefined) params[k] = options[k];
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return apiClient.get(`apps/${appSlug}/data-sources/${dataSourceSlug}/items`, params);
|
|
61
|
+
},
|
|
62
|
+
insertRecord: (appSlug: string, dataSourceSlug: string, data: unknown) => apiClient.post(`apps/${appSlug}/data-sources/${dataSourceSlug}/items`, data),
|
|
63
|
+
updateRecord: (appSlug: string, dataSourceSlug: string, recordId: string, data: unknown) => apiClient.patch(`apps/${appSlug}/data-sources/${dataSourceSlug}/items/${recordId}`, data),
|
|
64
|
+
deleteRecord: (appSlug: string, dataSourceSlug: string, recordId: string) => apiClient.delete(`apps/${appSlug}/data-sources/${dataSourceSlug}/items/${recordId}`),
|
|
65
|
+
viewRecord: async () => {},
|
|
66
|
+
runAggregateQuery: (appSlug: string, dataSourceSlug: string, rows: unknown, calculations: unknown) => apiClient.get(`apps/${appSlug}/data-sources/${dataSourceSlug}/items`, { rows, calculations } as any),
|
|
67
|
+
runCustomQuery: (customQueryId: string, options: unknown) => apiClient.put(`reports/runCustomQuery/${customQueryId}`, options),
|
|
68
|
+
sendToChat: (message: string) => { onSendToChatRef.current?.(message); },
|
|
69
|
+
list: (...args: any[]) => apiClient.get(args[0], args[1]),
|
|
70
|
+
get: (...args: any[]) => apiClient.get(args[0], args[1]),
|
|
71
|
+
post: (...args: any[]) => apiClient.post(args[0], args[1]),
|
|
72
|
+
put: (...args: any[]) => apiClient.put(args[0], args[1]),
|
|
73
|
+
patch: (...args: any[]) => apiClient.patch(args[0], args[1]),
|
|
74
|
+
delete: (...args: any[]) => apiClient.delete(args[0])
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const handleMessage = async (event: MessageEvent) => {
|
|
78
|
+
if (!ALLOWED_ORIGINS.includes(event.origin)) return;
|
|
79
|
+
|
|
80
|
+
const { type, id } = event.data ?? {};
|
|
81
|
+
|
|
82
|
+
if (type === 'handshake') {
|
|
83
|
+
(event.source as Window)?.postMessage(
|
|
84
|
+
{
|
|
85
|
+
type: 'handshake_ack',
|
|
86
|
+
id,
|
|
87
|
+
sessionId: crypto.randomUUID(),
|
|
88
|
+
allowedMethods: Object.keys(api)
|
|
89
|
+
},
|
|
90
|
+
event.origin
|
|
91
|
+
);
|
|
92
|
+
} else if (type === 'rpc') {
|
|
93
|
+
const { method, params = [] } = event.data;
|
|
94
|
+
|
|
95
|
+
if (!Object.prototype.hasOwnProperty.call(api, method)) return;
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
const result = await (api[method] as any)(...params);
|
|
99
|
+
|
|
100
|
+
(event.source as Window)?.postMessage({ type: 'rpc_response', id, result }, event.origin);
|
|
101
|
+
} catch (err: any) {
|
|
102
|
+
(event.source as Window)?.postMessage(
|
|
103
|
+
{ type: 'rpc_response', id, error: err?.message ?? 'Unknown error' },
|
|
104
|
+
event.origin
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
window.addEventListener('message', handleMessage);
|
|
111
|
+
|
|
112
|
+
return () => window.removeEventListener('message', handleMessage);
|
|
113
|
+
}, [apiClient, user]);
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<iframe
|
|
117
|
+
src={src}
|
|
118
|
+
title={title}
|
|
119
|
+
className="w-full h-full border-0"
|
|
120
|
+
sandbox="allow-scripts allow-same-origin allow-downloads allow-modals allow-forms allow-presentation allow-top-navigation-by-user-activation allow-popups" />
|
|
121
|
+
);
|
|
122
|
+
}
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useCallback, useEffect, useMemo, useRef, useState
|
|
5
|
+
} from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
ChevronDown, Download, FileSpreadsheet, FileText
|
|
9
|
+
} from 'lucide-react';
|
|
10
|
+
|
|
11
|
+
import { Button } from '@docyrus/ui-pro-shared/components/button';
|
|
12
|
+
import {
|
|
13
|
+
DropdownMenu,
|
|
14
|
+
DropdownMenuContent,
|
|
15
|
+
DropdownMenuItem,
|
|
16
|
+
DropdownMenuTrigger
|
|
17
|
+
} from '@docyrus/ui-pro-shared/components/dropdown-menu';
|
|
18
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
19
|
+
|
|
20
|
+
interface ColumnFormat {
|
|
21
|
+
formatter: 'number' | 'percent' | 'currency' | 'date' | 'datetime';
|
|
22
|
+
format?: Record<string, any> | string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface Column {
|
|
26
|
+
name?: string;
|
|
27
|
+
field?: string;
|
|
28
|
+
title?: string;
|
|
29
|
+
label?: string;
|
|
30
|
+
width?: number;
|
|
31
|
+
align?: 'left' | 'center' | 'right';
|
|
32
|
+
format?: ColumnFormat;
|
|
33
|
+
sortable?: boolean;
|
|
34
|
+
minWidth?: number;
|
|
35
|
+
maxWidth?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface ShowAdvancedDataTableProps {
|
|
39
|
+
title?: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
additionalComments?: string | null;
|
|
42
|
+
state?: string;
|
|
43
|
+
errorText?: string;
|
|
44
|
+
data?: string;
|
|
45
|
+
columns?: Column[];
|
|
46
|
+
enableTree?: boolean;
|
|
47
|
+
treeChildrenField?: string;
|
|
48
|
+
sortable?: boolean;
|
|
49
|
+
defaultRowHeight?: number;
|
|
50
|
+
defaultHeaderRowHeight?: number;
|
|
51
|
+
defaultColWidth?: number;
|
|
52
|
+
height?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const formatCellValue = (value: any, formatConfig?: ColumnFormat): string => {
|
|
56
|
+
if (value === null || value === undefined) return '-';
|
|
57
|
+
if (!formatConfig?.formatter) return String(value);
|
|
58
|
+
|
|
59
|
+
const { formatter, format } = formatConfig;
|
|
60
|
+
const fmt = typeof format === 'string' ? JSON.parse(format) : (format ?? {});
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
switch (formatter) {
|
|
64
|
+
case 'number': {
|
|
65
|
+
const num = typeof value === 'string' ? parseFloat(value) : value;
|
|
66
|
+
|
|
67
|
+
if (typeof num !== 'number' || isNaN(num)) return String(value);
|
|
68
|
+
const { thousandsSeparator = ',', decimalsSeparator = '.', decimalPlaces = 2 } = fmt;
|
|
69
|
+
const fixed = num.toFixed(decimalPlaces);
|
|
70
|
+
const [intPart, decPart] = fixed.split('.');
|
|
71
|
+
const formattedInt = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, thousandsSeparator);
|
|
72
|
+
|
|
73
|
+
return decPart ? `${formattedInt}${decimalsSeparator}${decPart}` : formattedInt;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
case 'percent': {
|
|
77
|
+
const num = typeof value === 'string' ? parseFloat(value) : value;
|
|
78
|
+
|
|
79
|
+
if (typeof num !== 'number' || isNaN(num)) return String(value);
|
|
80
|
+
|
|
81
|
+
return `${(num * 100).toFixed(fmt.decimalPlaces ?? 2)}%`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
case 'currency': {
|
|
85
|
+
const num = typeof value === 'string' ? parseFloat(value) : value;
|
|
86
|
+
|
|
87
|
+
if (typeof num !== 'number' || isNaN(num)) return String(value);
|
|
88
|
+
|
|
89
|
+
return `${fmt.symbol ?? '$'}${num.toFixed(2)}`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
case 'date': {
|
|
93
|
+
const d = new Date(value);
|
|
94
|
+
|
|
95
|
+
if (isNaN(d.getTime())) return String(value);
|
|
96
|
+
|
|
97
|
+
return d.toISOString().split('T')[0];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
case 'datetime': {
|
|
101
|
+
const d = new Date(value);
|
|
102
|
+
|
|
103
|
+
if (isNaN(d.getTime())) return String(value);
|
|
104
|
+
const iso = d.toISOString();
|
|
105
|
+
|
|
106
|
+
return `${iso.split('T')[0]} ${iso.split('T')[1].slice(0, 5)}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
default:
|
|
110
|
+
return String(value);
|
|
111
|
+
}
|
|
112
|
+
} catch {
|
|
113
|
+
return String(value);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export function ShowAdvancedDataTable({
|
|
118
|
+
title = 'Data Table',
|
|
119
|
+
description,
|
|
120
|
+
additionalComments,
|
|
121
|
+
state,
|
|
122
|
+
errorText,
|
|
123
|
+
data,
|
|
124
|
+
columns = [],
|
|
125
|
+
enableTree = false,
|
|
126
|
+
treeChildrenField = 'children',
|
|
127
|
+
sortable = true,
|
|
128
|
+
defaultRowHeight = 40,
|
|
129
|
+
defaultHeaderRowHeight = 40,
|
|
130
|
+
defaultColWidth = 150,
|
|
131
|
+
height = 500
|
|
132
|
+
}: ShowAdvancedDataTableProps) {
|
|
133
|
+
const [open, setOpen] = useState(true);
|
|
134
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
135
|
+
const tableRef = useRef<any>(null);
|
|
136
|
+
|
|
137
|
+
const parsedData = useMemo(() => {
|
|
138
|
+
if (!data) return [];
|
|
139
|
+
try {
|
|
140
|
+
const parsed = JSON.parse(data);
|
|
141
|
+
|
|
142
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
143
|
+
} catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}, [data]);
|
|
147
|
+
|
|
148
|
+
const parseError = useMemo(() => {
|
|
149
|
+
if (!data) return null;
|
|
150
|
+
try {
|
|
151
|
+
JSON.parse(data);
|
|
152
|
+
|
|
153
|
+
return null;
|
|
154
|
+
} catch (e: any) {
|
|
155
|
+
return e.message as string;
|
|
156
|
+
}
|
|
157
|
+
}, [data]);
|
|
158
|
+
|
|
159
|
+
const vtableColumns = useMemo(() => {
|
|
160
|
+
return columns.map((col) => {
|
|
161
|
+
const field = col.field ?? col.name ?? '';
|
|
162
|
+
const column: Record<string, any> = {
|
|
163
|
+
field,
|
|
164
|
+
title: col.title ?? col.label ?? field
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
if (col.width) column.width = typeof col.width === 'string' ? parseInt(col.width) : col.width;
|
|
168
|
+
if (col.minWidth) column.minWidth = col.minWidth;
|
|
169
|
+
if (col.maxWidth) column.maxWidth = col.maxWidth;
|
|
170
|
+
column.sort = col.sortable !== undefined ? col.sortable : sortable;
|
|
171
|
+
if (col.align) {
|
|
172
|
+
column.headerStyle = { textAlign: col.align };
|
|
173
|
+
column.style = { textAlign: col.align };
|
|
174
|
+
}
|
|
175
|
+
if (col.format?.formatter) {
|
|
176
|
+
column.format = (value: any) => formatCellValue(value, col.format);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return column;
|
|
180
|
+
});
|
|
181
|
+
}, [columns, sortable]);
|
|
182
|
+
|
|
183
|
+
const initTable = useCallback(async () => {
|
|
184
|
+
if (!containerRef.current || !parsedData || parsedData.length === 0) return;
|
|
185
|
+
|
|
186
|
+
// Ensure container has dimensions
|
|
187
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
188
|
+
|
|
189
|
+
if (rect.width === 0) return;
|
|
190
|
+
|
|
191
|
+
try {
|
|
192
|
+
const VTable = await import('@visactor/vtable');
|
|
193
|
+
|
|
194
|
+
if (tableRef.current) {
|
|
195
|
+
tableRef.current.release();
|
|
196
|
+
tableRef.current = null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const options: Record<string, any> = {
|
|
200
|
+
container: containerRef.current,
|
|
201
|
+
records: parsedData,
|
|
202
|
+
columns: vtableColumns,
|
|
203
|
+
defaultRowHeight,
|
|
204
|
+
defaultHeaderRowHeight,
|
|
205
|
+
defaultColWidth,
|
|
206
|
+
widthMode: 'standard',
|
|
207
|
+
height,
|
|
208
|
+
animationAppear: false
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
if (enableTree) {
|
|
212
|
+
options.tree = { children: treeChildrenField, defaultOpenLevel: 1 };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
tableRef.current = new VTable.ListTable(options);
|
|
216
|
+
} catch (err) {
|
|
217
|
+
console.error('Failed to initialize VTable:', err);
|
|
218
|
+
}
|
|
219
|
+
}, [
|
|
220
|
+
parsedData,
|
|
221
|
+
vtableColumns,
|
|
222
|
+
defaultRowHeight,
|
|
223
|
+
defaultHeaderRowHeight,
|
|
224
|
+
defaultColWidth,
|
|
225
|
+
height,
|
|
226
|
+
enableTree,
|
|
227
|
+
treeChildrenField
|
|
228
|
+
]);
|
|
229
|
+
|
|
230
|
+
useEffect(() => {
|
|
231
|
+
if (state !== 'output-available' || !open) return;
|
|
232
|
+
|
|
233
|
+
// First attempt after short delay for layout
|
|
234
|
+
const t1 = setTimeout(() => initTable(), 150);
|
|
235
|
+
|
|
236
|
+
// Retry via ResizeObserver in case container has no dimensions yet
|
|
237
|
+
const observer = new ResizeObserver((entries) => {
|
|
238
|
+
const entry = entries[0];
|
|
239
|
+
|
|
240
|
+
if (entry && entry.contentRect.width > 0 && !tableRef.current) {
|
|
241
|
+
initTable();
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
if (containerRef.current) {
|
|
246
|
+
observer.observe(containerRef.current);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return () => {
|
|
250
|
+
clearTimeout(t1);
|
|
251
|
+
observer.disconnect();
|
|
252
|
+
};
|
|
253
|
+
}, [state, open, initTable]);
|
|
254
|
+
|
|
255
|
+
useEffect(() => {
|
|
256
|
+
return () => {
|
|
257
|
+
if (tableRef.current) {
|
|
258
|
+
tableRef.current.release();
|
|
259
|
+
tableRef.current = null;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}, []);
|
|
263
|
+
|
|
264
|
+
const handleDownload = useCallback(async (type: 'csv' | 'xlsx') => {
|
|
265
|
+
if (!tableRef.current) return;
|
|
266
|
+
const fileName = title;
|
|
267
|
+
|
|
268
|
+
if (type === 'csv') {
|
|
269
|
+
tableRef.current.exportToCsv?.({ fileName: `${fileName}.csv`, downloadFile: true, exportAllData: true });
|
|
270
|
+
} else {
|
|
271
|
+
tableRef.current.exportToExcel?.({
|
|
272
|
+
fileName: `${fileName}.xlsx`, downloadFile: true, exportAllData: true, ignoreIcon: true
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}, [title]);
|
|
276
|
+
|
|
277
|
+
return (
|
|
278
|
+
<div className="rounded-xl shadow bg-card border overflow-hidden">
|
|
279
|
+
{/* Header */}
|
|
280
|
+
<div
|
|
281
|
+
role="button"
|
|
282
|
+
tabIndex={0}
|
|
283
|
+
onClick={() => setOpen(v => !v)}
|
|
284
|
+
onKeyDown={e => (e.key === 'Enter' || e.key === ' ') && setOpen(v => !v)}
|
|
285
|
+
className="flex w-full items-center justify-between gap-1.5 px-4 py-3 text-left bg-muted/50 hover:bg-muted transition-colors cursor-pointer select-none">
|
|
286
|
+
<div className="flex items-center gap-2 grow min-w-0">
|
|
287
|
+
<span className="font-medium text-sm truncate">{title}</span>
|
|
288
|
+
{description && (
|
|
289
|
+
<span className="text-xs text-muted-foreground truncate hidden sm:block">{description}</span>
|
|
290
|
+
)}
|
|
291
|
+
</div>
|
|
292
|
+
<div className="flex items-center gap-1 shrink-0">
|
|
293
|
+
<DropdownMenu>
|
|
294
|
+
<DropdownMenuTrigger asChild>
|
|
295
|
+
<Button
|
|
296
|
+
variant="ghost"
|
|
297
|
+
size="icon"
|
|
298
|
+
className="h-7 w-7"
|
|
299
|
+
onClick={e => e.stopPropagation()}>
|
|
300
|
+
<Download className="size-3.5" />
|
|
301
|
+
</Button>
|
|
302
|
+
</DropdownMenuTrigger>
|
|
303
|
+
<DropdownMenuContent align="end">
|
|
304
|
+
<DropdownMenuItem onClick={() => handleDownload('csv')}>
|
|
305
|
+
<FileText className="size-4 mr-2" />
|
|
306
|
+
Download as CSV
|
|
307
|
+
</DropdownMenuItem>
|
|
308
|
+
<DropdownMenuItem onClick={() => handleDownload('xlsx')}>
|
|
309
|
+
<FileSpreadsheet className="size-4 mr-2" />
|
|
310
|
+
Download as XLSX
|
|
311
|
+
</DropdownMenuItem>
|
|
312
|
+
</DropdownMenuContent>
|
|
313
|
+
</DropdownMenu>
|
|
314
|
+
<ChevronDown className={cn('size-4 text-muted-foreground transition-transform', open && 'rotate-180')} />
|
|
315
|
+
</div>
|
|
316
|
+
</div>
|
|
317
|
+
|
|
318
|
+
{/* Body — always in DOM so VTable container keeps its ref */}
|
|
319
|
+
<div className={cn('p-4', !open && 'hidden')}>
|
|
320
|
+
{state !== 'output-available' && !parseError && (
|
|
321
|
+
<div className="w-full h-[200px] rounded-lg bg-muted/30 animate-pulse" />
|
|
322
|
+
)}
|
|
323
|
+
{parseError && (
|
|
324
|
+
<div className="text-sm text-destructive bg-destructive/10 border border-destructive/20 rounded-lg p-3">
|
|
325
|
+
<div className="font-medium">Error parsing data</div>
|
|
326
|
+
<div className="text-xs mt-1">{parseError}</div>
|
|
327
|
+
</div>
|
|
328
|
+
)}
|
|
329
|
+
{errorText && !parseError && (
|
|
330
|
+
<div className="text-sm text-destructive bg-destructive/10 border border-destructive/20 rounded-lg p-3">
|
|
331
|
+
{errorText}
|
|
332
|
+
</div>
|
|
333
|
+
)}
|
|
334
|
+
{state === 'output-available' && !parseError && parsedData && parsedData.length === 0 && (
|
|
335
|
+
<div className="text-sm text-muted-foreground text-center py-6">No data to display</div>
|
|
336
|
+
)}
|
|
337
|
+
<div ref={containerRef} className="w-full rounded-lg" style={{ height: `${height}px` }} />
|
|
338
|
+
{state === 'output-available' && parsedData && parsedData.length > 0 && (
|
|
339
|
+
<div className="text-xs text-muted-foreground mt-2">
|
|
340
|
+
{parsedData.length} {parsedData.length === 1 ? 'row' : 'rows'}
|
|
341
|
+
</div>
|
|
342
|
+
)}
|
|
343
|
+
{additionalComments && (
|
|
344
|
+
<div className="mt-4 text-sm bg-blue-50 border border-blue-200 rounded-lg p-3 dark:bg-blue-950/30 dark:border-blue-800">
|
|
345
|
+
<div className="font-medium text-blue-900 dark:text-blue-300 mb-1">Note</div>
|
|
346
|
+
<div className="text-blue-800 dark:text-blue-400">{additionalComments}</div>
|
|
347
|
+
</div>
|
|
348
|
+
)}
|
|
349
|
+
</div>
|
|
350
|
+
</div>
|
|
351
|
+
);
|
|
352
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { List, Plus, RefreshCw } from 'lucide-react';
|
|
4
|
+
|
|
5
|
+
import { Button } from '@docyrus/ui-pro-shared/components/button';
|
|
6
|
+
|
|
7
|
+
interface ContentOption {
|
|
8
|
+
title?: string;
|
|
9
|
+
text?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface ShowGeneratedContentOptionsProps {
|
|
13
|
+
output?: ContentOption[] | null;
|
|
14
|
+
state: string;
|
|
15
|
+
onInsertText?: (data: { text: string }) => void;
|
|
16
|
+
onReplaceText?: (data: { text: string }) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function ShowGeneratedContentOptions({
|
|
20
|
+
output,
|
|
21
|
+
state,
|
|
22
|
+
onInsertText,
|
|
23
|
+
onReplaceText
|
|
24
|
+
}: ShowGeneratedContentOptionsProps) {
|
|
25
|
+
const options: ContentOption[] = Array.isArray(output) ? output : [];
|
|
26
|
+
|
|
27
|
+
if (state === 'output-error') {
|
|
28
|
+
return <div className="text-xs text-destructive py-1">Failed to load options</div>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (state === 'output-available' && options.length === 0) {
|
|
32
|
+
return <div className="text-xs text-muted-foreground py-1">No options to display</div>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (state !== 'output-available' || options.length === 0) return null;
|
|
36
|
+
|
|
37
|
+
const handleInsert = (option: ContentOption) => {
|
|
38
|
+
onInsertText?.({ text: option.text || option.title || '' });
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const handleReplace = (option: ContentOption) => {
|
|
42
|
+
onReplaceText?.({ text: option.text || option.title || '' });
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div className="w-full">
|
|
47
|
+
<div className="flex items-center p-1 gap-2 mb-2">
|
|
48
|
+
<List className="w-4 h-4 text-primary" />
|
|
49
|
+
<p className="text-xs font-medium text-primary">
|
|
50
|
+
{`${options.length} options generated:`}
|
|
51
|
+
</p>
|
|
52
|
+
</div>
|
|
53
|
+
<div className="flex flex-col gap-2">
|
|
54
|
+
{options.map((option, index) => (
|
|
55
|
+
<div key={index} className="flex px-4 pt-2 rounded-lg bg-slate-50">
|
|
56
|
+
<div className="flex items-center justify-between mb-4 w-full">
|
|
57
|
+
<div className="flex flex-col w-full">
|
|
58
|
+
<div className="flex mb-2 justify-between items-center">
|
|
59
|
+
{option.title && (
|
|
60
|
+
<h3 className="text-sm ps-2 font-semibold text-foreground w-fit">
|
|
61
|
+
{option.title}
|
|
62
|
+
</h3>
|
|
63
|
+
)}
|
|
64
|
+
<div className="flex justify-end gap-2">
|
|
65
|
+
<Button
|
|
66
|
+
size="sm"
|
|
67
|
+
variant="secondary"
|
|
68
|
+
className="gap-1.5 [&_svg]:size-3.5 text-sky-600 hover:text-sky-700"
|
|
69
|
+
onClick={() => handleInsert(option)}>
|
|
70
|
+
<Plus />
|
|
71
|
+
Insert
|
|
72
|
+
</Button>
|
|
73
|
+
<Button
|
|
74
|
+
size="sm"
|
|
75
|
+
variant="secondary"
|
|
76
|
+
className="gap-1.5 [&_svg]:size-3.5 text-amber-600 hover:text-amber-700"
|
|
77
|
+
onClick={() => handleReplace(option)}>
|
|
78
|
+
<RefreshCw />
|
|
79
|
+
Replace
|
|
80
|
+
</Button>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
{option.text && (
|
|
84
|
+
<p className="text-xs text-muted-foreground">{option.text}</p>
|
|
85
|
+
)}
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
))}
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
}
|