@plurid/plurid-functions-react 0.0.0-5 → 0.0.0-6

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.
@@ -1,318 +1,259 @@
1
- 'use strict';
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
19
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
20
+ // source/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createMarkup: () => createMarkup_default,
24
+ mergeReferences: () => mergeReferences_default,
25
+ useDebouncedCallback: () => debounce_default,
26
+ useElementEvent: () => useElementEvent,
27
+ useFalseAfterTimedTrue: () => useFalseAfterTimedTrue,
28
+ useGlobalKeyDown: () => useGlobalKeyDown,
29
+ useGlobalWheel: () => useGlobalWheel,
30
+ useMounted: () => useMounted,
31
+ usePortal: () => portal_default,
32
+ useThrottledCallback: () => throttle_default,
33
+ useWindowEvent: () => useWindowEvent
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
4
36
 
5
- var react = require('react');
37
+ // source/hooks/event/index.ts
38
+ var import_react = require("react");
39
+ var useWindowEvent = (event, callback) => {
40
+ (0, import_react.useEffect)(() => {
41
+ if (typeof window === "undefined") {
42
+ return;
43
+ }
44
+ window.addEventListener(event, callback, { passive: false });
45
+ return () => {
46
+ if (typeof window === "undefined") {
47
+ return;
48
+ }
49
+ window.removeEventListener(event, callback);
50
+ };
51
+ }, [
52
+ event,
53
+ callback
54
+ ]);
55
+ };
56
+ var useElementEvent = (event, element, callback) => {
57
+ (0, import_react.useEffect)(() => {
58
+ if (element) {
59
+ element.addEventListener(event, callback, { passive: false });
60
+ }
61
+ return () => element.removeEventListener(event, callback);
62
+ }, [event, callback]);
63
+ };
64
+ var useGlobalKeyDown = (callback, element) => {
65
+ return useElementEvent(
66
+ "keydown",
67
+ element,
68
+ callback
69
+ );
70
+ };
71
+ var useGlobalWheel = (callback, element) => {
72
+ return useElementEvent(
73
+ "wheel",
74
+ element,
75
+ callback
76
+ );
77
+ };
6
78
 
7
- // #region imports
8
- // #endregion imports
9
- // #region module
10
- const useWindowEvent = (event, callback) => {
11
- react.useEffect(() => {
12
- if (typeof window === 'undefined') {
13
- return;
14
- }
15
- window.addEventListener(event, callback, { passive: false });
16
- return () => {
17
- if (typeof window === 'undefined') {
18
- return;
19
- }
20
- window.removeEventListener(event, callback);
21
- };
22
- }, [
23
- event,
24
- callback,
25
- ]);
26
- };
27
- const useElementEvent = (event, element, callback) => {
28
- react.useEffect(() => {
29
- if (element) {
30
- element.addEventListener(event, callback, { passive: false });
31
- }
32
- return () => element.removeEventListener(event, callback);
33
- }, [event, callback]);
34
- };
35
- const useGlobalKeyDown = (callback, element) => {
36
- // if (!element) {
37
- // return useWindowEvent('keydown', callback);
38
- // }
39
- return useElementEvent('keydown', element, callback);
40
- };
41
- const useGlobalWheel = (callback, element) => {
42
- // if (!element) {
43
- // return useWindowEvent('wheel', callback);
44
- // }
45
- return useElementEvent('wheel', element, callback);
46
- };
47
- // #endregion module
79
+ // source/hooks/debounce/index.ts
80
+ var import_react2 = require("react");
81
+ function useDebouncedCallback(callback, wait) {
82
+ const argsRef = (0, import_react2.useRef)();
83
+ const timeout = (0, import_react2.useRef)();
84
+ function cleanup() {
85
+ if (timeout.current) {
86
+ clearTimeout(timeout.current);
87
+ }
88
+ }
89
+ (0, import_react2.useEffect)(() => cleanup, []);
90
+ return function debouncedCallback(...args) {
91
+ argsRef.current = args;
92
+ cleanup();
93
+ timeout.current = setTimeout(() => {
94
+ if (argsRef.current) {
95
+ callback(...argsRef.current);
96
+ }
97
+ }, wait);
98
+ };
99
+ }
100
+ var debounce_default = useDebouncedCallback;
48
101
 
