cursedbelt 5.92.3 → 5.94.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.
- package/dist/react/components/ComboboxField.d.ts +10 -0
- package/dist/react/components/ComboboxField.d.ts.map +1 -1
- package/dist/react/components/ComboboxField.js +4 -4
- package/dist/react/components/ComboboxField.js.map +1 -1
- package/dist/react/components/CommentThread.d.ts +9 -3
- package/dist/react/components/CommentThread.d.ts.map +1 -1
- package/dist/react/components/CommentThread.js +25 -11
- package/dist/react/components/CommentThread.js.map +1 -1
- package/dist/react/components/VoiceNote.d.ts +20 -0
- package/dist/react/components/VoiceNote.d.ts.map +1 -0
- package/dist/react/components/VoiceNote.js +54 -0
- package/dist/react/components/VoiceNote.js.map +1 -0
- package/dist/react/components/VoiceRecorder.d.ts +35 -0
- package/dist/react/components/VoiceRecorder.d.ts.map +1 -0
- package/dist/react/components/VoiceRecorder.js +155 -0
- package/dist/react/components/VoiceRecorder.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/map-frame/MapFrame.d.ts +219 -0
- package/dist/react/map-frame/MapFrame.d.ts.map +1 -0
- package/dist/react/map-frame/MapFrame.js +726 -0
- package/dist/react/map-frame/MapFrame.js.map +1 -0
- package/dist/react/map-frame/geo.d.ts +210 -0
- package/dist/react/map-frame/geo.d.ts.map +1 -0
- package/dist/react/map-frame/geo.js +345 -0
- package/dist/react/map-frame/geo.js.map +1 -0
- package/dist/react/map-frame/index.d.ts +5 -0
- package/dist/react/map-frame/index.d.ts.map +1 -0
- package/dist/react/map-frame/index.js +3 -0
- package/dist/react/map-frame/index.js.map +1 -0
- package/dist/styles-areas/canvas-hud.css +5 -5
- package/dist/styles-areas/workbench.css +17 -17
- package/package.json +13 -1
- package/scripts/guardrails-baseline.json +1 -1
- package/scripts/styleAreas.ts +1 -1
- package/src/react/components/ComboboxField.spec.tsx +39 -0
- package/src/react/components/ComboboxField.tsx +20 -4
- package/src/react/components/CommentThread.spec.tsx +25 -0
- package/src/react/components/CommentThread.tsx +60 -10
- package/src/react/components/VoiceNote.tsx +92 -0
- package/src/react/components/VoiceRecorder.spec.tsx +116 -0
- package/src/react/components/VoiceRecorder.tsx +224 -0
- package/src/react/index.ts +9 -0
- package/src/react/map-frame/MapFrame.spec.ts +168 -0
- package/src/react/map-frame/MapFrame.tsx +954 -0
- package/src/react/map-frame/geo.spec.ts +393 -0
- package/src/react/map-frame/geo.ts +421 -0
- package/src/react/map-frame/index.ts +34 -0
- package/src/react/media/HoverScrubVideoThumb.spec.tsx +4 -0
- package/src/styles-areas/canvas-hud.css +5 -5
- package/src/styles-areas/workbench.css +17 -17
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* cursedbelt — the `canvas-hud` area's utility candidates. GENERATED BUILD ARTIFACT. Never hand-edit.
|
|
3
3
|
*
|
|
4
|
-
* the pan-and-zoom canvas HUD — zoom keys, minimap, find pill, node menu.
|
|
4
|
+
* the pan-and-zoom canvas HUD — zoom keys, minimap, find pill, node menu — and the map frame, which draws with inline styles and adds no utility.
|
|
5
5
|
*
|
|
6
6
|
* Every Tailwind utility the modules in this area's import closure use, MINUS the
|
|
7
7
|
* ones `styles-areas/core.css` already ships. 🔴 Import ALL of these, in
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* after an app's responsive variant (task 2124). An app that imports every area gets exactly
|
|
19
19
|
* what `cursedbelt/styles-utilities.css` emits — proved rule by rule in
|
|
20
20
|
* src/stylesAreas.spec.ts, which is also what fails when this file is stale.
|
|
21
|
-
*
|
|
21
|
+
* 42 candidate(s).
|
|
22
22
|
*
|
|
23
23
|
* Written by scripts/generateAreaStyles.ts (`bun run styles:areas`), which
|
|
24
24
|
* `bun run build` runs. The map of what is in which area, and why the areas are
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
@source inline("[&::-webkit-scrollbar]:hidden [&::-webkit-search-cancel-button]:hidden [&_select]:w-full");
|
|
29
29
|
@source inline("[scrollbar-width:none] aria-pressed:bg-muted aria-pressed:text-foreground basis-0 basis-full");
|
|
30
30
|
@source inline("bg-background/40 bg-background/70 bottom-3 bottom-4 focus-visible:border-transparent");
|
|
31
|
-
@source inline("focus-visible:ring-0 left-3 max-w-48 min-w-10 min-w-26 min-w-40 ml-2 opacity-100 order-1
|
|
32
|
-
@source inline("order-3 overflow-visible pb-1.5 pl-0 pl-1 place-items-center pt-1 px-0.5 right-3 right-4
|
|
33
|
-
@source inline("w-64 z-[5000]");
|
|
31
|
+
@source inline("focus-visible:ring-0 left-3 max-w-48 mi min-w-10 min-w-26 min-w-40 ml-2 opacity-100 order-1");
|
|
32
|
+
@source inline("order-2 order-3 overflow-visible pb-1.5 pl-0 pl-1 place-items-center pt-1 px-0.5 right-3 right-4");
|
|
33
|
+
@source inline("w-40 w-64 z-[5000]");
|
|
@@ -18,27 +18,27 @@
|
|
|
18
18
|
* after an app's responsive variant (task 2124). An app that imports every area gets exactly
|
|
19
19
|
* what `cursedbelt/styles-utilities.css` emits — proved rule by rule in
|
|
20
20
|
* src/stylesAreas.spec.ts, which is also what fails when this file is stale.
|
|
21
|
-
*
|
|
21
|
+
* 102 candidate(s).
|
|
22
22
|
*
|
|
23
23
|
* Written by scripts/generateAreaStyles.ts (`bun run styles:areas`), which
|
|
24
24
|
* `bun run build` runs. The map of what is in which area, and why the areas are
|
|
25
25
|
* import closures rather than a hand-written list, is scripts/styleAreas.ts.
|
|
26
26
|
*/
|
|
27
|
-
@source inline("-my-0.5 [&::-webkit-scrollbar]:hidden [&_svg]:size-3.5 [scrollbar-width:none]
|
|
28
|
-
@source inline("
|
|
29
|
-
@source inline("bg-success/8 border-2 border-8 border-accent-solid
|
|
30
|
-
@source inline("border-border/50 border-dashed border-solid bottom-6");
|
|
27
|
+
@source inline("-my-0.5 [&::-webkit-scrollbar]:hidden [&_svg]:size-3.5 [scrollbar-width:none]");
|
|
28
|
+
@source inline("accent-[var(--accent-solid)] bg-accent/15 bg-accent/40 bg-accent/8 bg-background/85");
|
|
29
|
+
@source inline("bg-card-overlay/85 bg-muted/30 bg-muted/60 bg-success/8 border-2 border-8 border-accent-solid");
|
|
30
|
+
@source inline("border-accent/70 border-border-strong/60 border-border/50 border-dashed border-solid bottom-6");
|
|
31
31
|
@source inline("bottom-[max(env(safe-area-inset-bottom,0px),0.75rem)] disabled:opacity-0 duration-150 first:pt-1");
|
|
32
|
-
@source inline("flex-row group-hover:disabled:opacity-50 h-105 h-40 hover:bg-card-overlay");
|
|
32
|
+
@source inline("flex-row group-hover:disabled:opacity-50 h-105 h-3.5 h-40 hover:bg-card-overlay");
|
|
33
33
|
@source inline("hover:bg-muted-foreground/10 hover:bg-muted/80 hover:border-field-ring hover:shadow-popover");
|
|
34
|
-
@source inline("inset-x-3 italic items-stretch left-2.5 max-h-full min-h min-h-20 min-h-8 min-h-9
|
|
35
|
-
@source inline("min-h-full min-w-20 min-w-40 opacity-100 pb-0.5
|
|
36
|
-
@source inline("
|
|
37
|
-
@source inline("peer-focus:rounded-lg pl-1 pl-3
|
|
38
|
-
@source inline("pointer-coarse:w-12 pr-16 pr-9 pt-1.5
|
|
39
|
-
@source inline("ring-
|
|
40
|
-
@source inline("rounded-[var(--radius-device)] scale-[1.01] self-stretch
|
|
41
|
-
@source inline("sm:shrink-0 sm:w-56 text-muted-foreground/60
|
|
42
|
-
@source inline("text-tone-
|
|
43
|
-
@source inline("text-tone-
|
|
44
|
-
@source inline("translate-y-2 w-0 w-88");
|
|
34
|
+
@source inline("inset-x-3 italic items-stretch left-2.5 max-h-full max-w-80 min-h min-h-20 min-h-8 min-h-9");
|
|
35
|
+
@source inline("min-h-dvh min-h-full min-w-16 min-w-20 min-w-40 opacity-100 pb-0.5");
|
|
36
|
+
@source inline("pb-[max(env(safe-area-inset-bottom,0px),0.5rem)] peer-focus peer-focus:outline-none");
|
|
37
|
+
@source inline("peer-focus:ring-2 peer-focus:ring-field-ring/40 peer-focus:rounded-lg pl-1 pl-3");
|
|
38
|
+
@source inline("pointer-coarse:disabled:opacity-50 pointer-coarse:h-12 pointer-coarse:w-12 pr-16 pr-9 pt-1.5");
|
|
39
|
+
@source inline("resize-none right-4 ring-1 ring-4 ring-accent/20 ring-accent/30 ring-accent/40 ring-border");
|
|
40
|
+
@source inline("ring-inset ring-ring rounded-2xl rounded-[var(--radius-device)] scale-[1.01] self-stretch");
|
|
41
|
+
@source inline("shrink-[2] size-7 sm:flex-1 sm:min-w-40 sm:shrink-0 sm:w-56 text-muted-foreground/60");
|
|
42
|
+
@source inline("text-tone-amber-ink text-tone-cyan-ink text-tone-emerald-ink text-tone-orange-ink");
|
|
43
|
+
@source inline("text-tone-purple-ink text-tone-rose-ink text-tone-sky-ink text-tone-slate-ink text-xl");
|
|
44
|
+
@source inline("transition-[opacity,transform] translate-y-0 translate-y-2 w-0 w-88");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursedbelt",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.94.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "The React design system of the cursedbelt split — components, styles, theme. cursedbelt-core below it; server tier in cursedbelt-server.",
|
|
@@ -337,6 +337,18 @@
|
|
|
337
337
|
"source": "./src/react/markdown/MarkdownDoc.tsx",
|
|
338
338
|
"import": "./dist/react/markdown/MarkdownDoc.js"
|
|
339
339
|
},
|
|
340
|
+
"./react/map-frame": {
|
|
341
|
+
"types": "./dist/react/map-frame/index.d.ts",
|
|
342
|
+
"bun": "./src/react/map-frame/index.ts",
|
|
343
|
+
"source": "./src/react/map-frame/index.ts",
|
|
344
|
+
"import": "./dist/react/map-frame/index.js"
|
|
345
|
+
},
|
|
346
|
+
"./react/map-frame/geo": {
|
|
347
|
+
"types": "./dist/react/map-frame/geo.d.ts",
|
|
348
|
+
"bun": "./src/react/map-frame/geo.ts",
|
|
349
|
+
"source": "./src/react/map-frame/geo.ts",
|
|
350
|
+
"import": "./dist/react/map-frame/geo.js"
|
|
351
|
+
},
|
|
340
352
|
"./react/master-detail": {
|
|
341
353
|
"types": "./dist/react/master-detail/index.d.ts",
|
|
342
354
|
"bun": "./src/react/master-detail/index.ts",
|
package/scripts/styleAreas.ts
CHANGED
|
@@ -234,7 +234,7 @@ export const AREAS: readonly Area[] = [
|
|
|
234
234
|
roots: ['components/auth', 'AuthGate.tsx'],
|
|
235
235
|
},
|
|
236
236
|
{ name: 'calendar', why: 'the date-picker family: a calendar grid is a whole layout nothing else shares', roots: ['components/calendar'] },
|
|
237
|
-
{ name: 'canvas-hud', why: 'the pan-and-zoom canvas HUD — zoom keys, minimap, find pill, node menu', roots: ['canvas-hud'] },
|
|
237
|
+
{ name: 'canvas-hud', why: 'the pan-and-zoom canvas HUD — zoom keys, minimap, find pill, node menu — and the map frame, which draws with inline styles and adds no utility', roots: ['canvas-hud', 'map-frame'] },
|
|
238
238
|
{ name: 'charts', why: 'the recharts wrappers — an app with no dashboard renders none of them', roots: ['charts'] },
|
|
239
239
|
{
|
|
240
240
|
name: 'chart-table',
|
|
@@ -156,6 +156,45 @@ describe('ComboboxField (async)', () => {
|
|
|
156
156
|
});
|
|
157
157
|
});
|
|
158
158
|
|
|
159
|
+
describe('ComboboxField (empty)', () => {
|
|
160
|
+
// Forge task 3691: photos' tree picker searches the family tree by name and had to opt out
|
|
161
|
+
// of `choice-needs-empty-state`, because the belt's fixed line could not say what belongs.
|
|
162
|
+
const typeNobody = (container: HTMLElement) => {
|
|
163
|
+
act(() => {
|
|
164
|
+
fireEvent.click(container.querySelector('[aria-label="Toggle options"]') as HTMLElement);
|
|
165
|
+
});
|
|
166
|
+
act(() => {
|
|
167
|
+
fireEvent.input(container.querySelector('input') as HTMLInputElement, {
|
|
168
|
+
target: { value: 'Zebedee' },
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
test('🔴 a search that finds nothing says the caller\'s emptyLabel, not the generic line', async () => {
|
|
174
|
+
const { container, getByText, queryByText } = render(
|
|
175
|
+
<ComboboxField
|
|
176
|
+
options={OPTIONS}
|
|
177
|
+
emptyLabel='Nobody in the tree by that name'
|
|
178
|
+
value={null}
|
|
179
|
+
onChange={() => {}}
|
|
180
|
+
/>,
|
|
181
|
+
);
|
|
182
|
+
typeNobody(container);
|
|
183
|
+
await waitFor(() => expect(getByText('Nobody in the tree by that name')).not.toBeNull(), {
|
|
184
|
+
timeout: 1000,
|
|
185
|
+
});
|
|
186
|
+
expect(queryByText('No options found')).toBeNull();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('without one, the generic line stands in', async () => {
|
|
190
|
+
const { container, getByText } = render(
|
|
191
|
+
<ComboboxField options={OPTIONS} value={null} onChange={() => {}} />,
|
|
192
|
+
);
|
|
193
|
+
typeNobody(container);
|
|
194
|
+
await waitFor(() => expect(getByText('No options found')).not.toBeNull(), { timeout: 1000 });
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
159
198
|
describe('ComboboxField on a touch screen', () => {
|
|
160
199
|
// binary-server's design audit at 390 (forge task 2621): the multi-select's text input
|
|
161
200
|
// measured 190×36 — the group never took the coarse-pointer floor every other field control
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { Combobox } from '@base-ui/react/combobox';
|
|
4
4
|
import { Check, ChevronDown, Loader2, Plus, X } from 'lucide-react';
|
|
5
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { type ReactNode, useCallback, useEffect, useRef, useState } from 'react';
|
|
6
6
|
import { cn } from '../lib/cn.js';
|
|
7
7
|
import {
|
|
8
8
|
CONTROL_HEIGHT_CLASS,
|
|
@@ -32,6 +32,15 @@ interface ComboboxBase {
|
|
|
32
32
|
loadOptions?: (query: string) => Promise<ComboboxOption[]>;
|
|
33
33
|
/** Allow typing a value that isn't in the list and creating it on the fly. */
|
|
34
34
|
creatable?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* What the list says when nothing matches — *"Nobody in the tree by that name"*.
|
|
37
|
+
*
|
|
38
|
+
* 🔴 Required in practice for a combobox whose options come from DATA (`loadOptions`, or a
|
|
39
|
+
* list read from a store): the generic line cannot say what belongs here, and the
|
|
40
|
+
* `choice-needs-empty-state` guardrail reports one without it. Rendered as plain text, not
|
|
41
|
+
* as an item, so it can never be picked or keyboard-focused. Default "No options found".
|
|
42
|
+
*/
|
|
43
|
+
emptyLabel?: ReactNode;
|
|
35
44
|
placeholder?: string;
|
|
36
45
|
disabled?: boolean;
|
|
37
46
|
id?: string;
|
|
@@ -71,9 +80,10 @@ interface ListProps {
|
|
|
71
80
|
creatable: boolean;
|
|
72
81
|
query: string;
|
|
73
82
|
onCreateClick: (q: string) => void;
|
|
83
|
+
emptyLabel: ReactNode;
|
|
74
84
|
}
|
|
75
85
|
|
|
76
|
-
function ComboboxList({ creatable, query, onCreateClick }: ListProps) {
|
|
86
|
+
function ComboboxList({ creatable, query, onCreateClick, emptyLabel }: ListProps) {
|
|
77
87
|
const filtered = Combobox.useFilteredItems<ComboboxOption>();
|
|
78
88
|
const trimmed = query.trim();
|
|
79
89
|
const hasExact = filtered.some(
|
|
@@ -123,7 +133,7 @@ function ComboboxList({ creatable, query, onCreateClick }: ListProps) {
|
|
|
123
133
|
</Combobox.Item>
|
|
124
134
|
)}
|
|
125
135
|
<Combobox.Empty className='py-2 text-center text-sm text-muted-foreground'>
|
|
126
|
-
|
|
136
|
+
{emptyLabel}
|
|
127
137
|
</Combobox.Empty>
|
|
128
138
|
</Combobox.List>
|
|
129
139
|
);
|
|
@@ -148,6 +158,7 @@ export function ComboboxField(props: ComboboxFieldProps) {
|
|
|
148
158
|
options = [],
|
|
149
159
|
loadOptions,
|
|
150
160
|
creatable = false,
|
|
161
|
+
emptyLabel = 'No options found',
|
|
151
162
|
placeholder = 'Select…',
|
|
152
163
|
disabled,
|
|
153
164
|
id,
|
|
@@ -337,7 +348,12 @@ export function ComboboxField(props: ComboboxFieldProps) {
|
|
|
337
348
|
'data-[ending-style]:scale-95 data-[ending-style]:opacity-0',
|
|
338
349
|
)}
|
|
339
350
|
>
|
|
340
|
-
<ComboboxList
|
|
351
|
+
<ComboboxList
|
|
352
|
+
creatable={creatable}
|
|
353
|
+
query={query}
|
|
354
|
+
onCreateClick={handleCreate}
|
|
355
|
+
emptyLabel={emptyLabel}
|
|
356
|
+
/>
|
|
341
357
|
</Combobox.Popup>
|
|
342
358
|
</Combobox.Positioner>
|
|
343
359
|
</Combobox.Portal>
|
|
@@ -134,4 +134,29 @@ describe('CommentThread', () => {
|
|
|
134
134
|
fireEvent.click(replyBtn!);
|
|
135
135
|
expect(onPost).toHaveBeenCalledWith('My reply', 'p1');
|
|
136
136
|
});
|
|
137
|
+
|
|
138
|
+
test('a voice comment plays inline, and a voice-only one draws no empty text line', () => {
|
|
139
|
+
const { getByRole, container } = render(
|
|
140
|
+
<CommentThread comments={[makeComment({ body: '', audioUrl: 'https://media.test/c1.webm' })]} onPost={() => {}} />,
|
|
141
|
+
);
|
|
142
|
+
expect(getByRole('button', { name: 'Play voice comment by Alice' })).toBeTruthy();
|
|
143
|
+
expect(container.querySelector('audio')?.getAttribute('src')).toBe('https://media.test/c1.webm');
|
|
144
|
+
expect(container.querySelector('p.whitespace-pre-wrap')).toBeNull();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('a deleted voice comment plays nothing', () => {
|
|
148
|
+
const { queryByRole, getByText } = render(
|
|
149
|
+
<CommentThread comments={[makeComment({ deleted: true, audioUrl: 'https://media.test/c1.webm' })]} onPost={() => {}} />,
|
|
150
|
+
);
|
|
151
|
+
expect(getByText('deleted')).toBeTruthy();
|
|
152
|
+
expect(queryByRole('button', { name: /Play voice comment/ })).toBeNull();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('the record button appears only when the app takes voice comments', () => {
|
|
156
|
+
const without = render(<CommentThread comments={[]} onPost={() => {}} />);
|
|
157
|
+
expect(without.queryByRole('button', { name: 'Record a voice comment' })).toBeNull();
|
|
158
|
+
without.unmount();
|
|
159
|
+
const withVoice = render(<CommentThread comments={[]} onPost={() => {}} onPostVoice={() => {}} />);
|
|
160
|
+
expect(withVoice.getByRole('button', { name: 'Record a voice comment' })).toBeTruthy();
|
|
161
|
+
});
|
|
137
162
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Edit2, Send, Trash2 } from 'lucide-react';
|
|
1
|
+
import { Edit2, Mic, Send, Trash2 } from 'lucide-react';
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { cn } from '../lib/cn.js';
|
|
4
4
|
import { FIELD_CLASS } from '../lib/field.js';
|
|
@@ -9,6 +9,8 @@ import { Button } from './Button.js';
|
|
|
9
9
|
import { IconButton } from './IconButton.js';
|
|
10
10
|
import { ReactionBar, type ReactionGroup } from './ReactionBar.js';
|
|
11
11
|
import { Skeleton } from './Skeleton.js';
|
|
12
|
+
import { VoiceNote } from './VoiceNote.js';
|
|
13
|
+
import { type VoiceRecording, VoiceRecorder } from './VoiceRecorder.js';
|
|
12
14
|
|
|
13
15
|
// ── Types ─────────────────────────────────────────────────────────────────────
|
|
14
16
|
|
|
@@ -37,6 +39,8 @@ export interface CommentData {
|
|
|
37
39
|
/** Whether the current user may delete this comment. */
|
|
38
40
|
canDelete?: boolean;
|
|
39
41
|
reactions?: CommentReactionSummary;
|
|
42
|
+
/** A voice comment's audio, played inline above its (optional) text. */
|
|
43
|
+
audioUrl?: string | null;
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
export interface CommentThreadProps {
|
|
@@ -48,6 +52,8 @@ export interface CommentThreadProps {
|
|
|
48
52
|
onDelete?: (id: string) => void;
|
|
49
53
|
/** Toggle a reaction on a comment. */
|
|
50
54
|
onReact?: (commentId: string, emoji: string) => void;
|
|
55
|
+
/** Post a voice comment (parentId for a reply). When set, every composer grows a record button. */
|
|
56
|
+
onPostVoice?: (recording: VoiceRecording, parentId?: string) => void;
|
|
51
57
|
className?: string;
|
|
52
58
|
emptyMessage?: string;
|
|
53
59
|
/** Placeholder for the root-level composer. */
|
|
@@ -81,16 +87,19 @@ function formatRelative(target: Date, from = new Date()): string {
|
|
|
81
87
|
|
|
82
88
|
function Composer({
|
|
83
89
|
onSubmit,
|
|
90
|
+
onVoice,
|
|
84
91
|
placeholder,
|
|
85
92
|
autoFocus,
|
|
86
93
|
onCancel,
|
|
87
94
|
}: {
|
|
88
95
|
onSubmit: (body: string) => void;
|
|
96
|
+
onVoice?: (recording: VoiceRecording) => void;
|
|
89
97
|
placeholder: string;
|
|
90
98
|
autoFocus?: boolean;
|
|
91
99
|
onCancel?: () => void;
|
|
92
100
|
}) {
|
|
93
101
|
const [body, setBody] = useState('');
|
|
102
|
+
const [recording, setRecording] = useState(false);
|
|
94
103
|
const submit = () => {
|
|
95
104
|
const trimmed = body.trim();
|
|
96
105
|
if (!trimmed) return;
|
|
@@ -98,6 +107,18 @@ function Composer({
|
|
|
98
107
|
setBody('');
|
|
99
108
|
};
|
|
100
109
|
|
|
110
|
+
if (recording && onVoice) {
|
|
111
|
+
return (
|
|
112
|
+
<VoiceRecorder
|
|
113
|
+
onCancel={() => setRecording(false)}
|
|
114
|
+
onDone={(r) => {
|
|
115
|
+
setRecording(false);
|
|
116
|
+
onVoice(r);
|
|
117
|
+
}}
|
|
118
|
+
/>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
101
122
|
return (
|
|
102
123
|
<div className='flex items-end gap-2'>
|
|
103
124
|
<AutoGrowTextarea
|
|
@@ -114,6 +135,11 @@ function Composer({
|
|
|
114
135
|
// floor on a coarse pointer (DESIGN.md LAY-13).
|
|
115
136
|
className={cn(FIELD_CLASS, 'min-h-9 flex-1', TAP_TARGET_HEIGHT)}
|
|
116
137
|
/>
|
|
138
|
+
{onVoice && (
|
|
139
|
+
<IconButton label='Record a voice comment' variant='secondary' onClick={() => setRecording(true)}>
|
|
140
|
+
<Mic />
|
|
141
|
+
</IconButton>
|
|
142
|
+
)}
|
|
117
143
|
<Button
|
|
118
144
|
variant='primary'
|
|
119
145
|
size='sm'
|
|
@@ -159,6 +185,7 @@ function CommentItem({
|
|
|
159
185
|
onEdit,
|
|
160
186
|
onDelete,
|
|
161
187
|
onReact,
|
|
188
|
+
onPostVoice,
|
|
162
189
|
}: {
|
|
163
190
|
comment: CommentData;
|
|
164
191
|
replies: CommentData[];
|
|
@@ -166,6 +193,7 @@ function CommentItem({
|
|
|
166
193
|
onEdit?: (id: string, body: string) => void;
|
|
167
194
|
onDelete?: (id: string) => void;
|
|
168
195
|
onReact?: (commentId: string, emoji: string) => void;
|
|
196
|
+
onPostVoice?: (recording: VoiceRecording, parentId?: string) => void;
|
|
169
197
|
}) {
|
|
170
198
|
const [replying, setReplying] = useState(false);
|
|
171
199
|
const [editing, setEditing] = useState(false);
|
|
@@ -221,14 +249,21 @@ function CommentItem({
|
|
|
221
249
|
Cancel
|
|
222
250
|
</Button>
|
|
223
251
|
</div>
|
|
252
|
+
) : comment.deleted ? (
|
|
253
|
+
<p className='mt-0.5 text-sm italic text-muted-foreground'>deleted</p>
|
|
224
254
|
) : (
|
|
225
|
-
|
|
226
|
-
{comment.
|
|
227
|
-
<
|
|
228
|
-
|
|
229
|
-
|
|
255
|
+
<>
|
|
256
|
+
{comment.audioUrl && (
|
|
257
|
+
<VoiceNote
|
|
258
|
+
src={comment.audioUrl}
|
|
259
|
+
label={`Play voice comment by ${comment.author.name || 'someone'}`}
|
|
260
|
+
className='mt-1 max-w-80'
|
|
261
|
+
/>
|
|
262
|
+
)}
|
|
263
|
+
{comment.body && (
|
|
264
|
+
<p className='mt-0.5 whitespace-pre-wrap break-words text-sm text-foreground'>{comment.body}</p>
|
|
230
265
|
)}
|
|
231
|
-
|
|
266
|
+
</>
|
|
232
267
|
)}
|
|
233
268
|
</div>
|
|
234
269
|
|
|
@@ -294,6 +329,13 @@ function CommentItem({
|
|
|
294
329
|
onPost(body, comment.id);
|
|
295
330
|
setReplying(false);
|
|
296
331
|
}}
|
|
332
|
+
onVoice={
|
|
333
|
+
onPostVoice &&
|
|
334
|
+
((r) => {
|
|
335
|
+
onPostVoice(r, comment.id);
|
|
336
|
+
setReplying(false);
|
|
337
|
+
})
|
|
338
|
+
}
|
|
297
339
|
/>
|
|
298
340
|
</div>
|
|
299
341
|
)}
|
|
@@ -309,6 +351,7 @@ function CommentItem({
|
|
|
309
351
|
onEdit={onEdit}
|
|
310
352
|
onDelete={onDelete}
|
|
311
353
|
onReact={onReact}
|
|
354
|
+
onPostVoice={onPostVoice}
|
|
312
355
|
/>
|
|
313
356
|
))}
|
|
314
357
|
</div>
|
|
@@ -325,8 +368,9 @@ function CommentItem({
|
|
|
325
368
|
* query/mutation hooks bundled — wire up your own TanStack Query mutations and pass
|
|
326
369
|
* the results as props.
|
|
327
370
|
*
|
|
328
|
-
* Supports one level of replies, edit, delete (with confirm),
|
|
329
|
-
* via {@link ReactionBar}
|
|
371
|
+
* Supports one level of replies, edit, delete (with confirm), emoji reactions
|
|
372
|
+
* via {@link ReactionBar}, and — with `onPostVoice` — voice comments recorded by
|
|
373
|
+
* {@link VoiceRecorder} and played inline by {@link VoiceNote}. Each interaction calls its corresponding handler; the
|
|
330
374
|
* caller re-renders with fresh data.
|
|
331
375
|
*/
|
|
332
376
|
export function CommentThread({
|
|
@@ -336,6 +380,7 @@ export function CommentThread({
|
|
|
336
380
|
onEdit,
|
|
337
381
|
onDelete,
|
|
338
382
|
onReact,
|
|
383
|
+
onPostVoice,
|
|
339
384
|
className,
|
|
340
385
|
emptyMessage = 'No comments yet — start the conversation.',
|
|
341
386
|
placeholder = 'Add a comment… (⌘/Ctrl+Enter to send)',
|
|
@@ -356,6 +401,7 @@ export function CommentThread({
|
|
|
356
401
|
onEdit={onEdit}
|
|
357
402
|
onDelete={onDelete}
|
|
358
403
|
onReact={onReact}
|
|
404
|
+
onPostVoice={onPostVoice}
|
|
359
405
|
/>
|
|
360
406
|
))}
|
|
361
407
|
{/* Loading drew nothing at all — only the composer — which read as an empty thread. */}
|
|
@@ -363,7 +409,11 @@ export function CommentThread({
|
|
|
363
409
|
{!isLoading && topLevel.length === 0 && (
|
|
364
410
|
<p className='text-xs text-muted-foreground'>{emptyMessage}</p>
|
|
365
411
|
)}
|
|
366
|
-
<Composer
|
|
412
|
+
<Composer
|
|
413
|
+
placeholder={placeholder}
|
|
414
|
+
onSubmit={(body) => onPost(body)}
|
|
415
|
+
onVoice={onPostVoice && ((r) => onPostVoice(r))}
|
|
416
|
+
/>
|
|
367
417
|
</div>
|
|
368
418
|
);
|
|
369
419
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Pause, Play } from 'lucide-react';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { cn } from '../lib/cn.js';
|
|
4
|
+
import { IconButton } from './IconButton.js';
|
|
5
|
+
|
|
6
|
+
/** `m:ss` — a voice note is minutes long at most. */
|
|
7
|
+
export function formatVoiceTime(ms: number): string {
|
|
8
|
+
const s = Math.max(0, Math.floor(ms / 1000));
|
|
9
|
+
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface VoiceNoteProps {
|
|
13
|
+
/** The audio's URL — a signed media URL, or an object URL for a recording not yet sent. */
|
|
14
|
+
src: string;
|
|
15
|
+
/** The length when the caller already knows it; otherwise the element's own metadata says. */
|
|
16
|
+
durationMs?: number;
|
|
17
|
+
/** What the play button names: "Play voice comment by Alice". */
|
|
18
|
+
label?: string;
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A voice note: play/pause, a seek track and the time — the compact pill a message thread draws
|
|
24
|
+
* (iMessage, WhatsApp, Slack huddles), not the browser's own `<audio controls>`, whose look and
|
|
25
|
+
* height differ in every engine and which ignores the theme.
|
|
26
|
+
*
|
|
27
|
+
* `preload='metadata'`: a thread of ten notes fetches ten headers, not ten files.
|
|
28
|
+
*/
|
|
29
|
+
export function VoiceNote({ src, durationMs, label = 'Play voice note', className, ...rest }: VoiceNoteProps) {
|
|
30
|
+
const audio = useRef<HTMLAudioElement>(null);
|
|
31
|
+
const [playing, setPlaying] = useState(false);
|
|
32
|
+
const [at, setAt] = useState(0);
|
|
33
|
+
const [length, setLength] = useState(durationMs ?? 0);
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (durationMs) setLength(durationMs);
|
|
37
|
+
}, [durationMs]);
|
|
38
|
+
|
|
39
|
+
const toggle = () => {
|
|
40
|
+
const el = audio.current;
|
|
41
|
+
if (!el) return;
|
|
42
|
+
if (el.paused) void el.play().catch(() => setPlaying(false));
|
|
43
|
+
else el.pause();
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div {...rest} data-cb-voice-note='' className={cn('flex min-w-0 items-center gap-2', className)}>
|
|
48
|
+
{/* biome-ignore lint/a11y/useMediaCaption: a family member's spoken note has no caption track; any words they typed sit beside it */}
|
|
49
|
+
<audio
|
|
50
|
+
ref={audio}
|
|
51
|
+
src={src}
|
|
52
|
+
preload='metadata'
|
|
53
|
+
onPlay={() => setPlaying(true)}
|
|
54
|
+
onPause={() => setPlaying(false)}
|
|
55
|
+
onEnded={() => {
|
|
56
|
+
setPlaying(false);
|
|
57
|
+
setAt(0);
|
|
58
|
+
}}
|
|
59
|
+
onTimeUpdate={(e) => setAt(e.currentTarget.currentTime * 1000)}
|
|
60
|
+
onLoadedMetadata={(e) => {
|
|
61
|
+
// A MediaRecorder WebM says `Infinity` until it has been read through; keep the caller's.
|
|
62
|
+
const d = e.currentTarget.duration;
|
|
63
|
+
if (Number.isFinite(d) && d > 0) setLength(d * 1000);
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
<IconButton label={playing ? 'Pause' : label} size='sm' variant='secondary' className='shrink-0 rounded-full' onClick={toggle}>
|
|
67
|
+
{playing ? <Pause /> : <Play />}
|
|
68
|
+
</IconButton>
|
|
69
|
+
<input
|
|
70
|
+
// guardrails-ignore no-raw-inputs: perf — a voice note's own seek track (type=range), not a form
|
|
71
|
+
// field — the native range keeps Radix's slider (~6 kB gzip) out of every comment thread.
|
|
72
|
+
type='range'
|
|
73
|
+
aria-label='Position'
|
|
74
|
+
aria-valuetext={formatVoiceTime(at)}
|
|
75
|
+
min={0}
|
|
76
|
+
max={Math.max(1, length)}
|
|
77
|
+
step={100}
|
|
78
|
+
value={Math.min(at, Math.max(1, length))}
|
|
79
|
+
disabled={!length}
|
|
80
|
+
onChange={(e) => {
|
|
81
|
+
const v = Number(e.target.value);
|
|
82
|
+
setAt(v);
|
|
83
|
+
if (audio.current) audio.current.currentTime = v / 1000;
|
|
84
|
+
}}
|
|
85
|
+
className='h-1 min-w-16 flex-1 cursor-pointer accent-[var(--accent-solid)] disabled:cursor-not-allowed'
|
|
86
|
+
/>
|
|
87
|
+
<span className='shrink-0 text-xs tabular-nums text-muted-foreground'>
|
|
88
|
+
{formatVoiceTime(playing || at > 0 ? at : length)}
|
|
89
|
+
</span>
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test';
|
|
2
|
+
import { act, cleanup, fireEvent, render, waitFor } from '@testing-library/react';
|
|
3
|
+
import { pickVoiceMime, type VoiceRecording, VoiceRecorder } from './VoiceRecorder.js';
|
|
4
|
+
|
|
5
|
+
/** A microphone and a MediaRecorder that hands back one chunk when it stops. */
|
|
6
|
+
function fakeMedia(o: { supported?: readonly string[]; refuse?: string } = {}) {
|
|
7
|
+
const supported = o.supported ?? ['audio/webm;codecs=opus', 'audio/mp4'];
|
|
8
|
+
const track = { stopped: false, stop() { this.stopped = true; } };
|
|
9
|
+
const stream = { getTracks: () => [track] } as unknown as MediaStream;
|
|
10
|
+
class FakeRecorder {
|
|
11
|
+
static isTypeSupported = (t: string) => supported.includes(t);
|
|
12
|
+
state: 'inactive' | 'recording' = 'inactive';
|
|
13
|
+
mimeType: string;
|
|
14
|
+
ondataavailable: ((e: { data: Blob }) => void) | null = null;
|
|
15
|
+
onstop: (() => void) | null = null;
|
|
16
|
+
constructor(_s: MediaStream, opts: { mimeType: string }) {
|
|
17
|
+
this.mimeType = opts.mimeType;
|
|
18
|
+
}
|
|
19
|
+
start() {
|
|
20
|
+
this.state = 'recording';
|
|
21
|
+
}
|
|
22
|
+
stop() {
|
|
23
|
+
this.state = 'inactive';
|
|
24
|
+
this.ondataavailable?.({ data: new Blob(['voice-bytes']) });
|
|
25
|
+
this.onstop?.();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const getUserMedia = mock(() => (o.refuse ? Promise.reject(new DOMException('no', o.refuse)) : Promise.resolve(stream)));
|
|
29
|
+
Object.assign(globalThis, { MediaRecorder: FakeRecorder });
|
|
30
|
+
Object.defineProperty(navigator, 'mediaDevices', { value: { getUserMedia }, configurable: true });
|
|
31
|
+
return { track, getUserMedia };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
URL.createObjectURL = () => 'blob:take';
|
|
36
|
+
URL.revokeObjectURL = () => {};
|
|
37
|
+
});
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
cleanup();
|
|
40
|
+
delete (globalThis as { MediaRecorder?: unknown }).MediaRecorder;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('pickVoiceMime', () => {
|
|
44
|
+
test('Opus in WebM first, AAC in MP4 for WebKit, nothing when the browser records nothing', () => {
|
|
45
|
+
expect(pickVoiceMime((t) => ['audio/webm;codecs=opus', 'audio/mp4'].includes(t))).toBe('audio/webm;codecs=opus');
|
|
46
|
+
expect(pickVoiceMime((t) => t === 'audio/mp4')).toBe('audio/mp4');
|
|
47
|
+
expect(pickVoiceMime(() => false)).toBeNull();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('VoiceRecorder', () => {
|
|
52
|
+
test('starts on mount, and Send hands over the take in the container without its codec — the microphone released', async () => {
|
|
53
|
+
const media = fakeMedia();
|
|
54
|
+
const onDone = mock((_r: VoiceRecording) => {});
|
|
55
|
+
const { findByRole, getByRole } = render(<VoiceRecorder onDone={onDone} onCancel={() => {}} />);
|
|
56
|
+
await findByRole('timer', { name: 'Recording time' });
|
|
57
|
+
await waitFor(() => expect((getByRole('button', { name: /Send/ }) as HTMLButtonElement).disabled).toBe(false));
|
|
58
|
+
fireEvent.click(getByRole('button', { name: /Send/ }));
|
|
59
|
+
expect(onDone).toHaveBeenCalledTimes(1);
|
|
60
|
+
const r = onDone.mock.calls[0]?.[0] as VoiceRecording;
|
|
61
|
+
expect(r.mime).toBe('audio/webm');
|
|
62
|
+
expect(r.blob.type).toBe('audio/webm');
|
|
63
|
+
expect(await r.blob.text()).toBe('voice-bytes');
|
|
64
|
+
expect(media.track.stopped).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('Safari records MP4, and the take says so', async () => {
|
|
68
|
+
fakeMedia({ supported: ['audio/mp4'] });
|
|
69
|
+
const onDone = mock((_r: VoiceRecording) => {});
|
|
70
|
+
const { getByRole } = render(<VoiceRecorder onDone={onDone} onCancel={() => {}} />);
|
|
71
|
+
await waitFor(() => expect((getByRole('button', { name: /Send/ }) as HTMLButtonElement).disabled).toBe(false));
|
|
72
|
+
fireEvent.click(getByRole('button', { name: /Send/ }));
|
|
73
|
+
expect((onDone.mock.calls[0]![0] as VoiceRecording).mime).toBe('audio/mp4');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('Cancel throws the take away and releases the microphone', async () => {
|
|
77
|
+
const media = fakeMedia();
|
|
78
|
+
const onDone = mock(() => {});
|
|
79
|
+
const onCancel = mock(() => {});
|
|
80
|
+
const { getByRole } = render(<VoiceRecorder onDone={onDone} onCancel={onCancel} />);
|
|
81
|
+
await waitFor(() => expect((getByRole('button', { name: /Send/ }) as HTMLButtonElement).disabled).toBe(false));
|
|
82
|
+
fireEvent.click(getByRole('button', { name: 'Cancel' }));
|
|
83
|
+
expect(onCancel).toHaveBeenCalledTimes(1);
|
|
84
|
+
expect(onDone).not.toHaveBeenCalled();
|
|
85
|
+
expect(media.track.stopped).toBe(true);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('a refused microphone says so, and Close leaves', async () => {
|
|
89
|
+
fakeMedia({ refuse: 'NotAllowedError' });
|
|
90
|
+
const onCancel = mock(() => {});
|
|
91
|
+
const { findByRole, getByRole } = render(<VoiceRecorder onDone={() => {}} onCancel={onCancel} />);
|
|
92
|
+
expect((await findByRole('alert')).textContent).toContain('Microphone access was refused');
|
|
93
|
+
fireEvent.click(getByRole('button', { name: 'Close' }));
|
|
94
|
+
expect(onCancel).toHaveBeenCalledTimes(1);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('a browser with no recorder says so instead of failing silently', async () => {
|
|
98
|
+
fakeMedia({ supported: [] });
|
|
99
|
+
const { findByRole } = render(<VoiceRecorder onDone={() => {}} onCancel={() => {}} />);
|
|
100
|
+
expect((await findByRole('alert')).textContent).toContain('cannot record audio');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('at the length limit it stops by itself and waits to be sent or discarded — it never sends unasked', async () => {
|
|
104
|
+
fakeMedia();
|
|
105
|
+
const onDone = mock((_r: VoiceRecording) => {});
|
|
106
|
+
const { findByRole } = render(<VoiceRecorder maxMs={250} onDone={onDone} onCancel={() => {}} />);
|
|
107
|
+
const discard = await findByRole('button', { name: /Discard/ }, { timeout: 2000 });
|
|
108
|
+
expect(discard).toBeTruthy();
|
|
109
|
+
expect(onDone).not.toHaveBeenCalled();
|
|
110
|
+
await act(async () => {
|
|
111
|
+
fireEvent.click(await findByRole('button', { name: /Send/ }));
|
|
112
|
+
});
|
|
113
|
+
expect(onDone).toHaveBeenCalledTimes(1);
|
|
114
|
+
expect((onDone.mock.calls[0]![0] as VoiceRecording).durationMs).toBeLessThanOrEqual(250);
|
|
115
|
+
});
|
|
116
|
+
});
|