@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
@@ -23,7 +23,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
23
23
  // the expression is; this runs at render time, where the answer is
24
24
  // simply available. A fallback being right about a case the compiler has
25
25
  // to leave is not a divergence worth removing.
26
- import { Children } from 'react';
26
+ import { Children, Fragment, isValidElement } from 'react';
27
27
  import { Text } from 'react-native';
28
28
  /**
29
29
  * Children with every text one inside a `Text`, and nothing else touched.
@@ -35,8 +35,22 @@ import { Text } from 'react-native';
35
35
  *
36
36
  * Numbers as well as strings. React renders both as text nodes, and React
37
37
  * Native rejects both for the same reason.
38
+ *
39
+ * `style` is for a component whose box carries text classes -- a panel's
40
+ * colour, a tooltip's size -- which a `View` drops and the Web would have
41
+ * let its text inherit. A pattern that puts a caller's `ReactNode` into a
42
+ * `View` passes it through here, with the box's text half (#1205).
38
43
  */
39
- export function hozoTextChildren(children) {
40
- return Children.map(children, (child) => typeof child === 'string' || typeof child === 'number' ? _jsx(Text, { children: child }) : child);
44
+ export function hozoTextChildren(children, style) {
45
+ return Children.map(children, (child) => {
46
+ if (typeof child === 'string' || typeof child === 'number')
47
+ return _jsx(Text, { style: style, children: child });
48
+ // A Fragment is a transparent container, not a native text boundary.
49
+ // Preserve its key while normalizing its children; never inspect or
50
+ // execute arbitrary component elements to guess what they render.
51
+ if (isValidElement(child) && child.type === Fragment)
52
+ return _jsx(Fragment, { children: hozoTextChildren(child.props.children, style) }, child.key);
53
+ return child;
54
+ });
41
55
  }
42
56
  //# sourceMappingURL=text-child.native.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"text-child.native.js","sourceRoot":"","sources":["../src/text-child.native.tsx"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,EAAE;AACF,wEAAwE;AACxE,2EAA2E;AAC3E,2EAA2E;AAC3E,EAAE;AACF,sFAAsF;AACtF,EAAE;AACF,sEAAsE;AACtE,yEAAyE;AACzE,uEAAuE;AACvE,8BAA8B;AAC9B,EAAE;AACF,sEAAsE;AACtE,uEAAuE;AACvE,qEAAqE;AACrE,qEAAqE;AACrE,0EAA0E;AAC1E,EAAE;AACF,qEAAqE;AACrE,0EAA0E;AAC1E,mEAAmE;AACnE,yEAAyE;AACzE,+CAA+C;AAE/C,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAmB;IAClD,OAAO,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CACtC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAC,IAAI,cAAE,KAAK,GAAQ,CAAC,CAAC,CAAC,KAAK,CACtF,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"text-child.native.js","sourceRoot":"","sources":["../src/text-child.native.tsx"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,EAAE;AACF,wEAAwE;AACxE,2EAA2E;AAC3E,2EAA2E;AAC3E,EAAE;AACF,sFAAsF;AACtF,EAAE;AACF,sEAAsE;AACtE,yEAAyE;AACzE,uEAAuE;AACvE,8BAA8B;AAC9B,EAAE;AACF,sEAAsE;AACtE,uEAAuE;AACvE,qEAAqE;AACrE,qEAAqE;AACrE,0EAA0E;AAC1E,EAAE;AACF,qEAAqE;AACrE,0EAA0E;AAC1E,mEAAmE;AACnE,yEAAyE;AACzE,+CAA+C;AAE/C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAkB,MAAM,OAAO,CAAA;AAC1E,OAAO,EAAkB,IAAI,EAAkB,MAAM,cAAc,CAAA;AAEnE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAmB,EAAE,KAA4B;IAChF,OAAO,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;QACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ;YACxD,OAAO,KAAC,IAAI,IAAC,KAAK,EAAE,KAAK,YAAG,KAAK,GAAQ,CAAA;QAC3C,qEAAqE;QACrE,oEAAoE;QACpE,kEAAkE;QAClE,IAAI,cAAc,CAA2B,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ;YAC5E,OAAO,KAAC,QAAQ,cAAkB,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAzD,KAAK,CAAC,GAAG,CAA4D,CAAA;QAC7F,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CAAA;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hozo/behaviors",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Hozo's accessibility and internationalisation behaviours (FocusScope, RovingFocus, LiveRegion, Portal, DismissableLayer, FloatingPositioner), shared by Web and React Native.",
5
5
  "keywords": [
6
6
  "react-native",
@@ -62,7 +62,7 @@
62
62
  "peerDependencies": {
63
63
  "react": "^19.0.0",
64
64
  "react-dom": "^19.0.0",
65
- "react-native": ">=0.86"
65
+ "react-native": ">=0.87"
66
66
  },
67
67
  "peerDependenciesMeta": {
68
68
  "react-dom": {
@@ -0,0 +1,77 @@
1
+ export interface Drag1DOptions {
2
+ axis: 'x' | 'y'
3
+ disabled?: boolean
4
+ /** Native can wait for movement so a Pressable still receives ordinary taps. */
5
+ nativeActivationDistance?: number
6
+ /** Validate measured geometry before starting a session. */
7
+ canStart?: () => boolean
8
+ /** Horizontal deltas follow the platform's writing direction. */
9
+ onStart?: () => void
10
+ onMove?: (delta: number, details: Drag1DDetails) => void
11
+ onEnd?: (delta: number, details: Drag1DDetails) => void
12
+ onCancel?: () => void
13
+ }
14
+
15
+ export interface Drag1DDetails {
16
+ /** Pixels per millisecond along the same logical axis as delta. */
17
+ velocity: number
18
+ }
19
+
20
+ /** Shared lifecycle: moves are coalesced, but release always flushes its final delta. */
21
+ export function createDrag1DSession(
22
+ options: () => Drag1DOptions,
23
+ schedule: (callback: () => void) => number,
24
+ unschedule: (id: number) => void,
25
+ ) {
26
+ let active = false
27
+ let pending: number | undefined
28
+ let delta = 0
29
+ let delivered = 0
30
+ let details: Drag1DDetails = { velocity: 0 }
31
+ const flush = () => {
32
+ if (pending !== undefined) unschedule(pending)
33
+ pending = undefined
34
+ if (active && delta !== delivered) {
35
+ delivered = delta
36
+ options().onMove?.(delta, details)
37
+ }
38
+ }
39
+ const cancel = () => {
40
+ if (!active) return
41
+ active = false
42
+ if (pending !== undefined) unschedule(pending)
43
+ pending = undefined
44
+ options().onCancel?.()
45
+ }
46
+ return {
47
+ get active() {
48
+ return active
49
+ },
50
+ start() {
51
+ if (active || options().disabled || options().canStart?.() === false) return false
52
+ active = true
53
+ delta = delivered = 0
54
+ details = { velocity: 0 }
55
+ options().onStart?.()
56
+ return active
57
+ },
58
+ move(next: number, sample: Drag1DDetails = { velocity: 0 }) {
59
+ if (!active) return
60
+ if (options().disabled) return cancel()
61
+ delta = next
62
+ details = sample
63
+ if (pending === undefined) pending = schedule(flush)
64
+ },
65
+ end(next: number, sample: Drag1DDetails = details) {
66
+ if (!active) return
67
+ if (options().disabled) return cancel()
68
+ delta = next
69
+ details = sample
70
+ flush()
71
+ if (!active) return
72
+ active = false
73
+ options().onEnd?.(delta, details)
74
+ },
75
+ cancel,
76
+ }
77
+ }
@@ -0,0 +1,65 @@
1
+ import { useEffect, useMemo, useRef, useState } from 'react'
2
+ import { I18nManager, PanResponder, type PanResponderInstance } from 'react-native'
3
+ import { createDrag1DSession, type Drag1DOptions } from './drag-1d-session.ts'
4
+
5
+ export type { Drag1DDetails, Drag1DOptions } from './drag-1d-session.ts'
6
+
7
+ export function useDrag1D(options: Drag1DOptions): {
8
+ dragging: boolean
9
+ handlers: PanResponderInstance['panHandlers']
10
+ } {
11
+ const live = useRef(options)
12
+ live.current = options
13
+ const [dragging, setDragging] = useState(false)
14
+ const session = useMemo(
15
+ () =>
16
+ createDrag1DSession(
17
+ () => live.current,
18
+ (callback) => requestAnimationFrame(callback),
19
+ (id) => cancelAnimationFrame(id),
20
+ ),
21
+ [],
22
+ )
23
+ const responder = useMemo(() => {
24
+ let axis: 'x' | 'y' = 'x'
25
+ let sign = 1
26
+ const delta = (dx: number, dy: number) => (axis === 'x' ? dx : dy) * sign
27
+ return PanResponder.create({
28
+ onStartShouldSetPanResponder: () =>
29
+ !live.current.disabled && (live.current.nativeActivationDistance ?? 0) <= 0,
30
+ onMoveShouldSetPanResponder: (_, state) => {
31
+ if (live.current.disabled) return false
32
+ const distance = live.current.nativeActivationDistance ?? 0
33
+ return distance <= 0 || Math.abs(live.current.axis === 'x' ? state.dx : state.dy) > distance
34
+ },
35
+ onPanResponderGrant: () => {
36
+ axis = live.current.axis
37
+ sign = axis === 'x' && I18nManager.isRTL ? -1 : 1
38
+ if (session.start()) setDragging(true)
39
+ },
40
+ onPanResponderMove: (_, state) =>
41
+ session.move(delta(state.dx, state.dy), {
42
+ velocity: ((axis === 'x' ? state.vx : state.vy) ?? 0) * sign,
43
+ }),
44
+ onPanResponderRelease: (_, state) => {
45
+ session.end(delta(state.dx, state.dy), {
46
+ velocity: ((axis === 'x' ? state.vx : state.vy) ?? 0) * sign,
47
+ })
48
+ setDragging(false)
49
+ },
50
+ onPanResponderTerminate: () => {
51
+ session.cancel()
52
+ setDragging(false)
53
+ },
54
+ onPanResponderTerminationRequest: () => true,
55
+ })
56
+ }, [session])
57
+ useEffect(() => {
58
+ if (options.disabled) {
59
+ session.cancel()
60
+ setDragging(false)
61
+ }
62
+ }, [options.disabled, session])
63
+ useEffect(() => () => session.cancel(), [session])
64
+ return { dragging, handlers: responder.panHandlers }
65
+ }
package/src/drag-1d.ts ADDED
@@ -0,0 +1,108 @@
1
+ import { type PointerEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react'
2
+ import { createDrag1DSession, type Drag1DOptions } from './drag-1d-session.ts'
3
+
4
+ export type { Drag1DDetails, Drag1DOptions } from './drag-1d-session.ts'
5
+
6
+ export function useDrag1D(options: Drag1DOptions) {
7
+ const live = useRef(options)
8
+ live.current = options
9
+ const [dragging, setDragging] = useState(false)
10
+ const gesture = useRef<{
11
+ id: number
12
+ start: number
13
+ sign: number
14
+ axis: 'x' | 'y'
15
+ host: HTMLElement
16
+ last: number
17
+ lastAt: number
18
+ velocity: number
19
+ } | null>(null)
20
+ const session = useMemo(
21
+ () =>
22
+ createDrag1DSession(
23
+ () => live.current,
24
+ (callback) => requestAnimationFrame(callback),
25
+ (id) => cancelAnimationFrame(id),
26
+ ),
27
+ [],
28
+ )
29
+ const release = useCallback(() => {
30
+ const current = gesture.current
31
+ gesture.current = null
32
+ if (current?.host.hasPointerCapture(current.id)) current.host.releasePointerCapture(current.id)
33
+ }, [])
34
+ const cancel = useCallback(() => {
35
+ session.cancel()
36
+ release()
37
+ setDragging(false)
38
+ }, [session, release])
39
+ useEffect(() => {
40
+ if (options.disabled) cancel()
41
+ }, [options.disabled, cancel])
42
+ useEffect(
43
+ () => () => {
44
+ session.cancel()
45
+ release()
46
+ },
47
+ [session, release],
48
+ )
49
+ const delta = (event: PointerEvent<HTMLElement>) => {
50
+ const at = gesture.current!
51
+ return ((at.axis === 'x' ? event.clientX : event.clientY) - at.start) * at.sign
52
+ }
53
+ const matches = (event: PointerEvent<HTMLElement>) => gesture.current?.id === event.pointerId
54
+ const sample = (event: PointerEvent<HTMLElement>, retainVelocity = false) => {
55
+ const at = gesture.current!
56
+ const position = at.axis === 'x' ? event.clientX : event.clientY
57
+ if (position !== at.last || !retainVelocity) {
58
+ at.velocity = ((position - at.last) * at.sign) / Math.max(1, event.timeStamp - at.lastAt)
59
+ }
60
+ at.last = position
61
+ at.lastAt = event.timeStamp
62
+ return { velocity: at.velocity }
63
+ }
64
+ return {
65
+ dragging,
66
+ handlers: {
67
+ onPointerDown(event: PointerEvent<HTMLElement>) {
68
+ if (gesture.current || event.button !== 0 || !event.isPrimary || options.disabled) return
69
+ const host = event.currentTarget
70
+ const axis = options.axis
71
+ const sign = axis === 'x' && getComputedStyle(host).direction === 'rtl' ? -1 : 1
72
+ gesture.current = {
73
+ id: event.pointerId,
74
+ host,
75
+ axis,
76
+ sign,
77
+ start: axis === 'x' ? event.clientX : event.clientY,
78
+ last: axis === 'x' ? event.clientX : event.clientY,
79
+ lastAt: event.timeStamp,
80
+ velocity: 0,
81
+ }
82
+ if (!session.start()) {
83
+ gesture.current = null
84
+ return
85
+ }
86
+ host.setPointerCapture(event.pointerId)
87
+ host.focus()
88
+ event.preventDefault()
89
+ setDragging(true)
90
+ },
91
+ onPointerMove(event: PointerEvent<HTMLElement>) {
92
+ if (matches(event)) session.move(delta(event), sample(event))
93
+ },
94
+ onPointerUp(event: PointerEvent<HTMLElement>) {
95
+ if (!matches(event)) return
96
+ session.end(delta(event), sample(event, true))
97
+ release()
98
+ setDragging(false)
99
+ },
100
+ onPointerCancel(event: PointerEvent<HTMLElement>) {
101
+ if (matches(event)) cancel()
102
+ },
103
+ onLostPointerCapture(event: PointerEvent<HTMLElement>) {
104
+ if (matches(event)) cancel()
105
+ },
106
+ },
107
+ }
108
+ }
@@ -304,3 +304,27 @@ export function computePosition(
304
304
  arrow,
305
305
  }
306
306
  }
307
+
308
+ /**
309
+ * A position computed in window coordinates, moved into the coordinates of the
310
+ * box the floating element is laid out in.
311
+ *
312
+ * React Native measures in the window but places `position: absolute` against
313
+ * the parent, so the two agree only when the parent sits at the window's
314
+ * origin. Without a `PortalProvider` the panel renders where it was written,
315
+ * inside its own pattern's padding, and landed that far from its anchor
316
+ * (#1326). The parent's origin is not measurable from the floating element
317
+ * directly, but it is where the element is in the window less where it was
318
+ * placed: `floatingInWindow - placed`.
319
+ */
320
+ export function toContainingBlock(
321
+ position: PositionResult,
322
+ floatingInWindow: { x: number; y: number },
323
+ placed: { x: number; y: number },
324
+ ): PositionResult {
325
+ return {
326
+ ...position,
327
+ x: position.x - (floatingInWindow.x - placed.x),
328
+ y: position.y - (floatingInWindow.y - placed.y),
329
+ }
330
+ }
@@ -7,13 +7,17 @@ import React, {
7
7
  useRef,
8
8
  useState,
9
9
  } from 'react'
10
- import { type StyleProp, View, type ViewStyle } from 'react-native'
10
+ import { type StyleProp, useWindowDimensions, View, type ViewStyle } from 'react-native'
11
11
  import {
12
12
  type ComputePositionOptions,
13
13
  computePosition,
14
14
  type PositionResult,
15
+ toContainingBlock,
15
16
  } from './floating-geometry.ts'
16
17
 
18
+ /** Where the positioner parks the panel until it has been measured once. */
19
+ const OFFSCREEN = -9999
20
+
17
21
  /**
18
22
  * What React Native hands back for a `<View>`, rather than a shape of our
19
23
  * own that happens to have `measureInWindow` on it.
@@ -31,6 +35,11 @@ export interface UseFloatingPositionOptions extends ComputePositionOptions {
31
35
 
32
36
  /**
33
37
  * Universal React hook for floating element positioning on React Native.
38
+ *
39
+ * The result is in the coordinates of the floating element's parent, for its
40
+ * `left`/`top`. That assumes the element sits at `left: -9999, top: -9999`
41
+ * until the first result and at each result after, as `FloatingPositioner`
42
+ * places it: the parent's origin is read back from where that put it.
34
43
  */
35
44
  export function useFloatingPosition({
36
45
  anchorRef,
@@ -45,6 +54,14 @@ export function useFloatingPosition({
45
54
  arrowPadding = 4,
46
55
  }: UseFloatingPositionOptions): PositionResult | null {
47
56
  const [position, setPosition] = useState<PositionResult | null>(null)
57
+ // The window the anchor was measured in, so flip and shift know where its
58
+ // edges are. A fixed 400x800 flipped panels on a tall phone that had room
59
+ // below, and let them run off a narrower one. Read as a hook so a rotation
60
+ // or a resized window positions the panel again.
61
+ const { width: windowWidth, height: windowHeight } = useWindowDimensions()
62
+ // Where the floating element was last placed, in its parent's coordinates:
63
+ // what turns its window measurement back into the parent's origin.
64
+ const placed = useRef({ x: OFFSCREEN, y: OFFSCREEN })
48
65
 
49
66
  const update = useCallback(() => {
50
67
  if (!enabled) return
@@ -54,9 +71,8 @@ export function useFloatingPosition({
54
71
  anchor.measureInWindow((ax, ay, aw, ah) => {
55
72
  const floating = floatingRef.current
56
73
  if (floating?.measureInWindow) {
57
- floating.measureInWindow((_fx, _fy, fw, fh) => {
58
- // Assume standard device screen dimensions fallback
59
- const viewport = { width: 400, height: 800 }
74
+ floating.measureInWindow((fx, fy, fw, fh) => {
75
+ const viewport = { width: windowWidth, height: windowHeight }
60
76
  const result = computePosition(
61
77
  { x: ax, y: ay, width: aw, height: ah },
62
78
  { x: 0, y: 0, width: fw, height: fh },
@@ -71,7 +87,9 @@ export function useFloatingPosition({
71
87
  arrowPadding,
72
88
  },
73
89
  )
74
- setPosition(result)
90
+ const local = toContainingBlock(result, { x: fx, y: fy }, placed.current)
91
+ placed.current = { x: local.x, y: local.y }
92
+ setPosition(local)
75
93
  })
76
94
  }
77
95
  })
@@ -86,6 +104,8 @@ export function useFloatingPosition({
86
104
  shift,
87
105
  viewportPadding,
88
106
  arrowPadding,
107
+ windowWidth,
108
+ windowHeight,
89
109
  ])
90
110
 
91
111
  useEffect(() => {
@@ -139,8 +159,8 @@ export function FloatingPositioner({
139
159
  }
140
160
  : {
141
161
  position: 'absolute' as const,
142
- left: -9999,
143
- top: -9999,
162
+ left: OFFSCREEN,
163
+ top: OFFSCREEN,
144
164
  opacity: 0,
145
165
  }
146
166
 
@@ -4,6 +4,7 @@ import {
4
4
  type RefObject,
5
5
  useCallback,
6
6
  useEffect,
7
+ useLayoutEffect,
7
8
  useRef,
8
9
  useState,
9
10
  } from 'react'
@@ -121,6 +122,25 @@ export interface FloatingPositionerProps extends ComputePositionOptions {
121
122
  anchorRef: RefObject<HTMLElement | null>
122
123
  className?: string
123
124
  style?: CSSProperties
125
+ /** Opt in to a non-modal top layer without moving the DOM or its CSS ancestry.
126
+ * Engines without showPopover keep inline positioning and warn once. */
127
+ topLayer?: boolean
128
+ }
129
+
130
+ let warnedTopLayerFallback = false
131
+
132
+ // Popover's UA box is a visible panel. Here the same host remains only a
133
+ // transparent positioning box; the caller still owns the panel's appearance.
134
+ const topLayerReset: CSSProperties = {
135
+ inset: 'auto',
136
+ width: 'auto',
137
+ height: 'auto',
138
+ margin: 0,
139
+ padding: 0,
140
+ border: 0,
141
+ overflow: 'visible',
142
+ color: 'inherit',
143
+ background: 'transparent',
124
144
  }
125
145
 
126
146
  /**
@@ -132,9 +152,30 @@ export function FloatingPositioner({
132
152
  anchorRef,
133
153
  className,
134
154
  style,
155
+ topLayer = false,
135
156
  ...options
136
157
  }: FloatingPositionerProps) {
137
158
  const floatingRef = useRef<HTMLDivElement>(null)
159
+ useLayoutEffect(() => {
160
+ const node = floatingRef.current
161
+ if (!topLayer || !node) return
162
+ if (typeof node.showPopover !== 'function') {
163
+ // Otherwise the browser's [popover]:not(:popover-open) rule can keep
164
+ // an unsupported/polyfilled host hidden rather than restoring inline.
165
+ node.removeAttribute('popover')
166
+ if (!warnedTopLayerFallback) {
167
+ warnedTopLayerFallback = true
168
+ console.warn(
169
+ '[hozo] FloatingPositioner: showPopover is unavailable; inline fallback cannot escape ancestor clipping or stacking contexts.',
170
+ )
171
+ }
172
+ return
173
+ }
174
+ if (!node.matches(':popover-open')) node.showPopover()
175
+ // DOM removal (or removing the attribute) removes it from the top layer.
176
+ // Do not call hidePopover during unmount: Menu owns focus restoration,
177
+ // including the outside-click path which deliberately does not restore.
178
+ }, [topLayer])
138
179
  const position = useFloatingPosition({
139
180
  anchorRef,
140
181
  floatingRef,
@@ -146,7 +187,11 @@ export function FloatingPositioner({
146
187
  position: 'fixed',
147
188
  left: `${position.x}px`,
148
189
  top: `${position.y}px`,
149
- width: options.matchAnchorWidth ? `${position.anchorWidth}px` : undefined,
190
+ width: options.matchAnchorWidth
191
+ ? `${position.anchorWidth}px`
192
+ : topLayer
193
+ ? 'auto'
194
+ : undefined,
150
195
  willChange: 'transform',
151
196
  display: position.referenceHidden ? 'none' : undefined,
152
197
  }
@@ -160,8 +205,9 @@ export function FloatingPositioner({
160
205
  return (
161
206
  <div
162
207
  ref={floatingRef}
208
+ popover={topLayer ? 'manual' : undefined}
163
209
  className={className}
164
- style={{ ...positionStyles, ...style }}
210
+ style={{ ...(topLayer ? topLayerReset : undefined), ...positionStyles, ...style }}
165
211
  data-placement={position?.placement}
166
212
  data-flipped={position?.flipped ? '' : undefined}
167
213
  data-shifted={position?.shifted ? '' : undefined}
package/src/i18n.ts CHANGED
@@ -22,6 +22,19 @@ import { createContext, createElement, type ReactNode, useCallback, useContext }
22
22
  * library this connects to interpolates by name.
23
23
  */
24
24
  export const hozoMessages = {
25
+ 'hozo.code.label': 'Code',
26
+ 'hozo.code.contents': 'Code contents: {title}',
27
+ 'hozo.code.lines': '{title}, {count} lines',
28
+ 'hozo.code.added': 'Added',
29
+ 'hozo.code.removed': 'Removed',
30
+ 'hozo.code.highlighted': 'Highlighted',
31
+ 'hozo.code.copy': 'Copy code',
32
+ 'hozo.code.copied': 'Copied',
33
+ 'hozo.code.copyFailed': 'Could not copy code',
34
+ 'hozo.splitter.label': 'Resize {label}',
35
+ 'hozo.splitter.value': '{size} pixels',
36
+ 'hozo.splitter.expand': 'Expand',
37
+ 'hozo.splitter.collapse': 'Collapse',
25
38
  'hozo.avatar.label': '{name}, {status}',
26
39
  'hozo.avatar.statusBusy': 'busy',
27
40
  'hozo.avatar.statusOffline': 'offline',
@@ -66,6 +79,7 @@ export const hozoMessages = {
66
79
  'hozo.dateRangePicker.dialog': 'Choose a range of dates',
67
80
  'hozo.dateTimePicker.dialog': 'Choose a date and time',
68
81
  'hozo.dateTimePicker.done': 'Done',
82
+ 'hozo.field.required': 'Required',
69
83
  'hozo.fileDropzone.selectedMany': '{count} files selected',
70
84
  'hozo.fileDropzone.selectedOne': '{name} selected, {size}',
71
85
  'hozo.fileDropzone.tooLarge': '{name} is too large: {size}, and the limit is {limit}',
@@ -7,6 +7,7 @@ export {
7
7
  DismissableLayer,
8
8
  type DismissableLayerProps,
9
9
  } from './dismissable-layer.native.tsx'
10
+ export { type Drag1DDetails, type Drag1DOptions, useDrag1D } from './drag-1d.native.ts'
10
11
  export {
11
12
  type Alignment,
12
13
  type BasePlacement,
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export {
7
7
  DismissableLayer,
8
8
  type DismissableLayerProps,
9
9
  } from './dismissable-layer.tsx'
10
+ export { type Drag1DDetails, type Drag1DOptions, useDrag1D } from './drag-1d.ts'
10
11
  export {
11
12
  type Alignment,
12
13
  type BasePlacement,
package/src/native.ts CHANGED
@@ -5,6 +5,7 @@ export {
5
5
  moveAccessibilityFocus,
6
6
  setAccessibilityFocusMover,
7
7
  } from './accessibility-focus.native.ts'
8
+ export { type Drag1DOptions, useDrag1D } from './drag-1d.native.ts'
8
9
  export type { Placement } from './floating-geometry.ts'
9
10
  export {
10
11
  FloatingPositioner,
@@ -1,4 +1,12 @@
1
- import React, { createContext, type ReactNode, useContext, useEffect, useId, useState } from 'react'
1
+ import React, {
2
+ createContext,
3
+ type ReactNode,
4
+ useContext,
5
+ useEffect,
6
+ useId,
7
+ useMemo,
8
+ useState,
9
+ } from 'react'
2
10
  import { View } from 'react-native'
3
11
 
4
12
  export interface PortalProps {
@@ -18,7 +26,6 @@ export interface PortalProps {
18
26
  }
19
27
 
20
28
  type PortalMethods = {
21
- mount: (id: string, children: ReactNode) => void
22
29
  update: (id: string, children: ReactNode) => void
23
30
  unmount: (id: string) => void
24
31
  }
@@ -32,29 +39,29 @@ const PortalContext = createContext<PortalMethods | null>(null)
32
39
  export function PortalProvider({ children }: { children: ReactNode }) {
33
40
  const [items, setItems] = useState<Map<string, ReactNode>>(() => new Map())
34
41
 
35
- const methods: PortalMethods = {
36
- mount: (id, node) => {
42
+ // Portal effects depend on this API, not the item snapshot. Recreating it
43
+ // after a registration makes that effect unregister/register forever.
44
+ const methods = useMemo<PortalMethods>(() => {
45
+ const put: PortalMethods['update'] = (id, node) => {
37
46
  setItems((prev) => {
47
+ if (prev.has(id) && prev.get(id) === node) return prev
38
48
  const next = new Map(prev)
39
49
  next.set(id, node)
40
50
  return next
41
51
  })
42
- },
43
- update: (id, node) => {
44
- setItems((prev) => {
45
- const next = new Map(prev)
46
- next.set(id, node)
47
- return next
48
- })
49
- },
50
- unmount: (id) => {
51
- setItems((prev) => {
52
- const next = new Map(prev)
53
- next.delete(id)
54
- return next
55
- })
56
- },
57
- }
52
+ }
53
+ return {
54
+ update: put,
55
+ unmount: (id) => {
56
+ setItems((prev) => {
57
+ if (!prev.has(id)) return prev
58
+ const next = new Map(prev)
59
+ next.delete(id)
60
+ return next
61
+ })
62
+ },
63
+ }
64
+ }, [])
58
65
 
59
66
  return (
60
67
  <PortalContext.Provider value={methods}>
@@ -111,11 +118,12 @@ export function Portal({ children, disabled = false }: PortalProps) {
111
118
 
112
119
  useEffect(() => {
113
120
  if (disabled || !portal) return
114
- portal.mount(id, children)
121
+ // A changed child is an in-place item update, not an unregister/register:
122
+ // deleting/readding the same key would move it after unaffected siblings.
115
123
  return () => {
116
124
  portal.unmount(id)
117
125
  }
118
- }, [disabled, portal, id, children])
126
+ }, [disabled, portal, id])
119
127
 
120
128
  useEffect(() => {
121
129
  if (disabled || !portal) return
package/src/presence.ts CHANGED
@@ -53,7 +53,13 @@ function longest(durations: string, delays: string): number {
53
53
  function exitDuration(element: Element): number {
54
54
  const style = getComputedStyle(element)
55
55
  return Math.max(
56
- longest(style.transitionDuration, style.transitionDelay),
56
+ // `transition-none` -- and so `motion-reduce:transition-none` -- sets
57
+ // the property list to `none` and leaves the duration where the other
58
+ // classes put it. Nothing transitions then, and no `transitionend` will
59
+ // come to end the exit early.
60
+ style.transitionProperty === 'none'
61
+ ? 0
62
+ : longest(style.transitionDuration, style.transitionDelay),
57
63
  style.animationName === 'none' ? 0 : longest(style.animationDuration, style.animationDelay),
58
64
  )
59
65
  }