@zayne-labs/toolkit-react 0.8.22
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/dist/esm/chunk-AHVBSEEO.js +462 -0
- package/dist/esm/chunk-AHVBSEEO.js.map +1 -0
- package/dist/esm/createCustomContext-b8lQCth3.d.ts +18 -0
- package/dist/esm/global-DMxqhOh1.d.ts +26 -0
- package/dist/esm/hooks/index.d.ts +192 -0
- package/dist/esm/hooks/index.js +3 -0
- package/dist/esm/hooks/index.js.map +1 -0
- package/dist/esm/utils/index.d.ts +31 -0
- package/dist/esm/utils/index.js +86 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/zustand/index.d.ts +20 -0
- package/dist/esm/zustand/index.js +29 -0
- package/dist/esm/zustand/index.js.map +1 -0
- package/package.json +111 -0
@@ -0,0 +1,462 @@
|
|
1
|
+
import { createContext, useRef, useLayoutEffect, useCallback, useEffect, useState, useSyncExternalStore, useDebugValue, useContext } from 'react';
|
2
|
+
import { on, setAnimationInterval, debounce, lockScroll, createLocationStore, isBrowser, createExternalStorageStore, throttleBySetTimeout, throttleByTime, throttleByFrame, copyToClipboard, createSearchParams } from '@zayne-labs/toolkit-core';
|
3
|
+
import { isArray, isPlainObject, isString, isFunction } from '@zayne-labs/toolkit-type-helpers';
|
4
|
+
|
5
|
+
// src/hooks/createCustomContext.ts
|
6
|
+
var ContextError = class extends Error {
|
7
|
+
name = "ContextError";
|
8
|
+
};
|
9
|
+
var getErrorMessage = (hook, provider) => {
|
10
|
+
return `${hook} returned "null". Did you forget to wrap the necessary components within ${provider}?`;
|
11
|
+
};
|
12
|
+
var createCustomContext = (options = {}) => {
|
13
|
+
const {
|
14
|
+
defaultValue = null,
|
15
|
+
errorMessage,
|
16
|
+
hookName = "Unnamed Context hook",
|
17
|
+
name = "Unnamed Context",
|
18
|
+
providerName = "Unnamed Provider",
|
19
|
+
strict = true
|
20
|
+
} = options;
|
21
|
+
const Context = createContext(defaultValue);
|
22
|
+
Context.displayName = name;
|
23
|
+
const useCustomContext = () => {
|
24
|
+
const contextValue = useContext(Context);
|
25
|
+
if (strict && contextValue === null) {
|
26
|
+
throw new ContextError(errorMessage ?? getErrorMessage(hookName, providerName));
|
27
|
+
}
|
28
|
+
return contextValue;
|
29
|
+
};
|
30
|
+
return [Context.Provider, useCustomContext];
|
31
|
+
};
|
32
|
+
var useCallbackRef = (callbackFn) => {
|
33
|
+
const callbackRef = useRef(callbackFn);
|
34
|
+
useLayoutEffect(() => {
|
35
|
+
callbackRef.current = callbackFn;
|
36
|
+
}, [callbackFn]);
|
37
|
+
const savedCallback = useCallback(
|
38
|
+
// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- callbackRef.current can be null in some cases
|
39
|
+
(...params) => callbackRef.current?.(...params),
|
40
|
+
[]
|
41
|
+
);
|
42
|
+
return savedCallback;
|
43
|
+
};
|
44
|
+
|
45
|
+
// src/hooks/effects/useAfterMountEffect.ts
|
46
|
+
var useAfterMountEffect = (callBackFn, deps) => {
|
47
|
+
const isFirstMount = useRef(true);
|
48
|
+
const stableCallback = useCallbackRef(callBackFn);
|
49
|
+
useEffect(() => {
|
50
|
+
if (isFirstMount.current) {
|
51
|
+
isFirstMount.current = false;
|
52
|
+
return;
|
53
|
+
}
|
54
|
+
stableCallback();
|
55
|
+
}, deps);
|
56
|
+
};
|
57
|
+
var useEffectOnce = (callBackFn) => {
|
58
|
+
const stableCallback = useCallbackRef(callBackFn);
|
59
|
+
const effectGuard = useRef(false);
|
60
|
+
useEffect(() => {
|
61
|
+
if (effectGuard.current) return;
|
62
|
+
effectGuard.current = true;
|
63
|
+
return stableCallback();
|
64
|
+
}, []);
|
65
|
+
};
|
66
|
+
var useLifeCycle = ({ onMount, onUnmount }) => {
|
67
|
+
const stableOnMount = useCallbackRef(onMount);
|
68
|
+
const stableOnUnmount = useCallbackRef(onUnmount);
|
69
|
+
useEffect(() => {
|
70
|
+
stableOnMount();
|
71
|
+
return stableOnUnmount;
|
72
|
+
}, []);
|
73
|
+
};
|
74
|
+
|
75
|
+
// src/hooks/effects/useOnMountEffect.ts
|
76
|
+
var useMountEffect = (callBackFn) => {
|
77
|
+
useLifeCycle({ onMount: callBackFn });
|
78
|
+
};
|
79
|
+
|
80
|
+
// src/hooks/effects/useOnUnMountEffect.ts
|
81
|
+
var useOnUnmountEffect = (cleanUpFn) => useLifeCycle({ onUnmount: cleanUpFn });
|
82
|
+
var removeClass = (target, className) => () => target.classList.remove(className);
|
83
|
+
var useAnimateElementRefs = (elementsInfoArray) => {
|
84
|
+
const elementsRef = useRef({});
|
85
|
+
const addAnimationClasses = useCallbackRef(() => {
|
86
|
+
if (!isArray(elementsInfoArray)) {
|
87
|
+
console.error("elementsInfo is not an Array");
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
for (const { animationClass, targetElement } of elementsInfoArray) {
|
91
|
+
if (!elementsRef.current[targetElement]) {
|
92
|
+
console.error("ElementError", `"${targetElement}" element does not exist`);
|
93
|
+
return;
|
94
|
+
}
|
95
|
+
elementsRef.current[targetElement].classList.add(animationClass);
|
96
|
+
}
|
97
|
+
});
|
98
|
+
const removeAnimationClasses = useCallbackRef(() => {
|
99
|
+
if (!isArray(elementsInfoArray)) {
|
100
|
+
console.error("elementsInfo is not an Array");
|
101
|
+
return;
|
102
|
+
}
|
103
|
+
for (const { animationClass, targetElement } of elementsInfoArray) {
|
104
|
+
if (!elementsRef.current[targetElement]) {
|
105
|
+
console.error("ElementError", `"${targetElement}" element does not exist`);
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
on(
|
109
|
+
"transitionend",
|
110
|
+
elementsRef.current[targetElement],
|
111
|
+
removeClass(elementsRef.current[targetElement], animationClass)
|
112
|
+
);
|
113
|
+
on(
|
114
|
+
"animationend",
|
115
|
+
elementsRef.current[targetElement],
|
116
|
+
removeClass(elementsRef.current[targetElement], animationClass)
|
117
|
+
);
|
118
|
+
}
|
119
|
+
});
|
120
|
+
const handleElementsAnimation = useCallback(() => {
|
121
|
+
addAnimationClasses();
|
122
|
+
removeAnimationClasses();
|
123
|
+
}, [addAnimationClasses, removeAnimationClasses]);
|
124
|
+
return { animatedElements: elementsRef.current, handleElementsAnimation };
|
125
|
+
};
|
126
|
+
var useConstant = (initCallbackFn) => useState(initCallbackFn)[0];
|
127
|
+
|
128
|
+
// src/hooks/useAnimationInterval.ts
|
129
|
+
var useAnimationInterval = (options) => {
|
130
|
+
const { intervalDuration, onAnimation, once } = options;
|
131
|
+
const latestCallback = useCallbackRef(onAnimation);
|
132
|
+
const { start, stop } = useConstant(() => setAnimationInterval(latestCallback, intervalDuration, { once }));
|
133
|
+
useEffect(() => {
|
134
|
+
if (intervalDuration === null) return;
|
135
|
+
start();
|
136
|
+
return stop;
|
137
|
+
}, [intervalDuration]);
|
138
|
+
return { start, stop };
|
139
|
+
};
|
140
|
+
var useCopyToClipboard = () => {
|
141
|
+
const [state, setState] = useState("");
|
142
|
+
const handleCopy = (value) => {
|
143
|
+
setState(value);
|
144
|
+
void copyToClipboard(value);
|
145
|
+
};
|
146
|
+
return { copiedValue: state, handleCopy };
|
147
|
+
};
|
148
|
+
var useDebouncedFn = (callBackFn, delay) => {
|
149
|
+
const latestCallback = useCallbackRef(callBackFn);
|
150
|
+
const debouncedFn = useConstant(() => debounce(latestCallback, delay));
|
151
|
+
useOnUnmountEffect(() => {
|
152
|
+
debouncedFn.cancel();
|
153
|
+
debouncedFn.cancelMaxWait();
|
154
|
+
});
|
155
|
+
return debouncedFn;
|
156
|
+
};
|
157
|
+
var useDebouncedState = (defaultValue, delay) => {
|
158
|
+
const [value, setValue] = useState(defaultValue);
|
159
|
+
const setDebouncedValue = useConstant(() => debounce(setValue, delay));
|
160
|
+
useOnUnmountEffect(() => {
|
161
|
+
setDebouncedValue.cancel();
|
162
|
+
setDebouncedValue.cancelMaxWait();
|
163
|
+
});
|
164
|
+
return [value, setDebouncedValue, setValue];
|
165
|
+
};
|
166
|
+
var useToggle = (initialValue = false) => {
|
167
|
+
const [value, setValue] = useState(initialValue);
|
168
|
+
const toggle = useCallback((newValue) => {
|
169
|
+
if (typeof newValue === "boolean") {
|
170
|
+
setValue(newValue);
|
171
|
+
return;
|
172
|
+
}
|
173
|
+
setValue((prev) => !prev);
|
174
|
+
}, []);
|
175
|
+
return [value, toggle];
|
176
|
+
};
|
177
|
+
|
178
|
+
// src/hooks/useDisclosure.ts
|
179
|
+
var useDisclosure = (options = {}) => {
|
180
|
+
const { hasScrollControl = false, initialState = false } = options;
|
181
|
+
const [isOpen, toggleIsOpen] = useToggle(initialState);
|
182
|
+
const handleScrollControl = useCallbackRef(
|
183
|
+
(state) => hasScrollControl && lockScroll({ isActive: state })
|
184
|
+
);
|
185
|
+
const onOpen = useCallbackRef((value) => {
|
186
|
+
const booleanValue = typeof value === "boolean" && value ? value : true;
|
187
|
+
toggleIsOpen(booleanValue);
|
188
|
+
handleScrollControl(booleanValue);
|
189
|
+
});
|
190
|
+
const onClose = useCallbackRef((value) => {
|
191
|
+
const booleanValue = typeof value === "boolean" && !value ? value : false;
|
192
|
+
toggleIsOpen(booleanValue);
|
193
|
+
handleScrollControl(booleanValue);
|
194
|
+
});
|
195
|
+
const onToggle = useCallbackRef((value) => {
|
196
|
+
if (typeof value === "boolean") {
|
197
|
+
value ? onOpen(value) : onClose(value);
|
198
|
+
return;
|
199
|
+
}
|
200
|
+
isOpen ? onClose() : onOpen();
|
201
|
+
});
|
202
|
+
return { isOpen, onClose, onOpen, onToggle };
|
203
|
+
};
|
204
|
+
var noopStore = {
|
205
|
+
getServerSnapshot: () => true,
|
206
|
+
getSnapshot: () => false,
|
207
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping -- It's fine
|
208
|
+
subscribe: () => () => {
|
209
|
+
}
|
210
|
+
};
|
211
|
+
var useIsServer = () => {
|
212
|
+
const isServer = useSyncExternalStore(
|
213
|
+
noopStore.subscribe,
|
214
|
+
noopStore.getSnapshot,
|
215
|
+
noopStore.getServerSnapshot
|
216
|
+
);
|
217
|
+
return isServer;
|
218
|
+
};
|
219
|
+
var useStore = (store, selector) => {
|
220
|
+
const slice = useSyncExternalStore(
|
221
|
+
store.subscribe,
|
222
|
+
() => selector(store.getState()),
|
223
|
+
() => selector(store.getInitialState())
|
224
|
+
);
|
225
|
+
useDebugValue(slice);
|
226
|
+
return slice;
|
227
|
+
};
|
228
|
+
|
229
|
+
// src/hooks/useLocation.ts
|
230
|
+
var useLocation = (selector, options) => {
|
231
|
+
const locationStore = useConstant(() => createLocationStore(options));
|
232
|
+
const stateSlice = useStore(locationStore, selector);
|
233
|
+
return [
|
234
|
+
stateSlice,
|
235
|
+
{
|
236
|
+
push: locationStore.push,
|
237
|
+
replace: locationStore.replace,
|
238
|
+
triggerPopstate: locationStore.triggerPopstateEvent
|
239
|
+
}
|
240
|
+
];
|
241
|
+
};
|
242
|
+
var useAnimationPresence = (options = {}) => {
|
243
|
+
const { defaultValue = true, duration, onExitComplete } = options;
|
244
|
+
const [isShown, setIsShown] = useState(defaultValue);
|
245
|
+
const [isMounted, setDebouncedIsMounted, setRegularIsMounted] = useDebouncedState(
|
246
|
+
defaultValue,
|
247
|
+
duration
|
248
|
+
);
|
249
|
+
const elementRef = useRef(null);
|
250
|
+
const stableOnExitComplete = useCallbackRef(onExitComplete);
|
251
|
+
useEffect(() => {
|
252
|
+
!isMounted && stableOnExitComplete();
|
253
|
+
}, [isMounted]);
|
254
|
+
const handleIsMountedWithoutRef = (value) => {
|
255
|
+
if (value) {
|
256
|
+
setRegularIsMounted(true);
|
257
|
+
return;
|
258
|
+
}
|
259
|
+
setDebouncedIsMounted(false);
|
260
|
+
};
|
261
|
+
const handleIsMountedWithRef = (value) => {
|
262
|
+
if (value) {
|
263
|
+
setRegularIsMounted(true);
|
264
|
+
return;
|
265
|
+
}
|
266
|
+
on("animationend", elementRef.current, () => {
|
267
|
+
setDebouncedIsMounted.cancel();
|
268
|
+
setRegularIsMounted(false);
|
269
|
+
});
|
270
|
+
};
|
271
|
+
const toggleVisibility = useCallbackRef((newValue) => {
|
272
|
+
const handleSetIsMounted = !duration ? handleIsMountedWithRef : handleIsMountedWithoutRef;
|
273
|
+
if (typeof newValue === "boolean") {
|
274
|
+
setIsShown(newValue);
|
275
|
+
handleSetIsMounted(newValue);
|
276
|
+
return;
|
277
|
+
}
|
278
|
+
setIsShown(!isShown);
|
279
|
+
handleSetIsMounted(!isShown);
|
280
|
+
});
|
281
|
+
return {
|
282
|
+
isPresent: isMounted,
|
283
|
+
isVisible: isShown,
|
284
|
+
toggleVisibility,
|
285
|
+
...duration === void 0 && { elementRef }
|
286
|
+
};
|
287
|
+
};
|
288
|
+
var useTransitionPresence = (options = {}) => {
|
289
|
+
const { defaultValue = true, duration, onExitComplete } = options;
|
290
|
+
const [isShown, setIsShown] = useState(defaultValue);
|
291
|
+
const [isMounted, setDebouncedIsMounted, setRegularIsMounted] = useDebouncedState(
|
292
|
+
defaultValue,
|
293
|
+
duration
|
294
|
+
);
|
295
|
+
const elementRef = useRef(null);
|
296
|
+
const stableOnExitComplete = useCallbackRef(onExitComplete);
|
297
|
+
const handleIsMountedWithoutRef = (value) => {
|
298
|
+
if (value) {
|
299
|
+
setDebouncedIsMounted(value, { $delay: 0 });
|
300
|
+
return;
|
301
|
+
}
|
302
|
+
setDebouncedIsMounted(false);
|
303
|
+
};
|
304
|
+
const handleIsMountedWithRef = (value) => {
|
305
|
+
if (value) {
|
306
|
+
setDebouncedIsMounted(value, { $delay: 0 });
|
307
|
+
return;
|
308
|
+
}
|
309
|
+
on("transitionend", elementRef.current, () => {
|
310
|
+
setDebouncedIsMounted.cancel();
|
311
|
+
setRegularIsMounted(false);
|
312
|
+
});
|
313
|
+
};
|
314
|
+
const toggleVisibility = useCallbackRef((newValue) => {
|
315
|
+
const handleSetIsMounted = !duration ? handleIsMountedWithRef : handleIsMountedWithoutRef;
|
316
|
+
if (typeof newValue === "boolean") {
|
317
|
+
setIsShown(newValue);
|
318
|
+
handleSetIsMounted(newValue);
|
319
|
+
return;
|
320
|
+
}
|
321
|
+
setIsShown(!isShown);
|
322
|
+
handleSetIsMounted(!isShown);
|
323
|
+
});
|
324
|
+
useEffect(() => {
|
325
|
+
!isMounted && stableOnExitComplete();
|
326
|
+
}, [isMounted]);
|
327
|
+
return {
|
328
|
+
isPresent: isMounted || isShown,
|
329
|
+
isVisible: isMounted && isShown,
|
330
|
+
toggleVisibility,
|
331
|
+
...duration === void 0 && { elementRef }
|
332
|
+
};
|
333
|
+
};
|
334
|
+
|
335
|
+
// src/hooks/usePresence/usePresence.ts
|
336
|
+
var usePresence = (options = {}) => {
|
337
|
+
const { type = "transition", ...restOfOptions } = options;
|
338
|
+
const useSpecificPresence = type === "transition" ? useTransitionPresence : useAnimationPresence;
|
339
|
+
return useSpecificPresence(restOfOptions);
|
340
|
+
};
|
341
|
+
var useScrollObserver = (options = {}) => {
|
342
|
+
const { rootMargin = "10px 0px 0px 0px", ...restOfOptions } = options;
|
343
|
+
const [isScrolled, setIsScrolled] = useState(false);
|
344
|
+
const elementObserver = useConstant(() => {
|
345
|
+
if (!isBrowser()) return;
|
346
|
+
return new IntersectionObserver(
|
347
|
+
([entry]) => {
|
348
|
+
if (!entry) return;
|
349
|
+
setIsScrolled(!entry.isIntersecting);
|
350
|
+
},
|
351
|
+
{ rootMargin, ...restOfOptions }
|
352
|
+
);
|
353
|
+
});
|
354
|
+
const observedElementRef = useCallbackRef((element) => {
|
355
|
+
const scrollWatcher = document.createElement("span");
|
356
|
+
scrollWatcher.dataset.scrollWatcher = "";
|
357
|
+
element?.before(scrollWatcher);
|
358
|
+
if (!elementObserver) return;
|
359
|
+
elementObserver.observe(scrollWatcher);
|
360
|
+
const cleanupFn = () => {
|
361
|
+
scrollWatcher.remove();
|
362
|
+
elementObserver.disconnect();
|
363
|
+
};
|
364
|
+
if (!element) {
|
365
|
+
cleanupFn();
|
366
|
+
return;
|
367
|
+
}
|
368
|
+
return cleanupFn;
|
369
|
+
});
|
370
|
+
return { isScrolled, observedElementRef };
|
371
|
+
};
|
372
|
+
var isSerializable = (item) => typeof item === "string" || typeof item === "number" || typeof item === "boolean";
|
373
|
+
var checkObjectPropsForQuery = (item, query) => {
|
374
|
+
for (const value of Object.values(item)) {
|
375
|
+
if (isSerializable(value) && value.toString().toLowerCase().includes(query)) {
|
376
|
+
return true;
|
377
|
+
}
|
378
|
+
}
|
379
|
+
return false;
|
380
|
+
};
|
381
|
+
var useSearch = (initialData, delay) => {
|
382
|
+
const [searchQuery, setSearchQuery] = useState("");
|
383
|
+
const [filteredData, setFilteredData] = useState(initialData);
|
384
|
+
const [isLoading, setIsLoading] = useState(false);
|
385
|
+
const handleDebouncedSearch = useDebouncedFn(() => {
|
386
|
+
const query = searchQuery.toLowerCase();
|
387
|
+
const filteredResults = initialData.filter((item) => {
|
388
|
+
if (isSerializable(item)) {
|
389
|
+
return item.toString().toLowerCase().includes(query);
|
390
|
+
}
|
391
|
+
if (isPlainObject(item)) {
|
392
|
+
return checkObjectPropsForQuery(item, query);
|
393
|
+
}
|
394
|
+
return false;
|
395
|
+
});
|
396
|
+
setFilteredData(filteredResults);
|
397
|
+
setIsLoading(false);
|
398
|
+
}, delay);
|
399
|
+
useAfterMountEffect(() => {
|
400
|
+
setIsLoading(true);
|
401
|
+
handleDebouncedSearch();
|
402
|
+
}, [searchQuery]);
|
403
|
+
return { data: filteredData, isLoading, query: searchQuery, setQuery: setSearchQuery };
|
404
|
+
};
|
405
|
+
var useSearchParams = (options) => {
|
406
|
+
const { action = "push", locationOptions } = options ?? {};
|
407
|
+
const [searchParams, setLocation] = useLocation((state) => state.search, locationOptions);
|
408
|
+
const setSearchParams = (newQueryParams) => {
|
409
|
+
const params = isFunction(newQueryParams) ? newQueryParams(searchParams) : newQueryParams;
|
410
|
+
const nextSearchParams = createSearchParams(params);
|
411
|
+
if (Object.is(searchParams.toString(), nextSearchParams.toString())) return;
|
412
|
+
setLocation[action]({ search: nextSearchParams });
|
413
|
+
};
|
414
|
+
setSearchParams.triggerPopstate = setLocation.triggerPopstate;
|
415
|
+
return [searchParams, setSearchParams];
|
416
|
+
};
|
417
|
+
var useSearchParamsObject = (options) => {
|
418
|
+
const [searchParams, setSearchParams] = useSearchParams(options);
|
419
|
+
const searchParamsObject = Object.fromEntries(searchParams);
|
420
|
+
const setSearchParamsObject = (newQueryParams) => {
|
421
|
+
const params = isFunction(newQueryParams) ? newQueryParams(searchParamsObject) : newQueryParams;
|
422
|
+
setSearchParams(params);
|
423
|
+
};
|
424
|
+
return [searchParamsObject, setSearchParamsObject];
|
425
|
+
};
|
426
|
+
var useStorageState = (...params) => {
|
427
|
+
const [keyOrOptions, $initialValue, options] = params;
|
428
|
+
const _key = isString(keyOrOptions) ? keyOrOptions : keyOrOptions.key;
|
429
|
+
const _initialValue = isString(keyOrOptions) ? $initialValue : keyOrOptions.initialValue;
|
430
|
+
const {
|
431
|
+
initialValue = _initialValue,
|
432
|
+
key = _key,
|
433
|
+
select = (value) => value,
|
434
|
+
...restOfOptions
|
435
|
+
} = isString(keyOrOptions) ? options ?? {} : keyOrOptions;
|
436
|
+
const externalStore = useConstant(
|
437
|
+
() => createExternalStorageStore({ initialValue, key, ...restOfOptions })
|
438
|
+
);
|
439
|
+
const stateInStorage = useStore(externalStore, select);
|
440
|
+
return [stateInStorage, externalStore.setState, externalStore];
|
441
|
+
};
|
442
|
+
var useThrottleBySetTimeout = (callbackFn, delay) => {
|
443
|
+
const latestCallback = useCallbackRef(callbackFn);
|
444
|
+
const throttledCallback = useConstant(() => throttleBySetTimeout(latestCallback, delay));
|
445
|
+
useOnUnmountEffect(() => throttledCallback.cancelTimeout());
|
446
|
+
return throttledCallback;
|
447
|
+
};
|
448
|
+
var useThrottleByTimer = (callbackFn, delay) => {
|
449
|
+
const latestCallback = useCallbackRef(callbackFn);
|
450
|
+
const throttledCallback = useConstant(() => throttleByTime(latestCallback, delay));
|
451
|
+
return throttledCallback;
|
452
|
+
};
|
453
|
+
var useThrottleByFrame = (callbackFn) => {
|
454
|
+
const latestCallback = useCallbackRef(callbackFn);
|
455
|
+
const throttledCallback = useConstant(() => throttleByFrame(latestCallback));
|
456
|
+
useOnUnmountEffect(() => throttledCallback.cancelAnimation());
|
457
|
+
return throttledCallback;
|
458
|
+
};
|
459
|
+
|
460
|
+
export { ContextError, createCustomContext, getErrorMessage, useAfterMountEffect, useAnimateElementRefs, useAnimationInterval, useCallbackRef, useConstant, useCopyToClipboard, useDebouncedFn, useDebouncedState, useDisclosure, useEffectOnce, useIsServer, useLifeCycle, useLocation, useMountEffect, useOnUnmountEffect, usePresence, useScrollObserver, useSearch, useSearchParams, useSearchParamsObject, useStorageState, useStore, useThrottleByFrame, useThrottleBySetTimeout, useThrottleByTimer, useToggle };
|
461
|
+
//# sourceMappingURL=chunk-AHVBSEEO.js.map
|
462
|
+
//# sourceMappingURL=chunk-AHVBSEEO.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/createCustomContext.ts","../../src/hooks/useCallbackRef.ts","../../src/hooks/effects/useAfterMountEffect.ts","../../src/hooks/effects/useEffectOnce.ts","../../src/hooks/effects/useLifeCycle.ts","../../src/hooks/effects/useOnMountEffect.ts","../../src/hooks/effects/useOnUnMountEffect.ts","../../src/hooks/useAnimateElementRefs.ts","../../src/hooks/useConstant.ts","../../src/hooks/useAnimationInterval.ts","../../src/hooks/useCopyToClipboard.ts","../../src/hooks/useDebounce.ts","../../src/hooks/useToggle.ts","../../src/hooks/useDisclosure.ts","../../src/hooks/useIsServer.ts","../../src/hooks/useStore.ts","../../src/hooks/useLocation.ts","../../src/hooks/usePresence/useAnimationPresence.ts","../../src/hooks/usePresence/useTransitionPresence.ts","../../src/hooks/usePresence/usePresence.ts","../../src/hooks/useScrollObserver.ts","../../src/hooks/useSearch.ts","../../src/hooks/useSearchParams.ts","../../src/hooks/useStorageState.ts","../../src/hooks/useThrottle.ts"],"names":["useRef","useEffect","useCallback","useState","useSyncExternalStore","on"],"mappings":";;;;;AAEa,IAAA,YAAA,GAAN,cAA2B,KAAM,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CAAC,CAAA;AAE3E,EAAmB,kBAAA,CAAA,MAAM,iBAAkB,CAAA,eAAA,EAAiB,CAAA;AAE5D,EAAO,OAAA,iBAAA;AACR","file":"chunk-AHVBSEEO.js","sourcesContent":["import { createContext, useContext } from \"react\";\n\nexport class ContextError extends Error {\n\toverride name = \"ContextError\";\n}\n\nexport const getErrorMessage = (hook: string, provider: string) => {\n\treturn `${hook} returned \"null\". Did you forget to wrap the necessary components within ${provider}?`;\n};\n\nexport type CustomContextOptions<TDefaultContextValue, TStrict extends boolean> = {\n\tdefaultValue?: TDefaultContextValue | null;\n\terrorMessage?: string;\n\thookName?: string;\n\tname?: string;\n\tproviderName?: string;\n\tstrict?: TStrict;\n};\n\ntype UseCustomContextResult<TContextValue, TStrict extends boolean> = TStrict extends true\n\t? TContextValue\n\t: TContextValue | null;\n\nconst createCustomContext = <TContextValue, TStrict extends boolean = true>(\n\toptions: CustomContextOptions<TContextValue, TStrict> = {}\n) => {\n\tconst {\n\t\tdefaultValue = null,\n\t\terrorMessage,\n\t\thookName = \"Unnamed Context hook\",\n\t\tname = \"Unnamed Context\",\n\t\tproviderName = \"Unnamed Provider\",\n\t\tstrict = true,\n\t} = options;\n\n\tconst Context = createContext<TContextValue | null>(defaultValue);\n\n\tContext.displayName = name;\n\n\tconst useCustomContext = (): UseCustomContextResult<TContextValue, TStrict> => {\n\t\tconst contextValue = useContext(Context);\n\n\t\tif (strict && contextValue === null) {\n\t\t\tthrow new ContextError(errorMessage ?? getErrorMessage(hookName, providerName));\n\t\t}\n\n\t\treturn contextValue as UseCustomContextResult<TContextValue, TStrict>;\n\t};\n\n\treturn [Context.Provider, useCustomContext] as const;\n};\n\nexport { createCustomContext };\n","import type { AnyFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useLayoutEffect, useRef } from \"react\";\n\n/**\n * Returns a stable function that always points to the latest version of the callback function.\n * @param callbackFn - The function to reference\n * @returns a stable function that always points to the latest version of the callback function\n */\n\nconst useCallbackRef = <TCallback = AnyFunction>(callbackFn: TCallback | undefined) => {\n\tconst callbackRef = useRef(callbackFn);\n\n\tuseLayoutEffect(() => {\n\t\t// == Doing this instead updating it during render cuz according to Dan Abramov, render should be pure\n\t\tcallbackRef.current = callbackFn;\n\t}, [callbackFn]);\n\n\tconst savedCallback = useCallback(\n\t\t// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- callbackRef.current can be null in some cases\n\t\t(...params: unknown[]) => (callbackRef.current as AnyFunction)?.(...params) as unknown,\n\t\t[]\n\t);\n\n\treturn savedCallback as TCallback;\n};\n\nexport { useCallbackRef };\n","import { useEffect, useRef } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\n\nconst useAfterMountEffect: typeof useEffect = (callBackFn, deps) => {\n\tconst isFirstMount = useRef(true);\n\tconst stableCallback = useCallbackRef(callBackFn);\n\n\tuseEffect(() => {\n\t\tif (isFirstMount.current) {\n\t\t\tisFirstMount.current = false;\n\t\t\treturn;\n\t\t}\n\n\t\tstableCallback();\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableCallback is stable\n\t}, deps);\n};\nexport { useAfterMountEffect };\n","import { useEffect, useRef } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\n\nconst useEffectOnce = (callBackFn: React.EffectCallback) => {\n\tconst stableCallback = useCallbackRef(callBackFn);\n\n\tconst effectGuard = useRef(false);\n\n\t// == savedCallback is always stable so no worries about re-execution of this effect\n\tuseEffect(() => {\n\t\tif (effectGuard.current) return;\n\n\t\teffectGuard.current = true;\n\n\t\treturn stableCallback();\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableCallback is stable\n\t}, []);\n};\n\nexport { useEffectOnce };\n","import { useEffect } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\n\nexport type Destructor = ReturnType<React.EffectCallback>;\n\ntype LifeCycleOptions = {\n\tonMount?: () => void;\n\tonUnmount?: Destructor;\n};\n\nconst useLifeCycle = ({ onMount, onUnmount }: LifeCycleOptions) => {\n\tconst stableOnMount = useCallbackRef(onMount);\n\tconst stableOnUnmount = useCallbackRef(onUnmount);\n\n\tuseEffect(() => {\n\t\tstableOnMount();\n\n\t\treturn stableOnUnmount;\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableOnMount and stableOnUnmount are stable\n\t}, []);\n};\n\nexport { useLifeCycle };\n","import { useLifeCycle } from \"./useLifeCycle\";\n\nconst useMountEffect = (callBackFn: () => void) => {\n\tuseLifeCycle({ onMount: callBackFn });\n};\n\nexport { useMountEffect };\n","import { type Destructor, useLifeCycle } from \"./useLifeCycle\";\n\nconst useOnUnmountEffect = (cleanUpFn: Destructor) => useLifeCycle({ onUnmount: cleanUpFn });\n\nexport { useOnUnmountEffect };\n","import { on } from \"@zayne-labs/toolkit-core\";\nimport { type NonEmptyArray, isArray } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useRef } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\n\ntype ElementsInfoArray<TTargetElement extends string> = NonEmptyArray<{\n\tanimationClass: string;\n\ttargetElement: TTargetElement;\n}>;\n\nconst removeClass = (target: HTMLElement, className: string) => () => target.classList.remove(className);\n\n/**\n * This is a custom React hook that adds and removes animation classes to specified HTML elements.\n * @param elementsInfoArray - An array of objects that contain information about the animation class and the target HTML element.\n * @returns - An object containing the refs of the animated elements and a function to handle the initiation and removal animation.\n */\n\nconst useAnimateElementRefs = <TTargetElement extends string>(\n\telementsInfoArray: ElementsInfoArray<TTargetElement>\n) => {\n\tconst elementsRef = useRef<Record<TTargetElement, HTMLElement | null>>({} as never);\n\n\tconst addAnimationClasses = useCallbackRef(() => {\n\t\tif (!isArray(elementsInfoArray)) {\n\t\t\tconsole.error(\"elementsInfo is not an Array\");\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const { animationClass, targetElement } of elementsInfoArray) {\n\t\t\tif (!elementsRef.current[targetElement]) {\n\t\t\t\tconsole.error(\"ElementError\", `\"${targetElement}\" element does not exist`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\telementsRef.current[targetElement].classList.add(animationClass);\n\t\t}\n\t});\n\n\tconst removeAnimationClasses = useCallbackRef(() => {\n\t\tif (!isArray(elementsInfoArray)) {\n\t\t\tconsole.error(\"elementsInfo is not an Array\");\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const { animationClass, targetElement } of elementsInfoArray) {\n\t\t\tif (!elementsRef.current[targetElement]) {\n\t\t\t\tconsole.error(\"ElementError\", `\"${targetElement}\" element does not exist`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ton(\n\t\t\t\t\"transitionend\",\n\t\t\t\telementsRef.current[targetElement],\n\t\t\t\tremoveClass(elementsRef.current[targetElement], animationClass)\n\t\t\t);\n\n\t\t\ton(\n\t\t\t\t\"animationend\",\n\t\t\t\telementsRef.current[targetElement],\n\t\t\t\tremoveClass(elementsRef.current[targetElement], animationClass)\n\t\t\t);\n\t\t}\n\t});\n\n\t// Add animation classes to elements and remove them after the animation ends\n\tconst handleElementsAnimation = useCallback(() => {\n\t\taddAnimationClasses();\n\n\t\tremoveAnimationClasses();\n\t}, [addAnimationClasses, removeAnimationClasses]);\n\n\treturn { animatedElements: elementsRef.current, handleElementsAnimation };\n};\n\nexport { useAnimateElementRefs };\n","import { useState } from \"react\";\n\nconst useConstant = <TResult>(initCallbackFn: () => TResult) => useState(initCallbackFn)[0];\n\nexport { useConstant };\n","import { type AnimationIntervalOptions, setAnimationInterval } from \"@zayne-labs/toolkit-core\";\nimport type { Prettify } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useEffect } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useConstant } from \"./useConstant\";\n\ntype AnimationOptions = Prettify<\n\tAnimationIntervalOptions & {\n\t\tintervalDuration: number | null;\n\t\tonAnimation: () => void;\n\t}\n>;\n\nconst useAnimationInterval = (options: AnimationOptions) => {\n\tconst { intervalDuration, onAnimation, once } = options;\n\n\tconst latestCallback = useCallbackRef(onAnimation);\n\n\t// prettier-ignore\n\tconst { start, stop } = useConstant(() => setAnimationInterval(latestCallback, intervalDuration, { once }));\n\n\tuseEffect(() => {\n\t\tif (intervalDuration === null) return;\n\n\t\tstart();\n\n\t\treturn stop;\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- start and stop are stable\n\t}, [intervalDuration]);\n\n\treturn { start, stop };\n};\n\nexport { useAnimationInterval };\n","import { copyToClipboard } from \"@zayne-labs/toolkit-core\";\nimport { useState } from \"react\";\n\nconst useCopyToClipboard = () => {\n\tconst [state, setState] = useState(\"\");\n\n\tconst handleCopy = (value: string) => {\n\t\tsetState(value);\n\t\tvoid copyToClipboard(value);\n\t};\n\n\treturn { copiedValue: state, handleCopy };\n};\n\nexport { useCopyToClipboard };\n","import { debounce } from \"@zayne-labs/toolkit-core\";\nimport type { CallbackFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useState } from \"react\";\nimport { useOnUnmountEffect } from \"./effects/useOnUnMountEffect\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useConstant } from \"./useConstant\";\n\nexport const useDebouncedFn = <TParams>(callBackFn: CallbackFn<TParams>, delay: number | undefined) => {\n\tconst latestCallback = useCallbackRef(callBackFn);\n\n\tconst debouncedFn = useConstant(() => debounce(latestCallback, delay));\n\n\tuseOnUnmountEffect(() => {\n\t\tdebouncedFn.cancel();\n\t\tdebouncedFn.cancelMaxWait();\n\t});\n\n\treturn debouncedFn;\n};\n\nexport const useDebouncedState = <TValue>(defaultValue: TValue, delay: number | undefined) => {\n\tconst [value, setValue] = useState(defaultValue);\n\n\tconst setDebouncedValue = useConstant(() => debounce(setValue, delay));\n\n\tuseOnUnmountEffect(() => {\n\t\tsetDebouncedValue.cancel();\n\t\tsetDebouncedValue.cancelMaxWait();\n\t});\n\n\treturn [value, setDebouncedValue, setValue] as const;\n};\n","import { useCallback, useState } from \"react\";\n\ntype InitialState = boolean | (() => boolean);\n\nconst useToggle = (initialValue: InitialState = false) => {\n\tconst [value, setValue] = useState(initialValue);\n\n\tconst toggle = useCallback(<TValue>(newValue?: TValue) => {\n\t\tif (typeof newValue === \"boolean\") {\n\t\t\tsetValue(newValue);\n\t\t\treturn;\n\t\t}\n\n\t\tsetValue((prev) => !prev);\n\t}, []);\n\n\treturn [value, toggle] as const;\n};\n\nexport { useToggle };\n","import { lockScroll } from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useToggle } from \"./useToggle\";\n\ntype DisclosureOptions = {\n\thasScrollControl?: boolean;\n\tinitialState?: boolean | (() => boolean);\n};\n\nconst useDisclosure = (options: DisclosureOptions = {}) => {\n\tconst { hasScrollControl = false, initialState = false } = options;\n\tconst [isOpen, toggleIsOpen] = useToggle(initialState);\n\n\tconst handleScrollControl = useCallbackRef(\n\t\t(state: boolean) => hasScrollControl && lockScroll({ isActive: state })\n\t);\n\n\tconst onOpen = useCallbackRef(<TValue>(value?: TValue) => {\n\t\tconst booleanValue = typeof value === \"boolean\" && value ? value : true;\n\t\ttoggleIsOpen(booleanValue);\n\t\thandleScrollControl(booleanValue);\n\t});\n\n\tconst onClose = useCallbackRef(<TValue>(value?: TValue) => {\n\t\tconst booleanValue = typeof value === \"boolean\" && !value ? value : false;\n\n\t\ttoggleIsOpen(booleanValue);\n\t\thandleScrollControl(booleanValue);\n\t});\n\n\tconst onToggle = useCallbackRef(<TValue>(value?: TValue) => {\n\t\tif (typeof value === \"boolean\") {\n\t\t\tvalue ? onOpen(value) : onClose(value);\n\t\t\treturn;\n\t\t}\n\n\t\tisOpen ? onClose() : onOpen();\n\t});\n\n\treturn { isOpen, onClose, onOpen, onToggle };\n};\n\nexport { useDisclosure };\n","import { useSyncExternalStore } from \"react\";\n\nconst noopStore = {\n\tgetServerSnapshot: () => true,\n\tgetSnapshot: () => false,\n\t// eslint-disable-next-line unicorn/consistent-function-scoping -- It's fine\n\tsubscribe: () => () => {},\n};\n\n/**\n * @description Returns whether the component is currently being server side rendered or\n * hydrated on the client. Can be used to delay browser-specific rendering\n * until after hydration.\n */\nconst useIsServer = () => {\n\tconst isServer = useSyncExternalStore(\n\t\tnoopStore.subscribe,\n\t\tnoopStore.getSnapshot,\n\t\tnoopStore.getServerSnapshot\n\t);\n\n\treturn isServer;\n};\n\nexport { useIsServer };\n","import type { StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useDebugValue, useSyncExternalStore } from \"react\";\n\nconst useStore = <TState, TSlice>(store: StoreApi<TState>, selector: SelectorFn<TState, TSlice>) => {\n\tconst slice = useSyncExternalStore(\n\t\tstore.subscribe,\n\t\t() => selector(store.getState()),\n\t\t() => selector(store.getInitialState())\n\t);\n\n\tuseDebugValue(slice);\n\n\treturn slice;\n};\n\nexport { useStore };\n","import {\n\ttype LocationInfo,\n\ttype LocationStoreOptions,\n\tcreateLocationStore,\n} from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useConstant } from \"./useConstant\";\nimport { useStore } from \"./useStore\";\n\ntype LocationStore = ReturnType<typeof createLocationStore>;\n\ntype UseLocationResult<TSlice> = [\n\tstate: TSlice,\n\tsetState: {\n\t\tpush: LocationStore[\"push\"];\n\t\treplace: LocationStore[\"replace\"];\n\t\ttriggerPopstate: LocationStore[\"triggerPopstateEvent\"];\n\t},\n];\n\nconst useLocation = <TSlice = LocationInfo>(\n\tselector: SelectorFn<LocationInfo, TSlice>,\n\toptions?: LocationStoreOptions\n) => {\n\tconst locationStore = useConstant(() => createLocationStore(options));\n\n\tconst stateSlice = useStore(locationStore as never, selector);\n\n\treturn [\n\t\tstateSlice,\n\t\t{\n\t\t\tpush: locationStore.push,\n\t\t\treplace: locationStore.replace,\n\t\t\ttriggerPopstate: locationStore.triggerPopstateEvent,\n\t\t},\n\t] as UseLocationResult<TSlice>;\n};\n\nexport { useLocation };\n","import { on } from \"@zayne-labs/toolkit-core\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\nimport { useDebouncedState } from \"../useDebounce\";\nimport type { UseSpecificPresence } from \"./types\";\n\nconst useAnimationPresence: UseSpecificPresence = (options = {}) => {\n\tconst { defaultValue = true, duration, onExitComplete } = options;\n\n\tconst [isShown, setIsShown] = useState(defaultValue);\n\n\tconst [isMounted, setDebouncedIsMounted, setRegularIsMounted] = useDebouncedState(\n\t\tdefaultValue,\n\t\tduration\n\t);\n\tconst elementRef = useRef<HTMLElement>(null);\n\n\tconst stableOnExitComplete = useCallbackRef(onExitComplete);\n\n\tuseEffect(() => {\n\t\t!isMounted && stableOnExitComplete();\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableOnExitComplete is stable\n\t}, [isMounted]);\n\n\tconst handleIsMountedWithoutRef = (value: boolean) => {\n\t\tif (value) {\n\t\t\tsetRegularIsMounted(true);\n\t\t\treturn;\n\t\t}\n\n\t\tsetDebouncedIsMounted(false);\n\t};\n\n\tconst handleIsMountedWithRef = (value: boolean) => {\n\t\tif (value) {\n\t\t\tsetRegularIsMounted(true);\n\t\t\treturn;\n\t\t}\n\n\t\ton(\"animationend\", elementRef.current, () => {\n\t\t\tsetDebouncedIsMounted.cancel();\n\t\t\tsetRegularIsMounted(false);\n\t\t});\n\t};\n\n\tconst toggleVisibility = useCallbackRef(<TValue>(newValue?: TValue) => {\n\t\tconst handleSetIsMounted = !duration ? handleIsMountedWithRef : handleIsMountedWithoutRef;\n\n\t\tif (typeof newValue === \"boolean\") {\n\t\t\tsetIsShown(newValue);\n\t\t\thandleSetIsMounted(newValue);\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsShown(!isShown);\n\t\thandleSetIsMounted(!isShown);\n\t});\n\n\treturn {\n\t\tisPresent: isMounted,\n\t\tisVisible: isShown,\n\t\ttoggleVisibility,\n\t\t...(duration === undefined && { elementRef }),\n\t} as never;\n};\n\nexport { useAnimationPresence };\n","import { on } from \"@zayne-labs/toolkit-core\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\nimport { useDebouncedState } from \"../useDebounce\";\nimport type { UseSpecificPresence } from \"./types\";\n\nconst useTransitionPresence: UseSpecificPresence = (options = {}) => {\n\tconst { defaultValue = true, duration, onExitComplete } = options;\n\n\tconst [isShown, setIsShown] = useState(defaultValue);\n\n\tconst [isMounted, setDebouncedIsMounted, setRegularIsMounted] = useDebouncedState(\n\t\tdefaultValue,\n\t\tduration\n\t);\n\tconst elementRef = useRef<HTMLElement>(null);\n\tconst stableOnExitComplete = useCallbackRef(onExitComplete);\n\n\tconst handleIsMountedWithoutRef = (value: boolean) => {\n\t\tif (value) {\n\t\t\tsetDebouncedIsMounted(value, { $delay: 0 });\n\t\t\treturn;\n\t\t}\n\n\t\tsetDebouncedIsMounted(false);\n\t};\n\n\tconst handleIsMountedWithRef = (value: boolean) => {\n\t\tif (value) {\n\t\t\tsetDebouncedIsMounted(value, { $delay: 0 });\n\t\t\treturn;\n\t\t}\n\n\t\ton(\"transitionend\", elementRef.current, () => {\n\t\t\tsetDebouncedIsMounted.cancel();\n\t\t\tsetRegularIsMounted(false);\n\t\t});\n\t};\n\n\tconst toggleVisibility = useCallbackRef(<TValue>(newValue?: TValue) => {\n\t\tconst handleSetIsMounted = !duration ? handleIsMountedWithRef : handleIsMountedWithoutRef;\n\n\t\tif (typeof newValue === \"boolean\") {\n\t\t\tsetIsShown(newValue);\n\t\t\thandleSetIsMounted(newValue);\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsShown(!isShown);\n\t\thandleSetIsMounted(!isShown);\n\t});\n\n\tuseEffect(() => {\n\t\t!isMounted && stableOnExitComplete();\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableOnExitComplete is stable\n\t}, [isMounted]);\n\n\treturn {\n\t\tisPresent: isMounted || isShown,\n\t\tisVisible: isMounted && isShown,\n\t\ttoggleVisibility,\n\t\t...(duration === undefined && { elementRef }),\n\t} as never;\n};\n\nexport { useTransitionPresence };\n","import type { UsePresence } from \"./types\";\nimport { useAnimationPresence } from \"./useAnimationPresence\";\nimport { useTransitionPresence } from \"./useTransitionPresence\";\n\n/**\n * usePresence hook provides a way to animate an element, before removing it from the DOM.\n * @param defaultValue - The default value for the presence state. Defaults to `true`.\n * @param options - The options for the usePresence hook.\n * @returns A object containing the boolean that should be used to conditionally render the element (isPresent), another boolean used to toggle the animation classes, and a function to toggle the state.\n */\n\nconst usePresence: UsePresence = (options = {}) => {\n\tconst { type = \"transition\", ...restOfOptions } = options;\n\n\tconst useSpecificPresence = type === \"transition\" ? useTransitionPresence : useAnimationPresence;\n\n\treturn useSpecificPresence(restOfOptions);\n};\n\nexport { usePresence };\n","import { isBrowser } from \"@zayne-labs/toolkit-core\";\nimport { useState } from \"react\";\nimport type { RefCallback } from \"../utils\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useConstant } from \"./useConstant\";\n\nconst useScrollObserver = <TElement extends HTMLElement>(options: IntersectionObserverInit = {}) => {\n\tconst { rootMargin = \"10px 0px 0px 0px\", ...restOfOptions } = options;\n\n\tconst [isScrolled, setIsScrolled] = useState(false);\n\n\tconst elementObserver = useConstant(() => {\n\t\tif (!isBrowser()) return;\n\n\t\treturn new IntersectionObserver(\n\t\t\t([entry]) => {\n\t\t\t\tif (!entry) return;\n\t\t\t\tsetIsScrolled(!entry.isIntersecting);\n\t\t\t},\n\t\t\t{ rootMargin, ...restOfOptions }\n\t\t);\n\t});\n\n\tconst observedElementRef: RefCallback<TElement> = useCallbackRef((element) => {\n\t\tconst scrollWatcher = document.createElement(\"span\");\n\t\tscrollWatcher.dataset.scrollWatcher = \"\";\n\n\t\telement?.before(scrollWatcher);\n\n\t\tif (!elementObserver) return;\n\n\t\telementObserver.observe(scrollWatcher);\n\n\t\tconst cleanupFn = () => {\n\t\t\tscrollWatcher.remove();\n\t\t\telementObserver.disconnect();\n\t\t};\n\n\t\t// React 18 may not call the cleanup function so we need to call it manually on element unmount\n\t\tif (!element) {\n\t\t\tcleanupFn();\n\t\t\treturn;\n\t\t}\n\n\t\treturn cleanupFn;\n\t});\n\n\treturn { isScrolled, observedElementRef };\n};\n\nexport { useScrollObserver };\n","import { isPlainObject } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useState } from \"react\";\nimport { useAfterMountEffect } from \"./effects/useAfterMountEffect\";\nimport { useDebouncedFn } from \"./useDebounce\";\n\nconst isSerializable = (item: unknown): item is boolean | number | string =>\n\ttypeof item === \"string\" || typeof item === \"number\" || typeof item === \"boolean\";\n\nconst checkObjectPropsForQuery = (item: Record<string, unknown>, query: string): boolean => {\n\tfor (const value of Object.values(item)) {\n\t\tif (isSerializable(value) && value.toString().toLowerCase().includes(query)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n};\n\nconst useSearch = <TData>(initialData: TData[], delay?: number) => {\n\tconst [searchQuery, setSearchQuery] = useState(\"\");\n\tconst [filteredData, setFilteredData] = useState(initialData);\n\tconst [isLoading, setIsLoading] = useState(false);\n\n\tconst handleDebouncedSearch = useDebouncedFn(() => {\n\t\tconst query = searchQuery.toLowerCase();\n\n\t\tconst filteredResults = initialData.filter((item) => {\n\t\t\tif (isSerializable(item)) {\n\t\t\t\treturn item.toString().toLowerCase().includes(query);\n\t\t\t}\n\n\t\t\tif (isPlainObject(item)) {\n\t\t\t\treturn checkObjectPropsForQuery(item, query);\n\t\t\t}\n\n\t\t\treturn false;\n\t\t});\n\n\t\tsetFilteredData(filteredResults);\n\t\tsetIsLoading(false);\n\t}, delay);\n\n\tuseAfterMountEffect(() => {\n\t\tsetIsLoading(true);\n\t\thandleDebouncedSearch();\n\t}, [searchQuery]);\n\n\treturn { data: filteredData, isLoading, query: searchQuery, setQuery: setSearchQuery };\n};\n\nexport { useSearch };\n","import {\n\ttype LocationStoreOptions,\n\ttype URLSearchParamsInit,\n\tcreateSearchParams,\n} from \"@zayne-labs/toolkit-core\";\nimport { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useLocation } from \"./useLocation\";\n\ntype UseSearchParamsOptions = {\n\taction?: \"push\" | \"replace\";\n\tlocationOptions?: LocationStoreOptions;\n};\n\nexport const useSearchParams = <TSearchParams extends URLSearchParamsInit>(\n\toptions?: UseSearchParamsOptions\n) => {\n\tconst { action = \"push\", locationOptions } = options ?? {};\n\n\tconst [searchParams, setLocation] = useLocation((state) => state.search, locationOptions);\n\n\tconst setSearchParams = (\n\t\tnewQueryParams: TSearchParams | ((prev: URLSearchParams) => TSearchParams)\n\t) => {\n\t\tconst params = isFunction(newQueryParams) ? newQueryParams(searchParams) : newQueryParams;\n\n\t\tconst nextSearchParams = createSearchParams(params);\n\n\t\tif (Object.is(searchParams.toString(), nextSearchParams.toString())) return;\n\n\t\tsetLocation[action]({ search: nextSearchParams });\n\t};\n\n\tsetSearchParams.triggerPopstate = setLocation.triggerPopstate;\n\n\treturn [searchParams, setSearchParams] as const;\n};\n\nexport const useSearchParamsObject = <TSearchParams extends Record<string, string>>(\n\toptions?: UseSearchParamsOptions\n) => {\n\tconst [searchParams, setSearchParams] = useSearchParams(options);\n\n\tconst searchParamsObject = Object.fromEntries(searchParams) as TSearchParams;\n\n\tconst setSearchParamsObject = (\n\t\tnewQueryParams: TSearchParams | ((prev: TSearchParams) => TSearchParams)\n\t) => {\n\t\tconst params = isFunction(newQueryParams) ? newQueryParams(searchParamsObject) : newQueryParams;\n\n\t\tsetSearchParams(params);\n\t};\n\n\treturn [searchParamsObject, setSearchParamsObject] as const;\n};\n","import {\n\ttype SetStorageState,\n\ttype StorageOptions,\n\tcreateExternalStorageStore,\n} from \"@zayne-labs/toolkit-core\";\nimport { type SelectorFn, isString } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useConstant } from \"./useConstant\";\nimport { useStore } from \"./useStore\";\n\ntype UseStorageStateOptions<TValue, TSlice = TValue> = StorageOptions<TValue> & {\n\tselect?: SelectorFn<TValue, TSlice>;\n};\n\ntype StorageStoreApi<TValue> = ReturnType<typeof createExternalStorageStore<TValue>>;\n\ntype ParamsOne<TValue, TSlice> = [\n\tkey: string,\n\tinitialValue?: TValue,\n\toptions?: Omit<UseStorageStateOptions<TValue, TSlice>, \"initialValue\" | \"key\">,\n];\n\ntype ParamsTwo<TValue, TSlice> = [options: UseStorageStateOptions<TValue, TSlice>];\n\ntype UseStorageStateParams<TValue, TSlice> = ParamsOne<TValue, TSlice> | ParamsTwo<TValue, TSlice>;\n\n// TODO: Add createImpl that returns a hook for react later\nconst useStorageState = <TValue, TSlice = TValue>(...params: UseStorageStateParams<TValue, TSlice>) => {\n\tconst [keyOrOptions, $initialValue, options] = params;\n\n\tconst _key = isString(keyOrOptions) ? keyOrOptions : keyOrOptions.key;\n\tconst _initialValue = isString(keyOrOptions) ? $initialValue : keyOrOptions.initialValue;\n\n\tconst {\n\t\tinitialValue = _initialValue,\n\t\tkey = _key,\n\t\tselect = (value: TValue) => value,\n\t\t...restOfOptions\n\t} = isString(keyOrOptions)\n\t\t? ((options as UseStorageStateOptions<TValue, TSlice> | undefined) ?? {})\n\t\t: keyOrOptions;\n\n\tconst externalStore = useConstant(() =>\n\t\tcreateExternalStorageStore({ initialValue, key, ...restOfOptions })\n\t);\n\n\tconst stateInStorage = useStore(externalStore as never, select as never);\n\n\treturn [stateInStorage, externalStore.setState, externalStore] as [\n\t\tstate: TValue,\n\t\tsetState: SetStorageState<TValue>,\n\t\tstoreApi: StorageStoreApi<TValue>,\n\t];\n};\n\nexport { useStorageState };\n","import { throttleByFrame, throttleBySetTimeout, throttleByTime } from \"@zayne-labs/toolkit-core\";\nimport type { CallbackFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useOnUnmountEffect } from \"./effects\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useConstant } from \"./useConstant\";\n\nexport const useThrottleBySetTimeout = <TParams>(callbackFn: CallbackFn<TParams>, delay: number) => {\n\tconst latestCallback = useCallbackRef(callbackFn);\n\n\tconst throttledCallback = useConstant(() => throttleBySetTimeout(latestCallback, delay));\n\n\tuseOnUnmountEffect(() => throttledCallback.cancelTimeout());\n\n\treturn throttledCallback;\n};\n\nexport const useThrottleByTimer = <TParams>(callbackFn: CallbackFn<TParams>, delay: number) => {\n\tconst latestCallback = useCallbackRef(callbackFn);\n\n\tconst throttledCallback = useConstant(() => throttleByTime(latestCallback, delay));\n\n\treturn throttledCallback;\n};\n\nexport const useThrottleByFrame = <TParams>(callbackFn: CallbackFn<TParams>) => {\n\tconst latestCallback = useCallbackRef(callbackFn);\n\n\tconst throttledCallback = useConstant(() => throttleByFrame(latestCallback));\n\n\tuseOnUnmountEffect(() => throttledCallback.cancelAnimation());\n\n\treturn throttledCallback;\n};\n"]}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import * as react from 'react';
|
2
|
+
|
3
|
+
declare class ContextError extends Error {
|
4
|
+
name: string;
|
5
|
+
}
|
6
|
+
declare const getErrorMessage: (hook: string, provider: string) => string;
|
7
|
+
type CustomContextOptions<TDefaultContextValue, TStrict extends boolean> = {
|
8
|
+
defaultValue?: TDefaultContextValue | null;
|
9
|
+
errorMessage?: string;
|
10
|
+
hookName?: string;
|
11
|
+
name?: string;
|
12
|
+
providerName?: string;
|
13
|
+
strict?: TStrict;
|
14
|
+
};
|
15
|
+
type UseCustomContextResult<TContextValue, TStrict extends boolean> = TStrict extends true ? TContextValue : TContextValue | null;
|
16
|
+
declare const createCustomContext: <TContextValue, TStrict extends boolean = true>(options?: CustomContextOptions<TContextValue, TStrict>) => readonly [react.Provider<TContextValue | null>, () => UseCustomContextResult<TContextValue, TStrict>];
|
17
|
+
|
18
|
+
export { ContextError as C, type CustomContextOptions as a, createCustomContext as c, getErrorMessage as g };
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { AnyFunction } from '@zayne-labs/toolkit-type-helpers';
|
2
|
+
|
3
|
+
type ForwardedRefType<TComponent extends HTMLElement | React.ElementType> = TComponent extends React.ElementType ? React.ForwardedRef<React.Ref<TComponent>> : React.ForwardedRef<TComponent>;
|
4
|
+
type InferProps<TComponent extends HTMLElement | React.ElementType> = TComponent extends React.ElementType ? React.ComponentPropsWithRef<TComponent> : React.HTMLAttributes<TComponent>;
|
5
|
+
type StateSetter<TSetter = unknown> = React.Dispatch<React.SetStateAction<TSetter>>;
|
6
|
+
type MyCustomCss<TExtra extends Record<string, string> = NonNullable<unknown>> = React.CSSProperties & Record<`--${string}`, string> & TExtra;
|
7
|
+
/**
|
8
|
+
* @description Using this instead of the official react one to avoid build errors
|
9
|
+
*/
|
10
|
+
type RefCallback<TElement> = (instance: TElement | null) => void | (() => void);
|
11
|
+
/**
|
12
|
+
* @description Represents a set of props that can be used to render a component conditionally based on a discriminated union type.
|
13
|
+
* This type allows for the use of either a render prop or children prop, but not both at the same time.
|
14
|
+
* If both are provided, a TypeScript error will be thrown.
|
15
|
+
* @template TRenderPropType The type of the function that will be called to render the component when using the render prop.
|
16
|
+
* @template TMessage A message to display when the render prop is not used and the children prop is instead used.
|
17
|
+
*/
|
18
|
+
type DiscriminatedRenderProps<TRenderPropType extends AnyFunction, TMessage extends string = "Hey, Sorry but since you're currently using the children prop, the render prop is therefore redundant"> = {
|
19
|
+
children: TRenderPropType;
|
20
|
+
render?: TMessage;
|
21
|
+
} | {
|
22
|
+
children?: TMessage;
|
23
|
+
render: TRenderPropType;
|
24
|
+
};
|
25
|
+
|
26
|
+
export type { DiscriminatedRenderProps as D, ForwardedRefType as F, InferProps as I, MyCustomCss as M, RefCallback as R, StateSetter as S };
|
@@ -0,0 +1,192 @@
|
|
1
|
+
export { C as ContextError, a as CustomContextOptions, c as createCustomContext, g as getErrorMessage } from '../createCustomContext-b8lQCth3.js';
|
2
|
+
import * as react from 'react';
|
3
|
+
import { useEffect } from 'react';
|
4
|
+
import { NonEmptyArray, Prettify, AnyFunction, CallbackFn, SelectorFn } from '@zayne-labs/toolkit-type-helpers';
|
5
|
+
import * as _zayne_labs_toolkit_core from '@zayne-labs/toolkit-core';
|
6
|
+
import { AnimationIntervalOptions, LocationInfo, LocationStoreOptions, createLocationStore, URLSearchParamsInit, SetStorageState, createExternalStorageStore, StorageOptions, StoreApi } from '@zayne-labs/toolkit-core';
|
7
|
+
import { R as RefCallback } from '../global-DMxqhOh1.js';
|
8
|
+
|
9
|
+
declare const useAfterMountEffect: typeof useEffect;
|
10
|
+
|
11
|
+
declare const useEffectOnce: (callBackFn: React.EffectCallback) => void;
|
12
|
+
|
13
|
+
type Destructor = ReturnType<React.EffectCallback>;
|
14
|
+
type LifeCycleOptions = {
|
15
|
+
onMount?: () => void;
|
16
|
+
onUnmount?: Destructor;
|
17
|
+
};
|
18
|
+
declare const useLifeCycle: ({ onMount, onUnmount }: LifeCycleOptions) => void;
|
19
|
+
|
20
|
+
declare const useMountEffect: (callBackFn: () => void) => void;
|
21
|
+
|
22
|
+
declare const useOnUnmountEffect: (cleanUpFn: Destructor) => void;
|
23
|
+
|
24
|
+
type ElementsInfoArray<TTargetElement extends string> = NonEmptyArray<{
|
25
|
+
animationClass: string;
|
26
|
+
targetElement: TTargetElement;
|
27
|
+
}>;
|
28
|
+
/**
|
29
|
+
* This is a custom React hook that adds and removes animation classes to specified HTML elements.
|
30
|
+
* @param elementsInfoArray - An array of objects that contain information about the animation class and the target HTML element.
|
31
|
+
* @returns - An object containing the refs of the animated elements and a function to handle the initiation and removal animation.
|
32
|
+
*/
|
33
|
+
declare const useAnimateElementRefs: <TTargetElement extends string>(elementsInfoArray: ElementsInfoArray<TTargetElement>) => {
|
34
|
+
animatedElements: Record<TTargetElement, HTMLElement | null>;
|
35
|
+
handleElementsAnimation: () => void;
|
36
|
+
};
|
37
|
+
|
38
|
+
type AnimationOptions = Prettify<AnimationIntervalOptions & {
|
39
|
+
intervalDuration: number | null;
|
40
|
+
onAnimation: () => void;
|
41
|
+
}>;
|
42
|
+
declare const useAnimationInterval: (options: AnimationOptions) => {
|
43
|
+
start: () => void;
|
44
|
+
stop: () => void;
|
45
|
+
};
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Returns a stable function that always points to the latest version of the callback function.
|
49
|
+
* @param callbackFn - The function to reference
|
50
|
+
* @returns a stable function that always points to the latest version of the callback function
|
51
|
+
*/
|
52
|
+
declare const useCallbackRef: <TCallback = AnyFunction>(callbackFn: TCallback | undefined) => TCallback;
|
53
|
+
|
54
|
+
declare const useConstant: <TResult>(initCallbackFn: () => TResult) => TResult;
|
55
|
+
|
56
|
+
declare const useCopyToClipboard: () => {
|
57
|
+
copiedValue: string;
|
58
|
+
handleCopy: (value: string) => void;
|
59
|
+
};
|
60
|
+
|
61
|
+
declare const useDebouncedFn: <TParams>(callBackFn: CallbackFn<TParams>, delay: number | undefined) => {
|
62
|
+
(...params: TParams[]): void;
|
63
|
+
(params: TParams | TParams[], overrideOptions: {
|
64
|
+
$delay: number;
|
65
|
+
}): void;
|
66
|
+
cancel: () => void;
|
67
|
+
cancelMaxWait(): void;
|
68
|
+
};
|
69
|
+
declare const useDebouncedState: <TValue>(defaultValue: TValue, delay: number | undefined) => readonly [TValue, {
|
70
|
+
(...params: react.SetStateAction<TValue>[]): void;
|
71
|
+
(params: react.SetStateAction<TValue> | react.SetStateAction<TValue>[], overrideOptions: {
|
72
|
+
$delay: number;
|
73
|
+
}): void;
|
74
|
+
cancel: () => void;
|
75
|
+
cancelMaxWait(): void;
|
76
|
+
}, react.Dispatch<react.SetStateAction<TValue>>];
|
77
|
+
|
78
|
+
type DisclosureOptions = {
|
79
|
+
hasScrollControl?: boolean;
|
80
|
+
initialState?: boolean | (() => boolean);
|
81
|
+
};
|
82
|
+
declare const useDisclosure: (options?: DisclosureOptions) => {
|
83
|
+
isOpen: boolean;
|
84
|
+
onClose: <TValue>(value?: TValue) => void;
|
85
|
+
onOpen: <TValue>(value?: TValue) => void;
|
86
|
+
onToggle: <TValue>(value?: TValue) => void;
|
87
|
+
};
|
88
|
+
|
89
|
+
/**
|
90
|
+
* @description Returns whether the component is currently being server side rendered or
|
91
|
+
* hydrated on the client. Can be used to delay browser-specific rendering
|
92
|
+
* until after hydration.
|
93
|
+
*/
|
94
|
+
declare const useIsServer: () => boolean;
|
95
|
+
|
96
|
+
type LocationStore = ReturnType<typeof createLocationStore>;
|
97
|
+
type UseLocationResult<TSlice> = [
|
98
|
+
state: TSlice,
|
99
|
+
setState: {
|
100
|
+
push: LocationStore["push"];
|
101
|
+
replace: LocationStore["replace"];
|
102
|
+
triggerPopstate: LocationStore["triggerPopstateEvent"];
|
103
|
+
}
|
104
|
+
];
|
105
|
+
declare const useLocation: <TSlice = LocationInfo>(selector: SelectorFn<LocationInfo, TSlice>, options?: LocationStoreOptions) => UseLocationResult<TSlice>;
|
106
|
+
|
107
|
+
type InitialState = boolean | (() => boolean);
|
108
|
+
declare const useToggle: (initialValue?: InitialState) => readonly [boolean, <TValue>(newValue?: TValue) => void];
|
109
|
+
|
110
|
+
type UsePresenceOptions<TDuration extends number | undefined> = {
|
111
|
+
defaultValue?: boolean;
|
112
|
+
/**
|
113
|
+
* @description The duration of the animation or transition
|
114
|
+
*/
|
115
|
+
duration?: TDuration;
|
116
|
+
/**
|
117
|
+
* @description A callback function that will be called when the animation or transition ends
|
118
|
+
*/
|
119
|
+
onExitComplete?: () => void;
|
120
|
+
};
|
121
|
+
type UsePresenceResult<TElement, TDuration> = Prettify<(TDuration extends undefined ? {
|
122
|
+
elementRef: React.RefObject<TElement>;
|
123
|
+
} : unknown) & {
|
124
|
+
isPresent: boolean;
|
125
|
+
isVisible: boolean;
|
126
|
+
toggleVisibility: ReturnType<typeof useToggle>[1];
|
127
|
+
}>;
|
128
|
+
type TypeOption = {
|
129
|
+
/**
|
130
|
+
* @description The type of animation, whether animation or transition
|
131
|
+
* @default "transition"
|
132
|
+
*/
|
133
|
+
type?: "animation" | "transition";
|
134
|
+
};
|
135
|
+
type UsePresence = <TElement extends HTMLElement, TDuration extends number | undefined = undefined>(options?: Prettify<TypeOption & UsePresenceOptions<TDuration>>) => UsePresenceResult<TElement, TDuration>;
|
136
|
+
|
137
|
+
/**
|
138
|
+
* usePresence hook provides a way to animate an element, before removing it from the DOM.
|
139
|
+
* @param defaultValue - The default value for the presence state. Defaults to `true`.
|
140
|
+
* @param options - The options for the usePresence hook.
|
141
|
+
* @returns A object containing the boolean that should be used to conditionally render the element (isPresent), another boolean used to toggle the animation classes, and a function to toggle the state.
|
142
|
+
*/
|
143
|
+
declare const usePresence: UsePresence;
|
144
|
+
|
145
|
+
declare const useScrollObserver: <TElement extends HTMLElement>(options?: IntersectionObserverInit) => {
|
146
|
+
isScrolled: boolean;
|
147
|
+
observedElementRef: RefCallback<TElement>;
|
148
|
+
};
|
149
|
+
|
150
|
+
declare const useSearch: <TData>(initialData: TData[], delay?: number) => {
|
151
|
+
data: TData[];
|
152
|
+
isLoading: boolean;
|
153
|
+
query: string;
|
154
|
+
setQuery: react.Dispatch<react.SetStateAction<string>>;
|
155
|
+
};
|
156
|
+
|
157
|
+
type UseSearchParamsOptions = {
|
158
|
+
action?: "push" | "replace";
|
159
|
+
locationOptions?: LocationStoreOptions;
|
160
|
+
};
|
161
|
+
declare const useSearchParams: <TSearchParams extends URLSearchParamsInit>(options?: UseSearchParamsOptions) => readonly [URLSearchParams, {
|
162
|
+
(newQueryParams: TSearchParams | ((prev: URLSearchParams) => TSearchParams)): void;
|
163
|
+
triggerPopstate: (state?: _zayne_labs_toolkit_core.LocationInfo["state"]) => void;
|
164
|
+
}];
|
165
|
+
declare const useSearchParamsObject: <TSearchParams extends Record<string, string>>(options?: UseSearchParamsOptions) => readonly [TSearchParams, (newQueryParams: TSearchParams | ((prev: TSearchParams) => TSearchParams)) => void];
|
166
|
+
|
167
|
+
type UseStorageStateOptions<TValue, TSlice = TValue> = StorageOptions<TValue> & {
|
168
|
+
select?: SelectorFn<TValue, TSlice>;
|
169
|
+
};
|
170
|
+
type StorageStoreApi<TValue> = ReturnType<typeof createExternalStorageStore<TValue>>;
|
171
|
+
type ParamsOne<TValue, TSlice> = [
|
172
|
+
key: string,
|
173
|
+
initialValue?: TValue,
|
174
|
+
options?: Omit<UseStorageStateOptions<TValue, TSlice>, "initialValue" | "key">
|
175
|
+
];
|
176
|
+
type ParamsTwo<TValue, TSlice> = [options: UseStorageStateOptions<TValue, TSlice>];
|
177
|
+
type UseStorageStateParams<TValue, TSlice> = ParamsOne<TValue, TSlice> | ParamsTwo<TValue, TSlice>;
|
178
|
+
declare const useStorageState: <TValue, TSlice = TValue>(...params: UseStorageStateParams<TValue, TSlice>) => [state: TValue, setState: SetStorageState<TValue>, storeApi: StorageStoreApi<TValue>];
|
179
|
+
|
180
|
+
declare const useStore: <TState, TSlice>(store: StoreApi<TState>, selector: SelectorFn<TState, TSlice>) => TSlice;
|
181
|
+
|
182
|
+
declare const useThrottleBySetTimeout: <TParams>(callbackFn: CallbackFn<TParams>, delay: number) => {
|
183
|
+
(...params: TParams[]): void;
|
184
|
+
cancelTimeout(): void;
|
185
|
+
};
|
186
|
+
declare const useThrottleByTimer: <TParams>(callbackFn: CallbackFn<TParams>, delay: number) => (...params: TParams[]) => void;
|
187
|
+
declare const useThrottleByFrame: <TParams>(callbackFn: CallbackFn<TParams>) => {
|
188
|
+
(...params: TParams[]): void;
|
189
|
+
cancelAnimation(): void;
|
190
|
+
};
|
191
|
+
|
192
|
+
export { useAfterMountEffect, useAnimateElementRefs, useAnimationInterval, useCallbackRef, useConstant, useCopyToClipboard, useDebouncedFn, useDebouncedState, useDisclosure, useEffectOnce, useIsServer, useLifeCycle, useLocation, useMountEffect, useOnUnmountEffect, usePresence, useScrollObserver, useSearch, useSearchParams, useSearchParamsObject, useStorageState, useStore, useThrottleByFrame, useThrottleBySetTimeout, useThrottleByTimer, useToggle };
|
@@ -0,0 +1,3 @@
|
|
1
|
+
export { ContextError, createCustomContext, getErrorMessage, useAfterMountEffect, useAnimateElementRefs, useAnimationInterval, useCallbackRef, useConstant, useCopyToClipboard, useDebouncedFn, useDebouncedState, useDisclosure, useEffectOnce, useIsServer, useLifeCycle, useLocation, useMountEffect, useOnUnmountEffect, usePresence, useScrollObserver, useSearch, useSearchParams, useSearchParamsObject, useStorageState, useStore, useThrottleByFrame, useThrottleBySetTimeout, useThrottleByTimer, useToggle } from '../chunk-AHVBSEEO.js';
|
2
|
+
//# sourceMappingURL=index.js.map
|
3
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { R as RefCallback } from '../global-DMxqhOh1.js';
|
2
|
+
export { D as DiscriminatedRenderProps, F as ForwardedRefType, I as InferProps, M as MyCustomCss, S as StateSetter } from '../global-DMxqhOh1.js';
|
3
|
+
import * as react from 'react';
|
4
|
+
import '@zayne-labs/toolkit-type-helpers';
|
5
|
+
|
6
|
+
type AsProp<TElement extends React.ElementType> = {
|
7
|
+
as?: TElement;
|
8
|
+
};
|
9
|
+
type PropsWithOptionalAs<TElement extends React.ElementType, TProps> = "as" extends keyof TProps ? TProps : AsProp<TElement> & TProps;
|
10
|
+
type InferOtherProps<TElement extends React.ElementType, TProps> = Omit<React.ComponentPropsWithRef<TElement>, keyof PropsWithOptionalAs<TElement, TProps>>;
|
11
|
+
type PolymorphicProps<TElement extends React.ElementType, TProps extends Record<string, unknown> = AsProp<TElement>> = InferOtherProps<TElement, TProps> & PropsWithOptionalAs<TElement, TProps>;
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @description A utility to compose refs together.
|
15
|
+
*
|
16
|
+
* Accepts callback refs and RefObject(s)
|
17
|
+
*/
|
18
|
+
declare const composeRefs: <TRef>(refs: Array<React.Ref<TRef>>) => RefCallback<TRef>;
|
19
|
+
|
20
|
+
declare const isSlotElement: <TProps>(child: React.ReactNode, SlotWrapper: React.FunctionComponent<TProps>) => boolean;
|
21
|
+
type SlotOptions = {
|
22
|
+
errorMessage?: string;
|
23
|
+
throwOnMultipleSlotMatch?: boolean;
|
24
|
+
};
|
25
|
+
declare const getSlotElement: <TProps>(children: React.ReactNode, SlotWrapper: React.FunctionComponent<TProps>, options?: SlotOptions) => React.ReactElement<TProps> | undefined;
|
26
|
+
declare const getOtherChildren: <TProps, TChildren extends React.ReactNode = react.ReactNode>(children: TChildren, SlotWrapperOrWrappers: Array<React.FunctionComponent<TProps>> | React.FunctionComponent<TProps>) => TChildren extends unknown[] ? TChildren : TChildren[];
|
27
|
+
|
28
|
+
type UnknownProps = Record<string, unknown>;
|
29
|
+
declare const mergeProps: (slotProps: UnknownProps, childProps: UnknownProps) => UnknownProps;
|
30
|
+
|
31
|
+
export { type AsProp, type PolymorphicProps, RefCallback, composeRefs, getOtherChildren, getSlotElement, isSlotElement, mergeProps };
|
@@ -0,0 +1,86 @@
|
|
1
|
+
import { AssertionError, isArray, isPlainObject, isFunction } from '@zayne-labs/toolkit-type-helpers';
|
2
|
+
import { toArray } from '@zayne-labs/toolkit-core';
|
3
|
+
import { isValidElement } from 'react';
|
4
|
+
|
5
|
+
// src/utils/composeRefs.ts
|
6
|
+
var setRef = (ref, value) => {
|
7
|
+
if (!ref) return;
|
8
|
+
if (isFunction(ref)) {
|
9
|
+
return ref(value);
|
10
|
+
}
|
11
|
+
ref.current = value;
|
12
|
+
};
|
13
|
+
var composeRefs = (refs) => {
|
14
|
+
const refCallBack = (node) => {
|
15
|
+
const cleanupFnArray = refs.map((ref) => setRef(ref, node)).filter(Boolean);
|
16
|
+
const cleanupFn = () => cleanupFnArray.forEach((cleanup) => cleanup?.());
|
17
|
+
if (!node) {
|
18
|
+
cleanupFn();
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
return cleanupFn;
|
22
|
+
};
|
23
|
+
return refCallBack;
|
24
|
+
};
|
25
|
+
var isSlotElement = (child, SlotWrapper) => {
|
26
|
+
if (!isValidElement(child)) {
|
27
|
+
return false;
|
28
|
+
}
|
29
|
+
if (child.type.slot === SlotWrapper.slot) {
|
30
|
+
return true;
|
31
|
+
}
|
32
|
+
if (child.type.name === SlotWrapper.name) {
|
33
|
+
return true;
|
34
|
+
}
|
35
|
+
if (child.type === SlotWrapper) {
|
36
|
+
return true;
|
37
|
+
}
|
38
|
+
return child.type.toString() === SlotWrapper.toString();
|
39
|
+
};
|
40
|
+
var getSlotElement = (children, SlotWrapper, options = {}) => {
|
41
|
+
const {
|
42
|
+
errorMessage = "Only one instance of the SlotComponent is allowed",
|
43
|
+
throwOnMultipleSlotMatch = false
|
44
|
+
} = options;
|
45
|
+
const childrenArray = toArray(children);
|
46
|
+
const Slot = childrenArray.filter((child) => isSlotElement(child, SlotWrapper));
|
47
|
+
if (throwOnMultipleSlotMatch && Slot.length > 1) {
|
48
|
+
throw new AssertionError(errorMessage);
|
49
|
+
}
|
50
|
+
return Slot[0];
|
51
|
+
};
|
52
|
+
var isSlotElementMultiple = (child, SlotWrapperArray) => SlotWrapperArray.some((slotWrapper) => isSlotElement(child, slotWrapper));
|
53
|
+
var getOtherChildren = (children, SlotWrapperOrWrappers) => {
|
54
|
+
const childrenArray = toArray(children);
|
55
|
+
const otherChildren = isArray(SlotWrapperOrWrappers) ? childrenArray.filter((child) => !isSlotElementMultiple(child, SlotWrapperOrWrappers)) : childrenArray.filter((child) => !isSlotElement(child, SlotWrapperOrWrappers));
|
56
|
+
return otherChildren;
|
57
|
+
};
|
58
|
+
var mergeProps = (slotProps, childProps) => {
|
59
|
+
const overrideProps = { ...childProps };
|
60
|
+
for (const propName of Object.keys(slotProps)) {
|
61
|
+
const slotPropValue = slotProps[propName];
|
62
|
+
const childPropValue = childProps[propName];
|
63
|
+
if (propName === "style" && isPlainObject(slotPropValue) && isPlainObject(childPropValue)) {
|
64
|
+
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
|
65
|
+
}
|
66
|
+
if (propName === "className") {
|
67
|
+
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
|
68
|
+
}
|
69
|
+
const isHandler = propName.startsWith("on");
|
70
|
+
if (!isHandler) continue;
|
71
|
+
if (isFunction(slotPropValue) && isFunction(childPropValue)) {
|
72
|
+
overrideProps[propName] = (...args) => {
|
73
|
+
childPropValue(...args);
|
74
|
+
slotPropValue(...args);
|
75
|
+
};
|
76
|
+
}
|
77
|
+
if (isFunction(slotPropValue)) {
|
78
|
+
overrideProps[propName] = slotPropValue;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
return { ...slotProps, ...overrideProps };
|
82
|
+
};
|
83
|
+
|
84
|
+
export { composeRefs, getOtherChildren, getSlotElement, isSlotElement, mergeProps };
|
85
|
+
//# sourceMappingURL=index.js.map
|
86
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/composeRefs.ts","../../../src/utils/getSlotElement.ts","../../../src/utils/mergeProps.ts"],"names":["isFunction"],"mappings":";;;;;AAQA,IAAM,MAAA,GAAS,CAAO,GAAA,EAAsB,KAAgB,KAAA;AAC3D,EAAA,IAAI,CAAC,GAAK,EAAA;AAEV,EAAI,IAAA,UAAA,CAAW,GAAG,CAAG,EAAA;AACpB,IAAA,OAAO,IAAI,KAAK,CAAA;AAAA;AAIjB,EAAA,GAAA,CAAI,OAAU,GAAA,KAAA;AACf,CAAA;AAOM,IAAA,WAAA,GAAc,CAAO,IAAoD,KAAA;AAC9E,EAAM,MAAA,WAAA,GAAiC,CAAC,IAAS,KAAA;AAChD,IAAM,MAAA,cAAA,GAAiB,IAAK,CAAA,GAAA,CAAI,CAAC,GAAA,KAAQ,MAAO,CAAA,GAAA,EAAK,IAAI,CAAC,CAAE,CAAA,MAAA,CAAO,OAAO,CAAA;AAE1E,IAAA,MAAM,YAAY,MAAM,cAAA,CAAe,QAAQ,CAAC,OAAA,KAAY,WAAW,CAAA;AAGvE,IAAA,IAAI,CAAC,IAAM,EAAA;AACV,MAAU,SAAA,EAAA;AACV,MAAA;AAAA;AAGD,IAAO,OAAA,SAAA;AAAA,GACR;AAEA,EAAO,OAAA,WAAA;AACR;ACjCa,IAAA,aAAA,GAAgB,CAC5B,KAAA,EACA,WACI,KAAA;AACJ,EAAI,IAAA,CAAC,cAAe,CAAA,KAAK,CAAG,EAAA;AAC3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,CAAW,aAAa,CAAG,EAAA;AAC9B,MAAA,aAAA,CAAc,QAAQ,CAAI,GAAA,aAAA;AAAA;AAC3B;AAGD,EAAA,OAAO,EAAE,GAAG,SAAW,EAAA,GAAG,aAAc,EAAA;AACzC","file":"index.js","sourcesContent":["import { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { RefCallback } from \"./types\";\n\n/**\n * @description Set a given ref to a given value.\n *\n * This utility takes care of different types of refs: callback refs and RefObject(s)\n */\nconst setRef = <TRef>(ref: React.Ref<TRef>, value: TRef) => {\n\tif (!ref) return;\n\n\tif (isFunction(ref)) {\n\t\treturn ref(value);\n\t}\n\n\t// eslint-disable-next-line no-param-reassign -- Mutation is needed here\n\tref.current = value;\n};\n\n/**\n * @description A utility to compose refs together.\n *\n * Accepts callback refs and RefObject(s)\n */\nconst composeRefs = <TRef>(refs: Array<React.Ref<TRef>>): RefCallback<TRef> => {\n\tconst refCallBack: RefCallback<TRef> = (node) => {\n\t\tconst cleanupFnArray = refs.map((ref) => setRef(ref, node)).filter(Boolean);\n\n\t\tconst cleanupFn = () => cleanupFnArray.forEach((cleanup) => cleanup?.());\n\n\t\t// == React 18 may not call the cleanup function so we need to call it manually on element unmount\n\t\tif (!node) {\n\t\t\tcleanupFn();\n\t\t\treturn;\n\t\t}\n\n\t\treturn cleanupFn;\n\t};\n\n\treturn refCallBack;\n};\n\nexport { composeRefs };\n","import { toArray } from \"@zayne-labs/toolkit-core\";\nimport { AssertionError, isArray } from \"@zayne-labs/toolkit-type-helpers\";\nimport { isValidElement } from \"react\";\n\ntype Noop = () => void;\ntype WithSlot = { slot?: string };\n\nexport const isSlotElement = <TProps>(\n\tchild: React.ReactNode,\n\tSlotWrapper: React.FunctionComponent<TProps>\n) => {\n\tif (!isValidElement(child)) {\n\t\treturn false;\n\t}\n\n\tif ((child.type as WithSlot).slot === (SlotWrapper as WithSlot).slot) {\n\t\treturn true;\n\t}\n\n\tif ((child.type as Noop).name === (SlotWrapper as Noop).name) {\n\t\treturn true;\n\t}\n\n\tif (child.type === SlotWrapper) {\n\t\treturn true;\n\t}\n\n\treturn child.type.toString() === SlotWrapper.toString();\n};\n\ntype SlotOptions = {\n\terrorMessage?: string;\n\tthrowOnMultipleSlotMatch?: boolean;\n};\n\nexport const getSlotElement = <TProps>(\n\tchildren: React.ReactNode,\n\tSlotWrapper: React.FunctionComponent<TProps>,\n\toptions: SlotOptions = {}\n) => {\n\tconst {\n\t\terrorMessage = \"Only one instance of the SlotComponent is allowed\",\n\t\tthrowOnMultipleSlotMatch = false,\n\t} = options;\n\n\tconst childrenArray = toArray<React.ReactNode>(children);\n\n\tconst Slot = childrenArray.filter((child) => isSlotElement(child, SlotWrapper));\n\n\tif (throwOnMultipleSlotMatch && Slot.length > 1) {\n\t\tthrow new AssertionError(errorMessage);\n\t}\n\n\treturn Slot[0] as React.ReactElement<TProps> | undefined;\n};\n\nconst isSlotElementMultiple = <TProps>(\n\tchild: React.ReactNode,\n\tSlotWrapperArray: Array<React.FunctionComponent<TProps>>\n) => SlotWrapperArray.some((slotWrapper) => isSlotElement(child, slotWrapper));\n\n// Check if the child is a Slot element by matching any in the SlotWrapperArray\nexport const getOtherChildren = <TProps, TChildren extends React.ReactNode = React.ReactNode>(\n\tchildren: TChildren,\n\tSlotWrapperOrWrappers: Array<React.FunctionComponent<TProps>> | React.FunctionComponent<TProps>\n) => {\n\tconst childrenArray = toArray<TChildren>(children);\n\n\tconst otherChildren = isArray(SlotWrapperOrWrappers)\n\t\t? childrenArray.filter((child) => !isSlotElementMultiple(child, SlotWrapperOrWrappers))\n\t\t: childrenArray.filter((child) => !isSlotElement(child, SlotWrapperOrWrappers));\n\n\treturn otherChildren as TChildren extends unknown[] ? TChildren : TChildren[];\n};\n","import { isFunction, isPlainObject } from \"@zayne-labs/toolkit-type-helpers\";\n\ntype UnknownProps = Record<string, unknown>;\n\nconst mergeProps = (slotProps: UnknownProps, childProps: UnknownProps): UnknownProps => {\n\t// all child props should override slotProps\n\tconst overrideProps = { ...childProps };\n\n\tfor (const propName of Object.keys(slotProps)) {\n\t\tconst slotPropValue = slotProps[propName];\n\t\tconst childPropValue = childProps[propName];\n\n\t\t// == if it's `style`, we merge them\n\t\tif (propName === \"style\" && isPlainObject(slotPropValue) && isPlainObject(childPropValue)) {\n\t\t\toverrideProps[propName] = { ...slotPropValue, ...childPropValue };\n\t\t}\n\n\t\tif (propName === \"className\") {\n\t\t\toverrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(\" \");\n\t\t}\n\n\t\tconst isHandler = propName.startsWith(\"on\");\n\n\t\tif (!isHandler) continue;\n\n\t\t// == if the handler exists on both, we compose them\n\t\tif (isFunction(slotPropValue) && isFunction(childPropValue)) {\n\t\t\toverrideProps[propName] = (...args: unknown[]) => {\n\t\t\t\tchildPropValue(...args);\n\t\t\t\tslotPropValue(...args);\n\t\t\t};\n\t\t}\n\n\t\t// == but if it exists only on the slot, we use only that one\n\t\tif (isFunction(slotPropValue)) {\n\t\t\toverrideProps[propName] = slotPropValue;\n\t\t}\n\t}\n\n\treturn { ...slotProps, ...overrideProps };\n};\n\nexport { mergeProps };\n"]}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import * as react from 'react';
|
2
|
+
import { SelectorFn, AnyObject } from '@zayne-labs/toolkit-type-helpers';
|
3
|
+
import * as zustand from 'zustand';
|
4
|
+
import { UseBoundStore, StoreApi, StoreMutatorIdentifier, StateCreator } from 'zustand';
|
5
|
+
import { a as CustomContextOptions } from '../createCustomContext-b8lQCth3.js';
|
6
|
+
|
7
|
+
declare const createZustandContext: <TState extends Record<string, unknown>, TUseBoundStore extends UseBoundStore<StoreApi<TState>> = UseBoundStore<StoreApi<TState>>>(options?: CustomContextOptions<TUseBoundStore, true>) => [ZustandProvider: (props: {
|
8
|
+
children: React.ReactNode;
|
9
|
+
createStore: () => TUseBoundStore;
|
10
|
+
} | {
|
11
|
+
children: React.ReactNode;
|
12
|
+
value: TUseBoundStore;
|
13
|
+
}) => react.FunctionComponentElement<react.ProviderProps<TUseBoundStore | null>>, useBoundStore: <TResult>(selector: SelectorFn<TState, TResult>) => TResult];
|
14
|
+
|
15
|
+
type Combine = <TInitialState extends AnyObject, TExtraState extends AnyObject, Mps extends Array<[StoreMutatorIdentifier, unknown]> = [], Mcs extends Array<[StoreMutatorIdentifier, unknown]> = []>(initialState: TInitialState, additionalStateCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>) => StateCreator<TExtraState & TInitialState>;
|
16
|
+
declare const combine: Combine;
|
17
|
+
declare const createStoreWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(initialState: TInitialState, additionalStateCreator: StateCreator<TInitialState, [], [], TExtraState>) => zustand.StoreApi<TExtraState & TInitialState>;
|
18
|
+
declare const createWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(initialState: TInitialState, additionalStateCreator: StateCreator<TInitialState, [], [], TExtraState>) => zustand.UseBoundStore<zustand.StoreApi<TExtraState & TInitialState>>;
|
19
|
+
|
20
|
+
export { type Combine, combine, createStoreWithCombine, createWithCombine, createZustandContext };
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { createCustomContext, useConstant } from '../chunk-AHVBSEEO.js';
|
2
|
+
import { createElement } from 'react';
|
3
|
+
import { createStore, create } from 'zustand';
|
4
|
+
|
5
|
+
var createZustandContext = (options) => {
|
6
|
+
const [Provider, useCustomContext] = createCustomContext(options);
|
7
|
+
function ZustandProvider(props) {
|
8
|
+
const { children, ...restOfProps } = props;
|
9
|
+
const useZustandStore = useConstant(
|
10
|
+
() => "createStore" in restOfProps ? restOfProps.createStore() : restOfProps.value
|
11
|
+
);
|
12
|
+
return createElement(Provider, { value: useZustandStore }, children);
|
13
|
+
}
|
14
|
+
const useBoundStore = (selector) => useCustomContext()(selector);
|
15
|
+
return [ZustandProvider, useBoundStore];
|
16
|
+
};
|
17
|
+
var combine = (initialState, storeCreator) => (
|
18
|
+
// eslint-disable-next-line ts-eslint/no-unsafe-return -- We don't know what the storeCreator will return
|
19
|
+
(...params) => ({
|
20
|
+
...initialState,
|
21
|
+
...storeCreator(...params)
|
22
|
+
})
|
23
|
+
);
|
24
|
+
var createStoreWithCombine = (...params) => createStore(combine(...params));
|
25
|
+
var createWithCombine = (...params) => create(combine(...params));
|
26
|
+
|
27
|
+
export { combine, createStoreWithCombine, createWithCombine, createZustandContext };
|
28
|
+
//# sourceMappingURL=index.js.map
|
29
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/zustand/createZustandContext.ts","../../../src/zustand/createZustandStoreWithCombine.ts"],"names":[],"mappings":";;;;AAKM,IAAA,oBAAA,GAAuB,CAI5B,OACI,KAAA;AACJ,EAAA,MAAM,CAAC,QAAA,EAAU,gBAAgB,CAAA,GAAI,oBAAoB,OAAO,CAAA;AAYhE,EAAA,SAAS,gBAAgB,KAA6B,EAAA;AACrD,IAAA,MAAM,EAAE,QAAA,EAAU,GAAG,WAAA,EAAgB,GAAA,KAAA;AAErC,IAAA,MAAM,eAAkB,GAAA,WAAA;AAAA,MAAY,MACnC,aAAiB,IAAA,WAAA,GAAc,WAAY,CAAA,WAAA,KAAgB,WAAY,CAAA;AAAA,KACxE;AAEA,IAAA,OAAO,cAAc,QAAU,EAAA,EAAE,KAAO,EAAA,eAAA,IAAmB,QAAQ,CAAA;AAAA;AAGpE,EAAA,MAAM,aAAgB,GAAA,CAAU,QAA0C,KAAA,gBAAA,GAAmB,QAAQ,CAAA;AAErG,EAAO,OAAA,CAAC,iBAAiB,aAAa,CAAA;AAIvC;AC1Ba,IAAA,OAAA,GACZ,CAAC,YAAc,EAAA,YAAA;AAAA;AAAA,EAEf,IAAI,MAAY,MAAA;AAAA,IACf,GAAG,YAAA;AAAA,IACH,GAAI,YAA6B,CAAA,GAAG,MAAM;AAAA,GAC3C;AAAA;AAEM,IAAM,yBAAyB,CAClC,GAAA,MAAA,KACC,YAAY,OAAQ,CAAA,GAAG,MAAM,CAAC;AAE5B,IAAM,oBAAoB,CAC7B,GAAA,MAAA,KACC,OAAO,OAAQ,CAAA,GAAG,MAAM,CAAC","file":"index.js","sourcesContent":["import type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createElement } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { type CustomContextOptions, createCustomContext, useConstant } from \"../hooks\";\n\nconst createZustandContext = <\n\tTState extends Record<string, unknown>,\n\tTUseBoundStore extends UseBoundStore<StoreApi<TState>> = UseBoundStore<StoreApi<TState>>,\n>(\n\toptions?: CustomContextOptions<TUseBoundStore, true>\n) => {\n\tconst [Provider, useCustomContext] = createCustomContext(options);\n\n\ttype ZustandProviderProps =\n\t\t| {\n\t\t\t\tchildren: React.ReactNode;\n\t\t\t\tcreateStore: () => TUseBoundStore;\n\t\t }\n\t\t| {\n\t\t\t\tchildren: React.ReactNode;\n\t\t\t\tvalue: TUseBoundStore;\n\t\t };\n\n\tfunction ZustandProvider(props: ZustandProviderProps) {\n\t\tconst { children, ...restOfProps } = props;\n\n\t\tconst useZustandStore = useConstant(() =>\n\t\t\t\"createStore\" in restOfProps ? restOfProps.createStore() : restOfProps.value\n\t\t);\n\n\t\treturn createElement(Provider, { value: useZustandStore }, children);\n\t}\n\n\tconst useBoundStore = <TResult>(selector: SelectorFn<TState, TResult>) => useCustomContext()(selector);\n\n\treturn [ZustandProvider, useBoundStore] as [\n\t\tZustandProvider: typeof ZustandProvider,\n\t\tuseBoundStore: typeof useBoundStore,\n\t];\n};\n\nexport { createZustandContext };\n","import type { AnyFunction, AnyObject } from \"@zayne-labs/toolkit-type-helpers\";\nimport { type StateCreator, type StoreMutatorIdentifier, create, createStore } from \"zustand\";\n\nexport type Combine = <\n\tTInitialState extends AnyObject,\n\tTExtraState extends AnyObject,\n\tMps extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\tMcs extends Array<[StoreMutatorIdentifier, unknown]> = [],\n>(\n\tinitialState: TInitialState,\n\tadditionalStateCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>\n) => StateCreator<TExtraState & TInitialState>;\n\nexport const combine: Combine =\n\t(initialState, storeCreator) =>\n\t// eslint-disable-next-line ts-eslint/no-unsafe-return -- We don't know what the storeCreator will return\n\t(...params) => ({\n\t\t...initialState,\n\t\t...(storeCreator as AnyFunction)(...params),\n\t});\n\nexport const createStoreWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => createStore(combine(...params));\n\nexport const createWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => create(combine(...params));\n"]}
|
package/package.json
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
{
|
2
|
+
"name": "@zayne-labs/toolkit-react",
|
3
|
+
"type": "module",
|
4
|
+
"version": "0.8.22",
|
5
|
+
"description": "A collection of utility functions, types and composables used by my other projects. Nothing too fancy but can be useful.",
|
6
|
+
"author": "Ryan Zayne",
|
7
|
+
"license": "MIT",
|
8
|
+
"homepage": "https://github.com/zayne-labs/toolkit#readme",
|
9
|
+
"repository": {
|
10
|
+
"type": "git",
|
11
|
+
"url": "https://github.com/zayne-labs/toolkit.git"
|
12
|
+
},
|
13
|
+
"bugs": {
|
14
|
+
"url": "https://github.com/zayne-labs/toolkit/issues"
|
15
|
+
},
|
16
|
+
"keywords": [
|
17
|
+
"utilities",
|
18
|
+
"types",
|
19
|
+
"hooks"
|
20
|
+
],
|
21
|
+
"sideEffects": false,
|
22
|
+
"exports": {
|
23
|
+
".": "./dist/esm/hooks/index.js",
|
24
|
+
"./utils": "./dist/esm/utils/index.js",
|
25
|
+
"./zustand": "./dist/esm/zustand/index.js"
|
26
|
+
},
|
27
|
+
"main": "./dist/esm/hooks/index.js",
|
28
|
+
"module": "./dist/esm/hooks/index.js",
|
29
|
+
"types": "./dist/esm/hooks/index.d.ts",
|
30
|
+
"files": [
|
31
|
+
"dist"
|
32
|
+
],
|
33
|
+
"engines": {
|
34
|
+
"node": ">=18.x"
|
35
|
+
},
|
36
|
+
"peerDependencies": {
|
37
|
+
"react": ">=18.0.0",
|
38
|
+
"react-dom": ">=18.0.0",
|
39
|
+
"zustand": ">=4.0.0"
|
40
|
+
},
|
41
|
+
"peerDependenciesMeta": {
|
42
|
+
"react": {
|
43
|
+
"optional": true
|
44
|
+
},
|
45
|
+
"react-dom": {
|
46
|
+
"optional": true
|
47
|
+
},
|
48
|
+
"zustand": {
|
49
|
+
"optional": true
|
50
|
+
}
|
51
|
+
},
|
52
|
+
"dependencies": {
|
53
|
+
"@zayne-labs/toolkit-core": "0.8.22",
|
54
|
+
"@zayne-labs/toolkit-type-helpers": "0.8.22"
|
55
|
+
},
|
56
|
+
"devDependencies": {
|
57
|
+
"@arethetypeswrong/cli": "^0.17.2",
|
58
|
+
"@changesets/cli": "^2.27.11",
|
59
|
+
"@size-limit/esbuild-why": "^11.1.6",
|
60
|
+
"@size-limit/preset-small-lib": "^11.1.6",
|
61
|
+
"@total-typescript/ts-reset": "^0.6.1",
|
62
|
+
"@types/node": "^22.10.3",
|
63
|
+
"@types/react": "^19.0.2",
|
64
|
+
"@types/react-dom": "^19.0.2",
|
65
|
+
"@zayne-labs/tsconfig": "0.2.1",
|
66
|
+
"concurrently": "^9.1.2",
|
67
|
+
"cross-env": "^7.0.3",
|
68
|
+
"prettier-plugin-classnames": "^0.7.5",
|
69
|
+
"prettier-plugin-merge": "^0.7.2",
|
70
|
+
"prettier-plugin-tailwindcss": "^0.6.9",
|
71
|
+
"publint": "^0.2.12",
|
72
|
+
"react": "^19.0.0",
|
73
|
+
"react-dom": "^19.0.0",
|
74
|
+
"size-limit": "^11.1.6",
|
75
|
+
"tailwindcss": "^3.4.17",
|
76
|
+
"terser": "^5.37.0",
|
77
|
+
"tsup": "^8.3.5",
|
78
|
+
"typescript": "^5.7.2",
|
79
|
+
"zustand": "^5.0.2"
|
80
|
+
},
|
81
|
+
"publishConfig": {
|
82
|
+
"access": "public",
|
83
|
+
"registry": "https://registry.npmjs.org/",
|
84
|
+
"provenance": true
|
85
|
+
},
|
86
|
+
"size-limit": [
|
87
|
+
{
|
88
|
+
"path": "./src/hooks/index.ts",
|
89
|
+
"limit": "5.2 kb"
|
90
|
+
},
|
91
|
+
{
|
92
|
+
"path": "./src/utils/index.ts",
|
93
|
+
"limit": "1 kb"
|
94
|
+
},
|
95
|
+
{
|
96
|
+
"path": "./src/zustand/index.ts",
|
97
|
+
"limit": "600 b"
|
98
|
+
}
|
99
|
+
],
|
100
|
+
"scripts": {
|
101
|
+
"build": "tsup",
|
102
|
+
"build:dev": "cross-env NODE_ENV=development tsup",
|
103
|
+
"build:test": "concurrently --prefix-colors \"yellow.bold,#7da4f8.bold,magenta\" --names PUBLINT,TSUP 'pnpm:lint:publint' 'pnpm:build:dev'",
|
104
|
+
"lint:attw": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
|
105
|
+
"lint:check-types": "tsc --pretty --incremental -p tsconfig.json",
|
106
|
+
"lint:publint": "publint --strict .",
|
107
|
+
"lint:size": "size-limit",
|
108
|
+
"release": "pnpm publish --no-git-checks",
|
109
|
+
"test:release": "pnpx pkg-pr-new publish"
|
110
|
+
}
|
111
|
+
}
|