cursedbelt 6.13.2 → 6.15.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/Button.d.ts +11 -1
- package/dist/react/components/Button.d.ts.map +1 -1
- package/dist/react/components/Button.js +4 -3
- package/dist/react/components/Button.js.map +1 -1
- package/dist/react/components/ControlPanel.d.ts +2 -1
- package/dist/react/components/ControlPanel.d.ts.map +1 -1
- package/dist/react/components/ControlPanel.js +4 -3
- package/dist/react/components/ControlPanel.js.map +1 -1
- package/dist/react/components/FieldGrid.d.ts +23 -1
- package/dist/react/components/FieldGrid.d.ts.map +1 -1
- package/dist/react/components/FieldGrid.js +26 -4
- package/dist/react/components/FieldGrid.js.map +1 -1
- package/dist/react/components/SliderField.d.ts.map +1 -1
- package/dist/react/components/SliderField.js +8 -2
- package/dist/react/components/SliderField.js.map +1 -1
- package/dist/react/hooks/useIntersectionObserver.d.ts +23 -0
- package/dist/react/{media → hooks}/useIntersectionObserver.d.ts.map +1 -1
- package/dist/react/{media → hooks}/useIntersectionObserver.js +9 -4
- package/dist/react/hooks/useIntersectionObserver.js.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/media/MediaCatalogueViewer.js +1 -1
- package/dist/react/media/MediaCatalogueViewer.js.map +1 -1
- package/dist/react/media/index.d.ts +1 -1
- package/dist/react/media/index.d.ts.map +1 -1
- package/dist/react/media/index.js +1 -1
- package/dist/react/media/index.js.map +1 -1
- package/dist/react/workspace-shell/PlaceHeader.d.ts +5 -1
- package/dist/react/workspace-shell/PlaceHeader.d.ts.map +1 -1
- package/dist/react/workspace-shell/PlaceHeader.js.map +1 -1
- package/dist/styles-areas/core.css +3 -3
- package/dist/styles-utilities.css +11 -0
- package/dist/testing/designAudit.d.ts.map +1 -1
- package/dist/testing/designAudit.js +26 -1
- package/dist/testing/designAudit.js.map +1 -1
- package/package.json +8 -2
- package/src/react/components/Button.spec.tsx +16 -0
- package/src/react/components/Button.tsx +20 -2
- package/src/react/components/ControlPanel.tsx +5 -4
- package/src/react/components/FieldGrid.tsx +41 -3
- package/src/react/components/SliderField.tsx +8 -2
- package/src/react/components/SliderField.valueColumn.spec.tsx +73 -0
- package/src/react/hooks/useIntersectionObserver.spec.tsx +107 -0
- package/src/react/{media → hooks}/useIntersectionObserver.ts +11 -6
- package/src/react/index.ts +4 -0
- package/src/react/media/MediaCatalogueViewer.tsx +1 -1
- package/src/react/media/index.ts +1 -1
- package/src/react/workspace-shell/PlaceHeader.tsx +5 -1
- package/src/styles-areas/core.css +3 -3
- package/src/styles-utilities.css +11 -0
- package/src/testing/designAudit.ts +22 -1
- package/dist/react/media/useIntersectionObserver.d.ts +0 -18
- package/dist/react/media/useIntersectionObserver.js.map +0 -1
|
@@ -224,6 +224,16 @@ export interface ButtonProps
|
|
|
224
224
|
* Came from desk's own Button (forge task 2410), which had carried it since its file 80.
|
|
225
225
|
*/
|
|
226
226
|
unavailableReason?: string;
|
|
227
|
+
/**
|
|
228
|
+
* Below `sm` (a phone) the button is its icon alone: the words in `children` stay in the
|
|
229
|
+
* accessible name (sr-only) and the tooltip, and the hint comes on a hold as an icon button's
|
|
230
|
+
* does. For a labeled action in a place header, whose row is a phone's narrowest: the
|
|
231
|
+
* header's actions never shrink, so two labeled buttons left games' Chess reading "CHE…"
|
|
232
|
+
* at 375px (forge task 5451; `auditDesign`'s NAV-11 names the actions that took the room).
|
|
233
|
+
* Give it a `leftIcon` (or an icon in `children`) — without one there is nothing left to see.
|
|
234
|
+
* A count beside the words (a `Badge`) belongs in `leftIcon`'s place or outside the button.
|
|
235
|
+
*/
|
|
236
|
+
iconOnlyBelow?: 'sm';
|
|
227
237
|
/** How long the post-completion checkmark flash shows (ms). Default 1200. */
|
|
228
238
|
resetMs?: number;
|
|
229
239
|
children?: ReactNode;
|
|
@@ -274,6 +284,7 @@ export function Button({
|
|
|
274
284
|
onClick,
|
|
275
285
|
onKeyDown,
|
|
276
286
|
unavailableReason,
|
|
287
|
+
iconOnlyBelow,
|
|
277
288
|
...props
|
|
278
289
|
}: ButtonProps) {
|
|
279
290
|
const classes = cn(buttonVariants({ variant, size }), className);
|
|
@@ -363,13 +374,20 @@ export function Button({
|
|
|
363
374
|
{/* Label stays mounted (visibility:hidden, not display:none) so width never changes. */}
|
|
364
375
|
<span className={cn('contents', (isLoading || justSucceeded) && 'invisible')}>
|
|
365
376
|
{leftIcon}
|
|
366
|
-
{children
|
|
377
|
+
{iconOnlyBelow && children != null && children !== false ? (
|
|
378
|
+
<span data-cb-button-words='' className='max-sm:sr-only'>
|
|
379
|
+
{children}
|
|
380
|
+
</span>
|
|
381
|
+
) : (
|
|
382
|
+
children
|
|
383
|
+
)}
|
|
367
384
|
</span>
|
|
368
385
|
</button>
|
|
369
386
|
);
|
|
370
387
|
|
|
371
388
|
// An icon-only button's tooltip is its only label, so a phone gets it on a hold (CPY-4).
|
|
372
|
-
|
|
389
|
+
// `iconOnlyBelow` is icon-only exactly where touch is likeliest, so it takes the same hold.
|
|
390
|
+
const touchHint = tooltipMobile ?? ((typeof size === 'string' && size.startsWith('icon')) || iconOnlyBelow ? 'press' : undefined);
|
|
373
391
|
|
|
374
392
|
// The single "button with a tooltip" seam: wrap once, here, so no call site re-implements it.
|
|
375
393
|
// `multiline`: a hint that is a sentence ("Nothing to restore — the trash is empty") wraps
|
|
@@ -2,7 +2,7 @@ import type { CSSProperties, ReactNode } from 'react';
|
|
|
2
2
|
import { useMediaQuery } from '../hooks/useMediaQuery.js';
|
|
3
3
|
import { cn } from '../lib/cn.js';
|
|
4
4
|
import { Collapsible } from './Collapsible.js';
|
|
5
|
-
import { FieldGrid, type FieldGridProps } from './FieldGrid.js';
|
|
5
|
+
import { FieldGrid, type FieldGridProps, SliderValueColumnScope } from './FieldGrid.js';
|
|
6
6
|
|
|
7
7
|
/** Below this a panel's columns would be squeezed past use, so they stack as accordions (FRM-17). */
|
|
8
8
|
const PHONE_QUERY = '(max-width: 639px)';
|
|
@@ -50,7 +50,8 @@ const COLUMN_MIN: Record<NonNullable<ControlPanelProps['columnMin']>, string> =
|
|
|
50
50
|
* boxes — whitespace and a 1px vertical rule between columns. Columns wrap whole, every column in
|
|
51
51
|
* a row is the same height and padding, and each group's fields share one label column. On a
|
|
52
52
|
* phone the groups become stacked accordions (the first open), so the canvas above stays in view
|
|
53
|
-
* and no column is squeezed past use.
|
|
53
|
+
* and no column is squeezed past use. Every slider in the panel shares one value column
|
|
54
|
+
* ({@link SliderValueColumnScope}), across its groups.
|
|
54
55
|
*/
|
|
55
56
|
export function ControlPanel({ title, actions, children, columnMin = 'md', className, ...rest }: ControlPanelProps) {
|
|
56
57
|
const phone = useMediaQuery(PHONE_QUERY);
|
|
@@ -70,7 +71,7 @@ export function ControlPanel({ title, actions, children, columnMin = 'md', class
|
|
|
70
71
|
) : null}
|
|
71
72
|
{phone ? (
|
|
72
73
|
<div className='flex flex-col divide-y divide-border' data-cb-control-panel-groups='' data-phone=''>
|
|
73
|
-
{children}
|
|
74
|
+
<SliderValueColumnScope>{children}</SliderValueColumnScope>
|
|
74
75
|
</div>
|
|
75
76
|
) : (
|
|
76
77
|
<div className='cb-control-panel-frame'>
|
|
@@ -79,7 +80,7 @@ export function ControlPanel({ title, actions, children, columnMin = 'md', class
|
|
|
79
80
|
data-cb-control-panel-groups=''
|
|
80
81
|
style={{ '--cb-panel-col-min': COLUMN_MIN[columnMin] } as CSSProperties}
|
|
81
82
|
>
|
|
82
|
-
{children}
|
|
83
|
+
<SliderValueColumnScope>{children}</SliderValueColumnScope>
|
|
83
84
|
</div>
|
|
84
85
|
</div>
|
|
85
86
|
)}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CSSProperties, createContext, type ReactNode, useContext } from 'react';
|
|
1
|
+
import { type CSSProperties, createContext, type ReactNode, useCallback, useContext, useMemo, useState } from 'react';
|
|
2
2
|
import { cn } from '../lib/cn.js';
|
|
3
3
|
|
|
4
4
|
export interface FieldGridProps {
|
|
@@ -25,13 +25,49 @@ const LabelWidthContext = createContext<NonNullable<FieldGridProps['labelWidth']
|
|
|
25
25
|
/** The enclosing FieldGrid's label width, or `null` outside one — SliderField sizes its narrow-grid threshold from it (forge task 2667). */
|
|
26
26
|
export const useFieldGridLabelWidth = () => useContext(LabelWidthContext);
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* The value column a panel's `SliderField`s share (forge task 5550). Each slider measures its own
|
|
30
|
+
* longest readout; one that needs the wide box registers here, and while any does, every slider in
|
|
31
|
+
* the scope draws the wide box — so a `1.00×` row and an `Auto 2×` row end their tracks on one edge.
|
|
32
|
+
*/
|
|
33
|
+
export interface SliderValueColumn {
|
|
34
|
+
/** Some slider in the scope needs the wide value box. */
|
|
35
|
+
wide: boolean;
|
|
36
|
+
/** A slider that needs the wide box calls this; the returned function takes it back. */
|
|
37
|
+
claimWide: () => () => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const ValueColumnContext = createContext<SliderValueColumn | null>(null);
|
|
41
|
+
|
|
42
|
+
/** The enclosing scope's shared value column, or `null` outside one — then a slider sizes its box alone. */
|
|
43
|
+
export const useSliderValueColumn = () => useContext(ValueColumnContext);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Opens a shared value column for the `SliderField`s inside it. `ControlPanel` opens one for the
|
|
47
|
+
* whole panel and `FieldGrid` for itself; an inner scope defers to the outer, so every group of
|
|
48
|
+
* one panel shares ONE column, not one per group.
|
|
49
|
+
*/
|
|
50
|
+
// no-attribute-forward: a context provider around its children, with no element of its own.
|
|
51
|
+
export function SliderValueColumnScope({ children }: { children: ReactNode }) {
|
|
52
|
+
const outer = useContext(ValueColumnContext);
|
|
53
|
+
const [claims, setClaims] = useState(0);
|
|
54
|
+
const claimWide = useCallback(() => {
|
|
55
|
+
setClaims((n) => n + 1);
|
|
56
|
+
return () => setClaims((n) => n - 1);
|
|
57
|
+
}, []);
|
|
58
|
+
const own = useMemo(() => ({ wide: claims > 0, claimWide }), [claims, claimWide]);
|
|
59
|
+
if (outer) return <>{children}</>;
|
|
60
|
+
return <ValueColumnContext.Provider value={own}>{children}</ValueColumnContext.Provider>;
|
|
61
|
+
}
|
|
62
|
+
|
|
28
63
|
/**
|
|
29
64
|
* A column of fields whose labels share ONE label column (FRM-1, FRM-2): every label shares a
|
|
30
65
|
* left edge, and every control shares its left edge, so a dense settings list or a control
|
|
31
66
|
* panel reads as one straight-edged table instead of a zig-zag. Put `Field layout="inline"`
|
|
32
67
|
* and `SliderField` inside it. Stacked labels (a plain `Stack` of `Field`s) stay the default
|
|
33
68
|
* for an ordinary form; reach for this only for a dense panel or a settings list. On a phone
|
|
34
|
-
* each row stacks its label over its control.
|
|
69
|
+
* each row stacks its label over its control. Its sliders share one value column too
|
|
70
|
+
* ({@link SliderValueColumnScope}), so their tracks end on one right edge.
|
|
35
71
|
*/
|
|
36
72
|
export function FieldGrid({ children, labelWidth = 'md', density = 'dense', className, ...rest }: FieldGridProps) {
|
|
37
73
|
return (
|
|
@@ -43,7 +79,9 @@ export function FieldGrid({ children, labelWidth = 'md', density = 'dense', clas
|
|
|
43
79
|
// A live custom property — the one track every row's label column reads.
|
|
44
80
|
style={{ '--cb-label-col': LABEL_COL[labelWidth] } as CSSProperties}
|
|
45
81
|
>
|
|
46
|
-
<LabelWidthContext.Provider value={labelWidth}>
|
|
82
|
+
<LabelWidthContext.Provider value={labelWidth}>
|
|
83
|
+
<SliderValueColumnScope>{children}</SliderValueColumnScope>
|
|
84
|
+
</LabelWidthContext.Provider>
|
|
47
85
|
</div>
|
|
48
86
|
);
|
|
49
87
|
}
|
|
@@ -4,7 +4,7 @@ import { useDebouncedCallback } from '../hooks/useDebouncedCallback.js';
|
|
|
4
4
|
import { cn } from '../lib/cn.js';
|
|
5
5
|
import { HELP_FOLD_CHARS } from '../lib/field.js';
|
|
6
6
|
import { Button } from './Button.js';
|
|
7
|
-
import { useFieldGridLabelWidth } from './FieldGrid.js';
|
|
7
|
+
import { useFieldGridLabelWidth, useSliderValueColumn } from './FieldGrid.js';
|
|
8
8
|
import { InfoHint } from './InfoHint.js';
|
|
9
9
|
import { Input } from './Input.js';
|
|
10
10
|
import { Slider } from './Slider.js';
|
|
@@ -260,7 +260,13 @@ export function SliderField({
|
|
|
260
260
|
return typeof r === 'string' || typeof r === 'number' ? String(r).length : 0;
|
|
261
261
|
}),
|
|
262
262
|
);
|
|
263
|
-
const
|
|
263
|
+
const ownWide = widest > WIDE_READOUT_CHARS;
|
|
264
|
+
// Inside a FieldGrid or ControlPanel the box is the scope's: any slider that needs the wide box
|
|
265
|
+
// widens every one, so the panel's tracks end on one edge (forge task 5550). Alone, its own.
|
|
266
|
+
const column = useSliderValueColumn();
|
|
267
|
+
const claimWide = column?.claimWide;
|
|
268
|
+
useLayoutEffect(() => (ownWide && claimWide ? claimWide() : undefined), [ownWide, claimWide]);
|
|
269
|
+
const wide = ownWide || (column?.wide ?? false);
|
|
264
270
|
const gridLabel = useFieldGridLabelWidth();
|
|
265
271
|
const folds = typeof hint === 'string' && hint.length > HELP_FOLD_CHARS;
|
|
266
272
|
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
2
|
+
import { cleanup, render } from '@testing-library/react';
|
|
3
|
+
import { ControlGroup, ControlPanel } from './ControlPanel.js';
|
|
4
|
+
import { FieldGrid } from './FieldGrid.js';
|
|
5
|
+
import { SliderField } from './SliderField.js';
|
|
6
|
+
|
|
7
|
+
afterEach(cleanup);
|
|
8
|
+
|
|
9
|
+
// Forge task 5550: patterns' Controls inspector drew "Auto 2×" and "133 iter" in an 8rem box and
|
|
10
|
+
// "1.00×" in a 5rem one, so the Shape group's tracks stopped 3rem short of View's and Motion's. A
|
|
11
|
+
// panel's sliders share ONE value column: any slider whose readout needs the wide box widens all.
|
|
12
|
+
const times = (v: number) => `${v.toFixed(2)}×`;
|
|
13
|
+
const iter = (v: number) => `${v} iter`;
|
|
14
|
+
const Warp = () => <SliderField label='Text warp' value={1} min={0} max={4} step={0.01} formatValue={times} />;
|
|
15
|
+
const Detail = () => <SliderField label='Detail' value={133} min={10} max={500} step={1} formatValue={iter} />;
|
|
16
|
+
|
|
17
|
+
const boxes = (root: HTMLElement) => [...root.querySelectorAll<HTMLInputElement>('[data-cb-slider-value]')];
|
|
18
|
+
const widths = (root: HTMLElement) => boxes(root).map((b) => (b.className.includes('w-32') ? 'wide' : 'narrow'));
|
|
19
|
+
const fits = (root: HTMLElement) => [...root.querySelectorAll('.cb-slider-row')].map((r) => r.getAttribute('data-cb-slider-fit'));
|
|
20
|
+
|
|
21
|
+
describe('SliderField value column', () => {
|
|
22
|
+
test('one group: a 1.00× slider takes the wide box a 133 iter slider needs, and the wide stack threshold', () => {
|
|
23
|
+
const { container } = render(
|
|
24
|
+
<ControlGroup title='Shape' labelWidth='sm'>
|
|
25
|
+
<Warp />
|
|
26
|
+
<Detail />
|
|
27
|
+
</ControlGroup>,
|
|
28
|
+
);
|
|
29
|
+
expect(widths(container)).toEqual(['wide', 'wide']);
|
|
30
|
+
expect(fits(container)).toEqual(['22.5', '22.5']);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('one panel: every group shares the column, not one column per group', () => {
|
|
34
|
+
const { container } = render(
|
|
35
|
+
<ControlPanel title='Pattern'>
|
|
36
|
+
<ControlGroup title='Shape' labelWidth='sm'>
|
|
37
|
+
<Detail />
|
|
38
|
+
</ControlGroup>
|
|
39
|
+
<ControlGroup title='View' labelWidth='sm'>
|
|
40
|
+
<Warp />
|
|
41
|
+
</ControlGroup>
|
|
42
|
+
</ControlPanel>,
|
|
43
|
+
);
|
|
44
|
+
expect(widths(container)).toEqual(['wide', 'wide']);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('a grid of short readouts keeps the narrow box, and loses the wide one when its wide slider goes', () => {
|
|
48
|
+
const { container, rerender } = render(
|
|
49
|
+
<FieldGrid>
|
|
50
|
+
<Warp />
|
|
51
|
+
<Detail />
|
|
52
|
+
</FieldGrid>,
|
|
53
|
+
);
|
|
54
|
+
expect(widths(container)).toEqual(['wide', 'wide']);
|
|
55
|
+
rerender(
|
|
56
|
+
<FieldGrid>
|
|
57
|
+
<Warp />
|
|
58
|
+
</FieldGrid>,
|
|
59
|
+
);
|
|
60
|
+
expect(widths(container)).toEqual(['narrow']);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('outside a grid each slider sizes its own box', () => {
|
|
64
|
+
const { container } = render(
|
|
65
|
+
<div>
|
|
66
|
+
<Warp />
|
|
67
|
+
<Detail />
|
|
68
|
+
</div>,
|
|
69
|
+
);
|
|
70
|
+
expect(widths(container)).toEqual(['narrow', 'wide']);
|
|
71
|
+
expect(fits(container)).toEqual([null, null]);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { useIntersectionObserver } from './useIntersectionObserver.js';
|
|
4
|
+
|
|
5
|
+
/** Every observer the hook built, so a test can say "it came into view". */
|
|
6
|
+
interface FakeObserver {
|
|
7
|
+
callback: IntersectionObserverCallback;
|
|
8
|
+
options: IntersectionObserverInit | undefined;
|
|
9
|
+
observed: Element[];
|
|
10
|
+
disconnected: boolean;
|
|
11
|
+
}
|
|
12
|
+
let built: FakeObserver[] = [];
|
|
13
|
+
const real = globalThis.IntersectionObserver;
|
|
14
|
+
|
|
15
|
+
function installFake(): void {
|
|
16
|
+
built = [];
|
|
17
|
+
globalThis.IntersectionObserver = class {
|
|
18
|
+
readonly me: FakeObserver;
|
|
19
|
+
constructor(callback: IntersectionObserverCallback, options?: IntersectionObserverInit) {
|
|
20
|
+
this.me = { callback, options, observed: [], disconnected: false };
|
|
21
|
+
built.push(this.me);
|
|
22
|
+
}
|
|
23
|
+
observe(el: Element): void {
|
|
24
|
+
this.me.observed.push(el);
|
|
25
|
+
}
|
|
26
|
+
disconnect(): void {
|
|
27
|
+
this.me.disconnected = true;
|
|
28
|
+
}
|
|
29
|
+
} as unknown as typeof IntersectionObserver;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function enter(observer: FakeObserver, isIntersecting: boolean): void {
|
|
33
|
+
const target = observer.observed[0] as Element;
|
|
34
|
+
observer.callback([{ isIntersecting, target } as IntersectionObserverEntry], observer as unknown as IntersectionObserver);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function Sentinel({ onIntersect, enabled }: { onIntersect: () => void; enabled: boolean }) {
|
|
38
|
+
const ref = useIntersectionObserver({ onIntersect, enabled, rootMargin: '600px' });
|
|
39
|
+
return <div data-testid='sentinel' ref={ref} />;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function NearLink({ onIntersect }: { onIntersect: () => void }) {
|
|
43
|
+
// The element type is the caller's: an anchor that loads its picture once it is near.
|
|
44
|
+
const ref = useIntersectionObserver<HTMLAnchorElement>({ onIntersect, rootMargin: '400px 0px' });
|
|
45
|
+
return (
|
|
46
|
+
<a href='#x' ref={ref}>
|
|
47
|
+
Open
|
|
48
|
+
</a>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
globalThis.IntersectionObserver = real;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/** Forge task 5497: the endless-feed trigger family and photos had each re-stated. */
|
|
57
|
+
describe('useIntersectionObserver', () => {
|
|
58
|
+
test('observes the sentinel with its rootMargin and fires as it comes into view', () => {
|
|
59
|
+
installFake();
|
|
60
|
+
let fired = 0;
|
|
61
|
+
const view = render(<Sentinel enabled onIntersect={() => fired++} />);
|
|
62
|
+
expect(built).toHaveLength(1);
|
|
63
|
+
const observer = built[0] as FakeObserver;
|
|
64
|
+
expect(observer.observed[0]).toBe(view.getByTestId('sentinel'));
|
|
65
|
+
expect(observer.options?.rootMargin).toBe('600px');
|
|
66
|
+
enter(observer, false);
|
|
67
|
+
expect(fired).toBe(0);
|
|
68
|
+
enter(observer, true);
|
|
69
|
+
expect(fired).toBe(1);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('a disabled sentinel builds no observer, and enabling it arms one', () => {
|
|
73
|
+
installFake();
|
|
74
|
+
let fired = 0;
|
|
75
|
+
const view = render(<Sentinel enabled={false} onIntersect={() => fired++} />);
|
|
76
|
+
expect(built).toHaveLength(0);
|
|
77
|
+
view.rerender(<Sentinel enabled onIntersect={() => fired++} />);
|
|
78
|
+
expect(built).toHaveLength(1);
|
|
79
|
+
view.rerender(<Sentinel enabled={false} onIntersect={() => fired++} />);
|
|
80
|
+
expect((built[0] as FakeObserver).disconnected).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('the latest onIntersect is called without rebuilding the observer', () => {
|
|
84
|
+
installFake();
|
|
85
|
+
const calls: string[] = [];
|
|
86
|
+
const view = render(<Sentinel enabled onIntersect={() => calls.push('first')} />);
|
|
87
|
+
view.rerender(<Sentinel enabled onIntersect={() => calls.push('second')} />);
|
|
88
|
+
expect(built).toHaveLength(1);
|
|
89
|
+
enter(built[0] as FakeObserver, true);
|
|
90
|
+
expect(calls).toEqual(['second']);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('the ref fits any element type', () => {
|
|
94
|
+
installFake();
|
|
95
|
+
render(<NearLink onIntersect={() => undefined} />);
|
|
96
|
+
expect((built[0] as FakeObserver).observed[0]?.tagName).toBe('A');
|
|
97
|
+
expect((built[0] as FakeObserver).options?.rootMargin).toBe('400px 0px');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('a browser with no IntersectionObserver renders and never fires', () => {
|
|
101
|
+
// @ts-expect-error — the environment this guards is one without it.
|
|
102
|
+
globalThis.IntersectionObserver = undefined;
|
|
103
|
+
let fired = 0;
|
|
104
|
+
expect(() => render(<Sentinel enabled onIntersect={() => fired++} />)).not.toThrow();
|
|
105
|
+
expect(fired).toBe(0);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -12,18 +12,23 @@ export interface UseIntersectionObserverOptions {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Minimal IntersectionObserver hook for infinite-load sentinels. Returns a
|
|
16
|
-
* on a
|
|
17
|
-
*
|
|
18
|
-
* disabled viewer never fires and re-enabling re-arms it.
|
|
15
|
+
* Minimal IntersectionObserver hook for infinite-load sentinels and near-view loading. Returns a
|
|
16
|
+
* ref to put on a sentinel after the last item (or on the element itself); `onIntersect` fires
|
|
17
|
+
* when it comes within `rootMargin` of view. The observer is torn down + rebuilt when
|
|
18
|
+
* `enabled`/options change, so a disabled viewer never fires and re-enabling re-arms it.
|
|
19
|
+
*
|
|
20
|
+
* Its own light subpath, `cursedbelt/react/intersection-observer`, so an app without the media
|
|
21
|
+
* area's album and lightbox packages reaches it (the `./react/media` index resolves whole). With
|
|
22
|
+
* no `IntersectionObserver` in the browser it never fires: pair a sentinel with a button that
|
|
23
|
+
* asks for the same thing.
|
|
19
24
|
*/
|
|
20
|
-
export function useIntersectionObserver({
|
|
25
|
+
export function useIntersectionObserver<T extends Element = HTMLDivElement>({
|
|
21
26
|
onIntersect,
|
|
22
27
|
enabled = true,
|
|
23
28
|
rootMargin = '200px',
|
|
24
29
|
root = null,
|
|
25
30
|
}: UseIntersectionObserverOptions) {
|
|
26
|
-
const targetRef = useRef<
|
|
31
|
+
const targetRef = useRef<T | null>(null);
|
|
27
32
|
// Keep the latest callback without re-creating the observer each render.
|
|
28
33
|
const cb = useRef(onIntersect);
|
|
29
34
|
cb.current = onIntersect;
|
package/src/react/index.ts
CHANGED
|
@@ -903,6 +903,10 @@ export {
|
|
|
903
903
|
type UseKeepAwakeOptions,
|
|
904
904
|
type UseKeepAwakeResult,
|
|
905
905
|
} from './keep-awake/index.js';
|
|
906
|
+
export {
|
|
907
|
+
useIntersectionObserver,
|
|
908
|
+
type UseIntersectionObserverOptions,
|
|
909
|
+
} from './hooks/useIntersectionObserver.js';
|
|
906
910
|
export { useMediaQuery } from './hooks/useMediaQuery.js';
|
|
907
911
|
export { type ModifierKey, useModifierKey } from './hooks/useModifierKey.js';
|
|
908
912
|
export { useOnlineStatus } from './hooks/useOnlineStatus.js';
|
|
@@ -8,7 +8,7 @@ import { MediaCell } from './MediaCell.js';
|
|
|
8
8
|
import { MediaLightbox } from './MediaLightbox.js';
|
|
9
9
|
import { type MediaPhoto, mediaItemsToPhotos, mediaItemsToSlides } from './mediaPhoto.js';
|
|
10
10
|
import type { MediaCatalogueViewerProps } from './types.js';
|
|
11
|
-
import { useIntersectionObserver } from '
|
|
11
|
+
import { useIntersectionObserver } from '../hooks/useIntersectionObserver.js';
|
|
12
12
|
import { VirtualizedRows } from './VirtualizedRows.js';
|
|
13
13
|
|
|
14
14
|
// Stable keys for the loading skeletons (no array-index keys).
|
package/src/react/media/index.ts
CHANGED
|
@@ -157,7 +157,7 @@ export type {
|
|
|
157
157
|
VideoTrimmerProps,
|
|
158
158
|
} from './types.js';
|
|
159
159
|
export { type UseAudioPeaksOptions, useAudioPeaks } from './useAudioPeaks.js';
|
|
160
|
-
export { useIntersectionObserver } from '
|
|
160
|
+
export { useIntersectionObserver } from '../hooks/useIntersectionObserver.js';
|
|
161
161
|
export { useObjectUrl } from './useObjectUrl.js';
|
|
162
162
|
// Attaching an adaptive ladder to a bare `<video>` — native HLS first, hls.js second, the
|
|
163
163
|
// progressive remux always. Exported because three surfaces in the fleet drive a plain
|
|
@@ -32,7 +32,11 @@ export interface PlaceHeaderProps extends Omit<ComponentPropsWithoutRef<'header'
|
|
|
32
32
|
meta?: ReactNode;
|
|
33
33
|
/** What the place is for, behind the `?` beside its name (NAV-11: never a subtitle row). */
|
|
34
34
|
hint?: ReactNode;
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* The place's actions, at the right; at most one primary. They never shrink, so on a phone a labeled action takes
|
|
37
|
+
* the name's room: pass each one Button's `iconOnlyBelow='sm'` (its words stay its accessible name and its tooltip).
|
|
38
|
+
* `auditDesign`'s NAV-11 reds a name crowded under four characters and names the actions that took it (forge task 5451).
|
|
39
|
+
*/
|
|
36
40
|
actions?: ReactNode;
|
|
37
41
|
/** Before the name: a Back that leads out of a page the place opened (Settings on a phone). */
|
|
38
42
|
lead?: ReactNode;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* after an app's responsive variant (task 2124). An app that imports every area gets exactly
|
|
16
16
|
* what `cursedbelt/styles-utilities.css` emits — proved rule by rule in
|
|
17
17
|
* src/stylesAreas.spec.ts, which is also what fails when this file is stale.
|
|
18
|
-
*
|
|
18
|
+
* 1015 candidate(s).
|
|
19
19
|
*
|
|
20
20
|
* Written by scripts/generateAreaStyles.ts (`bun run styles:areas`), which
|
|
21
21
|
* `bun run build` runs. The map of what is in which area, and why the areas are
|
|
@@ -156,8 +156,8 @@
|
|
|
156
156
|
@source inline("max-sm:border-x-0 max-sm:bottom-0 max-sm:data-[state=closed]:slide-out-to-bottom");
|
|
157
157
|
@source inline("max-sm:data-[state=open]:slide-in-from-bottom max-sm:h-dvh max-sm:hidden max-sm:inset-x-0");
|
|
158
158
|
@source inline("max-sm:max-h-[var(--sheet-h-phone)] max-sm:max-h-dvh max-sm:max-w-none max-sm:pt-6");
|
|
159
|
-
@source inline("max-sm:rounded-b-none max-sm:rounded-none max-sm:rounded-t-2xl max-sm:
|
|
160
|
-
@source inline("max-w-(--radix-popover-content-available-width) max-w-2xl max-w-40 max-w-6xl");
|
|
159
|
+
@source inline("max-sm:rounded-b-none max-sm:rounded-none max-sm:rounded-t-2xl max-sm:sr-only max-sm:touch-none");
|
|
160
|
+
@source inline("max-sm:w-full max-w-(--radix-popover-content-available-width) max-w-2xl max-w-40 max-w-6xl");
|
|
161
161
|
@source inline("max-w-[calc(100vw-2rem)] max-w-[var(--modal-w-sm)] max-w-[var(--page-w-dashboard)]");
|
|
162
162
|
@source inline("max-w-[var(--page-w-fluid)] max-w-[var(--page-w-form)] max-w-[var(--page-w-wide)]");
|
|
163
163
|
@source inline("max-w-[var(--reading-width)] max-w-full max-w-full! max-w-lg max-w-md max-w-none max-w-sm");
|
package/src/styles-utilities.css
CHANGED
|
@@ -4860,6 +4860,17 @@
|
|
|
4860
4860
|
}
|
|
4861
4861
|
}
|
|
4862
4862
|
@media (width < 40rem) {
|
|
4863
|
+
.max-sm\:sr-only {
|
|
4864
|
+
position: absolute;
|
|
4865
|
+
width: 1px;
|
|
4866
|
+
height: 1px;
|
|
4867
|
+
padding: 0;
|
|
4868
|
+
margin: -1px;
|
|
4869
|
+
overflow: hidden;
|
|
4870
|
+
clip-path: inset(50%);
|
|
4871
|
+
white-space: nowrap;
|
|
4872
|
+
border-width: 0;
|
|
4873
|
+
}
|
|
4863
4874
|
.max-sm\:inset-x-0 {
|
|
4864
4875
|
inset-inline: 0px;
|
|
4865
4876
|
}
|
|
@@ -97,7 +97,7 @@ export const DESIGN_RULE_TITLES: Record<DesignRuleId, string> = {
|
|
|
97
97
|
'DAT-16': 'a non-value (`[object Object]`, `undefined`, `NaN`, `null`, `Invalid Date`) on screen',
|
|
98
98
|
'LAY-13': 'a tap target under 44px on a coarse pointer',
|
|
99
99
|
'FND-4': 'controls in one row with different heights',
|
|
100
|
-
'NAV-11': 'a page without exactly one visible h1,
|
|
100
|
+
'NAV-11': 'a page without exactly one visible h1, a place header whose `?` sits among its actions instead of beside its name, or a place name its actions crowd under four characters',
|
|
101
101
|
'FRM-12': 'more than one primary button in a view',
|
|
102
102
|
'NAV-2': 'a place nobody can name: a rail icon without its name, tooltip or key, a phone-bar tab without its word, or a labeled nav item with no text',
|
|
103
103
|
'NAV-15': 'a top bar above a page that already has a sidebar, at ≥768px — the places belong in the sidebar',
|
|
@@ -823,6 +823,27 @@ export function designProbe({ rules, allowProse, specimens }: ProbeArgs): Design
|
|
|
823
823
|
const name = trigger.closest('[data-cb-place-header]')?.querySelector('h1')?.textContent ?? '';
|
|
824
824
|
push('NAV-11', trigger, `"${short(name, 30)}"'s ? sits among its header's actions — pass it as PlaceHeader's hint`);
|
|
825
825
|
}
|
|
826
|
+
// A place's name its header's actions crowd out (forge task 5451). PlaceHeader's h1 truncates and its actions never
|
|
827
|
+
// shrink, so two labeled buttons on a phone left games' Chess reading "CHE…" at 375px, or a 0px h1 that the phone
|
|
828
|
+
// exception above still counted as a title. Read even when it draws 0px wide: that is the worst case, not a hidden one.
|
|
829
|
+
for (const h1 of document.querySelectorAll('[data-cb-place-header] h1')) {
|
|
830
|
+
if (h1.closest('[hidden], [aria-hidden="true"], [inert]') || getComputedStyle(h1).display === 'none') continue;
|
|
831
|
+
const header = h1.closest('[data-cb-place-header]') as HTMLElement;
|
|
832
|
+
if (!drawn(header)) continue;
|
|
833
|
+
const name = (h1.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
834
|
+
const full = h1.scrollWidth;
|
|
835
|
+
if (!name || full <= 0) continue;
|
|
836
|
+
const seen = h1.clientWidth;
|
|
837
|
+
// How many of its characters the reader sees, at the name's own average glyph width.
|
|
838
|
+
const chars = seen / (full / name.length);
|
|
839
|
+
if (seen >= full - 1 || chars >= Math.min(name.length, 4)) continue;
|
|
840
|
+
const labeled = Array.from(header.querySelectorAll('[data-cb-place-actions] :is(button, a, [role="button"])'))
|
|
841
|
+
.filter(shown)
|
|
842
|
+
.map((el) => ((el as HTMLElement).innerText ?? '').replace(/\s+/g, ' ').trim())
|
|
843
|
+
.filter(Boolean);
|
|
844
|
+
const took = labeled.length ? `its labeled actions take the room (${labeled.map((t) => `"${short(t, 20)}"`).join(', ')}) — Button's iconOnlyBelow="sm" keeps each one's name for a screen reader` : 'the row beside it takes the room';
|
|
845
|
+
push('NAV-11', h1, `"${short(name, 30)}" shows ${Math.max(0, Math.floor(chars))} of its ${name.length} characters at ${window.innerWidth}px: ${took}`);
|
|
846
|
+
}
|
|
826
847
|
|
|
827
848
|
// ── FRM-12 · one primary per view · IA-5 · two charts per view ──────────────
|
|
828
849
|
// A view is the nearest `[data-cb-view]` or dialog; otherwise the main region, else the page.
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export interface UseIntersectionObserverOptions {
|
|
2
|
-
/** Called when the target enters view (armed → fires once per (re-)entry). */
|
|
3
|
-
onIntersect: () => void;
|
|
4
|
-
/** Only observe while enabled (e.g. there is more to load and not already loading). */
|
|
5
|
-
enabled?: boolean;
|
|
6
|
-
/** Root margin — `'200px'` pre-fetches before the sentinel is on screen. */
|
|
7
|
-
rootMargin?: string;
|
|
8
|
-
/** Optional explicit scroll root (defaults to the viewport). */
|
|
9
|
-
root?: Element | null;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Minimal IntersectionObserver hook for infinite-load sentinels. Returns a ref to put
|
|
13
|
-
* on a 1px sentinel element after the last item; `onIntersect` fires when it becomes
|
|
14
|
-
* visible. The observer is torn down + rebuilt when `enabled`/options change, so a
|
|
15
|
-
* disabled viewer never fires and re-enabling re-arms it.
|
|
16
|
-
*/
|
|
17
|
-
export declare function useIntersectionObserver({ onIntersect, enabled, rootMargin, root, }: UseIntersectionObserverOptions): import("react").RefObject<HTMLDivElement | null>;
|
|
18
|
-
//# sourceMappingURL=useIntersectionObserver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIntersectionObserver.js","sourceRoot":"","sources":["../../../src/react/media/useIntersectionObserver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAa1C;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,EACtC,WAAW,EACX,OAAO,GAAG,IAAI,EACd,UAAU,GAAG,OAAO,EACpB,IAAI,GAAG,IAAI,GACoB;IAC/B,MAAM,SAAS,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IACtD,yEAAyE;IACzE,MAAM,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IAC/B,EAAE,CAAC,OAAO,GAAG,WAAW,CAAC;IAEzB,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,EAAE,IAAI,CAAC,OAAO,IAAI,OAAO,oBAAoB,KAAK,WAAW;YAAE,OAAO;QAC3E,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CACvC,CAAC,OAAO,EAAE,EAAE;YACV,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;gBAC5B,IAAI,KAAK,CAAC,cAAc;oBAAE,EAAE,CAAC,OAAO,EAAE,CAAC;YACzC,CAAC;QACH,CAAC,EACD,EAAE,IAAI,EAAE,UAAU,EAAE,CACrB,CAAC;QACF,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACrB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;IAEhC,OAAO,SAAS,CAAC;AACnB,CAAC"}
|