Skip to content

Commit 918491f

Browse files
committed
chore(core): Core's internal touch entry re-exports what Lab's TabBar reads, and its strings join the catalog
Re-exports only, no new behavior: @astryxdesign/core/internal/touch adds the press tracker, the action-group tracker, the finger-scroll reader and the text-selection lock, none under a public factory's name. The names TabBar shares with other Lab components come from the base entry. Core's message catalog gains TabBar's three strings: the More tab's label, the search's Cancel button and a badged tab's name. They land ahead of the Lab component, so the Lab batches change only Lab. The entry stays outside the public API: no docs, no root re-export, and the @astryx/no-core-internal-import rule keeps it to Core and Lab. One type widens: useFingerScroll also takes a ref that holds a document. It already watched a document passed to it directly, so nothing runs differently. A component can then fill the ref from its own element and watch the page of the document that element is in.
1 parent 4e363d8 commit 918491f

6 files changed

Lines changed: 66 additions & 4 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[experimental] Core's internal `@astryxdesign/core/internal/touch` entry re-exports the press tracker, action-group tracker, finger-scroll reader and selection lock for Lab components. The finger-scroll reader also takes a ref that holds a document. Three tab-bar strings join Core's message catalog.
6+
7+
@vjeux

‎packages/core/locales/en.json‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,10 +931,22 @@
931931
"defaultMessage": "Maximum value",
932932
"description": "Accessible name of the upper thumb of a range Slider (two thumbs), announced together with the Slider's own label, for example \"Price range, Maximum value, 80\". Never shown on screen."
933933
},
934+
"@astryx.tabBar.badgedItem": {
935+
"defaultMessage": "{label}, {badge}",
936+
"description": "Screen-reader name of a bottom tab bar item that shows a badge (\"Library, 3\"). {label} is the tab's visible name; {badge} is the badge's count or its own label (\"3 unread\"). Translators may reorder the two or change the separator."
937+
},
934938
"@astryx.tabList.label": {
935939
"defaultMessage": "Tabs",
936940
"description": "Screen-reader-only fallback name for a horizontal tab bar. Plural noun; \"Tabs\" here = UI tab panels, not browser tabs or the Tab key."
937941
},
942+
"@astryx.tabBar.more": {
943+
"defaultMessage": "More",
944+
"description": "Label of the tab that collects a phone tab bar's sections past the fourth (iOS's More tab), and the name of the list of those sections it shows. One short word."
945+
},
946+
"@astryx.tabBar.cancelSearch": {
947+
"defaultMessage": "Cancel",
948+
"description": "Name of the button that ends search in a phone tab bar's search tab. The tab bar draws it over its search circle, beside the active field, as iOS draws its cancel button. One short word."
949+
},
938950
"@astryx.table.label": {
939951
"defaultMessage": "Table",
940952
"description": "Fallback screen-reader-only accessible name for a data-table region when the consumer provides none. Noun (\"a table\"), not the verb \"to table\"."

‎packages/core/src/gestures/__tests__/useFingerScroll.test.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ function Page() {
7676
return <p data-testid="row">row</p>;
7777
}
7878

79+
const pageByRef: {current: Document | null} = {current: null};
80+
const fillPageByRef = (element: HTMLElement | null) => {
81+
pageByRef.current = element?.ownerDocument ?? null;
82+
};
83+
84+
function PageByRef() {
85+
read = useFingerScroll(pageByRef);
86+
return (
87+
<p data-testid="row" ref={fillPageByRef}>
88+
row
89+
</p>
90+
);
91+
}
92+
7993
// A phone: the finger-scroll watch listens only where the primary pointer is
8094
// coarse.
8195
let restorePointer: () => void;
@@ -135,6 +149,16 @@ describe('useFingerScroll', () => {
135149
expect(read()).toBe(false);
136150
});
137151

152+
it('reads the page’s own scroll through a ref that an element’s ref fills with its document', () => {
153+
const {getByTestId} = render(<PageByRef />);
154+
touch('touchstart', getByTestId('row'), true);
155+
document.dispatchEvent(new Event('scroll'));
156+
expect(read()).toBe(true);
157+
touch('touchend', getByTestId('row'), false);
158+
document.dispatchEvent(new Event('scrollend'));
159+
expect(read()).toBe(false);
160+
});
161+
138162
it("follows the ref's node, and stops watching on unmount", () => {
139163
const {getByTestId, rerender, unmount} = render(<List />);
140164
rerender(<List other />);

‎packages/core/src/gestures/useFingerScroll.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ function documentOf(node: Element | Document): Document {
4545

4646
/**
4747
* Watch a scroller's finger scrolls. Pass a ref to a scrolling element, or
48-
* the document for the page's own scroll. Returns a reader, stable across
49-
* renders: `true` while the scroller's scroll is a finger's.
50-
* Internal: not exported from the package.
48+
* the document (or a ref that holds it) for the page's own scroll. Returns a
49+
* reader, stable across renders: `true` while the scroller's scroll is a
50+
* finger's.
51+
* Internal: outside Core, only `@astryxdesign/core/internal/touch` reaches it.
5152
*/
5253
export function useFingerScroll(
53-
scroller: RefObject<Element | null> | Document,
54+
scroller: RefObject<Element | Document | null> | Document,
5455
): () => boolean {
5556
/** The node the watch is on now, for the reader. */
5657
const watchedRef = useRef<Element | Document | null>(null);

‎packages/core/src/internal/touch.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ describe('internal/touch', () => {
7878
expect(entry).not.toHaveProperty('touchModule');
7979
});
8080

81+
it('re-exports the press tracker, the action-group tracker, the finger-scroll reader and the selection lock by name', async () => {
82+
const entry: Record<string, unknown> = await import('./touch');
83+
const modules: Record<string, Record<string, unknown>> = {
84+
useFingerScroll: await import('../gestures/useFingerScroll'),
85+
usePressTracker: await import('../gestures/usePressTracker'),
86+
createActionGroupTracker: await import('../hooks/actionGroupTracker'),
87+
lockSelection: await import('../utils/selectionLock'),
88+
};
89+
for (const [name, module] of Object.entries(modules)) {
90+
expect(entry[name], name).toBe(module[name]);
91+
}
92+
});
93+
8194
it('attaches no window or document listeners when it loads', async () => {
8295
vi.resetModules();
8396
const onWindow = vi.spyOn(window, 'addEventListener');

‎packages/core/src/internal/touch.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ export {LongPressGestureRecognizer} from '../gestures/LongPressGestureRecognizer
4141
export {PanGestureRecognizer} from '../gestures/PanGestureRecognizer';
4242
export {TapGestureRecognizer} from '../gestures/TapGestureRecognizer';
4343
export {DEFAULT_ENVIRONMENT} from '../gestures/types';
44+
export {useFingerScroll} from '../gestures/useFingerScroll';
4445
export {useGestureRecognizer} from '../gestures/useGestureRecognizer';
46+
export {usePressTracker} from '../gestures/usePressTracker';
47+
export {createActionGroupTracker} from '../hooks/actionGroupTracker';
48+
export type {ActionGroupTarget} from '../hooks/actionGroupTracker';
4549
export {isRtlElement} from '../hooks/isRtlElement';
4650
export {createMotionEngine} from '../motion/animator';
4751
export type {
@@ -55,5 +59,6 @@ export {cubicBezier} from '../motion/bezier';
5559
export {rubberBand} from '../motion/rubberBand';
5660
export {UIKIT_GESTURES} from '../motion/uikit/gestures';
5761
export {timing} from '../motion/uikit/timing';
62+
export {lockSelection} from '../utils/selectionLock';
5863
export {useTouchPresentation} from '../utils/touchPresentation';
5964
export {TOUCH_QUERY} from '../utils/touchQueries';

0 commit comments

Comments
 (0)