49
- // #region imports
50
- // #endregion imports
51
- // #region module
52
- /**
53
- * Source: https://stackoverflow.com/a/57335271
54
- *
55
- * @param callback Function to be called.
56
- * @param wait Debounce time.
57
- */
58
- function useDebouncedCallback(callback, wait) {
59
- // track args & timeout handle between calls
60
- const argsRef = react.useRef();
61
- const timeout = react.useRef();
62
- function cleanup() {
63
- if (timeout.current) {
64
- clearTimeout(timeout.current);
65
- }
66
- }
67
- // make sure our timeout gets cleared if
68
- // our consuming component gets unmounted
69
- react.useEffect(() => cleanup, []);
70
- return function debouncedCallback(...args) {
71
- // capture latest args
72
- argsRef.current = args;
73
- // clear debounce timer
74
- cleanup();
75
- // start waiting again
76
- timeout.current = setTimeout(() => {
77
- if (argsRef.current) {
78
- callback(...argsRef.current);
79
- }
80
- }, wait);
81
- };
82
- }
83
- // #endregion exports
102
+ // source/hooks/throttle/index.ts
103
+ var import_react3 = require("react");
104
+ var useThrottledCallback = (callback, delay) => {
105
+ const lastRan = (0, import_react3.useRef)(Date.now());
106
+ const argsRef = (0, import_react3.useRef)();
107
+ const timeout = (0, import_react3.useRef)();
108
+ const cleanup = () => {
109
+ if (timeout.current) {
110
+ clearTimeout(timeout.current);
111
+ }
112
+ };
113
+ (0, import_react3.useEffect)(() => cleanup, []);
114
+ return (...args) => {
115
+ argsRef.current = args;
116
+ timeout.current = setTimeout(
117
+ () => {
118
+ if (Date.now() - lastRan.current >= delay) {
119
+ if (argsRef.current) {
120
+ callback(...argsRef.current);
121
+ }
122
+ lastRan.current = Date.now();
123
+ }
124
+ },
125
+ delay - (Date.now() - lastRan.current)
126
+ );
127
+ };
128
+ };
129
+ var throttle_default = useThrottledCallback;
84
130
 
85
- // #region imports
86
- // #endregion imports
87
- // #region module
88
- /**
89
- * @param callback
90
- * @param delay
91
- */
92
- const useThrottledCallback = (callback, delay) => {
93
- // track args & timeout handle between calls
94
- const lastRan = react.useRef(Date.now());
95
- const argsRef = react.useRef();
96
- const timeout = react.useRef();
97
- const cleanup = () => {
98
- if (timeout.current) {
99
- clearTimeout(timeout.current);
100
- }
101
- };
102
- react.useEffect(() => cleanup, []);
103
- return (...args) => {
104
- argsRef.current = args;
105
- timeout.current = setTimeout(() => {
106
- if (Date.now() - lastRan.current >= delay) {
107
- if (argsRef.current) {
108
- callback(...argsRef.current);
109
- }
110
- lastRan.current = Date.now();
111
- }
112
- }, delay - (Date.now() - lastRan.current));
113
- };
114
- };
115
- // #endregion exports
131
+ // source/hooks/portal/index.tsx
132
+ var import_react4 = require("react");
133
+ var createRootElement = (id) => {
134
+ const rootContainer = document.createElement("div");
135
+ rootContainer.setAttribute("id", id);
136
+ return rootContainer;
137
+ };
138
+ var addRootElement = (rootElement, parentID) => {
139
+ const parent = document.getElementById(parentID);
140
+ if (parent) {
141
+ parent.appendChild(rootElement);
142
+ }
143
+ };
144
+ var usePortal = (id, parentID) => {
145
+ const rootElemRef = (0, import_react4.useRef)(null);
146
+ (0, import_react4.useEffect)(() => {
147
+ const existingParent = document.querySelector(`#${id}`);
148
+ const parentElem = existingParent || createRootElement(id);
149
+ if (!existingParent) {
150
+ addRootElement(parentElem, parentID);
151
+ }
152
+ if (rootElemRef.current) {
153
+ parentElem.appendChild(rootElemRef.current);
154
+ }
155
+ return () => {
156
+ if (rootElemRef.current) {
157
+ rootElemRef.current.remove();
158
+ }
159
+ if (parentElem.childNodes.length === -1) {
160
+ parentElem.remove();
161
+ }
162
+ };
163
+ }, []);
164
+ const getRootElem = () => {
165
+ if (!rootElemRef.current) {
166
+ rootElemRef.current = document.createElement("div");
167
+ }
168
+ return rootElemRef.current;
169
+ };
170
+ return getRootElem();
171
+ };
172
+ var portal_default = usePortal;
116
173
 
