UNPKG

@wordpress/widget-dashboard

Version:

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

48 lines • 2.08 kB
import type { WidgetType } from '@wordpress/widget-primitives'; import type { CanPerformDashboardOperation, DashboardWidget } from '../types'; interface EnforceLayoutPolicyArgs { /** * The staging layout the incoming one replaces. */ previous: DashboardWidget[]; /** * The incoming layout. */ next: DashboardWidget[]; /** * The resolved policy. */ canPerform: CanPerformDashboardOperation; /** * Registered types, to resolve each instance's `WidgetType` for the * policy request. */ widgetTypes: WidgetType[]; } /** * Re-asserts every change the policy denies before a layout enters * staging, so no composed trigger can slip a denied operation past the * interface: what the UI hides, the staging layer rejects. * * Per instance: a new instance whose type the policy rejects for * `insert` is dropped. An unregistered type has no type to ask about, * so a new instance of one passes, and instance operations on a * surviving tile still ask with `widgetType` absent: a lock keyed on * the type does not fire. Denied `edit` keeps the staged `attributes`; * denied `resize` keeps the placement spans; denied `move` keeps the * masonry `lane` and holds the instance's canonical position, adjusted * for allowed membership changes: the same hold `remove` uses, and the * position the grid's pinned items keep. * * Both layouts are canonicalized before the diff (sorted by * `order ?? index` with `order` stripped, as the renderer and the * commit read them), so a move is a move whichever encoding expressed * it. Returns `next` itself when it was already canonical and nothing * was re-asserted. * * @param {EnforceLayoutPolicyArgs} args The layouts to diff and the policy. * @return {DashboardWidget[]} The incoming layout with denied changes re-asserted. */ export declare function enforceLayoutPolicy({ previous: rawPrevious, next: rawNext, canPerform, widgetTypes, }: EnforceLayoutPolicyArgs): DashboardWidget[]; export {}; //# sourceMappingURL=enforce-layout-policy.d.ts.map