@vite-hub/ui 0.1.0 → 0.4.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/README.md +247 -21
- package/dist/attachments-BzTwqRTU.js +90 -0
- package/dist/{avatar-stack-DXmCQhxd.d.ts → avatar-stack-DPRFuezh.d.ts} +1 -1
- package/dist/choices-input-ByXJvDn1.d.ts +94 -0
- package/dist/{code-view-J4OsgEdh.js → code-view-DsU-xzic.js} +20 -4
- package/dist/colors-BghReA9C-CjF9gnmy.js +28 -0
- package/dist/comment-attachments-C4yNbcx5.js +20 -0
- package/dist/comment-composer-fINL5bxo.d.ts +243 -0
- package/dist/comment-composer-jYv2ULNP.js +591 -0
- package/dist/comment-layer-C_sbPIR5.d.ts +176 -0
- package/dist/comment-list-BcSaLngS.d.ts +62 -0
- package/dist/comment-marks.css +234 -0
- package/dist/comment-panel-CfvdRUMX.d.ts +208 -0
- package/dist/comment-person-CLPlW_SS.js +40 -0
- package/dist/comment-pin-DHOdRvUw.d.ts +68 -0
- package/dist/comment-row-Bn3nr8l5.js +39 -0
- package/dist/comment-selection-bar-CyVBNYl9.d.ts +42 -0
- package/dist/comment-thread-DKJjmWN0.d.ts +385 -0
- package/dist/comment-visibility-DsVuVndP.d.ts +40 -0
- package/dist/{comments-C08J3z4e.js → comments-D0d26ghV.js} +210 -59
- package/dist/comments-D8hulVPy.d.ts +198 -0
- package/dist/comments-context-C2lOZyQ5.js +38 -0
- package/dist/config-DgxBW013.d.ts +80 -0
- package/dist/config-Dk67emQt.js +63 -0
- package/dist/copy-button-CRN3kmSD.js +253 -0
- package/dist/draw-DzSmD7uo-Dwz8zoH2.js +72976 -0
- package/dist/editor-C_wt4RRV.js +582 -0
- package/dist/error-diagnostics-SXtnk6bz.js +38 -0
- package/dist/{file-tree-C1pv4_AI.js → file-tree-C4OYgbV-.js} +292 -145
- package/dist/{file-tree-Ctb8hZ_g.d.ts → file-tree-DlT9RGhu.d.ts} +51 -15
- package/dist/format-orwcdZL_.js +39 -0
- package/dist/handlers-DMl-Na3x.js +182 -0
- package/dist/headless.d.ts +5 -176
- package/dist/headless.js +5 -3
- package/dist/icon-swap.css +69 -0
- package/dist/{image-preview-VfknBEFu.js → image-preview-C9tdkmEj.js} +8 -5
- package/dist/{index-DcH0QSI5.d.ts → index-BYRFQfCd.d.ts} +14 -0
- package/dist/{code-view-vDM-hph-.d.ts → index-CNY1uNTh.d.ts} +14 -228
- package/dist/index.d.ts +55 -57
- package/dist/index.js +678 -25
- package/dist/markdown-editor-CMbNZOdN.js +2394 -0
- package/dist/markdown-editor-wQF0yD5o.d.ts +195 -0
- package/dist/markdown-editor.d.ts +108 -0
- package/dist/markdown-editor.js +3 -0
- package/dist/message-scroller-jrYN9dG9.d.ts +175 -0
- package/dist/nuxt-ui-DSQFzq3s.js +38 -0
- package/dist/nuxt.d.ts +84 -2
- package/dist/nuxt.js +243 -35
- package/dist/parts/components/agent-session.d.ts +254 -0
- package/dist/parts/components/agent-session.js +640 -0
- package/dist/{attachment-BBndG9_P.d.ts → parts/components/attachment.d.ts} +14 -15
- package/dist/{attachment-B3dXC7jM.js → parts/components/attachment.js} +6 -4
- package/dist/{avatar-stack.d.ts → parts/components/avatar-stack.d.ts} +1 -1
- package/dist/{avatar-stack-DM6HRnc0.js → parts/components/avatar-stack.js} +2 -5
- package/dist/{bubble-BJH2rfii.d.ts → parts/components/bubble.d.ts} +7 -8
- package/dist/{bubble-BPyFQlW7.js → parts/components/bubble.js} +2 -2
- package/dist/{chat-message-mpDmZbIC.d.ts → parts/components/chat-message.d.ts} +2 -3
- package/dist/{chat-message-BNK9G7xF.js → parts/components/chat-message.js} +4 -4
- package/dist/{chat-session-D6C7VJBR.d.ts → parts/components/chat-session.d.ts} +3 -4
- package/dist/{chat-session-DYEHB1HC.js → parts/components/chat-session.js} +2 -2
- package/dist/{chat-B9HlZWA2.d.ts → parts/components/chat.d.ts} +8 -4
- package/dist/{chat-BoFHlu9V.js → parts/components/chat.js} +42 -9
- package/dist/{highlighted-code-Dzf6o54i.d.ts → parts/components/code-block.d.ts} +15 -23
- package/dist/{code-block-Br-02hn-.js → parts/components/code-block.js} +9 -38
- package/dist/parts/components/code-view.d.ts +270 -0
- package/dist/parts/components/code-view.js +2 -0
- package/dist/parts/components/comment-composer.d.ts +2 -0
- package/dist/parts/components/comment-composer.js +2 -0
- package/dist/parts/components/comment-layer.d.ts +2 -0
- package/dist/parts/components/comment-layer.js +631 -0
- package/dist/parts/components/comment-list.d.ts +2 -0
- package/dist/parts/components/comment-list.js +168 -0
- package/dist/parts/components/comment-panel.d.ts +2 -0
- package/dist/parts/components/comment-panel.js +311 -0
- package/dist/parts/components/comment-pin.d.ts +2 -0
- package/dist/parts/components/comment-pin.js +75 -0
- package/dist/parts/components/comment-selection-bar.d.ts +2 -0
- package/dist/parts/components/comment-selection-bar.js +116 -0
- package/dist/parts/components/comment-thread.d.ts +2 -0
- package/dist/parts/components/comment-thread.js +598 -0
- package/dist/parts/components/comments.d.ts +8 -0
- package/dist/parts/components/comments.js +9 -0
- package/dist/{connection-status-DjGBw6xX.d.ts → parts/components/connection-status.d.ts} +6 -7
- package/dist/{connection-status-CzuWBENf.js → parts/components/connection-status.js} +1 -1
- package/dist/parts/components/copy-button.d.ts +118 -0
- package/dist/parts/components/copy-button.js +2 -0
- package/dist/parts/components/device-frame.d.ts +130 -0
- package/dist/parts/components/device-frame.js +471 -0
- package/dist/parts/components/file-tree.d.ts +2 -0
- package/dist/parts/components/file-tree.js +2 -0
- package/dist/parts/components/filter-search.d.ts +47 -0
- package/dist/parts/components/filter-search.js +58 -0
- package/dist/parts/components/markdown-editor.d.ts +2 -0
- package/dist/parts/components/markdown-editor.js +2 -0
- package/dist/parts/components/markdown-renderer.d.ts +52 -0
- package/dist/parts/components/markdown-renderer.js +23077 -0
- package/dist/{markdown-Dse5ldJe.d.ts → parts/components/markdown.d.ts} +7 -7
- package/dist/parts/components/markdown.js +47 -0
- package/dist/{marker-ea-tvx-J.d.ts → parts/components/marker.d.ts} +6 -7
- package/dist/{marker-Di2ZG_k1.js → parts/components/marker.js} +2 -2
- package/dist/{message-parts-BBFUkluC.d.ts → parts/components/message-parts.d.ts} +2 -3
- package/dist/{message-parts-DQnfioAH.js → parts/components/message-parts.js} +6 -6
- package/dist/{message-CW_paC1k.d.ts → parts/components/message.d.ts} +8 -9
- package/dist/{message-DiyBthIq.js → parts/components/message.js} +2 -2
- package/dist/parts/components/patch-parsers.d.ts +2 -0
- package/dist/parts/components/patch-parsers.js +2 -0
- package/dist/{prompt-input-Cy_Ue6B5.d.ts → parts/components/prompt-input.d.ts} +53 -10
- package/dist/{prompt-input-BbnCb80O.js → parts/components/prompt-input.js} +66 -111
- package/dist/parts/components/relative-time.d.ts +73 -0
- package/dist/parts/components/relative-time.js +2 -0
- package/dist/parts/components/status.d.ts +60 -0
- package/dist/parts/components/status.js +48 -0
- package/dist/{sync-status-refELOZn.d.ts → parts/components/sync-status.d.ts} +5 -6
- package/dist/{sync-status-BpxYdZIJ.js → parts/components/sync-status.js} +1 -1
- package/dist/{tool-list-E7CA52rz.d.ts → parts/components/tool-list.d.ts} +3 -4
- package/dist/{tool-list-BdSr5CT4.js → parts/components/tool-list.js} +7 -38
- package/dist/{trace-run-COeXn46Z.d.ts → parts/components/trace-run.d.ts} +3 -4
- package/dist/{trace-run-BIQ17CED.js → parts/components/trace-run.js} +15 -23
- package/dist/{trace-V7rM3Pyd.d.ts → parts/components/trace.d.ts} +11 -12
- package/dist/{trace-llBCDiSW.js → parts/components/trace.js} +20 -13
- package/dist/parts/composables/attachments.d.ts +32 -0
- package/dist/parts/composables/attachments.js +2 -0
- package/dist/parts/composables/highlighted-code.d.ts +9 -0
- package/dist/{highlighted-code-Ck4zexJX.js → parts/composables/highlighted-code.js} +5 -2
- package/dist/parts/headless/choices-input.d.ts +2 -0
- package/dist/parts/headless/choices-input.js +162 -0
- package/dist/parts/headless/comment-visibility.d.ts +2 -0
- package/dist/parts/headless/comment-visibility.js +128 -0
- package/dist/parts/headless/comments.d.ts +2 -0
- package/dist/parts/headless/comments.js +2 -0
- package/dist/parts/headless/message-scroller.d.ts +2 -0
- package/dist/{message-scroller-CX6NJTdm.js → parts/headless/message-scroller.js} +2 -2
- package/dist/parts/playground/highlight.d.ts +5 -0
- package/dist/parts/playground/highlight.js +23 -0
- package/dist/parts/playground/paths.d.ts +4 -0
- package/dist/parts/playground/paths.js +7 -0
- package/dist/parts/playground/playground-render.d.ts +126 -0
- package/dist/parts/playground/playground-render.js +356 -0
- package/dist/parts/playground/share.d.ts +2 -0
- package/dist/parts/playground/share.js +92 -0
- package/dist/parts/playground/zip.d.ts +6 -0
- package/dist/parts/playground/zip.js +76 -0
- package/dist/parts/workspace/browser-support-notice.d.ts +76 -0
- package/dist/parts/workspace/browser-support-notice.js +105 -0
- package/dist/parts/workspace/codemirror.d.ts +16 -0
- package/dist/parts/workspace/codemirror.js +243 -0
- package/dist/parts/workspace/connect-panel.d.ts +129 -0
- package/dist/parts/workspace/connect-panel.js +285 -0
- package/dist/parts/workspace/connect-store.d.ts +26 -0
- package/dist/parts/workspace/connect-store.js +59 -0
- package/dist/parts/workspace/icons.d.ts +34 -0
- package/dist/parts/workspace/icons.js +46 -0
- package/dist/parts/workspace/playground-container.d.ts +192 -0
- package/dist/parts/workspace/playground-container.js +603 -0
- package/dist/parts/workspace/workspace-boot-status.d.ts +75 -0
- package/dist/parts/workspace/workspace-boot-status.js +207 -0
- package/dist/parts/workspace/workspace-editor.d.ts +43 -0
- package/dist/parts/workspace/workspace-editor.js +54 -0
- package/dist/parts/workspace/workspace-file-tree.d.ts +53 -0
- package/dist/parts/workspace/workspace-file-tree.js +68 -0
- package/dist/parts/workspace/workspace-preview.d.ts +72 -0
- package/dist/parts/workspace/workspace-preview.js +307 -0
- package/dist/parts/workspace/workspace-shell.d.ts +88 -0
- package/dist/parts/workspace/workspace-shell.js +291 -0
- package/dist/parts/workspace/workspace-terminal.d.ts +39 -0
- package/dist/parts/workspace/workspace-terminal.js +130 -0
- package/dist/payload-text-sjkYAwvw.js +32 -0
- package/dist/{pierre-code-view-T7V67hwT.js → pierre-code-view-NE35tkmR.js} +245 -102
- package/dist/{pierre-dark-DDWDl8g6.js → pierre-dark-CzUmjETS.js} +3 -1
- package/dist/{pierre-light-CWhW4NrH.js → pierre-light-Dn6E0sWv.js} +3 -1
- package/dist/playground.d.ts +4 -0
- package/dist/playground.js +4 -0
- package/dist/relative-time-BVmjOsYG.js +309 -0
- package/dist/rolldown-runtime-C9mWXvCC.js +29 -0
- package/dist/runtime/nuxt-plugin.js +23 -4
- package/dist/sankey-CAYwt82B-D4uDQoMR.js +2887 -0
- package/dist/share-DM4eNy4q.d.ts +37 -0
- package/dist/{slot-part-C7Ocxn3b.js → slot-part-Doic71uh.js} +7 -1
- package/dist/styles.css +2609 -620
- package/dist/temml-BilSAAws.js +12362 -0
- package/dist/theme-focus-ring.css +42 -0
- package/dist/theme.css +376 -0
- package/dist/theme.d.ts +355 -0
- package/dist/theme.js +265 -0
- package/dist/{types-CqDwuJAm.d.ts → types-Dj7vp0lZ.d.ts} +1 -1
- package/dist/vue-BDmSCtay.js +30779 -0
- package/dist/vue-DGstVdGn.js +2492 -0
- package/dist/workspace.d.ts +15 -0
- package/dist/workspace.js +12 -0
- package/package.json +135 -149
- package/dist/andromeeda-BASpqCeJ.js +0 -4
- package/dist/attachment.d.ts +0 -2
- package/dist/attachment.js +0 -2
- package/dist/aurora-x-DugsLcii.js +0 -4
- package/dist/avatar-stack.js +0 -2
- package/dist/ayu-dark-BT3qdi3o.js +0 -4
- package/dist/ayu-light-BVZyHoh9.js +0 -4
- package/dist/ayu-mirage-XFwUVZQZ.js +0 -4
- package/dist/bubble.d.ts +0 -2
- package/dist/bubble.js +0 -2
- package/dist/catppuccin-frappe-D20KODDN.js +0 -4
- package/dist/catppuccin-latte-eGLVHIUJ.js +0 -4
- package/dist/catppuccin-macchiato-bQGch4PY.js +0 -4
- package/dist/catppuccin-mocha-Bes8-0Mr.js +0 -4
- package/dist/chat-message.d.ts +0 -2
- package/dist/chat-message.js +0 -2
- package/dist/chat-session.d.ts +0 -2
- package/dist/chat-session.js +0 -2
- package/dist/chat.d.ts +0 -2
- package/dist/chat.js +0 -2
- package/dist/code-block.d.ts +0 -2
- package/dist/code-block.js +0 -3
- package/dist/code-view.d.ts +0 -2
- package/dist/code-view.js +0 -2
- package/dist/comment-layer-CBlxJ8eK.js +0 -1113
- package/dist/comments-ChNJkV1d.d.ts +0 -108
- package/dist/comments-Cq5eewsu.d.ts +0 -537
- package/dist/comments.d.ts +0 -2
- package/dist/comments.js +0 -2
- package/dist/config-Bux_AJzm.d.ts +0 -29
- package/dist/config-bHqE4JOs.js +0 -38
- package/dist/connection-status.d.ts +0 -2
- package/dist/connection-status.js +0 -2
- package/dist/dark-plus-BGuiqa1B.js +0 -4
- package/dist/dracula-0CVA2XY5.js +0 -4
- package/dist/dracula-soft-Dk9bpbVU.js +0 -4
- package/dist/error-diagnostics-B4hMpJRL.js +0 -13
- package/dist/everforest-dark-CRjTbhh5.js +0 -4
- package/dist/everforest-light-CEeYFLn8.js +0 -4
- package/dist/file-diff.d.ts +0 -2
- package/dist/file-diff.js +0 -2
- package/dist/file-tree.d.ts +0 -2
- package/dist/file-tree.js +0 -2
- package/dist/file-view.d.ts +0 -2
- package/dist/file-view.js +0 -2
- package/dist/github-dark-BXgKmOw_.js +0 -4
- package/dist/github-dark-default-DzJQXksd.js +0 -4
- package/dist/github-dark-dimmed-B1pEmGtS.js +0 -4
- package/dist/github-dark-high-contrast-BkHIa6jc.js +0 -4
- package/dist/github-light-BKRlUbaB.js +0 -4
- package/dist/github-light-default-BU3eYkzs.js +0 -4
- package/dist/github-light-high-contrast-B3MumDcI.js +0 -4
- package/dist/gruvbox-dark-hard-B0ecF443.js +0 -4
- package/dist/gruvbox-dark-medium-BQnpC39k.js +0 -4
- package/dist/gruvbox-dark-soft-DFZUgESr.js +0 -4
- package/dist/gruvbox-light-hard-CuB_LOJr.js +0 -4
- package/dist/gruvbox-light-medium-idDHgxjs.js +0 -4
- package/dist/gruvbox-light-soft-CfWH49MY.js +0 -4
- package/dist/horizon-bright-Ba6M8QSV.js +0 -4
- package/dist/horizon-h92C5OlZ.js +0 -4
- package/dist/houston-EQnPegWq.js +0 -4
- package/dist/kanagawa-dragon-DgDvwi3B.js +0 -4
- package/dist/kanagawa-lotus-BgoQro20.js +0 -4
- package/dist/kanagawa-wave-DgXEowHs.js +0 -4
- package/dist/laserwave-IxBH_3yW.js +0 -4
- package/dist/light-plus-S8JBx6is.js +0 -4
- package/dist/markdown-BoLBN0qH.js +0 -197
- package/dist/markdown.d.ts +0 -2
- package/dist/markdown.js +0 -2
- package/dist/marker.d.ts +0 -2
- package/dist/marker.js +0 -2
- package/dist/material-theme-D1f3HBq-.js +0 -4
- package/dist/material-theme-darker-ExzYhT0j.js +0 -4
- package/dist/material-theme-lighter-D6gH9nnA.js +0 -4
- package/dist/material-theme-ocean-D1w5BPAa.js +0 -4
- package/dist/material-theme-palenight-CkqWmVpF.js +0 -4
- package/dist/message-parts.d.ts +0 -2
- package/dist/message-parts.js +0 -2
- package/dist/message.d.ts +0 -2
- package/dist/message.js +0 -2
- package/dist/min-dark-npsJH98j.js +0 -4
- package/dist/min-light-DUk1XsVt.js +0 -4
- package/dist/monokai-CfFRWUNl.js +0 -4
- package/dist/multi-file-diff.d.ts +0 -2
- package/dist/multi-file-diff.js +0 -2
- package/dist/night-owl-BS7V-av_.js +0 -4
- package/dist/night-owl-light-CZtRawYE.js +0 -4
- package/dist/nord-BFh54Nqz.js +0 -4
- package/dist/one-dark-pro-zDovGosB.js +0 -4
- package/dist/one-light-gmHK3iK6.js +0 -4
- package/dist/patch-diff.d.ts +0 -2
- package/dist/patch-diff.js +0 -2
- package/dist/plastic-DtdaCjub.js +0 -4
- package/dist/poimandres-Hdda6aHK.js +0 -4
- package/dist/primitive-rail.d.ts +0 -222
- package/dist/primitive-rail.js +0 -348
- package/dist/prompt-input.d.ts +0 -2
- package/dist/prompt-input.js +0 -2
- package/dist/red-VqZFRByZ.js +0 -4
- package/dist/rose-pine-DiTkEueR.js +0 -4
- package/dist/rose-pine-dawn-tfo5y2X0.js +0 -4
- package/dist/rose-pine-moon-C0gON9XN.js +0 -4
- package/dist/runtime-type-DlCscMfw.js +0 -59
- package/dist/slack-dark-v8P_eXr6.js +0 -4
- package/dist/slack-ochin-D8SyEdKz.js +0 -4
- package/dist/snazzy-light-BtkQkvXb.js +0 -4
- package/dist/solarized-dark-B8nAdMfM.js +0 -4
- package/dist/solarized-light-B-3F1INj.js +0 -4
- package/dist/sync-status.d.ts +0 -2
- package/dist/sync-status.js +0 -2
- package/dist/synthwave-84-DcsXCF_c.js +0 -4
- package/dist/tokyo-night-Bvpqduda.js +0 -4
- package/dist/tool-list.d.ts +0 -2
- package/dist/tool-list.js +0 -2
- package/dist/trace-run.d.ts +0 -2
- package/dist/trace-run.js +0 -2
- package/dist/trace.d.ts +0 -2
- package/dist/trace.js +0 -2
- package/dist/unresolved-file.d.ts +0 -2
- package/dist/unresolved-file.js +0 -2
- package/dist/vesper-CfxmMOy3.js +0 -4
- package/dist/vitesse-black-D9-_1mjV.js +0 -4
- package/dist/vitesse-dark-DlSMLlr9.js +0 -4
- package/dist/vitesse-light-KRWWWztf.js +0 -4
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { r as useUIComponent } from "../../nuxt-ui-DSQFzq3s.js";
|
|
2
|
+
import { DeviceFrame } from "../components/device-frame.js";
|
|
3
|
+
import { icon } from "./icons.js";
|
|
4
|
+
import { computed, defineComponent, h, onBeforeUnmount, onMounted, ref, shallowRef, useId, watch } from "vue";
|
|
5
|
+
//#region src/workspace/workspace-preview.ts
|
|
6
|
+
function join(base, path) {
|
|
7
|
+
try {
|
|
8
|
+
return new URL(path || "/", base).href;
|
|
9
|
+
} catch {
|
|
10
|
+
return base;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Runs first in every HTML page of the preview: pass it to `useWebContainer({ previewScript })`. The preview is
|
|
15
|
+
* cross-origin, so the page around it cannot read its address or its history. This script sends the page address to
|
|
16
|
+
* `WorkspacePreview` through a `MessagePort`, and goes Back, Forward, or reloads when the preview asks. A page that runs
|
|
17
|
+
* in its own tab does nothing.
|
|
18
|
+
*/
|
|
19
|
+
const workspacePreviewScript = `(() => {
|
|
20
|
+
if (window.top === window) return;
|
|
21
|
+
const { port1: port, port2 } = new MessageChannel();
|
|
22
|
+
const navigation = window.navigation;
|
|
23
|
+
const report = () => port.postMessage({
|
|
24
|
+
type: "location",
|
|
25
|
+
path: location.pathname + location.search + location.hash,
|
|
26
|
+
back: navigation ? navigation.canGoBack : true,
|
|
27
|
+
forward: navigation ? navigation.canGoForward : true,
|
|
28
|
+
});
|
|
29
|
+
for (const name of ["pushState", "replaceState"]) {
|
|
30
|
+
const original = history[name];
|
|
31
|
+
history[name] = function (...args) {
|
|
32
|
+
const result = original.apply(this, args);
|
|
33
|
+
report();
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
addEventListener("popstate", report);
|
|
38
|
+
addEventListener("hashchange", report);
|
|
39
|
+
port.onmessage = ({ data }) => {
|
|
40
|
+
if (data === "back") history.back();
|
|
41
|
+
else if (data === "forward") history.forward();
|
|
42
|
+
else if (data === "reload") location.reload();
|
|
43
|
+
};
|
|
44
|
+
window.top.postMessage({ type: "vitehub:preview" }, "*", [port2]);
|
|
45
|
+
report();
|
|
46
|
+
})();`;
|
|
47
|
+
function readLocation(data) {
|
|
48
|
+
if (!data || typeof data !== "object") return void 0;
|
|
49
|
+
const { type, path, back, forward } = data;
|
|
50
|
+
if (type !== "location" || typeof path !== "string") return void 0;
|
|
51
|
+
return {
|
|
52
|
+
path,
|
|
53
|
+
back: back === true,
|
|
54
|
+
forward: forward === true
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Whether `source` is `frame` or a frame inside it. The preview origin wraps the app in frames of its own. */
|
|
58
|
+
function isInside(source, frame) {
|
|
59
|
+
let current = source;
|
|
60
|
+
for (let depth = 0; frame && current && typeof current === "object" && depth < 8; depth++) {
|
|
61
|
+
if (current === frame) return true;
|
|
62
|
+
const parent = Reflect.get(current, "parent");
|
|
63
|
+
if (parent === current) return false;
|
|
64
|
+
current = parent;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const devices = [
|
|
69
|
+
{
|
|
70
|
+
id: "desktop",
|
|
71
|
+
label: "Desktop",
|
|
72
|
+
icon: "monitor"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: "tablet",
|
|
76
|
+
label: "Tablet",
|
|
77
|
+
icon: "tablet"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: "phone",
|
|
81
|
+
label: "Phone",
|
|
82
|
+
icon: "smartphone"
|
|
83
|
+
}
|
|
84
|
+
];
|
|
85
|
+
const presets = [{
|
|
86
|
+
id: "tablet",
|
|
87
|
+
label: "Tablet",
|
|
88
|
+
kind: "tablet",
|
|
89
|
+
width: 768,
|
|
90
|
+
height: 1024
|
|
91
|
+
}, {
|
|
92
|
+
id: "phone",
|
|
93
|
+
label: "Phone",
|
|
94
|
+
kind: "phone",
|
|
95
|
+
width: 390,
|
|
96
|
+
height: 844
|
|
97
|
+
}];
|
|
98
|
+
const storageKey = "vitehub:workspace-preview:device";
|
|
99
|
+
function sizeOf(device) {
|
|
100
|
+
const preset = presets.find((item) => item.id === device) ?? presets[0];
|
|
101
|
+
return {
|
|
102
|
+
on: device !== "desktop",
|
|
103
|
+
id: preset.id,
|
|
104
|
+
width: preset.width,
|
|
105
|
+
height: preset.height,
|
|
106
|
+
zoom: null
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function storedDevice() {
|
|
110
|
+
if (typeof localStorage === "undefined") return "desktop";
|
|
111
|
+
try {
|
|
112
|
+
const value = localStorage.getItem(storageKey);
|
|
113
|
+
return devices.find((item) => item.id === value)?.id ?? "desktop";
|
|
114
|
+
} catch {
|
|
115
|
+
return "desktop";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The preview of the dev server, in a browser frame: Back, Forward, Reload, the address of the page, a device width
|
|
120
|
+
* switch, and Open in new tab. The page cannot `fetch()` the WebContainer preview origin, so an iframe is the only way
|
|
121
|
+
* to show it. Back, Forward, and an address that follows links in the app need `workspacePreviewScript` in the
|
|
122
|
+
* WebContainer. Without it, the bar shows the path that it opened.
|
|
123
|
+
*/
|
|
124
|
+
const WorkspacePreview = defineComponent({
|
|
125
|
+
name: "WorkspacePreview",
|
|
126
|
+
props: {
|
|
127
|
+
/** The preview URL, such as `workspace.previewUrl`. Unset until the dev server is ready. */
|
|
128
|
+
url: {
|
|
129
|
+
default: void 0,
|
|
130
|
+
type: String
|
|
131
|
+
},
|
|
132
|
+
/** The path that the frame opens. Use `v-model:path`. */
|
|
133
|
+
path: {
|
|
134
|
+
default: "/",
|
|
135
|
+
type: String
|
|
136
|
+
},
|
|
137
|
+
title: {
|
|
138
|
+
default: "App preview",
|
|
139
|
+
type: String
|
|
140
|
+
},
|
|
141
|
+
/** The width of the page. Use `v-model:device`. Defaults to the last width that the reader picked. */
|
|
142
|
+
device: {
|
|
143
|
+
default: void 0,
|
|
144
|
+
type: String
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
emits: {
|
|
148
|
+
"update:path": (path) => typeof path === "string",
|
|
149
|
+
"update:device": (device) => typeof device === "string"
|
|
150
|
+
},
|
|
151
|
+
setup(props, { emit, expose, slots }) {
|
|
152
|
+
const inputId = useId();
|
|
153
|
+
const UInput = useUIComponent("UInput");
|
|
154
|
+
const reloads = ref(0);
|
|
155
|
+
const src = computed(() => props.url ? join(props.url, props.path) : void 0);
|
|
156
|
+
const live = shallowRef();
|
|
157
|
+
const port = shallowRef();
|
|
158
|
+
let appWindow;
|
|
159
|
+
const frame = ref();
|
|
160
|
+
const current = computed(() => live.value?.path ?? props.path);
|
|
161
|
+
const draft = ref(current.value);
|
|
162
|
+
watch(current, (path) => {
|
|
163
|
+
draft.value = path;
|
|
164
|
+
});
|
|
165
|
+
watch(() => `${src.value}#${reloads.value}`, () => {
|
|
166
|
+
live.value = void 0;
|
|
167
|
+
port.value?.close();
|
|
168
|
+
port.value = void 0;
|
|
169
|
+
appWindow = void 0;
|
|
170
|
+
});
|
|
171
|
+
function onMessage(event) {
|
|
172
|
+
const data = event.data;
|
|
173
|
+
if (!data || typeof data !== "object" || Reflect.get(data, "type") !== "vitehub:preview") return;
|
|
174
|
+
const next = event.ports[0];
|
|
175
|
+
if (!next || !isInside(event.source, frame.value?.contentWindow)) return;
|
|
176
|
+
if (appWindow && event.source !== appWindow && !isInside(appWindow, event.source)) {
|
|
177
|
+
next.close();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
appWindow = event.source;
|
|
181
|
+
port.value?.close();
|
|
182
|
+
live.value = void 0;
|
|
183
|
+
port.value = next;
|
|
184
|
+
next.onmessage = (message) => {
|
|
185
|
+
const location = readLocation(message.data);
|
|
186
|
+
if (port.value === next && location) live.value = location;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
onMounted(() => window.addEventListener("message", onMessage));
|
|
190
|
+
onBeforeUnmount(() => {
|
|
191
|
+
window.removeEventListener("message", onMessage);
|
|
192
|
+
port.value?.close();
|
|
193
|
+
});
|
|
194
|
+
function go() {
|
|
195
|
+
const path = draft.value.startsWith("/") ? draft.value : `/${draft.value}`;
|
|
196
|
+
draft.value = path;
|
|
197
|
+
if (path === props.path) reloads.value++;
|
|
198
|
+
else emit("update:path", path);
|
|
199
|
+
}
|
|
200
|
+
function reload() {
|
|
201
|
+
if (port.value) port.value.postMessage("reload");
|
|
202
|
+
else reloads.value++;
|
|
203
|
+
}
|
|
204
|
+
const step = (direction) => port.value?.postMessage(direction);
|
|
205
|
+
expose({ reload });
|
|
206
|
+
const picked = ref(props.device ?? "desktop");
|
|
207
|
+
const size = ref(sizeOf(picked.value));
|
|
208
|
+
function show(device) {
|
|
209
|
+
picked.value = device;
|
|
210
|
+
size.value = sizeOf(device);
|
|
211
|
+
}
|
|
212
|
+
onMounted(() => {
|
|
213
|
+
if (!props.device) show(storedDevice());
|
|
214
|
+
});
|
|
215
|
+
watch(() => props.device, (device) => {
|
|
216
|
+
if (device && device !== picked.value) show(device);
|
|
217
|
+
});
|
|
218
|
+
function pick(device) {
|
|
219
|
+
show(device);
|
|
220
|
+
try {
|
|
221
|
+
localStorage.setItem(storageKey, device);
|
|
222
|
+
} catch {}
|
|
223
|
+
emit("update:device", device);
|
|
224
|
+
}
|
|
225
|
+
const button = (name, label, title, disabled, onClick) => h("button", {
|
|
226
|
+
"aria-label": label,
|
|
227
|
+
class: "vh-ws-icon-button",
|
|
228
|
+
disabled,
|
|
229
|
+
title,
|
|
230
|
+
type: "button",
|
|
231
|
+
onClick
|
|
232
|
+
}, [icon(name)]);
|
|
233
|
+
return () => {
|
|
234
|
+
const connected = !!port.value && !!src.value;
|
|
235
|
+
return h("div", {
|
|
236
|
+
class: "vh-ws-preview",
|
|
237
|
+
"data-device": picked.value
|
|
238
|
+
}, [h("form", {
|
|
239
|
+
class: "vh-ws-preview-bar",
|
|
240
|
+
onSubmit(event) {
|
|
241
|
+
event.preventDefault();
|
|
242
|
+
go();
|
|
243
|
+
}
|
|
244
|
+
}, [
|
|
245
|
+
button("arrow-left", "Go back", "Back", !connected || !live.value?.back, () => step("back")),
|
|
246
|
+
button("arrow-right", "Go forward", "Forward", !connected || !live.value?.forward, () => step("forward")),
|
|
247
|
+
button("rotate-cw", "Reload preview", "Reload", !src.value, reload),
|
|
248
|
+
h("label", {
|
|
249
|
+
class: "vh-ws-sr-only",
|
|
250
|
+
for: inputId
|
|
251
|
+
}, "Preview path"),
|
|
252
|
+
h(UInput, {
|
|
253
|
+
autocapitalize: "off",
|
|
254
|
+
autocomplete: "off",
|
|
255
|
+
class: "vh-ws-preview-path",
|
|
256
|
+
disabled: !src.value,
|
|
257
|
+
id: inputId,
|
|
258
|
+
modelValue: draft.value,
|
|
259
|
+
spellcheck: false,
|
|
260
|
+
"onUpdate:modelValue": (value) => {
|
|
261
|
+
draft.value = String(value);
|
|
262
|
+
}
|
|
263
|
+
}),
|
|
264
|
+
h("div", {
|
|
265
|
+
"aria-label": "Device width",
|
|
266
|
+
class: "vh-ws-preview-devices",
|
|
267
|
+
role: "group"
|
|
268
|
+
}, devices.map((device) => h("button", {
|
|
269
|
+
"aria-label": device.label,
|
|
270
|
+
"aria-pressed": picked.value === device.id ? "true" : "false",
|
|
271
|
+
class: "vh-ws-icon-button",
|
|
272
|
+
key: device.id,
|
|
273
|
+
title: device.id === "desktop" ? device.label : `${device.label}, ${sizeOf(device.id).width} pixels wide`,
|
|
274
|
+
type: "button",
|
|
275
|
+
onClick: () => pick(device.id)
|
|
276
|
+
}, [icon(device.icon)]))),
|
|
277
|
+
h("a", {
|
|
278
|
+
"aria-disabled": src.value ? void 0 : "true",
|
|
279
|
+
"aria-label": "Open preview in a new tab",
|
|
280
|
+
class: "vh-ws-icon-button",
|
|
281
|
+
href: props.url ? join(props.url, current.value) : void 0,
|
|
282
|
+
rel: "noopener",
|
|
283
|
+
target: "_blank",
|
|
284
|
+
title: "Open in new tab"
|
|
285
|
+
}, [icon("external-link")])
|
|
286
|
+
]), src.value ? h(DeviceFrame, {
|
|
287
|
+
breakpoints: [],
|
|
288
|
+
insetBottom: 16,
|
|
289
|
+
modelValue: size.value,
|
|
290
|
+
presets,
|
|
291
|
+
toolbar: false,
|
|
292
|
+
"onUpdate:modelValue": (next) => {
|
|
293
|
+
size.value = next;
|
|
294
|
+
}
|
|
295
|
+
}, () => h("iframe", {
|
|
296
|
+
allow: "cross-origin-isolated; clipboard-read; clipboard-write",
|
|
297
|
+
class: "vh-ws-preview-frame",
|
|
298
|
+
key: `${src.value}#${reloads.value}`,
|
|
299
|
+
ref: frame,
|
|
300
|
+
src: src.value,
|
|
301
|
+
title: props.title
|
|
302
|
+
})) : h("div", { class: "vh-ws-empty" }, slots.empty?.() ?? [h("p", { class: "vh-ws-empty-title" }, "No preview yet"), h("p", { class: "vh-ws-muted" }, "The preview opens here when the dev server is ready.")])]);
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
//#endregion
|
|
307
|
+
export { WorkspacePreview, workspacePreviewScript };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { PropType, VNode } from "vue";
|
|
2
|
+
//#region src/workspace/workspace-shell.d.ts
|
|
3
|
+
export type WorkspaceLayout = "tutorial" | "playground";
|
|
4
|
+
/** A built-in panel, or the slot name of a panel that the page adds. */
|
|
5
|
+
export type WorkspaceTab = "preview" | "terminal" | "connect" | (string & {});
|
|
6
|
+
/** One tab of the panel group. It shows the slot with the name `value`. */
|
|
7
|
+
export interface WorkspaceTabItem {
|
|
8
|
+
value: WorkspaceTab;
|
|
9
|
+
label: string;
|
|
10
|
+
/** A short count or state next to the label, such as the number of connected accounts. */
|
|
11
|
+
badge?: string | number;
|
|
12
|
+
}
|
|
13
|
+
/** Split sizes. `files` is in pixels. `main` and `side` are percents of the shell. */
|
|
14
|
+
export interface WorkspaceSplits {
|
|
15
|
+
files: number;
|
|
16
|
+
main: number;
|
|
17
|
+
side: number;
|
|
18
|
+
}
|
|
19
|
+
export declare const WorkspaceShell: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
20
|
+
layout: {
|
|
21
|
+
default: string;
|
|
22
|
+
type: PropType<WorkspaceLayout>;
|
|
23
|
+
};
|
|
24
|
+
/** The visible tab. Use `v-model:tab`. */
|
|
25
|
+
tab: {
|
|
26
|
+
default: undefined;
|
|
27
|
+
type: PropType<WorkspaceTab>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The tabs of the panel group, in order. Each tab shows the slot with the name of its `value`. Defaults to Preview,
|
|
31
|
+
* Terminal, and Connect, for the slots that are set. A playground shows the preview at the side, never as a tab.
|
|
32
|
+
*/
|
|
33
|
+
tabs: {
|
|
34
|
+
default: undefined;
|
|
35
|
+
type: PropType<readonly WorkspaceTabItem[]>;
|
|
36
|
+
};
|
|
37
|
+
/** The localStorage key for split sizes. `false` keeps them in memory. Defaults to one key per layout. */
|
|
38
|
+
storageKey: {
|
|
39
|
+
default: undefined;
|
|
40
|
+
type: PropType<string | false>;
|
|
41
|
+
};
|
|
42
|
+
/** The accessible name of the workspace region. */
|
|
43
|
+
label: {
|
|
44
|
+
default: string;
|
|
45
|
+
type: StringConstructor;
|
|
46
|
+
};
|
|
47
|
+
}>, () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
50
|
+
"update:tab": (tab: WorkspaceTab) => boolean;
|
|
51
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
52
|
+
layout: {
|
|
53
|
+
default: string;
|
|
54
|
+
type: PropType<WorkspaceLayout>;
|
|
55
|
+
};
|
|
56
|
+
/** The visible tab. Use `v-model:tab`. */
|
|
57
|
+
tab: {
|
|
58
|
+
default: undefined;
|
|
59
|
+
type: PropType<WorkspaceTab>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* The tabs of the panel group, in order. Each tab shows the slot with the name of its `value`. Defaults to Preview,
|
|
63
|
+
* Terminal, and Connect, for the slots that are set. A playground shows the preview at the side, never as a tab.
|
|
64
|
+
*/
|
|
65
|
+
tabs: {
|
|
66
|
+
default: undefined;
|
|
67
|
+
type: PropType<readonly WorkspaceTabItem[]>;
|
|
68
|
+
};
|
|
69
|
+
/** The localStorage key for split sizes. `false` keeps them in memory. Defaults to one key per layout. */
|
|
70
|
+
storageKey: {
|
|
71
|
+
default: undefined;
|
|
72
|
+
type: PropType<string | false>;
|
|
73
|
+
};
|
|
74
|
+
/** The accessible name of the workspace region. */
|
|
75
|
+
label: {
|
|
76
|
+
default: string;
|
|
77
|
+
type: StringConstructor;
|
|
78
|
+
};
|
|
79
|
+
}>> & Readonly<{
|
|
80
|
+
"onUpdate:tab"?: ((tab: WorkspaceTab) => any) | undefined;
|
|
81
|
+
}>, {
|
|
82
|
+
label: string;
|
|
83
|
+
storageKey: string | false;
|
|
84
|
+
layout: WorkspaceLayout;
|
|
85
|
+
tab: WorkspaceTab;
|
|
86
|
+
tabs: readonly WorkspaceTabItem[];
|
|
87
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
88
|
+
//#endregion
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { r as useUIComponent } from "../../nuxt-ui-DSQFzq3s.js";
|
|
2
|
+
import { computed, defineComponent, h, onMounted, ref, watch } from "vue";
|
|
3
|
+
//#region src/workspace/workspace-shell.ts
|
|
4
|
+
const defaultSplits = {
|
|
5
|
+
playground: {
|
|
6
|
+
files: 200,
|
|
7
|
+
main: 68,
|
|
8
|
+
side: 40
|
|
9
|
+
},
|
|
10
|
+
tutorial: {
|
|
11
|
+
files: 180,
|
|
12
|
+
main: 55,
|
|
13
|
+
side: 45
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const limits = {
|
|
17
|
+
files: [
|
|
18
|
+
120,
|
|
19
|
+
420,
|
|
20
|
+
16
|
|
21
|
+
],
|
|
22
|
+
main: [
|
|
23
|
+
20,
|
|
24
|
+
80,
|
|
25
|
+
5
|
|
26
|
+
],
|
|
27
|
+
side: [
|
|
28
|
+
25,
|
|
29
|
+
75,
|
|
30
|
+
5
|
|
31
|
+
]
|
|
32
|
+
};
|
|
33
|
+
const builtInTabs = [
|
|
34
|
+
{
|
|
35
|
+
label: "Preview",
|
|
36
|
+
value: "preview"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
label: "Terminal",
|
|
40
|
+
value: "terminal"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
label: "Connect",
|
|
44
|
+
value: "connect"
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
function clamp(key, value) {
|
|
48
|
+
const [min, max] = limits[key];
|
|
49
|
+
return Math.round(Math.min(max, Math.max(min, value)));
|
|
50
|
+
}
|
|
51
|
+
function readSplits(key, layout) {
|
|
52
|
+
const fallback = { ...defaultSplits[layout] };
|
|
53
|
+
if (!key || typeof window === "undefined") return fallback;
|
|
54
|
+
try {
|
|
55
|
+
const value = JSON.parse(window.localStorage.getItem(key) ?? "null");
|
|
56
|
+
if (!value || typeof value !== "object") return fallback;
|
|
57
|
+
for (const name of Object.keys(fallback)) {
|
|
58
|
+
const size = Reflect.get(value, name);
|
|
59
|
+
if (typeof size === "number" && Number.isFinite(size)) fallback[name] = clamp(name, size);
|
|
60
|
+
}
|
|
61
|
+
} catch {}
|
|
62
|
+
return fallback;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A resize handle. It uses pointer capture so a drag over the preview iframe keeps working,
|
|
66
|
+
* and it moves by a step with the arrow keys.
|
|
67
|
+
*/
|
|
68
|
+
function separator(options) {
|
|
69
|
+
const { name, orientation, splits } = options;
|
|
70
|
+
const [min, max, step] = limits[name];
|
|
71
|
+
const decrease = orientation === "vertical" ? "ArrowLeft" : "ArrowUp";
|
|
72
|
+
const increase = orientation === "vertical" ? "ArrowRight" : "ArrowDown";
|
|
73
|
+
return h("div", {
|
|
74
|
+
"aria-label": options.label,
|
|
75
|
+
"aria-orientation": orientation,
|
|
76
|
+
"aria-valuemax": max,
|
|
77
|
+
"aria-valuemin": min,
|
|
78
|
+
"aria-valuenow": splits[name],
|
|
79
|
+
class: ["vh-ws-separator", `vh-ws-separator--${orientation}`],
|
|
80
|
+
"data-split": name,
|
|
81
|
+
role: "separator",
|
|
82
|
+
tabindex: 0,
|
|
83
|
+
onKeydown(event) {
|
|
84
|
+
if (event.key === decrease) options.set(name, splits[name] - step);
|
|
85
|
+
else if (event.key === increase) options.set(name, splits[name] + step);
|
|
86
|
+
else if (event.key === "Home") options.set(name, min);
|
|
87
|
+
else if (event.key === "End") options.set(name, max);
|
|
88
|
+
else return;
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
},
|
|
91
|
+
onPointerdown(event) {
|
|
92
|
+
const container = options.container();
|
|
93
|
+
if (!container || event.button !== 0) return;
|
|
94
|
+
const handle = event.currentTarget;
|
|
95
|
+
if (!(handle instanceof HTMLElement)) return;
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
handle.setPointerCapture(event.pointerId);
|
|
98
|
+
const rect = container.getBoundingClientRect();
|
|
99
|
+
const move = (next) => options.set(name, options.measure(next, rect));
|
|
100
|
+
const end = () => {
|
|
101
|
+
handle.removeEventListener("pointermove", move);
|
|
102
|
+
handle.removeEventListener("pointerup", end);
|
|
103
|
+
handle.removeEventListener("pointercancel", end);
|
|
104
|
+
};
|
|
105
|
+
handle.addEventListener("pointermove", move);
|
|
106
|
+
handle.addEventListener("pointerup", end);
|
|
107
|
+
handle.addEventListener("pointercancel", end);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const WorkspaceShell = defineComponent({
|
|
112
|
+
name: "WorkspaceShell",
|
|
113
|
+
props: {
|
|
114
|
+
layout: {
|
|
115
|
+
default: "tutorial",
|
|
116
|
+
type: String
|
|
117
|
+
},
|
|
118
|
+
/** The visible tab. Use `v-model:tab`. */
|
|
119
|
+
tab: {
|
|
120
|
+
default: void 0,
|
|
121
|
+
type: String
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* The tabs of the panel group, in order. Each tab shows the slot with the name of its `value`. Defaults to Preview,
|
|
125
|
+
* Terminal, and Connect, for the slots that are set. A playground shows the preview at the side, never as a tab.
|
|
126
|
+
*/
|
|
127
|
+
tabs: {
|
|
128
|
+
default: void 0,
|
|
129
|
+
type: Array
|
|
130
|
+
},
|
|
131
|
+
/** The localStorage key for split sizes. `false` keeps them in memory. Defaults to one key per layout. */
|
|
132
|
+
storageKey: {
|
|
133
|
+
default: void 0,
|
|
134
|
+
type: [String, Boolean]
|
|
135
|
+
},
|
|
136
|
+
/** The accessible name of the workspace region. */
|
|
137
|
+
label: {
|
|
138
|
+
default: "Workspace",
|
|
139
|
+
type: String
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
emits: { "update:tab": (tab) => typeof tab === "string" },
|
|
143
|
+
setup(props, { emit, slots }) {
|
|
144
|
+
const root = ref(null);
|
|
145
|
+
const key = computed(() => props.storageKey === false ? false : props.storageKey ?? `vitehub:workspace:${props.layout}`);
|
|
146
|
+
const splits = ref({ ...defaultSplits[props.layout] });
|
|
147
|
+
const localTab = ref();
|
|
148
|
+
onMounted(() => {
|
|
149
|
+
splits.value = readSplits(key.value, props.layout);
|
|
150
|
+
});
|
|
151
|
+
watch(() => props.layout, () => {
|
|
152
|
+
splits.value = readSplits(key.value, props.layout);
|
|
153
|
+
});
|
|
154
|
+
function set(name, value) {
|
|
155
|
+
splits.value = {
|
|
156
|
+
...splits.value,
|
|
157
|
+
[name]: clamp(name, value)
|
|
158
|
+
};
|
|
159
|
+
if (!key.value) return;
|
|
160
|
+
try {
|
|
161
|
+
window.localStorage.setItem(key.value, JSON.stringify(splits.value));
|
|
162
|
+
} catch {}
|
|
163
|
+
}
|
|
164
|
+
const items = computed(() => (props.tabs ?? builtInTabs.filter((item) => slots[item.value])).filter((item) => props.layout !== "playground" || item.value !== "preview"));
|
|
165
|
+
const tabs = computed(() => items.value.map((item) => item.value));
|
|
166
|
+
const active = computed(() => {
|
|
167
|
+
const wanted = props.tab ?? localTab.value;
|
|
168
|
+
if (wanted && tabs.value.includes(wanted)) return wanted;
|
|
169
|
+
return tabs.value[0];
|
|
170
|
+
});
|
|
171
|
+
function select(tab) {
|
|
172
|
+
localTab.value = tab;
|
|
173
|
+
emit("update:tab", tab);
|
|
174
|
+
}
|
|
175
|
+
const slotProps = () => ({
|
|
176
|
+
layout: props.layout,
|
|
177
|
+
tab: active.value,
|
|
178
|
+
showTab: select
|
|
179
|
+
});
|
|
180
|
+
const UTabs = useUIComponent("UTabs");
|
|
181
|
+
function tabList() {
|
|
182
|
+
if (tabs.value.length === 0) return void 0;
|
|
183
|
+
const panels = tabs.value.map((name) => h("div", {
|
|
184
|
+
"aria-label": items.value.find((item) => item.value === name)?.label,
|
|
185
|
+
class: ["vh-ws-tab-panel", active.value !== name && "is-hidden"],
|
|
186
|
+
"data-tab": name,
|
|
187
|
+
inert: active.value === name ? void 0 : "",
|
|
188
|
+
key: name,
|
|
189
|
+
role: "tabpanel"
|
|
190
|
+
}, renderSlot(slots, name, slotProps())));
|
|
191
|
+
return h("div", { class: "vh-ws-tabs" }, [h(UTabs, {
|
|
192
|
+
"aria-label": "Workspace panels",
|
|
193
|
+
class: "vh-ws-tab-list",
|
|
194
|
+
content: false,
|
|
195
|
+
items: items.value.map(({ badge, label, value }) => ({
|
|
196
|
+
badge: badge === "" ? void 0 : badge,
|
|
197
|
+
label,
|
|
198
|
+
value
|
|
199
|
+
})),
|
|
200
|
+
modelValue: active.value,
|
|
201
|
+
"onUpdate:modelValue": (value) => {
|
|
202
|
+
const tab = tabs.value.find((name) => name === value);
|
|
203
|
+
if (tab) select(tab);
|
|
204
|
+
}
|
|
205
|
+
}), h("div", { class: "vh-ws-tab-panels" }, panels)]);
|
|
206
|
+
}
|
|
207
|
+
return () => {
|
|
208
|
+
const s = splits.value;
|
|
209
|
+
const container = () => root.value?.querySelector(".vh-ws-body") ?? null;
|
|
210
|
+
const filesSplit = slots.files ? [h("div", {
|
|
211
|
+
class: "vh-ws-pane vh-ws-pane--files",
|
|
212
|
+
style: { flexBasis: `${s.files}px` }
|
|
213
|
+
}, renderSlot(slots, "files", slotProps())), separator({
|
|
214
|
+
container,
|
|
215
|
+
label: "Resize files",
|
|
216
|
+
measure: (event, rect) => event.clientX - rect.left,
|
|
217
|
+
name: "files",
|
|
218
|
+
orientation: "vertical",
|
|
219
|
+
set,
|
|
220
|
+
splits: s
|
|
221
|
+
})] : [];
|
|
222
|
+
const editor = h("div", { class: "vh-ws-pane vh-ws-pane--editor" }, renderSlot(slots, "editor", slotProps()));
|
|
223
|
+
let body;
|
|
224
|
+
if (props.layout === "playground") {
|
|
225
|
+
const panels = tabList();
|
|
226
|
+
const center = panels ? h("div", { class: "vh-ws-stack" }, [
|
|
227
|
+
h("div", {
|
|
228
|
+
class: "vh-ws-pane",
|
|
229
|
+
style: { flexBasis: `${s.main}%` }
|
|
230
|
+
}, [editor]),
|
|
231
|
+
separator({
|
|
232
|
+
container: () => root.value?.querySelector(".vh-ws-stack") ?? null,
|
|
233
|
+
label: "Resize panels",
|
|
234
|
+
measure: (event, rect) => (event.clientY - rect.top) / rect.height * 100,
|
|
235
|
+
name: "main",
|
|
236
|
+
orientation: "horizontal",
|
|
237
|
+
set,
|
|
238
|
+
splits: s
|
|
239
|
+
}),
|
|
240
|
+
h("div", { class: "vh-ws-pane vh-ws-pane--panels" }, [panels])
|
|
241
|
+
]) : editor;
|
|
242
|
+
body = h("div", { class: "vh-ws-body vh-ws-body--row" }, [
|
|
243
|
+
...filesSplit,
|
|
244
|
+
h("div", { class: "vh-ws-pane vh-ws-pane--center" }, [center]),
|
|
245
|
+
...slots.preview ? [separator({
|
|
246
|
+
container,
|
|
247
|
+
label: "Resize preview",
|
|
248
|
+
measure: (event, rect) => (rect.right - event.clientX) / rect.width * 100,
|
|
249
|
+
name: "side",
|
|
250
|
+
orientation: "vertical",
|
|
251
|
+
set,
|
|
252
|
+
splits: s
|
|
253
|
+
}), h("div", {
|
|
254
|
+
class: "vh-ws-pane vh-ws-pane--side",
|
|
255
|
+
style: { flexBasis: `${s.side}%` }
|
|
256
|
+
}, renderSlot(slots, "preview", slotProps()))] : []
|
|
257
|
+
]);
|
|
258
|
+
} else body = h("div", { class: "vh-ws-body vh-ws-body--column" }, [
|
|
259
|
+
h("div", {
|
|
260
|
+
class: "vh-ws-row",
|
|
261
|
+
style: { flexBasis: `${s.main}%` }
|
|
262
|
+
}, [...filesSplit, editor]),
|
|
263
|
+
separator({
|
|
264
|
+
container,
|
|
265
|
+
label: "Resize editor",
|
|
266
|
+
measure: (event, rect) => (event.clientY - rect.top) / rect.height * 100,
|
|
267
|
+
name: "main",
|
|
268
|
+
orientation: "horizontal",
|
|
269
|
+
set,
|
|
270
|
+
splits: s
|
|
271
|
+
}),
|
|
272
|
+
h("div", { class: "vh-ws-pane vh-ws-pane--panels" }, [tabList()])
|
|
273
|
+
]);
|
|
274
|
+
return h("section", {
|
|
275
|
+
"aria-label": props.label,
|
|
276
|
+
class: ["vh-ws-shell", `vh-ws-shell--${props.layout}`],
|
|
277
|
+
"data-layout": props.layout,
|
|
278
|
+
ref: root
|
|
279
|
+
}, [
|
|
280
|
+
slots.toolbar ? h("div", { class: "vh-ws-toolbar" }, renderSlot(slots, "toolbar", slotProps())) : void 0,
|
|
281
|
+
body,
|
|
282
|
+
slots.overlay ? h("div", { class: "vh-ws-overlay" }, renderSlot(slots, "overlay", slotProps())) : void 0
|
|
283
|
+
]);
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
function renderSlot(slots, name, props) {
|
|
288
|
+
return slots[name]?.(props);
|
|
289
|
+
}
|
|
290
|
+
//#endregion
|
|
291
|
+
export { WorkspaceShell };
|