@wordpress/widget-dashboard 0.1.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 +228 -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,476 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
import { act, render } from '@testing-library/react';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { useEffect, useState } from '@wordpress/element';
|
|
11
|
+
import type { WidgetType } from '@wordpress/widget-primitives';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import { useDashboardInternalContext } from '../context/dashboard-context';
|
|
17
|
+
import { WidgetDashboard } from '../widget-dashboard';
|
|
18
|
+
import type { DashboardWidget, WidgetGridSettings } from '../types';
|
|
19
|
+
|
|
20
|
+
const widgetTypes: WidgetType[] = [];
|
|
21
|
+
|
|
22
|
+
const initialLayout: DashboardWidget[] = [
|
|
23
|
+
{ uuid: 'a', type: 'core/test', placement: { width: 1, height: 1 } },
|
|
24
|
+
{ uuid: 'b', type: 'core/test', placement: { width: 1, height: 1 } },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
interface ProbeApi {
|
|
28
|
+
layout: DashboardWidget[];
|
|
29
|
+
gridSettings: WidgetGridSettings;
|
|
30
|
+
hasUncommittedChanges: boolean;
|
|
31
|
+
editMode: boolean;
|
|
32
|
+
mutate: ( next: DashboardWidget[] ) => void;
|
|
33
|
+
mutateGridSettings: ( next: WidgetGridSettings ) => void;
|
|
34
|
+
commit: ( options?: { exitEditMode?: boolean } ) => void;
|
|
35
|
+
cancel: ( options?: {
|
|
36
|
+
exitEditMode?: boolean;
|
|
37
|
+
revertLayout?: boolean;
|
|
38
|
+
} ) => void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const probeRef: { current: ProbeApi | null } = { current: null };
|
|
42
|
+
|
|
43
|
+
function Probe() {
|
|
44
|
+
const ctx = useDashboardInternalContext();
|
|
45
|
+
useEffect( () => {
|
|
46
|
+
probeRef.current = {
|
|
47
|
+
layout: ctx.layout,
|
|
48
|
+
gridSettings: ctx.gridSettings,
|
|
49
|
+
hasUncommittedChanges: ctx.hasUncommittedChanges,
|
|
50
|
+
editMode: ctx.editMode,
|
|
51
|
+
mutate: ctx.onLayoutChange,
|
|
52
|
+
mutateGridSettings: ctx.onGridSettingsChange,
|
|
53
|
+
commit: ctx.commit,
|
|
54
|
+
cancel: ctx.cancel,
|
|
55
|
+
};
|
|
56
|
+
} );
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function readProbe(): ProbeApi {
|
|
61
|
+
if ( ! probeRef.current ) {
|
|
62
|
+
throw new Error( 'Probe not mounted yet' );
|
|
63
|
+
}
|
|
64
|
+
return probeRef.current;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface HarnessProps {
|
|
68
|
+
layout: DashboardWidget[];
|
|
69
|
+
onLayoutChange: ( next: DashboardWidget[] ) => void;
|
|
70
|
+
gridSettings?: WidgetGridSettings;
|
|
71
|
+
onGridSettingsChange?: ( next: WidgetGridSettings ) => void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function Harness( {
|
|
75
|
+
layout,
|
|
76
|
+
onLayoutChange,
|
|
77
|
+
gridSettings,
|
|
78
|
+
onGridSettingsChange,
|
|
79
|
+
}: HarnessProps ) {
|
|
80
|
+
const [ editMode, setEditMode ] = useState( true );
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<WidgetDashboard
|
|
84
|
+
layout={ layout }
|
|
85
|
+
onLayoutChange={ onLayoutChange }
|
|
86
|
+
gridSettings={ gridSettings }
|
|
87
|
+
onGridSettingsChange={ onGridSettingsChange }
|
|
88
|
+
widgetTypes={ widgetTypes }
|
|
89
|
+
editMode={ editMode }
|
|
90
|
+
onEditChange={ setEditMode }
|
|
91
|
+
>
|
|
92
|
+
<Probe />
|
|
93
|
+
</WidgetDashboard>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
describe( 'WidgetDashboard staging layer', () => {
|
|
98
|
+
it( 'keeps mutations in staging without firing onLayoutChange', () => {
|
|
99
|
+
const onLayoutChange = jest.fn();
|
|
100
|
+
render(
|
|
101
|
+
<Harness
|
|
102
|
+
layout={ initialLayout }
|
|
103
|
+
onLayoutChange={ onLayoutChange }
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
expect( readProbe().hasUncommittedChanges ).toBe( false );
|
|
108
|
+
|
|
109
|
+
const moved: DashboardWidget[] = [
|
|
110
|
+
{ ...initialLayout[ 1 ] },
|
|
111
|
+
{ ...initialLayout[ 0 ] },
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
act( () => {
|
|
115
|
+
readProbe().mutate( moved );
|
|
116
|
+
} );
|
|
117
|
+
|
|
118
|
+
expect( onLayoutChange ).not.toHaveBeenCalled();
|
|
119
|
+
expect( readProbe().hasUncommittedChanges ).toBe( true );
|
|
120
|
+
expect( readProbe().layout.map( ( w ) => w.uuid ) ).toEqual( [
|
|
121
|
+
'b',
|
|
122
|
+
'a',
|
|
123
|
+
] );
|
|
124
|
+
} );
|
|
125
|
+
|
|
126
|
+
it( 'fires onLayoutChange with the staged layout on commit', () => {
|
|
127
|
+
const onLayoutChange = jest.fn();
|
|
128
|
+
render(
|
|
129
|
+
<Harness
|
|
130
|
+
layout={ initialLayout }
|
|
131
|
+
onLayoutChange={ onLayoutChange }
|
|
132
|
+
/>
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const next: DashboardWidget[] = [
|
|
136
|
+
...initialLayout,
|
|
137
|
+
{
|
|
138
|
+
uuid: 'c',
|
|
139
|
+
type: 'core/test',
|
|
140
|
+
placement: { width: 1, height: 1 },
|
|
141
|
+
},
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
act( () => {
|
|
145
|
+
readProbe().mutate( next );
|
|
146
|
+
} );
|
|
147
|
+
|
|
148
|
+
act( () => {
|
|
149
|
+
readProbe().commit();
|
|
150
|
+
} );
|
|
151
|
+
|
|
152
|
+
expect( onLayoutChange ).toHaveBeenCalledTimes( 1 );
|
|
153
|
+
expect(
|
|
154
|
+
onLayoutChange.mock.calls[ 0 ][ 0 ].map(
|
|
155
|
+
( w: DashboardWidget ) => w.uuid
|
|
156
|
+
)
|
|
157
|
+
).toEqual( [ 'a', 'b', 'c' ] );
|
|
158
|
+
} );
|
|
159
|
+
|
|
160
|
+
it( 'restores staging to the committed layout on cancel', () => {
|
|
161
|
+
const onLayoutChange = jest.fn();
|
|
162
|
+
render(
|
|
163
|
+
<Harness
|
|
164
|
+
layout={ initialLayout }
|
|
165
|
+
onLayoutChange={ onLayoutChange }
|
|
166
|
+
/>
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
act( () => {
|
|
170
|
+
readProbe().mutate( [ initialLayout[ 0 ] ] );
|
|
171
|
+
} );
|
|
172
|
+
|
|
173
|
+
expect( readProbe().hasUncommittedChanges ).toBe( true );
|
|
174
|
+
|
|
175
|
+
act( () => {
|
|
176
|
+
readProbe().cancel();
|
|
177
|
+
} );
|
|
178
|
+
|
|
179
|
+
expect( readProbe().hasUncommittedChanges ).toBe( false );
|
|
180
|
+
expect( readProbe().layout.map( ( w ) => w.uuid ) ).toEqual( [
|
|
181
|
+
'a',
|
|
182
|
+
'b',
|
|
183
|
+
] );
|
|
184
|
+
expect( onLayoutChange ).not.toHaveBeenCalled();
|
|
185
|
+
} );
|
|
186
|
+
|
|
187
|
+
it( 'reports no uncommitted changes after a swap-and-revert when the visible order is restored', () => {
|
|
188
|
+
const onLayoutChange = jest.fn();
|
|
189
|
+
render(
|
|
190
|
+
<Harness
|
|
191
|
+
layout={ initialLayout }
|
|
192
|
+
onLayoutChange={ onLayoutChange }
|
|
193
|
+
/>
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
// Initial: committed has no `order`. After a swap, the grid assigns
|
|
197
|
+
// explicit order values. After re-swapping, the visible order
|
|
198
|
+
// matches initial but the array shape carries explicit orders.
|
|
199
|
+
act( () => {
|
|
200
|
+
readProbe().mutate( [
|
|
201
|
+
{
|
|
202
|
+
...initialLayout[ 0 ],
|
|
203
|
+
placement: { width: 1, height: 1, order: 0 },
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
...initialLayout[ 1 ],
|
|
207
|
+
placement: { width: 1, height: 1, order: 1 },
|
|
208
|
+
},
|
|
209
|
+
] );
|
|
210
|
+
} );
|
|
211
|
+
|
|
212
|
+
expect( readProbe().hasUncommittedChanges ).toBe( false );
|
|
213
|
+
} );
|
|
214
|
+
|
|
215
|
+
it( 'commits a canonicalized layout, sorted by order with order stripped', () => {
|
|
216
|
+
const onLayoutChange = jest.fn();
|
|
217
|
+
render(
|
|
218
|
+
<Harness
|
|
219
|
+
layout={ initialLayout }
|
|
220
|
+
onLayoutChange={ onLayoutChange }
|
|
221
|
+
/>
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
// Stage a layout where the array is in reverse visual order but
|
|
225
|
+
// the placements carry explicit `order` values that restore the
|
|
226
|
+
// visible "a then b" arrangement.
|
|
227
|
+
act( () => {
|
|
228
|
+
readProbe().mutate( [
|
|
229
|
+
{
|
|
230
|
+
...initialLayout[ 1 ],
|
|
231
|
+
placement: { width: 1, height: 1, order: 1 },
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
...initialLayout[ 0 ],
|
|
235
|
+
placement: { width: 1, height: 1, order: 0 },
|
|
236
|
+
},
|
|
237
|
+
] );
|
|
238
|
+
} );
|
|
239
|
+
|
|
240
|
+
// hasUncommittedChanges should be false (visual order is unchanged).
|
|
241
|
+
expect( readProbe().hasUncommittedChanges ).toBe( false );
|
|
242
|
+
|
|
243
|
+
// Now stage a true visual change that also carries `order`, and
|
|
244
|
+
// commit. The publish payload should be sorted by order with the
|
|
245
|
+
// `order` field stripped.
|
|
246
|
+
act( () => {
|
|
247
|
+
readProbe().mutate( [
|
|
248
|
+
{
|
|
249
|
+
...initialLayout[ 0 ],
|
|
250
|
+
placement: { width: 1, height: 1, order: 1 },
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
...initialLayout[ 1 ],
|
|
254
|
+
placement: { width: 1, height: 1, order: 0 },
|
|
255
|
+
},
|
|
256
|
+
] );
|
|
257
|
+
} );
|
|
258
|
+
|
|
259
|
+
act( () => {
|
|
260
|
+
readProbe().commit();
|
|
261
|
+
} );
|
|
262
|
+
|
|
263
|
+
expect( onLayoutChange ).toHaveBeenCalledTimes( 1 );
|
|
264
|
+
const committed = onLayoutChange.mock.calls[ 0 ][ 0 ];
|
|
265
|
+
expect( committed.map( ( w: DashboardWidget ) => w.uuid ) ).toEqual( [
|
|
266
|
+
'b',
|
|
267
|
+
'a',
|
|
268
|
+
] );
|
|
269
|
+
for ( const widget of committed ) {
|
|
270
|
+
expect( widget.placement ).not.toHaveProperty( 'order' );
|
|
271
|
+
}
|
|
272
|
+
} );
|
|
273
|
+
|
|
274
|
+
it( 'forces edit mode when the layout becomes empty', () => {
|
|
275
|
+
const onLayoutChange = jest.fn();
|
|
276
|
+
const { rerender } = render(
|
|
277
|
+
<Harness
|
|
278
|
+
layout={ initialLayout }
|
|
279
|
+
onLayoutChange={ onLayoutChange }
|
|
280
|
+
/>
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
// Empty committed -> auto edit-mode after sync.
|
|
284
|
+
rerender( <Harness layout={ [] } onLayoutChange={ onLayoutChange } /> );
|
|
285
|
+
|
|
286
|
+
expect( readProbe().editMode ).toBe( true );
|
|
287
|
+
} );
|
|
288
|
+
|
|
289
|
+
describe( 'grid settings staging', () => {
|
|
290
|
+
const initialSettings: WidgetGridSettings = {
|
|
291
|
+
model: 'grid',
|
|
292
|
+
rowHeight: 200,
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
it( 'keeps settings mutations in staging without firing onGridSettingsChange', () => {
|
|
296
|
+
const onLayoutChange = jest.fn();
|
|
297
|
+
const onGridSettingsChange = jest.fn();
|
|
298
|
+
render(
|
|
299
|
+
<Harness
|
|
300
|
+
layout={ initialLayout }
|
|
301
|
+
onLayoutChange={ onLayoutChange }
|
|
302
|
+
gridSettings={ initialSettings }
|
|
303
|
+
onGridSettingsChange={ onGridSettingsChange }
|
|
304
|
+
/>
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
expect( readProbe().hasUncommittedChanges ).toBe( false );
|
|
308
|
+
|
|
309
|
+
act( () => {
|
|
310
|
+
readProbe().mutateGridSettings( {
|
|
311
|
+
...initialSettings,
|
|
312
|
+
rowHeight: 300,
|
|
313
|
+
} );
|
|
314
|
+
} );
|
|
315
|
+
|
|
316
|
+
expect( onGridSettingsChange ).not.toHaveBeenCalled();
|
|
317
|
+
expect( readProbe().hasUncommittedChanges ).toBe( true );
|
|
318
|
+
expect( readProbe().gridSettings.rowHeight ).toBe( 300 );
|
|
319
|
+
} );
|
|
320
|
+
|
|
321
|
+
it( 'publishes both layout and settings on commit', () => {
|
|
322
|
+
const onLayoutChange = jest.fn();
|
|
323
|
+
const onGridSettingsChange = jest.fn();
|
|
324
|
+
render(
|
|
325
|
+
<Harness
|
|
326
|
+
layout={ initialLayout }
|
|
327
|
+
onLayoutChange={ onLayoutChange }
|
|
328
|
+
gridSettings={ initialSettings }
|
|
329
|
+
onGridSettingsChange={ onGridSettingsChange }
|
|
330
|
+
/>
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
act( () => {
|
|
334
|
+
readProbe().mutate( [ initialLayout[ 0 ] ] );
|
|
335
|
+
readProbe().mutateGridSettings( {
|
|
336
|
+
...initialSettings,
|
|
337
|
+
model: 'masonry',
|
|
338
|
+
} );
|
|
339
|
+
} );
|
|
340
|
+
|
|
341
|
+
act( () => {
|
|
342
|
+
readProbe().commit();
|
|
343
|
+
} );
|
|
344
|
+
|
|
345
|
+
expect( onLayoutChange ).toHaveBeenCalledTimes( 1 );
|
|
346
|
+
expect( onGridSettingsChange ).toHaveBeenCalledTimes( 1 );
|
|
347
|
+
expect( onGridSettingsChange.mock.calls[ 0 ][ 0 ] ).toMatchObject( {
|
|
348
|
+
model: 'masonry',
|
|
349
|
+
} );
|
|
350
|
+
} );
|
|
351
|
+
|
|
352
|
+
it( 'reverts settings on cancel', () => {
|
|
353
|
+
const onLayoutChange = jest.fn();
|
|
354
|
+
const onGridSettingsChange = jest.fn();
|
|
355
|
+
render(
|
|
356
|
+
<Harness
|
|
357
|
+
layout={ initialLayout }
|
|
358
|
+
onLayoutChange={ onLayoutChange }
|
|
359
|
+
gridSettings={ initialSettings }
|
|
360
|
+
onGridSettingsChange={ onGridSettingsChange }
|
|
361
|
+
/>
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
act( () => {
|
|
365
|
+
readProbe().mutateGridSettings( {
|
|
366
|
+
...initialSettings,
|
|
367
|
+
model: 'masonry',
|
|
368
|
+
} );
|
|
369
|
+
} );
|
|
370
|
+
|
|
371
|
+
expect( readProbe().hasUncommittedChanges ).toBe( true );
|
|
372
|
+
|
|
373
|
+
act( () => {
|
|
374
|
+
readProbe().cancel();
|
|
375
|
+
} );
|
|
376
|
+
|
|
377
|
+
expect( onGridSettingsChange ).not.toHaveBeenCalled();
|
|
378
|
+
expect( readProbe().hasUncommittedChanges ).toBe( false );
|
|
379
|
+
expect( readProbe().gridSettings.model ).toBe( 'grid' );
|
|
380
|
+
} );
|
|
381
|
+
|
|
382
|
+
it( 'skips publishing settings when only the layout changed', () => {
|
|
383
|
+
const onLayoutChange = jest.fn();
|
|
384
|
+
const onGridSettingsChange = jest.fn();
|
|
385
|
+
render(
|
|
386
|
+
<Harness
|
|
387
|
+
layout={ initialLayout }
|
|
388
|
+
onLayoutChange={ onLayoutChange }
|
|
389
|
+
gridSettings={ initialSettings }
|
|
390
|
+
onGridSettingsChange={ onGridSettingsChange }
|
|
391
|
+
/>
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
act( () => {
|
|
395
|
+
readProbe().mutate( [ initialLayout[ 0 ] ] );
|
|
396
|
+
} );
|
|
397
|
+
|
|
398
|
+
act( () => {
|
|
399
|
+
readProbe().commit();
|
|
400
|
+
} );
|
|
401
|
+
|
|
402
|
+
expect( onLayoutChange ).toHaveBeenCalledTimes( 1 );
|
|
403
|
+
expect( onGridSettingsChange ).not.toHaveBeenCalled();
|
|
404
|
+
} );
|
|
405
|
+
} );
|
|
406
|
+
|
|
407
|
+
it( 'reverts only grid settings when cancel passes revertLayout: false', () => {
|
|
408
|
+
const onLayoutChange = jest.fn();
|
|
409
|
+
const onGridSettingsChange = jest.fn();
|
|
410
|
+
const initialSettings: WidgetGridSettings = {
|
|
411
|
+
model: 'grid',
|
|
412
|
+
minColumnWidth: 350,
|
|
413
|
+
rowHeight: 200,
|
|
414
|
+
};
|
|
415
|
+
render(
|
|
416
|
+
<Harness
|
|
417
|
+
layout={ initialLayout }
|
|
418
|
+
onLayoutChange={ onLayoutChange }
|
|
419
|
+
gridSettings={ initialSettings }
|
|
420
|
+
onGridSettingsChange={ onGridSettingsChange }
|
|
421
|
+
/>
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
act( () => {
|
|
425
|
+
readProbe().mutate( [ initialLayout[ 0 ] ] );
|
|
426
|
+
readProbe().mutateGridSettings( {
|
|
427
|
+
...initialSettings,
|
|
428
|
+
minColumnWidth: 420,
|
|
429
|
+
} );
|
|
430
|
+
} );
|
|
431
|
+
|
|
432
|
+
expect( readProbe().hasUncommittedChanges ).toBe( true );
|
|
433
|
+
|
|
434
|
+
act( () => {
|
|
435
|
+
readProbe().cancel( {
|
|
436
|
+
exitEditMode: false,
|
|
437
|
+
revertLayout: false,
|
|
438
|
+
} );
|
|
439
|
+
} );
|
|
440
|
+
|
|
441
|
+
expect( readProbe().hasUncommittedChanges ).toBe( true );
|
|
442
|
+
expect( readProbe().layout ).toHaveLength( 1 );
|
|
443
|
+
expect( readProbe().gridSettings.minColumnWidth ).toBe( 350 );
|
|
444
|
+
} );
|
|
445
|
+
|
|
446
|
+
it( 'stays in edit mode when commit or cancel passes exitEditMode: false', () => {
|
|
447
|
+
const onLayoutChange = jest.fn();
|
|
448
|
+
render(
|
|
449
|
+
<Harness
|
|
450
|
+
layout={ initialLayout }
|
|
451
|
+
onLayoutChange={ onLayoutChange }
|
|
452
|
+
/>
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
act( () => {
|
|
456
|
+
readProbe().mutate( [ initialLayout[ 0 ] ] );
|
|
457
|
+
} );
|
|
458
|
+
|
|
459
|
+
act( () => {
|
|
460
|
+
readProbe().commit( { exitEditMode: false } );
|
|
461
|
+
} );
|
|
462
|
+
|
|
463
|
+
expect( readProbe().editMode ).toBe( true );
|
|
464
|
+
expect( onLayoutChange ).toHaveBeenCalledTimes( 1 );
|
|
465
|
+
|
|
466
|
+
act( () => {
|
|
467
|
+
readProbe().mutate( [ initialLayout[ 0 ] ] );
|
|
468
|
+
} );
|
|
469
|
+
|
|
470
|
+
act( () => {
|
|
471
|
+
readProbe().cancel( { exitEditMode: false } );
|
|
472
|
+
} );
|
|
473
|
+
|
|
474
|
+
expect( readProbe().editMode ).toBe( true );
|
|
475
|
+
} );
|
|
476
|
+
} );
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
import type { ComponentType } from 'react';
|
|
6
|
+
import { render, screen } from '@testing-library/react';
|
|
7
|
+
import userEvent from '@testing-library/user-event';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* WordPress dependencies
|
|
11
|
+
*/
|
|
12
|
+
import { useState } from '@wordpress/element';
|
|
13
|
+
import type {
|
|
14
|
+
ResolveWidgetModule,
|
|
15
|
+
WidgetRenderProps,
|
|
16
|
+
WidgetType,
|
|
17
|
+
} from '@wordpress/widget-primitives';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies
|
|
21
|
+
*/
|
|
22
|
+
import { WidgetDashboard } from '../widget-dashboard';
|
|
23
|
+
import type { DashboardWidget } from '../types';
|
|
24
|
+
|
|
25
|
+
type Attrs = { greeting: string };
|
|
26
|
+
|
|
27
|
+
function TestWidget( {
|
|
28
|
+
attributes,
|
|
29
|
+
setAttributes,
|
|
30
|
+
}: WidgetRenderProps< Attrs > ) {
|
|
31
|
+
return (
|
|
32
|
+
<div>
|
|
33
|
+
<p data-testid="greeting">{ attributes.greeting }</p>
|
|
34
|
+
<button
|
|
35
|
+
onClick={ () => setAttributes?.( { greeting: 'updated' } ) }
|
|
36
|
+
>
|
|
37
|
+
Update
|
|
38
|
+
</button>
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const widgetTypes: WidgetType[] = [
|
|
44
|
+
{
|
|
45
|
+
apiVersion: 1,
|
|
46
|
+
name: 'test/greet',
|
|
47
|
+
title: 'Greet',
|
|
48
|
+
renderModule: 'test-greet-module',
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
const resolveWidgetModule: ResolveWidgetModule = async ( id ) => {
|
|
53
|
+
if ( id === 'test-greet-module' ) {
|
|
54
|
+
return {
|
|
55
|
+
default: TestWidget as ComponentType<
|
|
56
|
+
WidgetRenderProps< unknown >
|
|
57
|
+
>,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
throw new Error( `Unknown module: ${ id }` );
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const initialLayout: DashboardWidget< Attrs >[] = [
|
|
64
|
+
{
|
|
65
|
+
uuid: 'w1',
|
|
66
|
+
type: 'test/greet',
|
|
67
|
+
attributes: { greeting: 'hello' },
|
|
68
|
+
placement: { width: 2, height: 2 },
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
function Harness( {
|
|
73
|
+
onLayoutChange,
|
|
74
|
+
}: {
|
|
75
|
+
onLayoutChange?: ( layout: DashboardWidget[] ) => void;
|
|
76
|
+
} ) {
|
|
77
|
+
const [ layout, setLayout ] = useState( initialLayout );
|
|
78
|
+
const [ editMode, setEditMode ] = useState( false );
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<WidgetDashboard
|
|
82
|
+
layout={ layout }
|
|
83
|
+
onLayoutChange={ ( next ) => {
|
|
84
|
+
setLayout( next as DashboardWidget< Attrs >[] );
|
|
85
|
+
onLayoutChange?.( next );
|
|
86
|
+
} }
|
|
87
|
+
widgetTypes={ widgetTypes }
|
|
88
|
+
resolveWidgetModule={ resolveWidgetModule }
|
|
89
|
+
editMode={ editMode }
|
|
90
|
+
onEditChange={ setEditMode }
|
|
91
|
+
/>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
describe( 'WidgetDashboard', () => {
|
|
96
|
+
it( 'resolves the widget module and renders attributes', async () => {
|
|
97
|
+
render( <Harness /> );
|
|
98
|
+
|
|
99
|
+
expect( await screen.findByTestId( 'greeting' ) ).toHaveTextContent(
|
|
100
|
+
'hello'
|
|
101
|
+
);
|
|
102
|
+
} );
|
|
103
|
+
|
|
104
|
+
it( 'threads setAttributes into onLayoutChange on commit with merged attributes', async () => {
|
|
105
|
+
const onChange = jest.fn();
|
|
106
|
+
render( <Harness onLayoutChange={ onChange } /> );
|
|
107
|
+
|
|
108
|
+
const button = await screen.findByRole( 'button', {
|
|
109
|
+
name: 'Update',
|
|
110
|
+
} );
|
|
111
|
+
await userEvent.click( button );
|
|
112
|
+
|
|
113
|
+
// Attribute changes stay in staging until commit.
|
|
114
|
+
expect( onChange ).not.toHaveBeenCalled();
|
|
115
|
+
expect( screen.getByTestId( 'greeting' ) ).toHaveTextContent(
|
|
116
|
+
'updated'
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
// Enter edit mode to surface the Done button, then commit.
|
|
120
|
+
await userEvent.click(
|
|
121
|
+
screen.getByRole( 'button', { name: 'Customize' } )
|
|
122
|
+
);
|
|
123
|
+
await userEvent.click( screen.getByRole( 'button', { name: 'Done' } ) );
|
|
124
|
+
|
|
125
|
+
expect( onChange ).toHaveBeenCalledTimes( 1 );
|
|
126
|
+
const [ updated ] = onChange.mock.calls[ 0 ];
|
|
127
|
+
expect( updated ).toHaveLength( 1 );
|
|
128
|
+
expect( updated[ 0 ] ).toMatchObject( {
|
|
129
|
+
uuid: 'w1',
|
|
130
|
+
type: 'test/greet',
|
|
131
|
+
attributes: { greeting: 'updated' },
|
|
132
|
+
} );
|
|
133
|
+
} );
|
|
134
|
+
|
|
135
|
+
it( 'shows a loading placeholder while widget types are resolving', () => {
|
|
136
|
+
render(
|
|
137
|
+
<WidgetDashboard
|
|
138
|
+
layout={ [
|
|
139
|
+
{
|
|
140
|
+
uuid: 'w1',
|
|
141
|
+
type: 'test/greet',
|
|
142
|
+
placement: { width: 1, height: 1 },
|
|
143
|
+
},
|
|
144
|
+
] }
|
|
145
|
+
onLayoutChange={ () => {} }
|
|
146
|
+
widgetTypes={ [] }
|
|
147
|
+
isResolvingWidgetTypes
|
|
148
|
+
resolveWidgetModule={ resolveWidgetModule }
|
|
149
|
+
/>
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
expect(
|
|
153
|
+
screen.getByRole( 'region', { name: 'Loading' } )
|
|
154
|
+
).toBeInTheDocument();
|
|
155
|
+
expect(
|
|
156
|
+
screen.queryByText( 'Widget is no longer available.' )
|
|
157
|
+
).not.toBeInTheDocument();
|
|
158
|
+
} );
|
|
159
|
+
|
|
160
|
+
it( 'shows an unavailable placeholder for an unknown widget type (no crash)', () => {
|
|
161
|
+
render(
|
|
162
|
+
<WidgetDashboard
|
|
163
|
+
layout={ [
|
|
164
|
+
{
|
|
165
|
+
uuid: 'w1',
|
|
166
|
+
type: 'does/not-exist',
|
|
167
|
+
placement: { width: 1, height: 1 },
|
|
168
|
+
},
|
|
169
|
+
] }
|
|
170
|
+
onLayoutChange={ () => {} }
|
|
171
|
+
widgetTypes={ widgetTypes }
|
|
172
|
+
resolveWidgetModule={ resolveWidgetModule }
|
|
173
|
+
/>
|
|
174
|
+
);
|
|
175
|
+
expect( screen.queryByTestId( 'greeting' ) ).not.toBeInTheDocument();
|
|
176
|
+
expect(
|
|
177
|
+
screen.getByRole( 'region', { name: 'Missing widget' } )
|
|
178
|
+
).toBeInTheDocument();
|
|
179
|
+
expect(
|
|
180
|
+
screen.getByText( 'Widget is no longer available.' )
|
|
181
|
+
).toBeInTheDocument();
|
|
182
|
+
expect( screen.getByText( 'does/not-exist' ) ).toBeInTheDocument();
|
|
183
|
+
expect(
|
|
184
|
+
screen.queryByRole( 'heading', { level: 2 } )
|
|
185
|
+
).not.toBeInTheDocument();
|
|
186
|
+
} );
|
|
187
|
+
|
|
188
|
+
it( 'renders the NoWidgetsState compound when layout is empty', () => {
|
|
189
|
+
render(
|
|
190
|
+
<WidgetDashboard
|
|
191
|
+
layout={ [] }
|
|
192
|
+
onLayoutChange={ () => {} }
|
|
193
|
+
widgetTypes={ widgetTypes }
|
|
194
|
+
resolveWidgetModule={ resolveWidgetModule }
|
|
195
|
+
>
|
|
196
|
+
<WidgetDashboard.NoWidgetsState>
|
|
197
|
+
<p>Nothing here yet</p>
|
|
198
|
+
</WidgetDashboard.NoWidgetsState>
|
|
199
|
+
<WidgetDashboard.Widgets />
|
|
200
|
+
</WidgetDashboard>
|
|
201
|
+
);
|
|
202
|
+
expect( screen.getByText( 'Nothing here yet' ) ).toBeInTheDocument();
|
|
203
|
+
} );
|
|
204
|
+
} );
|