@ankhorage/zora 27.3.6 → 27.3.8
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/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/features/content-rail/adapters/inbound/ContentRail.d.ts.map +1 -1
- package/dist/features/content-rail/adapters/inbound/ContentRail.js.map +1 -1
- package/dist/features/form/radio/adapters/inbound/RadioGroup.d.ts.map +1 -1
- package/dist/features/form/radio/adapters/inbound/RadioGroup.js +20 -3
- package/dist/features/form/radio/adapters/inbound/RadioGroup.js.map +1 -1
- package/dist/features/form/radio/adapters/inbound/RadioOptionControl.d.ts +4 -0
- package/dist/features/form/radio/adapters/inbound/RadioOptionControl.d.ts.map +1 -1
- package/dist/features/form/radio/adapters/inbound/RadioOptionControl.js +4 -4
- package/dist/features/form/radio/adapters/inbound/RadioOptionControl.js.map +1 -1
- package/dist/features/form/radio/utils/handleRadioOptionKeyDown.d.ts +2 -12
- package/dist/features/form/radio/utils/handleRadioOptionKeyDown.d.ts.map +1 -1
- package/dist/features/form/radio/utils/handleRadioOptionKeyDown.js +8 -15
- package/dist/features/form/radio/utils/handleRadioOptionKeyDown.js.map +1 -1
- package/dist/features/game/adapters/inbound/GameEntity.d.ts.map +1 -1
- package/dist/features/game/adapters/inbound/GameEntity.js.map +1 -1
- package/dist/features/game/adapters/inbound/GameInputZone.js +7 -1
- package/dist/features/game/adapters/inbound/GameInputZone.js.map +1 -1
- package/dist/features/game/utils/measureGameEntity.d.ts +2 -1
- package/dist/features/game/utils/measureGameEntity.d.ts.map +1 -1
- package/dist/features/game/utils/measureGameEntity.js.map +1 -1
- package/dist/features/game/utils/useGameEntityMeasurement.d.ts +2 -1
- package/dist/features/game/utils/useGameEntityMeasurement.d.ts.map +1 -1
- package/dist/features/game/utils/useGameEntityMeasurement.js.map +1 -1
- package/dist/features/grid-interactions/adapters/inbound/GridInteractions.d.ts.map +1 -1
- package/dist/features/grid-interactions/adapters/inbound/GridInteractions.js.map +1 -1
- package/dist/features/grid-view/adapters/inbound/GridView.d.ts.map +1 -1
- package/dist/features/grid-view/adapters/inbound/GridView.js.map +1 -1
- package/dist/features/list/adapters/inbound/FlatList.js +1 -1
- package/dist/features/list/adapters/inbound/FlatList.js.map +1 -1
- package/dist/features/list/adapters/inbound/SectionList.js +1 -1
- package/dist/features/list/adapters/inbound/SectionList.js.map +1 -1
- package/dist/features/list/adapters/inbound/useListVisibility.d.ts +5 -2
- package/dist/features/list/adapters/inbound/useListVisibility.d.ts.map +1 -1
- package/dist/features/list/adapters/inbound/useListVisibility.js +1 -1
- package/dist/features/list/adapters/inbound/useListVisibility.js.map +1 -1
- package/dist/features/reader/composition/useReaderController.js +7 -2
- package/dist/features/reader/composition/useReaderController.js.map +1 -1
- package/dist/types/activity-indicator.d.ts +1 -1
- package/dist/types/activity-indicator.d.ts.map +1 -1
- package/dist/types/activity-indicator.js.map +1 -1
- package/dist/types/layout.d.ts +1 -1
- package/dist/types/layout.d.ts.map +1 -1
- package/dist/types/layout.js.map +1 -1
- package/dist/types/react-native.d.ts +6 -0
- package/dist/types/react-native.d.ts.map +1 -0
- package/dist/types/react-native.js +2 -0
- package/dist/types/react-native.js.map +1 -0
- package/package.json +2 -2
- package/src/features/content-rail/adapters/inbound/ContentRail.tsx +2 -1
- package/src/features/form/radio/adapters/inbound/RadioGroup.tsx +40 -2
- package/src/features/form/radio/adapters/inbound/RadioOptionControl.tsx +28 -7
- package/src/features/form/radio/utils/handleRadioOptionKeyDown.test.ts +16 -34
- package/src/features/form/radio/utils/handleRadioOptionKeyDown.ts +10 -28
- package/src/features/game/adapters/inbound/GameEntity.tsx +4 -2
- package/src/features/game/adapters/inbound/GameInputZone.tsx +14 -1
- package/src/features/game/utils/measureGameEntity.ts +2 -1
- package/src/features/game/utils/useGameEntityMeasurement.ts +2 -1
- package/src/features/grid-interactions/adapters/inbound/GridInteractions.tsx +2 -1
- package/src/features/grid-view/adapters/inbound/GridView.tsx +6 -3
- package/src/features/list/adapters/inbound/FlatList.tsx +3 -3
- package/src/features/list/adapters/inbound/SectionList.tsx +3 -3
- package/src/features/list/adapters/inbound/useListVisibility.ts +7 -3
- package/src/features/reader/composition/useReaderController.ts +8 -1
- package/src/types/activity-indicator.ts +1 -1
- package/src/types/layout.ts +1 -1
- package/src/types/react-native.ts +9 -0
- package/web-dist/chunks/{Accordion-19k3xdzb.js → Accordion-25xjvp3t.js} +7 -1
- package/web-dist/chunks/{Accordion-9a3a3nbw.js → Accordion-c1x8bqnr.js} +41 -17
- package/web-dist/chunks/{Accordion-cdyywh25.js → Accordion-vyr0wyp9.js} +7 -7
- package/web-dist/chunks/{Accordion-x8r4nhae.js → Accordion-x3shxr1k.js} +1 -1
- package/web-dist/components/data-table/DataTable.js +2 -2
- package/web-dist/components/flat-list/FlatList.js +1 -1
- package/web-dist/components/game/Game.js +1 -1
- package/web-dist/components/game-entity/GameEntity.js +1 -1
- package/web-dist/components/game-field/GameField.js +1 -1
- package/web-dist/components/game-input-zone/GameInputZone.js +1 -1
- package/web-dist/components/game-measurement-probe/GameMeasurementProbe.js +1 -1
- package/web-dist/components/game-overlay/GameOverlay.js +1 -1
- package/web-dist/components/list/List.js +1 -1
- package/web-dist/components/list-item/ListItem.js +1 -1
- package/web-dist/components/list-section/ListSection.js +1 -1
- package/web-dist/components/radio/Radio.js +1 -1
- package/web-dist/components/radio-group/RadioGroup.js +1 -1
- package/web-dist/components/reader/Reader.js +7 -3
- package/web-dist/components/section-list/SectionList.js +1 -1
- package/web-dist/components/skeleton/Skeleton.js +2 -2
- package/web-dist/components/skeleton-card/SkeletonCard.js +2 -2
- package/web-dist/components/skeleton-list/SkeletonList.js +2 -2
- package/web-dist/components/skeleton-text/SkeletonText.js +2 -2
- package/web-dist/components/tree-item/TreeItem.js +1 -1
- package/web-dist/manifest.json +24 -24
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Radio } from '@ankhorage/surface';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import type { Pressable } from 'react-native';
|
|
3
4
|
import { StyleSheet } from 'react-native';
|
|
4
5
|
|
|
5
6
|
import type { RadioGroupProps } from '../../../../../types/radio';
|
|
7
|
+
import type { ReactNativeComponentInstance } from '../../../../../types/react-native';
|
|
6
8
|
import { View } from '../../../../layout/public';
|
|
7
9
|
import { withZoraThemeScope } from '../../../../theme/adapters/inbound/withZoraThemeScope';
|
|
8
10
|
import { useZoraThemeRecipe } from '../../../../theme/composition/useZoraThemeRecipe';
|
|
@@ -21,10 +23,32 @@ function RadioGroupInner<TValue extends string>({
|
|
|
21
23
|
...props
|
|
22
24
|
}: RadioGroupProps<TValue>) {
|
|
23
25
|
const [localValue, setLocalValue] = React.useState(props.defaultValue);
|
|
26
|
+
const cardOptionRefs = React.useRef<Map<TValue, ReactNativeComponentInstance<typeof Pressable>>>(
|
|
27
|
+
new Map(),
|
|
28
|
+
);
|
|
24
29
|
const onValueChange = (next: TValue) => {
|
|
25
30
|
if (props.value === undefined) setLocalValue(next);
|
|
26
31
|
props.onValueChange?.(next);
|
|
27
32
|
};
|
|
33
|
+
const onNavigateCardOption = (currentValue: TValue, direction: -1 | 1) => {
|
|
34
|
+
const currentIndex = props.options.findIndex((option) => option.value === currentValue);
|
|
35
|
+
if (currentIndex < 0) return;
|
|
36
|
+
const nextOption = Array.from({ length: props.options.length - 1 }, (_, offset) =>
|
|
37
|
+
props.options.at(
|
|
38
|
+
(currentIndex + direction * (offset + 1) + props.options.length) % props.options.length,
|
|
39
|
+
),
|
|
40
|
+
).find((option) => option !== undefined && !props.disabled && !option.disabled);
|
|
41
|
+
if (nextOption === undefined) return;
|
|
42
|
+
onValueChange(nextOption.value);
|
|
43
|
+
cardOptionRefs.current.get(nextOption.value)?.focus();
|
|
44
|
+
};
|
|
45
|
+
const onCardOptionRef = (
|
|
46
|
+
value: TValue,
|
|
47
|
+
element: ReactNativeComponentInstance<typeof Pressable> | null,
|
|
48
|
+
) => {
|
|
49
|
+
if (element === null) cardOptionRefs.current.delete(value);
|
|
50
|
+
else cardOptionRefs.current.set(value, element);
|
|
51
|
+
};
|
|
28
52
|
const selectedProps = { ...props, value: props.value ?? localValue, onValueChange };
|
|
29
53
|
const themeFields = useZoraThemeRecipe(radioGroupThemeRecipeMeta);
|
|
30
54
|
const recipe = resolveRadioGroupThemeRecipe({ ...props, themeFields });
|
|
@@ -41,7 +65,13 @@ function RadioGroupInner<TValue extends string>({
|
|
|
41
65
|
<View key={index} direction="row" gap={recipe.gap}>
|
|
42
66
|
{options.map((option) => (
|
|
43
67
|
<View key={option.value} style={styles.option}>
|
|
44
|
-
<RadioGroupItem
|
|
68
|
+
<RadioGroupItem
|
|
69
|
+
{...selectedProps}
|
|
70
|
+
{...recipe}
|
|
71
|
+
onNavigate={onNavigateCardOption}
|
|
72
|
+
onOptionRef={onCardOptionRef}
|
|
73
|
+
option={option}
|
|
74
|
+
/>
|
|
45
75
|
</View>
|
|
46
76
|
))}
|
|
47
77
|
{Array.from({ length: columns - options.length }, (_, slot) => (
|
|
@@ -74,10 +104,16 @@ function RadioGroupInline<TValue extends string>(props: RadioGroupProps<TValue>)
|
|
|
74
104
|
/*** Delegate icon options to their composed radio boundary and ordinary options to Surface Radio. */
|
|
75
105
|
function RadioGroupItem<TValue extends string>(
|
|
76
106
|
props: RadioGroupProps<TValue> & {
|
|
107
|
+
onNavigate?: (currentValue: TValue, direction: -1 | 1) => void;
|
|
108
|
+
onOptionRef?: (
|
|
109
|
+
value: TValue,
|
|
110
|
+
element: ReactNativeComponentInstance<typeof Pressable> | null,
|
|
111
|
+
) => void;
|
|
77
112
|
option: RadioGroupProps<TValue>['options'][number];
|
|
78
113
|
},
|
|
79
114
|
) {
|
|
80
|
-
const { option, value, onValueChange, interactionPolicy, color, size } =
|
|
115
|
+
const { option, value, onValueChange, interactionPolicy, color, size, onNavigate, onOptionRef } =
|
|
116
|
+
props;
|
|
81
117
|
const checked = value === option.value;
|
|
82
118
|
const inactive = props.disabled === true || option.disabled === true;
|
|
83
119
|
const readOnly = props.readOnly === true;
|
|
@@ -95,6 +131,8 @@ function RadioGroupItem<TValue extends string>(
|
|
|
95
131
|
readOnly={readOnly}
|
|
96
132
|
invalid={invalid}
|
|
97
133
|
layout={props.contentOrientation ?? 'horizontal'}
|
|
134
|
+
onNavigate={(direction) => onNavigate?.(option.value, direction)}
|
|
135
|
+
onOptionRef={(element) => onOptionRef?.(option.value, element)}
|
|
98
136
|
onSelect={onSelect}
|
|
99
137
|
/>
|
|
100
138
|
);
|
|
@@ -3,25 +3,37 @@ import React from 'react';
|
|
|
3
3
|
import { Platform, Pressable, StyleSheet, View } from 'react-native';
|
|
4
4
|
|
|
5
5
|
import type { RadioGroupProps } from '../../../../../types/radio';
|
|
6
|
+
import type { ReactNativeComponentInstance } from '../../../../../types/react-native';
|
|
6
7
|
import { Icon } from '../../../../icon/public';
|
|
7
8
|
import { Text } from '../../../../typography/public';
|
|
8
|
-
import {
|
|
9
|
-
handleRadioOptionKeyDown,
|
|
10
|
-
type RadioOptionKeyboardTarget,
|
|
11
|
-
} from '../../utils/handleRadioOptionKeyDown';
|
|
9
|
+
import { handleRadioOptionKeyDown } from '../../utils/handleRadioOptionKeyDown';
|
|
12
10
|
import { resolveRadioOptionColors } from '../../utils/resolveRadioOptionColors';
|
|
13
11
|
|
|
14
12
|
/*** Render a selectable icon radio option with one accessible radio target and a trailing check. */
|
|
15
13
|
export function RadioOptionControl<TValue extends string>(props: RadioOptionControlProps<TValue>) {
|
|
16
14
|
const { theme } = useTheme();
|
|
17
|
-
const {
|
|
15
|
+
const {
|
|
16
|
+
option,
|
|
17
|
+
checked,
|
|
18
|
+
disabled,
|
|
19
|
+
readOnly,
|
|
20
|
+
interactionPolicy,
|
|
21
|
+
onNavigate,
|
|
22
|
+
onOptionRef,
|
|
23
|
+
onSelect,
|
|
24
|
+
} = props;
|
|
18
25
|
const colors = resolveRadioOptionColors(theme, props);
|
|
19
26
|
const [focused, setFocused] = React.useState(false);
|
|
20
27
|
const keyboardProps =
|
|
21
28
|
Platform.OS === 'web' && !readOnly && !disabled && interactionPolicy !== 'passive'
|
|
22
29
|
? {
|
|
23
|
-
onKeyDown: (event:
|
|
24
|
-
handleRadioOptionKeyDown(
|
|
30
|
+
onKeyDown: (event: RadioOptionKeyboardEvent) =>
|
|
31
|
+
handleRadioOptionKeyDown(
|
|
32
|
+
event.nativeEvent?.key ?? event.key ?? '',
|
|
33
|
+
() => event.preventDefault(),
|
|
34
|
+
onSelect,
|
|
35
|
+
onNavigate,
|
|
36
|
+
),
|
|
25
37
|
}
|
|
26
38
|
: {};
|
|
27
39
|
const controlStyle = {
|
|
@@ -36,6 +48,7 @@ export function RadioOptionControl<TValue extends string>(props: RadioOptionCont
|
|
|
36
48
|
return (
|
|
37
49
|
<Pressable
|
|
38
50
|
{...keyboardProps}
|
|
51
|
+
ref={onOptionRef}
|
|
39
52
|
accessibilityRole="radio"
|
|
40
53
|
accessibilityState={{ checked, disabled }}
|
|
41
54
|
aria-checked={checked}
|
|
@@ -98,9 +111,17 @@ interface RadioOptionControlProps<TValue extends string> extends Pick<
|
|
|
98
111
|
readOnly: boolean;
|
|
99
112
|
invalid: boolean;
|
|
100
113
|
layout: 'horizontal' | 'vertical';
|
|
114
|
+
onNavigate: (direction: -1 | 1) => void;
|
|
115
|
+
onOptionRef: (element: ReactNativeComponentInstance<typeof Pressable> | null) => void;
|
|
101
116
|
onSelect: () => void;
|
|
102
117
|
}
|
|
103
118
|
|
|
119
|
+
interface RadioOptionKeyboardEvent {
|
|
120
|
+
readonly key?: string;
|
|
121
|
+
readonly nativeEvent?: { readonly key?: string };
|
|
122
|
+
preventDefault(): void;
|
|
123
|
+
}
|
|
124
|
+
|
|
104
125
|
/*** Keep decoration passive while allowing labels to wrap at narrow widths and large text sizes. */
|
|
105
126
|
function RadioOptionControlContent<TValue extends string>({
|
|
106
127
|
option,
|
|
@@ -1,47 +1,29 @@
|
|
|
1
1
|
import { expect, test } from 'bun:test';
|
|
2
|
-
import type { KeyboardEvent } from 'react';
|
|
3
2
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
handleRadioOptionKeyDown,
|
|
7
|
-
type RadioOptionKeyboardTarget,
|
|
8
|
-
} from './handleRadioOptionKeyDown';
|
|
3
|
+
import { handleRadioOptionKeyDown } from './handleRadioOptionKeyDown';
|
|
9
4
|
|
|
10
5
|
test('Space selects the focused radio and prevents page scrolling', () => {
|
|
11
6
|
let selected = 0;
|
|
12
7
|
let prevented = 0;
|
|
13
8
|
handleRadioOptionKeyDown(
|
|
14
|
-
|
|
9
|
+
' ',
|
|
10
|
+
() => prevented++,
|
|
15
11
|
() => selected++,
|
|
12
|
+
() => undefined,
|
|
16
13
|
);
|
|
17
14
|
expect(selected).toBe(1);
|
|
18
15
|
expect(prevented).toBe(1);
|
|
19
16
|
});
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
handleRadioOptionKeyDown(
|
|
34
|
-
{
|
|
35
|
-
key,
|
|
36
|
-
currentTarget,
|
|
37
|
-
preventDefault: () => prevented++,
|
|
38
|
-
} as KeyboardEvent<RadioOptionKeyboardTarget>,
|
|
39
|
-
() => undefined,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
const expected = direction === 1 ? [2, 3, 0] : [3, 0, 2];
|
|
43
|
-
expect(focused).toEqual(expected);
|
|
44
|
-
expect(activated).toEqual(expected);
|
|
45
|
-
expect(prevented).toBe(3);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
18
|
+
test('Arrow keys delegate directional selection to the radio group', () => {
|
|
19
|
+
const directions: number[] = [];
|
|
20
|
+
let prevented = 0;
|
|
21
|
+
handleRadioOptionKeyDown(
|
|
22
|
+
'ArrowDown',
|
|
23
|
+
() => prevented++,
|
|
24
|
+
() => undefined,
|
|
25
|
+
(direction) => directions.push(direction),
|
|
26
|
+
);
|
|
27
|
+
expect(directions).toEqual([1]);
|
|
28
|
+
expect(prevented).toBe(1);
|
|
29
|
+
});
|
|
@@ -1,37 +1,19 @@
|
|
|
1
|
-
import type { KeyboardEvent } from 'react';
|
|
2
|
-
|
|
3
1
|
import { DIRECTION_MODIFIERS } from '../constants';
|
|
4
2
|
|
|
5
|
-
/***
|
|
3
|
+
/*** Select a focused radio option through the React Native keyboard event contract. */
|
|
6
4
|
export function handleRadioOptionKeyDown(
|
|
7
|
-
|
|
5
|
+
key: string,
|
|
6
|
+
preventDefault: () => void,
|
|
8
7
|
select: () => void,
|
|
8
|
+
navigate: (direction: -1 | 1) => void,
|
|
9
9
|
): void {
|
|
10
|
-
if (
|
|
11
|
-
|
|
10
|
+
if (key === ' ') {
|
|
11
|
+
preventDefault();
|
|
12
12
|
select();
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
const direction = DIRECTION_MODIFIERS.get(
|
|
16
|
-
if (direction
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
(option) => option.getAttribute('aria-disabled') !== 'true',
|
|
20
|
-
);
|
|
21
|
-
const index = options.indexOf(event.currentTarget);
|
|
22
|
-
if (index < 0 || options.length === 0) return;
|
|
23
|
-
event.preventDefault();
|
|
24
|
-
const next = options.at((index + direction + options.length) % options.length);
|
|
25
|
-
next?.focus();
|
|
26
|
-
next?.click();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Minimal web target contract keeps the native build independent of DOM ambient libraries. */
|
|
30
|
-
export interface RadioOptionKeyboardTarget {
|
|
31
|
-
closest(
|
|
32
|
-
selector: string,
|
|
33
|
-
): { querySelectorAll(selector: string): ArrayLike<RadioOptionKeyboardTarget> } | null;
|
|
34
|
-
getAttribute(name: string): string | null;
|
|
35
|
-
focus(): void;
|
|
36
|
-
click(): void;
|
|
15
|
+
const direction = DIRECTION_MODIFIERS.get(key);
|
|
16
|
+
if (direction !== -1 && direction !== 1) return;
|
|
17
|
+
preventDefault();
|
|
18
|
+
navigate(direction);
|
|
37
19
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import type { View } from 'react-native';
|
|
3
|
+
import { Animated, StyleSheet, type ViewStyle } from 'react-native';
|
|
3
4
|
|
|
4
5
|
import type { GameEntityProps } from '../../../../types/gamePresentation';
|
|
6
|
+
import type { ReactNativeComponentInstance } from '../../../../types/react-native';
|
|
5
7
|
import { withZoraThemeScope } from '../../../theme/adapters/inbound/withZoraThemeScope';
|
|
6
8
|
import { useGameEntityAnimatedStyle } from '../../utils/useGameEntityAnimatedStyle';
|
|
7
9
|
import { useGameEntityMeasurement } from '../../utils/useGameEntityMeasurement';
|
|
@@ -11,7 +13,7 @@ export const GameEntity = withZoraThemeScope(GameEntityInner);
|
|
|
11
13
|
|
|
12
14
|
/*** Render the positioned entity inside the inherited ZORA theme scope. */
|
|
13
15
|
function GameEntityInner(props: GameEntityProps) {
|
|
14
|
-
const elementRef = React.useRef<View | null>(null);
|
|
16
|
+
const elementRef = React.useRef<ReactNativeComponentInstance<typeof View> | null>(null);
|
|
15
17
|
const animatedStyle = useGameEntityAnimatedStyle(props);
|
|
16
18
|
useGameEntityMeasurement(elementRef, props.measurementId);
|
|
17
19
|
|
|
@@ -73,7 +73,20 @@ function createGameInputZoneKeyboardProps({
|
|
|
73
73
|
if (Platform.OS !== 'web' || !enabled || keyboardBindings === undefined) return {};
|
|
74
74
|
if (keyboardBindings.length === 0) return {};
|
|
75
75
|
|
|
76
|
-
return {
|
|
76
|
+
return {
|
|
77
|
+
onKeyDown: (event: GameInputZoneKeyboardEvent) =>
|
|
78
|
+
dispatchKeyboard({
|
|
79
|
+
key: event.nativeEvent?.key ?? event.key ?? '',
|
|
80
|
+
preventDefault: () => event.preventDefault(),
|
|
81
|
+
}),
|
|
82
|
+
tabIndex: 0 as const,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface GameInputZoneKeyboardEvent {
|
|
87
|
+
readonly key?: string;
|
|
88
|
+
readonly nativeEvent?: { readonly key?: string };
|
|
89
|
+
preventDefault(): void;
|
|
77
90
|
}
|
|
78
91
|
|
|
79
92
|
interface InputZoneStyleInput {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { View } from 'react-native';
|
|
2
2
|
|
|
3
3
|
import type { GameMeasurementBounds } from '../../../types/gameRuntime';
|
|
4
|
+
import type { ReactNativeComponentInstance } from '../../../types/react-native';
|
|
4
5
|
|
|
5
6
|
/*** Measure one rendered React Native or React Native Web game entity in window coordinates. */
|
|
6
7
|
export function measureGameEntity(
|
|
7
|
-
element: View | null,
|
|
8
|
+
element: ReactNativeComponentInstance<typeof View> | null,
|
|
8
9
|
): Promise<GameMeasurementBounds | undefined> {
|
|
9
10
|
if (element === null) return Promise.resolve(undefined);
|
|
10
11
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { View } from 'react-native';
|
|
3
3
|
|
|
4
|
+
import type { ReactNativeComponentInstance } from '../../../types/react-native';
|
|
4
5
|
import { GameRuntimeContext } from '../composition/GameRuntimeContext';
|
|
5
6
|
import { measureGameEntity } from './measureGameEntity';
|
|
6
7
|
|
|
7
8
|
/*** Register one optional measurable GameEntity view inside its local Game scope. */
|
|
8
9
|
export function useGameEntityMeasurement(
|
|
9
|
-
elementRef: React.RefObject<View | null>,
|
|
10
|
+
elementRef: React.RefObject<ReactNativeComponentInstance<typeof View> | null>,
|
|
10
11
|
measurementId: string | undefined,
|
|
11
12
|
): void {
|
|
12
13
|
const runtime = React.useContext(GameRuntimeContext);
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
GridInteractionsController,
|
|
6
6
|
GridInteractionsProps,
|
|
7
7
|
} from '../../../../types/grid-interactions';
|
|
8
|
+
import type { ReactNativeComponentInstance } from '../../../../types/react-native';
|
|
8
9
|
import { createGridInteractionsController } from '../../application/createGridInteractionsController';
|
|
9
10
|
import { createGridInteractionsPointerQueue } from './createGridInteractionsPointerQueue';
|
|
10
11
|
import { GridInteractionsKeyboardProxy } from './GridInteractionsKeyboardProxy';
|
|
@@ -26,7 +27,7 @@ export function GridInteractions({
|
|
|
26
27
|
const [controller] = React.useState<GridInteractionsController>(() =>
|
|
27
28
|
createGridInteractionsController(controllerProps),
|
|
28
29
|
);
|
|
29
|
-
const surfaceRef = React.useRef<View
|
|
30
|
+
const surfaceRef = React.useRef<ReactNativeComponentInstance<typeof View>>(null);
|
|
30
31
|
const spaceKeyRef = React.useRef(false);
|
|
31
32
|
const [pointerQueue] = React.useState(() => createGridInteractionsPointerQueue());
|
|
32
33
|
const scrollLock = useGridInteractionScrollLock();
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
} from 'react-native';
|
|
19
19
|
|
|
20
20
|
import type { GridScrollAxis, GridScrollSync, GridViewProps } from '../../../../types/grid-view';
|
|
21
|
+
import type { ReactNativeComponentInstance } from '../../../../types/react-native';
|
|
21
22
|
import { createGridScrollSync } from '../../application/createGridScrollSync';
|
|
22
23
|
|
|
23
24
|
type PinchGesture = Readonly<{ distance: number; focalPoint: GridPoint }>;
|
|
@@ -58,9 +59,11 @@ export function GridView({
|
|
|
58
59
|
const [uncontrolledViewport, setUncontrolledViewport] = React.useState(() =>
|
|
59
60
|
createInitialViewport(width, height, zoom, defaultViewport),
|
|
60
61
|
);
|
|
61
|
-
const horizontalScrollRef =
|
|
62
|
-
|
|
63
|
-
const
|
|
62
|
+
const horizontalScrollRef =
|
|
63
|
+
React.useRef<ReactNativeComponentInstance<typeof NativeScrollView>>(null);
|
|
64
|
+
const verticalScrollRef =
|
|
65
|
+
React.useRef<ReactNativeComponentInstance<typeof NativeScrollView>>(null);
|
|
66
|
+
const gridRef = React.useRef<ReactNativeComponentInstance<typeof NativeView>>(null);
|
|
64
67
|
const panRef = React.useRef<(displacement: GridPoint) => void>(() => undefined);
|
|
65
68
|
const scrollSyncRef = React.useRef<GridScrollSync | undefined>(undefined);
|
|
66
69
|
const pinchGestureRef = React.useRef<PinchGesture | undefined>(undefined);
|
|
@@ -61,9 +61,9 @@ function FlatListInner({
|
|
|
61
61
|
}
|
|
62
62
|
showsHorizontalScrollIndicator={showsScrollIndicator}
|
|
63
63
|
showsVerticalScrollIndicator={showsScrollIndicator}
|
|
64
|
-
ListHeaderComponent={headerText ? <Text>{headerText}</Text> :
|
|
65
|
-
ListFooterComponent={footerText ? <Text>{footerText}</Text> :
|
|
66
|
-
ListEmptyComponent={emptyText ? <Text>{emptyText}</Text> :
|
|
64
|
+
ListHeaderComponent={headerText ? <Text>{headerText}</Text> : undefined}
|
|
65
|
+
ListFooterComponent={footerText ? <Text>{footerText}</Text> : undefined}
|
|
66
|
+
ListEmptyComponent={emptyText ? <Text>{emptyText}</Text> : undefined}
|
|
67
67
|
testID={testID}
|
|
68
68
|
/>
|
|
69
69
|
);
|
|
@@ -68,9 +68,9 @@ function SectionListInner({
|
|
|
68
68
|
}
|
|
69
69
|
showsHorizontalScrollIndicator={showsScrollIndicator}
|
|
70
70
|
showsVerticalScrollIndicator={showsScrollIndicator}
|
|
71
|
-
ListHeaderComponent={headerText ? <Text>{headerText}</Text> :
|
|
72
|
-
ListFooterComponent={footerText ? <Text>{footerText}</Text> :
|
|
73
|
-
ListEmptyComponent={emptyText ? <Text>{emptyText}</Text> :
|
|
71
|
+
ListHeaderComponent={headerText ? <Text>{headerText}</Text> : undefined}
|
|
72
|
+
ListFooterComponent={footerText ? <Text>{footerText}</Text> : undefined}
|
|
73
|
+
ListEmptyComponent={emptyText ? <Text>{emptyText}</Text> : undefined}
|
|
74
74
|
testID={testID}
|
|
75
75
|
/>
|
|
76
76
|
);
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { FlatList } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import type { ManifestListProps } from '../../../../types/manifest-list';
|
|
5
5
|
|
|
6
|
+
type NativeViewToken = Parameters<
|
|
7
|
+
NonNullable<React.ComponentProps<typeof FlatList>['onViewableItemsChanged']>
|
|
8
|
+
>[0]['viewableItems'][number];
|
|
9
|
+
|
|
6
10
|
/*** Keeps the native visibility callback stable and emits only serializable item identities. */
|
|
7
11
|
export function useListVisibility(
|
|
8
12
|
onVisibleItemsChange: ManifestListProps['onVisibleItemsChange'],
|
|
@@ -14,11 +18,11 @@ export function useListVisibility(
|
|
|
14
18
|
handler.current = onVisibleItemsChange;
|
|
15
19
|
disabled.current = passive;
|
|
16
20
|
}, [onVisibleItemsChange, passive]);
|
|
17
|
-
return React.useCallback(({ viewableItems }: { viewableItems:
|
|
21
|
+
return React.useCallback(({ viewableItems }: { viewableItems: NativeViewToken[] }) => {
|
|
18
22
|
if (!disabled.current)
|
|
19
23
|
handler.current?.({
|
|
20
24
|
keys: viewableItems
|
|
21
|
-
.filter((item) => item.isViewable && item.index
|
|
25
|
+
.filter((item) => item.isViewable && typeof item.index === 'number' && item.index >= 0)
|
|
22
26
|
.map((item) => item.key),
|
|
23
27
|
});
|
|
24
28
|
}, []);
|
|
@@ -105,6 +105,13 @@ export function useReaderController(props: ControllerProps) {
|
|
|
105
105
|
/*** Resolve a ZORA file source to the independent ReaderView's URI. */
|
|
106
106
|
function resolveReaderSourceUri(source: ReaderProps['source']): string | undefined {
|
|
107
107
|
if (typeof source === 'string') return source;
|
|
108
|
-
if (typeof source === 'number')
|
|
108
|
+
if (typeof source === 'number') {
|
|
109
|
+
return resolveReaderAssetUri(Image.resolveAssetSource(source));
|
|
110
|
+
}
|
|
109
111
|
return source?.uri;
|
|
110
112
|
}
|
|
113
|
+
|
|
114
|
+
/*** Extract the URI from either supported React Native asset-source result shape. */
|
|
115
|
+
function resolveReaderAssetUri(asset: { readonly uri: string } | undefined): string | undefined {
|
|
116
|
+
return asset?.uri;
|
|
117
|
+
}
|
|
@@ -3,6 +3,6 @@ import type { ActivityIndicatorProps as ReactNativeActivityIndicatorProps } from
|
|
|
3
3
|
import type { ZoraBaseProps } from './base';
|
|
4
4
|
|
|
5
5
|
export interface ActivityIndicatorProps
|
|
6
|
-
extends ZoraBaseProps, Omit<ReactNativeActivityIndicatorProps, 'color'> {
|
|
6
|
+
extends ZoraBaseProps, Omit<ReactNativeActivityIndicatorProps, 'color' | 'testID'> {
|
|
7
7
|
color?: ReactNativeActivityIndicatorProps['color'];
|
|
8
8
|
}
|
package/src/types/layout.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type ZoraContentWidth = 'narrow' | 'default' | 'wide';
|
|
|
12
12
|
|
|
13
13
|
export interface ViewProps extends ZoraBaseProps, Omit<SurfaceViewProps, 'mode' | 'themeId'> {}
|
|
14
14
|
export interface ScrollViewProps
|
|
15
|
-
extends ZoraBaseProps, Omit<SurfaceScrollViewProps, 'mode' | 'themeId'> {}
|
|
15
|
+
extends ZoraBaseProps, Omit<SurfaceScrollViewProps, 'mode' | 'testID' | 'themeId'> {}
|
|
16
16
|
export interface DividerProps
|
|
17
17
|
extends ZoraBaseProps, Omit<SurfaceDividerProps, 'mode' | 'themeId'> {}
|
|
18
18
|
export interface GridProps extends ZoraBaseProps, Omit<SurfaceGridProps, 'mode' | 'themeId'> {}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
|
|
3
|
+
/** The instance accepted by a React Native component ref across supported React Native type APIs. */
|
|
4
|
+
export type ReactNativeComponentInstance<TComponent extends React.ElementType> =
|
|
5
|
+
React.ComponentPropsWithRef<TComponent> extends { readonly ref?: infer TRef }
|
|
6
|
+
? Exclude<TRef, string | null | undefined> extends React.Ref<infer TInstance>
|
|
7
|
+
? TInstance
|
|
8
|
+
: never
|
|
9
|
+
: never;
|
|
@@ -1406,7 +1406,13 @@ function createGameInputZoneKeyboardProps({
|
|
|
1406
1406
|
return {};
|
|
1407
1407
|
if (keyboardBindings.length === 0)
|
|
1408
1408
|
return {};
|
|
1409
|
-
return {
|
|
1409
|
+
return {
|
|
1410
|
+
onKeyDown: (event) => dispatchKeyboard({
|
|
1411
|
+
key: event.nativeEvent?.key ?? event.key ?? "",
|
|
1412
|
+
preventDefault: () => event.preventDefault()
|
|
1413
|
+
}),
|
|
1414
|
+
tabIndex: 0
|
|
1415
|
+
};
|
|
1410
1416
|
}
|
|
1411
1417
|
function createInputZoneStyle({ x, y, width, height, zIndex }) {
|
|
1412
1418
|
return {
|
|
@@ -259,24 +259,17 @@ var DIRECTION_MODIFIERS = new Map([
|
|
|
259
259
|
]);
|
|
260
260
|
|
|
261
261
|
// src/features/form/radio/utils/handleRadioOptionKeyDown.ts
|
|
262
|
-
function handleRadioOptionKeyDown(
|
|
263
|
-
if (
|
|
264
|
-
|
|
262
|
+
function handleRadioOptionKeyDown(key, preventDefault, select, navigate) {
|
|
263
|
+
if (key === " ") {
|
|
264
|
+
preventDefault();
|
|
265
265
|
select();
|
|
266
266
|
return;
|
|
267
267
|
}
|
|
268
|
-
const direction = DIRECTION_MODIFIERS.get(
|
|
269
|
-
if (direction
|
|
268
|
+
const direction = DIRECTION_MODIFIERS.get(key);
|
|
269
|
+
if (direction !== -1 && direction !== 1)
|
|
270
270
|
return;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const index = options.indexOf(event.currentTarget);
|
|
274
|
-
if (index < 0 || options.length === 0)
|
|
275
|
-
return;
|
|
276
|
-
event.preventDefault();
|
|
277
|
-
const next = options.at((index + direction + options.length) % options.length);
|
|
278
|
-
next?.focus();
|
|
279
|
-
next?.click();
|
|
271
|
+
preventDefault();
|
|
272
|
+
navigate(direction);
|
|
280
273
|
}
|
|
281
274
|
|
|
282
275
|
// src/features/form/radio/utils/resolveRadioOptionColors.ts
|
|
@@ -310,11 +303,20 @@ function resolveRadioOptionColors(theme, {
|
|
|
310
303
|
import { jsx as jsx3, jsxs as jsxs2, Fragment } from "react/jsx-runtime";
|
|
311
304
|
function RadioOptionControl(props) {
|
|
312
305
|
const { theme } = useTheme();
|
|
313
|
-
const {
|
|
306
|
+
const {
|
|
307
|
+
option,
|
|
308
|
+
checked,
|
|
309
|
+
disabled,
|
|
310
|
+
readOnly,
|
|
311
|
+
interactionPolicy,
|
|
312
|
+
onNavigate,
|
|
313
|
+
onOptionRef,
|
|
314
|
+
onSelect
|
|
315
|
+
} = props;
|
|
314
316
|
const colors = resolveRadioOptionColors(theme, props);
|
|
315
317
|
const [focused, setFocused] = React.useState(false);
|
|
316
318
|
const keyboardProps = import_react_native.Platform.OS === "web" && !readOnly && !disabled && interactionPolicy !== "passive" ? {
|
|
317
|
-
onKeyDown: (event) => handleRadioOptionKeyDown(event, onSelect)
|
|
319
|
+
onKeyDown: (event) => handleRadioOptionKeyDown(event.nativeEvent?.key ?? event.key ?? "", () => event.preventDefault(), onSelect, onNavigate)
|
|
318
320
|
} : {};
|
|
319
321
|
const controlStyle = {
|
|
320
322
|
flex: 1,
|
|
@@ -327,6 +329,7 @@ function RadioOptionControl(props) {
|
|
|
327
329
|
};
|
|
328
330
|
return /* @__PURE__ */ jsx3(import_react_native.Pressable, {
|
|
329
331
|
...keyboardProps,
|
|
332
|
+
ref: onOptionRef,
|
|
330
333
|
accessibilityRole: "radio",
|
|
331
334
|
accessibilityState: { checked, disabled },
|
|
332
335
|
"aria-checked": checked,
|
|
@@ -467,11 +470,28 @@ function RadioGroupInner({
|
|
|
467
470
|
...props
|
|
468
471
|
}) {
|
|
469
472
|
const [localValue, setLocalValue] = React2.useState(props.defaultValue);
|
|
473
|
+
const cardOptionRefs = React2.useRef(new Map);
|
|
470
474
|
const onValueChange = (next) => {
|
|
471
475
|
if (props.value === undefined)
|
|
472
476
|
setLocalValue(next);
|
|
473
477
|
props.onValueChange?.(next);
|
|
474
478
|
};
|
|
479
|
+
const onNavigateCardOption = (currentValue, direction) => {
|
|
480
|
+
const currentIndex = props.options.findIndex((option) => option.value === currentValue);
|
|
481
|
+
if (currentIndex < 0)
|
|
482
|
+
return;
|
|
483
|
+
const nextOption = Array.from({ length: props.options.length - 1 }, (_, offset) => props.options.at((currentIndex + direction * (offset + 1) + props.options.length) % props.options.length)).find((option) => option !== undefined && !props.disabled && !option.disabled);
|
|
484
|
+
if (nextOption === undefined)
|
|
485
|
+
return;
|
|
486
|
+
onValueChange(nextOption.value);
|
|
487
|
+
cardOptionRefs.current.get(nextOption.value)?.focus();
|
|
488
|
+
};
|
|
489
|
+
const onCardOptionRef = (value, element) => {
|
|
490
|
+
if (element === null)
|
|
491
|
+
cardOptionRefs.current.delete(value);
|
|
492
|
+
else
|
|
493
|
+
cardOptionRefs.current.set(value, element);
|
|
494
|
+
};
|
|
475
495
|
const selectedProps = { ...props, value: props.value ?? localValue, onValueChange };
|
|
476
496
|
const themeFields = useZoraThemeRecipe(radioGroupThemeRecipeMeta);
|
|
477
497
|
const recipe = resolveRadioGroupThemeRecipe({ ...props, themeFields });
|
|
@@ -496,6 +516,8 @@ function RadioGroupInner({
|
|
|
496
516
|
children: /* @__PURE__ */ jsx4(RadioGroupItem, {
|
|
497
517
|
...selectedProps,
|
|
498
518
|
...recipe,
|
|
519
|
+
onNavigate: onNavigateCardOption,
|
|
520
|
+
onOptionRef: onCardOptionRef,
|
|
499
521
|
option
|
|
500
522
|
})
|
|
501
523
|
}, option.value)),
|
|
@@ -523,7 +545,7 @@ function RadioGroupInline(props) {
|
|
|
523
545
|
});
|
|
524
546
|
}
|
|
525
547
|
function RadioGroupItem(props) {
|
|
526
|
-
const { option, value, onValueChange, interactionPolicy, color, size } = props;
|
|
548
|
+
const { option, value, onValueChange, interactionPolicy, color, size, onNavigate, onOptionRef } = props;
|
|
527
549
|
const checked = value === option.value;
|
|
528
550
|
const inactive = props.disabled === true || option.disabled === true;
|
|
529
551
|
const readOnly = props.readOnly === true;
|
|
@@ -540,6 +562,8 @@ function RadioGroupItem(props) {
|
|
|
540
562
|
readOnly,
|
|
541
563
|
invalid,
|
|
542
564
|
layout: props.contentOrientation ?? "horizontal",
|
|
565
|
+
onNavigate: (direction) => onNavigate?.(option.value, direction),
|
|
566
|
+
onOptionRef: (element) => onOptionRef?.(option.value, element),
|
|
543
567
|
onSelect
|
|
544
568
|
});
|
|
545
569
|
}
|