@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,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.BACKGROUND_SUPPORT_KEY = void 0;
|
|
8
|
+
exports.BackgroundImagePanel = BackgroundImagePanel;
|
|
9
|
+
exports.IMAGE_BACKGROUND_TYPE = void 0;
|
|
10
|
+
exports.hasBackgroundImageValue = hasBackgroundImageValue;
|
|
11
|
+
exports.hasBackgroundSupport = hasBackgroundSupport;
|
|
12
|
+
exports.resetBackgroundImage = resetBackgroundImage;
|
|
13
|
+
var _element = require("@wordpress/element");
|
|
14
|
+
var _blob = require("@wordpress/blob");
|
|
15
|
+
var _blocks = require("@wordpress/blocks");
|
|
16
|
+
var _components = require("@wordpress/components");
|
|
17
|
+
var _data = require("@wordpress/data");
|
|
18
|
+
var _i18n = require("@wordpress/i18n");
|
|
19
|
+
var _notices = require("@wordpress/notices");
|
|
20
|
+
var _url = require("@wordpress/url");
|
|
21
|
+
var _inspectorControls = _interopRequireDefault(require("../components/inspector-controls"));
|
|
22
|
+
var _mediaReplaceFlow = _interopRequireDefault(require("../components/media-replace-flow"));
|
|
23
|
+
var _mediaUpload = _interopRequireDefault(require("../components/media-upload"));
|
|
24
|
+
var _check = _interopRequireDefault(require("../components/media-upload/check"));
|
|
25
|
+
var _useSetting = _interopRequireDefault(require("../components/use-setting"));
|
|
26
|
+
var _utils = require("./utils");
|
|
27
|
+
var _store = require("../store");
|
|
28
|
+
/**
|
|
29
|
+
* WordPress dependencies
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Internal dependencies
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
const BACKGROUND_SUPPORT_KEY = 'background';
|
|
37
|
+
exports.BACKGROUND_SUPPORT_KEY = BACKGROUND_SUPPORT_KEY;
|
|
38
|
+
const IMAGE_BACKGROUND_TYPE = 'image';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Checks if there is a current value in the background image block support
|
|
42
|
+
* attributes.
|
|
43
|
+
*
|
|
44
|
+
* @param {Object} props Block props.
|
|
45
|
+
* @return {boolean} Whether or not the block has a background image value set.
|
|
46
|
+
*/
|
|
47
|
+
exports.IMAGE_BACKGROUND_TYPE = IMAGE_BACKGROUND_TYPE;
|
|
48
|
+
function hasBackgroundImageValue(props) {
|
|
49
|
+
const hasValue = !!props.attributes.style?.background?.backgroundImage?.id || !!props.attributes.style?.background?.backgroundImage?.url;
|
|
50
|
+
return hasValue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Determine whether there is block support for background.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} blockName Block name.
|
|
57
|
+
* @param {string} feature Background image feature to check for.
|
|
58
|
+
*
|
|
59
|
+
* @return {boolean} Whether there is support.
|
|
60
|
+
*/
|
|
61
|
+
function hasBackgroundSupport(blockName, feature = 'any') {
|
|
62
|
+
if (_element.Platform.OS !== 'web') {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const support = (0, _blocks.getBlockSupport)(blockName, BACKGROUND_SUPPORT_KEY);
|
|
66
|
+
if (support === true) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
if (feature === 'any') {
|
|
70
|
+
return !!support?.backgroundImage;
|
|
71
|
+
}
|
|
72
|
+
return !!support?.[feature];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Resets the background image block support attributes. This can be used when disabling
|
|
77
|
+
* the background image controls for a block via a `ToolsPanel`.
|
|
78
|
+
*
|
|
79
|
+
* @param {Object} props Block props.
|
|
80
|
+
* @param {Object} props.attributes Block's attributes.
|
|
81
|
+
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
82
|
+
*/
|
|
83
|
+
function resetBackgroundImage({
|
|
84
|
+
attributes = {},
|
|
85
|
+
setAttributes
|
|
86
|
+
}) {
|
|
87
|
+
const {
|
|
88
|
+
style = {}
|
|
89
|
+
} = attributes;
|
|
90
|
+
setAttributes({
|
|
91
|
+
style: (0, _utils.cleanEmptyObject)({
|
|
92
|
+
...style,
|
|
93
|
+
background: {
|
|
94
|
+
...style?.background,
|
|
95
|
+
backgroundImage: undefined
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function InspectorImagePreview({
|
|
101
|
+
label,
|
|
102
|
+
url: imgUrl
|
|
103
|
+
}) {
|
|
104
|
+
const imgLabel = label || (0, _url.getFilename)(imgUrl);
|
|
105
|
+
return (0, _element.createElement)(_components.__experimentalItemGroup, {
|
|
106
|
+
as: "span"
|
|
107
|
+
}, (0, _element.createElement)(_components.__experimentalHStack, {
|
|
108
|
+
justify: "flex-start",
|
|
109
|
+
as: "span"
|
|
110
|
+
}, (0, _element.createElement)("img", {
|
|
111
|
+
src: imgUrl,
|
|
112
|
+
alt: ""
|
|
113
|
+
}), (0, _element.createElement)(_components.FlexItem, {
|
|
114
|
+
as: "span"
|
|
115
|
+
}, (0, _element.createElement)(_components.__experimentalTruncate, {
|
|
116
|
+
numberOfLines: 1,
|
|
117
|
+
className: "block-editor-hooks__background__inspector-media-replace-title"
|
|
118
|
+
}, imgLabel))));
|
|
119
|
+
}
|
|
120
|
+
function BackgroundImagePanelItem(props) {
|
|
121
|
+
const {
|
|
122
|
+
attributes,
|
|
123
|
+
clientId,
|
|
124
|
+
setAttributes
|
|
125
|
+
} = props;
|
|
126
|
+
const {
|
|
127
|
+
id,
|
|
128
|
+
title,
|
|
129
|
+
url
|
|
130
|
+
} = attributes.style?.background?.backgroundImage || {};
|
|
131
|
+
const {
|
|
132
|
+
mediaUpload
|
|
133
|
+
} = (0, _data.useSelect)(select => {
|
|
134
|
+
return {
|
|
135
|
+
mediaUpload: select(_store.store).getSettings().mediaUpload
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
const {
|
|
139
|
+
createErrorNotice
|
|
140
|
+
} = (0, _data.useDispatch)(_notices.store);
|
|
141
|
+
const onUploadError = message => {
|
|
142
|
+
createErrorNotice(message, {
|
|
143
|
+
type: 'snackbar'
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
const onSelectMedia = media => {
|
|
147
|
+
if (!media || !media.url) {
|
|
148
|
+
const newStyle = {
|
|
149
|
+
...attributes.style,
|
|
150
|
+
background: {
|
|
151
|
+
...attributes.style?.background,
|
|
152
|
+
backgroundImage: undefined
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const newAttributes = {
|
|
156
|
+
style: (0, _utils.cleanEmptyObject)(newStyle)
|
|
157
|
+
};
|
|
158
|
+
setAttributes(newAttributes);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if ((0, _blob.isBlobURL)(media.url)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// For media selections originated from a file upload.
|
|
166
|
+
if (media.media_type && media.media_type !== IMAGE_BACKGROUND_TYPE || !media.media_type && media.type && media.type !== IMAGE_BACKGROUND_TYPE) {
|
|
167
|
+
onUploadError((0, _i18n.__)('Only images can be used as a background image.'));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const newStyle = {
|
|
171
|
+
...attributes.style,
|
|
172
|
+
background: {
|
|
173
|
+
...attributes.style?.background,
|
|
174
|
+
backgroundImage: {
|
|
175
|
+
url: media.url,
|
|
176
|
+
id: media.id,
|
|
177
|
+
source: 'file',
|
|
178
|
+
title: media.title || undefined
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
const newAttributes = {
|
|
183
|
+
style: (0, _utils.cleanEmptyObject)(newStyle)
|
|
184
|
+
};
|
|
185
|
+
setAttributes(newAttributes);
|
|
186
|
+
};
|
|
187
|
+
const onFilesDrop = filesList => {
|
|
188
|
+
mediaUpload({
|
|
189
|
+
allowedTypes: ['image'],
|
|
190
|
+
filesList,
|
|
191
|
+
onFileChange([image]) {
|
|
192
|
+
if ((0, _blob.isBlobURL)(image?.url)) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
onSelectMedia(image);
|
|
196
|
+
},
|
|
197
|
+
onError: onUploadError
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
const resetAllFilter = (0, _element.useCallback)(previousValue => {
|
|
201
|
+
return {
|
|
202
|
+
...previousValue,
|
|
203
|
+
style: {
|
|
204
|
+
...previousValue.style,
|
|
205
|
+
background: undefined
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}, []);
|
|
209
|
+
return (0, _element.createElement)(_components.__experimentalToolsPanelItem, {
|
|
210
|
+
className: "single-column",
|
|
211
|
+
hasValue: () => hasBackgroundImageValue(props),
|
|
212
|
+
label: (0, _i18n.__)('Background image'),
|
|
213
|
+
onDeselect: () => resetBackgroundImage(props),
|
|
214
|
+
isShownByDefault: true,
|
|
215
|
+
resetAllFilter: resetAllFilter,
|
|
216
|
+
panelId: clientId
|
|
217
|
+
}, (0, _element.createElement)("div", {
|
|
218
|
+
className: "block-editor-hooks__background__inspector-media-replace-container"
|
|
219
|
+
}, !!url && (0, _element.createElement)(_mediaReplaceFlow.default, {
|
|
220
|
+
mediaId: id,
|
|
221
|
+
mediaURL: url,
|
|
222
|
+
allowedTypes: [IMAGE_BACKGROUND_TYPE],
|
|
223
|
+
accept: "image/*",
|
|
224
|
+
onSelect: onSelectMedia,
|
|
225
|
+
name: (0, _element.createElement)(InspectorImagePreview, {
|
|
226
|
+
label: title,
|
|
227
|
+
url: url
|
|
228
|
+
}),
|
|
229
|
+
variant: "secondary"
|
|
230
|
+
}, (0, _element.createElement)(_components.MenuItem, {
|
|
231
|
+
onClick: () => resetBackgroundImage(props)
|
|
232
|
+
}, (0, _i18n.__)('Reset '))), !url && (0, _element.createElement)(_check.default, null, (0, _element.createElement)(_mediaUpload.default, {
|
|
233
|
+
onSelect: onSelectMedia,
|
|
234
|
+
allowedTypes: [IMAGE_BACKGROUND_TYPE],
|
|
235
|
+
render: ({
|
|
236
|
+
open
|
|
237
|
+
}) => (0, _element.createElement)("div", {
|
|
238
|
+
className: "block-editor-hooks__background__inspector-upload-container"
|
|
239
|
+
}, (0, _element.createElement)(_components.Button, {
|
|
240
|
+
onClick: open,
|
|
241
|
+
variant: "secondary"
|
|
242
|
+
}, (0, _i18n.__)('Add background image')), (0, _element.createElement)(_components.DropZone, {
|
|
243
|
+
onFilesDrop: onFilesDrop
|
|
244
|
+
}))
|
|
245
|
+
}))));
|
|
246
|
+
}
|
|
247
|
+
function BackgroundImagePanel(props) {
|
|
248
|
+
const isBackgroundImageSupported = (0, _useSetting.default)('background.backgroundImage') && hasBackgroundSupport(props.name, 'backgroundImage');
|
|
249
|
+
if (!isBackgroundImageSupported) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
return (0, _element.createElement)(_inspectorControls.default, {
|
|
253
|
+
group: "background"
|
|
254
|
+
}, isBackgroundImageSupported && (0, _element.createElement)(BackgroundImagePanelItem, {
|
|
255
|
+
...props
|
|
256
|
+
}));
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=background.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_element","require","_blob","_blocks","_components","_data","_i18n","_notices","_url","_inspectorControls","_interopRequireDefault","_mediaReplaceFlow","_mediaUpload","_check","_useSetting","_utils","_store","BACKGROUND_SUPPORT_KEY","exports","IMAGE_BACKGROUND_TYPE","hasBackgroundImageValue","props","hasValue","attributes","style","background","backgroundImage","id","url","hasBackgroundSupport","blockName","feature","Platform","OS","support","getBlockSupport","resetBackgroundImage","setAttributes","cleanEmptyObject","undefined","InspectorImagePreview","label","imgUrl","imgLabel","getFilename","createElement","__experimentalItemGroup","as","__experimentalHStack","justify","src","alt","FlexItem","__experimentalTruncate","numberOfLines","className","BackgroundImagePanelItem","clientId","title","mediaUpload","useSelect","select","blockEditorStore","getSettings","createErrorNotice","useDispatch","noticesStore","onUploadError","message","type","onSelectMedia","media","newStyle","newAttributes","isBlobURL","media_type","__","source","onFilesDrop","filesList","allowedTypes","onFileChange","image","onError","resetAllFilter","useCallback","previousValue","__experimentalToolsPanelItem","onDeselect","isShownByDefault","panelId","default","mediaId","mediaURL","accept","onSelect","name","variant","MenuItem","onClick","render","open","Button","DropZone","BackgroundImagePanel","isBackgroundImageSupported","useSetting","group"],"sources":["@wordpress/block-editor/src/hooks/background.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { isBlobURL } from '@wordpress/blob';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\tButton,\n\tDropZone,\n\tFlexItem,\n\tMenuItem,\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalHStack as HStack,\n\t__experimentalTruncate as Truncate,\n} from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { Platform, useCallback } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { getFilename } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport InspectorControls from '../components/inspector-controls';\nimport MediaReplaceFlow from '../components/media-replace-flow';\nimport MediaUpload from '../components/media-upload';\nimport MediaUploadCheck from '../components/media-upload/check';\nimport useSetting from '../components/use-setting';\nimport { cleanEmptyObject } from './utils';\nimport { store as blockEditorStore } from '../store';\n\nexport const BACKGROUND_SUPPORT_KEY = 'background';\nexport const IMAGE_BACKGROUND_TYPE = 'image';\n\n/**\n * Checks if there is a current value in the background image block support\n * attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a background image value set.\n */\nexport function hasBackgroundImageValue( props ) {\n\tconst hasValue =\n\t\t!! props.attributes.style?.background?.backgroundImage?.id ||\n\t\t!! props.attributes.style?.background?.backgroundImage?.url;\n\n\treturn hasValue;\n}\n\n/**\n * Determine whether there is block support for background.\n *\n * @param {string} blockName Block name.\n * @param {string} feature Background image feature to check for.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasBackgroundSupport( blockName, feature = 'any' ) {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst support = getBlockSupport( blockName, BACKGROUND_SUPPORT_KEY );\n\n\tif ( support === true ) {\n\t\treturn true;\n\t}\n\n\tif ( feature === 'any' ) {\n\t\treturn !! support?.backgroundImage;\n\t}\n\n\treturn !! support?.[ feature ];\n}\n\n/**\n * Resets the background image block support attributes. This can be used when disabling\n * the background image controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetBackgroundImage( { attributes = {}, setAttributes } ) {\n\tconst { style = {} } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tbackground: {\n\t\t\t\t...style?.background,\n\t\t\t\tbackgroundImage: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\nfunction InspectorImagePreview( { label, url: imgUrl } ) {\n\tconst imgLabel = label || getFilename( imgUrl );\n\treturn (\n\t\t<ItemGroup as=\"span\">\n\t\t\t<HStack justify=\"flex-start\" as=\"span\">\n\t\t\t\t<img src={ imgUrl } alt=\"\" />\n\t\t\t\t<FlexItem as=\"span\">\n\t\t\t\t\t<Truncate\n\t\t\t\t\t\tnumberOfLines={ 1 }\n\t\t\t\t\t\tclassName=\"block-editor-hooks__background__inspector-media-replace-title\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ imgLabel }\n\t\t\t\t\t</Truncate>\n\t\t\t\t</FlexItem>\n\t\t\t</HStack>\n\t\t</ItemGroup>\n\t);\n}\n\nfunction BackgroundImagePanelItem( props ) {\n\tconst { attributes, clientId, setAttributes } = props;\n\n\tconst { id, title, url } =\n\t\tattributes.style?.background?.backgroundImage || {};\n\n\tconst { mediaUpload } = useSelect( ( select ) => {\n\t\treturn {\n\t\t\tmediaUpload: select( blockEditorStore ).getSettings().mediaUpload,\n\t\t};\n\t} );\n\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst onUploadError = ( message ) => {\n\t\tcreateErrorNotice( message, { type: 'snackbar' } );\n\t};\n\n\tconst onSelectMedia = ( media ) => {\n\t\tif ( ! media || ! media.url ) {\n\t\t\tconst newStyle = {\n\t\t\t\t...attributes.style,\n\t\t\t\tbackground: {\n\t\t\t\t\t...attributes.style?.background,\n\t\t\t\t\tbackgroundImage: undefined,\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst newAttributes = {\n\t\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t\t};\n\n\t\t\tsetAttributes( newAttributes );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isBlobURL( media.url ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// For media selections originated from a file upload.\n\t\tif (\n\t\t\t( media.media_type &&\n\t\t\t\tmedia.media_type !== IMAGE_BACKGROUND_TYPE ) ||\n\t\t\t( ! media.media_type &&\n\t\t\t\tmedia.type &&\n\t\t\t\tmedia.type !== IMAGE_BACKGROUND_TYPE )\n\t\t) {\n\t\t\tonUploadError(\n\t\t\t\t__( 'Only images can be used as a background image.' )\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst newStyle = {\n\t\t\t...attributes.style,\n\t\t\tbackground: {\n\t\t\t\t...attributes.style?.background,\n\t\t\t\tbackgroundImage: {\n\t\t\t\t\turl: media.url,\n\t\t\t\t\tid: media.id,\n\t\t\t\t\tsource: 'file',\n\t\t\t\t\ttitle: media.title || undefined,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\tconst newAttributes = {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t};\n\n\t\tsetAttributes( newAttributes );\n\t};\n\n\tconst onFilesDrop = ( filesList ) => {\n\t\tmediaUpload( {\n\t\t\tallowedTypes: [ 'image' ],\n\t\t\tfilesList,\n\t\t\tonFileChange( [ image ] ) {\n\t\t\t\tif ( isBlobURL( image?.url ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonSelectMedia( image );\n\t\t\t},\n\t\t\tonError: onUploadError,\n\t\t} );\n\t};\n\n\tconst resetAllFilter = useCallback( ( previousValue ) => {\n\t\treturn {\n\t\t\t...previousValue,\n\t\t\tstyle: {\n\t\t\t\t...previousValue.style,\n\t\t\t\tbackground: undefined,\n\t\t\t},\n\t\t};\n\t}, [] );\n\n\treturn (\n\t\t<ToolsPanelItem\n\t\t\tclassName=\"single-column\"\n\t\t\thasValue={ () => hasBackgroundImageValue( props ) }\n\t\t\tlabel={ __( 'Background image' ) }\n\t\t\tonDeselect={ () => resetBackgroundImage( props ) }\n\t\t\tisShownByDefault={ true }\n\t\t\tresetAllFilter={ resetAllFilter }\n\t\t\tpanelId={ clientId }\n\t\t>\n\t\t\t<div className=\"block-editor-hooks__background__inspector-media-replace-container\">\n\t\t\t\t{ !! url && (\n\t\t\t\t\t<MediaReplaceFlow\n\t\t\t\t\t\tmediaId={ id }\n\t\t\t\t\t\tmediaURL={ url }\n\t\t\t\t\t\tallowedTypes={ [ IMAGE_BACKGROUND_TYPE ] }\n\t\t\t\t\t\taccept=\"image/*\"\n\t\t\t\t\t\tonSelect={ onSelectMedia }\n\t\t\t\t\t\tname={\n\t\t\t\t\t\t\t<InspectorImagePreview\n\t\t\t\t\t\t\t\tlabel={ title }\n\t\t\t\t\t\t\t\turl={ url }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t}\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => resetBackgroundImage( props ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Reset ' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t</MediaReplaceFlow>\n\t\t\t\t) }\n\t\t\t\t{ ! url && (\n\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\t\tonSelect={ onSelectMedia }\n\t\t\t\t\t\t\tallowedTypes={ [ IMAGE_BACKGROUND_TYPE ] }\n\t\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t\t<div className=\"block-editor-hooks__background__inspector-upload-container\">\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\tonClick={ open }\n\t\t\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Add background image' ) }\n\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t\t<DropZone onFilesDrop={ onFilesDrop } />\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</MediaUploadCheck>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</ToolsPanelItem>\n\t);\n}\n\nexport function BackgroundImagePanel( props ) {\n\tconst isBackgroundImageSupported =\n\t\tuseSetting( 'background.backgroundImage' ) &&\n\t\thasBackgroundSupport( props.name, 'backgroundImage' );\n\n\tif ( ! isBackgroundImageSupported ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"background\">\n\t\t\t{ isBackgroundImageSupported && (\n\t\t\t\t<BackgroundImagePanelItem { ...props } />\n\t\t\t) }\n\t\t</InspectorControls>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,IAAAA,QAAA,GAAAC,OAAA;AAbA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAUA,IAAAI,KAAA,GAAAJ,OAAA;AAEA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AACA,IAAAO,IAAA,GAAAP,OAAA;AAKA,IAAAQ,kBAAA,GAAAC,sBAAA,CAAAT,OAAA;AACA,IAAAU,iBAAA,GAAAD,sBAAA,CAAAT,OAAA;AACA,IAAAW,YAAA,GAAAF,sBAAA,CAAAT,OAAA;AACA,IAAAY,MAAA,GAAAH,sBAAA,CAAAT,OAAA;AACA,IAAAa,WAAA,GAAAJ,sBAAA,CAAAT,OAAA;AACA,IAAAc,MAAA,GAAAd,OAAA;AACA,IAAAe,MAAA,GAAAf,OAAA;AA9BA;AACA;AACA;;AAmBA;AACA;AACA;;AASO,MAAMgB,sBAAsB,GAAG,YAAY;AAACC,OAAA,CAAAD,sBAAA,GAAAA,sBAAA;AAC5C,MAAME,qBAAqB,GAAG,OAAO;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AANAD,OAAA,CAAAC,qBAAA,GAAAA,qBAAA;AAOO,SAASC,uBAAuBA,CAAEC,KAAK,EAAG;EAChD,MAAMC,QAAQ,GACb,CAAC,CAAED,KAAK,CAACE,UAAU,CAACC,KAAK,EAAEC,UAAU,EAAEC,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+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.withBlockHooks = void 0;
|
|
7
|
+
var _element = require("@wordpress/element");
|
|
8
|
+
var _i18n = require("@wordpress/i18n");
|
|
9
|
+
var _hooks = require("@wordpress/hooks");
|
|
10
|
+
var _components = require("@wordpress/components");
|
|
11
|
+
var _compose = require("@wordpress/compose");
|
|
12
|
+
var _blocks = require("@wordpress/blocks");
|
|
13
|
+
var _data = require("@wordpress/data");
|
|
14
|
+
var _components2 = require("../components");
|
|
15
|
+
var _store = require("../store");
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const EMPTY_OBJECT = {};
|
|
25
|
+
function BlockHooksControl(props) {
|
|
26
|
+
const blockTypes = (0, _data.useSelect)(select => select(_blocks.store).getBlockTypes(), []);
|
|
27
|
+
const hookedBlocksForCurrentBlock = (0, _element.useMemo)(() => blockTypes?.filter(({
|
|
28
|
+
blockHooks
|
|
29
|
+
}) => blockHooks && props.blockName in blockHooks), [blockTypes, props.blockName]);
|
|
30
|
+
const {
|
|
31
|
+
blockIndex,
|
|
32
|
+
rootClientId,
|
|
33
|
+
innerBlocksLength
|
|
34
|
+
} = (0, _data.useSelect)(select => {
|
|
35
|
+
const {
|
|
36
|
+
getBlock,
|
|
37
|
+
getBlockIndex,
|
|
38
|
+
getBlockRootClientId
|
|
39
|
+
} = select(_store.store);
|
|
40
|
+
return {
|
|
41
|
+
blockIndex: getBlockIndex(props.clientId),
|
|
42
|
+
innerBlocksLength: getBlock(props.clientId)?.innerBlocks?.length,
|
|
43
|
+
rootClientId: getBlockRootClientId(props.clientId)
|
|
44
|
+
};
|
|
45
|
+
}, [props.clientId]);
|
|
46
|
+
const hookedBlockClientIds = (0, _data.useSelect)(select => {
|
|
47
|
+
const {
|
|
48
|
+
getBlock,
|
|
49
|
+
getGlobalBlockCount
|
|
50
|
+
} = select(_store.store);
|
|
51
|
+
const _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce((clientIds, block) => {
|
|
52
|
+
// If the block doesn't exist anywhere in the block tree,
|
|
53
|
+
// we know that we have to display the toggle for it, and set
|
|
54
|
+
// it to disabled.
|
|
55
|
+
if (getGlobalBlockCount(block.name) === 0) {
|
|
56
|
+
return clientIds;
|
|
57
|
+
}
|
|
58
|
+
const relativePosition = block?.blockHooks?.[props.blockName];
|
|
59
|
+
let candidates;
|
|
60
|
+
switch (relativePosition) {
|
|
61
|
+
case 'before':
|
|
62
|
+
case 'after':
|
|
63
|
+
// Any of the current block's siblings (with the right block type) qualifies
|
|
64
|
+
// as a hooked block (inserted `before` or `after` the current one), as the block
|
|
65
|
+
// might've been automatically inserted and then moved around a bit by the user.
|
|
66
|
+
candidates = getBlock(rootClientId)?.innerBlocks;
|
|
67
|
+
break;
|
|
68
|
+
case 'first_child':
|
|
69
|
+
case 'last_child':
|
|
70
|
+
// Any of the current block's child blocks (with the right block type) qualifies
|
|
71
|
+
// as a hooked first or last child block, as the block might've been automatically
|
|
72
|
+
// inserted and then moved around a bit by the user.
|
|
73
|
+
candidates = getBlock(props.clientId).innerBlocks;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
const hookedBlock = candidates?.find(({
|
|
77
|
+
name
|
|
78
|
+
}) => name === block.name);
|
|
79
|
+
|
|
80
|
+
// If the block exists in the designated location, we consider it hooked
|
|
81
|
+
// and show the toggle as enabled.
|
|
82
|
+
if (hookedBlock) {
|
|
83
|
+
return {
|
|
84
|
+
...clientIds,
|
|
85
|
+
[block.name]: hookedBlock.clientId
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// If no hooked block was found in any of its designated locations,
|
|
90
|
+
// but it exists elsewhere in the block tree, we consider it manually inserted.
|
|
91
|
+
// In this case, we take note and will remove the corresponding toggle from the
|
|
92
|
+
// block inspector panel.
|
|
93
|
+
return {
|
|
94
|
+
...clientIds,
|
|
95
|
+
[block.name]: false
|
|
96
|
+
};
|
|
97
|
+
}, {});
|
|
98
|
+
if (Object.values(_hookedBlockClientIds).length > 0) {
|
|
99
|
+
return _hookedBlockClientIds;
|
|
100
|
+
}
|
|
101
|
+
return EMPTY_OBJECT;
|
|
102
|
+
}, [hookedBlocksForCurrentBlock, props.blockName, props.clientId, rootClientId]);
|
|
103
|
+
const {
|
|
104
|
+
insertBlock,
|
|
105
|
+
removeBlock
|
|
106
|
+
} = (0, _data.useDispatch)(_store.store);
|
|
107
|
+
|
|
108
|
+
// Remove toggle if block isn't present in the designated location but elsewhere in the block tree.
|
|
109
|
+
const hookedBlocksForCurrentBlockIfNotPresentElsewhere = hookedBlocksForCurrentBlock?.filter(block => hookedBlockClientIds?.[block.name] !== false);
|
|
110
|
+
if (!hookedBlocksForCurrentBlockIfNotPresentElsewhere.length) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Group by block namespace (i.e. prefix before the slash).
|
|
115
|
+
const groupedHookedBlocks = hookedBlocksForCurrentBlock.reduce((groups, block) => {
|
|
116
|
+
const [namespace] = block.name.split('/');
|
|
117
|
+
if (!groups[namespace]) {
|
|
118
|
+
groups[namespace] = [];
|
|
119
|
+
}
|
|
120
|
+
groups[namespace].push(block);
|
|
121
|
+
return groups;
|
|
122
|
+
}, {});
|
|
123
|
+
const insertBlockIntoDesignatedLocation = (block, relativePosition) => {
|
|
124
|
+
switch (relativePosition) {
|
|
125
|
+
case 'before':
|
|
126
|
+
case 'after':
|
|
127
|
+
insertBlock(block, relativePosition === 'after' ? blockIndex + 1 : blockIndex, rootClientId,
|
|
128
|
+
// Insert as a child of the current block's parent
|
|
129
|
+
false);
|
|
130
|
+
break;
|
|
131
|
+
case 'first_child':
|
|
132
|
+
case 'last_child':
|
|
133
|
+
insertBlock(block,
|
|
134
|
+
// TODO: It'd be great if insertBlock() would accept negative indices for insertion.
|
|
135
|
+
relativePosition === 'first_child' ? 0 : innerBlocksLength, props.clientId,
|
|
136
|
+
// Insert as a child of the current block.
|
|
137
|
+
false);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
return (0, _element.createElement)(_components2.InspectorControls, null, (0, _element.createElement)(_components.PanelBody, {
|
|
142
|
+
className: "block-editor-hooks__block-hooks",
|
|
143
|
+
title: (0, _i18n.__)('Plugins'),
|
|
144
|
+
initialOpen: true
|
|
145
|
+
}, Object.keys(groupedHookedBlocks).map(vendor => {
|
|
146
|
+
return (0, _element.createElement)(_element.Fragment, {
|
|
147
|
+
key: vendor
|
|
148
|
+
}, (0, _element.createElement)("h3", null, vendor), groupedHookedBlocks[vendor].map(block => {
|
|
149
|
+
const checked = (block.name in hookedBlockClientIds);
|
|
150
|
+
return (0, _element.createElement)(_components.ToggleControl, {
|
|
151
|
+
checked: checked,
|
|
152
|
+
key: block.title,
|
|
153
|
+
label: (0, _element.createElement)(_components.__experimentalHStack, {
|
|
154
|
+
justify: "flex-start"
|
|
155
|
+
}, (0, _element.createElement)(_components2.BlockIcon, {
|
|
156
|
+
icon: block.icon
|
|
157
|
+
}), (0, _element.createElement)("span", null, block.title)),
|
|
158
|
+
onChange: () => {
|
|
159
|
+
if (!checked) {
|
|
160
|
+
// Create and insert block.
|
|
161
|
+
const relativePosition = block.blockHooks[props.blockName];
|
|
162
|
+
insertBlockIntoDesignatedLocation((0, _blocks.createBlock)(block.name), relativePosition);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Remove block.
|
|
167
|
+
const clientId = hookedBlockClientIds[block.name];
|
|
168
|
+
removeBlock(clientId, false);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}));
|
|
172
|
+
})));
|
|
173
|
+
}
|
|
174
|
+
const withBlockHooks = (0, _compose.createHigherOrderComponent)(BlockEdit => {
|
|
175
|
+
return props => {
|
|
176
|
+
const blockEdit = (0, _element.createElement)(BlockEdit, {
|
|
177
|
+
key: "edit",
|
|
178
|
+
...props
|
|
179
|
+
});
|
|
180
|
+
return (0, _element.createElement)(_element.Fragment, null, blockEdit, (0, _element.createElement)(BlockHooksControl, {
|
|
181
|
+
blockName: props.name,
|
|
182
|
+
clientId: props.clientId
|
|
183
|
+
}));
|
|
184
|
+
};
|
|
185
|
+
}, 'withBlockHooks');
|
|
186
|
+
exports.withBlockHooks = withBlockHooks;
|
|
187
|
+
(0, _hooks.addFilter)('editor.BlockEdit', 'core/block-hooks/with-inspector-control', withBlockHooks);
|
|
188
|
+
//# sourceMappingURL=block-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_element","require","_i18n","_hooks","_components","_compose","_blocks","_data","_components2","_store","EMPTY_OBJECT","BlockHooksControl","props","blockTypes","useSelect","select","blocksStore","getBlockTypes","hookedBlocksForCurrentBlock","useMemo","filter","blockHooks","blockName","blockIndex","rootClientId","innerBlocksLength","getBlock","getBlockIndex","getBlockRootClientId","blockEditorStore","clientId","innerBlocks","length","hookedBlockClientIds","getGlobalBlockCount","_hookedBlockClientIds","reduce","clientIds","block","name","relativePosition","candidates","hookedBlock","find","Object","values","insertBlock","removeBlock","useDispatch","hookedBlocksForCurrentBlockIfNotPresentElsewhere","groupedHookedBlocks","groups","namespace","split","push","insertBlockIntoDesignatedLocation","createElement","InspectorControls","PanelBody","className","title","__","initialOpen","keys","map","vendor","Fragment","key","checked","ToggleControl","label","__experimentalHStack","justify","BlockIcon","icon","onChange","createBlock","withBlockHooks","createHigherOrderComponent","BlockEdit","blockEdit","exports","addFilter"],"sources":["@wordpress/block-editor/src/hooks/block-hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { addFilter } from '@wordpress/hooks';\nimport { Fragment, useMemo } from '@wordpress/element';\nimport {\n\t__experimentalHStack as HStack,\n\tPanelBody,\n\tToggleControl,\n} from '@wordpress/components';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { createBlock, store as blocksStore } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { BlockIcon, InspectorControls } from '../components';\nimport { store as blockEditorStore } from '../store';\n\nconst EMPTY_OBJECT = {};\n\nfunction BlockHooksControl( props ) {\n\tconst blockTypes = useSelect(\n\t\t( select ) => select( blocksStore ).getBlockTypes(),\n\t\t[]\n\t);\n\n\tconst hookedBlocksForCurrentBlock = useMemo(\n\t\t() =>\n\t\t\tblockTypes?.filter(\n\t\t\t\t( { blockHooks } ) =>\n\t\t\t\t\tblockHooks && props.blockName in blockHooks\n\t\t\t),\n\t\t[ blockTypes, props.blockName ]\n\t);\n\n\tconst { blockIndex, rootClientId, innerBlocksLength } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, getBlockIndex, getBlockRootClientId } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\tblockIndex: getBlockIndex( props.clientId ),\n\t\t\t\tinnerBlocksLength: getBlock( props.clientId )?.innerBlocks\n\t\t\t\t\t?.length,\n\t\t\t\trootClientId: getBlockRootClientId( props.clientId ),\n\t\t\t};\n\t\t},\n\t\t[ props.clientId ]\n\t);\n\n\tconst hookedBlockClientIds = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, getGlobalBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\tconst _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce(\n\t\t\t\t( clientIds, block ) => {\n\t\t\t\t\t// If the block doesn't exist anywhere in the block tree,\n\t\t\t\t\t// we know that we have to display the toggle for it, and set\n\t\t\t\t\t// it to disabled.\n\t\t\t\t\tif ( getGlobalBlockCount( block.name ) === 0 ) {\n\t\t\t\t\t\treturn clientIds;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst relativePosition =\n\t\t\t\t\t\tblock?.blockHooks?.[ props.blockName ];\n\t\t\t\t\tlet candidates;\n\n\t\t\t\t\tswitch ( relativePosition ) {\n\t\t\t\t\t\tcase 'before':\n\t\t\t\t\t\tcase 'after':\n\t\t\t\t\t\t\t// Any of the current block's siblings (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked block (inserted `before` or `after` the current one), as the block\n\t\t\t\t\t\t\t// might've been automatically inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlock( rootClientId )?.innerBlocks;\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tcase 'first_child':\n\t\t\t\t\t\tcase 'last_child':\n\t\t\t\t\t\t\t// Any of the current block's child blocks (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked first or last child block, as the block might've been automatically\n\t\t\t\t\t\t\t// inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlock( props.clientId ).innerBlocks;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst hookedBlock = candidates?.find(\n\t\t\t\t\t\t( { name } ) => name === block.name\n\t\t\t\t\t);\n\n\t\t\t\t\t// If the block exists in the designated location, we consider it hooked\n\t\t\t\t\t// and show the toggle as enabled.\n\t\t\t\t\tif ( hookedBlock ) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...clientIds,\n\t\t\t\t\t\t\t[ block.name ]: hookedBlock.clientId,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// If no hooked block was found in any of its designated locations,\n\t\t\t\t\t// but it exists elsewhere in the block tree, we consider it manually inserted.\n\t\t\t\t\t// In this case, we take note and will remove the corresponding toggle from the\n\t\t\t\t\t// block inspector panel.\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...clientIds,\n\t\t\t\t\t\t[ block.name ]: false,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tif ( Object.values( _hookedBlockClientIds ).length > 0 ) {\n\t\t\t\treturn _hookedBlockClientIds;\n\t\t\t}\n\n\t\t\treturn EMPTY_OBJECT;\n\t\t},\n\t\t[\n\t\t\thookedBlocksForCurrentBlock,\n\t\t\tprops.blockName,\n\t\t\tprops.clientId,\n\t\t\trootClientId,\n\t\t]\n\t);\n\n\tconst { insertBlock, removeBlock } = useDispatch( blockEditorStore );\n\n\t// Remove toggle if block isn't present in the designated location but elsewhere in the block tree.\n\tconst hookedBlocksForCurrentBlockIfNotPresentElsewhere =\n\t\thookedBlocksForCurrentBlock?.filter(\n\t\t\t( block ) => hookedBlockClientIds?.[ block.name ] !== false\n\t\t);\n\n\tif ( ! hookedBlocksForCurrentBlockIfNotPresentElsewhere.length ) {\n\t\treturn null;\n\t}\n\n\t// Group by block namespace (i.e. prefix before the slash).\n\tconst groupedHookedBlocks = hookedBlocksForCurrentBlock.reduce(\n\t\t( groups, block ) => {\n\t\t\tconst [ namespace ] = block.name.split( '/' );\n\t\t\tif ( ! groups[ namespace ] ) {\n\t\t\t\tgroups[ namespace ] = [];\n\t\t\t}\n\t\t\tgroups[ namespace ].push( block );\n\t\t\treturn groups;\n\t\t},\n\t\t{}\n\t);\n\n\tconst insertBlockIntoDesignatedLocation = ( block, relativePosition ) => {\n\t\tswitch ( relativePosition ) {\n\t\t\tcase 'before':\n\t\t\tcase 'after':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\trelativePosition === 'after' ? blockIndex + 1 : blockIndex,\n\t\t\t\t\trootClientId, // Insert as a child of the current block's parent\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\n\t\t\tcase 'first_child':\n\t\t\tcase 'last_child':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\t// TODO: It'd be great if insertBlock() would accept negative indices for insertion.\n\t\t\t\t\trelativePosition === 'first_child' ? 0 : innerBlocksLength,\n\t\t\t\t\tprops.clientId, // Insert as a child of the current block.\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn (\n\t\t<InspectorControls>\n\t\t\t<PanelBody\n\t\t\t\tclassName=\"block-editor-hooks__block-hooks\"\n\t\t\t\ttitle={ __( 'Plugins' ) }\n\t\t\t\tinitialOpen={ true }\n\t\t\t>\n\t\t\t\t{ Object.keys( groupedHookedBlocks ).map( ( vendor ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Fragment key={ vendor }>\n\t\t\t\t\t\t\t<h3>{ vendor }</h3>\n\t\t\t\t\t\t\t{ groupedHookedBlocks[ vendor ].map( ( block ) => {\n\t\t\t\t\t\t\t\tconst checked =\n\t\t\t\t\t\t\t\t\tblock.name in hookedBlockClientIds;\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t\t\tchecked={ checked }\n\t\t\t\t\t\t\t\t\t\tkey={ block.title }\n\t\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\t\t<HStack justify=\"flex-start\">\n\t\t\t\t\t\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\t\t\t\t\t\ticon={ block.icon }\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t<span>{ block.title }</span>\n\t\t\t\t\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\tif ( ! checked ) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Create and insert block.\n\t\t\t\t\t\t\t\t\t\t\t\tconst relativePosition =\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.blockHooks[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tprops.blockName\n\t\t\t\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t\t\t\tinsertBlockIntoDesignatedLocation(\n\t\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock( block.name ),\n\t\t\t\t\t\t\t\t\t\t\t\t\trelativePosition\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t// Remove block.\n\t\t\t\t\t\t\t\t\t\t\tconst clientId =\n\t\t\t\t\t\t\t\t\t\t\t\thookedBlockClientIds[\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.name\n\t\t\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t\t\tremoveBlock( clientId, false );\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</Fragment>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n}\n\nexport const withBlockHooks = createHigherOrderComponent( ( BlockEdit ) => {\n\treturn ( props ) => {\n\t\tconst blockEdit = <BlockEdit key=\"edit\" { ...props } />;\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ blockEdit }\n\t\t\t\t<BlockHooksControl\n\t\t\t\t\tblockName={ props.name }\n\t\t\t\t\tclientId={ props.clientId }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t};\n}, 'withBlockHooks' );\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/block-hooks/with-inspector-control',\n\twithBlockHooks\n);\n"],"mappings":";;;;;;AAKA,IAAAA,QAAA,GAAAC,OAAA;AAFA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AAKA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AAKA,IAAAO,YAAA,GAAAP,OAAA;AACA,IAAA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GAAG,IAAAC,mCAA0B,EAAIC,SAAS,IAAM;EAC1E,OAASnE,KAAK,IAAM;IACnB,MAAMoE,SAAS,GAAG,IAAAhF,QAAA,CAAAwD,aAAA,EAACuB,SAAS;MAACZ,GAAG,EAAC,MAAM;MAAA,GAAMvD;IAAK,CAAI,CAAC;IACvD,OACC,IAAAZ,QAAA,CAAAwD,aAAA,EAAAxD,QAAA,CAAAkE,QAAA,QACGc,SAAS,EACX,IAAAhF,QAAA,CAAAwD,aAAA,EAAC7C,iBAAiB;MACjBW,SAAS,EAAGV,KAAK,CAAC2B,IAAM;MACxBT,QAAQ,EAAGlB,KAAK,CAACkB;IAAU,CAC3B,CACA,CAAC;EAEL,CAAC;AACF,CAAC,EAAE,gBAAiB,CAAC;AAACmD,OAAA,CAAAJ,cAAA,GAAAA,cAAA;AAEtB,IAAAK,gBAAS,EACR,kBAAkB,EAClB,yCAAyC,EACzCL,cACD,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.withBlockRenameControl = void 0;
|
|
7
|
+
var _element = require("@wordpress/element");
|
|
8
|
+
var _compose = require("@wordpress/compose");
|
|
9
|
+
var _hooks = require("@wordpress/hooks");
|
|
10
|
+
var _i18n = require("@wordpress/i18n");
|
|
11
|
+
var _blocks = require("@wordpress/blocks");
|
|
12
|
+
var _components = require("@wordpress/components");
|
|
13
|
+
var _a11y = require("@wordpress/a11y");
|
|
14
|
+
var _components2 = require("../components");
|
|
15
|
+
/**
|
|
16
|
+
* WordPress dependencies
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const emptyString = testString => testString?.trim()?.length === 0;
|
|
24
|
+
function RenameModal({
|
|
25
|
+
blockName,
|
|
26
|
+
originalBlockName,
|
|
27
|
+
onClose,
|
|
28
|
+
onSave
|
|
29
|
+
}) {
|
|
30
|
+
const [editedBlockName, setEditedBlockName] = (0, _element.useState)(blockName);
|
|
31
|
+
const nameHasChanged = editedBlockName !== blockName;
|
|
32
|
+
const nameIsOriginal = editedBlockName === originalBlockName;
|
|
33
|
+
const nameIsEmpty = emptyString(editedBlockName);
|
|
34
|
+
const isNameValid = nameHasChanged || nameIsOriginal;
|
|
35
|
+
const autoSelectInputText = event => event.target.select();
|
|
36
|
+
const dialogDescription = (0, _compose.useInstanceId)(RenameModal, `block-editor-rename-modal__description`);
|
|
37
|
+
const handleSubmit = () => {
|
|
38
|
+
// Must be assertive to immediately announce change.
|
|
39
|
+
(0, _a11y.speak)((0, _i18n.sprintf)( /* translators: %1$s: type of update (either reset of changed). %2$s: new name/label for the block */
|
|
40
|
+
(0, _i18n.__)('Block name %1$s to: "%2$s".'), nameIsOriginal || nameIsEmpty ? (0, _i18n.__)('reset') : (0, _i18n.__)('changed'), editedBlockName), 'assertive');
|
|
41
|
+
onSave(editedBlockName);
|
|
42
|
+
|
|
43
|
+
// Immediate close avoids ability to hit save multiple times.
|
|
44
|
+
onClose();
|
|
45
|
+
};
|
|
46
|
+
return (0, _element.createElement)(_components.Modal, {
|
|
47
|
+
title: (0, _i18n.__)('Rename'),
|
|
48
|
+
onRequestClose: onClose,
|
|
49
|
+
overlayClassName: "block-editor-block-rename-modal",
|
|
50
|
+
aria: {
|
|
51
|
+
describedby: dialogDescription
|
|
52
|
+
}
|
|
53
|
+
}, (0, _element.createElement)("p", {
|
|
54
|
+
id: dialogDescription
|
|
55
|
+
}, (0, _i18n.__)('Enter a custom name for this block.')), (0, _element.createElement)("form", {
|
|
56
|
+
onSubmit: e => {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
if (!isNameValid) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
handleSubmit();
|
|
62
|
+
}
|
|
63
|
+
}, (0, _element.createElement)(_components.__experimentalVStack, {
|
|
64
|
+
spacing: "3"
|
|
65
|
+
}, (0, _element.createElement)(_components.TextControl, {
|
|
66
|
+
__nextHasNoMarginBottom: true,
|
|
67
|
+
value: editedBlockName,
|
|
68
|
+
label: (0, _i18n.__)('Block name'),
|
|
69
|
+
hideLabelFromVision: true,
|
|
70
|
+
placeholder: originalBlockName,
|
|
71
|
+
onChange: setEditedBlockName,
|
|
72
|
+
onFocus: autoSelectInputText
|
|
73
|
+
}), (0, _element.createElement)(_components.__experimentalHStack, {
|
|
74
|
+
justify: "right"
|
|
75
|
+
}, (0, _element.createElement)(_components.Button, {
|
|
76
|
+
variant: "tertiary",
|
|
77
|
+
onClick: onClose
|
|
78
|
+
}, (0, _i18n.__)('Cancel')), (0, _element.createElement)(_components.Button, {
|
|
79
|
+
"aria-disabled": !isNameValid,
|
|
80
|
+
variant: "primary",
|
|
81
|
+
type: "submit"
|
|
82
|
+
}, (0, _i18n.__)('Save'))))));
|
|
83
|
+
}
|
|
84
|
+
function BlockRenameControl(props) {
|
|
85
|
+
const [renamingBlock, setRenamingBlock] = (0, _element.useState)(false);
|
|
86
|
+
const {
|
|
87
|
+
clientId,
|
|
88
|
+
customName,
|
|
89
|
+
onChange
|
|
90
|
+
} = props;
|
|
91
|
+
const blockInformation = (0, _components2.useBlockDisplayInformation)(clientId);
|
|
92
|
+
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components2.InspectorControls, {
|
|
93
|
+
group: "advanced"
|
|
94
|
+
}, (0, _element.createElement)(_components.TextControl, {
|
|
95
|
+
__nextHasNoMarginBottom: true,
|
|
96
|
+
label: (0, _i18n.__)('Block name'),
|
|
97
|
+
value: customName || '',
|
|
98
|
+
onChange: onChange
|
|
99
|
+
})), (0, _element.createElement)(_components2.BlockSettingsMenuControls, null, ({
|
|
100
|
+
selectedClientIds
|
|
101
|
+
}) => {
|
|
102
|
+
// Only enabled for single selections.
|
|
103
|
+
const canRename = selectedClientIds.length === 1 && clientId === selectedClientIds[0];
|
|
104
|
+
|
|
105
|
+
// This check ensures the `BlockSettingsMenuControls` fill
|
|
106
|
+
// doesn't render multiple times and also that it renders for
|
|
107
|
+
// the block from which the menu was triggered.
|
|
108
|
+
if (!canRename) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
return (0, _element.createElement)(_components.MenuItem, {
|
|
112
|
+
onClick: () => {
|
|
113
|
+
setRenamingBlock(true);
|
|
114
|
+
},
|
|
115
|
+
"aria-expanded": renamingBlock,
|
|
116
|
+
"aria-haspopup": "dialog"
|
|
117
|
+
}, (0, _i18n.__)('Rename'));
|
|
118
|
+
}), renamingBlock && (0, _element.createElement)(RenameModal, {
|
|
119
|
+
blockName: customName || '',
|
|
120
|
+
originalBlockName: blockInformation?.title,
|
|
121
|
+
onClose: () => setRenamingBlock(false),
|
|
122
|
+
onSave: newName => {
|
|
123
|
+
// If the new value is the block's original name (e.g. `Group`)
|
|
124
|
+
// or it is an empty string then assume the intent is to reset
|
|
125
|
+
// the value. Therefore reset the metadata.
|
|
126
|
+
if (newName === blockInformation?.title || emptyString(newName)) {
|
|
127
|
+
newName = undefined;
|
|
128
|
+
}
|
|
129
|
+
onChange(newName);
|
|
130
|
+
}
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
const withBlockRenameControl = (0, _compose.createHigherOrderComponent)(BlockEdit => props => {
|
|
134
|
+
const {
|
|
135
|
+
clientId,
|
|
136
|
+
name,
|
|
137
|
+
attributes,
|
|
138
|
+
setAttributes
|
|
139
|
+
} = props;
|
|
140
|
+
const metaDataSupport = (0, _blocks.getBlockSupport)(name, '__experimentalMetadata', false);
|
|
141
|
+
const supportsBlockNaming = !!(true === metaDataSupport || metaDataSupport?.name);
|
|
142
|
+
return (0, _element.createElement)(_element.Fragment, null, supportsBlockNaming && (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(BlockRenameControl, {
|
|
143
|
+
clientId: clientId,
|
|
144
|
+
customName: attributes?.metadata?.name,
|
|
145
|
+
onChange: newName => {
|
|
146
|
+
setAttributes({
|
|
147
|
+
metadata: {
|
|
148
|
+
...(attributes?.metadata && attributes?.metadata),
|
|
149
|
+
name: newName
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
})), (0, _element.createElement)(BlockEdit, {
|
|
154
|
+
key: "edit",
|
|
155
|
+
...props
|
|
156
|
+
}));
|
|
157
|
+
}, 'withToolbarControls');
|
|
158
|
+
exports.withBlockRenameControl = withBlockRenameControl;
|
|
159
|
+
(0, _hooks.addFilter)('editor.BlockEdit', 'core/block-rename-ui/with-block-rename-control', withBlockRenameControl);
|
|
160
|
+
//# sourceMappingURL=block-rename-ui.js.map
|