@wordpress/widget-dashboard 0.1.1-next.v.202606191442.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/LICENSE.md +788 -0
- package/README.md +241 -0
- package/build/components/actions/actions.cjs +265 -0
- package/build/components/actions/actions.cjs.map +7 -0
- package/build/components/actions/index.cjs +31 -0
- package/build/components/actions/index.cjs.map +7 -0
- package/build/components/actions-menu/actions-menu.cjs +92 -0
- package/build/components/actions-menu/actions-menu.cjs.map +7 -0
- package/build/components/actions-menu/index.cjs +31 -0
- package/build/components/actions-menu/index.cjs.map +7 -0
- package/build/components/commands/commands.cjs +177 -0
- package/build/components/commands/commands.cjs.map +7 -0
- package/build/components/commands/index.cjs +33 -0
- package/build/components/commands/index.cjs.map +7 -0
- package/build/components/commands/use-pending-when-edit-mode.cjs +57 -0
- package/build/components/commands/use-pending-when-edit-mode.cjs.map +7 -0
- package/build/components/layout-settings/index.cjs +31 -0
- package/build/components/layout-settings/index.cjs.map +7 -0
- package/build/components/layout-settings/layout-model-edit-field/index.cjs +186 -0
- package/build/components/layout-settings/layout-model-edit-field/index.cjs.map +7 -0
- package/build/components/layout-settings/layout-model-edit-field/thumbnail-grid.cjs +53 -0
- package/build/components/layout-settings/layout-model-edit-field/thumbnail-grid.cjs.map +7 -0
- package/build/components/layout-settings/layout-model-edit-field/thumbnail-masonry.cjs +53 -0
- package/build/components/layout-settings/layout-model-edit-field/thumbnail-masonry.cjs.map +7 -0
- package/build/components/layout-settings/layout-settings.cjs +207 -0
- package/build/components/layout-settings/layout-settings.cjs.map +7 -0
- package/build/components/no-widgets-state/index.cjs +31 -0
- package/build/components/no-widgets-state/index.cjs.map +7 -0
- package/build/components/no-widgets-state/no-widgets-state.cjs +140 -0
- package/build/components/no-widgets-state/no-widgets-state.cjs.map +7 -0
- package/build/components/reset-confirmation/index.cjs +31 -0
- package/build/components/reset-confirmation/index.cjs.map +7 -0
- package/build/components/reset-confirmation/reset-confirmation.cjs +62 -0
- package/build/components/reset-confirmation/reset-confirmation.cjs.map +7 -0
- package/build/components/widget-chrome/index.cjs +31 -0
- package/build/components/widget-chrome/index.cjs.map +7 -0
- package/build/components/widget-chrome/widget-chrome.cjs +277 -0
- package/build/components/widget-chrome/widget-chrome.cjs.map +7 -0
- package/build/components/widget-inserter/index.cjs +31 -0
- package/build/components/widget-inserter/index.cjs.map +7 -0
- package/build/components/widget-inserter/widget-inserter.cjs +78 -0
- package/build/components/widget-inserter/widget-inserter.cjs.map +7 -0
- package/build/components/widget-picker/index.cjs +31 -0
- package/build/components/widget-picker/index.cjs.map +7 -0
- package/build/components/widget-picker/widget-picker.cjs +209 -0
- package/build/components/widget-picker/widget-picker.cjs.map +7 -0
- package/build/components/widget-render/index.cjs +31 -0
- package/build/components/widget-render/index.cjs.map +7 -0
- package/build/components/widget-render/widget-render.cjs +62 -0
- package/build/components/widget-render/widget-render.cjs.map +7 -0
- package/build/components/widget-settings/index.cjs +37 -0
- package/build/components/widget-settings/index.cjs.map +7 -0
- package/build/components/widget-settings/utils/get-admin-menu-inset.cjs +41 -0
- package/build/components/widget-settings/utils/get-admin-menu-inset.cjs.map +7 -0
- package/build/components/widget-settings/utils/get-widget-settings.cjs +38 -0
- package/build/components/widget-settings/utils/get-widget-settings.cjs.map +7 -0
- package/build/components/widget-settings/utils/index.cjs +34 -0
- package/build/components/widget-settings/utils/index.cjs.map +7 -0
- package/build/components/widget-settings/widget-settings-toolbar.cjs +138 -0
- package/build/components/widget-settings/widget-settings-toolbar.cjs.map +7 -0
- package/build/components/widget-settings/widget-settings-trigger.cjs +82 -0
- package/build/components/widget-settings/widget-settings-trigger.cjs.map +7 -0
- package/build/components/widget-settings/widget-settings.cjs +269 -0
- package/build/components/widget-settings/widget-settings.cjs.map +7 -0
- package/build/components/widget-toolbar/index.cjs +31 -0
- package/build/components/widget-toolbar/index.cjs.map +7 -0
- package/build/components/widget-toolbar/widget-toolbar.cjs +148 -0
- package/build/components/widget-toolbar/widget-toolbar.cjs.map +7 -0
- package/build/components/widgets/index.cjs +31 -0
- package/build/components/widgets/index.cjs.map +7 -0
- package/build/components/widgets/widget-layout-toolbar.cjs +206 -0
- package/build/components/widgets/widget-layout-toolbar.cjs.map +7 -0
- package/build/components/widgets/widget-resize-handle.cjs +163 -0
- package/build/components/widgets/widget-resize-handle.cjs.map +7 -0
- package/build/components/widgets/widgets.cjs +277 -0
- package/build/components/widgets/widgets.cjs.map +7 -0
- package/build/context/dashboard-context.cjs +234 -0
- package/build/context/dashboard-context.cjs.map +7 -0
- package/build/context/ui-context.cjs +77 -0
- package/build/context/ui-context.cjs.map +7 -0
- package/build/context/widget-context.cjs +44 -0
- package/build/context/widget-context.cjs.map +7 -0
- package/build/hooks/use-dashboard-container-column-count.cjs +61 -0
- package/build/hooks/use-dashboard-container-column-count.cjs.map +7 -0
- package/build/index.cjs +45 -0
- package/build/index.cjs.map +7 -0
- package/build/lock-unlock.cjs +37 -0
- package/build/lock-unlock.cjs.map +7 -0
- package/build/types.cjs +31 -0
- package/build/types.cjs.map +7 -0
- package/build/utils/create-dashboard-widget/create-dashboard-widget.cjs +44 -0
- package/build/utils/create-dashboard-widget/create-dashboard-widget.cjs.map +7 -0
- package/build/utils/create-dashboard-widget/index.cjs +31 -0
- package/build/utils/create-dashboard-widget/index.cjs.map +7 -0
- package/build/utils/default-grid/default-grid.cjs +37 -0
- package/build/utils/default-grid/default-grid.cjs.map +7 -0
- package/build/utils/default-grid/index.cjs +31 -0
- package/build/utils/default-grid/index.cjs.map +7 -0
- package/build/utils/grid-model-change/grid-model-change.cjs +56 -0
- package/build/utils/grid-model-change/grid-model-change.cjs.map +7 -0
- package/build/utils/grid-model-change/index.cjs +33 -0
- package/build/utils/grid-model-change/index.cjs.map +7 -0
- package/build/utils/index.cjs +34 -0
- package/build/utils/index.cjs.map +7 -0
- package/build/utils/migrate-layout/index.cjs +31 -0
- package/build/utils/migrate-layout/index.cjs.map +7 -0
- package/build/utils/migrate-layout/migrate-layout.cjs +94 -0
- package/build/utils/migrate-layout/migrate-layout.cjs.map +7 -0
- package/build/utils/normalize-grid-settings/index.cjs +31 -0
- package/build/utils/normalize-grid-settings/index.cjs.map +7 -0
- package/build/utils/normalize-grid-settings/normalize-grid-settings.cjs +46 -0
- package/build/utils/normalize-grid-settings/normalize-grid-settings.cjs.map +7 -0
- package/build/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.cjs +49 -0
- package/build/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.cjs.map +7 -0
- package/build/utils/row-height-presets/index.cjs +39 -0
- package/build/utils/row-height-presets/index.cjs.map +7 -0
- package/build/utils/row-height-presets/row-height-presets.cjs +63 -0
- package/build/utils/row-height-presets/row-height-presets.cjs.map +7 -0
- package/build/widget-dashboard.cjs +86 -0
- package/build/widget-dashboard.cjs.map +7 -0
- package/build/wordpress-commands.d.cjs +2 -0
- package/build/wordpress-commands.d.cjs.map +7 -0
- package/build-module/components/actions/actions.mjs +240 -0
- package/build-module/components/actions/actions.mjs.map +7 -0
- package/build-module/components/actions/index.mjs +6 -0
- package/build-module/components/actions/index.mjs.map +7 -0
- package/build-module/components/actions-menu/actions-menu.mjs +67 -0
- package/build-module/components/actions-menu/actions-menu.mjs.map +7 -0
- package/build-module/components/actions-menu/index.mjs +6 -0
- package/build-module/components/actions-menu/index.mjs.map +7 -0
- package/build-module/components/commands/commands.mjs +160 -0
- package/build-module/components/commands/commands.mjs.map +7 -0
- package/build-module/components/commands/index.mjs +7 -0
- package/build-module/components/commands/index.mjs.map +7 -0
- package/build-module/components/commands/use-pending-when-edit-mode.mjs +32 -0
- package/build-module/components/commands/use-pending-when-edit-mode.mjs.map +7 -0
- package/build-module/components/layout-settings/index.mjs +6 -0
- package/build-module/components/layout-settings/index.mjs.map +7 -0
- package/build-module/components/layout-settings/layout-model-edit-field/index.mjs +151 -0
- package/build-module/components/layout-settings/layout-model-edit-field/index.mjs.map +7 -0
- package/build-module/components/layout-settings/layout-model-edit-field/thumbnail-grid.mjs +28 -0
- package/build-module/components/layout-settings/layout-model-edit-field/thumbnail-grid.mjs.map +7 -0
- package/build-module/components/layout-settings/layout-model-edit-field/thumbnail-masonry.mjs +28 -0
- package/build-module/components/layout-settings/layout-model-edit-field/thumbnail-masonry.mjs.map +7 -0
- package/build-module/components/layout-settings/layout-settings.mjs +187 -0
- package/build-module/components/layout-settings/layout-settings.mjs.map +7 -0
- package/build-module/components/no-widgets-state/index.mjs +6 -0
- package/build-module/components/no-widgets-state/index.mjs.map +7 -0
- package/build-module/components/no-widgets-state/no-widgets-state.mjs +115 -0
- package/build-module/components/no-widgets-state/no-widgets-state.mjs.map +7 -0
- package/build-module/components/reset-confirmation/index.mjs +6 -0
- package/build-module/components/reset-confirmation/index.mjs.map +7 -0
- package/build-module/components/reset-confirmation/reset-confirmation.mjs +37 -0
- package/build-module/components/reset-confirmation/reset-confirmation.mjs.map +7 -0
- package/build-module/components/widget-chrome/index.mjs +6 -0
- package/build-module/components/widget-chrome/index.mjs.map +7 -0
- package/build-module/components/widget-chrome/widget-chrome.mjs +248 -0
- package/build-module/components/widget-chrome/widget-chrome.mjs.map +7 -0
- package/build-module/components/widget-inserter/index.mjs +6 -0
- package/build-module/components/widget-inserter/index.mjs.map +7 -0
- package/build-module/components/widget-inserter/widget-inserter.mjs +53 -0
- package/build-module/components/widget-inserter/widget-inserter.mjs.map +7 -0
- package/build-module/components/widget-picker/index.mjs +6 -0
- package/build-module/components/widget-picker/index.mjs.map +7 -0
- package/build-module/components/widget-picker/widget-picker.mjs +184 -0
- package/build-module/components/widget-picker/widget-picker.mjs.map +7 -0
- package/build-module/components/widget-render/index.mjs +6 -0
- package/build-module/components/widget-render/index.mjs.map +7 -0
- package/build-module/components/widget-render/widget-render.mjs +37 -0
- package/build-module/components/widget-render/widget-render.mjs.map +7 -0
- package/build-module/components/widget-settings/index.mjs +10 -0
- package/build-module/components/widget-settings/index.mjs.map +7 -0
- package/build-module/components/widget-settings/utils/get-admin-menu-inset.mjs +16 -0
- package/build-module/components/widget-settings/utils/get-admin-menu-inset.mjs.map +7 -0
- package/build-module/components/widget-settings/utils/get-widget-settings.mjs +13 -0
- package/build-module/components/widget-settings/utils/get-widget-settings.mjs.map +7 -0
- package/build-module/components/widget-settings/utils/index.mjs +8 -0
- package/build-module/components/widget-settings/utils/index.mjs.map +7 -0
- package/build-module/components/widget-settings/widget-settings-toolbar.mjs +113 -0
- package/build-module/components/widget-settings/widget-settings-toolbar.mjs.map +7 -0
- package/build-module/components/widget-settings/widget-settings-trigger.mjs +57 -0
- package/build-module/components/widget-settings/widget-settings-trigger.mjs.map +7 -0
- package/build-module/components/widget-settings/widget-settings.mjs +244 -0
- package/build-module/components/widget-settings/widget-settings.mjs.map +7 -0
- package/build-module/components/widget-toolbar/index.mjs +6 -0
- package/build-module/components/widget-toolbar/index.mjs.map +7 -0
- package/build-module/components/widget-toolbar/widget-toolbar.mjs +113 -0
- package/build-module/components/widget-toolbar/widget-toolbar.mjs.map +7 -0
- package/build-module/components/widgets/index.mjs +6 -0
- package/build-module/components/widgets/index.mjs.map +7 -0
- package/build-module/components/widgets/widget-layout-toolbar.mjs +181 -0
- package/build-module/components/widgets/widget-layout-toolbar.mjs.map +7 -0
- package/build-module/components/widgets/widget-resize-handle.mjs +128 -0
- package/build-module/components/widgets/widget-resize-handle.mjs.map +7 -0
- package/build-module/components/widgets/widgets.mjs +242 -0
- package/build-module/components/widgets/widgets.mjs.map +7 -0
- package/build-module/context/dashboard-context.mjs +205 -0
- package/build-module/context/dashboard-context.mjs.map +7 -0
- package/build-module/context/ui-context.mjs +56 -0
- package/build-module/context/ui-context.mjs.map +7 -0
- package/build-module/context/widget-context.mjs +18 -0
- package/build-module/context/widget-context.mjs.map +7 -0
- package/build-module/hooks/use-dashboard-container-column-count.mjs +40 -0
- package/build-module/hooks/use-dashboard-container-column-count.mjs.map +7 -0
- package/build-module/index.mjs +18 -0
- package/build-module/index.mjs.map +7 -0
- package/build-module/lock-unlock.mjs +11 -0
- package/build-module/lock-unlock.mjs.map +7 -0
- package/build-module/types.mjs +6 -0
- package/build-module/types.mjs.map +7 -0
- package/build-module/utils/create-dashboard-widget/create-dashboard-widget.mjs +19 -0
- package/build-module/utils/create-dashboard-widget/create-dashboard-widget.mjs.map +7 -0
- package/build-module/utils/create-dashboard-widget/index.mjs +6 -0
- package/build-module/utils/create-dashboard-widget/index.mjs.map +7 -0
- package/build-module/utils/default-grid/default-grid.mjs +12 -0
- package/build-module/utils/default-grid/default-grid.mjs.map +7 -0
- package/build-module/utils/default-grid/index.mjs +6 -0
- package/build-module/utils/default-grid/index.mjs.map +7 -0
- package/build-module/utils/grid-model-change/grid-model-change.mjs +30 -0
- package/build-module/utils/grid-model-change/grid-model-change.mjs.map +7 -0
- package/build-module/utils/grid-model-change/index.mjs +7 -0
- package/build-module/utils/grid-model-change/index.mjs.map +7 -0
- package/build-module/utils/index.mjs +8 -0
- package/build-module/utils/index.mjs.map +7 -0
- package/build-module/utils/migrate-layout/index.mjs +6 -0
- package/build-module/utils/migrate-layout/index.mjs.map +7 -0
- package/build-module/utils/migrate-layout/migrate-layout.mjs +69 -0
- package/build-module/utils/migrate-layout/migrate-layout.mjs.map +7 -0
- package/build-module/utils/normalize-grid-settings/index.mjs +6 -0
- package/build-module/utils/normalize-grid-settings/index.mjs.map +7 -0
- package/build-module/utils/normalize-grid-settings/normalize-grid-settings.mjs +21 -0
- package/build-module/utils/normalize-grid-settings/normalize-grid-settings.mjs.map +7 -0
- package/build-module/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.mjs +22 -0
- package/build-module/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.mjs.map +7 -0
- package/build-module/utils/row-height-presets/index.mjs +16 -0
- package/build-module/utils/row-height-presets/index.mjs.map +7 -0
- package/build-module/utils/row-height-presets/row-height-presets.mjs +34 -0
- package/build-module/utils/row-height-presets/row-height-presets.mjs.map +7 -0
- package/build-module/widget-dashboard.mjs +61 -0
- package/build-module/widget-dashboard.mjs.map +7 -0
- package/build-module/wordpress-commands.d.mjs +1 -0
- package/build-module/wordpress-commands.d.mjs.map +7 -0
- package/build-types/components/actions/actions.d.ts +11 -0
- package/build-types/components/actions/actions.d.ts.map +1 -0
- package/build-types/components/actions/index.d.ts +2 -0
- package/build-types/components/actions/index.d.ts.map +1 -0
- package/build-types/components/actions-menu/actions-menu.d.ts +22 -0
- package/build-types/components/actions-menu/actions-menu.d.ts.map +1 -0
- package/build-types/components/actions-menu/index.d.ts +3 -0
- package/build-types/components/actions-menu/index.d.ts.map +1 -0
- package/build-types/components/commands/commands.d.ts +7 -0
- package/build-types/components/commands/commands.d.ts.map +1 -0
- package/build-types/components/commands/index.d.ts +2 -0
- package/build-types/components/commands/index.d.ts.map +1 -0
- package/build-types/components/commands/use-pending-when-edit-mode.d.ts +15 -0
- package/build-types/components/commands/use-pending-when-edit-mode.d.ts.map +1 -0
- package/build-types/components/layout-settings/index.d.ts +2 -0
- package/build-types/components/layout-settings/index.d.ts.map +1 -0
- package/build-types/components/layout-settings/layout-model-edit-field/index.d.ts +17 -0
- package/build-types/components/layout-settings/layout-model-edit-field/index.d.ts.map +1 -0
- package/build-types/components/layout-settings/layout-model-edit-field/thumbnail-grid.d.ts +6 -0
- package/build-types/components/layout-settings/layout-model-edit-field/thumbnail-grid.d.ts.map +1 -0
- package/build-types/components/layout-settings/layout-model-edit-field/thumbnail-masonry.d.ts +6 -0
- package/build-types/components/layout-settings/layout-model-edit-field/thumbnail-masonry.d.ts.map +1 -0
- package/build-types/components/layout-settings/layout-settings.d.ts +14 -0
- package/build-types/components/layout-settings/layout-settings.d.ts.map +1 -0
- package/build-types/components/no-widgets-state/index.d.ts +2 -0
- package/build-types/components/no-widgets-state/index.d.ts.map +1 -0
- package/build-types/components/no-widgets-state/no-widgets-state.d.ts +17 -0
- package/build-types/components/no-widgets-state/no-widgets-state.d.ts.map +1 -0
- package/build-types/components/reset-confirmation/index.d.ts +2 -0
- package/build-types/components/reset-confirmation/index.d.ts.map +1 -0
- package/build-types/components/reset-confirmation/reset-confirmation.d.ts +8 -0
- package/build-types/components/reset-confirmation/reset-confirmation.d.ts.map +1 -0
- package/build-types/components/widget-chrome/index.d.ts +2 -0
- package/build-types/components/widget-chrome/index.d.ts.map +1 -0
- package/build-types/components/widget-chrome/widget-chrome.d.ts +22 -0
- package/build-types/components/widget-chrome/widget-chrome.d.ts.map +1 -0
- package/build-types/components/widget-inserter/index.d.ts +2 -0
- package/build-types/components/widget-inserter/index.d.ts.map +1 -0
- package/build-types/components/widget-inserter/widget-inserter.d.ts +7 -0
- package/build-types/components/widget-inserter/widget-inserter.d.ts.map +1 -0
- package/build-types/components/widget-picker/index.d.ts +2 -0
- package/build-types/components/widget-picker/index.d.ts.map +1 -0
- package/build-types/components/widget-picker/widget-picker.d.ts +26 -0
- package/build-types/components/widget-picker/widget-picker.d.ts.map +1 -0
- package/build-types/components/widget-render/index.d.ts +2 -0
- package/build-types/components/widget-render/index.d.ts.map +1 -0
- package/build-types/components/widget-render/widget-render.d.ts +17 -0
- package/build-types/components/widget-render/widget-render.d.ts.map +1 -0
- package/build-types/components/widget-settings/index.d.ts +5 -0
- package/build-types/components/widget-settings/index.d.ts.map +1 -0
- package/build-types/components/widget-settings/utils/get-admin-menu-inset.d.ts +17 -0
- package/build-types/components/widget-settings/utils/get-admin-menu-inset.d.ts.map +1 -0
- package/build-types/components/widget-settings/utils/get-widget-settings.d.ts +10 -0
- package/build-types/components/widget-settings/utils/get-widget-settings.d.ts.map +1 -0
- package/build-types/components/widget-settings/utils/index.d.ts +3 -0
- package/build-types/components/widget-settings/utils/index.d.ts.map +1 -0
- package/build-types/components/widget-settings/widget-settings-toolbar.d.ts +20 -0
- package/build-types/components/widget-settings/widget-settings-toolbar.d.ts.map +1 -0
- package/build-types/components/widget-settings/widget-settings-trigger.d.ts +23 -0
- package/build-types/components/widget-settings/widget-settings-trigger.d.ts.map +1 -0
- package/build-types/components/widget-settings/widget-settings.d.ts +13 -0
- package/build-types/components/widget-settings/widget-settings.d.ts.map +1 -0
- package/build-types/components/widget-toolbar/index.d.ts +3 -0
- package/build-types/components/widget-toolbar/index.d.ts.map +1 -0
- package/build-types/components/widget-toolbar/widget-toolbar.d.ts +16 -0
- package/build-types/components/widget-toolbar/widget-toolbar.d.ts.map +1 -0
- package/build-types/components/widgets/index.d.ts +2 -0
- package/build-types/components/widgets/index.d.ts.map +1 -0
- package/build-types/components/widgets/widget-layout-toolbar.d.ts +14 -0
- package/build-types/components/widgets/widget-layout-toolbar.d.ts.map +1 -0
- package/build-types/components/widgets/widget-resize-handle.d.ts +12 -0
- package/build-types/components/widgets/widget-resize-handle.d.ts.map +1 -0
- package/build-types/components/widgets/widgets.d.ts +10 -0
- package/build-types/components/widgets/widgets.d.ts.map +1 -0
- package/build-types/context/dashboard-context.d.ts +111 -0
- package/build-types/context/dashboard-context.d.ts.map +1 -0
- package/build-types/context/ui-context.d.ts +54 -0
- package/build-types/context/ui-context.d.ts.map +1 -0
- package/build-types/context/widget-context.d.ts +25 -0
- package/build-types/context/widget-context.d.ts.map +1 -0
- package/build-types/hooks/use-dashboard-container-column-count.d.ts +15 -0
- package/build-types/hooks/use-dashboard-container-column-count.d.ts.map +1 -0
- package/build-types/index.d.ts +7 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/lock-unlock.d.ts +2 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/types.d.ts +222 -0
- package/build-types/types.d.ts.map +1 -0
- package/build-types/utils/create-dashboard-widget/create-dashboard-widget.d.ts +20 -0
- package/build-types/utils/create-dashboard-widget/create-dashboard-widget.d.ts.map +1 -0
- package/build-types/utils/create-dashboard-widget/index.d.ts +2 -0
- package/build-types/utils/create-dashboard-widget/index.d.ts.map +1 -0
- package/build-types/utils/default-grid/default-grid.d.ts +11 -0
- package/build-types/utils/default-grid/default-grid.d.ts.map +1 -0
- package/build-types/utils/default-grid/index.d.ts +2 -0
- package/build-types/utils/default-grid/index.d.ts.map +1 -0
- package/build-types/utils/grid-model-change/grid-model-change.d.ts +20 -0
- package/build-types/utils/grid-model-change/grid-model-change.d.ts.map +1 -0
- package/build-types/utils/grid-model-change/index.d.ts +2 -0
- package/build-types/utils/grid-model-change/index.d.ts.map +1 -0
- package/build-types/utils/index.d.ts +3 -0
- package/build-types/utils/index.d.ts.map +1 -0
- package/build-types/utils/migrate-layout/index.d.ts +2 -0
- package/build-types/utils/migrate-layout/index.d.ts.map +1 -0
- package/build-types/utils/migrate-layout/migrate-layout.d.ts +36 -0
- package/build-types/utils/migrate-layout/migrate-layout.d.ts.map +1 -0
- package/build-types/utils/normalize-grid-settings/index.d.ts +2 -0
- package/build-types/utils/normalize-grid-settings/index.d.ts.map +1 -0
- package/build-types/utils/normalize-grid-settings/normalize-grid-settings.d.ts +11 -0
- package/build-types/utils/normalize-grid-settings/normalize-grid-settings.d.ts.map +1 -0
- package/build-types/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.d.ts +21 -0
- package/build-types/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.d.ts.map +1 -0
- package/build-types/utils/row-height-presets/index.d.ts +3 -0
- package/build-types/utils/row-height-presets/index.d.ts.map +1 -0
- package/build-types/utils/row-height-presets/row-height-presets.d.ts +17 -0
- package/build-types/utils/row-height-presets/row-height-presets.d.ts.map +1 -0
- package/build-types/widget-dashboard.d.ts +51 -0
- package/build-types/widget-dashboard.d.ts.map +1 -0
- package/package.json +90 -0
- package/src/components/actions/actions.module.css +54 -0
- package/src/components/actions/actions.tsx +180 -0
- package/src/components/actions/index.ts +1 -0
- package/src/components/actions-menu/actions-menu.tsx +104 -0
- package/src/components/actions-menu/index.ts +2 -0
- package/src/components/commands/commands.tsx +182 -0
- package/src/components/commands/index.ts +1 -0
- package/src/components/commands/use-pending-when-edit-mode.ts +48 -0
- package/src/components/layout-settings/index.ts +1 -0
- package/src/components/layout-settings/layout-model-edit-field/index.tsx +98 -0
- package/src/components/layout-settings/layout-model-edit-field/style.module.css +34 -0
- package/src/components/layout-settings/layout-model-edit-field/thumbnail-grid.tsx +28 -0
- package/src/components/layout-settings/layout-model-edit-field/thumbnail-masonry.tsx +28 -0
- package/src/components/layout-settings/layout-settings.tsx +217 -0
- package/src/components/no-widgets-state/index.ts +1 -0
- package/src/components/no-widgets-state/no-widgets-state.module.css +3 -0
- package/src/components/no-widgets-state/no-widgets-state.tsx +56 -0
- package/src/components/reset-confirmation/index.ts +1 -0
- package/src/components/reset-confirmation/reset-confirmation.tsx +44 -0
- package/src/components/widget-chrome/index.ts +1 -0
- package/src/components/widget-chrome/widget-chrome.module.css +87 -0
- package/src/components/widget-chrome/widget-chrome.tsx +255 -0
- package/src/components/widget-inserter/index.ts +1 -0
- package/src/components/widget-inserter/widget-inserter.tsx +70 -0
- package/src/components/widget-picker/index.ts +1 -0
- package/src/components/widget-picker/widget-picker.module.css +11 -0
- package/src/components/widget-picker/widget-picker.tsx +137 -0
- package/src/components/widget-render/index.ts +1 -0
- package/src/components/widget-render/widget-render.tsx +58 -0
- package/src/components/widget-settings/index.ts +4 -0
- package/src/components/widget-settings/utils/get-admin-menu-inset.ts +30 -0
- package/src/components/widget-settings/utils/get-widget-settings.ts +22 -0
- package/src/components/widget-settings/utils/index.ts +2 -0
- package/src/components/widget-settings/widget-settings-toolbar.module.css +25 -0
- package/src/components/widget-settings/widget-settings-toolbar.tsx +45 -0
- package/src/components/widget-settings/widget-settings-trigger.tsx +96 -0
- package/src/components/widget-settings/widget-settings.module.css +8 -0
- package/src/components/widget-settings/widget-settings.tsx +200 -0
- package/src/components/widget-toolbar/index.ts +2 -0
- package/src/components/widget-toolbar/widget-toolbar.module.css +12 -0
- package/src/components/widget-toolbar/widget-toolbar.tsx +46 -0
- package/src/components/widgets/index.ts +1 -0
- package/src/components/widgets/widget-layout-toolbar.module.css +6 -0
- package/src/components/widgets/widget-layout-toolbar.tsx +118 -0
- package/src/components/widgets/widget-resize-handle.module.css +135 -0
- package/src/components/widgets/widget-resize-handle.tsx +60 -0
- package/src/components/widgets/widgets.module.css +43 -0
- package/src/components/widgets/widgets.tsx +208 -0
- package/src/context/dashboard-context.tsx +386 -0
- package/src/context/ui-context.tsx +118 -0
- package/src/context/widget-context.tsx +45 -0
- package/src/hooks/use-dashboard-container-column-count.ts +63 -0
- package/src/index.ts +9 -0
- package/src/lock-unlock.ts +10 -0
- package/src/test/actions.test.tsx +226 -0
- package/src/test/commands.test.tsx +176 -0
- package/src/test/create-dashboard-widget.test.ts +59 -0
- package/src/test/dashboard-context.test.tsx +26 -0
- package/src/test/staging.test.tsx +476 -0
- package/src/test/widget-dashboard.test.tsx +204 -0
- package/src/test/widget-inserter.test.tsx +210 -0
- package/src/test/widget-settings.test.tsx +199 -0
- package/src/types.ts +260 -0
- package/src/utils/create-dashboard-widget/create-dashboard-widget.ts +43 -0
- package/src/utils/create-dashboard-widget/index.ts +1 -0
- package/src/utils/default-grid/default-grid.ts +17 -0
- package/src/utils/default-grid/index.ts +1 -0
- package/src/utils/grid-model-change/grid-model-change.ts +53 -0
- package/src/utils/grid-model-change/index.ts +1 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/migrate-layout/index.ts +1 -0
- package/src/utils/migrate-layout/migrate-layout.ts +156 -0
- package/src/utils/migrate-layout/test/migrate-layout.test.ts +114 -0
- package/src/utils/normalize-grid-settings/index.ts +1 -0
- package/src/utils/normalize-grid-settings/normalize-grid-settings.ts +38 -0
- package/src/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.ts +41 -0
- package/src/utils/resolve-dashboard-column-count/test/resolve-dashboard-column-count.test.ts +44 -0
- package/src/utils/row-height-presets/index.ts +8 -0
- package/src/utils/row-height-presets/row-height-presets.ts +43 -0
- package/src/widget-dashboard.tsx +102 -0
- package/src/wordpress-commands.d.ts +12 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import fastDeepEqual from 'fast-deep-equal/es6/index.js';
|
|
5
|
+
import type { ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
import {
|
|
11
|
+
createContext,
|
|
12
|
+
useCallback,
|
|
13
|
+
useContext,
|
|
14
|
+
useEffect,
|
|
15
|
+
useMemo,
|
|
16
|
+
useState,
|
|
17
|
+
} from '@wordpress/element';
|
|
18
|
+
import type {
|
|
19
|
+
ResolveWidgetModule,
|
|
20
|
+
WidgetType,
|
|
21
|
+
} from '@wordpress/widget-primitives';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Internal dependencies
|
|
25
|
+
*/
|
|
26
|
+
import { DEFAULT_GRID } from '../utils/default-grid';
|
|
27
|
+
import { computeGridModelChange } from '../utils/grid-model-change';
|
|
28
|
+
import { normalizeGridSettings } from '../utils/normalize-grid-settings';
|
|
29
|
+
import { DEFAULT_ROW_HEIGHT } from '../utils/row-height-presets';
|
|
30
|
+
import type {
|
|
31
|
+
WidgetGridModel,
|
|
32
|
+
WidgetGridSettings,
|
|
33
|
+
DashboardWidget,
|
|
34
|
+
} from '../types';
|
|
35
|
+
import { WIDGET_DASHBOARD_COLUMN_COUNT } from '../types';
|
|
36
|
+
|
|
37
|
+
type GridSettingsWithColumns = WidgetGridSettings & { columns: number };
|
|
38
|
+
|
|
39
|
+
function resolveGridSettings(
|
|
40
|
+
settings: WidgetGridSettings
|
|
41
|
+
): GridSettingsWithColumns {
|
|
42
|
+
const normalized = normalizeGridSettings( settings, DEFAULT_ROW_HEIGHT );
|
|
43
|
+
return {
|
|
44
|
+
...normalized,
|
|
45
|
+
columns: WIDGET_DASHBOARD_COLUMN_COUNT,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const DEFAULT_RESOLVE_WIDGET_MODULE: ResolveWidgetModule = ( moduleId ) =>
|
|
50
|
+
import( /* webpackIgnore: true */ moduleId );
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Canonical form of `layout`: widgets sorted by `placement.order` (falling
|
|
54
|
+
* back to array index), then `order` stripped since position now implies it.
|
|
55
|
+
* Used both as the comparison form for `hasUncommittedChanges` (so a change
|
|
56
|
+
* and its undo compare equal) and as the publish form, keeping persisted
|
|
57
|
+
* payloads free of redundant `order` fields.
|
|
58
|
+
*
|
|
59
|
+
* @param {DashboardWidget[]} layout Layout to canonicalize.
|
|
60
|
+
* @return {DashboardWidget[]} Canonicalized layout.
|
|
61
|
+
*/
|
|
62
|
+
function canonicalize( layout: DashboardWidget[] ): DashboardWidget[] {
|
|
63
|
+
const indexed = layout.map( ( widget, index ) => ( {
|
|
64
|
+
widget,
|
|
65
|
+
order: widget.placement?.order ?? index,
|
|
66
|
+
} ) );
|
|
67
|
+
|
|
68
|
+
indexed.sort( ( a, b ) => a.order - b.order );
|
|
69
|
+
|
|
70
|
+
return indexed.map( ( { widget } ) => {
|
|
71
|
+
if ( ! widget.placement ) {
|
|
72
|
+
return widget;
|
|
73
|
+
}
|
|
74
|
+
const { order: _stripped, ...placement } = widget.placement;
|
|
75
|
+
return { ...widget, placement };
|
|
76
|
+
} );
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Rich state distributed to every compound component inside `WidgetDashboard`.
|
|
81
|
+
* Internal — compounds reach the full state via `useDashboardInternalContext()`.
|
|
82
|
+
*
|
|
83
|
+
* `layout`/`onLayoutChange` and `gridSettings`/`onGridSettingsChange` here
|
|
84
|
+
* operate on the staging layer, not the committed props. Mutations from
|
|
85
|
+
* compound children stay in staging until `commit` publishes them on the
|
|
86
|
+
* consumer.
|
|
87
|
+
*/
|
|
88
|
+
interface InternalDashboardContextValue {
|
|
89
|
+
widgetTypes: WidgetType[];
|
|
90
|
+
isResolvingWidgetTypes: boolean;
|
|
91
|
+
layout: DashboardWidget[];
|
|
92
|
+
onLayoutChange: ( layout: DashboardWidget[] ) => void;
|
|
93
|
+
onLayoutReset?: () => void;
|
|
94
|
+
gridSettings: GridSettingsWithColumns;
|
|
95
|
+
onGridSettingsChange: ( gridSettings: WidgetGridSettings ) => void;
|
|
96
|
+
canEditGridSettings: boolean;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Restores the staging copy of `gridSettings` to the package's
|
|
100
|
+
* built-in defaults. Does not touch the committed slice; the user
|
|
101
|
+
* must `commit` to publish the reset, or `cancel` to discard it.
|
|
102
|
+
*/
|
|
103
|
+
resetGridSettings: () => void;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Publishes staged slices that differ from their committed
|
|
107
|
+
* counterparts. By default also exits edit mode; pass
|
|
108
|
+
* `{ exitEditMode: false }` when committing from the layout
|
|
109
|
+
* settings drawer so customize mode stays active.
|
|
110
|
+
*/
|
|
111
|
+
commit: ( options?: CommitOptions ) => void;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Switches the layout model, updates staging, and publishes
|
|
115
|
+
* immediately — equivalent to changing the model in layout
|
|
116
|
+
* settings and clicking Save.
|
|
117
|
+
*/
|
|
118
|
+
commitGridModelChange: ( targetModel: WidgetGridModel ) => void;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Reverts staging slices. By default reverts both layout and grid
|
|
122
|
+
* settings and exits edit mode. Pass `{ exitEditMode: false }` when
|
|
123
|
+
* dismissing the layout settings drawer. Pass `{ revertLayout: false }`
|
|
124
|
+
* to revert only grid settings (preserves in-progress widget layout
|
|
125
|
+
* edits while customize mode is active).
|
|
126
|
+
*/
|
|
127
|
+
cancel: ( options?: CancelOptions ) => void;
|
|
128
|
+
|
|
129
|
+
hasUncommittedChanges: boolean;
|
|
130
|
+
editMode: boolean;
|
|
131
|
+
onEditChange?: ( next: boolean ) => void;
|
|
132
|
+
resolveWidgetModule: ResolveWidgetModule;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
interface CommitOptions {
|
|
136
|
+
exitEditMode?: boolean;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface CancelOptions {
|
|
140
|
+
exitEditMode?: boolean;
|
|
141
|
+
revertLayout?: boolean;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const Context = createContext< InternalDashboardContextValue | null >( null );
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Compound-internal hook — exposes the full provider state.
|
|
148
|
+
* Not part of the public API; lives in the same module
|
|
149
|
+
* so compound components can reach the state directly.
|
|
150
|
+
*/
|
|
151
|
+
export function useDashboardInternalContext(): InternalDashboardContextValue {
|
|
152
|
+
const ctx = useContext( Context );
|
|
153
|
+
if ( ! ctx ) {
|
|
154
|
+
throw new Error(
|
|
155
|
+
'Dashboard compound used outside a WidgetDashboard subtree.'
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
return ctx;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
interface ProviderProps {
|
|
162
|
+
widgetTypes: WidgetType[];
|
|
163
|
+
isResolvingWidgetTypes?: boolean;
|
|
164
|
+
layout: DashboardWidget[];
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Fired on commit when the staged layout differs from `layout`.
|
|
168
|
+
*/
|
|
169
|
+
onLayoutChange: ( layout: DashboardWidget[] ) => void;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Optional reset action surfaced by the bundled `Actions`.
|
|
173
|
+
*/
|
|
174
|
+
onLayoutReset?: () => void;
|
|
175
|
+
|
|
176
|
+
editMode?: boolean;
|
|
177
|
+
onEditChange?: ( next: boolean ) => void;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Overrides the default `import()` resolution of
|
|
181
|
+
* `WidgetType.renderModule`.
|
|
182
|
+
*/
|
|
183
|
+
resolveWidgetModule?: ResolveWidgetModule;
|
|
184
|
+
|
|
185
|
+
gridSettings?: WidgetGridSettings;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Fired on commit when the staged settings differ from
|
|
189
|
+
* `gridSettings`.
|
|
190
|
+
*/
|
|
191
|
+
onGridSettingsChange?: ( gridSettings: WidgetGridSettings ) => void;
|
|
192
|
+
|
|
193
|
+
children: ReactNode;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Provider for the dashboard's staging layer. Owns staging copies of
|
|
198
|
+
* `layout` and `gridSettings`; `commit` publishes whichever slice
|
|
199
|
+
* differs from its committed prop, `cancel` reverts both.
|
|
200
|
+
*
|
|
201
|
+
* Staging re-syncs from the committed props on prop change. In-flight
|
|
202
|
+
* edits are dropped silently when an external update (cross-tab commit,
|
|
203
|
+
* reset, websocket push) lands. Consumers that cannot tolerate this
|
|
204
|
+
* loss should mediate the prop updates before forwarding them here.
|
|
205
|
+
*
|
|
206
|
+
* @param {ProviderProps} props Component props.
|
|
207
|
+
*/
|
|
208
|
+
export function WidgetDashboardProvider( {
|
|
209
|
+
widgetTypes,
|
|
210
|
+
isResolvingWidgetTypes = false,
|
|
211
|
+
layout: committedLayout,
|
|
212
|
+
onLayoutChange,
|
|
213
|
+
onLayoutReset,
|
|
214
|
+
editMode = false,
|
|
215
|
+
onEditChange,
|
|
216
|
+
resolveWidgetModule = DEFAULT_RESOLVE_WIDGET_MODULE,
|
|
217
|
+
gridSettings: committedGridSettings = DEFAULT_GRID,
|
|
218
|
+
onGridSettingsChange,
|
|
219
|
+
children,
|
|
220
|
+
}: ProviderProps ): React.ReactNode {
|
|
221
|
+
const [ stagingLayout, setStagingLayout ] =
|
|
222
|
+
useState< DashboardWidget[] >( committedLayout );
|
|
223
|
+
|
|
224
|
+
// External change in `layout` (consumer-side reset, cross-tab sync,
|
|
225
|
+
// websocket push, etc.) drops any in-flight staging edits without
|
|
226
|
+
// surfacing a warning. See the provider JSDoc for the trade-off.
|
|
227
|
+
useEffect( () => {
|
|
228
|
+
setStagingLayout( committedLayout );
|
|
229
|
+
}, [ committedLayout ] );
|
|
230
|
+
|
|
231
|
+
const [ stagingGridSettings, setStagingGridSettings ] =
|
|
232
|
+
useState< WidgetGridSettings >( () =>
|
|
233
|
+
normalizeGridSettings( committedGridSettings, DEFAULT_ROW_HEIGHT )
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
// Same external-resync semantics as `stagingLayout`.
|
|
237
|
+
useEffect( () => {
|
|
238
|
+
setStagingGridSettings(
|
|
239
|
+
normalizeGridSettings( committedGridSettings, DEFAULT_ROW_HEIGHT )
|
|
240
|
+
);
|
|
241
|
+
}, [ committedGridSettings ] );
|
|
242
|
+
|
|
243
|
+
const hasLayoutChanges = useMemo(
|
|
244
|
+
() =>
|
|
245
|
+
! fastDeepEqual(
|
|
246
|
+
canonicalize( committedLayout ),
|
|
247
|
+
canonicalize( stagingLayout )
|
|
248
|
+
),
|
|
249
|
+
[ committedLayout, stagingLayout ]
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
const hasGridSettingsChanges = useMemo(
|
|
253
|
+
() => ! fastDeepEqual( committedGridSettings, stagingGridSettings ),
|
|
254
|
+
[ committedGridSettings, stagingGridSettings ]
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
const hasUncommittedChanges = hasLayoutChanges || hasGridSettingsChanges;
|
|
258
|
+
|
|
259
|
+
const commit = useCallback(
|
|
260
|
+
( options?: CommitOptions ) => {
|
|
261
|
+
if ( hasLayoutChanges ) {
|
|
262
|
+
onLayoutChange( canonicalize( stagingLayout ) );
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if ( hasGridSettingsChanges ) {
|
|
266
|
+
onGridSettingsChange?.(
|
|
267
|
+
normalizeGridSettings(
|
|
268
|
+
stagingGridSettings,
|
|
269
|
+
DEFAULT_ROW_HEIGHT
|
|
270
|
+
)
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if ( options?.exitEditMode !== false ) {
|
|
275
|
+
onEditChange?.( false );
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
[
|
|
279
|
+
hasLayoutChanges,
|
|
280
|
+
hasGridSettingsChanges,
|
|
281
|
+
onLayoutChange,
|
|
282
|
+
onGridSettingsChange,
|
|
283
|
+
stagingLayout,
|
|
284
|
+
stagingGridSettings,
|
|
285
|
+
onEditChange,
|
|
286
|
+
]
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
const cancel = useCallback(
|
|
290
|
+
( options?: CancelOptions ) => {
|
|
291
|
+
if ( options?.revertLayout !== false ) {
|
|
292
|
+
setStagingLayout( committedLayout );
|
|
293
|
+
}
|
|
294
|
+
setStagingGridSettings( committedGridSettings );
|
|
295
|
+
if ( options?.exitEditMode !== false ) {
|
|
296
|
+
onEditChange?.( false );
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
[ committedLayout, committedGridSettings, onEditChange ]
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
const commitGridModelChange = useCallback(
|
|
303
|
+
( targetModel: WidgetGridModel ) => {
|
|
304
|
+
const next = computeGridModelChange( {
|
|
305
|
+
layout: stagingLayout,
|
|
306
|
+
gridSettings: stagingGridSettings,
|
|
307
|
+
targetModel,
|
|
308
|
+
} );
|
|
309
|
+
|
|
310
|
+
if ( ! next ) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
setStagingLayout( next.layout );
|
|
315
|
+
setStagingGridSettings( next.gridSettings );
|
|
316
|
+
onLayoutChange( canonicalize( next.layout ) );
|
|
317
|
+
onGridSettingsChange?.(
|
|
318
|
+
normalizeGridSettings( next.gridSettings, DEFAULT_ROW_HEIGHT )
|
|
319
|
+
);
|
|
320
|
+
onEditChange?.( false );
|
|
321
|
+
},
|
|
322
|
+
[
|
|
323
|
+
stagingLayout,
|
|
324
|
+
stagingGridSettings,
|
|
325
|
+
onLayoutChange,
|
|
326
|
+
onGridSettingsChange,
|
|
327
|
+
onEditChange,
|
|
328
|
+
]
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
const resetGridSettings = useCallback( () => {
|
|
332
|
+
setStagingGridSettings( DEFAULT_GRID );
|
|
333
|
+
}, [] );
|
|
334
|
+
|
|
335
|
+
useEffect( () => {
|
|
336
|
+
if ( stagingLayout.length === 0 ) {
|
|
337
|
+
onEditChange?.( true );
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Only react to the layout count flipping to zero; firing on every
|
|
341
|
+
// onEditChange identity change would also reopen edit mode after the
|
|
342
|
+
// user explicitly closed it on a non-empty layout.
|
|
343
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
344
|
+
}, [ stagingLayout.length === 0 ] );
|
|
345
|
+
|
|
346
|
+
const canEditGridSettings = onGridSettingsChange !== undefined;
|
|
347
|
+
|
|
348
|
+
const value = useMemo< InternalDashboardContextValue >(
|
|
349
|
+
() => ( {
|
|
350
|
+
widgetTypes,
|
|
351
|
+
isResolvingWidgetTypes,
|
|
352
|
+
layout: stagingLayout,
|
|
353
|
+
onLayoutChange: setStagingLayout,
|
|
354
|
+
onLayoutReset,
|
|
355
|
+
gridSettings: resolveGridSettings( stagingGridSettings ),
|
|
356
|
+
onGridSettingsChange: setStagingGridSettings,
|
|
357
|
+
canEditGridSettings,
|
|
358
|
+
resetGridSettings,
|
|
359
|
+
commit,
|
|
360
|
+
commitGridModelChange,
|
|
361
|
+
cancel,
|
|
362
|
+
hasUncommittedChanges,
|
|
363
|
+
editMode,
|
|
364
|
+
onEditChange,
|
|
365
|
+
resolveWidgetModule,
|
|
366
|
+
} ),
|
|
367
|
+
[
|
|
368
|
+
widgetTypes,
|
|
369
|
+
isResolvingWidgetTypes,
|
|
370
|
+
stagingLayout,
|
|
371
|
+
onLayoutReset,
|
|
372
|
+
stagingGridSettings,
|
|
373
|
+
canEditGridSettings,
|
|
374
|
+
resetGridSettings,
|
|
375
|
+
commit,
|
|
376
|
+
commitGridModelChange,
|
|
377
|
+
cancel,
|
|
378
|
+
hasUncommittedChanges,
|
|
379
|
+
editMode,
|
|
380
|
+
onEditChange,
|
|
381
|
+
resolveWidgetModule,
|
|
382
|
+
]
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
return <Context.Provider value={ value }>{ children }</Context.Provider>;
|
|
386
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
createContext,
|
|
11
|
+
useContext,
|
|
12
|
+
useMemo,
|
|
13
|
+
useState,
|
|
14
|
+
} from '@wordpress/element';
|
|
15
|
+
|
|
16
|
+
type DrawerSide = 'left' | 'right';
|
|
17
|
+
|
|
18
|
+
interface DashboardUIContextValue {
|
|
19
|
+
inserterOpen: boolean;
|
|
20
|
+
setInserterOpen: ( next: boolean ) => void;
|
|
21
|
+
|
|
22
|
+
layoutSettingsOpen: boolean;
|
|
23
|
+
setLayoutSettingsOpen: ( next: boolean ) => void;
|
|
24
|
+
resetDialogOpen: boolean;
|
|
25
|
+
setResetDialogOpen: ( next: boolean ) => void;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* `uuid` of the instance whose settings drawer is open, or `null`
|
|
29
|
+
* when no settings drawer is showing. The per-instance gear in the
|
|
30
|
+
* chrome sets it; the single `WidgetSettings` at the root reads
|
|
31
|
+
* it.
|
|
32
|
+
*/
|
|
33
|
+
settingsWidgetUuid: string | null;
|
|
34
|
+
setSettingsWidgetUuid: ( next: string | null ) => void;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Edge the settings drawer slides in from. The gear sets it from the
|
|
38
|
+
* widget's on-screen position so the drawer opens on the side away
|
|
39
|
+
* from the widget, trying not to cover it.
|
|
40
|
+
*/
|
|
41
|
+
settingsDrawerSide: DrawerSide;
|
|
42
|
+
setSettingsDrawerSide: ( next: DrawerSide ) => void;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Inline-start inset (px) the settings drawer is offset by when it
|
|
46
|
+
* opens from the left, so it clears fixed page chrome (the WordPress
|
|
47
|
+
* admin menu) instead of sliding over it. `0` when there's nothing to
|
|
48
|
+
* clear.
|
|
49
|
+
*/
|
|
50
|
+
settingsDrawerInset: number;
|
|
51
|
+
setSettingsDrawerInset: ( next: number ) => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const Context = createContext< DashboardUIContextValue | null >( null );
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Accesses the shared UI state: overlay open flags and the active settings
|
|
58
|
+
* instance with its placement. Throws when called outside `WidgetDashboard`.
|
|
59
|
+
*/
|
|
60
|
+
export function useDashboardUIContext(): DashboardUIContextValue {
|
|
61
|
+
const ctx = useContext( Context );
|
|
62
|
+
if ( ! ctx ) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
'Dashboard compound used outside a WidgetDashboard subtree.'
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
return ctx;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface ProviderProps {
|
|
71
|
+
children: ReactNode;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Holds transient UI state shared across compounds (the inserter modal and
|
|
76
|
+
* the per-instance settings drawer). Kept separate from the data context so
|
|
77
|
+
* that data mutations don't churn the UI state and vice-versa.
|
|
78
|
+
*
|
|
79
|
+
* @param {ProviderProps} props Component props.
|
|
80
|
+
*/
|
|
81
|
+
export function WidgetDashboardUIProvider( { children }: ProviderProps ) {
|
|
82
|
+
const [ inserterOpen, setInserterOpen ] = useState( false );
|
|
83
|
+
const [ layoutSettingsOpen, setLayoutSettingsOpen ] = useState( false );
|
|
84
|
+
const [ resetDialogOpen, setResetDialogOpen ] = useState( false );
|
|
85
|
+
const [ settingsWidgetUuid, setSettingsWidgetUuid ] = useState<
|
|
86
|
+
string | null
|
|
87
|
+
>( null );
|
|
88
|
+
const [ settingsDrawerSide, setSettingsDrawerSide ] =
|
|
89
|
+
useState< DrawerSide >( 'right' );
|
|
90
|
+
const [ settingsDrawerInset, setSettingsDrawerInset ] = useState( 0 );
|
|
91
|
+
|
|
92
|
+
const value = useMemo< DashboardUIContextValue >(
|
|
93
|
+
() => ( {
|
|
94
|
+
inserterOpen,
|
|
95
|
+
setInserterOpen,
|
|
96
|
+
layoutSettingsOpen,
|
|
97
|
+
setLayoutSettingsOpen,
|
|
98
|
+
resetDialogOpen,
|
|
99
|
+
setResetDialogOpen,
|
|
100
|
+
settingsWidgetUuid,
|
|
101
|
+
setSettingsWidgetUuid,
|
|
102
|
+
settingsDrawerSide,
|
|
103
|
+
setSettingsDrawerSide,
|
|
104
|
+
settingsDrawerInset,
|
|
105
|
+
setSettingsDrawerInset,
|
|
106
|
+
} ),
|
|
107
|
+
[
|
|
108
|
+
inserterOpen,
|
|
109
|
+
layoutSettingsOpen,
|
|
110
|
+
resetDialogOpen,
|
|
111
|
+
settingsWidgetUuid,
|
|
112
|
+
settingsDrawerSide,
|
|
113
|
+
settingsDrawerInset,
|
|
114
|
+
]
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
return <Context.Provider value={ value }>{ children }</Context.Provider>;
|
|
118
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { createContext, useContext } from '@wordpress/element';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import type { WidgetContextValue } from '../types';
|
|
15
|
+
|
|
16
|
+
const WidgetContext = createContext< WidgetContextValue | null >( null );
|
|
17
|
+
|
|
18
|
+
interface ProviderProps {
|
|
19
|
+
value: WidgetContextValue;
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Provides the current widget's identity to its render subtree.
|
|
25
|
+
*
|
|
26
|
+
* @param {ProviderProps} props Component props.
|
|
27
|
+
*/
|
|
28
|
+
export function WidgetContextProvider( {
|
|
29
|
+
value,
|
|
30
|
+
children,
|
|
31
|
+
}: ProviderProps ): React.ReactNode {
|
|
32
|
+
return (
|
|
33
|
+
<WidgetContext.Provider value={ value }>
|
|
34
|
+
{ children }
|
|
35
|
+
</WidgetContext.Provider>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Returns the current widget's identity (`uuid`, `name`, `index`). Returns
|
|
41
|
+
* `null` when called outside a widget render subtree.
|
|
42
|
+
*/
|
|
43
|
+
export function useWidgetContext(): WidgetContextValue | null {
|
|
44
|
+
return useContext( WidgetContext );
|
|
45
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useResizeObserver, useMergeRefs } from '@wordpress/compose';
|
|
5
|
+
import {
|
|
6
|
+
useLayoutEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
useState,
|
|
9
|
+
type Ref,
|
|
10
|
+
} from '@wordpress/element';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import { resolveDashboardColumnCount } from '../utils/resolve-dashboard-column-count/resolve-dashboard-column-count';
|
|
16
|
+
|
|
17
|
+
interface UseDashboardContainerColumnCountResult {
|
|
18
|
+
containerRef: Ref< HTMLDivElement >;
|
|
19
|
+
columnCount: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Tracks the dashboard grid container width and maps it to an opinionated
|
|
24
|
+
* column count (4 → 2 → 1). Measurement is container-based via
|
|
25
|
+
* `ResizeObserver`, not viewport media queries.
|
|
26
|
+
*
|
|
27
|
+
* @param {Ref< HTMLDivElement >} [forwardedRef] Ref forwarded from the grid wrapper.
|
|
28
|
+
*/
|
|
29
|
+
export function useDashboardContainerColumnCount(
|
|
30
|
+
forwardedRef?: Ref< HTMLDivElement >
|
|
31
|
+
): UseDashboardContainerColumnCountResult {
|
|
32
|
+
const [ container, setContainer ] = useState< HTMLDivElement | null >(
|
|
33
|
+
null
|
|
34
|
+
);
|
|
35
|
+
const [ containerWidth, setContainerWidth ] = useState( 0 );
|
|
36
|
+
|
|
37
|
+
const resizeObserverRef = useResizeObserver( ( [ { contentRect } ] ) => {
|
|
38
|
+
setContainerWidth( contentRect.width );
|
|
39
|
+
} );
|
|
40
|
+
|
|
41
|
+
const containerRef = useMergeRefs( [
|
|
42
|
+
setContainer,
|
|
43
|
+
resizeObserverRef,
|
|
44
|
+
forwardedRef ?? null,
|
|
45
|
+
] );
|
|
46
|
+
|
|
47
|
+
useLayoutEffect( () => {
|
|
48
|
+
if ( ! container ) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const { width } = container.getBoundingClientRect();
|
|
52
|
+
if ( width > 0 ) {
|
|
53
|
+
setContainerWidth( width );
|
|
54
|
+
}
|
|
55
|
+
}, [ container ] );
|
|
56
|
+
|
|
57
|
+
const columnCount = useMemo(
|
|
58
|
+
() => resolveDashboardColumnCount( containerWidth ),
|
|
59
|
+
[ containerWidth ]
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return { containerRef, columnCount };
|
|
63
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { WidgetDashboard } from './widget-dashboard';
|
|
2
|
+
export type { DashboardWidget, WidgetGridSettings } from './types';
|
|
3
|
+
export { WIDGET_DASHBOARD_COLUMN_COUNT } from './types';
|
|
4
|
+
export { DEFAULT_GRID } from './utils/default-grid';
|
|
5
|
+
export { normalizeGridSettings } from './utils/normalize-grid-settings';
|
|
6
|
+
export {
|
|
7
|
+
ROW_HEIGHT_PRESETS,
|
|
8
|
+
DEFAULT_ROW_HEIGHT,
|
|
9
|
+
} from './utils/row-height-presets';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
|
|
5
|
+
|
|
6
|
+
export const { lock, unlock } =
|
|
7
|
+
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
|
|
8
|
+
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
|
|
9
|
+
'@wordpress/widget-dashboard'
|
|
10
|
+
);
|