@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
26 lines (25 loc) • 744 B
JavaScript
// packages/widget-dashboard/src/utils/canonicalize-layout.ts
function canonicalizeLayout(layout) {
const indexed = layout.map((widget, index) => ({
widget,
order: widget.placement?.order ?? index
}));
indexed.sort((a, b) => a.order - b.order);
let changed = false;
const canonical = indexed.map(({ widget }, index) => {
if (widget !== layout[index]) {
changed = true;
}
if (!widget.placement || !("order" in widget.placement)) {
return widget;
}
changed = true;
const { order: _stripped, ...placement } = widget.placement;
return { ...widget, placement };
});
return changed ? canonical : layout;
}
export {
canonicalizeLayout
};
//# sourceMappingURL=canonicalize-layout.mjs.map