@vite-hub/ui 0.3.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 (176) hide show
  1. package/README.md +107 -81
  2. package/dist/announce-Cy_Tn9wW.js +32 -0
  3. package/dist/{code-view-D0bqhogi.js → code-view-DsU-xzic.js} +4 -4
  4. package/dist/comment-attachments-C4yNbcx5.js +20 -0
  5. package/dist/{comment-composer-jYv2ULNP.js → comment-composer-D7ZytyER.js} +257 -10
  6. package/dist/{comment-composer-Cc8Jvu6u.d.ts → comment-composer-DvKMTrAi.d.ts} +1 -1
  7. package/dist/{comment-layer-ClH4MLj4.d.ts → comment-layer-GTsLdABl.d.ts} +17 -6
  8. package/dist/{comment-list-B8hphLfS.d.ts → comment-list-BI96empx.d.ts} +2 -2
  9. package/dist/comment-marks.css +18 -22
  10. package/dist/{comment-panel-fcKSKwLC.d.ts → comment-panel-CsKWTms_.d.ts} +15 -4
  11. package/dist/{comment-row-Bbm9WwuF.js → comment-row-JmTC0uXr.js} +2 -2
  12. package/dist/comment-selection-bar-CyVBNYl9.d.ts +42 -0
  13. package/dist/comment-send-7bg4NEEM.js +277 -0
  14. package/dist/comment-send-C45dHC22.d.ts +25 -0
  15. package/dist/comment-send.css +267 -0
  16. package/dist/comment-thread-B_Sc2QX6.js +797 -0
  17. package/dist/{comment-thread-CoTLrdal.d.ts → comment-thread-C6U-bsK_.d.ts} +23 -6
  18. package/dist/{comments-CkWc2Khc.js → comments-B88zg9gC.js} +66 -10
  19. package/dist/{comments-Bx2WRsYy.d.ts → comments-D8hulVPy.d.ts} +34 -6
  20. package/dist/{comments-context-C2lOZyQ5.js → comments-context-DhbIdYQ1.js} +2 -1
  21. package/dist/{config-Dk67emQt.js → config-B1u7zqMB.js} +8 -1
  22. package/dist/{config-DgxBW013.d.ts → config-pHazYdq6.d.ts} +11 -0
  23. package/dist/drop-field-3CDRFFRm.js +163 -0
  24. package/dist/{editor-C_wt4RRV.js → editor-BHYGLgty.js} +42 -3
  25. package/dist/effects-Ql6VzCRa.js +2971 -0
  26. package/dist/format-orwcdZL_.js +39 -0
  27. package/dist/headless.d.ts +2 -2
  28. package/dist/headless.js +1 -1
  29. package/dist/hold-to-delete-DjWzRDyY.d.ts +51 -0
  30. package/dist/hold-to-delete-ROLQRZg_.js +434 -0
  31. package/dist/icon-c5Jb_Tl7.d.ts +31 -0
  32. package/dist/{image-preview-C9tdkmEj.js → image-preview-BigoAvb3.js} +2 -2
  33. package/dist/{index-BD1e8vx5.d.ts → index-YUvL2nV8.d.ts} +10 -6
  34. package/dist/index.d.ts +18 -12
  35. package/dist/index.js +47 -45
  36. package/dist/install-D5f6msEU.js +17 -0
  37. package/dist/list-RCbNZ14q.js +271 -0
  38. package/dist/{markdown-editor-CMbNZOdN.js → markdown-editor-Dfl2DgPS.js} +1 -1
  39. package/dist/{markdown-editor-DqdZfIEn.d.ts → markdown-editor-wQF0yD5o.d.ts} +1 -1
  40. package/dist/markdown-editor.d.ts +1 -1
  41. package/dist/markdown-editor.js +1 -1
  42. package/dist/motion/core.d.ts +4 -0
  43. package/dist/motion/core.js +11 -0
  44. package/dist/motion-core-lHRF8PZz.d.ts +456 -0
  45. package/dist/motion.d.ts +16 -0
  46. package/dist/motion.js +13 -0
  47. package/dist/{nuxt-ui-DSQFzq3s.js → nuxt-ui-CgvMzO5v.js} +20 -14
  48. package/dist/nuxt.d.ts +2 -2
  49. package/dist/nuxt.js +20 -5
  50. package/dist/opt-out-b6bnUjIT.js +208 -0
  51. package/dist/parts/components/agent-session.js +1 -1
  52. package/dist/parts/components/attachment.js +1 -1
  53. package/dist/parts/components/avatar-stack.js +3 -2
  54. package/dist/parts/components/chat-session.d.ts +1 -1
  55. package/dist/parts/components/chat.js +2 -2
  56. package/dist/parts/components/code-block.js +1 -1
  57. package/dist/parts/components/code-view.js +1 -1
  58. package/dist/parts/components/comment-composer.d.ts +1 -1
  59. package/dist/parts/components/comment-composer.js +1 -1
  60. package/dist/parts/components/comment-layer.d.ts +1 -1
  61. package/dist/parts/components/comment-layer.js +54 -23
  62. package/dist/parts/components/comment-list.d.ts +1 -1
  63. package/dist/parts/components/comment-list.js +13 -7
  64. package/dist/parts/components/comment-panel.d.ts +1 -1
  65. package/dist/parts/components/comment-panel.js +46 -20
  66. package/dist/parts/components/comment-pin.js +1 -1
  67. package/dist/parts/components/comment-selection-bar.d.ts +2 -0
  68. package/dist/parts/components/comment-selection-bar.js +117 -0
  69. package/dist/parts/components/comment-send.d.ts +2 -0
  70. package/dist/parts/components/comment-send.js +2 -0
  71. package/dist/parts/components/comment-thread.d.ts +2 -2
  72. package/dist/parts/components/comment-thread.js +2 -570
  73. package/dist/parts/components/comments.d.ts +8 -6
  74. package/dist/parts/components/comments.js +6 -4
  75. package/dist/parts/components/copy-button.d.ts +12 -2
  76. package/dist/parts/components/copy-button.js +226 -1
  77. package/dist/parts/components/drop-field.d.ts +69 -0
  78. package/dist/parts/components/drop-field.js +77 -0
  79. package/dist/parts/components/filter-search.js +1 -1
  80. package/dist/parts/components/hold-to-delete.d.ts +82 -0
  81. package/dist/parts/components/hold-to-delete.js +76 -0
  82. package/dist/parts/components/markdown-editor.d.ts +1 -1
  83. package/dist/parts/components/markdown-editor.js +1 -1
  84. package/dist/parts/components/markdown-renderer.js +1 -1
  85. package/dist/parts/components/markdown.js +1 -1
  86. package/dist/parts/components/message-parts.js +13 -5
  87. package/dist/parts/components/motion-list.d.ts +42 -0
  88. package/dist/parts/components/motion-list.js +42 -0
  89. package/dist/parts/components/motion.d.ts +124 -0
  90. package/dist/parts/components/motion.js +172 -0
  91. package/dist/parts/components/progress.d.ts +41 -0
  92. package/dist/parts/components/progress.js +54 -0
  93. package/dist/parts/components/prompt-input.d.ts +3 -3
  94. package/dist/parts/components/prompt-input.js +3 -3
  95. package/dist/parts/components/relative-time.js +1 -1
  96. package/dist/parts/components/sync-status.js +2 -1
  97. package/dist/parts/components/tool-list.d.ts +1 -1
  98. package/dist/parts/components/trace-run.d.ts +1 -1
  99. package/dist/parts/components/trace-run.js +2 -2
  100. package/dist/parts/headless/comments.d.ts +2 -2
  101. package/dist/parts/headless/comments.js +1 -1
  102. package/dist/parts/playground/share.d.ts +36 -2
  103. package/dist/parts/workspace/browser-support-notice.js +12 -4
  104. package/dist/parts/workspace/codemirror.d.ts +9 -0
  105. package/dist/parts/workspace/codemirror.js +37 -4
  106. package/dist/parts/workspace/connect-panel.js +1 -1
  107. package/dist/parts/workspace/file-icons.d.ts +16 -0
  108. package/dist/parts/workspace/file-icons.js +82 -0
  109. package/dist/parts/workspace/icons.d.ts +1 -0
  110. package/dist/parts/workspace/icons.js +1 -0
  111. package/dist/parts/workspace/runners/render.d.ts +26 -0
  112. package/dist/parts/workspace/runners/render.js +124 -0
  113. package/dist/parts/workspace/runners/web-container.d.ts +29 -0
  114. package/dist/parts/workspace/runners/web-container.js +186 -0
  115. package/dist/parts/workspace/workspace-bar.d.ts +51 -0
  116. package/dist/parts/workspace/workspace-bar.js +51 -0
  117. package/dist/parts/workspace/workspace-boot-status.js +1 -1
  118. package/dist/parts/workspace/workspace-editor-head.d.ts +47 -0
  119. package/dist/parts/workspace/workspace-editor-head.js +66 -0
  120. package/dist/parts/workspace/workspace-editor.d.ts +17 -0
  121. package/dist/parts/workspace/workspace-editor.js +29 -3
  122. package/dist/parts/workspace/workspace-examples.d.ts +74 -0
  123. package/dist/parts/workspace/workspace-examples.js +72 -0
  124. package/dist/parts/workspace/workspace-file-link.d.ts +35 -0
  125. package/dist/parts/workspace/workspace-file-link.js +39 -0
  126. package/dist/parts/workspace/workspace-file-tree.d.ts +8 -8
  127. package/dist/parts/workspace/workspace-file-tree.js +26 -19
  128. package/dist/parts/workspace/workspace-guide.d.ts +52 -0
  129. package/dist/parts/workspace/workspace-guide.js +91 -0
  130. package/dist/parts/workspace/workspace-issues.d.ts +46 -0
  131. package/dist/parts/workspace/workspace-issues.js +49 -0
  132. package/dist/parts/workspace/workspace-preview.js +1 -1
  133. package/dist/parts/workspace/workspace-shell.d.ts +2 -88
  134. package/dist/parts/workspace/workspace-shell.js +131 -78
  135. package/dist/parts/workspace/workspace-sidebar.d.ts +75 -0
  136. package/dist/parts/workspace/workspace-sidebar.js +132 -0
  137. package/dist/parts/workspace/workspace-start.d.ts +47 -0
  138. package/dist/parts/workspace/workspace-start.js +60 -0
  139. package/dist/parts/workspace/workspace-status.d.ts +69 -0
  140. package/dist/parts/workspace/workspace-status.js +74 -0
  141. package/dist/parts/workspace/workspace-steps.d.ts +2 -0
  142. package/dist/parts/workspace/workspace-steps.js +128 -0
  143. package/dist/parts/workspace/workspace-task.d.ts +20 -0
  144. package/dist/parts/workspace/workspace-task.js +20 -0
  145. package/dist/parts/workspace/workspace.d.ts +251 -0
  146. package/dist/parts/workspace/workspace.js +665 -0
  147. package/dist/{pierre-code-view-xgBL6DO7.js → pierre-code-view-NE35tkmR.js} +37 -17
  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 +657 -526
  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-Dyr6CfBW.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 +17 -4
  165. package/dist/workspace.js +16 -3
  166. package/package.json +22 -11
  167. package/dist/copy-button-CRN3kmSD.js +0 -253
  168. package/dist/format-Du58PlsG.js +0 -18
  169. package/dist/icon-swap.css +0 -69
  170. package/dist/parts/playground/highlight.d.ts +0 -5
  171. package/dist/parts/playground/highlight.js +0 -23
  172. package/dist/parts/playground/playground-render.d.ts +0 -126
  173. package/dist/parts/playground/playground-render.js +0 -356
  174. package/dist/parts/workspace/playground-container.d.ts +0 -192
  175. package/dist/parts/workspace/playground-container.js +0 -603
  176. package/dist/share-DM4eNy4q.d.ts +0 -37
