@wordpress/block-editor 12.9.1-next.5a1d1283.0 → 12.10.1
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 +6 -0
- package/README.md +33 -3
- package/build/components/block-canvas/index.js +107 -0
- package/build/components/block-canvas/index.js.map +1 -0
- package/build/components/block-inspector/index.js +4 -1
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-patterns-list/index.js +28 -8
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-patterns-paging/index.js +68 -0
- package/build/components/block-patterns-paging/index.js.map +1 -0
- package/build/components/block-settings-menu/block-settings-dropdown.js +28 -0
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +4 -7
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/block-styles/index.js +1 -0
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-toolbar/block-toolbar-menu.native.js +3 -7
- package/build/components/block-toolbar/block-toolbar-menu.native.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +18 -7
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/block-tools/block-selection-button.js +5 -1
- package/build/components/block-tools/block-selection-button.js.map +1 -1
- package/build/components/border-radius-control/input-controls.js +1 -1
- package/build/components/border-radius-control/input-controls.js.map +1 -1
- package/build/components/border-radius-control/linked-button.js +2 -4
- package/build/components/border-radius-control/linked-button.js.map +1 -1
- package/build/components/colors/with-colors.js.map +1 -1
- package/build/components/convert-to-group-buttons/use-convert-to-group-button-props.js +8 -21
- package/build/components/convert-to-group-buttons/use-convert-to-group-button-props.js.map +1 -1
- package/build/components/default-block-appender/index.native.js +20 -1
- package/build/components/default-block-appender/index.native.js.map +1 -1
- package/build/components/duotone/utils.js +68 -0
- package/build/components/duotone/utils.js.map +1 -1
- package/build/components/editor-styles/index.js +28 -9
- package/build/components/editor-styles/index.js.map +1 -1
- package/build/components/global-styles/hooks.js +2 -101
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/image-settings-panel.js +61 -0
- package/build/components/global-styles/image-settings-panel.js.map +1 -0
- package/build/components/global-styles/index.js +11 -17
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +19 -15
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +1 -1
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/iframe/index.js +67 -33
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/image-editor/use-save-image.js +2 -5
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/image-editor/use-transform-image.js +9 -9
- package/build/components/image-editor/use-transform-image.js.map +1 -1
- package/build/components/index.js +8 -12
- package/build/components/index.js.map +1 -1
- package/build/components/index.native.js +6 -5
- package/build/components/index.native.js.map +1 -1
- package/build/components/inner-blocks/use-nested-settings-update.js +13 -7
- package/build/components/inner-blocks/use-nested-settings-update.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/explorer.js +12 -6
- package/build/components/inserter/block-patterns-explorer/explorer.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/patterns-list.js +45 -22
- package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/sidebar.js +9 -9
- package/build/components/inserter/block-patterns-explorer/sidebar.js.map +1 -1
- package/build/components/inserter/block-patterns-filter.js +137 -0
- package/build/components/inserter/block-patterns-filter.js.map +1 -0
- package/build/components/inserter/block-patterns-tab.js +128 -42
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-paging.js +61 -0
- package/build/components/inserter/hooks/use-patterns-paging.js.map +1 -0
- package/build/components/inserter/hooks/use-patterns-state.js +21 -10
- package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build/components/inserter/menu.js +13 -11
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter/search-results.js +4 -3
- package/build/components/inserter/search-results.js.map +1 -1
- package/build/components/inserter/tabs.js +1 -12
- package/build/components/inserter/tabs.js.map +1 -1
- package/build/components/inspector-controls/block-support-slot-container.js +12 -1
- package/build/components/inspector-controls/block-support-slot-container.js.map +1 -1
- package/build/components/inspector-controls/fill.js +24 -13
- package/build/components/inspector-controls/fill.js.map +1 -1
- package/build/components/inspector-controls/groups.js +5 -3
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/inspector-controls/slot.js +13 -0
- package/build/components/inspector-controls/slot.js.map +1 -1
- package/build/components/inspector-controls-tabs/styles-tab.js +3 -0
- package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build/components/link-control/index.js +12 -2
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +1 -3
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +13 -1
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/use-block-selection.js +29 -24
- package/build/components/list-view/use-block-selection.js.map +1 -1
- package/build/components/media-placeholder/index.js +2 -2
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/media-placeholder/index.native.js +11 -11
- package/build/components/media-placeholder/index.native.js.map +1 -1
- package/build/components/media-replace-flow/index.js +2 -3
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/media-upload/constants.js +30 -0
- package/build/components/media-upload/constants.js.map +1 -0
- package/build/components/media-upload/index.native.js +63 -53
- package/build/components/media-upload/index.native.js.map +1 -1
- package/build/components/preview-options/index.js +1 -1
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/rich-text/index.js +34 -35
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +14 -32
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/rich-text/multiline.js +95 -0
- package/build/components/rich-text/multiline.js.map +1 -0
- package/build/components/rich-text/split-value.js +10 -16
- package/build/components/rich-text/split-value.js.map +1 -1
- package/build/components/rich-text/use-enter.js +31 -40
- package/build/components/rich-text/use-enter.js.map +1 -1
- package/build/components/rich-text/use-paste-handler.js +18 -33
- package/build/components/rich-text/use-paste-handler.js.map +1 -1
- package/build/components/spacing-sizes-control/utils.js +1 -1
- package/build/components/spacing-sizes-control/utils.js.map +1 -1
- package/build/components/use-block-commands/index.js +30 -18
- package/build/components/use-block-commands/index.js.map +1 -1
- package/build/components/use-block-display-information/index.js +5 -2
- package/build/components/use-block-display-information/index.js.map +1 -1
- package/build/hooks/background.js +263 -0
- package/build/hooks/background.js.map +1 -0
- package/build/hooks/block-hooks.js +188 -0
- package/build/hooks/block-hooks.js.map +1 -0
- package/build/hooks/block-rename-ui.js +161 -0
- package/build/hooks/block-rename-ui.js.map +1 -0
- package/build/hooks/duotone.js +29 -42
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/index.js +2 -2
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/layout.js +31 -14
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/position.js +4 -2
- package/build/hooks/position.js.map +1 -1
- package/build/hooks/style.js +10 -3
- package/build/hooks/style.js.map +1 -1
- package/build/private-apis.js +2 -0
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +33 -10
- package/build/store/actions.js.map +1 -1
- package/build/store/private-actions.js +42 -8
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +25 -3
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +43 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +84 -23
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils.js +0 -4
- package/build/store/utils.js.map +1 -1
- package/build-module/components/block-canvas/index.js +97 -0
- package/build-module/components/block-canvas/index.js.map +1 -0
- package/build-module/components/block-inspector/index.js +4 -1
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +30 -10
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-patterns-paging/index.js +61 -0
- package/build-module/components/block-patterns-paging/index.js.map +1 -0
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +28 -0
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +4 -7
- package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
- package/build-module/components/block-styles/index.js +1 -0
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-toolbar/block-toolbar-menu.native.js +3 -7
- package/build-module/components/block-toolbar/block-toolbar-menu.native.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +18 -7
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +5 -1
- package/build-module/components/block-tools/block-selection-button.js.map +1 -1
- package/build-module/components/border-radius-control/input-controls.js +1 -1
- package/build-module/components/border-radius-control/input-controls.js.map +1 -1
- package/build-module/components/border-radius-control/linked-button.js +2 -4
- package/build-module/components/border-radius-control/linked-button.js.map +1 -1
- package/build-module/components/colors/with-colors.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/use-convert-to-group-button-props.js +8 -21
- package/build-module/components/convert-to-group-buttons/use-convert-to-group-button-props.js.map +1 -1
- package/build-module/components/default-block-appender/index.native.js +20 -1
- package/build-module/components/default-block-appender/index.native.js.map +1 -1
- package/build-module/components/duotone/utils.js +65 -0
- package/build-module/components/duotone/utils.js.map +1 -1
- package/build-module/components/editor-styles/index.js +28 -9
- package/build-module/components/editor-styles/index.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +3 -100
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/image-settings-panel.js +53 -0
- package/build-module/components/global-styles/image-settings-panel.js.map +1 -0
- package/build-module/components/global-styles/index.js +2 -2
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +18 -16
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +1 -1
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/iframe/index.js +66 -33
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/image-editor/use-save-image.js +2 -5
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/image-editor/use-transform-image.js +9 -9
- package/build-module/components/image-editor/use-transform-image.js.map +1 -1
- package/build-module/components/index.js +1 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/index.native.js +2 -1
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inner-blocks/use-nested-settings-update.js +14 -8
- package/build-module/components/inner-blocks/use-nested-settings-update.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/explorer.js +12 -6
- package/build-module/components/inserter/block-patterns-explorer/explorer.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js +47 -24
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/sidebar.js +9 -9
- package/build-module/components/inserter/block-patterns-explorer/sidebar.js.map +1 -1
- package/build-module/components/inserter/block-patterns-filter.js +128 -0
- package/build-module/components/inserter/block-patterns-filter.js.map +1 -0
- package/build-module/components/inserter/block-patterns-tab.js +125 -44
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-paging.js +54 -0
- package/build-module/components/inserter/hooks/use-patterns-paging.js.map +1 -0
- package/build-module/components/inserter/hooks/use-patterns-state.js +22 -10
- package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build-module/components/inserter/menu.js +13 -11
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/search-results.js +4 -3
- package/build-module/components/inserter/search-results.js.map +1 -1
- package/build-module/components/inserter/tabs.js +1 -12
- package/build-module/components/inserter/tabs.js.map +1 -1
- package/build-module/components/inspector-controls/block-support-slot-container.js +13 -2
- package/build-module/components/inspector-controls/block-support-slot-container.js.map +1 -1
- package/build-module/components/inspector-controls/fill.js +25 -14
- package/build-module/components/inspector-controls/fill.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +5 -3
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/inspector-controls/slot.js +15 -1
- package/build-module/components/inspector-controls/slot.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/styles-tab.js +3 -0
- package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build-module/components/link-control/index.js +12 -2
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +1 -3
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +13 -1
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/use-block-selection.js +30 -25
- package/build-module/components/list-view/use-block-selection.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +2 -2
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/media-placeholder/index.native.js +7 -7
- package/build-module/components/media-placeholder/index.native.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +2 -3
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/media-upload/constants.js +14 -0
- package/build-module/components/media-upload/constants.js.map +1 -0
- package/build-module/components/media-upload/index.native.js +53 -34
- package/build-module/components/media-upload/index.native.js.map +1 -1
- package/build-module/components/preview-options/index.js +1 -1
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +35 -37
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +15 -33
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/rich-text/multiline.js +87 -0
- package/build-module/components/rich-text/multiline.js.map +1 -0
- package/build-module/components/rich-text/split-value.js +10 -16
- package/build-module/components/rich-text/split-value.js.map +1 -1
- package/build-module/components/rich-text/use-enter.js +33 -42
- package/build-module/components/rich-text/use-enter.js.map +1 -1
- package/build-module/components/rich-text/use-paste-handler.js +19 -34
- package/build-module/components/rich-text/use-paste-handler.js.map +1 -1
- package/build-module/components/spacing-sizes-control/utils.js +2 -2
- package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
- package/build-module/components/use-block-commands/index.js +28 -16
- package/build-module/components/use-block-commands/index.js.map +1 -1
- package/build-module/components/use-block-display-information/index.js +5 -2
- package/build-module/components/use-block-display-information/index.js.map +1 -1
- package/build-module/hooks/background.js +249 -0
- package/build-module/hooks/background.js.map +1 -0
- package/build-module/hooks/block-hooks.js +181 -0
- package/build-module/hooks/block-hooks.js.map +1 -0
- package/build-module/hooks/block-rename-ui.js +154 -0
- package/build-module/hooks/block-rename-ui.js.map +1 -0
- package/build-module/hooks/duotone.js +26 -39
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/index.js +2 -2
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/layout.js +33 -16
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/position.js +4 -2
- package/build-module/hooks/position.js.map +1 -1
- package/build-module/hooks/style.js +10 -3
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/private-apis.js +2 -0
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +33 -10
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/private-actions.js +39 -8
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +23 -3
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +41 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +78 -22
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils.js +0 -4
- package/build-module/store/utils.js.map +1 -1
- package/build-style/content-rtl.css +0 -1
- package/build-style/content.css +0 -1
- package/build-style/style-rtl.css +201 -131
- package/build-style/style.css +201 -131
- package/package.json +32 -32
- package/src/components/block-canvas/index.js +108 -0
- package/src/components/block-inspector/index.js +5 -1
- package/src/components/block-list/content.scss +0 -1
- package/src/components/block-patterns-list/index.js +53 -19
- package/src/components/block-patterns-list/style.scss +26 -9
- package/src/components/block-patterns-paging/index.js +92 -0
- package/src/components/block-patterns-paging/style.scss +45 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +44 -0
- package/src/components/block-settings-menu-controls/index.js +4 -9
- package/src/components/block-styles/index.js +1 -0
- package/src/components/block-styles/style.scss +3 -3
- package/src/components/block-toolbar/block-toolbar-menu.native.js +1 -6
- package/src/components/block-tools/block-contextual-toolbar.js +16 -5
- package/src/components/block-tools/block-selection-button.js +9 -1
- package/src/components/block-tools/style.scss +0 -98
- package/src/components/border-radius-control/input-controls.js +1 -1
- package/src/components/border-radius-control/linked-button.js +8 -11
- package/src/components/color-palette/test/__snapshots__/control.js.snap +34 -21
- package/src/components/colors/with-colors.js +3 -2
- package/src/components/convert-to-group-buttons/use-convert-to-group-button-props.js +8 -35
- package/src/components/default-block-appender/index.native.js +26 -3
- package/src/components/duotone/utils.js +65 -0
- package/src/components/editor-styles/index.js +32 -23
- package/src/components/global-styles/hooks.js +4 -112
- package/src/components/global-styles/image-settings-panel.js +71 -0
- package/src/components/global-styles/index.js +4 -3
- package/src/components/global-styles/use-global-styles-output.js +25 -16
- package/src/components/global-styles/utils.js +1 -2
- package/src/components/iframe/index.js +72 -33
- package/src/components/image-editor/use-save-image.js +2 -9
- package/src/components/image-editor/use-transform-image.js +9 -9
- package/src/components/index.js +1 -1
- package/src/components/index.native.js +2 -2
- package/src/components/inner-blocks/use-nested-settings-update.js +15 -10
- package/src/components/inserter/block-patterns-explorer/explorer.js +17 -5
- package/src/components/inserter/block-patterns-explorer/patterns-list.js +68 -43
- package/src/components/inserter/block-patterns-explorer/sidebar.js +8 -8
- package/src/components/inserter/block-patterns-filter.js +183 -0
- package/src/components/inserter/block-patterns-tab.js +217 -58
- package/src/components/inserter/hooks/use-patterns-paging.js +76 -0
- package/src/components/inserter/hooks/use-patterns-state.js +27 -16
- package/src/components/inserter/menu.js +15 -17
- package/src/components/inserter/search-results.js +6 -4
- package/src/components/inserter/style.scss +36 -7
- package/src/components/inserter/tabs.js +2 -12
- package/src/components/inserter/test/index.native.js +8 -12
- package/src/components/inspector-controls/block-support-slot-container.js +19 -3
- package/src/components/inspector-controls/fill.js +28 -14
- package/src/components/inspector-controls/groups.js +6 -2
- package/src/components/inspector-controls/slot.js +28 -3
- package/src/components/inspector-controls-tabs/styles-tab.js +4 -0
- package/src/components/link-control/index.js +13 -0
- package/src/components/link-control/style.scss +23 -2
- package/src/components/link-control/test/index.js +88 -6
- package/src/components/list-view/block-select-button.js +1 -3
- package/src/components/list-view/block.js +19 -1
- package/src/components/list-view/style.scss +1 -2
- package/src/components/list-view/use-block-selection.js +38 -32
- package/src/components/media-placeholder/README.md +2 -2
- package/src/components/media-placeholder/index.js +2 -2
- package/src/components/media-placeholder/index.native.js +11 -12
- package/src/components/media-replace-flow/index.js +2 -2
- package/src/components/media-replace-flow/test/index.js +5 -23
- package/src/components/media-upload/README.md +3 -2
- package/src/components/media-upload/constants.js +15 -0
- package/src/components/media-upload/index.native.js +66 -40
- package/src/components/media-upload/style.native.scss +4 -0
- package/src/components/media-upload/test/index.native.js +2 -2
- package/src/components/preview-options/README.md +7 -0
- package/src/components/preview-options/index.js +1 -1
- package/src/components/rich-text/index.js +48 -44
- package/src/components/rich-text/index.native.js +14 -42
- package/src/components/rich-text/multiline.js +121 -0
- package/src/components/rich-text/split-value.js +10 -35
- package/src/components/rich-text/use-enter.js +32 -42
- package/src/components/rich-text/use-paste-handler.js +16 -40
- package/src/components/spacing-sizes-control/style.scss +5 -7
- package/src/components/spacing-sizes-control/utils.js +1 -2
- package/src/components/use-block-commands/index.js +28 -20
- package/src/components/use-block-display-information/index.js +3 -0
- package/src/hooks/background.js +299 -0
- package/src/hooks/background.scss +75 -0
- package/src/hooks/block-hooks.js +257 -0
- package/src/hooks/block-hooks.scss +16 -0
- package/src/hooks/block-rename-ui.js +231 -0
- package/src/hooks/block-rename-ui.scss +3 -0
- package/src/hooks/duotone.js +42 -43
- package/src/hooks/index.js +2 -2
- package/src/hooks/layout.js +31 -33
- package/src/hooks/position.js +4 -3
- package/src/hooks/style.js +11 -2
- package/src/hooks/test/align.native.js +4 -3
- package/src/private-apis.js +2 -0
- package/src/store/actions.js +52 -10
- package/src/store/private-actions.js +37 -6
- package/src/store/private-selectors.js +28 -3
- package/src/store/reducer.js +38 -0
- package/src/store/selectors.js +107 -26
- package/src/store/test/actions.js +19 -8
- package/src/store/test/private-actions.js +17 -0
- package/src/store/test/reducer.js +25 -0
- package/src/store/test/selectors.js +130 -123
- package/src/store/utils.js +3 -10
- package/src/style.scss +4 -0
- package/build/components/duotone/components.js +0 -135
- package/build/components/duotone/components.js.map +0 -1
- package/build/components/duotone/index.js +0 -38
- package/build/components/duotone/index.js.map +0 -1
- package/build/components/global-styles/behaviors-panel.js +0 -64
- package/build/components/global-styles/behaviors-panel.js.map +0 -1
- package/build/components/inserter/reusable-blocks-tab.js +0 -85
- package/build/components/inserter/reusable-blocks-tab.js.map +0 -1
- package/build/hooks/auto-inserting-blocks.js +0 -174
- package/build/hooks/auto-inserting-blocks.js.map +0 -1
- package/build/hooks/behaviors.js +0 -173
- package/build/hooks/behaviors.js.map +0 -1
- package/build-module/components/duotone/components.js +0 -126
- package/build-module/components/duotone/components.js.map +0 -1
- package/build-module/components/duotone/index.js +0 -3
- package/build-module/components/duotone/index.js.map +0 -1
- package/build-module/components/global-styles/behaviors-panel.js +0 -57
- package/build-module/components/global-styles/behaviors-panel.js.map +0 -1
- package/build-module/components/inserter/reusable-blocks-tab.js +0 -76
- package/build-module/components/inserter/reusable-blocks-tab.js.map +0 -1
- package/build-module/hooks/auto-inserting-blocks.js +0 -167
- package/build-module/hooks/auto-inserting-blocks.js.map +0 -1
- package/build-module/hooks/behaviors.js +0 -166
- package/build-module/hooks/behaviors.js.map +0 -1
- package/src/components/duotone/components.js +0 -133
- package/src/components/duotone/index.js +0 -7
- package/src/components/global-styles/behaviors-panel.js +0 -71
- package/src/components/inserter/reusable-blocks-tab.js +0 -84
- package/src/components/inserter/test/reusable-blocks-tab.js +0 -73
- package/src/hooks/auto-inserting-blocks.js +0 -232
- package/src/hooks/behaviors.js +0 -206
|
@@ -8,17 +8,21 @@ import {
|
|
|
8
8
|
useRef,
|
|
9
9
|
useEffect,
|
|
10
10
|
} from '@wordpress/element';
|
|
11
|
-
import { _x, __, isRTL } from '@wordpress/i18n';
|
|
12
|
-
import {
|
|
11
|
+
import { _x, __, _n, isRTL, sprintf } from '@wordpress/i18n';
|
|
12
|
+
import { useViewportMatch } from '@wordpress/compose';
|
|
13
13
|
import {
|
|
14
14
|
__experimentalItemGroup as ItemGroup,
|
|
15
15
|
__experimentalItem as Item,
|
|
16
16
|
__experimentalHStack as HStack,
|
|
17
|
+
__experimentalVStack as VStack,
|
|
18
|
+
__experimentalHeading as Heading,
|
|
19
|
+
__experimentalText as Text,
|
|
17
20
|
FlexBlock,
|
|
18
21
|
Button,
|
|
19
22
|
} from '@wordpress/components';
|
|
20
23
|
import { Icon, chevronRight, chevronLeft } from '@wordpress/icons';
|
|
21
24
|
import { focus } from '@wordpress/dom';
|
|
25
|
+
import { speak } from '@wordpress/a11y';
|
|
22
26
|
|
|
23
27
|
/**
|
|
24
28
|
* Internal dependencies
|
|
@@ -27,29 +31,88 @@ import usePatternsState from './hooks/use-patterns-state';
|
|
|
27
31
|
import BlockPatternList from '../block-patterns-list';
|
|
28
32
|
import PatternsExplorerModal from './block-patterns-explorer/explorer';
|
|
29
33
|
import MobileTabNavigation from './mobile-tab-navigation';
|
|
34
|
+
import usePatternsPaging from './hooks/use-patterns-paging';
|
|
35
|
+
import {
|
|
36
|
+
BlockPatternsSyncFilter,
|
|
37
|
+
SYNC_TYPES,
|
|
38
|
+
PATTERN_TYPES,
|
|
39
|
+
} from './block-patterns-filter';
|
|
30
40
|
|
|
31
41
|
const noop = () => {};
|
|
32
42
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
'
|
|
40
|
-
'
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
'
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
export const allPatternsCategory = {
|
|
44
|
+
name: 'allPatterns',
|
|
45
|
+
label: __( 'All Patterns' ),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const myPatternsCategory = {
|
|
49
|
+
name: 'myPatterns',
|
|
50
|
+
label: __( 'My patterns' ),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export function isPatternFiltered( pattern, sourceFilter, syncFilter ) {
|
|
54
|
+
const isUserPattern = pattern.name.startsWith( 'core/block' );
|
|
55
|
+
const isDirectoryPattern =
|
|
56
|
+
pattern.source === 'core' ||
|
|
57
|
+
pattern.source?.startsWith( 'pattern-directory' );
|
|
58
|
+
|
|
59
|
+
// If theme source selected, filter out user created patterns and those from
|
|
60
|
+
// the core patterns directory.
|
|
61
|
+
if (
|
|
62
|
+
sourceFilter === PATTERN_TYPES.theme &&
|
|
63
|
+
( isUserPattern || isDirectoryPattern )
|
|
64
|
+
) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// If the directory source is selected, filter out user created patterns
|
|
69
|
+
// and those bundled with the theme.
|
|
70
|
+
if (
|
|
71
|
+
sourceFilter === PATTERN_TYPES.directory &&
|
|
72
|
+
( isUserPattern || ! isDirectoryPattern )
|
|
73
|
+
) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// If user source selected, filter out theme patterns. Any pattern without
|
|
78
|
+
// an id wasn't created by a user.
|
|
79
|
+
if ( sourceFilter === PATTERN_TYPES.user && ! pattern.id ) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Filter by sync status.
|
|
84
|
+
if ( syncFilter === SYNC_TYPES.full && pattern.syncStatus !== '' ) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (
|
|
89
|
+
syncFilter === SYNC_TYPES.unsynced &&
|
|
90
|
+
pattern.syncStatus !== 'unsynced' &&
|
|
91
|
+
isUserPattern
|
|
92
|
+
) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function usePatternsCategories( rootClientId, sourceFilter = 'all' ) {
|
|
100
|
+
const [ patterns, allCategories ] = usePatternsState(
|
|
49
101
|
undefined,
|
|
50
102
|
rootClientId
|
|
51
103
|
);
|
|
52
104
|
|
|
105
|
+
const filteredPatterns = useMemo(
|
|
106
|
+
() =>
|
|
107
|
+
sourceFilter === 'all'
|
|
108
|
+
? patterns
|
|
109
|
+
: patterns.filter(
|
|
110
|
+
( pattern ) =>
|
|
111
|
+
! isPatternFiltered( pattern, sourceFilter )
|
|
112
|
+
),
|
|
113
|
+
[ sourceFilter, patterns ]
|
|
114
|
+
);
|
|
115
|
+
|
|
53
116
|
const hasRegisteredCategory = useCallback(
|
|
54
117
|
( pattern ) => {
|
|
55
118
|
if ( ! pattern.categories || ! pattern.categories.length ) {
|
|
@@ -67,22 +130,14 @@ function usePatternsCategories( rootClientId ) {
|
|
|
67
130
|
const populatedCategories = useMemo( () => {
|
|
68
131
|
const categories = allCategories
|
|
69
132
|
.filter( ( category ) =>
|
|
70
|
-
|
|
133
|
+
filteredPatterns.some( ( pattern ) =>
|
|
71
134
|
pattern.categories?.includes( category.name )
|
|
72
135
|
)
|
|
73
136
|
)
|
|
74
|
-
.sort( (
|
|
75
|
-
// Sort categories according to `patternCategoriesOrder`.
|
|
76
|
-
let aIndex = patternCategoriesOrder.indexOf( aName );
|
|
77
|
-
let bIndex = patternCategoriesOrder.indexOf( bName );
|
|
78
|
-
// All other categories should come after that.
|
|
79
|
-
if ( aIndex < 0 ) aIndex = patternCategoriesOrder.length;
|
|
80
|
-
if ( bIndex < 0 ) bIndex = patternCategoriesOrder.length;
|
|
81
|
-
return aIndex - bIndex;
|
|
82
|
-
} );
|
|
137
|
+
.sort( ( a, b ) => a.label.localeCompare( b.label ) );
|
|
83
138
|
|
|
84
139
|
if (
|
|
85
|
-
|
|
140
|
+
filteredPatterns.some(
|
|
86
141
|
( pattern ) => ! hasRegisteredCategory( pattern )
|
|
87
142
|
) &&
|
|
88
143
|
! categories.find(
|
|
@@ -94,9 +149,28 @@ function usePatternsCategories( rootClientId ) {
|
|
|
94
149
|
label: _x( 'Uncategorized' ),
|
|
95
150
|
} );
|
|
96
151
|
}
|
|
97
|
-
|
|
152
|
+
if ( filteredPatterns.some( ( pattern ) => pattern.id ) ) {
|
|
153
|
+
categories.unshift( myPatternsCategory );
|
|
154
|
+
}
|
|
155
|
+
if ( filteredPatterns.length > 0 ) {
|
|
156
|
+
categories.unshift( {
|
|
157
|
+
name: allPatternsCategory.name,
|
|
158
|
+
label: allPatternsCategory.label,
|
|
159
|
+
} );
|
|
160
|
+
}
|
|
161
|
+
speak(
|
|
162
|
+
sprintf(
|
|
163
|
+
/* translators: %d: number of categories . */
|
|
164
|
+
_n(
|
|
165
|
+
'%d category button displayed.',
|
|
166
|
+
'%d category buttons displayed.',
|
|
167
|
+
categories.length
|
|
168
|
+
),
|
|
169
|
+
categories.length
|
|
170
|
+
)
|
|
171
|
+
);
|
|
98
172
|
return categories;
|
|
99
|
-
}, [ allCategories,
|
|
173
|
+
}, [ allCategories, filteredPatterns, hasRegisteredCategory ] );
|
|
100
174
|
|
|
101
175
|
return populatedCategories;
|
|
102
176
|
}
|
|
@@ -107,6 +181,7 @@ export function BlockPatternsCategoryDialog( {
|
|
|
107
181
|
onHover,
|
|
108
182
|
category,
|
|
109
183
|
showTitlesAsTooltip,
|
|
184
|
+
patternFilter,
|
|
110
185
|
} ) {
|
|
111
186
|
const container = useRef();
|
|
112
187
|
|
|
@@ -124,11 +199,13 @@ export function BlockPatternsCategoryDialog( {
|
|
|
124
199
|
className="block-editor-inserter__patterns-category-dialog"
|
|
125
200
|
>
|
|
126
201
|
<BlockPatternsCategoryPanel
|
|
202
|
+
key={ category.name }
|
|
127
203
|
rootClientId={ rootClientId }
|
|
128
204
|
onInsert={ onInsert }
|
|
129
205
|
onHover={ onHover }
|
|
130
206
|
category={ category }
|
|
131
207
|
showTitlesAsTooltip={ showTitlesAsTooltip }
|
|
208
|
+
patternFilter={ patternFilter }
|
|
132
209
|
/>
|
|
133
210
|
</div>
|
|
134
211
|
);
|
|
@@ -141,15 +218,37 @@ export function BlockPatternsCategoryPanel( {
|
|
|
141
218
|
category,
|
|
142
219
|
showTitlesAsTooltip,
|
|
143
220
|
} ) {
|
|
144
|
-
const [ allPatterns, ,
|
|
221
|
+
const [ allPatterns, , onClickPattern ] = usePatternsState(
|
|
145
222
|
onInsert,
|
|
146
223
|
rootClientId
|
|
147
224
|
);
|
|
225
|
+
const [ patternSyncFilter, setPatternSyncFilter ] = useState( 'all' );
|
|
226
|
+
const [ patternSourceFilter, setPatternSourceFilter ] = useState( 'all' );
|
|
148
227
|
|
|
149
|
-
const availableCategories = usePatternsCategories(
|
|
228
|
+
const availableCategories = usePatternsCategories(
|
|
229
|
+
rootClientId,
|
|
230
|
+
patternSourceFilter
|
|
231
|
+
);
|
|
232
|
+
const scrollContainerRef = useRef();
|
|
150
233
|
const currentCategoryPatterns = useMemo(
|
|
151
234
|
() =>
|
|
152
235
|
allPatterns.filter( ( pattern ) => {
|
|
236
|
+
if (
|
|
237
|
+
isPatternFiltered(
|
|
238
|
+
pattern,
|
|
239
|
+
patternSourceFilter,
|
|
240
|
+
patternSyncFilter
|
|
241
|
+
)
|
|
242
|
+
) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if ( category.name === allPatternsCategory.name ) {
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
if ( category.name === myPatternsCategory.name && pattern.id ) {
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
153
252
|
if ( category.name !== 'uncategorized' ) {
|
|
154
253
|
return pattern.categories?.includes( category.name );
|
|
155
254
|
}
|
|
@@ -166,35 +265,91 @@ export function BlockPatternsCategoryPanel( {
|
|
|
166
265
|
|
|
167
266
|
return availablePatternCategories.length === 0;
|
|
168
267
|
} ),
|
|
169
|
-
[
|
|
268
|
+
[
|
|
269
|
+
allPatterns,
|
|
270
|
+
availableCategories,
|
|
271
|
+
category.name,
|
|
272
|
+
patternSourceFilter,
|
|
273
|
+
patternSyncFilter,
|
|
274
|
+
]
|
|
170
275
|
);
|
|
171
276
|
|
|
172
|
-
const
|
|
277
|
+
const pagingProps = usePatternsPaging(
|
|
278
|
+
currentCategoryPatterns,
|
|
279
|
+
category,
|
|
280
|
+
scrollContainerRef
|
|
281
|
+
);
|
|
282
|
+
const { changePage } = pagingProps;
|
|
173
283
|
|
|
174
284
|
// Hide block pattern preview on unmount.
|
|
285
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
175
286
|
useEffect( () => () => onHover( null ), [] );
|
|
176
287
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
288
|
+
const onSetPatternSyncFilter = useCallback(
|
|
289
|
+
( value ) => {
|
|
290
|
+
setPatternSyncFilter( value );
|
|
291
|
+
changePage( 1 );
|
|
292
|
+
},
|
|
293
|
+
[ setPatternSyncFilter, changePage ]
|
|
294
|
+
);
|
|
295
|
+
const onSetPatternSourceFilter = useCallback(
|
|
296
|
+
( value ) => {
|
|
297
|
+
setPatternSourceFilter( value );
|
|
298
|
+
changePage( 1 );
|
|
299
|
+
},
|
|
300
|
+
[ setPatternSourceFilter, changePage ]
|
|
301
|
+
);
|
|
180
302
|
|
|
181
303
|
return (
|
|
182
304
|
<div className="block-editor-inserter__patterns-category-panel">
|
|
183
|
-
<
|
|
184
|
-
{
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
305
|
+
<VStack
|
|
306
|
+
spacing={ 2 }
|
|
307
|
+
className="block-editor-inserter__patterns-category-panel-header"
|
|
308
|
+
>
|
|
309
|
+
<HStack>
|
|
310
|
+
<FlexBlock>
|
|
311
|
+
<Heading level={ 4 } as="div">
|
|
312
|
+
{ category.label }
|
|
313
|
+
</Heading>
|
|
314
|
+
</FlexBlock>
|
|
315
|
+
<BlockPatternsSyncFilter
|
|
316
|
+
patternSyncFilter={ patternSyncFilter }
|
|
317
|
+
patternSourceFilter={ patternSourceFilter }
|
|
318
|
+
setPatternSyncFilter={ onSetPatternSyncFilter }
|
|
319
|
+
setPatternSourceFilter={ onSetPatternSourceFilter }
|
|
320
|
+
scrollContainerRef={ scrollContainerRef }
|
|
321
|
+
category={ category }
|
|
322
|
+
/>
|
|
323
|
+
</HStack>
|
|
324
|
+
{ category.description && (
|
|
325
|
+
<Text>{ category.description }</Text>
|
|
326
|
+
) }
|
|
327
|
+
{ ! currentCategoryPatterns.length && (
|
|
328
|
+
<Text
|
|
329
|
+
variant="muted"
|
|
330
|
+
className="block-editor-inserter__patterns-category-no-results"
|
|
331
|
+
>
|
|
332
|
+
{ __( 'No results found' ) }
|
|
333
|
+
</Text>
|
|
334
|
+
) }
|
|
335
|
+
</VStack>
|
|
336
|
+
|
|
337
|
+
{ currentCategoryPatterns.length > 0 && (
|
|
338
|
+
<BlockPatternList
|
|
339
|
+
ref={ scrollContainerRef }
|
|
340
|
+
shownPatterns={ pagingProps.categoryPatternsAsyncList }
|
|
341
|
+
blockPatterns={ pagingProps.categoryPatterns }
|
|
342
|
+
onClickPattern={ onClickPattern }
|
|
343
|
+
onHover={ onHover }
|
|
344
|
+
label={ category.label }
|
|
345
|
+
orientation="vertical"
|
|
346
|
+
category={ category.name }
|
|
347
|
+
isDraggable
|
|
348
|
+
showTitlesAsTooltip={ showTitlesAsTooltip }
|
|
349
|
+
patternFilter={ patternSourceFilter }
|
|
350
|
+
pagingProps={ pagingProps }
|
|
351
|
+
/>
|
|
352
|
+
) }
|
|
198
353
|
</div>
|
|
199
354
|
);
|
|
200
355
|
}
|
|
@@ -206,18 +361,20 @@ function BlockPatternsTabs( {
|
|
|
206
361
|
rootClientId,
|
|
207
362
|
} ) {
|
|
208
363
|
const [ showPatternsExplorer, setShowPatternsExplorer ] = useState( false );
|
|
364
|
+
|
|
209
365
|
const categories = usePatternsCategories( rootClientId );
|
|
366
|
+
|
|
210
367
|
const initialCategory = selectedCategory || categories[ 0 ];
|
|
211
368
|
const isMobile = useViewportMatch( 'medium', '<' );
|
|
212
369
|
return (
|
|
213
370
|
<>
|
|
214
371
|
{ ! isMobile && (
|
|
215
372
|
<div className="block-editor-inserter__block-patterns-tabs-container">
|
|
216
|
-
<nav
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
>
|
|
373
|
+
<nav
|
|
374
|
+
aria-label={ __( 'Block pattern categories' ) }
|
|
375
|
+
className="block-editor-inserter__block-patterns-tabs"
|
|
376
|
+
>
|
|
377
|
+
<ItemGroup role="list">
|
|
221
378
|
{ categories.map( ( category ) => (
|
|
222
379
|
<Item
|
|
223
380
|
role="listitem"
|
|
@@ -270,6 +427,7 @@ function BlockPatternsTabs( {
|
|
|
270
427
|
<MobileTabNavigation categories={ categories }>
|
|
271
428
|
{ ( category ) => (
|
|
272
429
|
<BlockPatternsCategoryPanel
|
|
430
|
+
key={ category.name }
|
|
273
431
|
onInsert={ onInsert }
|
|
274
432
|
rootClientId={ rootClientId }
|
|
275
433
|
category={ category }
|
|
@@ -283,6 +441,7 @@ function BlockPatternsTabs( {
|
|
|
283
441
|
initialCategory={ initialCategory }
|
|
284
442
|
patternCategories={ categories }
|
|
285
443
|
onModalClose={ () => setShowPatternsExplorer( false ) }
|
|
444
|
+
rootClientId={ rootClientId }
|
|
286
445
|
/>
|
|
287
446
|
) }
|
|
288
447
|
</>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useMemo, useState, useEffect } from '@wordpress/element';
|
|
5
|
+
import { useAsyncList, usePrevious } from '@wordpress/compose';
|
|
6
|
+
import { getScrollContainer } from '@wordpress/dom';
|
|
7
|
+
|
|
8
|
+
const PAGE_SIZE = 20;
|
|
9
|
+
const INITIAL_INSERTER_RESULTS = 5;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Supplies values needed to page the patterns list client side.
|
|
13
|
+
*
|
|
14
|
+
* @param {Array} currentCategoryPatterns An array of the current patterns to display.
|
|
15
|
+
* @param {string} currentCategory The currently selected category.
|
|
16
|
+
* @param {Object} scrollContainerRef Ref of container to to find scroll container for when moving between pages.
|
|
17
|
+
* @param {string} currentFilter The currently search filter.
|
|
18
|
+
*
|
|
19
|
+
* @return {Object} Returns the relevant paging values. (totalItems, categoryPatternsList, numPages, changePage, currentPage)
|
|
20
|
+
*/
|
|
21
|
+
export default function usePatternsPaging(
|
|
22
|
+
currentCategoryPatterns,
|
|
23
|
+
currentCategory,
|
|
24
|
+
scrollContainerRef,
|
|
25
|
+
currentFilter = ''
|
|
26
|
+
) {
|
|
27
|
+
const [ currentPage, setCurrentPage ] = useState( 1 );
|
|
28
|
+
const previousCategory = usePrevious( currentCategory );
|
|
29
|
+
const previousFilter = usePrevious( currentFilter );
|
|
30
|
+
if (
|
|
31
|
+
( previousCategory !== currentCategory ||
|
|
32
|
+
previousFilter !== currentFilter ) &&
|
|
33
|
+
currentPage !== 1
|
|
34
|
+
) {
|
|
35
|
+
setCurrentPage( 1 );
|
|
36
|
+
}
|
|
37
|
+
const totalItems = currentCategoryPatterns.length;
|
|
38
|
+
const pageIndex = currentPage - 1;
|
|
39
|
+
const categoryPatterns = useMemo( () => {
|
|
40
|
+
return currentCategoryPatterns.slice(
|
|
41
|
+
pageIndex * PAGE_SIZE,
|
|
42
|
+
pageIndex * PAGE_SIZE + PAGE_SIZE
|
|
43
|
+
);
|
|
44
|
+
}, [ pageIndex, currentCategoryPatterns ] );
|
|
45
|
+
const categoryPatternsAsyncList = useAsyncList( categoryPatterns, {
|
|
46
|
+
step: INITIAL_INSERTER_RESULTS,
|
|
47
|
+
} );
|
|
48
|
+
const numPages = Math.ceil( currentCategoryPatterns.length / PAGE_SIZE );
|
|
49
|
+
const changePage = ( page ) => {
|
|
50
|
+
const scrollContainer = getScrollContainer(
|
|
51
|
+
scrollContainerRef?.current
|
|
52
|
+
);
|
|
53
|
+
scrollContainer?.scrollTo( 0, 0 );
|
|
54
|
+
|
|
55
|
+
setCurrentPage( page );
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
useEffect(
|
|
59
|
+
function scrollToTopOnCategoryChange() {
|
|
60
|
+
const scrollContainer = getScrollContainer(
|
|
61
|
+
scrollContainerRef?.current
|
|
62
|
+
);
|
|
63
|
+
scrollContainer?.scrollTo( 0, 0 );
|
|
64
|
+
},
|
|
65
|
+
[ currentCategory, scrollContainerRef ]
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
totalItems,
|
|
70
|
+
categoryPatterns,
|
|
71
|
+
categoryPatternsAsyncList,
|
|
72
|
+
numPages,
|
|
73
|
+
changePage,
|
|
74
|
+
currentPage,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useCallback, useMemo } from '@wordpress/element';
|
|
5
|
-
import { cloneBlock } from '@wordpress/blocks';
|
|
5
|
+
import { cloneBlock, createBlock } from '@wordpress/blocks';
|
|
6
6
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
7
7
|
import { __, sprintf } from '@wordpress/i18n';
|
|
8
8
|
import { store as noticesStore } from '@wordpress/notices';
|
|
@@ -12,12 +12,6 @@ import { store as noticesStore } from '@wordpress/notices';
|
|
|
12
12
|
*/
|
|
13
13
|
import { store as blockEditorStore } from '../../../store';
|
|
14
14
|
|
|
15
|
-
const CUSTOM_CATEGORY = {
|
|
16
|
-
name: 'custom',
|
|
17
|
-
label: __( 'My patterns' ),
|
|
18
|
-
description: __( 'Custom patterns added by site users.' ),
|
|
19
|
-
};
|
|
20
|
-
|
|
21
15
|
/**
|
|
22
16
|
* Retrieves the block patterns inserter state.
|
|
23
17
|
*
|
|
@@ -27,30 +21,47 @@ const CUSTOM_CATEGORY = {
|
|
|
27
21
|
* @return {Array} Returns the patterns state. (patterns, categories, onSelect handler)
|
|
28
22
|
*/
|
|
29
23
|
const usePatternsState = ( onInsert, rootClientId ) => {
|
|
30
|
-
const { patternCategories, patterns } = useSelect(
|
|
24
|
+
const { patternCategories, patterns, userPatternCategories } = useSelect(
|
|
31
25
|
( select ) => {
|
|
32
26
|
const { __experimentalGetAllowedPatterns, getSettings } =
|
|
33
27
|
select( blockEditorStore );
|
|
34
|
-
|
|
28
|
+
const {
|
|
29
|
+
__experimentalUserPatternCategories,
|
|
30
|
+
__experimentalBlockPatternCategories,
|
|
31
|
+
} = getSettings();
|
|
35
32
|
return {
|
|
36
33
|
patterns: __experimentalGetAllowedPatterns( rootClientId ),
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
userPatternCategories: __experimentalUserPatternCategories,
|
|
35
|
+
patternCategories: __experimentalBlockPatternCategories,
|
|
39
36
|
};
|
|
40
37
|
},
|
|
41
38
|
[ rootClientId ]
|
|
42
39
|
);
|
|
43
40
|
|
|
44
|
-
const allCategories = useMemo(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
const allCategories = useMemo( () => {
|
|
42
|
+
const categories = [ ...patternCategories ];
|
|
43
|
+
userPatternCategories?.forEach( ( userCategory ) => {
|
|
44
|
+
if (
|
|
45
|
+
! categories.find(
|
|
46
|
+
( existingCategory ) =>
|
|
47
|
+
existingCategory.name === userCategory.name
|
|
48
|
+
)
|
|
49
|
+
) {
|
|
50
|
+
categories.push( userCategory );
|
|
51
|
+
}
|
|
52
|
+
} );
|
|
53
|
+
return categories;
|
|
54
|
+
}, [ patternCategories, userPatternCategories ] );
|
|
48
55
|
|
|
49
56
|
const { createSuccessNotice } = useDispatch( noticesStore );
|
|
50
57
|
const onClickPattern = useCallback(
|
|
51
58
|
( pattern, blocks ) => {
|
|
59
|
+
const patternBlocks =
|
|
60
|
+
pattern.id && pattern.syncStatus !== 'unsynced'
|
|
61
|
+
? [ createBlock( 'core/block', { ref: pattern.id } ) ]
|
|
62
|
+
: blocks;
|
|
52
63
|
onInsert(
|
|
53
|
-
(
|
|
64
|
+
( patternBlocks ?? [] ).map( ( block ) => cloneBlock( block ) ),
|
|
54
65
|
pattern.name
|
|
55
66
|
);
|
|
56
67
|
createSuccessNotice(
|
|
@@ -27,7 +27,6 @@ import BlockTypesTab from './block-types-tab';
|
|
|
27
27
|
import BlockPatternsTabs, {
|
|
28
28
|
BlockPatternsCategoryDialog,
|
|
29
29
|
} from './block-patterns-tab';
|
|
30
|
-
import ReusableBlocksTab from './reusable-blocks-tab';
|
|
31
30
|
import { MediaTab, MediaCategoryDialog, useMediaCategories } from './media-tab';
|
|
32
31
|
import InserterSearchResults from './search-results';
|
|
33
32
|
import useDebouncedInput from './hooks/use-debounced-input';
|
|
@@ -55,6 +54,7 @@ function InserterMenu(
|
|
|
55
54
|
const [ hoveredItem, setHoveredItem ] = useState( null );
|
|
56
55
|
const [ selectedPatternCategory, setSelectedPatternCategory ] =
|
|
57
56
|
useState( null );
|
|
57
|
+
const [ patternFilter, setPatternFilter ] = useState( 'all' );
|
|
58
58
|
const [ selectedMediaCategory, setSelectedMediaCategory ] =
|
|
59
59
|
useState( null );
|
|
60
60
|
const [ selectedTab, setSelectedTab ] = useState( null );
|
|
@@ -121,8 +121,9 @@ function InserterMenu(
|
|
|
121
121
|
);
|
|
122
122
|
|
|
123
123
|
const onClickPatternCategory = useCallback(
|
|
124
|
-
( patternCategory ) => {
|
|
124
|
+
( patternCategory, filter ) => {
|
|
125
125
|
setSelectedPatternCategory( patternCategory );
|
|
126
|
+
setPatternFilter( filter );
|
|
126
127
|
},
|
|
127
128
|
[ setSelectedPatternCategory ]
|
|
128
129
|
);
|
|
@@ -174,17 +175,6 @@ function InserterMenu(
|
|
|
174
175
|
]
|
|
175
176
|
);
|
|
176
177
|
|
|
177
|
-
const reusableBlocksTab = useMemo(
|
|
178
|
-
() => (
|
|
179
|
-
<ReusableBlocksTab
|
|
180
|
-
rootClientId={ destinationRootClientId }
|
|
181
|
-
onInsert={ onInsert }
|
|
182
|
-
onHover={ onHover }
|
|
183
|
-
/>
|
|
184
|
-
),
|
|
185
|
-
[ destinationRootClientId, onInsert, onHover ]
|
|
186
|
-
);
|
|
187
|
-
|
|
188
178
|
const mediaTab = useMemo(
|
|
189
179
|
() => (
|
|
190
180
|
<MediaTab
|
|
@@ -208,13 +198,11 @@ function InserterMenu(
|
|
|
208
198
|
return blocksTab;
|
|
209
199
|
} else if ( tab.name === 'patterns' ) {
|
|
210
200
|
return patternsTab;
|
|
211
|
-
} else if ( tab.name === 'reusable' ) {
|
|
212
|
-
return reusableBlocksTab;
|
|
213
201
|
} else if ( tab.name === 'media' ) {
|
|
214
202
|
return mediaTab;
|
|
215
203
|
}
|
|
216
204
|
},
|
|
217
|
-
[ blocksTab, patternsTab,
|
|
205
|
+
[ blocksTab, patternsTab, mediaTab ]
|
|
218
206
|
);
|
|
219
207
|
|
|
220
208
|
const searchRef = useRef();
|
|
@@ -235,6 +223,15 @@ function InserterMenu(
|
|
|
235
223
|
selectedTab === 'media' &&
|
|
236
224
|
! delayedFilterValue &&
|
|
237
225
|
selectedMediaCategory;
|
|
226
|
+
|
|
227
|
+
const handleSetSelectedTab = ( value ) => {
|
|
228
|
+
// If no longer on patterns tab remove the category setting.
|
|
229
|
+
if ( value !== 'patterns' ) {
|
|
230
|
+
setSelectedPatternCategory( null );
|
|
231
|
+
}
|
|
232
|
+
setSelectedTab( value );
|
|
233
|
+
};
|
|
234
|
+
|
|
238
235
|
return (
|
|
239
236
|
<div className="block-editor-inserter__menu">
|
|
240
237
|
<div
|
|
@@ -278,7 +275,7 @@ function InserterMenu(
|
|
|
278
275
|
showReusableBlocks={ hasReusableBlocks }
|
|
279
276
|
showMedia={ showMedia }
|
|
280
277
|
prioritizePatterns={ prioritizePatterns }
|
|
281
|
-
onSelect={
|
|
278
|
+
onSelect={ handleSetSelectedTab }
|
|
282
279
|
>
|
|
283
280
|
{ getCurrentTab }
|
|
284
281
|
</InserterTabs>
|
|
@@ -305,6 +302,7 @@ function InserterMenu(
|
|
|
305
302
|
onInsert={ onInsertPattern }
|
|
306
303
|
onHover={ onHoverPattern }
|
|
307
304
|
category={ selectedPatternCategory }
|
|
305
|
+
patternFilter={ patternFilter }
|
|
308
306
|
showTitlesAsTooltip
|
|
309
307
|
/>
|
|
310
308
|
) }
|
|
@@ -81,7 +81,7 @@ function InserterSearchResults( {
|
|
|
81
81
|
blockTypeCollections,
|
|
82
82
|
onSelectBlockType,
|
|
83
83
|
] = useBlockTypesState( destinationRootClientId, onInsertBlocks );
|
|
84
|
-
const [ patterns, ,
|
|
84
|
+
const [ patterns, , onClickPattern ] = usePatternsState(
|
|
85
85
|
onInsertBlocks,
|
|
86
86
|
destinationRootClientId
|
|
87
87
|
);
|
|
@@ -105,8 +105,10 @@ function InserterSearchResults( {
|
|
|
105
105
|
if ( maxBlockTypesToShow === 0 ) {
|
|
106
106
|
return [];
|
|
107
107
|
}
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
const nonPatternBlockTypes = blockTypes.filter(
|
|
109
|
+
( blockType ) => blockType.name !== 'core/block'
|
|
110
|
+
);
|
|
111
|
+
let orderedItems = orderBy( nonPatternBlockTypes, 'frecency', 'desc' );
|
|
110
112
|
|
|
111
113
|
if ( ! filterValue && prioritizedBlocks.length ) {
|
|
112
114
|
orderedItems = orderInserterBlockItems(
|
|
@@ -189,7 +191,7 @@ function InserterSearchResults( {
|
|
|
189
191
|
<BlockPatternsList
|
|
190
192
|
shownPatterns={ currentShownPatterns }
|
|
191
193
|
blockPatterns={ filteredBlockPatterns }
|
|
192
|
-
onClickPattern={
|
|
194
|
+
onClickPattern={ onClickPattern }
|
|
193
195
|
onHover={ onHoverPattern }
|
|
194
196
|
isDraggable={ isDraggable }
|
|
195
197
|
/>
|