@wordpress/core-data 4.7.0 → 4.10.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 +56 -56
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +1 -1
- package/build/batch/create-batch.js.map +1 -1
- package/build/batch/default-processor.js +13 -7
- package/build/batch/default-processor.js.map +1 -1
- package/build/entities.js +49 -35
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js.map +1 -1
- package/build/entity-types/entities.js +6 -0
- package/build/entity-types/entities.js.map +1 -0
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/hooks/use-resource-permissions.js +94 -0
- package/build/hooks/use-resource-permissions.js.map +1 -0
- package/build/index.js +28 -1
- package/build/index.js.map +1 -1
- package/build/queried-data/selectors.js.map +1 -1
- package/build/resolvers.js +4 -14
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +45 -8
- package/build/selectors.js.map +1 -1
- package/build/utils/forward-resolver.js.map +1 -1
- package/build/utils/on-sub-key.js.map +1 -1
- package/build/utils/with-weak-map-cache.js +1 -7
- package/build/utils/with-weak-map-cache.js.map +1 -1
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +2 -2
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/batch/default-processor.js +12 -5
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/entities.js +49 -35
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/entity-types/entities.js +2 -0
- package/build-module/entity-types/entities.js.map +1 -0
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/hooks/use-resource-permissions.js +82 -0
- package/build-module/hooks/use-resource-permissions.js.map +1 -0
- package/build-module/index.js +3 -0
- package/build-module/index.js.map +1 -1
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/resolvers.js +5 -15
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +40 -4
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/forward-resolver.js.map +1 -1
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/build-module/utils/with-weak-map-cache.js +1 -6
- package/build-module/utils/with-weak-map-cache.js.map +1 -1
- package/package.json +12 -12
- package/src/actions.js +389 -372
- package/src/batch/create-batch.js +2 -2
- package/src/batch/default-processor.js +10 -5
- package/src/entities.ts +357 -135
- package/src/entity-provider.js +4 -6
- package/src/entity-types/attachment.ts +4 -3
- package/src/entity-types/comment.ts +4 -3
- package/src/entity-types/entities.ts +130 -0
- package/src/entity-types/index.ts +115 -20
- package/src/entity-types/menu-location.ts +4 -3
- package/src/entity-types/nav-menu-item.ts +4 -3
- package/src/entity-types/nav-menu.ts +3 -3
- package/src/entity-types/page.ts +3 -3
- package/src/entity-types/plugin.ts +3 -3
- package/src/entity-types/post.ts +3 -3
- package/src/entity-types/settings.ts +3 -3
- package/src/entity-types/sidebar.ts +4 -3
- package/src/entity-types/taxonomy.ts +4 -3
- package/src/entity-types/theme.ts +3 -3
- package/src/entity-types/type.ts +3 -3
- package/src/entity-types/user.ts +3 -3
- package/src/entity-types/widget-type.ts +4 -3
- package/src/entity-types/widget.ts +3 -3
- package/src/entity-types/wp-template-part.ts +4 -3
- package/src/entity-types/wp-template.ts +4 -3
- package/src/fetch/test/__experimental-fetch-link-suggestions.js +2 -4
- package/src/hooks/test/use-query-select.js +4 -2
- package/src/hooks/test/use-resource-permissions.js +115 -0
- package/src/hooks/use-entity-record.ts +0 -1
- package/src/hooks/use-query-select.ts +26 -24
- package/src/hooks/use-resource-permissions.ts +120 -0
- package/src/index.js +3 -0
- package/src/locks/test/selectors.js +2 -1
- package/src/queried-data/selectors.js +2 -8
- package/src/resolvers.js +344 -326
- package/src/selectors.ts +347 -194
- package/src/test/reducer.js +5 -4
- package/src/test/resolvers.js +1 -3
- package/src/test/selectors.js +1 -2
- package/src/utils/forward-resolver.js +6 -5
- package/src/utils/on-sub-key.js +20 -20
- package/src/utils/with-weak-map-cache.js +1 -6
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,7 +157,8 @@ const rootEntitiesConfig = [{
|
|
|
155
157
|
plural: 'menuLocations',
|
|
156
158
|
label: (0, _i18n.__)('Menu Location'),
|
|
157
159
|
key: 'name'
|
|
158
|
-
}
|
|
160
|
+
};
|
|
161
|
+
const globalStyleConfig = {
|
|
159
162
|
label: (0, _i18n.__)('Global Styles'),
|
|
160
163
|
name: 'globalStyles',
|
|
161
164
|
kind: 'root',
|
|
@@ -170,7 +173,8 @@ const rootEntitiesConfig = [{
|
|
|
170
173
|
|
|
171
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);
|
|
172
175
|
}
|
|
173
|
-
}
|
|
176
|
+
};
|
|
177
|
+
const themeConfig = {
|
|
174
178
|
label: (0, _i18n.__)('Themes'),
|
|
175
179
|
name: 'theme',
|
|
176
180
|
kind: 'root',
|
|
@@ -179,7 +183,8 @@ const rootEntitiesConfig = [{
|
|
|
179
183
|
context: 'edit'
|
|
180
184
|
},
|
|
181
185
|
key: 'stylesheet'
|
|
182
|
-
}
|
|
186
|
+
};
|
|
187
|
+
const pluginConfig = {
|
|
183
188
|
label: (0, _i18n.__)('Plugins'),
|
|
184
189
|
name: 'plugin',
|
|
185
190
|
kind: 'root',
|
|
@@ -188,7 +193,16 @@ const rootEntitiesConfig = [{
|
|
|
188
193
|
context: 'edit'
|
|
189
194
|
},
|
|
190
195
|
key: 'plugin'
|
|
191
|
-
}
|
|
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];
|
|
192
206
|
exports.rootEntitiesConfig = rootEntitiesConfig;
|
|
193
207
|
const additionalEntityConfigLoaders = [{
|
|
194
208
|
kind: 'postType',
|
|
@@ -324,7 +338,7 @@ const getMethodName = function (kind, name) {
|
|
|
324
338
|
});
|
|
325
339
|
const kindPrefix = kind === 'root' ? '' : (0, _lodash.upperFirst)((0, _lodash.camelCase)(kind));
|
|
326
340
|
const nameSuffix = (0, _lodash.upperFirst)((0, _lodash.camelCase)(name)) + (usePlural ? 's' : '');
|
|
327
|
-
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;
|
|
328
342
|
return `${prefix}${kindPrefix}${suffix}`;
|
|
329
343
|
};
|
|
330
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","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;;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;;;;AACO,MAAMC,uBAAuB,GAAKlD,IAAF,IAAY,cAG5C;AAAA,MAHoD;AAC1DmD,IAAAA,MAD0D;AAE1DC,IAAAA;AAF0D,GAGpD;AACN,MAAIC,OAAO,GAAGF,MAAM,CAACG,iBAAP,CAA0BtD,IAA1B,CAAd;;AACA,MAAKqD,OAAO,IAAIA,OAAO,CAACE,MAAR,KAAmB,CAAnC,EAAuC;AACtC,WAAOF,OAAP;AACA;;AAED,QAAMG,MAAM,GAAG,kBAAMzC,6BAAN,EAAqC;AAAEf,IAAAA;AAAF,GAArC,CAAf;;AACA,MAAK,CAAEwD,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\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;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AAAA;AAAR,GAA1B,CAArB;AACA,QAAMgE,UAAU,GAAG/D,IAAI,KAAK,MAAT,GAAkB,EAAlB,GAAuB,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,IAA0CA,YAA1C,aAA0CA,YAA1C,eAA0CA,YAAY,CAAE1D,MAAxD,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,GACjClE,IAAF,IACA,cAAkC;AAAA,MAA1B;AAAEmE,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAA0B;AACjC,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,CAjBK","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 =\n\t( kind ) =>\n\tasync ( { select, dispatch } ) => {\n\t\tlet configs = select.getEntitiesConfig( kind );\n\t\tif ( configs && configs.length !== 0 ) {\n\t\t\treturn configs;\n\t\t}\n\n\t\tconst loader = find( additionalEntityConfigLoaders, { kind } );\n\t\tif ( ! loader ) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconfigs = await loader.loadEntities();\n\t\tdispatch( addEntities( configs ) );\n\n\t\treturn configs;\n\t};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/entity-provider.js"],"names":["EMPTY_ARRAY","entityContexts","rootEntitiesConfig","reduce","acc","loader","kind","name","context","undefined","additionalEntityConfigLoaders","getEntityContext","Error","EntityProvider","type","id","children","Provider","useEntityId","useEntityProp","prop","_id","providerId","value","fullValue","select","getEntityRecord","getEditedEntityRecord","STORE_NAME","record","editedRecord","editEntityRecord","setValue","newValue","useEntityBlockEditor","content","blocks","__unstableCreateUndoLevel","parsedContent","undoIgnore","onChange","newBlocks","options","selection","edits","noChange","blocksForSerialization","onInput"],"mappings":";;;;;;;;;;AAGA;;AAMA;;AACA;;AAKA;;AASA;;AAxBA;AACA;AACA;;AAUA;AACA;AACA;;AAGA;AAEA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;;AAGA,MAAMC,cAAc,GAAG,EACtB,GAAGC,6BAAmBC,MAAnB,CAA2B,CAAEC,GAAF,EAAOC,MAAP,KAAmB;AAChD,QAAK,CAAED,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAV,EAA4B;AAC3BF,MAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,GAAqB,EAArB;AACA;;AACDF,IAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,CAAoBD,MAAM,CAACE,IAA3B,IAAoC;AACnCC,MAAAA,OAAO,EAAE,4BAAe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EAAyB+C,OAAzB,EAAkCP,QAAlC,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseCallback,\n\tuseEffect,\n} from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\n\n/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Internal dependencies\n */\nimport { rootEntitiesConfig, additionalEntityConfigLoaders } from './entities';\n\nconst entityContexts = {\n\t...rootEntitiesConfig.reduce( ( acc, loader ) => {\n\t\tif ( ! acc[ loader.kind ] ) {\n\t\t\tacc[ loader.kind ] = {};\n\t\t}\n\t\tacc[ loader.kind ][ loader.name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t\treturn acc;\n\t}, {} ),\n\t...additionalEntityConfigLoaders.reduce( ( acc, loader ) => {\n\t\tacc[ loader.kind ] = {};\n\t\treturn acc;\n\t}, {} ),\n};\nconst getEntityContext = ( kind, name ) => {\n\tif ( ! entityContexts[ kind ] ) {\n\t\tthrow new Error( `Missing entity config for kind: ${ kind }.` );\n\t}\n\n\tif ( ! entityContexts[ kind ][ name ] ) {\n\t\tentityContexts[ kind ][ name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t}\n\n\treturn entityContexts[ kind ][ name ].context;\n};\n\n/**\n * Context provider component for providing\n * an entity for a specific entity.\n *\n * @param {Object} props The component's props.\n * @param {string} props.kind The entity kind.\n * @param {string} props.type The entity name.\n * @param {number} props.id The entity ID.\n * @param {*} props.children The children to wrap.\n *\n * @return {Object} The provided children, wrapped with\n * the entity's context provider.\n */\nexport default function EntityProvider( { kind, type: name, id, children } ) {\n\tconst Provider = getEntityContext( kind, name ).Provider;\n\treturn <Provider value={ id }>{ children }</Provider>;\n}\n\n/**\n * Hook that returns the ID for the nearest\n * provided entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n */\nexport function useEntityId( kind, name ) {\n\treturn useContext( getEntityContext( kind, name ) );\n}\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {string} prop The property name.\n * @param {string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } = select(\n\t\t\t\tSTORE_NAME\n\t\t\t);\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * peristent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[WPBlock[], Function, Function]} The block array and setters.\n */\nexport function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { content, blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord } = select( STORE_NAME );\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn {\n\t\t\t\tblocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t};\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } = useDispatch(\n\t\tSTORE_NAME\n\t);\n\n\tuseEffect( () => {\n\t\t// Load the blocks from the content if not already in state\n\t\t// Guard against other instances that might have\n\t\t// set content to a function already or the blocks are already in state.\n\t\tif ( content && typeof content !== 'function' && ! blocks ) {\n\t\t\tconst parsedContent = parse( content );\n\t\t\teditEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\tblocks: parsedContent,\n\t\t\t\t},\n\t\t\t\t{ undoIgnore: true }\n\t\t\t);\n\t\t}\n\t}, [ content ] );\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst edits = { blocks: newBlocks, selection };\n\n\t\t\tconst noChange = blocks === edits.blocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, name, id );\n\t\t\t}\n\n\t\t\t// We create a new function here on every persistent edit\n\t\t\t// to make sure the edit makes the post dirty and creates\n\t\t\t// a new undo level.\n\t\t\tedits.content = ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t__unstableSerializeAndClean( blocksForSerialization );\n\n\t\t\teditEntityRecord( kind, name, id, edits );\n\t\t},\n\t\t[ kind, name, id, blocks ]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst edits = { blocks: newBlocks, selection };\n\t\t\teditEntityRecord( kind, name, id, edits );\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\n\treturn [ blocks ?? EMPTY_ARRAY, onInput, onChange ];\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/entity-provider.js"],"names":["EMPTY_ARRAY","entityContexts","rootEntitiesConfig","reduce","acc","loader","kind","name","context","undefined","additionalEntityConfigLoaders","getEntityContext","Error","EntityProvider","type","id","children","Provider","useEntityId","useEntityProp","prop","_id","providerId","value","fullValue","select","getEntityRecord","getEditedEntityRecord","STORE_NAME","record","editedRecord","editEntityRecord","setValue","newValue","useEntityBlockEditor","content","blocks","__unstableCreateUndoLevel","parsedContent","undoIgnore","onChange","newBlocks","options","selection","edits","noChange","blocksForSerialization","onInput"],"mappings":";;;;;;;;;;AAGA;;AAMA;;AACA;;AAKA;;AASA;;AAxBA;AACA;AACA;;AAUA;AACA;AACA;;AAGA;AAEA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;;AAGA,MAAMC,cAAc,GAAG,EACtB,GAAGC,6BAAmBC,MAAnB,CAA2B,CAAEC,GAAF,EAAOC,MAAP,KAAmB;AAChD,QAAK,CAAED,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAV,EAA4B;AAC3BF,MAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,GAAqB,EAArB;AACA;;AACDF,IAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,CAAoBD,MAAM,CAACE,IAA3B,IAAoC;AACnCC,MAAAA,OAAO,EAAE,4BAAeC,SAAf;AAD0B,KAApC;AAGA,WAAOL,GAAP;AACA,GARE,EAQA,EARA,CADmB;AAUtB,KAAGM,wCAA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seContext,\n\tuseCallback,\n\tuseEffect,\n} from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\n\n/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Internal dependencies\n */\nimport { rootEntitiesConfig, additionalEntityConfigLoaders } from './entities';\n\nconst entityContexts = {\n\t...rootEntitiesConfig.reduce( ( acc, loader ) => {\n\t\tif ( ! acc[ loader.kind ] ) {\n\t\t\tacc[ loader.kind ] = {};\n\t\t}\n\t\tacc[ loader.kind ][ loader.name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t\treturn acc;\n\t}, {} ),\n\t...additionalEntityConfigLoaders.reduce( ( acc, loader ) => {\n\t\tacc[ loader.kind ] = {};\n\t\treturn acc;\n\t}, {} ),\n};\nconst getEntityContext = ( kind, name ) => {\n\tif ( ! entityContexts[ kind ] ) {\n\t\tthrow new Error( `Missing entity config for kind: ${ kind }.` );\n\t}\n\n\tif ( ! entityContexts[ kind ][ name ] ) {\n\t\tentityContexts[ kind ][ name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t}\n\n\treturn entityContexts[ kind ][ name ].context;\n};\n\n/**\n * Context provider component for providing\n * an entity for a specific entity.\n *\n * @param {Object} props The component's props.\n * @param {string} props.kind The entity kind.\n * @param {string} props.type The entity name.\n * @param {number} props.id The entity ID.\n * @param {*} props.children The children to wrap.\n *\n * @return {Object} The provided children, wrapped with\n * the entity's context provider.\n */\nexport default function EntityProvider( { kind, type: name, id, children } ) {\n\tconst Provider = getEntityContext( kind, name ).Provider;\n\treturn <Provider value={ id }>{ children }</Provider>;\n}\n\n/**\n * Hook that returns the ID for the nearest\n * provided entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n */\nexport function useEntityId( kind, name ) {\n\treturn useContext( getEntityContext( kind, name ) );\n}\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {string} prop The property name.\n * @param {string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * peristent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[WPBlock[], Function, Function]} The block array and setters.\n */\nexport function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { content, blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord } = select( STORE_NAME );\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn {\n\t\t\t\tblocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t};\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } =\n\t\tuseDispatch( STORE_NAME );\n\n\tuseEffect( () => {\n\t\t// Load the blocks from the content if not already in state\n\t\t// Guard against other instances that might have\n\t\t// set content to a function already or the blocks are already in state.\n\t\tif ( content && typeof content !== 'function' && ! blocks ) {\n\t\t\tconst parsedContent = parse( content );\n\t\t\teditEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\tblocks: parsedContent,\n\t\t\t\t},\n\t\t\t\t{ undoIgnore: true }\n\t\t\t);\n\t\t}\n\t}, [ content ] );\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst edits = { blocks: newBlocks, selection };\n\n\t\t\tconst noChange = blocks === edits.blocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, name, id );\n\t\t\t}\n\n\t\t\t// We create a new function here on every persistent edit\n\t\t\t// to make sure the edit makes the post dirty and creates\n\t\t\t// a new undo level.\n\t\t\tedits.content = ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t__unstableSerializeAndClean( blocksForSerialization );\n\n\t\t\teditEntityRecord( kind, name, id, edits );\n\t\t},\n\t\t[ kind, name, id, blocks ]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst edits = { blocks: newBlocks, selection };\n\t\t\teditEntityRecord( kind, name, id, edits );\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\n\treturn [ blocks ?? EMPTY_ARRAY, onInput, onChange ];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -1 +1 @@
|
|
|
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;;
|
|
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;;AAgCA;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';\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"names":["META_SELECTORS","__experimentalUseQuerySelect","mapQuerySelect","deps","select","registry","resolve","store","enrichSelectors","selectors","resolvers","selectorName","includes","Object","defineProperty","get","getIsResolving","hasFinishedResolution","args","isResolving","hasResolved","data","status","Status","Resolving","Success","Error","Idle"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;AAIO,MAAMA,cAAc,GAAG,CAC7B,gBAD6B,EAE7B,sBAF6B,EAG7B,uBAH6B,EAI7B,aAJ6B,EAK7B,oBAL6B,CAAvB;;;AAsBP;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;AACA;AACA;AACe,SAASC,4BAAT,CAAuCC,cAAvC,EAAuDC,IAAvD,EAA8D;AAC5E,SAAO,qBAAW,CAAEC,MAAF,EAAUC,QAAV,KAAwB;AACzC,UAAMC,OAAO,GAAKC,KAAF,IAAaC,eAAe,CAAEJ,MAAM,CAAEG,KAAF,CAAR,CAA5C;;AACA,WAAOL,cAAc,CAAEI,OAAF,EAAWD,QAAX,CAArB;AACA,GAHM,EAGJF,IAHI,CAAP;AAIA;;AAYD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMK,eAAe,GAAG,sBAAaC,SAAF,IAAiB;AACnD,QAAMC,SAAS,GAAG,EAAlB;;AACA,OAAM,MAAMC,YAAZ,IAA4BF,SAA5B,EAAwC;AACvC,QAAKT,cAAc,CAACY,QAAf,CAAyBD,YAAzB,CAAL,EAA+C;AAC9C;AACA;;AACDE,IAAAA,MAAM,CAACC,cAAP,CAAuBJ,SAAvB,EAAkCC,YAAlC,EAAgD;AAC/CI,MAAAA,GAAG,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"names":["META_SELECTORS","__experimentalUseQuerySelect","mapQuerySelect","deps","select","registry","resolve","store","enrichSelectors","selectors","resolvers","selectorName","includes","Object","defineProperty","get","getIsResolving","hasFinishedResolution","args","isResolving","hasResolved","data","status","Status","Resolving","Success","Error","Idle"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;AAIO,MAAMA,cAAc,GAAG,CAC7B,gBAD6B,EAE7B,sBAF6B,EAG7B,uBAH6B,EAI7B,aAJ6B,EAK7B,oBAL6B,CAAvB;;;AAsBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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EAAY;AACXC,YAAAA,MAAM,GAAGC,kBAAOE,OAAhB;AACA,WAFD,MAEO;AACNH,YAAAA,MAAM,GAAGC,kBAAOG,KAAhB;AACA;AACD,SANM,MAMA;AACNJ,UAAAA,MAAM,GAAGC,kBAAOI,IAAhB;AACA;;AAED,eAAO;AACNN,UAAAA,IADM;AAENC,UAAAA,MAFM;AAGNH,UAAAA,WAHM;AAINC,UAAAA;AAJM,SAAP;AAMA;AA9B6C,KAAhD;AAgCA;;AACD,SAAOV,SAAP;AACA,CAxCuB,CAAxB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport memoize from './memoize';\nimport { Status } from './constants';\n\nexport const META_SELECTORS = [\n\t'getIsResolving',\n\t'hasStartedResolution',\n\t'hasFinishedResolution',\n\t'isResolving',\n\t'getCachedResolvers',\n];\n\ninterface QuerySelectResponse< Data > {\n\t/** the requested selector return value */\n\tdata: Data;\n\n\t/** is the record still being resolved? Via the `getIsResolving` meta-selector */\n\tisResolving: boolean;\n\n\t/** was the resolution started? Via the `hasStartedResolution` meta-selector */\n\thasStarted: boolean;\n\n\t/** has the resolution finished? Via the `hasFinishedResolution` meta-selector. */\n\thasResolved: boolean;\n}\n\n/**\n * Like useSelect, but the selectors return objects containing\n * both the original data AND the resolution info.\n *\n * @param {Function} mapQuerySelect see useSelect\n * @param {Array} deps see useSelect\n *\n * @example\n * ```js\n * import { useQuerySelect } from '@wordpress/data';\n * import { store as coreDataStore } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { data: page, isResolving } = useQuerySelect( ( query ) => {\n * return query( coreDataStore ).getEntityRecord( 'postType', 'page', id )\n * }, [ id ] );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return page.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 10 } />\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 the `mapSelect` callback on `useQuerySelect`.\n *\n * If the id prop changes then any page in the state for that id is\n * retrieved. If the id prop doesn't change and other props are passed in\n * that do change, the title will not change because the dependency is just\n * the id.\n * @see useSelect\n *\n * @return {QuerySelectResponse} Queried data.\n */\nexport default function __experimentalUseQuerySelect( mapQuerySelect, deps ) {\n\treturn useSelect( ( select, registry ) => {\n\t\tconst resolve = ( store ) => enrichSelectors( select( store ) );\n\t\treturn mapQuerySelect( resolve, registry );\n\t}, deps );\n}\n\ninterface EnrichedSelectors {\n\t< Selectors extends Record< string, ( ...args: any[] ) => any > >(\n\t\tselectors: Selectors\n\t): {\n\t\t[ Selector in keyof Selectors ]: (\n\t\t\t...args: Parameters< Selectors[ Selector ] >\n\t\t) => QuerySelectResponse< ReturnType< Selectors[ Selector ] > >;\n\t};\n}\n\n/**\n * Transform simple selectors into ones that return an object with the\n * original return value AND the resolution info.\n *\n * @param {Object} selectors Selectors to enrich\n * @return {EnrichedSelectors} Enriched selectors\n */\nconst enrichSelectors = memoize( ( ( selectors ) => {\n\tconst resolvers = {};\n\tfor ( const selectorName in selectors ) {\n\t\tif ( META_SELECTORS.includes( selectorName ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tObject.defineProperty( resolvers, selectorName, {\n\t\t\tget:\n\t\t\t\t() =>\n\t\t\t\t( ...args: unknown[] ) => {\n\t\t\t\t\tconst { getIsResolving, hasFinishedResolution } = selectors;\n\t\t\t\t\tconst isResolving = !! getIsResolving( selectorName, args );\n\t\t\t\t\tconst hasResolved =\n\t\t\t\t\t\t! isResolving &&\n\t\t\t\t\t\thasFinishedResolution( selectorName, args );\n\t\t\t\t\tconst data = selectors[ selectorName ]( ...args );\n\n\t\t\t\t\tlet status;\n\t\t\t\t\tif ( isResolving ) {\n\t\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\t\tif ( data ) {\n\t\t\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tstatus = Status.Error;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstatus = Status.Idle;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t\tisResolving,\n\t\t\t\t\t\thasResolved,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t} );\n\t}\n\treturn resolvers;\n} ) as EnrichedSelectors );\n"]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = __experimentalUseResourcePermissions;
|
|
9
|
+
|
|
10
|
+
var _ = require("../");
|
|
11
|
+
|
|
12
|
+
var _constants = require("./constants");
|
|
13
|
+
|
|
14
|
+
var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Resolves resource permissions.
|
|
22
|
+
*
|
|
23
|
+
* @param resource The resource in question, e.g. media.
|
|
24
|
+
* @param id ID of a specific resource entry, if needed, e.g. 10.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```js
|
|
28
|
+
* import { useResourcePermissions } from '@wordpress/core-data';
|
|
29
|
+
*
|
|
30
|
+
* function PagesList() {
|
|
31
|
+
* const { canCreate, isResolving } = useResourcePermissions( 'pages' );
|
|
32
|
+
*
|
|
33
|
+
* if ( isResolving ) {
|
|
34
|
+
* return 'Loading ...';
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* return (
|
|
38
|
+
* <div>
|
|
39
|
+
* {canCreate ? (<button>+ Create a new page</button>) : false}
|
|
40
|
+
* // ...
|
|
41
|
+
* </div>
|
|
42
|
+
* );
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* // Rendered in the application:
|
|
46
|
+
* // <PagesList />
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* In the above example, when `PagesList` is rendered into an
|
|
50
|
+
* application, the appropriate permissions and the resolution details will be retrieved from
|
|
51
|
+
* the store state using `canUser()`, or resolved if missing.
|
|
52
|
+
*
|
|
53
|
+
* @return Entity records data.
|
|
54
|
+
* @template IdType
|
|
55
|
+
*/
|
|
56
|
+
function __experimentalUseResourcePermissions(resource, id) {
|
|
57
|
+
return (0, _useQuerySelect.default)(resolve => {
|
|
58
|
+
const {
|
|
59
|
+
canUser
|
|
60
|
+
} = resolve(_.store);
|
|
61
|
+
const create = canUser('create', resource);
|
|
62
|
+
|
|
63
|
+
if (!id) {
|
|
64
|
+
return [create.hasResolved, {
|
|
65
|
+
status: create.status,
|
|
66
|
+
isResolving: create.isResolving,
|
|
67
|
+
canCreate: create.hasResolved && create.data
|
|
68
|
+
}];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const update = canUser('update', resource, id);
|
|
72
|
+
|
|
73
|
+
const _delete = canUser('delete', resource, id);
|
|
74
|
+
|
|
75
|
+
const isResolving = create.isResolving || update.isResolving || _delete.isResolving;
|
|
76
|
+
const hasResolved = create.hasResolved && update.hasResolved && _delete.hasResolved;
|
|
77
|
+
let status = _constants.Status.Idle;
|
|
78
|
+
|
|
79
|
+
if (isResolving) {
|
|
80
|
+
status = _constants.Status.Resolving;
|
|
81
|
+
} else if (hasResolved) {
|
|
82
|
+
status = _constants.Status.Success;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return [hasResolved, {
|
|
86
|
+
status,
|
|
87
|
+
isResolving,
|
|
88
|
+
canCreate: hasResolved && create.data,
|
|
89
|
+
canUpdate: hasResolved && update.data,
|
|
90
|
+
canDelete: hasResolved && _delete.data
|
|
91
|
+
}];
|
|
92
|
+
}, [resource, id]);
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=use-resource-permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"names":["__experimentalUseResourcePermissions","resource","id","resolve","canUser","coreStore","create","hasResolved","status","isResolving","canCreate","data","update","_delete","Status","Idle","Resolving","Success","canUpdate","canDelete"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;;AAoCA;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,SAASA,oCAAT,CACdC,QADc,EAEdC,EAFc,EAG4B;AAC1C,SAAO,6BACJC,OAAF,IAAe;AACd,UAAM;AAAEC,MAAAA;AAAF,QAAcD,OAAO,CAAEE,OAAF,CAA3B;AACA,UAAMC,MAAM,GAAGF,OAAO,CAAE,QAAF,EAAYH,QAAZ,CAAtB;;AACA,QAAK,CAAEC,EAAP,EAAY;AACX,aAAO,CACNI,MAAM,CAACC,WADD,EAEN;AACCC,QAAAA,MAAM,EAAEF,MAAM,CAACE,MADhB;AAECC,QAAAA,WAAW,EAAEH,MAAM,CAACG,WAFrB;AAGCC,QAAAA,SAAS,EAAEJ,MAAM,CAACC,WAAP,IAAsBD,MAAM,CAACK;AAHzC,OAFM,CAAP;AAQA;;AAED,UAAMC,MAAM,GAAGR,OAAO,CAAE,QAAF,EAAYH,QAAZ,EAAsBC,EAAtB,CAAtB;;AACA,UAAMW,OAAO,GAAGT,OAAO,CAAE,QAAF,EAAYH,QAAZ,EAAsBC,EAAtB,CAAvB;;AACA,UAAMO,WAAW,GAChBH,MAAM,CAACG,WAAP,IAAsBG,MAAM,CAACH,WAA7B,IAA4CI,OAAO,CAACJ,WADrD;AAEA,UAAMF,WAAW,GAChBD,MAAM,CAACC,WAAP,IAAsBK,MAAM,CAACL,WAA7B,IAA4CM,OAAO,CAACN,WADrD;AAGA,QAAIC,MAAM,GAAGM,kBAAOC,IAApB;;AACA,QAAKN,WAAL,EAAmB;AAClBD,MAAAA,MAAM,GAAGM,kBAAOE,SAAhB;AACA,KAFD,MAEO,IAAKT,WAAL,EAAmB;AACzBC,MAAAA,MAAM,GAAGM,kBAAOG,OAAhB;AACA;;AACD,WAAO,CACNV,WADM,EAEN;AACCC,MAAAA,MADD;AAECC,MAAAA,WAFD;AAGCC,MAAAA,SAAS,EAAEH,WAAW,IAAID,MAAM,CAACK,IAHlC;AAICO,MAAAA,SAAS,EAAEX,WAAW,IAAIK,MAAM,CAACD,IAJlC;AAKCQ,MAAAA,SAAS,EAAEZ,WAAW,IAAIM,OAAO,CAACF;AALnC,KAFM,CAAP;AAUA,GAtCK,EAuCN,CAAEV,QAAF,EAAYC,EAAZ,CAvCM,CAAP;AAyCA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\nimport useQuerySelect from './use-query-select';\n\ninterface GlobalResourcePermissionsResolution {\n\t/** Can the current user create new resources of this type? */\n\tcanCreate: boolean;\n}\ninterface SpecificResourcePermissionsResolution {\n\t/** Can the current user update resources of this type? */\n\tcanUpdate: boolean;\n\t/** Can the current user delete resources of this type? */\n\tcanDelete: boolean;\n}\ninterface ResolutionDetails {\n\t/** Resolution status */\n\tstatus: Status;\n\t/**\n\t * Is the data still being resolved?\n\t */\n\tisResolving: boolean;\n}\n\n/**\n * Is the data resolved by now?\n */\ntype HasResolved = boolean;\n\ntype ResourcePermissionsResolution< IdType > = [\n\tHasResolved,\n\tResolutionDetails &\n\t\tGlobalResourcePermissionsResolution &\n\t\t( IdType extends void ? SpecificResourcePermissionsResolution : {} )\n];\n\n/**\n * Resolves resource permissions.\n *\n * @param resource The resource in question, e.g. media.\n * @param id ID of a specific resource entry, if needed, e.g. 10.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( 'pages' );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PagesList />\n * ```\n *\n * In the above example, when `PagesList` is rendered into an\n * application, the appropriate permissions and the resolution details will be retrieved from\n * the store state using `canUser()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template IdType\n */\nexport default function __experimentalUseResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser( 'create', resource );\n\t\t\tif ( ! id ) {\n\t\t\t\treturn [\n\t\t\t\t\tcreate.hasResolved,\n\t\t\t\t\t{\n\t\t\t\t\t\tstatus: create.status,\n\t\t\t\t\t\tisResolving: create.isResolving,\n\t\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tconst update = canUser( 'update', resource, id );\n\t\t\tconst _delete = canUser( 'delete', resource, id );\n\t\t\tconst isResolving =\n\t\t\t\tcreate.isResolving || update.isResolving || _delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tcreate.hasResolved && update.hasResolved && _delete.hasResolved;\n\n\t\t\tlet status = Status.Idle;\n\t\t\tif ( isResolving ) {\n\t\t\t\tstatus = Status.Resolving;\n\t\t\t} else if ( hasResolved ) {\n\t\t\t\tstatus = Status.Success;\n\t\t\t}\n\t\t\treturn [\n\t\t\t\thasResolved,\n\t\t\t\t{\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t\t},\n\t\t\t];\n\t\t},\n\t\t[ resource, id ]\n\t);\n}\n"]}
|
package/build/index.js
CHANGED
|
@@ -7,7 +7,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
var _exportNames = {
|
|
9
9
|
store: true,
|
|
10
|
-
EntityProvider: true
|
|
10
|
+
EntityProvider: true,
|
|
11
|
+
useEntityRecord: true,
|
|
12
|
+
useEntityRecords: true,
|
|
13
|
+
__experimentalUseResourcePermissions: true
|
|
11
14
|
};
|
|
12
15
|
Object.defineProperty(exports, "EntityProvider", {
|
|
13
16
|
enumerable: true,
|
|
@@ -15,7 +18,25 @@ Object.defineProperty(exports, "EntityProvider", {
|
|
|
15
18
|
return _entityProvider.default;
|
|
16
19
|
}
|
|
17
20
|
});
|
|
21
|
+
Object.defineProperty(exports, "__experimentalUseResourcePermissions", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _useResourcePermissions.default;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
18
27
|
exports.store = void 0;
|
|
28
|
+
Object.defineProperty(exports, "useEntityRecord", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return _useEntityRecord.default;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, "useEntityRecords", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () {
|
|
37
|
+
return _useEntityRecords.default;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
19
40
|
|
|
20
41
|
var _data = require("@wordpress/data");
|
|
21
42
|
|
|
@@ -47,6 +68,12 @@ Object.keys(_entityProvider).forEach(function (key) {
|
|
|
47
68
|
});
|
|
48
69
|
});
|
|
49
70
|
|
|
71
|
+
var _useEntityRecord = _interopRequireDefault(require("./hooks/use-entity-record"));
|
|
72
|
+
|
|
73
|
+
var _useEntityRecords = _interopRequireDefault(require("./hooks/use-entity-records"));
|
|
74
|
+
|
|
75
|
+
var _useResourcePermissions = _interopRequireDefault(require("./hooks/use-resource-permissions"));
|
|
76
|
+
|
|
50
77
|
var _entityTypes = require("./entity-types");
|
|
51
78
|
|
|
52
79
|
Object.keys(_entityTypes).forEach(function (key) {
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","rootEntitiesConfig","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","getEntityRecords","entityResolvers","resolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","store","STORE_NAME"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","rootEntitiesConfig","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","getEntityRecords","entityResolvers","resolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","store","STORE_NAME"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAuDA;;AAIA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAHA;;AACA;;AACA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;AA5EA;AACA;AACA;;AAGA;AACA;AACA;AASA;AACA;AACA;AACA;AAEA,MAAMA,eAAe,GAAGC,6BAAmBC,MAAnB,CAA2B,CAAEC,MAAF,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B,EAA8BH,WAAW,EAAzC,CAAd;;AAEP,oBAAUE,KAAV","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { rootEntitiesConfig, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\n\nregister( store );\n\nexport { default as EntityProvider } from './entity-provider';\nexport { default as useEntityRecord } from './hooks/use-entity-record';\nexport { default as useEntityRecords } from './hooks/use-entity-records';\nexport { default as __experimentalUseResourcePermissions } from './hooks/use-resource-permissions';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\n"]}
|