@wordpress/block-editor 12.9.0 → 12.10.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 +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 +19 -4
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-patterns-paging/index.js +66 -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 +57 -23
- package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/sidebar.js +24 -9
- package/build/components/inserter/block-patterns-explorer/sidebar.js.map +1 -1
- package/build/components/inserter/block-patterns-source-filter.js +54 -0
- package/build/components/inserter/block-patterns-source-filter.js.map +1 -0
- package/build/components/inserter/block-patterns-sync-filter.js +46 -0
- package/build/components/inserter/block-patterns-sync-filter.js.map +1 -0
- package/build/components/inserter/block-patterns-tab.js +91 -45
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-paging.js +57 -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 +13 -2
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/settings.js +2 -1
- package/build/components/link-control/settings.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 +258 -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 +160 -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 +74 -25
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/utils.js +4 -0
- package/build/hooks/utils.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 +23 -0
- 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 +20 -5
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-patterns-paging/index.js +59 -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 +59 -25
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/sidebar.js +23 -9
- package/build-module/components/inserter/block-patterns-explorer/sidebar.js.map +1 -1
- package/build-module/components/inserter/block-patterns-source-filter.js +44 -0
- package/build-module/components/inserter/block-patterns-source-filter.js.map +1 -0
- package/build-module/components/inserter/block-patterns-sync-filter.js +38 -0
- package/build-module/components/inserter/block-patterns-sync-filter.js.map +1 -0
- package/build-module/components/inserter/block-patterns-tab.js +87 -46
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-paging.js +50 -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 +13 -2
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/settings.js +2 -1
- package/build-module/components/link-control/settings.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 +244 -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 +153 -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 +73 -24
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/utils.js +4 -0
- package/build-module/hooks/utils.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 +21 -0
- 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 +174 -131
- package/build-style/style.css +174 -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 +32 -7
- 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 +42 -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 +109 -40
- package/src/components/inserter/block-patterns-explorer/sidebar.js +23 -8
- package/src/components/inserter/block-patterns-source-filter.js +40 -0
- package/src/components/inserter/block-patterns-sync-filter.js +35 -0
- package/src/components/inserter/block-patterns-tab.js +168 -57
- package/src/components/inserter/hooks/use-patterns-paging.js +65 -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 +23 -2
- 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 +14 -0
- package/src/components/link-control/settings.js +1 -0
- package/src/components/link-control/style.scss +28 -7
- 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 +288 -0
- package/src/hooks/background.scss +57 -0
- package/src/hooks/block-hooks.js +257 -0
- package/src/hooks/block-hooks.scss +16 -0
- package/src/hooks/block-rename-ui.js +230 -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 +96 -37
- package/src/hooks/test/align.native.js +4 -3
- package/src/hooks/utils.js +4 -0
- 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 +21 -0
- 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
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { isBlobURL } from '@wordpress/blob';
|
|
5
|
+
import { getBlockSupport } from '@wordpress/blocks';
|
|
6
|
+
import {
|
|
7
|
+
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
8
|
+
Button,
|
|
9
|
+
DropZone,
|
|
10
|
+
FlexItem,
|
|
11
|
+
MenuItem,
|
|
12
|
+
__experimentalItemGroup as ItemGroup,
|
|
13
|
+
__experimentalHStack as HStack,
|
|
14
|
+
__experimentalTruncate as Truncate,
|
|
15
|
+
} from '@wordpress/components';
|
|
16
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
17
|
+
import { Platform, useCallback } from '@wordpress/element';
|
|
18
|
+
import { __ } from '@wordpress/i18n';
|
|
19
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
20
|
+
import { getFilename } from '@wordpress/url';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Internal dependencies
|
|
24
|
+
*/
|
|
25
|
+
import InspectorControls from '../components/inspector-controls';
|
|
26
|
+
import MediaReplaceFlow from '../components/media-replace-flow';
|
|
27
|
+
import MediaUpload from '../components/media-upload';
|
|
28
|
+
import MediaUploadCheck from '../components/media-upload/check';
|
|
29
|
+
import useSetting from '../components/use-setting';
|
|
30
|
+
import { cleanEmptyObject } from './utils';
|
|
31
|
+
import { store as blockEditorStore } from '../store';
|
|
32
|
+
|
|
33
|
+
export const BACKGROUND_SUPPORT_KEY = 'background';
|
|
34
|
+
export const IMAGE_BACKGROUND_TYPE = 'image';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Checks if there is a current value in the background image block support
|
|
38
|
+
* attributes.
|
|
39
|
+
*
|
|
40
|
+
* @param {Object} props Block props.
|
|
41
|
+
* @return {boolean} Whether or not the block has a background image value set.
|
|
42
|
+
*/
|
|
43
|
+
export function hasBackgroundImageValue( props ) {
|
|
44
|
+
const hasValue =
|
|
45
|
+
!! props.attributes.style?.background?.backgroundImage?.id ||
|
|
46
|
+
!! props.attributes.style?.background?.backgroundImage?.url;
|
|
47
|
+
|
|
48
|
+
return hasValue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Determine whether there is block support for background.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} blockName Block name.
|
|
55
|
+
* @param {string} feature Background image feature to check for.
|
|
56
|
+
*
|
|
57
|
+
* @return {boolean} Whether there is support.
|
|
58
|
+
*/
|
|
59
|
+
export function hasBackgroundSupport( blockName, feature = 'any' ) {
|
|
60
|
+
if ( Platform.OS !== 'web' ) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const support = getBlockSupport( blockName, BACKGROUND_SUPPORT_KEY );
|
|
65
|
+
|
|
66
|
+
if ( support === true ) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if ( feature === 'any' ) {
|
|
71
|
+
return !! support?.backgroundImage;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return !! support?.[ feature ];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Resets the background image block support attributes. This can be used when disabling
|
|
79
|
+
* the background image controls for a block via a `ToolsPanel`.
|
|
80
|
+
*
|
|
81
|
+
* @param {Object} props Block props.
|
|
82
|
+
* @param {Object} props.attributes Block's attributes.
|
|
83
|
+
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
84
|
+
*/
|
|
85
|
+
export function resetBackgroundImage( { attributes = {}, setAttributes } ) {
|
|
86
|
+
const { style = {} } = attributes;
|
|
87
|
+
|
|
88
|
+
setAttributes( {
|
|
89
|
+
style: cleanEmptyObject( {
|
|
90
|
+
...style,
|
|
91
|
+
background: {
|
|
92
|
+
...style?.background,
|
|
93
|
+
backgroundImage: undefined,
|
|
94
|
+
},
|
|
95
|
+
} ),
|
|
96
|
+
} );
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function InspectorImagePreview( { label, url: imgUrl } ) {
|
|
100
|
+
const imgLabel = label || getFilename( imgUrl );
|
|
101
|
+
return (
|
|
102
|
+
<ItemGroup as="span">
|
|
103
|
+
<HStack justify="flex-start" as="span">
|
|
104
|
+
<img src={ imgUrl } alt="" />
|
|
105
|
+
<FlexItem as="span">
|
|
106
|
+
<Truncate
|
|
107
|
+
numberOfLines={ 1 }
|
|
108
|
+
className="block-editor-hooks__background__inspector-media-replace-title"
|
|
109
|
+
>
|
|
110
|
+
{ imgLabel }
|
|
111
|
+
</Truncate>
|
|
112
|
+
</FlexItem>
|
|
113
|
+
</HStack>
|
|
114
|
+
</ItemGroup>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function BackgroundImagePanelItem( props ) {
|
|
119
|
+
const { attributes, clientId, setAttributes } = props;
|
|
120
|
+
|
|
121
|
+
const { id, title, url } =
|
|
122
|
+
attributes.style?.background?.backgroundImage || {};
|
|
123
|
+
|
|
124
|
+
const { mediaUpload } = useSelect( ( select ) => {
|
|
125
|
+
return {
|
|
126
|
+
mediaUpload: select( blockEditorStore ).getSettings().mediaUpload,
|
|
127
|
+
};
|
|
128
|
+
} );
|
|
129
|
+
|
|
130
|
+
const { createErrorNotice } = useDispatch( noticesStore );
|
|
131
|
+
const onUploadError = ( message ) => {
|
|
132
|
+
createErrorNotice( message, { type: 'snackbar' } );
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const onSelectMedia = ( media ) => {
|
|
136
|
+
if ( ! media || ! media.url ) {
|
|
137
|
+
const newStyle = {
|
|
138
|
+
...attributes.style,
|
|
139
|
+
background: {
|
|
140
|
+
...attributes.style?.background,
|
|
141
|
+
backgroundImage: undefined,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const newAttributes = {
|
|
146
|
+
style: cleanEmptyObject( newStyle ),
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
setAttributes( newAttributes );
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if ( isBlobURL( media.url ) ) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// For media selections originated from a file upload.
|
|
158
|
+
if (
|
|
159
|
+
( media.media_type &&
|
|
160
|
+
media.media_type !== IMAGE_BACKGROUND_TYPE ) ||
|
|
161
|
+
( ! media.media_type &&
|
|
162
|
+
media.type &&
|
|
163
|
+
media.type !== IMAGE_BACKGROUND_TYPE )
|
|
164
|
+
) {
|
|
165
|
+
onUploadError(
|
|
166
|
+
__( 'Only images can be used as a background image.' )
|
|
167
|
+
);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const newStyle = {
|
|
172
|
+
...attributes.style,
|
|
173
|
+
background: {
|
|
174
|
+
...attributes.style?.background,
|
|
175
|
+
backgroundImage: {
|
|
176
|
+
url: media.url,
|
|
177
|
+
id: media.id,
|
|
178
|
+
source: 'file',
|
|
179
|
+
title: media.title || undefined,
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const newAttributes = {
|
|
185
|
+
style: cleanEmptyObject( newStyle ),
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
setAttributes( newAttributes );
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const onFilesDrop = ( filesList ) => {
|
|
192
|
+
mediaUpload( {
|
|
193
|
+
allowedTypes: [ 'image' ],
|
|
194
|
+
filesList,
|
|
195
|
+
onFileChange( [ image ] ) {
|
|
196
|
+
if ( isBlobURL( image?.url ) ) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
onSelectMedia( image );
|
|
200
|
+
},
|
|
201
|
+
onError: onUploadError,
|
|
202
|
+
} );
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const resetAllFilter = useCallback( ( previousValue ) => {
|
|
206
|
+
return {
|
|
207
|
+
...previousValue,
|
|
208
|
+
style: {
|
|
209
|
+
...previousValue.style,
|
|
210
|
+
background: undefined,
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
}, [] );
|
|
214
|
+
|
|
215
|
+
return (
|
|
216
|
+
<ToolsPanelItem
|
|
217
|
+
className="single-column"
|
|
218
|
+
hasValue={ () => hasBackgroundImageValue( props ) }
|
|
219
|
+
label={ __( 'Background image' ) }
|
|
220
|
+
onDeselect={ () => resetBackgroundImage( props ) }
|
|
221
|
+
isShownByDefault={ true }
|
|
222
|
+
resetAllFilter={ resetAllFilter }
|
|
223
|
+
panelId={ clientId }
|
|
224
|
+
>
|
|
225
|
+
<div className="block-editor-hooks__background__inspector-media-replace-container">
|
|
226
|
+
{ !! url && (
|
|
227
|
+
<MediaReplaceFlow
|
|
228
|
+
mediaId={ id }
|
|
229
|
+
mediaURL={ url }
|
|
230
|
+
allowedTypes={ [ IMAGE_BACKGROUND_TYPE ] }
|
|
231
|
+
accept="image/*"
|
|
232
|
+
onSelect={ onSelectMedia }
|
|
233
|
+
name={
|
|
234
|
+
<InspectorImagePreview
|
|
235
|
+
label={ title }
|
|
236
|
+
url={ url }
|
|
237
|
+
/>
|
|
238
|
+
}
|
|
239
|
+
variant="secondary"
|
|
240
|
+
>
|
|
241
|
+
<MenuItem
|
|
242
|
+
onClick={ () => resetBackgroundImage( props ) }
|
|
243
|
+
>
|
|
244
|
+
{ __( 'Reset ' ) }
|
|
245
|
+
</MenuItem>
|
|
246
|
+
</MediaReplaceFlow>
|
|
247
|
+
) }
|
|
248
|
+
{ ! url && (
|
|
249
|
+
<MediaUploadCheck>
|
|
250
|
+
<MediaUpload
|
|
251
|
+
onSelect={ onSelectMedia }
|
|
252
|
+
allowedTypes={ [ IMAGE_BACKGROUND_TYPE ] }
|
|
253
|
+
render={ ( { open } ) => (
|
|
254
|
+
<div className="block-editor-hooks__background__inspector-upload-container">
|
|
255
|
+
<Button
|
|
256
|
+
onClick={ open }
|
|
257
|
+
variant="secondary"
|
|
258
|
+
>
|
|
259
|
+
{ __( 'Add background image' ) }
|
|
260
|
+
</Button>
|
|
261
|
+
<DropZone onFilesDrop={ onFilesDrop } />
|
|
262
|
+
</div>
|
|
263
|
+
) }
|
|
264
|
+
/>
|
|
265
|
+
</MediaUploadCheck>
|
|
266
|
+
) }
|
|
267
|
+
</div>
|
|
268
|
+
</ToolsPanelItem>
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function BackgroundImagePanel( props ) {
|
|
273
|
+
const isBackgroundImageSupported =
|
|
274
|
+
useSetting( 'background.backgroundImage' ) &&
|
|
275
|
+
hasBackgroundSupport( props.name, 'backgroundImage' );
|
|
276
|
+
|
|
277
|
+
if ( ! isBackgroundImageSupported ) {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<InspectorControls group="background">
|
|
283
|
+
{ isBackgroundImageSupported && (
|
|
284
|
+
<BackgroundImagePanelItem { ...props } />
|
|
285
|
+
) }
|
|
286
|
+
</InspectorControls>
|
|
287
|
+
);
|
|
288
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
.block-editor-hooks__background__inspector-upload-container {
|
|
2
|
+
position: relative;
|
|
3
|
+
// Since there is no option to skip rendering the drag'n'drop icon in drop
|
|
4
|
+
// zone, we hide it for now.
|
|
5
|
+
.components-drop-zone__content-icon {
|
|
6
|
+
display: none;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.block-editor-hooks__background__inspector-upload-container,
|
|
11
|
+
.block-editor-hooks__background__inspector-media-replace-container {
|
|
12
|
+
button.components-button {
|
|
13
|
+
color: $gray-900;
|
|
14
|
+
box-shadow: inset 0 0 0 1px $gray-400;
|
|
15
|
+
width: 100%;
|
|
16
|
+
display: block;
|
|
17
|
+
height: $grid-unit-50;
|
|
18
|
+
|
|
19
|
+
&:hover {
|
|
20
|
+
color: var(--wp-admin-theme-color);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&:focus {
|
|
24
|
+
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.block-editor-hooks__background__inspector-media-replace-title {
|
|
29
|
+
word-break: break-all;
|
|
30
|
+
// The Button component is white-space: nowrap, and that won't work with line-clamp.
|
|
31
|
+
white-space: normal;
|
|
32
|
+
|
|
33
|
+
// Without this, the ellipsis can sometimes be partially hidden by the Button padding.
|
|
34
|
+
text-align: start;
|
|
35
|
+
text-align-last: center;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.block-editor-hooks__background__inspector-media-replace-container {
|
|
40
|
+
.components-dropdown {
|
|
41
|
+
display: block;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
img {
|
|
45
|
+
width: 20px;
|
|
46
|
+
min-width: 20px;
|
|
47
|
+
aspect-ratio: 1;
|
|
48
|
+
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
|
|
49
|
+
border-radius: 50% !important;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.block-editor-hooks__background__inspector-readonly-logo-preview {
|
|
53
|
+
padding: 6px 12px;
|
|
54
|
+
display: flex;
|
|
55
|
+
height: $grid-unit-50;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { addFilter } from '@wordpress/hooks';
|
|
6
|
+
import { Fragment, useMemo } from '@wordpress/element';
|
|
7
|
+
import {
|
|
8
|
+
__experimentalHStack as HStack,
|
|
9
|
+
PanelBody,
|
|
10
|
+
ToggleControl,
|
|
11
|
+
} from '@wordpress/components';
|
|
12
|
+
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
13
|
+
import { createBlock, store as blocksStore } from '@wordpress/blocks';
|
|
14
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal dependencies
|
|
18
|
+
*/
|
|
19
|
+
import { BlockIcon, InspectorControls } from '../components';
|
|
20
|
+
import { store as blockEditorStore } from '../store';
|
|
21
|
+
|
|
22
|
+
const EMPTY_OBJECT = {};
|
|
23
|
+
|
|
24
|
+
function BlockHooksControl( props ) {
|
|
25
|
+
const blockTypes = useSelect(
|
|
26
|
+
( select ) => select( blocksStore ).getBlockTypes(),
|
|
27
|
+
[]
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const hookedBlocksForCurrentBlock = useMemo(
|
|
31
|
+
() =>
|
|
32
|
+
blockTypes?.filter(
|
|
33
|
+
( { blockHooks } ) =>
|
|
34
|
+
blockHooks && props.blockName in blockHooks
|
|
35
|
+
),
|
|
36
|
+
[ blockTypes, props.blockName ]
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const { blockIndex, rootClientId, innerBlocksLength } = useSelect(
|
|
40
|
+
( select ) => {
|
|
41
|
+
const { getBlock, getBlockIndex, getBlockRootClientId } =
|
|
42
|
+
select( blockEditorStore );
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
blockIndex: getBlockIndex( props.clientId ),
|
|
46
|
+
innerBlocksLength: getBlock( props.clientId )?.innerBlocks
|
|
47
|
+
?.length,
|
|
48
|
+
rootClientId: getBlockRootClientId( props.clientId ),
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
[ props.clientId ]
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const hookedBlockClientIds = useSelect(
|
|
55
|
+
( select ) => {
|
|
56
|
+
const { getBlock, getGlobalBlockCount } =
|
|
57
|
+
select( blockEditorStore );
|
|
58
|
+
|
|
59
|
+
const _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce(
|
|
60
|
+
( clientIds, block ) => {
|
|
61
|
+
// If the block doesn't exist anywhere in the block tree,
|
|
62
|
+
// we know that we have to display the toggle for it, and set
|
|
63
|
+
// it to disabled.
|
|
64
|
+
if ( getGlobalBlockCount( block.name ) === 0 ) {
|
|
65
|
+
return clientIds;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const relativePosition =
|
|
69
|
+
block?.blockHooks?.[ props.blockName ];
|
|
70
|
+
let candidates;
|
|
71
|
+
|
|
72
|
+
switch ( relativePosition ) {
|
|
73
|
+
case 'before':
|
|
74
|
+
case 'after':
|
|
75
|
+
// Any of the current block's siblings (with the right block type) qualifies
|
|
76
|
+
// as a hooked block (inserted `before` or `after` the current one), as the block
|
|
77
|
+
// might've been automatically inserted and then moved around a bit by the user.
|
|
78
|
+
candidates = getBlock( rootClientId )?.innerBlocks;
|
|
79
|
+
break;
|
|
80
|
+
|
|
81
|
+
case 'first_child':
|
|
82
|
+
case 'last_child':
|
|
83
|
+
// Any of the current block's child blocks (with the right block type) qualifies
|
|
84
|
+
// as a hooked first or last child block, as the block might've been automatically
|
|
85
|
+
// inserted and then moved around a bit by the user.
|
|
86
|
+
candidates = getBlock( props.clientId ).innerBlocks;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const hookedBlock = candidates?.find(
|
|
91
|
+
( { name } ) => name === block.name
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// If the block exists in the designated location, we consider it hooked
|
|
95
|
+
// and show the toggle as enabled.
|
|
96
|
+
if ( hookedBlock ) {
|
|
97
|
+
return {
|
|
98
|
+
...clientIds,
|
|
99
|
+
[ block.name ]: hookedBlock.clientId,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// If no hooked block was found in any of its designated locations,
|
|
104
|
+
// but it exists elsewhere in the block tree, we consider it manually inserted.
|
|
105
|
+
// In this case, we take note and will remove the corresponding toggle from the
|
|
106
|
+
// block inspector panel.
|
|
107
|
+
return {
|
|
108
|
+
...clientIds,
|
|
109
|
+
[ block.name ]: false,
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
{}
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
if ( Object.values( _hookedBlockClientIds ).length > 0 ) {
|
|
116
|
+
return _hookedBlockClientIds;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return EMPTY_OBJECT;
|
|
120
|
+
},
|
|
121
|
+
[
|
|
122
|
+
hookedBlocksForCurrentBlock,
|
|
123
|
+
props.blockName,
|
|
124
|
+
props.clientId,
|
|
125
|
+
rootClientId,
|
|
126
|
+
]
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const { insertBlock, removeBlock } = useDispatch( blockEditorStore );
|
|
130
|
+
|
|
131
|
+
// Remove toggle if block isn't present in the designated location but elsewhere in the block tree.
|
|
132
|
+
const hookedBlocksForCurrentBlockIfNotPresentElsewhere =
|
|
133
|
+
hookedBlocksForCurrentBlock?.filter(
|
|
134
|
+
( block ) => hookedBlockClientIds?.[ block.name ] !== false
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
if ( ! hookedBlocksForCurrentBlockIfNotPresentElsewhere.length ) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Group by block namespace (i.e. prefix before the slash).
|
|
142
|
+
const groupedHookedBlocks = hookedBlocksForCurrentBlock.reduce(
|
|
143
|
+
( groups, block ) => {
|
|
144
|
+
const [ namespace ] = block.name.split( '/' );
|
|
145
|
+
if ( ! groups[ namespace ] ) {
|
|
146
|
+
groups[ namespace ] = [];
|
|
147
|
+
}
|
|
148
|
+
groups[ namespace ].push( block );
|
|
149
|
+
return groups;
|
|
150
|
+
},
|
|
151
|
+
{}
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const insertBlockIntoDesignatedLocation = ( block, relativePosition ) => {
|
|
155
|
+
switch ( relativePosition ) {
|
|
156
|
+
case 'before':
|
|
157
|
+
case 'after':
|
|
158
|
+
insertBlock(
|
|
159
|
+
block,
|
|
160
|
+
relativePosition === 'after' ? blockIndex + 1 : blockIndex,
|
|
161
|
+
rootClientId, // Insert as a child of the current block's parent
|
|
162
|
+
false
|
|
163
|
+
);
|
|
164
|
+
break;
|
|
165
|
+
|
|
166
|
+
case 'first_child':
|
|
167
|
+
case 'last_child':
|
|
168
|
+
insertBlock(
|
|
169
|
+
block,
|
|
170
|
+
// TODO: It'd be great if insertBlock() would accept negative indices for insertion.
|
|
171
|
+
relativePosition === 'first_child' ? 0 : innerBlocksLength,
|
|
172
|
+
props.clientId, // Insert as a child of the current block.
|
|
173
|
+
false
|
|
174
|
+
);
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
return (
|
|
180
|
+
<InspectorControls>
|
|
181
|
+
<PanelBody
|
|
182
|
+
className="block-editor-hooks__block-hooks"
|
|
183
|
+
title={ __( 'Plugins' ) }
|
|
184
|
+
initialOpen={ true }
|
|
185
|
+
>
|
|
186
|
+
{ Object.keys( groupedHookedBlocks ).map( ( vendor ) => {
|
|
187
|
+
return (
|
|
188
|
+
<Fragment key={ vendor }>
|
|
189
|
+
<h3>{ vendor }</h3>
|
|
190
|
+
{ groupedHookedBlocks[ vendor ].map( ( block ) => {
|
|
191
|
+
const checked =
|
|
192
|
+
block.name in hookedBlockClientIds;
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
<ToggleControl
|
|
196
|
+
checked={ checked }
|
|
197
|
+
key={ block.title }
|
|
198
|
+
label={
|
|
199
|
+
<HStack justify="flex-start">
|
|
200
|
+
<BlockIcon
|
|
201
|
+
icon={ block.icon }
|
|
202
|
+
/>
|
|
203
|
+
<span>{ block.title }</span>
|
|
204
|
+
</HStack>
|
|
205
|
+
}
|
|
206
|
+
onChange={ () => {
|
|
207
|
+
if ( ! checked ) {
|
|
208
|
+
// Create and insert block.
|
|
209
|
+
const relativePosition =
|
|
210
|
+
block.blockHooks[
|
|
211
|
+
props.blockName
|
|
212
|
+
];
|
|
213
|
+
insertBlockIntoDesignatedLocation(
|
|
214
|
+
createBlock( block.name ),
|
|
215
|
+
relativePosition
|
|
216
|
+
);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Remove block.
|
|
221
|
+
const clientId =
|
|
222
|
+
hookedBlockClientIds[
|
|
223
|
+
block.name
|
|
224
|
+
];
|
|
225
|
+
removeBlock( clientId, false );
|
|
226
|
+
} }
|
|
227
|
+
/>
|
|
228
|
+
);
|
|
229
|
+
} ) }
|
|
230
|
+
</Fragment>
|
|
231
|
+
);
|
|
232
|
+
} ) }
|
|
233
|
+
</PanelBody>
|
|
234
|
+
</InspectorControls>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export const withBlockHooks = createHigherOrderComponent( ( BlockEdit ) => {
|
|
239
|
+
return ( props ) => {
|
|
240
|
+
const blockEdit = <BlockEdit key="edit" { ...props } />;
|
|
241
|
+
return (
|
|
242
|
+
<>
|
|
243
|
+
{ blockEdit }
|
|
244
|
+
<BlockHooksControl
|
|
245
|
+
blockName={ props.name }
|
|
246
|
+
clientId={ props.clientId }
|
|
247
|
+
/>
|
|
248
|
+
</>
|
|
249
|
+
);
|
|
250
|
+
};
|
|
251
|
+
}, 'withBlockHooks' );
|
|
252
|
+
|
|
253
|
+
addFilter(
|
|
254
|
+
'editor.BlockEdit',
|
|
255
|
+
'core/block-hooks/with-inspector-control',
|
|
256
|
+
withBlockHooks
|
|
257
|
+
);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.block-editor-hooks__block-hooks {
|
|
2
|
+
/**
|
|
3
|
+
* Since we're displaying the block icon alongside the block name,
|
|
4
|
+
* we need to right-align the toggle.
|
|
5
|
+
*/
|
|
6
|
+
.components-toggle-control .components-h-stack {
|
|
7
|
+
flex-direction: row-reverse;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Un-reverse the flex direction for the toggle's label.
|
|
12
|
+
*/
|
|
13
|
+
.components-toggle-control .components-h-stack .components-h-stack {
|
|
14
|
+
flex-direction: row;
|
|
15
|
+
}
|
|
16
|
+
}
|