@wordpress/core-data 6.18.0 → 6.19.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 (107) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +13 -1
  3. package/build/actions.js +34 -30
  4. package/build/actions.js.map +1 -1
  5. package/build/entity-provider.js +2 -99
  6. package/build/entity-provider.js.map +1 -1
  7. package/build/entity-types/helpers.js.map +1 -1
  8. package/build/footnotes/get-footnotes-order.js +35 -0
  9. package/build/footnotes/get-footnotes-order.js.map +1 -0
  10. package/build/footnotes/get-rich-text-values-cached.js +39 -0
  11. package/build/footnotes/get-rich-text-values-cached.js.map +1 -0
  12. package/build/footnotes/index.js +96 -0
  13. package/build/footnotes/index.js.map +1 -0
  14. package/build/hooks/use-entity-record.js +6 -3
  15. package/build/hooks/use-entity-record.js.map +1 -1
  16. package/build/hooks/use-resource-permissions.js.map +1 -1
  17. package/build/private-selectors.js +4 -17
  18. package/build/private-selectors.js.map +1 -1
  19. package/build/reducer.js +33 -145
  20. package/build/reducer.js.map +1 -1
  21. package/build/resolvers.js +20 -1
  22. package/build/resolvers.js.map +1 -1
  23. package/build/selectors.js +21 -25
  24. package/build/selectors.js.map +1 -1
  25. package/build/utils/get-nested-value.js +30 -0
  26. package/build/utils/get-nested-value.js.map +1 -0
  27. package/build/utils/index.js +7 -0
  28. package/build/utils/index.js.map +1 -1
  29. package/build/utils/set-nested-value.js +11 -6
  30. package/build/utils/set-nested-value.js.map +1 -1
  31. package/build-module/actions.js +32 -28
  32. package/build-module/actions.js.map +1 -1
  33. package/build-module/entity-provider.js +2 -99
  34. package/build-module/entity-provider.js.map +1 -1
  35. package/build-module/entity-types/helpers.js.map +1 -1
  36. package/build-module/footnotes/get-footnotes-order.js +27 -0
  37. package/build-module/footnotes/get-footnotes-order.js.map +1 -0
  38. package/build-module/footnotes/get-rich-text-values-cached.js +33 -0
  39. package/build-module/footnotes/get-rich-text-values-cached.js.map +1 -0
  40. package/build-module/footnotes/index.js +88 -0
  41. package/build-module/footnotes/index.js.map +1 -0
  42. package/build-module/hooks/use-entity-record.js +6 -3
  43. package/build-module/hooks/use-entity-record.js.map +1 -1
  44. package/build-module/hooks/use-resource-permissions.js.map +1 -1
  45. package/build-module/private-selectors.js +3 -15
  46. package/build-module/private-selectors.js.map +1 -1
  47. package/build-module/reducer.js +30 -144
  48. package/build-module/reducer.js.map +1 -1
  49. package/build-module/resolvers.js +18 -0
  50. package/build-module/resolvers.js.map +1 -1
  51. package/build-module/selectors.js +19 -29
  52. package/build-module/selectors.js.map +1 -1
  53. package/build-module/utils/get-nested-value.js +24 -0
  54. package/build-module/utils/get-nested-value.js.map +1 -0
  55. package/build-module/utils/index.js +1 -0
  56. package/build-module/utils/index.js.map +1 -1
  57. package/build-module/utils/set-nested-value.js +11 -6
  58. package/build-module/utils/set-nested-value.js.map +1 -1
  59. package/build-types/actions.d.ts +1 -6
  60. package/build-types/actions.d.ts.map +1 -1
  61. package/build-types/entity-provider.d.ts.map +1 -1
  62. package/build-types/footnotes/get-footnotes-order.d.ts +2 -0
  63. package/build-types/footnotes/get-footnotes-order.d.ts.map +1 -0
  64. package/build-types/footnotes/get-rich-text-values-cached.d.ts +2 -0
  65. package/build-types/footnotes/get-rich-text-values-cached.d.ts.map +1 -0
  66. package/build-types/footnotes/index.d.ts +4 -0
  67. package/build-types/footnotes/index.d.ts.map +1 -0
  68. package/build-types/hooks/use-entity-record.d.ts +2 -0
  69. package/build-types/hooks/use-entity-record.d.ts.map +1 -1
  70. package/build-types/index.d.ts +3 -2
  71. package/build-types/index.d.ts.map +1 -1
  72. package/build-types/private-selectors.d.ts +3 -13
  73. package/build-types/private-selectors.d.ts.map +1 -1
  74. package/build-types/reducer.d.ts +7 -23
  75. package/build-types/reducer.d.ts.map +1 -1
  76. package/build-types/resolvers.d.ts +4 -0
  77. package/build-types/resolvers.d.ts.map +1 -1
  78. package/build-types/selectors.d.ts +19 -14
  79. package/build-types/selectors.d.ts.map +1 -1
  80. package/build-types/utils/get-nested-value.d.ts +14 -0
  81. package/build-types/utils/get-nested-value.d.ts.map +1 -0
  82. package/build-types/utils/index.d.ts +1 -0
  83. package/build-types/utils/set-nested-value.d.ts +8 -4
  84. package/build-types/utils/set-nested-value.d.ts.map +1 -1
  85. package/package.json +16 -15
  86. package/src/actions.js +36 -26
  87. package/src/entity-provider.js +2 -134
  88. package/src/entity-types/helpers.ts +2 -2
  89. package/src/footnotes/get-footnotes-order.js +30 -0
  90. package/src/footnotes/get-rich-text-values-cached.js +35 -0
  91. package/src/footnotes/index.js +119 -0
  92. package/src/hooks/test/use-entity-record.js +4 -0
  93. package/src/hooks/use-entity-record.ts +12 -3
  94. package/src/hooks/use-resource-permissions.ts +1 -1
  95. package/src/private-selectors.ts +4 -17
  96. package/src/reducer.js +36 -155
  97. package/src/resolvers.js +25 -0
  98. package/src/selectors.ts +39 -51
  99. package/src/test/reducer.js +0 -233
  100. package/src/test/selectors.js +0 -54
  101. package/src/utils/get-nested-value.js +27 -0
  102. package/src/utils/index.js +1 -0
  103. package/src/utils/set-nested-value.js +12 -6
  104. package/src/utils/test/get-nested-value.js +61 -0
  105. package/src/utils/test/set-nested-value.js +7 -0
  106. package/tsconfig.json +1 -0
  107. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = getFootnotesOrder;
