@vite-hub/ui 0.4.1 → 0.5.0

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.
Files changed (175) hide show
  1. package/README.md +102 -76
  2. package/dist/announce-Cy_Tn9wW.js +32 -0
  3. package/dist/{avatar-stack-DPRFuezh.d.ts → avatar-stack-DXmCQhxd.d.ts} +1 -1
  4. package/dist/{comment-composer-jYv2ULNP.js → comment-composer-D7ZytyER.js} +257 -10
  5. package/dist/{comment-composer-fINL5bxo.d.ts → comment-composer-DvKMTrAi.d.ts} +4 -4
  6. package/dist/{comment-layer-C_sbPIR5.d.ts → comment-layer-GTsLdABl.d.ts} +4 -4
  7. package/dist/{comment-list-BcSaLngS.d.ts → comment-list-BI96empx.d.ts} +2 -2
  8. package/dist/comment-marks.css +18 -22
  9. package/dist/{comment-panel-CfvdRUMX.d.ts → comment-panel-CsKWTms_.d.ts} +2 -2
  10. package/dist/{comment-pin-DHOdRvUw.d.ts → comment-pin-CvwgRSDR.d.ts} +1 -1
  11. package/dist/{comment-row-Bn3nr8l5.js → comment-row-JmTC0uXr.js} +1 -1
  12. package/dist/comment-send-7bg4NEEM.js +277 -0
  13. package/dist/comment-send-C45dHC22.d.ts +25 -0
  14. package/dist/comment-send.css +267 -0
  15. package/dist/comment-thread-B_Sc2QX6.js +797 -0
  16. package/dist/{comment-thread-DKJjmWN0.d.ts → comment-thread-C6U-bsK_.d.ts} +4 -4
  17. package/dist/{comments-D0d26ghV.js → comments-B88zg9gC.js} +1 -1
  18. package/dist/{comments-context-C2lOZyQ5.js → comments-context-DhbIdYQ1.js} +2 -1
  19. package/dist/{config-Dk67emQt.js → config-B1u7zqMB.js} +8 -1
  20. package/dist/{config-DgxBW013.d.ts → config-pHazYdq6.d.ts} +11 -0
  21. package/dist/drop-field-3CDRFFRm.js +163 -0
  22. package/dist/{editor-C_wt4RRV.js → editor-BHYGLgty.js} +42 -3
  23. package/dist/effects-Ql6VzCRa.js +2971 -0
  24. package/dist/headless.d.ts +1 -1
  25. package/dist/headless.js +1 -1
  26. package/dist/hold-to-delete-DjWzRDyY.d.ts +51 -0
  27. package/dist/hold-to-delete-ROLQRZg_.js +434 -0
  28. package/dist/icon-c5Jb_Tl7.d.ts +31 -0
  29. package/dist/{image-preview-C9tdkmEj.js → image-preview-BigoAvb3.js} +2 -2
  30. package/dist/{index-BYRFQfCd.d.ts → index-YUvL2nV8.d.ts} +8 -10
  31. package/dist/index.d.ts +19 -14
  32. package/dist/index.js +45 -44
  33. package/dist/install-D5f6msEU.js +17 -0
  34. package/dist/list-RCbNZ14q.js +271 -0
  35. package/dist/{markdown-editor-CMbNZOdN.js → markdown-editor-Dfl2DgPS.js} +1 -1
  36. package/dist/markdown-editor.js +1 -1
  37. package/dist/{message-scroller-jrYN9dG9.d.ts → message-scroller-Bm1YWTeY.d.ts} +2 -2
  38. package/dist/motion/core.d.ts +4 -0
  39. package/dist/motion/core.js +11 -0
  40. package/dist/motion-core-lHRF8PZz.d.ts +456 -0
  41. package/dist/motion.d.ts +16 -0
  42. package/dist/motion.js +13 -0
  43. package/dist/{nuxt-ui-DSQFzq3s.js → nuxt-ui-CgvMzO5v.js} +20 -14
  44. package/dist/nuxt.d.ts +1 -1
  45. package/dist/nuxt.js +12 -3
  46. package/dist/opt-out-b6bnUjIT.js +208 -0
  47. package/dist/parts/components/agent-session.js +1 -1
  48. package/dist/parts/components/attachment.d.ts +1 -1
  49. package/dist/parts/components/attachment.js +1 -1
  50. package/dist/parts/components/avatar-stack.d.ts +1 -1
  51. package/dist/parts/components/avatar-stack.js +2 -1
  52. package/dist/parts/components/bubble.d.ts +1 -1
  53. package/dist/parts/components/chat-session.d.ts +1 -1
  54. package/dist/parts/components/chat.js +2 -2
  55. package/dist/parts/components/code-block.d.ts +1 -1
  56. package/dist/parts/components/code-block.js +1 -1
  57. package/dist/parts/components/comment-composer.d.ts +1 -1
  58. package/dist/parts/components/comment-composer.js +1 -1
  59. package/dist/parts/components/comment-layer.d.ts +1 -1
  60. package/dist/parts/components/comment-layer.js +24 -6
  61. package/dist/parts/components/comment-list.d.ts +1 -1
  62. package/dist/parts/components/comment-list.js +12 -7
  63. package/dist/parts/components/comment-panel.d.ts +1 -1
  64. package/dist/parts/components/comment-panel.js +24 -10
  65. package/dist/parts/components/comment-pin.d.ts +1 -1
  66. package/dist/parts/components/comment-selection-bar.js +3 -2
  67. package/dist/parts/components/comment-send.d.ts +2 -0
  68. package/dist/parts/components/comment-send.js +2 -0
  69. package/dist/parts/components/comment-thread.d.ts +1 -1
  70. package/dist/parts/components/comment-thread.js +2 -597
  71. package/dist/parts/components/comments.d.ts +8 -7
  72. package/dist/parts/components/comments.js +5 -4
  73. package/dist/parts/components/copy-button.d.ts +13 -3
  74. package/dist/parts/components/copy-button.js +226 -1
  75. package/dist/parts/components/device-frame.d.ts +2 -2
  76. package/dist/parts/components/drop-field.d.ts +69 -0
  77. package/dist/parts/components/drop-field.js +77 -0
  78. package/dist/parts/components/filter-search.js +1 -1
  79. package/dist/parts/components/hold-to-delete.d.ts +82 -0
  80. package/dist/parts/components/hold-to-delete.js +76 -0
  81. package/dist/parts/components/markdown-editor.js +1 -1
  82. package/dist/parts/components/markdown-renderer.js +1 -1
  83. package/dist/parts/components/markdown.js +1 -1
  84. package/dist/parts/components/marker.d.ts +1 -1
  85. package/dist/parts/components/message-parts.js +13 -5
  86. package/dist/parts/components/motion-list.d.ts +42 -0
  87. package/dist/parts/components/motion-list.js +42 -0
  88. package/dist/parts/components/motion.d.ts +124 -0
  89. package/dist/parts/components/motion.js +172 -0
  90. package/dist/parts/components/progress.d.ts +41 -0
  91. package/dist/parts/components/progress.js +54 -0
  92. package/dist/parts/components/prompt-input.d.ts +5 -5
  93. package/dist/parts/components/prompt-input.js +3 -3
  94. package/dist/parts/components/relative-time.js +1 -1
  95. package/dist/parts/components/sync-status.js +2 -1
  96. package/dist/parts/components/tool-list.d.ts +1 -1
  97. package/dist/parts/components/trace-run.d.ts +1 -1
  98. package/dist/parts/components/trace-run.js +1 -1
  99. package/dist/parts/components/trace.d.ts +1 -1
  100. package/dist/parts/headless/comments.js +1 -1
  101. package/dist/parts/headless/message-scroller.d.ts +1 -1
  102. package/dist/parts/playground/share.d.ts +36 -2
  103. package/dist/parts/workspace/browser-support-notice.d.ts +1 -1
  104. package/dist/parts/workspace/browser-support-notice.js +12 -4
  105. package/dist/parts/workspace/codemirror.d.ts +9 -0
  106. package/dist/parts/workspace/codemirror.js +37 -4
  107. package/dist/parts/workspace/connect-panel.d.ts +1 -1
  108. package/dist/parts/workspace/connect-panel.js +1 -1
  109. package/dist/parts/workspace/file-icons.d.ts +16 -0
  110. package/dist/parts/workspace/file-icons.js +82 -0
  111. package/dist/parts/workspace/icons.d.ts +1 -0
  112. package/dist/parts/workspace/icons.js +1 -0
  113. package/dist/parts/workspace/runners/render.d.ts +26 -0
  114. package/dist/parts/workspace/runners/render.js +124 -0
  115. package/dist/parts/workspace/runners/web-container.d.ts +29 -0
  116. package/dist/parts/workspace/runners/web-container.js +186 -0
  117. package/dist/parts/workspace/workspace-bar.d.ts +51 -0
  118. package/dist/parts/workspace/workspace-bar.js +51 -0
  119. package/dist/parts/workspace/workspace-editor-head.d.ts +47 -0
  120. package/dist/parts/workspace/workspace-editor-head.js +66 -0
  121. package/dist/parts/workspace/workspace-editor.d.ts +17 -0
  122. package/dist/parts/workspace/workspace-editor.js +29 -3
  123. package/dist/parts/workspace/workspace-examples.d.ts +74 -0
  124. package/dist/parts/workspace/workspace-examples.js +72 -0
  125. package/dist/parts/workspace/workspace-file-link.d.ts +35 -0
  126. package/dist/parts/workspace/workspace-file-link.js +39 -0
  127. package/dist/parts/workspace/workspace-file-tree.d.ts +8 -8
  128. package/dist/parts/workspace/workspace-file-tree.js +26 -19
  129. package/dist/parts/workspace/workspace-guide.d.ts +52 -0
  130. package/dist/parts/workspace/workspace-guide.js +91 -0
  131. package/dist/parts/workspace/workspace-issues.d.ts +46 -0
  132. package/dist/parts/workspace/workspace-issues.js +49 -0
  133. package/dist/parts/workspace/workspace-preview.js +1 -1
  134. package/dist/parts/workspace/workspace-shell.d.ts +2 -88
  135. package/dist/parts/workspace/workspace-shell.js +131 -78
  136. package/dist/parts/workspace/workspace-sidebar.d.ts +75 -0
  137. package/dist/parts/workspace/workspace-sidebar.js +132 -0
  138. package/dist/parts/workspace/workspace-start.d.ts +47 -0
  139. package/dist/parts/workspace/workspace-start.js +60 -0
  140. package/dist/parts/workspace/workspace-status.d.ts +69 -0
  141. package/dist/parts/workspace/workspace-status.js +74 -0
  142. package/dist/parts/workspace/workspace-steps.d.ts +2 -0
  143. package/dist/parts/workspace/workspace-steps.js +128 -0
  144. package/dist/parts/workspace/workspace-task.d.ts +20 -0
  145. package/dist/parts/workspace/workspace-task.js +20 -0
  146. package/dist/parts/workspace/workspace.d.ts +251 -0
  147. package/dist/parts/workspace/workspace.js +665 -0
  148. package/dist/playground.d.ts +1 -1
  149. package/dist/progress-C7afI5vq.js +266 -0
  150. package/dist/registry-D3-ysX7l.js +78 -0
  151. package/dist/{relative-time-BVmjOsYG.js → relative-time-DgSS3zKN.js} +1 -1
  152. package/dist/ring-B7Qxu7zd.js +175 -0
  153. package/dist/runtime/nuxt-plugin.js +2 -2
  154. package/dist/styles.css +586 -573
  155. package/dist/text-BCJflBJf.js +826 -0
  156. package/dist/theme.d.ts +43 -0
  157. package/dist/theme.js +22 -7
  158. package/dist/travel-C87xd5Wh.js +182 -0
  159. package/dist/tween-CO24nMpf.js +62 -0
  160. package/dist/{types-Dj7vp0lZ.d.ts → types-BX64qHlV.d.ts} +1 -1
  161. package/dist/visual-copy-CrVc3z4n.js +15 -0
  162. package/dist/workspace-shell-BJGnoF3p.d.ts +112 -0
  163. package/dist/workspace-steps-Bgph2rpr.d.ts +72 -0
  164. package/dist/workspace.d.ts +16 -3
  165. package/dist/workspace.js +15 -2
  166. package/package.json +21 -10
  167. package/dist/copy-button-CRN3kmSD.js +0 -253
  168. package/dist/icon-swap.css +0 -69
  169. package/dist/parts/playground/highlight.d.ts +0 -5
  170. package/dist/parts/playground/highlight.js +0 -23
  171. package/dist/parts/playground/playground-render.d.ts +0 -126
  172. package/dist/parts/playground/playground-render.js +0 -356
  173. package/dist/parts/workspace/playground-container.d.ts +0 -192
  174. package/dist/parts/workspace/playground-container.js +0 -603
  175. package/dist/share-DM4eNy4q.d.ts +0 -37
