yummies 7.11.0 → 7.12.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/async.cjs +162 -48
- package/async.cjs.map +1 -1
- package/async.d.ts +108 -7
- package/async.js +163 -54
- package/async.js.map +1 -1
- package/chunk-CVq3Gv4J.cjs +50 -0
- package/chunk-YKewjYmz.js +37 -0
- package/common.cjs +48 -8
- package/common.cjs.map +1 -1
- package/common.d.ts +35 -2
- package/common.js +49 -11
- package/common.js.map +1 -1
- package/complex.cjs +275 -128
- package/complex.cjs.map +1 -1
- package/complex.js +275 -133
- package/complex.js.map +1 -1
- package/cookie.cjs +17 -7
- package/cookie.cjs.map +1 -1
- package/cookie.d.ts +8 -0
- package/cookie.js +18 -9
- package/cookie.js.map +1 -1
- package/css.cjs +147 -39
- package/css.cjs.map +1 -1
- package/css.d.ts +98 -6
- package/css.js +143 -41
- package/css.js.map +1 -1
- package/data.cjs +90 -55
- package/data.cjs.map +1 -1
- package/data.d.ts +32 -0
- package/data.js +91 -61
- package/data.js.map +1 -1
- package/date-time.cjs +578 -412
- package/date-time.cjs.map +1 -1
- package/date-time.d.ts +88 -0
- package/date-time.js +575 -421
- package/date-time.js.map +1 -1
- package/device.cjs +48 -23
- package/device.cjs.map +1 -1
- package/device.d.ts +32 -0
- package/device.js +49 -31
- package/device.js.map +1 -1
- package/encodings.cjs +275 -266
- package/encodings.cjs.map +1 -1
- package/encodings.d.ts +8 -0
- package/encodings.js +276 -268
- package/encodings.js.map +1 -1
- package/errors.cjs +20 -18
- package/errors.cjs.map +1 -1
- package/errors.js +19 -19
- package/errors.js.map +1 -1
- package/file.cjs +42 -24
- package/file.cjs.map +1 -1
- package/file.d.ts +16 -0
- package/file.js +43 -27
- package/file.js.map +1 -1
- package/format.cjs +125 -83
- package/format.cjs.map +1 -1
- package/format.js +118 -82
- package/format.js.map +1 -1
- package/html.cjs +226 -137
- package/html.cjs.map +1 -1
- package/html.d.ts +64 -0
- package/html.js +223 -150
- package/html.js.map +1 -1
- package/id.cjs +74 -17
- package/id.cjs.map +1 -1
- package/id.js +73 -24
- package/id.js.map +1 -1
- package/imports.cjs +41 -29
- package/imports.cjs.map +1 -1
- package/imports.d.ts +8 -0
- package/imports.js +40 -31
- package/imports.js.map +1 -1
- package/math.cjs +32 -6
- package/math.cjs.map +1 -1
- package/math.d.ts +16 -0
- package/math.js +33 -10
- package/math.js.map +1 -1
- package/media.cjs +275 -84
- package/media.cjs.map +1 -1
- package/media.d.ts +188 -2
- package/media.js +274 -93
- package/media.js.map +1 -1
- package/mobx.cjs +353 -193
- package/mobx.cjs.map +1 -1
- package/mobx.d.ts +7 -0
- package/mobx.js +351 -200
- package/mobx.js.map +1 -1
- package/ms.cjs +21 -10
- package/ms.cjs.map +1 -1
- package/ms.js +22 -13
- package/ms.js.map +1 -1
- package/number.cjs +13 -7
- package/number.cjs.map +1 -1
- package/number.js +14 -9
- package/number.js.map +1 -1
- package/package.json +10 -2
- package/parser.cjs +117 -64
- package/parser.cjs.map +1 -1
- package/parser.js +111 -64
- package/parser.js.map +1 -1
- package/price.cjs +24 -18
- package/price.cjs.map +1 -1
- package/price.d.ts +8 -0
- package/price.js +25 -20
- package/price.js.map +1 -1
- package/random.cjs +79 -13
- package/random.cjs.map +1 -1
- package/random.d.ts +64 -0
- package/random.js +80 -22
- package/random.js.map +1 -1
- package/react.cjs +673 -214
- package/react.cjs.map +1 -1
- package/react.d.ts +21 -0
- package/react.js +674 -239
- package/react.js.map +1 -1
- package/sound.cjs +14 -9
- package/sound.cjs.map +1 -1
- package/sound.js +15 -11
- package/sound.js.map +1 -1
- package/storage.cjs +49 -50
- package/storage.cjs.map +1 -1
- package/storage.d.ts +8 -0
- package/storage.js +50 -53
- package/storage.js.map +1 -1
- package/text.cjs +51 -34
- package/text.cjs.map +1 -1
- package/text.js +52 -37
- package/text.js.map +1 -1
- package/type-guard.cjs +292 -72
- package/type-guard.cjs.map +1 -1
- package/type-guard.js +288 -73
- package/type-guard.js.map +1 -1
- package/types.cjs +0 -2
- package/types.global.cjs +0 -2
- package/types.global.js +0 -2
- package/types.js +0 -2
- package/vibrate.cjs +31 -6
- package/vibrate.cjs.map +1 -1
- package/vibrate.d.ts +23 -1
- package/vibrate.js +32 -8
- package/vibrate.js.map +1 -1
- package/types.cjs.map +0 -1
- package/types.global.cjs.map +0 -1
- package/types.global.js.map +0 -1
- package/types.js.map +0 -1
package/react.cjs
CHANGED
|
@@ -1,219 +1,677 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
require("./chunk-CVq3Gv4J.cjs");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
//#region src/react/attach-refs.ts
|
|
5
|
+
/**
|
|
6
|
+
* Assigns the same value to multiple React refs, including callback refs.
|
|
7
|
+
*
|
|
8
|
+
* @template T Referenced value type.
|
|
9
|
+
* @param value Value that should be written into every provided ref.
|
|
10
|
+
* @param refs Target refs to update.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* attachRefs(node, localRef, forwardedRef);
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* attachRefs(null, inputRef, (value) => console.log(value));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
var attachRefs = (value, ...refs) => refs.forEach((ref) => {
|
|
23
|
+
if (typeof ref === "function") ref(value);
|
|
24
|
+
else if (ref && typeof ref !== "string") ref.current = value;
|
|
10
25
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
handler,
|
|
38
|
-
options,
|
|
39
|
-
deps = [],
|
|
40
|
-
debounce,
|
|
41
|
-
node = document
|
|
42
|
-
}) => {
|
|
43
|
-
const handlerRef = useSyncRef(handler);
|
|
44
|
-
react.useEffect(() => {
|
|
45
|
-
let timerId;
|
|
46
|
-
const handleEvent = (e) => {
|
|
47
|
-
if (debounce == null) {
|
|
48
|
-
handlerRef.current(e);
|
|
49
|
-
} else {
|
|
50
|
-
clearTimeout(timerId);
|
|
51
|
-
timerId = setTimeout(() => {
|
|
52
|
-
handlerRef.current(e);
|
|
53
|
-
timerId = void 0;
|
|
54
|
-
}, debounce);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
node.addEventListener(event, handleEvent, options);
|
|
58
|
-
return () => {
|
|
59
|
-
node.removeEventListener(event, handleEvent, options);
|
|
60
|
-
clearTimeout(timerId);
|
|
61
|
-
};
|
|
62
|
-
}, deps);
|
|
63
|
-
};
|
|
64
|
-
const useClickOutside = ({
|
|
65
|
-
contentRef,
|
|
66
|
-
onClick,
|
|
67
|
-
options
|
|
68
|
-
}) => {
|
|
69
|
-
useEventListener({
|
|
70
|
-
event: "mousedown",
|
|
71
|
-
handler: (event) => {
|
|
72
|
-
if (contentRef.current && !contentRef.current.contains(event.target)) {
|
|
73
|
-
onClick();
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
options
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
const useDefineRef = (defineFn) => {
|
|
80
|
-
const ref = react.useRef(void 0);
|
|
81
|
-
if (!ref.current) {
|
|
82
|
-
ref.current = defineFn();
|
|
83
|
-
}
|
|
84
|
-
return ref;
|
|
85
|
-
};
|
|
86
|
-
const useElementRef = (selector) => {
|
|
87
|
-
const ref = react.useRef();
|
|
88
|
-
react.useLayoutEffect(() => {
|
|
89
|
-
ref.current = selector();
|
|
90
|
-
}, []);
|
|
91
|
-
return ref;
|
|
92
|
-
};
|
|
93
|
-
const useEvent = (handler) => {
|
|
94
|
-
const handlerRef = react.useRef(handler);
|
|
95
|
-
react.useLayoutEffect(() => {
|
|
96
|
-
handlerRef.current = handler;
|
|
97
|
-
});
|
|
98
|
-
return react.useCallback((...args) => {
|
|
99
|
-
const fn = handlerRef.current;
|
|
100
|
-
return fn(...args);
|
|
101
|
-
}, []);
|
|
102
|
-
};
|
|
103
|
-
const useFlag = (defaultValue = false) => {
|
|
104
|
-
const [enabled, setEnabled] = react.useState(defaultValue);
|
|
105
|
-
const toggle = react.useCallback(() => setEnabled((value) => !value), []);
|
|
106
|
-
const enable = react.useCallback(() => setEnabled(true), []);
|
|
107
|
-
const disable = react.useCallback(() => setEnabled(false), []);
|
|
108
|
-
const flagObjRef = react.useRef({
|
|
109
|
-
enabled,
|
|
110
|
-
toggle,
|
|
111
|
-
enable,
|
|
112
|
-
disable
|
|
113
|
-
});
|
|
114
|
-
flagObjRef.current.enabled = enabled;
|
|
115
|
-
return flagObjRef.current;
|
|
116
|
-
};
|
|
117
|
-
const useForceUpdate = () => {
|
|
118
|
-
const [, setState] = react.useState(null);
|
|
119
|
-
return react.useCallback(() => {
|
|
120
|
-
setState({});
|
|
121
|
-
}, []);
|
|
122
|
-
};
|
|
123
|
-
const useInitialHeight = () => {
|
|
124
|
-
const ref = react.useRef(null);
|
|
125
|
-
const [initialHeight, setInitialHeight] = react.useState(
|
|
126
|
-
void 0
|
|
127
|
-
);
|
|
128
|
-
react.useEffect(() => {
|
|
129
|
-
if (ref.current && !initialHeight) {
|
|
130
|
-
setInitialHeight(ref.current.offsetHeight);
|
|
131
|
-
}
|
|
132
|
-
}, [initialHeight]);
|
|
133
|
-
return { ref, initialHeight };
|
|
134
|
-
};
|
|
135
|
-
const createUseInstanceHook = (extension) => (factory, config) => {
|
|
136
|
-
const abortSignal = useAbortSignal();
|
|
137
|
-
const instance = useConstant(
|
|
138
|
-
() => factory({
|
|
139
|
-
...extension,
|
|
140
|
-
abortSignal,
|
|
141
|
-
payload: config?.payload
|
|
142
|
-
})
|
|
143
|
-
);
|
|
144
|
-
react.useLayoutEffect(() => {
|
|
145
|
-
config?.onUpdate?.(config.payload);
|
|
146
|
-
}, [config?.payload]);
|
|
147
|
-
return instance;
|
|
148
|
-
};
|
|
149
|
-
const useInstance = createUseInstanceHook();
|
|
150
|
-
const useIntersectionObserver = (callback, options) => {
|
|
151
|
-
const [intersectionObserver] = react.useState(
|
|
152
|
-
() => new IntersectionObserver(callback, options)
|
|
153
|
-
);
|
|
154
|
-
react.useEffect(() => {
|
|
155
|
-
return () => {
|
|
156
|
-
intersectionObserver.disconnect();
|
|
157
|
-
};
|
|
158
|
-
}, []);
|
|
159
|
-
return intersectionObserver;
|
|
160
|
-
};
|
|
161
|
-
const useLastDefinedValue = (value) => {
|
|
162
|
-
const ref = react.useRef(value);
|
|
163
|
-
if (value != null) {
|
|
164
|
-
ref.current = value;
|
|
165
|
-
}
|
|
166
|
-
return ref.current;
|
|
167
|
-
};
|
|
168
|
-
const useLastValueRef = (value) => {
|
|
169
|
-
const ref = react.useRef(value);
|
|
170
|
-
if (value != null) {
|
|
171
|
-
ref.current = value;
|
|
172
|
-
}
|
|
173
|
-
return ref;
|
|
174
|
-
};
|
|
175
|
-
const useLifeCycle = (fn) => {
|
|
176
|
-
const fnRef = useSyncRef(fn);
|
|
177
|
-
react.useEffect(() => {
|
|
178
|
-
const fnOperation = fnRef.current();
|
|
179
|
-
fnOperation.mount?.();
|
|
180
|
-
return fnOperation.unmount?.();
|
|
181
|
-
}, []);
|
|
182
|
-
};
|
|
183
|
-
const useResizeObserver = (callback) => {
|
|
184
|
-
const resizeObserverRef = useDefineRef(() => new ResizeObserver(callback));
|
|
185
|
-
react.useLayoutEffect(() => {
|
|
186
|
-
return () => {
|
|
187
|
-
resizeObserverRef.current.disconnect();
|
|
188
|
-
};
|
|
189
|
-
}, []);
|
|
190
|
-
return resizeObserverRef;
|
|
191
|
-
};
|
|
192
|
-
const useToggle = (initialState) => {
|
|
193
|
-
const [toggled, setToggled] = react.useState(!!initialState);
|
|
194
|
-
const toggle = react.useCallback(() => setToggled((toggled2) => !toggled2), []);
|
|
195
|
-
return [toggled, toggle, setToggled];
|
|
196
|
-
};
|
|
197
|
-
const useValue = (defaults) => {
|
|
198
|
-
const [value, setValue] = react.useState(defaults);
|
|
199
|
-
return {
|
|
200
|
-
value,
|
|
201
|
-
set: setValue
|
|
202
|
-
};
|
|
203
|
-
};
|
|
204
|
-
const useVisibilityState = () => {
|
|
205
|
-
const [state, setState] = react.useState();
|
|
206
|
-
react.useEffect(() => {
|
|
207
|
-
const handleVisibilityChange = () => {
|
|
208
|
-
setState(document.visibilityState);
|
|
209
|
-
};
|
|
210
|
-
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
211
|
-
return () => {
|
|
212
|
-
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
213
|
-
};
|
|
214
|
-
}, []);
|
|
215
|
-
return state;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/react/hooks/use-constant.ts
|
|
28
|
+
/**
|
|
29
|
+
* React hook for creating a value exactly once.
|
|
30
|
+
*
|
|
31
|
+
* Unlike `useMemo`, this guarantees that the initializer is executed only once
|
|
32
|
+
* for the component lifetime.
|
|
33
|
+
*
|
|
34
|
+
* @template T Value type.
|
|
35
|
+
* @param defineValue Function that lazily creates the value.
|
|
36
|
+
* @returns Stable value created on the first render.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const id = useConstant(() => crypto.randomUUID());
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const formatter = useConstant(() => new Intl.NumberFormat('en-US'));
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
var useConstant = (defineValue) => {
|
|
49
|
+
const ref = (0, react.useRef)();
|
|
50
|
+
if (!ref.current) ref.current = { value: defineValue() };
|
|
51
|
+
return ref.current.value;
|
|
216
52
|
};
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/react/hooks/use-abort-controller.ts
|
|
55
|
+
/**
|
|
56
|
+
* Creates a single `AbortController` instance for the component lifetime.
|
|
57
|
+
*
|
|
58
|
+
* The controller is aborted automatically during unmount.
|
|
59
|
+
*
|
|
60
|
+
* @returns Stable abort controller instance.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const controller = useAbortController();
|
|
65
|
+
* fetch('/api', { signal: controller.signal });
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const controller = useAbortController();
|
|
71
|
+
* controller.abort();
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
var useAbortController = () => {
|
|
75
|
+
const controller = useConstant(() => new AbortController());
|
|
76
|
+
(0, react.useEffect)(() => {
|
|
77
|
+
return () => {
|
|
78
|
+
controller.abort();
|
|
79
|
+
};
|
|
80
|
+
}, []);
|
|
81
|
+
return controller;
|
|
82
|
+
};
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/react/hooks/use-abort-signal.ts
|
|
85
|
+
/**
|
|
86
|
+
* Returns an `AbortSignal` tied to the component lifecycle.
|
|
87
|
+
*
|
|
88
|
+
* The signal is aborted automatically on unmount.
|
|
89
|
+
*
|
|
90
|
+
* @returns Lifecycle-bound abort signal.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* const signal = useAbortSignal();
|
|
95
|
+
* fetch('/api/users', { signal });
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const signal = useAbortSignal();
|
|
101
|
+
* someAsyncTask({ signal });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
var useAbortSignal = () => {
|
|
105
|
+
return useAbortController().signal;
|
|
106
|
+
};
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/react/hooks/use-sync-ref.ts
|
|
109
|
+
/**
|
|
110
|
+
* Returns a ref whose `current` value is synchronized with the latest input
|
|
111
|
+
* on every render.
|
|
112
|
+
*
|
|
113
|
+
* @template T Value type.
|
|
114
|
+
* @param value Current value to expose through the ref.
|
|
115
|
+
* @returns Ref containing the latest value.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const latestHandler = useSyncRef(onSubmit);
|
|
120
|
+
* latestHandler.current();
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* const latestValue = useSyncRef(props.value);
|
|
126
|
+
* latestValue.current;
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
var useSyncRef = (value) => {
|
|
130
|
+
const ref = (0, react.useRef)(value);
|
|
131
|
+
ref.current = value;
|
|
132
|
+
return ref;
|
|
133
|
+
};
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/react/hooks/use-event-listener.ts
|
|
136
|
+
/**
|
|
137
|
+
* Subscribes to a DOM event and keeps the latest handler without resubscribing
|
|
138
|
+
* on every render.
|
|
139
|
+
*
|
|
140
|
+
* Supports optional debounce and custom effect dependencies.
|
|
141
|
+
*
|
|
142
|
+
* @template EventName DOM event name from `HTMLElementEventMap`.
|
|
143
|
+
* @param config Event subscription configuration.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* useEventListener({
|
|
148
|
+
* event: 'click',
|
|
149
|
+
* handler: () => console.log('clicked'),
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* useEventListener({
|
|
156
|
+
* event: 'scroll',
|
|
157
|
+
* node: window,
|
|
158
|
+
* debounce: 100,
|
|
159
|
+
* handler: () => console.log('scroll'),
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
var useEventListener = ({ event, handler, options, deps = [], debounce, node = document }) => {
|
|
164
|
+
const handlerRef = useSyncRef(handler);
|
|
165
|
+
(0, react.useEffect)(() => {
|
|
166
|
+
let timerId;
|
|
167
|
+
const handleEvent = (e) => {
|
|
168
|
+
if (debounce == null) handlerRef.current(e);
|
|
169
|
+
else {
|
|
170
|
+
clearTimeout(timerId);
|
|
171
|
+
timerId = setTimeout(() => {
|
|
172
|
+
handlerRef.current(e);
|
|
173
|
+
timerId = void 0;
|
|
174
|
+
}, debounce);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
node.addEventListener(event, handleEvent, options);
|
|
178
|
+
return () => {
|
|
179
|
+
node.removeEventListener(event, handleEvent, options);
|
|
180
|
+
clearTimeout(timerId);
|
|
181
|
+
};
|
|
182
|
+
}, deps);
|
|
183
|
+
};
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/react/hooks/use-click-outside.ts
|
|
186
|
+
/**
|
|
187
|
+
* Calls a handler when a pointer interaction happens outside the referenced element.
|
|
188
|
+
*
|
|
189
|
+
* @param input Target element ref, callback and event listener options.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* useClickOutside({
|
|
194
|
+
* contentRef: modalRef,
|
|
195
|
+
* onClick: () => closeModal(),
|
|
196
|
+
* });
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* useClickOutside({
|
|
202
|
+
* contentRef: dropdownRef,
|
|
203
|
+
* onClick: hideDropdown,
|
|
204
|
+
* options: { capture: true },
|
|
205
|
+
* });
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
var useClickOutside = ({ contentRef, onClick, options }) => {
|
|
209
|
+
useEventListener({
|
|
210
|
+
event: "mousedown",
|
|
211
|
+
handler: (event) => {
|
|
212
|
+
if (contentRef.current && !contentRef.current.contains(event.target)) onClick();
|
|
213
|
+
},
|
|
214
|
+
options
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/react/hooks/use-define-ref.ts
|
|
219
|
+
/**
|
|
220
|
+
* Creates a mutable ref whose value is initialized exactly once.
|
|
221
|
+
*
|
|
222
|
+
* @template T Ref value type.
|
|
223
|
+
* @param defineFn Function that lazily creates the initial ref value.
|
|
224
|
+
* @returns Mutable ref with a stable initialized value.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* const cacheRef = useDefineRef(() => new Map());
|
|
229
|
+
* ```
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* const observerRef = useDefineRef(() => new ResizeObserver(() => {}));
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
var useDefineRef = (defineFn) => {
|
|
237
|
+
const ref = (0, react.useRef)(void 0);
|
|
238
|
+
if (!ref.current) ref.current = defineFn();
|
|
239
|
+
return ref;
|
|
240
|
+
};
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/react/hooks/use-element-ref.ts
|
|
243
|
+
/**
|
|
244
|
+
* Resolves an element once after mount and stores it in a ref.
|
|
245
|
+
*
|
|
246
|
+
* @template T Element type.
|
|
247
|
+
* @param selector Function returning the target element.
|
|
248
|
+
* @returns Ref containing the selected element.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* const buttonRef = useElementRef(() => document.getElementById('save') as HTMLButtonElement);
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* const modalRef = useElementRef(() => document.querySelector('.modal') as HTMLDivElement);
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
var useElementRef = (selector) => {
|
|
261
|
+
const ref = (0, react.useRef)();
|
|
262
|
+
(0, react.useLayoutEffect)(() => {
|
|
263
|
+
ref.current = selector();
|
|
264
|
+
}, []);
|
|
265
|
+
return ref;
|
|
266
|
+
};
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/react/hooks/use-event.ts
|
|
269
|
+
/**
|
|
270
|
+
* Creates an event callback with a stable function identity and up-to-date logic.
|
|
271
|
+
*
|
|
272
|
+
* Borrowed from the `useEvent` RFC idea by React contributors.
|
|
273
|
+
*
|
|
274
|
+
* @template H Handler function type.
|
|
275
|
+
* @param handler Latest callback implementation.
|
|
276
|
+
* @returns Stable callback that always delegates to the latest handler.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```ts
|
|
280
|
+
* const onClick = useEvent(() => {
|
|
281
|
+
* console.log('clicked');
|
|
282
|
+
* });
|
|
283
|
+
* ```
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```ts
|
|
287
|
+
* const onSubmit = useEvent((value: string) => save(value));
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
var useEvent = (handler) => {
|
|
291
|
+
const handlerRef = (0, react.useRef)(handler);
|
|
292
|
+
(0, react.useLayoutEffect)(() => {
|
|
293
|
+
handlerRef.current = handler;
|
|
294
|
+
});
|
|
295
|
+
return (0, react.useCallback)((...args) => {
|
|
296
|
+
const fn = handlerRef.current;
|
|
297
|
+
return fn(...args);
|
|
298
|
+
}, []);
|
|
299
|
+
};
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/react/hooks/use-flag.ts
|
|
302
|
+
/**
|
|
303
|
+
* Manages a reusable boolean flag object with stable helper methods.
|
|
304
|
+
*
|
|
305
|
+
* @param defaultValue Initial enabled state.
|
|
306
|
+
* @returns Stable object exposing current state and mutators.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* const modal = useFlag();
|
|
311
|
+
* modal.enable();
|
|
312
|
+
* ```
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```ts
|
|
316
|
+
* const loading = useFlag(true);
|
|
317
|
+
* loading.disable();
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
var useFlag = (defaultValue = false) => {
|
|
321
|
+
const [enabled, setEnabled] = (0, react.useState)(defaultValue);
|
|
322
|
+
const flagObjRef = (0, react.useRef)({
|
|
323
|
+
enabled,
|
|
324
|
+
toggle: (0, react.useCallback)(() => setEnabled((value) => !value), []),
|
|
325
|
+
enable: (0, react.useCallback)(() => setEnabled(true), []),
|
|
326
|
+
disable: (0, react.useCallback)(() => setEnabled(false), [])
|
|
327
|
+
});
|
|
328
|
+
flagObjRef.current.enabled = enabled;
|
|
329
|
+
return flagObjRef.current;
|
|
330
|
+
};
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/react/hooks/use-force-update.ts
|
|
333
|
+
/**
|
|
334
|
+
* Forces a component re-render by updating an internal dummy state.
|
|
335
|
+
*
|
|
336
|
+
* @returns Stable callback that triggers a re-render.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```ts
|
|
340
|
+
* const forceUpdate = useForceUpdate();
|
|
341
|
+
* forceUpdate();
|
|
342
|
+
* ```
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* ```ts
|
|
346
|
+
* const rerender = useForceUpdate();
|
|
347
|
+
* setTimeout(rerender, 1000);
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
var useForceUpdate = () => {
|
|
351
|
+
const [, setState] = (0, react.useState)(null);
|
|
352
|
+
return (0, react.useCallback)(() => {
|
|
353
|
+
setState({});
|
|
354
|
+
}, []);
|
|
355
|
+
};
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/react/hooks/use-initial-height.ts
|
|
358
|
+
/**
|
|
359
|
+
* Captures an element's height the first time its ref becomes available.
|
|
360
|
+
*
|
|
361
|
+
* @template T Element type attached to the returned ref.
|
|
362
|
+
* @returns Ref and the initial measured height.
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```ts
|
|
366
|
+
* const { ref, initialHeight } = useInitialHeight<HTMLDivElement>();
|
|
367
|
+
* ```
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```ts
|
|
371
|
+
* const state = useInitialHeight<HTMLTextAreaElement>();
|
|
372
|
+
* state.initialHeight;
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
var useInitialHeight = () => {
|
|
376
|
+
const ref = (0, react.useRef)(null);
|
|
377
|
+
const [initialHeight, setInitialHeight] = (0, react.useState)(void 0);
|
|
378
|
+
(0, react.useEffect)(() => {
|
|
379
|
+
if (ref.current && !initialHeight) setInitialHeight(ref.current.offsetHeight);
|
|
380
|
+
}, [initialHeight]);
|
|
381
|
+
return {
|
|
382
|
+
ref,
|
|
383
|
+
initialHeight
|
|
384
|
+
};
|
|
385
|
+
};
|
|
386
|
+
//#endregion
|
|
387
|
+
//#region src/react/hooks/use-instance.ts
|
|
388
|
+
/**
|
|
389
|
+
* Builds a custom hook that creates an instance once and wires lifecycle helpers
|
|
390
|
+
* such as an `AbortSignal` and optional extension data into the factory.
|
|
391
|
+
*
|
|
392
|
+
* @template TExtension Extra configuration injected into every factory call.
|
|
393
|
+
* @param extension Optional static extension object merged into the factory config.
|
|
394
|
+
* @returns Hook factory that creates stable instances from a supplied factory.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```ts
|
|
398
|
+
* const useStoreInstance = createUseInstanceHook({ api });
|
|
399
|
+
* ```
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* ```ts
|
|
403
|
+
* const useService = createUseInstanceHook({ logger });
|
|
404
|
+
* const service = useService(({ logger, payload }) => new Service(logger, payload));
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
var createUseInstanceHook = (extension) => (factory, config) => {
|
|
408
|
+
const abortSignal = useAbortSignal();
|
|
409
|
+
const instance = useConstant(() => factory({
|
|
410
|
+
...extension,
|
|
411
|
+
abortSignal,
|
|
412
|
+
payload: config?.payload
|
|
413
|
+
}));
|
|
414
|
+
(0, react.useLayoutEffect)(() => {
|
|
415
|
+
config?.onUpdate?.(config.payload);
|
|
416
|
+
}, [config?.payload]);
|
|
417
|
+
return instance;
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* The `useInstance` hook is used to create and manage an instance of an object
|
|
421
|
+
* that requires access to the root store and an abort signal.
|
|
422
|
+
*
|
|
423
|
+
* You can create YOUR OWN CUSTOM `useInstance` hook using `createUseInstanceHook` if you need
|
|
424
|
+
* to provide some specific data
|
|
425
|
+
*
|
|
426
|
+
* @param factory - A factory function that takes a configuration and returns an instance.
|
|
427
|
+
* @param config - An optional configuration containing additional input parameters and an update function.
|
|
428
|
+
* @returns An instance created by the factory function.
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* ```ts
|
|
432
|
+
* const service = useInstance(({ abortSignal }) => new UsersService({ abortSignal }));
|
|
433
|
+
* ```
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* ```ts
|
|
437
|
+
* const store = useInstance(
|
|
438
|
+
* ({ payload }) => new UserStore(payload),
|
|
439
|
+
* { payload: userId, onUpdate: (nextId) => console.log(nextId) },
|
|
440
|
+
* );
|
|
441
|
+
* ```
|
|
442
|
+
*/
|
|
443
|
+
var useInstance = createUseInstanceHook();
|
|
444
|
+
//#endregion
|
|
445
|
+
//#region src/react/hooks/use-intersection-observer.ts
|
|
446
|
+
/**
|
|
447
|
+
* Creates a single `IntersectionObserver` instance and disposes it on unmount.
|
|
448
|
+
*
|
|
449
|
+
* @param callback Observer callback invoked for intersection changes.
|
|
450
|
+
* @param options Optional observer configuration.
|
|
451
|
+
* @returns Stable `IntersectionObserver` instance.
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```ts
|
|
455
|
+
* const observer = useIntersectionObserver((entries) => {
|
|
456
|
+
* console.log(entries[0]?.isIntersecting);
|
|
457
|
+
* });
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
460
|
+
* @example
|
|
461
|
+
* ```ts
|
|
462
|
+
* const observer = useIntersectionObserver(handleIntersect, { threshold: 0.5 });
|
|
463
|
+
* observer.observe(element);
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
var useIntersectionObserver = (callback, options) => {
|
|
467
|
+
const [intersectionObserver] = (0, react.useState)(() => new IntersectionObserver(callback, options));
|
|
468
|
+
(0, react.useEffect)(() => {
|
|
469
|
+
return () => {
|
|
470
|
+
intersectionObserver.disconnect();
|
|
471
|
+
};
|
|
472
|
+
}, []);
|
|
473
|
+
return intersectionObserver;
|
|
474
|
+
};
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/react/hooks/use-last-defined-value.ts
|
|
477
|
+
/**
|
|
478
|
+
* Remembers and returns the last non-nullish value passed to the hook.
|
|
479
|
+
*
|
|
480
|
+
* @template T Value type.
|
|
481
|
+
* @param value Current value that may be `null` or `undefined`.
|
|
482
|
+
* @returns Current value when defined, otherwise the previous defined value.
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```ts
|
|
486
|
+
* const title = useLastDefinedValue(props.title);
|
|
487
|
+
* ```
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* ```ts
|
|
491
|
+
* const user = useLastDefinedValue<User | null>(selectedUser);
|
|
492
|
+
* ```
|
|
493
|
+
*/
|
|
494
|
+
var useLastDefinedValue = (value) => {
|
|
495
|
+
const ref = (0, react.useRef)(value);
|
|
496
|
+
if (value != null) ref.current = value;
|
|
497
|
+
return ref.current;
|
|
498
|
+
};
|
|
499
|
+
//#endregion
|
|
500
|
+
//#region src/react/hooks/use-last-value-ref.ts
|
|
501
|
+
/**
|
|
502
|
+
* Returns a ref that always points to the last non-nullish value.
|
|
503
|
+
*
|
|
504
|
+
* @template T Value type.
|
|
505
|
+
* @param value Current value that may temporarily become `null` or `undefined`.
|
|
506
|
+
* @returns Ref containing the last defined value.
|
|
507
|
+
*
|
|
508
|
+
* @example
|
|
509
|
+
* ```ts
|
|
510
|
+
* const latestUserRef = useLastValueRef(user);
|
|
511
|
+
* latestUserRef.current;
|
|
512
|
+
* ```
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* ```ts
|
|
516
|
+
* const latestNodeRef = useLastValueRef<HTMLDivElement | null>(node);
|
|
517
|
+
* ```
|
|
518
|
+
*/
|
|
519
|
+
var useLastValueRef = (value) => {
|
|
520
|
+
const ref = (0, react.useRef)(value);
|
|
521
|
+
if (value != null) ref.current = value;
|
|
522
|
+
return ref;
|
|
523
|
+
};
|
|
524
|
+
//#endregion
|
|
525
|
+
//#region src/react/hooks/use-life-cycle.ts
|
|
526
|
+
/**
|
|
527
|
+
* Runs mount and unmount callbacks returned by a factory function.
|
|
528
|
+
*
|
|
529
|
+
* The latest factory is stored in a ref, while the effect itself is only
|
|
530
|
+
* subscribed once.
|
|
531
|
+
*
|
|
532
|
+
* @param fn Factory returning optional `mount` and `unmount` handlers.
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* ```ts
|
|
536
|
+
* useLifeCycle(() => ({
|
|
537
|
+
* mount: () => console.log('mounted'),
|
|
538
|
+
* unmount: () => console.log('unmounted'),
|
|
539
|
+
* }));
|
|
540
|
+
* ```
|
|
541
|
+
*
|
|
542
|
+
* @example
|
|
543
|
+
* ```ts
|
|
544
|
+
* useLifeCycle(() => ({
|
|
545
|
+
* mount: subscribe,
|
|
546
|
+
* unmount: unsubscribe,
|
|
547
|
+
* }));
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
var useLifeCycle = (fn) => {
|
|
551
|
+
const fnRef = useSyncRef(fn);
|
|
552
|
+
(0, react.useEffect)(() => {
|
|
553
|
+
const fnOperation = fnRef.current();
|
|
554
|
+
fnOperation.mount?.();
|
|
555
|
+
return fnOperation.unmount?.();
|
|
556
|
+
}, []);
|
|
557
|
+
};
|
|
558
|
+
//#endregion
|
|
559
|
+
//#region src/react/hooks/use-resize-observer.ts
|
|
560
|
+
/**
|
|
561
|
+
* Creates a stable `ResizeObserver` instance and disconnects it on unmount.
|
|
562
|
+
*
|
|
563
|
+
* @param callback Resize observer callback.
|
|
564
|
+
* @returns Ref containing the observer instance.
|
|
565
|
+
*
|
|
566
|
+
* @example
|
|
567
|
+
* ```ts
|
|
568
|
+
* const observerRef = useResizeObserver((entries) => {
|
|
569
|
+
* console.log(entries[0]?.contentRect.width);
|
|
570
|
+
* });
|
|
571
|
+
* ```
|
|
572
|
+
*
|
|
573
|
+
* @example
|
|
574
|
+
* ```ts
|
|
575
|
+
* const resizeObserver = useResizeObserver(handleResize);
|
|
576
|
+
* resizeObserver.current.observe(element);
|
|
577
|
+
* ```
|
|
578
|
+
*/
|
|
579
|
+
var useResizeObserver = (callback) => {
|
|
580
|
+
const resizeObserverRef = useDefineRef(() => new ResizeObserver(callback));
|
|
581
|
+
(0, react.useLayoutEffect)(() => {
|
|
582
|
+
return () => {
|
|
583
|
+
resizeObserverRef.current.disconnect();
|
|
584
|
+
};
|
|
585
|
+
}, []);
|
|
586
|
+
return resizeObserverRef;
|
|
587
|
+
};
|
|
588
|
+
//#endregion
|
|
589
|
+
//#region src/react/hooks/use-toggle.ts
|
|
590
|
+
/**
|
|
591
|
+
* Manages a boolean state and returns helpers to toggle or set it directly.
|
|
592
|
+
*
|
|
593
|
+
* @param initialState Initial boolean value.
|
|
594
|
+
* @returns Tuple with current state, toggle callback and raw setter.
|
|
595
|
+
*
|
|
596
|
+
* @example
|
|
597
|
+
* ```ts
|
|
598
|
+
* const [open, toggleOpen] = useToggle();
|
|
599
|
+
* toggleOpen();
|
|
600
|
+
* ```
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* ```ts
|
|
604
|
+
* const [enabled, , setEnabled] = useToggle(true);
|
|
605
|
+
* setEnabled(false);
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
var useToggle = (initialState) => {
|
|
609
|
+
const [toggled, setToggled] = (0, react.useState)(!!initialState);
|
|
610
|
+
return [
|
|
611
|
+
toggled,
|
|
612
|
+
(0, react.useCallback)(() => setToggled((toggled) => !toggled), []),
|
|
613
|
+
setToggled
|
|
614
|
+
];
|
|
615
|
+
};
|
|
616
|
+
//#endregion
|
|
617
|
+
//#region src/react/hooks/use-value.ts
|
|
618
|
+
/**
|
|
619
|
+
* Wraps `useState` and returns the state value as an object with a `set` method.
|
|
620
|
+
*
|
|
621
|
+
* @template T State value type.
|
|
622
|
+
* @param defaults Initial state value or lazy initializer.
|
|
623
|
+
* @returns Object containing the current value and setter.
|
|
624
|
+
*
|
|
625
|
+
* @example
|
|
626
|
+
* ```ts
|
|
627
|
+
* const counter = useValue(0);
|
|
628
|
+
* counter.set(1);
|
|
629
|
+
* ```
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```ts
|
|
633
|
+
* const user = useValue(() => ({ name: 'Ann' }));
|
|
634
|
+
* user.value.name;
|
|
635
|
+
* ```
|
|
636
|
+
*/
|
|
637
|
+
var useValue = (defaults) => {
|
|
638
|
+
const [value, setValue] = (0, react.useState)(defaults);
|
|
639
|
+
return {
|
|
640
|
+
value,
|
|
641
|
+
set: setValue
|
|
642
|
+
};
|
|
643
|
+
};
|
|
644
|
+
//#endregion
|
|
645
|
+
//#region src/react/hooks/use-visibility-state.ts
|
|
646
|
+
/**
|
|
647
|
+
* Tracks `document.visibilityState` and updates when the page visibility changes.
|
|
648
|
+
*
|
|
649
|
+
* @returns Current document visibility state.
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* ```ts
|
|
653
|
+
* const visibility = useVisibilityState();
|
|
654
|
+
* ```
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```ts
|
|
658
|
+
* const isHidden = useVisibilityState() === 'hidden';
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
var useVisibilityState = () => {
|
|
662
|
+
const [state, setState] = (0, react.useState)();
|
|
663
|
+
(0, react.useEffect)(() => {
|
|
664
|
+
const handleVisibilityChange = () => {
|
|
665
|
+
setState(document.visibilityState);
|
|
666
|
+
};
|
|
667
|
+
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
668
|
+
return () => {
|
|
669
|
+
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
670
|
+
};
|
|
671
|
+
}, []);
|
|
672
|
+
return state;
|
|
673
|
+
};
|
|
674
|
+
//#endregion
|
|
217
675
|
exports.attachRefs = attachRefs;
|
|
218
676
|
exports.createUseInstanceHook = createUseInstanceHook;
|
|
219
677
|
exports.useAbortController = useAbortController;
|
|
@@ -237,4 +695,5 @@ exports.useSyncRef = useSyncRef;
|
|
|
237
695
|
exports.useToggle = useToggle;
|
|
238
696
|
exports.useValue = useValue;
|
|
239
697
|
exports.useVisibilityState = useVisibilityState;
|
|
240
|
-
|
|
698
|
+
|
|
699
|
+
//# sourceMappingURL=react.cjs.map
|