@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
1 lines • 4.35 kB
Source Map (JSON)
{"version":3,"file":"widget-dashboard.mjs","names":[],"sources":["../src/widget-dashboard.tsx"],"sourcesContent":["import { WidgetDashboardProvider } from './context/dashboard-context';\nimport { WidgetDashboardUIProvider } from './context/ui-context';\nimport { Actions } from './components/actions';\nimport { Commands } from './components/commands';\nimport { NoWidgetsState } from './components/no-widgets-state';\nimport { ResetConfirmation } from './components/reset-confirmation';\nimport { WidgetChrome } from './components/widget-chrome';\nimport { WidgetInserter } from './components/widget-inserter';\nimport { WidgetDashboardPolicy } from './components/dashboard-policy';\nimport { WidgetSettings } from './components/widget-settings';\nimport { Widgets } from './components/widgets';\nimport type { WidgetDashboardProps } from './types';\n\n/**\n * Stateless rendering engine for widget dashboards.\n *\n * The consumer owns `layout` and `editMode` state; every mutation fires\n * `onLayoutChange` with the fully updated array. The engine never queries a\n * widget store; types flow in via the `widgetTypes` prop.\n *\n * ```tsx\n * import { WidgetDashboard } from '@wordpress/widget-dashboard';\n *\n * function MyDashboard() {\n * \tconst [ layout, setLayout ] = useState( defaultLayout );\n * \tconst [ editMode, setEditMode ] = useState( false );\n * \treturn (\n * \t\t<WidgetDashboard\n * \t\t\tlayout={ layout }\n * \t\t\tonLayoutChange={ setLayout }\n * \t\t\twidgetTypes={ widgetTypes }\n * \t\t\teditMode={ editMode }\n * \t\t\tonEditChange={ setEditMode }\n * \t\t>\n * \t\t\t<WidgetDashboard.NoWidgetsState>\n * \t\t\t\t<p>No widgets yet.</p>\n * \t\t\t</WidgetDashboard.NoWidgetsState>\n * \t\t\t<WidgetDashboard.Actions />\n * \t\t\t<WidgetDashboard.Widgets />\n * \t\t\t<WidgetDashboard.Commands />\n * \t\t</WidgetDashboard>\n * \t);\n * }\n * ```\n *\n * Children compose the dashboard's triggers and chrome: `Actions`,\n * `Widgets`, `Commands`, `NoWidgetsState`. The targets they open (the\n * widget inserter, the widget settings editor, the reset confirmation) are\n * mounted by the engine and driven by shared UI state, so a trigger works\n * wherever it is composed without a matching target in the tree. Omitting\n * `children` renders the default arrangement.\n *\n * `Policy` mounts above one or several dashboards and governs what users\n * may do on them; every compound asks the resolved policy through the\n * internal context.\n */\nexport const WidgetDashboard = Object.assign(\n\tfunction WidgetDashboardRoot( {\n\t\tlayout,\n\t\tonLayoutChange,\n\t\tonLayoutReset,\n\t\twidgetTypes,\n\t\tisResolvingWidgetTypes,\n\t\teditMode,\n\t\tonEditChange,\n\t\tresolveWidgetModule,\n\t\tgridSettings,\n\t\tchildren,\n\t}: WidgetDashboardProps ) {\n\t\treturn (\n\t\t\t<WidgetDashboardProvider\n\t\t\t\tlayout={ layout }\n\t\t\t\tonLayoutChange={ onLayoutChange }\n\t\t\t\tonLayoutReset={ onLayoutReset }\n\t\t\t\twidgetTypes={ widgetTypes }\n\t\t\t\tisResolvingWidgetTypes={ isResolvingWidgetTypes }\n\t\t\t\teditMode={ editMode }\n\t\t\t\tonEditChange={ onEditChange }\n\t\t\t\tresolveWidgetModule={ resolveWidgetModule }\n\t\t\t\tgridSettings={ gridSettings }\n\t\t\t>\n\t\t\t\t<WidgetDashboardUIProvider>\n\t\t\t\t\t{ children ?? (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<NoWidgetsState />\n\t\t\t\t\t\t\t<Actions />\n\t\t\t\t\t\t\t<Widgets />\n\t\t\t\t\t\t\t<Commands />\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\n\t\t\t\t\t<WidgetInserter />\n\t\t\t\t\t<WidgetSettings />\n\t\t\t\t\t<ResetConfirmation />\n\t\t\t\t</WidgetDashboardUIProvider>\n\t\t\t</WidgetDashboardProvider>\n\t\t);\n\t},\n\t{\n\t\tActions,\n\t\tWidgets,\n\t\tWidgetChrome,\n\t\tNoWidgetsState,\n\t\tCommands,\n\t\tPolicy: WidgetDashboardPolicy,\n\t}\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,MAAa,kBAAkB,OAAO,OACrC,SAAS,oBAAqB,EAC7B,QACA,gBACA,eACA,aACA,wBACA,UACA,cACA,qBACA,cACA,YACyB;CACzB,OACC,oBAAC,yBAAD;EACU;EACQ;EACD;EACF;EACW;EACd;EACI;EACO;EACP;EAEf,UAAA,qBAAC,2BAAD,EAAA,UAAA;GACG,YACD,qBAAA,UAAA,EAAA,UAAA;IACC,oBAAC,gBAAD,CAAiB,CAAA;IACjB,oBAAC,SAAD,CAAU,CAAA;IACV,oBAAC,SAAD,CAAU,CAAA;IACV,oBAAC,UAAD,CAAW,CAAA;GACV,EAAA,CAAA;GAGH,oBAAC,gBAAD,CAAiB,CAAA;GACjB,oBAAC,gBAAD,CAAiB,CAAA;GACjB,oBAAC,mBAAD,CAAoB,CAAA;EACM,EAAA,CAAA;CACH,CAAA;AAE3B,GACA;CACC;CACA;CACA;CACA;CACA;CACA,QAAQ;AACT,CACD"}