@hozo/primitives 0.2.0 → 0.3.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/CHANGELOG.md +27 -0
- package/README.md +17 -0
- package/dist/foundation.d.ts +7 -4
- package/dist/foundation.d.ts.map +1 -1
- package/dist/foundation.js +33 -16
- package/dist/foundation.js.map +1 -1
- package/dist/link.native.d.ts +16 -7
- package/dist/link.native.d.ts.map +1 -1
- package/dist/link.native.js +9 -5
- package/dist/link.native.js.map +1 -1
- package/dist/pressable.d.ts +1 -1
- package/dist/pressable.d.ts.map +1 -1
- package/dist/pressable.js +7 -4
- package/dist/pressable.js.map +1 -1
- package/dist/pressable.native.d.ts.map +1 -1
- package/dist/pressable.native.js +181 -195
- package/dist/pressable.native.js.map +1 -1
- package/dist/runtime-container.native.d.ts +11 -9
- package/dist/runtime-container.native.d.ts.map +1 -1
- package/dist/runtime-container.native.js +8 -6
- package/dist/runtime-container.native.js.map +1 -1
- package/dist/view.d.ts +1 -285
- package/dist/view.d.ts.map +1 -1
- package/dist/view.js +5 -4
- package/dist/view.js.map +1 -1
- package/package.json +3 -3
- package/src/foundation.tsx +66 -25
- package/src/link.native.tsx +29 -18
- package/src/pressable.native.tsx +251 -243
- package/src/pressable.ts +26 -16
- package/src/runtime-container.native.tsx +30 -15
- package/src/view.ts +34 -25
package/src/pressable.ts
CHANGED
|
@@ -2,11 +2,13 @@ import {
|
|
|
2
2
|
type HozoDomStyle,
|
|
3
3
|
hozoDomStyle,
|
|
4
4
|
hozoInteractive,
|
|
5
|
+
hozoViewBase,
|
|
5
6
|
type ResponderProps,
|
|
6
7
|
useResponderDomProps,
|
|
7
8
|
} from '@hozo/engine'
|
|
8
9
|
import {
|
|
9
10
|
createElement,
|
|
11
|
+
Fragment,
|
|
10
12
|
type HTMLAttributes,
|
|
11
13
|
type KeyboardEvent,
|
|
12
14
|
type MouseEvent,
|
|
@@ -236,6 +238,7 @@ export function HozoPressable({
|
|
|
236
238
|
: {
|
|
237
239
|
'aria-disabled': unavailable || undefined,
|
|
238
240
|
'data-hozo-disabled': unavailable ? '' : undefined,
|
|
241
|
+
'data-hozo-pressable': undefined,
|
|
239
242
|
tabIndex: undefined,
|
|
240
243
|
onClick: undefined,
|
|
241
244
|
onKeyDown: undefined,
|
|
@@ -340,22 +343,29 @@ export function HozoPressable({
|
|
|
340
343
|
resolvedChildren,
|
|
341
344
|
)
|
|
342
345
|
}
|
|
346
|
+
// The base stylesheet carries the pointer cursor for `data-hozo-pressable`.
|
|
347
|
+
// Always in a fragment, so gaining a handler never remounts the element.
|
|
343
348
|
return createElement(
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
349
|
+
Fragment,
|
|
350
|
+
null,
|
|
351
|
+
hozoViewBase(),
|
|
352
|
+
createElement(
|
|
353
|
+
'div',
|
|
354
|
+
{
|
|
355
|
+
...common,
|
|
356
|
+
...interaction,
|
|
357
|
+
onKeyDown: (event: KeyboardEvent<HTMLElement>) => {
|
|
358
|
+
if (event.key === 'Enter' || event.key === ' ') pressIn(event)
|
|
359
|
+
interaction.onKeyDown?.(event)
|
|
360
|
+
onKeyDown?.(event as never)
|
|
361
|
+
},
|
|
362
|
+
onKeyUp: (event: KeyboardEvent<HTMLElement>) => {
|
|
363
|
+
if (event.key === 'Enter' || event.key === ' ') pressOut(event)
|
|
364
|
+
interaction.onKeyUp?.(event)
|
|
365
|
+
onKeyUp?.(event as never)
|
|
366
|
+
},
|
|
367
|
+
} as unknown as HTMLAttributes<HTMLDivElement>,
|
|
368
|
+
resolvedChildren,
|
|
369
|
+
),
|
|
360
370
|
)
|
|
361
371
|
}
|
|
@@ -16,8 +16,16 @@
|
|
|
16
16
|
// component boundary between the provider and the read, and adding a View
|
|
17
17
|
// to do that would change the layout the query is measuring.
|
|
18
18
|
|
|
19
|
-
import {
|
|
20
|
-
|
|
19
|
+
import {
|
|
20
|
+
type ComponentPropsWithRef,
|
|
21
|
+
createContext,
|
|
22
|
+
type ElementType,
|
|
23
|
+
type ReactNode,
|
|
24
|
+
useContext,
|
|
25
|
+
useMemo,
|
|
26
|
+
useState,
|
|
27
|
+
} from 'react'
|
|
28
|
+
import { type LayoutChangeEvent, View } from 'react-native'
|
|
21
29
|
|
|
22
30
|
import { keepIfSettled } from './runtime-measured.ts'
|
|
23
31
|
|
|
@@ -39,24 +47,29 @@ export type HozoContainerWidths = Readonly<Record<string, number | undefined>>
|
|
|
39
47
|
|
|
40
48
|
const HozoContainerContext = createContext<HozoContainerWidths>({})
|
|
41
49
|
|
|
42
|
-
export
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
export type HozoContainerProps<Host extends ElementType = typeof View> =
|
|
51
|
+
ComponentPropsWithRef<Host> & {
|
|
52
|
+
/** Compiler-selected host: measurement must not turn a control into a View. */
|
|
53
|
+
hozoContainerComponent?: Host
|
|
54
|
+
/** `@container/main` -- the name `@sm/main:` addresses. */
|
|
55
|
+
hozoContainerName?: string
|
|
56
|
+
}
|
|
47
57
|
|
|
48
58
|
/**
|
|
49
|
-
*
|
|
59
|
+
* Measures the existing host and hands its width to its subtree.
|
|
50
60
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
61
|
+
* A provider adds no layout node. The host keeps its own style/children
|
|
62
|
+
* callbacks, refs and events rather than asking a replacement View to
|
|
63
|
+
* approximate them. An ordinary container still defaults to View.
|
|
53
64
|
*/
|
|
54
|
-
export function HozoContainer({
|
|
65
|
+
export function HozoContainer<Host extends ElementType = typeof View>({
|
|
66
|
+
hozoContainerComponent,
|
|
55
67
|
hozoContainerName,
|
|
56
68
|
onLayout,
|
|
57
69
|
children,
|
|
58
70
|
...rest
|
|
59
|
-
}: HozoContainerProps): ReactNode {
|
|
71
|
+
}: HozoContainerProps<Host>): ReactNode {
|
|
72
|
+
const Component: ElementType = hozoContainerComponent ?? View
|
|
60
73
|
const [width, setWidth] = useState<number | undefined>(undefined)
|
|
61
74
|
const outer = useContext(HozoContainerContext)
|
|
62
75
|
|
|
@@ -82,9 +95,11 @@ export function HozoContainer({
|
|
|
82
95
|
}
|
|
83
96
|
|
|
84
97
|
return (
|
|
85
|
-
<
|
|
86
|
-
<
|
|
87
|
-
|
|
98
|
+
<HozoContainerContext.Provider value={widths}>
|
|
99
|
+
<Component {...rest} onLayout={measure}>
|
|
100
|
+
{children}
|
|
101
|
+
</Component>
|
|
102
|
+
</HozoContainerContext.Provider>
|
|
88
103
|
)
|
|
89
104
|
}
|
|
90
105
|
|
package/src/view.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type HozoDomStyle,
|
|
3
3
|
hozoDomStyle,
|
|
4
|
+
hozoViewBase,
|
|
5
|
+
hozoViewClassName,
|
|
4
6
|
type ResponderProps,
|
|
5
7
|
useResponderDomProps,
|
|
6
8
|
} from '@hozo/engine'
|
|
7
9
|
import {
|
|
8
10
|
createElement,
|
|
11
|
+
Fragment,
|
|
9
12
|
type HTMLAttributes,
|
|
10
13
|
type ReactNode,
|
|
11
14
|
type Ref,
|
|
@@ -142,30 +145,36 @@ export function HozoView({
|
|
|
142
145
|
const state = accessibilityState
|
|
143
146
|
const value = accessibilityValue
|
|
144
147
|
return createElement(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
148
|
+
Fragment,
|
|
149
|
+
null,
|
|
150
|
+
hozoViewBase(),
|
|
151
|
+
createElement(
|
|
152
|
+
'div',
|
|
153
|
+
{
|
|
154
|
+
...props,
|
|
155
|
+
className: hozoViewClassName(props.className),
|
|
156
|
+
...responder,
|
|
157
|
+
ref: setRef,
|
|
158
|
+
role: accessibilityRole ?? role,
|
|
159
|
+
style: hozoDomStyle(style),
|
|
160
|
+
'data-testid': testID,
|
|
161
|
+
id: nativeID,
|
|
162
|
+
'data-hozo-pointer-events': pointerEvents,
|
|
163
|
+
'data-hozo-disabled': state?.disabled ? '' : dataHozoDisabled,
|
|
164
|
+
'aria-disabled': state?.disabled ? true : ariaDisabled,
|
|
165
|
+
'aria-selected': state?.selected,
|
|
166
|
+
'aria-checked': state?.checked,
|
|
167
|
+
'aria-busy': state?.busy,
|
|
168
|
+
'aria-expanded': state?.expanded,
|
|
169
|
+
'aria-valuemin': value?.min,
|
|
170
|
+
'aria-valuemax': value?.max,
|
|
171
|
+
'aria-valuenow': value?.now,
|
|
172
|
+
'aria-valuetext': value?.text,
|
|
173
|
+
'aria-live': accessibilityLiveRegion === 'none' ? undefined : accessibilityLiveRegion,
|
|
174
|
+
'aria-label': accessibilityLabel,
|
|
175
|
+
'aria-description': accessibilityHint,
|
|
176
|
+
},
|
|
177
|
+
children,
|
|
178
|
+
),
|
|
170
179
|
)
|
|
171
180
|
}
|