@wordpress/block-editor 12.4.0 → 12.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 +4 -0
- package/README.md +1 -0
- package/build/components/block-draggable/index.js +6 -3
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-draggable/index.native.js +2 -2
- package/build/components/block-draggable/index.native.js.map +1 -1
- package/build/components/block-edit/edit.js +25 -13
- package/build/components/block-edit/edit.js.map +1 -1
- package/build/components/block-heading-level-dropdown/heading-level-icon.js +10 -2
- package/build/components/block-heading-level-dropdown/heading-level-icon.js.map +1 -1
- package/build/components/block-heading-level-dropdown/index.native.js +4 -3
- package/build/components/block-heading-level-dropdown/index.native.js.map +1 -1
- package/build/components/block-list/block-outline.native.js +14 -18
- package/build/components/block-list/block-outline.native.js.map +1 -1
- package/build/components/block-list/block.native.js +21 -42
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-lock/toolbar.js +25 -6
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-mover/index.native.js +1 -1
- package/build/components/block-mover/index.native.js.map +1 -1
- package/build/components/block-parent-selector/index.js +8 -5
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-removal-warning-modal/index.js +15 -25
- package/build/components/block-removal-warning-modal/index.js.map +1 -1
- package/build/components/block-settings/button.native.js +2 -2
- package/build/components/block-settings/button.native.js.map +1 -1
- package/build/components/{block-mobile-toolbar/block-actions-menu.native.js → block-toolbar/block-toolbar-menu.native.js} +10 -11
- package/build/components/block-toolbar/block-toolbar-menu.native.js.map +1 -0
- package/build/components/block-toolbar/index.js +12 -8
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-toolbar/index.native.js +62 -3
- package/build/components/block-toolbar/index.native.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +7 -11
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/colors-gradients/control.js +4 -2
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/dimensions-tool/aspect-ratio-tool.js +99 -0
- package/build/components/dimensions-tool/aspect-ratio-tool.js.map +1 -0
- package/build/components/dimensions-tool/index.js +207 -0
- package/build/components/dimensions-tool/index.js.map +1 -0
- package/build/components/dimensions-tool/scale-tool.js +111 -0
- package/build/components/dimensions-tool/scale-tool.js.map +1 -0
- package/build/components/dimensions-tool/width-height-tool.js +125 -0
- package/build/components/dimensions-tool/width-height-tool.js.map +1 -0
- package/build/components/global-styles/color-panel.js +22 -16
- package/build/components/global-styles/color-panel.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +13 -2
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/filters-panel.js +1 -1
- package/build/components/global-styles/filters-panel.js.map +1 -1
- package/build/components/global-styles/get-block-css-selector.js +4 -8
- package/build/components/global-styles/get-block-css-selector.js.map +1 -1
- package/build/components/global-styles/hooks.js +15 -25
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +52 -5
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +12 -18
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +6 -6
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/iframe/index.js +36 -48
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/iframe/use-compatibility-styles.js +5 -0
- package/build/components/iframe/use-compatibility-styles.js.map +1 -1
- package/build/components/image-editor/aspect-ratio-dropdown.js +1 -1
- package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build/components/image-editor/use-save-image.js +1 -2
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/image-size-control/index.js +6 -0
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/index.js +9 -0
- package/build/components/index.js.map +1 -1
- package/build/components/inner-blocks/index.js +3 -1
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inner-blocks/index.native.js +3 -1
- package/build/components/inner-blocks/index.native.js.map +1 -1
- package/build/components/inner-blocks/use-nested-settings-update.js +33 -7
- package/build/components/inner-blocks/use-nested-settings-update.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/patterns-list.js +2 -2
- package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +7 -35
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/hooks/use-block-types-state.js +3 -4
- package/build/components/inserter/hooks/use-block-types-state.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-state.js +9 -3
- package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build/components/inserter/index.js +2 -4
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/index.native.js +21 -32
- package/build/components/inserter/index.native.js.map +1 -1
- package/build/components/inserter/media-tab/hooks.js +2 -21
- package/build/components/inserter/media-tab/hooks.js.map +1 -1
- package/build/components/inserter/reusable-block-rename-hint.js +82 -0
- package/build/components/inserter/reusable-block-rename-hint.js.map +1 -0
- package/build/components/inserter/reusable-blocks-tab.js +6 -2
- package/build/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build/components/inserter/reusable-blocks-tab.native.js +2 -2
- package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build/components/inserter/tabs.native.js +1 -1
- package/build/components/inserter/tabs.native.js.map +1 -1
- package/build/components/inserter-draggable-blocks/index.js +9 -1
- package/build/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build/components/link-control/constants.js +1 -1
- package/build/components/link-control/constants.js.map +1 -1
- package/build/components/link-control/index.js +21 -16
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/search-create-button.js +5 -21
- package/build/components/link-control/search-create-button.js.map +1 -1
- package/build/components/link-control/search-input.js +4 -4
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/link-control/search-item.js +13 -30
- package/build/components/link-control/search-item.js.map +1 -1
- package/build/components/link-control/search-results.js +2 -2
- package/build/components/link-control/search-results.js.map +1 -1
- package/build/components/link-control/settings-drawer.js +2 -3
- package/build/components/link-control/settings-drawer.js.map +1 -1
- package/build/components/list-view/appender.js +2 -6
- package/build/components/list-view/appender.js.map +1 -1
- package/build/components/list-view/use-list-view-client-ids.js +2 -2
- package/build/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build/components/media-placeholder/index.native.js +65 -31
- package/build/components/media-placeholder/index.native.js.map +1 -1
- package/build/components/preview-options/index.js +2 -2
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/provider/index.js +5 -2
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/use-block-sync.js +21 -0
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/components/resolution-tool/index.js +55 -0
- package/build/components/resolution-tool/index.js.map +1 -0
- package/build/components/rich-text/content.js +0 -36
- package/build/components/rich-text/content.js.map +1 -1
- package/build/components/rich-text/get-rich-text-values.js +118 -0
- package/build/components/rich-text/get-rich-text-values.js.map +1 -0
- package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js +1 -1
- package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
- package/build/components/spacing-sizes-control/input-controls/axial.js +6 -2
- package/build/components/spacing-sizes-control/input-controls/axial.js.map +1 -1
- package/build/components/spacing-sizes-control/input-controls/separated.js +5 -1
- package/build/components/spacing-sizes-control/input-controls/separated.js.map +1 -1
- package/build/components/spacing-sizes-control/input-controls/single.js +5 -1
- package/build/components/spacing-sizes-control/input-controls/single.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/url-input/index.js +4 -2
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/use-block-display-information/index.js +7 -3
- package/build/components/use-block-display-information/index.js.map +1 -1
- package/build/components/use-block-drop-zone/index.native.js +49 -8
- package/build/components/use-block-drop-zone/index.native.js.map +1 -1
- package/build/components/use-setting/index.js +5 -9
- package/build/components/use-setting/index.js.map +1 -1
- package/build/components/writing-flow/use-tab-nav.js +10 -27
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build/components/writing-mode-control/index.js +70 -0
- package/build/components/writing-mode-control/index.js.map +1 -0
- package/build/hooks/behaviors.js +25 -20
- package/build/hooks/behaviors.js.map +1 -1
- package/build/hooks/margin.js +1 -1
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +1 -1
- 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 +2 -1
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/utils.js +5 -9
- package/build/hooks/utils.js.map +1 -1
- package/build/private-apis.js +16 -3
- package/build/private-apis.js.map +1 -1
- package/build/private-apis.native.js +3 -0
- package/build/private-apis.native.js.map +1 -1
- package/build/store/actions.js +196 -2
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +1 -0
- package/build/store/defaults.js.map +1 -1
- package/build/store/index.js +10 -1
- package/build/store/index.js.map +1 -1
- package/build/store/private-actions.js +46 -40
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +8 -9
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +22 -9
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +52 -23
- package/build/store/selectors.js.map +1 -1
- package/build/utils/object.js +38 -2
- package/build/utils/object.js.map +1 -1
- package/build-module/components/block-draggable/index.js +6 -3
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-draggable/index.native.js +2 -2
- package/build-module/components/block-draggable/index.native.js.map +1 -1
- package/build-module/components/block-edit/edit.js +27 -10
- package/build-module/components/block-edit/edit.js.map +1 -1
- package/build-module/components/block-heading-level-dropdown/heading-level-icon.js +9 -2
- package/build-module/components/block-heading-level-dropdown/heading-level-icon.js.map +1 -1
- package/build-module/components/block-heading-level-dropdown/index.native.js +4 -3
- package/build-module/components/block-heading-level-dropdown/index.native.js.map +1 -1
- package/build-module/components/block-list/block-outline.native.js +14 -18
- package/build-module/components/block-list/block-outline.native.js.map +1 -1
- package/build-module/components/block-list/block.native.js +24 -43
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +25 -7
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-mover/index.native.js +3 -3
- package/build-module/components/block-mover/index.native.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +7 -5
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-removal-warning-modal/index.js +17 -24
- package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
- package/build-module/components/block-settings/button.native.js +3 -3
- package/build-module/components/block-settings/button.native.js.map +1 -1
- package/build-module/components/{block-mobile-toolbar/block-actions-menu.native.js → block-toolbar/block-toolbar-menu.native.js} +13 -13
- package/build-module/components/block-toolbar/block-toolbar-menu.native.js.map +1 -0
- package/build-module/components/block-toolbar/index.js +12 -8
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-toolbar/index.native.js +60 -4
- package/build-module/components/block-toolbar/index.native.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +8 -11
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +3 -2
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js +87 -0
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js.map +1 -0
- package/build-module/components/dimensions-tool/index.js +195 -0
- package/build-module/components/dimensions-tool/index.js.map +1 -0
- package/build-module/components/dimensions-tool/scale-tool.js +103 -0
- package/build-module/components/dimensions-tool/scale-tool.js.map +1 -0
- package/build-module/components/dimensions-tool/width-height-tool.js +122 -0
- package/build-module/components/dimensions-tool/width-height-tool.js.map +1 -0
- package/build-module/components/global-styles/color-panel.js +22 -16
- package/build-module/components/global-styles/color-panel.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +13 -2
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/filters-panel.js +2 -2
- package/build-module/components/global-styles/filters-panel.js.map +1 -1
- package/build-module/components/global-styles/get-block-css-selector.js +4 -8
- package/build-module/components/global-styles/get-block-css-selector.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +14 -24
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +51 -5
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +13 -18
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +5 -5
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/iframe/index.js +37 -49
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/iframe/use-compatibility-styles.js +5 -0
- package/build-module/components/iframe/use-compatibility-styles.js.map +1 -1
- package/build-module/components/image-editor/aspect-ratio-dropdown.js +1 -1
- package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build-module/components/image-editor/use-save-image.js +1 -2
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/image-size-control/index.js +5 -0
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/index.js +1 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +3 -1
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.native.js +3 -1
- package/build-module/components/inner-blocks/index.native.js.map +1 -1
- package/build-module/components/inner-blocks/use-nested-settings-update.js +30 -7
- package/build-module/components/inner-blocks/use-nested-settings-update.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js +2 -2
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +7 -33
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/hooks/use-block-types-state.js +3 -4
- package/build-module/components/inserter/hooks/use-block-types-state.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js +9 -3
- package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build-module/components/inserter/index.js +2 -4
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/index.native.js +22 -33
- package/build-module/components/inserter/index.native.js.map +1 -1
- package/build-module/components/inserter/media-tab/hooks.js +2 -21
- package/build-module/components/inserter/media-tab/hooks.js.map +1 -1
- package/build-module/components/inserter/reusable-block-rename-hint.js +67 -0
- package/build-module/components/inserter/reusable-block-rename-hint.js.map +1 -0
- package/build-module/components/inserter/reusable-blocks-tab.js +5 -2
- package/build-module/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build-module/components/inserter/reusable-blocks-tab.native.js +2 -2
- package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build-module/components/inserter/tabs.native.js +1 -1
- package/build-module/components/inserter/tabs.native.js.map +1 -1
- package/build-module/components/inserter-draggable-blocks/index.js +9 -2
- package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build-module/components/link-control/constants.js +1 -1
- package/build-module/components/link-control/constants.js.map +1 -1
- package/build-module/components/link-control/index.js +21 -16
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/search-create-button.js +7 -20
- package/build-module/components/link-control/search-create-button.js.map +1 -1
- package/build-module/components/link-control/search-input.js +4 -4
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/link-control/search-item.js +14 -28
- package/build-module/components/link-control/search-item.js.map +1 -1
- package/build-module/components/link-control/search-results.js +3 -3
- package/build-module/components/link-control/search-results.js.map +1 -1
- package/build-module/components/link-control/settings-drawer.js +4 -5
- package/build-module/components/link-control/settings-drawer.js.map +1 -1
- package/build-module/components/list-view/appender.js +2 -6
- package/build-module/components/list-view/appender.js.map +1 -1
- package/build-module/components/list-view/use-list-view-client-ids.js +2 -2
- package/build-module/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build-module/components/media-placeholder/index.native.js +66 -33
- package/build-module/components/media-placeholder/index.native.js.map +1 -1
- package/build-module/components/preview-options/index.js +2 -2
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/provider/index.js +5 -2
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/use-block-sync.js +21 -0
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/components/resolution-tool/index.js +45 -0
- package/build-module/components/resolution-tool/index.js.map +1 -0
- package/build-module/components/rich-text/content.js +1 -36
- package/build-module/components/rich-text/content.js.map +1 -1
- package/build-module/components/rich-text/get-rich-text-values.js +105 -0
- package/build-module/components/rich-text/get-rich-text-values.js.map +1 -0
- package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js +1 -1
- package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/axial.js +7 -3
- package/build-module/components/spacing-sizes-control/input-controls/axial.js.map +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/separated.js +6 -2
- package/build-module/components/spacing-sizes-control/input-controls/separated.js.map +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/single.js +6 -2
- package/build-module/components/spacing-sizes-control/input-controls/single.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/url-input/index.js +4 -2
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/use-block-display-information/index.js +7 -3
- package/build-module/components/use-block-display-information/index.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.native.js +50 -8
- package/build-module/components/use-block-drop-zone/index.native.js.map +1 -1
- package/build-module/components/use-setting/index.js +5 -9
- package/build-module/components/use-setting/index.js.map +1 -1
- package/build-module/components/writing-flow/use-tab-nav.js +8 -26
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/components/writing-mode-control/index.js +57 -0
- package/build-module/components/writing-mode-control/index.js.map +1 -0
- package/build-module/hooks/behaviors.js +26 -20
- package/build-module/hooks/behaviors.js.map +1 -1
- package/build-module/hooks/margin.js +1 -1
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +1 -1
- 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 +2 -1
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/utils.js +6 -9
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/private-apis.js +11 -2
- package/build-module/private-apis.js.map +1 -1
- package/build-module/private-apis.native.js +2 -0
- package/build-module/private-apis.native.js.map +1 -1
- package/build-module/store/actions.js +193 -3
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +1 -0
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/index.js +10 -1
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-actions.js +45 -36
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +5 -5
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +22 -9
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +49 -21
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/object.js +34 -2
- package/build-module/utils/object.js.map +1 -1
- package/build-style/content-rtl.css +4 -0
- package/build-style/content.css +4 -0
- package/build-style/style-rtl.css +137 -129
- package/build-style/style.css +137 -129
- package/package.json +33 -32
- package/src/components/alignment-control/test/__snapshots__/index.js.snap +6 -6
- package/src/components/block-alignment-control/test/__snapshots__/index.js.snap +5 -5
- package/src/components/block-controls/README.md +89 -0
- package/src/components/block-draggable/index.js +13 -4
- package/src/components/block-draggable/index.native.js +7 -3
- package/src/components/block-draggable/style.scss +1 -0
- package/src/components/block-draggable/test/index.native.js +0 -54
- package/src/components/block-edit/edit.js +26 -9
- package/src/components/block-edit/test/edit.js +1 -1
- package/src/components/block-heading-level-dropdown/heading-level-icon.js +6 -1
- package/src/components/block-heading-level-dropdown/index.native.js +8 -4
- package/src/components/block-inspector/style.scss +2 -1
- package/src/components/block-list/block-outline.native.js +26 -25
- package/src/components/block-list/block.native.js +24 -38
- package/src/components/block-list/block.native.scss +18 -40
- package/src/components/block-list/style.native.scss +3 -3
- package/src/components/block-lock/toolbar.js +34 -6
- package/src/components/block-mover/index.native.js +3 -3
- package/src/components/block-mover/test/__snapshots__/index.native.js.snap +16 -6
- package/src/components/block-parent-selector/index.js +13 -8
- package/src/components/block-removal-warning-modal/index.js +17 -33
- package/src/components/block-settings/button.native.js +12 -6
- package/src/components/{block-mobile-toolbar/block-actions-menu.native.js → block-toolbar/block-toolbar-menu.native.js} +19 -18
- package/src/components/block-toolbar/index.js +11 -9
- package/src/components/block-toolbar/index.native.js +86 -6
- package/src/components/{block-mobile-toolbar/test/block-actions-menu.native.js → block-toolbar/test/block-toolbar-menu.native.js} +20 -54
- package/src/components/block-toolbar/test/index.native.js +42 -0
- package/src/components/block-tools/block-contextual-toolbar.js +5 -11
- package/src/components/block-tools/style.scss +73 -26
- package/src/components/button-block-appender/styles.native.scss +2 -2
- package/src/components/caption/README.md +49 -0
- package/src/components/colors-gradients/control.js +3 -2
- package/src/components/default-block-appender/content.scss +11 -0
- package/src/components/dimensions-tool/aspect-ratio-tool.js +124 -0
- package/src/components/dimensions-tool/index.js +212 -0
- package/src/components/dimensions-tool/scale-tool.js +124 -0
- package/src/components/dimensions-tool/stories/aspect-ratio-tool.js +52 -0
- package/src/components/dimensions-tool/stories/index.js +54 -0
- package/src/components/dimensions-tool/stories/scale-tool.js +48 -0
- package/src/components/dimensions-tool/stories/width-height-tool.js +54 -0
- package/src/components/dimensions-tool/test/index.js +641 -0
- package/src/components/dimensions-tool/width-height-tool.js +113 -0
- package/src/components/font-family/README.md +71 -0
- package/src/components/global-styles/color-panel.js +24 -17
- package/src/components/global-styles/dimensions-panel.js +8 -2
- package/src/components/global-styles/filters-panel.js +2 -2
- package/src/components/global-styles/get-block-css-selector.js +5 -9
- package/src/components/global-styles/hooks.js +22 -26
- package/src/components/global-styles/typography-panel.js +57 -5
- package/src/components/global-styles/use-global-styles-output.js +36 -18
- package/src/components/global-styles/utils.js +15 -6
- package/src/components/iframe/index.js +30 -56
- package/src/components/iframe/use-compatibility-styles.js +5 -0
- package/src/components/image-editor/aspect-ratio-dropdown.js +1 -1
- package/src/components/image-editor/use-save-image.js +0 -1
- package/src/components/image-size-control/index.js +6 -0
- package/src/components/index.js +1 -0
- package/src/components/inner-blocks/README.md +10 -0
- package/src/components/inner-blocks/index.js +4 -0
- package/src/components/inner-blocks/index.native.js +4 -0
- package/src/components/inner-blocks/use-nested-settings-update.js +32 -5
- package/src/components/inserter/block-patterns-explorer/patterns-list.js +8 -2
- package/src/components/inserter/block-patterns-tab.js +8 -56
- package/src/components/inserter/hooks/use-block-types-state.js +3 -4
- package/src/components/inserter/hooks/use-patterns-state.js +35 -19
- package/src/components/inserter/index.js +2 -3
- package/src/components/inserter/index.native.js +17 -36
- package/src/components/inserter/media-tab/hooks.js +2 -22
- package/src/components/inserter/reusable-block-rename-hint.js +69 -0
- package/src/components/inserter/reusable-blocks-tab.js +5 -1
- package/src/components/inserter/reusable-blocks-tab.native.js +2 -2
- package/src/components/inserter/style.native.scss +10 -15
- package/src/components/inserter/style.scss +28 -0
- package/src/components/inserter/tabs.native.js +5 -1
- package/src/components/inserter-draggable-blocks/index.js +13 -2
- package/src/components/link-control/constants.js +1 -1
- package/src/components/link-control/index.js +36 -29
- package/src/components/link-control/search-create-button.js +8 -26
- package/src/components/link-control/search-input.js +4 -3
- package/src/components/link-control/search-item.js +21 -43
- package/src/components/link-control/search-results.js +48 -46
- package/src/components/link-control/settings-drawer.js +6 -5
- package/src/components/link-control/style.scss +58 -123
- package/src/components/link-control/test/index.js +161 -123
- package/src/components/list-view/appender.js +5 -6
- package/src/components/list-view/style.scss +1 -2
- package/src/components/list-view/use-list-view-client-ids.js +2 -2
- package/src/components/media-placeholder/index.native.js +108 -59
- package/src/components/media-placeholder/styles.native.scss +59 -24
- package/src/components/media-replace-flow/test/index.js +1 -1
- package/src/components/panel-color-settings/README.md +98 -0
- package/src/components/preview-options/README.md +18 -17
- package/src/components/preview-options/index.js +2 -2
- package/src/components/provider/index.js +9 -2
- package/src/components/provider/test/use-block-sync.js +21 -6
- package/src/components/provider/use-block-sync.js +19 -0
- package/src/components/recursion-provider/README.md +101 -0
- package/src/components/resolution-tool/index.js +56 -0
- package/src/components/resolution-tool/stories/index.js +48 -0
- package/src/components/rich-text/content.js +1 -46
- package/src/components/rich-text/get-rich-text-values.js +105 -0
- package/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js +1 -1
- package/src/components/spacing-sizes-control/input-controls/axial.js +17 -2
- package/src/components/spacing-sizes-control/input-controls/separated.js +17 -2
- package/src/components/spacing-sizes-control/input-controls/single.js +12 -2
- package/src/components/spacing-sizes-control/utils.js +1 -1
- package/src/components/text-transform-control/README.md +44 -0
- package/src/components/url-input/index.js +2 -0
- package/src/components/use-block-display-information/index.js +12 -5
- package/src/components/use-block-drop-zone/index.native.js +65 -28
- package/src/components/use-setting/index.js +8 -8
- package/src/components/writing-flow/use-tab-nav.js +10 -33
- package/src/components/writing-mode-control/index.js +68 -0
- package/src/components/writing-mode-control/style.scss +18 -0
- package/src/hooks/behaviors.js +25 -16
- package/src/hooks/margin.js +4 -1
- package/src/hooks/padding.js +4 -1
- package/src/hooks/supports.js +7 -0
- package/src/hooks/typography.js +2 -0
- package/src/hooks/utils.js +8 -7
- package/src/private-apis.js +13 -1
- package/src/private-apis.native.js +2 -0
- package/src/store/actions.js +195 -3
- package/src/store/defaults.js +1 -0
- package/src/store/index.js +10 -0
- package/src/store/private-actions.js +39 -39
- package/src/store/private-selectors.js +5 -8
- package/src/store/reducer.js +22 -9
- package/src/store/selectors.js +87 -25
- package/src/store/test/actions.js +114 -0
- package/src/store/test/private-actions.js +56 -0
- package/src/store/test/private-selectors.js +5 -5
- package/src/store/test/reducer.js +14 -7
- package/src/store/test/selectors.js +1 -1
- package/src/utils/object.js +32 -2
- package/src/utils/test/object.js +36 -0
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +0 -1
- package/build/components/block-mobile-toolbar/index.native.js +0 -135
- package/build/components/block-mobile-toolbar/index.native.js.map +0 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +0 -1
- package/build-module/components/block-mobile-toolbar/index.native.js +0 -116
- package/build-module/components/block-mobile-toolbar/index.native.js.map +0 -1
- package/src/components/block-mobile-toolbar/index.native.js +0 -127
- package/src/components/block-mobile-toolbar/style.native.scss +0 -16
- /package/src/components/{block-mobile-toolbar/test/__snapshots__/block-actions-menu.native.js.snap → block-toolbar/test/__snapshots__/block-toolbar-menu.native.js.snap} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/provider/use-block-sync.js"],"names":["useEffect","useRef","useRegistry","useSelect","cloneBlock","store","blockEditorStore","noop","useBlockSync","clientId","value","controlledBlocks","selection","controlledSelection","onChange","onInput","registry","resetBlocks","resetSelection","replaceInnerBlocks","selectBlock","setHasControlledInnerBlocks","__unstableMarkNextChangeAsNotPersistent","dispatch","hasSelectedBlock","getBlockName","getBlocks","getSelectionStart","getSelectionEnd","getBlock","select","isControlled","areInnerBlocksControlled","pendingChanges","incoming","outgoing","subscribed","setControlledBlocks","batch","storeBlocks","map","block","current","onInputRef","onChangeRef","includes","length","hadSelecton","selectionAnchor","selectionFocus","selectionStart","selectionEnd","initialPosition","selectionStillExists","getSelectedBlocksInitialCaretPosition","isLastBlockChangePersistent","__unstableIsLastBlockChangeIgnored","blocks","isPersistent","previousAreBlocksDifferent","unsubscribe","subscribe","isStillControlled","newIsPersistent","newBlocks","areBlocksDifferent","didPersistenceChange","push","updateParent"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,oBAAlC;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,UAAT,QAA2B,mBAA3B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;;AAEA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,SAASC,YAAT,CAAuB;AACrCC,EAAAA,QAAQ,GAAG,IAD0B;AAErCC,EAAAA,KAAK,EAAEC,gBAF8B;AAGrCC,EAAAA,SAAS,EAAEC,mBAH0B;AAIrCC,EAAAA,QAAQ,GAAGP,IAJ0B;AAKrCQ,EAAAA,OAAO,GAAGR;AAL2B,CAAvB,EAMX;AACH,QAAMS,QAAQ,GAAGd,WAAW,EAA5B;AAEA,QAAM;AACLe,IAAAA,WADK;AAELC,IAAAA,cAFK;AAGLC,IAAAA,kBAHK;AAILC,IAAAA,WAJK;AAKLC,IAAAA,2BALK;AAMLC,IAAAA;AANK,MAOFN,QAAQ,CAACO,QAAT,CAAmBjB,gBAAnB,CAPJ;AAQA,QAAM;AACLkB,IAAAA,gBADK;AAELC,IAAAA,YAFK;AAGLC,IAAAA,SAHK;AAILC,IAAAA,iBAJK;AAKLC,IAAAA,eALK;AAMLC,IAAAA;AANK,MAOFb,QAAQ,CAACc,MAAT,CAAiBxB,gBAAjB,CAPJ;AAQA,QAAMyB,YAAY,GAAG5B,SAAS,CAC3B2B,MAAF,IAAc;AACb,WACC,CAAErB,QAAF,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f,CAAuBR,QAAvB,IACDsB,kCAAkC,EAFjB,CADnB,EAIE;AACDvB,QAAAA,cAAc,CAACS,OAAf,CAAuBR,QAAvB,GAAkC,IAAlC;AACAwB,QAAAA,YAAY,GAAGK,eAAf;AACA;AACA,OAjC4C,CAmC7C;AACA;AACA;;;AACA,YAAMG,oBAAoB,GACzBP,0BAA0B,IAC1B,CAAEM,kBADF,IAEAF,eAFA,IAGA,CAAEL,YAJH;;AAMA,UAAKO,kBAAkB,IAAIC,oBAA3B,EAAkD;AACjDR,QAAAA,YAAY,GAAGK,eAAf,CADiD,CAEjD;AACA;AACA;AACA;;AACA9B,QAAAA,cAAc,CAACS,OAAf,CAAuBP,QAAvB,CAAgCgC,IAAhC,CAAsCV,MAAtC,EANiD,CAQjD;AACA;;AACA,cAAMW,YAAY,GAAGV,YAAY,GAC9Bd,WAAW,CAACF,OADkB,GAE9BC,UAAU,CAACD,OAFd;AAGA0B,QAAAA,YAAY,CAAEX,MAAF,EAAU;AACrB7C,UAAAA,SAAS,EAAE;AACVsC,YAAAA,cAAc,EAAEvB,iBAAiB,EADvB;AAEVwB,YAAAA,YAAY,EAAEvB,eAAe,EAFnB;AAGVwB,YAAAA,eAAe,EACdE,qCAAqC;AAJ5B;AADU,SAAV,CAAZ;AAQA;;AACDK,MAAAA,0BAA0B,GAAGM,kBAA7B;AACA,KAnEmB,CAApB;AAqEA,WAAO,MAAM;AACZ7B,MAAAA,UAAU,CAACM,OAAX,GAAqB,KAArB;AACAkB,MAAAA,WAAW;AACX,KAHD;AAIA,GAtFQ,EAsFN,CAAE5C,QAAF,EAAYP,QAAZ,CAtFM,CAAT;AAuFA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { cloneBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nconst noop = () => {};\n\n/**\n * A function to call when the block value has been updated in the block-editor\n * store.\n *\n * @callback onBlockUpdate\n * @param {Object[]} blocks The updated blocks.\n * @param {Object} options The updated block options, such as selectionStart\n * and selectionEnd.\n */\n\n/**\n * useBlockSync is a side effect which handles bidirectional sync between the\n * block-editor store and a controlling data source which provides blocks. This\n * is most commonly used by the BlockEditorProvider to synchronize the contents\n * of the block-editor store with the root entity, like a post.\n *\n * Another example would be the template part block, which provides blocks from\n * a separate entity data source than a root entity. This hook syncs edits to\n * the template part in the block editor back to the entity and vice-versa.\n *\n * Here are some of its basic functions:\n * - Initalizes the block-editor store for the given clientID to the blocks\n * given via props.\n * - Adds incoming changes (like undo) to the block-editor store.\n * - Adds outgoing changes (like editing content) to the controlling entity,\n * determining if a change should be considered persistent or not.\n * - Handles edge cases and race conditions which occur in those operations.\n * - Ignores changes which happen to other entities (like nested inner block\n * controllers.\n * - Passes selection state from the block-editor store to the controlling entity.\n *\n * @param {Object} props Props for the block sync hook\n * @param {string} props.clientId The client ID of the inner block controller.\n * If none is passed, then it is assumed to be a\n * root controller rather than an inner block\n * controller.\n * @param {Object[]} props.value The control value for the blocks. This value\n * is used to initalize the block-editor store\n * and for resetting the blocks to incoming\n * changes like undo.\n * @param {Object} props.selection The selection state responsible to restore the selection on undo/redo.\n * @param {onBlockUpdate} props.onChange Function to call when a persistent\n * change has been made in the block-editor blocks\n * for the given clientId. For example, after\n * this function is called, an entity is marked\n * dirty because it has changes to save.\n * @param {onBlockUpdate} props.onInput Function to call when a non-persistent\n * change has been made in the block-editor blocks\n * for the given clientId. When this is called,\n * controlling sources do not become dirty.\n */\nexport default function useBlockSync( {\n\tclientId = null,\n\tvalue: controlledBlocks,\n\tselection: controlledSelection,\n\tonChange = noop,\n\tonInput = noop,\n} ) {\n\tconst registry = useRegistry();\n\n\tconst {\n\t\tresetBlocks,\n\t\tresetSelection,\n\t\treplaceInnerBlocks,\n\t\tselectBlock,\n\t\tsetHasControlledInnerBlocks,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t} = registry.dispatch( blockEditorStore );\n\tconst {\n\t\thasSelectedBlock,\n\t\tgetBlockName,\n\t\tgetBlocks,\n\t\tgetSelectionStart,\n\t\tgetSelectionEnd,\n\t\tgetBlock,\n\t} = registry.select( blockEditorStore );\n\tconst isControlled = useSelect(\n\t\t( select ) => {\n\t\t\treturn (\n\t\t\t\t! clientId ||\n\t\t\t\tselect( blockEditorStore ).areInnerBlocksControlled( clientId )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst pendingChanges = useRef( { incoming: null, outgoing: [] } );\n\tconst subscribed = useRef( false );\n\n\tconst setControlledBlocks = () => {\n\t\tif ( ! controlledBlocks ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We don't need to persist this change because we only replace\n\t\t// controlled inner blocks when the change was caused by an entity,\n\t\t// and so it would already be persisted.\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tif ( clientId ) {\n\t\t\t// It is important to batch here because otherwise,\n\t\t\t// as soon as `setHasControlledInnerBlocks` is called\n\t\t\t// the effect to restore might be triggered\n\t\t\t// before the actual blocks get set properly in state.\n\t\t\tregistry.batch( () => {\n\t\t\t\tsetHasControlledInnerBlocks( clientId, true );\n\t\t\t\tconst storeBlocks = controlledBlocks.map( ( block ) =>\n\t\t\t\t\tcloneBlock( block )\n\t\t\t\t);\n\t\t\t\tif ( subscribed.current ) {\n\t\t\t\t\tpendingChanges.current.incoming = storeBlocks;\n\t\t\t\t}\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\treplaceInnerBlocks( clientId, storeBlocks );\n\t\t\t} );\n\t\t} else {\n\t\t\tif ( subscribed.current ) {\n\t\t\t\tpendingChanges.current.incoming = controlledBlocks;\n\t\t\t}\n\t\t\tresetBlocks( controlledBlocks );\n\t\t}\n\t};\n\n\t// Add a subscription to the block-editor registry to detect when changes\n\t// have been made. This lets us inform the data source of changes. This\n\t// is an effect so that the subscriber can run synchronously without\n\t// waiting for React renders for changes.\n\tconst onInputRef = useRef( onInput );\n\tconst onChangeRef = useRef( onChange );\n\tuseEffect( () => {\n\t\tonInputRef.current = onInput;\n\t\tonChangeRef.current = onChange;\n\t}, [ onInput, onChange ] );\n\n\t// Determine if blocks need to be reset when they change.\n\tuseEffect( () => {\n\t\tif ( pendingChanges.current.outgoing.includes( controlledBlocks ) ) {\n\t\t\t// Skip block reset if the value matches expected outbound sync\n\t\t\t// triggered by this component by a preceding change detection.\n\t\t\t// Only skip if the value matches expectation, since a reset should\n\t\t\t// still occur if the value is modified (not equal by reference),\n\t\t\t// to allow that the consumer may apply modifications to reflect\n\t\t\t// back on the editor.\n\t\t\tif (\n\t\t\t\tpendingChanges.current.outgoing[\n\t\t\t\t\tpendingChanges.current.outgoing.length - 1\n\t\t\t\t] === controlledBlocks\n\t\t\t) {\n\t\t\t\tpendingChanges.current.outgoing = [];\n\t\t\t}\n\t\t} else if ( getBlocks( clientId ) !== controlledBlocks ) {\n\t\t\t// Reset changing value in all other cases than the sync described\n\t\t\t// above. Since this can be reached in an update following an out-\n\t\t\t// bound sync, unset the outbound value to avoid considering it in\n\t\t\t// subsequent renders.\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tconst hadSelecton = hasSelectedBlock();\n\t\t\tconst selectionAnchor = getSelectionStart();\n\t\t\tconst selectionFocus = getSelectionEnd();\n\t\t\tsetControlledBlocks();\n\n\t\t\tif ( controlledSelection ) {\n\t\t\t\tresetSelection(\n\t\t\t\t\tcontrolledSelection.selectionStart,\n\t\t\t\t\tcontrolledSelection.selectionEnd,\n\t\t\t\t\tcontrolledSelection.initialPosition\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst selectionStillExists = getBlock(\n\t\t\t\t\tselectionAnchor.clientId\n\t\t\t\t);\n\t\t\t\tif ( hadSelecton && ! selectionStillExists ) {\n\t\t\t\t\tselectBlock( clientId );\n\t\t\t\t} else {\n\t\t\t\t\tresetSelection( selectionAnchor, selectionFocus );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [ controlledBlocks, clientId ] );\n\n\tuseEffect( () => {\n\t\t// When the block becomes uncontrolled, it means its inner state has been reset\n\t\t// we need to take the blocks again from the external value property.\n\t\tif ( ! isControlled ) {\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tsetControlledBlocks();\n\t\t}\n\t}, [ isControlled ] );\n\n\tuseEffect( () => {\n\t\tconst {\n\t\t\tgetSelectedBlocksInitialCaretPosition,\n\t\t\tisLastBlockChangePersistent,\n\t\t\t__unstableIsLastBlockChangeIgnored,\n\t\t\tareInnerBlocksControlled,\n\t\t} = registry.select( blockEditorStore );\n\n\t\tlet blocks = getBlocks( clientId );\n\t\tlet isPersistent = isLastBlockChangePersistent();\n\t\tlet previousAreBlocksDifferent = false;\n\n\t\tsubscribed.current = true;\n\t\tconst unsubscribe = registry.subscribe( () => {\n\t\t\t// Sometimes, when changing block lists, lingering subscriptions\n\t\t\t// might trigger before they are cleaned up. If the block for which\n\t\t\t// the subscription runs is no longer in the store, this would clear\n\t\t\t// its parent entity's block list. To avoid this, we bail out if\n\t\t\t// the subscription is triggering for a block (`clientId !== null`)\n\t\t\t// and its block name can't be found because it's not on the list.\n\t\t\t// (`getBlockName( clientId ) === null`).\n\t\t\tif ( clientId !== null && getBlockName( clientId ) === null )\n\t\t\t\treturn;\n\n\t\t\t// When RESET_BLOCKS on parent blocks get called, the controlled blocks\n\t\t\t// can reset to uncontrolled, in these situations, it means we need to populate\n\t\t\t// the blocks again from the external blocks (the value property here)\n\t\t\t// and we should stop triggering onChange\n\t\t\tconst isStillControlled =\n\t\t\t\t! clientId || areInnerBlocksControlled( clientId );\n\t\t\tif ( ! isStillControlled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst newIsPersistent = isLastBlockChangePersistent();\n\t\t\tconst newBlocks = getBlocks( clientId );\n\t\t\tconst areBlocksDifferent = newBlocks !== blocks;\n\t\t\tblocks = newBlocks;\n\t\t\tif (\n\t\t\t\tareBlocksDifferent &&\n\t\t\t\t( pendingChanges.current.incoming ||\n\t\t\t\t\t__unstableIsLastBlockChangeIgnored() )\n\t\t\t) {\n\t\t\t\tpendingChanges.current.incoming = null;\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Since we often dispatch an action to mark the previous action as\n\t\t\t// persistent, we need to make sure that the blocks changed on the\n\t\t\t// previous action before committing the change.\n\t\t\tconst didPersistenceChange =\n\t\t\t\tpreviousAreBlocksDifferent &&\n\t\t\t\t! areBlocksDifferent &&\n\t\t\t\tnewIsPersistent &&\n\t\t\t\t! isPersistent;\n\n\t\t\tif ( areBlocksDifferent || didPersistenceChange ) {\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\t// We know that onChange/onInput will update controlledBlocks.\n\t\t\t\t// We need to be aware that it was caused by an outgoing change\n\t\t\t\t// so that we do not treat it as an incoming change later on,\n\t\t\t\t// which would cause a block reset.\n\t\t\t\tpendingChanges.current.outgoing.push( blocks );\n\n\t\t\t\t// Inform the controlling entity that changes have been made to\n\t\t\t\t// the block-editor store they should be aware about.\n\t\t\t\tconst updateParent = isPersistent\n\t\t\t\t\t? onChangeRef.current\n\t\t\t\t\t: onInputRef.current;\n\t\t\t\tupdateParent( blocks, {\n\t\t\t\t\tselection: {\n\t\t\t\t\t\tselectionStart: getSelectionStart(),\n\t\t\t\t\t\tselectionEnd: getSelectionEnd(),\n\t\t\t\t\t\tinitialPosition:\n\t\t\t\t\t\t\tgetSelectedBlocksInitialCaretPosition(),\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t\tpreviousAreBlocksDifferent = areBlocksDifferent;\n\t\t} );\n\n\t\treturn () => {\n\t\t\tsubscribed.current = false;\n\t\t\tunsubscribe();\n\t\t};\n\t}, [ registry, clientId ] );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/provider/use-block-sync.js"],"names":["useEffect","useRef","useRegistry","useSelect","cloneBlock","store","blockEditorStore","noop","useBlockSync","clientId","value","controlledBlocks","selection","controlledSelection","onChange","onInput","registry","resetBlocks","resetSelection","replaceInnerBlocks","selectBlock","setHasControlledInnerBlocks","__unstableMarkNextChangeAsNotPersistent","dispatch","hasSelectedBlock","getBlockName","getBlocks","getSelectionStart","getSelectionEnd","getBlock","select","isControlled","areInnerBlocksControlled","pendingChanges","incoming","outgoing","subscribed","setControlledBlocks","batch","storeBlocks","map","block","current","unsetControlledBlocks","onInputRef","onChangeRef","includes","length","hadSelecton","selectionAnchor","selectionFocus","selectionStart","selectionEnd","initialPosition","selectionStillExists","getSelectedBlocksInitialCaretPosition","isLastBlockChangePersistent","__unstableIsLastBlockChangeIgnored","blocks","isPersistent","previousAreBlocksDifferent","unsubscribe","subscribe","isStillControlled","newIsPersistent","newBlocks","areBlocksDifferent","didPersistenceChange","push","updateParent"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,oBAAlC;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,UAAT,QAA2B,mBAA3B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;;AAEA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,SAASC,YAAT,CAAuB;AACrCC,EAAAA,QAAQ,GAAG,IAD0B;AAErCC,EAAAA,KAAK,EAAEC,gBAF8B;AAGrCC,EAAAA,SAAS,EAAEC,mBAH0B;AAIrCC,EAAAA,QAAQ,GAAGP,IAJ0B;AAKrCQ,EAAAA,OAAO,GAAGR;AAL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,CAAuBP,QAAvB,CAAgCiC,IAAhC,CAAsCV,MAAtC,EANiD,CAQjD;AACA;;AACA,cAAMW,YAAY,GAAGV,YAAY,GAC9Bd,WAAW,CAACH,OADkB,GAE9BE,UAAU,CAACF,OAFd;AAGA2B,QAAAA,YAAY,CAAEX,MAAF,EAAU;AACrB9C,UAAAA,SAAS,EAAE;AACVuC,YAAAA,cAAc,EAAExB,iBAAiB,EADvB;AAEVyB,YAAAA,YAAY,EAAExB,eAAe,EAFnB;AAGVyB,YAAAA,eAAe,EACdE,qCAAqC;AAJ5B;AADU,SAAV,CAAZ;AAQA;;AACDK,MAAAA,0BAA0B,GAAGM,kBAA7B;AACA,KAnEmB,CAApB;AAqEA,WAAO,MAAM;AACZ9B,MAAAA,UAAU,CAACM,OAAX,GAAqB,KAArB;AACAmB,MAAAA,WAAW;AACX,KAHD;AAIA,GAtFQ,EAsFN,CAAE7C,QAAF,EAAYP,QAAZ,CAtFM,CAAT;AAwFAT,EAAAA,SAAS,CAAE,MAAM;AAChB,WAAO,MAAM;AACZ2C,MAAAA,qBAAqB;AACrB,KAFD;AAGA,GAJQ,EAIN,EAJM,CAAT;AAKA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { cloneBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nconst noop = () => {};\n\n/**\n * A function to call when the block value has been updated in the block-editor\n * store.\n *\n * @callback onBlockUpdate\n * @param {Object[]} blocks The updated blocks.\n * @param {Object} options The updated block options, such as selectionStart\n * and selectionEnd.\n */\n\n/**\n * useBlockSync is a side effect which handles bidirectional sync between the\n * block-editor store and a controlling data source which provides blocks. This\n * is most commonly used by the BlockEditorProvider to synchronize the contents\n * of the block-editor store with the root entity, like a post.\n *\n * Another example would be the template part block, which provides blocks from\n * a separate entity data source than a root entity. This hook syncs edits to\n * the template part in the block editor back to the entity and vice-versa.\n *\n * Here are some of its basic functions:\n * - Initalizes the block-editor store for the given clientID to the blocks\n * given via props.\n * - Adds incoming changes (like undo) to the block-editor store.\n * - Adds outgoing changes (like editing content) to the controlling entity,\n * determining if a change should be considered persistent or not.\n * - Handles edge cases and race conditions which occur in those operations.\n * - Ignores changes which happen to other entities (like nested inner block\n * controllers.\n * - Passes selection state from the block-editor store to the controlling entity.\n *\n * @param {Object} props Props for the block sync hook\n * @param {string} props.clientId The client ID of the inner block controller.\n * If none is passed, then it is assumed to be a\n * root controller rather than an inner block\n * controller.\n * @param {Object[]} props.value The control value for the blocks. This value\n * is used to initalize the block-editor store\n * and for resetting the blocks to incoming\n * changes like undo.\n * @param {Object} props.selection The selection state responsible to restore the selection on undo/redo.\n * @param {onBlockUpdate} props.onChange Function to call when a persistent\n * change has been made in the block-editor blocks\n * for the given clientId. For example, after\n * this function is called, an entity is marked\n * dirty because it has changes to save.\n * @param {onBlockUpdate} props.onInput Function to call when a non-persistent\n * change has been made in the block-editor blocks\n * for the given clientId. When this is called,\n * controlling sources do not become dirty.\n */\nexport default function useBlockSync( {\n\tclientId = null,\n\tvalue: controlledBlocks,\n\tselection: controlledSelection,\n\tonChange = noop,\n\tonInput = noop,\n} ) {\n\tconst registry = useRegistry();\n\n\tconst {\n\t\tresetBlocks,\n\t\tresetSelection,\n\t\treplaceInnerBlocks,\n\t\tselectBlock,\n\t\tsetHasControlledInnerBlocks,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t} = registry.dispatch( blockEditorStore );\n\tconst {\n\t\thasSelectedBlock,\n\t\tgetBlockName,\n\t\tgetBlocks,\n\t\tgetSelectionStart,\n\t\tgetSelectionEnd,\n\t\tgetBlock,\n\t} = registry.select( blockEditorStore );\n\tconst isControlled = useSelect(\n\t\t( select ) => {\n\t\t\treturn (\n\t\t\t\t! clientId ||\n\t\t\t\tselect( blockEditorStore ).areInnerBlocksControlled( clientId )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst pendingChanges = useRef( { incoming: null, outgoing: [] } );\n\tconst subscribed = useRef( false );\n\n\tconst setControlledBlocks = () => {\n\t\tif ( ! controlledBlocks ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We don't need to persist this change because we only replace\n\t\t// controlled inner blocks when the change was caused by an entity,\n\t\t// and so it would already be persisted.\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tif ( clientId ) {\n\t\t\t// It is important to batch here because otherwise,\n\t\t\t// as soon as `setHasControlledInnerBlocks` is called\n\t\t\t// the effect to restore might be triggered\n\t\t\t// before the actual blocks get set properly in state.\n\t\t\tregistry.batch( () => {\n\t\t\t\tsetHasControlledInnerBlocks( clientId, true );\n\t\t\t\tconst storeBlocks = controlledBlocks.map( ( block ) =>\n\t\t\t\t\tcloneBlock( block )\n\t\t\t\t);\n\t\t\t\tif ( subscribed.current ) {\n\t\t\t\t\tpendingChanges.current.incoming = storeBlocks;\n\t\t\t\t}\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\treplaceInnerBlocks( clientId, storeBlocks );\n\t\t\t} );\n\t\t} else {\n\t\t\tif ( subscribed.current ) {\n\t\t\t\tpendingChanges.current.incoming = controlledBlocks;\n\t\t\t}\n\t\t\tresetBlocks( controlledBlocks );\n\t\t}\n\t};\n\n\t// Clean up the changes made by setControlledBlocks() when the component\n\t// containing useBlockSync() unmounts.\n\tconst unsetControlledBlocks = () => {\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tif ( clientId ) {\n\t\t\tsetHasControlledInnerBlocks( clientId, false );\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\treplaceInnerBlocks( clientId, [] );\n\t\t} else {\n\t\t\tresetBlocks( [] );\n\t\t}\n\t};\n\n\t// Add a subscription to the block-editor registry to detect when changes\n\t// have been made. This lets us inform the data source of changes. This\n\t// is an effect so that the subscriber can run synchronously without\n\t// waiting for React renders for changes.\n\tconst onInputRef = useRef( onInput );\n\tconst onChangeRef = useRef( onChange );\n\tuseEffect( () => {\n\t\tonInputRef.current = onInput;\n\t\tonChangeRef.current = onChange;\n\t}, [ onInput, onChange ] );\n\n\t// Determine if blocks need to be reset when they change.\n\tuseEffect( () => {\n\t\tif ( pendingChanges.current.outgoing.includes( controlledBlocks ) ) {\n\t\t\t// Skip block reset if the value matches expected outbound sync\n\t\t\t// triggered by this component by a preceding change detection.\n\t\t\t// Only skip if the value matches expectation, since a reset should\n\t\t\t// still occur if the value is modified (not equal by reference),\n\t\t\t// to allow that the consumer may apply modifications to reflect\n\t\t\t// back on the editor.\n\t\t\tif (\n\t\t\t\tpendingChanges.current.outgoing[\n\t\t\t\t\tpendingChanges.current.outgoing.length - 1\n\t\t\t\t] === controlledBlocks\n\t\t\t) {\n\t\t\t\tpendingChanges.current.outgoing = [];\n\t\t\t}\n\t\t} else if ( getBlocks( clientId ) !== controlledBlocks ) {\n\t\t\t// Reset changing value in all other cases than the sync described\n\t\t\t// above. Since this can be reached in an update following an out-\n\t\t\t// bound sync, unset the outbound value to avoid considering it in\n\t\t\t// subsequent renders.\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tconst hadSelecton = hasSelectedBlock();\n\t\t\tconst selectionAnchor = getSelectionStart();\n\t\t\tconst selectionFocus = getSelectionEnd();\n\t\t\tsetControlledBlocks();\n\n\t\t\tif ( controlledSelection ) {\n\t\t\t\tresetSelection(\n\t\t\t\t\tcontrolledSelection.selectionStart,\n\t\t\t\t\tcontrolledSelection.selectionEnd,\n\t\t\t\t\tcontrolledSelection.initialPosition\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst selectionStillExists = getBlock(\n\t\t\t\t\tselectionAnchor.clientId\n\t\t\t\t);\n\t\t\t\tif ( hadSelecton && ! selectionStillExists ) {\n\t\t\t\t\tselectBlock( clientId );\n\t\t\t\t} else {\n\t\t\t\t\tresetSelection( selectionAnchor, selectionFocus );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [ controlledBlocks, clientId ] );\n\n\tuseEffect( () => {\n\t\t// When the block becomes uncontrolled, it means its inner state has been reset\n\t\t// we need to take the blocks again from the external value property.\n\t\tif ( ! isControlled ) {\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tsetControlledBlocks();\n\t\t}\n\t}, [ isControlled ] );\n\n\tuseEffect( () => {\n\t\tconst {\n\t\t\tgetSelectedBlocksInitialCaretPosition,\n\t\t\tisLastBlockChangePersistent,\n\t\t\t__unstableIsLastBlockChangeIgnored,\n\t\t\tareInnerBlocksControlled,\n\t\t} = registry.select( blockEditorStore );\n\n\t\tlet blocks = getBlocks( clientId );\n\t\tlet isPersistent = isLastBlockChangePersistent();\n\t\tlet previousAreBlocksDifferent = false;\n\n\t\tsubscribed.current = true;\n\t\tconst unsubscribe = registry.subscribe( () => {\n\t\t\t// Sometimes, when changing block lists, lingering subscriptions\n\t\t\t// might trigger before they are cleaned up. If the block for which\n\t\t\t// the subscription runs is no longer in the store, this would clear\n\t\t\t// its parent entity's block list. To avoid this, we bail out if\n\t\t\t// the subscription is triggering for a block (`clientId !== null`)\n\t\t\t// and its block name can't be found because it's not on the list.\n\t\t\t// (`getBlockName( clientId ) === null`).\n\t\t\tif ( clientId !== null && getBlockName( clientId ) === null )\n\t\t\t\treturn;\n\n\t\t\t// When RESET_BLOCKS on parent blocks get called, the controlled blocks\n\t\t\t// can reset to uncontrolled, in these situations, it means we need to populate\n\t\t\t// the blocks again from the external blocks (the value property here)\n\t\t\t// and we should stop triggering onChange\n\t\t\tconst isStillControlled =\n\t\t\t\t! clientId || areInnerBlocksControlled( clientId );\n\t\t\tif ( ! isStillControlled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst newIsPersistent = isLastBlockChangePersistent();\n\t\t\tconst newBlocks = getBlocks( clientId );\n\t\t\tconst areBlocksDifferent = newBlocks !== blocks;\n\t\t\tblocks = newBlocks;\n\t\t\tif (\n\t\t\t\tareBlocksDifferent &&\n\t\t\t\t( pendingChanges.current.incoming ||\n\t\t\t\t\t__unstableIsLastBlockChangeIgnored() )\n\t\t\t) {\n\t\t\t\tpendingChanges.current.incoming = null;\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Since we often dispatch an action to mark the previous action as\n\t\t\t// persistent, we need to make sure that the blocks changed on the\n\t\t\t// previous action before committing the change.\n\t\t\tconst didPersistenceChange =\n\t\t\t\tpreviousAreBlocksDifferent &&\n\t\t\t\t! areBlocksDifferent &&\n\t\t\t\tnewIsPersistent &&\n\t\t\t\t! isPersistent;\n\n\t\t\tif ( areBlocksDifferent || didPersistenceChange ) {\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\t// We know that onChange/onInput will update controlledBlocks.\n\t\t\t\t// We need to be aware that it was caused by an outgoing change\n\t\t\t\t// so that we do not treat it as an incoming change later on,\n\t\t\t\t// which would cause a block reset.\n\t\t\t\tpendingChanges.current.outgoing.push( blocks );\n\n\t\t\t\t// Inform the controlling entity that changes have been made to\n\t\t\t\t// the block-editor store they should be aware about.\n\t\t\t\tconst updateParent = isPersistent\n\t\t\t\t\t? onChangeRef.current\n\t\t\t\t\t: onInputRef.current;\n\t\t\t\tupdateParent( blocks, {\n\t\t\t\t\tselection: {\n\t\t\t\t\t\tselectionStart: getSelectionStart(),\n\t\t\t\t\t\tselectionEnd: getSelectionEnd(),\n\t\t\t\t\t\tinitialPosition:\n\t\t\t\t\t\t\tgetSelectedBlocksInitialCaretPosition(),\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t\tpreviousAreBlocksDifferent = areBlocksDifferent;\n\t\t} );\n\n\t\treturn () => {\n\t\t\tsubscribed.current = false;\n\t\t\tunsubscribe();\n\t\t};\n\t}, [ registry, clientId ] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tunsetControlledBlocks();\n\t\t};\n\t}, [] );\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createElement } from "@wordpress/element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WordPress dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { SelectControl, __experimentalToolsPanelItem as ToolsPanelItem } from '@wordpress/components';
|
|
7
|
+
import { __, _x } from '@wordpress/i18n';
|
|
8
|
+
const DEFAULT_SIZE_OPTIONS = [{
|
|
9
|
+
label: _x('Thumbnail', 'Image size option for resolution control'),
|
|
10
|
+
value: 'thumbnail'
|
|
11
|
+
}, {
|
|
12
|
+
label: _x('Medium', 'Image size option for resolution control'),
|
|
13
|
+
value: 'medium'
|
|
14
|
+
}, {
|
|
15
|
+
label: _x('Large', 'Image size option for resolution control'),
|
|
16
|
+
value: 'large'
|
|
17
|
+
}, {
|
|
18
|
+
label: _x('Full Size', 'Image size option for resolution control'),
|
|
19
|
+
value: 'full'
|
|
20
|
+
}];
|
|
21
|
+
export default function ResolutionTool({
|
|
22
|
+
panelId,
|
|
23
|
+
value,
|
|
24
|
+
onChange,
|
|
25
|
+
options = DEFAULT_SIZE_OPTIONS,
|
|
26
|
+
defaultValue = DEFAULT_SIZE_OPTIONS[0].value,
|
|
27
|
+
isShownByDefault = true
|
|
28
|
+
}) {
|
|
29
|
+
const displayValue = value !== null && value !== void 0 ? value : defaultValue;
|
|
30
|
+
return createElement(ToolsPanelItem, {
|
|
31
|
+
hasValue: () => displayValue !== defaultValue,
|
|
32
|
+
label: __('Resolution'),
|
|
33
|
+
onDeselect: () => onChange(defaultValue),
|
|
34
|
+
isShownByDefault: isShownByDefault,
|
|
35
|
+
panelId: panelId
|
|
36
|
+
}, createElement(SelectControl, {
|
|
37
|
+
label: __('Resolution'),
|
|
38
|
+
value: displayValue,
|
|
39
|
+
options: options,
|
|
40
|
+
onChange: onChange,
|
|
41
|
+
help: __('Select the size of the source image.'),
|
|
42
|
+
size: '__unstable-large'
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/resolution-tool/index.js"],"names":["SelectControl","__experimentalToolsPanelItem","ToolsPanelItem","__","_x","DEFAULT_SIZE_OPTIONS","label","value","ResolutionTool","panelId","onChange","options","defaultValue","isShownByDefault","displayValue"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,aADD,EAECC,4BAA4B,IAAIC,cAFjC,QAGO,uBAHP;AAIA,SAASC,EAAT,EAAaC,EAAb,QAAuB,iBAAvB;AAEA,MAAMC,oBAAoB,GAAG,CAC5B;AACCC,EAAAA,KAAK,EAAEF,EAAE,CAAE,WAAF,EAAe,0CAAf,CADV;AAECG,EAAAA,KAAK,EAAE;AAFR,CAD4B,EAK5B;AACCD,EAAAA,KAAK,EAAEF,EAAE,CAAE,QAAF,EAAY,0CAAZ,CADV;AAECG,EAAAA,KAAK,EAAE;AAFR,CAL4B,EAS5B;AACCD,EAAAA,KAAK,EAAEF,EAAE,CAAE,OAAF,EAAW,0CAAX,CADV;AAECG,EAAAA,KAAK,EAAE;AAFR,CAT4B,EAa5B;AACCD,EAAAA,KAAK,EAAEF,EAAE,CAAE,WAAF,EAAe,0CAAf,CADV;AAECG,EAAAA,KAAK,EAAE;AAFR,CAb4B,CAA7B;AAmBA,eAAe,SAASC,cAAT,CAAyB;AACvCC,EAAAA,OADuC;AAEvCF,EAAAA,KAFuC;AAGvCG,EAAAA,QAHuC;AAIvCC,EAAAA,OAAO,GAAGN,oBAJ6B;AAKvCO,EAAAA,YAAY,GAAGP,oBAAoB,CAAE,CAAF,CAApB,CAA0BE,KALF;AAMvCM,EAAAA,gBAAgB,GAAG;AANoB,CAAzB,EAOX;AACH,QAAMC,YAAY,GAAGP,KAAH,aAAGA,KAAH,cAAGA,KAAH,GAAYK,YAA9B;AACA,SACC,cAAC,cAAD;AACC,IAAA,QAAQ,EAAG,MAAME,YAAY,KAAKF,YADnC;AAEC,IAAA,KAAK,EAAGT,EAAE,CAAE,YAAF,CAFX;AAGC,IAAA,UAAU,EAAG,MAAMO,QAAQ,CAAEE,YAAF,CAH5B;AAIC,IAAA,gBAAgB,EAAGC,gBAJpB;AAKC,IAAA,OAAO,EAAGJ;AALX,KAOC,cAAC,aAAD;AACC,IAAA,KAAK,EAAGN,EAAE,CAAE,YAAF,CADX;AAEC,IAAA,KAAK,EAAGW,YAFT;AAGC,IAAA,OAAO,EAAGH,OAHX;AAIC,IAAA,QAAQ,EAAGD,QAJZ;AAKC,IAAA,IAAI,EAAGP,EAAE,CAAE,sCAAF,CALV;AAMC,IAAA,IAAI,EAAG;AANR,IAPD,CADD;AAkBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tSelectControl,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\n\nconst DEFAULT_SIZE_OPTIONS = [\n\t{\n\t\tlabel: _x( 'Thumbnail', 'Image size option for resolution control' ),\n\t\tvalue: 'thumbnail',\n\t},\n\t{\n\t\tlabel: _x( 'Medium', 'Image size option for resolution control' ),\n\t\tvalue: 'medium',\n\t},\n\t{\n\t\tlabel: _x( 'Large', 'Image size option for resolution control' ),\n\t\tvalue: 'large',\n\t},\n\t{\n\t\tlabel: _x( 'Full Size', 'Image size option for resolution control' ),\n\t\tvalue: 'full',\n\t},\n];\n\nexport default function ResolutionTool( {\n\tpanelId,\n\tvalue,\n\tonChange,\n\toptions = DEFAULT_SIZE_OPTIONS,\n\tdefaultValue = DEFAULT_SIZE_OPTIONS[ 0 ].value,\n\tisShownByDefault = true,\n} ) {\n\tconst displayValue = value ?? defaultValue;\n\treturn (\n\t\t<ToolsPanelItem\n\t\t\thasValue={ () => displayValue !== defaultValue }\n\t\t\tlabel={ __( 'Resolution' ) }\n\t\t\tonDeselect={ () => onChange( defaultValue ) }\n\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\tpanelId={ panelId }\n\t\t>\n\t\t\t<SelectControl\n\t\t\t\tlabel={ __( 'Resolution' ) }\n\t\t\t\tvalue={ displayValue }\n\t\t\t\toptions={ options }\n\t\t\t\tonChange={ onChange }\n\t\t\t\thelp={ __( 'Select the size of the source image.' ) }\n\t\t\t\tsize={ '__unstable-large' }\n\t\t\t/>\n\t\t</ToolsPanelItem>\n\t);\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import { createElement } from "@wordpress/element";
|
|
|
4
4
|
* WordPress dependencies
|
|
5
5
|
*/
|
|
6
6
|
import { RawHTML } from '@wordpress/element';
|
|
7
|
-
import { children as childrenSource
|
|
7
|
+
import { children as childrenSource } from '@wordpress/blocks';
|
|
8
8
|
import deprecated from '@wordpress/deprecated';
|
|
9
9
|
/**
|
|
10
10
|
* Internal dependencies
|
|
@@ -47,39 +47,4 @@ export const Content = ({
|
|
|
47
47
|
|
|
48
48
|
return content;
|
|
49
49
|
};
|
|
50
|
-
Content.__unstableIsRichTextContent = {};
|
|
51
|
-
|
|
52
|
-
function findContent(blocks, richTextValues = []) {
|
|
53
|
-
if (!Array.isArray(blocks)) {
|
|
54
|
-
blocks = [blocks];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
for (const block of blocks) {
|
|
58
|
-
if (block?.type?.__unstableIsRichTextContent === Content.__unstableIsRichTextContent) {
|
|
59
|
-
richTextValues.push(block.props.value);
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (block?.props?.children) {
|
|
64
|
-
findContent(block.props.children, richTextValues);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return richTextValues;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function _getSaveElement({
|
|
72
|
-
name,
|
|
73
|
-
attributes,
|
|
74
|
-
innerBlocks
|
|
75
|
-
}) {
|
|
76
|
-
return getSaveElement(name, attributes, innerBlocks.map(_getSaveElement));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function getRichTextValues(blocks = []) {
|
|
80
|
-
getBlockProps.skipFilters = true;
|
|
81
|
-
const values = findContent((Array.isArray(blocks) ? blocks : [blocks]).map(_getSaveElement));
|
|
82
|
-
getBlockProps.skipFilters = false;
|
|
83
|
-
return values;
|
|
84
|
-
}
|
|
85
50
|
//# sourceMappingURL=content.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/content.js"],"names":["RawHTML","children","childrenSource","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/content.js"],"names":["RawHTML","children","childrenSource","deprecated","getMultilineTag","Content","value","tagName","Tag","multiline","props","Array","isArray","since","version","alternative","link","toHTML","MultilineTag","content","format","restProps"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,oBAAxB;AACA,SAASC,QAAQ,IAAIC,cAArB,QAA2C,mBAA3C;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,SAASC,eAAT,QAAgC,SAAhC;AAEA,OAAO,MAAMC,OAAO,GAAG,CAAE;AAAEC,EAAAA,KAAF;AAASC,EAAAA,OAAO,EAAEC,GAAlB;AAAuBC,EAAAA,SAAvB;AAAkC,KAAGC;AAArC,CAAF,KAAoD;AAC1E;AACA,MAAKC,KAAK,CAACC,OAAN,CAAeN,KAAf,CAAL,EAA8B;AAC7BH,IAAAA,UAAU,CAAE,qDAAF,EAAyD;AAClEU,MAAAA,KAAK,EAAE,KAD2D;AAElEC,MAAAA,OAAO,EAAE,KAFyD;AAGlEC,MAAAA,WAAW,EAAE,sBAHqD;AAIlEC,MAAAA,IAAI,EAAE;AAJ4D,KAAzD,CAAV;AAOAV,IAAAA,KAAK,GAAGJ,cAAc,CAACe,MAAf,CAAuBX,KAAvB,CAAR;AACA;;AAED,QAAMY,YAAY,GAAGd,eAAe,CAAEK,SAAF,CAApC;;AAEA,MAAK,CAAEH,KAAF,IAAWY,YAAhB,EAA+B;AAC9BZ,IAAAA,KAAK,GAAI,IAAIY,YAAc,MAAMA,YAAc,GAA/C;AACA;;AAED,QAAMC,OAAO,GAAG,cAAC,OAAD,QAAWb,KAAX,CAAhB;;AAEA,MAAKE,GAAL,EAAW;AACV,UAAM;AAAEY,MAAAA,MAAF;AAAU,SAAGC;AAAb,QAA2BX,KAAjC;AACA,WAAO,cAAC,GAAD,OAAUW;AAAV,OAAwBF,OAAxB,CAAP;AACA;;AAED,SAAOA,OAAP;AACA,CA3BM","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { RawHTML } from '@wordpress/element';\nimport { children as childrenSource } from '@wordpress/blocks';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { getMultilineTag } from './utils';\n\nexport const Content = ( { value, tagName: Tag, multiline, ...props } ) => {\n\t// Handle deprecated `children` and `node` sources.\n\tif ( Array.isArray( value ) ) {\n\t\tdeprecated( 'wp.blockEditor.RichText value prop as children type', {\n\t\t\tsince: '6.1',\n\t\t\tversion: '6.3',\n\t\t\talternative: 'value prop as string',\n\t\t\tlink: 'https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/introducing-attributes-and-editable-fields/',\n\t\t} );\n\n\t\tvalue = childrenSource.toHTML( value );\n\t}\n\n\tconst MultilineTag = getMultilineTag( multiline );\n\n\tif ( ! value && MultilineTag ) {\n\t\tvalue = `<${ MultilineTag }></${ MultilineTag }>`;\n\t}\n\n\tconst content = <RawHTML>{ value }</RawHTML>;\n\n\tif ( Tag ) {\n\t\tconst { format, ...restProps } = props;\n\t\treturn <Tag { ...restProps }>{ content }</Tag>;\n\t}\n\n\treturn content;\n};\n"]}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { RawHTML, StrictMode, Fragment } from '@wordpress/element';
|
|
5
|
+
import { getSaveElement, __unstableGetBlockProps as getBlockProps } from '@wordpress/blocks';
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import InnerBlocks from '../inner-blocks';
|
|
11
|
+
import { Content } from './content';
|
|
12
|
+
/*
|
|
13
|
+
* This function is similar to `@wordpress/element`'s `renderToString` function,
|
|
14
|
+
* except that it does not render the elements to a string, but instead collects
|
|
15
|
+
* the values of all rich text `Content` elements.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
function addValuesForElement(element, ...args) {
|
|
19
|
+
if (null === element || undefined === element || false === element) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (Array.isArray(element)) {
|
|
24
|
+
return addValuesForElements(element, ...args);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
switch (typeof element) {
|
|
28
|
+
case 'string':
|
|
29
|
+
case 'number':
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const {
|
|
34
|
+
type,
|
|
35
|
+
props
|
|
36
|
+
} = element;
|
|
37
|
+
|
|
38
|
+
switch (type) {
|
|
39
|
+
case StrictMode:
|
|
40
|
+
case Fragment:
|
|
41
|
+
return addValuesForElements(props.children, ...args);
|
|
42
|
+
|
|
43
|
+
case RawHTML:
|
|
44
|
+
return;
|
|
45
|
+
|
|
46
|
+
case InnerBlocks.Content:
|
|
47
|
+
return addValuesForBlocks(...args);
|
|
48
|
+
|
|
49
|
+
case Content:
|
|
50
|
+
const [values] = args;
|
|
51
|
+
values.push(props.value);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
switch (typeof type) {
|
|
56
|
+
case 'string':
|
|
57
|
+
if (typeof props.children !== 'undefined') {
|
|
58
|
+
return addValuesForElements(props.children, ...args);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return;
|
|
62
|
+
|
|
63
|
+
case 'function':
|
|
64
|
+
if (type.prototype && typeof type.prototype.render === 'function') {
|
|
65
|
+
return addValuesForElement(new type(props).render(), ...args);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return addValuesForElement(type(props), ...args);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function addValuesForElements(children, ...args) {
|
|
73
|
+
children = Array.isArray(children) ? children : [children];
|
|
74
|
+
|
|
75
|
+
for (let i = 0; i < children.length; i++) {
|
|
76
|
+
addValuesForElement(children[i], ...args);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function _getSaveElement(name, attributes, innerBlocks) {
|
|
81
|
+
return getSaveElement(name, attributes, innerBlocks.map(block => _getSaveElement(block.name, block.attributes, block.innerBlocks)));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function addValuesForBlocks(values, blocks) {
|
|
85
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
86
|
+
const {
|
|
87
|
+
name,
|
|
88
|
+
attributes,
|
|
89
|
+
innerBlocks
|
|
90
|
+
} = blocks[i];
|
|
91
|
+
|
|
92
|
+
const saveElement = _getSaveElement(name, attributes, innerBlocks);
|
|
93
|
+
|
|
94
|
+
addValuesForElement(saveElement, values, innerBlocks);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function getRichTextValues(blocks = []) {
|
|
99
|
+
getBlockProps.skipFilters = true;
|
|
100
|
+
const values = [];
|
|
101
|
+
addValuesForBlocks(values, blocks);
|
|
102
|
+
getBlockProps.skipFilters = false;
|
|
103
|
+
return values;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=get-rich-text-values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/get-rich-text-values.js"],"names":["RawHTML","StrictMode","Fragment","getSaveElement","__unstableGetBlockProps","getBlockProps","InnerBlocks","Content","addValuesForElement","element","args","undefined","Array","isArray","addValuesForElements","type","props","children","addValuesForBlocks","values","push","value","prototype","render","i","length","_getSaveElement","name","attributes","innerBlocks","map","block","blocks","saveElement","getRichTextValues","skipFilters"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EA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AEC,IAAF,EAAQC,UAAR,EAAoBC,WAApB,CAAnC;;AACArB,IAAAA,mBAAmB,CAAEyB,WAAF,EAAed,MAAf,EAAuBU,WAAvB,CAAnB;AACA;AACD;;AAED,OAAO,SAASK,iBAAT,CAA4BF,MAAM,GAAG,EAArC,EAA0C;AAChD3B,EAAAA,aAAa,CAAC8B,WAAd,GAA4B,IAA5B;AACA,QAAMhB,MAAM,GAAG,EAAf;AACAD,EAAAA,kBAAkB,CAAEC,MAAF,EAAUa,MAAV,CAAlB;AACA3B,EAAAA,aAAa,CAAC8B,WAAd,GAA4B,KAA5B;AACA,SAAOhB,MAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { RawHTML, StrictMode, Fragment } from '@wordpress/element';\nimport {\n\tgetSaveElement,\n\t__unstableGetBlockProps as getBlockProps,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport InnerBlocks from '../inner-blocks';\nimport { Content } from './content';\n\n/*\n * This function is similar to `@wordpress/element`'s `renderToString` function,\n * except that it does not render the elements to a string, but instead collects\n * the values of all rich text `Content` elements.\n */\nfunction addValuesForElement( element, ...args ) {\n\tif ( null === element || undefined === element || false === element ) {\n\t\treturn;\n\t}\n\n\tif ( Array.isArray( element ) ) {\n\t\treturn addValuesForElements( element, ...args );\n\t}\n\n\tswitch ( typeof element ) {\n\t\tcase 'string':\n\t\tcase 'number':\n\t\t\treturn;\n\t}\n\n\tconst { type, props } = element;\n\n\tswitch ( type ) {\n\t\tcase StrictMode:\n\t\tcase Fragment:\n\t\t\treturn addValuesForElements( props.children, ...args );\n\t\tcase RawHTML:\n\t\t\treturn;\n\t\tcase InnerBlocks.Content:\n\t\t\treturn addValuesForBlocks( ...args );\n\t\tcase Content:\n\t\t\tconst [ values ] = args;\n\t\t\tvalues.push( props.value );\n\t\t\treturn;\n\t}\n\n\tswitch ( typeof type ) {\n\t\tcase 'string':\n\t\t\tif ( typeof props.children !== 'undefined' ) {\n\t\t\t\treturn addValuesForElements( props.children, ...args );\n\t\t\t}\n\t\t\treturn;\n\t\tcase 'function':\n\t\t\tif (\n\t\t\t\ttype.prototype &&\n\t\t\t\ttypeof type.prototype.render === 'function'\n\t\t\t) {\n\t\t\t\treturn addValuesForElement(\n\t\t\t\t\tnew type( props ).render(),\n\t\t\t\t\t...args\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn addValuesForElement( type( props ), ...args );\n\t}\n}\n\nfunction addValuesForElements( children, ...args ) {\n\tchildren = Array.isArray( children ) ? children : [ children ];\n\n\tfor ( let i = 0; i < children.length; i++ ) {\n\t\taddValuesForElement( children[ i ], ...args );\n\t}\n}\n\nfunction _getSaveElement( name, attributes, innerBlocks ) {\n\treturn getSaveElement(\n\t\tname,\n\t\tattributes,\n\t\tinnerBlocks.map( ( block ) =>\n\t\t\t_getSaveElement( block.name, block.attributes, block.innerBlocks )\n\t\t)\n\t);\n}\n\nfunction addValuesForBlocks( values, blocks ) {\n\tfor ( let i = 0; i < blocks.length; i++ ) {\n\t\tconst { name, attributes, innerBlocks } = blocks[ i ];\n\t\tconst saveElement = _getSaveElement( name, attributes, innerBlocks );\n\t\taddValuesForElement( saveElement, values, innerBlocks );\n\t}\n}\n\nexport function getRichTextValues( blocks = [] ) {\n\tgetBlockProps.skipFilters = true;\n\tconst values = [];\n\taddValuesForBlocks( values, blocks );\n\tgetBlockProps.skipFilters = false;\n\treturn values;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js"],"names":["__","useSetting","useSpacingSizes","spacingSizes","name","slug","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js"],"names":["__","useSetting","useSpacingSizes","spacingSizes","name","slug","size","length","unshift","undefined"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,mBAAvB;AAEA,eAAe,SAASC,eAAT,GAA2B;AACzC,QAAMC,YAAY,GAAG,CACpB;AAAEC,IAAAA,IAAI,EAAE,CAAR;AAAWC,IAAAA,IAAI,EAAE,GAAjB;AAAsBC,IAAAA,IAAI,EAAE;AAA5B,GADoB,EAEpB,IAAKL,UAAU,CAAE,sBAAF,CAAV,IAAwC,EAA7C,CAFoB,CAArB;;AAKA,MAAKE,YAAY,CAACI,MAAb,GAAsB,CAA3B,EAA+B;AAC9BJ,IAAAA,YAAY,CAACK,OAAb,CAAsB;AACrBJ,MAAAA,IAAI,EAAEJ,EAAE,CAAE,SAAF,CADa;AAErBK,MAAAA,IAAI,EAAE,SAFe;AAGrBC,MAAAA,IAAI,EAAEG;AAHe,KAAtB;AAKA;;AAED,SAAON,YAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../../use-setting';\n\nexport default function useSpacingSizes() {\n\tconst spacingSizes = [\n\t\t{ name: 0, slug: '0', size: 0 },\n\t\t...( useSetting( 'spacing.spacingSizes' ) || [] ),\n\t];\n\n\tif ( spacingSizes.length > 8 ) {\n\t\tspacingSizes.unshift( {\n\t\t\tname: __( 'Default' ),\n\t\t\tslug: 'default',\n\t\t\tsize: undefined,\n\t\t} );\n\t}\n\n\treturn spacingSizes;\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
4
4
|
* Internal dependencies
|
|
5
5
|
*/
|
|
6
6
|
import SpacingInputControl from './spacing-input-control';
|
|
7
|
-
import { LABELS, ICONS, hasAxisSupport } from '../utils';
|
|
7
|
+
import { LABELS, ICONS, getPresetValueFromCustomValue, hasAxisSupport } from '../utils';
|
|
8
8
|
const groupedSides = ['vertical', 'horizontal'];
|
|
9
9
|
export default function AxialInputControls({
|
|
10
10
|
minimumCustomValue,
|
|
@@ -19,9 +19,13 @@ export default function AxialInputControls({
|
|
|
19
19
|
const createHandleOnChange = side => next => {
|
|
20
20
|
if (!onChange) {
|
|
21
21
|
return;
|
|
22
|
-
}
|
|
22
|
+
} // Encode the existing value into the preset value if the passed in value matches the value of one of the spacingSizes.
|
|
23
|
+
|
|
23
24
|
|
|
24
|
-
const nextValues = { ...values
|
|
25
|
+
const nextValues = { ...Object.keys(values).reduce((acc, key) => {
|
|
26
|
+
acc[key] = getPresetValueFromCustomValue(values[key], spacingSizes);
|
|
27
|
+
return acc;
|
|
28
|
+
}, {})
|
|
25
29
|
};
|
|
26
30
|
|
|
27
31
|
if (side === 'vertical') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/input-controls/axial.js"],"names":["SpacingInputControl","LABELS","ICONS","hasAxisSupport","groupedSides","AxialInputControls","minimumCustomValue","onChange","onMouseOut","onMouseOver","sides","spacingSizes","type","values","createHandleOnChange","side","next","nextValues","top","bottom","left","right","filteredSides","length","filter","map","axisValue"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,mBAAP,MAAgC,yBAAhC;AACA,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/input-controls/axial.js"],"names":["SpacingInputControl","LABELS","ICONS","getPresetValueFromCustomValue","hasAxisSupport","groupedSides","AxialInputControls","minimumCustomValue","onChange","onMouseOut","onMouseOver","sides","spacingSizes","type","values","createHandleOnChange","side","next","nextValues","Object","keys","reduce","acc","key","top","bottom","left","right","filteredSides","length","filter","map","axisValue"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,mBAAP,MAAgC,yBAAhC;AACA,SACCC,MADD,EAECC,KAFD,EAGCC,6BAHD,EAICC,cAJD,QAKO,UALP;AAOA,MAAMC,YAAY,GAAG,CAAE,UAAF,EAAc,YAAd,CAArB;AAEA,eAAe,SAASC,kBAAT,CAA6B;AAC3CC,EAAAA,kBAD2C;AAE3CC,EAAAA,QAF2C;AAG3CC,EAA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AAA,GAAG,EAAI,yBAAyBV,IAAM,EADvC;AAEC,MAAA,IAAI,EAAGd,KAAK,CAAEc,IAAF,CAFb;AAGC,MAAA,KAAK,EAAGf,MAAM,CAAEe,IAAF,CAHf;AAIC,MAAA,kBAAkB,EAAGT,kBAJtB;AAKC,MAAA,QAAQ,EAAGQ,oBAAoB,CAAEC,IAAF,CALhC;AAMC,MAAA,UAAU,EAAGP,UANd;AAOC,MAAA,WAAW,EAAGC,WAPf;AAQC,MAAA,IAAI,EAAGM,IARR;AASC,MAAA,YAAY,EAAGJ,YAThB;AAUC,MAAA,IAAI,EAAGC,IAVR;AAWC,MAAA,KAAK,EAAGmB,SAXT;AAYC,MAAA,cAAc,EAAG;AAZlB,MADD;AAgBA,GAnBC,CADH,CADD;AAwBA","sourcesContent":["/**\n * Internal dependencies\n */\nimport SpacingInputControl from './spacing-input-control';\nimport {\n\tLABELS,\n\tICONS,\n\tgetPresetValueFromCustomValue,\n\thasAxisSupport,\n} from '../utils';\n\nconst groupedSides = [ 'vertical', 'horizontal' ];\n\nexport default function AxialInputControls( {\n\tminimumCustomValue,\n\tonChange,\n\tonMouseOut,\n\tonMouseOver,\n\tsides,\n\tspacingSizes,\n\ttype,\n\tvalues,\n} ) {\n\tconst createHandleOnChange = ( side ) => ( next ) => {\n\t\tif ( ! onChange ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Encode the existing value into the preset value if the passed in value matches the value of one of the spacingSizes.\n\t\tconst nextValues = {\n\t\t\t...Object.keys( values ).reduce( ( acc, key ) => {\n\t\t\t\tacc[ key ] = getPresetValueFromCustomValue(\n\t\t\t\t\tvalues[ key ],\n\t\t\t\t\tspacingSizes\n\t\t\t\t);\n\t\t\t\treturn acc;\n\t\t\t}, {} ),\n\t\t};\n\n\t\tif ( side === 'vertical' ) {\n\t\t\tnextValues.top = next;\n\t\t\tnextValues.bottom = next;\n\t\t}\n\n\t\tif ( side === 'horizontal' ) {\n\t\t\tnextValues.left = next;\n\t\t\tnextValues.right = next;\n\t\t}\n\n\t\tonChange( nextValues );\n\t};\n\n\t// Filter sides if custom configuration provided, maintaining default order.\n\tconst filteredSides = sides?.length\n\t\t? groupedSides.filter( ( side ) => hasAxisSupport( sides, side ) )\n\t\t: groupedSides;\n\n\treturn (\n\t\t<>\n\t\t\t{ filteredSides.map( ( side ) => {\n\t\t\t\tconst axisValue =\n\t\t\t\t\tside === 'vertical' ? values.top : values.left;\n\t\t\t\treturn (\n\t\t\t\t\t<SpacingInputControl\n\t\t\t\t\t\tkey={ `spacing-sizes-control-${ side }` }\n\t\t\t\t\t\ticon={ ICONS[ side ] }\n\t\t\t\t\t\tlabel={ LABELS[ side ] }\n\t\t\t\t\t\tminimumCustomValue={ minimumCustomValue }\n\t\t\t\t\t\tonChange={ createHandleOnChange( side ) }\n\t\t\t\t\t\tonMouseOut={ onMouseOut }\n\t\t\t\t\t\tonMouseOver={ onMouseOver }\n\t\t\t\t\t\tside={ side }\n\t\t\t\t\t\tspacingSizes={ spacingSizes }\n\t\t\t\t\t\ttype={ type }\n\t\t\t\t\t\tvalue={ axisValue }\n\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
4
4
|
* Internal dependencies
|
|
5
5
|
*/
|
|
6
6
|
import SpacingInputControl from './spacing-input-control';
|
|
7
|
-
import { ALL_SIDES, LABELS, ICONS } from '../utils';
|
|
7
|
+
import { ALL_SIDES, LABELS, ICONS, getPresetValueFromCustomValue } from '../utils';
|
|
8
8
|
export default function SeparatedInputControls({
|
|
9
9
|
minimumCustomValue,
|
|
10
10
|
onChange,
|
|
@@ -19,7 +19,11 @@ export default function SeparatedInputControls({
|
|
|
19
19
|
const filteredSides = sides?.length ? ALL_SIDES.filter(side => sides.includes(side)) : ALL_SIDES;
|
|
20
20
|
|
|
21
21
|
const createHandleOnChange = side => next => {
|
|
22
|
-
|
|
22
|
+
// Encode the existing value into the preset value if the passed in value matches the value of one of the spacingSizes.
|
|
23
|
+
const nextValues = { ...Object.keys(values).reduce((acc, key) => {
|
|
24
|
+
acc[key] = getPresetValueFromCustomValue(values[key], spacingSizes);
|
|
25
|
+
return acc;
|
|
26
|
+
}, {})
|
|
23
27
|
};
|
|
24
28
|
nextValues[side] = next;
|
|
25
29
|
onChange(nextValues);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/input-controls/separated.js"],"names":["SpacingInputControl","ALL_SIDES","LABELS","ICONS","SeparatedInputControls","minimumCustomValue","onChange","onMouseOut","onMouseOver","sides","spacingSizes","type","values","filteredSides","length","filter","side","includes","createHandleOnChange","next","nextValues","map"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,mBAAP,MAAgC,yBAAhC;AACA,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/input-controls/separated.js"],"names":["SpacingInputControl","ALL_SIDES","LABELS","ICONS","getPresetValueFromCustomValue","SeparatedInputControls","minimumCustomValue","onChange","onMouseOut","onMouseOver","sides","spacingSizes","type","values","filteredSides","length","filter","side","includes","createHandleOnChange","next","nextValues","Object","keys","reduce","acc","key","map"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,mBAAP,MAAgC,yBAAhC;AACA,SACCC,SADD,EAECC,MAFD,EAGCC,KAHD,EAICC,6BAJD,QAKO,UALP;AAOA,eAAe,SAASC,sBAAT,CAAiC;AAC/CC,EAAAA,kBAD+C;AAE/CC,EAAAA,QAF+C;AAG/CC,EAAAA,UAH+C;AAI/CC,EAAAA,WAJ+C;AAK/CC,EAAAA,KAL+C;AAM/CC,EAAAA,YAN+C;AAO/CC,EAAAA,IAP+C;AAQ/CC,EAAAA;AAR+C,CAAjC,EASX;AACH;AACA,QAAMC,aAAa,GAAGJ,KAAK,EAAEK,MAAP,GACnBd,SAAS,CAACe,MAAV,CAAoBC,IAAF,IAAYP,KAAK,CAACQ,QAAN,CAAgBD,IAAhB,CAA9B,CADmB,GAEnBhB,SAFH;;AAIA,QAAMkB,oBAAoB,GAAKF,IAAF,IAAcG,IAAF,IAAY;AACpD;AACA,UAAMC,UAAU,GAAG,EAClB,GAAGC,MAAM,CAACC,IAAP,CAAaV,MAAb,EAAsBW,MAAtB,CAA8B,CAAEC,GAAF,EAAOC,GAAP,KAAgB;AAChDD,QAAAA,GAAG,CAAEC,GAAF,CAAH,GAAatB,6BAA6B,CACzCS,MAAM,CAAEa,GAAF,CADmC,EAEzCf,YAFyC,CAA1C;AAIA,eAAOc,GAAP;AACA,OANE,EAMA,EANA;AADe,KAAnB;AAUAJ,IAAAA,UAAU,CAAEJ,IAAF,CAAV,GAAqBG,IAArB;AAEAb,IAAAA,QAAQ,CAAEc,UAAF,CAAR;AACA,GAfD;;AAiBA,SACC,8BACGP,aAAa,CAACa,GAAd,CAAqBV,IAAF,IAAY;AAChC,WACC,cAAC,mBAAD;AACC,MAAA,GAAG,EAAI,yBAAyBA,IAAM,EADvC;AAEC,MAAA,IAAI,EAAGd,KAAK,CAAEc,IAAF,CAFb;AAGC,MAAA,KAAK,EAAGf,MAAM,CAAEe,IAAF,CAHf;AAIC,MAAA,kBAAkB,EAAGX,kBAJtB;AAKC,MAAA,QAAQ,EAAGa,oBAAoB,CAAEF,IAAF,CALhC;AAMC,MAAA,UAAU,EAAGT,UANd;AAOC,MAAA,WAAW,EAAGC,WAPf;AAQC,MAAA,IAAI,EAAGQ,IARR;AASC,MAAA,YAAY,EAAGN,YAThB;AAUC,MAAA,IAAI,EAAGC,IAVR;AAWC,MAAA,KAAK,EAAGC,MAAM,CAAEI,IAAF,CAXf;AAYC,MAAA,cAAc,EAAG;AAZlB,MADD;AAgBA,GAjBC,CADH,CADD;AAsBA","sourcesContent":["/**\n * Internal dependencies\n */\nimport SpacingInputControl from './spacing-input-control';\nimport {\n\tALL_SIDES,\n\tLABELS,\n\tICONS,\n\tgetPresetValueFromCustomValue,\n} from '../utils';\n\nexport default function SeparatedInputControls( {\n\tminimumCustomValue,\n\tonChange,\n\tonMouseOut,\n\tonMouseOver,\n\tsides,\n\tspacingSizes,\n\ttype,\n\tvalues,\n} ) {\n\t// Filter sides if custom configuration provided, maintaining default order.\n\tconst filteredSides = sides?.length\n\t\t? ALL_SIDES.filter( ( side ) => sides.includes( side ) )\n\t\t: ALL_SIDES;\n\n\tconst createHandleOnChange = ( side ) => ( next ) => {\n\t\t// Encode the existing value into the preset value if the passed in value matches the value of one of the spacingSizes.\n\t\tconst nextValues = {\n\t\t\t...Object.keys( values ).reduce( ( acc, key ) => {\n\t\t\t\tacc[ key ] = getPresetValueFromCustomValue(\n\t\t\t\t\tvalues[ key ],\n\t\t\t\t\tspacingSizes\n\t\t\t\t);\n\t\t\t\treturn acc;\n\t\t\t}, {} ),\n\t\t};\n\n\t\tnextValues[ side ] = next;\n\n\t\tonChange( nextValues );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t{ filteredSides.map( ( side ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<SpacingInputControl\n\t\t\t\t\t\tkey={ `spacing-sizes-control-${ side }` }\n\t\t\t\t\t\ticon={ ICONS[ side ] }\n\t\t\t\t\t\tlabel={ LABELS[ side ] }\n\t\t\t\t\t\tminimumCustomValue={ minimumCustomValue }\n\t\t\t\t\t\tonChange={ createHandleOnChange( side ) }\n\t\t\t\t\t\tonMouseOut={ onMouseOut }\n\t\t\t\t\t\tonMouseOver={ onMouseOver }\n\t\t\t\t\t\tside={ side }\n\t\t\t\t\t\tspacingSizes={ spacingSizes }\n\t\t\t\t\t\ttype={ type }\n\t\t\t\t\t\tvalue={ values[ side ] }\n\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import { createElement } from "@wordpress/element";
|
|
|
4
4
|
* Internal dependencies
|
|
5
5
|
*/
|
|
6
6
|
import SpacingInputControl from './spacing-input-control';
|
|
7
|
-
import { LABELS } from '../utils';
|
|
7
|
+
import { LABELS, getPresetValueFromCustomValue } from '../utils';
|
|
8
8
|
export default function SingleInputControl({
|
|
9
9
|
minimumCustomValue,
|
|
10
10
|
onChange,
|
|
@@ -17,7 +17,11 @@ export default function SingleInputControl({
|
|
|
17
17
|
values
|
|
18
18
|
}) {
|
|
19
19
|
const createHandleOnChange = currentSide => next => {
|
|
20
|
-
|
|
20
|
+
// Encode the existing value into the preset value if the passed in value matches the value of one of the spacingSizes.
|
|
21
|
+
const nextValues = { ...Object.keys(values).reduce((acc, key) => {
|
|
22
|
+
acc[key] = getPresetValueFromCustomValue(values[key], spacingSizes);
|
|
23
|
+
return acc;
|
|
24
|
+
}, {})
|
|
21
25
|
};
|
|
22
26
|
nextValues[currentSide] = next;
|
|
23
27
|
onChange(nextValues);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/input-controls/single.js"],"names":["SpacingInputControl","LABELS","SingleInputControl","minimumCustomValue","onChange","onMouseOut","onMouseOver","showSideInLabel","side","spacingSizes","type","values","createHandleOnChange","currentSide","next","nextValues"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,mBAAP,MAAgC,yBAAhC;AACA,SAASC,MAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/input-controls/single.js"],"names":["SpacingInputControl","LABELS","getPresetValueFromCustomValue","SingleInputControl","minimumCustomValue","onChange","onMouseOut","onMouseOver","showSideInLabel","side","spacingSizes","type","values","createHandleOnChange","currentSide","next","nextValues","Object","keys","reduce","acc","key"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,mBAAP,MAAgC,yBAAhC;AACA,SAASC,MAAT,EAAiBC,6BAAjB,QAAsD,UAAtD;AAEA,eAAe,SAASC,kBAAT,CAA6B;AAC3CC,EAAAA,kBAD2C;AAE3CC,EAAAA,QAF2C;AAG3CC,EAAAA,UAH2C;AAI3CC,EAAAA,WAJ2C;AAK3CC,EAAAA,eAL2C;AAM3CC,EAAAA,IAN2C;AAO3CC,EAAAA,YAP2C;AAQ3CC,EAAAA,IAR2C;AAS3CC,EAAAA;AAT2C,CAA7B,EAUX;AACH,QAAMC,oBAAoB,GAAKC,WAAF,IAAqBC,IAAF,IAAY;AAC3D;AACA,UAAMC,UAAU,GAAG,EAClB,GAAGC,MAAM,CAACC,IAAP,CAAaN,MAAb,EAAsBO,MAAtB,CAA8B,CAAEC,GAAF,EAAOC,GAAP,KAAgB;AAChDD,QAAAA,GAAG,CAAEC,GAAF,CAAH,GAAanB,6BAA6B,CACzCU,MAAM,CAAES,GAAF,CADmC,EAEzCX,YAFyC,CAA1C;AAIA,eAAOU,GAAP;AACA,OANE,EAMA,EANA;AADe,KAAnB;AAUAJ,IAAAA,UAAU,CAAEF,WAAF,CAAV,GAA4BC,IAA5B;AAEAV,IAAAA,QAAQ,CAAEW,UAAF,CAAR;AACA,GAfD;;AAiBA,SACC,cAAC,mBAAD;AACC,IAAA,KAAK,EAAGf,MAAM,CAAEQ,IAAF,CADf;AAEC,IAAA,kBAAkB,EAAGL,kBAFtB;AAGC,IAAA,QAAQ,EAAGS,oBAAoB,CAAEJ,IAAF,CAHhC;AAIC,IAAA,UAAU,EAAGH,UAJd;AAKC,IAAA,WAAW,EAAGC,WALf;AAMC,IAAA,eAAe,EAAGC,eANnB;AAOC,IAAA,IAAI,EAAGC,IAPR;AAQC,IAAA,YAAY,EAAGC,YARhB;AASC,IAAA,IAAI,EAAGC,IATR;AAUC,IAAA,KAAK,EAAGC,MAAM,CAAEH,IAAF,CAVf;AAWC,IAAA,cAAc,EAAG;AAXlB,IADD;AAeA","sourcesContent":["/**\n * Internal dependencies\n */\nimport SpacingInputControl from './spacing-input-control';\nimport { LABELS, getPresetValueFromCustomValue } from '../utils';\n\nexport default function SingleInputControl( {\n\tminimumCustomValue,\n\tonChange,\n\tonMouseOut,\n\tonMouseOver,\n\tshowSideInLabel,\n\tside,\n\tspacingSizes,\n\ttype,\n\tvalues,\n} ) {\n\tconst createHandleOnChange = ( currentSide ) => ( next ) => {\n\t\t// Encode the existing value into the preset value if the passed in value matches the value of one of the spacingSizes.\n\t\tconst nextValues = {\n\t\t\t...Object.keys( values ).reduce( ( acc, key ) => {\n\t\t\t\tacc[ key ] = getPresetValueFromCustomValue(\n\t\t\t\t\tvalues[ key ],\n\t\t\t\t\tspacingSizes\n\t\t\t\t);\n\t\t\t\treturn acc;\n\t\t\t}, {} ),\n\t\t};\n\n\t\tnextValues[ currentSide ] = next;\n\n\t\tonChange( nextValues );\n\t};\n\n\treturn (\n\t\t<SpacingInputControl\n\t\t\tlabel={ LABELS[ side ] }\n\t\t\tminimumCustomValue={ minimumCustomValue }\n\t\t\tonChange={ createHandleOnChange( side ) }\n\t\t\tonMouseOut={ onMouseOut }\n\t\t\tonMouseOver={ onMouseOver }\n\t\t\tshowSideInLabel={ showSideInLabel }\n\t\t\tside={ side }\n\t\t\tspacingSizes={ spacingSizes }\n\t\t\ttype={ type }\n\t\t\tvalue={ values[ side ] }\n\t\t\twithInputField={ false }\n\t\t/>\n\t);\n}\n"]}
|
|
@@ -86,7 +86,7 @@ export function getCustomValueFromPreset(value, spacingSizes) {
|
|
|
86
86
|
|
|
87
87
|
export function getPresetValueFromCustomValue(value, spacingSizes) {
|
|
88
88
|
// Return value as-is if it is already a preset;
|
|
89
|
-
if (isValueSpacingPreset(value)) {
|
|
89
|
+
if (isValueSpacingPreset(value) || value === '0') {
|
|
90
90
|
return value;
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/utils.js"],"names":["__","sidesAll","sidesAxial","sidesBottom","sidesHorizontal","sidesLeft","sidesRight","sidesTop","sidesVertical","ALL_SIDES","DEFAULT_VALUES","top","undefined","right","bottom","left","ICONS","custom","axial","horizontal","vertical","LABELS","default","mixed","VIEWS","isValueSpacingPreset","value","includes","getCustomValueFromPreset","spacingSizes","slug","getSpacingPresetSlug","spacingSize","find","size","String","getPresetValueFromCustomValue","spacingMatch","getSpacingPresetCssVar","match","getSliderValueFromPreset","presetValue","parseFloat","sliderValue","findIndex","NaN","mode","arr","sort","a","b","filter","v","length","pop","getAllRawValue","values","Object","isValuesMixed","sides","Set","isValuesDefined","hasAxisSupport","axis","hasHorizontalSupport","hasVerticalSupport","getSupportedMenuItems","menuItems","label","icon","numberOfIndividualSides","forEach","side","hasBalancedSidesSupport","counts","getInitialView","sideValues","Boolean","hasMatchingAxialValues","hasNoValuesAndBalancedSides","entries","some","key"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SACCC,QADD,EAECC,UAFD,EAGCC,WAHD,EAICC,eAJD,EAKCC,SALD,EAMCC,UAND,EAOCC,QAPD,EAQCC,aARD,QASO,kBATP;AAWA,OAAO,MAAMC,SAAS,GAAG,CAAE,KAAF,EAAS,OAAT,EAAkB,QAAlB,EAA4B,MAA5B,CAAlB;AAEP,OAAO,MAAMC,cAAc,GAAG;AAC7BC,EAAAA,GAAG,EAAEC,SADwB;AAE7BC,EAAAA,KAAK,EAAED,SAFsB;AAG7BE,EAAAA,MAAM,EAAEF,SAHqB;AAI7BG,EAAAA,IAAI,EAAEH;AAJuB,CAAvB;AAOP,OAAO,MAAMI,KAAK,GAAG;AACpBC,EAAAA,MAAM,EAAEhB,QADY;AAEpBiB,EAAAA,KAAK,EAAEhB,UAFa;AAGpBiB,EAAAA,UAAU,EAAEf,eAHQ;AAIpBgB,EAAAA,QAAQ,EAAEZ,aAJU;AAKpBG,EAAAA,GAAG,EAAEJ,QALe;AAMpBM,EAAAA,KAAK,EAAEP,UANa;AAOpBQ,EAAAA,MAAM,EAAEX,WAPY;AAQpBY,EAAAA,IAAI,EAAEV;AARc,CAAd;AAWP,OAAO,MAAMgB,MAAM,GAA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CAFoD,CAIpD;AACA;AACA;AACA;;AACA,QAAMC,sBAAsB,GAC3BnE,GAAG,KAAKG,MAAR,IAAkBC,IAAI,KAAKF,KAA3B,KAAsC,CAAC,CAAEF,GAAH,IAAU,CAAC,CAAEI,IAAnD,CADD;AAEA,QAAMgE,2BAA2B,GAChC,CAAEH,UAAU,CAACvB,MAAb,IAAuBoB,uBAAuB,CAAEd,KAAF,CAD/C;;AAGA,MACCG,cAAc,CAAEH,KAAF,CAAd,KACEmB,sBAAsB,IAAIC,2BAD5B,CADD,EAGE;AACD,WAAOvD,KAAK,CAACN,KAAb;AACA,GAlBmD,CAoBpD;AACA;;;AACA,MAAK0D,UAAU,CAACvB,MAAX,KAAsB,CAA3B,EAA+B;AAC9B,QAAImB,IAAJ;AAEAf,IAAAA,MAAM,CAACuB,OAAP,CAAgBxB,MAAhB,EAAyByB,IAAzB,CAA+B,CAAE,CAAEC,GAAF,EAAOxD,KAAP,CAAF,KAAsB;AACpD8C,MAAAA,IAAI,GAAGU,GAAP;AACA,aAAOxD,KAAK,KAAKd,SAAjB;AACA,KAHD;AAKA,WAAO4D,IAAP;AACA,GA/BmD,CAiCpD;;;AACA,MAAKb,KAAK,EAAEN,MAAP,KAAkB,CAAlB,IAAuB,CAAEuB,UAAU,CAACvB,MAAzC,EAAkD;AACjD,WAAOM,KAAK,CAAE,CAAF,CAAZ;AACA,GApCmD,CAsCpD;;;AACA,SAAOnC,KAAK,CAACP,MAAb;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tsidesAll,\n\tsidesAxial,\n\tsidesBottom,\n\tsidesHorizontal,\n\tsidesLeft,\n\tsidesRight,\n\tsidesTop,\n\tsidesVertical,\n} from '@wordpress/icons';\n\nexport const ALL_SIDES = [ 'top', 'right', 'bottom', 'left' ];\n\nexport const DEFAULT_VALUES = {\n\ttop: undefined,\n\tright: undefined,\n\tbottom: undefined,\n\tleft: undefined,\n};\n\nexport const ICONS = {\n\tcustom: sidesAll,\n\taxial: sidesAxial,\n\thorizontal: sidesHorizontal,\n\tvertical: sidesVertical,\n\ttop: sidesTop,\n\tright: sidesRight,\n\tbottom: sidesBottom,\n\tleft: sidesLeft,\n};\n\nexport const LABELS = {\n\tdefault: __( 'Spacing control' ),\n\ttop: __( 'Top' ),\n\tbottom: __( 'Bottom' ),\n\tleft: __( 'Left' ),\n\tright: __( 'Right' ),\n\tmixed: __( 'Mixed' ),\n\tvertical: __( 'Vertical' ),\n\thorizontal: __( 'Horizontal' ),\n\taxial: __( 'Horizontal & vertical' ),\n\tcustom: __( 'Custom' ),\n};\n\nexport const VIEWS = {\n\taxial: 'axial',\n\ttop: 'top',\n\tright: 'right',\n\tbottom: 'bottom',\n\tleft: 'left',\n\tcustom: 'custom',\n};\n\n/**\n * Checks is given value is a spacing preset.\n *\n * @param {string} value Value to check\n *\n * @return {boolean} Return true if value is string in format var:preset|spacing|.\n */\nexport function isValueSpacingPreset( value ) {\n\tif ( ! value?.includes ) {\n\t\treturn false;\n\t}\n\treturn value === '0' || value.includes( 'var:preset|spacing|' );\n}\n\n/**\n * Converts a spacing preset into a custom value.\n *\n * @param {string} value Value to convert\n * @param {Array} spacingSizes Array of the current spacing preset objects\n *\n * @return {string} Mapping of the spacing preset to its equivalent custom value.\n */\nexport function getCustomValueFromPreset( value, spacingSizes ) {\n\tif ( ! isValueSpacingPreset( value ) ) {\n\t\treturn value;\n\t}\n\n\tconst slug = getSpacingPresetSlug( value );\n\tconst spacingSize = spacingSizes.find(\n\t\t( size ) => String( size.slug ) === slug\n\t);\n\n\treturn spacingSize?.size;\n}\n\n/**\n * Converts a custom value to preset value if one can be found.\n *\n * Returns value as-is if no match is found.\n *\n * @param {string} value Value to convert\n * @param {Array} spacingSizes Array of the current spacing preset objects\n *\n * @return {string} The preset value if it can be found.\n */\nexport function getPresetValueFromCustomValue( value, spacingSizes ) {\n\t// Return value as-is if it is already a preset;\n\tif ( isValueSpacingPreset( value ) ) {\n\t\treturn value;\n\t}\n\n\tconst spacingMatch = spacingSizes.find(\n\t\t( size ) => String( size.size ) === String( value )\n\t);\n\n\tif ( spacingMatch?.slug ) {\n\t\treturn `var:preset|spacing|${ spacingMatch.slug }`;\n\t}\n\n\treturn value;\n}\n\n/**\n * Converts a spacing preset into a custom value.\n *\n * @param {string} value Value to convert.\n *\n * @return {string | undefined} CSS var string for given spacing preset value.\n */\nexport function getSpacingPresetCssVar( value ) {\n\tif ( ! value ) {\n\t\treturn;\n\t}\n\n\tconst slug = value.match( /var:preset\\|spacing\\|(.+)/ );\n\n\tif ( ! slug ) {\n\t\treturn value;\n\t}\n\n\treturn `var(--wp--preset--spacing--${ slug[ 1 ] })`;\n}\n\n/**\n * Returns the slug section of the given spacing preset string.\n *\n * @param {string} value Value to extract slug from.\n *\n * @return {string|undefined} The int value of the slug from given spacing preset.\n */\nexport function getSpacingPresetSlug( value ) {\n\tif ( ! value ) {\n\t\treturn;\n\t}\n\n\tif ( value === '0' || value === 'default' ) {\n\t\treturn value;\n\t}\n\n\tconst slug = value.match( /var:preset\\|spacing\\|(.+)/ );\n\n\treturn slug ? slug[ 1 ] : undefined;\n}\n\n/**\n * Converts spacing preset value into a Range component value .\n *\n * @param {string} presetValue Value to convert to Range value.\n * @param {Array} spacingSizes Array of current spacing preset value objects.\n *\n * @return {number} The int value for use in Range control.\n */\nexport function getSliderValueFromPreset( presetValue, spacingSizes ) {\n\tif ( presetValue === undefined ) {\n\t\treturn 0;\n\t}\n\tconst slug =\n\t\tparseFloat( presetValue, 10 ) === 0\n\t\t\t? '0'\n\t\t\t: getSpacingPresetSlug( presetValue );\n\tconst sliderValue = spacingSizes.findIndex( ( spacingSize ) => {\n\t\treturn String( spacingSize.slug ) === slug;\n\t} );\n\n\t// Returning NaN rather than undefined as undefined makes range control thumb sit in center\n\treturn sliderValue !== -1 ? sliderValue : NaN;\n}\n\n/**\n * Gets an items with the most occurrence within an array\n * https://stackoverflow.com/a/20762713\n *\n * @param {Array<any>} arr Array of items to check.\n * @return {any} The item with the most occurrences.\n */\nfunction mode( arr ) {\n\treturn arr\n\t\t.sort(\n\t\t\t( a, b ) =>\n\t\t\t\tarr.filter( ( v ) => v === a ).length -\n\t\t\t\tarr.filter( ( v ) => v === b ).length\n\t\t)\n\t\t.pop();\n}\n\n/**\n * Gets the 'all' input value from values data.\n *\n * @param {Object} values Box spacing values\n *\n * @return {string} The most common value from all sides of box.\n */\nexport function getAllRawValue( values = {} ) {\n\treturn mode( Object.values( values ) );\n}\n\n/**\n * Checks to determine if values are mixed.\n *\n * @param {Object} values Box values.\n * @param {Array} sides Sides that values relate to.\n *\n * @return {boolean} Whether values are mixed.\n */\nexport function isValuesMixed( values = {}, sides = ALL_SIDES ) {\n\treturn (\n\t\t( Object.values( values ).length >= 1 &&\n\t\t\tObject.values( values ).length < sides.length ) ||\n\t\tnew Set( Object.values( values ) ).size > 1\n\t);\n}\n\n/**\n * Checks to determine if values are defined.\n *\n * @param {Object} values Box values.\n *\n * @return {boolean} Whether values are defined.\n */\nexport function isValuesDefined( values ) {\n\tif ( values === undefined || values === null ) {\n\t\treturn false;\n\t}\n\treturn Object.values( values ).filter( ( value ) => !! value ).length > 0;\n}\n\n/**\n * Determines whether a particular axis has support. If no axis is\n * specified, this function checks if either axis is supported.\n *\n * @param {Array} sides Supported sides.\n * @param {string} axis Which axis to check.\n *\n * @return {boolean} Whether there is support for the specified axis or both axes.\n */\nexport function hasAxisSupport( sides, axis ) {\n\tif ( ! sides || ! sides.length ) {\n\t\treturn false;\n\t}\n\n\tconst hasHorizontalSupport =\n\t\tsides.includes( 'horizontal' ) ||\n\t\t( sides.includes( 'left' ) && sides.includes( 'right' ) );\n\n\tconst hasVerticalSupport =\n\t\tsides.includes( 'vertical' ) ||\n\t\t( sides.includes( 'top' ) && sides.includes( 'bottom' ) );\n\n\tif ( axis === 'horizontal' ) {\n\t\treturn hasHorizontalSupport;\n\t}\n\n\tif ( axis === 'vertical' ) {\n\t\treturn hasVerticalSupport;\n\t}\n\n\treturn hasHorizontalSupport || hasVerticalSupport;\n}\n\n/**\n * Determines which menu options should be included in the SidePicker.\n *\n * @param {Array} sides Supported sides.\n *\n * @return {Object} Menu options with each option containing label & icon.\n */\nexport function getSupportedMenuItems( sides ) {\n\tif ( ! sides || ! sides.length ) {\n\t\treturn {};\n\t}\n\n\tconst menuItems = {};\n\n\t// Determine the primary \"side\" menu options.\n\tconst hasHorizontalSupport = hasAxisSupport( sides, 'horizontal' );\n\tconst hasVerticalSupport = hasAxisSupport( sides, 'vertical' );\n\n\tif ( hasHorizontalSupport && hasVerticalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.axial, icon: ICONS.axial };\n\t} else if ( hasHorizontalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.horizontal, icon: ICONS.horizontal };\n\t} else if ( hasVerticalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.vertical, icon: ICONS.vertical };\n\t}\n\n\t// Track whether we have any individual sides so we can omit the custom\n\t// option if required.\n\tlet numberOfIndividualSides = 0;\n\n\tALL_SIDES.forEach( ( side ) => {\n\t\tif ( sides.includes( side ) ) {\n\t\t\tnumberOfIndividualSides += 1;\n\t\t\tmenuItems[ side ] = {\n\t\t\t\tlabel: LABELS[ side ],\n\t\t\t\ticon: ICONS[ side ],\n\t\t\t};\n\t\t}\n\t} );\n\n\t// Add custom item if there are enough sides to warrant a separated view.\n\tif ( numberOfIndividualSides > 1 ) {\n\t\tmenuItems.custom = { label: LABELS.custom, icon: ICONS.custom };\n\t}\n\n\treturn menuItems;\n}\n\n/**\n * Checks if the supported sides are balanced for each axis.\n * - Horizontal - both left and right sides are supported.\n * - Vertical - both top and bottom are supported.\n *\n * @param {Array} sides The supported sides which may be axes as well.\n *\n * @return {boolean} Whether or not the supported sides are balanced.\n */\nexport function hasBalancedSidesSupport( sides = [] ) {\n\tconst counts = { top: 0, right: 0, bottom: 0, left: 0 };\n\tsides.forEach( ( side ) => ( counts[ side ] += 1 ) );\n\n\treturn (\n\t\t( counts.top + counts.bottom ) % 2 === 0 &&\n\t\t( counts.left + counts.right ) % 2 === 0\n\t);\n}\n\n/**\n * Determines which view the SpacingSizesControl should default to on its\n * first render; Axial, Custom, or Single side.\n *\n * @param {Object} values Current side values.\n * @param {Array} sides Supported sides.\n *\n * @return {string} View to display.\n */\nexport function getInitialView( values = {}, sides ) {\n\tconst { top, right, bottom, left } = values;\n\tconst sideValues = [ top, right, bottom, left ].filter( Boolean );\n\n\t// Axial ( Horizontal & vertical ).\n\t// - Has axial side support\n\t// - Has axial side values which match\n\t// - Has no values and the supported sides are balanced\n\tconst hasMatchingAxialValues =\n\t\ttop === bottom && left === right && ( !! top || !! left );\n\tconst hasNoValuesAndBalancedSides =\n\t\t! sideValues.length && hasBalancedSidesSupport( sides );\n\n\tif (\n\t\thasAxisSupport( sides ) &&\n\t\t( hasMatchingAxialValues || hasNoValuesAndBalancedSides )\n\t) {\n\t\treturn VIEWS.axial;\n\t}\n\n\t// Single side.\n\t// - Ensure the side returned is the first side that has a value.\n\tif ( sideValues.length === 1 ) {\n\t\tlet side;\n\n\t\tObject.entries( values ).some( ( [ key, value ] ) => {\n\t\t\tside = key;\n\t\t\treturn value !== undefined;\n\t\t} );\n\n\t\treturn side;\n\t}\n\n\t// Only single side supported and no value defined.\n\tif ( sides?.length === 1 && ! sideValues.length ) {\n\t\treturn sides[ 0 ];\n\t}\n\n\t// Default to the Custom (separated sides) view.\n\treturn VIEWS.custom;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/utils.js"],"names":["__","sidesAll","sidesAxial","sidesBottom","sidesHorizontal","sidesLeft","sidesRight","sidesTop","sidesVertical","ALL_SIDES","DEFAULT_VALUES","top","undefined","right","bottom","left","ICONS","custom","axial","horizontal","vertical","LABELS","default","mixed","VIEWS","isValueSpacingPreset","value","includes","getCustomValueFromPreset","spacingSizes","slug","getSpacingPresetSlug","spacingSize","find","size","String","getPresetValueFromCustomValue","spacingMatch","getSpacingPresetCssVar","match","getSliderValueFromPreset","presetValue","parseFloat","sliderValue","findIndex","NaN","mode","arr","sort","a","b","filter","v","length","pop","getAllRawValue","values","Object","isValuesMixed","sides","Set","isValuesDefined","hasAxisSupport","axis","hasHorizontalSupport","hasVerticalSupport","getSupportedMenuItems","menuItems","label","icon","numberOfIndividualSides","forEach","side","hasBalancedSidesSupport","counts","getInitialView","sideValues","Boolean","hasMatchingAxialValues","hasNoValuesAndBalancedSides","entries","some","key"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SACCC,QADD,EAECC,UAFD,EAGCC,WAHD,EAICC,eAJD,EAKCC,SALD,EAMCC,UAND,EAOCC,QAPD,EAQCC,aARD,QASO,kBATP;AAWA,OAAO,MAAMC,SAAS,GAAG,CAAE,KAAF,EAAS,OAAT,EAAkB,QAAlB,EAA4B,MAA5B,CAAlB;AAEP,OAAO,MAAMC,cAAc,GAAG;AAC7BC,EAAAA,GAAG,EAAEC,SADwB;AAE7BC,EAAAA,KAAK,EAAED,SAFsB;AAG7BE,EAAAA,MAAM,EAAEF,SAHqB;AAI7BG,EAAAA,IAAI,EAAEH;AAJuB,CAAvB;AAOP,OAAO,MAAMI,KAAK,GAAG;AACpBC,EAAAA,MAAM,EAAEhB,QADY;AAEpBiB,EAAAA,KAAK,EAAEhB,UAFa;AAGpBiB,EAAAA,UAAU,EAAEf,eAHQ;AAIpBgB,EAAAA,QAAQ,EAAEZ,aAJU;AAKpBG,EAAAA,GAAG,EAAEJ,QALe;AAMpBM,EAAAA,KAAK,EAAEP,UANa;AAOpBQ,EAAAA,MAAM,EAAEX,WAPY;AAQpBY,EAAAA,IAAI,EAAEV;AARc,CAAd;AAWP,OAAO,MAAMgB,MAAM,GAAG;AACrBC,EAAAA,OAAO,EAAEtB,EAAE,CAAE,iBAAF,CADU;AAErBW,EAAAA,GAAG,EAAEX,EAAE,CAAE,KAAF,CAFc;AAGrBc,EAAAA,MAAM,EAAEd,EAAE,C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AAC,CAAEF,GAAH,IAAU,CAAC,CAAEI,IAAnD,CADD;AAEA,QAAMgE,2BAA2B,GAChC,CAAEH,UAAU,CAACvB,MAAb,IAAuBoB,uBAAuB,CAAEd,KAAF,CAD/C;;AAGA,MACCG,cAAc,CAAEH,KAAF,CAAd,KACEmB,sBAAsB,IAAIC,2BAD5B,CADD,EAGE;AACD,WAAOvD,KAAK,CAACN,KAAb;AACA,GAlBmD,CAoBpD;AACA;;;AACA,MAAK0D,UAAU,CAACvB,MAAX,KAAsB,CAA3B,EAA+B;AAC9B,QAAImB,IAAJ;AAEAf,IAAAA,MAAM,CAACuB,OAAP,CAAgBxB,MAAhB,EAAyByB,IAAzB,CAA+B,CAAE,CAAEC,GAAF,EAAOxD,KAAP,CAAF,KAAsB;AACpD8C,MAAAA,IAAI,GAAGU,GAAP;AACA,aAAOxD,KAAK,KAAKd,SAAjB;AACA,KAHD;AAKA,WAAO4D,IAAP;AACA,GA/BmD,CAiCpD;;;AACA,MAAKb,KAAK,EAAEN,MAAP,KAAkB,CAAlB,IAAuB,CAAEuB,UAAU,CAACvB,MAAzC,EAAkD;AACjD,WAAOM,KAAK,CAAE,CAAF,CAAZ;AACA,GApCmD,CAsCpD;;;AACA,SAAOnC,KAAK,CAACP,MAAb;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tsidesAll,\n\tsidesAxial,\n\tsidesBottom,\n\tsidesHorizontal,\n\tsidesLeft,\n\tsidesRight,\n\tsidesTop,\n\tsidesVertical,\n} from '@wordpress/icons';\n\nexport const ALL_SIDES = [ 'top', 'right', 'bottom', 'left' ];\n\nexport const DEFAULT_VALUES = {\n\ttop: undefined,\n\tright: undefined,\n\tbottom: undefined,\n\tleft: undefined,\n};\n\nexport const ICONS = {\n\tcustom: sidesAll,\n\taxial: sidesAxial,\n\thorizontal: sidesHorizontal,\n\tvertical: sidesVertical,\n\ttop: sidesTop,\n\tright: sidesRight,\n\tbottom: sidesBottom,\n\tleft: sidesLeft,\n};\n\nexport const LABELS = {\n\tdefault: __( 'Spacing control' ),\n\ttop: __( 'Top' ),\n\tbottom: __( 'Bottom' ),\n\tleft: __( 'Left' ),\n\tright: __( 'Right' ),\n\tmixed: __( 'Mixed' ),\n\tvertical: __( 'Vertical' ),\n\thorizontal: __( 'Horizontal' ),\n\taxial: __( 'Horizontal & vertical' ),\n\tcustom: __( 'Custom' ),\n};\n\nexport const VIEWS = {\n\taxial: 'axial',\n\ttop: 'top',\n\tright: 'right',\n\tbottom: 'bottom',\n\tleft: 'left',\n\tcustom: 'custom',\n};\n\n/**\n * Checks is given value is a spacing preset.\n *\n * @param {string} value Value to check\n *\n * @return {boolean} Return true if value is string in format var:preset|spacing|.\n */\nexport function isValueSpacingPreset( value ) {\n\tif ( ! value?.includes ) {\n\t\treturn false;\n\t}\n\treturn value === '0' || value.includes( 'var:preset|spacing|' );\n}\n\n/**\n * Converts a spacing preset into a custom value.\n *\n * @param {string} value Value to convert\n * @param {Array} spacingSizes Array of the current spacing preset objects\n *\n * @return {string} Mapping of the spacing preset to its equivalent custom value.\n */\nexport function getCustomValueFromPreset( value, spacingSizes ) {\n\tif ( ! isValueSpacingPreset( value ) ) {\n\t\treturn value;\n\t}\n\n\tconst slug = getSpacingPresetSlug( value );\n\tconst spacingSize = spacingSizes.find(\n\t\t( size ) => String( size.slug ) === slug\n\t);\n\n\treturn spacingSize?.size;\n}\n\n/**\n * Converts a custom value to preset value if one can be found.\n *\n * Returns value as-is if no match is found.\n *\n * @param {string} value Value to convert\n * @param {Array} spacingSizes Array of the current spacing preset objects\n *\n * @return {string} The preset value if it can be found.\n */\nexport function getPresetValueFromCustomValue( value, spacingSizes ) {\n\t// Return value as-is if it is already a preset;\n\tif ( isValueSpacingPreset( value ) || value === '0' ) {\n\t\treturn value;\n\t}\n\n\tconst spacingMatch = spacingSizes.find(\n\t\t( size ) => String( size.size ) === String( value )\n\t);\n\n\tif ( spacingMatch?.slug ) {\n\t\treturn `var:preset|spacing|${ spacingMatch.slug }`;\n\t}\n\n\treturn value;\n}\n\n/**\n * Converts a spacing preset into a custom value.\n *\n * @param {string} value Value to convert.\n *\n * @return {string | undefined} CSS var string for given spacing preset value.\n */\nexport function getSpacingPresetCssVar( value ) {\n\tif ( ! value ) {\n\t\treturn;\n\t}\n\n\tconst slug = value.match( /var:preset\\|spacing\\|(.+)/ );\n\n\tif ( ! slug ) {\n\t\treturn value;\n\t}\n\n\treturn `var(--wp--preset--spacing--${ slug[ 1 ] })`;\n}\n\n/**\n * Returns the slug section of the given spacing preset string.\n *\n * @param {string} value Value to extract slug from.\n *\n * @return {string|undefined} The int value of the slug from given spacing preset.\n */\nexport function getSpacingPresetSlug( value ) {\n\tif ( ! value ) {\n\t\treturn;\n\t}\n\n\tif ( value === '0' || value === 'default' ) {\n\t\treturn value;\n\t}\n\n\tconst slug = value.match( /var:preset\\|spacing\\|(.+)/ );\n\n\treturn slug ? slug[ 1 ] : undefined;\n}\n\n/**\n * Converts spacing preset value into a Range component value .\n *\n * @param {string} presetValue Value to convert to Range value.\n * @param {Array} spacingSizes Array of current spacing preset value objects.\n *\n * @return {number} The int value for use in Range control.\n */\nexport function getSliderValueFromPreset( presetValue, spacingSizes ) {\n\tif ( presetValue === undefined ) {\n\t\treturn 0;\n\t}\n\tconst slug =\n\t\tparseFloat( presetValue, 10 ) === 0\n\t\t\t? '0'\n\t\t\t: getSpacingPresetSlug( presetValue );\n\tconst sliderValue = spacingSizes.findIndex( ( spacingSize ) => {\n\t\treturn String( spacingSize.slug ) === slug;\n\t} );\n\n\t// Returning NaN rather than undefined as undefined makes range control thumb sit in center\n\treturn sliderValue !== -1 ? sliderValue : NaN;\n}\n\n/**\n * Gets an items with the most occurrence within an array\n * https://stackoverflow.com/a/20762713\n *\n * @param {Array<any>} arr Array of items to check.\n * @return {any} The item with the most occurrences.\n */\nfunction mode( arr ) {\n\treturn arr\n\t\t.sort(\n\t\t\t( a, b ) =>\n\t\t\t\tarr.filter( ( v ) => v === a ).length -\n\t\t\t\tarr.filter( ( v ) => v === b ).length\n\t\t)\n\t\t.pop();\n}\n\n/**\n * Gets the 'all' input value from values data.\n *\n * @param {Object} values Box spacing values\n *\n * @return {string} The most common value from all sides of box.\n */\nexport function getAllRawValue( values = {} ) {\n\treturn mode( Object.values( values ) );\n}\n\n/**\n * Checks to determine if values are mixed.\n *\n * @param {Object} values Box values.\n * @param {Array} sides Sides that values relate to.\n *\n * @return {boolean} Whether values are mixed.\n */\nexport function isValuesMixed( values = {}, sides = ALL_SIDES ) {\n\treturn (\n\t\t( Object.values( values ).length >= 1 &&\n\t\t\tObject.values( values ).length < sides.length ) ||\n\t\tnew Set( Object.values( values ) ).size > 1\n\t);\n}\n\n/**\n * Checks to determine if values are defined.\n *\n * @param {Object} values Box values.\n *\n * @return {boolean} Whether values are defined.\n */\nexport function isValuesDefined( values ) {\n\tif ( values === undefined || values === null ) {\n\t\treturn false;\n\t}\n\treturn Object.values( values ).filter( ( value ) => !! value ).length > 0;\n}\n\n/**\n * Determines whether a particular axis has support. If no axis is\n * specified, this function checks if either axis is supported.\n *\n * @param {Array} sides Supported sides.\n * @param {string} axis Which axis to check.\n *\n * @return {boolean} Whether there is support for the specified axis or both axes.\n */\nexport function hasAxisSupport( sides, axis ) {\n\tif ( ! sides || ! sides.length ) {\n\t\treturn false;\n\t}\n\n\tconst hasHorizontalSupport =\n\t\tsides.includes( 'horizontal' ) ||\n\t\t( sides.includes( 'left' ) && sides.includes( 'right' ) );\n\n\tconst hasVerticalSupport =\n\t\tsides.includes( 'vertical' ) ||\n\t\t( sides.includes( 'top' ) && sides.includes( 'bottom' ) );\n\n\tif ( axis === 'horizontal' ) {\n\t\treturn hasHorizontalSupport;\n\t}\n\n\tif ( axis === 'vertical' ) {\n\t\treturn hasVerticalSupport;\n\t}\n\n\treturn hasHorizontalSupport || hasVerticalSupport;\n}\n\n/**\n * Determines which menu options should be included in the SidePicker.\n *\n * @param {Array} sides Supported sides.\n *\n * @return {Object} Menu options with each option containing label & icon.\n */\nexport function getSupportedMenuItems( sides ) {\n\tif ( ! sides || ! sides.length ) {\n\t\treturn {};\n\t}\n\n\tconst menuItems = {};\n\n\t// Determine the primary \"side\" menu options.\n\tconst hasHorizontalSupport = hasAxisSupport( sides, 'horizontal' );\n\tconst hasVerticalSupport = hasAxisSupport( sides, 'vertical' );\n\n\tif ( hasHorizontalSupport && hasVerticalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.axial, icon: ICONS.axial };\n\t} else if ( hasHorizontalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.horizontal, icon: ICONS.horizontal };\n\t} else if ( hasVerticalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.vertical, icon: ICONS.vertical };\n\t}\n\n\t// Track whether we have any individual sides so we can omit the custom\n\t// option if required.\n\tlet numberOfIndividualSides = 0;\n\n\tALL_SIDES.forEach( ( side ) => {\n\t\tif ( sides.includes( side ) ) {\n\t\t\tnumberOfIndividualSides += 1;\n\t\t\tmenuItems[ side ] = {\n\t\t\t\tlabel: LABELS[ side ],\n\t\t\t\ticon: ICONS[ side ],\n\t\t\t};\n\t\t}\n\t} );\n\n\t// Add custom item if there are enough sides to warrant a separated view.\n\tif ( numberOfIndividualSides > 1 ) {\n\t\tmenuItems.custom = { label: LABELS.custom, icon: ICONS.custom };\n\t}\n\n\treturn menuItems;\n}\n\n/**\n * Checks if the supported sides are balanced for each axis.\n * - Horizontal - both left and right sides are supported.\n * - Vertical - both top and bottom are supported.\n *\n * @param {Array} sides The supported sides which may be axes as well.\n *\n * @return {boolean} Whether or not the supported sides are balanced.\n */\nexport function hasBalancedSidesSupport( sides = [] ) {\n\tconst counts = { top: 0, right: 0, bottom: 0, left: 0 };\n\tsides.forEach( ( side ) => ( counts[ side ] += 1 ) );\n\n\treturn (\n\t\t( counts.top + counts.bottom ) % 2 === 0 &&\n\t\t( counts.left + counts.right ) % 2 === 0\n\t);\n}\n\n/**\n * Determines which view the SpacingSizesControl should default to on its\n * first render; Axial, Custom, or Single side.\n *\n * @param {Object} values Current side values.\n * @param {Array} sides Supported sides.\n *\n * @return {string} View to display.\n */\nexport function getInitialView( values = {}, sides ) {\n\tconst { top, right, bottom, left } = values;\n\tconst sideValues = [ top, right, bottom, left ].filter( Boolean );\n\n\t// Axial ( Horizontal & vertical ).\n\t// - Has axial side support\n\t// - Has axial side values which match\n\t// - Has no values and the supported sides are balanced\n\tconst hasMatchingAxialValues =\n\t\ttop === bottom && left === right && ( !! top || !! left );\n\tconst hasNoValuesAndBalancedSides =\n\t\t! sideValues.length && hasBalancedSidesSupport( sides );\n\n\tif (\n\t\thasAxisSupport( sides ) &&\n\t\t( hasMatchingAxialValues || hasNoValuesAndBalancedSides )\n\t) {\n\t\treturn VIEWS.axial;\n\t}\n\n\t// Single side.\n\t// - Ensure the side returned is the first side that has a value.\n\tif ( sideValues.length === 1 ) {\n\t\tlet side;\n\n\t\tObject.entries( values ).some( ( [ key, value ] ) => {\n\t\t\tside = key;\n\t\t\treturn value !== undefined;\n\t\t} );\n\n\t\treturn side;\n\t}\n\n\t// Only single side supported and no value defined.\n\tif ( sides?.length === 1 && ! sideValues.length ) {\n\t\treturn sides[ 0 ];\n\t}\n\n\t// Default to the Custom (separated sides) view.\n\treturn VIEWS.custom;\n}\n"]}
|