@wordpress/block-editor 11.0.0 → 11.2.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 +16 -1
- package/LICENSE.md +1 -1
- package/README.md +2 -1
- package/build/components/alignment-control/ui.js +1 -7
- package/build/components/alignment-control/ui.js.map +1 -1
- package/build/components/block-actions/index.js +9 -0
- package/build/components/block-actions/index.js.map +1 -1
- package/build/components/block-alignment-control/use-available-alignments.js +4 -3
- package/build/components/block-alignment-control/use-available-alignments.js.map +1 -1
- package/build/components/block-icon/index.js +4 -2
- package/build/components/block-icon/index.js.map +1 -1
- package/build/components/block-inspector/index.js +58 -5
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list-appender/index.js +46 -34
- package/build/components/block-list-appender/index.js.map +1 -1
- package/build/components/block-list-appender/index.native.js +39 -34
- package/build/components/block-list-appender/index.native.js.map +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js +18 -18
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build/components/block-mobile-toolbar/index.native.js +1 -1
- package/build/components/block-mobile-toolbar/index.native.js.map +1 -1
- package/build/components/block-pattern-setup/index.js +14 -7
- package/build/components/block-pattern-setup/index.js.map +1 -1
- package/build/components/block-preview/auto.js +1 -4
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-styles/index.js +3 -1
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-styles/index.native.js +1 -3
- package/build/components/block-styles/index.native.js.map +1 -1
- package/build/components/block-styles/utils.js +7 -10
- package/build/components/block-styles/utils.js.map +1 -1
- package/build/components/block-toolbar/index.native.js +6 -8
- package/build/components/block-toolbar/index.native.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +1 -3
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/block-tools/use-block-toolbar-popover-props.js +43 -10
- package/build/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
- package/build/components/block-variation-picker/index.js +1 -1
- package/build/components/block-variation-picker/index.js.map +1 -1
- package/build/components/colors/utils.js +2 -6
- package/build/components/colors/utils.js.map +1 -1
- package/build/components/colors-gradients/control.js +0 -3
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/dropdown.js +0 -2
- package/build/components/colors-gradients/dropdown.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +2 -19
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +4 -3
- package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
- package/build/components/copy-handler/index.js +37 -9
- package/build/components/copy-handler/index.js.map +1 -1
- package/build/components/default-style-picker/index.js +1 -0
- package/build/components/default-style-picker/index.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +5 -2
- package/build/components/font-sizes/fluid-utils.js.map +1 -1
- package/build/components/font-sizes/utils.js +10 -4
- package/build/components/font-sizes/utils.js.map +1 -1
- package/build/components/font-sizes/with-font-sizes.js +14 -12
- package/build/components/font-sizes/with-font-sizes.js.map +1 -1
- package/build/components/gradients/use-gradient.js +2 -8
- package/build/components/gradients/use-gradient.js.map +1 -1
- package/build/components/iframe/index.js +48 -101
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/iframe/use-compatibility-styles.js +98 -0
- package/build/components/iframe/use-compatibility-styles.js.map +1 -0
- package/build/components/image-size-control/index.js +1 -0
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/inner-blocks/index.js +6 -2
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +4 -4
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/hooks/use-insertion-point.js +4 -3
- package/build/components/inserter/hooks/use-insertion-point.js.map +1 -1
- package/build/components/inserter/index.js +16 -6
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/media-tab/hooks.js +8 -5
- package/build/components/inserter/media-tab/hooks.js.map +1 -1
- package/build/components/inserter/menu.js +11 -5
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter/quick-inserter.js +6 -3
- package/build/components/inserter/quick-inserter.js.map +1 -1
- package/build/components/inserter/search-items.js +15 -14
- package/build/components/inserter/search-items.js.map +1 -1
- package/build/components/inserter/search-results.js +4 -2
- package/build/components/inserter/search-results.js.map +1 -1
- package/build/components/inspector-controls/groups.js +3 -1
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/inspector-controls-tabs/position-controls-panel.js +46 -0
- package/build/components/inspector-controls-tabs/position-controls-panel.js.map +1 -0
- package/build/components/inspector-controls-tabs/settings-tab.js +3 -1
- package/build/components/inspector-controls-tabs/settings-tab.js.map +1 -1
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +4 -11
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build/components/link-control/search-input.js +1 -0
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/list-view/block-select-button.js +1 -1
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/off-canvas-editor/appender.js +3 -44
- package/build/components/off-canvas-editor/appender.js.map +1 -1
- package/build/components/off-canvas-editor/block-contents.js +38 -5
- package/build/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build/components/off-canvas-editor/block-select-button.js +3 -2
- package/build/components/off-canvas-editor/block-select-button.js.map +1 -1
- package/build/components/off-canvas-editor/block.js +51 -57
- package/build/components/off-canvas-editor/block.js.map +1 -1
- package/build/components/off-canvas-editor/index.js +12 -5
- package/build/components/off-canvas-editor/index.js.map +1 -1
- package/build/components/off-canvas-editor/use-inserted-block.js +58 -0
- package/build/components/off-canvas-editor/use-inserted-block.js.map +1 -0
- package/build/components/provider/index.js +3 -1
- package/build/components/provider/index.js.map +1 -1
- package/build/components/responsive-block-control/label.js.map +1 -1
- package/build/components/rich-text/format-edit.js +12 -10
- package/build/components/rich-text/format-edit.js.map +1 -1
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/use-enter.js +4 -5
- package/build/components/rich-text/use-enter.js.map +1 -1
- package/build/components/rich-text/use-paste-handler.js +21 -12
- package/build/components/rich-text/use-paste-handler.js.map +1 -1
- package/build/components/spacing-sizes-control/index.js +0 -1
- package/build/components/spacing-sizes-control/index.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/typewriter/index.js +1 -1
- package/build/components/typewriter/index.js.map +1 -1
- package/build/components/url-input/button.js +1 -0
- package/build/components/url-input/button.js.map +1 -1
- package/build/components/url-input/index.js +15 -1
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/url-popover/image-url-input-ui.js +2 -2
- package/build/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build/components/url-popover/link-editor.js +1 -0
- package/build/components/url-popover/link-editor.js.map +1 -1
- package/build/components/use-paste-styles/index.js +188 -0
- package/build/components/use-paste-styles/index.js.map +1 -0
- package/build/components/writing-flow/index.js +1 -1
- package/build/components/writing-flow/index.js.map +1 -1
- package/build/components/writing-flow/use-arrow-nav.js +22 -29
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/hooks/border.js +0 -1
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color-panel.js +0 -1
- package/build/hooks/color-panel.js.map +1 -1
- package/build/hooks/color.js +1 -2
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/font-family.js +4 -4
- package/build/hooks/font-family.js.map +1 -1
- package/build/hooks/font-size.js +5 -3
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/metadata.js +1 -1
- package/build/hooks/metadata.js.map +1 -1
- package/build/hooks/position.js +376 -0
- package/build/hooks/position.js.map +1 -0
- package/build/hooks/supports.js +328 -0
- package/build/hooks/supports.js.map +1 -0
- package/build/hooks/use-typography-props.js +11 -8
- package/build/hooks/use-typography-props.js.map +1 -1
- package/build/store/reducer.js +27 -9
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +9 -7
- package/build/store/selectors.js.map +1 -1
- package/build/utils/pasting.js +6 -11
- package/build/utils/pasting.js.map +1 -1
- package/build-module/components/alignment-control/ui.js +1 -6
- package/build-module/components/alignment-control/ui.js.map +1 -1
- package/build-module/components/block-actions/index.js +6 -0
- package/build-module/components/block-actions/index.js.map +1 -1
- package/build-module/components/block-alignment-control/use-available-alignments.js +4 -3
- package/build-module/components/block-alignment-control/use-available-alignments.js.map +1 -1
- package/build-module/components/block-icon/index.js +4 -2
- package/build-module/components/block-icon/index.js.map +1 -1
- package/build-module/components/block-inspector/index.js +58 -6
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list-appender/index.js +46 -34
- package/build-module/components/block-list-appender/index.js.map +1 -1
- package/build-module/components/block-list-appender/index.native.js +39 -32
- package/build-module/components/block-list-appender/index.native.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +18 -18
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/index.native.js +1 -1
- package/build-module/components/block-mobile-toolbar/index.native.js.map +1 -1
- package/build-module/components/block-pattern-setup/index.js +14 -7
- package/build-module/components/block-pattern-setup/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +1 -4
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-styles/index.js +2 -1
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-styles/index.native.js +1 -2
- package/build-module/components/block-styles/index.native.js.map +1 -1
- package/build-module/components/block-styles/utils.js +7 -9
- package/build-module/components/block-styles/utils.js.map +1 -1
- package/build-module/components/block-toolbar/index.native.js +6 -8
- package/build-module/components/block-toolbar/index.native.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +1 -2
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/block-tools/use-block-toolbar-popover-props.js +42 -11
- package/build-module/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
- package/build-module/components/block-variation-picker/index.js +1 -1
- package/build-module/components/block-variation-picker/index.js.map +1 -1
- package/build-module/components/colors/utils.js +3 -7
- package/build-module/components/colors/utils.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +0 -3
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/dropdown.js +0 -2
- package/build-module/components/colors-gradients/dropdown.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +4 -19
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +4 -2
- package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
- package/build-module/components/copy-handler/index.js +38 -10
- package/build-module/components/copy-handler/index.js.map +1 -1
- package/build-module/components/default-style-picker/index.js +1 -0
- package/build-module/components/default-style-picker/index.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +5 -2
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
- package/build-module/components/font-sizes/utils.js +11 -5
- package/build-module/components/font-sizes/utils.js.map +1 -1
- package/build-module/components/font-sizes/with-font-sizes.js +14 -11
- package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
- package/build-module/components/gradients/use-gradient.js +2 -7
- package/build-module/components/gradients/use-gradient.js.map +1 -1
- package/build-module/components/iframe/index.js +46 -102
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/iframe/use-compatibility-styles.js +90 -0
- package/build-module/components/iframe/use-compatibility-styles.js.map +1 -0
- package/build-module/components/image-size-control/index.js +1 -0
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +6 -2
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +4 -4
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/hooks/use-insertion-point.js +4 -3
- package/build-module/components/inserter/hooks/use-insertion-point.js.map +1 -1
- package/build-module/components/inserter/index.js +16 -6
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/media-tab/hooks.js +8 -5
- package/build-module/components/inserter/media-tab/hooks.js.map +1 -1
- package/build-module/components/inserter/menu.js +11 -5
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/quick-inserter.js +6 -3
- package/build-module/components/inserter/quick-inserter.js.map +1 -1
- package/build-module/components/inserter/search-items.js +15 -13
- package/build-module/components/inserter/search-items.js.map +1 -1
- package/build-module/components/inserter/search-results.js +4 -2
- package/build-module/components/inserter/search-results.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +3 -1
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/position-controls-panel.js +33 -0
- package/build-module/components/inspector-controls-tabs/position-controls-panel.js.map +1 -0
- package/build-module/components/inspector-controls-tabs/settings-tab.js +2 -1
- package/build-module/components/inspector-controls-tabs/settings-tab.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +4 -11
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build-module/components/link-control/search-input.js +1 -0
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +1 -1
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/off-canvas-editor/appender.js +5 -44
- package/build-module/components/off-canvas-editor/appender.js.map +1 -1
- package/build-module/components/off-canvas-editor/block-contents.js +37 -7
- package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build-module/components/off-canvas-editor/block-select-button.js +3 -2
- package/build-module/components/off-canvas-editor/block-select-button.js.map +1 -1
- package/build-module/components/off-canvas-editor/block.js +54 -60
- package/build-module/components/off-canvas-editor/block.js.map +1 -1
- package/build-module/components/off-canvas-editor/index.js +12 -5
- package/build-module/components/off-canvas-editor/index.js.map +1 -1
- package/build-module/components/off-canvas-editor/use-inserted-block.js +47 -0
- package/build-module/components/off-canvas-editor/use-inserted-block.js.map +1 -0
- package/build-module/components/provider/index.js +3 -1
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/responsive-block-control/label.js +1 -2
- package/build-module/components/responsive-block-control/label.js.map +1 -1
- package/build-module/components/rich-text/format-edit.js +12 -9
- package/build-module/components/rich-text/format-edit.js.map +1 -1
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/use-enter.js +4 -5
- package/build-module/components/rich-text/use-enter.js.map +1 -1
- package/build-module/components/rich-text/use-paste-handler.js +22 -12
- package/build-module/components/rich-text/use-paste-handler.js.map +1 -1
- package/build-module/components/spacing-sizes-control/index.js +0 -1
- package/build-module/components/spacing-sizes-control/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/utils.js +1 -1
- package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
- package/build-module/components/typewriter/index.js +1 -1
- package/build-module/components/typewriter/index.js.map +1 -1
- package/build-module/components/url-input/button.js +1 -0
- package/build-module/components/url-input/button.js.map +1 -1
- package/build-module/components/url-input/index.js +14 -1
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/url-popover/image-url-input-ui.js +3 -3
- package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build-module/components/url-popover/link-editor.js +1 -0
- package/build-module/components/url-popover/link-editor.js.map +1 -1
- package/build-module/components/use-paste-styles/index.js +174 -0
- package/build-module/components/use-paste-styles/index.js.map +1 -0
- package/build-module/components/writing-flow/index.js +1 -1
- package/build-module/components/writing-flow/index.js.map +1 -1
- package/build-module/components/writing-flow/use-arrow-nav.js +22 -29
- package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build-module/hooks/border.js +0 -1
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color-panel.js +0 -1
- package/build-module/hooks/color-panel.js.map +1 -1
- package/build-module/hooks/color.js +1 -2
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/font-family.js +5 -5
- package/build-module/hooks/font-family.js.map +1 -1
- package/build-module/hooks/font-size.js +5 -3
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/metadata.js +1 -1
- package/build-module/hooks/metadata.js.map +1 -1
- package/build-module/hooks/position.js +337 -0
- package/build-module/hooks/position.js.map +1 -0
- package/build-module/hooks/supports.js +257 -0
- package/build-module/hooks/supports.js.map +1 -0
- package/build-module/hooks/use-typography-props.js +11 -8
- package/build-module/hooks/use-typography-props.js.map +1 -1
- package/build-module/store/reducer.js +27 -8
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +9 -7
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/pasting.js +6 -10
- package/build-module/utils/pasting.js.map +1 -1
- package/build-style/content-rtl.css +60 -3
- package/build-style/content.css +60 -3
- package/build-style/default-editor-styles-rtl.css +3 -3
- package/build-style/default-editor-styles.css +3 -3
- package/build-style/style-rtl.css +62 -69
- package/build-style/style.css +62 -69
- package/package.json +29 -29
- package/src/components/alignment-control/test/index.js +2 -0
- package/src/components/alignment-control/ui.js +1 -7
- package/src/components/block-actions/index.js +5 -0
- package/src/components/block-alignment-control/test/index.js +2 -0
- package/src/components/block-alignment-control/use-available-alignments.js +4 -3
- package/src/components/block-icon/index.js +4 -2
- package/src/components/block-icon/test/index.js +9 -5
- package/src/components/block-inspector/index.js +79 -4
- package/src/components/block-inspector/style.scss +7 -0
- package/src/components/block-list-appender/index.js +65 -54
- package/src/components/block-list-appender/index.native.js +45 -34
- package/src/components/block-mobile-toolbar/block-actions-menu.native.js +18 -22
- package/src/components/block-mobile-toolbar/index.native.js +1 -1
- package/src/components/block-mobile-toolbar/test/__snapshots__/block-actions-menu.native.js.snap +125 -0
- package/src/components/block-mobile-toolbar/test/block-actions-menu.native.js +439 -0
- package/src/components/block-mover/test/__snapshots__/index.native.js.snap +42 -0
- package/src/components/block-mover/test/index.native.js +157 -1
- package/src/components/block-pattern-setup/index.js +15 -6
- package/src/components/block-pattern-setup/style.scss +29 -1
- package/src/components/block-preview/auto.js +2 -4
- package/src/components/block-settings-menu/block-settings-dropdown.js +4 -0
- package/src/components/block-styles/index.js +4 -1
- package/src/components/block-styles/index.native.js +1 -2
- package/src/components/block-styles/utils.js +5 -7
- package/src/components/block-switcher/test/index.js +3 -2
- package/src/components/block-toolbar/index.native.js +8 -11
- package/src/components/block-tools/selected-block-popover.js +1 -3
- package/src/components/block-tools/use-block-toolbar-popover-props.js +68 -12
- package/src/components/block-variation-picker/index.js +5 -1
- package/src/components/block-vertical-alignment-control/test/index.js +2 -0
- package/src/components/button-block-appender/{style.scss → content.scss} +0 -0
- package/src/components/colors/test/with-colors.js +2 -0
- package/src/components/colors/utils.js +5 -3
- package/src/components/colors-gradients/control.js +0 -7
- package/src/components/colors-gradients/dropdown.js +0 -2
- package/src/components/colors-gradients/panel-color-gradient-settings.js +4 -22
- package/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +4 -2
- package/src/components/copy-handler/index.js +53 -7
- package/src/components/default-block-appender/test/index.js +2 -0
- package/src/components/default-style-picker/index.js +1 -0
- package/src/components/font-sizes/fluid-utils.js +7 -1
- package/src/components/font-sizes/utils.js +5 -3
- package/src/components/font-sizes/with-font-sizes.js +36 -36
- package/src/components/gradients/use-gradient.js +2 -7
- package/src/components/iframe/index.js +60 -122
- package/src/components/iframe/use-compatibility-styles.js +101 -0
- package/src/components/image-size-control/index.js +1 -0
- package/src/components/image-size-control/test/index.js +147 -79
- package/src/components/inner-blocks/index.js +4 -2
- package/src/components/inserter/block-patterns-tab.js +7 -4
- package/src/components/inserter/hooks/use-insertion-point.js +3 -2
- package/src/components/inserter/index.js +61 -43
- package/src/components/inserter/media-tab/hooks.js +5 -4
- package/src/components/inserter/menu.js +8 -4
- package/src/components/inserter/quick-inserter.js +3 -0
- package/src/components/inserter/search-items.js +1 -2
- package/src/components/inserter/search-results.js +2 -0
- package/src/components/inserter/test/__snapshots__/index.native.js.snap +117 -0
- package/src/components/inserter/test/index.native.js +255 -1
- package/src/components/inspector-controls/groups.js +2 -0
- package/src/components/inspector-controls-tabs/position-controls-panel.js +37 -0
- package/src/components/inspector-controls-tabs/settings-tab.js +2 -0
- package/src/components/inspector-controls-tabs/style.scss +15 -0
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +3 -8
- package/src/components/link-control/search-input.js +1 -0
- package/src/components/link-control/style.scss +1 -0
- package/src/components/link-control/test/index.js +18 -4
- package/src/components/list-view/block-select-button.js +1 -1
- package/src/components/list-view/style.scss +14 -10
- package/src/components/media-replace-flow/test/index.js +2 -0
- package/src/components/off-canvas-editor/appender.js +4 -49
- package/src/components/off-canvas-editor/block-contents.js +84 -23
- package/src/components/off-canvas-editor/block-select-button.js +6 -2
- package/src/components/off-canvas-editor/block.js +90 -105
- package/src/components/off-canvas-editor/index.js +21 -2
- package/src/components/off-canvas-editor/style.scss +5 -1
- package/src/components/off-canvas-editor/test/use-inserted-block.js +108 -0
- package/src/components/off-canvas-editor/use-inserted-block.js +47 -0
- package/src/components/provider/index.js +4 -1
- package/src/components/responsive-block-control/label.js +2 -3
- package/src/components/responsive-block-control/test/index.js +4 -2
- package/src/components/rich-text/format-edit.js +6 -10
- package/src/components/rich-text/index.js +1 -0
- package/src/components/rich-text/use-enter.js +4 -4
- package/src/components/rich-text/use-paste-handler.js +33 -14
- package/src/components/spacing-sizes-control/index.js +0 -1
- package/src/components/spacing-sizes-control/utils.js +1 -1
- package/src/components/typewriter/index.js +3 -1
- package/src/components/url-input/README.md +5 -0
- package/src/components/url-input/button.js +1 -0
- package/src/components/url-input/index.js +15 -1
- package/src/components/url-input/test/button.js +2 -0
- package/src/components/url-popover/image-url-input-ui.js +5 -4
- package/src/components/url-popover/link-editor.js +1 -0
- package/src/components/url-popover/test/index.js +21 -5
- package/src/components/use-paste-styles/index.js +230 -0
- package/src/components/warning/test/index.js +2 -0
- package/src/components/writing-flow/index.js +1 -1
- package/src/components/writing-flow/use-arrow-nav.js +20 -28
- package/src/content.scss +1 -0
- package/src/hooks/border.js +0 -1
- package/src/hooks/color-panel.js +0 -1
- package/src/hooks/color.js +0 -2
- package/src/hooks/font-family.js +3 -5
- package/src/hooks/font-size.js +13 -4
- package/src/hooks/index.js +1 -0
- package/src/hooks/metadata.js +1 -2
- package/src/hooks/position.js +375 -0
- package/src/hooks/position.scss +18 -0
- package/src/hooks/supports.js +302 -0
- package/src/hooks/test/__snapshots__/align.native.js.snap +73 -0
- package/src/hooks/test/align.native.js +133 -0
- package/src/hooks/test/use-typography-props.js +26 -0
- package/src/hooks/use-typography-props.js +15 -7
- package/src/store/reducer.js +20 -8
- package/src/store/selectors.js +7 -8
- package/src/store/test/reducer.js +45 -3
- package/src/store/test/selectors.js +12 -9
- package/src/style.scss +2 -1
- package/src/utils/pasting.js +3 -9
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/colors-gradients/use-common-single-multiple-selects.js +0 -21
- package/build/components/colors-gradients/use-common-single-multiple-selects.js.map +0 -1
- package/build/components/rich-text/file-paste-handler.js +0 -21
- package/build/components/rich-text/file-paste-handler.js.map +0 -1
- package/build-module/components/colors-gradients/use-common-single-multiple-selects.js +0 -11
- package/build-module/components/colors-gradients/use-common-single-multiple-selects.js.map +0 -1
- package/build-module/components/rich-text/file-paste-handler.js +0 -13
- package/build-module/components/rich-text/file-paste-handler.js.map +0 -1
- package/src/components/colors-gradients/use-common-single-multiple-selects.js +0 -11
- package/src/components/rich-text/file-paste-handler.js +0 -13
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { store as blockEditorStore } from '../../store';
|
|
10
|
+
|
|
11
|
+
export const useInsertedBlock = ( insertedBlockClientId ) => {
|
|
12
|
+
const { insertedBlockAttributes, insertedBlockName } = useSelect(
|
|
13
|
+
( select ) => {
|
|
14
|
+
const { getBlockName, getBlockAttributes } =
|
|
15
|
+
select( blockEditorStore );
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
insertedBlockAttributes: getBlockAttributes(
|
|
19
|
+
insertedBlockClientId
|
|
20
|
+
),
|
|
21
|
+
insertedBlockName: getBlockName( insertedBlockClientId ),
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
[ insertedBlockClientId ]
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
|
28
|
+
|
|
29
|
+
const setInsertedBlockAttributes = ( _updatedAttributes ) => {
|
|
30
|
+
if ( ! insertedBlockClientId ) return;
|
|
31
|
+
updateBlockAttributes( insertedBlockClientId, _updatedAttributes );
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if ( ! insertedBlockClientId ) {
|
|
35
|
+
return {
|
|
36
|
+
insertedBlockAttributes: undefined,
|
|
37
|
+
insertedBlockName: undefined,
|
|
38
|
+
setInsertedBlockAttributes,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
insertedBlockAttributes,
|
|
44
|
+
insertedBlockName,
|
|
45
|
+
setInsertedBlockAttributes,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
@@ -19,7 +19,10 @@ function BlockEditorProvider( props ) {
|
|
|
19
19
|
|
|
20
20
|
const { updateSettings } = useDispatch( blockEditorStore );
|
|
21
21
|
useEffect( () => {
|
|
22
|
-
updateSettings(
|
|
22
|
+
updateSettings( {
|
|
23
|
+
...settings,
|
|
24
|
+
__internalIsInitialized: true,
|
|
25
|
+
} );
|
|
23
26
|
}, [ settings ] );
|
|
24
27
|
|
|
25
28
|
// Syncs the entity provider with changes in the block-editor store.
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import { useInstanceId } from '@wordpress/compose';
|
|
5
5
|
import { VisuallyHidden } from '@wordpress/components';
|
|
6
6
|
import { _x, sprintf } from '@wordpress/i18n';
|
|
7
|
-
import { Fragment } from '@wordpress/element';
|
|
8
7
|
|
|
9
8
|
export default function ResponsiveBlockControlLabel( {
|
|
10
9
|
property,
|
|
@@ -24,13 +23,13 @@ export default function ResponsiveBlockControlLabel( {
|
|
|
24
23
|
viewport.label
|
|
25
24
|
);
|
|
26
25
|
return (
|
|
27
|
-
|
|
26
|
+
<>
|
|
28
27
|
<span aria-describedby={ `rbc-desc-${ instanceId }` }>
|
|
29
28
|
{ viewport.label }
|
|
30
29
|
</span>
|
|
31
30
|
<VisuallyHidden as="span" id={ `rbc-desc-${ instanceId }` }>
|
|
32
31
|
{ accessibleLabel }
|
|
33
32
|
</VisuallyHidden>
|
|
34
|
-
|
|
33
|
+
</>
|
|
35
34
|
);
|
|
36
35
|
}
|
|
@@ -15,6 +15,8 @@ import { SelectControl } from '@wordpress/components';
|
|
|
15
15
|
*/
|
|
16
16
|
import ResponsiveBlockControl from '../index';
|
|
17
17
|
|
|
18
|
+
jest.useFakeTimers();
|
|
19
|
+
|
|
18
20
|
const inputId = 'input-12345678';
|
|
19
21
|
|
|
20
22
|
const sizeOptions = [
|
|
@@ -38,13 +40,13 @@ const sizeOptions = [
|
|
|
38
40
|
|
|
39
41
|
const renderTestDefaultControlComponent = ( labelComponent, device ) => {
|
|
40
42
|
return (
|
|
41
|
-
|
|
43
|
+
<>
|
|
42
44
|
<SelectControl label={ labelComponent } options={ sizeOptions } />
|
|
43
45
|
<p id={ device.id }>
|
|
44
46
|
{ device.label } is used here for testing purposes to ensure we
|
|
45
47
|
have access to details about the device.
|
|
46
48
|
</p>
|
|
47
|
-
|
|
49
|
+
</>
|
|
48
50
|
);
|
|
49
51
|
};
|
|
50
52
|
|
|
@@ -6,10 +6,6 @@ import {
|
|
|
6
6
|
getActiveObject,
|
|
7
7
|
isCollapsed,
|
|
8
8
|
} from '@wordpress/rich-text';
|
|
9
|
-
/**
|
|
10
|
-
* External dependencies
|
|
11
|
-
*/
|
|
12
|
-
import { find } from 'lodash';
|
|
13
9
|
|
|
14
10
|
export default function FormatEdit( {
|
|
15
11
|
formatTypes,
|
|
@@ -40,13 +36,13 @@ export default function FormatEdit( {
|
|
|
40
36
|
if ( name === 'core/link' && ! isCollapsed( value ) ) {
|
|
41
37
|
const formats = value.formats;
|
|
42
38
|
|
|
43
|
-
const linkFormatAtStart =
|
|
44
|
-
type
|
|
45
|
-
|
|
39
|
+
const linkFormatAtStart = formats[ value.start ]?.find(
|
|
40
|
+
( { type } ) => type === 'core/link'
|
|
41
|
+
);
|
|
46
42
|
|
|
47
|
-
const linkFormatAtEnd =
|
|
48
|
-
type
|
|
49
|
-
|
|
43
|
+
const linkFormatAtEnd = formats[ value.end - 1 ]?.find(
|
|
44
|
+
( { type } ) => type === 'core/link'
|
|
45
|
+
);
|
|
50
46
|
|
|
51
47
|
if (
|
|
52
48
|
! linkFormatAtStart ||
|
|
@@ -28,6 +28,10 @@ export function useEnter( props ) {
|
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
if ( event.keyCode !== ENTER ) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
31
35
|
const {
|
|
32
36
|
removeEditorOnlyFormats,
|
|
33
37
|
value,
|
|
@@ -40,10 +44,6 @@ export function useEnter( props ) {
|
|
|
40
44
|
onSplitAtEnd,
|
|
41
45
|
} = propsRef.current;
|
|
42
46
|
|
|
43
|
-
if ( event.keyCode !== ENTER ) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
47
|
event.preventDefault();
|
|
48
48
|
|
|
49
49
|
const _value = { ...value };
|
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
import { useRef } from '@wordpress/element';
|
|
5
5
|
import { useRefEffect } from '@wordpress/compose';
|
|
6
6
|
import { getFilesFromDataTransfer } from '@wordpress/dom';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
pasteHandler,
|
|
9
|
+
findTransform,
|
|
10
|
+
getBlockTransforms,
|
|
11
|
+
} from '@wordpress/blocks';
|
|
8
12
|
import {
|
|
9
13
|
isEmpty,
|
|
10
14
|
insert,
|
|
@@ -17,7 +21,6 @@ import { isURL } from '@wordpress/url';
|
|
|
17
21
|
/**
|
|
18
22
|
* Internal dependencies
|
|
19
23
|
*/
|
|
20
|
-
import { filePasteHandler } from './file-paste-handler';
|
|
21
24
|
import { addActiveFormats, isShortcode } from './utils';
|
|
22
25
|
import { splitValue } from './split-value';
|
|
23
26
|
import { shouldDismissPastedFiles } from '../../utils/pasting';
|
|
@@ -155,6 +158,12 @@ export function usePasteHandler( props ) {
|
|
|
155
158
|
return;
|
|
156
159
|
}
|
|
157
160
|
|
|
161
|
+
if ( files?.length ) {
|
|
162
|
+
// Allows us to ask for this information when we get a report.
|
|
163
|
+
// eslint-disable-next-line no-console
|
|
164
|
+
window.console.log( 'Received items:\n\n', files );
|
|
165
|
+
}
|
|
166
|
+
|
|
158
167
|
// Process any attached files, unless we infer that the files in
|
|
159
168
|
// question are redundant "screenshots" of the actual HTML payload,
|
|
160
169
|
// as created by certain office-type programs.
|
|
@@ -164,23 +173,33 @@ export function usePasteHandler( props ) {
|
|
|
164
173
|
files?.length &&
|
|
165
174
|
! shouldDismissPastedFiles( files, html, plainText )
|
|
166
175
|
) {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
176
|
+
const fromTransforms = getBlockTransforms( 'from' );
|
|
177
|
+
const blocks = files
|
|
178
|
+
.reduce( ( accumulator, file ) => {
|
|
179
|
+
const transformation = findTransform(
|
|
180
|
+
fromTransforms,
|
|
181
|
+
( transform ) =>
|
|
182
|
+
transform.type === 'files' &&
|
|
183
|
+
transform.isMatch( [ file ] )
|
|
184
|
+
);
|
|
185
|
+
if ( transformation ) {
|
|
186
|
+
accumulator.push(
|
|
187
|
+
transformation.transform( [ file ] )
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
return accumulator;
|
|
191
|
+
}, [] )
|
|
192
|
+
.flat();
|
|
193
|
+
if ( ! blocks.length ) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
177
196
|
|
|
178
197
|
if ( onReplace && isEmpty( value ) ) {
|
|
179
|
-
onReplace(
|
|
198
|
+
onReplace( blocks );
|
|
180
199
|
} else {
|
|
181
200
|
splitValue( {
|
|
182
201
|
value,
|
|
183
|
-
pastedBlocks:
|
|
202
|
+
pastedBlocks: blocks,
|
|
184
203
|
onReplace,
|
|
185
204
|
onSplit,
|
|
186
205
|
onSplitMiddle,
|
|
@@ -96,7 +96,7 @@ export function getSpacingPresetCssVar( value ) {
|
|
|
96
96
|
*
|
|
97
97
|
* @param {string} value Value to extract slug from.
|
|
98
98
|
*
|
|
99
|
-
* @return {
|
|
99
|
+
* @return {string|undefined} The int value of the slug from given spacing preset.
|
|
100
100
|
*/
|
|
101
101
|
export function getSpacingPresetSlug( value ) {
|
|
102
102
|
if ( ! value ) {
|
|
@@ -105,7 +105,9 @@ export function useTypewriter() {
|
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
const windowScroll =
|
|
108
|
+
const windowScroll =
|
|
109
|
+
scrollContainer === ownerDocument.body ||
|
|
110
|
+
scrollContainer === ownerDocument.documentElement;
|
|
109
111
|
const scrollY = windowScroll
|
|
110
112
|
? defaultView.scrollY
|
|
111
113
|
: scrollContainer.scrollTop;
|
|
@@ -160,6 +160,10 @@ When hiding the URLInput using CSS (as is sometimes done for accessibility purpo
|
|
|
160
160
|
|
|
161
161
|
This prop allows the suggestions list to be programmatically not rendered by passing a boolean—it can be `true` to make sure suggestions aren't rendered, or `false`/`undefined` to fall back to the default behaviour of showing suggestions when matching autocompletion items are found.
|
|
162
162
|
|
|
163
|
+
### `__nextHasNoMarginBottom: Boolean`
|
|
164
|
+
|
|
165
|
+
Start opting into the new margin-free styles that will become the default in a future version, currently scheduled to be WordPress 6.4. (The prop can be safely removed once this happens.)
|
|
166
|
+
|
|
163
167
|
## Example
|
|
164
168
|
|
|
165
169
|
{% codetabs %}
|
|
@@ -217,6 +221,7 @@ registerBlockType( /* ... */, {
|
|
|
217
221
|
edit( { className, attributes, setAttributes } ) {
|
|
218
222
|
return (
|
|
219
223
|
<URLInput
|
|
224
|
+
__nextHasNoMarginBottom
|
|
220
225
|
className={ className }
|
|
221
226
|
value={ attributes.url }
|
|
222
227
|
onChange={ ( url, post ) => setAttributes( { url, text: (post && post.title) || 'Click here' } ) }
|
|
@@ -7,6 +7,7 @@ import scrollIntoView from 'dom-scroll-into-view';
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
|
+
import deprecated from '@wordpress/deprecated';
|
|
10
11
|
import { __, sprintf, _n } from '@wordpress/i18n';
|
|
11
12
|
import { Component, createRef } from '@wordpress/element';
|
|
12
13
|
import { UP, DOWN, ENTER, TAB } from '@wordpress/keycodes';
|
|
@@ -424,6 +425,8 @@ class URLInput extends Component {
|
|
|
424
425
|
|
|
425
426
|
renderControl() {
|
|
426
427
|
const {
|
|
428
|
+
/** Start opting into the new margin-free styles that will become the default in a future version. */
|
|
429
|
+
__nextHasNoMarginBottom = false,
|
|
427
430
|
label = null,
|
|
428
431
|
className,
|
|
429
432
|
isFullWidth,
|
|
@@ -477,8 +480,19 @@ class URLInput extends Component {
|
|
|
477
480
|
return renderControl( controlProps, inputProps, loading );
|
|
478
481
|
}
|
|
479
482
|
|
|
483
|
+
if ( ! __nextHasNoMarginBottom ) {
|
|
484
|
+
deprecated( 'Bottom margin styles for wp.blockEditor.URLInput', {
|
|
485
|
+
since: '6.2',
|
|
486
|
+
version: '6.5',
|
|
487
|
+
hint: 'Set the `__nextHasNoMarginBottom` prop to true to start opting into the new styles, which will become the default in a future version',
|
|
488
|
+
} );
|
|
489
|
+
}
|
|
490
|
+
|
|
480
491
|
return (
|
|
481
|
-
<BaseControl
|
|
492
|
+
<BaseControl
|
|
493
|
+
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
|
|
494
|
+
{ ...controlProps }
|
|
495
|
+
>
|
|
482
496
|
<input { ...inputProps } />
|
|
483
497
|
{ loading && <Spinner /> }
|
|
484
498
|
</BaseControl>
|
|
@@ -9,6 +9,8 @@ import userEvent from '@testing-library/user-event';
|
|
|
9
9
|
*/
|
|
10
10
|
import URLInputButton from '../button';
|
|
11
11
|
|
|
12
|
+
jest.useFakeTimers();
|
|
13
|
+
|
|
12
14
|
describe( 'URLInputButton', () => {
|
|
13
15
|
it( 'should render a `Insert link` button and not be pressed when `url` is not provided', () => {
|
|
14
16
|
render( <URLInputButton /> );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { map } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -189,7 +189,7 @@ const ImageURLInputUI = ( {
|
|
|
189
189
|
linkDestinationInput = LINK_DESTINATION_NONE;
|
|
190
190
|
} else {
|
|
191
191
|
linkDestinationInput = (
|
|
192
|
-
find(
|
|
192
|
+
linkDestinations.find( ( destination ) => {
|
|
193
193
|
return destination.url === value;
|
|
194
194
|
} ) || { linkDestination: LINK_DESTINATION_CUSTOM }
|
|
195
195
|
).linkDestination;
|
|
@@ -236,8 +236,9 @@ const ImageURLInputUI = ( {
|
|
|
236
236
|
const linkEditorValue = urlInput !== null ? urlInput : url;
|
|
237
237
|
|
|
238
238
|
const urlLabel = (
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
getLinkDestinations().find(
|
|
240
|
+
( destination ) => destination.linkDestination === linkDestination
|
|
241
|
+
) || {}
|
|
241
242
|
).title;
|
|
242
243
|
|
|
243
244
|
return (
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
5
5
|
import userEvent from '@testing-library/user-event';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -11,6 +11,16 @@ import URLPopover from '../';
|
|
|
11
11
|
|
|
12
12
|
jest.useRealTimers();
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Returns the first found popover element up the DOM tree.
|
|
16
|
+
*
|
|
17
|
+
* @param {HTMLElement} element Element to start with.
|
|
18
|
+
* @return {HTMLElement|null} Popover element, or `null` if not found.
|
|
19
|
+
*/
|
|
20
|
+
function getWrappingPopoverElement( element ) {
|
|
21
|
+
return element.closest( '.components-popover' );
|
|
22
|
+
}
|
|
23
|
+
|
|
14
24
|
describe( 'URLPopover', () => {
|
|
15
25
|
it( 'matches the snapshot in its default state', async () => {
|
|
16
26
|
const { container } = render(
|
|
@@ -22,8 +32,11 @@ describe( 'URLPopover', () => {
|
|
|
22
32
|
</URLPopover>
|
|
23
33
|
);
|
|
24
34
|
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
await waitFor( () =>
|
|
36
|
+
expect(
|
|
37
|
+
getWrappingPopoverElement( screen.getByText( 'Editor' ) )
|
|
38
|
+
).toBePositionedPopover()
|
|
39
|
+
);
|
|
27
40
|
|
|
28
41
|
expect( container ).toMatchSnapshot();
|
|
29
42
|
} );
|
|
@@ -53,8 +66,11 @@ describe( 'URLPopover', () => {
|
|
|
53
66
|
</URLPopover>
|
|
54
67
|
);
|
|
55
68
|
|
|
56
|
-
|
|
57
|
-
|
|
69
|
+
await waitFor( () =>
|
|
70
|
+
expect(
|
|
71
|
+
getWrappingPopoverElement( screen.getByText( 'Editor' ) )
|
|
72
|
+
).toBePositionedPopover()
|
|
73
|
+
);
|
|
58
74
|
|
|
59
75
|
expect( container ).toMatchSnapshot();
|
|
60
76
|
} );
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useCallback } from '@wordpress/element';
|
|
5
|
+
import { getBlockType, parse } from '@wordpress/blocks';
|
|
6
|
+
import { useDispatch, useRegistry } from '@wordpress/data';
|
|
7
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
8
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { store as blockEditorStore } from '../../store';
|
|
14
|
+
import {
|
|
15
|
+
hasAlignSupport,
|
|
16
|
+
hasBorderSupport,
|
|
17
|
+
hasBackgroundColorSupport,
|
|
18
|
+
hasTextColorSupport,
|
|
19
|
+
hasGradientSupport,
|
|
20
|
+
hasCustomClassNameSupport,
|
|
21
|
+
hasFontFamilySupport,
|
|
22
|
+
hasFontSizeSupport,
|
|
23
|
+
hasLayoutSupport,
|
|
24
|
+
hasStyleSupport,
|
|
25
|
+
} from '../../hooks/supports';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Determine if the copied text looks like serialized blocks or not.
|
|
29
|
+
* Since plain text will always get parsed into a freeform block,
|
|
30
|
+
* we check that if the parsed blocks is anything other than that.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} text The copied text.
|
|
33
|
+
* @return {boolean} True if the text looks like serialized blocks, false otherwise.
|
|
34
|
+
*/
|
|
35
|
+
function hasSerializedBlocks( text ) {
|
|
36
|
+
try {
|
|
37
|
+
const blocks = parse( text, {
|
|
38
|
+
__unstableSkipMigrationLogs: true,
|
|
39
|
+
__unstableSkipAutop: true,
|
|
40
|
+
} );
|
|
41
|
+
if ( blocks.length === 1 && blocks[ 0 ].name === 'core/freeform' ) {
|
|
42
|
+
// It's likely that the text is just plain text and not serialized blocks.
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
} catch ( err ) {
|
|
47
|
+
// Parsing error, the text is not serialized blocks.
|
|
48
|
+
// (Even though that it technically won't happen)
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Style attributes are attributes being added in `block-editor/src/hooks/*`.
|
|
55
|
+
* (Except for some unrelated to style like `anchor` or `settings`.)
|
|
56
|
+
* They generally represent the default block supports.
|
|
57
|
+
*/
|
|
58
|
+
const STYLE_ATTRIBUTES = {
|
|
59
|
+
align: hasAlignSupport,
|
|
60
|
+
borderColor: ( nameOrType ) => hasBorderSupport( nameOrType, 'color' ),
|
|
61
|
+
backgroundColor: hasBackgroundColorSupport,
|
|
62
|
+
textColor: hasTextColorSupport,
|
|
63
|
+
gradient: hasGradientSupport,
|
|
64
|
+
className: hasCustomClassNameSupport,
|
|
65
|
+
fontFamily: hasFontFamilySupport,
|
|
66
|
+
fontSize: hasFontSizeSupport,
|
|
67
|
+
layout: hasLayoutSupport,
|
|
68
|
+
style: hasStyleSupport,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Get the "style attributes" from a given block to a target block.
|
|
73
|
+
*
|
|
74
|
+
* @param {WPBlock} sourceBlock The source block.
|
|
75
|
+
* @param {WPBlock} targetBlock The target block.
|
|
76
|
+
* @return {Object} the filtered attributes object.
|
|
77
|
+
*/
|
|
78
|
+
function getStyleAttributes( sourceBlock, targetBlock ) {
|
|
79
|
+
return Object.entries( STYLE_ATTRIBUTES ).reduce(
|
|
80
|
+
( attributes, [ attributeKey, hasSupport ] ) => {
|
|
81
|
+
// Only apply the attribute if both blocks support it.
|
|
82
|
+
if (
|
|
83
|
+
hasSupport( sourceBlock.name ) &&
|
|
84
|
+
hasSupport( targetBlock.name )
|
|
85
|
+
) {
|
|
86
|
+
// Override attributes that are not present in the block to their defaults.
|
|
87
|
+
attributes[ attributeKey ] =
|
|
88
|
+
sourceBlock.attributes[ attributeKey ];
|
|
89
|
+
}
|
|
90
|
+
return attributes;
|
|
91
|
+
},
|
|
92
|
+
{}
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Update the target blocks with style attributes recursively.
|
|
98
|
+
*
|
|
99
|
+
* @param {WPBlock[]} targetBlocks The target blocks to be updated.
|
|
100
|
+
* @param {WPBlock[]} sourceBlocks The source blocks to get th style attributes from.
|
|
101
|
+
* @param {Function} updateBlockAttributes The function to update the attributes.
|
|
102
|
+
*/
|
|
103
|
+
function recursivelyUpdateBlockAttributes(
|
|
104
|
+
targetBlocks,
|
|
105
|
+
sourceBlocks,
|
|
106
|
+
updateBlockAttributes
|
|
107
|
+
) {
|
|
108
|
+
for (
|
|
109
|
+
let index = 0;
|
|
110
|
+
index < Math.min( sourceBlocks.length, targetBlocks.length );
|
|
111
|
+
index += 1
|
|
112
|
+
) {
|
|
113
|
+
updateBlockAttributes(
|
|
114
|
+
targetBlocks[ index ].clientId,
|
|
115
|
+
getStyleAttributes( sourceBlocks[ index ], targetBlocks[ index ] )
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
recursivelyUpdateBlockAttributes(
|
|
119
|
+
targetBlocks[ index ].innerBlocks,
|
|
120
|
+
sourceBlocks[ index ].innerBlocks,
|
|
121
|
+
updateBlockAttributes
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A hook to return a pasteStyles event function for handling pasting styles to blocks.
|
|
128
|
+
*
|
|
129
|
+
* @return {Function} A function to update the styles to the blocks.
|
|
130
|
+
*/
|
|
131
|
+
export default function usePasteStyles() {
|
|
132
|
+
const registry = useRegistry();
|
|
133
|
+
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
|
134
|
+
const { createSuccessNotice, createWarningNotice, createErrorNotice } =
|
|
135
|
+
useDispatch( noticesStore );
|
|
136
|
+
|
|
137
|
+
return useCallback(
|
|
138
|
+
async ( targetBlocks ) => {
|
|
139
|
+
let html = '';
|
|
140
|
+
try {
|
|
141
|
+
// `http:` sites won't have the clipboard property on navigator.
|
|
142
|
+
// (with the exception of localhost.)
|
|
143
|
+
if ( ! window.navigator.clipboard ) {
|
|
144
|
+
createErrorNotice(
|
|
145
|
+
__(
|
|
146
|
+
'Unable to paste styles. This feature is only available on secure (https) sites in supporting browsers.'
|
|
147
|
+
),
|
|
148
|
+
{ type: 'snackbar' }
|
|
149
|
+
);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
html = await window.navigator.clipboard.readText();
|
|
154
|
+
} catch ( error ) {
|
|
155
|
+
// Possibly the permission is denied.
|
|
156
|
+
createErrorNotice(
|
|
157
|
+
__(
|
|
158
|
+
'Unable to paste styles. Please allow browser clipboard permissions before continuing.'
|
|
159
|
+
),
|
|
160
|
+
{
|
|
161
|
+
type: 'snackbar',
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Abort if the copied text is empty or doesn't look like serialized blocks.
|
|
168
|
+
if ( ! html || ! hasSerializedBlocks( html ) ) {
|
|
169
|
+
createWarningNotice(
|
|
170
|
+
__(
|
|
171
|
+
"Unable to paste styles. Block styles couldn't be found within the copied content."
|
|
172
|
+
),
|
|
173
|
+
{
|
|
174
|
+
type: 'snackbar',
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const copiedBlocks = parse( html );
|
|
181
|
+
|
|
182
|
+
if ( copiedBlocks.length === 1 ) {
|
|
183
|
+
// Apply styles of the block to all the target blocks.
|
|
184
|
+
registry.batch( () => {
|
|
185
|
+
recursivelyUpdateBlockAttributes(
|
|
186
|
+
targetBlocks,
|
|
187
|
+
targetBlocks.map( () => copiedBlocks[ 0 ] ),
|
|
188
|
+
updateBlockAttributes
|
|
189
|
+
);
|
|
190
|
+
} );
|
|
191
|
+
} else {
|
|
192
|
+
registry.batch( () => {
|
|
193
|
+
recursivelyUpdateBlockAttributes(
|
|
194
|
+
targetBlocks,
|
|
195
|
+
copiedBlocks,
|
|
196
|
+
updateBlockAttributes
|
|
197
|
+
);
|
|
198
|
+
} );
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if ( targetBlocks.length === 1 ) {
|
|
202
|
+
const title = getBlockType( targetBlocks[ 0 ].name )?.title;
|
|
203
|
+
createSuccessNotice(
|
|
204
|
+
sprintf(
|
|
205
|
+
// Translators: Name of the block being pasted, e.g. "Paragraph".
|
|
206
|
+
__( 'Pasted styles to %s.' ),
|
|
207
|
+
title
|
|
208
|
+
),
|
|
209
|
+
{ type: 'snackbar' }
|
|
210
|
+
);
|
|
211
|
+
} else {
|
|
212
|
+
createSuccessNotice(
|
|
213
|
+
sprintf(
|
|
214
|
+
// Translators: The number of the blocks.
|
|
215
|
+
__( 'Pasted styles to %d blocks.' ),
|
|
216
|
+
targetBlocks.length
|
|
217
|
+
),
|
|
218
|
+
{ type: 'snackbar' }
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
[
|
|
223
|
+
registry.batch,
|
|
224
|
+
updateBlockAttributes,
|
|
225
|
+
createSuccessNotice,
|
|
226
|
+
createWarningNotice,
|
|
227
|
+
createErrorNotice,
|
|
228
|
+
]
|
|
229
|
+
);
|
|
230
|
+
}
|