@wordpress/edit-widgets 7.2.0 → 7.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/build/blocks/widget-area/edit/index.cjs +10 -8
- package/build/blocks/widget-area/edit/index.cjs.map +1 -1
- package/build/blocks/widget-area/edit/inner-blocks.cjs +10 -8
- package/build/blocks/widget-area/edit/inner-blocks.cjs.map +1 -1
- package/build/blocks/widget-area/edit/use-is-dragging-within.cjs.map +1 -1
- package/build/blocks/widget-area/index.cjs +9 -7
- package/build/blocks/widget-area/index.cjs.map +1 -1
- package/build/components/error-boundary/index.cjs.map +1 -1
- package/build/components/header/document-tools/index.cjs +20 -10
- package/build/components/header/document-tools/index.cjs.map +1 -1
- package/build/components/header/index.cjs +12 -10
- package/build/components/header/index.cjs.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/config.cjs +5 -0
- package/build/components/keyboard-shortcut-help-modal/config.cjs.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs +9 -7
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.cjs +12 -11
- package/build/components/keyboard-shortcut-help-modal/index.cjs.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/shortcut.cjs +34 -13
- package/build/components/keyboard-shortcut-help-modal/shortcut.cjs.map +1 -1
- package/build/components/keyboard-shortcuts/index.cjs.map +1 -1
- package/build/components/layout/index.cjs +19 -13
- package/build/components/layout/index.cjs.map +1 -1
- package/build/components/layout/interface.cjs +27 -13
- package/build/components/layout/interface.cjs.map +1 -1
- package/build/components/layout/unsaved-changes-warning.cjs.map +1 -1
- package/build/components/more-menu/index.cjs +14 -9
- package/build/components/more-menu/index.cjs.map +1 -1
- package/build/components/secondary-sidebar/index.cjs +10 -8
- package/build/components/secondary-sidebar/index.cjs.map +1 -1
- package/build/components/secondary-sidebar/inserter-sidebar.cjs +9 -7
- package/build/components/secondary-sidebar/inserter-sidebar.cjs.map +1 -1
- package/build/components/sidebar/index.cjs +23 -15
- package/build/components/sidebar/index.cjs.map +1 -1
- package/build/components/welcome-guide/index.cjs +5 -1
- package/build/components/welcome-guide/index.cjs.map +1 -1
- package/build/components/widget-areas-block-editor-content/index.cjs +10 -8
- package/build/components/widget-areas-block-editor-content/index.cjs.map +1 -1
- package/build/components/widget-areas-block-editor-provider/index.cjs +10 -8
- package/build/components/widget-areas-block-editor-provider/index.cjs.map +1 -1
- package/build/constants.cjs +0 -2
- package/build/constants.cjs.map +1 -1
- package/build/index.cjs +12 -10
- package/build/index.cjs.map +1 -1
- package/build/store/actions.cjs +11 -7
- package/build/store/actions.cjs.map +1 -1
- package/build/store/index.cjs +14 -12
- package/build/store/index.cjs.map +1 -1
- package/build/store/selectors.cjs +3 -1
- package/build/store/selectors.cjs.map +1 -1
- package/build-module/blocks/widget-area/index.mjs.map +1 -1
- package/build-module/components/header/document-tools/index.mjs +10 -2
- package/build-module/components/header/document-tools/index.mjs.map +1 -1
- package/build-module/components/header/undo-redo/redo.mjs.map +1 -1
- package/build-module/components/header/undo-redo/undo.mjs.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/config.mjs +5 -0
- package/build-module/components/keyboard-shortcut-help-modal/config.mjs.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.mjs +1 -2
- package/build-module/components/keyboard-shortcut-help-modal/index.mjs.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs +34 -13
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs.map +1 -1
- package/build-module/components/layout/index.mjs +5 -1
- package/build-module/components/layout/index.mjs.map +1 -1
- package/build-module/components/layout/interface.mjs +16 -4
- package/build-module/components/layout/interface.mjs.map +1 -1
- package/build-module/components/more-menu/index.mjs +4 -1
- package/build-module/components/more-menu/index.mjs.map +1 -1
- package/build-module/components/sidebar/index.mjs +14 -8
- package/build-module/components/sidebar/index.mjs.map +1 -1
- package/build-module/components/welcome-guide/index.mjs +5 -1
- package/build-module/components/welcome-guide/index.mjs.map +1 -1
- package/build-module/constants.mjs +1 -2
- package/build-module/constants.mjs.map +1 -1
- package/build-module/index.mjs +2 -2
- package/build-module/index.mjs.map +1 -1
- package/build-module/store/actions.mjs +11 -7
- package/build-module/store/actions.mjs.map +1 -1
- package/build-module/store/selectors.mjs +3 -1
- package/build-module/store/selectors.mjs.map +1 -1
- package/build-style/style-rtl.css +42 -37
- package/build-style/style.css +42 -37
- package/build-types/blocks/widget-area/edit/index.d.ts +10 -0
- package/build-types/blocks/widget-area/edit/index.d.ts.map +1 -0
- package/build-types/blocks/widget-area/edit/inner-blocks.d.ts +4 -0
- package/build-types/blocks/widget-area/edit/inner-blocks.d.ts.map +1 -0
- package/build-types/blocks/widget-area/edit/use-is-dragging-within.d.ts +12 -0
- package/build-types/blocks/widget-area/edit/use-is-dragging-within.d.ts.map +1 -0
- package/build-types/blocks/widget-area/index.d.ts +14 -0
- package/build-types/blocks/widget-area/index.d.ts.map +1 -0
- package/build-types/components/error-boundary/index.d.ts +14 -0
- package/build-types/components/error-boundary/index.d.ts.map +1 -0
- package/build-types/components/header/document-tools/index.d.ts +3 -0
- package/build-types/components/header/document-tools/index.d.ts.map +1 -0
- package/build-types/components/header/index.d.ts +3 -0
- package/build-types/components/header/index.d.ts.map +1 -0
- package/build-types/components/header/undo-redo/redo.d.ts +3 -0
- package/build-types/components/header/undo-redo/redo.d.ts.map +1 -0
- package/build-types/components/header/undo-redo/undo.d.ts +3 -0
- package/build-types/components/header/undo-redo/undo.d.ts.map +1 -0
- package/build-types/components/keyboard-shortcut-help-modal/config.d.ts +3 -0
- package/build-types/components/keyboard-shortcut-help-modal/config.d.ts.map +1 -0
- package/build-types/components/keyboard-shortcut-help-modal/dynamic-shortcut.d.ts +5 -0
- package/build-types/components/keyboard-shortcut-help-modal/dynamic-shortcut.d.ts.map +1 -0
- package/build-types/components/keyboard-shortcut-help-modal/index.d.ts +5 -0
- package/build-types/components/keyboard-shortcut-help-modal/index.d.ts.map +1 -0
- package/build-types/components/keyboard-shortcut-help-modal/shortcut.d.ts +25 -0
- package/build-types/components/keyboard-shortcut-help-modal/shortcut.d.ts.map +1 -0
- package/build-types/components/keyboard-shortcuts/index.d.ts +7 -0
- package/build-types/components/keyboard-shortcuts/index.d.ts.map +1 -0
- package/build-types/components/layout/index.d.ts +5 -0
- package/build-types/components/layout/index.d.ts.map +1 -0
- package/build-types/components/layout/interface.d.ts +5 -0
- package/build-types/components/layout/interface.d.ts.map +1 -0
- package/build-types/components/layout/unsaved-changes-warning.d.ts +10 -0
- package/build-types/components/layout/unsaved-changes-warning.d.ts.map +1 -0
- package/build-types/components/more-menu/index.d.ts +2 -0
- package/build-types/components/more-menu/index.d.ts.map +1 -0
- package/build-types/components/more-menu/tools-more-menu-group.d.ts +6 -0
- package/build-types/components/more-menu/tools-more-menu-group.d.ts.map +1 -0
- package/build-types/components/notices/index.d.ts +3 -0
- package/build-types/components/notices/index.d.ts.map +1 -0
- package/build-types/components/save-button/index.d.ts +3 -0
- package/build-types/components/save-button/index.d.ts.map +1 -0
- package/build-types/components/secondary-sidebar/index.d.ts +2 -0
- package/build-types/components/secondary-sidebar/index.d.ts.map +1 -0
- package/build-types/components/secondary-sidebar/inserter-sidebar.d.ts +2 -0
- package/build-types/components/secondary-sidebar/inserter-sidebar.d.ts.map +1 -0
- package/build-types/components/secondary-sidebar/list-view-sidebar.d.ts +2 -0
- package/build-types/components/secondary-sidebar/list-view-sidebar.d.ts.map +1 -0
- package/build-types/components/sidebar/index.d.ts +2 -0
- package/build-types/components/sidebar/index.d.ts.map +1 -0
- package/build-types/components/sidebar/widget-areas.d.ts +4 -0
- package/build-types/components/sidebar/widget-areas.d.ts.map +1 -0
- package/build-types/components/welcome-guide/index.d.ts +2 -0
- package/build-types/components/welcome-guide/index.d.ts.map +1 -0
- package/build-types/components/widget-areas-block-editor-content/index.d.ts +4 -0
- package/build-types/components/widget-areas-block-editor-content/index.d.ts.map +1 -0
- package/build-types/components/widget-areas-block-editor-provider/index.d.ts +6 -0
- package/build-types/components/widget-areas-block-editor-provider/index.d.ts.map +1 -0
- package/build-types/constants.d.ts +2 -0
- package/build-types/constants.d.ts.map +1 -0
- package/build-types/filters/index.d.ts +3 -0
- package/build-types/filters/index.d.ts.map +1 -0
- package/build-types/filters/move-to-widget-area.d.ts +2 -0
- package/build-types/filters/move-to-widget-area.d.ts.map +1 -0
- package/build-types/filters/replace-media-upload.d.ts +2 -0
- package/build-types/filters/replace-media-upload.d.ts.map +1 -0
- package/build-types/hooks/use-last-selected-widget-area.d.ts +9 -0
- package/build-types/hooks/use-last-selected-widget-area.d.ts.map +1 -0
- package/build-types/hooks/use-widget-library-insertion-point.d.ts +3 -0
- package/build-types/hooks/use-widget-library-insertion-point.d.ts.map +1 -0
- package/build-types/index.d.ts +16 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/lock-unlock.d.ts +2 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/store/actions.d.ts +144 -0
- package/build-types/store/actions.d.ts.map +1 -0
- package/build-types/store/constants.d.ts +5 -0
- package/build-types/store/constants.d.ts.map +1 -0
- package/build-types/store/index.d.ts +9 -0
- package/build-types/store/index.d.ts.map +1 -0
- package/build-types/store/private-selectors.d.ts +3 -0
- package/build-types/store/private-selectors.d.ts.map +1 -0
- package/build-types/store/reducer.d.ts +73 -0
- package/build-types/store/reducer.d.ts.map +1 -0
- package/build-types/store/resolvers.d.ts +17 -0
- package/build-types/store/resolvers.d.ts.map +1 -0
- package/build-types/store/selectors.d.ts +159 -0
- package/build-types/store/selectors.d.ts.map +1 -0
- package/build-types/store/transformers.d.ts +16 -0
- package/build-types/store/transformers.d.ts.map +1 -0
- package/build-types/store/utils.d.ts +53 -0
- package/build-types/store/utils.d.ts.map +1 -0
- package/package.json +33 -33
- package/src/components/header/style.scss +1 -1
- package/src/components/keyboard-shortcut-help-modal/config.js +3 -0
- package/src/components/keyboard-shortcut-help-modal/index.jsx +0 -2
- package/src/components/keyboard-shortcut-help-modal/shortcut.jsx +43 -29
- package/src/components/sidebar/index.jsx +1 -1
- package/src/components/sidebar/style.scss +6 -0
- package/src/components/welcome-guide/style.scss +1 -1
- package/src/components/widget-areas-block-editor-content/style.scss +1 -1
- package/src/constants.js +0 -1
- package/src/index.jsx +2 -7
- package/src/store/actions.js +8 -12
- package/src/store/selectors.js +4 -1
- package/src/store/test/actions.jsdom.test.js +47 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __ } from '@wordpress/i18n';
|
|
2
2
|
|
|
3
|
+
/** @type {Array<import('react').ComponentProps<typeof import('./shortcut').default>>} */
|
|
3
4
|
export const textFormattingShortcuts = [
|
|
4
5
|
{
|
|
5
6
|
keyCombination: { modifier: 'primary', character: 'b' },
|
|
@@ -19,6 +20,8 @@ export const textFormattingShortcuts = [
|
|
|
19
20
|
},
|
|
20
21
|
{
|
|
21
22
|
keyCombination: { character: '[[' },
|
|
23
|
+
/* translators: The keyboard sequence [[, pressing the left bracket key twice. */
|
|
24
|
+
ariaLabel: __( 'Left bracket twice' ),
|
|
22
25
|
description: __( 'Insert a link to a post or page.' ),
|
|
23
26
|
},
|
|
24
27
|
{
|
|
@@ -115,8 +115,6 @@ export default function KeyboardShortcutHelpModal( {
|
|
|
115
115
|
description: __(
|
|
116
116
|
'Change the block type after adding a new paragraph.'
|
|
117
117
|
),
|
|
118
|
-
/* translators: The forward-slash character. e.g. '/'. */
|
|
119
|
-
ariaLabel: __( 'Forward-slash' ),
|
|
120
118
|
},
|
|
121
119
|
] }
|
|
122
120
|
/>
|
|
@@ -1,43 +1,57 @@
|
|
|
1
1
|
import { Fragment } from '@wordpress/element';
|
|
2
2
|
import { displayShortcutList, shortcutAriaLabel } from '@wordpress/keycodes';
|
|
3
|
+
import { VisuallyHidden } from '@wordpress/ui';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {Object} ShortcutKeyCombination
|
|
7
|
+
* @property {string} character Shortcut key.
|
|
8
|
+
* @property {import('@wordpress/keycodes').WPKeycodeModifier | null} [modifier] Optional shortcut modifier.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {Object} props Component props.
|
|
13
|
+
* @param {ShortcutKeyCombination} props.keyCombination Shortcut to display.
|
|
14
|
+
* @param {string} [props.ariaLabel] Custom readable shortcut label.
|
|
15
|
+
*/
|
|
16
|
+
function KeyCombination( { keyCombination, ariaLabel } ) {
|
|
17
|
+
const { character, modifier } = keyCombination;
|
|
18
|
+
const normalizedModifier = modifier ?? 'undefined';
|
|
19
|
+
const keys = displayShortcutList[ normalizedModifier ]( character );
|
|
16
20
|
|
|
17
21
|
return (
|
|
18
22
|
<kbd
|
|
19
23
|
className="edit-widgets-keyboard-shortcut-help-modal__shortcut-key-combination"
|
|
20
24
|
dir="ltr"
|
|
21
|
-
aria-label={ forceAriaLabel || ariaLabel }
|
|
22
25
|
>
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<
|
|
30
|
-
key={ index }
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
<VisuallyHidden render={ <span /> }>
|
|
27
|
+
{ ariaLabel ||
|
|
28
|
+
shortcutAriaLabel[ normalizedModifier ]( character ) }
|
|
29
|
+
</VisuallyHidden>
|
|
30
|
+
<span aria-hidden="true">
|
|
31
|
+
{ keys.map( ( key, index ) =>
|
|
32
|
+
key === '+' && index < keys.length - 1 ? (
|
|
33
|
+
<Fragment key={ index }>{ key }</Fragment>
|
|
34
|
+
) : (
|
|
35
|
+
<kbd
|
|
36
|
+
key={ index }
|
|
37
|
+
className="edit-widgets-keyboard-shortcut-help-modal__shortcut-key"
|
|
38
|
+
>
|
|
39
|
+
{ key }
|
|
40
|
+
</kbd>
|
|
41
|
+
)
|
|
42
|
+
) }
|
|
43
|
+
</span>
|
|
37
44
|
</kbd>
|
|
38
45
|
);
|
|
39
46
|
}
|
|
40
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @param {Object} props Component props.
|
|
50
|
+
* @param {string} props.description Description of the shortcut action.
|
|
51
|
+
* @param {ShortcutKeyCombination} props.keyCombination Primary shortcut.
|
|
52
|
+
* @param {ShortcutKeyCombination[]} [props.aliases] Alternative shortcuts.
|
|
53
|
+
* @param {string} [props.ariaLabel] Custom readable shortcut label.
|
|
54
|
+
*/
|
|
41
55
|
function Shortcut( { description, keyCombination, aliases = [], ariaLabel } ) {
|
|
42
56
|
return (
|
|
43
57
|
<>
|
|
@@ -47,12 +61,12 @@ function Shortcut( { description, keyCombination, aliases = [], ariaLabel } ) {
|
|
|
47
61
|
<div className="edit-widgets-keyboard-shortcut-help-modal__shortcut-term">
|
|
48
62
|
<KeyCombination
|
|
49
63
|
keyCombination={ keyCombination }
|
|
50
|
-
|
|
64
|
+
ariaLabel={ ariaLabel }
|
|
51
65
|
/>
|
|
52
66
|
{ aliases.map( ( alias, index ) => (
|
|
53
67
|
<KeyCombination
|
|
54
68
|
keyCombination={ alias }
|
|
55
|
-
|
|
69
|
+
ariaLabel={ ariaLabel }
|
|
56
70
|
key={ index }
|
|
57
71
|
/>
|
|
58
72
|
) ) }
|
|
@@ -24,7 +24,7 @@ const { Tabs: WCTabs } = unlock( componentsPrivateApis );
|
|
|
24
24
|
|
|
25
25
|
function SidebarHeader( { selectedWidgetAreaBlock } ) {
|
|
26
26
|
return (
|
|
27
|
-
<WCTabs.TabList>
|
|
27
|
+
<WCTabs.TabList className="edit-widgets-sidebar__panel-tablist">
|
|
28
28
|
<WCTabs.Tab tabId={ WIDGET_AREAS_IDENTIFIER }>
|
|
29
29
|
{ selectedWidgetAreaBlock
|
|
30
30
|
? selectedWidgetAreaBlock.attributes.name
|
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
padding-left: 0;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
// Overlap the header's bottom border, so the selected tab's indicator
|
|
8
|
+
// covers it, as in the inserter.
|
|
9
|
+
.edit-widgets-sidebar__panel-tablist {
|
|
10
|
+
margin-bottom: -$border-width;
|
|
11
|
+
}
|
|
12
|
+
|
|
7
13
|
|
|
8
14
|
.edit-widgets-widget-areas__top-container {
|
|
9
15
|
display: flex;
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
// This is copied from edit-post/src/components/style.scss but without the padding.
|
|
29
29
|
& .components-button {
|
|
30
30
|
font-family: $default-font;
|
|
31
|
-
font-size:
|
|
31
|
+
font-size: var(--wpds-typography-font-size-md);
|
|
32
32
|
|
|
33
33
|
&.is-tertiary,
|
|
34
34
|
&.has-icon {
|
package/src/constants.js
CHANGED
package/src/index.jsx
CHANGED
|
@@ -23,10 +23,7 @@ import './store';
|
|
|
23
23
|
import './filters';
|
|
24
24
|
import * as widgetArea from './blocks/widget-area';
|
|
25
25
|
import Layout from './components/layout';
|
|
26
|
-
import {
|
|
27
|
-
ALLOW_REUSABLE_BLOCKS,
|
|
28
|
-
ENABLE_EXPERIMENTAL_FSE_BLOCKS,
|
|
29
|
-
} from './constants';
|
|
26
|
+
import { ALLOW_REUSABLE_BLOCKS } from './constants';
|
|
30
27
|
|
|
31
28
|
const disabledBlocks = [
|
|
32
29
|
'core/more',
|
|
@@ -67,9 +64,7 @@ export function initializeEditor( id, settings ) {
|
|
|
67
64
|
registerCoreBlocks( coreBlocks );
|
|
68
65
|
registerLegacyWidgetBlock();
|
|
69
66
|
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
|
|
70
|
-
__experimentalRegisterExperimentalCoreBlocks(
|
|
71
|
-
enableFSEBlocks: ENABLE_EXPERIMENTAL_FSE_BLOCKS,
|
|
72
|
-
} );
|
|
67
|
+
__experimentalRegisterExperimentalCoreBlocks();
|
|
73
68
|
}
|
|
74
69
|
registerLegacyWidgetVariations( settings );
|
|
75
70
|
registerBlock( widgetArea );
|
package/src/store/actions.js
CHANGED
|
@@ -108,7 +108,7 @@ export const saveWidgetAreas =
|
|
|
108
108
|
*/
|
|
109
109
|
export const saveWidgetArea =
|
|
110
110
|
( widgetAreaId ) =>
|
|
111
|
-
async ( {
|
|
111
|
+
async ( { select, registry } ) => {
|
|
112
112
|
const widgets = select.getWidgets();
|
|
113
113
|
|
|
114
114
|
const post = registry
|
|
@@ -287,17 +287,9 @@ export const saveWidgetArea =
|
|
|
287
287
|
{ undoIgnore: true }
|
|
288
288
|
);
|
|
289
289
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
registry
|
|
293
|
-
.dispatch( coreStore )
|
|
294
|
-
.receiveEntityRecords( KIND, POST_TYPE, post, undefined );
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
const trySaveWidgetArea =
|
|
298
|
-
( widgetAreaId ) =>
|
|
299
|
-
( { registry } ) => {
|
|
300
|
-
registry
|
|
290
|
+
// Sidebar and widget requests can both rewrite the sidebar lists. Finish
|
|
291
|
+
// this write before saveWidgetAreas starts saving the next area.
|
|
292
|
+
await registry
|
|
301
293
|
.dispatch( coreStore )
|
|
302
294
|
.saveEditedEntityRecord(
|
|
303
295
|
KIND,
|
|
@@ -307,6 +299,10 @@ const trySaveWidgetArea =
|
|
|
307
299
|
throwOnError: true,
|
|
308
300
|
}
|
|
309
301
|
);
|
|
302
|
+
|
|
303
|
+
registry
|
|
304
|
+
.dispatch( coreStore )
|
|
305
|
+
.receiveEntityRecords( KIND, POST_TYPE, post, undefined );
|
|
310
306
|
};
|
|
311
307
|
|
|
312
308
|
/**
|
package/src/store/selectors.js
CHANGED
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
} from './utils';
|
|
13
13
|
import { STORE_NAME as editWidgetsStoreName } from './constants';
|
|
14
14
|
|
|
15
|
+
/** @typedef {import('@wordpress/blocks').Block} Block */
|
|
16
|
+
|
|
15
17
|
const EMPTY_INSERTION_POINT = {
|
|
16
18
|
rootClientId: undefined,
|
|
17
19
|
insertionIndex: undefined,
|
|
@@ -108,7 +110,8 @@ export const getWidgetAreaForWidgetId = createRegistrySelector(
|
|
|
108
110
|
*
|
|
109
111
|
* @param {string} clientId The client id of a block in a widget area.
|
|
110
112
|
*
|
|
111
|
-
* @return {
|
|
113
|
+
* @return {Block | null} The widget area block.
|
|
114
|
+
* @type {(state: Record<string, unknown>, clientId: string) => Block | null}
|
|
112
115
|
*/
|
|
113
116
|
export const getParentWidgetAreaBlock = createRegistrySelector(
|
|
114
117
|
( select ) => ( state, clientId ) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { saveWidgetArea } from '../actions';
|
|
2
|
+
import { saveWidgetArea, saveWidgetAreas } from '../actions';
|
|
3
3
|
|
|
4
4
|
// Only the store descriptors are imported from these packages; stub them so
|
|
5
5
|
// their browser-only side effects do not run.
|
|
@@ -57,7 +57,6 @@ function setup(
|
|
|
57
57
|
return {
|
|
58
58
|
run: () =>
|
|
59
59
|
saveWidgetArea( area )( {
|
|
60
|
-
dispatch: vi.fn(),
|
|
61
60
|
select,
|
|
62
61
|
registry,
|
|
63
62
|
} ),
|
|
@@ -67,6 +66,52 @@ function setup(
|
|
|
67
66
|
};
|
|
68
67
|
}
|
|
69
68
|
|
|
69
|
+
describe( 'saveWidgetAreas', () => {
|
|
70
|
+
it( 'waits for a widget area’s sidebar save before saving the next area', async () => {
|
|
71
|
+
const firstSidebarSave = Promise.withResolvers();
|
|
72
|
+
const saveSidebar = vi.fn( ( kind, name, id ) =>
|
|
73
|
+
id === 'sidebar-1' ? firstSidebarSave.promise : Promise.resolve()
|
|
74
|
+
);
|
|
75
|
+
const registry = {
|
|
76
|
+
select: () => ( {
|
|
77
|
+
getEditedEntityRecord: () => ( { blocks: [] } ),
|
|
78
|
+
} ),
|
|
79
|
+
dispatch: () => ( {
|
|
80
|
+
__experimentalBatch: async () => [],
|
|
81
|
+
editEntityRecord: vi.fn(),
|
|
82
|
+
finishResolution: vi.fn(),
|
|
83
|
+
receiveEntityRecords: vi.fn(),
|
|
84
|
+
saveEditedEntityRecord: saveSidebar,
|
|
85
|
+
} ),
|
|
86
|
+
};
|
|
87
|
+
const select = { getWidgets: () => ( {} ) };
|
|
88
|
+
const dispatch = Object.assign(
|
|
89
|
+
( thunk ) => thunk( { registry, select, dispatch } ),
|
|
90
|
+
{
|
|
91
|
+
saveWidgetArea: vi.fn( ( id ) =>
|
|
92
|
+
dispatch( saveWidgetArea( id ) )
|
|
93
|
+
),
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
const save = dispatch(
|
|
97
|
+
saveWidgetAreas( [ { id: 'sidebar-1' }, { id: 'sidebar-2' } ] )
|
|
98
|
+
);
|
|
99
|
+
try {
|
|
100
|
+
await vi.waitFor( () => expect( saveSidebar ).toHaveBeenCalled() );
|
|
101
|
+
expect( dispatch.saveWidgetArea.mock.calls ).toEqual( [
|
|
102
|
+
[ 'sidebar-1' ],
|
|
103
|
+
] );
|
|
104
|
+
} finally {
|
|
105
|
+
firstSidebarSave.resolve();
|
|
106
|
+
await save;
|
|
107
|
+
}
|
|
108
|
+
expect( saveSidebar.mock.calls.map( ( [ , , id ] ) => id ) ).toEqual( [
|
|
109
|
+
'sidebar-1',
|
|
110
|
+
'sidebar-2',
|
|
111
|
+
] );
|
|
112
|
+
} );
|
|
113
|
+
} );
|
|
114
|
+
|
|
70
115
|
describe( 'saveWidgetArea', () => {
|
|
71
116
|
it( 'saves a block that shares an existing widget ID with an earlier block as a new widget', async () => {
|
|
72
117
|
// Splitting a paragraph widget copies the block's attributes,
|