@wordpress/edit-widgets 7.0.0 → 7.2.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 +106 -116
- package/build/blocks/widget-area/edit/index.cjs.map +1 -7
- package/build/blocks/widget-area/edit/inner-blocks.cjs +44 -62
- package/build/blocks/widget-area/edit/inner-blocks.cjs.map +1 -7
- package/build/blocks/widget-area/edit/use-is-dragging-within.cjs +41 -53
- package/build/blocks/widget-area/edit/use-is-dragging-within.cjs.map +1 -7
- package/build/blocks/widget-area/index.cjs +40 -44
- package/build/blocks/widget-area/index.cjs.map +1 -7
- package/build/components/error-boundary/index.cjs +115 -155
- package/build/components/error-boundary/index.cjs.map +1 -7
- package/build/components/header/document-tools/index.cjs +80 -115
- package/build/components/header/document-tools/index.cjs.map +1 -7
- package/build/components/header/index.cjs +77 -80
- package/build/components/header/index.cjs.map +1 -7
- package/build/components/header/undo-redo/redo.cjs +30 -52
- package/build/components/header/undo-redo/redo.cjs.map +1 -7
- package/build/components/header/undo-redo/undo.cjs +29 -51
- package/build/components/header/undo-redo/undo.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/config.cjs +88 -85
- package/build/components/keyboard-shortcut-help-modal/config.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs +40 -57
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/index.cjs +94 -161
- package/build/components/keyboard-shortcut-help-modal/index.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/shortcut.cjs +38 -75
- package/build/components/keyboard-shortcut-help-modal/shortcut.cjs.map +1 -7
- package/build/components/keyboard-shortcuts/index.cjs +107 -140
- package/build/components/keyboard-shortcuts/index.cjs.map +1 -7
- package/build/components/layout/index.cjs +65 -74
- package/build/components/layout/index.cjs.map +1 -7
- package/build/components/layout/interface.cjs +82 -108
- package/build/components/layout/interface.cjs.map +1 -7
- package/build/components/layout/unsaved-changes-warning.cjs +41 -48
- package/build/components/layout/unsaved-changes-warning.cjs.map +1 -7
- package/build/components/more-menu/index.cjs +124 -191
- package/build/components/more-menu/index.cjs.map +1 -7
- package/build/components/more-menu/tools-more-menu-group.cjs +9 -29
- package/build/components/more-menu/tools-more-menu-group.cjs.map +1 -7
- package/build/components/notices/index.cjs +19 -39
- package/build/components/notices/index.cjs.map +1 -7
- package/build/components/save-button/index.cjs +31 -58
- package/build/components/save-button/index.cjs.map +1 -7
- package/build/components/secondary-sidebar/index.cjs +38 -45
- package/build/components/secondary-sidebar/index.cjs.map +1 -7
- package/build/components/secondary-sidebar/inserter-sidebar.cjs +50 -51
- package/build/components/secondary-sidebar/inserter-sidebar.cjs.map +1 -7
- package/build/components/secondary-sidebar/list-view-sidebar.cjs +51 -82
- package/build/components/secondary-sidebar/list-view-sidebar.cjs.map +1 -7
- package/build/components/sidebar/index.cjs +117 -180
- package/build/components/sidebar/index.cjs.map +1 -7
- package/build/components/sidebar/widget-areas.cjs +43 -85
- package/build/components/sidebar/widget-areas.cjs.map +1 -7
- package/build/components/welcome-guide/index.cjs +110 -186
- package/build/components/welcome-guide/index.cjs.map +1 -7
- package/build/components/widget-areas-block-editor-content/index.cjs +59 -64
- package/build/components/widget-areas-block-editor-content/index.cjs.map +1 -7
- package/build/components/widget-areas-block-editor-provider/index.cjs +105 -140
- package/build/components/widget-areas-block-editor-provider/index.cjs.map +1 -7
- package/build/constants.cjs +11 -32
- package/build/constants.cjs.map +1 -7
- package/build/filters/index.cjs +7 -4
- package/build/filters/move-to-widget-area.cjs +38 -53
- package/build/filters/move-to-widget-area.cjs.map +1 -7
- package/build/filters/replace-media-upload.cjs +11 -9
- package/build/filters/replace-media-upload.cjs.map +1 -7
- package/build/hooks/use-last-selected-widget-area.cjs +28 -49
- package/build/hooks/use-last-selected-widget-area.cjs.map +1 -7
- package/build/hooks/use-widget-library-insertion-point.cjs +33 -67
- package/build/hooks/use-widget-library-insertion-point.cjs.map +1 -7
- package/build/index.cjs +96 -97
- package/build/index.cjs.map +1 -7
- package/build/lock-unlock.cjs +10 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/store/actions.cjs +276 -278
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +12 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +61 -52
- package/build/store/index.cjs.map +1 -7
- package/build/store/private-selectors.cjs +11 -32
- package/build/store/private-selectors.cjs.map +1 -7
- package/build/store/reducer.cjs +107 -88
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/resolvers.cjs +60 -91
- package/build/store/resolvers.cjs.map +1 -7
- package/build/store/selectors.cjs +196 -229
- package/build/store/selectors.cjs.map +1 -7
- package/build/store/transformers.cjs +51 -82
- package/build/store/transformers.cjs.map +1 -7
- package/build/store/utils.cjs +76 -63
- package/build/store/utils.cjs.map +1 -7
- package/build-module/blocks/widget-area/edit/index.mjs +82 -94
- package/build-module/blocks/widget-area/edit/index.mjs.map +1 -7
- package/build-module/blocks/widget-area/edit/inner-blocks.mjs +19 -35
- package/build-module/blocks/widget-area/edit/inner-blocks.mjs.map +1 -7
- package/build-module/blocks/widget-area/edit/use-is-dragging-within.mjs +36 -33
- package/build-module/blocks/widget-area/edit/use-is-dragging-within.mjs.map +1 -7
- package/build-module/blocks/widget-area/index.mjs +12 -15
- package/build-module/blocks/widget-area/index.mjs.map +1 -7
- package/build-module/components/error-boundary/index.mjs +104 -129
- package/build-module/components/error-boundary/index.mjs.map +1 -7
- package/build-module/components/header/document-tools/index.mjs +51 -84
- package/build-module/components/header/document-tools/index.mjs.map +1 -7
- package/build-module/components/header/index.mjs +44 -47
- package/build-module/components/header/index.mjs.map +1 -7
- package/build-module/components/header/undo-redo/redo.mjs +20 -27
- package/build-module/components/header/undo-redo/redo.mjs.map +1 -7
- package/build-module/components/header/undo-redo/undo.mjs +19 -26
- package/build-module/components/header/undo-redo/undo.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/config.mjs +83 -61
- package/build-module/components/keyboard-shortcut-help-modal/config.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs +19 -33
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/index.mjs +67 -136
- package/build-module/components/keyboard-shortcut-help-modal/index.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs +32 -54
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs.map +1 -7
- package/build-module/components/keyboard-shortcuts/index.mjs +99 -119
- package/build-module/components/keyboard-shortcuts/index.mjs.map +1 -7
- package/build-module/components/layout/index.mjs +29 -40
- package/build-module/components/layout/index.mjs.map +1 -7
- package/build-module/components/layout/interface.mjs +53 -82
- package/build-module/components/layout/interface.mjs.map +1 -7
- package/build-module/components/layout/unsaved-changes-warning.mjs +35 -27
- package/build-module/components/layout/unsaved-changes-warning.mjs.map +1 -7
- package/build-module/components/more-menu/index.mjs +94 -162
- package/build-module/components/more-menu/index.mjs.map +1 -7
- package/build-module/components/more-menu/tools-more-menu-group.mjs +5 -9
- package/build-module/components/more-menu/tools-more-menu-group.mjs.map +1 -7
- package/build-module/components/notices/index.mjs +12 -17
- package/build-module/components/notices/index.mjs.map +1 -7
- package/build-module/components/save-button/index.mjs +23 -35
- package/build-module/components/save-button/index.mjs.map +1 -7
- package/build-module/components/secondary-sidebar/index.mjs +15 -20
- package/build-module/components/secondary-sidebar/index.mjs.map +1 -7
- package/build-module/components/secondary-sidebar/inserter-sidebar.mjs +27 -25
- package/build-module/components/secondary-sidebar/inserter-sidebar.mjs.map +1 -7
- package/build-module/components/secondary-sidebar/list-view-sidebar.mjs +39 -55
- package/build-module/components/secondary-sidebar/list-view-sidebar.mjs.map +1 -7
- package/build-module/components/sidebar/index.mjs +96 -162
- package/build-module/components/sidebar/index.mjs.map +1 -7
- package/build-module/components/sidebar/widget-areas.mjs +30 -57
- package/build-module/components/sidebar/widget-areas.mjs.map +1 -7
- package/build-module/components/welcome-guide/index.mjs +103 -164
- package/build-module/components/welcome-guide/index.mjs.map +1 -7
- package/build-module/components/widget-areas-block-editor-content/index.mjs +34 -44
- package/build-module/components/widget-areas-block-editor-content/index.mjs.map +1 -7
- package/build-module/components/widget-areas-block-editor-provider/index.mjs +76 -109
- package/build-module/components/widget-areas-block-editor-provider/index.mjs.map +1 -7
- package/build-module/constants.mjs +5 -7
- package/build-module/constants.mjs.map +1 -7
- package/build-module/filters/index.mjs +0 -2
- package/build-module/filters/move-to-widget-area.mjs +28 -48
- package/build-module/filters/move-to-widget-area.mjs.map +1 -7
- package/build-module/filters/replace-media-upload.mjs +5 -8
- package/build-module/filters/replace-media-upload.mjs.map +1 -7
- package/build-module/hooks/use-last-selected-widget-area.mjs +23 -29
- package/build-module/hooks/use-last-selected-widget-area.mjs.map +1 -7
- package/build-module/hooks/use-widget-library-insertion-point.mjs +28 -47
- package/build-module/hooks/use-widget-library-insertion-point.mjs.map +1 -7
- package/build-module/index.mjs +62 -79
- package/build-module/index.mjs.map +1 -7
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/store/actions.mjs +257 -247
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +7 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +18 -16
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/private-selectors.mjs +5 -7
- package/build-module/store/private-selectors.mjs.map +1 -7
- package/build-module/store/reducer.mjs +95 -58
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/resolvers.mjs +52 -71
- package/build-module/store/resolvers.mjs.map +1 -7
- package/build-module/store/selectors.mjs +178 -199
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/store/transformers.mjs +44 -56
- package/build-module/store/transformers.mjs.map +1 -7
- package/build-module/store/utils.mjs +64 -32
- package/build-module/store/utils.mjs.map +1 -7
- package/build-style/style-rtl.css +32 -11
- package/build-style/style.css +32 -11
- package/package.json +33 -33
- package/src/components/error-boundary/index.jsx +2 -2
- package/src/components/header/index.jsx +13 -4
- package/src/components/header/style.scss +30 -3
- package/src/components/keyboard-shortcut-help-modal/shortcut.jsx +1 -0
- package/src/components/keyboard-shortcut-help-modal/style.scss +1 -1
- package/src/components/layout/style.scss +5 -9
- package/src/components/layout/unsaved-changes-warning.js +4 -9
- package/src/components/more-menu/index.jsx +0 -1
- package/src/components/sidebar/index.jsx +18 -18
- package/src/components/welcome-guide/index.jsx +4 -2
- package/src/store/actions.js +25 -2
- package/src/store/test/actions.jsdom.test.js +230 -0
- package/build/filters/index.cjs.map +0 -7
- package/build-module/filters/index.mjs.map +0 -7
|
@@ -20,20 +20,20 @@ import WidgetAreas from './widget-areas';
|
|
|
20
20
|
import { store as editWidgetsStore } from '../../store';
|
|
21
21
|
import { unlock } from '../../lock-unlock';
|
|
22
22
|
|
|
23
|
-
const { Tabs } = unlock( componentsPrivateApis );
|
|
23
|
+
const { Tabs: WCTabs } = unlock( componentsPrivateApis );
|
|
24
24
|
|
|
25
25
|
function SidebarHeader( { selectedWidgetAreaBlock } ) {
|
|
26
26
|
return (
|
|
27
|
-
<
|
|
28
|
-
<
|
|
27
|
+
<WCTabs.TabList>
|
|
28
|
+
<WCTabs.Tab tabId={ WIDGET_AREAS_IDENTIFIER }>
|
|
29
29
|
{ selectedWidgetAreaBlock
|
|
30
30
|
? selectedWidgetAreaBlock.attributes.name
|
|
31
31
|
: __( 'Widget Areas' ) }
|
|
32
|
-
</
|
|
33
|
-
<
|
|
32
|
+
</WCTabs.Tab>
|
|
33
|
+
<WCTabs.Tab tabId={ BLOCK_INSPECTOR_IDENTIFIER }>
|
|
34
34
|
{ __( 'Block' ) }
|
|
35
|
-
</
|
|
36
|
-
</
|
|
35
|
+
</WCTabs.Tab>
|
|
36
|
+
</WCTabs.TabList>
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -71,17 +71,17 @@ function SidebarContent( {
|
|
|
71
71
|
// block selection changes, not sidebar state changes.
|
|
72
72
|
}, [ hasSelectedNonAreaBlock, enableComplementaryArea ] );
|
|
73
73
|
|
|
74
|
-
const tabsContextValue = useContext(
|
|
74
|
+
const tabsContextValue = useContext( WCTabs.Context );
|
|
75
75
|
|
|
76
76
|
return (
|
|
77
77
|
<ComplementaryArea
|
|
78
78
|
className="edit-widgets-sidebar"
|
|
79
79
|
header={
|
|
80
|
-
<
|
|
80
|
+
<WCTabs.Context.Provider value={ tabsContextValue }>
|
|
81
81
|
<SidebarHeader
|
|
82
82
|
selectedWidgetAreaBlock={ selectedWidgetAreaBlock }
|
|
83
83
|
/>
|
|
84
|
-
</
|
|
84
|
+
</WCTabs.Context.Provider>
|
|
85
85
|
}
|
|
86
86
|
headerClassName="edit-widgets-sidebar__panel-tabs"
|
|
87
87
|
/* translators: button label text should, if possible, be under 16 characters. */
|
|
@@ -92,8 +92,8 @@ function SidebarContent( {
|
|
|
92
92
|
icon={ isRTL() ? drawerLeft : drawerRight }
|
|
93
93
|
isActiveByDefault={ SIDEBAR_ACTIVE_BY_DEFAULT }
|
|
94
94
|
>
|
|
95
|
-
<
|
|
96
|
-
<
|
|
95
|
+
<WCTabs.Context.Provider value={ tabsContextValue }>
|
|
96
|
+
<WCTabs.TabPanel
|
|
97
97
|
tabId={ WIDGET_AREAS_IDENTIFIER }
|
|
98
98
|
focusable={ false }
|
|
99
99
|
>
|
|
@@ -102,8 +102,8 @@ function SidebarContent( {
|
|
|
102
102
|
selectedWidgetAreaBlock?.attributes.id
|
|
103
103
|
}
|
|
104
104
|
/>
|
|
105
|
-
</
|
|
106
|
-
<
|
|
105
|
+
</WCTabs.TabPanel>
|
|
106
|
+
<WCTabs.TabPanel
|
|
107
107
|
tabId={ BLOCK_INSPECTOR_IDENTIFIER }
|
|
108
108
|
focusable={ false }
|
|
109
109
|
>
|
|
@@ -116,8 +116,8 @@ function SidebarContent( {
|
|
|
116
116
|
{ __( 'No block selected.' ) }
|
|
117
117
|
</span>
|
|
118
118
|
) }
|
|
119
|
-
</
|
|
120
|
-
</
|
|
119
|
+
</WCTabs.TabPanel>
|
|
120
|
+
</WCTabs.Context.Provider>
|
|
121
121
|
</ComplementaryArea>
|
|
122
122
|
);
|
|
123
123
|
}
|
|
@@ -189,7 +189,7 @@ export default function Sidebar() {
|
|
|
189
189
|
);
|
|
190
190
|
|
|
191
191
|
return (
|
|
192
|
-
<
|
|
192
|
+
<WCTabs
|
|
193
193
|
// Due to how this component is controlled (via a value from the
|
|
194
194
|
// `interfaceStore`), when the sidebar closes the currently selected
|
|
195
195
|
// tab can't be found. This causes the component to continuously reset
|
|
@@ -205,6 +205,6 @@ export default function Sidebar() {
|
|
|
205
205
|
isGeneralSidebarOpen={ isGeneralSidebarOpen }
|
|
206
206
|
selectedWidgetAreaBlock={ selectedWidgetAreaBlock }
|
|
207
207
|
/>
|
|
208
|
-
</
|
|
208
|
+
</WCTabs>
|
|
209
209
|
);
|
|
210
210
|
}
|
|
@@ -15,7 +15,7 @@ export default function WelcomeGuide() {
|
|
|
15
15
|
[]
|
|
16
16
|
);
|
|
17
17
|
|
|
18
|
-
const {
|
|
18
|
+
const { set: setPreference } = useDispatch( preferencesStore );
|
|
19
19
|
|
|
20
20
|
const widgetAreas = useSelect(
|
|
21
21
|
( select ) =>
|
|
@@ -45,7 +45,9 @@ export default function WelcomeGuide() {
|
|
|
45
45
|
className="edit-widgets-welcome-guide"
|
|
46
46
|
contentLabel={ __( 'Welcome to block Widgets' ) }
|
|
47
47
|
finishButtonText={ __( 'Get started' ) }
|
|
48
|
-
onFinish={ () =>
|
|
48
|
+
onFinish={ () =>
|
|
49
|
+
setPreference( 'core/edit-widgets', 'welcomeGuide', false )
|
|
50
|
+
}
|
|
49
51
|
pages={ [
|
|
50
52
|
{
|
|
51
53
|
image: (
|
package/src/store/actions.js
CHANGED
|
@@ -155,9 +155,32 @@ export const saveWidgetArea =
|
|
|
155
155
|
const batchMeta = [];
|
|
156
156
|
const batchTasks = [];
|
|
157
157
|
const sidebarWidgetsIds = [];
|
|
158
|
+
const claimedWidgetIds = new Set();
|
|
158
159
|
for ( let i = 0; i < widgetsBlocks.length; i++ ) {
|
|
159
160
|
const block = widgetsBlocks[ i ];
|
|
160
|
-
|
|
161
|
+
let widgetId = getWidgetIdFromBlock( block );
|
|
162
|
+
|
|
163
|
+
// Splitting a block, e.g. pressing Enter in the middle of a
|
|
164
|
+
// paragraph, copies all of its attributes to the new block,
|
|
165
|
+
// including the widget ID, and the new block can then be moved to
|
|
166
|
+
// another widget area. Only the first block with a given ID, in the
|
|
167
|
+
// first widget area that holds it, updates that widget. Any other
|
|
168
|
+
// block with the same ID is saved as a new widget.
|
|
169
|
+
if ( widgetId ) {
|
|
170
|
+
if (
|
|
171
|
+
claimedWidgetIds.has( widgetId ) ||
|
|
172
|
+
select.getWidgetAreaForWidgetId( widgetId )?.id !==
|
|
173
|
+
widgetAreaId
|
|
174
|
+
) {
|
|
175
|
+
widgetId = undefined;
|
|
176
|
+
// Drop the duplicate ID now, so nothing reads it before the
|
|
177
|
+
// new widget's ID is written back after the batch.
|
|
178
|
+
delete block.attributes.__internalWidgetId;
|
|
179
|
+
} else {
|
|
180
|
+
claimedWidgetIds.add( widgetId );
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
161
184
|
const oldWidget = widgets[ widgetId ];
|
|
162
185
|
const widget = transformBlockToWidget( block, oldWidget );
|
|
163
186
|
|
|
@@ -230,7 +253,7 @@ export const saveWidgetArea =
|
|
|
230
253
|
|
|
231
254
|
// Set __internalWidgetId on the block. This will be persisted to the
|
|
232
255
|
// store when we dispatch receiveEntityRecords( post ) below.
|
|
233
|
-
|
|
256
|
+
block.attributes.__internalWidgetId = widget.id;
|
|
234
257
|
|
|
235
258
|
const error = registry
|
|
236
259
|
.select( coreStore )
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { saveWidgetArea } from '../actions';
|
|
3
|
+
|
|
4
|
+
// Only the store descriptors are imported from these packages; stub them so
|
|
5
|
+
// their browser-only side effects do not run.
|
|
6
|
+
vi.mock( import( '@wordpress/interface' ), () => ( {
|
|
7
|
+
store: 'core/interface',
|
|
8
|
+
} ) );
|
|
9
|
+
vi.mock( import( '@wordpress/block-editor' ), () => ( {
|
|
10
|
+
store: 'core/block-editor',
|
|
11
|
+
} ) );
|
|
12
|
+
vi.mock( import( '@wordpress/notices' ), () => ( { store: 'core/notices' } ) );
|
|
13
|
+
|
|
14
|
+
vi.mock( import( '../transformers' ), () => ( {
|
|
15
|
+
transformBlockToWidget: ( block, relatedWidget = {} ) => ( {
|
|
16
|
+
...relatedWidget,
|
|
17
|
+
id_base: 'block',
|
|
18
|
+
instance: { raw: { content: block.attributes.content } },
|
|
19
|
+
} ),
|
|
20
|
+
} ) );
|
|
21
|
+
|
|
22
|
+
function setup(
|
|
23
|
+
blocks,
|
|
24
|
+
widgets,
|
|
25
|
+
{ area = 'sidebar-1', areaHoldingId = 'sidebar-1' } = {}
|
|
26
|
+
) {
|
|
27
|
+
let nextWidgetNumber = 10;
|
|
28
|
+
const saveEntityRecord = vi.fn( () => ( {
|
|
29
|
+
id: `block-${ nextWidgetNumber++ }`,
|
|
30
|
+
} ) );
|
|
31
|
+
const saveEditedEntityRecord = vi.fn( ( kind, name, id ) => ( { id } ) );
|
|
32
|
+
const coreDispatch = {
|
|
33
|
+
editEntityRecord: vi.fn(),
|
|
34
|
+
receiveEntityRecords: vi.fn(),
|
|
35
|
+
saveEditedEntityRecord: vi.fn(),
|
|
36
|
+
__experimentalBatch: vi.fn( async ( tasks ) =>
|
|
37
|
+
Promise.all(
|
|
38
|
+
tasks.map( ( task ) =>
|
|
39
|
+
task( { saveEntityRecord, saveEditedEntityRecord } )
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
),
|
|
43
|
+
};
|
|
44
|
+
const coreSelect = {
|
|
45
|
+
getEditedEntityRecord: () => ( { blocks } ),
|
|
46
|
+
hasEditsForEntityRecord: () => true,
|
|
47
|
+
getLastEntitySaveError: () => undefined,
|
|
48
|
+
};
|
|
49
|
+
const registry = {
|
|
50
|
+
select: () => coreSelect,
|
|
51
|
+
dispatch: () => coreDispatch,
|
|
52
|
+
};
|
|
53
|
+
const select = {
|
|
54
|
+
getWidgets: () => widgets,
|
|
55
|
+
getWidgetAreaForWidgetId: () => ( { id: areaHoldingId } ),
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
run: () =>
|
|
59
|
+
saveWidgetArea( area )( {
|
|
60
|
+
dispatch: vi.fn(),
|
|
61
|
+
select,
|
|
62
|
+
registry,
|
|
63
|
+
} ),
|
|
64
|
+
coreDispatch,
|
|
65
|
+
saveEntityRecord,
|
|
66
|
+
saveEditedEntityRecord,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
describe( 'saveWidgetArea', () => {
|
|
71
|
+
it( 'saves a block that shares an existing widget ID with an earlier block as a new widget', async () => {
|
|
72
|
+
// Splitting a paragraph widget copies the block's attributes,
|
|
73
|
+
// including `__internalWidgetId`, to the new block.
|
|
74
|
+
const blocks = [
|
|
75
|
+
{
|
|
76
|
+
name: 'core/paragraph',
|
|
77
|
+
clientId: 'head',
|
|
78
|
+
attributes: { content: 'Hello', __internalWidgetId: 'block-2' },
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: 'core/paragraph',
|
|
82
|
+
clientId: 'tail',
|
|
83
|
+
attributes: { content: 'world', __internalWidgetId: 'block-2' },
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
const widgets = {
|
|
87
|
+
'block-2': {
|
|
88
|
+
id: 'block-2',
|
|
89
|
+
id_base: 'block',
|
|
90
|
+
sidebar: 'sidebar-1',
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
const { run, coreDispatch, saveEntityRecord, saveEditedEntityRecord } =
|
|
94
|
+
setup( blocks, widgets );
|
|
95
|
+
|
|
96
|
+
await run();
|
|
97
|
+
|
|
98
|
+
const widgetEdits = coreDispatch.editEntityRecord.mock.calls.filter(
|
|
99
|
+
( [ kind, name ] ) => kind === 'root' && name === 'widget'
|
|
100
|
+
);
|
|
101
|
+
expect( widgetEdits ).toHaveLength( 1 );
|
|
102
|
+
expect( widgetEdits[ 0 ][ 3 ].instance.raw.content ).toBe( 'Hello' );
|
|
103
|
+
expect( saveEditedEntityRecord ).toHaveBeenCalledTimes( 1 );
|
|
104
|
+
expect( saveEntityRecord ).toHaveBeenCalledTimes( 1 );
|
|
105
|
+
expect( saveEntityRecord.mock.calls[ 0 ][ 2 ] ).toMatchObject( {
|
|
106
|
+
sidebar: 'sidebar-1',
|
|
107
|
+
instance: { raw: { content: 'world' } },
|
|
108
|
+
} );
|
|
109
|
+
|
|
110
|
+
expect( coreDispatch.editEntityRecord ).toHaveBeenCalledWith(
|
|
111
|
+
'root',
|
|
112
|
+
'sidebar',
|
|
113
|
+
'sidebar-1',
|
|
114
|
+
{ widgets: [ 'block-2', 'block-10' ] },
|
|
115
|
+
{ undoIgnore: true }
|
|
116
|
+
);
|
|
117
|
+
expect( blocks[ 1 ].attributes.__internalWidgetId ).toBe( 'block-10' );
|
|
118
|
+
} );
|
|
119
|
+
|
|
120
|
+
it( 'keeps updating existing widgets when every block has its own widget ID', async () => {
|
|
121
|
+
const blocks = [
|
|
122
|
+
{
|
|
123
|
+
name: 'core/paragraph',
|
|
124
|
+
clientId: 'a',
|
|
125
|
+
attributes: { content: 'A', __internalWidgetId: 'block-2' },
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: 'core/paragraph',
|
|
129
|
+
clientId: 'b',
|
|
130
|
+
attributes: { content: 'B', __internalWidgetId: 'block-3' },
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
const widgets = {
|
|
134
|
+
'block-2': {
|
|
135
|
+
id: 'block-2',
|
|
136
|
+
id_base: 'block',
|
|
137
|
+
sidebar: 'sidebar-1',
|
|
138
|
+
},
|
|
139
|
+
'block-3': {
|
|
140
|
+
id: 'block-3',
|
|
141
|
+
id_base: 'block',
|
|
142
|
+
sidebar: 'sidebar-1',
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
const { run, coreDispatch, saveEntityRecord, saveEditedEntityRecord } =
|
|
146
|
+
setup( blocks, widgets );
|
|
147
|
+
|
|
148
|
+
await run();
|
|
149
|
+
|
|
150
|
+
expect( saveEntityRecord ).not.toHaveBeenCalled();
|
|
151
|
+
expect( saveEditedEntityRecord ).toHaveBeenCalledTimes( 2 );
|
|
152
|
+
expect( coreDispatch.editEntityRecord ).toHaveBeenCalledWith(
|
|
153
|
+
'root',
|
|
154
|
+
'sidebar',
|
|
155
|
+
'sidebar-1',
|
|
156
|
+
{ widgets: [ 'block-2', 'block-3' ] },
|
|
157
|
+
{ undoIgnore: true }
|
|
158
|
+
);
|
|
159
|
+
} );
|
|
160
|
+
|
|
161
|
+
it( 'saves a block as a new widget when an earlier widget area holds the same widget ID', async () => {
|
|
162
|
+
// The new block from a split was moved to another widget area, so both
|
|
163
|
+
// areas hold a block with `block-2`. The first area keeps the widget.
|
|
164
|
+
const blocks = [
|
|
165
|
+
{
|
|
166
|
+
name: 'core/paragraph',
|
|
167
|
+
clientId: 'tail',
|
|
168
|
+
attributes: { content: 'world', __internalWidgetId: 'block-2' },
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
const widgets = {
|
|
172
|
+
'block-2': {
|
|
173
|
+
id: 'block-2',
|
|
174
|
+
id_base: 'block',
|
|
175
|
+
sidebar: 'sidebar-1',
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
const { run, coreDispatch, saveEntityRecord, saveEditedEntityRecord } =
|
|
179
|
+
setup( blocks, widgets, {
|
|
180
|
+
area: 'sidebar-2',
|
|
181
|
+
areaHoldingId: 'sidebar-1',
|
|
182
|
+
} );
|
|
183
|
+
|
|
184
|
+
await run();
|
|
185
|
+
|
|
186
|
+
expect( saveEditedEntityRecord ).not.toHaveBeenCalled();
|
|
187
|
+
expect( saveEntityRecord ).toHaveBeenCalledTimes( 1 );
|
|
188
|
+
expect( saveEntityRecord.mock.calls[ 0 ][ 2 ] ).toMatchObject( {
|
|
189
|
+
sidebar: 'sidebar-2',
|
|
190
|
+
} );
|
|
191
|
+
expect( coreDispatch.editEntityRecord ).toHaveBeenCalledWith(
|
|
192
|
+
'root',
|
|
193
|
+
'sidebar',
|
|
194
|
+
'sidebar-2',
|
|
195
|
+
{ widgets: [ 'block-10' ] },
|
|
196
|
+
{ undoIgnore: true }
|
|
197
|
+
);
|
|
198
|
+
} );
|
|
199
|
+
|
|
200
|
+
it( 'keeps updating a widget that was moved to another widget area', async () => {
|
|
201
|
+
const blocks = [
|
|
202
|
+
{
|
|
203
|
+
name: 'core/paragraph',
|
|
204
|
+
clientId: 'moved',
|
|
205
|
+
attributes: { content: 'Moved', __internalWidgetId: 'block-2' },
|
|
206
|
+
},
|
|
207
|
+
];
|
|
208
|
+
const widgets = {
|
|
209
|
+
'block-2': {
|
|
210
|
+
id: 'block-2',
|
|
211
|
+
id_base: 'block',
|
|
212
|
+
sidebar: 'sidebar-1',
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
const { run, saveEntityRecord, saveEditedEntityRecord } = setup(
|
|
216
|
+
blocks,
|
|
217
|
+
widgets,
|
|
218
|
+
{ area: 'sidebar-2', areaHoldingId: 'sidebar-2' }
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
await run();
|
|
222
|
+
|
|
223
|
+
expect( saveEntityRecord ).not.toHaveBeenCalled();
|
|
224
|
+
expect( saveEditedEntityRecord ).toHaveBeenCalledWith(
|
|
225
|
+
'root',
|
|
226
|
+
'widget',
|
|
227
|
+
'block-2'
|
|
228
|
+
);
|
|
229
|
+
} );
|
|
230
|
+
} );
|