@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,839 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
ChevronDown, ChevronRight, FolderOpen, LayoutDashboard, Menu, Table2
|
|
7
|
+
} from 'lucide-react';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
Bar,
|
|
11
|
+
BarChart,
|
|
12
|
+
Cell,
|
|
13
|
+
Legend,
|
|
14
|
+
Line,
|
|
15
|
+
LineChart,
|
|
16
|
+
Pie,
|
|
17
|
+
PieChart,
|
|
18
|
+
ResponsiveContainer,
|
|
19
|
+
Tooltip,
|
|
20
|
+
XAxis,
|
|
21
|
+
YAxis
|
|
22
|
+
} from 'recharts';
|
|
23
|
+
|
|
24
|
+
import { Button } from '@docyrus/ui-pro-shared/components/button';
|
|
25
|
+
import { cn } from '@docyrus/ui-pro-shared/lib/utils';
|
|
26
|
+
|
|
27
|
+
import { MermaidDiagram } from '../components/mermaid-diagram';
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* ─────────────────────────────────────────────────────────────
|
|
31
|
+
* Mermaid generators (ported from mermaid-generator.js)
|
|
32
|
+
* ─────────────────────────────────────────────────────────────
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
function generateLayoutDiagram(app: any): string {
|
|
36
|
+
if (!app?.layout) return '';
|
|
37
|
+
const { layout } = app;
|
|
38
|
+
let d = 'graph LR\n';
|
|
39
|
+
const menuArr: any[] = Array.isArray(layout.menu) ? layout.menu : Object.values(layout.menu ?? {});
|
|
40
|
+
const widgetsArr: any[] = Array.isArray(layout.widgets) ? layout.widgets : Object.values(layout.widgets ?? {});
|
|
41
|
+
|
|
42
|
+
d += ` App["${layout.title || 'App'}"]\n`;
|
|
43
|
+
menuArr.forEach((item: any, i: number) => {
|
|
44
|
+
const mid = `Menu_${i}`;
|
|
45
|
+
|
|
46
|
+
d += ` subgraph cluster_${mid}\n direction TB\n ${mid}["${item.title || item.id}"]\n`;
|
|
47
|
+
item.views?.forEach((v: any, j: number) => {
|
|
48
|
+
const vid = `View_${i}_${j}`;
|
|
49
|
+
|
|
50
|
+
d += ` ${vid}["${v.title || v.id} (${v.type})"]\n ${mid} --> ${vid}\n`;
|
|
51
|
+
});
|
|
52
|
+
d += ` end\n App --> ${mid}\n`;
|
|
53
|
+
});
|
|
54
|
+
if (widgetsArr.length > 0) {
|
|
55
|
+
d += ` subgraph cluster_Widgets\n direction TB\n Widgets[Widgets]\n`;
|
|
56
|
+
widgetsArr.forEach((w: any, i: number) => {
|
|
57
|
+
d += ` Widget_${i}["${w.title || w.type}"]\n Widgets --> Widget_${i}\n`;
|
|
58
|
+
});
|
|
59
|
+
d += ` end\n App -.-> Widgets\n`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return d;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function generateDataStructureDiagram(app: any): string {
|
|
66
|
+
if (!app?.data_sources) return '';
|
|
67
|
+
|
|
68
|
+
const dsArr: any[] = Array.isArray(app.data_sources) ? app.data_sources : Object.values(app.data_sources);
|
|
69
|
+
let d = 'classDiagram\n direction TB\n';
|
|
70
|
+
const idMap: Record<string, string> = {};
|
|
71
|
+
|
|
72
|
+
dsArr.forEach((ds: any) => {
|
|
73
|
+
const safe = (ds.name || ds.slug || 'DS').replace(/[^a-zA-Z0-9_]/g, '_');
|
|
74
|
+
const key = ds.id || ds.slug || ds.name;
|
|
75
|
+
|
|
76
|
+
if (key) idMap[key] = safe;
|
|
77
|
+
});
|
|
78
|
+
dsArr.forEach((ds: any) => {
|
|
79
|
+
const safe = (ds.name || ds.slug || 'DS').replace(/[^a-zA-Z0-9_]/g, '_');
|
|
80
|
+
const fieldsArr: any[] = Array.isArray(ds.fields) ? ds.fields : Object.values(ds.fields ?? {});
|
|
81
|
+
|
|
82
|
+
d += ` class ${safe} {\n`;
|
|
83
|
+
fieldsArr.forEach((f: any) => {
|
|
84
|
+
d += ` +${f.type || 'string'} ${f.name || f.slug}\n`;
|
|
85
|
+
});
|
|
86
|
+
d += ' }\n';
|
|
87
|
+
fieldsArr.forEach((f: any) => {
|
|
88
|
+
if (f.type === 'field-relation' && f.relationDataSourceId) {
|
|
89
|
+
const target = idMap[f.relationDataSourceId];
|
|
90
|
+
|
|
91
|
+
if (target) d += ` ${safe} --> ${target} : ${f.name || f.slug}\n`;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return d;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/*
|
|
100
|
+
* ─────────────────────────────────────────────────────────────
|
|
101
|
+
* AppSidebar
|
|
102
|
+
* ─────────────────────────────────────────────────────────────
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
function AppSidebar({
|
|
106
|
+
data, title, onMenuClick
|
|
107
|
+
}: {
|
|
108
|
+
data: any[];
|
|
109
|
+
title?: string;
|
|
110
|
+
onMenuClick: (id: string) => void;
|
|
111
|
+
}) {
|
|
112
|
+
const [collapsed, setCollapsed] = useState(false);
|
|
113
|
+
const [expanded, setExpanded] = useState<Set<string>>(new Set());
|
|
114
|
+
|
|
115
|
+
const toggleFolder = (id: string) => {
|
|
116
|
+
if (collapsed) {
|
|
117
|
+
setCollapsed(false);
|
|
118
|
+
setExpanded(prev => new Set([...prev, id]));
|
|
119
|
+
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
setExpanded((prev) => {
|
|
123
|
+
const next = new Set(prev);
|
|
124
|
+
|
|
125
|
+
next.has(id) ? next.delete(id) : next.add(id);
|
|
126
|
+
|
|
127
|
+
return next;
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<aside
|
|
133
|
+
className={cn(
|
|
134
|
+
'h-full bg-white border-r border-gray-200 transition-all duration-300 flex flex-col shrink-0',
|
|
135
|
+
collapsed ? 'w-12' : 'w-52'
|
|
136
|
+
)}>
|
|
137
|
+
{/* Header */}
|
|
138
|
+
<div className="flex items-center justify-between px-2 py-1.5 border-b border-gray-200 h-9 shrink-0">
|
|
139
|
+
{!collapsed && (
|
|
140
|
+
<span className="grow text-sm font-semibold text-gray-900 truncate mr-1">{title}</span>
|
|
141
|
+
)}
|
|
142
|
+
<Button
|
|
143
|
+
variant="ghost"
|
|
144
|
+
size="icon"
|
|
145
|
+
className="h-6 w-6 shrink-0"
|
|
146
|
+
onClick={() => setCollapsed(v => !v)}>
|
|
147
|
+
<Menu className="size-3.5" />
|
|
148
|
+
</Button>
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
{/* Nav */}
|
|
152
|
+
<nav className="flex-1 overflow-y-auto p-1.5 space-y-0.5">
|
|
153
|
+
{data.map((item: any) => {
|
|
154
|
+
if (item.type === 'folder') {
|
|
155
|
+
const isExp = expanded.has(item.id);
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<div key={item.id}>
|
|
159
|
+
<button
|
|
160
|
+
onClick={() => toggleFolder(item.id)}
|
|
161
|
+
className="w-full flex items-center gap-2 px-2 py-1.5 rounded-md hover:bg-gray-100 text-left text-sm">
|
|
162
|
+
<FolderOpen className="size-4 text-gray-500 shrink-0" />
|
|
163
|
+
{!collapsed && (
|
|
164
|
+
<>
|
|
165
|
+
<span className="flex-1 truncate text-gray-900 font-medium">{item.title}</span>
|
|
166
|
+
{isExp ? <ChevronDown className="size-3 text-gray-400" /> : <ChevronRight className="size-3 text-gray-400" />}
|
|
167
|
+
</>
|
|
168
|
+
)}
|
|
169
|
+
</button>
|
|
170
|
+
{!collapsed && isExp && (
|
|
171
|
+
<div className="ml-4 mt-0.5 space-y-0.5">
|
|
172
|
+
{item.menu?.map((sub: any) => (
|
|
173
|
+
<button
|
|
174
|
+
key={sub.id}
|
|
175
|
+
onClick={() => { onMenuClick(sub.id); }}
|
|
176
|
+
className="w-full flex items-center gap-2 px-2 py-1.5 rounded-md hover:bg-gray-100 text-left text-sm text-gray-700">
|
|
177
|
+
<span className="truncate">{sub.title}</span>
|
|
178
|
+
</button>
|
|
179
|
+
))}
|
|
180
|
+
</div>
|
|
181
|
+
)}
|
|
182
|
+
</div>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<button
|
|
188
|
+
key={item.id}
|
|
189
|
+
onClick={() => { onMenuClick(item.id); }}
|
|
190
|
+
title={collapsed ? item.title : undefined}
|
|
191
|
+
className="w-full flex items-center gap-2 px-2 py-1.5 rounded-md hover:bg-gray-100 text-left text-sm">
|
|
192
|
+
<LayoutDashboard className="size-4 text-gray-500 shrink-0" />
|
|
193
|
+
{!collapsed && (
|
|
194
|
+
<span className="truncate text-gray-900 font-medium">{item.title}</span>
|
|
195
|
+
)}
|
|
196
|
+
</button>
|
|
197
|
+
);
|
|
198
|
+
})}
|
|
199
|
+
</nav>
|
|
200
|
+
</aside>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/*
|
|
205
|
+
* ─────────────────────────────────────────────────────────────
|
|
206
|
+
* AppBoardView — simplified board (shows columns/fields as table)
|
|
207
|
+
* ─────────────────────────────────────────────────────────────
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
function AppBoardView({ page, dataSources }: { page: any; dataSources: any[] }) {
|
|
211
|
+
const [activeViewIdx, setActiveViewIdx] = useState(0);
|
|
212
|
+
const views = page?.views ?? [];
|
|
213
|
+
const activeView = views[activeViewIdx];
|
|
214
|
+
const dsId = activeView?.config?.dataSourceId ?? activeView?.dataSourceId;
|
|
215
|
+
const ds = dsId ? dataSources.find(
|
|
216
|
+
(d: any) => d.id === dsId
|
|
217
|
+
|| d.slug === dsId
|
|
218
|
+
|| d.name === dsId
|
|
219
|
+
) ?? dataSources[0] ?? null : dataSources[0] ?? null;
|
|
220
|
+
|
|
221
|
+
// Columns: from view config, falling back to data source fields
|
|
222
|
+
const columns: any[] = activeView?.config?.columns ?? activeView?.columns ?? ds?.fields ?? [];
|
|
223
|
+
|
|
224
|
+
// DEBUG
|
|
225
|
+
console.info('[AppBoardView] dsId', dsId, 'ds.id', ds?.id, 'records', ds?.records?.length);
|
|
226
|
+
console.info('[AppBoardView] columns[0]', columns[0], 'record[0] keys', Object.keys(ds?.records?.[0] ?? {}));
|
|
227
|
+
|
|
228
|
+
// Records: dummy data from the data source
|
|
229
|
+
const records: any[] = ds?.records ?? [];
|
|
230
|
+
|
|
231
|
+
const getCellValue = (record: any, col: any): string => {
|
|
232
|
+
// column.field is the primary key (from view config), fallback to slug/id/name
|
|
233
|
+
const key = col.field || col.slug || col.id || col.name || col;
|
|
234
|
+
const val = record[key];
|
|
235
|
+
|
|
236
|
+
if (val === null || val === undefined) return '';
|
|
237
|
+
// Relation fields: {id, name} → show name
|
|
238
|
+
if (typeof val === 'object' && !Array.isArray(val)) return val.name ?? JSON.stringify(val);
|
|
239
|
+
if (Array.isArray(val)) return val.map((v: any) => v?.name ?? v).join(', ');
|
|
240
|
+
|
|
241
|
+
return String(val);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
return (
|
|
245
|
+
<div className="flex flex-col h-full w-full overflow-hidden">
|
|
246
|
+
<div className="flex items-center gap-2 px-3 py-2 border-b bg-muted/30 shrink-0">
|
|
247
|
+
<Table2 className="size-4 text-muted-foreground" />
|
|
248
|
+
<span className="text-sm font-medium">{page.title}</span>
|
|
249
|
+
</div>
|
|
250
|
+
{views.length > 1 && (
|
|
251
|
+
<div className="flex gap-1 px-3 py-1 border-b shrink-0">
|
|
252
|
+
{views.map((v: any, i: number) => (
|
|
253
|
+
<button
|
|
254
|
+
key={v.id || i}
|
|
255
|
+
onClick={() => setActiveViewIdx(i)}
|
|
256
|
+
className={cn(
|
|
257
|
+
'px-2 py-0.5 rounded text-xs',
|
|
258
|
+
activeViewIdx === i ? 'bg-primary text-primary-foreground' : 'hover:bg-muted text-muted-foreground'
|
|
259
|
+
)}>
|
|
260
|
+
{v.title || v.type}
|
|
261
|
+
</button>
|
|
262
|
+
))}
|
|
263
|
+
</div>
|
|
264
|
+
)}
|
|
265
|
+
<div className="flex-1 overflow-auto p-3">
|
|
266
|
+
{columns.length > 0 ? (
|
|
267
|
+
<table className="w-full text-xs border border-gray-200">
|
|
268
|
+
<thead className="bg-gray-50">
|
|
269
|
+
<tr>
|
|
270
|
+
{columns.map((col: any, i: number) => (
|
|
271
|
+
<th key={i} className="border border-gray-200 px-2 py-1 text-left font-medium text-gray-700">
|
|
272
|
+
{col.name || col.title || col.slug || col}
|
|
273
|
+
</th>
|
|
274
|
+
))}
|
|
275
|
+
</tr>
|
|
276
|
+
</thead>
|
|
277
|
+
<tbody>
|
|
278
|
+
{records.length > 0 ? records.map((record: any, ri: number) => (
|
|
279
|
+
<tr key={ri} className="hover:bg-gray-50">
|
|
280
|
+
{columns.map((col: any, ci: number) => (
|
|
281
|
+
<td key={ci} className="border border-gray-200 px-2 py-1 max-w-[200px] truncate">
|
|
282
|
+
{getCellValue(record, col)}
|
|
283
|
+
</td>
|
|
284
|
+
))}
|
|
285
|
+
</tr>
|
|
286
|
+
)) : (
|
|
287
|
+
<tr>
|
|
288
|
+
{columns.map((_: any, i: number) => (
|
|
289
|
+
<td key={i} className="border border-gray-200 px-2 py-1 text-gray-400 italic">—</td>
|
|
290
|
+
))}
|
|
291
|
+
</tr>
|
|
292
|
+
)}
|
|
293
|
+
</tbody>
|
|
294
|
+
</table>
|
|
295
|
+
) : (
|
|
296
|
+
<div className="text-sm text-muted-foreground text-center py-8">
|
|
297
|
+
{ds ? `Data source: ${ds.title || ds.slug}` : 'No view data available'}
|
|
298
|
+
</div>
|
|
299
|
+
)}
|
|
300
|
+
</div>
|
|
301
|
+
</div>
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/*
|
|
306
|
+
* ─────────────────────────────────────────────────────────────
|
|
307
|
+
* AppDashboardPreview — widget cards with dot background
|
|
308
|
+
* ─────────────────────────────────────────────────────────────
|
|
309
|
+
*/
|
|
310
|
+
|
|
311
|
+
function WidgetSummary({ widget }: { widget: any }) {
|
|
312
|
+
const ds = widget.options?.dataSource;
|
|
313
|
+
const records: any[] = ds?.records ?? [];
|
|
314
|
+
const widgetType: string = widget.options?.type || widget.type || '';
|
|
315
|
+
const normType = widgetType.toLowerCase().replace(/_/g, '');
|
|
316
|
+
|
|
317
|
+
const dataConfig = widget.options?.dataConfig ?? {};
|
|
318
|
+
|
|
319
|
+
// Calculations from dataConfig (each has func + field)
|
|
320
|
+
const calculations: any[] = Array.isArray(dataConfig.calculations) ? dataConfig.calculations : [];
|
|
321
|
+
|
|
322
|
+
// Group-by rows from dataConfig.fields.rows
|
|
323
|
+
const rowFields: string[] = Array.isArray(dataConfig.fields?.rows) ? dataConfig.fields.rows : [];
|
|
324
|
+
const groupField: string = rowFields[0] || '';
|
|
325
|
+
|
|
326
|
+
// Primary metric: first calculation's field
|
|
327
|
+
const primaryCalc = calculations[0];
|
|
328
|
+
const metricField: string = primaryCalc?.field || '';
|
|
329
|
+
|
|
330
|
+
console.info('[WidgetSummary]', widget.title, {
|
|
331
|
+
widgetType, groupField, metricField, records: records.length
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const isKpi = normType === 'chartstatistic'
|
|
335
|
+
|| normType.includes('kpi')
|
|
336
|
+
|| normType.includes('stat')
|
|
337
|
+
|| normType.includes('metric');
|
|
338
|
+
|
|
339
|
+
// For KPI: sum of primary calc field
|
|
340
|
+
const kpiValue = (() => {
|
|
341
|
+
if (!metricField || records.length === 0) return null;
|
|
342
|
+
|
|
343
|
+
if (primaryCalc?.func === 'count') return records.length;
|
|
344
|
+
|
|
345
|
+
const sum = records.reduce((acc: number, r: any) => {
|
|
346
|
+
const v = r[metricField];
|
|
347
|
+
const num = typeof v === 'object' && v !== null ? Number(v.id ?? 0) : Number(v) || 0;
|
|
348
|
+
|
|
349
|
+
return acc + num;
|
|
350
|
+
}, 0);
|
|
351
|
+
|
|
352
|
+
return sum;
|
|
353
|
+
})();
|
|
354
|
+
|
|
355
|
+
// For bar/pie charts: group records by rowField, aggregate by calc field
|
|
356
|
+
const groups: [string, number][] = (() => {
|
|
357
|
+
if (!groupField || records.length === 0) return [];
|
|
358
|
+
|
|
359
|
+
const map: Record<string, number> = {};
|
|
360
|
+
|
|
361
|
+
records.forEach((r: any) => {
|
|
362
|
+
const rawKey = r[groupField];
|
|
363
|
+
const label = typeof rawKey === 'object' && rawKey !== null ? (rawKey.name ?? String(rawKey.id ?? '—')) : String(rawKey ?? '—');
|
|
364
|
+
|
|
365
|
+
const val = primaryCalc?.func === 'count' ? 1 : metricField ? (() => {
|
|
366
|
+
const v = r[metricField];
|
|
367
|
+
|
|
368
|
+
return typeof v === 'object' && v !== null ? Number(v.id ?? 0) : Number(v) || 0;
|
|
369
|
+
})() : 1;
|
|
370
|
+
|
|
371
|
+
map[label] = (map[label] || 0) + val;
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
return Object.entries(map).sort((a, b) => b[1] - a[1]).slice(0, 6);
|
|
375
|
+
})();
|
|
376
|
+
|
|
377
|
+
const COLORS = [
|
|
378
|
+
'#6366f1',
|
|
379
|
+
'#22d3ee',
|
|
380
|
+
'#f59e0b',
|
|
381
|
+
'#10b981',
|
|
382
|
+
'#f43f5e',
|
|
383
|
+
'#8b5cf6'
|
|
384
|
+
];
|
|
385
|
+
const chartData = groups.map(([name, value]) => ({ name, value }));
|
|
386
|
+
|
|
387
|
+
const isPie = normType.includes('pie') || normType.includes('donut');
|
|
388
|
+
const isLine = normType.includes('line') || normType.includes('area');
|
|
389
|
+
const isColumn = normType.includes('column');
|
|
390
|
+
|
|
391
|
+
const metricLabel = primaryCalc?.name || metricField || 'Value';
|
|
392
|
+
|
|
393
|
+
return (
|
|
394
|
+
<div className="bg-white border border-gray-200 rounded-lg p-3 shadow-sm flex flex-col gap-1 min-h-[140px]">
|
|
395
|
+
<div className="text-xs font-semibold text-gray-700 truncate">{widget.title || widget.type}</div>
|
|
396
|
+
|
|
397
|
+
{isKpi && kpiValue !== null && (
|
|
398
|
+
<div className="mt-auto">
|
|
399
|
+
<div className="text-2xl font-bold text-gray-900">
|
|
400
|
+
{kpiValue.toLocaleString(undefined, { maximumFractionDigits: 1 })}
|
|
401
|
+
</div>
|
|
402
|
+
<div className="text-[10px] text-muted-foreground">
|
|
403
|
+
{metricLabel} · {records.length} records
|
|
404
|
+
</div>
|
|
405
|
+
</div>
|
|
406
|
+
)}
|
|
407
|
+
|
|
408
|
+
{isPie && chartData.length === 0 && records.length > 0 && (
|
|
409
|
+
<div className="text-xs text-muted-foreground mt-auto py-2">
|
|
410
|
+
{records.length} records · no group field configured
|
|
411
|
+
</div>
|
|
412
|
+
)}
|
|
413
|
+
|
|
414
|
+
{isPie && chartData.length > 0 && (
|
|
415
|
+
<div style={{ width: '100%', height: 160 }}>
|
|
416
|
+
<ResponsiveContainer width="100%" height="100%">
|
|
417
|
+
<PieChart>
|
|
418
|
+
<Pie
|
|
419
|
+
data={chartData}
|
|
420
|
+
dataKey="value"
|
|
421
|
+
nameKey="name"
|
|
422
|
+
cx="50%"
|
|
423
|
+
cy="50%"
|
|
424
|
+
innerRadius={normType.includes('donut') ? 35 : 0}
|
|
425
|
+
outerRadius={55}
|
|
426
|
+
paddingAngle={2}>
|
|
427
|
+
{chartData.map((_: any, i: number) => (
|
|
428
|
+
<Cell key={i} fill={COLORS[i % COLORS.length]} />
|
|
429
|
+
))}
|
|
430
|
+
</Pie>
|
|
431
|
+
<Tooltip formatter={(v: any) => v.toLocaleString(undefined, { maximumFractionDigits: 1 })} />
|
|
432
|
+
<Legend iconSize={8} wrapperStyle={{ fontSize: 10 }} />
|
|
433
|
+
</PieChart>
|
|
434
|
+
</ResponsiveContainer>
|
|
435
|
+
</div>
|
|
436
|
+
)}
|
|
437
|
+
|
|
438
|
+
{isLine && chartData.length > 0 && (
|
|
439
|
+
<div style={{ width: '100%', height: 110 }}>
|
|
440
|
+
<ResponsiveContainer width="100%" height="100%">
|
|
441
|
+
<LineChart
|
|
442
|
+
data={chartData}
|
|
443
|
+
margin={{
|
|
444
|
+
top: 4, right: 4, left: -20, bottom: 0
|
|
445
|
+
}}>
|
|
446
|
+
<XAxis dataKey="name" tick={{ fontSize: 9 }} interval="preserveStartEnd" />
|
|
447
|
+
<YAxis tick={{ fontSize: 9 }} />
|
|
448
|
+
<Tooltip formatter={(v: any) => v.toLocaleString(undefined, { maximumFractionDigits: 1 })} />
|
|
449
|
+
<Line type="monotone" dataKey="value" stroke="#6366f1" strokeWidth={2} dot={{ r: 3 }} name={metricLabel} />
|
|
450
|
+
</LineChart>
|
|
451
|
+
</ResponsiveContainer>
|
|
452
|
+
</div>
|
|
453
|
+
)}
|
|
454
|
+
|
|
455
|
+
{(isColumn || (!isKpi && !isPie && !isLine)) && chartData.length > 0 && (
|
|
456
|
+
<div style={{ width: '100%', height: 110 }}>
|
|
457
|
+
<ResponsiveContainer width="100%" height="100%">
|
|
458
|
+
<BarChart
|
|
459
|
+
data={chartData}
|
|
460
|
+
layout={isColumn ? 'vertical' : 'horizontal'}
|
|
461
|
+
margin={{
|
|
462
|
+
top: 4, right: 4, left: isColumn ? 40 : -20, bottom: 0
|
|
463
|
+
}}>
|
|
464
|
+
{isColumn ? (
|
|
465
|
+
<>
|
|
466
|
+
<XAxis type="number" tick={{ fontSize: 9 }} />
|
|
467
|
+
<YAxis type="category" dataKey="name" tick={{ fontSize: 9 }} width={36} />
|
|
468
|
+
</>
|
|
469
|
+
) : (
|
|
470
|
+
<>
|
|
471
|
+
<XAxis dataKey="name" tick={{ fontSize: 9 }} interval={0} />
|
|
472
|
+
<YAxis tick={{ fontSize: 9 }} />
|
|
473
|
+
</>
|
|
474
|
+
)}
|
|
475
|
+
<Tooltip formatter={(v: any) => v.toLocaleString(undefined, { maximumFractionDigits: 1 })} />
|
|
476
|
+
<Bar
|
|
477
|
+
dataKey="value"
|
|
478
|
+
name={metricLabel}
|
|
479
|
+
radius={[
|
|
480
|
+
3,
|
|
481
|
+
3,
|
|
482
|
+
0,
|
|
483
|
+
0
|
|
484
|
+
]}>
|
|
485
|
+
{chartData.map((_: any, i: number) => (
|
|
486
|
+
<Cell key={i} fill={COLORS[i % COLORS.length]} />
|
|
487
|
+
))}
|
|
488
|
+
</Bar>
|
|
489
|
+
</BarChart>
|
|
490
|
+
</ResponsiveContainer>
|
|
491
|
+
</div>
|
|
492
|
+
)}
|
|
493
|
+
|
|
494
|
+
{!isKpi && chartData.length > 0 && (
|
|
495
|
+
<div className="text-[10px] text-muted-foreground">
|
|
496
|
+
{metricLabel}{groupField ? ` by ${groupField}` : ''}
|
|
497
|
+
</div>
|
|
498
|
+
)}
|
|
499
|
+
|
|
500
|
+
{kpiValue === null && chartData.length === 0 && (
|
|
501
|
+
<div className="text-[10px] text-muted-foreground mt-auto">
|
|
502
|
+
{records.length > 0 ? `${records.length} records` : 'No data'}
|
|
503
|
+
</div>
|
|
504
|
+
)}
|
|
505
|
+
</div>
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function AppDashboardPreview({ page, widgets }: { page: any; widgets: any[] }) {
|
|
510
|
+
return (
|
|
511
|
+
<div className="flex flex-col h-full w-full overflow-hidden">
|
|
512
|
+
<div className="flex items-center gap-2 px-3 py-2 border-b bg-muted/30 shrink-0">
|
|
513
|
+
<LayoutDashboard className="size-4 text-muted-foreground" />
|
|
514
|
+
<span className="text-sm font-medium">{page.title}</span>
|
|
515
|
+
</div>
|
|
516
|
+
<div
|
|
517
|
+
className="flex-1 overflow-auto p-4"
|
|
518
|
+
style={{
|
|
519
|
+
background: 'radial-gradient(circle, #94a3b8 1.5px, transparent 1.5px) 0 0 / 22px 22px #f1f5f9'
|
|
520
|
+
}}>
|
|
521
|
+
<div className="grid grid-cols-2 gap-3">
|
|
522
|
+
{widgets.map((widget: any, i: number) => (
|
|
523
|
+
<WidgetSummary key={widget.id || i} widget={widget} />
|
|
524
|
+
))}
|
|
525
|
+
{widgets.length === 0 && (
|
|
526
|
+
<div className="col-span-2 text-sm text-muted-foreground text-center py-8">No widgets configured</div>
|
|
527
|
+
)}
|
|
528
|
+
</div>
|
|
529
|
+
</div>
|
|
530
|
+
</div>
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/*
|
|
535
|
+
* ─────────────────────────────────────────────────────────────
|
|
536
|
+
* AppPreviewDocument — mermaid diagrams + data structure table
|
|
537
|
+
* ─────────────────────────────────────────────────────────────
|
|
538
|
+
*/
|
|
539
|
+
|
|
540
|
+
function AppPreviewDocument({ app }: { app: any }) {
|
|
541
|
+
const [tab, setTab] = useState(0);
|
|
542
|
+
const tabs = ['Layout Structure', 'Data Structure Table', 'Data Structure Diagram'];
|
|
543
|
+
const layoutDiagram = generateLayoutDiagram(app);
|
|
544
|
+
const dataDiagram = generateDataStructureDiagram(app);
|
|
545
|
+
|
|
546
|
+
return (
|
|
547
|
+
<div className="flex flex-col h-full overflow-hidden">
|
|
548
|
+
<div className="flex border-b shrink-0">
|
|
549
|
+
{tabs.map((t, i) => (
|
|
550
|
+
<button
|
|
551
|
+
key={i}
|
|
552
|
+
onClick={() => setTab(i)}
|
|
553
|
+
className={cn(
|
|
554
|
+
'px-3 py-2 text-xs font-medium border-b-2 -mb-px',
|
|
555
|
+
tab === i ? 'border-primary text-primary' : 'border-transparent text-muted-foreground hover:text-foreground'
|
|
556
|
+
)}>
|
|
557
|
+
{t}
|
|
558
|
+
</button>
|
|
559
|
+
))}
|
|
560
|
+
</div>
|
|
561
|
+
<div className="flex-1 overflow-auto p-4">
|
|
562
|
+
{tab === 0 && (
|
|
563
|
+
<MermaidDiagram
|
|
564
|
+
title="Layout Structure"
|
|
565
|
+
mermaidNotation={layoutDiagram}
|
|
566
|
+
state="output-available" />
|
|
567
|
+
)}
|
|
568
|
+
{tab === 2 && (
|
|
569
|
+
<MermaidDiagram
|
|
570
|
+
title="Data Structure Diagram"
|
|
571
|
+
mermaidNotation={dataDiagram}
|
|
572
|
+
state="output-available" />
|
|
573
|
+
)}
|
|
574
|
+
{tab === 1 && (
|
|
575
|
+
<div className="text-sm space-y-6">
|
|
576
|
+
<div>
|
|
577
|
+
<h3 className="font-bold border-b pb-2 mb-3">Data Sources</h3>
|
|
578
|
+
<table className="w-full border border-gray-200 text-xs">
|
|
579
|
+
<thead className="bg-gray-50">
|
|
580
|
+
<tr>
|
|
581
|
+
{['Title', 'Name', 'Slug'].map(h => (
|
|
582
|
+
<th key={h} className="border border-gray-200 px-2 py-1 text-left">{h}</th>
|
|
583
|
+
))}
|
|
584
|
+
</tr>
|
|
585
|
+
</thead>
|
|
586
|
+
<tbody>
|
|
587
|
+
{(Array.isArray(app?.data_sources) ? app.data_sources : Object.values(app?.data_sources ?? {})).map((ds: any) => (
|
|
588
|
+
<tr key={ds.slug}>
|
|
589
|
+
<td className="border border-gray-200 px-2 py-1">{ds.title}</td>
|
|
590
|
+
<td className="border border-gray-200 px-2 py-1">{ds.name}</td>
|
|
591
|
+
<td className="border border-gray-200 px-2 py-1">{ds.slug}</td>
|
|
592
|
+
</tr>
|
|
593
|
+
))}
|
|
594
|
+
</tbody>
|
|
595
|
+
</table>
|
|
596
|
+
</div>
|
|
597
|
+
|
|
598
|
+
<div>
|
|
599
|
+
<h3 className="font-bold border-b pb-2 mb-3">Fields</h3>
|
|
600
|
+
{(Array.isArray(app?.data_sources) ? app.data_sources : Object.values(app?.data_sources ?? {})).map((ds: any) => (
|
|
601
|
+
<div key={ds.slug} className="border border-gray-300 bg-gray-50 rounded p-3 mb-3">
|
|
602
|
+
<div className="font-bold text-sm mb-2">
|
|
603
|
+
{ds.title}
|
|
604
|
+
{' '}
|
|
605
|
+
<span className="text-muted-foreground font-normal text-xs">{ds.name}</span>
|
|
606
|
+
</div>
|
|
607
|
+
<table className="w-full border border-gray-200 text-xs bg-white">
|
|
608
|
+
<thead className="bg-gray-50">
|
|
609
|
+
<tr>
|
|
610
|
+
{[
|
|
611
|
+
'Name',
|
|
612
|
+
'Slug',
|
|
613
|
+
'Type',
|
|
614
|
+
'Validations'
|
|
615
|
+
].map(h => (
|
|
616
|
+
<th key={h} className="border border-gray-200 px-2 py-1 text-left">{h}</th>
|
|
617
|
+
))}
|
|
618
|
+
</tr>
|
|
619
|
+
</thead>
|
|
620
|
+
<tbody>
|
|
621
|
+
{ds.fields?.map((field: any) => (
|
|
622
|
+
<tr key={field.id || field.slug}>
|
|
623
|
+
<td className="border border-gray-200 px-2 py-1">{field.name}</td>
|
|
624
|
+
<td className="border border-gray-200 px-2 py-1">{field.slug}</td>
|
|
625
|
+
<td className="border border-gray-200 px-2 py-1">{field.type}</td>
|
|
626
|
+
<td className="border border-gray-200 px-2 py-1 max-w-[200px] truncate">
|
|
627
|
+
{JSON.stringify(field.validations)}
|
|
628
|
+
</td>
|
|
629
|
+
</tr>
|
|
630
|
+
))}
|
|
631
|
+
</tbody>
|
|
632
|
+
</table>
|
|
633
|
+
</div>
|
|
634
|
+
))}
|
|
635
|
+
</div>
|
|
636
|
+
</div>
|
|
637
|
+
)}
|
|
638
|
+
</div>
|
|
639
|
+
</div>
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/*
|
|
644
|
+
* ─────────────────────────────────────────────────────────────
|
|
645
|
+
* CanvasAppView — main export (mirrors KvCanvasAppPreview.vue)
|
|
646
|
+
* ─────────────────────────────────────────────────────────────
|
|
647
|
+
*/
|
|
648
|
+
|
|
649
|
+
interface CanvasAppViewProps {
|
|
650
|
+
app: any;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
export function CanvasAppView({ app }: CanvasAppViewProps) {
|
|
654
|
+
// DEBUG — runs regardless of app being null
|
|
655
|
+
console.info('[CanvasAppView] render, app=', app);
|
|
656
|
+
|
|
657
|
+
const [activeTab, setActiveTab] = useState(0);
|
|
658
|
+
const [activeMenuId, setActiveMenuId] = useState<string | null>(() => {
|
|
659
|
+
const m = app?.layout?.menu;
|
|
660
|
+
|
|
661
|
+
if (!m) return null;
|
|
662
|
+
|
|
663
|
+
const first = Array.isArray(m) ? m[0] : Object.values(m)[0];
|
|
664
|
+
|
|
665
|
+
return (first as any)?.id ?? null;
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
if (!app) {
|
|
669
|
+
return (
|
|
670
|
+
<div className="flex h-full items-center justify-center text-sm text-muted-foreground">
|
|
671
|
+
No app data available
|
|
672
|
+
</div>
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// Normalize values that may arrive as {0:{...},1:{...}} objects or proper arrays
|
|
677
|
+
const toArray = (val: any): any[] => {
|
|
678
|
+
if (!val) return [];
|
|
679
|
+
if (Array.isArray(val)) return val;
|
|
680
|
+
if (typeof val === 'object') return Object.values(val);
|
|
681
|
+
|
|
682
|
+
return [];
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
const rawDataSources = toArray(app.data_sources);
|
|
686
|
+
const rawWidgets = toArray(app.layout?.widgets);
|
|
687
|
+
const menu = toArray(app.layout?.menu);
|
|
688
|
+
|
|
689
|
+
// DEBUG
|
|
690
|
+
console.info('[CanvasAppView] app.data_sources', app.data_sources);
|
|
691
|
+
console.info('[CanvasAppView] app.layout.dummy_data_json', app.layout?.dummy_data_json);
|
|
692
|
+
|
|
693
|
+
/*
|
|
694
|
+
* Parse dummy data from layout (mirrors Vue's dummyData parsing)
|
|
695
|
+
* Format can be either:
|
|
696
|
+
* { "ds_slug": [...records], "other_slug": [...] } — keyed by data source slug
|
|
697
|
+
* [...records] — flat array for single data source
|
|
698
|
+
* dummy_data_json may be a JSON string or already a parsed object/array.
|
|
699
|
+
*/
|
|
700
|
+
let dummyDataMap: Record<string, any[]> = {};
|
|
701
|
+
|
|
702
|
+
try {
|
|
703
|
+
const raw = app.layout?.dummy_data_json;
|
|
704
|
+
|
|
705
|
+
if (raw) {
|
|
706
|
+
const parsed = typeof raw === 'string' ? JSON.parse(raw) : raw;
|
|
707
|
+
|
|
708
|
+
if (Array.isArray(parsed)) {
|
|
709
|
+
// Flat array — assign to ALL possible keys for every data source
|
|
710
|
+
rawDataSources.forEach((ds: any) => {
|
|
711
|
+
if (ds.slug) dummyDataMap[ds.slug] = parsed;
|
|
712
|
+
if (ds.id) dummyDataMap[ds.id] = parsed;
|
|
713
|
+
if (ds.name) dummyDataMap[ds.name] = parsed;
|
|
714
|
+
});
|
|
715
|
+
dummyDataMap['__all__'] = parsed;
|
|
716
|
+
} else if (parsed && typeof parsed === 'object') {
|
|
717
|
+
// Keyed object (slug → records[])
|
|
718
|
+
dummyDataMap = parsed;
|
|
719
|
+
const firstArr = Object.values(parsed).find(v => Array.isArray(v));
|
|
720
|
+
|
|
721
|
+
if (firstArr) dummyDataMap['__all__'] = firstArr as any[];
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
} catch {
|
|
725
|
+
// invalid JSON, skip
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
const findRecords = (ds: any): any[] => dummyDataMap[ds.slug]
|
|
729
|
+
?? dummyDataMap[ds.id]
|
|
730
|
+
?? dummyDataMap[ds.name]
|
|
731
|
+
?? dummyDataMap['__all__']
|
|
732
|
+
?? [];
|
|
733
|
+
|
|
734
|
+
/*
|
|
735
|
+
* Prepare data sources with normalized fields + dummy records.
|
|
736
|
+
* Vue sets id = slug (useInlineDataSource({ id: ds.slug })), mirror that.
|
|
737
|
+
*/
|
|
738
|
+
const dataSources = rawDataSources.map((ds: any) => ({
|
|
739
|
+
...ds,
|
|
740
|
+
_originalId: ds.id, // keep UUID for widget lookup
|
|
741
|
+
id: ds.slug || ds.id,
|
|
742
|
+
slug: ds.slug || ds.id,
|
|
743
|
+
fields: toArray(ds.fields).map((f: any) => ({
|
|
744
|
+
...f,
|
|
745
|
+
id: f.id || f.slug,
|
|
746
|
+
type: f.type?.replace('field-', '') ?? f.type
|
|
747
|
+
})),
|
|
748
|
+
records: findRecords(ds)
|
|
749
|
+
}));
|
|
750
|
+
|
|
751
|
+
const findDataSource = (id: string | undefined) => {
|
|
752
|
+
if (!id) return undefined;
|
|
753
|
+
|
|
754
|
+
return dataSources.find(
|
|
755
|
+
(ds: any) => ds.id === id
|
|
756
|
+
|| ds.slug === id
|
|
757
|
+
|| ds.name === id
|
|
758
|
+
|| ds._originalId === id
|
|
759
|
+
);
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
// Prepare widgets — resolve dataSource, clear dataConfig.meta as Vue does
|
|
763
|
+
const widgets = rawWidgets.map((widget: any) => ({
|
|
764
|
+
...widget,
|
|
765
|
+
options: {
|
|
766
|
+
...widget.options,
|
|
767
|
+
dataConfig: { ...(widget.options?.dataConfig ?? {}), meta: [] },
|
|
768
|
+
dataSource: findDataSource(widget.options?.dataSourceId ?? widget.dataSourceId)
|
|
769
|
+
}
|
|
770
|
+
}));
|
|
771
|
+
|
|
772
|
+
const activeMenu = menu.find((m: any) => m.id === activeMenuId) ?? menu[0] ?? null;
|
|
773
|
+
|
|
774
|
+
// DEBUG
|
|
775
|
+
console.info('[CanvasAppView] dummyDataMap keys', Object.keys(dummyDataMap));
|
|
776
|
+
console.info('[CanvasAppView] dataSources', dataSources.map((ds: any) => ({ id: ds.id, slug: ds.slug, records: ds.records?.length })));
|
|
777
|
+
console.info('[CanvasAppView] widgets', widgets.map((w: any) => ({ title: w.title, dsId: w.options?.dataSourceId, resolved: !!w.options?.dataSource })));
|
|
778
|
+
console.info('[CanvasAppView] menu activeMenu', activeMenu?.type, activeMenu?.id);
|
|
779
|
+
|
|
780
|
+
const tabLabels = ['Preview', 'JSON', 'Docs'];
|
|
781
|
+
|
|
782
|
+
return (
|
|
783
|
+
<div className="flex flex-col h-full w-full overflow-hidden">
|
|
784
|
+
{/* Tab bar */}
|
|
785
|
+
<div className="flex border-b shrink-0 bg-background">
|
|
786
|
+
{tabLabels.map((t, i) => (
|
|
787
|
+
<button
|
|
788
|
+
key={i}
|
|
789
|
+
onClick={() => setActiveTab(i)}
|
|
790
|
+
className={cn(
|
|
791
|
+
'px-4 py-2 text-xs font-medium border-b-2 -mb-px transition-colors',
|
|
792
|
+
activeTab === i ? 'border-primary text-primary' : 'border-transparent text-muted-foreground hover:text-foreground'
|
|
793
|
+
)}>
|
|
794
|
+
{t}
|
|
795
|
+
</button>
|
|
796
|
+
))}
|
|
797
|
+
</div>
|
|
798
|
+
|
|
799
|
+
{/* Tab 0: App preview */}
|
|
800
|
+
{activeTab === 0 && (
|
|
801
|
+
<div className="flex flex-1 overflow-hidden">
|
|
802
|
+
<AppSidebar
|
|
803
|
+
data={menu}
|
|
804
|
+
title={app.layout?.title}
|
|
805
|
+
onMenuClick={setActiveMenuId} />
|
|
806
|
+
<div className="grow overflow-hidden">
|
|
807
|
+
{activeMenu?.type === 'board' && (
|
|
808
|
+
<AppBoardView page={activeMenu} dataSources={dataSources} />
|
|
809
|
+
)}
|
|
810
|
+
{activeMenu?.type === 'dashboard' && (
|
|
811
|
+
<AppDashboardPreview page={activeMenu} widgets={widgets} />
|
|
812
|
+
)}
|
|
813
|
+
{!activeMenu && (
|
|
814
|
+
<div className="flex h-full items-center justify-center text-sm text-muted-foreground">
|
|
815
|
+
Select a menu item to preview
|
|
816
|
+
</div>
|
|
817
|
+
)}
|
|
818
|
+
</div>
|
|
819
|
+
</div>
|
|
820
|
+
)}
|
|
821
|
+
|
|
822
|
+
{/* Tab 1: JSON editor */}
|
|
823
|
+
{activeTab === 1 && (
|
|
824
|
+
<div className="flex-1 overflow-auto p-4">
|
|
825
|
+
<pre className="text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all">
|
|
826
|
+
{JSON.stringify(app, null, 2)}
|
|
827
|
+
</pre>
|
|
828
|
+
</div>
|
|
829
|
+
)}
|
|
830
|
+
|
|
831
|
+
{/* Tab 2: Documentation */}
|
|
832
|
+
{activeTab === 2 && (
|
|
833
|
+
<div className="flex-1 overflow-hidden">
|
|
834
|
+
<AppPreviewDocument app={app} />
|
|
835
|
+
</div>
|
|
836
|
+
)}
|
|
837
|
+
</div>
|
|
838
|
+
);
|
|
839
|
+
}
|