@wordpress/core-data 6.14.0 → 6.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 6.16.0 (2023-08-10)
6
+
7
+ ## 6.15.0 (2023-07-20)
8
+
5
9
  ## 6.14.0 (2023-07-05)
6
10
 
7
11
  ## 6.13.0 (2023-06-23)
package/README.md CHANGED
@@ -313,7 +313,7 @@ _Parameters_
313
313
 
314
314
  _Returns_
315
315
 
316
- - `Object | null`: The current global styles.
316
+ - `Array< object > | null`: The current global styles.
317
317
 
318
318
  ### getCurrentUser
319
319
 
package/build/actions.js CHANGED
@@ -44,8 +44,6 @@ var _batch = require("./batch");
44
44
 
45
45
  var _name = require("./name");
46
46
 
47
- var _privateSelectors = require("./private-selectors");
48
-
49
47
  /**
50
48
  * External dependencies
51
49
  */
@@ -433,8 +431,7 @@ const undo = () => ({
433
431
  select,
434
432
  dispatch
435
433
  }) => {
436
- // Todo: we shouldn't have to pass "root" here.
437
- const undoEdit = select(state => (0, _privateSelectors.getUndoEdits)(state.root));
434
+ const undoEdit = select.getUndoEdits();
438
435
 
439
436
  if (!undoEdit) {
440
437
  return;
@@ -457,8 +454,7 @@ const redo = () => ({
457
454
  select,
458
455
  dispatch
459
456
  }) => {
460
- // Todo: we shouldn't have to pass "root" here.
461
- const redoEdit = select(state => (0, _privateSelectors.getRedoEdits)(state.root));
457
+ const redoEdit = select.getRedoEdits();
462
458
 
463
459
  if (!redoEdit) {
464
460
  return;
@@ -568,7 +564,7 @@ const saveEntityRecord = (kind, name, record, {
568
564
  ...record
569
565
  };
570
566
  data = Object.keys(data).reduce((acc, key) => {
571
- if (['title', 'excerpt', 'content'].includes(key)) {
567
+ if (['title', 'excerpt', 'content', 'meta'].includes(key)) {
572
568
  acc[key] = data[key];
573
569
  }
574
570
 
@@ -766,6 +762,17 @@ const __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, itemsToSav
766
762
  }
767
763
  }
768
764
 
765
+ const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(kind));
766
+ const entityConfig = configs.find(config => config.kind === kind && config.name === name);
767
+ const entityIdKey = entityConfig?.key || _entities.DEFAULT_ENTITY_KEY; // If a record key is provided then update the existing record.
768
+ // This necessitates providing `recordKey` to saveEntityRecord as part of the
769
+ // `record` argument (here called `editsToSave`) to stop that action creating
770
+ // a new record and instead cause it to update the existing record.
771
+
772
+ if (recordId) {
773
+ editsToSave[entityIdKey] = recordId;
774
+ }
775
+
769
776
  return await dispatch.saveEntityRecord(kind, name, editsToSave, options);
770
777
  };
771
778
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/actions.js"],"names":["receiveUserQuery","queryID","users","type","Array","isArray","receiveCurrentUser","currentUser","addEntities","entities","receiveEntityRecords","kind","name","records","query","invalidateCache","edits","map","record","status","title","action","receiveCurrentTheme","currentTheme","__experimentalReceiveCurrentGlobalStylesId","currentGlobalStylesId","id","__experimentalReceiveThemeBaseGlobalStyles","stylesheet","globalStyles","__experimentalReceiveThemeGlobalStyleVariations","variations","receiveThemeSupports","since","receiveThemeGlobalStyleRevisions","currentId","revisions","receiveEmbedPreview","url","preview","deleteEntityRecord","recordId","__unstableFetch","apiFetch","throwOnError","dispatch","configs","entityConfig","find","config","error","deletedRecord","__experimentalNoFetch","lock","__unstableAcquireStoreLock","STORE_NAME","exclusive","hasError","path","baseURL","method","_error","__unstableReleaseStoreLock","editEntityRecord","options","select","getEntityConfig","Error","mergedEdits","getRawEntityRecord","editedRecord","getEditedEntityRecord","edit","Object","keys","reduce","acc","key","recordValue","editedRecordValue","value","undefined","meta","undo","undoIgnore","isCached","undoEdit","state","root","stackedEdits","redo","redoEdit","__unstableCreateUndoLevel","saveEntityRecord","isAutosave","resolveSelect","entityIdKey","DEFAULT_ENTITY_KEY","entries","evaluatedValue","updatedRecord","persistedRecord","getCurrentUser","currentUserId","autosavePost","getAutosave","data","includes","newRecord","receiveAutosaves","__unstablePrePersist","__experimentalBatch","requests","batch","api","add","saveEditedEntityRecord","resultPromises","request","results","Promise","all","run","hasEditsForEntityRecord","getEntityRecordNonTransientEdits","__experimentalSaveSpecifiedEntityEdits","itemsToSave","editsToSave","some","item","receiveUploadPermissions","hasUploadPermissions","alternative","receiveUserPermission","isAllowed","postId","autosaves","receiveNavigationFallbackId","fallbackId"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AApBA;AACA;AACA;;AAIA;AACA;AACA;;AAKA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,gBAAT,CAA2BC,OAA3B,EAAoCC,KAApC,EAA4C;AAClD,SAAO;AACNC,IAAAA,IAAI,EAAE,oBADA;AAEND,IAAAA,KAAK,EAAEE,KAAK,CAACC,OAAN,CAAeH,KAAf,IAAyBA,KAAzB,GAAiC,CAAEA,KAAF,CAFlC;AAGND,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASK,kBAAT,CAA6BC,WAA7B,EAA2C;AACjD,SAAO;AACNJ,IAAAA,IAAI,EAAE,sBADA;AAENI,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,WAAT,CAAsBC,QAAtB,EAAiC;AACvC,SAAO;AACNN,IAAAA,IAAI,EAAE,cADA;AAENM,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,oBAAT,CACNC,IADM,EAENC,IAFM,EAGNC,OAHM,EAINC,KAJM,EAKNC,eAAe,GAAG,KALZ,EAMNC,KANM,EAOL;AACD;AACA;AACA,MAAKL,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;AACD;;AACD,SAAO,MAAM3B,QAAQ,CAACgD,gBAAT,CACZlF,IADY,EAEZC,IAFY,EAGZmH,WAHY,EAIZ/D,OAJY,CAAb;AAMA,CAvBK;AAyBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASkE,wBAAT,CAAmCC,oBAAnC,EAA0D;AAChE,2BAAY,qDAAZ,EAAmE;AAClElG,IAAAA,KAAK,EAAE,KAD2D;AAElEmG,IAAAA,WAAW,EAAE;AAFqD,GAAnE;AAKA,SAAOC,qBAAqB,CAAE,cAAF,EAAkBF,oBAAlB,CAA5B;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,qBAAT,CAAgCxD,GAAhC,EAAqCyD,SAArC,EAAiD;AACvD,SAAO;AACNnI,IAAAA,IAAI,EAAE,yBADA;AAEN0E,IAAAA,GAFM;AAGNyD,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASzB,gBAAT,CAA2B0B,MAA3B,EAAmCC,SAAnC,EAA+C;AACrD,SAAO;AACNrI,IAAAA,IAAI,EAAE,mBADA;AAENoI,IAAAA,MAFM;AAGNC,IAAAA,SAAS,EAAEpI,KAAK,CAACC,OAAN,CAAemI,SAAf,IAA6BA,SAA7B,GAAyC,CAAEA,SAAF;AAH9C,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,2BAAT,CAAsCC,UAAtC,EAAmD;AACzD,SAAO;AACNvI,IAAAA,IAAI,EAAE,gCADA;AAENuI,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\nimport { v4 as uuid } from 'uuid';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { receiveItems, removeItems, receiveQueriedItems } from './queried-data';\nimport { getOrLoadEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';\nimport { createBatch } from './batch';\nimport { STORE_NAME } from './name';\nimport { getUndoEdits, getRedoEdits } from './private-selectors';\n\n/**\n * Returns an action object used in signalling that authors have been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {string} queryID Query ID.\n * @param {Array|Object} users Users received.\n *\n * @return {Object} Action object.\n */\nexport function receiveUserQuery( queryID, users ) {\n\treturn {\n\t\ttype: 'RECEIVE_USER_QUERY',\n\t\tusers: Array.isArray( users ) ? users : [ users ],\n\t\tqueryID,\n\t};\n}\n\n/**\n * Returns an action used in signalling that the current user has been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {Object} currentUser Current user object.\n *\n * @return {Object} Action object.\n */\nexport function receiveCurrentUser( currentUser ) {\n\treturn {\n\t\ttype: 'RECEIVE_CURRENT_USER',\n\t\tcurrentUser,\n\t};\n}\n\n/**\n * Returns an action object used in adding new entities.\n *\n * @param {Array} entities Entities received.\n *\n * @return {Object} Action object.\n */\nexport function addEntities( entities ) {\n\treturn {\n\t\ttype: 'ADD_ENTITIES',\n\t\tentities,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that entity records have been received.\n *\n * @param {string} kind Kind of the received entity record.\n * @param {string} name Name of the received entity record.\n * @param {Array|Object} records Records received.\n * @param {?Object} query Query Object.\n * @param {?boolean} invalidateCache Should invalidate query caches.\n * @param {?Object} edits Edits to reset.\n * @return {Object} Action object.\n */\nexport function receiveEntityRecords(\n\tkind,\n\tname,\n\trecords,\n\tquery,\n\tinvalidateCache = false,\n\tedits\n) {\n\t// Auto drafts should not have titles, but some plugins rely on them so we can't filter this\n\t// on the server.\n\tif ( kind === 'postType' ) {\n\t\trecords = ( Array.isArray( records ) ? records : [ records ] ).map(\n\t\t\t( record ) =>\n\t\t\t\trecord.status === 'auto-draft'\n\t\t\t\t\t? { ...record, title: '' }\n\t\t\t\t\t: record\n\t\t);\n\t}\n\tlet action;\n\tif ( query ) {\n\t\taction = receiveQueriedItems( records, query, edits );\n\t} else {\n\t\taction = receiveItems( records, edits );\n\t}\n\n\treturn {\n\t\t...action,\n\t\tkind,\n\t\tname,\n\t\tinvalidateCache,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the current theme has been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {Object} currentTheme The current theme.\n *\n * @return {Object} Action object.\n */\nexport function receiveCurrentTheme( currentTheme ) {\n\treturn {\n\t\ttype: 'RECEIVE_CURRENT_THEME',\n\t\tcurrentTheme,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the current global styles id has been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {string} currentGlobalStylesId The current global styles id.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalReceiveCurrentGlobalStylesId(\n\tcurrentGlobalStylesId\n) {\n\treturn {\n\t\ttype: 'RECEIVE_CURRENT_GLOBAL_STYLES_ID',\n\t\tid: currentGlobalStylesId,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the theme base global styles have been received\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {string} stylesheet The theme's identifier\n * @param {Object} globalStyles The global styles object.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalReceiveThemeBaseGlobalStyles(\n\tstylesheet,\n\tglobalStyles\n) {\n\treturn {\n\t\ttype: 'RECEIVE_THEME_GLOBAL_STYLES',\n\t\tstylesheet,\n\t\tglobalStyles,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the theme global styles variations have been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {string} stylesheet The theme's identifier\n * @param {Array} variations The global styles variations.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalReceiveThemeGlobalStyleVariations(\n\tstylesheet,\n\tvariations\n) {\n\treturn {\n\t\ttype: 'RECEIVE_THEME_GLOBAL_STYLE_VARIATIONS',\n\t\tstylesheet,\n\t\tvariations,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the index has been received.\n *\n * @deprecated since WP 5.9, this is not useful anymore, use the selector direclty.\n *\n * @return {Object} Action object.\n */\nexport function receiveThemeSupports() {\n\tdeprecated( \"wp.data.dispatch( 'core' ).receiveThemeSupports\", {\n\t\tsince: '5.9',\n\t} );\n\n\treturn {\n\t\ttype: 'DO_NOTHING',\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the theme global styles CPT post revisions have been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {number} currentId The post id.\n * @param {Array} revisions The global styles revisions.\n *\n * @return {Object} Action object.\n */\nexport function receiveThemeGlobalStyleRevisions( currentId, revisions ) {\n\treturn {\n\t\ttype: 'RECEIVE_THEME_GLOBAL_STYLE_REVISIONS',\n\t\tcurrentId,\n\t\trevisions,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the preview data for\n * a given URl has been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {string} url URL to preview the embed for.\n * @param {*} preview Preview data.\n *\n * @return {Object} Action object.\n */\nexport function receiveEmbedPreview( url, preview ) {\n\treturn {\n\t\ttype: 'RECEIVE_EMBED_PREVIEW',\n\t\turl,\n\t\tpreview,\n\t};\n}\n\n/**\n * Action triggered to delete an entity record.\n *\n * @param {string} kind Kind of the deleted entity.\n * @param {string} name Name of the deleted entity.\n * @param {string} recordId Record ID of the deleted entity.\n * @param {?Object} query Special query parameters for the\n * DELETE API call.\n * @param {Object} [options] Delete options.\n * @param {Function} [options.__unstableFetch] Internal use only. Function to\n * call instead of `apiFetch()`.\n * Must return a promise.\n * @param {boolean} [options.throwOnError=false] If false, this action suppresses all\n * the exceptions. Defaults to false.\n */\nexport const deleteEntityRecord =\n\t(\n\t\tkind,\n\t\tname,\n\t\trecordId,\n\t\tquery,\n\t\t{ __unstableFetch = apiFetch, throwOnError = false } = {}\n\t) =>\n\tasync ( { dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.kind === kind && config.name === name\n\t\t);\n\t\tlet error;\n\t\tlet deletedRecord = false;\n\t\tif ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name, recordId ],\n\t\t\t{ exclusive: true }\n\t\t);\n\n\t\ttry {\n\t\t\tdispatch( {\n\t\t\t\ttype: 'DELETE_ENTITY_RECORD_START',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId,\n\t\t\t} );\n\n\t\t\tlet hasError = false;\n\t\t\ttry {\n\t\t\t\tlet path = `${ entityConfig.baseURL }/${ recordId }`;\n\n\t\t\t\tif ( query ) {\n\t\t\t\t\tpath = addQueryArgs( path, query );\n\t\t\t\t}\n\n\t\t\t\tdeletedRecord = await __unstableFetch( {\n\t\t\t\t\tpath,\n\t\t\t\t\tmethod: 'DELETE',\n\t\t\t\t} );\n\n\t\t\t\tawait dispatch( removeItems( kind, name, recordId, true ) );\n\t\t\t} catch ( _error ) {\n\t\t\t\thasError = true;\n\t\t\t\terror = _error;\n\t\t\t}\n\n\t\t\tdispatch( {\n\t\t\t\ttype: 'DELETE_ENTITY_RECORD_FINISH',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId,\n\t\t\t\terror,\n\t\t\t} );\n\n\t\t\tif ( hasError && throwOnError ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn deletedRecord;\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n/**\n * Returns an action object that triggers an\n * edit to an entity record.\n *\n * @param {string} kind Kind of the edited entity record.\n * @param {string} name Name of the edited entity record.\n * @param {number|string} recordId Record ID of the edited entity record.\n * @param {Object} edits The edits.\n * @param {Object} options Options for the edit.\n * @param {boolean} [options.undoIgnore] Whether to ignore the edit in undo history or not.\n *\n * @return {Object} Action object.\n */\nexport const editEntityRecord =\n\t( kind, name, recordId, edits, options = {} ) =>\n\t( { select, dispatch } ) => {\n\t\tconst entityConfig = select.getEntityConfig( kind, name );\n\t\tif ( ! entityConfig ) {\n\t\t\tthrow new Error(\n\t\t\t\t`The entity being edited (${ kind }, ${ name }) does not have a loaded config.`\n\t\t\t);\n\t\t}\n\t\tconst { mergedEdits = {} } = entityConfig;\n\t\tconst record = select.getRawEntityRecord( kind, name, recordId );\n\t\tconst editedRecord = select.getEditedEntityRecord(\n\t\t\tkind,\n\t\t\tname,\n\t\t\trecordId\n\t\t);\n\n\t\tconst edit = {\n\t\t\tkind,\n\t\t\tname,\n\t\t\trecordId,\n\t\t\t// Clear edits when they are equal to their persisted counterparts\n\t\t\t// so that the property is not considered dirty.\n\t\t\tedits: Object.keys( edits ).reduce( ( acc, key ) => {\n\t\t\t\tconst recordValue = record[ key ];\n\t\t\t\tconst editedRecordValue = editedRecord[ key ];\n\t\t\t\tconst value = mergedEdits[ key ]\n\t\t\t\t\t? { ...editedRecordValue, ...edits[ key ] }\n\t\t\t\t\t: edits[ key ];\n\t\t\t\tacc[ key ] = fastDeepEqual( recordValue, value )\n\t\t\t\t\t? undefined\n\t\t\t\t\t: value;\n\t\t\t\treturn acc;\n\t\t\t}, {} ),\n\t\t};\n\t\tdispatch( {\n\t\t\ttype: 'EDIT_ENTITY_RECORD',\n\t\t\t...edit,\n\t\t\tmeta: {\n\t\t\t\tundo: ! options.undoIgnore && {\n\t\t\t\t\t...edit,\n\t\t\t\t\t// Send the current values for things like the first undo stack entry.\n\t\t\t\t\tedits: Object.keys( edits ).reduce( ( acc, key ) => {\n\t\t\t\t\t\tacc[ key ] = editedRecord[ key ];\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t}, {} ),\n\t\t\t\t\tisCached: options.isCached,\n\t\t\t\t},\n\t\t\t},\n\t\t} );\n\t};\n\n/**\n * Action triggered to undo the last edit to\n * an entity record, if any.\n */\nexport const undo =\n\t() =>\n\t( { select, dispatch } ) => {\n\t\t// Todo: we shouldn't have to pass \"root\" here.\n\t\tconst undoEdit = select( ( state ) => getUndoEdits( state.root ) );\n\t\tif ( ! undoEdit ) {\n\t\t\treturn;\n\t\t}\n\t\tdispatch( {\n\t\t\ttype: 'UNDO',\n\t\t\tstackedEdits: undoEdit,\n\t\t} );\n\t};\n\n/**\n * Action triggered to redo the last undoed\n * edit to an entity record, if any.\n */\nexport const redo =\n\t() =>\n\t( { select, dispatch } ) => {\n\t\t// Todo: we shouldn't have to pass \"root\" here.\n\t\tconst redoEdit = select( ( state ) => getRedoEdits( state.root ) );\n\t\tif ( ! redoEdit ) {\n\t\t\treturn;\n\t\t}\n\t\tdispatch( {\n\t\t\ttype: 'REDO',\n\t\t\tstackedEdits: redoEdit,\n\t\t} );\n\t};\n\n/**\n * Forces the creation of a new undo level.\n *\n * @return {Object} Action object.\n */\nexport function __unstableCreateUndoLevel() {\n\treturn { type: 'CREATE_UNDO_LEVEL' };\n}\n\n/**\n * Action triggered to save an entity record.\n *\n * @param {string} kind Kind of the received entity.\n * @param {string} name Name of the received entity.\n * @param {Object} record Record to be saved.\n * @param {Object} options Saving options.\n * @param {boolean} [options.isAutosave=false] Whether this is an autosave.\n * @param {Function} [options.__unstableFetch] Internal use only. Function to\n * call instead of `apiFetch()`.\n * Must return a promise.\n * @param {boolean} [options.throwOnError=false] If false, this action suppresses all\n * the exceptions. Defaults to false.\n */\nexport const saveEntityRecord =\n\t(\n\t\tkind,\n\t\tname,\n\t\trecord,\n\t\t{\n\t\t\tisAutosave = false,\n\t\t\t__unstableFetch = apiFetch,\n\t\t\tthrowOnError = false,\n\t\t} = {}\n\t) =>\n\tasync ( { select, resolveSelect, dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.kind === kind && config.name === name\n\t\t);\n\t\tif ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {\n\t\t\treturn;\n\t\t}\n\t\tconst entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;\n\t\tconst recordId = record[ entityIdKey ];\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name, recordId || uuid() ],\n\t\t\t{ exclusive: true }\n\t\t);\n\n\t\ttry {\n\t\t\t// Evaluate optimized edits.\n\t\t\t// (Function edits that should be evaluated on save to avoid expensive computations on every edit.)\n\t\t\tfor ( const [ key, value ] of Object.entries( record ) ) {\n\t\t\t\tif ( typeof value === 'function' ) {\n\t\t\t\t\tconst evaluatedValue = value(\n\t\t\t\t\t\tselect.getEditedEntityRecord( kind, name, recordId )\n\t\t\t\t\t);\n\t\t\t\t\tdispatch.editEntityRecord(\n\t\t\t\t\t\tkind,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\trecordId,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t[ key ]: evaluatedValue,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ undoIgnore: true }\n\t\t\t\t\t);\n\t\t\t\t\trecord[ key ] = evaluatedValue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SAVE_ENTITY_RECORD_START',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId,\n\t\t\t\tisAutosave,\n\t\t\t} );\n\t\t\tlet updatedRecord;\n\t\t\tlet error;\n\t\t\tlet hasError = false;\n\t\t\ttry {\n\t\t\t\tconst path = `${ entityConfig.baseURL }${\n\t\t\t\t\trecordId ? '/' + recordId : ''\n\t\t\t\t}`;\n\t\t\t\tconst persistedRecord = select.getRawEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t);\n\n\t\t\t\tif ( isAutosave ) {\n\t\t\t\t\t// Most of this autosave logic is very specific to posts.\n\t\t\t\t\t// This is fine for now as it is the only supported autosave,\n\t\t\t\t\t// but ideally this should all be handled in the back end,\n\t\t\t\t\t// so the client just sends and receives objects.\n\t\t\t\t\tconst currentUser = select.getCurrentUser();\n\t\t\t\t\tconst currentUserId = currentUser\n\t\t\t\t\t\t? currentUser.id\n\t\t\t\t\t\t: undefined;\n\t\t\t\t\tconst autosavePost = await resolveSelect.getAutosave(\n\t\t\t\t\t\tpersistedRecord.type,\n\t\t\t\t\t\tpersistedRecord.id,\n\t\t\t\t\t\tcurrentUserId\n\t\t\t\t\t);\n\t\t\t\t\t// Autosaves need all expected fields to be present.\n\t\t\t\t\t// So we fallback to the previous autosave and then\n\t\t\t\t\t// to the actual persisted entity if the edits don't\n\t\t\t\t\t// have a value.\n\t\t\t\t\tlet data = {\n\t\t\t\t\t\t...persistedRecord,\n\t\t\t\t\t\t...autosavePost,\n\t\t\t\t\t\t...record,\n\t\t\t\t\t};\n\t\t\t\t\tdata = Object.keys( data ).reduce(\n\t\t\t\t\t\t( acc, key ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t[ 'title', 'excerpt', 'content' ].includes(\n\t\t\t\t\t\t\t\t\tkey\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tacc[ key ] = data[ key ];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus:\n\t\t\t\t\t\t\t\tdata.status === 'auto-draft'\n\t\t\t\t\t\t\t\t\t? 'draft'\n\t\t\t\t\t\t\t\t\t: data.status,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t\tupdatedRecord = await __unstableFetch( {\n\t\t\t\t\t\tpath: `${ path }/autosaves`,\n\t\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\t\tdata,\n\t\t\t\t\t} );\n\n\t\t\t\t\t// An autosave may be processed by the server as a regular save\n\t\t\t\t\t// when its update is requested by the author and the post had\n\t\t\t\t\t// draft or auto-draft status.\n\t\t\t\t\tif ( persistedRecord.id === updatedRecord.id ) {\n\t\t\t\t\t\tlet newRecord = {\n\t\t\t\t\t\t\t...persistedRecord,\n\t\t\t\t\t\t\t...data,\n\t\t\t\t\t\t\t...updatedRecord,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tnewRecord = Object.keys( newRecord ).reduce(\n\t\t\t\t\t\t\t( acc, key ) => {\n\t\t\t\t\t\t\t\t// These properties are persisted in autosaves.\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t[ 'title', 'excerpt', 'content' ].includes(\n\t\t\t\t\t\t\t\t\t\tkey\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tacc[ key ] = newRecord[ key ];\n\t\t\t\t\t\t\t\t} else if ( key === 'status' ) {\n\t\t\t\t\t\t\t\t\t// Status is only persisted in autosaves when going from\n\t\t\t\t\t\t\t\t\t// \"auto-draft\" to \"draft\".\n\t\t\t\t\t\t\t\t\tacc[ key ] =\n\t\t\t\t\t\t\t\t\t\tpersistedRecord.status ===\n\t\t\t\t\t\t\t\t\t\t\t'auto-draft' &&\n\t\t\t\t\t\t\t\t\t\tnewRecord.status === 'draft'\n\t\t\t\t\t\t\t\t\t\t\t? newRecord.status\n\t\t\t\t\t\t\t\t\t\t\t: persistedRecord.status;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// These properties are not persisted in autosaves.\n\t\t\t\t\t\t\t\t\tacc[ key ] = persistedRecord[ key ];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{}\n\t\t\t\t\t\t);\n\t\t\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tnewRecord,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdispatch.receiveAutosaves(\n\t\t\t\t\t\t\tpersistedRecord.id,\n\t\t\t\t\t\t\tupdatedRecord\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tlet edits = record;\n\t\t\t\t\tif ( entityConfig.__unstablePrePersist ) {\n\t\t\t\t\t\tedits = {\n\t\t\t\t\t\t\t...edits,\n\t\t\t\t\t\t\t...entityConfig.__unstablePrePersist(\n\t\t\t\t\t\t\t\tpersistedRecord,\n\t\t\t\t\t\t\t\tedits\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tupdatedRecord = await __unstableFetch( {\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\tmethod: recordId ? 'PUT' : 'POST',\n\t\t\t\t\t\tdata: edits,\n\t\t\t\t\t} );\n\t\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\t\tkind,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tupdatedRecord,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\tedits\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch ( _error ) {\n\t\t\t\thasError = true;\n\t\t\t\terror = _error;\n\t\t\t}\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SAVE_ENTITY_RECORD_FINISH',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId,\n\t\t\t\terror,\n\t\t\t\tisAutosave,\n\t\t\t} );\n\n\t\t\tif ( hasError && throwOnError ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn updatedRecord;\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n/**\n * Runs multiple core-data actions at the same time using one API request.\n *\n * Example:\n *\n * ```\n * const [ savedRecord, updatedRecord, deletedRecord ] =\n * await dispatch( 'core' ).__experimentalBatch( [\n * ( { saveEntityRecord } ) => saveEntityRecord( 'root', 'widget', widget ),\n * ( { saveEditedEntityRecord } ) => saveEntityRecord( 'root', 'widget', 123 ),\n * ( { deleteEntityRecord } ) => deleteEntityRecord( 'root', 'widget', 123, null ),\n * ] );\n * ```\n *\n * @param {Array} requests Array of functions which are invoked simultaneously.\n * Each function is passed an object containing\n * `saveEntityRecord`, `saveEditedEntityRecord`, and\n * `deleteEntityRecord`.\n *\n * @return {(thunkArgs: Object) => Promise} A promise that resolves to an array containing the return\n * values of each function given in `requests`.\n */\nexport const __experimentalBatch =\n\t( requests ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst batch = createBatch();\n\t\tconst api = {\n\t\t\tsaveEntityRecord( kind, name, record, options ) {\n\t\t\t\treturn batch.add( ( add ) =>\n\t\t\t\t\tdispatch.saveEntityRecord( kind, name, record, {\n\t\t\t\t\t\t...options,\n\t\t\t\t\t\t__unstableFetch: add,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t},\n\t\t\tsaveEditedEntityRecord( kind, name, recordId, options ) {\n\t\t\t\treturn batch.add( ( add ) =>\n\t\t\t\t\tdispatch.saveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\t\t...options,\n\t\t\t\t\t\t__unstableFetch: add,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t},\n\t\t\tdeleteEntityRecord( kind, name, recordId, query, options ) {\n\t\t\t\treturn batch.add( ( add ) =>\n\t\t\t\t\tdispatch.deleteEntityRecord( kind, name, recordId, query, {\n\t\t\t\t\t\t...options,\n\t\t\t\t\t\t__unstableFetch: add,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t\tconst resultPromises = requests.map( ( request ) => request( api ) );\n\t\tconst [ , ...results ] = await Promise.all( [\n\t\t\tbatch.run(),\n\t\t\t...resultPromises,\n\t\t] );\n\t\treturn results;\n\t};\n\n/**\n * Action triggered to save an entity record's edits.\n *\n * @param {string} kind Kind of the entity.\n * @param {string} name Name of the entity.\n * @param {Object} recordId ID of the record.\n * @param {Object} options Saving options.\n */\nexport const saveEditedEntityRecord =\n\t( kind, name, recordId, options ) =>\n\tasync ( { select, dispatch } ) => {\n\t\tif ( ! select.hasEditsForEntityRecord( kind, name, recordId ) ) {\n\t\t\treturn;\n\t\t}\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.kind === kind && config.name === name\n\t\t);\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\t\tconst entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;\n\n\t\tconst edits = select.getEntityRecordNonTransientEdits(\n\t\t\tkind,\n\t\t\tname,\n\t\t\trecordId\n\t\t);\n\t\tconst record = { [ entityIdKey ]: recordId, ...edits };\n\t\treturn await dispatch.saveEntityRecord( kind, name, record, options );\n\t};\n\n/**\n * Action triggered to save only specified properties for the entity.\n *\n * @param {string} kind Kind of the entity.\n * @param {string} name Name of the entity.\n * @param {Object} recordId ID of the record.\n * @param {Array} itemsToSave List of entity properties to save.\n * @param {Object} options Saving options.\n */\nexport const __experimentalSaveSpecifiedEntityEdits =\n\t( kind, name, recordId, itemsToSave, options ) =>\n\tasync ( { select, dispatch } ) => {\n\t\tif ( ! select.hasEditsForEntityRecord( kind, name, recordId ) ) {\n\t\t\treturn;\n\t\t}\n\t\tconst edits = select.getEntityRecordNonTransientEdits(\n\t\t\tkind,\n\t\t\tname,\n\t\t\trecordId\n\t\t);\n\t\tconst editsToSave = {};\n\t\tfor ( const edit in edits ) {\n\t\t\tif ( itemsToSave.some( ( item ) => item === edit ) ) {\n\t\t\t\teditsToSave[ edit ] = edits[ edit ];\n\t\t\t}\n\t\t}\n\t\treturn await dispatch.saveEntityRecord(\n\t\t\tkind,\n\t\t\tname,\n\t\t\teditsToSave,\n\t\t\toptions\n\t\t);\n\t};\n\n/**\n * Returns an action object used in signalling that Upload permissions have been received.\n *\n * @deprecated since WP 5.9, use receiveUserPermission instead.\n *\n * @param {boolean} hasUploadPermissions Does the user have permission to upload files?\n *\n * @return {Object} Action object.\n */\nexport function receiveUploadPermissions( hasUploadPermissions ) {\n\tdeprecated( \"wp.data.dispatch( 'core' ).receiveUploadPermissions\", {\n\t\tsince: '5.9',\n\t\talternative: 'receiveUserPermission',\n\t} );\n\n\treturn receiveUserPermission( 'create/media', hasUploadPermissions );\n}\n\n/**\n * Returns an action object used in signalling that the current user has\n * permission to perform an action on a REST resource.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {string} key A key that represents the action and REST resource.\n * @param {boolean} isAllowed Whether or not the user can perform the action.\n *\n * @return {Object} Action object.\n */\nexport function receiveUserPermission( key, isAllowed ) {\n\treturn {\n\t\ttype: 'RECEIVE_USER_PERMISSION',\n\t\tkey,\n\t\tisAllowed,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the autosaves for a\n * post have been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {number} postId The id of the post that is parent to the autosave.\n * @param {Array|Object} autosaves An array of autosaves or singular autosave object.\n *\n * @return {Object} Action object.\n */\nexport function receiveAutosaves( postId, autosaves ) {\n\treturn {\n\t\ttype: 'RECEIVE_AUTOSAVES',\n\t\tpostId,\n\t\tautosaves: Array.isArray( autosaves ) ? autosaves : [ autosaves ],\n\t};\n}\n\n/**\n * Returns an action object signalling that the fallback Navigation\n * Menu id has been received.\n *\n * @param {integer} fallbackId the id of the fallback Navigation Menu\n * @return {Object} Action object.\n */\nexport function receiveNavigationFallbackId( fallbackId ) {\n\treturn {\n\t\ttype: 'RECEIVE_NAVIGATION_FALLBACK_ID',\n\t\tfallbackId,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/actions.js"],"names":["receiveUserQuery","queryID","users","type","Array","isArray","receiveCurrentUser","currentUser","addEntities","entities","receiveEntityRecords","kind","name","records","query","invalidateCache","edits","map","record","status","title","action","receiveCurrentTheme","currentTheme","__experimentalReceiveCurrentGlobalStylesId","currentGlobalStylesId","id","__experimentalReceiveThemeBaseGlobalStyles","stylesheet","globalStyles","__experimentalReceiveThemeGlobalStyleVariations","variations","receiveThemeSupports","since","receiveThemeGlobalStyleRevisions","currentId","revisions","receiveEmbedPreview","url","preview","deleteEntityRecord","recordId","__unstableFetch","apiFetch","throwOnError","dispatch","configs","entityConfig","find","config","error","deletedRecord","__experimentalNoFetch","lock","__unstableAcquireStoreLock","STORE_NAME","exclusive","hasError","path","baseURL","method","_error","__unstableReleaseStoreLock","editEntityRecord","options","select","getEntityConfig","Error","mergedEdits","getRawEntityRecord","editedRecord","getEditedEntityRecord","edit","Object","keys","reduce","acc","key","recordValue","editedRecordValue","value","undefined","meta","undo","undoIgnore","isCached","undoEdit","getUndoEdits","stackedEdits","redo","redoEdit","getRedoEdits","__unstableCreateUndoLevel","saveEntityRecord","isAutosave","resolveSelect","entityIdKey","DEFAULT_ENTITY_KEY","entries","evaluatedValue","updatedRecord","persistedRecord","getCurrentUser","currentUserId","autosavePost","getAutosave","data","includes","newRecord","receiveAutosaves","__unstablePrePersist","__experimentalBatch","requests","batch","api","add","saveEditedEntityRecord","resultPromises","request","results","Promise","all","run","hasEditsForEntityRecord","getEntityRecordNonTransientEdits","__experimentalSaveSpecifiedEntityEdits","itemsToSave","editsToSave","some","item","receiveUploadPermissions","hasUploadPermissions","alternative","receiveUserPermission","isAllowed","postId","autosaves","receiveNavigationFallbackId","fallbackId"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AAnBA;AACA;AACA;;AAIA;AACA;AACA;;AAKA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA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AuBG,KAAvB,CAAT;AACA;;AAED,SAAO,EACN,GAAGK,MADG;AAENV,IAAAA,IAFM;AAGNC,IAAAA,IAHM;AAING,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASO,mBAAT,CAA8BC,YAA9B,EAA6C;AACnD,SAAO;AACNpB,IAAAA,IAAI,EAAE,uBADA;AAENoB,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,0CAAT,CACNC,qBADM,EAEL;AACD,SAAO;AACNtB,IAAAA,IAAI,EAAE,kCADA;AAENuB,IAAAA,EAAE,EAAED;AAFE,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,0CAAT,CACNC,UADM,EAENC,YAFM,EAGL;AACD,SAAO;AACN1B,IAAAA,IAAI,EAAE,6BADA;AAENyB,IAAAA,UAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,+CAAT,CACNF,UADM,EAENG,UAFM,EAGL;AACD,SAAO;AACN5B,IAAAA,IAAI,EAAE,uCADA;AAENyB,IAAAA,UAFM;AAGNG,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,oBAAT,GAAgC;AACtC,2BAAY,iDAAZ,EAA+D;AAC9DC,IAAAA,KAAK,EAAE;AADuD,GAA/D;AAIA,SAAO;AACN9B,IAAAA,IAAI,EAAE;AADA,GAAP;AAGA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAAS+B,gCAAT,CAA2CC,SAA3C,EAAsDC,SAAtD,EAAkE;AACxE,SAAO;AACNjC,IAAAA,IAAI,EAAE,sCADA;AAENgC,IAAAA,SAFM;AAG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A;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASkE,wBAAT,CAAmCC,oBAAnC,EAA0D;AAChE,2BAAY,qDAAZ,EAAmE;AAClElG,IAAAA,KAAK,EAAE,KAD2D;AAElEmG,IAAAA,WAAW,EAAE;AAFqD,GAAnE;AAKA,SAAOC,qBAAqB,CAAE,cAAF,EAAkBF,oBAAlB,CAA5B;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,qBAAT,CAAgCxD,GAAhC,EAAqCyD,SAArC,EAAiD;AACvD,SAAO;AACNnI,IAAAA,IAAI,EAAE,yBADA;AAEN0E,IAAAA,GAFM;AAGNyD,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASzB,gBAAT,CAA2B0B,MAA3B,EAAmCC,SAAnC,EAA+C;AACrD,SAAO;AACNrI,IAAAA,IAAI,EAAE,mBADA;AAENoI,IAAAA,MAFM;AAGNC,IAAAA,SAAS,EAAEpI,KAAK,CAACC,OAAN,CAAemI,SAAf,IAA6BA,SAA7B,GAAyC,CAAEA,SAAF;AAH9C,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,2BAAT,CAAsCC,UAAtC,EAAmD;AACzD,SAAO;AACNvI,IAAAA,IAAI,EAAE,gCADA;AAENuI,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\nimport { v4 as uuid } from 'uuid';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { receiveItems, removeItems, receiveQueriedItems } from './queried-data';\nimport { getOrLoadEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';\nimport { createBatch } from './batch';\nimport { STORE_NAME } from './name';\n\n/**\n * Returns an action object used in signalling that authors have been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {string} queryID Query ID.\n * @param {Array|Object} users Users received.\n *\n * @return {Object} Action object.\n */\nexport function receiveUserQuery( queryID, users ) {\n\treturn {\n\t\ttype: 'RECEIVE_USER_QUERY',\n\t\tusers: Array.isArray( users ) ? users : [ users ],\n\t\tqueryID,\n\t};\n}\n\n/**\n * Returns an action used in signalling that the current user has been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {Object} currentUser Current user object.\n *\n * @return {Object} Action object.\n */\nexport function receiveCurrentUser( currentUser ) {\n\treturn {\n\t\ttype: 'RECEIVE_CURRENT_USER',\n\t\tcurrentUser,\n\t};\n}\n\n/**\n * Returns an action object used in adding new entities.\n *\n * @param {Array} entities Entities received.\n *\n * @return {Object} Action object.\n */\nexport function addEntities( entities ) {\n\treturn {\n\t\ttype: 'ADD_ENTITIES',\n\t\tentities,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that entity records have been received.\n *\n * @param {string} kind Kind of the received entity record.\n * @param {string} name Name of the received entity record.\n * @param {Array|Object} records Records received.\n * @param {?Object} query Query Object.\n * @param {?boolean} invalidateCache Should invalidate query caches.\n * @param {?Object} edits Edits to reset.\n * @return {Object} Action object.\n */\nexport function receiveEntityRecords(\n\tkind,\n\tname,\n\trecords,\n\tquery,\n\tinvalidateCache = false,\n\tedits\n) {\n\t// Auto drafts should not have titles, but some plugins rely on them so we can't filter this\n\t// on the server.\n\tif ( kind === 'postType' ) {\n\t\trecords = ( Array.isArray( records ) ? records : [ records ] ).map(\n\t\t\t( record ) =>\n\t\t\t\trecord.status === 'auto-draft'\n\t\t\t\t\t? { ...record, title: '' }\n\t\t\t\t\t: record\n\t\t);\n\t}\n\tlet action;\n\tif ( query ) {\n\t\taction = receiveQueriedItems( records, query, edits );\n\t} else {\n\t\taction = receiveItems( records, edits );\n\t}\n\n\treturn {\n\t\t...action,\n\t\tkind,\n\t\tname,\n\t\tinvalidateCache,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the current theme has been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {Object} currentTheme The current theme.\n *\n * @return {Object} Action object.\n */\nexport function receiveCurrentTheme( currentTheme ) {\n\treturn {\n\t\ttype: 'RECEIVE_CURRENT_THEME',\n\t\tcurrentTheme,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the current global styles id has been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {string} currentGlobalStylesId The current global styles id.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalReceiveCurrentGlobalStylesId(\n\tcurrentGlobalStylesId\n) {\n\treturn {\n\t\ttype: 'RECEIVE_CURRENT_GLOBAL_STYLES_ID',\n\t\tid: currentGlobalStylesId,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the theme base global styles have been received\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {string} stylesheet The theme's identifier\n * @param {Object} globalStyles The global styles object.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalReceiveThemeBaseGlobalStyles(\n\tstylesheet,\n\tglobalStyles\n) {\n\treturn {\n\t\ttype: 'RECEIVE_THEME_GLOBAL_STYLES',\n\t\tstylesheet,\n\t\tglobalStyles,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the theme global styles variations have been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {string} stylesheet The theme's identifier\n * @param {Array} variations The global styles variations.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalReceiveThemeGlobalStyleVariations(\n\tstylesheet,\n\tvariations\n) {\n\treturn {\n\t\ttype: 'RECEIVE_THEME_GLOBAL_STYLE_VARIATIONS',\n\t\tstylesheet,\n\t\tvariations,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the index has been received.\n *\n * @deprecated since WP 5.9, this is not useful anymore, use the selector direclty.\n *\n * @return {Object} Action object.\n */\nexport function receiveThemeSupports() {\n\tdeprecated( \"wp.data.dispatch( 'core' ).receiveThemeSupports\", {\n\t\tsince: '5.9',\n\t} );\n\n\treturn {\n\t\ttype: 'DO_NOTHING',\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the theme global styles CPT post revisions have been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {number} currentId The post id.\n * @param {Array} revisions The global styles revisions.\n *\n * @return {Object} Action object.\n */\nexport function receiveThemeGlobalStyleRevisions( currentId, revisions ) {\n\treturn {\n\t\ttype: 'RECEIVE_THEME_GLOBAL_STYLE_REVISIONS',\n\t\tcurrentId,\n\t\trevisions,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the preview data for\n * a given URl has been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {string} url URL to preview the embed for.\n * @param {*} preview Preview data.\n *\n * @return {Object} Action object.\n */\nexport function receiveEmbedPreview( url, preview ) {\n\treturn {\n\t\ttype: 'RECEIVE_EMBED_PREVIEW',\n\t\turl,\n\t\tpreview,\n\t};\n}\n\n/**\n * Action triggered to delete an entity record.\n *\n * @param {string} kind Kind of the deleted entity.\n * @param {string} name Name of the deleted entity.\n * @param {string} recordId Record ID of the deleted entity.\n * @param {?Object} query Special query parameters for the\n * DELETE API call.\n * @param {Object} [options] Delete options.\n * @param {Function} [options.__unstableFetch] Internal use only. Function to\n * call instead of `apiFetch()`.\n * Must return a promise.\n * @param {boolean} [options.throwOnError=false] If false, this action suppresses all\n * the exceptions. Defaults to false.\n */\nexport const deleteEntityRecord =\n\t(\n\t\tkind,\n\t\tname,\n\t\trecordId,\n\t\tquery,\n\t\t{ __unstableFetch = apiFetch, throwOnError = false } = {}\n\t) =>\n\tasync ( { dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.kind === kind && config.name === name\n\t\t);\n\t\tlet error;\n\t\tlet deletedRecord = false;\n\t\tif ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name, recordId ],\n\t\t\t{ exclusive: true }\n\t\t);\n\n\t\ttry {\n\t\t\tdispatch( {\n\t\t\t\ttype: 'DELETE_ENTITY_RECORD_START',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId,\n\t\t\t} );\n\n\t\t\tlet hasError = false;\n\t\t\ttry {\n\t\t\t\tlet path = `${ entityConfig.baseURL }/${ recordId }`;\n\n\t\t\t\tif ( query ) {\n\t\t\t\t\tpath = addQueryArgs( path, query );\n\t\t\t\t}\n\n\t\t\t\tdeletedRecord = await __unstableFetch( {\n\t\t\t\t\tpath,\n\t\t\t\t\tmethod: 'DELETE',\n\t\t\t\t} );\n\n\t\t\t\tawait dispatch( removeItems( kind, name, recordId, true ) );\n\t\t\t} catch ( _error ) {\n\t\t\t\thasError = true;\n\t\t\t\terror = _error;\n\t\t\t}\n\n\t\t\tdispatch( {\n\t\t\t\ttype: 'DELETE_ENTITY_RECORD_FINISH',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId,\n\t\t\t\terror,\n\t\t\t} );\n\n\t\t\tif ( hasError && throwOnError ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn deletedRecord;\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n/**\n * Returns an action object that triggers an\n * edit to an entity record.\n *\n * @param {string} kind Kind of the edited entity record.\n * @param {string} name Name of the edited entity record.\n * @param {number|string} recordId Record ID of the edited entity record.\n * @param {Object} edits The edits.\n * @param {Object} options Options for the edit.\n * @param {boolean} [options.undoIgnore] Whether to ignore the edit in undo history or not.\n *\n * @return {Object} Action object.\n */\nexport const editEntityRecord =\n\t( kind, name, recordId, edits, options = {} ) =>\n\t( { select, dispatch } ) => {\n\t\tconst entityConfig = select.getEntityConfig( kind, name );\n\t\tif ( ! entityConfig ) {\n\t\t\tthrow new Error(\n\t\t\t\t`The entity being edited (${ kind }, ${ name }) does not have a loaded config.`\n\t\t\t);\n\t\t}\n\t\tconst { mergedEdits = {} } = entityConfig;\n\t\tconst record = select.getRawEntityRecord( kind, name, recordId );\n\t\tconst editedRecord = select.getEditedEntityRecord(\n\t\t\tkind,\n\t\t\tname,\n\t\t\trecordId\n\t\t);\n\n\t\tconst edit = {\n\t\t\tkind,\n\t\t\tname,\n\t\t\trecordId,\n\t\t\t// Clear edits when they are equal to their persisted counterparts\n\t\t\t// so that the property is not considered dirty.\n\t\t\tedits: Object.keys( edits ).reduce( ( acc, key ) => {\n\t\t\t\tconst recordValue = record[ key ];\n\t\t\t\tconst editedRecordValue = editedRecord[ key ];\n\t\t\t\tconst value = mergedEdits[ key ]\n\t\t\t\t\t? { ...editedRecordValue, ...edits[ key ] }\n\t\t\t\t\t: edits[ key ];\n\t\t\t\tacc[ key ] = fastDeepEqual( recordValue, value )\n\t\t\t\t\t? undefined\n\t\t\t\t\t: value;\n\t\t\t\treturn acc;\n\t\t\t}, {} ),\n\t\t};\n\t\tdispatch( {\n\t\t\ttype: 'EDIT_ENTITY_RECORD',\n\t\t\t...edit,\n\t\t\tmeta: {\n\t\t\t\tundo: ! options.undoIgnore && {\n\t\t\t\t\t...edit,\n\t\t\t\t\t// Send the current values for things like the first undo stack entry.\n\t\t\t\t\tedits: Object.keys( edits ).reduce( ( acc, key ) => {\n\t\t\t\t\t\tacc[ key ] = editedRecord[ key ];\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t}, {} ),\n\t\t\t\t\tisCached: options.isCached,\n\t\t\t\t},\n\t\t\t},\n\t\t} );\n\t};\n\n/**\n * Action triggered to undo the last edit to\n * an entity record, if any.\n */\nexport const undo =\n\t() =>\n\t( { select, dispatch } ) => {\n\t\tconst undoEdit = select.getUndoEdits();\n\t\tif ( ! undoEdit ) {\n\t\t\treturn;\n\t\t}\n\t\tdispatch( {\n\t\t\ttype: 'UNDO',\n\t\t\tstackedEdits: undoEdit,\n\t\t} );\n\t};\n\n/**\n * Action triggered to redo the last undoed\n * edit to an entity record, if any.\n */\nexport const redo =\n\t() =>\n\t( { select, dispatch } ) => {\n\t\tconst redoEdit = select.getRedoEdits();\n\t\tif ( ! redoEdit ) {\n\t\t\treturn;\n\t\t}\n\t\tdispatch( {\n\t\t\ttype: 'REDO',\n\t\t\tstackedEdits: redoEdit,\n\t\t} );\n\t};\n\n/**\n * Forces the creation of a new undo level.\n *\n * @return {Object} Action object.\n */\nexport function __unstableCreateUndoLevel() {\n\treturn { type: 'CREATE_UNDO_LEVEL' };\n}\n\n/**\n * Action triggered to save an entity record.\n *\n * @param {string} kind Kind of the received entity.\n * @param {string} name Name of the received entity.\n * @param {Object} record Record to be saved.\n * @param {Object} options Saving options.\n * @param {boolean} [options.isAutosave=false] Whether this is an autosave.\n * @param {Function} [options.__unstableFetch] Internal use only. Function to\n * call instead of `apiFetch()`.\n * Must return a promise.\n * @param {boolean} [options.throwOnError=false] If false, this action suppresses all\n * the exceptions. Defaults to false.\n */\nexport const saveEntityRecord =\n\t(\n\t\tkind,\n\t\tname,\n\t\trecord,\n\t\t{\n\t\t\tisAutosave = false,\n\t\t\t__unstableFetch = apiFetch,\n\t\t\tthrowOnError = false,\n\t\t} = {}\n\t) =>\n\tasync ( { select, resolveSelect, dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.kind === kind && config.name === name\n\t\t);\n\t\tif ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {\n\t\t\treturn;\n\t\t}\n\t\tconst entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;\n\t\tconst recordId = record[ entityIdKey ];\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name, recordId || uuid() ],\n\t\t\t{ exclusive: true }\n\t\t);\n\n\t\ttry {\n\t\t\t// Evaluate optimized edits.\n\t\t\t// (Function edits that should be evaluated on save to avoid expensive computations on every edit.)\n\t\t\tfor ( const [ key, value ] of Object.entries( record ) ) {\n\t\t\t\tif ( typeof value === 'function' ) {\n\t\t\t\t\tconst evaluatedValue = value(\n\t\t\t\t\t\tselect.getEditedEntityRecord( kind, name, recordId )\n\t\t\t\t\t);\n\t\t\t\t\tdispatch.editEntityRecord(\n\t\t\t\t\t\tkind,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\trecordId,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t[ key ]: evaluatedValue,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ undoIgnore: true }\n\t\t\t\t\t);\n\t\t\t\t\trecord[ key ] = evaluatedValue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SAVE_ENTITY_RECORD_START',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId,\n\t\t\t\tisAutosave,\n\t\t\t} );\n\t\t\tlet updatedRecord;\n\t\t\tlet error;\n\t\t\tlet hasError = false;\n\t\t\ttry {\n\t\t\t\tconst path = `${ entityConfig.baseURL }${\n\t\t\t\t\trecordId ? '/' + recordId : ''\n\t\t\t\t}`;\n\t\t\t\tconst persistedRecord = select.getRawEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t);\n\n\t\t\t\tif ( isAutosave ) {\n\t\t\t\t\t// Most of this autosave logic is very specific to posts.\n\t\t\t\t\t// This is fine for now as it is the only supported autosave,\n\t\t\t\t\t// but ideally this should all be handled in the back end,\n\t\t\t\t\t// so the client just sends and receives objects.\n\t\t\t\t\tconst currentUser = select.getCurrentUser();\n\t\t\t\t\tconst currentUserId = currentUser\n\t\t\t\t\t\t? currentUser.id\n\t\t\t\t\t\t: undefined;\n\t\t\t\t\tconst autosavePost = await resolveSelect.getAutosave(\n\t\t\t\t\t\tpersistedRecord.type,\n\t\t\t\t\t\tpersistedRecord.id,\n\t\t\t\t\t\tcurrentUserId\n\t\t\t\t\t);\n\t\t\t\t\t// Autosaves need all expected fields to be present.\n\t\t\t\t\t// So we fallback to the previous autosave and then\n\t\t\t\t\t// to the actual persisted entity if the edits don't\n\t\t\t\t\t// have a value.\n\t\t\t\t\tlet data = {\n\t\t\t\t\t\t...persistedRecord,\n\t\t\t\t\t\t...autosavePost,\n\t\t\t\t\t\t...record,\n\t\t\t\t\t};\n\t\t\t\t\tdata = Object.keys( data ).reduce(\n\t\t\t\t\t\t( acc, key ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t'title',\n\t\t\t\t\t\t\t\t\t'excerpt',\n\t\t\t\t\t\t\t\t\t'content',\n\t\t\t\t\t\t\t\t\t'meta',\n\t\t\t\t\t\t\t\t].includes( key )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tacc[ key ] = data[ key ];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus:\n\t\t\t\t\t\t\t\tdata.status === 'auto-draft'\n\t\t\t\t\t\t\t\t\t? 'draft'\n\t\t\t\t\t\t\t\t\t: data.status,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t\tupdatedRecord = await __unstableFetch( {\n\t\t\t\t\t\tpath: `${ path }/autosaves`,\n\t\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\t\tdata,\n\t\t\t\t\t} );\n\n\t\t\t\t\t// An autosave may be processed by the server as a regular save\n\t\t\t\t\t// when its update is requested by the author and the post had\n\t\t\t\t\t// draft or auto-draft status.\n\t\t\t\t\tif ( persistedRecord.id === updatedRecord.id ) {\n\t\t\t\t\t\tlet newRecord = {\n\t\t\t\t\t\t\t...persistedRecord,\n\t\t\t\t\t\t\t...data,\n\t\t\t\t\t\t\t...updatedRecord,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tnewRecord = Object.keys( newRecord ).reduce(\n\t\t\t\t\t\t\t( acc, key ) => {\n\t\t\t\t\t\t\t\t// These properties are persisted in autosaves.\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t[ 'title', 'excerpt', 'content' ].includes(\n\t\t\t\t\t\t\t\t\t\tkey\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tacc[ key ] = newRecord[ key ];\n\t\t\t\t\t\t\t\t} else if ( key === 'status' ) {\n\t\t\t\t\t\t\t\t\t// Status is only persisted in autosaves when going from\n\t\t\t\t\t\t\t\t\t// \"auto-draft\" to \"draft\".\n\t\t\t\t\t\t\t\t\tacc[ key ] =\n\t\t\t\t\t\t\t\t\t\tpersistedRecord.status ===\n\t\t\t\t\t\t\t\t\t\t\t'auto-draft' &&\n\t\t\t\t\t\t\t\t\t\tnewRecord.status === 'draft'\n\t\t\t\t\t\t\t\t\t\t\t? newRecord.status\n\t\t\t\t\t\t\t\t\t\t\t: persistedRecord.status;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// These properties are not persisted in autosaves.\n\t\t\t\t\t\t\t\t\tacc[ key ] = persistedRecord[ key ];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{}\n\t\t\t\t\t\t);\n\t\t\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tnewRecord,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdispatch.receiveAutosaves(\n\t\t\t\t\t\t\tpersistedRecord.id,\n\t\t\t\t\t\t\tupdatedRecord\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tlet edits = record;\n\t\t\t\t\tif ( entityConfig.__unstablePrePersist ) {\n\t\t\t\t\t\tedits = {\n\t\t\t\t\t\t\t...edits,\n\t\t\t\t\t\t\t...entityConfig.__unstablePrePersist(\n\t\t\t\t\t\t\t\tpersistedRecord,\n\t\t\t\t\t\t\t\tedits\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tupdatedRecord = await __unstableFetch( {\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\tmethod: recordId ? 'PUT' : 'POST',\n\t\t\t\t\t\tdata: edits,\n\t\t\t\t\t} );\n\t\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\t\tkind,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tupdatedRecord,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\tedits\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch ( _error ) {\n\t\t\t\thasError = true;\n\t\t\t\terror = _error;\n\t\t\t}\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SAVE_ENTITY_RECORD_FINISH',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId,\n\t\t\t\terror,\n\t\t\t\tisAutosave,\n\t\t\t} );\n\n\t\t\tif ( hasError && throwOnError ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn updatedRecord;\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n/**\n * Runs multiple core-data actions at the same time using one API request.\n *\n * Example:\n *\n * ```\n * const [ savedRecord, updatedRecord, deletedRecord ] =\n * await dispatch( 'core' ).__experimentalBatch( [\n * ( { saveEntityRecord } ) => saveEntityRecord( 'root', 'widget', widget ),\n * ( { saveEditedEntityRecord } ) => saveEntityRecord( 'root', 'widget', 123 ),\n * ( { deleteEntityRecord } ) => deleteEntityRecord( 'root', 'widget', 123, null ),\n * ] );\n * ```\n *\n * @param {Array} requests Array of functions which are invoked simultaneously.\n * Each function is passed an object containing\n * `saveEntityRecord`, `saveEditedEntityRecord`, and\n * `deleteEntityRecord`.\n *\n * @return {(thunkArgs: Object) => Promise} A promise that resolves to an array containing the return\n * values of each function given in `requests`.\n */\nexport const __experimentalBatch =\n\t( requests ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst batch = createBatch();\n\t\tconst api = {\n\t\t\tsaveEntityRecord( kind, name, record, options ) {\n\t\t\t\treturn batch.add( ( add ) =>\n\t\t\t\t\tdispatch.saveEntityRecord( kind, name, record, {\n\t\t\t\t\t\t...options,\n\t\t\t\t\t\t__unstableFetch: add,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t},\n\t\t\tsaveEditedEntityRecord( kind, name, recordId, options ) {\n\t\t\t\treturn batch.add( ( add ) =>\n\t\t\t\t\tdispatch.saveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\t\t...options,\n\t\t\t\t\t\t__unstableFetch: add,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t},\n\t\t\tdeleteEntityRecord( kind, name, recordId, query, options ) {\n\t\t\t\treturn batch.add( ( add ) =>\n\t\t\t\t\tdispatch.deleteEntityRecord( kind, name, recordId, query, {\n\t\t\t\t\t\t...options,\n\t\t\t\t\t\t__unstableFetch: add,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t\tconst resultPromises = requests.map( ( request ) => request( api ) );\n\t\tconst [ , ...results ] = await Promise.all( [\n\t\t\tbatch.run(),\n\t\t\t...resultPromises,\n\t\t] );\n\t\treturn results;\n\t};\n\n/**\n * Action triggered to save an entity record's edits.\n *\n * @param {string} kind Kind of the entity.\n * @param {string} name Name of the entity.\n * @param {Object} recordId ID of the record.\n * @param {Object} options Saving options.\n */\nexport const saveEditedEntityRecord =\n\t( kind, name, recordId, options ) =>\n\tasync ( { select, dispatch } ) => {\n\t\tif ( ! select.hasEditsForEntityRecord( kind, name, recordId ) ) {\n\t\t\treturn;\n\t\t}\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.kind === kind && config.name === name\n\t\t);\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\t\tconst entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;\n\n\t\tconst edits = select.getEntityRecordNonTransientEdits(\n\t\t\tkind,\n\t\t\tname,\n\t\t\trecordId\n\t\t);\n\t\tconst record = { [ entityIdKey ]: recordId, ...edits };\n\t\treturn await dispatch.saveEntityRecord( kind, name, record, options );\n\t};\n\n/**\n * Action triggered to save only specified properties for the entity.\n *\n * @param {string} kind Kind of the entity.\n * @param {string} name Name of the entity.\n * @param {Object} recordId ID of the record.\n * @param {Array} itemsToSave List of entity properties to save.\n * @param {Object} options Saving options.\n */\nexport const __experimentalSaveSpecifiedEntityEdits =\n\t( kind, name, recordId, itemsToSave, options ) =>\n\tasync ( { select, dispatch } ) => {\n\t\tif ( ! select.hasEditsForEntityRecord( kind, name, recordId ) ) {\n\t\t\treturn;\n\t\t}\n\t\tconst edits = select.getEntityRecordNonTransientEdits(\n\t\t\tkind,\n\t\t\tname,\n\t\t\trecordId\n\t\t);\n\t\tconst editsToSave = {};\n\t\tfor ( const edit in edits ) {\n\t\t\tif ( itemsToSave.some( ( item ) => item === edit ) ) {\n\t\t\t\teditsToSave[ edit ] = edits[ edit ];\n\t\t\t}\n\t\t}\n\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.kind === kind && config.name === name\n\t\t);\n\n\t\tconst entityIdKey = entityConfig?.key || DEFAULT_ENTITY_KEY;\n\n\t\t// If a record key is provided then update the existing record.\n\t\t// This necessitates providing `recordKey` to saveEntityRecord as part of the\n\t\t// `record` argument (here called `editsToSave`) to stop that action creating\n\t\t// a new record and instead cause it to update the existing record.\n\t\tif ( recordId ) {\n\t\t\teditsToSave[ entityIdKey ] = recordId;\n\t\t}\n\n\t\treturn await dispatch.saveEntityRecord(\n\t\t\tkind,\n\t\t\tname,\n\t\t\teditsToSave,\n\t\t\toptions\n\t\t);\n\t};\n\n/**\n * Returns an action object used in signalling that Upload permissions have been received.\n *\n * @deprecated since WP 5.9, use receiveUserPermission instead.\n *\n * @param {boolean} hasUploadPermissions Does the user have permission to upload files?\n *\n * @return {Object} Action object.\n */\nexport function receiveUploadPermissions( hasUploadPermissions ) {\n\tdeprecated( \"wp.data.dispatch( 'core' ).receiveUploadPermissions\", {\n\t\tsince: '5.9',\n\t\talternative: 'receiveUserPermission',\n\t} );\n\n\treturn receiveUserPermission( 'create/media', hasUploadPermissions );\n}\n\n/**\n * Returns an action object used in signalling that the current user has\n * permission to perform an action on a REST resource.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {string} key A key that represents the action and REST resource.\n * @param {boolean} isAllowed Whether or not the user can perform the action.\n *\n * @return {Object} Action object.\n */\nexport function receiveUserPermission( key, isAllowed ) {\n\treturn {\n\t\ttype: 'RECEIVE_USER_PERMISSION',\n\t\tkey,\n\t\tisAllowed,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the autosaves for a\n * post have been received.\n * Ignored from documentation as it's internal to the data store.\n *\n * @ignore\n *\n * @param {number} postId The id of the post that is parent to the autosave.\n * @param {Array|Object} autosaves An array of autosaves or singular autosave object.\n *\n * @return {Object} Action object.\n */\nexport function receiveAutosaves( postId, autosaves ) {\n\treturn {\n\t\ttype: 'RECEIVE_AUTOSAVES',\n\t\tpostId,\n\t\tautosaves: Array.isArray( autosaves ) ? autosaves : [ autosaves ],\n\t};\n}\n\n/**\n * Returns an action object signalling that the fallback Navigation\n * Menu id has been received.\n *\n * @param {integer} fallbackId the id of the fallback Navigation Menu\n * @return {Object} Action object.\n */\nexport function receiveNavigationFallbackId( fallbackId ) {\n\treturn {\n\t\ttype: 'RECEIVE_NAVIGATION_FALLBACK_ID',\n\t\tfallbackId,\n\t};\n}\n"]}
@@ -149,7 +149,7 @@ function useEntityProp(kind, name, prop, _id) {
149
149
  editEntityRecord(kind, name, id, {
150
150
  [prop]: newValue
151
151
  });
152
- }, [kind, name, id, prop]);
152
+ }, [editEntityRecord, kind, name, id, prop]);
153
153
  return [value, setValue, fullValue];
154
154
  }
155
155
  /**
@@ -179,7 +179,7 @@ function useEntityBlockEditor(kind, name, {
179
179
  const id = _id !== null && _id !== void 0 ? _id : providerId;
180
180
  const {
181
181
  content,
182
- blocks,
182
+ editedBlocks,
183
183
  meta
184
184
  } = (0, _data.useSelect)(select => {
185
185
  const {
@@ -187,7 +187,7 @@ function useEntityBlockEditor(kind, name, {
187
187
  } = select(_name.STORE_NAME);
188
188
  const editedRecord = getEditedEntityRecord(kind, name, id);
189
189
  return {
190
- blocks: editedRecord.blocks,
190
+ editedBlocks: editedRecord.blocks,
191
191
  content: editedRecord.content,
192
192
  meta: editedRecord.meta
193
193
  };
@@ -196,23 +196,20 @@ function useEntityBlockEditor(kind, name, {
196
196
  __unstableCreateUndoLevel,
197
197
  editEntityRecord
198
198
  } = (0, _data.useDispatch)(_name.STORE_NAME);
199
- (0, _element.useEffect)(() => {
200
- // Load the blocks from the content if not already in state
201
- // Guard against other instances that might have
202
- // set content to a function already or the blocks are already in state.
203
- if (content && typeof content !== 'function' && !blocks) {
204
- const parsedContent = (0, _blocks2.parse)(content);
205
- editEntityRecord(kind, name, id, {
206
- blocks: parsedContent
207
- }, {
208
- undoIgnore: true
209
- });
199
+ const blocks = (0, _element.useMemo)(() => {
200
+ if (editedBlocks) {
201
+ return editedBlocks;
210
202
  }
211
- }, [content]);
203
+
204
+ return content && typeof content !== 'function' ? (0, _blocks2.parse)(content) : EMPTY_ARRAY;
205
+ }, [editedBlocks, content]);
212
206
  const updateFootnotes = (0, _element.useCallback)(_blocks => {
213
- if (!meta) return; // If meta.footnotes is empty, it means the meta is not registered.
207
+ const output = {
208
+ blocks: _blocks
209
+ };
210
+ if (!meta) return output; // If meta.footnotes is empty, it means the meta is not registered.
214
211
 
215
- if (meta.footnotes === undefined) return {};
212
+ if (meta.footnotes === undefined) return output;
216
213
  const {
217
214
  getRichTextValues
218
215
  } = (0, _privateApis.unlock)(_blockEditor.privateApis);
@@ -234,11 +231,61 @@ function useEntityBlockEditor(kind, name, {
234
231
 
235
232
  const footnotes = meta.footnotes ? JSON.parse(meta.footnotes) : [];
236
233
  const currentOrder = footnotes.map(fn => fn.id);
237
- if (currentOrder.join('') === newOrder.join('')) return;
234
+ if (currentOrder.join('') === newOrder.join('')) return output;
238
235
  const newFootnotes = newOrder.map(fnId => footnotes.find(fn => fn.id === fnId) || oldFootnotes[fnId] || {
239
236
  id: fnId,
240
237
  content: ''
241
238
  });
239
+
240
+ function updateAttributes(attributes) {
241
+ attributes = { ...attributes
242
+ };
243
+
244
+ for (const key in attributes) {
245
+ const value = attributes[key];
246
+
247
+ if (Array.isArray(value)) {
248
+ attributes[key] = value.map(updateAttributes);
249
+ continue;
250
+ }
251
+
252
+ if (typeof value !== 'string') {
253
+ continue;
254
+ }
255
+
256
+ if (value.indexOf('data-fn') === -1) {
257
+ continue;
258
+ } // When we store rich text values, this would no longer
259
+ // require a regex.
260
+
261
+
262
+ const regex = /(<sup[^>]+data-fn="([^"]+)"[^>]*><a[^>]*>)[\d*]*<\/a><\/sup>/g;
263
+ attributes[key] = value.replace(regex, (match, opening, fnId) => {
264
+ const index = newOrder.indexOf(fnId);
265
+ return `${opening}${index + 1}</a></sup>`;
266
+ });
267
+ const compatRegex = /<a[^>]+data-fn="([^"]+)"[^>]*>\*<\/a>/g;
268
+ attributes[key] = attributes[key].replace(compatRegex, (match, fnId) => {
269
+ const index = newOrder.indexOf(fnId);
270
+ return `<sup data-fn="${fnId}" class="fn"><a href="#${fnId}" id="${fnId}-link">${index + 1}</a></sup>`;
271
+ });
272
+ }
273
+
274
+ return attributes;
275
+ }
276
+
277
+ function updateBlocksAttributes(__blocks) {
278
+ return __blocks.map(block => {
279
+ return { ...block,
280
+ attributes: updateAttributes(block.attributes),
281
+ innerBlocks: updateBlocksAttributes(block.innerBlocks)
282
+ };
283
+ });
284
+ } // We need to go through all block attributs deeply and update the
285
+ // footnote anchor numbering (textContent) to match the new order.
286
+
287
+
288
+ const newBlocks = updateBlocksAttributes(_blocks);
242
289
  oldFootnotes = { ...oldFootnotes,
243
290
  ...footnotes.reduce((acc, fn) => {
244
291
  if (!newOrder.includes(fn.id)) {
@@ -251,7 +298,8 @@ function useEntityBlockEditor(kind, name, {
251
298
  return {
252
299
  meta: { ...meta,
253
300
  footnotes: JSON.stringify(newFootnotes)
254
- }
301
+ },
302
+ blocks: newBlocks
255
303
  };
256
304
  }, [meta]);
257
305
  const onChange = (0, _element.useCallback)((newBlocks, options) => {
@@ -268,7 +316,6 @@ function useEntityBlockEditor(kind, name, {
268
316
  // a new undo level.
269
317
 
270
318
  const edits = {
271
- blocks: newBlocks,
272
319
  selection,
273
320
  content: ({
274
321
  blocks: blocksForSerialization = []
@@ -285,7 +332,6 @@ function useEntityBlockEditor(kind, name, {
285
332
  } = options;
286
333
  const footnotesChanges = updateFootnotes(newBlocks);
287
334
  const edits = {
288
- blocks: newBlocks,
289
335
  selection,
290
336
  ...footnotesChanges
291
337
  };
@@ -293,6 +339,6 @@ function useEntityBlockEditor(kind, name, {
293
339
  isCached: true
294
340
  });
295
341
  }, [kind, name, id, updateFootnotes, editEntityRecord]);
296
- return [blocks !== null && blocks !== void 0 ? blocks : EMPTY_ARRAY, onInput, onChange];
342
+ return [blocks, onInput, onChange];
297
343
  }
298
344
  //# sourceMappingURL=entity-provider.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/entity-provider.js"],"names":["EMPTY_ARRAY","oldFootnotes","entityContexts","rootEntitiesConfig","reduce","acc","loader","kind","name","context","undefined","additionalEntityConfigLoaders","getEntityContext","Error","EntityProvider","type","id","children","Provider","useEntityId","useEntityProp","prop","_id","providerId","value","fullValue","select","getEntityRecord","getEditedEntityRecord","STORE_NAME","record","editedRecord","editEntityRecord","setValue","newValue","useEntityBlockEditor","content","blocks","meta","__unstableCreateUndoLevel","parsedContent","undoIgnore","updateFootnotes","_blocks","footnotes","getRichTextValues","blockEditorPrivateApis","_content","join","newOrder","indexOf","regex","match","exec","push","JSON","parse","currentOrder","map","fn","newFootnotes","fnId","find","includes","stringify","onChange","newBlocks","options","noChange","selection","edits","blocksForSerialization","isCached","onInput","footnotesChanges"],"mappings":";;;;;;;;;;AAGA;;AAMA;;AACA;;AACA;;AAKA;;AACA;;AAWA;;AA5BA;AACA;AACA;;AAWA;AACA;AACA;;AAIA;AAEA,MAAMA,WAAW,GAAG,EAApB;AAEA,IAAIC,YAAY,GAAG,EAAnB;AAEA;AACA;AACA;;AAGA,MAAMC,cAAc,GAAG,EACtB,GAAGC,6BAAmBC,MAAnB,CAA2B,CAAEC,GAAF,EAAOC,MAAP,KAAmB;AAChD,QAAK,CAAED,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAV,EAA4B;AAC3BF,MAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,GAAqB,EAArB;AACA;;AACDF,IAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,CAAoBD,MAAM,CAACE,IAA3B,IAAoC;AACnCC,MAAAA,OAAO,EAAE,4BAAeC,SAAf;AAD0B,KAApC;AAGA,WAAOL,GAAP;AACA,GARE,EAQA,EARA,CADmB;AAUtB,KAAGM,wCAA8BP,MAA9B,CAAsC,CAAEC,GAAF,EAAOC,MAAP,KAAmB;AAC3DD,IAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,GAAqB,EAArB;AACA,WAAOF,GAAP;AACA,GAHE,EAGA,EAHA;AAVmB,CAAvB;;AAeA,MAAMO,gBAAgB,GAAG,CAAEL,IAAF,EAA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EE,MAAAA;AAAF,QAAgBF,OAAtB;AACA,UAAMO,gBAAgB,GAAGhC,eAAe,CAAEwB,SAAF,CAAxC;AACA,UAAMI,KAAK,GAAG;AAAEjC,MAAAA,MAAM,EAAE6B,SAAV;AAAqBG,MAAAA,SAArB;AAAgC,SAAGK;AAAnC,KAAd;AAEA1C,IAAAA,gBAAgB,CAAEzB,IAAF,EAAQC,IAAR,EAAcQ,EAAd,EAAkBsD,KAAlB,EAAyB;AAAEE,MAAAA,QAAQ,EAAE;AAAZ,KAAzB,CAAhB;AACA,GAPc,EAQf,CAAEjE,IAAF,EAAQC,IAAR,EAAcQ,EAAd,EAAkB0B,eAAlB,EAAmCV,gBAAnC,CARe,CAAhB;AAWA,SAAO,CAAEK,MAAF,aAAEA,MAAF,cAAEA,MAAF,GAAYrC,WAAZ,EAAyByE,OAAzB,EAAkCR,QAAlC,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseCallback,\n\tuseEffect,\n} from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\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[ kind, name, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * peristent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[WPBlock[], Function, Function]} The block array and setters.\n */\nexport function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { content, blocks, 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\tblocks: 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\tuseEffect( () => {\n\t\t// Load the blocks from the content if not already in state\n\t\t// Guard against other instances that might have\n\t\t// set content to a function already or the blocks are already in state.\n\t\tif ( content && typeof content !== 'function' && ! blocks ) {\n\t\t\tconst parsedContent = parse( content );\n\t\t\teditEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\tblocks: parsedContent,\n\t\t\t\t},\n\t\t\t\t{ undoIgnore: true }\n\t\t\t);\n\t\t}\n\t}, [ content ] );\n\n\tconst updateFootnotes = useCallback(\n\t\t( _blocks ) => {\n\t\t\tif ( ! meta ) return;\n\t\t\t// If meta.footnotes is empty, it means the meta is not registered.\n\t\t\tif ( meta.footnotes === undefined ) return {};\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( '' ) ) return;\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\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};\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\tblocks: newBlocks,\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 = { blocks: newBlocks, 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 ?? EMPTY_ARRAY, onInput, onChange ];\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/entity-provider.js"],"names":["EMPTY_ARRAY","oldFootnotes","entityContexts","rootEntitiesConfig","reduce","acc","loader","kind","name","context","undefined","additionalEntityConfigLoaders","getEntityContext","Error","EntityProvider","type","id","children","Provider","useEntityId","useEntityProp","prop","_id","providerId","value","fullValue","select","getEntityRecord","getEditedEntityRecord","STORE_NAME","record","editedRecord","editEntityRecord","setValue","newValue","useEntityBlockEditor","content","editedBlocks","meta","blocks","__unstableCreateUndoLevel","updateFootnotes","_blocks","output","footnotes","getRichTextValues","blockEditorPrivateApis","_content","join","newOrder","indexOf","regex","match","exec","push","JSON","parse","currentOrder","map","fn","newFootnotes","fnId","find","updateAttributes","attributes","key","Array","isArray","replace","opening","index","compatRegex","updateBlocksAttributes","__blocks","block","innerBlocks","newBlocks","includes","stringify","onChange","options","noChange","selection","edits","blocksForSerialization","isCached","onInput","footnotesChanges"],"mappings":";;;;;;;;;;AAGA;;AAMA;;AACA;;AACA;;AAKA;;AACA;;AAWA;;AA5BA;AACA;AACA;;AAWA;AACA;AACA;;AAIA;AAEA,MAAMA,WAAW,GAAG,EAApB;AAEA,IAAIC,YAAY,GAAG,EAAnB;AAEA;AACA;AACA;;AAGA,MAAMC,cAAc,GAAG,EACtB,GAAGC,6BAAmBC,MAAnB,CAA2B,CAAEC,GAAF,EAAOC,MAAP,KAAmB;AAChD,QAAK,CAAED,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAV,EAA4B;AAC3BF,MAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,GAAqB,EAArB;AACA;;AACDF,IAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,CAAoBD,MAAM,CAACE,IAA3B,IAAoC;AACnCC,MAAAA,OAAO,EAAE,4BAAeC,SAAf;AAD0B,KAApC;AAGA,WAAOL,GAAP;AACA,GARE,EAQA,EARA,CADmB;AAUtB,KAAGM,wCAA8BP,MAA9B,CAAsC,CAAEC,GAAF,EAAOC,MAAP,KA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,MAAAA,SADa;AAEb9C,MAAAA,OAAO,EAAE,CAAE;AAAEG,QAAAA,MAAM,EAAE6C,sBAAsB,GAAG;AAAnC,OAAF,KACR,0CAA6BA,sBAA7B,CAHY;AAIb,SAAG3C,eAAe,CAAEmC,SAAF;AAJL,KAAd;AAOA5C,IAAAA,gBAAgB,CAAEzB,IAAF,EAAQC,IAAR,EAAcQ,EAAd,EAAkBmE,KAAlB,EAAyB;AAAEE,MAAAA,QAAQ,EAAE;AAAZ,KAAzB,CAAhB;AACA,GAnBe,EAoBhB,CACC9E,IADD,EAECC,IAFD,EAGCQ,EAHD,EAICuB,MAJD,EAKCE,eALD,EAMCD,yBAND,EAOCR,gBAPD,CApBgB,CAAjB;AA+BA,QAAMsD,OAAO,GAAG,0BACf,CAAEV,SAAF,EAAaI,OAAb,KAA0B;AACzB,UAAM;AAAEE,MAAAA;AAAF,QAAgBF,OAAtB;AACA,UAAMO,gBAAgB,GAAG9C,eAAe,CAAEmC,SAAF,CAAxC;AACA,UAAMO,KAAK,GAAG;AAAED,MAAAA,SAAF;AAAa,SAAGK;AAAhB,KAAd;AAEAvD,IAAAA,gBAAgB,CAAEzB,IAAF,EAAQC,IAAR,EAAcQ,EAAd,EAAkBmE,KAAlB,EAAyB;AAAEE,MAAAA,QAAQ,EAAE;AAAZ,KAAzB,CAAhB;AACA,GAPc,EAQf,CAAE9E,IAAF,EAAQC,IAAR,EAAcQ,EAAd,EAAkByB,eAAlB,EAAmCT,gBAAnC,CARe,CAAhB;AAWA,SAAO,CAAEO,MAAF,EAAU+C,OAAV,EAAmBP,QAAnB,CAAP;AACA","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 * peristent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[WPBlock[], Function, Function]} The block array and setters.\n */\nexport function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { content, 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\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 attributs 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"]}
package/build/index.js CHANGED
@@ -23,6 +23,8 @@ var _reducer = _interopRequireDefault(require("./reducer"));
23
23
 
24
24
  var selectors = _interopRequireWildcard(require("./selectors"));
25
25
 
26
+ var privateSelectors = _interopRequireWildcard(require("./private-selectors"));
27
+
26
28
  var actions = _interopRequireWildcard(require("./actions"));
27
29
 
28
30
  var resolvers = _interopRequireWildcard(require("./resolvers"));
@@ -35,8 +37,6 @@ var _name = require("./name");
35
37
 
36
38
  var _privateApis = require("./private-apis");
37
39
 
38
- var _privateSelectors = require("./private-selectors");
39
-
40
40
  var _entityProvider = _interopRequireWildcard(require("./entity-provider"));
41
41
 
42
42
  Object.keys(_entityProvider).forEach(function (key) {
@@ -173,8 +173,6 @@ const storeConfig = () => ({
173
173
 
174
174
  const store = (0, _data.createReduxStore)(_name.STORE_NAME, storeConfig());
175
175
  exports.store = store;
176
- (0, _privateApis.unlock)(store).registerPrivateSelectors({
177
- getNavigationFallbackId: _privateSelectors.getNavigationFallbackId
178
- });
176
+ (0, _privateApis.unlock)(store).registerPrivateSelectors(privateSelectors);
179
177
  (0, _data.register)(store); // Register store after unlocking private selectors to allow resolvers to use them.
180
178
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","rootEntitiesConfig","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","getEntityRecords","entityResolvers","resolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","store","STORE_NAME","registerPrivateSelectors","getNavigationFallbackId"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAuDA;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;AA3EA;AACA;AACA;;AAGA;AACA;AACA;AAWA;AACA;AACA;AACA;AAEA,MAAMA,eAAe,GAAGC,6BAAmBC,MAAnB,CAA2B,CAAEC,MAAF,EAAUC,MAAV,KAAsB;AACxE,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAiBF,MAAvB;;AACAD,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,CAAF,CAAN,GAAwC,CAAEC,KAAF,EAASC,GAAT,EAAcC,KAAd,KACvCC,SAAS,CAACC,eAAV,CAA2BJ,KAA3B,EAAkCF,IAAlC,EAAwCC,IAAxC,EAA8CE,GAA9C,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AF;AAAQC,IAAAA;AAAR,MAAiBF,MAAvB;;AACAD,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,EAA2B,MAA3B,CAAF,CAAN,GAAkDE,GAAF,IAC/CY,OAAO,CAACC,gBAAR,CAA0BhB,IAA1B,EAAgCC,IAAhC,EAAsCE,GAAtC,CADD;;AAEAL,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,EAA2B,QAA3B,CAAF,CAAN,GAAkD,CAAEE,GAAF,EAAOC,KAAP,KACjDW,OAAO,CAACE,kBAAR,CAA4BjB,IAA5B,EAAkCC,IAAlC,EAAwCE,GAAxC,EAA6CC,KAA7C,CADD;;AAEA,SAAON,MAAP;AACA,CAPqB,EAOnB,EAPmB,CAAtB;;AASA,MAAMoB,WAAW,GAAG,OAAQ;AAC3BC,EAAAA,OAAO,EAAPA,gBAD2B;AAE3BJ,EAAAA,OAAO,EAAE,EAAE,GAAGA,OAAL;AAAc,OAAGD,aAAjB;AAAgC,OAAG;AAAnC,GAFkB;AAG3BT,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGV;AAAnB,GAHgB;AAI3Bc,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGD;AAAnB;AAJgB,CAAR,CAApB;AAOA;AACA;AACA;AACA;AACA;;;AACO,MAAMY,KAAK,GAAG,4BAAkBC,gBAAlB,EAA8BH,WAAW,EAAzC,CAAd;;AACP,yBAAQE,KAAR,EAAgBE,wBAAhB,CAA0C;AACzCC,EAAAA,uBAAuB,EAAvBA;AADyC,CAA1C;AAGA,oBAAUH,KAAV,E,CAAmB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { rootEntitiesConfig, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\nimport { unlock } from './private-apis';\nimport { getNavigationFallbackId } from './private-selectors';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\nunlock( store ).registerPrivateSelectors( {\n\tgetNavigationFallbackId,\n} );\nregister( store ); // Register store after unlocking private selectors to allow resolvers to use them.\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","rootEntitiesConfig","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","getEntityRecords","entityResolvers","resolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","store","STORE_NAME","registerPrivateSelectors","privateSelectors"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAqDA;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;AAzEA;AACA;AACA;;AAGA;AACA;AACA;AAWA;AACA;AACA;AACA;AAEA,MAAMA,eAAe,GAAGC,6BAAmBC,MAAnB,CAA2B,CAAEC,MAAF,EAAUC,MAAV,KAAsB;AACxE,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAiBF,MAAvB;;AACAD,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,CAAF,CAAN,GAAwC,CAAEC,KAAF,EAASC,GAAT,EAAcC,KAAd,KACvCC,SAAS,CAACC,eAAV,CAA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AEC,MAAF,EAAUC,MAAV,KAAsB;AACtE,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAiBF,MAAvB;;AACAD,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,EAA2B,MAA3B,CAAF,CAAN,GAAkDE,GAAF,IAC/CY,OAAO,CAACC,gBAAR,CAA0BhB,IAA1B,EAAgCC,IAAhC,EAAsCE,GAAtC,CADD;;AAEAL,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,EAA2B,QAA3B,CAAF,CAAN,GAAkD,CAAEE,GAAF,EAAOC,KAAP,KACjDW,OAAO,CAACE,kBAAR,CAA4BjB,IAA5B,EAAkCC,IAAlC,EAAwCE,GAAxC,EAA6CC,KAA7C,CADD;;AAEA,SAAON,MAAP;AACA,CAPqB,EAOnB,EAPmB,CAAtB;;AASA,MAAMoB,WAAW,GAAG,OAAQ;AAC3BC,EAAAA,OAAO,EAAPA,gBAD2B;AAE3BJ,EAAAA,OAAO,EAAE,EAAE,GAAGA,OAAL;AAAc,OAAGD,aAAjB;AAAgC,OAAG;AAAnC,GAFkB;AAG3BT,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGV;AAAnB,GAHgB;AAI3Bc,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGD;AAAnB;AAJgB,CAAR,CAApB;AAOA;AACA;AACA;AACA;AACA;;;AACO,MAAMY,KAAK,GAAG,4BAAkBC,gBAAlB,EAA8BH,WAAW,EAAzC,CAAd;;AACP,yBAAQE,KAAR,EAAgBE,wBAAhB,CAA0CC,gBAA1C;AACA,oBAAUH,KAAV,E,CAAmB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as privateSelectors from './private-selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { rootEntitiesConfig, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\nimport { unlock } from './private-apis';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\nunlock( store ).registerPrivateSelectors( privateSelectors );\nregister( store ); // Register store after unlocking private selectors to allow resolvers to use them.\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\n"]}