@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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -0
  3. package/css/styles.css +120 -0
  4. package/dist/ResponsiveGridLayout-B_6TXsWM.d.ts +80 -0
  5. package/dist/ResponsiveGridLayout-Bin5MBC3.d.mts +80 -0
  6. package/dist/calculate-CoBSgofg.d.mts +196 -0
  7. package/dist/calculate-K0IBpu53.d.ts +196 -0
  8. package/dist/chunk-7BT7XXIT.js +74 -0
  9. package/dist/chunk-G3PAJYGP.mjs +72 -0
  10. package/dist/chunk-ITLZ7N2R.mjs +456 -0
  11. package/dist/chunk-J4LTYI7L.js +485 -0
  12. package/dist/chunk-KKV4ZCG4.mjs +583 -0
  13. package/dist/chunk-LQOPWRJR.js +623 -0
  14. package/dist/chunk-O3KX3VYW.mjs +1 -0
  15. package/dist/chunk-STBCV65G.js +3159 -0
  16. package/dist/chunk-UZL6BMXQ.mjs +3146 -0
  17. package/dist/chunk-ZJHF4QM5.js +2 -0
  18. package/dist/core.d.mts +160 -0
  19. package/dist/core.d.ts +160 -0
  20. package/dist/core.js +268 -0
  21. package/dist/core.mjs +3 -0
  22. package/dist/extras.d.mts +208 -0
  23. package/dist/extras.d.ts +208 -0
  24. package/dist/extras.js +388 -0
  25. package/dist/extras.mjs +380 -0
  26. package/dist/index.d.mts +7 -0
  27. package/dist/index.d.ts +7 -0
  28. package/dist/index.js +152 -0
  29. package/dist/index.mjs +5 -0
  30. package/dist/legacy.d.mts +163 -0
  31. package/dist/legacy.d.ts +163 -0
  32. package/dist/legacy.js +331 -0
  33. package/dist/legacy.mjs +319 -0
  34. package/dist/position-BeP60S5h.d.ts +316 -0
  35. package/dist/position-CeG3Nr4z.d.mts +316 -0
  36. package/dist/react.d.mts +214 -0
  37. package/dist/react.d.ts +214 -0
  38. package/dist/react.js +94 -0
  39. package/dist/react.mjs +5 -0
  40. package/dist/responsive-D4zBXLkH.d.ts +145 -0
  41. package/dist/responsive-DQi_9rBi.d.mts +145 -0
  42. package/dist/types-Dbg8jAWj.d.mts +458 -0
  43. package/dist/types-Dbg8jAWj.d.ts +458 -0
  44. package/index-dev.js +23 -0
  45. package/index.js +8 -0
  46. package/package.json +238 -0
