@wordpress/core-data 6.18.1-next.5a1d1283.0 → 6.19.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.
Files changed (113) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +13 -1
  3. package/build/actions.js +38 -32
  4. package/build/actions.js.map +1 -1
  5. package/build/entities.js +10 -2
  6. package/build/entities.js.map +1 -1
  7. package/build/entity-provider.js +2 -99
  8. package/build/entity-provider.js.map +1 -1
  9. package/build/entity-types/helpers.js.map +1 -1
  10. package/build/footnotes/get-footnotes-order.js +35 -0
  11. package/build/footnotes/get-footnotes-order.js.map +1 -0
  12. package/build/footnotes/get-rich-text-values-cached.js +39 -0
  13. package/build/footnotes/get-rich-text-values-cached.js.map +1 -0
  14. package/build/footnotes/index.js +96 -0
  15. package/build/footnotes/index.js.map +1 -0
  16. package/build/hooks/use-entity-record.js +6 -3
  17. package/build/hooks/use-entity-record.js.map +1 -1
  18. package/build/hooks/use-resource-permissions.js.map +1 -1
  19. package/build/private-selectors.js +4 -17
  20. package/build/private-selectors.js.map +1 -1
  21. package/build/reducer.js +33 -145
  22. package/build/reducer.js.map +1 -1
  23. package/build/resolvers.js +39 -18
  24. package/build/resolvers.js.map +1 -1
  25. package/build/selectors.js +21 -25
  26. package/build/selectors.js.map +1 -1
  27. package/build/utils/get-nested-value.js +30 -0
  28. package/build/utils/get-nested-value.js.map +1 -0
  29. package/build/utils/index.js +7 -0
  30. package/build/utils/index.js.map +1 -1
  31. package/build/utils/set-nested-value.js +11 -6
  32. package/build/utils/set-nested-value.js.map +1 -1
  33. package/build-module/actions.js +36 -30
  34. package/build-module/actions.js.map +1 -1
  35. package/build-module/entities.js +10 -2
  36. package/build-module/entities.js.map +1 -1
  37. package/build-module/entity-provider.js +2 -99
  38. package/build-module/entity-provider.js.map +1 -1
  39. package/build-module/entity-types/helpers.js.map +1 -1
  40. package/build-module/footnotes/get-footnotes-order.js +27 -0
  41. package/build-module/footnotes/get-footnotes-order.js.map +1 -0
  42. package/build-module/footnotes/get-rich-text-values-cached.js +33 -0
  43. package/build-module/footnotes/get-rich-text-values-cached.js.map +1 -0
  44. package/build-module/footnotes/index.js +88 -0
  45. package/build-module/footnotes/index.js.map +1 -0
  46. package/build-module/hooks/use-entity-record.js +6 -3
  47. package/build-module/hooks/use-entity-record.js.map +1 -1
  48. package/build-module/hooks/use-resource-permissions.js.map +1 -1
  49. package/build-module/private-selectors.js +3 -15
  50. package/build-module/private-selectors.js.map +1 -1
  51. package/build-module/reducer.js +30 -144
  52. package/build-module/reducer.js.map +1 -1
  53. package/build-module/resolvers.js +37 -17
  54. package/build-module/resolvers.js.map +1 -1
  55. package/build-module/selectors.js +19 -29
  56. package/build-module/selectors.js.map +1 -1
  57. package/build-module/utils/get-nested-value.js +24 -0
  58. package/build-module/utils/get-nested-value.js.map +1 -0
  59. package/build-module/utils/index.js +1 -0
  60. package/build-module/utils/index.js.map +1 -1
  61. package/build-module/utils/set-nested-value.js +11 -6
  62. package/build-module/utils/set-nested-value.js.map +1 -1
  63. package/build-types/actions.d.ts +1 -6
  64. package/build-types/actions.d.ts.map +1 -1
  65. package/build-types/entities.d.ts.map +1 -1
  66. package/build-types/entity-provider.d.ts.map +1 -1
  67. package/build-types/footnotes/get-footnotes-order.d.ts +2 -0
  68. package/build-types/footnotes/get-footnotes-order.d.ts.map +1 -0
  69. package/build-types/footnotes/get-rich-text-values-cached.d.ts +2 -0
  70. package/build-types/footnotes/get-rich-text-values-cached.d.ts.map +1 -0
  71. package/build-types/footnotes/index.d.ts +4 -0
  72. package/build-types/footnotes/index.d.ts.map +1 -0
  73. package/build-types/hooks/use-entity-record.d.ts +2 -0
  74. package/build-types/hooks/use-entity-record.d.ts.map +1 -1
  75. package/build-types/index.d.ts +3 -2
  76. package/build-types/index.d.ts.map +1 -1
  77. package/build-types/private-selectors.d.ts +3 -13
  78. package/build-types/private-selectors.d.ts.map +1 -1
  79. package/build-types/reducer.d.ts +7 -23
  80. package/build-types/reducer.d.ts.map +1 -1
  81. package/build-types/resolvers.d.ts +4 -0
  82. package/build-types/resolvers.d.ts.map +1 -1
  83. package/build-types/selectors.d.ts +19 -14
  84. package/build-types/selectors.d.ts.map +1 -1
  85. package/build-types/utils/get-nested-value.d.ts +14 -0
  86. package/build-types/utils/get-nested-value.d.ts.map +1 -0
  87. package/build-types/utils/index.d.ts +1 -0
  88. package/build-types/utils/set-nested-value.d.ts +8 -4
  89. package/build-types/utils/set-nested-value.d.ts.map +1 -1
  90. package/package.json +17 -16
  91. package/src/actions.js +44 -32
  92. package/src/entities.js +12 -2
  93. package/src/entity-provider.js +2 -134
  94. package/src/entity-types/helpers.ts +2 -2
  95. package/src/footnotes/get-footnotes-order.js +30 -0
  96. package/src/footnotes/get-rich-text-values-cached.js +35 -0
  97. package/src/footnotes/index.js +119 -0
  98. package/src/hooks/test/use-entity-record.js +4 -0
  99. package/src/hooks/use-entity-record.ts +12 -3
  100. package/src/hooks/use-resource-permissions.ts +1 -1
  101. package/src/private-selectors.ts +4 -17
  102. package/src/reducer.js +36 -155
  103. package/src/resolvers.js +59 -32
  104. package/src/selectors.ts +39 -51
  105. package/src/test/reducer.js +0 -233
  106. package/src/test/selectors.js +0 -54
  107. package/src/utils/get-nested-value.js +27 -0
  108. package/src/utils/index.js +1 -0
  109. package/src/utils/set-nested-value.js +12 -6
  110. package/src/utils/test/get-nested-value.js +61 -0
  111. package/src/utils/test/set-nested-value.js +7 -0
  112. package/tsconfig.json +1 -0
  113. package/tsconfig.tsbuildinfo +1 -1
