@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
28 lines (27 loc) • 854 B
JavaScript
import { v4 } from "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: v4(),
type: widgetType.name,
attributes: initialAttributes ?? widgetType.example?.attributes,
placement: DEFAULT_PLACEMENT
};
}
export { createDashboardWidget };
//# sourceMappingURL=create-dashboard-widget.mjs.map