@wordpress/block-editor 11.4.0 → 11.6.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 +8 -0
- package/build/components/block-inspector/index.js +11 -10
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-inspector/useBlockInspectorAnimationSettings.js +46 -0
- package/build/components/block-inspector/useBlockInspectorAnimationSettings.js.map +1 -0
- package/build/components/block-list/block-invalid-warning.js +63 -80
- package/build/components/block-list/block-invalid-warning.js.map +1 -1
- package/build/components/block-lock/modal.js +1 -0
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +2 -2
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +1 -1
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/block-styles/index.js +2 -1
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-switcher/block-transformations-menu.native.js +1 -0
- package/build/components/block-switcher/block-transformations-menu.native.js.map +1 -1
- package/build/components/child-layout-control/index.js +107 -0
- package/build/components/child-layout-control/index.js.map +1 -0
- package/build/components/convert-to-group-buttons/use-convert-to-group-button-props.js +6 -3
- package/build/components/convert-to-group-buttons/use-convert-to-group-button-props.js.map +1 -1
- package/build/components/date-format-picker/index.js +3 -3
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/global-styles/border-panel.js +306 -0
- package/build/components/global-styles/border-panel.js.map +1 -0
- package/build/components/global-styles/dimensions-panel.js +594 -0
- package/build/components/global-styles/dimensions-panel.js.map +1 -0
- package/build/components/global-styles/hooks.js +127 -37
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +36 -2
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +87 -27
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +21 -14
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +2 -0
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/index.native.js +23 -0
- package/build/components/index.native.js.map +1 -1
- package/build/components/inserter/index.js +29 -17
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/media-tab/hooks.js +10 -11
- package/build/components/inserter/media-tab/hooks.js.map +1 -1
- package/build/components/inserter/media-tab/media-list.js +5 -108
- package/build/components/inserter/media-tab/media-list.js.map +1 -1
- package/build/components/inserter/media-tab/media-preview.js +242 -0
- package/build/components/inserter/media-tab/media-preview.js.map +1 -0
- package/build/components/inserter/menu.js +1 -1
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter/quick-inserter.js +4 -2
- package/build/components/inserter/quick-inserter.js.map +1 -1
- package/build/components/inserter/search-results.js +10 -3
- package/build/components/inserter/search-results.js.map +1 -1
- package/build/components/inserter/tabs.js +1 -1
- package/build/components/inserter/tabs.js.map +1 -1
- package/build/components/inspector-controls/block-support-tools-panel.js +1 -1
- package/build/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build/components/inspector-controls/fill.js +38 -9
- package/build/components/inspector-controls/fill.js.map +1 -1
- package/build/components/link-control/index.js +1 -1
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/search-item.js +5 -2
- package/build/components/link-control/search-item.js.map +1 -1
- package/build/components/link-control/settings-drawer.js +1 -1
- package/build/components/link-control/settings-drawer.js.map +1 -1
- package/build/components/link-control/settings.js +1 -0
- package/build/components/link-control/settings.js.map +1 -1
- package/build/components/list-view/block.js +17 -3
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +2 -2
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/expander.js +2 -1
- package/build/components/list-view/expander.js.map +1 -1
- package/build/components/list-view/leaf.js +10 -6
- package/build/components/list-view/leaf.js.map +1 -1
- package/build/components/list-view/use-block-selection.js +1 -2
- package/build/components/list-view/use-block-selection.js.map +1 -1
- package/build/components/list-view/use-list-view-scroll-into-view.js +51 -0
- package/build/components/list-view/use-list-view-scroll-into-view.js.map +1 -0
- package/build/components/off-canvas-editor/appender.js +33 -13
- package/build/components/off-canvas-editor/appender.js.map +1 -1
- package/build/components/off-canvas-editor/branch.js +6 -3
- package/build/components/off-canvas-editor/branch.js.map +1 -1
- package/build/components/off-canvas-editor/index.js +8 -2
- package/build/components/off-canvas-editor/index.js.map +1 -1
- package/build/components/off-canvas-editor/leaf-more-menu.js +34 -4
- package/build/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
- package/build/components/provider/use-block-sync.js +17 -3
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/components/responsive-block-control/index.js +1 -0
- package/build/components/responsive-block-control/index.js.map +1 -1
- package/build/components/rich-text/format-toolbar-container.js +0 -3
- package/build/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build/components/rich-text/index.js +9 -43
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/use-delete.js +73 -0
- package/build/components/rich-text/use-delete.js.map +1 -0
- package/build/components/rich-text/use-input-rules.js +14 -6
- package/build/components/rich-text/use-input-rules.js.map +1 -1
- package/build/components/writing-flow/use-selection-observer.js +4 -1
- package/build/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build/hooks/align.js +3 -1
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/border.js +91 -240
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/custom-class-name.js +4 -4
- package/build/hooks/custom-class-name.js.map +1 -1
- package/build/hooks/custom-class-name.native.js +3 -4
- package/build/hooks/custom-class-name.native.js.map +1 -1
- package/build/hooks/dimensions.js +72 -190
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/duotone.js +94 -25
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/gap.js +0 -202
- package/build/hooks/gap.js.map +1 -1
- package/build/hooks/layout.js +33 -27
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/margin.js +7 -163
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +7 -163
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/supports.js +7 -1
- package/build/hooks/supports.js.map +1 -1
- package/build/hooks/typography.js +52 -66
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/utils.js +101 -0
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/constrained.js +6 -2
- package/build/layouts/constrained.js.map +1 -1
- package/build/layouts/flex.js +1 -0
- package/build/layouts/flex.js.map +1 -1
- package/build/private-apis.js +4 -1
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +28 -14
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +28 -1
- package/build/store/defaults.js.map +1 -1
- package/build/store/reducer.js +53 -47
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +24 -4
- package/build/store/selectors.js.map +1 -1
- package/build/utils/parse-css-unit-to-px.js +49 -10
- package/build/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-module/components/block-inspector/index.js +9 -9
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-inspector/useBlockInspectorAnimationSettings.js +37 -0
- package/build-module/components/block-inspector/useBlockInspectorAnimationSettings.js.map +1 -0
- package/build-module/components/block-list/block-invalid-warning.js +66 -78
- package/build-module/components/block-list/block-invalid-warning.js.map +1 -1
- package/build-module/components/block-lock/modal.js +1 -0
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +2 -2
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +1 -1
- package/build-module/components/block-settings-menu-controls/index.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-switcher/block-transformations-menu.native.js +1 -0
- package/build-module/components/block-switcher/block-transformations-menu.native.js.map +1 -1
- package/build-module/components/child-layout-control/index.js +98 -0
- package/build-module/components/child-layout-control/index.js.map +1 -0
- package/build-module/components/convert-to-group-buttons/use-convert-to-group-button-props.js +6 -3
- package/build-module/components/convert-to-group-buttons/use-convert-to-group-button-props.js.map +1 -1
- package/build-module/components/date-format-picker/index.js +4 -4
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +291 -0
- package/build-module/components/global-styles/border-panel.js.map +1 -0
- package/build-module/components/global-styles/dimensions-panel.js +574 -0
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -0
- package/build-module/components/global-styles/hooks.js +123 -34
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/index.js +3 -1
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +88 -27
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +21 -14
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +2 -0
- package/build-module/components/global-styles/utils.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/inserter/index.js +28 -16
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/media-tab/hooks.js +10 -11
- package/build-module/components/inserter/media-tab/hooks.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-list.js +6 -105
- package/build-module/components/inserter/media-tab/media-list.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-preview.js +222 -0
- package/build-module/components/inserter/media-tab/media-preview.js.map +1 -0
- package/build-module/components/inserter/menu.js +1 -1
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/quick-inserter.js +4 -2
- package/build-module/components/inserter/quick-inserter.js.map +1 -1
- package/build-module/components/inserter/search-results.js +10 -3
- package/build-module/components/inserter/search-results.js.map +1 -1
- package/build-module/components/inserter/tabs.js +1 -1
- package/build-module/components/inserter/tabs.js.map +1 -1
- package/build-module/components/inspector-controls/block-support-tools-panel.js +1 -1
- package/build-module/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build-module/components/inspector-controls/fill.js +39 -9
- package/build-module/components/inspector-controls/fill.js.map +1 -1
- package/build-module/components/link-control/index.js +1 -1
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/search-item.js +4 -2
- package/build-module/components/link-control/search-item.js.map +1 -1
- package/build-module/components/link-control/settings-drawer.js +1 -1
- package/build-module/components/link-control/settings-drawer.js.map +1 -1
- package/build-module/components/link-control/settings.js +1 -0
- package/build-module/components/link-control/settings.js.map +1 -1
- package/build-module/components/list-view/block.js +16 -3
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +2 -2
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/expander.js +2 -1
- package/build-module/components/list-view/expander.js.map +1 -1
- package/build-module/components/list-view/leaf.js +8 -4
- package/build-module/components/list-view/leaf.js.map +1 -1
- package/build-module/components/list-view/use-block-selection.js +1 -2
- package/build-module/components/list-view/use-block-selection.js.map +1 -1
- package/build-module/components/list-view/use-list-view-scroll-into-view.js +42 -0
- package/build-module/components/list-view/use-list-view-scroll-into-view.js.map +1 -0
- package/build-module/components/off-canvas-editor/appender.js +33 -14
- package/build-module/components/off-canvas-editor/appender.js.map +1 -1
- package/build-module/components/off-canvas-editor/branch.js +6 -3
- package/build-module/components/off-canvas-editor/branch.js.map +1 -1
- package/build-module/components/off-canvas-editor/index.js +8 -2
- package/build-module/components/off-canvas-editor/index.js.map +1 -1
- package/build-module/components/off-canvas-editor/leaf-more-menu.js +36 -7
- package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
- package/build-module/components/provider/use-block-sync.js +17 -3
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/components/responsive-block-control/index.js +1 -0
- package/build-module/components/responsive-block-control/index.js.map +1 -1
- package/build-module/components/rich-text/format-toolbar-container.js +0 -3
- package/build-module/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build-module/components/rich-text/index.js +9 -43
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/use-delete.js +62 -0
- package/build-module/components/rich-text/use-delete.js.map +1 -0
- package/build-module/components/rich-text/use-input-rules.js +14 -6
- package/build-module/components/rich-text/use-input-rules.js.map +1 -1
- package/build-module/components/writing-flow/use-selection-observer.js +4 -1
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build-module/hooks/align.js +3 -1
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/border.js +93 -240
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/custom-class-name.js +4 -4
- package/build-module/hooks/custom-class-name.js.map +1 -1
- package/build-module/hooks/custom-class-name.native.js +3 -4
- package/build-module/hooks/custom-class-name.native.js.map +1 -1
- package/build-module/hooks/dimensions.js +75 -187
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/duotone.js +86 -24
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/gap.js +0 -183
- package/build-module/hooks/gap.js.map +1 -1
- package/build-module/hooks/layout.js +33 -27
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/margin.js +4 -143
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +4 -143
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/supports.js +7 -1
- package/build-module/hooks/supports.js.map +1 -1
- package/build-module/hooks/typography.js +54 -66
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/utils.js +96 -0
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/constrained.js +6 -2
- package/build-module/layouts/constrained.js.map +1 -1
- package/build-module/layouts/flex.js +1 -0
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/private-apis.js +3 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +28 -14
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +28 -1
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/reducer.js +53 -45
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +22 -4
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/parse-css-unit-to-px.js +49 -10
- package/build-module/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-style/style-rtl.css +39 -27
- package/build-style/style.css +39 -27
- package/package.json +31 -31
- package/src/components/block-draggable/test/__snapshots__/index.native.js.snap +24 -24
- package/src/components/block-inspector/index.js +11 -14
- package/src/components/block-inspector/style.scss +3 -0
- package/src/components/block-inspector/useBlockInspectorAnimationSettings.js +53 -0
- package/src/components/block-list/block-invalid-warning.js +72 -64
- package/src/components/block-lock/modal.js +1 -0
- package/src/components/block-lock/style.scss +0 -9
- package/src/components/block-mobile-toolbar/test/__snapshots__/block-actions-menu.native.js.snap +20 -20
- package/src/components/block-mover/test/__snapshots__/index.native.js.snap +35 -17
- package/src/components/block-preview/test/index.js +0 -2
- package/src/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/src/components/block-settings-menu-controls/index.js +2 -1
- package/src/components/block-styles/index.js +5 -1
- package/src/components/block-styles/style.scss +2 -2
- package/src/components/block-switcher/block-transformations-menu.native.js +1 -0
- package/src/components/child-layout-control/index.js +106 -0
- package/src/components/color-palette/test/__snapshots__/control.js.snap +17 -15
- package/src/components/convert-to-group-buttons/use-convert-to-group-button-props.js +48 -38
- package/src/components/date-format-picker/index.js +6 -8
- package/src/components/date-format-picker/style.scss +0 -5
- package/src/components/global-styles/border-panel.js +285 -0
- package/src/components/global-styles/dimensions-panel.js +627 -0
- package/src/components/global-styles/hooks.js +160 -44
- package/src/components/global-styles/index.js +7 -1
- package/src/components/global-styles/test/use-global-styles-output.js +1 -1
- package/src/components/global-styles/typography-panel.js +81 -9
- package/src/components/global-styles/use-global-styles-output.js +17 -16
- package/src/components/global-styles/utils.js +2 -0
- package/src/components/index.native.js +5 -0
- package/src/components/inner-blocks/test/__snapshots__/index.js.snap +1 -1
- package/src/components/inserter/index.js +30 -11
- package/src/components/inserter/media-tab/hooks.js +9 -8
- package/src/components/inserter/media-tab/media-list.js +3 -122
- package/src/components/inserter/media-tab/media-preview.js +268 -0
- package/src/components/inserter/menu.js +0 -1
- package/src/components/inserter/quick-inserter.js +2 -0
- package/src/components/inserter/search-results.js +7 -1
- package/src/components/inserter/style.scss +25 -0
- package/src/components/inserter/tabs.js +1 -9
- package/src/components/inserter/test/__snapshots__/index.native.js.snap +15 -15
- package/src/components/inspector-controls/block-support-tools-panel.js +0 -1
- package/src/components/inspector-controls/fill.js +32 -8
- package/src/components/link-control/index.js +1 -1
- package/src/components/link-control/search-item.js +3 -1
- package/src/components/link-control/settings-drawer.js +2 -1
- package/src/components/link-control/settings.js +1 -0
- package/src/components/link-control/style.scss +18 -12
- package/src/components/link-control/test/index.js +3 -5
- package/src/components/list-view/block.js +19 -1
- package/src/components/list-view/branch.js +1 -2
- package/src/components/list-view/expander.js +1 -0
- package/src/components/list-view/leaf.js +43 -29
- package/src/components/list-view/use-block-selection.js +0 -2
- package/src/components/list-view/use-list-view-scroll-into-view.js +48 -0
- package/src/components/media-replace-flow/style.scss +7 -9
- package/src/components/off-canvas-editor/appender.js +44 -21
- package/src/components/off-canvas-editor/branch.js +4 -1
- package/src/components/off-canvas-editor/index.js +7 -1
- package/src/components/off-canvas-editor/leaf-more-menu.js +57 -15
- package/src/components/provider/use-block-sync.js +21 -4
- package/src/components/responsive-block-control/index.js +1 -0
- package/src/components/rich-text/format-toolbar-container.js +1 -7
- package/src/components/rich-text/index.js +8 -44
- package/src/components/rich-text/use-delete.js +59 -0
- package/src/components/rich-text/use-input-rules.js +13 -5
- package/src/components/spacing-sizes-control/style.scss +1 -1
- package/src/components/url-popover/stories/index.js +1 -0
- package/src/components/url-popover/test/index.js +0 -2
- package/src/components/writing-flow/use-selection-observer.js +5 -1
- package/src/hooks/align.js +1 -1
- package/src/hooks/border.js +94 -225
- package/src/hooks/custom-class-name.js +4 -4
- package/src/hooks/custom-class-name.native.js +3 -4
- package/src/hooks/dimensions.js +85 -269
- package/src/hooks/duotone.js +100 -30
- package/src/hooks/gap.js +0 -208
- package/src/hooks/layout.js +38 -22
- package/src/hooks/margin.js +1 -164
- package/src/hooks/padding.js +1 -163
- package/src/hooks/supports.js +6 -0
- package/src/hooks/test/__snapshots__/align.native.js.snap +24 -24
- package/src/hooks/test/duotone.js +102 -0
- package/src/hooks/test/style.js +2 -1
- package/src/hooks/test/use-typography-props.js +2 -0
- package/src/hooks/typography.js +68 -88
- package/src/hooks/utils.js +126 -0
- package/src/layouts/constrained.js +23 -17
- package/src/layouts/flex.js +1 -0
- package/src/private-apis.js +2 -0
- package/src/store/actions.js +16 -6
- package/src/store/defaults.js +14 -1
- package/src/store/reducer.js +68 -43
- package/src/store/selectors.js +28 -4
- package/src/store/test/actions.js +4 -2
- package/src/utils/parse-css-unit-to-px.js +48 -13
- package/src/utils/test/parse-css-unit-to-px.js +13 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/build/hooks/border-radius.js +0 -100
- package/build/hooks/border-radius.js.map +0 -1
- package/build/hooks/child-layout.js +0 -213
- package/build/hooks/child-layout.js.map +0 -1
- package/build/hooks/min-height.js +0 -139
- package/build/hooks/min-height.js.map +0 -1
- package/build-module/hooks/border-radius.js +0 -84
- package/build-module/hooks/border-radius.js.map +0 -1
- package/build-module/hooks/child-layout.js +0 -193
- package/build-module/hooks/child-layout.js.map +0 -1
- package/build-module/hooks/min-height.js +0 -116
- package/build-module/hooks/min-height.js.map +0 -1
- package/src/hooks/border-radius.js +0 -70
- package/src/hooks/child-layout.js +0 -195
- package/src/hooks/min-height.js +0 -104
package/src/hooks/gap.js
CHANGED
|
@@ -1,50 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { __ } from '@wordpress/i18n';
|
|
5
|
-
import { Platform } from '@wordpress/element';
|
|
6
|
-
import { getBlockSupport } from '@wordpress/blocks';
|
|
7
|
-
import {
|
|
8
|
-
__experimentalUseCustomUnits as useCustomUnits,
|
|
9
|
-
__experimentalBoxControl as BoxControl,
|
|
10
|
-
__experimentalUnitControl as UnitControl,
|
|
11
|
-
} from '@wordpress/components';
|
|
12
|
-
|
|
13
1
|
/**
|
|
14
2
|
* Internal dependencies
|
|
15
3
|
*/
|
|
16
|
-
import { __unstableUseBlockRef as useBlockRef } from '../components/block-list/use-block-props/use-block-refs';
|
|
17
4
|
import { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils';
|
|
18
|
-
import SpacingSizesControl from '../components/spacing-sizes-control';
|
|
19
|
-
import useSetting from '../components/use-setting';
|
|
20
|
-
import {
|
|
21
|
-
AXIAL_SIDES,
|
|
22
|
-
SPACING_SUPPORT_KEY,
|
|
23
|
-
useCustomSides,
|
|
24
|
-
useIsDimensionsSupportValid,
|
|
25
|
-
} from './dimensions';
|
|
26
|
-
import { cleanEmptyObject } from './utils';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Determines if there is gap support.
|
|
30
|
-
*
|
|
31
|
-
* @param {string|Object} blockType Block name or Block Type object.
|
|
32
|
-
* @return {boolean} Whether there is support.
|
|
33
|
-
*/
|
|
34
|
-
export function hasGapSupport( blockType ) {
|
|
35
|
-
const support = getBlockSupport( blockType, SPACING_SUPPORT_KEY );
|
|
36
|
-
return !! ( true === support || support?.blockGap );
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Checks if there is a current value in the gap block support attributes.
|
|
41
|
-
*
|
|
42
|
-
* @param {Object} props Block props.
|
|
43
|
-
* @return {boolean} Whether or not the block has a gap value set.
|
|
44
|
-
*/
|
|
45
|
-
export function hasGapValue( props ) {
|
|
46
|
-
return props.attributes.style?.spacing?.blockGap !== undefined;
|
|
47
|
-
}
|
|
48
5
|
|
|
49
6
|
/**
|
|
50
7
|
* Returns a BoxControl object value from a given blockGap style value.
|
|
@@ -87,168 +44,3 @@ export function getGapCSSValue( blockGapValue, defaultValue = '0' ) {
|
|
|
87
44
|
|
|
88
45
|
return row === column ? row : `${ row } ${ column }`;
|
|
89
46
|
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Resets the gap block support attribute. This can be used when disabling
|
|
93
|
-
* the gap support controls for a block via a progressive discovery panel.
|
|
94
|
-
*
|
|
95
|
-
* @param {Object} props Block props.
|
|
96
|
-
* @param {Object} props.attributes Block's attributes.
|
|
97
|
-
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
98
|
-
*/
|
|
99
|
-
export function resetGap( { attributes = {}, setAttributes } ) {
|
|
100
|
-
const { style } = attributes;
|
|
101
|
-
|
|
102
|
-
setAttributes( {
|
|
103
|
-
style: {
|
|
104
|
-
...style,
|
|
105
|
-
spacing: {
|
|
106
|
-
...style?.spacing,
|
|
107
|
-
blockGap: undefined,
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
} );
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Custom hook that checks if gap settings have been disabled.
|
|
115
|
-
*
|
|
116
|
-
* @param {string} name The name of the block.
|
|
117
|
-
* @return {boolean} Whether the gap setting is disabled.
|
|
118
|
-
*/
|
|
119
|
-
export function useIsGapDisabled( { name: blockName } = {} ) {
|
|
120
|
-
const isDisabled = ! useSetting( 'spacing.blockGap' );
|
|
121
|
-
const isInvalid = ! useIsDimensionsSupportValid( blockName, 'blockGap' );
|
|
122
|
-
|
|
123
|
-
return ! hasGapSupport( blockName ) || isDisabled || isInvalid;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Inspector control panel containing the gap related configuration
|
|
128
|
-
*
|
|
129
|
-
* @param {Object} props
|
|
130
|
-
*
|
|
131
|
-
* @return {WPElement} Gap edit element.
|
|
132
|
-
*/
|
|
133
|
-
export function GapEdit( props ) {
|
|
134
|
-
const {
|
|
135
|
-
clientId,
|
|
136
|
-
attributes: { style },
|
|
137
|
-
name: blockName,
|
|
138
|
-
setAttributes,
|
|
139
|
-
} = props;
|
|
140
|
-
|
|
141
|
-
const spacingSizes = useSetting( 'spacing.spacingSizes' );
|
|
142
|
-
|
|
143
|
-
const units = useCustomUnits( {
|
|
144
|
-
availableUnits: useSetting( 'spacing.units' ) || [
|
|
145
|
-
'%',
|
|
146
|
-
'px',
|
|
147
|
-
'em',
|
|
148
|
-
'rem',
|
|
149
|
-
'vw',
|
|
150
|
-
],
|
|
151
|
-
} );
|
|
152
|
-
const sides = useCustomSides( blockName, 'blockGap' );
|
|
153
|
-
const ref = useBlockRef( clientId );
|
|
154
|
-
|
|
155
|
-
if ( useIsGapDisabled( props ) ) {
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const splitOnAxis =
|
|
160
|
-
sides && sides.some( ( side ) => AXIAL_SIDES.includes( side ) );
|
|
161
|
-
|
|
162
|
-
const onChange = ( next ) => {
|
|
163
|
-
let blockGap = next;
|
|
164
|
-
|
|
165
|
-
// If splitOnAxis activated we need to return a BoxControl object to the BoxControl component.
|
|
166
|
-
if ( !! next && splitOnAxis ) {
|
|
167
|
-
blockGap = { ...getGapBoxControlValueFromStyle( next ) };
|
|
168
|
-
} else if ( next?.hasOwnProperty( 'top' ) ) {
|
|
169
|
-
// If splitOnAxis is not enabled, treat the 'top' value as the shorthand gap value.
|
|
170
|
-
blockGap = next.top;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const newStyle = {
|
|
174
|
-
...style,
|
|
175
|
-
spacing: {
|
|
176
|
-
...style?.spacing,
|
|
177
|
-
blockGap,
|
|
178
|
-
},
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
setAttributes( {
|
|
182
|
-
style: cleanEmptyObject( newStyle ),
|
|
183
|
-
} );
|
|
184
|
-
|
|
185
|
-
// In Safari, changing the `gap` CSS value on its own will not trigger the layout
|
|
186
|
-
// to be recalculated / re-rendered. To force the updated gap to re-render, here
|
|
187
|
-
// we replace the block's node with itself.
|
|
188
|
-
const isSafari =
|
|
189
|
-
window?.navigator.userAgent &&
|
|
190
|
-
window.navigator.userAgent.includes( 'Safari' ) &&
|
|
191
|
-
! window.navigator.userAgent.includes( 'Chrome ' ) &&
|
|
192
|
-
! window.navigator.userAgent.includes( 'Chromium ' );
|
|
193
|
-
|
|
194
|
-
if ( ref.current && isSafari ) {
|
|
195
|
-
ref.current.parentNode?.replaceChild( ref.current, ref.current );
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const gapValue = getGapBoxControlValueFromStyle( style?.spacing?.blockGap );
|
|
200
|
-
|
|
201
|
-
// The BoxControl component expects a full complement of side values.
|
|
202
|
-
// Gap row and column values translate to top/bottom and left/right respectively.
|
|
203
|
-
const boxControlGapValue = splitOnAxis
|
|
204
|
-
? {
|
|
205
|
-
...gapValue,
|
|
206
|
-
right: gapValue?.left,
|
|
207
|
-
bottom: gapValue?.top,
|
|
208
|
-
}
|
|
209
|
-
: {
|
|
210
|
-
top: gapValue?.top,
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
return Platform.select( {
|
|
214
|
-
web: (
|
|
215
|
-
<>
|
|
216
|
-
{ ( ! spacingSizes || spacingSizes?.length === 0 ) &&
|
|
217
|
-
( splitOnAxis ? (
|
|
218
|
-
<BoxControl
|
|
219
|
-
label={ __( 'Block spacing' ) }
|
|
220
|
-
min={ 0 }
|
|
221
|
-
onChange={ onChange }
|
|
222
|
-
units={ units }
|
|
223
|
-
sides={ sides }
|
|
224
|
-
values={ boxControlGapValue }
|
|
225
|
-
allowReset={ false }
|
|
226
|
-
splitOnAxis={ splitOnAxis }
|
|
227
|
-
/>
|
|
228
|
-
) : (
|
|
229
|
-
<UnitControl
|
|
230
|
-
label={ __( 'Block spacing' ) }
|
|
231
|
-
__unstableInputWidth="80px"
|
|
232
|
-
min={ 0 }
|
|
233
|
-
onChange={ onChange }
|
|
234
|
-
units={ units }
|
|
235
|
-
// Default to `row` for combined values.
|
|
236
|
-
value={ boxControlGapValue }
|
|
237
|
-
/>
|
|
238
|
-
) ) }
|
|
239
|
-
{ spacingSizes?.length > 0 && (
|
|
240
|
-
<SpacingSizesControl
|
|
241
|
-
values={ boxControlGapValue }
|
|
242
|
-
onChange={ onChange }
|
|
243
|
-
label={ __( 'Block spacing' ) }
|
|
244
|
-
sides={ splitOnAxis ? sides : [ 'top' ] } // Use 'top' as the shorthand property in non-axial configurations.
|
|
245
|
-
units={ units }
|
|
246
|
-
allowReset={ false }
|
|
247
|
-
splitOnAxis={ splitOnAxis }
|
|
248
|
-
/>
|
|
249
|
-
) }
|
|
250
|
-
</>
|
|
251
|
-
),
|
|
252
|
-
native: null,
|
|
253
|
-
} );
|
|
254
|
-
}
|
package/src/hooks/layout.js
CHANGED
|
@@ -35,11 +35,12 @@ const layoutBlockSupportKey = '__experimentalLayout';
|
|
|
35
35
|
/**
|
|
36
36
|
* Generates the utility classnames for the given block's layout attributes.
|
|
37
37
|
*
|
|
38
|
-
* @param { Object }
|
|
38
|
+
* @param { Object } blockAttributes Block attributes.
|
|
39
|
+
* @param { string } blockName Block name.
|
|
39
40
|
*
|
|
40
41
|
* @return { Array } Array of CSS classname strings.
|
|
41
42
|
*/
|
|
42
|
-
export function useLayoutClasses(
|
|
43
|
+
export function useLayoutClasses( blockAttributes = {}, blockName = '' ) {
|
|
43
44
|
const rootPaddingAlignment = useSelect( ( select ) => {
|
|
44
45
|
const { getSettings } = select( blockEditorStore );
|
|
45
46
|
return getSettings().__experimentalFeatures
|
|
@@ -47,11 +48,10 @@ export function useLayoutClasses( block = {} ) {
|
|
|
47
48
|
}, [] );
|
|
48
49
|
const globalLayoutSettings = useSetting( 'layout' ) || {};
|
|
49
50
|
|
|
50
|
-
const {
|
|
51
|
-
const { layout } = attributes;
|
|
51
|
+
const { layout } = blockAttributes;
|
|
52
52
|
|
|
53
53
|
const { default: defaultBlockLayout } =
|
|
54
|
-
getBlockSupport(
|
|
54
|
+
getBlockSupport( blockName, layoutBlockSupportKey ) || {};
|
|
55
55
|
const usedLayout =
|
|
56
56
|
layout?.inherit || layout?.contentSize || layout?.wideSize
|
|
57
57
|
? { ...layout, type: 'constrained' }
|
|
@@ -63,10 +63,13 @@ export function useLayoutClasses( block = {} ) {
|
|
|
63
63
|
globalLayoutSettings?.definitions?.[ usedLayout?.type || 'default' ]
|
|
64
64
|
?.className
|
|
65
65
|
) {
|
|
66
|
-
|
|
66
|
+
const baseClassName =
|
|
67
67
|
globalLayoutSettings?.definitions?.[ usedLayout?.type || 'default' ]
|
|
68
|
-
?.className
|
|
69
|
-
|
|
68
|
+
?.className;
|
|
69
|
+
const compoundClassName = `wp-block-${ blockName
|
|
70
|
+
.split( '/' )
|
|
71
|
+
.pop() }-${ baseClassName }`;
|
|
72
|
+
layoutClassnames.push( baseClassName, compoundClassName );
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
if (
|
|
@@ -100,14 +103,14 @@ export function useLayoutClasses( block = {} ) {
|
|
|
100
103
|
/**
|
|
101
104
|
* Generates a CSS rule with the given block's layout styles.
|
|
102
105
|
*
|
|
103
|
-
* @param { Object }
|
|
104
|
-
* @param { string }
|
|
106
|
+
* @param { Object } blockAttributes Block attributes.
|
|
107
|
+
* @param { string } blockName Block name.
|
|
108
|
+
* @param { string } selector A selector to use in generating the CSS rule.
|
|
105
109
|
*
|
|
106
110
|
* @return { string } CSS rule.
|
|
107
111
|
*/
|
|
108
|
-
export function useLayoutStyles(
|
|
109
|
-
const {
|
|
110
|
-
const { layout = {}, style = {} } = attributes;
|
|
112
|
+
export function useLayoutStyles( blockAttributes = {}, blockName, selector ) {
|
|
113
|
+
const { layout = {}, style = {} } = blockAttributes;
|
|
111
114
|
// Update type for blocks using legacy layouts.
|
|
112
115
|
const usedLayout =
|
|
113
116
|
layout?.inherit || layout?.contentSize || layout?.wideSize
|
|
@@ -118,7 +121,7 @@ export function useLayoutStyles( block = {}, selector ) {
|
|
|
118
121
|
const blockGapSupport = useSetting( 'spacing.blockGap' );
|
|
119
122
|
const hasBlockGapSupport = blockGapSupport !== null;
|
|
120
123
|
const css = fullLayoutType?.getLayoutStyle?.( {
|
|
121
|
-
blockName
|
|
124
|
+
blockName,
|
|
122
125
|
selector,
|
|
123
126
|
layout,
|
|
124
127
|
layoutDefinitions: globalLayoutSettings?.definitions,
|
|
@@ -128,13 +131,25 @@ export function useLayoutStyles( block = {}, selector ) {
|
|
|
128
131
|
return css;
|
|
129
132
|
}
|
|
130
133
|
|
|
131
|
-
function LayoutPanel( {
|
|
134
|
+
function LayoutPanel( {
|
|
135
|
+
clientId,
|
|
136
|
+
setAttributes,
|
|
137
|
+
attributes,
|
|
138
|
+
name: blockName,
|
|
139
|
+
} ) {
|
|
132
140
|
const { layout } = attributes;
|
|
133
141
|
const defaultThemeLayout = useSetting( 'layout' );
|
|
134
|
-
const themeSupportsLayout = useSelect(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
142
|
+
const { themeSupportsLayout, isContentLocked } = useSelect(
|
|
143
|
+
( select ) => {
|
|
144
|
+
const { getSettings, __unstableGetContentLockingParent } =
|
|
145
|
+
select( blockEditorStore );
|
|
146
|
+
return {
|
|
147
|
+
themeSupportsLayout: getSettings().supportsLayout,
|
|
148
|
+
isContentLocked: __unstableGetContentLockingParent( clientId ),
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
[ clientId ]
|
|
152
|
+
);
|
|
138
153
|
|
|
139
154
|
const layoutBlockSupport = getBlockSupport(
|
|
140
155
|
blockName,
|
|
@@ -199,6 +214,7 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
|
|
|
199
214
|
{ showInheritToggle && (
|
|
200
215
|
<>
|
|
201
216
|
<ToggleControl
|
|
217
|
+
__nextHasNoMarginBottom
|
|
202
218
|
className="block-editor-hooks__toggle-control"
|
|
203
219
|
label={ __( 'Inner blocks use content width' ) }
|
|
204
220
|
checked={
|
|
@@ -254,7 +270,7 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
|
|
|
254
270
|
) }
|
|
255
271
|
</PanelBody>
|
|
256
272
|
</InspectorControls>
|
|
257
|
-
{ ! inherit && layoutType && (
|
|
273
|
+
{ ! inherit && ! isContentLocked && layoutType && (
|
|
258
274
|
<layoutType.toolBarControls
|
|
259
275
|
layout={ usedLayout }
|
|
260
276
|
onChange={ onChangeLayout }
|
|
@@ -338,7 +354,7 @@ export const withInspectorControls = createHigherOrderComponent(
|
|
|
338
354
|
*/
|
|
339
355
|
export const withLayoutStyles = createHigherOrderComponent(
|
|
340
356
|
( BlockListBlock ) => ( props ) => {
|
|
341
|
-
const { name, attributes
|
|
357
|
+
const { name, attributes } = props;
|
|
342
358
|
const hasLayoutBlockSupport = hasBlockSupport(
|
|
343
359
|
name,
|
|
344
360
|
layoutBlockSupportKey
|
|
@@ -360,7 +376,7 @@ export const withLayoutStyles = createHigherOrderComponent(
|
|
|
360
376
|
? { ...layout, type: 'constrained' }
|
|
361
377
|
: layout || defaultBlockLayout || {};
|
|
362
378
|
const layoutClasses = hasLayoutBlockSupport
|
|
363
|
-
? useLayoutClasses(
|
|
379
|
+
? useLayoutClasses( attributes, name )
|
|
364
380
|
: null;
|
|
365
381
|
// Higher specificity to override defaults from theme.json.
|
|
366
382
|
const selector = `.wp-container-${ id }.wp-container-${ id }`;
|
package/src/hooks/margin.js
CHANGED
|
@@ -1,178 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
Platform,
|
|
7
|
-
useMemo,
|
|
8
|
-
useRef,
|
|
9
|
-
useState,
|
|
10
|
-
useEffect,
|
|
11
|
-
} from '@wordpress/element';
|
|
12
|
-
import { getBlockSupport } from '@wordpress/blocks';
|
|
13
|
-
import {
|
|
14
|
-
__experimentalUseCustomUnits as useCustomUnits,
|
|
15
|
-
__experimentalBoxControl as BoxControl,
|
|
16
|
-
} from '@wordpress/components';
|
|
4
|
+
import { useMemo, useRef, useState, useEffect } from '@wordpress/element';
|
|
17
5
|
import isShallowEqual from '@wordpress/is-shallow-equal';
|
|
18
6
|
|
|
19
7
|
/**
|
|
20
8
|
* Internal dependencies
|
|
21
9
|
*/
|
|
22
|
-
import useSetting from '../components/use-setting';
|
|
23
|
-
import {
|
|
24
|
-
AXIAL_SIDES,
|
|
25
|
-
SPACING_SUPPORT_KEY,
|
|
26
|
-
useCustomSides,
|
|
27
|
-
useIsDimensionsSupportValid,
|
|
28
|
-
} from './dimensions';
|
|
29
|
-
import { cleanEmptyObject } from './utils';
|
|
30
10
|
import BlockPopover from '../components/block-popover';
|
|
31
|
-
import SpacingSizesControl from '../components/spacing-sizes-control';
|
|
32
11
|
import { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils';
|
|
33
12
|
|
|
34
|
-
/**
|
|
35
|
-
* Determines if there is margin support.
|
|
36
|
-
*
|
|
37
|
-
* @param {string|Object} blockType Block name or Block Type object.
|
|
38
|
-
*
|
|
39
|
-
* @return {boolean} Whether there is support.
|
|
40
|
-
*/
|
|
41
|
-
export function hasMarginSupport( blockType ) {
|
|
42
|
-
const support = getBlockSupport( blockType, SPACING_SUPPORT_KEY );
|
|
43
|
-
return !! ( true === support || support?.margin );
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Checks if there is a current value in the margin block support attributes.
|
|
48
|
-
*
|
|
49
|
-
* @param {Object} props Block props.
|
|
50
|
-
* @return {boolean} Whether or not the block has a margin value set.
|
|
51
|
-
*/
|
|
52
|
-
export function hasMarginValue( props ) {
|
|
53
|
-
return props.attributes.style?.spacing?.margin !== undefined;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Resets the margin block support attributes. This can be used when disabling
|
|
58
|
-
* the margin support controls for a block via a `ToolsPanel`.
|
|
59
|
-
*
|
|
60
|
-
* @param {Object} props Block props.
|
|
61
|
-
* @param {Object} props.attributes Block's attributes.
|
|
62
|
-
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
63
|
-
*/
|
|
64
|
-
export function resetMargin( { attributes = {}, setAttributes } ) {
|
|
65
|
-
const { style } = attributes;
|
|
66
|
-
|
|
67
|
-
setAttributes( {
|
|
68
|
-
style: cleanEmptyObject( {
|
|
69
|
-
...style,
|
|
70
|
-
spacing: {
|
|
71
|
-
...style?.spacing,
|
|
72
|
-
margin: undefined,
|
|
73
|
-
},
|
|
74
|
-
} ),
|
|
75
|
-
} );
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Custom hook that checks if margin settings have been disabled.
|
|
80
|
-
*
|
|
81
|
-
* @param {string} name The name of the block.
|
|
82
|
-
*
|
|
83
|
-
* @return {boolean} Whether margin setting is disabled.
|
|
84
|
-
*/
|
|
85
|
-
export function useIsMarginDisabled( { name: blockName } = {} ) {
|
|
86
|
-
const isDisabled = ! useSetting( 'spacing.margin' );
|
|
87
|
-
const isInvalid = ! useIsDimensionsSupportValid( blockName, 'margin' );
|
|
88
|
-
|
|
89
|
-
return ! hasMarginSupport( blockName ) || isDisabled || isInvalid;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Inspector control panel containing the margin related configuration
|
|
94
|
-
*
|
|
95
|
-
* @param {Object} props Block props.
|
|
96
|
-
*
|
|
97
|
-
* @return {WPElement} Margin edit element.
|
|
98
|
-
*/
|
|
99
|
-
export function MarginEdit( props ) {
|
|
100
|
-
const {
|
|
101
|
-
name: blockName,
|
|
102
|
-
attributes: { style },
|
|
103
|
-
setAttributes,
|
|
104
|
-
onMouseOver,
|
|
105
|
-
onMouseOut,
|
|
106
|
-
} = props;
|
|
107
|
-
|
|
108
|
-
const spacingSizes = useSetting( 'spacing.spacingSizes' );
|
|
109
|
-
|
|
110
|
-
const units = useCustomUnits( {
|
|
111
|
-
availableUnits: useSetting( 'spacing.units' ) || [
|
|
112
|
-
'%',
|
|
113
|
-
'px',
|
|
114
|
-
'em',
|
|
115
|
-
'rem',
|
|
116
|
-
'vw',
|
|
117
|
-
],
|
|
118
|
-
} );
|
|
119
|
-
const sides = useCustomSides( blockName, 'margin' );
|
|
120
|
-
const splitOnAxis =
|
|
121
|
-
sides && sides.some( ( side ) => AXIAL_SIDES.includes( side ) );
|
|
122
|
-
|
|
123
|
-
if ( useIsMarginDisabled( props ) ) {
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const onChange = ( next ) => {
|
|
128
|
-
const newStyle = {
|
|
129
|
-
...style,
|
|
130
|
-
spacing: {
|
|
131
|
-
...style?.spacing,
|
|
132
|
-
margin: next,
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
setAttributes( {
|
|
137
|
-
style: cleanEmptyObject( newStyle ),
|
|
138
|
-
} );
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
return Platform.select( {
|
|
142
|
-
web: (
|
|
143
|
-
<>
|
|
144
|
-
{ ( ! spacingSizes || spacingSizes?.length === 0 ) && (
|
|
145
|
-
<BoxControl
|
|
146
|
-
values={ style?.spacing?.margin }
|
|
147
|
-
onChange={ onChange }
|
|
148
|
-
label={ __( 'Margin' ) }
|
|
149
|
-
sides={ sides }
|
|
150
|
-
units={ units }
|
|
151
|
-
allowReset={ false }
|
|
152
|
-
splitOnAxis={ splitOnAxis }
|
|
153
|
-
onMouseOver={ onMouseOver }
|
|
154
|
-
onMouseOut={ onMouseOut }
|
|
155
|
-
/>
|
|
156
|
-
) }
|
|
157
|
-
{ spacingSizes?.length > 0 && (
|
|
158
|
-
<SpacingSizesControl
|
|
159
|
-
values={ style?.spacing?.margin }
|
|
160
|
-
onChange={ onChange }
|
|
161
|
-
label={ __( 'Margin' ) }
|
|
162
|
-
sides={ sides }
|
|
163
|
-
units={ units }
|
|
164
|
-
allowReset={ false }
|
|
165
|
-
splitOnAxis={ false }
|
|
166
|
-
onMouseOver={ onMouseOver }
|
|
167
|
-
onMouseOut={ onMouseOut }
|
|
168
|
-
/>
|
|
169
|
-
) }
|
|
170
|
-
</>
|
|
171
|
-
),
|
|
172
|
-
native: null,
|
|
173
|
-
} );
|
|
174
|
-
}
|
|
175
|
-
|
|
176
13
|
export function MarginVisualizer( { clientId, attributes, forceShow } ) {
|
|
177
14
|
const margin = attributes?.style?.spacing?.margin;
|
|
178
15
|
|
package/src/hooks/padding.js
CHANGED
|
@@ -1,176 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
Platform,
|
|
7
|
-
useState,
|
|
8
|
-
useRef,
|
|
9
|
-
useEffect,
|
|
10
|
-
useMemo,
|
|
11
|
-
} from '@wordpress/element';
|
|
12
|
-
import { getBlockSupport } from '@wordpress/blocks';
|
|
13
|
-
import {
|
|
14
|
-
__experimentalUseCustomUnits as useCustomUnits,
|
|
15
|
-
__experimentalBoxControl as BoxControl,
|
|
16
|
-
} from '@wordpress/components';
|
|
4
|
+
import { useState, useRef, useEffect, useMemo } from '@wordpress/element';
|
|
17
5
|
import isShallowEqual from '@wordpress/is-shallow-equal';
|
|
18
6
|
|
|
19
7
|
/**
|
|
20
8
|
* Internal dependencies
|
|
21
9
|
*/
|
|
22
|
-
import useSetting from '../components/use-setting';
|
|
23
|
-
import {
|
|
24
|
-
AXIAL_SIDES,
|
|
25
|
-
SPACING_SUPPORT_KEY,
|
|
26
|
-
useCustomSides,
|
|
27
|
-
useIsDimensionsSupportValid,
|
|
28
|
-
} from './dimensions';
|
|
29
|
-
import { cleanEmptyObject } from './utils';
|
|
30
10
|
import BlockPopover from '../components/block-popover';
|
|
31
|
-
import SpacingSizesControl from '../components/spacing-sizes-control';
|
|
32
11
|
import { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils';
|
|
33
|
-
/**
|
|
34
|
-
* Determines if there is padding support.
|
|
35
|
-
*
|
|
36
|
-
* @param {string|Object} blockType Block name or Block Type object.
|
|
37
|
-
*
|
|
38
|
-
* @return {boolean} Whether there is support.
|
|
39
|
-
*/
|
|
40
|
-
export function hasPaddingSupport( blockType ) {
|
|
41
|
-
const support = getBlockSupport( blockType, SPACING_SUPPORT_KEY );
|
|
42
|
-
return !! ( true === support || support?.padding );
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Checks if there is a current value in the padding block support attributes.
|
|
47
|
-
*
|
|
48
|
-
* @param {Object} props Block props.
|
|
49
|
-
* @return {boolean} Whether or not the block has a padding value set.
|
|
50
|
-
*/
|
|
51
|
-
export function hasPaddingValue( props ) {
|
|
52
|
-
return props.attributes.style?.spacing?.padding !== undefined;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Resets the padding block support attributes. This can be used when disabling
|
|
57
|
-
* the padding support controls for a block via a `ToolsPanel`.
|
|
58
|
-
*
|
|
59
|
-
* @param {Object} props Block props.
|
|
60
|
-
* @param {Object} props.attributes Block's attributes.
|
|
61
|
-
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
62
|
-
*/
|
|
63
|
-
export function resetPadding( { attributes = {}, setAttributes } ) {
|
|
64
|
-
const { style } = attributes;
|
|
65
|
-
|
|
66
|
-
setAttributes( {
|
|
67
|
-
style: cleanEmptyObject( {
|
|
68
|
-
...style,
|
|
69
|
-
spacing: {
|
|
70
|
-
...style?.spacing,
|
|
71
|
-
padding: undefined,
|
|
72
|
-
},
|
|
73
|
-
} ),
|
|
74
|
-
} );
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Custom hook that checks if padding settings have been disabled.
|
|
79
|
-
*
|
|
80
|
-
* @param {string} name The name of the block.
|
|
81
|
-
*
|
|
82
|
-
* @return {boolean} Whether padding setting is disabled.
|
|
83
|
-
*/
|
|
84
|
-
export function useIsPaddingDisabled( { name: blockName } = {} ) {
|
|
85
|
-
const isDisabled = ! useSetting( 'spacing.padding' );
|
|
86
|
-
const isInvalid = ! useIsDimensionsSupportValid( blockName, 'padding' );
|
|
87
|
-
|
|
88
|
-
return ! hasPaddingSupport( blockName ) || isDisabled || isInvalid;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Inspector control panel containing the padding related configuration
|
|
93
|
-
*
|
|
94
|
-
* @param {Object} props
|
|
95
|
-
*
|
|
96
|
-
* @return {WPElement} Padding edit element.
|
|
97
|
-
*/
|
|
98
|
-
export function PaddingEdit( props ) {
|
|
99
|
-
const {
|
|
100
|
-
name: blockName,
|
|
101
|
-
attributes: { style },
|
|
102
|
-
setAttributes,
|
|
103
|
-
onMouseOver,
|
|
104
|
-
onMouseOut,
|
|
105
|
-
} = props;
|
|
106
|
-
|
|
107
|
-
const spacingSizes = useSetting( 'spacing.spacingSizes' );
|
|
108
|
-
|
|
109
|
-
const units = useCustomUnits( {
|
|
110
|
-
availableUnits: useSetting( 'spacing.units' ) || [
|
|
111
|
-
'%',
|
|
112
|
-
'px',
|
|
113
|
-
'em',
|
|
114
|
-
'rem',
|
|
115
|
-
'vw',
|
|
116
|
-
],
|
|
117
|
-
} );
|
|
118
|
-
const sides = useCustomSides( blockName, 'padding' );
|
|
119
|
-
const splitOnAxis =
|
|
120
|
-
sides && sides.some( ( side ) => AXIAL_SIDES.includes( side ) );
|
|
121
|
-
|
|
122
|
-
if ( useIsPaddingDisabled( props ) ) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const onChange = ( next ) => {
|
|
127
|
-
const newStyle = {
|
|
128
|
-
...style,
|
|
129
|
-
spacing: {
|
|
130
|
-
...style?.spacing,
|
|
131
|
-
padding: next,
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
setAttributes( {
|
|
136
|
-
style: cleanEmptyObject( newStyle ),
|
|
137
|
-
} );
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
return Platform.select( {
|
|
141
|
-
web: (
|
|
142
|
-
<>
|
|
143
|
-
{ ( ! spacingSizes || spacingSizes?.length === 0 ) && (
|
|
144
|
-
<BoxControl
|
|
145
|
-
values={ style?.spacing?.padding }
|
|
146
|
-
onChange={ onChange }
|
|
147
|
-
label={ __( 'Padding' ) }
|
|
148
|
-
sides={ sides }
|
|
149
|
-
units={ units }
|
|
150
|
-
allowReset={ false }
|
|
151
|
-
splitOnAxis={ splitOnAxis }
|
|
152
|
-
onMouseOver={ onMouseOver }
|
|
153
|
-
onMouseOut={ onMouseOut }
|
|
154
|
-
/>
|
|
155
|
-
) }
|
|
156
|
-
{ spacingSizes?.length > 0 && (
|
|
157
|
-
<SpacingSizesControl
|
|
158
|
-
values={ style?.spacing?.padding }
|
|
159
|
-
onChange={ onChange }
|
|
160
|
-
label={ __( 'Padding' ) }
|
|
161
|
-
sides={ sides }
|
|
162
|
-
units={ units }
|
|
163
|
-
allowReset={ false }
|
|
164
|
-
splitOnAxis={ splitOnAxis }
|
|
165
|
-
onMouseOver={ onMouseOver }
|
|
166
|
-
onMouseOut={ onMouseOut }
|
|
167
|
-
/>
|
|
168
|
-
) }
|
|
169
|
-
</>
|
|
170
|
-
),
|
|
171
|
-
native: null,
|
|
172
|
-
} );
|
|
173
|
-
}
|
|
174
12
|
|
|
175
13
|
export function PaddingVisualizer( { clientId, attributes, forceShow } ) {
|
|
176
14
|
const padding = attributes?.style?.spacing?.padding;
|