{"version":3,"file":"widget-render.mjs","names":["WidgetRenderPrimitive"],"sources":["../../../src/components/widget-render/widget-render.tsx"],"sourcesContent":["import { useCallback, useId, useMemo } from '@wordpress/element';\nimport {\n\tWidgetHostProvider,\n\tWidgetRender as WidgetRenderPrimitive,\n} from '@wordpress/widget-primitives';\nimport type { WidgetHost, WidgetType } from '@wordpress/widget-primitives';\nimport { useDashboardInternalContext } from '../../context/dashboard-context';\nimport { declareRuntimeActions } from '../../utils/runtime-actions-map';\nimport type { DashboardWidget } from '../../types';\n\ninterface WidgetRenderProps {\n\twidget: DashboardWidget< unknown >;\n\twidgetType: WidgetType;\n}\n\n/**\n * Adapter around the host-agnostic `WidgetRender` primitive. Bridges the\n * dashboard context (`resolveWidgetModule`, layout state) and turns\n * layout-level attribute updates into the per-instance `setAttributes`\n * callback the render contract expects. When the policy denies `edit`,\n * the widget renders read-only: it receives no `setAttributes`.\n *\n * Lends the widget the `actions` capability, bound to this render of the\n * instance.\n *\n * @param {WidgetRenderProps} props Component props.\n */\nexport function WidgetRender( { widget, widgetType }: WidgetRenderProps ) {\n\tconst {\n\t\tlayout,\n\t\tonLayoutChange,\n\t\tresolveWidgetModule,\n\t\tcanPerform,\n\t\truntimeActions,\n\t} = useDashboardInternalContext();\n\tconst canEdit = canPerform( { operation: 'edit', widget, widgetType } );\n\n\tconst setAttributes = useCallback(\n\t\t( next: Partial< unknown > ) => {\n\t\t\tonLayoutChange(\n\t\t\t\tlayout.map( ( w ) =>\n\t\t\t\t\tw.uuid === widget.uuid\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t...w,\n\t\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\t\t...( w.attributes as object ),\n\t\t\t\t\t\t\t\t\t...( next as object ),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: w\n\t\t\t\t)\n\t\t\t);\n\t\t},\n\t\t[ widget.uuid, layout, onLayoutChange ]\n\t);\n\n\tconst renderId = useId();\n\tconst host = useMemo< WidgetHost >(\n\t\t() => ( {\n\t\t\tactions: {\n\t\t\t\tdeclare: ( actions ) =>\n\t\t\t\t\tdeclareRuntimeActions(\n\t\t\t\t\t\truntimeActions,\n\t\t\t\t\t\twidget.uuid,\n\t\t\t\t\t\trenderId,\n\t\t\t\t\t\tactions\n\t\t\t\t\t),\n\t\t\t},\n\t\t} ),\n\t\t[ runtimeActions, widget.uuid, renderId ]\n\t);\n\n\treturn (\n\t\t<WidgetHostProvider value={ host }>\n\t\t\t<WidgetRenderPrimitive\n\t\t\t\twidgetType={ widgetType }\n\t\t\t\tattributes={ widget.attributes }\n\t\t\t\tsetAttributes={ canEdit ? setAttributes : undefined }\n\t\t\t\tresolveWidgetModule={ resolveWidgetModule }\n\t\t\t/>\n\t\t</WidgetHostProvider>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2BA,SAAgB,aAAc,EAAE,QAAQ,cAAkC;CACzE,MAAM,EACL,QACA,gBACA,qBACA,YACA,mBACG,4BAA4B;CAChC,MAAM,UAAU,WAAY;EAAE,WAAW;EAAQ;EAAQ;CAAW,CAAE;CAEtE,MAAM,gBAAgB,aACnB,SAA8B;EAC/B,eACC,OAAO,KAAO,MACb,EAAE,SAAS,OAAO,OACf;GACA,GAAG;GACH,YAAY;IACX,GAAK,EAAE;IACP,GAAK;GACN;EACD,IACC,CACJ,CACD;CACD,GACA;EAAE,OAAO;EAAM;EAAQ;CAAe,CACvC;CAEA,MAAM,WAAW,MAAM;CACvB,MAAM,OAAO,eACJ,EACP,SAAS,EACR,UAAW,YACV,sBACC,gBACA,OAAO,MACP,UACA,OACD,EACF,EACD,IACA;EAAE;EAAgB,OAAO;EAAM;CAAS,CACzC;CAEA,OACC,oBAAC,oBAAD;EAAoB,OAAQ;EAC3B,UAAA,oBAACA,gBAAD;GACc;GACb,YAAa,OAAO;GACpB,eAAgB,UAAU,gBAAgB,KAAA;GACpB;EACtB,CAAA;CACkB,CAAA;AAEtB"}