@sguisse/react-grid-layout 2.2.3-sguisse.3
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/LICENSE +21 -0
- package/README.md +125 -0
- package/css/styles.css +120 -0
- package/dist/ResponsiveGridLayout-B_6TXsWM.d.ts +80 -0
- package/dist/ResponsiveGridLayout-Bin5MBC3.d.mts +80 -0
- package/dist/calculate-CoBSgofg.d.mts +196 -0
- package/dist/calculate-K0IBpu53.d.ts +196 -0
- package/dist/chunk-7BT7XXIT.js +74 -0
- package/dist/chunk-G3PAJYGP.mjs +72 -0
- package/dist/chunk-ITLZ7N2R.mjs +456 -0
- package/dist/chunk-J4LTYI7L.js +485 -0
- package/dist/chunk-KKV4ZCG4.mjs +583 -0
- package/dist/chunk-LQOPWRJR.js +623 -0
- package/dist/chunk-O3KX3VYW.mjs +1 -0
- package/dist/chunk-STBCV65G.js +3159 -0
- package/dist/chunk-UZL6BMXQ.mjs +3146 -0
- package/dist/chunk-ZJHF4QM5.js +2 -0
- package/dist/core.d.mts +160 -0
- package/dist/core.d.ts +160 -0
- package/dist/core.js +268 -0
- package/dist/core.mjs +3 -0
- package/dist/extras.d.mts +208 -0
- package/dist/extras.d.ts +208 -0
- package/dist/extras.js +388 -0
- package/dist/extras.mjs +380 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +152 -0
- package/dist/index.mjs +5 -0
- package/dist/legacy.d.mts +163 -0
- package/dist/legacy.d.ts +163 -0
- package/dist/legacy.js +331 -0
- package/dist/legacy.mjs +319 -0
- package/dist/position-BeP60S5h.d.ts +316 -0
- package/dist/position-CeG3Nr4z.d.mts +316 -0
- package/dist/react.d.mts +214 -0
- package/dist/react.d.ts +214 -0
- package/dist/react.js +94 -0
- package/dist/react.mjs +5 -0
- package/dist/responsive-D4zBXLkH.d.ts +145 -0
- package/dist/responsive-DQi_9rBi.d.mts +145 -0
- package/dist/types-Dbg8jAWj.d.mts +458 -0
- package/dist/types-Dbg8jAWj.d.ts +458 -0
- package/index-dev.js +23 -0
- package/index.js +8 -0
- package/package.json +238 -0
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
import { getStatics, collides, getFirstCollision, bottom, sortLayoutItemsByRowCol, cloneLayoutItem, sortLayoutItemsByColRow, cloneLayout, correctBounds } from './chunk-ITLZ7N2R.mjs';
|
|
2
|
+
|
|
3
|
+
// src/core/constraints.ts
|
|
4
|
+
function clamp(value, min, max) {
|
|
5
|
+
return Math.max(min, Math.min(max, value));
|
|
6
|
+
}
|
|
7
|
+
var gridBounds = {
|
|
8
|
+
name: "gridBounds",
|
|
9
|
+
constrainPosition(item, x, y, { cols, maxRows }) {
|
|
10
|
+
return {
|
|
11
|
+
x: clamp(x, 0, Math.max(0, cols - item.w)),
|
|
12
|
+
y: clamp(y, 0, Math.max(0, maxRows - item.h))
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
constrainSize(item, w, h, handle, { cols, maxRows }) {
|
|
16
|
+
const maxW = handle === "w" || handle === "nw" || handle === "sw" ? item.x + item.w : cols - item.x;
|
|
17
|
+
const maxH = handle === "n" || handle === "nw" || handle === "ne" ? item.y + item.h : maxRows - item.y;
|
|
18
|
+
return {
|
|
19
|
+
w: clamp(w, 1, Math.max(1, maxW)),
|
|
20
|
+
h: clamp(h, 1, Math.max(1, maxH))
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var minMaxSize = {
|
|
25
|
+
name: "minMaxSize",
|
|
26
|
+
constrainSize(item, w, h) {
|
|
27
|
+
return {
|
|
28
|
+
w: clamp(w, item.minW ?? 1, item.maxW ?? Infinity),
|
|
29
|
+
h: clamp(h, item.minH ?? 1, item.maxH ?? Infinity)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var containerBounds = {
|
|
34
|
+
name: "containerBounds",
|
|
35
|
+
constrainPosition(item, x, y, { cols, maxRows, containerHeight, rowHeight, margin }) {
|
|
36
|
+
const visibleRows = containerHeight > 0 ? Math.floor((containerHeight + margin[1]) / (rowHeight + margin[1])) : maxRows;
|
|
37
|
+
return {
|
|
38
|
+
x: clamp(x, 0, Math.max(0, cols - item.w)),
|
|
39
|
+
y: clamp(y, 0, Math.max(0, visibleRows - item.h))
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var boundedX = {
|
|
44
|
+
name: "boundedX",
|
|
45
|
+
constrainPosition(item, x, y, { cols }) {
|
|
46
|
+
return {
|
|
47
|
+
x: clamp(x, 0, Math.max(0, cols - item.w)),
|
|
48
|
+
y
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var boundedY = {
|
|
53
|
+
name: "boundedY",
|
|
54
|
+
constrainPosition(item, x, y, { maxRows }) {
|
|
55
|
+
return {
|
|
56
|
+
x,
|
|
57
|
+
y: clamp(y, 0, Math.max(0, maxRows - item.h))
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
function aspectRatio(ratio) {
|
|
62
|
+
return {
|
|
63
|
+
name: `aspectRatio(${ratio})`,
|
|
64
|
+
constrainSize(_item, w, _h, _handle, context) {
|
|
65
|
+
const { cols, containerWidth, rowHeight, margin } = context;
|
|
66
|
+
const colWidth = (containerWidth - margin[0] * (cols - 1)) / cols;
|
|
67
|
+
const pixelWidth = colWidth * w + margin[0] * Math.max(0, w - 1);
|
|
68
|
+
const pixelHeight = pixelWidth / ratio;
|
|
69
|
+
const h = Math.max(
|
|
70
|
+
1,
|
|
71
|
+
Math.round((pixelHeight + margin[1]) / (rowHeight + margin[1]))
|
|
72
|
+
);
|
|
73
|
+
return { w, h };
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function snapToGrid(stepX, stepY = stepX) {
|
|
78
|
+
if (stepX <= 0 || stepY <= 0) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`snapToGrid: step values must be positive (got stepX=${stepX}, stepY=${stepY})`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
name: `snapToGrid(${stepX}, ${stepY})`,
|
|
85
|
+
constrainPosition(_item, x, y) {
|
|
86
|
+
return {
|
|
87
|
+
x: Math.round(x / stepX) * stepX,
|
|
88
|
+
y: Math.round(y / stepY) * stepY
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function minSize(minW, minH) {
|
|
94
|
+
return {
|
|
95
|
+
name: `minSize(${minW}, ${minH})`,
|
|
96
|
+
constrainSize(_item, w, h) {
|
|
97
|
+
return {
|
|
98
|
+
w: Math.max(minW, w),
|
|
99
|
+
h: Math.max(minH, h)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function maxSize(maxW, maxH) {
|
|
105
|
+
return {
|
|
106
|
+
name: `maxSize(${maxW}, ${maxH})`,
|
|
107
|
+
constrainSize(_item, w, h) {
|
|
108
|
+
return {
|
|
109
|
+
w: Math.min(maxW, w),
|
|
110
|
+
h: Math.min(maxH, h)
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
var defaultConstraints = [gridBounds, minMaxSize];
|
|
116
|
+
function applyPositionConstraints(constraints, item, x, y, context) {
|
|
117
|
+
let result = { x, y };
|
|
118
|
+
for (const constraint of constraints) {
|
|
119
|
+
if (constraint.constrainPosition) {
|
|
120
|
+
result = constraint.constrainPosition(item, result.x, result.y, context);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (item.constraints) {
|
|
124
|
+
for (const constraint of item.constraints) {
|
|
125
|
+
if (constraint.constrainPosition) {
|
|
126
|
+
result = constraint.constrainPosition(
|
|
127
|
+
item,
|
|
128
|
+
result.x,
|
|
129
|
+
result.y,
|
|
130
|
+
context
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
function applySizeConstraints(constraints, item, w, h, handle, context) {
|
|
138
|
+
let result = { w, h };
|
|
139
|
+
for (const constraint of constraints) {
|
|
140
|
+
if (constraint.constrainSize) {
|
|
141
|
+
result = constraint.constrainSize(
|
|
142
|
+
item,
|
|
143
|
+
result.w,
|
|
144
|
+
result.h,
|
|
145
|
+
handle,
|
|
146
|
+
context
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (item.constraints) {
|
|
151
|
+
for (const constraint of item.constraints) {
|
|
152
|
+
if (constraint.constrainSize) {
|
|
153
|
+
result = constraint.constrainSize(
|
|
154
|
+
item,
|
|
155
|
+
result.w,
|
|
156
|
+
result.h,
|
|
157
|
+
handle,
|
|
158
|
+
context
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/core/position.ts
|
|
167
|
+
function setTransform({
|
|
168
|
+
top,
|
|
169
|
+
left,
|
|
170
|
+
width,
|
|
171
|
+
height
|
|
172
|
+
}) {
|
|
173
|
+
function buildTranslateValue(l, t) {
|
|
174
|
+
return `translate(${l}px,${t}px)`;
|
|
175
|
+
}
|
|
176
|
+
const translate = buildTranslateValue(left, top);
|
|
177
|
+
return {
|
|
178
|
+
transform: translate,
|
|
179
|
+
WebkitTransform: translate,
|
|
180
|
+
MozTransform: translate,
|
|
181
|
+
msTransform: translate,
|
|
182
|
+
OTransform: translate,
|
|
183
|
+
width: `${width}px`,
|
|
184
|
+
height: `${height}px`,
|
|
185
|
+
position: "absolute"
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function setTopLeft({
|
|
189
|
+
top,
|
|
190
|
+
left,
|
|
191
|
+
width,
|
|
192
|
+
height
|
|
193
|
+
}) {
|
|
194
|
+
return {
|
|
195
|
+
top: `${top}px`,
|
|
196
|
+
left: `${left}px`,
|
|
197
|
+
width: `${width}px`,
|
|
198
|
+
height: `${height}px`,
|
|
199
|
+
position: "absolute"
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function perc(num) {
|
|
203
|
+
return num * 100 + "%";
|
|
204
|
+
}
|
|
205
|
+
function constrainWidth(left, currentWidth, newWidth, containerWidth) {
|
|
206
|
+
return left + newWidth > containerWidth ? currentWidth : newWidth;
|
|
207
|
+
}
|
|
208
|
+
function constrainHeight(top, currentHeight, newHeight) {
|
|
209
|
+
return top < 0 ? currentHeight : newHeight;
|
|
210
|
+
}
|
|
211
|
+
function constrainLeft(left) {
|
|
212
|
+
return Math.max(0, left);
|
|
213
|
+
}
|
|
214
|
+
function constrainTop(top) {
|
|
215
|
+
return Math.max(0, top);
|
|
216
|
+
}
|
|
217
|
+
var resizeNorth = (currentSize, newSize, _containerWidth) => {
|
|
218
|
+
const { left, height, width } = newSize;
|
|
219
|
+
const top = currentSize.top - (height - currentSize.height);
|
|
220
|
+
return {
|
|
221
|
+
left,
|
|
222
|
+
width,
|
|
223
|
+
height: constrainHeight(top, currentSize.height, height),
|
|
224
|
+
top: constrainTop(top)
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
var resizeEast = (currentSize, newSize, containerWidth) => {
|
|
228
|
+
const { top, left, height, width } = newSize;
|
|
229
|
+
return {
|
|
230
|
+
top,
|
|
231
|
+
height,
|
|
232
|
+
width: constrainWidth(
|
|
233
|
+
currentSize.left,
|
|
234
|
+
currentSize.width,
|
|
235
|
+
width,
|
|
236
|
+
containerWidth
|
|
237
|
+
),
|
|
238
|
+
left: constrainLeft(left)
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
var resizeWest = (currentSize, newSize, _containerWidth) => {
|
|
242
|
+
const { top, height, width } = newSize;
|
|
243
|
+
const left = currentSize.left + currentSize.width - width;
|
|
244
|
+
if (left < 0) {
|
|
245
|
+
return {
|
|
246
|
+
height,
|
|
247
|
+
width: currentSize.left + currentSize.width,
|
|
248
|
+
top: constrainTop(top),
|
|
249
|
+
left: 0
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
height,
|
|
254
|
+
width,
|
|
255
|
+
top: constrainTop(top),
|
|
256
|
+
left
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
var resizeSouth = (currentSize, newSize, _containerWidth) => {
|
|
260
|
+
const { top, left, height, width } = newSize;
|
|
261
|
+
return {
|
|
262
|
+
width,
|
|
263
|
+
left,
|
|
264
|
+
height: constrainHeight(top, currentSize.height, height),
|
|
265
|
+
top: constrainTop(top)
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
var resizeNorthEast = (currentSize, newSize, containerWidth) => resizeNorth(
|
|
269
|
+
currentSize,
|
|
270
|
+
resizeEast(currentSize, newSize, containerWidth));
|
|
271
|
+
var resizeNorthWest = (currentSize, newSize, containerWidth) => resizeNorth(
|
|
272
|
+
currentSize,
|
|
273
|
+
resizeWest(currentSize, newSize));
|
|
274
|
+
var resizeSouthEast = (currentSize, newSize, containerWidth) => resizeSouth(
|
|
275
|
+
currentSize,
|
|
276
|
+
resizeEast(currentSize, newSize, containerWidth));
|
|
277
|
+
var resizeSouthWest = (currentSize, newSize, containerWidth) => resizeSouth(
|
|
278
|
+
currentSize,
|
|
279
|
+
resizeWest(currentSize, newSize));
|
|
280
|
+
var resizeHandlerMap = {
|
|
281
|
+
n: resizeNorth,
|
|
282
|
+
ne: resizeNorthEast,
|
|
283
|
+
e: resizeEast,
|
|
284
|
+
se: resizeSouthEast,
|
|
285
|
+
s: resizeSouth,
|
|
286
|
+
sw: resizeSouthWest,
|
|
287
|
+
w: resizeWest,
|
|
288
|
+
nw: resizeNorthWest
|
|
289
|
+
};
|
|
290
|
+
function resizeItemInDirection(direction, currentSize, newSize, containerWidth) {
|
|
291
|
+
const handler = resizeHandlerMap[direction];
|
|
292
|
+
if (!handler) {
|
|
293
|
+
return newSize;
|
|
294
|
+
}
|
|
295
|
+
return handler(currentSize, { ...currentSize, ...newSize }, containerWidth);
|
|
296
|
+
}
|
|
297
|
+
var transformStrategy = {
|
|
298
|
+
type: "transform",
|
|
299
|
+
scale: 1,
|
|
300
|
+
calcStyle(pos) {
|
|
301
|
+
return setTransform(pos);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
var absoluteStrategy = {
|
|
305
|
+
type: "absolute",
|
|
306
|
+
scale: 1,
|
|
307
|
+
calcStyle(pos) {
|
|
308
|
+
return setTopLeft(pos);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
function createScaledStrategy(scale) {
|
|
312
|
+
return {
|
|
313
|
+
type: "transform",
|
|
314
|
+
scale,
|
|
315
|
+
calcStyle(pos) {
|
|
316
|
+
return setTransform(pos);
|
|
317
|
+
},
|
|
318
|
+
calcDragPosition(clientX, clientY, offsetX, offsetY) {
|
|
319
|
+
return {
|
|
320
|
+
left: (clientX - offsetX) / scale,
|
|
321
|
+
top: (clientY - offsetY) / scale
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
var defaultPositionStrategy = transformStrategy;
|
|
327
|
+
|
|
328
|
+
// src/core/types.ts
|
|
329
|
+
var defaultGridConfig = {
|
|
330
|
+
cols: 12,
|
|
331
|
+
rowHeight: 150,
|
|
332
|
+
margin: [10, 10],
|
|
333
|
+
containerPadding: null,
|
|
334
|
+
maxRows: Infinity
|
|
335
|
+
};
|
|
336
|
+
var defaultDragConfig = {
|
|
337
|
+
enabled: true,
|
|
338
|
+
bounded: false,
|
|
339
|
+
threshold: 3
|
|
340
|
+
};
|
|
341
|
+
var defaultResizeConfig = {
|
|
342
|
+
enabled: true,
|
|
343
|
+
handles: ["se"]
|
|
344
|
+
};
|
|
345
|
+
var defaultDropConfig = /* @__PURE__ */ (() => {
|
|
346
|
+
const DEFAULT_DROPPING_ITEM_SIZE = { w: 1, h: 1 };
|
|
347
|
+
return { enabled: false, defaultItem: DEFAULT_DROPPING_ITEM_SIZE };
|
|
348
|
+
})();
|
|
349
|
+
|
|
350
|
+
// src/core/compactors.ts
|
|
351
|
+
function getCompactionTarget(item, collision, axis) {
|
|
352
|
+
return axis === "x" ? collision.x + collision.w : collision.y + collision.h;
|
|
353
|
+
}
|
|
354
|
+
function projectCompactionItem(item, moveToCoord, axis) {
|
|
355
|
+
if (axis === "x") {
|
|
356
|
+
return { i: item.i, x: moveToCoord, y: item.y, w: item.w, h: item.h };
|
|
357
|
+
}
|
|
358
|
+
return { i: item.i, x: item.x, y: moveToCoord, w: item.w, h: item.h };
|
|
359
|
+
}
|
|
360
|
+
function resolveCompactionCollision(layout, item, moveToCoord, axis, hasStatics) {
|
|
361
|
+
item[axis] += 1;
|
|
362
|
+
const itemIndex = layout.findIndex((l) => l.i === item.i);
|
|
363
|
+
const layoutHasStatics = hasStatics ?? getStatics(layout).length > 0;
|
|
364
|
+
const projectedItem = projectCompactionItem(item, moveToCoord, axis);
|
|
365
|
+
const projectedTarget = getCompactionTarget(
|
|
366
|
+
item,
|
|
367
|
+
projectedItem,
|
|
368
|
+
axis
|
|
369
|
+
);
|
|
370
|
+
for (let i = itemIndex + 1; i < layout.length; i++) {
|
|
371
|
+
const otherItem = layout[i];
|
|
372
|
+
if (otherItem === void 0) continue;
|
|
373
|
+
if (otherItem.static) continue;
|
|
374
|
+
if (!layoutHasStatics && otherItem.y > item.y + item.h) break;
|
|
375
|
+
if (collides(item, otherItem)) {
|
|
376
|
+
resolveCompactionCollision(
|
|
377
|
+
layout,
|
|
378
|
+
otherItem,
|
|
379
|
+
projectedTarget,
|
|
380
|
+
axis,
|
|
381
|
+
layoutHasStatics
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
item[axis] = moveToCoord;
|
|
386
|
+
}
|
|
387
|
+
function compactItemVertical(compareWith, l, fullLayout, maxY) {
|
|
388
|
+
l.x = Math.max(l.x, 0);
|
|
389
|
+
l.y = Math.max(l.y, 0);
|
|
390
|
+
l.y = Math.min(maxY, l.y);
|
|
391
|
+
while (l.y > 0 && !getFirstCollision(compareWith, l)) {
|
|
392
|
+
l.y--;
|
|
393
|
+
}
|
|
394
|
+
let collision;
|
|
395
|
+
while ((collision = getFirstCollision(compareWith, l)) !== void 0) {
|
|
396
|
+
resolveCompactionCollision(fullLayout, l, collision.y + collision.h, "y");
|
|
397
|
+
}
|
|
398
|
+
l.y = Math.max(l.y, 0);
|
|
399
|
+
return l;
|
|
400
|
+
}
|
|
401
|
+
function compactItemHorizontal(compareWith, l, cols, fullLayout) {
|
|
402
|
+
l.x = Math.max(l.x, 0);
|
|
403
|
+
l.y = Math.max(l.y, 0);
|
|
404
|
+
while (l.x > 0 && !getFirstCollision(compareWith, l)) {
|
|
405
|
+
l.x--;
|
|
406
|
+
}
|
|
407
|
+
let collision;
|
|
408
|
+
while ((collision = getFirstCollision(compareWith, l)) !== void 0) {
|
|
409
|
+
resolveCompactionCollision(fullLayout, l, collision.x + collision.w, "x");
|
|
410
|
+
if (l.x + l.w > cols) {
|
|
411
|
+
l.x = cols - l.w;
|
|
412
|
+
l.y++;
|
|
413
|
+
while (l.x > 0 && !getFirstCollision(compareWith, l)) {
|
|
414
|
+
l.x--;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
l.x = Math.max(l.x, 0);
|
|
419
|
+
return l;
|
|
420
|
+
}
|
|
421
|
+
var verticalCompactor = {
|
|
422
|
+
type: "vertical",
|
|
423
|
+
allowOverlap: false,
|
|
424
|
+
compact(layout, _cols) {
|
|
425
|
+
const compareWith = getStatics(layout);
|
|
426
|
+
let maxY = bottom(compareWith);
|
|
427
|
+
const sorted = sortLayoutItemsByRowCol(layout);
|
|
428
|
+
const out = new Array(layout.length);
|
|
429
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
430
|
+
const sortedItem = sorted[i];
|
|
431
|
+
if (sortedItem === void 0) continue;
|
|
432
|
+
let l = cloneLayoutItem(sortedItem);
|
|
433
|
+
if (!l.static) {
|
|
434
|
+
l = compactItemVertical(compareWith, l, sorted, maxY);
|
|
435
|
+
maxY = Math.max(maxY, l.y + l.h);
|
|
436
|
+
compareWith.push(l);
|
|
437
|
+
}
|
|
438
|
+
const originalIndex = layout.indexOf(sortedItem);
|
|
439
|
+
out[originalIndex] = l;
|
|
440
|
+
l.moved = false;
|
|
441
|
+
}
|
|
442
|
+
return out;
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
var horizontalCompactor = {
|
|
446
|
+
type: "horizontal",
|
|
447
|
+
allowOverlap: false,
|
|
448
|
+
compact(layout, cols) {
|
|
449
|
+
const compareWith = getStatics(layout);
|
|
450
|
+
const sorted = sortLayoutItemsByColRow(layout);
|
|
451
|
+
const out = new Array(layout.length);
|
|
452
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
453
|
+
const sortedItem = sorted[i];
|
|
454
|
+
if (sortedItem === void 0) continue;
|
|
455
|
+
let l = cloneLayoutItem(sortedItem);
|
|
456
|
+
if (!l.static) {
|
|
457
|
+
l = compactItemHorizontal(compareWith, l, cols, sorted);
|
|
458
|
+
compareWith.push(l);
|
|
459
|
+
}
|
|
460
|
+
const originalIndex = layout.indexOf(sortedItem);
|
|
461
|
+
out[originalIndex] = l;
|
|
462
|
+
l.moved = false;
|
|
463
|
+
}
|
|
464
|
+
return out;
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
var noCompactor = {
|
|
468
|
+
type: null,
|
|
469
|
+
allowOverlap: false,
|
|
470
|
+
compact(layout, _cols) {
|
|
471
|
+
return cloneLayout(layout);
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
var verticalOverlapCompactor = {
|
|
475
|
+
...verticalCompactor,
|
|
476
|
+
allowOverlap: true,
|
|
477
|
+
compact(layout, _cols) {
|
|
478
|
+
return cloneLayout(layout);
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
var horizontalOverlapCompactor = {
|
|
482
|
+
...horizontalCompactor,
|
|
483
|
+
allowOverlap: true,
|
|
484
|
+
compact(layout, _cols) {
|
|
485
|
+
return cloneLayout(layout);
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
var noOverlapCompactor = {
|
|
489
|
+
...noCompactor,
|
|
490
|
+
allowOverlap: true
|
|
491
|
+
};
|
|
492
|
+
function getCompactor(compactType, allowOverlap = false, preventCollision = false) {
|
|
493
|
+
let baseCompactor;
|
|
494
|
+
if (allowOverlap) {
|
|
495
|
+
if (compactType === "vertical") baseCompactor = verticalOverlapCompactor;
|
|
496
|
+
else if (compactType === "horizontal")
|
|
497
|
+
baseCompactor = horizontalOverlapCompactor;
|
|
498
|
+
else baseCompactor = noOverlapCompactor;
|
|
499
|
+
} else {
|
|
500
|
+
if (compactType === "vertical") baseCompactor = verticalCompactor;
|
|
501
|
+
else if (compactType === "horizontal") baseCompactor = horizontalCompactor;
|
|
502
|
+
else baseCompactor = noCompactor;
|
|
503
|
+
}
|
|
504
|
+
if (preventCollision) {
|
|
505
|
+
return { ...baseCompactor, preventCollision };
|
|
506
|
+
}
|
|
507
|
+
return baseCompactor;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// src/core/responsive.ts
|
|
511
|
+
function sortBreakpoints(breakpoints) {
|
|
512
|
+
const keys = Object.keys(breakpoints);
|
|
513
|
+
return keys.sort((a, b) => breakpoints[a] - breakpoints[b]);
|
|
514
|
+
}
|
|
515
|
+
function getBreakpointFromWidth(breakpoints, width) {
|
|
516
|
+
const sorted = sortBreakpoints(breakpoints);
|
|
517
|
+
let matching = sorted[0];
|
|
518
|
+
if (matching === void 0) {
|
|
519
|
+
throw new Error("No breakpoints defined");
|
|
520
|
+
}
|
|
521
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
522
|
+
const breakpointName = sorted[i];
|
|
523
|
+
if (breakpointName === void 0) continue;
|
|
524
|
+
const breakpointWidth = breakpoints[breakpointName];
|
|
525
|
+
if (width > breakpointWidth) {
|
|
526
|
+
matching = breakpointName;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return matching;
|
|
530
|
+
}
|
|
531
|
+
function getColsFromBreakpoint(breakpoint, cols) {
|
|
532
|
+
const colCount = cols[breakpoint];
|
|
533
|
+
if (colCount === void 0) {
|
|
534
|
+
throw new Error(
|
|
535
|
+
`ResponsiveReactGridLayout: \`cols\` entry for breakpoint ${String(breakpoint)} is missing!`
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
return colCount;
|
|
539
|
+
}
|
|
540
|
+
function findOrGenerateResponsiveLayout(layouts, breakpoints, breakpoint, lastBreakpoint, cols, compactTypeOrCompactor) {
|
|
541
|
+
const existingLayout = layouts[breakpoint];
|
|
542
|
+
if (existingLayout) {
|
|
543
|
+
return cloneLayout(existingLayout);
|
|
544
|
+
}
|
|
545
|
+
let layout = layouts[lastBreakpoint];
|
|
546
|
+
const breakpointsSorted = sortBreakpoints(breakpoints);
|
|
547
|
+
const breakpointsAbove = breakpointsSorted.slice(
|
|
548
|
+
breakpointsSorted.indexOf(breakpoint)
|
|
549
|
+
);
|
|
550
|
+
for (let i = 0; i < breakpointsAbove.length; i++) {
|
|
551
|
+
const b = breakpointsAbove[i];
|
|
552
|
+
if (b === void 0) continue;
|
|
553
|
+
const layoutForBreakpoint = layouts[b];
|
|
554
|
+
if (layoutForBreakpoint) {
|
|
555
|
+
layout = layoutForBreakpoint;
|
|
556
|
+
break;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
const clonedLayout = cloneLayout(layout || []);
|
|
560
|
+
const corrected = correctBounds(clonedLayout, { cols });
|
|
561
|
+
const compactor = typeof compactTypeOrCompactor === "object" && compactTypeOrCompactor !== null ? compactTypeOrCompactor : getCompactor(compactTypeOrCompactor);
|
|
562
|
+
return compactor.compact(corrected, cols);
|
|
563
|
+
}
|
|
564
|
+
function getIndentationValue(value, breakpoint) {
|
|
565
|
+
if (Array.isArray(value)) {
|
|
566
|
+
return value;
|
|
567
|
+
}
|
|
568
|
+
const breakpointMap = value;
|
|
569
|
+
const breakpointValue = breakpointMap[breakpoint];
|
|
570
|
+
if (breakpointValue !== void 0) {
|
|
571
|
+
return breakpointValue;
|
|
572
|
+
}
|
|
573
|
+
const keys = Object.keys(breakpointMap);
|
|
574
|
+
for (const key of keys) {
|
|
575
|
+
const v = breakpointMap[key];
|
|
576
|
+
if (v !== void 0) {
|
|
577
|
+
return v;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return [10, 10];
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
export { absoluteStrategy, applyPositionConstraints, applySizeConstraints, aspectRatio, boundedX, boundedY, compactItemHorizontal, compactItemVertical, containerBounds, createScaledStrategy, defaultConstraints, defaultDragConfig, defaultDropConfig, defaultGridConfig, defaultPositionStrategy, defaultResizeConfig, findOrGenerateResponsiveLayout, getBreakpointFromWidth, getColsFromBreakpoint, getCompactor, getIndentationValue, gridBounds, horizontalCompactor, horizontalOverlapCompactor, maxSize, minMaxSize, minSize, noCompactor, noOverlapCompactor, perc, resizeItemInDirection, resolveCompactionCollision, setTopLeft, setTransform, snapToGrid, sortBreakpoints, transformStrategy, verticalCompactor, verticalOverlapCompactor };
|