@@ -0,0 +1,665 @@
1
+ import { r as useUIComponent } from "../../nuxt-ui-CgvMzO5v.js";
2
+ import { t as ring } from "../../ring-B7Qxu7zd.js";
3
+ import { t as uiErrorDiagnostics } from "../../error-diagnostics-SXtnk6bz.js";
4
+ import { useCopy } from "../components/copy-button.js";
5
+ import { Status } from "../components/status.js";
6
+ import { decodePlaygroundLink, encodePlaygroundLink, playgroundLinkLimit, playgroundUrl, readPlaygroundHash } from "../playground/share.js";
7
+ import { downloadZip } from "../playground/zip.js";
8
+ import { BrowserSupportNotice } from "./browser-support-notice.js";
9
+ import { WorkspaceBar } from "./workspace-bar.js";
10
+ import { WorkspaceEditorHead } from "./workspace-editor-head.js";
11
+ import { WorkspaceEditor } from "./workspace-editor.js";
12
+ import { WorkspaceExamples } from "./workspace-examples.js";
13
+ import { provideWorkspaceFileOpener } from "./workspace-file-link.js";
14
+ import { WorkspaceFileTree } from "./workspace-file-tree.js";
15
+ import { WorkspaceSteps } from "./workspace-steps.js";
16
+ import { WorkspaceGuide } from "./workspace-guide.js";
17
+ import { WorkspaceShell } from "./workspace-shell.js";
18
+ import { WorkspaceSidebar } from "./workspace-sidebar.js";
19
+ import { WorkspaceStart } from "./workspace-start.js";
20
+ import { WorkspaceStatus } from "./workspace-status.js";
21
+ import { computed, defineComponent, h, inject, markRaw, nextTick, onBeforeUnmount, onMounted, provide, reactive, ref, shallowRef, watch } from "vue";
22
+ //#region src/workspace/workspace.ts
23
+ const contextKey = Symbol("Workspace");
24
+ /** The workspace around the calling component: its files, edits, and actions. Call it in a slot of `Workspace`. */
25
+ function useWorkspace() {
26
+ const context = inject(contextKey, void 0);
27
+ if (!context) throw uiErrorDiagnostics.UI_R0002({ message: "useWorkspace() must be used in a component inside Workspace." });
28
+ return context;
29
+ }
30
+ /**
31
+ * The device of the page, and whether the browser can run `runner`, known after mount. Desktops are 64rem wide or
32
+ * more, and tablets 48rem. Use it to place the workspace, as a page with a lesson next to it does.
33
+ */
34
+ function useWorkspaceDevice(runner) {
35
+ const device = ref("pending");
36
+ const supported = ref();
37
+ let queries = [];
38
+ const update = () => {
39
+ const [desktop, tablet] = queries;
40
+ device.value = desktop?.matches ? "desktop" : tablet?.matches ? "tablet" : "phone";
41
+ };
42
+ onMounted(() => {
43
+ queries = [window.matchMedia("(min-width: 64rem)"), window.matchMedia("(min-width: 48rem)")];
44
+ for (const query of queries) query.addEventListener("change", update);
45
+ update();
46
+ supported.value = runner?.supported?.() ?? true;
47
+ });
48
+ onBeforeUnmount(() => {
49
+ for (const query of queries) query.removeEventListener("change", update);
50
+ });
51
+ return {
52
+ device,
53
+ supported
54
+ };
55
+ }
56
+ const statusTones = {
57
+ busy: "warning",
58
+ error: "error",
59
+ ready: "success"
60
+ };
61
+ function diff(base, files) {
62
+ return [.../* @__PURE__ */ new Set([...Object.keys(base), ...Object.keys(files)])].filter((path) => base[path] !== files[path]).sort();
63
+ }
64
+ const filesOf = (example) => ({ ...example.files });
65
+ function firstFile(example, files) {
66
+ return example.open !== void 0 && files[example.open] !== void 0 ? example.open : Object.keys(files).sort()[0] ?? "";
67
+ }
68
+ const capitalize = (text) => text.charAt(0).toUpperCase() + text.slice(1);
69
+ const zipName = (prefix, example) => prefix ? `${prefix}-${example.id}` : example.id;
70
+ const workspaceProps = {
71
+ examples: {
72
+ required: true,
73
+ type: Array
74
+ },
75
+ runner: {
76
+ required: true,
77
+ type: Object
78
+ },
79
+ example: {
80
+ default: void 0,
81
+ type: String
82
+ },
83
+ selected: {
84
+ default: void 0,
85
+ type: String
86
+ },
87
+ steps: {
88
+ default: () => [],
89
+ type: Array
90
+ },
91
+ step: {
92
+ default: void 0,
93
+ type: Number
94
+ },
95
+ guide: {
96
+ default: void 0,
97
+ type: String
98
+ },
99
+ tabs: {
100
+ default: () => [],
101
+ type: Array
102
+ },
103
+ share: {
104
+ default: true,
105
+ type: Boolean
106
+ },
107
+ name: {
108
+ default: "",
109
+ type: String
110
+ },
111
+ start: {
112
+ default: false,
113
+ type: Boolean
114
+ },
115
+ label: {
116
+ default: "workspace",
117
+ type: String
118
+ },
119
+ open: {
120
+ default: false,
121
+ type: Boolean
122
+ },
123
+ reset: {
124
+ default: void 0,
125
+ type: Function
126
+ }
127
+ };
128
+ const WorkspaceSession = defineComponent({
129
+ name: "WorkspaceSession",
130
+ props: {
131
+ config: {
132
+ required: true,
133
+ type: Object
134
+ },
135
+ booted: {
136
+ required: true,
137
+ type: Object
138
+ },
139
+ files: {
140
+ required: true,
141
+ type: Object
142
+ },
143
+ notice: {
144
+ default: void 0,
145
+ type: String
146
+ },
147
+ step: {
148
+ default: 0,
149
+ type: Number
150
+ },
151
+ shared: {
152
+ default: void 0,
153
+ type: Object
154
+ }
155
+ },
156
+ emits: {
157
+ "update:selected": (path) => typeof path === "string",
158
+ "update:step": (step) => Number.isInteger(step),
159
+ change: (example) => !!example,
160
+ remount: (example) => !!example,
161
+ restore: (link) => !!link
162
+ },
163
+ setup(props, { emit, slots }) {
164
+ const UButton = useUIComponent("UButton");
165
+ const UDropdownMenu = useUIComponent("UDropdownMenu");
166
+ const UModal = useUIComponent("UModal");
167
+ const config = props.config;
168
+ const tab = ref();
169
+ const showTab = (next) => {
170
+ tab.value = next;
171
+ };
172
+ const showFile = (path) => {
173
+ if (run.files.value[path] !== void 0) show(path);
174
+ };
175
+ const run = config.runner.start({
176
+ example: props.booted,
177
+ files: { ...props.files },
178
+ showTab,
179
+ show: showFile
180
+ });
181
+ const current = shallowRef(props.booted);
182
+ const example = computed(() => config.examples.find((item) => item.id === current.value.id) ?? current.value);
183
+ const edited = computed(() => diff(filesOf(example.value), run.files.value));
184
+ const paths = computed(() => Object.keys(run.files.value).sort());
185
+ const selected = ref(config.selected !== void 0 && props.files[config.selected] !== void 0 ? config.selected : firstFile(props.booted, props.files));
186
+ watch(() => config.selected, (path) => {
187
+ if (path !== void 0) selected.value = path;
188
+ });
189
+ watch(selected, (path) => emit("update:selected", path), { immediate: true });
190
+ const wrap = ref(false);
191
+ const cursor = ref({
192
+ column: 1,
193
+ line: 1
194
+ });
195
+ const sidebar = ref(false);
196
+ const confirm = ref();
197
+ function guard(title, label, action) {
198
+ if (edited.value.length === 0) action();
199
+ else confirm.value = {
200
+ title,
201
+ label,
202
+ action
203
+ };
204
+ }
205
+ function confirmAction() {
206
+ confirm.value?.action();
207
+ confirm.value = void 0;
208
+ }
209
+ async function load(next, files = filesOf(next)) {
210
+ if (!run.keeps(next)) return emit("remount", next);
211
+ current.value = next;
212
+ selected.value = firstFile(next, files);
213
+ emit("change", next);
214
+ await run.open(next, files);
215
+ }
216
+ function pick(id) {
217
+ const next = config.examples.find((item) => item.id === id);
218
+ if (!next || next.id === example.value.id && edited.value.length === 0) return;
219
+ guard(`Open the ${next.label} example?`, "Replace files", () => void load(next));
220
+ }
221
+ watch(() => config.example, (id) => {
222
+ if (id !== void 0 && id !== example.value.id) pick(id);
223
+ });
224
+ watch(() => props.shared, (link) => {
225
+ if (link) guard(`Open the shared files${config.examples.length > 1 ? ` on the ${link.example.label} example` : ""}?`, "Replace files", () => emit("restore", link));
226
+ });
227
+ function reset() {
228
+ guard(config.examples.length > 1 ? `Discard your changes to the ${example.value.label} example?` : "Discard your changes?", "Discard changes", () => void load(example.value, config.reset?.(run.files.value, example.value)));
229
+ }
230
+ const { copy, copied } = useCopy();
231
+ const problem = ref();
232
+ async function copyLink(button) {
233
+ problem.value = void 0;
234
+ const code = await encodePlaygroundLink({
235
+ template: example.value.id,
236
+ files: run.files.value
237
+ }, filesOf(example.value));
238
+ const url = `${location.origin}${playgroundUrl(location.pathname, code)}`;
239
+ if (url.length > 16e3) {
240
+ problem.value = `This link would have ${(url.length / 1e3).toFixed(1)} KB, and a share link can have ${playgroundLinkLimit / 1e3} KB. Download the files instead.`;
241
+ return;
242
+ }
243
+ if (!await copy(url)) problem.value = "The browser blocked the clipboard. Download the files instead.";
244
+ else if (button instanceof HTMLElement) ring(button);
245
+ }
246
+ const download = () => downloadZip(run.files.value, zipName(config.name ?? "", example.value));
247
+ const setFile = (path, contents) => run.setFiles({ [path]: contents });
248
+ const show = (path) => {
249
+ selected.value = path;
250
+ };
251
+ const context = {
252
+ edited,
253
+ example,
254
+ files: run.files,
255
+ guard,
256
+ run,
257
+ runner: config.runner,
258
+ setFile,
259
+ show,
260
+ showTab
261
+ };
262
+ provide(contextKey, context);
263
+ provideWorkspaceFileOpener({ show });
264
+ const slotProps = reactive({
265
+ ...context,
266
+ run: markRaw(run),
267
+ runner: markRaw(config.runner)
268
+ });
269
+ const source = computed({
270
+ get: () => run.files.value[selected.value] ?? "",
271
+ set: (value) => void setFile(selected.value, value).catch(() => {})
272
+ });
273
+ const locked = computed(() => example.value.readonly?.includes(selected.value) ?? false);
274
+ const layout = computed(() => {
275
+ if (config.steps.length) return `guide-${config.guide ?? "top"}`;
276
+ return config.guide ? `guide-${config.guide}` : "side";
277
+ });
278
+ const tabItems = computed(() => [...run.tabs.value, ...config.tabs]);
279
+ function bar() {
280
+ const state = run.state?.value;
281
+ const actions = run.actions?.value ?? [];
282
+ const hasSidebar = !!slots.sidebar;
283
+ const examples = config.steps.length ? () => h(WorkspaceSteps, {
284
+ step: props.step,
285
+ steps: config.steps,
286
+ "onUpdate:step": (step) => emit("update:step", step)
287
+ }) : config.examples.length > 1 ? () => h(WorkspaceExamples, {
288
+ examples: config.examples,
289
+ modelValue: example.value.id,
290
+ "onUpdate:modelValue": pick
291
+ }) : void 0;
292
+ return [h(WorkspaceBar, {
293
+ sidebar: hasSidebar ? sidebar.value : void 0,
294
+ sidebarId: hasSidebar ? "vh-workspace-sidebar" : void 0,
295
+ "onUpdate:sidebar": (open) => {
296
+ sidebar.value = open;
297
+ }
298
+ }, {
299
+ lead: slots["bar-lead"] && (() => slots["bar-lead"]?.(slotProps) ?? []),
300
+ examples,
301
+ default: state ? () => [h("span", {
302
+ class: "vh-workspace-run-state",
303
+ role: "status"
304
+ }, h(Status, {
305
+ colored: state.tone === "error",
306
+ label: state.label,
307
+ pulse: state.tone === "busy",
308
+ tone: statusTones[state.tone]
309
+ }))] : void 0,
310
+ actions: () => [
311
+ slots["bar-actions"]?.(slotProps),
312
+ hasSidebar ? void 0 : h(UButton, {
313
+ color: "neutral",
314
+ disabled: edited.value.length === 0,
315
+ icon: "i-lucide-rotate-ccw",
316
+ label: "Reset",
317
+ variant: "ghost",
318
+ onClick: reset
319
+ }),
320
+ ...config.share && !hasSidebar ? [h(UButton, {
321
+ color: "neutral",
322
+ icon: "i-lucide-download",
323
+ label: "Download",
324
+ variant: "ghost",
325
+ onClick: download
326
+ }), h(UButton, {
327
+ color: "neutral",
328
+ icon: copied.value ? "i-lucide-check" : "i-lucide-link",
329
+ label: copied.value ? "Link copied" : "Copy link",
330
+ variant: "outline",
331
+ onClick: (event) => void copyLink(event.currentTarget)
332
+ })] : [],
333
+ actions.length ? h(UDropdownMenu, {
334
+ content: { align: "end" },
335
+ items: [actions.map((item) => ({
336
+ disabled: item.disabled,
337
+ icon: item.icon,
338
+ label: item.label,
339
+ onSelect: item.onSelect
340
+ }))]
341
+ }, () => h(UButton, {
342
+ "aria-label": "More actions",
343
+ color: "neutral",
344
+ icon: "i-lucide-ellipsis",
345
+ variant: "ghost"
346
+ })) : void 0
347
+ ]
348
+ }), hasSidebar ? h(WorkspaceSidebar, {
349
+ actions: config.share ? [
350
+ "reset",
351
+ "download",
352
+ "copy-link"
353
+ ] : ["reset"],
354
+ copied: copied.value,
355
+ id: "vh-workspace-sidebar",
356
+ open: sidebar.value,
357
+ "onUpdate:open": (open) => {
358
+ sidebar.value = open;
359
+ },
360
+ onReset: reset,
361
+ onDownload: download,
362
+ "onCopy-link": () => void copyLink()
363
+ }, () => slots.sidebar?.(slotProps)) : void 0];
364
+ }
365
+ return () => {
366
+ const notice = problem.value ?? props.notice;
367
+ const shellSlots = {
368
+ bar,
369
+ banner: notice || slots.banner ? () => [notice ? h("div", {
370
+ class: "vh-workspace-notice",
371
+ role: "status"
372
+ }, notice) : void 0, ...slots.banner?.(slotProps) ?? []] : void 0,
373
+ files: () => [h("div", { class: "vh-ws-head" }, h("span", { class: "vh-ws-muted" }, "Files")), h(WorkspaceFileTree, {
374
+ edited: edited.value,
375
+ paths: paths.value,
376
+ selected: selected.value,
377
+ "onUpdate:selected": show
378
+ })],
379
+ "editor-head": () => h(WorkspaceEditorHead, {
380
+ path: selected.value,
381
+ readonly: locked.value,
382
+ wrap: wrap.value,
383
+ "onUpdate:wrap": (next) => {
384
+ wrap.value = next;
385
+ }
386
+ }),
387
+ editor: () => h(WorkspaceEditor, {
388
+ modelValue: source.value,
389
+ path: selected.value,
390
+ readonly: locked.value,
391
+ wrap: wrap.value,
392
+ onCursor: (next) => {
393
+ cursor.value = next;
394
+ },
395
+ "onUpdate:modelValue": (value) => {
396
+ source.value = value;
397
+ },
398
+ "onUpdate:wrap": (next) => {
399
+ wrap.value = next;
400
+ }
401
+ }),
402
+ status: () => h(WorkspaceStatus, {
403
+ cursor: cursor.value,
404
+ path: selected.value
405
+ }),
406
+ guide: config.steps.length ? () => h(WorkspaceGuide, {
407
+ step: props.step,
408
+ steps: config.steps,
409
+ "onUpdate:step": (step) => emit("update:step", step)
410
+ }, { default: () => slots.guide?.(slotProps) }) : slots.guide && (() => slots.guide?.(slotProps)),
411
+ ...Object.fromEntries(run.tabs.value.map((item) => [`tab-${item.value}`, () => run.panel(item.value)])),
412
+ ...Object.fromEntries(config.tabs.map((item) => [`tab-${item.value}`, () => slots[item.value]?.(slotProps)]))
413
+ };
414
+ return h("div", { class: "vh-workspace-session" }, [h(WorkspaceShell, {
415
+ label: capitalize(config.label ?? "workspace"),
416
+ layout: layout.value,
417
+ storageKey: `vitehub:workspace:${config.label}:${layout.value}`,
418
+ tab: tab.value,
419
+ tabs: tabItems.value,
420
+ "onUpdate:tab": showTab
421
+ }, shellSlots), h(UModal, {
422
+ description: config.share ? "Your edits to the current files are lost. Copy a link or download them first to keep them." : "Your edits to the current files are lost.",
423
+ open: !!confirm.value,
424
+ title: confirm.value?.title,
425
+ "onUpdate:open": (open) => {
426
+ if (!open) confirm.value = void 0;
427
+ }
428
+ }, { footer: () => h("div", { class: "vh-workspace-modal-actions" }, [h(UButton, {
429
+ color: "neutral",
430
+ label: "Cancel",
431
+ variant: "ghost",
432
+ onClick: () => {
433
+ confirm.value = void 0;
434
+ }
435
+ }), h(UButton, {
436
+ color: "neutral",
437
+ label: confirm.value?.label,
438
+ onClick: confirmAction
439
+ })]) })]);
440
+ };
441
+ }
442
+ });
443
+ /**
444
+ * A complete workspace: the bar, the file tree, the editor, the output, and with `steps` the guide of a lesson. The
445
+ * runner runs the files: `webContainer()` runs an app in the browser, and `render()` renders the files to a page. It
446
+ * tracks edits, asks before it discards them, copies share links, and downloads zips.
447
+ */
448
+ const Workspace = defineComponent({
449
+ name: "Workspace",
450
+ props: workspaceProps,
451
+ emits: {
452
+ "update:example": (id) => typeof id === "string",
453
+ "update:selected": (path) => typeof path === "string",
454
+ "update:step": (step) => Number.isInteger(step),
455
+ "update:open": (open) => typeof open === "boolean"
456
+ },
457
+ setup(props, { emit, slots }) {
458
+ const UButton = useUIComponent("UButton");
459
+ const { device, supported } = useWorkspaceDevice(props.runner);
460
+ const root = ref();
461
+ const first = () => props.examples.find((item) => item.id === props.example) ?? props.examples[0];
462
+ const session = shallowRef();
463
+ const active = computed(() => props.examples.find((item) => item.id === session.value?.example.id) ?? session.value?.example ?? first());
464
+ const link = ref();
465
+ const starting = ref(props.start);
466
+ const localStep = ref(props.step ?? 0);
467
+ watch(() => props.step, (step) => {
468
+ if (step !== void 0) localStep.value = step;
469
+ });
470
+ const step = computed(() => Math.min(Math.max(0, props.steps.length - 1), Math.max(0, localStep.value)));
471
+ function setStep(next) {
472
+ localStep.value = next;
473
+ emit("update:step", next);
474
+ }
475
+ function boot(example, files) {
476
+ session.value = {
477
+ example,
478
+ files,
479
+ id: (session.value?.id ?? 0) + 1
480
+ };
481
+ }
482
+ let restoration = 0;
483
+ let opening = 0;
484
+ const shared = shallowRef();
485
+ async function readLink() {
486
+ const request = ++restoration;
487
+ const code = props.share ? readPlaygroundHash(location.hash) : void 0;
488
+ const decoded = code ? await decodePlaygroundLink(code, props.examples.map((item) => ({
489
+ files: filesOf(item),
490
+ id: item.id
491
+ }))) : void 0;
492
+ if (request !== restoration) return void 0;
493
+ const example = decoded?.template === void 0 ? void 0 : props.examples.find((item) => item.id === decoded.template);
494
+ return {
495
+ code,
496
+ link: example && decoded ? {
497
+ example,
498
+ files: decoded.files
499
+ } : void 0
500
+ };
501
+ }
502
+ function openLink(next) {
503
+ shared.value = void 0;
504
+ link.value = "restored";
505
+ starting.value = false;
506
+ boot(next.example, next.files);
507
+ }
508
+ async function restore() {
509
+ const read = await readLink();
510
+ if (!read) return;
511
+ if (read.link) return openLink(read.link);
512
+ link.value = read.code ? "invalid" : void 0;
513
+ boot(first());
514
+ }
515
+ async function follow() {
516
+ if (!readPlaygroundHash(location.hash)) return;
517
+ if (!session.value) return restore();
518
+ const before = opening;
519
+ const read = await readLink();
520
+ if (!read || before !== opening) return;
521
+ if (!read.link) {
522
+ link.value = "invalid";
523
+ return;
524
+ }
525
+ if (shown.value && !starting.value) shared.value = { ...read.link };
526
+ else openLink(read.link);
527
+ }
528
+ onMounted(() => {
529
+ restore();
530
+ if (props.share) window.addEventListener("hashchange", follow);
531
+ });
532
+ onBeforeUnmount(() => window.removeEventListener("hashchange", follow));
533
+ function opened(example) {
534
+ opening++;
535
+ link.value = void 0;
536
+ emit("update:example", example.id);
537
+ }
538
+ async function startExample(id) {
539
+ const example = props.examples.find((item) => item.id === id);
540
+ if (!starting.value || !example) return;
541
+ starting.value = false;
542
+ opened(example);
543
+ boot(example);
544
+ await nextTick();
545
+ root.value?.querySelector(".vh-ws-topbar .vh-ws-examples-button, .vh-ws-topbar button[aria-label='More actions']")?.focus();
546
+ }
547
+ watch(() => props.example, (id) => {
548
+ const example = props.examples.find((item) => item.id === id);
549
+ if (!starting.value || !example) return;
550
+ starting.value = false;
551
+ boot(example);
552
+ });
553
+ function chooser() {
554
+ const text = notice();
555
+ return h("div", { class: "vh-workspace-session" }, [
556
+ h(WorkspaceBar, null, { examples: props.examples.length > 1 ? () => h(WorkspaceExamples, {
557
+ examples: props.examples,
558
+ modelValue: null,
559
+ "onUpdate:modelValue": startExample
560
+ }) : void 0 }),
561
+ text ? h("div", {
562
+ class: "vh-workspace-notice",
563
+ role: "status"
564
+ }, text) : void 0,
565
+ h(WorkspaceStart, {
566
+ examples: props.examples,
567
+ onPick: startExample
568
+ })
569
+ ]);
570
+ }
571
+ const requested = ref(props.open);
572
+ watch(() => props.open, (open) => {
573
+ requested.value = open;
574
+ });
575
+ const shown = computed(() => {
576
+ if (!session.value || supported.value !== true) return false;
577
+ if (!props.runner.desktop) return true;
578
+ return device.value === "desktop" || device.value === "tablet" && requested.value;
579
+ });
580
+ watch(shown, (value) => {
581
+ if (value !== props.open) emit("update:open", value);
582
+ });
583
+ const { copy: copyPage, copied } = useCopy({ duration: 1500 });
584
+ function download() {
585
+ downloadZip(session.value?.files ?? filesOf(active.value), zipName(props.name, active.value));
586
+ }
587
+ const downloadButton = () => h(UButton, {
588
+ color: "neutral",
589
+ icon: "i-lucide-download",
590
+ label: "Download files",
591
+ size: "sm",
592
+ variant: "outline",
593
+ onClick: download
594
+ });
595
+ function notice() {
596
+ if (!link.value || !session.value) return void 0;
597
+ const label = session.value.example.label;
598
+ const many = props.examples.length > 1;
599
+ return link.value === "invalid" ? `This link has no files that the ${props.label} can read.${many && !starting.value ? ` It opened the ${label} example.` : ""}` : `You opened shared files${many ? ` on the ${label} example` : ""}.`;
600
+ }
601
+ function gate() {
602
+ if (!props.runner.desktop) return h("div", {
603
+ class: "vh-workspace-gate",
604
+ "data-state": "pending"
605
+ }, h("div", { class: "vh-workspace-placeholder" }, [h("div", { class: "vh-workspace-placeholder-bar" }), h("p", { class: "vh-workspace-muted" }, `Starting the ${props.label}`)]));
606
+ const state = device.value === "pending" ? "pending" : device.value === "phone" ? "phone" : supported.value === false ? "unsupported" : device.value === "tablet" ? "tablet" : "pending";
607
+ const phone = h("aside", { class: "vh-workspace-card vh-workspace-phone" }, [h("p", { class: "vh-workspace-strong" }, `The live ${props.label} runs in a desktop browser. Open this page on a desktop to edit and run the code.`), h("div", { class: "vh-workspace-actions" }, [h(UButton, {
608
+ color: "neutral",
609
+ icon: copied.value ? "i-lucide-check" : "i-lucide-link",
610
+ label: copied.value ? "Copied" : "Copy link",
611
+ size: "sm",
612
+ variant: "outline",
613
+ onClick: (event) => {
614
+ const button = event.currentTarget;
615
+ copyPage(location.href).then((ok) => ok && button instanceof HTMLElement && ring(button));
616
+ }
617
+ }), downloadButton()])]);
618
+ const card = state === "pending" || state === "phone" ? phone : state === "unsupported" ? h("div", { class: "vh-workspace-unsupported" }, [h(BrowserSupportNotice, {
619
+ description: "Download the files to run the app on your machine, or open this page in Chrome, Edge, or Firefox on a desktop to edit and run it here.",
620
+ supported: false
621
+ }), h("div", { class: "vh-workspace-actions" }, [downloadButton()])]) : h("div", { class: "vh-workspace-card" }, [h("p", { class: "vh-workspace-muted" }, "Edit and run the code in your browser. The first start downloads the dependencies of the app."), h("div", { class: "vh-workspace-actions" }, [h(UButton, {
622
+ color: "neutral",
623
+ icon: "i-lucide-play",
624
+ label: `Open ${props.label}`,
625
+ onClick: () => {
626
+ requested.value = true;
627
+ }
628
+ })])]);
629
+ return h("div", {
630
+ class: "vh-workspace-gate",
631
+ "data-state": state
632
+ }, [state === "pending" ? h("div", { class: "vh-workspace-placeholder" }, [h("div", { class: "vh-workspace-placeholder-bar" }), h("p", { class: "vh-workspace-muted" }, `Starting the ${props.label}`)]) : void 0, h("div", { class: "vh-workspace-gate-content" }, [
633
+ slots.intro?.(),
634
+ card,
635
+ slots.fallback?.()
636
+ ])]);
637
+ }
638
+ return () => {
639
+ const current = session.value;
640
+ return h("div", {
641
+ class: "vh-workspace",
642
+ "data-runner": props.runner.desktop ? "desktop" : "any",
643
+ ref: root
644
+ }, [!shown.value || !current ? gate() : starting.value ? chooser() : h(WorkspaceSession, {
645
+ key: current.id,
646
+ booted: active.value,
647
+ config: props,
648
+ files: current.files ?? filesOf(active.value),
649
+ notice: notice(),
650
+ shared: shared.value,
651
+ step: step.value,
652
+ onChange: opened,
653
+ onRestore: openLink,
654
+ onRemount: (example) => {
655
+ opened(example);
656
+ boot(example);
657
+ },
658
+ "onUpdate:selected": (path) => emit("update:selected", path),
659
+ "onUpdate:step": setStep
660
+ }, slots)]);
661
+ };
662
+ }
663
+ });
664
+ //#endregion
665
+ export { Workspace, useWorkspace, useWorkspaceDevice };
@@ -1,4 +1,4 @@
1
- import { a as encodePlaygroundLink, c as playgroundUrl, i as decodePlaygroundLink, l as readPlaygroundHash, n as PlaygroundState, o as playgroundHashKey, r as PlaygroundTemplate, s as playgroundLinkLimit, t as PlaygroundFiles } from "./share-DM4eNy4q.js";
1
+ import { PlaygroundFiles, PlaygroundState, PlaygroundTemplate, decodePlaygroundLink, encodePlaygroundLink, playgroundHashKey, playgroundLinkLimit, playgroundUrl, readPlaygroundHash } from "./parts/playground/share.js";
2
2
  import { isProjectPath } from "./parts/playground/paths.js";
3
3
  import { downloadZip, zipFiles } from "./parts/playground/zip.js";
4
4
  export { type PlaygroundFiles, type PlaygroundState, type PlaygroundTemplate, decodePlaygroundLink, downloadZip, encodePlaygroundLink, isProjectPath, playgroundHashKey, playgroundLinkLimit, playgroundUrl, readPlaygroundHash, zipFiles };