@hozo/behaviors 0.1.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +16 -2
  3. package/dist/accessibility-focus.native.d.ts +23 -0
  4. package/dist/accessibility-focus.native.d.ts.map +1 -0
  5. package/dist/accessibility-focus.native.js +81 -0
  6. package/dist/accessibility-focus.native.js.map +1 -0
  7. package/dist/command-shortcut.d.ts +23 -0
  8. package/dist/command-shortcut.d.ts.map +1 -0
  9. package/dist/command-shortcut.js +47 -0
  10. package/dist/command-shortcut.js.map +1 -0
  11. package/dist/command-shortcut.native.d.ts +11 -0
  12. package/dist/command-shortcut.native.d.ts.map +1 -0
  13. package/dist/command-shortcut.native.js +11 -0
  14. package/dist/command-shortcut.native.js.map +1 -0
  15. package/dist/focus-scope.d.ts +9 -1
  16. package/dist/focus-scope.d.ts.map +1 -1
  17. package/dist/focus-scope.js +43 -11
  18. package/dist/focus-scope.js.map +1 -1
  19. package/dist/i18n.d.ts +140 -0
  20. package/dist/i18n.d.ts.map +1 -0
  21. package/dist/i18n.js +144 -0
  22. package/dist/i18n.js.map +1 -0
  23. package/dist/index.d.ts +3 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +3 -0
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.native.d.ts +3 -0
  28. package/dist/index.native.d.ts.map +1 -1
  29. package/dist/index.native.js +3 -0
  30. package/dist/index.native.js.map +1 -1
  31. package/dist/native.d.ts +3 -0
  32. package/dist/native.d.ts.map +1 -1
  33. package/dist/native.js +3 -0
  34. package/dist/native.js.map +1 -1
  35. package/dist/presence.d.ts +19 -0
  36. package/dist/presence.d.ts.map +1 -0
  37. package/dist/presence.js +96 -0
  38. package/dist/presence.js.map +1 -0
  39. package/dist/presence.native.d.ts +10 -0
  40. package/dist/presence.native.d.ts.map +1 -0
  41. package/dist/presence.native.js +18 -0
  42. package/dist/presence.native.js.map +1 -0
  43. package/dist/pressable-interaction.d.ts +30 -0
  44. package/dist/pressable-interaction.d.ts.map +1 -0
  45. package/dist/pressable-interaction.js +64 -0
  46. package/dist/pressable-interaction.js.map +1 -0
  47. package/package.json +7 -2
  48. package/src/accessibility-focus.native.ts +88 -0
  49. package/src/command-shortcut.native.ts +15 -0
  50. package/src/command-shortcut.ts +51 -0
  51. package/src/focus-scope.tsx +49 -8
  52. package/src/i18n.ts +198 -0
  53. package/src/index.native.ts +20 -0
  54. package/src/index.ts +24 -0
  55. package/src/native.ts +22 -0
  56. package/src/presence.native.ts +27 -0
  57. package/src/presence.ts +118 -0
  58. package/src/pressable-interaction.ts +79 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,49 @@
