UNPKG

@wordpress/widget-dashboard

Version:

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

36 lines (35 loc) • 1.27 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); // packages/widget-dashboard/src/utils/merge-widget-actions.ts function upgradeDeclaredAction(declared, runtime) { const { icon, relevance } = declared; return { ...icon !== void 0 && { icon }, ...relevance !== void 0 && { relevance }, ...runtime }; } /** * Joins the type's declared actions with the instance's runtime ones. A * runtime action carrying a declared `id` takes that action's position; * the rest follow in their own order. * * @param {WidgetAction[]} declared The type's declared actions. * @param {WidgetRuntimeAction[]} runtime The instance's runtime actions. * @return {WidgetRuntimeAction[]} The actions the surfaces place. */ function mergeWidgetActions(declared, runtime) { if (runtime.length === 0) return declared; const byId = new Map(runtime.map((action) => [action.id, action])); return [...declared.map((action) => { const replacement = byId.get(action.id); if (!replacement) return action; byId.delete(action.id); return upgradeDeclaredAction(action, replacement); }), ...byId.values()]; } exports.mergeWidgetActions = mergeWidgetActions; //# sourceMappingURL=merge-widget-actions.cjs.map