@hozo/behaviors 0.3.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +1 -1
  3. package/dist/drag-1d-session.d.ts +26 -0
  4. package/dist/drag-1d-session.d.ts.map +1 -0
  5. package/dist/drag-1d-session.js +65 -0
  6. package/dist/drag-1d-session.js.map +1 -0
  7. package/dist/drag-1d.d.ts +14 -0
  8. package/dist/drag-1d.d.ts.map +1 -0
  9. package/dist/drag-1d.js +93 -0
  10. package/dist/drag-1d.js.map +1 -0
  11. package/dist/drag-1d.native.d.ts +8 -0
  12. package/dist/drag-1d.native.d.ts.map +1 -0
  13. package/dist/drag-1d.native.js +52 -0
  14. package/dist/drag-1d.native.js.map +1 -0
  15. package/dist/floating-geometry.d.ts +19 -0
  16. package/dist/floating-geometry.d.ts.map +1 -1
  17. package/dist/floating-geometry.js +19 -0
  18. package/dist/floating-geometry.js.map +1 -1
  19. package/dist/floating-positioner.d.ts +4 -1
  20. package/dist/floating-positioner.d.ts.map +1 -1
  21. package/dist/floating-positioner.js +42 -4
  22. package/dist/floating-positioner.js.map +1 -1
  23. package/dist/floating-positioner.native.d.ts +5 -0
  24. package/dist/floating-positioner.native.d.ts.map +1 -1
  25. package/dist/floating-positioner.native.js +26 -8
  26. package/dist/floating-positioner.native.js.map +1 -1
  27. package/dist/i18n.d.ts +14 -0
  28. package/dist/i18n.d.ts.map +1 -1
  29. package/dist/i18n.js +14 -0
  30. package/dist/i18n.js.map +1 -1
  31. package/dist/index.d.ts +1 -0
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +1 -0
  34. package/dist/index.js.map +1 -1
  35. package/dist/index.native.d.ts +1 -0
  36. package/dist/index.native.d.ts.map +1 -1
  37. package/dist/index.native.js +1 -0
  38. package/dist/index.native.js.map +1 -1
  39. package/dist/native.d.ts +1 -0
  40. package/dist/native.d.ts.map +1 -1
  41. package/dist/native.js +1 -0
  42. package/dist/native.js.map +1 -1
  43. package/dist/portal.native.d.ts.map +1 -1
  44. package/dist/portal.native.js +24 -21
  45. package/dist/portal.native.js.map +1 -1
  46. package/dist/presence.d.ts.map +1 -1
  47. package/dist/presence.js +8 -1
  48. package/dist/presence.js.map +1 -1
  49. package/dist/pressable-interaction.d.ts +12 -1
  50. package/dist/pressable-interaction.d.ts.map +1 -1
  51. package/dist/pressable-interaction.js +14 -6
  52. package/dist/pressable-interaction.js.map +1 -1
  53. package/dist/text-child.d.ts +1 -1
  54. package/dist/text-child.d.ts.map +1 -1
  55. package/dist/text-child.js +1 -1
  56. package/dist/text-child.js.map +1 -1
  57. package/dist/text-child.native.d.ts +7 -1
  58. package/dist/text-child.native.d.ts.map +1 -1
  59. package/dist/text-child.native.js +17 -3
  60. package/dist/text-child.native.js.map +1 -1
  61. package/package.json +2 -2
  62. package/src/drag-1d-session.ts +77 -0
  63. package/src/drag-1d.native.ts +65 -0
  64. package/src/drag-1d.ts +108 -0
  65. package/src/floating-geometry.ts +24 -0
  66. package/src/floating-positioner.native.tsx +27 -7
  67. package/src/floating-positioner.tsx +48 -2
  68. package/src/i18n.ts +14 -0
  69. package/src/index.native.ts +1 -0
  70. package/src/index.ts +1 -0
  71. package/src/native.ts +1 -0
  72. package/src/portal.native.tsx +30 -22
  73. package/src/presence.ts +7 -1
  74. package/src/pressable-interaction.ts +20 -7
  75. package/src/text-child.native.tsx +18 -6
  76. package/src/text-child.ts +1 -1
@@ -1,4 +1,4 @@
1
- import { useCallback, useMemo, useRef, useState } from 'react'
1
+ import { createContext, useCallback, useMemo, useRef, useState } from 'react'
2
2
 
