@wordpress/core-data 4.1.1 → 4.2.0-next.e230fbab09.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/README.md +2 -10
- package/build/actions.js +9 -13
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +17 -12
- package/build/batch/create-batch.js.map +1 -1
- package/build/entities.js +1 -1
- package/build/entities.js.map +1 -1
- package/build/entity-types/attachment.js +6 -0
- package/build/entity-types/attachment.js.map +1 -0
- package/build/entity-types/base-entity-types.js +47 -0
- package/build/entity-types/base-entity-types.js.map +1 -0
- package/build/entity-types/comment.js +6 -0
- package/build/entity-types/comment.js.map +1 -0
- package/build/entity-types/helpers.js +6 -0
- package/build/entity-types/helpers.js.map +1 -0
- package/build/entity-types/index.js +6 -0
- package/build/entity-types/index.js.map +1 -0
- package/build/entity-types/menu-location.js +6 -0
- package/build/entity-types/menu-location.js.map +1 -0
- package/build/entity-types/nav-menu-item.js +6 -0
- package/build/entity-types/nav-menu-item.js.map +1 -0
- package/build/entity-types/nav-menu.js +6 -0
- package/build/entity-types/nav-menu.js.map +1 -0
- package/build/entity-types/navigation-area.js +6 -0
- package/build/entity-types/navigation-area.js.map +1 -0
- package/build/entity-types/page.js +6 -0
- package/build/entity-types/page.js.map +1 -0
- package/build/entity-types/plugin.js +6 -0
- package/build/entity-types/plugin.js.map +1 -0
- package/build/entity-types/post.js +6 -0
- package/build/entity-types/post.js.map +1 -0
- package/build/entity-types/settings.js +6 -0
- package/build/entity-types/settings.js.map +1 -0
- package/build/entity-types/sidebar.js +6 -0
- package/build/entity-types/sidebar.js.map +1 -0
- package/build/entity-types/taxonomy.js +6 -0
- package/build/entity-types/taxonomy.js.map +1 -0
- package/build/entity-types/theme.js +6 -0
- package/build/entity-types/theme.js.map +1 -0
- package/build/entity-types/type.js +6 -0
- package/build/entity-types/type.js.map +1 -0
- package/build/entity-types/user.js +6 -0
- package/build/entity-types/user.js.map +1 -0
- package/build/entity-types/widget-type.js +6 -0
- package/build/entity-types/widget-type.js.map +1 -0
- package/build/entity-types/widget.js +6 -0
- package/build/entity-types/widget.js.map +1 -0
- package/build/entity-types/wp-template-part.js +6 -0
- package/build/entity-types/wp-template-part.js.map +1 -0
- package/build/entity-types/wp-template.js +6 -0
- package/build/entity-types/wp-template.js.map +1 -0
- package/build/fetch/__experimental-fetch-link-suggestions.js +2 -2
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/hooks/constants.js +18 -0
- package/build/hooks/constants.js.map +1 -0
- package/build/hooks/memoize.js +18 -0
- package/build/hooks/memoize.js.map +1 -0
- package/build/hooks/use-entity-record.js +60 -0
- package/build/hooks/use-entity-record.js.map +1 -0
- package/build/hooks/use-entity-records.js +77 -0
- package/build/hooks/use-entity-records.js.map +1 -0
- package/build/hooks/use-query-select.js +130 -0
- package/build/hooks/use-query-select.js.map +1 -0
- package/build/index.js +34 -3
- package/build/index.js.map +1 -1
- package/build/reducer.js +1 -1
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +7 -17
- package/build/resolvers.js.map +1 -1
- package/build-module/actions.js +9 -13
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +17 -12
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/entities.js +1 -1
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-types/attachment.js +2 -0
- package/build-module/entity-types/attachment.js.map +1 -0
- package/build-module/entity-types/base-entity-types.js +39 -0
- package/build-module/entity-types/base-entity-types.js.map +1 -0
- package/build-module/entity-types/comment.js +2 -0
- package/build-module/entity-types/comment.js.map +1 -0
- package/build-module/entity-types/helpers.js +2 -0
- package/build-module/entity-types/helpers.js.map +1 -0
- package/build-module/entity-types/index.js +2 -0
- package/build-module/entity-types/index.js.map +1 -0
- package/build-module/entity-types/menu-location.js +2 -0
- package/build-module/entity-types/menu-location.js.map +1 -0
- package/build-module/entity-types/nav-menu-item.js +2 -0
- package/build-module/entity-types/nav-menu-item.js.map +1 -0
- package/build-module/entity-types/nav-menu.js +2 -0
- package/build-module/entity-types/nav-menu.js.map +1 -0
- package/build-module/entity-types/navigation-area.js +2 -0
- package/build-module/entity-types/navigation-area.js.map +1 -0
- package/build-module/entity-types/page.js +2 -0
- package/build-module/entity-types/page.js.map +1 -0
- package/build-module/entity-types/plugin.js +2 -0
- package/build-module/entity-types/plugin.js.map +1 -0
- package/build-module/entity-types/post.js +2 -0
- package/build-module/entity-types/post.js.map +1 -0
- package/build-module/entity-types/settings.js +2 -0
- package/build-module/entity-types/settings.js.map +1 -0
- package/build-module/entity-types/sidebar.js +2 -0
- package/build-module/entity-types/sidebar.js.map +1 -0
- package/build-module/entity-types/taxonomy.js +2 -0
- package/build-module/entity-types/taxonomy.js.map +1 -0
- package/build-module/entity-types/theme.js +2 -0
- package/build-module/entity-types/theme.js.map +1 -0
- package/build-module/entity-types/type.js +2 -0
- package/build-module/entity-types/type.js.map +1 -0
- package/build-module/entity-types/user.js +2 -0
- package/build-module/entity-types/user.js.map +1 -0
- package/build-module/entity-types/widget-type.js +2 -0
- package/build-module/entity-types/widget-type.js.map +1 -0
- package/build-module/entity-types/widget.js +2 -0
- package/build-module/entity-types/widget.js.map +1 -0
- package/build-module/entity-types/wp-template-part.js +2 -0
- package/build-module/entity-types/wp-template-part.js.map +1 -0
- package/build-module/entity-types/wp-template.js +2 -0
- package/build-module/entity-types/wp-template.js.map +1 -0
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +2 -2
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/hooks/constants.js +10 -0
- package/build-module/hooks/constants.js.map +1 -0
- package/build-module/hooks/memoize.js +7 -0
- package/build-module/hooks/memoize.js.map +1 -0
- package/build-module/hooks/use-entity-record.js +49 -0
- package/build-module/hooks/use-entity-record.js.map +1 -0
- package/build-module/hooks/use-entity-records.js +65 -0
- package/build-module/hooks/use-entity-records.js.map +1 -0
- package/build-module/hooks/use-query-select.js +116 -0
- package/build-module/hooks/use-query-select.js.map +1 -0
- package/build-module/index.js +4 -2
- package/build-module/index.js.map +1 -1
- package/build-module/reducer.js +1 -1
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +8 -18
- package/build-module/resolvers.js.map +1 -1
- package/package.json +15 -11
- package/src/actions.js +9 -13
- package/src/batch/create-batch.js +16 -12
- package/src/entities.js +1 -1
- package/src/entity-types/README.md +193 -0
- package/src/entity-types/attachment.ts +146 -0
- package/src/entity-types/base-entity-types.ts +36 -0
- package/src/entity-types/comment.ts +96 -0
- package/src/entity-types/helpers.ts +153 -0
- package/src/entity-types/index.ts +72 -0
- package/src/entity-types/menu-location.ts +29 -0
- package/src/entity-types/nav-menu-item.ts +106 -0
- package/src/entity-types/nav-menu.ts +53 -0
- package/src/entity-types/navigation-area.ts +29 -0
- package/src/entity-types/page.ts +144 -0
- package/src/entity-types/plugin.ts +74 -0
- package/src/entity-types/post.ts +153 -0
- package/src/entity-types/settings.ts +93 -0
- package/src/entity-types/sidebar.ts +60 -0
- package/src/entity-types/taxonomy.ts +92 -0
- package/src/entity-types/theme.ts +222 -0
- package/src/entity-types/type.ts +80 -0
- package/src/entity-types/user.ts +109 -0
- package/src/entity-types/widget-type.ts +37 -0
- package/src/entity-types/widget.ts +64 -0
- package/src/entity-types/wp-template-part.ts +94 -0
- package/src/entity-types/wp-template.ts +94 -0
- package/src/fetch/__experimental-fetch-link-suggestions.js +2 -2
- package/src/hooks/constants.ts +7 -0
- package/src/hooks/memoize.js +7 -0
- package/src/hooks/test/use-entity-record.js +74 -0
- package/src/hooks/test/use-entity-records.js +78 -0
- package/src/hooks/test/use-query-select.js +194 -0
- package/src/hooks/use-entity-record.ts +72 -0
- package/src/hooks/use-entity-records.ts +89 -0
- package/src/hooks/use-query-select.ts +131 -0
- package/src/index.js +3 -1
- package/src/locks/test/engine.js +13 -13
- package/src/locks/test/reducer.js +3 -3
- package/src/locks/test/utils.js +2 -2
- package/src/reducer.js +1 -1
- package/src/resolvers.js +6 -17
- package/src/test/resolvers.js +17 -23
- package/src/test/selectors.js +2 -3
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
Context,
|
|
6
|
+
ContextualField,
|
|
7
|
+
MediaType,
|
|
8
|
+
PostStatus,
|
|
9
|
+
RenderedText,
|
|
10
|
+
OmitNevers,
|
|
11
|
+
CommentingStatus,
|
|
12
|
+
PingStatus,
|
|
13
|
+
} from './helpers';
|
|
14
|
+
|
|
15
|
+
import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
|
|
16
|
+
|
|
17
|
+
declare module './base-entity-types' {
|
|
18
|
+
export namespace BaseEntityTypes {
|
|
19
|
+
export interface Attachment< C extends Context > {
|
|
20
|
+
/**
|
|
21
|
+
* The date the post was published, in the site's timezone.
|
|
22
|
+
*/
|
|
23
|
+
date: string | null;
|
|
24
|
+
/**
|
|
25
|
+
* The date the post was published, as GMT.
|
|
26
|
+
*/
|
|
27
|
+
date_gmt: ContextualField< string | null, 'view' | 'edit', C >;
|
|
28
|
+
/**
|
|
29
|
+
* The globally unique identifier for the post.
|
|
30
|
+
*/
|
|
31
|
+
guid: ContextualField< RenderedText< C >, 'view' | 'edit', C >;
|
|
32
|
+
/**
|
|
33
|
+
* Unique identifier for the post.
|
|
34
|
+
*/
|
|
35
|
+
id: number;
|
|
36
|
+
/**
|
|
37
|
+
* URL to the post.
|
|
38
|
+
*/
|
|
39
|
+
link: string;
|
|
40
|
+
/**
|
|
41
|
+
* The date the post was last modified, in the site's timezone.
|
|
42
|
+
*/
|
|
43
|
+
modified: ContextualField< string, 'view' | 'edit', C >;
|
|
44
|
+
/**
|
|
45
|
+
* The date the post was last modified, as GMT.
|
|
46
|
+
*/
|
|
47
|
+
modified_gmt: ContextualField< string, 'view' | 'edit', C >;
|
|
48
|
+
/**
|
|
49
|
+
* An alphanumeric identifier for the post unique to its type.
|
|
50
|
+
*/
|
|
51
|
+
slug: string;
|
|
52
|
+
/**
|
|
53
|
+
* A named status for the post.
|
|
54
|
+
*/
|
|
55
|
+
status: ContextualField< PostStatus, 'view' | 'edit', C >;
|
|
56
|
+
/**
|
|
57
|
+
* Type of post.
|
|
58
|
+
*/
|
|
59
|
+
type: string;
|
|
60
|
+
/**
|
|
61
|
+
* Permalink template for the post.
|
|
62
|
+
*/
|
|
63
|
+
permalink_template: ContextualField< string, 'edit', C >;
|
|
64
|
+
/**
|
|
65
|
+
* Slug automatically generated from the post title.
|
|
66
|
+
*/
|
|
67
|
+
generated_slug: ContextualField< string, 'edit', C >;
|
|
68
|
+
/**
|
|
69
|
+
* The title for the post.
|
|
70
|
+
*/
|
|
71
|
+
title: RenderedText< C >;
|
|
72
|
+
/**
|
|
73
|
+
* The ID for the author of the post.
|
|
74
|
+
*/
|
|
75
|
+
author: number;
|
|
76
|
+
/**
|
|
77
|
+
* Whether or not comments are open on the post.
|
|
78
|
+
*/
|
|
79
|
+
comment_status: ContextualField<
|
|
80
|
+
CommentingStatus,
|
|
81
|
+
'view' | 'edit',
|
|
82
|
+
C
|
|
83
|
+
>;
|
|
84
|
+
/**
|
|
85
|
+
* Whether or not the post can be pinged.
|
|
86
|
+
*/
|
|
87
|
+
ping_status: ContextualField< PingStatus, 'view' | 'edit', C >;
|
|
88
|
+
/**
|
|
89
|
+
* Meta fields.
|
|
90
|
+
*/
|
|
91
|
+
meta: ContextualField<
|
|
92
|
+
Record< string, string >,
|
|
93
|
+
'view' | 'edit',
|
|
94
|
+
C
|
|
95
|
+
>;
|
|
96
|
+
/**
|
|
97
|
+
* The theme file to use to display the post.
|
|
98
|
+
*/
|
|
99
|
+
template: ContextualField< string, 'view' | 'edit', C >;
|
|
100
|
+
/**
|
|
101
|
+
* Alternative text to display when attachment is not displayed.
|
|
102
|
+
*/
|
|
103
|
+
alt_text: string;
|
|
104
|
+
/**
|
|
105
|
+
* The attachment caption.
|
|
106
|
+
*/
|
|
107
|
+
caption: ContextualField< string, 'edit', C >;
|
|
108
|
+
/**
|
|
109
|
+
* The attachment description.
|
|
110
|
+
*/
|
|
111
|
+
description: ContextualField<
|
|
112
|
+
RenderedText< C >,
|
|
113
|
+
'view' | 'edit',
|
|
114
|
+
C
|
|
115
|
+
>;
|
|
116
|
+
/**
|
|
117
|
+
* Attachment type.
|
|
118
|
+
*/
|
|
119
|
+
media_type: MediaType;
|
|
120
|
+
/**
|
|
121
|
+
* The attachment MIME type.
|
|
122
|
+
*/
|
|
123
|
+
mime_type: string;
|
|
124
|
+
/**
|
|
125
|
+
* Details about the media file, specific to its type.
|
|
126
|
+
*/
|
|
127
|
+
media_details: Record< string, string >;
|
|
128
|
+
/**
|
|
129
|
+
* The ID for the associated post of the attachment.
|
|
130
|
+
*/
|
|
131
|
+
post: ContextualField< number, 'view' | 'edit', C >;
|
|
132
|
+
/**
|
|
133
|
+
* URL to the original attachment file.
|
|
134
|
+
*/
|
|
135
|
+
source_url: string;
|
|
136
|
+
/**
|
|
137
|
+
* List of the missing image sizes of the attachment.
|
|
138
|
+
*/
|
|
139
|
+
missing_image_sizes: ContextualField< string[], 'edit', C >;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export type Attachment< C extends Context > = OmitNevers<
|
|
145
|
+
_BaseEntityTypes.Attachment< C >
|
|
146
|
+
>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module exists solely to make the BaseEntityTypes namespace extensible
|
|
3
|
+
* with declaration merging:
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* declare module './base-entity-types' {
|
|
7
|
+
* export namespace BaseEntityTypes {
|
|
8
|
+
* export interface Comment< C extends Context > {
|
|
9
|
+
* id: number;
|
|
10
|
+
* // ...
|
|
11
|
+
* }
|
|
12
|
+
* }
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* The huge upside is that consumers of @wordpress/core-data may extend the
|
|
17
|
+
* exported data types using interface merging as follows:
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import type { Context } from '@wordpress/core-data';
|
|
21
|
+
* declare module '@wordpress/core-data' {
|
|
22
|
+
* export namespace BaseEntityTypes {
|
|
23
|
+
* export interface Comment< C extends Context > {
|
|
24
|
+
* numberOfViews: number;
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* import type { Comment } from '@wordpress/core-data';
|
|
30
|
+
* const c : Comment< 'view' > = ...;
|
|
31
|
+
*
|
|
32
|
+
* // c.numberOfViews is a number
|
|
33
|
+
* // c.id is still present
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export namespace BaseEntityTypes {}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
AvatarUrls,
|
|
6
|
+
Context,
|
|
7
|
+
ContextualField,
|
|
8
|
+
OmitNevers,
|
|
9
|
+
RenderedText,
|
|
10
|
+
} from './helpers';
|
|
11
|
+
import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
|
|
12
|
+
|
|
13
|
+
export type CommentStatus = 'hold' | 'approve' | 'spam' | 'trash' | '1' | '0';
|
|
14
|
+
|
|
15
|
+
declare module './base-entity-types' {
|
|
16
|
+
export namespace BaseEntityTypes {
|
|
17
|
+
export interface Comment< C extends Context > {
|
|
18
|
+
/**
|
|
19
|
+
* Unique identifier for the comment.
|
|
20
|
+
*/
|
|
21
|
+
id: number;
|
|
22
|
+
/**
|
|
23
|
+
* The ID of the user object, if author was a user.
|
|
24
|
+
*/
|
|
25
|
+
author: number;
|
|
26
|
+
/**
|
|
27
|
+
* Email address for the comment author.
|
|
28
|
+
*/
|
|
29
|
+
author_email: ContextualField< string, 'edit', C >;
|
|
30
|
+
/**
|
|
31
|
+
* IP address for the comment author.
|
|
32
|
+
*/
|
|
33
|
+
author_ip: ContextualField< string, 'edit', C >;
|
|
34
|
+
/**
|
|
35
|
+
* Display name for the comment author.
|
|
36
|
+
*/
|
|
37
|
+
author_name: string;
|
|
38
|
+
/**
|
|
39
|
+
* URL for the comment author.
|
|
40
|
+
*/
|
|
41
|
+
author_url: string;
|
|
42
|
+
/**
|
|
43
|
+
* User agent for the comment author.
|
|
44
|
+
*/
|
|
45
|
+
author_user_agent: ContextualField< string, 'edit', C >;
|
|
46
|
+
/**
|
|
47
|
+
* The content for the comment.
|
|
48
|
+
*/
|
|
49
|
+
content: RenderedText< C >;
|
|
50
|
+
/**
|
|
51
|
+
* The date the comment was published, in the site's timezone.
|
|
52
|
+
*/
|
|
53
|
+
date: string;
|
|
54
|
+
/**
|
|
55
|
+
* The date the comment was published, as GMT.
|
|
56
|
+
*/
|
|
57
|
+
date_gmt: ContextualField< string, 'view' | 'edit', C >;
|
|
58
|
+
/**
|
|
59
|
+
* URL to the comment.
|
|
60
|
+
*/
|
|
61
|
+
link: string;
|
|
62
|
+
/**
|
|
63
|
+
* The ID for the parent of the comment.
|
|
64
|
+
*/
|
|
65
|
+
parent: number;
|
|
66
|
+
/**
|
|
67
|
+
* The ID of the associated post object.
|
|
68
|
+
*/
|
|
69
|
+
post: ContextualField< number, 'view' | 'edit', C >;
|
|
70
|
+
/**
|
|
71
|
+
* State of the comment.
|
|
72
|
+
*/
|
|
73
|
+
status: ContextualField< CommentStatus, 'view' | 'edit', C >;
|
|
74
|
+
/**
|
|
75
|
+
* Type of the comment.
|
|
76
|
+
*/
|
|
77
|
+
type: string;
|
|
78
|
+
/**
|
|
79
|
+
* Avatar URLs for the comment author.
|
|
80
|
+
*/
|
|
81
|
+
author_avatar_urls: AvatarUrls;
|
|
82
|
+
/**
|
|
83
|
+
* Meta fields.
|
|
84
|
+
*/
|
|
85
|
+
meta: ContextualField<
|
|
86
|
+
Record< string, string >,
|
|
87
|
+
'view' | 'edit',
|
|
88
|
+
C
|
|
89
|
+
>;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export type Comment< C extends Context > = OmitNevers<
|
|
95
|
+
_BaseEntityTypes.Comment< C >
|
|
96
|
+
>;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { EntityRecord } from './index';
|
|
5
|
+
|
|
6
|
+
export interface AvatarUrls {
|
|
7
|
+
/**
|
|
8
|
+
* Avatar URL with image size of 24 pixels.
|
|
9
|
+
*/
|
|
10
|
+
'24': string;
|
|
11
|
+
/**
|
|
12
|
+
* Avatar URL with image size of 48 pixels.
|
|
13
|
+
*/
|
|
14
|
+
'48': string;
|
|
15
|
+
/**
|
|
16
|
+
* Avatar URL with image size of 96 pixels.
|
|
17
|
+
*/
|
|
18
|
+
'96': string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type MediaType = 'image' | 'file';
|
|
22
|
+
export type CommentingStatus = 'open' | 'closed';
|
|
23
|
+
export type PingStatus = 'open' | 'closed';
|
|
24
|
+
export type PostStatus = 'publish' | 'future' | 'draft' | 'pending' | 'private';
|
|
25
|
+
export type PostFormat =
|
|
26
|
+
| 'standard'
|
|
27
|
+
| 'aside'
|
|
28
|
+
| 'chat'
|
|
29
|
+
| 'gallery'
|
|
30
|
+
| 'link'
|
|
31
|
+
| 'image'
|
|
32
|
+
| 'quote'
|
|
33
|
+
| 'status'
|
|
34
|
+
| 'video'
|
|
35
|
+
| 'audio';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The REST API context parameter.
|
|
39
|
+
*/
|
|
40
|
+
export type Context = 'view' | 'edit' | 'embed';
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* ContextualField makes the field available only in the specified given contexts,
|
|
44
|
+
* and ensure the field is absent from the object when in a different context.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* interface Post< C extends Context > {
|
|
49
|
+
* …
|
|
50
|
+
* modified: ContextualField< string, 'edit' | 'view', C >;
|
|
51
|
+
* password: ContextualField< string, 'edit', C >;
|
|
52
|
+
* …
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* const post: Post<'edit'> = …
|
|
56
|
+
* // post.modified exists as a string
|
|
57
|
+
* // post.password exists as a string
|
|
58
|
+
*
|
|
59
|
+
* const post: Post<'view'> = …
|
|
60
|
+
* // post.modified still exists as a string
|
|
61
|
+
* // post.password is missing, undefined, because we're not in the `edit` context.
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export type ContextualField<
|
|
65
|
+
FieldType,
|
|
66
|
+
AvailableInContexts extends Context,
|
|
67
|
+
C extends Context
|
|
68
|
+
> = AvailableInContexts extends C ? FieldType : never;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Removes all the properties of type never, even the deeply nested ones.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* type MyType = {
|
|
76
|
+
* foo: string;
|
|
77
|
+
* bar: never;
|
|
78
|
+
* nested: {
|
|
79
|
+
* foo: string;
|
|
80
|
+
* bar: never;
|
|
81
|
+
* }
|
|
82
|
+
* }
|
|
83
|
+
* const x = {} as OmitNevers<MyType>;
|
|
84
|
+
* // x is of type { foo: string; nested: { foo: string; }}
|
|
85
|
+
* // The `never` properties were removed entirely
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export type OmitNevers<
|
|
89
|
+
T,
|
|
90
|
+
Nevers = {
|
|
91
|
+
[ K in keyof T ]: Exclude< T[ K ], undefined > extends never
|
|
92
|
+
? never
|
|
93
|
+
: T[ K ] extends Record< string, unknown >
|
|
94
|
+
? OmitNevers< T[ K ] >
|
|
95
|
+
: T[ K ];
|
|
96
|
+
}
|
|
97
|
+
> = Pick<
|
|
98
|
+
Nevers,
|
|
99
|
+
{
|
|
100
|
+
[ K in keyof Nevers ]: Nevers[ K ] extends never ? never : K;
|
|
101
|
+
}[ keyof Nevers ]
|
|
102
|
+
>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A string that the server renders which often involves
|
|
106
|
+
* modifications from the raw source string.
|
|
107
|
+
*
|
|
108
|
+
* For example, block HTML with the comment delimiters exists
|
|
109
|
+
* in `post_content` but those comments are stripped out when
|
|
110
|
+
* rendering to a page view. Similarly, plugins might modify
|
|
111
|
+
* content or replace shortcodes.
|
|
112
|
+
*/
|
|
113
|
+
export interface RenderedText< C extends Context > {
|
|
114
|
+
/**
|
|
115
|
+
* The source string which will be rendered on page views.
|
|
116
|
+
*/
|
|
117
|
+
raw: ContextualField< string, 'edit', C >;
|
|
118
|
+
/**
|
|
119
|
+
* The output of the raw source after processing and filtering on the server.
|
|
120
|
+
*/
|
|
121
|
+
rendered: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Updatable<EntityRecord> is a type describing Edited Entity Records. They are like
|
|
126
|
+
* regular Entity Records, but they have all the local edits applied on top of the REST API data.
|
|
127
|
+
*
|
|
128
|
+
* This turns certain field from an object into a string.
|
|
129
|
+
*
|
|
130
|
+
* Entities like Post have fields that only be rendered on the server, like title, excerpt,
|
|
131
|
+
* and content. The REST API exposes both the raw markup and the rendered version of those fields.
|
|
132
|
+
* For example, in the block editor, content.rendered could used as a visual preview, and
|
|
133
|
+
* content.raw could be used to populate the code editor.
|
|
134
|
+
*
|
|
135
|
+
* When updating these rendered fields, Javascript is not be able to properly render arbitrary block
|
|
136
|
+
* markup. Therefore, it stores only the raw markup without the rendered part. And since that's a string,
|
|
137
|
+
* the entire field becomes a string.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* type Post< C extends Context > {
|
|
142
|
+
* title: RenderedText< C >;
|
|
143
|
+
* }
|
|
144
|
+
* const post = {} as Post;
|
|
145
|
+
* // post.title is an object with raw and rendered properties
|
|
146
|
+
*
|
|
147
|
+
* const updatablePost = {} as Updatable< Post >;
|
|
148
|
+
* // updatablePost.title is a string
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export type Updatable< T extends EntityRecord< 'edit' > > = {
|
|
152
|
+
[ K in keyof T ]: T[ K ] extends RenderedText< any > ? string : T[ K ];
|
|
153
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { Attachment } from './attachment';
|
|
5
|
+
import type { Comment } from './comment';
|
|
6
|
+
import type { MenuLocation } from './menu-location';
|
|
7
|
+
import type { NavMenu } from './nav-menu';
|
|
8
|
+
import type { NavMenuItem } from './nav-menu-item';
|
|
9
|
+
import type { NavigationArea } from './navigation-area';
|
|
10
|
+
import type { Page } from './page';
|
|
11
|
+
import type { Plugin } from './plugin';
|
|
12
|
+
import type { Post } from './post';
|
|
13
|
+
import type { Settings } from './settings';
|
|
14
|
+
import type { Sidebar } from './sidebar';
|
|
15
|
+
import type { Taxonomy } from './taxonomy';
|
|
16
|
+
import type { Theme } from './theme';
|
|
17
|
+
import type { User } from './user';
|
|
18
|
+
import type { Type } from './type';
|
|
19
|
+
import type { Widget } from './widget';
|
|
20
|
+
import type { WidgetType } from './widget-type';
|
|
21
|
+
import type { WpTemplate } from './wp-template';
|
|
22
|
+
import type { WpTemplatePart } from './wp-template-part';
|
|
23
|
+
import type { Context, Updatable } from './helpers';
|
|
24
|
+
|
|
25
|
+
export type { BaseEntityTypes } from './base-entity-types';
|
|
26
|
+
|
|
27
|
+
export type {
|
|
28
|
+
Context,
|
|
29
|
+
Updatable,
|
|
30
|
+
Attachment,
|
|
31
|
+
Comment,
|
|
32
|
+
MenuLocation,
|
|
33
|
+
NavMenu,
|
|
34
|
+
NavMenuItem,
|
|
35
|
+
NavigationArea,
|
|
36
|
+
Page,
|
|
37
|
+
Plugin,
|
|
38
|
+
Post,
|
|
39
|
+
Settings,
|
|
40
|
+
Sidebar,
|
|
41
|
+
Taxonomy,
|
|
42
|
+
Theme,
|
|
43
|
+
User,
|
|
44
|
+
Type,
|
|
45
|
+
Widget,
|
|
46
|
+
WidgetType,
|
|
47
|
+
WpTemplate,
|
|
48
|
+
WpTemplatePart,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type EntityRecord< C extends Context > =
|
|
52
|
+
| Attachment< C >
|
|
53
|
+
| Comment< C >
|
|
54
|
+
| MenuLocation< C >
|
|
55
|
+
| NavMenu< C >
|
|
56
|
+
| NavMenuItem< C >
|
|
57
|
+
| NavigationArea< C >
|
|
58
|
+
| Page< C >
|
|
59
|
+
| Plugin< C >
|
|
60
|
+
| Post< C >
|
|
61
|
+
| Settings< C >
|
|
62
|
+
| Sidebar< C >
|
|
63
|
+
| Taxonomy< C >
|
|
64
|
+
| Theme< C >
|
|
65
|
+
| Type< C >
|
|
66
|
+
| User< C >
|
|
67
|
+
| Widget< C >
|
|
68
|
+
| WidgetType< C >
|
|
69
|
+
| WpTemplate< C >
|
|
70
|
+
| WpTemplatePart< C >;
|
|
71
|
+
|
|
72
|
+
export type UpdatableEntityRecord = Updatable< EntityRecord< 'edit' > >;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Context, OmitNevers } from './helpers';
|
|
5
|
+
|
|
6
|
+
import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
|
|
7
|
+
|
|
8
|
+
declare module './base-entity-types' {
|
|
9
|
+
export namespace BaseEntityTypes {
|
|
10
|
+
export interface MenuLocation< C extends Context > {
|
|
11
|
+
/**
|
|
12
|
+
* The name of the menu location.
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* The description of the menu location.
|
|
17
|
+
*/
|
|
18
|
+
description: string;
|
|
19
|
+
/**
|
|
20
|
+
* The ID of the assigned menu.
|
|
21
|
+
*/
|
|
22
|
+
menu: number;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type MenuLocation< C extends Context > = OmitNevers<
|
|
28
|
+
_BaseEntityTypes.MenuLocation< C >
|
|
29
|
+
>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { RenderedText, Context, ContextualField, OmitNevers } from './helpers';
|
|
5
|
+
|
|
6
|
+
import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
|
|
7
|
+
|
|
8
|
+
export type NavMenuItemType =
|
|
9
|
+
| 'taxonomy'
|
|
10
|
+
| 'post_type'
|
|
11
|
+
| 'post_type_archive'
|
|
12
|
+
| 'custom';
|
|
13
|
+
export type NavMenuItemStatus =
|
|
14
|
+
| 'publish'
|
|
15
|
+
| 'future'
|
|
16
|
+
| 'draft'
|
|
17
|
+
| 'pending'
|
|
18
|
+
| 'private';
|
|
19
|
+
export type Target = '_blank' | '';
|
|
20
|
+
|
|
21
|
+
declare module './base-entity-types' {
|
|
22
|
+
export namespace BaseEntityTypes {
|
|
23
|
+
export interface NavMenuItem< C extends Context > {
|
|
24
|
+
/**
|
|
25
|
+
* The title for the object.
|
|
26
|
+
*/
|
|
27
|
+
title: RenderedText< C >;
|
|
28
|
+
/**
|
|
29
|
+
* Unique identifier for the object.
|
|
30
|
+
*/
|
|
31
|
+
id: number;
|
|
32
|
+
/**
|
|
33
|
+
* The singular label used to describe this type of menu item.
|
|
34
|
+
*/
|
|
35
|
+
type_label: string;
|
|
36
|
+
/**
|
|
37
|
+
* The family of objects originally represented, such as "post_type" or "taxonomy".
|
|
38
|
+
*/
|
|
39
|
+
type: NavMenuItemType;
|
|
40
|
+
/**
|
|
41
|
+
* A named status for the object.
|
|
42
|
+
*/
|
|
43
|
+
status: NavMenuItemStatus;
|
|
44
|
+
/**
|
|
45
|
+
* The ID for the parent of the object.
|
|
46
|
+
*/
|
|
47
|
+
parent: number;
|
|
48
|
+
/**
|
|
49
|
+
* Text for the title attribute of the link element for this menu item.
|
|
50
|
+
*/
|
|
51
|
+
attr_title: string;
|
|
52
|
+
/**
|
|
53
|
+
* Class names for the link element of this menu item.
|
|
54
|
+
*/
|
|
55
|
+
classes: string[];
|
|
56
|
+
/**
|
|
57
|
+
* The description of this menu item.
|
|
58
|
+
*/
|
|
59
|
+
description: string;
|
|
60
|
+
/**
|
|
61
|
+
* The DB ID of the nav_menu_item that is this item's menu parent, if any, otherwise 0.
|
|
62
|
+
*/
|
|
63
|
+
menu_order: number;
|
|
64
|
+
/**
|
|
65
|
+
* The type of object originally represented, such as "category", "post", or "attachment".
|
|
66
|
+
*/
|
|
67
|
+
object: string;
|
|
68
|
+
/**
|
|
69
|
+
* The database ID of the original object this menu item represents, for example the ID for posts or the term_id for categories.
|
|
70
|
+
*/
|
|
71
|
+
object_id: number;
|
|
72
|
+
/**
|
|
73
|
+
* The target attribute of the link element for this menu item.
|
|
74
|
+
*/
|
|
75
|
+
target: Target;
|
|
76
|
+
/**
|
|
77
|
+
* The URL to which this menu item points.
|
|
78
|
+
*/
|
|
79
|
+
url: string;
|
|
80
|
+
/**
|
|
81
|
+
* The XFN relationship expressed in the link of this menu item.
|
|
82
|
+
*/
|
|
83
|
+
xfn: string[];
|
|
84
|
+
/**
|
|
85
|
+
* Whether the menu item represents an object that no longer exists.
|
|
86
|
+
*/
|
|
87
|
+
invalid: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* The terms assigned to the object in the nav_menu taxonomy.
|
|
90
|
+
*/
|
|
91
|
+
menus: ContextualField< number, 'view' | 'edit', C >;
|
|
92
|
+
/**
|
|
93
|
+
* Meta fields.
|
|
94
|
+
*/
|
|
95
|
+
meta: ContextualField<
|
|
96
|
+
Record< string, string >,
|
|
97
|
+
'view' | 'edit',
|
|
98
|
+
C
|
|
99
|
+
>;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export type NavMenuItem< C extends Context > = OmitNevers<
|
|
105
|
+
_BaseEntityTypes.NavMenuItem< C >
|
|
106
|
+
>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Context, ContextualField, OmitNevers } from './helpers';
|
|
5
|
+
|
|
6
|
+
import { BaseEntityTypes as _BaseEntityTypes } from './base-entity-types';
|
|
7
|
+
|
|
8
|
+
declare module './base-entity-types' {
|
|
9
|
+
export namespace BaseEntityTypes {
|
|
10
|
+
export interface NavMenu< C extends Context > {
|
|
11
|
+
/**
|
|
12
|
+
* Unique identifier for the term.
|
|
13
|
+
*/
|
|
14
|
+
id: number;
|
|
15
|
+
/**
|
|
16
|
+
* HTML description of the term.
|
|
17
|
+
*/
|
|
18
|
+
description: ContextualField< string, 'view' | 'edit', C >;
|
|
19
|
+
/**
|
|
20
|
+
* HTML title for the term.
|
|
21
|
+
*/
|
|
22
|
+
name: string;
|
|
23
|
+
/**
|
|
24
|
+
* An alphanumeric identifier for the term unique to its type.
|
|
25
|
+
*/
|
|
26
|
+
slug: string;
|
|
27
|
+
/**
|
|
28
|
+
* Meta fields.
|
|
29
|
+
*/
|
|
30
|
+
meta: ContextualField<
|
|
31
|
+
Record< string, string >,
|
|
32
|
+
'view' | 'edit',
|
|
33
|
+
C
|
|
34
|
+
>;
|
|
35
|
+
/**
|
|
36
|
+
* The locations assigned to the menu.
|
|
37
|
+
*/
|
|
38
|
+
locations: ContextualField< string[], 'view' | 'edit', C >;
|
|
39
|
+
/**
|
|
40
|
+
* The DB ID of the original object this menu item represents, e . g . ID for posts and term_id for categories.
|
|
41
|
+
*/
|
|
42
|
+
object_id: number;
|
|
43
|
+
/**
|
|
44
|
+
* Whether to automatically add top level pages to this menu.
|
|
45
|
+
*/
|
|
46
|
+
auto_add: ContextualField< boolean, 'view' | 'edit', C >;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type NavMenu< C extends Context > = OmitNevers<
|
|
52
|
+
_BaseEntityTypes.NavMenu< C >
|
|
53
|
+
>;
|