@wordpress/block-editor 11.7.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +56 -57
- package/build/components/block-info-slot-fill/index.js +47 -0
- package/build/components/block-info-slot-fill/index.js.map +1 -0
- package/build/components/block-inspector/index.js +4 -2
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/index.native.js +11 -21
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +3 -1
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-popover/inbetween.js +2 -9
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +1 -10
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-toolbar/index.js +2 -1
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +83 -9
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +11 -28
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/caption/index.native.js +0 -1
- package/build/components/caption/index.native.js.map +1 -1
- package/build/components/date-format-picker/index.js +1 -1
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/editor-styles/index.js +4 -3
- package/build/components/editor-styles/index.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +21 -14
- package/build/components/font-sizes/fluid-utils.js.map +1 -1
- package/build/components/global-styles/border-panel.js +15 -59
- package/build/components/global-styles/border-panel.js.map +1 -1
- package/build/components/global-styles/color-panel.js +12 -12
- package/build/components/global-styles/color-panel.js.map +1 -1
- package/build/components/global-styles/color-panel.native.js +174 -0
- package/build/components/global-styles/color-panel.native.js.map +1 -0
- package/build/components/global-styles/dimensions-panel.js +21 -20
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/effects-panel.js +244 -0
- package/build/components/global-styles/effects-panel.js.map +1 -0
- package/build/components/global-styles/filters-panel.js +215 -0
- package/build/components/global-styles/filters-panel.js.map +1 -0
- package/build/components/global-styles/get-block-css-selector.js +1 -12
- package/build/components/global-styles/get-block-css-selector.js.map +1 -1
- package/build/components/global-styles/hooks.js +7 -0
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +28 -0
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +9 -9
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +100 -82
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/iframe/index.js +1 -1
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/image-size-control/use-dimension-handler.js +5 -3
- package/build/components/image-size-control/use-dimension-handler.js.map +1 -1
- package/build/components/index.js +23 -0
- package/build/components/index.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +4 -2
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/block-types-tab.js +12 -7
- package/build/components/inserter/block-types-tab.js.map +1 -1
- package/build/components/inserter/index.js +2 -1
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inspector-controls/groups.js +2 -0
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/inspector-controls-tabs/styles-tab.js +2 -0
- package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build/components/inspector-controls-tabs/utils.js +5 -3
- package/build/components/inspector-controls-tabs/utils.js.map +1 -1
- package/build/components/list-view/block-select-button.js +7 -2
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +13 -21
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/drop-indicator.js +37 -10
- package/build/components/list-view/drop-indicator.js.map +1 -1
- package/build/components/list-view/index.js +31 -7
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/leaf.js +2 -1
- package/build/components/list-view/leaf.js.map +1 -1
- package/build/components/list-view/use-block-selection.js +1 -1
- package/build/components/list-view/use-block-selection.js.map +1 -1
- package/build/components/list-view/use-list-view-client-ids.js +7 -3
- package/build/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +8 -2
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/media-replace-flow/index.js +5 -5
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/navigable-toolbar/index.js +12 -4
- package/build/components/navigable-toolbar/index.js.map +1 -1
- package/build/components/off-canvas-editor/appender.js +2 -7
- package/build/components/off-canvas-editor/appender.js.map +1 -1
- package/build/components/off-canvas-editor/block-contents.js +6 -1
- package/build/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build/components/off-canvas-editor/index.js +17 -14
- package/build/components/off-canvas-editor/index.js.map +1 -1
- package/build/components/resizable-box-popover/index.js +38 -0
- package/build/components/resizable-box-popover/index.js.map +1 -0
- package/build/components/rich-text/index.js +0 -1
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +7 -11
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js +8 -0
- package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build/hooks/anchor.js +1 -1
- package/build/hooks/anchor.js.map +1 -1
- package/build/hooks/border.js +1 -1
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/duotone.js +121 -70
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/margin.js +27 -17
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +19 -9
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/utils.js +22 -7
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/utils.js +3 -2
- package/build/layouts/utils.js.map +1 -1
- package/build/private-apis.js +13 -1
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +8 -1
- package/build/store/actions.js.map +1 -1
- package/build/utils/object.js +6 -6
- package/build/utils/object.js.map +1 -1
- package/build/utils/transform-styles/index.js +2 -2
- package/build/utils/transform-styles/index.js.map +1 -1
- package/build/utils/use-should-contextual-toolbar-show.js +68 -0
- package/build/utils/use-should-contextual-toolbar-show.js.map +1 -0
- package/build-module/components/block-info-slot-fill/index.js +34 -0
- package/build-module/components/block-info-slot-fill/index.js.map +1 -0
- package/build-module/components/block-inspector/index.js +3 -2
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/index.native.js +11 -19
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +2 -1
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +2 -9
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +1 -9
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +2 -1
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +79 -9
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +10 -27
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/caption/index.native.js +0 -1
- package/build-module/components/caption/index.native.js.map +1 -1
- package/build-module/components/date-format-picker/index.js +1 -1
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/editor-styles/index.js +4 -3
- package/build-module/components/editor-styles/index.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +21 -14
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +15 -59
- package/build-module/components/global-styles/border-panel.js.map +1 -1
- package/build-module/components/global-styles/color-panel.js +13 -13
- package/build-module/components/global-styles/color-panel.js.map +1 -1
- package/build-module/components/global-styles/color-panel.native.js +150 -0
- package/build-module/components/global-styles/color-panel.native.js.map +1 -0
- package/build-module/components/global-styles/dimensions-panel.js +22 -21
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/effects-panel.js +228 -0
- package/build-module/components/global-styles/effects-panel.js.map +1 -0
- package/build-module/components/global-styles/filters-panel.js +201 -0
- package/build-module/components/global-styles/filters-panel.js.map +1 -0
- package/build-module/components/global-styles/get-block-css-selector.js +1 -12
- package/build-module/components/global-styles/get-block-css-selector.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +7 -0
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/index.js +2 -0
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +10 -10
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +101 -83
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/iframe/index.js +1 -1
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/image-size-control/use-dimension-handler.js +5 -3
- package/build-module/components/image-size-control/use-dimension-handler.js.map +1 -1
- package/build-module/components/index.js +1 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +5 -2
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/block-types-tab.js +12 -6
- package/build-module/components/inserter/block-types-tab.js.map +1 -1
- package/build-module/components/inserter/index.js +2 -1
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +2 -0
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/styles-tab.js +2 -0
- package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/utils.js +4 -3
- package/build-module/components/inspector-controls-tabs/utils.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +7 -2
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +15 -22
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/drop-indicator.js +36 -10
- package/build-module/components/list-view/drop-indicator.js.map +1 -1
- package/build-module/components/list-view/index.js +31 -8
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/leaf.js +2 -1
- package/build-module/components/list-view/leaf.js.map +1 -1
- package/build-module/components/list-view/use-block-selection.js +1 -1
- package/build-module/components/list-view/use-block-selection.js.map +1 -1
- package/build-module/components/list-view/use-list-view-client-ids.js +7 -3
- package/build-module/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +8 -4
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +5 -5
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/navigable-toolbar/index.js +12 -4
- package/build-module/components/navigable-toolbar/index.js.map +1 -1
- package/build-module/components/off-canvas-editor/appender.js +1 -5
- package/build-module/components/off-canvas-editor/appender.js.map +1 -1
- package/build-module/components/off-canvas-editor/block-contents.js +5 -1
- package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build-module/components/off-canvas-editor/index.js +17 -14
- package/build-module/components/off-canvas-editor/index.js.map +1 -1
- package/build-module/components/resizable-box-popover/index.js +26 -0
- package/build-module/components/resizable-box-popover/index.js.map +1 -0
- package/build-module/components/rich-text/index.js +0 -1
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +7 -10
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js +7 -0
- package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build-module/hooks/anchor.js +1 -1
- package/build-module/hooks/anchor.js.map +1 -1
- package/build-module/hooks/border.js +1 -1
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/duotone.js +118 -71
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/margin.js +29 -18
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +21 -10
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/utils.js +24 -9
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/utils.js +3 -2
- package/build-module/layouts/utils.js.map +1 -1
- package/build-module/private-apis.js +9 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +8 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/utils/object.js +5 -5
- package/build-module/utils/object.js.map +1 -1
- package/build-module/utils/transform-styles/index.js +2 -2
- package/build-module/utils/transform-styles/index.js.map +1 -1
- package/build-module/utils/use-should-contextual-toolbar-show.js +56 -0
- package/build-module/utils/use-should-contextual-toolbar-show.js.map +1 -0
- package/build-style/content-rtl.css +9 -6
- package/build-style/content.css +9 -6
- package/build-style/style-rtl.css +272 -54
- package/build-style/style.css +272 -54
- package/package.json +32 -32
- package/src/components/block-info-slot-fill/index.js +24 -0
- package/src/components/block-inspector/index.js +3 -0
- package/src/components/block-inspector/style.scss +6 -4
- package/src/components/block-list/content.scss +16 -15
- package/src/components/block-list/index.native.js +19 -38
- package/src/components/block-list/use-in-between-inserter.js +4 -1
- package/src/components/block-mobile-toolbar/test/block-actions-menu.native.js +9 -9
- package/src/components/block-mover/style.scss +10 -4
- package/src/components/block-mover/test/index.native.js +4 -4
- package/src/components/block-popover/inbetween.js +2 -13
- package/src/components/block-settings-menu/block-settings-dropdown.js +2 -12
- package/src/components/block-toolbar/index.js +4 -3
- package/src/components/block-toolbar/style.scss +56 -33
- package/src/components/block-tools/block-contextual-toolbar.js +94 -11
- package/src/components/block-tools/selected-block-popover.js +11 -44
- package/src/components/block-tools/style.scss +157 -3
- package/src/components/caption/index.native.js +0 -1
- package/src/components/date-format-picker/index.js +1 -1
- package/src/components/editor-styles/index.js +9 -5
- package/src/components/font-sizes/fluid-utils.js +31 -14
- package/src/components/font-sizes/test/fluid-utils.js +5 -16
- package/src/components/global-styles/README.md +129 -16
- package/src/components/global-styles/border-panel.js +13 -61
- package/src/components/global-styles/color-panel.js +13 -13
- package/src/components/global-styles/color-panel.native.js +207 -0
- package/src/components/global-styles/dimensions-panel.js +47 -20
- package/src/components/global-styles/effects-panel.js +228 -0
- package/src/components/global-styles/filters-panel.js +230 -0
- package/src/components/global-styles/get-block-css-selector.js +0 -11
- package/src/components/global-styles/hooks.js +10 -0
- package/src/components/global-styles/index.js +2 -0
- package/src/components/global-styles/style.scss +43 -0
- package/src/components/global-styles/test/typography-utils.js +63 -22
- package/src/components/global-styles/test/use-global-styles-output.js +130 -8
- package/src/components/global-styles/typography-panel.js +37 -11
- package/src/components/global-styles/use-global-styles-output.js +88 -72
- package/src/components/iframe/index.js +1 -1
- package/src/components/image-size-control/use-dimension-handler.js +4 -3
- package/src/components/index.js +5 -1
- package/src/components/inserter/block-patterns-tab.js +3 -1
- package/src/components/inserter/block-types-tab.js +9 -6
- package/src/components/inserter/index.js +1 -1
- package/src/components/inspector-controls/groups.js +2 -0
- package/src/components/inspector-controls-tabs/styles-tab.js +1 -0
- package/src/components/inspector-controls-tabs/utils.js +4 -3
- package/src/components/list-view/README.md +2 -0
- package/src/components/list-view/block-select-button.js +6 -1
- package/src/components/list-view/block.js +24 -31
- package/src/components/list-view/drop-indicator.js +67 -22
- package/src/components/list-view/index.js +26 -3
- package/src/components/list-view/leaf.js +1 -0
- package/src/components/list-view/style.scss +18 -4
- package/src/components/list-view/test/use-list-view-drop-zone.js +188 -0
- package/src/components/list-view/use-block-selection.js +1 -1
- package/src/components/list-view/use-list-view-client-ids.js +5 -3
- package/src/components/list-view/use-list-view-drop-zone.js +9 -3
- package/src/components/media-replace-flow/README.md +3 -2
- package/src/components/media-replace-flow/index.js +4 -5
- package/src/components/navigable-toolbar/index.js +12 -3
- package/src/components/off-canvas-editor/appender.js +1 -4
- package/src/components/off-canvas-editor/block-contents.js +4 -0
- package/src/components/off-canvas-editor/index.js +15 -11
- package/src/components/resizable-box-popover/index.js +27 -0
- package/src/components/rich-text/index.js +0 -1
- package/src/components/rich-text/index.native.js +2 -5
- package/src/components/spacing-sizes-control/spacing-input-control.js +10 -0
- package/src/components/spacing-sizes-control/style.scss +7 -7
- package/src/components/url-popover/test/__snapshots__/index.js.snap +3 -3
- package/src/hooks/anchor.js +1 -1
- package/src/hooks/border.js +1 -1
- package/src/hooks/duotone.js +162 -99
- package/src/hooks/margin.js +31 -26
- package/src/hooks/padding.js +24 -18
- package/src/hooks/test/anchor.js +113 -0
- package/src/hooks/test/color.js +0 -9
- package/src/hooks/test/use-typography-props.js +2 -2
- package/src/hooks/test/utils.js +20 -101
- package/src/hooks/utils.js +23 -6
- package/src/layouts/utils.js +2 -2
- package/src/private-apis.js +8 -0
- package/src/store/actions.js +8 -1
- package/src/style.scss +1 -0
- package/src/utils/object.js +5 -5
- package/src/utils/test/object.js +53 -15
- package/src/utils/transform-styles/index.js +2 -2
- package/src/utils/use-should-contextual-toolbar-show.js +75 -0
- package/tsconfig.json +1 -0
- package/build/components/rich-text/use-native-props.js +0 -11
- package/build/components/rich-text/use-native-props.js.map +0 -1
- package/build/components/rich-text/use-native-props.native.js +0 -24
- package/build/components/rich-text/use-native-props.native.js.map +0 -1
- package/build/hooks/color-panel.native.js +0 -77
- package/build/hooks/color-panel.native.js.map +0 -1
- package/build-module/components/rich-text/use-native-props.js +0 -4
- package/build-module/components/rich-text/use-native-props.js.map +0 -1
- package/build-module/components/rich-text/use-native-props.native.js +0 -15
- package/build-module/components/rich-text/use-native-props.native.js.map +0 -1
- package/build-module/hooks/color-panel.native.js +0 -62
- package/build-module/hooks/color-panel.native.js.map +0 -1
- package/src/components/rich-text/use-native-props.js +0 -3
- package/src/components/rich-text/use-native-props.native.js +0 -17
- package/src/hooks/color-panel.native.js +0 -63
|
@@ -7,8 +7,16 @@ import classnames from 'classnames';
|
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { __ } from '@wordpress/i18n';
|
|
10
|
+
import { forwardRef, useEffect, useRef, useState } from '@wordpress/element';
|
|
10
11
|
import { hasBlockSupport, store as blocksStore } from '@wordpress/blocks';
|
|
11
12
|
import { useSelect } from '@wordpress/data';
|
|
13
|
+
import {
|
|
14
|
+
ToolbarItem,
|
|
15
|
+
ToolbarButton,
|
|
16
|
+
ToolbarGroup,
|
|
17
|
+
} from '@wordpress/components';
|
|
18
|
+
import { levelUp } from '@wordpress/icons';
|
|
19
|
+
import { useViewportMatch } from '@wordpress/compose';
|
|
12
20
|
|
|
13
21
|
/**
|
|
14
22
|
* Internal dependencies
|
|
@@ -16,10 +24,57 @@ import { useSelect } from '@wordpress/data';
|
|
|
16
24
|
import NavigableToolbar from '../navigable-toolbar';
|
|
17
25
|
import BlockToolbar from '../block-toolbar';
|
|
18
26
|
import { store as blockEditorStore } from '../../store';
|
|
27
|
+
import BlockIcon from '../block-icon';
|
|
28
|
+
|
|
29
|
+
const CollapseFixedToolbarButton = forwardRef( ( { onClick }, ref ) => {
|
|
30
|
+
return (
|
|
31
|
+
<ToolbarItem
|
|
32
|
+
as={ ToolbarButton }
|
|
33
|
+
className="block-editor-block-toolbar__collapse-fixed-toolbar"
|
|
34
|
+
icon={ levelUp }
|
|
35
|
+
onClick={ onClick }
|
|
36
|
+
ref={ ref }
|
|
37
|
+
label={ __( 'Show document tools' ) }
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
} );
|
|
41
|
+
|
|
42
|
+
const ExpandFixedToolbarButton = forwardRef( ( { onClick, icon }, ref ) => {
|
|
43
|
+
return (
|
|
44
|
+
<ToolbarItem
|
|
45
|
+
as={ ToolbarButton }
|
|
46
|
+
className="block-editor-block-toolbar__expand-fixed-toolbar"
|
|
47
|
+
icon={ <BlockIcon icon={ icon } /> }
|
|
48
|
+
onClick={ onClick }
|
|
49
|
+
ref={ ref }
|
|
50
|
+
label={ __( 'Show block tools' ) }
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
} );
|
|
19
54
|
|
|
20
55
|
function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
|
|
21
|
-
|
|
22
|
-
|
|
56
|
+
// When the toolbar is fixed it can be collapsed
|
|
57
|
+
const [ isCollapsed, setIsCollapsed ] = useState( false );
|
|
58
|
+
const expandFixedToolbarButtonRef = useRef();
|
|
59
|
+
const collapseFixedToolbarButtonRef = useRef();
|
|
60
|
+
|
|
61
|
+
// Don't focus the block toolbar just because it mounts
|
|
62
|
+
const initialRender = useRef( true );
|
|
63
|
+
useEffect( () => {
|
|
64
|
+
if ( initialRender.current ) {
|
|
65
|
+
initialRender.current = false;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if ( isCollapsed && expandFixedToolbarButtonRef.current ) {
|
|
69
|
+
expandFixedToolbarButtonRef.current.focus();
|
|
70
|
+
}
|
|
71
|
+
if ( ! isCollapsed && collapseFixedToolbarButtonRef.current ) {
|
|
72
|
+
collapseFixedToolbarButtonRef.current.focus();
|
|
73
|
+
}
|
|
74
|
+
}, [ isCollapsed ] );
|
|
75
|
+
|
|
76
|
+
const { blockType, hasParents, showParentSelector, selectedBlockClientId } =
|
|
77
|
+
useSelect( ( select ) => {
|
|
23
78
|
const {
|
|
24
79
|
getBlockName,
|
|
25
80
|
getBlockParents,
|
|
@@ -28,16 +83,17 @@ function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
|
|
|
28
83
|
} = select( blockEditorStore );
|
|
29
84
|
const { getBlockType } = select( blocksStore );
|
|
30
85
|
const selectedBlockClientIds = getSelectedBlockClientIds();
|
|
31
|
-
const
|
|
32
|
-
const parents = getBlockParents(
|
|
86
|
+
const _selectedBlockClientId = selectedBlockClientIds[ 0 ];
|
|
87
|
+
const parents = getBlockParents( _selectedBlockClientId );
|
|
33
88
|
const firstParentClientId = parents[ parents.length - 1 ];
|
|
34
89
|
const parentBlockName = getBlockName( firstParentClientId );
|
|
35
90
|
const parentBlockType = getBlockType( parentBlockName );
|
|
36
91
|
|
|
37
92
|
return {
|
|
93
|
+
selectedBlockClientId: _selectedBlockClientId,
|
|
38
94
|
blockType:
|
|
39
|
-
|
|
40
|
-
getBlockType( getBlockName(
|
|
95
|
+
_selectedBlockClientId &&
|
|
96
|
+
getBlockType( getBlockName( _selectedBlockClientId ) ),
|
|
41
97
|
hasParents: parents.length,
|
|
42
98
|
showParentSelector:
|
|
43
99
|
parentBlockType &&
|
|
@@ -48,12 +104,16 @@ function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
|
|
|
48
104
|
) &&
|
|
49
105
|
selectedBlockClientIds.length <= 1 &&
|
|
50
106
|
! __unstableGetContentLockingParent(
|
|
51
|
-
|
|
107
|
+
_selectedBlockClientId
|
|
52
108
|
),
|
|
53
109
|
};
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
)
|
|
110
|
+
}, [] );
|
|
111
|
+
|
|
112
|
+
useEffect( () => {
|
|
113
|
+
setIsCollapsed( false );
|
|
114
|
+
}, [ selectedBlockClientId ] );
|
|
115
|
+
|
|
116
|
+
const isLargeViewport = useViewportMatch( 'medium' );
|
|
57
117
|
|
|
58
118
|
if ( blockType ) {
|
|
59
119
|
if ( ! hasBlockSupport( blockType, '__experimentalToolbar', true ) ) {
|
|
@@ -65,6 +125,7 @@ function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
|
|
|
65
125
|
const classes = classnames( 'block-editor-block-contextual-toolbar', {
|
|
66
126
|
'has-parent': hasParents && showParentSelector,
|
|
67
127
|
'is-fixed': isFixed,
|
|
128
|
+
'is-collapsed': isCollapsed,
|
|
68
129
|
} );
|
|
69
130
|
|
|
70
131
|
return (
|
|
@@ -75,7 +136,29 @@ function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
|
|
|
75
136
|
aria-label={ __( 'Block tools' ) }
|
|
76
137
|
{ ...props }
|
|
77
138
|
>
|
|
78
|
-
|
|
139
|
+
{ isFixed && isLargeViewport && blockType && (
|
|
140
|
+
<ToolbarGroup
|
|
141
|
+
className={
|
|
142
|
+
isCollapsed
|
|
143
|
+
? 'block-editor-block-toolbar__group-expand-fixed-toolbar'
|
|
144
|
+
: 'block-editor-block-toolbar__group-collapse-fixed-toolbar'
|
|
145
|
+
}
|
|
146
|
+
>
|
|
147
|
+
{ isCollapsed ? (
|
|
148
|
+
<ExpandFixedToolbarButton
|
|
149
|
+
onClick={ () => setIsCollapsed( false ) }
|
|
150
|
+
icon={ blockType.icon }
|
|
151
|
+
ref={ expandFixedToolbarButtonRef }
|
|
152
|
+
/>
|
|
153
|
+
) : (
|
|
154
|
+
<CollapseFixedToolbarButton
|
|
155
|
+
onClick={ () => setIsCollapsed( true ) }
|
|
156
|
+
ref={ collapseFixedToolbarButtonRef }
|
|
157
|
+
/>
|
|
158
|
+
) }
|
|
159
|
+
</ToolbarGroup>
|
|
160
|
+
) }
|
|
161
|
+
{ ! isCollapsed && <BlockToolbar hideDragHandle={ isFixed } /> }
|
|
79
162
|
</NavigableToolbar>
|
|
80
163
|
);
|
|
81
164
|
}
|
|
@@ -10,7 +10,6 @@ import { useRef, useEffect } from '@wordpress/element';
|
|
|
10
10
|
import { isUnmodifiedDefaultBlock } from '@wordpress/blocks';
|
|
11
11
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
12
12
|
import { useShortcut } from '@wordpress/keyboard-shortcuts';
|
|
13
|
-
import { useViewportMatch } from '@wordpress/compose';
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* Internal dependencies
|
|
@@ -22,26 +21,20 @@ import BlockPopover from '../block-popover';
|
|
|
22
21
|
import useBlockToolbarPopoverProps from './use-block-toolbar-popover-props';
|
|
23
22
|
import Inserter from '../inserter';
|
|
24
23
|
import { unlock } from '../../lock-unlock';
|
|
24
|
+
import { privateApis } from '../../private-apis';
|
|
25
25
|
|
|
26
26
|
function selector( select ) {
|
|
27
27
|
const {
|
|
28
28
|
__unstableGetEditorMode,
|
|
29
|
-
isMultiSelecting,
|
|
30
29
|
hasMultiSelection,
|
|
31
30
|
isTyping,
|
|
32
|
-
isBlockInterfaceHidden,
|
|
33
|
-
getSettings,
|
|
34
31
|
getLastMultiSelectedBlockClientId,
|
|
35
32
|
} = unlock( select( blockEditorStore ) );
|
|
36
33
|
|
|
37
34
|
return {
|
|
38
35
|
editorMode: __unstableGetEditorMode(),
|
|
39
36
|
hasMultiSelection: hasMultiSelection(),
|
|
40
|
-
isMultiSelecting: isMultiSelecting(),
|
|
41
37
|
isTyping: isTyping(),
|
|
42
|
-
isBlockInterfaceHidden: isBlockInterfaceHidden(),
|
|
43
|
-
hasFixedToolbar: getSettings().hasFixedToolbar,
|
|
44
|
-
isDistractionFree: getSettings().isDistractionFree,
|
|
45
38
|
lastClientId: hasMultiSelection()
|
|
46
39
|
? getLastMultiSelectedBlockClientId()
|
|
47
40
|
: null,
|
|
@@ -52,21 +45,16 @@ function SelectedBlockPopover( {
|
|
|
52
45
|
clientId,
|
|
53
46
|
rootClientId,
|
|
54
47
|
isEmptyDefaultBlock,
|
|
55
|
-
showContents, // we may need to mount an empty popover because we reuse
|
|
56
48
|
capturingClientId,
|
|
57
49
|
__unstablePopoverSlot,
|
|
58
50
|
__unstableContentRef,
|
|
59
51
|
} ) {
|
|
60
|
-
const {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
hasFixedToolbar,
|
|
67
|
-
isDistractionFree,
|
|
68
|
-
lastClientId,
|
|
69
|
-
} = useSelect( selector, [] );
|
|
52
|
+
const { editorMode, hasMultiSelection, isTyping, lastClientId } = useSelect(
|
|
53
|
+
selector,
|
|
54
|
+
[]
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const { useShouldContextualToolbarShow } = unlock( privateApis );
|
|
70
58
|
const isInsertionPointVisible = useSelect(
|
|
71
59
|
( select ) => {
|
|
72
60
|
const {
|
|
@@ -85,8 +73,10 @@ function SelectedBlockPopover( {
|
|
|
85
73
|
},
|
|
86
74
|
[ clientId ]
|
|
87
75
|
);
|
|
88
|
-
const isLargeViewport = useViewportMatch( 'medium' );
|
|
89
76
|
const isToolbarForced = useRef( false );
|
|
77
|
+
const { shouldShowContextualToolbar, canFocusHiddenToolbar } =
|
|
78
|
+
useShouldContextualToolbarShow( clientId );
|
|
79
|
+
|
|
90
80
|
const { stopTyping } = useDispatch( blockEditorStore );
|
|
91
81
|
|
|
92
82
|
const showEmptyBlockSideInserter =
|
|
@@ -94,20 +84,6 @@ function SelectedBlockPopover( {
|
|
|
94
84
|
const shouldShowBreadcrumb =
|
|
95
85
|
! hasMultiSelection &&
|
|
96
86
|
( editorMode === 'navigation' || editorMode === 'zoom-out' );
|
|
97
|
-
const shouldShowContextualToolbar =
|
|
98
|
-
editorMode === 'edit' &&
|
|
99
|
-
! hasFixedToolbar &&
|
|
100
|
-
isLargeViewport &&
|
|
101
|
-
! isMultiSelecting &&
|
|
102
|
-
! showEmptyBlockSideInserter &&
|
|
103
|
-
! isTyping &&
|
|
104
|
-
! isBlockInterfaceHidden;
|
|
105
|
-
const canFocusHiddenToolbar =
|
|
106
|
-
editorMode === 'edit' &&
|
|
107
|
-
! shouldShowContextualToolbar &&
|
|
108
|
-
! hasFixedToolbar &&
|
|
109
|
-
! isDistractionFree &&
|
|
110
|
-
! isEmptyDefaultBlock;
|
|
111
87
|
|
|
112
88
|
useShortcut(
|
|
113
89
|
'core/block-editor/focus-toolbar',
|
|
@@ -179,7 +155,7 @@ function SelectedBlockPopover( {
|
|
|
179
155
|
resize={ false }
|
|
180
156
|
{ ...popoverProps }
|
|
181
157
|
>
|
|
182
|
-
{ shouldShowContextualToolbar &&
|
|
158
|
+
{ shouldShowContextualToolbar && (
|
|
183
159
|
<BlockContextualToolbar
|
|
184
160
|
// If the toolbar is being shown because of being forced
|
|
185
161
|
// it should focus the toolbar right after the mount.
|
|
@@ -215,8 +191,6 @@ function wrapperSelector( select ) {
|
|
|
215
191
|
getBlockRootClientId,
|
|
216
192
|
getBlock,
|
|
217
193
|
getBlockParents,
|
|
218
|
-
getSettings,
|
|
219
|
-
isNavigationMode: _isNavigationMode,
|
|
220
194
|
__experimentalGetBlockListSettingsForBlocks,
|
|
221
195
|
} = select( blockEditorStore );
|
|
222
196
|
|
|
@@ -242,14 +216,10 @@ function wrapperSelector( select ) {
|
|
|
242
216
|
?.__experimentalCaptureToolbars
|
|
243
217
|
);
|
|
244
218
|
|
|
245
|
-
const settings = getSettings();
|
|
246
|
-
|
|
247
219
|
return {
|
|
248
220
|
clientId,
|
|
249
221
|
rootClientId: getBlockRootClientId( clientId ),
|
|
250
222
|
name,
|
|
251
|
-
isDistractionFree: settings.isDistractionFree,
|
|
252
|
-
isNavigationMode: _isNavigationMode(),
|
|
253
223
|
isEmptyDefaultBlock:
|
|
254
224
|
name && isUnmodifiedDefaultBlock( { name, attributes } ),
|
|
255
225
|
capturingClientId,
|
|
@@ -272,8 +242,6 @@ export default function WrappedBlockPopover( {
|
|
|
272
242
|
name,
|
|
273
243
|
isEmptyDefaultBlock,
|
|
274
244
|
capturingClientId,
|
|
275
|
-
isDistractionFree,
|
|
276
|
-
isNavigationMode,
|
|
277
245
|
} = selected;
|
|
278
246
|
|
|
279
247
|
if ( ! name ) {
|
|
@@ -285,7 +253,6 @@ export default function WrappedBlockPopover( {
|
|
|
285
253
|
clientId={ clientId }
|
|
286
254
|
rootClientId={ rootClientId }
|
|
287
255
|
isEmptyDefaultBlock={ isEmptyDefaultBlock }
|
|
288
|
-
showContents={ ! isDistractionFree || isNavigationMode }
|
|
289
256
|
capturingClientId={ capturingClientId }
|
|
290
257
|
__unstablePopoverSlot={ __unstablePopoverSlot }
|
|
291
258
|
__unstableContentRef={ __unstableContentRef }
|
|
@@ -89,6 +89,9 @@
|
|
|
89
89
|
* Block Toolbar when contextual.
|
|
90
90
|
*/
|
|
91
91
|
|
|
92
|
+
// Base left position for the toolbar when fixed.
|
|
93
|
+
@include editor-left(".block-editor-block-contextual-toolbar.is-fixed");
|
|
94
|
+
|
|
92
95
|
.block-editor-block-contextual-toolbar {
|
|
93
96
|
// Block UI appearance.
|
|
94
97
|
display: inline-flex;
|
|
@@ -104,11 +107,9 @@
|
|
|
104
107
|
&.is-fixed {
|
|
105
108
|
position: sticky;
|
|
106
109
|
top: 0;
|
|
107
|
-
width: 100%;
|
|
108
110
|
z-index: z-index(".block-editor-block-popover");
|
|
109
|
-
// Fill up when empty
|
|
110
|
-
min-height: $block-toolbar-height;
|
|
111
111
|
display: block;
|
|
112
|
+
width: 100%;
|
|
112
113
|
|
|
113
114
|
border: none;
|
|
114
115
|
border-bottom: $border-width solid $gray-200;
|
|
@@ -119,6 +120,159 @@
|
|
|
119
120
|
border-right-color: $gray-200;
|
|
120
121
|
}
|
|
121
122
|
}
|
|
123
|
+
|
|
124
|
+
// on desktop and tablet viewports the toolbar is fixed
|
|
125
|
+
// on top of interface header
|
|
126
|
+
|
|
127
|
+
@include break-medium() {
|
|
128
|
+
&.is-fixed {
|
|
129
|
+
|
|
130
|
+
// leave room for block inserter
|
|
131
|
+
margin-left: $grid-unit-80;
|
|
132
|
+
// position on top of interface header
|
|
133
|
+
position: fixed;
|
|
134
|
+
top: $admin-bar-height + $grid-unit;
|
|
135
|
+
// Don't fill up when empty
|
|
136
|
+
min-height: initial;
|
|
137
|
+
// remove the border
|
|
138
|
+
border-bottom: none;
|
|
139
|
+
// has to be flex for collapse button to fit
|
|
140
|
+
display: flex;
|
|
141
|
+
|
|
142
|
+
&.is-collapsed {
|
|
143
|
+
width: initial;
|
|
144
|
+
margin-left: $grid-unit-80 * 3 + $grid-unit-30;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.is-fullscreen-mode & {
|
|
148
|
+
// leave room for block inserter
|
|
149
|
+
margin-left: $grid-unit-80 + $grid-unit-70;
|
|
150
|
+
top: $grid-unit;
|
|
151
|
+
&.is-collapsed {
|
|
152
|
+
width: initial;
|
|
153
|
+
margin-left: $grid-unit-80 * 4 + $grid-unit-30;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
& > .block-editor-block-toolbar__group-collapse-fixed-toolbar {
|
|
158
|
+
border: none;
|
|
159
|
+
|
|
160
|
+
// Add a border as separator in the block toolbar.
|
|
161
|
+
&::after {
|
|
162
|
+
content: "";
|
|
163
|
+
width: $border-width;
|
|
164
|
+
height: 24px;
|
|
165
|
+
margin-top: $grid-unit + $grid-unit-05;
|
|
166
|
+
margin-bottom: $grid-unit + $grid-unit-05;
|
|
167
|
+
background-color: $gray-300;
|
|
168
|
+
position: absolute;
|
|
169
|
+
left: 44px;
|
|
170
|
+
top: -1px;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
& > .block-editor-block-toolbar__group-expand-fixed-toolbar {
|
|
175
|
+
border: none;
|
|
176
|
+
|
|
177
|
+
// Add a border as separator in the block toolbar.
|
|
178
|
+
&::before {
|
|
179
|
+
content: "";
|
|
180
|
+
width: $border-width;
|
|
181
|
+
margin-top: $grid-unit + $grid-unit-05;
|
|
182
|
+
margin-bottom: $grid-unit + $grid-unit-05;
|
|
183
|
+
background-color: $gray-300;
|
|
184
|
+
position: relative;
|
|
185
|
+
left: -12px; //the padding of buttons
|
|
186
|
+
height: 24px;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.show-icon-labels & {
|
|
191
|
+
|
|
192
|
+
margin-left: $grid-unit-80;
|
|
193
|
+
|
|
194
|
+
&.is-collapsed {
|
|
195
|
+
margin-left: $grid-unit-80 * 6;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.is-fullscreen-mode & {
|
|
199
|
+
margin-left: $grid-unit-80 + $grid-unit-80;
|
|
200
|
+
&.is-collapsed {
|
|
201
|
+
margin-left: $grid-unit-80 * 7;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
.block-editor-block-parent-selector .block-editor-block-parent-selector__button::after {
|
|
207
|
+
left: 0;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.block-editor-block-toolbar__block-controls .block-editor-block-mover {
|
|
211
|
+
border-left: none;
|
|
212
|
+
&::before {
|
|
213
|
+
content: "";
|
|
214
|
+
width: $border-width;
|
|
215
|
+
margin-top: $grid-unit + $grid-unit-05;
|
|
216
|
+
margin-bottom: $grid-unit + $grid-unit-05;
|
|
217
|
+
background-color: $gray-300;
|
|
218
|
+
position: relative;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
&.is-fixed .block-editor-block-parent-selector {
|
|
225
|
+
.block-editor-block-parent-selector__button {
|
|
226
|
+
position: relative;
|
|
227
|
+
top: -1px;
|
|
228
|
+
border: 0;
|
|
229
|
+
padding-right: 6px;
|
|
230
|
+
padding-left: 6px;
|
|
231
|
+
&::after {
|
|
232
|
+
content: "\00B7";
|
|
233
|
+
font-size: 16px;
|
|
234
|
+
line-height: $grid-unit-40 + $grid-unit-10;
|
|
235
|
+
position: absolute;
|
|
236
|
+
left: $grid-unit-40 + $grid-unit-15 + 2px;
|
|
237
|
+
bottom: $grid-unit-05;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
&:not(.is-fixed) .block-editor-block-parent-selector {
|
|
243
|
+
position: absolute;
|
|
244
|
+
top: -$border-width;
|
|
245
|
+
left: calc(-#{$grid-unit-60} - #{$grid-unit-10} - #{$border-width});
|
|
246
|
+
|
|
247
|
+
.show-icon-labels & {
|
|
248
|
+
position: relative;
|
|
249
|
+
left: auto;
|
|
250
|
+
top: auto;
|
|
251
|
+
margin-top: -$border-width;
|
|
252
|
+
margin-left: -$border-width;
|
|
253
|
+
margin-bottom: -$border-width;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// on tablet vewports the toolbar is fixed
|
|
259
|
+
// on top of interface header and covers the whole header
|
|
260
|
+
// except for the inserter on the left
|
|
261
|
+
@include break-medium() {
|
|
262
|
+
&.is-fixed {
|
|
263
|
+
width: 100%;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// on desktop viewports the toolbar is fixed
|
|
268
|
+
// on top of interface header and leaves room
|
|
269
|
+
// for the block inserter the publish button
|
|
270
|
+
@include break-large() {
|
|
271
|
+
&.is-fixed {
|
|
272
|
+
width: initial;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
122
276
|
}
|
|
123
277
|
|
|
124
278
|
/**
|
|
@@ -142,7 +142,7 @@ function NonDefaultControls( { format, onChange } ) {
|
|
|
142
142
|
Link: (
|
|
143
143
|
<ExternalLink
|
|
144
144
|
href={ __(
|
|
145
|
-
'https://wordpress.org/
|
|
145
|
+
'https://wordpress.org/documentation/article/customize-date-and-time-format/'
|
|
146
146
|
) }
|
|
147
147
|
/>
|
|
148
148
|
),
|
|
@@ -68,29 +68,33 @@ function useDarkThemeBodyClassName( styles ) {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
export default function EditorStyles( { styles } ) {
|
|
71
|
+
const stylesArray = useMemo(
|
|
72
|
+
() => Object.values( styles ?? [] ),
|
|
73
|
+
[ styles ]
|
|
74
|
+
);
|
|
71
75
|
const transformedStyles = useMemo(
|
|
72
76
|
() =>
|
|
73
77
|
transformStyles(
|
|
74
|
-
|
|
78
|
+
stylesArray.filter( ( style ) => style?.css ),
|
|
75
79
|
EDITOR_STYLES_SELECTOR
|
|
76
80
|
),
|
|
77
|
-
[
|
|
81
|
+
[ stylesArray ]
|
|
78
82
|
);
|
|
79
83
|
|
|
80
84
|
const transformedSvgs = useMemo(
|
|
81
85
|
() =>
|
|
82
|
-
|
|
86
|
+
stylesArray
|
|
83
87
|
.filter( ( style ) => style.__unstableType === 'svgs' )
|
|
84
88
|
.map( ( style ) => style.assets )
|
|
85
89
|
.join( '' ),
|
|
86
|
-
[
|
|
90
|
+
[ stylesArray ]
|
|
87
91
|
);
|
|
88
92
|
|
|
89
93
|
return (
|
|
90
94
|
<>
|
|
91
95
|
{ /* Use an empty style element to have a document reference,
|
|
92
96
|
but this could be any element. */ }
|
|
93
|
-
<style ref={ useDarkThemeBodyClassName(
|
|
97
|
+
<style ref={ useDarkThemeBodyClassName( stylesArray ) } />
|
|
94
98
|
{ transformedStyles.map( ( css, index ) => (
|
|
95
99
|
<style key={ index }>{ css }</style>
|
|
96
100
|
) ) }
|
|
@@ -6,18 +6,17 @@
|
|
|
6
6
|
|
|
7
7
|
// Defaults.
|
|
8
8
|
const DEFAULT_MAXIMUM_VIEWPORT_WIDTH = '1600px';
|
|
9
|
-
const DEFAULT_MINIMUM_VIEWPORT_WIDTH = '
|
|
9
|
+
const DEFAULT_MINIMUM_VIEWPORT_WIDTH = '320px';
|
|
10
10
|
const DEFAULT_SCALE_FACTOR = 1;
|
|
11
|
-
const
|
|
11
|
+
const DEFAULT_MINIMUM_FONT_SIZE_FACTOR_MIN = 0.25;
|
|
12
|
+
const DEFAULT_MINIMUM_FONT_SIZE_FACTOR_MAX = 0.75;
|
|
12
13
|
const DEFAULT_MINIMUM_FONT_SIZE_LIMIT = '14px';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Computes a fluid font-size value that uses clamp(). A minimum and maximum
|
|
16
17
|
* font size OR a single font size can be specified.
|
|
17
18
|
*
|
|
18
|
-
* If a single font size is specified, it is scaled up and down
|
|
19
|
-
* minimumFontSizeFactor and maximumFontSizeFactor to arrive at the minimum and
|
|
20
|
-
* maximum sizes.
|
|
19
|
+
* If a single font size is specified, it is scaled up and down using a logarithmic scale.
|
|
21
20
|
*
|
|
22
21
|
* @example
|
|
23
22
|
* ```js
|
|
@@ -33,14 +32,13 @@ const DEFAULT_MINIMUM_FONT_SIZE_LIMIT = '14px';
|
|
|
33
32
|
* ```
|
|
34
33
|
*
|
|
35
34
|
* @param {Object} args
|
|
36
|
-
* @param {?string} args.minimumViewPortWidth
|
|
37
|
-
* @param {?string} args.maximumViewPortWidth
|
|
38
|
-
* @param {string|number} [args.fontSize]
|
|
39
|
-
* @param {?string} args.maximumFontSize
|
|
40
|
-
* @param {?string} args.minimumFontSize
|
|
41
|
-
* @param {?number} args.scaleFactor
|
|
42
|
-
* @param {?
|
|
43
|
-
* @param {?string} args.minimumFontSizeLimit The smallest a calculated font size may be. Optional.
|
|
35
|
+
* @param {?string} args.minimumViewPortWidth Minimum viewport size from which type will have fluidity. Optional if fontSize is specified.
|
|
36
|
+
* @param {?string} args.maximumViewPortWidth Maximum size up to which type will have fluidity. Optional if fontSize is specified.
|
|
37
|
+
* @param {string|number} [args.fontSize] Size to derive maximumFontSize and minimumFontSize from, if necessary. Optional if minimumFontSize and maximumFontSize are specified.
|
|
38
|
+
* @param {?string} args.maximumFontSize Maximum font size for any clamp() calculation. Optional.
|
|
39
|
+
* @param {?string} args.minimumFontSize Minimum font size for any clamp() calculation. Optional.
|
|
40
|
+
* @param {?number} args.scaleFactor A scale factor to determine how fast a font scales within boundaries. Optional.
|
|
41
|
+
* @param {?string} args.minimumFontSizeLimit The smallest a calculated font size may be. Optional.
|
|
44
42
|
*
|
|
45
43
|
* @return {string|null} A font-size value using clamp().
|
|
46
44
|
*/
|
|
@@ -51,7 +49,6 @@ export function getComputedFluidTypographyValue( {
|
|
|
51
49
|
minimumViewPortWidth = DEFAULT_MINIMUM_VIEWPORT_WIDTH,
|
|
52
50
|
maximumViewPortWidth = DEFAULT_MAXIMUM_VIEWPORT_WIDTH,
|
|
53
51
|
scaleFactor = DEFAULT_SCALE_FACTOR,
|
|
54
|
-
minimumFontSizeFactor = DEFAULT_MINIMUM_FONT_SIZE_FACTOR,
|
|
55
52
|
minimumFontSizeLimit,
|
|
56
53
|
} ) {
|
|
57
54
|
// Validate incoming settings and set defaults.
|
|
@@ -106,6 +103,26 @@ export function getComputedFluidTypographyValue( {
|
|
|
106
103
|
* the given font size multiplied by the min font size scale factor.
|
|
107
104
|
*/
|
|
108
105
|
if ( ! minimumFontSize ) {
|
|
106
|
+
const fontSizeValueInPx =
|
|
107
|
+
fontSizeParsed.unit === 'px'
|
|
108
|
+
? fontSizeParsed.value
|
|
109
|
+
: fontSizeParsed.value * 16;
|
|
110
|
+
|
|
111
|
+
/*
|
|
112
|
+
* The scale factor is a multiplier that affects how quickly the curve will move towards the minimum,
|
|
113
|
+
* that is, how quickly the size factor reaches 0 given increasing font size values.
|
|
114
|
+
* For a - b * log2(), lower values of b will make the curve move towards the minimum faster.
|
|
115
|
+
* The scale factor is constrained between min and max values.
|
|
116
|
+
*/
|
|
117
|
+
const minimumFontSizeFactor = Math.min(
|
|
118
|
+
Math.max(
|
|
119
|
+
1 - 0.075 * Math.log2( fontSizeValueInPx ),
|
|
120
|
+
DEFAULT_MINIMUM_FONT_SIZE_FACTOR_MIN
|
|
121
|
+
),
|
|
122
|
+
DEFAULT_MINIMUM_FONT_SIZE_FACTOR_MAX
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
// Calculates the minimum font size.
|
|
109
126
|
const calculatedMinimumFontSize = roundToPrecision(
|
|
110
127
|
fontSizeParsed.value * minimumFontSizeFactor,
|
|
111
128
|
3
|
|
@@ -24,7 +24,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
|
|
|
24
24
|
maximumFontSize: '45px',
|
|
25
25
|
} );
|
|
26
26
|
expect( fluidTypographyValues ).toBe(
|
|
27
|
-
'clamp(20px, 1.25rem + ((1vw -
|
|
27
|
+
'clamp(20px, 1.25rem + ((1vw - 3.2px) * 1.953), 45px)'
|
|
28
28
|
);
|
|
29
29
|
} );
|
|
30
30
|
|
|
@@ -33,7 +33,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
|
|
|
33
33
|
fontSize: '30px',
|
|
34
34
|
} );
|
|
35
35
|
expect( fluidTypographyValues ).toBe(
|
|
36
|
-
'clamp(
|
|
36
|
+
'clamp(18.959px, 1.185rem + ((1vw - 3.2px) * 0.863), 30px)'
|
|
37
37
|
);
|
|
38
38
|
} );
|
|
39
39
|
|
|
@@ -42,7 +42,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
|
|
|
42
42
|
fontSize: '30px',
|
|
43
43
|
} );
|
|
44
44
|
expect( fluidTypographyValues ).toBe(
|
|
45
|
-
'clamp(
|
|
45
|
+
'clamp(18.959px, 1.185rem + ((1vw - 3.2px) * 0.863), 30px)'
|
|
46
46
|
);
|
|
47
47
|
} );
|
|
48
48
|
|
|
@@ -53,7 +53,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
|
|
|
53
53
|
maximumViewPortWidth: '1000px',
|
|
54
54
|
} );
|
|
55
55
|
expect( fluidTypographyValues ).toBe(
|
|
56
|
-
'clamp(
|
|
56
|
+
'clamp(18.959px, 1.185rem + ((1vw - 5px) * 2.208), 30px)'
|
|
57
57
|
);
|
|
58
58
|
} );
|
|
59
59
|
|
|
@@ -63,18 +63,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
|
|
|
63
63
|
scaleFactor: '2',
|
|
64
64
|
} );
|
|
65
65
|
expect( fluidTypographyValues ).toBe(
|
|
66
|
-
'clamp(
|
|
67
|
-
);
|
|
68
|
-
} );
|
|
69
|
-
|
|
70
|
-
it( 'should return a fluid font size when given a min and max font size factor', () => {
|
|
71
|
-
const fluidTypographyValues = getComputedFluidTypographyValue( {
|
|
72
|
-
fontSize: '30px',
|
|
73
|
-
minimumFontSizeFactor: '0.5',
|
|
74
|
-
maximumFontSizeFactor: '2',
|
|
75
|
-
} );
|
|
76
|
-
expect( fluidTypographyValues ).toBe(
|
|
77
|
-
'clamp(15px, 0.938rem + ((1vw - 7.68px) * 1.803), 30px)'
|
|
66
|
+
'clamp(18.959px, 1.185rem + ((1vw - 3.2px) * 1.725), 30px)'
|
|
78
67
|
);
|
|
79
68
|
} );
|
|
80
69
|
|