@wordpress/edit-widgets 5.15.0 → 5.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/build/blocks/widget-area/edit/index.js +4 -16
- package/build/blocks/widget-area/edit/index.js.map +1 -1
- package/build/blocks/widget-area/edit/inner-blocks.js +5 -10
- package/build/blocks/widget-area/edit/inner-blocks.js.map +1 -1
- package/build/blocks/widget-area/edit/use-is-dragging-within.js +5 -10
- package/build/blocks/widget-area/edit/use-is-dragging-within.js.map +1 -1
- package/build/blocks/widget-area/index.js +0 -5
- package/build/blocks/widget-area/index.js.map +1 -1
- package/build/components/error-boundary/index.js +1 -15
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/header/index.js +9 -32
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/undo-redo/redo.js +3 -9
- package/build/components/header/undo-redo/redo.js.map +1 -1
- package/build/components/header/undo-redo/undo.js +3 -9
- package/build/components/header/undo-redo/undo.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/config.js +1 -2
- package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +1 -9
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +4 -20
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/shortcut.js +1 -6
- package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +1 -18
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/layout/index.js +2 -19
- package/build/components/layout/index.js.map +1 -1
- package/build/components/layout/interface.js +5 -21
- package/build/components/layout/interface.js.map +1 -1
- package/build/components/layout/unsaved-changes-warning.js +0 -6
- package/build/components/layout/unsaved-changes-warning.js.map +1 -1
- package/build/components/more-menu/index.js +2 -17
- package/build/components/more-menu/index.js.map +1 -1
- package/build/components/more-menu/tools-more-menu-group.js +1 -5
- package/build/components/more-menu/tools-more-menu-group.js.map +1 -1
- package/build/components/notices/index.js +1 -6
- package/build/components/notices/index.js.map +1 -1
- package/build/components/save-button/index.js +1 -7
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/secondary-sidebar/index.js +1 -10
- package/build/components/secondary-sidebar/index.js.map +1 -1
- package/build/components/secondary-sidebar/inserter-sidebar.js +1 -11
- package/build/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
- package/build/components/secondary-sidebar/list-view-sidebar.js +6 -15
- package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build/components/sidebar/index.js +12 -26
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/sidebar/widget-areas.js +1 -12
- package/build/components/sidebar/widget-areas.js.map +1 -1
- package/build/components/welcome-guide/index.js +3 -12
- package/build/components/welcome-guide/index.js.map +1 -1
- package/build/components/widget-areas-block-editor-content/index.js +1 -8
- package/build/components/widget-areas-block-editor-content/index.js.map +1 -1
- package/build/components/widget-areas-block-editor-provider/index.js +8 -23
- package/build/components/widget-areas-block-editor-provider/index.js.map +1 -1
- package/build/constants.js.map +1 -1
- package/build/filters/index.js +0 -1
- package/build/filters/index.js.map +1 -1
- package/build/filters/move-to-widget-area.js +3 -9
- package/build/filters/move-to-widget-area.js.map +1 -1
- package/build/filters/replace-media-upload.js +1 -3
- package/build/filters/replace-media-upload.js.map +1 -1
- package/build/hooks/use-last-selected-widget-area.js +5 -13
- package/build/hooks/use-last-selected-widget-area.js.map +1 -1
- package/build/hooks/use-widget-library-insertion-point.js +6 -14
- package/build/hooks/use-widget-library-insertion-point.js.map +1 -1
- package/build/index.js +6 -34
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +1 -2
- package/build/lock-unlock.js.map +1 -1
- package/build/store/actions.js +41 -79
- package/build/store/actions.js.map +1 -1
- package/build/store/constants.js +0 -1
- package/build/store/constants.js.map +1 -1
- package/build/store/index.js +4 -15
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +4 -16
- package/build/store/reducer.js.map +1 -1
- package/build/store/resolvers.js +1 -17
- package/build/store/resolvers.js.map +1 -1
- package/build/store/selectors.js +28 -49
- package/build/store/selectors.js.map +1 -1
- package/build/store/transformers.js +7 -16
- package/build/store/transformers.js.map +1 -1
- package/build/store/utils.js +7 -16
- package/build/store/utils.js.map +1 -1
- package/build-module/blocks/widget-area/edit/index.js +5 -8
- package/build-module/blocks/widget-area/edit/index.js.map +1 -1
- package/build-module/blocks/widget-area/edit/inner-blocks.js +6 -6
- package/build-module/blocks/widget-area/edit/inner-blocks.js.map +1 -1
- package/build-module/blocks/widget-area/edit/use-is-dragging-within.js +6 -9
- package/build-module/blocks/widget-area/edit/use-is-dragging-within.js.map +1 -1
- package/build-module/blocks/widget-area/index.js +1 -1
- package/build-module/blocks/widget-area/index.js.map +1 -1
- package/build-module/components/error-boundary/index.js +0 -9
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/header/index.js +9 -17
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/undo-redo/redo.js +2 -2
- package/build-module/components/header/undo-redo/redo.js.map +1 -1
- package/build-module/components/header/undo-redo/undo.js +2 -2
- package/build-module/components/header/undo-redo/undo.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +1 -6
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +5 -13
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js +0 -5
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js +1 -10
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/layout/index.js +2 -8
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/layout/interface.js +5 -9
- package/build-module/components/layout/interface.js.map +1 -1
- package/build-module/components/layout/unsaved-changes-warning.js +2 -3
- package/build-module/components/layout/unsaved-changes-warning.js.map +1 -1
- package/build-module/components/more-menu/index.js +2 -6
- package/build-module/components/more-menu/index.js.map +1 -1
- package/build-module/components/more-menu/tools-more-menu-group.js +0 -3
- package/build-module/components/more-menu/tools-more-menu-group.js.map +1 -1
- package/build-module/components/notices/index.js +0 -3
- package/build-module/components/notices/index.js.map +1 -1
- package/build-module/components/save-button/index.js +1 -4
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/secondary-sidebar/index.js +1 -6
- package/build-module/components/secondary-sidebar/index.js.map +1 -1
- package/build-module/components/secondary-sidebar/inserter-sidebar.js +1 -2
- package/build-module/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
- package/build-module/components/secondary-sidebar/list-view-sidebar.js +6 -7
- package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build-module/components/sidebar/index.js +13 -18
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/sidebar/widget-areas.js +1 -4
- package/build-module/components/sidebar/widget-areas.js.map +1 -1
- package/build-module/components/welcome-guide/index.js +3 -7
- package/build-module/components/welcome-guide/index.js.map +1 -1
- package/build-module/components/widget-areas-block-editor-content/index.js +1 -2
- package/build-module/components/widget-areas-block-editor-content/index.js.map +1 -1
- package/build-module/components/widget-areas-block-editor-provider/index.js +8 -7
- package/build-module/components/widget-areas-block-editor-provider/index.js.map +1 -1
- package/build-module/constants.js.map +1 -1
- package/build-module/filters/index.js.map +1 -1
- package/build-module/filters/move-to-widget-area.js +4 -4
- package/build-module/filters/move-to-widget-area.js.map +1 -1
- package/build-module/filters/replace-media-upload.js +0 -2
- package/build-module/filters/replace-media-upload.js.map +1 -1
- package/build-module/hooks/use-last-selected-widget-area.js +7 -9
- package/build-module/hooks/use-last-selected-widget-area.js.map +1 -1
- package/build-module/hooks/use-widget-library-insertion-point.js +6 -10
- package/build-module/hooks/use-widget-library-insertion-point.js.map +1 -1
- package/build-module/index.js +8 -20
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/store/actions.js +43 -56
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/constants.js.map +1 -1
- package/build-module/store/index.js +6 -6
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +5 -11
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/resolvers.js +3 -10
- package/build-module/store/resolvers.js.map +1 -1
- package/build-module/store/selectors.js +29 -38
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/transformers.js +8 -13
- package/build-module/store/transformers.js.map +1 -1
- package/build-module/store/utils.js +7 -7
- package/build-module/store/utils.js.map +1 -1
- package/build-style/style-rtl.css +14 -8
- package/build-style/style.css +14 -8
- package/package.json +28 -27
- package/src/components/widget-areas-block-editor-provider/index.js +3 -3
- package/src/index.js +0 -1
- package/src/store/selectors.js +10 -2
package/build/store/reducer.js
CHANGED
|
@@ -7,9 +7,7 @@ exports.blockInserterPanel = blockInserterPanel;
|
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
exports.listViewPanel = listViewPanel;
|
|
9
9
|
exports.widgetAreasOpenState = widgetAreasOpenState;
|
|
10
|
-
|
|
11
10
|
var _data = require("@wordpress/data");
|
|
12
|
-
|
|
13
11
|
/**
|
|
14
12
|
* WordPress dependencies
|
|
15
13
|
*/
|
|
@@ -26,30 +24,29 @@ function widgetAreasOpenState(state = {}, action) {
|
|
|
26
24
|
const {
|
|
27
25
|
type
|
|
28
26
|
} = action;
|
|
29
|
-
|
|
30
27
|
switch (type) {
|
|
31
28
|
case 'SET_WIDGET_AREAS_OPEN_STATE':
|
|
32
29
|
{
|
|
33
30
|
return action.widgetAreasOpenState;
|
|
34
31
|
}
|
|
35
|
-
|
|
36
32
|
case 'SET_IS_WIDGET_AREA_OPEN':
|
|
37
33
|
{
|
|
38
34
|
const {
|
|
39
35
|
clientId,
|
|
40
36
|
isOpen
|
|
41
37
|
} = action;
|
|
42
|
-
return {
|
|
38
|
+
return {
|
|
39
|
+
...state,
|
|
43
40
|
[clientId]: isOpen
|
|
44
41
|
};
|
|
45
42
|
}
|
|
46
|
-
|
|
47
43
|
default:
|
|
48
44
|
{
|
|
49
45
|
return state;
|
|
50
46
|
}
|
|
51
47
|
}
|
|
52
48
|
}
|
|
49
|
+
|
|
53
50
|
/**
|
|
54
51
|
* Reducer to set the block inserter panel open or closed.
|
|
55
52
|
*
|
|
@@ -59,19 +56,16 @@ function widgetAreasOpenState(state = {}, action) {
|
|
|
59
56
|
* @param {Object} state Current state.
|
|
60
57
|
* @param {Object} action Dispatched action.
|
|
61
58
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
59
|
function blockInserterPanel(state = false, action) {
|
|
65
60
|
switch (action.type) {
|
|
66
61
|
case 'SET_IS_LIST_VIEW_OPENED':
|
|
67
62
|
return action.isOpen ? false : state;
|
|
68
|
-
|
|
69
63
|
case 'SET_IS_INSERTER_OPENED':
|
|
70
64
|
return action.value;
|
|
71
65
|
}
|
|
72
|
-
|
|
73
66
|
return state;
|
|
74
67
|
}
|
|
68
|
+
|
|
75
69
|
/**
|
|
76
70
|
* Reducer to set the list view panel open or closed.
|
|
77
71
|
*
|
|
@@ -81,25 +75,19 @@ function blockInserterPanel(state = false, action) {
|
|
|
81
75
|
* @param {Object} state Current state.
|
|
82
76
|
* @param {Object} action Dispatched action.
|
|
83
77
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
78
|
function listViewPanel(state = false, action) {
|
|
87
79
|
switch (action.type) {
|
|
88
80
|
case 'SET_IS_INSERTER_OPENED':
|
|
89
81
|
return action.value ? false : state;
|
|
90
|
-
|
|
91
82
|
case 'SET_IS_LIST_VIEW_OPENED':
|
|
92
83
|
return action.isOpen;
|
|
93
84
|
}
|
|
94
|
-
|
|
95
85
|
return state;
|
|
96
86
|
}
|
|
97
|
-
|
|
98
87
|
var _default = (0, _data.combineReducers)({
|
|
99
88
|
blockInserterPanel,
|
|
100
89
|
listViewPanel,
|
|
101
90
|
widgetAreasOpenState
|
|
102
91
|
});
|
|
103
|
-
|
|
104
92
|
exports.default = _default;
|
|
105
93
|
//# sourceMappingURL=reducer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_data","require","widgetAreasOpenState","state","action","type","clientId","isOpen","blockInserterPanel","value","listViewPanel","_default","combineReducers","exports","default"],"sources":["@wordpress/edit-widgets/src/store/reducer.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Controls the open state of the widget areas.\n *\n * @param {Object} state Redux state.\n * @param {Object} action Redux action.\n *\n * @return {Array} Updated state.\n */\nexport function widgetAreasOpenState( state = {}, action ) {\n\tconst { type } = action;\n\tswitch ( type ) {\n\t\tcase 'SET_WIDGET_AREAS_OPEN_STATE': {\n\t\t\treturn action.widgetAreasOpenState;\n\t\t}\n\t\tcase 'SET_IS_WIDGET_AREA_OPEN': {\n\t\t\tconst { clientId, isOpen } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ clientId ]: isOpen,\n\t\t\t};\n\t\t}\n\t\tdefault: {\n\t\t\treturn state;\n\t\t}\n\t}\n}\n\n/**\n * Reducer to set the block inserter panel open or closed.\n *\n * Note: this reducer interacts with the list view panel reducer\n * to make sure that only one of the two panels is open at the same time.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n */\nexport function blockInserterPanel( state = false, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IS_LIST_VIEW_OPENED':\n\t\t\treturn action.isOpen ? false : state;\n\t\tcase 'SET_IS_INSERTER_OPENED':\n\t\t\treturn action.value;\n\t}\n\treturn state;\n}\n\n/**\n * Reducer to set the list view panel open or closed.\n *\n * Note: this reducer interacts with the inserter panel reducer\n * to make sure that only one of the two panels is open at the same time.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n */\nexport function listViewPanel( state = false, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IS_INSERTER_OPENED':\n\t\t\treturn action.value ? false : state;\n\t\tcase 'SET_IS_LIST_VIEW_OPENED':\n\t\t\treturn action.isOpen;\n\t}\n\treturn state;\n}\n\nexport default combineReducers( {\n\tblockInserterPanel,\n\tlistViewPanel,\n\twidgetAreasOpenState,\n} );\n"],"mappings":";;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,oBAAoBA,CAAEC,KAAK,GAAG,CAAC,CAAC,EAAEC,MAAM,EAAG;EAC1D,MAAM;IAAEC;EAAK,CAAC,GAAGD,MAAM;EACvB,QAASC,IAAI;IACZ,KAAK,6BAA6B;MAAE;QACnC,OAAOD,MAAM,CAACF,oBAAoB;MACnC;IACA,KAAK,yBAAyB;MAAE;QAC/B,MAAM;UAAEI,QAAQ;UAAEC;QAAO,CAAC,GAAGH,MAAM;QACnC,OAAO;UACN,GAAGD,KAAK;UACR,CAAEG,QAAQ,GAAIC;QACf,CAAC;MACF;IACA;MAAS;QACR,OAAOJ,KAAK;MACb;EACD;AACD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASK,kBAAkBA,CAAEL,KAAK,GAAG,KAAK,EAAEC,MAAM,EAAG;EAC3D,QAASA,MAAM,CAACC,IAAI;IACnB,KAAK,yBAAyB;MAC7B,OAAOD,MAAM,CAACG,MAAM,GAAG,KAAK,GAAGJ,KAAK;IACrC,KAAK,wBAAwB;MAC5B,OAAOC,MAAM,CAACK,KAAK;EACrB;EACA,OAAON,KAAK;AACb;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASO,aAAaA,CAAEP,KAAK,GAAG,KAAK,EAAEC,MAAM,EAAG;EACtD,QAASA,MAAM,CAACC,IAAI;IACnB,KAAK,wBAAwB;MAC5B,OAAOD,MAAM,CAACK,KAAK,GAAG,KAAK,GAAGN,KAAK;IACpC,KAAK,yBAAyB;MAC7B,OAAOC,MAAM,CAACG,MAAM;EACtB;EACA,OAAOJ,KAAK;AACb;AAAC,IAAAQ,QAAA,GAEc,IAAAC,qBAAe,EAAE;EAC/BJ,kBAAkB;EAClBE,aAAa;EACbR;AACD,CAAE,CAAC;AAAAW,OAAA,CAAAC,OAAA,GAAAH,QAAA"}
|
package/build/store/resolvers.js
CHANGED
|
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getWidgets = exports.getWidgetAreas = void 0;
|
|
7
|
-
|
|
8
7
|
var _blocks = require("@wordpress/blocks");
|
|
9
|
-
|
|
10
8
|
var _coreData = require("@wordpress/core-data");
|
|
11
|
-
|
|
12
9
|
var _actions = require("./actions");
|
|
13
|
-
|
|
14
10
|
var _utils = require("./utils");
|
|
15
|
-
|
|
16
11
|
var _transformers = require("./transformers");
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
13
|
* WordPress dependencies
|
|
20
14
|
*/
|
|
@@ -43,27 +37,22 @@ const getWidgetAreas = () => async ({
|
|
|
43
37
|
if (a.id === 'wp_inactive_widgets') {
|
|
44
38
|
return 1;
|
|
45
39
|
}
|
|
46
|
-
|
|
47
40
|
if (b.id === 'wp_inactive_widgets') {
|
|
48
41
|
return -1;
|
|
49
42
|
}
|
|
50
|
-
|
|
51
43
|
return 0;
|
|
52
44
|
});
|
|
53
|
-
|
|
54
45
|
for (const widgetArea of sortedWidgetAreas) {
|
|
55
46
|
widgetAreaBlocks.push((0, _blocks.createBlock)('core/widget-area', {
|
|
56
47
|
id: widgetArea.id,
|
|
57
48
|
name: widgetArea.name
|
|
58
49
|
}));
|
|
59
|
-
|
|
60
50
|
if (!widgetArea.widgets.length) {
|
|
61
51
|
// If this widget area has no widgets, it won't get a post setup by
|
|
62
52
|
// the getWidgets resolver.
|
|
63
53
|
dispatch((0, _actions.persistStubPost)((0, _utils.buildWidgetAreaPostId)(widgetArea.id), []));
|
|
64
54
|
}
|
|
65
55
|
}
|
|
66
|
-
|
|
67
56
|
const widgetAreasOpenState = {};
|
|
68
57
|
widgetAreaBlocks.forEach((widgetAreaBlock, index) => {
|
|
69
58
|
// Defaults to open the first widget area.
|
|
@@ -72,15 +61,13 @@ const getWidgetAreas = () => async ({
|
|
|
72
61
|
dispatch((0, _actions.setWidgetAreasOpenState)(widgetAreasOpenState));
|
|
73
62
|
dispatch((0, _actions.persistStubPost)((0, _utils.buildWidgetAreasPostId)(), widgetAreaBlocks));
|
|
74
63
|
};
|
|
64
|
+
|
|
75
65
|
/**
|
|
76
66
|
* Fetches all widgets from all widgets ares, and groups them by widget area Id.
|
|
77
67
|
*
|
|
78
68
|
* @return {Function} An action creator.
|
|
79
69
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
70
|
exports.getWidgetAreas = getWidgetAreas;
|
|
83
|
-
|
|
84
71
|
const getWidgets = () => async ({
|
|
85
72
|
dispatch,
|
|
86
73
|
registry
|
|
@@ -88,13 +75,11 @@ const getWidgets = () => async ({
|
|
|
88
75
|
const query = (0, _utils.buildWidgetsQuery)();
|
|
89
76
|
const widgets = await registry.resolveSelect(_coreData.store).getEntityRecords('root', 'widget', query);
|
|
90
77
|
const groupedBySidebar = {};
|
|
91
|
-
|
|
92
78
|
for (const widget of widgets) {
|
|
93
79
|
const block = (0, _transformers.transformWidgetToBlock)(widget);
|
|
94
80
|
groupedBySidebar[widget.sidebar] = groupedBySidebar[widget.sidebar] || [];
|
|
95
81
|
groupedBySidebar[widget.sidebar].push(block);
|
|
96
82
|
}
|
|
97
|
-
|
|
98
83
|
for (const sidebarId in groupedBySidebar) {
|
|
99
84
|
if (groupedBySidebar.hasOwnProperty(sidebarId)) {
|
|
100
85
|
// Persist the actual post containing the widget block
|
|
@@ -102,6 +87,5 @@ const getWidgets = () => async ({
|
|
|
102
87
|
}
|
|
103
88
|
}
|
|
104
89
|
};
|
|
105
|
-
|
|
106
90
|
exports.getWidgets = getWidgets;
|
|
107
91
|
//# sourceMappingURL=resolvers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_blocks","require","_coreData","_actions","_utils","_transformers","getWidgetAreas","dispatch","registry","query","buildWidgetAreasQuery","widgetAreas","resolveSelect","coreStore","getEntityRecords","KIND","WIDGET_AREA_ENTITY_TYPE","widgetAreaBlocks","sortedWidgetAreas","sort","a","b","id","widgetArea","push","createBlock","name","widgets","length","persistStubPost","buildWidgetAreaPostId","widgetAreasOpenState","forEach","widgetAreaBlock","index","clientId","setWidgetAreasOpenState","buildWidgetAreasPostId","exports","getWidgets","buildWidgetsQuery","groupedBySidebar","widget","block","transformWidgetToBlock","sidebar","sidebarId","hasOwnProperty"],"sources":["@wordpress/edit-widgets/src/store/resolvers.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { persistStubPost, setWidgetAreasOpenState } from './actions';\nimport {\n\tKIND,\n\tWIDGET_AREA_ENTITY_TYPE,\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tbuildWidgetAreasPostId,\n} from './utils';\nimport { transformWidgetToBlock } from './transformers';\n\n/**\n * Creates a \"stub\" widgets post reflecting all available widget areas. The\n * post is meant as a convenient to only exists in runtime and should never be saved. It\n * enables a convenient way of editing the widgets by using a regular post editor.\n *\n * Fetches all widgets from all widgets aras, converts them into blocks, and hydrates a new post with them.\n *\n * @return {Function} An action creator.\n */\nexport const getWidgetAreas =\n\t() =>\n\tasync ( { dispatch, registry } ) => {\n\t\tconst query = buildWidgetAreasQuery();\n\t\tconst widgetAreas = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEntityRecords( KIND, WIDGET_AREA_ENTITY_TYPE, query );\n\n\t\tconst widgetAreaBlocks = [];\n\t\tconst sortedWidgetAreas = widgetAreas.sort( ( a, b ) => {\n\t\t\tif ( a.id === 'wp_inactive_widgets' ) {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tif ( b.id === 'wp_inactive_widgets' ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 0;\n\t\t} );\n\t\tfor ( const widgetArea of sortedWidgetAreas ) {\n\t\t\twidgetAreaBlocks.push(\n\t\t\t\tcreateBlock( 'core/widget-area', {\n\t\t\t\t\tid: widgetArea.id,\n\t\t\t\t\tname: widgetArea.name,\n\t\t\t\t} )\n\t\t\t);\n\n\t\t\tif ( ! widgetArea.widgets.length ) {\n\t\t\t\t// If this widget area has no widgets, it won't get a post setup by\n\t\t\t\t// the getWidgets resolver.\n\t\t\t\tdispatch(\n\t\t\t\t\tpersistStubPost(\n\t\t\t\t\t\tbuildWidgetAreaPostId( widgetArea.id ),\n\t\t\t\t\t\t[]\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst widgetAreasOpenState = {};\n\t\twidgetAreaBlocks.forEach( ( widgetAreaBlock, index ) => {\n\t\t\t// Defaults to open the first widget area.\n\t\t\twidgetAreasOpenState[ widgetAreaBlock.clientId ] = index === 0;\n\t\t} );\n\t\tdispatch( setWidgetAreasOpenState( widgetAreasOpenState ) );\n\n\t\tdispatch(\n\t\t\tpersistStubPost( buildWidgetAreasPostId(), widgetAreaBlocks )\n\t\t);\n\t};\n\n/**\n * Fetches all widgets from all widgets ares, and groups them by widget area Id.\n *\n * @return {Function} An action creator.\n */\nexport const getWidgets =\n\t() =>\n\tasync ( { dispatch, registry } ) => {\n\t\tconst query = buildWidgetsQuery();\n\t\tconst widgets = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEntityRecords( 'root', 'widget', query );\n\n\t\tconst groupedBySidebar = {};\n\n\t\tfor ( const widget of widgets ) {\n\t\t\tconst block = transformWidgetToBlock( widget );\n\t\t\tgroupedBySidebar[ widget.sidebar ] =\n\t\t\t\tgroupedBySidebar[ widget.sidebar ] || [];\n\t\t\tgroupedBySidebar[ widget.sidebar ].push( block );\n\t\t}\n\n\t\tfor ( const sidebarId in groupedBySidebar ) {\n\t\t\tif ( groupedBySidebar.hasOwnProperty( sidebarId ) ) {\n\t\t\t\t// Persist the actual post containing the widget block\n\t\t\t\tdispatch(\n\t\t\t\t\tpersistStubPost(\n\t\t\t\t\t\tbuildWidgetAreaPostId( sidebarId ),\n\t\t\t\t\t\tgroupedBySidebar[ sidebarId ]\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t};\n"],"mappings":";;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAKA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAQA,IAAAI,aAAA,GAAAJ,OAAA;AAlBA;AACA;AACA;;AAIA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMK,cAAc,GAC1BA,CAAA,KACA,OAAQ;EAAEC,QAAQ;EAAEC;AAAS,CAAC,KAAM;EACnC,MAAMC,KAAK,GAAG,IAAAC,4BAAqB,EAAC,CAAC;EACrC,MAAMC,WAAW,GAAG,MAAMH,QAAQ,CAChCI,aAAa,CAAEC,eAAU,CAAC,CAC1BC,gBAAgB,CAAEC,WAAI,EAAEC,8BAAuB,EAAEP,KAAM,CAAC;EAE1D,MAAMQ,gBAAgB,GAAG,EAAE;EAC3B,MAAMC,iBAAiB,GAAGP,WAAW,CAACQ,IAAI,CAAE,CAAEC,CAAC,EAAEC,CAAC,KAAM;IACvD,IAAKD,CAAC,CAACE,EAAE,KAAK,qBAAqB,EAAG;MACrC,OAAO,CAAC;IACT;IACA,IAAKD,CAAC,C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AAgB,GAAG,CAAC,CAAC;EAE3B,KAAM,MAAMC,MAAM,IAAIf,OAAO,EAAG;IAC/B,MAAMgB,KAAK,GAAG,IAAAC,oCAAsB,EAAEF,MAAO,CAAC;IAC9CD,gBAAgB,CAAEC,MAAM,CAACG,OAAO,CAAE,GACjCJ,gBAAgB,CAAEC,MAAM,CAACG,OAAO,CAAE,IAAI,EAAE;IACzCJ,gBAAgB,CAAEC,MAAM,CAACG,OAAO,CAAE,CAACrB,IAAI,CAAEmB,KAAM,CAAC;EACjD;EAEA,KAAM,MAAMG,SAAS,IAAIL,gBAAgB,EAAG;IAC3C,IAAKA,gBAAgB,CAACM,cAAc,CAAED,SAAU,CAAC,EAAG;MACnD;MACAvC,QAAQ,CACP,IAAAsB,wBAAe,EACd,IAAAC,4BAAqB,EAAEgB,SAAU,CAAC,EAClCL,gBAAgB,CAAEK,SAAS,CAC5B,CACD,CAAC;IACF;EACD;AACD,CAAC;AAACR,OAAA,CAAAC,UAAA,GAAAA,UAAA"}
|
package/build/store/selectors.js
CHANGED
|
@@ -8,19 +8,12 @@ exports.getWidgets = exports.getWidgetAreas = exports.getWidgetAreaForWidgetId =
|
|
|
8
8
|
exports.isInserterOpened = isInserterOpened;
|
|
9
9
|
exports.isListViewOpened = isListViewOpened;
|
|
10
10
|
exports.isSavingWidgetAreas = void 0;
|
|
11
|
-
|
|
12
11
|
var _data = require("@wordpress/data");
|
|
13
|
-
|
|
14
12
|
var _widgets = require("@wordpress/widgets");
|
|
15
|
-
|
|
16
13
|
var _coreData = require("@wordpress/core-data");
|
|
17
|
-
|
|
18
14
|
var _blockEditor = require("@wordpress/block-editor");
|
|
19
|
-
|
|
20
15
|
var _utils = require("./utils");
|
|
21
|
-
|
|
22
16
|
var _constants = require("./constants");
|
|
23
|
-
|
|
24
17
|
/**
|
|
25
18
|
* WordPress dependencies
|
|
26
19
|
*/
|
|
@@ -29,6 +22,11 @@ var _constants = require("./constants");
|
|
|
29
22
|
* Internal dependencies
|
|
30
23
|
*/
|
|
31
24
|
|
|
25
|
+
const EMPTY_INSERTION_POINT = {
|
|
26
|
+
rootClientId: undefined,
|
|
27
|
+
insertionIndex: undefined
|
|
28
|
+
};
|
|
29
|
+
|
|
32
30
|
/**
|
|
33
31
|
* Returns all API widgets.
|
|
34
32
|
*
|
|
@@ -36,12 +34,15 @@ var _constants = require("./constants");
|
|
|
36
34
|
*/
|
|
37
35
|
const getWidgets = (0, _data.createRegistrySelector)(select => () => {
|
|
38
36
|
const widgets = select(_coreData.store).getEntityRecords('root', 'widget', (0, _utils.buildWidgetsQuery)());
|
|
39
|
-
return (
|
|
40
|
-
widgets
|
|
37
|
+
return (
|
|
38
|
+
// Key widgets by their ID.
|
|
39
|
+
widgets?.reduce((allWidgets, widget) => ({
|
|
40
|
+
...allWidgets,
|
|
41
41
|
[widget.id]: widget
|
|
42
42
|
}), {}) || {}
|
|
43
43
|
);
|
|
44
44
|
});
|
|
45
|
+
|
|
45
46
|
/**
|
|
46
47
|
* Returns API widget data for a particular widget ID.
|
|
47
48
|
*
|
|
@@ -49,30 +50,29 @@ const getWidgets = (0, _data.createRegistrySelector)(select => () => {
|
|
|
49
50
|
*
|
|
50
51
|
* @return {Object} API widget data for a particular widget ID.
|
|
51
52
|
*/
|
|
52
|
-
|
|
53
53
|
exports.getWidgets = getWidgets;
|
|
54
54
|
const getWidget = (0, _data.createRegistrySelector)(select => (state, id) => {
|
|
55
55
|
const widgets = select(_constants.STORE_NAME).getWidgets();
|
|
56
56
|
return widgets[id];
|
|
57
57
|
});
|
|
58
|
+
|
|
58
59
|
/**
|
|
59
60
|
* Returns all API widget areas.
|
|
60
61
|
*
|
|
61
62
|
* @return {Object[]} API List of widget areas.
|
|
62
63
|
*/
|
|
63
|
-
|
|
64
64
|
exports.getWidget = getWidget;
|
|
65
65
|
const getWidgetAreas = (0, _data.createRegistrySelector)(select => () => {
|
|
66
66
|
const query = (0, _utils.buildWidgetAreasQuery)();
|
|
67
67
|
return select(_coreData.store).getEntityRecords(_utils.KIND, _utils.WIDGET_AREA_ENTITY_TYPE, query);
|
|
68
68
|
});
|
|
69
|
+
|
|
69
70
|
/**
|
|
70
71
|
* Returns widgetArea containing a block identify by given widgetId
|
|
71
72
|
*
|
|
72
73
|
* @param {string} widgetId The ID of the widget.
|
|
73
74
|
* @return {Object} Containing widget area.
|
|
74
75
|
*/
|
|
75
|
-
|
|
76
76
|
exports.getWidgetAreas = getWidgetAreas;
|
|
77
77
|
const getWidgetAreaForWidgetId = (0, _data.createRegistrySelector)(select => (state, widgetId) => {
|
|
78
78
|
const widgetAreas = select(_constants.STORE_NAME).getWidgetAreas();
|
|
@@ -82,6 +82,7 @@ const getWidgetAreaForWidgetId = (0, _data.createRegistrySelector)(select => (st
|
|
|
82
82
|
return blockWidgetIds.includes(widgetId);
|
|
83
83
|
});
|
|
84
84
|
});
|
|
85
|
+
|
|
85
86
|
/**
|
|
86
87
|
* Given a child client id, returns the parent widget area block.
|
|
87
88
|
*
|
|
@@ -89,7 +90,6 @@ const getWidgetAreaForWidgetId = (0, _data.createRegistrySelector)(select => (st
|
|
|
89
90
|
*
|
|
90
91
|
* @return {WPBlock} The widget area block.
|
|
91
92
|
*/
|
|
92
|
-
|
|
93
93
|
exports.getWidgetAreaForWidgetId = getWidgetAreaForWidgetId;
|
|
94
94
|
const getParentWidgetAreaBlock = (0, _data.createRegistrySelector)(select => (state, clientId) => {
|
|
95
95
|
const {
|
|
@@ -101,93 +101,82 @@ const getParentWidgetAreaBlock = (0, _data.createRegistrySelector)(select => (st
|
|
|
101
101
|
const widgetAreaClientId = blockParents.find(parentClientId => getBlockName(parentClientId) === 'core/widget-area');
|
|
102
102
|
return getBlock(widgetAreaClientId);
|
|
103
103
|
});
|
|
104
|
+
|
|
104
105
|
/**
|
|
105
106
|
* Returns all edited widget area entity records.
|
|
106
107
|
*
|
|
107
108
|
* @return {Object[]} List of edited widget area entity records.
|
|
108
109
|
*/
|
|
109
|
-
|
|
110
110
|
exports.getParentWidgetAreaBlock = getParentWidgetAreaBlock;
|
|
111
111
|
const getEditedWidgetAreas = (0, _data.createRegistrySelector)(select => (state, ids) => {
|
|
112
112
|
let widgetAreas = select(_constants.STORE_NAME).getWidgetAreas();
|
|
113
|
-
|
|
114
113
|
if (!widgetAreas) {
|
|
115
114
|
return [];
|
|
116
115
|
}
|
|
117
|
-
|
|
118
116
|
if (ids) {
|
|
119
117
|
widgetAreas = widgetAreas.filter(({
|
|
120
118
|
id
|
|
121
119
|
}) => ids.includes(id));
|
|
122
120
|
}
|
|
123
|
-
|
|
124
121
|
return widgetAreas.filter(({
|
|
125
122
|
id
|
|
126
123
|
}) => select(_coreData.store).hasEditsForEntityRecord(_utils.KIND, _utils.POST_TYPE, (0, _utils.buildWidgetAreaPostId)(id))).map(({
|
|
127
124
|
id
|
|
128
125
|
}) => select(_coreData.store).getEditedEntityRecord(_utils.KIND, _utils.WIDGET_AREA_ENTITY_TYPE, id));
|
|
129
126
|
});
|
|
127
|
+
|
|
130
128
|
/**
|
|
131
129
|
* Returns all blocks representing reference widgets.
|
|
132
130
|
*
|
|
133
131
|
* @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.
|
|
134
132
|
* @return {Array} List of all blocks representing reference widgets
|
|
135
133
|
*/
|
|
136
|
-
|
|
137
134
|
exports.getEditedWidgetAreas = getEditedWidgetAreas;
|
|
138
135
|
const getReferenceWidgetBlocks = (0, _data.createRegistrySelector)(select => (state, referenceWidgetName = null) => {
|
|
139
136
|
const results = [];
|
|
140
137
|
const widgetAreas = select(_constants.STORE_NAME).getWidgetAreas();
|
|
141
|
-
|
|
142
138
|
for (const _widgetArea of widgetAreas) {
|
|
143
139
|
const post = select(_coreData.store).getEditedEntityRecord(_utils.KIND, _utils.POST_TYPE, (0, _utils.buildWidgetAreaPostId)(_widgetArea.id));
|
|
144
|
-
|
|
145
140
|
for (const block of post.blocks) {
|
|
146
141
|
if (block.name === 'core/legacy-widget' && (!referenceWidgetName || block.attributes?.referenceWidgetName === referenceWidgetName)) {
|
|
147
142
|
results.push(block);
|
|
148
143
|
}
|
|
149
144
|
}
|
|
150
145
|
}
|
|
151
|
-
|
|
152
146
|
return results;
|
|
153
147
|
});
|
|
148
|
+
|
|
154
149
|
/**
|
|
155
150
|
* Returns true if any widget area is currently being saved.
|
|
156
151
|
*
|
|
157
152
|
* @return {boolean} True if any widget area is currently being saved. False otherwise.
|
|
158
153
|
*/
|
|
159
|
-
|
|
160
154
|
exports.getReferenceWidgetBlocks = getReferenceWidgetBlocks;
|
|
161
155
|
const isSavingWidgetAreas = (0, _data.createRegistrySelector)(select => () => {
|
|
162
156
|
const widgetAreasIds = select(_constants.STORE_NAME).getWidgetAreas()?.map(({
|
|
163
157
|
id
|
|
164
158
|
}) => id);
|
|
165
|
-
|
|
166
159
|
if (!widgetAreasIds) {
|
|
167
160
|
return false;
|
|
168
161
|
}
|
|
169
|
-
|
|
170
162
|
for (const id of widgetAreasIds) {
|
|
171
163
|
const isSaving = select(_coreData.store).isSavingEntityRecord(_utils.KIND, _utils.WIDGET_AREA_ENTITY_TYPE, id);
|
|
172
|
-
|
|
173
164
|
if (isSaving) {
|
|
174
165
|
return true;
|
|
175
166
|
}
|
|
176
167
|
}
|
|
177
|
-
|
|
178
168
|
const widgetIds = [...Object.keys(select(_constants.STORE_NAME).getWidgets()), undefined // account for new widgets without an ID
|
|
179
169
|
];
|
|
180
170
|
|
|
181
171
|
for (const id of widgetIds) {
|
|
182
172
|
const isSaving = select(_coreData.store).isSavingEntityRecord('root', 'widget', id);
|
|
183
|
-
|
|
184
173
|
if (isSaving) {
|
|
185
174
|
return true;
|
|
186
175
|
}
|
|
187
176
|
}
|
|
188
|
-
|
|
189
177
|
return false;
|
|
190
178
|
});
|
|
179
|
+
|
|
191
180
|
/**
|
|
192
181
|
* Gets whether the widget area is opened.
|
|
193
182
|
*
|
|
@@ -196,15 +185,14 @@ const isSavingWidgetAreas = (0, _data.createRegistrySelector)(select => () => {
|
|
|
196
185
|
*
|
|
197
186
|
* @return {boolean} True if the widget area is open.
|
|
198
187
|
*/
|
|
199
|
-
|
|
200
188
|
exports.isSavingWidgetAreas = isSavingWidgetAreas;
|
|
201
|
-
|
|
202
189
|
const getIsWidgetAreaOpen = (state, clientId) => {
|
|
203
190
|
const {
|
|
204
191
|
widgetAreasOpenState
|
|
205
192
|
} = state;
|
|
206
193
|
return !!widgetAreasOpenState[clientId];
|
|
207
194
|
};
|
|
195
|
+
|
|
208
196
|
/**
|
|
209
197
|
* Returns true if the inserter is opened.
|
|
210
198
|
*
|
|
@@ -212,13 +200,11 @@ const getIsWidgetAreaOpen = (state, clientId) => {
|
|
|
212
200
|
*
|
|
213
201
|
* @return {boolean} Whether the inserter is opened.
|
|
214
202
|
*/
|
|
215
|
-
|
|
216
|
-
|
|
217
203
|
exports.getIsWidgetAreaOpen = getIsWidgetAreaOpen;
|
|
218
|
-
|
|
219
204
|
function isInserterOpened(state) {
|
|
220
205
|
return !!state.blockInserterPanel;
|
|
221
206
|
}
|
|
207
|
+
|
|
222
208
|
/**
|
|
223
209
|
* Get the insertion point for the inserter.
|
|
224
210
|
*
|
|
@@ -226,18 +212,13 @@ function isInserterOpened(state) {
|
|
|
226
212
|
*
|
|
227
213
|
* @return {Object} The root client ID and index to insert at.
|
|
228
214
|
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
215
|
function __experimentalGetInsertionPoint(state) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return {
|
|
237
|
-
rootClientId,
|
|
238
|
-
insertionIndex
|
|
239
|
-
};
|
|
216
|
+
if (typeof state === 'boolean') {
|
|
217
|
+
return EMPTY_INSERTION_POINT;
|
|
218
|
+
}
|
|
219
|
+
return state.blockInserterPanel;
|
|
240
220
|
}
|
|
221
|
+
|
|
241
222
|
/**
|
|
242
223
|
* Returns true if a block can be inserted into a widget area.
|
|
243
224
|
*
|
|
@@ -246,17 +227,17 @@ function __experimentalGetInsertionPoint(state) {
|
|
|
246
227
|
*
|
|
247
228
|
* @return {boolean} True if the block can be inserted in a widget area.
|
|
248
229
|
*/
|
|
249
|
-
|
|
250
|
-
|
|
251
230
|
const canInsertBlockInWidgetArea = (0, _data.createRegistrySelector)(select => (state, blockName) => {
|
|
252
231
|
// Widget areas are always top-level blocks, which getBlocks will return.
|
|
253
|
-
const widgetAreas = select(_blockEditor.store).getBlocks();
|
|
232
|
+
const widgetAreas = select(_blockEditor.store).getBlocks();
|
|
233
|
+
|
|
234
|
+
// Makes an assumption that a block that can be inserted into one
|
|
254
235
|
// widget area can be inserted into any widget area. Uses the first
|
|
255
236
|
// widget area for testing whether the block can be inserted.
|
|
256
|
-
|
|
257
237
|
const [firstWidgetArea] = widgetAreas;
|
|
258
238
|
return select(_blockEditor.store).canInsertBlockType(blockName, firstWidgetArea.clientId);
|
|
259
239
|
});
|
|
240
|
+
|
|
260
241
|
/**
|
|
261
242
|
* Returns true if the list view is opened.
|
|
262
243
|
*
|
|
@@ -264,9 +245,7 @@ const canInsertBlockInWidgetArea = (0, _data.createRegistrySelector)(select => (
|
|
|
264
245
|
*
|
|
265
246
|
* @return {boolean} Whether the list view is opened.
|
|
266
247
|
*/
|
|
267
|
-
|
|
268
248
|
exports.canInsertBlockInWidgetArea = canInsertBlockInWidgetArea;
|
|
269
|
-
|
|
270
249
|
function isListViewOpened(state) {
|
|
271
250
|
return state.listViewPanel;
|
|
272
251
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/store/selectors.js"],"names":["getWidgets","select","widgets","coreStore","getEntityRecords","reduce","allWidgets","widget","id","getWidget","state","editWidgetsStoreName","getWidgetAreas","query","KIND","WIDGET_AREA_ENTITY_TYPE","getWidgetAreaForWidgetId","widgetId","widgetAreas","find","widgetArea","post","getEditedEntityRecord","POST_TYPE","blockWidgetIds","blocks","map","block","includes","getParentWidgetAreaBlock","clientId","getBlock","getBlockName","getBlockParents","blockEditorStore","blockParents","widgetAreaClientId","parentClientId","getEditedWidgetAreas","ids","filter","hasEditsForEntityRecord","getReferenceWidgetBlocks","referenceWidgetName","results","_widgetArea","name","attributes","push","isSavingWidgetAreas","widgetAreasIds","isSaving","isSavingEntityRecord","widgetIds","Object","keys","undefined","getIsWidgetAreaOpen","widgetAreasOpenState","isInserterOpened","blockInserterPanel","__experimentalGetInsertionPoint","rootClientId","insertionIndex","canInsertBlockInWidgetArea","blockName","getBlocks","firstWidgetArea","canInsertBlockType","isListViewOpened","listViewPanel"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AAQA;;AAnBA;AACA;AACA;;AAMA;AACA;AACA;;AAWA;AACA;AACA;AACA;AACA;AACO,MAAMA,UAAU,GAAG,kCAA0BC,MAAF,IAAc,MAAM;AACrE,QAAMC,OAAO,GAAGD,MAAM,CAAEE,eAAF,CAAN,CAAoBC,gBAApB,CACf,MADe,EAEf,QAFe,EAGf,+BAHe,CAAhB;AAMA,SACC;AACAF,IAAAA,OAAO,EAAEG,MAAT,CACC,CAAEC,UAAF,EAAcC,MAAd,MAA4B,EAC3B,GAAGD,UADwB;AAE3B,OAAEC,MAAM,CAACC,EAAT,GAAeD;AAFY,KAA5B,CADD,EAKC,EALD,KAMK;AARN;AAUA,CAjByB,CAAnB;AAmBP;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAME,SAAS,GAAG,kCACtBR,MAAF,IAAc,CAAES,KAAF,EAASF,EAAT,KAAiB;AAC9B,QAAMN,OAAO,GAAGD,MAAM,CAAEU,qBAAF,CAAN,CAA+BX,UAA/B,EAAhB;AACA,SAAOE,OAAO,CAAEM,EAAF,CAAd;AACA,CAJuB,CAAlB;AAOP;AACA;AACA;AACA;AACA;;;AACO,MAAMI,cAAc,GAAG,kCAA0BX,MAAF,IAAc,MAAM;AACzE,QAAMY,KAAK,GAAG,mCAAd;AACA,SAAOZ,MAAM,CAAEE,eAAF,CAAN,CAAoBC,gBAApB,CACNU,WADM,EAENC,8BAFM,EAGNF,KAHM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,CAAE5B,QAAF,CAA9B;AACA,CAHM;AAKP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAAS6B,gBAAT,CAA2BjD,KAA3B,EAAmC;AACzC,SAAO,CAAC,CAAEA,KAAK,CAACkD,kBAAhB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,+BAAT,CAA0CnD,KAA1C,EAAkD;AACxD,QAAM;AAAEoD,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAAmCrD,KAAK,CAACkD,kBAA/C;AACA,SAAO;AAAEE,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,GAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,0BAA0B,GAAG,kCACvC/D,MAAF,IAAc,CAAES,KAAF,EAASuD,SAAT,KAAwB;AACrC;AACA,QAAM/C,WAAW,GAAGjB,MAAM,CAAEiC,kBAAF,CAAN,CAA2BgC,SAA3B,EAApB,CAFqC,CAIrC;AACA;AACA;;AACA,QAAM,CAAEC,eAAF,IAAsBjD,WAA5B;AACA,SAAOjB,MAAM,CAAEiC,kBAAF,CAAN,CAA2BkC,kBAA3B,CACNH,SADM,EAENE,eAAe,CAACrC,QAFV,CAAP;AAIA,CAbwC,CAAnC;AAgBP;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACO,SAASuC,gBAAT,CAA2B3D,KAA3B,EAAmC;AACzC,SAAOA,KAAK,CAAC4D,aAAb;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { 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';\n\n/**\n * Internal dependencies\n */\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\n/**\n * Returns all API widgets.\n *\n * @return {Object[]} API List of widgets.\n */\nexport const getWidgets = createRegistrySelector( ( select ) => () => {\n\tconst widgets = select( coreStore ).getEntityRecords(\n\t\t'root',\n\t\t'widget',\n\t\tbuildWidgetsQuery()\n\t);\n\n\treturn (\n\t\t// Key widgets by their ID.\n\t\twidgets?.reduce(\n\t\t\t( allWidgets, widget ) => ( {\n\t\t\t\t...allWidgets,\n\t\t\t\t[ widget.id ]: widget,\n\t\t\t} ),\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\tconst { rootClientId, insertionIndex } = state.blockInserterPanel;\n\treturn { rootClientId, insertionIndex };\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\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"]}
|
|
1
|
+
{"version":3,"names":["_data","require","_widgets","_coreData","_blockEditor","_utils","_constants","EMPTY_INSERTION_POINT","rootClientId","undefined","insertionIndex","getWidgets","createRegistrySelector","select","widgets","coreStore","getEntityRecords","buildWidgetsQuery","reduce","allWidgets","widget","id","exports","getWidget","state","editWidgetsStoreName","getWidgetAreas","query","buildWidgetAreasQuery","KIND","WIDGET_AREA_ENTITY_TYPE","getWidgetAreaForWidgetId","widgetId","widgetAreas","find","widgetArea","post","getEditedEntityRecord","POST_TYPE","buildWidgetAreaPostId","blockWidgetIds","blocks","map","block","getWidgetIdFromBlock","includes","getParentWidgetAreaBlock","clientId","getBlock","getBlockName","getBlockParents","blockEditorStore","blockParents","widgetAreaClientId","parentClientId","getEditedWidgetAreas","ids","filter","hasEditsForEntityRecord","getReferenceWidgetBlocks","referenceWidgetName","results","_widgetArea","name","attributes","push","isSavingWidgetAreas","widgetAreasIds","isSaving","isSavingEntityRecord","widgetIds","Object","keys","getIsWidgetAreaOpen","widgetAreasOpenState","isInserterOpened","blockInserterPanel","__experimentalGetInsertionPoint","canInsertBlockInWidgetArea","blockName","getBlocks","firstWidgetArea","canInsertBlockType","isListViewOpened","listViewPanel"],"sources":["@wordpress/edit-widgets/src/store/selectors.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { 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';\n\n/**\n * Internal dependencies\n */\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\tconst widgets = select( coreStore ).getEntityRecords(\n\t\t'root',\n\t\t'widget',\n\t\tbuildWidgetsQuery()\n\t);\n\n\treturn (\n\t\t// Key widgets by their ID.\n\t\twidgets?.reduce(\n\t\t\t( allWidgets, widget ) => ( {\n\t\t\t\t...allWidgets,\n\t\t\t\t[ widget.id ]: widget,\n\t\t\t} ),\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 === '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\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"],"mappings":";;;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAKA,IAAAI,MAAA,GAAAJ,OAAA;AAQA,IAAAK,UAAA,GAAAL,OAAA;AAnBA;AACA;AACA;;AAMA;AACA;AACA;;AAWA,MAAMM,qBAAqB,GAAG;EAC7BC,YAAY,EAAEC,SAAS;EACvBC,c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AM;IAAE2B;EAAqB,CAAC,GAAGlD,KAAK;EACtC,OAAO,CAAC,CAAEkD,oBAAoB,CAAE3B,QAAQ,CAAE;AAC3C,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AANAzB,OAAA,CAAAmD,mBAAA,GAAAA,mBAAA;AAOO,SAASE,gBAAgBA,CAAEnD,KAAK,EAAG;EACzC,OAAO,CAAC,CAAEA,KAAK,CAACoD,kBAAkB;AACnC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,+BAA+BA,CAAErD,KAAK,EAAG;EACxD,IAAK,OAAOA,KAAK,KAAK,SAAS,EAAG;IACjC,OAAOjB,qBAAqB;EAC7B;EAEA,OAAOiB,KAAK,CAACoD,kBAAkB;AAChC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,0BAA0B,GAAG,IAAAlE,4BAAsB,EAC7DC,MAAM,IAAM,CAAEW,KAAK,EAAEuD,SAAS,KAAM;EACrC;EACA,MAAM9C,WAAW,GAAGpB,MAAM,CAAEsC,kBAAiB,CAAC,CAAC6B,SAAS,CAAC,CAAC;;EAE1D;EACA;EACA;EACA,MAAM,CAAEC,eAAe,CAAE,GAAGhD,WAAW;EACvC,OAAOpB,MAAM,CAAEsC,kBAAiB,CAAC,CAAC+B,kBAAkB,CACnDH,SAAS,EACTE,eAAe,CAAClC,QACjB,CAAC;AACF,CACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AANAzB,OAAA,CAAAwD,0BAAA,GAAAA,0BAAA;AAOO,SAASK,gBAAgBA,CAAE3D,KAAK,EAAG;EACzC,OAAOA,KAAK,CAAC4D,aAAa;AAC3B"}
|
|
@@ -5,11 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.transformBlockToWidget = transformBlockToWidget;
|
|
7
7
|
exports.transformWidgetToBlock = transformWidgetToBlock;
|
|
8
|
-
|
|
9
8
|
var _blocks = require("@wordpress/blocks");
|
|
10
|
-
|
|
11
9
|
var _widgets = require("@wordpress/widgets");
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
11
|
* WordPress dependencies
|
|
15
12
|
*/
|
|
@@ -25,16 +22,12 @@ function transformWidgetToBlock(widget) {
|
|
|
25
22
|
const parsedBlocks = (0, _blocks.parse)(widget.instance.raw.content, {
|
|
26
23
|
__unstableSkipAutop: true
|
|
27
24
|
});
|
|
28
|
-
|
|
29
25
|
if (!parsedBlocks.length) {
|
|
30
26
|
return (0, _widgets.addWidgetIdToBlock)((0, _blocks.createBlock)('core/paragraph', {}, []), widget.id);
|
|
31
27
|
}
|
|
32
|
-
|
|
33
28
|
return (0, _widgets.addWidgetIdToBlock)(parsedBlocks[0], widget.id);
|
|
34
29
|
}
|
|
35
|
-
|
|
36
30
|
let attributes;
|
|
37
|
-
|
|
38
31
|
if (widget._embedded.about[0].is_multi) {
|
|
39
32
|
attributes = {
|
|
40
33
|
idBase: widget.id_base,
|
|
@@ -45,9 +38,9 @@ function transformWidgetToBlock(widget) {
|
|
|
45
38
|
id: widget.id
|
|
46
39
|
};
|
|
47
40
|
}
|
|
48
|
-
|
|
49
41
|
return (0, _widgets.addWidgetIdToBlock)((0, _blocks.createBlock)('core/legacy-widget', attributes, []), widget.id);
|
|
50
42
|
}
|
|
43
|
+
|
|
51
44
|
/**
|
|
52
45
|
* Converts a block to a widget entity record.
|
|
53
46
|
*
|
|
@@ -55,22 +48,20 @@ function transformWidgetToBlock(widget) {
|
|
|
55
48
|
* @param {Object?} relatedWidget A related widget entity record from the API (optional).
|
|
56
49
|
* @return {Object} the widget object (converted from block).
|
|
57
50
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
51
|
function transformBlockToWidget(block, relatedWidget = {}) {
|
|
61
52
|
let widget;
|
|
62
53
|
const isValidLegacyWidgetBlock = block.name === 'core/legacy-widget' && (block.attributes.id || block.attributes.instance);
|
|
63
|
-
|
|
64
54
|
if (isValidLegacyWidgetBlock) {
|
|
65
55
|
var _block$attributes$id, _block$attributes$idB, _block$attributes$ins;
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
widget = {
|
|
57
|
+
...relatedWidget,
|
|
68
58
|
id: (_block$attributes$id = block.attributes.id) !== null && _block$attributes$id !== void 0 ? _block$attributes$id : relatedWidget.id,
|
|
69
59
|
id_base: (_block$attributes$idB = block.attributes.idBase) !== null && _block$attributes$idB !== void 0 ? _block$attributes$idB : relatedWidget.id_base,
|
|
70
60
|
instance: (_block$attributes$ins = block.attributes.instance) !== null && _block$attributes$ins !== void 0 ? _block$attributes$ins : relatedWidget.instance
|
|
71
61
|
};
|
|
72
62
|
} else {
|
|
73
|
-
widget = {
|
|
63
|
+
widget = {
|
|
64
|
+
...relatedWidget,
|
|
74
65
|
id_base: 'block',
|
|
75
66
|
instance: {
|
|
76
67
|
raw: {
|
|
@@ -78,9 +69,9 @@ function transformBlockToWidget(block, relatedWidget = {}) {
|
|
|
78
69
|
}
|
|
79
70
|
}
|
|
80
71
|
};
|
|
81
|
-
}
|
|
82
|
-
|
|
72
|
+
}
|
|
83
73
|
|
|
74
|
+
// Delete read-only properties.
|
|
84
75
|
delete widget.rendered;
|
|
85
76
|
delete widget.rendered_form;
|
|
86
77
|
return widget;
|