3
3
  export interface HozoPressableInteractionState {
4
4
  pressed: boolean
@@ -7,6 +7,17 @@ export interface HozoPressableInteractionState {
7
7
  focusVisible: boolean
8
8
  }
9
9
 
10
+ /**
11
+ * The state a Native pressable shares with the Text inside it: a `HozoText`
12
+ * anywhere below reads it to apply its `hover:` and `active:` looks (#876).
13
+ * Here rather than in `@hozo/primitives` so `@hozo/patterns`' pressable
14
+ * provides the same one, and a Text a caller nests in a pattern reads it too
15
+ * (#974). `transition` is the primitive's own, for its colour motion.
16
+ */
17
+ export const HozoInteractionContext = createContext<
18
+ (HozoPressableInteractionState & { transition?: unknown }) | null
19
+ >(null)
20
+
10
21
  const HOVERED = 1
11
22
  const FOCUSED = 2
12
23
  const PRESSED = 4
@@ -29,13 +40,14 @@ export function usePressableInteraction({
29
40
  focusVisible = false,
30
41
  onChange,
31
42
  }: {
32
- focusVisible?: boolean
43
+ /** Text fields indicate focus even after a pointer brings up their keyboard. */
44
+ focusVisible?: boolean | 'keyboard-input'
33
45
  onChange?: (state: HozoPressableInteractionState) => void
34
46
  } = {}) {
35
47
  const [mask, setMask] = useState(0)
36
48
  const live = useRef(0)
37
- // Matches the primitive's existing policy: initial focus is keyboard-like;
38
- // a pointer/press clears it, and a key makes a currently focused host visible.
49
+ // Buttons use the existing modality policy: a pointer/press clears visible
50
+ // focus, a key restores it. Keyboard-input fields instead keep it until blur.
39
51
  const modality = useRef<'keyboard' | 'pointer'>('keyboard')
40
52
  const set = useCallback(
41
53
  (flag: number, active: boolean) => {
@@ -52,7 +64,8 @@ export function usePressableInteraction({
52
64
  hoverOut: () => set(HOVERED, false),
53
65
  focus: () => {
54
66
  set(FOCUSED, true)
55
- if (focusVisible) set(FOCUS_VISIBLE, modality.current === 'keyboard')
67
+ if (focusVisible)
68
+ set(FOCUS_VISIBLE, focusVisible === 'keyboard-input' || modality.current === 'keyboard')
56
69
  },
57
70
  blur: () => {
58
71
  set(FOCUSED, false)
@@ -60,7 +73,7 @@ export function usePressableInteraction({
60
73
  },
61
74
  pointerDown: () => {
62
75
  modality.current = 'pointer'
63
- if (focusVisible) set(FOCUS_VISIBLE, false)
76
+ if (focusVisible === true) set(FOCUS_VISIBLE, false)
64
77
  },
65
78
  keyDown: () => {
66
79
  modality.current = 'keyboard'
@@ -68,7 +81,7 @@ export function usePressableInteraction({
68
81
  },
69
82
  pressIn: () => {
70
83
  modality.current = 'pointer'
71
- if (focusVisible) set(FOCUS_VISIBLE, false)
84
+ if (focusVisible === true) set(FOCUS_VISIBLE, false)
72
85
  set(PRESSED, true)
73
86
  },
74
87
  pressOut: () => set(PRESSED, false),
@@ -23,8 +23,8 @@
23
23
  // simply available. A fallback being right about a case the compiler has
24
24
  // to leave is not a divergence worth removing.
25
25
 
26
- import { Children, type ReactNode } from 'react'
27
- import { Text } from 'react-native'
26
+ import { Children, Fragment, isValidElement, type ReactNode } from 'react'
27
+ import { type StyleProp, Text, type TextStyle } from 'react-native'
28
28
 
29
29
  /**
30
30
  * Children with every text one inside a `Text`, and nothing else touched.
@@ -36,9 +36,21 @@ import { Text } from 'react-native'
36
36
  *
37
37
  * Numbers as well as strings. React renders both as text nodes, and React
38
38
  * Native rejects both for the same reason.
39
+ *
40
+ * `style` is for a component whose box carries text classes -- a panel's
41
+ * colour, a tooltip's size -- which a `View` drops and the Web would have
42
+ * let its text inherit. A pattern that puts a caller's `ReactNode` into a
43
+ * `View` passes it through here, with the box's text half (#1205).
39
44
  */
40
- export function hozoTextChildren(children: ReactNode): ReactNode {
41
- return Children.map(children, (child) =>
42
- typeof child === 'string' || typeof child === 'number' ? <Text>{child}</Text> : child,
43
- )
45
+ export function hozoTextChildren(children: ReactNode, style?: StyleProp<TextStyle>): ReactNode {
46
+ return Children.map(children, (child) => {
47
+ if (typeof child === 'string' || typeof child === 'number')
48
+ return <Text style={style}>{child}</Text>
49
+ // A Fragment is a transparent container, not a native text boundary.
50
+ // Preserve its key while normalizing its children; never inspect or
51
+ // execute arbitrary component elements to guess what they render.
52
+ if (isValidElement<{ children?: ReactNode }>(child) && child.type === Fragment)
53
+ return <Fragment key={child.key}>{hozoTextChildren(child.props.children, style)}</Fragment>
54
+ return child
55
+ })
44
56
  }
package/src/text-child.ts CHANGED
@@ -14,6 +14,6 @@
14
14
  import type { ReactNode } from 'react'
15
15
 
16
16
  /** Identity. See above, and `text-child.native.tsx` for the real one. */
17
- export function hozoTextChildren(children: ReactNode): ReactNode {
17
+ export function hozoTextChildren(children: ReactNode, _style?: unknown): ReactNode {
18
18
  return children
19
19
  }