@bsuite/page-builder 1.0.6 → 1.0.7
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;AAED,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,cAAc,EACd,WAAgB,EAChB,aAAiB,EACjB,WAAkB,EAClB,gBAA6C,EAC7C,iBAA4C,EAC5C,iBAAiB,GAClB,EAAE,wBAAwB,GAAG,uBAAuB,CA2sBpD"}
|
|
@@ -55,57 +55,6 @@ 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
|
-
return compare(a, b, false);
|
|
73
|
-
}
|
|
74
|
-
/** Same, but blind to the height of items whose height is MEASURED, not authored. */
|
|
75
|
-
function samePlacement(a, b) {
|
|
76
|
-
return compare(a, b, true);
|
|
77
|
-
}
|
|
78
|
-
function compare(a, b, ignoreDerivedHeight) {
|
|
79
|
-
if (!a || !b)
|
|
80
|
-
return false;
|
|
81
|
-
const keys = new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
82
|
-
/*
|
|
83
|
-
* `h` is EXCLUDED for an autoHeight item, and that exclusion is the whole point.
|
|
84
|
-
*
|
|
85
|
-
* An autoHeight card's height is MEASURED, not authored: change the column count,
|
|
86
|
-
* the card gets narrower, its content rewraps taller, and the ResizeObserver
|
|
87
|
-
* emits a new `h`. That emission differs from what was rendered, so a comparison
|
|
88
|
-
* including `h` calls it a gesture — and commits the RESCALED WIDTHS riding along
|
|
89
|
-
* with it. Measured: three cards authored w=4,3,4 came back w=1,1,1 after nothing
|
|
90
|
-
* but a height re-measure.
|
|
91
|
-
*
|
|
92
|
-
* NARROWED, because the first version was too broad and two existing tests said
|
|
93
|
-
* so: a user CAN drag an autoHeight card's height, and that stamps `hUserSet`.
|
|
94
|
-
* Once stamped, the height IS a choice and must be compared like any other. So
|
|
95
|
-
* `h` is excluded only where it is purely derived — autoHeight AND not user-set.
|
|
96
|
-
* A real resize changes `w`, or stamps `hUserSet`, or both; none of those are
|
|
97
|
-
* hidden by this.
|
|
98
|
-
*/
|
|
99
|
-
const fingerprint = (items) => (items ?? [])
|
|
100
|
-
.map((i) => `${i.i}:${i.x}:${i.y}:${i.w}:${ignoreDerivedHeight && i.autoHeight ? 'auto' : i.h}`)
|
|
101
|
-
.sort()
|
|
102
|
-
.join('|');
|
|
103
|
-
for (const k of keys) {
|
|
104
|
-
if (fingerprint(a[k]) !== fingerprint(b[k]))
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
58
|
export function usePageGridLayout({ pageKey, defaultLayouts, defaultCols = 12, layoutVersion = 1, canEditPage = true, editorEventNames = DEFAULT_EDITOR_EVENT_NAMES, preferenceAdapter = defaultPreferenceAdapter, defaultAutoHeight, }) {
|
|
110
59
|
const effectiveLayoutVersion = layoutVersion + PACKAGE_LAYOUT_EPOCH;
|
|
111
60
|
const containerRef = useRef(null);
|
|
@@ -512,28 +461,33 @@ export function usePageGridLayout({ pageKey, defaultLayouts, defaultCols = 12, l
|
|
|
512
461
|
* Identified by comparison rather than by a flag, so it needs no event
|
|
513
462
|
* ordering to be correct.
|
|
514
463
|
*/
|
|
515
|
-
const emitted = layouts;
|
|
516
|
-
/* Identical to what was just rendered: a pure reflow, nothing to commit. */
|
|
517
|
-
if (sameArrangement(emitted, currentLayouts))
|
|
518
|
-
return;
|
|
519
464
|
/*
|
|
520
|
-
*
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
465
|
+
* ONLY A POINTER GESTURE MAY COMMIT A LAYOUT. Nothing else.
|
|
466
|
+
*
|
|
467
|
+
* Three attempts tried to classify the emission by SHAPE and all three
|
|
468
|
+
* shipped and all three failed on the deployed app:
|
|
469
|
+
*
|
|
470
|
+
* 1.0.4 removed the writes in handleColumnChange — the grid still emitted
|
|
471
|
+
* 1.0.5 skipped an emission equal to what we rendered
|
|
472
|
+
* 1.0.6 ...ignoring measured heights as well
|
|
473
|
+
*
|
|
474
|
+
* Shape can never work, and the reason is structural: react-grid-layout
|
|
475
|
+
* COMPACTS after a reflow. Its emission is therefore legitimately different
|
|
476
|
+
* from `currentLayouts` in x and y, so every comparison against what we
|
|
477
|
+
* rendered says "this is a gesture" and commits the rescaled arrangement.
|
|
478
|
+
* Measured on d.crm.crm7.app with 1.0.6 confirmed in the served bundle: a
|
|
479
|
+
* 12 -> 4 -> 8 -> 2 -> 12 round trip produced THIRTEEN writes and turned
|
|
480
|
+
* widths 4,4,4,7,5,5,12 into 6,6,6,6,6,6,6.
|
|
524
481
|
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
* existing caller behaving exactly as before; `PageGridLayout` passes the
|
|
528
|
-
* real answer.
|
|
482
|
+
* The grid knows what we cannot infer: whether a pointer gesture produced
|
|
483
|
+
* this emission. That is the only sound signal, so it is the whole rule.
|
|
529
484
|
*
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
* silently dropped, which is crm7#744 reopened.
|
|
485
|
+
* Every other mutation — add, remove, compact, reset — calls `commitItems`
|
|
486
|
+
* directly and is unaffected. A deliberate resize of an auto-height card
|
|
487
|
+
* (crm7#744) IS a gesture and still commits. `wasGesture` defaults to true,
|
|
488
|
+
* so any caller that does not pass it behaves exactly as before.
|
|
535
489
|
*/
|
|
536
|
-
if (!wasGesture
|
|
490
|
+
if (!wasGesture)
|
|
537
491
|
return;
|
|
538
492
|
pendingLayoutRef.current = layouts;
|
|
539
493
|
if (layoutCommitFrameRef.current !== null)
|