etudes 5.2.0 → 5.3.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/components/Accordion.js +171 -205
- package/components/BurgerButton.js +40 -94
- package/components/Carousel.js +87 -123
- package/components/Collection.js +84 -120
- package/components/Counter.js +32 -63
- package/components/CoverImage.js +24 -68
- package/components/CoverVideo.js +25 -69
- package/components/DebugConsole.js +27 -79
- package/components/Dial.js +28 -65
- package/components/Dropdown.js +86 -98
- package/components/FlatSVG.js +22 -71
- package/components/Image.js +21 -50
- package/components/MasonryGrid.js +122 -257
- package/components/Panorama.js +48 -92
- package/components/PanoramaSlider.js +57 -113
- package/components/RangeSlider.js +125 -182
- package/components/RotatingGallery.js +28 -59
- package/components/SelectableButton.js +10 -54
- package/components/Slider.js +108 -159
- package/components/StepwiseSlider.js +124 -176
- package/components/SwipeContainer.js +30 -73
- package/components/TextField.js +12 -49
- package/components/Video.js +31 -61
- package/components/WithTooltip.js +117 -111
- package/components/index.js +24 -0
- package/hooks/index.js +17 -0
- package/hooks/useClickOutsideEffect.js +8 -38
- package/hooks/useDragEffect.js +20 -53
- package/hooks/useDragValueEffect.js +31 -81
- package/hooks/useImageSize.js +16 -38
- package/hooks/useInterval.js +9 -41
- package/hooks/useLoadImageEffect.js +15 -48
- package/hooks/useLoadVideoMetadataEffect.js +15 -48
- package/hooks/useMounted.js +5 -25
- package/hooks/usePrevious.js +4 -9
- package/hooks/useRect.js +9 -29
- package/hooks/useResizeEffect.js +10 -44
- package/hooks/useScrollPositionEffect.js +19 -50
- package/hooks/useSearchParamState.js +12 -34
- package/hooks/useSize.js +9 -29
- package/hooks/useTimeout.js +8 -38
- package/hooks/useVideoSize.js +16 -38
- package/hooks/useViewportSize.js +7 -27
- package/operators/Conditional.js +6 -11
- package/operators/Each.js +6 -14
- package/operators/ExtractChild.js +9 -36
- package/operators/ExtractChildren.js +7 -34
- package/operators/Repeat.js +4 -37
- package/operators/index.js +5 -0
- package/package.json +27 -41
- package/providers/ScrollPositionProvider.js +37 -60
- package/providers/index.js +1 -0
- package/utils/asClassNameDict.js +1 -5
- package/utils/asComponentDict.js +11 -16
- package/utils/asStyleDict.js +1 -5
- package/utils/cloneStyledElement.js +14 -61
- package/utils/index.js +5 -22
- package/utils/styles.js +5 -21
- package/components/Accordion.d.ts +0 -219
- package/components/Accordion.js.map +0 -1
- package/components/BurgerButton.d.ts +0 -34
- package/components/BurgerButton.js.map +0 -1
- package/components/Carousel.d.ts +0 -53
- package/components/Carousel.js.map +0 -1
- package/components/Collection.d.ts +0 -171
- package/components/Collection.js.map +0 -1
- package/components/Counter.d.ts +0 -11
- package/components/Counter.js.map +0 -1
- package/components/CoverImage.d.ts +0 -28
- package/components/CoverImage.js.map +0 -1
- package/components/CoverVideo.d.ts +0 -28
- package/components/CoverVideo.js.map +0 -1
- package/components/DebugConsole.d.ts +0 -15
- package/components/DebugConsole.js.map +0 -1
- package/components/Dial.d.ts +0 -79
- package/components/Dial.js.map +0 -1
- package/components/Dropdown.d.ts +0 -109
- package/components/Dropdown.js.map +0 -1
- package/components/FlatSVG.d.ts +0 -72
- package/components/FlatSVG.js.map +0 -1
- package/components/Image.d.ts +0 -144
- package/components/Image.js.map +0 -1
- package/components/MasonryGrid.d.ts +0 -29
- package/components/MasonryGrid.js.map +0 -1
- package/components/Panorama.d.ts +0 -77
- package/components/Panorama.js.map +0 -1
- package/components/PanoramaSlider.d.ts +0 -71
- package/components/PanoramaSlider.js.map +0 -1
- package/components/RangeSlider.d.ts +0 -34
- package/components/RangeSlider.js.map +0 -1
- package/components/RotatingGallery.d.ts +0 -91
- package/components/RotatingGallery.js.map +0 -1
- package/components/SelectableButton.d.ts +0 -19
- package/components/SelectableButton.js.map +0 -1
- package/components/Slider.d.ts +0 -160
- package/components/Slider.js.map +0 -1
- package/components/StepwiseSlider.d.ts +0 -215
- package/components/StepwiseSlider.js.map +0 -1
- package/components/SwipeContainer.d.ts +0 -21
- package/components/SwipeContainer.js.map +0 -1
- package/components/TextField.d.ts +0 -21
- package/components/TextField.js.map +0 -1
- package/components/Video.d.ts +0 -38
- package/components/Video.js.map +0 -1
- package/components/WithTooltip.d.ts +0 -32
- package/components/WithTooltip.js.map +0 -1
- package/hooks/useClickOutsideEffect.d.ts +0 -2
- package/hooks/useClickOutsideEffect.js.map +0 -1
- package/hooks/useDragEffect.d.ts +0 -48
- package/hooks/useDragEffect.js.map +0 -1
- package/hooks/useDragValueEffect.d.ts +0 -56
- package/hooks/useDragValueEffect.js.map +0 -1
- package/hooks/useImageSize.d.ts +0 -21
- package/hooks/useImageSize.js.map +0 -1
- package/hooks/useInterval.d.ts +0 -18
- package/hooks/useInterval.js.map +0 -1
- package/hooks/useLoadImageEffect.d.ts +0 -43
- package/hooks/useLoadImageEffect.js.map +0 -1
- package/hooks/useLoadVideoMetadataEffect.d.ts +0 -35
- package/hooks/useLoadVideoMetadataEffect.js.map +0 -1
- package/hooks/useMounted.d.ts +0 -1
- package/hooks/useMounted.js.map +0 -1
- package/hooks/usePrevious.d.ts +0 -19
- package/hooks/usePrevious.js.map +0 -1
- package/hooks/useRect.d.ts +0 -11
- package/hooks/useRect.js.map +0 -1
- package/hooks/useResizeEffect.d.ts +0 -17
- package/hooks/useResizeEffect.js.map +0 -1
- package/hooks/useScrollPositionEffect.d.ts +0 -13
- package/hooks/useScrollPositionEffect.js.map +0 -1
- package/hooks/useSearchParamState.d.ts +0 -34
- package/hooks/useSearchParamState.js.map +0 -1
- package/hooks/useSize.d.ts +0 -10
- package/hooks/useSize.js.map +0 -1
- package/hooks/useTimeout.d.ts +0 -10
- package/hooks/useTimeout.js.map +0 -1
- package/hooks/useVideoSize.d.ts +0 -21
- package/hooks/useVideoSize.js.map +0 -1
- package/hooks/useViewportSize.d.ts +0 -7
- package/hooks/useViewportSize.js.map +0 -1
- package/operators/Conditional.d.ts +0 -5
- package/operators/Conditional.js.map +0 -1
- package/operators/Each.d.ts +0 -7
- package/operators/Each.js.map +0 -1
- package/operators/ExtractChild.d.ts +0 -8
- package/operators/ExtractChild.js.map +0 -1
- package/operators/ExtractChildren.d.ts +0 -6
- package/operators/ExtractChildren.js.map +0 -1
- package/operators/Repeat.d.ts +0 -11
- package/operators/Repeat.js.map +0 -1
- package/providers/ScrollPositionProvider.d.ts +0 -15
- package/providers/ScrollPositionProvider.js.map +0 -1
- package/utils/asClassNameDict.d.ts +0 -3
- package/utils/asClassNameDict.js.map +0 -1
- package/utils/asComponentDict.d.ts +0 -5
- package/utils/asComponentDict.js.map +0 -1
- package/utils/asStyleDict.d.ts +0 -4
- package/utils/asStyleDict.js.map +0 -1
- package/utils/cloneStyledElement.d.ts +0 -18
- package/utils/cloneStyledElement.js.map +0 -1
- package/utils/index.d.ts +0 -5
- package/utils/index.js.map +0 -1
- package/utils/styles.d.ts +0 -2
- package/utils/styles.js.map +0 -1
package/hooks/useMounted.js
CHANGED
|
@@ -1,31 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.useMounted = useMounted;
|
|
20
|
-
var react_1 = require("react");
|
|
21
|
-
function useMounted() {
|
|
22
|
-
var _a = __read((0, react_1.useState)(false), 2), isMounted = _a[0], setIsMounted = _a[1];
|
|
23
|
-
(0, react_1.useEffect)(function () {
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export function useMounted() {
|
|
3
|
+
const [isMounted, setIsMounted] = useState(false);
|
|
4
|
+
useEffect(() => {
|
|
24
5
|
setIsMounted(true);
|
|
25
|
-
return
|
|
6
|
+
return () => {
|
|
26
7
|
setIsMounted(false);
|
|
27
8
|
};
|
|
28
9
|
}, []);
|
|
29
10
|
return isMounted;
|
|
30
11
|
}
|
|
31
|
-
//# sourceMappingURL=useMounted.js.map
|
package/hooks/usePrevious.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.usePrevious = usePrevious;
|
|
4
|
-
var react_1 = require("react");
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
5
2
|
/**
|
|
6
3
|
* Returns the previous value of a value.
|
|
7
4
|
*
|
|
8
5
|
* @param value The value.
|
|
9
6
|
* @param options See {@link Options}.
|
|
10
7
|
*/
|
|
11
|
-
function usePrevious(value,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
(0, react_1.useEffect)(function () {
|
|
8
|
+
export function usePrevious(value, { sanitizeDependency = t => t } = {}) {
|
|
9
|
+
const ref = useRef();
|
|
10
|
+
useEffect(() => {
|
|
15
11
|
ref.current = value;
|
|
16
12
|
}, [sanitizeDependency(value)]);
|
|
17
13
|
return ref.current;
|
|
18
14
|
}
|
|
19
|
-
//# sourceMappingURL=usePrevious.js.map
|
package/hooks/useRect.js
CHANGED
|
@@ -1,25 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.useRect = useRect;
|
|
20
|
-
var react_1 = require("react");
|
|
21
|
-
var spase_1 = require("spase");
|
|
22
|
-
var useResizeEffect_1 = require("./useResizeEffect");
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { Rect } from 'spase';
|
|
3
|
+
import { useResizeEffect } from './useResizeEffect.js';
|
|
23
4
|
/**
|
|
24
5
|
* Hook for monitoring changes in and returning the size and position of the
|
|
25
6
|
* target element.
|
|
@@ -28,17 +9,16 @@ var useResizeEffect_1 = require("./useResizeEffect");
|
|
|
28
9
|
*
|
|
29
10
|
* @returns The most current {@link Rect} of the target element.
|
|
30
11
|
*/
|
|
31
|
-
function useRect(targetRef) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
12
|
+
export function useRect(targetRef) {
|
|
13
|
+
const [rect, setRect] = useState(new Rect());
|
|
14
|
+
const handleResize = (element) => {
|
|
15
|
+
const newRect = Rect.from(element);
|
|
35
16
|
if (!newRect)
|
|
36
17
|
return;
|
|
37
18
|
setRect(newRect);
|
|
38
19
|
};
|
|
39
|
-
|
|
40
|
-
onResize:
|
|
20
|
+
useResizeEffect(targetRef, {
|
|
21
|
+
onResize: element => handleResize(element),
|
|
41
22
|
});
|
|
42
23
|
return rect;
|
|
43
24
|
}
|
|
44
|
-
//# sourceMappingURL=useRect.js.map
|
package/hooks/useResizeEffect.js
CHANGED
|
@@ -1,36 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
-
};
|
|
30
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.useResizeEffect = useResizeEffect;
|
|
32
|
-
var react_1 = require("react");
|
|
33
|
-
var resize_observer_polyfill_1 = __importDefault(require("resize-observer-polyfill"));
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import ResizeObserver from 'resize-observer-polyfill';
|
|
34
3
|
/**
|
|
35
4
|
* Hook for monitoring the resizing event of the target element.
|
|
36
5
|
*
|
|
@@ -38,25 +7,22 @@ var resize_observer_polyfill_1 = __importDefault(require("resize-observer-polyfi
|
|
|
38
7
|
* @param options See {@link Options}.
|
|
39
8
|
* @param deps Additional dependencies.
|
|
40
9
|
*/
|
|
41
|
-
function useResizeEffect(targetRef,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
observerRef.current = new resize_observer_polyfill_1.default(function () {
|
|
47
|
-
var element = targetRef.current;
|
|
10
|
+
export function useResizeEffect(targetRef, { onResize } = {}, deps = []) {
|
|
11
|
+
const observerRef = useRef(undefined);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
observerRef.current = new ResizeObserver(() => {
|
|
14
|
+
const element = targetRef.current;
|
|
48
15
|
if (!element)
|
|
49
16
|
return;
|
|
50
|
-
onResize
|
|
17
|
+
onResize?.(element);
|
|
51
18
|
});
|
|
52
19
|
if (observerRef.current && targetRef.current) {
|
|
53
20
|
observerRef.current.observe(targetRef.current);
|
|
54
21
|
}
|
|
55
|
-
return
|
|
22
|
+
return () => {
|
|
56
23
|
if (observerRef.current && targetRef.current) {
|
|
57
24
|
observerRef.current.unobserve(targetRef.current);
|
|
58
25
|
}
|
|
59
26
|
};
|
|
60
|
-
},
|
|
27
|
+
}, [targetRef.current, ...deps]);
|
|
61
28
|
}
|
|
62
|
-
//# sourceMappingURL=useResizeEffect.js.map
|
|
@@ -1,69 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.useScrollPositionEffect = useScrollPositionEffect;
|
|
29
|
-
var react_1 = require("react");
|
|
30
|
-
var spase_1 = require("spase");
|
|
31
|
-
function useScrollPositionEffect(_a, deps) {
|
|
32
|
-
var onChange = _a.onChange;
|
|
33
|
-
if (deps === void 0) { deps = []; }
|
|
34
|
-
var handleScrollPositionChange = function () {
|
|
35
|
-
var newValue = getScrollPositionInfo();
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { Point, Rect } from 'spase';
|
|
3
|
+
export function useScrollPositionEffect({ onChange }, deps = []) {
|
|
4
|
+
const handleScrollPositionChange = () => {
|
|
5
|
+
const newValue = getScrollPositionInfo();
|
|
36
6
|
if (!newValue)
|
|
37
7
|
return;
|
|
38
8
|
onChange(newValue, prevInfo.current);
|
|
39
9
|
prevInfo.current = newValue;
|
|
40
10
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
11
|
+
const getScrollPositionInfo = () => {
|
|
12
|
+
const refRect = Rect.fromViewport();
|
|
13
|
+
const refRectMin = refRect.clone({ x: 0, y: 0 });
|
|
14
|
+
const refRectFull = Rect.from(window, { overflow: true });
|
|
45
15
|
if (!refRectFull)
|
|
46
16
|
return undefined;
|
|
47
|
-
|
|
48
|
-
|
|
17
|
+
const refRectMax = refRectMin.clone({ x: refRectFull.width - refRect.width, y: refRectFull.height - refRect.height });
|
|
18
|
+
const step = new Point([refRect.left / refRectMax.left, refRect.top / refRectMax.top]);
|
|
49
19
|
return {
|
|
50
|
-
minPos: new
|
|
51
|
-
maxPos: new
|
|
52
|
-
pos: new
|
|
53
|
-
step
|
|
20
|
+
minPos: new Point([refRectMin.left, refRectMin.top]),
|
|
21
|
+
maxPos: new Point([refRectMax.left, refRectMax.top]),
|
|
22
|
+
pos: new Point([refRect.left, refRect.top]),
|
|
23
|
+
step,
|
|
54
24
|
};
|
|
55
25
|
};
|
|
56
|
-
|
|
57
|
-
|
|
26
|
+
const prevInfo = useRef();
|
|
27
|
+
useEffect(() => {
|
|
58
28
|
window.addEventListener('scroll', handleScrollPositionChange);
|
|
59
29
|
window.addEventListener('resize', handleScrollPositionChange);
|
|
60
30
|
window.addEventListener('orientationchange', handleScrollPositionChange);
|
|
61
31
|
handleScrollPositionChange();
|
|
62
|
-
return
|
|
32
|
+
return () => {
|
|
63
33
|
window.removeEventListener('scroll', handleScrollPositionChange);
|
|
64
34
|
window.removeEventListener('resize', handleScrollPositionChange);
|
|
65
35
|
window.removeEventListener('orientationchange', handleScrollPositionChange);
|
|
66
36
|
};
|
|
67
|
-
},
|
|
37
|
+
}, [...deps]);
|
|
68
38
|
}
|
|
69
|
-
//# sourceMappingURL=useScrollPositionEffect.js.map
|
|
@@ -1,24 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.useSearchParamState = useSearchParamState;
|
|
20
|
-
var react_1 = require("react");
|
|
21
|
-
var react_router_dom_1 = require("react-router-dom");
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useSearchParams } from 'react-router-dom';
|
|
22
3
|
/**
|
|
23
4
|
* Hook for mapping a search param to a state. Whenever the value of the target
|
|
24
5
|
* search param changes, the mapped state will change as well, and vice versa.
|
|
@@ -30,10 +11,8 @@ var react_router_dom_1 = require("react-router-dom");
|
|
|
30
11
|
* @returns A tuple consisting of a stateful value representing the current
|
|
31
12
|
* value of the mapped state and a function that updates it.
|
|
32
13
|
*/
|
|
33
|
-
function useSearchParamState(param, defaultValue,
|
|
34
|
-
|
|
35
|
-
var _c = _a === void 0 ? {} : _a, mapSearchParamToState = _c.mapSearchParamToState, mapStateToSearchParam = _c.mapStateToSearchParam;
|
|
36
|
-
var defaultMapSearchParamToState = function (value, fallback) {
|
|
14
|
+
export function useSearchParamState(param, defaultValue, { mapSearchParamToState, mapStateToSearchParam } = {}) {
|
|
15
|
+
const defaultMapSearchParamToState = (value, fallback) => {
|
|
37
16
|
if (mapSearchParamToState) {
|
|
38
17
|
return mapSearchParamToState(value);
|
|
39
18
|
}
|
|
@@ -44,7 +23,7 @@ function useSearchParamState(param, defaultValue, _a) {
|
|
|
44
23
|
return value;
|
|
45
24
|
}
|
|
46
25
|
};
|
|
47
|
-
|
|
26
|
+
const defaultMapStateToSearchParam = (state) => {
|
|
48
27
|
if (mapStateToSearchParam) {
|
|
49
28
|
return mapStateToSearchParam(state);
|
|
50
29
|
}
|
|
@@ -52,15 +31,15 @@ function useSearchParamState(param, defaultValue, _a) {
|
|
|
52
31
|
return undefined;
|
|
53
32
|
}
|
|
54
33
|
else {
|
|
55
|
-
return
|
|
34
|
+
return `${state}`;
|
|
56
35
|
}
|
|
57
36
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
37
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
38
|
+
const currentState = defaultMapSearchParamToState(searchParams.get(param) ?? undefined, defaultValue);
|
|
39
|
+
const [state, setState] = useState(currentState);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const value = searchParams.get(param);
|
|
42
|
+
const newValue = defaultMapStateToSearchParam(state);
|
|
64
43
|
if (newValue === value)
|
|
65
44
|
return;
|
|
66
45
|
if (!newValue) {
|
|
@@ -73,4 +52,3 @@ function useSearchParamState(param, defaultValue, _a) {
|
|
|
73
52
|
}, [state]);
|
|
74
53
|
return [state, setState];
|
|
75
54
|
}
|
|
76
|
-
//# sourceMappingURL=useSearchParamState.js.map
|
package/hooks/useSize.js
CHANGED
|
@@ -1,25 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.useSize = useSize;
|
|
20
|
-
var react_1 = require("react");
|
|
21
|
-
var spase_1 = require("spase");
|
|
22
|
-
var useResizeEffect_1 = require("./useResizeEffect");
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { Rect } from 'spase';
|
|
3
|
+
import { useResizeEffect } from './useResizeEffect.js';
|
|
23
4
|
/**
|
|
24
5
|
* Hook for monitoring changes in and returning the size of the target element.
|
|
25
6
|
*
|
|
@@ -27,17 +8,16 @@ var useResizeEffect_1 = require("./useResizeEffect");
|
|
|
27
8
|
*
|
|
28
9
|
* @returns The most current {@link Size} of the target element.
|
|
29
10
|
*/
|
|
30
|
-
function useSize(targetRef) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
11
|
+
export function useSize(targetRef) {
|
|
12
|
+
const [rect, setRect] = useState(new Rect());
|
|
13
|
+
const handleResize = (element) => {
|
|
14
|
+
const newRect = Rect.from(element);
|
|
34
15
|
if (!newRect)
|
|
35
16
|
return;
|
|
36
17
|
setRect(newRect);
|
|
37
18
|
};
|
|
38
|
-
|
|
39
|
-
onResize:
|
|
19
|
+
useResizeEffect(targetRef, {
|
|
20
|
+
onResize: element => handleResize(element),
|
|
40
21
|
});
|
|
41
22
|
return rect.size;
|
|
42
23
|
}
|
|
43
|
-
//# sourceMappingURL=useSize.js.map
|
package/hooks/useTimeout.js
CHANGED
|
@@ -1,32 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.useTimeout = useTimeout;
|
|
29
|
-
var react_1 = require("react");
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
30
2
|
/**
|
|
31
3
|
* Hoook for invoking a method after a set timeout.
|
|
32
4
|
*
|
|
@@ -35,17 +7,15 @@ var react_1 = require("react");
|
|
|
35
7
|
* `undefined` or less than 0, the timeout is disabled.
|
|
36
8
|
* @param deps Dependencies that trigger this effect.
|
|
37
9
|
*/
|
|
38
|
-
function useTimeout(handler, timeout, deps) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
(0, react_1.useEffect)(function () {
|
|
10
|
+
export function useTimeout(handler, timeout, deps = []) {
|
|
11
|
+
const handlerRef = useRef();
|
|
12
|
+
useEffect(() => {
|
|
42
13
|
handlerRef.current = handler;
|
|
43
14
|
}, [handler]);
|
|
44
|
-
|
|
15
|
+
useEffect(() => {
|
|
45
16
|
if (timeout === undefined || timeout < 0)
|
|
46
17
|
return;
|
|
47
|
-
|
|
48
|
-
return
|
|
49
|
-
},
|
|
18
|
+
const timer = window.setTimeout(() => handlerRef.current?.(), timeout);
|
|
19
|
+
return () => clearTimeout(timer);
|
|
20
|
+
}, [timeout, ...deps]);
|
|
50
21
|
}
|
|
51
|
-
//# sourceMappingURL=useTimeout.js.map
|
package/hooks/useVideoSize.js
CHANGED
|
@@ -1,25 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.useVideoSize = useVideoSize;
|
|
20
|
-
var react_1 = require("react");
|
|
21
|
-
var spase_1 = require("spase");
|
|
22
|
-
var useLoadVideoMetadataEffect_1 = require("./useLoadVideoMetadataEffect");
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { Size } from 'spase';
|
|
3
|
+
import { useLoadVideoMetadataEffect } from './useLoadVideoMetadataEffect.js';
|
|
23
4
|
/**
|
|
24
5
|
* Hook for retrieving the size of a video.
|
|
25
6
|
*
|
|
@@ -29,28 +10,26 @@ var useLoadVideoMetadataEffect_1 = require("./useLoadVideoMetadataEffect");
|
|
|
29
10
|
* @returns The actual size of the video if loading was successful, `undefined`
|
|
30
11
|
* otherwise.
|
|
31
12
|
*/
|
|
32
|
-
function useVideoSize(
|
|
33
|
-
|
|
34
|
-
var _c = _b === void 0 ? {} : _b, _d = _c.preservesSizeBetweenLoads, preservesSizeBetweenLoads = _d === void 0 ? true : _d, onLoadStart = _c.onLoadStart, onLoadComplete = _c.onLoadComplete, onLoadError = _c.onLoadError;
|
|
35
|
-
var handleLoad = function (element) {
|
|
13
|
+
export function useVideoSize({ src }, { preservesSizeBetweenLoads = true, onLoadStart, onLoadComplete, onLoadError } = {}) {
|
|
14
|
+
const handleLoad = (element) => {
|
|
36
15
|
if (!preservesSizeBetweenLoads)
|
|
37
16
|
setSize(undefined);
|
|
38
|
-
onLoadStart
|
|
17
|
+
onLoadStart?.(element);
|
|
39
18
|
};
|
|
40
|
-
|
|
19
|
+
const handleLoadComplete = (element) => {
|
|
41
20
|
setSize(getSize(element));
|
|
42
|
-
onLoadComplete
|
|
21
|
+
onLoadComplete?.(element);
|
|
43
22
|
};
|
|
44
|
-
|
|
23
|
+
const handleLoadError = (element) => {
|
|
45
24
|
if (!preservesSizeBetweenLoads)
|
|
46
25
|
setSize(undefined);
|
|
47
|
-
onLoadError
|
|
26
|
+
onLoadError?.(element);
|
|
48
27
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
onLoadStart:
|
|
52
|
-
onLoadComplete:
|
|
53
|
-
onLoadError:
|
|
28
|
+
const [size, setSize] = useState(undefined);
|
|
29
|
+
useLoadVideoMetadataEffect({ src }, {
|
|
30
|
+
onLoadStart: t => handleLoad(t),
|
|
31
|
+
onLoadComplete: t => handleLoadComplete(t),
|
|
32
|
+
onLoadError: t => handleLoadError(t),
|
|
54
33
|
});
|
|
55
34
|
return size;
|
|
56
35
|
}
|
|
@@ -61,6 +40,5 @@ function getSize(element) {
|
|
|
61
40
|
return undefined;
|
|
62
41
|
if (typeof element.videoHeight !== 'number')
|
|
63
42
|
return undefined;
|
|
64
|
-
return new
|
|
43
|
+
return new Size([element.videoWidth, element.videoHeight]);
|
|
65
44
|
}
|
|
66
|
-
//# sourceMappingURL=useVideoSize.js.map
|
package/hooks/useViewportSize.js
CHANGED
|
@@ -1,40 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.useViewportSize = useViewportSize;
|
|
20
|
-
var react_1 = require("react");
|
|
21
|
-
var spase_1 = require("spase");
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Rect, Size } from 'spase';
|
|
22
3
|
/**
|
|
23
4
|
* Hook for returning the size of the viewport whenever it changes.
|
|
24
5
|
*
|
|
25
6
|
* @returns The most current viewport size.
|
|
26
7
|
*/
|
|
27
|
-
function useViewportSize() {
|
|
28
|
-
|
|
29
|
-
|
|
8
|
+
export function useViewportSize() {
|
|
9
|
+
const [size, setSize] = useState(new Size());
|
|
10
|
+
useEffect(() => {
|
|
30
11
|
function onViewportResize() {
|
|
31
|
-
|
|
12
|
+
const viewportSize = Rect.fromViewport().size;
|
|
32
13
|
setSize(viewportSize);
|
|
33
14
|
}
|
|
34
15
|
window.addEventListener('resize', onViewportResize);
|
|
35
16
|
onViewportResize();
|
|
36
|
-
return
|
|
17
|
+
return () => window.removeEventListener('resize', onViewportResize);
|
|
37
18
|
}, []);
|
|
38
19
|
return size;
|
|
39
20
|
}
|
|
40
|
-
//# sourceMappingURL=useViewportSize.js.map
|
package/operators/Conditional.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Conditional = Conditional;
|
|
4
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
function Conditional(_a) {
|
|
6
|
-
var children = _a.children, boolOrExpression = _a.if;
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export function Conditional({ children, if: boolOrExpression }) {
|
|
7
3
|
switch (typeof boolOrExpression) {
|
|
8
4
|
case 'boolean':
|
|
9
|
-
return boolOrExpression ? (
|
|
5
|
+
return boolOrExpression ? _jsx(_Fragment, { children: children }) : _jsx(_Fragment, {});
|
|
10
6
|
case 'function':
|
|
11
|
-
return boolOrExpression() ? (
|
|
7
|
+
return boolOrExpression() ? _jsx(_Fragment, { children: children }) : _jsx(_Fragment, {});
|
|
12
8
|
default:
|
|
13
|
-
console.error(
|
|
14
|
-
return (
|
|
9
|
+
console.error(`[etudes::Conditional] The type of provided condition ${boolOrExpression} is not supported.`);
|
|
10
|
+
return _jsx(_Fragment, {});
|
|
15
11
|
}
|
|
16
12
|
}
|
|
17
13
|
Object.defineProperty(Conditional, 'displayName', { value: 'Conditional', writable: false });
|
|
18
|
-
//# sourceMappingURL=Conditional.js.map
|
package/operators/Each.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
var react_1 = require("react");
|
|
6
|
-
function Each(_a) {
|
|
7
|
-
var array = _a.in, children = _a.children, render = _a.render;
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment } from 'react';
|
|
3
|
+
export function Each({ in: array, children, render, }) {
|
|
8
4
|
if (array === undefined || array === null)
|
|
9
|
-
return (
|
|
5
|
+
return _jsx(_Fragment, {});
|
|
10
6
|
if (!(array instanceof Array))
|
|
11
|
-
throw TypeError(
|
|
12
|
-
return ((
|
|
13
|
-
var _a;
|
|
14
|
-
return ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: (_a = render === null || render === void 0 ? void 0 : render(v, i)) !== null && _a !== void 0 ? _a : (typeof children === 'function' ? children(v, i) : children) }, "item-".concat(i)));
|
|
15
|
-
}) }));
|
|
7
|
+
throw TypeError(`Provided list <${array}> is not an array`);
|
|
8
|
+
return (_jsx(_Fragment, { children: array.map((v, i) => (_jsx(Fragment, { children: render?.(v, i) ?? (typeof children === 'function' ? children(v, i) : children) }, `item-${i}`))) }));
|
|
16
9
|
}
|
|
17
10
|
Object.defineProperty(Each, 'displayName', { value: 'Each', writable: false });
|
|
18
|
-
//# sourceMappingURL=Each.js.map
|