@proedis/react 2.1.1 → 2.2.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 (53) hide show
  1. package/README.md +29 -1
  2. package/cjs/hooks/useAnnouncer.js +81 -0
  3. package/cjs/hooks/useAnnouncer.js.map +1 -0
  4. package/cjs/hooks/useClipboard.js +116 -0
  5. package/cjs/hooks/useClipboard.js.map +1 -0
  6. package/cjs/hooks/useDelayedBusy.js +80 -0
  7. package/cjs/hooks/useDelayedBusy.js.map +1 -0
  8. package/cjs/hooks/useForkRef.js +7 -2
  9. package/cjs/hooks/useForkRef.js.map +1 -1
  10. package/cjs/hooks/useMediaQuery.js +69 -0
  11. package/cjs/hooks/useMediaQuery.js.map +1 -0
  12. package/cjs/hooks/useOverflowItems.js +129 -0
  13. package/cjs/hooks/useOverflowItems.js.map +1 -0
  14. package/cjs/hooks/usePrefersReducedMotion.js +34 -0
  15. package/cjs/hooks/usePrefersReducedMotion.js.map +1 -0
  16. package/cjs/index.js +16 -0
  17. package/cjs/index.js.map +1 -1
  18. package/cjs/utils/contextBuilder.js +26 -0
  19. package/cjs/utils/contextBuilder.js.map +1 -1
  20. package/cjs/utils/inertValue.js +40 -0
  21. package/cjs/utils/inertValue.js.map +1 -0
  22. package/esm/hooks/useAnnouncer.js +60 -0
  23. package/esm/hooks/useAnnouncer.js.map +1 -0
  24. package/esm/hooks/useClipboard.js +95 -0
  25. package/esm/hooks/useClipboard.js.map +1 -0
  26. package/esm/hooks/useDelayedBusy.js +59 -0
  27. package/esm/hooks/useDelayedBusy.js.map +1 -0
  28. package/esm/hooks/useForkRef.js +7 -2
  29. package/esm/hooks/useForkRef.js.map +1 -1
  30. package/esm/hooks/useMediaQuery.js +48 -0
  31. package/esm/hooks/useMediaQuery.js.map +1 -0
  32. package/esm/hooks/useOverflowItems.js +107 -0
  33. package/esm/hooks/useOverflowItems.js.map +1 -0
  34. package/esm/hooks/usePrefersReducedMotion.js +32 -0
  35. package/esm/hooks/usePrefersReducedMotion.js.map +1 -0
  36. package/esm/index.js +8 -1
  37. package/esm/index.js.map +1 -1
  38. package/esm/utils/contextBuilder.js +26 -1
  39. package/esm/utils/contextBuilder.js.map +1 -1
  40. package/esm/utils/inertValue.js +19 -0
  41. package/esm/utils/inertValue.js.map +1 -0
  42. package/package.json +3 -3
  43. package/types/hooks/index.d.ts +6 -0
  44. package/types/hooks/useAnnouncer.d.ts +22 -0
  45. package/types/hooks/useClipboard.d.ts +28 -0
  46. package/types/hooks/useDelayedBusy.d.ts +28 -0
  47. package/types/hooks/useForkRef.d.ts +8 -2
  48. package/types/hooks/useMediaQuery.d.ts +25 -0
  49. package/types/hooks/useOverflowItems.d.ts +46 -0
  50. package/types/hooks/usePrefersReducedMotion.d.ts +18 -0
  51. package/types/utils/contextBuilder.d.ts +20 -0
  52. package/types/utils/index.d.ts +1 -0
  53. package/types/utils/inertValue.d.ts +9 -0
package/README.md CHANGED
@@ -19,7 +19,7 @@ No UI kit, no styling, no opinions about how anything looks. 🎨
19
19
  | | |
20
20
  | --- | --- |
21
21
  | **Contexts** | `contextBuilder` — a context and its hook, with a real error instead of `undefined` |
22
- | **Component props** | `UIComponentProps` / `UIVoidComponentProps`, the shared prop surface every component starts from |
22
+ | **Component props** | `UIComponentProps` / `UIVoidComponentProps`, the composers every component's props are written with, over the `CoreUIComponentProps` / `CoreUIVoidComponentProps` surface they inherit |
23
23
  | **Shorthands** | `ShorthandItem`, `createShorthandFactory`, `creatableComponent` — accept props *or* a node for the same slot |
24
24
  | **Components** | `RenderWhen`, `compose` |
