@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/link.native.tsx
CHANGED
|
@@ -4,17 +4,23 @@ import {
|
|
|
4
4
|
prefetchHozoNavigation,
|
|
5
5
|
useHozoNavigation,
|
|
6
6
|
} from '@hozo/engine/navigation'
|
|
7
|
-
import { type ReactNode, useRef } from 'react'
|
|
7
|
+
import { type ComponentPropsWithRef, type ElementType, type ReactNode, useRef } from 'react'
|
|
8
8
|
import { Linking, Pressable, type PressableProps } from 'react-native'
|
|
9
|
+
import type { HozoPressable } from './pressable.native.tsx'
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
type LinkHost = typeof Pressable | typeof HozoPressable
|
|
12
|
+
|
|
13
|
+
export type HozoLinkProps<Host extends LinkHost = typeof Pressable> =
|
|
14
|
+
ComponentPropsWithRef<Host> & {
|
|
15
|
+
/** Compiler-only host selection; ordinary links retain RN's cheap path. */
|
|
16
|
+
hozoLinkComponent?: Host
|
|
17
|
+
href: string
|
|
18
|
+
external?: boolean
|
|
19
|
+
replace?: boolean
|
|
20
|
+
prefetch?: boolean
|
|
21
|
+
onPress?: PressableProps['onPress']
|
|
22
|
+
children?: PressableProps['children']
|
|
23
|
+
}
|
|
18
24
|
|
|
19
25
|
/**
|
|
20
26
|
* Native semantic link with the same destination-bearing API as `<a>`.
|
|
@@ -34,11 +40,15 @@ export interface HozoLinkProps extends Omit<PressableProps, 'onPress'> {
|
|
|
34
40
|
* `Link` carried its own copy of exactly this and is why it existed
|
|
35
41
|
* separately at all; it delegates here now.
|
|
36
42
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
43
|
+
* Normalization wraps text runs, not whole arrays: embedded controls remain
|
|
44
|
+
* controls. Function children are still evaluated by React Native itself.
|
|
45
|
+
*
|
|
46
|
+
* State variants select HozoPressable without duplicating its event machine
|
|
47
|
+
* or navigation. The type-only import keeps that machinery out of ordinary
|
|
48
|
+
* links' Metro graph, where unused static imports would still cost modules.
|
|
40
49
|
*/
|
|
41
|
-
export function HozoLink({
|
|
50
|
+
export function HozoLink<Host extends LinkHost = typeof Pressable>({
|
|
51
|
+
hozoLinkComponent,
|
|
42
52
|
href,
|
|
43
53
|
external,
|
|
44
54
|
replace,
|
|
@@ -49,22 +59,23 @@ export function HozoLink({
|
|
|
49
59
|
children,
|
|
50
60
|
accessibilityRole = 'link',
|
|
51
61
|
...props
|
|
52
|
-
}: HozoLinkProps) {
|
|
62
|
+
}: HozoLinkProps<Host>) {
|
|
63
|
+
const Component: ElementType = hozoLinkComponent ?? Pressable
|
|
53
64
|
const navigation = useHozoNavigation()
|
|
54
65
|
const prefetchedHref = useRef<string | null>(null)
|
|
55
66
|
return (
|
|
56
|
-
<
|
|
67
|
+
<Component
|
|
57
68
|
{...props}
|
|
58
69
|
disabled={disabled}
|
|
59
70
|
accessibilityRole={accessibilityRole}
|
|
60
|
-
onPressIn={(event) => {
|
|
71
|
+
onPressIn={(event: Parameters<NonNullable<PressableProps['onPressIn']>>[0]) => {
|
|
61
72
|
onPressIn?.(event)
|
|
62
73
|
if (prefetch && !disabled && prefetchedHref.current !== href) {
|
|
63
74
|
prefetchedHref.current = href
|
|
64
75
|
prefetchHozoNavigation(navigation, { href, external, replace })
|
|
65
76
|
}
|
|
66
77
|
}}
|
|
67
|
-
onPress={(event) => {
|
|
78
|
+
onPress={(event: Parameters<NonNullable<PressableProps['onPress']>>[0]) => {
|
|
68
79
|
onPress?.(event)
|
|
69
80
|
if (!event.defaultPrevented) {
|
|
70
81
|
void activateHozoNavigation(navigation, { href, external, replace }, Linking.openURL)
|
|
@@ -72,6 +83,6 @@ export function HozoLink({
|
|
|
72
83
|
}}
|
|
73
84
|
>
|
|
74
85
|
{typeof children === 'function' ? children : hozoTextChildren(children as ReactNode)}
|
|
75
|
-
</
|
|
86
|
+
</Component>
|
|
76
87
|
)
|
|
77
88
|
}
|