@proedis/react 1.6.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +238 -0
- package/cjs/components/RenderWhen/RenderWhen.js +1 -1
- package/cjs/components/RenderWhen/RenderWhen.js.map +1 -1
- package/cjs/hooks/useAutoControlledState.js.map +1 -1
- package/cjs/hooks/useAutoSizer.js +246 -0
- package/cjs/hooks/useAutoSizer.js.map +1 -0
- package/cjs/hooks/useClickOutside.js +7 -0
- package/cjs/hooks/useClickOutside.js.map +1 -1
- package/cjs/hooks/useDataManager.js.map +1 -1
- package/cjs/hooks/useDataSelector.js +53 -19
- package/cjs/hooks/useDataSelector.js.map +1 -1
- package/cjs/hooks/useDebouncedCallback.js.map +1 -1
- package/cjs/hooks/useElementType.js.map +1 -1
- package/cjs/hooks/useEnhancedEffect.js.map +1 -1
- package/cjs/hooks/useEvent.js.map +1 -1
- package/cjs/hooks/useForkRef.js +37 -9
- package/cjs/hooks/useForkRef.js.map +1 -1
- package/cjs/hooks/useInputValue.js.map +1 -1
- package/cjs/hooks/useObjectState.js.map +1 -1
- package/cjs/hooks/useSafeState.js.map +1 -1
- package/cjs/hooks/useSyncedRef.js +37 -5
- package/cjs/hooks/useSyncedRef.js.map +1 -1
- package/cjs/hooks/useUnmountEffect.js.map +1 -1
- package/cjs/hooks/useWindowSize.js.map +1 -1
- package/cjs/index.js +3 -0
- package/cjs/index.js.map +1 -1
- package/cjs/package.json +3 -0
- package/cjs/utils/compose.js.map +1 -1
- package/cjs/utils/contextBuilder.js.map +1 -1
- package/cjs/utils/shorthands.js +5 -6
- package/cjs/utils/shorthands.js.map +1 -1
- package/esm/components/RenderWhen/RenderWhen.js +1 -1
- package/esm/components/RenderWhen/RenderWhen.js.map +1 -1
- package/esm/hooks/useAutoControlledState.js.map +1 -1
- package/esm/hooks/useAutoSizer.js +224 -0
- package/esm/hooks/useAutoSizer.js.map +1 -0
- package/esm/hooks/useClickOutside.js +7 -0
- package/esm/hooks/useClickOutside.js.map +1 -1
- package/esm/hooks/useDataManager.js.map +1 -1
- package/esm/hooks/useDataSelector.js +53 -19
- package/esm/hooks/useDataSelector.js.map +1 -1
- package/esm/hooks/useDebouncedCallback.js.map +1 -1
- package/esm/hooks/useElementType.js.map +1 -1
- package/esm/hooks/useEnhancedEffect.js.map +1 -1
- package/esm/hooks/useEvent.js.map +1 -1
- package/esm/hooks/useForkRef.js +37 -9
- package/esm/hooks/useForkRef.js.map +1 -1
- package/esm/hooks/useInputValue.js.map +1 -1
- package/esm/hooks/useObjectState.js.map +1 -1
- package/esm/hooks/useSafeState.js.map +1 -1
- package/esm/hooks/useSyncedRef.js +37 -5
- package/esm/hooks/useSyncedRef.js.map +1 -1
- package/esm/hooks/useUnmountEffect.js.map +1 -1
- package/esm/hooks/useWindowSize.js.map +1 -1
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/package.json +3 -0
- package/esm/utils/compose.js.map +1 -1
- package/esm/utils/contextBuilder.js.map +1 -1
- package/esm/utils/shorthands.js +5 -6
- package/esm/utils/shorthands.js.map +1 -1
- package/package.json +13 -3
- package/types/hooks/index.d.ts +1 -0
- package/types/hooks/useAutoSizer.d.ts +82 -0
- package/types/hooks/useClickOutside.d.ts +10 -2
- package/types/hooks/useForkRef.d.ts +31 -4
- package/types/hooks/useSyncedRef.d.ts +36 -5
- package/tsconfig.declaration.tsbuildinfo +0 -1
|
@@ -15,7 +15,7 @@ function useDataSelector(data, options) {
|
|
|
15
15
|
// ----
|
|
16
16
|
// Internal State
|
|
17
17
|
// ----
|
|
18
|
-
const [
|
|
18
|
+
const [requestedSelection, setRequestedSelection] = React.useState(options?.defaultSelected);
|
|
19
19
|
// ----
|
|
20
20
|
// Internal Hooks
|
|
21
21
|
// ----
|
|
@@ -40,34 +40,68 @@ function useDataSelector(data, options) {
|
|
|
40
40
|
return selectableData.includes(item) ? item : undefined;
|
|
41
41
|
}, [data, userDefinedComparer]);
|
|
42
42
|
const setSelected = React.useCallback((item) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const { current: currentUserDefinedOnSelectChange } = userDefinedOnSelectChange;
|
|
46
|
-
if (typeof currentUserDefinedOnSelectChange === 'function') {
|
|
47
|
-
currentUserDefinedOnSelectChange(sourceItem);
|
|
48
|
-
}
|
|
49
|
-
}, [getSourceItem, userDefinedOnSelectChange]);
|
|
43
|
+
setRequestedSelection(item);
|
|
44
|
+
}, []);
|
|
50
45
|
const clearSelected = React.useCallback(() => setSelected(undefined), [setSelected]);
|
|
51
46
|
const createSelectorHandler = React.useCallback((item) => () => setSelected(item), [setSelected]);
|
|
52
47
|
// ----
|
|
53
48
|
// Selected Assertion
|
|
54
49
|
// ----
|
|
50
|
+
/**
|
|
51
|
+
* Resolve the requested selection against the data as it is *now*, while rendering.
|
|
52
|
+
*
|
|
53
|
+
* 'getSourceItem' already answers every case the reconciliation has to cover: it returns the matching
|
|
54
|
+
* source item, or 'undefined' when the requested one is not in the data any more — and 'undefined' in,
|
|
55
|
+
* 'undefined' out. So the whole thing is one derivation.
|
|
56
|
+
*
|
|
57
|
+
* It used to be an effect that called setState, which meant every data change that invalidated the
|
|
58
|
+
* selection rendered twice: once with the stale selection, once with the corrected one. Deriving it
|
|
59
|
+
* here means a render never shows a selection the data does not back.
|
|
60
|
+
*/
|
|
61
|
+
const selected = getSourceItem(requestedSelection);
|
|
62
|
+
// ----
|
|
63
|
+
// Selection Change Notification
|
|
64
|
+
// ----
|
|
65
|
+
/**
|
|
66
|
+
* Notify the consumer once per actual change, from a single place.
|
|
67
|
+
*
|
|
68
|
+
* There used to be two sources for this callback — a synchronous call inside the setter and the
|
|
69
|
+
* reconciliation effect calling that same setter — and between them they reported things that were not
|
|
70
|
+
* changes: selecting what was already selected notified, clearing an already empty selection notified
|
|
71
|
+
* twice, and resolving `defaultSelected` against the data notified at mount. Watching the resolved
|
|
72
|
+
* value reports each transition exactly once, after the commit that made it real.
|
|
73
|
+
*/
|
|
74
|
+
const lastNotifiedSelection = React.useRef(selected);
|
|
55
75
|
React.useEffect(() => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/** If selected exists, but source item not, remove selection */
|
|
59
|
-
if (selected && !sourceItem) {
|
|
60
|
-
setSelected(undefined);
|
|
76
|
+
if (lastNotifiedSelection.current === selected) {
|
|
77
|
+
return;
|
|
61
78
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
79
|
+
lastNotifiedSelection.current = selected;
|
|
80
|
+
const { current: currentUserDefinedOnSelectChange } = userDefinedOnSelectChange;
|
|
81
|
+
if (typeof currentUserDefinedOnSelectChange === 'function') {
|
|
82
|
+
currentUserDefinedOnSelectChange(selected);
|
|
65
83
|
}
|
|
66
|
-
}, [
|
|
84
|
+
}, [selected, userDefinedOnSelectChange]);
|
|
67
85
|
// ----
|
|
68
|
-
//
|
|
86
|
+
// Unmount Notification
|
|
69
87
|
// ----
|
|
70
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Report the selection as gone when the component unmounts.
|
|
90
|
+
*
|
|
91
|
+
* This was `useUnmountEffect(clearSelected)`, and it notified only as a side effect of how the
|
|
92
|
+
* callback used to be wired: `clearSelected` went through the setter, and the setter notified
|
|
93
|
+
* synchronously. Now that notifying belongs to an effect — and effects do not run on the way out —
|
|
94
|
+
* that call became inert, which dropped a notification every consumer had always received.
|
|
95
|
+
*
|
|
96
|
+
* It fires unconditionally, which is what the old path did: it resolved `undefined` through
|
|
97
|
+
* `getSourceItem` and reported it even when nothing was selected to begin with.
|
|
98
|
+
*/
|
|
99
|
+
useUnmountEffect(() => {
|
|
100
|
+
const { current: currentUserDefinedOnSelectChange } = userDefinedOnSelectChange;
|
|
101
|
+
if (typeof currentUserDefinedOnSelectChange === 'function') {
|
|
102
|
+
currentUserDefinedOnSelectChange(undefined);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
71
105
|
// ----
|
|
72
106
|
// Return utilities
|
|
73
107
|
// ----
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataSelector.js","sources":["../../../src/hooks/useDataSelector.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAmCA;;AAEc;AAEd;;;;;AAKG;
|
|
1
|
+
{"version":3,"file":"useDataSelector.js","sources":["../../../src/hooks/useDataSelector.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAmCA;;AAEc;AAEd;;;;;AAKG;AACG,SAAU,eAAe,CAC7B,IAA4B,EAC5B,OAAmC,EAAA;;;;AAMnC,IAAA,MAAM,CAAE,kBAAkB,EAAE,qBAAqB,CAAE,GAAG,KAAK,CAAC,QAAQ,CAAgB,OAAO,EAAE,eAAe,CAAC;;;;IAM7G,MAAM,yBAAyB,GAAG,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC;IACzE,MAAM,mBAAmB,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC;;;;IAM3D,MAAM,aAAa,GAAG,KAAK,CAAC,WAAW,CACrC,CAAC,IAAmB,KAAmB;;AAErC,QAAA,IAAI,IAAI,KAAK,SAAS,EAAE;AACtB,YAAA,OAAO,SAAS;QAClB;;AAGA,QAAA,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,EAAE;;AAGtD,QAAA,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,mBAAmB;AACxD,QAAA,IAAI,OAAO,eAAe,KAAK,UAAU,EAAE;AACzC,YAAA,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACrE;;AAGA,QAAA,OAAO,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS;AACzD,IAAA,CAAC,EACD,CAAE,IAAI,EAAE,mBAAmB,CAAE,CAC9B;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CACnC,CAAC,IAAmB,KAAI;QACtB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AK,MAAM,CAAC,EAAE,CACvB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDebouncedCallback.js","sources":["../../../src/hooks/useDebouncedCallback.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAcA;;;;;;;;;AASG;SACa,oBAAoB,CAClC,QAAY,EACZ,IAA0B,EAC1B,QAAgB,EAAA;;IAIhB,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAA4C,SAAS,CAAC
|
|
1
|
+
{"version":3,"file":"useDebouncedCallback.js","sources":["../../../src/hooks/useDebouncedCallback.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAcA;;;;;;;;;AASG;SACa,oBAAoB,CAClC,QAAY,EACZ,IAA0B,EAC1B,QAAgB,EAAA;;IAIhB,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAA4C,SAAS,CAAC;AAClF,IAAA,MAAM,gBAAgB,GAAG,YAAY,CAAC,QAAQ,CAAC;;AAG/C,IAAA,MAAM,eAAe,GAAG,KAAK,CAAC,WAAW,CACvC,MAAK;AACH,QAAA,IAAI,OAAO,CAAC,OAAO,EAAE;AACnB,YAAA,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC;AAC7B,YAAA,OAAO,CAAC,OAAO,GAAG,SAAS;QAC7B;IACF,CAAC,EACD,EAAE,CACH;;IAGD,gBAAgB,CAAC,MAAK;AACpB,QAAA,eAAe,EAAE;AACnB,IAAA,CAAC,CAAC;;IAGF,OAAO,KAAK,CAAC,WAAW,CACtB,CAAC,GAAG,IAAI,KAAI;;AAEV,QAAA,eAAe,EAAE;;AAGjB,QAAA,OAAO,CAAC,OAAO,GAAG,UAAU,CAAC,MAAK;AAChC,YAAA,gBAAgB,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;QACnC,CAAC,EAAE,QAAQ,CAAC;IACd,CAAC,EACD,CAAE,eAAe,EAAE,QAAQ,EAAE,gBAAgB,CAAE,CAChD;AAEH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useElementType.js","sources":["../../../src/hooks/useElementType.ts"],"sourcesContent":[null],"names":[],"mappings":"AAiCA;;AAEc;AAEd;;;;;;;AAOG;AACG,SAAU,cAAc,CAC5B,SAAmE,EACnE,KAAY,EACZ,kBAAsC,EACtC,UAAkC,EAAA;;AAIlC,IAAA,MAAM,EAAE,YAAY,EAAE,qBAAqB,EAAE,GAAG,SAAgB
|
|
1
|
+
{"version":3,"file":"useElementType.js","sources":["../../../src/hooks/useElementType.ts"],"sourcesContent":[null],"names":[],"mappings":"AAiCA;;AAEc;AAEd;;;;;;;AAOG;AACG,SAAU,cAAc,CAC5B,SAAmE,EACnE,KAAY,EACZ,kBAAsC,EACtC,UAAkC,EAAA;;AAIlC,IAAA,MAAM,EAAE,YAAY,EAAE,qBAAqB,EAAE,GAAG,SAAgB;;AAGhE,IAAA,IAAI,KAAK,CAAC,EAAE,IAAI,KAAK,CAAC,EAAE,KAAK,qBAAqB,EAAE,EAAE,EAAE;QACtD,OAAO,KAAK,CAAC,EAAE;IACjB;;AAGA,IAAA,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE;AACpC,QAAA,MAAM,mBAAmB,GAAG,UAAU,CAAC,KAAK,CAAC;QAE7C,IAAI,mBAAmB,EAAE;AACvB,YAAA,OAAO,mBAAmB;QAC5B;IACF;;AAGA,IAAA,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;AAClC,QAAA,OAAO,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,UAAU,CAAC,OAAO;IACtE;;AAGA,IAAA,IAAI,KAAK,CAAC,IAAI,EAAE;AACd,QAAA,OAAO,GAAG;IACZ;;AAGA,IAAA,OAAO,qBAAqB,EAAE,EAAE,IAAI,kBAAkB,IAAI,KAAK;AACjE;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEnhancedEffect.js","sources":["../../../src/hooks/useEnhancedEffect.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAKA;;;;;AAKG;AACI,MAAM,iBAAiB,GAAG
|
|
1
|
+
{"version":3,"file":"useEnhancedEffect.js","sources":["../../../src/hooks/useEnhancedEffect.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAKA;;;;;AAKG;AACI,MAAM,iBAAiB,GAAG;MAC7B,KAAK,CAAC;AACR,MAAE,KAAK,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEvent.js","sources":["../../../src/hooks/useEvent.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAkBA;;;;;;AAMG;SACa,QAAQ,CACtB,IAAO,EACP,QAA0B,EAC1B,OAAyB,EAAA;;AAIzB,IAAA,MAAM,EACJ,QAAQ,GAAG,KAAK,EAChB,MAAM,GAAG,QAAQ,CAAC,eAAe,EAClC,GAAG,OAAO,IAAI,EAAE
|
|
1
|
+
{"version":3,"file":"useEvent.js","sources":["../../../src/hooks/useEvent.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAkBA;;;;;;AAMG;SACa,QAAQ,CACtB,IAAO,EACP,QAA0B,EAC1B,OAAyB,EAAA;;AAIzB,IAAA,MAAM,EACJ,QAAQ,GAAG,KAAK,EAChB,MAAM,GAAG,QAAQ,CAAC,eAAe,EAClC,GAAG,OAAO,IAAI,EAAE;AAGjB;;;;;;AAMG;AACH,IAAA,MAAM,OAAO,GAAG,YAAY,CAAmB,QAAQ,CAAC;IAGxD,iBAAiB,CACf,MAAK;;QAEH,IAAI,QAAQ,EAAE;YACZ;QACF;AAEA;;;;;AAKG;QACH,MAAM,aAAa,GAAqB,CAAC,KAAK,MAC5C,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAE,KAAK,CAAE,CAAC,CACzC;;AAGD,QAAA,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,aAAa,CAAC;;AAG5C,QAAA,OAAO,MAAK;AACV,YAAA,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,aAAa,CAAC;AACjD,QAAA,CAAC;IACH,CAAC,EACD,CAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAE,CACpC;AAEH;;;;"}
|
package/esm/hooks/useForkRef.js
CHANGED
|
@@ -1,20 +1,48 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
|
+
/* --------
|
|
4
|
+
* Hook Definition
|
|
5
|
+
* -------- */
|
|
3
6
|
/**
|
|
4
|
-
*
|
|
5
|
-
* assign the referenced element to each single ref.
|
|
7
|
+
* Merge several refs into the single ref callback a JSX element can accept.
|
|
6
8
|
*
|
|
7
|
-
*
|
|
9
|
+
* The returned callback assigns the element to every ref it was given, which is how a component both
|
|
10
|
+
* exposes a ref to its parent and keeps one for itself.
|
|
11
|
+
*
|
|
12
|
+
* Its identity is **stable** as long as the same ref containers are passed, which matters beyond
|
|
13
|
+
* tidiness: React calls a ref callback with `null` and then with the node again every time the
|
|
14
|
+
* callback's identity changes.
|
|
15
|
+
*
|
|
16
|
+
* @param refs The refs to assign to
|
|
17
|
+
* @returns A ref callback, stable across renders that pass the same refs
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const Input = React.forwardRef<HTMLInputElement, Props>((props, ref) => {
|
|
21
|
+
* const innerRef = React.useRef<HTMLInputElement>(null);
|
|
22
|
+
* const handleRef = useForkRef(innerRef, ref as MutableRefLike<HTMLInputElement>);
|
|
23
|
+
*
|
|
24
|
+
* return <input {...props} ref={handleRef} />;
|
|
25
|
+
* });
|
|
8
26
|
*/
|
|
9
27
|
function useForkRef(...refs) {
|
|
10
28
|
return React.useCallback((refValue) => {
|
|
11
|
-
refs.forEach((ref) =>
|
|
29
|
+
refs.forEach((ref) => {
|
|
30
|
+
ref.current = refValue ?? undefined;
|
|
31
|
+
});
|
|
12
32
|
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
33
|
+
/**
|
|
34
|
+
* The rest parameter is a new array on every render, so the refs are spread into the dependency
|
|
35
|
+
* list one by one: ref containers are stable, so the callback survives every render that passes
|
|
36
|
+
* the same ones.
|
|
37
|
+
*
|
|
38
|
+
* Both hook rules object to this, and neither has a better answer here. 'exhaustive-deps' wants the
|
|
39
|
+
* array itself, which changes identity every render and would rebuild the callback each time.
|
|
40
|
+
* 'use-memo' wants a literal, which cannot express a variadic list. Routing the refs through a
|
|
41
|
+
* synced container satisfies both — and then the React Compiler refuses the memoization outright,
|
|
42
|
+
* because it cannot prove a closure reading 'ref.current' is stable. This is the shape the compiler
|
|
43
|
+
* is meant to replace: with it enabled, drop the useCallback entirely and let it do the work.
|
|
44
|
+
*/
|
|
45
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps, react-hooks/use-memo
|
|
18
46
|
[...refs]);
|
|
19
47
|
}
|
|
20
48
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForkRef.js","sources":["../../../src/hooks/useForkRef.ts"],"sourcesContent":[null],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"useForkRef.js","sources":["../../../src/hooks/useForkRef.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAoBA;;AAEc;AAEd;;;;;;;;;;;;;;;;;;;;AAoBG;AACG,SAAU,UAAU,CAAI,GAAG,IAAyB,EAAA;AACxD,IAAA,OAAO,KAAK,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInputValue.js","sources":["../../../src/hooks/useInputValue.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGM,SAAU,aAAa,CAAC,YAAqB,EAAA;;;;AASjD,IAAA,MAAM,CAAE,KAAK,EAAE,QAAQ,CAAE,GAAG,KAAK,CAAC,QAAQ,CAAS,YAAY,IAAI,EAAE,CAAC
|
|
1
|
+
{"version":3,"file":"useInputValue.js","sources":["../../../src/hooks/useInputValue.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGM,SAAU,aAAa,CAAC,YAAqB,EAAA;;;;AASjD,IAAA,MAAM,CAAE,KAAK,EAAE,QAAQ,CAAE,GAAG,KAAK,CAAC,QAAQ,CAAS,YAAY,IAAI,EAAE,CAAC;;;;IAMtE,MAAM,sBAAsB,GAAG,KAAK,CAAC,WAAW,CAC9C,CAAC,KAAK,KAAI;AACR,QAAA,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC;IACrC,CAAC,EACD,EAAE,CACH;;;;AAMD,IAAA,OAAO,CAAE,KAAK,EAAE,sBAAsB,EAAE,QAAQ,CAAE;AAEpD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObjectState.js","sources":["../../../src/hooks/useObjectState.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AA+BA;;;;;;AAMG;
|
|
1
|
+
{"version":3,"file":"useObjectState.js","sources":["../../../src/hooks/useObjectState.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AA+BA;;;;;;AAMG;AACG,SAAU,cAAc,CAC5B,aAAsC,EACtC,OAAuC,EAAA;;IAIvC,MAAM,CAAE,KAAK,EAAE,QAAQ,CAAE,GAAG,YAAY,CAAC,aAAa,CAAC;;IAGvD,MAAM,gBAAgB,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC;AACxD,IAAA,KAAK,CAAC,SAAS,CACb,MAAK;AACH,QAAA,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,gBAAgB;AAErD,QAAA,IAAI,OAAO,eAAe,KAAK,UAAU,EAAE;YACzC,eAAe,CAAC,KAAK,CAAC;QACxB;AACF,IAAA,CAAC,EACD,CAAE,gBAAgB,EAAE,KAAK,CAAE,CAC5B;;IAGD,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAChC,CAAC,SAAS,KAAI;AACZ,QAAA,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE;AACnC,YAAA,QAAQ,CAAC,CAAC,IAAI,MAAM;gBAClB,GAAG,SAAS,CAAC,IAAI;AAClB,aAAA,CAAC,CAAC;QACL;aACK;AACH,YAAA,QAAQ,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC;QAC5B;AACF,IAAA,CAAC,EACD,CAAE,QAAQ,CAAE,CACb;;IAGD,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAChC,CAAkC,IAAU,MAC1C,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CACxB,EACD,CAAE,KAAK,CAAE,CACV;;IAGD,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAChC,CAAkC,IAAU,EAAE,KAAoC,KAAI;QACpF,QAAQ,CAAC,CAAC,IAAI,MACZ,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CACnD,CAAC;AACJ,IAAA,CAAC,EACD,CAAE,QAAQ,CAAE,CACb;;IAGD,OAAO,CAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAE;AAEpD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSafeState.js","sources":["../../../src/hooks/useSafeState.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAKA;;;;;;AAMG;AACG,SAAU,YAAY,CAC1B,YAA2B,EAAA;;AAI3B,IAAA,MAAM,CAAE,KAAK,EAAE,QAAQ,CAAE,GAAG,KAAK,CAAC,QAAQ,CAAI,YAAY,CAAC
|
|
1
|
+
{"version":3,"file":"useSafeState.js","sources":["../../../src/hooks/useSafeState.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAKA;;;;;;AAMG;AACG,SAAU,YAAY,CAC1B,YAA2B,EAAA;;AAI3B,IAAA,MAAM,CAAE,KAAK,EAAE,QAAQ,CAAE,GAAG,KAAK,CAAC,QAAQ,CAAI,YAAY,CAAC;;IAG3D,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAU,KAAK,CAAC;;IAG9C,iBAAiB,CACf,MAAK;AACH,QAAA,SAAS,CAAC,OAAO,GAAG,IAAI;AAExB,QAAA,OAAO,MAAK;AACV,YAAA,SAAS,CAAC,OAAO,GAAG,KAAK;AAC3B,QAAA,CAAC;IACH,CAAC,EACD,EAAE,CACH;;IAGD,MAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CACtC,CAAC,QAAQ,KAAI;AACX,QAAA,IAAI,SAAS,CAAC,OAAO,EAAE;YACrB,QAAQ,CAAC,QAAQ,CAAC;QACpB;IACF,CAAC,EACD,EAAE,CACH;;AAGD,IAAA,OAAO,CAAE,KAAK,EAAE,cAAc,CAAE;AAElC;;;;"}
|
|
@@ -1,15 +1,47 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* It will return a 'ref' style object with the
|
|
6
|
-
* current key memoized, returning each time
|
|
7
|
-
* the most updated version of the value
|
|
4
|
+
* Keep the latest value passed to a component inside a stable, read only ref container.
|
|
8
5
|
*
|
|
9
|
-
*
|
|
6
|
+
* The container identity never changes, so it can sit in a dependency array without ever
|
|
7
|
+
* invalidating it — which is the whole point: it lets an event handler, a debounce timer or a
|
|
8
|
+
* cleanup function read the *current* value without the effect that owns them having to be torn
|
|
9
|
+
* down and rebuilt on every render.
|
|
10
|
+
*
|
|
11
|
+
* The returned object is frozen and exposes `current` as a getter, so a consumer can read the value
|
|
12
|
+
* but cannot write it.
|
|
13
|
+
*
|
|
14
|
+
* @param value The value to keep in sync
|
|
15
|
+
* @returns A stable container whose `current` always reads the latest value
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* function useAutoSave(onSave: () => void, delay: number) {
|
|
19
|
+
* const latestOnSave = useSyncedRef(onSave);
|
|
20
|
+
*
|
|
21
|
+
* React.useEffect(
|
|
22
|
+
* () => {
|
|
23
|
+
* // the interval is created once, and still calls the newest callback
|
|
24
|
+
* const id = setInterval(() => latestOnSave.current(), delay);
|
|
25
|
+
* return () => clearInterval(id);
|
|
26
|
+
* },
|
|
27
|
+
* [ delay, latestOnSave ]
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* ⚠️ Read `current` from an effect, an event handler or a cleanup function — **not while rendering**.
|
|
33
|
+
* The value is written during render, which is what makes it available to the very commit it belongs
|
|
34
|
+
* to, and reading a ref during render is not something React guarantees anything about: a render that
|
|
35
|
+
* gets discarded leaves the container holding a value that was never committed.
|
|
36
|
+
*
|
|
37
|
+
* That write is also why `react-hooks/refs` is switched off just below. Every alternative loses the
|
|
38
|
+
* guarantee this hook exists to provide — writing in an effect makes `current` lag one commit behind,
|
|
39
|
+
* which is precisely the bug the callers of this hook are avoiding. The exposure is bounded: the
|
|
40
|
+
* container is only ever read after a commit, and every commit writes it again.
|
|
10
41
|
*/
|
|
11
42
|
function useSyncedRef(value) {
|
|
12
43
|
const ref = React.useRef(value);
|
|
44
|
+
// eslint-disable-next-line react-hooks/refs -- see the remark above: the render time write is the contract
|
|
13
45
|
ref.current = value;
|
|
14
46
|
return React.useMemo(() => Object.freeze({
|
|
15
47
|
get current() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSyncedRef.js","sources":["../../../src/hooks/useSyncedRef.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA
|
|
1
|
+
{"version":3,"file":"useSyncedRef.js","sources":["../../../src/hooks/useSyncedRef.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCG;AACG,SAAU,YAAY,CAAI,KAAQ,EAAA;IACtC,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;;AAG/B,IAAA,GAAG,CAAC,OAAO,GAAG,KAAK;IAEnB,OAAO,KAAK,CAAC,OAAO,CAClB,MAAM,MAAM,CAAC,MAAM,CAAC;AAClB,QAAA,IAAI,OAAO,GAAA;YACT,OAAO,GAAG,CAAC,OAAO;QACpB;KACD,CAAC,EACF,EAAE,CACH;AACH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUnmountEffect.js","sources":["../../../src/hooks/useUnmountEffect.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAIA;;;;;;AAMG;AACG,SAAU,gBAAgB,CAC9B,QAA0B,EAAA;;AAI1B,IAAA,MAAM,eAAe,GAAG,YAAY,CAAC,QAAQ,CAAC
|
|
1
|
+
{"version":3,"file":"useUnmountEffect.js","sources":["../../../src/hooks/useUnmountEffect.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAIA;;;;;;AAMG;AACG,SAAU,gBAAgB,CAC9B,QAA0B,EAAA;;AAI1B,IAAA,MAAM,eAAe,GAAG,YAAY,CAAC,QAAQ,CAAC;;AAG9C,IAAA,iBAAiB,CACf,MAAM,MAAK;QACT,eAAe,CAAC,OAAO,EAAE;AAC3B,IAAA,CAAC,EACD,CAAE,eAAe,CAAE,CACpB;AAEH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowSize.js","sources":["../../../src/hooks/useWindowSize.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAsBA;;;;;;;;;;;;;;;;;AAiBG;AACG,SAAU,aAAa,CAAC,OAA8B,EAAA;AAE1D,IAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,IAAI,EAAE
|
|
1
|
+
{"version":3,"file":"useWindowSize.js","sources":["../../../src/hooks/useWindowSize.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAsBA;;;;;;;;;;;;;;;;;AAiBG;AACG,SAAU,aAAa,CAAC,OAA8B,EAAA;AAE1D,IAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,IAAI,EAAE;;;;AAKlC,IAAA,MAAM,CAAE,WAAW,EAAE,cAAc,CAAE,GAAG,KAAK,CAAC,QAAQ,CAAa,OAAO;AACxE,QAAA,MAAM,EAAE,OAAO,MAAM,KAAK,WAAW,GAAG,MAAM,CAAC,WAAW,GAAG,CAAC;AAC9D,QAAA,KAAK,EAAG,OAAO,MAAM,KAAK,WAAW,GAAG,MAAM,CAAC,UAAU,GAAG;AAC7D,KAAA,CAAC,CAAC;;;;AAMH,IAAA,MAAM,sBAAsB,GAAG,KAAK,CAAC,WAAW,CAC9C,MAAM,cAAc,CAAC,CAAC,IAAI,KAAI;AAC5B,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW;AAChC,QAAA,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,UAAU;AAC9B,QAAA,OAAO,IAAI;AACb,IAAA,CAAC,CAAC,EACF,EAAE,CACH;;;;IAMD,iBAAiB,CACf,MAAK;;QAEH,IAAI,QAAQ,EAAE;YACZ;QACF;;AAGA,QAAA,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,sBAAsB,CAAC;;AAGzD,QAAA,OAAO,MAAK;AACV,YAAA,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,sBAAsB,CAAC;AAC9D,QAAA,CAAC;AACH,IAAA,CAAC,EACD,CAAE,QAAQ,EAAE,sBAAsB,CAAE,CACrC;;;;AAMD,IAAA,OAAO,WAAW;AAEpB;;;;"}
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as RenderWhen } from './components/RenderWhen/RenderWhen.js';
|
|
2
2
|
export { useAutoControlledState } from './hooks/useAutoControlledState.js';
|
|
3
|
+
export { getAncestorsSpace, useAutoSizer } from './hooks/useAutoSizer.js';
|
|
3
4
|
export { useClickOutside } from './hooks/useClickOutside.js';
|
|
4
5
|
export { useDataManager } from './hooks/useDataManager.js';
|
|
5
6
|
export { useDataSelector } from './hooks/useDataSelector.js';
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
|
package/esm/package.json
ADDED
package/esm/utils/compose.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.js","sources":["../../../src/utils/compose.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;AAeA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;
|
|
1
|
+
{"version":3,"file":"compose.js","sources":["../../../src/utils/compose.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;AAeA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;AACG,SAAU,OAAO,CAAC,GAAG,UAAgC,EAAA;IAEzD,MAAM,iBAAiB,GAAqD,CAAC,KAAK,MAChFA,GAAA,CAAC,KAAK,CAAC,QAAQ,EAAA,EAAA,QAAA,EACZ,UAAU,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,QAAQ,KAAI;;AAE7C,YAAA,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;;AAE3B,gBAAA,MAAM,CAAE,SAAS,EAAE,cAAc,CAAE,GAAG,QAAQ;;gBAE9C,QACEA,IAAC,SAAS,EAAA,EAAA,GAAK,cAAc,EAAA,QAAA,EAC1B,QAAQ,EAAA,CACC;YAEhB;;AAGA,YAAA,QACEA,GAAA,CAAC,QAAQ,cACN,QAAQ,EAAA,CACA;AAEf,QAAA,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAA,CACH,CAClB;AAED,IAAA,iBAAiB,CAAC,WAAW,GAAG,mBAAmB;AAEnD,IAAA,OAAO,iBAAiB;AAE1B;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextBuilder.js","sources":["../../../src/utils/contextBuilder.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAWA;;;;;;AAMG;
|
|
1
|
+
{"version":3,"file":"contextBuilder.js","sources":["../../../src/utils/contextBuilder.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAWA;;;;;;AAMG;AACG,SAAU,cAAc,CAAsB,IAAY,EAAE,cAAkB,EAAA;;IAGlF,MAAM,WAAW,GAAG,KAAK,CAAC,aAAa,CAAgB,cAAc,CAAC;;IAGtE,MAAM,cAAc,GAAY,MAAK;;QAEnC,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC;;QAElD,IAAI,CAAC,YAAY,EAAE;AACjB,YAAA,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,CAAA,yCAAA,CAA2C,CAAC;QAC3F;;AAEA,QAAA,OAAO,YAAY;AACrB,IAAA,CAAC;;AAGD,IAAA,WAAW,CAAC,WAAW,GAAG,IAAI;AAE9B,IAAA,OAAO,CAAE,WAAW,EAAE,cAAc,CAAE;AACxC;;;;"}
|
package/esm/utils/shorthands.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
|
-
import
|
|
4
|
+
import kindOf from 'kind-of';
|
|
5
5
|
import { isNil } from '@proedis/utils';
|
|
6
6
|
|
|
7
7
|
/* --------
|
|
@@ -31,15 +31,15 @@ function createComponentShorthand(Component, mapValueToProps, computeComponentKe
|
|
|
31
31
|
const valueIsString = typeof value === 'string';
|
|
32
32
|
const valueIsNumber = typeof value === 'number' && !Number.isNaN(value);
|
|
33
33
|
const valueIsReactElement = React.isValidElement(value);
|
|
34
|
-
const valueIsPropObject =
|
|
35
|
-
const valueIsPrimitiveValue = valueIsString || valueIsNumber ||
|
|
34
|
+
const valueIsPropObject = kindOf(value) === 'object';
|
|
35
|
+
const valueIsPrimitiveValue = valueIsString || valueIsNumber || kindOf(value) === 'array';
|
|
36
36
|
/** Check the validity of provided value, logging the error only in production */
|
|
37
37
|
if (!valueIsReactElement && !valueIsPrimitiveValue && !valueIsPropObject) {
|
|
38
38
|
if (process.env.NODE_ENV !== 'production') {
|
|
39
39
|
console.error([
|
|
40
40
|
'Shorthand value must be a string|number|array|object|ReactElement|function.',
|
|
41
41
|
'Use null|undefined|boolean for none.',
|
|
42
|
-
`Received ${
|
|
42
|
+
`Received ${kindOf(value)}`
|
|
43
43
|
].join(' '));
|
|
44
44
|
}
|
|
45
45
|
return null;
|
|
@@ -138,8 +138,7 @@ function createShorthandFactory(Component, mapValueToProps, computeComponentKey)
|
|
|
138
138
|
*/
|
|
139
139
|
function creatableComponent(Component, mapValueToProps, computeComponentKey) {
|
|
140
140
|
/** Attach create method to the provided Component function */
|
|
141
|
-
Component.create =
|
|
142
|
-
createShorthandFactory(Component, mapValueToProps, computeComponentKey);
|
|
141
|
+
Component.create = createShorthandFactory(Component, mapValueToProps, computeComponentKey);
|
|
143
142
|
/** Return the Component */
|
|
144
143
|
return Component;
|
|
145
144
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shorthands.js","sources":["../../../src/utils/shorthands.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;;;AA8FA;;AAEc;AAEd;;;;;;;;;AASG;AACH,SAAS,wBAAwB,CAC/B,SAAsC,EACtC,eAAsD,EACtD,mBAAmD,EACnD,KAA+B,EAC/B,OAAmC,EAAA;AAGnC;;;AAGG;IACH,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE;AAC9C,QAAA,OAAO,IAAI
|
|
1
|
+
{"version":3,"file":"shorthands.js","sources":["../../../src/utils/shorthands.ts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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proedis/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A set of React Hooks, that add UI or Core functionality to your Apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"proedis",
|
|
@@ -10,15 +10,25 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"main": "./cjs/index.js",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@proedis/
|
|
13
|
+
"@proedis/types": "^2.1.0",
|
|
14
|
+
"@proedis/utils": "^2.1.0",
|
|
14
15
|
"clsx": "^2.1.1",
|
|
15
16
|
"kind-of": "^6.0.3"
|
|
16
17
|
},
|
|
17
18
|
"peerDependencies": {
|
|
18
|
-
"react": "
|
|
19
|
+
"react": ">=18.0.0 <20.0.0"
|
|
19
20
|
},
|
|
20
21
|
"module": "./esm/index.js",
|
|
21
22
|
"types": "./types/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./types/index.d.ts",
|
|
26
|
+
"import": "./esm/index.js",
|
|
27
|
+
"require": "./cjs/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"sideEffects": false,
|
|
22
32
|
"private": false,
|
|
23
33
|
"author": {
|
|
24
34
|
"name": "Proedis S.r.l.",
|
package/types/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface UseAutoSizerOptions {
|
|
3
|
+
/** Stop measuring, keeping the last size. For a panel that is collapsed, or a tab that is hidden */
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
/** Skip the height computation entirely and answer with this value */
|
|
6
|
+
fixedHeight?: number;
|
|
7
|
+
/** Skip the width computation entirely and answer with this value */
|
|
8
|
+
fixedWidth?: number;
|
|
9
|
+
/** Never grow taller than this */
|
|
10
|
+
maxHeight?: number;
|
|
11
|
+
/** Never grow wider than this */
|
|
12
|
+
maxWidth?: number;
|
|
13
|
+
/** Never shrink shorter than this */
|
|
14
|
+
minHeight?: number;
|
|
15
|
+
/** Never shrink narrower than this */
|
|
16
|
+
minWidth?: number;
|
|
17
|
+
/** Measure the element's own height instead of the room left below it */
|
|
18
|
+
useOwnHeight?: boolean;
|
|
19
|
+
/** Measure the element's own width instead of the room left beside it */
|
|
20
|
+
useOwnWidth?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface AutoSizerSize {
|
|
23
|
+
height: number;
|
|
24
|
+
width: number;
|
|
25
|
+
}
|
|
26
|
+
/** The measurement anchor: a plain `div` that reports the room around it. */
|
|
27
|
+
export type AutoSizerComponent = React.ForwardRefExoticComponent<React.PropsWithoutRef<React.ComponentProps<'div'>> & React.RefAttributes<HTMLDivElement>>;
|
|
28
|
+
export type UseAutoSizerReturn = [AutoSizerComponent, AutoSizerSize];
|
|
29
|
+
/** The room the ancestors still need after the element, on each axis */
|
|
30
|
+
export interface AncestorsSpace {
|
|
31
|
+
bottom: number;
|
|
32
|
+
right: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Sum the space every ancestor still needs *after* the element, walking up to the document.
|
|
36
|
+
*
|
|
37
|
+
* This is what makes the hook worth having. An element's `getBoundingClientRect().top` says where it
|
|
38
|
+
* starts; the room left below it is the rest of the viewport **minus** the bottom padding, margin and
|
|
39
|
+
* border of each ancestor — otherwise a table filling "the rest of the screen" overflows its card by
|
|
40
|
+
* exactly the card's own padding, and the page grows a scrollbar nobody asked for.
|
|
41
|
+
*
|
|
42
|
+
* Exported because it is the useful half on its own: anything sizing an element it does not own — a
|
|
43
|
+
* canvas, a third-party widget — needs the same number and has no reason to reimplement the walk.
|
|
44
|
+
*
|
|
45
|
+
* @param element - Where to start. Usually the parent of the element being sized.
|
|
46
|
+
*/
|
|
47
|
+
export declare function getAncestorsSpace(element: HTMLElement | null): AncestorsSpace;
|
|
48
|
+
/**
|
|
49
|
+
* Measure the room an element has, and keep measuring it.
|
|
50
|
+
*
|
|
51
|
+
* The problem it replaces is `height: calc(100vh - 320px)`: a virtualized table, a map or a chart
|
|
52
|
+
* needs a pixel height, the height available depends on everything rendered above it, and that
|
|
53
|
+
* number is not a constant — a filter bar wraps onto a second line, a sidebar collapses, a
|
|
54
|
+
* notification appears, the font finally loads.
|
|
55
|
+
*
|
|
56
|
+
* Render the returned component where the sized content goes, and use the numbers:
|
|
57
|
+
*
|
|
58
|
+
* ```tsx
|
|
59
|
+
* const [ AutoSizer, { height } ] = useAutoSizer({ minHeight: 240 });
|
|
60
|
+
*
|
|
61
|
+
* return (
|
|
62
|
+
* <AutoSizer>
|
|
63
|
+
* <VirtualizedTable height={height} rows={rows} />
|
|
64
|
+
* </AutoSizer>
|
|
65
|
+
* );
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* By default each axis answers with **the room left between the element and the far edge of the
|
|
69
|
+
* viewport**, minus what the ancestors still need for their own padding, margin and border. Switch an
|
|
70
|
+
* axis to `useOwnHeight` / `useOwnWidth` to measure the element itself instead, or pin it with
|
|
71
|
+
* `fixedHeight` / `fixedWidth`.
|
|
72
|
+
*
|
|
73
|
+
* What it watches: the element and its parent through a `ResizeObserver`, the viewport through a
|
|
74
|
+
* resize listener, and its own visibility through an `IntersectionObserver` — so a tab that was
|
|
75
|
+
* hidden when it mounted measures itself the moment it is shown, instead of reporting zero until the
|
|
76
|
+
* next window resize. Measurements are coalesced into one animation frame, because a resize observer
|
|
77
|
+
* fires several times per frame while a layout settles.
|
|
78
|
+
*
|
|
79
|
+
* @param options - See `UseAutoSizerOptions`. Read through a ref, so changing them mid-life is safe
|
|
80
|
+
* and never re-subscribes the observers.
|
|
81
|
+
*/
|
|
82
|
+
export declare function useAutoSizer(options?: UseAutoSizerOptions): UseAutoSizerReturn;
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import type * as React from 'react';
|
|
2
1
|
/**
|
|
3
2
|
* Use this hook to fire an event every time a click occurs outside
|
|
4
3
|
* the provided target element
|
|
4
|
+
*
|
|
5
|
+
* The target is typed as the minimal structural shape the hook actually reads instead of
|
|
6
|
+
* 'React.RefObject<T> | React.MutableRefObject<T>'. Those aliases changed meaning between
|
|
7
|
+
* @types/react 18 and 19: in 19 'useRef<T>(null)' yields 'RefObject<T | null>', which no
|
|
8
|
+
* longer satisfies 'RefObject<T>' and made every call site fail to compile. The
|
|
9
|
+
* implementation already null-checks 'current', so admitting it in the type costs nothing.
|
|
10
|
+
*
|
|
5
11
|
* @param target
|
|
6
12
|
* @param callback
|
|
7
13
|
* @param events
|
|
8
14
|
*/
|
|
9
|
-
export declare function useClickOutside<T extends HTMLElement>(target:
|
|
15
|
+
export declare function useClickOutside<T extends HTMLElement>(target: {
|
|
16
|
+
readonly current: T | null | undefined;
|
|
17
|
+
}, callback: EventListener, events?: ReadonlyArray<keyof HTMLElementEventMap>): void;
|
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* assign the referenced element to each single ref.
|
|
3
|
+
* The minimal shape of a mutable ref container.
|
|
5
4
|
*
|
|
6
|
-
*
|
|
5
|
+
* Deliberately structural rather than `React.MutableRefObject` or
|
|
6
|
+
* `ReturnType<typeof React.useRef<T>>`: those resolve differently between @types/react 18 and 19, and
|
|
7
|
+
* the latter made `T` infer as `HTMLElement | null`, producing a return type React 18 rejects as a JSX
|
|
8
|
+
* `ref` prop.
|
|
7
9
|
*/
|
|
8
|
-
|
|
10
|
+
interface MutableRefLike<T> {
|
|
11
|
+
current: T | null | undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Merge several refs into the single ref callback a JSX element can accept.
|
|
15
|
+
*
|
|
16
|
+
* The returned callback assigns the element to every ref it was given, which is how a component both
|
|
17
|
+
* exposes a ref to its parent and keeps one for itself.
|
|
18
|
+
*
|
|
19
|
+
* Its identity is **stable** as long as the same ref containers are passed, which matters beyond
|
|
20
|
+
* tidiness: React calls a ref callback with `null` and then with the node again every time the
|
|
21
|
+
* callback's identity changes.
|
|
22
|
+
*
|
|
23
|
+
* @param refs The refs to assign to
|
|
24
|
+
* @returns A ref callback, stable across renders that pass the same refs
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const Input = React.forwardRef<HTMLInputElement, Props>((props, ref) => {
|
|
28
|
+
* const innerRef = React.useRef<HTMLInputElement>(null);
|
|
29
|
+
* const handleRef = useForkRef(innerRef, ref as MutableRefLike<HTMLInputElement>);
|
|
30
|
+
*
|
|
31
|
+
* return <input {...props} ref={handleRef} />;
|
|
32
|
+
* });
|
|
33
|
+
*/
|
|
34
|
+
export declare function useForkRef<T>(...refs: MutableRefLike<T>[]): React.RefCallback<T>;
|
|
35
|
+
export {};
|