@wordpress/edit-widgets 7.0.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/blocks/widget-area/edit/index.cjs +106 -116
- package/build/blocks/widget-area/edit/index.cjs.map +1 -7
- package/build/blocks/widget-area/edit/inner-blocks.cjs +44 -62
- package/build/blocks/widget-area/edit/inner-blocks.cjs.map +1 -7
- package/build/blocks/widget-area/edit/use-is-dragging-within.cjs +41 -53
- package/build/blocks/widget-area/edit/use-is-dragging-within.cjs.map +1 -7
- package/build/blocks/widget-area/index.cjs +40 -44
- package/build/blocks/widget-area/index.cjs.map +1 -7
- package/build/components/error-boundary/index.cjs +115 -155
- package/build/components/error-boundary/index.cjs.map +1 -7
- package/build/components/header/document-tools/index.cjs +80 -115
- package/build/components/header/document-tools/index.cjs.map +1 -7
- package/build/components/header/index.cjs +72 -80
- package/build/components/header/index.cjs.map +1 -7
- package/build/components/header/undo-redo/redo.cjs +30 -52
- package/build/components/header/undo-redo/redo.cjs.map +1 -7
- package/build/components/header/undo-redo/undo.cjs +29 -51
- package/build/components/header/undo-redo/undo.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/config.cjs +88 -85
- package/build/components/keyboard-shortcut-help-modal/config.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs +40 -57
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/index.cjs +94 -161
- package/build/components/keyboard-shortcut-help-modal/index.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/shortcut.cjs +37 -75
- package/build/components/keyboard-shortcut-help-modal/shortcut.cjs.map +1 -7
- package/build/components/keyboard-shortcuts/index.cjs +107 -140
- package/build/components/keyboard-shortcuts/index.cjs.map +1 -7
- package/build/components/layout/index.cjs +65 -74
- package/build/components/layout/index.cjs.map +1 -7
- package/build/components/layout/interface.cjs +82 -108
- package/build/components/layout/interface.cjs.map +1 -7
- package/build/components/layout/unsaved-changes-warning.cjs +44 -48
- package/build/components/layout/unsaved-changes-warning.cjs.map +1 -7
- package/build/components/more-menu/index.cjs +125 -191
- package/build/components/more-menu/index.cjs.map +1 -7
- package/build/components/more-menu/tools-more-menu-group.cjs +9 -29
- package/build/components/more-menu/tools-more-menu-group.cjs.map +1 -7
- package/build/components/notices/index.cjs +19 -39
- package/build/components/notices/index.cjs.map +1 -7
- package/build/components/save-button/index.cjs +31 -58
- package/build/components/save-button/index.cjs.map +1 -7
- package/build/components/secondary-sidebar/index.cjs +38 -45
- package/build/components/secondary-sidebar/index.cjs.map +1 -7
- package/build/components/secondary-sidebar/inserter-sidebar.cjs +50 -51
- package/build/components/secondary-sidebar/inserter-sidebar.cjs.map +1 -7
- package/build/components/secondary-sidebar/list-view-sidebar.cjs +51 -82
- package/build/components/secondary-sidebar/list-view-sidebar.cjs.map +1 -7
- package/build/components/sidebar/index.cjs +117 -180
- package/build/components/sidebar/index.cjs.map +1 -7
- package/build/components/sidebar/widget-areas.cjs +43 -85
- package/build/components/sidebar/widget-areas.cjs.map +1 -7
- package/build/components/welcome-guide/index.cjs +110 -186
- package/build/components/welcome-guide/index.cjs.map +1 -7
- package/build/components/widget-areas-block-editor-content/index.cjs +59 -64
- package/build/components/widget-areas-block-editor-content/index.cjs.map +1 -7
- package/build/components/widget-areas-block-editor-provider/index.cjs +105 -140
- package/build/components/widget-areas-block-editor-provider/index.cjs.map +1 -7
- package/build/constants.cjs +11 -32
- package/build/constants.cjs.map +1 -7
- package/build/filters/index.cjs +7 -4
- package/build/filters/move-to-widget-area.cjs +38 -53
- package/build/filters/move-to-widget-area.cjs.map +1 -7
- package/build/filters/replace-media-upload.cjs +11 -9
- package/build/filters/replace-media-upload.cjs.map +1 -7
- package/build/hooks/use-last-selected-widget-area.cjs +28 -49
- package/build/hooks/use-last-selected-widget-area.cjs.map +1 -7
- package/build/hooks/use-widget-library-insertion-point.cjs +33 -67
- package/build/hooks/use-widget-library-insertion-point.cjs.map +1 -7
- package/build/index.cjs +96 -97
- package/build/index.cjs.map +1 -7
- package/build/lock-unlock.cjs +10 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/store/actions.cjs +269 -278
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +12 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +61 -52
- package/build/store/index.cjs.map +1 -7
- package/build/store/private-selectors.cjs +11 -32
- package/build/store/private-selectors.cjs.map +1 -7
- package/build/store/reducer.cjs +107 -88
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/resolvers.cjs +60 -91
- package/build/store/resolvers.cjs.map +1 -7
- package/build/store/selectors.cjs +196 -229
- package/build/store/selectors.cjs.map +1 -7
- package/build/store/transformers.cjs +51 -82
- package/build/store/transformers.cjs.map +1 -7
- package/build/store/utils.cjs +76 -63
- package/build/store/utils.cjs.map +1 -7
- package/build-module/blocks/widget-area/edit/index.mjs +82 -94
- package/build-module/blocks/widget-area/edit/index.mjs.map +1 -7
- package/build-module/blocks/widget-area/edit/inner-blocks.mjs +19 -35
- package/build-module/blocks/widget-area/edit/inner-blocks.mjs.map +1 -7
- package/build-module/blocks/widget-area/edit/use-is-dragging-within.mjs +36 -33
- package/build-module/blocks/widget-area/edit/use-is-dragging-within.mjs.map +1 -7
- package/build-module/blocks/widget-area/index.mjs +12 -15
- package/build-module/blocks/widget-area/index.mjs.map +1 -7
- package/build-module/components/error-boundary/index.mjs +103 -128
- package/build-module/components/error-boundary/index.mjs.map +1 -7
- package/build-module/components/header/document-tools/index.mjs +51 -84
- package/build-module/components/header/document-tools/index.mjs.map +1 -7
- package/build-module/components/header/index.mjs +40 -47
- package/build-module/components/header/index.mjs.map +1 -7
- package/build-module/components/header/undo-redo/redo.mjs +20 -27
- package/build-module/components/header/undo-redo/redo.mjs.map +1 -7
- package/build-module/components/header/undo-redo/undo.mjs +19 -26
- package/build-module/components/header/undo-redo/undo.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/config.mjs +83 -61
- package/build-module/components/keyboard-shortcut-help-modal/config.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs +19 -33
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/index.mjs +67 -136
- package/build-module/components/keyboard-shortcut-help-modal/index.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs +31 -54
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs.map +1 -7
- package/build-module/components/keyboard-shortcuts/index.mjs +99 -119
- package/build-module/components/keyboard-shortcuts/index.mjs.map +1 -7
- package/build-module/components/layout/index.mjs +29 -40
- package/build-module/components/layout/index.mjs.map +1 -7
- package/build-module/components/layout/interface.mjs +53 -82
- package/build-module/components/layout/interface.mjs.map +1 -7
- package/build-module/components/layout/unsaved-changes-warning.mjs +37 -26
- package/build-module/components/layout/unsaved-changes-warning.mjs.map +1 -7
- package/build-module/components/more-menu/index.mjs +95 -162
- package/build-module/components/more-menu/index.mjs.map +1 -7
- package/build-module/components/more-menu/tools-more-menu-group.mjs +5 -9
- package/build-module/components/more-menu/tools-more-menu-group.mjs.map +1 -7
- package/build-module/components/notices/index.mjs +12 -17
- package/build-module/components/notices/index.mjs.map +1 -7
- package/build-module/components/save-button/index.mjs +23 -35
- package/build-module/components/save-button/index.mjs.map +1 -7
- package/build-module/components/secondary-sidebar/index.mjs +15 -20
- package/build-module/components/secondary-sidebar/index.mjs.map +1 -7
- package/build-module/components/secondary-sidebar/inserter-sidebar.mjs +27 -25
- package/build-module/components/secondary-sidebar/inserter-sidebar.mjs.map +1 -7
- package/build-module/components/secondary-sidebar/list-view-sidebar.mjs +39 -55
- package/build-module/components/secondary-sidebar/list-view-sidebar.mjs.map +1 -7
- package/build-module/components/sidebar/index.mjs +96 -162
- package/build-module/components/sidebar/index.mjs.map +1 -7
- package/build-module/components/sidebar/widget-areas.mjs +30 -57
- package/build-module/components/sidebar/widget-areas.mjs.map +1 -7
- package/build-module/components/welcome-guide/index.mjs +103 -164
- package/build-module/components/welcome-guide/index.mjs.map +1 -7
- package/build-module/components/widget-areas-block-editor-content/index.mjs +34 -44
- package/build-module/components/widget-areas-block-editor-content/index.mjs.map +1 -7
- package/build-module/components/widget-areas-block-editor-provider/index.mjs +76 -109
- package/build-module/components/widget-areas-block-editor-provider/index.mjs.map +1 -7
- package/build-module/constants.mjs +5 -7
- package/build-module/constants.mjs.map +1 -7
- package/build-module/filters/index.mjs +0 -2
- package/build-module/filters/move-to-widget-area.mjs +28 -48
- package/build-module/filters/move-to-widget-area.mjs.map +1 -7
- package/build-module/filters/replace-media-upload.mjs +5 -8
- package/build-module/filters/replace-media-upload.mjs.map +1 -7
- package/build-module/hooks/use-last-selected-widget-area.mjs +23 -29
- package/build-module/hooks/use-last-selected-widget-area.mjs.map +1 -7
- package/build-module/hooks/use-widget-library-insertion-point.mjs +28 -47
- package/build-module/hooks/use-widget-library-insertion-point.mjs.map +1 -7
- package/build-module/index.mjs +62 -79
- package/build-module/index.mjs.map +1 -7
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/store/actions.mjs +250 -247
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +7 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +18 -16
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/private-selectors.mjs +5 -7
- package/build-module/store/private-selectors.mjs.map +1 -7
- package/build-module/store/reducer.mjs +95 -58
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/resolvers.mjs +52 -71
- package/build-module/store/resolvers.mjs.map +1 -7
- package/build-module/store/selectors.mjs +178 -199
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/store/transformers.mjs +44 -56
- package/build-module/store/transformers.mjs.map +1 -7
- package/build-module/store/utils.mjs +64 -32
- package/build-module/store/utils.mjs.map +1 -7
- package/package.json +33 -33
- package/src/components/header/index.jsx +2 -2
- package/src/components/sidebar/index.jsx +18 -18
- package/src/components/welcome-guide/index.jsx +4 -2
- package/build/filters/index.cjs.map +0 -7
- package/build-module/filters/index.mjs.map +0 -7
package/build/store/actions.cjs
CHANGED
|
@@ -1,300 +1,291 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
19
|
-
// packages/edit-widgets/src/store/actions.js
|
|
20
|
-
var actions_exports = {};
|
|
21
|
-
__export(actions_exports, {
|
|
22
|
-
closeGeneralSidebar: () => closeGeneralSidebar,
|
|
23
|
-
lockWidgetSaving: () => lockWidgetSaving,
|
|
24
|
-
moveBlockToWidgetArea: () => moveBlockToWidgetArea,
|
|
25
|
-
persistStubPost: () => persistStubPost,
|
|
26
|
-
saveEditedWidgetAreas: () => saveEditedWidgetAreas,
|
|
27
|
-
saveWidgetArea: () => saveWidgetArea,
|
|
28
|
-
saveWidgetAreas: () => saveWidgetAreas,
|
|
29
|
-
setIsInserterOpened: () => setIsInserterOpened,
|
|
30
|
-
setIsListViewOpened: () => setIsListViewOpened,
|
|
31
|
-
setIsWidgetAreaOpen: () => setIsWidgetAreaOpen,
|
|
32
|
-
setWidgetAreasOpenState: () => setWidgetAreasOpenState,
|
|
33
|
-
setWidgetIdForClientId: () => setWidgetIdForClientId,
|
|
34
|
-
unlockWidgetSaving: () => unlockWidgetSaving
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
35
5
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
6
|
+
let _wordpress_i18n = require("@wordpress/i18n");
|
|
7
|
+
let _wordpress_notices = require("@wordpress/notices");
|
|
8
|
+
let _wordpress_interface = require("@wordpress/interface");
|
|
9
|
+
let _wordpress_widgets = require("@wordpress/widgets");
|
|
10
|
+
let _wordpress_core_data = require("@wordpress/core-data");
|
|
11
|
+
let _wordpress_block_editor = require("@wordpress/block-editor");
|
|
12
|
+
let __transformers_js = require("./transformers.cjs");
|
|
13
|
+
let __utils_js = require("./utils.cjs");
|
|
14
|
+
let __constants_js = require("./constants.cjs");
|
|
15
|
+
// packages/edit-widgets/src/store/actions.js
|
|
16
|
+
/**
|
|
17
|
+
* Persists a stub post with given ID to core data store. The post is meant to be in-memory only and
|
|
18
|
+
* shouldn't be saved via the API.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} id Post ID.
|
|
21
|
+
* @param {Array} blocks Blocks the post should consist of.
|
|
22
|
+
* @return {Object} The post object.
|
|
23
|
+
*/
|
|
24
|
+
const persistStubPost = (id, blocks) => ({ registry }) => {
|
|
25
|
+
const stubPost = (0, __utils_js.createStubPost)(id, blocks);
|
|
26
|
+
registry.dispatch(_wordpress_core_data.store).receiveEntityRecords(__utils_js.KIND, __utils_js.POST_TYPE, stubPost, { id: stubPost.id }, false);
|
|
27
|
+
return stubPost;
|
|
56
28
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
);
|
|
75
|
-
}
|
|
29
|
+
/**
|
|
30
|
+
* Converts all the blocks from edited widget areas into widgets,
|
|
31
|
+
* and submits a batch request to save everything at once.
|
|
32
|
+
*
|
|
33
|
+
* Creates a snackbar notice on either success or error.
|
|
34
|
+
*
|
|
35
|
+
* @return {Function} An action creator.
|
|
36
|
+
*/
|
|
37
|
+
const saveEditedWidgetAreas = () => async ({ select, dispatch, registry }) => {
|
|
38
|
+
const editedWidgetAreas = select.getEditedWidgetAreas();
|
|
39
|
+
if (!editedWidgetAreas?.length) return;
|
|
40
|
+
try {
|
|
41
|
+
await dispatch.saveWidgetAreas(editedWidgetAreas);
|
|
42
|
+
registry.dispatch(_wordpress_notices.store).createSuccessNotice((0, _wordpress_i18n.__)("Widgets saved."), { type: "snackbar" });
|
|
43
|
+
} catch (e) {
|
|
44
|
+
registry.dispatch(_wordpress_notices.store).createErrorNotice((0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("There was an error. %s"), e.message), { type: "snackbar" });
|
|
45
|
+
}
|
|
76
46
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Converts all the blocks from specified widget areas into widgets,
|
|
49
|
+
* and submits a batch request to save everything at once.
|
|
50
|
+
*
|
|
51
|
+
* @param {Object[]} widgetAreas Widget areas to save.
|
|
52
|
+
* @return {Function} An action creator.
|
|
53
|
+
*/
|
|
54
|
+
const saveWidgetAreas = (widgetAreas) => async ({ dispatch, registry }) => {
|
|
55
|
+
try {
|
|
56
|
+
for (const widgetArea of widgetAreas) await dispatch.saveWidgetArea(widgetArea.id);
|
|
57
|
+
} finally {
|
|
58
|
+
await registry.dispatch(_wordpress_core_data.store).finishResolution("getEntityRecord", __utils_js.KIND, __utils_js.WIDGET_AREA_ENTITY_TYPE, (0, __utils_js.buildWidgetAreasQuery)());
|
|
59
|
+
}
|
|
90
60
|
};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
batchMeta.push({
|
|
155
|
-
block,
|
|
156
|
-
position: i,
|
|
157
|
-
clientId: block.clientId
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
for (const widget of deletedWidgets) {
|
|
161
|
-
batchTasks.push(
|
|
162
|
-
({ deleteEntityRecord }) => deleteEntityRecord("root", "widget", widget.id, {
|
|
163
|
-
force: true
|
|
164
|
-
})
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
const records = await registry.dispatch(import_core_data.store).__experimentalBatch(batchTasks);
|
|
168
|
-
const preservedRecords = records.filter(
|
|
169
|
-
(record) => !record.hasOwnProperty("deleted")
|
|
170
|
-
);
|
|
171
|
-
const failedWidgetNames = [];
|
|
172
|
-
for (let i = 0; i < preservedRecords.length; i++) {
|
|
173
|
-
const widget = preservedRecords[i];
|
|
174
|
-
const { block, position } = batchMeta[i];
|
|
175
|
-
post.blocks[position].attributes.__internalWidgetId = widget.id;
|
|
176
|
-
const error = registry.select(import_core_data.store).getLastEntitySaveError("root", "widget", widget.id);
|
|
177
|
-
if (error) {
|
|
178
|
-
failedWidgetNames.push(block.attributes?.name || block?.name);
|
|
179
|
-
}
|
|
180
|
-
if (!sidebarWidgetsIds[position]) {
|
|
181
|
-
sidebarWidgetsIds[position] = widget.id;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
if (failedWidgetNames.length) {
|
|
185
|
-
throw new Error(
|
|
186
|
-
(0, import_i18n.sprintf)(
|
|
187
|
-
/* translators: %s: List of widget names */
|
|
188
|
-
(0, import_i18n.__)("Could not save the following widgets: %s."),
|
|
189
|
-
failedWidgetNames.join(", ")
|
|
190
|
-
)
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
registry.dispatch(import_core_data.store).editEntityRecord(
|
|
194
|
-
import_utils.KIND,
|
|
195
|
-
import_utils.WIDGET_AREA_ENTITY_TYPE,
|
|
196
|
-
widgetAreaId,
|
|
197
|
-
{
|
|
198
|
-
widgets: sidebarWidgetsIds
|
|
199
|
-
},
|
|
200
|
-
{ undoIgnore: true }
|
|
201
|
-
);
|
|
202
|
-
dispatch(trySaveWidgetArea(widgetAreaId));
|
|
203
|
-
registry.dispatch(import_core_data.store).receiveEntityRecords(import_utils.KIND, import_utils.POST_TYPE, post, void 0);
|
|
61
|
+
/**
|
|
62
|
+
* Converts all the blocks from a widget area specified by ID into widgets,
|
|
63
|
+
* and submits a batch request to save everything at once.
|
|
64
|
+
*
|
|
65
|
+
* @param {string} widgetAreaId ID of the widget area to process.
|
|
66
|
+
* @return {Function} An action creator.
|
|
67
|
+
*/
|
|
68
|
+
const saveWidgetArea = (widgetAreaId) => async ({ dispatch, select, registry }) => {
|
|
69
|
+
const widgets = select.getWidgets();
|
|
70
|
+
const post = registry.select(_wordpress_core_data.store).getEditedEntityRecord(__utils_js.KIND, __utils_js.POST_TYPE, (0, __utils_js.buildWidgetAreaPostId)(widgetAreaId));
|
|
71
|
+
const areaWidgets = Object.values(widgets).filter(({ sidebar }) => sidebar === widgetAreaId);
|
|
72
|
+
const usedReferenceWidgets = [];
|
|
73
|
+
const widgetsBlocks = post.blocks.filter((block) => {
|
|
74
|
+
const { id } = block.attributes;
|
|
75
|
+
if (block.name === "core/legacy-widget" && id) {
|
|
76
|
+
if (usedReferenceWidgets.includes(id)) return false;
|
|
77
|
+
usedReferenceWidgets.push(id);
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
});
|
|
81
|
+
const deletedWidgets = [];
|
|
82
|
+
for (const widget of areaWidgets) if (!select.getWidgetAreaForWidgetId(widget.id)) deletedWidgets.push(widget);
|
|
83
|
+
const batchMeta = [];
|
|
84
|
+
const batchTasks = [];
|
|
85
|
+
const sidebarWidgetsIds = [];
|
|
86
|
+
for (let i = 0; i < widgetsBlocks.length; i++) {
|
|
87
|
+
const block = widgetsBlocks[i];
|
|
88
|
+
const widgetId = (0, _wordpress_widgets.getWidgetIdFromBlock)(block);
|
|
89
|
+
const oldWidget = widgets[widgetId];
|
|
90
|
+
const widget = (0, __transformers_js.transformBlockToWidget)(block, oldWidget);
|
|
91
|
+
sidebarWidgetsIds.push(widgetId);
|
|
92
|
+
if (oldWidget) {
|
|
93
|
+
registry.dispatch(_wordpress_core_data.store).editEntityRecord("root", "widget", widgetId, {
|
|
94
|
+
...widget,
|
|
95
|
+
sidebar: widgetAreaId
|
|
96
|
+
}, { undoIgnore: true });
|
|
97
|
+
if (!registry.select(_wordpress_core_data.store).hasEditsForEntityRecord("root", "widget", widgetId)) continue;
|
|
98
|
+
batchTasks.push(({ saveEditedEntityRecord }) => saveEditedEntityRecord("root", "widget", widgetId));
|
|
99
|
+
} else batchTasks.push(({ saveEntityRecord }) => saveEntityRecord("root", "widget", {
|
|
100
|
+
...widget,
|
|
101
|
+
sidebar: widgetAreaId
|
|
102
|
+
}));
|
|
103
|
+
batchMeta.push({
|
|
104
|
+
block,
|
|
105
|
+
position: i,
|
|
106
|
+
clientId: block.clientId
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
for (const widget of deletedWidgets) batchTasks.push(({ deleteEntityRecord }) => deleteEntityRecord("root", "widget", widget.id, { force: true }));
|
|
110
|
+
const preservedRecords = (await registry.dispatch(_wordpress_core_data.store).__experimentalBatch(batchTasks)).filter((record) => !record.hasOwnProperty("deleted"));
|
|
111
|
+
const failedWidgetNames = [];
|
|
112
|
+
for (let i = 0; i < preservedRecords.length; i++) {
|
|
113
|
+
const widget = preservedRecords[i];
|
|
114
|
+
const { block, position } = batchMeta[i];
|
|
115
|
+
post.blocks[position].attributes.__internalWidgetId = widget.id;
|
|
116
|
+
if (registry.select(_wordpress_core_data.store).getLastEntitySaveError("root", "widget", widget.id)) failedWidgetNames.push(block.attributes?.name || block?.name);
|
|
117
|
+
if (!sidebarWidgetsIds[position]) sidebarWidgetsIds[position] = widget.id;
|
|
118
|
+
}
|
|
119
|
+
if (failedWidgetNames.length) throw new Error((0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Could not save the following widgets: %s."), failedWidgetNames.join(", ")));
|
|
120
|
+
registry.dispatch(_wordpress_core_data.store).editEntityRecord(__utils_js.KIND, __utils_js.WIDGET_AREA_ENTITY_TYPE, widgetAreaId, { widgets: sidebarWidgetsIds }, { undoIgnore: true });
|
|
121
|
+
dispatch(trySaveWidgetArea(widgetAreaId));
|
|
122
|
+
registry.dispatch(_wordpress_core_data.store).receiveEntityRecords(__utils_js.KIND, __utils_js.POST_TYPE, post, void 0);
|
|
204
123
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
import_utils.KIND,
|
|
208
|
-
import_utils.WIDGET_AREA_ENTITY_TYPE,
|
|
209
|
-
widgetAreaId,
|
|
210
|
-
{
|
|
211
|
-
throwOnError: true
|
|
212
|
-
}
|
|
213
|
-
);
|
|
124
|
+
const trySaveWidgetArea = (widgetAreaId) => ({ registry }) => {
|
|
125
|
+
registry.dispatch(_wordpress_core_data.store).saveEditedEntityRecord(__utils_js.KIND, __utils_js.WIDGET_AREA_ENTITY_TYPE, widgetAreaId, { throwOnError: true });
|
|
214
126
|
};
|
|
127
|
+
/**
|
|
128
|
+
* Sets the clientId stored for a particular widgetId.
|
|
129
|
+
*
|
|
130
|
+
* @param {number} clientId Client id.
|
|
131
|
+
* @param {number} widgetId Widget id.
|
|
132
|
+
*
|
|
133
|
+
* @return {Object} Action.
|
|
134
|
+
*/
|
|
215
135
|
function setWidgetIdForClientId(clientId, widgetId) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
136
|
+
return {
|
|
137
|
+
type: "SET_WIDGET_ID_FOR_CLIENT_ID",
|
|
138
|
+
clientId,
|
|
139
|
+
widgetId
|
|
140
|
+
};
|
|
221
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Sets the open state of all the widget areas.
|
|
144
|
+
*
|
|
145
|
+
* @param {Object} widgetAreasOpenState The open states of all the widget areas.
|
|
146
|
+
*
|
|
147
|
+
* @return {Object} Action.
|
|
148
|
+
*/
|
|
222
149
|
function setWidgetAreasOpenState(widgetAreasOpenState) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
150
|
+
return {
|
|
151
|
+
type: "SET_WIDGET_AREAS_OPEN_STATE",
|
|
152
|
+
widgetAreasOpenState
|
|
153
|
+
};
|
|
227
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Sets the open state of the widget area.
|
|
157
|
+
*
|
|
158
|
+
* @param {string} clientId The clientId of the widget area.
|
|
159
|
+
* @param {boolean} isOpen Whether the widget area should be opened.
|
|
160
|
+
*
|
|
161
|
+
* @return {Object} Action.
|
|
162
|
+
*/
|
|
228
163
|
function setIsWidgetAreaOpen(clientId, isOpen) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
164
|
+
return {
|
|
165
|
+
type: "SET_IS_WIDGET_AREA_OPEN",
|
|
166
|
+
clientId,
|
|
167
|
+
isOpen
|
|
168
|
+
};
|
|
234
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Returns an action object used to open/close the inserter.
|
|
172
|
+
*
|
|
173
|
+
* @param {boolean|Object} value Whether the inserter should be
|
|
174
|
+
* opened (true) or closed (false).
|
|
175
|
+
* To specify an insertion point,
|
|
176
|
+
* use an object.
|
|
177
|
+
* @param {string} value.rootClientId The root client ID to insert at.
|
|
178
|
+
* @param {number} value.insertionIndex The index to insert at.
|
|
179
|
+
*
|
|
180
|
+
* @return {Object} Action object.
|
|
181
|
+
*/
|
|
235
182
|
function setIsInserterOpened(value) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
183
|
+
return {
|
|
184
|
+
type: "SET_IS_INSERTER_OPENED",
|
|
185
|
+
value
|
|
186
|
+
};
|
|
240
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Returns an action object used to open/close the list view.
|
|
190
|
+
*
|
|
191
|
+
* @param {boolean} isOpen A boolean representing whether the list view should be opened or closed.
|
|
192
|
+
* @return {Object} Action object.
|
|
193
|
+
*/
|
|
241
194
|
function setIsListViewOpened(isOpen) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
195
|
+
return {
|
|
196
|
+
type: "SET_IS_LIST_VIEW_OPENED",
|
|
197
|
+
isOpen
|
|
198
|
+
};
|
|
246
199
|
}
|
|
247
|
-
|
|
248
|
-
|
|
200
|
+
/**
|
|
201
|
+
* Returns an action object signalling that the user closed the sidebar.
|
|
202
|
+
*
|
|
203
|
+
* @return {Object} Action creator.
|
|
204
|
+
*/
|
|
205
|
+
const closeGeneralSidebar = () => ({ registry }) => {
|
|
206
|
+
registry.dispatch(_wordpress_interface.store).disableComplementaryArea(__constants_js.STORE_NAME);
|
|
249
207
|
};
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if (!isDestinationWidgetAreaOpen) {
|
|
263
|
-
dispatch.setIsWidgetAreaOpen(destinationRootClientId, true);
|
|
264
|
-
}
|
|
265
|
-
registry.dispatch(import_block_editor.store).moveBlocksToPosition(
|
|
266
|
-
[clientId],
|
|
267
|
-
sourceRootClientId,
|
|
268
|
-
destinationRootClientId,
|
|
269
|
-
destinationIndex
|
|
270
|
-
);
|
|
208
|
+
/**
|
|
209
|
+
* Action that handles moving a block between widget areas
|
|
210
|
+
*
|
|
211
|
+
* @param {string} clientId The clientId of the block to move.
|
|
212
|
+
* @param {string} widgetAreaId The id of the widget area to move the block to.
|
|
213
|
+
*/
|
|
214
|
+
const moveBlockToWidgetArea = (clientId, widgetAreaId) => async ({ dispatch, select, registry }) => {
|
|
215
|
+
const sourceRootClientId = registry.select(_wordpress_block_editor.store).getBlockRootClientId(clientId);
|
|
216
|
+
const destinationRootClientId = registry.select(_wordpress_block_editor.store).getBlocks().find(({ attributes }) => attributes.id === widgetAreaId).clientId;
|
|
217
|
+
const destinationIndex = registry.select(_wordpress_block_editor.store).getBlockOrder(destinationRootClientId).length;
|
|
218
|
+
if (!select.getIsWidgetAreaOpen(destinationRootClientId)) dispatch.setIsWidgetAreaOpen(destinationRootClientId, true);
|
|
219
|
+
registry.dispatch(_wordpress_block_editor.store).moveBlocksToPosition([clientId], sourceRootClientId, destinationRootClientId, destinationIndex);
|
|
271
220
|
};
|
|
221
|
+
/**
|
|
222
|
+
* Returns an action object used to signal that widget saving is unlocked.
|
|
223
|
+
*
|
|
224
|
+
* @param {string} lockName The lock name.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```js
|
|
228
|
+
* import { store as widgetStore } from '@wordpress/edit-widgets';
|
|
229
|
+
* import { useDispatch } from '@wordpress/data';
|
|
230
|
+
*
|
|
231
|
+
* const ExampleComponent = () => {
|
|
232
|
+
* const { unlockWidgetSaving } = useDispatch( widgetStore );
|
|
233
|
+
* return (
|
|
234
|
+
* <Button onClick={ () => unlockWidgetSaving( 'lockName' ) }>
|
|
235
|
+
* { __( 'Unlock Widget Saving' ) }
|
|
236
|
+
* </Button>
|
|
237
|
+
* );
|
|
238
|
+
* };
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
* @return {Object} Action object
|
|
242
|
+
*/
|
|
272
243
|
function unlockWidgetSaving(lockName) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
244
|
+
return {
|
|
245
|
+
type: "UNLOCK_WIDGET_SAVING",
|
|
246
|
+
lockName
|
|
247
|
+
};
|
|
277
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Returns an action object used to signal that widget saving is locked.
|
|
251
|
+
*
|
|
252
|
+
* @param {string} lockName The lock name.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```js
|
|
256
|
+
* import { store as widgetStore } from '@wordpress/edit-widgets';
|
|
257
|
+
* import { useDispatch } from '@wordpress/data';
|
|
258
|
+
*
|
|
259
|
+
* const ExampleComponent = () => {
|
|
260
|
+
* const { lockWidgetSaving } = useDispatch( widgetStore );
|
|
261
|
+
* return (
|
|
262
|
+
* <Button onClick={ () => lockWidgetSaving( 'lockName' ) }>
|
|
263
|
+
* { __( 'Lock Widget Saving' ) }
|
|
264
|
+
* </Button>
|
|
265
|
+
* );
|
|
266
|
+
* };
|
|
267
|
+
* ```
|
|
268
|
+
*
|
|
269
|
+
* @return {Object} Action object
|
|
270
|
+
*/
|
|
278
271
|
function lockWidgetSaving(lockName) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
272
|
+
return {
|
|
273
|
+
type: "LOCK_WIDGET_SAVING",
|
|
274
|
+
lockName
|
|
275
|
+
};
|
|
283
276
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
});
|
|
300
|
-
//# sourceMappingURL=actions.cjs.map
|
|
277
|
+
exports.closeGeneralSidebar = closeGeneralSidebar;
|
|
278
|
+
exports.lockWidgetSaving = lockWidgetSaving;
|
|
279
|
+
exports.moveBlockToWidgetArea = moveBlockToWidgetArea;
|
|
280
|
+
exports.persistStubPost = persistStubPost;
|
|
281
|
+
exports.saveEditedWidgetAreas = saveEditedWidgetAreas;
|
|
282
|
+
exports.saveWidgetArea = saveWidgetArea;
|
|
283
|
+
exports.saveWidgetAreas = saveWidgetAreas;
|
|
284
|
+
exports.setIsInserterOpened = setIsInserterOpened;
|
|
285
|
+
exports.setIsListViewOpened = setIsListViewOpened;
|
|
286
|
+
exports.setIsWidgetAreaOpen = setIsWidgetAreaOpen;
|
|
287
|
+
exports.setWidgetAreasOpenState = setWidgetAreasOpenState;
|
|
288
|
+
exports.setWidgetIdForClientId = setWidgetIdForClientId;
|
|
289
|
+
exports.unlockWidgetSaving = unlockWidgetSaving;
|
|
290
|
+
|
|
291
|
+
//# sourceMappingURL=actions.cjs.map
|