@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,212 +1,191 @@
|
|
|
1
|
-
|
|
2
|
-
import { createSelector, createRegistrySelector } from "@wordpress/data";
|
|
1
|
+
import { createRegistrySelector, createSelector } from "@wordpress/data";
|
|
3
2
|
import { getWidgetIdFromBlock } from "@wordpress/widgets";
|
|
4
|
-
import { store
|
|
5
|
-
import { store as
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
WIDGET_AREA_ENTITY_TYPE
|
|
13
|
-
} from "./utils.mjs";
|
|
14
|
-
import { STORE_NAME as editWidgetsStoreName } from "./constants.mjs";
|
|
15
|
-
var EMPTY_INSERTION_POINT = {
|
|
16
|
-
rootClientId: void 0,
|
|
17
|
-
insertionIndex: void 0
|
|
3
|
+
import { store } from "@wordpress/core-data";
|
|
4
|
+
import { store as store$1 } from "@wordpress/block-editor";
|
|
5
|
+
import { KIND, POST_TYPE, WIDGET_AREA_ENTITY_TYPE, buildWidgetAreaPostId, buildWidgetAreasQuery, buildWidgetsQuery } from "./utils.mjs";
|
|
6
|
+
import { STORE_NAME } from "./constants.mjs";
|
|
7
|
+
// packages/edit-widgets/src/store/selectors.js
|
|
8
|
+
const EMPTY_INSERTION_POINT = {
|
|
9
|
+
rootClientId: void 0,
|
|
10
|
+
insertionIndex: void 0
|
|
18
11
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Returns all API widgets.
|
|
14
|
+
*
|
|
15
|
+
* @return {Object[]} API List of widgets.
|
|
16
|
+
*/
|
|
17
|
+
const getWidgets = createRegistrySelector((select) => createSelector(() => {
|
|
18
|
+
return select(store).getEntityRecords("root", "widget", buildWidgetsQuery())?.reduce((allWidgets, widget) => ({
|
|
19
|
+
...allWidgets,
|
|
20
|
+
[widget.id]: widget
|
|
21
|
+
}), {}) ?? {};
|
|
22
|
+
}, () => [select(store).getEntityRecords("root", "widget", buildWidgetsQuery())]));
|
|
23
|
+
/**
|
|
24
|
+
* Returns API widget data for a particular widget ID.
|
|
25
|
+
*
|
|
26
|
+
* @param {number} id Widget ID.
|
|
27
|
+
*
|
|
28
|
+
* @return {Object} API widget data for a particular widget ID.
|
|
29
|
+
*/
|
|
30
|
+
const getWidget = createRegistrySelector((select) => (state, id) => {
|
|
31
|
+
return select(STORE_NAME).getWidgets()[id];
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Returns all API widget areas.
|
|
35
|
+
*
|
|
36
|
+
* @return {Object[]} API List of widget areas.
|
|
37
|
+
*/
|
|
38
|
+
const getWidgetAreas = createRegistrySelector((select) => () => {
|
|
39
|
+
const query = buildWidgetAreasQuery();
|
|
40
|
+
return select(store).getEntityRecords(KIND, WIDGET_AREA_ENTITY_TYPE, query);
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* Returns widgetArea containing a block identify by given widgetId
|
|
44
|
+
*
|
|
45
|
+
* @param {string} widgetId The ID of the widget.
|
|
46
|
+
* @return {Object} Containing widget area.
|
|
47
|
+
*/
|
|
48
|
+
const getWidgetAreaForWidgetId = createRegistrySelector((select) => (state, widgetId) => {
|
|
49
|
+
return select(STORE_NAME).getWidgetAreas().find((widgetArea) => {
|
|
50
|
+
return select(store).getEditedEntityRecord(KIND, POST_TYPE, buildWidgetAreaPostId(widgetArea.id)).blocks.map((block) => getWidgetIdFromBlock(block)).includes(widgetId);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* Given a child client id, returns the parent widget area block.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} clientId The client id of a block in a widget area.
|
|
57
|
+
*
|
|
58
|
+
* @return {WPBlock} The widget area block.
|
|
59
|
+
*/
|
|
60
|
+
const getParentWidgetAreaBlock = createRegistrySelector((select) => (state, clientId) => {
|
|
61
|
+
const { getBlock, getBlockName, getBlockParents } = select(store$1);
|
|
62
|
+
return getBlock(getBlockParents(clientId).find((parentClientId) => getBlockName(parentClientId) === "core/widget-area"));
|
|
60
63
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
(block) => getWidgetIdFromBlock(block)
|
|
72
|
-
);
|
|
73
|
-
return blockWidgetIds.includes(widgetId);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
);
|
|
77
|
-
var getParentWidgetAreaBlock = createRegistrySelector(
|
|
78
|
-
(select) => (state, clientId) => {
|
|
79
|
-
const { getBlock, getBlockName, getBlockParents } = select(blockEditorStore);
|
|
80
|
-
const blockParents = getBlockParents(clientId);
|
|
81
|
-
const widgetAreaClientId = blockParents.find(
|
|
82
|
-
(parentClientId) => getBlockName(parentClientId) === "core/widget-area"
|
|
83
|
-
);
|
|
84
|
-
return getBlock(widgetAreaClientId);
|
|
85
|
-
}
|
|
86
|
-
);
|
|
87
|
-
var getEditedWidgetAreas = createRegistrySelector(
|
|
88
|
-
(select) => (state, ids) => {
|
|
89
|
-
let widgetAreas = select(editWidgetsStoreName).getWidgetAreas();
|
|
90
|
-
if (!widgetAreas) {
|
|
91
|
-
return [];
|
|
92
|
-
}
|
|
93
|
-
if (ids) {
|
|
94
|
-
widgetAreas = widgetAreas.filter(
|
|
95
|
-
({ id }) => ids.includes(id)
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
return widgetAreas.filter(
|
|
99
|
-
({ id }) => select(coreStore).hasEditsForEntityRecord(
|
|
100
|
-
KIND,
|
|
101
|
-
POST_TYPE,
|
|
102
|
-
buildWidgetAreaPostId(id)
|
|
103
|
-
)
|
|
104
|
-
).map(
|
|
105
|
-
({ id }) => select(coreStore).getEditedEntityRecord(
|
|
106
|
-
KIND,
|
|
107
|
-
WIDGET_AREA_ENTITY_TYPE,
|
|
108
|
-
id
|
|
109
|
-
)
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
);
|
|
113
|
-
var getReferenceWidgetBlocks = createRegistrySelector(
|
|
114
|
-
(select) => (state, referenceWidgetName = null) => {
|
|
115
|
-
const results = [];
|
|
116
|
-
const widgetAreas = select(editWidgetsStoreName).getWidgetAreas();
|
|
117
|
-
for (const _widgetArea of widgetAreas) {
|
|
118
|
-
const post = select(coreStore).getEditedEntityRecord(
|
|
119
|
-
KIND,
|
|
120
|
-
POST_TYPE,
|
|
121
|
-
buildWidgetAreaPostId(_widgetArea.id)
|
|
122
|
-
);
|
|
123
|
-
for (const block of post.blocks) {
|
|
124
|
-
if (block.name === "core/legacy-widget" && (!referenceWidgetName || block.attributes?.referenceWidgetName === referenceWidgetName)) {
|
|
125
|
-
results.push(block);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return results;
|
|
130
|
-
}
|
|
131
|
-
);
|
|
132
|
-
var isSavingWidgetAreas = createRegistrySelector((select) => () => {
|
|
133
|
-
const widgetAreasIds = select(editWidgetsStoreName).getWidgetAreas()?.map(({ id }) => id);
|
|
134
|
-
if (!widgetAreasIds) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
for (const id of widgetAreasIds) {
|
|
138
|
-
const isSaving = select(coreStore).isSavingEntityRecord(
|
|
139
|
-
KIND,
|
|
140
|
-
WIDGET_AREA_ENTITY_TYPE,
|
|
141
|
-
id
|
|
142
|
-
);
|
|
143
|
-
if (isSaving) {
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
const widgetIds = [
|
|
148
|
-
...Object.keys(select(editWidgetsStoreName).getWidgets()),
|
|
149
|
-
void 0
|
|
150
|
-
// account for new widgets without an ID
|
|
151
|
-
];
|
|
152
|
-
for (const id of widgetIds) {
|
|
153
|
-
const isSaving = select(coreStore).isSavingEntityRecord(
|
|
154
|
-
"root",
|
|
155
|
-
"widget",
|
|
156
|
-
id
|
|
157
|
-
);
|
|
158
|
-
if (isSaving) {
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return false;
|
|
64
|
+
/**
|
|
65
|
+
* Returns all edited widget area entity records.
|
|
66
|
+
*
|
|
67
|
+
* @return {Object[]} List of edited widget area entity records.
|
|
68
|
+
*/
|
|
69
|
+
const getEditedWidgetAreas = createRegistrySelector((select) => (state, ids) => {
|
|
70
|
+
let widgetAreas = select(STORE_NAME).getWidgetAreas();
|
|
71
|
+
if (!widgetAreas) return [];
|
|
72
|
+
if (ids) widgetAreas = widgetAreas.filter(({ id }) => ids.includes(id));
|
|
73
|
+
return widgetAreas.filter(({ id }) => select(store).hasEditsForEntityRecord(KIND, POST_TYPE, buildWidgetAreaPostId(id))).map(({ id }) => select(store).getEditedEntityRecord(KIND, WIDGET_AREA_ENTITY_TYPE, id));
|
|
163
74
|
});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Returns all blocks representing reference widgets.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.
|
|
79
|
+
* @return {Array} List of all blocks representing reference widgets
|
|
80
|
+
*/
|
|
81
|
+
const getReferenceWidgetBlocks = createRegistrySelector((select) => (state, referenceWidgetName = null) => {
|
|
82
|
+
const results = [];
|
|
83
|
+
const widgetAreas = select(STORE_NAME).getWidgetAreas();
|
|
84
|
+
for (const _widgetArea of widgetAreas) {
|
|
85
|
+
const post = select(store).getEditedEntityRecord(KIND, POST_TYPE, buildWidgetAreaPostId(_widgetArea.id));
|
|
86
|
+
for (const block of post.blocks) if (block.name === "core/legacy-widget" && (!referenceWidgetName || block.attributes?.referenceWidgetName === referenceWidgetName)) results.push(block);
|
|
87
|
+
}
|
|
88
|
+
return results;
|
|
89
|
+
});
|
|
90
|
+
/**
|
|
91
|
+
* Returns true if any widget area is currently being saved.
|
|
92
|
+
*
|
|
93
|
+
* @return {boolean} True if any widget area is currently being saved. False otherwise.
|
|
94
|
+
*/
|
|
95
|
+
const isSavingWidgetAreas = createRegistrySelector((select) => () => {
|
|
96
|
+
const widgetAreasIds = select(STORE_NAME).getWidgetAreas()?.map(({ id }) => id);
|
|
97
|
+
if (!widgetAreasIds) return false;
|
|
98
|
+
for (const id of widgetAreasIds) if (select(store).isSavingEntityRecord(KIND, WIDGET_AREA_ENTITY_TYPE, id)) return true;
|
|
99
|
+
const widgetIds = [...Object.keys(select(STORE_NAME).getWidgets()), void 0];
|
|
100
|
+
for (const id of widgetIds) if (select(store).isSavingEntityRecord("root", "widget", id)) return true;
|
|
101
|
+
return false;
|
|
102
|
+
});
|
|
103
|
+
/**
|
|
104
|
+
* Gets whether the widget area is opened.
|
|
105
|
+
*
|
|
106
|
+
* @param {Array} state The open state of the widget areas.
|
|
107
|
+
* @param {string} clientId The clientId of the widget area.
|
|
108
|
+
*
|
|
109
|
+
* @return {boolean} True if the widget area is open.
|
|
110
|
+
*/
|
|
111
|
+
const getIsWidgetAreaOpen = (state, clientId) => {
|
|
112
|
+
const { widgetAreasOpenState } = state;
|
|
113
|
+
return !!widgetAreasOpenState[clientId];
|
|
167
114
|
};
|
|
115
|
+
/**
|
|
116
|
+
* Returns true if the inserter is opened.
|
|
117
|
+
*
|
|
118
|
+
* @param {Object} state Global application state.
|
|
119
|
+
*
|
|
120
|
+
* @return {boolean} Whether the inserter is opened.
|
|
121
|
+
*/
|
|
168
122
|
function isInserterOpened(state) {
|
|
169
|
-
|
|
123
|
+
return !!state.blockInserterPanel;
|
|
170
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Get the insertion point for the inserter.
|
|
127
|
+
*
|
|
128
|
+
* @param {Object} state Global application state.
|
|
129
|
+
*
|
|
130
|
+
* @return {Object} The root client ID and index to insert at.
|
|
131
|
+
*/
|
|
171
132
|
function __experimentalGetInsertionPoint(state) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
return state.blockInserterPanel;
|
|
133
|
+
if (typeof state.blockInserterPanel === "boolean") return EMPTY_INSERTION_POINT;
|
|
134
|
+
return state.blockInserterPanel;
|
|
176
135
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
);
|
|
136
|
+
/**
|
|
137
|
+
* Returns true if a block can be inserted into a widget area.
|
|
138
|
+
*
|
|
139
|
+
* @param {Array} state The open state of the widget areas.
|
|
140
|
+
* @param {string} blockName The name of the block being inserted.
|
|
141
|
+
*
|
|
142
|
+
* @return {boolean} True if the block can be inserted in a widget area.
|
|
143
|
+
*/
|
|
144
|
+
const canInsertBlockInWidgetArea = createRegistrySelector((select) => (state, blockName) => {
|
|
145
|
+
const [firstWidgetArea] = select(store$1).getBlocks();
|
|
146
|
+
if (!firstWidgetArea) return false;
|
|
147
|
+
return select(store$1).canInsertBlockType(blockName, firstWidgetArea.clientId);
|
|
148
|
+
});
|
|
149
|
+
/**
|
|
150
|
+
* Returns true if the list view is opened.
|
|
151
|
+
*
|
|
152
|
+
* @param {Object} state Global application state.
|
|
153
|
+
*
|
|
154
|
+
* @return {boolean} Whether the list view is opened.
|
|
155
|
+
*/
|
|
190
156
|
function isListViewOpened(state) {
|
|
191
|
-
|
|
157
|
+
return state.listViewPanel;
|
|
192
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Returns whether widget saving is locked.
|
|
161
|
+
*
|
|
162
|
+
* @param {Object} state Global application state.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```jsx
|
|
166
|
+
* import { __ } from '@wordpress/i18n';
|
|
167
|
+
* import { store as widgetStore } from '@wordpress/edit-widgets';
|
|
168
|
+
* import { useSelect } from '@wordpress/data';
|
|
169
|
+
*
|
|
170
|
+
* const ExampleComponent = () => {
|
|
171
|
+
* const isSavingLocked = useSelect(
|
|
172
|
+
* ( select ) => select( widgetStore ).isWidgetSavingLocked(),
|
|
173
|
+
* []
|
|
174
|
+
* );
|
|
175
|
+
*
|
|
176
|
+
* return isSavingLocked ? (
|
|
177
|
+
* <p>{ __( 'Widget saving is locked' ) }</p>
|
|
178
|
+
* ) : (
|
|
179
|
+
* <p>{ __( 'Widget saving is not locked' ) }</p>
|
|
180
|
+
* );
|
|
181
|
+
* };
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* @return {boolean} Is locked.
|
|
185
|
+
*/
|
|
193
186
|
function isWidgetSavingLocked(state) {
|
|
194
|
-
|
|
187
|
+
return Object.keys(state.widgetSavingLock).length > 0;
|
|
195
188
|
}
|
|
196
|
-
export {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
getEditedWidgetAreas,
|
|
200
|
-
getIsWidgetAreaOpen,
|
|
201
|
-
getParentWidgetAreaBlock,
|
|
202
|
-
getReferenceWidgetBlocks,
|
|
203
|
-
getWidget,
|
|
204
|
-
getWidgetAreaForWidgetId,
|
|
205
|
-
getWidgetAreas,
|
|
206
|
-
getWidgets,
|
|
207
|
-
isInserterOpened,
|
|
208
|
-
isListViewOpened,
|
|
209
|
-
isSavingWidgetAreas,
|
|
210
|
-
isWidgetSavingLocked
|
|
211
|
-
};
|
|
212
|
-
//# sourceMappingURL=selectors.mjs.map
|
|
189
|
+
export { __experimentalGetInsertionPoint, canInsertBlockInWidgetArea, getEditedWidgetAreas, getIsWidgetAreaOpen, getParentWidgetAreaBlock, getReferenceWidgetBlocks, getWidget, getWidgetAreaForWidgetId, getWidgetAreas, getWidgets, isInserterOpened, isListViewOpened, isSavingWidgetAreas, isWidgetSavingLocked };
|
|
190
|
+
|
|
191
|
+
//# sourceMappingURL=selectors.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/selectors.js"],
|
|
4
|
-
"sourcesContent": ["import { createSelector, createRegistrySelector } from '@wordpress/data';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport {\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tKIND,\n\tPOST_TYPE,\n\tWIDGET_AREA_ENTITY_TYPE,\n} from './utils';\nimport { STORE_NAME as editWidgetsStoreName } from './constants';\n\nconst EMPTY_INSERTION_POINT = {\n\trootClientId: undefined,\n\tinsertionIndex: undefined,\n};\n\n/**\n * Returns all API widgets.\n *\n * @return {Object[]} API List of widgets.\n */\nexport const getWidgets = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst widgets = select( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t// Key widgets by their ID.\n\t\t\t\twidgets?.reduce(\n\t\t\t\t\t( allWidgets, widget ) => ( {\n\t\t\t\t\t\t...allWidgets,\n\t\t\t\t\t\t[ widget.id ]: widget,\n\t\t\t\t\t} ),\n\t\t\t\t\t{}\n\t\t\t\t) ?? {}\n\t\t\t);\n\t\t},\n\t\t() => [\n\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t),\n\t\t]\n\t)\n);\n\n/**\n * Returns API widget data for a particular widget ID.\n *\n * @param {number} id Widget ID.\n *\n * @return {Object} API widget data for a particular widget ID.\n */\nexport const getWidget = createRegistrySelector(\n\t( select ) => ( state, id ) => {\n\t\tconst widgets = select( editWidgetsStoreName ).getWidgets();\n\t\treturn widgets[ id ];\n\t}\n);\n\n/**\n * Returns all API widget areas.\n *\n * @return {Object[]} API List of widget areas.\n */\nexport const getWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst query = buildWidgetAreasQuery();\n\treturn select( coreStore ).getEntityRecords(\n\t\tKIND,\n\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\tquery\n\t);\n} );\n\n/**\n * Returns widgetArea containing a block identify by given widgetId\n *\n * @param {string} widgetId The ID of the widget.\n * @return {Object} Containing widget area.\n */\nexport const getWidgetAreaForWidgetId = createRegistrySelector(\n\t( select ) => ( state, widgetId ) => {\n\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\treturn widgetAreas.find( ( widgetArea ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tbuildWidgetAreaPostId( widgetArea.id )\n\t\t\t);\n\t\t\tconst blockWidgetIds = post.blocks.map( ( block ) =>\n\t\t\t\tgetWidgetIdFromBlock( block )\n\t\t\t);\n\t\t\treturn blockWidgetIds.includes( widgetId );\n\t\t} );\n\t}\n);\n\n/**\n * Given a child client id, returns the parent widget area block.\n *\n * @param {string} clientId The client id of a block in a widget area.\n *\n * @return {WPBlock} The widget area block.\n */\nexport const getParentWidgetAreaBlock = createRegistrySelector(\n\t( select ) => ( state, clientId ) => {\n\t\tconst { getBlock, getBlockName, getBlockParents } =\n\t\t\tselect( blockEditorStore );\n\t\tconst blockParents = getBlockParents( clientId );\n\t\tconst widgetAreaClientId = blockParents.find(\n\t\t\t( parentClientId ) =>\n\t\t\t\tgetBlockName( parentClientId ) === 'core/widget-area'\n\t\t);\n\t\treturn getBlock( widgetAreaClientId );\n\t}\n);\n\n/**\n * Returns all edited widget area entity records.\n *\n * @return {Object[]} List of edited widget area entity records.\n */\nexport const getEditedWidgetAreas = createRegistrySelector(\n\t( select ) => ( state, ids ) => {\n\t\tlet widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\tif ( ! widgetAreas ) {\n\t\t\treturn [];\n\t\t}\n\t\tif ( ids ) {\n\t\t\twidgetAreas = widgetAreas.filter( ( { id } ) =>\n\t\t\t\tids.includes( id )\n\t\t\t);\n\t\t}\n\t\treturn widgetAreas\n\t\t\t.filter( ( { id } ) =>\n\t\t\t\tselect( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( id )\n\t\t\t\t)\n\t\t\t)\n\t\t\t.map( ( { id } ) =>\n\t\t\t\tselect( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\t\tid\n\t\t\t\t)\n\t\t\t);\n\t}\n);\n\n/**\n * Returns all blocks representing reference widgets.\n *\n * @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.\n * @return {Array} List of all blocks representing reference widgets\n */\nexport const getReferenceWidgetBlocks = createRegistrySelector(\n\t( select ) =>\n\t\t( state, referenceWidgetName = null ) => {\n\t\t\tconst results = [];\n\t\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\t\tfor ( const _widgetArea of widgetAreas ) {\n\t\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( _widgetArea.id )\n\t\t\t\t);\n\t\t\t\tfor ( const block of post.blocks ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tblock.name === 'core/legacy-widget' &&\n\t\t\t\t\t\t( ! referenceWidgetName ||\n\t\t\t\t\t\t\tblock.attributes?.referenceWidgetName ===\n\t\t\t\t\t\t\t\treferenceWidgetName )\n\t\t\t\t\t) {\n\t\t\t\t\t\tresults.push( block );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n);\n\n/**\n * Returns true if any widget area is currently being saved.\n *\n * @return {boolean} True if any widget area is currently being saved. False otherwise.\n */\nexport const isSavingWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst widgetAreasIds = select( editWidgetsStoreName )\n\t\t.getWidgetAreas()\n\t\t?.map( ( { id } ) => id );\n\tif ( ! widgetAreasIds ) {\n\t\treturn false;\n\t}\n\n\tfor ( const id of widgetAreasIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\tKIND,\n\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tconst widgetIds = [\n\t\t...Object.keys( select( editWidgetsStoreName ).getWidgets() ),\n\t\tundefined, // account for new widgets without an ID\n\t];\n\tfor ( const id of widgetIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\t'root',\n\t\t\t'widget',\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n} );\n\n/**\n * Gets whether the widget area is opened.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} clientId The clientId of the widget area.\n *\n * @return {boolean} True if the widget area is open.\n */\nexport const getIsWidgetAreaOpen = ( state, clientId ) => {\n\tconst { widgetAreasOpenState } = state;\n\treturn !! widgetAreasOpenState[ clientId ];\n};\n\n/**\n * Returns true if the inserter is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the inserter is opened.\n */\nexport function isInserterOpened( state ) {\n\treturn !! state.blockInserterPanel;\n}\n\n/**\n * Get the insertion point for the inserter.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} The root client ID and index to insert at.\n */\nexport function __experimentalGetInsertionPoint( state ) {\n\tif ( typeof state.blockInserterPanel === 'boolean' ) {\n\t\treturn EMPTY_INSERTION_POINT;\n\t}\n\n\treturn state.blockInserterPanel;\n}\n\n/**\n * Returns true if a block can be inserted into a widget area.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} blockName The name of the block being inserted.\n *\n * @return {boolean} True if the block can be inserted in a widget area.\n */\nexport const canInsertBlockInWidgetArea = createRegistrySelector(\n\t( select ) => ( state, blockName ) => {\n\t\t// Widget areas are always top-level blocks, which getBlocks will return.\n\t\tconst widgetAreas = select( blockEditorStore ).getBlocks();\n\n\t\t// Makes an assumption that a block that can be inserted into one\n\t\t// widget area can be inserted into any widget area. Uses the first\n\t\t// widget area for testing whether the block can be inserted.\n\t\tconst [ firstWidgetArea ] = widgetAreas;\n\t\tif ( ! firstWidgetArea ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn select( blockEditorStore ).canInsertBlockType(\n\t\t\tblockName,\n\t\t\tfirstWidgetArea.clientId\n\t\t);\n\t}\n);\n\n/**\n * Returns true if the list view is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the list view is opened.\n */\nexport function isListViewOpened( state ) {\n\treturn state.listViewPanel;\n}\n\n/**\n * Returns whether widget saving is locked.\n *\n * @param {Object} state Global application state.\n *\n * @example\n * ```jsx\n * import { __ } from '@wordpress/i18n';\n * import { store as widgetStore } from '@wordpress/edit-widgets';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * \tconst isSavingLocked = useSelect(\n * \t\t( select ) => select( widgetStore ).isWidgetSavingLocked(),\n * \t\t[]\n * \t);\n *\n * \treturn isSavingLocked ? (\n * \t\t<p>{ __( 'Widget saving is locked' ) }</p>\n * \t) : (\n * \t\t<p>{ __( 'Widget saving is not locked' ) }</p>\n * \t);\n * };\n * ```\n *\n * @return {boolean} Is locked.\n */\nexport function isWidgetSavingLocked( state ) {\n\treturn Object.keys( state.widgetSavingLock ).length > 0;\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,gBAAgB,8BAA8B;AACvD,SAAS,4BAA4B;AACrC,SAAS,SAAS,iBAAiB;AACnC,SAAS,SAAS,wBAAwB;AAC1C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,cAAc,4BAA4B;AAEnD,IAAM,wBAAwB;AAAA,EAC7B,cAAc;AAAA,EACd,gBAAgB;AACjB;AAOO,IAAM,aAAa;AAAA,EAAwB,CAAE,WACnD;AAAA,IACC,MAAM;AACL,YAAM,UAAU,OAAQ,SAAU,EAAE;AAAA,QACnC;AAAA,QACA;AAAA,QACA,kBAAkB;AAAA,MACnB;AAEA;AAAA;AAAA,QAEC,SAAS;AAAA,UACR,CAAE,YAAY,YAAc;AAAA,YAC3B,GAAG;AAAA,YACH,CAAE,OAAO,EAAG,GAAG;AAAA,UAChB;AAAA,UACA,CAAC;AAAA,QACF,KAAK,CAAC;AAAA;AAAA,IAER;AAAA,IACA,MAAM;AAAA,MACL,OAAQ,SAAU,EAAE;AAAA,QACnB;AAAA,QACA;AAAA,QACA,kBAAkB;AAAA,MACnB;A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EACD;AACA,aAAY,MAAM,WAAY;AAC7B,UAAM,WAAW,OAAQ,SAAU,EAAE;AAAA,MACpC;AAAA,MACA;AAAA,MACA;AAAA,IACD;AACA,QAAK,UAAW;AACf,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO;AACR,CAAE;AAUK,IAAM,sBAAsB,CAAE,OAAO,aAAc;AACzD,QAAM,EAAE,qBAAqB,IAAI;AACjC,SAAO,CAAC,CAAE,qBAAsB,QAAS;AAC1C;AASO,SAAS,iBAAkB,OAAQ;AACzC,SAAO,CAAC,CAAE,MAAM;AACjB;AASO,SAAS,gCAAiC,OAAQ;AACxD,MAAK,OAAO,MAAM,uBAAuB,WAAY;AACpD,WAAO;AAAA,EACR;AAEA,SAAO,MAAM;AACd;AAUO,IAAM,6BAA6B;AAAA,EACzC,CAAE,WAAY,CAAE,OAAO,cAAe;AAErC,UAAM,cAAc,OAAQ,gBAAiB,EAAE,UAAU;AAKzD,UAAM,CAAE,eAAgB,IAAI;AAC5B,QAAK,CAAE,iBAAkB;AACxB,aAAO;AAAA,IACR;AAEA,WAAO,OAAQ,gBAAiB,EAAE;AAAA,MACjC;AAAA,MACA,gBAAgB;AAAA,IACjB;AAAA,EACD;AACD;AASO,SAAS,iBAAkB,OAAQ;AACzC,SAAO,MAAM;AACd;AA6BO,SAAS,qBAAsB,OAAQ;AAC7C,SAAO,OAAO,KAAM,MAAM,gBAAiB,EAAE,SAAS;AACvD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"selectors.mjs","names":["coreStore","editWidgetsStoreName","blockEditorStore"],"sources":["../../src/store/selectors.js"],"sourcesContent":["import { createSelector, createRegistrySelector } from '@wordpress/data';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport {\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tKIND,\n\tPOST_TYPE,\n\tWIDGET_AREA_ENTITY_TYPE,\n} from './utils';\nimport { STORE_NAME as editWidgetsStoreName } from './constants';\n\nconst EMPTY_INSERTION_POINT = {\n\trootClientId: undefined,\n\tinsertionIndex: undefined,\n};\n\n/**\n * Returns all API widgets.\n *\n * @return {Object[]} API List of widgets.\n */\nexport const getWidgets = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst widgets = select( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t// Key widgets by their ID.\n\t\t\t\twidgets?.reduce(\n\t\t\t\t\t( allWidgets, widget ) => ( {\n\t\t\t\t\t\t...allWidgets,\n\t\t\t\t\t\t[ widget.id ]: widget,\n\t\t\t\t\t} ),\n\t\t\t\t\t{}\n\t\t\t\t) ?? {}\n\t\t\t);\n\t\t},\n\t\t() => [\n\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t),\n\t\t]\n\t)\n);\n\n/**\n * Returns API widget data for a particular widget ID.\n *\n * @param {number} id Widget ID.\n *\n * @return {Object} API widget data for a particular widget ID.\n */\nexport const getWidget = createRegistrySelector(\n\t( select ) => ( state, id ) => {\n\t\tconst widgets = select( editWidgetsStoreName ).getWidgets();\n\t\treturn widgets[ id ];\n\t}\n);\n\n/**\n * Returns all API widget areas.\n *\n * @return {Object[]} API List of widget areas.\n */\nexport const getWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst query = buildWidgetAreasQuery();\n\treturn select( coreStore ).getEntityRecords(\n\t\tKIND,\n\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\tquery\n\t);\n} );\n\n/**\n * Returns widgetArea containing a block identify by given widgetId\n *\n * @param {string} widgetId The ID of the widget.\n * @return {Object} Containing widget area.\n */\nexport const getWidgetAreaForWidgetId = createRegistrySelector(\n\t( select ) => ( state, widgetId ) => {\n\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\treturn widgetAreas.find( ( widgetArea ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tbuildWidgetAreaPostId( widgetArea.id )\n\t\t\t);\n\t\t\tconst blockWidgetIds = post.blocks.map( ( block ) =>\n\t\t\t\tgetWidgetIdFromBlock( block )\n\t\t\t);\n\t\t\treturn blockWidgetIds.includes( widgetId );\n\t\t} );\n\t}\n);\n\n/**\n * Given a child client id, returns the parent widget area block.\n *\n * @param {string} clientId The client id of a block in a widget area.\n *\n * @return {WPBlock} The widget area block.\n */\nexport const getParentWidgetAreaBlock = createRegistrySelector(\n\t( select ) => ( state, clientId ) => {\n\t\tconst { getBlock, getBlockName, getBlockParents } =\n\t\t\tselect( blockEditorStore );\n\t\tconst blockParents = getBlockParents( clientId );\n\t\tconst widgetAreaClientId = blockParents.find(\n\t\t\t( parentClientId ) =>\n\t\t\t\tgetBlockName( parentClientId ) === 'core/widget-area'\n\t\t);\n\t\treturn getBlock( widgetAreaClientId );\n\t}\n);\n\n/**\n * Returns all edited widget area entity records.\n *\n * @return {Object[]} List of edited widget area entity records.\n */\nexport const getEditedWidgetAreas = createRegistrySelector(\n\t( select ) => ( state, ids ) => {\n\t\tlet widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\tif ( ! widgetAreas ) {\n\t\t\treturn [];\n\t\t}\n\t\tif ( ids ) {\n\t\t\twidgetAreas = widgetAreas.filter( ( { id } ) =>\n\t\t\t\tids.includes( id )\n\t\t\t);\n\t\t}\n\t\treturn widgetAreas\n\t\t\t.filter( ( { id } ) =>\n\t\t\t\tselect( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( id )\n\t\t\t\t)\n\t\t\t)\n\t\t\t.map( ( { id } ) =>\n\t\t\t\tselect( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\t\tid\n\t\t\t\t)\n\t\t\t);\n\t}\n);\n\n/**\n * Returns all blocks representing reference widgets.\n *\n * @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.\n * @return {Array} List of all blocks representing reference widgets\n */\nexport const getReferenceWidgetBlocks = createRegistrySelector(\n\t( select ) =>\n\t\t( state, referenceWidgetName = null ) => {\n\t\t\tconst results = [];\n\t\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\t\tfor ( const _widgetArea of widgetAreas ) {\n\t\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( _widgetArea.id )\n\t\t\t\t);\n\t\t\t\tfor ( const block of post.blocks ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tblock.name === 'core/legacy-widget' &&\n\t\t\t\t\t\t( ! referenceWidgetName ||\n\t\t\t\t\t\t\tblock.attributes?.referenceWidgetName ===\n\t\t\t\t\t\t\t\treferenceWidgetName )\n\t\t\t\t\t) {\n\t\t\t\t\t\tresults.push( block );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n);\n\n/**\n * Returns true if any widget area is currently being saved.\n *\n * @return {boolean} True if any widget area is currently being saved. False otherwise.\n */\nexport const isSavingWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst widgetAreasIds = select( editWidgetsStoreName )\n\t\t.getWidgetAreas()\n\t\t?.map( ( { id } ) => id );\n\tif ( ! widgetAreasIds ) {\n\t\treturn false;\n\t}\n\n\tfor ( const id of widgetAreasIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\tKIND,\n\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tconst widgetIds = [\n\t\t...Object.keys( select( editWidgetsStoreName ).getWidgets() ),\n\t\tundefined, // account for new widgets without an ID\n\t];\n\tfor ( const id of widgetIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\t'root',\n\t\t\t'widget',\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n} );\n\n/**\n * Gets whether the widget area is opened.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} clientId The clientId of the widget area.\n *\n * @return {boolean} True if the widget area is open.\n */\nexport const getIsWidgetAreaOpen = ( state, clientId ) => {\n\tconst { widgetAreasOpenState } = state;\n\treturn !! widgetAreasOpenState[ clientId ];\n};\n\n/**\n * Returns true if the inserter is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the inserter is opened.\n */\nexport function isInserterOpened( state ) {\n\treturn !! state.blockInserterPanel;\n}\n\n/**\n * Get the insertion point for the inserter.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} The root client ID and index to insert at.\n */\nexport function __experimentalGetInsertionPoint( state ) {\n\tif ( typeof state.blockInserterPanel === 'boolean' ) {\n\t\treturn EMPTY_INSERTION_POINT;\n\t}\n\n\treturn state.blockInserterPanel;\n}\n\n/**\n * Returns true if a block can be inserted into a widget area.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} blockName The name of the block being inserted.\n *\n * @return {boolean} True if the block can be inserted in a widget area.\n */\nexport const canInsertBlockInWidgetArea = createRegistrySelector(\n\t( select ) => ( state, blockName ) => {\n\t\t// Widget areas are always top-level blocks, which getBlocks will return.\n\t\tconst widgetAreas = select( blockEditorStore ).getBlocks();\n\n\t\t// Makes an assumption that a block that can be inserted into one\n\t\t// widget area can be inserted into any widget area. Uses the first\n\t\t// widget area for testing whether the block can be inserted.\n\t\tconst [ firstWidgetArea ] = widgetAreas;\n\t\tif ( ! firstWidgetArea ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn select( blockEditorStore ).canInsertBlockType(\n\t\t\tblockName,\n\t\t\tfirstWidgetArea.clientId\n\t\t);\n\t}\n);\n\n/**\n * Returns true if the list view is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the list view is opened.\n */\nexport function isListViewOpened( state ) {\n\treturn state.listViewPanel;\n}\n\n/**\n * Returns whether widget saving is locked.\n *\n * @param {Object} state Global application state.\n *\n * @example\n * ```jsx\n * import { __ } from '@wordpress/i18n';\n * import { store as widgetStore } from '@wordpress/edit-widgets';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * \tconst isSavingLocked = useSelect(\n * \t\t( select ) => select( widgetStore ).isWidgetSavingLocked(),\n * \t\t[]\n * \t);\n *\n * \treturn isSavingLocked ? (\n * \t\t<p>{ __( 'Widget saving is locked' ) }</p>\n * \t) : (\n * \t\t<p>{ __( 'Widget saving is not locked' ) }</p>\n * \t);\n * };\n * ```\n *\n * @return {boolean} Is locked.\n */\nexport function isWidgetSavingLocked( state ) {\n\treturn Object.keys( state.widgetSavingLock ).length > 0;\n}\n"],"mappings":";;;;;;;AAcA,MAAM,wBAAwB;CAC7B,cAAc,KAAA;CACd,gBAAgB,KAAA;AACjB;;;;;;AAOA,MAAa,aAAa,wBAA0B,WACnD,qBACO;CAOL,OANgB,OAAQA,KAAU,CAAC,CAAC,iBACnC,QACA,UACA,kBAAkB,CAKZ,CAAC,EAAE,QACN,YAAY,YAAc;EAC3B,GAAG;GACD,OAAO,KAAM;CAChB,IACA,CAAC,CACF,KAAK,CAAC;AAER,SACM,CACL,OAAQA,KAAU,CAAC,CAAC,iBACnB,QACA,UACA,kBAAkB,CACnB,CACD,CACD,CACD;;;;;;;;AASA,MAAa,YAAY,wBACtB,YAAc,OAAO,OAAQ;CAE9B,OADgB,OAAQC,UAAqB,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;;;;;;;;AASA,SAAgB,iBAAkB,OAAQ;CACzC,OAAO,MAAM;AACd;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,qBAAsB,OAAQ;CAC7C,OAAO,OAAO,KAAM,MAAM,gBAAiB,CAAC,CAAC,SAAS;AACvD"}
|
|
@@ -1,62 +1,50 @@
|
|
|
1
|
-
// packages/edit-widgets/src/store/transformers.js
|
|
2
1
|
import { createBlock, parse, serialize } from "@wordpress/blocks";
|
|
3
2
|
import { addWidgetIdToBlock } from "@wordpress/widgets";
|
|
3
|
+
// packages/edit-widgets/src/store/transformers.js
|
|
4
|
+
/**
|
|
5
|
+
* Converts a widget entity record into a block.
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} widget The widget entity record.
|
|
8
|
+
* @return {Object} a block (converted from the entity record).
|
|
9
|
+
*/
|
|
4
10
|
function transformWidgetToBlock(widget) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let attributes;
|
|
18
|
-
if (widget._embedded.about[0].is_multi) {
|
|
19
|
-
attributes = {
|
|
20
|
-
idBase: widget.id_base,
|
|
21
|
-
instance: widget.instance
|
|
22
|
-
};
|
|
23
|
-
} else {
|
|
24
|
-
attributes = {
|
|
25
|
-
id: widget.id
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
return addWidgetIdToBlock(
|
|
29
|
-
createBlock("core/legacy-widget", attributes, []),
|
|
30
|
-
widget.id
|
|
31
|
-
);
|
|
11
|
+
if (widget.id_base === "block") {
|
|
12
|
+
const parsedBlocks = parse(widget.instance.raw.content, { __unstableSkipAutop: true });
|
|
13
|
+
if (!parsedBlocks.length) return addWidgetIdToBlock(createBlock("core/paragraph", {}, []), widget.id);
|
|
14
|
+
return addWidgetIdToBlock(parsedBlocks[0], widget.id);
|
|
15
|
+
}
|
|
16
|
+
let attributes;
|
|
17
|
+
if (widget._embedded.about[0].is_multi) attributes = {
|
|
18
|
+
idBase: widget.id_base,
|
|
19
|
+
instance: widget.instance
|
|
20
|
+
};
|
|
21
|
+
else attributes = { id: widget.id };
|
|
22
|
+
return addWidgetIdToBlock(createBlock("core/legacy-widget", attributes, []), widget.id);
|
|
32
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Converts a block to a widget entity record.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} block The block.
|
|
28
|
+
* @param {?Object} relatedWidget A related widget entity record from the API (optional).
|
|
29
|
+
* @return {Object} the widget object (converted from block).
|
|
30
|
+
*/
|
|
33
31
|
function transformBlockToWidget(block, relatedWidget = {}) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
content: serialize(block)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
delete widget.rendered;
|
|
55
|
-
delete widget.rendered_form;
|
|
56
|
-
return widget;
|
|
32
|
+
let widget;
|
|
33
|
+
if (block.name === "core/legacy-widget" && (block.attributes.id || block.attributes.instance)) widget = {
|
|
34
|
+
...relatedWidget,
|
|
35
|
+
id: block.attributes.id ?? relatedWidget.id,
|
|
36
|
+
id_base: block.attributes.idBase ?? relatedWidget.id_base,
|
|
37
|
+
instance: block.attributes.instance ?? relatedWidget.instance
|
|
38
|
+
};
|
|
39
|
+
else widget = {
|
|
40
|
+
...relatedWidget,
|
|
41
|
+
id_base: "block",
|
|
42
|
+
instance: { raw: { content: serialize(block) } }
|
|
43
|
+
};
|
|
44
|
+
delete widget.rendered;
|
|
45
|
+
delete widget.rendered_form;
|
|
46
|
+
return widget;
|
|
57
47
|
}
|
|
58
|
-
export {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
//# sourceMappingURL=transformers.mjs.map
|
|
48
|
+
export { transformBlockToWidget, transformWidgetToBlock };
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=transformers.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/transformers.js"],
|
|
4
|
-
"sourcesContent": ["import { createBlock, parse, serialize } from '@wordpress/blocks';\nimport { addWidgetIdToBlock } from '@wordpress/widgets';\n\n/**\n * Converts a widget entity record into a block.\n *\n * @param {Object} widget The widget entity record.\n * @return {Object} a block (converted from the entity record).\n */\nexport function transformWidgetToBlock( widget ) {\n\tif ( widget.id_base === 'block' ) {\n\t\tconst parsedBlocks = parse( widget.instance.raw.content, {\n\t\t\t__unstableSkipAutop: true,\n\t\t} );\n\t\tif ( ! parsedBlocks.length ) {\n\t\t\treturn addWidgetIdToBlock(\n\t\t\t\tcreateBlock( 'core/paragraph', {}, [] ),\n\t\t\t\twidget.id\n\t\t\t);\n\t\t}\n\t\treturn addWidgetIdToBlock( parsedBlocks[ 0 ], widget.id );\n\t}\n\n\tlet attributes;\n\tif ( widget._embedded.about[ 0 ].is_multi ) {\n\t\tattributes = {\n\t\t\tidBase: widget.id_base,\n\t\t\tinstance: widget.instance,\n\t\t};\n\t} else {\n\t\tattributes = {\n\t\t\tid: widget.id,\n\t\t};\n\t}\n\n\treturn addWidgetIdToBlock(\n\t\tcreateBlock( 'core/legacy-widget', attributes, [] ),\n\t\twidget.id\n\t);\n}\n\n/**\n * Converts a block to a widget entity record.\n *\n * @param {Object} block The block.\n * @param {?Object} relatedWidget A related widget entity record from the API (optional).\n * @return {Object} the widget object (converted from block).\n */\nexport function transformBlockToWidget( block, relatedWidget = {} ) {\n\tlet widget;\n\n\tconst isValidLegacyWidgetBlock =\n\t\tblock.name === 'core/legacy-widget' &&\n\t\t( block.attributes.id || block.attributes.instance );\n\n\tif ( isValidLegacyWidgetBlock ) {\n\t\twidget = {\n\t\t\t...relatedWidget,\n\t\t\tid: block.attributes.id ?? relatedWidget.id,\n\t\t\tid_base: block.attributes.idBase ?? relatedWidget.id_base,\n\t\t\tinstance: block.attributes.instance ?? relatedWidget.instance,\n\t\t};\n\t} else {\n\t\twidget = {\n\t\t\t...relatedWidget,\n\t\t\tid_base: 'block',\n\t\t\tinstance: {\n\t\t\t\traw: {\n\t\t\t\t\tcontent: serialize( block ),\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\t// Delete read-only properties.\n\tdelete widget.rendered;\n\tdelete widget.rendered_form;\n\n\treturn widget;\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,aAAa,OAAO,iBAAiB;AAC9C,SAAS,0BAA0B;AAQ5B,SAAS,uBAAwB,QAAS;AAChD,MAAK,OAAO,YAAY,SAAU;AACjC,UAAM,eAAe,MAAO,OAAO,SAAS,IAAI,SAAS;AAAA,MACxD,qBAAqB;AAAA,IACtB,CAAE;AACF,QAAK,CAAE,aAAa,QAAS;AAC5B,aAAO;AAAA,QACN,YAAa,kBAAkB,CAAC,GAAG,CAAC,CAAE;AAAA,QACtC,OAAO;AAAA,MACR;AAAA,IACD;AACA,WAAO,mBAAoB,aAAc,CAAE,GAAG,OAAO,EAAG;AAAA,EACzD;AAEA,MAAI;AACJ,MAAK,OAAO,UAAU,MAAO,CAAE,EAAE,UAAW;AAC3C,iBAAa;AAAA,MACZ,QAAQ,OAAO;AAAA,MACf,UAAU,OAAO;AAAA,IAClB;AAAA,EACD,OAAO;AACN,iBAAa;AAAA,MACZ,IAAI,OAAO;AAAA,IACZ;AAAA,EACD;AAEA,SAAO;AAAA,IACN,YAAa,sBAAsB,YAAY,CAAC,CAAE;AAAA,IAClD,OAAO;AAAA,EACR;AACD;AASO,SAAS,uBAAwB,OAAO,gBAAgB,CAAC,GAAI;AACnE,MAAI;AAEJ,QAAM,2BACL,MAAM,SAAS,yBACb,MAAM,WAAW,MAAM,MAAM,WAAW;AAE3C,MAAK,0BAA2B;AAC/B,aAAS;AAAA,MACR,GAAG;AAAA,MACH,IAAI,MAAM,WAAW,MAAM,cAAc;AAAA,MACzC,SAAS,MAAM,WAAW,UAAU,cAAc;AAAA,MAClD,UAAU,MAAM,WAAW,YAAY,cAAc;AAAA,IACtD;AAAA,EACD,OAAO;AACN,aAAS;AAAA,MACR,GAAG;AAAA,MACH,SAAS;AAAA,MACT,UAAU;AAAA,QACT,KAAK;AAAA,UACJ,SAAS,UAAW,KAAM;AAAA,QAC3B;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAGA,SAAO,OAAO;AACd,SAAO,OAAO;AAEd,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"transformers.mjs","names":[],"sources":["../../src/store/transformers.js"],"sourcesContent":["import { createBlock, parse, serialize } from '@wordpress/blocks';\nimport { addWidgetIdToBlock } from '@wordpress/widgets';\n\n/**\n * Converts a widget entity record into a block.\n *\n * @param {Object} widget The widget entity record.\n * @return {Object} a block (converted from the entity record).\n */\nexport function transformWidgetToBlock( widget ) {\n\tif ( widget.id_base === 'block' ) {\n\t\tconst parsedBlocks = parse( widget.instance.raw.content, {\n\t\t\t__unstableSkipAutop: true,\n\t\t} );\n\t\tif ( ! parsedBlocks.length ) {\n\t\t\treturn addWidgetIdToBlock(\n\t\t\t\tcreateBlock( 'core/paragraph', {}, [] ),\n\t\t\t\twidget.id\n\t\t\t);\n\t\t}\n\t\treturn addWidgetIdToBlock( parsedBlocks[ 0 ], widget.id );\n\t}\n\n\tlet attributes;\n\tif ( widget._embedded.about[ 0 ].is_multi ) {\n\t\tattributes = {\n\t\t\tidBase: widget.id_base,\n\t\t\tinstance: widget.instance,\n\t\t};\n\t} else {\n\t\tattributes = {\n\t\t\tid: widget.id,\n\t\t};\n\t}\n\n\treturn addWidgetIdToBlock(\n\t\tcreateBlock( 'core/legacy-widget', attributes, [] ),\n\t\twidget.id\n\t);\n}\n\n/**\n * Converts a block to a widget entity record.\n *\n * @param {Object} block The block.\n * @param {?Object} relatedWidget A related widget entity record from the API (optional).\n * @return {Object} the widget object (converted from block).\n */\nexport function transformBlockToWidget( block, relatedWidget = {} ) {\n\tlet widget;\n\n\tconst isValidLegacyWidgetBlock =\n\t\tblock.name === 'core/legacy-widget' &&\n\t\t( block.attributes.id || block.attributes.instance );\n\n\tif ( isValidLegacyWidgetBlock ) {\n\t\twidget = {\n\t\t\t...relatedWidget,\n\t\t\tid: block.attributes.id ?? relatedWidget.id,\n\t\t\tid_base: block.attributes.idBase ?? relatedWidget.id_base,\n\t\t\tinstance: block.attributes.instance ?? relatedWidget.instance,\n\t\t};\n\t} else {\n\t\twidget = {\n\t\t\t...relatedWidget,\n\t\t\tid_base: 'block',\n\t\t\tinstance: {\n\t\t\t\traw: {\n\t\t\t\t\tcontent: serialize( block ),\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\t// Delete read-only properties.\n\tdelete widget.rendered;\n\tdelete widget.rendered_form;\n\n\treturn widget;\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,uBAAwB,QAAS;CAChD,IAAK,OAAO,YAAY,SAAU;EACjC,MAAM,eAAe,MAAO,OAAO,SAAS,IAAI,SAAS,EACxD,qBAAqB,KACtB,CAAE;EACF,IAAK,CAAE,aAAa,QACnB,OAAO,mBACN,YAAa,kBAAkB,CAAC,GAAG,CAAC,CAAE,GACtC,OAAO,EACR;EAED,OAAO,mBAAoB,aAAc,IAAK,OAAO,EAAG;CACzD;CAEA,IAAI;CACJ,IAAK,OAAO,UAAU,MAAO,EAAG,CAAC,UAChC,aAAa;EACZ,QAAQ,OAAO;EACf,UAAU,OAAO;CAClB;MAEA,aAAa,EACZ,IAAI,OAAO,GACZ;CAGD,OAAO,mBACN,YAAa,sBAAsB,YAAY,CAAC,CAAE,GAClD,OAAO,EACR;AACD;;;;;;;;AASA,SAAgB,uBAAwB,OAAO,gBAAgB,CAAC,GAAI;CACnE,IAAI;CAMJ,IAHC,MAAM,SAAS,yBACb,MAAM,WAAW,MAAM,MAAM,WAAW,WAG1C,SAAS;EACR,GAAG;EACH,IAAI,MAAM,WAAW,MAAM,cAAc;EACzC,SAAS,MAAM,WAAW,UAAU,cAAc;EAClD,UAAU,MAAM,WAAW,YAAY,cAAc;CACtD;MAEA,SAAS;EACR,GAAG;EACH,SAAS;EACT,UAAU,EACT,KAAK,EACJ,SAAS,UAAW,KAAM,EAC3B,EACD;CACD;CAID,OAAO,OAAO;CACd,OAAO,OAAO;CAEd,OAAO;AACR"}
|