@hozo/primitives 0.2.0 → 0.4.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 +71 -0
- package/README.md +18 -1
- package/dist/button-host-attributes.d.ts +20 -0
- package/dist/button-host-attributes.d.ts.map +1 -0
- package/dist/button-host-attributes.js +47 -0
- package/dist/button-host-attributes.js.map +1 -0
- package/dist/button-host-props.native.d.ts +8 -0
- package/dist/button-host-props.native.d.ts.map +1 -0
- package/dist/button-host-props.native.js +20 -0
- package/dist/button-host-props.native.js.map +1 -0
- package/dist/foundation.d.ts +27 -6
- package/dist/foundation.d.ts.map +1 -1
- package/dist/foundation.js +72 -19
- package/dist/foundation.js.map +1 -1
- package/dist/foundation.native.d.ts +27 -7
- package/dist/foundation.native.d.ts.map +1 -1
- package/dist/foundation.native.js +18 -3
- package/dist/foundation.native.js.map +1 -1
- package/dist/generated/button-dom-props.d.ts +11 -0
- package/dist/generated/button-dom-props.d.ts.map +1 -0
- package/dist/generated/button-dom-props.js +132 -0
- package/dist/generated/button-dom-props.js.map +1 -0
- package/dist/generated/button-props.d.ts +3 -0
- package/dist/generated/button-props.d.ts.map +1 -0
- package/dist/generated/button-props.js +5 -0
- package/dist/generated/button-props.js.map +1 -0
- package/dist/generated/button-props.native.d.ts +2 -0
- package/dist/generated/button-props.native.d.ts.map +1 -0
- package/dist/generated/button-props.native.js +2 -0
- package/dist/generated/button-props.native.js.map +1 -0
- package/dist/generated/inherited-label.d.ts +2 -0
- package/dist/generated/inherited-label.d.ts.map +1 -0
- package/dist/generated/inherited-label.js +3 -0
- package/dist/generated/inherited-label.js.map +1 -0
- package/dist/generated/inherited-pressable.d.ts +2 -0
- package/dist/generated/inherited-pressable.d.ts.map +1 -0
- package/dist/generated/inherited-pressable.js +3 -0
- package/dist/generated/inherited-pressable.js.map +1 -0
- package/dist/generated/inherited-relative-text.d.ts +2 -0
- package/dist/generated/inherited-relative-text.d.ts.map +1 -0
- package/dist/generated/inherited-relative-text.js +3 -0
- package/dist/generated/inherited-relative-text.js.map +1 -0
- package/dist/generated/inherited-text.d.ts +2 -0
- package/dist/generated/inherited-text.d.ts.map +1 -0
- package/dist/generated/inherited-text.js +3 -0
- package/dist/generated/inherited-text.js.map +1 -0
- package/dist/generated/inherited-view.d.ts +2 -0
- package/dist/generated/inherited-view.d.ts.map +1 -0
- package/dist/generated/inherited-view.js +3 -0
- package/dist/generated/inherited-view.js.map +1 -0
- package/dist/generated/native-disabled.d.ts +2 -0
- package/dist/generated/native-disabled.d.ts.map +1 -0
- package/dist/generated/native-disabled.js +2 -0
- package/dist/generated/native-disabled.js.map +1 -0
- package/dist/generated/text-input-dom-props.d.ts +7 -0
- package/dist/generated/text-input-dom-props.d.ts.map +1 -0
- package/dist/generated/text-input-dom-props.js +130 -0
- package/dist/generated/text-input-dom-props.js.map +1 -0
- package/dist/generated/text-input.native.d.ts +1 -1
- package/dist/generated/text-input.native.d.ts.map +1 -1
- package/dist/generated/text-input.native.js +1 -1
- package/dist/generated/text-input.native.js.map +1 -1
- package/dist/generated/view-dom-props.d.ts +8 -0
- package/dist/generated/view-dom-props.d.ts.map +1 -0
- package/dist/generated/view-dom-props.js +241 -0
- package/dist/generated/view-dom-props.js.map +1 -0
- package/dist/inherited-label.native.d.ts +8 -0
- package/dist/inherited-label.native.d.ts.map +1 -0
- package/dist/inherited-label.native.js +12 -0
- package/dist/inherited-label.native.js.map +1 -0
- package/dist/inherited-pressable.native.d.ts +11 -0
- package/dist/inherited-pressable.native.d.ts.map +1 -0
- package/dist/inherited-pressable.native.js +75 -0
- package/dist/inherited-pressable.native.js.map +1 -0
- package/dist/inherited-relative-text.native.d.ts +13 -0
- package/dist/inherited-relative-text.native.d.ts.map +1 -0
- package/dist/inherited-relative-text.native.js +16 -0
- package/dist/inherited-relative-text.native.js.map +1 -0
- package/dist/inherited-text-scope.d.ts +8 -0
- package/dist/inherited-text-scope.d.ts.map +1 -0
- package/dist/inherited-text-scope.js +10 -0
- package/dist/inherited-text-scope.js.map +1 -0
- package/dist/inherited-text-style.native.d.ts +5 -0
- package/dist/inherited-text-style.native.d.ts.map +1 -0
- package/dist/inherited-text-style.native.js +30 -0
- package/dist/inherited-text-style.native.js.map +1 -0
- package/dist/inherited-text.native.d.ts +5 -0
- package/dist/inherited-text.native.d.ts.map +1 -0
- package/dist/inherited-text.native.js +18 -0
- package/dist/inherited-text.native.js.map +1 -0
- package/dist/inherited-view.native.d.ts +9 -0
- package/dist/inherited-view.native.d.ts.map +1 -0
- package/dist/inherited-view.native.js +17 -0
- package/dist/inherited-view.native.js.map +1 -0
- package/dist/link.d.ts +4 -3
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +9 -1
- package/dist/link.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 +15 -5
- package/dist/link.native.js.map +1 -1
- package/dist/native-disabled.d.ts +13 -0
- package/dist/native-disabled.d.ts.map +1 -0
- package/dist/native-disabled.js +13 -0
- package/dist/native-disabled.js.map +1 -0
- package/dist/presence.native.d.ts.map +1 -1
- package/dist/presence.native.js +1 -1
- package/dist/presence.native.js.map +1 -1
- package/dist/pressable.d.ts +1 -1
- package/dist/pressable.d.ts.map +1 -1
- package/dist/pressable.js +15 -5
- package/dist/pressable.js.map +1 -1
- package/dist/pressable.native.d.ts +10 -1
- package/dist/pressable.native.d.ts.map +1 -1
- package/dist/pressable.native.js +206 -221
- 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/text-color-transition.native.d.ts +12 -0
- package/dist/text-color-transition.native.d.ts.map +1 -0
- package/dist/text-color-transition.native.js +87 -0
- package/dist/text-color-transition.native.js.map +1 -0
- package/dist/text-input-props.native.d.ts +10 -0
- package/dist/text-input-props.native.d.ts.map +1 -0
- package/dist/text-input-props.native.js +15 -0
- package/dist/text-input-props.native.js.map +1 -0
- package/dist/text-input.native.d.ts +19 -0
- package/dist/text-input.native.d.ts.map +1 -0
- package/dist/text-input.native.js +32 -0
- package/dist/text-input.native.js.map +1 -0
- 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 +51 -7
- package/src/button-host-attributes.ts +56 -0
- package/src/button-host-props.native.ts +22 -0
- package/src/foundation.native.tsx +45 -6
- package/src/foundation.tsx +139 -28
- package/src/generated/button-dom-props.ts +127 -0
- package/src/generated/button-props.native.ts +1 -0
- package/src/generated/button-props.ts +4 -0
- package/src/generated/inherited-label.ts +2 -0
- package/src/generated/inherited-pressable.ts +2 -0
- package/src/generated/inherited-relative-text.ts +2 -0
- package/src/generated/inherited-text.ts +2 -0
- package/src/generated/inherited-view.ts +2 -0
- package/src/generated/native-disabled.ts +1 -0
- package/src/generated/text-input-dom-props.ts +128 -0
- package/src/generated/text-input.native.ts +1 -4
- package/src/generated/view-dom-props.ts +267 -0
- package/src/inherited-label.native.tsx +28 -0
- package/src/inherited-pressable.native.tsx +152 -0
- package/src/inherited-relative-text.native.tsx +22 -0
- package/src/inherited-text-scope.tsx +27 -0
- package/src/inherited-text-style.native.ts +35 -0
- package/src/inherited-text.native.tsx +32 -0
- package/src/inherited-view.native.tsx +37 -0
- package/src/link.native.tsx +43 -28
- package/src/link.ts +12 -0
- package/src/native-disabled.ts +23 -0
- package/src/presence.native.tsx +1 -1
- package/src/pressable.native.tsx +298 -262
- package/src/pressable.ts +34 -17
- package/src/runtime-container.native.tsx +30 -15
- package/src/text-color-transition.native.ts +96 -0
- package/src/text-input-props.native.ts +26 -0
- package/src/text-input.native.tsx +57 -0
- package/src/view.ts +34 -25
- package/dist/generated/animated.d.ts +0 -2
- package/dist/generated/animated.d.ts.map +0 -1
- package/dist/generated/animated.js +0 -3
- package/dist/generated/animated.js.map +0 -1
- package/dist/presence-context.d.ts +0 -15
- package/dist/presence-context.d.ts.map +0 -1
- package/dist/presence-context.js +0 -11
- package/dist/presence-context.js.map +0 -1
- package/dist/runtime-transition.native.d.ts +0 -30
- package/dist/runtime-transition.native.d.ts.map +0 -1
- package/dist/runtime-transition.native.js +0 -183
- package/dist/runtime-transition.native.js.map +0 -1
- package/src/generated/animated.ts +0 -6
- package/src/presence-context.ts +0 -27
- package/src/runtime-transition.native.tsx +0 -244
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,
|
|
@@ -323,6 +326,13 @@ export function HozoPressable({
|
|
|
323
326
|
HozoLink,
|
|
324
327
|
{
|
|
325
328
|
...common,
|
|
329
|
+
// common is already DOM-shaped. HozoLink normalizes its canonical
|
|
330
|
+
// identity/name props itself; omitting these let its undefined
|
|
331
|
+
// defaults overwrite the id and label just passed in common.
|
|
332
|
+
nativeID,
|
|
333
|
+
testID,
|
|
334
|
+
accessibilityLabel,
|
|
335
|
+
accessibilityHint,
|
|
326
336
|
ref: setRef as Ref<HTMLAnchorElement>,
|
|
327
337
|
href,
|
|
328
338
|
external,
|
|
@@ -332,7 +342,7 @@ export function HozoPressable({
|
|
|
332
342
|
rel,
|
|
333
343
|
download,
|
|
334
344
|
disabled: unavailable,
|
|
335
|
-
accessibilityRole,
|
|
345
|
+
accessibilityRole: accessibilityRole ?? role,
|
|
336
346
|
onPress: unavailable ? undefined : (activate as never),
|
|
337
347
|
onKeyDown,
|
|
338
348
|
onKeyUp,
|
|
@@ -340,22 +350,29 @@ export function HozoPressable({
|
|
|
340
350
|
resolvedChildren,
|
|
341
351
|
)
|
|
342
352
|
}
|
|
353
|
+
// The base stylesheet carries the pointer cursor for `data-hozo-pressable`.
|
|
354
|
+
// Always in a fragment, so gaining a handler never remounts the element.
|
|
343
355
|
return createElement(
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
356
|
+
Fragment,
|
|
357
|
+
null,
|
|
358
|
+
hozoViewBase(),
|
|
359
|
+
createElement(
|
|
360
|
+
'div',
|
|
361
|
+
{
|
|
362
|
+
...common,
|
|
363
|
+
...interaction,
|
|
364
|
+
onKeyDown: (event: KeyboardEvent<HTMLElement>) => {
|
|
365
|
+
if (event.key === 'Enter' || event.key === ' ') pressIn(event)
|
|
366
|
+
interaction.onKeyDown?.(event)
|
|
367
|
+
onKeyDown?.(event as never)
|
|
368
|
+
},
|
|
369
|
+
onKeyUp: (event: KeyboardEvent<HTMLElement>) => {
|
|
370
|
+
if (event.key === 'Enter' || event.key === ' ') pressOut(event)
|
|
371
|
+
interaction.onKeyUp?.(event)
|
|
372
|
+
onKeyUp?.(event as never)
|
|
373
|
+
},
|
|
374
|
+
} as unknown as HTMLAttributes<HTMLDivElement>,
|
|
375
|
+
resolvedChildren,
|
|
376
|
+
),
|
|
360
377
|
)
|
|
361
378
|
}
|
|
@@ -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
|
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { blendColor } from '@hozo/engine'
|
|
2
|
+
import { useLayoutEffect, useMemo, useRef, useState } from 'react'
|
|
3
|
+
import { Animated, Easing } from 'react-native'
|
|
4
|
+
import type { HozoTransition } from './pressable.native.tsx'
|
|
5
|
+
|
|
6
|
+
type Spec = Pick<HozoTransition, 'duration' | 'delay' | 'easing'>
|
|
7
|
+
|
|
8
|
+
function easingFor(name: Spec['easing']) {
|
|
9
|
+
switch (name) {
|
|
10
|
+
case 'linear':
|
|
11
|
+
return Easing.linear
|
|
12
|
+
case 'ease-in':
|
|
13
|
+
return Easing.in(Easing.ease)
|
|
14
|
+
case 'ease-out':
|
|
15
|
+
return Easing.out(Easing.ease)
|
|
16
|
+
case 'ease-in-out':
|
|
17
|
+
return Easing.inOut(Easing.ease)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* One colour timeline, reusable by a leaf or an inherited label owner.
|
|
23
|
+
* Progress is not reset when retargeting: the new interpolation starts at the
|
|
24
|
+
* observed position. Resetting a live value to zero would briefly send the
|
|
25
|
+
* previous interpolation back to its old starting colour.
|
|
26
|
+
*/
|
|
27
|
+
export function useHozoTextColorTransition(
|
|
28
|
+
target: string | undefined,
|
|
29
|
+
revision: string,
|
|
30
|
+
spec: Spec,
|
|
31
|
+
) {
|
|
32
|
+
const [progress] = useState(() => new Animated.Value(0))
|
|
33
|
+
const position = useRef(0)
|
|
34
|
+
const animation = useRef<Animated.CompositeAnimation | null>(null)
|
|
35
|
+
const [range, setRange] = useState(() => ({
|
|
36
|
+
from: target ?? '',
|
|
37
|
+
to: target ?? '',
|
|
38
|
+
target,
|
|
39
|
+
revision,
|
|
40
|
+
start: 0,
|
|
41
|
+
animate: false,
|
|
42
|
+
}))
|
|
43
|
+
useLayoutEffect(() => {
|
|
44
|
+
const listener = progress.addListener(({ value }) => {
|
|
45
|
+
position.current = value
|
|
46
|
+
})
|
|
47
|
+
return () => {
|
|
48
|
+
progress.removeListener(listener)
|
|
49
|
+
animation.current?.stop()
|
|
50
|
+
}
|
|
51
|
+
}, [progress])
|
|
52
|
+
useLayoutEffect(() => {
|
|
53
|
+
if (range.target === target && range.revision === revision) return
|
|
54
|
+
animation.current?.stop()
|
|
55
|
+
const start = position.current
|
|
56
|
+
const fraction = Math.max(0, Math.min(1, start - range.start))
|
|
57
|
+
const current = range.from ? blendColor(range.from, range.to, fraction) : (target ?? '')
|
|
58
|
+
// Only committed inputs may replace the range. An abandoned Suspense
|
|
59
|
+
// render must not consume the target or mutate the visible timeline.
|
|
60
|
+
setRange({
|
|
61
|
+
from: target ? current : '',
|
|
62
|
+
to: target ?? '',
|
|
63
|
+
target,
|
|
64
|
+
revision,
|
|
65
|
+
start,
|
|
66
|
+
animate: Boolean(target),
|
|
67
|
+
})
|
|
68
|
+
}, [range, target, revision])
|
|
69
|
+
const { duration, delay = 0, easing } = spec
|
|
70
|
+
useLayoutEffect(() => {
|
|
71
|
+
if (!range.animate) return
|
|
72
|
+
const next = Animated.timing(progress, {
|
|
73
|
+
toValue: range.start + 1,
|
|
74
|
+
duration,
|
|
75
|
+
delay,
|
|
76
|
+
easing: easingFor(easing),
|
|
77
|
+
useNativeDriver: false,
|
|
78
|
+
})
|
|
79
|
+
animation.current = next
|
|
80
|
+
next.start()
|
|
81
|
+
return () => {
|
|
82
|
+
next.stop()
|
|
83
|
+
if (animation.current === next) animation.current = null
|
|
84
|
+
}
|
|
85
|
+
}, [progress, range, duration, delay, easing])
|
|
86
|
+
return useMemo(
|
|
87
|
+
() =>
|
|
88
|
+
range.from
|
|
89
|
+
? progress.interpolate({
|
|
90
|
+
inputRange: [range.start, range.start + 1],
|
|
91
|
+
outputRange: [range.from, range.to],
|
|
92
|
+
})
|
|
93
|
+
: undefined,
|
|
94
|
+
[progress, range],
|
|
95
|
+
)
|
|
96
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TextInputProps as RNTextInputProps } from 'react-native'
|
|
2
|
+
|
|
3
|
+
/** Canonical disabled is distinct from an editable/read-only field. */
|
|
4
|
+
export interface NativeTextInputProps extends RNTextInputProps {
|
|
5
|
+
disabled?: boolean
|
|
6
|
+
className?: string
|
|
7
|
+
'aria-invalid'?: boolean | 'false' | 'true' | 'grammar' | 'spelling'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Shared by value-level and generated hosts; RN has no disabled input prop. */
|
|
11
|
+
export function nativeTextInputProps({
|
|
12
|
+
disabled,
|
|
13
|
+
'aria-invalid': _invalid,
|
|
14
|
+
...props
|
|
15
|
+
}: NativeTextInputProps): RNTextInputProps {
|
|
16
|
+
if (!disabled) return props
|
|
17
|
+
// Both RN spellings must prevent editing even if the caller authored
|
|
18
|
+
// readOnly=false. Do not turn ordinary read-only fields into disabled ones.
|
|
19
|
+
return {
|
|
20
|
+
...props,
|
|
21
|
+
editable: false,
|
|
22
|
+
readOnly: true,
|
|
23
|
+
accessibilityState: { ...props.accessibilityState, disabled: true },
|
|
24
|
+
'aria-disabled': true,
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type HozoPressableInteractionState,
|
|
3
|
+
usePressableInteraction,
|
|
4
|
+
} from '@hozo/behaviors/pressable-interaction'
|
|
5
|
+
import type { ComponentRef, Ref } from 'react'
|
|
6
|
+
import { TextInput, type TextInputProps } from 'react-native'
|
|
7
|
+
import { type NativeTextInputProps, nativeTextInputProps } from './text-input-props.native.ts'
|
|
8
|
+
|
|
9
|
+
export interface HozoTextInputProps extends NativeTextInputProps {
|
|
10
|
+
ref?: Ref<ComponentRef<typeof TextInput>>
|
|
11
|
+
/** Compiler-only style evaluation on this input, not an ancestor Pressable. */
|
|
12
|
+
hozoStyle?: (state: HozoPressableInteractionState) => TextInputProps['style']
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Generated-code host when static or dynamic classes need input focus. Ordinary
|
|
17
|
+
* compiled inputs stay RN TextInput. No extra box, context, animation or
|
|
18
|
+
* subscriptions; the same native field keeps its ref, events and semantics.
|
|
19
|
+
*
|
|
20
|
+
* A keyboard-input field indicates focus even after a pointer/touch focuses
|
|
21
|
+
* it (Selectors 4 §9.4). A button's pointer modality is not its policy.
|
|
22
|
+
*/
|
|
23
|
+
export function HozoTextInput(props: HozoTextInputProps) {
|
|
24
|
+
// A prop-only adapter needs no state subscription. The focus child exists
|
|
25
|
+
// only for a compiler callback and still renders exactly one RN field.
|
|
26
|
+
if (!props.hozoStyle) {
|
|
27
|
+
const { hozoStyle: _hozoStyle, ref, ...hostProps } = props
|
|
28
|
+
return <TextInput {...nativeTextInputProps(hostProps)} ref={ref} />
|
|
29
|
+
}
|
|
30
|
+
return <FocusedTextInput {...props} />
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function FocusedTextInput({
|
|
34
|
+
ref,
|
|
35
|
+
hozoStyle,
|
|
36
|
+
style,
|
|
37
|
+
onFocus,
|
|
38
|
+
onBlur,
|
|
39
|
+
...props
|
|
40
|
+
}: HozoTextInputProps) {
|
|
41
|
+
const { state, handlers } = usePressableInteraction({ focusVisible: 'keyboard-input' })
|
|
42
|
+
return (
|
|
43
|
+
<TextInput
|
|
44
|
+
{...nativeTextInputProps(props)}
|
|
45
|
+
ref={ref}
|
|
46
|
+
style={[hozoStyle?.(state), style]}
|
|
47
|
+
onFocus={(event) => {
|
|
48
|
+
handlers.focus()
|
|
49
|
+
onFocus?.(event)
|
|
50
|
+
}}
|
|
51
|
+
onBlur={(event) => {
|
|
52
|
+
handlers.blur()
|
|
53
|
+
onBlur?.(event)
|
|
54
|
+
}}
|
|
55
|
+
/>
|
|
56
|
+
)
|
|
57
|
+
}
|
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
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"animated.d.ts","sourceRoot":"","sources":["../../src/generated/animated.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,kCAAkC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"animated.js","sourceRoot":"","sources":["../../src/generated/animated.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,OAAO,EACL,YAAY,GAGb,MAAM,iCAAkC,CAAA"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type PresenceState = 'open' | 'closed';
|
|
2
|
-
export interface PresenceContextValue {
|
|
3
|
-
state: PresenceState;
|
|
4
|
-
/**
|
|
5
|
-
* Called by an element that will animate out, once, on mount. `Presence`
|
|
6
|
-
* waits for every registered element before it removes its child, and
|
|
7
|
-
* removes it at once when none registered. The returned function
|
|
8
|
-
* unregisters.
|
|
9
|
-
*/
|
|
10
|
-
register(id: symbol, durationMs: number): () => void;
|
|
11
|
-
/** Called by a registered element when its exit animation has ended. */
|
|
12
|
-
done(id: symbol): void;
|
|
13
|
-
}
|
|
14
|
-
export declare const PresenceContext: import("react").Context<PresenceContextValue | null>;
|
|
15
|
-
//# sourceMappingURL=presence-context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"presence-context.d.ts","sourceRoot":"","sources":["../src/presence-context.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,CAAA;AAE7C,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,aAAa,CAAA;IACpB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,IAAI,CAAA;IACpD,wEAAwE;IACxE,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB;AAED,eAAO,MAAM,eAAe,sDAAmD,CAAA"}
|
package/dist/presence-context.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// What `Presence` tells the elements that animate out inside it, on
|
|
2
|
-
// Native (decision 007, amendment 1).
|
|
3
|
-
//
|
|
4
|
-
// On Web the same thing travels as an attribute, `data-state`, and CSS
|
|
5
|
-
// does the rest. React Native has no attributes to select on, so the
|
|
6
|
-
// state is a context instead, and `HozoAnimated` -- the component the
|
|
7
|
-
// compiler puts in place of an element with a `data-[state=closed]:`
|
|
8
|
-
// class -- reads it.
|
|
9
|
-
import { createContext } from 'react';
|
|
10
|
-
export const PresenceContext = createContext(null);
|
|
11
|
-
//# sourceMappingURL=presence-context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"presence-context.js","sourceRoot":"","sources":["../src/presence-context.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,uEAAuE;AACvE,qEAAqE;AACrE,sEAAsE;AACtE,qEAAqE;AACrE,qBAAqB;AAErB,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAiBrC,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAA8B,IAAI,CAAC,CAAA"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { type ReactNode } from 'react';
|
|
2
|
-
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
-
export interface HozoTransitionSpec {
|
|
4
|
-
duration: number;
|
|
5
|
-
delay?: number;
|
|
6
|
-
easing: 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';
|
|
7
|
-
}
|
|
8
|
-
export interface HozoAnimatedProps {
|
|
9
|
-
style?: StyleProp<ViewStyle>;
|
|
10
|
-
hozoTransition?: HozoTransitionSpec;
|
|
11
|
-
/**
|
|
12
|
-
* The first frame of an enter animation, from a `starting:` class
|
|
13
|
-
* (decision 007). The element mounts at these values and transitions to
|
|
14
|
-
* `style`, which is what `@starting-style` does on Web. Read once, on
|
|
15
|
-
* mount: it is where the element enters from, not a style it keeps.
|
|
16
|
-
*/
|
|
17
|
-
hozoStarting?: StyleProp<ViewStyle>;
|
|
18
|
-
/**
|
|
19
|
-
* The last frame of an exit animation, from a `data-[state=closed]:`
|
|
20
|
-
* class (decision 007, amendment 1). Laid over `style` while the
|
|
21
|
-
* enclosing `Presence` is closing, which is what the attribute selector
|
|
22
|
-
* does on Web; `Presence` removes the element when the transition to it
|
|
23
|
-
* ends.
|
|
24
|
-
*/
|
|
25
|
-
hozoExit?: StyleProp<ViewStyle>;
|
|
26
|
-
children?: ReactNode;
|
|
27
|
-
[key: string]: unknown;
|
|
28
|
-
}
|
|
29
|
-
export declare function HozoAnimated({ style, hozoTransition, hozoStarting, hozoExit, children, ...props }: HozoAnimatedProps): import("react").JSX.Element;
|
|
30
|
-
//# sourceMappingURL=runtime-transition.native.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-transition.native.d.ts","sourceRoot":"","sources":["../src/runtime-transition.native.tsx"],"names":[],"mappings":"AAsBA,OAAO,EAAE,KAAK,SAAS,EAAoD,MAAM,OAAO,CAAA;AACxF,OAAO,EAAoB,KAAK,SAAS,EAAc,KAAK,SAAS,EAAE,MAAM,cAAc,CAAA;AAG3F,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,aAAa,CAAA;CAC1D;AA6BD,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;IAC5B,cAAc,CAAC,EAAE,kBAAkB,CAAA;IACnC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;IACnC;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;IAC/B,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,iBAAiB,+BA0InB"}
|