@wordpress/block-editor 10.1.1-next.4d3b314fd5.0 → 10.3.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 +14 -0
- package/README.md +41 -0
- package/build/components/block-controls/slot.js +2 -2
- package/build/components/block-controls/slot.js.map +1 -1
- package/build/components/block-draggable/draggable-chip.js +4 -2
- package/build/components/block-draggable/draggable-chip.js.map +1 -1
- package/build/components/block-inspector/index.js +4 -5
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block-list-compact.native.js +1 -0
- package/build/components/block-list/block-list-compact.native.js.map +1 -1
- package/build/components/block-list/block.js +72 -14
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +79 -12
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +7 -23
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-lock/modal.js +9 -6
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-parent-selector/index.js +5 -5
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-patterns-list/index.js +5 -4
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-popover/drop-zone.js +85 -0
- package/build/components/block-popover/drop-zone.js.map +1 -0
- package/build/components/block-popover/inbetween.js +3 -1
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +22 -17
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/block-preview/auto.js +2 -2
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-preview/index.js +6 -9
- package/build/components/block-preview/index.js.map +1 -1
- package/build/components/block-preview/live.js +3 -7
- package/build/components/block-preview/live.js.map +1 -1
- package/build/components/block-selection-clearer/index.js +9 -1
- package/build/components/block-selection-clearer/index.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +22 -16
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-styles/index.js +18 -42
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-toolbar/index.js +4 -4
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-tools/back-compat.js +2 -1
- package/build/components/block-tools/back-compat.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +50 -20
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +15 -3
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/colors-gradients/control.js +1 -1
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +2 -2
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +256 -0
- package/build/components/font-sizes/fluid-utils.js.map +1 -0
- package/build/components/font-sizes/index.js +8 -0
- package/build/components/font-sizes/index.js.map +1 -1
- package/build/components/image-editor/use-transform-image.js +2 -2
- package/build/components/image-editor/use-transform-image.js.map +1 -1
- package/build/components/index.js +0 -9
- package/build/components/index.js.map +1 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/build/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +151 -78
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/block-types-tab.js +1 -1
- package/build/components/inserter/block-types-tab.js.map +1 -1
- package/build/components/inserter/menu.js +14 -3
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter/search-items.js +2 -17
- package/build/components/inserter/search-items.js.map +1 -1
- package/build/components/inserter-draggable-blocks/index.js +4 -2
- package/build/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build/components/inspector-controls/slot.js +2 -1
- package/build/components/inspector-controls/slot.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +1 -14
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/preview-options/index.js +2 -3
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/rich-text/index.js +17 -0
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/spacing-sizes-control/index.js +10 -2
- package/build/components/spacing-sizes-control/index.js.map +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js +40 -9
- package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +98 -57
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-on-block-drop/index.js +12 -12
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/use-on-block-drop/types.js +6 -0
- package/build/components/use-on-block-drop/types.js.map +1 -0
- package/build/hooks/align.js +1 -3
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/align.native.js +1 -7
- package/build/hooks/align.native.js.map +1 -1
- package/build/hooks/font-size.js +60 -0
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/margin.js +6 -5
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +2 -1
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/style.js +126 -4
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/use-typography-props.js +17 -3
- package/build/hooks/use-typography-props.js.map +1 -1
- package/build/hooks/utils.js +1 -1
- package/build/hooks/utils.js.map +1 -1
- package/build/store/actions.js +59 -45
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +3 -0
- package/build/store/defaults.js.map +1 -1
- package/build/store/reducer.js +36 -18
- package/build/store/reducer.js.map +1 -1
- package/build/utils/math.js +14 -0
- package/build/utils/math.js.map +1 -1
- package/build/utils/pre-parse-patterns.js +19 -2
- package/build/utils/pre-parse-patterns.js.map +1 -1
- package/build-module/components/block-controls/slot.js +3 -3
- package/build-module/components/block-controls/slot.js.map +1 -1
- package/build-module/components/block-draggable/draggable-chip.js +7 -3
- package/build-module/components/block-draggable/draggable-chip.js.map +1 -1
- package/build-module/components/block-inspector/index.js +5 -6
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block-list-compact.native.js +1 -0
- package/build-module/components/block-list/block-list-compact.native.js.map +1 -1
- package/build-module/components/block-list/block.js +72 -14
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +80 -13
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +8 -24
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-lock/modal.js +10 -8
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +5 -5
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +5 -4
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-popover/drop-zone.js +70 -0
- package/build-module/components/block-popover/drop-zone.js.map +1 -0
- package/build-module/components/block-popover/inbetween.js +3 -1
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +22 -17
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +1 -1
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-preview/index.js +6 -9
- package/build-module/components/block-preview/index.js.map +1 -1
- package/build-module/components/block-preview/live.js +3 -6
- package/build-module/components/block-preview/live.js.map +1 -1
- package/build-module/components/block-selection-clearer/index.js +9 -1
- package/build-module/components/block-selection-clearer/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +25 -19
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-styles/index.js +19 -44
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +4 -4
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-tools/back-compat.js +2 -1
- package/build-module/components/block-tools/back-compat.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +48 -20
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +15 -3
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +2 -2
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +3 -3
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +245 -0
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -0
- package/build-module/components/font-sizes/index.js +1 -0
- package/build-module/components/font-sizes/index.js.map +1 -1
- package/build-module/components/image-editor/use-transform-image.js +2 -2
- package/build-module/components/image-editor/use-transform-image.js.map +1 -1
- package/build-module/components/index.js +0 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/build-module/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +148 -81
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/block-types-tab.js +3 -3
- package/build-module/components/inserter/block-types-tab.js.map +1 -1
- package/build-module/components/inserter/menu.js +10 -3
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/search-items.js +3 -17
- package/build-module/components/inserter/search-items.js.map +1 -1
- package/build-module/components/inserter-draggable-blocks/index.js +4 -2
- package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build-module/components/inspector-controls/slot.js +3 -2
- package/build-module/components/inspector-controls/slot.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +1 -14
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/preview-options/index.js +2 -3
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +17 -0
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/index.js +10 -3
- package/build-module/components/spacing-sizes-control/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js +40 -10
- package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +98 -58
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js +12 -12
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/types.js +2 -0
- package/build-module/components/use-on-block-drop/types.js.map +1 -0
- package/build-module/hooks/align.js +1 -2
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/align.native.js +1 -6
- package/build-module/hooks/align.native.js.map +1 -1
- package/build-module/hooks/font-size.js +59 -1
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/margin.js +6 -5
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +2 -1
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/style.js +124 -3
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/use-typography-props.js +17 -4
- package/build-module/hooks/use-typography-props.js.map +1 -1
- package/build-module/hooks/utils.js +2 -2
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/store/actions.js +55 -42
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +3 -0
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/reducer.js +36 -19
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/utils/math.js +12 -0
- package/build-module/utils/math.js.map +1 -1
- package/build-module/utils/pre-parse-patterns.js +19 -2
- package/build-module/utils/pre-parse-patterns.js.map +1 -1
- package/build-style/style-rtl.css +256 -152
- package/build-style/style.css +256 -152
- package/package.json +28 -29
- package/src/components/block-breadcrumb/test/index.js +1 -1
- package/src/components/block-controls/slot.js +3 -3
- package/src/components/block-draggable/draggable-chip.js +4 -2
- package/src/components/block-inspector/index.js +8 -11
- package/src/components/block-list/block-list-compact.native.js +1 -0
- package/src/components/block-list/block.js +111 -7
- package/src/components/block-list/block.native.js +123 -9
- package/src/components/block-list/style.scss +93 -126
- package/src/components/block-list/use-in-between-inserter.js +8 -19
- package/src/components/block-lock/modal.js +12 -7
- package/src/components/block-mover/style.scss +0 -1
- package/src/components/block-parent-selector/index.js +5 -5
- package/src/components/block-patterns-list/index.js +9 -5
- package/src/components/block-patterns-list/style.scss +7 -3
- package/src/components/block-popover/README.md +8 -0
- package/src/components/block-popover/drop-zone.js +63 -0
- package/src/components/block-popover/inbetween.js +1 -1
- package/src/components/block-popover/index.js +39 -22
- package/src/components/block-popover/style.scss +17 -1
- package/src/components/block-preview/auto.js +1 -1
- package/src/components/block-preview/index.js +7 -8
- package/src/components/block-preview/live.js +2 -7
- package/src/components/block-preview/test/index.js +1 -7
- package/src/components/block-selection-clearer/index.js +7 -2
- package/src/components/block-selection-clearer/test/index.js +118 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +32 -18
- package/src/components/block-settings-menu/test/block-mode-toggle.js +17 -17
- package/src/components/block-styles/index.js +26 -49
- package/src/components/block-switcher/test/__snapshots__/index.js.snap +104 -33
- package/src/components/block-switcher/test/index.js +121 -61
- package/src/components/block-toolbar/index.js +4 -6
- package/src/components/block-toolbar/style.scss +38 -14
- package/src/components/block-tools/back-compat.js +1 -0
- package/src/components/block-tools/insertion-point.js +42 -17
- package/src/components/block-tools/selected-block-popover.js +14 -1
- package/src/components/button-block-appender/style.scss +5 -1
- package/src/components/color-palette/test/__snapshots__/control.js.snap +32 -52
- package/src/components/color-palette/test/control.js +11 -15
- package/src/components/colors-gradients/control.js +2 -2
- package/src/components/colors-gradients/panel-color-gradient-settings.js +3 -4
- package/src/components/colors-gradients/test/control.js +49 -77
- package/src/components/font-sizes/fluid-utils.js +296 -0
- package/src/components/font-sizes/index.js +1 -0
- package/src/components/font-sizes/test/fluid-utils.js +168 -0
- package/src/components/image-editor/use-transform-image.js +2 -2
- package/src/components/image-size-control/test/index.js +47 -60
- package/src/components/index.js +0 -1
- package/src/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/src/components/inserter/block-patterns-tab.js +232 -98
- package/src/components/inserter/block-types-tab.js +3 -3
- package/src/components/inserter/menu.js +15 -2
- package/src/components/inserter/search-items.js +3 -15
- package/src/components/inserter/style.scss +94 -9
- package/src/components/inserter/test/reusable-blocks-tab.js +6 -6
- package/src/components/inserter/test/search-items.js +4 -0
- package/src/components/inserter-draggable-blocks/index.js +12 -2
- package/src/components/inserter-list-item/style.scss +20 -1
- package/src/components/inspector-controls/slot.js +6 -2
- package/src/components/link-control/test/index.js +1 -1
- package/src/components/list-view/use-list-view-drop-zone.js +4 -18
- package/src/components/panel-color-settings/test/index.js +4 -4
- package/src/components/preview-options/index.js +2 -2
- package/src/components/preview-options/style.scss +1 -1
- package/src/components/provider/test/use-block-sync.js +131 -165
- package/src/components/responsive-block-control/test/index.js +77 -122
- package/src/components/rich-text/index.js +22 -0
- package/src/components/spacing-sizes-control/index.js +15 -3
- package/src/components/spacing-sizes-control/spacing-input-control.js +24 -9
- package/src/components/spacing-sizes-control/style.scss +42 -31
- package/src/components/use-block-drop-zone/index.js +136 -79
- package/src/components/use-block-drop-zone/test/index.js +333 -81
- package/src/components/use-on-block-drop/index.js +11 -12
- package/src/components/use-on-block-drop/types.ts +1 -0
- package/src/hooks/align.js +3 -2
- package/src/hooks/align.native.js +5 -8
- package/src/hooks/font-size.js +75 -0
- package/src/hooks/margin.js +5 -4
- package/src/hooks/padding.js +1 -0
- package/src/hooks/style.js +122 -3
- package/src/hooks/test/style.js +206 -1
- package/src/hooks/test/use-typography-props.js +22 -0
- package/src/hooks/use-typography-props.js +18 -3
- package/src/hooks/utils.js +6 -2
- package/src/store/actions.js +20 -12
- package/src/store/defaults.js +3 -0
- package/src/store/reducer.js +35 -28
- package/src/store/test/actions.js +0 -9
- package/src/utils/math.js +17 -0
- package/src/utils/pre-parse-patterns.js +12 -7
- package/build/components/inserter/pattern-panel.js +0 -87
- package/build/components/inserter/pattern-panel.js.map +0 -1
- package/build-module/components/inserter/pattern-panel.js +0 -74
- package/build-module/components/inserter/pattern-panel.js.map +0 -1
- package/src/components/inserter/pattern-panel.js +0 -93
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { render, screen, fireEvent
|
|
4
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
@@ -85,7 +85,7 @@ describe( 'ImageSizeControl', () => {
|
|
|
85
85
|
} );
|
|
86
86
|
|
|
87
87
|
describe( 'updating dimension inputs', () => {
|
|
88
|
-
it( 'updates height and calls onChange',
|
|
88
|
+
it( 'updates height and calls onChange', () => {
|
|
89
89
|
render( <ImageSizeControl onChange={ mockOnChange } /> );
|
|
90
90
|
|
|
91
91
|
const heightInput = getHeightInput();
|
|
@@ -96,16 +96,14 @@ describe( 'ImageSizeControl', () => {
|
|
|
96
96
|
|
|
97
97
|
fireEvent.change( heightInput, { target: { value: '500' } } );
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
expect( mockOnChange ).toHaveBeenCalledWith( { height: 500 } );
|
|
102
|
-
} );
|
|
99
|
+
expect( mockOnChange ).toHaveBeenCalledTimes( 1 );
|
|
100
|
+
expect( mockOnChange ).toHaveBeenCalledWith( { height: 500 } );
|
|
103
101
|
|
|
104
102
|
expect( heightInput.value ).toBe( '500' );
|
|
105
103
|
expect( widthInput.value ).toBe( '' );
|
|
106
104
|
} );
|
|
107
105
|
|
|
108
|
-
it( 'updates width and calls onChange',
|
|
106
|
+
it( 'updates width and calls onChange', () => {
|
|
109
107
|
render( <ImageSizeControl onChange={ mockOnChange } /> );
|
|
110
108
|
|
|
111
109
|
const heightInput = getHeightInput();
|
|
@@ -115,16 +113,15 @@ describe( 'ImageSizeControl', () => {
|
|
|
115
113
|
expect( widthInput.value ).toBe( '' );
|
|
116
114
|
|
|
117
115
|
fireEvent.change( widthInput, { target: { value: '500' } } );
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
} );
|
|
116
|
+
|
|
117
|
+
expect( mockOnChange ).toHaveBeenCalledTimes( 1 );
|
|
118
|
+
expect( mockOnChange ).toHaveBeenCalledWith( { width: 500 } );
|
|
122
119
|
|
|
123
120
|
expect( heightInput.value ).toBe( '' );
|
|
124
121
|
expect( widthInput.value ).toBe( '500' );
|
|
125
122
|
} );
|
|
126
123
|
|
|
127
|
-
it( 'updates height and calls onChange for empty value',
|
|
124
|
+
it( 'updates height and calls onChange for empty value', () => {
|
|
128
125
|
render(
|
|
129
126
|
<ImageSizeControl
|
|
130
127
|
imageHeight="100"
|
|
@@ -141,20 +138,19 @@ describe( 'ImageSizeControl', () => {
|
|
|
141
138
|
|
|
142
139
|
fireEvent.change( heightInput, { target: { value: '' } } );
|
|
143
140
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
height: undefined,
|
|
150
|
-
} );
|
|
141
|
+
// onChange is called and sets the dimension to undefined rather than
|
|
142
|
+
// the empty string.
|
|
143
|
+
expect( mockOnChange ).toHaveBeenCalledTimes( 1 );
|
|
144
|
+
expect( mockOnChange ).toHaveBeenCalledWith( {
|
|
145
|
+
height: undefined,
|
|
151
146
|
} );
|
|
147
|
+
|
|
152
148
|
// Height is updated to empty value and does not reset to default.
|
|
153
149
|
expect( heightInput.value ).toBe( '' );
|
|
154
150
|
expect( widthInput.value ).toBe( '100' );
|
|
155
151
|
} );
|
|
156
152
|
|
|
157
|
-
it( 'updates width and calls onChange for empty value',
|
|
153
|
+
it( 'updates width and calls onChange for empty value', () => {
|
|
158
154
|
render(
|
|
159
155
|
<ImageSizeControl
|
|
160
156
|
imageHeight="100"
|
|
@@ -171,14 +167,13 @@ describe( 'ImageSizeControl', () => {
|
|
|
171
167
|
|
|
172
168
|
fireEvent.change( widthInput, { target: { value: '' } } );
|
|
173
169
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
width: undefined,
|
|
180
|
-
} );
|
|
170
|
+
// onChange is called and sets the dimension to undefined rather than
|
|
171
|
+
// the empty string.
|
|
172
|
+
expect( mockOnChange ).toHaveBeenCalledTimes( 1 );
|
|
173
|
+
expect( mockOnChange ).toHaveBeenCalledWith( {
|
|
174
|
+
width: undefined,
|
|
181
175
|
} );
|
|
176
|
+
|
|
182
177
|
// Width is updated to empty value and does not reset to default.
|
|
183
178
|
expect( heightInput.value ).toBe( '100' );
|
|
184
179
|
expect( widthInput.value ).toBe( '' );
|
|
@@ -186,7 +181,7 @@ describe( 'ImageSizeControl', () => {
|
|
|
186
181
|
} );
|
|
187
182
|
|
|
188
183
|
describe( 'reset button', () => {
|
|
189
|
-
it( 'resets both height and width to default values',
|
|
184
|
+
it( 'resets both height and width to default values', () => {
|
|
190
185
|
render(
|
|
191
186
|
<ImageSizeControl
|
|
192
187
|
imageHeight="100"
|
|
@@ -206,22 +201,20 @@ describe( 'ImageSizeControl', () => {
|
|
|
206
201
|
|
|
207
202
|
fireEvent.click( screen.getByText( 'Reset' ) );
|
|
208
203
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
width: undefined,
|
|
214
|
-
} );
|
|
215
|
-
|
|
216
|
-
// The inputs display the default values once more.
|
|
217
|
-
expect( heightInput.value ).toBe( '100' );
|
|
218
|
-
expect( widthInput.value ).toBe( '200' );
|
|
204
|
+
// Both attributes are set to undefined to clear custom values.
|
|
205
|
+
expect( mockOnChange ).toHaveBeenCalledWith( {
|
|
206
|
+
height: undefined,
|
|
207
|
+
width: undefined,
|
|
219
208
|
} );
|
|
209
|
+
|
|
210
|
+
// The inputs display the default values once more.
|
|
211
|
+
expect( heightInput.value ).toBe( '100' );
|
|
212
|
+
expect( widthInput.value ).toBe( '200' );
|
|
220
213
|
} );
|
|
221
214
|
} );
|
|
222
215
|
|
|
223
216
|
describe( 'image size percentage presets', () => {
|
|
224
|
-
it( 'updates height and width attributes on selection',
|
|
217
|
+
it( 'updates height and width attributes on selection', () => {
|
|
225
218
|
render(
|
|
226
219
|
<ImageSizeControl
|
|
227
220
|
imageHeight="100"
|
|
@@ -232,18 +225,16 @@ describe( 'ImageSizeControl', () => {
|
|
|
232
225
|
|
|
233
226
|
fireEvent.click( screen.getByText( '50%' ) );
|
|
234
227
|
|
|
235
|
-
|
|
236
|
-
expect( screen.getByText( '50%' ) ).toHaveClass( 'is-pressed' );
|
|
228
|
+
expect( screen.getByText( '50%' ) ).toHaveClass( 'is-pressed' );
|
|
237
229
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
} );
|
|
230
|
+
// Both attributes are set to the rounded scaled value.
|
|
231
|
+
expect( mockOnChange ).toHaveBeenCalledWith( {
|
|
232
|
+
height: 50,
|
|
233
|
+
width: 101,
|
|
243
234
|
} );
|
|
244
235
|
} );
|
|
245
236
|
|
|
246
|
-
it( 'updates height and width inputs on selection',
|
|
237
|
+
it( 'updates height and width inputs on selection', () => {
|
|
247
238
|
render(
|
|
248
239
|
<ImageSizeControl
|
|
249
240
|
imageHeight="100"
|
|
@@ -254,11 +245,9 @@ describe( 'ImageSizeControl', () => {
|
|
|
254
245
|
|
|
255
246
|
fireEvent.click( screen.getByText( '50%' ) );
|
|
256
247
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
expect( getWidthInput().value ).toBe( '101' );
|
|
261
|
-
} );
|
|
248
|
+
// Both attributes are set to the rounded scaled value.
|
|
249
|
+
expect( getHeightInput().value ).toBe( '50' );
|
|
250
|
+
expect( getWidthInput().value ).toBe( '101' );
|
|
262
251
|
} );
|
|
263
252
|
} );
|
|
264
253
|
|
|
@@ -284,7 +273,7 @@ describe( 'ImageSizeControl', () => {
|
|
|
284
273
|
);
|
|
285
274
|
} );
|
|
286
275
|
|
|
287
|
-
it( 'calls onChangeImage with selected slug on selection',
|
|
276
|
+
it( 'calls onChangeImage with selected slug on selection', () => {
|
|
288
277
|
render(
|
|
289
278
|
<ImageSizeControl
|
|
290
279
|
imageSizeOptions={ IMAGE_SIZE_OPTIONS }
|
|
@@ -298,13 +287,11 @@ describe( 'ImageSizeControl', () => {
|
|
|
298
287
|
target: { value: 'thumbnail' },
|
|
299
288
|
} );
|
|
300
289
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
);
|
|
307
|
-
} );
|
|
290
|
+
// onChangeImage is called with the slug and the event.
|
|
291
|
+
expect( mockOnChangeImage ).toHaveBeenCalledWith(
|
|
292
|
+
'thumbnail',
|
|
293
|
+
expect.any( Object )
|
|
294
|
+
);
|
|
308
295
|
} );
|
|
309
296
|
} );
|
|
310
297
|
} );
|
package/src/components/index.js
CHANGED
|
@@ -155,7 +155,6 @@ export {
|
|
|
155
155
|
export { default as __experimentalBlockPatternsList } from './block-patterns-list';
|
|
156
156
|
export { default as __experimentalPublishDateTimePicker } from './publish-date-time-picker';
|
|
157
157
|
export { default as __experimentalInspectorPopoverHeader } from './inspector-popover-header';
|
|
158
|
-
export { default as __experimentalUseOnBlockDrop } from './use-on-block-drop';
|
|
159
158
|
|
|
160
159
|
/*
|
|
161
160
|
* State Related Components
|
|
@@ -40,7 +40,7 @@ export default function useInnerBlockTemplateSync(
|
|
|
40
40
|
templateLock,
|
|
41
41
|
templateInsertUpdatesSelection
|
|
42
42
|
) {
|
|
43
|
-
const { getSelectedBlocksInitialCaretPosition } =
|
|
43
|
+
const { getSelectedBlocksInitialCaretPosition, isBlockSelected } =
|
|
44
44
|
useSelect( blockEditorStore );
|
|
45
45
|
const { replaceInnerBlocks } = useDispatch( blockEditorStore );
|
|
46
46
|
const innerBlocks = useSelect(
|
|
@@ -86,7 +86,8 @@ export default function useInnerBlockTemplateSync(
|
|
|
86
86
|
nextBlocks,
|
|
87
87
|
currentInnerBlocks.length === 0 &&
|
|
88
88
|
templateInsertUpdatesSelection &&
|
|
89
|
-
nextBlocks.length !== 0
|
|
89
|
+
nextBlocks.length !== 0 &&
|
|
90
|
+
isBlockSelected( clientId ),
|
|
90
91
|
// This ensures the "initialPosition" doesn't change when applying the template
|
|
91
92
|
// If we're supposed to focus the block, we'll focus the first inner block
|
|
92
93
|
// otherwise, we won't apply any auto-focus.
|
|
@@ -1,96 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import {
|
|
5
|
+
useMemo,
|
|
6
|
+
useState,
|
|
7
|
+
useCallback,
|
|
8
|
+
useRef,
|
|
9
|
+
useEffect,
|
|
10
|
+
} from '@wordpress/element';
|
|
11
|
+
import { _x, __, isRTL } from '@wordpress/i18n';
|
|
12
|
+
import { useAsyncList, useViewportMatch } from '@wordpress/compose';
|
|
13
|
+
import {
|
|
14
|
+
__experimentalItemGroup as ItemGroup,
|
|
15
|
+
__experimentalItem as Item,
|
|
16
|
+
__experimentalHStack as HStack,
|
|
17
|
+
__experimentalNavigatorProvider as NavigatorProvider,
|
|
18
|
+
__experimentalNavigatorScreen as NavigatorScreen,
|
|
19
|
+
__experimentalNavigatorButton as NavigatorButton,
|
|
20
|
+
__experimentalNavigatorBackButton as NavigatorBackButton,
|
|
21
|
+
FlexBlock,
|
|
22
|
+
Button,
|
|
23
|
+
} from '@wordpress/components';
|
|
24
|
+
import { Icon, chevronRight, chevronLeft } from '@wordpress/icons';
|
|
25
|
+
import { focus } from '@wordpress/dom';
|
|
7
26
|
|
|
8
27
|
/**
|
|
9
28
|
* Internal dependencies
|
|
10
29
|
*/
|
|
11
|
-
import PatternInserterPanel from './pattern-panel';
|
|
12
30
|
import usePatternsState from './hooks/use-patterns-state';
|
|
13
31
|
import BlockPatternList from '../block-patterns-list';
|
|
14
32
|
import PatternsExplorerModal from './block-patterns-explorer/explorer';
|
|
15
33
|
|
|
16
|
-
function
|
|
17
|
-
rootClientId,
|
|
18
|
-
onInsert,
|
|
19
|
-
selectedCategory,
|
|
20
|
-
populatedCategories,
|
|
21
|
-
} ) {
|
|
22
|
-
const [ allPatterns, , onClick ] = usePatternsState(
|
|
23
|
-
onInsert,
|
|
24
|
-
rootClientId
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
const getPatternIndex = useCallback(
|
|
28
|
-
( pattern ) => {
|
|
29
|
-
if ( ! pattern.categories?.length ) {
|
|
30
|
-
return Infinity;
|
|
31
|
-
}
|
|
32
|
-
const indexedCategories = populatedCategories.reduce(
|
|
33
|
-
( accumulator, { name }, index ) => {
|
|
34
|
-
accumulator[ name ] = index;
|
|
35
|
-
return accumulator;
|
|
36
|
-
},
|
|
37
|
-
{}
|
|
38
|
-
);
|
|
39
|
-
return Math.min(
|
|
40
|
-
...pattern.categories.map( ( cat ) =>
|
|
41
|
-
indexedCategories[ cat ] !== undefined
|
|
42
|
-
? indexedCategories[ cat ]
|
|
43
|
-
: Infinity
|
|
44
|
-
)
|
|
45
|
-
);
|
|
46
|
-
},
|
|
47
|
-
[ populatedCategories ]
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const currentCategoryPatterns = useMemo(
|
|
51
|
-
() =>
|
|
52
|
-
allPatterns.filter( ( pattern ) =>
|
|
53
|
-
selectedCategory.name === 'uncategorized'
|
|
54
|
-
? getPatternIndex( pattern ) === Infinity
|
|
55
|
-
: pattern.categories?.includes( selectedCategory.name )
|
|
56
|
-
),
|
|
57
|
-
[ allPatterns, selectedCategory ]
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
// Ordering the patterns is important for the async rendering.
|
|
61
|
-
const orderedPatterns = useMemo( () => {
|
|
62
|
-
return currentCategoryPatterns.sort( ( a, b ) => {
|
|
63
|
-
return getPatternIndex( a ) - getPatternIndex( b );
|
|
64
|
-
} );
|
|
65
|
-
}, [ currentCategoryPatterns, getPatternIndex ] );
|
|
66
|
-
|
|
67
|
-
const currentShownPatterns = useAsyncList( orderedPatterns );
|
|
68
|
-
|
|
69
|
-
if ( ! currentCategoryPatterns.length ) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<div className="block-editor-inserter__panel-content">
|
|
75
|
-
<BlockPatternList
|
|
76
|
-
shownPatterns={ currentShownPatterns }
|
|
77
|
-
blockPatterns={ currentCategoryPatterns }
|
|
78
|
-
onClickPattern={ onClick }
|
|
79
|
-
label={ selectedCategory.label }
|
|
80
|
-
orientation="vertical"
|
|
81
|
-
isDraggable
|
|
82
|
-
/>
|
|
83
|
-
</div>
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function BlockPatternsTabs( {
|
|
88
|
-
rootClientId,
|
|
89
|
-
onInsert,
|
|
90
|
-
onClickCategory,
|
|
91
|
-
selectedCategory,
|
|
92
|
-
} ) {
|
|
93
|
-
const [ showPatternsExplorer, setShowPatternsExplorer ] = useState( false );
|
|
34
|
+
function usePatternsCategories() {
|
|
94
35
|
const [ allPatterns, allCategories ] = usePatternsState();
|
|
95
36
|
|
|
96
37
|
const hasRegisteredCategory = useCallback(
|
|
@@ -138,30 +79,173 @@ function BlockPatternsTabs( {
|
|
|
138
79
|
return categories;
|
|
139
80
|
}, [ allPatterns, allCategories ] );
|
|
140
81
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
82
|
+
return populatedCategories;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function BlockPatternsCategoryDialog( {
|
|
86
|
+
rootClientId,
|
|
87
|
+
onInsert,
|
|
88
|
+
category,
|
|
89
|
+
} ) {
|
|
90
|
+
const container = useRef();
|
|
91
|
+
|
|
92
|
+
useEffect( () => {
|
|
93
|
+
const timeout = setTimeout( () => {
|
|
94
|
+
const [ firstTabbable ] = focus.tabbable.find( container.current );
|
|
95
|
+
firstTabbable?.focus();
|
|
96
|
+
} );
|
|
97
|
+
return () => clearTimeout( timeout );
|
|
98
|
+
}, [ category ] );
|
|
144
99
|
|
|
145
100
|
return (
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
101
|
+
<div
|
|
102
|
+
ref={ container }
|
|
103
|
+
className="block-editor-inserter__patterns-category-panel"
|
|
104
|
+
>
|
|
105
|
+
<BlockPatternsCategoryPanel
|
|
106
|
+
rootClientId={ rootClientId }
|
|
107
|
+
onInsert={ onInsert }
|
|
108
|
+
category={ category }
|
|
152
109
|
/>
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
110
|
+
</div>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function BlockPatternsCategoryPanel( {
|
|
115
|
+
rootClientId,
|
|
116
|
+
onInsert,
|
|
117
|
+
category,
|
|
118
|
+
} ) {
|
|
119
|
+
const [ allPatterns, , onClick ] = usePatternsState(
|
|
120
|
+
onInsert,
|
|
121
|
+
rootClientId
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const availableCategories = usePatternsCategories();
|
|
125
|
+
const currentCategoryPatterns = useMemo(
|
|
126
|
+
() =>
|
|
127
|
+
allPatterns.filter( ( pattern ) => {
|
|
128
|
+
if ( category.name !== 'uncategorized' ) {
|
|
129
|
+
return pattern.categories?.includes( category.name );
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// The uncategorized category should show all the patterns without any category
|
|
133
|
+
// or with no available category.
|
|
134
|
+
const availablePatternCategories =
|
|
135
|
+
pattern.categories?.filter( ( cat ) =>
|
|
136
|
+
availableCategories.find(
|
|
137
|
+
( availableCategory ) =>
|
|
138
|
+
availableCategory.name === cat
|
|
139
|
+
)
|
|
140
|
+
) ?? [];
|
|
141
|
+
|
|
142
|
+
return availablePatternCategories.length === 0;
|
|
143
|
+
} ),
|
|
144
|
+
[ allPatterns, category ]
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
const currentShownPatterns = useAsyncList( currentCategoryPatterns );
|
|
148
|
+
|
|
149
|
+
if ( ! currentCategoryPatterns.length ) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<div>
|
|
155
|
+
<div className="block-editor-inserter__patterns-category-panel-title">
|
|
156
|
+
{ category.label }
|
|
157
|
+
</div>
|
|
158
|
+
<p>{ category.description }</p>
|
|
159
|
+
<BlockPatternList
|
|
160
|
+
shownPatterns={ currentShownPatterns }
|
|
161
|
+
blockPatterns={ currentCategoryPatterns }
|
|
162
|
+
onClickPattern={ onClick }
|
|
163
|
+
label={ category.label }
|
|
164
|
+
orientation="vertical"
|
|
165
|
+
category={ category.label }
|
|
166
|
+
isDraggable
|
|
167
|
+
/>
|
|
168
|
+
</div>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function BlockPatternsTabs( {
|
|
173
|
+
onSelectCategory,
|
|
174
|
+
selectedCategory,
|
|
175
|
+
onInsert,
|
|
176
|
+
rootClientId,
|
|
177
|
+
} ) {
|
|
178
|
+
const [ showPatternsExplorer, setShowPatternsExplorer ] = useState( false );
|
|
179
|
+
const categories = usePatternsCategories();
|
|
180
|
+
const isMobile = useViewportMatch( 'medium', '<' );
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<>
|
|
184
|
+
{ ! isMobile && (
|
|
185
|
+
<div className="block-editor-inserter__block-patterns-tabs-container">
|
|
186
|
+
<nav aria-label={ __( 'Block pattern categories' ) }>
|
|
187
|
+
<ItemGroup
|
|
188
|
+
role="list"
|
|
189
|
+
className="block-editor-inserter__block-patterns-tabs"
|
|
190
|
+
>
|
|
191
|
+
{ categories.map( ( category ) => (
|
|
192
|
+
<Item
|
|
193
|
+
role="listitem"
|
|
194
|
+
key={ category.name }
|
|
195
|
+
onClick={ () =>
|
|
196
|
+
onSelectCategory( category )
|
|
197
|
+
}
|
|
198
|
+
className={
|
|
199
|
+
category === selectedCategory
|
|
200
|
+
? 'block-editor-inserter__patterns-category block-editor-inserter__patterns-selected-category'
|
|
201
|
+
: 'block-editor-inserter__patterns-category'
|
|
202
|
+
}
|
|
203
|
+
aria-label={ category.label }
|
|
204
|
+
aria-current={
|
|
205
|
+
category === selectedCategory
|
|
206
|
+
? 'true'
|
|
207
|
+
: undefined
|
|
208
|
+
}
|
|
209
|
+
>
|
|
210
|
+
<HStack>
|
|
211
|
+
<FlexBlock>
|
|
212
|
+
{ category.label }
|
|
213
|
+
</FlexBlock>
|
|
214
|
+
<Icon icon={ chevronRight } />
|
|
215
|
+
</HStack>
|
|
216
|
+
</Item>
|
|
217
|
+
) ) }
|
|
218
|
+
|
|
219
|
+
<div
|
|
220
|
+
role="presentation"
|
|
221
|
+
className="block-editor-inserter__patterns-fill-space"
|
|
222
|
+
/>
|
|
223
|
+
|
|
224
|
+
<div role="listitem">
|
|
225
|
+
<Button
|
|
226
|
+
className="block-editor-inserter__patterns-explore-button"
|
|
227
|
+
onClick={ () =>
|
|
228
|
+
setShowPatternsExplorer( true )
|
|
229
|
+
}
|
|
230
|
+
variant="secondary"
|
|
231
|
+
>
|
|
232
|
+
{ __( 'Explore all patterns' ) }
|
|
233
|
+
</Button>
|
|
234
|
+
</div>
|
|
235
|
+
</ItemGroup>
|
|
236
|
+
</nav>
|
|
237
|
+
</div>
|
|
238
|
+
) }
|
|
239
|
+
{ isMobile && (
|
|
240
|
+
<BlockPatternsTabNavigation
|
|
156
241
|
onInsert={ onInsert }
|
|
157
|
-
|
|
158
|
-
populatedCategories={ populatedCategories }
|
|
242
|
+
rootClientId={ rootClientId }
|
|
159
243
|
/>
|
|
160
244
|
) }
|
|
161
245
|
{ showPatternsExplorer && (
|
|
162
246
|
<PatternsExplorerModal
|
|
163
|
-
initialCategory={
|
|
164
|
-
patternCategories={
|
|
247
|
+
initialCategory={ selectedCategory }
|
|
248
|
+
patternCategories={ categories }
|
|
165
249
|
onModalClose={ () => setShowPatternsExplorer( false ) }
|
|
166
250
|
/>
|
|
167
251
|
) }
|
|
@@ -169,4 +253,54 @@ function BlockPatternsTabs( {
|
|
|
169
253
|
);
|
|
170
254
|
}
|
|
171
255
|
|
|
256
|
+
function BlockPatternsTabNavigation( { onInsert, rootClientId } ) {
|
|
257
|
+
const categories = usePatternsCategories();
|
|
258
|
+
|
|
259
|
+
return (
|
|
260
|
+
<NavigatorProvider initialPath="/">
|
|
261
|
+
<NavigatorScreen path="/">
|
|
262
|
+
<ItemGroup>
|
|
263
|
+
{ categories.map( ( category ) => (
|
|
264
|
+
<NavigatorButton
|
|
265
|
+
key={ category.name }
|
|
266
|
+
path={ `/category/${ category.name }` }
|
|
267
|
+
as={ Item }
|
|
268
|
+
isAction
|
|
269
|
+
>
|
|
270
|
+
<HStack>
|
|
271
|
+
<FlexBlock>{ category.label }</FlexBlock>
|
|
272
|
+
<Icon
|
|
273
|
+
icon={
|
|
274
|
+
isRTL() ? chevronLeft : chevronRight
|
|
275
|
+
}
|
|
276
|
+
/>
|
|
277
|
+
</HStack>
|
|
278
|
+
</NavigatorButton>
|
|
279
|
+
) ) }
|
|
280
|
+
</ItemGroup>
|
|
281
|
+
</NavigatorScreen>
|
|
282
|
+
|
|
283
|
+
{ categories.map( ( category ) => (
|
|
284
|
+
<NavigatorScreen
|
|
285
|
+
key={ category.name }
|
|
286
|
+
path={ `/category/${ category.name }` }
|
|
287
|
+
>
|
|
288
|
+
<NavigatorBackButton
|
|
289
|
+
icon={ isRTL() ? chevronRight : chevronLeft }
|
|
290
|
+
isSmall
|
|
291
|
+
aria-label={ __( 'Navigate to the categories list' ) }
|
|
292
|
+
>
|
|
293
|
+
{ __( 'Back' ) }
|
|
294
|
+
</NavigatorBackButton>
|
|
295
|
+
<BlockPatternsCategoryPanel
|
|
296
|
+
category={ category }
|
|
297
|
+
rootClientId={ rootClientId }
|
|
298
|
+
onInsert={ onInsert }
|
|
299
|
+
/>
|
|
300
|
+
</NavigatorScreen>
|
|
301
|
+
) ) }
|
|
302
|
+
</NavigatorProvider>
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
172
306
|
export default BlockPatternsTabs;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { map,
|
|
4
|
+
import { map, groupBy, orderBy } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { __, _x } from '@wordpress/i18n';
|
|
10
10
|
import { useMemo, useEffect } from '@wordpress/element';
|
|
11
|
-
import { useAsyncList } from '@wordpress/compose';
|
|
11
|
+
import { pipe, useAsyncList } from '@wordpress/compose';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Internal dependencies
|
|
@@ -53,7 +53,7 @@ export function BlockTypesTab( {
|
|
|
53
53
|
}, [ items ] );
|
|
54
54
|
|
|
55
55
|
const itemsPerCategory = useMemo( () => {
|
|
56
|
-
return
|
|
56
|
+
return pipe(
|
|
57
57
|
( itemList ) =>
|
|
58
58
|
itemList.filter(
|
|
59
59
|
( item ) => item.category && item.category !== 'reusable'
|
|
@@ -24,7 +24,9 @@ import { useSelect } from '@wordpress/data';
|
|
|
24
24
|
import Tips from './tips';
|
|
25
25
|
import InserterPreviewPanel from './preview-panel';
|
|
26
26
|
import BlockTypesTab from './block-types-tab';
|
|
27
|
-
import BlockPatternsTabs
|
|
27
|
+
import BlockPatternsTabs, {
|
|
28
|
+
BlockPatternsCategoryDialog,
|
|
29
|
+
} from './block-patterns-tab';
|
|
28
30
|
import ReusableBlocksTab from './reusable-blocks-tab';
|
|
29
31
|
import InserterSearchResults from './search-results';
|
|
30
32
|
import useInsertionPoint from './hooks/use-insertion-point';
|
|
@@ -52,6 +54,7 @@ function InserterMenu(
|
|
|
52
54
|
const [ hoveredItem, setHoveredItem ] = useState( null );
|
|
53
55
|
const [ selectedPatternCategory, setSelectedPatternCategory ] =
|
|
54
56
|
useState( null );
|
|
57
|
+
const [ selectedTab, setSelectedTab ] = useState( null );
|
|
55
58
|
|
|
56
59
|
const [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ] =
|
|
57
60
|
useInsertionPoint( {
|
|
@@ -144,7 +147,7 @@ function InserterMenu(
|
|
|
144
147
|
<BlockPatternsTabs
|
|
145
148
|
rootClientId={ destinationRootClientId }
|
|
146
149
|
onInsert={ onInsertPattern }
|
|
147
|
-
|
|
150
|
+
onSelectCategory={ onClickPatternCategory }
|
|
148
151
|
selectedCategory={ selectedPatternCategory }
|
|
149
152
|
/>
|
|
150
153
|
),
|
|
@@ -186,6 +189,8 @@ function InserterMenu(
|
|
|
186
189
|
},
|
|
187
190
|
} ) );
|
|
188
191
|
|
|
192
|
+
const showPatternPanel =
|
|
193
|
+
selectedTab === 'patterns' && ! filterValue && selectedPatternCategory;
|
|
189
194
|
const showAsTabs = ! filterValue && ( showPatterns || hasReusableBlocks );
|
|
190
195
|
|
|
191
196
|
return (
|
|
@@ -228,6 +233,7 @@ function InserterMenu(
|
|
|
228
233
|
showPatterns={ showPatterns }
|
|
229
234
|
showReusableBlocks={ hasReusableBlocks }
|
|
230
235
|
prioritizePatterns={ prioritizePatterns }
|
|
236
|
+
onSelect={ setSelectedTab }
|
|
231
237
|
>
|
|
232
238
|
{ getCurrentTab }
|
|
233
239
|
</InserterTabs>
|
|
@@ -241,6 +247,13 @@ function InserterMenu(
|
|
|
241
247
|
{ showInserterHelpPanel && hoveredItem && (
|
|
242
248
|
<InserterPreviewPanel item={ hoveredItem } />
|
|
243
249
|
) }
|
|
250
|
+
{ showPatternPanel && (
|
|
251
|
+
<BlockPatternsCategoryDialog
|
|
252
|
+
rootClientId={ destinationRootClientId }
|
|
253
|
+
onInsert={ onInsertPattern }
|
|
254
|
+
category={ selectedPatternCategory }
|
|
255
|
+
/>
|
|
256
|
+
) }
|
|
244
257
|
</div>
|
|
245
258
|
);
|
|
246
259
|
}
|