@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/build/entities.js
CHANGED
|
@@ -29,15 +29,18 @@ var _actions = require("./actions");
|
|
|
29
29
|
const DEFAULT_ENTITY_KEY = 'id';
|
|
30
30
|
exports.DEFAULT_ENTITY_KEY = DEFAULT_ENTITY_KEY;
|
|
31
31
|
const POST_RAW_ATTRIBUTES = ['title', 'excerpt', 'content'];
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
name: '__unstableBase',
|
|
32
|
+
const attachmentConfig = {
|
|
33
|
+
name: 'media',
|
|
35
34
|
kind: 'root',
|
|
36
|
-
baseURL: '/',
|
|
35
|
+
baseURL: '/wp/v2/media',
|
|
37
36
|
baseURLParams: {
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
37
|
+
context: 'edit'
|
|
38
|
+
},
|
|
39
|
+
plural: 'mediaItems',
|
|
40
|
+
label: (0, _i18n.__)('Media'),
|
|
41
|
+
rawAttributes: ['caption', 'title', 'description']
|
|
42
|
+
};
|
|
43
|
+
const siteConfig = {
|
|
41
44
|
label: (0, _i18n.__)('Site'),
|
|
42
45
|
name: 'site',
|
|
43
46
|
kind: 'root',
|
|
@@ -45,7 +48,8 @@ const rootEntitiesConfig = [{
|
|
|
45
48
|
getTitle: record => {
|
|
46
49
|
return (0, _lodash.get)(record, ['title'], (0, _i18n.__)('Site Title'));
|
|
47
50
|
}
|
|
48
|
-
}
|
|
51
|
+
};
|
|
52
|
+
const postTypeConfig = {
|
|
49
53
|
label: (0, _i18n.__)('Post Type'),
|
|
50
54
|
name: 'postType',
|
|
51
55
|
kind: 'root',
|
|
@@ -53,19 +57,9 @@ const rootEntitiesConfig = [{
|
|
|
53
57
|
baseURL: '/wp/v2/types',
|
|
54
58
|
baseURLParams: {
|
|
55
59
|
context: 'edit'
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
name: 'media',
|
|
60
|
-
kind: 'root',
|
|
61
|
-
baseURL: '/wp/v2/media',
|
|
62
|
-
baseURLParams: {
|
|
63
|
-
context: 'edit'
|
|
64
|
-
},
|
|
65
|
-
plural: 'mediaItems',
|
|
66
|
-
label: (0, _i18n.__)('Media'),
|
|
67
|
-
rawAttributes: ['caption', 'title', 'description']
|
|
68
|
-
}, {
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const taxonomyConfig = {
|
|
69
63
|
name: 'taxonomy',
|
|
70
64
|
kind: 'root',
|
|
71
65
|
key: 'slug',
|
|
@@ -75,7 +69,8 @@ const rootEntitiesConfig = [{
|
|
|
75
69
|
},
|
|
76
70
|
plural: 'taxonomies',
|
|
77
71
|
label: (0, _i18n.__)('Taxonomy')
|
|
78
|
-
}
|
|
72
|
+
};
|
|
73
|
+
const sidebarConfig = {
|
|
79
74
|
name: 'sidebar',
|
|
80
75
|
kind: 'root',
|
|
81
76
|
baseURL: '/wp/v2/sidebars',
|
|
@@ -87,7 +82,8 @@ const rootEntitiesConfig = [{
|
|
|
87
82
|
blocks: true
|
|
88
83
|
},
|
|
89
84
|
label: (0, _i18n.__)('Widget areas')
|
|
90
|
-
}
|
|
85
|
+
};
|
|
86
|
+
const widgetConfig = {
|
|
91
87
|
name: 'widget',
|
|
92
88
|
kind: 'root',
|
|
93
89
|
baseURL: '/wp/v2/widgets',
|
|
@@ -99,7 +95,8 @@ const rootEntitiesConfig = [{
|
|
|
99
95
|
blocks: true
|
|
100
96
|
},
|
|
101
97
|
label: (0, _i18n.__)('Widgets')
|
|
102
|
-
}
|
|
98
|
+
};
|
|
99
|
+
const widgetTypeConfig = {
|
|
103
100
|
name: 'widgetType',
|
|
104
101
|
kind: 'root',
|
|
105
102
|
baseURL: '/wp/v2/widget-types',
|
|
@@ -108,7 +105,8 @@ const rootEntitiesConfig = [{
|
|
|
108
105
|
},
|
|
109
106
|
plural: 'widgetTypes',
|
|
110
107
|
label: (0, _i18n.__)('Widget types')
|
|
111
|
-
}
|
|
108
|
+
};
|
|
109
|
+
const userConfig = {
|
|
112
110
|
label: (0, _i18n.__)('User'),
|
|
113
111
|
name: 'user',
|
|
114
112
|
kind: 'root',
|
|
@@ -117,7 +115,8 @@ const rootEntitiesConfig = [{
|
|
|
117
115
|
context: 'edit'
|
|
118
116
|
},
|
|
119
117
|
plural: 'users'
|
|
120
|
-
}
|
|
118
|
+
};
|
|
119
|
+
const commentConfig = {
|
|
121
120
|
name: 'comment',
|
|
122
121
|
kind: 'root',
|
|
123
122
|
baseURL: '/wp/v2/comments',
|
|
@@ -126,7 +125,8 @@ const rootEntitiesConfig = [{
|
|
|
126
125
|
},
|
|
127
126
|
plural: 'comments',
|
|
128
127
|
label: (0, _i18n.__)('Comment')
|
|
129
|
-
}
|
|
128
|
+
};
|
|
129
|
+
const menuConfig = {
|
|
130
130
|
name: 'menu',
|
|
131
131
|
kind: 'root',
|
|
132
132
|
baseURL: '/wp/v2/menus',
|
|
@@ -135,7 +135,8 @@ const rootEntitiesConfig = [{
|
|
|
135
135
|
},
|
|
136
136
|
plural: 'menus',
|
|
137
137
|
label: (0, _i18n.__)('Menu')
|
|
138
|
-
}
|
|
138
|
+
};
|
|
139
|
+
const menuItemConfig = {
|
|
139
140
|
name: 'menuItem',
|
|
140
141
|
kind: 'root',
|
|
141
142
|
baseURL: '/wp/v2/menu-items',
|
|
@@ -144,8 +145,9 @@ const rootEntitiesConfig = [{
|
|
|
144
145
|
},
|
|
145
146
|
plural: 'menuItems',
|
|
146
147
|
label: (0, _i18n.__)('Menu Item'),
|
|
147
|
-
rawAttributes: ['title'
|
|
148
|
-
}
|
|
148
|
+
rawAttributes: ['title']
|
|
149
|
+
};
|
|
150
|
+
const menuLocationConfig = {
|
|
149
151
|
name: 'menuLocation',
|
|
150
152
|
kind: 'root',
|
|
151
153
|
baseURL: '/wp/v2/menu-locations',
|
|
@@ -155,18 +157,8 @@ const rootEntitiesConfig = [{
|
|
|
155
157
|
plural: 'menuLocations',
|
|
156
158
|
label: (0, _i18n.__)('Menu Location'),
|
|
157
159
|
key: 'name'
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
kind: 'root',
|
|
161
|
-
baseURL: '/wp/v2/block-navigation-areas',
|
|
162
|
-
baseURLParams: {
|
|
163
|
-
context: 'edit'
|
|
164
|
-
},
|
|
165
|
-
plural: 'navigationAreas',
|
|
166
|
-
label: (0, _i18n.__)('Navigation Area'),
|
|
167
|
-
key: 'name',
|
|
168
|
-
getTitle: record => record === null || record === void 0 ? void 0 : record.description
|
|
169
|
-
}, {
|
|
160
|
+
};
|
|
161
|
+
const globalStyleConfig = {
|
|
170
162
|
label: (0, _i18n.__)('Global Styles'),
|
|
171
163
|
name: 'globalStyles',
|
|
172
164
|
kind: 'root',
|
|
@@ -181,7 +173,8 @@ const rootEntitiesConfig = [{
|
|
|
181
173
|
|
|
182
174
|
return (record === null || record === void 0 ? void 0 : (_record$title = record.title) === null || _record$title === void 0 ? void 0 : _record$title.rendered) || (record === null || record === void 0 ? void 0 : record.title);
|
|
183
175
|
}
|
|
184
|
-
}
|
|
176
|
+
};
|
|
177
|
+
const themeConfig = {
|
|
185
178
|
label: (0, _i18n.__)('Themes'),
|
|
186
179
|
name: 'theme',
|
|
187
180
|
kind: 'root',
|
|
@@ -190,7 +183,8 @@ const rootEntitiesConfig = [{
|
|
|
190
183
|
context: 'edit'
|
|
191
184
|
},
|
|
192
185
|
key: 'stylesheet'
|
|
193
|
-
}
|
|
186
|
+
};
|
|
187
|
+
const pluginConfig = {
|
|
194
188
|
label: (0, _i18n.__)('Plugins'),
|
|
195
189
|
name: 'plugin',
|
|
196
190
|
kind: 'root',
|
|
@@ -199,7 +193,16 @@ const rootEntitiesConfig = [{
|
|
|
199
193
|
context: 'edit'
|
|
200
194
|
},
|
|
201
195
|
key: 'plugin'
|
|
202
|
-
}
|
|
196
|
+
};
|
|
197
|
+
const rootEntitiesConfig = [{
|
|
198
|
+
label: (0, _i18n.__)('Base'),
|
|
199
|
+
kind: 'root',
|
|
200
|
+
name: '__unstableBase',
|
|
201
|
+
baseURL: '/',
|
|
202
|
+
baseURLParams: {
|
|
203
|
+
_fields: ['description', 'gmt_offset', 'home', 'name', 'site_icon', 'site_icon_url', 'site_logo', 'timezone_string', 'url'].join(',')
|
|
204
|
+
}
|
|
205
|
+
}, siteConfig, postTypeConfig, attachmentConfig, taxonomyConfig, sidebarConfig, widgetConfig, widgetTypeConfig, userConfig, commentConfig, menuConfig, menuItemConfig, menuLocationConfig, globalStyleConfig, themeConfig, pluginConfig];
|
|
203
206
|
exports.rootEntitiesConfig = rootEntitiesConfig;
|
|
204
207
|
const additionalEntityConfigLoaders = [{
|
|
205
208
|
kind: 'postType',
|
|
@@ -335,7 +338,7 @@ const getMethodName = function (kind, name) {
|
|
|
335
338
|
});
|
|
336
339
|
const kindPrefix = kind === 'root' ? '' : (0, _lodash.upperFirst)((0, _lodash.camelCase)(kind));
|
|
337
340
|
const nameSuffix = (0, _lodash.upperFirst)((0, _lodash.camelCase)(name)) + (usePlural ? 's' : '');
|
|
338
|
-
const suffix = usePlural && entityConfig !== null && entityConfig !== void 0 && entityConfig.plural ? (0, _lodash.upperFirst)((0, _lodash.camelCase)(entityConfig.plural)) : nameSuffix;
|
|
341
|
+
const suffix = usePlural && 'plural' in entityConfig && entityConfig !== null && entityConfig !== void 0 && entityConfig.plural ? (0, _lodash.upperFirst)((0, _lodash.camelCase)(entityConfig.plural)) : nameSuffix;
|
|
339
342
|
return `${prefix}${kindPrefix}${suffix}`;
|
|
340
343
|
};
|
|
341
344
|
/**
|
package/build/entities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/entities.ts"],"names":["DEFAULT_ENTITY_KEY","POST_RAW_ATTRIBUTES","rootEntitiesConfig","label","name","kind","baseURL","baseURLParams","_fields","join","getTitle","record","key","context","rawAttributes","plural","transientEdits","blocks","description","title","rendered","additionalEntityConfigLoaders","loadEntities","loadPostTypeEntities","loadTaxonomyEntities","prePersistPostType","persistedRecord","edits","newEdits","status","postTypes","path","postType","isTemplate","includes","namespace","rest_namespace","rest_base","selection","mergedEdits","meta","slug","String","id","__unstablePrePersist","undefined","__unstable_rest_base","taxonomies","taxonomy","getMethodName","prefix","usePlural","entityConfig","kindPrefix","nameSuffix","suffix","getOrLoadEntitiesConfig","select","dispatch","configs","getEntitiesConfig","length","loader"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;AAIO,MAAMA,kBAAkB,GAAG,IAA3B;;AAEP,MAAMC,mBAAmB,GAAG,CAAE,OAAF,EAAW,SAAX,EAAsB,SAAtB,CAA5B;AAEO,MAAMC,kBAAkB,GAAG,CACjC;AACCC,EAAAA,KAAK,EAAE,cAAI,MAAJ,CADR;AAECC,EAAAA,IAAI,EAAE,gBAFP;AAGCC,EAAAA,IAAI,EAAE,MAHP;AAICC,EAAAA,OAAO,EAAE,GAJV;AAKCC,EAAAA,aAAa,EAAE;AACdC,IAAAA,OAAO,EAAE,CACR,aADQ,EAER,YAFQ,EAGR,MAHQ,EAIR,MAJQ,EAKR,WALQ,EAMR,eANQ,EAOR,WAPQ,EAQR,iBARQ,EASR,KATQ,EAUPC,IAVO,CAUD,GAVC;AADK;AALhB,CADiC,EAoBjC;AACCN,EAAAA,KAAK,EAAE,cAAI,MAAJ,CADR;AAECC,EAAAA,IAAI,EAAE,MAFP;AAGCC,EAAAA,IAAI,EAAE,MAHP;AAICC,EAAAA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G,MAAM,GAAG,kBAAMzC,6BAAN,EAAqC;AAAEhB,IAAAA;AAAF,GAArC,CAAf;;AACA,MAAK,CAAEyD,MAAP,EAAgB;AACf,WAAO,EAAP;AACA;;AAEDH,EAAAA,OAAO,GAAG,MAAMG,MAAM,CAACxC,YAAP,EAAhB;AACAoC,EAAAA,QAAQ,CAAE,0BAAaC,OAAb,CAAF,CAAR;AAEA,SAAOA,OAAP;AACA,CAlBM","sourcesContent":["/**\n * External dependencies\n */\nimport { upperFirst, camelCase, map, find, get, startCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { addEntities } from './actions';\nimport type { Post, Taxonomy, Type, Updatable } from './entity-types';\n\nexport const DEFAULT_ENTITY_KEY = 'id';\n\nconst POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];\n\nexport const rootEntitiesConfig = [\n\t{\n\t\tlabel: __( 'Base' ),\n\t\tname: '__unstableBase',\n\t\tkind: 'root',\n\t\tbaseURL: '/',\n\t\tbaseURLParams: {\n\t\t\t_fields: [\n\t\t\t\t'description',\n\t\t\t\t'gmt_offset',\n\t\t\t\t'home',\n\t\t\t\t'name',\n\t\t\t\t'site_icon',\n\t\t\t\t'site_icon_url',\n\t\t\t\t'site_logo',\n\t\t\t\t'timezone_string',\n\t\t\t\t'url',\n\t\t\t].join( ',' ),\n\t\t},\n\t},\n\t{\n\t\tlabel: __( 'Site' ),\n\t\tname: 'site',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/settings',\n\t\tgetTitle: ( record ) => {\n\t\t\treturn get( record, [ 'title' ], __( 'Site Title' ) );\n\t\t},\n\t},\n\t{\n\t\tlabel: __( 'Post Type' ),\n\t\tname: 'postType',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t},\n\t{\n\t\tname: 'media',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/media',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'mediaItems',\n\t\tlabel: __( 'Media' ),\n\t\trawAttributes: [ 'caption', 'title', 'description' ],\n\t},\n\t{\n\t\tname: 'taxonomy',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/taxonomies',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'taxonomies',\n\t\tlabel: __( 'Taxonomy' ),\n\t},\n\t{\n\t\tname: 'sidebar',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/sidebars',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'sidebars',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widget areas' ),\n\t},\n\t{\n\t\tname: 'widget',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widgets',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgets',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widgets' ),\n\t},\n\t{\n\t\tname: 'widgetType',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widget-types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgetTypes',\n\t\tlabel: __( 'Widget types' ),\n\t},\n\t{\n\t\tlabel: __( 'User' ),\n\t\tname: 'user',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/users',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'users',\n\t},\n\t{\n\t\tname: 'comment',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/comments',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'comments',\n\t\tlabel: __( 'Comment' ),\n\t},\n\t{\n\t\tname: 'menu',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menus',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menus',\n\t\tlabel: __( 'Menu' ),\n\t},\n\t{\n\t\tname: 'menuItem',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-items',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuItems',\n\t\tlabel: __( 'Menu Item' ),\n\t\trawAttributes: [ 'title', 'content' ],\n\t},\n\t{\n\t\tname: 'menuLocation',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-locations',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuLocations',\n\t\tlabel: __( 'Menu Location' ),\n\t\tkey: 'name',\n\t},\n\t{\n\t\tname: 'navigationArea',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/block-navigation-areas',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'navigationAreas',\n\t\tlabel: __( 'Navigation Area' ),\n\t\tkey: 'name',\n\t\tgetTitle: ( record ) => record?.description,\n\t},\n\t{\n\t\tlabel: __( 'Global Styles' ),\n\t\tname: 'globalStyles',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/global-styles',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'globalStylesVariations', // Should be different than name.\n\t\tgetTitle: ( record ) => record?.title?.rendered || record?.title,\n\t},\n\t{\n\t\tlabel: __( 'Themes' ),\n\t\tname: 'theme',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/themes',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tkey: 'stylesheet',\n\t},\n\t{\n\t\tlabel: __( 'Plugins' ),\n\t\tname: 'plugin',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/plugins',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tkey: 'plugin',\n\t},\n];\n\nexport const additionalEntityConfigLoaders = [\n\t{ kind: 'postType', loadEntities: loadPostTypeEntities },\n\t{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },\n];\n\n/**\n * Returns a function to be used to retrieve extra edits to apply before persisting a post type.\n *\n * @param {Object} persistedRecord Already persisted Post\n * @param {Object} edits Edits.\n * @return {Object} Updated edits.\n */\nexport const prePersistPostType = ( persistedRecord, edits ) => {\n\tconst newEdits = {} as Partial< Updatable< Post< 'edit' > > >;\n\n\tif ( persistedRecord?.status === 'auto-draft' ) {\n\t\t// Saving an auto-draft should create a draft by default.\n\t\tif ( ! edits.status && ! newEdits.status ) {\n\t\t\tnewEdits.status = 'draft';\n\t\t}\n\n\t\t// Fix the auto-draft default title.\n\t\tif (\n\t\t\t( ! edits.title || edits.title === 'Auto Draft' ) &&\n\t\t\t! newEdits.title &&\n\t\t\t( ! persistedRecord?.title ||\n\t\t\t\tpersistedRecord?.title === 'Auto Draft' )\n\t\t) {\n\t\t\tnewEdits.title = '';\n\t\t}\n\t}\n\n\treturn newEdits;\n};\n\n/**\n * Returns the list of post type entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadPostTypeEntities() {\n\tconst postTypes = ( await apiFetch( {\n\t\tpath: '/wp/v2/types?context=view',\n\t} ) ) as Record< string, Type< 'view' > >;\n\treturn map( postTypes, ( postType, name ) => {\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tname\n\t\t);\n\t\tconst namespace = postType?.rest_namespace ?? 'wp/v2';\n\t\treturn {\n\t\t\tkind: 'postType',\n\t\t\tbaseURL: `/${ namespace }/${ postType.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: postType.name,\n\t\t\ttransientEdits: {\n\t\t\t\tblocks: true,\n\t\t\t\tselection: true,\n\t\t\t},\n\t\t\tmergedEdits: { meta: true },\n\t\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t\t\tgetTitle: ( record ) =>\n\t\t\t\trecord?.title?.rendered ||\n\t\t\t\trecord?.title ||\n\t\t\t\t( isTemplate ? startCase( record.slug ) : String( record.id ) ),\n\t\t\t__unstablePrePersist: isTemplate ? undefined : prePersistPostType,\n\t\t\t__unstable_rest_base: postType.rest_base,\n\t\t};\n\t} );\n}\n\n/**\n * Returns the list of the taxonomies entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadTaxonomyEntities() {\n\tconst taxonomies = ( await apiFetch( {\n\t\tpath: '/wp/v2/taxonomies?context=view',\n\t} ) ) as Record< string, Taxonomy< 'view' > >;\n\treturn map( taxonomies, ( taxonomy, name ) => {\n\t\tconst namespace = taxonomy?.rest_namespace ?? 'wp/v2';\n\t\treturn {\n\t\t\tkind: 'taxonomy',\n\t\t\tbaseURL: `/${ namespace }/${ taxonomy.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: taxonomy.name,\n\t\t};\n\t} );\n}\n\n/**\n * Returns the entity's getter method name given its kind and name.\n *\n * @example\n * ```js\n * const nameSingular = getMethodName( 'root', 'theme', 'get' );\n * // nameSingular is getRootTheme\n *\n * const namePlural = getMethodName( 'root', 'theme', 'set' );\n * // namePlural is setRootThemes\n * ```\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} prefix Function prefix.\n * @param {boolean} usePlural Whether to use the plural form or not.\n *\n * @return {string} Method name\n */\nexport const getMethodName = (\n\tkind,\n\tname,\n\tprefix = 'get',\n\tusePlural = false\n) => {\n\tconst entityConfig = find( rootEntitiesConfig, { kind, name } );\n\tconst kindPrefix = kind === 'root' ? '' : upperFirst( camelCase( kind ) );\n\tconst nameSuffix =\n\t\tupperFirst( camelCase( name ) ) + ( usePlural ? 's' : '' );\n\tconst suffix =\n\t\tusePlural && entityConfig?.plural\n\t\t\t? upperFirst( camelCase( entityConfig.plural ) )\n\t\t\t: nameSuffix;\n\treturn `${ prefix }${ kindPrefix }${ suffix }`;\n};\n\n/**\n * Loads the kind entities into the store.\n *\n * @param {string} kind Kind\n *\n * @return {(thunkArgs: object) => Promise<Array>} Entities\n */\nexport const getOrLoadEntitiesConfig = ( kind ) => async ( {\n\tselect,\n\tdispatch,\n} ) => {\n\tlet configs = select.getEntitiesConfig( kind );\n\tif ( configs && configs.length !== 0 ) {\n\t\treturn configs;\n\t}\n\n\tconst loader = find( additionalEntityConfigLoaders, { kind } );\n\tif ( ! loader ) {\n\t\treturn [];\n\t}\n\n\tconfigs = await loader.loadEntities();\n\tdispatch( addEntities( configs ) );\n\n\treturn configs;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/entities.ts"],"names":["DEFAULT_ENTITY_KEY","POST_RAW_ATTRIBUTES","attachmentConfig","name","kind","baseURL","baseURLParams","context","plural","label","rawAttributes","siteConfig","getTitle","record","postTypeConfig","key","taxonomyConfig","sidebarConfig","transientEdits","blocks","widgetConfig","widgetTypeConfig","userConfig","commentConfig","menuConfig","menuItemConfig","menuLocationConfig","globalStyleConfig","title","rendered","themeConfig","pluginConfig","rootEntitiesConfig","_fields","join","additionalEntityConfigLoaders","loadEntities","loadPostTypeEntities","loadTaxonomyEntities","prePersistPostType","persistedRecord","edits","newEdits","status","postTypes","path","postType","isTemplate","includes","namespace","rest_namespace","rest_base","selection","mergedEdits","meta","slug","String","id","__unstablePrePersist","undefined","__unstable_rest_base","taxonomies","taxonomy","getMethodName","prefix","usePlural","entityConfig","kindPrefix","nameSuffix","suffix","getOrLoadEntitiesConfig","select","dispatch","configs","getEntitiesConfig","length","loader"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;AAYO,MAAMA,kBAAkB,GAAG,IAA3B;;AAEP,MAAMC,mBAAmB,GAAG,CAAE,OAAF,EAAW,SAAX,EAAsB,SAAtB,CAA5B;AAYA,MAAMC,gBAA8C,GAAG;AACtDC,EAAAA,IAAI,EAAE,OADgD;AAEtDC,EAAAA,IAAI,EAAE,MAFgD;AAGtDC,EAAAA,OAAO,EAAE,cAH6C;AAItDC,EAAAA,aAAa,EAAE;AAAEC,IAAAA,OAAO,EAAE;AAAX,GAJuC;AAKtDC,EAAAA,MAAM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AAuB,wBAAY,uBAAWA,IAAX,CAAZ,CAA1C;AACA,QAAMgE,UAAU,GACf,wBAAY,uBAAWjE,IAAX,CAAZ,KAAoC8D,SAAS,GAAG,GAAH,GAAS,EAAtD,CADD;AAEA,QAAMI,MAAM,GACXJ,SAAS,IAAI,YAAYC,YAAzB,IAAyCA,YAAzC,aAAyCA,YAAzC,eAAyCA,YAAY,CAAE1D,MAAvD,GACG,wBAAY,uBAAW0D,YAAY,CAAC1D,MAAxB,CAAZ,CADH,GAEG4D,UAHJ;AAIA,SAAQ,GAAGJ,MAAQ,GAAGG,UAAY,GAAGE,MAAQ,EAA7C;AACA,CAfM;AAiBP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,uBAAuB,GAAKlE,IAAF,IAAY,cAG5C;AAAA,MAHoD;AAC1DmE,IAAAA,MAD0D;AAE1DC,IAAAA;AAF0D,GAGpD;AACN,MAAIC,OAAO,GAAGF,MAAM,CAACG,iBAAP,CAA0BtE,IAA1B,CAAd;;AACA,MAAKqE,OAAO,IAAIA,OAAO,CAACE,MAAR,KAAmB,CAAnC,EAAuC;AACtC,WAAOF,OAAP;AACA;;AAED,QAAMG,MAAM,GAAG,kBAAMzC,6BAAN,EAAqC;AAAE/B,IAAAA;AAAF,GAArC,CAAf;;AACA,MAAK,CAAEwE,MAAP,EAAgB;AACf,WAAO,EAAP;AACA;;AAEDH,EAAAA,OAAO,GAAG,MAAMG,MAAM,CAACxC,YAAP,EAAhB;AACAoC,EAAAA,QAAQ,CAAE,0BAAaC,OAAb,CAAF,CAAR;AAEA,SAAOA,OAAP;AACA,CAlBM","sourcesContent":["/**\n * External dependencies\n */\nimport { upperFirst, camelCase, map, find, get, startCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { addEntities } from './actions';\nimport type * as Records from './entity-types';\nimport type {\n\tEntityType,\n\tContext,\n\tPost,\n\tTaxonomy,\n\tType,\n\tUpdatable,\n} from './entity-types';\n\nexport const DEFAULT_ENTITY_KEY = 'id';\n\nconst POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];\n\ntype AttachmentEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'media';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Attachment< C >,\n\tC\n>;\n\nconst attachmentConfig: AttachmentEntity[ 'config' ] = {\n\tname: 'media',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/media',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'mediaItems',\n\tlabel: __( 'Media' ),\n\trawAttributes: [ 'caption', 'title', 'description' ],\n};\n\ntype SiteEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'site';\n\t\tkind: 'root';\n\t},\n\tRecords.Settings< C >,\n\tC\n>;\n\nconst siteConfig: SiteEntity[ 'config' ] = {\n\tlabel: __( 'Site' ),\n\tname: 'site',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/settings',\n\tgetTitle: ( record: Records.Settings< 'edit' > ) => {\n\t\treturn get( record, [ 'title' ], __( 'Site Title' ) );\n\t},\n};\n\ntype PostTypeEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'postType';\n\t\tkind: 'root';\n\t\tkey: 'slug';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Type< C >,\n\tC\n>;\n\nconst postTypeConfig: PostTypeEntity[ 'config' ] = {\n\tlabel: __( 'Post Type' ),\n\tname: 'postType',\n\tkind: 'root',\n\tkey: 'slug',\n\tbaseURL: '/wp/v2/types',\n\tbaseURLParams: { context: 'edit' },\n};\n\ntype TaxonomyEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'taxonomy';\n\t\tkind: 'root';\n\t\tkey: 'slug';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Taxonomy< C >,\n\tC\n>;\n\nconst taxonomyConfig: TaxonomyEntity[ 'config' ] = {\n\tname: 'taxonomy',\n\tkind: 'root',\n\tkey: 'slug',\n\tbaseURL: '/wp/v2/taxonomies',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'taxonomies',\n\tlabel: __( 'Taxonomy' ),\n};\n\ntype SidebarEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'sidebar';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Sidebar< C >,\n\tC\n>;\n\nconst sidebarConfig: SidebarEntity[ 'config' ] = {\n\tname: 'sidebar',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/sidebars',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'sidebars',\n\ttransientEdits: { blocks: true },\n\tlabel: __( 'Widget areas' ),\n};\n\ntype WidgetEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'widget';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Widget< C >,\n\tC\n>;\nconst widgetConfig: WidgetEntity[ 'config' ] = {\n\tname: 'widget',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/widgets',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'widgets',\n\ttransientEdits: { blocks: true },\n\tlabel: __( 'Widgets' ),\n};\n\ntype WidgetTypeEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'widgetType';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.WidgetType< C >,\n\tC\n>;\nconst widgetTypeConfig: WidgetTypeEntity[ 'config' ] = {\n\tname: 'widgetType',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/widget-types',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'widgetTypes',\n\tlabel: __( 'Widget types' ),\n};\n\ntype UserEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'user';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.User< C >,\n\tC\n>;\nconst userConfig: UserEntity[ 'config' ] = {\n\tlabel: __( 'User' ),\n\tname: 'user',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/users',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'users',\n};\n\ntype CommentEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'comment';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Comment< C >,\n\tC\n>;\nconst commentConfig: CommentEntity[ 'config' ] = {\n\tname: 'comment',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/comments',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'comments',\n\tlabel: __( 'Comment' ),\n};\n\ntype NavMenuEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'menu';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.NavMenu< C >,\n\tC\n>;\n\nconst menuConfig: NavMenuEntity[ 'config' ] = {\n\tname: 'menu',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/menus',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'menus',\n\tlabel: __( 'Menu' ),\n};\n\ntype NavMenuItemEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'menuItem';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.NavMenuItem< C >,\n\tC\n>;\n\nconst menuItemConfig: NavMenuItemEntity[ 'config' ] = {\n\tname: 'menuItem',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/menu-items',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'menuItems',\n\tlabel: __( 'Menu Item' ),\n\trawAttributes: [ 'title' ],\n};\n\ntype MenuLocationEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'menuLocation';\n\t\tkind: 'root';\n\t\tkey: 'name';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.MenuLocation< C >,\n\tC\n>;\n\nconst menuLocationConfig: MenuLocationEntity[ 'config' ] = {\n\tname: 'menuLocation',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/menu-locations',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'menuLocations',\n\tlabel: __( 'Menu Location' ),\n\tkey: 'name',\n};\n\nconst globalStyleConfig = {\n\tlabel: __( 'Global Styles' ),\n\tname: 'globalStyles',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/global-styles',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'globalStylesVariations', // Should be different than name.\n\tgetTitle: ( record ) => record?.title?.rendered || record?.title,\n};\n\ntype ThemeEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'theme';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t\tkey: 'stylesheet';\n\t},\n\tRecords.Theme< C >,\n\tC\n>;\n\nconst themeConfig: ThemeEntity[ 'config' ] = {\n\tlabel: __( 'Themes' ),\n\tname: 'theme',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/themes',\n\tbaseURLParams: { context: 'edit' },\n\tkey: 'stylesheet',\n};\n\ntype PluginEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'plugin';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t\tkey: 'plugin';\n\t},\n\tRecords.Plugin< C >,\n\tC\n>;\nconst pluginConfig: PluginEntity[ 'config' ] = {\n\tlabel: __( 'Plugins' ),\n\tname: 'plugin',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/plugins',\n\tbaseURLParams: { context: 'edit' },\n\tkey: 'plugin',\n};\n\nexport const rootEntitiesConfig = [\n\t{\n\t\tlabel: __( 'Base' ),\n\t\tkind: 'root',\n\t\tname: '__unstableBase',\n\t\tbaseURL: '/',\n\t\tbaseURLParams: {\n\t\t\t_fields: [\n\t\t\t\t'description',\n\t\t\t\t'gmt_offset',\n\t\t\t\t'home',\n\t\t\t\t'name',\n\t\t\t\t'site_icon',\n\t\t\t\t'site_icon_url',\n\t\t\t\t'site_logo',\n\t\t\t\t'timezone_string',\n\t\t\t\t'url',\n\t\t\t].join( ',' ),\n\t\t},\n\t},\n\tsiteConfig,\n\tpostTypeConfig,\n\tattachmentConfig,\n\ttaxonomyConfig,\n\tsidebarConfig,\n\twidgetConfig,\n\twidgetTypeConfig,\n\tuserConfig,\n\tcommentConfig,\n\tmenuConfig,\n\tmenuItemConfig,\n\tmenuLocationConfig,\n\tglobalStyleConfig,\n\tthemeConfig,\n\tpluginConfig,\n];\n\ntype PostTypeConfig = {\n\tkind: 'postType';\n\tkey: 'id';\n\tdefaultContext: 'edit';\n};\n\ntype PostEntity< C extends Context = Context > = EntityType<\n\tPostTypeConfig & { name: 'post' },\n\tRecords.Post< C >,\n\tC\n>;\ntype PageEntity< C extends Context > = EntityType<\n\tPostTypeConfig & { name: 'page' },\n\tRecords.Page< C >,\n\tC\n>;\ntype WpTemplateEntity< C extends Context > = EntityType<\n\tPostTypeConfig & { name: 'wp_template' },\n\tRecords.WpTemplate< C >,\n\tC\n>;\ntype WpTemplatePartEntity< C extends Context > = EntityType<\n\tPostTypeConfig & { name: 'wp_template_part' },\n\tRecords.WpTemplatePart< C >,\n\tC\n>;\n\nexport type CoreEntities< C extends Context > =\n\t| SiteEntity< C >\n\t| PostTypeEntity< C >\n\t| AttachmentEntity< C >\n\t| TaxonomyEntity< C >\n\t| SidebarEntity< C >\n\t| WidgetEntity< C >\n\t| WidgetTypeEntity< C >\n\t| UserEntity< C >\n\t| CommentEntity< C >\n\t| NavMenuEntity< C >\n\t| NavMenuItemEntity< C >\n\t| MenuLocationEntity< C >\n\t| ThemeEntity< C >\n\t| PluginEntity< C >\n\t| PostEntity< C >\n\t| PageEntity< C >\n\t| WpTemplateEntity< C >\n\t| WpTemplatePartEntity< C >;\n\nexport const additionalEntityConfigLoaders = [\n\t{ kind: 'postType', loadEntities: loadPostTypeEntities },\n\t{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },\n];\n\n/**\n * Returns a function to be used to retrieve extra edits to apply before persisting a post type.\n *\n * @param {Object} persistedRecord Already persisted Post\n * @param {Object} edits Edits.\n * @return {Object} Updated edits.\n */\nexport const prePersistPostType = ( persistedRecord, edits ) => {\n\tconst newEdits = {} as Partial< Updatable< Post< 'edit' > > >;\n\n\tif ( persistedRecord?.status === 'auto-draft' ) {\n\t\t// Saving an auto-draft should create a draft by default.\n\t\tif ( ! edits.status && ! newEdits.status ) {\n\t\t\tnewEdits.status = 'draft';\n\t\t}\n\n\t\t// Fix the auto-draft default title.\n\t\tif (\n\t\t\t( ! edits.title || edits.title === 'Auto Draft' ) &&\n\t\t\t! newEdits.title &&\n\t\t\t( ! persistedRecord?.title ||\n\t\t\t\tpersistedRecord?.title === 'Auto Draft' )\n\t\t) {\n\t\t\tnewEdits.title = '';\n\t\t}\n\t}\n\n\treturn newEdits;\n};\n\n/**\n * Returns the list of post type entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadPostTypeEntities() {\n\tconst postTypes = ( await apiFetch( {\n\t\tpath: '/wp/v2/types?context=view',\n\t} ) ) as Record< string, Type< 'view' > >;\n\treturn map( postTypes, ( postType, name ) => {\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tname\n\t\t);\n\t\tconst namespace = postType?.rest_namespace ?? 'wp/v2';\n\t\treturn {\n\t\t\tkind: 'postType',\n\t\t\tbaseURL: `/${ namespace }/${ postType.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: postType.name,\n\t\t\ttransientEdits: {\n\t\t\t\tblocks: true,\n\t\t\t\tselection: true,\n\t\t\t},\n\t\t\tmergedEdits: { meta: true },\n\t\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t\t\tgetTitle: ( record ) =>\n\t\t\t\trecord?.title?.rendered ||\n\t\t\t\trecord?.title ||\n\t\t\t\t( isTemplate ? startCase( record.slug ) : String( record.id ) ),\n\t\t\t__unstablePrePersist: isTemplate ? undefined : prePersistPostType,\n\t\t\t__unstable_rest_base: postType.rest_base,\n\t\t};\n\t} );\n}\n\n/**\n * Returns the list of the taxonomies entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadTaxonomyEntities() {\n\tconst taxonomies = ( await apiFetch( {\n\t\tpath: '/wp/v2/taxonomies?context=view',\n\t} ) ) as Record< string, Taxonomy< 'view' > >;\n\treturn map( taxonomies, ( taxonomy, name ) => {\n\t\tconst namespace = taxonomy?.rest_namespace ?? 'wp/v2';\n\t\treturn {\n\t\t\tkind: 'taxonomy',\n\t\t\tbaseURL: `/${ namespace }/${ taxonomy.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: taxonomy.name,\n\t\t};\n\t} );\n}\n\n/**\n * Returns the entity's getter method name given its kind and name.\n *\n * @example\n * ```js\n * const nameSingular = getMethodName( 'root', 'theme', 'get' );\n * // nameSingular is getRootTheme\n *\n * const namePlural = getMethodName( 'root', 'theme', 'set' );\n * // namePlural is setRootThemes\n * ```\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} prefix Function prefix.\n * @param {boolean} usePlural Whether to use the plural form or not.\n *\n * @return {string} Method name\n */\nexport const getMethodName = (\n\tkind,\n\tname,\n\tprefix = 'get',\n\tusePlural = false\n) => {\n\tconst entityConfig = find( rootEntitiesConfig, { kind, name } );\n\tconst kindPrefix = kind === 'root' ? '' : upperFirst( camelCase( kind ) );\n\tconst nameSuffix =\n\t\tupperFirst( camelCase( name ) ) + ( usePlural ? 's' : '' );\n\tconst suffix =\n\t\tusePlural && 'plural' in entityConfig && entityConfig?.plural\n\t\t\t? upperFirst( camelCase( entityConfig.plural ) )\n\t\t\t: nameSuffix;\n\treturn `${ prefix }${ kindPrefix }${ suffix }`;\n};\n\n/**\n * Loads the kind entities into the store.\n *\n * @param {string} kind Kind\n *\n * @return {(thunkArgs: object) => Promise<Array>} Entities\n */\nexport const getOrLoadEntitiesConfig = ( kind ) => async ( {\n\tselect,\n\tdispatch,\n} ) => {\n\tlet configs = select.getEntitiesConfig( kind );\n\tif ( configs && configs.length !== 0 ) {\n\t\treturn configs;\n\t}\n\n\tconst loader = find( additionalEntityConfigLoaders, { kind } );\n\tif ( ! loader ) {\n\t\treturn [];\n\t}\n\n\tconfigs = await loader.loadEntities();\n\tdispatch( addEntities( configs ) );\n\n\treturn configs;\n};\n"]}
|
|
File without changes
|
package/build/hooks/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/constants.ts"],"names":["Status"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/constants.ts"],"names":["Status"],"mappings":";;;;;;IAAkBA,M;;;WAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;GAAAA,M,sBAAAA,M","sourcesContent":["export const enum Status {\n\tIdle = 'IDLE',\n\tResolving = 'RESOLVING',\n\tError = 'ERROR',\n\tSuccess = 'SUCCESS',\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "__experimentalUseEntityRecord", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _useEntityRecord.__experimentalUseEntityRecord;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "__experimentalUseEntityRecords", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _useEntityRecords.__experimentalUseEntityRecords;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "useEntityRecord", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _useEntityRecord.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "useEntityRecords", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _useEntityRecords.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
var _useEntityRecord = _interopRequireWildcard(require("./use-entity-record"));
|
|
32
|
+
|
|
33
|
+
var _useEntityRecords = _interopRequireWildcard(require("./use-entity-records"));
|
|
34
|
+
|
|
35
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
36
|
+
|
|
37
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAIA","sourcesContent":["export {\n\tdefault as useEntityRecord,\n\t__experimentalUseEntityRecord,\n} from './use-entity-record';\nexport {\n\tdefault as useEntityRecords,\n\t__experimentalUseEntityRecords,\n} from './use-entity-records';\n"]}
|
|
@@ -5,12 +5,19 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.__experimentalUseEntityRecord = __experimentalUseEntityRecord;
|
|
9
|
+
exports.default = useEntityRecord;
|
|
10
|
+
|
|
11
|
+
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
9
12
|
|
|
10
13
|
var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
|
|
11
14
|
|
|
12
15
|
var _ = require("../");
|
|
13
16
|
|
|
17
|
+
/**
|
|
18
|
+
* WordPress dependencies
|
|
19
|
+
*/
|
|
20
|
+
|
|
14
21
|
/**
|
|
15
22
|
* Internal dependencies
|
|
16
23
|
*/
|
|
@@ -18,11 +25,10 @@ var _ = require("../");
|
|
|
18
25
|
/**
|
|
19
26
|
* Resolves the specified entity record.
|
|
20
27
|
*
|
|
21
|
-
* @param kind
|
|
22
|
-
* @param name
|
|
23
|
-
* @param recordId
|
|
24
|
-
* @param options
|
|
25
|
-
* @param [options.enabled=true] Whether to run the query or short-circuit and return null. Defaults to true.
|
|
28
|
+
* @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
|
|
29
|
+
* @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
|
|
30
|
+
* @param recordId ID of the requested entity record.
|
|
31
|
+
* @param options Optional hook options.
|
|
26
32
|
* @example
|
|
27
33
|
* ```js
|
|
28
34
|
* import { useEntityRecord } from '@wordpress/core-data';
|
|
@@ -45,10 +51,10 @@ var _ = require("../");
|
|
|
45
51
|
* application, the page and the resolution details will be retrieved from
|
|
46
52
|
* the store state using `getEntityRecord()`, or resolved if missing.
|
|
47
53
|
*
|
|
48
|
-
* @return
|
|
54
|
+
* @return Entity record data.
|
|
49
55
|
* @template RecordType
|
|
50
56
|
*/
|
|
51
|
-
function
|
|
57
|
+
function useEntityRecord(kind, name, recordId) {
|
|
52
58
|
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
53
59
|
enabled: true
|
|
54
60
|
};
|
|
@@ -67,4 +73,12 @@ function __experimentalUseEntityRecord(kind, name, recordId) {
|
|
|
67
73
|
...rest
|
|
68
74
|
};
|
|
69
75
|
}
|
|
76
|
+
|
|
77
|
+
function __experimentalUseEntityRecord(kind, name, recordId, options) {
|
|
78
|
+
(0, _deprecated.default)(`wp.data.__experimentalUseEntityRecord`, {
|
|
79
|
+
alternative: 'wp.data.useEntityRecord',
|
|
80
|
+
since: '6.1'
|
|
81
|
+
});
|
|
82
|
+
return useEntityRecord(kind, name, recordId, options);
|
|
83
|
+
}
|
|
70
84
|
//# sourceMappingURL=use-entity-record.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["useEntityRecord","kind","name","recordId","options","enabled","data","record","rest","query","coreStore","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAiCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,eAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,QAHc,EAKyB;AAAA,MADvCC,OACuC,uEADpB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GACoB;AACvC,QAAM;AAAEC,IAAAA,IAAI,EAAEC,MAAR;AAAgB,OAAGC;AAAnB,MAA4B,6BAC/BC,KAAF,IAAa;AACZ,QAAK,CAAEL,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO,IAAP;AACA;;AACD,WAAOI,KAAK,CAAEC,OAAF,CAAL,CAAmBC,eAAnB,CAAoCV,IAApC,EAA0CC,IAA1C,EAAgDC,QAAhD,CAAP;AACA,GANgC,EAOjC,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAO,CAACC,OAAhC,CAPiC,CAAlC;AAUA,SAAO;AACNE,IAAAA,MADM;AAEN,OAAGC;AAFG,GAAP;AAIA;;AAEM,SAASI,6BAAT,CACNX,IADM,EAENC,IAFM,EAGNC,QAHM,EAINC,OAJM,EAKL;AACD,2BAAa,uCAAb,EAAqD;AACpDS,IAAAA,WAAW,EAAE,yBADuC;AAEpDC,IAAAA,KAAK,EAAE;AAF6C,GAArD;AAIA,SAAOd,eAAe,CAAEC,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAxB,CAAtB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\nimport useEntityRecords from './use-entity-records';\n\nexport interface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nexport interface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\n/**\n * Resolves the specified entity record.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param recordId ID of the requested entity record.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @return Entity record data.\n * @template RecordType\n */\nexport default function useEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { data: record, ...rest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\t...rest,\n\t};\n}\n\nexport function __experimentalUseEntityRecord(\n\tkind: string,\n\tname: string,\n\trecordId: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecord`, {\n\t\talternative: 'wp.data.useEntityRecord',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecord( kind, name, recordId, options );\n}\n"]}
|
|
@@ -5,10 +5,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.__experimentalUseEntityRecords = __experimentalUseEntityRecords;
|
|
9
|
+
exports.default = useEntityRecords;
|
|
9
10
|
|
|
10
11
|
var _url = require("@wordpress/url");
|
|
11
12
|
|
|
13
|
+
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
14
|
+
|
|
12
15
|
var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
|
|
13
16
|
|
|
14
17
|
var _ = require("../");
|
|
@@ -20,14 +23,14 @@ var _ = require("../");
|
|
|
20
23
|
/**
|
|
21
24
|
* Internal dependencies
|
|
22
25
|
*/
|
|
23
|
-
|
|
26
|
+
const EMPTY_ARRAY = [];
|
|
24
27
|
/**
|
|
25
28
|
* Resolves the specified entity records.
|
|
26
29
|
*
|
|
27
|
-
* @param kind Kind of the
|
|
28
|
-
* @param name Name of the
|
|
29
|
-
* @param queryArgs HTTP query for the requested
|
|
30
|
-
* @param options
|
|
30
|
+
* @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
|
|
31
|
+
* @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
|
|
32
|
+
* @param queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.
|
|
33
|
+
* @param options Optional hook options.
|
|
31
34
|
* @example
|
|
32
35
|
* ```js
|
|
33
36
|
* import { useEntityRecord } from '@wordpress/core-data';
|
|
@@ -59,7 +62,8 @@ var _ = require("../");
|
|
|
59
62
|
* @return Entity records data.
|
|
60
63
|
* @template RecordType
|
|
61
64
|
*/
|
|
62
|
-
|
|
65
|
+
|
|
66
|
+
function useEntityRecords(kind, name) {
|
|
63
67
|
let queryArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
64
68
|
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
65
69
|
enabled: true
|
|
@@ -75,7 +79,8 @@ function __experimentalUseEntityRecords(kind, name) {
|
|
|
75
79
|
} = (0, _useQuerySelect.default)(query => {
|
|
76
80
|
if (!options.enabled) {
|
|
77
81
|
return {
|
|
78
|
-
|
|
82
|
+
// Avoiding returning a new reference on every execution.
|
|
83
|
+
data: EMPTY_ARRAY
|
|
79
84
|
};
|
|
80
85
|
}
|
|
81
86
|
|
|
@@ -86,4 +91,12 @@ function __experimentalUseEntityRecords(kind, name) {
|
|
|
86
91
|
...rest
|
|
87
92
|
};
|
|
88
93
|
}
|
|
94
|
+
|
|
95
|
+
function __experimentalUseEntityRecords(kind, name, queryArgs, options) {
|
|
96
|
+
(0, _deprecated.default)(`wp.data.__experimentalUseEntityRecords`, {
|
|
97
|
+
alternative: 'wp.data.useEntityRecords',
|
|
98
|
+
since: '6.1'
|
|
99
|
+
});
|
|
100
|
+
return useEntityRecords(kind, name, queryArgs, options);
|
|
101
|
+
}
|
|
89
102
|
//# sourceMappingURL=use-entity-records.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["EMPTY_ARRAY","useEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","data","records","rest","query","coreStore","getEntityRecords","__experimentalUseEntityRecords","alternative","since"],"mappings":";;;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;AAaA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,gBAAT,CACdC,IADc,EAEdC,IAFc,EAK0B;AAAA,MAFxCC,SAEwC,uEAFD,EAEC;AAAA,MADxCC,OACwC,uEADrB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GACqB;AACxC;AACA;AACA;AACA;AACA,QAAMC,aAAa,GAAG,uBAAc,EAAd,EAAkBH,SAAlB,CAAtB;AAEA,QAAM;AAAEI,IAAAA,IAAI,EAAEC,OAAR;AAAiB,OAAGC;AAApB,MAA6B,6BAChCC,KAAF,IAAa;AACZ,QAAK,CAAEN,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO;AACN;AACAE,QAAAA,IAAI,EAAER;AAFA,OAAP;AAIA;;AACD,WAAOW,KAAK,CAAEC,OAAF,CAAL,CAAmBC,gBAAnB,CAAqCX,IAArC,EAA2CC,IAA3C,EAAiDC,SAAjD,CAAP;AACA,GATiC,EAUlC,CAAEF,IAAF,EAAQC,IAAR,EAAcI,aAAd,EAA6BF,OAAO,CAACC,OAArC,CAVkC,CAAnC;AAaA,SAAO;AACNG,IAAAA,OADM;AAEN,OAAGC;AAFG,GAAP;AAIA;;AAEM,SAASI,8BAAT,CACNZ,IADM,EAENC,IAFM,EAGNC,SAHM,EAINC,OAJM,EAKL;AACD,2BAAa,wCAAb,EAAsD;AACrDU,IAAAA,WAAW,EAAE,0BADwC;AAErDC,IAAAA,KAAK,EAAE;AAF8C,GAAtD;AAIA,SAAOf,gBAAgB,CAAEC,IAAF,EAAQC,IAAR,EAAcC,SAAd,EAAyBC,OAAzB,CAAvB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Options, EntityRecordResolution } from './use-entity-record';\n\ntype EntityRecordsResolution< RecordType > = Omit<\n\tEntityRecordResolution< RecordType >,\n\t'record'\n> & {\n\t/** The requested entity record */\n\trecords: RecordType[] | null;\n};\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Resolves the specified entity records.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitlesList() {\n * const { records, isResolving } = useEntityRecords( 'postType', 'page' );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return (\n * <ul>\n * {records.map(( page ) => (\n * <li>{ page.title }</li>\n * ))}\n * </ul>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PageTitlesList />\n * ```\n *\n * In the above example, when `PageTitlesList` is rendered into an\n * application, the list of records and the resolution details will be retrieved from\n * the store state using `getEntityRecords()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template RecordType\n */\nexport default function useEntityRecords< RecordType >(\n\tkind: string,\n\tname: string,\n\tqueryArgs: Record< string, unknown > = {},\n\toptions: Options = { enabled: true }\n): EntityRecordsResolution< RecordType > {\n\t// Serialize queryArgs to a string that can be safely used as a React dep.\n\t// We can't just pass queryArgs as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst queryAsString = addQueryArgs( '', queryArgs );\n\n\tconst { data: records, ...rest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\t// Avoiding returning a new reference on every execution.\n\t\t\t\t\tdata: EMPTY_ARRAY,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecords( kind, name, queryArgs );\n\t\t},\n\t\t[ kind, name, queryAsString, options.enabled ]\n\t);\n\n\treturn {\n\t\trecords,\n\t\t...rest,\n\t};\n}\n\nexport function __experimentalUseEntityRecords(\n\tkind: string,\n\tname: string,\n\tqueryArgs: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecords`, {\n\t\talternative: 'wp.data.useEntityRecords',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecords( kind, name, queryArgs, options );\n}\n"]}
|
package/build/index.js
CHANGED
|
@@ -7,9 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
var _exportNames = {
|
|
9
9
|
store: true,
|
|
10
|
-
EntityProvider: true
|
|
11
|
-
__experimentalUseEntityRecord: true,
|
|
12
|
-
__experimentalUseEntityRecords: true
|
|
10
|
+
EntityProvider: true
|
|
13
11
|
};
|
|
14
12
|
Object.defineProperty(exports, "EntityProvider", {
|
|
15
13
|
enumerable: true,
|
|
@@ -17,18 +15,6 @@ Object.defineProperty(exports, "EntityProvider", {
|
|
|
17
15
|
return _entityProvider.default;
|
|
18
16
|
}
|
|
19
17
|
});
|
|
20
|
-
Object.defineProperty(exports, "__experimentalUseEntityRecord", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: function () {
|
|
23
|
-
return _useEntityRecord.default;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
Object.defineProperty(exports, "__experimentalUseEntityRecords", {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
get: function () {
|
|
29
|
-
return _useEntityRecords.default;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
18
|
exports.store = void 0;
|
|
33
19
|
|
|
34
20
|
var _data = require("@wordpress/data");
|
|
@@ -61,9 +47,19 @@ Object.keys(_entityProvider).forEach(function (key) {
|
|
|
61
47
|
});
|
|
62
48
|
});
|
|
63
49
|
|
|
64
|
-
var
|
|
50
|
+
var _entityTypes = require("./entity-types");
|
|
65
51
|
|
|
66
|
-
|
|
52
|
+
Object.keys(_entityTypes).forEach(function (key) {
|
|
53
|
+
if (key === "default" || key === "__esModule") return;
|
|
54
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
55
|
+
if (key in exports && exports[key] === _entityTypes[key]) return;
|
|
56
|
+
Object.defineProperty(exports, key, {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function () {
|
|
59
|
+
return _entityTypes[key];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
67
63
|
|
|
68
64
|
var _fetch = require("./fetch");
|
|
69
65
|
|
|
@@ -79,16 +75,16 @@ Object.keys(_fetch).forEach(function (key) {
|
|
|
79
75
|
});
|
|
80
76
|
});
|
|
81
77
|
|
|
82
|
-
var
|
|
78
|
+
var _hooks = require("./hooks");
|
|
83
79
|
|
|
84
|
-
Object.keys(
|
|
80
|
+
Object.keys(_hooks).forEach(function (key) {
|
|
85
81
|
if (key === "default" || key === "__esModule") return;
|
|
86
82
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
87
|
-
if (key in exports && exports[key] ===
|
|
83
|
+
if (key in exports && exports[key] === _hooks[key]) return;
|
|
88
84
|
Object.defineProperty(exports, key, {
|
|
89
85
|
enumerable: true,
|
|
90
86
|
get: function () {
|
|
91
|
-
return
|
|
87
|
+
return _hooks[key];
|
|
92
88
|
}
|
|
93
89
|
});
|
|
94
90
|
});
|