@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
8 lines (7 loc) • 1.42 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/utils/create-dashboard-widget/create-dashboard-widget.ts"],
"sourcesContent": ["import { v4 as uuid } from 'uuid';\nimport type { WidgetType } from '@wordpress/widget-primitives';\nimport type { DashboardWidget, GridTilePlacement } from '../../types';\n\nconst DEFAULT_PLACEMENT: GridTilePlacement = {\n\twidth: 1,\n\theight: 2,\n\torder: 0,\n};\n\n/**\n * Create a new dashboard widget from a widget type.\n *\n * Generates a unique id and applies default placement. If no initial\n * attributes are provided, falls back to the type's `example.attributes`\n * (matching the `widget.json` schema).\n *\n * @param widgetType Source widget type.\n * @param initialAttributes Initial attributes; default to the type's example.\n */\nexport function createDashboardWidget< T >(\n\twidgetType: WidgetType,\n\tinitialAttributes?: T\n): DashboardWidget< T > {\n\treturn {\n\t\tuuid: uuid(),\n\t\ttype: widgetType.name,\n\t\tattributes:\n\t\t\tinitialAttributes ?? ( widgetType.example?.attributes as T ),\n\t\tplacement: DEFAULT_PLACEMENT,\n\t};\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2B;AAI3B,IAAM,oBAAuC;AAAA,EAC5C,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AACR;AAYO,SAAS,sBACf,YACA,mBACuB;AACvB,SAAO;AAAA,IACN,UAAM,YAAAA,IAAK;AAAA,IACX,MAAM,WAAW;AAAA,IACjB,YACC,qBAAuB,WAAW,SAAS;AAAA,IAC5C,WAAW;AAAA,EACZ;AACD;",
"names": ["uuid"]
}