cursedbelt 5.22.1 → 5.23.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/SearchInput.d.ts +15 -1
- package/dist/react/components/SearchInput.d.ts.map +1 -1
- package/dist/react/components/SearchInput.js +36 -4
- package/dist/react/components/SearchInput.js.map +1 -1
- package/dist/react/components/searchInput.css +179 -0
- package/dist/react/media/DenseGalleryShell.d.ts +8 -2
- package/dist/react/media/DenseGalleryShell.d.ts.map +1 -1
- package/dist/react/media/DenseGalleryShell.js +2 -2
- package/dist/react/media/DenseGalleryShell.js.map +1 -1
- package/dist/react/media-gallery/GalleryTable.js +1 -1
- package/dist/react/media-gallery/GalleryTable.js.map +1 -1
- package/dist/react/media-gallery/MediaGallery.d.ts.map +1 -1
- package/dist/react/media-gallery/MediaGallery.js +16 -4
- package/dist/react/media-gallery/MediaGallery.js.map +1 -1
- package/dist/react/media-gallery/galleryReturn.d.ts +50 -0
- package/dist/react/media-gallery/galleryReturn.d.ts.map +1 -0
- package/dist/react/media-gallery/galleryReturn.js +221 -0
- package/dist/react/media-gallery/galleryReturn.js.map +1 -0
- package/package.json +8 -1
- package/src/demoFixture.spec.ts +4 -2
- package/src/react/components/SearchInput.spec.tsx +57 -0
- package/src/react/components/SearchInput.tsx +74 -20
- package/src/react/components/searchInput.css +179 -0
- package/src/react/media/DenseGalleryShell.tsx +9 -1
- package/src/react/media-gallery/GalleryTable.tsx +2 -0
- package/src/react/media-gallery/MediaGallery.tsx +19 -1
- package/src/react/media-gallery/galleryReturn.ts +248 -0
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { afterEach, describe, expect, mock, test } from 'bun:test';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { createRef } from 'react';
|
|
2
4
|
import { cleanup, fireEvent, render } from '@testing-library/react';
|
|
3
5
|
import { SearchInput } from './SearchInput.js';
|
|
4
6
|
|
|
@@ -56,4 +58,59 @@ describe('SearchInput', () => {
|
|
|
56
58
|
expect(badge(container)).toBeNull();
|
|
57
59
|
expect(getByRole('searchbox').className).not.toContain('pr-9');
|
|
58
60
|
});
|
|
61
|
+
|
|
62
|
+
test('no ✕ unless asked for — a box that never had one does not grow one', () => {
|
|
63
|
+
const { queryByRole } = render(<SearchInput value='the office' onChange={() => {}} />);
|
|
64
|
+
expect(queryByRole('button', { name: 'Clear search' })).toBeNull();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('clearable: the ✕ appears with text, empties the box, and leaves the caret in it', () => {
|
|
68
|
+
const onChange = mock((_: string) => {});
|
|
69
|
+
const empty = render(<SearchInput value='' onChange={onChange} clearable />);
|
|
70
|
+
expect(empty.queryByRole('button', { name: 'Clear search' })).toBeNull();
|
|
71
|
+
empty.unmount();
|
|
72
|
+
|
|
73
|
+
const { getByRole } = render(<SearchInput value='report' onChange={onChange} clearable />);
|
|
74
|
+
const input = getByRole('searchbox');
|
|
75
|
+
expect(input.getAttribute('data-trailing')).toBe('1');
|
|
76
|
+
fireEvent.click(getByRole('button', { name: 'Clear search' }));
|
|
77
|
+
expect(onChange).toHaveBeenLastCalledWith('');
|
|
78
|
+
expect(document.activeElement).toBe(input);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('badge and ✕ together: the field makes room for both', () => {
|
|
82
|
+
const { getByRole } = render(<SearchInput value='q3*report' onChange={() => {}} clearable />);
|
|
83
|
+
const input = getByRole('searchbox');
|
|
84
|
+
expect(input.getAttribute('data-trailing')).toBe('2');
|
|
85
|
+
expect(input.className).toContain('pr-16');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("a ref and a data attribute reach the <input> — desk's ⌘F finds its field by one", () => {
|
|
89
|
+
const ref = createRef<HTMLInputElement>();
|
|
90
|
+
const { getByRole } = render(
|
|
91
|
+
<SearchInput ref={ref} value='' onChange={() => {}} data-find-field='true' clearable />,
|
|
92
|
+
);
|
|
93
|
+
const input = getByRole('searchbox');
|
|
94
|
+
expect(ref.current).toBe(input as HTMLInputElement);
|
|
95
|
+
expect(input.getAttribute('data-find-field')).toBe('true');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('every element carries its plain `cbsi-` class beside its utilities', () => {
|
|
99
|
+
const { container, getByRole } = render(<SearchInput value='the*the' onChange={() => {}} clearable />);
|
|
100
|
+
expect(container.querySelector('.cbsi')).not.toBeNull();
|
|
101
|
+
expect(container.querySelector('svg.cbsi-icon')).not.toBeNull();
|
|
102
|
+
expect(getByRole('searchbox').className).toContain('cbsi-input');
|
|
103
|
+
expect(badge(container)?.className).toContain('cbsi-badge');
|
|
104
|
+
expect(container.querySelector('button.cbsi-clear')).not.toBeNull();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('🔴 the stylesheet is imported by the component and every rule sits in `@layer base`', () => {
|
|
108
|
+
// An import nobody makes ships a look nobody sees; an unlayered rule would override a
|
|
109
|
+
// Tailwind app's `inputClassName` (see the stylesheet's header). Both are silent in a DOM test.
|
|
110
|
+
const source = readFileSync(new URL('./SearchInput.tsx', import.meta.url), 'utf8');
|
|
111
|
+
expect(source).toContain("import './searchInput.css';");
|
|
112
|
+
const css = readFileSync(new URL('./searchInput.css', import.meta.url), 'utf8').replace(/\/\*[\s\S]*?\*\//g, '');
|
|
113
|
+
const outside = css.replace(/@layer base\s*\{[\s\S]*\}\s*$/, '').trim();
|
|
114
|
+
expect(outside).toBe('');
|
|
115
|
+
});
|
|
59
116
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Asterisk, Regex, Search, TriangleAlert } from 'lucide-react';
|
|
2
|
-
import { useMemo } from 'react';
|
|
1
|
+
import { Asterisk, Regex, Search, TriangleAlert, X } from 'lucide-react';
|
|
2
|
+
import { useMemo, useRef } from 'react';
|
|
3
3
|
import {
|
|
4
4
|
parseSearchPattern,
|
|
5
5
|
type SearchPattern,
|
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
import { cn } from '../lib/cn.js';
|
|
9
9
|
import { Input, type InputProps } from './Input.js';
|
|
10
10
|
import { Tooltip } from './Tooltip.js';
|
|
11
|
+
// 🔴 The look travels with the component — see the stylesheet's header for why every rule in it
|
|
12
|
+
// sits in `@layer base`, below the Tailwind utilities this file still carries.
|
|
13
|
+
import './searchInput.css';
|
|
11
14
|
|
|
12
15
|
export interface SearchInputProps extends Omit<InputProps, 'value' | 'onChange' | 'type'> {
|
|
13
16
|
value: string;
|
|
@@ -25,6 +28,12 @@ export interface SearchInputProps extends Omit<InputProps, 'value' | 'onChange'
|
|
|
25
28
|
className?: string;
|
|
26
29
|
/** Classes for the `<input>` itself — colours, radius, text size. */
|
|
27
30
|
inputClassName?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Draw a ✕ that empties the box (and keeps the caret in it) while there is text to clear.
|
|
33
|
+
* Default `false`, so a box that never had one does not grow one. The browser's own ✕ on a
|
|
34
|
+
* `type="search"` field is hidden while this is on, so there is only ever one.
|
|
35
|
+
*/
|
|
36
|
+
clearable?: boolean;
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
const PLAIN_ONLY: SearchSyntaxOptions = { wildcard: false, regex: false };
|
|
@@ -64,6 +73,13 @@ function badgeFor(pattern: SearchPattern) {
|
|
|
64
73
|
* Parsing is the app's too: this component only DISPLAYS the pattern. An app
|
|
65
74
|
* that filters in memory calls `createSearchMatcher(value, syntax)`; one that
|
|
66
75
|
* queries a server parses there with the same options.
|
|
76
|
+
*
|
|
77
|
+
* ── In an app with no Tailwind ──────────────────────────────────────────────
|
|
78
|
+
* It draws from its own `searchInput.css` (5.23.0, task 2256), so import it by its
|
|
79
|
+
* own subpath, `cursedbelt/react/search-input`, rather than the `cursedbelt/react`
|
|
80
|
+
* barrel. Everything else a field needs passes straight to the `<input>`: `ref`,
|
|
81
|
+
* `autoFocus`, and any `data-*` attribute (desk's ⌘F finds its field by
|
|
82
|
+
* `data-find-field="true"`).
|
|
67
83
|
*/
|
|
68
84
|
export function SearchInput({
|
|
69
85
|
value,
|
|
@@ -74,43 +90,81 @@ export function SearchInput({
|
|
|
74
90
|
inputClassName,
|
|
75
91
|
placeholder = 'Search…',
|
|
76
92
|
'aria-label': ariaLabel,
|
|
93
|
+
clearable = false,
|
|
94
|
+
ref,
|
|
77
95
|
...inputProps
|
|
78
96
|
}: SearchInputProps) {
|
|
79
97
|
const pattern = useMemo(() => parseSearchPattern(value, syntax === false ? PLAIN_ONLY : syntax), [value, syntax]);
|
|
80
98
|
const badge = showSyntaxBadge ? badgeFor(pattern) : null;
|
|
81
99
|
const invalid = pattern.kind === 'invalid';
|
|
100
|
+
const clear = clearable && value !== '';
|
|
101
|
+
const trailing = (badge ? 1 : 0) + (clear ? 1 : 0);
|
|
102
|
+
// Our own handle on the field, so the ✕ can put the caret back — merged with the caller's.
|
|
103
|
+
const own = useRef<HTMLInputElement | null>(null);
|
|
104
|
+
const setRef = (node: HTMLInputElement | null): void => {
|
|
105
|
+
own.current = node;
|
|
106
|
+
if (typeof ref === 'function') ref(node);
|
|
107
|
+
else if (ref) ref.current = node;
|
|
108
|
+
};
|
|
82
109
|
|
|
110
|
+
/*
|
|
111
|
+
* Every element carries BOTH its `cbsi-` class (the plain look, for an app with no Tailwind)
|
|
112
|
+
* and the Tailwind utilities it always had (the look a Tailwind app restyles through
|
|
113
|
+
* `className`/`inputClassName`). The stylesheet's header says why the two cannot fight.
|
|
114
|
+
*/
|
|
83
115
|
return (
|
|
84
|
-
<div className={cn('relative min-w-0', className)}>
|
|
116
|
+
<div className={cn('cbsi relative min-w-0', className)}>
|
|
85
117
|
<Search
|
|
86
118
|
aria-hidden
|
|
87
|
-
className='-translate-y-1/2 pointer-events-none absolute top-1/2 left-2.5 size-4 text-muted-foreground'
|
|
119
|
+
className='cbsi-icon -translate-y-1/2 pointer-events-none absolute top-1/2 left-2.5 size-4 text-muted-foreground'
|
|
88
120
|
/>
|
|
89
121
|
<Input
|
|
90
122
|
{...inputProps}
|
|
123
|
+
ref={setRef}
|
|
91
124
|
type='search'
|
|
92
125
|
value={value}
|
|
93
126
|
onChange={(event) => onChange(event.target.value)}
|
|
94
127
|
placeholder={placeholder}
|
|
95
128
|
aria-label={ariaLabel ?? (typeof placeholder === 'string' ? placeholder : 'Search')}
|
|
96
129
|
aria-invalid={invalid || undefined}
|
|
97
|
-
|
|
130
|
+
data-trailing={trailing || undefined}
|
|
131
|
+
data-clearable={clearable || undefined}
|
|
132
|
+
className={cn('cbsi-input pl-8', trailing === 1 && 'pr-9', trailing === 2 && 'pr-16', inputClassName)}
|
|
98
133
|
/>
|
|
99
|
-
{
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
134
|
+
{trailing > 0 ? (
|
|
135
|
+
<span className='cbsi-trail -translate-y-1/2 absolute top-1/2 right-2 inline-flex items-center gap-1'>
|
|
136
|
+
{badge ? (
|
|
137
|
+
<Tooltip content={badge.tip} side='bottom' multiline>
|
|
138
|
+
<span
|
|
139
|
+
role='img'
|
|
140
|
+
aria-label={badge.label}
|
|
141
|
+
data-testid='search-syntax-badge'
|
|
142
|
+
data-kind={pattern.kind}
|
|
143
|
+
className={cn(
|
|
144
|
+
'cbsi-badge inline-flex size-6 items-center justify-center rounded-full',
|
|
145
|
+
invalid ? 'bg-destructive/15 text-destructive' : 'bg-accent/15 text-accent-strong',
|
|
146
|
+
)}
|
|
147
|
+
>
|
|
148
|
+
<badge.icon className='size-3.5' aria-hidden />
|
|
149
|
+
</span>
|
|
150
|
+
</Tooltip>
|
|
151
|
+
) : null}
|
|
152
|
+
{clear ? (
|
|
153
|
+
<button
|
|
154
|
+
// guardrails-ignore no-raw-action-button: a 24px glyph INSIDE the field, styled by
|
|
155
|
+
// this component's own plain CSS (`.cbsi-clear`) so it draws without Tailwind.
|
|
156
|
+
type='button'
|
|
157
|
+
className='cbsi-clear'
|
|
158
|
+
aria-label='Clear search'
|
|
159
|
+
onClick={() => {
|
|
160
|
+
onChange('');
|
|
161
|
+
own.current?.focus();
|
|
162
|
+
}}
|
|
163
|
+
>
|
|
164
|
+
<X aria-hidden />
|
|
165
|
+
</button>
|
|
166
|
+
) : null}
|
|
167
|
+
</span>
|
|
114
168
|
) : null}
|
|
115
169
|
</div>
|
|
116
170
|
);
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SearchInput's own look, as plain CSS — so it draws in an app with NO Tailwind (desk), the way
|
|
3
|
+
* `activityBar.css` and `fileTree.css` let those two travel. Prefix `cbsi-`. Task 2256.
|
|
4
|
+
*
|
|
5
|
+
* 🔴 Everything here is inside `@layer base`, and that is the whole trick — read before editing.
|
|
6
|
+
*
|
|
7
|
+
* The component KEEPS its Tailwind utilities, because a Tailwind app restyles the field through
|
|
8
|
+
* them: flix passes `inputClassName="rounded-full bg-[var(--surface-1)] …"`. An UNLAYERED rule
|
|
9
|
+
* beats every layered one whatever its specificity, and Tailwind v4 puts utilities in
|
|
10
|
+
* `@layer utilities` — so a plain `.cbsi-input { border-radius: … }` would silently undo flix's
|
|
11
|
+
* `rounded-full`. In `@layer base` these rules sit BELOW utilities in every Tailwind app, in
|
|
12
|
+
* either load order: if Tailwind's `@layer theme, base, components, utilities` came first,
|
|
13
|
+
* `base` is second of four; if this file came first, `base` is registered first and Tailwind's
|
|
14
|
+
* statement appends the rest after it. Within `base`, a `.cbsi-` class out-ranks preflight's
|
|
15
|
+
* element selectors, and every value below is the value Tailwind already computes, so a
|
|
16
|
+
* Tailwind app draws exactly what it drew before this file existed.
|
|
17
|
+
*
|
|
18
|
+
* In an app without Tailwind this is the only author layer that matches these elements, so it
|
|
19
|
+
* is the look. Its tokens fall back to the plainer ones an app is most likely to bridge
|
|
20
|
+
* (`--border`, `--background`, `--foreground`, `--muted-foreground`, `--ring`, `--accent`,
|
|
21
|
+
* `--destructive`, `--radius-sm`) — desk answers those on `.cs-root`.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
@layer base {
|
|
25
|
+
.cbsi {
|
|
26
|
+
position: relative;
|
|
27
|
+
min-width: 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.cbsi-icon {
|
|
31
|
+
position: absolute;
|
|
32
|
+
top: 50%;
|
|
33
|
+
left: 0.625rem;
|
|
34
|
+
translate: 0 -50%;
|
|
35
|
+
width: 1rem;
|
|
36
|
+
height: 1rem;
|
|
37
|
+
pointer-events: none;
|
|
38
|
+
color: var(--muted-foreground);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* The field — `fieldControlClass('md')`, written out. */
|
|
42
|
+
.cbsi-input {
|
|
43
|
+
box-sizing: border-box;
|
|
44
|
+
width: 100%;
|
|
45
|
+
height: var(--control-h-md, 36px);
|
|
46
|
+
margin: 0;
|
|
47
|
+
padding: 0 0.75rem 0 2rem;
|
|
48
|
+
border: 1px solid var(--field-border, var(--border));
|
|
49
|
+
border-radius: var(--field-radius, var(--radius-md, var(--radius-sm, 0.375rem)));
|
|
50
|
+
background-color: var(--field-bg, var(--background));
|
|
51
|
+
color: var(--field-fg, var(--foreground));
|
|
52
|
+
font: inherit;
|
|
53
|
+
font-size: 1rem;
|
|
54
|
+
line-height: 1.5rem;
|
|
55
|
+
outline: none;
|
|
56
|
+
appearance: none;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* 16px on a phone keeps iOS from zooming on focus; 14px from `sm:` up, as `text-sm`. */
|
|
60
|
+
@media (min-width: 40rem) {
|
|
61
|
+
.cbsi-input {
|
|
62
|
+
font-size: 0.875rem;
|
|
63
|
+
line-height: 1.25rem;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* DESIGN.md §5: 44px to a thumb. */
|
|
68
|
+
@media (pointer: coarse) {
|
|
69
|
+
.cbsi-input {
|
|
70
|
+
min-height: 2.75rem;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.cbsi-input::placeholder {
|
|
75
|
+
color: var(--field-placeholder, var(--muted-foreground));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.cbsi-input:focus-visible {
|
|
79
|
+
border-color: var(--field-ring, var(--ring));
|
|
80
|
+
box-shadow: 0 0 0 2px color-mix(in oklab, var(--field-ring, var(--ring)) 30%, transparent);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.cbsi-input[aria-invalid='true'] {
|
|
84
|
+
border-color: var(--field-error, var(--destructive));
|
|
85
|
+
box-shadow: 0 0 0 2px color-mix(in oklab, var(--field-error, var(--destructive)) 30%, transparent);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.cbsi-input:disabled {
|
|
89
|
+
cursor: not-allowed;
|
|
90
|
+
opacity: 0.5;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* Room on the right for whatever sits there: a badge, a clear button, or both. */
|
|
94
|
+
.cbsi-input[data-trailing='1'] {
|
|
95
|
+
padding-right: 2.25rem;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.cbsi-input[data-trailing='2'] {
|
|
99
|
+
padding-right: 4rem;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* A clearable box draws its own ✕, so the browser's must not draw a second one. */
|
|
103
|
+
.cbsi-input[data-clearable]::-webkit-search-cancel-button {
|
|
104
|
+
appearance: none;
|
|
105
|
+
display: none;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.cbsi-trail {
|
|
109
|
+
position: absolute;
|
|
110
|
+
top: 50%;
|
|
111
|
+
right: 0.5rem;
|
|
112
|
+
translate: 0 -50%;
|
|
113
|
+
display: inline-flex;
|
|
114
|
+
align-items: center;
|
|
115
|
+
gap: 0.25rem;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* The badge: a filled capsule (DESIGN.md §3), accent while a syntax is in play. */
|
|
119
|
+
.cbsi-badge {
|
|
120
|
+
display: inline-flex;
|
|
121
|
+
align-items: center;
|
|
122
|
+
justify-content: center;
|
|
123
|
+
width: 1.5rem;
|
|
124
|
+
height: 1.5rem;
|
|
125
|
+
border-radius: 9999px;
|
|
126
|
+
background-color: color-mix(in oklab, var(--accent) 15%, transparent);
|
|
127
|
+
color: var(--accent-strong, var(--accent));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.cbsi-badge[data-kind='invalid'] {
|
|
131
|
+
background-color: color-mix(in oklab, var(--destructive) 15%, transparent);
|
|
132
|
+
color: var(--destructive);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.cbsi-badge svg {
|
|
136
|
+
width: 0.875rem;
|
|
137
|
+
height: 0.875rem;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.cbsi-clear {
|
|
141
|
+
position: relative;
|
|
142
|
+
display: inline-flex;
|
|
143
|
+
align-items: center;
|
|
144
|
+
justify-content: center;
|
|
145
|
+
width: 1.5rem;
|
|
146
|
+
height: 1.5rem;
|
|
147
|
+
margin: 0;
|
|
148
|
+
padding: 0;
|
|
149
|
+
border: 0;
|
|
150
|
+
border-radius: var(--radius-sm, 0.375rem);
|
|
151
|
+
background: transparent;
|
|
152
|
+
color: var(--muted-foreground);
|
|
153
|
+
cursor: pointer;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.cbsi-clear:hover {
|
|
157
|
+
color: var(--foreground);
|
|
158
|
+
background: var(--muted, color-mix(in oklab, var(--foreground) 8%, transparent));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.cbsi-clear:focus-visible {
|
|
162
|
+
outline: 2px solid var(--ring);
|
|
163
|
+
outline-offset: 1px;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* The ✕ is 24px to the eye; to a thumb it reaches the 44px floor (DESIGN.md §5). */
|
|
167
|
+
@media (pointer: coarse) {
|
|
168
|
+
.cbsi-clear::after {
|
|
169
|
+
content: '';
|
|
170
|
+
position: absolute;
|
|
171
|
+
inset: -10px;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.cbsi-clear svg {
|
|
176
|
+
width: 0.75rem;
|
|
177
|
+
height: 0.75rem;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type CSSProperties,
|
|
6
6
|
type MouseEvent as ReactMouseEvent,
|
|
7
7
|
type ReactNode,
|
|
8
|
+
type Ref,
|
|
8
9
|
useCallback,
|
|
9
10
|
useEffect,
|
|
10
11
|
useState,
|
|
@@ -231,6 +232,12 @@ export interface DenseGalleryShellProps<O extends string = string> {
|
|
|
231
232
|
* exactly one place the caption height is written down.
|
|
232
233
|
*/
|
|
233
234
|
rowExtraHeight?: number;
|
|
235
|
+
/**
|
|
236
|
+
* The shell's root element (`.cbgd-root`) — for a caller that has to find the browse view's
|
|
237
|
+
* scroller in the DOM. `MediaGallery` uses it to put the grid back where you were when a
|
|
238
|
+
* file closes (`media-gallery/galleryReturn.ts`), because closing a file mounts a new shell.
|
|
239
|
+
*/
|
|
240
|
+
rootRef?: Ref<HTMLDivElement>;
|
|
234
241
|
}
|
|
235
242
|
|
|
236
243
|
/** The browse view: header + optional filter strip + a virtualized thumbnail grid. */
|
|
@@ -254,9 +261,10 @@ export function DenseGalleryShell<O extends string = string>({
|
|
|
254
261
|
minColumnWidth = 160,
|
|
255
262
|
// 🔴 Deliberately NOT defaulted here — see the prop's doc comment.
|
|
256
263
|
rowExtraHeight,
|
|
264
|
+
rootRef,
|
|
257
265
|
}: DenseGalleryShellProps<O>) {
|
|
258
266
|
return (
|
|
259
|
-
<div className='cbgd-root'>
|
|
267
|
+
<div className='cbgd-root' ref={rootRef}>
|
|
260
268
|
{chrome === 'none' ? null : (
|
|
261
269
|
<header className='cbgd-header'>
|
|
262
270
|
<span className='cbgd-title'>{title}</span>
|
|
@@ -496,6 +496,8 @@ function GalleryTableRow({
|
|
|
496
496
|
// The same two hooks the grid tile carries: the attribute is what the gallery's reveal
|
|
497
497
|
// scrolls to, and `aria-current` is what says "this is the one" to a screen reader.
|
|
498
498
|
data-playing={stageMark ? 'true' : undefined}
|
|
499
|
+
// How a returning table finds the last file shown — see `galleryReturn.ts`.
|
|
500
|
+
data-item-id={item.id}
|
|
499
501
|
aria-current={stageMark ? 'true' : undefined}
|
|
500
502
|
{...(previewSrc
|
|
501
503
|
? {
|
|
@@ -78,6 +78,7 @@ import {
|
|
|
78
78
|
} from '../hooks/useCheckboxSelection.js';
|
|
79
79
|
import { DenseGalleryDetail, DenseGalleryShell } from '../media/DenseGalleryShell.js';
|
|
80
80
|
import { CBGD_BARE_TILE_HEIGHT } from '../media/VirtualMediaGrid.js';
|
|
81
|
+
import { useGalleryReturn } from './galleryReturn.js';
|
|
81
82
|
import { useHlsSource } from '../media/hlsSource.js';
|
|
82
83
|
import {
|
|
83
84
|
isRecoverableFault,
|
|
@@ -552,12 +553,16 @@ interface TileDrag {
|
|
|
552
553
|
* `stopPropagation` in {@link SelectBox} buys.
|
|
553
554
|
*/
|
|
554
555
|
function TileShell({
|
|
556
|
+
id,
|
|
555
557
|
name,
|
|
556
558
|
selection,
|
|
557
559
|
drag,
|
|
558
560
|
stageMark,
|
|
559
561
|
children,
|
|
560
562
|
}: {
|
|
563
|
+
/** The item's id, carried as `data-item-id` — how a returning grid finds the last file shown
|
|
564
|
+
* (`galleryReturn.ts`). */
|
|
565
|
+
id: string;
|
|
561
566
|
name: string;
|
|
562
567
|
selection?: TileSelection;
|
|
563
568
|
drag?: TileDrag;
|
|
@@ -582,6 +587,7 @@ function TileShell({
|
|
|
582
587
|
// The hook the reveal below finds the tile by — see `MediaGallery`'s `revealPlaying`.
|
|
583
588
|
// An attribute rather than the class, so the query cannot be broken by a styling change.
|
|
584
589
|
data-playing={stageMark ? 'true' : undefined}
|
|
590
|
+
data-item-id={id}
|
|
585
591
|
aria-current={stageMark ? 'true' : undefined}
|
|
586
592
|
// 🔴 The DRAGGABLE element is this wrapper, not the tile inside it. Every tile branch
|
|
587
593
|
// is a <button>, and a draggable button is a browser-by-browser coin toss: some start
|
|
@@ -684,7 +690,7 @@ function GalleryTile({
|
|
|
684
690
|
* handlers, so this costs nothing and cannot change behavior anywhere else.
|
|
685
691
|
*/
|
|
686
692
|
return (
|
|
687
|
-
<TileShell name={item.name} selection={selection} drag={drag} stageMark={stageMark}>
|
|
693
|
+
<TileShell id={item.id} name={item.name} selection={selection} drag={drag} stageMark={stageMark}>
|
|
688
694
|
<RawGalleryTile
|
|
689
695
|
item={item}
|
|
690
696
|
cache={cache}
|
|
@@ -2021,6 +2027,17 @@ export function MediaGallery({
|
|
|
2021
2027
|
}, [checkedKey]);
|
|
2022
2028
|
|
|
2023
2029
|
const selected = selectedId ? (items.find((i) => i.id === selectedId) ?? null) : null;
|
|
2030
|
+
/** The browse view's root — how the return below finds the grid it puts back in place. */
|
|
2031
|
+
const browseRootRef = useRef<HTMLDivElement | null>(null);
|
|
2032
|
+
// Closing a file mounts a NEW grid; this puts it back where you were, then shows the last
|
|
2033
|
+
// file the stage showed. Task 2255 — see `galleryReturn.ts`.
|
|
2034
|
+
useGalleryReturn({
|
|
2035
|
+
rootRef: browseRootRef,
|
|
2036
|
+
browsing: selected === null,
|
|
2037
|
+
viewMode,
|
|
2038
|
+
shownId: selected?.id ?? null,
|
|
2039
|
+
displayIds,
|
|
2040
|
+
});
|
|
2024
2041
|
const select = (item: MediaGalleryItem | null) => {
|
|
2025
2042
|
// Only move our own state when we own it; a controlled consumer decides for itself what
|
|
2026
2043
|
// the notification means.
|
|
@@ -3164,6 +3181,7 @@ export function MediaGallery({
|
|
|
3164
3181
|
{capabilityDialogs}
|
|
3165
3182
|
<DenseGalleryShell<MediaGalleryOrder>
|
|
3166
3183
|
{...(tileCaptions ? {} : { rowExtraHeight: CBGD_BARE_TILE_HEIGHT })}
|
|
3184
|
+
rootRef={browseRootRef}
|
|
3167
3185
|
title={title}
|
|
3168
3186
|
order={{
|
|
3169
3187
|
value: order,
|