@hozo/behaviors 0.1.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/LICENSE +21 -0
- package/README.md +80 -0
- package/dist/dismissable-layer.d.ts +17 -0
- package/dist/dismissable-layer.d.ts.map +1 -0
- package/dist/dismissable-layer.js +67 -0
- package/dist/dismissable-layer.js.map +1 -0
- package/dist/dismissable-layer.native.d.ts +28 -0
- package/dist/dismissable-layer.native.d.ts.map +1 -0
- package/dist/dismissable-layer.native.js +38 -0
- package/dist/dismissable-layer.native.js.map +1 -0
- package/dist/floating-geometry.d.ts +63 -0
- package/dist/floating-geometry.d.ts.map +1 -0
- package/dist/floating-geometry.js +191 -0
- package/dist/floating-geometry.js.map +1 -0
- package/dist/floating-positioner.d.ts +24 -0
- package/dist/floating-positioner.d.ts.map +1 -0
- package/dist/floating-positioner.js +110 -0
- package/dist/floating-positioner.js.map +1 -0
- package/dist/floating-positioner.native.d.ts +43 -0
- package/dist/floating-positioner.native.d.ts.map +1 -0
- package/dist/floating-positioner.native.js +82 -0
- package/dist/floating-positioner.native.js.map +1 -0
- package/dist/focus-scope.d.ts +31 -0
- package/dist/focus-scope.d.ts.map +1 -0
- package/dist/focus-scope.js +96 -0
- package/dist/focus-scope.js.map +1 -0
- package/dist/focus-scope.native.d.ts +33 -0
- package/dist/focus-scope.native.d.ts.map +1 -0
- package/dist/focus-scope.native.js +25 -0
- package/dist/focus-scope.native.js.map +1 -0
- package/dist/hover-geometry.d.ts +64 -0
- package/dist/hover-geometry.d.ts.map +1 -0
- package/dist/hover-geometry.js +146 -0
- package/dist/hover-geometry.js.map +1 -0
- package/dist/hover-trigger.d.ts +64 -0
- package/dist/hover-trigger.d.ts.map +1 -0
- package/dist/hover-trigger.js +174 -0
- package/dist/hover-trigger.js.map +1 -0
- package/dist/hover-trigger.native.d.ts +45 -0
- package/dist/hover-trigger.native.d.ts.map +1 -0
- package/dist/hover-trigger.native.js +101 -0
- package/dist/hover-trigger.native.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/index.native.d.ts +12 -0
- package/dist/index.native.d.ts.map +1 -0
- package/dist/index.native.js +12 -0
- package/dist/index.native.js.map +1 -0
- package/dist/live-region.d.ts +19 -0
- package/dist/live-region.d.ts.map +1 -0
- package/dist/live-region.js +51 -0
- package/dist/live-region.js.map +1 -0
- package/dist/live-region.native.d.ts +31 -0
- package/dist/live-region.native.d.ts.map +1 -0
- package/dist/live-region.native.js +38 -0
- package/dist/live-region.native.js.map +1 -0
- package/dist/native.d.ts +5 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +4 -0
- package/dist/native.js.map +1 -0
- package/dist/portal.d.ts +26 -0
- package/dist/portal.d.ts.map +1 -0
- package/dist/portal.js +41 -0
- package/dist/portal.js.map +1 -0
- package/dist/portal.native.d.ts +44 -0
- package/dist/portal.native.d.ts.map +1 -0
- package/dist/portal.native.js +79 -0
- package/dist/portal.native.js.map +1 -0
- package/dist/roving-focus-rules.d.ts +13 -0
- package/dist/roving-focus-rules.d.ts.map +1 -0
- package/dist/roving-focus-rules.js +49 -0
- package/dist/roving-focus-rules.js.map +1 -0
- package/dist/roving-focus.d.ts +27 -0
- package/dist/roving-focus.d.ts.map +1 -0
- package/dist/roving-focus.js +52 -0
- package/dist/roving-focus.js.map +1 -0
- package/dist/roving-focus.native.d.ts +36 -0
- package/dist/roving-focus.native.d.ts.map +1 -0
- package/dist/roving-focus.native.js +28 -0
- package/dist/roving-focus.native.js.map +1 -0
- package/dist/text-child.d.ts +4 -0
- package/dist/text-child.d.ts.map +1 -0
- package/dist/text-child.js +17 -0
- package/dist/text-child.js.map +1 -0
- package/dist/text-child.native.d.ts +14 -0
- package/dist/text-child.native.d.ts.map +1 -0
- package/dist/text-child.native.js +42 -0
- package/dist/text-child.native.js.map +1 -0
- package/dist/typeahead.d.ts +36 -0
- package/dist/typeahead.d.ts.map +1 -0
- package/dist/typeahead.js +97 -0
- package/dist/typeahead.js.map +1 -0
- package/package.json +82 -0
- package/src/dismissable-layer.native.tsx +72 -0
- package/src/dismissable-layer.tsx +106 -0
- package/src/floating-geometry.ts +306 -0
- package/src/floating-positioner.native.tsx +155 -0
- package/src/floating-positioner.tsx +173 -0
- package/src/focus-scope.native.tsx +53 -0
- package/src/focus-scope.tsx +143 -0
- package/src/hover-geometry.ts +182 -0
- package/src/hover-trigger.native.tsx +179 -0
- package/src/hover-trigger.tsx +303 -0
- package/src/index.native.ts +77 -0
- package/src/index.ts +77 -0
- package/src/live-region.native.tsx +61 -0
- package/src/live-region.tsx +74 -0
- package/src/native.ts +15 -0
- package/src/portal.native.tsx +130 -0
- package/src/portal.tsx +68 -0
- package/src/roving-focus-rules.ts +79 -0
- package/src/roving-focus.native.tsx +81 -0
- package/src/roving-focus.tsx +118 -0
- package/src/text-child.native.tsx +44 -0
- package/src/text-child.ts +19 -0
- package/src/typeahead.ts +120 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.native.js","sourceRoot":"","sources":["../src/index.native.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAEjB,MAAM,+BAAgC,CAAA;AACvC,OAAO,EAIL,eAAe,EAGf,cAAc,GAGf,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,iCAAkC,CAAA;AACzC,OAAO,EAEL,UAAU,EAEV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,yBAA0B,CAAA;AACjC,OAAO,EACL,kBAAkB,EAElB,iBAAiB,EACjB,gBAAgB,GAGjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAGL,oBAAoB,EAIpB,eAAe,EACf,eAAe,GAChB,MAAM,2BAA4B,CAAA;AACnC,OAAO,EACL,UAAU,EAGV,WAAW,GACZ,MAAM,yBAA0B,CAAA;AACjC,OAAO,EACL,MAAM,EACN,UAAU,EAEV,cAAc,GACf,MAAM,oBAAqB,CAAA;AAC5B,OAAO,EACL,SAAS,EAET,gBAAgB,EAIhB,QAAQ,EACR,aAAa,GACd,MAAM,0BAA2B,CAAA;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAyB,CAAA;AAC1D,OAAO,EACL,cAAc,EACd,UAAU,EACV,WAAW,EACX,oBAAoB,EAEpB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
export type LiveRegionMode = 'polite' | 'assertive';
|
|
3
|
+
export interface LiveRegionProps {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
mode?: LiveRegionMode;
|
|
6
|
+
className?: string;
|
|
7
|
+
style?: CSSProperties;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Universal `<LiveRegion>` component for Web.
|
|
11
|
+
* Renders an accessible off-screen container that announces content changes to screen readers.
|
|
12
|
+
*/
|
|
13
|
+
export declare function LiveRegion({ children, mode, className, style }: LiveRegionProps): import("react").JSX.Element;
|
|
14
|
+
/**
|
|
15
|
+
* Imperative announcement hook for Web.
|
|
16
|
+
* Dynamically updates an internal live region to announce messages to screen readers.
|
|
17
|
+
*/
|
|
18
|
+
export declare function useAnnounce(): (message: string, mode?: LiveRegionMode) => void;
|
|
19
|
+
//# sourceMappingURL=live-region.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-region.d.ts","sourceRoot":"","sources":["../src/live-region.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAErD,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,WAAW,CAAA;AAEnD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,IAAI,CAAC,EAAE,cAAc,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAcD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAe,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,eAAe,+BAY1F;AAED;;;GAGG;AACH,wBAAgB,WAAW,cACR,MAAM,SAAQ,cAAc,UA2B9C"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
const visuallyHiddenStyle = {
|
|
3
|
+
position: 'absolute',
|
|
4
|
+
width: 1,
|
|
5
|
+
height: 1,
|
|
6
|
+
padding: 0,
|
|
7
|
+
margin: -1,
|
|
8
|
+
overflow: 'hidden',
|
|
9
|
+
clip: 'rect(0, 0, 0, 0)',
|
|
10
|
+
whiteSpace: 'nowrap',
|
|
11
|
+
borderWidth: 0,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Universal `<LiveRegion>` component for Web.
|
|
15
|
+
* Renders an accessible off-screen container that announces content changes to screen readers.
|
|
16
|
+
*/
|
|
17
|
+
export function LiveRegion({ children, mode = 'polite', className, style }) {
|
|
18
|
+
return (_jsx("div", { role: mode === 'assertive' ? 'alert' : 'status', "aria-live": mode, "aria-atomic": "true", className: className, style: { ...visuallyHiddenStyle, ...style }, children: children }));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Imperative announcement hook for Web.
|
|
22
|
+
* Dynamically updates an internal live region to announce messages to screen readers.
|
|
23
|
+
*/
|
|
24
|
+
export function useAnnounce() {
|
|
25
|
+
return (message, mode = 'polite') => {
|
|
26
|
+
if (typeof document === 'undefined')
|
|
27
|
+
return;
|
|
28
|
+
const id = '__hozo_live_announcer';
|
|
29
|
+
let container = document.getElementById(id);
|
|
30
|
+
if (!container) {
|
|
31
|
+
container = document.createElement('div');
|
|
32
|
+
container.id = id;
|
|
33
|
+
Object.assign(container.style, visuallyHiddenStyle);
|
|
34
|
+
document.body.appendChild(container);
|
|
35
|
+
}
|
|
36
|
+
const region = document.createElement('div');
|
|
37
|
+
region.setAttribute('role', mode === 'assertive' ? 'alert' : 'status');
|
|
38
|
+
region.setAttribute('aria-live', mode);
|
|
39
|
+
region.setAttribute('aria-atomic', 'true');
|
|
40
|
+
container.appendChild(region);
|
|
41
|
+
// Delay insertion slightly to trigger DOM mutation observers in assistive tech
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
region.textContent = message;
|
|
44
|
+
}, 50);
|
|
45
|
+
// Cleanup node after announcement has been picked up
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
region.remove();
|
|
48
|
+
}, 1000);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=live-region.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-region.js","sourceRoot":"","sources":["../src/live-region.tsx"],"names":[],"mappings":";AAWA,MAAM,mBAAmB,GAAkB;IACzC,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;IACV,MAAM,EAAE,CAAC,CAAC;IACV,QAAQ,EAAE,QAAQ;IAClB,IAAI,EAAE,kBAAkB;IACxB,UAAU,EAAE,QAAQ;IACpB,WAAW,EAAE,CAAC;CACf,CAAA;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,GAAG,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAmB;IACzF,OAAO,CACL,cACE,IAAI,EAAE,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,eACpC,IAAI,iBACH,MAAM,EAClB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,EAAE,GAAG,mBAAmB,EAAE,GAAG,KAAK,EAAE,YAE1C,QAAQ,GACL,CACP,CAAA;AACH,CAAC;AAED;;;GAGG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import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
export type LiveRegionMode = 'polite' | 'assertive';
|
|
4
|
+
export interface LiveRegionProps {
|
|
5
|
+
/**
|
|
6
|
+
* Tailwind classes, the same prop the Web half takes.
|
|
7
|
+
*
|
|
8
|
+
* On a tag the compiler lowers it is gone by runtime, replaced by a
|
|
9
|
+
* `StyleSheet` entry. Anywhere else it is carried and ignored here --
|
|
10
|
+
* this side has no CSS engine to resolve a class list against -- and
|
|
11
|
+
* the type still has to accept it, because an app is type-checked
|
|
12
|
+
* against the source the compiler reads rather than its output.
|
|
13
|
+
*/
|
|
14
|
+
className?: string;
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
mode?: LiveRegionMode;
|
|
17
|
+
style?: StyleProp<ViewStyle>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Universal `<LiveRegion>` component for React Native.
|
|
21
|
+
* Renders an off-screen/accessible container that instructs TalkBack/VoiceOver to announce updates.
|
|
22
|
+
*/
|
|
23
|
+
export declare function LiveRegion({ children, mode, style, ...props }: LiveRegionProps): React.FunctionComponentElement<Omit<import("react-native").ViewProps, "ref"> & {
|
|
24
|
+
ref?: React.Ref<import("react-native").ViewInstance> | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Imperative announcement hook for React Native.
|
|
28
|
+
* Calls `AccessibilityInfo.announceForAccessibility` directly.
|
|
29
|
+
*/
|
|
30
|
+
export declare function useAnnounce(): (message: string, _mode?: LiveRegionMode) => void;
|
|
31
|
+
//# sourceMappingURL=live-region.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-region.native.d.ts","sourceRoot":"","sources":["../src/live-region.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAC7C,OAAO,EAAqB,KAAK,SAAS,EAAc,KAAK,SAAS,EAAE,MAAM,cAAc,CAAA;AAE5F,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,WAAW,CAAA;AAEnD,MAAM,WAAW,eAAe;IAC9B;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,IAAI,CAAC,EAAE,cAAc,CAAA;IACrB,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;CAC7B;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAe,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,eAAe;;GAqBzF;AAED;;;GAGG;AACH,wBAAgB,WAAW,cACR,MAAM,UAAS,cAAc,UAO/C"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, {} from 'react';
|
|
2
|
+
import { AccessibilityInfo, Text, View } from 'react-native';
|
|
3
|
+
/**
|
|
4
|
+
* Universal `<LiveRegion>` component for React Native.
|
|
5
|
+
* Renders an off-screen/accessible container that instructs TalkBack/VoiceOver to announce updates.
|
|
6
|
+
*/
|
|
7
|
+
export function LiveRegion({ children, mode = 'polite', style, ...props }) {
|
|
8
|
+
return React.createElement(View, {
|
|
9
|
+
accessibilityLiveRegion: mode,
|
|
10
|
+
style: [
|
|
11
|
+
{
|
|
12
|
+
position: 'absolute',
|
|
13
|
+
opacity: 0,
|
|
14
|
+
height: 1,
|
|
15
|
+
width: 1,
|
|
16
|
+
overflow: 'hidden',
|
|
17
|
+
},
|
|
18
|
+
style,
|
|
19
|
+
],
|
|
20
|
+
...props,
|
|
21
|
+
}, typeof children === 'string'
|
|
22
|
+
? React.createElement(Text, { accessibilityLiveRegion: mode }, children)
|
|
23
|
+
: children);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Imperative announcement hook for React Native.
|
|
27
|
+
* Calls `AccessibilityInfo.announceForAccessibility` directly.
|
|
28
|
+
*/
|
|
29
|
+
export function useAnnounce() {
|
|
30
|
+
return (message, _mode = 'polite') => {
|
|
31
|
+
// `AccessibilityInfo` imported rather than read off `globalThis`, where React Native
|
|
32
|
+
// has never put it. The lookup always returned `undefined` and the
|
|
33
|
+
// `if` around it always failed, so this did nothing at all -- silently,
|
|
34
|
+
// which is the worst way for an accessibility affordance to be absent.
|
|
35
|
+
AccessibilityInfo.announceForAccessibility(message);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=live-region.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-region.native.js","sourceRoot":"","sources":["../src/live-region.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAkB,MAAM,OAAO,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAkB,IAAI,EAAE,IAAI,EAAkB,MAAM,cAAc,CAAA;AAoB5F;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,GAAG,QAAQ,EAAE,KAAK,EAAE,GAAG,KAAK,EAAmB;IACxF,OAAO,KAAK,CAAC,aAAa,CACxB,IAAI,EACJ;QACE,uBAAuB,EAAE,IAAI;QAC7B,KAAK,EAAE;YACL;gBACE,QAAQ,EAAE,UAAU;gBACpB,OAAO,EAAE,CAAC;gBACV,MAAM,EAAE,CAAC;gBACT,KAAK,EAAE,CAAC;gBACR,QAAQ,EAAE,QAAQ;aACnB;YACD,KAAK;SACN;QACD,GAAG,KAAK;KACT,EACD,OAAO,QAAQ,KAAK,QAAQ;QAC1B,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,uBAAuB,EAAE,IAAI,EAAE,EAAE,QAAQ,CAAC;QACxE,CAAC,CAAC,QAAQ,CACb,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,CAAC,OAAe,EAAE,KAAK,GAAmB,QAAQ,EAAE,EAAE;QAC3D,qFAAqF;QACrF,mEAAmE;QACnE,wEAAwE;QACxE,uEAAuE;QACvE,iBAAiB,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAA;IACrD,CAAC,CAAA;AACH,CAAC"}
|
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { Placement } from './floating-geometry.ts';
|
|
2
|
+
export { FloatingPositioner, type FloatingPositionerProps, type UseFloatingPositionOptions, useFloatingPosition, } from './floating-positioner.native.tsx';
|
|
3
|
+
export { type NativeContentProps, type NativeTriggerProps, type UseHoverTriggerOptions, type UseHoverTriggerReturn, useHoverTrigger, } from './hover-trigger.native.tsx';
|
|
4
|
+
export { Portal, PortalHost, type PortalProps, PortalProvider } from './portal.native.tsx';
|
|
5
|
+
//# sourceMappingURL=native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,mBAAmB,GACpB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,eAAe,GAChB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA"}
|
package/dist/native.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,iCAAkC,CAAA;AACzC,OAAO,EAKL,eAAe,GAChB,MAAM,2BAA4B,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAoB,cAAc,EAAE,MAAM,oBAAqB,CAAA"}
|
package/dist/portal.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface PortalProps {
|
|
3
|
+
children?: ReactNode;
|
|
4
|
+
container?: Element | DocumentFragment | null;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Optional PortalProvider to override default portal mounting target.
|
|
9
|
+
*/
|
|
10
|
+
export declare function PortalProvider({ children, container, }: {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
container: Element | DocumentFragment | null;
|
|
13
|
+
}): import("react").JSX.Element;
|
|
14
|
+
/**
|
|
15
|
+
* Universal `<Portal>` component for Web.
|
|
16
|
+
* Renders children into a DOM container (default: `document.body`) outside parent DOM hierarchy.
|
|
17
|
+
*/
|
|
18
|
+
export declare function Portal({ children, container, disabled }: PortalProps): import("react").JSX.Element | null;
|
|
19
|
+
/**
|
|
20
|
+
* Marker host element for Web (acts as default target anchor if placed explicitly).
|
|
21
|
+
*/
|
|
22
|
+
export declare function PortalHost({ id, className, }: {
|
|
23
|
+
id?: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
}): import("react").JSX.Element;
|
|
26
|
+
//# sourceMappingURL=portal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal.d.ts","sourceRoot":"","sources":["../src/portal.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,SAAS,EAAmC,MAAM,OAAO,CAAA;AAGtF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,SAAS,CAAC,EAAE,OAAO,GAAG,gBAAgB,GAAG,IAAI,CAAA;IAC7C,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAQD;;GAEG;AACH,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,SAAS,GACV,EAAE;IACD,QAAQ,EAAE,SAAS,CAAA;IACnB,SAAS,EAAE,OAAO,GAAG,gBAAgB,GAAG,IAAI,CAAA;CAC7C,+BAEA;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAgB,EAAE,EAAE,WAAW,sCAsB5E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,EACzB,EAAyB,EACzB,SAAS,GACV,EAAE;IACD,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,+BAEA"}
|
package/dist/portal.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useState } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
4
|
+
const PortalContext = createContext({
|
|
5
|
+
container: null,
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* Optional PortalProvider to override default portal mounting target.
|
|
9
|
+
*/
|
|
10
|
+
export function PortalProvider({ children, container, }) {
|
|
11
|
+
return _jsx(PortalContext.Provider, { value: { container }, children: children });
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Universal `<Portal>` component for Web.
|
|
15
|
+
* Renders children into a DOM container (default: `document.body`) outside parent DOM hierarchy.
|
|
16
|
+
*/
|
|
17
|
+
export function Portal({ children, container, disabled = false }) {
|
|
18
|
+
const context = useContext(PortalContext);
|
|
19
|
+
const [mounted, setMounted] = useState(false);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
setMounted(true);
|
|
22
|
+
}, []);
|
|
23
|
+
if (disabled) {
|
|
24
|
+
return _jsx(_Fragment, { children: children });
|
|
25
|
+
}
|
|
26
|
+
if (!mounted || typeof document === 'undefined') {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const target = container ?? context.container ?? document.body;
|
|
30
|
+
if (!target) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return createPortal(children, target);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Marker host element for Web (acts as default target anchor if placed explicitly).
|
|
37
|
+
*/
|
|
38
|
+
export function PortalHost({ id = '__hozo_portal_host', className, }) {
|
|
39
|
+
return _jsx("div", { id: id, className: className });
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=portal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal.js","sourceRoot":"","sources":["../src/portal.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAkB,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACtF,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAQxC,MAAM,aAAa,GAAG,aAAa,CAEhC;IACD,SAAS,EAAE,IAAI;CAChB,CAAC,CAAA;AAEF;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,QAAQ,EACR,SAAS,GAIV;IACC,OAAO,KAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,SAAS,EAAE,YAAG,QAAQ,GAA0B,CAAA;AAC1F,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,GAAG,KAAK,EAAe;IAC3E,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,CAAA;IACzC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAE7C,SAAS,CAAC,GAAG,EAAE;QACb,UAAU,CAAC,IAAI,CAAC,CAAA;IAClB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,4BAAG,QAAQ,GAAI,CAAA;IACxB,CAAC;IAED,IAAI,CAAC,OAAO,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QAChD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,MAAM,GAAG,SAAS,IAAI,OAAO,CAAC,SAAS,IAAI,QAAQ,CAAC,IAAI,CAAA;IAC9D,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,EAAE,GAAG,oBAAoB,EACzB,SAAS,GAIV;IACC,OAAO,cAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,SAAS,GAAI,CAAA;AAC9C,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
export interface PortalProps {
|
|
3
|
+
/**
|
|
4
|
+
* Tailwind classes, the same prop the Web half takes.
|
|
5
|
+
*
|
|
6
|
+
* On a tag the compiler lowers it is gone by runtime, replaced by a
|
|
7
|
+
* `StyleSheet` entry. Anywhere else it is carried and ignored here --
|
|
8
|
+
* this side has no CSS engine to resolve a class list against -- and
|
|
9
|
+
* the type still has to accept it, because an app is type-checked
|
|
10
|
+
* against the source the compiler reads rather than its output.
|
|
11
|
+
*/
|
|
12
|
+
className?: string;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
name?: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Global PortalProvider for React Native applications.
|
|
19
|
+
* Typically placed at the root of the app next to the root View.
|
|
20
|
+
*/
|
|
21
|
+
export declare function PortalProvider({ children }: {
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
}): React.JSX.Element;
|
|
24
|
+
/**
|
|
25
|
+
* Root host that renders the active portaled items at the top of the React Native view hierarchy.
|
|
26
|
+
*/
|
|
27
|
+
export declare function PortalHost({ items: directItems, }: {
|
|
28
|
+
items?: Map<string, ReactNode>;
|
|
29
|
+
/**
|
|
30
|
+
* Accepted and unused, so the two halves agree on the prop every other
|
|
31
|
+
* component takes. The rest of this component's props do not agree --
|
|
32
|
+
* the Web half is a marker `<div>` taking an `id`, this one renders the
|
|
33
|
+
* items -- which is a divergence of its own and not this one's to fix.
|
|
34
|
+
*/
|
|
35
|
+
className?: string;
|
|
36
|
+
}): React.FunctionComponentElement<Omit<import("react-native").ViewProps, "ref"> & {
|
|
37
|
+
ref?: React.Ref<import("react-native").ViewInstance> | undefined;
|
|
38
|
+
}> | null;
|
|
39
|
+
/**
|
|
40
|
+
* Universal `<Portal>` component for React Native.
|
|
41
|
+
* Teleports children to the nearest `PortalHost` / `PortalProvider`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function Portal({ children, disabled }: PortalProps): React.JSX.Element | null;
|
|
44
|
+
//# sourceMappingURL=portal.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal.native.d.ts","sourceRoot":"","sources":["../src/portal.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,KAAK,SAAS,EAA0C,MAAM,OAAO,CAAA;AAGpG,MAAM,WAAW,WAAW;IAC1B;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAUD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,qBAiCnE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,EACzB,KAAK,EAAE,WAAW,GACnB,EAAE;IACD,KAAK,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAC9B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;;UAqBA;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,EAAE,QAAQ,EAAE,QAAgB,EAAE,EAAE,WAAW,4BAsBjE"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { createContext, useContext, useEffect, useId, useState } from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
const PortalContext = createContext(null);
|
|
5
|
+
/**
|
|
6
|
+
* Global PortalProvider for React Native applications.
|
|
7
|
+
* Typically placed at the root of the app next to the root View.
|
|
8
|
+
*/
|
|
9
|
+
export function PortalProvider({ children }) {
|
|
10
|
+
const [items, setItems] = useState(() => new Map());
|
|
11
|
+
const methods = {
|
|
12
|
+
mount: (id, node) => {
|
|
13
|
+
setItems((prev) => {
|
|
14
|
+
const next = new Map(prev);
|
|
15
|
+
next.set(id, node);
|
|
16
|
+
return next;
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
update: (id, node) => {
|
|
20
|
+
setItems((prev) => {
|
|
21
|
+
const next = new Map(prev);
|
|
22
|
+
next.set(id, node);
|
|
23
|
+
return next;
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
unmount: (id) => {
|
|
27
|
+
setItems((prev) => {
|
|
28
|
+
const next = new Map(prev);
|
|
29
|
+
next.delete(id);
|
|
30
|
+
return next;
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
return (_jsxs(PortalContext.Provider, { value: methods, children: [children, _jsx(PortalHost, { items: items })] }));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Root host that renders the active portaled items at the top of the React Native view hierarchy.
|
|
38
|
+
*/
|
|
39
|
+
export function PortalHost({ items: directItems, }) {
|
|
40
|
+
if (!directItems || directItems.size === 0) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return React.createElement(View, {
|
|
44
|
+
pointerEvents: 'box-none',
|
|
45
|
+
style: {
|
|
46
|
+
position: 'absolute',
|
|
47
|
+
top: 0,
|
|
48
|
+
left: 0,
|
|
49
|
+
right: 0,
|
|
50
|
+
bottom: 0,
|
|
51
|
+
},
|
|
52
|
+
}, Array.from(directItems.entries()).map(([id, node]) => (_jsx(React.Fragment, { children: node }, id))));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Universal `<Portal>` component for React Native.
|
|
56
|
+
* Teleports children to the nearest `PortalHost` / `PortalProvider`.
|
|
57
|
+
*/
|
|
58
|
+
export function Portal({ children, disabled = false }) {
|
|
59
|
+
const portal = useContext(PortalContext);
|
|
60
|
+
const id = useId();
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (disabled || !portal)
|
|
63
|
+
return;
|
|
64
|
+
portal.mount(id, children);
|
|
65
|
+
return () => {
|
|
66
|
+
portal.unmount(id);
|
|
67
|
+
};
|
|
68
|
+
}, [disabled, portal, id, children]);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (disabled || !portal)
|
|
71
|
+
return;
|
|
72
|
+
portal.update(id, children);
|
|
73
|
+
}, [disabled, portal, id, children]);
|
|
74
|
+
if (disabled || !portal) {
|
|
75
|
+
return _jsx(_Fragment, { children: children });
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=portal.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal.native.js","sourceRoot":"","sources":["../src/portal.native.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAkB,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACpG,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAwBnC,MAAM,aAAa,GAAG,aAAa,CAAuB,IAAI,CAAC,CAAA;AAE/D;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,EAAE,QAAQ,EAA2B;IAClE,MAAM,CAAC,KAAK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Q,IAAI,CAAC,MAAM,EAAE,CAAC;QACxB,OAAO,4BAAG,QAAQ,GAAI,CAAA;IACxB,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type Orientation = 'horizontal' | 'vertical' | 'both';
|
|
2
|
+
export type RovingKey = 'ArrowLeft' | 'ArrowRight' | 'ArrowUp' | 'ArrowDown' | 'Home' | 'End';
|
|
3
|
+
export interface RovingOptions {
|
|
4
|
+
count: number;
|
|
5
|
+
active: number;
|
|
6
|
+
orientation?: Orientation;
|
|
7
|
+
wrap?: boolean;
|
|
8
|
+
disabled?: readonly number[];
|
|
9
|
+
rtl?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function nextIndex(key: RovingKey, options: RovingOptions): number | null;
|
|
12
|
+
export declare function tabStops(options: Pick<RovingOptions, 'count' | 'active' | 'disabled'>): number[];
|
|
13
|
+
//# sourceMappingURL=roving-focus-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roving-focus-rules.d.ts","sourceRoot":"","sources":["../src/roving-focus-rules.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,UAAU,GAAG,MAAM,CAAA;AAC5D,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,YAAY,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,GAAG,KAAK,CAAA;AAE7F,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAC5B,GAAG,CAAC,EAAE,OAAO,CAAA;CACd;AA0CD,wBAAgB,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CAoB/E;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC,GAAG,MAAM,EAAE,CAIhG"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
function arrowStep(key, horizontal, vertical, rtl) {
|
|
2
|
+
switch (key) {
|
|
3
|
+
case 'ArrowLeft':
|
|
4
|
+
return horizontal ? (rtl ? 1 : -1) : null;
|
|
5
|
+
case 'ArrowRight':
|
|
6
|
+
return horizontal ? (rtl ? -1 : 1) : null;
|
|
7
|
+
case 'ArrowUp':
|
|
8
|
+
return vertical ? -1 : null;
|
|
9
|
+
case 'ArrowDown':
|
|
10
|
+
return vertical ? 1 : null;
|
|
11
|
+
default:
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function seek(from, step, count, disabled, wrap, active) {
|
|
16
|
+
let index = from;
|
|
17
|
+
for (let moved = 0; moved <= count; moved += 1) {
|
|
18
|
+
if (index < 0 || index >= count) {
|
|
19
|
+
if (!wrap)
|
|
20
|
+
return active;
|
|
21
|
+
index = index < 0 ? count - 1 : 0;
|
|
22
|
+
}
|
|
23
|
+
if (!disabled.includes(index))
|
|
24
|
+
return index;
|
|
25
|
+
index += step;
|
|
26
|
+
}
|
|
27
|
+
return active;
|
|
28
|
+
}
|
|
29
|
+
export function nextIndex(key, options) {
|
|
30
|
+
const { count, active, orientation = 'horizontal', wrap = true, disabled = [], rtl = false, } = options;
|
|
31
|
+
if (count <= 0)
|
|
32
|
+
return null;
|
|
33
|
+
const horizontal = orientation === 'horizontal' || orientation === 'both';
|
|
34
|
+
const vertical = orientation === 'vertical' || orientation === 'both';
|
|
35
|
+
if (key === 'Home')
|
|
36
|
+
return seek(0, 1, count, disabled, false, active);
|
|
37
|
+
if (key === 'End')
|
|
38
|
+
return seek(count - 1, -1, count, disabled, false, active);
|
|
39
|
+
const step = arrowStep(key, horizontal, vertical, rtl);
|
|
40
|
+
if (step === null)
|
|
41
|
+
return null;
|
|
42
|
+
return seek(active + step, step, count, disabled, wrap, active);
|
|
43
|
+
}
|
|
44
|
+
export function tabStops(options) {
|
|
45
|
+
const { count, active, disabled = [] } = options;
|
|
46
|
+
const stop = disabled.includes(active) ? seek(0, 1, count, disabled, false, active) : active;
|
|
47
|
+
return Array.from({ length: count }, (_, index) => (index === stop ? 0 : -1));
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=roving-focus-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roving-focus-rules.js","sourceRoot":"","sources":["../src/roving-focus-rules.ts"],"names":[],"mappings":"AAYA,SAAS,SAAS,CAChB,GAAc,EACd,UAAmB,EACnB,QAAiB,EACjB,GAAY;IAEZ,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,WAAW;YACd,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QAC3C,KAAK,YAAY;YACf,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QAC3C,KAAK,SAAS;YACZ,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QAC7B,KAAK,WAAW;YACd,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QAC5B;YACE,OAAO,IAAI,CAAA;IACf,CAAC;AACH,CAAC;AAED,SAAS,IAAI,CACX,IAAY,EACZ,IAAY,EACZ,KAAa,EACb,QAA2B,EAC3B,IAAa,EACb,MAAc;IAEd,IAAI,KAAK,GAAG,IAAI,CAAA;IAChB,KAAK,IAAI,KAAK,GAAG,CAA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tD,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAC9B,OAAO,IAAI,CAAC,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;AACjE,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,OAA6D;IACpF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;IAC5F,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAC/E,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type CSSProperties, type KeyboardEvent, type ReactNode } from 'react';
|
|
2
|
+
import { type Orientation } from './roving-focus-rules.ts';
|
|
3
|
+
export { nextIndex, type Orientation, type RovingKey, type RovingOptions, tabStops, } from './roving-focus-rules.ts';
|
|
4
|
+
export interface RovingFocusGroupProps {
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
count: number;
|
|
7
|
+
active: number;
|
|
8
|
+
onActiveChange: (index: number) => void;
|
|
9
|
+
orientation?: Orientation;
|
|
10
|
+
wrap?: boolean;
|
|
11
|
+
disabled?: readonly number[];
|
|
12
|
+
rtl?: boolean;
|
|
13
|
+
className?: string;
|
|
14
|
+
style?: CSSProperties;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Universal `<RovingFocusGroup>` component for Web.
|
|
18
|
+
* Coordinates 1D and 2D arrow key navigation with a single active tab stop.
|
|
19
|
+
*/
|
|
20
|
+
export declare function RovingFocusGroup({ children, count, active, onActiveChange, orientation, wrap, disabled, rtl, className, style, }: RovingFocusGroupProps): import("react").JSX.Element;
|
|
21
|
+
export declare function useRovingItem(index: number): {
|
|
22
|
+
tabIndex: number;
|
|
23
|
+
isActive: boolean;
|
|
24
|
+
onFocus: () => void;
|
|
25
|
+
onKeyDown: (event: KeyboardEvent) => void;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=roving-focus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roving-focus.d.ts","sourceRoot":"","sources":["../src/roving-focus.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,aAAa,EAClB,KAAK,SAAS,EAIf,MAAM,OAAO,CAAA;AAEd,OAAO,EAAa,KAAK,WAAW,EAA4B,MAAM,yBAAyB,CAAA;AAE/F,OAAO,EACL,SAAS,EACT,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,QAAQ,GACT,MAAM,yBAAyB,CAAA;AAYhC,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACvC,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAC5B,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,KAAK,EACL,MAAM,EACN,cAAc,EACd,WAA0B,EAC1B,IAAW,EACX,QAAa,EACb,GAAW,EACX,SAAS,EACT,KAAK,GACN,EAAE,qBAAqB,+BAwCvB;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM;;;;uBAepB,aAAa;EAEnC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useMemo, } from 'react';
|
|
3
|
+
import { nextIndex, tabStops } from './roving-focus-rules.js';
|
|
4
|
+
export { nextIndex, tabStops, } from './roving-focus-rules.js';
|
|
5
|
+
const RovingFocusContext = createContext(null);
|
|
6
|
+
/**
|
|
7
|
+
* Universal `<RovingFocusGroup>` component for Web.
|
|
8
|
+
* Coordinates 1D and 2D arrow key navigation with a single active tab stop.
|
|
9
|
+
*/
|
|
10
|
+
export function RovingFocusGroup({ children, count, active, onActiveChange, orientation = 'horizontal', wrap = true, disabled = [], rtl = false, className, style, }) {
|
|
11
|
+
const stops = useMemo(() => tabStops({ count, active, disabled }), [count, active, disabled]);
|
|
12
|
+
const handleItemKeyDown = useCallback((index, event) => {
|
|
13
|
+
const key = event.key;
|
|
14
|
+
const next = nextIndex(key, {
|
|
15
|
+
count,
|
|
16
|
+
active: index,
|
|
17
|
+
orientation,
|
|
18
|
+
wrap,
|
|
19
|
+
disabled,
|
|
20
|
+
rtl,
|
|
21
|
+
});
|
|
22
|
+
if (next !== null && next !== index) {
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
onActiveChange(next);
|
|
25
|
+
}
|
|
26
|
+
}, [count, orientation, wrap, disabled, rtl, onActiveChange]);
|
|
27
|
+
const contextValue = useMemo(() => ({
|
|
28
|
+
active,
|
|
29
|
+
tabStops: stops,
|
|
30
|
+
onItemFocus: onActiveChange,
|
|
31
|
+
onItemKeyDown: handleItemKeyDown,
|
|
32
|
+
}), [active, stops, onActiveChange, handleItemKeyDown]);
|
|
33
|
+
return (_jsx(RovingFocusContext.Provider, { value: contextValue, children: _jsx("div", { className: className, style: style, children: children }) }));
|
|
34
|
+
}
|
|
35
|
+
export function useRovingItem(index) {
|
|
36
|
+
const context = useContext(RovingFocusContext);
|
|
37
|
+
if (!context) {
|
|
38
|
+
return {
|
|
39
|
+
tabIndex: 0,
|
|
40
|
+
onFocus: () => { },
|
|
41
|
+
onKeyDown: () => { },
|
|
42
|
+
isActive: true,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
tabIndex: context.tabStops[index] ?? -1,
|
|
47
|
+
isActive: context.active === index,
|
|
48
|
+
onFocus: () => context.onItemFocus(index),
|
|
49
|
+
onKeyDown: (event) => context.onItemKeyDown(index, event),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=roving-focus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roving-focus.js","sourceRoot":"","sources":["../src/roving-focus.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEL,aAAa,EAGb,WAAW,EACX,UAAU,EACV,OAAO,GACR,MAAM,OAAO,CAAA;AAEd,OAAO,EAAE,SAAS,EAAoC,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAE/F,OAAO,EACL,SAAS,EAIT,QAAQ,GACT,MAAM,yBAAyB,CAAA;AAUhC,MAAM,kBAAkB,GAAG,aAAa,CAAiC,IAAI,CAAC,CAAA;AAe9E;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,QAAQ,EACR,KAAK,EACL,MAAM,EACN,cAAc,EACd,WAAW,GAAG,YAAY,EAC1B,IAAI,GAAG,IAAI,EACX,QAAQ,GAAG,EAAE,EACb,GAAG,GAAG,KAAK,EACX,SAAS,EACT,KAAK,GACiB;IACtB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE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CAAC;YACnB,QAAQ,EAAE,IAAI;SACf,CAAA;IACH,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvC,QAAQ,EAAE,OAAO,CAAC,MAAM,KAAK,KAAK;QAClC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC;QACzC,SAAS,EAAE,CAAC,KAAoB,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC;KACzE,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import type { Orientation } from './roving-focus-rules.ts';
|
|
4
|
+
export { nextIndex, type Orientation, type RovingKey, type RovingOptions, tabStops, } from './roving-focus-rules.ts';
|
|
5
|
+
export interface RovingFocusGroupProps {
|
|
6
|
+
/**
|
|
7
|
+
* Tailwind classes, the same prop the Web half takes.
|
|
8
|
+
*
|
|
9
|
+
* On a tag the compiler lowers it is gone by runtime, replaced by a
|
|
10
|
+
* `StyleSheet` entry. Anywhere else it is carried and ignored here --
|
|
11
|
+
* this side has no CSS engine to resolve a class list against -- and
|
|
12
|
+
* the type still has to accept it, because an app is type-checked
|
|
13
|
+
* against the source the compiler reads rather than its output.
|
|
14
|
+
*/
|
|
15
|
+
className?: string;
|
|
16
|
+
children?: ReactNode;
|
|
17
|
+
count: number;
|
|
18
|
+
active: number;
|
|
19
|
+
onActiveChange: (index: number) => void;
|
|
20
|
+
orientation?: Orientation;
|
|
21
|
+
wrap?: boolean;
|
|
22
|
+
disabled?: readonly number[];
|
|
23
|
+
rtl?: boolean;
|
|
24
|
+
style?: StyleProp<ViewStyle>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Universal `<RovingFocusGroup>` component for React Native.
|
|
28
|
+
*/
|
|
29
|
+
export declare function RovingFocusGroup({ children, active, onActiveChange, style, ...props }: RovingFocusGroupProps): React.FunctionComponentElement<Omit<import("react-native").ViewProps, "ref"> & {
|
|
30
|
+
ref?: React.Ref<import("react-native").ViewInstance> | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
export declare function useRovingItem(index: number): {
|
|
33
|
+
isActive: boolean;
|
|
34
|
+
onFocus: () => void;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=roving-focus.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roving-focus.native.d.ts","sourceRoot":"","sources":["../src/roving-focus.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAA;AACjF,OAAO,EAAE,KAAK,SAAS,EAAQ,KAAK,SAAS,EAAE,MAAM,cAAc,CAAA;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE1D,OAAO,EACL,SAAS,EACT,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,QAAQ,GACT,MAAM,yBAAyB,CAAA;AAShC,MAAM,WAAW,qBAAqB;IACpC;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACvC,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAC5B,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;CAC7B;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,MAAM,EACN,cAAc,EACd,KAAK,EACL,GAAG,KAAK,EACT,EAAE,qBAAqB;;GAcvB;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM;;;EAa1C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { createContext, useContext, useMemo } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
export { nextIndex, tabStops, } from './roving-focus-rules.js';
|
|
4
|
+
const RovingFocusContext = createContext(null);
|
|
5
|
+
/**
|
|
6
|
+
* Universal `<RovingFocusGroup>` component for React Native.
|
|
7
|
+
*/
|
|
8
|
+
export function RovingFocusGroup({ children, active, onActiveChange, style, ...props }) {
|
|
9
|
+
const contextValue = useMemo(() => ({
|
|
10
|
+
active,
|
|
11
|
+
onItemFocus: onActiveChange,
|
|
12
|
+
}), [active, onActiveChange]);
|
|
13
|
+
return React.createElement(View, { style, ...props }, React.createElement(RovingFocusContext.Provider, { value: contextValue }, children));
|
|
14
|
+
}
|
|
15
|
+
export function useRovingItem(index) {
|
|
16
|
+
const context = useContext(RovingFocusContext);
|
|
17
|
+
if (!context) {
|
|
18
|
+
return {
|
|
19
|
+
isActive: true,
|
|
20
|
+
onFocus: () => { },
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
isActive: context.active === index,
|
|
25
|
+
onFocus: () => context.onItemFocus(index),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=roving-focus.native.js.map
|