@wordpress/block-editor 11.3.6 → 11.5.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 +3 -1
- package/build/components/block-lock/modal.js +1 -0
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-popover/inbetween.js +10 -33
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +2 -2
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-styles/index.js +2 -1
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-types-list/index.native.js +2 -0
- package/build/components/block-types-list/index.native.js.map +1 -1
- package/build/components/child-layout-control/index.js +107 -0
- package/build/components/child-layout-control/index.js.map +1 -0
- package/build/components/colors-gradients/control.js +6 -3
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/date-format-picker/index.js +3 -3
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/font-appearance-control/index.js +0 -3
- package/build/components/font-appearance-control/index.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +594 -0
- package/build/components/global-styles/dimensions-panel.js.map +1 -0
- package/build/components/global-styles/hooks.js +142 -45
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +38 -0
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +434 -0
- package/build/components/global-styles/typography-panel.js.map +1 -0
- package/build/components/global-styles/use-global-styles-output.js +7 -3
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +2 -0
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/iframe/index.js +17 -11
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/image-editor/aspect-ratio-dropdown.js +2 -1
- package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build/components/image-size-control/index.js +6 -11
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/index.native.js +23 -0
- package/build/components/index.native.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +9 -15
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/block-types-tab.native.js +4 -1
- package/build/components/inserter/block-types-tab.native.js.map +1 -1
- package/build/components/inserter/reusable-blocks-tab.native.js +4 -1
- package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build/components/inserter/search-results.native.js +4 -1
- package/build/components/inserter/search-results.native.js.map +1 -1
- package/build/components/inspector-controls/block-support-tools-panel.js +1 -1
- package/build/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build/components/inspector-controls/fill.js +38 -9
- package/build/components/inspector-controls/fill.js.map +1 -1
- package/build/components/link-control/index.js +55 -28
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/settings-drawer.js +72 -30
- package/build/components/link-control/settings-drawer.js.map +1 -1
- package/build/components/link-control/settings.js +53 -0
- package/build/components/link-control/settings.js.map +1 -0
- package/build/components/list-view/block.js +4 -2
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/expander.js +2 -1
- package/build/components/list-view/expander.js.map +1 -1
- package/build/components/list-view/index.js +6 -1
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/off-canvas-editor/appender.js +5 -10
- package/build/components/off-canvas-editor/appender.js.map +1 -1
- package/build/components/off-canvas-editor/block-contents.js +3 -2
- package/build/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build/components/off-canvas-editor/branch.js +1 -0
- package/build/components/off-canvas-editor/branch.js.map +1 -1
- package/build/components/off-canvas-editor/index.js +7 -3
- package/build/components/off-canvas-editor/index.js.map +1 -1
- package/build/components/off-canvas-editor/leaf-more-menu.js +24 -4
- package/build/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
- package/build/components/off-canvas-editor/link-ui.js +2 -0
- package/build/components/off-canvas-editor/link-ui.js.map +1 -1
- package/build/components/responsive-block-control/index.js +1 -0
- package/build/components/responsive-block-control/index.js.map +1 -1
- package/build/components/rich-text/index.js +9 -45
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/use-delete.js +73 -0
- package/build/components/rich-text/use-delete.js.map +1 -0
- package/build/components/rich-text/use-input-rules.js +14 -6
- package/build/components/rich-text/use-input-rules.js.map +1 -1
- package/build/components/url-input/index.js +2 -2
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/writing-flow/use-selection-observer.js +4 -1
- package/build/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build/hooks/align.js +3 -1
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/dimensions.js +78 -190
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/duotone.js +94 -25
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/font-family.js +2 -76
- package/build/hooks/font-family.js.map +1 -1
- package/build/hooks/font-size.js +3 -51
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/gap.js +0 -201
- package/build/hooks/gap.js.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/layout.js +14 -5
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/line-height.js +0 -42
- package/build/hooks/line-height.js.map +1 -1
- package/build/hooks/margin.js +7 -163
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +7 -163
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/typography.js +98 -128
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/utils.js +75 -0
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/flex.js +1 -0
- package/build/layouts/flex.js.map +1 -1
- package/build/store/actions.js +24 -12
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +53 -47
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +22 -1
- package/build/store/selectors.js.map +1 -1
- package/build/utils/parse-css-unit-to-px.js +36 -3
- package/build/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-module/components/block-lock/modal.js +1 -0
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +10 -33
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +2 -2
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-styles/index.js +2 -1
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-types-list/index.native.js +2 -0
- package/build-module/components/block-types-list/index.native.js.map +1 -1
- package/build-module/components/child-layout-control/index.js +98 -0
- package/build-module/components/child-layout-control/index.js.map +1 -0
- package/build-module/components/colors-gradients/control.js +6 -3
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/date-format-picker/index.js +4 -4
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/font-appearance-control/index.js +2 -1
- package/build-module/components/font-appearance-control/index.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +574 -0
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -0
- package/build-module/components/global-styles/hooks.js +138 -46
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/index.js +3 -1
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +415 -0
- package/build-module/components/global-styles/typography-panel.js.map +1 -0
- package/build-module/components/global-styles/use-global-styles-output.js +7 -3
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +2 -0
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/iframe/index.js +17 -11
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/image-editor/aspect-ratio-dropdown.js +2 -1
- package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build-module/components/image-size-control/index.js +7 -12
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/index.native.js +2 -1
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +9 -15
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/block-types-tab.native.js +3 -1
- package/build-module/components/inserter/block-types-tab.native.js.map +1 -1
- package/build-module/components/inserter/reusable-blocks-tab.native.js +3 -1
- package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build-module/components/inserter/search-results.native.js +3 -1
- package/build-module/components/inserter/search-results.native.js.map +1 -1
- package/build-module/components/inspector-controls/block-support-tools-panel.js +1 -1
- package/build-module/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build-module/components/inspector-controls/fill.js +39 -9
- package/build-module/components/inspector-controls/fill.js.map +1 -1
- package/build-module/components/link-control/index.js +56 -28
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/settings-drawer.js +68 -30
- package/build-module/components/link-control/settings-drawer.js.map +1 -1
- package/build-module/components/link-control/settings.js +44 -0
- package/build-module/components/link-control/settings.js.map +1 -0
- package/build-module/components/list-view/block.js +4 -2
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/expander.js +2 -1
- package/build-module/components/list-view/expander.js.map +1 -1
- package/build-module/components/list-view/index.js +6 -1
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/off-canvas-editor/appender.js +5 -10
- package/build-module/components/off-canvas-editor/appender.js.map +1 -1
- package/build-module/components/off-canvas-editor/block-contents.js +3 -2
- package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build-module/components/off-canvas-editor/branch.js +1 -0
- package/build-module/components/off-canvas-editor/branch.js.map +1 -1
- package/build-module/components/off-canvas-editor/index.js +7 -3
- package/build-module/components/off-canvas-editor/index.js.map +1 -1
- package/build-module/components/off-canvas-editor/leaf-more-menu.js +27 -7
- package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
- package/build-module/components/off-canvas-editor/link-ui.js +2 -0
- package/build-module/components/off-canvas-editor/link-ui.js.map +1 -1
- package/build-module/components/responsive-block-control/index.js +1 -0
- package/build-module/components/responsive-block-control/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +9 -45
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/use-delete.js +62 -0
- package/build-module/components/rich-text/use-delete.js.map +1 -0
- package/build-module/components/rich-text/use-input-rules.js +14 -6
- package/build-module/components/rich-text/use-input-rules.js.map +1 -1
- package/build-module/components/url-input/index.js +2 -2
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/writing-flow/use-selection-observer.js +4 -1
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build-module/hooks/align.js +3 -1
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/dimensions.js +81 -187
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/duotone.js +86 -24
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/font-family.js +3 -69
- package/build-module/hooks/font-family.js.map +1 -1
- package/build-module/hooks/font-size.js +6 -47
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/gap.js +0 -182
- package/build-module/hooks/gap.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/layout.js +14 -5
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/line-height.js +0 -38
- package/build-module/hooks/line-height.js.map +1 -1
- package/build-module/hooks/margin.js +4 -143
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +4 -143
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/typography.js +97 -123
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/utils.js +70 -0
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/flex.js +1 -0
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/store/actions.js +24 -12
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +53 -45
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +22 -1
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/parse-css-unit-to-px.js +36 -3
- package/build-module/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-style/style-rtl.css +54 -64
- package/build-style/style.css +54 -64
- package/package.json +31 -31
- package/src/components/block-draggable/test/__snapshots__/index.native.js.snap +24 -24
- package/src/components/block-lock/modal.js +1 -0
- package/src/components/block-lock/style.scss +0 -9
- package/src/components/block-mobile-toolbar/test/__snapshots__/block-actions-menu.native.js.snap +20 -20
- package/src/components/block-mover/test/__snapshots__/index.native.js.snap +15 -15
- package/src/components/block-popover/inbetween.js +21 -53
- package/src/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/src/components/block-styles/index.js +5 -1
- package/src/components/block-types-list/index.native.js +2 -0
- package/src/components/child-layout-control/index.js +106 -0
- package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
- package/src/components/colors-gradients/control.js +3 -0
- package/src/components/date-format-picker/index.js +6 -8
- package/src/components/date-format-picker/style.scss +0 -5
- package/src/components/font-appearance-control/index.js +1 -1
- package/src/components/global-styles/dimensions-panel.js +627 -0
- package/src/components/global-styles/hooks.js +229 -66
- package/src/components/global-styles/index.js +9 -0
- package/src/components/global-styles/typography-panel.js +428 -0
- package/src/components/global-styles/use-global-styles-output.js +10 -5
- package/src/components/global-styles/utils.js +2 -0
- package/src/components/iframe/index.js +20 -18
- package/src/components/image-editor/aspect-ratio-dropdown.js +1 -0
- package/src/components/image-size-control/index.js +10 -12
- package/src/components/image-size-control/style.scss +3 -21
- package/src/components/index.native.js +5 -0
- package/src/components/inner-blocks/test/__snapshots__/index.js.snap +1 -1
- package/src/components/inserter/block-patterns-tab.js +9 -23
- package/src/components/inserter/block-types-tab.native.js +2 -0
- package/src/components/inserter/reusable-blocks-tab.native.js +2 -0
- package/src/components/inserter/search-results.native.js +2 -0
- package/src/components/inserter/test/__snapshots__/index.native.js.snap +15 -15
- package/src/components/inspector-controls/block-support-tools-panel.js +0 -1
- package/src/components/inspector-controls/fill.js +32 -8
- package/src/components/link-control/index.js +69 -34
- package/src/components/link-control/settings-drawer.js +85 -29
- package/src/components/link-control/settings.js +42 -0
- package/src/components/link-control/style.scss +63 -37
- package/src/components/link-control/test/index.js +347 -9
- package/src/components/list-view/block.js +7 -1
- package/src/components/list-view/expander.js +1 -0
- package/src/components/list-view/index.js +5 -0
- package/src/components/media-replace-flow/style.scss +7 -9
- package/src/components/media-replace-flow/test/index.js +1 -1
- package/src/components/off-canvas-editor/appender.js +13 -16
- package/src/components/off-canvas-editor/block-contents.js +2 -1
- package/src/components/off-canvas-editor/branch.js +1 -0
- package/src/components/off-canvas-editor/index.js +8 -2
- package/src/components/off-canvas-editor/leaf-more-menu.js +52 -15
- package/src/components/off-canvas-editor/link-ui.js +2 -0
- package/src/components/responsive-block-control/index.js +1 -0
- package/src/components/rich-text/index.js +8 -46
- package/src/components/rich-text/use-delete.js +59 -0
- package/src/components/rich-text/use-input-rules.js +13 -5
- package/src/components/url-input/index.js +3 -2
- package/src/components/url-popover/stories/index.js +1 -0
- package/src/components/writing-flow/use-selection-observer.js +5 -1
- package/src/hooks/align.js +1 -1
- package/src/hooks/dimensions.js +97 -269
- package/src/hooks/duotone.js +100 -30
- package/src/hooks/font-family.js +0 -58
- package/src/hooks/font-size.js +1 -36
- package/src/hooks/gap.js +0 -201
- package/src/hooks/index.js +1 -0
- package/src/hooks/layout.js +19 -6
- package/src/hooks/line-height.js +0 -33
- package/src/hooks/margin.js +1 -164
- package/src/hooks/padding.js +1 -163
- package/src/hooks/test/__snapshots__/align.native.js.snap +24 -24
- package/src/hooks/test/duotone.js +102 -0
- package/src/hooks/typography.js +112 -213
- package/src/hooks/utils.js +90 -0
- package/src/layouts/flex.js +1 -0
- package/src/store/actions.js +12 -4
- package/src/store/reducer.js +68 -43
- package/src/store/selectors.js +20 -1
- package/src/store/test/actions.js +4 -2
- package/src/utils/parse-css-unit-to-px.js +35 -5
- package/src/utils/test/parse-css-unit-to-px.js +12 -0
- package/build/hooks/child-layout.js +0 -213
- package/build/hooks/child-layout.js.map +0 -1
- package/build/hooks/font-appearance.js +0 -188
- package/build/hooks/font-appearance.js.map +0 -1
- package/build/hooks/letter-spacing.js +0 -129
- package/build/hooks/letter-spacing.js.map +0 -1
- package/build/hooks/min-height.js +0 -139
- package/build/hooks/min-height.js.map +0 -1
- package/build/hooks/text-decoration.js +0 -130
- package/build/hooks/text-decoration.js.map +0 -1
- package/build/hooks/text-transform.js +0 -130
- package/build/hooks/text-transform.js.map +0 -1
- package/build-module/hooks/child-layout.js +0 -193
- package/build-module/hooks/child-layout.js.map +0 -1
- package/build-module/hooks/font-appearance.js +0 -161
- package/build-module/hooks/font-appearance.js.map +0 -1
- package/build-module/hooks/letter-spacing.js +0 -107
- package/build-module/hooks/letter-spacing.js.map +0 -1
- package/build-module/hooks/min-height.js +0 -116
- package/build-module/hooks/min-height.js.map +0 -1
- package/build-module/hooks/text-decoration.js +0 -108
- package/build-module/hooks/text-decoration.js.map +0 -1
- package/build-module/hooks/text-transform.js +0 -108
- package/build-module/hooks/text-transform.js.map +0 -1
- package/src/hooks/child-layout.js +0 -195
- package/src/hooks/font-appearance.js +0 -146
- package/src/hooks/letter-spacing.js +0 -101
- package/src/hooks/min-height.js +0 -104
- package/src/hooks/text-decoration.js +0 -102
- package/src/hooks/text-transform.js +0 -101
package/src/store/actions.js
CHANGED
|
@@ -232,17 +232,24 @@ export function selectBlock( clientId, initialPosition = 0 ) {
|
|
|
232
232
|
|
|
233
233
|
/**
|
|
234
234
|
* Yields action objects used in signalling that the block preceding the given
|
|
235
|
-
* clientId
|
|
235
|
+
* clientId (or optionally, its first parent from bottom to top)
|
|
236
|
+
* should be selected.
|
|
236
237
|
*
|
|
237
|
-
* @param {string}
|
|
238
|
+
* @param {string} clientId Block client ID.
|
|
239
|
+
* @param {boolean} orFirstParent If true, select the first parent if there is no previous block.
|
|
238
240
|
*/
|
|
239
241
|
export const selectPreviousBlock =
|
|
240
|
-
( clientId ) =>
|
|
242
|
+
( clientId, orFirstParent = false ) =>
|
|
241
243
|
( { select, dispatch } ) => {
|
|
242
244
|
const previousBlockClientId =
|
|
243
245
|
select.getPreviousBlockClientId( clientId );
|
|
244
246
|
if ( previousBlockClientId ) {
|
|
245
247
|
dispatch.selectBlock( previousBlockClientId, -1 );
|
|
248
|
+
} else if ( orFirstParent ) {
|
|
249
|
+
const firstParentClientId = select.getBlockRootClientId( clientId );
|
|
250
|
+
if ( firstParentClientId ) {
|
|
251
|
+
dispatch.selectBlock( firstParentClientId, -1 );
|
|
252
|
+
}
|
|
246
253
|
}
|
|
247
254
|
};
|
|
248
255
|
|
|
@@ -1197,7 +1204,8 @@ export const removeBlocks =
|
|
|
1197
1204
|
}
|
|
1198
1205
|
|
|
1199
1206
|
if ( selectPrevious ) {
|
|
1200
|
-
|
|
1207
|
+
const shouldSelectParent = true;
|
|
1208
|
+
dispatch.selectPreviousBlock( clientIds[ 0 ], shouldSelectParent );
|
|
1201
1209
|
}
|
|
1202
1210
|
|
|
1203
1211
|
dispatch( { type: 'REMOVE_BLOCKS', clientIds } );
|
package/src/store/reducer.js
CHANGED
|
@@ -1416,9 +1416,19 @@ export function selection( state = {}, action ) {
|
|
|
1416
1416
|
}
|
|
1417
1417
|
}
|
|
1418
1418
|
|
|
1419
|
+
const selectionStart = selectionHelper( state.selectionStart, action );
|
|
1420
|
+
const selectionEnd = selectionHelper( state.selectionEnd, action );
|
|
1421
|
+
|
|
1422
|
+
if (
|
|
1423
|
+
selectionStart === state.selectionStart &&
|
|
1424
|
+
selectionEnd === state.selectionEnd
|
|
1425
|
+
) {
|
|
1426
|
+
return state;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1419
1429
|
return {
|
|
1420
|
-
selectionStart
|
|
1421
|
-
selectionEnd
|
|
1430
|
+
selectionStart,
|
|
1431
|
+
selectionEnd,
|
|
1422
1432
|
};
|
|
1423
1433
|
}
|
|
1424
1434
|
|
|
@@ -1750,45 +1760,6 @@ export function lastBlockAttributesChange( state = null, action ) {
|
|
|
1750
1760
|
return state;
|
|
1751
1761
|
}
|
|
1752
1762
|
|
|
1753
|
-
/**
|
|
1754
|
-
* Reducer returning automatic change state.
|
|
1755
|
-
*
|
|
1756
|
-
* @param {?string} state Current state.
|
|
1757
|
-
* @param {Object} action Dispatched action.
|
|
1758
|
-
*
|
|
1759
|
-
* @return {string | undefined} Updated state.
|
|
1760
|
-
*/
|
|
1761
|
-
export function automaticChangeStatus( state, action ) {
|
|
1762
|
-
switch ( action.type ) {
|
|
1763
|
-
case 'MARK_AUTOMATIC_CHANGE':
|
|
1764
|
-
return 'pending';
|
|
1765
|
-
case 'MARK_AUTOMATIC_CHANGE_FINAL':
|
|
1766
|
-
if ( state === 'pending' ) {
|
|
1767
|
-
return 'final';
|
|
1768
|
-
}
|
|
1769
|
-
|
|
1770
|
-
return;
|
|
1771
|
-
case 'SELECTION_CHANGE':
|
|
1772
|
-
// As long as the state is not final, ignore any selection changes.
|
|
1773
|
-
if ( state !== 'final' ) {
|
|
1774
|
-
return state;
|
|
1775
|
-
}
|
|
1776
|
-
|
|
1777
|
-
return;
|
|
1778
|
-
// Undoing an automatic change should still be possible after mouse
|
|
1779
|
-
// move or after visibility change.
|
|
1780
|
-
case 'SET_BLOCK_VISIBILITY':
|
|
1781
|
-
case 'START_TYPING':
|
|
1782
|
-
case 'STOP_TYPING':
|
|
1783
|
-
case 'UPDATE_BLOCK_LIST_SETTINGS':
|
|
1784
|
-
return state;
|
|
1785
|
-
}
|
|
1786
|
-
|
|
1787
|
-
// TODO: This is a source of bug, as each time there's a change in timing,
|
|
1788
|
-
// or a new action is added, this could break.
|
|
1789
|
-
// Reset the state by default (for any action not handled).
|
|
1790
|
-
}
|
|
1791
|
-
|
|
1792
1763
|
/**
|
|
1793
1764
|
* Reducer returning current highlighted block.
|
|
1794
1765
|
*
|
|
@@ -1863,7 +1834,7 @@ export function temporarilyEditingAsBlocks( state = '', action ) {
|
|
|
1863
1834
|
return state;
|
|
1864
1835
|
}
|
|
1865
1836
|
|
|
1866
|
-
|
|
1837
|
+
const combinedReducers = combineReducers( {
|
|
1867
1838
|
blocks,
|
|
1868
1839
|
isTyping,
|
|
1869
1840
|
isBlockInterfaceHidden,
|
|
@@ -1881,9 +1852,63 @@ export default combineReducers( {
|
|
|
1881
1852
|
lastBlockAttributesChange,
|
|
1882
1853
|
editorMode,
|
|
1883
1854
|
hasBlockMovingClientId,
|
|
1884
|
-
automaticChangeStatus,
|
|
1885
1855
|
highlightedBlock,
|
|
1886
1856
|
lastBlockInserted,
|
|
1887
1857
|
temporarilyEditingAsBlocks,
|
|
1888
1858
|
blockVisibility,
|
|
1889
1859
|
} );
|
|
1860
|
+
|
|
1861
|
+
function withAutomaticChangeReset( reducer ) {
|
|
1862
|
+
return ( state, action ) => {
|
|
1863
|
+
const nextState = reducer( state, action );
|
|
1864
|
+
|
|
1865
|
+
if ( ! state ) {
|
|
1866
|
+
return nextState;
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
// Take over the last value without creating a new reference.
|
|
1870
|
+
nextState.automaticChangeStatus = state.automaticChangeStatus;
|
|
1871
|
+
|
|
1872
|
+
if ( action.type === 'MARK_AUTOMATIC_CHANGE' ) {
|
|
1873
|
+
return {
|
|
1874
|
+
...nextState,
|
|
1875
|
+
automaticChangeStatus: 'pending',
|
|
1876
|
+
};
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
if (
|
|
1880
|
+
action.type === 'MARK_AUTOMATIC_CHANGE_FINAL' &&
|
|
1881
|
+
state.automaticChangeStatus === 'pending'
|
|
1882
|
+
) {
|
|
1883
|
+
return {
|
|
1884
|
+
...nextState,
|
|
1885
|
+
automaticChangeStatus: 'final',
|
|
1886
|
+
};
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
// If there's a change that doesn't affect blocks or selection, maintain
|
|
1890
|
+
// the current status.
|
|
1891
|
+
if (
|
|
1892
|
+
nextState.blocks === state.blocks &&
|
|
1893
|
+
nextState.selection === state.selection
|
|
1894
|
+
) {
|
|
1895
|
+
return nextState;
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
// As long as the state is not final, ignore any selection changes.
|
|
1899
|
+
if (
|
|
1900
|
+
nextState.automaticChangeStatus !== 'final' &&
|
|
1901
|
+
nextState.selection !== state.selection
|
|
1902
|
+
) {
|
|
1903
|
+
return nextState;
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
// Reset the status if blocks change or selection changes (when status is final).
|
|
1907
|
+
return {
|
|
1908
|
+
...nextState,
|
|
1909
|
+
automaticChangeStatus: undefined,
|
|
1910
|
+
};
|
|
1911
|
+
};
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
export default withAutomaticChangeReset( combinedReducers );
|
package/src/store/selectors.js
CHANGED
|
@@ -55,6 +55,17 @@ const MILLISECONDS_PER_WEEK = 7 * 24 * 3600 * 1000;
|
|
|
55
55
|
*/
|
|
56
56
|
const EMPTY_ARRAY = [];
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Shared reference to an empty Set for cases where it is important to avoid
|
|
60
|
+
* returning a new Set reference on every invocation, as in a connected or
|
|
61
|
+
* other pure component which performs `shouldComponentUpdate` check on props.
|
|
62
|
+
* This should be used as a last resort, since the normalized data should be
|
|
63
|
+
* maintained by the reducer result in state.
|
|
64
|
+
*
|
|
65
|
+
* @type {Set}
|
|
66
|
+
*/
|
|
67
|
+
const EMPTY_SET = new Set();
|
|
68
|
+
|
|
58
69
|
/**
|
|
59
70
|
* Returns a block's name given its client ID, or null if no block exists with
|
|
60
71
|
* the client ID.
|
|
@@ -499,6 +510,10 @@ export const getBlockParents = createSelector(
|
|
|
499
510
|
parents.push( current );
|
|
500
511
|
}
|
|
501
512
|
|
|
513
|
+
if ( ! parents.length ) {
|
|
514
|
+
return EMPTY_ARRAY;
|
|
515
|
+
}
|
|
516
|
+
|
|
502
517
|
return ascending ? parents : parents.reverse();
|
|
503
518
|
},
|
|
504
519
|
( state ) => [ state.blocks.parents ]
|
|
@@ -2722,11 +2737,15 @@ export function isBlockVisible( state, clientId ) {
|
|
|
2722
2737
|
*/
|
|
2723
2738
|
export const __unstableGetVisibleBlocks = createSelector(
|
|
2724
2739
|
( state ) => {
|
|
2725
|
-
|
|
2740
|
+
const visibleBlocks = new Set(
|
|
2726
2741
|
Object.keys( state.blockVisibility ).filter(
|
|
2727
2742
|
( key ) => state.blockVisibility[ key ]
|
|
2728
2743
|
)
|
|
2729
2744
|
);
|
|
2745
|
+
if ( visibleBlocks.size === 0 ) {
|
|
2746
|
+
return EMPTY_SET;
|
|
2747
|
+
}
|
|
2748
|
+
return visibleBlocks;
|
|
2730
2749
|
},
|
|
2731
2750
|
( state ) => [ state.blockVisibility ]
|
|
2732
2751
|
);
|
|
@@ -625,7 +625,8 @@ describe( 'actions', () => {
|
|
|
625
625
|
removeBlocks( clientIds )( { select, dispatch } );
|
|
626
626
|
|
|
627
627
|
expect( dispatch.selectPreviousBlock ).toHaveBeenCalledWith(
|
|
628
|
-
clientId
|
|
628
|
+
clientId,
|
|
629
|
+
true
|
|
629
630
|
);
|
|
630
631
|
|
|
631
632
|
expect( dispatch ).toHaveBeenCalledWith( {
|
|
@@ -734,7 +735,8 @@ describe( 'actions', () => {
|
|
|
734
735
|
removeBlock( clientId )( { select, dispatch } );
|
|
735
736
|
|
|
736
737
|
expect( dispatch.selectPreviousBlock ).toHaveBeenCalledWith(
|
|
737
|
-
clientId
|
|
738
|
+
clientId,
|
|
739
|
+
true
|
|
738
740
|
);
|
|
739
741
|
|
|
740
742
|
expect( dispatch ).toHaveBeenCalledWith( {
|
|
@@ -24,7 +24,11 @@ function parseUnit( cssUnit ) {
|
|
|
24
24
|
* @return {number} evaluated expression.
|
|
25
25
|
*/
|
|
26
26
|
function calculate( expression ) {
|
|
27
|
-
|
|
27
|
+
try {
|
|
28
|
+
return Function( `'use strict'; return (${ expression })` )();
|
|
29
|
+
} catch ( err ) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
/**
|
|
@@ -117,9 +121,9 @@ function isMathExpression( cssUnit ) {
|
|
|
117
121
|
function evalMathExpression( cssUnit ) {
|
|
118
122
|
let errorFound = false;
|
|
119
123
|
// Convert every part of the expression to px values.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
// The following regex matches numbers that have a following unit
|
|
125
|
+
// E.g. 5.25rem, 1vw
|
|
126
|
+
const cssUnitsBits = cssUnit.match( /\d+\.?\d*[a-zA-Z]+|\.\d+[a-zA-Z]+/g );
|
|
123
127
|
for ( const unit of cssUnitsBits ) {
|
|
124
128
|
// Standardize the unit to px and extract the value.
|
|
125
129
|
const parsedUnit = parseUnit( getPxFromCssUnit( unit ) );
|
|
@@ -131,7 +135,33 @@ function evalMathExpression( cssUnit ) {
|
|
|
131
135
|
cssUnit = cssUnit.replace( unit, parsedUnit.value );
|
|
132
136
|
}
|
|
133
137
|
|
|
134
|
-
|
|
138
|
+
// For mixed math expressions wrapped within CSS expressions
|
|
139
|
+
if ( ! errorFound && cssUnit.match( /(max|min|clamp)/g ) ) {
|
|
140
|
+
const values = cssUnit.split( ',' );
|
|
141
|
+
for ( const currentValue of values ) {
|
|
142
|
+
// Check for nested calc() and remove them to calculate the value.
|
|
143
|
+
const rawCurrentValue = currentValue.replace( /\s|calc/g, '' );
|
|
144
|
+
|
|
145
|
+
if ( isMathExpression( rawCurrentValue ) ) {
|
|
146
|
+
const calculatedExpression = calculate( rawCurrentValue );
|
|
147
|
+
|
|
148
|
+
if ( calculatedExpression ) {
|
|
149
|
+
const calculatedValue =
|
|
150
|
+
calculatedExpression.toFixed( 0 ) + 'px';
|
|
151
|
+
cssUnit = cssUnit.replace( currentValue, calculatedValue );
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const parsedValue = parseUnitFunction( cssUnit );
|
|
156
|
+
return ! parsedValue ? null : parsedValue.value + parsedValue.unit;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if ( errorFound ) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const calculatedResult = calculate( cssUnit );
|
|
164
|
+
return calculatedResult ? calculatedResult.toFixed( 0 ) + 'px' : null;
|
|
135
165
|
}
|
|
136
166
|
|
|
137
167
|
/**
|
|
@@ -116,6 +116,18 @@ describe( 'getPxFromCssUnit', () => {
|
|
|
116
116
|
[ 'console.log("howdy"); + 10px', null ],
|
|
117
117
|
[ 'calc(12vw * 10px', null ], // Missing closing bracket.
|
|
118
118
|
[ 'calc( 1em + 0.875rem )', '30px' ], // Decimals
|
|
119
|
+
[
|
|
120
|
+
'clamp(1.8rem, 1.8rem + ((1vw / 0.48rem + 1rem) * 2.885), 3rem)',
|
|
121
|
+
'48px',
|
|
122
|
+
],
|
|
123
|
+
[
|
|
124
|
+
'clamp(5rem, 5.25rem + ((1vw - 0.48rem) * 9.096), 8rem)',
|
|
125
|
+
'80px',
|
|
126
|
+
],
|
|
127
|
+
[
|
|
128
|
+
'clamp(2.625rem, calc(2.625rem + ((1vw - 0.48rem) * 8.4135)), 3.25rem)',
|
|
129
|
+
'42px',
|
|
130
|
+
],
|
|
119
131
|
];
|
|
120
132
|
|
|
121
133
|
test.each( testData )( 'getPxFromCssUnit( %s )', ( unit, expected ) => {
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.ChildLayoutEdit = ChildLayoutEdit;
|
|
9
|
-
exports.childLayoutOrientation = childLayoutOrientation;
|
|
10
|
-
exports.hasChildLayoutSupport = hasChildLayoutSupport;
|
|
11
|
-
exports.hasChildLayoutValue = hasChildLayoutValue;
|
|
12
|
-
exports.resetChildLayout = resetChildLayout;
|
|
13
|
-
exports.useIsChildLayoutDisabled = useIsChildLayoutDisabled;
|
|
14
|
-
|
|
15
|
-
var _element = require("@wordpress/element");
|
|
16
|
-
|
|
17
|
-
var _components = require("@wordpress/components");
|
|
18
|
-
|
|
19
|
-
var _i18n = require("@wordpress/i18n");
|
|
20
|
-
|
|
21
|
-
var _useSetting = _interopRequireDefault(require("../components/use-setting"));
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* WordPress dependencies
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Internal dependencies
|
|
29
|
-
*/
|
|
30
|
-
function helpText(selfStretch, parentLayout) {
|
|
31
|
-
const {
|
|
32
|
-
orientation = 'horizontal'
|
|
33
|
-
} = parentLayout;
|
|
34
|
-
|
|
35
|
-
if (selfStretch === 'fill') {
|
|
36
|
-
return (0, _i18n.__)('Stretch to fill available space.');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (selfStretch === 'fixed') {
|
|
40
|
-
if (orientation === 'horizontal') {
|
|
41
|
-
return (0, _i18n.__)('Specify a fixed width.');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return (0, _i18n.__)('Specify a fixed height.');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return (0, _i18n.__)('Fit contents.');
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Inspector controls containing the child layout related configuration.
|
|
51
|
-
*
|
|
52
|
-
* @param {Object} props Block props.
|
|
53
|
-
* @param {Object} props.attributes Block attributes.
|
|
54
|
-
* @param {Object} props.setAttributes Function to set block attributes.
|
|
55
|
-
* @param {Object} props.__unstableParentLayout
|
|
56
|
-
*
|
|
57
|
-
* @return {WPElement} child layout edit element.
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
function ChildLayoutEdit(_ref) {
|
|
62
|
-
let {
|
|
63
|
-
attributes,
|
|
64
|
-
setAttributes,
|
|
65
|
-
__unstableParentLayout: parentLayout
|
|
66
|
-
} = _ref;
|
|
67
|
-
const {
|
|
68
|
-
style = {}
|
|
69
|
-
} = attributes;
|
|
70
|
-
const {
|
|
71
|
-
layout: childLayout = {}
|
|
72
|
-
} = style;
|
|
73
|
-
const {
|
|
74
|
-
selfStretch,
|
|
75
|
-
flexSize
|
|
76
|
-
} = childLayout;
|
|
77
|
-
(0, _element.useEffect)(() => {
|
|
78
|
-
if (selfStretch === 'fixed' && !flexSize) {
|
|
79
|
-
setAttributes({
|
|
80
|
-
style: { ...style,
|
|
81
|
-
layout: { ...childLayout,
|
|
82
|
-
selfStretch: 'fit'
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}, []);
|
|
88
|
-
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.__experimentalToggleGroupControl, {
|
|
89
|
-
__nextHasNoMarginBottom: true,
|
|
90
|
-
size: '__unstable-large',
|
|
91
|
-
label: childLayoutOrientation(parentLayout),
|
|
92
|
-
value: selfStretch || 'fit',
|
|
93
|
-
help: helpText(selfStretch, parentLayout),
|
|
94
|
-
onChange: value => {
|
|
95
|
-
const newFlexSize = value !== 'fixed' ? null : flexSize;
|
|
96
|
-
setAttributes({
|
|
97
|
-
style: { ...style,
|
|
98
|
-
layout: { ...childLayout,
|
|
99
|
-
selfStretch: value,
|
|
100
|
-
flexSize: newFlexSize
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
},
|
|
105
|
-
isBlock: true
|
|
106
|
-
}, (0, _element.createElement)(_components.__experimentalToggleGroupControlOption, {
|
|
107
|
-
key: 'fit',
|
|
108
|
-
value: 'fit',
|
|
109
|
-
label: (0, _i18n.__)('Fit')
|
|
110
|
-
}), (0, _element.createElement)(_components.__experimentalToggleGroupControlOption, {
|
|
111
|
-
key: 'fill',
|
|
112
|
-
value: 'fill',
|
|
113
|
-
label: (0, _i18n.__)('Fill')
|
|
114
|
-
}), (0, _element.createElement)(_components.__experimentalToggleGroupControlOption, {
|
|
115
|
-
key: 'fixed',
|
|
116
|
-
value: 'fixed',
|
|
117
|
-
label: (0, _i18n.__)('Fixed')
|
|
118
|
-
})), selfStretch === 'fixed' && (0, _element.createElement)(_components.__experimentalUnitControl, {
|
|
119
|
-
size: '__unstable-large',
|
|
120
|
-
onChange: value => {
|
|
121
|
-
setAttributes({
|
|
122
|
-
style: { ...style,
|
|
123
|
-
layout: { ...childLayout,
|
|
124
|
-
flexSize: value
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
},
|
|
129
|
-
value: flexSize
|
|
130
|
-
}));
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Determines if there is child layout support.
|
|
134
|
-
*
|
|
135
|
-
* @param {Object} props Block Props object.
|
|
136
|
-
* @param {Object} props.__unstableParentLayout Parent layout.
|
|
137
|
-
*
|
|
138
|
-
* @return {boolean} Whether there is support.
|
|
139
|
-
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
function hasChildLayoutSupport(_ref2) {
|
|
143
|
-
let {
|
|
144
|
-
__unstableParentLayout: parentLayout = {}
|
|
145
|
-
} = _ref2;
|
|
146
|
-
const {
|
|
147
|
-
type: parentLayoutType = 'default',
|
|
148
|
-
default: {
|
|
149
|
-
type: defaultParentLayoutType = 'default'
|
|
150
|
-
} = {},
|
|
151
|
-
allowSizingOnChildren = false
|
|
152
|
-
} = parentLayout;
|
|
153
|
-
const support = (defaultParentLayoutType === 'flex' || parentLayoutType === 'flex') && allowSizingOnChildren;
|
|
154
|
-
return support;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Checks if there is a current value in the child layout attributes.
|
|
158
|
-
*
|
|
159
|
-
* @param {Object} props Block props.
|
|
160
|
-
* @return {boolean} Whether or not the block has a child layout value set.
|
|
161
|
-
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
function hasChildLayoutValue(props) {
|
|
165
|
-
var _props$attributes$sty;
|
|
166
|
-
|
|
167
|
-
return ((_props$attributes$sty = props.attributes.style) === null || _props$attributes$sty === void 0 ? void 0 : _props$attributes$sty.layout) !== undefined;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Resets the child layout attribute. This can be used when disabling
|
|
171
|
-
* child layout controls for a block via a progressive discovery panel.
|
|
172
|
-
*
|
|
173
|
-
* @param {Object} props Block props.
|
|
174
|
-
* @param {Object} props.attributes Block attributes.
|
|
175
|
-
* @param {Object} props.setAttributes Function to set block attributes.
|
|
176
|
-
*/
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
function resetChildLayout(_ref3) {
|
|
180
|
-
let {
|
|
181
|
-
attributes = {},
|
|
182
|
-
setAttributes
|
|
183
|
-
} = _ref3;
|
|
184
|
-
const {
|
|
185
|
-
style
|
|
186
|
-
} = attributes;
|
|
187
|
-
setAttributes({
|
|
188
|
-
style: { ...style,
|
|
189
|
-
layout: undefined
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Custom hook that checks if child layout settings have been disabled.
|
|
195
|
-
*
|
|
196
|
-
* @param {Object} props Block props.
|
|
197
|
-
*
|
|
198
|
-
* @return {boolean} Whether the child layout setting is disabled.
|
|
199
|
-
*/
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
function useIsChildLayoutDisabled(props) {
|
|
203
|
-
const isDisabled = !(0, _useSetting.default)('layout');
|
|
204
|
-
return !hasChildLayoutSupport(props) || isDisabled;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function childLayoutOrientation(parentLayout) {
|
|
208
|
-
const {
|
|
209
|
-
orientation = 'horizontal'
|
|
210
|
-
} = parentLayout;
|
|
211
|
-
return orientation === 'horizontal' ? (0, _i18n.__)('Width') : (0, _i18n.__)('Height');
|
|
212
|
-
}
|
|
213
|
-
//# sourceMappingURL=child-layout.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/child-layout.js"],"names":["helpText","selfStretch","parentLayout","orientation","ChildLayoutEdit","attributes","setAttributes","__unstableParentLayout","style","layout","childLayout","flexSize","childLayoutOrientation","value","newFlexSize","hasChildLayoutSupport","type","parentLayoutType","default","defaultParentLayoutType","allowSizingOnChildren","support","hasChildLayoutValue","props","undefined","resetChildLayout","useIsChildLayoutDisabled","isDisabled"],"mappings":"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","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n\t__experimentalUnitControl as UnitControl,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../components/use-setting';\n\nfunction helpText( selfStretch, parentLayout ) {\n\tconst { orientation = 'horizontal' } = parentLayout;\n\n\tif ( selfStretch === 'fill' ) {\n\t\treturn __( 'Stretch to fill available space.' );\n\t}\n\tif ( selfStretch === 'fixed' ) {\n\t\tif ( orientation === 'horizontal' ) {\n\t\t\treturn __( 'Specify a fixed width.' );\n\t\t}\n\t\treturn __( 'Specify a fixed height.' );\n\t}\n\treturn __( 'Fit contents.' );\n}\n\n/**\n * Inspector controls containing the child layout related configuration.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block attributes.\n * @param {Object} props.setAttributes Function to set block attributes.\n * @param {Object} props.__unstableParentLayout\n *\n * @return {WPElement} child layout edit element.\n */\nexport function ChildLayoutEdit( {\n\tattributes,\n\tsetAttributes,\n\t__unstableParentLayout: parentLayout,\n} ) {\n\tconst { style = {} } = attributes;\n\tconst { layout: childLayout = {} } = style;\n\tconst { selfStretch, flexSize } = childLayout;\n\n\tuseEffect( () => {\n\t\tif ( selfStretch === 'fixed' && ! flexSize ) {\n\t\t\tsetAttributes( {\n\t\t\t\tstyle: {\n\t\t\t\t\t...style,\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\t...childLayout,\n\t\t\t\t\t\tselfStretch: 'fit',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\t}, [] );\n\n\treturn (\n\t\t<>\n\t\t\t<ToggleGroupControl\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tsize={ '__unstable-large' }\n\t\t\t\tlabel={ childLayoutOrientation( parentLayout ) }\n\t\t\t\tvalue={ selfStretch || 'fit' }\n\t\t\t\thelp={ helpText( selfStretch, parentLayout ) }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tconst newFlexSize = value !== 'fixed' ? null : flexSize;\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\t...style,\n\t\t\t\t\t\t\tlayout: {\n\t\t\t\t\t\t\t\t...childLayout,\n\t\t\t\t\t\t\t\tselfStretch: value,\n\t\t\t\t\t\t\t\tflexSize: newFlexSize,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\tisBlock={ true }\n\t\t\t>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ 'fit' }\n\t\t\t\t\tvalue={ 'fit' }\n\t\t\t\t\tlabel={ __( 'Fit' ) }\n\t\t\t\t/>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ 'fill' }\n\t\t\t\t\tvalue={ 'fill' }\n\t\t\t\t\tlabel={ __( 'Fill' ) }\n\t\t\t\t/>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ 'fixed' }\n\t\t\t\t\tvalue={ 'fixed' }\n\t\t\t\t\tlabel={ __( 'Fixed' ) }\n\t\t\t\t/>\n\t\t\t</ToggleGroupControl>\n\t\t\t{ selfStretch === 'fixed' && (\n\t\t\t\t<UnitControl\n\t\t\t\t\tsize={ '__unstable-large' }\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\t\t...style,\n\t\t\t\t\t\t\t\tlayout: {\n\t\t\t\t\t\t\t\t\t...childLayout,\n\t\t\t\t\t\t\t\t\tflexSize: value,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tvalue={ flexSize }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\n/**\n * Determines if there is child layout support.\n *\n * @param {Object} props Block Props object.\n * @param {Object} props.__unstableParentLayout Parent layout.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasChildLayoutSupport( {\n\t__unstableParentLayout: parentLayout = {},\n} ) {\n\tconst {\n\t\ttype: parentLayoutType = 'default',\n\t\tdefault: { type: defaultParentLayoutType = 'default' } = {},\n\t\tallowSizingOnChildren = false,\n\t} = parentLayout;\n\n\tconst support =\n\t\t( defaultParentLayoutType === 'flex' || parentLayoutType === 'flex' ) &&\n\t\tallowSizingOnChildren;\n\n\treturn support;\n}\n\n/**\n * Checks if there is a current value in the child layout attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a child layout value set.\n */\nexport function hasChildLayoutValue( props ) {\n\treturn props.attributes.style?.layout !== undefined;\n}\n\n/**\n * Resets the child layout attribute. This can be used when disabling\n * child layout controls for a block via a progressive discovery panel.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block attributes.\n * @param {Object} props.setAttributes Function to set block attributes.\n */\nexport function resetChildLayout( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: {\n\t\t\t...style,\n\t\t\tlayout: undefined,\n\t\t},\n\t} );\n}\n\n/**\n * Custom hook that checks if child layout settings have been disabled.\n *\n * @param {Object} props Block props.\n *\n * @return {boolean} Whether the child layout setting is disabled.\n */\nexport function useIsChildLayoutDisabled( props ) {\n\tconst isDisabled = ! useSetting( 'layout' );\n\n\treturn ! hasChildLayoutSupport( props ) || isDisabled;\n}\n\nexport function childLayoutOrientation( parentLayout ) {\n\tconst { orientation = 'horizontal' } = parentLayout;\n\n\treturn orientation === 'horizontal' ? __( 'Width' ) : __( 'Height' );\n}\n"]}
|