@wordpress/block-editor 15.21.0 → 15.22.1-next.v.202606191442.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 +23 -1
- package/build/components/block-card/index.cjs +4 -5
- package/build/components/block-card/index.cjs.map +2 -2
- package/build/components/block-compare/index.cjs +2 -2
- package/build/components/block-compare/index.cjs.map +2 -2
- package/build/components/block-inspector/index.cjs +3 -4
- package/build/components/block-inspector/index.cjs.map +2 -2
- package/build/components/block-mover/mover-description.cjs +6 -6
- package/build/components/block-mover/mover-description.cjs.map +1 -1
- package/build/components/block-patterns-list/index.cjs +1 -1
- package/build/components/block-patterns-list/index.cjs.map +2 -2
- package/build/components/block-patterns-paging/index.cjs +4 -4
- package/build/components/block-patterns-paging/index.cjs.map +2 -2
- package/build/components/block-popover/use-popover-scroll.cjs.map +1 -1
- package/build/components/block-quick-navigation/index.cjs +7 -5
- package/build/components/block-quick-navigation/index.cjs.map +2 -2
- package/build/components/block-switcher/block-transformations-menu.cjs +16 -15
- package/build/components/block-switcher/block-transformations-menu.cjs.map +2 -2
- package/build/components/block-switcher/index.cjs +4 -4
- package/build/components/block-switcher/index.cjs.map +2 -2
- package/build/components/block-toolbar/edit-section-button.cjs.map +1 -1
- package/build/components/block-tools/use-block-toolbar-popover-props.cjs +10 -4
- package/build/components/block-tools/use-block-toolbar-popover-props.cjs.map +2 -2
- package/build/components/child-layout-control/index.cjs +51 -19
- package/build/components/child-layout-control/index.cjs.map +2 -2
- package/build/components/dimensions-tool/index.cjs +4 -5
- package/build/components/dimensions-tool/index.cjs.map +2 -2
- package/build/components/dimensions-tool/scale-tool.cjs +1 -1
- package/build/components/dimensions-tool/scale-tool.cjs.map +2 -2
- package/build/components/global-styles/advanced-panel.cjs +23 -15
- package/build/components/global-styles/advanced-panel.cjs.map +2 -2
- package/build/components/global-styles/background-panel.cjs +2 -2
- package/build/components/global-styles/background-panel.cjs.map +2 -2
- package/build/components/global-styles/border-panel.cjs +2 -0
- package/build/components/global-styles/border-panel.cjs.map +2 -2
- package/build/components/global-styles/dimensions-panel.cjs +2 -2
- package/build/components/global-styles/dimensions-panel.cjs.map +2 -2
- package/build/components/global-styles/shadow-panel-components.cjs.map +2 -2
- package/build/components/grid/grid-item-resizer.cjs.map +1 -1
- package/build/components/grid/grid-visualizer.cjs.map +1 -1
- package/build/components/iframe/index.cjs +6 -3
- package/build/components/iframe/index.cjs.map +3 -3
- package/build/components/image-editor/use-transform-image.cjs.map +1 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.cjs +3 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.cjs.map +2 -2
- package/build/components/inserter/get-appender-label.cjs.map +1 -1
- package/build/components/inserter/hooks/use-patterns-state.cjs +1 -1
- package/build/components/inserter/hooks/use-patterns-state.cjs.map +2 -2
- package/build/components/inserter/index.cjs +179 -220
- package/build/components/inserter/index.cjs.map +3 -3
- package/build/components/inserter/media-tab/media-preview.cjs.map +2 -2
- package/build/components/inserter/search-items.cjs.map +1 -1
- package/build/components/inserter/search-results.cjs +1 -1
- package/build/components/inserter/search-results.cjs.map +2 -2
- package/build/components/inspector-controls/fill.cjs +1 -3
- package/build/components/inspector-controls/fill.cjs.map +2 -2
- package/build/components/inspector-controls-tabs/index.cjs.map +2 -2
- package/build/components/inspector-controls-tabs/styles-tab.cjs +1 -1
- package/build/components/inspector-controls-tabs/styles-tab.cjs.map +2 -2
- package/build/components/keyboard-shortcuts/index.cjs.map +1 -1
- package/build/components/line-height-control/index.cjs.map +1 -1
- package/build/components/link-control/index.cjs +1 -1
- package/build/components/link-control/index.cjs.map +1 -1
- package/build/components/link-control/normalize-url.cjs.map +1 -1
- package/build/components/list-view/block-select-button.cjs +10 -12
- package/build/components/list-view/block-select-button.cjs.map +2 -2
- package/build/components/list-view/block.cjs +2 -1
- package/build/components/list-view/block.cjs.map +2 -2
- package/build/components/list-view/utils.cjs.map +1 -1
- package/build/components/preset-input-control/custom-value-controls.cjs.map +2 -2
- package/build/components/provider/index.cjs.map +1 -1
- package/build/components/provider/use-block-sync.cjs +11 -2
- package/build/components/provider/use-block-sync.cjs.map +2 -2
- package/build/components/rich-text/event-listeners/before-input-rules.cjs +5 -5
- package/build/components/rich-text/event-listeners/before-input-rules.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/delete.cjs +4 -4
- package/build/components/rich-text/event-listeners/delete.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/enter.cjs +7 -2
- package/build/components/rich-text/event-listeners/enter.cjs.map +2 -2
- package/build/components/rich-text/event-listeners/input-events.cjs +4 -4
- package/build/components/rich-text/event-listeners/input-events.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/input-rules.cjs +17 -4
- package/build/components/rich-text/event-listeners/input-rules.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/insert-replacement-text.cjs +4 -4
- package/build/components/rich-text/event-listeners/insert-replacement-text.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/paste-handler.cjs.map +1 -1
- package/build/components/rich-text/event-listeners/remove-browser-shortcuts.cjs +4 -4
- package/build/components/rich-text/event-listeners/remove-browser-shortcuts.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/shortcuts.cjs +4 -4
- package/build/components/rich-text/event-listeners/shortcuts.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/undo-automatic-change.cjs +4 -4
- package/build/components/rich-text/event-listeners/undo-automatic-change.cjs.map +3 -3
- package/build/components/rich-text/index.cjs +1 -23
- package/build/components/rich-text/index.cjs.map +2 -2
- package/build/components/rich-text/prevent-event-discovery.cjs +1 -1
- package/build/components/rich-text/prevent-event-discovery.cjs.map +1 -1
- package/build/components/use-block-commands/index.cjs +5 -5
- package/build/components/use-block-commands/index.cjs.map +2 -2
- package/build/components/writing-flow/use-tab-nav.cjs.map +1 -1
- package/build/hooks/anchor.cjs +12 -16
- package/build/hooks/anchor.cjs.map +2 -2
- package/build/hooks/background.cjs.map +1 -1
- package/build/hooks/block-fields/index.cjs +13 -2
- package/build/hooks/block-fields/index.cjs.map +2 -2
- package/build/hooks/border.cjs +0 -3
- package/build/hooks/border.cjs.map +2 -2
- package/build/hooks/color.cjs +1 -4
- package/build/hooks/color.cjs.map +2 -2
- package/build/hooks/dimensions.cjs +13 -5
- package/build/hooks/dimensions.cjs.map +2 -2
- package/build/hooks/fit-text.cjs +11 -0
- package/build/hooks/fit-text.cjs.map +2 -2
- package/build/hooks/layout-child.cjs +27 -2
- package/build/hooks/layout-child.cjs.map +2 -2
- package/build/hooks/list-view.cjs +10 -7
- package/build/hooks/list-view.cjs.map +2 -2
- package/build/hooks/position.cjs +19 -22
- package/build/hooks/position.cjs.map +2 -2
- package/build/hooks/spacing-visualizer.cjs.map +1 -1
- package/build/hooks/state-utils.cjs.map +1 -1
- package/build/hooks/style.cjs +42 -2
- package/build/hooks/style.cjs.map +2 -2
- package/build/hooks/supports.cjs +0 -7
- package/build/hooks/supports.cjs.map +2 -2
- package/build/private-apis.cjs +4 -0
- package/build/private-apis.cjs.map +2 -2
- package/build/store/actions.cjs +7 -3
- package/build/store/actions.cjs.map +2 -2
- package/build/store/private-actions.cjs +1 -2
- package/build/store/private-actions.cjs.map +2 -2
- package/build/store/private-selectors.cjs +42 -2
- package/build/store/private-selectors.cjs.map +2 -2
- package/build/store/reducer.cjs +14 -6
- package/build/store/reducer.cjs.map +2 -2
- package/build/store/selectors.cjs +60 -41
- package/build/store/selectors.cjs.map +2 -2
- package/build/utils/dom.cjs.map +1 -1
- package/build/utils/selection.cjs +1 -1
- package/build-module/components/block-card/index.mjs +5 -6
- package/build-module/components/block-card/index.mjs.map +2 -2
- package/build-module/components/block-compare/index.mjs +1 -1
- package/build-module/components/block-compare/index.mjs.map +2 -2
- package/build-module/components/block-inspector/index.mjs +3 -5
- package/build-module/components/block-inspector/index.mjs.map +2 -2
- package/build-module/components/block-mover/mover-description.mjs +6 -6
- package/build-module/components/block-mover/mover-description.mjs.map +1 -1
- package/build-module/components/block-patterns-list/index.mjs +1 -1
- package/build-module/components/block-patterns-list/index.mjs.map +2 -2
- package/build-module/components/block-patterns-paging/index.mjs +4 -4
- package/build-module/components/block-patterns-paging/index.mjs.map +2 -2
- package/build-module/components/block-popover/use-popover-scroll.mjs.map +1 -1
- package/build-module/components/block-quick-navigation/index.mjs +8 -6
- package/build-module/components/block-quick-navigation/index.mjs.map +2 -2
- package/build-module/components/block-switcher/block-transformations-menu.mjs +16 -15
- package/build-module/components/block-switcher/block-transformations-menu.mjs.map +2 -2
- package/build-module/components/block-switcher/index.mjs +4 -4
- package/build-module/components/block-switcher/index.mjs.map +2 -2
- package/build-module/components/block-toolbar/edit-section-button.mjs.map +1 -1
- package/build-module/components/block-tools/use-block-toolbar-popover-props.mjs +10 -4
- package/build-module/components/block-tools/use-block-toolbar-popover-props.mjs.map +2 -2
- package/build-module/components/child-layout-control/index.mjs +51 -19
- package/build-module/components/child-layout-control/index.mjs.map +2 -2
- package/build-module/components/dimensions-tool/index.mjs +4 -5
- package/build-module/components/dimensions-tool/index.mjs.map +2 -2
- package/build-module/components/dimensions-tool/scale-tool.mjs +1 -1
- package/build-module/components/dimensions-tool/scale-tool.mjs.map +2 -2
- package/build-module/components/global-styles/advanced-panel.mjs +23 -15
- package/build-module/components/global-styles/advanced-panel.mjs.map +2 -2
- package/build-module/components/global-styles/background-panel.mjs +3 -3
- package/build-module/components/global-styles/background-panel.mjs.map +2 -2
- package/build-module/components/global-styles/border-panel.mjs +2 -0
- package/build-module/components/global-styles/border-panel.mjs.map +2 -2
- package/build-module/components/global-styles/dimensions-panel.mjs +3 -4
- package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
- package/build-module/components/global-styles/shadow-panel-components.mjs.map +2 -2
- package/build-module/components/grid/grid-item-resizer.mjs.map +1 -1
- package/build-module/components/grid/grid-visualizer.mjs.map +1 -1
- package/build-module/components/iframe/index.mjs +6 -3
- package/build-module/components/iframe/index.mjs.map +2 -2
- package/build-module/components/image-editor/use-transform-image.mjs.map +1 -1
- package/build-module/components/inner-blocks/use-inner-block-template-sync.mjs +3 -1
- package/build-module/components/inner-blocks/use-inner-block-template-sync.mjs.map +2 -2
- package/build-module/components/inserter/get-appender-label.mjs.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.mjs +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.mjs.map +2 -2
- package/build-module/components/inserter/index.mjs +185 -222
- package/build-module/components/inserter/index.mjs.map +3 -3
- package/build-module/components/inserter/media-tab/media-preview.mjs.map +2 -2
- package/build-module/components/inserter/search-items.mjs.map +1 -1
- package/build-module/components/inserter/search-results.mjs +1 -1
- package/build-module/components/inserter/search-results.mjs.map +2 -2
- package/build-module/components/inspector-controls/fill.mjs +1 -3
- package/build-module/components/inspector-controls/fill.mjs.map +2 -2
- package/build-module/components/inspector-controls-tabs/index.mjs.map +2 -2
- package/build-module/components/inspector-controls-tabs/styles-tab.mjs +1 -1
- package/build-module/components/inspector-controls-tabs/styles-tab.mjs.map +2 -2
- package/build-module/components/keyboard-shortcuts/index.mjs.map +1 -1
- package/build-module/components/line-height-control/index.mjs.map +1 -1
- package/build-module/components/link-control/index.mjs +1 -1
- package/build-module/components/link-control/index.mjs.map +1 -1
- package/build-module/components/link-control/normalize-url.mjs.map +1 -1
- package/build-module/components/list-view/block-select-button.mjs +10 -12
- package/build-module/components/list-view/block-select-button.mjs.map +2 -2
- package/build-module/components/list-view/block.mjs +2 -1
- package/build-module/components/list-view/block.mjs.map +2 -2
- package/build-module/components/list-view/utils.mjs.map +1 -1
- package/build-module/components/preset-input-control/custom-value-controls.mjs.map +2 -2
- package/build-module/components/provider/index.mjs.map +1 -1
- package/build-module/components/provider/use-block-sync.mjs +11 -2
- package/build-module/components/provider/use-block-sync.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/before-input-rules.mjs +5 -5
- package/build-module/components/rich-text/event-listeners/before-input-rules.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/delete.mjs +4 -4
- package/build-module/components/rich-text/event-listeners/delete.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/enter.mjs +7 -2
- package/build-module/components/rich-text/event-listeners/enter.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/input-events.mjs +4 -4
- package/build-module/components/rich-text/event-listeners/input-events.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/input-rules.mjs +17 -4
- package/build-module/components/rich-text/event-listeners/input-rules.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/insert-replacement-text.mjs +4 -4
- package/build-module/components/rich-text/event-listeners/insert-replacement-text.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/paste-handler.mjs.map +1 -1
- package/build-module/components/rich-text/event-listeners/remove-browser-shortcuts.mjs +4 -4
- package/build-module/components/rich-text/event-listeners/remove-browser-shortcuts.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/shortcuts.mjs +4 -4
- package/build-module/components/rich-text/event-listeners/shortcuts.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/undo-automatic-change.mjs +4 -4
- package/build-module/components/rich-text/event-listeners/undo-automatic-change.mjs.map +2 -2
- package/build-module/components/rich-text/index.mjs +1 -23
- package/build-module/components/rich-text/index.mjs.map +2 -2
- package/build-module/components/rich-text/prevent-event-discovery.mjs +1 -1
- package/build-module/components/rich-text/prevent-event-discovery.mjs.map +1 -1
- package/build-module/components/use-block-commands/index.mjs +5 -5
- package/build-module/components/use-block-commands/index.mjs.map +2 -2
- package/build-module/components/writing-flow/use-tab-nav.mjs.map +1 -1
- package/build-module/hooks/anchor.mjs +12 -16
- package/build-module/hooks/anchor.mjs.map +2 -2
- package/build-module/hooks/background.mjs.map +1 -1
- package/build-module/hooks/block-fields/index.mjs +13 -2
- package/build-module/hooks/block-fields/index.mjs.map +2 -2
- package/build-module/hooks/border.mjs +1 -4
- package/build-module/hooks/border.mjs.map +2 -2
- package/build-module/hooks/color.mjs +2 -5
- package/build-module/hooks/color.mjs.map +2 -2
- package/build-module/hooks/dimensions.mjs +13 -6
- package/build-module/hooks/dimensions.mjs.map +2 -2
- package/build-module/hooks/fit-text.mjs +11 -0
- package/build-module/hooks/fit-text.mjs.map +2 -2
- package/build-module/hooks/layout-child.mjs +27 -2
- package/build-module/hooks/layout-child.mjs.map +2 -2
- package/build-module/hooks/list-view.mjs +10 -7
- package/build-module/hooks/list-view.mjs.map +2 -2
- package/build-module/hooks/position.mjs +20 -23
- package/build-module/hooks/position.mjs.map +2 -2
- package/build-module/hooks/spacing-visualizer.mjs.map +1 -1
- package/build-module/hooks/state-utils.mjs.map +1 -1
- package/build-module/hooks/style.mjs +44 -3
- package/build-module/hooks/style.mjs.map +2 -2
- package/build-module/hooks/supports.mjs +0 -7
- package/build-module/hooks/supports.mjs.map +2 -2
- package/build-module/private-apis.mjs +8 -0
- package/build-module/private-apis.mjs.map +2 -2
- package/build-module/store/actions.mjs +7 -3
- package/build-module/store/actions.mjs.map +2 -2
- package/build-module/store/private-actions.mjs +1 -2
- package/build-module/store/private-actions.mjs.map +2 -2
- package/build-module/store/private-selectors.mjs +39 -1
- package/build-module/store/private-selectors.mjs.map +2 -2
- package/build-module/store/reducer.mjs +14 -6
- package/build-module/store/reducer.mjs.map +2 -2
- package/build-module/store/selectors.mjs +62 -42
- package/build-module/store/selectors.mjs.map +2 -2
- package/build-module/utils/dom.mjs.map +1 -1
- package/build-module/utils/selection.mjs +1 -1
- package/build-style/content-rtl.css +12 -0
- package/build-style/content.css +12 -0
- package/build-style/style-rtl.css +26 -8
- package/build-style/style.css +26 -8
- package/package.json +54 -46
- package/src/components/block-breadcrumb/README.md +2 -2
- package/src/components/block-card/index.js +7 -13
- package/src/components/block-compare/README.md +6 -6
- package/src/components/block-compare/index.js +1 -3
- package/src/components/block-inspector/index.js +2 -10
- package/src/components/block-patterns-list/index.js +1 -2
- package/src/components/block-preview/README.md +1 -1
- package/src/components/block-quick-navigation/index.js +7 -7
- package/src/components/block-switcher/block-transformations-menu.js +16 -18
- package/src/components/block-switcher/index.js +4 -4
- package/src/components/block-tools/use-block-toolbar-popover-props.js +10 -4
- package/src/components/block-types-list/README.md +0 -19
- package/src/components/child-layout-control/index.js +65 -20
- package/src/components/child-layout-control/test/index.js +64 -0
- package/src/components/dimensions-tool/index.js +4 -9
- package/src/components/dimensions-tool/scale-tool.js +1 -2
- package/src/components/dimensions-tool/test/index.js +89 -11
- package/src/components/global-styles/advanced-panel.js +5 -1
- package/src/components/global-styles/background-panel.js +3 -3
- package/src/components/global-styles/border-panel.js +2 -0
- package/src/components/global-styles/dimensions-panel.js +13 -15
- package/src/components/global-styles/shadow-panel-components.js +0 -1
- package/src/components/iframe/index.js +8 -3
- package/src/components/inner-blocks/use-inner-block-template-sync.js +3 -1
- package/src/components/inserter/hooks/use-patterns-state.js +1 -1
- package/src/components/inserter/index.js +257 -288
- package/src/components/inserter/media-tab/media-preview.js +0 -1
- package/src/components/inserter/search-results.js +1 -3
- package/src/components/inspector-controls/fill.js +6 -8
- package/src/components/inspector-controls-tabs/index.js +0 -1
- package/src/components/inspector-controls-tabs/styles-tab.js +5 -1
- package/src/components/justify-content-control/README.md +1 -1
- package/src/components/list-view/block-select-button.js +9 -14
- package/src/components/list-view/block.js +1 -0
- package/src/components/media-placeholder/README.md +1 -29
- package/src/components/media-upload/README.md +0 -19
- package/src/components/preset-input-control/custom-value-controls.js +0 -1
- package/src/components/provider/test/use-block-sync.js +40 -0
- package/src/components/provider/use-block-sync.js +12 -2
- package/src/components/rich-text/event-listeners/before-input-rules.js +5 -4
- package/src/components/rich-text/event-listeners/delete.js +9 -4
- package/src/components/rich-text/event-listeners/enter.js +9 -2
- package/src/components/rich-text/event-listeners/input-events.js +13 -4
- package/src/components/rich-text/event-listeners/input-rules.js +20 -4
- package/src/components/rich-text/event-listeners/insert-replacement-text.js +9 -4
- package/src/components/rich-text/event-listeners/remove-browser-shortcuts.js +9 -4
- package/src/components/rich-text/event-listeners/shortcuts.js +13 -4
- package/src/components/rich-text/event-listeners/undo-automatic-change.js +5 -4
- package/src/components/rich-text/index.js +1 -33
- package/src/components/unit-control/README.md +1 -1
- package/src/components/url-popover/README.md +1 -1
- package/src/components/use-block-commands/index.js +5 -5
- package/src/hooks/anchor.js +9 -17
- package/src/hooks/block-fields/index.js +27 -2
- package/src/hooks/border.js +1 -5
- package/src/hooks/color.js +1 -6
- package/src/hooks/dimensions.js +15 -8
- package/src/hooks/fit-text.js +16 -0
- package/src/hooks/layout-child.js +41 -2
- package/src/hooks/list-view.js +10 -11
- package/src/hooks/position.js +23 -27
- package/src/hooks/style.js +80 -2
- package/src/hooks/supports.js +0 -9
- package/src/hooks/test/dimensions.js +71 -0
- package/src/hooks/test/layout-child.js +165 -0
- package/src/hooks/test/style.js +126 -4
- package/src/private-apis.js +8 -0
- package/src/store/actions.js +13 -3
- package/src/store/private-actions.js +1 -4
- package/src/store/private-selectors.js +89 -0
- package/src/store/reducer.js +19 -7
- package/src/store/selectors.js +91 -53
- package/src/store/test/actions.js +21 -0
- package/src/store/test/private-selectors.js +138 -0
- package/src/store/test/reducer.js +46 -0
- package/src/store/test/selectors.js +77 -0
- package/build/components/media-upload-progress/constants.cjs +0 -46
- package/build/components/media-upload-progress/constants.cjs.map +0 -7
- package/build/components/rich-text/native/format-edit.cjs +0 -60
- package/build/components/rich-text/native/format-edit.cjs.map +0 -7
- package/build/components/rich-text/native/index.cjs +0 -28
- package/build/components/rich-text/native/index.cjs.map +0 -7
- package/build/components/rich-text/native/use-format-types.cjs +0 -139
- package/build/components/rich-text/native/use-format-types.cjs.map +0 -7
- package/build-module/components/media-upload-progress/constants.mjs +0 -16
- package/build-module/components/media-upload-progress/constants.mjs.map +0 -7
- package/build-module/components/rich-text/native/format-edit.mjs +0 -39
- package/build-module/components/rich-text/native/format-edit.mjs.map +0 -7
- package/build-module/components/rich-text/native/index.mjs +0 -7
- package/build-module/components/rich-text/native/index.mjs.map +0 -7
- package/build-module/components/rich-text/native/use-format-types.mjs +0 -114
- package/build-module/components/rich-text/native/use-format-types.mjs.map +0 -7
- package/src/components/audio-player/audio-url-parser.native.js +0 -20
- package/src/components/audio-player/index.native.js +0 -225
- package/src/components/audio-player/styles.native.scss +0 -114
- package/src/components/audio-player/test/audio-url-parser.native.js +0 -53
- package/src/components/block-alignment-control/test/index.native.js +0 -37
- package/src/components/block-alignment-control/ui.native.js +0 -86
- package/src/components/block-caption/README.md +0 -104
- package/src/components/block-caption/index.native.js +0 -89
- package/src/components/block-caption/styles.native.scss +0 -7
- package/src/components/block-controls/slot.native.js +0 -33
- package/src/components/block-draggable/draggable-chip.native.js +0 -49
- package/src/components/block-draggable/dropping-insertion-point.native.js +0 -181
- package/src/components/block-draggable/dropping-insertion-point.native.scss +0 -8
- package/src/components/block-draggable/index.native.js +0 -467
- package/src/components/block-draggable/style.native.scss +0 -19
- package/src/components/block-draggable/test/__snapshots__/index.native.js.snap +0 -73
- package/src/components/block-draggable/test/helpers.native.js +0 -182
- package/src/components/block-draggable/test/index.native.js +0 -419
- package/src/components/block-draggable/use-scroll-when-dragging.native.js +0 -135
- package/src/components/block-edit/edit.native.js +0 -49
- package/src/components/block-edit/test/edit.native.js +0 -65
- package/src/components/block-heading-level-dropdown/index.native.js +0 -68
- package/src/components/block-icon/index.native.js +0 -47
- package/src/components/block-icon/style.native.scss +0 -7
- package/src/components/block-list/block-crash-boundary.native.js +0 -43
- package/src/components/block-list/block-crash-warning.native.js +0 -21
- package/src/components/block-list/block-invalid-warning.native.js +0 -70
- package/src/components/block-list/block-list-context.native.js +0 -172
- package/src/components/block-list/block-list-item-cell.native.js +0 -62
- package/src/components/block-list/block-list-item.native.js +0 -209
- package/src/components/block-list/block-list-item.native.scss +0 -16
- package/src/components/block-list/block-outline.native.js +0 -77
- package/src/components/block-list/block-selection-button.native.js +0 -100
- package/src/components/block-list/block-selection-button.native.scss +0 -34
- package/src/components/block-list/block.native.js +0 -716
- package/src/components/block-list/block.native.scss +0 -62
- package/src/components/block-list/grid-item.native.js +0 -58
- package/src/components/block-list/index.native.js +0 -437
- package/src/components/block-list/insertion-point.native.js +0 -36
- package/src/components/block-list/style.native.scss +0 -117
- package/src/components/block-list/test/block-invalid-warning.native.js +0 -62
- package/src/components/block-list/test/block-list-context.native.js +0 -243
- package/src/components/block-list/test/block-outline.native.js +0 -255
- package/src/components/block-list/test/fixtures/block-list-context.native.js +0 -79
- package/src/components/block-list/test/index.native.js +0 -205
- package/src/components/block-list/use-block-props/index.native.js +0 -10
- package/src/components/block-list/use-scroll-upon-insertion.native.js +0 -52
- package/src/components/block-list-appender/index.native.js +0 -70
- package/src/components/block-list-appender/style.native.scss +0 -8
- package/src/components/block-media-update-progress/README.md +0 -100
- package/src/components/block-media-update-progress/index.native.js +0 -299
- package/src/components/block-media-update-progress/styles.native.scss +0 -9
- package/src/components/block-media-update-progress/test/index.native.js +0 -543
- package/src/components/block-mover/index.native.js +0 -193
- package/src/components/block-mover/mover-description.native.js +0 -155
- package/src/components/block-mover/test/__snapshots__/index.native.js.snap +0 -218
- package/src/components/block-mover/test/index.native.js +0 -186
- package/src/components/block-settings/button.native.js +0 -41
- package/src/components/block-settings/container.native.js +0 -91
- package/src/components/block-settings/container.native.scss +0 -4
- package/src/components/block-settings/index.native.js +0 -5
- package/src/components/block-styles/index.native.js +0 -94
- package/src/components/block-styles/preview.native.js +0 -109
- package/src/components/block-styles/style.native.scss +0 -64
- package/src/components/block-switcher/block-transformations-menu.native.js +0 -91
- package/src/components/block-toolbar/block-toolbar-menu.native.js +0 -477
- package/src/components/block-toolbar/index.native.js +0 -126
- package/src/components/block-toolbar/test/__snapshots__/block-toolbar-menu.native.js.snap +0 -125
- package/src/components/block-toolbar/test/block-toolbar-menu.native.js +0 -405
- package/src/components/block-toolbar/test/index.native.js +0 -36
- package/src/components/block-types-list/index.native.js +0 -175
- package/src/components/block-types-list/style.native.scss +0 -25
- package/src/components/block-variation-picker/index.native.js +0 -107
- package/src/components/block-variation-picker/style.native.scss +0 -32
- package/src/components/button-block-appender/index.native.js +0 -92
- package/src/components/button-block-appender/styles.native.scss +0 -43
- package/src/components/caption/README.md +0 -44
- package/src/components/caption/index.native.js +0 -61
- package/src/components/colors-gradients/panel-color-gradient-settings.native.js +0 -59
- package/src/components/contrast-checker/index.native.js +0 -113
- package/src/components/contrast-checker/style.native.scss +0 -26
- package/src/components/convert-to-group-buttons/index.native.js +0 -79
- package/src/components/default-block-appender/index.native.js +0 -113
- package/src/components/default-block-appender/style.native.scss +0 -18
- package/src/components/floating-toolbar/floatingToolbar.android.scss +0 -4
- package/src/components/floating-toolbar/floatingToolbar.ios.scss +0 -3
- package/src/components/floating-toolbar/index.native.js +0 -141
- package/src/components/floating-toolbar/styles.native.scss +0 -43
- package/src/components/font-sizes/index.native.js +0 -7
- package/src/components/global-styles/color-panel.native.js +0 -207
- package/src/components/global-styles/test/use-global-styles-context.native.js +0 -435
- package/src/components/global-styles/use-global-styles-context.native.js +0 -592
- package/src/components/gradients/index.native.js +0 -2
- package/src/components/image-link-destinations/index.native.js +0 -152
- package/src/components/image-link-destinations/style.native.scss +0 -16
- package/src/components/index.native.js +0 -108
- package/src/components/inner-blocks/constants.native.js +0 -5
- package/src/components/inner-blocks/index.native.js +0 -221
- package/src/components/inner-blocks/warning-max-depth-exceeded.native.js +0 -124
- package/src/components/inserter/block-types-tab.native.js +0 -76
- package/src/components/inserter/hooks/use-block-type-impressions.native.js +0 -47
- package/src/components/inserter/hooks/use-clipboard-block.native.js +0 -40
- package/src/components/inserter/index.native.js +0 -424
- package/src/components/inserter/menu.native.js +0 -237
- package/src/components/inserter/no-results.native.js +0 -49
- package/src/components/inserter/reusable-blocks-tab.native.js +0 -45
- package/src/components/inserter/search-results.native.js +0 -67
- package/src/components/inserter/style.native.scss +0 -83
- package/src/components/inserter/tabs.native.js +0 -152
- package/src/components/inserter/test/__snapshots__/index.native.js.snap +0 -117
- package/src/components/inserter/test/fixtures/index.native.js +0 -12
- package/src/components/inserter/test/index.native.js +0 -273
- package/src/components/inserter/test/reusable-blocks-tab.native.js +0 -62
- package/src/components/inserter/test/utils.native.js +0 -37
- package/src/components/inserter/utils.native.js +0 -46
- package/src/components/inserter-button/index.native.js +0 -108
- package/src/components/inserter-button/style.native.scss +0 -72
- package/src/components/inspector-controls/fill.native.js +0 -62
- package/src/components/inspector-controls/slot.native.js +0 -35
- package/src/components/inspector-controls-tabs/advanced-controls-panel.native.js +0 -31
- package/src/components/line-height-control/index.native.js +0 -28
- package/src/components/media-placeholder/index.native.js +0 -258
- package/src/components/media-placeholder/styles.native.scss +0 -108
- package/src/components/media-replace-flow/index.native.js +0 -12
- package/src/components/media-upload/constants.native.js +0 -14
- package/src/components/media-upload/index.native.js +0 -356
- package/src/components/media-upload/style.native.scss +0 -4
- package/src/components/media-upload/test/index.native.js +0 -172
- package/src/components/media-upload-progress/README.md +0 -100
- package/src/components/media-upload-progress/constants.js +0 -6
- package/src/components/media-upload-progress/index.native.js +0 -233
- package/src/components/media-upload-progress/styles.native.scss +0 -15
- package/src/components/media-upload-progress/test/index.native.js +0 -220
- package/src/components/plain-text/index.native.js +0 -164
- package/src/components/plain-text/style.native.scss +0 -10
- package/src/components/provider/index.native.js +0 -32
- package/src/components/rich-text/embed-handler-picker.native.js +0 -65
- package/src/components/rich-text/file-paste-handler.native.js +0 -3
- package/src/components/rich-text/format-toolbar/index.native.js +0 -21
- package/src/components/rich-text/format-toolbar-container.native.js +0 -16
- package/src/components/rich-text/index.native.js +0 -701
- package/src/components/rich-text/input-event.native.js +0 -10
- package/src/components/rich-text/native/format-edit.js +0 -44
- package/src/components/rich-text/native/get-format-colors.native.js +0 -47
- package/src/components/rich-text/native/index.js +0 -1
- package/src/components/rich-text/native/index.native.js +0 -1389
- package/src/components/rich-text/native/style.native.scss +0 -28
- package/src/components/rich-text/native/test/__snapshots__/index.native.js.snap +0 -79
- package/src/components/rich-text/native/test/index.native.js +0 -345
- package/src/components/rich-text/native/test/performance/rich-text.native.js +0 -44
- package/src/components/rich-text/native/toolbar-button-with-options.native.js +0 -61
- package/src/components/rich-text/native/use-format-types.js +0 -146
- package/src/components/rich-text/remove-browser-shortcuts.native.js +0 -1
- package/src/components/rich-text/shortcut.native.js +0 -10
- package/src/components/ungroup-button/README.md +0 -23
- package/src/components/ungroup-button/index.native.js +0 -77
- package/src/components/unsupported-block-details/index.native.js +0 -187
- package/src/components/unsupported-block-details/style.native.scss +0 -56
- package/src/components/url-input/index.native.js +0 -33
- package/src/components/use-block-drop-zone/index.native.js +0 -207
- package/src/components/use-on-block-drop/index.native.js +0 -115
- package/src/components/use-unsupported-block-editor/index.native.js +0 -59
- package/src/components/video-player/gridicon-play.native.js +0 -13
- package/src/components/video-player/index.native.js +0 -133
- package/src/components/video-player/styles.native.scss +0 -29
- package/src/components/warning/index.native.js +0 -64
- package/src/components/warning/style.native.scss +0 -47
- package/src/hooks/align.native.js +0 -49
- package/src/hooks/custom-class-name.native.js +0 -70
- package/src/hooks/index.native.js +0 -36
- package/src/hooks/layout.native.js +0 -23
- package/src/hooks/test/__snapshots__/align.native.js.snap +0 -73
- package/src/hooks/test/__snapshots__/anchor.native.js.snap +0 -7
- package/src/hooks/test/align.native.js +0 -134
- package/src/hooks/test/anchor.native.js +0 -32
- package/src/hooks/test/use-editor-wrapper-styles.native.js +0 -282
- package/src/hooks/typography.native.js +0 -60
- package/src/hooks/use-editor-wrapper-styles.native.js +0 -250
- package/src/hooks/use-editor-wrapper-styles.native.scss +0 -12
- package/src/index.native.js +0 -6
- package/src/private-apis.native.js +0 -21
- package/src/store/defaults.native.js +0 -23
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/fit-text.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport { useEffect, useCallback, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tToggleControl,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\nconst EMPTY_OBJECT = {};\nconst MIN_FONT_SIZE_FOR_WARNING = 12;\n\n/**\n * Internal dependencies\n */\nimport { optimizeFitText } from '../utils/fit-text-utils';\nimport { store as blockEditorStore } from '../store';\nimport { useBlockElement } from '../components/block-list/use-block-props/use-block-refs';\nimport InspectorControls from '../components/inspector-controls';\nimport FitTextSizeWarning from '../components/fit-text-size-warning';\n\nexport const FIT_TEXT_SUPPORT_KEY = 'typography.fitText';\n\n/**\n * Filters registered block settings, extending attributes to include\n * the `fitText` attribute.\n *\n * @param {Object} settings Original block settings.\n * @return {Object} Filtered block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBlockSupport( settings, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify their own attribute definition.\n\tif ( settings.attributes?.fitText ) {\n\t\treturn settings;\n\t}\n\n\t// Add fitText attribute.\n\treturn {\n\t\t...settings,\n\t\tattributes: {\n\t\t\t...settings.attributes,\n\t\t\tfitText: {\n\t\t\t\ttype: 'boolean',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Custom hook to handle fit text functionality in the editor.\n *\n * @param {Object} props Component props.\n * @param {?boolean} props.fitText Fit text attribute.\n * @param {string} props.name Block name.\n * @param {string} props.clientId Block client ID.\n */\nfunction useFitText( { fitText, name, clientId } ) {\n\tconst [ fontSize, setFontSize ] = useState( null );\n\tconst hasFitTextSupport = hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY );\n\tconst blockElement = useBlockElement( clientId );\n\n\t// Monitor block attribute changes, parent changes, and block mode.\n\t// Any attribute or parent change may change the available space.\n\t// Block mode is needed to disable fit text when in HTML editing mode.\n\tconst { blockAttributes, parentId, blockMode } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! clientId || ! hasFitTextSupport || ! fitText ) {\n\t\t\t\treturn EMPTY_OBJECT;\n\t\t\t}\n\t\t\tconst _blockMode =\n\t\t\t\tselect( blockEditorStore ).getBlockMode( clientId );\n\t\t\tif ( _blockMode === 'html' ) {\n\t\t\t\treturn { blockMode: _blockMode };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tblockAttributes:\n\t\t\t\t\tselect( blockEditorStore ).getBlockAttributes( clientId ),\n\t\t\t\tparentId:\n\t\t\t\t\tselect( blockEditorStore ).getBlockRootClientId( clientId ),\n\t\t\t\tblockMode: _blockMode,\n\t\t\t};\n\t\t},\n\t\t[ clientId, hasFitTextSupport, fitText ]\n\t);\n\n\tconst applyFitText = useCallback( () => {\n\t\tif ( ! blockElement || ! hasFitTextSupport || ! fitText ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Get or create style element with unique ID\n\t\tconst styleId = `fit-text-${ clientId }`;\n\t\tlet styleElement = blockElement.ownerDocument.getElementById( styleId );\n\t\tif ( ! styleElement ) {\n\t\t\tstyleElement = blockElement.ownerDocument.createElement( 'style' );\n\t\t\tstyleElement.id = styleId;\n\t\t\tblockElement.ownerDocument.head.appendChild( styleElement );\n\t\t}\n\n\t\tconst blockSelector = `#block-${ clientId }`;\n\n\t\tconst applyFontSizeStyle = ( size ) => {\n\t\t\tif ( size === 0 ) {\n\t\t\t\tstyleElement.textContent = '';\n\t\t\t} else {\n\t\t\t\tstyleElement.textContent = `${ blockSelector } { font-size: ${ size }px !important; }`;\n\t\t\t}\n\t\t};\n\n\t\tconst optimalSize = optimizeFitText( blockElement, applyFontSizeStyle );\n\t\tsetFontSize( optimalSize );\n\t}, [ blockElement, clientId, hasFitTextSupport, fitText ] );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! fitText ||\n\t\t\t! blockElement ||\n\t\t\t! clientId ||\n\t\t\t! hasFitTextSupport ||\n\t\t\tblockMode === 'html'\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Store current element value for cleanup\n\t\tconst currentElement = blockElement;\n\t\tconst previousVisibility = currentElement.style.visibility;\n\n\t\t// Store IDs for cleanup\n\t\tlet hideFrameId = null;\n\t\tlet calculateFrameId = null;\n\t\tlet showTimeoutId = null;\n\n\t\t// We are hiding the element doing the calculation of fit text\n\t\t// and then showing it again to avoid the user noticing a flash of potentially\n\t\t// big fitText while the binary search is happening.\n\t\thideFrameId = window.requestAnimationFrame( () => {\n\t\t\tcurrentElement.style.visibility = 'hidden';\n\t\t\t// Wait for browser to render the hidden state\n\t\t\tcalculateFrameId = window.requestAnimationFrame( () => {\n\t\t\t\tapplyFitText();\n\n\t\t\t\t// Using a timeout instead of requestAnimationFrame, because\n\t\t\t\t// with requestAnimationFrame a flash of very high size\n\t\t\t\t// can still occur although rare.\n\t\t\t\tshowTimeoutId = setTimeout( () => {\n\t\t\t\t\tcurrentElement.style.visibility = previousVisibility;\n\t\t\t\t}, 10 );\n\t\t\t} );\n\t\t} );\n\n\t\t// Watch for size changes\n\t\tlet resizeObserver;\n\t\tif ( window.ResizeObserver && currentElement.parentElement ) {\n\t\t\tresizeObserver = new window.ResizeObserver( applyFitText );\n\t\t\tresizeObserver.observe( currentElement.parentElement );\n\t\t\tresizeObserver.observe( currentElement );\n\t\t}\n\n\t\t// Cleanup function\n\t\treturn () => {\n\t\t\t// Cancel pending async operations\n\t\t\tif ( hideFrameId !== null ) {\n\t\t\t\twindow.cancelAnimationFrame( hideFrameId );\n\t\t\t}\n\t\t\tif ( calculateFrameId !== null ) {\n\t\t\t\twindow.cancelAnimationFrame( calculateFrameId );\n\t\t\t}\n\t\t\tif ( showTimeoutId !== null ) {\n\t\t\t\tclearTimeout( showTimeoutId );\n\t\t\t}\n\n\t\t\tif ( resizeObserver ) {\n\t\t\t\tresizeObserver.disconnect();\n\t\t\t}\n\n\t\t\tconst styleId = `fit-text-${ clientId }`;\n\t\t\tconst styleElement =\n\t\t\t\tcurrentElement.ownerDocument.getElementById( styleId );\n\t\t\tif ( styleElement ) {\n\t\t\t\tstyleElement.remove();\n\t\t\t}\n\t\t};\n\t}, [\n\t\tfitText,\n\t\tclientId,\n\t\tparentId,\n\t\tapplyFitText,\n\t\tblockElement,\n\t\thasFitTextSupport,\n\t\tblockMode,\n\t] );\n\n\t// Trigger fit text recalculation when content changes\n\tuseEffect( () => {\n\t\tif (\n\t\t\tfitText &&\n\t\t\tblockElement &&\n\t\t\thasFitTextSupport &&\n\t\t\tblockMode !== 'html'\n\t\t) {\n\t\t\t// Wait for next frame to ensure DOM has updated after content changes\n\t\t\tconst frameId = window.requestAnimationFrame( () => {\n\t\t\t\tif ( blockElement ) {\n\t\t\t\t\tapplyFitText();\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\treturn () => window.cancelAnimationFrame( frameId );\n\t\t}\n\t}, [\n\t\tblockAttributes,\n\t\tfitText,\n\t\tapplyFitText,\n\t\tblockElement,\n\t\thasFitTextSupport,\n\t\tblockMode,\n\t] );\n\n\treturn { fontSize };\n}\n\n/**\n * Fit text control component for the typography panel.\n *\n * @param {Object} props Component props.\n * @param {string} props.clientId Block client ID.\n * @param {Function} props.setAttributes Function to set block attributes.\n * @param {string} props.name Block name.\n * @param {boolean} props.fitText Whether fit text is enabled.\n * @param {string} props.fontSize Font size slug.\n * @param {Object} props.style Block style object.\n */\nexport function FitTextControl( {\n\tclientId,\n\tfitText = false,\n\tsetAttributes,\n\tname,\n\tfontSize,\n\tstyle,\n} ) {\n\tif ( ! hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<ToolsPanelItem\n\t\t\thasValue={ () => fitText }\n\t\t\tlabel={ __( 'Fit text' ) }\n\t\t\tonDeselect={ () => setAttributes( { fitText: undefined } ) }\n\t\t\tresetAllFilter={ () => ( { fitText: undefined } ) }\n\t\t\tpanelId={ clientId }\n\t\t>\n\t\t\t<ToggleControl\n\t\t\t\tlabel={ __( 'Fit text' ) }\n\t\t\t\tchecked={ fitText }\n\t\t\t\tonChange={ () => {\n\t\t\t\t\tconst newFitText = ! fitText || undefined;\n\t\t\t\t\tconst updates = { fitText: newFitText };\n\n\t\t\t\t\t// When enabling fit text, clear font size if it has a value\n\t\t\t\t\tif ( newFitText ) {\n\t\t\t\t\t\tif ( fontSize ) {\n\t\t\t\t\t\t\tupdates.fontSize = undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( style?.typography?.fontSize ) {\n\t\t\t\t\t\t\tupdates.style = {\n\t\t\t\t\t\t\t\t...style,\n\t\t\t\t\t\t\t\ttypography: {\n\t\t\t\t\t\t\t\t\t...style?.typography,\n\t\t\t\t\t\t\t\t\tfontSize: undefined,\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\n\t\t\t\t\tsetAttributes( updates );\n\t\t\t\t} }\n\t\t\t\thelp={\n\t\t\t\t\tfitText\n\t\t\t\t\t\t? __( 'Text will resize to fit its container.' )\n\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t'The text will resize to fit its container, resetting other font size settings.'\n\t\t\t\t\t\t )\n\t\t\t\t}\n\t\t\t/>\n\t\t</ToolsPanelItem>\n\t);\n}\n\n/**\n * Override props applied to the block element on save.\n *\n * @param {Object} props Additional props applied to the block element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Block attributes.\n * @return {Object} Filtered props applied to the block element.\n */\nfunction addSaveProps( props, blockType, attributes ) {\n\tif ( ! hasBlockSupport( blockType, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn props;\n\t}\n\n\tconst { fitText } = attributes;\n\n\tif ( ! fitText ) {\n\t\treturn props;\n\t}\n\n\t// Add CSS class for frontend detection and styling\n\tconst className = props.className\n\t\t? `${ props.className } has-fit-text`\n\t\t: 'has-fit-text';\n\n\treturn {\n\t\t...props,\n\t\tclassName,\n\t};\n}\n\n/**\n * Override props applied to the block element in the editor.\n *\n * @param {Object} props Component props including block attributes.\n * @param {string} props.name Block name.\n * @param {boolean} props.fitText Whether fit text is enabled.\n * @return {Object} Filtered props applied to the block element.\n */\nfunction useBlockProps( { name, fitText } ) {\n\tif ( fitText && hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn {\n\t\t\tclassName: 'has-fit-text',\n\t\t};\n\t}\n\treturn {};\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/fit-text/addAttribute',\n\taddAttributes\n);\n\nconst hasFitTextSupport = ( blockNameOrType ) => {\n\treturn hasBlockSupport( blockNameOrType, FIT_TEXT_SUPPORT_KEY );\n};\n\n/**\n * Component that handles the fit text font size and displays a warning\n * if the fit text font size is below a minimum threshold.\n *\n * @param {Object} props Component props.\n * @param {boolean} props.fitText Whether fit text is enabled.\n * @param {string} props.name Block name.\n * @param {string} props.clientId Block client ID.\n * @param {boolean} props.isSelected Whether the block is selected.\n * @return {Element|null} Warning component or null.\n */\nfunction FitTextFontSize( { fitText, name, clientId, isSelected } ) {\n\tconst { fontSize } = useFitText( { fitText, name, clientId } );\n\tif ( isSelected && fontSize && fontSize < MIN_FONT_SIZE_FOR_WARNING ) {\n\t\treturn (\n\t\t\t<InspectorControls group=\"typography\">\n\t\t\t\t<FitTextSizeWarning />\n\t\t\t</InspectorControls>\n\t\t);\n\t}\n\treturn null;\n}\n\n/*\n * Fit-text requires that layout calculations be done even when a block is not\n * currently selected. Therefore, the regular hooking approach using an\n * exported `edit` method is not enough, and we must use this HoC with the\n * `editor.BlockEdit` filter.\n */\nconst addFitTextControl = createHigherOrderComponent( ( BlockEdit ) => {\n\treturn function AddFitTextControl( props ) {\n\t\tconst { name, attributes, clientId, isSelected, setAttributes } = props;\n\t\tconst { fitText } = attributes;\n\t\tconst supportsFitText = hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY );\n\t\tif ( ! supportsFitText ) {\n\t\t\treturn <BlockEdit { ...props } />;\n\t\t}\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t\t<InspectorControls group=\"typography\">\n\t\t\t\t\t<FitTextControl\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tfitText={ fitText }\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\tname={ name }\n\t\t\t\t\t\tfontSize={ attributes.fontSize }\n\t\t\t\t\t\tstyle={ attributes.style }\n\t\t\t\t\t/>\n\t\t\t\t</InspectorControls>\n\t\t\t\t{ fitText && (\n\t\t\t\t\t<FitTextFontSize\n\t\t\t\t\t\tfitText={ fitText }\n\t\t\t\t\t\tname={ name }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t};\n}, 'addFitTextControl' );\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/fit-text/add-fit-text-control',\n\taddFitTextControl\n);\n\nexport default {\n\tuseBlockProps,\n\taddSaveProps,\n\tattributeKeys: [ 'fitText', 'fontSize', 'style' ],\n\thasSupport: hasFitTextSupport,\n\tedit: () => null,\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAA0B;AAC1B,oBAAgC;AAChC,qBAAiD;AACjD,kBAA0B;AAC1B,kBAAmB;AACnB,wBAGO;AACP,qBAA2C;AAQ3C,4BAAgC;AAChC,mBAA0C;AAC1C,4BAAgC;AAChC,gCAA8B;AAC9B,mCAA+B;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport { useEffect, useCallback, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tToggleControl,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\nconst EMPTY_OBJECT = {};\nconst MIN_FONT_SIZE_FOR_WARNING = 12;\n\n/**\n * Internal dependencies\n */\nimport { optimizeFitText } from '../utils/fit-text-utils';\nimport { store as blockEditorStore } from '../store';\nimport { useBlockElement } from '../components/block-list/use-block-props/use-block-refs';\nimport InspectorControls from '../components/inspector-controls';\nimport FitTextSizeWarning from '../components/fit-text-size-warning';\nimport { unlock } from '../lock-unlock';\n\nexport const FIT_TEXT_SUPPORT_KEY = 'typography.fitText';\n\n/**\n * Filters registered block settings, extending attributes to include\n * the `fitText` attribute.\n *\n * @param {Object} settings Original block settings.\n * @return {Object} Filtered block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBlockSupport( settings, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify their own attribute definition.\n\tif ( settings.attributes?.fitText ) {\n\t\treturn settings;\n\t}\n\n\t// Add fitText attribute.\n\treturn {\n\t\t...settings,\n\t\tattributes: {\n\t\t\t...settings.attributes,\n\t\t\tfitText: {\n\t\t\t\ttype: 'boolean',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Custom hook to handle fit text functionality in the editor.\n *\n * @param {Object} props Component props.\n * @param {?boolean} props.fitText Fit text attribute.\n * @param {string} props.name Block name.\n * @param {string} props.clientId Block client ID.\n */\nfunction useFitText( { fitText, name, clientId } ) {\n\tconst [ fontSize, setFontSize ] = useState( null );\n\tconst hasFitTextSupport = hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY );\n\tconst blockElement = useBlockElement( clientId );\n\n\t// Monitor block attribute changes, parent changes, and block mode.\n\t// Any attribute or parent change may change the available space.\n\t// Block mode is needed to disable fit text when in HTML editing mode.\n\tconst { blockAttributes, parentId, blockMode } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! clientId || ! hasFitTextSupport || ! fitText ) {\n\t\t\t\treturn EMPTY_OBJECT;\n\t\t\t}\n\t\t\tconst _blockMode =\n\t\t\t\tselect( blockEditorStore ).getBlockMode( clientId );\n\t\t\tif ( _blockMode === 'html' ) {\n\t\t\t\treturn { blockMode: _blockMode };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tblockAttributes:\n\t\t\t\t\tselect( blockEditorStore ).getBlockAttributes( clientId ),\n\t\t\t\tparentId:\n\t\t\t\t\tselect( blockEditorStore ).getBlockRootClientId( clientId ),\n\t\t\t\tblockMode: _blockMode,\n\t\t\t};\n\t\t},\n\t\t[ clientId, hasFitTextSupport, fitText ]\n\t);\n\n\tconst applyFitText = useCallback( () => {\n\t\tif ( ! blockElement || ! hasFitTextSupport || ! fitText ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Get or create style element with unique ID\n\t\tconst styleId = `fit-text-${ clientId }`;\n\t\tlet styleElement = blockElement.ownerDocument.getElementById( styleId );\n\t\tif ( ! styleElement ) {\n\t\t\tstyleElement = blockElement.ownerDocument.createElement( 'style' );\n\t\t\tstyleElement.id = styleId;\n\t\t\tblockElement.ownerDocument.head.appendChild( styleElement );\n\t\t}\n\n\t\tconst blockSelector = `#block-${ clientId }`;\n\n\t\tconst applyFontSizeStyle = ( size ) => {\n\t\t\tif ( size === 0 ) {\n\t\t\t\tstyleElement.textContent = '';\n\t\t\t} else {\n\t\t\t\tstyleElement.textContent = `${ blockSelector } { font-size: ${ size }px !important; }`;\n\t\t\t}\n\t\t};\n\n\t\tconst optimalSize = optimizeFitText( blockElement, applyFontSizeStyle );\n\t\tsetFontSize( optimalSize );\n\t}, [ blockElement, clientId, hasFitTextSupport, fitText ] );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! fitText ||\n\t\t\t! blockElement ||\n\t\t\t! clientId ||\n\t\t\t! hasFitTextSupport ||\n\t\t\tblockMode === 'html'\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Store current element value for cleanup\n\t\tconst currentElement = blockElement;\n\t\tconst previousVisibility = currentElement.style.visibility;\n\n\t\t// Store IDs for cleanup\n\t\tlet hideFrameId = null;\n\t\tlet calculateFrameId = null;\n\t\tlet showTimeoutId = null;\n\n\t\t// We are hiding the element doing the calculation of fit text\n\t\t// and then showing it again to avoid the user noticing a flash of potentially\n\t\t// big fitText while the binary search is happening.\n\t\thideFrameId = window.requestAnimationFrame( () => {\n\t\t\tcurrentElement.style.visibility = 'hidden';\n\t\t\t// Wait for browser to render the hidden state\n\t\t\tcalculateFrameId = window.requestAnimationFrame( () => {\n\t\t\t\tapplyFitText();\n\n\t\t\t\t// Using a timeout instead of requestAnimationFrame, because\n\t\t\t\t// with requestAnimationFrame a flash of very high size\n\t\t\t\t// can still occur although rare.\n\t\t\t\tshowTimeoutId = setTimeout( () => {\n\t\t\t\t\tcurrentElement.style.visibility = previousVisibility;\n\t\t\t\t}, 10 );\n\t\t\t} );\n\t\t} );\n\n\t\t// Watch for size changes\n\t\tlet resizeObserver;\n\t\tif ( window.ResizeObserver && currentElement.parentElement ) {\n\t\t\tresizeObserver = new window.ResizeObserver( applyFitText );\n\t\t\tresizeObserver.observe( currentElement.parentElement );\n\t\t\tresizeObserver.observe( currentElement );\n\t\t}\n\n\t\t// Cleanup function\n\t\treturn () => {\n\t\t\t// Cancel pending async operations\n\t\t\tif ( hideFrameId !== null ) {\n\t\t\t\twindow.cancelAnimationFrame( hideFrameId );\n\t\t\t}\n\t\t\tif ( calculateFrameId !== null ) {\n\t\t\t\twindow.cancelAnimationFrame( calculateFrameId );\n\t\t\t}\n\t\t\tif ( showTimeoutId !== null ) {\n\t\t\t\tclearTimeout( showTimeoutId );\n\t\t\t}\n\n\t\t\tif ( resizeObserver ) {\n\t\t\t\tresizeObserver.disconnect();\n\t\t\t}\n\n\t\t\tconst styleId = `fit-text-${ clientId }`;\n\t\t\tconst styleElement =\n\t\t\t\tcurrentElement.ownerDocument.getElementById( styleId );\n\t\t\tif ( styleElement ) {\n\t\t\t\tstyleElement.remove();\n\t\t\t}\n\t\t};\n\t}, [\n\t\tfitText,\n\t\tclientId,\n\t\tparentId,\n\t\tapplyFitText,\n\t\tblockElement,\n\t\thasFitTextSupport,\n\t\tblockMode,\n\t] );\n\n\t// Trigger fit text recalculation when content changes\n\tuseEffect( () => {\n\t\tif (\n\t\t\tfitText &&\n\t\t\tblockElement &&\n\t\t\thasFitTextSupport &&\n\t\t\tblockMode !== 'html'\n\t\t) {\n\t\t\t// Wait for next frame to ensure DOM has updated after content changes\n\t\t\tconst frameId = window.requestAnimationFrame( () => {\n\t\t\t\tif ( blockElement ) {\n\t\t\t\t\tapplyFitText();\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\treturn () => window.cancelAnimationFrame( frameId );\n\t\t}\n\t}, [\n\t\tblockAttributes,\n\t\tfitText,\n\t\tapplyFitText,\n\t\tblockElement,\n\t\thasFitTextSupport,\n\t\tblockMode,\n\t] );\n\n\treturn { fontSize };\n}\n\n/**\n * Fit text control component for the typography panel.\n *\n * @param {Object} props Component props.\n * @param {string} props.clientId Block client ID.\n * @param {Function} props.setAttributes Function to set block attributes.\n * @param {string} props.name Block name.\n * @param {boolean} props.fitText Whether fit text is enabled.\n * @param {string} props.fontSize Font size slug.\n * @param {Object} props.style Block style object.\n */\nexport function FitTextControl( {\n\tclientId,\n\tfitText = false,\n\tsetAttributes,\n\tname,\n\tfontSize,\n\tstyle,\n} ) {\n\tconst hasSelectedStyleState = useSelect(\n\t\t( select ) => {\n\t\t\tconst { hasSelectedStyleState: hasSelectedBlockStyleState } =\n\t\t\t\tunlock( select( blockEditorStore ) );\n\n\t\t\treturn hasSelectedBlockStyleState( clientId );\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tif ( ! hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn null;\n\t}\n\n\tif ( hasSelectedStyleState ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<ToolsPanelItem\n\t\t\thasValue={ () => fitText }\n\t\t\tlabel={ __( 'Fit text' ) }\n\t\t\tonDeselect={ () => setAttributes( { fitText: undefined } ) }\n\t\t\tresetAllFilter={ () => ( { fitText: undefined } ) }\n\t\t\tpanelId={ clientId }\n\t\t>\n\t\t\t<ToggleControl\n\t\t\t\tlabel={ __( 'Fit text' ) }\n\t\t\t\tchecked={ fitText }\n\t\t\t\tonChange={ () => {\n\t\t\t\t\tconst newFitText = ! fitText || undefined;\n\t\t\t\t\tconst updates = { fitText: newFitText };\n\n\t\t\t\t\t// When enabling fit text, clear font size if it has a value\n\t\t\t\t\tif ( newFitText ) {\n\t\t\t\t\t\tif ( fontSize ) {\n\t\t\t\t\t\t\tupdates.fontSize = undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( style?.typography?.fontSize ) {\n\t\t\t\t\t\t\tupdates.style = {\n\t\t\t\t\t\t\t\t...style,\n\t\t\t\t\t\t\t\ttypography: {\n\t\t\t\t\t\t\t\t\t...style?.typography,\n\t\t\t\t\t\t\t\t\tfontSize: undefined,\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\n\t\t\t\t\tsetAttributes( updates );\n\t\t\t\t} }\n\t\t\t\thelp={\n\t\t\t\t\tfitText\n\t\t\t\t\t\t? __( 'Text will resize to fit its container.' )\n\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t'The text will resize to fit its container, resetting other font size settings.'\n\t\t\t\t\t\t )\n\t\t\t\t}\n\t\t\t/>\n\t\t</ToolsPanelItem>\n\t);\n}\n\n/**\n * Override props applied to the block element on save.\n *\n * @param {Object} props Additional props applied to the block element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Block attributes.\n * @return {Object} Filtered props applied to the block element.\n */\nfunction addSaveProps( props, blockType, attributes ) {\n\tif ( ! hasBlockSupport( blockType, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn props;\n\t}\n\n\tconst { fitText } = attributes;\n\n\tif ( ! fitText ) {\n\t\treturn props;\n\t}\n\n\t// Add CSS class for frontend detection and styling\n\tconst className = props.className\n\t\t? `${ props.className } has-fit-text`\n\t\t: 'has-fit-text';\n\n\treturn {\n\t\t...props,\n\t\tclassName,\n\t};\n}\n\n/**\n * Override props applied to the block element in the editor.\n *\n * @param {Object} props Component props including block attributes.\n * @param {string} props.name Block name.\n * @param {boolean} props.fitText Whether fit text is enabled.\n * @return {Object} Filtered props applied to the block element.\n */\nfunction useBlockProps( { name, fitText } ) {\n\tif ( fitText && hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn {\n\t\t\tclassName: 'has-fit-text',\n\t\t};\n\t}\n\treturn {};\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/fit-text/addAttribute',\n\taddAttributes\n);\n\nconst hasFitTextSupport = ( blockNameOrType ) => {\n\treturn hasBlockSupport( blockNameOrType, FIT_TEXT_SUPPORT_KEY );\n};\n\n/**\n * Component that handles the fit text font size and displays a warning\n * if the fit text font size is below a minimum threshold.\n *\n * @param {Object} props Component props.\n * @param {boolean} props.fitText Whether fit text is enabled.\n * @param {string} props.name Block name.\n * @param {string} props.clientId Block client ID.\n * @param {boolean} props.isSelected Whether the block is selected.\n * @return {Element|null} Warning component or null.\n */\nfunction FitTextFontSize( { fitText, name, clientId, isSelected } ) {\n\tconst { fontSize } = useFitText( { fitText, name, clientId } );\n\tif ( isSelected && fontSize && fontSize < MIN_FONT_SIZE_FOR_WARNING ) {\n\t\treturn (\n\t\t\t<InspectorControls group=\"typography\">\n\t\t\t\t<FitTextSizeWarning />\n\t\t\t</InspectorControls>\n\t\t);\n\t}\n\treturn null;\n}\n\n/*\n * Fit-text requires that layout calculations be done even when a block is not\n * currently selected. Therefore, the regular hooking approach using an\n * exported `edit` method is not enough, and we must use this HoC with the\n * `editor.BlockEdit` filter.\n */\nconst addFitTextControl = createHigherOrderComponent( ( BlockEdit ) => {\n\treturn function AddFitTextControl( props ) {\n\t\tconst { name, attributes, clientId, isSelected, setAttributes } = props;\n\t\tconst { fitText } = attributes;\n\t\tconst supportsFitText = hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY );\n\t\tif ( ! supportsFitText ) {\n\t\t\treturn <BlockEdit { ...props } />;\n\t\t}\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t\t<InspectorControls group=\"typography\">\n\t\t\t\t\t<FitTextControl\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tfitText={ fitText }\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\tname={ name }\n\t\t\t\t\t\tfontSize={ attributes.fontSize }\n\t\t\t\t\t\tstyle={ attributes.style }\n\t\t\t\t\t/>\n\t\t\t\t</InspectorControls>\n\t\t\t\t{ fitText && (\n\t\t\t\t\t<FitTextFontSize\n\t\t\t\t\t\tfitText={ fitText }\n\t\t\t\t\t\tname={ name }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t};\n}, 'addFitTextControl' );\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/fit-text/add-fit-text-control',\n\taddFitTextControl\n);\n\nexport default {\n\tuseBlockProps,\n\taddSaveProps,\n\tattributeKeys: [ 'fitText', 'fontSize', 'style' ],\n\thasSupport: hasFitTextSupport,\n\tedit: () => null,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAA0B;AAC1B,oBAAgC;AAChC,qBAAiD;AACjD,kBAA0B;AAC1B,kBAAmB;AACnB,wBAGO;AACP,qBAA2C;AAQ3C,4BAAgC;AAChC,mBAA0C;AAC1C,4BAAgC;AAChC,gCAA8B;AAC9B,mCAA+B;AAC/B,yBAAuB;AA4PpB;AAvQH,IAAM,eAAe,CAAC;AACtB,IAAM,4BAA4B;AAY3B,IAAM,uBAAuB;AASpC,SAAS,cAAe,UAAW;AAClC,MAAK,KAAE,+BAAiB,UAAU,oBAAqB,GAAI;AAC1D,WAAO;AAAA,EACR;AAGA,MAAK,SAA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,EAAmB,GACrB;AAAA,EAEF;AACA,SAAO;AACR;AAQA,IAAM,wBAAoB,2CAA4B,CAAE,cAAe;AACtE,SAAO,SAAS,kBAAmB,OAAQ;AAC1C,UAAM,EAAE,MAAM,YAAY,UAAU,YAAY,cAAc,IAAI;AAClE,UAAM,EAAE,QAAQ,IAAI;AACpB,UAAM,sBAAkB,+BAAiB,MAAM,oBAAqB;AACpE,QAAK,CAAE,iBAAkB;AACxB,aAAO,4CAAC,aAAY,GAAG,OAAQ;AAAA,IAChC;AACA,WACC,4EACC;AAAA,kDAAC,aAAY,GAAG,OAAQ;AAAA,MACxB,4CAAC,0BAAAD,SAAA,EAAkB,OAAM,cACxB;AAAA,QAAC;AAAA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,UAAW,WAAW;AAAA,UACtB,OAAQ,WAAW;AAAA;AAAA,MACpB,GACD;AAAA,MACE,WACD;AAAA,QAAC;AAAA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA;AAAA,MACD;AAAA,OAEF;AAAA,EAEF;AACD,GAAG,mBAAoB;AAAA,IAEvB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;AAEA,IAAO,mBAAQ;AAAA,EACd;AAAA,EACA;AAAA,EACA,eAAe,CAAE,WAAW,YAAY,OAAQ;AAAA,EAChD,YAAY;AAAA,EACZ,MAAM,MAAM;AACb;",
|
|
6
6
|
"names": ["hasFitTextSupport", "blockEditorStore", "ToolsPanelItem", "InspectorControls", "FitTextSizeWarning"]
|
|
7
7
|
}
|
|
@@ -52,6 +52,19 @@ var RESPONSIVE_BREAKPOINTS = {
|
|
|
52
52
|
mobile: "@media (width <= 480px)",
|
|
53
53
|
tablet: "@media (480px < width <= 782px)"
|
|
54
54
|
};
|
|
55
|
+
var FLEX_CHILD_LAYOUT_VALUES = {
|
|
56
|
+
fit: "fit",
|
|
57
|
+
grow: "fill",
|
|
58
|
+
max: "fixed",
|
|
59
|
+
fixed: "fixedNoShrink"
|
|
60
|
+
};
|
|
61
|
+
var FLEX_SIZE_VALUES = [
|
|
62
|
+
FLEX_CHILD_LAYOUT_VALUES.max,
|
|
63
|
+
FLEX_CHILD_LAYOUT_VALUES.fixed
|
|
64
|
+
];
|
|
65
|
+
function isFlexSizeValue(value) {
|
|
66
|
+
return FLEX_SIZE_VALUES.includes(value);
|
|
67
|
+
}
|
|
55
68
|
function serializeRule({ selector, declarations }) {
|
|
56
69
|
return `${selector} {
|
|
57
70
|
${Object.entries(declarations).map(([property, value]) => `${property}: ${value}`).join("; ")};
|
|
@@ -78,14 +91,26 @@ function getChildLayoutStyleRules({
|
|
|
78
91
|
columnSpan,
|
|
79
92
|
rowSpan
|
|
80
93
|
} = effectiveLayout;
|
|
94
|
+
const baseSelfStretch = layout.selfStretch;
|
|
81
95
|
const { columnCount, minimumColumnWidth } = parentLayout;
|
|
82
96
|
const rules = [];
|
|
83
97
|
const declarations = {};
|
|
84
98
|
if (!hasViewportOverrides || hasViewportOverride("selfStretch") || hasViewportOverride("flexSize")) {
|
|
85
|
-
if (selfStretch ===
|
|
99
|
+
if (hasViewportOverrides && (selfStretch === FLEX_CHILD_LAYOUT_VALUES.fit || selfStretch === FLEX_CHILD_LAYOUT_VALUES.grow) && isFlexSizeValue(baseSelfStretch) && layout.flexSize) {
|
|
100
|
+
declarations["flex-basis"] = "unset";
|
|
101
|
+
if (baseSelfStretch === FLEX_CHILD_LAYOUT_VALUES.fixed) {
|
|
102
|
+
declarations["flex-shrink"] = "unset";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (isFlexSizeValue(selfStretch) && flexSize) {
|
|
86
106
|
declarations["flex-basis"] = flexSize;
|
|
107
|
+
if (selfStretch === FLEX_CHILD_LAYOUT_VALUES.fixed) {
|
|
108
|
+
declarations["flex-shrink"] = "0";
|
|
109
|
+
} else if (hasViewportOverrides && baseSelfStretch === FLEX_CHILD_LAYOUT_VALUES.fixed) {
|
|
110
|
+
declarations["flex-shrink"] = "unset";
|
|
111
|
+
}
|
|
87
112
|
declarations["box-sizing"] = "border-box";
|
|
88
|
-
} else if (selfStretch ===
|
|
113
|
+
} else if (selfStretch === FLEX_CHILD_LAYOUT_VALUES.grow) {
|
|
89
114
|
declarations["flex-grow"] = "1";
|
|
90
115
|
}
|
|
91
116
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/layout-child.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useInstanceId } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { useStyleOverride } from './utils';\nimport { useLayout } from '../components/block-list/layout';\nimport {\n\tGridVisualizer,\n\tGridItemResizer,\n\tGridItemMovers,\n} from '../components/grid';\nimport useBlockVisibility from '../components/block-visibility/use-block-visibility';\nimport { deviceTypeKey } from '../store/private-keys';\nimport { BLOCK_VISIBILITY_VIEWPORTS } from '../components/block-visibility/constants';\n\n// Used for generating the instance ID\nconst LAYOUT_CHILD_BLOCK_PROPS_REFERENCE = {};\n// Keep in sync with WP_Theme_JSON_Gutenberg::RESPONSIVE_BREAKPOINTS.\nconst RESPONSIVE_BREAKPOINTS = {\n\tmobile: '@media (width <= 480px)',\n\ttablet: '@media (480px < width <= 782px)',\n};\n\nfunction serializeRule( { selector, declarations } ) {\n\treturn `${ selector } {\n\t\t${ Object.entries( declarations )\n\t\t\t.map( ( [ property, value ] ) => `${ property }: ${ value }` )\n\t\t\t.join( '; ' ) };\n\t}`;\n}\n\nexport function getChildLayoutStyleRules( {\n\tselector,\n\tlayout = {},\n\tviewportOverrides,\n\tparentLayout = {},\n\tincludeContainerQuery = true,\n} ) {\n\tconst hasViewportOverrides = viewportOverrides !== undefined;\n\tconst effectiveLayout = hasViewportOverrides\n\t\t? {\n\t\t\t\t...layout,\n\t\t\t\t...viewportOverrides,\n\t\t }\n\t\t: layout;\n\tconst hasViewportOverride = ( key ) =>\n\t\tObject.hasOwn( viewportOverrides || {}, key );\n\tconst {\n\t\tselfStretch,\n\t\tflexSize,\n\t\tcolumnStart,\n\t\trowStart,\n\t\tcolumnSpan,\n\t\trowSpan,\n\t} = effectiveLayout;\n\tconst { columnCount, minimumColumnWidth } = parentLayout;\n\tconst rules = [];\n\n\tconst declarations = {};\n\tif (\n\t\t! hasViewportOverrides ||\n\t\thasViewportOverride( 'selfStretch' ) ||\n\t\thasViewportOverride( 'flexSize' )\n\t) {\n\t\tif ( selfStretch === 'fixed' && flexSize ) {\n\t\t\tdeclarations[ 'flex-basis' ] = flexSize;\n\t\t\tdeclarations[ 'box-sizing' ] = 'border-box';\n\t\t} else if ( selfStretch === 'fill' ) {\n\t\t\tdeclarations[ 'flex-grow' ] = '1';\n\t\t}\n\t}\n\n\tif (\n\t\t! hasViewportOverrides ||\n\t\thasViewportOverride( 'columnStart' ) ||\n\t\thasViewportOverride( 'columnSpan' )\n\t) {\n\t\tif ( columnStart && columnSpan ) {\n\t\t\tdeclarations[\n\t\t\t\t'grid-column'\n\t\t\t] = `${ columnStart } / span ${ columnSpan }`;\n\t\t} else if ( columnStart ) {\n\t\t\tdeclarations[ 'grid-column' ] = `${ columnStart }`;\n\t\t} else if ( columnSpan ) {\n\t\t\tdeclarations[ 'grid-column' ] = `span ${ columnSpan }`;\n\t\t}\n\t}\n\n\tif (\n\t\t! hasViewportOverrides ||\n\t\thasViewportOverride( 'rowStart' ) ||\n\t\thasViewportOverride( 'rowSpan' )\n\t) {\n\t\tif ( rowStart && rowSpan ) {\n\t\t\tdeclarations[ 'grid-row' ] = `${ rowStart } / span ${ rowSpan }`;\n\t\t} else if ( rowStart ) {\n\t\t\tdeclarations[ 'grid-row' ] = `${ rowStart }`;\n\t\t} else if ( rowSpan ) {\n\t\t\tdeclarations[ 'grid-row' ] = `span ${ rowSpan }`;\n\t\t}\n\t}\n\n\tif ( Object.keys( declarations ).length ) {\n\t\trules.push( { selector, declarations } );\n\t}\n\n\tif ( includeContainerQuery && ! hasViewportOverrides ) {\n\t\t/**\n\t\t * If minimumColumnWidth is set on the parent, or if no\n\t\t * columnCount is set, the grid is responsive so a\n\t\t * container query is needed for the span to resize.\n\t\t */\n\t\tif (\n\t\t\t( columnSpan || columnStart ) &&\n\t\t\t( minimumColumnWidth || ! columnCount )\n\t\t) {\n\t\t\tlet parentColumnValue = parseFloat( minimumColumnWidth );\n\t\t\t/**\n\t\t\t * 12rem is the default minimumColumnWidth value.\n\t\t\t * If parentColumnValue is not a number, default to 12.\n\t\t\t */\n\t\t\tif ( isNaN( parentColumnValue ) ) {\n\t\t\t\tparentColumnValue = 12;\n\t\t\t}\n\n\t\t\tlet parentColumnUnit = minimumColumnWidth?.replace(\n\t\t\t\tparentColumnValue,\n\t\t\t\t''\n\t\t\t);\n\t\t\t/**\n\t\t\t * Check that parent column unit is either 'px', 'rem' or 'em'.\n\t\t\t * If not, default to 'rem'.\n\t\t\t */\n\t\t\tif ( ! [ 'px', 'rem', 'em' ].includes( parentColumnUnit ) ) {\n\t\t\t\tparentColumnUnit = 'rem';\n\t\t\t}\n\n\t\t\tlet numColsToBreakAt = 2;\n\n\t\t\tif ( columnSpan && columnStart ) {\n\t\t\t\tnumColsToBreakAt = columnSpan + columnStart - 1;\n\t\t\t} else if ( columnSpan ) {\n\t\t\t\tnumColsToBreakAt = columnSpan;\n\t\t\t} else {\n\t\t\t\tnumColsToBreakAt = columnStart;\n\t\t\t}\n\n\t\t\tconst defaultGapValue = parentColumnUnit === 'px' ? 24 : 1.5;\n\t\t\tconst containerQueryValue =\n\t\t\t\tnumColsToBreakAt * parentColumnValue +\n\t\t\t\t( numColsToBreakAt - 1 ) * defaultGapValue;\n\t\t\t// For blocks that only span one column, we want to remove any rowStart values as\n\t\t\t// the container reduces in size, so that blocks are still arranged in markup order.\n\t\t\tconst minimumContainerQueryValue =\n\t\t\t\tparentColumnValue * 2 + defaultGapValue - 1;\n\t\t\t// If a span is set we want to preserve it as long as possible, otherwise we just reset the value.\n\t\t\tconst gridColumnValue =\n\t\t\t\tcolumnSpan && columnSpan > 1 ? '1/-1' : 'auto';\n\n\t\t\trules.push( {\n\t\t\t\trulesGroup: `@container (max-width: ${ Math.max(\n\t\t\t\t\tcontainerQueryValue,\n\t\t\t\t\tminimumContainerQueryValue\n\t\t\t\t) }${ parentColumnUnit })`,\n\t\t\t\tselector,\n\t\t\t\tdeclarations: {\n\t\t\t\t\t'grid-column': gridColumnValue,\n\t\t\t\t\t'grid-row': 'auto',\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\t}\n\n\treturn rules;\n}\n\nexport function getChildLayoutStyles( {\n\tselector,\n\tlayout = {},\n\tparentLayout = {},\n\tincludeContainerQuery = true,\n} ) {\n\treturn getChildLayoutStyleRules( {\n\t\tselector,\n\t\tlayout,\n\t\tparentLayout,\n\t\tincludeContainerQuery,\n\t} )\n\t\t.map( ( rule ) => {\n\t\t\tconst serializedRule = serializeRule( rule );\n\t\t\treturn rule.rulesGroup\n\t\t\t\t? `${ rule.rulesGroup } {\n\t\t\t\t${ serializedRule }\n\t\t\t}`\n\t\t\t\t: serializedRule;\n\t\t} )\n\t\t.join( '' );\n}\n\nexport function getResponsiveChildLayoutStyles( {\n\tstyle = {},\n\tselector,\n\tparentLayout = {},\n} ) {\n\tconst baseLayout = style?.layout ?? {};\n\n\treturn Object.entries( RESPONSIVE_BREAKPOINTS )\n\t\t.map( ( [ viewport, mediaQuery ] ) => {\n\t\t\tconst viewportLayout = style?.[ viewport ]?.layout;\n\t\t\tif ( ! viewportLayout || ! Object.keys( viewportLayout ).length ) {\n\t\t\t\treturn '';\n\t\t\t}\n\n\t\t\tconst viewportRules = getChildLayoutStyleRules( {\n\t\t\t\tselector,\n\t\t\t\tlayout: baseLayout,\n\t\t\t\tviewportOverrides: viewportLayout,\n\t\t\t\tparentLayout,\n\t\t\t\tincludeContainerQuery: false,\n\t\t\t} );\n\t\t\tconst css = viewportRules.map( serializeRule ).join( '' );\n\n\t\t\treturn css ? `${ mediaQuery }{${ css }}` : '';\n\t\t} )\n\t\t.filter( Boolean )\n\t\t.join( '' );\n}\n\nfunction useBlockPropsChildLayoutStyles( { style } ) {\n\tconst shouldRenderChildLayoutStyles = useSelect( ( select ) => {\n\t\treturn ! select( blockEditorStore ).getSettings().disableLayoutStyles;\n\t} );\n\tconst layout = style?.layout ?? {};\n\tconst { columnStart, rowStart, columnSpan, rowSpan } = layout;\n\tconst parentLayout = useLayout() || {};\n\tconst id = useInstanceId( LAYOUT_CHILD_BLOCK_PROPS_REFERENCE );\n\tconst selector = `.wp-container-content-${ id }`;\n\n\t// Check that the grid layout attributes are of the correct type, so that we don't accidentally\n\t// write code that stores a string attribute instead of a number.\n\tif ( process.env.NODE_ENV === 'development' ) {\n\t\tif ( columnStart && typeof columnStart !== 'number' ) {\n\t\t\tthrow new Error( 'columnStart must be a number' );\n\t\t}\n\t\tif ( rowStart && typeof rowStart !== 'number' ) {\n\t\t\tthrow new Error( 'rowStart must be a number' );\n\t\t}\n\t\tif ( columnSpan && typeof columnSpan !== 'number' ) {\n\t\t\tthrow new Error( 'columnSpan must be a number' );\n\t\t}\n\t\tif ( rowSpan && typeof rowSpan !== 'number' ) {\n\t\t\tthrow new Error( 'rowSpan must be a number' );\n\t\t}\n\t}\n\n\tlet css = '';\n\tif ( shouldRenderChildLayoutStyles ) {\n\t\tcss = [\n\t\t\tgetChildLayoutStyles( {\n\t\t\t\tselector,\n\t\t\t\tlayout,\n\t\t\t\tparentLayout,\n\t\t\t} ),\n\t\t\tgetResponsiveChildLayoutStyles( {\n\t\t\t\tstyle,\n\t\t\t\tselector,\n\t\t\t\tparentLayout,\n\t\t\t} ),\n\t\t].join( '' );\n\t}\n\n\tuseStyleOverride( { css } );\n\n\t// Only attach a container class if there is generated CSS to be attached.\n\tif ( ! css ) {\n\t\treturn;\n\t}\n\n\t// Attach a `wp-container-content` id-based classname.\n\treturn { className: `wp-container-content-${ id }` };\n}\n\nfunction ChildLayoutControlsPure( { clientId, style, setAttributes } ) {\n\tconst parentLayout = useLayout() || {};\n\tconst {\n\t\ttype: parentLayoutType = 'default',\n\t\tallowSizingOnChildren = false,\n\t\tisManualPlacement,\n\t} = parentLayout;\n\n\tif ( parentLayoutType !== 'grid' ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<GridTools\n\t\t\tclientId={ clientId }\n\t\t\tstyle={ style }\n\t\t\tsetAttributes={ setAttributes }\n\t\t\tallowSizingOnChildren={ allowSizingOnChildren }\n\t\t\tisManualPlacement={ isManualPlacement }\n\t\t\tparentLayout={ parentLayout }\n\t\t/>\n\t);\n}\n\nfunction GridTools( {\n\tclientId,\n\tstyle,\n\tsetAttributes,\n\tallowSizingOnChildren,\n\tisManualPlacement,\n\tparentLayout,\n} ) {\n\tconst {\n\t\trootClientId,\n\t\tisVisible,\n\t\tparentBlockVisibility,\n\t\tblockBlockVisibility,\n\t\tdeviceType,\n\t\tisChildBlockAGrid,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\tgetBlockEditingMode,\n\t\t\t\tgetTemplateLock,\n\t\t\t\tgetBlockAttributes,\n\t\t\t\tgetSettings,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst _rootClientId = getBlockRootClientId( clientId );\n\n\t\t\tif (\n\t\t\t\tgetTemplateLock( _rootClientId ) ||\n\t\t\t\tgetBlockEditingMode( _rootClientId ) !== 'default'\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\trootClientId: _rootClientId,\n\t\t\t\t\tisVisible: false,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst parentAttributes = getBlockAttributes( _rootClientId );\n\t\t\tconst blockAttributes = getBlockAttributes( clientId );\n\t\t\tconst settings = getSettings();\n\n\t\t\treturn {\n\t\t\t\trootClientId: _rootClientId,\n\t\t\t\tisVisible: true,\n\t\t\t\tparentBlockVisibility:\n\t\t\t\t\tparentAttributes?.metadata?.blockVisibility,\n\t\t\t\tblockBlockVisibility:\n\t\t\t\t\tblockAttributes?.metadata?.blockVisibility,\n\t\t\t\tdeviceType:\n\t\t\t\t\tsettings?.[ deviceTypeKey ]?.toLowerCase() ||\n\t\t\t\t\tBLOCK_VISIBILITY_VIEWPORTS.desktop.key,\n\t\t\t\t// Check if the selected child block is itself a grid.\n\t\t\t\tisChildBlockAGrid: blockAttributes?.layout?.type === 'grid',\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { isBlockCurrentlyHidden: isParentBlockCurrentlyHidden } =\n\t\tuseBlockVisibility( {\n\t\t\tblockVisibility: parentBlockVisibility,\n\t\t\tdeviceType,\n\t\t} );\n\n\tconst { isBlockCurrentlyHidden: isBlockItselfCurrentlyHidden } =\n\t\tuseBlockVisibility( {\n\t\t\tblockVisibility: blockBlockVisibility,\n\t\t\tdeviceType,\n\t\t} );\n\n\t// Use useState() instead of useRef() so that GridItemResizer updates when ref is set.\n\tconst [ resizerBounds, setResizerBounds ] = useState();\n\n\tconst childGridClientId = isChildBlockAGrid ? clientId : undefined;\n\n\tif ( ! isVisible || isParentBlockCurrentlyHidden ) {\n\t\treturn null;\n\t}\n\n\tconst showResizer = allowSizingOnChildren && ! isBlockItselfCurrentlyHidden;\n\n\tfunction updateLayout( layout ) {\n\t\tsetAttributes( {\n\t\t\tstyle: {\n\t\t\t\t...style,\n\t\t\t\tlayout: {\n\t\t\t\t\t...style?.layout,\n\t\t\t\t\t...layout,\n\t\t\t\t},\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<GridVisualizer\n\t\t\t\tclientId={ rootClientId }\n\t\t\t\tcontentRef={ setResizerBounds }\n\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\tchildGridClientId={ childGridClientId }\n\t\t\t/>\n\t\t\t{ showResizer && (\n\t\t\t\t<GridItemResizer\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t// Don't allow resizing beyond the grid visualizer.\n\t\t\t\t\tbounds={ resizerBounds }\n\t\t\t\t\tonChange={ updateLayout }\n\t\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ isManualPlacement &&\n\t\t\t\twindow.__experimentalEnableGridInteractivity && (\n\t\t\t\t\t<GridItemMovers\n\t\t\t\t\t\tlayout={ style?.layout }\n\t\t\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\t\t\tonChange={ updateLayout }\n\t\t\t\t\t\tgridClientId={ rootClientId }\n\t\t\t\t\t\tblockClientId={ clientId }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default {\n\tuseBlockProps: useBlockPropsChildLayoutStyles,\n\tedit: ChildLayoutControlsPure,\n\tattributeKeys: [ 'style' ],\n\thasSupport() {\n\t\treturn true;\n\t},\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA8B;AAC9B,kBAA0B;AAC1B,qBAAyB;AAKzB,mBAA0C;AAC1C,mBAAiC;AACjC,oBAA0B;AAC1B,kBAIO;AACP,kCAA+B;AAC/B,0BAA8B;AAC9B,uBAA2C;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useInstanceId } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { useStyleOverride } from './utils';\nimport { useLayout } from '../components/block-list/layout';\nimport {\n\tGridVisualizer,\n\tGridItemResizer,\n\tGridItemMovers,\n} from '../components/grid';\nimport useBlockVisibility from '../components/block-visibility/use-block-visibility';\nimport { deviceTypeKey } from '../store/private-keys';\nimport { BLOCK_VISIBILITY_VIEWPORTS } from '../components/block-visibility/constants';\n\n// Used for generating the instance ID\nconst LAYOUT_CHILD_BLOCK_PROPS_REFERENCE = {};\n// Keep in sync with WP_Theme_JSON_Gutenberg::RESPONSIVE_BREAKPOINTS.\nconst RESPONSIVE_BREAKPOINTS = {\n\tmobile: '@media (width <= 480px)',\n\ttablet: '@media (480px < width <= 782px)',\n};\n\n// These are the serialized `selfStretch` values. `max` used to be called\n// \"Fixed\" in the UI, but was renamed and replaced by `fixedNoShrink`.\nconst FLEX_CHILD_LAYOUT_VALUES = {\n\tfit: 'fit',\n\tgrow: 'fill',\n\tmax: 'fixed',\n\tfixed: 'fixedNoShrink',\n};\n\nconst FLEX_SIZE_VALUES = [\n\tFLEX_CHILD_LAYOUT_VALUES.max,\n\tFLEX_CHILD_LAYOUT_VALUES.fixed,\n];\n\nfunction isFlexSizeValue( value ) {\n\treturn FLEX_SIZE_VALUES.includes( value );\n}\n\nfunction serializeRule( { selector, declarations } ) {\n\treturn `${ selector } {\n\t\t${ Object.entries( declarations )\n\t\t\t.map( ( [ property, value ] ) => `${ property }: ${ value }` )\n\t\t\t.join( '; ' ) };\n\t}`;\n}\n\nexport function getChildLayoutStyleRules( {\n\tselector,\n\tlayout = {},\n\tviewportOverrides,\n\tparentLayout = {},\n\tincludeContainerQuery = true,\n} ) {\n\tconst hasViewportOverrides = viewportOverrides !== undefined;\n\tconst effectiveLayout = hasViewportOverrides\n\t\t? {\n\t\t\t\t...layout,\n\t\t\t\t...viewportOverrides,\n\t\t }\n\t\t: layout;\n\tconst hasViewportOverride = ( key ) =>\n\t\tObject.hasOwn( viewportOverrides || {}, key );\n\tconst {\n\t\tselfStretch,\n\t\tflexSize,\n\t\tcolumnStart,\n\t\trowStart,\n\t\tcolumnSpan,\n\t\trowSpan,\n\t} = effectiveLayout;\n\tconst baseSelfStretch = layout.selfStretch;\n\tconst { columnCount, minimumColumnWidth } = parentLayout;\n\tconst rules = [];\n\n\tconst declarations = {};\n\tif (\n\t\t! hasViewportOverrides ||\n\t\thasViewportOverride( 'selfStretch' ) ||\n\t\thasViewportOverride( 'flexSize' )\n\t) {\n\t\tif (\n\t\t\thasViewportOverrides &&\n\t\t\t( selfStretch === FLEX_CHILD_LAYOUT_VALUES.fit ||\n\t\t\t\tselfStretch === FLEX_CHILD_LAYOUT_VALUES.grow ) &&\n\t\t\tisFlexSizeValue( baseSelfStretch ) &&\n\t\t\tlayout.flexSize\n\t\t) {\n\t\t\tdeclarations[ 'flex-basis' ] = 'unset';\n\t\t\tif ( baseSelfStretch === FLEX_CHILD_LAYOUT_VALUES.fixed ) {\n\t\t\t\tdeclarations[ 'flex-shrink' ] = 'unset';\n\t\t\t}\n\t\t}\n\t\tif ( isFlexSizeValue( selfStretch ) && flexSize ) {\n\t\t\tdeclarations[ 'flex-basis' ] = flexSize;\n\t\t\tif ( selfStretch === FLEX_CHILD_LAYOUT_VALUES.fixed ) {\n\t\t\t\tdeclarations[ 'flex-shrink' ] = '0';\n\t\t\t} else if (\n\t\t\t\thasViewportOverrides &&\n\t\t\t\tbaseSelfStretch === FLEX_CHILD_LAYOUT_VALUES.fixed\n\t\t\t) {\n\t\t\t\tdeclarations[ 'flex-shrink' ] = 'unset';\n\t\t\t}\n\t\t\tdeclarations[ 'box-sizing' ] = 'border-box';\n\t\t} else if ( selfStretch === FLEX_CHILD_LAYOUT_VALUES.grow ) {\n\t\t\tdeclarations[ 'flex-grow' ] = '1';\n\t\t}\n\t}\n\n\tif (\n\t\t! hasViewportOverrides ||\n\t\thasViewportOverride( 'columnStart' ) ||\n\t\thasViewportOverride( 'columnSpan' )\n\t) {\n\t\tif ( columnStart && columnSpan ) {\n\t\t\tdeclarations[\n\t\t\t\t'grid-column'\n\t\t\t] = `${ columnStart } / span ${ columnSpan }`;\n\t\t} else if ( columnStart ) {\n\t\t\tdeclarations[ 'grid-column' ] = `${ columnStart }`;\n\t\t} else if ( columnSpan ) {\n\t\t\tdeclarations[ 'grid-column' ] = `span ${ columnSpan }`;\n\t\t}\n\t}\n\n\tif (\n\t\t! hasViewportOverrides ||\n\t\thasViewportOverride( 'rowStart' ) ||\n\t\thasViewportOverride( 'rowSpan' )\n\t) {\n\t\tif ( rowStart && rowSpan ) {\n\t\t\tdeclarations[ 'grid-row' ] = `${ rowStart } / span ${ rowSpan }`;\n\t\t} else if ( rowStart ) {\n\t\t\tdeclarations[ 'grid-row' ] = `${ rowStart }`;\n\t\t} else if ( rowSpan ) {\n\t\t\tdeclarations[ 'grid-row' ] = `span ${ rowSpan }`;\n\t\t}\n\t}\n\n\tif ( Object.keys( declarations ).length ) {\n\t\trules.push( { selector, declarations } );\n\t}\n\n\tif ( includeContainerQuery && ! hasViewportOverrides ) {\n\t\t/**\n\t\t * If minimumColumnWidth is set on the parent, or if no\n\t\t * columnCount is set, the grid is responsive so a\n\t\t * container query is needed for the span to resize.\n\t\t */\n\t\tif (\n\t\t\t( columnSpan || columnStart ) &&\n\t\t\t( minimumColumnWidth || ! columnCount )\n\t\t) {\n\t\t\tlet parentColumnValue = parseFloat( minimumColumnWidth );\n\t\t\t/**\n\t\t\t * 12rem is the default minimumColumnWidth value.\n\t\t\t * If parentColumnValue is not a number, default to 12.\n\t\t\t */\n\t\t\tif ( isNaN( parentColumnValue ) ) {\n\t\t\t\tparentColumnValue = 12;\n\t\t\t}\n\n\t\t\tlet parentColumnUnit = minimumColumnWidth?.replace(\n\t\t\t\tparentColumnValue,\n\t\t\t\t''\n\t\t\t);\n\t\t\t/**\n\t\t\t * Check that parent column unit is either 'px', 'rem' or 'em'.\n\t\t\t * If not, default to 'rem'.\n\t\t\t */\n\t\t\tif ( ! [ 'px', 'rem', 'em' ].includes( parentColumnUnit ) ) {\n\t\t\t\tparentColumnUnit = 'rem';\n\t\t\t}\n\n\t\t\tlet numColsToBreakAt = 2;\n\n\t\t\tif ( columnSpan && columnStart ) {\n\t\t\t\tnumColsToBreakAt = columnSpan + columnStart - 1;\n\t\t\t} else if ( columnSpan ) {\n\t\t\t\tnumColsToBreakAt = columnSpan;\n\t\t\t} else {\n\t\t\t\tnumColsToBreakAt = columnStart;\n\t\t\t}\n\n\t\t\tconst defaultGapValue = parentColumnUnit === 'px' ? 24 : 1.5;\n\t\t\tconst containerQueryValue =\n\t\t\t\tnumColsToBreakAt * parentColumnValue +\n\t\t\t\t( numColsToBreakAt - 1 ) * defaultGapValue;\n\t\t\t// For blocks that only span one column, we want to remove any rowStart values as\n\t\t\t// the container reduces in size, so that blocks are still arranged in markup order.\n\t\t\tconst minimumContainerQueryValue =\n\t\t\t\tparentColumnValue * 2 + defaultGapValue - 1;\n\t\t\t// If a span is set we want to preserve it as long as possible, otherwise we just reset the value.\n\t\t\tconst gridColumnValue =\n\t\t\t\tcolumnSpan && columnSpan > 1 ? '1/-1' : 'auto';\n\n\t\t\trules.push( {\n\t\t\t\trulesGroup: `@container (max-width: ${ Math.max(\n\t\t\t\t\tcontainerQueryValue,\n\t\t\t\t\tminimumContainerQueryValue\n\t\t\t\t) }${ parentColumnUnit })`,\n\t\t\t\tselector,\n\t\t\t\tdeclarations: {\n\t\t\t\t\t'grid-column': gridColumnValue,\n\t\t\t\t\t'grid-row': 'auto',\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\t}\n\n\treturn rules;\n}\n\nexport function getChildLayoutStyles( {\n\tselector,\n\tlayout = {},\n\tparentLayout = {},\n\tincludeContainerQuery = true,\n} ) {\n\treturn getChildLayoutStyleRules( {\n\t\tselector,\n\t\tlayout,\n\t\tparentLayout,\n\t\tincludeContainerQuery,\n\t} )\n\t\t.map( ( rule ) => {\n\t\t\tconst serializedRule = serializeRule( rule );\n\t\t\treturn rule.rulesGroup\n\t\t\t\t? `${ rule.rulesGroup } {\n\t\t\t\t${ serializedRule }\n\t\t\t}`\n\t\t\t\t: serializedRule;\n\t\t} )\n\t\t.join( '' );\n}\n\nexport function getResponsiveChildLayoutStyles( {\n\tstyle = {},\n\tselector,\n\tparentLayout = {},\n} ) {\n\tconst baseLayout = style?.layout ?? {};\n\n\treturn Object.entries( RESPONSIVE_BREAKPOINTS )\n\t\t.map( ( [ viewport, mediaQuery ] ) => {\n\t\t\tconst viewportLayout = style?.[ viewport ]?.layout;\n\t\t\tif ( ! viewportLayout || ! Object.keys( viewportLayout ).length ) {\n\t\t\t\treturn '';\n\t\t\t}\n\n\t\t\tconst viewportRules = getChildLayoutStyleRules( {\n\t\t\t\tselector,\n\t\t\t\tlayout: baseLayout,\n\t\t\t\tviewportOverrides: viewportLayout,\n\t\t\t\tparentLayout,\n\t\t\t\tincludeContainerQuery: false,\n\t\t\t} );\n\t\t\tconst css = viewportRules.map( serializeRule ).join( '' );\n\n\t\t\treturn css ? `${ mediaQuery }{${ css }}` : '';\n\t\t} )\n\t\t.filter( Boolean )\n\t\t.join( '' );\n}\n\nfunction useBlockPropsChildLayoutStyles( { style } ) {\n\tconst shouldRenderChildLayoutStyles = useSelect( ( select ) => {\n\t\treturn ! select( blockEditorStore ).getSettings().disableLayoutStyles;\n\t} );\n\tconst layout = style?.layout ?? {};\n\tconst { columnStart, rowStart, columnSpan, rowSpan } = layout;\n\tconst parentLayout = useLayout() || {};\n\tconst id = useInstanceId( LAYOUT_CHILD_BLOCK_PROPS_REFERENCE );\n\tconst selector = `.wp-container-content-${ id }`;\n\n\t// Check that the grid layout attributes are of the correct type, so that we don't accidentally\n\t// write code that stores a string attribute instead of a number.\n\tif ( process.env.NODE_ENV === 'development' ) {\n\t\tif ( columnStart && typeof columnStart !== 'number' ) {\n\t\t\tthrow new Error( 'columnStart must be a number' );\n\t\t}\n\t\tif ( rowStart && typeof rowStart !== 'number' ) {\n\t\t\tthrow new Error( 'rowStart must be a number' );\n\t\t}\n\t\tif ( columnSpan && typeof columnSpan !== 'number' ) {\n\t\t\tthrow new Error( 'columnSpan must be a number' );\n\t\t}\n\t\tif ( rowSpan && typeof rowSpan !== 'number' ) {\n\t\t\tthrow new Error( 'rowSpan must be a number' );\n\t\t}\n\t}\n\n\tlet css = '';\n\tif ( shouldRenderChildLayoutStyles ) {\n\t\tcss = [\n\t\t\tgetChildLayoutStyles( {\n\t\t\t\tselector,\n\t\t\t\tlayout,\n\t\t\t\tparentLayout,\n\t\t\t} ),\n\t\t\tgetResponsiveChildLayoutStyles( {\n\t\t\t\tstyle,\n\t\t\t\tselector,\n\t\t\t\tparentLayout,\n\t\t\t} ),\n\t\t].join( '' );\n\t}\n\n\tuseStyleOverride( { css } );\n\n\t// Only attach a container class if there is generated CSS to be attached.\n\tif ( ! css ) {\n\t\treturn;\n\t}\n\n\t// Attach a `wp-container-content` id-based classname.\n\treturn { className: `wp-container-content-${ id }` };\n}\n\nfunction ChildLayoutControlsPure( { clientId, style, setAttributes } ) {\n\tconst parentLayout = useLayout() || {};\n\tconst {\n\t\ttype: parentLayoutType = 'default',\n\t\tallowSizingOnChildren = false,\n\t\tisManualPlacement,\n\t} = parentLayout;\n\n\tif ( parentLayoutType !== 'grid' ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<GridTools\n\t\t\tclientId={ clientId }\n\t\t\tstyle={ style }\n\t\t\tsetAttributes={ setAttributes }\n\t\t\tallowSizingOnChildren={ allowSizingOnChildren }\n\t\t\tisManualPlacement={ isManualPlacement }\n\t\t\tparentLayout={ parentLayout }\n\t\t/>\n\t);\n}\n\nfunction GridTools( {\n\tclientId,\n\tstyle,\n\tsetAttributes,\n\tallowSizingOnChildren,\n\tisManualPlacement,\n\tparentLayout,\n} ) {\n\tconst {\n\t\trootClientId,\n\t\tisVisible,\n\t\tparentBlockVisibility,\n\t\tblockBlockVisibility,\n\t\tdeviceType,\n\t\tisChildBlockAGrid,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\tgetBlockEditingMode,\n\t\t\t\tgetTemplateLock,\n\t\t\t\tgetBlockAttributes,\n\t\t\t\tgetSettings,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst _rootClientId = getBlockRootClientId( clientId );\n\n\t\t\tif (\n\t\t\t\tgetTemplateLock( _rootClientId ) ||\n\t\t\t\tgetBlockEditingMode( _rootClientId ) !== 'default'\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\trootClientId: _rootClientId,\n\t\t\t\t\tisVisible: false,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst parentAttributes = getBlockAttributes( _rootClientId );\n\t\t\tconst blockAttributes = getBlockAttributes( clientId );\n\t\t\tconst settings = getSettings();\n\n\t\t\treturn {\n\t\t\t\trootClientId: _rootClientId,\n\t\t\t\tisVisible: true,\n\t\t\t\tparentBlockVisibility:\n\t\t\t\t\tparentAttributes?.metadata?.blockVisibility,\n\t\t\t\tblockBlockVisibility:\n\t\t\t\t\tblockAttributes?.metadata?.blockVisibility,\n\t\t\t\tdeviceType:\n\t\t\t\t\tsettings?.[ deviceTypeKey ]?.toLowerCase() ||\n\t\t\t\t\tBLOCK_VISIBILITY_VIEWPORTS.desktop.key,\n\t\t\t\t// Check if the selected child block is itself a grid.\n\t\t\t\tisChildBlockAGrid: blockAttributes?.layout?.type === 'grid',\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { isBlockCurrentlyHidden: isParentBlockCurrentlyHidden } =\n\t\tuseBlockVisibility( {\n\t\t\tblockVisibility: parentBlockVisibility,\n\t\t\tdeviceType,\n\t\t} );\n\n\tconst { isBlockCurrentlyHidden: isBlockItselfCurrentlyHidden } =\n\t\tuseBlockVisibility( {\n\t\t\tblockVisibility: blockBlockVisibility,\n\t\t\tdeviceType,\n\t\t} );\n\n\t// Use useState() instead of useRef() so that GridItemResizer updates when ref is set.\n\tconst [ resizerBounds, setResizerBounds ] = useState();\n\n\tconst childGridClientId = isChildBlockAGrid ? clientId : undefined;\n\n\tif ( ! isVisible || isParentBlockCurrentlyHidden ) {\n\t\treturn null;\n\t}\n\n\tconst showResizer = allowSizingOnChildren && ! isBlockItselfCurrentlyHidden;\n\n\tfunction updateLayout( layout ) {\n\t\tsetAttributes( {\n\t\t\tstyle: {\n\t\t\t\t...style,\n\t\t\t\tlayout: {\n\t\t\t\t\t...style?.layout,\n\t\t\t\t\t...layout,\n\t\t\t\t},\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<GridVisualizer\n\t\t\t\tclientId={ rootClientId }\n\t\t\t\tcontentRef={ setResizerBounds }\n\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\tchildGridClientId={ childGridClientId }\n\t\t\t/>\n\t\t\t{ showResizer && (\n\t\t\t\t<GridItemResizer\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t// Don't allow resizing beyond the grid visualizer.\n\t\t\t\t\tbounds={ resizerBounds }\n\t\t\t\t\tonChange={ updateLayout }\n\t\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ isManualPlacement &&\n\t\t\t\twindow.__experimentalEnableGridInteractivity && (\n\t\t\t\t\t<GridItemMovers\n\t\t\t\t\t\tlayout={ style?.layout }\n\t\t\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\t\t\tonChange={ updateLayout }\n\t\t\t\t\t\tgridClientId={ rootClientId }\n\t\t\t\t\t\tblockClientId={ clientId }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default {\n\tuseBlockProps: useBlockPropsChildLayoutStyles,\n\tedit: ChildLayoutControlsPure,\n\tattributeKeys: [ 'style' ],\n\thasSupport() {\n\t\treturn true;\n\t},\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA8B;AAC9B,kBAA0B;AAC1B,qBAAyB;AAKzB,mBAA0C;AAC1C,mBAAiC;AACjC,oBAA0B;AAC1B,kBAIO;AACP,kCAA+B;AAC/B,0BAA8B;AAC9B,uBAA2C;AAiUzC;AA9TF,IAAM,qCAAqC,CAAC;AAE5C,IAAM,yBAAyB;AAAA,EAC9B,QAAQ;AAAA,EACR,QAAQ;AACT;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CAAE,OAAQ;AAAA,EACzB,aAAa;AACZ,WAAO;AAAA,EACR;AACD;",
|
|
6
6
|
"names": ["blockEditorStore", "useBlockVisibility"]
|
|
7
7
|
}
|
|
@@ -58,16 +58,19 @@ function ListViewPanel({ clientId, name }) {
|
|
|
58
58
|
const { openListViewContentPanel } = (0, import_lock_unlock.unlock)(
|
|
59
59
|
(0, import_data.useDispatch)(import_store.store)
|
|
60
60
|
);
|
|
61
|
-
const isEnabled =
|
|
62
|
-
const { hasChildren, isNestedListView } = (0, import_data.useSelect)(
|
|
61
|
+
const { isEnabled, hasChildren, isNestedListView } = (0, import_data.useSelect)(
|
|
63
62
|
(select) => {
|
|
64
|
-
const {
|
|
63
|
+
const {
|
|
64
|
+
getBlockCount,
|
|
65
|
+
getBlockParents,
|
|
66
|
+
shouldRenderBlockListView
|
|
67
|
+
} = (0, import_lock_unlock.unlock)(select(import_store.store));
|
|
65
68
|
const parents = getBlockParents(clientId, false);
|
|
66
|
-
const _isNestedListView = parents.find(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
69
|
+
const _isNestedListView = parents.find(
|
|
70
|
+
(parentId) => shouldRenderBlockListView(parentId)
|
|
71
|
+
);
|
|
70
72
|
return {
|
|
73
|
+
isEnabled: shouldRenderBlockListView(clientId),
|
|
71
74
|
hasChildren: !!getBlockCount(clientId),
|
|
72
75
|
isNestedListView: _isNestedListView
|
|
73
76
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/list-view.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { PanelBody } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { hasBlockSupport, getBlockType } from '@wordpress/blocks';\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { PrivateListView } from '../components/list-view';\nimport InspectorControls from '../components/inspector-controls/fill';\nimport { PrivateBlockContext } from '../components/block-list/private-block-context';\nimport useListViewPanelState from '../components/use-list-view-panel-state';\n\nimport { unlock } from '../lock-unlock';\n\nexport const LIST_VIEW_SUPPORT_KEY = 'listView';\n\n/**\n * Check if the block has list view support.\n *\n * @param {string|Object} nameOrType Block name or block type object.\n * @return {boolean} Whether the block has list view support.\n */\nexport function hasListViewSupport( nameOrType ) {\n\treturn hasBlockSupport( nameOrType, LIST_VIEW_SUPPORT_KEY );\n}\n\n/**\n * Inspector controls panel for list view.\n *\n * @param {Object} props Component props.\n * @param {string} props.clientId Block client ID.\n * @param {string} props.name Block name.\n * @return {Element|null} List view inspector controls or null.\n */\nexport function ListViewPanel( { clientId, name } ) {\n\tconst { isSelectionWithinCurrentSection } =\n\t\tuseContext( PrivateBlockContext );\n\n\tconst { isOpened, expandRevision, handleToggle } =\n\t\tuseListViewPanelState( clientId );\n\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { openListViewContentPanel } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\n\tconst isEnabled
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,wBAA0B;AAC1B,kBAAuC;AACvC,oBAA8C;AAC9C,qBAA2B;AAK3B,mBAA0C;AAC1C,uBAAgC;AAChC,kBAA8B;AAC9B,mCAAoC;AACpC,uCAAkC;AAElC,yBAAuB;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { PanelBody } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { hasBlockSupport, getBlockType } from '@wordpress/blocks';\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { PrivateListView } from '../components/list-view';\nimport InspectorControls from '../components/inspector-controls/fill';\nimport { PrivateBlockContext } from '../components/block-list/private-block-context';\nimport useListViewPanelState from '../components/use-list-view-panel-state';\n\nimport { unlock } from '../lock-unlock';\n\nexport const LIST_VIEW_SUPPORT_KEY = 'listView';\n\n/**\n * Check if the block has list view support.\n *\n * @param {string|Object} nameOrType Block name or block type object.\n * @return {boolean} Whether the block has list view support.\n */\nexport function hasListViewSupport( nameOrType ) {\n\treturn hasBlockSupport( nameOrType, LIST_VIEW_SUPPORT_KEY );\n}\n\n/**\n * Inspector controls panel for list view.\n *\n * @param {Object} props Component props.\n * @param {string} props.clientId Block client ID.\n * @param {string} props.name Block name.\n * @return {Element|null} List view inspector controls or null.\n */\nexport function ListViewPanel( { clientId, name } ) {\n\tconst { isSelectionWithinCurrentSection } =\n\t\tuseContext( PrivateBlockContext );\n\n\tconst { isOpened, expandRevision, handleToggle } =\n\t\tuseListViewPanelState( clientId );\n\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { openListViewContentPanel } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\n\tconst { isEnabled, hasChildren, isNestedListView } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockCount,\n\t\t\t\tgetBlockParents,\n\t\t\t\tshouldRenderBlockListView,\n\t\t\t} = unlock( select( blockEditorStore ) );\n\n\t\t\t// Avoid showing List Views for both parent and child blocks that have support.\n\t\t\t// In this situation the parent will show the child in its list already.\n\t\t\t// Search parents to see if there's one that also has support, and if so skip rendering.\n\t\t\t// This matches closely the logic in the `BlockCard` component.\n\t\t\tconst parents = getBlockParents( clientId, false );\n\t\t\tconst _isNestedListView = parents.find( ( parentId ) =>\n\t\t\t\tshouldRenderBlockListView( parentId )\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tisEnabled: shouldRenderBlockListView( clientId ),\n\t\t\t\thasChildren: !! getBlockCount( clientId ),\n\t\t\t\tisNestedListView: _isNestedListView,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst blockType = getBlockType( name );\n\tconst title = blockType?.title || name;\n\n\tif ( ! isEnabled || isNestedListView ) {\n\t\treturn null;\n\t}\n\n\tconst showBlockTitle = isSelectionWithinCurrentSection;\n\n\treturn (\n\t\t<InspectorControls group=\"list\">\n\t\t\t<PanelBody\n\t\t\t\ttitle={ showBlockTitle ? title : undefined }\n\t\t\t\topened={ isOpened }\n\t\t\t\tonToggle={ handleToggle }\n\t\t\t>\n\t\t\t\t{ ! hasChildren && (\n\t\t\t\t\t<p className=\"block-editor-block-inspector__no-blocks\">\n\t\t\t\t\t\t{ __( 'No items yet.' ) }\n\t\t\t\t\t</p>\n\t\t\t\t) }\n\t\t\t\t<PrivateListView\n\t\t\t\t\tkey={ `${ clientId }-${ expandRevision }` }\n\t\t\t\t\trootClientId={ clientId }\n\t\t\t\t\tisExpanded\n\t\t\t\t\tdescription={ title }\n\t\t\t\t\tshowAppender\n\t\t\t\t\tonSelect={ openListViewContentPanel }\n\t\t\t\t/>\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n}\n\n/**\n * Export block support definition.\n */\nexport default {\n\tedit: ListViewPanel,\n\thasSupport: hasListViewSupport,\n\tattributeKeys: [],\n\tsupportsPatternEditing: true,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,wBAA0B;AAC1B,kBAAuC;AACvC,oBAA8C;AAC9C,qBAA2B;AAK3B,mBAA0C;AAC1C,uBAAgC;AAChC,kBAA8B;AAC9B,mCAAoC;AACpC,uCAAkC;AAElC,yBAAuB;AAuEpB;AArEI,IAAM,wBAAwB;AAQ9B,SAAS,mBAAoB,YAAa;AAChD,aAAO,+BAAiB,YAAY,qBAAsB;AAC3D;AAUO,SAAS,cAAe,EAAE,UAAU,KAAK,GAAI;AACnD,QAAM,EAAE,gC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;AAAA,EACZ,eAAe,CAAC;AAAA,EAChB,wBAAwB;AACzB;",
|
|
6
6
|
"names": ["useListViewPanelState", "blockEditorStore", "InspectorControls"]
|
|
7
7
|
}
|
package/build/hooks/position.cjs
CHANGED
|
@@ -189,28 +189,25 @@ function PositionPanelPure({
|
|
|
189
189
|
});
|
|
190
190
|
};
|
|
191
191
|
const selectedOption = value ? options.find((option) => option.value === value) || DEFAULT_OPTION : DEFAULT_OPTION;
|
|
192
|
-
return
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
) }) }) : null,
|
|
212
|
-
native: null
|
|
213
|
-
});
|
|
192
|
+
return options.length > 1 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_inspector_controls.default, { group: "position", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.BaseControl, { help: stickyHelpText, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
193
|
+
import_components.CustomSelectControl,
|
|
194
|
+
{
|
|
195
|
+
__next40pxDefaultSize: true,
|
|
196
|
+
label: (0, import_i18n.__)("Position"),
|
|
197
|
+
hideLabelFromVision: true,
|
|
198
|
+
describedBy: (0, import_i18n.sprintf)(
|
|
199
|
+
// translators: %s: Currently selected position.
|
|
200
|
+
(0, import_i18n.__)("Currently selected position: %s"),
|
|
201
|
+
selectedOption.name
|
|
202
|
+
),
|
|
203
|
+
options,
|
|
204
|
+
value: selectedOption,
|
|
205
|
+
onChange: ({ selectedItem }) => {
|
|
206
|
+
onChangeType(selectedItem.value);
|
|
207
|
+
},
|
|
208
|
+
size: "__unstable-large"
|
|
209
|
+
}
|
|
210
|
+
) }) }) : null;
|
|
214
211
|
}
|
|
215
212
|
var position_default = {
|
|
216
213
|
edit: function Edit(props) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/position.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';\nimport { BaseControl, CustomSelectControl } from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo, Platform } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { useSettings } from '../components/use-settings';\nimport InspectorControls from '../components/inspector-controls';\nimport useBlockDisplayInformation from '../components/use-block-display-information';\nimport { cleanEmptyObject, useStyleOverride } from './utils';\nimport { store as blockEditorStore } from '../store';\n\nconst POSITION_SUPPORT_KEY = 'position';\n\nconst DEFAULT_OPTION = {\n\tkey: 'default',\n\tvalue: '',\n\tname: __( 'Default' ),\n};\n\nconst STICKY_OPTION = {\n\tkey: 'sticky',\n\tvalue: 'sticky',\n\tname: _x( 'Sticky', 'Name for the value of the CSS position property' ),\n\thint: __(\n\t\t'The block will stick to the top of the window instead of scrolling.'\n\t),\n};\n\nconst FIXED_OPTION = {\n\tkey: 'fixed',\n\tvalue: 'fixed',\n\tname: _x( 'Fixed', 'Name for the value of the CSS position property' ),\n\thint: __( 'The block will not move when the page is scrolled.' ),\n};\n\nconst POSITION_SIDES = [ 'top', 'right', 'bottom', 'left' ];\nconst VALID_POSITION_TYPES = [ 'sticky', 'fixed' ];\n\n/**\n * Get calculated position CSS.\n *\n * @param {Object} props Component props.\n * @param {string} props.selector Selector to use.\n * @param {Object} props.style Style object.\n * @return {string} The generated CSS rules.\n */\nexport function getPositionCSS( { selector, style } ) {\n\tlet output = '';\n\n\tconst { type: positionType } = style?.position || {};\n\n\tif ( ! VALID_POSITION_TYPES.includes( positionType ) ) {\n\t\treturn output;\n\t}\n\n\toutput += `${ selector } {`;\n\toutput += `position: ${ positionType };`;\n\n\tPOSITION_SIDES.forEach( ( side ) => {\n\t\tif ( style?.position?.[ side ] !== undefined ) {\n\t\t\toutput += `${ side }: ${ style.position[ side ] };`;\n\t\t}\n\t} );\n\n\tif ( positionType === 'sticky' || positionType === 'fixed' ) {\n\t\t// TODO: Replace hard-coded z-index value with a z-index preset approach in theme.json.\n\t\toutput += `z-index: 10`;\n\t}\n\toutput += `}`;\n\n\treturn output;\n}\n\n/**\n * Determines if there is sticky position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasStickyPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! ( true === support || support?.sticky );\n}\n\n/**\n * Determines if there is fixed position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasFixedPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! ( true === support || support?.fixed );\n}\n\n/**\n * Determines if there is position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! support;\n}\n\n/**\n * Checks if there is a current value in the position block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a position value set.\n */\nexport function hasPositionValue( props ) {\n\treturn props.attributes.style?.position?.type !== undefined;\n}\n\n/**\n * Checks if the block is currently set to a sticky or fixed position.\n * This check is helpful for determining how to position block toolbars or other elements.\n *\n * @param {Object} attributes Block attributes.\n * @return {boolean} Whether or not the block is set to a sticky or fixed position.\n */\nexport function hasStickyOrFixedPositionValue( attributes ) {\n\tconst positionType = attributes?.style?.position?.type;\n\treturn positionType === 'sticky' || positionType === 'fixed';\n}\n\n/**\n * Resets the position block support attributes. This can be used when disabling\n * the position support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetPosition( { attributes = {}, setAttributes } ) {\n\tconst { style = {} } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tposition: {\n\t\t\t\t...style?.position,\n\t\t\t\ttype: undefined,\n\t\t\t\ttop: undefined,\n\t\t\t\tright: undefined,\n\t\t\t\tbottom: undefined,\n\t\t\t\tleft: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if position settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether padding setting is disabled.\n */\nexport function useIsPositionDisabled( { name: blockName } = {} ) {\n\tconst [ allowFixed, allowSticky ] = useSettings(\n\t\t'position.fixed',\n\t\t'position.sticky'\n\t);\n\tconst isDisabled = ! allowFixed && ! allowSticky;\n\n\treturn ! hasPositionSupport( blockName ) || isDisabled;\n}\n\n/*\n * Position controls rendered in an inspector control panel.\n *\n * @param {Object} props\n *\n * @return {Element} Position panel.\n */\nexport function PositionPanelPure( {\n\tstyle = {},\n\tclientId,\n\tname: blockName,\n\tsetAttributes,\n} ) {\n\tconst allowFixed = hasFixedPositionSupport( blockName );\n\tconst allowSticky = hasStickyPositionSupport( blockName );\n\tconst value = style?.position?.type;\n\n\tconst { firstParentClientId } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockParents } = select( blockEditorStore );\n\t\t\tconst parents = getBlockParents( clientId );\n\t\t\treturn { firstParentClientId: parents[ parents.length - 1 ] };\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst blockInformation = useBlockDisplayInformation( firstParentClientId );\n\tconst stickyHelpText =\n\t\tallowSticky && value === STICKY_OPTION.value && blockInformation\n\t\t\t? sprintf(\n\t\t\t\t\t/* translators: %s: the name of the parent block. */\n\t\t\t\t\t__(\n\t\t\t\t\t\t'The block will stick to the scrollable area of the parent %s block.'\n\t\t\t\t\t),\n\t\t\t\t\tblockInformation.title\n\t\t\t )\n\t\t\t: null;\n\n\tconst options = useMemo( () => {\n\t\tconst availableOptions = [ DEFAULT_OPTION ];\n\t\t// Display options if they are allowed, or if a block already has a valid value set.\n\t\t// This allows for a block to be switched off from a position type that is not allowed.\n\t\tif ( allowSticky || value === STICKY_OPTION.value ) {\n\t\t\tavailableOptions.push( STICKY_OPTION );\n\t\t}\n\t\tif ( allowFixed || value === FIXED_OPTION.value ) {\n\t\t\tavailableOptions.push( FIXED_OPTION );\n\t\t}\n\t\treturn availableOptions;\n\t}, [ allowFixed, allowSticky, value ] );\n\n\tconst onChangeType = ( next ) => {\n\t\t// For now, use a hard-coded `0px` value for the position.\n\t\t// `0px` is preferred over `0` as it can be used in `calc()` functions.\n\t\t// In the future, it could be useful to allow for an offset value.\n\t\tconst placementValue = '0px';\n\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tposition: {\n\t\t\t\t...style?.position,\n\t\t\t\ttype: next,\n\t\t\t\ttop:\n\t\t\t\t\tnext === 'sticky' || next === 'fixed'\n\t\t\t\t\t\t? placementValue\n\t\t\t\t\t\t: undefined,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\tconst selectedOption = value\n\t\t? options.find( ( option ) => option.value === value ) || DEFAULT_OPTION\n\t\t: DEFAULT_OPTION;\n\n\t// Only display position controls if there is at least one option to choose from.\n\treturn Platform.select( {\n\t\tweb:\n\t\t\toptions.length > 1 ? (\n\t\t\t\t<InspectorControls group=\"position\">\n\t\t\t\t\t<BaseControl help={ stickyHelpText }>\n\t\t\t\t\t\t<CustomSelectControl\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tlabel={ __( 'Position' ) }\n\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\tdescribedBy={ sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: Currently selected position.\n\t\t\t\t\t\t\t\t__( 'Currently selected position: %s' ),\n\t\t\t\t\t\t\t\tselectedOption.name\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\toptions={ options }\n\t\t\t\t\t\t\tvalue={ selectedOption }\n\t\t\t\t\t\t\tonChange={ ( { selectedItem } ) => {\n\t\t\t\t\t\t\t\tonChangeType( selectedItem.value );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tsize=\"__unstable-large\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BaseControl>\n\t\t\t\t</InspectorControls>\n\t\t\t) : null,\n\t\tnative: null,\n\t} );\n}\n\nexport default {\n\tedit: function Edit( props ) {\n\t\tconst isPositionDisabled = useIsPositionDisabled( props );\n\t\tif ( isPositionDisabled ) {\n\t\t\treturn null;\n\t\t}\n\t\treturn <PositionPanelPure { ...props } />;\n\t},\n\tuseBlockProps,\n\tattributeKeys: [ 'style' ],\n\thasSupport( name ) {\n\t\treturn hasBlockSupport( name, POSITION_SUPPORT_KEY );\n\t},\n};\n\n// Used for generating the instance ID\nconst POSITION_BLOCK_PROPS_REFERENCE = {};\n\nfunction useBlockProps( { name, style } ) {\n\tconst hasPositionBlockSupport = hasBlockSupport(\n\t\tname,\n\t\tPOSITION_SUPPORT_KEY\n\t);\n\tconst isPositionDisabled = useIsPositionDisabled( { name } );\n\tconst allowPositionStyles = hasPositionBlockSupport && ! isPositionDisabled;\n\n\tconst id = useInstanceId( POSITION_BLOCK_PROPS_REFERENCE );\n\n\t// Higher specificity to override defaults in editor UI.\n\tconst positionSelector = `.wp-container-${ id }.wp-container-${ id }`;\n\n\t// Get CSS string for the current position values.\n\tlet css;\n\tif ( allowPositionStyles ) {\n\t\tcss =\n\t\t\tgetPositionCSS( {\n\t\t\t\tselector: positionSelector,\n\t\t\t\tstyle,\n\t\t\t} ) || '';\n\t}\n\n\t// Attach a `wp-container-` id-based class name.\n\tconst className = clsx( {\n\t\t[ `wp-container-${ id }` ]: allowPositionStyles && !! css, // Only attach a container class if there is generated CSS to be attached.\n\t\t[ `is-position-${ style?.position?.type }` ]:\n\t\t\tallowPositionStyles && !! css && !! style?.position?.type,\n\t} );\n\n\tuseStyleOverride( { css } );\n\n\treturn { className };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,kBAAgC;AAChC,oBAAiD;AACjD,wBAAiD;AACjD,qBAA8B;AAC9B,kBAA0B;AAC1B,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';\nimport { BaseControl, CustomSelectControl } from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { useSettings } from '../components/use-settings';\nimport InspectorControls from '../components/inspector-controls';\nimport useBlockDisplayInformation from '../components/use-block-display-information';\nimport { cleanEmptyObject, useStyleOverride } from './utils';\nimport { store as blockEditorStore } from '../store';\n\nconst POSITION_SUPPORT_KEY = 'position';\n\nconst DEFAULT_OPTION = {\n\tkey: 'default',\n\tvalue: '',\n\tname: __( 'Default' ),\n};\n\nconst STICKY_OPTION = {\n\tkey: 'sticky',\n\tvalue: 'sticky',\n\tname: _x( 'Sticky', 'Name for the value of the CSS position property' ),\n\thint: __(\n\t\t'The block will stick to the top of the window instead of scrolling.'\n\t),\n};\n\nconst FIXED_OPTION = {\n\tkey: 'fixed',\n\tvalue: 'fixed',\n\tname: _x( 'Fixed', 'Name for the value of the CSS position property' ),\n\thint: __( 'The block will not move when the page is scrolled.' ),\n};\n\nconst POSITION_SIDES = [ 'top', 'right', 'bottom', 'left' ];\nconst VALID_POSITION_TYPES = [ 'sticky', 'fixed' ];\n\n/**\n * Get calculated position CSS.\n *\n * @param {Object} props Component props.\n * @param {string} props.selector Selector to use.\n * @param {Object} props.style Style object.\n * @return {string} The generated CSS rules.\n */\nexport function getPositionCSS( { selector, style } ) {\n\tlet output = '';\n\n\tconst { type: positionType } = style?.position || {};\n\n\tif ( ! VALID_POSITION_TYPES.includes( positionType ) ) {\n\t\treturn output;\n\t}\n\n\toutput += `${ selector } {`;\n\toutput += `position: ${ positionType };`;\n\n\tPOSITION_SIDES.forEach( ( side ) => {\n\t\tif ( style?.position?.[ side ] !== undefined ) {\n\t\t\toutput += `${ side }: ${ style.position[ side ] };`;\n\t\t}\n\t} );\n\n\tif ( positionType === 'sticky' || positionType === 'fixed' ) {\n\t\t// TODO: Replace hard-coded z-index value with a z-index preset approach in theme.json.\n\t\toutput += `z-index: 10`;\n\t}\n\toutput += `}`;\n\n\treturn output;\n}\n\n/**\n * Determines if there is sticky position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasStickyPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! ( true === support || support?.sticky );\n}\n\n/**\n * Determines if there is fixed position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasFixedPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! ( true === support || support?.fixed );\n}\n\n/**\n * Determines if there is position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! support;\n}\n\n/**\n * Checks if there is a current value in the position block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a position value set.\n */\nexport function hasPositionValue( props ) {\n\treturn props.attributes.style?.position?.type !== undefined;\n}\n\n/**\n * Checks if the block is currently set to a sticky or fixed position.\n * This check is helpful for determining how to position block toolbars or other elements.\n *\n * @param {Object} attributes Block attributes.\n * @return {boolean} Whether or not the block is set to a sticky or fixed position.\n */\nexport function hasStickyOrFixedPositionValue( attributes ) {\n\tconst positionType = attributes?.style?.position?.type;\n\treturn positionType === 'sticky' || positionType === 'fixed';\n}\n\n/**\n * Resets the position block support attributes. This can be used when disabling\n * the position support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetPosition( { attributes = {}, setAttributes } ) {\n\tconst { style = {} } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tposition: {\n\t\t\t\t...style?.position,\n\t\t\t\ttype: undefined,\n\t\t\t\ttop: undefined,\n\t\t\t\tright: undefined,\n\t\t\t\tbottom: undefined,\n\t\t\t\tleft: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if position settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether padding setting is disabled.\n */\nexport function useIsPositionDisabled( { name: blockName } = {} ) {\n\tconst [ allowFixed, allowSticky ] = useSettings(\n\t\t'position.fixed',\n\t\t'position.sticky'\n\t);\n\tconst isDisabled = ! allowFixed && ! allowSticky;\n\n\treturn ! hasPositionSupport( blockName ) || isDisabled;\n}\n\n/*\n * Position controls rendered in an inspector control panel.\n *\n * @param {Object} props\n *\n * @return {Element} Position panel.\n */\nexport function PositionPanelPure( {\n\tstyle = {},\n\tclientId,\n\tname: blockName,\n\tsetAttributes,\n} ) {\n\tconst allowFixed = hasFixedPositionSupport( blockName );\n\tconst allowSticky = hasStickyPositionSupport( blockName );\n\tconst value = style?.position?.type;\n\n\tconst { firstParentClientId } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockParents } = select( blockEditorStore );\n\t\t\tconst parents = getBlockParents( clientId );\n\t\t\treturn { firstParentClientId: parents[ parents.length - 1 ] };\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst blockInformation = useBlockDisplayInformation( firstParentClientId );\n\tconst stickyHelpText =\n\t\tallowSticky && value === STICKY_OPTION.value && blockInformation\n\t\t\t? sprintf(\n\t\t\t\t\t/* translators: %s: the name of the parent block. */\n\t\t\t\t\t__(\n\t\t\t\t\t\t'The block will stick to the scrollable area of the parent %s block.'\n\t\t\t\t\t),\n\t\t\t\t\tblockInformation.title\n\t\t\t )\n\t\t\t: null;\n\n\tconst options = useMemo( () => {\n\t\tconst availableOptions = [ DEFAULT_OPTION ];\n\t\t// Display options if they are allowed, or if a block already has a valid value set.\n\t\t// This allows for a block to be switched off from a position type that is not allowed.\n\t\tif ( allowSticky || value === STICKY_OPTION.value ) {\n\t\t\tavailableOptions.push( STICKY_OPTION );\n\t\t}\n\t\tif ( allowFixed || value === FIXED_OPTION.value ) {\n\t\t\tavailableOptions.push( FIXED_OPTION );\n\t\t}\n\t\treturn availableOptions;\n\t}, [ allowFixed, allowSticky, value ] );\n\n\tconst onChangeType = ( next ) => {\n\t\t// For now, use a hard-coded `0px` value for the position.\n\t\t// `0px` is preferred over `0` as it can be used in `calc()` functions.\n\t\t// In the future, it could be useful to allow for an offset value.\n\t\tconst placementValue = '0px';\n\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tposition: {\n\t\t\t\t...style?.position,\n\t\t\t\ttype: next,\n\t\t\t\ttop:\n\t\t\t\t\tnext === 'sticky' || next === 'fixed'\n\t\t\t\t\t\t? placementValue\n\t\t\t\t\t\t: undefined,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\tconst selectedOption = value\n\t\t? options.find( ( option ) => option.value === value ) || DEFAULT_OPTION\n\t\t: DEFAULT_OPTION;\n\n\t// Only display position controls if there is at least one option to choose from.\n\treturn options.length > 1 ? (\n\t\t<InspectorControls group=\"position\">\n\t\t\t<BaseControl help={ stickyHelpText }>\n\t\t\t\t<CustomSelectControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'Position' ) }\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t\tdescribedBy={ sprintf(\n\t\t\t\t\t\t// translators: %s: Currently selected position.\n\t\t\t\t\t\t__( 'Currently selected position: %s' ),\n\t\t\t\t\t\tselectedOption.name\n\t\t\t\t\t) }\n\t\t\t\t\toptions={ options }\n\t\t\t\t\tvalue={ selectedOption }\n\t\t\t\t\tonChange={ ( { selectedItem } ) => {\n\t\t\t\t\t\tonChangeType( selectedItem.value );\n\t\t\t\t\t} }\n\t\t\t\t\tsize=\"__unstable-large\"\n\t\t\t\t/>\n\t\t\t</BaseControl>\n\t\t</InspectorControls>\n\t) : null;\n}\n\nexport default {\n\tedit: function Edit( props ) {\n\t\tconst isPositionDisabled = useIsPositionDisabled( props );\n\t\tif ( isPositionDisabled ) {\n\t\t\treturn null;\n\t\t}\n\t\treturn <PositionPanelPure { ...props } />;\n\t},\n\tuseBlockProps,\n\tattributeKeys: [ 'style' ],\n\thasSupport( name ) {\n\t\treturn hasBlockSupport( name, POSITION_SUPPORT_KEY );\n\t},\n};\n\n// Used for generating the instance ID\nconst POSITION_BLOCK_PROPS_REFERENCE = {};\n\nfunction useBlockProps( { name, style } ) {\n\tconst hasPositionBlockSupport = hasBlockSupport(\n\t\tname,\n\t\tPOSITION_SUPPORT_KEY\n\t);\n\tconst isPositionDisabled = useIsPositionDisabled( { name } );\n\tconst allowPositionStyles = hasPositionBlockSupport && ! isPositionDisabled;\n\n\tconst id = useInstanceId( POSITION_BLOCK_PROPS_REFERENCE );\n\n\t// Higher specificity to override defaults in editor UI.\n\tconst positionSelector = `.wp-container-${ id }.wp-container-${ id }`;\n\n\t// Get CSS string for the current position values.\n\tlet css;\n\tif ( allowPositionStyles ) {\n\t\tcss =\n\t\t\tgetPositionCSS( {\n\t\t\t\tselector: positionSelector,\n\t\t\t\tstyle,\n\t\t\t} ) || '';\n\t}\n\n\t// Attach a `wp-container-` id-based class name.\n\tconst className = clsx( {\n\t\t[ `wp-container-${ id }` ]: allowPositionStyles && !! css, // Only attach a container class if there is generated CSS to be attached.\n\t\t[ `is-position-${ style?.position?.type }` ]:\n\t\t\tallowPositionStyles && !! css && !! style?.position?.type,\n\t} );\n\n\tuseStyleOverride( { css } );\n\n\treturn { className };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,kBAAgC;AAChC,oBAAiD;AACjD,wBAAiD;AACjD,qBAA8B;AAC9B,kBAA0B;AAC1B,qBAAwB;AAKxB,0BAA4B;AAC5B,gCAA8B;AAC9B,2CAAuC;AACvC,mBAAmD;AACnD,mBAA0C;AAuPtC;AArPJ,IAAM,uBAAuB;AAE7B,IAAM,iBAAiB;AAAA,EACtB,KAAK;AAAA,EACL,OAAO;AAAA,EACP,UAAM,gBAAI,SAAU;AACrB;AAEA,IAAM,gBAAgB;AAAA,EACrB,KAAK;AAAA,EACL,OAAO;AAAA,EACP,UAAM,gBAAI,UAAU,iDAAkD;AAAA,EACtE,UAAM;AAAA,IACL;AAAA,EACD;AACD;AAEA,IAAM,eAAe;AAAA,EACpB,KAAK;AAAA,EACL,OAAO;AAAA,EACP,UAAM,gBAAI,SAAS,iDAAkD;AAAA,EACrE,UAAM,gBAAI,oDAAqD;AAChE;AAEA,IAAM,iBAAiB,CAAE,OAAO,SAAS,UAAU,MAAO;AAC1D,IAAM,uBAAuB,CAAE,UAAU,OAAQ;AAU1C,SAAS,eAAgB,EA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2B,CAAE;AAEzD,QAAM,SAAK,8BAAe,8BAA+B;AAGzD,QAAM,mBAAmB,iBAAkB,EAAG,iBAAkB,EAAG;AAGnE,MAAI;AACJ,MAAK,qBAAsB;AAC1B,UACC,eAAgB;AAAA,MACf,UAAU;AAAA,MACV;AAAA,IACD,CAAE,KAAK;AAAA,EACT;AAGA,QAAM,gBAAY,YAAAC,SAAM;AAAA,IACvB,CAAE,gBAAiB,EAAG,EAAG,GAAG,uBAAuB,CAAC,CAAE;AAAA;AAAA,IACtD,CAAE,eAAgB,OAAO,UAAU,IAAK,EAAG,GAC1C,uBAAuB,CAAC,CAAE,OAAO,CAAC,CAAE,OAAO,UAAU;AAAA,EACvD,CAAE;AAEF,qCAAkB,EAAE,IAAI,CAAE;AAE1B,SAAO,EAAE,UAAU;AACpB;",
|
|
6
6
|
"names": ["blockEditorStore", "useBlockDisplayInformation", "InspectorControls", "clsx"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/spacing-visualizer.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useState, useRef, useEffect, useReducer } from '@wordpress/element';\nimport { isShallowEqual } from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport BlockPopoverCover from '../components/block-popover/cover';\nimport { useBlockElement } from '../components/block-list/use-block-props/use-block-refs';\n\nfunction SpacingVisualizer( { clientId, value, computeStyle, forceShow } ) {\n\tconst blockElement = useBlockElement( clientId );\n\tconst [ style, updateStyle ] = useReducer( () =>\n\t\tcomputeStyle( blockElement )\n\t);\n\n\t// Force style computation when forceShow becomes true (e.g., when hovering control)\n\t// to ensure visualizer displays correct dimensions on first render.\n\tuseEffect( () => {\n\t\tif ( blockElement && forceShow ) {\n\t\t\tupdateStyle();\n\t\t}\n\t}, [ blockElement, forceShow ] );\n\n\t// It's not sufficient to read the block's computed style when `value` changes because\n\t// the effect would run before the block
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useState, useRef, useEffect, useReducer } from '@wordpress/element';\nimport { isShallowEqual } from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport BlockPopoverCover from '../components/block-popover/cover';\nimport { useBlockElement } from '../components/block-list/use-block-props/use-block-refs';\n\nfunction SpacingVisualizer( { clientId, value, computeStyle, forceShow } ) {\n\tconst blockElement = useBlockElement( clientId );\n\tconst [ style, updateStyle ] = useReducer( () =>\n\t\tcomputeStyle( blockElement )\n\t);\n\n\t// Force style computation when forceShow becomes true (e.g., when hovering control)\n\t// to ensure visualizer displays correct dimensions on first render.\n\tuseEffect( () => {\n\t\tif ( blockElement && forceShow ) {\n\t\t\tupdateStyle();\n\t\t}\n\t}, [ blockElement, forceShow ] );\n\n\t// It's not sufficient to read the block's computed style when `value` changes because\n\t// the effect would run before the block’s style has updated. Thus observing mutations\n\t// to the block’s attributes is used to trigger updates to the visualizer’s styles.\n\tuseEffect( () => {\n\t\tif ( ! blockElement ) {\n\t\t\treturn;\n\t\t}\n\t\tconst observer = new window.MutationObserver( updateStyle );\n\t\tobserver.observe( blockElement, {\n\t\t\tattributes: true,\n\t\t\tattributeFilter: [ 'style', 'class' ],\n\t\t} );\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [ blockElement ] );\n\n\tconst previousValueRef = useRef( value );\n\tconst [ isActive, setIsActive ] = useState( false );\n\n\tuseEffect( () => {\n\t\tif ( isShallowEqual( value, previousValueRef.current ) || forceShow ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsActive( true );\n\t\tpreviousValueRef.current = value;\n\n\t\tconst timeout = setTimeout( () => {\n\t\t\tsetIsActive( false );\n\t\t}, 400 );\n\n\t\treturn () => {\n\t\t\tsetIsActive( false );\n\t\t\tclearTimeout( timeout );\n\t\t};\n\t}, [ value, forceShow ] );\n\n\tif ( ! isActive && ! forceShow ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockPopoverCover\n\t\t\tclientId={ clientId }\n\t\t\t__unstablePopoverSlot=\"block-toolbar\"\n\t\t>\n\t\t\t<div className=\"block-editor__spacing-visualizer\" style={ style } />\n\t\t</BlockPopoverCover>\n\t);\n}\n\nfunction getComputedCSS( element, property ) {\n\treturn element.ownerDocument.defaultView\n\t\t.getComputedStyle( element )\n\t\t.getPropertyValue( property );\n}\n\nexport function MarginVisualizer( { clientId, value, forceShow } ) {\n\treturn (\n\t\t<SpacingVisualizer\n\t\t\tclientId={ clientId }\n\t\t\tvalue={ value?.spacing?.margin }\n\t\t\tcomputeStyle={ ( blockElement ) => {\n\t\t\t\tconst top = getComputedCSS( blockElement, 'margin-top' );\n\t\t\t\tconst right = getComputedCSS( blockElement, 'margin-right' );\n\t\t\t\tconst bottom = getComputedCSS( blockElement, 'margin-bottom' );\n\t\t\t\tconst left = getComputedCSS( blockElement, 'margin-left' );\n\t\t\t\treturn {\n\t\t\t\t\tborderTopWidth: top,\n\t\t\t\t\tborderRightWidth: right,\n\t\t\t\t\tborderBottomWidth: bottom,\n\t\t\t\t\tborderLeftWidth: left,\n\t\t\t\t\ttop: top ? `-${ top }` : 0,\n\t\t\t\t\tright: right ? `-${ right }` : 0,\n\t\t\t\t\tbottom: bottom ? `-${ bottom }` : 0,\n\t\t\t\t\tleft: left ? `-${ left }` : 0,\n\t\t\t\t};\n\t\t\t} }\n\t\t\tforceShow={ forceShow }\n\t\t/>\n\t);\n}\n\nexport function PaddingVisualizer( { clientId, value, forceShow } ) {\n\treturn (\n\t\t<SpacingVisualizer\n\t\t\tclientId={ clientId }\n\t\t\tvalue={ value?.spacing?.padding }\n\t\t\tcomputeStyle={ ( blockElement ) => ( {\n\t\t\t\tborderTopWidth: getComputedCSS( blockElement, 'padding-top' ),\n\t\t\t\tborderRightWidth: getComputedCSS(\n\t\t\t\t\tblockElement,\n\t\t\t\t\t'padding-right'\n\t\t\t\t),\n\t\t\t\tborderBottomWidth: get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AkB;AAAA,UACjB;AAAA,UACA;AAAA,QACD;AAAA,QACA,mBAAmB;AAAA,UAClB;AAAA,UACA;AAAA,QACD;AAAA,QACA,iBAAiB,eAAgB,cAAc,cAAe;AAAA,MAC/D;AAAA,MACA;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": ["BlockPopoverCover"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/state-utils.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { getBlockType } from '@wordpress/blocks';\nimport { splitSelectorList } from '@wordpress/global-styles-engine';\n\n/**\n * Given a block's `selectors.root` value, returns the part of the selector\n * that is relative to the block wrapper
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { getBlockType } from '@wordpress/blocks';\nimport { splitSelectorList } from '@wordpress/global-styles-engine';\n\n/**\n * Given a block's `selectors.root` value, returns the part of the selector\n * that is relative to the block wrapper — i.e., everything after the first\n * compound selector segment.\n *\n * Examples:\n * \".wp-block-button .wp-block-button__link\" → \".wp-block-button__link\"\n * \".wp-block-foo > .inner\" → \"> .inner\"\n * \".wp-block-foo\" → null (no descendant)\n *\n * @param {string} rootSelector The block's `selectors.root` value.\n * @return {string|null} Relative selector, or null if rootSelector targets the wrapper itself.\n */\nexport function getRelativeRootSelector( rootSelector ) {\n\t// Match everything after the first compound selector (up to the first\n\t// whitespace or combinator character).\n\t// Require at least one combinator character (space, >, +, ~) between the\n\t// first compound selector and the rest. Without this anchor, a greedy\n\t// quantifier would backtrack into the first token and produce false matches.\n\tconst match = rootSelector.trim().match( /^[^ >+~]+[ >+~](.*)$/ );\n\tif ( ! match ) {\n\t\treturn null;\n\t}\n\tconst rest = match[ 1 ].trim();\n\treturn rest || null;\n}\n\n/**\n * Builds a scoped selector from a block selector and optional suffix.\n *\n * If the block selector targets a descendant, the descendant portion is scoped\n * under the provided base selector. Otherwise the base selector itself is used.\n *\n * @param {string} baseSelector The block-instance scoping selector.\n * @param {string} blockSelector The block or feature selector from block metadata.\n * @param {string} suffix Optional selector suffix, e.g. \":hover\".\n * @return {string} The scoped CSS selector.\n */\nexport function buildScopedBlockSelector(\n\tbaseSelector,\n\tblockSelector,\n\tsuffix = ''\n) {\n\tif ( typeof blockSelector !== 'string' || ! blockSelector ) {\n\t\treturn splitSelectorList( baseSelector )\n\t\t\t.map( ( selector ) => `${ selector.trim() }${ suffix }` )\n\t\t\t.join( ', ' );\n\t}\n\n\tconst baseSelectors = splitSelectorList( baseSelector ).filter(\n\t\t( selector ) => selector.trim()\n\t);\n\tconst selectors = splitSelectorList( blockSelector ).filter( ( selector ) =>\n\t\tselector.trim()\n\t);\n\n\tif ( ! selectors.length ) {\n\t\treturn baseSelectors\n\t\t\t.map( ( selector ) => `${ selector.trim() }${ suffix }` )\n\t\t\t.join( ', ' );\n\t}\n\n\treturn selectors\n\t\t.map( ( selector ) => {\n\t\t\tselector = selector.trim();\n\n\t\t\t/*\n\t\t\t * Replace only the leading block selector part (e.g. class name,\n\t\t\t * attribute selector, ID, or tag name) with the block instance selector.\n\t\t\t * Preserve anything after that prefix, including modifier classes on the\n\t\t\t * same element and combinators without spaces.\n\t\t\t */\n\t\t\tconst match = selector.match( /^([.#]?[-_a-zA-Z0-9]+|\\[[^\\]]+\\])/ );\n\t\t\tif ( match ) {\n\t\t\t\treturn baseSelectors\n\t\t\t\t\t.map(\n\t\t\t\t\t\t( base ) =>\n\t\t\t\t\t\t\t`${ base.trim() }${ selector.slice(\n\t\t\t\t\t\t\t\tmatch[ 0 ].length\n\t\t\t\t\t\t\t) }${ suffix }`\n\t\t\t\t\t)\n\t\t\t\t\t.join( ', ' );\n\t\t\t}\n\n\t\t\treturn baseSelectors\n\t\t\t\t.map( ( base ) => `${ base.trim() }${ suffix }` )\n\t\t\t\t.join( ', ' );\n\t\t} )\n\t\t.join( ', ' );\n}\n\n/**\n * Builds the scoped selector for root block style state styles.\n *\n * Uses the block's `selectors.root` to determine which element should receive\n * root-level state styles. If `selectors.root` describes a descendant element\n * (e.g. `.wp-block-button .wp-block-button__link`), the relative portion is\n * scoped under `baseSelector`. If no descendant is present, falls back to the\n * base selector.\n *\n * @param {string} baseSelector The block-instance scoping class selector.\n * @param {string} name The block name, used to look up selectors.\n * @return {string} The fully-scoped CSS selector for root state styles.\n */\nexport function buildRootStyleStateSelector( baseSelector, name ) {\n\tconst rootSelector = getBlockType( name )?.selectors?.root;\n\treturn buildScopedBlockSelector( baseSelector, rootSelector );\n}\n\n/**\n * Builds the scoped CSS selector for a block state (e.g. :hover, :focus).\n *\n * Uses the block's `selectors.root` to determine which element the state\n * pseudo-class should apply to. If `selectors.root` describes a descendant\n * element (e.g. \".wp-block-button .wp-block-button__link\"), the relative\n * portion (\".wp-block-button__link\") is scoped under `baseSelector`. If no\n * descendant is present, falls back to appending the state to `baseSelector`.\n *\n * @param {string} baseSelector The block-instance scoping class selector.\n * @param {string} name The block name, used to look up selectors.\n * @param {string} state The pseudo-class string, e.g. \":hover\".\n * @return {string} The fully-scoped CSS selector for this state.\n */\nexport function buildPseudoStyleStateSelector( baseSelector, name, state ) {\n\treturn `${ buildRootStyleStateSelector( baseSelector, name ) }${ state }`;\n}\n\nexport function buildStateSelector( baseSelector, name, state ) {\n\tconst rootSelector = getBlockType( name )?.selectors?.root;\n\treturn buildScopedBlockSelector( baseSelector, rootSelector, state );\n}\n\n/**\n * Builds the CSS selector used to preview a state on the editor canvas,\n * scoped to a specific block instance via its `data-block` attribute.\n *\n * For blocks whose `selectors.root` targets a descendant element\n * (e.g. \".wp-block-button .wp-block-button__link\"), the selector targets\n * that descendant inside the block wrapper. Otherwise it targets the wrapper\n * itself.\n *\n * @param {string} clientId The block's clientId.\n * @param {string} name The block name, used to look up selectors.\n * @return {string} CSS selector scoped to this block instance.\n */\nexport function buildCanvasStateSelector( clientId, name ) {\n\tconst rootSelector = getBlockType( name )?.selectors?.root;\n\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L,IAAK,CAAE,SAAU,GAAI,KAAK,KAAK,CAAE,GAAI,MAAO,EAAG,EAC/C,KAAM,IAAK;AAAA,EACd,CAAE,EACD,KAAM,IAAK;AACd;AAeO,SAAS,4BAA6B,cAAc,MAAO;AACjE,QAAM,mBAAe,4BAAc,IAAK,GAAG,WAAW;AACtD,SAAO,yBAA0B,cAAc,YAAa;AAC7D;AAgBO,SAAS,8BAA+B,cAAc,MAAM,OAAQ;AAC1E,SAAO,GAAI,4BAA6B,cAAc,IAAK,CAAE,GAAI,KAAM;AACxE;AAEO,SAAS,mBAAoB,cAAc,MAAM,OAAQ;AAC/D,QAAM,mBAAe,4BAAc,IAAK,GAAG,WAAW;AACtD,SAAO,yBAA0B,cAAc,cAAc,KAAM;AACpE;AAeO,SAAS,yBAA0B,UAAU,MAAO;AAC1D,QAAM,mBAAe,4BAAc,IAAK,GAAG,WAAW;AACtD,SAAO;AAAA,IACN,gBAAiB,QAAS;AAAA,IAC1B;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/hooks/style.cjs
CHANGED
|
@@ -98,12 +98,52 @@ function getStateFallbackBorderStyles(stateStyles) {
|
|
|
98
98
|
});
|
|
99
99
|
return (0, import_utils.cleanEmptyObject)({ border: (0, import_utils.cleanEmptyObject)(fallbackBorder) });
|
|
100
100
|
}
|
|
101
|
+
function getStateBackgroundResetCSS(stateStyles, selector) {
|
|
102
|
+
const hasSolidBackground = !!stateStyles?.color?.background;
|
|
103
|
+
if (!hasSolidBackground) {
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
const hasColorGradient = !!stateStyles?.color?.gradient;
|
|
107
|
+
const hasBackgroundGradient = !!stateStyles?.background?.gradient || !!stateStyles?.background?.backgroundImage;
|
|
108
|
+
if (hasColorGradient || hasBackgroundGradient) {
|
|
109
|
+
return void 0;
|
|
110
|
+
}
|
|
111
|
+
const declaration = "background-image: unset !important";
|
|
112
|
+
return selector ? `${selector} { ${declaration}; }` : `${declaration};`;
|
|
113
|
+
}
|
|
114
|
+
function getStateFallbackDimensionStyles(stateStyles) {
|
|
115
|
+
const dimensions = stateStyles?.dimensions;
|
|
116
|
+
if (!dimensions) {
|
|
117
|
+
return void 0;
|
|
118
|
+
}
|
|
119
|
+
if ((0, import_dimensions.isExplicitAspectRatio)(dimensions.aspectRatio)) {
|
|
120
|
+
return {
|
|
121
|
+
dimensions: {
|
|
122
|
+
minHeight: "unset",
|
|
123
|
+
height: "unset"
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (dimensions.minHeight || dimensions.height) {
|
|
128
|
+
return {
|
|
129
|
+
dimensions: {
|
|
130
|
+
aspectRatio: "unset"
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
101
135
|
function getStateStylesCSS(stateStyles, selector) {
|
|
102
|
-
const
|
|
136
|
+
const fallbackDimensionStyles = getStateFallbackDimensionStyles(stateStyles);
|
|
137
|
+
const stylesWithDimensionFallbacks = fallbackDimensionStyles ? mergeStyleObjects(stateStyles, fallbackDimensionStyles) : stateStyles;
|
|
138
|
+
const css = (0, import_style_engine.compileCSS)(stylesWithDimensionFallbacks, { selector });
|
|
103
139
|
const importantCSS = css ? css.replace(/;/g, " !important;") : void 0;
|
|
104
140
|
const fallbackBorderStyles = getStateFallbackBorderStyles(stateStyles);
|
|
105
141
|
const fallbackCSS = fallbackBorderStyles ? (0, import_style_engine.compileCSS)(fallbackBorderStyles, { selector }) : void 0;
|
|
106
|
-
|
|
142
|
+
const backgroundResetCSS = getStateBackgroundResetCSS(
|
|
143
|
+
stateStyles,
|
|
144
|
+
selector
|
|
145
|
+
);
|
|
146
|
+
return [importantCSS, fallbackCSS, backgroundResetCSS].filter(Boolean).join("\n");
|
|
107
147
|
}
|
|
108
148
|
function isPlainObject(value) {
|
|
109
149
|
return !!value && typeof value === "object" && !Array.isArray(value);
|