etudes 2.5.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Accordion.d.ts +16 -7
- package/lib/Accordion.js +36 -11
- package/lib/Accordion.js.map +1 -1
- package/lib/BurgerButton.d.ts +2 -2
- package/lib/BurgerButton.js +1 -1
- package/lib/BurgerButton.js.map +1 -1
- package/lib/Conditional.d.ts +1 -1
- package/lib/Conditional.js.map +1 -1
- package/lib/DebugConsole.d.ts +1 -1
- package/lib/DebugConsole.js.map +1 -1
- package/lib/Dial.d.ts +1 -1
- package/lib/Dial.js.map +1 -1
- package/lib/Dropdown.d.ts +13 -4
- package/lib/Dropdown.js +36 -15
- package/lib/Dropdown.js.map +1 -1
- package/lib/Each.d.ts +1 -1
- package/lib/Each.js.map +1 -1
- package/lib/ExtractChild.d.ts +1 -1
- package/lib/ExtractChild.js.map +1 -1
- package/lib/ExtractChildren.d.ts +1 -1
- package/lib/ExtractChildren.js.map +1 -1
- package/lib/FlatSVG.d.ts +1 -1
- package/lib/FlatSVG.js.map +1 -1
- package/lib/List.d.ts +1 -1
- package/lib/List.js.map +1 -1
- package/lib/MasonryGrid.d.ts +1 -1
- package/lib/MasonryGrid.js +10 -10
- package/lib/MasonryGrid.js.map +1 -1
- package/lib/Panorama.d.ts +15 -15
- package/lib/Panorama.js.map +1 -1
- package/lib/PanoramaSlider.d.ts +8 -8
- package/lib/PanoramaSlider.js +6 -6
- package/lib/PanoramaSlider.js.map +1 -1
- package/lib/RangeSlider.d.ts +1 -1
- package/lib/RangeSlider.js.map +1 -1
- package/lib/Repeat.d.ts +1 -1
- package/lib/Repeat.js.map +1 -1
- package/lib/RotatingGallery.d.ts +5 -5
- package/lib/RotatingGallery.js +2 -2
- package/lib/RotatingGallery.js.map +1 -1
- package/lib/SelectableButton.d.ts +1 -1
- package/lib/SelectableButton.js.map +1 -1
- package/lib/Slider.d.ts +11 -11
- package/lib/Slider.js +4 -4
- package/lib/Slider.js.map +1 -1
- package/lib/StepwiseSlider.d.ts +18 -18
- package/lib/StepwiseSlider.js +9 -9
- package/lib/StepwiseSlider.js.map +1 -1
- package/lib/SwipeContainer.d.ts +1 -1
- package/lib/SwipeContainer.js.map +1 -1
- package/lib/TextField.d.ts +1 -1
- package/lib/TextField.js.map +1 -1
- package/lib/Video.d.ts +1 -1
- package/lib/Video.js.map +1 -1
- package/lib/WithTooltip.d.ts +1 -1
- package/lib/WithTooltip.js.map +1 -1
- package/lib/hooks/useDragEffect.d.ts +15 -15
- package/lib/hooks/useDragEffect.js +6 -6
- package/lib/hooks/useDragEffect.js.map +1 -1
- package/lib/hooks/useElementRect.d.ts +2 -2
- package/lib/hooks/useElementRect.js +1 -1
- package/lib/hooks/useElementRect.js.map +1 -1
- package/lib/hooks/useInterval.d.ts +5 -5
- package/lib/hooks/useInterval.js +4 -4
- package/lib/hooks/useInterval.js.map +1 -1
- package/lib/hooks/useLoadImageEffect.d.ts +6 -6
- package/lib/hooks/useLoadImageEffect.js +3 -3
- package/lib/hooks/useLoadImageEffect.js.map +1 -1
- package/lib/hooks/usePrevious.d.ts +1 -1
- package/lib/hooks/usePrevious.js +1 -1
- package/lib/hooks/usePrevious.js.map +1 -1
- package/lib/hooks/useResizeEffect.d.ts +5 -5
- package/lib/hooks/useResizeEffect.js +3 -3
- package/lib/hooks/useResizeEffect.js.map +1 -1
- package/lib/hooks/useSearchParamState.d.ts +7 -7
- package/lib/hooks/useSearchParamState.js +3 -3
- package/lib/hooks/useSearchParamState.js.map +1 -1
- package/lib/providers/ScrollPositionProvider.d.ts +1 -1
- package/lib/providers/ScrollPositionProvider.js.map +1 -1
- package/lib/utils/asComponentDict.d.ts +1 -1
- package/lib/utils/asComponentDict.js.map +1 -1
- package/lib/utils/asStyleDict.d.ts +1 -1
- package/lib/utils/asStyleDict.js.map +1 -1
- package/lib/utils/cloneStyledElement.d.ts +6 -6
- package/lib/utils/cloneStyledElement.js.map +1 -1
- package/lib/utils/styles.d.ts +1 -1
- package/lib/utils/styles.js.map +1 -1
- package/package.json +12 -12
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DependencyList, Dispatch, RefObject, SetStateAction } from 'react';
|
|
1
|
+
import { type DependencyList, type Dispatch, type RefObject, type SetStateAction } from 'react';
|
|
2
2
|
type ReturnedStates<T> = {
|
|
3
3
|
isDragging: [boolean, Dispatch<SetStateAction<boolean>>];
|
|
4
4
|
isReleasing: [boolean, Dispatch<SetStateAction<boolean>>];
|
|
@@ -14,11 +14,11 @@ type Options<T> = Omit<InteractDraggableOptions, 'onstart' | 'onmove' | 'onend'>
|
|
|
14
14
|
* A function that transforms the drag move delta values to the associated
|
|
15
15
|
* value of this hook.
|
|
16
16
|
*
|
|
17
|
-
* @param currentValue
|
|
18
|
-
* @param dx
|
|
19
|
-
*
|
|
20
|
-
* @param dy
|
|
21
|
-
*
|
|
17
|
+
* @param currentValue The current associated value.
|
|
18
|
+
* @param dx The displacement on the x-axis (in pixels) since the last emitted
|
|
19
|
+
* drag move event.
|
|
20
|
+
* @param dy The displacement on the y-axis (in pixels) since the last emitted
|
|
21
|
+
* drag move event.
|
|
22
22
|
*
|
|
23
23
|
* @returns The transformed value.
|
|
24
24
|
*/
|
|
@@ -30,10 +30,10 @@ type Options<T> = Omit<InteractDraggableOptions, 'onstart' | 'onmove' | 'onend'>
|
|
|
30
30
|
/**
|
|
31
31
|
* Handler invoked when dragging.
|
|
32
32
|
*
|
|
33
|
-
* @param dx
|
|
34
|
-
*
|
|
35
|
-
* @param dy
|
|
36
|
-
*
|
|
33
|
+
* @param dx The displacement on the x-axis (in pixels) since the last emitted
|
|
34
|
+
* drag move event.
|
|
35
|
+
* @param dy The displacement on the y-axis (in pixels) since the last emitted
|
|
36
|
+
* drag move event.
|
|
37
37
|
*/
|
|
38
38
|
onDragMove?: (dx: number, dy: number) => void;
|
|
39
39
|
/**
|
|
@@ -44,11 +44,11 @@ type Options<T> = Omit<InteractDraggableOptions, 'onstart' | 'onmove' | 'onend'>
|
|
|
44
44
|
/**
|
|
45
45
|
* Hook for adding effectful dragging interaction to an element.
|
|
46
46
|
*
|
|
47
|
-
* @param targetRef
|
|
48
|
-
*
|
|
49
|
-
* @param options
|
|
50
|
-
*
|
|
51
|
-
* @param deps
|
|
47
|
+
* @param targetRef The reference to the target element to add drag interaction
|
|
48
|
+
* to.
|
|
49
|
+
* @param options Additional options which include options for
|
|
50
|
+
* `module:interactjs.draggable`.
|
|
51
|
+
* @param deps Dependencies that trigger this effect.
|
|
52
52
|
*
|
|
53
53
|
* @returns The states created for this effect.
|
|
54
54
|
*/
|
|
@@ -56,11 +56,11 @@ var react_1 = require("react");
|
|
|
56
56
|
/**
|
|
57
57
|
* Hook for adding effectful dragging interaction to an element.
|
|
58
58
|
*
|
|
59
|
-
* @param targetRef
|
|
60
|
-
*
|
|
61
|
-
* @param options
|
|
62
|
-
*
|
|
63
|
-
* @param deps
|
|
59
|
+
* @param targetRef The reference to the target element to add drag interaction
|
|
60
|
+
* to.
|
|
61
|
+
* @param options Additional options which include options for
|
|
62
|
+
* `module:interactjs.draggable`.
|
|
63
|
+
* @param deps Dependencies that trigger this effect.
|
|
64
64
|
*
|
|
65
65
|
* @returns The states created for this effect.
|
|
66
66
|
*/
|
|
@@ -72,7 +72,7 @@ function useDragEffect(targetRef, _a, deps) {
|
|
|
72
72
|
* states are asynchronous by nature, this reference object is used to cache
|
|
73
73
|
* time-sensitive value changes while drag event happens.
|
|
74
74
|
*
|
|
75
|
-
* @param value
|
|
75
|
+
* @param value The value to set the associated value to.
|
|
76
76
|
*
|
|
77
77
|
* @returns `true` if the value was set, `false` otherwise.
|
|
78
78
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDragEffect.js","sourceRoot":"/","sources":["hooks/useDragEffect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oEAAqC;AACrC,0DAAiC;AAC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AAC;QACR,IAAI,UAAU;YAAE,OAAM;QACtB,QAAQ,CAAC,YAAY,CAAC,CAAA;IACxB,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAA;IAElB,IAAA,iBAAS,EAAC;QACR,WAAW,CAAC,KAAK,CAAC,CAAA;IACpB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEX,OAAO;QACL,UAAU,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC;QACvC,WAAW,EAAE,CAAC,WAAW,EAAE,cAAc,CAAC;QAC1C,KAAK,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC;KACzB,CAAA;AACH,CAAC;AApFD,gCAoFC","sourcesContent":["import isEqual from 'fast-deep-equal'\nimport interact from 'interactjs'\nimport { useEffect, useRef, useState, type DependencyList, type Dispatch, type RefObject, type SetStateAction } from 'react'\n\ntype ReturnedStates<T> = {\n isDragging: [boolean, Dispatch<SetStateAction<boolean>>]\n isReleasing: [boolean, Dispatch<SetStateAction<boolean>>]\n value: [T, Dispatch<SetStateAction<T>>]\n}\n\ntype InteractDraggableOptions = Parameters<Interact.Interactable['draggable']>[0]\n\ntype Options<T> = Omit<InteractDraggableOptions, 'onstart' | 'onmove' | 'onend'> & {\n /**\n * The initial associated value of this hook.\n */\n initialValue: T\n\n /**\n * A function that transforms the drag move delta values to the associated\n * value of this hook.\n *\n * @param currentValue The current associated value.\n * @param dx The displacement on the x-axis (in pixels) since the last emitted\n * drag move event.\n * @param dy The displacement on the y-axis (in pixels) since the last emitted\n * drag move event.\n *\n * @returns The transformed value.\n */\n transform: (currentValue: T, dx: number, dy: number) => T\n\n /**\n * Handler invoked when dragging starts.\n */\n onDragStart?: () => void\n\n /**\n * Handler invoked when dragging.\n *\n * @param dx The displacement on the x-axis (in pixels) since the last emitted\n * drag move event.\n * @param dy The displacement on the y-axis (in pixels) since the last emitted\n * drag move event.\n */\n onDragMove?: (dx: number, dy: number) => void\n\n /**\n * Handler invoked when dragging ends.\n */\n onDragEnd?: () => void\n}\n\n/**\n * Hook for adding effectful dragging interaction to an element.\n *\n * @param targetRef The reference to the target element to add drag interaction\n * to.\n * @param options Additional options which include options for\n * `module:interactjs.draggable`.\n * @param deps Dependencies that trigger this effect.\n *\n * @returns The states created for this effect.\n */\nexport default function useDragEffect<T = [number, number]>(targetRef: RefObject<HTMLElement>, {\n initialValue,\n transform,\n onDragStart,\n onDragMove,\n onDragEnd,\n ...options\n}: Options<T>, deps?: DependencyList): ReturnedStates<T> {\n /**\n * Sets the current associated value reference. This reference object is equal\n * to the `value` state but differs slightly in how they are set. Because\n * states are asynchronous by nature, this reference object is used to cache\n * time-sensitive value changes while drag event happens.\n *\n * @param value The value to set the associated value to.\n *\n * @returns `true` if the value was set, `false` otherwise.\n */\n const setValueRef = (value: T): boolean => {\n if (isEqual(valueRef.current, value)) return false\n valueRef.current = value\n\n return true\n }\n\n const valueRef = useRef<T>(initialValue)\n const [hasDragged, setHasDragged] = useState<boolean>(false)\n const [isDragging, setIsDragging] = useState<boolean>(false)\n const [isReleasing, setIsReleasing] = useState<boolean>(false)\n const [value, setValue] = useState(initialValue)\n\n useEffect(() => {\n if (targetRef.current && !interact.isSet(targetRef.current)) {\n // Do not consume states in these listeners as they will remain their\n // initial values within the scope of the listeners.\n interact(targetRef.current).draggable({\n inertia: true,\n ...options,\n onstart: () => {\n setHasDragged(true)\n setIsDragging(true)\n setIsReleasing(false)\n onDragStart?.()\n },\n onmove: ({ dx, dy }) => {\n const newValue = transform(valueRef.current, dx, dy)\n\n if (setValueRef(newValue)) {\n setValue(newValue)\n }\n\n setIsDragging(true)\n setIsReleasing(false)\n onDragMove?.(dx, dy)\n },\n onend: () => {\n setIsDragging(false)\n setIsReleasing(true)\n onDragEnd?.()\n },\n })\n }\n\n return () => {\n if (targetRef.current && interact.isSet(targetRef.current)) {\n interact(targetRef.current).unset()\n }\n }\n }, [...deps ? deps : []])\n\n useEffect(() => {\n if (hasDragged) return\n setValue(initialValue)\n }, [initialValue])\n\n useEffect(() => {\n setValueRef(value)\n }, [value])\n\n return {\n isDragging: [isDragging, setIsDragging],\n isReleasing: [isReleasing, setIsReleasing],\n value: [value, setValue],\n }\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
2
|
import { Rect } from 'spase';
|
|
3
3
|
/**
|
|
4
4
|
* Hook for monitoring changes in and returning the size and position of the
|
|
5
5
|
* target element.
|
|
6
6
|
*
|
|
7
|
-
* @param targetRef
|
|
7
|
+
* @param targetRef Reference to the target element.
|
|
8
8
|
*
|
|
9
9
|
* @returns The most current {@link Rect} of the target element.
|
|
10
10
|
*/
|
|
@@ -26,7 +26,7 @@ var spase_1 = require("spase");
|
|
|
26
26
|
* Hook for monitoring changes in and returning the size and position of the
|
|
27
27
|
* target element.
|
|
28
28
|
*
|
|
29
|
-
* @param targetRef
|
|
29
|
+
* @param targetRef Reference to the target element.
|
|
30
30
|
*
|
|
31
31
|
* @returns The most current {@link Rect} of the target element.
|
|
32
32
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useElementRect.js","sourceRoot":"/","sources":["hooks/useElementRect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"useElementRect.js","sourceRoot":"/","sources":["hooks/useElementRect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,+BAAmE;AACnE,sFAAqD;AACrD,+BAA4B;AAE5B;;;;;;;GAOG;AACH,SAAwB,cAAc,CAAC,SAA6B;IAClE,IAAM,WAAW,GAAG,IAAA,cAAM,EAA6B,SAAS,CAAC,CAAA;IAC3D,IAAA,KAAA,OAAkB,IAAA,gBAAQ,EAAO,IAAI,YAAI,EAAE,CAAC,IAAA,EAA3C,IAAI,QAAA,EAAE,OAAO,QAA8B,CAAA;IAElD,IAAA,iBAAS,EAAC;QACR,WAAW,CAAC,OAAO,GAAG,IAAI,kCAAc,CAAC;YACvC,IAAM,OAAO,GAAG,YAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;YAE5C,IAAI,CAAC,OAAO;gBAAE,OAAM;YAEpB,OAAO,CAAC,OAAO,CAAC,CAAA;QAClB,CAAC,CAAC,CAAA;QAEF,IAAI,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;YAC5C,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;SAC/C;QAED,OAAO;YACL,IAAI,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;gBAC5C,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;aACjD;QACH,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IAEf,OAAO,IAAI,CAAA;AACb,CAAC;AAzBD,iCAyBC","sourcesContent":["import { useEffect, useRef, useState, type RefObject } from 'react'\nimport ResizeObserver from 'resize-observer-polyfill'\nimport { Rect } from 'spase'\n\n/**\n * Hook for monitoring changes in and returning the size and position of the\n * target element.\n *\n * @param targetRef Reference to the target element.\n *\n * @returns The most current {@link Rect} of the target element.\n */\nexport default function useElementRect(targetRef: RefObject<Element>): Rect {\n const observerRef = useRef<ResizeObserver | undefined>(undefined)\n const [rect, setRect] = useState<Rect>(new Rect())\n\n useEffect(() => {\n observerRef.current = new ResizeObserver(() => {\n const newRect = Rect.from(targetRef.current)\n\n if (!newRect) return\n\n setRect(newRect)\n })\n\n if (observerRef.current && targetRef.current) {\n observerRef.current.observe(targetRef.current)\n }\n\n return () => {\n if (observerRef.current && targetRef.current) {\n observerRef.current.unobserve(targetRef.current)\n }\n }\n }, [targetRef])\n\n return rect\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DependencyList } from 'react';
|
|
1
|
+
import { type DependencyList } from 'react';
|
|
2
2
|
type Options = {
|
|
3
3
|
/**
|
|
4
4
|
* Specifies if the handler should be invoked initially (as opposed to waiting
|
|
@@ -9,10 +9,10 @@ type Options = {
|
|
|
9
9
|
/**
|
|
10
10
|
* Hoook for invoking a method repeatedly on every set interval.
|
|
11
11
|
*
|
|
12
|
-
* @param handler
|
|
13
|
-
* @param timeout
|
|
14
|
-
* @param options
|
|
15
|
-
* @param deps
|
|
12
|
+
* @param handler The method to invoke on every interval.
|
|
13
|
+
* @param timeout Time (in milliseconds) between each invocation.
|
|
14
|
+
* @param options See {@link Options}.
|
|
15
|
+
* @param deps Dependencies that trigger this effect.
|
|
16
16
|
*/
|
|
17
17
|
export default function useInterval(handler: () => void, timeout?: number, { shouldInvokeInitially }?: Options, deps?: DependencyList): void;
|
|
18
18
|
export {};
|
package/lib/hooks/useInterval.js
CHANGED
|
@@ -29,10 +29,10 @@ var react_1 = require("react");
|
|
|
29
29
|
/**
|
|
30
30
|
* Hoook for invoking a method repeatedly on every set interval.
|
|
31
31
|
*
|
|
32
|
-
* @param handler
|
|
33
|
-
* @param timeout
|
|
34
|
-
* @param options
|
|
35
|
-
* @param deps
|
|
32
|
+
* @param handler The method to invoke on every interval.
|
|
33
|
+
* @param timeout Time (in milliseconds) between each invocation.
|
|
34
|
+
* @param options See {@link Options}.
|
|
35
|
+
* @param deps Dependencies that trigger this effect.
|
|
36
36
|
*/
|
|
37
37
|
function useInterval(handler, timeout, _a, deps) {
|
|
38
38
|
var _b = _a === void 0 ? {} : _a, _c = _b.shouldInvokeInitially, shouldInvokeInitially = _c === void 0 ? false : _c;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInterval.js","sourceRoot":"/","sources":["hooks/useInterval.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"useInterval.js","sourceRoot":"/","sources":["hooks/useInterval.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAA8D;AAU9D;;;;;;;GAOG;AACH,SAAwB,WAAW,CAAC,OAAmB,EAAE,OAAgB,EAAE,EAA+C,EAAE,IAAqB;QAAtE,qBAA6C,EAAE,KAAA,EAA7C,6BAA6B,EAA7B,qBAAqB,mBAAG,KAAK,KAAA;IACxG,IAAM,UAAU,GAAG,IAAA,cAAM,GAAgB,CAAA;IAEzC,IAAA,iBAAS,EAAC;QACR,UAAU,CAAC,OAAO,GAAG,OAAO,CAAA;IAC9B,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAEb,IAAA,iBAAS,EAAC;;QACR,IAAI,OAAO,KAAK,SAAS;YAAE,OAAM;QAEjC,IAAI,qBAAqB,KAAK,IAAI;YAAE,MAAA,UAAU,CAAC,OAAO,0DAAI,CAAA;QAC1D,IAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,sBAAM,OAAA,MAAA,UAAU,CAAC,OAAO,0DAAI,CAAA,EAAA,EAAE,OAAO,CAAC,CAAA;QAEvE,OAAO,cAAM,OAAA,aAAa,CAAC,KAAK,CAAC,EAApB,CAAoB,CAAA;IACnC,CAAC,yCAAM,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,YAAE,OAAO,UAAE,CAAA;AACpC,CAAC;AAfD,8BAeC","sourcesContent":["import { useEffect, useRef, type DependencyList } from 'react'\n\ntype Options = {\n /**\n * Specifies if the handler should be invoked initially (as opposed to waiting\n * for the specified interval for the initial invocation).\n */\n shouldInvokeInitially?: boolean\n}\n\n/**\n * Hoook for invoking a method repeatedly on every set interval.\n *\n * @param handler The method to invoke on every interval.\n * @param timeout Time (in milliseconds) between each invocation.\n * @param options See {@link Options}.\n * @param deps Dependencies that trigger this effect.\n */\nexport default function useInterval(handler: () => void, timeout?: number, { shouldInvokeInitially = false }: Options = {}, deps?: DependencyList) {\n const handlerRef = useRef<(() => void)>()\n\n useEffect(() => {\n handlerRef.current = handler\n }, [handler])\n\n useEffect(() => {\n if (timeout === undefined) return\n\n if (shouldInvokeInitially === true) handlerRef.current?.()\n const timer = window.setInterval(() => handlerRef.current?.(), timeout)\n\n return () => clearInterval(timer)\n }, [...deps ? deps : [], timeout])\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DependencyList, Dispatch, SetStateAction } from 'react';
|
|
1
|
+
import { type DependencyList, type Dispatch, type SetStateAction } from 'react';
|
|
2
2
|
import { Size } from 'spase';
|
|
3
3
|
type ReturnedStates = {
|
|
4
4
|
/**
|
|
@@ -16,7 +16,7 @@ type Options = {
|
|
|
16
16
|
/**
|
|
17
17
|
* Handler invoked when the image is done loading.
|
|
18
18
|
*
|
|
19
|
-
* @param imageElement
|
|
19
|
+
* @param imageElement The loaded image element.
|
|
20
20
|
*/
|
|
21
21
|
onImageLoadComplete?: (imageElement: HTMLImageElement) => void;
|
|
22
22
|
/**
|
|
@@ -27,16 +27,16 @@ type Options = {
|
|
|
27
27
|
* Handler invoked when the image size changes. If there is no loaded image,
|
|
28
28
|
* the size is `undefined`.
|
|
29
29
|
*
|
|
30
|
-
* @param size
|
|
30
|
+
* @param size The original image size.
|
|
31
31
|
*/
|
|
32
32
|
onImageSizeChange?: (size?: Size) => void;
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
35
35
|
* Hook for preloading an image.
|
|
36
36
|
*
|
|
37
|
-
* @param src
|
|
38
|
-
* @param options
|
|
39
|
-
* @param deps
|
|
37
|
+
* @param src The image source.
|
|
38
|
+
* @param options See {@link Options}.
|
|
39
|
+
* @param deps Additional dependencies.
|
|
40
40
|
*
|
|
41
41
|
* @returns See {@link ReturnedStates}.
|
|
42
42
|
*/
|
|
@@ -33,9 +33,9 @@ function getImageSize(imageElement) {
|
|
|
33
33
|
/**
|
|
34
34
|
* Hook for preloading an image.
|
|
35
35
|
*
|
|
36
|
-
* @param src
|
|
37
|
-
* @param options
|
|
38
|
-
* @param deps
|
|
36
|
+
* @param src The image source.
|
|
37
|
+
* @param options See {@link Options}.
|
|
38
|
+
* @param deps Additional dependencies.
|
|
39
39
|
*
|
|
40
40
|
* @returns See {@link ReturnedStates}.
|
|
41
41
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoadImageEffect.js","sourceRoot":"/","sources":["hooks/useLoadImageEffect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"useLoadImageEffect.js","sourceRoot":"/","sources":["hooks/useLoadImageEffect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAA4G;AAC5G,+BAA4B;AAsC5B,SAAS,YAAY,CAAC,YAA8B;IAClD,OAAO,IAAI,YAAI,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAA;AAC5D,CAAC;AAED;;;;;;;;GAQG;AACH,SAAwB,kBAAkB,CAAC,GAAY,EAAE,EAA0E,EAAE,IAAqB;QAAjG,qBAAwE,EAAE,KAAA,EAAxE,mBAAmB,yBAAA,EAAE,gBAAgB,sBAAA,EAAE,iBAAiB,uBAAA;IACjH,IAAM,wBAAwB,GAAG,UAAC,KAAY;QAC5C,IAAM,YAAY,GAAG,KAAK,CAAC,aAAiC,CAAA;QAC5D,IAAM,SAAS,GAAG,YAAY,CAAC,YAAY,CAAC,CAAA;QAE5C,YAAY,CAAC,KAAK,CAAC,CAAA;QACnB,YAAY,CAAC,SAAS,CAAC,CAAA;QAEvB,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAG,YAAY,CAAC,CAAA;IACrC,CAAC,CAAA;IAED,IAAM,qBAAqB,GAAG,UAAC,KAAY;QACzC,YAAY,CAAC,KAAK,CAAC,CAAA;QACnB,YAAY,CAAC,SAAS,CAAC,CAAA;QAEvB,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,EAAI,CAAA;IACtB,CAAC,CAAA;IAED,IAAM,QAAQ,GAAG,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AACH,CAAC;AA/CD,qCA+CC","sourcesContent":["import { useEffect, useRef, useState, type DependencyList, type Dispatch, type SetStateAction } from 'react'\nimport { Size } from 'spase'\n\ntype ReturnedStates = {\n /**\n * A tuple consisting of a stateful value indicating if the image is loading,\n * and a function that updates the loading state.\n */\n isLoading: [boolean, Dispatch<SetStateAction<boolean>>]\n\n /**\n * A tuple consisting of a stateful value representing the size of the image,\n * and a function that updates the size.\n */\n imageSize: [Size | undefined, Dispatch<SetStateAction<Size | undefined>>]\n}\n\ntype Options = {\n /**\n * Handler invoked when the image is done loading.\n *\n * @param imageElement The loaded image element.\n */\n onImageLoadComplete?: (imageElement: HTMLImageElement) => void\n\n /**\n * Handler invoked when there is an error loading the image.\n */\n onImageLoadError?: () => void\n\n /**\n * Handler invoked when the image size changes. If there is no loaded image,\n * the size is `undefined`.\n *\n * @param size The original image size.\n */\n onImageSizeChange?: (size?: Size) => void\n}\n\nfunction getImageSize(imageElement: HTMLImageElement): Size {\n return new Size([imageElement.width, imageElement.height])\n}\n\n/**\n * Hook for preloading an image.\n *\n * @param src The image source.\n * @param options See {@link Options}.\n * @param deps Additional dependencies.\n *\n * @returns See {@link ReturnedStates}.\n */\nexport default function useLoadImageEffect(src?: string, { onImageLoadComplete, onImageLoadError, onImageSizeChange }: Options = {}, deps?: DependencyList): ReturnedStates {\n const imageLoadCompleteHandler = (event: Event) => {\n const imageElement = event.currentTarget as HTMLImageElement\n const imageSize = getImageSize(imageElement)\n\n setIsLoading(false)\n setImageSize(imageSize)\n\n onImageLoadComplete?.(imageElement)\n }\n\n const imageLoadErrorHandler = (event: Event) => {\n setIsLoading(false)\n setImageSize(undefined)\n\n onImageLoadError?.()\n }\n\n const imageRef = useRef<HTMLImageElement | undefined>(undefined)\n const [isLoading, setIsLoading] = useState(true)\n const [imageSize, setImageSize] = useState<Size | undefined>(undefined)\n\n useEffect(() => {\n if (!src) return\n\n setIsLoading(true)\n\n imageRef.current = new Image()\n imageRef.current.src = src\n imageRef.current.addEventListener('load', imageLoadCompleteHandler)\n imageRef.current.addEventListener('error', imageLoadErrorHandler)\n\n return () => {\n imageRef.current?.removeEventListener('load', imageLoadCompleteHandler)\n imageRef.current?.removeEventListener('error', imageLoadErrorHandler)\n imageRef.current = undefined\n }\n }, [src, ...deps ? deps : []])\n\n useEffect(() => {\n onImageSizeChange?.(imageSize)\n }, [imageSize])\n\n return {\n isLoading: [isLoading, setIsLoading],\n imageSize: [imageSize, setImageSize],\n }\n}\n"]}
|
package/lib/hooks/usePrevious.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePrevious.js","sourceRoot":"/","sources":["hooks/usePrevious.ts"],"names":[],"mappings":";;AAAA,+BAAyC;AAEzC;;;;GAIG;AACH,SAAwB,WAAW,CAAI,WAAc;IACnD,IAAM,GAAG,GAAG,IAAA,cAAM,GAAK,CAAA;IAEvB,IAAA,iBAAS,EAAC;QACR,GAAG,CAAC,OAAO,GAAG,WAAW,CAAA;IAC3B,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;IAEjB,OAAO,GAAG,CAAC,OAAO,CAAA;AACpB,CAAC;AARD,8BAQC","sourcesContent":["import { useEffect, useRef } from 'react'\n\n/**\n * Returns the previous value of a state or prop.\n *\n * @param stateOrProp
|
|
1
|
+
{"version":3,"file":"usePrevious.js","sourceRoot":"/","sources":["hooks/usePrevious.ts"],"names":[],"mappings":";;AAAA,+BAAyC;AAEzC;;;;GAIG;AACH,SAAwB,WAAW,CAAI,WAAc;IACnD,IAAM,GAAG,GAAG,IAAA,cAAM,GAAK,CAAA;IAEvB,IAAA,iBAAS,EAAC;QACR,GAAG,CAAC,OAAO,GAAG,WAAW,CAAA;IAC3B,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;IAEjB,OAAO,GAAG,CAAC,OAAO,CAAA;AACpB,CAAC;AARD,8BAQC","sourcesContent":["import { useEffect, useRef } from 'react'\n\n/**\n * Returns the previous value of a state or prop.\n *\n * @param stateOrProp The state or prop.\n */\nexport default function usePrevious<T>(stateOrProp: T): T | undefined {\n const ref = useRef<T>()\n\n useEffect(() => {\n ref.current = stateOrProp\n }, [stateOrProp])\n\n return ref.current\n}\n"]}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { DependencyList, Dispatch, RefObject, SetStateAction } from 'react';
|
|
1
|
+
import { type DependencyList, type Dispatch, type RefObject, type SetStateAction } from 'react';
|
|
2
2
|
import { Size } from 'spase';
|
|
3
3
|
type Options = {
|
|
4
4
|
/**
|
|
5
5
|
* Handler invoked when the target element resizes.
|
|
6
6
|
*
|
|
7
|
-
* @param size
|
|
7
|
+
* @param size The current size of the target element.
|
|
8
8
|
*/
|
|
9
9
|
onResize?: (size: Size) => void;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* Hook for monitoring the resizing event of the target element.
|
|
13
13
|
*
|
|
14
|
-
* @param targetRef
|
|
15
|
-
* @param options
|
|
16
|
-
* @param deps
|
|
14
|
+
* @param targetRef Reference to the target element.
|
|
15
|
+
* @param options See {@link Options}.
|
|
16
|
+
* @param deps Additional dependencies.
|
|
17
17
|
*
|
|
18
18
|
* @returns A tuple consisting of a stateful value indicating the size of the
|
|
19
19
|
* target ref, and a function that sets its size.
|
|
@@ -34,9 +34,9 @@ var spase_1 = require("spase");
|
|
|
34
34
|
/**
|
|
35
35
|
* Hook for monitoring the resizing event of the target element.
|
|
36
36
|
*
|
|
37
|
-
* @param targetRef
|
|
38
|
-
* @param options
|
|
39
|
-
* @param deps
|
|
37
|
+
* @param targetRef Reference to the target element.
|
|
38
|
+
* @param options See {@link Options}.
|
|
39
|
+
* @param deps Additional dependencies.
|
|
40
40
|
*
|
|
41
41
|
* @returns A tuple consisting of a stateful value indicating the size of the
|
|
42
42
|
* target ref, and a function that sets its size.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResizeEffect.js","sourceRoot":"/","sources":["hooks/useResizeEffect.ts"],"names":[],"mappings":";;;;;;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AC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,UAAE,CAAA;IAEpC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AACxB,CAAC;AA5BD,kCA4BC","sourcesContent":["import { useEffect, useRef, useState, type DependencyList, type Dispatch, type RefObject, type SetStateAction } from 'react'\nimport ResizeObserver from 'resize-observer-polyfill'\nimport { Rect, Size } from 'spase'\n\ntype Options = {\n /**\n * Handler invoked when the target element resizes.\n *\n * @param size The current size of the target element.\n */\n onResize?: (size: Size) => void\n}\n\n/**\n * Hook for monitoring the resizing event of the target element.\n *\n * @param targetRef Reference to the target element.\n * @param options See {@link Options}.\n * @param deps Additional dependencies.\n *\n * @returns A tuple consisting of a stateful value indicating the size of the\n * target ref, and a function that sets its size.\n */\nexport default function useResizeEffect(targetRef: RefObject<Element>, { onResize }: Options = {}, deps?: DependencyList): [Size, Dispatch<SetStateAction<Size>>] {\n const observerRef = useRef<ResizeObserver | undefined>(undefined)\n const [size, setSize] = useState<Size>(new Size())\n\n useEffect(() => {\n observerRef.current = new ResizeObserver(() => {\n const rect = Rect.from(targetRef.current)\n\n if (!rect) return\n\n const newSize = rect.size\n\n setSize(newSize)\n onResize?.(newSize)\n })\n\n if (observerRef.current && targetRef.current) {\n observerRef.current.observe(targetRef.current)\n }\n\n return () => {\n if (observerRef.current && targetRef.current) {\n observerRef.current.unobserve(targetRef.current)\n }\n }\n }, [targetRef, ...deps ? deps : []])\n\n return [size, setSize]\n}\n"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction } from 'react';
|
|
1
|
+
import { type Dispatch, type SetStateAction } from 'react';
|
|
2
2
|
export type Options<T> = {
|
|
3
3
|
/**
|
|
4
4
|
* Function for transforming the search param value to the value of the mapped
|
|
5
5
|
* state.
|
|
6
6
|
*
|
|
7
|
-
* @param value
|
|
8
|
-
*
|
|
7
|
+
* @param value The search param value. `undefined` means the value is
|
|
8
|
+
* unavailable.
|
|
9
9
|
*
|
|
10
10
|
* @returns The equivalent state value.
|
|
11
11
|
*/
|
|
@@ -14,7 +14,7 @@ export type Options<T> = {
|
|
|
14
14
|
* Function for transforming the value of the mapped state to the search param
|
|
15
15
|
* value.
|
|
16
16
|
*
|
|
17
|
-
* @param state
|
|
17
|
+
* @param state The state value.
|
|
18
18
|
*
|
|
19
19
|
* @returns The equivalent search param value.
|
|
20
20
|
*/
|
|
@@ -24,9 +24,9 @@ export type Options<T> = {
|
|
|
24
24
|
* Hook for mapping a search param to a state. Whenever the value of the target
|
|
25
25
|
* search param changes, the mapped state will change as well, and vice versa.
|
|
26
26
|
*
|
|
27
|
-
* @param param
|
|
28
|
-
* @param defaultValue
|
|
29
|
-
* @param options
|
|
27
|
+
* @param param The search param key.
|
|
28
|
+
* @param defaultValue The default value of the state.
|
|
29
|
+
* @param options See {@link Options}.
|
|
30
30
|
*
|
|
31
31
|
* @returns A tuple consisting of a stateful value representing the current
|
|
32
32
|
* value of the mapped state and a function that updates it.
|
|
@@ -27,9 +27,9 @@ var debug = (0, useDebug_1.default)('hooks');
|
|
|
27
27
|
* Hook for mapping a search param to a state. Whenever the value of the target
|
|
28
28
|
* search param changes, the mapped state will change as well, and vice versa.
|
|
29
29
|
*
|
|
30
|
-
* @param param
|
|
31
|
-
* @param defaultValue
|
|
32
|
-
* @param options
|
|
30
|
+
* @param param The search param key.
|
|
31
|
+
* @param defaultValue The default value of the state.
|
|
32
|
+
* @param options See {@link Options}.
|
|
33
33
|
*
|
|
34
34
|
* @returns A tuple consisting of a stateful value representing the current
|
|
35
35
|
* value of the mapped state and a function that updates it.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSearchParamState.js","sourceRoot":"/","sources":["hooks/useSearchParamState.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"useSearchParamState.js","sourceRoot":"/","sources":["hooks/useSearchParamState.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;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,GAAG,CAAC,KAAK,CAAC,CAAA;QACrC,IAAM,QAAQ,GAAG,4BAA4B,CAAC,KAAK,CAAC,CAAA;QAEpD,IAAI,QAAQ,KAAK,KAAK;YAAE,OAAM;QAE9B,IAAI,CAAC,QAAQ,EAAE;YACb,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;SAC3B;aACI;YACH,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;SAClC;QAED,KAAK,CAAC,0BAA0B,EAAE,IAAI,EAAE,gBAAS,KAAK,wBAAc,KAAK,wBAAc,QAAQ,CAAE,CAAC,CAAA;QAElG,eAAe,CAAC,YAAY,CAAC,CAAA;IAC/B,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEX,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;AAC1B,CAAC;AAlDD,sCAkDC","sourcesContent":["import { useEffect, useState, type Dispatch, type SetStateAction } from 'react'\nimport { useSearchParams } from 'react-router-dom'\nimport useDebug from '../utils/useDebug'\n\nconst debug = useDebug('hooks')\n\nexport type Options<T> = {\n /**\n * Function for transforming the search param value to the value of the mapped\n * state.\n *\n * @param value The search param value. `undefined` means the value is\n * unavailable.\n *\n * @returns The equivalent state value.\n */\n mapSearchParamToState?: (value?: string) => T\n\n /**\n * Function for transforming the value of the mapped state to the search param\n * value.\n *\n * @param state The state value.\n *\n * @returns The equivalent search param value.\n */\n mapStateToSearchParam?: (state: T) => string | undefined\n}\n\n/**\n * Hook for mapping a search param to a state. Whenever the value of the target\n * search param changes, the mapped state will change as well, and vice versa.\n *\n * @param param The search param key.\n * @param defaultValue The default value of the state.\n * @param options See {@link Options}.\n *\n * @returns A tuple consisting of a stateful value representing the current\n * value of the mapped state and a function that updates it.\n */\nexport default function useSearchParamState<T>(param: string, defaultValue: T, { mapSearchParamToState, mapStateToSearchParam }: Options<T> = {}): [T, Dispatch<SetStateAction<T>>] {\n const defaultMapSearchParamToState = (value: string | undefined, fallback: T): T => {\n if (mapSearchParamToState) {\n return mapSearchParamToState(value)\n }\n else if (!value) {\n return fallback\n }\n else {\n return value as unknown as NonNullable<T>\n }\n }\n\n const defaultMapStateToSearchParam = (state: T): string | undefined => {\n if (mapStateToSearchParam) {\n return mapStateToSearchParam(state)\n }\n else if (state === defaultValue) {\n return undefined\n }\n else {\n return `${state}`\n }\n }\n\n const [searchParams, setSearchParams] = useSearchParams()\n const currentState = defaultMapSearchParamToState(searchParams.get(param) ?? undefined, defaultValue)\n const [state, setState] = useState(currentState)\n\n debug('Using search param state...', 'OK', `param=${param}, defaultValue=${currentState}`)\n\n useEffect(() => {\n const value = searchParams.get(param)\n const newValue = defaultMapStateToSearchParam(state)\n\n if (newValue === value) return\n\n if (!newValue) {\n searchParams.delete(param)\n }\n else {\n searchParams.set(param, newValue)\n }\n\n debug('Handling state change...', 'OK', `state=${state}, oldValue=${value}, newValue=${newValue}`)\n\n setSearchParams(searchParams)\n }, [state])\n\n return [state, setState]\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScrollPositionProvider.js","sourceRoot":"/","sources":["providers/ScrollPositionProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"ScrollPositionProvider.js","sourceRoot":"/","sources":["providers/ScrollPositionProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAqH;AACrH,+BAAmC;AActB,QAAA,qBAAqB,GAAG,IAAA,qBAAa,EAAyC,SAAS,CAAC,CAAA;AAErG,SAAwB,sBAAsB,CAAC,EAEjB;QAD5B,QAAQ,cAAA;IAEF,IAAA,KAAA,OAAoB,IAAA,gBAAQ,EAA6B;QAC7D,MAAM,EAAE,IAAI,aAAK,EAAE;QACnB,MAAM,EAAE,IAAI,aAAK,EAAE;QACnB,GAAG,EAAE,IAAI,aA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I,CAAC,IAAI,CAAA;IACtC,IAAM,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAA;IACtC,IAAM,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC,KAAK,CAAA;IAC/B,IAAM,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC,MAAM,CAAA;IAEhC,OAAO;QACL,GAAG,EAAE,IAAI,aAAK,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC5B,IAAI,EAAE,IAAI,aAAK,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;KAChC,CAAA;AACH,CAAC;AAhCD,8CAgCC","sourcesContent":["import React, { createContext, useContext, useEffect, useState, type PropsWithChildren, type RefObject } from 'react'\nimport { Point, Rect } from 'spase'\n\ntype ScrollPosition = {\n pos: Point\n step: Point\n}\n\ntype ScrollPositionContextValue = ScrollPosition & {\n minPos: Point\n maxPos: Point\n}\n\ntype ScrollPositionProviderProps = PropsWithChildren\n\nexport const ScrollPositionContext = createContext<ScrollPositionContextValue | undefined>(undefined)\n\nexport default function ScrollPositionProvider({\n children,\n}: ScrollPositionProviderProps) {\n const [value, setValue] = useState<ScrollPositionContextValue>({\n minPos: new Point(),\n maxPos: new Point(),\n pos: new Point(),\n step: new Point(),\n })\n\n useEffect(() => {\n const updateScrollPosition = () => {\n const refRect = Rect.fromViewport()\n const refRectMin = refRect.clone({ x: 0, y: 0 })\n const refRectFull = Rect.from(window, { overflow: true })\n\n if (!refRectFull) return\n\n const refRectMax = refRectMin.clone({ x: refRectFull.width - refRect.width, y: refRectFull.height - refRect.height })\n const step = new Point([refRect.left / refRectMax.left, refRect.top / refRectMax.top])\n\n setValue({\n minPos: new Point([refRectMin.left, refRectMin.top]),\n maxPos: new Point([refRectMax.left, refRectMax.top]),\n pos: new Point([refRect.left, refRect.top]),\n step,\n })\n }\n\n window.addEventListener('scroll', updateScrollPosition)\n window.addEventListener('resize', updateScrollPosition)\n window.addEventListener('orientationchange', updateScrollPosition)\n\n updateScrollPosition()\n\n return () => {\n window.removeEventListener('scroll', updateScrollPosition)\n window.removeEventListener('resize', updateScrollPosition)\n window.removeEventListener('orientationchange', updateScrollPosition)\n }\n }, [])\n\n return (\n <ScrollPositionContext.Provider value={value}>\n {children}\n </ScrollPositionContext.Provider>\n )\n}\n\nexport function useScrollPosition(targetRef?: RefObject<Element>): ScrollPosition {\n const context = useContext(ScrollPositionContext)\n if (!context) throw Error('Cannot fetch the current scroll position context, is the corresponding provider instated?')\n\n if (!targetRef) {\n return {\n pos: context.pos,\n step: context.step,\n }\n }\n\n const element = targetRef.current\n\n const refRect = Rect.fromViewport()\n const rect = Rect.from(element)\n\n if (!refRect || !rect) {\n return {\n pos: new Point(),\n step: new Point(),\n }\n }\n\n const posX = refRect.right - rect.left\n const posY = refRect.bottom - rect.top\n const stepX = posX / rect.width\n const stepY = posY / rect.height\n\n return {\n pos: new Point([posX, posY]),\n step: new Point([stepX, stepY]),\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSXElementConstructor, ReactNode } from 'react';
|
|
1
|
+
import { type JSXElementConstructor, type ReactNode } from 'react';
|
|
2
2
|
type ComponentTypeDict = Record<string, JSXElementConstructor<any>>;
|
|
3
3
|
type ComponentElementDict<T extends ComponentTypeDict> = Record<keyof T, JSX.Element>;
|
|
4
4
|
export default function asComponentDict<T extends ComponentTypeDict>(children?: ReactNode, typeDict?: T): Partial<ComponentElementDict<T>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asComponentDict.js","sourceRoot":"/","sources":["utils/asComponentDict.ts"],"names":[],"mappings":";;AAAA,+
|
|
1
|
+
{"version":3,"file":"asComponentDict.js","sourceRoot":"/","sources":["utils/asComponentDict.ts"],"names":[],"mappings":";;AAAA,+BAA4F;AAM5F,SAAwB,eAAe,CAA8B,QAAoB,EAAE,QAAqB;IAArB,yBAAA,EAAA,WAAc,EAAO;IAC9G,IAAM,IAAI,GAAgB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC/C,IAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACrC,IAAM,UAAU,GAAqC,EAAE,CAAA;IAEvD,gBAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAA,KAAK;QAC9B,IAAI,CAAC,IAAA,sBAAc,EAAC,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC,wBAAwB,CAAC,CAAA;QAEjE,IAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAW,CAAC,CAAA;QAC9C,IAAI,KAAK,GAAG,CAAC;YAAE,MAAM,KAAK,CAAC,sEAA+D,KAAK,CAAE,CAAC,CAAA;QAElG,IAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;QACvB,IAAI,UAAU,CAAC,GAAG,CAAC;YAAE,MAAM,KAAK,CAAC,mBAAY,KAAK,CAAC,KAAK,CAAC,gCAA6B,CAAC,CAAA;QAEvF,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;IACzB,CAAC,CAAC,CAAA;IAEF,OAAO,UAAU,CAAA;AACnB,CAAC;AAlBD,kCAkBC","sourcesContent":["import { Children, isValidElement, type JSXElementConstructor, type ReactNode } from 'react'\n\ntype ComponentTypeDict = Record<string, JSXElementConstructor<any>>\n\ntype ComponentElementDict<T extends ComponentTypeDict> = Record<keyof T, JSX.Element>\n\nexport default function asComponentDict<T extends ComponentTypeDict>(children?: ReactNode, typeDict: T = {} as T): Partial<ComponentElementDict<T>> {\n const keys: (keyof T)[] = Object.keys(typeDict)\n const types = Object.values(typeDict)\n const components: Partial<ComponentElementDict<T>> = {}\n\n Children.forEach(children, child => {\n if (!isValidElement(child)) throw Error('Invalid child detected')\n\n const index = types.indexOf(child.type as any)\n if (index < 0) throw Error(`Unsupported child, only the following children are allowed: ${types}`)\n\n const key = keys[index]\n if (components[key]) throw Error(`Only one ${types[index]} can be provided as a child`)\n\n components[key] = child\n })\n\n return components\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asStyleDict.js","sourceRoot":"/","sources":["utils/asStyleDict.ts"],"names":[],"mappings":";;AAEA,SAAwB,WAAW,CAAI,IAAuC;IAC5E,OAAO,IAAI,CAAA;AACb,CAAC;AAFD,8BAEC","sourcesContent":["import { CSSProperties } from 'react'\n\nexport default function asStyleDict<T>(dict: { [K in keyof T]: CSSProperties }) {\n return dict\n}\n"]}
|
|
1
|
+
{"version":3,"file":"asStyleDict.js","sourceRoot":"/","sources":["utils/asStyleDict.ts"],"names":[],"mappings":";;AAEA,SAAwB,WAAW,CAAI,IAAuC;IAC5E,OAAO,IAAI,CAAA;AACb,CAAC;AAFD,8BAEC","sourcesContent":["import { type CSSProperties } from 'react'\n\nexport default function asStyleDict<T>(dict: { [K in keyof T]: CSSProperties }) {\n return dict\n}\n"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Attributes, CElement, ClassAttributes, Component, ComponentState, FunctionComponentElement, ReactElement, ReactNode } from 'react';
|
|
1
|
+
import { type Attributes, type CElement, type ClassAttributes, type Component, type ComponentState, type FunctionComponentElement, type ReactElement, type ReactNode } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* Wrapper for {@link cloneElement} but instead of overwriting `className` and
|
|
4
4
|
* `style` of the cloned element with the values specified in the `props`
|
|
5
5
|
* argument, they are merged instead.
|
|
6
6
|
*
|
|
7
|
-
* @param element
|
|
8
|
-
* @param props
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @param children
|
|
7
|
+
* @param element The target element to clone.
|
|
8
|
+
* @param props The props to apply to the cloned element. Overlapping props are
|
|
9
|
+
* overwritten with the exception of `className` and `style`, which
|
|
10
|
+
* are merged.
|
|
11
|
+
* @param children Optional child elements add into the cloned element.
|
|
12
12
|
*
|
|
13
13
|
* @returns The cloned element.
|
|
14
14
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloneStyledElement.js","sourceRoot":"/","sources":["utils/cloneStyledElement.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"cloneStyledElement.js","sourceRoot":"/","sources":["utils/cloneStyledElement.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAiM;AAkBjM,SAAS,kBAAkB,CACzB,OAAuE,EACvE,KAAqE;;IAArE,sBAAA,EAAA,UAAqE;IACrE,kBAAwB;SAAxB,UAAwB,EAAxB,qBAAwB,EAAxB,IAAwB;QAAxB,iCAAwB;;IAExB,IAAM,KAAsC,KAAY,EAAhD,SAAS,eAAA,EAAE,KAAK,WAAA,EAAK,UAAU,cAAjC,sBAAmC,CAAe,CAAA;IACxD,IAAM,YAAY,GAAG,OAAO,CAAC,KAAY,CAAA;IAEzC,OAAO,oBAAY,8BAAC,OAAO,EAAE,WAC3B,SAAS,EAAE,UAAG,MAAA,YAAY,CAAC,SAAS,mCAAI,EAAE,cAAI,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,EAAE,CAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EACpG,KAAK,wBACA,MAAA,YAAY,CAAC,KAAK,mCAAI,EAAE,GACxB,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,KAEb,UAAU,CACP,UAAK,QAAQ,WAAC;AACxB,CAAC;AAED,kBAAe,kBAAkB,CAAA","sourcesContent":["import { cloneElement, type Attributes, type CElement, type ClassAttributes, type Component, type ComponentState, type FunctionComponentElement, type ReactElement, type ReactNode } from 'react'\n\n/**\n * Wrapper for {@link cloneElement} but instead of overwriting `className` and\n * `style` of the cloned element with the values specified in the `props`\n * argument, they are merged instead.\n *\n * @param element The target element to clone.\n * @param props The props to apply to the cloned element. Overlapping props are\n * overwritten with the exception of `className` and `style`, which\n * are merged.\n * @param children Optional child elements add into the cloned element.\n *\n * @returns The cloned element.\n */\nfunction cloneStyledElement<P>(element: FunctionComponentElement<P>, props?: Partial<P> & Attributes, ...children: ReactNode[]): FunctionComponentElement<P>\nfunction cloneStyledElement<P, T extends Component<P, ComponentState>>(element: CElement<P, T>, props?: Partial<P> & ClassAttributes<T>, ...children: ReactNode[]): CElement<P, T>\nfunction cloneStyledElement<P>(element: ReactElement<P>, props?: Partial<P> & Attributes, ...children: ReactNode[]): ReactElement<P>\nfunction cloneStyledElement<P, T extends Component<P, ComponentState> = never>(\n element: FunctionComponentElement<P> | CElement<P, T> | ReactElement<P>,\n props: Partial<P> & Attributes | Partial<P> & ClassAttributes<T> = {},\n ...children: ReactNode[]\n) {\n const { className, style, ...otherProps } = props as any\n const elementProps = element.props as any\n\n return cloneElement(element, {\n className: `${elementProps.className ?? ''} ${className ?? ''}`.split(' ').filter(Boolean).join(' '),\n style: {\n ...elementProps.style ?? {},\n ...style ?? {},\n },\n ...otherProps,\n } as any, ...children)\n}\n\nexport default cloneStyledElement\n"]}
|
package/lib/utils/styles.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CSSProperties } from 'react';
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
2
|
export default function styles(...args: (CSSProperties | undefined | false)[]): CSSProperties;
|
package/lib/utils/styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sourceRoot":"/","sources":["utils/styles.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,SAAwB,MAAM;IAAC,cAA8C;SAA9C,UAA8C,EAA9C,qBAA8C,EAA9C,IAA8C;QAA9C,yBAA8C;;IAC3E,OAAO,IAAI,CAAC,MAAM,CAAgB,UAAC,GAAG,EAAE,IAAI,IAAK,OAAA,uBAC5C,GAAG,GACH,IAAI,IAAI,EAAE,EACb,EAH+C,CAG/C,EAAE,EAAE,CAAC,CAAA;AACT,CAAC;AALD,yBAKC","sourcesContent":["import { CSSProperties } from 'react'\n\nexport default function styles(...args: (CSSProperties | undefined | false)[]): CSSProperties {\n return args.reduce<CSSProperties>((out, curr) => ({\n ...out,\n ...curr || {},\n }), {})\n}\n"]}
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"/","sources":["utils/styles.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,SAAwB,MAAM;IAAC,cAA8C;SAA9C,UAA8C,EAA9C,qBAA8C,EAA9C,IAA8C;QAA9C,yBAA8C;;IAC3E,OAAO,IAAI,CAAC,MAAM,CAAgB,UAAC,GAAG,EAAE,IAAI,IAAK,OAAA,uBAC5C,GAAG,GACH,IAAI,IAAI,EAAE,EACb,EAH+C,CAG/C,EAAE,EAAE,CAAC,CAAA;AACT,CAAC;AALD,yBAKC","sourcesContent":["import { type CSSProperties } from 'react'\n\nexport default function styles(...args: (CSSProperties | undefined | false)[]): CSSProperties {\n return args.reduce<CSSProperties>((out, curr) => ({\n ...out,\n ...curr || {},\n }), {})\n}\n"]}
|