@vite-hub/ui 0.3.1 → 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.
Files changed (71) hide show
  1. package/README.md +5 -5
  2. package/dist/{avatar-stack-DXmCQhxd.d.ts → avatar-stack-DPRFuezh.d.ts} +1 -1
  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-Cc8Jvu6u.d.ts → comment-composer-fINL5bxo.d.ts} +3 -3
  6. package/dist/{comment-layer-ClH4MLj4.d.ts → comment-layer-C_sbPIR5.d.ts} +18 -7
  7. package/dist/{comment-list-B8hphLfS.d.ts → comment-list-BcSaLngS.d.ts} +3 -3
  8. package/dist/{comment-panel-fcKSKwLC.d.ts → comment-panel-CfvdRUMX.d.ts} +16 -5
  9. package/dist/{comment-pin-CvwgRSDR.d.ts → comment-pin-DHOdRvUw.d.ts} +1 -1
  10. package/dist/{comment-row-Bbm9WwuF.js → comment-row-Bn3nr8l5.js} +1 -1
  11. package/dist/comment-selection-bar-CyVBNYl9.d.ts +42 -0
  12. package/dist/{comment-thread-CoTLrdal.d.ts → comment-thread-DKJjmWN0.d.ts} +23 -6
  13. package/dist/{comments-CkWc2Khc.js → comments-D0d26ghV.js} +65 -9
  14. package/dist/{comments-Bx2WRsYy.d.ts → comments-D8hulVPy.d.ts} +34 -6
  15. package/dist/format-orwcdZL_.js +39 -0
  16. package/dist/headless.d.ts +3 -3
  17. package/dist/headless.js +1 -1
  18. package/dist/{index-BD1e8vx5.d.ts → index-BYRFQfCd.d.ts} +6 -0
  19. package/dist/index.d.ts +13 -12
  20. package/dist/index.js +4 -3
  21. package/dist/{markdown-editor-DqdZfIEn.d.ts → markdown-editor-wQF0yD5o.d.ts} +1 -1
  22. package/dist/markdown-editor.d.ts +1 -1
  23. package/dist/{message-scroller-Bm1YWTeY.d.ts → message-scroller-jrYN9dG9.d.ts} +2 -2
  24. package/dist/nuxt.d.ts +1 -1
  25. package/dist/nuxt.js +8 -2
  26. package/dist/parts/components/attachment.d.ts +1 -1
  27. package/dist/parts/components/avatar-stack.d.ts +1 -1
  28. package/dist/parts/components/avatar-stack.js +1 -1
  29. package/dist/parts/components/bubble.d.ts +1 -1
  30. package/dist/parts/components/chat-session.d.ts +1 -1
  31. package/dist/parts/components/code-block.d.ts +1 -1
  32. package/dist/parts/components/code-view.js +1 -1
  33. package/dist/parts/components/comment-composer.d.ts +1 -1
  34. package/dist/parts/components/comment-layer.d.ts +1 -1
  35. package/dist/parts/components/comment-layer.js +32 -19
  36. package/dist/parts/components/comment-list.d.ts +1 -1
  37. package/dist/parts/components/comment-list.js +3 -2
  38. package/dist/parts/components/comment-panel.d.ts +1 -1
  39. package/dist/parts/components/comment-panel.js +24 -12
  40. package/dist/parts/components/comment-pin.d.ts +1 -1
  41. package/dist/parts/components/comment-pin.js +1 -1
  42. package/dist/parts/components/comment-selection-bar.d.ts +2 -0
  43. package/dist/parts/components/comment-selection-bar.js +116 -0
  44. package/dist/parts/components/comment-thread.d.ts +2 -2
  45. package/dist/parts/components/comment-thread.js +33 -6
  46. package/dist/parts/components/comments.d.ts +8 -7
  47. package/dist/parts/components/comments.js +3 -2
  48. package/dist/parts/components/copy-button.d.ts +1 -1
  49. package/dist/parts/components/device-frame.d.ts +2 -2
  50. package/dist/parts/components/markdown-editor.d.ts +1 -1
  51. package/dist/parts/components/marker.d.ts +1 -1
  52. package/dist/parts/components/prompt-input.d.ts +3 -3
  53. package/dist/parts/components/tool-list.d.ts +1 -1
  54. package/dist/parts/components/trace-run.d.ts +1 -1
  55. package/dist/parts/components/trace-run.js +1 -1
  56. package/dist/parts/components/trace.d.ts +1 -1
  57. package/dist/parts/headless/comments.d.ts +2 -2
  58. package/dist/parts/headless/comments.js +1 -1
  59. package/dist/parts/headless/message-scroller.d.ts +1 -1
  60. package/dist/parts/workspace/browser-support-notice.d.ts +1 -1
  61. package/dist/parts/workspace/connect-panel.d.ts +1 -1
  62. package/dist/parts/workspace/playground-container.d.ts +2 -2
  63. package/dist/parts/workspace/workspace-boot-status.js +1 -1
  64. package/dist/parts/workspace/workspace-shell.d.ts +1 -1
  65. package/dist/{pierre-code-view-xgBL6DO7.js → pierre-code-view-NE35tkmR.js} +37 -17
  66. package/dist/styles.css +119 -1
  67. package/dist/{types-Dyr6CfBW.d.ts → types-Dj7vp0lZ.d.ts} +1 -1
  68. package/dist/workspace.d.ts +1 -1
  69. package/dist/workspace.js +1 -1
  70. package/package.json +7 -7
  71. package/dist/format-Du58PlsG.js +0 -18
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # @vite-hub/ui
2
2
 
