@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
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { combineReducers } from '@wordpress/data';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Controls the open state of the widget areas.
|
|
7
8
|
*
|
|
@@ -10,35 +11,33 @@ import { combineReducers } from '@wordpress/data';
|
|
|
10
11
|
*
|
|
11
12
|
* @return {Array} Updated state.
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
14
|
export function widgetAreasOpenState(state = {}, action) {
|
|
15
15
|
const {
|
|
16
16
|
type
|
|
17
17
|
} = action;
|
|
18
|
-
|
|
19
18
|
switch (type) {
|
|
20
19
|
case 'SET_WIDGET_AREAS_OPEN_STATE':
|
|
21
20
|
{
|
|
22
21
|
return action.widgetAreasOpenState;
|
|
23
22
|
}
|
|
24
|
-
|
|
25
23
|
case 'SET_IS_WIDGET_AREA_OPEN':
|
|
26
24
|
{
|
|
27
25
|
const {
|
|
28
26
|
clientId,
|
|
29
27
|
isOpen
|
|
30
28
|
} = action;
|
|
31
|
-
return {
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
32
31
|
[clientId]: isOpen
|
|
33
32
|
};
|
|
34
33
|
}
|
|
35
|
-
|
|
36
34
|
default:
|
|
37
35
|
{
|
|
38
36
|
return state;
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
}
|
|
40
|
+
|
|
42
41
|
/**
|
|
43
42
|
* Reducer to set the block inserter panel open or closed.
|
|
44
43
|
*
|
|
@@ -48,18 +47,16 @@ export function widgetAreasOpenState(state = {}, action) {
|
|
|
48
47
|
* @param {Object} state Current state.
|
|
49
48
|
* @param {Object} action Dispatched action.
|
|
50
49
|
*/
|
|
51
|
-
|
|
52
50
|
export function blockInserterPanel(state = false, action) {
|
|
53
51
|
switch (action.type) {
|
|
54
52
|
case 'SET_IS_LIST_VIEW_OPENED':
|
|
55
53
|
return action.isOpen ? false : state;
|
|
56
|
-
|
|
57
54
|
case 'SET_IS_INSERTER_OPENED':
|
|
58
55
|
return action.value;
|
|
59
56
|
}
|
|
60
|
-
|
|
61
57
|
return state;
|
|
62
58
|
}
|
|
59
|
+
|
|
63
60
|
/**
|
|
64
61
|
* Reducer to set the list view panel open or closed.
|
|
65
62
|
*
|
|
@@ -69,16 +66,13 @@ export function blockInserterPanel(state = false, action) {
|
|
|
69
66
|
* @param {Object} state Current state.
|
|
70
67
|
* @param {Object} action Dispatched action.
|
|
71
68
|
*/
|
|
72
|
-
|
|
73
69
|
export function listViewPanel(state = false, action) {
|
|
74
70
|
switch (action.type) {
|
|
75
71
|
case 'SET_IS_INSERTER_OPENED':
|
|
76
72
|
return action.value ? false : state;
|
|
77
|
-
|
|
78
73
|
case 'SET_IS_LIST_VIEW_OPENED':
|
|
79
74
|
return action.isOpen;
|
|
80
75
|
}
|
|
81
|
-
|
|
82
76
|
return state;
|
|
83
77
|
}
|
|
84
78
|
export default combineReducers({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["combineReducers","widgetAreasOpenState","state","action","type","clientId","isOpen","blockInserterPanel","value","listViewPanel"],"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":"AAAA;AACA;AACA;AACA,SAASA,eAAe,QAAQ,iBAAiB;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,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;AACA,OAAO,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;AACA,OAAO,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;AAEA,eAAeF,eAAe,CAAE;EAC/BO,kBAAkB;EAClBE,aAAa;EACbR;AACD,CAAE,CAAC"}
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { createBlock } from '@wordpress/blocks';
|
|
5
5
|
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Internal dependencies
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
10
|
import { persistStubPost, setWidgetAreasOpenState } from './actions';
|
|
11
11
|
import { KIND, WIDGET_AREA_ENTITY_TYPE, buildWidgetsQuery, buildWidgetAreasQuery, buildWidgetAreaPostId, buildWidgetAreasPostId } from './utils';
|
|
12
12
|
import { transformWidgetToBlock } from './transformers';
|
|
13
|
+
|
|
13
14
|
/**
|
|
14
15
|
* Creates a "stub" widgets post reflecting all available widget areas. The
|
|
15
16
|
* post is meant as a convenient to only exists in runtime and should never be saved. It
|
|
@@ -19,7 +20,6 @@ import { transformWidgetToBlock } from './transformers';
|
|
|
19
20
|
*
|
|
20
21
|
* @return {Function} An action creator.
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
23
|
export const getWidgetAreas = () => async ({
|
|
24
24
|
dispatch,
|
|
25
25
|
registry
|
|
@@ -31,27 +31,22 @@ export const getWidgetAreas = () => async ({
|
|
|
31
31
|
if (a.id === 'wp_inactive_widgets') {
|
|
32
32
|
return 1;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
34
|
if (b.id === 'wp_inactive_widgets') {
|
|
36
35
|
return -1;
|
|
37
36
|
}
|
|
38
|
-
|
|
39
37
|
return 0;
|
|
40
38
|
});
|
|
41
|
-
|
|
42
39
|
for (const widgetArea of sortedWidgetAreas) {
|
|
43
40
|
widgetAreaBlocks.push(createBlock('core/widget-area', {
|
|
44
41
|
id: widgetArea.id,
|
|
45
42
|
name: widgetArea.name
|
|
46
43
|
}));
|
|
47
|
-
|
|
48
44
|
if (!widgetArea.widgets.length) {
|
|
49
45
|
// If this widget area has no widgets, it won't get a post setup by
|
|
50
46
|
// the getWidgets resolver.
|
|
51
47
|
dispatch(persistStubPost(buildWidgetAreaPostId(widgetArea.id), []));
|
|
52
48
|
}
|
|
53
49
|
}
|
|
54
|
-
|
|
55
50
|
const widgetAreasOpenState = {};
|
|
56
51
|
widgetAreaBlocks.forEach((widgetAreaBlock, index) => {
|
|
57
52
|
// Defaults to open the first widget area.
|
|
@@ -60,12 +55,12 @@ export const getWidgetAreas = () => async ({
|
|
|
60
55
|
dispatch(setWidgetAreasOpenState(widgetAreasOpenState));
|
|
61
56
|
dispatch(persistStubPost(buildWidgetAreasPostId(), widgetAreaBlocks));
|
|
62
57
|
};
|
|
58
|
+
|
|
63
59
|
/**
|
|
64
60
|
* Fetches all widgets from all widgets ares, and groups them by widget area Id.
|
|
65
61
|
*
|
|
66
62
|
* @return {Function} An action creator.
|
|
67
63
|
*/
|
|
68
|
-
|
|
69
64
|
export const getWidgets = () => async ({
|
|
70
65
|
dispatch,
|
|
71
66
|
registry
|
|
@@ -73,13 +68,11 @@ export const getWidgets = () => async ({
|
|
|
73
68
|
const query = buildWidgetsQuery();
|
|
74
69
|
const widgets = await registry.resolveSelect(coreStore).getEntityRecords('root', 'widget', query);
|
|
75
70
|
const groupedBySidebar = {};
|
|
76
|
-
|
|
77
71
|
for (const widget of widgets) {
|
|
78
72
|
const block = transformWidgetToBlock(widget);
|
|
79
73
|
groupedBySidebar[widget.sidebar] = groupedBySidebar[widget.sidebar] || [];
|
|
80
74
|
groupedBySidebar[widget.sidebar].push(block);
|
|
81
75
|
}
|
|
82
|
-
|
|
83
76
|
for (const sidebarId in groupedBySidebar) {
|
|
84
77
|
if (groupedBySidebar.hasOwnProperty(sidebarId)) {
|
|
85
78
|
// Persist the actual post containing the widget block
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createBlock","store","coreStore","persistStubPost","setWidgetAreasOpenState","KIND","WIDGET_AREA_ENTITY_TYPE","buildWidgetsQuery","buildWidgetAreasQuery","buildWidgetAreaPostId","buildWidgetAreasPostId","transformWidgetToBlock","getWidgetAreas","dispatch","registry","query","widgetAreas","resolveSelect","getEntityRecords","widgetAreaBlocks","sortedWidgetAreas","sort","a","b","id","widgetArea","push","name","widgets","length","widgetAreasOpenState","forEach","widgetAreaBlock","index","clientId","getWidgets","groupedBySidebar","widget","block","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\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EAEA,KAAM,MAAME,SAAS,IAAIJ,gBAAgB,EAAG;IAC3C,IAAKA,gBAAgB,CAACK,cAAc,CAAED,SAAU,CAAC,EAAG;MACnD;MACA3B,QAAQ,CACPV,eAAe,CACdM,qBAAqB,CAAE+B,SAAU,CAAC,EAClCJ,gBAAgB,CAAEI,SAAS,CAC5B,CACD,CAAC;IACF;EACD;AACD,CAAC"}
|
|
@@ -5,26 +5,33 @@ import { createRegistrySelector } from '@wordpress/data';
|
|
|
5
5
|
import { getWidgetIdFromBlock } from '@wordpress/widgets';
|
|
6
6
|
import { store as coreStore } from '@wordpress/core-data';
|
|
7
7
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
8
|
+
|
|
8
9
|
/**
|
|
9
10
|
* Internal dependencies
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
12
|
import { buildWidgetsQuery, buildWidgetAreasQuery, buildWidgetAreaPostId, KIND, POST_TYPE, WIDGET_AREA_ENTITY_TYPE } from './utils';
|
|
13
13
|
import { STORE_NAME as editWidgetsStoreName } from './constants';
|
|
14
|
+
const EMPTY_INSERTION_POINT = {
|
|
15
|
+
rootClientId: undefined,
|
|
16
|
+
insertionIndex: undefined
|
|
17
|
+
};
|
|
18
|
+
|
|
14
19
|
/**
|
|
15
20
|
* Returns all API widgets.
|
|
16
21
|
*
|
|
17
22
|
* @return {Object[]} API List of widgets.
|
|
18
23
|
*/
|
|
19
|
-
|
|
20
24
|
export const getWidgets = createRegistrySelector(select => () => {
|
|
21
25
|
const widgets = select(coreStore).getEntityRecords('root', 'widget', buildWidgetsQuery());
|
|
22
|
-
return (
|
|
23
|
-
widgets
|
|
26
|
+
return (
|
|
27
|
+
// Key widgets by their ID.
|
|
28
|
+
widgets?.reduce((allWidgets, widget) => ({
|
|
29
|
+
...allWidgets,
|
|
24
30
|
[widget.id]: widget
|
|
25
31
|
}), {}) || {}
|
|
26
32
|
);
|
|
27
33
|
});
|
|
34
|
+
|
|
28
35
|
/**
|
|
29
36
|
* Returns API widget data for a particular widget ID.
|
|
30
37
|
*
|
|
@@ -32,28 +39,27 @@ export const getWidgets = createRegistrySelector(select => () => {
|
|
|
32
39
|
*
|
|
33
40
|
* @return {Object} API widget data for a particular widget ID.
|
|
34
41
|
*/
|
|
35
|
-
|
|
36
42
|
export const getWidget = createRegistrySelector(select => (state, id) => {
|
|
37
43
|
const widgets = select(editWidgetsStoreName).getWidgets();
|
|
38
44
|
return widgets[id];
|
|
39
45
|
});
|
|
46
|
+
|
|
40
47
|
/**
|
|
41
48
|
* Returns all API widget areas.
|
|
42
49
|
*
|
|
43
50
|
* @return {Object[]} API List of widget areas.
|
|
44
51
|
*/
|
|
45
|
-
|
|
46
52
|
export const getWidgetAreas = createRegistrySelector(select => () => {
|
|
47
53
|
const query = buildWidgetAreasQuery();
|
|
48
54
|
return select(coreStore).getEntityRecords(KIND, WIDGET_AREA_ENTITY_TYPE, query);
|
|
49
55
|
});
|
|
56
|
+
|
|
50
57
|
/**
|
|
51
58
|
* Returns widgetArea containing a block identify by given widgetId
|
|
52
59
|
*
|
|
53
60
|
* @param {string} widgetId The ID of the widget.
|
|
54
61
|
* @return {Object} Containing widget area.
|
|
55
62
|
*/
|
|
56
|
-
|
|
57
63
|
export const getWidgetAreaForWidgetId = createRegistrySelector(select => (state, widgetId) => {
|
|
58
64
|
const widgetAreas = select(editWidgetsStoreName).getWidgetAreas();
|
|
59
65
|
return widgetAreas.find(widgetArea => {
|
|
@@ -62,6 +68,7 @@ export const getWidgetAreaForWidgetId = createRegistrySelector(select => (state,
|
|
|
62
68
|
return blockWidgetIds.includes(widgetId);
|
|
63
69
|
});
|
|
64
70
|
});
|
|
71
|
+
|
|
65
72
|
/**
|
|
66
73
|
* Given a child client id, returns the parent widget area block.
|
|
67
74
|
*
|
|
@@ -69,7 +76,6 @@ export const getWidgetAreaForWidgetId = createRegistrySelector(select => (state,
|
|
|
69
76
|
*
|
|
70
77
|
* @return {WPBlock} The widget area block.
|
|
71
78
|
*/
|
|
72
|
-
|
|
73
79
|
export const getParentWidgetAreaBlock = createRegistrySelector(select => (state, clientId) => {
|
|
74
80
|
const {
|
|
75
81
|
getBlock,
|
|
@@ -80,90 +86,79 @@ export const getParentWidgetAreaBlock = createRegistrySelector(select => (state,
|
|
|
80
86
|
const widgetAreaClientId = blockParents.find(parentClientId => getBlockName(parentClientId) === 'core/widget-area');
|
|
81
87
|
return getBlock(widgetAreaClientId);
|
|
82
88
|
});
|
|
89
|
+
|
|
83
90
|
/**
|
|
84
91
|
* Returns all edited widget area entity records.
|
|
85
92
|
*
|
|
86
93
|
* @return {Object[]} List of edited widget area entity records.
|
|
87
94
|
*/
|
|
88
|
-
|
|
89
95
|
export const getEditedWidgetAreas = createRegistrySelector(select => (state, ids) => {
|
|
90
96
|
let widgetAreas = select(editWidgetsStoreName).getWidgetAreas();
|
|
91
|
-
|
|
92
97
|
if (!widgetAreas) {
|
|
93
98
|
return [];
|
|
94
99
|
}
|
|
95
|
-
|
|
96
100
|
if (ids) {
|
|
97
101
|
widgetAreas = widgetAreas.filter(({
|
|
98
102
|
id
|
|
99
103
|
}) => ids.includes(id));
|
|
100
104
|
}
|
|
101
|
-
|
|
102
105
|
return widgetAreas.filter(({
|
|
103
106
|
id
|
|
104
107
|
}) => select(coreStore).hasEditsForEntityRecord(KIND, POST_TYPE, buildWidgetAreaPostId(id))).map(({
|
|
105
108
|
id
|
|
106
109
|
}) => select(coreStore).getEditedEntityRecord(KIND, WIDGET_AREA_ENTITY_TYPE, id));
|
|
107
110
|
});
|
|
111
|
+
|
|
108
112
|
/**
|
|
109
113
|
* Returns all blocks representing reference widgets.
|
|
110
114
|
*
|
|
111
115
|
* @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.
|
|
112
116
|
* @return {Array} List of all blocks representing reference widgets
|
|
113
117
|
*/
|
|
114
|
-
|
|
115
118
|
export const getReferenceWidgetBlocks = createRegistrySelector(select => (state, referenceWidgetName = null) => {
|
|
116
119
|
const results = [];
|
|
117
120
|
const widgetAreas = select(editWidgetsStoreName).getWidgetAreas();
|
|
118
|
-
|
|
119
121
|
for (const _widgetArea of widgetAreas) {
|
|
120
122
|
const post = select(coreStore).getEditedEntityRecord(KIND, POST_TYPE, buildWidgetAreaPostId(_widgetArea.id));
|
|
121
|
-
|
|
122
123
|
for (const block of post.blocks) {
|
|
123
124
|
if (block.name === 'core/legacy-widget' && (!referenceWidgetName || block.attributes?.referenceWidgetName === referenceWidgetName)) {
|
|
124
125
|
results.push(block);
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
|
-
|
|
129
129
|
return results;
|
|
130
130
|
});
|
|
131
|
+
|
|
131
132
|
/**
|
|
132
133
|
* Returns true if any widget area is currently being saved.
|
|
133
134
|
*
|
|
134
135
|
* @return {boolean} True if any widget area is currently being saved. False otherwise.
|
|
135
136
|
*/
|
|
136
|
-
|
|
137
137
|
export const isSavingWidgetAreas = createRegistrySelector(select => () => {
|
|
138
138
|
const widgetAreasIds = select(editWidgetsStoreName).getWidgetAreas()?.map(({
|
|
139
139
|
id
|
|
140
140
|
}) => id);
|
|
141
|
-
|
|
142
141
|
if (!widgetAreasIds) {
|
|
143
142
|
return false;
|
|
144
143
|
}
|
|
145
|
-
|
|
146
144
|
for (const id of widgetAreasIds) {
|
|
147
145
|
const isSaving = select(coreStore).isSavingEntityRecord(KIND, WIDGET_AREA_ENTITY_TYPE, id);
|
|
148
|
-
|
|
149
146
|
if (isSaving) {
|
|
150
147
|
return true;
|
|
151
148
|
}
|
|
152
149
|
}
|
|
153
|
-
|
|
154
150
|
const widgetIds = [...Object.keys(select(editWidgetsStoreName).getWidgets()), undefined // account for new widgets without an ID
|
|
155
151
|
];
|
|
156
152
|
|
|
157
153
|
for (const id of widgetIds) {
|
|
158
154
|
const isSaving = select(coreStore).isSavingEntityRecord('root', 'widget', id);
|
|
159
|
-
|
|
160
155
|
if (isSaving) {
|
|
161
156
|
return true;
|
|
162
157
|
}
|
|
163
158
|
}
|
|
164
|
-
|
|
165
159
|
return false;
|
|
166
160
|
});
|
|
161
|
+
|
|
167
162
|
/**
|
|
168
163
|
* Gets whether the widget area is opened.
|
|
169
164
|
*
|
|
@@ -172,13 +167,13 @@ export const isSavingWidgetAreas = createRegistrySelector(select => () => {
|
|
|
172
167
|
*
|
|
173
168
|
* @return {boolean} True if the widget area is open.
|
|
174
169
|
*/
|
|
175
|
-
|
|
176
170
|
export const getIsWidgetAreaOpen = (state, clientId) => {
|
|
177
171
|
const {
|
|
178
172
|
widgetAreasOpenState
|
|
179
173
|
} = state;
|
|
180
174
|
return !!widgetAreasOpenState[clientId];
|
|
181
175
|
};
|
|
176
|
+
|
|
182
177
|
/**
|
|
183
178
|
* Returns true if the inserter is opened.
|
|
184
179
|
*
|
|
@@ -186,10 +181,10 @@ export const getIsWidgetAreaOpen = (state, clientId) => {
|
|
|
186
181
|
*
|
|
187
182
|
* @return {boolean} Whether the inserter is opened.
|
|
188
183
|
*/
|
|
189
|
-
|
|
190
184
|
export function isInserterOpened(state) {
|
|
191
185
|
return !!state.blockInserterPanel;
|
|
192
186
|
}
|
|
187
|
+
|
|
193
188
|
/**
|
|
194
189
|
* Get the insertion point for the inserter.
|
|
195
190
|
*
|
|
@@ -197,17 +192,13 @@ export function isInserterOpened(state) {
|
|
|
197
192
|
*
|
|
198
193
|
* @return {Object} The root client ID and index to insert at.
|
|
199
194
|
*/
|
|
200
|
-
|
|
201
195
|
export function __experimentalGetInsertionPoint(state) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
return {
|
|
207
|
-
rootClientId,
|
|
208
|
-
insertionIndex
|
|
209
|
-
};
|
|
196
|
+
if (typeof state === 'boolean') {
|
|
197
|
+
return EMPTY_INSERTION_POINT;
|
|
198
|
+
}
|
|
199
|
+
return state.blockInserterPanel;
|
|
210
200
|
}
|
|
201
|
+
|
|
211
202
|
/**
|
|
212
203
|
* Returns true if a block can be inserted into a widget area.
|
|
213
204
|
*
|
|
@@ -216,16 +207,17 @@ export function __experimentalGetInsertionPoint(state) {
|
|
|
216
207
|
*
|
|
217
208
|
* @return {boolean} True if the block can be inserted in a widget area.
|
|
218
209
|
*/
|
|
219
|
-
|
|
220
210
|
export const canInsertBlockInWidgetArea = createRegistrySelector(select => (state, blockName) => {
|
|
221
211
|
// Widget areas are always top-level blocks, which getBlocks will return.
|
|
222
|
-
const widgetAreas = select(blockEditorStore).getBlocks();
|
|
212
|
+
const widgetAreas = select(blockEditorStore).getBlocks();
|
|
213
|
+
|
|
214
|
+
// Makes an assumption that a block that can be inserted into one
|
|
223
215
|
// widget area can be inserted into any widget area. Uses the first
|
|
224
216
|
// widget area for testing whether the block can be inserted.
|
|
225
|
-
|
|
226
217
|
const [firstWidgetArea] = widgetAreas;
|
|
227
218
|
return select(blockEditorStore).canInsertBlockType(blockName, firstWidgetArea.clientId);
|
|
228
219
|
});
|
|
220
|
+
|
|
229
221
|
/**
|
|
230
222
|
* Returns true if the list view is opened.
|
|
231
223
|
*
|
|
@@ -233,7 +225,6 @@ export const canInsertBlockInWidgetArea = createRegistrySelector(select => (stat
|
|
|
233
225
|
*
|
|
234
226
|
* @return {boolean} Whether the list view is opened.
|
|
235
227
|
*/
|
|
236
|
-
|
|
237
228
|
export function isListViewOpened(state) {
|
|
238
229
|
return state.listViewPanel;
|
|
239
230
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/store/selectors.js"],"names":["createRegistrySelector","getWidgetIdFromBlock","store","coreStore","blockEditorStore","buildWidgetsQuery","buildWidgetAreasQuery","buildWidgetAreaPostId","KIND","POST_TYPE","WIDGET_AREA_ENTITY_TYPE","STORE_NAME","editWidgetsStoreName","getWidgets","select","widgets","getEntityRecords","reduce","allWidgets","widget","id","getWidget","state","getWidgetAreas","query","getWidgetAreaForWidgetId","widgetId","widgetAreas","find","widgetArea","post","getEditedEntityRecord","blockWidgetIds","blocks","map","block","includes","getParentWidgetAreaBlock","clientId","getBlock","getBlockName","getBlockParents","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":"AAAA;AACA;AACA;AACA,SAASA,sBAAT,QAAuC,iBAAvC;AACA,SAASC,oBAAT,QAAqC,oBAArC;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASD,KAAK,IAAIE,gBAAlB,QAA0C,yBAA1C;AAEA;AACA;AACA;;AACA,SACCC,iBADD,EAECC,qBAFD,EAGCC,qBAHD,EAICC,IAJD,EAKCC,SALD,EAMCC,uBAND,QAOO,SAPP;AAQA,SAASC,UAAU,IAAIC,oBAAvB,QAAmD,aAAnD;AAEA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,UAAU,GAAGb,sBAAsB,CAAIc,MAAF,IAAc,MAAM;AACrE,QAAMC,OAAO,GAAGD,MAAM,CAAEX,SAAF,CAAN,CAAoBa,gBAApB,CACf,MADe,EAEf,QAFe,EAGfX,iBAAiB,EAHF,CAAhB;AAMA,SACC;AACAU,IAAAA,OAAO,EAAEE,MAAT,CACC,CAAEC,UAAF,EAAcC,MAAd,MAA4B,EAC3B,GAAGD,UADwB;AAE3B,OAAEC,MAAM,CAACC,EAAT,GAAeD;AAFY,KAA5B,CADD,EAKC,EALD,KAMK;AARN;AAUA,CAjB+C,CAAzC;AAmBP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAME,SAAS,GAAGrB,sBAAsB,CAC5Cc,MAAF,IAAc,CAAEQ,KAAF,EAASF,EAAT,KAAi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eAAe,CAACpC,QAFV,CAAP;AAIA,CAb8D,CAAzD;AAgBP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASsC,gBAAT,CAA2BtD,KAA3B,EAAmC;AACzC,SAAOA,KAAK,CAACuD,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":["createRegistrySelector","getWidgetIdFromBlock","store","coreStore","blockEditorStore","buildWidgetsQuery","buildWidgetAreasQuery","buildWidgetAreaPostId","KIND","POST_TYPE","WIDGET_AREA_ENTITY_TYPE","STORE_NAME","editWidgetsStoreName","EMPTY_INSERTION_POINT","rootClientId","undefined","insertionIndex","getWidgets","select","widgets","getEntityRecords","reduce","allWidgets","widget","id","getWidget","state","getWidgetAreas","query","getWidgetAreaForWidgetId","widgetId","widgetAreas","find","widgetArea","post","getEditedEntityRecord","blockWidgetIds","blocks","map","block","includes","getParentWidgetAreaBlock","clientId","getBlock","getBlockName","getBlockParents","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":"AAAA;AACA;AACA;AACA,SAASA,sBAAsB,QAAQ,iBAAiB;AACxD,SAASC,oBAAoB,QAAQ,oBAAoB;AACzD,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASD,KAAK,IAAIE,gBAAgB,QAAQ,yBAAyB;;AAEnE;AACA;AACA;AACA,SACCC,iBAAiB,EACjBC,qBAAqB,EACrBC,qBAAqB,EACrBC,IAAI,EACJC,SAAS,EACTC,uBAAuB,QACjB,SAAS;AAChB,SAASC,UAAU,IAAIC,oBAAoB,QAAQ,aAAa;AAEhE,MAAMC,qBAAqB,GAAG;EAC7BC,YAAY,EAAEC,SAAS;EACvBC,cAAc,EAAED;AACjB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,MAAME,UAAU,GAAGjB,sBAAsB,CAAIkB,MAAM,IAAM,MAAM;EACrE,MAAMC,OAAO,GAAGD,MAAM,CAAEf,SAAU,CAAC,CAACiB,gBAAgB,CACnD,MAAM,EACN,QAAQ,EACRf,iBAAiB,CAAC,CACnB,CAAC;EAED;IACC;IACAc,OAAO,EAAEE,MAAM,CACd,CAAEC,UAAU,EAAEC,MAAM,MAAQ;MAC3B,GAAGD,UAAU;MACb,CAAEC,MAAM,CAACC,EAAE,GAAID;IAChB,CAAC,CAAE,EACH,CAAC,CACF,CAAC,IAAI,CAAC;EAAC;AAET,CAAE,CAAC;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAME,SAAS,GAAGzB,sBAAsB,CAC5CkB,MAAM,IAAM,CAAEQ,KAAK,EAAEF,EAAE,KAAM;EAC9B,MAAML,OAAO,GAAGD,MAAM,CAAEN,oBAAqB,CAAC,CAACK,UAAU,CAAC,CAAC;EAC3D,O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|
|
4
4
|
import { createBlock, parse, serialize } from '@wordpress/blocks';
|
|
5
5
|
import { addWidgetIdToBlock } from '@wordpress/widgets';
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Converts a widget entity record into a block.
|
|
8
9
|
*
|
|
9
10
|
* @param {Object} widget The widget entity record.
|
|
10
11
|
* @return {Object} a block (converted from the entity record).
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
13
|
export function transformWidgetToBlock(widget) {
|
|
14
14
|
if (widget.id_base === 'block') {
|
|
15
15
|
const parsedBlocks = parse(widget.instance.raw.content, {
|
|
16
16
|
__unstableSkipAutop: true
|
|
17
17
|
});
|
|
18
|
-
|
|
19
18
|
if (!parsedBlocks.length) {
|
|
20
19
|
return addWidgetIdToBlock(createBlock('core/paragraph', {}, []), widget.id);
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
return addWidgetIdToBlock(parsedBlocks[0], widget.id);
|
|
24
22
|
}
|
|
25
|
-
|
|
26
23
|
let attributes;
|
|
27
|
-
|
|
28
24
|
if (widget._embedded.about[0].is_multi) {
|
|
29
25
|
attributes = {
|
|
30
26
|
idBase: widget.id_base,
|
|
@@ -35,9 +31,9 @@ export function transformWidgetToBlock(widget) {
|
|
|
35
31
|
id: widget.id
|
|
36
32
|
};
|
|
37
33
|
}
|
|
38
|
-
|
|
39
34
|
return addWidgetIdToBlock(createBlock('core/legacy-widget', attributes, []), widget.id);
|
|
40
35
|
}
|
|
36
|
+
|
|
41
37
|
/**
|
|
42
38
|
* Converts a block to a widget entity record.
|
|
43
39
|
*
|
|
@@ -45,21 +41,20 @@ export function transformWidgetToBlock(widget) {
|
|
|
45
41
|
* @param {Object?} relatedWidget A related widget entity record from the API (optional).
|
|
46
42
|
* @return {Object} the widget object (converted from block).
|
|
47
43
|
*/
|
|
48
|
-
|
|
49
44
|
export function transformBlockToWidget(block, relatedWidget = {}) {
|
|
50
45
|
let widget;
|
|
51
46
|
const isValidLegacyWidgetBlock = block.name === 'core/legacy-widget' && (block.attributes.id || block.attributes.instance);
|
|
52
|
-
|
|
53
47
|
if (isValidLegacyWidgetBlock) {
|
|
54
48
|
var _block$attributes$id, _block$attributes$idB, _block$attributes$ins;
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
widget = {
|
|
50
|
+
...relatedWidget,
|
|
57
51
|
id: (_block$attributes$id = block.attributes.id) !== null && _block$attributes$id !== void 0 ? _block$attributes$id : relatedWidget.id,
|
|
58
52
|
id_base: (_block$attributes$idB = block.attributes.idBase) !== null && _block$attributes$idB !== void 0 ? _block$attributes$idB : relatedWidget.id_base,
|
|
59
53
|
instance: (_block$attributes$ins = block.attributes.instance) !== null && _block$attributes$ins !== void 0 ? _block$attributes$ins : relatedWidget.instance
|
|
60
54
|
};
|
|
61
55
|
} else {
|
|
62
|
-
widget = {
|
|
56
|
+
widget = {
|
|
57
|
+
...relatedWidget,
|
|
63
58
|
id_base: 'block',
|
|
64
59
|
instance: {
|
|
65
60
|
raw: {
|
|
@@ -67,9 +62,9 @@ export function transformBlockToWidget(block, relatedWidget = {}) {
|
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
64
|
};
|
|
70
|
-
}
|
|
71
|
-
|
|
65
|
+
}
|
|
72
66
|
|
|
67
|
+
// Delete read-only properties.
|
|
73
68
|
delete widget.rendered;
|
|
74
69
|
delete widget.rendered_form;
|
|
75
70
|
return widget;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createBlock","parse","serialize","addWidgetIdToBlock","transformWidgetToBlock","widget","id_base","parsedBlocks","instance","raw","content","__unstableSkipAutop","length","id","attributes","_embedded","about","is_multi","idBase","transformBlockToWidget","block","relatedWidget","isValidLegacyWidgetBlock","name","_block$attributes$id","_block$attributes$idB","_block$attributes$ins","rendered","rendered_form"],"sources":["@wordpress/edit-widgets/src/store/transformers.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { 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":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,KAAK,EAAEC,SAAS,QAAQ,mBAAmB;AACjE,SAASC,kBAAkB,QAAQ,oBAAoB;;AAEvD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,sBAAsBA,CAAEC,MAAM,EAAG;EAChD,IAAKA,MAAM,CAACC,OAAO,KAAK,OAAO,EAAG;IACjC,MAAMC,YAAY,GAAGN,KAAK,CAAEI,MAAM,CAACG,QAAQ,CAACC,GAAG,CAACC,OAAO,EAAE;MACxDC,mBAAmB,EAAE;IACtB,CAAE,CAAC;IACH,IAAK,CAAEJ,YAAY,CAACK,MAAM,EAAG;MAC5B,OAAOT,kBAAkB,CACxBH,WAAW,CAAE,gBAAgB,EAAE,CAAC,CAAC,EAAE,EAAG,CAAC,EACvCK,MAAM,CAACQ,EACR,CAAC;IACF;IACA,OAAOV,kBAAkB,CAAEI,YAAY,CAAE,CAAC,CAAE,EAAEF,MAAM,CAACQ,EAAG,CAAC;EAC1D;EAEA,IAAIC,UAAU;EACd,IAAKT,MAAM,CAACU,SAAS,CAACC,KAAK,CAAE,CAAC,CAAE,CAACC,QAAQ,EAAG;IAC3CH,UAAU,GAAG;MACZI,MAAM,EAAEb,MAAM,CAACC,OAAO;MACtBE,QAAQ,EAAEH,MAAM,CAACG;IAClB,CAAC;EACF,CAAC,MAAM;IACNM,UAAU,GAAG;MACZD,EAAE,EAAER,MAAM,CAACQ;IACZ,CAAC;EACF;EAEA,OAAOV,kBAAkB,CACxBH,WAAW,CAAE,oBAAoB,EAAEc,UAAU,EAAE,EAAG,CAAC,EACnDT,MAAM,CAACQ,EACR,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM,sBAAsBA,CAAEC,KAAK,EAAEC,aAAa,GAAG,CAAC,CAA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