@bsuite/page-builder 1.0.3 → 1.0.4

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;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,CAwnBpD"}
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,CA4pBpD"}
@@ -184,13 +184,24 @@ export function usePageGridLayout({ pageKey, defaultLayouts, defaultCols = 12, l
184
184
  }
185
185
  return resolved;
186
186
  }, [rawLayouts, baseCols, layoutCols, defaultAutoHeight]);
187
- useEffect(() => {
188
- if (baseCols !== layoutCols) {
189
- const rescaled = rescaleLayout(rawLayouts, baseCols, layoutCols);
190
- setSavedLayout(rescaled);
191
- setBaseCols(layoutCols);
192
- }
193
- }, [baseCols, layoutCols, rawLayouts, setBaseCols, setSavedLayout]);
187
+ /*
188
+ * THERE IS DELIBERATELY NO EFFECT HERE.
189
+ *
190
+ * This used to rescale the stored layout to the new column count and write it
191
+ * back, which made a column change DESTRUCTIVE and unrecoverable. Measured on
192
+ * `rescaleLayout` directly: an 11 -> 2 -> 11 round trip takes
193
+ *
194
+ * a(w4 @x0) b(w3 @x4) c(w4 @x7) / d(w6 @x0) e(w5 @x6)
195
+ *
196
+ * to five items of w6 stacked one per row at x0. Everything narrows to the
197
+ * one-column minimum on the way down, the row-packer puts one item per row,
198
+ * and coming back up cannot recover an arrangement that no longer exists.
199
+ * That is what flattened the operator's dashboard.
200
+ *
201
+ * `currentLayouts` above already derives the DISPLAY at `layoutCols` from the
202
+ * authored layout at `baseCols`. Leaving storage alone makes the column
203
+ * control a view, and the round trip exact.
204
+ */
194
205
  const activeCols = useMemo(() => ({ lg: layoutCols, md: layoutCols, sm: layoutCols, xs: layoutCols, xxs: layoutCols }), [layoutCols]);
195
206
  /**
196
207
  * The compactor handed to react-grid-layout — the SAME one in edit mode and
@@ -413,12 +424,22 @@ export function usePageGridLayout({ pageKey, defaultLayouts, defaultCols = 12, l
413
424
  }
414
425
  return next;
415
426
  }, []);
427
+ /**
428
+ * Persist a layout the USER authored, and re-base the column count to the one
429
+ * they authored it at.
430
+ *
431
+ * Re-basing belongs here and ONLY here. A column-count change is a view
432
+ * operation and must not touch storage — see `handleColumnChange`. An edit is
433
+ * the one moment the stored arrangement and the stored column count are known
434
+ * to agree, so it is the one moment `baseCols` may move.
435
+ */
416
436
  const commitLayout = useCallback((layouts) => {
417
437
  const canonical = canonicaliseLayoutForPersist(layouts);
418
438
  if (!canonical)
419
439
  return;
420
440
  setSavedLayout(stripAutoHeightRows(canonical));
421
- }, [canonicaliseLayoutForPersist, setSavedLayout, stripAutoHeightRows]);
441
+ setBaseCols(layoutCols);
442
+ }, [canonicaliseLayoutForPersist, layoutCols, setBaseCols, setSavedLayout, stripAutoHeightRows]);
422
443
  const onLayoutChange = useCallback((_layout, layouts) => {
423
444
  if (!isEditing)
424
445
  return;
@@ -448,12 +469,18 @@ export function usePageGridLayout({ pageKey, defaultLayouts, defaultCols = 12, l
448
469
  }
449
470
  };
450
471
  }, []);
