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/components/Collection.js
CHANGED
|
@@ -1,70 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
25
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
26
|
-
if (!m) return o;
|
|
27
|
-
var i = m.call(o), r, ar = [], e;
|
|
28
|
-
try {
|
|
29
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
30
|
-
}
|
|
31
|
-
catch (error) { e = { error: error }; }
|
|
32
|
-
finally {
|
|
33
|
-
try {
|
|
34
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
35
|
-
}
|
|
36
|
-
finally { if (e) throw e.error; }
|
|
37
|
-
}
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
41
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
42
|
-
if (ar || !(i in from)) {
|
|
43
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
44
|
-
ar[i] = from[i];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
48
|
-
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.Collection = void 0;
|
|
54
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
55
|
-
var clsx_1 = __importDefault(require("clsx"));
|
|
56
|
-
var react_1 = __importDefault(require("fast-deep-equal/react"));
|
|
57
|
-
var react_2 = require("react");
|
|
58
|
-
var Each_1 = require("../operators/Each");
|
|
59
|
-
var utils_1 = require("../utils");
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import isDeepEqual from 'fast-deep-equal/react';
|
|
4
|
+
import { forwardRef, useEffect, useRef } from 'react';
|
|
5
|
+
import { Each } from '../operators/Each.js';
|
|
6
|
+
import { asStyleDict, styles } from '../utils/index.js';
|
|
60
7
|
/**
|
|
61
8
|
* A collection of selectable items with generic data. Items are generated based
|
|
62
9
|
* on the provided `ItemComponent`. This component supports different layouts in
|
|
63
10
|
* both horizontal and vertical orientations.
|
|
64
11
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
var isIndexOutOfRange = function (index) {
|
|
12
|
+
export const Collection = forwardRef(({ className, style, isSelectionTogglable = false, itemLength, itemPadding = 0, items, layout = 'list', numSegments = 1, orientation = 'vertical', selection: externalSelection, selectionMode = 'none', onActivateAt, onDeselectAt, onItemCustomEvent, onSelectAt, onSelectionChange, ItemComponent, ...props }, ref) => {
|
|
13
|
+
const isIndexOutOfRange = (index) => {
|
|
68
14
|
if (isNaN(index))
|
|
69
15
|
return true;
|
|
70
16
|
if (index >= items.length)
|
|
@@ -73,9 +19,9 @@ exports.Collection = (0, react_2.forwardRef)(function (_a, ref) {
|
|
|
73
19
|
return true;
|
|
74
20
|
return false;
|
|
75
21
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
22
|
+
const sanitizeSelection = (indices) => sortIndices(indices).filter(t => !isIndexOutOfRange(t));
|
|
23
|
+
const isSelectedAt = (index) => selection.indexOf(index) >= 0;
|
|
24
|
+
const toggleAt = (index) => {
|
|
79
25
|
if (isSelectedAt(index)) {
|
|
80
26
|
deselectAt(index);
|
|
81
27
|
}
|
|
@@ -83,36 +29,36 @@ exports.Collection = (0, react_2.forwardRef)(function (_a, ref) {
|
|
|
83
29
|
selectAt(index);
|
|
84
30
|
}
|
|
85
31
|
};
|
|
86
|
-
|
|
32
|
+
const selectAt = (index) => {
|
|
87
33
|
if (isSelectedAt(index))
|
|
88
34
|
return;
|
|
89
|
-
|
|
35
|
+
let transform;
|
|
90
36
|
switch (selectionMode) {
|
|
91
37
|
case 'multiple': {
|
|
92
|
-
transform =
|
|
38
|
+
transform = val => sortIndices([...val.filter(t => t !== index), index]);
|
|
93
39
|
break;
|
|
94
40
|
}
|
|
95
41
|
case 'single': {
|
|
96
|
-
transform =
|
|
42
|
+
transform = val => [index];
|
|
97
43
|
break;
|
|
98
44
|
}
|
|
99
45
|
default:
|
|
100
46
|
return;
|
|
101
47
|
}
|
|
102
|
-
|
|
48
|
+
const newValue = transform(selection);
|
|
103
49
|
prevSelectionRef.current = newValue;
|
|
104
50
|
handleSelectionChange(selection, newValue);
|
|
105
51
|
};
|
|
106
|
-
|
|
52
|
+
const deselectAt = (index) => {
|
|
107
53
|
if (!isSelectedAt(index))
|
|
108
54
|
return;
|
|
109
|
-
|
|
110
|
-
|
|
55
|
+
const transform = (val) => val.filter(t => t !== index);
|
|
56
|
+
const newValue = transform(selection);
|
|
111
57
|
prevSelectionRef.current = newValue;
|
|
112
58
|
handleSelectionChange(selection, newValue);
|
|
113
59
|
};
|
|
114
|
-
|
|
115
|
-
onActivateAt
|
|
60
|
+
const activateAt = (index) => {
|
|
61
|
+
onActivateAt?.(index);
|
|
116
62
|
if (selectionMode === 'none')
|
|
117
63
|
return;
|
|
118
64
|
if (isSelectionTogglable) {
|
|
@@ -122,61 +68,79 @@ exports.Collection = (0, react_2.forwardRef)(function (_a, ref) {
|
|
|
122
68
|
selectAt(index);
|
|
123
69
|
}
|
|
124
70
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if ((0, react_1.default)(oldValue, newValue))
|
|
71
|
+
const handleSelectionChange = (oldValue, newValue) => {
|
|
72
|
+
if (isDeepEqual(oldValue, newValue))
|
|
128
73
|
return;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
deselected.forEach(
|
|
132
|
-
selected.forEach(
|
|
133
|
-
onSelectionChange
|
|
74
|
+
const deselected = oldValue?.filter(t => newValue.indexOf(t) === -1) ?? [];
|
|
75
|
+
const selected = newValue.filter(t => oldValue?.indexOf(t) === -1);
|
|
76
|
+
deselected.forEach(t => onDeselectAt?.(t));
|
|
77
|
+
selected.forEach(t => onSelectAt?.(t));
|
|
78
|
+
onSelectionChange?.(newValue);
|
|
134
79
|
};
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
80
|
+
const selection = sanitizeSelection(externalSelection ?? []);
|
|
81
|
+
const fixedStyles = getFixedStyles({ itemLength, itemPadding, layout, numSegments, orientation });
|
|
82
|
+
const prevSelectionRef = useRef();
|
|
83
|
+
const prevSelection = prevSelectionRef.current;
|
|
84
|
+
useEffect(() => {
|
|
140
85
|
prevSelectionRef.current = selection;
|
|
141
86
|
if (prevSelection === undefined)
|
|
142
87
|
return;
|
|
143
88
|
handleSelectionChange(prevSelection, selection);
|
|
144
89
|
}, [JSON.stringify(selection)]);
|
|
145
|
-
return ((
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
90
|
+
return (_jsx("div", { ...props, ref: ref, className: clsx(className), "data-component": 'collection', style: styles(style, fixedStyles.root), children: ItemComponent && (_jsx(Each, { in: items, children: (val, idx) => (_jsx(ItemComponent, { className: clsx({ selected: isSelectedAt(idx) }), "data-child": 'item', "data-index": idx, index: idx, isSelected: isSelectedAt(idx), item: val, orientation: orientation, style: styles(fixedStyles.item, {
|
|
91
|
+
pointerEvents: isSelectionTogglable !== true && isSelectedAt(idx) ? 'none' : 'auto',
|
|
92
|
+
...idx >= items.length - 1 ? {} : {
|
|
93
|
+
...layout === 'list' ? {
|
|
94
|
+
...orientation === 'vertical' ? {
|
|
95
|
+
marginBottom: `${itemPadding}px`,
|
|
96
|
+
} : {
|
|
97
|
+
marginRight: `${itemPadding}px`,
|
|
98
|
+
},
|
|
99
|
+
} : {},
|
|
100
|
+
},
|
|
101
|
+
}), onClick: () => activateAt(idx), onCustomEvent: (name, info) => onItemCustomEvent?.(idx, name, info) })) })) }));
|
|
150
102
|
});
|
|
151
|
-
Object.defineProperty(
|
|
103
|
+
Object.defineProperty(Collection, 'displayName', { value: 'Collection', writable: false });
|
|
152
104
|
function sortIndices(indices) {
|
|
153
|
-
return indices.sort(
|
|
105
|
+
return indices.sort((a, b) => a - b);
|
|
154
106
|
}
|
|
155
|
-
function getFixedStyles(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
107
|
+
function getFixedStyles({ itemLength = NaN, itemPadding = 0, layout = 'collection', numSegments = 1, orientation = 'vertical' }) {
|
|
108
|
+
return asStyleDict({
|
|
109
|
+
root: {
|
|
110
|
+
counterReset: 'item-counter',
|
|
111
|
+
listStyle: 'none',
|
|
112
|
+
...layout === 'list' ? {
|
|
113
|
+
alignItems: 'flex-start',
|
|
114
|
+
display: 'flex',
|
|
115
|
+
flex: '0 0 auto',
|
|
116
|
+
flexDirection: orientation === 'horizontal' ? 'row' : 'column',
|
|
117
|
+
justifyContent: 'flex-start',
|
|
118
|
+
} : {
|
|
119
|
+
display: 'grid',
|
|
120
|
+
gap: `${itemPadding}px`,
|
|
121
|
+
...orientation === 'vertical' ? {
|
|
122
|
+
gridAutoRows: isNaN(itemLength) ? undefined : `${itemLength}px`,
|
|
123
|
+
gridTemplateColumns: `repeat(${numSegments}, 1fr)`,
|
|
124
|
+
gridAutoFlow: 'row',
|
|
125
|
+
} : {
|
|
126
|
+
gridAutoColumns: isNaN(itemLength) ? undefined : `${itemLength}px`,
|
|
127
|
+
gridTemplateRows: `repeat(${numSegments}, 1fr)`,
|
|
128
|
+
gridAutoFlow: 'column',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
item: {
|
|
133
|
+
counterIncrement: 'item-counter',
|
|
161
134
|
flex: '0 0 auto',
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
})),
|
|
173
|
-
item: __assign({ counterIncrement: 'item-counter', flex: '0 0 auto' }, layout === 'list' ? __assign({}, orientation === 'vertical' ? {
|
|
174
|
-
width: '100%',
|
|
175
|
-
height: isNaN(itemLength) ? undefined : "".concat(itemLength, "px"),
|
|
176
|
-
} : {
|
|
177
|
-
width: isNaN(itemLength) ? undefined : "".concat(itemLength, "px"),
|
|
178
|
-
height: '100%',
|
|
179
|
-
}) : {}),
|
|
135
|
+
...layout === 'list' ? {
|
|
136
|
+
...orientation === 'vertical' ? {
|
|
137
|
+
width: '100%',
|
|
138
|
+
height: isNaN(itemLength) ? undefined : `${itemLength}px`,
|
|
139
|
+
} : {
|
|
140
|
+
width: isNaN(itemLength) ? undefined : `${itemLength}px`,
|
|
141
|
+
height: '100%',
|
|
142
|
+
},
|
|
143
|
+
} : {},
|
|
144
|
+
},
|
|
180
145
|
});
|
|
181
146
|
}
|
|
182
|
-
//# sourceMappingURL=Collection.js.map
|
package/components/Counter.js
CHANGED
|
@@ -1,102 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { forwardRef, useEffect } from 'react';
|
|
4
|
+
import { usePrevious } from '../hooks/usePrevious.js';
|
|
5
|
+
import { asStyleDict, styles } from '../utils/index.js';
|
|
6
|
+
import { TextField } from './TextField.js';
|
|
7
|
+
export const Counter = forwardRef(({ style, min = NaN, max = NaN, allowsInput = true, quantity = 0, usesDefaultStyles = true, onChange, AddButtonComponent, SubtractButtonComponent, ...props }, ref) => {
|
|
8
|
+
const handleSubtract = () => {
|
|
9
|
+
onChange?.(isNaN(min) ? quantity - 1 : Math.max(min, quantity - 1));
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.Counter = void 0;
|
|
29
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
30
|
-
var clsx_1 = __importDefault(require("clsx"));
|
|
31
|
-
var react_1 = require("react");
|
|
32
|
-
var usePrevious_1 = require("../hooks/usePrevious");
|
|
33
|
-
var asStyleDict_1 = require("../utils/asStyleDict");
|
|
34
|
-
var styles_1 = require("../utils/styles");
|
|
35
|
-
var TextField_1 = require("./TextField");
|
|
36
|
-
exports.Counter = (0, react_1.forwardRef)(function (_a, ref) {
|
|
37
|
-
var style = _a.style, _b = _a.min, min = _b === void 0 ? NaN : _b, _c = _a.max, max = _c === void 0 ? NaN : _c, _d = _a.allowsInput, allowsInput = _d === void 0 ? true : _d, _e = _a.quantity, quantity = _e === void 0 ? 0 : _e, _f = _a.usesDefaultStyles, usesDefaultStyles = _f === void 0 ? true : _f, onChange = _a.onChange, AddButtonComponent = _a.AddButtonComponent, SubtractButtonComponent = _a.SubtractButtonComponent, props = __rest(_a, ["style", "min", "max", "allowsInput", "quantity", "usesDefaultStyles", "onChange", "AddButtonComponent", "SubtractButtonComponent"]);
|
|
38
|
-
var handleSubtract = function () {
|
|
39
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(isNaN(min) ? quantity - 1 : Math.max(min, quantity - 1));
|
|
11
|
+
const handleAdd = () => {
|
|
12
|
+
onChange?.(isNaN(max) ? quantity + 1 : Math.min(max, quantity + 1));
|
|
40
13
|
};
|
|
41
|
-
|
|
42
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(isNaN(max) ? quantity + 1 : Math.min(max, quantity + 1));
|
|
43
|
-
};
|
|
44
|
-
var handleQuantityChange = function (newValue) {
|
|
14
|
+
const handleQuantityChange = (newValue) => {
|
|
45
15
|
if (newValue === quantity)
|
|
46
16
|
return;
|
|
47
|
-
onChange
|
|
17
|
+
onChange?.(newValue);
|
|
48
18
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
19
|
+
const prevQuantity = usePrevious(quantity);
|
|
20
|
+
const defaultStyles = usesDefaultStyles ? DEFAULT_STYLES : undefined;
|
|
21
|
+
const isAddingDisabled = !isNaN(max) && quantity + 1 > max;
|
|
22
|
+
const isSubtractingDisabled = !isNaN(min) && quantity - 1 < min;
|
|
23
|
+
useEffect(() => {
|
|
54
24
|
if (prevQuantity === undefined)
|
|
55
25
|
return;
|
|
56
26
|
handleQuantityChange(quantity);
|
|
57
27
|
}, [quantity]);
|
|
58
|
-
|
|
28
|
+
useEffect(() => {
|
|
59
29
|
handleQuantityChange(isNaN(min) ? quantity : Math.max(min, quantity));
|
|
60
30
|
}, [min]);
|
|
61
|
-
|
|
31
|
+
useEffect(() => {
|
|
62
32
|
if (isNaN(max))
|
|
63
33
|
return;
|
|
64
34
|
handleQuantityChange(isNaN(max) ? quantity : Math.min(max, quantity));
|
|
65
35
|
}, [max]);
|
|
66
|
-
return ((
|
|
36
|
+
return (_jsxs("div", { ...props, ref: ref, "data-component": 'counter', style: styles(style, FIXED_STYLES.root, defaultStyles?.root), children: [SubtractButtonComponent && (_jsx(SubtractButtonComponent, { className: clsx({ disabled: isSubtractingDisabled }), "data-child": 'subtract-button', style: styles(FIXED_STYLES.subtract), onClick: () => handleSubtract() })) || (_jsx("button", { className: clsx({ disabled: isSubtractingDisabled }), "data-child": 'subtract-button', style: styles(FIXED_STYLES.subtract, defaultStyles?.subtract), onClick: () => handleSubtract() })), _jsx(TextField, { "data-child": 'text-field', formatter: (oldValue, newValue) => isNaN(Number(`0${newValue}`)) ? oldValue : newValue, isDisabled: !allowsInput, style: styles(FIXED_STYLES.text, defaultStyles?.text), value: quantity.toString() }), AddButtonComponent && (_jsx(AddButtonComponent, { className: clsx({ disabled: isAddingDisabled }), "data-child": 'add-button', style: styles(FIXED_STYLES.add), onClick: () => handleAdd() })) || (_jsx("button", { className: clsx({ disabled: isAddingDisabled }), "data-child": 'add-button', style: styles(FIXED_STYLES.add, defaultStyles?.add), onClick: () => handleAdd() }))] }));
|
|
67
37
|
});
|
|
68
|
-
Object.defineProperty(
|
|
69
|
-
|
|
70
|
-
root:
|
|
38
|
+
Object.defineProperty(Counter, 'displayName', { value: 'Counter', writable: false });
|
|
39
|
+
const FIXED_STYLES = asStyleDict({
|
|
40
|
+
root: styles({
|
|
71
41
|
display: 'flex',
|
|
72
42
|
flexDirection: 'row',
|
|
73
43
|
justifyContent: 'flex-start',
|
|
74
44
|
alignItems: 'stretch',
|
|
75
45
|
}),
|
|
76
|
-
subtract:
|
|
46
|
+
subtract: styles({
|
|
77
47
|
flex: '0 0 auto',
|
|
78
48
|
}),
|
|
79
|
-
add:
|
|
49
|
+
add: styles({
|
|
80
50
|
flex: '0 0 auto',
|
|
81
51
|
}),
|
|
82
|
-
text:
|
|
52
|
+
text: styles({
|
|
83
53
|
flex: '1 1 auto',
|
|
84
54
|
}),
|
|
85
55
|
});
|
|
86
|
-
|
|
87
|
-
root:
|
|
88
|
-
subtract:
|
|
56
|
+
const DEFAULT_STYLES = asStyleDict({
|
|
57
|
+
root: styles({}),
|
|
58
|
+
subtract: styles({
|
|
89
59
|
width: '20px',
|
|
90
60
|
height: '100%',
|
|
91
61
|
background: '#000',
|
|
92
62
|
}),
|
|
93
|
-
add:
|
|
63
|
+
add: styles({
|
|
94
64
|
width: '20px',
|
|
95
65
|
height: '100%',
|
|
96
66
|
background: '#000',
|
|
97
67
|
}),
|
|
98
|
-
text:
|
|
68
|
+
text: styles({
|
|
99
69
|
height: '100%',
|
|
100
70
|
}),
|
|
101
71
|
});
|
|
102
|
-
//# sourceMappingURL=Counter.js.map
|
package/components/CoverImage.js
CHANGED
|
@@ -1,63 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
25
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
26
|
-
if (!m) return o;
|
|
27
|
-
var i = m.call(o), r, ar = [], e;
|
|
28
|
-
try {
|
|
29
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
30
|
-
}
|
|
31
|
-
catch (error) { e = { error: error }; }
|
|
32
|
-
finally {
|
|
33
|
-
try {
|
|
34
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
35
|
-
}
|
|
36
|
-
finally { if (e) throw e.error; }
|
|
37
|
-
}
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.CoverImage = void 0;
|
|
42
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
43
|
-
var react_1 = require("react");
|
|
44
|
-
var spase_1 = require("spase");
|
|
45
|
-
var useRect_1 = require("../hooks/useRect");
|
|
46
|
-
var utils_1 = require("../utils");
|
|
47
|
-
var Image_1 = require("./Image");
|
|
48
|
-
exports.CoverImage = (0, react_1.forwardRef)(function (_a, ref) {
|
|
49
|
-
var _b;
|
|
50
|
-
var children = _a.children, style = _a.style, alt = _a.alt, _c = _a.aspectRatio, externalAspectRatio = _c === void 0 ? NaN : _c, loadingMode = _a.loadingMode, renderViewportContent = _a.renderViewportContent, sizes = _a.sizes, src = _a.src, srcSet = _a.srcSet, onLoadStart = _a.onLoadStart, onLoadComplete = _a.onLoadComplete, onLoadError = _a.onLoadError, props = __rest(_a, ["children", "style", "alt", "aspectRatio", "loadingMode", "renderViewportContent", "sizes", "src", "srcSet", "onLoadStart", "onLoadComplete", "onLoadError"]);
|
|
51
|
-
var handleSizeChange = function (size) {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useRef, useState } from 'react';
|
|
3
|
+
import { Size } from 'spase';
|
|
4
|
+
import { useRect } from '../hooks/useRect.js';
|
|
5
|
+
import { asStyleDict, styles } from '../utils/index.js';
|
|
6
|
+
import { Image } from './Image.js';
|
|
7
|
+
export const CoverImage = forwardRef(({ children, style, alt, aspectRatio: externalAspectRatio = NaN, loadingMode, renderViewportContent, sizes, src, srcSet, onLoadStart, onLoadComplete, onLoadError, ...props }, ref) => {
|
|
8
|
+
const handleSizeChange = (size) => {
|
|
52
9
|
setLocalAspectRatio(size ? size.width / size.height : NaN);
|
|
53
10
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
11
|
+
const localRef = useRef(null);
|
|
12
|
+
const rootRef = ref ?? localRef;
|
|
13
|
+
const [localAspectRatio, setLocalAspectRatio] = useState(NaN);
|
|
14
|
+
const aspectRatio = isNaN(externalAspectRatio) ? localAspectRatio : externalAspectRatio;
|
|
15
|
+
const rootRect = useRect(rootRef);
|
|
16
|
+
const rootAspectRatio = rootRect.width / rootRect.height;
|
|
17
|
+
const imageSize = new Size([
|
|
61
18
|
rootAspectRatio > 1
|
|
62
19
|
? Math.max(rootRect.width, rootRect.height * aspectRatio)
|
|
63
20
|
: Math.max(rootRect.width, (Math.max(rootRect.height, rootRect.width / aspectRatio)) * aspectRatio),
|
|
@@ -65,17 +22,17 @@ exports.CoverImage = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
65
22
|
? Math.max(rootRect.height, Math.max(rootRect.width, rootRect.height * aspectRatio) / aspectRatio)
|
|
66
23
|
: Math.max(rootRect.height, rootRect.width / aspectRatio),
|
|
67
24
|
]);
|
|
68
|
-
return ((
|
|
69
|
-
width:
|
|
70
|
-
height:
|
|
71
|
-
}), onLoadComplete: onLoadComplete, onLoadError: onLoadError, onLoadStart: onLoadStart, onSizeChange:
|
|
72
|
-
height:
|
|
25
|
+
return (_jsxs("div", { ...props, ref: rootRef, "data-component": 'cover-image', style: styles(style, FIXED_STYLES.root), children: [_jsx(Image, { alt: alt, "data-child": 'image', sizes: sizes, src: src, srcSet: srcSet, style: styles(FIXED_STYLES.viewport, {
|
|
26
|
+
width: `${imageSize.width}px`,
|
|
27
|
+
height: `${imageSize.height}px`,
|
|
28
|
+
}), onLoadComplete: onLoadComplete, onLoadError: onLoadError, onLoadStart: onLoadStart, onSizeChange: size => handleSizeChange(size) }), renderViewportContent && (_jsx("div", { "data-child": 'viewport', style: styles(FIXED_STYLES.viewport, {
|
|
29
|
+
height: `${imageSize.height}px`,
|
|
73
30
|
pointerEvents: 'none',
|
|
74
|
-
width:
|
|
75
|
-
}), children: renderViewportContent() })), children] }))
|
|
31
|
+
width: `${imageSize.width}px`,
|
|
32
|
+
}), children: renderViewportContent() })), children] }));
|
|
76
33
|
});
|
|
77
|
-
Object.defineProperty(
|
|
78
|
-
|
|
34
|
+
Object.defineProperty(CoverImage, 'displayName', { value: 'CoverImage', writable: false });
|
|
35
|
+
const FIXED_STYLES = asStyleDict({
|
|
79
36
|
root: {
|
|
80
37
|
overflow: 'hidden',
|
|
81
38
|
},
|
|
@@ -94,4 +51,3 @@ var FIXED_STYLES = (0, utils_1.asStyleDict)({
|
|
|
94
51
|
width: '100%',
|
|
95
52
|
},
|
|
96
53
|
});
|
|
97
|
-
//# sourceMappingURL=CoverImage.js.map
|