UNPKG

@wordpress/widget-dashboard

Version:

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

99 lines • 4.04 kB
import type { ReactNode } from 'react'; import type { ResolveWidgetModule, WidgetType } from '@wordpress/widget-primitives'; import type { CanPerformDashboardOperation, WidgetGridSettings, DashboardWidget } from '../types'; type GridSettingsWithColumns = WidgetGridSettings & { columns: number; }; /** * Rich state distributed to every compound component inside `WidgetDashboard`. * Internal — compounds reach the full state via `useDashboardInternalContext()`. * * `layout`/`onLayoutChange` here operate on the staging layer, not the * committed props. Mutations from compound children stay in staging until * `commit` publishes them on the consumer. */ interface InternalDashboardContextValue { widgetTypes: WidgetType[]; isResolvingWidgetTypes: boolean; layout: DashboardWidget[]; onLayoutChange: (layout: DashboardWidget[]) => void; onLayoutReset?: () => void; gridSettings: GridSettingsWithColumns; /** * Publishes the staged layout when it differs from the committed * prop. By default also exits edit mode; pass `{ exitEditMode: false }` * for inline auto-saves that keep the current mode. */ commit: (options?: CommitOptions) => void; /** * Reverts the staged layout and exits edit mode. */ cancel: () => void; /** * Debounced auto-save for inline widget-instance edits. Controls call it * after staging a change; a single global timer publishes once the edits * settle. The settings drawer does not use it (it commits on Save). */ scheduleAutoSave: () => void; /** * Publishes any pending auto-save immediately. Called when leaving the * inline surface (opening the drawer, entering customize) so staged inline * edits do not commingle with the drawer's explicit-save flow. */ flushAutoSave: () => void; hasUncommittedChanges: boolean; editMode: boolean; onEditChange?: (next: boolean) => void; resolveWidgetModule: ResolveWidgetModule; /** * Resolved policy. Every compound asks here, never the policy provider, * so further policy sources compose at this single point. */ canPerform: CanPerformDashboardOperation; } interface CommitOptions { exitEditMode?: boolean; } /** * Compound-internal hook — exposes the full provider state. * Not part of the public API; lives in the same module * so compound components can reach the state directly. */ export declare function useDashboardInternalContext(): InternalDashboardContextValue; interface ProviderProps { widgetTypes: WidgetType[]; isResolvingWidgetTypes?: boolean; layout: DashboardWidget[]; /** * Fired on commit when the staged layout differs from `layout`. */ onLayoutChange: (layout: DashboardWidget[]) => void; /** * Optional reset action surfaced by the bundled `Actions`. */ onLayoutReset?: () => void; editMode?: boolean; onEditChange?: (next: boolean) => void; /** * Overrides the default `import()` resolution of * `WidgetType.renderModule`. */ resolveWidgetModule?: ResolveWidgetModule; gridSettings?: WidgetGridSettings; children: ReactNode; } /** * Provider for the dashboard's staging layer. Owns the staging copy of * `layout`; `commit` publishes it when it differs from the committed * prop, `cancel` reverts it. * * Staging re-syncs from the committed prop on prop change. In-flight * edits are dropped silently when an external update (cross-tab commit, * reset, websocket push) lands. Consumers that cannot tolerate this * loss should mediate the prop updates before forwarding them here. * * @param {ProviderProps} props Component props. */ export declare function WidgetDashboardProvider({ widgetTypes, isResolvingWidgetTypes, layout: committedLayout, onLayoutChange, onLayoutReset, editMode, onEditChange, resolveWidgetModule, gridSettings: committedGridSettings, children, }: ProviderProps): React.ReactNode; export {}; //# sourceMappingURL=dashboard-context.d.ts.map