@wordpress/edit-widgets 6.32.0 → 6.32.1-next.47f435fc9.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/block.json +26 -0
- package/build/blocks/widget-area/edit/index.js +94 -87
- package/build/blocks/widget-area/edit/index.js.map +7 -1
- package/build/blocks/widget-area/edit/inner-blocks.js +68 -50
- package/build/blocks/widget-area/edit/inner-blocks.js.map +7 -1
- package/build/blocks/widget-area/edit/use-is-dragging-within.js +34 -40
- package/build/blocks/widget-area/edit/use-is-dragging-within.js.map +7 -1
- package/build/blocks/widget-area/index.js +49 -52
- package/build/blocks/widget-area/index.js.map +7 -1
- package/build/components/error-boundary/index.js +49 -51
- package/build/components/error-boundary/index.js.map +7 -1
- package/build/components/header/document-tools/index.js +104 -74
- package/build/components/header/document-tools/index.js.map +7 -1
- package/build/components/header/index.js +81 -62
- package/build/components/header/index.js.map +7 -1
- package/build/components/header/undo-redo/redo.js +50 -38
- package/build/components/header/undo-redo/redo.js.map +7 -1
- package/build/components/header/undo-redo/undo.js +49 -37
- package/build/components/header/undo-redo/undo.js.map +7 -1
- package/build/components/keyboard-shortcut-help-modal/config.js +74 -71
- package/build/components/keyboard-shortcut-help-modal/config.js.map +7 -1
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +61 -44
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +7 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +154 -103
- package/build/components/keyboard-shortcut-help-modal/index.js.map +7 -1
- package/build/components/keyboard-shortcut-help-modal/shortcut.js +74 -56
- package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +7 -1
- package/build/components/keyboard-shortcuts/index.js +89 -82
- package/build/components/keyboard-shortcuts/index.js.map +7 -1
- package/build/components/layout/index.js +75 -49
- package/build/components/layout/index.js.map +7 -1
- package/build/components/layout/interface.js +89 -75
- package/build/components/layout/interface.js.map +7 -1
- package/build/components/layout/unsaved-changes-warning.js +35 -42
- package/build/components/layout/unsaved-changes-warning.js.map +7 -1
- package/build/components/more-menu/index.js +189 -108
- package/build/components/more-menu/index.js.map +7 -1
- package/build/components/more-menu/tools-more-menu-group.js +29 -23
- package/build/components/more-menu/tools-more-menu-group.js.map +7 -1
- package/build/components/notices/index.js +62 -48
- package/build/components/notices/index.js.map +7 -1
- package/build/components/save-button/index.js +55 -47
- package/build/components/save-button/index.js.map +7 -1
- package/build/components/secondary-sidebar/index.js +41 -34
- package/build/components/secondary-sidebar/index.js.map +7 -1
- package/build/components/secondary-sidebar/inserter-sidebar.js +55 -46
- package/build/components/secondary-sidebar/inserter-sidebar.js.map +7 -1
- package/build/components/secondary-sidebar/list-view-sidebar.js +76 -67
- package/build/components/secondary-sidebar/list-view-sidebar.js.map +7 -1
- package/build/components/sidebar/index.js +149 -138
- package/build/components/sidebar/index.js.map +7 -1
- package/build/components/sidebar/widget-areas.js +73 -57
- package/build/components/sidebar/widget-areas.js.map +7 -1
- package/build/components/welcome-guide/index.js +182 -137
- package/build/components/welcome-guide/index.js.map +7 -1
- package/build/components/widget-areas-block-editor-content/index.js +64 -43
- package/build/components/widget-areas-block-editor-content/index.js.map +7 -1
- package/build/components/widget-areas-block-editor-provider/index.js +115 -92
- package/build/components/widget-areas-block-editor-provider/index.js.map +7 -1
- package/build/constants.js +30 -8
- package/build/constants.js.map +7 -1
- package/build/filters/index.js +3 -5
- package/build/filters/index.js.map +7 -1
- package/build/filters/move-to-widget-area.js +52 -59
- package/build/filters/move-to-widget-area.js.map +7 -1
- package/build/filters/replace-media-upload.js +9 -11
- package/build/filters/replace-media-upload.js.map +7 -1
- package/build/hooks/use-last-selected-widget-area.js +38 -44
- package/build/hooks/use-last-selected-widget-area.js.map +7 -1
- package/build/hooks/use-widget-library-insertion-point.js +60 -55
- package/build/hooks/use-widget-library-insertion-point.js.map +7 -1
- package/build/index.js +86 -93
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -15
- package/build/lock-unlock.js.map +7 -1
- package/build/store/actions.js +181 -313
- package/build/store/actions.js.map +7 -1
- package/build/store/constants.js +27 -10
- package/build/store/constants.js.map +7 -1
- package/build/store/index.js +51 -51
- package/build/store/index.js.map +7 -1
- package/build/store/private-selectors.js +28 -7
- package/build/store/private-selectors.js.map +7 -1
- package/build/store/reducer.js +65 -118
- package/build/store/reducer.js.map +7 -1
- package/build/store/resolvers.js +64 -63
- package/build/store/resolvers.js.map +7 -1
- package/build/store/selectors.js +194 -231
- package/build/store/selectors.js.map +7 -1
- package/build/store/transformers.js +47 -41
- package/build/store/transformers.js.map +7 -1
- package/build/store/utils.js +47 -70
- package/build/store/utils.js.map +7 -1
- package/build-module/blocks/widget-area/block.json +26 -0
- package/build-module/blocks/widget-area/edit/index.js +63 -75
- package/build-module/blocks/widget-area/edit/index.js.map +7 -1
- package/build-module/blocks/widget-area/edit/inner-blocks.js +38 -41
- package/build-module/blocks/widget-area/edit/inner-blocks.js.map +7 -1
- package/build-module/blocks/widget-area/edit/use-is-dragging-within.js +14 -33
- package/build-module/blocks/widget-area/edit/use-is-dragging-within.js.map +7 -1
- package/build-module/blocks/widget-area/index.js +14 -46
- package/build-module/blocks/widget-area/index.js.map +7 -1
- package/build-module/components/error-boundary/index.js +30 -43
- package/build-module/components/error-boundary/index.js.map +7 -1
- package/build-module/components/header/document-tools/index.js +75 -66
- package/build-module/components/header/document-tools/index.js.map +7 -1
- package/build-module/components/header/index.js +52 -54
- package/build-module/components/header/index.js.map +7 -1
- package/build-module/components/header/undo-redo/redo.js +32 -32
- package/build-module/components/header/undo-redo/redo.js.map +7 -1
- package/build-module/components/header/undo-redo/undo.js +31 -31
- package/build-module/components/header/undo-redo/undo.js.map +7 -1
- package/build-module/components/keyboard-shortcut-help-modal/config.js +62 -75
- package/build-module/components/keyboard-shortcut-help-modal/config.js.map +7 -1
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +33 -37
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +7 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +130 -97
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +7 -1
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js +56 -50
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js.map +7 -1
- package/build-module/components/keyboard-shortcuts/index.js +73 -75
- package/build-module/components/keyboard-shortcuts/index.js.map +7 -1
- package/build-module/components/layout/index.js +46 -41
- package/build-module/components/layout/index.js.map +7 -1
- package/build-module/components/layout/interface.js +63 -66
- package/build-module/components/layout/interface.js.map +7 -1
- package/build-module/components/layout/unsaved-changes-warning.js +17 -37
- package/build-module/components/layout/unsaved-changes-warning.js.map +7 -1
- package/build-module/components/more-menu/index.js +167 -102
- package/build-module/components/more-menu/index.js.map +7 -1
- package/build-module/components/more-menu/tools-more-menu-group.js +11 -17
- package/build-module/components/more-menu/tools-more-menu-group.js.map +7 -1
- package/build-module/components/notices/index.js +43 -42
- package/build-module/components/notices/index.js.map +7 -1
- package/build-module/components/save-button/index.js +37 -41
- package/build-module/components/save-button/index.js.map +7 -1
- package/build-module/components/secondary-sidebar/index.js +14 -27
- package/build-module/components/secondary-sidebar/index.js.map +7 -1
- package/build-module/components/secondary-sidebar/inserter-sidebar.js +26 -38
- package/build-module/components/secondary-sidebar/inserter-sidebar.js.map +7 -1
- package/build-module/components/secondary-sidebar/list-view-sidebar.js +57 -60
- package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +7 -1
- package/build-module/components/sidebar/index.js +129 -127
- package/build-module/components/sidebar/index.js.map +7 -1
- package/build-module/components/sidebar/widget-areas.js +53 -49
- package/build-module/components/sidebar/widget-areas.js.map +7 -1
- package/build-module/components/welcome-guide/index.js +165 -132
- package/build-module/components/welcome-guide/index.js.map +7 -1
- package/build-module/components/widget-areas-block-editor-content/index.js +43 -36
- package/build-module/components/widget-areas-block-editor-content/index.js.map +7 -1
- package/build-module/components/widget-areas-block-editor-provider/index.js +85 -83
- package/build-module/components/widget-areas-block-editor-provider/index.js.map +7 -1
- package/build-module/constants.js +7 -3
- package/build-module/constants.js.map +7 -1
- package/build-module/filters/index.js +3 -6
- package/build-module/filters/index.js.map +7 -1
- package/build-module/filters/move-to-widget-area.js +52 -57
- package/build-module/filters/move-to-widget-area.js.map +7 -1
- package/build-module/filters/replace-media-upload.js +8 -7
- package/build-module/filters/replace-media-upload.js.map +7 -1
- package/build-module/hooks/use-last-selected-widget-area.js +20 -39
- package/build-module/hooks/use-last-selected-widget-area.js.map +7 -1
- package/build-module/hooks/use-widget-library-insertion-point.js +42 -49
- package/build-module/hooks/use-widget-library-insertion-point.js.map +7 -1
- package/build-module/index.js +60 -72
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/store/actions.js +153 -293
- package/build-module/store/actions.js.map +7 -1
- package/build-module/store/constants.js +5 -5
- package/build-module/store/constants.js.map +7 -1
- package/build-module/store/index.js +16 -40
- package/build-module/store/index.js.map +7 -1
- package/build-module/store/private-selectors.js +7 -3
- package/build-module/store/private-selectors.js.map +7 -1
- package/build-module/store/reducer.js +42 -111
- package/build-module/store/reducer.js.map +7 -1
- package/build-module/store/resolvers.js +43 -51
- package/build-module/store/resolvers.js.map +7 -1
- package/build-module/store/selectors.js +171 -224
- package/build-module/store/selectors.js.map +7 -1
- package/build-module/store/transformers.js +23 -34
- package/build-module/store/transformers.js.map +7 -1
- package/build-module/store/utils.js +22 -63
- package/build-module/store/utils.js.map +7 -1
- package/build-style/style-rtl.css +216 -88
- package/build-style/style.css +216 -88
- package/package.json +36 -29
- package/src/blocks/widget-area/editor.scss +3 -0
- package/src/components/customizer-edit-widgets-initializer/style.scss +3 -0
- package/src/components/error-boundary/style.scss +2 -0
- package/src/components/header/style.scss +5 -0
- package/src/components/keyboard-shortcut-help-modal/style.scss +2 -0
- package/src/components/layout/style.scss +3 -0
- package/src/components/more-menu/style.scss +2 -0
- package/src/components/notices/style.scss +3 -0
- package/src/components/secondary-sidebar/style.scss +4 -0
- package/src/components/sidebar/style.scss +2 -0
- package/src/components/welcome-guide/style.scss +2 -0
- package/src/components/widget-areas-block-editor-content/style.scss +2 -0
- package/src/style.scss +16 -13
package/build/lock-unlock.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lock-unlock.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/edit-widgets'\n\t);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAiE;AAE1D,MAAM,EAAE,MAAM,OAAO,QAC3B;AAAA,EACC;AAAA,EACA;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/store/actions.js
CHANGED
|
@@ -1,136 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var actions_exports = {};
|
|
19
|
+
__export(actions_exports, {
|
|
20
|
+
closeGeneralSidebar: () => closeGeneralSidebar,
|
|
21
|
+
lockWidgetSaving: () => lockWidgetSaving,
|
|
22
|
+
moveBlockToWidgetArea: () => moveBlockToWidgetArea,
|
|
23
|
+
persistStubPost: () => persistStubPost,
|
|
24
|
+
saveEditedWidgetAreas: () => saveEditedWidgetAreas,
|
|
25
|
+
saveWidgetArea: () => saveWidgetArea,
|
|
26
|
+
saveWidgetAreas: () => saveWidgetAreas,
|
|
27
|
+
setIsInserterOpened: () => setIsInserterOpened,
|
|
28
|
+
setIsListViewOpened: () => setIsListViewOpened,
|
|
29
|
+
setIsWidgetAreaOpen: () => setIsWidgetAreaOpen,
|
|
30
|
+
setWidgetAreasOpenState: () => setWidgetAreasOpenState,
|
|
31
|
+
setWidgetIdForClientId: () => setWidgetIdForClientId,
|
|
32
|
+
unlockWidgetSaving: () => unlockWidgetSaving
|
|
5
33
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* WordPress dependencies
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Internal dependencies
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Persists a stub post with given ID to core data store. The post is meant to be in-memory only and
|
|
34
|
-
* shouldn't be saved via the API.
|
|
35
|
-
*
|
|
36
|
-
* @param {string} id Post ID.
|
|
37
|
-
* @param {Array} blocks Blocks the post should consist of.
|
|
38
|
-
* @return {Object} The post object.
|
|
39
|
-
*/
|
|
40
|
-
const persistStubPost = (id, blocks) => ({
|
|
41
|
-
registry
|
|
42
|
-
}) => {
|
|
43
|
-
const stubPost = (0, _utils.createStubPost)(id, blocks);
|
|
44
|
-
registry.dispatch(_coreData.store).receiveEntityRecords(_utils.KIND, _utils.POST_TYPE, stubPost, {
|
|
45
|
-
id: stubPost.id
|
|
46
|
-
}, false);
|
|
34
|
+
module.exports = __toCommonJS(actions_exports);
|
|
35
|
+
var import_i18n = require("@wordpress/i18n");
|
|
36
|
+
var import_notices = require("@wordpress/notices");
|
|
37
|
+
var import_interface = require("@wordpress/interface");
|
|
38
|
+
var import_widgets = require("@wordpress/widgets");
|
|
39
|
+
var import_core_data = require("@wordpress/core-data");
|
|
40
|
+
var import_block_editor = require("@wordpress/block-editor");
|
|
41
|
+
var import_transformers = require("./transformers");
|
|
42
|
+
var import_utils = require("./utils");
|
|
43
|
+
var import_constants = require("./constants");
|
|
44
|
+
const persistStubPost = (id, blocks) => ({ registry }) => {
|
|
45
|
+
const stubPost = (0, import_utils.createStubPost)(id, blocks);
|
|
46
|
+
registry.dispatch(import_core_data.store).receiveEntityRecords(
|
|
47
|
+
import_utils.KIND,
|
|
48
|
+
import_utils.POST_TYPE,
|
|
49
|
+
stubPost,
|
|
50
|
+
{ id: stubPost.id },
|
|
51
|
+
false
|
|
52
|
+
);
|
|
47
53
|
return stubPost;
|
|
48
54
|
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Converts all the blocks from edited widget areas into widgets,
|
|
52
|
-
* and submits a batch request to save everything at once.
|
|
53
|
-
*
|
|
54
|
-
* Creates a snackbar notice on either success or error.
|
|
55
|
-
*
|
|
56
|
-
* @return {Function} An action creator.
|
|
57
|
-
*/
|
|
58
|
-
exports.persistStubPost = persistStubPost;
|
|
59
|
-
const saveEditedWidgetAreas = () => async ({
|
|
60
|
-
select,
|
|
61
|
-
dispatch,
|
|
62
|
-
registry
|
|
63
|
-
}) => {
|
|
55
|
+
const saveEditedWidgetAreas = () => async ({ select, dispatch, registry }) => {
|
|
64
56
|
const editedWidgetAreas = select.getEditedWidgetAreas();
|
|
65
57
|
if (!editedWidgetAreas?.length) {
|
|
66
58
|
return;
|
|
67
59
|
}
|
|
68
60
|
try {
|
|
69
61
|
await dispatch.saveWidgetAreas(editedWidgetAreas);
|
|
70
|
-
registry.dispatch(
|
|
71
|
-
type:
|
|
62
|
+
registry.dispatch(import_notices.store).createSuccessNotice((0, import_i18n.__)("Widgets saved."), {
|
|
63
|
+
type: "snackbar"
|
|
72
64
|
});
|
|
73
65
|
} catch (e) {
|
|
74
|
-
registry.dispatch(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
registry.dispatch(import_notices.store).createErrorNotice(
|
|
67
|
+
/* translators: %s: The error message. */
|
|
68
|
+
(0, import_i18n.sprintf)((0, import_i18n.__)("There was an error. %s"), e.message),
|
|
69
|
+
{
|
|
70
|
+
type: "snackbar"
|
|
71
|
+
}
|
|
72
|
+
);
|
|
78
73
|
}
|
|
79
74
|
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Converts all the blocks from specified widget areas into widgets,
|
|
83
|
-
* and submits a batch request to save everything at once.
|
|
84
|
-
*
|
|
85
|
-
* @param {Object[]} widgetAreas Widget areas to save.
|
|
86
|
-
* @return {Function} An action creator.
|
|
87
|
-
*/
|
|
88
|
-
exports.saveEditedWidgetAreas = saveEditedWidgetAreas;
|
|
89
|
-
const saveWidgetAreas = widgetAreas => async ({
|
|
90
|
-
dispatch,
|
|
91
|
-
registry
|
|
92
|
-
}) => {
|
|
75
|
+
const saveWidgetAreas = (widgetAreas) => async ({ dispatch, registry }) => {
|
|
93
76
|
try {
|
|
94
77
|
for (const widgetArea of widgetAreas) {
|
|
95
78
|
await dispatch.saveWidgetArea(widgetArea.id);
|
|
96
79
|
}
|
|
97
80
|
} finally {
|
|
98
|
-
|
|
99
|
-
|
|
81
|
+
await registry.dispatch(import_core_data.store).finishResolution(
|
|
82
|
+
"getEntityRecord",
|
|
83
|
+
import_utils.KIND,
|
|
84
|
+
import_utils.WIDGET_AREA_ENTITY_TYPE,
|
|
85
|
+
(0, import_utils.buildWidgetAreasQuery)()
|
|
86
|
+
);
|
|
100
87
|
}
|
|
101
88
|
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Converts all the blocks from a widget area specified by ID into widgets,
|
|
105
|
-
* and submits a batch request to save everything at once.
|
|
106
|
-
*
|
|
107
|
-
* @param {string} widgetAreaId ID of the widget area to process.
|
|
108
|
-
* @return {Function} An action creator.
|
|
109
|
-
*/
|
|
110
|
-
exports.saveWidgetAreas = saveWidgetAreas;
|
|
111
|
-
const saveWidgetArea = widgetAreaId => async ({
|
|
112
|
-
dispatch,
|
|
113
|
-
select,
|
|
114
|
-
registry
|
|
115
|
-
}) => {
|
|
89
|
+
const saveWidgetArea = (widgetAreaId) => async ({ dispatch, select, registry }) => {
|
|
116
90
|
const widgets = select.getWidgets();
|
|
117
|
-
const post = registry.select(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
// Why? We filter out the widgets with duplicate IDs to prevent adding more than one instance of a widget
|
|
126
|
-
// implemented using a function. WordPress doesn't support having more than one instance of these, if you try to
|
|
127
|
-
// save multiple instances of these in different sidebars you will run into undefined behaviors.
|
|
91
|
+
const post = registry.select(import_core_data.store).getEditedEntityRecord(
|
|
92
|
+
import_utils.KIND,
|
|
93
|
+
import_utils.POST_TYPE,
|
|
94
|
+
(0, import_utils.buildWidgetAreaPostId)(widgetAreaId)
|
|
95
|
+
);
|
|
96
|
+
const areaWidgets = Object.values(widgets).filter(
|
|
97
|
+
({ sidebar }) => sidebar === widgetAreaId
|
|
98
|
+
);
|
|
128
99
|
const usedReferenceWidgets = [];
|
|
129
|
-
const widgetsBlocks = post.blocks.filter(block => {
|
|
130
|
-
const {
|
|
131
|
-
|
|
132
|
-
} = block.attributes;
|
|
133
|
-
if (block.name === 'core/legacy-widget' && id) {
|
|
100
|
+
const widgetsBlocks = post.blocks.filter((block) => {
|
|
101
|
+
const { id } = block.attributes;
|
|
102
|
+
if (block.name === "core/legacy-widget" && id) {
|
|
134
103
|
if (usedReferenceWidgets.includes(id)) {
|
|
135
104
|
return false;
|
|
136
105
|
}
|
|
@@ -138,10 +107,6 @@ const saveWidgetArea = widgetAreaId => async ({
|
|
|
138
107
|
}
|
|
139
108
|
return true;
|
|
140
109
|
});
|
|
141
|
-
|
|
142
|
-
// Determine which widgets have been deleted. We can tell if a widget is
|
|
143
|
-
// deleted and not just moved to a different area by looking to see if
|
|
144
|
-
// getWidgetAreaForWidgetId() finds something.
|
|
145
110
|
const deletedWidgets = [];
|
|
146
111
|
for (const widget of areaWidgets) {
|
|
147
112
|
const widgetsNewArea = select.getWidgetAreaForWidgetId(widget.id);
|
|
@@ -154,39 +119,35 @@ const saveWidgetArea = widgetAreaId => async ({
|
|
|
154
119
|
const sidebarWidgetsIds = [];
|
|
155
120
|
for (let i = 0; i < widgetsBlocks.length; i++) {
|
|
156
121
|
const block = widgetsBlocks[i];
|
|
157
|
-
const widgetId = (0,
|
|
122
|
+
const widgetId = (0, import_widgets.getWidgetIdFromBlock)(block);
|
|
158
123
|
const oldWidget = widgets[widgetId];
|
|
159
|
-
const widget = (0,
|
|
160
|
-
|
|
161
|
-
// We'll replace the null widgetId after save, but we track it here
|
|
162
|
-
// since order is important.
|
|
124
|
+
const widget = (0, import_transformers.transformBlockToWidget)(block, oldWidget);
|
|
163
125
|
sidebarWidgetsIds.push(widgetId);
|
|
164
|
-
|
|
165
|
-
// Check oldWidget as widgetId might refer to an ID which has been
|
|
166
|
-
// deleted, e.g. if a deleted block is restored via undo after saving.
|
|
167
126
|
if (oldWidget) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
127
|
+
registry.dispatch(import_core_data.store).editEntityRecord(
|
|
128
|
+
"root",
|
|
129
|
+
"widget",
|
|
130
|
+
widgetId,
|
|
131
|
+
{
|
|
132
|
+
...widget,
|
|
133
|
+
sidebar: widgetAreaId
|
|
134
|
+
},
|
|
135
|
+
{ undoIgnore: true }
|
|
136
|
+
);
|
|
137
|
+
const hasEdits = registry.select(import_core_data.store).hasEditsForEntityRecord("root", "widget", widgetId);
|
|
176
138
|
if (!hasEdits) {
|
|
177
139
|
continue;
|
|
178
140
|
}
|
|
179
|
-
batchTasks.push(
|
|
180
|
-
saveEditedEntityRecord
|
|
181
|
-
|
|
141
|
+
batchTasks.push(
|
|
142
|
+
({ saveEditedEntityRecord }) => saveEditedEntityRecord("root", "widget", widgetId)
|
|
143
|
+
);
|
|
182
144
|
} else {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}));
|
|
145
|
+
batchTasks.push(
|
|
146
|
+
({ saveEntityRecord }) => saveEntityRecord("root", "widget", {
|
|
147
|
+
...widget,
|
|
148
|
+
sidebar: widgetAreaId
|
|
149
|
+
})
|
|
150
|
+
);
|
|
190
151
|
}
|
|
191
152
|
batchMeta.push({
|
|
192
153
|
block,
|
|
@@ -195,26 +156,22 @@ const saveWidgetArea = widgetAreaId => async ({
|
|
|
195
156
|
});
|
|
196
157
|
}
|
|
197
158
|
for (const widget of deletedWidgets) {
|
|
198
|
-
batchTasks.push(
|
|
199
|
-
deleteEntityRecord
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
159
|
+
batchTasks.push(
|
|
160
|
+
({ deleteEntityRecord }) => deleteEntityRecord("root", "widget", widget.id, {
|
|
161
|
+
force: true
|
|
162
|
+
})
|
|
163
|
+
);
|
|
203
164
|
}
|
|
204
|
-
const records = await registry.dispatch(
|
|
205
|
-
const preservedRecords = records.filter(
|
|
165
|
+
const records = await registry.dispatch(import_core_data.store).__experimentalBatch(batchTasks);
|
|
166
|
+
const preservedRecords = records.filter(
|
|
167
|
+
(record) => !record.hasOwnProperty("deleted")
|
|
168
|
+
);
|
|
206
169
|
const failedWidgetNames = [];
|
|
207
170
|
for (let i = 0; i < preservedRecords.length; i++) {
|
|
208
171
|
const widget = preservedRecords[i];
|
|
209
|
-
const {
|
|
210
|
-
block,
|
|
211
|
-
position
|
|
212
|
-
} = batchMeta[i];
|
|
213
|
-
|
|
214
|
-
// Set __internalWidgetId on the block. This will be persisted to the
|
|
215
|
-
// store when we dispatch receiveEntityRecords( post ) below.
|
|
172
|
+
const { block, position } = batchMeta[i];
|
|
216
173
|
post.blocks[position].attributes.__internalWidgetId = widget.id;
|
|
217
|
-
const error = registry.select(
|
|
174
|
+
const error = registry.select(import_core_data.store).getLastEntitySaveError("root", "widget", widget.id);
|
|
218
175
|
if (error) {
|
|
219
176
|
failedWidgetNames.push(block.attributes?.name || block?.name);
|
|
220
177
|
}
|
|
@@ -223,208 +180,119 @@ const saveWidgetArea = widgetAreaId => async ({
|
|
|
223
180
|
}
|
|
224
181
|
}
|
|
225
182
|
if (failedWidgetNames.length) {
|
|
226
|
-
throw new Error(
|
|
227
|
-
|
|
183
|
+
throw new Error(
|
|
184
|
+
(0, import_i18n.sprintf)(
|
|
185
|
+
/* translators: %s: List of widget names */
|
|
186
|
+
(0, import_i18n.__)("Could not save the following widgets: %s."),
|
|
187
|
+
failedWidgetNames.join(", ")
|
|
188
|
+
)
|
|
189
|
+
);
|
|
228
190
|
}
|
|
229
|
-
registry.dispatch(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
191
|
+
registry.dispatch(import_core_data.store).editEntityRecord(
|
|
192
|
+
import_utils.KIND,
|
|
193
|
+
import_utils.WIDGET_AREA_ENTITY_TYPE,
|
|
194
|
+
widgetAreaId,
|
|
195
|
+
{
|
|
196
|
+
widgets: sidebarWidgetsIds
|
|
197
|
+
},
|
|
198
|
+
{ undoIgnore: true }
|
|
199
|
+
);
|
|
234
200
|
dispatch(trySaveWidgetArea(widgetAreaId));
|
|
235
|
-
registry.dispatch(
|
|
201
|
+
registry.dispatch(import_core_data.store).receiveEntityRecords(import_utils.KIND, import_utils.POST_TYPE, post, void 0);
|
|
236
202
|
};
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
203
|
+
const trySaveWidgetArea = (widgetAreaId) => ({ registry }) => {
|
|
204
|
+
registry.dispatch(import_core_data.store).saveEditedEntityRecord(
|
|
205
|
+
import_utils.KIND,
|
|
206
|
+
import_utils.WIDGET_AREA_ENTITY_TYPE,
|
|
207
|
+
widgetAreaId,
|
|
208
|
+
{
|
|
209
|
+
throwOnError: true
|
|
210
|
+
}
|
|
211
|
+
);
|
|
244
212
|
};
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Sets the clientId stored for a particular widgetId.
|
|
248
|
-
*
|
|
249
|
-
* @param {number} clientId Client id.
|
|
250
|
-
* @param {number} widgetId Widget id.
|
|
251
|
-
*
|
|
252
|
-
* @return {Object} Action.
|
|
253
|
-
*/
|
|
254
213
|
function setWidgetIdForClientId(clientId, widgetId) {
|
|
255
214
|
return {
|
|
256
|
-
type:
|
|
215
|
+
type: "SET_WIDGET_ID_FOR_CLIENT_ID",
|
|
257
216
|
clientId,
|
|
258
217
|
widgetId
|
|
259
218
|
};
|
|
260
219
|
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Sets the open state of all the widget areas.
|
|
264
|
-
*
|
|
265
|
-
* @param {Object} widgetAreasOpenState The open states of all the widget areas.
|
|
266
|
-
*
|
|
267
|
-
* @return {Object} Action.
|
|
268
|
-
*/
|
|
269
220
|
function setWidgetAreasOpenState(widgetAreasOpenState) {
|
|
270
221
|
return {
|
|
271
|
-
type:
|
|
222
|
+
type: "SET_WIDGET_AREAS_OPEN_STATE",
|
|
272
223
|
widgetAreasOpenState
|
|
273
224
|
};
|
|
274
225
|
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Sets the open state of the widget area.
|
|
278
|
-
*
|
|
279
|
-
* @param {string} clientId The clientId of the widget area.
|
|
280
|
-
* @param {boolean} isOpen Whether the widget area should be opened.
|
|
281
|
-
*
|
|
282
|
-
* @return {Object} Action.
|
|
283
|
-
*/
|
|
284
226
|
function setIsWidgetAreaOpen(clientId, isOpen) {
|
|
285
227
|
return {
|
|
286
|
-
type:
|
|
228
|
+
type: "SET_IS_WIDGET_AREA_OPEN",
|
|
287
229
|
clientId,
|
|
288
230
|
isOpen
|
|
289
231
|
};
|
|
290
232
|
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Returns an action object used to open/close the inserter.
|
|
294
|
-
*
|
|
295
|
-
* @param {boolean|Object} value Whether the inserter should be
|
|
296
|
-
* opened (true) or closed (false).
|
|
297
|
-
* To specify an insertion point,
|
|
298
|
-
* use an object.
|
|
299
|
-
* @param {string} value.rootClientId The root client ID to insert at.
|
|
300
|
-
* @param {number} value.insertionIndex The index to insert at.
|
|
301
|
-
*
|
|
302
|
-
* @return {Object} Action object.
|
|
303
|
-
*/
|
|
304
233
|
function setIsInserterOpened(value) {
|
|
305
234
|
return {
|
|
306
|
-
type:
|
|
235
|
+
type: "SET_IS_INSERTER_OPENED",
|
|
307
236
|
value
|
|
308
237
|
};
|
|
309
238
|
}
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Returns an action object used to open/close the list view.
|
|
313
|
-
*
|
|
314
|
-
* @param {boolean} isOpen A boolean representing whether the list view should be opened or closed.
|
|
315
|
-
* @return {Object} Action object.
|
|
316
|
-
*/
|
|
317
239
|
function setIsListViewOpened(isOpen) {
|
|
318
240
|
return {
|
|
319
|
-
type:
|
|
241
|
+
type: "SET_IS_LIST_VIEW_OPENED",
|
|
320
242
|
isOpen
|
|
321
243
|
};
|
|
322
244
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
* Returns an action object signalling that the user closed the sidebar.
|
|
326
|
-
*
|
|
327
|
-
* @return {Object} Action creator.
|
|
328
|
-
*/
|
|
329
|
-
const closeGeneralSidebar = () => ({
|
|
330
|
-
registry
|
|
331
|
-
}) => {
|
|
332
|
-
registry.dispatch(_interface.store).disableComplementaryArea(_constants.STORE_NAME);
|
|
245
|
+
const closeGeneralSidebar = () => ({ registry }) => {
|
|
246
|
+
registry.dispatch(import_interface.store).disableComplementaryArea(import_constants.STORE_NAME);
|
|
333
247
|
};
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
*/
|
|
341
|
-
exports.closeGeneralSidebar = closeGeneralSidebar;
|
|
342
|
-
const moveBlockToWidgetArea = (clientId, widgetAreaId) => async ({
|
|
343
|
-
dispatch,
|
|
344
|
-
select,
|
|
345
|
-
registry
|
|
346
|
-
}) => {
|
|
347
|
-
const sourceRootClientId = registry.select(_blockEditor.store).getBlockRootClientId(clientId);
|
|
348
|
-
|
|
349
|
-
// Search the top level blocks (widget areas) for the one with the matching
|
|
350
|
-
// id attribute. Makes the assumption that all top-level blocks are widget
|
|
351
|
-
// areas.
|
|
352
|
-
const widgetAreas = registry.select(_blockEditor.store).getBlocks();
|
|
353
|
-
const destinationWidgetAreaBlock = widgetAreas.find(({
|
|
354
|
-
attributes
|
|
355
|
-
}) => attributes.id === widgetAreaId);
|
|
248
|
+
const moveBlockToWidgetArea = (clientId, widgetAreaId) => async ({ dispatch, select, registry }) => {
|
|
249
|
+
const sourceRootClientId = registry.select(import_block_editor.store).getBlockRootClientId(clientId);
|
|
250
|
+
const widgetAreas = registry.select(import_block_editor.store).getBlocks();
|
|
251
|
+
const destinationWidgetAreaBlock = widgetAreas.find(
|
|
252
|
+
({ attributes }) => attributes.id === widgetAreaId
|
|
253
|
+
);
|
|
356
254
|
const destinationRootClientId = destinationWidgetAreaBlock.clientId;
|
|
357
|
-
|
|
358
|
-
// Get the index for moving to the end of the destination widget area.
|
|
359
|
-
const destinationInnerBlocksClientIds = registry.select(_blockEditor.store).getBlockOrder(destinationRootClientId);
|
|
255
|
+
const destinationInnerBlocksClientIds = registry.select(import_block_editor.store).getBlockOrder(destinationRootClientId);
|
|
360
256
|
const destinationIndex = destinationInnerBlocksClientIds.length;
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
257
|
+
const isDestinationWidgetAreaOpen = select.getIsWidgetAreaOpen(
|
|
258
|
+
destinationRootClientId
|
|
259
|
+
);
|
|
364
260
|
if (!isDestinationWidgetAreaOpen) {
|
|
365
261
|
dispatch.setIsWidgetAreaOpen(destinationRootClientId, true);
|
|
366
262
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
263
|
+
registry.dispatch(import_block_editor.store).moveBlocksToPosition(
|
|
264
|
+
[clientId],
|
|
265
|
+
sourceRootClientId,
|
|
266
|
+
destinationRootClientId,
|
|
267
|
+
destinationIndex
|
|
268
|
+
);
|
|
370
269
|
};
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Returns an action object used to signal that widget saving is unlocked.
|
|
374
|
-
*
|
|
375
|
-
* @param {string} lockName The lock name.
|
|
376
|
-
*
|
|
377
|
-
* @example
|
|
378
|
-
* ```js
|
|
379
|
-
* import { store as widgetStore } from '@wordpress/edit-widgets';
|
|
380
|
-
* import { useDispatch } from '@wordpress/data';
|
|
381
|
-
*
|
|
382
|
-
* const ExampleComponent = () => {
|
|
383
|
-
* const { unlockWidgetSaving } = useDispatch( widgetStore );
|
|
384
|
-
* return (
|
|
385
|
-
* <Button onClick={ () => unlockWidgetSaving( 'lockName' ) }>
|
|
386
|
-
* { __( 'Unlock Widget Saving' ) }
|
|
387
|
-
* </Button>
|
|
388
|
-
* );
|
|
389
|
-
* };
|
|
390
|
-
* ```
|
|
391
|
-
*
|
|
392
|
-
* @return {Object} Action object
|
|
393
|
-
*/
|
|
394
|
-
exports.moveBlockToWidgetArea = moveBlockToWidgetArea;
|
|
395
270
|
function unlockWidgetSaving(lockName) {
|
|
396
271
|
return {
|
|
397
|
-
type:
|
|
272
|
+
type: "UNLOCK_WIDGET_SAVING",
|
|
398
273
|
lockName
|
|
399
274
|
};
|
|
400
275
|
}
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* Returns an action object used to signal that widget saving is locked.
|
|
404
|
-
*
|
|
405
|
-
* @param {string} lockName The lock name.
|
|
406
|
-
*
|
|
407
|
-
* @example
|
|
408
|
-
* ```js
|
|
409
|
-
* import { store as widgetStore } from '@wordpress/edit-widgets';
|
|
410
|
-
* import { useDispatch } from '@wordpress/data';
|
|
411
|
-
*
|
|
412
|
-
* const ExampleComponent = () => {
|
|
413
|
-
* const { lockWidgetSaving } = useDispatch( widgetStore );
|
|
414
|
-
* return (
|
|
415
|
-
* <Button onClick={ () => lockWidgetSaving( 'lockName' ) }>
|
|
416
|
-
* { __( 'Lock Widget Saving' ) }
|
|
417
|
-
* </Button>
|
|
418
|
-
* );
|
|
419
|
-
* };
|
|
420
|
-
* ```
|
|
421
|
-
*
|
|
422
|
-
* @return {Object} Action object
|
|
423
|
-
*/
|
|
424
276
|
function lockWidgetSaving(lockName) {
|
|
425
277
|
return {
|
|
426
|
-
type:
|
|
278
|
+
type: "LOCK_WIDGET_SAVING",
|
|
427
279
|
lockName
|
|
428
280
|
};
|
|
429
281
|
}
|
|
430
|
-
|
|
282
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
283
|
+
0 && (module.exports = {
|
|
284
|
+
closeGeneralSidebar,
|
|
285
|
+
lockWidgetSaving,
|
|
286
|
+
moveBlockToWidgetArea,
|
|
287
|
+
persistStubPost,
|
|
288
|
+
saveEditedWidgetAreas,
|
|
289
|
+
saveWidgetArea,
|
|
290
|
+
saveWidgetAreas,
|
|
291
|
+
setIsInserterOpened,
|
|
292
|
+
setIsListViewOpened,
|
|
293
|
+
setIsWidgetAreaOpen,
|
|
294
|
+
setWidgetAreasOpenState,
|
|
295
|
+
setWidgetIdForClientId,
|
|
296
|
+
unlockWidgetSaving
|
|
297
|
+
});
|
|
298
|
+
//# sourceMappingURL=actions.js.map
|