UNPKG

@wordpress/widget-dashboard

Version:

Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.

1 lines • 1.95 kB
{"version":3,"file":"runtime-actions-map.cjs","names":["observableMap"],"sources":["../../src/utils/runtime-actions-map.ts"],"sourcesContent":["import { observableMap } from '@wordpress/compose';\nimport type { ObservableMap } from '@wordpress/compose';\nimport type { WidgetRuntimeAction } from '@wordpress/widget-primitives';\n\n/**\n * What each mounted render of an instance declares, in mount order, keyed by\n * uuid. A drag preview is a second render of its instance.\n */\nexport type RuntimeActionsMap = ObservableMap<\n\tstring,\n\tReadonlyMap< string, WidgetRuntimeAction[] >\n>;\n\nexport function createRuntimeActionsMap(): RuntimeActionsMap {\n\treturn observableMap();\n}\n\n/**\n * Replaces what one render of an instance declares; an empty list clears it.\n *\n * @param {RuntimeActionsMap} map The dashboard's map.\n * @param {string} uuid The instance.\n * @param {string} renderId The render declaring.\n * @param {WidgetRuntimeAction[]} actions The actions it declares.\n */\nexport function declareRuntimeActions(\n\tmap: RuntimeActionsMap,\n\tuuid: string,\n\trenderId: string,\n\tactions: WidgetRuntimeAction[]\n): void {\n\tconst declared = map.get( uuid );\n\tif ( actions.length === 0 && ! declared?.has( renderId ) ) {\n\t\treturn;\n\t}\n\n\tconst next = new Map( declared );\n\tif ( actions.length > 0 ) {\n\t\tnext.set( renderId, actions );\n\t} else {\n\t\tnext.delete( renderId );\n\t}\n\n\tif ( next.size > 0 ) {\n\t\tmap.set( uuid, next );\n\t} else {\n\t\tmap.delete( uuid );\n\t}\n}\n"],"mappings":";;;;;;;AAaA,SAAgB,0BAA6C;CAC5D,QAAA,GAAOA,mBAAAA,cAAAA,CAAc;AACtB;;;;;;;;;AAUA,SAAgB,sBACf,KACA,MACA,UACA,SACO;CACP,MAAM,WAAW,IAAI,IAAK,IAAK;CAC/B,IAAK,QAAQ,WAAW,KAAK,CAAE,UAAU,IAAK,QAAS,GACtD;CAGD,MAAM,OAAO,IAAI,IAAK,QAAS;CAC/B,IAAK,QAAQ,SAAS,GACrB,KAAK,IAAK,UAAU,OAAQ;MAE5B,KAAK,OAAQ,QAAS;CAGvB,IAAK,KAAK,OAAO,GAChB,IAAI,IAAK,MAAM,IAAK;MAEpB,IAAI,OAAQ,IAAK;AAEnB"}