@dowel-ui/react 0.2.0 → 0.4.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 (141) hide show
  1. package/README.md +14 -7
  2. package/dist/components/ai-agent-plan/ai-agent-plan.d.ts +50 -0
  3. package/dist/components/ai-agent-plan/ai-agent-plan.d.ts.map +1 -0
  4. package/dist/components/ai-agent-plan/ai-agent-plan.js +156 -0
  5. package/dist/components/ai-agent-plan/ai-agent-plan.js.map +1 -0
  6. package/dist/components/ai-agent-plan/index.d.ts +2 -0
  7. package/dist/components/ai-agent-plan/index.js +2 -0
  8. package/dist/components/ai-agent-plan/meta.js +17 -0
  9. package/dist/components/ai-agent-plan/meta.js.map +1 -0
  10. package/dist/components/ai-agent-status/ai-agent-status.d.ts +1 -1
  11. package/dist/components/ai-approval-request/ai-approval-request.d.ts +67 -0
  12. package/dist/components/ai-approval-request/ai-approval-request.d.ts.map +1 -0
  13. package/dist/components/ai-approval-request/ai-approval-request.js +218 -0
  14. package/dist/components/ai-approval-request/ai-approval-request.js.map +1 -0
  15. package/dist/components/ai-approval-request/index.d.ts +2 -0
  16. package/dist/components/ai-approval-request/index.js +2 -0
  17. package/dist/components/ai-approval-request/meta.js +17 -0
  18. package/dist/components/ai-approval-request/meta.js.map +1 -0
  19. package/dist/components/ai-disclosure/ai-disclosure.d.ts +92 -0
  20. package/dist/components/ai-disclosure/ai-disclosure.d.ts.map +1 -0
  21. package/dist/components/ai-disclosure/ai-disclosure.js +122 -0
  22. package/dist/components/ai-disclosure/ai-disclosure.js.map +1 -0
  23. package/dist/components/ai-disclosure/index.d.ts +2 -0
  24. package/dist/components/ai-disclosure/index.js +2 -0
  25. package/dist/components/ai-disclosure/meta.js +17 -0
  26. package/dist/components/ai-disclosure/meta.js.map +1 -0
  27. package/dist/components/ai-response/ai-response.d.ts.map +1 -1
  28. package/dist/components/ai-response/ai-response.js +1 -0
  29. package/dist/components/ai-response/ai-response.js.map +1 -1
  30. package/dist/components/ai-structured-output/ai-structured-output.d.ts.map +1 -1
  31. package/dist/components/ai-structured-output/ai-structured-output.js +13 -2
  32. package/dist/components/ai-structured-output/ai-structured-output.js.map +1 -1
  33. package/dist/components/ai-tool/ai-tool.d.ts +1 -1
  34. package/dist/components/alert/alert.d.ts +1 -1
  35. package/dist/components/avatar/avatar.d.ts +1 -1
  36. package/dist/components/badge/badge.d.ts +1 -1
  37. package/dist/components/button/button.d.ts +1 -1
  38. package/dist/components/date-picker/date-picker.js +1 -1
  39. package/dist/components/diff-viewer/diff-model.d.ts +69 -0
  40. package/dist/components/diff-viewer/diff-model.d.ts.map +1 -0
  41. package/dist/components/diff-viewer/diff-model.js +180 -0
  42. package/dist/components/diff-viewer/diff-model.js.map +1 -0
  43. package/dist/components/diff-viewer/diff-viewer.d.ts +42 -0
  44. package/dist/components/diff-viewer/diff-viewer.d.ts.map +1 -0
  45. package/dist/components/diff-viewer/diff-viewer.js +212 -0
  46. package/dist/components/diff-viewer/diff-viewer.js.map +1 -0
  47. package/dist/components/diff-viewer/index.d.ts +3 -0
  48. package/dist/components/diff-viewer/index.js +3 -0
  49. package/dist/components/diff-viewer/meta.js +17 -0
  50. package/dist/components/diff-viewer/meta.js.map +1 -0
  51. package/dist/components/file-upload/file-upload.d.ts +46 -0
  52. package/dist/components/file-upload/file-upload.d.ts.map +1 -0
  53. package/dist/components/file-upload/file-upload.js +204 -0
  54. package/dist/components/file-upload/file-upload.js.map +1 -0
  55. package/dist/components/file-upload/index.d.ts +3 -0
  56. package/dist/components/file-upload/index.js +3 -0
  57. package/dist/components/file-upload/meta.js +17 -0
  58. package/dist/components/file-upload/meta.js.map +1 -0
  59. package/dist/components/file-upload/upload-queue.d.ts +87 -0
  60. package/dist/components/file-upload/upload-queue.d.ts.map +1 -0
  61. package/dist/components/file-upload/upload-queue.js +249 -0
  62. package/dist/components/file-upload/upload-queue.js.map +1 -0
  63. package/dist/components/log-viewer/index.d.ts +3 -0
  64. package/dist/components/log-viewer/index.js +3 -0
  65. package/dist/components/log-viewer/log-stream.d.ts +68 -0
  66. package/dist/components/log-viewer/log-stream.d.ts.map +1 -0
  67. package/dist/components/log-viewer/log-stream.js +120 -0
  68. package/dist/components/log-viewer/log-stream.js.map +1 -0
  69. package/dist/components/log-viewer/log-viewer.d.ts +51 -0
  70. package/dist/components/log-viewer/log-viewer.d.ts.map +1 -0
  71. package/dist/components/log-viewer/log-viewer.js +284 -0
  72. package/dist/components/log-viewer/log-viewer.js.map +1 -0
  73. package/dist/components/log-viewer/meta.js +17 -0
  74. package/dist/components/log-viewer/meta.js.map +1 -0
  75. package/dist/components/progress/progress.d.ts +1 -1
  76. package/dist/components/progress/progress.js +1 -0
  77. package/dist/components/progress/progress.js.map +1 -1
  78. package/dist/components/spinner/spinner.d.ts +1 -1
  79. package/dist/components/spinner/spinner.js +1 -0
  80. package/dist/components/spinner/spinner.js.map +1 -1
  81. package/dist/components/tags-input/index.d.ts +2 -0
  82. package/dist/components/tags-input/index.js +2 -0
  83. package/dist/components/tags-input/meta.js +17 -0
  84. package/dist/components/tags-input/meta.js.map +1 -0
  85. package/dist/components/tags-input/tags-input.d.ts +47 -0
  86. package/dist/components/tags-input/tags-input.d.ts.map +1 -0
  87. package/dist/components/tags-input/tags-input.js +182 -0
  88. package/dist/components/tags-input/tags-input.js.map +1 -0
  89. package/dist/components/time-range-picker/index.d.ts +3 -0
  90. package/dist/components/time-range-picker/index.js +3 -0
  91. package/dist/components/time-range-picker/meta.js +22 -0
  92. package/dist/components/time-range-picker/meta.js.map +1 -0
  93. package/dist/components/time-range-picker/time-expression.d.ts +88 -0
  94. package/dist/components/time-range-picker/time-expression.d.ts.map +1 -0
  95. package/dist/components/time-range-picker/time-expression.js +335 -0
  96. package/dist/components/time-range-picker/time-expression.js.map +1 -0
  97. package/dist/components/time-range-picker/time-range-picker.d.ts +65 -0
  98. package/dist/components/time-range-picker/time-range-picker.d.ts.map +1 -0
  99. package/dist/components/time-range-picker/time-range-picker.js +377 -0
  100. package/dist/components/time-range-picker/time-range-picker.js.map +1 -0
  101. package/dist/components/toast/toast.d.ts +1 -1
  102. package/dist/index.d.ts +21 -1
  103. package/dist/index.js +14 -2
  104. package/dist/registry/components.d.ts.map +1 -1
  105. package/dist/registry/components.js +66 -50
  106. package/dist/registry/components.js.map +1 -1
  107. package/package.json +6 -4
  108. package/src/components/ai-agent-plan/ai-agent-plan.tsx +0 -0
  109. package/src/components/ai-agent-plan/index.ts +10 -0
  110. package/src/components/ai-agent-plan/meta.ts +19 -0
  111. package/src/components/ai-approval-request/ai-approval-request.tsx +368 -0
  112. package/src/components/ai-approval-request/index.ts +7 -0
  113. package/src/components/ai-approval-request/meta.ts +21 -0
  114. package/src/components/ai-disclosure/ai-disclosure.tsx +244 -0
  115. package/src/components/ai-disclosure/index.ts +9 -0
  116. package/src/components/ai-disclosure/meta.ts +23 -0
  117. package/src/components/ai-response/ai-response.tsx +1 -0
  118. package/src/components/ai-structured-output/ai-structured-output.tsx +25 -1
  119. package/src/components/diff-viewer/diff-model.ts +256 -0
  120. package/src/components/diff-viewer/diff-viewer.tsx +339 -0
  121. package/src/components/diff-viewer/index.ts +17 -0
  122. package/src/components/diff-viewer/meta.ts +20 -0
  123. package/src/components/file-upload/file-upload.tsx +322 -0
  124. package/src/components/file-upload/index.ts +20 -0
  125. package/src/components/file-upload/meta.ts +21 -0
  126. package/src/components/file-upload/upload-queue.ts +337 -0
  127. package/src/components/log-viewer/index.ts +21 -0
  128. package/src/components/log-viewer/log-stream.ts +176 -0
  129. package/src/components/log-viewer/log-viewer.tsx +424 -0
  130. package/src/components/log-viewer/meta.ts +21 -0
  131. package/src/components/progress/progress.tsx +3 -0
  132. package/src/components/spinner/spinner.tsx +5 -0
  133. package/src/components/tags-input/index.ts +1 -0
  134. package/src/components/tags-input/meta.ts +23 -0
  135. package/src/components/tags-input/tags-input.tsx +300 -0
  136. package/src/components/time-range-picker/index.ts +25 -0
  137. package/src/components/time-range-picker/meta.ts +22 -0
  138. package/src/components/time-range-picker/time-expression.ts +491 -0
  139. package/src/components/time-range-picker/time-range-picker.tsx +522 -0
  140. package/src/index.ts +8 -0
  141. package/src/registry/components.ts +16 -0
