@proedis/react 1.5.2 → 2.0.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 +188 -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/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/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/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/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/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
package/cjs/utils/shorthands.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var clsx = require('clsx');
|
|
6
|
-
var
|
|
6
|
+
var kindOf = require('kind-of');
|
|
7
7
|
var utils = require('@proedis/utils');
|
|
8
8
|
|
|
9
9
|
function _interopNamespaceDefault(e) {
|
|
@@ -52,15 +52,15 @@ function createComponentShorthand(Component, mapValueToProps, computeComponentKe
|
|
|
52
52
|
const valueIsString = typeof value === 'string';
|
|
53
53
|
const valueIsNumber = typeof value === 'number' && !Number.isNaN(value);
|
|
54
54
|
const valueIsReactElement = React__namespace.isValidElement(value);
|
|
55
|
-
const valueIsPropObject =
|
|
56
|
-
const valueIsPrimitiveValue = valueIsString || valueIsNumber ||
|
|
55
|
+
const valueIsPropObject = kindOf(value) === 'object';
|
|
56
|
+
const valueIsPrimitiveValue = valueIsString || valueIsNumber || kindOf(value) === 'array';
|
|
57
57
|
/** Check the validity of provided value, logging the error only in production */
|
|
58
58
|
if (!valueIsReactElement && !valueIsPrimitiveValue && !valueIsPropObject) {
|
|
59
59
|
if (process.env.NODE_ENV !== 'production') {
|
|
60
60
|
console.error([
|
|
61
61
|
'Shorthand value must be a string|number|array|object|ReactElement|function.',
|
|
62
62
|
'Use null|undefined|boolean for none.',
|
|
63
|
-
`Received ${
|
|
63
|
+
`Received ${kindOf(value)}`
|
|
64
64
|
].join(' '));
|
|
65
65
|
}
|
|
66
66
|
return null;
|
|
@@ -159,8 +159,7 @@ function createShorthandFactory(Component, mapValueToProps, computeComponentKey)
|
|
|
159
159
|
*/
|
|
160
160
|
function creatableComponent(Component, mapValueToProps, computeComponentKey) {
|
|
161
161
|
/** Attach create method to the provided Component function */
|
|
162
|
-
Component.create =
|
|
163
|
-
createShorthandFactory(Component, mapValueToProps, computeComponentKey);
|
|
162
|
+
Component.create = createShorthandFactory(Component, mapValueToProps, computeComponentKey);
|
|
164
163
|
/** Return the Component */
|
|
165
164
|
return Component;
|
|
166
165
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shorthands.js","sources":["../../../src/utils/shorthands.tsx"],"sourcesContent":[null],"names":["isNil","React","_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,IAAIA,WAAK,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE;AAC9C,QAAA,OAAO,IAAI
|
|
1
|
+
{"version":3,"file":"shorthands.js","sources":["../../../src/utils/shorthands.tsx"],"sourcesContent":[null],"names":["isNil","React","_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8FA;;AAEc;AAEd;;;;;;;;;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
15
15
|
const { children, isFalse: invertConditionLogic } = props;
|
|
16
16
|
/** Check if the node must render or not */
|
|
17
|
-
if (children &&
|
|
17
|
+
if ((children && !invertConditionLogic && condition) || (invertConditionLogic && !condition)) {
|
|
18
18
|
return (jsx(React.Fragment, { children: children }));
|
|
19
19
|
}
|
|
20
20
|
/** Return Empty */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderWhen.js","sources":["../../../../src/components/RenderWhen/RenderWhen.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;AAKA;;AAEc;AACd,MAAM,UAAU,GAA6C,CAAC,KAAK,KAAI;;;;AAKrE,IAAA,MAAM,EACJ,SAAS,EACV,GAAG,KAAK
|
|
1
|
+
{"version":3,"file":"RenderWhen.js","sources":["../../../../src/components/RenderWhen/RenderWhen.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;AAKA;;AAEc;AACd,MAAM,UAAU,GAA6C,CAAC,KAAK,KAAI;;;;AAKrE,IAAA,MAAM,EACJ,SAAS,EACV,GAAG,KAAK;;AAIT,IAAA,IAAI,UAAU,IAAI,KAAK,EAAE;;QAEvB,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,oBAAoB,EAAE,GAAG,KAAK;;AAGzD,QAAA,IAAI,CAAC,QAAQ,IAAI,CAAC,oBAAoB,IAAI,SAAS,MAAM,oBAAoB,IAAI,CAAC,SAAS,CAAC,EAAE;YAC5F,QACEA,IAAC,KAAK,CAAC,QAAQ,EAAA,EAAA,QAAA,EACZ,QAAQ,EAAA,CACM;QAErB;;AAGA,QAAA,OAAO,IAAI;IACb;;IAIA,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,KAAK;;AAIpE,IAAA,QACEA,GAAA,CAAC,KAAK,CAAC,QAAQ,cACZ,SAAS,GAAG,eAAe,GAAG,gBAAgB,EAAA,CAChC;AAGrB;AAEA,UAAU,CAAC,WAAW,GAAG,YAAY;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAutoControlledState.js","sources":["../../../src/hooks/useAutoControlledState.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AA+BA;;AAEc;AAEd;;;;;;;;AAQG;
|
|
1
|
+
{"version":3,"file":"useAutoControlledState.js","sources":["../../../src/hooks/useAutoControlledState.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AA+BA;;AAEc;AAEd;;;;;;;;AAQG;AACG,SAAU,sBAAsB,CACpC,YAA2B,EAC3B,OAA0C,EAAA;AAI1C;;;;AAIG;IACH,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,OAAO,IAAI,EAAE;AAG7C;;;;;AAKG;IACH,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAU,KAAK,KAAK,SAAS,CAAC;AAGnE;;;AAGG;IACH,iBAAiB,CACf,MAAK;AACH,QAAA,gBAAgB,CAAC,OAAO,GAAG,KAAK,KAAK,SAAS;AAChD,IAAA,CAAC,EACD,CAAE,KAAK,CAAE,CACV;AAGD;;;;;;AAMG;IACH,MAAM,CAAE,KAAK,EAAE,QAAQ,CAAE,GAAG,YAAY,CACtC,MAAK;;AAEH,QAAA,MAAM,WAAW,GAAG,KAAK,KAAK,SAAS,GAAG,YAAY,GAAG,SAAS;;AAGlE,QAAA,IAAI,WAAW,KAAK,SAAS,EAAE;AAC7B,YAAA,OAAO,WAAW;QACpB;;QAGA,OAAO,OAAO,YAAY,KAAK;cAC1B,YAAwB;cACzB,YAAY;AAClB,IAAA,CAAC,CACF;AAGD;;;;AAIG;IACH,MAAM,WAAW,GAA4C,KAAK,CAAC,WAAW,CAC5E,CAAC,QAAQ,KAAI;;AAEX,QAAA,IAAI,gBAAgB,CAAC,OAAO,EAAE;YAC5B,QAAQ,CAAC,QAAQ,CAAC;QACpB;AACF,IAAA,CAAC,EACD,CAAE,QAAQ,CAAE,CACb;;IAID,OAAO;QACL,KAAK,KAAK,SAAS,GAAG,KAAK,GAAG,KAAK;QACnC,WAAW;QACX;KACQ;AAEZ;;;;"}
|
|
@@ -9,6 +9,13 @@ const DEFAULT_EVENTS = [
|
|
|
9
9
|
/**
|
|
10
10
|
* Use this hook to fire an event every time a click occurs outside
|
|
11
11
|
* the provided target element
|
|
12
|
+
*
|
|
13
|
+
* The target is typed as the minimal structural shape the hook actually reads instead of
|
|
14
|
+
* 'React.RefObject<T> | React.MutableRefObject<T>'. Those aliases changed meaning between
|
|
15
|
+
* @types/react 18 and 19: in 19 'useRef<T>(null)' yields 'RefObject<T | null>', which no
|
|
16
|
+
* longer satisfies 'RefObject<T>' and made every call site fail to compile. The
|
|
17
|
+
* implementation already null-checks 'current', so admitting it in the type costs nothing.
|
|
18
|
+
*
|
|
12
19
|
* @param target
|
|
13
20
|
* @param callback
|
|
14
21
|
* @param events
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClickOutside.js","sources":["../../../src/hooks/useClickOutside.ts"],"sourcesContent":[null],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"useClickOutside.js","sources":["../../../src/hooks/useClickOutside.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAIA;AACA,MAAM,cAAc,GAA6C;IAC/D,WAAW;IACX;CACD;AAGD;;;;;;;;;;;;;AAaG;AACG,SAAU,eAAe,CAC7B,MAAkD,EAClD,QAAuB,EACvB,SAAmD,cAAc,EAAA;;AAIjE,IAAA,MAAM,aAAa,GAAG,YAAY,CAAC,MAAM,CAAC;AAC1C,IAAA,MAAM,gBAAgB,GAAG,YAAY,CAAC,QAAQ,CAAC;;IAG/C,iBAAiB,CACf,MAAK;AAEH;;;;;;AAMG;QACH,SAAS,OAAO,CAAoB,KAAY,EAAA;;AAE9C,YAAA,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,EAAE;gBAClC;YACF;;AAGA,YAAA,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK;AACrC,YAAA,MAAM,EAAE,GAAG,gBAAgB,CAAC,OAAO;AAEnC,YAAA,IACE,CAAC;AACE,oBAAC,CAAC,CAAC,WAAW,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAmB,CAAC,CAAC,EAAE;;AAEpF,gBAAA,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC;YACtB;QACF;;AAGA,QAAA,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,KAAI;;AAE3B,YAAA,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAClE,QAAA,CAAC,CAAC;;AAGF,QAAA,OAAO,MAAK;AACV,YAAA,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,KAAI;;AAE3B,gBAAA,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC;AAClD,YAAA,CAAC,CAAC;AACJ,QAAA,CAAC;IACH,CAAC;;IAED,CAAE,gBAAgB,EAAE,aAAa,EAAE,GAAG,MAAM,CAAE,CAC/C;AAEH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataManager.js","sources":["../../../src/hooks/useDataManager.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAiCA;;AAEc;SACE,cAAc,GAAA;;;;AAK5B,IAAA,MAAM,CAAE,QAAQ,EAAE,WAAW,CAAE,GAAG,KAAK,CAAC,QAAQ,CAAgB,SAAS,CAAC
|
|
1
|
+
{"version":3,"file":"useDataManager.js","sources":["../../../src/hooks/useDataManager.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAiCA;;AAEc;SACE,cAAc,GAAA;;;;AAK5B,IAAA,MAAM,CAAE,QAAQ,EAAE,WAAW,CAAE,GAAG,KAAK,CAAC,QAAQ,CAAgB,SAAS,CAAC;AAC1E,IAAA,MAAM,CAAE,QAAQ,EAAE,WAAW,CAAE,GAAG,KAAK,CAAC,QAAQ,CAAgB,SAAS,CAAC;;;;AAM1E,IAAA,MAAM,aAAa,GAAG,KAAK,CAAC,WAAW,CACrC,MAAM,WAAW,CAAC,SAAS,CAAC,EAC5B,EAAE,CACH;AAED,IAAA,MAAM,aAAa,GAAG,KAAK,CAAC,WAAW,CACrC,MAAM,WAAW,CAAC,SAAS,CAAC,EAC5B,EAAE,CACH;IAED,MAAM,qBAAqB,GAAG,KAAK,CAAC,WAAW,CAC7C,CAAC,OAAsB,KAAK,MAAM,WAAW,CAAC,OAAO,CAAC,EACtD,EAAE,CACH;IAED,MAAM,qBAAqB,GAAG,KAAK,CAAC,WAAW,CAC7C,CAAC,OAAsB,KAAK,MAAM,WAAW,CAAC,OAAO,CAAC,EACtD,EAAE,CACH;;;;IAMD,OAAO;QACL,QAAQ;QACR,aAAa;QACb,aAAa;QACb,qBAAqB;QACrB,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX;KACD;AAEH;;;;"}
|
|
@@ -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,EA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
|
+
{"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/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.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;IACb;;;;AAOA,IAAA,MAAM,aAAa,GAAG,OAAO,KAAK,KAAK,QAAQ;AAC/C,IAAA,MAAM,aAAa,GAAG,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;IACvE,MAAM,mBAAmB,GAAG,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC;IACvD,MAAM,iBAAiB,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,QAAQ;AACpD,IAAA,MAAM,qBAAqB,GAAG,aAAa,IAAI,aAAa,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,OAAO;;IAGzF,IAAI,CAAC,mBAAmB,IAAI,CAAC,qBAAqB,IAAI,CAAC,iBAAiB,EAAE;QACxE,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;YACzC,OAA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AA0C,CAAC,MAAM,GAAG,sBAAsB,CACzE,SAAS,EACT,eAAe,EACf,mBAAmB,CACpB;;AAGD,IAAA,OAAO,SAAyC;AAElD;AAGA;;AAEc;SACE,sBAAsB,CAAC,EAAE,QAAQ,EAAE,OAAO,EAGzD,EAAA;;IAEC,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,SAAS,KAAK,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE;AACrG,QAAA,OAAO,OAAO;IAChB;;AAGA,IAAA,OAAO,QAAQ;AACjB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proedis/react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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.0.0",
|
|
14
|
+
"@proedis/utils": "^2.0.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.",
|
|
@@ -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;
|