@wordpress/edit-widgets 5.11.0 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/blocks/widget-area/edit/index.js +24 -29
- package/build/blocks/widget-area/edit/index.js.map +1 -1
- package/build/blocks/widget-area/edit/inner-blocks.js +3 -4
- package/build/blocks/widget-area/edit/inner-blocks.js.map +1 -1
- package/build/blocks/widget-area/index.js +3 -6
- package/build/blocks/widget-area/index.js.map +1 -1
- package/build/components/error-boundary/index.js +8 -10
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +3 -4
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +41 -50
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/shortcut.js +10 -12
- package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build/components/layout/index.js +3 -4
- package/build/components/layout/index.js.map +1 -1
- package/build/components/layout/interface.js +3 -4
- package/build/components/layout/interface.js.map +1 -1
- package/build/components/layout/unsaved-changes-warning.js +1 -1
- package/build/components/layout/unsaved-changes-warning.js.map +1 -1
- package/build/components/more-menu/tools-more-menu-group.js +5 -8
- package/build/components/more-menu/tools-more-menu-group.js.map +1 -1
- package/build/components/notices/index.js +11 -20
- package/build/components/notices/index.js.map +1 -1
- package/build/components/save-button/index.js +1 -3
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/secondary-sidebar/list-view-sidebar.js +8 -3
- package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build/components/sidebar/index.js +7 -8
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/sidebar/widget-areas.js +5 -6
- package/build/components/sidebar/widget-areas.js.map +1 -1
- package/build/components/welcome-guide/index.js +6 -7
- package/build/components/welcome-guide/index.js.map +1 -1
- package/build/components/widget-areas-block-editor-content/index.js +3 -4
- package/build/components/widget-areas-block-editor-content/index.js.map +1 -1
- package/build/components/widget-areas-block-editor-provider/index.js +12 -17
- package/build/components/widget-areas-block-editor-provider/index.js.map +1 -1
- package/build/filters/move-to-widget-area.js +2 -4
- package/build/filters/move-to-widget-area.js.map +1 -1
- package/build/hooks/use-last-selected-widget-area.js +2 -4
- package/build/hooks/use-last-selected-widget-area.js.map +1 -1
- package/build/hooks/use-widget-library-insertion-point.js +1 -3
- package/build/hooks/use-widget-library-insertion-point.js.map +1 -1
- package/build/store/actions.js +49 -74
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +1 -3
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +3 -11
- package/build/store/reducer.js.map +1 -1
- package/build/store/resolvers.js +8 -10
- package/build/store/resolvers.js.map +1 -1
- package/build/store/selectors.js +15 -32
- package/build/store/selectors.js.map +1 -1
- package/build/store/transformers.js +1 -2
- package/build/store/transformers.js.map +1 -1
- package/build-module/blocks/widget-area/edit/index.js +24 -29
- package/build-module/blocks/widget-area/edit/index.js.map +1 -1
- package/build-module/blocks/widget-area/edit/inner-blocks.js +3 -4
- package/build-module/blocks/widget-area/edit/inner-blocks.js.map +1 -1
- package/build-module/blocks/widget-area/index.js +3 -6
- package/build-module/blocks/widget-area/index.js.map +1 -1
- package/build-module/components/error-boundary/index.js +8 -10
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +3 -4
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +39 -48
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js +10 -12
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build-module/components/layout/index.js +3 -4
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/layout/interface.js +3 -4
- package/build-module/components/layout/interface.js.map +1 -1
- package/build-module/components/layout/unsaved-changes-warning.js +1 -1
- package/build-module/components/layout/unsaved-changes-warning.js.map +1 -1
- package/build-module/components/more-menu/tools-more-menu-group.js +5 -8
- package/build-module/components/more-menu/tools-more-menu-group.js.map +1 -1
- package/build-module/components/notices/index.js +11 -20
- package/build-module/components/notices/index.js.map +1 -1
- package/build-module/components/save-button/index.js +1 -3
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/secondary-sidebar/list-view-sidebar.js +9 -3
- package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build-module/components/sidebar/index.js +9 -10
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/sidebar/widget-areas.js +5 -6
- package/build-module/components/sidebar/widget-areas.js.map +1 -1
- package/build-module/components/welcome-guide/index.js +6 -7
- package/build-module/components/welcome-guide/index.js.map +1 -1
- package/build-module/components/widget-areas-block-editor-content/index.js +3 -4
- package/build-module/components/widget-areas-block-editor-content/index.js.map +1 -1
- package/build-module/components/widget-areas-block-editor-provider/index.js +12 -17
- package/build-module/components/widget-areas-block-editor-provider/index.js.map +1 -1
- package/build-module/filters/move-to-widget-area.js +2 -4
- package/build-module/filters/move-to-widget-area.js.map +1 -1
- package/build-module/hooks/use-last-selected-widget-area.js +2 -4
- package/build-module/hooks/use-last-selected-widget-area.js.map +1 -1
- package/build-module/hooks/use-widget-library-insertion-point.js +1 -3
- package/build-module/hooks/use-widget-library-insertion-point.js.map +1 -1
- package/build-module/store/actions.js +49 -74
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +1 -3
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +3 -11
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/resolvers.js +8 -10
- package/build-module/store/resolvers.js.map +1 -1
- package/build-module/store/selectors.js +15 -32
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/transformers.js +1 -2
- package/build-module/store/transformers.js.map +1 -1
- package/package.json +27 -27
- package/src/components/secondary-sidebar/list-view-sidebar.js +8 -1
- package/src/components/sidebar/index.js +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/hooks/use-widget-library-insertion-point.js"],"names":["useWidgetLibraryInsertionPoint","firstRootId","select","getEntityRecord","coreStore","widgetAreasPost","KIND","POST_TYPE","blocks","clientId","getBlockRootClientId","getBlockSelectionEnd","getBlockOrder","getBlockIndex","blockEditorStore","insertionPoint","editWidgetsStore","__experimentalGetInsertionPoint","rootClientId","insertionIndex","length"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AAXA;AACA;AACA;;AAKA;AACA;AACA;AAIA,MAAMA,8BAA8B,GAAG,MAAM;AAC5C,QAAMC,WAAW,GAAG,qBAAaC,MAAF,IAAc;
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/hooks/use-widget-library-insertion-point.js"],"names":["useWidgetLibraryInsertionPoint","firstRootId","select","getEntityRecord","coreStore","widgetAreasPost","KIND","POST_TYPE","blocks","clientId","getBlockRootClientId","getBlockSelectionEnd","getBlockOrder","getBlockIndex","blockEditorStore","insertionPoint","editWidgetsStore","__experimentalGetInsertionPoint","rootClientId","insertionIndex","length"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AAXA;AACA;AACA;;AAKA;AACA;AACA;AAIA,MAAMA,8BAA8B,GAAG,MAAM;AAC5C,QAAMC,WAAW,GAAG,qBAAaC,MAAF,IAAc;AAC5C;AACA,UAAM;AAAEC,MAAAA;AAAF,QAAsBD,MAAM,CAAEE,eAAF,CAAlC;AACA,UAAMC,eAAe,GAAGF,eAAe,CACtCG,WADsC,EAEtCC,gBAFsC,EAGtC,oCAHsC,CAAvC;AAKA,WAAOF,eAAe,EAAEG,MAAjB,CAAyB,CAAzB,GAA8BC,QAArC;AACA,GATmB,EASjB,EATiB,CAApB;AAWA,SAAO,qBACJP,MAAF,IAAc;AACb,UAAM;AACLQ,MAAAA,oBADK;AAELC,MAAAA,oBAFK;AAGLC,MAAAA,aAHK;AAILC,MAAAA;AAJK,QAKFX,MAAM,CAAEY,kBAAF,CALV;;AAOA,UAAMC,cAAc,GACnBb,MAAM,CAAEc,YAAF,CAAN,CAA2BC,+BAA3B,EADD,CARa,CAWb;AACA;;;AACA,QAAKF,cAAc,CAACG,YAApB,EAAmC;AAClC,aAAOH,cAAP;AACA;;AAED,UAAMN,QAAQ,GAAGE,oBAAoB,MAAMV,WAA3C;AACA,UAAMiB,YAAY,GAAGR,oBAAoB,CAAED,QAAF,CAAzC,CAlBa,CAoBb;AACA;AACA;;AACA,QAAKA,QAAQ,IAAIS,YAAY,KAAK,EAAlC,EAAuC;AACtC,aAAO;AACNA,QAAAA,YAAY,EAAET,QADR;AAENU,QAAAA,cAAc,EAAEP,aAAa,CAAEH,QAAF,CAAb,CAA0BW;AAFpC,OAAP;AAIA;;AAED,WAAO;AACNF,MAAAA,YADM;AAENC,MAAAA,cAAc,EAAEN,aAAa,CAAEJ,QAAF,CAAb,GAA4B;AAFtC,KAAP;AAIA,GAnCK,EAoCN,CAAER,WAAF,CApCM,CAAP;AAsCA,CAlDD;;eAoDeD,8B","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editWidgetsStore } from '../store';\nimport { buildWidgetAreasPostId, KIND, POST_TYPE } from '../store/utils';\n\nconst useWidgetLibraryInsertionPoint = () => {\n\tconst firstRootId = useSelect( ( select ) => {\n\t\t// Default to the first widget area\n\t\tconst { getEntityRecord } = select( coreStore );\n\t\tconst widgetAreasPost = getEntityRecord(\n\t\t\tKIND,\n\t\t\tPOST_TYPE,\n\t\t\tbuildWidgetAreasPostId()\n\t\t);\n\t\treturn widgetAreasPost?.blocks[ 0 ]?.clientId;\n\t}, [] );\n\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\tgetBlockSelectionEnd,\n\t\t\t\tgetBlockOrder,\n\t\t\t\tgetBlockIndex,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst insertionPoint =\n\t\t\t\tselect( editWidgetsStore ).__experimentalGetInsertionPoint();\n\n\t\t\t// \"Browse all\" in the quick inserter will set the rootClientId to the current block.\n\t\t\t// Otherwise, it will just be undefined, and we'll have to handle it differently below.\n\t\t\tif ( insertionPoint.rootClientId ) {\n\t\t\t\treturn insertionPoint;\n\t\t\t}\n\n\t\t\tconst clientId = getBlockSelectionEnd() || firstRootId;\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\t// If the selected block is at the root level, it's a widget area and\n\t\t\t// blocks can't be inserted here. Return this block as the root and the\n\t\t\t// last child clientId indicating insertion at the end.\n\t\t\tif ( clientId && rootClientId === '' ) {\n\t\t\t\treturn {\n\t\t\t\t\trootClientId: clientId,\n\t\t\t\t\tinsertionIndex: getBlockOrder( clientId ).length,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\trootClientId,\n\t\t\t\tinsertionIndex: getBlockIndex( clientId ) + 1,\n\t\t\t};\n\t\t},\n\t\t[ firstRootId ]\n\t);\n};\n\nexport default useWidgetLibraryInsertionPoint;\n"]}
|
package/build/store/actions.js
CHANGED
|
@@ -44,10 +44,9 @@ var _constants = require("./constants");
|
|
|
44
44
|
* @param {Array} blocks Blocks the post should consist of.
|
|
45
45
|
* @return {Object} The post object.
|
|
46
46
|
*/
|
|
47
|
-
const persistStubPost = (id, blocks) =>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} = _ref;
|
|
47
|
+
const persistStubPost = (id, blocks) => ({
|
|
48
|
+
registry
|
|
49
|
+
}) => {
|
|
51
50
|
const stubPost = (0, _utils.createStubPost)(id, blocks);
|
|
52
51
|
registry.dispatch(_coreData.store).receiveEntityRecords(_utils.KIND, _utils.POST_TYPE, stubPost, {
|
|
53
52
|
id: stubPost.id
|
|
@@ -66,15 +65,14 @@ const persistStubPost = (id, blocks) => _ref => {
|
|
|
66
65
|
|
|
67
66
|
exports.persistStubPost = persistStubPost;
|
|
68
67
|
|
|
69
|
-
const saveEditedWidgetAreas = () => async
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
} = _ref2;
|
|
68
|
+
const saveEditedWidgetAreas = () => async ({
|
|
69
|
+
select,
|
|
70
|
+
dispatch,
|
|
71
|
+
registry
|
|
72
|
+
}) => {
|
|
75
73
|
const editedWidgetAreas = select.getEditedWidgetAreas();
|
|
76
74
|
|
|
77
|
-
if (!
|
|
75
|
+
if (!editedWidgetAreas?.length) {
|
|
78
76
|
return;
|
|
79
77
|
}
|
|
80
78
|
|
|
@@ -102,12 +100,10 @@ const saveEditedWidgetAreas = () => async _ref2 => {
|
|
|
102
100
|
|
|
103
101
|
exports.saveEditedWidgetAreas = saveEditedWidgetAreas;
|
|
104
102
|
|
|
105
|
-
const saveWidgetAreas = widgetAreas => async
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
} = _ref3;
|
|
110
|
-
|
|
103
|
+
const saveWidgetAreas = widgetAreas => async ({
|
|
104
|
+
dispatch,
|
|
105
|
+
registry
|
|
106
|
+
}) => {
|
|
111
107
|
try {
|
|
112
108
|
for (const widgetArea of widgetAreas) {
|
|
113
109
|
await dispatch.saveWidgetArea(widgetArea.id);
|
|
@@ -128,21 +124,17 @@ const saveWidgetAreas = widgetAreas => async _ref3 => {
|
|
|
128
124
|
|
|
129
125
|
exports.saveWidgetAreas = saveWidgetAreas;
|
|
130
126
|
|
|
131
|
-
const saveWidgetArea = widgetAreaId => async
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
} = _ref4;
|
|
127
|
+
const saveWidgetArea = widgetAreaId => async ({
|
|
128
|
+
dispatch,
|
|
129
|
+
select,
|
|
130
|
+
registry
|
|
131
|
+
}) => {
|
|
137
132
|
const widgets = select.getWidgets();
|
|
138
133
|
const post = registry.select(_coreData.store).getEditedEntityRecord(_utils.KIND, _utils.POST_TYPE, (0, _utils.buildWidgetAreaPostId)(widgetAreaId)); // Get all widgets from this area
|
|
139
134
|
|
|
140
|
-
const areaWidgets = Object.values(widgets).filter(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
} = _ref5;
|
|
144
|
-
return sidebar === widgetAreaId;
|
|
145
|
-
}); // Remove all duplicate reference widget instances for legacy widgets.
|
|
135
|
+
const areaWidgets = Object.values(widgets).filter(({
|
|
136
|
+
sidebar
|
|
137
|
+
}) => sidebar === widgetAreaId); // Remove all duplicate reference widget instances for legacy widgets.
|
|
146
138
|
// Why? We filter out the widgets with duplicate IDs to prevent adding more than one instance of a widget
|
|
147
139
|
// implemented using a function. WordPress doesn't support having more than one instance of these, if you try to
|
|
148
140
|
// save multiple instances of these in different sidebars you will run into undefined behaviors.
|
|
@@ -203,22 +195,16 @@ const saveWidgetArea = widgetAreaId => async _ref4 => {
|
|
|
203
195
|
continue;
|
|
204
196
|
}
|
|
205
197
|
|
|
206
|
-
batchTasks.push(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
} = _ref6;
|
|
210
|
-
return saveEditedEntityRecord('root', 'widget', widgetId);
|
|
211
|
-
});
|
|
198
|
+
batchTasks.push(({
|
|
199
|
+
saveEditedEntityRecord
|
|
200
|
+
}) => saveEditedEntityRecord('root', 'widget', widgetId));
|
|
212
201
|
} else {
|
|
213
202
|
// Create a new widget.
|
|
214
|
-
batchTasks.push(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
sidebar: widgetAreaId
|
|
220
|
-
});
|
|
221
|
-
});
|
|
203
|
+
batchTasks.push(({
|
|
204
|
+
saveEntityRecord
|
|
205
|
+
}) => saveEntityRecord('root', 'widget', { ...widget,
|
|
206
|
+
sidebar: widgetAreaId
|
|
207
|
+
}));
|
|
222
208
|
}
|
|
223
209
|
|
|
224
210
|
batchMeta.push({
|
|
@@ -229,14 +215,11 @@ const saveWidgetArea = widgetAreaId => async _ref4 => {
|
|
|
229
215
|
}
|
|
230
216
|
|
|
231
217
|
for (const widget of deletedWidgets) {
|
|
232
|
-
batchTasks.push(
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
force: true
|
|
238
|
-
});
|
|
239
|
-
});
|
|
218
|
+
batchTasks.push(({
|
|
219
|
+
deleteEntityRecord
|
|
220
|
+
}) => deleteEntityRecord('root', 'widget', widget.id, {
|
|
221
|
+
force: true
|
|
222
|
+
}));
|
|
240
223
|
}
|
|
241
224
|
|
|
242
225
|
const records = await registry.dispatch(_coreData.store).__experimentalBatch(batchTasks);
|
|
@@ -255,9 +238,7 @@ const saveWidgetArea = widgetAreaId => async _ref4 => {
|
|
|
255
238
|
const error = registry.select(_coreData.store).getLastEntitySaveError('root', 'widget', widget.id);
|
|
256
239
|
|
|
257
240
|
if (error) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
failedWidgetNames.push(((_block$attributes = block.attributes) === null || _block$attributes === void 0 ? void 0 : _block$attributes.name) || (block === null || block === void 0 ? void 0 : block.name));
|
|
241
|
+
failedWidgetNames.push(block.attributes?.name || block?.name);
|
|
261
242
|
}
|
|
262
243
|
|
|
263
244
|
if (!sidebarWidgetsIds[position]) {
|
|
@@ -282,10 +263,9 @@ const saveWidgetArea = widgetAreaId => async _ref4 => {
|
|
|
282
263
|
|
|
283
264
|
exports.saveWidgetArea = saveWidgetArea;
|
|
284
265
|
|
|
285
|
-
const trySaveWidgetArea = widgetAreaId =>
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
} = _ref9;
|
|
266
|
+
const trySaveWidgetArea = widgetAreaId => ({
|
|
267
|
+
registry
|
|
268
|
+
}) => {
|
|
289
269
|
registry.dispatch(_coreData.store).saveEditedEntityRecord(_utils.KIND, _utils.WIDGET_AREA_ENTITY_TYPE, widgetAreaId, {
|
|
290
270
|
throwOnError: true
|
|
291
271
|
});
|
|
@@ -380,10 +360,9 @@ function setIsListViewOpened(isOpen) {
|
|
|
380
360
|
*/
|
|
381
361
|
|
|
382
362
|
|
|
383
|
-
const closeGeneralSidebar = () =>
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
} = _ref10;
|
|
363
|
+
const closeGeneralSidebar = () => ({
|
|
364
|
+
registry
|
|
365
|
+
}) => {
|
|
387
366
|
registry.dispatch(_interface.store).disableComplementaryArea(_constants.STORE_NAME);
|
|
388
367
|
};
|
|
389
368
|
/**
|
|
@@ -396,23 +375,19 @@ const closeGeneralSidebar = () => _ref10 => {
|
|
|
396
375
|
|
|
397
376
|
exports.closeGeneralSidebar = closeGeneralSidebar;
|
|
398
377
|
|
|
399
|
-
const moveBlockToWidgetArea = (clientId, widgetAreaId) => async
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
} = _ref11;
|
|
378
|
+
const moveBlockToWidgetArea = (clientId, widgetAreaId) => async ({
|
|
379
|
+
dispatch,
|
|
380
|
+
select,
|
|
381
|
+
registry
|
|
382
|
+
}) => {
|
|
405
383
|
const sourceRootClientId = registry.select(_blockEditor.store).getBlockRootClientId(clientId); // Search the top level blocks (widget areas) for the one with the matching
|
|
406
384
|
// id attribute. Makes the assumption that all top-level blocks are widget
|
|
407
385
|
// areas.
|
|
408
386
|
|
|
409
387
|
const widgetAreas = registry.select(_blockEditor.store).getBlocks();
|
|
410
|
-
const destinationWidgetAreaBlock = widgetAreas.find(
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
} = _ref12;
|
|
414
|
-
return attributes.id === widgetAreaId;
|
|
415
|
-
});
|
|
388
|
+
const destinationWidgetAreaBlock = widgetAreas.find(({
|
|
389
|
+
attributes
|
|
390
|
+
}) => attributes.id === widgetAreaId);
|
|
416
391
|
const destinationRootClientId = destinationWidgetAreaBlock.clientId; // Get the index for moving to the end of the destination widget area.
|
|
417
392
|
|
|
418
393
|
const destinationInnerBlocksClientIds = registry.select(_blockEditor.store).getBlockOrder(destinationRootClientId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/store/actions.js"],"names":["persistStubPost","id","blocks","registry","stubPost","dispatch","coreStore","receiveEntityRecords","KIND","POST_TYPE","saveEditedWidgetAreas","select","editedWidgetAreas","getEditedWidgetAreas","length","saveWidgetAreas","noticesStore","createSuccessNotice","type","e","createErrorNotice","message","widgetAreas","widgetArea","saveWidgetArea","finishResolution","WIDGET_AREA_ENTITY_TYPE","widgetAreaId","widgets","getWidgets","post","getEditedEntityRecord","areaWidgets","Object","values","filter","sidebar","usedReferenceWidgets","widgetsBlocks","block","attributes","name","includes","push","deletedWidgets","widget","widgetsNewArea","getWidgetAreaForWidgetId","batchMeta","batchTasks","sidebarWidgetsIds","i","widgetId","oldWidget","editEntityRecord","undoIgnore","hasEdits","hasEditsForEntityRecord","saveEditedEntityRecord","saveEntityRecord","position","clientId","deleteEntityRecord","force","records","__experimentalBatch","preservedRecords","record","hasOwnProperty","failedWidgetNames","__internalWidgetId","error","getLastEntitySaveError","Error","join","trySaveWidgetArea","undefined","throwOnError","setWidgetIdForClientId","setWidgetAreasOpenState","widgetAreasOpenState","setIsWidgetAreaOpen","isOpen","setIsInserterOpened","value","setIsListViewOpened","closeGeneralSidebar","interfaceStore","disableComplementaryArea","editWidgetsStoreName","moveBlockToWidgetArea","sourceRootClientId","blockEditorStore","getBlockRootClientId","getBlocks","destinationWidgetAreaBlock","find","destinationRootClientId","destinationInnerBlocksClientIds","getBlockOrder","destinationIndex","isDestinationWidgetAreaOpen","getIsWidgetAreaOpen","moveBlocksToPosition"],"mappings":";;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAQA;;AAtBA;AACA;AACA;;AAQA;AACA;AACA;;AAYA;AACA;AAC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G,IAAAA,QAAQ,CAAC4E,mBAAT,CAA8BgB,uBAA9B,EAAuD,IAAvD;AACA,GA3B0C,CA6B3C;;;AACA9F,EAAAA,QAAQ,CACNE,QADF,CACYuF,kBADZ,EAEEW,oBAFF,CAGE,CAAE1C,QAAF,CAHF,EAIE8B,kBAJF,EAKEM,uBALF,EAMEG,gBANF;AAQA,CAxCK","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { transformBlockToWidget } from './transformers';\nimport {\n\tbuildWidgetAreaPostId,\n\tbuildWidgetAreasQuery,\n\tcreateStubPost,\n\tKIND,\n\tPOST_TYPE,\n\tWIDGET_AREA_ENTITY_TYPE,\n} from './utils';\nimport { STORE_NAME as editWidgetsStoreName } from './constants';\n\n/**\n * Persists a stub post with given ID to core data store. The post is meant to be in-memory only and\n * shouldn't be saved via the API.\n *\n * @param {string} id Post ID.\n * @param {Array} blocks Blocks the post should consist of.\n * @return {Object} The post object.\n */\nexport const persistStubPost =\n\t( id, blocks ) =>\n\t( { registry } ) => {\n\t\tconst stubPost = createStubPost( id, blocks );\n\t\tregistry\n\t\t\t.dispatch( coreStore )\n\t\t\t.receiveEntityRecords(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tstubPost,\n\t\t\t\t{ id: stubPost.id },\n\t\t\t\tfalse\n\t\t\t);\n\t\treturn stubPost;\n\t};\n\n/**\n * Converts all the blocks from edited widget areas into widgets,\n * and submits a batch request to save everything at once.\n *\n * Creates a snackbar notice on either success or error.\n *\n * @return {Function} An action creator.\n */\nexport const saveEditedWidgetAreas =\n\t() =>\n\tasync ( { select, dispatch, registry } ) => {\n\t\tconst editedWidgetAreas = select.getEditedWidgetAreas();\n\t\tif ( ! editedWidgetAreas?.length ) {\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tawait dispatch.saveWidgetAreas( editedWidgetAreas );\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createSuccessNotice( __( 'Widgets saved.' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t} catch ( e ) {\n\t\t\tregistry.dispatch( noticesStore ).createErrorNotice(\n\t\t\t\t/* translators: %s: The error message. */\n\t\t\t\tsprintf( __( 'There was an error. %s' ), e.message ),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t};\n\n/**\n * Converts all the blocks from specified widget areas into widgets,\n * and submits a batch request to save everything at once.\n *\n * @param {Object[]} widgetAreas Widget areas to save.\n * @return {Function} An action creator.\n */\nexport const saveWidgetAreas =\n\t( widgetAreas ) =>\n\tasync ( { dispatch, registry } ) => {\n\t\ttry {\n\t\t\tfor ( const widgetArea of widgetAreas ) {\n\t\t\t\tawait dispatch.saveWidgetArea( widgetArea.id );\n\t\t\t}\n\t\t} finally {\n\t\t\t// saveEditedEntityRecord resets the resolution status, let's fix it manually.\n\t\t\tawait registry\n\t\t\t\t.dispatch( coreStore )\n\t\t\t\t.finishResolution(\n\t\t\t\t\t'getEntityRecord',\n\t\t\t\t\tKIND,\n\t\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\t\tbuildWidgetAreasQuery()\n\t\t\t\t);\n\t\t}\n\t};\n\n/**\n * Converts all the blocks from a widget area specified by ID into widgets,\n * and submits a batch request to save everything at once.\n *\n * @param {string} widgetAreaId ID of the widget area to process.\n * @return {Function} An action creator.\n */\nexport const saveWidgetArea =\n\t( widgetAreaId ) =>\n\tasync ( { dispatch, select, registry } ) => {\n\t\tconst widgets = select.getWidgets();\n\n\t\tconst post = registry\n\t\t\t.select( coreStore )\n\t\t\t.getEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tbuildWidgetAreaPostId( widgetAreaId )\n\t\t\t);\n\n\t\t// Get all widgets from this area\n\t\tconst areaWidgets = Object.values( widgets ).filter(\n\t\t\t( { sidebar } ) => sidebar === widgetAreaId\n\t\t);\n\n\t\t// Remove all duplicate reference widget instances for legacy widgets.\n\t\t// Why? We filter out the widgets with duplicate IDs to prevent adding more than one instance of a widget\n\t\t// implemented using a function. WordPress doesn't support having more than one instance of these, if you try to\n\t\t// save multiple instances of these in different sidebars you will run into undefined behaviors.\n\t\tconst usedReferenceWidgets = [];\n\t\tconst widgetsBlocks = post.blocks.filter( ( block ) => {\n\t\t\tconst { id } = block.attributes;\n\n\t\t\tif ( block.name === 'core/legacy-widget' && id ) {\n\t\t\t\tif ( usedReferenceWidgets.includes( id ) ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tusedReferenceWidgets.push( id );\n\t\t\t}\n\t\t\treturn true;\n\t\t} );\n\n\t\t// Determine which widgets have been deleted. We can tell if a widget is\n\t\t// deleted and not just moved to a different area by looking to see if\n\t\t// getWidgetAreaForWidgetId() finds something.\n\t\tconst deletedWidgets = [];\n\t\tfor ( const widget of areaWidgets ) {\n\t\t\tconst widgetsNewArea = select.getWidgetAreaForWidgetId( widget.id );\n\t\t\tif ( ! widgetsNewArea ) {\n\t\t\t\tdeletedWidgets.push( widget );\n\t\t\t}\n\t\t}\n\n\t\tconst batchMeta = [];\n\t\tconst batchTasks = [];\n\t\tconst sidebarWidgetsIds = [];\n\t\tfor ( let i = 0; i < widgetsBlocks.length; i++ ) {\n\t\t\tconst block = widgetsBlocks[ i ];\n\t\t\tconst widgetId = getWidgetIdFromBlock( block );\n\t\t\tconst oldWidget = widgets[ widgetId ];\n\t\t\tconst widget = transformBlockToWidget( block, oldWidget );\n\n\t\t\t// We'll replace the null widgetId after save, but we track it here\n\t\t\t// since order is important.\n\t\t\tsidebarWidgetsIds.push( widgetId );\n\n\t\t\t// Check oldWidget as widgetId might refer to an ID which has been\n\t\t\t// deleted, e.g. if a deleted block is restored via undo after saving.\n\t\t\tif ( oldWidget ) {\n\t\t\t\t// Update an existing widget.\n\t\t\t\tregistry.dispatch( coreStore ).editEntityRecord(\n\t\t\t\t\t'root',\n\t\t\t\t\t'widget',\n\t\t\t\t\twidgetId,\n\t\t\t\t\t{\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tsidebar: widgetAreaId,\n\t\t\t\t\t},\n\t\t\t\t\t{ undoIgnore: true }\n\t\t\t\t);\n\n\t\t\t\tconst hasEdits = registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.hasEditsForEntityRecord( 'root', 'widget', widgetId );\n\n\t\t\t\tif ( ! hasEdits ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tbatchTasks.push( ( { saveEditedEntityRecord } ) =>\n\t\t\t\t\tsaveEditedEntityRecord( 'root', 'widget', widgetId )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Create a new widget.\n\t\t\t\tbatchTasks.push( ( { saveEntityRecord } ) =>\n\t\t\t\t\tsaveEntityRecord( 'root', 'widget', {\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tsidebar: widgetAreaId,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tbatchMeta.push( {\n\t\t\t\tblock,\n\t\t\t\tposition: i,\n\t\t\t\tclientId: block.clientId,\n\t\t\t} );\n\t\t}\n\t\tfor ( const widget of deletedWidgets ) {\n\t\t\tbatchTasks.push( ( { deleteEntityRecord } ) =>\n\t\t\t\tdeleteEntityRecord( 'root', 'widget', widget.id, {\n\t\t\t\t\tforce: true,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tconst records = await registry\n\t\t\t.dispatch( coreStore )\n\t\t\t.__experimentalBatch( batchTasks );\n\t\tconst preservedRecords = records.filter(\n\t\t\t( record ) => ! record.hasOwnProperty( 'deleted' )\n\t\t);\n\n\t\tconst failedWidgetNames = [];\n\n\t\tfor ( let i = 0; i < preservedRecords.length; i++ ) {\n\t\t\tconst widget = preservedRecords[ i ];\n\t\t\tconst { block, position } = batchMeta[ i ];\n\n\t\t\t// Set __internalWidgetId on the block. This will be persisted to the\n\t\t\t// store when we dispatch receiveEntityRecords( post ) below.\n\t\t\tpost.blocks[ position ].attributes.__internalWidgetId = widget.id;\n\n\t\t\tconst error = registry\n\t\t\t\t.select( coreStore )\n\t\t\t\t.getLastEntitySaveError( 'root', 'widget', widget.id );\n\t\t\tif ( error ) {\n\t\t\t\tfailedWidgetNames.push( block.attributes?.name || block?.name );\n\t\t\t}\n\n\t\t\tif ( ! sidebarWidgetsIds[ position ] ) {\n\t\t\t\tsidebarWidgetsIds[ position ] = widget.id;\n\t\t\t}\n\t\t}\n\n\t\tif ( failedWidgetNames.length ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: List of widget names */\n\t\t\t\t\t__( 'Could not save the following widgets: %s.' ),\n\t\t\t\t\tfailedWidgetNames.join( ', ' )\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\tregistry.dispatch( coreStore ).editEntityRecord(\n\t\t\tKIND,\n\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\twidgetAreaId,\n\t\t\t{\n\t\t\t\twidgets: sidebarWidgetsIds,\n\t\t\t},\n\t\t\t{ undoIgnore: true }\n\t\t);\n\n\t\tdispatch( trySaveWidgetArea( widgetAreaId ) );\n\n\t\tregistry\n\t\t\t.dispatch( coreStore )\n\t\t\t.receiveEntityRecords( KIND, POST_TYPE, post, undefined );\n\t};\n\nconst trySaveWidgetArea =\n\t( widgetAreaId ) =>\n\t( { registry } ) => {\n\t\tregistry\n\t\t\t.dispatch( coreStore )\n\t\t\t.saveEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\twidgetAreaId,\n\t\t\t\t{\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t}\n\t\t\t);\n\t};\n\n/**\n * Sets the clientId stored for a particular widgetId.\n *\n * @param {number} clientId Client id.\n * @param {number} widgetId Widget id.\n *\n * @return {Object} Action.\n */\nexport function setWidgetIdForClientId( clientId, widgetId ) {\n\treturn {\n\t\ttype: 'SET_WIDGET_ID_FOR_CLIENT_ID',\n\t\tclientId,\n\t\twidgetId,\n\t};\n}\n\n/**\n * Sets the open state of all the widget areas.\n *\n * @param {Object} widgetAreasOpenState The open states of all the widget areas.\n *\n * @return {Object} Action.\n */\nexport function setWidgetAreasOpenState( widgetAreasOpenState ) {\n\treturn {\n\t\ttype: 'SET_WIDGET_AREAS_OPEN_STATE',\n\t\twidgetAreasOpenState,\n\t};\n}\n\n/**\n * Sets the open state of the widget area.\n *\n * @param {string} clientId The clientId of the widget area.\n * @param {boolean} isOpen Whether the widget area should be opened.\n *\n * @return {Object} Action.\n */\nexport function setIsWidgetAreaOpen( clientId, isOpen ) {\n\treturn {\n\t\ttype: 'SET_IS_WIDGET_AREA_OPEN',\n\t\tclientId,\n\t\tisOpen,\n\t};\n}\n\n/**\n * Returns an action object used to open/close the inserter.\n *\n * @param {boolean|Object} value Whether the inserter should be\n * opened (true) or closed (false).\n * To specify an insertion point,\n * use an object.\n * @param {string} value.rootClientId The root client ID to insert at.\n * @param {number} value.insertionIndex The index to insert at.\n *\n * @return {Object} Action object.\n */\nexport function setIsInserterOpened( value ) {\n\treturn {\n\t\ttype: 'SET_IS_INSERTER_OPENED',\n\t\tvalue,\n\t};\n}\n\n/**\n * Returns an action object used to open/close the list view.\n *\n * @param {boolean} isOpen A boolean representing whether the list view should be opened or closed.\n * @return {Object} Action object.\n */\nexport function setIsListViewOpened( isOpen ) {\n\treturn {\n\t\ttype: 'SET_IS_LIST_VIEW_OPENED',\n\t\tisOpen,\n\t};\n}\n\n/**\n * Returns an action object signalling that the user closed the sidebar.\n *\n * @return {Object} Action creator.\n */\nexport const closeGeneralSidebar =\n\t() =>\n\t( { registry } ) => {\n\t\tregistry\n\t\t\t.dispatch( interfaceStore )\n\t\t\t.disableComplementaryArea( editWidgetsStoreName );\n\t};\n\n/**\n * Action that handles moving a block between widget areas\n *\n * @param {string} clientId The clientId of the block to move.\n * @param {string} widgetAreaId The id of the widget area to move the block to.\n */\nexport const moveBlockToWidgetArea =\n\t( clientId, widgetAreaId ) =>\n\tasync ( { dispatch, select, registry } ) => {\n\t\tconst sourceRootClientId = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlockRootClientId( clientId );\n\n\t\t// Search the top level blocks (widget areas) for the one with the matching\n\t\t// id attribute. Makes the assumption that all top-level blocks are widget\n\t\t// areas.\n\t\tconst widgetAreas = registry.select( blockEditorStore ).getBlocks();\n\t\tconst destinationWidgetAreaBlock = widgetAreas.find(\n\t\t\t( { attributes } ) => attributes.id === widgetAreaId\n\t\t);\n\t\tconst destinationRootClientId = destinationWidgetAreaBlock.clientId;\n\n\t\t// Get the index for moving to the end of the destination widget area.\n\t\tconst destinationInnerBlocksClientIds = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlockOrder( destinationRootClientId );\n\t\tconst destinationIndex = destinationInnerBlocksClientIds.length;\n\n\t\t// Reveal the widget area, if it's not open.\n\t\tconst isDestinationWidgetAreaOpen = select.getIsWidgetAreaOpen(\n\t\t\tdestinationRootClientId\n\t\t);\n\n\t\tif ( ! isDestinationWidgetAreaOpen ) {\n\t\t\tdispatch.setIsWidgetAreaOpen( destinationRootClientId, true );\n\t\t}\n\n\t\t// Move the block.\n\t\tregistry\n\t\t\t.dispatch( blockEditorStore )\n\t\t\t.moveBlocksToPosition(\n\t\t\t\t[ clientId ],\n\t\t\t\tsourceRootClientId,\n\t\t\t\tdestinationRootClientId,\n\t\t\t\tdestinationIndex\n\t\t\t);\n\t};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/store/actions.js"],"names":["persistStubPost","id","blocks","registry","stubPost","dispatch","coreStore","receiveEntityRecords","KIND","POST_TYPE","saveEditedWidgetAreas","select","editedWidgetAreas","getEditedWidgetAreas","length","saveWidgetAreas","noticesStore","createSuccessNotice","type","e","createErrorNotice","message","widgetAreas","widgetArea","saveWidgetArea","finishResolution","WIDGET_AREA_ENTITY_TYPE","widgetAreaId","widgets","getWidgets","post","getEditedEntityRecord","areaWidgets","Object","values","filter","sidebar","usedReferenceWidgets","widgetsBlocks","block","attributes","name","includes","push","deletedWidgets","widget","widgetsNewArea","getWidgetAreaForWidgetId","batchMeta","batchTasks","sidebarWidgetsIds","i","widgetId","oldWidget","editEntityRecord","undoIgnore","hasEdits","hasEditsForEntityRecord","saveEditedEntityRecord","saveEntityRecord","position","clientId","deleteEntityRecord","force","records","__experimentalBatch","preservedRecords","record","hasOwnProperty","failedWidgetNames","__internalWidgetId","error","getLastEntitySaveError","Error","join","trySaveWidgetArea","undefined","throwOnError","setWidgetIdForClientId","setWidgetAreasOpenState","widgetAreasOpenState","setIsWidgetAreaOpen","isOpen","setIsInserterOpened","value","setIsListViewOpened","closeGeneralSidebar","interfaceStore","disableComplementaryArea","editWidgetsStoreName","moveBlockToWidgetArea","sourceRootClientId","blockEditorStore","getBlockRootClientId","getBlocks","destinationWidgetAreaBlock","find","destinationRootClientId","destinationInnerBlocksClientIds","getBlockOrder","destinationIndex","isDestinationWidgetAreaOpen","getIsWidgetAreaOpen","moveBlocksToPosition"],"mappings":";;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAQA;;AAtBA;AACA;AACA;;AAQA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,eAAe,GAC3B,CAAEC,EAAF,EAAMC,MAAN,KACA,CAAE;AAAEC,EAAAA;AAAF,CAAF,KAAoB;AACnB,QAAMC,QAAQ,GAAG,2BAAgBH,EAAhB,EAAoBC,MAApB,CAAjB;AACAC,EAAAA,QAAQ,CACNE,QADF,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EAAAA;AAApB,CAAR,KAA4C;AAC3C,QAAMwF,kBAAkB,GAAGxF,QAAQ,CACjCQ,MADyB,CACjBiF,kBADiB,EAEzBC,oBAFyB,CAEHhC,QAFG,CAA3B,CAD2C,CAK3C;AACA;AACA;;AACA,QAAMvC,WAAW,GAAGnB,QAAQ,CAACQ,MAAT,CAAiBiF,kBAAjB,EAAoCE,SAApC,EAApB;AACA,QAAMC,0BAA0B,GAAGzE,WAAW,CAAC0E,IAAZ,CAClC,CAAE;AAAExD,IAAAA;AAAF,GAAF,KAAsBA,UAAU,CAACvC,EAAX,KAAkB0B,YADN,CAAnC;AAGA,QAAMsE,uBAAuB,GAAGF,0BAA0B,CAAClC,QAA3D,CAZ2C,CAc3C;;AACA,QAAMqC,+BAA+B,GAAG/F,QAAQ,CAC9CQ,MADsC,CAC9BiF,kBAD8B,EAEtCO,aAFsC,CAEvBF,uBAFuB,CAAxC;AAGA,QAAMG,gBAAgB,GAAGF,+BAA+B,CAACpF,MAAzD,CAlB2C,CAoB3C;;AACA,QAAMuF,2BAA2B,GAAG1F,MAAM,CAAC2F,mBAAP,CACnCL,uBADmC,CAApC;;AAIA,MAAK,CAAEI,2BAAP,EAAqC;AACpChG,IAAAA,QAAQ,CAAC4E,mBAAT,CAA8BgB,uBAA9B,EAAuD,IAAvD;AACA,GA3B0C,CA6B3C;;;AACA9F,EAAAA,QAAQ,CACNE,QADF,CACYuF,kBADZ,EAEEW,oBAFF,CAGE,CAAE1C,QAAF,CAHF,EAIE8B,kBAJF,EAKEM,uBALF,EAMEG,gBANF;AAQA,CAxCK","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { transformBlockToWidget } from './transformers';\nimport {\n\tbuildWidgetAreaPostId,\n\tbuildWidgetAreasQuery,\n\tcreateStubPost,\n\tKIND,\n\tPOST_TYPE,\n\tWIDGET_AREA_ENTITY_TYPE,\n} from './utils';\nimport { STORE_NAME as editWidgetsStoreName } from './constants';\n\n/**\n * Persists a stub post with given ID to core data store. The post is meant to be in-memory only and\n * shouldn't be saved via the API.\n *\n * @param {string} id Post ID.\n * @param {Array} blocks Blocks the post should consist of.\n * @return {Object} The post object.\n */\nexport const persistStubPost =\n\t( id, blocks ) =>\n\t( { registry } ) => {\n\t\tconst stubPost = createStubPost( id, blocks );\n\t\tregistry\n\t\t\t.dispatch( coreStore )\n\t\t\t.receiveEntityRecords(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tstubPost,\n\t\t\t\t{ id: stubPost.id },\n\t\t\t\tfalse\n\t\t\t);\n\t\treturn stubPost;\n\t};\n\n/**\n * Converts all the blocks from edited widget areas into widgets,\n * and submits a batch request to save everything at once.\n *\n * Creates a snackbar notice on either success or error.\n *\n * @return {Function} An action creator.\n */\nexport const saveEditedWidgetAreas =\n\t() =>\n\tasync ( { select, dispatch, registry } ) => {\n\t\tconst editedWidgetAreas = select.getEditedWidgetAreas();\n\t\tif ( ! editedWidgetAreas?.length ) {\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tawait dispatch.saveWidgetAreas( editedWidgetAreas );\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createSuccessNotice( __( 'Widgets saved.' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t} catch ( e ) {\n\t\t\tregistry.dispatch( noticesStore ).createErrorNotice(\n\t\t\t\t/* translators: %s: The error message. */\n\t\t\t\tsprintf( __( 'There was an error. %s' ), e.message ),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t};\n\n/**\n * Converts all the blocks from specified widget areas into widgets,\n * and submits a batch request to save everything at once.\n *\n * @param {Object[]} widgetAreas Widget areas to save.\n * @return {Function} An action creator.\n */\nexport const saveWidgetAreas =\n\t( widgetAreas ) =>\n\tasync ( { dispatch, registry } ) => {\n\t\ttry {\n\t\t\tfor ( const widgetArea of widgetAreas ) {\n\t\t\t\tawait dispatch.saveWidgetArea( widgetArea.id );\n\t\t\t}\n\t\t} finally {\n\t\t\t// saveEditedEntityRecord resets the resolution status, let's fix it manually.\n\t\t\tawait registry\n\t\t\t\t.dispatch( coreStore )\n\t\t\t\t.finishResolution(\n\t\t\t\t\t'getEntityRecord',\n\t\t\t\t\tKIND,\n\t\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\t\tbuildWidgetAreasQuery()\n\t\t\t\t);\n\t\t}\n\t};\n\n/**\n * Converts all the blocks from a widget area specified by ID into widgets,\n * and submits a batch request to save everything at once.\n *\n * @param {string} widgetAreaId ID of the widget area to process.\n * @return {Function} An action creator.\n */\nexport const saveWidgetArea =\n\t( widgetAreaId ) =>\n\tasync ( { dispatch, select, registry } ) => {\n\t\tconst widgets = select.getWidgets();\n\n\t\tconst post = registry\n\t\t\t.select( coreStore )\n\t\t\t.getEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tbuildWidgetAreaPostId( widgetAreaId )\n\t\t\t);\n\n\t\t// Get all widgets from this area\n\t\tconst areaWidgets = Object.values( widgets ).filter(\n\t\t\t( { sidebar } ) => sidebar === widgetAreaId\n\t\t);\n\n\t\t// Remove all duplicate reference widget instances for legacy widgets.\n\t\t// Why? We filter out the widgets with duplicate IDs to prevent adding more than one instance of a widget\n\t\t// implemented using a function. WordPress doesn't support having more than one instance of these, if you try to\n\t\t// save multiple instances of these in different sidebars you will run into undefined behaviors.\n\t\tconst usedReferenceWidgets = [];\n\t\tconst widgetsBlocks = post.blocks.filter( ( block ) => {\n\t\t\tconst { id } = block.attributes;\n\n\t\t\tif ( block.name === 'core/legacy-widget' && id ) {\n\t\t\t\tif ( usedReferenceWidgets.includes( id ) ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tusedReferenceWidgets.push( id );\n\t\t\t}\n\t\t\treturn true;\n\t\t} );\n\n\t\t// Determine which widgets have been deleted. We can tell if a widget is\n\t\t// deleted and not just moved to a different area by looking to see if\n\t\t// getWidgetAreaForWidgetId() finds something.\n\t\tconst deletedWidgets = [];\n\t\tfor ( const widget of areaWidgets ) {\n\t\t\tconst widgetsNewArea = select.getWidgetAreaForWidgetId( widget.id );\n\t\t\tif ( ! widgetsNewArea ) {\n\t\t\t\tdeletedWidgets.push( widget );\n\t\t\t}\n\t\t}\n\n\t\tconst batchMeta = [];\n\t\tconst batchTasks = [];\n\t\tconst sidebarWidgetsIds = [];\n\t\tfor ( let i = 0; i < widgetsBlocks.length; i++ ) {\n\t\t\tconst block = widgetsBlocks[ i ];\n\t\t\tconst widgetId = getWidgetIdFromBlock( block );\n\t\t\tconst oldWidget = widgets[ widgetId ];\n\t\t\tconst widget = transformBlockToWidget( block, oldWidget );\n\n\t\t\t// We'll replace the null widgetId after save, but we track it here\n\t\t\t// since order is important.\n\t\t\tsidebarWidgetsIds.push( widgetId );\n\n\t\t\t// Check oldWidget as widgetId might refer to an ID which has been\n\t\t\t// deleted, e.g. if a deleted block is restored via undo after saving.\n\t\t\tif ( oldWidget ) {\n\t\t\t\t// Update an existing widget.\n\t\t\t\tregistry.dispatch( coreStore ).editEntityRecord(\n\t\t\t\t\t'root',\n\t\t\t\t\t'widget',\n\t\t\t\t\twidgetId,\n\t\t\t\t\t{\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tsidebar: widgetAreaId,\n\t\t\t\t\t},\n\t\t\t\t\t{ undoIgnore: true }\n\t\t\t\t);\n\n\t\t\t\tconst hasEdits = registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.hasEditsForEntityRecord( 'root', 'widget', widgetId );\n\n\t\t\t\tif ( ! hasEdits ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tbatchTasks.push( ( { saveEditedEntityRecord } ) =>\n\t\t\t\t\tsaveEditedEntityRecord( 'root', 'widget', widgetId )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Create a new widget.\n\t\t\t\tbatchTasks.push( ( { saveEntityRecord } ) =>\n\t\t\t\t\tsaveEntityRecord( 'root', 'widget', {\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tsidebar: widgetAreaId,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tbatchMeta.push( {\n\t\t\t\tblock,\n\t\t\t\tposition: i,\n\t\t\t\tclientId: block.clientId,\n\t\t\t} );\n\t\t}\n\t\tfor ( const widget of deletedWidgets ) {\n\t\t\tbatchTasks.push( ( { deleteEntityRecord } ) =>\n\t\t\t\tdeleteEntityRecord( 'root', 'widget', widget.id, {\n\t\t\t\t\tforce: true,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tconst records = await registry\n\t\t\t.dispatch( coreStore )\n\t\t\t.__experimentalBatch( batchTasks );\n\t\tconst preservedRecords = records.filter(\n\t\t\t( record ) => ! record.hasOwnProperty( 'deleted' )\n\t\t);\n\n\t\tconst failedWidgetNames = [];\n\n\t\tfor ( let i = 0; i < preservedRecords.length; i++ ) {\n\t\t\tconst widget = preservedRecords[ i ];\n\t\t\tconst { block, position } = batchMeta[ i ];\n\n\t\t\t// Set __internalWidgetId on the block. This will be persisted to the\n\t\t\t// store when we dispatch receiveEntityRecords( post ) below.\n\t\t\tpost.blocks[ position ].attributes.__internalWidgetId = widget.id;\n\n\t\t\tconst error = registry\n\t\t\t\t.select( coreStore )\n\t\t\t\t.getLastEntitySaveError( 'root', 'widget', widget.id );\n\t\t\tif ( error ) {\n\t\t\t\tfailedWidgetNames.push( block.attributes?.name || block?.name );\n\t\t\t}\n\n\t\t\tif ( ! sidebarWidgetsIds[ position ] ) {\n\t\t\t\tsidebarWidgetsIds[ position ] = widget.id;\n\t\t\t}\n\t\t}\n\n\t\tif ( failedWidgetNames.length ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: List of widget names */\n\t\t\t\t\t__( 'Could not save the following widgets: %s.' ),\n\t\t\t\t\tfailedWidgetNames.join( ', ' )\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\tregistry.dispatch( coreStore ).editEntityRecord(\n\t\t\tKIND,\n\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\twidgetAreaId,\n\t\t\t{\n\t\t\t\twidgets: sidebarWidgetsIds,\n\t\t\t},\n\t\t\t{ undoIgnore: true }\n\t\t);\n\n\t\tdispatch( trySaveWidgetArea( widgetAreaId ) );\n\n\t\tregistry\n\t\t\t.dispatch( coreStore )\n\t\t\t.receiveEntityRecords( KIND, POST_TYPE, post, undefined );\n\t};\n\nconst trySaveWidgetArea =\n\t( widgetAreaId ) =>\n\t( { registry } ) => {\n\t\tregistry\n\t\t\t.dispatch( coreStore )\n\t\t\t.saveEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\twidgetAreaId,\n\t\t\t\t{\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t}\n\t\t\t);\n\t};\n\n/**\n * Sets the clientId stored for a particular widgetId.\n *\n * @param {number} clientId Client id.\n * @param {number} widgetId Widget id.\n *\n * @return {Object} Action.\n */\nexport function setWidgetIdForClientId( clientId, widgetId ) {\n\treturn {\n\t\ttype: 'SET_WIDGET_ID_FOR_CLIENT_ID',\n\t\tclientId,\n\t\twidgetId,\n\t};\n}\n\n/**\n * Sets the open state of all the widget areas.\n *\n * @param {Object} widgetAreasOpenState The open states of all the widget areas.\n *\n * @return {Object} Action.\n */\nexport function setWidgetAreasOpenState( widgetAreasOpenState ) {\n\treturn {\n\t\ttype: 'SET_WIDGET_AREAS_OPEN_STATE',\n\t\twidgetAreasOpenState,\n\t};\n}\n\n/**\n * Sets the open state of the widget area.\n *\n * @param {string} clientId The clientId of the widget area.\n * @param {boolean} isOpen Whether the widget area should be opened.\n *\n * @return {Object} Action.\n */\nexport function setIsWidgetAreaOpen( clientId, isOpen ) {\n\treturn {\n\t\ttype: 'SET_IS_WIDGET_AREA_OPEN',\n\t\tclientId,\n\t\tisOpen,\n\t};\n}\n\n/**\n * Returns an action object used to open/close the inserter.\n *\n * @param {boolean|Object} value Whether the inserter should be\n * opened (true) or closed (false).\n * To specify an insertion point,\n * use an object.\n * @param {string} value.rootClientId The root client ID to insert at.\n * @param {number} value.insertionIndex The index to insert at.\n *\n * @return {Object} Action object.\n */\nexport function setIsInserterOpened( value ) {\n\treturn {\n\t\ttype: 'SET_IS_INSERTER_OPENED',\n\t\tvalue,\n\t};\n}\n\n/**\n * Returns an action object used to open/close the list view.\n *\n * @param {boolean} isOpen A boolean representing whether the list view should be opened or closed.\n * @return {Object} Action object.\n */\nexport function setIsListViewOpened( isOpen ) {\n\treturn {\n\t\ttype: 'SET_IS_LIST_VIEW_OPENED',\n\t\tisOpen,\n\t};\n}\n\n/**\n * Returns an action object signalling that the user closed the sidebar.\n *\n * @return {Object} Action creator.\n */\nexport const closeGeneralSidebar =\n\t() =>\n\t( { registry } ) => {\n\t\tregistry\n\t\t\t.dispatch( interfaceStore )\n\t\t\t.disableComplementaryArea( editWidgetsStoreName );\n\t};\n\n/**\n * Action that handles moving a block between widget areas\n *\n * @param {string} clientId The clientId of the block to move.\n * @param {string} widgetAreaId The id of the widget area to move the block to.\n */\nexport const moveBlockToWidgetArea =\n\t( clientId, widgetAreaId ) =>\n\tasync ( { dispatch, select, registry } ) => {\n\t\tconst sourceRootClientId = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlockRootClientId( clientId );\n\n\t\t// Search the top level blocks (widget areas) for the one with the matching\n\t\t// id attribute. Makes the assumption that all top-level blocks are widget\n\t\t// areas.\n\t\tconst widgetAreas = registry.select( blockEditorStore ).getBlocks();\n\t\tconst destinationWidgetAreaBlock = widgetAreas.find(\n\t\t\t( { attributes } ) => attributes.id === widgetAreaId\n\t\t);\n\t\tconst destinationRootClientId = destinationWidgetAreaBlock.clientId;\n\n\t\t// Get the index for moving to the end of the destination widget area.\n\t\tconst destinationInnerBlocksClientIds = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlockOrder( destinationRootClientId );\n\t\tconst destinationIndex = destinationInnerBlocksClientIds.length;\n\n\t\t// Reveal the widget area, if it's not open.\n\t\tconst isDestinationWidgetAreaOpen = select.getIsWidgetAreaOpen(\n\t\t\tdestinationRootClientId\n\t\t);\n\n\t\tif ( ! isDestinationWidgetAreaOpen ) {\n\t\t\tdispatch.setIsWidgetAreaOpen( destinationRootClientId, true );\n\t\t}\n\n\t\t// Move the block.\n\t\tregistry\n\t\t\t.dispatch( blockEditorStore )\n\t\t\t.moveBlocksToPosition(\n\t\t\t\t[ clientId ],\n\t\t\t\tsourceRootClientId,\n\t\t\t\tdestinationRootClientId,\n\t\t\t\tdestinationIndex\n\t\t\t);\n\t};\n"]}
|
package/build/store/index.js
CHANGED
|
@@ -61,9 +61,7 @@ exports.store = store;
|
|
|
61
61
|
// bound to fail anyway.
|
|
62
62
|
|
|
63
63
|
_apiFetch.default.use(function (options, next) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (((_options$path = options.path) === null || _options$path === void 0 ? void 0 : _options$path.indexOf('/wp/v2/types/widget-area')) === 0) {
|
|
64
|
+
if (options.path?.indexOf('/wp/v2/types/widget-area') === 0) {
|
|
67
65
|
return Promise.resolve({});
|
|
68
66
|
}
|
|
69
67
|
|
package/build/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/store/index.js"],"names":["storeConfig","reducer","selectors","resolvers","actions","store","STORE_NAME","apiFetch","use","options","next","path","indexOf","Promise","resolve"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;;;;;AAbA;AACA;AACA;;AAIA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,WAAW,GAAG;AACnBC,EAAAA,OAAO,EAAPA,gBADmB;AAEnBC,EAAAA,SAFmB;AAGnBC,EAAAA,SAHmB;AAInBC,EAAAA;AAJmB,CAApB;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,KAAK,GAAG,4BAAkBC,qBAAlB,EAA8BN,WAA9B,CAAd;;AACP,oBAAUK,KAAV,E,CAEA;AACA;AACA;;AACAE,kBAASC,GAAT,CAAc,UAAWC,OAAX,EAAoBC,IAApB,EAA2B;
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/store/index.js"],"names":["storeConfig","reducer","selectors","resolvers","actions","store","STORE_NAME","apiFetch","use","options","next","path","indexOf","Promise","resolve"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;;;;;AAbA;AACA;AACA;;AAIA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,WAAW,GAAG;AACnBC,EAAAA,OAAO,EAAPA,gBADmB;AAEnBC,EAAAA,SAFmB;AAGnBC,EAAAA,SAHmB;AAInBC,EAAAA;AAJmB,CAApB;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,KAAK,GAAG,4BAAkBC,qBAAlB,EAA8BN,WAA9B,CAAd;;AACP,oBAAUK,KAAV,E,CAEA;AACA;AACA;;AACAE,kBAASC,GAAT,CAAc,UAAWC,OAAX,EAAoBC,IAApB,EAA2B;AACxC,MAAKD,OAAO,CAACE,IAAR,EAAcC,OAAd,CAAuB,0BAAvB,MAAwD,CAA7D,EAAiE;AAChE,WAAOC,OAAO,CAACC,OAAR,CAAiB,EAAjB,CAAP;AACA;;AAED,SAAOJ,IAAI,CAAED,OAAF,CAAX;AACA,CAND","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as resolvers from './resolvers';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport { STORE_NAME } from './constants';\n\n/**\n * Block editor data store configuration.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#register\n *\n * @type {Object}\n */\nconst storeConfig = {\n\treducer,\n\tselectors,\n\tresolvers,\n\tactions,\n};\n\n/**\n * Store definition for the edit widgets namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig );\nregister( store );\n\n// This package uses a few in-memory post types as wrappers for convenience.\n// This middleware prevents any network requests related to these types as they are\n// bound to fail anyway.\napiFetch.use( function ( options, next ) {\n\tif ( options.path?.indexOf( '/wp/v2/types/widget-area' ) === 0 ) {\n\t\treturn Promise.resolve( {} );\n\t}\n\n\treturn next( options );\n} );\n"]}
|
package/build/store/reducer.js
CHANGED
|
@@ -22,9 +22,7 @@ var _data = require("@wordpress/data");
|
|
|
22
22
|
*
|
|
23
23
|
* @return {Array} Updated state.
|
|
24
24
|
*/
|
|
25
|
-
function widgetAreasOpenState() {
|
|
26
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
27
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
25
|
+
function widgetAreasOpenState(state = {}, action) {
|
|
28
26
|
const {
|
|
29
27
|
type
|
|
30
28
|
} = action;
|
|
@@ -63,10 +61,7 @@ function widgetAreasOpenState() {
|
|
|
63
61
|
*/
|
|
64
62
|
|
|
65
63
|
|
|
66
|
-
function blockInserterPanel() {
|
|
67
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
68
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
69
|
-
|
|
64
|
+
function blockInserterPanel(state = false, action) {
|
|
70
65
|
switch (action.type) {
|
|
71
66
|
case 'SET_IS_LIST_VIEW_OPENED':
|
|
72
67
|
return action.isOpen ? false : state;
|
|
@@ -88,10 +83,7 @@ function blockInserterPanel() {
|
|
|
88
83
|
*/
|
|
89
84
|
|
|
90
85
|
|
|
91
|
-
function listViewPanel() {
|
|
92
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
93
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
94
|
-
|
|
86
|
+
function listViewPanel(state = false, action) {
|
|
95
87
|
switch (action.type) {
|
|
96
88
|
case 'SET_IS_INSERTER_OPENED':
|
|
97
89
|
return action.value ? false : state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/store/reducer.js"],"names":["widgetAreasOpenState","state","action","type","clientId","isOpen","blockInserterPanel","value","listViewPanel"],"mappings":";;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,oBAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/store/reducer.js"],"names":["widgetAreasOpenState","state","action","type","clientId","isOpen","blockInserterPanel","value","listViewPanel"],"mappings":";;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,oBAAT,CAA+BC,KAAK,GAAG,EAAvC,EAA2CC,MAA3C,EAAoD;AAC1D,QAAM;AAAEC,IAAAA;AAAF,MAAWD,MAAjB;;AACA,UAASC,IAAT;AACC,SAAK,6BAAL;AAAoC;AACnC,eAAOD,MAAM,CAACF,oBAAd;AACA;;AACD,SAAK,yBAAL;AAAgC;AAC/B,cAAM;AAAEI,UAAAA,QAAF;AAAYC,UAAAA;AAAZ,YAAuBH,MAA7B;AACA,eAAO,EACN,GAAGD,KADG;AAEN,WAAEG,QAAF,GAAcC;AAFR,SAAP;AAIA;;AACD;AAAS;AACR,eAAOJ,KAAP;AACA;AAbF;AAeA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASK,kBAAT,CAA6BL,KAAK,GAAG,KAArC,EAA4CC,MAA5C,EAAqD;AAC3D,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,yBAAL;AACC,aAAOD,MAAM,CAACG,MAAP,GAAgB,KAAhB,GAAwBJ,KAA/B;;AACD,SAAK,wBAAL;AACC,aAAOC,MAAM,CAACK,KAAd;AAJF;;AAMA,SAAON,KAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASO,aAAT,CAAwBP,KAAK,GAAG,KAAhC,EAAuCC,MAAvC,EAAgD;AACtD,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,wBAAL;AACC,aAAOD,MAAM,CAACK,KAAP,GAAe,KAAf,GAAuBN,KAA9B;;AACD,SAAK,yBAAL;AACC,aAAOC,MAAM,CAACG,MAAd;AAJF;;AAMA,SAAOJ,KAAP;AACA;;eAEc,2BAAiB;AAC/BK,EAAAA,kBAD+B;AAE/BE,EAAAA,aAF+B;AAG/BR,EAAAA;AAH+B,CAAjB,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Controls the open state of the widget areas.\n *\n * @param {Object} state Redux state.\n * @param {Object} action Redux action.\n *\n * @return {Array} Updated state.\n */\nexport function widgetAreasOpenState( state = {}, action ) {\n\tconst { type } = action;\n\tswitch ( type ) {\n\t\tcase 'SET_WIDGET_AREAS_OPEN_STATE': {\n\t\t\treturn action.widgetAreasOpenState;\n\t\t}\n\t\tcase 'SET_IS_WIDGET_AREA_OPEN': {\n\t\t\tconst { clientId, isOpen } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ clientId ]: isOpen,\n\t\t\t};\n\t\t}\n\t\tdefault: {\n\t\t\treturn state;\n\t\t}\n\t}\n}\n\n/**\n * Reducer to set the block inserter panel open or closed.\n *\n * Note: this reducer interacts with the list view panel reducer\n * to make sure that only one of the two panels is open at the same time.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n */\nexport function blockInserterPanel( state = false, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IS_LIST_VIEW_OPENED':\n\t\t\treturn action.isOpen ? false : state;\n\t\tcase 'SET_IS_INSERTER_OPENED':\n\t\t\treturn action.value;\n\t}\n\treturn state;\n}\n\n/**\n * Reducer to set the list view panel open or closed.\n *\n * Note: this reducer interacts with the inserter panel reducer\n * to make sure that only one of the two panels is open at the same time.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n */\nexport function listViewPanel( state = false, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IS_INSERTER_OPENED':\n\t\t\treturn action.value ? false : state;\n\t\tcase 'SET_IS_LIST_VIEW_OPENED':\n\t\t\treturn action.isOpen;\n\t}\n\treturn state;\n}\n\nexport default combineReducers( {\n\tblockInserterPanel,\n\tlistViewPanel,\n\twidgetAreasOpenState,\n} );\n"]}
|
package/build/store/resolvers.js
CHANGED
|
@@ -32,11 +32,10 @@ var _transformers = require("./transformers");
|
|
|
32
32
|
*
|
|
33
33
|
* @return {Function} An action creator.
|
|
34
34
|
*/
|
|
35
|
-
const getWidgetAreas = () => async
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} = _ref;
|
|
35
|
+
const getWidgetAreas = () => async ({
|
|
36
|
+
dispatch,
|
|
37
|
+
registry
|
|
38
|
+
}) => {
|
|
40
39
|
const query = (0, _utils.buildWidgetAreasQuery)();
|
|
41
40
|
const widgetAreas = await registry.resolveSelect(_coreData.store).getEntityRecords(_utils.KIND, _utils.WIDGET_AREA_ENTITY_TYPE, query);
|
|
42
41
|
const widgetAreaBlocks = [];
|
|
@@ -82,11 +81,10 @@ const getWidgetAreas = () => async _ref => {
|
|
|
82
81
|
|
|
83
82
|
exports.getWidgetAreas = getWidgetAreas;
|
|
84
83
|
|
|
85
|
-
const getWidgets = () => async
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
} = _ref2;
|
|
84
|
+
const getWidgets = () => async ({
|
|
85
|
+
dispatch,
|
|
86
|
+
registry
|
|
87
|
+
}) => {
|
|
90
88
|
const query = (0, _utils.buildWidgetsQuery)();
|
|
91
89
|
const widgets = await registry.resolveSelect(_coreData.store).getEntityRecords('root', 'widget', query);
|
|
92
90
|
const groupedBySidebar = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/store/resolvers.js"],"names":["getWidgetAreas","dispatch","registry","query","widgetAreas","resolveSelect","coreStore","getEntityRecords","KIND","WIDGET_AREA_ENTITY_TYPE","widgetAreaBlocks","sortedWidgetAreas","sort","a","b","id","widgetArea","push","name","widgets","length","widgetAreasOpenState","forEach","widgetAreaBlock","index","clientId","getWidgets","groupedBySidebar","widget","block","sidebar","sidebarId","hasOwnProperty"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAQA;;AAlBA;AACA;AACA;;AAIA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,cAAc,GAC1B,MACA,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/store/resolvers.js"],"names":["getWidgetAreas","dispatch","registry","query","widgetAreas","resolveSelect","coreStore","getEntityRecords","KIND","WIDGET_AREA_ENTITY_TYPE","widgetAreaBlocks","sortedWidgetAreas","sort","a","b","id","widgetArea","push","name","widgets","length","widgetAreasOpenState","forEach","widgetAreaBlock","index","clientId","getWidgets","groupedBySidebar","widget","block","sidebar","sidebarId","hasOwnProperty"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAQA;;AAlBA;AACA;AACA;;AAIA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,cAAc,GAC1B,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BAAiB,oCAAjB,EAA2CS,gBAA3C,CADO,CAAR;AAGA,CAhDK;AAkDP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMgB,UAAU,GACtB,MACA,OAAQ;AAAEzB,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,CAAR,KAAoC;AACnC,QAAMC,KAAK,GAAG,+BAAd;AACA,QAAMgB,OAAO,GAAG,MAAMjB,QAAQ,CAC5BG,aADoB,CACLC,eADK,EAEpBC,gBAFoB,CAEF,MAFE,EAEM,QAFN,EAEgBJ,KAFhB,CAAtB;AAIA,QAAMwB,gBAAgB,GAAG,EAAzB;;AAEA,OAAM,MAAMC,MAAZ,IAAsBT,OAAtB,EAAgC;AAC/B,UAAMU,KAAK,GAAG,0CAAwBD,MAAxB,CAAd;AACAD,IAAAA,gBAAgB,CAAEC,MAAM,CAACE,OAAT,CAAhB,GACCH,gBAAgB,CAAEC,MAAM,CAACE,OAAT,CAAhB,IAAsC,EADvC;AAEAH,IAAAA,gBAAgB,CAAEC,MAAM,CAACE,OAAT,CAAhB,CAAmCb,IAAnC,CAAyCY,KAAzC;AACA;;AAED,OAAM,MAAME,SAAZ,IAAyBJ,gBAAzB,EAA4C;AAC3C,QAAKA,gBAAgB,CAACK,cAAjB,CAAiCD,SAAjC,CAAL,EAAoD;AACnD;AACA9B,MAAAA,QAAQ,CACP,8BACC,kCAAuB8B,SAAvB,CADD,EAECJ,gBAAgB,CAAEI,SAAF,CAFjB,CADO,CAAR;AAMA;AACD;AACD,CA5BK","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { persistStubPost, setWidgetAreasOpenState } from './actions';\nimport {\n\tKIND,\n\tWIDGET_AREA_ENTITY_TYPE,\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tbuildWidgetAreasPostId,\n} from './utils';\nimport { transformWidgetToBlock } from './transformers';\n\n/**\n * Creates a \"stub\" widgets post reflecting all available widget areas. The\n * post is meant as a convenient to only exists in runtime and should never be saved. It\n * enables a convenient way of editing the widgets by using a regular post editor.\n *\n * Fetches all widgets from all widgets aras, converts them into blocks, and hydrates a new post with them.\n *\n * @return {Function} An action creator.\n */\nexport const getWidgetAreas =\n\t() =>\n\tasync ( { dispatch, registry } ) => {\n\t\tconst query = buildWidgetAreasQuery();\n\t\tconst widgetAreas = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEntityRecords( KIND, WIDGET_AREA_ENTITY_TYPE, query );\n\n\t\tconst widgetAreaBlocks = [];\n\t\tconst sortedWidgetAreas = widgetAreas.sort( ( a, b ) => {\n\t\t\tif ( a.id === 'wp_inactive_widgets' ) {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tif ( b.id === 'wp_inactive_widgets' ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 0;\n\t\t} );\n\t\tfor ( const widgetArea of sortedWidgetAreas ) {\n\t\t\twidgetAreaBlocks.push(\n\t\t\t\tcreateBlock( 'core/widget-area', {\n\t\t\t\t\tid: widgetArea.id,\n\t\t\t\t\tname: widgetArea.name,\n\t\t\t\t} )\n\t\t\t);\n\n\t\t\tif ( ! widgetArea.widgets.length ) {\n\t\t\t\t// If this widget area has no widgets, it won't get a post setup by\n\t\t\t\t// the getWidgets resolver.\n\t\t\t\tdispatch(\n\t\t\t\t\tpersistStubPost(\n\t\t\t\t\t\tbuildWidgetAreaPostId( widgetArea.id ),\n\t\t\t\t\t\t[]\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst widgetAreasOpenState = {};\n\t\twidgetAreaBlocks.forEach( ( widgetAreaBlock, index ) => {\n\t\t\t// Defaults to open the first widget area.\n\t\t\twidgetAreasOpenState[ widgetAreaBlock.clientId ] = index === 0;\n\t\t} );\n\t\tdispatch( setWidgetAreasOpenState( widgetAreasOpenState ) );\n\n\t\tdispatch(\n\t\t\tpersistStubPost( buildWidgetAreasPostId(), widgetAreaBlocks )\n\t\t);\n\t};\n\n/**\n * Fetches all widgets from all widgets ares, and groups them by widget area Id.\n *\n * @return {Function} An action creator.\n */\nexport const getWidgets =\n\t() =>\n\tasync ( { dispatch, registry } ) => {\n\t\tconst query = buildWidgetsQuery();\n\t\tconst widgets = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEntityRecords( 'root', 'widget', query );\n\n\t\tconst groupedBySidebar = {};\n\n\t\tfor ( const widget of widgets ) {\n\t\t\tconst block = transformWidgetToBlock( widget );\n\t\t\tgroupedBySidebar[ widget.sidebar ] =\n\t\t\t\tgroupedBySidebar[ widget.sidebar ] || [];\n\t\t\tgroupedBySidebar[ widget.sidebar ].push( block );\n\t\t}\n\n\t\tfor ( const sidebarId in groupedBySidebar ) {\n\t\t\tif ( groupedBySidebar.hasOwnProperty( sidebarId ) ) {\n\t\t\t\t// Persist the actual post containing the widget block\n\t\t\t\tdispatch(\n\t\t\t\t\tpersistStubPost(\n\t\t\t\t\t\tbuildWidgetAreaPostId( sidebarId ),\n\t\t\t\t\t\tgroupedBySidebar[ sidebarId ]\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t};\n"]}
|
package/build/store/selectors.js
CHANGED
|
@@ -37,9 +37,9 @@ var _constants = require("./constants");
|
|
|
37
37
|
const getWidgets = (0, _data.createRegistrySelector)(select => () => {
|
|
38
38
|
const widgets = select(_coreData.store).getEntityRecords('root', 'widget', (0, _utils.buildWidgetsQuery)());
|
|
39
39
|
return (// Key widgets by their ID.
|
|
40
|
-
|
|
40
|
+
widgets?.reduce((allWidgets, widget) => ({ ...allWidgets,
|
|
41
41
|
[widget.id]: widget
|
|
42
|
-
}), {})
|
|
42
|
+
}), {}) || {}
|
|
43
43
|
);
|
|
44
44
|
});
|
|
45
45
|
/**
|
|
@@ -116,25 +116,16 @@ const getEditedWidgetAreas = (0, _data.createRegistrySelector)(select => (state,
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
if (ids) {
|
|
119
|
-
widgetAreas = widgetAreas.filter(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
} = _ref;
|
|
123
|
-
return ids.includes(id);
|
|
124
|
-
});
|
|
119
|
+
widgetAreas = widgetAreas.filter(({
|
|
120
|
+
id
|
|
121
|
+
}) => ids.includes(id));
|
|
125
122
|
}
|
|
126
123
|
|
|
127
|
-
return widgetAreas.filter(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}).map(_ref3 => {
|
|
133
|
-
let {
|
|
134
|
-
id
|
|
135
|
-
} = _ref3;
|
|
136
|
-
return select(_coreData.store).getEditedEntityRecord(_utils.KIND, _utils.WIDGET_AREA_ENTITY_TYPE, id);
|
|
137
|
-
});
|
|
124
|
+
return widgetAreas.filter(({
|
|
125
|
+
id
|
|
126
|
+
}) => select(_coreData.store).hasEditsForEntityRecord(_utils.KIND, _utils.POST_TYPE, (0, _utils.buildWidgetAreaPostId)(id))).map(({
|
|
127
|
+
id
|
|
128
|
+
}) => select(_coreData.store).getEditedEntityRecord(_utils.KIND, _utils.WIDGET_AREA_ENTITY_TYPE, id));
|
|
138
129
|
});
|
|
139
130
|
/**
|
|
140
131
|
* Returns all blocks representing reference widgets.
|
|
@@ -144,8 +135,7 @@ const getEditedWidgetAreas = (0, _data.createRegistrySelector)(select => (state,
|
|
|
144
135
|
*/
|
|
145
136
|
|
|
146
137
|
exports.getEditedWidgetAreas = getEditedWidgetAreas;
|
|
147
|
-
const getReferenceWidgetBlocks = (0, _data.createRegistrySelector)(select =>
|
|
148
|
-
let referenceWidgetName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
138
|
+
const getReferenceWidgetBlocks = (0, _data.createRegistrySelector)(select => (state, referenceWidgetName = null) => {
|
|
149
139
|
const results = [];
|
|
150
140
|
const widgetAreas = select(_constants.STORE_NAME).getWidgetAreas();
|
|
151
141
|
|
|
@@ -153,9 +143,7 @@ const getReferenceWidgetBlocks = (0, _data.createRegistrySelector)(select => fun
|
|
|
153
143
|
const post = select(_coreData.store).getEditedEntityRecord(_utils.KIND, _utils.POST_TYPE, (0, _utils.buildWidgetAreaPostId)(_widgetArea.id));
|
|
154
144
|
|
|
155
145
|
for (const block of post.blocks) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (block.name === 'core/legacy-widget' && (!referenceWidgetName || ((_block$attributes = block.attributes) === null || _block$attributes === void 0 ? void 0 : _block$attributes.referenceWidgetName) === referenceWidgetName)) {
|
|
146
|
+
if (block.name === 'core/legacy-widget' && (!referenceWidgetName || block.attributes?.referenceWidgetName === referenceWidgetName)) {
|
|
159
147
|
results.push(block);
|
|
160
148
|
}
|
|
161
149
|
}
|
|
@@ -171,14 +159,9 @@ const getReferenceWidgetBlocks = (0, _data.createRegistrySelector)(select => fun
|
|
|
171
159
|
|
|
172
160
|
exports.getReferenceWidgetBlocks = getReferenceWidgetBlocks;
|
|
173
161
|
const isSavingWidgetAreas = (0, _data.createRegistrySelector)(select => () => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
let {
|
|
178
|
-
id
|
|
179
|
-
} = _ref4;
|
|
180
|
-
return id;
|
|
181
|
-
});
|
|
162
|
+
const widgetAreasIds = select(_constants.STORE_NAME).getWidgetAreas()?.map(({
|
|
163
|
+
id
|
|
164
|
+
}) => id);
|
|
182
165
|
|
|
183
166
|
if (!widgetAreasIds) {
|
|
184
167
|
return false;
|