117
- /**
118
- * Based on
119
- * https://www.jayfreestone.com/writing/react-portals-with-hooks/
120
- *
121
- */
122
- // #endregion imports
123
- // #region module
124
- const createRootElement = (id) => {
125
- const rootContainer = document.createElement('div');
126
- rootContainer.setAttribute('id', id);
127
- return rootContainer;
128
- };
129
- /**
130
- * Appends element as last child of body.
131
- *
132
- * @param rootElement
133
- */
134
- const addRootElement = (rootElement, parentID) => {
135
- const parent = document.getElementById(parentID);
136
- if (parent) {
137
- parent.appendChild(rootElement);
138
- }
139
- };
140
- /**
141
- * Hook to create a React Portal.
142
- * Automatically handles creating and tearing-down the root elements (no SRR
143
- * makes this trivial), so there is no need to ensure the parent target already
144
- * exists.
145
- * @example
146
- * const target = usePortal(id, [id]);
147
- * return createPortal(children, target);
148
- *
149
- * @param id The id of the target container, e.g 'modal' or 'spotlight'
150
- * @returns The DOM node to use as the Portal target.
151
- */
152
- const usePortal = (id, parentID) => {
153
- const rootElemRef = react.useRef(null);
154
- react.useEffect(() => {
155
- // Look for existing target dom element to append to
156
- const existingParent = document.querySelector(`#${id}`);
157
- // Parent is either a new root or the existing dom element
158
- const parentElem = existingParent || createRootElement(id);
159
- // If there is no existing DOM element, add a new one.
160
- if (!existingParent) {
161
- addRootElement(parentElem, parentID);
162
- }
163
- // Add the detached element to the parent
164
- if (rootElemRef.current) {
165
- parentElem.appendChild(rootElemRef.current);
166
- }
167
- return () => {
168
- if (rootElemRef.current) {
169
- rootElemRef.current.remove();
170
- }
171
- if (parentElem.childNodes.length === -1) {
172
- parentElem.remove();
173
- }
174
- };
175
- }, []);
176
- /**
177
- * It's important we evaluate this lazily:
178
- * - We need first render to contain the DOM element, so it shouldn't happen
179
- * in useEffect. We would normally put this in the constructor().
180
- * - We can't do 'const rootElemRef = useRef(document.createElement('div))',
181
- * since this will run every single render (that's a lot).
182
- * - We want the ref to consistently point to the same DOM element and only
183
- * ever run once.
184
- * @link https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily
185
- */
186
- const getRootElem = () => {
187
- if (!rootElemRef.current) {
188
- rootElemRef.current = document.createElement('div');
189
- }
190
- return rootElemRef.current;
191
- };
192
- return getRootElem();
193
- };
194
- // #endregion exports
174
+ // source/hooks/general/index.ts
175
+ var import_react5 = require("react");
176
+ var useFalseAfterTimedTrue = (intervalTime = 2e3) => {
177
+ const mounted = useMounted();
178
+ const [
179
+ disabledAfterActivation,
180
+ setDisabledAfterActivation
181
+ ] = (0, import_react5.useState)(false);
182
+ (0, import_react5.useEffect)(() => {
183
+ let timeout;
184
+ if (disabledAfterActivation) {
185
+ timeout = setTimeout(() => {
186
+ if (!mounted) {
187
+ return;
188
+ }
189
+ setDisabledAfterActivation(false);
190
+ }, intervalTime);
191
+ }
192
+ return () => {
193
+ if (timeout) {
194
+ clearTimeout(timeout);
195
+ timeout = void 0;
196
+ }
197
+ };
198
+ }, [
199
+ disabledAfterActivation
200
+ ]);
201
+ return [
202
+ disabledAfterActivation,
203
+ setDisabledAfterActivation
204
+ ];
205
+ };
206
+ var useMounted = () => {
207
+ const isMounted = (0, import_react5.useRef)(false);
208
+ (0, import_react5.useEffect)(() => {
209
+ isMounted.current = true;
210
+ return () => {
211
+ isMounted.current = false;
212
+ };
213
+ }, []);
214
+ return isMounted.current;
215
+ };
195
216
 
196
- // #region imports
197
- // #endregion libraries
198
- // #region imports
199
- // #region module
200
- /**
201
- * After a `true` dispatch, it will wait the `intervalTime` and autoset to `false`.
202
- *
203
- * @param intervalTime
204
- * @returns
205
- */
206
- const useFalseAfterTimedTrue = (intervalTime = 2000) => {
207
- // #region references
208
- const mounted = useMounted();
209
- // #endregion references
210
- // #region state
211
- const [disabledAfterActivation, setDisabledAfterActivation,] = react.useState(false);
212
- // #endregion state
213
- // #region effects
214
- react.useEffect(() => {
215
- let timeout;
216
- if (disabledAfterActivation) {
217
- timeout = setTimeout(() => {
218
- if (!mounted) {
219
- return;
220
- }
221
- setDisabledAfterActivation(false);
222
- }, intervalTime);
223
- }
224
- return () => {
225
- if (timeout) {
226
- clearTimeout(timeout);
227
- timeout = undefined;
228
- }
229
- };
230
- }, [
231
- disabledAfterActivation,
232
- ]);
233
- // #endregion effects
234
- // #region return
235
- return [
236
- disabledAfterActivation,
237
- setDisabledAfterActivation,
238
- ];
239
- // #endregion return
240
- };
241
- /**
242
- * Keeps reference of the current mounted component.
243
- *
244
- * @returns
245
- */
246
- const useMounted = () => {
247
- // #region references
248
- const isMounted = react.useRef(false);
249
- // #endregion references
250
- // #region effects
251
- react.useEffect(() => {
252
- isMounted.current = true;
253
- return () => {
254
- isMounted.current = false;
255
- };
256
- }, []);
257
- // #endregion effects
258
- // #region return
259
- return isMounted.current;
260
- // #endregion return
261
- };
262
- // #endregion exports
217
+ // source/utilities/createMarkup/index.ts
218
+ var createMarkup = (text) => {
219
+ return {
220
+ __html: text
221
+ };
222
+ };
223
+ var createMarkup_default = createMarkup;
263
224
 
