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
|
@@ -1,74 +1,10 @@
|
|
|
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
|
-
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 __values = (this && this.__values) || function(o) {
|
|
50
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
51
|
-
if (m) return m.call(o);
|
|
52
|
-
if (o && typeof o.length === "number") return {
|
|
53
|
-
next: function () {
|
|
54
|
-
if (o && i >= o.length) o = void 0;
|
|
55
|
-
return { value: o && o[i++], done: !o };
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
59
|
-
};
|
|
60
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
61
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
62
|
-
};
|
|
63
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
-
exports.MasonryGrid = void 0;
|
|
65
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
66
|
-
var clsx_1 = __importDefault(require("clsx"));
|
|
67
|
-
var react_1 = require("react");
|
|
68
|
-
var spase_1 = require("spase");
|
|
69
|
-
var useResizeEffect_1 = require("../hooks/useResizeEffect");
|
|
70
|
-
var utils_1 = require("../utils");
|
|
71
|
-
var BASE_MODIFIER_CLASS_PREFIX = 'base-';
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { forwardRef, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { Rect, Size } from 'spase';
|
|
5
|
+
import { useResizeEffect } from '../hooks/useResizeEffect.js';
|
|
6
|
+
import { asClassNameDict, asStyleDict } from '../utils/index.js';
|
|
7
|
+
const BASE_MODIFIER_CLASS_PREFIX = 'base-';
|
|
72
8
|
/**
|
|
73
9
|
* This is a React component that arranges all of its immediate children in a
|
|
74
10
|
* masonry grid. Refrain from assigning CSS styles to it via `className` or
|
|
@@ -86,146 +22,102 @@ var BASE_MODIFIER_CLASS_PREFIX = 'base-';
|
|
|
86
22
|
* rows*, whereas in a horizontally oriented grid, *number of sections* refers
|
|
87
23
|
* to the *number of columns*.
|
|
88
24
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
100
|
-
var _e, _f, _g, _h;
|
|
101
|
-
var rootNode = bodyRef.current;
|
|
25
|
+
export const MasonryGrid = forwardRef(({ areSectionsAligned = false, children, className, horizontalSpacing = 0, isReversed = false, orientation = 'vertical', sections = 3, verticalSpacing = 0, ...props }, ref) => {
|
|
26
|
+
const bodyRef = useRef(null);
|
|
27
|
+
const [minWidth, setMinWidth] = useState(NaN);
|
|
28
|
+
const [minHeight, setMinHeight] = useState(NaN);
|
|
29
|
+
const [maxWidth, setMaxWidth] = useState(NaN);
|
|
30
|
+
const [maxHeight, setMaxHeight] = useState(NaN);
|
|
31
|
+
const getCurrentWidth = () => Rect.from(bodyRef.current)?.width ?? 0;
|
|
32
|
+
const getCurrentHeight = () => Rect.from(bodyRef.current)?.height ?? 0;
|
|
33
|
+
const repositionChildren = () => {
|
|
34
|
+
const rootNode = bodyRef.current;
|
|
102
35
|
if (!rootNode)
|
|
103
36
|
return;
|
|
104
|
-
|
|
105
|
-
|
|
37
|
+
const nodes = rootNode.children;
|
|
38
|
+
const numSections = sections;
|
|
106
39
|
if (numSections <= 0)
|
|
107
40
|
throw new Error('You must specifiy a minimum of 1 section(s) (a.k.a. row(s) for horizontal orientation, column(s) for vertical orientation) for a MasonryGrid instance');
|
|
108
41
|
if (orientation === 'vertical') {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
for (var j = 0; j < base; j++) {
|
|
123
|
-
sectionHeights[colIdx + j] = y + (y === 0 ? 0 : verticalSpacing) + ((_f = (_e = spase_1.Rect.from(child)) === null || _e === void 0 ? void 0 : _e.height) !== null && _f !== void 0 ? _f : 0);
|
|
124
|
-
}
|
|
125
|
-
if (areSectionsAligned && colIdx + base === numSections) {
|
|
126
|
-
var m = computeMaxLength(sectionHeights);
|
|
127
|
-
for (var j = 0; j < numSections; j++) {
|
|
128
|
-
sectionHeights[j] = m;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
42
|
+
const sectionHeights = [...new Array(numSections)].map(() => 0);
|
|
43
|
+
for (const child of Array.from(nodes)) {
|
|
44
|
+
if (!(child instanceof HTMLElement))
|
|
45
|
+
continue;
|
|
46
|
+
const base = computeBaseFromElement(child, sections);
|
|
47
|
+
const [colIdx, y] = computeNextAvailableSectionAndLengthByBase(sectionHeights, base);
|
|
48
|
+
child.style.position = 'absolute';
|
|
49
|
+
child.style.width = `calc(${100 / numSections * base}% - ${horizontalSpacing * (numSections - 1) / numSections * base}px + ${horizontalSpacing * (base - 1)}px)`;
|
|
50
|
+
child.style.height = '';
|
|
51
|
+
child.style.left = `calc(${100 / numSections * colIdx}% - ${horizontalSpacing * (numSections - 1) / numSections * colIdx}px + ${horizontalSpacing * colIdx}px)`;
|
|
52
|
+
child.style.top = `${y + (y === 0 ? 0 : verticalSpacing)}px`;
|
|
53
|
+
for (let j = 0; j < base; j++) {
|
|
54
|
+
sectionHeights[colIdx + j] = y + (y === 0 ? 0 : verticalSpacing) + (Rect.from(child)?.height ?? 0);
|
|
131
55
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
56
|
+
if (areSectionsAligned && colIdx + base === numSections) {
|
|
57
|
+
const m = computeMaxLength(sectionHeights);
|
|
58
|
+
for (let j = 0; j < numSections; j++) {
|
|
59
|
+
sectionHeights[j] = m;
|
|
60
|
+
}
|
|
137
61
|
}
|
|
138
|
-
finally { if (e_1) throw e_1.error; }
|
|
139
62
|
}
|
|
140
|
-
|
|
141
|
-
|
|
63
|
+
const w = getCurrentWidth();
|
|
64
|
+
const h = computeMaxLength(sectionHeights, numSections);
|
|
142
65
|
setMinWidth(w);
|
|
143
66
|
setMinHeight(h);
|
|
144
67
|
if (!isNaN(h))
|
|
145
|
-
rootNode.style.height =
|
|
68
|
+
rootNode.style.height = `${h}px`;
|
|
146
69
|
if (isReversed) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
var x = parseFloat(child.style.left);
|
|
153
|
-
child.style.left = "".concat(w - x - parseFloat(child.style.width), "px");
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
157
|
-
finally {
|
|
158
|
-
try {
|
|
159
|
-
if (_o && !_o.done && (_b = _m.return)) _b.call(_m);
|
|
160
|
-
}
|
|
161
|
-
finally { if (e_2) throw e_2.error; }
|
|
70
|
+
for (const child of Array.from(nodes)) {
|
|
71
|
+
if (!(child instanceof HTMLElement))
|
|
72
|
+
continue;
|
|
73
|
+
const x = parseFloat(child.style.left);
|
|
74
|
+
child.style.left = `${w - x - parseFloat(child.style.width)}px`;
|
|
162
75
|
}
|
|
163
76
|
}
|
|
164
77
|
}
|
|
165
78
|
else {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
for (var j = 0; j < base; j++) {
|
|
180
|
-
sectionWidths[rowIdx + j] = x + (x === 0 ? 0 : horizontalSpacing) + ((_h = (_g = spase_1.Rect.from(child)) === null || _g === void 0 ? void 0 : _g.width) !== null && _h !== void 0 ? _h : 0);
|
|
181
|
-
}
|
|
182
|
-
if (areSectionsAligned && rowIdx + base === numSections) {
|
|
183
|
-
var m = computeMaxLength(sectionWidths);
|
|
184
|
-
for (var j = 0; j < numSections; j++) {
|
|
185
|
-
sectionWidths[j] = m;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
79
|
+
const sectionWidths = [...new Array(numSections)].map(() => 0);
|
|
80
|
+
for (const child of Array.from(nodes)) {
|
|
81
|
+
if (!(child instanceof HTMLElement))
|
|
82
|
+
continue;
|
|
83
|
+
const base = computeBaseFromElement(child, sections);
|
|
84
|
+
const [rowIdx, x] = computeNextAvailableSectionAndLengthByBase(sectionWidths, base);
|
|
85
|
+
child.style.position = 'absolute';
|
|
86
|
+
child.style.width = '';
|
|
87
|
+
child.style.height = `calc(${100 / numSections * base}% - ${verticalSpacing * (numSections - 1) / numSections * base}px + ${verticalSpacing * (base - 1)}px)`;
|
|
88
|
+
child.style.top = `calc(${100 / numSections * rowIdx}% - ${verticalSpacing * (numSections - 1) / numSections * rowIdx}px + ${verticalSpacing * rowIdx}px)`;
|
|
89
|
+
child.style.left = `${x + (x === 0 ? 0 : horizontalSpacing)}px`;
|
|
90
|
+
for (let j = 0; j < base; j++) {
|
|
91
|
+
sectionWidths[rowIdx + j] = x + (x === 0 ? 0 : horizontalSpacing) + (Rect.from(child)?.width ?? 0);
|
|
188
92
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
93
|
+
if (areSectionsAligned && rowIdx + base === numSections) {
|
|
94
|
+
const m = computeMaxLength(sectionWidths);
|
|
95
|
+
for (let j = 0; j < numSections; j++) {
|
|
96
|
+
sectionWidths[j] = m;
|
|
97
|
+
}
|
|
194
98
|
}
|
|
195
|
-
finally { if (e_3) throw e_3.error; }
|
|
196
99
|
}
|
|
197
|
-
|
|
198
|
-
|
|
100
|
+
const h = getCurrentHeight();
|
|
101
|
+
const w = computeMaxLength(sectionWidths, numSections);
|
|
199
102
|
setMinHeight(h);
|
|
200
103
|
setMinWidth(w);
|
|
201
104
|
if (!isNaN(w))
|
|
202
|
-
rootNode.style.width =
|
|
105
|
+
rootNode.style.width = `${w}px`;
|
|
203
106
|
if (isReversed) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
var y = parseFloat(child.style.top);
|
|
210
|
-
child.style.top = "".concat(h - y - parseFloat(child.style.height), "px");
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
214
|
-
finally {
|
|
215
|
-
try {
|
|
216
|
-
if (_t && !_t.done && (_d = _s.return)) _d.call(_s);
|
|
217
|
-
}
|
|
218
|
-
finally { if (e_4) throw e_4.error; }
|
|
107
|
+
for (const child of Array.from(nodes)) {
|
|
108
|
+
if (!(child instanceof HTMLElement))
|
|
109
|
+
continue;
|
|
110
|
+
const y = parseFloat(child.style.top);
|
|
111
|
+
child.style.top = `${h - y - parseFloat(child.style.height)}px`;
|
|
219
112
|
}
|
|
220
113
|
}
|
|
221
114
|
}
|
|
222
115
|
};
|
|
223
|
-
|
|
224
|
-
onResize:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
var currHeight = getCurrentHeight();
|
|
116
|
+
useResizeEffect(bodyRef, {
|
|
117
|
+
onResize: element => {
|
|
118
|
+
const maxSize = Rect.from(element)?.size ?? new Size();
|
|
119
|
+
const currWidth = getCurrentWidth();
|
|
120
|
+
const currHeight = getCurrentHeight();
|
|
229
121
|
if (minWidth !== currWidth || minHeight !== currHeight || maxSize.width !== maxWidth || maxSize.height !== maxHeight) {
|
|
230
122
|
repositionChildren();
|
|
231
123
|
setMaxWidth(maxSize.width);
|
|
@@ -233,37 +125,34 @@ exports.MasonryGrid = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
233
125
|
}
|
|
234
126
|
},
|
|
235
127
|
}, [areSectionsAligned, horizontalSpacing, isReversed, sections, verticalSpacing]);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
var imageSources = getAllImageSources((_a = bodyRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML);
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
const imageSources = getAllImageSources(bodyRef.current?.innerHTML);
|
|
239
130
|
if (imageSources.length === 0)
|
|
240
131
|
return repositionChildren();
|
|
241
|
-
|
|
242
|
-
for (
|
|
243
|
-
|
|
244
|
-
|
|
132
|
+
const numImages = imageSources.length;
|
|
133
|
+
for (let i = 0; i < numImages; i++) {
|
|
134
|
+
const src = imageSources[i];
|
|
135
|
+
const image = new Image();
|
|
245
136
|
image.src = src;
|
|
246
|
-
image.onload =
|
|
137
|
+
image.onload = () => repositionChildren();
|
|
247
138
|
}
|
|
248
139
|
}, [children]);
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return ((
|
|
140
|
+
const fixedClassNames = getFixedClassNames({ orientation });
|
|
141
|
+
const fixedStyles = getFixedStyles({ orientation, minHeight, minWidth });
|
|
142
|
+
return (_jsx("div", { ...props, ref: ref, className: clsx(className, fixedClassNames.root), "data-component": 'masonry-grid', children: _jsx("div", { ref: bodyRef, style: fixedStyles.body, children: children }) }));
|
|
252
143
|
});
|
|
253
|
-
Object.defineProperty(
|
|
254
|
-
function getFixedClassNames(
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
root: (0, clsx_1.default)(orientation),
|
|
144
|
+
Object.defineProperty(MasonryGrid, 'displayName', { value: 'MasonryGrid', writable: false });
|
|
145
|
+
function getFixedClassNames({ orientation = 'horizontal' }) {
|
|
146
|
+
return asClassNameDict({
|
|
147
|
+
root: clsx(orientation),
|
|
258
148
|
});
|
|
259
149
|
}
|
|
260
|
-
function getFixedStyles(
|
|
261
|
-
|
|
262
|
-
return (0, utils_1.asStyleDict)({
|
|
150
|
+
function getFixedStyles({ orientation = 'horizontal', minHeight = NaN, minWidth = NaN }) {
|
|
151
|
+
return asStyleDict({
|
|
263
152
|
body: {
|
|
264
153
|
height: orientation === 'horizontal' ? '100%' : 'auto',
|
|
265
|
-
minHeight: orientation === 'vertical' && !isNaN(minHeight) ?
|
|
266
|
-
minWidth: orientation === 'horizontal' && !isNaN(minWidth) ?
|
|
154
|
+
minHeight: orientation === 'vertical' && !isNaN(minHeight) ? `${minHeight}px` : '',
|
|
155
|
+
minWidth: orientation === 'horizontal' && !isNaN(minWidth) ? `${minWidth}px` : '',
|
|
267
156
|
padding: '0',
|
|
268
157
|
width: orientation === 'horizontal' ? 'auto' : '100%',
|
|
269
158
|
},
|
|
@@ -281,22 +170,22 @@ function getFixedStyles(_a) {
|
|
|
281
170
|
* length if a new item were to be placed in it.
|
|
282
171
|
*/
|
|
283
172
|
function computeNextAvailableSectionAndLengthByBase(currentSectionLengths, base) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
for (
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
for (
|
|
293
|
-
if (currentSectionLengths[i + j] >
|
|
173
|
+
const numSections = currentSectionLengths.length;
|
|
174
|
+
let sectionIdx = NaN;
|
|
175
|
+
let minLength = Infinity;
|
|
176
|
+
for (let i = 0; i < numSections; i++) {
|
|
177
|
+
const length = currentSectionLengths[i];
|
|
178
|
+
const isShorter = length < minLength;
|
|
179
|
+
const isEligibleSection = i + base <= numSections;
|
|
180
|
+
let hasRoomInSubsequentSections = true;
|
|
181
|
+
for (let j = 1; j < base; j++) {
|
|
182
|
+
if (currentSectionLengths[i + j] > length) {
|
|
294
183
|
hasRoomInSubsequentSections = false;
|
|
295
184
|
}
|
|
296
185
|
}
|
|
297
186
|
if (isShorter && isEligibleSection && hasRoomInSubsequentSections) {
|
|
298
187
|
sectionIdx = i;
|
|
299
|
-
minLength =
|
|
188
|
+
minLength = length;
|
|
300
189
|
}
|
|
301
190
|
}
|
|
302
191
|
if (isNaN(sectionIdx)) {
|
|
@@ -319,11 +208,11 @@ function computeNextAvailableSectionAndLengthByBase(currentSectionLengths, base)
|
|
|
319
208
|
* @returns The max section length.
|
|
320
209
|
*/
|
|
321
210
|
function computeMaxLength(currentSectionLengths, base) {
|
|
322
|
-
|
|
211
|
+
let arr = currentSectionLengths;
|
|
323
212
|
if (base !== undefined && base !== null && !isNaN(base)) {
|
|
324
213
|
arr = arr.slice(0, Math.max(1, Math.min(base, currentSectionLengths.length)));
|
|
325
214
|
}
|
|
326
|
-
return arr.reduce(
|
|
215
|
+
return arr.reduce((out, curr, i) => curr > out ? curr : out, 0);
|
|
327
216
|
}
|
|
328
217
|
/**
|
|
329
218
|
* Computes the base value of an element from its classes.
|
|
@@ -335,25 +224,14 @@ function computeMaxLength(currentSectionLengths, base) {
|
|
|
335
224
|
* sections.
|
|
336
225
|
*/
|
|
337
226
|
function computeBaseFromElement(element, numSections) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
var base = parseFloat(c.replace(BASE_MODIFIER_CLASS_PREFIX, ''));
|
|
345
|
-
if (!isNaN(base))
|
|
346
|
-
return Math.min(Math.max(base, 1), numSections);
|
|
347
|
-
}
|
|
227
|
+
const classList = element.classList;
|
|
228
|
+
for (const c of Array.from(classList)) {
|
|
229
|
+
if (c.startsWith(BASE_MODIFIER_CLASS_PREFIX)) {
|
|
230
|
+
const base = parseFloat(c.replace(BASE_MODIFIER_CLASS_PREFIX, ''));
|
|
231
|
+
if (!isNaN(base))
|
|
232
|
+
return Math.min(Math.max(base, 1), numSections);
|
|
348
233
|
}
|
|
349
234
|
}
|
|
350
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
351
|
-
finally {
|
|
352
|
-
try {
|
|
353
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
354
|
-
}
|
|
355
|
-
finally { if (e_5) throw e_5.error; }
|
|
356
|
-
}
|
|
357
235
|
return 1;
|
|
358
236
|
}
|
|
359
237
|
/**
|
|
@@ -364,30 +242,17 @@ function computeBaseFromElement(element, numSections) {
|
|
|
364
242
|
* @returns The image sources.
|
|
365
243
|
*/
|
|
366
244
|
function getAllImageSources(htmlString) {
|
|
367
|
-
var e_6, _a;
|
|
368
|
-
var _b, _c;
|
|
369
245
|
if (!htmlString)
|
|
370
246
|
return [];
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
continue;
|
|
381
|
-
out.push(src);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
385
|
-
finally {
|
|
386
|
-
try {
|
|
387
|
-
if (imageTags_1_1 && !imageTags_1_1.done && (_a = imageTags_1.return)) _a.call(imageTags_1);
|
|
388
|
-
}
|
|
389
|
-
finally { if (e_6) throw e_6.error; }
|
|
247
|
+
const regexImg = /<img.*?src=(["'])(.*?)\1/g;
|
|
248
|
+
const regexSrc = /<img.*?src=(["'])(.*?)\1/;
|
|
249
|
+
const imageTags = regexImg.exec(htmlString) ?? [];
|
|
250
|
+
const out = [];
|
|
251
|
+
for (const tag of imageTags) {
|
|
252
|
+
const src = regexSrc.exec(tag)?.[2];
|
|
253
|
+
if (!src)
|
|
254
|
+
continue;
|
|
255
|
+
out.push(src);
|
|
390
256
|
}
|
|
391
257
|
return out;
|
|
392
258
|
}
|
|
393
|
-
//# sourceMappingURL=MasonryGrid.js.map
|