@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
33 lines (32 loc) • 1.01 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let uuid = require("uuid");
// packages/widget-dashboard/src/utils/create-dashboard-widget/create-dashboard-widget.ts
const DEFAULT_PLACEMENT = {
width: 1,
height: 2,
order: 0
};
/**
* Create a new dashboard widget from a widget type.
*
* Generates a unique id and applies default placement. If no initial
* attributes are provided, falls back to the type's `example.attributes`
* (matching the `widget.json` schema).
*
* @param widgetType Source widget type.
* @param initialAttributes Initial attributes; default to the type's example.
*/
function createDashboardWidget(widgetType, initialAttributes) {
return {
uuid: (0, uuid.v4)(),
type: widgetType.name,
attributes: initialAttributes ?? widgetType.example?.attributes,
placement: DEFAULT_PLACEMENT
};
}
exports.createDashboardWidget = createDashboardWidget;
//# sourceMappingURL=create-dashboard-widget.cjs.map