264
- // #region module
265
- const createMarkup = (text) => {
266
- return {
267
- __html: text,
268
- };
269
- };
270
- // #endregion exports
271
-
272
- // #region module
273
- /**
274
- * Merges multiple references into one `ref` attribute.
275
- *
276
- * ``` jsx
277
- * <SomeComponent
278
- * ref={merge(ref1, ref2)}
279
- * />
280
- * ```
281
- *
282
- * Source: https://www.davedrinks.coffee/how-do-i-use-two-react-refs/
283
- *
284
- * @param refs
285
- */
286
- const mergeReferences = (...refs) => {
287
- const filteredRefs = refs.filter(Boolean);
288
- if (!filteredRefs.length) {
289
- return null;
290
- }
291
- if (filteredRefs.length === 1) {
292
- return filteredRefs[0];
293
- }
294
- return (inst) => {
295
- for (const ref of filteredRefs) {
296
- if (typeof ref === 'function') {
297
- ref(inst);
298
- }
299
- else if (ref) {
300
- ref.current = inst;
301
- }
302
- }
303
- };
304
- };
305
- // #endregion exports
306
-
307
- exports.createMarkup = createMarkup;
308
- exports.mergeReferences = mergeReferences;
309
- exports.useDebouncedCallback = useDebouncedCallback;
310
- exports.useElementEvent = useElementEvent;
311
- exports.useFalseAfterTimedTrue = useFalseAfterTimedTrue;
312
- exports.useGlobalKeyDown = useGlobalKeyDown;
313
- exports.useGlobalWheel = useGlobalWheel;
314
- exports.useMounted = useMounted;
315
- exports.usePortal = usePortal;
316
- exports.useThrottledCallback = useThrottledCallback;
317
- exports.useWindowEvent = useWindowEvent;
318
- //# sourceMappingURL=index.js.map
225
+ // source/utilities/mergeReferences/index.ts
226
+ var mergeReferences = (...refs) => {
227
+ const filteredRefs = refs.filter(Boolean);
228
+ if (!filteredRefs.length) {
229
+ return null;
230
+ }
231
+ if (filteredRefs.length === 1) {
232
+ return filteredRefs[0];
233
+ }
234
+ return (inst) => {
235
+ for (const ref of filteredRefs) {
236
+ if (typeof ref === "function") {
237
+ ref(inst);
238
+ } else if (ref) {
239
+ ref.current = inst;
240
+ }
241
+ }
242
+ };
243
+ };
244
+ var mergeReferences_default = mergeReferences;
245
+ // Annotate the CommonJS export names for ESM import in node:
246
+ 0 && (module.exports = {
247
+ createMarkup,
248
+ mergeReferences,
249
+ useDebouncedCallback,
250
+ useElementEvent,
251
+ useFalseAfterTimedTrue,
252
+ useGlobalKeyDown,
253
+ useGlobalWheel,
254
+ useMounted,
255
+ usePortal,
256
+ useThrottledCallback,
257
+ useWindowEvent
258
+ });
259
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../source/hooks/event/index.ts","../source/hooks/debounce/index.ts","../source/hooks/throttle/index.ts","../source/hooks/portal/index.tsx","../source/hooks/general/index.ts","../source/utilities/createMarkup/index.ts","../source/utilities/mergeReferences/index.ts"],"sourcesContent":["// #region imports\nimport {\n useEffect,\n} from 'react';\n// #endregion imports\n\n\n\n// #region module\nexport const useWindowEvent = (\n event: any,\n callback: any,\n) => {\n useEffect(() => {\n if (typeof window === 'undefined') {\n return;\n }\n window.addEventListener(event, callback, { passive: false });\n\n return () => {\n if (typeof window === 'undefined') {\n return;\n }\n window.removeEventListener(event, callback);\n }\n }, [\n event,\n callback,\n ]);\n};\n\n\nexport const useElementEvent = (\n event: any,\n element: any,\n callback: any,\n) => {\n useEffect(() => {\n if (element) {\n element.addEventListener(event, callback, { passive: false });\n }\n return () => element.removeEventListener(event, callback);\n }, [event, callback]);\n}\n\nexport const useGlobalKeyDown = (\n callback: any,\n element?: any,\n) => {\n // if (!element) {\n // return useWindowEvent('keydown', callback);\n // }\n\n return useElementEvent(\n 'keydown',\n element,\n callback,\n );\n}\n\nexport const useGlobalWheel = (\n callback: any,\n element?: any,\n) => {\n // if (!element) {\n // return useWindowEvent('wheel', callback);\n // }\n\n return useElementEvent(\n 'wheel',\n element,\n callback,\n );\n}\n// #endregion module\n","// #region imports\nimport {\n useRef,\n useEffect,\n} from 'react';\n// #endregion imports\n\n\n\n// #region module\n/**\n * Source: https://stackoverflow.com/a/57335271\n *\n * @param callback Function to be called.\n * @param wait Debounce time.\n */\nfunction useDebouncedCallback<A extends any[]>(\n callback: (...args: A) => void,\n wait: number,\n) {\n // track args & timeout handle between calls\n const argsRef = useRef<A>();\n const timeout = useRef<ReturnType<typeof setTimeout>>();\n\n function cleanup() {\n if(timeout.current) {\n clearTimeout(timeout.current);\n }\n }\n\n // make sure our timeout gets cleared if\n // our consuming component gets unmounted\n useEffect(() => cleanup, []);\n\n return function debouncedCallback(\n ...args: A\n ) {\n // capture latest args\n argsRef.current = args;\n\n // clear debounce timer\n cleanup();\n\n // start waiting again\n timeout.current = setTimeout(() => {\n if(argsRef.current) {\n callback(...argsRef.current);\n }\n }, wait);\n };\n}\n// #endregion module\n\n\n\n// #region exports\nexport default useDebouncedCallback;\n// #endregion exports\n","// #region imports\nimport {\n useEffect,\n useRef,\n} from 'react';\n// #endregion imports\n\n\n\n// #region module\n/**\n * @param callback\n * @param delay\n */\nconst useThrottledCallback = <A extends any[]>(\n callback: (...args: A) => void,\n delay: number,\n) => {\n // track args & timeout handle between calls\n const lastRan = useRef(Date.now());\n const argsRef = useRef<A>();\n const timeout = useRef<ReturnType<typeof setTimeout>>();\n\n const cleanup = () => {\n if(timeout.current) {\n clearTimeout(timeout.current);\n }\n }\n\n useEffect(() => cleanup, []);\n\n return (\n ...args: A\n ) => {\n argsRef.current = args;\n\n timeout.current = setTimeout(\n () => {\n if (Date.now() - lastRan.current >= delay) {\n if(argsRef.current) {\n callback(...argsRef.current);\n }\n lastRan.current = Date.now();\n }\n },\n delay - (Date.now() - lastRan.current)\n );\n };\n}\n// #endregion module\n\n\n\n// #region exports\nexport default useThrottledCallback;\n// #endregion exports\n","/**\n * Based on\n * https://www.jayfreestone.com/writing/react-portals-with-hooks/\n *\n */\n\n\n// #region imports\nimport {\n useRef,\n useEffect,\n} from 'react';\n// #endregion imports\n\n\n\n// #region module\nconst createRootElement = (\n id: string,\n): Element => {\n const rootContainer = document.createElement('div');\n rootContainer.setAttribute('id', id);\n return rootContainer;\n}\n\n\n/**\n * Appends element as last child of body.\n *\n * @param rootElement\n */\nconst addRootElement = (\n rootElement: Element,\n parentID: string,\n) => {\n const parent = document.getElementById(parentID);\n\n if (parent) {\n parent.appendChild(rootElement);\n }\n}\n\n\n/**\n * Hook to create a React Portal.\n * Automatically handles creating and tearing-down the root elements (no SRR\n * makes this trivial), so there is no need to ensure the parent target already\n * exists.\n * @example\n * const target = usePortal(id, [id]);\n * return createPortal(children, target);\n *\n * @param id The id of the target container, e.g 'modal' or 'spotlight'\n * @returns The DOM node to use as the Portal target.\n */\nconst usePortal = (\n id: string,\n parentID: string,\n): any => {\n const rootElemRef = useRef<Element | null>(null);\n\n useEffect(() => {\n // Look for existing target dom element to append to\n const existingParent = document.querySelector(`#${id}`);\n // Parent is either a new root or the existing dom element\n const parentElem = existingParent || createRootElement(id);\n\n // If there is no existing DOM element, add a new one.\n if (!existingParent) {\n addRootElement(parentElem, parentID);\n }\n\n // Add the detached element to the parent\n if (rootElemRef.current) {\n parentElem.appendChild(rootElemRef.current);\n }\n\n return () => {\n if (rootElemRef.current) {\n rootElemRef.current.remove();\n }\n\n if (parentElem.childNodes.length === -1) {\n parentElem.remove();\n }\n };\n }, []);\n\n /**\n * It's important we evaluate this lazily:\n * - We need first render to contain the DOM element, so it shouldn't happen\n * in useEffect. We would normally put this in the constructor().\n * - We can't do 'const rootElemRef = useRef(document.createElement('div))',\n * since this will run every single render (that's a lot).\n * - We want the ref to consistently point to the same DOM element and only\n * ever run once.\n * @link https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily\n */\n const getRootElem = () => {\n if (!rootElemRef.current) {\n rootElemRef.current = document.createElement('div');\n }\n return rootElemRef.current;\n }\n\n return getRootElem();\n}\n// #endregion module\n\n\n\n// #region exports\nexport default usePortal;\n// #endregion exports\n","// #region imports\n // #region libraries\n import React, {\n useRef,\n useState,\n useEffect,\n } from 'react';\n // #endregion libraries\n// #region imports\n\n\n\n// #region module\n/**\n * After a `true` dispatch, it will wait the `intervalTime` and autoset to `false`.\n *\n * @param intervalTime\n * @returns\n */\nconst useFalseAfterTimedTrue = (\n intervalTime = 2_000, // ms\n): [boolean, React.Dispatch<React.SetStateAction<boolean>>] => {\n // #region references\n const mounted = useMounted();\n // #endregion references\n\n // #region state\n const [\n disabledAfterActivation,\n setDisabledAfterActivation,\n ] = useState(false);\n // #endregion state\n\n // #region effects\n useEffect(() => {\n let timeout: NodeJS.Timeout | undefined;\n\n if (disabledAfterActivation) {\n timeout = setTimeout(() => {\n if (!mounted) {\n return;\n }\n\n setDisabledAfterActivation(false);\n }, intervalTime);\n }\n\n return () => {\n if (timeout) {\n clearTimeout(timeout);\n timeout = undefined;\n }\n }\n }, [\n disabledAfterActivation,\n ]);\n // #endregion effects\n\n // #region return\n return [\n disabledAfterActivation,\n setDisabledAfterActivation,\n ];\n // #endregion return\n}\n\n\n/**\n * Keeps reference of the current mounted component.\n *\n * @returns\n */\nconst useMounted = () => {\n // #region references\n const isMounted = useRef(false);\n // #endregion references\n\n // #region effects\n useEffect(() => {\n isMounted.current = true;\n\n return () => {\n isMounted.current = false;\n }\n }, []);\n // #endregion effects\n\n // #region return\n return isMounted.current;\n // #endregion return\n}\n// #endregion module\n\n\n\n// #region exports\nexport {\n useFalseAfterTimedTrue,\n useMounted,\n};\n// #endregion exports\n","// #region module\nconst createMarkup = (\n text: string,\n) => {\n return {\n __html: text,\n };\n}\n// #endregion module\n\n\n\n// #region exports\nexport default createMarkup;\n// #endregion exports\n","// #region module\n/**\n * Merges multiple references into one `ref` attribute.\n *\n * ``` jsx\n * <SomeComponent\n * ref={merge(ref1, ref2)}\n * />\n * ```\n *\n * Source: https://www.davedrinks.coffee/how-do-i-use-two-react-refs/\n *\n * @param refs\n */\nconst mergeReferences = (\n ...refs: any[]\n) => {\n const filteredRefs = refs.filter(Boolean);\n\n if (!filteredRefs.length) {\n return null;\n }\n\n if (filteredRefs.length === 1) {\n return filteredRefs[0];\n }\n\n return (inst: any) => {\n for (const ref of filteredRefs) {\n if (typeof ref === 'function') {\n ref(inst);\n } else if (ref) {\n ref.current = inst;\n }\n }\n };\n};\n// #endregion module\n\n\n\n// #region exports\nexport default mergeReferences;\n// #endregion exports\n"],"names":["useEffect","useRef","useState"],"mappings":";;;;;;AAAA;AAIA;AAIA;MACa,cAAc,GAAG,CAC1B,KAAU,EACV,QAAa,KACb;IACAA,eAAS,CAAC,MAAK;AACX,QAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YAC/B,OAAO;AACV,SAAA;AACD,QAAA,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAE7D,QAAA,OAAO,MAAK;AACR,YAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;gBAC/B,OAAO;AACV,aAAA;AACD,YAAA,MAAM,CAAC,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AAChD,SAAC,CAAA;AACL,KAAC,EAAE;QACC,KAAK;QACL,QAAQ;AACX,KAAA,CAAC,CAAC;AACP,EAAE;AAGW,MAAA,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C,MAAK;AACX,QAAA,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC;AAEzB,QAAA,OAAO,MAAK;AACR,YAAA,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC;AAC9B,SAAC,CAAA;KACJ,EAAE,EAAE,CAAC,CAAC;;;IAIP,OAAO,SAAS,CAAC,OAAO,CAAC;;AAE7B,EAAC;AAUD;;ACpGA;AACA,MAAM,YAAY,GAAG,CACjB,IAAY,KACZ;IACA,OAAO;AACH,QAAA,MAAM,EAAE,IAAI;KACf,CAAC;AACN,EAAC;AAOD;;ACdA;AACA;;;;;;;;;;;;AAYG;AACH,MAAM,eAAe,GAAG,CACpB,GAAG,IAAW,KACd;IACA,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAE1C,IAAA,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;AACtB,QAAA,OAAO,IAAI,CAAC;AACf,KAAA;AAED,IAAA,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE;AAC3B,QAAA,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC;AAC1B,KAAA;IAED,OAAO,CAAC,IAAS,KAAI;AACjB,QAAA,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE;AAC5B,YAAA,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;gBAC3B,GAAG,CAAC,IAAI,CAAC,CAAC;AACb,aAAA;AAAM,iBAAA,IAAI,GAAG,EAAE;AACZ,gBAAA,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC;AACtB,aAAA;AACJ,SAAA;AACL,KAAC,CAAC;AACN,EAAE;AAOF;;;;;;;;;;;;;;"}
1
+ {"version":3,"sources":["../source/index.ts","../source/hooks/event/index.ts","../source/hooks/debounce/index.ts","../source/hooks/throttle/index.ts","../source/hooks/portal/index.tsx","../source/hooks/general/index.ts","../source/utilities/createMarkup/index.ts","../source/utilities/mergeReferences/index.ts"],"sourcesContent":["// #region exports\nexport * from './hooks';\nexport * from './utilities';\n// #endregion exports\n","// #region imports\nimport {\n useEffect,\n} from 'react';\n// #endregion imports\n\n\n\n// #region module\nexport const useWindowEvent = (\n event: any,\n callback: any,\n) => {\n useEffect(() => {\n if (typeof window === 'undefined') {\n return;\n }\n window.addEventListener(event, callback, { passive: false });\n\n return () => {\n if (typeof window === 'undefined') {\n return;\n }\n window.removeEventListener(event, callback);\n }\n }, [\n event,\n callback,\n ]);\n};\n\n\nexport const useElementEvent = (\n event: any,\n element: any,\n callback: any,\n) => {\n useEffect(() => {\n if (element) {\n element.addEventListener(event, callback, { passive: false });\n }\n return () => element.removeEventListener(event, callback);\n }, [event, callback]);\n}\n\nexport const useGlobalKeyDown = (\n callback: any,\n element?: any,\n) => {\n // if (!element) {\n // return useWindowEvent('keydown', callback);\n // }\n\n return useElementEvent(\n 'keydown',\n element,\n callback,\n );\n}\n\nexport const useGlobalWheel = (\n callback: any,\n element?: any,\n) => {\n // if (!element) {\n // return useWindowEvent('wheel', callback);\n // }\n\n return useElementEvent(\n 'wheel',\n element,\n callback,\n );\n}\n// #endregion module\n","// #region imports\nimport {\n useRef,\n useEffect,\n} from 'react';\n// #endregion imports\n\n\n\n// #region module\n/**\n * Source: https://stackoverflow.com/a/57335271\n *\n * @param callback Function to be called.\n * @param wait Debounce time.\n */\nfunction useDebouncedCallback<A extends any[]>(\n callback: (...args: A) => void,\n wait: number,\n) {\n // track args & timeout handle between calls\n const argsRef = useRef<A>();\n const timeout = useRef<ReturnType<typeof setTimeout>>();\n\n function cleanup() {\n if(timeout.current) {\n clearTimeout(timeout.current);\n }\n }\n\n // make sure our timeout gets cleared if\n // our consuming component gets unmounted\n useEffect(() => cleanup, []);\n\n return function debouncedCallback(\n ...args: A\n ) {\n // capture latest args\n argsRef.current = args;\n\n // clear debounce timer\n cleanup();\n\n // start waiting again\n timeout.current = setTimeout(() => {\n if(argsRef.current) {\n callback(...argsRef.current);\n }\n }, wait);\n };\n}\n// #endregion module\n\n\n\n// #region exports\nexport default useDebouncedCallback;\n// #endregion exports\n","// #region imports\nimport {\n useEffect,\n useRef,\n} from 'react';\n// #endregion imports\n\n\n\n// #region module\n/**\n * @param callback\n * @param delay\n */\nconst useThrottledCallback = <A extends any[]>(\n callback: (...args: A) => void,\n delay: number,\n) => {\n // track args & timeout handle between calls\n const lastRan = useRef(Date.now());\n const argsRef = useRef<A>();\n const timeout = useRef<ReturnType<typeof setTimeout>>();\n\n const cleanup = () => {\n if(timeout.current) {\n clearTimeout(timeout.current);\n }\n }\n\n useEffect(() => cleanup, []);\n\n return (\n ...args: A\n ) => {\n argsRef.current = args;\n\n timeout.current = setTimeout(\n () => {\n if (Date.now() - lastRan.current >= delay) {\n if(argsRef.current) {\n callback(...argsRef.current);\n }\n lastRan.current = Date.now();\n }\n },\n delay - (Date.now() - lastRan.current)\n );\n };\n}\n// #endregion module\n\n\n\n// #region exports\nexport default useThrottledCallback;\n// #endregion exports\n","/**\n * Based on\n * https://www.jayfreestone.com/writing/react-portals-with-hooks/\n *\n */\n\n\n// #region imports\nimport {\n useRef,\n useEffect,\n} from 'react';\n// #endregion imports\n\n\n\n// #region module\nconst createRootElement = (\n id: string,\n): Element => {\n const rootContainer = document.createElement('div');\n rootContainer.setAttribute('id', id);\n return rootContainer;\n}\n\n\n/**\n * Appends element as last child of body.\n *\n * @param rootElement\n */\nconst addRootElement = (\n rootElement: Element,\n parentID: string,\n) => {\n const parent = document.getElementById(parentID);\n\n if (parent) {\n parent.appendChild(rootElement);\n }\n}\n\n\n/**\n * Hook to create a React Portal.\n * Automatically handles creating and tearing-down the root elements (no SRR\n * makes this trivial), so there is no need to ensure the parent target already\n * exists.\n * @example\n * const target = usePortal(id, [id]);\n * return createPortal(children, target);\n *\n * @param id The id of the target container, e.g 'modal' or 'spotlight'\n * @returns The DOM node to use as the Portal target.\n */\nconst usePortal = (\n id: string,\n parentID: string,\n): any => {\n const rootElemRef = useRef<Element | null>(null);\n\n useEffect(() => {\n // Look for existing target dom element to append to\n const existingParent = document.querySelector(`#${id}`);\n // Parent is either a new root or the existing dom element\n const parentElem = existingParent || createRootElement(id);\n\n // If there is no existing DOM element, add a new one.\n if (!existingParent) {\n addRootElement(parentElem, parentID);\n }\n\n // Add the detached element to the parent\n if (rootElemRef.current) {\n parentElem.appendChild(rootElemRef.current);\n }\n\n return () => {\n if (rootElemRef.current) {\n rootElemRef.current.remove();\n }\n\n if (parentElem.childNodes.length === -1) {\n parentElem.remove();\n }\n };\n }, []);\n\n /**\n * It's important we evaluate this lazily:\n * - We need first render to contain the DOM element, so it shouldn't happen\n * in useEffect. We would normally put this in the constructor().\n * - We can't do 'const rootElemRef = useRef(document.createElement('div))',\n * since this will run every single render (that's a lot).\n * - We want the ref to consistently point to the same DOM element and only\n * ever run once.\n * @link https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily\n */\n const getRootElem = () => {\n if (!rootElemRef.current) {\n rootElemRef.current = document.createElement('div');\n }\n return rootElemRef.current;\n }\n\n return getRootElem();\n}\n// #endregion module\n\n\n\n// #region exports\nexport default usePortal;\n// #endregion exports\n","// #region imports\n // #region libraries\n import React, {\n useRef,\n useState,\n useEffect,\n } from 'react';\n // #endregion libraries\n// #region imports\n\n\n\n// #region module\n/**\n * After a `true` dispatch, it will wait the `intervalTime` and autoset to `false`.\n *\n * @param intervalTime\n * @returns\n */\nconst useFalseAfterTimedTrue = (\n intervalTime = 2_000, // ms\n): [boolean, React.Dispatch<React.SetStateAction<boolean>>] => {\n // #region references\n const mounted = useMounted();\n // #endregion references\n\n // #region state\n const [\n disabledAfterActivation,\n setDisabledAfterActivation,\n ] = useState(false);\n // #endregion state\n\n // #region effects\n useEffect(() => {\n // `ReturnType<typeof setTimeout>` (universal) instead of the Node-only `NodeJS.Timeout` — works in\n // both the browser (number) and Node without depending on @types/node being resolvable.\n let timeout: ReturnType<typeof setTimeout> | undefined;\n\n if (disabledAfterActivation) {\n timeout = setTimeout(() => {\n if (!mounted) {\n return;\n }\n\n setDisabledAfterActivation(false);\n }, intervalTime);\n }\n\n return () => {\n if (timeout) {\n clearTimeout(timeout);\n timeout = undefined;\n }\n }\n }, [\n disabledAfterActivation,\n ]);\n // #endregion effects\n\n // #region return\n return [\n disabledAfterActivation,\n setDisabledAfterActivation,\n ];\n // #endregion return\n}\n\n\n/**\n * Keeps reference of the current mounted component.\n *\n * @returns\n */\nconst useMounted = () => {\n // #region references\n const isMounted = useRef(false);\n // #endregion references\n\n // #region effects\n useEffect(() => {\n isMounted.current = true;\n\n return () => {\n isMounted.current = false;\n }\n }, []);\n // #endregion effects\n\n // #region return\n return isMounted.current;\n // #endregion return\n}\n// #endregion module\n\n\n\n// #region exports\nexport {\n useFalseAfterTimedTrue,\n useMounted,\n};\n// #endregion exports\n","// #region module\nconst createMarkup = (\n text: string,\n) => {\n return {\n __html: text,\n };\n}\n// #endregion module\n\n\n\n// #region exports\nexport default createMarkup;\n// #endregion exports\n","// #region module\n/**\n * Merges multiple references into one `ref` attribute.\n *\n * ``` jsx\n * <SomeComponent\n * ref={merge(ref1, ref2)}\n * />\n * ```\n *\n * Source: https://www.davedrinks.coffee/how-do-i-use-two-react-refs/\n *\n * @param refs\n */\nconst mergeReferences = (\n ...refs: any[]\n) => {\n const filteredRefs = refs.filter(Boolean);\n\n if (!filteredRefs.length) {\n return null;\n }\n\n if (filteredRefs.length === 1) {\n return filteredRefs[0];\n }\n\n return (inst: any) => {\n for (const ref of filteredRefs) {\n if (typeof ref === 'function') {\n ref(inst);\n } else if (ref) {\n ref.current = inst;\n }\n }\n };\n};\n// #endregion module\n\n\n\n// #region exports\nexport default mergeReferences;\n// #endregion exports\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,mBAEO;AAMA,IAAM,iBAAiB,CAC1B,OACA,aACC;AACD,8BAAU,MAAM;AACZ,QAAI,OAAO,WAAW,aAAa;AAC/B;AAAA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