@wordpress/core-data 4.6.0 → 4.9.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 +11 -1
- package/README.md +209 -119
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +1 -1
- package/build/batch/create-batch.js.map +1 -1
- package/build/entities.js +49 -35
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js.map +1 -1
- package/build/entity-types/entities.js +6 -0
- package/build/entity-types/entities.js.map +1 -0
- package/build/hooks/constants.js +0 -2
- package/build/hooks/constants.js.map +1 -1
- package/build/hooks/index.js +38 -0
- package/build/hooks/index.js.map +1 -0
- package/build/hooks/use-entity-record.js +22 -8
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +21 -8
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/index.js +17 -21
- package/build/index.js.map +1 -1
- package/build/queried-data/selectors.js.map +1 -1
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +206 -169
- package/build/selectors.js.map +1 -1
- package/build/utils/forward-resolver.js.map +1 -1
- package/build/utils/on-sub-key.js.map +1 -1
- package/build/utils/with-weak-map-cache.js +1 -7
- package/build/utils/with-weak-map-cache.js.map +1 -1
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +2 -2
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/entities.js +49 -35
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/entity-types/entities.js +2 -0
- package/build-module/entity-types/entities.js.map +1 -0
- package/build-module/hooks/constants.js +0 -1
- package/build-module/hooks/constants.js.map +1 -1
- package/build-module/hooks/index.js +3 -0
- package/build-module/hooks/index.js.map +1 -0
- package/build-module/hooks/use-entity-record.js +18 -7
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +17 -7
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/index.js +2 -3
- package/build-module/index.js.map +1 -1
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +203 -166
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/forward-resolver.js.map +1 -1
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/build-module/utils/with-weak-map-cache.js +1 -6
- package/build-module/utils/with-weak-map-cache.js.map +1 -1
- package/package.json +12 -12
- package/src/actions.js +389 -372
- package/src/batch/create-batch.js +2 -2
- package/src/entities.ts +357 -135
- package/src/entity-provider.js +4 -6
- package/src/entity-types/attachment.ts +4 -3
- package/src/entity-types/comment.ts +4 -3
- package/src/entity-types/entities.ts +130 -0
- package/src/entity-types/index.ts +115 -20
- package/src/entity-types/menu-location.ts +4 -3
- package/src/entity-types/nav-menu-item.ts +4 -3
- package/src/entity-types/nav-menu.ts +3 -3
- package/src/entity-types/page.ts +3 -3
- package/src/entity-types/plugin.ts +3 -3
- package/src/entity-types/post.ts +3 -3
- package/src/entity-types/settings.ts +3 -3
- package/src/entity-types/sidebar.ts +4 -3
- package/src/entity-types/taxonomy.ts +4 -3
- package/src/entity-types/theme.ts +3 -3
- package/src/entity-types/type.ts +3 -3
- package/src/entity-types/user.ts +3 -3
- package/src/entity-types/widget-type.ts +4 -3
- package/src/entity-types/widget.ts +3 -3
- package/src/entity-types/wp-template-part.ts +4 -3
- package/src/entity-types/wp-template.ts +4 -3
- package/src/fetch/test/__experimental-fetch-link-suggestions.js +2 -4
- package/src/hooks/constants.ts +1 -2
- package/src/hooks/index.ts +8 -0
- package/src/hooks/test/use-query-select.js +4 -2
- package/src/hooks/use-entity-record.ts +31 -9
- package/src/hooks/use-entity-records.ts +28 -30
- package/src/hooks/use-query-select.ts +26 -24
- package/src/index.js +2 -3
- package/src/locks/test/selectors.js +2 -1
- package/src/queried-data/selectors.js +2 -8
- package/src/resolvers.js +344 -325
- package/src/selectors.ts +639 -296
- package/src/test/resolvers.js +1 -3
- package/src/test/selectors.js +1 -2
- package/src/utils/forward-resolver.js +6 -5
- package/src/utils/on-sub-key.js +20 -20
- package/src/utils/with-weak-map-cache.js +1 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { zip } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
@@ -88,7 +88,7 @@ export default function createBatch( processor = defaultProcessor ) {
|
|
|
88
88
|
pending.delete( id );
|
|
89
89
|
} );
|
|
90
90
|
|
|
91
|
-
if (
|
|
91
|
+
if ( typeof inputOrThunk === 'function' ) {
|
|
92
92
|
return Promise.resolve( inputOrThunk( add ) ).finally( () => {
|
|
93
93
|
pending.delete( id );
|
|
94
94
|
} );
|
package/src/entities.ts
CHANGED
|
@@ -13,163 +13,386 @@ import { __ } from '@wordpress/i18n';
|
|
|
13
13
|
* Internal dependencies
|
|
14
14
|
*/
|
|
15
15
|
import { addEntities } from './actions';
|
|
16
|
-
import type
|
|
16
|
+
import type * as Records from './entity-types';
|
|
17
|
+
import type {
|
|
18
|
+
EntityType,
|
|
19
|
+
Context,
|
|
20
|
+
Post,
|
|
21
|
+
Taxonomy,
|
|
22
|
+
Type,
|
|
23
|
+
Updatable,
|
|
24
|
+
} from './entity-types';
|
|
17
25
|
|
|
18
26
|
export const DEFAULT_ENTITY_KEY = 'id';
|
|
19
27
|
|
|
20
28
|
const POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];
|
|
21
29
|
|
|
22
|
-
|
|
30
|
+
type AttachmentEntity< C extends Context = Context > = EntityType<
|
|
23
31
|
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
baseURL: '/',
|
|
28
|
-
baseURLParams: {
|
|
29
|
-
_fields: [
|
|
30
|
-
'description',
|
|
31
|
-
'gmt_offset',
|
|
32
|
-
'home',
|
|
33
|
-
'name',
|
|
34
|
-
'site_icon',
|
|
35
|
-
'site_icon_url',
|
|
36
|
-
'site_logo',
|
|
37
|
-
'timezone_string',
|
|
38
|
-
'url',
|
|
39
|
-
].join( ',' ),
|
|
40
|
-
},
|
|
32
|
+
name: 'media';
|
|
33
|
+
kind: 'root';
|
|
34
|
+
baseURLParams: { context: 'edit' };
|
|
41
35
|
},
|
|
36
|
+
Records.Attachment< C >,
|
|
37
|
+
C
|
|
38
|
+
>;
|
|
39
|
+
|
|
40
|
+
const attachmentConfig: AttachmentEntity[ 'config' ] = {
|
|
41
|
+
name: 'media',
|
|
42
|
+
kind: 'root',
|
|
43
|
+
baseURL: '/wp/v2/media',
|
|
44
|
+
baseURLParams: { context: 'edit' },
|
|
45
|
+
plural: 'mediaItems',
|
|
46
|
+
label: __( 'Media' ),
|
|
47
|
+
rawAttributes: [ 'caption', 'title', 'description' ],
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type SiteEntity< C extends Context = Context > = EntityType<
|
|
42
51
|
{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
kind: 'root',
|
|
46
|
-
baseURL: '/wp/v2/settings',
|
|
47
|
-
getTitle: ( record ) => {
|
|
48
|
-
return get( record, [ 'title' ], __( 'Site Title' ) );
|
|
49
|
-
},
|
|
52
|
+
name: 'site';
|
|
53
|
+
kind: 'root';
|
|
50
54
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
Records.Settings< C >,
|
|
56
|
+
C
|
|
57
|
+
>;
|
|
58
|
+
|
|
59
|
+
const siteConfig: SiteEntity[ 'config' ] = {
|
|
60
|
+
label: __( 'Site' ),
|
|
61
|
+
name: 'site',
|
|
62
|
+
kind: 'root',
|
|
63
|
+
baseURL: '/wp/v2/settings',
|
|
64
|
+
getTitle: ( record: Records.Settings< 'edit' > ) => {
|
|
65
|
+
return get( record, [ 'title' ], __( 'Site Title' ) );
|
|
59
66
|
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
type PostTypeEntity< C extends Context = Context > = EntityType<
|
|
60
70
|
{
|
|
61
|
-
name: '
|
|
62
|
-
kind: 'root'
|
|
63
|
-
|
|
64
|
-
baseURLParams: { context: 'edit' }
|
|
65
|
-
plural: 'mediaItems',
|
|
66
|
-
label: __( 'Media' ),
|
|
67
|
-
rawAttributes: [ 'caption', 'title', 'description' ],
|
|
71
|
+
name: 'postType';
|
|
72
|
+
kind: 'root';
|
|
73
|
+
key: 'slug';
|
|
74
|
+
baseURLParams: { context: 'edit' };
|
|
68
75
|
},
|
|
76
|
+
Records.Type< C >,
|
|
77
|
+
C
|
|
78
|
+
>;
|
|
79
|
+
|
|
80
|
+
const postTypeConfig: PostTypeEntity[ 'config' ] = {
|
|
81
|
+
label: __( 'Post Type' ),
|
|
82
|
+
name: 'postType',
|
|
83
|
+
kind: 'root',
|
|
84
|
+
key: 'slug',
|
|
85
|
+
baseURL: '/wp/v2/types',
|
|
86
|
+
baseURLParams: { context: 'edit' },
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
type TaxonomyEntity< C extends Context = Context > = EntityType<
|
|
69
90
|
{
|
|
70
|
-
name: 'taxonomy'
|
|
71
|
-
kind: 'root'
|
|
72
|
-
key: 'slug'
|
|
73
|
-
|
|
74
|
-
baseURLParams: { context: 'edit' },
|
|
75
|
-
plural: 'taxonomies',
|
|
76
|
-
label: __( 'Taxonomy' ),
|
|
91
|
+
name: 'taxonomy';
|
|
92
|
+
kind: 'root';
|
|
93
|
+
key: 'slug';
|
|
94
|
+
baseURLParams: { context: 'edit' };
|
|
77
95
|
},
|
|
96
|
+
Records.Taxonomy< C >,
|
|
97
|
+
C
|
|
98
|
+
>;
|
|
99
|
+
|
|
100
|
+
const taxonomyConfig: TaxonomyEntity[ 'config' ] = {
|
|
101
|
+
name: 'taxonomy',
|
|
102
|
+
kind: 'root',
|
|
103
|
+
key: 'slug',
|
|
104
|
+
baseURL: '/wp/v2/taxonomies',
|
|
105
|
+
baseURLParams: { context: 'edit' },
|
|
106
|
+
plural: 'taxonomies',
|
|
107
|
+
label: __( 'Taxonomy' ),
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
type SidebarEntity< C extends Context = Context > = EntityType<
|
|
78
111
|
{
|
|
79
|
-
name: 'sidebar'
|
|
80
|
-
kind: 'root'
|
|
81
|
-
|
|
82
|
-
baseURLParams: { context: 'edit' },
|
|
83
|
-
plural: 'sidebars',
|
|
84
|
-
transientEdits: { blocks: true },
|
|
85
|
-
label: __( 'Widget areas' ),
|
|
112
|
+
name: 'sidebar';
|
|
113
|
+
kind: 'root';
|
|
114
|
+
baseURLParams: { context: 'edit' };
|
|
86
115
|
},
|
|
116
|
+
Records.Sidebar< C >,
|
|
117
|
+
C
|
|
118
|
+
>;
|
|
119
|
+
|
|
120
|
+
const sidebarConfig: SidebarEntity[ 'config' ] = {
|
|
121
|
+
name: 'sidebar',
|
|
122
|
+
kind: 'root',
|
|
123
|
+
baseURL: '/wp/v2/sidebars',
|
|
124
|
+
baseURLParams: { context: 'edit' },
|
|
125
|
+
plural: 'sidebars',
|
|
126
|
+
transientEdits: { blocks: true },
|
|
127
|
+
label: __( 'Widget areas' ),
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
type WidgetEntity< C extends Context = Context > = EntityType<
|
|
87
131
|
{
|
|
88
|
-
name: 'widget'
|
|
89
|
-
kind: 'root'
|
|
90
|
-
|
|
91
|
-
baseURLParams: { context: 'edit' },
|
|
92
|
-
plural: 'widgets',
|
|
93
|
-
transientEdits: { blocks: true },
|
|
94
|
-
label: __( 'Widgets' ),
|
|
132
|
+
name: 'widget';
|
|
133
|
+
kind: 'root';
|
|
134
|
+
baseURLParams: { context: 'edit' };
|
|
95
135
|
},
|
|
136
|
+
Records.Widget< C >,
|
|
137
|
+
C
|
|
138
|
+
>;
|
|
139
|
+
const widgetConfig: WidgetEntity[ 'config' ] = {
|
|
140
|
+
name: 'widget',
|
|
141
|
+
kind: 'root',
|
|
142
|
+
baseURL: '/wp/v2/widgets',
|
|
143
|
+
baseURLParams: { context: 'edit' },
|
|
144
|
+
plural: 'widgets',
|
|
145
|
+
transientEdits: { blocks: true },
|
|
146
|
+
label: __( 'Widgets' ),
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
type WidgetTypeEntity< C extends Context = Context > = EntityType<
|
|
96
150
|
{
|
|
97
|
-
name: 'widgetType'
|
|
98
|
-
kind: 'root'
|
|
99
|
-
|
|
100
|
-
baseURLParams: { context: 'edit' },
|
|
101
|
-
plural: 'widgetTypes',
|
|
102
|
-
label: __( 'Widget types' ),
|
|
151
|
+
name: 'widgetType';
|
|
152
|
+
kind: 'root';
|
|
153
|
+
baseURLParams: { context: 'edit' };
|
|
103
154
|
},
|
|
155
|
+
Records.WidgetType< C >,
|
|
156
|
+
C
|
|
157
|
+
>;
|
|
158
|
+
const widgetTypeConfig: WidgetTypeEntity[ 'config' ] = {
|
|
159
|
+
name: 'widgetType',
|
|
160
|
+
kind: 'root',
|
|
161
|
+
baseURL: '/wp/v2/widget-types',
|
|
162
|
+
baseURLParams: { context: 'edit' },
|
|
163
|
+
plural: 'widgetTypes',
|
|
164
|
+
label: __( 'Widget types' ),
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
type UserEntity< C extends Context = Context > = EntityType<
|
|
104
168
|
{
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
baseURL: '/wp/v2/users',
|
|
109
|
-
baseURLParams: { context: 'edit' },
|
|
110
|
-
plural: 'users',
|
|
169
|
+
name: 'user';
|
|
170
|
+
kind: 'root';
|
|
171
|
+
baseURLParams: { context: 'edit' };
|
|
111
172
|
},
|
|
173
|
+
Records.User< C >,
|
|
174
|
+
C
|
|
175
|
+
>;
|
|
176
|
+
const userConfig: UserEntity[ 'config' ] = {
|
|
177
|
+
label: __( 'User' ),
|
|
178
|
+
name: 'user',
|
|
179
|
+
kind: 'root',
|
|
180
|
+
baseURL: '/wp/v2/users',
|
|
181
|
+
baseURLParams: { context: 'edit' },
|
|
182
|
+
plural: 'users',
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
type CommentEntity< C extends Context = Context > = EntityType<
|
|
112
186
|
{
|
|
113
|
-
name: 'comment'
|
|
114
|
-
kind: 'root'
|
|
115
|
-
|
|
116
|
-
baseURLParams: { context: 'edit' },
|
|
117
|
-
plural: 'comments',
|
|
118
|
-
label: __( 'Comment' ),
|
|
187
|
+
name: 'comment';
|
|
188
|
+
kind: 'root';
|
|
189
|
+
baseURLParams: { context: 'edit' };
|
|
119
190
|
},
|
|
191
|
+
Records.Comment< C >,
|
|
192
|
+
C
|
|
193
|
+
>;
|
|
194
|
+
const commentConfig: CommentEntity[ 'config' ] = {
|
|
195
|
+
name: 'comment',
|
|
196
|
+
kind: 'root',
|
|
197
|
+
baseURL: '/wp/v2/comments',
|
|
198
|
+
baseURLParams: { context: 'edit' },
|
|
199
|
+
plural: 'comments',
|
|
200
|
+
label: __( 'Comment' ),
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
type NavMenuEntity< C extends Context = Context > = EntityType<
|
|
120
204
|
{
|
|
121
|
-
name: 'menu'
|
|
122
|
-
kind: 'root'
|
|
123
|
-
|
|
124
|
-
baseURLParams: { context: 'edit' },
|
|
125
|
-
plural: 'menus',
|
|
126
|
-
label: __( 'Menu' ),
|
|
205
|
+
name: 'menu';
|
|
206
|
+
kind: 'root';
|
|
207
|
+
baseURLParams: { context: 'edit' };
|
|
127
208
|
},
|
|
209
|
+
Records.NavMenu< C >,
|
|
210
|
+
C
|
|
211
|
+
>;
|
|
212
|
+
|
|
213
|
+
const menuConfig: NavMenuEntity[ 'config' ] = {
|
|
214
|
+
name: 'menu',
|
|
215
|
+
kind: 'root',
|
|
216
|
+
baseURL: '/wp/v2/menus',
|
|
217
|
+
baseURLParams: { context: 'edit' },
|
|
218
|
+
plural: 'menus',
|
|
219
|
+
label: __( 'Menu' ),
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
type NavMenuItemEntity< C extends Context = Context > = EntityType<
|
|
128
223
|
{
|
|
129
|
-
name: 'menuItem'
|
|
130
|
-
kind: 'root'
|
|
131
|
-
|
|
132
|
-
baseURLParams: { context: 'edit' },
|
|
133
|
-
plural: 'menuItems',
|
|
134
|
-
label: __( 'Menu Item' ),
|
|
135
|
-
rawAttributes: [ 'title', 'content' ],
|
|
224
|
+
name: 'menuItem';
|
|
225
|
+
kind: 'root';
|
|
226
|
+
baseURLParams: { context: 'edit' };
|
|
136
227
|
},
|
|
228
|
+
Records.NavMenuItem< C >,
|
|
229
|
+
C
|
|
230
|
+
>;
|
|
231
|
+
|
|
232
|
+
const menuItemConfig: NavMenuItemEntity[ 'config' ] = {
|
|
233
|
+
name: 'menuItem',
|
|
234
|
+
kind: 'root',
|
|
235
|
+
baseURL: '/wp/v2/menu-items',
|
|
236
|
+
baseURLParams: { context: 'edit' },
|
|
237
|
+
plural: 'menuItems',
|
|
238
|
+
label: __( 'Menu Item' ),
|
|
239
|
+
rawAttributes: [ 'title' ],
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
type MenuLocationEntity< C extends Context = Context > = EntityType<
|
|
137
243
|
{
|
|
138
|
-
name: 'menuLocation'
|
|
139
|
-
kind: 'root'
|
|
140
|
-
|
|
141
|
-
baseURLParams: { context: 'edit' }
|
|
142
|
-
plural: 'menuLocations',
|
|
143
|
-
label: __( 'Menu Location' ),
|
|
144
|
-
key: 'name',
|
|
244
|
+
name: 'menuLocation';
|
|
245
|
+
kind: 'root';
|
|
246
|
+
key: 'name';
|
|
247
|
+
baseURLParams: { context: 'edit' };
|
|
145
248
|
},
|
|
249
|
+
Records.MenuLocation< C >,
|
|
250
|
+
C
|
|
251
|
+
>;
|
|
252
|
+
|
|
253
|
+
const menuLocationConfig: MenuLocationEntity[ 'config' ] = {
|
|
254
|
+
name: 'menuLocation',
|
|
255
|
+
kind: 'root',
|
|
256
|
+
baseURL: '/wp/v2/menu-locations',
|
|
257
|
+
baseURLParams: { context: 'edit' },
|
|
258
|
+
plural: 'menuLocations',
|
|
259
|
+
label: __( 'Menu Location' ),
|
|
260
|
+
key: 'name',
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const globalStyleConfig = {
|
|
264
|
+
label: __( 'Global Styles' ),
|
|
265
|
+
name: 'globalStyles',
|
|
266
|
+
kind: 'root',
|
|
267
|
+
baseURL: '/wp/v2/global-styles',
|
|
268
|
+
baseURLParams: { context: 'edit' },
|
|
269
|
+
plural: 'globalStylesVariations', // Should be different than name.
|
|
270
|
+
getTitle: ( record ) => record?.title?.rendered || record?.title,
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
type ThemeEntity< C extends Context = Context > = EntityType<
|
|
146
274
|
{
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
baseURLParams: { context: 'edit' },
|
|
152
|
-
plural: 'globalStylesVariations', // Should be different than name.
|
|
153
|
-
getTitle: ( record ) => record?.title?.rendered || record?.title,
|
|
275
|
+
name: 'theme';
|
|
276
|
+
kind: 'root';
|
|
277
|
+
baseURLParams: { context: 'edit' };
|
|
278
|
+
key: 'stylesheet';
|
|
154
279
|
},
|
|
280
|
+
Records.Theme< C >,
|
|
281
|
+
C
|
|
282
|
+
>;
|
|
283
|
+
|
|
284
|
+
const themeConfig: ThemeEntity[ 'config' ] = {
|
|
285
|
+
label: __( 'Themes' ),
|
|
286
|
+
name: 'theme',
|
|
287
|
+
kind: 'root',
|
|
288
|
+
baseURL: '/wp/v2/themes',
|
|
289
|
+
baseURLParams: { context: 'edit' },
|
|
290
|
+
key: 'stylesheet',
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
type PluginEntity< C extends Context = Context > = EntityType<
|
|
155
294
|
{
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
baseURLParams: { context: 'edit' },
|
|
161
|
-
key: 'stylesheet',
|
|
295
|
+
name: 'plugin';
|
|
296
|
+
kind: 'root';
|
|
297
|
+
baseURLParams: { context: 'edit' };
|
|
298
|
+
key: 'plugin';
|
|
162
299
|
},
|
|
300
|
+
Records.Plugin< C >,
|
|
301
|
+
C
|
|
302
|
+
>;
|
|
303
|
+
const pluginConfig: PluginEntity[ 'config' ] = {
|
|
304
|
+
label: __( 'Plugins' ),
|
|
305
|
+
name: 'plugin',
|
|
306
|
+
kind: 'root',
|
|
307
|
+
baseURL: '/wp/v2/plugins',
|
|
308
|
+
baseURLParams: { context: 'edit' },
|
|
309
|
+
key: 'plugin',
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
export const rootEntitiesConfig = [
|
|
163
313
|
{
|
|
164
|
-
label: __( '
|
|
165
|
-
name: 'plugin',
|
|
314
|
+
label: __( 'Base' ),
|
|
166
315
|
kind: 'root',
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
316
|
+
name: '__unstableBase',
|
|
317
|
+
baseURL: '/',
|
|
318
|
+
baseURLParams: {
|
|
319
|
+
_fields: [
|
|
320
|
+
'description',
|
|
321
|
+
'gmt_offset',
|
|
322
|
+
'home',
|
|
323
|
+
'name',
|
|
324
|
+
'site_icon',
|
|
325
|
+
'site_icon_url',
|
|
326
|
+
'site_logo',
|
|
327
|
+
'timezone_string',
|
|
328
|
+
'url',
|
|
329
|
+
].join( ',' ),
|
|
330
|
+
},
|
|
170
331
|
},
|
|
332
|
+
siteConfig,
|
|
333
|
+
postTypeConfig,
|
|
334
|
+
attachmentConfig,
|
|
335
|
+
taxonomyConfig,
|
|
336
|
+
sidebarConfig,
|
|
337
|
+
widgetConfig,
|
|
338
|
+
widgetTypeConfig,
|
|
339
|
+
userConfig,
|
|
340
|
+
commentConfig,
|
|
341
|
+
menuConfig,
|
|
342
|
+
menuItemConfig,
|
|
343
|
+
menuLocationConfig,
|
|
344
|
+
globalStyleConfig,
|
|
345
|
+
themeConfig,
|
|
346
|
+
pluginConfig,
|
|
171
347
|
];
|
|
172
348
|
|
|
349
|
+
type PostTypeConfig = {
|
|
350
|
+
kind: 'postType';
|
|
351
|
+
key: 'id';
|
|
352
|
+
defaultContext: 'edit';
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
type PostEntity< C extends Context = Context > = EntityType<
|
|
356
|
+
PostTypeConfig & { name: 'post' },
|
|
357
|
+
Records.Post< C >,
|
|
358
|
+
C
|
|
359
|
+
>;
|
|
360
|
+
type PageEntity< C extends Context > = EntityType<
|
|
361
|
+
PostTypeConfig & { name: 'page' },
|
|
362
|
+
Records.Page< C >,
|
|
363
|
+
C
|
|
364
|
+
>;
|
|
365
|
+
type WpTemplateEntity< C extends Context > = EntityType<
|
|
366
|
+
PostTypeConfig & { name: 'wp_template' },
|
|
367
|
+
Records.WpTemplate< C >,
|
|
368
|
+
C
|
|
369
|
+
>;
|
|
370
|
+
type WpTemplatePartEntity< C extends Context > = EntityType<
|
|
371
|
+
PostTypeConfig & { name: 'wp_template_part' },
|
|
372
|
+
Records.WpTemplatePart< C >,
|
|
373
|
+
C
|
|
374
|
+
>;
|
|
375
|
+
|
|
376
|
+
export type CoreEntities< C extends Context > =
|
|
377
|
+
| SiteEntity< C >
|
|
378
|
+
| PostTypeEntity< C >
|
|
379
|
+
| AttachmentEntity< C >
|
|
380
|
+
| TaxonomyEntity< C >
|
|
381
|
+
| SidebarEntity< C >
|
|
382
|
+
| WidgetEntity< C >
|
|
383
|
+
| WidgetTypeEntity< C >
|
|
384
|
+
| UserEntity< C >
|
|
385
|
+
| CommentEntity< C >
|
|
386
|
+
| NavMenuEntity< C >
|
|
387
|
+
| NavMenuItemEntity< C >
|
|
388
|
+
| MenuLocationEntity< C >
|
|
389
|
+
| ThemeEntity< C >
|
|
390
|
+
| PluginEntity< C >
|
|
391
|
+
| PostEntity< C >
|
|
392
|
+
| PageEntity< C >
|
|
393
|
+
| WpTemplateEntity< C >
|
|
394
|
+
| WpTemplatePartEntity< C >;
|
|
395
|
+
|
|
173
396
|
export const additionalEntityConfigLoaders = [
|
|
174
397
|
{ kind: 'postType', loadEntities: loadPostTypeEntities },
|
|
175
398
|
{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },
|
|
@@ -292,7 +515,7 @@ export const getMethodName = (
|
|
|
292
515
|
const nameSuffix =
|
|
293
516
|
upperFirst( camelCase( name ) ) + ( usePlural ? 's' : '' );
|
|
294
517
|
const suffix =
|
|
295
|
-
usePlural && entityConfig?.plural
|
|
518
|
+
usePlural && 'plural' in entityConfig! && entityConfig?.plural
|
|
296
519
|
? upperFirst( camelCase( entityConfig.plural ) )
|
|
297
520
|
: nameSuffix;
|
|
298
521
|
return `${ prefix }${ kindPrefix }${ suffix }`;
|
|
@@ -305,22 +528,21 @@ export const getMethodName = (
|
|
|
305
528
|
*
|
|
306
529
|
* @return {(thunkArgs: object) => Promise<Array>} Entities
|
|
307
530
|
*/
|
|
308
|
-
export const getOrLoadEntitiesConfig =
|
|
309
|
-
|
|
310
|
-
dispatch
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
531
|
+
export const getOrLoadEntitiesConfig =
|
|
532
|
+
( kind ) =>
|
|
533
|
+
async ( { select, dispatch } ) => {
|
|
534
|
+
let configs = select.getEntitiesConfig( kind );
|
|
535
|
+
if ( configs && configs.length !== 0 ) {
|
|
536
|
+
return configs;
|
|
537
|
+
}
|
|
316
538
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
539
|
+
const loader = find( additionalEntityConfigLoaders, { kind } );
|
|
540
|
+
if ( ! loader ) {
|
|
541
|
+
return [];
|
|
542
|
+
}
|
|
321
543
|
|
|
322
|
-
|
|
323
|
-
|
|
544
|
+
configs = await loader.loadEntities();
|
|
545
|
+
dispatch( addEntities( configs ) );
|
|
324
546
|
|
|
325
|
-
|
|
326
|
-
};
|
|
547
|
+
return configs;
|
|
548
|
+
};
|
package/src/entity-provider.js
CHANGED
|
@@ -105,9 +105,8 @@ export function useEntityProp( kind, name, prop, _id ) {
|
|
|
105
105
|
|
|
106
106
|
const { value, fullValue } = useSelect(
|
|
107
107
|
( select ) => {
|
|
108
|
-
const { getEntityRecord, getEditedEntityRecord } =
|
|
109
|
-
STORE_NAME
|
|
110
|
-
);
|
|
108
|
+
const { getEntityRecord, getEditedEntityRecord } =
|
|
109
|
+
select( STORE_NAME );
|
|
111
110
|
const record = getEntityRecord( kind, name, id ); // Trigger resolver.
|
|
112
111
|
const editedRecord = getEditedEntityRecord( kind, name, id );
|
|
113
112
|
return record && editedRecord
|
|
@@ -164,9 +163,8 @@ export function useEntityBlockEditor( kind, name, { id: _id } = {} ) {
|
|
|
164
163
|
},
|
|
165
164
|
[ kind, name, id ]
|
|
166
165
|
);
|
|
167
|
-
const { __unstableCreateUndoLevel, editEntityRecord } =
|
|
168
|
-
STORE_NAME
|
|
169
|
-
);
|
|
166
|
+
const { __unstableCreateUndoLevel, editEntityRecord } =
|
|
167
|
+
useDispatch( STORE_NAME );
|
|
170
168
|
|
|
171
169
|
useEffect( () => {
|
|
172
170
|
// Load the blocks from the content if not already in state
|
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
} from './helpers';
|
|
14
14
|
|
|
15
15
|
import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
|
|
16
|
+
import type { DefaultContextOf } from './index';
|
|
16
17
|
|
|
17
18
|
declare module './base-entity-records' {
|
|
18
19
|
export namespace BaseEntityRecords {
|
|
@@ -141,6 +142,6 @@ declare module './base-entity-records' {
|
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
144
|
|
|
144
|
-
export type Attachment<
|
|
145
|
-
|
|
146
|
-
>;
|
|
145
|
+
export type Attachment<
|
|
146
|
+
C extends Context = DefaultContextOf< 'root', 'media' >
|
|
147
|
+
> = OmitNevers< _BaseEntityRecords.Attachment< C > >;
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
RenderedText,
|
|
10
10
|
} from './helpers';
|
|
11
11
|
import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
|
|
12
|
+
import type { DefaultContextOf } from './index';
|
|
12
13
|
|
|
13
14
|
export type CommentStatus = 'hold' | 'approve' | 'spam' | 'trash' | '1' | '0';
|
|
14
15
|
|
|
@@ -91,6 +92,6 @@ declare module './base-entity-records' {
|
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
export type Comment<
|
|
95
|
-
|
|
96
|
-
>;
|
|
95
|
+
export type Comment<
|
|
96
|
+
C extends Context = DefaultContextOf< 'root', 'comment' >
|
|
97
|
+
> = OmitNevers< _BaseEntityRecords.Comment< C > >;
|