@wordpress/core-data 6.11.0 → 6.12.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.
Files changed (114) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +4 -0
  3. package/build/actions.js +252 -276
  4. package/build/actions.js.map +1 -1
  5. package/build/batch/create-batch.js +8 -16
  6. package/build/batch/create-batch.js.map +1 -1
  7. package/build/batch/default-processor.js +1 -1
  8. package/build/batch/default-processor.js.map +1 -1
  9. package/build/entities.js +16 -25
  10. package/build/entities.js.map +1 -1
  11. package/build/entity-provider.js +12 -17
  12. package/build/entity-provider.js.map +1 -1
  13. package/build/fetch/__experimental-fetch-link-suggestions.js +2 -6
  14. package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  15. package/build/fetch/__experimental-fetch-url-data.js +1 -2
  16. package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
  17. package/build/hooks/use-entity-record.js +7 -11
  18. package/build/hooks/use-entity-record.js.map +1 -1
  19. package/build/hooks/use-entity-records.js +3 -5
  20. package/build/hooks/use-entity-records.js.map +1 -1
  21. package/build/hooks/use-query-select.js +1 -6
  22. package/build/hooks/use-query-select.js.map +1 -1
  23. package/build/index.js +1 -7
  24. package/build/index.js.map +1 -1
  25. package/build/locks/actions.js +3 -4
  26. package/build/locks/actions.js.map +1 -1
  27. package/build/locks/reducer.js +1 -4
  28. package/build/locks/reducer.js.map +1 -1
  29. package/build/locks/selectors.js +3 -4
  30. package/build/locks/selectors.js.map +1 -1
  31. package/build/locks/utils.js +3 -5
  32. package/build/locks/utils.js.map +1 -1
  33. package/build/private-selectors.js +37 -0
  34. package/build/private-selectors.js.map +1 -0
  35. package/build/queried-data/actions.js +2 -5
  36. package/build/queried-data/actions.js.map +1 -1
  37. package/build/queried-data/reducer.js +17 -47
  38. package/build/queried-data/reducer.js.map +1 -1
  39. package/build/queried-data/selectors.js +4 -11
  40. package/build/queried-data/selectors.js.map +1 -1
  41. package/build/reducer.js +167 -194
  42. package/build/reducer.js.map +1 -1
  43. package/build/resolvers.js +175 -220
  44. package/build/resolvers.js.map +1 -1
  45. package/build/selectors.js +53 -61
  46. package/build/selectors.js.map +1 -1
  47. package/build/utils/forward-resolver.js +4 -11
  48. package/build/utils/forward-resolver.js.map +1 -1
  49. package/build/utils/on-sub-key.js +1 -3
  50. package/build/utils/on-sub-key.js.map +1 -1
  51. package/build-module/actions.js +251 -276
  52. package/build-module/actions.js.map +1 -1
  53. package/build-module/batch/create-batch.js +8 -16
  54. package/build-module/batch/create-batch.js.map +1 -1
  55. package/build-module/batch/default-processor.js +1 -1
  56. package/build-module/batch/default-processor.js.map +1 -1
  57. package/build-module/entities.js +16 -25
  58. package/build-module/entities.js.map +1 -1
  59. package/build-module/entity-provider.js +12 -17
  60. package/build-module/entity-provider.js.map +1 -1
  61. package/build-module/fetch/__experimental-fetch-link-suggestions.js +2 -6
  62. package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  63. package/build-module/fetch/__experimental-fetch-url-data.js +1 -2
  64. package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
  65. package/build-module/hooks/use-entity-record.js +7 -11
  66. package/build-module/hooks/use-entity-record.js.map +1 -1
  67. package/build-module/hooks/use-entity-records.js +3 -5
  68. package/build-module/hooks/use-entity-records.js.map +1 -1
  69. package/build-module/hooks/use-query-select.js +1 -6
  70. package/build-module/hooks/use-query-select.js.map +1 -1
  71. package/build-module/index.js +1 -7
  72. package/build-module/index.js.map +1 -1
  73. package/build-module/locks/actions.js +3 -4
  74. package/build-module/locks/actions.js.map +1 -1
  75. package/build-module/locks/reducer.js +1 -4
  76. package/build-module/locks/reducer.js.map +1 -1
  77. package/build-module/locks/selectors.js +3 -4
  78. package/build-module/locks/selectors.js.map +1 -1
  79. package/build-module/locks/utils.js +3 -5
  80. package/build-module/locks/utils.js.map +1 -1
  81. package/build-module/private-selectors.js +28 -0
  82. package/build-module/private-selectors.js.map +1 -0
  83. package/build-module/queried-data/actions.js +2 -5
  84. package/build-module/queried-data/actions.js.map +1 -1
  85. package/build-module/queried-data/reducer.js +17 -47
  86. package/build-module/queried-data/reducer.js.map +1 -1
  87. package/build-module/queried-data/selectors.js +4 -11
  88. package/build-module/queried-data/selectors.js.map +1 -1
  89. package/build-module/reducer.js +168 -194
  90. package/build-module/reducer.js.map +1 -1
  91. package/build-module/resolvers.js +175 -220
  92. package/build-module/resolvers.js.map +1 -1
  93. package/build-module/selectors.js +55 -61
  94. package/build-module/selectors.js.map +1 -1
  95. package/build-module/utils/forward-resolver.js +4 -11
  96. package/build-module/utils/forward-resolver.js.map +1 -1
  97. package/build-module/utils/on-sub-key.js +1 -3
  98. package/build-module/utils/on-sub-key.js.map +1 -1
  99. package/build-types/actions.d.ts.map +1 -1
  100. package/build-types/private-selectors.d.ts +25 -0
  101. package/build-types/private-selectors.d.ts.map +1 -0
  102. package/build-types/reducer.d.ts +6 -2
  103. package/build-types/reducer.d.ts.map +1 -1
  104. package/build-types/selectors.d.ts +16 -4
  105. package/build-types/selectors.d.ts.map +1 -1
  106. package/package.json +12 -12
  107. package/src/actions.js +9 -8
  108. package/src/index.js +0 -1
  109. package/src/private-selectors.ts +30 -0
  110. package/src/reducer.js +130 -104
  111. package/src/selectors.ts +33 -13
  112. package/src/test/reducer.js +89 -54
  113. package/src/test/selectors.js +8 -8
  114. package/tsconfig.tsbuildinfo +1 -1