1
+ # @hozo/behaviors
2
+
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`80f2686`](https://github.com/iray-tno/hozo/commit/80f2686ace0922e27502695d0b88c1dba2e08be0) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `Avatar`: a person's picture, or their initials when it is absent or fails to load, read as one image named for the person, with an optional status read after the name ("Ada Lovelace, online"). The headless version lives in `@hozo/patterns`, and the look (three sizes and a status dot) in `@hozo/ui`. Its class lists compile on both platforms, as `Chip`'s do. `@hozo/core` now also exports `Chip`, which it previously reached only through compiled output.
8
+
9
+ - [#818](https://github.com/iray-tno/hozo/pull/818) [`adfe1fd`](https://github.com/iray-tno/hozo/commit/adfe1fd914d60effc27677efdaee6edf19feaf6b) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `ColorPicker`. It offers:
10
+ - preset swatches as a radio group;
11
+ - hue, saturation and lightness (and opacity, with `alpha`) as ordinary sliders rather than a two-dimensional square, which a keyboard and a screen reader can reach but not operate;
12
+ - a hex field;
13
+ - on the Web, an optional eyedropper where the browser has one.
14
+
15
+ Every colour is read named and numbered, for example "dark blue, #1e3a8a", and the names go through the i18n connection. `Slider` on the Web now also takes a track `style`.
16
+
17
+ - [#817](https://github.com/iray-tno/hozo/pull/817) [`496f1b7`](https://github.com/iray-tno/hozo/commit/496f1b75e06bc5f5b079870ce566754e7161c21a) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `CommandPalette` and `useCommandShortcut`.
18
+
19
+ **`CommandPalette`** is a searchable list of commands in a modal.
20
+ - On the Web it is a dialog holding a combobox and a grouped listbox. The arrow keys move through the matching commands while focus stays in the field (`aria-activedescendant`), Enter runs one, and Escape closes it and returns focus.
21
+ - On React Native it is a full-screen modal with a button per command.
22
+ - On both platforms, matches are ranked (starts with, then a word that starts with, then contains, then the letters in order), and the number of matches is announced as the query narrows them.
23
+ - The headless version lives in `@hozo/patterns` and the look in `@hozo/ui`.
24
+
25
+ **`useCommandShortcut`** (`@hozo/behaviors`) calls a function for ⌘K on a Mac and Ctrl+K elsewhere. It does nothing on React Native.
26
+
27
+ - [#821](https://github.com/iray-tno/hozo/pull/821) [`ad1ad0b`](https://github.com/iray-tno/hozo/commit/ad1ad0b355c6ecae07372f44a65aed279e539e22) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `FileDropzone`. It is a button that opens the file picker, with dropping files on it as a shortcut on the Web. Every pick is sorted by `accept`, the size limits and the count, and what was added and what was refused (with each reason) is announced in one sentence. On React Native it opens the application's `pickFiles`, or `expo-document-picker` when installed. With neither, it is disabled and says no picker is available.
28
+
29
+ - [#923](https://github.com/iray-tno/hozo/pull/923) [`8d58223`](https://github.com/iray-tno/hozo/commit/8d5822322607b6214fa7f57d233a9173a45815b6) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `HozoI18nProvider`, `hozoMessages`, locale/direction hooks and structural adapters for i18next and react-intl. Hozo's component labels, status descriptions and announcements can use the application's existing translation catalog, with English fallback messages. Hozo connects to an i18n library; it does not introduce a second translation engine or require one of these libraries as a dependency.
30
+
31
+ - [#923](https://github.com/iray-tno/hozo/pull/923) [`8d58223`](https://github.com/iray-tno/hozo/commit/8d5822322607b6214fa7f57d233a9173a45815b6) Thanks [@iray-tno](https://github.com/iray-tno)! - Resolve Native pattern class-name slots through the project's runtime class resolver. Pattern controls now share the primitive interaction engine and deliver hover, focus, focus-visible and pressed facts to their actual owners instead of reporting pressed alone.
32
+
33
+ Static interaction styles are additionally wired for Chip, ColorPicker swatches, Pagination page controls and CommandPalette pointer-state item slots. Selection slots and nested controls retain their own ownership: a remove button does not inherit its row's focus, and a command item does not borrow the input's focus. Other static state slots and semantic predicates remain subject to their existing diagnostics.
34
+
35
+ Styled Button receives a pressed look; Checkbox and Switch indicators are real elements on both platforms rather than Native-invisible pseudo-elements. Non-transition Native Pressables and their Text children no longer allocate animation values/listeners. Interaction ownership remains mounted when transitions are added or removed. This removes idle animation work, not every initial-mount cost or every platform delivery difference; measured list mount/update tradeoffs remain tracked separately.
36
+
37
+ - [#809](https://github.com/iray-tno/hozo/pull/809) [`70cc763`](https://github.com/iray-tno/hozo/commit/70cc763166d3f3aa04c466c5a12e7a8a4dba0a0f) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `OtpInput`, for a one-time code or a PIN. It is one real input drawn as cells, so a screen reader finds one field ("Verification code, 6 characters"), and a pasted or autofilled code lands at once. It asks each platform for a one-time code: `autocomplete="one-time-code"` on the Web, `textContentType="oneTimeCode"` on iOS and `autoComplete="sms-otp"` on Android. `mask` turns it into a PIN. The active and filled cells are styled by class lists the pattern applies, so the look reaches React Native as well.
38
+
39
+ - [#797](https://github.com/iray-tno/hozo/pull/797) [`9a33076`](https://github.com/iray-tno/hozo/commit/9a3307689c1a37847d45bea9083cee1f63c7edba) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `Pagination`: numbered pages with previous and next, inside a `<nav>` named "Pagination". The current page is marked with `aria-current="page"` (`selected` on Native), and the ends are disabled in place rather than removed. With `getPageHref` every page is a link, which on Native goes through the installed router. The current page and the disabled ends are styled by class lists the pattern applies (`currentItemClassName`, `disabledItemClassName`), so the same look reaches React Native, where there are no selectors.
40
+
41
+ - [#798](https://github.com/iray-tno/hozo/pull/798) [`030d179`](https://github.com/iray-tno/hozo/commit/030d1791515ef5523560c38c1788e4b23f6bfd92) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `Stepper`: where a person is in a process of several steps. Each step is read with its position and status in words ("Step 2 of 3: Profile, current"), so the status is never carried by colour alone. The current step is marked `aria-current="step"` on the Web and `selected` on Native. With `onStepPress` the steps are buttons. Each status has class lists for the step and its indicator, applied by the pattern, so the look reaches React Native as well.
42
+
43
+ ## 0.2.0
44
+
45
+ - Add headless `usePresence` with `PresenceBinding` / `PresenceState` for shared exit lifecycles.
46
+ - Let FocusScope place its first focus into a panel mounted after the scope.
47
+ - Support application injection of the optional Android accessibility-focus mover; keep absence of the native module a supported fallback.
48
+
49
+ See the [Hozo release notes and migration steps](https://github.com/iray-tno/hozo/blob/main/CHANGELOG.md#020) for cross-package changes and measured boundaries.
package/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # @hozo/behaviors
2
2
 
3
- Universal headless runtime behaviors and positioning primitives for Hozo.
3
+ Universal headless runtime behaviors for Hozo: the layer where **accessibility and internationalisation are first-class behaviours**.
4
4
 
5
- These primitives provide the essential interaction mechanics — focus management, outside click handling, keyboard navigation, collision-aware floating positioning, disclosure states, phonetic reading control, and hover delay groups — on both Web and React Native.
5
+ Those are the two concerns that should be designed in from the start and are usually added at the end. Defining them here, below every component, is how Hozo makes "from the start" the default ([decision 008](../../docs/decisions/008-i18n-is-a-connection.md)).
6
+
7
+ The behaviours cover focus management, outside click handling, keyboard navigation, collision-aware floating positioning, disclosure states, screen reader announcements, phonetic reading control, text direction, and hover delay groups, on both Web and React Native.
6
8
 
7
9
  ## Included Behaviors
8
10
 
@@ -71,6 +73,18 @@ export function HoverPreview() {
71
73
  }
72
74
  ```
73
75
 
76
+ ## Native pressable interaction facts
77
+
78
+ `@hozo/behaviors/pressable-interaction` exports `usePressableInteraction`.
79
+ It returns `state` (`pressed`, `hovered`, `focused`, `focusVisible`) and
80
+ eventless `handlers` for hover, focus, pointer/key modality and press changes.
81
+ The host delivers those events and composes any caller handlers afterwards.
82
+ Focus-visible inference is opt-in. The optional `onChange` callback receives
83
+ the next facts synchronously for the existing Native animation driver.
84
+ This is shared by the primitive and patterns; it has no listeners, subscriptions
85
+ or animation allocations of its own, and does not subscribe to environment
86
+ conditions such as media queries or colour scheme.
87
+
74
88
  <!-- generated: package-footer -->
75
89
 
76
90
  ---
@@ -0,0 +1,23 @@
1
+ import type { ComponentRef } from 'react';
2
+ import { type View } from 'react-native';
3
+ export type HozoFocusTarget = ComponentRef<typeof View>;
4
+ export type HozoFocusMover = (view: HozoFocusTarget) => void;
5
+ /**
6
+ * Hand over a better way to move accessibility focus, or `undefined` to stop.
7
+ *
8
+ * Idempotent and last-wins. Registering twice is a sign of two roots, which an
9
+ * application can legitimately have -- a test harness mounting its own -- and
10
+ * neither a throw nor a warning would help it.
11
+ */
12
+ export declare function setAccessibilityFocusMover(mover: HozoFocusMover | undefined | null): void;
13
+ /** Whether something has been registered. Read by diagnostics, not by behaviour. */
14
+ export declare function hasAccessibilityFocusMover(): boolean;
15
+ /**
16
+ * Put accessibility focus on `view`.
17
+ *
18
+ * Read at call time rather than captured, because registration happens during the
19
+ * application's startup and a module that captured the default at load would
20
+ * never see it.
21
+ */
22
+ export declare function moveAccessibilityFocus(view: HozoFocusTarget): void;
23
+ //# sourceMappingURL=accessibility-focus.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessibility-focus.native.d.ts","sourceRoot":"","sources":["../src/accessibility-focus.native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,EAAqB,KAAK,IAAI,EAAE,MAAM,cAAc,CAAA;AAE3D,MAAM,MAAM,eAAe,GAAG,YAAY,CAAC,OAAO,IAAI,CAAC,CAAA;AACvD,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAA;AAsD5D;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,CAEzF;AAED,oFAAoF;AACpF,wBAAgB,0BAA0B,IAAI,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAMlE"}
@@ -0,0 +1,81 @@
1
+ import { AccessibilityInfo } from 'react-native';
2
+ /**
3
+ * Moving accessibility focus, with `@hozo/native` able to take over.
4
+ *
5
+ * ## Registered, not resolved, and that is a correction
6
+ *
7
+ * `docs/decisions/006-shipping-native-code.md` says the capability is reached
8
+ * "through a resolved provider, never imported", pointing at
9
+ * `packages/engine/src/safe-area.native.ts:50`, which does
10
+ * `try { require('react-native-safe-area-context') } catch {}`. That shape does
11
+ * not transfer here, and the reason is Metro rather than taste.
12
+ *
13
+ * Metro resolves `require` at bundle time. A literal `require` of a package that
14
+ * is not installed is a **build failure**, `try`/`catch` or not -- the catch runs
15
+ * at runtime and the bundler never gets there. Safe areas get away with it
16
+ * because that module is only in the graph when the compiler emitted a safe-area
17
+ * class: a project that writes none never imports it. This module is in the graph
18
+ * of every application that renders a `Dialog`, so a `require` here would make an
19
+ * optional package mandatory, and would break every existing app on upgrade.
20
+ *
21
+ * So the application hands the capability in, in two lines next to wherever it
22
+ * registers its root component:
23
+ *
24
+ * ```ts
25
+ * import { setAccessibilityFocusMover } from '@hozo/behaviors/native'
26
+ * import { moveAccessibilityFocus } from '@hozo/native'
27
+ *
28
+ * setAccessibilityFocusMover(moveAccessibilityFocus)
29
+ * ```
30
+ *
31
+ * `moveAccessibilityFocus` is `undefined` on iOS and when the native module is
32
+ * not in the binary, and the setter accepts that and keeps the default -- so the
33
+ * call needs no condition around it.
34
+ *
35
+ * ## The default is what this library has always done
36
+ *
37
+ * `AccessibilityInfo.sendAccessibilityEvent(view, 'focus')`, which works about
38
+ * half the time on Android (#484). An application that registers nothing is
39
+ * exactly as well off as it was, which is the third part of the decision's gate
40
+ * and the reason the capability was admitted at all.
41
+ *
42
+ * ## Why this is in `@hozo/behaviors/native`
43
+ *
44
+ * It has one consumer today -- `Dialog` -- and the first draft of this lived in
45
+ * `@hozo/patterns` for that reason. Registration moved it: a module holding one
46
+ * mutable binding costs nothing to load, where a provider resolution would have
47
+ * run a `require` in every package that imported it, and the application doing
48
+ * the registering should not have to reach into a widget package to do it.
49
+ * `@hozo/behaviors/native` is the entry point that already exists for API with no
50
+ * Web counterpart.
51
+ */
52
+ let registered;
53
+ /**
54
+ * Hand over a better way to move accessibility focus, or `undefined` to stop.
55
+ *
56
+ * Idempotent and last-wins. Registering twice is a sign of two roots, which an
57
+ * application can legitimately have -- a test harness mounting its own -- and
58
+ * neither a throw nor a warning would help it.
59
+ */
60
+ export function setAccessibilityFocusMover(mover) {
61
+ registered = mover ?? undefined;
62
+ }
63
+ /** Whether something has been registered. Read by diagnostics, not by behaviour. */
64
+ export function hasAccessibilityFocusMover() {
65
+ return registered !== undefined;
66
+ }
67
+ /**
68
+ * Put accessibility focus on `view`.
69
+ *
70
+ * Read at call time rather than captured, because registration happens during the
71
+ * application's startup and a module that captured the default at load would
72
+ * never see it.
73
+ */
74
+ export function moveAccessibilityFocus(view) {
75
+ if (registered) {
76
+ registered(view);
77
+ return;
78
+ }
79
+ AccessibilityInfo.sendAccessibilityEvent(view, 'focus');
80
+ }
81
+ //# sourceMappingURL=accessibility-focus.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessibility-focus.native.js","sourceRoot":"","sources":["../src/accessibility-focus.native.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAa,MAAM,cAAc,CAAA;AAK3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,IAAI,UAAsC,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAwC;IACjF,UAAU,GAAG,KAAK,IAAI,SAAS,CAAA;AACjC,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,0BAA0B;IACxC,OAAO,UAAU,KAAK,SAAS,CAAA;AACjC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAqB;IAC1D,IAAI,UAAU,EAAE,CAAC;QACf,UAAU,CAAC,IAAI,CAAC,CAAA;QAChB,OAAM;IACR,CAAC;IACD,iBAAiB,CAAC,sBAAsB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AACzD,CAAC"}
@@ -0,0 +1,23 @@
1
+ export interface CommandShortcutOptions {
2
+ /** The letter, pressed with ⌘ on Apple platforms and Ctrl elsewhere; `k` by default. */
3
+ key?: string;
4
+ /** Off while something else owns the keyboard. */
5
+ enabled?: boolean;
6
+ }
7
+ /** ⌘ on an Apple platform, Ctrl elsewhere -- the modifier each one's own shortcuts use. */
8
+ export declare function isApplePlatform(): boolean;
9
+ /**
10
+ * Calls `onTrigger` for ⌘K on a Mac and Ctrl+K elsewhere, from anywhere on the
11
+ * page (#152).
12
+ *
13
+ * The browser's default is prevented only for the press that is handled:
14
+ * Ctrl+K is Chrome's "search from the address bar", and taking it away when
15
+ * nothing opens would be taking it for nothing. A press during IME
16
+ * composition is not a shortcut -- the composition owns the keyboard -- and
17
+ * neither is a held key repeating.
18
+ *
19
+ * A behaviour rather than part of `CommandPalette`, because a shortcut is
20
+ * useful without one: to focus a search field, or open a different panel.
21
+ */
22
+ export declare function useCommandShortcut(onTrigger: () => void, options?: CommandShortcutOptions): void;
23
+ //# sourceMappingURL=command-shortcut.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-shortcut.d.ts","sourceRoot":"","sources":["../src/command-shortcut.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,sBAAsB;IACrC,wFAAwF;IACxF,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,kDAAkD;IAClD,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,2FAA2F;AAC3F,wBAAgB,eAAe,IAAI,OAAO,CAOzC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,IAAI,EAAE,OAAO,GAAE,sBAA2B,QAkB7F"}
@@ -0,0 +1,47 @@
1
+ import { useEffect, useRef } from 'react';
2
+ /** ⌘ on an Apple platform, Ctrl elsewhere -- the modifier each one's own shortcuts use. */
3
+ export function isApplePlatform() {
4
+ if (typeof navigator === 'undefined')
5
+ return false;
6
+ const platform = navigator.userAgentData?.platform ??
7
+ navigator.platform ??
8
+ '';
9
+ return /mac|iphone|ipad|ipod/i.test(platform);
10
+ }
11
+ /**
12
+ * Calls `onTrigger` for ⌘K on a Mac and Ctrl+K elsewhere, from anywhere on the
13
+ * page (#152).
14
+ *
15
+ * The browser's default is prevented only for the press that is handled:
16
+ * Ctrl+K is Chrome's "search from the address bar", and taking it away when
17
+ * nothing opens would be taking it for nothing. A press during IME
18
+ * composition is not a shortcut -- the composition owns the keyboard -- and
19
+ * neither is a held key repeating.
20
+ *
21
+ * A behaviour rather than part of `CommandPalette`, because a shortcut is
22
+ * useful without one: to focus a search field, or open a different panel.
23
+ */
24
+ export function useCommandShortcut(onTrigger, options = {}) {
25
+ const { key = 'k', enabled = true } = options;
26
+ const latest = useRef(onTrigger);
27
+ latest.current = onTrigger;
28
+ useEffect(() => {
29
+ if (!enabled || typeof document === 'undefined')
30
+ return;
31
+ const apple = isApplePlatform();
32
+ const handle = (event) => {
33
+ if (event.isComposing || event.repeat)
34
+ return;
35
+ const modifier = apple ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey;
36
+ if (!modifier || event.altKey || event.shiftKey)
37
+ return;
38
+ if (event.key.toLowerCase() !== key.toLowerCase())
39
+ return;
40
+ event.preventDefault();
41
+ latest.current();
42
+ };
43
+ document.addEventListener('keydown', handle);
44
+ return () => document.removeEventListener('keydown', handle);
45
+ }, [enabled, key]);
46
+ }
47
+ //# sourceMappingURL=command-shortcut.js.map
@@ -0,0 +1 @@
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AW,EAAE,KAAK,GAAG,CAAC,WAAW,EAAE;gBAAE,OAAM;YACzD,KAAK,CAAC,cAAc,EAAE,CAAA;YACtB,MAAM,CAAC,OAAO,EAAE,CAAA;QAClB,CAAC,CAAA;QACD,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAC5C,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;IAC9D,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAA;AACpB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { CommandShortcutOptions } from './command-shortcut.ts';
2
+ export type { CommandShortcutOptions };
3
+ export declare function isApplePlatform(): boolean;
4
+ /**
5
+ * Nothing on React Native: a phone has no ⌘K, and a hardware keyboard reaches
6
+ * an application through APIs React Native does not expose as one event. The
7
+ * palette is opened from a control the application draws. Kept as a hook so a
8
+ * screen written once calls it on both platforms.
9
+ */
10
+ export declare function useCommandShortcut(_onTrigger: () => void, _options?: CommandShortcutOptions): void;
11
+ //# sourceMappingURL=command-shortcut.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-shortcut.native.d.ts","sourceRoot":"","sources":["../src/command-shortcut.native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAEnE,YAAY,EAAE,sBAAsB,EAAE,CAAA;AAEtC,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,IAAI,EAAE,QAAQ,GAAE,sBAA2B,QAAI"}
@@ -0,0 +1,11 @@
1
+ export function isApplePlatform() {
2
+ return false;
3
+ }
4
+ /**
5
+ * Nothing on React Native: a phone has no ⌘K, and a hardware keyboard reaches
6
+ * an application through APIs React Native does not expose as one event. The
7
+ * palette is opened from a control the application draws. Kept as a hook so a
8
+ * screen written once calls it on both platforms.
9
+ */
10
+ export function useCommandShortcut(_onTrigger, _options = {}) { }
11
+ //# sourceMappingURL=command-shortcut.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-shortcut.native.js","sourceRoot":"","sources":["../src/command-shortcut.native.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,eAAe;IAC7B,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAsB,EAAE,QAAQ,GAA2B,EAAE,IAAG,CAAC"}
@@ -20,6 +20,14 @@ export interface FocusScopeProps {
20
20
  trapped?: boolean;
21
21
  autoFocus?: boolean;
22
22
  restoreFocus?: boolean;
23
+ /**
24
+ * Whether the scope holds focus. Turning it false does what unmounting
25
+ * does -- the trap is released and focus goes back to the opener -- for
26
+ * an overlay that stays mounted while it animates out (decision 007).
27
+ * Focus left inside a panel that is fading away would be on something
28
+ * nobody can use, and on nothing once the panel goes.
29
+ */
30
+ active?: boolean;
23
31
  className?: string;
24
32
  style?: CSSProperties;
25
33
  }
@@ -27,5 +35,5 @@ export interface FocusScopeProps {
27
35
  * Universal `<FocusScope>` component for Web.
28
36
  * Traps Tab key navigation, moves initial focus, and safely restores focus on unmount.
29
37
  */
30
- export declare function FocusScope({ children, trapped, autoFocus, restoreFocus, className, style, }: FocusScopeProps): import("react").JSX.Element;
38
+ export declare function FocusScope({ children, trapped, autoFocus, restoreFocus, active, className, style, }: FocusScopeProps): import("react").JSX.Element;
31
39
  //# sourceMappingURL=focus-scope.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"focus-scope.d.ts","sourceRoot":"","sources":["../src/focus-scope.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAqB,MAAM,OAAO,CAAA;AAE7E,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,SAAS,CAAC,EAAE,OAAO,CAAA;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tB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAaD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EACzB,QAAQ,EACR,OAAc,EACd,SAAgB,EAChB,YAAmB,EACnB,MAAa,EACb,SAAS,EACT,KAAK,GACN,EAAE,eAAe,+BAmHjB"}
@@ -21,16 +21,25 @@ export function shouldRestoreFocus(opener) {
21
21
  return opener?.focusable === true;
22
22
  }
23
23
  const FOCUSABLE_SELECTOR = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
24
+ /**
25
+ * How long to keep trying to move focus in: ten tries a frame's length
26
+ * apart. A container hidden until it is measured shows by the first or
27
+ * second; ten is a bound, not a guess at a delay.
28
+ */
29
+ const INITIAL_FOCUS_ATTEMPTS = 10;
30
+ const INITIAL_FOCUS_INTERVAL_MS = 16;
24
31
  /**
25
32
  * Universal `<FocusScope>` component for Web.
26
33
  * Traps Tab key navigation, moves initial focus, and safely restores focus on unmount.
27
34
  */
28
- export function FocusScope({ children, trapped = true, autoFocus = true, restoreFocus = true, className, style, }) {
35
+ export function FocusScope({ children, trapped = true, autoFocus = true, restoreFocus = true, active = true, className, style, }) {
29
36
  const containerRef = useRef(null);
30
37
  const openerRef = useRef(null);
31
38
  useEffect(() => {
32
39
  if (typeof document === 'undefined')
33
40
  return;
41
+ if (!active)
42
+ return;
34
43
  // Capture the trigger element that opened this scope
35
44
  if (restoreFocus && document.activeElement instanceof HTMLElement) {
36
45
  openerRef.current = document.activeElement;
@@ -38,21 +47,43 @@ export function FocusScope({ children, trapped = true, autoFocus = true, restore
38
47
  const container = containerRef.current;
39
48
  if (!container)
40
49
  return;
41
- if (autoFocus) {
50
+ // Where focus goes on the way in: the first candidate, or the container
51
+ // itself (tabIndex="-1") so a screen reader still announces the role and
52
+ // name.
53
+ const initialTarget = () => {
42
54
  const focusables = Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter((el) => el.offsetParent !== null || el.getClientRects().length > 0);
43
55
  const candidates = focusables.map((el) => ({
44
56
  autofocus: el.hasAttribute('autofocus'),
45
57
  focusable: !el.hasAttribute('disabled') && el.tabIndex !== -1,
46
58
  }));
47
59
  const targetIdx = initialFocusIndex(candidates);
48
- if (targetIdx !== null && focusables[targetIdx]) {
49
- focusables[targetIdx].focus();
50
- }
51
- else {
52
- // Fallback: focus container itself (tabIndex="-1") so screen readers announce dialog role/label
53
- container.focus();
54
- }
55
- }
60
+ return (targetIdx !== null && focusables[targetIdx]) || container;
61
+ };
62
+ // `focus()` on an element that cannot take focus yet does nothing, and
63
+ // says nothing. `FloatingPositioner` is the case that found it: it draws
64
+ // its content `visibility: hidden` until it has measured, in an effect
65
+ // that runs after this one, so a popover's first focus landed on nothing
66
+ // and stayed on the trigger. Trying again shortly after covers that and
67
+ // any container like it -- but only while focus is still where the scope
68
+ // found it, so a person who has moved on is not pulled back. A timer
69
+ // rather than an animation frame: `focus()` resolves style itself, so it
70
+ // needs the positioner to have rendered, not the page to have painted --
71
+ // and frames do not run at all in a tab that is not being drawn.
72
+ let retry;
73
+ const moveIn = (attempt) => {
74
+ const target = initialTarget();
75
+ target.focus();
76
+ if (document.activeElement === target || attempt >= INITIAL_FOCUS_ATTEMPTS)
77
+ return;
78
+ const stillWaiting = document.activeElement === openerRef.current ||
79
+ document.activeElement === document.body ||
80
+ document.activeElement === null;
81
+ if (!stillWaiting)
82
+ return;
83
+ retry = setTimeout(() => moveIn(attempt + 1), INITIAL_FOCUS_INTERVAL_MS);
84
+ };
85
+ if (autoFocus)
86
+ moveIn(0);
56
87
  const handleKeyDown = (event) => {
57
88
  if (!trapped || event.key !== 'Tab')
58
89
  return;
@@ -79,6 +110,7 @@ export function FocusScope({ children, trapped = true, autoFocus = true, restore
79
110
  };
80
111
  container.addEventListener('keydown', handleKeyDown);
81
112
  return () => {
113
+ clearTimeout(retry);
82
114
  container.removeEventListener('keydown', handleKeyDown);
83
115
  if (restoreFocus) {
84
116
  const opener = openerRef.current;
@@ -90,7 +122,7 @@ export function FocusScope({ children, trapped = true, autoFocus = true, restore
90
122
  }
91
123
  }
92
124
  };
93
- }, [trapped, autoFocus, restoreFocus]);
125
+ }, [trapped, autoFocus, restoreFocus, active]);
94
126
  return (_jsx("div", { ref: containerRef, tabIndex: -1, className: className, style: { outline: 'none', ...style }, children: children }));
95
127
  }
96
128
  //# sourceMappingURL=focus-scope.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"focus-scope.js","sourceRoot":"","sources":["../src/focus-scope.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsC,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAO7E;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAqC;IACrE,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,SAAS,CAAC,CAAA;IACzE,IAAI,SAAS,KAAK,CAAC,CAAC;QAAE,OAAO,SAAS,CAAA;IACtC,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACtD,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAA;AACpC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAyC;IAC1E,OAAO,MAAM,EAAE,SAAS,KAAK,IAAI,CAAA;AACnC,CAAC;AAWD,MAAM,kBAAkB,GACtB,2IAA2I,CAAA;AAE7I;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,QAAQ,EACR,OAAO,GAAG,IAAI,EACd,SAAS,GAAG,IAAI,EAChB,YAAY,GAAG,IAAI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,MAAM,GAAG,SAAS,CAAC,OAAO,CAAA;gBAChC,IACE,MAAM;oBACN,kBAAkB,CAAC;wBACjB,SAAS,EAAE,MAAM,CAAC,WAAW,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC;qBAClE,CAAC,EACF,CAAC;oBACD,MAAM,CAAC,KAAK,EAAE,CAAA;gBAChB,CAAC;YACH,CAAC;QACH,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC,CAAA;IAE9C,OAAO,CACL,cACE,GAAG,EAAE,YAAY,EACjB,QAAQ,EAAE,CAAC,CAAC,EACZ,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,YAEnC,QAAQ,GACL,CACP,CAAA;AACH,CAAC"}
package/dist/i18n.d.ts ADDED
@@ -0,0 +1,140 @@
1
+ import { type ReactNode } from 'react';
2
+ /**
3
+ * Every string Hozo's components show or announce, in English, by key.
4
+ *
5
+ * Exported so a project can seed its catalogue from it, and so a test can
6
+ * check none is missing. Parameters are named (`{remaining}`), because every
7
+ * library this connects to interpolates by name.
8
+ */
9
+ export declare const hozoMessages: {
10
+ readonly 'hozo.avatar.label': '{name}, {status}';
11
+ readonly 'hozo.avatar.statusBusy': 'busy';
12
+ readonly 'hozo.avatar.statusOffline': 'offline';
13
+ readonly 'hozo.avatar.statusOnline': 'online';
14
+ readonly 'hozo.badge.overflow': 'more than {max}';
15
+ readonly 'hozo.bottomSheet.handle': 'Resize';
16
+ readonly 'hozo.calendar.nextMonth': 'Next month';
17
+ readonly 'hozo.calendar.previousMonth': 'Previous month';
18
+ readonly 'hozo.calendar.rangeEnd': 'end of range';
19
+ readonly 'hozo.calendar.rangeStart': 'start of range';
20
+ readonly 'hozo.calendar.today': 'today';
21
+ readonly 'hozo.chip.remove': 'Remove {label}';
22
+ readonly 'hozo.color.black': 'black';
23
+ readonly 'hozo.color.blue': 'blue';
24
+ readonly 'hozo.color.cyan': 'cyan';
25
+ readonly 'hozo.color.dark': 'dark {color}';
26
+ readonly 'hozo.color.gray': 'gray';
27
+ readonly 'hozo.color.green': 'green';
28
+ readonly 'hozo.color.light': 'light {color}';
29
+ readonly 'hozo.color.orange': 'orange';
30
+ readonly 'hozo.color.pink': 'pink';
31
+ readonly 'hozo.color.purple': 'purple';
32
+ readonly 'hozo.color.red': 'red';
33
+ readonly 'hozo.color.white': 'white';
34
+ readonly 'hozo.color.yellow': 'yellow';
35
+ readonly 'hozo.colorPicker.alpha': 'Opacity';
36
+ readonly 'hozo.colorPicker.alphaValue': '{value}% opaque';
37
+ readonly 'hozo.colorPicker.described': '{name}, {hex}';
38
+ readonly 'hozo.colorPicker.eyeDropper': 'Pick a colour from the screen';
39
+ readonly 'hozo.colorPicker.hex': 'Hex colour';
40
+ readonly 'hozo.colorPicker.hue': 'Hue';
41
+ readonly 'hozo.colorPicker.hueValue': '{degrees} degrees, {name}';
42
+ readonly 'hozo.colorPicker.lightness': 'Lightness';
43
+ readonly 'hozo.colorPicker.percent': '{value}%';
44
+ readonly 'hozo.colorPicker.presets': 'Presets';
45
+ readonly 'hozo.colorPicker.saturation': 'Saturation';
46
+ readonly 'hozo.commandPalette.empty': 'No results';
47
+ readonly 'hozo.commandPalette.label': 'Command palette';
48
+ readonly 'hozo.commandPalette.oneResult': '1 result';
49
+ readonly 'hozo.commandPalette.results': '{count} results';
50
+ readonly 'hozo.datePicker.dialog': 'Choose a date';
51
+ readonly 'hozo.dateRangePicker.dialog': 'Choose a range of dates';
52
+ readonly 'hozo.dateTimePicker.dialog': 'Choose a date and time';
53
+ readonly 'hozo.dateTimePicker.done': 'Done';
54
+ readonly 'hozo.fileDropzone.selectedMany': '{count} files selected';
55
+ readonly 'hozo.fileDropzone.selectedOne': '{name} selected, {size}';
56
+ readonly 'hozo.fileDropzone.tooLarge': '{name} is too large: {size}, and the limit is {limit}';
57
+ readonly 'hozo.fileDropzone.tooMany': '{name} was not added: one pick takes {max}';
58
+ readonly 'hozo.fileDropzone.tooSmall': '{name} is too small: {size}';
59
+ readonly 'hozo.fileDropzone.unavailable': 'No file picker is available';
60
+ readonly 'hozo.fileDropzone.wrongType': '{name} is not an accepted kind of file';
61
+ readonly 'hozo.nativeSelect.cancel': 'Cancel';
62
+ readonly 'hozo.otpInput.hint': '{length} characters';
63
+ readonly 'hozo.pagination.label': 'Pagination';
64
+ readonly 'hozo.pagination.next': 'Next page';
65
+ readonly 'hozo.pagination.page': 'Page {page}';
66
+ readonly 'hozo.pagination.previous': 'Previous page';
67
+ readonly 'hozo.stepper.completed': 'completed';
68
+ readonly 'hozo.stepper.current': 'current';
69
+ readonly 'hozo.stepper.error': 'has an error';
70
+ readonly 'hozo.stepper.label': 'Progress';
71
+ readonly 'hozo.stepper.step': 'Step {step} of {count}: {label}, {status}';
72
+ readonly 'hozo.stepper.upcoming': 'not started';
73
+ readonly 'hozo.textArea.remaining': '{remaining} of {maxLength} characters left';
74
+ readonly 'hozo.timePicker.decrease': 'Decrease';
75
+ readonly 'hozo.timePicker.empty': '--';
76
+ readonly 'hozo.timePicker.hour': 'Hour';
77
+ readonly 'hozo.timePicker.increase': 'Increase';
78
+ readonly 'hozo.timePicker.minute': 'Minute';
79
+ readonly 'hozo.timePicker.period': 'AM or PM';
80
+ };
81
+ export type HozoMessageKey = keyof typeof hozoMessages;
82
+ export type HozoMessageParams = Readonly<Record<string, string | number>>;
83
+ export interface HozoI18n {
84
+ /** BCP 47. Used for `Intl`: dates, numbers, the first day of the week. */
85
+ locale?: string;
86
+ /**
87
+ * Which way the content runs. Read by behaviours that cannot ask the
88
+ * platform; never applied. The Web's direction is `<html dir>` and
89
+ * Native's is `I18nManager`, and both are the application's to set.
90
+ */
91
+ dir?: 'ltr' | 'rtl';
92
+ /**
93
+ * The project's translation of `key`. `fallback` is Hozo's English with
94
+ * `params` already filled in, for a library that shows its default when a
95
+ * key is missing.
96
+ */
97
+ translate?: (key: HozoMessageKey, params: HozoMessageParams, fallback: string) => string;
98
+ }
99
+ export interface HozoI18nProviderProps {
100
+ value: HozoI18n;
101
+ children?: ReactNode;
102
+ }
103
+ /**
104
+ * Puts a project's i18n where Hozo's components can read it.
105
+ *
106
+ * Give it a new `value` when the language changes -- `useMemo` on the
107
+ * language -- and every Hozo string below re-renders in it.
108
+ */
109
+ export declare function HozoI18nProvider({ value, children }: HozoI18nProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<HozoI18n>>;
110
+ export declare function useHozoI18n(): HozoI18n;
111
+ /**
112
+ * A function resolving one of Hozo's strings: the component's own prop if
113
+ * there is one, then the project's translation, then Hozo's English.
114
+ */
115
+ export declare function useHozoMessage(): (key: HozoMessageKey, params?: HozoMessageParams, explicit?: string) => string;
116
+ /** The part of an i18next instance this reads. */
117
+ export interface I18nextLike {
118
+ t(key: string, options?: Record<string, unknown>): string;
119
+ language?: string;
120
+ dir?(language?: string): 'ltr' | 'rtl';
121
+ }
122
+ /**
123
+ * Hozo's i18n from an i18next instance: Hozo's keys are i18next keys, and
124
+ * Hozo's English is i18next's `defaultValue`.
125
+ */
126
+ export declare function fromI18next(i18n: I18nextLike): HozoI18n;
127
+ /** The part of a react-intl `IntlShape` this reads. */
128
+ export interface ReactIntlLike {
129
+ formatMessage(descriptor: {
130
+ id: string;
131
+ defaultMessage?: string;
132
+ }, values?: Record<string, string | number>): string;
133
+ locale?: string;
134
+ }
135
+ /**
136
+ * Hozo's i18n from react-intl: Hozo's keys are message ids, and Hozo's
137
+ * English is the `defaultMessage`.
138
+ */
139
+ export declare function fromReactIntl(intl: ReactIntlLike): HozoI18n;
140
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAcA,OAAO,EAAgC,KAAK,SAAS,EAA2B,MAAM,OAAO,CAAA;AAE7F;;;;;;GAMG;AACH,eAAO,MAAM,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