25
25
  | **State hooks** | `useAutoControlledState`, `useObjectState`, `useSafeState`, `useInputValue`, `useDataManager`, `useDataSelector` |
@@ -74,6 +74,20 @@ const [ AuthContext, useAuthContext ] = contextBuilder<AuthContextValue>('Auth')
74
74
  const { user } = useAuthContext(); // throws outside the provider, with the name in the message
75
75
  ```
76
76
 
77
+ ### 🏗️ `optionalContextBuilder(name, defaultValue)`
78
+
79
+ The same pair for a context whose provider is **optional**: outside it the hook returns `defaultValue`
80
+ instead of throwing. It is for a component that also works on its own and reads the context only when
81
+ something above provides it, a control inside or outside a field, a dialog nested or not. The value may
82
+ be anything, a primitive included, which `contextBuilder` cannot take: it tells a missing provider apart
83
+ by a falsy value.
84
+
85
+ ```tsx
86
+ const [ OverlayLevelContext, useOverlayLevel ] = optionalContextBuilder('OverlayLevel', 0);
87
+
88
+ const level = useOverlayLevel(); // 0 with no provider above
89
+ ```
90
+
77
91
  ### 🎛️ `UIComponentProps` and `UIVoidComponentProps`
78
92
 
79
93
  The prop surface every Proedis component starts from — `className`, `style`, the element type
@@ -151,6 +165,11 @@ providers at the root of an app into a single element.
151
165
  | `useClickOutside(target, callback)` | the outside-click primitive behind every dropdown |
152
166
  | `useWindowSize(options?)` | viewport size, debounced |
153
167
  | `useElementType(props, default)` | resolve the `as` prop into the element to render |
168
+ | `useMediaQuery(query, serverSnapshot?)` | whether a media query matches, through `useSyncExternalStore`; `false` on the server and on the first client render unless told otherwise |
169
+ | `usePrefersReducedMotion()` | whether the user asked for less motion; ⚠️ `true` on the server and on the first client render, because guessing "animate" is the worse mistake |
170
+ | `useDelayedBusy(busy, options?)` | `{ busy, visible }`: the block at once, the look of a wait after 300ms and held at least 400, so a fast answer flashes nothing |
171
+ | `useAnnouncer()` | `[ message, announce ]` for a live region: `announce` empties it first, so the same text twice is spoken twice; the last of two quick calls wins, an empty text is ignored, and the region stays the caller's to render |
172
+ | `useOverflowItems(containerRef, measureRef, options)` | which items of a row fit and which go into a "More" menu, measured on a hidden copy of the row; `fitItems` is the pure half |
154
173
  | `useAutoSizer(options?)` | the room an element has, in pixels, kept up to date — see below |
155
174
 
156
175
  💡 Several of these are built on `useSyncedRef`, and that is the pattern worth internalising: keep the
@@ -161,6 +180,15 @@ changes.
161
180
  value is written during render, which is what makes it current for the commit it belongs to, and a
162
181
  render that gets discarded leaves the container holding something that was never committed.
163
182
 
183
+ ### 🧩 `inertValue(value)`
184
+
185
+ The value of the `inert` attribute for the React that is running: `true` on 19, `''` on 18, which drops
186
+ a boolean with a warning and leaves the element live. `undefined` when `value` is false.
187
+
188
+ ```tsx
189
+ <div inert={inertValue(isBusy)}>…</div>
190
+ ```
191
+
164
192
  ### 📐 `useAutoSizer(options?)`
165
193
 
166
194
  The replacement for `height: calc(100vh - 320px)`.
@@ -0,0 +1,81 @@
1
+ 'use client';'use strict';
2
+
3
+ var React = require('react');
4
+ var useUnmountEffect = require('./useUnmountEffect.js');
5
+
6
+ function _interopNamespaceDefault(e) {
7
+ var n = Object.create(null);
8
+ if (e) {
9
+ Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default') {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ }
19
+ n.default = e;
20
+ return Object.freeze(n);
21
+ }
22
+
23
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
24
+
25
+ /* --------
26
+ * Hook Definition
27
+ * -------- */
28
+ /**
29
+ * The text of a live region, announced again even when it repeats.
30
+ *
31
+ * ```tsx
32
+ * const [ message, announce ] = useAnnouncer();
33
+ *
34
+ * <button onClick={() => { remove(file); announce(`${file.name} removed`); }}>Remove</button>
35
+ * <span role={'status'} className={'sr-only'}>{message}</span>
36
+ * ```
37
+ *
38
+ * A screen reader speaks a live region when its content changes, so setting the same text twice in
39
+ * a row says nothing the second time: two files with the same name removed one after the other, the
40
+ * same sort applied again. `announce` empties the region first and writes the text on the next task,
41
+ * which makes every call a change.
42
+ *
43
+ * A call replaces one still pending, so only the last text is spoken; an empty text is ignored, so
44
+ * an optional label can be passed as it is. The region itself is the caller's: the hook renders
45
+ * nothing, and the element, its role and its slot stay where the component decides.
46
+ */
47
+ function useAnnouncer() {
48
+ // ----
49
+ // Internal State
50
+ // ----
51
+ const [message, setMessage] = React__namespace.useState('');
52
+ const timerRef = React__namespace.useRef(null);
53
+ // ----
54
+ // Handlers
55
+ // ----
56
+ const announce = React__namespace.useCallback((text) => {
57
+ if (!text) {
58
+ return;
59
+ }
60
+ if (timerRef.current !== null) {
61
+ window.clearTimeout(timerRef.current);
62
+ }
63
+ setMessage('');
64
+ timerRef.current = window.setTimeout(() => {
65
+ timerRef.current = null;
66
+ setMessage(text);
67
+ });
68
+ }, []);
69
+ // ----
70
+ // Lifecycle Events
71
+ // ----
72
+ useUnmountEffect.useUnmountEffect(() => {
73
+ if (timerRef.current !== null) {
74
+ window.clearTimeout(timerRef.current);
75
+ }
76
+ });
77
+ return [message, announce];
78
+ }
79
+
80
+ exports.useAnnouncer = useAnnouncer;
81
+ //# sourceMappingURL=useAnnouncer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAnnouncer.js","sources":["../../../src/hooks/useAnnouncer.ts"],"sourcesContent":[null],"names":["React","useUnmountEffect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAeA;;AAEc;AAEd;;;;;;;;;;;;;;;;;;AAkBG;SACa,YAAY,GAAA;;;;AAK1B,IAAA,MAAM,CAAE,OAAO,EAAE,UAAU,CAAE,GAAGA,gBAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;IAClD,MAAM,QAAQ,GAAGA,gBAAK,CAAC,MAAM,CAAgB,IAAI,CAAC;;;;IAMlD,MAAM,QAAQ,GAAGA,gBAAK,CAAC,WAAW,CAAC,CAAC,IAA+B,KAAU;QAC3E,IAAI,CAAC,IAAI,EAAE;YACT;QACF;AAEA,QAAA,IAAI,QAAQ,CAAC,OAAO,KAAK,IAAI,EAAE;AAC7B,YAAA,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC;QACvC;QAEA,UAAU,CAAC,EAAE,CAAC;QAEd,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAK;AACxC,YAAA,QAAQ,CAAC,OAAO,GAAG,IAAI;YACvB,UAAU,CAAC,IAAI,CAAC;AAClB,QAAA,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC;;;;IAMNC,iCAAgB,CAAC,MAAK;AACpB,QAAA,IAAI,QAAQ,CAAC,OAAO,KAAK,IAAI,EAAE;AAC7B,YAAA,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC;QACvC;AACF,IAAA,CAAC,CAAC;AAGF,IAAA,OAAO,CAAE,OAAO,EAAE,QAAQ,CAAW;AAEvC;;;;"}
@@ -0,0 +1,116 @@
1
+ 'use client';'use strict';
2
+
3
+ var React = require('react');
4
+
5
+ function _interopNamespaceDefault(e) {
6
+ var n = Object.create(null);
7
+ if (e) {
8
+ Object.keys(e).forEach(function (k) {
9
+ if (k !== 'default') {
10
+ var d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: function () { return e[k]; }
14
+ });
15
+ }
16
+ });
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+
22
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
23
+
24
+ /* --------
25
+ * Helpers
26
+ * -------- */
27
+ /**
28
+ * Writes the text with the Clipboard API where the page may use it, a secure context, and with a
29
+ * selected textarea and `execCommand('copy')` elsewhere: an intranet served over plain http has no
30
+ * `navigator.clipboard` at all. The focus goes back where it was, without scrolling.
31
+ */
32
+ async function writeText(text) {
33
+ if (window.isSecureContext && typeof navigator.clipboard?.writeText === 'function') {
34
+ await navigator.clipboard.writeText(text);
35
+ return;
36
+ }
37
+ const active = document.activeElement instanceof HTMLElement ? document.activeElement : null;
38
+ const area = document.createElement('textarea');
39
+ area.value = text;
40
+ area.setAttribute('readonly', '');
41
+ area.setAttribute('aria-hidden', 'true');
42
+ area.style.position = 'fixed';
43
+ area.style.inset = '0 auto auto 0';
44
+ area.style.opacity = '0';
45
+ area.style.pointerEvents = 'none';
46
+ document.body.appendChild(area);
47
+ area.select();
48
+ try {
49
+ /* Deprecated, and the only way left where the Clipboard API is not offered */
50
+ if (!document.execCommand('copy')) {
51
+ throw new Error('The browser refused to copy');
52
+ }
53
+ }
54
+ finally {
55
+ area.remove();
56
+ active?.focus({ preventScroll: true });
57
+ }
58
+ }
59
+ /* --------
60
+ * Hook Definition
61
+ * -------- */
62
+ /**
63
+ * Copies a text to the clipboard and says how it went, for a button that turns into a tick for a moment.
64
+ *
65
+ * ```tsx
66
+ * const clipboard = useClipboard();
67
+ *
68
+ * <button onClick={() => clipboard.copy(apiKey)}>
69
+ * {clipboard.status === 'copied' ? 'Copied' : 'Copy'}
70
+ * </button>
71
+ * ```
72
+ *
73
+ * The value may be a function, read at the moment of the copy, and it may be asynchronous: a link
74
+ * created on demand. A second copy before the reset starts the time again.
75
+ */
76
+ function useClipboard(options = {}) {
77
+ // ----
78
+ // Options Deconstruct
79
+ // ----
80
+ const { resetAfter = 1500 } = options;
81
+ // ----
82
+ // Internal State
83
+ // ----
84
+ const [status, setStatus] = React__namespace.useState('idle');
85
+ const timerRef = React__namespace.useRef(undefined);
86
+ // ----
87
+ // Lifecycle Events
88
+ // ----
89
+ React__namespace.useEffect(() => () => window.clearTimeout(timerRef.current), []);
90
+ // ----
91
+ // Handlers
92
+ // ----
93
+ const settle = React__namespace.useCallback((next) => {
94
+ window.clearTimeout(timerRef.current);
95
+ setStatus(next);
96
+ timerRef.current = window.setTimeout(() => setStatus('idle'), resetAfter);
97
+ }, [resetAfter]);
98
+ const copy = React__namespace.useCallback(async (value) => {
99
+ try {
100
+ await writeText(typeof value === 'function' ? await value() : value);
101
+ settle('copied');
102
+ return true;
103
+ }
104
+ catch {
105
+ settle('failed');
106
+ return false;
107
+ }
108
+ }, [settle]);
109
+ // ----
110
+ // Hook Return
111
+ // ----
112
+ return { status, copy };
113
+ }
114
+
115
+ exports.useClipboard = useClipboard;
116
+ //# sourceMappingURL=useClipboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useClipboard.js","sources":["../../../src/hooks/useClipboard.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
+ var n = Object.create(null);
7
+ if (e) {
8
+ Object.keys(e).forEach(function (k) {
9
+ if (k !== 'default') {
10
+ var d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: function () { return e[k]; }
14
+ });
15
+ }
16
+ });
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+
22
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
23
+
24
+ /* --------
25
+ * Hook Definition
26
+ * -------- */
27
+ /**
28
+ * The timing every wait shares, in two values: the block comes at once, the look after 300ms, and
29
+ * once shown it stays at least 400ms.
30
+ *
31
+ * ```tsx
32
+ * const wait = useDelayedBusy(query.isFetching);
33
+ *
34
+ * <div aria-busy={wait.busy}>
35
+ * {wait.visible && <LoadingBar />}
36
+ * </div>
37
+ * ```
38
+ *
39
+ * Data that arrives is shown at once and replaces a skeleton: the minimum holds only the indicator
40
+ * (a bar, a veil, a spinner), which is what `visible` drives.
41
+ */
42
+ function useDelayedBusy(busy, options = {}) {
43
+ // ----
44
+ // Options Deconstruct
45
+ // ----
46
+ const { delay = 300, minDuration = 400 } = options;
47
+ // ----
48
+ // Internal State
49
+ // ----
50
+ const [visible, setVisible] = React__namespace.useState(false);
51
+ const shownAtRef = React__namespace.useRef(0);
52
+ // ----
53
+ // Lifecycle Events
54
+ // ----
55
+ React__namespace.useEffect(() => {
56
+ if (busy) {
57
+ if (visible) {
58
+ return undefined;
59
+ }
60
+ const timer = window.setTimeout(() => {
61
+ shownAtRef.current = Date.now();
62
+ setVisible(true);
63
+ }, delay);
64
+ return () => window.clearTimeout(timer);
65
+ }
66
+ if (!visible) {
67
+ return undefined;
68
+ }
69
+ const left = Math.max(0, minDuration - (Date.now() - shownAtRef.current));
70
+ const timer = window.setTimeout(() => setVisible(false), left);
71
+ return () => window.clearTimeout(timer);
72
+ }, [busy, visible, delay, minDuration]);
73
+ // ----
74
+ // Hook Return
75
+ // ----
76
+ return { busy, visible };
77
+ }
78
+
79
+ exports.useDelayedBusy = useDelayedBusy;
80
+ //# sourceMappingURL=useDelayedBusy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDelayedBusy.js","sources":["../../../src/hooks/useDelayedBusy.ts"],"sourcesContent":[null],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA0BA;;AAEc;AAEd;;;;;;;;;;;;;;AAcG;SACa,cAAc,CAAC,IAAa,EAAE,UAA8B,EAAE,EAAA;;;;IAK5E,MAAM,EAAE,KAAK,GAAG,GAAG,EAAE,WAAW,GAAG,GAAG,EAAE,GAAG,OAAO;;;;AAMlD,IAAA,MAAM,CAAE,OAAO,EAAE,UAAU,CAAE,GAAGA,gBAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;IACrD,MAAM,UAAU,GAAGA,gBAAK,CAAC,MAAM,CAAC,CAAC,CAAC;;;;AAMlC,IAAAA,gBAAK,CAAC,SAAS,CAAC,MAAK;QACnB,IAAI,IAAI,EAAE;YACR,IAAI,OAAO,EAAE;AACX,gBAAA,OAAO,SAAS;YAClB;AAEA,YAAA,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,MAAK;AACnC,gBAAA,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE;gBAC/B,UAAU,CAAC,IAAI,CAAC;YAClB,CAAC,EAAE,KAAK,CAAC;YAET,OAAO,MAAM,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC;QACzC;QAEA,IAAI,CAAC,OAAO,EAAE;AACZ,YAAA,OAAO,SAAS;QAClB;QAEA,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;AACzE,QAAA,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,UAAU,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC;QAE9D,OAAO,MAAM,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC;IACzC,CAAC,EAAE,CAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,CAAE,CAAC;;;;AAMzC,IAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE;AAE1B;;;;"}
@@ -40,7 +40,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
40
40
  * @example
41
41
  * const Input = React.forwardRef<HTMLInputElement, Props>((props, ref) => {
42
42
  * const innerRef = React.useRef<HTMLInputElement>(null);
43
- * const handleRef = useForkRef(innerRef, ref as MutableRefLike<HTMLInputElement>);
43
+ * const handleRef = useForkRef(innerRef, ref);
44
44
  *
45
45
  * return <input {...props} ref={handleRef} />;
46
46
  * });
@@ -48,7 +48,12 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
48
48
  function useForkRef(...refs) {
49
49
  return React__namespace.useCallback((refValue) => {
50
50
  refs.forEach((ref) => {
51
- ref.current = refValue ?? undefined;
51
+ if (typeof ref === 'function') {
52
+ ref(refValue);
53
+ }
54
+ else if (ref) {
55
+ ref.current = refValue;
56
+ }
52
57
  });
53
58
  },
54
59
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"useForkRef.js","sources":["../../../src/hooks/useForkRef.ts"],"sourcesContent":[null],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoBA;;AAEc;AAEd;;;;;;;;;;;;;;;;;;;;AAoBG;AACG,SAAU,UAAU,CAAI,GAAG,IAAyB,EAAA;AACxD,IAAA,OAAOA,gBAAK,CAAC,WAAW,CACtB,CAAC,QAAkB,KAAI;AACrB,QAAA,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;AACnB,YAAA,GAAG,CAAC,OAAO,GAAG,QAAQ,IAAI,SAAS;AACrC,QAAA,CAAC,CAAC;IACJ,CAAC;AACD;;;;;;;;;;;AAWG;;AAEH,IAAA,CAAE,GAAG,IAAI,CAAE,CACZ;AACH;;;;"}
1
+ {"version":3,"file":"useForkRef.js","sources":["../../../src/hooks/useForkRef.ts"],"sourcesContent":[null],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA2BA;;AAEc;AAEd;;;;;;;;;;;;;;;;;;;;AAoBG;AACG,SAAU,UAAU,CAAI,GAAG,IAAsB,EAAA;AACrD,IAAA,OAAOA,gBAAK,CAAC,WAAW,CACtB,CAAC,QAAkB,KAAI;AACrB,QAAA,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;AACnB,YAAA,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;gBAC7B,GAAG,CAAC,QAAQ,CAAC;YACf;iBACK,IAAI,GAAG,EAAE;AACZ,gBAAA,GAAG,CAAC,OAAO,GAAG,QAAQ;YACxB;AACF,QAAA,CAAC,CAAC;IACJ,CAAC;AACD;;;;;;;;;;;AAWG;;AAEH,IAAA,CAAE,GAAG,IAAI,CAAE,CACZ;AACH;;;;"}
@@ -0,0 +1,69 @@
1
+ 'use client';'use strict';
2
+
3
+ var React = require('react');
4
+
5
+ function _interopNamespaceDefault(e) {
6
+ var n = Object.create(null);
7
+ if (e) {
8
+ Object.keys(e).forEach(function (k) {
9
+ if (k !== 'default') {
10
+ var d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: function () { return e[k]; }
14
+ });
15
+ }
16
+ });
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+
22
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
23
+
24
+ /* --------
25
+ * Hook Definition
26
+ * -------- */
27
+ /**
28
+ * Whether a media query matches, kept in sync with the browser.
29
+ *
30
+ * The primitive `usePrefersReducedMotion` is built on, here, and `useBreakpoint` / `useIsMobile` in
31
+ * `@proedis/ui`, which add the vocabulary of the Tailwind breakpoints on top. Exported because a named
32
+ * breakpoint is not the only question worth asking: `(prefers-reduced-motion: reduce)`,
33
+ * `(prefers-contrast: more)`, `print`, `(orientation: landscape)`, `(hover: hover)` and a width outside
34
+ * the theme's scale all end here.
35
+ *
36
+ * ```tsx
37
+ * const isLandscape = useMediaQuery('(orientation: landscape)');
38
+ * const canHover = useMediaQuery('(hover: hover)');
39
+ * ```
40
+ *
41
+ * `useSyncExternalStore` rather than an effect with a `setState`: it takes a server snapshot as an
42
+ * argument, which is what turns a hydration-safe read into one line instead of the mounted-guard
43
+ * dance. The same snapshot is used while **hydrating** what the server rendered, so it has to be the
44
+ * answer that is safe to be wrong about for one frame; a tree rendered on the client only reads the
45
+ * real value from its first render.
46
+ *
47
+ * @param query - Any CSS media query, as `window.matchMedia` accepts it.
48
+ * @param serverSnapshot - What to answer with no `window` and while hydrating. Defaults
49
+ * to `false`, i.e. "does not match".
50
+ */
51
+ function useMediaQuery(query, serverSnapshot = false) {
52
+ // ----
53
+ // Handlers
54
+ // ----
55
+ const subscribe = React__namespace.useCallback((onStoreChange) => {
56
+ const list = window.matchMedia(query);
57
+ list.addEventListener('change', onStoreChange);
58
+ return () => list.removeEventListener('change', onStoreChange);
59
+ }, [query]);
60
+ const getSnapshot = React__namespace.useCallback(() => window.matchMedia(query).matches, [query]);
61
+ const getServerSnapshot = React__namespace.useCallback(() => serverSnapshot, [serverSnapshot]);
62
+ // ----
63
+ // Hook Return
64
+ // ----
65
+ return React__namespace.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
66
+ }
67
+
68
+ exports.useMediaQuery = useMediaQuery;
69
+ //# sourceMappingURL=useMediaQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMediaQuery.js","sources":["../../../src/hooks/useMediaQuery.ts"],"sourcesContent":[null],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAKA;;AAEc;AAEd;;;;;;;;;;;;;;;;;;;;;;;AAuBG;SACa,aAAa,CAAC,KAAa,EAAE,iBAA0B,KAAK,EAAA;;;;IAK1E,MAAM,SAAS,GAAGA,gBAAK,CAAC,WAAW,CACjC,CAAC,aAAyB,KAAI;QAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC;AAErC,QAAA,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,aAAa,CAAC;QAE9C,OAAO,MAAM,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,aAAa,CAAC;AAChE,IAAA,CAAC,EACD,CAAE,KAAK,CAAE,CACV;IAED,MAAM,WAAW,GAAGA,gBAAK,CAAC,WAAW,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAE,KAAK,CAAE,CAAC;AAExF,IAAA,MAAM,iBAAiB,GAAGA,gBAAK,CAAC,WAAW,CAAC,MAAM,cAAc,EAAE,CAAE,cAAc,CAAE,CAAC;;;;IAMrF,OAAOA,gBAAK,CAAC,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,iBAAiB,CAAC;AAE9E;;;;"}
@@ -0,0 +1,129 @@
1
+ 'use client';'use strict';
2
+
3
+ var React = require('react');
4
+
5
+ function _interopNamespaceDefault(e) {
6
+ var n = Object.create(null);
7
+ if (e) {
8
+ Object.keys(e).forEach(function (k) {
9
+ if (k !== 'default') {
10
+ var d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: function () { return e[k]; }
14
+ });
15
+ }
16
+ });
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+
22
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
23
+
24
+ /* --------
25
+ * Helpers
26
+ * -------- */
27
+ /** Which items fit, as a pure function of the measures: no frame where the pinned item is missing */
28
+ function fitItems(widths, available, options) {
29
+ const { gap, pinned, reserve } = options;
30
+ const all = widths.map((_, index) => index);
31
+ const total = widths.reduce((sum, width) => sum + width, 0) + gap * Math.max(0, widths.length - 1);
32
+ if (widths.length === 0 || total <= available) {
33
+ return { visible: all, overflow: [] };
34
+ }
35
+ const room = available - reserve;
36
+ const visible = [];
37
+ let used = 0;
38
+ for (const index of all) {
39
+ const width = widths[index] + (visible.length > 0 ? gap : 0);
40
+ if (used + width > room) {
41
+ break;
42
+ }
43
+ visible.push(index);
44
+ used += width;
45
+ }
46
+ if (pinned !== undefined && pinned >= 0 && pinned < widths.length && !visible.includes(pinned)) {
47
+ const pinnedWidth = () => widths[pinned] + (visible.length > 0 ? gap : 0);
48
+ while (visible.length > 0 && used + pinnedWidth() > room) {
49
+ const last = visible.pop();
50
+ used -= widths[last] + (visible.length > 0 ? gap : 0);
51
+ }
52
+ visible.push(pinned);
53
+ }
54
+ return { visible, overflow: all.filter((index) => !visible.includes(index)) };
55
+ }
56
+ /* --------
57
+ * Hook Definition
58
+ * -------- */
59
+ /**
60
+ * Which items of a row fit, and which go into a "More" menu: the tabs of a detail, the tabs of a
61
+ * header. The widths come from a hidden copy of the row (`measureRef`, `aria-hidden` and `inert`),
62
+ * one child per item, so measuring never moves what the user sees.
63
+ *
64
+ * ```tsx
65
+ * const { visible, overflow } = useOverflowItems(rowRef, copyRef, { count: tabs.length, pinned: active });
66
+ * ```
67
+ *
68
+ * It measures again when the row or the copy changes size, so a count that arrives late is taken in.
69
+ */
70
+ function useOverflowItems(containerRef, measureRef, options) {
71
+ // ----
72
+ // Options Deconstruct
73
+ // ----
74
+ const { available: readAvailable, count, gap, pinned, reserve } = options;
75
+ // ----
76
+ // Internal State
77
+ // ----
78
+ const [measures, setMeasures] = React__namespace.useState(null);
79
+ const readRef = React__namespace.useRef(readAvailable);
80
+ React__namespace.useEffect(() => {
81
+ readRef.current = readAvailable;
82
+ });
83
+ // ----
84
+ // Lifecycle Events
85
+ // ----
86
+ React__namespace.useEffect(() => {
87
+ const container = containerRef.current;
88
+ const copy = measureRef.current;
89
+ if (!container || !copy) {
90
+ return undefined;
91
+ }
92
+ const measure = () => {
93
+ const available = readRef.current ? readRef.current(container) : container.clientWidth;
94
+ const children = Array.from(copy.children);
95
+ const reserveElement = children.find((child) => child.hasAttribute('data-overflow-reserve'));
96
+ const widths = children.filter((child) => child !== reserveElement).map((child) => child.getBoundingClientRect().width);
97
+ const measuredReserve = reserveElement ? reserveElement.getBoundingClientRect().width : 0;
98
+ const measuredGap = Number.parseFloat(getComputedStyle(copy).columnGap) || 0;
99
+ setMeasures((previous) => (previous
100
+ && previous.available === available
101
+ && previous.reserve === measuredReserve
102
+ && previous.gap === measuredGap
103
+ && previous.widths.length === widths.length
104
+ && previous.widths.every((width, index) => width === widths[index])
105
+ ? previous
106
+ : { available, widths, reserve: measuredReserve, gap: measuredGap }));
107
+ };
108
+ const observer = new ResizeObserver(measure);
109
+ observer.observe(container);
110
+ observer.observe(copy);
111
+ measure();
112
+ return () => observer.disconnect();
113
+ }, [containerRef, measureRef]);
114
+ // ----
115
+ // Hook Return
116
+ // ----
117
+ if (!measures || measures.widths.length !== count) {
118
+ return { visible: Array.from({ length: count }, (_, index) => index), overflow: [] };
119
+ }
120
+ return fitItems(measures.widths, measures.available, {
121
+ gap: gap ?? measures.gap,
122
+ pinned,
123
+ reserve: reserve ?? measures.reserve
124
+ });
125
+ }
126
+
127
+ exports.fitItems = fitItems;
128
+ exports.useOverflowItems = useOverflowItems;
129
+ //# sourceMappingURL=useOverflowItems.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOverflowItems.js","sources":["../../../src/hooks/useOverflowItems.ts"],"sourcesContent":[null],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgDA;;AAEc;AAEd;SACgB,QAAQ,CACtB,MAAyB,EACzB,SAAiB,EACjB,OAA0D,EAAA;IAE1D,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO;AACxC,IAAA,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,KAAK,CAAC;AAC3C,IAAA,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC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AAM,KAAK,KAAK,EAAE;QACjD,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,KAAK,KAAK,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IACtF;IAEA,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,EAAE;AACnD,QAAA,GAAG,EAAM,GAAG,IAAI,QAAQ,CAAC,GAAG;QAC5B,MAAM;AACN,QAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,CAAC;AAC9B,KAAA,CAAC;AAEJ;;;;;"}
@@ -0,0 +1,34 @@
1
+ 'use client';'use strict';
2
+
3
+ var useMediaQuery = require('./useMediaQuery.js');
4
+
5
+ /* --------
6
+ * Constants Definition
7
+ * -------- */
8
+ const QUERY = '(prefers-reduced-motion: reduce)';
9
+ /* --------
10
+ * Hook Definition
11
+ * -------- */
12
+ /**
13
+ * Whether the user asked the system to reduce motion.
14
+ *
15
+ * For animation driven from JavaScript — a spring, a scroll interpolation, an autoplaying carousel.
16
+ * A transition written in CSS does **not** need this: `@media (prefers-reduced-motion: reduce)`
17
+ * answers the same question where the animation lives, without shipping a hook to the client.
18
+ *
19
+ * ```tsx
20
+ * const still = usePrefersReducedMotion();
21
+ * <motion.div animate={still ? {} : { y: 0 }} />
22
+ * ```
23
+ *
24
+ * ⚠️ It answers **`true`** with no `window` and on the first client render, unlike the other media
25
+ * query hooks, and the asymmetry is on purpose: the two possible mistakes are not equivalent. Guessing
26
+ * "reduce" and correcting to "animate" costs one frame of stillness; guessing the other way plays
27
+ * the animation this preference exists to prevent, to the person who asked for it not to.
28
+ */
29
+ function usePrefersReducedMotion() {
30
+ return useMediaQuery.useMediaQuery(QUERY, true);
31
+ }
32
+
33
+ exports.usePrefersReducedMotion = usePrefersReducedMotion;
34
+ //# sourceMappingURL=usePrefersReducedMotion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePrefersReducedMotion.js","sources":["../../../src/hooks/usePrefersReducedMotion.ts"],"sourcesContent":[null],"names":["useMediaQuery"],"mappings":";;;;AAKA;;AAEc;AACd,MAAM,KAAK,GAAG,kCAAkC;AAGhD;;AAEc;AAEd;;;;;;;;;;;;;;;;AAgBG;SACa,uBAAuB,GAAA;AACrC,IAAA,OAAOA,2BAAa,CAAC,KAAK,EAAE,IAAI,CAAC;AACnC;;;;"}