@@ -0,0 +1,300 @@
1
+ "use client";
2
+
3
+ import {
4
+ useId,
5
+ useRef,
6
+ useState,
7
+ type ClipboardEvent,
8
+ type ComponentPropsWithRef,
9
+ type KeyboardEvent,
10
+ } from "react";
11
+
12
+ import { disabledStyles, focusRing } from "@/lib/styles";
13
+ import { cn } from "@/lib/utils";
14
+
15
+ /**
16
+ * A field whose value is a list of short strings: invited emails, allowed
17
+ * domains, labels, stop sequences.
18
+ *
19
+ * The behaviour that makes this worth shipping is what happens to input that
20
+ * fails validation. Every implementation surveyed either refuses to create the
21
+ * token, or creates it and silently throws it away — and both leave the reader
22
+ * staring at a field that did not do what they asked, with nothing to correct.
23
+ * Here an invalid entry becomes a token like any other, marked invalid and
24
+ * carrying its reason, so it can be seen, read out, and fixed by removing it.
25
+ * `value` holds every token including the invalid ones; the consumer runs the
26
+ * same `validate` to decide whether the field is submittable.
27
+ *
28
+ * Deliberately no suggestion list. A token field with an anchored listbox is a
29
+ * multi-select combobox, and this library already has 544 lines of hand-rolled
30
+ * combobox ARIA. A second copy of that would be the expensive kind of
31
+ * duplication — the kind that drifts. When multi-select is wanted, it belongs in
32
+ * Combobox.
33
+ */
34
+
35
+ /** Returns `true` for a valid tag, or a reason it is not. */
36
+ export type TagValidator = (tag: string, existing: string[]) => true | string;
37
+
38
+ export interface TagsInputProps extends Omit<
39
+ ComponentPropsWithRef<"div">,
40
+ "onChange" | "children"
41
+ > {
42
+ value: string[];
43
+ onValueChange: (tags: string[]) => void;
44
+ /** Names the field. Required — an unlabelled list of tokens is unreadable. */
45
+ label: string;
46
+ /** Characters that commit the token being typed, besides Enter. */
47
+ delimiters?: string[];
48
+ /**
49
+ * Decides whether a tag is acceptable. An invalid tag is still added, marked,
50
+ * and given its reason, rather than being refused or dropped.
51
+ */
52
+ validate?: TagValidator;
53
+ /** Rejects a tag already present. Rejections are announced, never silent. */
54
+ allowDuplicates?: boolean;
55
+ /** Refuses further tags once reached, and says so. */
56
+ max?: number;
57
+ placeholder?: string;
58
+ disabled?: boolean;
59
+ inputProps?: Omit<ComponentPropsWithRef<"input">, "value" | "onChange" | "disabled">;
60
+ }
61
+
62
+ /** Splits pasted or typed text on any delimiter, dropping empty fragments. */
63
+ function splitOn(text: string, delimiters: string[]): string[] {
64
+ if (delimiters.length === 0) return [text];
65
+ const pattern = new RegExp(`[${delimiters.map((d) => `\\${d}`).join("")}]`);
66
+ return text
67
+ .split(pattern)
68
+ .map((part) => part.trim())
69
+ .filter((part) => part.length > 0);
70
+ }
71
+
72
+ export function TagsInput({
73
+ className,
74
+ value,
75
+ onValueChange,
76
+ label,
77
+ delimiters = [",", ";"],
78
+ validate,
79
+ allowDuplicates = false,
80
+ max,
81
+ placeholder,
82
+ disabled = false,
83
+ inputProps,
84
+ ...props
85
+ }: TagsInputProps) {
86
+ const [draft, setDraft] = useState("");
87
+ const [announcement, setAnnouncement] = useState("");
88
+ const inputRef = useRef<HTMLInputElement | null>(null);
89
+ const labelId = useId();
90
+ const inputId = useId();
91
+ const hintId = useId();
92
+
93
+ const atLimit = max !== undefined && value.length >= max;
94
+
95
+ function reasonFor(tag: string): string | null {
96
+ if (!validate) return null;
97
+ const result = validate(tag, value);
98
+ return result === true ? null : result;
99
+ }
100
+
101
+ /** Adds tags, reporting anything refused rather than dropping it in silence. */
102
+ function commit(candidates: string[]) {
103
+ const accepted: string[] = [];
104
+ const refused: string[] = [];
105
+
106
+ // Split defensively rather than trusting the caller. A draft can arrive
107
+ // holding a delimiter from autofill, an IME commit, or a programmatic set,
108
+ // and a token with a comma inside it is never what was meant.
109
+ for (const candidate of candidates.flatMap((part) => splitOn(part, delimiters))) {
110
+ const tag = candidate.trim();
111
+ if (tag.length === 0) continue;
112
+
113
+ if (!allowDuplicates && [...value, ...accepted].includes(tag)) {
114
+ refused.push(`${tag} is already added`);
115
+ continue;
116
+ }
117
+ if (max !== undefined && value.length + accepted.length >= max) {
118
+ refused.push(`${tag} not added, limit of ${String(max)} reached`);
119
+ continue;
120
+ }
121
+ // An invalid tag is still added. It is the reader's text and they need to
122
+ // see it to fix it; refusing silently is how these fields lose input.
123
+ accepted.push(tag);
124
+ }
125
+
126
+ if (accepted.length > 0) onValueChange([...value, ...accepted]);
127
+
128
+ const parts: string[] = [];
129
+ if (accepted.length > 0) {
130
+ const invalid = accepted.filter((tag) => reasonFor(tag) !== null);
131
+ parts.push(`Added ${accepted.join(", ")}`);
132
+ if (invalid.length > 0) parts.push(`${String(invalid.length)} need attention`);
133
+ }
134
+ parts.push(...refused);
135
+ setAnnouncement(parts.join(". "));
136
+ }
137
+
138
+ function removeAt(index: number) {
139
+ const removed = value[index];
140
+ onValueChange(value.filter((_, position) => position !== index));
141
+ setAnnouncement(removed === undefined ? "" : `Removed ${removed}`);
142
+ inputRef.current?.focus();
143
+ }
144
+
145
+ function handleKeyDown(event: KeyboardEvent<HTMLInputElement>) {
146
+ if (event.key === "Enter") {
147
+ // Never let a token commit submit the form as well.
148
+ event.preventDefault();
149
+ if (draft.trim().length > 0) {
150
+ commit([draft]);
151
+ setDraft("");
152
+ }
153
+ return;
154
+ }
155
+
156
+ if (delimiters.includes(event.key)) {
157
+ event.preventDefault();
158
+ if (draft.trim().length > 0) {
159
+ commit([draft]);
160
+ setDraft("");
161
+ }
162
+ return;
163
+ }
164
+
165
+ // Backspace on an empty field removes the last token — the expected
166
+ // shortcut, and the only way to correct without reaching for the mouse.
167
+ if (event.key === "Backspace" && draft.length === 0 && value.length > 0) {
168
+ event.preventDefault();
169
+ removeAt(value.length - 1);
170
+ }
171
+ }
172
+
173
+ function handlePaste(event: ClipboardEvent<HTMLInputElement>) {
174
+ const text = event.clipboardData.getData("text");
175
+ const parts = splitOn(text, delimiters);
176
+ // Only intercept a paste that actually contains several tags; a single
177
+ // value should behave like an ordinary paste and stay editable.
178
+ if (parts.length <= 1) return;
179
+
180
+ event.preventDefault();
181
+ commit(parts);
182
+ setDraft("");
183
+ }
184
+
185
+ return (
186
+ <div data-slot="tags-input" className={cn("flex flex-col gap-1.5", className)} {...props}>
187
+ <label id={labelId} htmlFor={inputId} className="w-fit text-sm font-medium">
188
+ {label}
189
+ </label>
190
+
191
+ {/* A group rather than a listbox: these are committed values, not options
192
+ being chosen from, and calling it a listbox would promise navigation
193
+ semantics that do not exist here. */}
194
+ <div
195
+ role="group"
196
+ aria-labelledby={labelId}
197
+ data-disabled={disabled || undefined}
198
+ className={cn(
199
+ "flex min-h-10 w-full flex-wrap items-center gap-1.5 rounded-md border border-input bg-background px-2 py-1.5",
200
+ "focus-within:ring-2 focus-within:ring-ring/55",
201
+ disabled && "pointer-events-none opacity-55",
202
+ )}
203
+ >
204
+ {value.length > 0 ? (
205
+ <ul className="contents">
206
+ {value.map((tag, index) => {
207
+ const reason = reasonFor(tag);
208
+ return (
209
+ <li
210
+ key={`${tag}-${String(index)}`}
211
+ data-slot="tags-input-tag"
212
+ data-invalid={reason !== null || undefined}
213
+ className={cn(
214
+ "inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-xs font-medium",
215
+ reason === null
216
+ ? "border-transparent bg-secondary text-secondary-foreground"
217
+ : "border-destructive/40 bg-destructive/10 text-destructive",
218
+ )}
219
+ >
220
+ {tag}
221
+ {/* The reason travels with the token, so it is announced when
222
+ the token is, rather than as a detached error elsewhere. */}
223
+ {reason === null ? null : (
224
+ <span className="sr-only">, invalid: {reason}</span>
225
+ )}
226
+ <button
227
+ type="button"
228
+ data-slot="tags-input-remove"
229
+ disabled={disabled}
230
+ aria-label={`Remove ${tag}`}
231
+ onClick={() => {
232
+ removeAt(index);
233
+ }}
234
+ className={cn(
235
+ "-mr-0.5 grid size-4 place-items-center rounded-full",
236
+ "transition-colors hover:bg-foreground/10",
237
+ focusRing,
238
+ disabledStyles,
239
+ )}
240
+ >
241
+ <svg viewBox="0 0 24 24" aria-hidden="true" className="size-2.5">
242
+ <path
243
+ d="M6 6l12 12M18 6L6 18"
244
+ stroke="currentColor"
245
+ strokeWidth="3"
246
+ strokeLinecap="round"
247
+ />
248
+ </svg>
249
+ </button>
250
+ </li>
251
+ );
252
+ })}
253
+ </ul>
254
+ ) : null}
255
+
256
+ <input
257
+ ref={inputRef}
258
+ type="text"
259
+ id={inputId}
260
+ data-slot="tags-input-field"
261
+ value={draft}
262
+ disabled={disabled}
263
+ placeholder={value.length === 0 ? placeholder : undefined}
264
+ aria-describedby={hintId}
265
+ onChange={(event) => {
266
+ setDraft(event.target.value);
267
+ }}
268
+ onKeyDown={handleKeyDown}
269
+ onPaste={handlePaste}
270
+ onBlur={() => {
271
+ // Committing on blur stops a typed-but-uncommitted value being lost
272
+ // when the reader tabs away thinking they are done.
273
+ if (draft.trim().length > 0) {
274
+ commit([draft]);
275
+ setDraft("");
276
+ }
277
+ }}
278
+ className={cn(
279
+ "min-w-24 flex-1 self-stretch bg-transparent text-sm outline-none",
280
+ "placeholder:text-muted-foreground",
281
+ )}
282
+ {...inputProps}
283
+ />
284
+ </div>
285
+
286
+ <span id={hintId} className="text-xs text-muted-foreground">
287
+ {atLimit
288
+ ? `Limit of ${String(max ?? 0)} reached`
289
+ : `Press Enter${delimiters.length > 0 ? ` or ${delimiters.join(" ")}` : ""} to add`}
290
+ </span>
291
+
292
+ {/* Additions, removals and refusals all land here. A refusal that is only
293
+ visible as "nothing happened" is the failure this component exists to
294
+ avoid. */}
295
+ <span aria-live="polite" className="sr-only">
296
+ {announcement}
297
+ </span>
298
+ </div>
299
+ );
300
+ }
@@ -0,0 +1,25 @@
1
+ export {
2
+ TimeRange,
3
+ TimeRangeCalendar,
4
+ TimeRangeContent,
5
+ TimeRangeExpression,
6
+ TimeRangePresets,
7
+ TimeRangeTrigger,
8
+ type TimeRangeContentProps,
9
+ type TimeRangeProps,
10
+ type TimeRangeTriggerProps,
11
+ } from "./time-range-picker";
12
+ export {
13
+ DEFAULT_PRESETS,
14
+ TimeExpressionError,
15
+ absoluteExpression,
16
+ describeTimeRange,
17
+ formatResolvedRange,
18
+ isValidTimeRange,
19
+ resolveExpression,
20
+ resolveTimeRange,
21
+ type ResolveOptions,
22
+ type ResolvedRange,
23
+ type TimeRangePreset,
24
+ type TimeUnit,
25
+ } from "./time-expression";
@@ -0,0 +1,22 @@
1
+ import { defineMeta } from "@/registry/schema";
2
+
3
+ export const meta = defineMeta({
4
+ name: "time-range-picker",
5
+ title: "Time Range Picker",
6
+ description:
7
+ "A time range whose value is an expression, so it stays relative across a reload.",
8
+ category: "form",
9
+ status: "stable",
10
+ dependencies: ["react-day-picker"],
11
+ registryDependencies: ["button", "calendar", "input", "popover"],
12
+ files: ["time-expression.ts", "time-range-picker.tsx"],
13
+ a11y:
14
+ 'The trigger is named by the range it holds — "Last 6 hours" — and the window that ' +
15
+ "resolves to is read after it, so the relative choice is not replaced by two timestamps. " +
16
+ 'The popover carries role="dialog" and is named. Presets are buttons rather than radios ' +
17
+ "because choosing one both selects and dismisses, with aria-pressed carrying which matches " +
18
+ "the current expression. The expression field reports why an unparseable entry is invalid " +
19
+ "through one aria-describedby element that the preview and the error share, so a reader " +
20
+ "hears the error replace the preview rather than both at once; an invalid expression is " +
21
+ "never applied, because a chart silently re-scoping itself is worse than one that refuses.",
22
+ });