@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
51 lines (49 loc) • 1.81 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/widget-dashboard/src/utils/canonicalize-layout.ts
var canonicalize_layout_exports = {};
__export(canonicalize_layout_exports, {
canonicalizeLayout: () => canonicalizeLayout
});
module.exports = __toCommonJS(canonicalize_layout_exports);
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;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
canonicalizeLayout
});
//# sourceMappingURL=canonicalize-layout.cjs.map