@wordpress/core-data 4.5.0 → 4.8.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 +175 -85
- package/build/entities.js +49 -46
- package/build/entities.js.map +1 -1
- package/build/entity-types/{navigation-area.js → entities.js} +1 -1
- package/build/entity-types/{navigation-area.js.map → entities.js.map} +0 -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/index.js +17 -21
- package/build/index.js.map +1 -1
- package/build/queried-data/get-query-parts.js +4 -0
- package/build/queried-data/get-query-parts.js.map +1 -1
- package/build/selectors.js +163 -163
- package/build/selectors.js.map +1 -1
- package/build-module/entities.js +49 -46
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-types/entities.js +2 -0
- package/build-module/entity-types/{navigation-area.js.map → entities.js.map} +0 -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/index.js +2 -3
- package/build-module/index.js.map +1 -1
- package/build-module/queried-data/get-query-parts.js +4 -0
- package/build-module/queried-data/get-query-parts.js.map +1 -1
- package/build-module/selectors.js +164 -163
- package/build-module/selectors.js.map +1 -1
- package/package.json +12 -12
- package/src/entities.ts +342 -129
- package/src/entity-types/entities.ts +127 -0
- package/src/entity-types/index.ts +1 -3
- package/src/hooks/constants.ts +1 -2
- package/src/hooks/index.ts +8 -0
- package/src/hooks/test/use-entity-record.js +1 -0
- package/src/hooks/test/use-entity-records.js +1 -0
- package/src/hooks/test/use-query-select.js +1 -0
- package/src/hooks/use-entity-record.ts +32 -9
- package/src/hooks/use-entity-records.ts +28 -30
- package/src/index.js +2 -3
- package/src/queried-data/get-query-parts.js +3 -0
- package/src/queried-data/test/get-query-parts.js +4 -0
- package/src/selectors.ts +406 -216
- package/src/test/actions.js +30 -14
- package/src/test/entities.js +5 -0
- package/src/test/resolvers.js +11 -0
- package/build-module/entity-types/navigation-area.js +0 -2
- package/src/entity-types/navigation-area.ts +0 -29
package/src/entities.ts
CHANGED
|
@@ -13,173 +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',
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
name: 'comment',
|
|
114
|
-
kind: 'root',
|
|
115
|
-
baseURL: '/wp/v2/comments',
|
|
116
|
-
baseURLParams: { context: 'edit' },
|
|
117
|
-
plural: 'comments',
|
|
118
|
-
label: __( 'Comment' ),
|
|
169
|
+
name: 'user';
|
|
170
|
+
kind: 'root';
|
|
171
|
+
baseURLParams: { context: 'edit' };
|
|
119
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<
|
|
120
186
|
{
|
|
121
|
-
name: '
|
|
122
|
-
kind: 'root'
|
|
123
|
-
|
|
124
|
-
baseURLParams: { context: 'edit' },
|
|
125
|
-
plural: 'menus',
|
|
126
|
-
label: __( 'Menu' ),
|
|
187
|
+
name: 'comment';
|
|
188
|
+
kind: 'root';
|
|
189
|
+
baseURLParams: { context: 'edit' };
|
|
127
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<
|
|
128
204
|
{
|
|
129
|
-
name: '
|
|
130
|
-
kind: 'root'
|
|
131
|
-
|
|
132
|
-
baseURLParams: { context: 'edit' },
|
|
133
|
-
plural: 'menuItems',
|
|
134
|
-
label: __( 'Menu Item' ),
|
|
135
|
-
rawAttributes: [ 'title', 'content' ],
|
|
205
|
+
name: 'menu';
|
|
206
|
+
kind: 'root';
|
|
207
|
+
baseURLParams: { context: 'edit' };
|
|
136
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<
|
|
137
223
|
{
|
|
138
|
-
name: '
|
|
139
|
-
kind: 'root'
|
|
140
|
-
|
|
141
|
-
baseURLParams: { context: 'edit' },
|
|
142
|
-
plural: 'menuLocations',
|
|
143
|
-
label: __( 'Menu Location' ),
|
|
144
|
-
key: 'name',
|
|
224
|
+
name: 'menuItem';
|
|
225
|
+
kind: 'root';
|
|
226
|
+
baseURLParams: { context: 'edit' };
|
|
145
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<
|
|
146
243
|
{
|
|
147
|
-
name: '
|
|
148
|
-
kind: 'root'
|
|
149
|
-
|
|
150
|
-
baseURLParams: { context: 'edit' }
|
|
151
|
-
plural: 'navigationAreas',
|
|
152
|
-
label: __( 'Navigation Area' ),
|
|
153
|
-
key: 'name',
|
|
154
|
-
getTitle: ( record ) => record?.description,
|
|
244
|
+
name: 'menuLocation';
|
|
245
|
+
kind: 'root';
|
|
246
|
+
key: 'name';
|
|
247
|
+
baseURLParams: { context: 'edit' };
|
|
155
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<
|
|
156
274
|
{
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
baseURLParams: { context: 'edit' },
|
|
162
|
-
plural: 'globalStylesVariations', // Should be different than name.
|
|
163
|
-
getTitle: ( record ) => record?.title?.rendered || record?.title,
|
|
275
|
+
name: 'theme';
|
|
276
|
+
kind: 'root';
|
|
277
|
+
baseURLParams: { context: 'edit' };
|
|
278
|
+
key: 'stylesheet';
|
|
164
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<
|
|
165
294
|
{
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
baseURLParams: { context: 'edit' },
|
|
171
|
-
key: 'stylesheet',
|
|
295
|
+
name: 'plugin';
|
|
296
|
+
kind: 'root';
|
|
297
|
+
baseURLParams: { context: 'edit' };
|
|
298
|
+
key: 'plugin';
|
|
172
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 = [
|
|
173
313
|
{
|
|
174
|
-
label: __( '
|
|
175
|
-
name: 'plugin',
|
|
314
|
+
label: __( 'Base' ),
|
|
176
315
|
kind: 'root',
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
+
},
|
|
180
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,
|
|
181
347
|
];
|
|
182
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
|
+
|
|
183
396
|
export const additionalEntityConfigLoaders = [
|
|
184
397
|
{ kind: 'postType', loadEntities: loadPostTypeEntities },
|
|
185
398
|
{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },
|
|
@@ -302,7 +515,7 @@ export const getMethodName = (
|
|
|
302
515
|
const nameSuffix =
|
|
303
516
|
upperFirst( camelCase( name ) ) + ( usePlural ? 's' : '' );
|
|
304
517
|
const suffix =
|
|
305
|
-
usePlural && entityConfig?.plural
|
|
518
|
+
usePlural && 'plural' in entityConfig && entityConfig?.plural
|
|
306
519
|
? upperFirst( camelCase( entityConfig.plural ) )
|
|
307
520
|
: nameSuffix;
|
|
308
521
|
return `${ prefix }${ kindPrefix }${ suffix }`;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { Context } from './helpers';
|
|
5
|
+
import { EntityRecord } from './index';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* HTTP Query parameters sent with the API request to fetch the entity records.
|
|
9
|
+
*/
|
|
10
|
+
export type EntityQuery<
|
|
11
|
+
C extends Context,
|
|
12
|
+
Fields extends string[] | undefined = undefined
|
|
13
|
+
> = Record< string, any > & {
|
|
14
|
+
context?: C;
|
|
15
|
+
/**
|
|
16
|
+
* The requested fields. If specified, the REST API will remove from the response
|
|
17
|
+
* any fields not on that list.
|
|
18
|
+
*/
|
|
19
|
+
_fields?: Fields;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
interface Edit {}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Helper type that transforms "raw" entity configuration from entities.ts
|
|
26
|
+
* into a format that makes searching by root and kind easy and extensible.
|
|
27
|
+
*
|
|
28
|
+
* This is the foundation of return type inference in calls such as:
|
|
29
|
+
* `getEntityRecord( "root", "comment", 15 )`.
|
|
30
|
+
*
|
|
31
|
+
* @see EntityRecordOf
|
|
32
|
+
* @see getEntityRecord
|
|
33
|
+
*/
|
|
34
|
+
export type EntityType<
|
|
35
|
+
Config extends Pick< EntityConfig< Record, Ctx >, RequiredConfigKeys >,
|
|
36
|
+
Record extends EntityRecord< Ctx >,
|
|
37
|
+
Ctx extends Context
|
|
38
|
+
> = {
|
|
39
|
+
record: Record;
|
|
40
|
+
config: Omit< EntityConfig< Record, Ctx >, RequiredConfigKeys > & Config;
|
|
41
|
+
key: Config[ 'key' ] extends string ? Config[ 'key' ] : 'id';
|
|
42
|
+
defaultContext: Config[ 'baseURLParams' ] extends {
|
|
43
|
+
context: infer InferredContext;
|
|
44
|
+
}
|
|
45
|
+
? InferredContext
|
|
46
|
+
: 'view';
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
type RequiredConfigKeys = 'name' | 'kind' | 'key' | 'baseURLParams';
|
|
50
|
+
|
|
51
|
+
interface EntityConfig< R extends EntityRecord< C >, C extends Context > {
|
|
52
|
+
/** Path in WP REST API from which to request records of this entity. */
|
|
53
|
+
baseURL: string;
|
|
54
|
+
|
|
55
|
+
/** Arguments to supply by default to API requests for records of this entity. */
|
|
56
|
+
baseURLParams?: EntityQuery< Context >;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns the title for a given record of this entity.
|
|
60
|
+
*
|
|
61
|
+
* Some entities have an associated title, such as the name of a
|
|
62
|
+
* particular template part ("full width") or of a menu ("main nav").
|
|
63
|
+
*/
|
|
64
|
+
getTitle?: ( record: R ) => string;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Indicates an alternate field in record that can be used for identification.
|
|
68
|
+
*
|
|
69
|
+
* e.g. a post has an id but may also be uniquely identified by its `slug`
|
|
70
|
+
*/
|
|
71
|
+
key?: string;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Collection in which to classify records of this entity.
|
|
75
|
+
*
|
|
76
|
+
* 'root' is a special name given to the core entities provided by the editor.
|
|
77
|
+
*
|
|
78
|
+
* It may be the case that we request an entity record for which we have no
|
|
79
|
+
* valid config in memory. In these cases the editor will look for a loader
|
|
80
|
+
* function to requests more entity configs from the server for the given
|
|
81
|
+
* "kind." This is how WordPress defers loading of template entity configs.
|
|
82
|
+
*/
|
|
83
|
+
kind: string;
|
|
84
|
+
|
|
85
|
+
/** Translated form of human-recognizable name or reference to records of this entity. */
|
|
86
|
+
label: string;
|
|
87
|
+
|
|
88
|
+
mergedEdits?: {
|
|
89
|
+
meta?: boolean;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/** Name given to records of this entity, e.g. 'media', 'postType', 'widget' */
|
|
93
|
+
name: string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Manually provided plural form of the entity name.
|
|
97
|
+
*
|
|
98
|
+
* When not supplied the editor will attempt to auto-generate a plural form.
|
|
99
|
+
*/
|
|
100
|
+
plural?: string;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Fields in record of this entity which may appear as a compound object with
|
|
104
|
+
* a source value (`raw`) as well as a processed value (`rendered`).
|
|
105
|
+
*
|
|
106
|
+
* e.g. a post's `content` in the edit context contains the raw value stored
|
|
107
|
+
* in the database as well as the rendered version with shortcodes replaced,
|
|
108
|
+
* content texturized, blocks transformed, etc…
|
|
109
|
+
*/
|
|
110
|
+
rawAttributes?: ( keyof R )[];
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Which transient edit operations records of this entity support.
|
|
114
|
+
*/
|
|
115
|
+
transientEdits?: {
|
|
116
|
+
blocks?: boolean;
|
|
117
|
+
selection?: boolean;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Unstable properties
|
|
121
|
+
|
|
122
|
+
/** Returns additional changes before applying edits to a record of this entity. */
|
|
123
|
+
__unstablePrePersist?: ( record: R, edits: Edit[] ) => Edit[];
|
|
124
|
+
|
|
125
|
+
/** Used in `canEdit()` */
|
|
126
|
+
__unstable_rest_base?: string;
|
|
127
|
+
}
|
|
@@ -7,7 +7,6 @@ import type { Comment } from './comment';
|
|
|
7
7
|
import type { MenuLocation } from './menu-location';
|
|
8
8
|
import type { NavMenu } from './nav-menu';
|
|
9
9
|
import type { NavMenuItem } from './nav-menu-item';
|
|
10
|
-
import type { NavigationArea } from './navigation-area';
|
|
11
10
|
import type { Page } from './page';
|
|
12
11
|
import type { Plugin } from './plugin';
|
|
13
12
|
import type { Post } from './post';
|
|
@@ -22,6 +21,7 @@ import type { WidgetType } from './widget-type';
|
|
|
22
21
|
import type { WpTemplate } from './wp-template';
|
|
23
22
|
import type { WpTemplatePart } from './wp-template-part';
|
|
24
23
|
|
|
24
|
+
export type { EntityType } from './entities';
|
|
25
25
|
export type { BaseEntityRecords } from './base-entity-records';
|
|
26
26
|
|
|
27
27
|
export type {
|
|
@@ -31,7 +31,6 @@ export type {
|
|
|
31
31
|
MenuLocation,
|
|
32
32
|
NavMenu,
|
|
33
33
|
NavMenuItem,
|
|
34
|
-
NavigationArea,
|
|
35
34
|
Page,
|
|
36
35
|
Plugin,
|
|
37
36
|
Post,
|
|
@@ -54,7 +53,6 @@ export type EntityRecord< C extends Context > =
|
|
|
54
53
|
| MenuLocation< C >
|
|
55
54
|
| NavMenu< C >
|
|
56
55
|
| NavMenuItem< C >
|
|
57
|
-
| NavigationArea< C >
|
|
58
56
|
| Page< C >
|
|
59
57
|
| Plugin< C >
|
|
60
58
|
| Post< C >
|
package/src/hooks/constants.ts
CHANGED