@@ -0,0 +1,3159 @@
1
+ 'use strict';
2
+
3
+ var chunkLQOPWRJR_js = require('./chunk-LQOPWRJR.js');
4
+ var chunkJ4LTYI7L_js = require('./chunk-J4LTYI7L.js');
5
+ var React3 = require('react');
6
+ var clsx = require('clsx');
7
+ var jsxRuntime = require('react/jsx-runtime');
8
+ var fastEquals = require('fast-equals');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var React3__default = /*#__PURE__*/_interopDefault(React3);
13
+ var clsx__default = /*#__PURE__*/_interopDefault(clsx);
14
+
15
+ var noopRef = () => {
16
+ };
17
+ function isTestRuntime() {
18
+ return process.env["NODE_ENV"] === "test";
19
+ }
20
+ function isRuntimeDndAvailable() {
21
+ return !isTestRuntime();
22
+ }
23
+ function loadReactDndRuntime() {
24
+ if (!isRuntimeDndAvailable()) {
25
+ return null;
26
+ }
27
+ return chunkJ4LTYI7L_js.__require("@dnd-kit/react");
28
+ }
29
+ function loadSortableRuntime() {
30
+ if (!isRuntimeDndAvailable()) {
31
+ return null;
32
+ }
33
+ return chunkJ4LTYI7L_js.__require("@dnd-kit/react/sortable");
34
+ }
35
+ function loadDomRuntime() {
36
+ if (!isRuntimeDndAvailable()) {
37
+ return null;
38
+ }
39
+ return chunkJ4LTYI7L_js.__require("@dnd-kit/dom");
40
+ }
41
+ function DragDropProvider({
42
+ children,
43
+ ...props
44
+ }) {
45
+ const runtime = loadReactDndRuntime();
46
+ if (!runtime) {
47
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
48
+ }
49
+ const Component = runtime.DragDropProvider;
50
+ return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props, children });
51
+ }
52
+ function DragOverlay({
53
+ children,
54
+ disabled,
55
+ dropAnimation
56
+ }) {
57
+ const runtime = loadReactDndRuntime();
58
+ if (!runtime || disabled) {
59
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {});
60
+ }
61
+ const Component = runtime.DragOverlay;
62
+ return /* @__PURE__ */ jsxRuntime.jsx(Component, { disabled, dropAnimation, children });
63
+ }
64
+ function useRuntimeSortable(input) {
65
+ const runtime = loadSortableRuntime();
66
+ if (!runtime) {
67
+ return {
68
+ isDragSource: false,
69
+ ref: noopRef,
70
+ handleRef: noopRef
71
+ };
72
+ }
73
+ return runtime.useSortable(input);
74
+ }
75
+ function useRuntimeDraggable(input) {
76
+ const runtime = loadReactDndRuntime();
77
+ if (!runtime) {
78
+ return {
79
+ isDragSource: false,
80
+ ref: noopRef,
81
+ handleRef: noopRef
82
+ };
83
+ }
84
+ return runtime.useDraggable(input);
85
+ }
86
+ function useRuntimeDragDropMonitor(handlers) {
87
+ const runtime = loadReactDndRuntime();
88
+ if (!runtime) {
89
+ React3__default.default.useEffect(() => {
90
+ console.debug("[runtime] useDragDropMonitor: runtime unavailable, handlers not attached", handlers);
91
+ }, [handlers]);
92
+ return;
93
+ }
94
+ const wrappedHandlers = React3__default.default.useMemo(() => {
95
+ const wrap = (name, fn) => {
96
+ if (!fn) return void 0;
97
+ return (event, manager) => {
98
+ try {
99
+ console.debug(`[runtime] dnd-monitor ${name}`, event, manager);
100
+ } catch (err) {
101
+ }
102
+ fn(event, manager);
103
+ };
104
+ };
105
+ return {
106
+ onDragStart: wrap("onDragStart", handlers.onDragStart),
107
+ onDragMove: wrap("onDragMove", handlers.onDragMove),
108
+ onDragEnd: wrap("onDragEnd", handlers.onDragEnd)
109
+ };
110
+ }, [handlers]);
111
+ runtime.useDragDropMonitor(wrappedHandlers);
112
+ }
113
+ var PointerSensor = {
114
+ configure(options) {
115
+ const runtime = loadDomRuntime();
116
+ return runtime ? runtime.PointerSensor.configure(options) : options;
117
+ }
118
+ };
119
+ var KeyboardSensor = {
120
+ configure(options) {
121
+ const runtime = loadDomRuntime();
122
+ return runtime ? runtime.KeyboardSensor.configure(options) : options;
123
+ }
124
+ };
125
+ var PointerActivationConstraints = {
126
+ Distance: class Distance {
127
+ constructor(options) {
128
+ const runtime = loadDomRuntime();
129
+ if (runtime && runtime.PointerActivationConstraints && runtime.PointerActivationConstraints.Distance) {
130
+ return new runtime.PointerActivationConstraints.Distance(options);
131
+ }
132
+ this.options = options;
133
+ }
134
+ }
135
+ };
136
+ function describeElementForDebug(node) {
137
+ if (!(node instanceof Element)) {
138
+ return null;
139
+ }
140
+ const className = typeof node.className === "string" ? node.className.trim() : "";
141
+ return className.length > 0 ? `${node.tagName.toLowerCase()}.${className.replace(/\s+/g, ".")}` : node.tagName.toLowerCase();
142
+ }
143
+ function getGridItemResizeData(data) {
144
+ if (!data || typeof data !== "object") {
145
+ return null;
146
+ }
147
+ const itemId = data.itemId;
148
+ const axis = data.axis;
149
+ const kind = data.kind;
150
+ return kind === "resize" && typeof itemId === "string" && typeof axis === "string" ? { kind, itemId, axis } : null;
151
+ }
152
+ function GridResizeHandle({
153
+ axis,
154
+ itemId,
155
+ resizeHandle,
156
+ supportsDndKitResize,
157
+ onPointerDown,
158
+ onMouseDown,
159
+ onTouchStart
160
+ }) {
161
+ const commonClassName = clsx__default.default(
162
+ "react-resizable-handle",
163
+ `react-resizable-handle-${axis}`
164
+ );
165
+ const { ref: resizeRef } = useRuntimeDraggable({
166
+ id: `${itemId}:resize:${axis}`,
167
+ data: {
168
+ kind: "resize",
169
+ itemId,
170
+ axis
171
+ },
172
+ disabled: !supportsDndKitResize,
173
+ feedback: "none"
174
+ });
175
+ const commonProps = {
176
+ className: commonClassName,
177
+ onPointerDown,
178
+ onMouseDown,
179
+ onTouchStart,
180
+ ref: supportsDndKitResize ? resizeRef : null,
181
+ style: { touchAction: "none" }
182
+ };
183
+ if (typeof resizeHandle === "function") {
184
+ return React3__default.default.cloneElement(
185
+ resizeHandle(axis, supportsDndKitResize ? resizeRef : null),
186
+ commonProps
187
+ );
188
+ }
189
+ if (React3__default.default.isValidElement(resizeHandle)) {
190
+ const element = resizeHandle;
191
+ return React3__default.default.cloneElement(element, {
192
+ ...commonProps,
193
+ className: clsx__default.default(commonClassName, element.props.className)
194
+ });
195
+ }
196
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { ...commonProps }, axis);
197
+ }
198
+ function getTargetElement(target) {
199
+ return target instanceof HTMLElement ? target : null;
200
+ }
201
+ function isTouchInputEvent(event) {
202
+ return "changedTouches" in event;
203
+ }
204
+ function isMouseLikeInputEvent(event) {
205
+ return !isTouchInputEvent(event);
206
+ }
207
+ function getTrackedTouch(event, touchId) {
208
+ const touchLists = [event.changedTouches, event.touches, event.targetTouches];
209
+ for (const touchList of touchLists) {
210
+ for (let index = 0; index < touchList.length; index += 1) {
211
+ const touch = typeof touchList.item === "function" ? touchList.item(index) : touchList[index];
212
+ if (!touch) {
213
+ continue;
214
+ }
215
+ if (touchId === void 0 || touch.identifier === touchId) {
216
+ return touch;
217
+ }
218
+ }
219
+ }
220
+ return null;
221
+ }
222
+ function getInputCoordinates(event, touchId) {
223
+ if (isTouchInputEvent(event)) {
224
+ const touch = getTrackedTouch(event, touchId);
225
+ return touch ? { clientX: touch.clientX, clientY: touch.clientY } : null;
226
+ }
227
+ return { clientX: event.clientX, clientY: event.clientY };
228
+ }
229
+ function createResizeCandidate(origin, handle, deltaX, deltaY) {
230
+ const next = { ...origin };
231
+ if (handle.includes("e")) {
232
+ next.width = origin.width + deltaX;
233
+ }
234
+ if (handle.includes("s")) {
235
+ next.height = origin.height + deltaY;
236
+ }
237
+ if (handle.includes("w")) {
238
+ next.width = origin.width - deltaX;
239
+ next.left = origin.left + deltaX;
240
+ }
241
+ if (handle.includes("n")) {
242
+ next.height = origin.height - deltaY;
243
+ next.top = origin.top + deltaY;
244
+ }
245
+ return next;
246
+ }
247
+ function isPrimaryInputStart(kind, event) {
248
+ if (kind === "touch") {
249
+ return true;
250
+ }
251
+ return isMouseLikeInputEvent(event) && event.button === 0;
252
+ }
253
+ function getTrackedInputId(kind, event) {
254
+ return kind === "touch" && isTouchInputEvent(event) ? getTrackedTouch(event)?.identifier : void 0;
255
+ }
256
+ function isTrackedInputEvent(kind, startEvent, nextEvent) {
257
+ if (kind === "pointer" && nextEvent instanceof PointerEvent && startEvent instanceof PointerEvent) {
258
+ return nextEvent.pointerId === startEvent.pointerId;
259
+ }
260
+ return true;
261
+ }
262
+ function preventTouchMoveDefault(kind, event) {
263
+ if (kind === "touch" && isTouchInputEvent(event)) {
264
+ event.preventDefault();
265
+ }
266
+ }
267
+ function createNativeInteractionSession(kind, startEvent, node, onMove, onEnd) {
268
+ const ownerDocument = node.ownerDocument ?? document;
269
+ if (kind === "pointer" && startEvent instanceof PointerEvent) {
270
+ const moveListener = (moveEvent) => onMove(moveEvent);
271
+ const endListener = (endEvent) => onEnd(endEvent);
272
+ ownerDocument.addEventListener("pointermove", moveListener);
273
+ ownerDocument.addEventListener("pointerup", endListener);
274
+ ownerDocument.addEventListener("pointercancel", endListener);
275
+ node.setPointerCapture?.(startEvent.pointerId);
276
+ return () => {
277
+ ownerDocument.removeEventListener("pointermove", moveListener);
278
+ ownerDocument.removeEventListener("pointerup", endListener);
279
+ ownerDocument.removeEventListener("pointercancel", endListener);
280
+ if (node.hasPointerCapture?.(startEvent.pointerId)) {
281
+ node.releasePointerCapture(startEvent.pointerId);
282
+ }
283
+ };
284
+ }
285
+ if (kind === "mouse" && startEvent instanceof MouseEvent) {
286
+ const moveListener = (moveEvent) => onMove(moveEvent);
287
+ const endListener = (endEvent) => onEnd(endEvent);
288
+ ownerDocument.addEventListener("mousemove", moveListener);
289
+ ownerDocument.addEventListener("mouseup", endListener);
290
+ return () => {
291
+ ownerDocument.removeEventListener("mousemove", moveListener);
292
+ ownerDocument.removeEventListener("mouseup", endListener);
293
+ };
294
+ }
295
+ if (kind === "touch" && isTouchInputEvent(startEvent)) {
296
+ const moveListener = (moveEvent) => onMove(moveEvent);
297
+ const endListener = (endEvent) => onEnd(endEvent);
298
+ ownerDocument.addEventListener("touchmove", moveListener, {
299
+ passive: false
300
+ });
301
+ ownerDocument.addEventListener("touchend", endListener);
302
+ ownerDocument.addEventListener("touchcancel", endListener);
303
+ return () => {
304
+ ownerDocument.removeEventListener("touchmove", moveListener);
305
+ ownerDocument.removeEventListener("touchend", endListener);
306
+ ownerDocument.removeEventListener("touchcancel", endListener);
307
+ };
308
+ }
309
+ return () => {
310
+ };
311
+ }
312
+ function GridItem(props) {
313
+ const {
314
+ children,
315
+ cols,
316
+ containerWidth,
317
+ margin,
318
+ containerPadding,
319
+ rowHeight,
320
+ maxRows,
321
+ isDraggable,
322
+ isResizable,
323
+ isBounded,
324
+ static: isStatic,
325
+ useCSSTransforms = true,
326
+ usePercentages = false,
327
+ transformScale = 1,
328
+ positionStrategy,
329
+ dragThreshold = 0,
330
+ droppingPosition,
331
+ enableSortable = true,
332
+ className = "",
333
+ style,
334
+ handle = "",
335
+ cancel = "",
336
+ x,
337
+ y,
338
+ w,
339
+ h,
340
+ minW = 1,
341
+ maxW = Infinity,
342
+ minH = 1,
343
+ maxH = Infinity,
344
+ i,
345
+ resizeHandles,
346
+ resizeHandle,
347
+ constraints = chunkLQOPWRJR_js.defaultConstraints,
348
+ isDndKitDragSource = false,
349
+ layoutItem,
350
+ layout = [],
351
+ onDragStart: onDragStartProp,
352
+ onDrag: onDragProp,
353
+ onDragStop: onDragStopProp,
354
+ onResizeStart: onResizeStartProp,
355
+ onResize: onResizeProp,
356
+ onResizeStop: onResizeStopProp,
357
+ onResizeCancel: onResizeCancelProp
358
+ } = props;
359
+ const [dragging, setDragging] = React3.useState(false);
360
+ const [resizing, setResizing] = React3.useState(false);
361
+ const elementRef = React3.useRef(null);
362
+ const dragPositionRef = React3.useRef({ left: 0, top: 0 });
363
+ const resizePositionRef = React3.useRef({
364
+ top: 0,
365
+ left: 0,
366
+ width: 0,
367
+ height: 0
368
+ });
369
+ const prevDroppingPositionRef = React3.useRef(void 0);
370
+ const layoutRef = React3.useRef(layout);
371
+ const dragSessionRef = React3.useRef(null);
372
+ const resizeSessionRef = React3.useRef(null);
373
+ const dragPendingRef = React3.useRef(false);
374
+ const initialDragClientRef = React3.useRef({ x: 0, y: 0 });
375
+ const thresholdExceededRef = React3.useRef(false);
376
+ const draggingRef = React3.useRef(false);
377
+ const activeDndResizeRef = React3.useRef(null);
378
+ const runtimeDndAvailable = isRuntimeDndAvailable();
379
+ const nativePointerEventsAvailable = typeof window !== "undefined" && "PointerEvent" in window;
380
+ const runtimePointerEventsAvailable = enableSortable && nativePointerEventsAvailable;
381
+ const supportsDndKitRuntime = runtimeDndAvailable && runtimePointerEventsAvailable;
382
+ const supportsDndKitDrag = supportsDndKitRuntime && isDraggable && !isStatic;
383
+ const supportsDndKitResize = supportsDndKitRuntime && isResizable && !isStatic;
384
+ const useNativeDragFallback = !supportsDndKitDrag && isDraggable && !isStatic;
385
+ const useNativeResizeFallback = !supportsDndKitResize && isResizable && !isStatic;
386
+ layoutRef.current = layout;
387
+ const resolvedResizeHandles = React3.useMemo(
388
+ () => [...resizeHandles ?? ["se"]],
389
+ [resizeHandles]
390
+ );
391
+ const sortableIndex = React3.useMemo(
392
+ () => Math.max(0, layout.findIndex((item) => item.i === i)),
393
+ [layout, i]
394
+ );
395
+ const {
396
+ isDragSource: isSortableDragSource,
397
+ ref: sortableRef,
398
+ handleRef: sortableHandleRef
399
+ } = useRuntimeSortable({
400
+ id: i,
401
+ index: sortableIndex,
402
+ group: "react-grid-layout",
403
+ data: { kind: "drag", itemId: i },
404
+ disabled: !supportsDndKitDrag,
405
+ feedback: "none",
406
+ transition: null
407
+ });
408
+ const dragCancelSelector = React3.useMemo(
409
+ () => [".react-resizable-handle", cancel].filter((value) => value.length > 0).join(","),
410
+ [cancel]
411
+ );
412
+ const setElementRef = React3.useCallback(
413
+ (node) => {
414
+ elementRef.current = node;
415
+ console.debug("[GridItem] setElementRef", {
416
+ i,
417
+ node: describeElementForDebug(node),
418
+ connected: node?.isConnected ?? false,
419
+ supportsDndKitDrag,
420
+ handle
421
+ });
422
+ sortableRef(node);
423
+ if (!supportsDndKitDrag) {
424
+ sortableHandleRef(null);
425
+ return;
426
+ }
427
+ const handleElement = handle && node ? node.querySelector(handle) : null;
428
+ console.debug("[GridItem] setElementRef: sortable handle assigned", {
429
+ i,
430
+ handle,
431
+ handleElement: describeElementForDebug(handleElement)
432
+ });
433
+ sortableHandleRef(handleElement instanceof Element ? handleElement : null);
434
+ },
435
+ [handle, i, sortableHandleRef, sortableRef, supportsDndKitDrag]
436
+ );
437
+ const positionParams = React3.useMemo(
438
+ () => ({
439
+ cols,
440
+ containerPadding,
441
+ containerWidth,
442
+ margin,
443
+ maxRows,
444
+ rowHeight
445
+ }),
446
+ [cols, containerPadding, containerWidth, margin, maxRows, rowHeight]
447
+ );
448
+ function createGridItemDndSnapshot(snapshotParams, item, dragPosition, resizePosition) {
449
+ const position = chunkJ4LTYI7L_js.calcGridItemPosition(
450
+ snapshotParams,
451
+ item.x,
452
+ item.y,
453
+ item.w,
454
+ item.h,
455
+ dragPosition ?? null,
456
+ resizePosition ?? null
457
+ );
458
+ const { x: gridX, y: gridY } = chunkJ4LTYI7L_js.calcXYRaw(
459
+ snapshotParams,
460
+ position.top,
461
+ position.left
462
+ );
463
+ return {
464
+ left: position.left,
465
+ top: position.top,
466
+ width: position.width,
467
+ height: position.height,
468
+ gridX,
469
+ gridY
470
+ };
471
+ }
472
+ function getGridItemPixelDelta(previous, next) {
473
+ return {
474
+ deltaX: next.left - previous.left,
475
+ deltaY: next.top - previous.top
476
+ };
477
+ }
478
+ const constraintContext = React3.useMemo(
479
+ () => ({
480
+ cols,
481
+ maxRows,
482
+ containerWidth,
483
+ containerHeight: 0,
484
+ rowHeight,
485
+ margin,
486
+ layout: []
487
+ }),
488
+ [cols, maxRows, containerWidth, rowHeight, margin]
489
+ );
490
+ const getConstraintContext = React3.useCallback(
491
+ () => ({
492
+ ...constraintContext,
493
+ layout: layoutRef.current
494
+ }),
495
+ [constraintContext]
496
+ );
497
+ const getRuntimeInteractionEvent = React3.useCallback(
498
+ (event) => event.nativeEvent ?? event.operation.activatorEvent ?? new Event("drag"),
499
+ []
500
+ );
501
+ const effectiveLayoutItem = React3.useMemo(
502
+ () => layoutItem ?? {
503
+ i,
504
+ x,
505
+ y,
506
+ w,
507
+ h,
508
+ minW,
509
+ maxW,
510
+ minH,
511
+ maxH
512
+ },
513
+ [layoutItem, i, x, y, w, h, minW, maxW, minH, maxH]
514
+ );
515
+ const createStyle = React3.useCallback(
516
+ (pos2) => {
517
+ if (positionStrategy?.calcStyle) {
518
+ return positionStrategy.calcStyle(pos2);
519
+ }
520
+ if (useCSSTransforms) {
521
+ return chunkLQOPWRJR_js.setTransform(pos2);
522
+ }
523
+ const styleObject = chunkLQOPWRJR_js.setTopLeft(pos2);
524
+ if (usePercentages) {
525
+ return {
526
+ ...styleObject,
527
+ left: chunkLQOPWRJR_js.perc(pos2.left / containerWidth),
528
+ width: chunkLQOPWRJR_js.perc(pos2.width / containerWidth)
529
+ };
530
+ }
531
+ return styleObject;
532
+ },
533
+ [positionStrategy, useCSSTransforms, usePercentages, containerWidth]
534
+ );
535
+ const getDragStartPosition = React3.useCallback(
536
+ (clientX, clientY, node) => {
537
+ const { offsetParent } = node;
538
+ if (!offsetParent) {
539
+ return null;
540
+ }
541
+ const parentRect = offsetParent.getBoundingClientRect();
542
+ const clientRect = node.getBoundingClientRect();
543
+ const cLeft = clientRect.left / transformScale;
544
+ const pLeft = parentRect.left / transformScale;
545
+ const cTop = clientRect.top / transformScale;
546
+ const pTop = parentRect.top / transformScale;
547
+ if (positionStrategy?.calcDragPosition) {
548
+ return positionStrategy.calcDragPosition(
549
+ clientX,
550
+ clientY,
551
+ clientX - clientRect.left,
552
+ clientY - clientRect.top
553
+ );
554
+ }
555
+ return {
556
+ left: cLeft - pLeft + offsetParent.scrollLeft,
557
+ top: cTop - pTop + offsetParent.scrollTop
558
+ };
559
+ },
560
+ [positionStrategy, transformScale]
561
+ );
562
+ const clearDragSession = React3.useCallback(() => {
563
+ const session = dragSessionRef.current;
564
+ if (!session) {
565
+ return;
566
+ }
567
+ session.cleanup();
568
+ dragSessionRef.current = null;
569
+ }, []);
570
+ const clearResizeSession = React3.useCallback(() => {
571
+ const session = resizeSessionRef.current;
572
+ if (!session) {
573
+ return;
574
+ }
575
+ session.cleanup();
576
+ resizeSessionRef.current = null;
577
+ }, []);
578
+ const emitDragStart = React3.useCallback(
579
+ (event, node, newPosition, skipThreshold, clientX, clientY) => {
580
+ console.debug("[GridItem] emitDragStart", { i, skipThreshold, clientX, clientY, newPosition });
581
+ dragPositionRef.current = newPosition;
582
+ if (clientX !== void 0 && clientY !== void 0) {
583
+ initialDragClientRef.current = { x: clientX, y: clientY };
584
+ }
585
+ setDragging(true);
586
+ draggingRef.current = true;
587
+ if (dragThreshold > 0 && !skipThreshold) {
588
+ dragPendingRef.current = true;
589
+ thresholdExceededRef.current = false;
590
+ return;
591
+ }
592
+ dragPendingRef.current = false;
593
+ thresholdExceededRef.current = true;
594
+ if (!onDragStartProp) {
595
+ return;
596
+ }
597
+ const rawPos = chunkJ4LTYI7L_js.calcXYRaw(positionParams, newPosition.top, newPosition.left);
598
+ const { x: newX, y: newY } = chunkLQOPWRJR_js.applyPositionConstraints(
599
+ constraints,
600
+ effectiveLayoutItem,
601
+ rawPos.x,
602
+ rawPos.y,
603
+ getConstraintContext()
604
+ );
605
+ console.debug("[GridItem] calling onDragStartProp", i, newX, newY);
606
+ onDragStartProp(i, newX, newY, {
607
+ e: event,
608
+ node,
609
+ newPosition
610
+ });
611
+ },
612
+ [
613
+ dragThreshold,
614
+ onDragStartProp,
615
+ positionParams,
616
+ constraints,
617
+ effectiveLayoutItem,
618
+ getConstraintContext,
619
+ i
620
+ ]
621
+ );
622
+ const emitDragMove = React3.useCallback(
623
+ (event, node, deltaX, deltaY, clientX, clientY) => {
624
+ console.debug("[GridItem] emitDragMove", { i, deltaX, deltaY, clientX, clientY });
625
+ if (!draggingRef.current && !dragPendingRef.current) {
626
+ return;
627
+ }
628
+ if (dragPendingRef.current && !thresholdExceededRef.current && clientX !== void 0 && clientY !== void 0) {
629
+ const dx = clientX - initialDragClientRef.current.x;
630
+ const dy = clientY - initialDragClientRef.current.y;
631
+ const distance = Math.hypot(dx, dy);
632
+ if (distance < dragThreshold) {
633
+ return;
634
+ }
635
+ thresholdExceededRef.current = true;
636
+ dragPendingRef.current = false;
637
+ if (onDragStartProp) {
638
+ const rawPos2 = chunkJ4LTYI7L_js.calcXYRaw(
639
+ positionParams,
640
+ dragPositionRef.current.top,
641
+ dragPositionRef.current.left
642
+ );
643
+ const { x: startX, y: startY } = chunkLQOPWRJR_js.applyPositionConstraints(
644
+ constraints,
645
+ effectiveLayoutItem,
646
+ rawPos2.x,
647
+ rawPos2.y,
648
+ getConstraintContext()
649
+ );
650
+ console.debug("[GridItem] emitting onDragStart from pending state", i, startX, startY);
651
+ onDragStartProp(i, startX, startY, {
652
+ e: event,
653
+ node,
654
+ newPosition: dragPositionRef.current
655
+ });
656
+ }
657
+ }
658
+ let top = dragPositionRef.current.top + deltaY;
659
+ let left = dragPositionRef.current.left + deltaX;
660
+ if (isBounded) {
661
+ const { offsetParent } = node;
662
+ if (offsetParent) {
663
+ const bottomBoundary = offsetParent.clientHeight - chunkJ4LTYI7L_js.calcGridItemWHPx(h, rowHeight, margin[1]);
664
+ top = chunkJ4LTYI7L_js.clamp(top, 0, bottomBoundary);
665
+ const colWidth = chunkJ4LTYI7L_js.calcGridColWidth(positionParams);
666
+ const rightBoundary = containerWidth - chunkJ4LTYI7L_js.calcGridItemWHPx(w, colWidth, margin[0]);
667
+ left = chunkJ4LTYI7L_js.clamp(left, 0, rightBoundary);
668
+ }
669
+ }
670
+ const newPosition = { top, left };
671
+ dragPositionRef.current = newPosition;
672
+ if (!onDragProp) {
673
+ return;
674
+ }
675
+ const rawPos = chunkJ4LTYI7L_js.calcXYRaw(positionParams, top, left);
676
+ const { x: newX, y: newY } = chunkLQOPWRJR_js.applyPositionConstraints(
677
+ constraints,
678
+ effectiveLayoutItem,
679
+ rawPos.x,
680
+ rawPos.y,
681
+ getConstraintContext()
682
+ );
683
+ console.debug("[GridItem] calling onDragProp", i, newX, newY);
684
+ onDragProp(i, newX, newY, {
685
+ e: event,
686
+ node,
687
+ newPosition
688
+ });
689
+ },
690
+ [
691
+ dragThreshold,
692
+ onDragStartProp,
693
+ positionParams,
694
+ constraints,
695
+ effectiveLayoutItem,
696
+ getConstraintContext,
697
+ i,
698
+ isBounded,
699
+ h,
700
+ rowHeight,
701
+ margin,
702
+ containerWidth,
703
+ w,
704
+ onDragProp
705
+ ]
706
+ );
707
+ const emitDragStop = React3.useCallback(
708
+ (event, node) => {
709
+ console.debug("[GridItem] emitDragStop", { i, eventType: event?.type });
710
+ if (!draggingRef.current && !dragPendingRef.current) {
711
+ return;
712
+ }
713
+ const wasPending = dragPendingRef.current;
714
+ dragPendingRef.current = false;
715
+ thresholdExceededRef.current = false;
716
+ initialDragClientRef.current = { x: 0, y: 0 };
717
+ if (wasPending) {
718
+ setDragging(false);
719
+ draggingRef.current = false;
720
+ dragPositionRef.current = { left: 0, top: 0 };
721
+ return;
722
+ }
723
+ const { left, top } = dragPositionRef.current;
724
+ const newPosition = { top, left };
725
+ setDragging(false);
726
+ draggingRef.current = false;
727
+ dragPositionRef.current = { left: 0, top: 0 };
728
+ if (!onDragStopProp) {
729
+ return;
730
+ }
731
+ const rawPos = chunkJ4LTYI7L_js.calcXYRaw(positionParams, top, left);
732
+ const { x: newX, y: newY } = chunkLQOPWRJR_js.applyPositionConstraints(
733
+ constraints,
734
+ effectiveLayoutItem,
735
+ rawPos.x,
736
+ rawPos.y,
737
+ getConstraintContext()
738
+ );
739
+ console.debug("[GridItem] calling onDragStopProp", i, newX, newY);
740
+ onDragStopProp(i, newX, newY, {
741
+ e: event,
742
+ node,
743
+ newPosition
744
+ });
745
+ },
746
+ [
747
+ onDragStopProp,
748
+ positionParams,
749
+ constraints,
750
+ effectiveLayoutItem,
751
+ getConstraintContext,
752
+ i
753
+ ]
754
+ );
755
+ const emitResize = React3.useCallback(
756
+ (handlerName, event, data, origin) => {
757
+ console.debug("[GridItem] emitResize", { i, handlerName, data, origin });
758
+ const handler = handlerName === "onResizeStart" ? onResizeStartProp : handlerName === "onResize" ? onResizeProp : onResizeStopProp;
759
+ resizePositionRef.current = data.size;
760
+ if (!handler) {
761
+ console.debug("[GridItem] emitResize: no handler", handlerName);
762
+ return;
763
+ }
764
+ const updatedSize = chunkLQOPWRJR_js.resizeItemInDirection(
765
+ data.handle,
766
+ origin,
767
+ data.size,
768
+ containerWidth
769
+ );
770
+ resizePositionRef.current = updatedSize;
771
+ const rawSize = chunkJ4LTYI7L_js.calcWHRaw(
772
+ positionParams,
773
+ updatedSize.width,
774
+ updatedSize.height
775
+ );
776
+ const { w: newW, h: newH } = chunkLQOPWRJR_js.applySizeConstraints(
777
+ constraints,
778
+ effectiveLayoutItem,
779
+ rawSize.w,
780
+ rawSize.h,
781
+ data.handle,
782
+ getConstraintContext()
783
+ );
784
+ console.debug("[GridItem] calling resize handler", { i, handlerName, newW, newH, updatedSize });
785
+ handler(i, newW, newH, {
786
+ e: event,
787
+ node: data.node,
788
+ size: updatedSize,
789
+ handle: data.handle
790
+ });
791
+ },
792
+ [
793
+ onResizeStartProp,
794
+ onResizeProp,
795
+ onResizeStopProp,
796
+ containerWidth,
797
+ positionParams,
798
+ constraints,
799
+ effectiveLayoutItem,
800
+ getConstraintContext,
801
+ i
802
+ ]
803
+ );
804
+ const clearDndResizeState = React3.useCallback(() => {
805
+ activeDndResizeRef.current = null;
806
+ setResizing(false);
807
+ resizePositionRef.current = { top: 0, left: 0, width: 0, height: 0 };
808
+ }, []);
809
+ useRuntimeDragDropMonitor({
810
+ onDragStart: (event) => {
811
+ console.debug("[GridItem] runtime onDragStart", { i, event });
812
+ const resizeData = getGridItemResizeData(event.operation.source?.data);
813
+ if (!supportsDndKitResize || !resizeData || resizeData.itemId !== i) {
814
+ console.debug("[GridItem] runtime onDragStart: ignored", { supportsDndKitResize, resizeData });
815
+ return;
816
+ }
817
+ const node = elementRef.current;
818
+ if (!node) {
819
+ console.debug("[GridItem] runtime onDragStart: no node");
820
+ return;
821
+ }
822
+ const origin = chunkJ4LTYI7L_js.calcGridItemPosition(positionParams, x, y, w, h);
823
+ activeDndResizeRef.current = {
824
+ axis: resizeData.axis,
825
+ node,
826
+ origin,
827
+ initialPointer: (() => {
828
+ const ae = event.operation.activatorEvent;
829
+ return ae ? { x: ae.clientX ?? 0, y: ae.clientY ?? 0 } : { x: 0, y: 0 };
830
+ })()
831
+ };
832
+ setResizing(true);
833
+ emitResize(
834
+ "onResizeStart",
835
+ getRuntimeInteractionEvent(event),
836
+ { node, size: origin, handle: resizeData.axis },
837
+ origin
838
+ );
839
+ },
840
+ onDragMove: (event) => {
841
+ console.debug("[GridItem] runtime onDragMove", { i, event });
842
+ const session = activeDndResizeRef.current;
843
+ const resizeData = getGridItemResizeData(event.operation.source?.data);
844
+ if (!session || !supportsDndKitResize || !resizeData || resizeData.itemId !== i || resizeData.axis !== session.axis) {
845
+ console.debug("[GridItem] runtime onDragMove: ignored", { session, resizeData });
846
+ return;
847
+ }
848
+ const moveTransform = event.to ? {
849
+ x: event.to.x - session.initialPointer.x,
850
+ y: event.to.y - session.initialPointer.y
851
+ } : event.operation.transform;
852
+ const nextCandidate = createResizeCandidate(
853
+ session.origin,
854
+ resizeData.axis,
855
+ moveTransform.x / transformScale,
856
+ moveTransform.y / transformScale
857
+ );
858
+ emitResize(
859
+ "onResize",
860
+ getRuntimeInteractionEvent(event),
861
+ { node: session.node, size: nextCandidate, handle: resizeData.axis },
862
+ session.origin
863
+ );
864
+ },
865
+ onDragEnd: (event) => {
866
+ console.debug("[GridItem] runtime onDragEnd", { i, event });
867
+ const session = activeDndResizeRef.current;
868
+ const resizeData = getGridItemResizeData(event.operation.source?.data);
869
+ if (!session || !supportsDndKitResize || !resizeData || resizeData.itemId !== i || resizeData.axis !== session.axis) {
870
+ console.debug("[GridItem] runtime onDragEnd: ignored", { session, resizeData });
871
+ return;
872
+ }
873
+ const nativeEnd = event.nativeEvent instanceof PointerEvent ? event.nativeEvent : null;
874
+ const endTransform = nativeEnd ? {
875
+ x: nativeEnd.clientX - session.initialPointer.x,
876
+ y: nativeEnd.clientY - session.initialPointer.y
877
+ } : event.operation.transform;
878
+ const nextCandidate = event.canceled ? session.origin : createResizeCandidate(
879
+ session.origin,
880
+ resizeData.axis,
881
+ endTransform.x / transformScale,
882
+ endTransform.y / transformScale
883
+ );
884
+ if (event.canceled) {
885
+ onResizeCancelProp?.(i);
886
+ clearDndResizeState();
887
+ return;
888
+ }
889
+ emitResize(
890
+ "onResizeStop",
891
+ getRuntimeInteractionEvent(event),
892
+ { node: session.node, size: nextCandidate, handle: resizeData.axis },
893
+ session.origin
894
+ );
895
+ clearDndResizeState();
896
+ }
897
+ });
898
+ const startDragSession = React3.useCallback(
899
+ (event, kind) => {
900
+ if (!isDraggable || isStatic || dragSessionRef.current) {
901
+ return;
902
+ }
903
+ if (!isPrimaryInputStart(kind, event)) {
904
+ return;
905
+ }
906
+ const node = elementRef.current;
907
+ const target = getTargetElement(event.target);
908
+ if (!node || !target) {
909
+ return;
910
+ }
911
+ if (dragCancelSelector && target.closest(dragCancelSelector)) {
912
+ return;
913
+ }
914
+ if (handle && !target.closest(handle)) {
915
+ return;
916
+ }
917
+ const touchId = getTrackedInputId(kind, event);
918
+ const startCoords = getInputCoordinates(event, touchId);
919
+ if (!startCoords) {
920
+ return;
921
+ }
922
+ const startPosition = getDragStartPosition(
923
+ startCoords.clientX,
924
+ startCoords.clientY,
925
+ node
926
+ );
927
+ if (!startPosition) {
928
+ return;
929
+ }
930
+ clearDragSession();
931
+ event.preventDefault();
932
+ let lastClientX = startCoords.clientX;
933
+ let lastClientY = startCoords.clientY;
934
+ const handleMove = (moveEvent) => {
935
+ if (!isTrackedInputEvent(kind, event, moveEvent)) {
936
+ return;
937
+ }
938
+ const coords = getInputCoordinates(moveEvent, touchId);
939
+ if (!coords) {
940
+ return;
941
+ }
942
+ preventTouchMoveDefault(kind, moveEvent);
943
+ const deltaX = (coords.clientX - lastClientX) / transformScale;
944
+ const deltaY = (coords.clientY - lastClientY) / transformScale;
945
+ lastClientX = coords.clientX;
946
+ lastClientY = coords.clientY;
947
+ emitDragMove(
948
+ moveEvent,
949
+ node,
950
+ deltaX,
951
+ deltaY,
952
+ coords.clientX,
953
+ coords.clientY
954
+ );
955
+ };
956
+ const handleEnd = (endEvent) => {
957
+ if (!isTrackedInputEvent(kind, event, endEvent)) {
958
+ return;
959
+ }
960
+ clearDragSession();
961
+ emitDragStop(endEvent, node);
962
+ };
963
+ dragSessionRef.current = {
964
+ cleanup: createNativeInteractionSession(
965
+ kind,
966
+ event,
967
+ node,
968
+ handleMove,
969
+ handleEnd
970
+ )
971
+ };
972
+ emitDragStart(
973
+ event,
974
+ node,
975
+ startPosition,
976
+ false,
977
+ startCoords.clientX,
978
+ startCoords.clientY
979
+ );
980
+ },
981
+ [
982
+ isDraggable,
983
+ isStatic,
984
+ dragCancelSelector,
985
+ handle,
986
+ getDragStartPosition,
987
+ clearDragSession,
988
+ transformScale,
989
+ emitDragMove,
990
+ emitDragStop,
991
+ emitDragStart
992
+ ]
993
+ );
994
+ const handleDragPointerDown = React3.useCallback(
995
+ (event) => {
996
+ startDragSession(event, "pointer");
997
+ },
998
+ [startDragSession]
999
+ );
1000
+ const handleDragMouseDown = React3.useCallback(
1001
+ (event) => {
1002
+ startDragSession(event, "mouse");
1003
+ },
1004
+ [startDragSession]
1005
+ );
1006
+ const handleDragTouchStart = React3.useCallback(
1007
+ (event) => {
1008
+ startDragSession(event, "touch");
1009
+ },
1010
+ [startDragSession]
1011
+ );
1012
+ const startResizeSession = React3.useCallback(
1013
+ (handleAxis, nativeEvent, kind) => {
1014
+ if (!isResizable || isStatic || resizeSessionRef.current) {
1015
+ return;
1016
+ }
1017
+ if (!isPrimaryInputStart(kind, nativeEvent)) {
1018
+ return;
1019
+ }
1020
+ const node = elementRef.current;
1021
+ if (!node) {
1022
+ return;
1023
+ }
1024
+ const touchId = getTrackedInputId(kind, nativeEvent);
1025
+ const startCoords = getInputCoordinates(nativeEvent, touchId);
1026
+ if (!startCoords) {
1027
+ return;
1028
+ }
1029
+ clearResizeSession();
1030
+ nativeEvent.preventDefault();
1031
+ setResizing(true);
1032
+ const origin = chunkJ4LTYI7L_js.calcGridItemPosition(positionParams, x, y, w, h);
1033
+ emitResize(
1034
+ "onResizeStart",
1035
+ nativeEvent,
1036
+ { node, size: origin, handle: handleAxis },
1037
+ origin
1038
+ );
1039
+ const startClientX = startCoords.clientX;
1040
+ const startClientY = startCoords.clientY;
1041
+ const handleMove = (moveEvent) => {
1042
+ if (!isTrackedInputEvent(kind, nativeEvent, moveEvent)) {
1043
+ return;
1044
+ }
1045
+ const coords = getInputCoordinates(moveEvent, touchId);
1046
+ if (!coords) {
1047
+ return;
1048
+ }
1049
+ preventTouchMoveDefault(kind, moveEvent);
1050
+ const deltaX = (coords.clientX - startClientX) / transformScale;
1051
+ const deltaY = (coords.clientY - startClientY) / transformScale;
1052
+ const nextCandidate = createResizeCandidate(
1053
+ origin,
1054
+ handleAxis,
1055
+ deltaX,
1056
+ deltaY
1057
+ );
1058
+ emitResize(
1059
+ "onResize",
1060
+ moveEvent,
1061
+ { node, size: nextCandidate, handle: handleAxis },
1062
+ origin
1063
+ );
1064
+ };
1065
+ const handleEnd = (endEvent) => {
1066
+ if (!isTrackedInputEvent(kind, nativeEvent, endEvent)) {
1067
+ return;
1068
+ }
1069
+ const coords = getInputCoordinates(endEvent, touchId) ?? startCoords;
1070
+ const deltaX = (coords.clientX - startClientX) / transformScale;
1071
+ const deltaY = (coords.clientY - startClientY) / transformScale;
1072
+ const nextCandidate = createResizeCandidate(
1073
+ origin,
1074
+ handleAxis,
1075
+ deltaX,
1076
+ deltaY
1077
+ );
1078
+ clearResizeSession();
1079
+ emitResize(
1080
+ "onResizeStop",
1081
+ endEvent,
1082
+ { node, size: nextCandidate, handle: handleAxis },
1083
+ origin
1084
+ );
1085
+ setResizing(false);
1086
+ resizePositionRef.current = { top: 0, left: 0, width: 0, height: 0 };
1087
+ };
1088
+ resizeSessionRef.current = {
1089
+ cleanup: createNativeInteractionSession(
1090
+ kind,
1091
+ nativeEvent,
1092
+ node,
1093
+ handleMove,
1094
+ handleEnd
1095
+ )
1096
+ };
1097
+ },
1098
+ [
1099
+ isResizable,
1100
+ isStatic,
1101
+ clearResizeSession,
1102
+ positionParams,
1103
+ x,
1104
+ y,
1105
+ w,
1106
+ h,
1107
+ emitResize,
1108
+ transformScale
1109
+ ]
1110
+ );
1111
+ const handleResizePointerDown = React3.useCallback(
1112
+ (handleAxis, event) => {
1113
+ event.preventDefault();
1114
+ event.stopPropagation();
1115
+ startResizeSession(handleAxis, event.nativeEvent, "pointer");
1116
+ },
1117
+ [startResizeSession]
1118
+ );
1119
+ const handleResizeMouseDown = React3.useCallback(
1120
+ (handleAxis, event) => {
1121
+ event.preventDefault();
1122
+ event.stopPropagation();
1123
+ startResizeSession(handleAxis, event.nativeEvent, "mouse");
1124
+ },
1125
+ [startResizeSession]
1126
+ );
1127
+ const handleResizeTouchStart = React3.useCallback(
1128
+ (handleAxis, event) => {
1129
+ event.preventDefault();
1130
+ event.stopPropagation();
1131
+ startResizeSession(handleAxis, event.nativeEvent, "touch");
1132
+ },
1133
+ [startResizeSession]
1134
+ );
1135
+ React3.useEffect(() => {
1136
+ if (!supportsDndKitDrag) {
1137
+ console.debug("[GridItem] sortable handle effect: disabled", { i });
1138
+ sortableHandleRef(null);
1139
+ return;
1140
+ }
1141
+ const node = elementRef.current;
1142
+ if (!node) {
1143
+ console.debug("[GridItem] sortable handle effect: no node", { i, handle });
1144
+ return;
1145
+ }
1146
+ const handleElement = handle ? node.querySelector(handle) : null;
1147
+ console.debug("[GridItem] sortable handle effect: applied", {
1148
+ i,
1149
+ handle,
1150
+ node: describeElementForDebug(node),
1151
+ handleElement: describeElementForDebug(handleElement)
1152
+ });
1153
+ sortableHandleRef(handleElement instanceof Element ? handleElement : null);
1154
+ return () => {
1155
+ console.debug("[GridItem] sortable handle effect: cleanup", { i });
1156
+ sortableHandleRef(null);
1157
+ };
1158
+ }, [supportsDndKitDrag, handle, i, sortableHandleRef]);
1159
+ React3.useEffect(() => {
1160
+ if (!supportsDndKitDrag || isDndKitDragSource || resizing) {
1161
+ return;
1162
+ }
1163
+ const node = elementRef.current;
1164
+ if (!node) {
1165
+ console.debug("[GridItem] sortable rebind skipped: no node", {
1166
+ i,
1167
+ x,
1168
+ y,
1169
+ w,
1170
+ h,
1171
+ isDndKitDragSource,
1172
+ resizing
1173
+ });
1174
+ return;
1175
+ }
1176
+ const handleElement = handle ? node.querySelector(handle) : null;
1177
+ console.debug("[GridItem] sortable rebind after geometry/state change", {
1178
+ i,
1179
+ x,
1180
+ y,
1181
+ w,
1182
+ h,
1183
+ node: describeElementForDebug(node),
1184
+ handle,
1185
+ handleElement: describeElementForDebug(handleElement),
1186
+ isSortableDragSource,
1187
+ isDndKitDragSource,
1188
+ resizing
1189
+ });
1190
+ sortableHandleRef(null);
1191
+ sortableRef(null);
1192
+ sortableRef(node);
1193
+ sortableHandleRef(handleElement instanceof Element ? handleElement : null);
1194
+ }, [
1195
+ h,
1196
+ handle,
1197
+ i,
1198
+ isDndKitDragSource,
1199
+ isSortableDragSource,
1200
+ resizing,
1201
+ sortableHandleRef,
1202
+ sortableRef,
1203
+ supportsDndKitDrag,
1204
+ w,
1205
+ x,
1206
+ y
1207
+ ]);
1208
+ React3.useEffect(() => {
1209
+ if (!useNativeDragFallback) {
1210
+ return;
1211
+ }
1212
+ const node = elementRef.current;
1213
+ if (!node) {
1214
+ return;
1215
+ }
1216
+ if (nativePointerEventsAvailable) {
1217
+ node.addEventListener("pointerdown", handleDragPointerDown);
1218
+ } else {
1219
+ node.addEventListener("mousedown", handleDragMouseDown);
1220
+ node.addEventListener("touchstart", handleDragTouchStart, {
1221
+ passive: false
1222
+ });
1223
+ }
1224
+ return () => {
1225
+ if (nativePointerEventsAvailable) {
1226
+ node.removeEventListener("pointerdown", handleDragPointerDown);
1227
+ } else {
1228
+ node.removeEventListener("mousedown", handleDragMouseDown);
1229
+ node.removeEventListener("touchstart", handleDragTouchStart);
1230
+ }
1231
+ };
1232
+ }, [
1233
+ handleDragPointerDown,
1234
+ handleDragMouseDown,
1235
+ handleDragTouchStart,
1236
+ nativePointerEventsAvailable,
1237
+ useNativeDragFallback
1238
+ ]);
1239
+ React3.useEffect(() => {
1240
+ return () => {
1241
+ clearDragSession();
1242
+ clearResizeSession();
1243
+ };
1244
+ }, [clearDragSession, clearResizeSession]);
1245
+ React3.useEffect(() => {
1246
+ if (!droppingPosition) {
1247
+ return;
1248
+ }
1249
+ const node = elementRef.current;
1250
+ if (!node) {
1251
+ return;
1252
+ }
1253
+ const prevDroppingPosition = prevDroppingPositionRef.current ?? {
1254
+ left: 0,
1255
+ top: 0,
1256
+ e: droppingPosition.e
1257
+ };
1258
+ const currentSnapshot = createGridItemDndSnapshot(
1259
+ positionParams,
1260
+ { x, y, w, h },
1261
+ droppingPosition,
1262
+ null
1263
+ );
1264
+ const previousSnapshot = createGridItemDndSnapshot(
1265
+ positionParams,
1266
+ { x, y, w, h },
1267
+ prevDroppingPosition,
1268
+ null
1269
+ );
1270
+ const nextPosition = {
1271
+ left: currentSnapshot.left,
1272
+ top: currentSnapshot.top
1273
+ };
1274
+ if (!dragging) {
1275
+ emitDragStart(droppingPosition.e, node, nextPosition, true);
1276
+ } else if (currentSnapshot.left !== previousSnapshot.left || currentSnapshot.top !== previousSnapshot.top) {
1277
+ const { deltaX, deltaY } = getGridItemPixelDelta(
1278
+ dragPositionRef.current,
1279
+ nextPosition
1280
+ );
1281
+ emitDragMove(droppingPosition.e, node, deltaX, deltaY);
1282
+ }
1283
+ prevDroppingPositionRef.current = droppingPosition;
1284
+ }, [droppingPosition, dragging, emitDragMove, emitDragStart, positionParams, x, y, w, h]);
1285
+ const dndSnapshot = createGridItemDndSnapshot(
1286
+ positionParams,
1287
+ { x, y, w, h },
1288
+ dragging ? dragPositionRef.current : null,
1289
+ resizing ? resizePositionRef.current : null
1290
+ );
1291
+ const pos = {
1292
+ left: dndSnapshot.left,
1293
+ top: dndSnapshot.top,
1294
+ width: dndSnapshot.width,
1295
+ height: dndSnapshot.height
1296
+ };
1297
+ const child = React3__default.default.Children.only(children);
1298
+ const childProps = child.props;
1299
+ const childClassName = childProps["className"];
1300
+ const childStyle = childProps["style"];
1301
+ const childOnPointerDownCapture = childProps["onPointerDownCapture"];
1302
+ const childOnMouseDownCapture = childProps["onMouseDownCapture"];
1303
+ const childOnClickCapture = childProps["onClickCapture"];
1304
+ const showSortableDragSource = supportsDndKitDrag && isSortableDragSource && isDndKitDragSource;
1305
+ const renderResizeHandle = React3.useCallback(
1306
+ (axis) => {
1307
+ return /* @__PURE__ */ jsxRuntime.jsx(
1308
+ GridResizeHandle,
1309
+ {
1310
+ axis,
1311
+ itemId: i,
1312
+ resizeHandle,
1313
+ supportsDndKitResize,
1314
+ onPointerDown: useNativeResizeFallback && nativePointerEventsAvailable ? (event) => handleResizePointerDown(axis, event) : void 0,
1315
+ onMouseDown: useNativeResizeFallback && !nativePointerEventsAvailable ? (event) => handleResizeMouseDown(axis, event) : void 0,
1316
+ onTouchStart: useNativeResizeFallback && !nativePointerEventsAvailable ? (event) => handleResizeTouchStart(axis, event) : void 0
1317
+ },
1318
+ axis
1319
+ );
1320
+ },
1321
+ [
1322
+ handleResizePointerDown,
1323
+ handleResizeMouseDown,
1324
+ handleResizeTouchStart,
1325
+ i,
1326
+ nativePointerEventsAvailable,
1327
+ resizeHandle,
1328
+ supportsDndKitResize,
1329
+ useNativeResizeFallback
1330
+ ]
1331
+ );
1332
+ const nextChildren = React3__default.default.Children.toArray(
1333
+ childProps["children"]
1334
+ );
1335
+ if (isResizable && !isStatic) {
1336
+ nextChildren.push(...resolvedResizeHandles.map(renderResizeHandle));
1337
+ }
1338
+ return React3__default.default.cloneElement(
1339
+ child,
1340
+ {
1341
+ ref: setElementRef,
1342
+ className: clsx__default.default("react-grid-item", childClassName, className, {
1343
+ static: isStatic,
1344
+ resizing,
1345
+ "react-draggable": isDraggable,
1346
+ "react-draggable-dragging": dragging || showSortableDragSource,
1347
+ dropping: Boolean(droppingPosition),
1348
+ cssTransforms: useCSSTransforms,
1349
+ "react-resizable-hide": !isResizable
1350
+ }),
1351
+ onPointerDownCapture: (event) => {
1352
+ const node = elementRef.current;
1353
+ console.debug("[GridItem] pointerdown capture", {
1354
+ i,
1355
+ target: describeElementForDebug(event.target),
1356
+ currentTarget: describeElementForDebug(event.currentTarget),
1357
+ node: describeElementForDebug(node),
1358
+ connected: node?.isConnected ?? false,
1359
+ supportsDndKitDrag,
1360
+ isSortableDragSource,
1361
+ isDndKitDragSource,
1362
+ dragging,
1363
+ resizing,
1364
+ handle,
1365
+ cancel,
1366
+ visibility: node && typeof window !== "undefined" ? window.getComputedStyle(node).visibility : void 0,
1367
+ pointerEvents: node && typeof window !== "undefined" ? window.getComputedStyle(node).pointerEvents : void 0
1368
+ });
1369
+ childOnPointerDownCapture?.(event);
1370
+ },
1371
+ onMouseDownCapture: (event) => {
1372
+ console.debug("[GridItem] mousedown capture", {
1373
+ i,
1374
+ target: describeElementForDebug(event.target),
1375
+ currentTarget: describeElementForDebug(event.currentTarget),
1376
+ supportsDndKitDrag,
1377
+ isSortableDragSource,
1378
+ isDndKitDragSource,
1379
+ dragging,
1380
+ resizing
1381
+ });
1382
+ childOnMouseDownCapture?.(event);
1383
+ },
1384
+ onClickCapture: (event) => {
1385
+ console.debug("[GridItem] click capture", {
1386
+ i,
1387
+ target: describeElementForDebug(event.target),
1388
+ currentTarget: describeElementForDebug(event.currentTarget),
1389
+ supportsDndKitDrag,
1390
+ isSortableDragSource,
1391
+ isDndKitDragSource,
1392
+ dragging,
1393
+ resizing
1394
+ });
1395
+ childOnClickCapture?.(event);
1396
+ },
1397
+ style: {
1398
+ ...style,
1399
+ ...childStyle,
1400
+ ...createStyle(pos),
1401
+ visibility: showSortableDragSource ? "hidden" : childStyle?.visibility,
1402
+ touchAction: isDraggable || isResizable ? "none" : childStyle?.touchAction
1403
+ }
1404
+ },
1405
+ ...nextChildren
1406
+ );
1407
+ }
1408
+ function createGridLayoutInteractionSnapshot(dragState, resizeState, dropState) {
1409
+ const isDragging = dragState.activeDrag !== null;
1410
+ const isResizing = resizeState.resizing;
1411
+ const isDropping = dropState.droppingPosition !== null;
1412
+ return {
1413
+ isDragging,
1414
+ isResizing,
1415
+ isDropping,
1416
+ isInteracting: isDragging || isResizing || isDropping,
1417
+ activeDragId: dragState.activeDrag?.i ?? null
1418
+ };
1419
+ }
1420
+ function useGridLayout(options) {
1421
+ const {
1422
+ layout: propsLayout,
1423
+ cols,
1424
+ preventCollision = false,
1425
+ onLayoutChange,
1426
+ compactor = chunkLQOPWRJR_js.verticalCompactor,
1427
+ droppingItemId = "__dropping-elem__"
1428
+ } = options;
1429
+ const isDraggingRef = React3.useRef(false);
1430
+ const [layout, setLayoutState] = React3.useState(() => {
1431
+ const corrected = chunkJ4LTYI7L_js.correctBounds(chunkJ4LTYI7L_js.cloneLayout(propsLayout), { cols });
1432
+ return compactor.compact(corrected, cols);
1433
+ });
1434
+ const [dragState, setDragState] = React3.useState({
1435
+ activeDrag: null,
1436
+ oldDragItem: null,
1437
+ oldLayout: null
1438
+ });
1439
+ const [resizeState, setResizeState] = React3.useState({
1440
+ resizing: false,
1441
+ oldResizeItem: null,
1442
+ oldLayout: null
1443
+ });
1444
+ const [dropState, setDropState] = React3.useState({
1445
+ droppingDOMNode: null,
1446
+ droppingPosition: null
1447
+ });
1448
+ const prevLayoutRef = React3.useRef(layout);
1449
+ const setLayout = React3.useCallback(
1450
+ (newLayout) => {
1451
+ const corrected = chunkJ4LTYI7L_js.correctBounds(chunkJ4LTYI7L_js.cloneLayout(newLayout), { cols });
1452
+ const compacted = compactor.compact(corrected, cols);
1453
+ setLayoutState(compacted);
1454
+ },
1455
+ [cols, compactor]
1456
+ );
1457
+ React3.useEffect(() => {
1458
+ if (isDraggingRef.current) {
1459
+ return;
1460
+ }
1461
+ if (!fastEquals.deepEqual(propsLayout, prevLayoutRef.current)) {
1462
+ setLayout(propsLayout);
1463
+ }
1464
+ }, [propsLayout, setLayout]);
1465
+ React3.useEffect(() => {
1466
+ if (!fastEquals.deepEqual(layout, prevLayoutRef.current)) {
1467
+ prevLayoutRef.current = layout;
1468
+ if (!layout.some((item) => item.i === droppingItemId)) {
1469
+ onLayoutChange?.(layout);
1470
+ }
1471
+ }
1472
+ }, [layout, onLayoutChange, droppingItemId]);
1473
+ const onDragStart = React3.useCallback(
1474
+ (itemId, x, y) => {
1475
+ const item = chunkJ4LTYI7L_js.getLayoutItem(layout, itemId);
1476
+ if (!item) {
1477
+ return null;
1478
+ }
1479
+ isDraggingRef.current = true;
1480
+ const placeholder = {
1481
+ ...chunkJ4LTYI7L_js.cloneLayoutItem(item),
1482
+ x,
1483
+ y,
1484
+ static: false,
1485
+ moved: false
1486
+ };
1487
+ setDragState({
1488
+ activeDrag: placeholder,
1489
+ oldDragItem: chunkJ4LTYI7L_js.cloneLayoutItem(item),
1490
+ oldLayout: chunkJ4LTYI7L_js.cloneLayout(layout)
1491
+ });
1492
+ return placeholder;
1493
+ },
1494
+ [layout]
1495
+ );
1496
+ const onDrag = React3.useCallback(
1497
+ (itemId, x, y) => {
1498
+ console.debug("[useGridLayout] onDrag received", { itemId, x, y });
1499
+ const item = chunkJ4LTYI7L_js.getLayoutItem(layout, itemId);
1500
+ if (!item) {
1501
+ console.debug("[useGridLayout] onDrag: item not found", itemId);
1502
+ return;
1503
+ }
1504
+ setDragState((prev) => ({
1505
+ ...prev,
1506
+ activeDrag: prev.activeDrag ? { ...prev.activeDrag, x, y } : null
1507
+ }));
1508
+ const newLayout = chunkJ4LTYI7L_js.moveElement(
1509
+ layout,
1510
+ item,
1511
+ x,
1512
+ y,
1513
+ true,
1514
+ preventCollision,
1515
+ compactor.type,
1516
+ cols,
1517
+ compactor.allowOverlap
1518
+ );
1519
+ console.debug("[useGridLayout] onDrag: moveElement computed", { itemId, x, y });
1520
+ const compacted = compactor.compact(newLayout, cols);
1521
+ setLayoutState(compacted);
1522
+ console.debug("[useGridLayout] onDrag: setLayoutState applied", { length: compacted.length });
1523
+ },
1524
+ [layout, cols, compactor, preventCollision]
1525
+ );
1526
+ const onDragStop = React3.useCallback(
1527
+ (itemId, x, y) => {
1528
+ const item = chunkJ4LTYI7L_js.getLayoutItem(layout, itemId);
1529
+ if (!item) {
1530
+ return;
1531
+ }
1532
+ const newLayout = chunkJ4LTYI7L_js.moveElement(
1533
+ layout,
1534
+ item,
1535
+ x,
1536
+ y,
1537
+ true,
1538
+ preventCollision,
1539
+ compactor.type,
1540
+ cols,
1541
+ compactor.allowOverlap
1542
+ );
1543
+ const compacted = compactor.compact(newLayout, cols);
1544
+ isDraggingRef.current = false;
1545
+ setDragState({ activeDrag: null, oldDragItem: null, oldLayout: null });
1546
+ setLayoutState(compacted);
1547
+ },
1548
+ [layout, cols, compactor, preventCollision]
1549
+ );
1550
+ const cancelDrag = React3.useCallback(() => {
1551
+ isDraggingRef.current = false;
1552
+ setDragState((prev) => {
1553
+ if (prev.oldLayout) {
1554
+ const corrected = chunkJ4LTYI7L_js.correctBounds(chunkJ4LTYI7L_js.cloneLayout(prev.oldLayout), { cols });
1555
+ const compacted = compactor.compact(corrected, cols);
1556
+ setLayoutState(compacted);
1557
+ }
1558
+ return { activeDrag: null, oldDragItem: null, oldLayout: null };
1559
+ });
1560
+ }, [cols, compactor]);
1561
+ const onResizeStart = React3.useCallback(
1562
+ (itemId) => {
1563
+ const item = chunkJ4LTYI7L_js.getLayoutItem(layout, itemId);
1564
+ if (!item) {
1565
+ return null;
1566
+ }
1567
+ setResizeState({
1568
+ resizing: true,
1569
+ oldResizeItem: chunkJ4LTYI7L_js.cloneLayoutItem(item),
1570
+ oldLayout: chunkJ4LTYI7L_js.cloneLayout(layout)
1571
+ });
1572
+ return item;
1573
+ },
1574
+ [layout]
1575
+ );
1576
+ const onResize = React3.useCallback(
1577
+ (itemId, w, h, x, y) => {
1578
+ const newLayout = layout.map((item) => {
1579
+ if (item.i !== itemId) {
1580
+ return item;
1581
+ }
1582
+ const updated = {
1583
+ ...item,
1584
+ w,
1585
+ h
1586
+ };
1587
+ if (x !== void 0) {
1588
+ updated.x = x;
1589
+ }
1590
+ if (y !== void 0) {
1591
+ updated.y = y;
1592
+ }
1593
+ return updated;
1594
+ });
1595
+ const corrected = chunkJ4LTYI7L_js.correctBounds(newLayout, { cols });
1596
+ const compacted = compactor.compact(corrected, cols);
1597
+ const activeResizeItem = chunkJ4LTYI7L_js.getLayoutItem(compacted, itemId);
1598
+ setLayoutState(compacted);
1599
+ setDragState((prev) => ({
1600
+ ...prev,
1601
+ activeDrag: activeResizeItem ? chunkJ4LTYI7L_js.cloneLayoutItem(activeResizeItem) : prev.activeDrag
1602
+ }));
1603
+ },
1604
+ [layout, cols, compactor]
1605
+ );
1606
+ const onResizeStop = React3.useCallback(
1607
+ (itemId, w, h, x, y) => {
1608
+ onResize(itemId, w, h, x, y);
1609
+ setResizeState({
1610
+ resizing: false,
1611
+ oldResizeItem: null,
1612
+ oldLayout: null
1613
+ });
1614
+ setDragState({ activeDrag: null, oldDragItem: null, oldLayout: null });
1615
+ },
1616
+ [onResize]
1617
+ );
1618
+ const cancelResize = React3.useCallback(() => {
1619
+ setResizeState((prev) => {
1620
+ if (prev.oldLayout) {
1621
+ const corrected = chunkJ4LTYI7L_js.correctBounds(chunkJ4LTYI7L_js.cloneLayout(prev.oldLayout), { cols });
1622
+ const compacted = compactor.compact(corrected, cols);
1623
+ setLayoutState(compacted);
1624
+ }
1625
+ return {
1626
+ resizing: false,
1627
+ oldResizeItem: null,
1628
+ oldLayout: null
1629
+ };
1630
+ });
1631
+ setDragState({ activeDrag: null, oldDragItem: null, oldLayout: null });
1632
+ }, [cols, compactor]);
1633
+ const onDropDragOver = React3.useCallback(
1634
+ (droppingItem, position) => {
1635
+ const existingItem = chunkJ4LTYI7L_js.getLayoutItem(layout, droppingItem.i);
1636
+ isDraggingRef.current = true;
1637
+ if (!existingItem) {
1638
+ const newLayout = [...layout, droppingItem];
1639
+ const corrected = chunkJ4LTYI7L_js.correctBounds(newLayout, { cols });
1640
+ setLayoutState(corrected);
1641
+ }
1642
+ setDropState({
1643
+ droppingDOMNode: null,
1644
+ droppingPosition: position
1645
+ });
1646
+ },
1647
+ [layout, cols]
1648
+ );
1649
+ const onDropDragLeave = React3.useCallback(() => {
1650
+ const newLayout = layout.filter((item) => item.i !== droppingItemId);
1651
+ setLayout(newLayout);
1652
+ isDraggingRef.current = false;
1653
+ setDragState({ activeDrag: null, oldDragItem: null, oldLayout: null });
1654
+ setResizeState((prev) => ({
1655
+ ...prev,
1656
+ resizing: false
1657
+ }));
1658
+ setDropState({
1659
+ droppingDOMNode: null,
1660
+ droppingPosition: null
1661
+ });
1662
+ }, [layout, droppingItemId, setLayout]);
1663
+ const onDrop = React3.useCallback(
1664
+ (droppingItem) => {
1665
+ const newLayout = layout.map((item) => {
1666
+ if (item.i !== droppingItemId) {
1667
+ return item;
1668
+ }
1669
+ return {
1670
+ ...item,
1671
+ i: droppingItem.i,
1672
+ static: false
1673
+ };
1674
+ });
1675
+ const corrected = chunkJ4LTYI7L_js.correctBounds(newLayout, { cols });
1676
+ const compacted = compactor.compact(corrected, cols);
1677
+ setLayoutState(compacted);
1678
+ isDraggingRef.current = false;
1679
+ setDragState({ activeDrag: null, oldDragItem: null, oldLayout: null });
1680
+ setDropState({
1681
+ droppingDOMNode: null,
1682
+ droppingPosition: null
1683
+ });
1684
+ },
1685
+ [layout, droppingItemId, cols, compactor]
1686
+ );
1687
+ const containerHeight = React3.useMemo(() => chunkJ4LTYI7L_js.bottom(layout), [layout]);
1688
+ const interactionSnapshot = React3.useMemo(
1689
+ () => createGridLayoutInteractionSnapshot(dragState, resizeState, dropState),
1690
+ [dragState, resizeState, dropState]
1691
+ );
1692
+ return {
1693
+ layout,
1694
+ setLayout,
1695
+ dragState,
1696
+ resizeState,
1697
+ dropState,
1698
+ onDragStart,
1699
+ onDrag,
1700
+ onDragStop,
1701
+ cancelDrag,
1702
+ onResizeStart,
1703
+ onResize,
1704
+ onResizeStop,
1705
+ cancelResize,
1706
+ onDropDragOver,
1707
+ onDropDragLeave,
1708
+ onDrop,
1709
+ containerHeight,
1710
+ isInteracting: interactionSnapshot.isInteracting,
1711
+ compactor
1712
+ };
1713
+ }
1714
+ var noop = () => {
1715
+ };
1716
+ var layoutClassName = "react-grid-layout";
1717
+ var isFirefox = false;
1718
+ try {
1719
+ isFirefox = /firefox/i.test(navigator.userAgent);
1720
+ } catch {
1721
+ }
1722
+ function childrenEqual(a, b) {
1723
+ const aArr = React3__default.default.Children.toArray(a);
1724
+ const bArr = React3__default.default.Children.toArray(b);
1725
+ if (aArr.length !== bArr.length) {
1726
+ return false;
1727
+ }
1728
+ for (let i = 0; i < aArr.length; i++) {
1729
+ const aChild = aArr[i];
1730
+ const bChild = bArr[i];
1731
+ if (aChild?.key !== bChild?.key) {
1732
+ return false;
1733
+ }
1734
+ }
1735
+ return true;
1736
+ }
1737
+ function synchronizeLayoutWithChildren(initialLayout, children, cols, compactor) {
1738
+ const layout = [];
1739
+ const childKeys = /* @__PURE__ */ new Set();
1740
+ React3__default.default.Children.forEach(children, (child) => {
1741
+ if (!React3__default.default.isValidElement(child) || child.key === null) {
1742
+ return;
1743
+ }
1744
+ const key = String(child.key);
1745
+ childKeys.add(key);
1746
+ const existingItem = initialLayout.find((l) => l.i === key);
1747
+ if (existingItem) {
1748
+ layout.push(chunkJ4LTYI7L_js.cloneLayoutItem(existingItem));
1749
+ return;
1750
+ }
1751
+ const childProps = child.props;
1752
+ const dataGrid = childProps["data-grid"];
1753
+ if (dataGrid) {
1754
+ layout.push({
1755
+ i: key,
1756
+ x: dataGrid.x ?? 0,
1757
+ y: dataGrid.y ?? 0,
1758
+ w: dataGrid.w ?? 1,
1759
+ h: dataGrid.h ?? 1,
1760
+ minW: dataGrid.minW,
1761
+ maxW: dataGrid.maxW,
1762
+ minH: dataGrid.minH,
1763
+ maxH: dataGrid.maxH,
1764
+ static: dataGrid.static,
1765
+ isDraggable: dataGrid.isDraggable,
1766
+ isResizable: dataGrid.isResizable,
1767
+ resizeHandles: dataGrid.resizeHandles,
1768
+ isBounded: dataGrid.isBounded
1769
+ });
1770
+ return;
1771
+ }
1772
+ layout.push({
1773
+ i: key,
1774
+ x: 0,
1775
+ y: chunkJ4LTYI7L_js.bottom(layout),
1776
+ w: 1,
1777
+ h: 1
1778
+ });
1779
+ });
1780
+ const corrected = chunkJ4LTYI7L_js.correctBounds(layout, { cols });
1781
+ return compactor.compact(corrected, cols);
1782
+ }
1783
+ function createGridDropPlaceholder(config) {
1784
+ return config.override ?? {
1785
+ i: "__dropping-elem__",
1786
+ x: 0,
1787
+ y: 0,
1788
+ ...config.defaultItem
1789
+ };
1790
+ }
1791
+ function createGridInteractionState(activeDrag, resizing, droppingPosition) {
1792
+ return {
1793
+ isInteracting: activeDrag !== null || resizing || droppingPosition !== void 0,
1794
+ activeDrag,
1795
+ resizing,
1796
+ droppingPosition
1797
+ };
1798
+ }
1799
+ function getGridItemDragData(value) {
1800
+ if (!value || typeof value !== "object") {
1801
+ return null;
1802
+ }
1803
+ const kind = value.kind;
1804
+ const itemId = value.itemId;
1805
+ return kind === "drag" && typeof itemId === "string" ? { kind: "drag", itemId } : null;
1806
+ }
1807
+ function GridLayout(props) {
1808
+ const {
1809
+ children,
1810
+ width,
1811
+ gridConfig: gridConfigProp,
1812
+ dragConfig: dragConfigProp,
1813
+ resizeConfig: resizeConfigProp,
1814
+ dropConfig: dropConfigProp,
1815
+ positionStrategy = chunkLQOPWRJR_js.defaultPositionStrategy,
1816
+ compactor: compactorProp,
1817
+ constraints = chunkLQOPWRJR_js.defaultConstraints,
1818
+ layout: propsLayout = [],
1819
+ droppingItem: droppingItemProp,
1820
+ autoSize = true,
1821
+ className = "",
1822
+ style = {},
1823
+ innerRef,
1824
+ onLayoutChange = noop,
1825
+ onDragStart: onDragStartProp = noop,
1826
+ onDrag: onDragProp = noop,
1827
+ onDragStop: onDragStopProp = noop,
1828
+ onResizeStart: onResizeStartProp = noop,
1829
+ onResize: onResizeProp = noop,
1830
+ onResizeStop: onResizeStopProp = noop,
1831
+ onDrop: onDropProp = noop,
1832
+ onDropDragOver: onDropDragOverProp = noop
1833
+ } = props;
1834
+ const gridConfig = React3.useMemo(
1835
+ () => ({ ...chunkLQOPWRJR_js.defaultGridConfig, ...gridConfigProp }),
1836
+ [gridConfigProp]
1837
+ );
1838
+ const dragConfig = React3.useMemo(
1839
+ () => ({ ...chunkLQOPWRJR_js.defaultDragConfig, ...dragConfigProp }),
1840
+ [dragConfigProp]
1841
+ );
1842
+ const resizeConfig = React3.useMemo(
1843
+ () => ({ ...chunkLQOPWRJR_js.defaultResizeConfig, ...resizeConfigProp }),
1844
+ [resizeConfigProp]
1845
+ );
1846
+ const dropConfig = React3.useMemo(
1847
+ () => ({ ...chunkLQOPWRJR_js.defaultDropConfig, ...dropConfigProp }),
1848
+ [dropConfigProp]
1849
+ );
1850
+ const { cols, rowHeight, maxRows, margin, containerPadding } = gridConfig;
1851
+ const {
1852
+ enabled: isDraggable,
1853
+ bounded: isBounded,
1854
+ handle: draggableHandle,
1855
+ cancel: draggableCancel,
1856
+ threshold: dragThreshold
1857
+ } = dragConfig;
1858
+ const {
1859
+ enabled: isResizable,
1860
+ handles: resizeHandles,
1861
+ handleComponent: resizeHandle
1862
+ } = resizeConfig;
1863
+ const {
1864
+ enabled: isDroppable,
1865
+ defaultItem: defaultDropItem,
1866
+ onDragOver: dropConfigOnDragOver
1867
+ } = dropConfig;
1868
+ const compactor = compactorProp ?? chunkLQOPWRJR_js.getCompactor("vertical");
1869
+ const compactType = compactor.type;
1870
+ const allowOverlap = compactor.allowOverlap;
1871
+ const preventCollision = compactor.preventCollision ?? false;
1872
+ const droppingItem = React3.useMemo(
1873
+ () => createGridDropPlaceholder({
1874
+ defaultItem: defaultDropItem,
1875
+ override: droppingItemProp
1876
+ }),
1877
+ [droppingItemProp, defaultDropItem]
1878
+ );
1879
+ const useCSSTransforms = positionStrategy.type === "transform";
1880
+ const transformScale = positionStrategy.scale;
1881
+ const effectiveContainerPadding = containerPadding ?? margin;
1882
+ const positionParams = React3.useMemo(
1883
+ () => ({
1884
+ cols,
1885
+ margin,
1886
+ maxRows,
1887
+ rowHeight,
1888
+ containerWidth: width,
1889
+ containerPadding: effectiveContainerPadding
1890
+ }),
1891
+ [cols, margin, maxRows, rowHeight, width, effectiveContainerPadding]
1892
+ );
1893
+ const { stepX, stepY } = React3.useMemo(
1894
+ () => chunkJ4LTYI7L_js.getGridPixelSteps(positionParams),
1895
+ [positionParams]
1896
+ );
1897
+ const synchronizedLayout = React3.useMemo(
1898
+ () => synchronizeLayoutWithChildren(propsLayout, children, cols, compactor),
1899
+ [propsLayout, children, cols, compactor]
1900
+ );
1901
+ const [mounted, setMounted] = React3.useState(false);
1902
+ const [droppingDOMNode, setDroppingDOMNode] = React3.useState(
1903
+ null
1904
+ );
1905
+ const [dragOverlayId, setDragOverlayId] = React3.useState(null);
1906
+ const containerRef = React3.useRef(null);
1907
+ const activeDndDragRef = React3.useRef(null);
1908
+ const setContainerNode = React3.useCallback(
1909
+ (node) => {
1910
+ containerRef.current = node;
1911
+ if (typeof innerRef === "function") {
1912
+ innerRef(node);
1913
+ return;
1914
+ }
1915
+ if (innerRef && "current" in innerRef) {
1916
+ innerRef.current = node;
1917
+ }
1918
+ },
1919
+ [innerRef]
1920
+ );
1921
+ const dndSensors = React3.useMemo(
1922
+ () => [
1923
+ PointerSensor.configure({
1924
+ activationConstraints: [
1925
+ new PointerActivationConstraints.Distance({
1926
+ value: Math.max(3, dragThreshold)
1927
+ })
1928
+ ],
1929
+ preventActivation: (event, source) => {
1930
+ const sourceData = source?.data;
1931
+ if (sourceData?.kind === "resize") return false;
1932
+ const target = event.target instanceof HTMLElement ? event.target : null;
1933
+ return Boolean(
1934
+ target && target.closest(
1935
+ [".react-resizable-handle", draggableCancel].filter(Boolean).join(",")
1936
+ )
1937
+ );
1938
+ }
1939
+ }),
1940
+ KeyboardSensor.configure({
1941
+ offset: {
1942
+ x: stepX,
1943
+ y: stepY
1944
+ }
1945
+ })
1946
+ ],
1947
+ [dragThreshold, draggableCancel, stepX, stepY]
1948
+ );
1949
+ const {
1950
+ layout,
1951
+ setLayout,
1952
+ dragState,
1953
+ resizeState,
1954
+ dropState,
1955
+ onDragStart: beginDragState,
1956
+ onDrag: updateDragState,
1957
+ onDragStop: stopDragState,
1958
+ cancelDrag: cancelDragState,
1959
+ onResizeStart: beginResizeState,
1960
+ onResize: updateResizeState,
1961
+ onResizeStop: stopResizeState,
1962
+ cancelResize: cancelResizeState,
1963
+ onDropDragOver: updateDropPlaceholder,
1964
+ onDropDragLeave: clearDropPlaceholder
1965
+ } = useGridLayout({
1966
+ layout: synchronizedLayout,
1967
+ cols,
1968
+ preventCollision,
1969
+ compactor,
1970
+ droppingItemId: droppingItem.i
1971
+ });
1972
+ const activeDrag = dragState.activeDrag;
1973
+ const resizing = resizeState.resizing;
1974
+ const droppingPosition = dropState.droppingPosition ?? void 0;
1975
+ const interactionState = React3.useMemo(
1976
+ () => createGridInteractionState(activeDrag, resizing, droppingPosition),
1977
+ [activeDrag, resizing, droppingPosition]
1978
+ );
1979
+ const oldDragItemRef = React3.useRef(null);
1980
+ const oldResizeItemRef = React3.useRef(null);
1981
+ const oldLayoutRef = React3.useRef(null);
1982
+ const dragEnterCounterRef = React3.useRef(0);
1983
+ const prevLayoutRef = React3.useRef(layout);
1984
+ const prevPropsLayoutRef = React3.useRef(propsLayout);
1985
+ const prevChildrenRef = React3.useRef(children);
1986
+ const prevCompactTypeRef = React3.useRef(compactType);
1987
+ const layoutRef = React3.useRef(layout);
1988
+ layoutRef.current = layout;
1989
+ const childMap = React3.useMemo(() => {
1990
+ const next = /* @__PURE__ */ new Map();
1991
+ React3__default.default.Children.forEach(children, (child) => {
1992
+ if (!React3__default.default.isValidElement(child) || child.key === null) {
1993
+ return;
1994
+ }
1995
+ next.set(String(child.key), child);
1996
+ });
1997
+ return next;
1998
+ }, [children]);
1999
+ const createConstraintContext = React3.useCallback(
2000
+ (currentLayout) => ({
2001
+ cols,
2002
+ maxRows,
2003
+ containerWidth: width,
2004
+ containerHeight: containerRef.current?.clientHeight ?? 0,
2005
+ rowHeight,
2006
+ margin,
2007
+ layout: currentLayout
2008
+ }),
2009
+ [cols, maxRows, width, rowHeight, margin]
2010
+ );
2011
+ const getDragEventNativeEvent = React3.useCallback(
2012
+ (event) => event.nativeEvent ?? event.operation.activatorEvent ?? new Event("drag"),
2013
+ []
2014
+ );
2015
+ const getDragSourceElement = React3.useCallback(
2016
+ (source) => {
2017
+ const element = source?.element;
2018
+ return element instanceof HTMLElement ? element : null;
2019
+ },
2020
+ []
2021
+ );
2022
+ const getDraggedGridPosition = React3.useCallback(
2023
+ (session, currentItem, transform) => {
2024
+ const newPosition = {
2025
+ left: session.origin.left + transform.x / transformScale,
2026
+ top: session.origin.top + transform.y / transformScale
2027
+ };
2028
+ const rawPosition = chunkJ4LTYI7L_js.calcXYRaw(
2029
+ positionParams,
2030
+ newPosition.top,
2031
+ newPosition.left
2032
+ );
2033
+ const constrained = chunkLQOPWRJR_js.applyPositionConstraints(
2034
+ constraints,
2035
+ currentItem,
2036
+ rawPosition.x,
2037
+ rawPosition.y,
2038
+ createConstraintContext(layoutRef.current)
2039
+ );
2040
+ return {
2041
+ x: constrained.x,
2042
+ y: constrained.y,
2043
+ newPosition
2044
+ };
2045
+ },
2046
+ [constraints, createConstraintContext, positionParams, transformScale]
2047
+ );
2048
+ React3.useEffect(() => {
2049
+ setMounted(true);
2050
+ if (!fastEquals.deepEqual(layout, propsLayout)) {
2051
+ onLayoutChange(layout);
2052
+ }
2053
+ }, []);
2054
+ React3.useEffect(() => {
2055
+ if (activeDrag || droppingDOMNode) {
2056
+ return;
2057
+ }
2058
+ const layoutChanged = !fastEquals.deepEqual(propsLayout, prevPropsLayoutRef.current);
2059
+ const childrenChanged = !childrenEqual(children, prevChildrenRef.current);
2060
+ const compactTypeChanged = compactType !== prevCompactTypeRef.current;
2061
+ if (layoutChanged || childrenChanged || compactTypeChanged) {
2062
+ const baseLayout = layoutChanged ? propsLayout : layoutRef.current;
2063
+ const nextLayout = synchronizeLayoutWithChildren(
2064
+ baseLayout,
2065
+ children,
2066
+ cols,
2067
+ compactor
2068
+ );
2069
+ if (!fastEquals.deepEqual(nextLayout, layoutRef.current)) {
2070
+ setLayout(nextLayout);
2071
+ }
2072
+ }
2073
+ prevPropsLayoutRef.current = propsLayout;
2074
+ prevChildrenRef.current = children;
2075
+ prevCompactTypeRef.current = compactType;
2076
+ }, [
2077
+ propsLayout,
2078
+ children,
2079
+ cols,
2080
+ compactType,
2081
+ compactor,
2082
+ activeDrag,
2083
+ droppingDOMNode
2084
+ // 'layout' intentionally omitted: we access it via layoutRef.current to avoid
2085
+ // re-running on every drag-move. 'setLayout' omitted because it only changes
2086
+ // when cols/compactor change, which are already in the deps.
2087
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2088
+ ]);
2089
+ React3.useEffect(() => {
2090
+ if (!activeDrag && !fastEquals.deepEqual(layout, prevLayoutRef.current)) {
2091
+ prevLayoutRef.current = layout;
2092
+ const publicLayout = layout.filter((l) => l.i !== droppingItem.i);
2093
+ onLayoutChange(publicLayout);
2094
+ }
2095
+ }, [layout, activeDrag, onLayoutChange, droppingItem.i]);
2096
+ const containerHeight = React3.useMemo(() => {
2097
+ if (!autoSize) {
2098
+ return void 0;
2099
+ }
2100
+ const nbRow = chunkJ4LTYI7L_js.bottom(layout);
2101
+ const containerPaddingY = effectiveContainerPadding[1];
2102
+ return nbRow * rowHeight + (nbRow - 1) * margin[1] + containerPaddingY * 2 + "px";
2103
+ }, [autoSize, layout, rowHeight, margin, effectiveContainerPadding]);
2104
+ const onDragStart = React3.useCallback(
2105
+ (i, x, y, data) => {
2106
+ const currentLayout = layoutRef.current;
2107
+ const item = chunkJ4LTYI7L_js.getLayoutItem(currentLayout, i);
2108
+ if (!item) {
2109
+ return;
2110
+ }
2111
+ oldDragItemRef.current = chunkJ4LTYI7L_js.cloneLayoutItem(item);
2112
+ oldLayoutRef.current = currentLayout;
2113
+ beginDragState(i, x, y);
2114
+ onDragStartProp(currentLayout, item, item, null, data.e, data.node);
2115
+ },
2116
+ [beginDragState, onDragStartProp]
2117
+ );
2118
+ const onDrag = React3.useCallback(
2119
+ (i, x, y, data) => {
2120
+ const currentLayout = layoutRef.current;
2121
+ const oldDragItem = oldDragItemRef.current;
2122
+ const item = chunkJ4LTYI7L_js.getLayoutItem(currentLayout, i);
2123
+ if (!item) {
2124
+ return;
2125
+ }
2126
+ const placeholder = {
2127
+ w: item.w,
2128
+ h: item.h,
2129
+ x: item.x,
2130
+ y: item.y,
2131
+ i
2132
+ };
2133
+ const newLayout = chunkJ4LTYI7L_js.moveElement(
2134
+ currentLayout,
2135
+ item,
2136
+ x,
2137
+ y,
2138
+ true,
2139
+ preventCollision,
2140
+ compactType,
2141
+ cols,
2142
+ allowOverlap
2143
+ );
2144
+ onDragProp(newLayout, oldDragItem, item, placeholder, data.e, data.node);
2145
+ updateDragState(i, x, y);
2146
+ },
2147
+ [
2148
+ preventCollision,
2149
+ compactType,
2150
+ cols,
2151
+ allowOverlap,
2152
+ onDragProp,
2153
+ updateDragState
2154
+ ]
2155
+ );
2156
+ const onDragStop = React3.useCallback(
2157
+ (i, x, y, data) => {
2158
+ const currentLayout = layoutRef.current;
2159
+ const oldDragItem = oldDragItemRef.current;
2160
+ const item = chunkJ4LTYI7L_js.getLayoutItem(currentLayout, i);
2161
+ if (!item) {
2162
+ return;
2163
+ }
2164
+ const newLayout = chunkJ4LTYI7L_js.moveElement(
2165
+ currentLayout,
2166
+ item,
2167
+ x,
2168
+ y,
2169
+ true,
2170
+ preventCollision,
2171
+ compactType,
2172
+ cols,
2173
+ allowOverlap
2174
+ );
2175
+ const finalLayout = compactor.compact(newLayout, cols);
2176
+ onDragStopProp(finalLayout, oldDragItem, item, null, data.e, data.node);
2177
+ oldDragItemRef.current = null;
2178
+ oldLayoutRef.current = null;
2179
+ stopDragState(i, x, y);
2180
+ },
2181
+ [
2182
+ preventCollision,
2183
+ compactType,
2184
+ cols,
2185
+ allowOverlap,
2186
+ compactor,
2187
+ onDragStopProp,
2188
+ stopDragState
2189
+ ]
2190
+ );
2191
+ const handleDndKitDragStart = React3.useCallback(
2192
+ (event) => {
2193
+ console.debug("[GridLayout] handleDndKitDragStart", {
2194
+ sourceData: event.operation.source?.data,
2195
+ activatorEvent: event.operation.activatorEvent,
2196
+ nativeEvent: event.nativeEvent
2197
+ });
2198
+ const dragData = getGridItemDragData(event.operation.source?.data);
2199
+ if (!dragData) {
2200
+ console.debug("[GridLayout] handleDndKitDragStart: no dragData");
2201
+ return;
2202
+ }
2203
+ const currentLayout = layoutRef.current;
2204
+ const item = chunkJ4LTYI7L_js.getLayoutItem(currentLayout, dragData.itemId);
2205
+ if (!item) {
2206
+ console.debug("[GridLayout] handleDndKitDragStart: item not found", dragData);
2207
+ return;
2208
+ }
2209
+ const originPosition = chunkJ4LTYI7L_js.calcGridItemPosition(
2210
+ positionParams,
2211
+ item.x,
2212
+ item.y,
2213
+ item.w,
2214
+ item.h
2215
+ );
2216
+ const node = getDragSourceElement(event.operation.source);
2217
+ const activatorEvent = event.operation.activatorEvent;
2218
+ const initialPointer = activatorEvent ? { x: activatorEvent.clientX ?? 0, y: activatorEvent.clientY ?? 0 } : { x: 0, y: 0 };
2219
+ activeDndDragRef.current = {
2220
+ itemId: item.i,
2221
+ node,
2222
+ initialPointer,
2223
+ origin: {
2224
+ left: originPosition.left,
2225
+ top: originPosition.top,
2226
+ x: item.x,
2227
+ y: item.y,
2228
+ w: item.w,
2229
+ h: item.h
2230
+ }
2231
+ };
2232
+ console.debug("[GridLayout] activeDndDragRef set", activeDndDragRef.current);
2233
+ setDragOverlayId(item.i);
2234
+ console.debug("[GridLayout] invoking onDragStart callback", item.i, item.x, item.y);
2235
+ onDragStart(item.i, item.x, item.y, {
2236
+ e: getDragEventNativeEvent(event),
2237
+ node: node ?? containerRef.current ?? document.body,
2238
+ newPosition: {
2239
+ left: originPosition.left,
2240
+ top: originPosition.top
2241
+ }
2242
+ });
2243
+ },
2244
+ [getDragEventNativeEvent, getDragSourceElement, onDragStart, positionParams]
2245
+ );
2246
+ const handleDndKitDragMove = React3.useCallback(
2247
+ (event) => {
2248
+ console.debug("[GridLayout] handleDndKitDragMove", {
2249
+ transform: event.operation.transform,
2250
+ to: event.to,
2251
+ sourceData: event.operation.source?.data
2252
+ });
2253
+ const session = activeDndDragRef.current;
2254
+ const dragData = getGridItemDragData(event.operation.source?.data);
2255
+ if (!session || !dragData || session.itemId !== dragData.itemId) {
2256
+ console.debug("[GridLayout] handleDndKitDragMove: session mismatch", { session, dragData });
2257
+ return;
2258
+ }
2259
+ const currentLayout = layoutRef.current;
2260
+ const item = chunkJ4LTYI7L_js.getLayoutItem(currentLayout, session.itemId);
2261
+ if (!item) {
2262
+ console.debug("[GridLayout] handleDndKitDragMove: item not found", session.itemId);
2263
+ return;
2264
+ }
2265
+ const transform = event.to ? {
2266
+ x: event.to.x - session.initialPointer.x,
2267
+ y: event.to.y - session.initialPointer.y
2268
+ } : event.operation.transform;
2269
+ const { x, y, newPosition } = getDraggedGridPosition(
2270
+ session,
2271
+ item,
2272
+ transform
2273
+ );
2274
+ const node = getDragSourceElement(event.operation.source) ?? session.node;
2275
+ console.debug("[GridLayout] invoking onDrag", session.itemId, { x, y, newPosition });
2276
+ onDrag(session.itemId, x, y, {
2277
+ e: getDragEventNativeEvent(event),
2278
+ node: node ?? containerRef.current ?? document.body,
2279
+ newPosition
2280
+ });
2281
+ },
2282
+ [getDragEventNativeEvent, getDragSourceElement, getDraggedGridPosition, onDrag]
2283
+ );
2284
+ const handleDndKitDragEnd = React3.useCallback(
2285
+ (event) => {
2286
+ console.debug("[GridLayout] handleDndKitDragEnd", {
2287
+ canceled: event.canceled,
2288
+ transform: event.operation.transform,
2289
+ sourceData: event.operation.source?.data
2290
+ });
2291
+ const session = activeDndDragRef.current;
2292
+ const dragData = getGridItemDragData(event.operation.source?.data);
2293
+ activeDndDragRef.current = null;
2294
+ setDragOverlayId(null);
2295
+ if (!session || !dragData || session.itemId !== dragData.itemId) {
2296
+ console.debug("[GridLayout] handleDndKitDragEnd: session or dragData mismatch", { session, dragData });
2297
+ return;
2298
+ }
2299
+ if (event.canceled) {
2300
+ console.debug("[GridLayout] drag canceled for", session.itemId);
2301
+ oldDragItemRef.current = null;
2302
+ oldLayoutRef.current = null;
2303
+ cancelDragState();
2304
+ return;
2305
+ }
2306
+ const currentLayout = layoutRef.current;
2307
+ const item = chunkJ4LTYI7L_js.getLayoutItem(currentLayout, session.itemId);
2308
+ if (!item) {
2309
+ console.debug("[GridLayout] handleDndKitDragEnd: item not found", session.itemId);
2310
+ cancelDragState();
2311
+ return;
2312
+ }
2313
+ const nativePointerEnd = event.nativeEvent instanceof PointerEvent ? event.nativeEvent : null;
2314
+ const endTransform = nativePointerEnd ? {
2315
+ x: nativePointerEnd.clientX - session.initialPointer.x,
2316
+ y: nativePointerEnd.clientY - session.initialPointer.y
2317
+ } : event.operation.transform;
2318
+ const { x, y, newPosition } = getDraggedGridPosition(
2319
+ session,
2320
+ item,
2321
+ endTransform
2322
+ );
2323
+ const node = getDragSourceElement(event.operation.source) ?? session.node;
2324
+ console.debug("[GridLayout] invoking onDragStop", session.itemId, { x, y, newPosition });
2325
+ onDragStop(session.itemId, x, y, {
2326
+ e: getDragEventNativeEvent(event),
2327
+ node: node ?? containerRef.current ?? document.body,
2328
+ newPosition
2329
+ });
2330
+ },
2331
+ [
2332
+ cancelDragState,
2333
+ getDragEventNativeEvent,
2334
+ getDragSourceElement,
2335
+ getDraggedGridPosition,
2336
+ onDragStop
2337
+ ]
2338
+ );
2339
+ const onResizeStart = React3.useCallback(
2340
+ (i, _w, _h, data) => {
2341
+ const currentLayout = layoutRef.current;
2342
+ const item = chunkJ4LTYI7L_js.getLayoutItem(currentLayout, i);
2343
+ if (!item) {
2344
+ return;
2345
+ }
2346
+ oldResizeItemRef.current = chunkJ4LTYI7L_js.cloneLayoutItem(item);
2347
+ oldLayoutRef.current = currentLayout;
2348
+ beginResizeState(i);
2349
+ onResizeStartProp(currentLayout, item, item, null, data.e, data.node);
2350
+ },
2351
+ [beginResizeState, onResizeStartProp]
2352
+ );
2353
+ const onResize = React3.useCallback(
2354
+ (i, w, h, data) => {
2355
+ const currentLayout = layoutRef.current;
2356
+ const oldResizeItem = oldResizeItemRef.current;
2357
+ const { handle } = data;
2358
+ let shouldMoveItem = false;
2359
+ let newX;
2360
+ let newY;
2361
+ const [newLayout, item] = chunkJ4LTYI7L_js.withLayoutItem(currentLayout, i, (layoutItem) => {
2362
+ newX = layoutItem.x;
2363
+ newY = layoutItem.y;
2364
+ if (["sw", "w", "nw", "n", "ne"].includes(handle)) {
2365
+ if (["sw", "nw", "w"].includes(handle)) {
2366
+ newX = layoutItem.x + (layoutItem.w - w);
2367
+ w = layoutItem.x !== newX && newX < 0 ? layoutItem.w : w;
2368
+ newX = newX < 0 ? 0 : newX;
2369
+ }
2370
+ if (["ne", "n", "nw"].includes(handle)) {
2371
+ newY = layoutItem.y + (layoutItem.h - h);
2372
+ h = layoutItem.y !== newY && newY < 0 ? layoutItem.h : h;
2373
+ newY = newY < 0 ? 0 : newY;
2374
+ }
2375
+ shouldMoveItem = true;
2376
+ }
2377
+ if (preventCollision && !allowOverlap) {
2378
+ const collisions = chunkJ4LTYI7L_js.getAllCollisions(currentLayout, {
2379
+ ...layoutItem,
2380
+ w,
2381
+ h,
2382
+ x: newX ?? layoutItem.x,
2383
+ y: newY ?? layoutItem.y
2384
+ }).filter((layoutEntry) => layoutEntry.i !== layoutItem.i);
2385
+ if (collisions.length > 0) {
2386
+ newY = layoutItem.y;
2387
+ h = layoutItem.h;
2388
+ newX = layoutItem.x;
2389
+ w = layoutItem.w;
2390
+ shouldMoveItem = false;
2391
+ }
2392
+ }
2393
+ layoutItem.w = w;
2394
+ layoutItem.h = h;
2395
+ return layoutItem;
2396
+ });
2397
+ if (!item) {
2398
+ return;
2399
+ }
2400
+ let finalLayout = newLayout;
2401
+ if (shouldMoveItem && newX !== void 0 && newY !== void 0) {
2402
+ finalLayout = chunkJ4LTYI7L_js.moveElement(
2403
+ newLayout,
2404
+ item,
2405
+ newX,
2406
+ newY,
2407
+ true,
2408
+ preventCollision,
2409
+ compactType,
2410
+ cols,
2411
+ allowOverlap
2412
+ );
2413
+ }
2414
+ const placeholder = {
2415
+ w: item.w,
2416
+ h: item.h,
2417
+ x: item.x,
2418
+ y: item.y,
2419
+ i,
2420
+ static: true
2421
+ };
2422
+ onResizeProp(
2423
+ finalLayout,
2424
+ oldResizeItem,
2425
+ item,
2426
+ placeholder,
2427
+ data.e,
2428
+ data.node
2429
+ );
2430
+ updateResizeState(i, w, h, newX, newY);
2431
+ },
2432
+ [
2433
+ preventCollision,
2434
+ allowOverlap,
2435
+ compactType,
2436
+ cols,
2437
+ onResizeProp,
2438
+ updateResizeState
2439
+ ]
2440
+ );
2441
+ const onResizeStop = React3.useCallback(
2442
+ (i, w, h, data) => {
2443
+ const currentLayout = layoutRef.current;
2444
+ const oldResizeItem = oldResizeItemRef.current;
2445
+ const item = chunkJ4LTYI7L_js.getLayoutItem(currentLayout, i);
2446
+ const finalLayout = compactor.compact(currentLayout, cols);
2447
+ onResizeStopProp(
2448
+ finalLayout,
2449
+ oldResizeItem,
2450
+ item ?? null,
2451
+ null,
2452
+ data.e,
2453
+ data.node
2454
+ );
2455
+ oldResizeItemRef.current = null;
2456
+ oldLayoutRef.current = null;
2457
+ stopResizeState(
2458
+ i,
2459
+ item?.w ?? w,
2460
+ item?.h ?? h,
2461
+ item?.x,
2462
+ item?.y
2463
+ );
2464
+ },
2465
+ [cols, compactor, onResizeStopProp, stopResizeState]
2466
+ );
2467
+ const onResizeCancel = React3.useCallback(
2468
+ (_i) => {
2469
+ oldResizeItemRef.current = null;
2470
+ oldLayoutRef.current = null;
2471
+ cancelResizeState();
2472
+ },
2473
+ [cancelResizeState]
2474
+ );
2475
+ const removeDroppingPlaceholder = React3.useCallback(() => {
2476
+ clearDropPlaceholder();
2477
+ setDroppingDOMNode(null);
2478
+ }, [clearDropPlaceholder]);
2479
+ const handleDragOver = React3.useCallback(
2480
+ (e) => {
2481
+ e.preventDefault();
2482
+ e.stopPropagation();
2483
+ if (isFirefox && !e.nativeEvent.target?.classList.contains(layoutClassName)) {
2484
+ return false;
2485
+ }
2486
+ const rawResult = dropConfigOnDragOver ? dropConfigOnDragOver(e.nativeEvent) : onDropDragOverProp(e);
2487
+ if (rawResult === false) {
2488
+ if (droppingDOMNode) {
2489
+ removeDroppingPlaceholder();
2490
+ }
2491
+ return false;
2492
+ }
2493
+ const safeDragOverResult = rawResult ?? {};
2494
+ const {
2495
+ dragOffsetX = 0,
2496
+ dragOffsetY = 0,
2497
+ ...onDragOverResult
2498
+ } = safeDragOverResult;
2499
+ const finalDroppingItem = { ...droppingItem, ...onDragOverResult };
2500
+ const gridRect = e.currentTarget.getBoundingClientRect();
2501
+ const positionParams2 = {
2502
+ cols,
2503
+ margin,
2504
+ maxRows,
2505
+ rowHeight,
2506
+ containerWidth: width,
2507
+ containerPadding: effectiveContainerPadding
2508
+ };
2509
+ const actualColWidth = chunkJ4LTYI7L_js.calcGridColWidth(positionParams2);
2510
+ const itemPixelWidth = chunkJ4LTYI7L_js.calcGridItemWHPx(
2511
+ finalDroppingItem.w,
2512
+ actualColWidth,
2513
+ margin[0]
2514
+ );
2515
+ const itemPixelHeight = chunkJ4LTYI7L_js.calcGridItemWHPx(
2516
+ finalDroppingItem.h,
2517
+ rowHeight,
2518
+ margin[1]
2519
+ );
2520
+ const itemCenterOffsetX = itemPixelWidth / 2;
2521
+ const itemCenterOffsetY = itemPixelHeight / 2;
2522
+ const rawGridX = e.clientX - gridRect.left + dragOffsetX - itemCenterOffsetX;
2523
+ const rawGridY = e.clientY - gridRect.top + dragOffsetY - itemCenterOffsetY;
2524
+ const clampedGridX = Math.max(0, rawGridX);
2525
+ const clampedGridY = Math.max(0, rawGridY);
2526
+ const newDroppingPosition = {
2527
+ left: clampedGridX / transformScale,
2528
+ top: clampedGridY / transformScale,
2529
+ e: e.nativeEvent
2530
+ };
2531
+ if (!droppingDOMNode) {
2532
+ const calculatedPosition = chunkJ4LTYI7L_js.calcXY(
2533
+ positionParams2,
2534
+ clampedGridY,
2535
+ clampedGridX,
2536
+ finalDroppingItem.w,
2537
+ finalDroppingItem.h
2538
+ );
2539
+ setDroppingDOMNode(/* @__PURE__ */ jsxRuntime.jsx("div", {}, finalDroppingItem.i));
2540
+ updateDropPlaceholder(
2541
+ {
2542
+ ...finalDroppingItem,
2543
+ x: calculatedPosition.x,
2544
+ y: calculatedPosition.y,
2545
+ static: false,
2546
+ isDraggable: true
2547
+ },
2548
+ newDroppingPosition
2549
+ );
2550
+ return;
2551
+ }
2552
+ if (!droppingPosition || droppingPosition.left !== newDroppingPosition.left || droppingPosition.top !== newDroppingPosition.top) {
2553
+ updateDropPlaceholder(finalDroppingItem, newDroppingPosition);
2554
+ }
2555
+ },
2556
+ [
2557
+ dropConfigOnDragOver,
2558
+ onDropDragOverProp,
2559
+ droppingDOMNode,
2560
+ removeDroppingPlaceholder,
2561
+ droppingItem,
2562
+ cols,
2563
+ margin,
2564
+ maxRows,
2565
+ rowHeight,
2566
+ width,
2567
+ effectiveContainerPadding,
2568
+ transformScale,
2569
+ droppingPosition,
2570
+ updateDropPlaceholder
2571
+ ]
2572
+ );
2573
+ const handleDragLeave = React3.useCallback(
2574
+ (e) => {
2575
+ e.preventDefault();
2576
+ e.stopPropagation();
2577
+ dragEnterCounterRef.current--;
2578
+ if (dragEnterCounterRef.current < 0) {
2579
+ dragEnterCounterRef.current = 0;
2580
+ }
2581
+ if (dragEnterCounterRef.current === 0) {
2582
+ removeDroppingPlaceholder();
2583
+ }
2584
+ },
2585
+ [removeDroppingPlaceholder]
2586
+ );
2587
+ const handleDragEnter = React3.useCallback((e) => {
2588
+ e.preventDefault();
2589
+ e.stopPropagation();
2590
+ dragEnterCounterRef.current++;
2591
+ }, []);
2592
+ const handleDrop = React3.useCallback(
2593
+ (e) => {
2594
+ e.preventDefault();
2595
+ e.stopPropagation();
2596
+ const currentLayout = layoutRef.current;
2597
+ const item = currentLayout.find((l) => l.i === droppingItem.i);
2598
+ dragEnterCounterRef.current = 0;
2599
+ removeDroppingPlaceholder();
2600
+ onDropProp(currentLayout, item, e.nativeEvent);
2601
+ },
2602
+ [droppingItem.i, removeDroppingPlaceholder, onDropProp]
2603
+ );
2604
+ const processGridItem = React3.useCallback(
2605
+ (child, isDroppingItem) => {
2606
+ if (!child || !child.key) {
2607
+ return null;
2608
+ }
2609
+ const layoutItem = chunkJ4LTYI7L_js.getLayoutItem(layout, String(child.key));
2610
+ if (!layoutItem) {
2611
+ return null;
2612
+ }
2613
+ const draggable = typeof layoutItem.isDraggable === "boolean" ? layoutItem.isDraggable : !layoutItem.static && isDraggable;
2614
+ const resizable = typeof layoutItem.isResizable === "boolean" ? layoutItem.isResizable : !layoutItem.static && isResizable;
2615
+ const resizeHandlesOptions = layoutItem.resizeHandles || [...resizeHandles];
2616
+ const bounded = draggable && isBounded && layoutItem.isBounded !== false;
2617
+ const resizeHandleElement = resizeHandle;
2618
+ return /* @__PURE__ */ jsxRuntime.jsx(
2619
+ GridItem,
2620
+ {
2621
+ containerWidth: width,
2622
+ cols,
2623
+ margin,
2624
+ containerPadding: effectiveContainerPadding,
2625
+ maxRows,
2626
+ rowHeight,
2627
+ cancel: draggableCancel,
2628
+ handle: draggableHandle,
2629
+ onDragStart: isDroppingItem ? void 0 : onDragStart,
2630
+ onDrag: isDroppingItem ? void 0 : onDrag,
2631
+ onDragStop: isDroppingItem ? void 0 : onDragStop,
2632
+ onResizeStart,
2633
+ onResize,
2634
+ onResizeStop,
2635
+ onResizeCancel,
2636
+ isDraggable: draggable,
2637
+ isResizable: resizable,
2638
+ isBounded: bounded,
2639
+ enableSortable: !isDroppingItem,
2640
+ useCSSTransforms: useCSSTransforms && mounted,
2641
+ usePercentages: !mounted,
2642
+ transformScale,
2643
+ positionStrategy,
2644
+ dragThreshold,
2645
+ w: layoutItem.w,
2646
+ h: layoutItem.h,
2647
+ x: layoutItem.x,
2648
+ y: layoutItem.y,
2649
+ i: layoutItem.i,
2650
+ minH: layoutItem.minH,
2651
+ minW: layoutItem.minW,
2652
+ maxH: layoutItem.maxH,
2653
+ maxW: layoutItem.maxW,
2654
+ static: layoutItem.static,
2655
+ isDndKitDragSource: !isDroppingItem && dragOverlayId === layoutItem.i,
2656
+ droppingPosition: isDroppingItem ? interactionState.droppingPosition : void 0,
2657
+ resizeHandles: resizeHandlesOptions,
2658
+ resizeHandle: resizeHandleElement,
2659
+ constraints,
2660
+ layoutItem,
2661
+ layout,
2662
+ children: child
2663
+ },
2664
+ layoutItem.i
2665
+ );
2666
+ },
2667
+ [
2668
+ layout,
2669
+ width,
2670
+ cols,
2671
+ margin,
2672
+ effectiveContainerPadding,
2673
+ maxRows,
2674
+ rowHeight,
2675
+ draggableCancel,
2676
+ draggableHandle,
2677
+ onDragStart,
2678
+ onDrag,
2679
+ onDragStop,
2680
+ onResizeStart,
2681
+ onResize,
2682
+ onResizeStop,
2683
+ isDraggable,
2684
+ isResizable,
2685
+ isBounded,
2686
+ useCSSTransforms,
2687
+ mounted,
2688
+ transformScale,
2689
+ positionStrategy,
2690
+ dragThreshold,
2691
+ dragOverlayId,
2692
+ interactionState.droppingPosition,
2693
+ resizeHandles,
2694
+ resizeHandle,
2695
+ constraints
2696
+ ]
2697
+ );
2698
+ const renderPlaceholder = () => {
2699
+ if (!interactionState.isInteracting || !interactionState.activeDrag) {
2700
+ return null;
2701
+ }
2702
+ const placeholderId = `__rgl-interaction-placeholder__${interactionState.activeDrag.i}`;
2703
+ return /* @__PURE__ */ jsxRuntime.jsx(
2704
+ GridItem,
2705
+ {
2706
+ w: interactionState.activeDrag.w,
2707
+ h: interactionState.activeDrag.h,
2708
+ x: interactionState.activeDrag.x,
2709
+ y: interactionState.activeDrag.y,
2710
+ i: placeholderId,
2711
+ className: `react-grid-placeholder ${interactionState.resizing ? "placeholder-resizing" : ""}`,
2712
+ containerWidth: width,
2713
+ cols,
2714
+ margin,
2715
+ containerPadding: effectiveContainerPadding,
2716
+ maxRows,
2717
+ rowHeight,
2718
+ isDraggable: false,
2719
+ isResizable: false,
2720
+ isBounded: false,
2721
+ onResizeCancel,
2722
+ enableSortable: false,
2723
+ useCSSTransforms,
2724
+ transformScale,
2725
+ constraints,
2726
+ layout,
2727
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", {})
2728
+ },
2729
+ placeholderId
2730
+ );
2731
+ };
2732
+ const renderDragOverlay = React3.useCallback(() => {
2733
+ if (!dragOverlayId) {
2734
+ return null;
2735
+ }
2736
+ const child = childMap.get(dragOverlayId);
2737
+ const session = activeDndDragRef.current;
2738
+ if (!child || !session) {
2739
+ return null;
2740
+ }
2741
+ const childProps = child.props;
2742
+ const childClassName = childProps["className"];
2743
+ const childStyle = childProps["style"];
2744
+ const size = chunkJ4LTYI7L_js.calcGridItemPosition(
2745
+ positionParams,
2746
+ session.origin.x,
2747
+ session.origin.y,
2748
+ session.origin.w,
2749
+ session.origin.h
2750
+ );
2751
+ return React3__default.default.cloneElement(child, {
2752
+ className: clsx__default.default(
2753
+ "react-grid-item",
2754
+ "react-draggable",
2755
+ "react-draggable-dragging",
2756
+ childClassName
2757
+ ),
2758
+ style: {
2759
+ ...childStyle,
2760
+ width: size.width,
2761
+ height: size.height,
2762
+ touchAction: "none"
2763
+ }
2764
+ });
2765
+ }, [childMap, dragOverlayId, positionParams]);
2766
+ const mergedClassName = clsx__default.default(layoutClassName, className);
2767
+ const mergedStyle = {
2768
+ height: containerHeight,
2769
+ ...style
2770
+ };
2771
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2772
+ DragDropProvider,
2773
+ {
2774
+ sensors: dndSensors,
2775
+ onDragStart: handleDndKitDragStart,
2776
+ onDragMove: handleDndKitDragMove,
2777
+ onDragEnd: handleDndKitDragEnd,
2778
+ children: [
2779
+ /* @__PURE__ */ jsxRuntime.jsxs(
2780
+ "div",
2781
+ {
2782
+ ref: setContainerNode,
2783
+ className: mergedClassName,
2784
+ style: mergedStyle,
2785
+ onDrop: isDroppable ? handleDrop : void 0,
2786
+ onDragLeave: isDroppable ? handleDragLeave : void 0,
2787
+ onDragEnter: isDroppable ? handleDragEnter : void 0,
2788
+ onDragOver: isDroppable ? handleDragOver : void 0,
2789
+ children: [
2790
+ React3__default.default.Children.map(children, (child) => {
2791
+ if (!React3__default.default.isValidElement(child)) {
2792
+ return null;
2793
+ }
2794
+ return processGridItem(child);
2795
+ }),
2796
+ isDroppable && droppingDOMNode && processGridItem(droppingDOMNode, true),
2797
+ renderPlaceholder()
2798
+ ]
2799
+ }
2800
+ ),
2801
+ /* @__PURE__ */ jsxRuntime.jsx(DragOverlay, { disabled: !dragOverlayId, dropAnimation: null, children: renderDragOverlay() })
2802
+ ]
2803
+ }
2804
+ );
2805
+ }
2806
+ var DEFAULT_BREAKPOINTS = {
2807
+ lg: 1200,
2808
+ md: 996,
2809
+ sm: 768,
2810
+ xs: 480,
2811
+ xxs: 0
2812
+ };
2813
+ var DEFAULT_COLS = {
2814
+ lg: 12,
2815
+ md: 10,
2816
+ sm: 6,
2817
+ xs: 4,
2818
+ xxs: 2
2819
+ };
2820
+ function cloneResponsiveLayouts(layouts) {
2821
+ const cloned = {};
2822
+ for (const breakpoint of Object.keys(layouts)) {
2823
+ const layout = layouts[breakpoint];
2824
+ if (layout) {
2825
+ cloned[breakpoint] = chunkJ4LTYI7L_js.cloneLayout(layout);
2826
+ }
2827
+ }
2828
+ return cloned;
2829
+ }
2830
+ function useResponsiveLayout(options) {
2831
+ const {
2832
+ width,
2833
+ breakpoint: breakpointProp,
2834
+ breakpoints = DEFAULT_BREAKPOINTS,
2835
+ cols: colsConfig = DEFAULT_COLS,
2836
+ layouts: propsLayouts = {},
2837
+ compactor = chunkLQOPWRJR_js.verticalCompactor,
2838
+ onBreakpointChange,
2839
+ onLayoutChange,
2840
+ onWidthChange
2841
+ } = options;
2842
+ const sortedBreakpoints = React3.useMemo(
2843
+ () => chunkLQOPWRJR_js.sortBreakpoints(breakpoints),
2844
+ [breakpoints]
2845
+ );
2846
+ const initialBreakpoint = React3.useMemo(
2847
+ () => breakpointProp ?? chunkLQOPWRJR_js.getBreakpointFromWidth(breakpoints, width),
2848
+ []
2849
+ );
2850
+ const [layoutsState, setLayoutsState] = React3.useState(
2851
+ () => cloneResponsiveLayouts(propsLayouts)
2852
+ );
2853
+ const prevWidthRef = React3.useRef(width);
2854
+ const prevBreakpointRef = React3.useRef(initialBreakpoint);
2855
+ const prevBreakpointsRef = React3.useRef(breakpoints);
2856
+ const prevColsRef = React3.useRef(colsConfig);
2857
+ const prevPropsLayoutsRef = React3.useRef(propsLayouts);
2858
+ const prevLayoutsRef = React3.useRef(layoutsState);
2859
+ const layoutsRef = React3.useRef(layoutsState);
2860
+ const currentBreakpoint = breakpointProp ?? chunkLQOPWRJR_js.getBreakpointFromWidth(breakpoints, width);
2861
+ const currentCols = chunkLQOPWRJR_js.getColsFromBreakpoint(currentBreakpoint, colsConfig);
2862
+ const propsLayoutsChanged = !fastEquals.deepEqual(propsLayouts, prevPropsLayoutsRef.current);
2863
+ const sourceLayouts = React3.useMemo(
2864
+ () => propsLayoutsChanged ? cloneResponsiveLayouts(propsLayouts) : layoutsState,
2865
+ [propsLayoutsChanged, propsLayouts, layoutsState]
2866
+ );
2867
+ const layout = React3.useMemo(
2868
+ () => chunkLQOPWRJR_js.findOrGenerateResponsiveLayout(
2869
+ sourceLayouts,
2870
+ breakpoints,
2871
+ currentBreakpoint,
2872
+ prevBreakpointRef.current,
2873
+ currentCols,
2874
+ compactor
2875
+ ),
2876
+ [sourceLayouts, breakpoints, currentBreakpoint, currentCols, compactor]
2877
+ );
2878
+ const effectiveLayouts = React3.useMemo(() => {
2879
+ const currentLayout = sourceLayouts[currentBreakpoint];
2880
+ if (currentLayout && fastEquals.deepEqual(currentLayout, layout)) {
2881
+ return sourceLayouts;
2882
+ }
2883
+ return {
2884
+ ...sourceLayouts,
2885
+ [currentBreakpoint]: chunkJ4LTYI7L_js.cloneLayout(layout)
2886
+ };
2887
+ }, [sourceLayouts, currentBreakpoint, layout]);
2888
+ const setLayoutForBreakpoint = React3.useCallback((breakpoint, layout2) => {
2889
+ setLayoutsState((previousLayouts) => ({
2890
+ ...previousLayouts,
2891
+ [breakpoint]: chunkJ4LTYI7L_js.cloneLayout(layout2)
2892
+ }));
2893
+ }, []);
2894
+ const setLayouts = React3.useCallback((layouts) => {
2895
+ setLayoutsState(cloneResponsiveLayouts(layouts));
2896
+ }, []);
2897
+ React3.useEffect(() => {
2898
+ layoutsRef.current = layoutsState;
2899
+ }, [layoutsState]);
2900
+ React3.useEffect(() => {
2901
+ if (!propsLayoutsChanged) {
2902
+ return;
2903
+ }
2904
+ const nextLayouts = cloneResponsiveLayouts(propsLayouts);
2905
+ setLayoutsState(nextLayouts);
2906
+ layoutsRef.current = nextLayouts;
2907
+ prevPropsLayoutsRef.current = propsLayouts;
2908
+ }, [propsLayoutsChanged, propsLayouts]);
2909
+ React3.useEffect(() => {
2910
+ const widthChanged = width !== prevWidthRef.current;
2911
+ const breakpointChanged = currentBreakpoint !== prevBreakpointRef.current;
2912
+ const breakpointsChanged = !fastEquals.deepEqual(breakpoints, prevBreakpointsRef.current);
2913
+ const colsChanged = !fastEquals.deepEqual(colsConfig, prevColsRef.current);
2914
+ const layoutsChanged = !fastEquals.deepEqual(effectiveLayouts, layoutsRef.current);
2915
+ if (layoutsChanged) {
2916
+ setLayoutsState(effectiveLayouts);
2917
+ layoutsRef.current = effectiveLayouts;
2918
+ }
2919
+ if (widthChanged || breakpointChanged || breakpointsChanged || colsChanged) {
2920
+ onWidthChange?.(width, [10, 10], currentCols, null);
2921
+ if (breakpointChanged || breakpointsChanged || colsChanged) {
2922
+ onBreakpointChange?.(currentBreakpoint, currentCols);
2923
+ }
2924
+ }
2925
+ if (layoutsChanged && !propsLayoutsChanged) {
2926
+ onLayoutChange?.(layout, effectiveLayouts);
2927
+ }
2928
+ prevWidthRef.current = width;
2929
+ prevBreakpointRef.current = currentBreakpoint;
2930
+ prevBreakpointsRef.current = breakpoints;
2931
+ prevColsRef.current = colsConfig;
2932
+ prevLayoutsRef.current = effectiveLayouts;
2933
+ if (!propsLayoutsChanged) {
2934
+ prevPropsLayoutsRef.current = propsLayouts;
2935
+ }
2936
+ }, [
2937
+ width,
2938
+ currentBreakpoint,
2939
+ currentCols,
2940
+ breakpoints,
2941
+ colsConfig,
2942
+ effectiveLayouts,
2943
+ layout,
2944
+ onBreakpointChange,
2945
+ onLayoutChange,
2946
+ onWidthChange,
2947
+ propsLayouts,
2948
+ propsLayoutsChanged
2949
+ ]);
2950
+ return {
2951
+ layout,
2952
+ layouts: effectiveLayouts,
2953
+ breakpoint: currentBreakpoint,
2954
+ cols: currentCols,
2955
+ setLayoutForBreakpoint,
2956
+ setLayouts,
2957
+ sortedBreakpoints
2958
+ };
2959
+ }
2960
+ var noop2 = () => {
2961
+ };
2962
+ function synchronizeLayoutWithChildren2(initialLayout, children, cols, compactor) {
2963
+ const layout = [];
2964
+ React3__default.default.Children.forEach(children, (child) => {
2965
+ if (!React3__default.default.isValidElement(child) || child.key === null) return;
2966
+ const key = String(child.key);
2967
+ const existingItem = initialLayout.find((l) => l.i === key);
2968
+ if (existingItem) {
2969
+ layout.push({
2970
+ ...existingItem,
2971
+ i: key
2972
+ });
2973
+ return;
2974
+ }
2975
+ const childProps = child.props;
2976
+ const dataGrid = childProps["data-grid"];
2977
+ if (dataGrid) {
2978
+ layout.push({
2979
+ i: key,
2980
+ x: dataGrid.x ?? 0,
2981
+ y: dataGrid.y ?? 0,
2982
+ w: dataGrid.w ?? 1,
2983
+ h: dataGrid.h ?? 1,
2984
+ minW: dataGrid.minW,
2985
+ maxW: dataGrid.maxW,
2986
+ minH: dataGrid.minH,
2987
+ maxH: dataGrid.maxH,
2988
+ static: dataGrid.static,
2989
+ isDraggable: dataGrid.isDraggable,
2990
+ isResizable: dataGrid.isResizable,
2991
+ resizeHandles: dataGrid.resizeHandles,
2992
+ isBounded: dataGrid.isBounded
2993
+ });
2994
+ return;
2995
+ }
2996
+ layout.push({
2997
+ i: key,
2998
+ x: 0,
2999
+ y: chunkJ4LTYI7L_js.bottom(layout),
3000
+ w: 1,
3001
+ h: 1
3002
+ });
3003
+ });
3004
+ const corrected = chunkJ4LTYI7L_js.correctBounds(layout, { cols });
3005
+ return compactor.compact(corrected, cols);
3006
+ }
3007
+ function ResponsiveGridLayout(props) {
3008
+ const {
3009
+ children,
3010
+ width,
3011
+ breakpoint: breakpointProp,
3012
+ breakpoints = DEFAULT_BREAKPOINTS,
3013
+ cols: colsConfig = DEFAULT_COLS,
3014
+ layouts: propsLayouts = {},
3015
+ rowHeight = 150,
3016
+ maxRows = Infinity,
3017
+ margin: marginProp = [10, 10],
3018
+ containerPadding: containerPaddingProp = null,
3019
+ compactor: compactorProp,
3020
+ onBreakpointChange = noop2,
3021
+ onLayoutChange = noop2,
3022
+ onWidthChange = noop2,
3023
+ ...restProps
3024
+ } = props;
3025
+ const compactor = compactorProp ?? chunkLQOPWRJR_js.getCompactor("vertical");
3026
+ const {
3027
+ layout: responsiveLayout,
3028
+ layouts,
3029
+ breakpoint,
3030
+ cols,
3031
+ setLayouts
3032
+ } = useResponsiveLayout({
3033
+ width,
3034
+ breakpoint: breakpointProp,
3035
+ breakpoints,
3036
+ cols: colsConfig,
3037
+ layouts: propsLayouts,
3038
+ compactor
3039
+ });
3040
+ const prevWidthRef = React3.useRef(width);
3041
+ const prevBreakpointRef = React3.useRef(breakpoint);
3042
+ const prevBreakpointsRef = React3.useRef(breakpoints);
3043
+ const prevColsRef = React3.useRef(colsConfig);
3044
+ const prevCompactTypeRef = React3.useRef(compactor.type);
3045
+ const currentMargin = React3.useMemo(
3046
+ () => chunkLQOPWRJR_js.getIndentationValue(
3047
+ marginProp,
3048
+ breakpoint
3049
+ ),
3050
+ [marginProp, breakpoint]
3051
+ );
3052
+ const currentContainerPadding = React3.useMemo(() => {
3053
+ if (containerPaddingProp === null) {
3054
+ return null;
3055
+ }
3056
+ return chunkLQOPWRJR_js.getIndentationValue(
3057
+ containerPaddingProp,
3058
+ breakpoint
3059
+ );
3060
+ }, [containerPaddingProp, breakpoint]);
3061
+ const synchronizedLayout = React3.useMemo(
3062
+ () => synchronizeLayoutWithChildren2(responsiveLayout, children, cols, compactor),
3063
+ [responsiveLayout, children, cols, compactor]
3064
+ );
3065
+ const effectiveLayouts = React3.useMemo(() => {
3066
+ const currentLayout = layouts[breakpoint];
3067
+ if (currentLayout && fastEquals.deepEqual(currentLayout, synchronizedLayout)) {
3068
+ return layouts;
3069
+ }
3070
+ return {
3071
+ ...layouts,
3072
+ [breakpoint]: chunkJ4LTYI7L_js.cloneLayout(synchronizedLayout)
3073
+ };
3074
+ }, [layouts, breakpoint, synchronizedLayout]);
3075
+ React3.useEffect(() => {
3076
+ if (fastEquals.deepEqual(effectiveLayouts, layouts)) {
3077
+ return;
3078
+ }
3079
+ setLayouts(effectiveLayouts);
3080
+ }, [effectiveLayouts, layouts, setLayouts]);
3081
+ React3.useEffect(() => {
3082
+ const widthChanged = width !== prevWidthRef.current;
3083
+ const breakpointChanged = breakpoint !== prevBreakpointRef.current;
3084
+ const breakpointsChanged = !fastEquals.deepEqual(breakpoints, prevBreakpointsRef.current);
3085
+ const colsChanged = !fastEquals.deepEqual(colsConfig, prevColsRef.current);
3086
+ if (widthChanged || breakpointChanged || breakpointsChanged || colsChanged) {
3087
+ if (breakpointChanged || breakpointsChanged || colsChanged) {
3088
+ onBreakpointChange(breakpoint, cols);
3089
+ onLayoutChange(synchronizedLayout, effectiveLayouts);
3090
+ }
3091
+ onWidthChange(width, currentMargin, cols, currentContainerPadding);
3092
+ }
3093
+ prevWidthRef.current = width;
3094
+ prevBreakpointRef.current = breakpoint;
3095
+ prevBreakpointsRef.current = breakpoints;
3096
+ prevColsRef.current = colsConfig;
3097
+ }, [
3098
+ width,
3099
+ breakpoint,
3100
+ cols,
3101
+ breakpoints,
3102
+ colsConfig,
3103
+ currentMargin,
3104
+ currentContainerPadding,
3105
+ effectiveLayouts,
3106
+ synchronizedLayout,
3107
+ onBreakpointChange,
3108
+ onLayoutChange,
3109
+ onWidthChange
3110
+ ]);
3111
+ React3.useEffect(() => {
3112
+ if (compactor.type === prevCompactTypeRef.current) {
3113
+ return;
3114
+ }
3115
+ prevCompactTypeRef.current = compactor.type;
3116
+ onLayoutChange(synchronizedLayout, effectiveLayouts);
3117
+ }, [compactor.type, synchronizedLayout, effectiveLayouts, onLayoutChange]);
3118
+ const handleLayoutChange = React3.useCallback(
3119
+ (layout) => {
3120
+ const nextLayouts = {
3121
+ ...effectiveLayouts,
3122
+ [breakpoint]: chunkJ4LTYI7L_js.cloneLayout(layout)
3123
+ };
3124
+ setLayouts(nextLayouts);
3125
+ onLayoutChange(layout, nextLayouts);
3126
+ },
3127
+ [effectiveLayouts, breakpoint, setLayouts, onLayoutChange]
3128
+ );
3129
+ const gridConfig = React3.useMemo(
3130
+ () => ({
3131
+ cols,
3132
+ rowHeight,
3133
+ maxRows,
3134
+ margin: currentMargin,
3135
+ containerPadding: currentContainerPadding
3136
+ }),
3137
+ [cols, rowHeight, maxRows, currentMargin, currentContainerPadding]
3138
+ );
3139
+ return /* @__PURE__ */ jsxRuntime.jsx(
3140
+ GridLayout,
3141
+ {
3142
+ ...restProps,
3143
+ width,
3144
+ gridConfig,
3145
+ compactor,
3146
+ onLayoutChange: handleLayoutChange,
3147
+ layout: synchronizedLayout,
3148
+ children
3149
+ }
3150
+ );
3151
+ }
3152
+
3153
+ exports.DEFAULT_BREAKPOINTS = DEFAULT_BREAKPOINTS;
3154
+ exports.DEFAULT_COLS = DEFAULT_COLS;
3155
+ exports.GridItem = GridItem;
3156
+ exports.GridLayout = GridLayout;
3157
+ exports.ResponsiveGridLayout = ResponsiveGridLayout;
3158
+ exports.useGridLayout = useGridLayout;
3159
+ exports.useResponsiveLayout = useResponsiveLayout;