@wordpress/core-data 4.2.1 → 4.3.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 +5 -0
- package/README.md +41 -8
- package/build/actions.js +61 -41
- package/build/actions.js.map +1 -1
- package/build/entities.js +36 -23
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js +46 -44
- package/build/entity-provider.js.map +1 -1
- package/build/entity-types/{base-entity-types.js → base-entity-records.js} +9 -9
- package/build/entity-types/base-entity-records.js.map +1 -0
- package/build/fetch/__experimental-fetch-link-suggestions.js +1 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/fetch/__experimental-fetch-url-data.js +1 -1
- package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build/hooks/use-entity-record.js +15 -5
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +17 -5
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/index.js +9 -21
- package/build/index.js.map +1 -1
- package/build/queried-data/actions.js +4 -4
- package/build/queried-data/actions.js.map +1 -1
- package/build/queried-data/get-query-parts.js +7 -3
- package/build/queried-data/get-query-parts.js.map +1 -1
- package/build/queried-data/reducer.js +8 -6
- package/build/queried-data/reducer.js.map +1 -1
- package/build/reducer.js +16 -16
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +17 -23
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +92 -51
- package/build/selectors.js.map +1 -1
- package/build/utils/conservative-map-item.js +1 -1
- package/build/utils/conservative-map-item.js.map +1 -1
- package/build/utils/is-raw-attribute.js +1 -1
- package/build/utils/is-raw-attribute.js.map +1 -1
- package/build-module/actions.js +62 -42
- package/build-module/actions.js.map +1 -1
- package/build-module/entities.js +32 -19
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js +47 -45
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/entity-types/{base-entity-types.js → base-entity-records.js} +7 -7
- package/build-module/entity-types/base-entity-records.js.map +1 -0
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +1 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +15 -5
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +17 -5
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/index.js +10 -22
- package/build-module/index.js.map +1 -1
- package/build-module/queried-data/actions.js +4 -4
- package/build-module/queried-data/actions.js.map +1 -1
- package/build-module/queried-data/get-query-parts.js +7 -3
- package/build-module/queried-data/get-query-parts.js.map +1 -1
- package/build-module/queried-data/reducer.js +8 -6
- package/build-module/queried-data/reducer.js.map +1 -1
- package/build-module/reducer.js +17 -17
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +18 -24
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +88 -51
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/conservative-map-item.js +1 -1
- package/build-module/utils/conservative-map-item.js.map +1 -1
- package/build-module/utils/is-raw-attribute.js +1 -1
- package/build-module/utils/is-raw-attribute.js.map +1 -1
- package/package.json +11 -11
- package/src/actions.js +62 -42
- package/src/entities.js +43 -17
- package/src/entity-provider.js +50 -44
- package/src/entity-types/attachment.ts +5 -5
- package/src/entity-types/{base-entity-types.ts → base-entity-records.ts} +5 -5
- package/src/entity-types/comment.ts +5 -5
- package/src/entity-types/helpers.ts +1 -1
- package/src/entity-types/index.ts +4 -4
- package/src/entity-types/menu-location.ts +5 -5
- package/src/entity-types/nav-menu-item.ts +10 -5
- package/src/entity-types/nav-menu.ts +5 -5
- package/src/entity-types/navigation-area.ts +5 -5
- package/src/entity-types/page.ts +5 -5
- package/src/entity-types/plugin.ts +10 -5
- package/src/entity-types/post.ts +5 -5
- package/src/entity-types/settings.ts +10 -5
- package/src/entity-types/sidebar.ts +6 -7
- package/src/entity-types/taxonomy.ts +5 -5
- package/src/entity-types/theme.ts +5 -5
- package/src/entity-types/type.ts +5 -5
- package/src/entity-types/user.ts +10 -5
- package/src/entity-types/widget-type.ts +5 -5
- package/src/entity-types/widget.ts +5 -5
- package/src/entity-types/wp-template-part.ts +5 -5
- package/src/entity-types/wp-template.ts +5 -5
- package/src/fetch/__experimental-fetch-link-suggestions.js +1 -1
- package/src/fetch/__experimental-fetch-url-data.js +1 -0
- package/src/hooks/use-entity-record.ts +19 -8
- package/src/hooks/use-entity-records.ts +26 -9
- package/src/index.js +10 -15
- package/src/locks/test/selectors.js +4 -4
- package/src/queried-data/actions.js +4 -4
- package/src/queried-data/get-query-parts.js +5 -5
- package/src/queried-data/reducer.js +6 -6
- package/src/reducer.js +17 -17
- package/src/resolvers.js +25 -30
- package/src/selectors.js +92 -53
- package/src/test/actions.js +138 -33
- package/src/test/entities.js +11 -11
- package/src/test/reducer.js +4 -4
- package/src/test/resolvers.js +5 -5
- package/src/test/selectors.js +22 -22
- package/src/utils/conservative-map-item.js +1 -1
- package/src/utils/is-raw-attribute.js +1 -1
- package/src/utils/test/is-raw-attribute.js +4 -4
- package/build/entity-types/base-entity-types.js.map +0 -1
- package/build-module/entity-types/base-entity-types.js.map +0 -1
package/src/entities.js
CHANGED
|
@@ -18,12 +18,25 @@ export const DEFAULT_ENTITY_KEY = 'id';
|
|
|
18
18
|
|
|
19
19
|
const POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];
|
|
20
20
|
|
|
21
|
-
export const
|
|
21
|
+
export const rootEntitiesConfig = [
|
|
22
22
|
{
|
|
23
23
|
label: __( 'Base' ),
|
|
24
24
|
name: '__unstableBase',
|
|
25
25
|
kind: 'root',
|
|
26
26
|
baseURL: '/',
|
|
27
|
+
baseURLParams: {
|
|
28
|
+
_fields: [
|
|
29
|
+
'description',
|
|
30
|
+
'gmt_offset',
|
|
31
|
+
'home',
|
|
32
|
+
'name',
|
|
33
|
+
'site_icon',
|
|
34
|
+
'site_icon_url',
|
|
35
|
+
'site_logo',
|
|
36
|
+
'timezone_string',
|
|
37
|
+
'url',
|
|
38
|
+
].join( ',' ),
|
|
39
|
+
},
|
|
27
40
|
},
|
|
28
41
|
{
|
|
29
42
|
label: __( 'Site' ),
|
|
@@ -50,6 +63,7 @@ export const defaultEntities = [
|
|
|
50
63
|
baseURLParams: { context: 'edit' },
|
|
51
64
|
plural: 'mediaItems',
|
|
52
65
|
label: __( 'Media' ),
|
|
66
|
+
rawAttributes: [ 'caption', 'title', 'description' ],
|
|
53
67
|
},
|
|
54
68
|
{
|
|
55
69
|
name: 'taxonomy',
|
|
@@ -164,9 +178,9 @@ export const defaultEntities = [
|
|
|
164
178
|
},
|
|
165
179
|
];
|
|
166
180
|
|
|
167
|
-
export const
|
|
168
|
-
{
|
|
169
|
-
{
|
|
181
|
+
export const additionalEntityConfigLoaders = [
|
|
182
|
+
{ kind: 'postType', loadEntities: loadPostTypeEntities },
|
|
183
|
+
{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },
|
|
170
184
|
];
|
|
171
185
|
|
|
172
186
|
/**
|
|
@@ -257,6 +271,15 @@ async function loadTaxonomyEntities() {
|
|
|
257
271
|
/**
|
|
258
272
|
* Returns the entity's getter method name given its kind and name.
|
|
259
273
|
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```js
|
|
276
|
+
* const nameSingular = getMethodName( 'root', 'theme', 'get' );
|
|
277
|
+
* // nameSingular is getRootTheme
|
|
278
|
+
*
|
|
279
|
+
* const namePlural = getMethodName( 'root', 'theme', 'set' );
|
|
280
|
+
* // namePlural is setRootThemes
|
|
281
|
+
* ```
|
|
282
|
+
*
|
|
260
283
|
* @param {string} kind Entity kind.
|
|
261
284
|
* @param {string} name Entity name.
|
|
262
285
|
* @param {string} prefix Function prefix.
|
|
@@ -270,13 +293,13 @@ export const getMethodName = (
|
|
|
270
293
|
prefix = 'get',
|
|
271
294
|
usePlural = false
|
|
272
295
|
) => {
|
|
273
|
-
const
|
|
296
|
+
const entityConfig = find( rootEntitiesConfig, { kind, name } );
|
|
274
297
|
const kindPrefix = kind === 'root' ? '' : upperFirst( camelCase( kind ) );
|
|
275
298
|
const nameSuffix =
|
|
276
299
|
upperFirst( camelCase( name ) ) + ( usePlural ? 's' : '' );
|
|
277
300
|
const suffix =
|
|
278
|
-
usePlural &&
|
|
279
|
-
? upperFirst( camelCase(
|
|
301
|
+
usePlural && entityConfig?.plural
|
|
302
|
+
? upperFirst( camelCase( entityConfig.plural ) )
|
|
280
303
|
: nameSuffix;
|
|
281
304
|
return `${ prefix }${ kindPrefix }${ suffix }`;
|
|
282
305
|
};
|
|
@@ -286,21 +309,24 @@ export const getMethodName = (
|
|
|
286
309
|
*
|
|
287
310
|
* @param {string} kind Kind
|
|
288
311
|
*
|
|
289
|
-
* @return {Array} Entities
|
|
312
|
+
* @return {(thunkArgs: object) => Promise<Array>} Entities
|
|
290
313
|
*/
|
|
291
|
-
export const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
314
|
+
export const getOrLoadEntitiesConfig = ( kind ) => async ( {
|
|
315
|
+
select,
|
|
316
|
+
dispatch,
|
|
317
|
+
} ) => {
|
|
318
|
+
let configs = select.getEntitiesConfig( kind );
|
|
319
|
+
if ( configs && configs.length !== 0 ) {
|
|
320
|
+
return configs;
|
|
295
321
|
}
|
|
296
322
|
|
|
297
|
-
const
|
|
298
|
-
if ( !
|
|
323
|
+
const loader = find( additionalEntityConfigLoaders, { kind } );
|
|
324
|
+
if ( ! loader ) {
|
|
299
325
|
return [];
|
|
300
326
|
}
|
|
301
327
|
|
|
302
|
-
|
|
303
|
-
dispatch( addEntities(
|
|
328
|
+
configs = await loader.loadEntities();
|
|
329
|
+
dispatch( addEntities( configs ) );
|
|
304
330
|
|
|
305
|
-
return
|
|
331
|
+
return configs;
|
|
306
332
|
};
|
package/src/entity-provider.js
CHANGED
|
@@ -15,53 +15,59 @@ import { parse, __unstableSerializeAndClean } from '@wordpress/blocks';
|
|
|
15
15
|
*/
|
|
16
16
|
import { STORE_NAME } from './name';
|
|
17
17
|
|
|
18
|
+
/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */
|
|
19
|
+
|
|
18
20
|
const EMPTY_ARRAY = [];
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Internal dependencies
|
|
22
24
|
*/
|
|
23
|
-
import {
|
|
25
|
+
import { rootEntitiesConfig, additionalEntityConfigLoaders } from './entities';
|
|
24
26
|
|
|
25
|
-
const
|
|
26
|
-
...
|
|
27
|
-
if ( ! acc[
|
|
28
|
-
acc[
|
|
27
|
+
const entityContexts = {
|
|
28
|
+
...rootEntitiesConfig.reduce( ( acc, loader ) => {
|
|
29
|
+
if ( ! acc[ loader.kind ] ) {
|
|
30
|
+
acc[ loader.kind ] = {};
|
|
29
31
|
}
|
|
30
|
-
acc[
|
|
32
|
+
acc[ loader.kind ][ loader.name ] = {
|
|
33
|
+
context: createContext( undefined ),
|
|
34
|
+
};
|
|
31
35
|
return acc;
|
|
32
36
|
}, {} ),
|
|
33
|
-
...
|
|
34
|
-
acc[ kind
|
|
37
|
+
...additionalEntityConfigLoaders.reduce( ( acc, loader ) => {
|
|
38
|
+
acc[ loader.kind ] = {};
|
|
35
39
|
return acc;
|
|
36
40
|
}, {} ),
|
|
37
41
|
};
|
|
38
|
-
const
|
|
39
|
-
if ( !
|
|
42
|
+
const getEntityContext = ( kind, name ) => {
|
|
43
|
+
if ( ! entityContexts[ kind ] ) {
|
|
40
44
|
throw new Error( `Missing entity config for kind: ${ kind }.` );
|
|
41
45
|
}
|
|
42
46
|
|
|
43
|
-
if ( !
|
|
44
|
-
|
|
47
|
+
if ( ! entityContexts[ kind ][ name ] ) {
|
|
48
|
+
entityContexts[ kind ][ name ] = {
|
|
49
|
+
context: createContext( undefined ),
|
|
50
|
+
};
|
|
45
51
|
}
|
|
46
52
|
|
|
47
|
-
return
|
|
53
|
+
return entityContexts[ kind ][ name ].context;
|
|
48
54
|
};
|
|
49
55
|
|
|
50
56
|
/**
|
|
51
57
|
* Context provider component for providing
|
|
52
|
-
* an entity for a specific entity
|
|
58
|
+
* an entity for a specific entity.
|
|
53
59
|
*
|
|
54
60
|
* @param {Object} props The component's props.
|
|
55
61
|
* @param {string} props.kind The entity kind.
|
|
56
|
-
* @param {string} props.type The entity
|
|
62
|
+
* @param {string} props.type The entity name.
|
|
57
63
|
* @param {number} props.id The entity ID.
|
|
58
64
|
* @param {*} props.children The children to wrap.
|
|
59
65
|
*
|
|
60
66
|
* @return {Object} The provided children, wrapped with
|
|
61
67
|
* the entity's context provider.
|
|
62
68
|
*/
|
|
63
|
-
export default function EntityProvider( { kind, type, id, children } ) {
|
|
64
|
-
const Provider =
|
|
69
|
+
export default function EntityProvider( { kind, type: name, id, children } ) {
|
|
70
|
+
const Provider = getEntityContext( kind, name ).Provider;
|
|
65
71
|
return <Provider value={ id }>{ children }</Provider>;
|
|
66
72
|
}
|
|
67
73
|
|
|
@@ -70,10 +76,10 @@ export default function EntityProvider( { kind, type, id, children } ) {
|
|
|
70
76
|
* provided entity of the specified type.
|
|
71
77
|
*
|
|
72
78
|
* @param {string} kind The entity kind.
|
|
73
|
-
* @param {string}
|
|
79
|
+
* @param {string} name The entity name.
|
|
74
80
|
*/
|
|
75
|
-
export function useEntityId( kind,
|
|
76
|
-
return useContext(
|
|
81
|
+
export function useEntityId( kind, name ) {
|
|
82
|
+
return useContext( getEntityContext( kind, name ) );
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
/**
|
|
@@ -82,7 +88,7 @@ export function useEntityId( kind, type ) {
|
|
|
82
88
|
* entity of the specified type.
|
|
83
89
|
*
|
|
84
90
|
* @param {string} kind The entity kind.
|
|
85
|
-
* @param {string}
|
|
91
|
+
* @param {string} name The entity name.
|
|
86
92
|
* @param {string} prop The property name.
|
|
87
93
|
* @param {string} [_id] An entity ID to use instead of the context-provided one.
|
|
88
94
|
*
|
|
@@ -93,8 +99,8 @@ export function useEntityId( kind, type ) {
|
|
|
93
99
|
* information like `raw`, `rendered` and
|
|
94
100
|
* `protected` props.
|
|
95
101
|
*/
|
|
96
|
-
export function useEntityProp( kind,
|
|
97
|
-
const providerId = useEntityId( kind,
|
|
102
|
+
export function useEntityProp( kind, name, prop, _id ) {
|
|
103
|
+
const providerId = useEntityId( kind, name );
|
|
98
104
|
const id = _id ?? providerId;
|
|
99
105
|
|
|
100
106
|
const { value, fullValue } = useSelect(
|
|
@@ -102,25 +108,25 @@ export function useEntityProp( kind, type, prop, _id ) {
|
|
|
102
108
|
const { getEntityRecord, getEditedEntityRecord } = select(
|
|
103
109
|
STORE_NAME
|
|
104
110
|
);
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
return
|
|
111
|
+
const record = getEntityRecord( kind, name, id ); // Trigger resolver.
|
|
112
|
+
const editedRecord = getEditedEntityRecord( kind, name, id );
|
|
113
|
+
return record && editedRecord
|
|
108
114
|
? {
|
|
109
|
-
value:
|
|
110
|
-
fullValue:
|
|
115
|
+
value: editedRecord[ prop ],
|
|
116
|
+
fullValue: record[ prop ],
|
|
111
117
|
}
|
|
112
118
|
: {};
|
|
113
119
|
},
|
|
114
|
-
[ kind,
|
|
120
|
+
[ kind, name, id, prop ]
|
|
115
121
|
);
|
|
116
122
|
const { editEntityRecord } = useDispatch( STORE_NAME );
|
|
117
123
|
const setValue = useCallback(
|
|
118
124
|
( newValue ) => {
|
|
119
|
-
editEntityRecord( kind,
|
|
125
|
+
editEntityRecord( kind, name, id, {
|
|
120
126
|
[ prop ]: newValue,
|
|
121
127
|
} );
|
|
122
128
|
},
|
|
123
|
-
[ kind,
|
|
129
|
+
[ kind, name, id, prop ]
|
|
124
130
|
);
|
|
125
131
|
|
|
126
132
|
return [ value, setValue, fullValue ];
|
|
@@ -138,25 +144,25 @@ export function useEntityProp( kind, type, prop, _id ) {
|
|
|
138
144
|
* or similar components or hooks.
|
|
139
145
|
*
|
|
140
146
|
* @param {string} kind The entity kind.
|
|
141
|
-
* @param {string}
|
|
147
|
+
* @param {string} name The entity name.
|
|
142
148
|
* @param {Object} options
|
|
143
149
|
* @param {string} [options.id] An entity ID to use instead of the context-provided one.
|
|
144
150
|
*
|
|
145
151
|
* @return {[WPBlock[], Function, Function]} The block array and setters.
|
|
146
152
|
*/
|
|
147
|
-
export function useEntityBlockEditor( kind,
|
|
148
|
-
const providerId = useEntityId( kind,
|
|
153
|
+
export function useEntityBlockEditor( kind, name, { id: _id } = {} ) {
|
|
154
|
+
const providerId = useEntityId( kind, name );
|
|
149
155
|
const id = _id ?? providerId;
|
|
150
156
|
const { content, blocks } = useSelect(
|
|
151
157
|
( select ) => {
|
|
152
158
|
const { getEditedEntityRecord } = select( STORE_NAME );
|
|
153
|
-
const
|
|
159
|
+
const editedRecord = getEditedEntityRecord( kind, name, id );
|
|
154
160
|
return {
|
|
155
|
-
blocks:
|
|
156
|
-
content:
|
|
161
|
+
blocks: editedRecord.blocks,
|
|
162
|
+
content: editedRecord.content,
|
|
157
163
|
};
|
|
158
164
|
},
|
|
159
|
-
[ kind,
|
|
165
|
+
[ kind, name, id ]
|
|
160
166
|
);
|
|
161
167
|
const { __unstableCreateUndoLevel, editEntityRecord } = useDispatch(
|
|
162
168
|
STORE_NAME
|
|
@@ -170,7 +176,7 @@ export function useEntityBlockEditor( kind, type, { id: _id } = {} ) {
|
|
|
170
176
|
const parsedContent = parse( content );
|
|
171
177
|
editEntityRecord(
|
|
172
178
|
kind,
|
|
173
|
-
|
|
179
|
+
name,
|
|
174
180
|
id,
|
|
175
181
|
{
|
|
176
182
|
blocks: parsedContent,
|
|
@@ -187,7 +193,7 @@ export function useEntityBlockEditor( kind, type, { id: _id } = {} ) {
|
|
|
187
193
|
|
|
188
194
|
const noChange = blocks === edits.blocks;
|
|
189
195
|
if ( noChange ) {
|
|
190
|
-
return __unstableCreateUndoLevel( kind,
|
|
196
|
+
return __unstableCreateUndoLevel( kind, name, id );
|
|
191
197
|
}
|
|
192
198
|
|
|
193
199
|
// We create a new function here on every persistent edit
|
|
@@ -196,18 +202,18 @@ export function useEntityBlockEditor( kind, type, { id: _id } = {} ) {
|
|
|
196
202
|
edits.content = ( { blocks: blocksForSerialization = [] } ) =>
|
|
197
203
|
__unstableSerializeAndClean( blocksForSerialization );
|
|
198
204
|
|
|
199
|
-
editEntityRecord( kind,
|
|
205
|
+
editEntityRecord( kind, name, id, edits );
|
|
200
206
|
},
|
|
201
|
-
[ kind,
|
|
207
|
+
[ kind, name, id, blocks ]
|
|
202
208
|
);
|
|
203
209
|
|
|
204
210
|
const onInput = useCallback(
|
|
205
211
|
( newBlocks, options ) => {
|
|
206
212
|
const { selection } = options;
|
|
207
213
|
const edits = { blocks: newBlocks, selection };
|
|
208
|
-
editEntityRecord( kind,
|
|
214
|
+
editEntityRecord( kind, name, id, edits );
|
|
209
215
|
},
|
|
210
|
-
[ kind,
|
|
216
|
+
[ kind, name, id ]
|
|
211
217
|
);
|
|
212
218
|
|
|
213
219
|
return [ blocks ?? EMPTY_ARRAY, onInput, onChange ];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import type {
|
|
5
5
|
Context,
|
|
6
6
|
ContextualField,
|
|
7
7
|
MediaType,
|
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
PingStatus,
|
|
13
13
|
} from './helpers';
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
|
|
16
16
|
|
|
17
|
-
declare module './base-entity-
|
|
18
|
-
export namespace
|
|
17
|
+
declare module './base-entity-records' {
|
|
18
|
+
export namespace BaseEntityRecords {
|
|
19
19
|
export interface Attachment< C extends Context > {
|
|
20
20
|
/**
|
|
21
21
|
* The date the post was published, in the site's timezone.
|
|
@@ -142,5 +142,5 @@ declare module './base-entity-types' {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
export type Attachment< C extends Context > = OmitNevers<
|
|
145
|
-
|
|
145
|
+
_BaseEntityRecords.Attachment< C >
|
|
146
146
|
>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This module exists solely to make the
|
|
2
|
+
* This module exists solely to make the BaseEntityRecords namespace extensible
|
|
3
3
|
* with declaration merging:
|
|
4
4
|
*
|
|
5
5
|
* ```ts
|
|
6
|
-
* declare module './base-entity-
|
|
7
|
-
* export namespace
|
|
6
|
+
* declare module './base-entity-records' {
|
|
7
|
+
* export namespace BaseEntityRecords {
|
|
8
8
|
* export interface Comment< C extends Context > {
|
|
9
9
|
* id: number;
|
|
10
10
|
* // ...
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* ```ts
|
|
20
20
|
* import type { Context } from '@wordpress/core-data';
|
|
21
21
|
* declare module '@wordpress/core-data' {
|
|
22
|
-
* export namespace
|
|
22
|
+
* export namespace BaseEntityRecords {
|
|
23
23
|
* export interface Comment< C extends Context > {
|
|
24
24
|
* numberOfViews: number;
|
|
25
25
|
* }
|
|
@@ -33,4 +33,4 @@
|
|
|
33
33
|
* // c.id is still present
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
export namespace
|
|
36
|
+
export namespace BaseEntityRecords {}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import type {
|
|
5
5
|
AvatarUrls,
|
|
6
6
|
Context,
|
|
7
7
|
ContextualField,
|
|
8
8
|
OmitNevers,
|
|
9
9
|
RenderedText,
|
|
10
10
|
} from './helpers';
|
|
11
|
-
import {
|
|
11
|
+
import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
|
|
12
12
|
|
|
13
13
|
export type CommentStatus = 'hold' | 'approve' | 'spam' | 'trash' | '1' | '0';
|
|
14
14
|
|
|
15
|
-
declare module './base-entity-
|
|
16
|
-
export namespace
|
|
15
|
+
declare module './base-entity-records' {
|
|
16
|
+
export namespace BaseEntityRecords {
|
|
17
17
|
export interface Comment< C extends Context > {
|
|
18
18
|
/**
|
|
19
19
|
* Unique identifier for the comment.
|
|
@@ -92,5 +92,5 @@ declare module './base-entity-types' {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
export type Comment< C extends Context > = OmitNevers<
|
|
95
|
-
|
|
95
|
+
_BaseEntityRecords.Comment< C >
|
|
96
96
|
>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
+
import type { Context, Updatable } from './helpers';
|
|
4
5
|
import type { Attachment } from './attachment';
|
|
5
6
|
import type { Comment } from './comment';
|
|
6
7
|
import type { MenuLocation } from './menu-location';
|
|
@@ -20,15 +21,13 @@ import type { Widget } from './widget';
|
|
|
20
21
|
import type { WidgetType } from './widget-type';
|
|
21
22
|
import type { WpTemplate } from './wp-template';
|
|
22
23
|
import type { WpTemplatePart } from './wp-template-part';
|
|
23
|
-
import type { Context, Updatable } from './helpers';
|
|
24
24
|
|
|
25
|
-
export type {
|
|
25
|
+
export type { BaseEntityRecords } from './base-entity-records';
|
|
26
26
|
|
|
27
27
|
export type {
|
|
28
|
-
Context,
|
|
29
|
-
Updatable,
|
|
30
28
|
Attachment,
|
|
31
29
|
Comment,
|
|
30
|
+
Context,
|
|
32
31
|
MenuLocation,
|
|
33
32
|
NavMenu,
|
|
34
33
|
NavMenuItem,
|
|
@@ -40,6 +39,7 @@ export type {
|
|
|
40
39
|
Sidebar,
|
|
41
40
|
Taxonomy,
|
|
42
41
|
Theme,
|
|
42
|
+
Updatable,
|
|
43
43
|
User,
|
|
44
44
|
Type,
|
|
45
45
|
Widget,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { Context, OmitNevers } from './helpers';
|
|
4
|
+
import type { Context, OmitNevers } from './helpers';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
|
|
7
7
|
|
|
8
|
-
declare module './base-entity-
|
|
9
|
-
export namespace
|
|
8
|
+
declare module './base-entity-records' {
|
|
9
|
+
export namespace BaseEntityRecords {
|
|
10
10
|
export interface MenuLocation< C extends Context > {
|
|
11
11
|
/**
|
|
12
12
|
* The name of the menu location.
|
|
@@ -25,5 +25,5 @@ declare module './base-entity-types' {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export type MenuLocation< C extends Context > = OmitNevers<
|
|
28
|
-
|
|
28
|
+
_BaseEntityRecords.MenuLocation< C >
|
|
29
29
|
>;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import type {
|
|
5
|
+
RenderedText,
|
|
6
|
+
Context,
|
|
7
|
+
ContextualField,
|
|
8
|
+
OmitNevers,
|
|
9
|
+
} from './helpers';
|
|
5
10
|
|
|
6
|
-
import {
|
|
11
|
+
import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
|
|
7
12
|
|
|
8
13
|
export type NavMenuItemType =
|
|
9
14
|
| 'taxonomy'
|
|
@@ -18,8 +23,8 @@ export type NavMenuItemStatus =
|
|
|
18
23
|
| 'private';
|
|
19
24
|
export type Target = '_blank' | '';
|
|
20
25
|
|
|
21
|
-
declare module './base-entity-
|
|
22
|
-
export namespace
|
|
26
|
+
declare module './base-entity-records' {
|
|
27
|
+
export namespace BaseEntityRecords {
|
|
23
28
|
export interface NavMenuItem< C extends Context > {
|
|
24
29
|
/**
|
|
25
30
|
* The title for the object.
|
|
@@ -102,5 +107,5 @@ declare module './base-entity-types' {
|
|
|
102
107
|
}
|
|
103
108
|
|
|
104
109
|
export type NavMenuItem< C extends Context > = OmitNevers<
|
|
105
|
-
|
|
110
|
+
_BaseEntityRecords.NavMenuItem< C >
|
|
106
111
|
>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { Context, ContextualField, OmitNevers } from './helpers';
|
|
4
|
+
import type { Context, ContextualField, OmitNevers } from './helpers';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
|
|
7
7
|
|
|
8
|
-
declare module './base-entity-
|
|
9
|
-
export namespace
|
|
8
|
+
declare module './base-entity-records' {
|
|
9
|
+
export namespace BaseEntityRecords {
|
|
10
10
|
export interface NavMenu< C extends Context > {
|
|
11
11
|
/**
|
|
12
12
|
* Unique identifier for the term.
|
|
@@ -49,5 +49,5 @@ declare module './base-entity-types' {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
export type NavMenu< C extends Context > = OmitNevers<
|
|
52
|
-
|
|
52
|
+
_BaseEntityRecords.NavMenu< C >
|
|
53
53
|
>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { Context, OmitNevers } from './helpers';
|
|
4
|
+
import type { Context, OmitNevers } from './helpers';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
|
|
7
7
|
|
|
8
|
-
declare module './base-entity-
|
|
9
|
-
export namespace
|
|
8
|
+
declare module './base-entity-records' {
|
|
9
|
+
export namespace BaseEntityRecords {
|
|
10
10
|
export interface NavigationArea< C extends Context > {
|
|
11
11
|
/**
|
|
12
12
|
* The name of the navigation area.
|
|
@@ -25,5 +25,5 @@ declare module './base-entity-types' {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export type NavigationArea< C extends Context > = OmitNevers<
|
|
28
|
-
|
|
28
|
+
_BaseEntityRecords.NavigationArea< C >
|
|
29
29
|
>;
|
package/src/entity-types/page.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import type {
|
|
5
5
|
CommentingStatus,
|
|
6
6
|
Context,
|
|
7
7
|
ContextualField,
|
|
@@ -11,10 +11,10 @@ import {
|
|
|
11
11
|
OmitNevers,
|
|
12
12
|
} from './helpers';
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
|
|
15
15
|
|
|
16
|
-
declare module './base-entity-
|
|
17
|
-
export namespace
|
|
16
|
+
declare module './base-entity-records' {
|
|
17
|
+
export namespace BaseEntityRecords {
|
|
18
18
|
export interface Page< C extends Context > {
|
|
19
19
|
/**
|
|
20
20
|
* The date the post was published, in the site's timezone.
|
|
@@ -140,5 +140,5 @@ declare module './base-entity-types' {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
export type Page< C extends Context > = OmitNevers<
|
|
143
|
-
|
|
143
|
+
_BaseEntityRecords.Page< C >
|
|
144
144
|
>;
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import type {
|
|
5
|
+
Context,
|
|
6
|
+
ContextualField,
|
|
7
|
+
RenderedText,
|
|
8
|
+
OmitNevers,
|
|
9
|
+
} from './helpers';
|
|
5
10
|
|
|
6
|
-
import {
|
|
11
|
+
import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
|
|
7
12
|
|
|
8
|
-
declare module './base-entity-
|
|
9
|
-
export namespace
|
|
13
|
+
declare module './base-entity-records' {
|
|
14
|
+
export namespace BaseEntityRecords {
|
|
10
15
|
export interface Plugin< C extends Context > {
|
|
11
16
|
/**
|
|
12
17
|
* The plugin file.
|
|
@@ -70,5 +75,5 @@ declare module './base-entity-types' {
|
|
|
70
75
|
|
|
71
76
|
export type PluginStatus = 'active' | 'inactive';
|
|
72
77
|
export type Plugin< C extends Context > = OmitNevers<
|
|
73
|
-
|
|
78
|
+
_BaseEntityRecords.Plugin< C >
|
|
74
79
|
>;
|
package/src/entity-types/post.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import type {
|
|
5
5
|
CommentingStatus,
|
|
6
6
|
Context,
|
|
7
7
|
ContextualField,
|
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
OmitNevers,
|
|
13
13
|
} from './helpers';
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
|
|
16
16
|
|
|
17
|
-
declare module './base-entity-
|
|
18
|
-
export namespace
|
|
17
|
+
declare module './base-entity-records' {
|
|
18
|
+
export namespace BaseEntityRecords {
|
|
19
19
|
export interface Post< C extends Context > {
|
|
20
20
|
/**
|
|
21
21
|
* The date the post was published, in the site's timezone.
|
|
@@ -149,5 +149,5 @@ declare module './base-entity-types' {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
export type Post< C extends Context > = OmitNevers<
|
|
152
|
-
|
|
152
|
+
_BaseEntityRecords.Post< C >
|
|
153
153
|
>;
|