@bsuite/page-builder 1.0.4 → 1.0.5
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePageGridLayout.d.ts","sourceRoot":"","sources":["../src/usePageGridLayout.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAGV,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,0BAA0B,2IAM7B,CAAC;AAEX;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAElE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAiBzC,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB;
|
|
1
|
+
{"version":3,"file":"usePageGridLayout.d.ts","sourceRoot":"","sources":["../src/usePageGridLayout.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAGV,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,0BAA0B,2IAM7B,CAAC;AAEX;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAElE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAiBzC,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB;AA6BD,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,cAAc,EACd,WAAgB,EAChB,aAAiB,EACjB,WAAkB,EAClB,gBAA6C,EAC7C,iBAA4C,EAC5C,iBAAiB,GAClB,EAAE,wBAAwB,GAAG,uBAAuB,CAirBpD"}
|
|
@@ -55,6 +55,33 @@ export const PACKAGE_LAYOUT_EPOCH = 1000;
|
|
|
55
55
|
* opts out with an explicit `autoHeight: false`.
|
|
56
56
|
*/
|
|
57
57
|
const DEFAULT_ITEM_AUTO_HEIGHT = true;
|
|
58
|
+
/**
|
|
59
|
+
* Do two layout SETS describe the same arrangement, at every breakpoint?
|
|
60
|
+
*
|
|
61
|
+
* Compares only the five fields that place an item. Anything else react-grid-layout
|
|
62
|
+
* attaches (`moved`, `static`, `isDraggable`, measured heights) is noise here, and
|
|
63
|
+
* comparing it would make every reflow look like a change.
|
|
64
|
+
*
|
|
65
|
+
* EVERY breakpoint, not just `lg`. A gesture made while the canvas is at `md`
|
|
66
|
+
* leaves `lg` untouched, so an `lg`-only comparison reads that real gesture as a
|
|
67
|
+
* reflow and silently drops it. That is not hypothetical — it broke the D-75
|
|
68
|
+
* "folds a gesture made at md back onto lg" test the moment the comparison was
|
|
69
|
+
* introduced.
|
|
70
|
+
*/
|
|
71
|
+
function sameArrangement(a, b) {
|
|
72
|
+
if (!a || !b)
|
|
73
|
+
return false;
|
|
74
|
+
const keys = new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
75
|
+
const fingerprint = (items) => (items ?? [])
|
|
76
|
+
.map((i) => `${i.i}:${i.x}:${i.y}:${i.w}:${i.h}`)
|
|
77
|
+
.sort()
|
|
78
|
+
.join('|');
|
|
79
|
+
for (const k of keys) {
|
|
80
|
+
if (fingerprint(a[k]) !== fingerprint(b[k]))
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
58
85
|
export function usePageGridLayout({ pageKey, defaultLayouts, defaultCols = 12, layoutVersion = 1, canEditPage = true, editorEventNames = DEFAULT_EDITOR_EVENT_NAMES, preferenceAdapter = defaultPreferenceAdapter, defaultAutoHeight, }) {
|
|
59
86
|
const effectiveLayoutVersion = layoutVersion + PACKAGE_LAYOUT_EPOCH;
|
|
60
87
|
const containerRef = useRef(null);
|
|
@@ -443,6 +470,26 @@ export function usePageGridLayout({ pageKey, defaultLayouts, defaultCols = 12, l
|
|
|
443
470
|
const onLayoutChange = useCallback((_layout, layouts) => {
|
|
444
471
|
if (!isEditing)
|
|
445
472
|
return;
|
|
473
|
+
/*
|
|
474
|
+
* A COLUMN-COUNT CHANGE MAKES REACT-GRID-LAYOUT REFLOW AND EMIT HERE, and
|
|
475
|
+
* that emission is not a user gesture. Committing it copies the rescaled
|
|
476
|
+
* DISPLAY back over the authored layout — which is the data loss this
|
|
477
|
+
* whole path exists to prevent, arriving through the back door.
|
|
478
|
+
*
|
|
479
|
+
* Removing the writes from `handleColumnChange` was not enough, and the
|
|
480
|
+
* unit tests did not catch it because they call the handler directly with
|
|
481
|
+
* no grid attached. Driving the deployed app is what found it: the
|
|
482
|
+
* persisted widths still marched 2,2,2 -> 4,4,4 -> 1,1,1 with the
|
|
483
|
+
* handler already inert.
|
|
484
|
+
*
|
|
485
|
+
* A reflow emits exactly `currentLayouts`, because that is what was just
|
|
486
|
+
* rendered. Any real gesture differs from it — and a gesture that does
|
|
487
|
+
* NOT differ has nothing to commit anyway, so this cannot swallow one.
|
|
488
|
+
* Identified by comparison rather than by a flag, so it needs no event
|
|
489
|
+
* ordering to be correct.
|
|
490
|
+
*/
|
|
491
|
+
if (sameArrangement(layouts, currentLayouts))
|
|
492
|
+
return;
|
|
446
493
|
pendingLayoutRef.current = layouts;
|
|
447
494
|
if (layoutCommitFrameRef.current !== null)
|
|
448
495
|
return;
|
|
@@ -459,7 +506,7 @@ export function usePageGridLayout({ pageKey, defaultLayouts, defaultCols = 12, l
|
|
|
459
506
|
commitLayout(pending);
|
|
460
507
|
}
|
|
461
508
|
});
|
|
462
|
-
}, [commitLayout, isEditing]);
|
|
509
|
+
}, [commitLayout, currentLayouts, isEditing]);
|
|
463
510
|
useEffect(() => {
|
|
464
511
|
return () => {
|
|
465
512
|
if (layoutCommitFrameRef.current !== null &&
|