@wordpress/core-data 6.16.0 → 6.17.1
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 +2 -0
- package/build/actions.js +69 -134
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +0 -22
- package/build/batch/create-batch.js.map +1 -1
- package/build/batch/default-processor.js +3 -15
- package/build/batch/default-processor.js.map +1 -1
- package/build/batch/index.js +0 -3
- package/build/batch/index.js.map +1 -1
- package/build/entities.js +109 -36
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js +34 -53
- package/build/entity-provider.js.map +1 -1
- package/build/entity-types/attachment.js.map +1 -1
- package/build/entity-types/base-entity-records.js +0 -3
- package/build/entity-types/base-entity-records.js.map +1 -1
- package/build/entity-types/comment.js.map +1 -1
- package/build/entity-types/helpers.js.map +1 -1
- package/build/entity-types/index.js.map +1 -1
- package/build/entity-types/menu-location.js.map +1 -1
- package/build/entity-types/nav-menu-item.js.map +1 -1
- package/build/entity-types/nav-menu.js.map +1 -1
- package/build/entity-types/page.js.map +1 -1
- package/build/entity-types/plugin.js.map +1 -1
- package/build/entity-types/post.js.map +1 -1
- package/build/entity-types/settings.js.map +1 -1
- package/build/entity-types/sidebar.js.map +1 -1
- package/build/entity-types/taxonomy.js.map +1 -1
- package/build/entity-types/theme.js.map +1 -1
- package/build/entity-types/type.js.map +1 -1
- package/build/entity-types/user.js.map +1 -1
- package/build/entity-types/widget-type.js.map +1 -1
- package/build/entity-types/widget.js.map +1 -1
- package/build/entity-types/wp-template-part.js.map +1 -1
- package/build/entity-types/wp-template.js.map +1 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js +14 -20
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/fetch/__experimental-fetch-url-data.js +4 -13
- package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build/fetch/index.js +0 -3
- package/build/fetch/index.js.map +1 -1
- package/build/hooks/constants.js +4 -5
- package/build/hooks/constants.js.map +1 -1
- package/build/hooks/index.js +0 -5
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/memoize.js +0 -3
- package/build/hooks/memoize.js.map +1 -1
- package/build/hooks/use-entity-record.js +0 -9
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +2 -9
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js +1 -13
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/hooks/use-resource-permissions.js +0 -15
- package/build/hooks/use-resource-permissions.js.map +1 -1
- package/build/index.js +9 -41
- package/build/index.js.map +1 -1
- package/build/locks/actions.js +1 -6
- package/build/locks/actions.js.map +1 -1
- package/build/locks/engine.js +1 -9
- package/build/locks/engine.js.map +1 -1
- package/build/locks/reducer.js +8 -9
- package/build/locks/reducer.js.map +1 -1
- package/build/locks/selectors.js +8 -11
- package/build/locks/selectors.js.map +1 -1
- package/build/locks/utils.js +4 -19
- package/build/locks/utils.js.map +1 -1
- package/build/name.js +0 -1
- package/build/name.js.map +1 -1
- package/build/private-apis.js +1 -2
- package/build/private-apis.js.map +1 -1
- package/build/private-selectors.js +2 -5
- package/build/private-selectors.js.map +1 -1
- package/build/queried-data/actions.js +4 -6
- package/build/queried-data/actions.js.map +1 -1
- package/build/queried-data/get-query-parts.js +11 -24
- package/build/queried-data/get-query-parts.js.map +1 -1
- package/build/queried-data/index.js +0 -6
- package/build/queried-data/index.js.map +1 -1
- package/build/queried-data/reducer.js +33 -51
- package/build/queried-data/reducer.js.map +1 -1
- package/build/queried-data/selectors.js +4 -25
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +76 -128
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +91 -133
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +51 -145
- package/build/selectors.js.map +1 -1
- package/build/sync.js +19 -0
- package/build/sync.js.map +1 -0
- package/build/types.js.map +1 -1
- package/build/utils/conservative-map-item.js +3 -10
- package/build/utils/conservative-map-item.js.map +1 -1
- package/build/utils/forward-resolver.js +0 -2
- package/build/utils/forward-resolver.js.map +1 -1
- package/build/utils/get-normalized-comma-separable.js +0 -3
- package/build/utils/get-normalized-comma-separable.js.map +1 -1
- package/build/utils/if-matching-action.js +0 -3
- package/build/utils/if-matching-action.js.map +1 -1
- package/build/utils/index.js +0 -10
- package/build/utils/index.js.map +1 -1
- package/build/utils/is-raw-attribute.js +0 -1
- package/build/utils/is-raw-attribute.js.map +1 -1
- package/build/utils/on-sub-key.js +5 -9
- package/build/utils/on-sub-key.js.map +1 -1
- package/build/utils/replace-action.js +0 -2
- package/build/utils/replace-action.js.map +1 -1
- package/build/utils/set-nested-value.js +0 -4
- package/build/utils/set-nested-value.js.map +1 -1
- package/build/utils/with-weak-map-cache.js +3 -6
- package/build/utils/with-weak-map-cache.js.map +1 -1
- package/build-module/actions.js +72 -95
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +1 -20
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/batch/default-processor.js +4 -13
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/batch/index.js.map +1 -1
- package/build-module/entities.js +109 -25
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js +35 -45
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/entity-types/attachment.js.map +1 -1
- package/build-module/entity-types/base-entity-records.js +0 -2
- package/build-module/entity-types/base-entity-records.js.map +1 -1
- package/build-module/entity-types/comment.js.map +1 -1
- package/build-module/entity-types/helpers.js.map +1 -1
- package/build-module/entity-types/index.js.map +1 -1
- package/build-module/entity-types/menu-location.js.map +1 -1
- package/build-module/entity-types/nav-menu-item.js.map +1 -1
- package/build-module/entity-types/nav-menu.js.map +1 -1
- package/build-module/entity-types/page.js.map +1 -1
- package/build-module/entity-types/plugin.js.map +1 -1
- package/build-module/entity-types/post.js.map +1 -1
- package/build-module/entity-types/settings.js.map +1 -1
- package/build-module/entity-types/sidebar.js.map +1 -1
- package/build-module/entity-types/taxonomy.js.map +1 -1
- package/build-module/entity-types/theme.js.map +1 -1
- package/build-module/entity-types/type.js.map +1 -1
- package/build-module/entity-types/user.js.map +1 -1
- package/build-module/entity-types/widget-type.js.map +1 -1
- package/build-module/entity-types/widget.js.map +1 -1
- package/build-module/entity-types/wp-template-part.js.map +1 -1
- package/build-module/entity-types/wp-template.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +15 -15
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +5 -10
- package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build-module/fetch/index.js.map +1 -1
- package/build-module/hooks/constants.js +3 -4
- package/build-module/hooks/constants.js.map +1 -1
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/memoize.js +2 -1
- package/build-module/hooks/memoize.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +1 -3
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +2 -3
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js +1 -9
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/hooks/use-resource-permissions.js +1 -10
- package/build-module/hooks/use-resource-permissions.js.map +1 -1
- package/build-module/index.js +11 -19
- package/build-module/index.js.map +1 -1
- package/build-module/locks/actions.js +0 -3
- package/build-module/locks/actions.js.map +1 -1
- package/build-module/locks/engine.js +0 -5
- package/build-module/locks/engine.js.map +1 -1
- package/build-module/locks/reducer.js +7 -7
- package/build-module/locks/reducer.js.map +1 -1
- package/build-module/locks/selectors.js +7 -8
- package/build-module/locks/selectors.js.map +1 -1
- package/build-module/locks/utils.js +4 -14
- package/build-module/locks/utils.js.map +1 -1
- package/build-module/name.js.map +1 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/private-selectors.js +2 -2
- package/build-module/private-selectors.js.map +1 -1
- package/build-module/queried-data/actions.js +4 -3
- package/build-module/queried-data/actions.js.map +1 -1
- package/build-module/queried-data/get-query-parts.js +13 -21
- package/build-module/queried-data/get-query-parts.js.map +1 -1
- package/build-module/queried-data/index.js.map +1 -1
- package/build-module/queried-data/reducer.js +33 -42
- package/build-module/queried-data/reducer.js.map +1 -1
- package/build-module/queried-data/selectors.js +6 -21
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +79 -104
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +94 -96
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +56 -92
- package/build-module/selectors.js.map +1 -1
- package/build-module/sync.js +12 -0
- package/build-module/sync.js.map +1 -0
- package/build-module/types.js.map +1 -1
- package/build-module/utils/conservative-map-item.js +4 -8
- package/build-module/utils/conservative-map-item.js.map +1 -1
- package/build-module/utils/forward-resolver.js +0 -1
- package/build-module/utils/forward-resolver.js.map +1 -1
- package/build-module/utils/get-normalized-comma-separable.js +0 -2
- package/build-module/utils/get-normalized-comma-separable.js.map +1 -1
- package/build-module/utils/if-matching-action.js +0 -2
- package/build-module/utils/if-matching-action.js.map +1 -1
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/is-raw-attribute.js.map +1 -1
- package/build-module/utils/on-sub-key.js +5 -7
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/build-module/utils/replace-action.js +0 -1
- package/build-module/utils/replace-action.js.map +1 -1
- package/build-module/utils/set-nested-value.js +0 -3
- package/build-module/utils/set-nested-value.js.map +1 -1
- package/build-module/utils/with-weak-map-cache.js +3 -5
- package/build-module/utils/with-weak-map-cache.js.map +1 -1
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/entities.d.ts +53 -0
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/entity-provider.d.ts +1 -1
- package/build-types/entity-provider.d.ts.map +1 -1
- package/build-types/hooks/memoize.d.ts +1 -1
- package/build-types/hooks/memoize.d.ts.map +1 -1
- package/build-types/index.d.ts +3 -3
- package/build-types/index.d.ts.map +1 -1
- package/build-types/resolvers.d.ts.map +1 -1
- package/build-types/sync.d.ts +2 -0
- package/build-types/sync.d.ts.map +1 -0
- package/package.json +17 -15
- package/src/actions.js +24 -14
- package/src/entities.js +91 -0
- package/src/entity-provider.js +11 -2
- package/src/resolvers.js +89 -41
- package/src/sync.js +18 -0
- package/src/test/entity-provider.js +272 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
package/build/reducer.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -24,21 +23,13 @@ exports.themeGlobalStyleVariations = themeGlobalStyleVariations;
|
|
|
24
23
|
exports.undo = undo;
|
|
25
24
|
exports.userPermissions = userPermissions;
|
|
26
25
|
exports.users = users;
|
|
27
|
-
|
|
28
26
|
var _es = _interopRequireDefault(require("fast-deep-equal/es6"));
|
|
29
|
-
|
|
30
27
|
var _compose = require("@wordpress/compose");
|
|
31
|
-
|
|
32
28
|
var _data = require("@wordpress/data");
|
|
33
|
-
|
|
34
29
|
var _isShallowEqual = _interopRequireDefault(require("@wordpress/is-shallow-equal"));
|
|
35
|
-
|
|
36
30
|
var _utils = require("./utils");
|
|
37
|
-
|
|
38
31
|
var _queriedData = require("./queried-data");
|
|
39
|
-
|
|
40
32
|
var _entities = require("./entities");
|
|
41
|
-
|
|
42
33
|
/**
|
|
43
34
|
* External dependencies
|
|
44
35
|
*/
|
|
@@ -67,13 +58,14 @@ var _entities = require("./entities");
|
|
|
67
58
|
function terms(state = {}, action) {
|
|
68
59
|
switch (action.type) {
|
|
69
60
|
case 'RECEIVE_TERMS':
|
|
70
|
-
return {
|
|
61
|
+
return {
|
|
62
|
+
...state,
|
|
71
63
|
[action.taxonomy]: action.terms
|
|
72
64
|
};
|
|
73
65
|
}
|
|
74
|
-
|
|
75
66
|
return state;
|
|
76
67
|
}
|
|
68
|
+
|
|
77
69
|
/**
|
|
78
70
|
* Reducer managing authors state. Keyed by id.
|
|
79
71
|
*
|
|
@@ -82,8 +74,6 @@ function terms(state = {}, action) {
|
|
|
82
74
|
*
|
|
83
75
|
* @return {Object} Updated state.
|
|
84
76
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
77
|
function users(state = {
|
|
88
78
|
byId: {},
|
|
89
79
|
queries: {}
|
|
@@ -91,20 +81,23 @@ function users(state = {
|
|
|
91
81
|
switch (action.type) {
|
|
92
82
|
case 'RECEIVE_USER_QUERY':
|
|
93
83
|
return {
|
|
94
|
-
byId: {
|
|
84
|
+
byId: {
|
|
85
|
+
...state.byId,
|
|
95
86
|
// Key users by their ID.
|
|
96
|
-
...action.users.reduce((newUsers, user) => ({
|
|
87
|
+
...action.users.reduce((newUsers, user) => ({
|
|
88
|
+
...newUsers,
|
|
97
89
|
[user.id]: user
|
|
98
90
|
}), {})
|
|
99
91
|
},
|
|
100
|
-
queries: {
|
|
92
|
+
queries: {
|
|
93
|
+
...state.queries,
|
|
101
94
|
[action.queryID]: action.users.map(user => user.id)
|
|
102
95
|
}
|
|
103
96
|
};
|
|
104
97
|
}
|
|
105
|
-
|
|
106
98
|
return state;
|
|
107
99
|
}
|
|
100
|
+
|
|
108
101
|
/**
|
|
109
102
|
* Reducer managing current user state.
|
|
110
103
|
*
|
|
@@ -113,16 +106,14 @@ function users(state = {
|
|
|
113
106
|
*
|
|
114
107
|
* @return {Object} Updated state.
|
|
115
108
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
118
109
|
function currentUser(state = {}, action) {
|
|
119
110
|
switch (action.type) {
|
|
120
111
|
case 'RECEIVE_CURRENT_USER':
|
|
121
112
|
return action.currentUser;
|
|
122
113
|
}
|
|
123
|
-
|
|
124
114
|
return state;
|
|
125
115
|
}
|
|
116
|
+
|
|
126
117
|
/**
|
|
127
118
|
* Reducer managing taxonomies.
|
|
128
119
|
*
|
|
@@ -131,16 +122,14 @@ function currentUser(state = {}, action) {
|
|
|
131
122
|
*
|
|
132
123
|
* @return {Object} Updated state.
|
|
133
124
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
125
|
function taxonomies(state = [], action) {
|
|
137
126
|
switch (action.type) {
|
|
138
127
|
case 'RECEIVE_TAXONOMIES':
|
|
139
128
|
return action.taxonomies;
|
|
140
129
|
}
|
|
141
|
-
|
|
142
130
|
return state;
|
|
143
131
|
}
|
|
132
|
+
|
|
144
133
|
/**
|
|
145
134
|
* Reducer managing the current theme.
|
|
146
135
|
*
|
|
@@ -149,16 +138,14 @@ function taxonomies(state = [], action) {
|
|
|
149
138
|
*
|
|
150
139
|
* @return {string|undefined} Updated state.
|
|
151
140
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
154
141
|
function currentTheme(state = undefined, action) {
|
|
155
142
|
switch (action.type) {
|
|
156
143
|
case 'RECEIVE_CURRENT_THEME':
|
|
157
144
|
return action.currentTheme.stylesheet;
|
|
158
145
|
}
|
|
159
|
-
|
|
160
146
|
return state;
|
|
161
147
|
}
|
|
148
|
+
|
|
162
149
|
/**
|
|
163
150
|
* Reducer managing the current global styles id.
|
|
164
151
|
*
|
|
@@ -167,16 +154,14 @@ function currentTheme(state = undefined, action) {
|
|
|
167
154
|
*
|
|
168
155
|
* @return {string|undefined} Updated state.
|
|
169
156
|
*/
|
|
170
|
-
|
|
171
|
-
|
|
172
157
|
function currentGlobalStylesId(state = undefined, action) {
|
|
173
158
|
switch (action.type) {
|
|
174
159
|
case 'RECEIVE_CURRENT_GLOBAL_STYLES_ID':
|
|
175
160
|
return action.id;
|
|
176
161
|
}
|
|
177
|
-
|
|
178
162
|
return state;
|
|
179
163
|
}
|
|
164
|
+
|
|
180
165
|
/**
|
|
181
166
|
* Reducer managing the theme base global styles.
|
|
182
167
|
*
|
|
@@ -185,18 +170,17 @@ function currentGlobalStylesId(state = undefined, action) {
|
|
|
185
170
|
*
|
|
186
171
|
* @return {Record<string, object>} Updated state.
|
|
187
172
|
*/
|
|
188
|
-
|
|
189
|
-
|
|
190
173
|
function themeBaseGlobalStyles(state = {}, action) {
|
|
191
174
|
switch (action.type) {
|
|
192
175
|
case 'RECEIVE_THEME_GLOBAL_STYLES':
|
|
193
|
-
return {
|
|
176
|
+
return {
|
|
177
|
+
...state,
|
|
194
178
|
[action.stylesheet]: action.globalStyles
|
|
195
179
|
};
|
|
196
180
|
}
|
|
197
|
-
|
|
198
181
|
return state;
|
|
199
182
|
}
|
|
183
|
+
|
|
200
184
|
/**
|
|
201
185
|
* Reducer managing the theme global styles variations.
|
|
202
186
|
*
|
|
@@ -205,19 +189,16 @@ function themeBaseGlobalStyles(state = {}, action) {
|
|
|
205
189
|
*
|
|
206
190
|
* @return {Record<string, object>} Updated state.
|
|
207
191
|
*/
|
|
208
|
-
|
|
209
|
-
|
|
210
192
|
function themeGlobalStyleVariations(state = {}, action) {
|
|
211
193
|
switch (action.type) {
|
|
212
194
|
case 'RECEIVE_THEME_GLOBAL_STYLE_VARIATIONS':
|
|
213
|
-
return {
|
|
195
|
+
return {
|
|
196
|
+
...state,
|
|
214
197
|
[action.stylesheet]: action.variations
|
|
215
198
|
};
|
|
216
199
|
}
|
|
217
|
-
|
|
218
200
|
return state;
|
|
219
201
|
}
|
|
220
|
-
|
|
221
202
|
const withMultiEntityRecordEdits = reducer => (state, action) => {
|
|
222
203
|
if (action.type === 'UNDO' || action.type === 'REDO') {
|
|
223
204
|
const {
|
|
@@ -244,9 +225,9 @@ const withMultiEntityRecordEdits = reducer => (state, action) => {
|
|
|
244
225
|
});
|
|
245
226
|
return newState;
|
|
246
227
|
}
|
|
247
|
-
|
|
248
228
|
return reducer(state, action);
|
|
249
229
|
};
|
|
230
|
+
|
|
250
231
|
/**
|
|
251
232
|
* Higher Order Reducer for a given entity config. It supports:
|
|
252
233
|
*
|
|
@@ -258,68 +239,62 @@ const withMultiEntityRecordEdits = reducer => (state, action) => {
|
|
|
258
239
|
*
|
|
259
240
|
* @return {AnyFunction} Reducer.
|
|
260
241
|
*/
|
|
261
|
-
|
|
262
|
-
|
|
263
242
|
function entity(entityConfig) {
|
|
264
|
-
return (0, _compose.compose)([withMultiEntityRecordEdits,
|
|
243
|
+
return (0, _compose.compose)([withMultiEntityRecordEdits,
|
|
244
|
+
// Limit to matching action type so we don't attempt to replace action on
|
|
265
245
|
// an unhandled action.
|
|
266
|
-
(0, _utils.ifMatchingAction)(action => action.name && action.kind && action.name === entityConfig.name && action.kind === entityConfig.kind),
|
|
246
|
+
(0, _utils.ifMatchingAction)(action => action.name && action.kind && action.name === entityConfig.name && action.kind === entityConfig.kind),
|
|
247
|
+
// Inject the entity config into the action.
|
|
267
248
|
(0, _utils.replaceAction)(action => {
|
|
268
|
-
return {
|
|
249
|
+
return {
|
|
250
|
+
...action,
|
|
269
251
|
key: entityConfig.key || _entities.DEFAULT_ENTITY_KEY
|
|
270
252
|
};
|
|
271
253
|
})])((0, _data.combineReducers)({
|
|
272
254
|
queriedData: _queriedData.reducer,
|
|
273
255
|
edits: (state = {}, action) => {
|
|
274
256
|
var _action$query$context;
|
|
275
|
-
|
|
276
257
|
switch (action.type) {
|
|
277
258
|
case 'RECEIVE_ITEMS':
|
|
278
259
|
const context = (_action$query$context = action?.query?.context) !== null && _action$query$context !== void 0 ? _action$query$context : 'default';
|
|
279
|
-
|
|
280
260
|
if (context !== 'default') {
|
|
281
261
|
return state;
|
|
282
262
|
}
|
|
283
|
-
|
|
284
|
-
|
|
263
|
+
const nextState = {
|
|
264
|
+
...state
|
|
285
265
|
};
|
|
286
|
-
|
|
287
266
|
for (const record of action.items) {
|
|
288
267
|
const recordId = record[action.key];
|
|
289
268
|
const edits = nextState[recordId];
|
|
290
|
-
|
|
291
269
|
if (!edits) {
|
|
292
270
|
continue;
|
|
293
271
|
}
|
|
294
|
-
|
|
295
272
|
const nextEdits = Object.keys(edits).reduce((acc, key) => {
|
|
296
273
|
var _record$key$raw;
|
|
297
|
-
|
|
298
274
|
// If the edited value is still different to the persisted value,
|
|
299
275
|
// keep the edited value in edits.
|
|
300
|
-
if (
|
|
276
|
+
if (
|
|
277
|
+
// Edits are the "raw" attribute values, but records may have
|
|
301
278
|
// objects with more properties, so we use `get` here for the
|
|
302
279
|
// comparison.
|
|
303
|
-
!(0, _es.default)(edits[key], (_record$key$raw = record[key]?.raw) !== null && _record$key$raw !== void 0 ? _record$key$raw : record[key]) && (
|
|
280
|
+
!(0, _es.default)(edits[key], (_record$key$raw = record[key]?.raw) !== null && _record$key$raw !== void 0 ? _record$key$raw : record[key]) && (
|
|
281
|
+
// Sometimes the server alters the sent value which means
|
|
304
282
|
// we need to also remove the edits before the api request.
|
|
305
283
|
!action.persistedEdits || !(0, _es.default)(edits[key], action.persistedEdits[key]))) {
|
|
306
284
|
acc[key] = edits[key];
|
|
307
285
|
}
|
|
308
|
-
|
|
309
286
|
return acc;
|
|
310
287
|
}, {});
|
|
311
|
-
|
|
312
288
|
if (Object.keys(nextEdits).length) {
|
|
313
289
|
nextState[recordId] = nextEdits;
|
|
314
290
|
} else {
|
|
315
291
|
delete nextState[recordId];
|
|
316
292
|
}
|
|
317
293
|
}
|
|
318
|
-
|
|
319
294
|
return nextState;
|
|
320
|
-
|
|
321
295
|
case 'EDIT_ENTITY_RECORD':
|
|
322
|
-
const nextEdits = {
|
|
296
|
+
const nextEdits = {
|
|
297
|
+
...state[action.recordId],
|
|
323
298
|
...action.edits
|
|
324
299
|
};
|
|
325
300
|
Object.keys(nextEdits).forEach(key => {
|
|
@@ -329,18 +304,19 @@ function entity(entityConfig) {
|
|
|
329
304
|
delete nextEdits[key];
|
|
330
305
|
}
|
|
331
306
|
});
|
|
332
|
-
return {
|
|
307
|
+
return {
|
|
308
|
+
...state,
|
|
333
309
|
[action.recordId]: nextEdits
|
|
334
310
|
};
|
|
335
311
|
}
|
|
336
|
-
|
|
337
312
|
return state;
|
|
338
313
|
},
|
|
339
314
|
saving: (state = {}, action) => {
|
|
340
315
|
switch (action.type) {
|
|
341
316
|
case 'SAVE_ENTITY_RECORD_START':
|
|
342
317
|
case 'SAVE_ENTITY_RECORD_FINISH':
|
|
343
|
-
return {
|
|
318
|
+
return {
|
|
319
|
+
...state,
|
|
344
320
|
[action.recordId]: {
|
|
345
321
|
pending: action.type === 'SAVE_ENTITY_RECORD_START',
|
|
346
322
|
error: action.error,
|
|
@@ -348,25 +324,25 @@ function entity(entityConfig) {
|
|
|
348
324
|
}
|
|
349
325
|
};
|
|
350
326
|
}
|
|
351
|
-
|
|
352
327
|
return state;
|
|
353
328
|
},
|
|
354
329
|
deleting: (state = {}, action) => {
|
|
355
330
|
switch (action.type) {
|
|
356
331
|
case 'DELETE_ENTITY_RECORD_START':
|
|
357
332
|
case 'DELETE_ENTITY_RECORD_FINISH':
|
|
358
|
-
return {
|
|
333
|
+
return {
|
|
334
|
+
...state,
|
|
359
335
|
[action.recordId]: {
|
|
360
336
|
pending: action.type === 'DELETE_ENTITY_RECORD_START',
|
|
361
337
|
error: action.error
|
|
362
338
|
}
|
|
363
339
|
};
|
|
364
340
|
}
|
|
365
|
-
|
|
366
341
|
return state;
|
|
367
342
|
}
|
|
368
343
|
}));
|
|
369
344
|
}
|
|
345
|
+
|
|
370
346
|
/**
|
|
371
347
|
* Reducer keeping track of the registered entities.
|
|
372
348
|
*
|
|
@@ -375,16 +351,14 @@ function entity(entityConfig) {
|
|
|
375
351
|
*
|
|
376
352
|
* @return {Object} Updated state.
|
|
377
353
|
*/
|
|
378
|
-
|
|
379
|
-
|
|
380
354
|
function entitiesConfig(state = _entities.rootEntitiesConfig, action) {
|
|
381
355
|
switch (action.type) {
|
|
382
356
|
case 'ADD_ENTITIES':
|
|
383
357
|
return [...state, ...action.entities];
|
|
384
358
|
}
|
|
385
|
-
|
|
386
359
|
return state;
|
|
387
360
|
}
|
|
361
|
+
|
|
388
362
|
/**
|
|
389
363
|
* Reducer keeping track of the registered entities config and data.
|
|
390
364
|
*
|
|
@@ -393,47 +367,42 @@ function entitiesConfig(state = _entities.rootEntitiesConfig, action) {
|
|
|
393
367
|
*
|
|
394
368
|
* @return {Object} Updated state.
|
|
395
369
|
*/
|
|
396
|
-
|
|
397
|
-
|
|
398
370
|
const entities = (state = {}, action) => {
|
|
399
|
-
const newConfig = entitiesConfig(state.config, action);
|
|
371
|
+
const newConfig = entitiesConfig(state.config, action);
|
|
400
372
|
|
|
373
|
+
// Generates a dynamic reducer for the entities.
|
|
401
374
|
let entitiesDataReducer = state.reducer;
|
|
402
|
-
|
|
403
375
|
if (!entitiesDataReducer || newConfig !== state.config) {
|
|
404
376
|
const entitiesByKind = newConfig.reduce((acc, record) => {
|
|
405
377
|
const {
|
|
406
378
|
kind
|
|
407
379
|
} = record;
|
|
408
|
-
|
|
409
380
|
if (!acc[kind]) {
|
|
410
381
|
acc[kind] = [];
|
|
411
382
|
}
|
|
412
|
-
|
|
413
383
|
acc[kind].push(record);
|
|
414
384
|
return acc;
|
|
415
385
|
}, {});
|
|
416
386
|
entitiesDataReducer = (0, _data.combineReducers)(Object.entries(entitiesByKind).reduce((memo, [kind, subEntities]) => {
|
|
417
|
-
const kindReducer = (0, _data.combineReducers)(subEntities.reduce((kindMemo, entityConfig) => ({
|
|
387
|
+
const kindReducer = (0, _data.combineReducers)(subEntities.reduce((kindMemo, entityConfig) => ({
|
|
388
|
+
...kindMemo,
|
|
418
389
|
[entityConfig.name]: entity(entityConfig)
|
|
419
390
|
}), {}));
|
|
420
391
|
memo[kind] = kindReducer;
|
|
421
392
|
return memo;
|
|
422
393
|
}, {}));
|
|
423
394
|
}
|
|
424
|
-
|
|
425
395
|
const newData = entitiesDataReducer(state.records, action);
|
|
426
|
-
|
|
427
396
|
if (newData === state.records && newConfig === state.config && entitiesDataReducer === state.reducer) {
|
|
428
397
|
return state;
|
|
429
398
|
}
|
|
430
|
-
|
|
431
399
|
return {
|
|
432
400
|
reducer: entitiesDataReducer,
|
|
433
401
|
records: newData,
|
|
434
402
|
config: newConfig
|
|
435
403
|
};
|
|
436
404
|
};
|
|
405
|
+
|
|
437
406
|
/**
|
|
438
407
|
* @typedef {Object} UndoStateMeta
|
|
439
408
|
*
|
|
@@ -449,13 +418,12 @@ const entities = (state = {}, action) => {
|
|
|
449
418
|
*
|
|
450
419
|
* @todo Given how we use this we might want to make a custom class for it.
|
|
451
420
|
*/
|
|
452
|
-
|
|
453
|
-
|
|
454
421
|
exports.entities = entities;
|
|
455
422
|
const UNDO_INITIAL_STATE = {
|
|
456
423
|
list: [],
|
|
457
424
|
offset: 0
|
|
458
425
|
};
|
|
426
|
+
|
|
459
427
|
/**
|
|
460
428
|
* Reducer keeping track of entity edit undo history.
|
|
461
429
|
*
|
|
@@ -464,32 +432,31 @@ const UNDO_INITIAL_STATE = {
|
|
|
464
432
|
*
|
|
465
433
|
* @return {UndoState} Updated state.
|
|
466
434
|
*/
|
|
467
|
-
|
|
468
435
|
function undo(state = UNDO_INITIAL_STATE, action) {
|
|
469
436
|
const omitPendingRedos = currentState => {
|
|
470
|
-
return {
|
|
437
|
+
return {
|
|
438
|
+
...currentState,
|
|
471
439
|
list: currentState.list.slice(0, currentState.offset || undefined),
|
|
472
440
|
offset: 0
|
|
473
441
|
};
|
|
474
442
|
};
|
|
475
|
-
|
|
476
443
|
const appendCachedEditsToLastUndo = currentState => {
|
|
477
444
|
if (!currentState.cache) {
|
|
478
445
|
return currentState;
|
|
479
446
|
}
|
|
480
|
-
|
|
481
|
-
|
|
447
|
+
let nextState = {
|
|
448
|
+
...currentState,
|
|
482
449
|
list: [...currentState.list]
|
|
483
450
|
};
|
|
484
451
|
nextState = omitPendingRedos(nextState);
|
|
485
452
|
const previousUndoState = nextState.list.pop();
|
|
486
453
|
const updatedUndoState = currentState.cache.reduce(appendEditToStack, previousUndoState);
|
|
487
454
|
nextState.list.push(updatedUndoState);
|
|
488
|
-
return {
|
|
455
|
+
return {
|
|
456
|
+
...nextState,
|
|
489
457
|
cache: undefined
|
|
490
458
|
};
|
|
491
459
|
};
|
|
492
|
-
|
|
493
460
|
const appendEditToStack = (stack = [], {
|
|
494
461
|
kind,
|
|
495
462
|
name,
|
|
@@ -507,10 +474,10 @@ function undo(state = UNDO_INITIAL_STATE, action) {
|
|
|
507
474
|
return k === kind && n === name && r === recordId && p === property;
|
|
508
475
|
});
|
|
509
476
|
const nextStack = [...stack];
|
|
510
|
-
|
|
511
477
|
if (existingEditIndex !== -1) {
|
|
512
478
|
// If the edit is already in the stack leave the initial "from" value.
|
|
513
|
-
nextStack[existingEditIndex] = {
|
|
479
|
+
nextStack[existingEditIndex] = {
|
|
480
|
+
...nextStack[existingEditIndex],
|
|
514
481
|
to
|
|
515
482
|
};
|
|
516
483
|
} else {
|
|
@@ -523,29 +490,25 @@ function undo(state = UNDO_INITIAL_STATE, action) {
|
|
|
523
490
|
to
|
|
524
491
|
});
|
|
525
492
|
}
|
|
526
|
-
|
|
527
493
|
return nextStack;
|
|
528
494
|
};
|
|
529
|
-
|
|
530
495
|
switch (action.type) {
|
|
531
496
|
case 'CREATE_UNDO_LEVEL':
|
|
532
497
|
return appendCachedEditsToLastUndo(state);
|
|
533
|
-
|
|
534
498
|
case 'UNDO':
|
|
535
499
|
case 'REDO':
|
|
536
500
|
{
|
|
537
501
|
const nextState = appendCachedEditsToLastUndo(state);
|
|
538
|
-
return {
|
|
502
|
+
return {
|
|
503
|
+
...nextState,
|
|
539
504
|
offset: state.offset + (action.type === 'UNDO' ? -1 : 1)
|
|
540
505
|
};
|
|
541
506
|
}
|
|
542
|
-
|
|
543
507
|
case 'EDIT_ENTITY_RECORD':
|
|
544
508
|
{
|
|
545
509
|
if (!action.meta.undo) {
|
|
546
510
|
return state;
|
|
547
511
|
}
|
|
548
|
-
|
|
549
512
|
const edits = Object.keys(action.edits).map(key => {
|
|
550
513
|
return {
|
|
551
514
|
kind: action.kind,
|
|
@@ -556,33 +519,31 @@ function undo(state = UNDO_INITIAL_STATE, action) {
|
|
|
556
519
|
to: action.edits[key]
|
|
557
520
|
};
|
|
558
521
|
});
|
|
559
|
-
|
|
560
522
|
if (action.meta.undo.isCached) {
|
|
561
|
-
return {
|
|
523
|
+
return {
|
|
524
|
+
...state,
|
|
562
525
|
cache: edits.reduce(appendEditToStack, state.cache)
|
|
563
526
|
};
|
|
564
527
|
}
|
|
565
|
-
|
|
566
528
|
let nextState = omitPendingRedos(state);
|
|
567
529
|
nextState = appendCachedEditsToLastUndo(nextState);
|
|
568
|
-
nextState = {
|
|
530
|
+
nextState = {
|
|
531
|
+
...nextState,
|
|
569
532
|
list: [...nextState.list]
|
|
570
|
-
};
|
|
533
|
+
};
|
|
534
|
+
// When an edit is a function it's an optimization to avoid running some expensive operation.
|
|
571
535
|
// We can't rely on the function references being the same so we opt out of comparing them here.
|
|
572
|
-
|
|
573
536
|
const comparisonUndoEdits = Object.values(action.meta.undo.edits).filter(edit => typeof edit !== 'function');
|
|
574
537
|
const comparisonEdits = Object.values(action.edits).filter(edit => typeof edit !== 'function');
|
|
575
|
-
|
|
576
538
|
if (!(0, _isShallowEqual.default)(comparisonUndoEdits, comparisonEdits)) {
|
|
577
539
|
nextState.list.push(edits);
|
|
578
540
|
}
|
|
579
|
-
|
|
580
541
|
return nextState;
|
|
581
542
|
}
|
|
582
543
|
}
|
|
583
|
-
|
|
584
544
|
return state;
|
|
585
545
|
}
|
|
546
|
+
|
|
586
547
|
/**
|
|
587
548
|
* Reducer managing embed preview data.
|
|
588
549
|
*
|
|
@@ -591,8 +552,6 @@ function undo(state = UNDO_INITIAL_STATE, action) {
|
|
|
591
552
|
*
|
|
592
553
|
* @return {Object} Updated state.
|
|
593
554
|
*/
|
|
594
|
-
|
|
595
|
-
|
|
596
555
|
function embedPreviews(state = {}, action) {
|
|
597
556
|
switch (action.type) {
|
|
598
557
|
case 'RECEIVE_EMBED_PREVIEW':
|
|
@@ -600,13 +559,14 @@ function embedPreviews(state = {}, action) {
|
|
|
600
559
|
url,
|
|
601
560
|
preview
|
|
602
561
|
} = action;
|
|
603
|
-
return {
|
|
562
|
+
return {
|
|
563
|
+
...state,
|
|
604
564
|
[url]: preview
|
|
605
565
|
};
|
|
606
566
|
}
|
|
607
|
-
|
|
608
567
|
return state;
|
|
609
568
|
}
|
|
569
|
+
|
|
610
570
|
/**
|
|
611
571
|
* State which tracks whether the user can perform an action on a REST
|
|
612
572
|
* resource.
|
|
@@ -616,18 +576,17 @@ function embedPreviews(state = {}, action) {
|
|
|
616
576
|
*
|
|
617
577
|
* @return {Object} Updated state.
|
|
618
578
|
*/
|
|
619
|
-
|
|
620
|
-
|
|
621
579
|
function userPermissions(state = {}, action) {
|
|
622
580
|
switch (action.type) {
|
|
623
581
|
case 'RECEIVE_USER_PERMISSION':
|
|
624
|
-
return {
|
|
582
|
+
return {
|
|
583
|
+
...state,
|
|
625
584
|
[action.key]: action.isAllowed
|
|
626
585
|
};
|
|
627
586
|
}
|
|
628
|
-
|
|
629
587
|
return state;
|
|
630
588
|
}
|
|
589
|
+
|
|
631
590
|
/**
|
|
632
591
|
* Reducer returning autosaves keyed by their parent's post id.
|
|
633
592
|
*
|
|
@@ -636,8 +595,6 @@ function userPermissions(state = {}, action) {
|
|
|
636
595
|
*
|
|
637
596
|
* @return {Object} Updated state.
|
|
638
597
|
*/
|
|
639
|
-
|
|
640
|
-
|
|
641
598
|
function autosaves(state = {}, action) {
|
|
642
599
|
switch (action.type) {
|
|
643
600
|
case 'RECEIVE_AUTOSAVES':
|
|
@@ -645,40 +602,35 @@ function autosaves(state = {}, action) {
|
|
|
645
602
|
postId,
|
|
646
603
|
autosaves: autosavesData
|
|
647
604
|
} = action;
|
|
648
|
-
return {
|
|
605
|
+
return {
|
|
606
|
+
...state,
|
|
649
607
|
[postId]: autosavesData
|
|
650
608
|
};
|
|
651
609
|
}
|
|
652
|
-
|
|
653
610
|
return state;
|
|
654
611
|
}
|
|
655
|
-
|
|
656
612
|
function blockPatterns(state = [], action) {
|
|
657
613
|
switch (action.type) {
|
|
658
614
|
case 'RECEIVE_BLOCK_PATTERNS':
|
|
659
615
|
return action.patterns;
|
|
660
616
|
}
|
|
661
|
-
|
|
662
617
|
return state;
|
|
663
618
|
}
|
|
664
|
-
|
|
665
619
|
function blockPatternCategories(state = [], action) {
|
|
666
620
|
switch (action.type) {
|
|
667
621
|
case 'RECEIVE_BLOCK_PATTERN_CATEGORIES':
|
|
668
622
|
return action.categories;
|
|
669
623
|
}
|
|
670
|
-
|
|
671
624
|
return state;
|
|
672
625
|
}
|
|
673
|
-
|
|
674
626
|
function navigationFallbackId(state = null, action) {
|
|
675
627
|
switch (action.type) {
|
|
676
628
|
case 'RECEIVE_NAVIGATION_FALLBACK_ID':
|
|
677
629
|
return action.fallbackId;
|
|
678
630
|
}
|
|
679
|
-
|
|
680
631
|
return state;
|
|
681
632
|
}
|
|
633
|
+
|
|
682
634
|
/**
|
|
683
635
|
* Reducer managing the theme global styles revisions.
|
|
684
636
|
*
|
|
@@ -687,19 +639,16 @@ function navigationFallbackId(state = null, action) {
|
|
|
687
639
|
*
|
|
688
640
|
* @return {Record<string, object>} Updated state.
|
|
689
641
|
*/
|
|
690
|
-
|
|
691
|
-
|
|
692
642
|
function themeGlobalStyleRevisions(state = {}, action) {
|
|
693
643
|
switch (action.type) {
|
|
694
644
|
case 'RECEIVE_THEME_GLOBAL_STYLE_REVISIONS':
|
|
695
|
-
return {
|
|
645
|
+
return {
|
|
646
|
+
...state,
|
|
696
647
|
[action.currentId]: action.revisions
|
|
697
648
|
};
|
|
698
649
|
}
|
|
699
|
-
|
|
700
650
|
return state;
|
|
701
651
|
}
|
|
702
|
-
|
|
703
652
|
var _default = (0, _data.combineReducers)({
|
|
704
653
|
terms,
|
|
705
654
|
users,
|
|
@@ -719,6 +668,5 @@ var _default = (0, _data.combineReducers)({
|
|
|
719
668
|
blockPatternCategories,
|
|
720
669
|
navigationFallbackId
|
|
721
670
|
});
|
|
722
|
-
|
|
723
671
|
exports.default = _default;
|
|
724
672
|
//# sourceMappingURL=reducer.js.map
|