package/build/reducer.js CHANGED
@@ -64,10 +64,7 @@ var _entities = require("./entities");
64
64
  *
65
65
  * @return {Object} Updated state.
66
66
  */
67
- function terms() {
68
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
69
- let action = arguments.length > 1 ? arguments[1] : undefined;
70
-
67
+ function terms(state = {}, action) {
71
68
  switch (action.type) {
72
69
  case 'RECEIVE_TERMS':
73
70
  return { ...state,
@@ -87,13 +84,10 @@ function terms() {
87
84
  */
88
85
 
89
86
 
90
- function users() {
91
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
92
- byId: {},
93
- queries: {}
94
- };
95
- let action = arguments.length > 1 ? arguments[1] : undefined;
96
-
87
+ function users(state = {
88
+ byId: {},
89
+ queries: {}
90
+ }, action) {
97
91
  switch (action.type) {
98
92
  case 'RECEIVE_USER_QUERY':
99
93
  return {
@@ -121,10 +115,7 @@ function users() {
121
115
  */
122
116
 
123
117
 
124
- function currentUser() {
125
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
126
- let action = arguments.length > 1 ? arguments[1] : undefined;
127
-
118
+ function currentUser(state = {}, action) {
128
119
  switch (action.type) {
129
120
  case 'RECEIVE_CURRENT_USER':
130
121
  return action.currentUser;
@@ -142,10 +133,7 @@ function currentUser() {
142
133
  */
143
134
 
144
135
 
145
- function taxonomies() {
146
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
147
- let action = arguments.length > 1 ? arguments[1] : undefined;
148
-
136
+ function taxonomies(state = [], action) {
149
137
  switch (action.type) {
150
138
  case 'RECEIVE_TAXONOMIES':
151
139
  return action.taxonomies;
@@ -163,10 +151,7 @@ function taxonomies() {
163
151
  */
164
152
 
165
153
 
166
- function currentTheme() {
167
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
168
- let action = arguments.length > 1 ? arguments[1] : undefined;
169
-
154
+ function currentTheme(state = undefined, action) {
170
155
  switch (action.type) {
171
156
  case 'RECEIVE_CURRENT_THEME':
172
157
  return action.currentTheme.stylesheet;
@@ -184,10 +169,7 @@ function currentTheme() {
184
169
  */
185
170
 
186
171
 
187
- function currentGlobalStylesId() {
188
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
189
- let action = arguments.length > 1 ? arguments[1] : undefined;
190
-
172
+ function currentGlobalStylesId(state = undefined, action) {
191
173
  switch (action.type) {
192
174
  case 'RECEIVE_CURRENT_GLOBAL_STYLES_ID':
193
175
  return action.id;
@@ -205,10 +187,7 @@ function currentGlobalStylesId() {
205
187
  */
206
188
 
207
189
 
208
- function themeBaseGlobalStyles() {
209
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
210
- let action = arguments.length > 1 ? arguments[1] : undefined;
211
-
190
+ function themeBaseGlobalStyles(state = {}, action) {
212
191
  switch (action.type) {
213
192
  case 'RECEIVE_THEME_GLOBAL_STYLES':
214
193
  return { ...state,
@@ -228,10 +207,7 @@ function themeBaseGlobalStyles() {
228
207
  */
229
208
 
230
209
 
231
- function themeGlobalStyleVariations() {
232
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
233
- let action = arguments.length > 1 ? arguments[1] : undefined;
234
-
210
+ function themeGlobalStyleVariations(state = {}, action) {
235
211
  switch (action.type) {
236
212
  case 'RECEIVE_THEME_GLOBAL_STYLE_VARIATIONS':
237
213
  return { ...state,
@@ -241,6 +217,36 @@ function themeGlobalStyleVariations() {
241
217
 
242
218
  return state;
243
219
  }
220
+
221
+ const withMultiEntityRecordEdits = reducer => (state, action) => {
222
+ if (action.type === 'UNDO' || action.type === 'REDO') {
223
+ const {
224
+ stackedEdits
225
+ } = action;
226
+ let newState = state;
227
+ stackedEdits.forEach(({
228
+ kind,
229
+ name,
230
+ recordId,
231
+ property,
232
+ from,
233
+ to
234
+ }) => {
235
+ newState = reducer(newState, {
236
+ type: 'EDIT_ENTITY_RECORD',
237
+ kind,
238
+ name,
239
+ recordId,
240
+ edits: {
241
+ [property]: action.type === 'UNDO' ? from : to
242
+ }
243
+ });
244
+ });
245
+ return newState;
246
+ }
247
+
248
+ return reducer(state, action);
249
+ };
244
250
  /**
245
251
  * Higher Order Reducer for a given entity config. It supports:
246
252
  *
@@ -255,7 +261,7 @@ function themeGlobalStyleVariations() {
255
261
 
256
262
 
257
263
  function entity(entityConfig) {
258
- return (0, _compose.compose)([// Limit to matching action type so we don't attempt to replace action on
264
+ return (0, _compose.compose)([withMultiEntityRecordEdits, // Limit to matching action type so we don't attempt to replace action on
259
265
  // an unhandled action.
260
266
  (0, _utils.ifMatchingAction)(action => action.name && action.kind && action.name === entityConfig.name && action.kind === entityConfig.kind), // Inject the entity config into the action.
261
267
  (0, _utils.replaceAction)(action => {
@@ -264,15 +270,12 @@ function entity(entityConfig) {
264
270
  };
265
271
  })])((0, _data.combineReducers)({
266
272
  queriedData: _queriedData.reducer,
267
- edits: function () {
268
- var _action$query$context, _action$query;
269
-
270
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
271
- let action = arguments.length > 1 ? arguments[1] : undefined;
273
+ edits: (state = {}, action) => {
274
+ var _action$query$context;
272
275
 
273
276
  switch (action.type) {
274
277
  case 'RECEIVE_ITEMS':
275
- const context = (_action$query$context = action === null || action === void 0 ? void 0 : (_action$query = action.query) === null || _action$query === void 0 ? void 0 : _action$query.context) !== null && _action$query$context !== void 0 ? _action$query$context : 'default';
278
+ const context = (_action$query$context = action?.query?.context) !== null && _action$query$context !== void 0 ? _action$query$context : 'default';
276
279
 
277
280
  if (context !== 'default') {
278
281
  return state;
@@ -290,14 +293,14 @@ function entity(entityConfig) {
290
293
  }
291
294
 
292
295
  const nextEdits = Object.keys(edits).reduce((acc, key) => {
293
- var _record$key$raw, _record$key;
296
+ var _record$key$raw;
294
297
 
295
298
  // If the edited value is still different to the persisted value,
296
299
  // keep the edited value in edits.
297
300
  if ( // Edits are the "raw" attribute values, but records may have
298
301
  // objects with more properties, so we use `get` here for the
299
302
  // comparison.
300
- !(0, _es.default)(edits[key], (_record$key$raw = (_record$key = record[key]) === null || _record$key === void 0 ? void 0 : _record$key.raw) !== null && _record$key$raw !== void 0 ? _record$key$raw : record[key]) && ( // Sometimes the server alters the sent value which means
303
+ !(0, _es.default)(edits[key], (_record$key$raw = record[key]?.raw) !== null && _record$key$raw !== void 0 ? _record$key$raw : record[key]) && ( // Sometimes the server alters the sent value which means
301
304
  // we need to also remove the edits before the api request.
302
305
  !action.persistedEdits || !(0, _es.default)(edits[key], action.persistedEdits[key]))) {
303
306
  acc[key] = edits[key];
@@ -333,10 +336,7 @@ function entity(entityConfig) {
333
336
 
334
337
  return state;
335
338
  },
336
- saving: function () {
337
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
338
- let action = arguments.length > 1 ? arguments[1] : undefined;
339
-
339
+ saving: (state = {}, action) => {
340
340
  switch (action.type) {
341
341
  case 'SAVE_ENTITY_RECORD_START':
342
342
  case 'SAVE_ENTITY_RECORD_FINISH':
@@ -351,10 +351,7 @@ function entity(entityConfig) {
351
351
 
352
352
  return state;
353
353
  },
354
- deleting: function () {
355
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
356
- let action = arguments.length > 1 ? arguments[1] : undefined;
357
-
354
+ deleting: (state = {}, action) => {
358
355
  switch (action.type) {
359
356
  case 'DELETE_ENTITY_RECORD_START':
360
357
  case 'DELETE_ENTITY_RECORD_FINISH':
@@ -380,10 +377,7 @@ function entity(entityConfig) {
380
377
  */
381
378
 
382
379
 
383
- function entitiesConfig() {
384
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _entities.rootEntitiesConfig;
385
- let action = arguments.length > 1 ? arguments[1] : undefined;
386
-
380
+ function entitiesConfig(state = _entities.rootEntitiesConfig, action) {
387
381
  switch (action.type) {
388
382
  case 'ADD_ENTITIES':
389
383
  return [...state, ...action.entities];
@@ -401,9 +395,7 @@ function entitiesConfig() {
401
395
  */
402
396
 
403
397
 
404
- const entities = function () {
405
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
406
- let action = arguments.length > 1 ? arguments[1] : undefined;
398
+ const entities = (state = {}, action) => {
407
399
  const newConfig = entitiesConfig(state.config, action); // Generates a dynamic reducer for the entities.
408
400
 
409
401
  let entitiesDataReducer = state.reducer;
@@ -421,8 +413,7 @@ const entities = function () {
421
413
  acc[kind].push(record);
422
414
  return acc;
423
415
  }, {});
424
- entitiesDataReducer = (0, _data.combineReducers)(Object.entries(entitiesByKind).reduce((memo, _ref) => {
425
- let [kind, subEntities] = _ref;
416
+ entitiesDataReducer = (0, _data.combineReducers)(Object.entries(entitiesByKind).reduce((memo, [kind, subEntities]) => {
426
417
  const kindReducer = (0, _data.combineReducers)(subEntities.reduce((kindMemo, entityConfig) => ({ ...kindMemo,
427
418
  [entityConfig.name]: entity(entityConfig)
428
419
  }), {}));
@@ -446,8 +437,9 @@ const entities = function () {
446
437
  /**
447
438
  * @typedef {Object} UndoStateMeta
448
439
  *
449
- * @property {number} offset Where in the undo stack we are.
450
- * @property {Object} [flattenedUndo] Flattened form of undo stack.
440
+ * @property {number} list The undo stack.
441
+ * @property {number} offset Where in the undo stack we are.
442
+ * @property {Object} cache Cache of unpersisted transient edits.
451
443
  */
452
444
 
453
445
  /** @typedef {Array<Object> & UndoStateMeta} UndoState */
@@ -460,12 +452,10 @@ const entities = function () {
460
452
 
461
453
 
462
454
  exports.entities = entities;
463
- const UNDO_INITIAL_STATE = Object.assign([], {
455
+ const UNDO_INITIAL_STATE = {
456
+ list: [],
464
457
  offset: 0
465
- });
466
- /** @type {Object} */
467
-
468
- let lastEditAction;
458
+ };
469
459
  /**
470
460
  * Reducer keeping track of entity edit undo history.
471
461
  *
@@ -475,117 +465,121 @@ let lastEditAction;
475
465
  * @return {UndoState} Updated state.
476
466
  */
477
467
 
478
- function undo() {
479
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : UNDO_INITIAL_STATE;
480
- let action = arguments.length > 1 ? arguments[1] : undefined;
468
+ function undo(state = UNDO_INITIAL_STATE, action) {
469
+ const omitPendingRedos = currentState => {
470
+ return { ...currentState,
471
+ list: currentState.list.slice(0, currentState.offset || undefined),
472
+ offset: 0
473
+ };
474
+ };
481
475
 
482
- switch (action.type) {
483
- case 'EDIT_ENTITY_RECORD':
484
- case 'CREATE_UNDO_LEVEL':
485
- let isCreateUndoLevel = action.type === 'CREATE_UNDO_LEVEL';
486
- const isUndoOrRedo = !isCreateUndoLevel && (action.meta.isUndo || action.meta.isRedo);
487
-
488
- if (isCreateUndoLevel) {
489
- action = lastEditAction;
490
- } else if (!isUndoOrRedo) {
491
- // Don't lose the last edit cache if the new one only has transient edits.
492
- // Transient edits don't create new levels so updating the cache would make
493
- // us skip an edit later when creating levels explicitly.
494
- if (Object.keys(action.edits).some(key => !action.transientEdits[key])) {
495
- lastEditAction = action;
496
- } else {
497
- lastEditAction = { ...action,
498
- edits: { ...(lastEditAction && lastEditAction.edits),
499
- ...action.edits
500
- }
501
- };
502
- }
503
- }
504
- /** @type {UndoState} */
505
-
506
-
507
- let nextState;
508
-
509
- if (isUndoOrRedo) {
510
- // @ts-ignore we might consider using Object.assign({}, state)
511
- nextState = [...state];
512
- nextState.offset = state.offset + (action.meta.isUndo ? -1 : 1);
513
-
514
- if (state.flattenedUndo) {
515
- // The first undo in a sequence of undos might happen while we have
516
- // flattened undos in state. If this is the case, we want execution
517
- // to continue as if we were creating an explicit undo level. This
518
- // will result in an extra undo level being appended with the flattened
519
- // undo values.
520
- // We also have to take into account if the `lastEditAction` had opted out
521
- // of being tracked in undo history, like the action that persists the latest
522
- // content right before saving. In that case we have to update the `lastEditAction`
523
- // to avoid returning early before applying the existing flattened undos.
524
- isCreateUndoLevel = true;
525
-
526
- if (!lastEditAction.meta.undo) {
527
- lastEditAction.meta.undo = {
528
- edits: {}
529
- };
530
- }
476
+ const appendCachedEditsToLastUndo = currentState => {
477
+ if (!currentState.cache) {
478
+ return currentState;
479
+ }
531
480
 
532
- action = lastEditAction;
533
- } else {
534
- return nextState;
535
- }
536
- }
481
+ let nextState = { ...currentState,
482
+ list: [...currentState.list]
483
+ };
484
+ nextState = omitPendingRedos(nextState);
485
+ const previousUndoState = nextState.list.pop();
486
+ const updatedUndoState = currentState.cache.reduce(appendEditToStack, previousUndoState);
487
+ nextState.list.push(updatedUndoState);
488
+ return { ...nextState,
489
+ cache: undefined
490
+ };
491
+ };
537
492
 
538
- if (!action.meta.undo) {
539
- return state;
540
- } // Transient edits don't create an undo level, but are
541
- // reachable in the next meaningful edit to which they
542
- // are merged. They are defined in the entity's config.
493
+ const appendEditToStack = (stack = [], {
494
+ kind,
495
+ name,
496
+ recordId,
497
+ property,
498
+ from,
499
+ to
500
+ }) => {
501
+ const existingEditIndex = stack?.findIndex(({
502
+ kind: k,
503
+ name: n,
504
+ recordId: r,
505
+ property: p
506
+ }) => {
507
+ return k === kind && n === name && r === recordId && p === property;
508
+ });
509
+ const nextStack = [...stack];
510
+
511
+ if (existingEditIndex !== -1) {
512
+ // If the edit is already in the stack leave the initial "from" value.
513
+ nextStack[existingEditIndex] = { ...nextStack[existingEditIndex],
514
+ to
515
+ };
516
+ } else {
517
+ nextStack.push({
518
+ kind,
519
+ name,
520
+ recordId,
521
+ property,
522
+ from,
523
+ to
524
+ });
525
+ }
543
526
 
527
+ return nextStack;
528
+ };
544
529
 
545
- if (!isCreateUndoLevel && !Object.keys(action.edits).some(key => !action.transientEdits[key])) {
546
- // @ts-ignore we might consider using Object.assign({}, state)
547
- nextState = [...state];
548
- nextState.flattenedUndo = { ...state.flattenedUndo,
549
- ...action.edits
530
+ switch (action.type) {
531
+ case 'CREATE_UNDO_LEVEL':
532
+ return appendCachedEditsToLastUndo(state);
533
+
534
+ case 'UNDO':
535
+ case 'REDO':
536
+ {
537
+ const nextState = appendCachedEditsToLastUndo(state);
538
+ return { ...nextState,
539
+ offset: state.offset + (action.type === 'UNDO' ? -1 : 1)
550
540
  };
551
- nextState.offset = state.offset;
552
- return nextState;
553
- } // Clear potential redos, because this only supports linear history.
554
-
541
+ }
555
542
 
556
- nextState = // @ts-ignore this needs additional cleanup, probably involving code-level changes
557
- nextState || state.slice(0, state.offset || undefined);
558
- nextState.offset = nextState.offset || 0;
559
- nextState.pop();
543
+ case 'EDIT_ENTITY_RECORD':
544
+ {
545
+ if (!action.meta.undo) {
546
+ return state;
547
+ }
560
548
 
561
- if (!isCreateUndoLevel) {
562
- nextState.push({
563
- kind: action.meta.undo.kind,
564
- name: action.meta.undo.name,
565
- recordId: action.meta.undo.recordId,
566
- edits: { ...state.flattenedUndo,
567
- ...action.meta.undo.edits
568
- }
549
+ const isCachedChange = Object.keys(action.edits).every(key => action.transientEdits[key]);
550
+ const edits = Object.keys(action.edits).map(key => {
551
+ return {
552
+ kind: action.kind,
553
+ name: action.name,
554
+ recordId: action.recordId,
555
+ property: key,
556
+ from: action.meta.undo.edits[key],
557
+ to: action.edits[key]
558
+ };
569
559
  });
570
- } // When an edit is a function it's an optimization to avoid running some expensive operation.
571
- // We can't rely on the function references being the same so we opt out of comparing them here.
572
560
 
561
+ if (isCachedChange) {
562
+ return { ...state,
563
+ cache: edits.reduce(appendEditToStack, state.cache)
564
+ };
565
+ }
573
566
 
574
- const comparisonUndoEdits = Object.values(action.meta.undo.edits).filter(edit => typeof edit !== 'function');
575
- const comparisonEdits = Object.values(action.edits).filter(edit => typeof edit !== 'function');
567
+ let nextState = omitPendingRedos(state);
568
+ nextState = appendCachedEditsToLastUndo(nextState);
569
+ nextState = { ...nextState,
570
+ list: [...nextState.list]
571
+ }; // When an edit is a function it's an optimization to avoid running some expensive operation.
572
+ // We can't rely on the function references being the same so we opt out of comparing them here.
576
573
 
577
- if (!(0, _isShallowEqual.default)(comparisonUndoEdits, comparisonEdits)) {
578
- nextState.push({
579
- kind: action.kind,
580
- name: action.name,
581
- recordId: action.recordId,
582
- edits: isCreateUndoLevel ? { ...state.flattenedUndo,
583
- ...action.edits
584
- } : action.edits
585
- });
586
- }
574
+ const comparisonUndoEdits = Object.values(action.meta.undo.edits).filter(edit => typeof edit !== 'function');
575
+ const comparisonEdits = Object.values(action.edits).filter(edit => typeof edit !== 'function');
576
+
577
+ if (!(0, _isShallowEqual.default)(comparisonUndoEdits, comparisonEdits)) {
578
+ nextState.list.push(edits);
579
+ }
587
580
 
588
- return nextState;
581
+ return nextState;
582
+ }
589
583
  }
590
584
 
591
585
  return state;
@@ -600,10 +594,7 @@ function undo() {
600
594
  */
601
595
 
602
596
 
603
- function embedPreviews() {
604
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
605
- let action = arguments.length > 1 ? arguments[1] : undefined;
606
-
597
+ function embedPreviews(state = {}, action) {
607
598
  switch (action.type) {
608
599
  case 'RECEIVE_EMBED_PREVIEW':
609
600
  const {
@@ -628,10 +619,7 @@ function embedPreviews() {
628
619
  */
629
620
 
630
621
 
631
- function userPermissions() {
632
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
633
- let action = arguments.length > 1 ? arguments[1] : undefined;
634
-
622
+ function userPermissions(state = {}, action) {
635
623
  switch (action.type) {
636
624
  case 'RECEIVE_USER_PERMISSION':
637
625
  return { ...state,
@@ -651,10 +639,7 @@ function userPermissions() {
651
639
  */
652
640
 
653
641
 
654
- function autosaves() {
655
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
656
- let action = arguments.length > 1 ? arguments[1] : undefined;
657
-
642
+ function autosaves(state = {}, action) {
658
643
  switch (action.type) {
659
644
  case 'RECEIVE_AUTOSAVES':
660
645
  const {
@@ -669,10 +654,7 @@ function autosaves() {
669
654
  return state;
670
655
  }
671
656
 
672
- function blockPatterns() {
673
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
674
- let action = arguments.length > 1 ? arguments[1] : undefined;
675
-
657
+ function blockPatterns(state = [], action) {
676
658
  switch (action.type) {
677
659
  case 'RECEIVE_BLOCK_PATTERNS':
678
660
  return action.patterns;
@@ -681,10 +663,7 @@ function blockPatterns() {
681
663
  return state;
682
664
  }
683
665
 
684
- function blockPatternCategories() {
685
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
686
- let action = arguments.length > 1 ? arguments[1] : undefined;
687
-
666
+ function blockPatternCategories(state = [], action) {
688
667
  switch (action.type) {
689
668
  case 'RECEIVE_BLOCK_PATTERN_CATEGORIES':
690
669
  return action.categories;
@@ -693,10 +672,7 @@ function blockPatternCategories() {
693
672
  return state;
694
673
  }
695
674
 
696
- function navigationFallbackId() {
697
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
698
- let action = arguments.length > 1 ? arguments[1] : undefined;
699
-
675
+ function navigationFallbackId(state = null, action) {
700
676
  switch (action.type) {
701
677
  case 'RECEIVE_NAVIGATION_FALLBACK_ID':
702
678
  return action.fallbackId;
@@ -714,10 +690,7 @@ function navigationFallbackId() {
714
690
  */
715
691
 
716
692
 
717
- function themeGlobalStyleRevisions() {
718
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
719
- let action = arguments.length > 1 ? arguments[1] : undefined;
720
-
693
+ function themeGlobalStyleRevisions(state = {}, action) {
721
694
  switch (action.type) {
722
695
  case 'RECEIVE_THEME_GLOBAL_STYLE_REVISIONS':
723
696
  return { ...state,