@@ -10,9 +10,8 @@ exports.useEntityProp = useEntityProp;
10
10
  var _element = require("@wordpress/element");
11
11
  var _data = require("@wordpress/data");
12
12
  var _blocks2 = require("@wordpress/blocks");
13
- var _blockEditor = require("@wordpress/block-editor");
14
13
  var _name = require("./name");
15
- var _privateApis = require("./private-apis");
14
+ var _footnotes = require("./footnotes");
16
15
  var _entities = require("./entities");
17
16
  /**
18
17
  * WordPress dependencies
@@ -25,7 +24,6 @@ var _entities = require("./entities");
25
24
  /** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */
26
25
 
27
26
  const EMPTY_ARRAY = [];
28
- let oldFootnotes = {};
29
27
 
30
28
  /**
31
29
  * Internal dependencies
@@ -188,102 +186,7 @@ function useEntityBlockEditor(kind, name, {
188
186
  }
189
187
  return content && typeof content !== 'function' ? (0, _blocks2.parse)(content) : EMPTY_ARRAY;
190
188
  }, [editedBlocks, content]);
191
- const updateFootnotes = (0, _element.useCallback)(_blocks => {
192
- const output = {
193
- blocks: _blocks
194
- };
195
- if (!meta) return output;
196
- // If meta.footnotes is empty, it means the meta is not registered.
197
- if (meta.footnotes === undefined) return output;
198
- const {
199
- getRichTextValues
200
- } = (0, _privateApis.unlock)(_blockEditor.privateApis);
201
- const _content = getRichTextValues(_blocks).join('') || '';
202
- const newOrder = [];
203
-
204
- // This can be avoided when
205
- // https://github.com/WordPress/gutenberg/pull/43204 lands. We can then
206
- // get the order directly from the rich text values.
207
- if (_content.indexOf('data-fn') !== -1) {
208
- const regex = /data-fn="([^"]+)"/g;
209
- let match;
210
- while ((match = regex.exec(_content)) !== null) {
211
- newOrder.push(match[1]);
212
- }
213
- }
214
- const footnotes = meta.footnotes ? JSON.parse(meta.footnotes) : [];
215
- const currentOrder = footnotes.map(fn => fn.id);
216
- if (currentOrder.join('') === newOrder.join('')) return output;
217
- const newFootnotes = newOrder.map(fnId => footnotes.find(fn => fn.id === fnId) || oldFootnotes[fnId] || {
218
- id: fnId,
219
- content: ''
220
- });
221
- function updateAttributes(attributes) {
222
- // Only attempt to update attributes, if attributes is an object.
223
- if (!attributes || Array.isArray(attributes) || typeof attributes !== 'object') {
224
- return attributes;
225
- }
226
- attributes = {
227
- ...attributes
228
- };
229
- for (const key in attributes) {
230
- const value = attributes[key];
231
- if (Array.isArray(value)) {
232
- attributes[key] = value.map(updateAttributes);
233
- continue;
234
- }
235
- if (typeof value !== 'string') {
236
- continue;
237
- }
238
- if (value.indexOf('data-fn') === -1) {
239
- continue;
240
- }
241
-
242
- // When we store rich text values, this would no longer
243
- // require a regex.
244
- const regex = /(<sup[^>]+data-fn="([^"]+)"[^>]*><a[^>]*>)[\d*]*<\/a><\/sup>/g;
245
- attributes[key] = value.replace(regex, (match, opening, fnId) => {
246
- const index = newOrder.indexOf(fnId);
247
- return `${opening}${index + 1}</a></sup>`;
248
- });
249
- const compatRegex = /<a[^>]+data-fn="([^"]+)"[^>]*>\*<\/a>/g;
250
- attributes[key] = attributes[key].replace(compatRegex, (match, fnId) => {
251
- const index = newOrder.indexOf(fnId);
252
- return `<sup data-fn="${fnId}" class="fn"><a href="#${fnId}" id="${fnId}-link">${index + 1}</a></sup>`;
253
- });
254
- }
255
- return attributes;
256
- }
257
- function updateBlocksAttributes(__blocks) {
258
- return __blocks.map(block => {
259
- return {
260
- ...block,
261
- attributes: updateAttributes(block.attributes),
262
- innerBlocks: updateBlocksAttributes(block.innerBlocks)
263
- };
264
- });
265
- }
266
-
267
- // We need to go through all block attributes deeply and update the
268
- // footnote anchor numbering (textContent) to match the new order.
269
- const newBlocks = updateBlocksAttributes(_blocks);
270
- oldFootnotes = {
271
- ...oldFootnotes,
272
- ...footnotes.reduce((acc, fn) => {
273
- if (!newOrder.includes(fn.id)) {
274
- acc[fn.id] = fn;
275
- }
276
- return acc;
277
- }, {})
278
- };
279
- return {
280
- meta: {
281
- ...meta,
282
- footnotes: JSON.stringify(newFootnotes)
283
- },
284
- blocks: newBlocks
285
- };
286
- }, [meta]);
189
+ const updateFootnotes = (0, _element.useCallback)(_blocks => (0, _footnotes.updateFootnotesFromMeta)(_blocks, meta), [meta]);
287
190
  const onChange = (0, _element.useCallback)((newBlocks, options) => {
288
191
  const noChange = blocks === newBlocks;
289
192
  if (noChange) {
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_data","_blocks2","_blockEditor","_name","_privateApis","_entities","EMPTY_ARRAY","oldFootnotes","entityContexts","rootEntitiesConfig","reduce","acc","loader","kind","name","context","createContext","undefined","additionalEntityConfigLoaders","getEntityContext","Error","EntityProvider","type","id","children","Provider","createElement","value","useEntityId","useContext","useEntityProp","prop","_id","providerId","fullValue","useSelect","select","getEntityRecord","getEditedEntityRecord","STORE_NAME","record","editedRecord","editEntityRecord","useDispatch","setValue","useCallback","newValue","useEntityBlockEditor","content","editedBlocks","meta","blocks","__unstableCreateUndoLevel","useMemo","parse","updateFootnotes","_blocks","output","footnotes","getRichTextValues","unlock","blockEditorPrivateApis","_content","join","newOrder","indexOf","regex","match","exec","push","JSON","currentOrder","map","fn","newFootnotes","fnId","find","updateAttributes","attributes","Array","isArray","key","replace","opening","index","compatRegex","updateBlocksAttributes","__blocks","block","innerBlocks","newBlocks","includes","stringify","onChange","options","noChange","selection","edits","blocksForSerialization","__unstableSerializeAndClean","isCached","onInput","footnotesChanges"],"sources":["@wordpress/core-data/src/entity-provider.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { unlock } from './private-apis';\n\n/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */\n\nconst EMPTY_ARRAY = [];\n\nlet oldFootnotes = {};\n\n/**\n * Internal dependencies\n */\nimport { rootEntitiesConfig, additionalEntityConfigLoaders } from './entities';\n\nconst entityContexts = {\n\t...rootEntitiesConfig.reduce( ( acc, loader ) => {\n\t\tif ( ! acc[ loader.kind ] ) {\n\t\t\tacc[ loader.kind ] = {};\n\t\t}\n\t\tacc[ loader.kind ][ loader.name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t\treturn acc;\n\t}, {} ),\n\t...additionalEntityConfigLoaders.reduce( ( acc, loader ) => {\n\t\tacc[ loader.kind ] = {};\n\t\treturn acc;\n\t}, {} ),\n};\nconst getEntityContext = ( kind, name ) => {\n\tif ( ! entityContexts[ kind ] ) {\n\t\tthrow new Error( `Missing entity config for kind: ${ kind }.` );\n\t}\n\n\tif ( ! entityContexts[ kind ][ name ] ) {\n\t\tentityContexts[ kind ][ name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t}\n\n\treturn entityContexts[ kind ][ name ].context;\n};\n\n/**\n * Context provider component for providing\n * an entity for a specific entity.\n *\n * @param {Object} props The component's props.\n * @param {string} props.kind The entity kind.\n * @param {string} props.type The entity name.\n * @param {number} props.id The entity ID.\n * @param {*} props.children The children to wrap.\n *\n * @return {Object} The provided children, wrapped with\n * the entity's context provider.\n */\nexport default function EntityProvider( { kind, type: name, id, children } ) {\n\tconst Provider = getEntityContext( kind, name ).Provider;\n\treturn <Provider value={ id }>{ children }</Provider>;\n}\n\n/**\n * Hook that returns the ID for the nearest\n * provided entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n */\nexport function useEntityId( kind, name ) {\n\treturn useContext( getEntityContext( kind, name ) );\n}\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {string} prop The property name.\n * @param {string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ editEntityRecord, kind, name, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * persistent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[WPBlock[], Function, Function]} The block array and setters.\n */\nexport function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { content, editedBlocks, meta } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord } = select( STORE_NAME );\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn {\n\t\t\t\teditedBlocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t\tmeta: editedRecord.meta,\n\t\t\t};\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } =\n\t\tuseDispatch( STORE_NAME );\n\n\tconst blocks = useMemo( () => {\n\t\tif ( editedBlocks ) {\n\t\t\treturn editedBlocks;\n\t\t}\n\n\t\treturn content && typeof content !== 'function'\n\t\t\t? parse( content )\n\t\t\t: EMPTY_ARRAY;\n\t}, [ editedBlocks, content ] );\n\n\tconst updateFootnotes = useCallback(\n\t\t( _blocks ) => {\n\t\t\tconst output = { blocks: _blocks };\n\t\t\tif ( ! meta ) return output;\n\t\t\t// If meta.footnotes is empty, it means the meta is not registered.\n\t\t\tif ( meta.footnotes === undefined ) return output;\n\n\t\t\tconst { getRichTextValues } = unlock( blockEditorPrivateApis );\n\t\t\tconst _content = getRichTextValues( _blocks ).join( '' ) || '';\n\t\t\tconst newOrder = [];\n\n\t\t\t// This can be avoided when\n\t\t\t// https://github.com/WordPress/gutenberg/pull/43204 lands. We can then\n\t\t\t// get the order directly from the rich text values.\n\t\t\tif ( _content.indexOf( 'data-fn' ) !== -1 ) {\n\t\t\t\tconst regex = /data-fn=\"([^\"]+)\"/g;\n\t\t\t\tlet match;\n\t\t\t\twhile ( ( match = regex.exec( _content ) ) !== null ) {\n\t\t\t\t\tnewOrder.push( match[ 1 ] );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst footnotes = meta.footnotes\n\t\t\t\t? JSON.parse( meta.footnotes )\n\t\t\t\t: [];\n\t\t\tconst currentOrder = footnotes.map( ( fn ) => fn.id );\n\n\t\t\tif ( currentOrder.join( '' ) === newOrder.join( '' ) )\n\t\t\t\treturn output;\n\n\t\t\tconst newFootnotes = newOrder.map(\n\t\t\t\t( fnId ) =>\n\t\t\t\t\tfootnotes.find( ( fn ) => fn.id === fnId ) ||\n\t\t\t\t\toldFootnotes[ fnId ] || {\n\t\t\t\t\t\tid: fnId,\n\t\t\t\t\t\tcontent: '',\n\t\t\t\t\t}\n\t\t\t);\n\n\t\t\tfunction updateAttributes( attributes ) {\n\t\t\t\t// Only attempt to update attributes, if attributes is an object.\n\t\t\t\tif (\n\t\t\t\t\t! attributes ||\n\t\t\t\t\tArray.isArray( attributes ) ||\n\t\t\t\t\ttypeof attributes !== 'object'\n\t\t\t\t) {\n\t\t\t\t\treturn attributes;\n\t\t\t\t}\n\n\t\t\t\tattributes = { ...attributes };\n\n\t\t\t\tfor ( const key in attributes ) {\n\t\t\t\t\tconst value = attributes[ key ];\n\n\t\t\t\t\tif ( Array.isArray( value ) ) {\n\t\t\t\t\t\tattributes[ key ] = value.map( updateAttributes );\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( typeof value !== 'string' ) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( value.indexOf( 'data-fn' ) === -1 ) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// When we store rich text values, this would no longer\n\t\t\t\t\t// require a regex.\n\t\t\t\t\tconst regex =\n\t\t\t\t\t\t/(<sup[^>]+data-fn=\"([^\"]+)\"[^>]*><a[^>]*>)[\\d*]*<\\/a><\\/sup>/g;\n\n\t\t\t\t\tattributes[ key ] = value.replace(\n\t\t\t\t\t\tregex,\n\t\t\t\t\t\t( match, opening, fnId ) => {\n\t\t\t\t\t\t\tconst index = newOrder.indexOf( fnId );\n\t\t\t\t\t\t\treturn `${ opening }${ index + 1 }</a></sup>`;\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\t\tconst compatRegex =\n\t\t\t\t\t\t/<a[^>]+data-fn=\"([^\"]+)\"[^>]*>\\*<\\/a>/g;\n\n\t\t\t\t\tattributes[ key ] = attributes[ key ].replace(\n\t\t\t\t\t\tcompatRegex,\n\t\t\t\t\t\t( match, fnId ) => {\n\t\t\t\t\t\t\tconst index = newOrder.indexOf( fnId );\n\t\t\t\t\t\t\treturn `<sup data-fn=\"${ fnId }\" class=\"fn\"><a href=\"#${ fnId }\" id=\"${ fnId }-link\">${\n\t\t\t\t\t\t\t\tindex + 1\n\t\t\t\t\t\t\t}</a></sup>`;\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn attributes;\n\t\t\t}\n\n\t\t\tfunction updateBlocksAttributes( __blocks ) {\n\t\t\t\treturn __blocks.map( ( block ) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...block,\n\t\t\t\t\t\tattributes: updateAttributes( block.attributes ),\n\t\t\t\t\t\tinnerBlocks: updateBlocksAttributes(\n\t\t\t\t\t\t\tblock.innerBlocks\n\t\t\t\t\t\t),\n\t\t\t\t\t};\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\t// We need to go through all block attributes deeply and update the\n\t\t\t// footnote anchor numbering (textContent) to match the new order.\n\t\t\tconst newBlocks = updateBlocksAttributes( _blocks );\n\n\t\t\toldFootnotes = {\n\t\t\t\t...oldFootnotes,\n\t\t\t\t...footnotes.reduce( ( acc, fn ) => {\n\t\t\t\t\tif ( ! newOrder.includes( fn.id ) ) {\n\t\t\t\t\t\tacc[ fn.id ] = fn;\n\t\t\t\t\t}\n\t\t\t\t\treturn acc;\n\t\t\t\t}, {} ),\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\tmeta: {\n\t\t\t\t\t...meta,\n\t\t\t\t\tfootnotes: JSON.stringify( newFootnotes ),\n\t\t\t\t},\n\t\t\t\tblocks: newBlocks,\n\t\t\t};\n\t\t},\n\t\t[ meta ]\n\t);\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst noChange = blocks === newBlocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, name, id );\n\t\t\t}\n\t\t\tconst { selection } = options;\n\n\t\t\t// We create a new function here on every persistent edit\n\t\t\t// to make sure the edit makes the post dirty and creates\n\t\t\t// a new undo level.\n\t\t\tconst edits = {\n\t\t\t\tselection,\n\t\t\t\tcontent: ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t\t__unstableSerializeAndClean( blocksForSerialization ),\n\t\t\t\t...updateFootnotes( newBlocks ),\n\t\t\t};\n\n\t\t\teditEntityRecord( kind, name, id, edits, { isCached: false } );\n\t\t},\n\t\t[\n\t\t\tkind,\n\t\t\tname,\n\t\t\tid,\n\t\t\tblocks,\n\t\t\tupdateFootnotes,\n\t\t\t__unstableCreateUndoLevel,\n\t\t\teditEntityRecord,\n\t\t]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst footnotesChanges = updateFootnotes( newBlocks );\n\t\t\tconst edits = { selection, ...footnotesChanges };\n\n\t\t\teditEntityRecord( kind, name, id, edits, { isCached: true } );\n\t\t},\n\t\t[ kind, name, id, updateFootnotes, editEntityRecord ]\n\t);\n\n\treturn [ blocks, onInput, onChange ];\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAMA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAKA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AAWA,IAAAM,SAAA,GAAAN,OAAA;AA5BA;AACA;AACA;;AAWA;AACA;AACA;;AAIA;;AAEA,MAAMO,WAAW,GAAG,EAAE;AAEtB,IAAIC,YAAY,GAAG,CAAC,CAAC;;AAErB;AACA;AACA;;AAGA,MAAMC,cAAc,GAAG;EACtB,GAAGC,4BAAkB,CAACC,MAAM,CAAE,CAAEC,GAAG,EAAEC,MAAM,KAAM;IAChD,IAAK,CAAED,GAAG,CAAEC,MAAM,CAACC,IAAI,CAAE,EAAG;MAC3BF,GAAG,CAAEC,MAAM,CAACC,IAAI,CAAE,GAAG,CAAC,CAAC;IACxB;IACAF,GAAG,CAAEC,MAAM,CAACC,IAAI,CAAE,CAAED,MAAM,CAACE,IAAI,CAAE,GAAG;MACnCC,OAAO,EAAE,IAAAC,sBAAa,EAAEC,SAAU;IACnC,CAAC;IACD,OAAON,GAAG;EACX,CAAC,EAAE,CAAC,CAAE,CAAC;EACP,GAAGO,uCAA6B,CAACR,MAA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MAAM,EAAE+C,sBAAsB,GAAG;MAAG,CAAC,KACjD,IAAAC,oCAA2B,EAAED,sBAAuB,CAAC;MACtD,GAAG3C,eAAe,CAAEmC,SAAU;IAC/B,CAAC;IAEDhD,gBAAgB,CAAE7B,IAAI,EAAEC,IAAI,EAAES,EAAE,EAAE0E,KAAK,EAAE;MAAEG,QAAQ,EAAE;IAAM,CAAE,CAAC;EAC/D,CAAC,EACD,CACCvF,IAAI,EACJC,IAAI,EACJS,EAAE,EACF4B,MAAM,EACNI,eAAe,EACfH,yBAAyB,EACzBV,gBAAgB,CAElB,CAAC;EAED,MAAM2D,OAAO,GAAG,IAAAxD,oBAAW,EAC1B,CAAE6C,SAAS,EAAEI,OAAO,KAAM;IACzB,MAAM;MAAEE;IAAU,CAAC,GAAGF,OAAO;IAC7B,MAAMQ,gBAAgB,GAAG/C,eAAe,CAAEmC,SAAU,CAAC;IACrD,MAAMO,KAAK,GAAG;MAAED,SAAS;MAAE,GAAGM;IAAiB,CAAC;IAEhD5D,gBAAgB,CAAE7B,IAAI,EAAEC,IAAI,EAAES,EAAE,EAAE0E,KAAK,EAAE;MAAEG,QAAQ,EAAE;IAAK,CAAE,CAAC;EAC9D,CAAC,EACD,CAAEvF,IAAI,EAAEC,IAAI,EAAES,EAAE,EAAEgC,eAAe,EAAEb,gBAAgB,CACpD,CAAC;EAED,OAAO,CAAES,MAAM,EAAEkD,OAAO,EAAER,QAAQ,CAAE;AACrC"}
1
+ {"version":3,"names":["_element","require","_data","_blocks2","_name","_footnotes","_entities","EMPTY_ARRAY","entityContexts","rootEntitiesConfig","reduce","acc","loader","kind","name","context","createContext","undefined","additionalEntityConfigLoaders","getEntityContext","Error","EntityProvider","type","id","children","Provider","createElement","value","useEntityId","useContext","useEntityProp","prop","_id","providerId","fullValue","useSelect","select","getEntityRecord","getEditedEntityRecord","STORE_NAME","record","editedRecord","editEntityRecord","useDispatch","setValue","useCallback","newValue","useEntityBlockEditor","content","editedBlocks","meta","blocks","__unstableCreateUndoLevel","useMemo","parse","updateFootnotes","_blocks","updateFootnotesFromMeta","onChange","newBlocks","options","noChange","selection","edits","blocksForSerialization","__unstableSerializeAndClean","isCached","onInput","footnotesChanges"],"sources":["@wordpress/core-data/src/entity-provider.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { updateFootnotesFromMeta } from './footnotes';\n\n/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Internal dependencies\n */\nimport { rootEntitiesConfig, additionalEntityConfigLoaders } from './entities';\n\nconst entityContexts = {\n\t...rootEntitiesConfig.reduce( ( acc, loader ) => {\n\t\tif ( ! acc[ loader.kind ] ) {\n\t\t\tacc[ loader.kind ] = {};\n\t\t}\n\t\tacc[ loader.kind ][ loader.name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t\treturn acc;\n\t}, {} ),\n\t...additionalEntityConfigLoaders.reduce( ( acc, loader ) => {\n\t\tacc[ loader.kind ] = {};\n\t\treturn acc;\n\t}, {} ),\n};\nconst getEntityContext = ( kind, name ) => {\n\tif ( ! entityContexts[ kind ] ) {\n\t\tthrow new Error( `Missing entity config for kind: ${ kind }.` );\n\t}\n\n\tif ( ! entityContexts[ kind ][ name ] ) {\n\t\tentityContexts[ kind ][ name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t}\n\n\treturn entityContexts[ kind ][ name ].context;\n};\n\n/**\n * Context provider component for providing\n * an entity for a specific entity.\n *\n * @param {Object} props The component's props.\n * @param {string} props.kind The entity kind.\n * @param {string} props.type The entity name.\n * @param {number} props.id The entity ID.\n * @param {*} props.children The children to wrap.\n *\n * @return {Object} The provided children, wrapped with\n * the entity's context provider.\n */\nexport default function EntityProvider( { kind, type: name, id, children } ) {\n\tconst Provider = getEntityContext( kind, name ).Provider;\n\treturn <Provider value={ id }>{ children }</Provider>;\n}\n\n/**\n * Hook that returns the ID for the nearest\n * provided entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n */\nexport function useEntityId( kind, name ) {\n\treturn useContext( getEntityContext( kind, name ) );\n}\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {string} prop The property name.\n * @param {string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ editEntityRecord, kind, name, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * persistent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[WPBlock[], Function, Function]} The block array and setters.\n */\nexport function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { content, editedBlocks, meta } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord } = select( STORE_NAME );\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn {\n\t\t\t\teditedBlocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t\tmeta: editedRecord.meta,\n\t\t\t};\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } =\n\t\tuseDispatch( STORE_NAME );\n\n\tconst blocks = useMemo( () => {\n\t\tif ( editedBlocks ) {\n\t\t\treturn editedBlocks;\n\t\t}\n\n\t\treturn content && typeof content !== 'function'\n\t\t\t? parse( content )\n\t\t\t: EMPTY_ARRAY;\n\t}, [ editedBlocks, content ] );\n\n\tconst updateFootnotes = useCallback(\n\t\t( _blocks ) => updateFootnotesFromMeta( _blocks, meta ),\n\t\t[ meta ]\n\t);\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst noChange = blocks === newBlocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, name, id );\n\t\t\t}\n\t\t\tconst { selection } = options;\n\n\t\t\t// We create a new function here on every persistent edit\n\t\t\t// to make sure the edit makes the post dirty and creates\n\t\t\t// a new undo level.\n\t\t\tconst edits = {\n\t\t\t\tselection,\n\t\t\t\tcontent: ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t\t__unstableSerializeAndClean( blocksForSerialization ),\n\t\t\t\t...updateFootnotes( newBlocks ),\n\t\t\t};\n\n\t\t\teditEntityRecord( kind, name, id, edits, { isCached: false } );\n\t\t},\n\t\t[\n\t\t\tkind,\n\t\t\tname,\n\t\t\tid,\n\t\t\tblocks,\n\t\t\tupdateFootnotes,\n\t\t\t__unstableCreateUndoLevel,\n\t\t\teditEntityRecord,\n\t\t]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst footnotesChanges = updateFootnotes( newBlocks );\n\t\t\tconst edits = { selection, ...footnotesChanges };\n\n\t\t\teditEntityRecord( kind, name, id, edits, { isCached: true } );\n\t\t},\n\t\t[ kind, name, id, updateFootnotes, editEntityRecord ]\n\t);\n\n\treturn [ blocks, onInput, onChange ];\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAMA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAKA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AASA,IAAAK,SAAA,GAAAL,OAAA;AAzBA;AACA;AACA;;AAUA;AACA;AACA;;AAIA;;AAEA,MAAMM,WAAW,GAAG,EAAE;;AAEtB;AACA;AACA;;AAGA,MAAMC,cAAc,GAAG;EACtB,GAAGC,4BAAkB,CAACC,MAAM,CAAE,CAAEC,GAAG,EAAEC,MAAM,KAAM;IAChD,IAAK,CAAED,GAAG,CAAEC,MAAM,CAACC,IAAI,CAAE,EAAG;MAC3BF,GAAG,CAAEC,MAAM,CAACC,IAAI,CAAE,GAAG,CAAC,CAAC;IACxB;IACAF,GAAG,CAAEC,MAAM,CAACC,IAAI,CAAE,CAAED,MAAM,CAACE,IAAI,CAAE,GAAG;MACnCC,OA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,CAAErD,IAAI,EAAEC,IAAI,EAAES,EAAE,EAAEgC,eAAe,EAAEb,gBAAgB,CACpD,CAAC;EAED,OAAO,CAAES,MAAM,EAAEgB,OAAO,EAAET,QAAQ,CAAE;AACrC"}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["@wordpress/core-data/src/entity-types/helpers.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { EntityRecord } from './index';\n\nexport interface AvatarUrls {\n\t/**\n\t * Avatar URL with image size of 24 pixels.\n\t */\n\t'24': string;\n\t/**\n\t * Avatar URL with image size of 48 pixels.\n\t */\n\t'48': string;\n\t/**\n\t * Avatar URL with image size of 96 pixels.\n\t */\n\t'96': string;\n}\n\nexport type MediaType = 'image' | 'file';\nexport type CommentingStatus = 'open' | 'closed';\nexport type PingStatus = 'open' | 'closed';\nexport type PostStatus = 'publish' | 'future' | 'draft' | 'pending' | 'private';\nexport type PostFormat =\n\t| 'standard'\n\t| 'aside'\n\t| 'chat'\n\t| 'gallery'\n\t| 'link'\n\t| 'image'\n\t| 'quote'\n\t| 'status'\n\t| 'video'\n\t| 'audio';\n\n/**\n * The REST API context parameter.\n */\nexport type Context = 'view' | 'edit' | 'embed';\n\n/**\n * ContextualField makes the field available only in the specified given contexts,\n * and ensure the field is absent from the object when in a different context.\n *\n * @example\n * ```ts\n * interface Post< C extends Context > {\n * \t…\n * \tmodified: ContextualField< string, 'edit' | 'view', C >;\n * \tpassword: ContextualField< string, 'edit', C >;\n * \t…\n * }\n *\n * const post: Post<'edit'> = …\n * // post.modified exists as a string\n * // post.password exists as a string\n *\n * const post: Post<'view'> = …\n * // post.modified still exists as a string\n * // post.password is missing, undefined, because we're not in the `edit` context.\n * ```\n */\nexport type ContextualField<\n\tFieldType,\n\tAvailableInContexts extends Context,\n\tC extends Context\n> = AvailableInContexts extends C ? FieldType : never;\n\n/**\n * Removes all the properties of type never, even the deeply nested ones.\n *\n * @example\n * ```ts\n * type MyType = {\n * foo: string;\n * bar: never;\n * nested: {\n * foo: string;\n * bar: never;\n * }\n * }\n * const x = {} as OmitNevers<MyType>;\n * // x is of type { foo: string; nested: { foo: string; }}\n * // The `never` properties were removed entirely\n * ```\n */\nexport type OmitNevers<\n\tT,\n\tNevers = {\n\t\t[ K in keyof T ]: Exclude< T[ K ], undefined > extends never\n\t\t\t? never\n\t\t\t: T[ K ] extends Record< string, unknown >\n\t\t\t? OmitNevers< T[ K ] >\n\t\t\t: T[ K ];\n\t}\n> = Pick<\n\tNevers,\n\t{\n\t\t[ K in keyof Nevers ]: Nevers[ K ] extends never ? never : K;\n\t}[ keyof Nevers ]\n>;\n\n/**\n * A string that the server renders which often involves\n * modifications from the raw source string.\n *\n * For example, block HTML with the comment delimiters exists\n * in `post_content` but those comments are stripped out when\n * rendering to a page view. Similarly, plugins might modify\n * content or replace shortcodes.\n */\nexport interface RenderedText< C extends Context > {\n\t/**\n\t * The source string which will be rendered on page views.\n\t */\n\traw: ContextualField< string, 'edit', C >;\n\t/**\n\t * The output of the raw source after processing and filtering on the server.\n\t */\n\trendered: string;\n}\n\n/**\n * Updatable<EntityRecord> is a type describing Edited Entity Records. They are like\n * regular Entity Records, but they have all the local edits applied on top of the REST API data.\n *\n * This turns certain field from an object into a string.\n *\n * Entities like Post have fields that only be rendered on the server, like title, excerpt,\n * and content. The REST API exposes both the raw markup and the rendered version of those fields.\n * For example, in the block editor, content.rendered could used as a visual preview, and\n * content.raw could be used to populate the code editor.\n *\n * When updating these rendered fields, Javascript is not be able to properly render arbitrary block\n * markup. Therefore, it stores only the raw markup without the rendered part. And since that's a string,\n * the entire field becomes a string.\n *\n * @example\n * ```ts\n * type Post< C extends Context > {\n * title: RenderedText< C >;\n * }\n * const post = {} as Post;\n * // post.title is an object with raw and rendered properties\n *\n * const updatablePost = {} as Updatable< Post >;\n * // updatablePost.title is a string\n * ```\n */\nexport type Updatable< T extends EntityRecord< 'edit' > > = {\n\t[ K in keyof T ]: T[ K ] extends RenderedText< any > ? string : T[ K ];\n};\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["@wordpress/core-data/src/entity-types/helpers.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { EntityRecord } from './index';\n\nexport interface AvatarUrls {\n\t/**\n\t * Avatar URL with image size of 24 pixels.\n\t */\n\t'24': string;\n\t/**\n\t * Avatar URL with image size of 48 pixels.\n\t */\n\t'48': string;\n\t/**\n\t * Avatar URL with image size of 96 pixels.\n\t */\n\t'96': string;\n}\n\nexport type MediaType = 'image' | 'file';\nexport type CommentingStatus = 'open' | 'closed';\nexport type PingStatus = 'open' | 'closed';\nexport type PostStatus = 'publish' | 'future' | 'draft' | 'pending' | 'private';\nexport type PostFormat =\n\t| 'standard'\n\t| 'aside'\n\t| 'chat'\n\t| 'gallery'\n\t| 'link'\n\t| 'image'\n\t| 'quote'\n\t| 'status'\n\t| 'video'\n\t| 'audio';\n\n/**\n * The REST API context parameter.\n */\nexport type Context = 'view' | 'edit' | 'embed';\n\n/**\n * ContextualField makes the field available only in the specified given contexts,\n * and ensure the field is absent from the object when in a different context.\n *\n * @example\n * ```ts\n * interface Post< C extends Context > {\n * \t…\n * \tmodified: ContextualField< string, 'edit' | 'view', C >;\n * \tpassword: ContextualField< string, 'edit', C >;\n * \t…\n * }\n *\n * const post: Post<'edit'> = …\n * // post.modified exists as a string\n * // post.password exists as a string\n *\n * const post: Post<'view'> = …\n * // post.modified still exists as a string\n * // post.password is missing, undefined, because we're not in the `edit` context.\n * ```\n */\nexport type ContextualField<\n\tFieldType,\n\tAvailableInContexts extends Context,\n\tC extends Context,\n> = AvailableInContexts extends C ? FieldType : never;\n\n/**\n * Removes all the properties of type never, even the deeply nested ones.\n *\n * @example\n * ```ts\n * type MyType = {\n * foo: string;\n * bar: never;\n * nested: {\n * foo: string;\n * bar: never;\n * }\n * }\n * const x = {} as OmitNevers<MyType>;\n * // x is of type { foo: string; nested: { foo: string; }}\n * // The `never` properties were removed entirely\n * ```\n */\nexport type OmitNevers<\n\tT,\n\tNevers = {\n\t\t[ K in keyof T ]: Exclude< T[ K ], undefined > extends never\n\t\t\t? never\n\t\t\t: T[ K ] extends Record< string, unknown >\n\t\t\t? OmitNevers< T[ K ] >\n\t\t\t: T[ K ];\n\t},\n> = Pick<\n\tNevers,\n\t{\n\t\t[ K in keyof Nevers ]: Nevers[ K ] extends never ? never : K;\n\t}[ keyof Nevers ]\n>;\n\n/**\n * A string that the server renders which often involves\n * modifications from the raw source string.\n *\n * For example, block HTML with the comment delimiters exists\n * in `post_content` but those comments are stripped out when\n * rendering to a page view. Similarly, plugins might modify\n * content or replace shortcodes.\n */\nexport interface RenderedText< C extends Context > {\n\t/**\n\t * The source string which will be rendered on page views.\n\t */\n\traw: ContextualField< string, 'edit', C >;\n\t/**\n\t * The output of the raw source after processing and filtering on the server.\n\t */\n\trendered: string;\n}\n\n/**\n * Updatable<EntityRecord> is a type describing Edited Entity Records. They are like\n * regular Entity Records, but they have all the local edits applied on top of the REST API data.\n *\n * This turns certain field from an object into a string.\n *\n * Entities like Post have fields that only be rendered on the server, like title, excerpt,\n * and content. The REST API exposes both the raw markup and the rendered version of those fields.\n * For example, in the block editor, content.rendered could used as a visual preview, and\n * content.raw could be used to populate the code editor.\n *\n * When updating these rendered fields, Javascript is not be able to properly render arbitrary block\n * markup. Therefore, it stores only the raw markup without the rendered part. And since that's a string,\n * the entire field becomes a string.\n *\n * @example\n * ```ts\n * type Post< C extends Context > {\n * title: RenderedText< C >;\n * }\n * const post = {} as Post;\n * // post.title is an object with raw and rendered properties\n *\n * const updatablePost = {} as Updatable< Post >;\n * // updatablePost.title is a string\n * ```\n */\nexport type Updatable< T extends EntityRecord< 'edit' > > = {\n\t[ K in keyof T ]: T[ K ] extends RenderedText< any > ? string : T[ K ];\n};\n"],"mappings":""}
@@ -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\t};\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA,IAAIC,YAAY,GAAG,CAAC,CAAC;AAEd,SAASC,uBAAuBA,CAAEC,MAAM,EAAEC,IAAI,EAAG;EACvD,MAAMC,MAAM,GAAG;IAAEF;EAAO,CAAC;EACzB,IAAK,CAAEC,IAAI,EAAG,OAAOC,MAAM;;EAE3B;EACA,IAAKD,IAAI,CAACE,SAAS,KAAKC,SAAS,EAAG,OAAOF,MAAM;EAEjD,MAAMG,QAAQ,GAAG,IAAAC,0BAAiB,EAAEN,MAAO,CAAC;EAE5C,MAAMG,SAAS,GAAGF,IAAI,CAACE,SAAS,GAAGI,IAAI,CAACC,KAAK,CAAEP,IAAI,CAACE,SAAU,CAAC,GAAG,EAAE;EACpE,MAAMM,YAAY,GAAGN,SAAS,CAACO,GAAG,CAAIC,EAAE,IAAMA,EAAE,CAACC,EAAG,CAAC;EAErD,IAAKH,YAAY,CAACI,IAAI,CAAE,EAAG,CAAC,KAAKR,QAAQ,CAACQ,IAAI,CAAE,EAAG,CAAC,EAAG,OAAOX,MAAM;EAEpE,MAAMY,YAAY,GAAGT,QAAQ,CAACK,GAAG,CAC9BK,IAAI,IACLZ,SAAS,CAACa,IAAI,CAAIL,EAAE,IAAMA,EAAE,CAACC,EAAE,KAAKG,IAAK,CAAC,IAC1CjB,YAAY,CAAEiB,IAAI,CAAE,IAAI;IACvBH,EAAE,EAAEG,IAAI;IACRE,OAA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UAC7Ec,KAAK,GAAG,CACR,YAAW;MACb,CACD,CAAC;IACF;IAEA,OAAOV,UAAU;EAClB;EAEA,SAASY,sBAAsBA,CAAEC,QAAQ,EAAG;IAC3C,OAAOA,QAAQ,CAACtB,GAAG,CAAIuB,KAAK,IAAM;MACjC,OAAO;QACN,GAAGA,KAAK;QACRd,UAAU,EAAED,gBAAgB,CAAEe,KAAK,CAACd,UAAW,CAAC;QAChDe,WAAW,EAAEH,sBAAsB,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;AAC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C,CAACkB,eAAe,CAAE1B,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;IACNI,YAAY;IACZC,QAAQ;IACR,GAAGM,eAAe;IAClB,GAAGd;EACJ,CAAC;AACF;AAEO,SAASkB,6BAA6BA,CAC5C3B,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;A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IACDiB,KAAK,EAAEE,MAAM,CAAEb,OAAU,CAAC,CAACgB,gCAAgC,CAC1DxB,IAAI,EACJC,IAAI,EACJC,QACD;EACD,CAAC,CAAE,EACH,CAAEF,IAAI,EAAEC,IAAI,EAAEC,QAAQ,CACvB,CAAC;EAED,MAAM;IAAEuB,IAAI,EAAEb,MAAM;IAAE,GAAGc;EAAgB,CAAC,GAAG,IAAAC,uBAAc,EACxDC,KAAK,IAAM;IACZ,IAAK,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;M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,MAAM,GAAGC,iBAAM,CAACG,OAAO;IACxB;IACA,OAAO;MACNJ,MAAM;MACNF,WAAW;MACXC,WAAW;MACXQ,OAAO,EAAER,WAAW,IAAIF,IAAI,CAACS,IAAI;MACjCD,SAAS,EAAEN,WAAW,IAAIH,MAAM,CAACU,IAAI;MACrCI,SAAS,EAAEX,WAAW,IAAIS,MAAM,CAACF,IAAI;MACrCK,SAAS,EAAEZ,WAAW,IAAIU,OAAO,CAACH;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;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,MAAM,GAAGC,iBAAM,CAACE,SAAS;MAC1B,CAAC,MAAM,IAAKJ,WAAW,EAAG;QACzBC,MAAM,G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qB,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"}
@@ -4,8 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  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"}