@@ -0,0 +1,797 @@
1
+ import { r as useUIComponent } from "./nuxt-ui-CgvMzO5v.js";
2
+ import { RollNumber } from "./parts/components/motion.js";
3
+ import { a as useViteHubUIIcons } from "./config-B1u7zqMB.js";
4
+ import { Markdown } from "./parts/components/markdown.js";
5
+ import { Attachment, AttachmentContent, AttachmentGroup, AttachmentMedia, AttachmentTitle } from "./parts/components/attachment.js";
6
+ import { AvatarStack } from "./parts/components/avatar-stack.js";
7
+ import { i as consumedPointerEvents, l as swallowNextClick, n as injectComments, o as pathOf, r as commentThreadPortals, s as shakeDirtyComposers, u as useDocumentPointerDown } from "./comments-context-DhbIdYQ1.js";
8
+ import { a as writerName, o as writerPerson, t as displayName } from "./comment-person-CLPlW_SS.js";
9
+ import { n as mentionPlugin, r as mentionTag, t as CommentComposer } from "./comment-composer-D7ZytyER.js";
10
+ import { t as travel } from "./travel-C87xd5Wh.js";
11
+ import { c as messagesSinceResolved, o as commentTitle, s as deliveryAttributes, t as defaultCommentCan } from "./comments-B88zg9gC.js";
12
+ import { t as RelativeTime } from "./relative-time-DgSS3zKN.js";
13
+ import { MotionList } from "./parts/components/motion-list.js";
14
+ import { Marker, MarkerContent } from "./parts/components/marker.js";
15
+ import { computed, defineComponent, h, inject, nextTick, onBeforeUnmount, provide, ref, watch } from "vue";
16
+ //#region src/internal/image-gallery.ts
17
+ const tileCount = 4;
18
+ /** The box of `width` by `height` that covers `box`, centered on it: the picture with the shape it has full size. */
19
+ function cover(box, width, height) {
20
+ if (!width || !height || !box.width || !box.height) return box;
21
+ const scale = Math.max(box.width / width, box.height / height);
22
+ const w = width * scale;
23
+ const h = height * scale;
24
+ return {
25
+ left: box.left + (box.width - w) / 2,
26
+ top: box.top + (box.height - h) / 2,
27
+ width: w,
28
+ height: h
29
+ };
30
+ }
31
+ /**
32
+ * The pictures of a comment as a mosaic: one keeps its own shape, two split the width, three put the first beside the
33
+ * other two, and four or more show a grid of four whose last tile says how many more. A click opens the picture full
34
+ * size, travelling from its tile, and the arrow keys and buttons step through every picture of the message. Closing
35
+ * sends the picture back to its tile (docs/design/motion.md, "Something moves to a new place: a picture that zooms").
36
+ */
37
+ const ImageGallery = defineComponent({
38
+ name: "ImageGallery",
39
+ props: { images: {
40
+ required: true,
41
+ type: Array
42
+ } },
43
+ setup(props) {
44
+ const UModal = useUIComponent("UModal");
45
+ const UButton = useUIComponent("UButton");
46
+ const icons = useViteHubUIIcons();
47
+ const current = ref(null);
48
+ const closing = ref(false);
49
+ const failed = ref(/* @__PURE__ */ new Map());
50
+ const body = ref();
51
+ const portals = inject(commentThreadPortals, void 0);
52
+ portals?.add(body);
53
+ const tiles = [];
54
+ const picture = ref(null);
55
+ let flight;
56
+ const tileOf = (index) => tiles[Math.min(index, 3)];
57
+ const shown = computed(() => current.value === null ? void 0 : props.images[current.value]);
58
+ watch(() => props.images, (images) => {
59
+ failed.value = new Map(images.filter(({ key, src }) => failed.value.get(key) === src).map(({ key, src }) => [key, src]));
60
+ });
61
+ const markFailed = ({ key, src }) => {
62
+ if (props.images.some((image) => image.key === key && image.src === src)) failed.value.set(key, src);
63
+ };
64
+ async function flyIn(index) {
65
+ await nextTick();
66
+ const image = picture.value;
67
+ const tile = tileOf(index);
68
+ if (!image || !tile || current.value !== index) return;
69
+ if (!image.complete) await new Promise((resolve) => image.addEventListener("load", resolve, { once: true }));
70
+ if (current.value !== index || !image.isConnected) return;
71
+ flight = travel(image, { from: cover(tile.getBoundingClientRect(), image.offsetWidth, image.offsetHeight) });
72
+ }
73
+ function open(index) {
74
+ flight?.stop();
75
+ closing.value = false;
76
+ current.value = index;
77
+ flyIn(index);
78
+ }
79
+ async function close() {
80
+ if (current.value === null || closing.value) return;
81
+ const image = picture.value;
82
+ const tile = tileOf(current.value);
83
+ closing.value = true;
84
+ if (image && tile && image.complete && image.naturalWidth) {
85
+ flight = travel(image, { to: cover(tile.getBoundingClientRect(), image.offsetWidth, image.offsetHeight) });
86
+ await flight.done;
87
+ }
88
+ flight?.stop();
89
+ if (!closing.value) return;
90
+ closing.value = false;
91
+ current.value = null;
92
+ }
93
+ function go(step) {
94
+ if (current.value === null || closing.value || props.images.length < 2) return;
95
+ flight?.stop();
96
+ current.value = (current.value + step + props.images.length) % props.images.length;
97
+ }
98
+ onBeforeUnmount(() => {
99
+ flight?.stop();
100
+ portals?.delete(body);
101
+ });
102
+ return () => {
103
+ const count = props.images.length;
104
+ tiles.length = 0;
105
+ const many = count > 1;
106
+ const active = shown.value;
107
+ return h("div", {
108
+ "data-count": Math.min(count, tileCount),
109
+ "data-slot": "comment-reply-images"
110
+ }, [...props.images.slice(0, tileCount).map((image, index) => h("button", {
111
+ "aria-label": `Preview ${image.name}`,
112
+ "data-open": current.value !== null && Math.min(current.value, 3) === index ? "true" : void 0,
113
+ "data-slot": "comment-reply-image",
114
+ key: image.key,
115
+ onClick: () => open(index),
116
+ ref: (element) => {
117
+ if (element instanceof HTMLElement) tiles[index] = element;
118
+ },
119
+ title: image.name,
120
+ type: "button"
121
+ }, [failed.value.get(image.key) === image.src ? h("span", { class: "vh-image-unavailable" }, "Image unavailable") : h("img", {
122
+ alt: "",
123
+ loading: "lazy",
124
+ key: image.src,
125
+ onError: () => markFailed(image),
126
+ src: image.src
127
+ }), index === 3 && count > tileCount ? h("span", {
128
+ "aria-hidden": "true",
129
+ "data-slot": "comment-reply-image-more"
130
+ }, `+${count - tileCount + 1}`) : null])), h(UModal, {
131
+ open: current.value !== null,
132
+ title: shown.value?.name ?? "Image",
133
+ transition: false,
134
+ ui: {
135
+ content: "vh-image-dialog vh-image-gallery",
136
+ overlay: closing.value ? "vh-image-overlay vh-image-overlay--closing" : "vh-image-overlay"
137
+ },
138
+ "onUpdate:open": (value) => {
139
+ if (!value) close();
140
+ }
141
+ }, { content: () => h("div", {
142
+ class: "vh-image-gallery__body",
143
+ ref: body,
144
+ onKeydown: (event) => {
145
+ if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
146
+ event.preventDefault();
147
+ go(event.key === "ArrowLeft" ? -1 : 1);
148
+ }
149
+ }, [h("div", {
150
+ class: "vh-image-dialog__toolbar",
151
+ "data-closing": closing.value ? "true" : void 0
152
+ }, [
153
+ h("span", {
154
+ class: "vh-image-dialog__name",
155
+ title: shown.value?.name
156
+ }, shown.value?.name),
157
+ many ? h("span", { class: "vh-image-gallery__count" }, [h(RollNumber, { value: (current.value ?? 0) + 1 }), ` of ${count}`]) : null,
158
+ h(UButton, {
159
+ "aria-label": "Open original image",
160
+ class: "vh-image-dialog__action",
161
+ color: "neutral",
162
+ external: true,
163
+ icon: icons.value.external,
164
+ rel: "noreferrer",
165
+ target: "_blank",
166
+ to: shown.value?.src,
167
+ variant: "ghost"
168
+ }),
169
+ h(UButton, {
170
+ "aria-label": "Close image preview",
171
+ class: "vh-image-dialog__action",
172
+ color: "neutral",
173
+ icon: icons.value.close,
174
+ onClick: () => void close(),
175
+ variant: "ghost"
176
+ })
177
+ ]), h("div", { class: "vh-image-gallery__stage" }, [
178
+ many ? h(UButton, {
179
+ "aria-label": "Previous picture",
180
+ class: "vh-image-gallery__step vh-image-gallery__step--previous rounded-full",
181
+ color: "neutral",
182
+ icon: icons.value.chevronLeft,
183
+ onClick: () => go(-1),
184
+ variant: "solid"
185
+ }) : null,
186
+ active && failed.value.get(active.key) === active.src ? h("p", {
187
+ class: "vh-image-dialog__error",
188
+ role: "status"
189
+ }, "Image unavailable. The file may have been moved or deleted.") : h("img", {
190
+ alt: active?.name ?? "",
191
+ class: "vh-image-dialog__image",
192
+ key: active?.src,
193
+ onError: () => active && markFailed(active),
194
+ ref: picture,
195
+ src: active?.src
196
+ }),
197
+ many ? h(UButton, {
198
+ "aria-label": "Next picture",
199
+ class: "vh-image-gallery__step vh-image-gallery__step--next rounded-full",
200
+ color: "neutral",
201
+ icon: icons.value.chevronRight,
202
+ onClick: () => go(1),
203
+ variant: "solid"
204
+ }) : null
205
+ ])]) })]);
206
+ };
207
+ }
208
+ });
209
+ //#endregion
210
+ //#region src/components/comment-thread.ts
211
+ const imageExtensions = /* @__PURE__ */ new Set([
212
+ "apng",
213
+ "avif",
214
+ "bmp",
215
+ "gif",
216
+ "heic",
217
+ "jpeg",
218
+ "jpg",
219
+ "png",
220
+ "svg",
221
+ "webp"
222
+ ]);
223
+ function reason(error) {
224
+ return error instanceof Error ? error.message : "That did not work. Try again.";
225
+ }
226
+ const fileName = (key) => key.split(/[/\\]/).at(-1) || key;
227
+ function attachmentHref(value) {
228
+ if (!value) return void 0;
229
+ try {
230
+ const { protocol } = new URL(value, "https://vitehub.invalid");
231
+ return protocol === "http:" || protocol === "https:" || protocol === "blob:" ? value : void 0;
232
+ } catch {
233
+ return;
234
+ }
235
+ }
236
+ function attachmentList(message, url, icon, fileIcon) {
237
+ if (message.attachments.length === 0) return null;
238
+ const items = message.attachments.map((key) => {
239
+ const found = url?.(key);
240
+ const link = typeof found === "string" ? { url: found } : found;
241
+ const name = link?.name || fileName(key);
242
+ const extension = /\.([a-z0-9]+)$/i.exec(name)?.[1]?.toLowerCase();
243
+ const href = attachmentHref(link?.url);
244
+ return {
245
+ href,
246
+ image: href !== void 0 && (link?.type ? link.type.startsWith("image/") : extension === void 0 || imageExtensions.has(extension)),
247
+ key,
248
+ name
249
+ };
250
+ });
251
+ const images = items.flatMap((item) => item.image && item.href ? [{
252
+ key: item.key,
253
+ name: item.name,
254
+ src: item.href
255
+ }] : []);
256
+ const files = items.filter((item) => !item.image);
257
+ return [images.length > 0 ? h(ImageGallery, { images }) : null, files.length > 0 ? h(AttachmentGroup, { "data-slot": "comment-reply-attachments" }, () => files.map((item) => h(Attachment, {
258
+ key: item.key,
259
+ size: "xs"
260
+ }, () => [h(AttachmentMedia, { variant: "icon" }, () => h(icon, { name: fileIcon })), h(AttachmentContent, () => h(AttachmentTitle, () => item.href ? h("a", {
261
+ href: item.href,
262
+ rel: "noreferrer",
263
+ target: "_blank"
264
+ }, item.name) : item.name))]))) : null];
265
+ }
266
+ const CommentReply = defineComponent({
267
+ name: "CommentReply",
268
+ props: {
269
+ message: {
270
+ required: true,
271
+ type: Object
272
+ },
273
+ /** The signed-in user. A mention of them looks different. Defaults to the user of the comments state. */
274
+ user: { type: Object },
275
+ /** The signed-in user may edit this message. */
276
+ editable: {
277
+ default: false,
278
+ type: Boolean
279
+ },
280
+ /** The signed-in user may delete this message. Defaults to `editable`. */
281
+ deletable: {
282
+ default: void 0,
283
+ type: Boolean
284
+ },
285
+ /** The message, and its author, show in one line without actions. */
286
+ compact: {
287
+ default: false,
288
+ type: Boolean
289
+ },
290
+ /** Deleting asks first. Deleting the first message of a thread deletes the whole thread, so a thread sets it there. */
291
+ confirmDelete: {
292
+ default: false,
293
+ type: Boolean
294
+ },
295
+ /** `sm` sets 14px text and shows Edit and Delete over the end of the name's row. The edit box gets the same size. */
296
+ size: {
297
+ default: "md",
298
+ type: String
299
+ },
300
+ /** People whose `@name` the message may hold, so an edit keeps their mentions and the body marks them. */
301
+ people: {
302
+ default: () => [],
303
+ type: Array
304
+ },
305
+ users: { type: Function },
306
+ /** Gives the URL of an attachment key. With it, image attachments show as thumbnails. */
307
+ attachmentUrl: { type: Function },
308
+ /** Saves an edit. Gets `(messageId, body, mentions)`. */
309
+ onEdit: { type: Function },
310
+ /** Deletes the message. Gets `(messageId)`. */
311
+ onDelete: { type: Function }
312
+ },
313
+ slots: Object,
314
+ setup(props, { slots }) {
315
+ const UButton = useUIComponent("UButton");
316
+ const UIcon = useUIComponent("UIcon");
317
+ const icons = useViteHubUIIcons();
318
+ const comments = injectComments();
319
+ const editing = ref(false);
320
+ const confirming = ref(false);
321
+ const busy = ref(false);
322
+ const error = ref();
323
+ const draft = ref("");
324
+ const mentions = ref([]);
325
+ const self = () => props.user?.id ?? comments?.user.value?.id;
326
+ const MentionChip = defineComponent({
327
+ props: {
328
+ label: {
329
+ default: "",
330
+ type: String
331
+ },
332
+ user: {
333
+ default: "",
334
+ type: String
335
+ }
336
+ },
337
+ setup(chip) {
338
+ return () => props.message.mentions.includes(chip.user) ? h("span", {
339
+ "data-self": chip.user === self() ? "true" : void 0,
340
+ "data-slot": "comment-mention"
341
+ }, `@${chip.label}`) : `@${chip.label}`;
342
+ }
343
+ });
344
+ const bodyComponents = { [mentionTag]: MentionChip };
345
+ const bodyPlugins = computed(() => {
346
+ const known = /* @__PURE__ */ new Map();
347
+ for (const person of [
348
+ ...comments?.people.value ?? [],
349
+ ...props.people,
350
+ ...props.user ? [props.user] : []
351
+ ]) known.set(person.id, person);
352
+ const named = props.message.mentions.flatMap((id) => {
353
+ const person = known.get(id);
354
+ return person ? [{
355
+ id,
356
+ name: displayName(person)
357
+ }] : [];
358
+ });
359
+ return [mentionPlugin(named)];
360
+ });
361
+ async function run(task) {
362
+ if (busy.value) return false;
363
+ busy.value = true;
364
+ error.value = void 0;
365
+ try {
366
+ await task();
367
+ return true;
368
+ } catch (cause) {
369
+ error.value = reason(cause);
370
+ return false;
371
+ } finally {
372
+ busy.value = false;
373
+ }
374
+ }
375
+ function startEdit() {
376
+ draft.value = props.message.body;
377
+ mentions.value = [...props.message.mentions];
378
+ error.value = void 0;
379
+ editing.value = true;
380
+ }
381
+ async function save(submit) {
382
+ if (!props.onEdit) return;
383
+ const submitted = draft.value;
384
+ const submittedMentions = mentions.value;
385
+ const savedMentions = submit.body === props.message.body ? [.../* @__PURE__ */ new Set([...props.message.mentions, ...submit.mentions])] : submit.mentions;
386
+ if (await run(() => props.onEdit?.(props.message.id, submit.body, savedMentions)) && draft.value === submitted && mentions.value === submittedMentions) editing.value = false;
387
+ }
388
+ const canEdit = () => props.editable && props.onEdit !== void 0;
389
+ const canDelete = () => (props.deletable ?? props.editable) && props.onDelete !== void 0;
390
+ async function remove() {
391
+ if (!props.onDelete) return;
392
+ if (await run(() => props.onDelete?.(props.message.id))) confirming.value = false;
393
+ }
394
+ const statusOf = (message, delivery) => {
395
+ if (!slots.status) return null;
396
+ const outbox = comments?.outbox;
397
+ const current = () => !props.compact && props.message.id === message.id && props.message.delivery !== void 0;
398
+ const mayEdit = () => current() && props.editable;
399
+ const mayDelete = () => current() && (props.deletable ?? props.editable);
400
+ return h("div", { "data-slot": "comment-reply-status" }, slots.status({
401
+ delivery,
402
+ dismiss: outbox?.enabled && mayDelete() ? async () => mayDelete() && await outbox.dismiss(message.id) : void 0,
403
+ edit: outbox?.enabled && mayEdit() ? async (body, mentions) => mayEdit() && await outbox.edit(message.id, body, mentions) : void 0,
404
+ message,
405
+ retry: outbox?.enabled && mayEdit() ? async () => {
406
+ if (mayEdit()) await outbox.retry(message.id);
407
+ } : void 0
408
+ }));
409
+ };
410
+ return () => {
411
+ const { message } = props;
412
+ return h("div", {
413
+ "data-compact": props.compact ? "true" : void 0,
414
+ "data-editing": editing.value ? "true" : void 0,
415
+ ...deliveryAttributes(message.delivery),
416
+ "data-size": props.size,
417
+ "data-slot": "comment-reply"
418
+ }, [h("div", { "data-slot": "comment-reply-content" }, [
419
+ h("div", { "data-slot": "comment-reply-header" }, [
420
+ h(AvatarStack, {
421
+ "aria-hidden": "true",
422
+ people: [writerPerson(message)],
423
+ size: "sm"
424
+ }),
425
+ h("span", {
426
+ "data-agent": message.actor ? "true" : void 0,
427
+ "data-slot": "comment-reply-author"
428
+ }, writerName(message)),
429
+ h(RelativeTime, {
430
+ at: message.createdAt,
431
+ "data-slot": "comment-reply-time"
432
+ }),
433
+ message.editedAt ? h("span", { "data-slot": "comment-reply-edited" }, "edited") : null
434
+ ]),
435
+ editing.value ? h(CommentComposer, {
436
+ autofocus: true,
437
+ busy: busy.value,
438
+ error: error.value,
439
+ mentions: mentions.value,
440
+ modelValue: draft.value,
441
+ onCancel: () => {
442
+ if (!busy.value) editing.value = false;
443
+ },
444
+ onSubmit: save,
445
+ "onUpdate:mentions": (value) => mentions.value = value,
446
+ "onUpdate:modelValue": (value) => draft.value = value,
447
+ people: props.people,
448
+ size: props.size,
449
+ users: props.users,
450
+ variant: "edit"
451
+ }, {
452
+ ...slots["mention-item"] ? { "mention-item": slots["mention-item"] } : {},
453
+ ...slots["mention-empty"] ? { "mention-empty": slots["mention-empty"] } : {}
454
+ }) : slots.body?.({ message }) ?? h(Markdown, {
455
+ components: bodyComponents,
456
+ "data-slot": "comment-reply-body",
457
+ plugins: bodyPlugins.value,
458
+ value: message.body
459
+ }),
460
+ editing.value || props.compact ? null : slots.attachments?.({ message }) ?? attachmentList(message, props.attachmentUrl, UIcon, icons.value.file),
461
+ !editing.value && message.delivery ? statusOf(message, message.delivery) : null,
462
+ confirming.value ? h("div", {
463
+ "aria-label": "Confirm delete",
464
+ "data-slot": "comment-reply-confirm",
465
+ role: "group"
466
+ }, [
467
+ h("p", "Delete this comment and every reply to it?"),
468
+ h(UButton, {
469
+ color: "error",
470
+ label: "Delete thread",
471
+ loading: busy.value,
472
+ onClick: remove,
473
+ size: "xs"
474
+ }),
475
+ h(UButton, {
476
+ color: "neutral",
477
+ label: "Cancel",
478
+ onClick: () => confirming.value = false,
479
+ size: "xs",
480
+ variant: "ghost"
481
+ })
482
+ ]) : null,
483
+ !editing.value && error.value ? h("p", {
484
+ "data-slot": "comment-reply-error",
485
+ role: "alert"
486
+ }, error.value) : null
487
+ ]), (canEdit() || canDelete()) && !editing.value && !confirming.value && !props.compact ? h("div", { "data-slot": "comment-reply-actions" }, [canEdit() ? h(UButton, {
488
+ "aria-label": "Edit",
489
+ color: "neutral",
490
+ icon: icons.value.edit,
491
+ onClick: startEdit,
492
+ size: "xs",
493
+ variant: "ghost"
494
+ }) : null, canDelete() ? h(UButton, {
495
+ "aria-label": "Delete",
496
+ color: "neutral",
497
+ icon: icons.value.delete,
498
+ onClick: () => props.confirmDelete ? confirming.value = true : void remove(),
499
+ size: "xs",
500
+ variant: "ghost"
501
+ }) : null]) : null]);
502
+ };
503
+ }
504
+ });
505
+ /** "Resolved by Ana", or "Resolved by Claude (Ana)" when her agent did, as a line across the thread. */
506
+ const resolvedMarker = (thread) => h(Marker, {
507
+ key: "resolved",
508
+ variant: "separator"
509
+ }, () => h(MarkerContent, () => `Resolved${thread.resolvedBy ? ` by ${writerName({
510
+ author: thread.resolvedBy,
511
+ ...thread.resolvedActor ? { actor: thread.resolvedActor } : {}
512
+ })}` : ""}`));
513
+ const CommentThread = defineComponent({
514
+ name: "CommentThread",
515
+ props: {
516
+ thread: {
517
+ required: true,
518
+ type: Object
519
+ },
520
+ /** The signed-in user. Their messages can be edited and deleted. */
521
+ user: { type: Object },
522
+ /** A read-only card for hovering a pin. */
523
+ preview: {
524
+ default: false,
525
+ type: Boolean
526
+ },
527
+ /** Keep the full thread readable without reply, edit, delete, or status controls. */
528
+ readOnly: {
529
+ default: false,
530
+ type: Boolean
531
+ },
532
+ /** What the signed-in user may do: reply, resolve, edit, or delete. Defaults to the `can` of the comments state. */
533
+ can: { type: Function },
534
+ /** Show a reply as being sent, on top of the thread's own tracking. */
535
+ busy: {
536
+ default: false,
537
+ type: Boolean
538
+ },
539
+ /** An error to show, on top of the ones from the handlers. */
540
+ error: { type: String },
541
+ /** The thread is no longer on the page, so no pin shows where it was. */
542
+ detached: {
543
+ default: false,
544
+ type: Boolean
545
+ },
546
+ /** People that messages may mention, on top of the authors of the thread. Their mentions show as chips. */
547
+ people: {
548
+ default: () => [],
549
+ type: Array
550
+ },
551
+ /** Finds people for `@mentions`. Defaults to the comments state, searching the people who may be mentioned in this thread. */
552
+ users: { type: Function },
553
+ /** The reply box takes files. `onReply` gets them. */
554
+ attachments: {
555
+ default: true,
556
+ type: Boolean
557
+ },
558
+ /** The file types that the reply box takes, such as `image/*`. */
559
+ accept: { type: String },
560
+ /** Gives the URL of an attachment key. With it, image attachments show as thumbnails. */
561
+ attachmentUrl: { type: Function },
562
+ /** `"back"` shows a Back button at the start of the header instead of Close, for a thread inside a list. Both emit `close`. */
563
+ navigation: {
564
+ default: "close",
565
+ type: String
566
+ },
567
+ /** A click outside the thread closes it. Turn it off when the thread is part of a panel. */
568
+ dismissible: {
569
+ default: true,
570
+ type: Boolean
571
+ },
572
+ /** `sm` is a compact thread for a small floating card: 14px text, tighter rows, and a compact reply box. */
573
+ size: {
574
+ default: "md",
575
+ type: String
576
+ },
577
+ /** Sends a reply. Gets `(body, mentions, files)`. */
578
+ onReply: { type: Function },
579
+ /** Saves an edited message. Gets `(messageId, body, mentions)`. */
580
+ onEdit: { type: Function },
581
+ /** Deletes a message. Gets `(messageId)`. Deleting the first message deletes the thread. */
582
+ onDelete: { type: Function },
583
+ onResolve: { type: Function },
584
+ onReopen: { type: Function }
585
+ },
586
+ emits: ["close"],
587
+ slots: Object,
588
+ setup(props, { emit, expose, slots }) {
589
+ const UButton = useUIComponent("UButton");
590
+ const icons = useViteHubUIIcons();
591
+ const comments = injectComments();
592
+ const root = ref(null);
593
+ const reply = ref("");
594
+ const mentions = ref([]);
595
+ const files = ref([]);
596
+ const sending = ref(false);
597
+ const failure = ref();
598
+ const composer = ref(null);
599
+ const portals = /* @__PURE__ */ new Set();
600
+ provide(commentThreadPortals, portals);
601
+ const user = computed(() => props.user ?? comments?.user.value);
602
+ const users = computed(() => props.users ?? (comments ? (query) => comments.users(query, props.thread.id) : void 0));
603
+ const allowed = (action, message) => !props.readOnly && (props.can ?? comments?.can ?? defaultCommentCan(user.value))(action, {
604
+ message,
605
+ thread: props.thread
606
+ });
607
+ const people = computed(() => {
608
+ const seen = /* @__PURE__ */ new Map();
609
+ for (const person of [
610
+ ...props.people,
611
+ props.thread.author,
612
+ ...props.thread.messages.map((message) => message.author),
613
+ ...user.value ? [user.value] : []
614
+ ]) seen.set(person.id, person);
615
+ return [...seen.values()];
616
+ });
617
+ const participants = computed(() => [.../* @__PURE__ */ new Set([props.thread.author.id, ...props.thread.messages.map((message) => message.author.id)])]);
618
+ useDocumentPointerDown((event) => {
619
+ const path = pathOf(event);
620
+ if (props.preview || !props.dismissible || !root.value || path.includes(root.value)) return;
621
+ for (const portal of portals) if (portal.value && path.includes(portal.value)) return;
622
+ if (path.some((element) => element.matches("[data-slot='comment-pin']")) || consumedPointerEvents.has(event)) return;
623
+ consumedPointerEvents.add(event);
624
+ const where = root.value.getRootNode();
625
+ if (shakeDirtyComposers(where instanceof ShadowRoot ? where : document)) {
626
+ event.stopPropagation();
627
+ swallowNextClick();
628
+ } else emit("close");
629
+ });
630
+ async function send(submit) {
631
+ if (sending.value || !props.onReply) return;
632
+ sending.value = true;
633
+ failure.value = void 0;
634
+ const submitted = reply.value;
635
+ const submittedMentions = mentions.value;
636
+ const submittedFiles = files.value;
637
+ try {
638
+ await props.onReply(submit.body, [...submit.mentions], [...submit.files]);
639
+ if (reply.value === submitted && mentions.value === submittedMentions && files.value === submittedFiles) {
640
+ reply.value = "";
641
+ mentions.value = [];
642
+ files.value = [];
643
+ }
644
+ nextTick(() => composer.value?.focus());
645
+ } catch (cause) {
646
+ failure.value = reason(cause);
647
+ } finally {
648
+ sending.value = false;
649
+ }
650
+ }
651
+ async function act(task) {
652
+ if (root.value && shakeDirtyComposers(root.value)) return;
653
+ failure.value = void 0;
654
+ try {
655
+ await task?.();
656
+ } catch (cause) {
657
+ failure.value = reason(cause);
658
+ }
659
+ }
660
+ function close() {
661
+ if (root.value && shakeDirtyComposers(root.value)) return;
662
+ emit("close");
663
+ }
664
+ expose({ close });
665
+ const replySlots = () => ({
666
+ ...slots.body ? { body: slots.body } : {},
667
+ ...slots.attachments ? { attachments: slots.attachments } : {},
668
+ ...slots.status ? { status: slots.status } : {},
669
+ ...slots["mention-item"] ? { "mention-item": slots["mention-item"] } : {},
670
+ ...slots["mention-empty"] ? { "mention-empty": slots["mention-empty"] } : {}
671
+ });
672
+ const composerSlots = () => ({
673
+ ...slots.extra ? { extra: slots.extra } : {},
674
+ ...slots["mention-item"] ? { "mention-item": slots["mention-item"] } : {},
675
+ ...slots["mention-empty"] ? { "mention-empty": slots["mention-empty"] } : {}
676
+ });
677
+ return () => {
678
+ const { thread } = props;
679
+ const resolved = thread.status === "resolved";
680
+ const later = messagesSinceResolved(thread);
681
+ const resolvable = !resolved || later.length > 0;
682
+ const first = thread.messages[0];
683
+ const quote = thread.anchor.kind === "text" ? thread.anchor.exact : void 0;
684
+ if (props.preview) {
685
+ const replies = thread.messages.length - 1;
686
+ return h("div", {
687
+ ...deliveryAttributes(thread.delivery),
688
+ "data-preview": "true",
689
+ "data-size": props.size,
690
+ "data-slot": "comment-thread",
691
+ "data-status": thread.status
692
+ }, [first ? h(CommentReply, {
693
+ compact: true,
694
+ message: first,
695
+ people: people.value,
696
+ size: props.size,
697
+ user: user.value
698
+ }, {
699
+ ...slots.body ? { body: slots.body } : {},
700
+ ...slots.status ? { status: slots.status } : {}
701
+ }) : null, replies > 0 ? h("p", { "data-slot": "comment-thread-count" }, [h(RollNumber, { value: replies }), replies === 1 ? " reply" : " replies"]) : null]);
702
+ }
703
+ const back = props.navigation === "back";
704
+ const anchor = slots.anchor ? slots.anchor({ thread }) : quote ? h("blockquote", { "data-slot": "comment-thread-quote" }, quote) : null;
705
+ return h("section", {
706
+ "aria-label": commentTitle(thread),
707
+ ...deliveryAttributes(thread.delivery),
708
+ "data-size": props.size,
709
+ "data-slot": "comment-thread",
710
+ "data-status": thread.status,
711
+ ref: root,
712
+ role: "dialog",
713
+ tabindex: -1
714
+ }, [
715
+ h("header", { "data-slot": "comment-thread-header" }, [
716
+ back ? h(UButton, {
717
+ "aria-label": "Back to comments",
718
+ color: "neutral",
719
+ icon: icons.value.arrowLeft,
720
+ onClick: close,
721
+ size: "xs",
722
+ variant: "ghost"
723
+ }) : null,
724
+ h("span", { "data-slot": "comment-thread-title" }, commentTitle(thread)),
725
+ h("span", { "data-slot": "comment-thread-spacer" }),
726
+ slots.actions ? h("div", { "data-slot": "comment-thread-actions" }, slots.actions({ thread })) : null,
727
+ !allowed("resolve") ? null : h(UButton, {
728
+ "aria-label": resolvable ? "Resolve" : "Reopen",
729
+ color: "neutral",
730
+ icon: resolvable ? icons.value.check : icons.value.reopen,
731
+ onClick: () => void act(resolvable ? props.onResolve : props.onReopen),
732
+ size: "xs",
733
+ variant: "ghost"
734
+ }),
735
+ back ? null : h(UButton, {
736
+ "aria-label": "Close",
737
+ color: "neutral",
738
+ icon: icons.value.close,
739
+ onClick: close,
740
+ size: "xs",
741
+ variant: "ghost"
742
+ })
743
+ ]),
744
+ h(MotionList, { "data-slot": "comment-thread-messages" }, () => [
745
+ anchor,
746
+ props.detached ? h("p", {
747
+ "data-slot": "comment-thread-detached",
748
+ role: "status"
749
+ }, "The place of this comment is no longer on the page.") : null,
750
+ ...thread.messages.flatMap((message, index) => [resolved && message === later[0] ? resolvedMarker(thread) : null, h(CommentReply, {
751
+ attachmentUrl: props.attachmentUrl,
752
+ confirmDelete: index === 0,
753
+ deletable: allowed("delete", message),
754
+ editable: allowed("edit", message),
755
+ key: message.id,
756
+ message,
757
+ onDelete: props.onDelete,
758
+ onEdit: props.onEdit,
759
+ people: people.value,
760
+ size: props.size,
761
+ user: user.value,
762
+ users: users.value
763
+ }, replySlots())]),
764
+ resolved && later.length === 0 ? resolvedMarker(thread) : null,
765
+ slots.after ? h("div", { "data-slot": "comment-thread-after" }, slots.after({ thread })) : null
766
+ ]),
767
+ !allowed("reply") && (failure.value ?? props.error) ? h("p", { role: "alert" }, failure.value ?? props.error) : null,
768
+ !allowed("reply") ? null : h(CommentComposer, {
769
+ accept: props.accept,
770
+ attachments: props.attachments,
771
+ autofocus: false,
772
+ busy: props.busy || sending.value,
773
+ error: failure.value ?? props.error,
774
+ files: files.value,
775
+ guard: false,
776
+ layout: "row",
777
+ mentions: mentions.value,
778
+ modelValue: reply.value,
779
+ onCancel: close,
780
+ onSubmit: send,
781
+ participants: participants.value,
782
+ "onUpdate:files": (value) => files.value = value,
783
+ "onUpdate:mentions": (value) => mentions.value = value,
784
+ "onUpdate:modelValue": (value) => reply.value = value,
785
+ people: people.value,
786
+ ref: composer,
787
+ size: props.size,
788
+ user: user.value,
789
+ users: users.value,
790
+ variant: "reply"
791
+ }, composerSlots())
792
+ ]);
793
+ };
794
+ }
795
+ });
796
+ //#endregion
797
+ export { CommentThread as n, CommentReply as t };