@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,93 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { CodeView, type CodeViewPart } from '../components/code-view';
|
|
4
|
+
|
|
5
|
+
type SandpackLanguage
|
|
6
|
+
= 'react-ts'
|
|
7
|
+
| 'react'
|
|
8
|
+
| 'vanilla-ts'
|
|
9
|
+
| 'vanilla'
|
|
10
|
+
| 'vue'
|
|
11
|
+
| 'svelte'
|
|
12
|
+
| 'static';
|
|
13
|
+
|
|
14
|
+
type InputLanguage
|
|
15
|
+
= SandpackLanguage
|
|
16
|
+
| 'typescript'
|
|
17
|
+
| 'javascript'
|
|
18
|
+
| 'html'
|
|
19
|
+
| 'css'
|
|
20
|
+
| 'json'
|
|
21
|
+
| 'sql'
|
|
22
|
+
| 'markdown'
|
|
23
|
+
| 'text';
|
|
24
|
+
|
|
25
|
+
interface CanvasCodeViewProps {
|
|
26
|
+
contentText?: string;
|
|
27
|
+
language?: InputLanguage;
|
|
28
|
+
title?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function mapToSandpackLanguage(lang?: InputLanguage): SandpackLanguage {
|
|
32
|
+
switch (lang) {
|
|
33
|
+
case 'typescript':
|
|
34
|
+
|
|
35
|
+
case 'react-ts':
|
|
36
|
+
return 'react-ts';
|
|
37
|
+
|
|
38
|
+
case 'javascript':
|
|
39
|
+
|
|
40
|
+
case 'react':
|
|
41
|
+
return 'react';
|
|
42
|
+
|
|
43
|
+
case 'html':
|
|
44
|
+
|
|
45
|
+
case 'css':
|
|
46
|
+
|
|
47
|
+
case 'json':
|
|
48
|
+
|
|
49
|
+
case 'sql':
|
|
50
|
+
|
|
51
|
+
case 'markdown':
|
|
52
|
+
|
|
53
|
+
case 'text':
|
|
54
|
+
return 'static';
|
|
55
|
+
|
|
56
|
+
case 'vue':
|
|
57
|
+
return 'vue';
|
|
58
|
+
|
|
59
|
+
case 'svelte':
|
|
60
|
+
return 'svelte';
|
|
61
|
+
|
|
62
|
+
case 'vanilla-ts':
|
|
63
|
+
return 'vanilla-ts';
|
|
64
|
+
|
|
65
|
+
case 'vanilla':
|
|
66
|
+
return 'vanilla';
|
|
67
|
+
|
|
68
|
+
default:
|
|
69
|
+
return 'react-ts';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function CanvasCodeView({
|
|
74
|
+
contentText = '',
|
|
75
|
+
language = 'react-ts',
|
|
76
|
+
title = 'Code Preview'
|
|
77
|
+
}: CanvasCodeViewProps) {
|
|
78
|
+
const sandpackLanguage = mapToSandpackLanguage(language);
|
|
79
|
+
|
|
80
|
+
const part: CodeViewPart = useMemo(() => ({
|
|
81
|
+
state: 'output-available',
|
|
82
|
+
toolCallId: 'canvas-code',
|
|
83
|
+
input: {
|
|
84
|
+
title,
|
|
85
|
+
language: sandpackLanguage,
|
|
86
|
+
code: contentText
|
|
87
|
+
}
|
|
88
|
+
}), [contentText, sandpackLanguage, title]);
|
|
89
|
+
|
|
90
|
+
return <CodeView part={part} codeOnly />;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export default CanvasCodeView;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { JsonSchemaLayout } from '../components/json-schema-layout';
|
|
4
|
+
|
|
5
|
+
export interface CanvasDeepResearchViewProps {
|
|
6
|
+
title?: string;
|
|
7
|
+
output_schema?: Record<string, any> | null;
|
|
8
|
+
content?: Record<string, any> | any[] | null;
|
|
9
|
+
basis?: any[] | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function CanvasDeepResearchView({
|
|
13
|
+
title,
|
|
14
|
+
output_schema,
|
|
15
|
+
content,
|
|
16
|
+
basis
|
|
17
|
+
}: CanvasDeepResearchViewProps) {
|
|
18
|
+
return (
|
|
19
|
+
<div className="h-full w-full overflow-x-auto bg-muted">
|
|
20
|
+
<div className="max-w-7xl mx-auto p-6">
|
|
21
|
+
{title && (
|
|
22
|
+
<div className="mb-6">
|
|
23
|
+
<h2 className="text-2xl font-semibold text-gray-900">{title}</h2>
|
|
24
|
+
</div>
|
|
25
|
+
)}
|
|
26
|
+
|
|
27
|
+
{output_schema && content ? (
|
|
28
|
+
<div className="bg-white rounded-lg shadow-sm p-6">
|
|
29
|
+
<JsonSchemaLayout
|
|
30
|
+
schema={output_schema}
|
|
31
|
+
data={content}
|
|
32
|
+
basis={basis ?? []} />
|
|
33
|
+
</div>
|
|
34
|
+
) : (
|
|
35
|
+
<div className="bg-gray-50 border border-gray-200 rounded-lg p-8 text-center">
|
|
36
|
+
<p className="text-gray-500">No data available to display</p>
|
|
37
|
+
</div>
|
|
38
|
+
)}
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default CanvasDeepResearchView;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type FC } from 'react';
|
|
2
|
+
|
|
3
|
+
interface ImageData {
|
|
4
|
+
url: string;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
mimeType?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface CanvasImageViewProps {
|
|
11
|
+
title?: string;
|
|
12
|
+
images?: ImageData[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const CanvasImageView: FC<CanvasImageViewProps> = ({ title = '', images = [] }) => (
|
|
16
|
+
<div className="h-full w-full overflow-x-hidden overflow-y-auto flex flex-col items-center space-y-2">
|
|
17
|
+
{images.map((image, index) => (
|
|
18
|
+
<img
|
|
19
|
+
key={index}
|
|
20
|
+
src={image.url}
|
|
21
|
+
alt={title || `Image ${index + 1}`}
|
|
22
|
+
className="w-fit max-w-full h-auto p-2 rounded" />
|
|
23
|
+
))}
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useCallback, useEffect, useState, type SyntheticEvent
|
|
5
|
+
} from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
AlertCircle, CheckCircle, Loader2
|
|
9
|
+
} from 'lucide-react';
|
|
10
|
+
|
|
11
|
+
import { Button } from '@docyrus/ui-pro-shared/components/button';
|
|
12
|
+
import { Input } from '@docyrus/ui-pro-shared/components/input';
|
|
13
|
+
import { Label } from '@docyrus/ui-pro-shared/components/label';
|
|
14
|
+
import { Separator } from '@docyrus/ui-pro-shared/components/separator';
|
|
15
|
+
|
|
16
|
+
import { useApiClient } from '../lib/api-client';
|
|
17
|
+
|
|
18
|
+
export type RecordMode = 'add' | 'edit' | 'view';
|
|
19
|
+
|
|
20
|
+
export interface CanvasRecordViewProps {
|
|
21
|
+
dataSourceId: string;
|
|
22
|
+
mode?: RecordMode;
|
|
23
|
+
defaultValues?: Record<string, any> | string;
|
|
24
|
+
recordId?: string;
|
|
25
|
+
onSave?: (id: string, data: Record<string, any>) => void;
|
|
26
|
+
onClose?: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface DsField {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
slug: string;
|
|
33
|
+
type: string;
|
|
34
|
+
read_only?: boolean;
|
|
35
|
+
sort_order?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface DsInfo {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
slug: string;
|
|
42
|
+
app: { id: string; name: string; slug: string };
|
|
43
|
+
fields: DsField[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const parseValues = (values: any): Record<string, any> => {
|
|
47
|
+
if (!values) return {};
|
|
48
|
+
|
|
49
|
+
if (typeof values === 'string') {
|
|
50
|
+
try {
|
|
51
|
+
return JSON.parse(values);
|
|
52
|
+
} catch {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return typeof values === 'object' ? values : {};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const isUuid = (str: string): boolean => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(str);
|
|
61
|
+
|
|
62
|
+
export function CanvasRecordView({
|
|
63
|
+
dataSourceId,
|
|
64
|
+
mode = 'add',
|
|
65
|
+
defaultValues,
|
|
66
|
+
recordId,
|
|
67
|
+
onSave,
|
|
68
|
+
onClose
|
|
69
|
+
}: CanvasRecordViewProps) {
|
|
70
|
+
const apiClient = useApiClient();
|
|
71
|
+
const parsedDefaults = parseValues(defaultValues);
|
|
72
|
+
|
|
73
|
+
// TODO: fetch dsInfo via config.getDataSourceSchema once auth strategy is finalized
|
|
74
|
+
const [dsInfo, _setDsInfo] = useState<DsInfo | null>(null);
|
|
75
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
76
|
+
const [formValues, setFormValues] = useState<Record<string, any>>(parsedDefaults);
|
|
77
|
+
const [isSaving, setIsSaving] = useState(false);
|
|
78
|
+
const [error, setError] = useState<string | null>(null);
|
|
79
|
+
const [savedId, setSavedId] = useState<string | null>(null);
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (!dataSourceId) {
|
|
83
|
+
setIsLoading(false);
|
|
84
|
+
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let cancelled = false;
|
|
89
|
+
|
|
90
|
+
const init = async () => {
|
|
91
|
+
setIsLoading(true);
|
|
92
|
+
|
|
93
|
+
/*
|
|
94
|
+
* TODO: Fetch data source schema (fields + app slug) via getDataSourceSchema,
|
|
95
|
+
* then load record via REST if mode !== 'add'.
|
|
96
|
+
* Blocked by: auth strategy for server-side Supabase query.
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
if (!cancelled) {
|
|
100
|
+
setFormValues(parsedDefaults);
|
|
101
|
+
setIsLoading(false);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
init();
|
|
106
|
+
|
|
107
|
+
return () => {
|
|
108
|
+
cancelled = true;
|
|
109
|
+
};
|
|
110
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
111
|
+
}, [dataSourceId, mode, recordId]);
|
|
112
|
+
|
|
113
|
+
const handleChange = useCallback((key: string, val: any) => {
|
|
114
|
+
setFormValues(prev => ({
|
|
115
|
+
...prev,
|
|
116
|
+
[key]: val
|
|
117
|
+
}));
|
|
118
|
+
}, []);
|
|
119
|
+
|
|
120
|
+
const handleSubmit = async (e: SyntheticEvent<HTMLFormElement>) => {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
if (mode === 'view') return;
|
|
123
|
+
|
|
124
|
+
const appSlug = dsInfo?.app?.slug;
|
|
125
|
+
const dsSlug = dsInfo?.slug;
|
|
126
|
+
|
|
127
|
+
if (!appSlug || !dsSlug) {
|
|
128
|
+
setError('Data source information not loaded yet');
|
|
129
|
+
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
setIsSaving(true);
|
|
134
|
+
setError(null);
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
let res: any;
|
|
138
|
+
|
|
139
|
+
if (mode === 'add') {
|
|
140
|
+
res = await apiClient.post(`/apps/${appSlug}/data-sources/${dsSlug}/items`, formValues);
|
|
141
|
+
} else if (mode === 'edit' && recordId) {
|
|
142
|
+
res = await apiClient.patch(`/apps/${appSlug}/data-sources/${dsSlug}/items/${recordId}`, formValues);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (res?.success) {
|
|
146
|
+
const id = res.data?.id || recordId || '';
|
|
147
|
+
|
|
148
|
+
setSavedId(id);
|
|
149
|
+
onSave?.(id, res.data ?? formValues);
|
|
150
|
+
} else {
|
|
151
|
+
setError(res?.error || res?.message || 'Failed to save record');
|
|
152
|
+
}
|
|
153
|
+
} catch (err) {
|
|
154
|
+
setError(err instanceof Error ? err.message : 'Failed to save record');
|
|
155
|
+
} finally {
|
|
156
|
+
setIsSaving(false);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const renderFields = () => {
|
|
161
|
+
const fields = dsInfo?.fields
|
|
162
|
+
?.filter(f => !f.read_only || mode === 'view')
|
|
163
|
+
?.sort((a, b) => (a.sort_order ?? 0) - (b.sort_order ?? 0));
|
|
164
|
+
|
|
165
|
+
if (fields && fields.length > 0) {
|
|
166
|
+
return fields.map((field) => {
|
|
167
|
+
const value = formValues[field.slug] ?? formValues[field.id] ?? '';
|
|
168
|
+
const label = field.name || field.slug;
|
|
169
|
+
const readOnly = mode === 'view' || !!field.read_only;
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<div key={field.id} className="space-y-1.5">
|
|
173
|
+
<Label className="text-xs font-medium capitalize">{label}</Label>
|
|
174
|
+
{isUuid(String(value)) ? (
|
|
175
|
+
<div className="px-3 py-2 rounded-md border bg-muted/30 text-xs text-muted-foreground truncate">
|
|
176
|
+
{String(value)}
|
|
177
|
+
</div>
|
|
178
|
+
) : (
|
|
179
|
+
<Input
|
|
180
|
+
value={String(value)}
|
|
181
|
+
onChange={e => handleChange(field.slug, e.target.value)}
|
|
182
|
+
readOnly={readOnly}
|
|
183
|
+
className="text-sm h-9" />
|
|
184
|
+
)}
|
|
185
|
+
</div>
|
|
186
|
+
);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Fallback: derive fields from formValues keys
|
|
191
|
+
return Object.entries(formValues).map(([key, value]) => {
|
|
192
|
+
if (key.endsWith('_currency')) return null;
|
|
193
|
+
|
|
194
|
+
const currencyKey = `${key}_currency`;
|
|
195
|
+
const currency = formValues[currencyKey];
|
|
196
|
+
const label = isUuid(key) ? `${key.slice(0, 8)}…` : key.replace(/_/g, ' ');
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<div key={key} className="space-y-1.5">
|
|
200
|
+
<Label className="text-xs font-medium capitalize">{label}</Label>
|
|
201
|
+
{isUuid(String(value)) ? (
|
|
202
|
+
<div className="px-3 py-2 rounded-md border bg-muted/30 text-xs text-muted-foreground truncate">
|
|
203
|
+
{String(value)}
|
|
204
|
+
</div>
|
|
205
|
+
) : (
|
|
206
|
+
<div className="flex gap-2">
|
|
207
|
+
<Input
|
|
208
|
+
value={String(value ?? '')}
|
|
209
|
+
onChange={e => handleChange(key, e.target.value)}
|
|
210
|
+
readOnly={mode === 'view'}
|
|
211
|
+
className="text-sm h-9" />
|
|
212
|
+
{currency && (
|
|
213
|
+
<div className="flex items-center px-2.5 bg-muted rounded-md text-xs font-medium shrink-0">
|
|
214
|
+
{String(currency)}
|
|
215
|
+
</div>
|
|
216
|
+
)}
|
|
217
|
+
</div>
|
|
218
|
+
)}
|
|
219
|
+
</div>
|
|
220
|
+
);
|
|
221
|
+
}).filter(Boolean);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const modeLabel = mode === 'add' ? 'Create' : mode === 'edit' ? 'Update' : 'View';
|
|
225
|
+
|
|
226
|
+
if (isLoading) {
|
|
227
|
+
return (
|
|
228
|
+
<div className="flex items-center justify-center h-full p-8">
|
|
229
|
+
<Loader2 className="size-5 animate-spin text-muted-foreground" />
|
|
230
|
+
</div>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (savedId !== null) {
|
|
235
|
+
return (
|
|
236
|
+
<div className="flex flex-col items-center justify-center h-full p-8 gap-4">
|
|
237
|
+
<CheckCircle className="size-10 text-green-500" />
|
|
238
|
+
<div className="text-center">
|
|
239
|
+
<div className="font-medium">Record saved successfully</div>
|
|
240
|
+
{savedId && <div className="text-xs text-muted-foreground mt-1">ID: {savedId}</div>}
|
|
241
|
+
</div>
|
|
242
|
+
<Button variant="outline" size="sm" onClick={onClose}>Close</Button>
|
|
243
|
+
</div>
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return (
|
|
248
|
+
<div className="flex flex-col h-full">
|
|
249
|
+
<form onSubmit={handleSubmit} className="flex flex-col flex-1 overflow-hidden">
|
|
250
|
+
<div className="flex-1 overflow-y-auto p-4 space-y-4">
|
|
251
|
+
{error && (
|
|
252
|
+
<div className="flex items-start gap-2 p-3 bg-destructive/10 border border-destructive/20 rounded-md text-destructive text-sm">
|
|
253
|
+
<AlertCircle className="size-4 mt-0.5 shrink-0" />
|
|
254
|
+
<span>{error}</span>
|
|
255
|
+
</div>
|
|
256
|
+
)}
|
|
257
|
+
|
|
258
|
+
{renderFields()}
|
|
259
|
+
|
|
260
|
+
{Object.keys(formValues).length === 0 && !dsInfo?.fields?.length && (
|
|
261
|
+
<div className="text-sm text-muted-foreground text-center py-8">
|
|
262
|
+
No fields available for this data source
|
|
263
|
+
</div>
|
|
264
|
+
)}
|
|
265
|
+
</div>
|
|
266
|
+
|
|
267
|
+
{mode !== 'view' && (
|
|
268
|
+
<>
|
|
269
|
+
<Separator />
|
|
270
|
+
<div className="flex items-center justify-end gap-2 p-4 shrink-0">
|
|
271
|
+
{onClose && (
|
|
272
|
+
<Button type="button" variant="outline" size="sm" onClick={onClose}>
|
|
273
|
+
Cancel
|
|
274
|
+
</Button>
|
|
275
|
+
)}
|
|
276
|
+
<Button type="submit" size="sm" disabled={isSaving}>
|
|
277
|
+
{isSaving ? <><Loader2 className="size-3.5 mr-1.5 animate-spin" />Saving…</> : `${modeLabel} Record`}
|
|
278
|
+
</Button>
|
|
279
|
+
</div>
|
|
280
|
+
</>
|
|
281
|
+
)}
|
|
282
|
+
</form>
|
|
283
|
+
</div>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
|
|
5
|
+
import { UniverSheets } from '../internal/sheets';
|
|
6
|
+
|
|
7
|
+
interface CanvasSpreadsheetViewProps {
|
|
8
|
+
title?: string;
|
|
9
|
+
content?: Record<string, any> | null;
|
|
10
|
+
workId?: string;
|
|
11
|
+
versionId?: string;
|
|
12
|
+
commands?: any[];
|
|
13
|
+
onData?: (data: { workbook: unknown; workbookJson: string }) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const toSparse = (arr: any): Record<string, any> => {
|
|
17
|
+
if (!Array.isArray(arr)) {
|
|
18
|
+
return arr || {};
|
|
19
|
+
}
|
|
20
|
+
const m: Record<string, any> = {};
|
|
21
|
+
|
|
22
|
+
arr.forEach((row: any, r: number) => row?.forEach((cell: any, c: number) => cell && ((m[r] = m[r] || {})[c] = cell)));
|
|
23
|
+
|
|
24
|
+
return m;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const transformSheet = (sheet: Record<string, any>, sheetId: string) => {
|
|
28
|
+
const keys = [
|
|
29
|
+
'id',
|
|
30
|
+
'name',
|
|
31
|
+
'columnCount',
|
|
32
|
+
'rowCount',
|
|
33
|
+
'mergeData',
|
|
34
|
+
'rowData',
|
|
35
|
+
'columnData',
|
|
36
|
+
'rowHeader',
|
|
37
|
+
'columnHeader',
|
|
38
|
+
'showGridlines',
|
|
39
|
+
'rightToLeft',
|
|
40
|
+
'freeze',
|
|
41
|
+
'defaultColumnWidth',
|
|
42
|
+
'defaultRowHeight',
|
|
43
|
+
'tabColor',
|
|
44
|
+
'hidden'
|
|
45
|
+
];
|
|
46
|
+
const result: Record<string, any> = { cellData: toSparse(sheet.cellData), id: sheetId };
|
|
47
|
+
|
|
48
|
+
keys.forEach(k => sheet[k] != null && (result[k] = sheet[k]));
|
|
49
|
+
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const transformWorkbook = (wb: Record<string, any> | null | undefined): Record<string, any> | null => {
|
|
54
|
+
if (!wb) return null;
|
|
55
|
+
|
|
56
|
+
const sheetsObject: Record<string, any> = {};
|
|
57
|
+
|
|
58
|
+
const rawSheets = Array.isArray(wb.sheets) ? wb.sheets : Object.values(wb.sheets ?? {});
|
|
59
|
+
|
|
60
|
+
rawSheets.forEach((s: any, index: number) => {
|
|
61
|
+
if (!s || s === '') return;
|
|
62
|
+
|
|
63
|
+
let sheetData: Record<string, any>;
|
|
64
|
+
|
|
65
|
+
if (typeof s === 'string') {
|
|
66
|
+
try {
|
|
67
|
+
sheetData = JSON.parse(s);
|
|
68
|
+
} catch {
|
|
69
|
+
console.warn(`Sheet at index ${index} is not valid JSON:`, s);
|
|
70
|
+
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
sheetData = s;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (sheetData?.id && sheetData?.sheet) {
|
|
78
|
+
sheetsObject[sheetData.id] = transformSheet(sheetData.sheet, sheetData.id);
|
|
79
|
+
} else if (sheetData?.id) {
|
|
80
|
+
sheetsObject[sheetData.id] = transformSheet(sheetData, sheetData.id);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const validSheetIds = new Set(Object.keys(sheetsObject));
|
|
85
|
+
const sheetOrder = (wb.sheetOrder || []).filter((id: string) => validSheetIds.has(id));
|
|
86
|
+
|
|
87
|
+
const workbookData: Record<string, any> = {
|
|
88
|
+
id: wb.id,
|
|
89
|
+
name: wb.name,
|
|
90
|
+
sheetOrder,
|
|
91
|
+
sheets: sheetsObject
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
if (wb.styles) {
|
|
95
|
+
if (Array.isArray(wb.styles)) {
|
|
96
|
+
workbookData.styles = {};
|
|
97
|
+
wb.styles.forEach((s: any) => {
|
|
98
|
+
if (s.id && s.style) {
|
|
99
|
+
workbookData.styles[s.id] = s.style;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
workbookData.styles = wb.styles;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return workbookData;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export function CanvasSpreadsheetView({
|
|
111
|
+
content,
|
|
112
|
+
commands,
|
|
113
|
+
onData
|
|
114
|
+
}: CanvasSpreadsheetViewProps) {
|
|
115
|
+
const workbookData = useMemo(() => transformWorkbook(content?.workbook ?? content), [content]);
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<div className="h-full w-full overflow-hidden bg-muted flex relative">
|
|
119
|
+
<UniverSheets
|
|
120
|
+
initialData={workbookData ?? undefined}
|
|
121
|
+
commands={commands}
|
|
122
|
+
onData={onData} />
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import { PlateEditor, type PlateEditorHandle } from '../internal/plate-editor';
|
|
4
|
+
|
|
5
|
+
import { useAssistantConfig } from '../lib/assistant-config';
|
|
6
|
+
import { CanvasCodeView } from './canvas-code';
|
|
7
|
+
|
|
8
|
+
type TextLanguage = 'markdown' | 'plain_text' | 'json' | 'javascript' | 'typescript' | 'html' | 'sql';
|
|
9
|
+
|
|
10
|
+
interface CanvasTextViewProps {
|
|
11
|
+
contentText?: string;
|
|
12
|
+
language?: TextLanguage;
|
|
13
|
+
title?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function MarkdownView({ contentText = '' }: { contentText?: string }) {
|
|
17
|
+
const editorRef = useRef<PlateEditorHandle>(null);
|
|
18
|
+
const { getAuthToken } = useAssistantConfig();
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
editorRef.current?.setMarkdown(contentText);
|
|
22
|
+
}, [contentText]);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<PlateEditor
|
|
26
|
+
ref={editorRef}
|
|
27
|
+
getAccessToken={getAuthToken}
|
|
28
|
+
onReady={() => editorRef.current?.setMarkdown(contentText)} />
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function CanvasTextView({
|
|
33
|
+
contentText = '',
|
|
34
|
+
language = 'markdown',
|
|
35
|
+
title = ''
|
|
36
|
+
}: CanvasTextViewProps) {
|
|
37
|
+
if (language === 'markdown' || language === 'plain_text') {
|
|
38
|
+
return (
|
|
39
|
+
<div className="h-full w-full overflow-x-auto bg-muted flex justify-center items-start">
|
|
40
|
+
<MarkdownView contentText={contentText} />
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div className="h-full w-full overflow-x-auto">
|
|
47
|
+
<CanvasCodeView contentText={contentText} language={language} title={title} />
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default CanvasTextView;
|