@wordpress/block-editor 12.4.0 → 12.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +5 -0
- package/build/components/block-heading-level-dropdown/heading-level-icon.js +10 -2
- package/build/components/block-heading-level-dropdown/heading-level-icon.js.map +1 -1
- package/build/components/block-heading-level-dropdown/index.native.js +4 -3
- package/build/components/block-heading-level-dropdown/index.native.js.map +1 -1
- package/build/components/block-lock/toolbar.js +25 -6
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js +3 -6
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build/components/block-parent-selector/index.js +8 -5
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-removal-warning-modal/index.js +18 -25
- package/build/components/block-removal-warning-modal/index.js.map +1 -1
- package/build/components/block-toolbar/index.js +8 -5
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +7 -11
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/dimensions-tool/aspect-ratio-tool.js +99 -0
- package/build/components/dimensions-tool/aspect-ratio-tool.js.map +1 -0
- package/build/components/dimensions-tool/index.js +207 -0
- package/build/components/dimensions-tool/index.js.map +1 -0
- package/build/components/dimensions-tool/scale-tool.js +111 -0
- package/build/components/dimensions-tool/scale-tool.js.map +1 -0
- package/build/components/dimensions-tool/width-height-tool.js +125 -0
- package/build/components/dimensions-tool/width-height-tool.js.map +1 -0
- package/build/components/global-styles/color-panel.js +1 -1
- package/build/components/global-styles/color-panel.js.map +1 -1
- package/build/components/global-styles/filters-panel.js +1 -1
- package/build/components/global-styles/filters-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +2 -2
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +34 -2
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/image-editor/aspect-ratio-dropdown.js +1 -1
- package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build/components/image-editor/use-save-image.js +1 -2
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/image-size-control/index.js +6 -0
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/index.js +19 -1
- package/build/components/index.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/patterns-list.js +2 -2
- package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +7 -35
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/hooks/use-block-types-state.js +3 -4
- package/build/components/inserter/hooks/use-block-types-state.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-state.js +9 -3
- package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build/components/inserter/media-tab/hooks.js +2 -21
- package/build/components/inserter/media-tab/hooks.js.map +1 -1
- package/build/components/inserter/reusable-block-rename-hint.js +62 -0
- package/build/components/inserter/reusable-block-rename-hint.js.map +1 -0
- package/build/components/inserter/reusable-blocks-tab.js +6 -2
- package/build/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build/components/inserter/reusable-blocks-tab.native.js +2 -2
- package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build/components/inserter/tabs.native.js +1 -1
- package/build/components/inserter/tabs.native.js.map +1 -1
- package/build/components/inserter-draggable-blocks/index.js +9 -1
- package/build/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build/components/link-control/constants.js +1 -1
- package/build/components/link-control/constants.js.map +1 -1
- package/build/components/link-control/index.js +17 -15
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/search-create-button.js +5 -21
- package/build/components/link-control/search-create-button.js.map +1 -1
- package/build/components/link-control/search-input.js +4 -4
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/link-control/search-item.js +13 -30
- package/build/components/link-control/search-item.js.map +1 -1
- package/build/components/link-control/search-results.js +2 -2
- package/build/components/link-control/search-results.js.map +1 -1
- package/build/components/link-control/settings-drawer.js +2 -3
- package/build/components/link-control/settings-drawer.js.map +1 -1
- package/build/components/list-view/appender.js +2 -6
- package/build/components/list-view/appender.js.map +1 -1
- package/build/components/provider/index.js +5 -2
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/use-block-sync.js +21 -0
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/components/resolution-tool/index.js +55 -0
- package/build/components/resolution-tool/index.js.map +1 -0
- package/build/components/url-input/index.js +4 -2
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/writing-flow/use-tab-nav.js +10 -27
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build/components/writing-mode-control/index.js +70 -0
- package/build/components/writing-mode-control/index.js.map +1 -0
- package/build/hooks/behaviors.js +25 -20
- package/build/hooks/behaviors.js.map +1 -1
- package/build/hooks/supports.js +7 -1
- package/build/hooks/supports.js.map +1 -1
- package/build/hooks/typography.js +2 -1
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/utils.js +4 -2
- package/build/hooks/utils.js.map +1 -1
- package/build/private-apis.js +10 -1
- package/build/private-apis.js.map +1 -1
- package/build/private-apis.native.js +3 -0
- package/build/private-apis.native.js.map +1 -1
- package/build/store/actions.js +195 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +1 -0
- package/build/store/defaults.js.map +1 -1
- package/build/store/index.js +10 -1
- package/build/store/index.js.map +1 -1
- package/build/store/private-actions.js +46 -40
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +3 -3
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +22 -8
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +33 -15
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-heading-level-dropdown/heading-level-icon.js +9 -2
- package/build-module/components/block-heading-level-dropdown/heading-level-icon.js.map +1 -1
- package/build-module/components/block-heading-level-dropdown/index.native.js +4 -3
- package/build-module/components/block-heading-level-dropdown/index.native.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +25 -7
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +4 -6
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +7 -5
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-removal-warning-modal/index.js +20 -24
- package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +8 -5
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +8 -11
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js +87 -0
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js.map +1 -0
- package/build-module/components/dimensions-tool/index.js +195 -0
- package/build-module/components/dimensions-tool/index.js.map +1 -0
- package/build-module/components/dimensions-tool/scale-tool.js +103 -0
- package/build-module/components/dimensions-tool/scale-tool.js.map +1 -0
- package/build-module/components/dimensions-tool/width-height-tool.js +122 -0
- package/build-module/components/dimensions-tool/width-height-tool.js.map +1 -0
- package/build-module/components/global-styles/color-panel.js +1 -1
- package/build-module/components/global-styles/color-panel.js.map +1 -1
- package/build-module/components/global-styles/filters-panel.js +2 -2
- package/build-module/components/global-styles/filters-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +2 -2
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +33 -2
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/image-editor/aspect-ratio-dropdown.js +1 -1
- package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build-module/components/image-editor/use-save-image.js +1 -2
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/image-size-control/index.js +5 -0
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/index.js +6 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js +2 -2
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +7 -33
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/hooks/use-block-types-state.js +3 -4
- package/build-module/components/inserter/hooks/use-block-types-state.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js +9 -3
- package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build-module/components/inserter/media-tab/hooks.js +2 -21
- package/build-module/components/inserter/media-tab/hooks.js.map +1 -1
- package/build-module/components/inserter/reusable-block-rename-hint.js +48 -0
- package/build-module/components/inserter/reusable-block-rename-hint.js.map +1 -0
- package/build-module/components/inserter/reusable-blocks-tab.js +5 -2
- package/build-module/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build-module/components/inserter/reusable-blocks-tab.native.js +2 -2
- package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build-module/components/inserter/tabs.native.js +1 -1
- package/build-module/components/inserter/tabs.native.js.map +1 -1
- package/build-module/components/inserter-draggable-blocks/index.js +9 -2
- package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build-module/components/link-control/constants.js +1 -1
- package/build-module/components/link-control/constants.js.map +1 -1
- package/build-module/components/link-control/index.js +17 -15
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/search-create-button.js +7 -20
- package/build-module/components/link-control/search-create-button.js.map +1 -1
- package/build-module/components/link-control/search-input.js +4 -4
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/link-control/search-item.js +14 -28
- package/build-module/components/link-control/search-item.js.map +1 -1
- package/build-module/components/link-control/search-results.js +3 -3
- package/build-module/components/link-control/search-results.js.map +1 -1
- package/build-module/components/link-control/settings-drawer.js +4 -5
- package/build-module/components/link-control/settings-drawer.js.map +1 -1
- package/build-module/components/list-view/appender.js +2 -6
- package/build-module/components/list-view/appender.js.map +1 -1
- package/build-module/components/provider/index.js +5 -2
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/use-block-sync.js +21 -0
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/components/resolution-tool/index.js +45 -0
- package/build-module/components/resolution-tool/index.js.map +1 -0
- package/build-module/components/url-input/index.js +4 -2
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/writing-flow/use-tab-nav.js +8 -26
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/components/writing-mode-control/index.js +57 -0
- package/build-module/components/writing-mode-control/index.js.map +1 -0
- package/build-module/hooks/behaviors.js +26 -20
- package/build-module/hooks/behaviors.js.map +1 -1
- package/build-module/hooks/supports.js +7 -1
- package/build-module/hooks/supports.js.map +1 -1
- package/build-module/hooks/typography.js +2 -1
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/utils.js +4 -2
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/private-apis.js +7 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/private-apis.native.js +2 -0
- package/build-module/private-apis.native.js.map +1 -1
- package/build-module/store/actions.js +191 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +1 -0
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/index.js +10 -1
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-actions.js +45 -36
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +2 -2
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +22 -8
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +33 -15
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/content-rtl.css +3 -0
- package/build-style/content.css +3 -0
- package/build-style/style-rtl.css +131 -129
- package/build-style/style.css +131 -129
- package/package.json +32 -31
- package/src/components/alignment-control/test/__snapshots__/index.js.snap +6 -6
- package/src/components/block-alignment-control/test/__snapshots__/index.js.snap +5 -5
- package/src/components/block-draggable/style.scss +1 -0
- package/src/components/block-heading-level-dropdown/heading-level-icon.js +6 -1
- package/src/components/block-heading-level-dropdown/index.native.js +8 -4
- package/src/components/block-inspector/style.scss +2 -1
- package/src/components/block-lock/toolbar.js +34 -6
- package/src/components/block-mobile-toolbar/block-actions-menu.native.js +4 -8
- package/src/components/block-parent-selector/index.js +13 -8
- package/src/components/block-removal-warning-modal/index.js +20 -33
- package/src/components/block-toolbar/index.js +9 -6
- package/src/components/block-tools/block-contextual-toolbar.js +5 -11
- package/src/components/block-tools/style.scss +73 -26
- package/src/components/default-block-appender/content.scss +11 -0
- package/src/components/dimensions-tool/aspect-ratio-tool.js +124 -0
- package/src/components/dimensions-tool/index.js +212 -0
- package/src/components/dimensions-tool/scale-tool.js +124 -0
- package/src/components/dimensions-tool/stories/aspect-ratio-tool.js +52 -0
- package/src/components/dimensions-tool/stories/index.js +54 -0
- package/src/components/dimensions-tool/stories/scale-tool.js +48 -0
- package/src/components/dimensions-tool/stories/width-height-tool.js +54 -0
- package/src/components/dimensions-tool/test/index.js +641 -0
- package/src/components/dimensions-tool/width-height-tool.js +113 -0
- package/src/components/font-family/README.md +71 -0
- package/src/components/global-styles/color-panel.js +1 -1
- package/src/components/global-styles/filters-panel.js +2 -2
- package/src/components/global-styles/hooks.js +2 -0
- package/src/components/global-styles/typography-panel.js +40 -0
- package/src/components/image-editor/aspect-ratio-dropdown.js +1 -1
- package/src/components/image-editor/use-save-image.js +0 -1
- package/src/components/image-size-control/index.js +6 -0
- package/src/components/index.js +6 -0
- package/src/components/inserter/block-patterns-explorer/patterns-list.js +8 -2
- package/src/components/inserter/block-patterns-tab.js +8 -56
- package/src/components/inserter/hooks/use-block-types-state.js +3 -4
- package/src/components/inserter/hooks/use-patterns-state.js +35 -19
- package/src/components/inserter/media-tab/hooks.js +2 -22
- package/src/components/inserter/reusable-block-rename-hint.js +52 -0
- package/src/components/inserter/reusable-blocks-tab.js +5 -1
- package/src/components/inserter/reusable-blocks-tab.native.js +2 -2
- package/src/components/inserter/style.scss +28 -0
- package/src/components/inserter/tabs.native.js +5 -1
- package/src/components/inserter-draggable-blocks/index.js +13 -2
- package/src/components/link-control/constants.js +1 -1
- package/src/components/link-control/index.js +32 -28
- package/src/components/link-control/search-create-button.js +8 -26
- package/src/components/link-control/search-input.js +4 -3
- package/src/components/link-control/search-item.js +21 -43
- package/src/components/link-control/search-results.js +48 -46
- package/src/components/link-control/settings-drawer.js +6 -5
- package/src/components/link-control/style.scss +51 -123
- package/src/components/link-control/test/index.js +135 -123
- package/src/components/list-view/appender.js +5 -6
- package/src/components/list-view/style.scss +1 -2
- package/src/components/media-replace-flow/test/index.js +1 -1
- package/src/components/panel-color-settings/README.md +98 -0
- package/src/components/provider/index.js +9 -2
- package/src/components/provider/test/use-block-sync.js +21 -6
- package/src/components/provider/use-block-sync.js +19 -0
- package/src/components/recursion-provider/README.md +101 -0
- package/src/components/resolution-tool/index.js +56 -0
- package/src/components/resolution-tool/stories/index.js +48 -0
- package/src/components/url-input/index.js +2 -0
- package/src/components/writing-flow/use-tab-nav.js +10 -33
- package/src/components/writing-mode-control/index.js +68 -0
- package/src/components/writing-mode-control/style.scss +18 -0
- package/src/hooks/behaviors.js +25 -16
- package/src/hooks/supports.js +7 -0
- package/src/hooks/typography.js +2 -0
- package/src/hooks/utils.js +3 -0
- package/src/private-apis.js +6 -0
- package/src/private-apis.native.js +2 -0
- package/src/store/actions.js +194 -1
- package/src/store/defaults.js +1 -0
- package/src/store/index.js +10 -0
- package/src/store/private-actions.js +39 -39
- package/src/store/private-selectors.js +2 -2
- package/src/store/reducer.js +22 -8
- package/src/store/selectors.js +54 -20
- package/src/store/test/actions.js +111 -0
- package/src/store/test/private-actions.js +56 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# PanelColorSettings
|
|
2
|
+
|
|
3
|
+
`PanelColorSettings` is a React component that renders a UI for managing various color settings.
|
|
4
|
+
It is essentially a wrapper around the `PanelColorGradientSettings` component, but specifically disables the gradient features.
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
|
|
8
|
+
```jsx
|
|
9
|
+
/**
|
|
10
|
+
* WordPress dependencies
|
|
11
|
+
*/
|
|
12
|
+
import { PanelColorSettings } from '@wordpress/block-editor';
|
|
13
|
+
import { useState } from '@wordpress/element';
|
|
14
|
+
import { __ } from '@wordpress/i18n';
|
|
15
|
+
|
|
16
|
+
// ...
|
|
17
|
+
|
|
18
|
+
const MyPanelColorSettings = () => {
|
|
19
|
+
const [ textColor, setTextColor ] = useState( { color: '#000' } );
|
|
20
|
+
const [ backgroundColor, setBackgroundColor ] = useState( {
|
|
21
|
+
color: '#fff',
|
|
22
|
+
} );
|
|
23
|
+
const [ overlayTextColor, setOverlayTextColor ] = useState( {
|
|
24
|
+
color: '#000',
|
|
25
|
+
} );
|
|
26
|
+
const [ overlayBackgroundColor, setOverlayBackgroundColor ] = useState( {
|
|
27
|
+
color: '#eee',
|
|
28
|
+
} );
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<PanelColorSettings
|
|
32
|
+
__experimentalIsRenderedInSidebar
|
|
33
|
+
title={ __( 'Color' ) }
|
|
34
|
+
colorSettings={ [
|
|
35
|
+
{
|
|
36
|
+
value: textColor.color,
|
|
37
|
+
onChange: setTextColor,
|
|
38
|
+
label: __( 'Text' ),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
value: backgroundColor.color,
|
|
42
|
+
onChange: setBackgroundColor,
|
|
43
|
+
label: __( 'Background' ),
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
value: overlayTextColor.color,
|
|
47
|
+
onChange: setOverlayTextColor,
|
|
48
|
+
label: __( 'Submenu & overlay text' ),
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
value: overlayBackgroundColor.color,
|
|
52
|
+
onChange: setOverlayBackgroundColor,
|
|
53
|
+
label: __( 'Submenu & overlay background' ),
|
|
54
|
+
},
|
|
55
|
+
] }
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/// ...
|
|
61
|
+
|
|
62
|
+
<MyPanelColorSettings />;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Props
|
|
66
|
+
|
|
67
|
+
The component accepts the following props:
|
|
68
|
+
|
|
69
|
+
### colorSettings
|
|
70
|
+
|
|
71
|
+
A user-provided set of color settings.
|
|
72
|
+
|
|
73
|
+
- Type: `Array`
|
|
74
|
+
- Required: No
|
|
75
|
+
|
|
76
|
+
Colors settings are provided as an array of objects with the following schema:
|
|
77
|
+
|
|
78
|
+
| Property | Description | Type |
|
|
79
|
+
| -------- | --------------------------------- | -------- |
|
|
80
|
+
| value | The current color of the setting | string |
|
|
81
|
+
| onChange | Callback on change of the setting | Function |
|
|
82
|
+
| label | Label of the setting | string |
|
|
83
|
+
|
|
84
|
+
Additionally, the following `PanelColorGradientSettings` props are supported and directly passed down to the underlying `PanelColorGradientSettings` instance:
|
|
85
|
+
|
|
86
|
+
- `className` - added to the underlying `ToolsPanel` instance.
|
|
87
|
+
- `colors` - array of colors to be used.
|
|
88
|
+
- `gradients` - not recommended to be used since `PanelColorSettings` resets it.
|
|
89
|
+
- `disableCustomColors` - whether addition of custom colors is enabled
|
|
90
|
+
- `disableCustomGradients` - not recommended to be used since `PanelColorSettings` sets it.
|
|
91
|
+
- `children` - displayed below the underlying `PanelColorGradientSettings` instance.
|
|
92
|
+
- `settings` - not recommended to be used, since `PanelColorSettings` builds it from the `colorSettings` prop.
|
|
93
|
+
- `title` - title of the underlying `ToolsPanel`.
|
|
94
|
+
- `showTitle` - whether to show the title of the `ToolsPanel`.
|
|
95
|
+
- `__experimentalIsRenderedInSidebar`
|
|
96
|
+
- `enableAlpha` - whether to enable setting opacity when specifying a color.
|
|
97
|
+
|
|
98
|
+
Please refer to the `PanelColorGradientSettings` component for more information.
|
|
@@ -28,9 +28,16 @@ export const ExperimentalBlockEditorProvider = withRegistryProvider(
|
|
|
28
28
|
...settings,
|
|
29
29
|
__internalIsInitialized: true,
|
|
30
30
|
},
|
|
31
|
-
|
|
31
|
+
{
|
|
32
|
+
stripExperimentalSettings,
|
|
33
|
+
reset: true,
|
|
34
|
+
}
|
|
32
35
|
);
|
|
33
|
-
}, [
|
|
36
|
+
}, [
|
|
37
|
+
settings,
|
|
38
|
+
stripExperimentalSettings,
|
|
39
|
+
__experimentalUpdateSettings,
|
|
40
|
+
] );
|
|
34
41
|
|
|
35
42
|
// Syncs the entity provider with changes in the block-editor store.
|
|
36
43
|
useBlockSync( props );
|
|
@@ -48,7 +48,7 @@ describe( 'useBlockSync hook', () => {
|
|
|
48
48
|
jest.clearAllMocks();
|
|
49
49
|
} );
|
|
50
50
|
|
|
51
|
-
it( 'resets the block-editor blocks when the
|
|
51
|
+
it( 'resets the block-editor blocks when the controlled value changes', async () => {
|
|
52
52
|
const fakeBlocks = [];
|
|
53
53
|
const resetBlocks = jest.spyOn( blockEditorActions, 'resetBlocks' );
|
|
54
54
|
const replaceInnerBlocks = jest.spyOn(
|
|
@@ -58,7 +58,7 @@ describe( 'useBlockSync hook', () => {
|
|
|
58
58
|
const onChange = jest.fn();
|
|
59
59
|
const onInput = jest.fn();
|
|
60
60
|
|
|
61
|
-
const { rerender } = render(
|
|
61
|
+
const { rerender, unmount } = render(
|
|
62
62
|
<TestWrapper
|
|
63
63
|
value={ fakeBlocks }
|
|
64
64
|
onChange={ onChange }
|
|
@@ -88,9 +88,16 @@ describe( 'useBlockSync hook', () => {
|
|
|
88
88
|
expect( onInput ).not.toHaveBeenCalled();
|
|
89
89
|
expect( replaceInnerBlocks ).not.toHaveBeenCalled();
|
|
90
90
|
expect( resetBlocks ).toHaveBeenCalledWith( testBlocks );
|
|
91
|
+
|
|
92
|
+
unmount();
|
|
93
|
+
|
|
94
|
+
expect( onChange ).not.toHaveBeenCalled();
|
|
95
|
+
expect( onInput ).not.toHaveBeenCalled();
|
|
96
|
+
expect( replaceInnerBlocks ).not.toHaveBeenCalled();
|
|
97
|
+
expect( resetBlocks ).toHaveBeenCalledWith( [] );
|
|
91
98
|
} );
|
|
92
99
|
|
|
93
|
-
it( 'replaces the inner blocks of a block when the
|
|
100
|
+
it( 'replaces the inner blocks of a block when the controlled value changes if a clientId is passed', async () => {
|
|
94
101
|
const fakeBlocks = [];
|
|
95
102
|
const replaceInnerBlocks = jest.spyOn(
|
|
96
103
|
blockEditorActions,
|
|
@@ -100,7 +107,7 @@ describe( 'useBlockSync hook', () => {
|
|
|
100
107
|
const onChange = jest.fn();
|
|
101
108
|
const onInput = jest.fn();
|
|
102
109
|
|
|
103
|
-
const { rerender } = render(
|
|
110
|
+
const { rerender, unmount } = render(
|
|
104
111
|
<TestWrapper
|
|
105
112
|
clientId="test"
|
|
106
113
|
value={ fakeBlocks }
|
|
@@ -138,8 +145,16 @@ describe( 'useBlockSync hook', () => {
|
|
|
138
145
|
expect( onChange ).not.toHaveBeenCalled();
|
|
139
146
|
expect( onInput ).not.toHaveBeenCalled();
|
|
140
147
|
expect( resetBlocks ).not.toHaveBeenCalled();
|
|
141
|
-
|
|
142
|
-
|
|
148
|
+
expect( replaceInnerBlocks ).toHaveBeenCalledWith( 'test', [
|
|
149
|
+
expect.objectContaining( { name: 'test/test-block' } ),
|
|
150
|
+
] );
|
|
151
|
+
|
|
152
|
+
unmount();
|
|
153
|
+
|
|
154
|
+
expect( onChange ).not.toHaveBeenCalled();
|
|
155
|
+
expect( onInput ).not.toHaveBeenCalled();
|
|
156
|
+
expect( resetBlocks ).not.toHaveBeenCalled();
|
|
157
|
+
expect( replaceInnerBlocks ).toHaveBeenCalledWith( 'test', [] );
|
|
143
158
|
} );
|
|
144
159
|
|
|
145
160
|
it( 'does not add the controlled blocks to the block-editor store if the store already contains them', async () => {
|
|
@@ -134,6 +134,19 @@ export default function useBlockSync( {
|
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
|
|
137
|
+
// Clean up the changes made by setControlledBlocks() when the component
|
|
138
|
+
// containing useBlockSync() unmounts.
|
|
139
|
+
const unsetControlledBlocks = () => {
|
|
140
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
141
|
+
if ( clientId ) {
|
|
142
|
+
setHasControlledInnerBlocks( clientId, false );
|
|
143
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
144
|
+
replaceInnerBlocks( clientId, [] );
|
|
145
|
+
} else {
|
|
146
|
+
resetBlocks( [] );
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
137
150
|
// Add a subscription to the block-editor registry to detect when changes
|
|
138
151
|
// have been made. This lets us inform the data source of changes. This
|
|
139
152
|
// is an effect so that the subscriber can run synchronously without
|
|
@@ -287,4 +300,10 @@ export default function useBlockSync( {
|
|
|
287
300
|
unsubscribe();
|
|
288
301
|
};
|
|
289
302
|
}, [ registry, clientId ] );
|
|
303
|
+
|
|
304
|
+
useEffect( () => {
|
|
305
|
+
return () => {
|
|
306
|
+
unsetControlledBlocks();
|
|
307
|
+
};
|
|
308
|
+
}, [] );
|
|
290
309
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# RecursionProvider
|
|
2
|
+
|
|
3
|
+
According to Gutenberg's block rendering architecture, any block type capable of recursion should be responsible for handling its own infinite loops.
|
|
4
|
+
|
|
5
|
+
To help with detecting infinite loops on the client, the `RecursionProvider` component and the `useHasRecursion()` hook are used to identify if a block has already been rendered.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```jsx
|
|
10
|
+
/**
|
|
11
|
+
* WordPress dependencies
|
|
12
|
+
*/
|
|
13
|
+
import {
|
|
14
|
+
__experimentalRecursionProvider as RecursionProvider,
|
|
15
|
+
__experimentalUseHasRecursion as useHasRecursion,
|
|
16
|
+
useBlockProps,
|
|
17
|
+
Warning,
|
|
18
|
+
} from '@wordpress/block-editor';
|
|
19
|
+
import { __ } from '@wordpress/i18n';
|
|
20
|
+
|
|
21
|
+
export default function MyRecursiveBlockEdit( { attributes: { ref } } ) {
|
|
22
|
+
const hasAlreadyRendered = useHasRecursion( ref );
|
|
23
|
+
const blockProps = useBlockProps( {
|
|
24
|
+
className: 'my-block__custom-class',
|
|
25
|
+
} );
|
|
26
|
+
|
|
27
|
+
if ( hasAlreadyRendered ) {
|
|
28
|
+
return (
|
|
29
|
+
<div { ...blockProps }>
|
|
30
|
+
<Warning>
|
|
31
|
+
{ __( 'Block cannot be rendered inside itself.' ) }
|
|
32
|
+
</Warning>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<RecursionProvider uniqueId={ ref }>
|
|
39
|
+
Block editing code here....
|
|
40
|
+
</RecursionProvider>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// ...
|
|
45
|
+
|
|
46
|
+
<MyRecursiveBlockEdit />;
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Props
|
|
50
|
+
|
|
51
|
+
The component accepts the following props:
|
|
52
|
+
|
|
53
|
+
### uniqueId
|
|
54
|
+
|
|
55
|
+
Any value that acts as a unique identifier for a block instance.
|
|
56
|
+
|
|
57
|
+
- Type: `any`
|
|
58
|
+
- Required: Yes
|
|
59
|
+
|
|
60
|
+
### children
|
|
61
|
+
|
|
62
|
+
Components to be rendered as content.
|
|
63
|
+
|
|
64
|
+
- Type: `Element`
|
|
65
|
+
- Required: Yes.
|
|
66
|
+
|
|
67
|
+
### blockName
|
|
68
|
+
|
|
69
|
+
Optional block name.
|
|
70
|
+
|
|
71
|
+
- Type: `String`
|
|
72
|
+
- Required: No
|
|
73
|
+
- Default: ''
|
|
74
|
+
|
|
75
|
+
# `useHasRecursion()`
|
|
76
|
+
|
|
77
|
+
Used in conjunction with `RecursionProvider`, this hook is used to identify if a block has already been rendered.
|
|
78
|
+
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
For example usage, refer to the example above.
|
|
82
|
+
|
|
83
|
+
## Props
|
|
84
|
+
|
|
85
|
+
The component accepts the following props:
|
|
86
|
+
|
|
87
|
+
### uniqueId
|
|
88
|
+
|
|
89
|
+
Any value that acts as a unique identifier for a block instance.
|
|
90
|
+
|
|
91
|
+
- Type: `any`
|
|
92
|
+
- Required: Yes
|
|
93
|
+
|
|
94
|
+
### blockName
|
|
95
|
+
|
|
96
|
+
Optional block name.
|
|
97
|
+
|
|
98
|
+
- Type: `String`
|
|
99
|
+
- Required: No
|
|
100
|
+
- Default: ''
|
|
101
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
SelectControl,
|
|
6
|
+
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
7
|
+
} from '@wordpress/components';
|
|
8
|
+
import { __, _x } from '@wordpress/i18n';
|
|
9
|
+
|
|
10
|
+
const DEFAULT_SIZE_OPTIONS = [
|
|
11
|
+
{
|
|
12
|
+
label: _x( 'Thumbnail', 'Image size option for resolution control' ),
|
|
13
|
+
value: 'thumbnail',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
label: _x( 'Medium', 'Image size option for resolution control' ),
|
|
17
|
+
value: 'medium',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
label: _x( 'Large', 'Image size option for resolution control' ),
|
|
21
|
+
value: 'large',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: _x( 'Full Size', 'Image size option for resolution control' ),
|
|
25
|
+
value: 'full',
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
export default function ResolutionTool( {
|
|
30
|
+
panelId,
|
|
31
|
+
value,
|
|
32
|
+
onChange,
|
|
33
|
+
options = DEFAULT_SIZE_OPTIONS,
|
|
34
|
+
defaultValue = DEFAULT_SIZE_OPTIONS[ 0 ].value,
|
|
35
|
+
isShownByDefault = true,
|
|
36
|
+
} ) {
|
|
37
|
+
const displayValue = value ?? defaultValue;
|
|
38
|
+
return (
|
|
39
|
+
<ToolsPanelItem
|
|
40
|
+
hasValue={ () => displayValue !== defaultValue }
|
|
41
|
+
label={ __( 'Resolution' ) }
|
|
42
|
+
onDeselect={ () => onChange( defaultValue ) }
|
|
43
|
+
isShownByDefault={ isShownByDefault }
|
|
44
|
+
panelId={ panelId }
|
|
45
|
+
>
|
|
46
|
+
<SelectControl
|
|
47
|
+
label={ __( 'Resolution' ) }
|
|
48
|
+
value={ displayValue }
|
|
49
|
+
options={ options }
|
|
50
|
+
onChange={ onChange }
|
|
51
|
+
help={ __( 'Select the size of the source image.' ) }
|
|
52
|
+
size={ '__unstable-large' }
|
|
53
|
+
/>
|
|
54
|
+
</ToolsPanelItem>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from '@wordpress/element';
|
|
5
|
+
import {
|
|
6
|
+
Panel,
|
|
7
|
+
__experimentalToolsPanel as ToolsPanel,
|
|
8
|
+
} from '@wordpress/components';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import ResolutionTool from '..';
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
title: 'BlockEditor (Private APIs)/ResolutionControl',
|
|
17
|
+
component: ResolutionTool,
|
|
18
|
+
argTypes: {
|
|
19
|
+
panelId: { control: { type: null } },
|
|
20
|
+
onChange: { action: 'changed' },
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const Default = ( { panelId, onChange: onChangeProp, ...props } ) => {
|
|
25
|
+
const [ resolution, setResolution ] = useState( undefined );
|
|
26
|
+
const resetAll = () => {
|
|
27
|
+
setResolution( undefined );
|
|
28
|
+
onChangeProp( undefined );
|
|
29
|
+
};
|
|
30
|
+
return (
|
|
31
|
+
<Panel>
|
|
32
|
+
<ToolsPanel panelId={ panelId } resetAll={ resetAll }>
|
|
33
|
+
<ResolutionTool
|
|
34
|
+
panelId={ panelId }
|
|
35
|
+
onChange={ ( newValue ) => {
|
|
36
|
+
setResolution( newValue );
|
|
37
|
+
onChangeProp( newValue );
|
|
38
|
+
} }
|
|
39
|
+
value={ resolution }
|
|
40
|
+
{ ...props }
|
|
41
|
+
/>
|
|
42
|
+
</ToolsPanel>
|
|
43
|
+
</Panel>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
Default.args = {
|
|
47
|
+
panelId: 'panel-id',
|
|
48
|
+
};
|
|
@@ -434,6 +434,7 @@ class URLInput extends Component {
|
|
|
434
434
|
placeholder = __( 'Paste URL or type to search' ),
|
|
435
435
|
__experimentalRenderControl: renderControl,
|
|
436
436
|
value = '',
|
|
437
|
+
hideLabelFromVision = false,
|
|
437
438
|
} = this.props;
|
|
438
439
|
|
|
439
440
|
const {
|
|
@@ -452,6 +453,7 @@ class URLInput extends Component {
|
|
|
452
453
|
className: classnames( 'block-editor-url-input', className, {
|
|
453
454
|
'is-full-width': isFullWidth,
|
|
454
455
|
} ),
|
|
456
|
+
hideLabelFromVision,
|
|
455
457
|
};
|
|
456
458
|
|
|
457
459
|
const inputProps = {
|
|
@@ -11,6 +11,7 @@ import { useRef } from '@wordpress/element';
|
|
|
11
11
|
* Internal dependencies
|
|
12
12
|
*/
|
|
13
13
|
import { store as blockEditorStore } from '../../store';
|
|
14
|
+
import { isInSameBlock, isInsideRootBlock } from '../../utils/dom';
|
|
14
15
|
|
|
15
16
|
export default function useTabNav() {
|
|
16
17
|
const container = useRef();
|
|
@@ -116,41 +117,20 @@ export default function useTabNav() {
|
|
|
116
117
|
return;
|
|
117
118
|
}
|
|
118
119
|
|
|
120
|
+
const nextTabbable = focus.tabbable[ direction ]( event.target );
|
|
121
|
+
|
|
119
122
|
// We want to constrain the tabbing to the block and its child blocks.
|
|
120
123
|
// If the preceding form element is within a different block,
|
|
121
124
|
// such as two sibling image blocks in the placeholder state,
|
|
122
125
|
// we want shift + tab from the first form element to move to the image
|
|
123
126
|
// block toolbar and not the previous image block's form element.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
* @return {boolean} Whether the element is part of or is the selected block.
|
|
131
|
-
*/
|
|
132
|
-
const isElementPartOfSelectedBlock = (
|
|
133
|
-
selectedBlockElement,
|
|
134
|
-
element
|
|
135
|
-
) => {
|
|
136
|
-
// Check if the element is or is within the selected block by finding the
|
|
137
|
-
// closest element with a data-block attribute and seeing if
|
|
138
|
-
// it matches our current selected block ID
|
|
139
|
-
const elementBlockId = element
|
|
140
|
-
.closest( '[data-block]' )
|
|
141
|
-
?.getAttribute( 'data-block' );
|
|
142
|
-
const isElementSameBlock =
|
|
143
|
-
elementBlockId === getSelectedBlockClientId();
|
|
144
|
-
|
|
145
|
-
// Check if the element is a child of the selected block. This could be a
|
|
146
|
-
// child block in a group or column block, etc.
|
|
147
|
-
const isElementChildOfBlock =
|
|
148
|
-
selectedBlockElement.contains( element );
|
|
149
|
-
|
|
150
|
-
return isElementSameBlock || isElementChildOfBlock;
|
|
151
|
-
};
|
|
127
|
+
const currentBlock = event.target.closest( '[data-block]' );
|
|
128
|
+
const isElementPartOfSelectedBlock =
|
|
129
|
+
currentBlock &&
|
|
130
|
+
nextTabbable &&
|
|
131
|
+
( isInSameBlock( currentBlock, nextTabbable ) ||
|
|
132
|
+
isInsideRootBlock( currentBlock, nextTabbable ) );
|
|
152
133
|
|
|
153
|
-
const nextTabbable = focus.tabbable[ direction ]( event.target );
|
|
154
134
|
// Allow tabbing from the block wrapper to a form element,
|
|
155
135
|
// and between form elements rendered in a block and its child blocks,
|
|
156
136
|
// such as inside a placeholder. Form elements are generally
|
|
@@ -159,10 +139,7 @@ export default function useTabNav() {
|
|
|
159
139
|
// future they can be rendered in an iframe or shadow DOM.
|
|
160
140
|
if (
|
|
161
141
|
isFormElement( nextTabbable ) &&
|
|
162
|
-
isElementPartOfSelectedBlock
|
|
163
|
-
event.target.closest( '[data-block]' ),
|
|
164
|
-
nextTabbable
|
|
165
|
-
)
|
|
142
|
+
isElementPartOfSelectedBlock
|
|
166
143
|
) {
|
|
167
144
|
return;
|
|
168
145
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { BaseControl, Button } from '@wordpress/components';
|
|
10
|
+
import { __, isRTL } from '@wordpress/i18n';
|
|
11
|
+
import { textHorizontal, textVertical } from '@wordpress/icons';
|
|
12
|
+
|
|
13
|
+
const WRITING_MODES = [
|
|
14
|
+
{
|
|
15
|
+
name: __( 'Horizontal' ),
|
|
16
|
+
value: 'horizontal-tb',
|
|
17
|
+
icon: textHorizontal,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: __( 'Vertical' ),
|
|
21
|
+
value: isRTL() ? 'vertical-lr' : 'vertical-rl',
|
|
22
|
+
icon: textVertical,
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Control to facilitate writing mode selections.
|
|
28
|
+
*
|
|
29
|
+
* @param {Object} props Component props.
|
|
30
|
+
* @param {string} props.className Class name to add to the control.
|
|
31
|
+
* @param {string} props.value Currently selected writing mode.
|
|
32
|
+
* @param {Function} props.onChange Handles change in the writing mode selection.
|
|
33
|
+
*
|
|
34
|
+
* @return {WPElement} Writing Mode control.
|
|
35
|
+
*/
|
|
36
|
+
export default function WritingModeControl( { className, value, onChange } ) {
|
|
37
|
+
return (
|
|
38
|
+
<fieldset
|
|
39
|
+
className={ classnames(
|
|
40
|
+
'block-editor-writing-mode-control',
|
|
41
|
+
className
|
|
42
|
+
) }
|
|
43
|
+
>
|
|
44
|
+
<BaseControl.VisualLabel as="legend">
|
|
45
|
+
{ __( 'Orientation' ) }
|
|
46
|
+
</BaseControl.VisualLabel>
|
|
47
|
+
<div className="block-editor-writing-mode-control__buttons">
|
|
48
|
+
{ WRITING_MODES.map( ( writingMode ) => {
|
|
49
|
+
return (
|
|
50
|
+
<Button
|
|
51
|
+
key={ writingMode.value }
|
|
52
|
+
icon={ writingMode.icon }
|
|
53
|
+
label={ writingMode.name }
|
|
54
|
+
isPressed={ writingMode.value === value }
|
|
55
|
+
onClick={ () => {
|
|
56
|
+
onChange(
|
|
57
|
+
writingMode.value === value
|
|
58
|
+
? undefined
|
|
59
|
+
: writingMode.value
|
|
60
|
+
);
|
|
61
|
+
} }
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
} ) }
|
|
65
|
+
</div>
|
|
66
|
+
</fieldset>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.block-editor-writing-mode-control {
|
|
2
|
+
border: 0;
|
|
3
|
+
margin: 0;
|
|
4
|
+
padding: 0;
|
|
5
|
+
|
|
6
|
+
.block-editor-writing-mode-control__buttons {
|
|
7
|
+
// 4px of padding makes the row 40px high, same as an input.
|
|
8
|
+
padding: $grid-unit-05 0;
|
|
9
|
+
display: flex;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.components-button.has-icon {
|
|
13
|
+
height: $grid-unit-40;
|
|
14
|
+
margin-right: $grid-unit-05;
|
|
15
|
+
min-width: $grid-unit-40;
|
|
16
|
+
padding: 0;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/hooks/behaviors.js
CHANGED
|
@@ -7,6 +7,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
7
7
|
import { hasBlockSupport } from '@wordpress/blocks';
|
|
8
8
|
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
9
9
|
import { useSelect } from '@wordpress/data';
|
|
10
|
+
import { useMemo } from '@wordpress/element';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Internal dependencies
|
|
@@ -65,35 +66,40 @@ function BehaviorsControl( {
|
|
|
65
66
|
...behaviorsOptions,
|
|
66
67
|
];
|
|
67
68
|
|
|
69
|
+
const { behaviors, behaviorsValue } = useMemo( () => {
|
|
70
|
+
const mergedBehaviors = {
|
|
71
|
+
...themeBehaviors,
|
|
72
|
+
...( blockBehaviors || {} ),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
let value = '';
|
|
76
|
+
if ( blockBehaviors === undefined ) {
|
|
77
|
+
value = 'default';
|
|
78
|
+
}
|
|
79
|
+
if ( blockBehaviors?.lightbox.enabled ) {
|
|
80
|
+
value = 'lightbox';
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
behaviors: mergedBehaviors,
|
|
84
|
+
behaviorsValue: value,
|
|
85
|
+
};
|
|
86
|
+
}, [ blockBehaviors, themeBehaviors ] );
|
|
68
87
|
// If every behavior is disabled, do not show the behaviors inspector control.
|
|
69
88
|
if ( behaviorsOptions.length === 0 ) {
|
|
70
89
|
return null;
|
|
71
90
|
}
|
|
72
|
-
// Block behaviors take precedence over theme behaviors.
|
|
73
|
-
const behaviors = { ...themeBehaviors, ...( blockBehaviors || {} ) };
|
|
74
91
|
|
|
75
92
|
const helpText = disabled
|
|
76
93
|
? __( 'The lightbox behavior is disabled for linked images.' )
|
|
77
94
|
: '';
|
|
78
95
|
|
|
79
|
-
const value = () => {
|
|
80
|
-
if ( blockBehaviors === undefined ) {
|
|
81
|
-
return 'default';
|
|
82
|
-
}
|
|
83
|
-
if ( behaviors?.lightbox.enabled ) {
|
|
84
|
-
return 'lightbox';
|
|
85
|
-
}
|
|
86
|
-
return '';
|
|
87
|
-
};
|
|
88
|
-
|
|
89
96
|
return (
|
|
90
97
|
<InspectorControls group="advanced">
|
|
91
|
-
{ /* This div is needed to prevent a margin bottom between the dropdown and the button. */ }
|
|
92
98
|
<div>
|
|
93
99
|
<SelectControl
|
|
94
100
|
label={ __( 'Behaviors' ) }
|
|
95
101
|
// At the moment we are only supporting one behavior (Lightbox)
|
|
96
|
-
value={
|
|
102
|
+
value={ behaviorsValue }
|
|
97
103
|
options={ options }
|
|
98
104
|
onChange={ onChangeBehavior }
|
|
99
105
|
hideCancelButton={ true }
|
|
@@ -101,7 +107,7 @@ function BehaviorsControl( {
|
|
|
101
107
|
size="__unstable-large"
|
|
102
108
|
disabled={ disabled }
|
|
103
109
|
/>
|
|
104
|
-
{
|
|
110
|
+
{ behaviorsValue === 'lightbox' && (
|
|
105
111
|
<SelectControl
|
|
106
112
|
label={ __( 'Animation' ) }
|
|
107
113
|
// At the moment we are only supporting one behavior (Lightbox)
|
|
@@ -115,7 +121,10 @@ function BehaviorsControl( {
|
|
|
115
121
|
value: 'zoom',
|
|
116
122
|
label: __( 'Zoom' ),
|
|
117
123
|
},
|
|
118
|
-
{
|
|
124
|
+
{
|
|
125
|
+
value: 'fade',
|
|
126
|
+
label: __( 'Fade' ),
|
|
127
|
+
},
|
|
119
128
|
] }
|
|
120
129
|
onChange={ onChangeAnimation }
|
|
121
130
|
hideCancelButton={ false }
|