3
- [![npm version](https://comark-ui.onmax.me/badge.svg?source=npm-version&package=%40vite-hub%2Fui&icon=npm)](https://npmx.dev/package/@vite-hub/ui)
4
- [![npm downloads](https://comark-ui.onmax.me/badge.svg?source=npm-downloads&package=%40vite-hub%2Fui&period=month&icon=npm)](https://npmx.dev/package/@vite-hub/ui)
5
- [![license](https://comark-ui.onmax.me/badge.svg?label=license&value=Apache-2.0)](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
6
- [![docs](https://comark-ui.onmax.me/badge.svg?label=docs&value=vitehub.dev)](https://vitehub.dev/docs)
3
+ [![npm version](https://img.shields.io/npm/v/@vite-hub/ui)](https://npmx.dev/package/@vite-hub/ui)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@vite-hub/ui)](https://npmx.dev/package/@vite-hub/ui)
5
+ [![license](https://img.shields.io/static/v1?label=license&message=Apache-2.0&color=blue)](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
6
+ [![docs](https://img.shields.io/static/v1?label=docs&message=vitehub.dev&color=blue)](https://vitehub.dev/docs)
7
7
 
8
8
  Vue primitives for AI chat, traces, diffs, and file trees. The styled components compose [Nuxt UI](https://ui.nuxt.com/) and render [AI SDK](https://ai-sdk.dev/) message contracts; the headless entry point provides message-scrolling behavior without the styled component layer.
9
9
 
@@ -335,7 +335,7 @@ The page displays **ViteHub UI is ready.** in bold. This confirms the public com
335
335
 
336
336
  ## Boundaries and requirements
337
337
 
338
- - Published builds require Node.js 22.22 or newer. The package is pre-1.0, so pin its version and review changes before upgrading.
338
+ - Published builds require Node.js 24.15 or newer. The package is pre-1.0, so pin its version and review changes before upgrading.
339
339
  - The components render state supplied by the application. They do not send messages, fetch Agent Invocations, choose routes, persist sessions, or authorize access to instruction and trace data.
340
340
  - `PromptInput` submits only in the ready state after attachment conversion finishes. It preserves the draft while blocked; Stop and Retry remain separate actions. Custom submit slots receive `canSubmit` and `preparingFiles`. The application owns draft recovery and clearing after a send; unmount the prompt when switching sessions with pending file reads.
341
341
  - Primary chat and trace output supports Vue server rendering. Scrolling observers, clipboard actions, and attachment conversion use browser APIs and become interactive after hydration. Upload and persist raw files yourself when data URLs are not appropriate.
@@ -52,8 +52,8 @@ declare const AvatarStack: import("vue").DefineComponent<import("vue").ExtractPr
52
52
  };
53
53
  }>> & Readonly<{}>, {
54
54
  size: AvatarStackSize;
55
- max: number | null;
56
55
  variant: AvatarStackVariant;
56
+ max: number | null;
57
57
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
58
58
  //#endregion
59
59
  export { AvatarStackVariant as i, AvatarStackPerson as n, AvatarStackSize as r, AvatarStack as t };
@@ -16,10 +16,10 @@ const pierrePropTypes = {
16
16
  };
17
17
  //#endregion
18
18
  //#region src/components/code-view.ts
19
- const PierreCodeView = defineAsyncComponent(() => import("./pierre-code-view-xgBL6DO7.js").then((module) => module.PierreCodeView));
20
- const PierreDiff = defineAsyncComponent(() => import("./pierre-code-view-xgBL6DO7.js").then((module) => module.PierreDiff));
21
- const PierreFile = defineAsyncComponent(() => import("./pierre-code-view-xgBL6DO7.js").then((module) => module.PierreFile));
22
- const PierreUnresolvedFile = defineAsyncComponent(() => import("./pierre-code-view-xgBL6DO7.js").then((module) => module.PierreUnresolvedFile));
19
+ const PierreCodeView = defineAsyncComponent(() => import("./pierre-code-view-NE35tkmR.js").then((module) => module.PierreCodeView));
20
+ const PierreDiff = defineAsyncComponent(() => import("./pierre-code-view-NE35tkmR.js").then((module) => module.PierreDiff));
21
+ const PierreFile = defineAsyncComponent(() => import("./pierre-code-view-NE35tkmR.js").then((module) => module.PierreFile));
22
+ const PierreUnresolvedFile = defineAsyncComponent(() => import("./pierre-code-view-NE35tkmR.js").then((module) => module.PierreUnresolvedFile));
23
23
  const diffProps = {
24
24
  lineAnnotations: { type: pierrePropTypes.diffLineAnnotations },
25
25
  options: { type: pierrePropTypes.fileDiffOptions },
@@ -0,0 +1,20 @@
1
+ import { computed } from "vue";
2
+ //#region src/internal/comment-attachments.ts
3
+ function useCommentAttachments(state, props) {
4
+ const mode = computed(() => {
5
+ if (state.client.transport.supportsAttachments === false) return void 0;
6
+ if (props.upload) return "upload";
7
+ if (state.outbox.enabled && props.queueFiles) return "queue";
8
+ });
9
+ return {
10
+ enabled: computed(() => mode.value !== void 0),
11
+ async prepare(files) {
12
+ return {
13
+ files: mode.value === "queue" ? files : [],
14
+ attachments: mode.value === "upload" && files.length > 0 && props.upload ? await props.upload(files) : []
15
+ };
16
+ }
17
+ };
18
+ }
19
+ //#endregion
20
+ export { useCommentAttachments as t };
@@ -225,17 +225,17 @@ declare const CommentComposer: import("vue").DefineComponent<import("vue").Extra
225
225
  "onUpdate:mentions"?: ((...args: any[]) => any) | undefined;
226
226
  "onUpdate:files"?: ((...args: any[]) => any) | undefined;
227
227
  }>, {
228
- layout: "row" | "box";
229
228
  size: CommentComposerSize;
230
229
  modelValue: string;
231
230
  autofocus: boolean;
232
231
  variant: CommentComposerVariant;
232
+ layout: "row" | "box";
233
233
  people: CommentUser[];
234
- mentions: string[];
235
234
  busy: boolean;
235
+ attachments: boolean;
236
+ mentions: string[];
236
237
  guard: boolean;
237
238
  participants: string[];
238
- attachments: boolean;
239
239
  allowEmpty: boolean;
240
240
  frame: CommentComposerFrame;
241
241
  }, SlotsType<CommentComposerSlots>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -1,8 +1,8 @@
1
- import { n as AvatarStackPerson } from "./avatar-stack-DXmCQhxd.js";
2
- import { r as CommentComposerSize } from "./comment-composer-Cc8Jvu6u.js";
3
- import { o as CommentsState, t as CommentCan } from "./comments-Bx2WRsYy.js";
4
- import { n as CommentAttachmentUrl } from "./comment-thread-CoTLrdal.js";
5
- import { c as CommentUpload } from "./comment-panel-fcKSKwLC.js";
1
+ import { n as AvatarStackPerson } from "./avatar-stack-DPRFuezh.js";
2
+ import { r as CommentComposerSize } from "./comment-composer-fINL5bxo.js";
3
+ import { s as CommentsState, t as CommentCan } from "./comments-D8hulVPy.js";
4
+ import { n as CommentAttachmentUrl } from "./comment-thread-DKJjmWN0.js";
5
+ import { c as CommentUpload } from "./comment-panel-CfvdRUMX.js";
6
6
  import { PropType } from "vue";
7
7
  import { CommentSubject, CommentUser, CommentsClient } from "@vite-hub/comments/client";
8
8
  //#region src/components/comment-layer.d.ts
@@ -51,10 +51,15 @@ declare const CommentLayer: import("vue").DefineComponent<import("vue").ExtractP
51
51
  can: {
52
52
  type: PropType<CommentCan>;
53
53
  };
54
- /** Turns attached files into attachment keys. Without it the boxes take no files. */
54
+ /** Turns attached files into attachment keys before the comment is saved or sent. */
55
55
  upload: {
56
56
  type: PropType<CommentUpload>;
57
57
  };
58
+ /** Save raw files with outbox entries. Set only when the server accepts file uploads. `upload` takes precedence. */
59
+ queueFiles: {
60
+ default: boolean;
61
+ type: BooleanConstructor;
62
+ };
58
63
  /** The file types that the boxes take, such as `image/*`. */
59
64
  accept: {
60
65
  type: StringConstructor;
@@ -125,10 +130,15 @@ declare const CommentLayer: import("vue").DefineComponent<import("vue").ExtractP
125
130
  can: {
126
131
  type: PropType<CommentCan>;
127
132
  };
128
- /** Turns attached files into attachment keys. Without it the boxes take no files. */
133
+ /** Turns attached files into attachment keys before the comment is saved or sent. */
129
134
  upload: {
130
135
  type: PropType<CommentUpload>;
131
136
  };
137
+ /** Save raw files with outbox entries. Set only when the server accepts file uploads. `upload` takes precedence. */
138
+ queueFiles: {
139
+ default: boolean;
140
+ type: BooleanConstructor;
141
+ };
132
142
  /** The file types that the boxes take, such as `image/*`. */
133
143
  accept: {
134
144
  type: StringConstructor;
@@ -159,6 +169,7 @@ declare const CommentLayer: import("vue").DefineComponent<import("vue").ExtractP
159
169
  people: AvatarStackPerson[];
160
170
  hotkey: string | false;
161
171
  readOnly: boolean;
172
+ queueFiles: boolean;
162
173
  placement: CommentPlacement;
163
174
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
164
175
  //#endregion
@@ -1,6 +1,6 @@
1
- import { n as AvatarStackPerson } from "./avatar-stack-DXmCQhxd.js";
2
- import { o as CommentsState } from "./comments-Bx2WRsYy.js";
3
- import { s as CommentRowSlots } from "./comment-panel-fcKSKwLC.js";
1
+ import { n as AvatarStackPerson } from "./avatar-stack-DPRFuezh.js";
2
+ import { s as CommentsState } from "./comments-D8hulVPy.js";
3
+ import { s as CommentRowSlots } from "./comment-panel-CfvdRUMX.js";
4
4
  import { PropType, SlotsType } from "vue";
5
5
  //#region src/components/comment-list.d.ts
6
6
  declare const CommentFilters: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
@@ -1,5 +1,5 @@
1
- import { o as CommentsState, t as CommentCan } from "./comments-Bx2WRsYy.js";
2
- import { c as CommentThreadSlots, n as CommentAttachmentUrl } from "./comment-thread-CoTLrdal.js";
1
+ import { s as CommentsState, t as CommentCan } from "./comments-D8hulVPy.js";
2
+ import { l as CommentThreadSlots, n as CommentAttachmentUrl } from "./comment-thread-DKJjmWN0.js";
3
3
  import { PropType, SlotsType, VNode } from "vue";
4
4
  import { CommentStatus, CommentSubject, CommentThread, CommentUser, CommentsClient } from "@vite-hub/comments/client";
5
5
  //#region src/components/comment-panel.d.ts
@@ -72,10 +72,15 @@ declare const CommentPanel: import("vue").DefineComponent<import("vue").ExtractP
72
72
  default: boolean;
73
73
  type: BooleanConstructor;
74
74
  };
75
- /** Turns attached files into attachment keys. Without it the boxes take no files. */
75
+ /** Turns attached files into attachment keys before the comment is saved or sent. */
76
76
  upload: {
77
77
  type: PropType<CommentUpload>;
78
78
  };
79
+ /** Save raw files with outbox entries. Set only when the server accepts file uploads. `upload` takes precedence. */
80
+ queueFiles: {
81
+ default: boolean;
82
+ type: BooleanConstructor;
83
+ };
79
84
  /** The file types that the boxes take, such as `image/*`. */
80
85
  accept: {
81
86
  type: StringConstructor;
@@ -148,10 +153,15 @@ declare const CommentPanel: import("vue").DefineComponent<import("vue").ExtractP
148
153
  default: boolean;
149
154
  type: BooleanConstructor;
150
155
  };
151
- /** Turns attached files into attachment keys. Without it the boxes take no files. */
156
+ /** Turns attached files into attachment keys before the comment is saved or sent. */
152
157
  upload: {
153
158
  type: PropType<CommentUpload>;
154
159
  };
160
+ /** Save raw files with outbox entries. Set only when the server accepts file uploads. `upload` takes precedence. */
161
+ queueFiles: {
162
+ default: boolean;
163
+ type: BooleanConstructor;
164
+ };
155
165
  /** The file types that the boxes take, such as `image/*`. */
156
166
  accept: {
157
167
  type: StringConstructor;
@@ -189,9 +199,10 @@ declare const CommentPanel: import("vue").DefineComponent<import("vue").ExtractP
189
199
  title: string;
190
200
  variant: CommentPanelVariant;
191
201
  people: CommentUser[];
192
- allowEmpty: boolean;
193
202
  readOnly: boolean;
203
+ queueFiles: boolean;
194
204
  thread: string | null;
205
+ allowEmpty: boolean;
195
206
  }, SlotsType<CommentPanelSlots>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
196
207
  //#endregion
197
208
  export { CommentPanelVariant as a, CommentUpload as c, CommentPanelSlots as i, CommentGroupSlotScope as n, CommentRowSlotScope as o, CommentPanel as r, CommentRowSlots as s, CommentGroup as t };
@@ -60,8 +60,8 @@ declare const CommentPin: import("vue").DefineComponent<import("vue").ExtractPro
60
60
  onHover?: ((...args: any[]) => any) | undefined;
61
61
  onLeave?: ((...args: any[]) => any) | undefined;
62
62
  }>, {
63
- active: boolean;
64
63
  status: CommentStatus;
64
+ active: boolean;
65
65
  draft: boolean;
66
66
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
67
67
  //#endregion
@@ -19,7 +19,7 @@ function rowSlotScope(thread) {
19
19
  function threadRow(thread, options = {}) {
20
20
  const replies = thread.messages.length - 1;
21
21
  return [
22
- h("span", { "data-slot": "comment-list-number" }, String(thread.n)),
22
+ h("span", { "data-slot": "comment-list-number" }, thread.n ? String(thread.n) : ""),
23
23
  h(AvatarStack, {
24
24
  "aria-hidden": "true",
25
25
  people: [writerPerson(thread)],
@@ -0,0 +1,42 @@
1
+ import { PropType, VNode } from "vue";
2
+ //#region src/components/comment-selection-bar.d.ts
3
+ /** The side of the selected text that the bar sits on. */
4
+ type CommentSelectionBarSide = "top" | "bottom";
5
+ /**
6
+ * The bar over selected text: Comment, and Suggest when the page takes suggested changes. It is the dark surface on a
7
+ * light page and its light twin on a dark one, so it stands out from the text. The page places it and listens for the
8
+ * keys. A press on the bar keeps the selection on the page.
9
+ */
10
+ declare const CommentSelectionBar: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
11
+ /** Show Suggest (E), for a page that takes suggested changes. */
12
+ suggest: {
13
+ default: boolean;
14
+ type: BooleanConstructor;
15
+ };
16
+ /** The side of the text that the bar is on. The bar grows from that side, and its tooltips open away from the text. */
17
+ side: {
18
+ default: string;
19
+ type: PropType<CommentSelectionBarSide>;
20
+ };
21
+ }>, () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
22
+ [key: string]: any;
23
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("comment" | "suggest")[], "comment" | "suggest", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
24
+ /** Show Suggest (E), for a page that takes suggested changes. */
25
+ suggest: {
26
+ default: boolean;
27
+ type: BooleanConstructor;
28
+ };
29
+ /** The side of the text that the bar is on. The bar grows from that side, and its tooltips open away from the text. */
30
+ side: {
31
+ default: string;
32
+ type: PropType<CommentSelectionBarSide>;
33
+ };
34
+ }>> & Readonly<{
35
+ onComment?: ((...args: any[]) => any) | undefined;
36
+ onSuggest?: ((...args: any[]) => any) | undefined;
37
+ }>, {
38
+ side: CommentSelectionBarSide;
39
+ suggest: boolean;
40
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
41
+ //#endregion
42
+ export { CommentSelectionBarSide as n, CommentSelectionBar as t };
@@ -1,7 +1,7 @@
1
- import { i as CommentComposerSlots, r as CommentComposerSize } from "./comment-composer-Cc8Jvu6u.js";
2
- import { t as CommentCan } from "./comments-Bx2WRsYy.js";
1
+ import { i as CommentComposerSlots, r as CommentComposerSize } from "./comment-composer-fINL5bxo.js";
2
+ import { t as CommentCan } from "./comments-D8hulVPy.js";
3
3
  import { PropType, SlotsType, VNode } from "vue";
4
- import { CommentMessage, CommentThread, CommentUser } from "@vite-hub/comments/client";
4
+ import { CommentDelivery, CommentMessage, CommentThread, CommentUser } from "@vite-hub/comments/client";
5
5
  //#region src/internal/comment-status.d.ts
6
6
  /** The messages written after the thread was resolved. Empty for an open thread. */
7
7
  declare function messagesSinceResolved(thread: Pick<CommentThread, "status" | "resolvedAt" | "messages">): CommentMessage[];
@@ -29,11 +29,28 @@ type CommentAttachmentUrl = (key: string) => string | CommentAttachmentLink | un
29
29
  interface CommentReplySlotScope {
30
30
  message: CommentMessage;
31
31
  }
32
+ /** The scope of the `status` slot: a message that the outbox holds, and what the reader can do with it. */
33
+ interface CommentStatusSlotScope {
34
+ message: CommentMessage;
35
+ /** `pending` while it waits or goes out, `failed` when the server refused it, with `error` saying why. */
36
+ delivery: CommentDelivery;
37
+ /** Sends it again now. Only available with edit permission. */
38
+ retry?: () => Promise<void>;
39
+ /** Throws it away. Only available with delete permission. `false` while it is on its way. */
40
+ dismiss?: () => Promise<boolean>;
41
+ /** Changes its text. Only available with edit permission. A refused one goes back in the queue. */
42
+ edit?: (body: string, mentions?: string[]) => Promise<boolean>;
43
+ }
32
44
  type CommentReplySlots = {
33
45
  /** The text of the message. Replaces the Markdown body with its mention chips. */
34
46
  body?: (scope: CommentReplySlotScope) => VNode[];
35
47
  /** The attachments of the message. Replaces the default thumbnails. */
36
48
  attachments?: (scope: CommentReplySlotScope) => VNode[];
49
+ /**
50
+ * Below a message that has not reached the server, such as "Waiting to send" or a refusal with Retry and Discard.
51
+ * Nothing shows without it. The message also gets `data-pending` or `data-failed`.
52
+ */
53
+ status?: (scope: CommentStatusSlotScope) => VNode[];
37
54
  };
38
55
  /** The scope of the `actions`, `anchor`, and `after` slots of `CommentThread`. */
39
56
  interface CommentThreadSlotScope {
@@ -356,13 +373,13 @@ declare const CommentThread$1: import("vue").DefineComponent<import("vue").Extra
356
373
  }>, {
357
374
  size: CommentComposerSize;
358
375
  people: CommentUser[];
359
- busy: boolean;
360
- attachments: boolean;
361
376
  readOnly: boolean;
362
377
  preview: boolean;
378
+ busy: boolean;
363
379
  detached: boolean;
380
+ attachments: boolean;
364
381
  navigation: "close" | "back";
365
382
  dismissible: boolean;
366
383
  }, SlotsType<CommentThreadSlots>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
367
384
  //#endregion
368
- export { CommentReplySlots as a, CommentThreadSlots as c, CommentReplySlotScope as i, messagesSinceResolved as l, CommentAttachmentUrl as n, CommentThread$1 as o, CommentReply as r, CommentThreadSlotScope as s, CommentAttachmentLink as t, repliedSinceResolved as u };
385
+ export { CommentReplySlots as a, CommentThreadSlotScope as c, repliedSinceResolved as d, CommentReplySlotScope as i, CommentThreadSlots as l, CommentAttachmentUrl as n, CommentStatusSlotScope as o, CommentReply as r, CommentThread$1 as s, CommentAttachmentLink as t, messagesSinceResolved as u };
@@ -3,6 +3,30 @@ import { i as hasDirtyComposer, n as injectComments, o as shakeDirtyComposers, t
3
3
  import { createCommentVisibility } from "./parts/headless/comment-visibility.js";
4
4
  import { computed, getCurrentInstance, isRef, onBeforeUnmount, onMounted, provide, reactive, ref, shallowRef, toRaw, toValue, watch } from "vue";
5
5
  import { createAnchor, resolveAnchor } from "@vite-hub/comments/client";
6
+ //#region src/internal/comment-selection.ts
7
+ function commentThreadKey(thread) {
8
+ return thread.requestId === void 0 ? thread.id : JSON.stringify([
9
+ thread.subject.kind,
10
+ thread.subject.id,
11
+ thread.author.id,
12
+ thread.requestId
13
+ ]);
14
+ }
15
+ function useSelectedComment(threads, id) {
16
+ const selection = computed((previous) => {
17
+ const selectedId = id.value;
18
+ const items = threads.value;
19
+ const direct = items.find((thread) => thread.id === selectedId);
20
+ const last = previous?.id === selectedId ? previous.thread : void 0;
21
+ const key = last?.requestId === void 0 ? void 0 : commentThreadKey(last);
22
+ return {
23
+ id: selectedId,
24
+ thread: direct ?? (key === void 0 ? void 0 : items.find((thread) => commentThreadKey(thread) === key))
25
+ };
26
+ });
27
+ return computed(() => selection.value.thread);
28
+ }
29
+ //#endregion
6
30
  //#region src/internal/comment-status.ts
7
31
  /** The messages written after the thread was resolved. Empty for an open thread. */
8
32
  function messagesSinceResolved(thread) {
@@ -15,6 +39,17 @@ function messagesSinceResolved(thread) {
15
39
  * resolved, and lists show it with the open threads until someone resolves it again.
16
40
  */
17
41
  const repliedSinceResolved = (thread) => messagesSinceResolved(thread).length > 0;
42
+ /** "Comment 3". A comment that waits in the outbox has no number yet. */
43
+ function commentTitle(thread) {
44
+ return thread.n ? `Comment ${thread.n}` : "Comment";
45
+ }
46
+ /** `data-pending` or `data-failed` for a thread, message, or row that the outbox holds. */
47
+ function deliveryAttributes(delivery) {
48
+ return {
49
+ "data-failed": delivery?.status === "failed" ? "true" : void 0,
50
+ "data-pending": delivery?.status === "pending" ? "true" : void 0
51
+ };
52
+ }
18
53
  //#endregion
19
54
  //#region src/headless/comments.ts
20
55
  /**
@@ -77,6 +112,7 @@ function useComments(options) {
77
112
  });
78
113
  const status = ref(client.status);
79
114
  const threads = shallowRef(client.threads);
115
+ const outboxEntries = shallowRef(client.outbox?.entries ?? []);
80
116
  const positions = shallowRef(/* @__PURE__ */ new Map());
81
117
  const draft = ref(null);
82
118
  const openId = ref(null);
@@ -109,7 +145,10 @@ function useComments(options) {
109
145
  resolved: scoped.filter((thread) => thread.status === "resolved").length
110
146
  };
111
147
  });
112
- const opened = computed(() => threads.value.find((thread) => thread.id === openId.value));
148
+ const opened = useSelectedComment(threads, openId);
149
+ watch(opened, (thread) => {
150
+ if (thread && thread.id !== openId.value) openId.value = thread.id;
151
+ }, { flush: "sync" });
113
152
  const visibility = isRef(options.visibility) ? options.visibility : ref(options.visibility ?? "all");
114
153
  const seen = createCommentVisibility({
115
154
  visibility: visibility.value,
@@ -228,10 +267,11 @@ function useComments(options) {
228
267
  };
229
268
  measure();
230
269
  }
231
- async function send() {
270
+ async function send(sendOptions = {}) {
232
271
  const current = draft.value;
233
272
  const body = current?.body.trim() ?? "";
234
- if (!current || current.busy || !body && current.attachments.length === 0) return void 0;
273
+ const files = sendOptions.files ?? [];
274
+ if (!current || current.busy || !body && current.attachments.length === 0 && files.length === 0) return void 0;
235
275
  const submittedBody = current.body;
236
276
  const mentions = [...current.mentions];
237
277
  const attachments = [...current.attachments];
@@ -243,7 +283,8 @@ function useComments(options) {
243
283
  anchor: toRaw(current.anchor),
244
284
  body,
245
285
  mentions,
246
- ...attachments.length > 0 ? { attachments } : {}
286
+ ...attachments.length > 0 ? { attachments } : {},
287
+ ...files.length > 0 ? { files } : {}
247
288
  });
248
289
  current.busy = false;
249
290
  flash(thread.id);
@@ -328,6 +369,7 @@ function useComments(options) {
328
369
  stops.push(client.onChange(() => {
329
370
  status.value = client.status;
330
371
  threads.value = client.threads;
372
+ outboxEntries.value = client.outbox?.entries ?? [];
331
373
  }));
332
374
  status.value = client.status;
333
375
  threads.value = client.threads;
@@ -459,6 +501,18 @@ function useComments(options) {
459
501
  filters,
460
502
  status,
461
503
  threads,
504
+ outbox: {
505
+ enabled: client.outbox !== void 0,
506
+ queued: computed(() => outboxEntries.value.filter((entry) => entry.status !== "failed")),
507
+ failures: computed(() => outboxEntries.value.filter((entry) => entry.status === "failed")),
508
+ delivery(threadId, messageId) {
509
+ const thread = threads.value.find((item) => item.id === threadId);
510
+ return messageId === void 0 ? thread?.delivery : thread?.messages.find((item) => item.id === messageId)?.delivery;
511
+ },
512
+ retry: async (id) => client.outbox?.retry(id),
513
+ dismiss: async (id) => await client.outbox?.dismiss(id) ?? false,
514
+ edit: async (id, body, mentions) => await client.outbox?.edit(id, body, mentions) ?? false
515
+ },
462
516
  pageThreads,
463
517
  listed,
464
518
  counts,
@@ -483,23 +537,25 @@ function useComments(options) {
483
537
  send,
484
538
  open,
485
539
  close,
486
- create: async ({ anchor = { kind: "page" }, attachments, body, mentions }) => {
540
+ create: async ({ anchor = { kind: "page" }, attachments, body, files, mentions }) => {
487
541
  const thread = await client.create({
488
542
  subject: subject.value,
489
543
  anchor,
490
544
  body,
491
545
  mentions,
492
- ...attachments?.length ? { attachments } : {}
546
+ ...attachments?.length ? { attachments } : {},
547
+ ...files?.length ? { files } : {}
493
548
  });
494
549
  flash(thread.id);
495
550
  return thread;
496
551
  },
497
- reply: async (threadId, body, mentions, attachments) => {
552
+ reply: async (threadId, body, mentions, attachments, files) => {
498
553
  const thread = await client.reply({
499
554
  threadId,
500
555
  body,
501
556
  mentions,
502
- ...attachments?.length ? { attachments } : {}
557
+ ...attachments?.length ? { attachments } : {},
558
+ ...files?.length ? { files } : {}
503
559
  });
504
560
  flash(threadId);
505
561
  return thread;
@@ -548,4 +604,4 @@ function useCommentsContext(state) {
548
604
  return found;
549
605
  }
550
606
  //#endregion
551
- export { useCommentsContext as a, useComments as i, draftPositionKey as n, messagesSinceResolved as o, provideComments as r, repliedSinceResolved as s, defaultCommentCan as t };
607
+ export { useCommentsContext as a, messagesSinceResolved as c, useSelectedComment as d, useComments as i, repliedSinceResolved as l, draftPositionKey as n, commentTitle as o, provideComments as r, deliveryAttributes as s, defaultCommentCan as t, commentThreadKey as u };
@@ -1,6 +1,6 @@
1
1
  import { t as CommentVisibility } from "./comment-visibility-DsVuVndP.js";
2
2
  import { ComputedRef, MaybeRefOrGetter, Ref, ShallowRef } from "vue";
3
- import { AnchorPoint, AnchorPosition, AnchorTarget, CommentAnchor, CommentMessage, CommentSubject, CommentThread, CommentUser, CommentsClient, CommentsClientStatus, CreateAnchorOptions } from "@vite-hub/comments/client";
3
+ import { AnchorPoint, AnchorPosition, AnchorTarget, CommentAnchor, CommentDelivery, CommentMessage, CommentSubject, CommentThread, CommentUser, CommentsClient, CommentsClientStatus, CommentsOutboxEntry, CreateAnchorOptions } from "@vite-hub/comments/client";
4
4
  //#region src/headless/comments.d.ts
5
5
  /**
6
6
  * Each switch shows one kind of thread. Resolved threads stay hidden until `resolved` is on. A resolved thread with a
@@ -74,6 +74,26 @@ interface UseCommentsOptions {
74
74
  /** How long a comment or reply that was just sent shows while comments are hidden. Default `2500`. */
75
75
  flashMs?: number;
76
76
  }
77
+ /**
78
+ * The comments and replies that the client's outbox saved and did not send yet. Without the `outbox` option of
79
+ * `createCommentsClient()`, it is empty and its actions do nothing.
80
+ */
81
+ interface CommentsOutboxState {
82
+ /** `true` when the client has an outbox. */
83
+ readonly enabled: boolean;
84
+ /** The entries that wait or go out now, in order. */
85
+ readonly queued: ComputedRef<readonly CommentsOutboxEntry[]>;
86
+ /** The entries that the server refused. */
87
+ readonly failures: ComputedRef<readonly CommentsOutboxEntry[]>;
88
+ /** Whether the thread, or one of its messages, is waiting or refused. `undefined` when the server has it. */
89
+ delivery: (threadId: string, messageId?: string) => CommentDelivery | undefined;
90
+ /** Sends the waiting comment or reply `id` now. Without `id`, the whole queue tries again, such as after a sign-in. */
91
+ retry: (id?: string) => Promise<void>;
92
+ /** Removes the waiting comment or reply. `false` while it is on its way. */
93
+ dismiss: (id: string) => Promise<boolean>;
94
+ /** Changes the text of the waiting comment or reply. A refused one goes back in the queue. `false` while it is on its way. */
95
+ edit: (id: string, body: string, mentions?: string[]) => Promise<boolean>;
96
+ }
77
97
  interface CommentsState {
78
98
  readonly client: CommentsClient;
79
99
  readonly subject: ComputedRef<CommentSubject>;
@@ -87,8 +107,9 @@ interface CommentsState {
87
107
  readonly scope: Ref<CommentScope>;
88
108
  readonly filters: CommentFilterState;
89
109
  readonly status: Ref<CommentsClientStatus>;
90
- /** Every thread that the client holds. */
110
+ /** Every thread that the client holds, with the ones that wait in the outbox. */
91
111
  readonly threads: ShallowRef<readonly CommentThread[]>;
112
+ readonly outbox: CommentsOutboxState;
92
113
  /** The threads of this page that pass the filters. They get pins. */
93
114
  readonly pageThreads: ComputedRef<CommentThread[]>;
94
115
  /** The threads that pass the filters, for the page or the whole site as `scope` says. The list shows them. */
@@ -131,8 +152,14 @@ interface CommentsState {
131
152
  files?: File[];
132
153
  }) => void;
133
154
  cancelDraft: () => void;
134
- /** Sends the draft. Resolves with the new thread, or `undefined` when there is nothing to send or the send failed. */
135
- send: () => Promise<CommentThread | undefined>;
155
+ /**
156
+ * Sends the draft. Resolves with the new thread, or `undefined` when there is nothing to send or the send failed. With
157
+ * an outbox it resolves, and the draft closes, once the comment is saved, before the server answers. `files` go with
158
+ * the comment, for a client with an outbox.
159
+ */
160
+ send: (options?: {
161
+ files?: Blob[];
162
+ }) => Promise<CommentThread | undefined>;
136
163
  open: (thread: CommentThread | string, options?: {
137
164
  scroll?: boolean;
138
165
  }) => void;
@@ -143,9 +170,10 @@ interface CommentsState {
143
170
  body: string;
144
171
  mentions?: string[];
145
172
  attachments?: string[];
173
+ files?: Blob[];
146
174
  anchor?: CommentAnchor;
147
175
  }) => Promise<CommentThread>;
148
- reply: (threadId: string, body: string, mentions?: string[], attachments?: string[]) => Promise<CommentThread>;
176
+ reply: (threadId: string, body: string, mentions?: string[], attachments?: string[], files?: Blob[]) => Promise<CommentThread>;
149
177
  edit: (threadId: string, messageId: string, body: string, mentions?: string[]) => Promise<CommentThread>;
150
178
  remove: (threadId: string, messageId?: string) => Promise<CommentThread | null>;
151
179
  resolve: (threadId: string) => Promise<CommentThread>;
@@ -167,4 +195,4 @@ declare function provideComments(state: CommentsState): void;
167
195
  /** The state that a comment part uses: the one you pass, else the one of the nearest `CommentLayer` or `provideComments()`. Call it in `setup()`. */
168
196
  declare function useCommentsContext(state?: CommentsState): CommentsState;
169
197
  //#endregion
170
- export { CommentThreadAction as a, defaultCommentCan as c, useComments as d, useCommentsContext as f, CommentScope as i, draftPositionKey as l, CommentDraft as n, CommentsState as o, CommentFilterState as r, UseCommentsOptions as s, CommentCan as t, provideComments as u };
198
+ export { CommentThreadAction as a, UseCommentsOptions as c, provideComments as d, useComments as f, CommentScope as i, defaultCommentCan as l, CommentDraft as n, CommentsOutboxState as o, useCommentsContext as p, CommentFilterState as r, CommentsState as s, CommentCan as t, draftPositionKey as u };
@@ -0,0 +1,39 @@
1
+ //#region src/internal/format.ts
2
+ const milliseconds = new Intl.DurationFormat("en", {
3
+ style: "narrow",
4
+ millisecondsDisplay: "always"
5
+ });
6
+ const tenths = new Intl.DurationFormat("en", {
7
+ style: "narrow",
8
+ milliseconds: "numeric",
9
+ fractionalDigits: 1
10
+ });
11
+ const minutes = new Intl.DurationFormat("en", {
12
+ style: "narrow",
13
+ secondsDisplay: "always"
14
+ });
15
+ /** "320ms", "1.2s", "30s", or "1m 35s". Seconds round down, so a running counter never shows "60s". */
16
+ function formatDuration(ms) {
17
+ const whole = Math.round(ms);
18
+ if (whole < 1e3) return milliseconds.format({ milliseconds: whole });
19
+ const elapsed = Math.max(ms, 1e3);
20
+ const seconds = Math.floor(elapsed / 1e3);
21
+ if (seconds < 10) return tenths.format({
22
+ seconds,
23
+ milliseconds: Math.floor(elapsed % 1e3)
24
+ });
25
+ if (seconds < 60) return minutes.format({ seconds });
26
+ return minutes.format({
27
+ minutes: Math.floor(seconds / 60),
28
+ seconds: seconds % 60
29
+ });
30
+ }
31
+ /** Two letters for an avatar without an image: `Ana Lopez` and `ana.lopez@vitehub.dev` are `AL`, `Ana` is `AN`. */
32
+ function initials(name) {
33
+ const words = name.replace(/@.*/, "").trim().split(/[\s._-]+/).filter(Boolean);
34
+ const first = words[0] ?? "";
35
+ const second = words.length > 1 ? words.at(-1) ?? "" : first.slice(1);
36
+ return (first.slice(0, 1) + second.slice(0, 1)).toUpperCase() || "?";
37
+ }
38
+ //#endregion
39
+ export { initials as n, formatDuration as t };
@@ -1,5 +1,5 @@
1
1
  import { a as createCommentVisibility, i as commentLeaveMs, n as CommentVisibilityModel, r as CommentVisibilityOptions, t as CommentVisibility } from "./comment-visibility-DsVuVndP.js";
2
- import { a as CommentThreadAction, c as defaultCommentCan, d as useComments, f as useCommentsContext, i as CommentScope, l as draftPositionKey, n as CommentDraft, o as CommentsState, r as CommentFilterState, s as UseCommentsOptions, t as CommentCan, u as provideComments } from "./comments-Bx2WRsYy.js";
2
+ import { a as CommentThreadAction, c as UseCommentsOptions, d as provideComments, f as useComments, i as CommentScope, l as defaultCommentCan, n as CommentDraft, o as CommentsOutboxState, p as useCommentsContext, r as CommentFilterState, s as CommentsState, t as CommentCan, u as draftPositionKey } from "./comments-D8hulVPy.js";
3
3
  import { a as ChoicesInputSource, i as ChoicesInputField, n as ChoicesInputClear, o as ChoicesInputState, r as ChoicesInputError, s as ChoicesInputStatus, t as ChoicesInput } from "./choices-input-ByXJvDn1.js";
4
- import { a as MessageScrollerContent, c as MessageScrollerViewport, i as MessageScrollerButton, l as calculatePrependScrollTop, n as MessageScrollPosition, o as MessageScrollerContext, r as MessageScroller, s as MessageScrollerItem, t as MessageScrollBehavior, u as useMessageScroller } from "./message-scroller-Bm1YWTeY.js";
5
- export { ChoicesInput, ChoicesInputClear, ChoicesInputError, ChoicesInputField, ChoicesInputSource, ChoicesInputState, ChoicesInputStatus, CommentCan, CommentDraft, CommentFilterState, CommentScope, CommentThreadAction, CommentVisibility, CommentVisibilityModel, CommentVisibilityOptions, CommentsState, MessageScrollBehavior, MessageScrollPosition, MessageScroller, MessageScrollerButton, MessageScrollerContent, MessageScrollerContext, MessageScrollerItem, MessageScrollerViewport, UseCommentsOptions, calculatePrependScrollTop, commentLeaveMs, createCommentVisibility, defaultCommentCan, draftPositionKey, provideComments, useComments, useCommentsContext, useMessageScroller };
4
+ import { a as MessageScrollerContent, c as MessageScrollerViewport, i as MessageScrollerButton, l as calculatePrependScrollTop, n as MessageScrollPosition, o as MessageScrollerContext, r as MessageScroller, s as MessageScrollerItem, t as MessageScrollBehavior, u as useMessageScroller } from "./message-scroller-jrYN9dG9.js";
5
+ export { ChoicesInput, ChoicesInputClear, ChoicesInputError, ChoicesInputField, ChoicesInputSource, ChoicesInputState, ChoicesInputStatus, CommentCan, CommentDraft, CommentFilterState, CommentScope, CommentThreadAction, CommentVisibility, CommentVisibilityModel, CommentVisibilityOptions, CommentsOutboxState, CommentsState, MessageScrollBehavior, MessageScrollPosition, MessageScroller, MessageScrollerButton, MessageScrollerContent, MessageScrollerContext, MessageScrollerItem, MessageScrollerViewport, UseCommentsOptions, calculatePrependScrollTop, commentLeaveMs, createCommentVisibility, defaultCommentCan, draftPositionKey, provideComments, useComments, useCommentsContext, useMessageScroller };
package/dist/headless.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MessageScroller, MessageScrollerButton, MessageScrollerContent, MessageScrollerItem, MessageScrollerViewport, calculatePrependScrollTop, useMessageScroller } from "./parts/headless/message-scroller.js";
2
2
  import { commentLeaveMs, createCommentVisibility } from "./parts/headless/comment-visibility.js";
3
- import { a as useCommentsContext, i as useComments, n as draftPositionKey, r as provideComments, t as defaultCommentCan } from "./comments-CkWc2Khc.js";
3
+ import { a as useCommentsContext, i as useComments, n as draftPositionKey, r as provideComments, t as defaultCommentCan } from "./comments-D0d26ghV.js";
4
4
  import { ChoicesInput, ChoicesInputClear, ChoicesInputError, ChoicesInputField, ChoicesInputStatus } from "./parts/headless/choices-input.js";
5
5
  export { ChoicesInput, ChoicesInputClear, ChoicesInputError, ChoicesInputField, ChoicesInputStatus, MessageScroller, MessageScrollerButton, MessageScrollerContent, MessageScrollerItem, MessageScrollerViewport, calculatePrependScrollTop, commentLeaveMs, createCommentVisibility, defaultCommentCan, draftPositionKey, provideComments, useComments, useCommentsContext, useMessageScroller };