472
+ /**
473
+ * Change how many columns the canvas is DISPLAYED at.
474
+ *
475
+ * This writes nothing to storage. `currentLayouts` rescales the authored
476
+ * layout for display on every render, so switching 11 -> 2 -> 11 returns the
477
+ * user to exactly what they authored. The previous version persisted the
478
+ * rescale, which destroyed the arrangement at the narrow end and offered no
479
+ * undo. Storage moves only when the user actually edits — see `commitLayout`.
480
+ */
451
481
  const handleColumnChange = useCallback((newCols) => {
452
- const rescaled = rescaleLayout(currentLayouts, layoutCols, newCols);
453
- setSavedLayout(rescaled);
454
482
  setLayoutCols(newCols);
455
- setBaseCols(newCols);
456
- }, [currentLayouts, layoutCols, setBaseCols, setLayoutCols, setSavedLayout]);
483
+ }, [setLayoutCols]);
457
484
  /**
458
485
  * Build the object handed to the preference adapter from a new `lg` array.
459
486
  *
@@ -471,6 +498,11 @@ export function usePageGridLayout({ pageKey, defaultLayouts, defaultCols = 12, l
471
498
  }
472
499
  return next;
473
500
  }, [currentLayouts]);
501
+ /** Persist a bare `lg` item list from a mutator, re-basing the same way. */
502
+ const commitItems = useCallback((items) => {
503
+ setSavedLayout(layoutsWithLg(items));
504
+ setBaseCols(layoutCols);
505
+ }, [layoutCols, layoutsWithLg, setBaseCols, setSavedLayout]);
474
506
  const handleCompact = useCallback(() => {
475
507
  if (!currentLayouts.lg)
476
508
  return;
@@ -487,8 +519,8 @@ export function usePageGridLayout({ pageKey, defaultLayouts, defaultCols = 12, l
487
519
  placed.push(compacted);
488
520
  return compacted;
489
521
  });
490
- startTransition(() => setSavedLayout(layoutsWithLg(result)));
491
- }, [currentLayouts, layoutsWithLg, setSavedLayout]);
522
+ startTransition(() => commitItems(result));
523
+ }, [currentLayouts, commitItems]);
492
524
  const handleReset = useCallback(() => {
493
525
  startTransition(() => {
494
526
  setSavedLayout(defaultLayouts);
@@ -507,7 +539,7 @@ export function usePageGridLayout({ pageKey, defaultLayouts, defaultCols = 12, l
507
539
  minW: initialSize?.minW,
508
540
  minH: initialSize?.minH,
509
541
  };
510
- startTransition(() => setSavedLayout(layoutsWithLg([...(currentLayouts.lg ?? []), newItem])));
542
+ startTransition(() => commitItems([...(currentLayouts.lg ?? []), newItem]));
511
543
  }, [currentLayouts, layoutCols, layoutsWithLg, setSavedLayout]);
512
544
  const moveWidget = useCallback((widgetKey, direction) => {
513
545
  const items = [...(currentLayouts.lg ?? [])];
@@ -524,7 +556,7 @@ export function usePageGridLayout({ pageKey, defaultLayouts, defaultCols = 12, l
524
556
  moved,
525
557
  ...withoutMoved.slice(targetIndex),
526
558
  ];
527
- startTransition(() => setSavedLayout(layoutsWithLg(nextItems)));
559
+ startTransition(() => commitItems(nextItems));
528
560
  }, [currentLayouts, layoutsWithLg, setSavedLayout]);
529
561
  const setWidgetLocked = useCallback((widgetKey, locked) => {
530
562
  const nextItems = (currentLayouts.lg ?? []).map((item) => {
@@ -537,11 +569,11 @@ export function usePageGridLayout({ pageKey, defaultLayouts, defaultCols = 12, l
537
569
  isResizable: !locked,
538
570
  };
539
571
  });
540
- startTransition(() => setSavedLayout(layoutsWithLg(nextItems)));
572
+ startTransition(() => commitItems(nextItems));
541
573
  }, [currentLayouts, layoutsWithLg, setSavedLayout]);
542
574
  const removeWidget = useCallback((widgetKey) => {
543
575
  const nextItems = (currentLayouts.lg ?? []).filter((item) => item.i !== widgetKey);
544
- startTransition(() => setSavedLayout(layoutsWithLg(nextItems)));
576
+ startTransition(() => commitItems(nextItems));
545
577
  }, [currentLayouts, layoutsWithLg, setSavedLayout]);
546
578
  /**
547
579
  * Measured auto-height overrides (widgetKey -> rows). DERIVED, in-memory-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsuite/page-builder",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Shared BSuite responsive page-builder grid and layout persistence primitives",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",