@wordpress/edit-widgets 6.57.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 -102
- 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 -63
- 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 -76
- 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 +35 -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/build-style/style-rtl.css +12 -12
- package/build-style/style.css +12 -12
- package/package.json +35 -36
- package/src/components/header/index.jsx +2 -2
- package/src/components/layout/interface.jsx +4 -1
- package/src/components/layout/style.scss +11 -0
- package/src/components/notices/style.scss +2 -2
- package/src/components/sidebar/index.jsx +18 -18
- package/src/components/welcome-guide/index.jsx +4 -2
- package/src/components/widget-areas-block-editor-content/index.jsx +4 -3
- package/CHANGELOG.md +0 -325
- package/build/filters/index.cjs.map +0 -7
- package/build-module/filters/index.mjs.map +0 -7
|
@@ -1,94 +1,63 @@
|
|
|
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/resolvers.js
|
|
20
|
-
var resolvers_exports = {};
|
|
21
|
-
__export(resolvers_exports, {
|
|
22
|
-
getWidgetAreas: () => getWidgetAreas,
|
|
23
|
-
getWidgets: () => getWidgets
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
5
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
widgetAreasOpenState[widgetAreaBlock.clientId] = index === 0;
|
|
63
|
-
});
|
|
64
|
-
dispatch((0, import_actions.setWidgetAreasOpenState)(widgetAreasOpenState));
|
|
65
|
-
dispatch(
|
|
66
|
-
(0, import_actions.persistStubPost)((0, import_utils.buildWidgetAreasPostId)(), widgetAreaBlocks)
|
|
67
|
-
);
|
|
6
|
+
let _wordpress_blocks = require("@wordpress/blocks");
|
|
7
|
+
let _wordpress_core_data = require("@wordpress/core-data");
|
|
8
|
+
let __actions_js = require("./actions.cjs");
|
|
9
|
+
let __utils_js = require("./utils.cjs");
|
|
10
|
+
let __transformers_js = require("./transformers.cjs");
|
|
11
|
+
// packages/edit-widgets/src/store/resolvers.js
|
|
12
|
+
/**
|
|
13
|
+
* Creates a "stub" widgets post reflecting all available widget areas. The
|
|
14
|
+
* post is meant as a convenient to only exists in runtime and should never be saved. It
|
|
15
|
+
* enables a convenient way of editing the widgets by using a regular post editor.
|
|
16
|
+
*
|
|
17
|
+
* Fetches all widgets from all widgets aras, converts them into blocks, and hydrates a new post with them.
|
|
18
|
+
*
|
|
19
|
+
* @return {Function} An action creator.
|
|
20
|
+
*/
|
|
21
|
+
const getWidgetAreas = () => async ({ dispatch, registry }) => {
|
|
22
|
+
const query = (0, __utils_js.buildWidgetAreasQuery)();
|
|
23
|
+
const widgetAreas = await registry.resolveSelect(_wordpress_core_data.store).getEntityRecords(__utils_js.KIND, __utils_js.WIDGET_AREA_ENTITY_TYPE, query);
|
|
24
|
+
const widgetAreaBlocks = [];
|
|
25
|
+
const sortedWidgetAreas = widgetAreas.sort((a, b) => {
|
|
26
|
+
if (a.id === "wp_inactive_widgets") return 1;
|
|
27
|
+
if (b.id === "wp_inactive_widgets") return -1;
|
|
28
|
+
return 0;
|
|
29
|
+
});
|
|
30
|
+
for (const widgetArea of sortedWidgetAreas) {
|
|
31
|
+
widgetAreaBlocks.push((0, _wordpress_blocks.createBlock)("core/widget-area", {
|
|
32
|
+
id: widgetArea.id,
|
|
33
|
+
name: widgetArea.name
|
|
34
|
+
}));
|
|
35
|
+
if (!widgetArea.widgets.length) dispatch((0, __actions_js.persistStubPost)((0, __utils_js.buildWidgetAreaPostId)(widgetArea.id), []));
|
|
36
|
+
}
|
|
37
|
+
const widgetAreasOpenState = {};
|
|
38
|
+
widgetAreaBlocks.forEach((widgetAreaBlock, index) => {
|
|
39
|
+
widgetAreasOpenState[widgetAreaBlock.clientId] = index === 0;
|
|
40
|
+
});
|
|
41
|
+
dispatch((0, __actions_js.setWidgetAreasOpenState)(widgetAreasOpenState));
|
|
42
|
+
dispatch((0, __actions_js.persistStubPost)((0, __utils_js.buildWidgetAreasPostId)(), widgetAreaBlocks));
|
|
68
43
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
)
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
44
|
+
/**
|
|
45
|
+
* Fetches all widgets from all widgets ares, and groups them by widget area Id.
|
|
46
|
+
*
|
|
47
|
+
* @return {Function} An action creator.
|
|
48
|
+
*/
|
|
49
|
+
const getWidgets = () => async ({ dispatch, registry }) => {
|
|
50
|
+
const query = (0, __utils_js.buildWidgetsQuery)();
|
|
51
|
+
const widgets = await registry.resolveSelect(_wordpress_core_data.store).getEntityRecords("root", "widget", query);
|
|
52
|
+
const groupedBySidebar = {};
|
|
53
|
+
for (const widget of widgets) {
|
|
54
|
+
const block = (0, __transformers_js.transformWidgetToBlock)(widget);
|
|
55
|
+
groupedBySidebar[widget.sidebar] = groupedBySidebar[widget.sidebar] || [];
|
|
56
|
+
groupedBySidebar[widget.sidebar].push(block);
|
|
57
|
+
}
|
|
58
|
+
for (const sidebarId in groupedBySidebar) if (groupedBySidebar.hasOwnProperty(sidebarId)) dispatch((0, __actions_js.persistStubPost)((0, __utils_js.buildWidgetAreaPostId)(sidebarId), groupedBySidebar[sidebarId]));
|
|
88
59
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
});
|
|
94
|
-
//# sourceMappingURL=resolvers.cjs.map
|
|
60
|
+
exports.getWidgetAreas = getWidgetAreas;
|
|
61
|
+
exports.getWidgets = getWidgets;
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=resolvers.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/resolvers.js"],
|
|
4
|
-
"sourcesContent": ["import { createBlock } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\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"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA4B;AAC5B,uBAAmC;AACnC,qBAAyD;AACzD,mBAOO;AACP,0BAAuC;AAWhC,IAAM,iBACZ,MACA,OAAQ,EAAE,UAAU,SAAS,MAAO;AACnC,QAAM,YAAQ,oCAAsB;AACpC,QAAM,cAAc,MAAM,SACxB,cAAe,iBAAAA,KAAU,EACzB,iBAAkB,mBAAM,sCAAyB,KAAM;AAEzD,QAAM,mBAAmB,CAAC;AAC1B,QAAM,oBAAoB,YAAY,KAAM,CAAE,GAAG,MAAO;AACvD,QAAK,EAAE,OAAO,uBAAwB;AACrC,aAAO;AAAA,IACR;AACA,QAAK,EAAE,OAAO,uBAAwB;AACrC,aAAO;AAAA,IACR;AACA,WAAO;AAAA,EACR,CAAE;AACF,aAAY,cAAc,mBAAoB;AAC7C,qBAAiB;AAAA,UAChB,2BAAa,oBAAoB;AAAA,QAChC,IAAI,WAAW;AAAA,QACf,MAAM,WAAW;AAAA,MAClB,CAAE;AAAA,IACH;AAEA,QAAK,CAAE,WAAW,QAAQ,QAAS;AAGlC;AAAA,YACC;AAAA,cACC,oCAAuB,WAAW,EAAG;AAAA,UACrC,CAAC;AAAA,QACF;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,QAAM,uBAAuB,CAAC;AAC9B,mBAAiB,QAAS,CAAE,iBAAiB,UAAW;AAEvD,yBAAsB,gBAAgB,QAAS,IAAI,UAAU;AAAA,EAC9D,CAAE;AACF,eAAU,wCAAyB,oBAAqB,CAAE;AAE1D;AAAA,QACC,oCAAiB,qCAAuB,GAAG,gBAAiB;AAAA,EAC7D;AACD;AAOM,IAAM,aACZ,MACA,OAAQ,EAAE,UAAU,SAAS,MAAO;AACnC,QAAM,YAAQ,gCAAkB;AAChC,QAAM,UAAU,MAAM,SACpB,cAAe,iBAAAA,KAAU,EACzB,iBAAkB,QAAQ,UAAU,KAAM;AAE5C,QAAM,mBAAmB,CAAC;AAE1B,aAAY,UAAU,SAAU;AAC/B,UAAM,YAAQ,4CAAwB,MAAO;AAC7C,qBAAkB,OAAO,OAAQ,IAChC,iBAAkB,OAAO,OAAQ,KAAK,CAAC;AACxC,qBAAkB,OAAO,OAAQ,EAAE,KAAM,KAAM;AAAA,EAChD;AAEA,aAAY,aAAa,kBAAmB;AAC3C,QAAK,iBAAiB,eAAgB,SAAU,GAAI;AAEnD;AAAA,YACC;AAAA,cACC,oCAAuB,SAAU;AAAA,UACjC,iBAAkB,SAAU;AAAA,QAC7B;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
|
-
"names": ["coreStore"]
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"resolvers.cjs","names":["buildWidgetAreasQuery","coreStore","KIND","WIDGET_AREA_ENTITY_TYPE","createBlock","persistStubPost","buildWidgetAreaPostId","setWidgetAreasOpenState","buildWidgetAreasPostId","buildWidgetsQuery","transformWidgetToBlock"],"sources":["../../src/store/resolvers.js"],"sourcesContent":["import { createBlock } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,uBAEZ,OAAQ,EAAE,UAAU,eAAgB;CACnC,MAAM,SAAA,GAAQA,WAAAA,sBAAAA,CAAsB;CACpC,MAAM,cAAc,MAAM,SACxB,cAAeC,qBAAAA,KAAU,CAAC,CAC1B,iBAAkBC,WAAAA,MAAMC,WAAAA,yBAAyB,KAAM;CAEzD,MAAM,mBAAmB,CAAC;CAC1B,MAAM,oBAAoB,YAAY,MAAQ,GAAG,MAAO;EACvD,IAAK,EAAE,OAAO,uBACb,OAAO;EAER,IAAK,EAAE,OAAO,uBACb,OAAO;EAER,OAAO;CACR,CAAE;CACF,KAAM,MAAM,cAAc,mBAAoB;EAC7C,iBAAiB,MAAA,GAChBC,kBAAAA,YAAAA,CAAa,oBAAoB;GAChC,IAAI,WAAW;GACf,MAAM,WAAW;EAClB,CAAE,CACH;EAEA,IAAK,CAAE,WAAW,QAAQ,QAGzB,UAAA,GACCC,aAAAA,gBAAAA,EAAAA,GACCC,WAAAA,sBAAAA,CAAuB,WAAW,EAAG,GACrC,CAAC,CACF,CACD;CAEF;CAEA,MAAM,uBAAuB,CAAC;CAC9B,iBAAiB,SAAW,iBAAiB,UAAW;EAEvD,qBAAsB,gBAAgB,YAAa,UAAU;CAC9D,CAAE;CACF,UAAA,GAAUC,aAAAA,wBAAAA,CAAyB,oBAAqB,CAAE;CAE1D,UAAA,GACCF,aAAAA,gBAAAA,EAAAA,GAAiBG,WAAAA,uBAAAA,CAAuB,GAAG,gBAAiB,CAC7D;AACD;;;;;;AAOD,MAAa,mBAEZ,OAAQ,EAAE,UAAU,eAAgB;CACnC,MAAM,SAAA,GAAQC,WAAAA,kBAAAA,CAAkB;CAChC,MAAM,UAAU,MAAM,SACpB,cAAeR,qBAAAA,KAAU,CAAC,CAC1B,iBAAkB,QAAQ,UAAU,KAAM;CAE5C,MAAM,mBAAmB,CAAC;CAE1B,KAAM,MAAM,UAAU,SAAU;EAC/B,MAAM,SAAA,GAAQS,kBAAAA,uBAAAA,CAAwB,MAAO;EAC7C,iBAAkB,OAAO,WACxB,iBAAkB,OAAO,YAAa,CAAC;EACxC,iBAAkB,OAAO,QAAS,CAAC,KAAM,KAAM;CAChD;CAEA,KAAM,MAAM,aAAa,kBACxB,IAAK,iBAAiB,eAAgB,SAAU,GAE/C,UAAA,GACCL,aAAAA,gBAAAA,EAAAA,GACCC,WAAAA,sBAAAA,CAAuB,SAAU,GACjC,iBAAkB,UACnB,CACD;AAGH"}
|
|
@@ -1,242 +1,209 @@
|
|
|
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/selectors.js
|
|
20
|
-
var selectors_exports = {};
|
|
21
|
-
__export(selectors_exports, {
|
|
22
|
-
__experimentalGetInsertionPoint: () => __experimentalGetInsertionPoint,
|
|
23
|
-
canInsertBlockInWidgetArea: () => canInsertBlockInWidgetArea,
|
|
24
|
-
getEditedWidgetAreas: () => getEditedWidgetAreas,
|
|
25
|
-
getIsWidgetAreaOpen: () => getIsWidgetAreaOpen,
|
|
26
|
-
getParentWidgetAreaBlock: () => getParentWidgetAreaBlock,
|
|
27
|
-
getReferenceWidgetBlocks: () => getReferenceWidgetBlocks,
|
|
28
|
-
getWidget: () => getWidget,
|
|
29
|
-
getWidgetAreaForWidgetId: () => getWidgetAreaForWidgetId,
|
|
30
|
-
getWidgetAreas: () => getWidgetAreas,
|
|
31
|
-
getWidgets: () => getWidgets,
|
|
32
|
-
isInserterOpened: () => isInserterOpened,
|
|
33
|
-
isListViewOpened: () => isListViewOpened,
|
|
34
|
-
isSavingWidgetAreas: () => isSavingWidgetAreas,
|
|
35
|
-
isWidgetSavingLocked: () => isWidgetSavingLocked
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
36
5
|
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
6
|
+
let _wordpress_data = require("@wordpress/data");
|
|
7
|
+
let _wordpress_widgets = require("@wordpress/widgets");
|
|
8
|
+
let _wordpress_core_data = require("@wordpress/core-data");
|
|
9
|
+
let _wordpress_block_editor = require("@wordpress/block-editor");
|
|
10
|
+
let __utils_js = require("./utils.cjs");
|
|
11
|
+
let __constants_js = require("./constants.cjs");
|
|
12
|
+
// packages/edit-widgets/src/store/selectors.js
|
|
13
|
+
const EMPTY_INSERTION_POINT = {
|
|
14
|
+
rootClientId: void 0,
|
|
15
|
+
insertionIndex: void 0
|
|
47
16
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
);
|
|
17
|
+
/**
|
|
18
|
+
* Returns all API widgets.
|
|
19
|
+
*
|
|
20
|
+
* @return {Object[]} API List of widgets.
|
|
21
|
+
*/
|
|
22
|
+
const getWidgets = (0, _wordpress_data.createRegistrySelector)((select) => (0, _wordpress_data.createSelector)(() => {
|
|
23
|
+
return select(_wordpress_core_data.store).getEntityRecords("root", "widget", (0, __utils_js.buildWidgetsQuery)())?.reduce((allWidgets, widget) => ({
|
|
24
|
+
...allWidgets,
|
|
25
|
+
[widget.id]: widget
|
|
26
|
+
}), {}) ?? {};
|
|
27
|
+
}, () => [select(_wordpress_core_data.store).getEntityRecords("root", "widget", (0, __utils_js.buildWidgetsQuery)())]));
|
|
28
|
+
/**
|
|
29
|
+
* Returns API widget data for a particular widget ID.
|
|
30
|
+
*
|
|
31
|
+
* @param {number} id Widget ID.
|
|
32
|
+
*
|
|
33
|
+
* @return {Object} API widget data for a particular widget ID.
|
|
34
|
+
*/
|
|
35
|
+
const getWidget = (0, _wordpress_data.createRegistrySelector)((select) => (state, id) => {
|
|
36
|
+
return select(__constants_js.STORE_NAME).getWidgets()[id];
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Returns all API widget areas.
|
|
40
|
+
*
|
|
41
|
+
* @return {Object[]} API List of widget areas.
|
|
42
|
+
*/
|
|
43
|
+
const getWidgetAreas = (0, _wordpress_data.createRegistrySelector)((select) => () => {
|
|
44
|
+
const query = (0, __utils_js.buildWidgetAreasQuery)();
|
|
45
|
+
return select(_wordpress_core_data.store).getEntityRecords(__utils_js.KIND, __utils_js.WIDGET_AREA_ENTITY_TYPE, query);
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* Returns widgetArea containing a block identify by given widgetId
|
|
49
|
+
*
|
|
50
|
+
* @param {string} widgetId The ID of the widget.
|
|
51
|
+
* @return {Object} Containing widget area.
|
|
52
|
+
*/
|
|
53
|
+
const getWidgetAreaForWidgetId = (0, _wordpress_data.createRegistrySelector)((select) => (state, widgetId) => {
|
|
54
|
+
return select(__constants_js.STORE_NAME).getWidgetAreas().find((widgetArea) => {
|
|
55
|
+
return select(_wordpress_core_data.store).getEditedEntityRecord(__utils_js.KIND, __utils_js.POST_TYPE, (0, __utils_js.buildWidgetAreaPostId)(widgetArea.id)).blocks.map((block) => (0, _wordpress_widgets.getWidgetIdFromBlock)(block)).includes(widgetId);
|
|
56
|
+
});
|
|
89
57
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
(block) => (0, import_widgets.getWidgetIdFromBlock)(block)
|
|
101
|
-
);
|
|
102
|
-
return blockWidgetIds.includes(widgetId);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
);
|
|
106
|
-
var getParentWidgetAreaBlock = (0, import_data.createRegistrySelector)(
|
|
107
|
-
(select) => (state, clientId) => {
|
|
108
|
-
const { getBlock, getBlockName, getBlockParents } = select(import_block_editor.store);
|
|
109
|
-
const blockParents = getBlockParents(clientId);
|
|
110
|
-
const widgetAreaClientId = blockParents.find(
|
|
111
|
-
(parentClientId) => getBlockName(parentClientId) === "core/widget-area"
|
|
112
|
-
);
|
|
113
|
-
return getBlock(widgetAreaClientId);
|
|
114
|
-
}
|
|
115
|
-
);
|
|
116
|
-
var getEditedWidgetAreas = (0, import_data.createRegistrySelector)(
|
|
117
|
-
(select) => (state, ids) => {
|
|
118
|
-
let widgetAreas = select(import_constants.STORE_NAME).getWidgetAreas();
|
|
119
|
-
if (!widgetAreas) {
|
|
120
|
-
return [];
|
|
121
|
-
}
|
|
122
|
-
if (ids) {
|
|
123
|
-
widgetAreas = widgetAreas.filter(
|
|
124
|
-
({ id }) => ids.includes(id)
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
return widgetAreas.filter(
|
|
128
|
-
({ id }) => select(import_core_data.store).hasEditsForEntityRecord(
|
|
129
|
-
import_utils.KIND,
|
|
130
|
-
import_utils.POST_TYPE,
|
|
131
|
-
(0, import_utils.buildWidgetAreaPostId)(id)
|
|
132
|
-
)
|
|
133
|
-
).map(
|
|
134
|
-
({ id }) => select(import_core_data.store).getEditedEntityRecord(
|
|
135
|
-
import_utils.KIND,
|
|
136
|
-
import_utils.WIDGET_AREA_ENTITY_TYPE,
|
|
137
|
-
id
|
|
138
|
-
)
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
);
|
|
142
|
-
var getReferenceWidgetBlocks = (0, import_data.createRegistrySelector)(
|
|
143
|
-
(select) => (state, referenceWidgetName = null) => {
|
|
144
|
-
const results = [];
|
|
145
|
-
const widgetAreas = select(import_constants.STORE_NAME).getWidgetAreas();
|
|
146
|
-
for (const _widgetArea of widgetAreas) {
|
|
147
|
-
const post = select(import_core_data.store).getEditedEntityRecord(
|
|
148
|
-
import_utils.KIND,
|
|
149
|
-
import_utils.POST_TYPE,
|
|
150
|
-
(0, import_utils.buildWidgetAreaPostId)(_widgetArea.id)
|
|
151
|
-
);
|
|
152
|
-
for (const block of post.blocks) {
|
|
153
|
-
if (block.name === "core/legacy-widget" && (!referenceWidgetName || block.attributes?.referenceWidgetName === referenceWidgetName)) {
|
|
154
|
-
results.push(block);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return results;
|
|
159
|
-
}
|
|
160
|
-
);
|
|
161
|
-
var isSavingWidgetAreas = (0, import_data.createRegistrySelector)((select) => () => {
|
|
162
|
-
const widgetAreasIds = select(import_constants.STORE_NAME).getWidgetAreas()?.map(({ id }) => id);
|
|
163
|
-
if (!widgetAreasIds) {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
for (const id of widgetAreasIds) {
|
|
167
|
-
const isSaving = select(import_core_data.store).isSavingEntityRecord(
|
|
168
|
-
import_utils.KIND,
|
|
169
|
-
import_utils.WIDGET_AREA_ENTITY_TYPE,
|
|
170
|
-
id
|
|
171
|
-
);
|
|
172
|
-
if (isSaving) {
|
|
173
|
-
return true;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
const widgetIds = [
|
|
177
|
-
...Object.keys(select(import_constants.STORE_NAME).getWidgets()),
|
|
178
|
-
void 0
|
|
179
|
-
// account for new widgets without an ID
|
|
180
|
-
];
|
|
181
|
-
for (const id of widgetIds) {
|
|
182
|
-
const isSaving = select(import_core_data.store).isSavingEntityRecord(
|
|
183
|
-
"root",
|
|
184
|
-
"widget",
|
|
185
|
-
id
|
|
186
|
-
);
|
|
187
|
-
if (isSaving) {
|
|
188
|
-
return true;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return false;
|
|
58
|
+
/**
|
|
59
|
+
* Given a child client id, returns the parent widget area block.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} clientId The client id of a block in a widget area.
|
|
62
|
+
*
|
|
63
|
+
* @return {WPBlock} The widget area block.
|
|
64
|
+
*/
|
|
65
|
+
const getParentWidgetAreaBlock = (0, _wordpress_data.createRegistrySelector)((select) => (state, clientId) => {
|
|
66
|
+
const { getBlock, getBlockName, getBlockParents } = select(_wordpress_block_editor.store);
|
|
67
|
+
return getBlock(getBlockParents(clientId).find((parentClientId) => getBlockName(parentClientId) === "core/widget-area"));
|
|
192
68
|
});
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Returns all edited widget area entity records.
|
|
71
|
+
*
|
|
72
|
+
* @return {Object[]} List of edited widget area entity records.
|
|
73
|
+
*/
|
|
74
|
+
const getEditedWidgetAreas = (0, _wordpress_data.createRegistrySelector)((select) => (state, ids) => {
|
|
75
|
+
let widgetAreas = select(__constants_js.STORE_NAME).getWidgetAreas();
|
|
76
|
+
if (!widgetAreas) return [];
|
|
77
|
+
if (ids) widgetAreas = widgetAreas.filter(({ id }) => ids.includes(id));
|
|
78
|
+
return widgetAreas.filter(({ id }) => select(_wordpress_core_data.store).hasEditsForEntityRecord(__utils_js.KIND, __utils_js.POST_TYPE, (0, __utils_js.buildWidgetAreaPostId)(id))).map(({ id }) => select(_wordpress_core_data.store).getEditedEntityRecord(__utils_js.KIND, __utils_js.WIDGET_AREA_ENTITY_TYPE, id));
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Returns all blocks representing reference widgets.
|
|
82
|
+
*
|
|
83
|
+
* @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.
|
|
84
|
+
* @return {Array} List of all blocks representing reference widgets
|
|
85
|
+
*/
|
|
86
|
+
const getReferenceWidgetBlocks = (0, _wordpress_data.createRegistrySelector)((select) => (state, referenceWidgetName = null) => {
|
|
87
|
+
const results = [];
|
|
88
|
+
const widgetAreas = select(__constants_js.STORE_NAME).getWidgetAreas();
|
|
89
|
+
for (const _widgetArea of widgetAreas) {
|
|
90
|
+
const post = select(_wordpress_core_data.store).getEditedEntityRecord(__utils_js.KIND, __utils_js.POST_TYPE, (0, __utils_js.buildWidgetAreaPostId)(_widgetArea.id));
|
|
91
|
+
for (const block of post.blocks) if (block.name === "core/legacy-widget" && (!referenceWidgetName || block.attributes?.referenceWidgetName === referenceWidgetName)) results.push(block);
|
|
92
|
+
}
|
|
93
|
+
return results;
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* Returns true if any widget area is currently being saved.
|
|
97
|
+
*
|
|
98
|
+
* @return {boolean} True if any widget area is currently being saved. False otherwise.
|
|
99
|
+
*/
|
|
100
|
+
const isSavingWidgetAreas = (0, _wordpress_data.createRegistrySelector)((select) => () => {
|
|
101
|
+
const widgetAreasIds = select(__constants_js.STORE_NAME).getWidgetAreas()?.map(({ id }) => id);
|
|
102
|
+
if (!widgetAreasIds) return false;
|
|
103
|
+
for (const id of widgetAreasIds) if (select(_wordpress_core_data.store).isSavingEntityRecord(__utils_js.KIND, __utils_js.WIDGET_AREA_ENTITY_TYPE, id)) return true;
|
|
104
|
+
const widgetIds = [...Object.keys(select(__constants_js.STORE_NAME).getWidgets()), void 0];
|
|
105
|
+
for (const id of widgetIds) if (select(_wordpress_core_data.store).isSavingEntityRecord("root", "widget", id)) return true;
|
|
106
|
+
return false;
|
|
107
|
+
});
|
|
108
|
+
/**
|
|
109
|
+
* Gets whether the widget area is opened.
|
|
110
|
+
*
|
|
111
|
+
* @param {Array} state The open state of the widget areas.
|
|
112
|
+
* @param {string} clientId The clientId of the widget area.
|
|
113
|
+
*
|
|
114
|
+
* @return {boolean} True if the widget area is open.
|
|
115
|
+
*/
|
|
116
|
+
const getIsWidgetAreaOpen = (state, clientId) => {
|
|
117
|
+
const { widgetAreasOpenState } = state;
|
|
118
|
+
return !!widgetAreasOpenState[clientId];
|
|
196
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* Returns true if the inserter is opened.
|
|
122
|
+
*
|
|
123
|
+
* @param {Object} state Global application state.
|
|
124
|
+
*
|
|
125
|
+
* @return {boolean} Whether the inserter is opened.
|
|
126
|
+
*/
|
|
197
127
|
function isInserterOpened(state) {
|
|
198
|
-
|
|
128
|
+
return !!state.blockInserterPanel;
|
|
199
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Get the insertion point for the inserter.
|
|
132
|
+
*
|
|
133
|
+
* @param {Object} state Global application state.
|
|
134
|
+
*
|
|
135
|
+
* @return {Object} The root client ID and index to insert at.
|
|
136
|
+
*/
|
|
200
137
|
function __experimentalGetInsertionPoint(state) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
return state.blockInserterPanel;
|
|
138
|
+
if (typeof state.blockInserterPanel === "boolean") return EMPTY_INSERTION_POINT;
|
|
139
|
+
return state.blockInserterPanel;
|
|
205
140
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
);
|
|
141
|
+
/**
|
|
142
|
+
* Returns true if a block can be inserted into a widget area.
|
|
143
|
+
*
|
|
144
|
+
* @param {Array} state The open state of the widget areas.
|
|
145
|
+
* @param {string} blockName The name of the block being inserted.
|
|
146
|
+
*
|
|
147
|
+
* @return {boolean} True if the block can be inserted in a widget area.
|
|
148
|
+
*/
|
|
149
|
+
const canInsertBlockInWidgetArea = (0, _wordpress_data.createRegistrySelector)((select) => (state, blockName) => {
|
|
150
|
+
const [firstWidgetArea] = select(_wordpress_block_editor.store).getBlocks();
|
|
151
|
+
if (!firstWidgetArea) return false;
|
|
152
|
+
return select(_wordpress_block_editor.store).canInsertBlockType(blockName, firstWidgetArea.clientId);
|
|
153
|
+
});
|
|
154
|
+
/**
|
|
155
|
+
* Returns true if the list view is opened.
|
|
156
|
+
*
|
|
157
|
+
* @param {Object} state Global application state.
|
|
158
|
+
*
|
|
159
|
+
* @return {boolean} Whether the list view is opened.
|
|
160
|
+
*/
|
|
219
161
|
function isListViewOpened(state) {
|
|
220
|
-
|
|
162
|
+
return state.listViewPanel;
|
|
221
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Returns whether widget saving is locked.
|
|
166
|
+
*
|
|
167
|
+
* @param {Object} state Global application state.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```jsx
|
|
171
|
+
* import { __ } from '@wordpress/i18n';
|
|
172
|
+
* import { store as widgetStore } from '@wordpress/edit-widgets';
|
|
173
|
+
* import { useSelect } from '@wordpress/data';
|
|
174
|
+
*
|
|
175
|
+
* const ExampleComponent = () => {
|
|
176
|
+
* const isSavingLocked = useSelect(
|
|
177
|
+
* ( select ) => select( widgetStore ).isWidgetSavingLocked(),
|
|
178
|
+
* []
|
|
179
|
+
* );
|
|
180
|
+
*
|
|
181
|
+
* return isSavingLocked ? (
|
|
182
|
+
* <p>{ __( 'Widget saving is locked' ) }</p>
|
|
183
|
+
* ) : (
|
|
184
|
+
* <p>{ __( 'Widget saving is not locked' ) }</p>
|
|
185
|
+
* );
|
|
186
|
+
* };
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @return {boolean} Is locked.
|
|
190
|
+
*/
|
|
222
191
|
function isWidgetSavingLocked(state) {
|
|
223
|
-
|
|
192
|
+
return Object.keys(state.widgetSavingLock).length > 0;
|
|
224
193
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
});
|
|
242
|
-
//# sourceMappingURL=selectors.cjs.map
|
|
194
|
+
exports.__experimentalGetInsertionPoint = __experimentalGetInsertionPoint;
|
|
195
|
+
exports.canInsertBlockInWidgetArea = canInsertBlockInWidgetArea;
|
|
196
|
+
exports.getEditedWidgetAreas = getEditedWidgetAreas;
|
|
197
|
+
exports.getIsWidgetAreaOpen = getIsWidgetAreaOpen;
|
|
198
|
+
exports.getParentWidgetAreaBlock = getParentWidgetAreaBlock;
|
|
199
|
+
exports.getReferenceWidgetBlocks = getReferenceWidgetBlocks;
|
|
200
|
+
exports.getWidget = getWidget;
|
|
201
|
+
exports.getWidgetAreaForWidgetId = getWidgetAreaForWidgetId;
|
|
202
|
+
exports.getWidgetAreas = getWidgetAreas;
|
|
203
|
+
exports.getWidgets = getWidgets;
|
|
204
|
+
exports.isInserterOpened = isInserterOpened;
|
|
205
|
+
exports.isListViewOpened = isListViewOpened;
|
|
206
|
+
exports.isSavingWidgetAreas = isSavingWidgetAreas;
|
|
207
|
+
exports.isWidgetSavingLocked = isWidgetSavingLocked;
|
|
208
|
+
|
|
209
|
+
//# sourceMappingURL=selectors.cjs.map
|