@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
95 lines (94 loc) • 4.58 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let __context_dashboard_context_tsx = require("./context/dashboard-context.cjs");
let __context_ui_context_tsx = require("./context/ui-context.cjs");
let __components_actions_index_ts = require("./components/actions/index.cjs");
let __components_commands_index_ts = require("./components/commands/index.cjs");
let __components_no_widgets_state_index_ts = require("./components/no-widgets-state/index.cjs");
let __components_reset_confirmation_index_ts = require("./components/reset-confirmation/index.cjs");
let __components_widget_chrome_index_ts = require("./components/widget-chrome/index.cjs");
let __components_widget_inserter_index_ts = require("./components/widget-inserter/index.cjs");
let __components_dashboard_policy_index_ts = require("./components/dashboard-policy/index.cjs");
let __components_widget_settings_index_ts = require("./components/widget-settings/index.cjs");
let __components_widgets_index_ts = require("./components/widgets/index.cjs");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/widget-dashboard/src/widget-dashboard.tsx
/**
* Stateless rendering engine for widget dashboards.
*
* The consumer owns `layout` and `editMode` state; every mutation fires
* `onLayoutChange` with the fully updated array. The engine never queries a
* widget store; types flow in via the `widgetTypes` prop.
*
* ```tsx
* import { WidgetDashboard } from '@wordpress/widget-dashboard';
*
* function MyDashboard() {
* const [ layout, setLayout ] = useState( defaultLayout );
* const [ editMode, setEditMode ] = useState( false );
* return (
* <WidgetDashboard
* layout={ layout }
* onLayoutChange={ setLayout }
* widgetTypes={ widgetTypes }
* editMode={ editMode }
* onEditChange={ setEditMode }
* >
* <WidgetDashboard.NoWidgetsState>
* <p>No widgets yet.</p>
* </WidgetDashboard.NoWidgetsState>
* <WidgetDashboard.Actions />
* <WidgetDashboard.Widgets />
* <WidgetDashboard.Commands />
* </WidgetDashboard>
* );
* }
* ```
*
* Children compose the dashboard's triggers and chrome: `Actions`,
* `Widgets`, `Commands`, `NoWidgetsState`. The targets they open (the
* widget inserter, the widget settings editor, the reset confirmation) are
* mounted by the engine and driven by shared UI state, so a trigger works
* wherever it is composed without a matching target in the tree. Omitting
* `children` renders the default arrangement.
*
* `Policy` mounts above one or several dashboards and governs what users
* may do on them; every compound asks the resolved policy through the
* internal context.
*/
const WidgetDashboard = Object.assign(function WidgetDashboardRoot({ layout, onLayoutChange, onLayoutReset, widgetTypes, isResolvingWidgetTypes, editMode, onEditChange, resolveWidgetModule, gridSettings, children }) {
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__context_dashboard_context_tsx.WidgetDashboardProvider, {
layout,
onLayoutChange,
onLayoutReset,
widgetTypes,
isResolvingWidgetTypes,
editMode,
onEditChange,
resolveWidgetModule,
gridSettings,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__context_ui_context_tsx.WidgetDashboardUIProvider, { children: [
children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__components_no_widgets_state_index_ts.NoWidgetsState, {}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__components_actions_index_ts.Actions, {}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__components_widgets_index_ts.Widgets, {}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__components_commands_index_ts.Commands, {})
] }),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__components_widget_inserter_index_ts.WidgetInserter, {}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__components_widget_settings_index_ts.WidgetSettings, {}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__components_reset_confirmation_index_ts.ResetConfirmation, {})
] })
});
}, {
Actions: __components_actions_index_ts.Actions,
Widgets: __components_widgets_index_ts.Widgets,
WidgetChrome: __components_widget_chrome_index_ts.WidgetChrome,
NoWidgetsState: __components_no_widgets_state_index_ts.NoWidgetsState,
Commands: __components_commands_index_ts.Commands,
Policy: __components_dashboard_policy_index_ts.WidgetDashboardPolicy
});
exports.WidgetDashboard = WidgetDashboard;
//# sourceMappingURL=widget-dashboard.cjs.map