8
+ var _getRichTextValuesCached = _interopRequireDefault(require("./get-rich-text-values-cached"));
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+
13
+ const cache = new WeakMap();
14
+ function getBlockFootnotesOrder(block) {
15
+ if (!cache.has(block)) {
16
+ const content = (0, _getRichTextValuesCached.default)(block).join('');
17
+ const newOrder = [];
18
+
19
+ // https://github.com/WordPress/gutenberg/pull/43204 lands. We can then
20
+ // get the order directly from the rich text values.
21
+ if (content.indexOf('data-fn') !== -1) {
22
+ const regex = /data-fn="([^"]+)"/g;
23
+ let match;
24
+ while ((match = regex.exec(content)) !== null) {
25
+ newOrder.push(match[1]);
26
+ }
27
+ }
28
+ cache.set(block, newOrder);
29
+ }
30
+ return cache.get(block);
31
+ }
32
+ function getFootnotesOrder(blocks) {
33
+ return blocks.flatMap(getBlockFootnotesOrder);
34
+ }
35
+ //# sourceMappingURL=get-footnotes-order.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_getRichTextValuesCached","_interopRequireDefault","require","cache","WeakMap","getBlockFootnotesOrder","block","has","content","getRichTextValuesCached","join","newOrder","indexOf","regex","match","exec","push","set","get","getFootnotesOrder","blocks","flatMap"],"sources":["@wordpress/core-data/src/footnotes/get-footnotes-order.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getRichTextValuesCached from './get-rich-text-values-cached';\n\nconst cache = new WeakMap();\n\nfunction getBlockFootnotesOrder( block ) {\n\tif ( ! cache.has( block ) ) {\n\t\tconst content = getRichTextValuesCached( block ).join( '' );\n\t\tconst newOrder = [];\n\n\t\t// https://github.com/WordPress/gutenberg/pull/43204 lands. We can then\n\t\t// get the order directly from the rich text values.\n\t\tif ( content.indexOf( 'data-fn' ) !== -1 ) {\n\t\t\tconst regex = /data-fn=\"([^\"]+)\"/g;\n\t\t\tlet match;\n\t\t\twhile ( ( match = regex.exec( content ) ) !== null ) {\n\t\t\t\tnewOrder.push( match[ 1 ] );\n\t\t\t}\n\t\t}\n\t\tcache.set( block, newOrder );\n\t}\n\n\treturn cache.get( block );\n}\n\nexport default function getFootnotesOrder( blocks ) {\n\treturn blocks.flatMap( getBlockFootnotesOrder );\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,wBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA,MAAMC,KAAK,GAAG,IAAIC,OAAO,CAAC,CAAC;AAE3B,SAASC,sBAAsBA,CAAEC,KAAK,EAAG;EACxC,IAAK,CAAEH,KAAK,CAACI,GAAG,CAAED,KAAM,CAAC,EAAG;IAC3B,MAAME,OAAO,GAAG,IAAAC,gCAAuB,EAAEH,KAAM,CAAC,CAACI,IAAI,CAAE,EAAG,CAAC;IAC3D,MAAMC,QAAQ,GAAG,EAAE;;IAEnB;IACA;IACA,IAAKH,OAAO,CAACI,OAAO,CAAE,SAAU,CAAC,KAAK,CAAC,CAAC,EAAG;MAC1C,MAAMC,KAAK,GAAG,oBAAoB;MAClC,IAAIC,KAAK;MACT,OAAQ,CAAEA,KAAK,GAAGD,KAAK,CAACE,IAAI,CAAEP,OAAQ,CAAC,MAAO,IAAI,EAAG;QACpDG,QAAQ,CAACK,IAAI,CAAEF,KAAK,CAAE,CAAC,CAAG,CAAC;MAC5B;IACD;IACAX,KAAK,CAACc,GAAG,CAAEX,KAAK,EAAEK,QAAS,CAAC;EAC7B;EAEA,OAAOR,KAAK,CAACe,GAAG,CAAEZ,KAAM,CAAC;AAC1B;AAEe,SAASa,iBAAiBA,CAAEC,MAAM,EAAG;EACnD,OAAOA,MAAM,CAACC,OAAO,CAAEhB,sBAAuB,CAAC;AAChD"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = getRichTextValuesCached;
7
+ var _blockEditor = require("@wordpress/block-editor");
8
+ var _privateApis = require("../private-apis");
9
+ /**
10
+ * WordPress dependencies
11
+ */
12
+
13
+ /**
14
+ * Internal dependencies
15
+ */
16
+
17
+ // TODO: The following line should have been:
18
+ //
19
+ // const unlockedApis = unlock( blockEditorPrivateApis );
20
+ //
21
+ // But there are hidden circular dependencies in RNMobile code, specifically in
22
+ // certain native components in the `components` package that depend on
23
+ // `block-editor`. What follows is a workaround that defers the `unlock` call
24
+ // to prevent native code from failing.
25
+ //
26
+ // Fix once https://github.com/WordPress/gutenberg/issues/52692 is closed.
27
+ let unlockedApis;
28
+ const cache = new WeakMap();
29
+ function getRichTextValuesCached(block) {
30
+ if (!unlockedApis) {
31
+ unlockedApis = (0, _privateApis.unlock)(_blockEditor.privateApis);
32
+ }
33
+ if (!cache.has(block)) {
34
+ const values = unlockedApis.getRichTextValues([block]);
35
+ cache.set(block, values);
36
+ }
37
+ return cache.get(block);
38
+ }
39
+ //# sourceMappingURL=get-rich-text-values-cached.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_blockEditor","require","_privateApis","unlockedApis","cache","WeakMap","getRichTextValuesCached","block","unlock","blockEditorPrivateApis","has","values","getRichTextValues","set","get"],"sources":["@wordpress/core-data/src/footnotes/get-rich-text-values-cached.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../private-apis';\n\n// TODO: The following line should have been:\n//\n// const unlockedApis = unlock( blockEditorPrivateApis );\n//\n// But there are hidden circular dependencies in RNMobile code, specifically in\n// certain native components in the `components` package that depend on\n// `block-editor`. What follows is a workaround that defers the `unlock` call\n// to prevent native code from failing.\n//\n// Fix once https://github.com/WordPress/gutenberg/issues/52692 is closed.\nlet unlockedApis;\n\nconst cache = new WeakMap();\n\nexport default function getRichTextValuesCached( block ) {\n\tif ( ! unlockedApis ) {\n\t\tunlockedApis = unlock( blockEditorPrivateApis );\n\t}\n\n\tif ( ! cache.has( block ) ) {\n\t\tconst values = unlockedApis.getRichTextValues( [ block ] );\n\t\tcache.set( block, values );\n\t}\n\treturn cache.get( block );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAKA,IAAAC,YAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIE,YAAY;AAEhB,MAAMC,KAAK,GAAG,IAAIC,OAAO,CAAC,CAAC;AAEZ,SAASC,uBAAuBA,CAAEC,KAAK,EAAG;EACxD,IAAK,CAAEJ,YAAY,EAAG;IACrBA,YAAY,GAAG,IAAAK,mBAAM,EAAEC,wBAAuB,CAAC;EAChD;EAEA,IAAK,CAAEL,KAAK,CAACM,GAAG,CAAEH,KAAM,CAAC,EAAG;IAC3B,MAAMI,MAAM,GAAGR,YAAY,CAACS,iBAAiB,CAAE,CAAEL,KAAK,CAAG,CAAC;IAC1DH,KAAK,CAACS,GAAG,CAAEN,KAAK,EAAEI,MAAO,CAAC;EAC3B;EACA,OAAOP,KAAK,CAACU,GAAG,CAAEP,KAAM,CAAC;AAC1B"}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.updateFootnotesFromMeta = updateFootnotesFromMeta;
8
+ var _getFootnotesOrder = _interopRequireDefault(require("./get-footnotes-order"));
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+
13
+ let oldFootnotes = {};
14
+ function updateFootnotesFromMeta(blocks, meta) {
15
+ const output = {
16
+ blocks
17
+ };
18
+ if (!meta) return output;
19
+
20
+ // If meta.footnotes is empty, it means the meta is not registered.
21
+ if (meta.footnotes === undefined) return output;
22
+ const newOrder = (0, _getFootnotesOrder.default)(blocks);
23
+ const footnotes = meta.footnotes ? JSON.parse(meta.footnotes) : [];
24
+ const currentOrder = footnotes.map(fn => fn.id);
25
+ if (currentOrder.join('') === newOrder.join('')) return output;
26
+ const newFootnotes = newOrder.map(fnId => footnotes.find(fn => fn.id === fnId) || oldFootnotes[fnId] || {
27
+ id: fnId,
28
+ content: ''
29
+ });
30
+ function updateAttributes(attributes) {
31
+ // Only attempt to update attributes, if attributes is an object.
32
+ if (!attributes || Array.isArray(attributes) || typeof attributes !== 'object') {
33
+ return attributes;
34
+ }
35
+ attributes = {
36
+ ...attributes
37
+ };
38
+ for (const key in attributes) {
39
+ const value = attributes[key];
40
+ if (Array.isArray(value)) {
41
+ attributes[key] = value.map(updateAttributes);
42
+ continue;
43
+ }
44
+ if (typeof value !== 'string') {
45
+ continue;
46
+ }
47
+ if (value.indexOf('data-fn') === -1) {
48
+ continue;
49
+ }
50
+
51
+ // When we store rich text values, this would no longer
52
+ // require a regex.
53
+ const regex = /(<sup[^>]+data-fn="([^"]+)"[^>]*><a[^>]*>)[\d*]*<\/a><\/sup>/g;
54
+ attributes[key] = value.replace(regex, (match, opening, fnId) => {
55
+ const index = newOrder.indexOf(fnId);
56
+ return `${opening}${index + 1}</a></sup>`;
57
+ });
58
+ const compatRegex = /<a[^>]+data-fn="([^"]+)"[^>]*>\*<\/a>/g;
59
+ attributes[key] = attributes[key].replace(compatRegex, (match, fnId) => {
60
+ const index = newOrder.indexOf(fnId);
61
+ return `<sup data-fn="${fnId}" class="fn"><a href="#${fnId}" id="${fnId}-link">${index + 1}</a></sup>`;
62
+ });
63
+ }
64
+ return attributes;
65
+ }
66
+ function updateBlocksAttributes(__blocks) {
67
+ return __blocks.map(block => {
68
+ return {
69
+ ...block,
70
+ attributes: updateAttributes(block.attributes),
71
+ innerBlocks: updateBlocksAttributes(block.innerBlocks)
72
+ };
73
+ });
74
+ }
75
+
76
+ // We need to go through all block attributes deeply and update the
77
+ // footnote anchor numbering (textContent) to match the new order.
78
+ const newBlocks = updateBlocksAttributes(blocks);
79
+ oldFootnotes = {
80
+ ...oldFootnotes,
81
+ ...footnotes.reduce((acc, fn) => {
82
+ if (!newOrder.includes(fn.id)) {
83
+ acc[fn.id] = fn;
84
+ }
85
+ return acc;
86
+ }, {})
87
+ };
88
+ return {
89
+ meta: {
90
+ ...meta,
91
+ footnotes: JSON.stringify(newFootnotes)
92
+ },
93
+ blocks: newBlocks
94
+ };
95
+ }
96
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_getFootnotesOrder","_interopRequireDefault","require","oldFootnotes","updateFootnotesFromMeta","blocks","meta","output","footnotes","undefined","newOrder","getFootnotesOrder","JSON","parse","currentOrder","map","fn","id","join","newFootnotes","fnId","find","content","updateAttributes","attributes","Array","isArray","key","value","indexOf","regex","replace","match","opening","index","compatRegex","updateBlocksAttributes","__blocks","block","innerBlocks","newBlocks","reduce","acc","includes","stringify"],"sources":["@wordpress/core-data/src/footnotes/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getFootnotesOrder from './get-footnotes-order';\n\nlet oldFootnotes = {};\n\nexport function updateFootnotesFromMeta( blocks, meta ) {\n\tconst output = { blocks };\n\tif ( ! meta ) return output;\n\n\t// If meta.footnotes is empty, it means the meta is not registered.\n\tif ( meta.footnotes === undefined ) return output;\n\n\tconst newOrder = getFootnotesOrder( blocks );\n\n\tconst footnotes = meta.footnotes ? JSON.parse( meta.footnotes ) : [];\n\tconst currentOrder = footnotes.map( ( fn ) => fn.id );\n\n\tif ( currentOrder.join( '' ) === newOrder.join( '' ) ) return output;\n\n\tconst newFootnotes = newOrder.map(\n\t\t( fnId ) =>\n\t\t\tfootnotes.find( ( fn ) => fn.id === fnId ) ||\n\t\t\toldFootnotes[ fnId ] || {\n\t\t\t\tid: fnId,\n\t\t\t\tcontent: '',\n\t\t\t}\n\t);\n\n\tfunction updateAttributes( attributes ) {\n\t\t// Only attempt to update attributes, if attributes is an object.\n\t\tif (\n\t\t\t! attributes ||\n\t\t\tArray.isArray( attributes ) ||\n\t\t\ttypeof attributes !== 'object'\n\t\t) {\n\t\t\treturn attributes;\n\t\t}\n\n\t\tattributes = { ...attributes };\n\n\t\tfor ( const key in attributes ) {\n\t\t\tconst value = attributes[ key ];\n\n\t\t\tif ( Array.isArray( value ) ) {\n\t\t\t\tattributes[ key ] = value.map( updateAttributes );\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif ( typeof value !== 'string' ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif ( value.indexOf( 'data-fn' ) === -1 ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// When we store rich text values, this would no longer\n\t\t\t// require a regex.\n\t\t\tconst regex =\n\t\t\t\t/(<sup[^>]+data-fn=\"([^\"]+)\"[^>]*><a[^>]*>)[\\d*]*<\\/a><\\/sup>/g;\n\n\t\t\tattributes[ key ] = value.replace(\n\t\t\t\tregex,\n\t\t\t\t( match, opening, fnId ) => {\n\t\t\t\t\tconst index = newOrder.indexOf( fnId );\n\t\t\t\t\treturn `${ opening }${ index + 1 }</a></sup>`;\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tconst compatRegex = /<a[^>]+data-fn=\"([^\"]+)\"[^>]*>\\*<\\/a>/g;\n\n\t\t\tattributes[ key ] = attributes[ key ].replace(\n\t\t\t\tcompatRegex,\n\t\t\t\t( match, fnId ) => {\n\t\t\t\t\tconst index = newOrder.indexOf( fnId );\n\t\t\t\t\treturn `<sup data-fn=\"${ fnId }\" class=\"fn\"><a href=\"#${ fnId }\" id=\"${ fnId }-link\">${\n\t\t\t\t\t\tindex + 1\n\t\t\t\t\t}</a></sup>`;\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\treturn attributes;\n\t}\n\n\tfunction updateBlocksAttributes( __blocks ) {\n\t\treturn __blocks.map( ( block ) => {\n\t\t\treturn {\n\t\t\t\t...block,\n\t\t\t\tattributes: updateAttributes( block.attributes ),\n\t\t\t\tinnerBlocks: updateBlocksAttributes( block.innerBlocks ),\n\t\t\t};\n\t\t} );\n\t}\n\n\t// We need to go through all block attributes deeply and update the\n\t// footnote anchor numbering (textContent) to match the new order.\n\tconst newBlocks = updateBlocksAttributes( blocks );\n\n\toldFootnotes = {\n\t\t...oldFootnotes,\n\t\t...footnotes.reduce( ( acc, fn ) => {\n\t\t\tif ( ! newOrder.includes( fn.id ) ) {\n\t\t\t\tacc[ fn.id ] = fn;\n\t\t\t}\n\t\t\treturn acc;\n\t\t}, {} ),\n\t};\n\n\treturn {\n\t\tmeta: {\n\t\t\t...meta,\n\t\t\tfootnotes: JSON.stringify( newFootnotes ),\n\t\t},\n\t\tblocks: newBlocks,\n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AAsB,CAAEE,KAAK,CAACC,WAAY;MACxD,CAAC;IACF,CAAE,CAAC;EACJ;;EAEA;EACA;EACA,MAAMC,SAAS,GAAGJ,sBAAsB,CAAE/B,MAAO,CAAC;EAElDF,YAAY,GAAG;IACd,GAAGA,YAAY;IACf,GAAGK,SAAS,CAACiC,MAAM,CAAE,CAAEC,GAAG,EAAE1B,EAAE,KAAM;MACnC,IAAK,CAAEN,QAAQ,CAACiC,QAAQ,CAAE3B,EAAE,CAACC,EAAG,CAAC,EAAG;QACnCyB,GAAG,CAAE1B,EAAE,CAACC,EAAE,CAAE,GAAGD,EAAE;MAClB;MACA,OAAO0B,GAAG;IACX,CAAC,EAAE,CAAC,CAAE;EACP,CAAC;EAED,OAAO;IACNpC,IAAI,EAAE;MACL,GAAGA,IAAI;MACPE,SAAS,EAAEI,IAAI,CAACgC,SAAS,CAAEzB,YAAa;IACzC,CAAC;IACDd,MAAM,EAAEmC;EACT,CAAC;AACF"}
@@ -115,7 +115,7 @@ function useEntityRecord(kind, name, recordId, options = {
115
115
  saveEditedEntityRecord
116
116
  } = (0, _data.useDispatch)(_.store);
117
117
  const mutations = (0, _element.useMemo)(() => ({
118
- edit: record => editEntityRecord(kind, name, recordId, record),
118
+ edit: (record, editOptions = {}) => editEntityRecord(kind, name, recordId, record, editOptions),
119
119
  save: (saveOptions = {}) => saveEditedEntityRecord(kind, name, recordId, {
120
120
  throwOnError: true,
121
121
  ...saveOptions
@@ -123,10 +123,12 @@ function useEntityRecord(kind, name, recordId, options = {
123
123
  }), [editEntityRecord, kind, name, recordId, saveEditedEntityRecord]);
124
124
  const {
125
125
  editedRecord,
126
- hasEdits
126
+ hasEdits,
127
+ edits
127
128
  } = (0, _data.useSelect)(select => ({
128
129
  editedRecord: select(_.store).getEditedEntityRecord(kind, name, recordId),
129
- hasEdits: select(_.store).hasEditsForEntityRecord(kind, name, recordId)
130
+ hasEdits: select(_.store).hasEditsForEntityRecord(kind, name, recordId),
131
+ edits: select(_.store).getEntityRecordNonTransientEdits(kind, name, recordId)
130
132
  }), [kind, name, recordId]);
131
133
  const {
132
134
  data: record,
@@ -143,6 +145,7 @@ function useEntityRecord(kind, name, recordId, options = {
143
145
  record,
144
146
  editedRecord,
145
147
  hasEdits,
148
+ edits,
146
149
  ...querySelectRest,
147
150
  ...mutations
148
151
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_data","require","_deprecated","_interopRequireDefault","_element","_useQuerySelect","_","useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","useDispatch","coreStore","mutations","useMemo","edit","record","save","saveOptions","throwOnError","editedRecord","hasEdits","useSelect","select","getEditedEntityRecord","hasEditsForEntityRecord","data","querySelectRest","useQuerySelect","query","getEntityRecord","__experimentalUseEntityRecord","deprecated","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo } from '@wordpress/element';\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/** The edited entity record */\n\teditedRecord: Partial< RecordType >;\n\n\t/** Apply local (in-browser) edits to the edited entity record */\n\tedit: ( diff: Partial< RecordType > ) => void;\n\n\t/** Persist the edits to the server */\n\tsave: () => Promise< void >;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Does the record have any local edits?\n\t */\n\thasEdits: 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 * @since 6.1.0 Introduced in WordPress core.\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 * @example\n * ```js\n * import { useDispatch } from '@wordpress/data';\n * import { useCallback } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n * import { TextControl } from '@wordpress/components';\n * import { store as noticeStore } from '@wordpress/notices';\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageRenameForm( { id } ) {\n * \tconst page = useEntityRecord( 'postType', 'page', id );\n * \tconst { createSuccessNotice, createErrorNotice } =\n * \t\tuseDispatch( noticeStore );\n *\n * \tconst setTitle = useCallback( ( title ) => {\n * \t\tpage.edit( { title } );\n * \t}, [ page.edit ] );\n *\n * \tif ( page.isResolving ) {\n * \t\treturn 'Loading...';\n * \t}\n *\n * \tasync function onRename( event ) {\n * \t\tevent.preventDefault();\n * \t\ttry {\n * \t\t\tawait page.save();\n * \t\t\tcreateSuccessNotice( __( 'Page renamed.' ), {\n * \t\t\t\ttype: 'snackbar',\n * \t\t\t} );\n * \t\t} catch ( error ) {\n * \t\t\tcreateErrorNotice( error.message, { type: 'snackbar' } );\n * \t\t}\n * \t}\n *\n * \treturn (\n * \t\t<form onSubmit={ onRename }>\n * \t\t\t<TextControl\n * \t\t\t\tlabel={ __( 'Name' ) }\n * \t\t\t\tvalue={ page.editedRecord.title }\n * \t\t\t\tonChange={ setTitle }\n * \t\t\t/>\n * \t\t\t<button type=\"submit\">{ __( 'Save' ) }</button>\n * \t\t</form>\n * \t);\n * }\n *\n * // Rendered in the application:\n * // <PageRenameForm id={ 1 } />\n * ```\n *\n * In the above example, updating and saving the page title is handled\n * via the `edit()` and `save()` mutation helpers provided by\n * `useEntityRecord()`;\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 { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\n\tconst mutations = useMemo(\n\t\t() => ( {\n\t\t\tedit: ( record ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record ),\n\t\t\tsave: ( saveOptions: any = {} ) =>\n\t\t\t\tsaveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t...saveOptions,\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ editEntityRecord, kind, name, recordId, saveEditedEntityRecord ]\n\t);\n\n\tconst { editedRecord, hasEdits } = useSelect(\n\t\t( select ) => ( {\n\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t} ),\n\t\t[ kind, name, recordId ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\tdata: null,\n\t\t\t\t};\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\teditedRecord,\n\t\thasEdits,\n\t\t...querySelectRest,\n\t\t...mutations,\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"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAKA,IAAAI,eAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,CAAA,GAAAL,OAAA;AAXA;AACA;AACA;;AAKA;AACA;AACA;;AA8CA;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;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASM,eAAeA,CACtCC,IAAY,EACZC,IAAY,EACZC,QAAyB,EACzBC,OAAgB,GAAG;EAAEC,OAAO,EAAE;AAAK,CAAC,EACG;EACvC,MAAM;IAAEC,gBAAgB;IAAEC;EAAuB,CAAC,GACjD,IAAAC,iBAAW,EAAEC,OAAU,CAAC;EAEzB,MAAMC,SAAS,GAAG,IAAAC,gBAAO,EACxB,OAAQ;IACPC,IAAI,EAAIC,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,IAAY,EACZC,IAAY,EACZC,QAAa,EACbC,OAAY,EACX;EACD,IAAAyB,mBAAU,EAAG,uCAAsC,EAAE;IACpDC,WAAW,EAAE,yBAAyB;IACtCC,KAAK,EAAE;EACR,CAAE,CAAC;EACH,OAAO/B,eAAe,CAAEC,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAQ,CAAC;AACxD"}
1
+ {"version":3,"names":["_data","require","_deprecated","_interopRequireDefault","_element","_useQuerySelect","_","useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","useDispatch","coreStore","mutations","useMemo","edit","record","editOptions","save","saveOptions","throwOnError","editedRecord","hasEdits","edits","useSelect","select","getEditedEntityRecord","hasEditsForEntityRecord","getEntityRecordNonTransientEdits","data","querySelectRest","useQuerySelect","query","getEntityRecord","__experimentalUseEntityRecord","deprecated","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo } from '@wordpress/element';\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/** The edited entity record */\n\teditedRecord: Partial< RecordType >;\n\n\t/** The edits to the edited entity record */\n\tedits: Partial< RecordType >;\n\n\t/** Apply local (in-browser) edits to the edited entity record */\n\tedit: ( diff: Partial< RecordType > ) => void;\n\n\t/** Persist the edits to the server */\n\tsave: () => Promise< void >;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Does the record have any local edits?\n\t */\n\thasEdits: 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 * @since 6.1.0 Introduced in WordPress core.\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 * @example\n * ```js\n * import { useDispatch } from '@wordpress/data';\n * import { useCallback } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n * import { TextControl } from '@wordpress/components';\n * import { store as noticeStore } from '@wordpress/notices';\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageRenameForm( { id } ) {\n * \tconst page = useEntityRecord( 'postType', 'page', id );\n * \tconst { createSuccessNotice, createErrorNotice } =\n * \t\tuseDispatch( noticeStore );\n *\n * \tconst setTitle = useCallback( ( title ) => {\n * \t\tpage.edit( { title } );\n * \t}, [ page.edit ] );\n *\n * \tif ( page.isResolving ) {\n * \t\treturn 'Loading...';\n * \t}\n *\n * \tasync function onRename( event ) {\n * \t\tevent.preventDefault();\n * \t\ttry {\n * \t\t\tawait page.save();\n * \t\t\tcreateSuccessNotice( __( 'Page renamed.' ), {\n * \t\t\t\ttype: 'snackbar',\n * \t\t\t} );\n * \t\t} catch ( error ) {\n * \t\t\tcreateErrorNotice( error.message, { type: 'snackbar' } );\n * \t\t}\n * \t}\n *\n * \treturn (\n * \t\t<form onSubmit={ onRename }>\n * \t\t\t<TextControl\n * \t\t\t\tlabel={ __( 'Name' ) }\n * \t\t\t\tvalue={ page.editedRecord.title }\n * \t\t\t\tonChange={ setTitle }\n * \t\t\t/>\n * \t\t\t<button type=\"submit\">{ __( 'Save' ) }</button>\n * \t\t</form>\n * \t);\n * }\n *\n * // Rendered in the application:\n * // <PageRenameForm id={ 1 } />\n * ```\n *\n * In the above example, updating and saving the page title is handled\n * via the `edit()` and `save()` mutation helpers provided by\n * `useEntityRecord()`;\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 { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\n\tconst mutations = useMemo(\n\t\t() => ( {\n\t\t\tedit: ( record, editOptions: any = {} ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record, editOptions ),\n\t\t\tsave: ( saveOptions: any = {} ) =>\n\t\t\t\tsaveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t...saveOptions,\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ editEntityRecord, kind, name, recordId, saveEditedEntityRecord ]\n\t);\n\n\tconst { editedRecord, hasEdits, edits } = useSelect(\n\t\t( select ) => ( {\n\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t\tedits: select( coreStore ).getEntityRecordNonTransientEdits(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t} ),\n\t\t[ kind, name, recordId ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\tdata: null,\n\t\t\t\t};\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\teditedRecord,\n\t\thasEdits,\n\t\tedits,\n\t\t...querySelectRest,\n\t\t...mutations,\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"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAKA,IAAAI,eAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,CAAA,GAAAL,OAAA;AAXA;AACA;AACA;;AAKA;AACA;AACA;;AAiDA;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;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASM,eAAeA,CACtCC,IAAY,EACZC,IAAY,EACZ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AAK,CAAEzB,OAAO,CAACC,OAAO,EAAG;MACxB,OAAO;QACNqB,IAAI,EAAE;MACP,CAAC;IACF;IACA,OAAOG,KAAK,CAAEpB,OAAU,CAAC,CAACqB,eAAe,CAAE7B,IAAI,EAAEC,IAAI,EAAEC,QAAS,CAAC;EAClE,CAAC,EACD,CAAEF,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,CAACC,OAAO,CACxC,CAAC;EAED,OAAO;IACNQ,MAAM;IACNK,YAAY;IACZC,QAAQ;IACRC,KAAK;IACL,GAAGO,eAAe;IAClB,GAAGjB;EACJ,CAAC;AACF;AAEO,SAASqB,6BAA6BA,CAC5C9B,IAAY,EACZC,IAAY,EACZC,QAAa,EACbC,OAAY,EACX;EACD,IAAA4B,mBAAU,EAAG,uCAAsC,EAAE;IACpDC,WAAW,EAAE,yBAAyB;IACtCC,KAAK,EAAE;EACR,CAAE,CAAC;EACH,OAAOlC,eAAe,CAAEC,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAQ,CAAC;AACxD"}
@@ -1 +1 @@
1
- {"version":3,"names":["_deprecated","_interopRequireDefault","require","_","_constants","_useQuerySelect","useResourcePermissions","resource","id","useQuerySelect","resolve","canUser","coreStore","create","read","isResolving","hasResolved","status","Status","Idle","Resolving","Success","canCreate","data","canRead","update","_delete","canUpdate","canDelete","__experimentalUseResourcePermissions","deprecated","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\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 * @since 6.1.0 Introduced in WordPress core.\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 * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function Page({ pageId }) {\n * const {\n * canCreate,\n * canUpdate,\n * canDelete,\n * isResolving\n * } = useResourcePermissions( 'pages', pageId );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * {canUpdate ? (<button>Edit page</button>) : false}\n * {canDelete ? (<button>Delete page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <Page pageId={ 15 } />\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 useResourcePermissions< 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\tconst read = canUser( 'read', resource );\n\n\t\t\t\tconst isResolving = create.isResolving || read.isResolving;\n\t\t\t\tconst hasResolved = create.hasResolved && read.hasResolved;\n\t\t\t\tlet status = Status.Idle;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\tcanRead: read.hasResolved && read.data,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst read = canUser( 'read', resource, id );\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\tread.isResolving ||\n\t\t\t\tcreate.isResolving ||\n\t\t\t\tupdate.isResolving ||\n\t\t\t\t_delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tread.hasResolved &&\n\t\t\t\tcreate.hasResolved &&\n\t\t\t\tupdate.hasResolved &&\n\t\t\t\t_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\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\n\t\t\t\tcanRead: hasResolved && read.data,\n\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t};\n\t\t},\n\t\t[ resource, id ]\n\t);\n}\n\nexport function __experimentalUseResourcePermissions(\n\tresource: string,\n\tid?: unknown\n) {\n\tdeprecated( `wp.data.__experimentalUseResourcePermissions`, {\n\t\talternative: 'wp.data.useResourcePermissions',\n\t\tsince: '6.1',\n\t} );\n\treturn useResourcePermissions( resource, id );\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,CAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAVA;AACA;AACA;;AAGA;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;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,SAASI,sBAAsBA,CAC7CC,QAAgB,EAChBC,EAAW,EAC+B;EAC1C,OAAO,IAAAC,uBAAc,EAClBC,OAAO,IAAM;IACd,MAAM;MAAEC;IAAQ,CAAC,GAAGD,OAAO,CAAEE,OAAU,CAAC;IACxC,MAAMC,MAAM,GAAGF,OAAO,CAAE,QAAQ,EAAEJ,QAAS,CAAC;IAC5C,IAAK,CAAEC,EAAE,EAAG;MACX,MAAMM,IAAI,GAAGH,OAAO,CAAE,MAAM,EAAEJ,QAAS,CAAC;MAExC,MAAMQ,WAAW,GAAGF,MAAM,CAACE,WAAW,IAAID,IAAI,CAACC,WAAW;MAC1D,MAAMC,WAAW,GAAGH,MAAM,CAACG,WAAW,IAAIF,IAAI,CAACE,WAAW;MAC1D,IAAIC,MAAM,GAAGC,iBAAM,CAACC,IAAI;MACxB,IAAKJ,WAAW,EAAG;QAClBE,MA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H;IACnC,CAAC;EACF,CAAC,EACD,CAAEhB,QAAQ,EAAEC,EAAE,CACf,CAAC;AACF;AAEO,SAASqB,oCAAoCA,CACnDtB,QAAgB,EAChBC,EAAY,EACX;EACD,IAAAsB,mBAAU,EAAG,8CAA6C,EAAE;IAC3DC,WAAW,EAAE,gCAAgC;IAC7CC,KAAK,EAAE;EACR,CAAE,CAAC;EACH,OAAO1B,sBAAsB,CAAEC,QAAQ,EAAEC,EAAG,CAAC;AAC9C"}
1
+ {"version":3,"names":["_deprecated","_interopRequireDefault","require","_","_constants","_useQuerySelect","useResourcePermissions","resource","id","useQuerySelect","resolve","canUser","coreStore","create","read","isResolving","hasResolved","status","Status","Idle","Resolving","Success","canCreate","data","canRead","update","_delete","canUpdate","canDelete","__experimentalUseResourcePermissions","deprecated","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\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 * @since 6.1.0 Introduced in WordPress core.\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 * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function Page({ pageId }) {\n * const {\n * canCreate,\n * canUpdate,\n * canDelete,\n * isResolving\n * } = useResourcePermissions( 'pages', pageId );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * {canUpdate ? (<button>Edit page</button>) : false}\n * {canDelete ? (<button>Delete page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <Page pageId={ 15 } />\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 useResourcePermissions< 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\tconst read = canUser( 'read', resource );\n\n\t\t\t\tconst isResolving = create.isResolving || read.isResolving;\n\t\t\t\tconst hasResolved = create.hasResolved && read.hasResolved;\n\t\t\t\tlet status = Status.Idle;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\tcanRead: read.hasResolved && read.data,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst read = canUser( 'read', resource, id );\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\tread.isResolving ||\n\t\t\t\tcreate.isResolving ||\n\t\t\t\tupdate.isResolving ||\n\t\t\t\t_delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tread.hasResolved &&\n\t\t\t\tcreate.hasResolved &&\n\t\t\t\tupdate.hasResolved &&\n\t\t\t\t_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\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\n\t\t\t\tcanRead: hasResolved && read.data,\n\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t};\n\t\t},\n\t\t[ resource, id ]\n\t);\n}\n\nexport function __experimentalUseResourcePermissions(\n\tresource: string,\n\tid?: unknown\n) {\n\tdeprecated( `wp.data.__experimentalUseResourcePermissions`, {\n\t\talternative: 'wp.data.useResourcePermissions',\n\t\tsince: '6.1',\n\t} );\n\treturn useResourcePermissions( resource, id );\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,CAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAVA;AACA;AACA;;AAGA;AACA;AACA;;AAoCA;AACA;AACA;AACA;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  exports.getNavigationFallbackId = getNavigationFallbackId;
7
- exports.getRedoEdits = getRedoEdits;
8
- exports.getUndoEdits = getUndoEdits;
7
+ exports.getUndoManager = getUndoManager;
9
8
  /**
10
9
  * Internal dependencies
11
10
  */
@@ -16,22 +15,10 @@ exports.getUndoEdits = getUndoEdits;
16
15
  *
17
16
  * @param state State tree.
18
17
  *
19
- * @return The edit.
18
+ * @return The undo manager.
20
19
  */
21
- function getUndoEdits(state) {
22
- return state.undo.list[state.undo.list.length - 1 + state.undo.offset];
23
- }
24
-
25
- /**
26
- * Returns the next edit from the current undo offset
27
- * for the entity records edits history, if any.
28
- *
29
- * @param state State tree.
30
- *
31
- * @return The edit.
32
- */
33
- function getRedoEdits(state) {
34
- return state.undo.list[state.undo.list.length + state.undo.offset];
20
+ function getUndoManager(state) {
21
+ return state.undoManager;
35
22
  }
36
23
 
37
24
  /**
@@ -1 +1 @@
1
- {"version":3,"names":["getUndoEdits","state","undo","list","length","offset","getRedoEdits","getNavigationFallbackId","navigationFallbackId"],"sources":["@wordpress/core-data/src/private-selectors.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { State, UndoEdit } from './selectors';\n\ntype Optional< T > = T | undefined;\ntype EntityRecordKey = string | number;\n\n/**\n * Returns the previous edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * @param state State tree.\n *\n * @return The edit.\n */\nexport function getUndoEdits( state: State ): Optional< UndoEdit[] > {\n\treturn state.undo.list[ state.undo.list.length - 1 + state.undo.offset ];\n}\n\n/**\n * Returns the next edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * @param state State tree.\n *\n * @return The edit.\n */\nexport function getRedoEdits( state: State ): Optional< UndoEdit[] > {\n\treturn state.undo.list[ state.undo.list.length + state.undo.offset ];\n}\n\n/**\n * Retrieve the fallback Navigation.\n *\n * @param state Data state.\n * @return The ID for the fallback Navigation post.\n */\nexport function getNavigationFallbackId(\n\tstate: State\n): EntityRecordKey | undefined {\n\treturn state.navigationFallbackId;\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,YAAYA,CAAEC,KAAY,EAA2B;EACpE,OAAOA,KAAK,CAACC,IAAI,CAACC,IAAI,CAAEF,KAAK,CAACC,IAAI,CAACC,IAAI,CAACC,MAAM,GAAG,CAAC,GAAGH,KAAK,CAACC,IAAI,CAACG,MAAM,CAAE;AACzE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,YAAYA,CAAEL,KAAY,EAA2B;EACpE,OAAOA,KAAK,CAACC,IAAI,CAACC,IAAI,CAAEF,KAAK,CAACC,IAAI,CAACC,IAAI,CAACC,MAAM,GAAGH,KAAK,CAACC,IAAI,CAACG,MAAM,CAAE;AACrE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,uBAAuBA,CACtCN,KAAY,EACkB;EAC9B,OAAOA,KAAK,CAACO,oBAAoB;AAClC"}
1
+ {"version":3,"names":["getUndoManager","state","undoManager","getNavigationFallbackId","navigationFallbackId"],"sources":["@wordpress/core-data/src/private-selectors.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { State } from './selectors';\n\ntype EntityRecordKey = string | number;\n\n/**\n * Returns the previous edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * @param state State tree.\n *\n * @return The undo manager.\n */\nexport function getUndoManager( state: State ) {\n\treturn state.undoManager;\n}\n\n/**\n * Retrieve the fallback Navigation.\n *\n * @param state Data state.\n * @return The ID for the fallback Navigation post.\n */\nexport function getNavigationFallbackId(\n\tstate: State\n): EntityRecordKey | undefined {\n\treturn state.navigationFallbackId;\n}\n"],"mappings":";;;;;;;AAAA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,cAAcA,CAAEC,KAAY,EAAG;EAC9C,OAAOA,KAAK,CAACC,WAAW;AACzB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,uBAAuBA,CACtCF,KAAY,EACkB;EAC9B,OAAOA,KAAK,CAACG,oBAAoB;AAClC"}
package/build/reducer.js CHANGED
@@ -11,6 +11,7 @@ exports.currentGlobalStylesId = currentGlobalStylesId;
11
11
  exports.currentTheme = currentTheme;
12
12
  exports.currentUser = currentUser;
13
13
  exports.default = void 0;
14
+ exports.editsReference = editsReference;
14
15
  exports.embedPreviews = embedPreviews;
15
16
  exports.entities = void 0;
16
17
  exports.entitiesConfig = entitiesConfig;
@@ -20,13 +21,14 @@ exports.terms = terms;
20
21
  exports.themeBaseGlobalStyles = themeBaseGlobalStyles;
21
22
  exports.themeGlobalStyleRevisions = themeGlobalStyleRevisions;
22
23
  exports.themeGlobalStyleVariations = themeGlobalStyleVariations;
23
- exports.undo = undo;
24
+ exports.undoManager = undoManager;
25
+ exports.userPatternCategories = userPatternCategories;
24
26
  exports.userPermissions = userPermissions;
25
27
  exports.users = users;
26
28
  var _es = _interopRequireDefault(require("fast-deep-equal/es6"));
27
29
  var _compose = require("@wordpress/compose");
28
30
  var _data = require("@wordpress/data");
29
- var _isShallowEqual = _interopRequireDefault(require("@wordpress/is-shallow-equal"));
31
+ var _undoManager = require("@wordpress/undo-manager");
30
32
  var _utils = require("./utils");
31
33
  var _queriedData = require("./queried-data");
32
34
  var _entities = require("./entities");
@@ -202,25 +204,26 @@ function themeGlobalStyleVariations(state = {}, action) {
202
204
  const withMultiEntityRecordEdits = reducer => (state, action) => {
203
205
  if (action.type === 'UNDO' || action.type === 'REDO') {
204
206
  const {
205
- stackedEdits
207
+ record
206
208
  } = action;
207
209
  let newState = state;
208
- stackedEdits.forEach(({
209
- kind,
210
- name,
211
- recordId,
212
- property,
213
- from,
214
- to
210
+ record.forEach(({
211
+ id: {
212
+ kind,
213
+ name,
214
+ recordId
215
+ },
216
+ changes
215
217
  }) => {
216
218
  newState = reducer(newState, {
217
219
  type: 'EDIT_ENTITY_RECORD',
218
220
  kind,
219
221
  name,
220
222
  recordId,
221
- edits: {
222
- [property]: action.type === 'UNDO' ? from : to
223
- }
223
+ edits: Object.entries(changes).reduce((acc, [key, value]) => {
224
+ acc[key] = action.type === 'UNDO' ? value.from : value.to;
225
+ return acc;
226
+ }, {})
224
227
  });
225
228
  });
226
229
  return newState;
@@ -404,142 +407,18 @@ const entities = (state = {}, action) => {
404
407
  };
405
408
 
406
409
  /**
407
- * @typedef {Object} UndoStateMeta
408
- *
409
- * @property {number} list The undo stack.
410
- * @property {number} offset Where in the undo stack we are.
411
- * @property {Object} cache Cache of unpersisted edits.
412
- */
413
-
414
- /** @typedef {Array<Object> & UndoStateMeta} UndoState */
415
-
416
- /**
417
- * @type {UndoState}
418
- *
419
- * @todo Given how we use this we might want to make a custom class for it.
410
+ * @type {UndoManager}
420
411
  */
421
412
  exports.entities = entities;
422
- const UNDO_INITIAL_STATE = {
423
- list: [],
424
- offset: 0
425
- };
426
-
427
- /**
428
- * Reducer keeping track of entity edit undo history.
429
- *
430
- * @param {UndoState} state Current state.
431
- * @param {Object} action Dispatched action.
432
- *
433
- * @return {UndoState} Updated state.
434
- */
435
- function undo(state = UNDO_INITIAL_STATE, action) {
436
- const omitPendingRedos = currentState => {
437
- return {
438
- ...currentState,
439
- list: currentState.list.slice(0, currentState.offset || undefined),
440
- offset: 0
441
- };
442
- };
443
- const appendCachedEditsToLastUndo = currentState => {
444
- if (!currentState.cache) {
445
- return currentState;
446
- }
447
- let nextState = {
448
- ...currentState,
449
- list: [...currentState.list]
450
- };
451
- nextState = omitPendingRedos(nextState);
452
- const previousUndoState = nextState.list.pop();
453
- const updatedUndoState = currentState.cache.reduce(appendEditToStack, previousUndoState);
454
- nextState.list.push(updatedUndoState);
455
- return {
456
- ...nextState,
457
- cache: undefined
458
- };
459
- };
460
- const appendEditToStack = (stack = [], {
461
- kind,
462
- name,
463
- recordId,
464
- property,
465
- from,
466
- to
467
- }) => {
468
- const existingEditIndex = stack?.findIndex(({
469
- kind: k,
470
- name: n,
471
- recordId: r,
472
- property: p
473
- }) => {
474
- return k === kind && n === name && r === recordId && p === property;
475
- });
476
- const nextStack = [...stack];
477
- if (existingEditIndex !== -1) {
478
- // If the edit is already in the stack leave the initial "from" value.
479
- nextStack[existingEditIndex] = {
480
- ...nextStack[existingEditIndex],
481
- to
482
- };
483
- } else {
484
- nextStack.push({
485
- kind,
486
- name,
487
- recordId,
488
- property,
489
- from,
490
- to
491
- });
492
- }
493
- return nextStack;
494
- };
413
+ function undoManager(state = (0, _undoManager.createUndoManager)()) {
414
+ return state;
415
+ }
416
+ function editsReference(state = {}, action) {
495
417
  switch (action.type) {
496
- case 'CREATE_UNDO_LEVEL':
497
- return appendCachedEditsToLastUndo(state);
418
+ case 'EDIT_ENTITY_RECORD':
498
419
  case 'UNDO':
499
420
  case 'REDO':
500
- {
501
- const nextState = appendCachedEditsToLastUndo(state);
502
- return {
503
- ...nextState,
504
- offset: state.offset + (action.type === 'UNDO' ? -1 : 1)
505
- };
506
- }
507
- case 'EDIT_ENTITY_RECORD':
508
- {
509
- if (!action.meta.undo) {
510
- return state;
511
- }
512
- const edits = Object.keys(action.edits).map(key => {
513
- return {
514
- kind: action.kind,
515
- name: action.name,
516
- recordId: action.recordId,
517
- property: key,
518
- from: action.meta.undo.edits[key],
519
- to: action.edits[key]
520
- };
521
- });
522
- if (action.meta.undo.isCached) {
523
- return {
524
- ...state,
525
- cache: edits.reduce(appendEditToStack, state.cache)
526
- };
527
- }
528
- let nextState = omitPendingRedos(state);
529
- nextState = appendCachedEditsToLastUndo(nextState);
530
- nextState = {
531
- ...nextState,
532
- list: [...nextState.list]
533
- };
534
- // When an edit is a function it's an optimization to avoid running some expensive operation.
535
- // We can't rely on the function references being the same so we opt out of comparing them here.
536
- const comparisonUndoEdits = Object.values(action.meta.undo.edits).filter(edit => typeof edit !== 'function');
537
- const comparisonEdits = Object.values(action.edits).filter(edit => typeof edit !== 'function');
538
- if (!(0, _isShallowEqual.default)(comparisonUndoEdits, comparisonEdits)) {
539
- nextState.list.push(edits);
540
- }
541
- return nextState;
542
- }
421
+ return {};
543
422
  }
544
423
  return state;
545
424
  }
@@ -623,6 +502,13 @@ function blockPatternCategories(state = [], action) {
623
502
  }
624
503
  return state;
625
504
  }
505
+ function userPatternCategories(state = [], action) {
506
+ switch (action.type) {
507
+ case 'RECEIVE_USER_PATTERN_CATEGORIES':
508
+ return action.patternCategories;
509
+ }
510
+ return state;
511
+ }
626
512
  function navigationFallbackId(state = null, action) {
627
513
  switch (action.type) {
628
514
  case 'RECEIVE_NAVIGATION_FALLBACK_ID':
@@ -660,12 +546,14 @@ var _default = (0, _data.combineReducers)({
660
546
  themeGlobalStyleRevisions,
661
547
  taxonomies,
662
548
  entities,
663
- undo,
549
+ editsReference,
550
+ undoManager,
664
551
  embedPreviews,
665
552
  userPermissions,
666
553
  autosaves,
667
554
  blockPatterns,
668
555
  blockPatternCategories,
556
+ userPatternCategories,
669
557
  navigationFallbackId
670
558
  });
671
559
  exports.default = _default;