@wordpress/edit-widgets 4.7.0 → 4.10.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 +6 -0
- package/build/blocks/widget-area/edit/inner-blocks.js.map +1 -1
- package/build/components/error-boundary/index.js +3 -0
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/header/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/config.js +17 -0
- package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +1 -3
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/layout/interface.js.map +1 -1
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/secondary-sidebar/index.js.map +1 -1
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/widget-areas-block-editor-provider/index.js +12 -14
- package/build/components/widget-areas-block-editor-provider/index.js.map +1 -1
- package/build/filters/move-to-widget-area.js.map +1 -1
- package/build/hooks/use-last-selected-widget-area.js.map +1 -1
- package/build/hooks/use-widget-library-insertion-point.js.map +1 -1
- package/build/store/actions.js +1 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/resolvers.js.map +1 -1
- package/build/store/selectors.js +5 -7
- package/build/store/selectors.js.map +1 -1
- package/build-module/blocks/widget-area/edit/inner-blocks.js.map +1 -1
- package/build-module/components/error-boundary/index.js +2 -0
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/config.js +17 -0
- package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +1 -2
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/layout/interface.js.map +1 -1
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/secondary-sidebar/index.js.map +1 -1
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/widget-areas-block-editor-provider/index.js +12 -13
- package/build-module/components/widget-areas-block-editor-provider/index.js.map +1 -1
- package/build-module/filters/move-to-widget-area.js.map +1 -1
- package/build-module/hooks/use-last-selected-widget-area.js.map +1 -1
- package/build-module/hooks/use-widget-library-insertion-point.js.map +1 -1
- package/build-module/store/actions.js +1 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/resolvers.js.map +1 -1
- package/build-module/store/selectors.js +5 -6
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +5 -14
- package/build-style/style.css +5 -14
- package/package.json +26 -26
- package/src/blocks/widget-area/edit/inner-blocks.js +2 -1
- package/src/components/error-boundary/index.js +3 -0
- package/src/components/header/index.js +4 -8
- package/src/components/header/style.scss +4 -10
- package/src/components/keyboard-shortcut-help-modal/config.js +12 -0
- package/src/components/keyboard-shortcut-help-modal/index.js +1 -2
- package/src/components/layout/interface.js +2 -5
- package/src/components/save-button/index.js +2 -3
- package/src/components/secondary-sidebar/index.js +2 -3
- package/src/components/sidebar/index.js +2 -5
- package/src/components/test/error-boundary.js +38 -0
- package/src/components/widget-areas-block-editor-provider/index.js +2 -9
- package/src/filters/move-to-widget-area.js +19 -24
- package/src/hooks/use-last-selected-widget-area.js +4 -6
- package/src/hooks/use-widget-library-insertion-point.js +2 -3
- package/src/store/actions.js +262 -258
- package/src/store/resolvers.js +69 -60
- package/src/store/selectors.js +32 -28
package/src/store/resolvers.js
CHANGED
|
@@ -27,78 +27,87 @@ import { transformWidgetToBlock } from './transformers';
|
|
|
27
27
|
*
|
|
28
28
|
* @return {Function} An action creator.
|
|
29
29
|
*/
|
|
30
|
-
export const getWidgetAreas =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
export const getWidgetAreas =
|
|
31
|
+
() =>
|
|
32
|
+
async ( { dispatch, registry } ) => {
|
|
33
|
+
const query = buildWidgetAreasQuery();
|
|
34
|
+
const widgetAreas = await registry
|
|
35
|
+
.resolveSelect( coreStore )
|
|
36
|
+
.getEntityRecords( KIND, WIDGET_AREA_ENTITY_TYPE, query );
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
if ( ! widgetArea.widgets.length ) {
|
|
55
|
-
// If this widget area has no widgets, it won't get a post setup by
|
|
56
|
-
// the getWidgets resolver.
|
|
57
|
-
dispatch(
|
|
58
|
-
persistStubPost( buildWidgetAreaPostId( widgetArea.id ), [] )
|
|
38
|
+
const widgetAreaBlocks = [];
|
|
39
|
+
const sortedWidgetAreas = widgetAreas.sort( ( a, b ) => {
|
|
40
|
+
if ( a.id === 'wp_inactive_widgets' ) {
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
if ( b.id === 'wp_inactive_widgets' ) {
|
|
44
|
+
return -1;
|
|
45
|
+
}
|
|
46
|
+
return 0;
|
|
47
|
+
} );
|
|
48
|
+
for ( const widgetArea of sortedWidgetAreas ) {
|
|
49
|
+
widgetAreaBlocks.push(
|
|
50
|
+
createBlock( 'core/widget-area', {
|
|
51
|
+
id: widgetArea.id,
|
|
52
|
+
name: widgetArea.name,
|
|
53
|
+
} )
|
|
59
54
|
);
|
|
55
|
+
|
|
56
|
+
if ( ! widgetArea.widgets.length ) {
|
|
57
|
+
// If this widget area has no widgets, it won't get a post setup by
|
|
58
|
+
// the getWidgets resolver.
|
|
59
|
+
dispatch(
|
|
60
|
+
persistStubPost(
|
|
61
|
+
buildWidgetAreaPostId( widgetArea.id ),
|
|
62
|
+
[]
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
60
66
|
}
|
|
61
|
-
}
|
|
62
67
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
const widgetAreasOpenState = {};
|
|
69
|
+
widgetAreaBlocks.forEach( ( widgetAreaBlock, index ) => {
|
|
70
|
+
// Defaults to open the first widget area.
|
|
71
|
+
widgetAreasOpenState[ widgetAreaBlock.clientId ] = index === 0;
|
|
72
|
+
} );
|
|
73
|
+
dispatch( setWidgetAreasOpenState( widgetAreasOpenState ) );
|
|
69
74
|
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
dispatch(
|
|
76
|
+
persistStubPost( buildWidgetAreasPostId(), widgetAreaBlocks )
|
|
77
|
+
);
|
|
78
|
+
};
|
|
72
79
|
|
|
73
80
|
/**
|
|
74
81
|
* Fetches all widgets from all widgets ares, and groups them by widget area Id.
|
|
75
82
|
*
|
|
76
83
|
* @return {Function} An action creator.
|
|
77
84
|
*/
|
|
78
|
-
export const getWidgets =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
export const getWidgets =
|
|
86
|
+
() =>
|
|
87
|
+
async ( { dispatch, registry } ) => {
|
|
88
|
+
const query = buildWidgetsQuery();
|
|
89
|
+
const widgets = await registry
|
|
90
|
+
.resolveSelect( coreStore )
|
|
91
|
+
.getEntityRecords( 'root', 'widget', query );
|
|
83
92
|
|
|
84
|
-
|
|
93
|
+
const groupedBySidebar = {};
|
|
85
94
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
for ( const widget of widgets ) {
|
|
96
|
+
const block = transformWidgetToBlock( widget );
|
|
97
|
+
groupedBySidebar[ widget.sidebar ] =
|
|
98
|
+
groupedBySidebar[ widget.sidebar ] || [];
|
|
99
|
+
groupedBySidebar[ widget.sidebar ].push( block );
|
|
100
|
+
}
|
|
92
101
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
for ( const sidebarId in groupedBySidebar ) {
|
|
103
|
+
if ( groupedBySidebar.hasOwnProperty( sidebarId ) ) {
|
|
104
|
+
// Persist the actual post containing the widget block
|
|
105
|
+
dispatch(
|
|
106
|
+
persistStubPost(
|
|
107
|
+
buildWidgetAreaPostId( sidebarId ),
|
|
108
|
+
groupedBySidebar[ sidebarId ]
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
}
|
|
102
112
|
}
|
|
103
|
-
}
|
|
104
|
-
};
|
|
113
|
+
};
|
package/src/store/selectors.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { keyBy } from 'lodash';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* WordPress dependencies
|
|
8
3
|
*/
|
|
@@ -36,7 +31,16 @@ export const getWidgets = createRegistrySelector( ( select ) => () => {
|
|
|
36
31
|
buildWidgetsQuery()
|
|
37
32
|
);
|
|
38
33
|
|
|
39
|
-
return
|
|
34
|
+
return (
|
|
35
|
+
// Key widgets by their ID.
|
|
36
|
+
widgets?.reduce(
|
|
37
|
+
( allWidgets, widget ) => ( {
|
|
38
|
+
...allWidgets,
|
|
39
|
+
[ widget.id ]: widget,
|
|
40
|
+
} ),
|
|
41
|
+
{}
|
|
42
|
+
) || {}
|
|
43
|
+
);
|
|
40
44
|
} );
|
|
41
45
|
|
|
42
46
|
/**
|
|
@@ -99,9 +103,8 @@ export const getWidgetAreaForWidgetId = createRegistrySelector(
|
|
|
99
103
|
*/
|
|
100
104
|
export const getParentWidgetAreaBlock = createRegistrySelector(
|
|
101
105
|
( select ) => ( state, clientId ) => {
|
|
102
|
-
const { getBlock, getBlockName, getBlockParents } =
|
|
103
|
-
blockEditorStore
|
|
104
|
-
);
|
|
106
|
+
const { getBlock, getBlockName, getBlockParents } =
|
|
107
|
+
select( blockEditorStore );
|
|
105
108
|
const blockParents = getBlockParents( clientId );
|
|
106
109
|
const widgetAreaClientId = blockParents.find(
|
|
107
110
|
( parentClientId ) =>
|
|
@@ -152,28 +155,29 @@ export const getEditedWidgetAreas = createRegistrySelector(
|
|
|
152
155
|
* @return {Array} List of all blocks representing reference widgets
|
|
153
156
|
*/
|
|
154
157
|
export const getReferenceWidgetBlocks = createRegistrySelector(
|
|
155
|
-
( select ) =>
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
referenceWidgetName
|
|
170
|
-
|
|
171
|
-
|
|
158
|
+
( select ) =>
|
|
159
|
+
( state, referenceWidgetName = null ) => {
|
|
160
|
+
const results = [];
|
|
161
|
+
const widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();
|
|
162
|
+
for ( const _widgetArea of widgetAreas ) {
|
|
163
|
+
const post = select( coreStore ).getEditedEntityRecord(
|
|
164
|
+
KIND,
|
|
165
|
+
POST_TYPE,
|
|
166
|
+
buildWidgetAreaPostId( _widgetArea.id )
|
|
167
|
+
);
|
|
168
|
+
for ( const block of post.blocks ) {
|
|
169
|
+
if (
|
|
170
|
+
block.name === 'core/legacy-widget' &&
|
|
171
|
+
( ! referenceWidgetName ||
|
|
172
|
+
block.attributes?.referenceWidgetName ===
|
|
173
|
+
referenceWidgetName )
|
|
174
|
+
) {
|
|
175
|
+
results.push( block );
|
|
176
|
+
}
|
|
172
177
|
}
|
|
173
178
|
}
|
|
179
|
+
return results;
|
|
174
180
|
}
|
|
175
|
-
return results;
|
|
176
|
-
}
|
|
177
181
|
);
|
|
178
182
|
|
|
179
183
|
/**
|