{"version":3,"file":"create-dashboard-widget.cjs","names":[],"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":";;;;;;;AAIA,MAAM,oBAAuC;CAC5C,OAAO;CACP,QAAQ;CACR,OAAO;AACR;;;;;;;;;;;AAYA,SAAgB,sBACf,YACA,mBACuB;CACvB,OAAO;EACN,OAAA,GAAM,KAAA,GAAA,CAAK;EACX,MAAM,WAAW;EACjB,YACC,qBAAuB,WAAW,SAAS;EAC5C,WAAW;CACZ;AACD"}