@wordpress/core-data 7.43.0 → 7.43.2-next.v.202604091042.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/build/entities.cjs +28 -20
  3. package/build/entities.cjs.map +2 -2
  4. package/build/hooks/index.cjs +3 -3
  5. package/build/hooks/index.cjs.map +1 -1
  6. package/build/hooks/use-entity-record.cjs +4 -4
  7. package/build/hooks/use-entity-record.cjs.map +2 -2
  8. package/build/hooks/use-entity-records.cjs +3 -3
  9. package/build/hooks/use-entity-records.cjs.map +2 -2
  10. package/build/hooks/use-query-select.cjs +2 -2
  11. package/build/hooks/use-query-select.cjs.map +2 -2
  12. package/build/hooks/use-resource-permissions.cjs +4 -4
  13. package/build/hooks/use-resource-permissions.cjs.map +2 -2
  14. package/build/queried-data/selectors.cjs +21 -17
  15. package/build/queried-data/selectors.cjs.map +2 -2
  16. package/build/resolvers.cjs +6 -6
  17. package/build/resolvers.cjs.map +2 -2
  18. package/build/selectors.cjs +4 -2
  19. package/build/selectors.cjs.map +2 -2
  20. package/build/utils/crdt-blocks.cjs +122 -30
  21. package/build/utils/crdt-blocks.cjs.map +2 -2
  22. package/build/utils/crdt.cjs +8 -0
  23. package/build/utils/crdt.cjs.map +2 -2
  24. package/build-module/entities.mjs +29 -20
  25. package/build-module/entities.mjs.map +2 -2
  26. package/build-module/hooks/index.mjs +6 -6
  27. package/build-module/hooks/index.mjs.map +2 -2
  28. package/build-module/hooks/use-entity-record.mjs +3 -3
  29. package/build-module/hooks/use-entity-record.mjs.map +2 -2
  30. package/build-module/hooks/use-entity-records.mjs +2 -2
  31. package/build-module/hooks/use-entity-records.mjs.map +2 -2
  32. package/build-module/hooks/use-query-select.mjs +1 -1
  33. package/build-module/hooks/use-query-select.mjs.map +1 -1
  34. package/build-module/hooks/use-resource-permissions.mjs +3 -3
  35. package/build-module/hooks/use-resource-permissions.mjs.map +2 -2
  36. package/build-module/queried-data/selectors.mjs +21 -17
  37. package/build-module/queried-data/selectors.mjs.map +2 -2
  38. package/build-module/resolvers.mjs +6 -6
  39. package/build-module/resolvers.mjs.map +2 -2
  40. package/build-module/selectors.mjs +4 -2
  41. package/build-module/selectors.mjs.map +2 -2
  42. package/build-module/utils/crdt-blocks.mjs +122 -30
  43. package/build-module/utils/crdt-blocks.mjs.map +2 -2
  44. package/build-module/utils/crdt.mjs +7 -0
  45. package/build-module/utils/crdt.mjs.map +2 -2
  46. package/build-types/entities.d.ts +51 -32
  47. package/build-types/entities.d.ts.map +1 -1
  48. package/build-types/hooks/index.d.ts +3 -3
  49. package/build-types/hooks/index.d.ts.map +1 -1
  50. package/build-types/hooks/use-entity-record.d.ts +1 -1
  51. package/build-types/hooks/use-entity-record.d.ts.map +1 -1
  52. package/build-types/hooks/use-entity-records.d.ts +1 -1
  53. package/build-types/hooks/use-entity-records.d.ts.map +1 -1
  54. package/build-types/hooks/use-resource-permissions.d.ts +1 -1
  55. package/build-types/hooks/use-resource-permissions.d.ts.map +1 -1
  56. package/build-types/index.d.ts.map +1 -1
  57. package/build-types/queried-data/selectors.d.ts +5 -3
  58. package/build-types/queried-data/selectors.d.ts.map +1 -1
  59. package/build-types/selectors.d.ts.map +1 -1
  60. package/build-types/utils/crdt-blocks.d.ts.map +1 -1
  61. package/build-types/utils/crdt.d.ts +7 -0
  62. package/build-types/utils/crdt.d.ts.map +1 -1
  63. package/package.json +18 -18
  64. package/src/entities.js +16 -8
  65. package/src/hooks/index.ts +3 -3
  66. package/src/hooks/test/use-entity-records.js +1 -1
  67. package/src/hooks/use-entity-record.ts +1 -1
  68. package/src/hooks/use-entity-records.ts +1 -1
  69. package/src/hooks/use-query-select.ts +1 -1
  70. package/src/hooks/use-resource-permissions.ts +1 -1
  71. package/src/queried-data/selectors.js +32 -26
  72. package/src/queried-data/test/selectors.js +30 -21
  73. package/src/resolvers.js +6 -6
  74. package/src/selectors.ts +8 -2
  75. package/src/utils/crdt-blocks.ts +268 -61
  76. package/src/utils/crdt.ts +15 -0
  77. package/src/utils/test/crdt-blocks.ts +785 -6
  78. package/src/utils/test/crdt.ts +39 -1
  79. package/build/hooks/memoize.cjs +0 -38
  80. package/build/hooks/memoize.cjs.map +0 -7
  81. package/build-module/hooks/memoize.mjs +0 -7
  82. package/build-module/hooks/memoize.mjs.map +0 -7
  83. package/build-types/hooks/memoize.d.ts +0 -3
  84. package/build-types/hooks/memoize.d.ts.map +0 -1
  85. package/src/hooks/memoize.js +0 -7
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/index.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { WithPermissions } from './use-entity-records';\n\n/**\n * Utility type that adds permissions to any record type.\n */\nexport type { WithPermissions };\nexport {\n\tdefault as useEntityRecord,\n\t__experimentalUseEntityRecord,\n} from './use-entity-record';\nexport {\n\tdefault as useEntityRecords,\n\t__experimentalUseEntityRecords,\n} from './use-entity-records';\nexport {\n\tdefault as useResourcePermissions,\n\t__experimentalUseResourcePermissions,\n} from './use-resource-permissions';\nexport { default as useEntityBlockEditor } from './use-entity-block-editor';\nexport { default as useEntityId } from './use-entity-id';\nexport { default as useEntityProp } from './use-entity-prop';\n"],
5
- "mappings": ";AASA;AAAA,EACY,WAAXA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACY,WAAXA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACY,WAAXA;AAAA,EACA;AAAA,OACM;AACP,SAAoB,WAAXA,gBAAuC;AAChD,SAAoB,WAAXA,gBAA8B;AACvC,SAAoB,WAAXA,gBAAgC;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { WithPermissions } from './use-entity-records';\n\n/**\n * Utility type that adds permissions to any record type.\n */\nexport type { WithPermissions };\nexport {\n\tdefault as useEntityRecord,\n\tuseDeprecatedEntityRecord as __experimentalUseEntityRecord,\n} from './use-entity-record';\nexport {\n\tdefault as useEntityRecords,\n\tuseDeprecatedEntityRecords as __experimentalUseEntityRecords,\n} from './use-entity-records';\nexport {\n\tdefault as useResourcePermissions,\n\tuseDeprecatedResourcePermissions as __experimentalUseResourcePermissions,\n} from './use-resource-permissions';\nexport { default as useEntityBlockEditor } from './use-entity-block-editor';\nexport { default as useEntityId } from './use-entity-id';\nexport { default as useEntityProp } from './use-entity-prop';\n"],
5
+ "mappings": ";AASA;AAAA,EACY,WAAXA;AAAA,EAC6B;AAAA,OACvB;AACP;AAAA,EACY,WAAXA;AAAA,EAC8B;AAAA,OACxB;AACP;AAAA,EACY,WAAXA;AAAA,EACoC;AAAA,OAC9B;AACP,SAAoB,WAAXA,gBAAuC;AAChD,SAAoB,WAAXA,gBAA8B;AACvC,SAAoB,WAAXA,gBAAgC;",
6
6
  "names": ["default"]
7
7
  }
@@ -66,7 +66,7 @@ function useEntityRecord(kind, name, recordId, options = { enabled: true }) {
66
66
  ...mutations
67
67
  };
68
68
  }
69
- function __experimentalUseEntityRecord(kind, name, recordId, options) {
69
+ function useDeprecatedEntityRecord(kind, name, recordId, options) {
70
70
  deprecated(`wp.data.__experimentalUseEntityRecord`, {
71
71
  alternative: "wp.data.useEntityRecord",
72
72
  since: "6.1"
@@ -74,7 +74,7 @@ function __experimentalUseEntityRecord(kind, name, recordId, options) {
74
74
  return useEntityRecord(kind, name, recordId, options);
75
75
  }
76
76
  export {
77
- __experimentalUseEntityRecord,
78
- useEntityRecord as default
77
+ useEntityRecord as default,
78
+ useDeprecatedEntityRecord
79
79
  };
80
80
  //# sourceMappingURL=use-entity-record.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/use-entity-record.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\nexport interface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/** The edited entity record */\n\teditedRecord: Partial< RecordType >;\n\n\t/** The edits to the edited entity record */\n\tedits: Partial< RecordType >;\n\n\t/** Apply local (in-browser) edits to the edited entity record */\n\tedit: ( diff: Partial< RecordType > ) => void;\n\n\t/** Persist the edits to the server */\n\tsave: () => Promise< void >;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Does the record have any local edits?\n\t */\n\thasEdits: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nexport interface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\nconst EMPTY_OBJECT = {};\n\n/**\n * Resolves the specified entity record.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param recordId ID of the requested entity record.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @example\n * ```js\n * import { useCallback } from 'react';\n * import { useDispatch } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n * import { TextControl } from '@wordpress/components';\n * import { store as noticeStore } from '@wordpress/notices';\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageRenameForm( { id } ) {\n * \tconst page = useEntityRecord( 'postType', 'page', id );\n * \tconst { createSuccessNotice, createErrorNotice } =\n * \t\tuseDispatch( noticeStore );\n *\n * \tconst setTitle = useCallback( ( title ) => {\n * \t\tpage.edit( { title } );\n * \t}, [ page.edit ] );\n *\n * \tif ( page.isResolving ) {\n * \t\treturn 'Loading...';\n * \t}\n *\n * \tasync function onRename( event ) {\n * \t\tevent.preventDefault();\n * \t\ttry {\n * \t\t\tawait page.save();\n * \t\t\tcreateSuccessNotice( __( 'Page renamed.' ), {\n * \t\t\t\ttype: 'snackbar',\n * \t\t\t} );\n * \t\t} catch ( error ) {\n * \t\t\tcreateErrorNotice( error.message, { type: 'snackbar' } );\n * \t\t}\n * \t}\n *\n * \treturn (\n * \t\t<form onSubmit={ onRename }>\n * \t\t\t<TextControl\n *\t\t\t\t__next40pxDefaultSize\n * \t\t\t\tlabel={ __( 'Name' ) }\n * \t\t\t\tvalue={ page.editedRecord.title }\n * \t\t\t\tonChange={ setTitle }\n * \t\t\t/>\n * \t\t\t<button type=\"submit\">{ __( 'Save' ) }</button>\n * \t\t</form>\n * \t);\n * }\n *\n * // Rendered in the application:\n * // <PageRenameForm id={ 1 } />\n * ```\n *\n * In the above example, updating and saving the page title is handled\n * via the `edit()` and `save()` mutation helpers provided by\n * `useEntityRecord()`;\n *\n * @return Entity record data.\n * @template RecordType\n */\nexport default function useEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\n\tconst mutations = useMemo(\n\t\t() => ( {\n\t\t\tedit: ( record, editOptions: any = {} ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record, editOptions ),\n\t\t\tsave: ( saveOptions: any = {} ) =>\n\t\t\t\tsaveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t...saveOptions,\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ editEntityRecord, kind, name, recordId, saveEditedEntityRecord ]\n\t);\n\n\tconst { editedRecord, hasEdits, edits } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\teditedRecord: EMPTY_OBJECT,\n\t\t\t\t\thasEdits: false,\n\t\t\t\t\tedits: EMPTY_OBJECT,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t\tedits: select( coreStore ).getEntityRecordNonTransientEdits(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\tdata: null,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\teditedRecord,\n\t\thasEdits,\n\t\tedits,\n\t\t...querySelectRest,\n\t\t...mutations,\n\t};\n}\n\nexport function __experimentalUseEntityRecord(\n\tkind: string,\n\tname: string,\n\trecordId: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecord`, {\n\t\talternative: 'wp.data.useEntityRecord',\n\t\tsince: '6.1',\n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AE,UAAW;AACZ,UAAK,CAAE,QAAQ,SAAU;AACxB,eAAO;AAAA,UACN,MAAM;AAAA,QACP;AAAA,MACD;AACA,aAAO,MAAO,SAAU,EAAE,gBAAiB,MAAM,MAAM,QAAS;AAAA,IACjE;AAAA,IACA,CAAE,MAAM,MAAM,UAAU,QAAQ,OAAQ;AAAA,EACzC;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,IACH,GAAG;AAAA,EACJ;AACD;AAEO,SAAS,8BACf,MACA,MACA,UACA,SACC;AACD,aAAY,yCAAyC;AAAA,IACpD,aAAa;AAAA,IACb,OAAO;AAAA,EACR,CAAE;AACF,SAAO,gBAAiB,MAAM,MAAM,UAAU,OAAQ;AACvD;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\nexport interface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/** The edited entity record */\n\teditedRecord: Partial< RecordType >;\n\n\t/** The edits to the edited entity record */\n\tedits: Partial< RecordType >;\n\n\t/** Apply local (in-browser) edits to the edited entity record */\n\tedit: ( diff: Partial< RecordType > ) => void;\n\n\t/** Persist the edits to the server */\n\tsave: () => Promise< void >;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Does the record have any local edits?\n\t */\n\thasEdits: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nexport interface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\nconst EMPTY_OBJECT = {};\n\n/**\n * Resolves the specified entity record.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param recordId ID of the requested entity record.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @example\n * ```js\n * import { useCallback } from 'react';\n * import { useDispatch } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n * import { TextControl } from '@wordpress/components';\n * import { store as noticeStore } from '@wordpress/notices';\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageRenameForm( { id } ) {\n * \tconst page = useEntityRecord( 'postType', 'page', id );\n * \tconst { createSuccessNotice, createErrorNotice } =\n * \t\tuseDispatch( noticeStore );\n *\n * \tconst setTitle = useCallback( ( title ) => {\n * \t\tpage.edit( { title } );\n * \t}, [ page.edit ] );\n *\n * \tif ( page.isResolving ) {\n * \t\treturn 'Loading...';\n * \t}\n *\n * \tasync function onRename( event ) {\n * \t\tevent.preventDefault();\n * \t\ttry {\n * \t\t\tawait page.save();\n * \t\t\tcreateSuccessNotice( __( 'Page renamed.' ), {\n * \t\t\t\ttype: 'snackbar',\n * \t\t\t} );\n * \t\t} catch ( error ) {\n * \t\t\tcreateErrorNotice( error.message, { type: 'snackbar' } );\n * \t\t}\n * \t}\n *\n * \treturn (\n * \t\t<form onSubmit={ onRename }>\n * \t\t\t<TextControl\n *\t\t\t\t__next40pxDefaultSize\n * \t\t\t\tlabel={ __( 'Name' ) }\n * \t\t\t\tvalue={ page.editedRecord.title }\n * \t\t\t\tonChange={ setTitle }\n * \t\t\t/>\n * \t\t\t<button type=\"submit\">{ __( 'Save' ) }</button>\n * \t\t</form>\n * \t);\n * }\n *\n * // Rendered in the application:\n * // <PageRenameForm id={ 1 } />\n * ```\n *\n * In the above example, updating and saving the page title is handled\n * via the `edit()` and `save()` mutation helpers provided by\n * `useEntityRecord()`;\n *\n * @return Entity record data.\n * @template RecordType\n */\nexport default function useEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\n\tconst mutations = useMemo(\n\t\t() => ( {\n\t\t\tedit: ( record, editOptions: any = {} ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record, editOptions ),\n\t\t\tsave: ( saveOptions: any = {} ) =>\n\t\t\t\tsaveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t...saveOptions,\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ editEntityRecord, kind, name, recordId, saveEditedEntityRecord ]\n\t);\n\n\tconst { editedRecord, hasEdits, edits } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\teditedRecord: EMPTY_OBJECT,\n\t\t\t\t\thasEdits: false,\n\t\t\t\t\tedits: EMPTY_OBJECT,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t\tedits: select( coreStore ).getEntityRecordNonTransientEdits(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\tdata: null,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\teditedRecord,\n\t\thasEdits,\n\t\tedits,\n\t\t...querySelectRest,\n\t\t...mutations,\n\t};\n}\n\nexport function useDeprecatedEntityRecord(\n\tkind: string,\n\tname: string,\n\trecordId: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecord`, {\n\t\talternative: 'wp.data.useEntityRecord',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecord( kind, name, recordId, options );\n}\n"],
5
+ "mappings": ";AAGA,SAAS,aAAa,iBAAiB;AACvC,OAAO,gBAAgB;AACvB,SAAS,eAAe;AAKxB,OAAO,oBAAoB;AAC3B,SAAS,SAAS,iBAAiB;AA+CnC,IAAM,eAAe,CAAC;AA2FP,SAAR,gBACN,MACA,MACA,UACA,UAAmB,EAAE,SAAS,KAAK,GACI;AACvC,QAAM,EAAE,kBAAkB,uBAAuB,IAChD,YAAa,SAAU;AAExB,QAAM,YAAY;AAAA,IACjB,OAAQ;AAAA,MACP,MAAM,CAAEA,SAAQ,cAAmB,CAAC,MACnC,iBAAkB,MAAM,MAAM,UAAUA,SAAQ,WAAY;AAAA,MAC7D,MAAM,CAAE,cAAmB,CAAC,MAC3B,uBAAwB,MAAM,MAAM,UAAU;AAAA,QAC7C,cAAc;AAAA,QACd,GAAG;AAAA,MACJ,CAAE;AAAA,IACJ;AAAA,IACA,CAAE,kBAAkB,MAAM,MAAM,UAAU,sBAAuB;AAAA,EAClE;AAEA,QAAM,EAAE,cAAc,UAAU,MAAM,IAAI;AAAA,IACzC,CAAE,WAAY;AACb,UAAK,CAAE,QAAQ,SAAU;AACxB,eAAO;AAAA,UACN,cAAc;AAAA,UACd,UAAU;AAAA,UACV,OAAO;AAAA,QACR;AAAA,MACD;AAEA,aAAO;AAAA,QACN,cAAc,OAAQ,SAAU,EAAE;AAAA,UACjC;AAAA,UACA;AAAA,UACA;AAAA,QACD;AAAA,QACA,UAAU,OAAQ,SAAU,EAAE;AAAA,UAC7B;AAAA,UACA;AAAA,UACA;AAAA,QACD;AAAA,QACA,OAAO,OAAQ,SAAU,EAAE;AAAA,UAC1B;AAAA,UACA;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,MAAM,MAAM,UAAU,QAAQ,OAAQ;AAAA,EACzC;AAEA,QAAM,EAAE,MAAM,QAAQ,GAAG,gBAAgB,IAAI;AAAA,IAC5C,CAAE,UAAW;AACZ,UAAK,CAAE,QAAQ,SAAU;AACxB,eAAO;AAAA,UACN,MAAM;AAAA,QACP;AAAA,MACD;AACA,aAAO,MAAO,SAAU,EAAE,gBAAiB,MAAM,MAAM,QAAS;AAAA,IACjE;AAAA,IACA,CAAE,MAAM,MAAM,UAAU,QAAQ,OAAQ;AAAA,EACzC;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,IACH,GAAG;AAAA,EACJ;AACD;AAEO,SAAS,0BACf,MACA,MACA,UACA,SACC;AACD,aAAY,yCAAyC;AAAA,IACpD,aAAa;AAAA,IACb,OAAO;AAAA,EACR,CAAE;AACF,SAAO,gBAAiB,MAAM,MAAM,UAAU,OAAQ;AACvD;",
6
6
  "names": ["record"]
7
7
  }
@@ -52,7 +52,7 @@ function useEntityRecords(kind, name, queryArgs = {}, options = { enabled: true
52
52
  ...rest
53
53
  };
54
54
  }
55
- function __experimentalUseEntityRecords(kind, name, queryArgs, options) {
55
+ function useDeprecatedEntityRecords(kind, name, queryArgs, options) {
56
56
  deprecated(`wp.data.__experimentalUseEntityRecords`, {
57
57
  alternative: "wp.data.useEntityRecords",
58
58
  since: "6.1"
@@ -110,8 +110,8 @@ function useEntityRecordsWithPermissions(kind, name, queryArgs = {}, options = {
110
110
  return { records: dataWithPermissions, ...ret };
111
111
  }
112
112
  export {
113
- __experimentalUseEntityRecords,
114
113
  useEntityRecords as default,
114
+ useDeprecatedEntityRecords,
115
115
  useEntityRecordsWithPermissions
116
116
  };
117
117
  //# sourceMappingURL=use-entity-records.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/use-entity-records.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport deprecated from '@wordpress/deprecated';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Options } from './use-entity-record';\nimport type { Status } from './constants';\nimport { unlock } from '../lock-unlock';\nimport { getNormalizedCommaSeparable } from '../utils';\n\ninterface EntityRecordsResolution< RecordType > {\n\t/** The requested entity records */\n\trecords: RecordType[] | null;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n\n\t/**\n\t * The total number of available items (if not paginated).\n\t */\n\ttotalItems: number | null;\n\n\t/**\n\t * The total number of pages.\n\t */\n\ttotalPages: number | null;\n}\n\nexport type WithPermissions< RecordType > = RecordType & {\n\tpermissions: { delete: boolean; update: boolean };\n};\n\ninterface EntityRecordsWithPermissionsResolution< RecordType >\n\textends Omit< EntityRecordsResolution< RecordType >, 'records' > {\n\t/** The requested entity records with permissions */\n\trecords: WithPermissions< RecordType >[] | null;\n}\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Resolves the specified entity records.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecords } from '@wordpress/core-data';\n *\n * function PageTitlesList() {\n * const { records, isResolving } = useEntityRecords( 'postType', 'page' );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return (\n * <ul>\n * {records.map(( page ) => (\n * <li>{ page.title }</li>\n * ))}\n * </ul>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PageTitlesList />\n * ```\n *\n * In the above example, when `PageTitlesList` is rendered into an\n * application, the list of records and the resolution details will be retrieved from\n * the store state using `getEntityRecords()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template RecordType\n */\nexport default function useEntityRecords< RecordType >(\n\tkind: string,\n\tname: string,\n\tqueryArgs: Record< string, unknown > = {},\n\toptions: Options = { enabled: true }\n): EntityRecordsResolution< RecordType > {\n\t// Serialize queryArgs to a string that can be safely used as a React dep.\n\t// We can't just pass queryArgs as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst queryAsString = addQueryArgs( '', queryArgs );\n\n\tconst { data: records, ...rest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\t// Avoiding returning a new reference on every execution.\n\t\t\t\t\tdata: EMPTY_ARRAY,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecords( kind, name, queryArgs );\n\t\t},\n\t\t[ kind, name, queryAsString, options.enabled ]\n\t);\n\n\tconst { totalItems, totalPages } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\ttotalItems: null,\n\t\t\t\t\ttotalPages: null,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\ttotalItems: select( coreStore ).getEntityRecordsTotalItems(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tqueryArgs\n\t\t\t\t),\n\t\t\t\ttotalPages: select( coreStore ).getEntityRecordsTotalPages(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tqueryArgs\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ kind, name, queryAsString, options.enabled ]\n\t);\n\n\treturn {\n\t\trecords,\n\t\ttotalItems,\n\t\ttotalPages,\n\t\t...rest,\n\t};\n}\n\nexport function __experimentalUseEntityRecords(\n\tkind: string,\n\tname: string,\n\tqueryArgs: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecords`, {\n\t\talternative: 'wp.data.useEntityRecords',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecords( kind, name, queryArgs, options );\n}\n\nexport function useEntityRecordsWithPermissions< RecordType >(\n\tkind: string,\n\tname: string,\n\tqueryArgs: Record< string, unknown > = {},\n\toptions: Options = { enabled: true }\n): EntityRecordsWithPermissionsResolution< RecordType > {\n\tconst entityConfig = useSelect(\n\t\t( select ) => select( coreStore ).getEntityConfig( kind, name ),\n\t\t[ kind, name ]\n\t);\n\tconst { records: data, ...ret } = useEntityRecords(\n\t\tkind,\n\t\tname,\n\t\t{\n\t\t\t...queryArgs,\n\t\t\t// If _fields is provided, we need to include _links in the request for permission caching to work.\n\t\t\t...( queryArgs._fields\n\t\t\t\t? {\n\t\t\t\t\t\t_fields: [\n\t\t\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t\t\t...( getNormalizedCommaSeparable(\n\t\t\t\t\t\t\t\t\tqueryArgs._fields\n\t\t\t\t\t\t\t\t) || [] ),\n\t\t\t\t\t\t\t\t'_links',\n\t\t\t\t\t\t\t] ),\n\t\t\t\t\t\t].join(),\n\t\t\t\t }\n\t\t\t\t: {} ),\n\t\t},\n\t\toptions\n\t);\n\tconst ids = useMemo(\n\t\t() =>\n\t\t\tdata?.map(\n\t\t\t\t// @ts-ignore\n\t\t\t\t( record: RecordType ) => record[ entityConfig?.key ?? 'id' ]\n\t\t\t) ?? [],\n\t\t[ data, entityConfig?.key ]\n\t);\n\n\tconst permissions = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecordsPermissions } = unlock(\n\t\t\t\tselect( coreStore )\n\t\t\t);\n\t\t\treturn getEntityRecordsPermissions( kind, name, ids );\n\t\t},\n\t\t[ ids, kind, name ]\n\t);\n\n\tconst dataWithPermissions = useMemo(\n\t\t() =>\n\t\t\tdata?.map( ( record, index ) => ( {\n\t\t\t\t// @ts-ignore\n\t\t\t\t...record,\n\t\t\t\tpermissions: permissions[ index ],\n\t\t\t} ) ) ?? [],\n\t\t[ data, permissions ]\n\t);\n\n\treturn { records: dataWithPermissions, ...ret };\n}\n"],
5
- "mappings": ";AAGA,SAAS,oBAAoB;AAC7B,OAAO,gBAAgB;AACvB,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AAKxB,OAAO,oBAAoB;AAC3B,SAAS,SAAS,iBAAiB;AAGnC,SAAS,cAAc;AACvB,SAAS,mCAAmC;AAwC5C,IAAM,cAAc,CAAC;AA0CN,SAAR,iBACN,MACA,MACA,YAAuC,CAAC,GACxC,UAAmB,EAAE,SAAS,KAAK,GACK;AAKxC,QAAM,gBAAgB,aAAc,IAAI,SAAU;AAElD,QAAM,EAAE,MAAM,SAAS,GAAG,KAAK,IAAI;AAAA,IAClC,CAAE,UAAW;AACZ,UAAK,CAAE,QAAQ,SAAU;AACxB,eAAO;AAAA;AAAA,UAEN,MAAM;AAAA,QACP;AAAA,MACD;AACA,aAAO,MAAO,SAAU,EA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,QACH,EAAE,KAAK;AAAA,MACP,IACA,CAAC;AAAA,IACL;AAAA,IACA;AAAA,EACD;AACA,QAAM,MAAM;AAAA,IACX,MACC,MAAM;AAAA;AAAA,MAEL,CAAE,WAAwB,OAAQ,cAAc,OAAO,IAAK;AAAA,IAC7D,KAAK,CAAC;AAAA,IACP,CAAE,MAAM,cAAc,GAAI;AAAA,EAC3B;AAEA,QAAM,cAAc;AAAA,IACnB,CAAE,WAAY;AACb,YAAM,EAAE,4BAA4B,IAAI;AAAA,QACvC,OAAQ,SAAU;AAAA,MACnB;AACA,aAAO,4BAA6B,MAAM,MAAM,GAAI;AAAA,IACrD;AAAA,IACA,CAAE,KAAK,MAAM,IAAK;AAAA,EACnB;AAEA,QAAM,sBAAsB;AAAA,IAC3B,MACC,MAAM,IAAK,CAAE,QAAQ,WAAa;AAAA;AAAA,MAEjC,GAAG;AAAA,MACH,aAAa,YAAa,KAAM;AAAA,IACjC,EAAI,KAAK,CAAC;AAAA,IACX,CAAE,MAAM,WAAY;AAAA,EACrB;AAEA,SAAO,EAAE,SAAS,qBAAqB,GAAG,IAAI;AAC/C;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport deprecated from '@wordpress/deprecated';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Options } from './use-entity-record';\nimport type { Status } from './constants';\nimport { unlock } from '../lock-unlock';\nimport { getNormalizedCommaSeparable } from '../utils';\n\ninterface EntityRecordsResolution< RecordType > {\n\t/** The requested entity records */\n\trecords: RecordType[] | null;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n\n\t/**\n\t * The total number of available items (if not paginated).\n\t */\n\ttotalItems: number | null;\n\n\t/**\n\t * The total number of pages.\n\t */\n\ttotalPages: number | null;\n}\n\nexport type WithPermissions< RecordType > = RecordType & {\n\tpermissions: { delete: boolean; update: boolean };\n};\n\ninterface EntityRecordsWithPermissionsResolution< RecordType >\n\textends Omit< EntityRecordsResolution< RecordType >, 'records' > {\n\t/** The requested entity records with permissions */\n\trecords: WithPermissions< RecordType >[] | null;\n}\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Resolves the specified entity records.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecords } from '@wordpress/core-data';\n *\n * function PageTitlesList() {\n * const { records, isResolving } = useEntityRecords( 'postType', 'page' );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return (\n * <ul>\n * {records.map(( page ) => (\n * <li>{ page.title }</li>\n * ))}\n * </ul>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PageTitlesList />\n * ```\n *\n * In the above example, when `PageTitlesList` is rendered into an\n * application, the list of records and the resolution details will be retrieved from\n * the store state using `getEntityRecords()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template RecordType\n */\nexport default function useEntityRecords< RecordType >(\n\tkind: string,\n\tname: string,\n\tqueryArgs: Record< string, unknown > = {},\n\toptions: Options = { enabled: true }\n): EntityRecordsResolution< RecordType > {\n\t// Serialize queryArgs to a string that can be safely used as a React dep.\n\t// We can't just pass queryArgs as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst queryAsString = addQueryArgs( '', queryArgs );\n\n\tconst { data: records, ...rest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\t// Avoiding returning a new reference on every execution.\n\t\t\t\t\tdata: EMPTY_ARRAY,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecords( kind, name, queryArgs );\n\t\t},\n\t\t[ kind, name, queryAsString, options.enabled ]\n\t);\n\n\tconst { totalItems, totalPages } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\ttotalItems: null,\n\t\t\t\t\ttotalPages: null,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\ttotalItems: select( coreStore ).getEntityRecordsTotalItems(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tqueryArgs\n\t\t\t\t),\n\t\t\t\ttotalPages: select( coreStore ).getEntityRecordsTotalPages(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tqueryArgs\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ kind, name, queryAsString, options.enabled ]\n\t);\n\n\treturn {\n\t\trecords,\n\t\ttotalItems,\n\t\ttotalPages,\n\t\t...rest,\n\t};\n}\n\nexport function useDeprecatedEntityRecords(\n\tkind: string,\n\tname: string,\n\tqueryArgs: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecords`, {\n\t\talternative: 'wp.data.useEntityRecords',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecords( kind, name, queryArgs, options );\n}\n\nexport function useEntityRecordsWithPermissions< RecordType >(\n\tkind: string,\n\tname: string,\n\tqueryArgs: Record< string, unknown > = {},\n\toptions: Options = { enabled: true }\n): EntityRecordsWithPermissionsResolution< RecordType > {\n\tconst entityConfig = useSelect(\n\t\t( select ) => select( coreStore ).getEntityConfig( kind, name ),\n\t\t[ kind, name ]\n\t);\n\tconst { records: data, ...ret } = useEntityRecords(\n\t\tkind,\n\t\tname,\n\t\t{\n\t\t\t...queryArgs,\n\t\t\t// If _fields is provided, we need to include _links in the request for permission caching to work.\n\t\t\t...( queryArgs._fields\n\t\t\t\t? {\n\t\t\t\t\t\t_fields: [\n\t\t\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t\t\t...( getNormalizedCommaSeparable(\n\t\t\t\t\t\t\t\t\tqueryArgs._fields\n\t\t\t\t\t\t\t\t) || [] ),\n\t\t\t\t\t\t\t\t'_links',\n\t\t\t\t\t\t\t] ),\n\t\t\t\t\t\t].join(),\n\t\t\t\t }\n\t\t\t\t: {} ),\n\t\t},\n\t\toptions\n\t);\n\tconst ids = useMemo(\n\t\t() =>\n\t\t\tdata?.map(\n\t\t\t\t// @ts-ignore\n\t\t\t\t( record: RecordType ) => record[ entityConfig?.key ?? 'id' ]\n\t\t\t) ?? [],\n\t\t[ data, entityConfig?.key ]\n\t);\n\n\tconst permissions = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecordsPermissions } = unlock(\n\t\t\t\tselect( coreStore )\n\t\t\t);\n\t\t\treturn getEntityRecordsPermissions( kind, name, ids );\n\t\t},\n\t\t[ ids, kind, name ]\n\t);\n\n\tconst dataWithPermissions = useMemo(\n\t\t() =>\n\t\t\tdata?.map( ( record, index ) => ( {\n\t\t\t\t// @ts-ignore\n\t\t\t\t...record,\n\t\t\t\tpermissions: permissions[ index ],\n\t\t\t} ) ) ?? [],\n\t\t[ data, permissions ]\n\t);\n\n\treturn { records: dataWithPermissions, ...ret };\n}\n"],
5
+ "mappings": ";AAGA,SAAS,oBAAoB;AAC7B,OAAO,gBAAgB;AACvB,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AAKxB,OAAO,oBAAoB;AAC3B,SAAS,SAAS,iBAAiB;AAGnC,SAAS,cAAc;AACvB,SAAS,mCAAmC;AAwC5C,IAAM,cAAc,CAAC;AA0CN,SAAR,iBACN,MACA,MACA,YAAuC,CAAC,GACxC,UAAmB,EAAE,SAAS,KAAK,GACK;AAKxC,QAAM,gBAAgB,aAAc,IAAI,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A;AAAA,MACC,GAAG;AAAA;AAAA,MAEH,GAAK,UAAU,UACZ;AAAA,QACA,SAAS;AAAA,UACR,GAAG,oBAAI,IAAK;AAAA,YACX,GAAK;AAAA,cACJ,UAAU;AAAA,YACX,KAAK,CAAC;AAAA,YACN;AAAA,UACD,CAAE;AAAA,QACH,EAAE,KAAK;AAAA,MACP,IACA,CAAC;AAAA,IACL;AAAA,IACA;AAAA,EACD;AACA,QAAM,MAAM;AAAA,IACX,MACC,MAAM;AAAA;AAAA,MAEL,CAAE,WAAwB,OAAQ,cAAc,OAAO,IAAK;AAAA,IAC7D,KAAK,CAAC;AAAA,IACP,CAAE,MAAM,cAAc,GAAI;AAAA,EAC3B;AAEA,QAAM,cAAc;AAAA,IACnB,CAAE,WAAY;AACb,YAAM,EAAE,4BAA4B,IAAI;AAAA,QACvC,OAAQ,SAAU;AAAA,MACnB;AACA,aAAO,4BAA6B,MAAM,MAAM,GAAI;AAAA,IACrD;AAAA,IACA,CAAE,KAAK,MAAM,IAAK;AAAA,EACnB;AAEA,QAAM,sBAAsB;AAAA,IAC3B,MACC,MAAM,IAAK,CAAE,QAAQ,WAAa;AAAA;AAAA,MAEjC,GAAG;AAAA,MACH,aAAa,YAAa,KAAM;AAAA,IACjC,EAAI,KAAK,CAAC;AAAA,IACX,CAAE,MAAM,WAAY;AAAA,EACrB;AAEA,SAAO,EAAE,SAAS,qBAAqB,GAAG,IAAI;AAC/C;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,6 @@
1
1
  // packages/core-data/src/hooks/use-query-select.ts
2
2
  import { useSelect } from "@wordpress/data";
3
- import memoize from "./memoize.mjs";
3
+ import memoize from "memize";
4
4
  import { Status } from "./constants.mjs";
5
5
  var META_SELECTORS = [
6
6
  "getIsResolving",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/use-query-select.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport memoize from './memoize';\nimport { Status } from './constants';\n\nexport const META_SELECTORS = [\n\t'getIsResolving',\n\t'hasStartedResolution',\n\t'hasFinishedResolution',\n\t'isResolving',\n\t'getCachedResolvers',\n];\n\ninterface QuerySelectResponse< Data > {\n\t/** the requested selector return value */\n\tdata: Data;\n\n\t/** is the record still being resolved? Via the `isResolving` meta-selector */\n\tisResolving: boolean;\n\n\t/** was the resolution started? Via the `hasStartedResolution` meta-selector */\n\thasStarted: boolean;\n\n\t/** has the resolution finished? Via the `hasFinishedResolution` meta-selector. */\n\thasResolved: boolean;\n}\n\n/**\n * Like useSelect, but the selectors return objects containing\n * both the original data AND the resolution info.\n *\n * @since 6.1.0 Introduced in WordPress core.\n * @private\n *\n * @param {Function} mapQuerySelect see useSelect\n * @param {Array} deps see useSelect\n *\n * @example\n * ```js\n * import { useQuerySelect } from '@wordpress/data';\n * import { store as coreDataStore } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { data: page, isResolving } = useQuerySelect( ( query ) => {\n * return query( coreDataStore ).getEntityRecord( 'postType', 'page', id )\n * }, [ id ] );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return page.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 10 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using the `mapSelect` callback on `useQuerySelect`.\n *\n * If the id prop changes then any page in the state for that id is\n * retrieved. If the id prop doesn't change and other props are passed in\n * that do change, the title will not change because the dependency is just\n * the id.\n * @see useSelect\n *\n * @return {QuerySelectResponse} Queried data.\n */\nexport default function useQuerySelect( mapQuerySelect, deps ) {\n\treturn useSelect( ( select, registry ) => {\n\t\tconst resolve = ( store ) => enrichSelectors( select( store ) );\n\t\treturn mapQuerySelect( resolve, registry );\n\t}, deps );\n}\n\ninterface EnrichedSelectors {\n\t< Selectors extends Record< string, ( ...args: any[] ) => any > >(\n\t\tselectors: Selectors\n\t): {\n\t\t[ Selector in keyof Selectors ]: (\n\t\t\t...args: Parameters< Selectors[ Selector ] >\n\t\t) => QuerySelectResponse< ReturnType< Selectors[ Selector ] > >;\n\t};\n}\n\n/**\n * Transform simple selectors into ones that return an object with the\n * original return value AND the resolution info.\n *\n * @param {Object} selectors Selectors to enrich\n * @return {EnrichedSelectors} Enriched selectors\n */\nconst enrichSelectors = memoize( ( ( selectors ) => {\n\tconst resolvers = {};\n\tfor ( const selectorName in selectors ) {\n\t\tif ( META_SELECTORS.includes( selectorName ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tObject.defineProperty( resolvers, selectorName, {\n\t\t\tget:\n\t\t\t\t() =>\n\t\t\t\t( ...args: unknown[] ) => {\n\t\t\t\t\tconst data = selectors[ selectorName ]( ...args );\n\t\t\t\t\tconst resolutionStatus = selectors.getResolutionState(\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t)?.status;\n\n\t\t\t\t\tlet status;\n\t\t\t\t\tswitch ( resolutionStatus ) {\n\t\t\t\t\t\tcase 'resolving':\n\t\t\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 'finished':\n\t\t\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 'error':\n\t\t\t\t\t\t\tstatus = Status.Error;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase undefined:\n\t\t\t\t\t\t\tstatus = Status.Idle;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t\tisResolving: status === Status.Resolving,\n\t\t\t\t\t\thasStarted: status !== Status.Idle,\n\t\t\t\t\t\thasResolved:\n\t\t\t\t\t\t\tstatus === Status.Success ||\n\t\t\t\t\t\t\tstatus === Status.Error,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t} );\n\t}\n\treturn resolvers;\n} ) as EnrichedSelectors );\n"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport memoize from 'memize';\nimport { Status } from './constants';\n\nexport const META_SELECTORS = [\n\t'getIsResolving',\n\t'hasStartedResolution',\n\t'hasFinishedResolution',\n\t'isResolving',\n\t'getCachedResolvers',\n];\n\ninterface QuerySelectResponse< Data > {\n\t/** the requested selector return value */\n\tdata: Data;\n\n\t/** is the record still being resolved? Via the `isResolving` meta-selector */\n\tisResolving: boolean;\n\n\t/** was the resolution started? Via the `hasStartedResolution` meta-selector */\n\thasStarted: boolean;\n\n\t/** has the resolution finished? Via the `hasFinishedResolution` meta-selector. */\n\thasResolved: boolean;\n}\n\n/**\n * Like useSelect, but the selectors return objects containing\n * both the original data AND the resolution info.\n *\n * @since 6.1.0 Introduced in WordPress core.\n * @private\n *\n * @param {Function} mapQuerySelect see useSelect\n * @param {Array} deps see useSelect\n *\n * @example\n * ```js\n * import { useQuerySelect } from '@wordpress/data';\n * import { store as coreDataStore } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { data: page, isResolving } = useQuerySelect( ( query ) => {\n * return query( coreDataStore ).getEntityRecord( 'postType', 'page', id )\n * }, [ id ] );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return page.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 10 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using the `mapSelect` callback on `useQuerySelect`.\n *\n * If the id prop changes then any page in the state for that id is\n * retrieved. If the id prop doesn't change and other props are passed in\n * that do change, the title will not change because the dependency is just\n * the id.\n * @see useSelect\n *\n * @return {QuerySelectResponse} Queried data.\n */\nexport default function useQuerySelect( mapQuerySelect, deps ) {\n\treturn useSelect( ( select, registry ) => {\n\t\tconst resolve = ( store ) => enrichSelectors( select( store ) );\n\t\treturn mapQuerySelect( resolve, registry );\n\t}, deps );\n}\n\ninterface EnrichedSelectors {\n\t< Selectors extends Record< string, ( ...args: any[] ) => any > >(\n\t\tselectors: Selectors\n\t): {\n\t\t[ Selector in keyof Selectors ]: (\n\t\t\t...args: Parameters< Selectors[ Selector ] >\n\t\t) => QuerySelectResponse< ReturnType< Selectors[ Selector ] > >;\n\t};\n}\n\n/**\n * Transform simple selectors into ones that return an object with the\n * original return value AND the resolution info.\n *\n * @param {Object} selectors Selectors to enrich\n * @return {EnrichedSelectors} Enriched selectors\n */\nconst enrichSelectors = memoize( ( ( selectors ) => {\n\tconst resolvers = {};\n\tfor ( const selectorName in selectors ) {\n\t\tif ( META_SELECTORS.includes( selectorName ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tObject.defineProperty( resolvers, selectorName, {\n\t\t\tget:\n\t\t\t\t() =>\n\t\t\t\t( ...args: unknown[] ) => {\n\t\t\t\t\tconst data = selectors[ selectorName ]( ...args );\n\t\t\t\t\tconst resolutionStatus = selectors.getResolutionState(\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t)?.status;\n\n\t\t\t\t\tlet status;\n\t\t\t\t\tswitch ( resolutionStatus ) {\n\t\t\t\t\t\tcase 'resolving':\n\t\t\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 'finished':\n\t\t\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 'error':\n\t\t\t\t\t\t\tstatus = Status.Error;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase undefined:\n\t\t\t\t\t\t\tstatus = Status.Idle;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t\tisResolving: status === Status.Resolving,\n\t\t\t\t\t\thasStarted: status !== Status.Idle,\n\t\t\t\t\t\thasResolved:\n\t\t\t\t\t\t\tstatus === Status.Success ||\n\t\t\t\t\t\t\tstatus === Status.Error,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t} );\n\t}\n\treturn resolvers;\n} ) as EnrichedSelectors );\n"],
5
5
  "mappings": ";AAGA,SAAS,iBAAiB;AAK1B,OAAO,aAAa;AACpB,SAAS,cAAc;AAEhB,IAAM,iBAAiB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AA2De,SAAR,eAAiC,gBAAgB,MAAO;AAC9D,SAAO,UAAW,CAAE,QAAQ,aAAc;AACzC,UAAM,UAAU,CAAE,UAAW,gBAAiB,OAAQ,KAAM,CAAE;AAC9D,WAAO,eAAgB,SAAS,QAAS;AAAA,EAC1C,GAAG,IAAK;AACT;AAmBA,IAAM,kBAAkB,SAAW,CAAE,cAAe;AACnD,QAAM,YAAY,CAAC;AACnB,aAAY,gBAAgB,WAAY;AACvC,QAAK,eAAe,SAAU,YAAa,GAAI;AAC9C;AAAA,IACD;AACA,WAAO,eAAgB,WAAW,cAAc;AAAA,MAC/C,KACC,MACA,IAAK,SAAqB;AACzB,cAAM,OAAO,UAAW,YAAa,EAAG,GAAG,IAAK;AAChD,cAAM,mBAAmB,UAAU;AAAA,UAClC;AAAA,UACA;AAAA,QACD,GAAG;AAEH,YAAI;AACJ,gBAAS,kBAAmB;AAAA,UAC3B,KAAK;AACJ,qBAAS,OAAO;AAChB;AAAA,UACD,KAAK;AACJ,qBAAS,OAAO;AAChB;AAAA,UACD,KAAK;AACJ,qBAAS,OAAO;AAChB;AAAA,UACD,KAAK;AACJ,qBAAS,OAAO;AAChB;AAAA,QACF;AAEA,eAAO;AAAA,UACN;AAAA,UACA;AAAA,UACA,aAAa,WAAW,OAAO;AAAA,UAC/B,YAAY,WAAW,OAAO;AAAA,UAC9B,aACC,WAAW,OAAO,WAClB,WAAW,OAAO;AAAA,QACpB;AAAA,MACD;AAAA,IACF,CAAE;AAAA,EACH;AACA,SAAO;AACR,EAAyB;",
6
6
  "names": []
7
7
  }
@@ -63,7 +63,7 @@ function useResourcePermissions(resource, id) {
63
63
  );
64
64
  }
65
65
  var use_resource_permissions_default = useResourcePermissions;
66
- function __experimentalUseResourcePermissions(resource, id) {
66
+ function useDeprecatedResourcePermissions(resource, id) {
67
67
  deprecated(`wp.data.__experimentalUseResourcePermissions`, {
68
68
  alternative: "wp.data.useResourcePermissions",
69
69
  since: "6.1"
@@ -71,7 +71,7 @@ function __experimentalUseResourcePermissions(resource, id) {
71
71
  return useResourcePermissions(resource, id);
72
72
  }
73
73
  export {
74
- __experimentalUseResourcePermissions,
75
- use_resource_permissions_default as default
74
+ use_resource_permissions_default as default,
75
+ useDeprecatedResourcePermissions
76
76
  };
77
77
  //# sourceMappingURL=use-resource-permissions.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/use-resource-permissions.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\nimport useQuerySelect from './use-query-select';\n\ninterface GlobalResourcePermissionsResolution {\n\t/** Can the current user create new resources of this type? */\n\tcanCreate: boolean;\n}\ninterface SpecificResourcePermissionsResolution {\n\t/** Can the current user update resources of this type? */\n\tcanUpdate: boolean;\n\t/** Can the current user delete resources of this type? */\n\tcanDelete: boolean;\n}\ninterface ResolutionDetails {\n\t/** Resolution status */\n\tstatus: Status;\n\t/**\n\t * Is the data still being resolved?\n\t */\n\tisResolving: boolean;\n}\n\n/**\n * Is the data resolved by now?\n */\ntype HasResolved = boolean;\n\ntype ResourcePermissionsResolution< IdType > = [\n\tHasResolved,\n\tResolutionDetails &\n\t\tGlobalResourcePermissionsResolution &\n\t\t( IdType extends void ? SpecificResourcePermissionsResolution : {} ),\n];\n\ntype EntityResource = { kind: string; name: string; id?: string | number };\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType >;\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: EntityResource,\n\tid?: never\n): ResourcePermissionsResolution< IdType >;\n\n/**\n * Resolves resource permissions.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`\n * or REST base as a string - `media`.\n * @param id Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged\n * when using an entity object as a resource to check permissions and will be ignored.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( { kind: 'postType', name: 'page' } );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PagesList />\n * ```\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function Page({ pageId }) {\n * const {\n * canCreate,\n * canUpdate,\n * canDelete,\n * isResolving\n * } = useResourcePermissions( { kind: 'postType', name: 'page', id: pageId } );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * {canUpdate ? (<button>Edit page</button>) : false}\n * {canDelete ? (<button>Delete page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <Page pageId={ 15 } />\n * ```\n *\n * In the above example, when `PagesList` is rendered into an\n * application, the appropriate permissions and the resolution details will be retrieved from\n * the store state using `canUser()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template IdType\n */\nfunction useResourcePermissions< IdType = void >(\n\tresource: string | EntityResource,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\t// Serialize `resource` to a string that can be safely used as a React dep.\n\t// We can't just pass `resource` as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst isEntity = typeof resource === 'object';\n\tconst resourceAsString = isEntity ? JSON.stringify( resource ) : resource;\n\n\tif ( isEntity && typeof id !== 'undefined' ) {\n\t\twarning(\n\t\t\t`When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`\n\t\t);\n\t}\n\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst hasId = isEntity ? !! resource.id : !! id;\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser(\n\t\t\t\t'create',\n\t\t\t\tisEntity\n\t\t\t\t\t? { kind: resource.kind, name: resource.name }\n\t\t\t\t\t: resource\n\t\t\t);\n\n\t\t\tif ( ! hasId ) {\n\t\t\t\tconst read = canUser( 'read', resource );\n\n\t\t\t\tconst isResolving = create.isResolving || read.isResolving;\n\t\t\t\tconst hasResolved = create.hasResolved && read.hasResolved;\n\t\t\t\tlet status = Status.Idle;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\tcanRead: read.hasResolved && read.data,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst read = canUser( 'read', resource, id );\n\t\t\tconst update = canUser( 'update', resource, id );\n\t\t\tconst _delete = canUser( 'delete', resource, id );\n\t\t\tconst isResolving =\n\t\t\t\tread.isResolving ||\n\t\t\t\tcreate.isResolving ||\n\t\t\t\tupdate.isResolving ||\n\t\t\t\t_delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tread.hasResolved &&\n\t\t\t\tcreate.hasResolved &&\n\t\t\t\tupdate.hasResolved &&\n\t\t\t\t_delete.hasResolved;\n\n\t\t\tlet status = Status.Idle;\n\t\t\tif ( isResolving ) {\n\t\t\t\tstatus = Status.Resolving;\n\t\t\t} else if ( hasResolved ) {\n\t\t\t\tstatus = Status.Success;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\n\t\t\t\tcanRead: hasResolved && read.data,\n\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t};\n\t\t},\n\t\t[ resourceAsString, id ]\n\t);\n}\n\nexport default useResourcePermissions;\n\nexport function __experimentalUseResourcePermissions(\n\tresource: string,\n\tid?: unknown\n) {\n\tdeprecated( `wp.data.__experimentalUseResourcePermissions`, {\n\t\talternative: 'wp.data.useResourcePermissions',\n\t\tsince: '6.1',\n\t} );\n\treturn useResourcePermissions( resource, id );\n}\n"],
5
- "mappings": ";AAGA,OAAO,gBAAgB;AACvB,OAAO,aAAa;AAKpB,SAAS,SAAS,iBAAiB;AACnC,SAAS,cAAc;AACvB,OAAO,oBAAoB;AAmH3B,SAAS,uBACR,UACA,IAC0C;AAK1C,QAAM,WAAW,OAAO,aAAa;AACrC,QAAM,mBAAmB,WAAW,KAAK,UAAW,QAAS,IAAI;AAEjE,MAAK,YAAY,OAAO,OAAO,aAAc;AAC5C;AAAA,MACC;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AAAA,IACN,CAAE,YAAa;AACd,YAAM,QAAQ,WAAW,CAAC,CAAE,SAAS,KAAK,CAAC,CAAE;AAC7C,YAAM,EAAE,QAAQ,IAAI,QAAS,SAAU;AACvC,YAAM,SAAS;AAAA,QACd;AAAA,QACA,WACG,EAAE,MAAM,SAAS,MAAM,MAAM,SAAS,KAAK,IAC3C;AAAA,MACJ;AAEA,U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ordpress/deprecated';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\nimport useQuerySelect from './use-query-select';\n\ninterface GlobalResourcePermissionsResolution {\n\t/** Can the current user create new resources of this type? */\n\tcanCreate: boolean;\n}\ninterface SpecificResourcePermissionsResolution {\n\t/** Can the current user update resources of this type? */\n\tcanUpdate: boolean;\n\t/** Can the current user delete resources of this type? */\n\tcanDelete: boolean;\n}\ninterface ResolutionDetails {\n\t/** Resolution status */\n\tstatus: Status;\n\t/**\n\t * Is the data still being resolved?\n\t */\n\tisResolving: boolean;\n}\n\n/**\n * Is the data resolved by now?\n */\ntype HasResolved = boolean;\n\ntype ResourcePermissionsResolution< IdType > = [\n\tHasResolved,\n\tResolutionDetails &\n\t\tGlobalResourcePermissionsResolution &\n\t\t( IdType extends void ? SpecificResourcePermissionsResolution : {} ),\n];\n\ntype EntityResource = { kind: string; name: string; id?: string | number };\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType >;\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: EntityResource,\n\tid?: never\n): ResourcePermissionsResolution< IdType >;\n\n/**\n * Resolves resource permissions.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`\n * or REST base as a string - `media`.\n * @param id Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged\n * when using an entity object as a resource to check permissions and will be ignored.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( { kind: 'postType', name: 'page' } );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PagesList />\n * ```\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function Page({ pageId }) {\n * const {\n * canCreate,\n * canUpdate,\n * canDelete,\n * isResolving\n * } = useResourcePermissions( { kind: 'postType', name: 'page', id: pageId } );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * {canUpdate ? (<button>Edit page</button>) : false}\n * {canDelete ? (<button>Delete page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <Page pageId={ 15 } />\n * ```\n *\n * In the above example, when `PagesList` is rendered into an\n * application, the appropriate permissions and the resolution details will be retrieved from\n * the store state using `canUser()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template IdType\n */\nfunction useResourcePermissions< IdType = void >(\n\tresource: string | EntityResource,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\t// Serialize `resource` to a string that can be safely used as a React dep.\n\t// We can't just pass `resource` as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst isEntity = typeof resource === 'object';\n\tconst resourceAsString = isEntity ? JSON.stringify( resource ) : resource;\n\n\tif ( isEntity && typeof id !== 'undefined' ) {\n\t\twarning(\n\t\t\t`When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`\n\t\t);\n\t}\n\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst hasId = isEntity ? !! resource.id : !! id;\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser(\n\t\t\t\t'create',\n\t\t\t\tisEntity\n\t\t\t\t\t? { kind: resource.kind, name: resource.name }\n\t\t\t\t\t: resource\n\t\t\t);\n\n\t\t\tif ( ! hasId ) {\n\t\t\t\tconst read = canUser( 'read', resource );\n\n\t\t\t\tconst isResolving = create.isResolving || read.isResolving;\n\t\t\t\tconst hasResolved = create.hasResolved && read.hasResolved;\n\t\t\t\tlet status = Status.Idle;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\tcanRead: read.hasResolved && read.data,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst read = canUser( 'read', resource, id );\n\t\t\tconst update = canUser( 'update', resource, id );\n\t\t\tconst _delete = canUser( 'delete', resource, id );\n\t\t\tconst isResolving =\n\t\t\t\tread.isResolving ||\n\t\t\t\tcreate.isResolving ||\n\t\t\t\tupdate.isResolving ||\n\t\t\t\t_delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tread.hasResolved &&\n\t\t\t\tcreate.hasResolved &&\n\t\t\t\tupdate.hasResolved &&\n\t\t\t\t_delete.hasResolved;\n\n\t\t\tlet status = Status.Idle;\n\t\t\tif ( isResolving ) {\n\t\t\t\tstatus = Status.Resolving;\n\t\t\t} else if ( hasResolved ) {\n\t\t\t\tstatus = Status.Success;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\n\t\t\t\tcanRead: hasResolved && read.data,\n\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t};\n\t\t},\n\t\t[ resourceAsString, id ]\n\t);\n}\n\nexport default useResourcePermissions;\n\nexport function useDeprecatedResourcePermissions(\n\tresource: string,\n\tid?: unknown\n) {\n\tdeprecated( `wp.data.__experimentalUseResourcePermissions`, {\n\t\talternative: 'wp.data.useResourcePermissions',\n\t\tsince: '6.1',\n\t} );\n\treturn useResourcePermissions( resource, id );\n}\n"],
5
+ "mappings": ";AAGA,OAAO,gBAAgB;AACvB,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;AAClB,iBAAS,OAAO;AAAA,MACjB,WAAY,aAAc;AACzB,iBAAS,OAAO;AAAA,MACjB;AACA,aAAO;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAS,eAAe,KAAK;AAAA,QAC7B,WAAW,eAAe,OAAO;AAAA,QACjC,WAAW,eAAe,OAAO;AAAA,QACjC,WAAW,eAAe,QAAQ;AAAA,MACnC;AAAA,IACD;AAAA,IACA,CAAE,kBAAkB,EAAG;AAAA,EACxB;AACD;AAEA,IAAO,mCAAQ;AAER,SAAS,iCACf,UACA,IACC;AACD,aAAY,gDAAgD;AAAA,IAC3D,aAAa;AAAA,IACb,OAAO;AAAA,EACR,CAAE;AACF,SAAO,uBAAwB,UAAU,EAAG;AAC7C;",
6
6
  "names": ["read", "isResolving", "hasResolved", "status"]
7
7
  }
@@ -4,7 +4,8 @@ import { createSelector } from "@wordpress/data";
4
4
  import getQueryParts from "./get-query-parts.mjs";
5
5
  import { setNestedValue } from "../utils/index.mjs";
6
6
  var queriedItemsCacheByState = /* @__PURE__ */ new WeakMap();
7
- function getQueriedItemsUncached(state, query) {
7
+ function getQueriedItemsUncached(state, query, options = {}) {
8
+ const { supportsPagination = true } = options;
8
9
  const {
9
10
  stableKey,
10
11
  page,
@@ -18,9 +19,10 @@ function getQueriedItemsUncached(state, query) {
18
19
  if (!itemIds) {
19
20
  return null;
20
21
  }
21
- const startOffset = perPage === -1 ? 0 : queryOffset ?? (page - 1) * perPage;
22
- const endOffset = perPage === -1 ? itemIds.length : Math.min(startOffset + perPage, itemIds.length);
23
- if (perPage !== -1 && itemIds.length < startOffset + perPage) {
22
+ const isPaginated = supportsPagination && perPage !== -1;
23
+ const startOffset = isPaginated ? queryOffset ?? (page - 1) * perPage : 0;
24
+ const endOffset = isPaginated ? Math.min(startOffset + perPage, itemIds.length) : itemIds.length;
25
+ if (isPaginated && itemIds.length < startOffset + perPage) {
24
26
  const totalItems = state.queries[context][stableKey].meta?.totalItems;
25
27
  if (Number.isFinite(totalItems) && itemIds.length < totalItems) {
26
28
  return null;
@@ -60,21 +62,23 @@ function getQueriedItemsUncached(state, query) {
60
62
  }
61
63
  return items;
62
64
  }
63
- var getQueriedItems = createSelector((state, query = {}) => {
64
- let queriedItemsCache = queriedItemsCacheByState.get(state);
65
- if (queriedItemsCache) {
66
- const queriedItems = queriedItemsCache.get(query);
67
- if (queriedItems !== void 0) {
68
- return queriedItems;
65
+ var getQueriedItems = createSelector(
66
+ (state, query = {}, options = {}) => {
67
+ let queriedItemsCache = queriedItemsCacheByState.get(state);
68
+ if (queriedItemsCache) {
69
+ const queriedItems = queriedItemsCache.get(query);
70
+ if (queriedItems !== void 0) {
71
+ return queriedItems;
72
+ }
73
+ } else {
74
+ queriedItemsCache = new EquivalentKeyMap();
75
+ queriedItemsCacheByState.set(state, queriedItemsCache);
69
76
  }
70
- } else {
71
- queriedItemsCache = new EquivalentKeyMap();
72
- queriedItemsCacheByState.set(state, queriedItemsCache);
77
+ const items = getQueriedItemsUncached(state, query, options);
78
+ queriedItemsCache.set(query, items);
79
+ return items;
73
80
  }
74
- const items = getQueriedItemsUncached(state, query);
75
- queriedItemsCache.set(query, items);
76
- return items;
77
- });
81
+ );
78
82
  function getQueriedTotalItems(state, query = {}) {
79
83
  const { stableKey, context } = getQueryParts(query);
80
84
  return state.queries?.[context]?.[stableKey]?.meta?.totalItems ?? null;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/queried-data/selectors.js"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport getQueryParts from './get-query-parts';\nimport { setNestedValue } from '../utils';\n\n/**\n * Cache of state keys to EquivalentKeyMap where the inner map tracks queries\n * to their resulting items set. WeakMap allows garbage collection on expired\n * state references.\n *\n * @type {WeakMap<Object,EquivalentKeyMap>}\n */\nconst queriedItemsCacheByState = new WeakMap();\n\n/**\n * Returns items for a given query, or null if the items are not known.\n *\n * @param {Object} state State object.\n * @param {?Object} query Optional query.\n *\n * @return {?Array} Query items.\n */\nfunction getQueriedItemsUncached( state, query ) {\n\tconst {\n\t\tstableKey,\n\t\tpage,\n\t\tperPage,\n\t\toffset: queryOffset,\n\t\tinclude,\n\t\tfields,\n\t\tcontext,\n\t} = getQueryParts( query );\n\n\tconst itemIds = state.queries?.[ context ]?.[ stableKey ]?.itemIds;\n\tif ( ! itemIds ) {\n\t\treturn null;\n\t}\n\n\tconst startOffset =\n\t\tperPage === -1 ? 0 : queryOffset ?? ( page - 1 ) * perPage;\n\tconst endOffset =\n\t\tperPage === -1\n\t\t\t? itemIds.length\n\t\t\t: Math.min( startOffset + perPage, itemIds.length );\n\n\t// If the requested page range exceeds the stored itemIds, the data for\n\t// this specific pagination window may not have been fetched yet. Return\n\t// null unless totalItems confirms we already have all available items.\n\tif ( perPage !== -1 && itemIds.length < startOffset + perPage ) {\n\t\tconst totalItems =\n\t\t\tstate.queries[ context ][ stableKey ].meta?.totalItems;\n\t\tif ( Number.isFinite( totalItems ) && itemIds.length < totalItems ) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tconst items = [];\n\tfor ( let i = startOffset; i < endOffset; i++ ) {\n\t\tconst itemId = itemIds[ i ];\n\t\tif ( Array.isArray( include ) && ! include.includes( itemId ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tif ( itemId === undefined ) {\n\t\t\tcontinue;\n\t\t}\n\t\t// Having a target item ID doesn't guarantee that this object has been queried.\n\t\tif ( ! state.items[ context ]?.hasOwnProperty( itemId ) ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst item = state.items[ context ][ itemId ];\n\n\t\tlet filteredItem;\n\t\tif ( Array.isArray( fields ) ) {\n\t\t\tfilteredItem = {};\n\n\t\t\tfor ( let f = 0; f < fields.length; f++ ) {\n\t\t\t\tconst field = fields[ f ].split( '.' );\n\t\t\t\tlet value = item;\n\t\t\t\tfield.forEach( ( fieldName ) => {\n\t\t\t\t\tvalue = value?.[ fieldName ];\n\t\t\t\t} );\n\n\t\t\t\tsetNestedValue( filteredItem, field, value );\n\t\t\t}\n\t\t} else {\n\t\t\t// If expecting a complete item, validate that completeness, or\n\t\t\t// otherwise abort.\n\t\t\tif ( ! state.itemIsComplete[ context ]?.[ itemId ] ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tfilteredItem = item;\n\t\t}\n\n\t\titems.push( filteredItem );\n\t}\n\n\treturn items;\n}\n\n/**\n * Returns items for a given query, or null if the items are not known. Caches\n * result both per state (by reference) and per query (by deep equality).\n * The caching approach is intended to be durable to query objects which are\n * deeply but not referentially equal, since otherwise:\n *\n * `getQueriedItems( state, {} ) !== getQueriedItems( state, {} )`\n *\n * @param {Object} state State object.\n * @param {?Object} query Optional query.\n *\n * @return {?Array} Query items.\n */\nexport const getQueriedItems = createSelector( ( state, query = {} ) => {\n\tlet queriedItemsCache = queriedItemsCacheByState.get( state );\n\tif ( queriedItemsCache ) {\n\t\tconst queriedItems = queriedItemsCache.get( query );\n\t\tif ( queriedItems !== undefined ) {\n\t\t\treturn queriedItems;\n\t\t}\n\t} else {\n\t\tqueriedItemsCache = new EquivalentKeyMap();\n\t\tqueriedItemsCacheByState.set( state, queriedItemsCache );\n\t}\n\n\tconst items = getQueriedItemsUncached( state, query );\n\tqueriedItemsCache.set( query, items );\n\treturn items;\n} );\n\nexport function getQueriedTotalItems( state, query = {} ) {\n\tconst { stableKey, context } = getQueryParts( query );\n\n\treturn state.queries?.[ context ]?.[ stableKey ]?.meta?.totalItems ?? null;\n}\n\nexport function getQueriedTotalPages( state, query = {} ) {\n\tconst { stableKey, context } = getQueryParts( query );\n\n\treturn state.queries?.[ context ]?.[ stableKey ]?.meta?.totalPages ?? null;\n}\n"],
5
- "mappings": ";AAGA,OAAO,sBAAsB;AAK7B,SAAS,sBAAsB;AAK/B,OAAO,mBAAmB;AAC1B,SAA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,kBAAQ,QAAS,SAAU;AAAA,QAC5B,CAAE;AAEF,uBAAgB,cAAc,OAAO,KAAM;AAAA,MAC5C;AAAA,IACD,OAAO;AAGN,UAAK,CAAE,MAAM,eAAgB,OAAQ,IAAK,MAAO,GAAI;AACpD,eAAO;AAAA,MACR;AAEA,qBAAe;AAAA,IAChB;AAEA,UAAM,KAAM,YAAa;AAAA,EAC1B;AAEA,SAAO;AACR;AAeO,IAAM,kBAAkB,eAAgB,CAAE,OAAO,QAAQ,CAAC,MAAO;AACvE,MAAI,oBAAoB,yBAAyB,IAAK,KAAM;AAC5D,MAAK,mBAAoB;AACxB,UAAM,eAAe,kBAAkB,IAAK,KAAM;AAClD,QAAK,iBAAiB,QAAY;AACjC,aAAO;AAAA,IACR;AAAA,EACD,OAAO;AACN,wBAAoB,IAAI,iBAAiB;AACzC,6BAAyB,IAAK,OAAO,iBAAkB;AAAA,EACxD;AAEA,QAAM,QAAQ,wBAAyB,OAAO,KAAM;AACpD,oBAAkB,IAAK,OAAO,KAAM;AACpC,SAAO;AACR,CAAE;AAEK,SAAS,qBAAsB,OAAO,QAAQ,CAAC,GAAI;AACzD,QAAM,EAAE,WAAW,QAAQ,IAAI,cAAe,KAAM;AAEpD,SAAO,MAAM,UAAW,OAAQ,IAAK,SAAU,GAAG,MAAM,cAAc;AACvE;AAEO,SAAS,qBAAsB,OAAO,QAAQ,CAAC,GAAI;AACzD,QAAM,EAAE,WAAW,QAAQ,IAAI,cAAe,KAAM;AAEpD,SAAO,MAAM,UAAW,OAAQ,IAAK,SAAU,GAAG,MAAM,cAAc;AACvE;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport getQueryParts from './get-query-parts';\nimport { setNestedValue } from '../utils';\n\n/**\n * Cache of state keys to EquivalentKeyMap where the inner map tracks queries\n * to their resulting items set. WeakMap allows garbage collection on expired\n * state references.\n *\n * @type {WeakMap<Object,EquivalentKeyMap>}\n */\nconst queriedItemsCacheByState = new WeakMap();\n\n/**\n * Returns items for a given query, or null if the items are not known.\n *\n * @param {Object} state State object.\n * @param {?Object} query Optional query.\n * @param {?Object} options Optional pagination options.\n * @param {boolean} options.supportsPagination Whether the entity supports pagination. Default true.\n *\n * @return {?Array} Query items.\n */\nfunction getQueriedItemsUncached( state, query, options = {} ) {\n\tconst { supportsPagination = true } = options;\n\tconst {\n\t\tstableKey,\n\t\tpage,\n\t\tperPage,\n\t\toffset: queryOffset,\n\t\tinclude,\n\t\tfields,\n\t\tcontext,\n\t} = getQueryParts( query );\n\n\tconst itemIds = state.queries?.[ context ]?.[ stableKey ]?.itemIds;\n\tif ( ! itemIds ) {\n\t\treturn null;\n\t}\n\n\tconst isPaginated = supportsPagination && perPage !== -1;\n\tconst startOffset = isPaginated ? queryOffset ?? ( page - 1 ) * perPage : 0;\n\tconst endOffset = isPaginated\n\t\t? Math.min( startOffset + perPage, itemIds.length )\n\t\t: itemIds.length;\n\n\t// If the requested page range exceeds the stored itemIds, the data for\n\t// this specific pagination window may not have been fetched yet. Return\n\t// null unless totalItems confirms we already have all available items.\n\tif ( isPaginated && itemIds.length < startOffset + perPage ) {\n\t\tconst totalItems =\n\t\t\tstate.queries[ context ][ stableKey ].meta?.totalItems;\n\t\tif ( Number.isFinite( totalItems ) && itemIds.length < totalItems ) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tconst items = [];\n\tfor ( let i = startOffset; i < endOffset; i++ ) {\n\t\tconst itemId = itemIds[ i ];\n\t\tif ( Array.isArray( include ) && ! include.includes( itemId ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tif ( itemId === undefined ) {\n\t\t\tcontinue;\n\t\t}\n\t\t// Having a target item ID doesn't guarantee that this object has been queried.\n\t\tif ( ! state.items[ context ]?.hasOwnProperty( itemId ) ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst item = state.items[ context ][ itemId ];\n\n\t\tlet filteredItem;\n\t\tif ( Array.isArray( fields ) ) {\n\t\t\tfilteredItem = {};\n\n\t\t\tfor ( let f = 0; f < fields.length; f++ ) {\n\t\t\t\tconst field = fields[ f ].split( '.' );\n\t\t\t\tlet value = item;\n\t\t\t\tfield.forEach( ( fieldName ) => {\n\t\t\t\t\tvalue = value?.[ fieldName ];\n\t\t\t\t} );\n\n\t\t\t\tsetNestedValue( filteredItem, field, value );\n\t\t\t}\n\t\t} else {\n\t\t\t// If expecting a complete item, validate that completeness, or\n\t\t\t// otherwise abort.\n\t\t\tif ( ! state.itemIsComplete[ context ]?.[ itemId ] ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tfilteredItem = item;\n\t\t}\n\n\t\titems.push( filteredItem );\n\t}\n\n\treturn items;\n}\n\n/**\n * Returns items for a given query, or null if the items are not known. Caches\n * result both per state (by reference) and per query (by deep equality).\n * The caching approach is intended to be durable to query objects which are\n * deeply but not referentially equal, since otherwise:\n *\n * `getQueriedItems( state, {} ) !== getQueriedItems( state, {} )`\n *\n * @param {Object} state State object.\n * @param {?Object} query Optional query.\n * @param {?Object} options Optional pagination options.\n * @param {boolean} options.supportsPagination Whether the entity supports pagination. Default true.\n *\n * @return {?Array} Query items.\n */\nexport const getQueriedItems = createSelector(\n\t( state, query = {}, options = {} ) => {\n\t\tlet queriedItemsCache = queriedItemsCacheByState.get( state );\n\t\tif ( queriedItemsCache ) {\n\t\t\tconst queriedItems = queriedItemsCache.get( query );\n\t\t\tif ( queriedItems !== undefined ) {\n\t\t\t\treturn queriedItems;\n\t\t\t}\n\t\t} else {\n\t\t\tqueriedItemsCache = new EquivalentKeyMap();\n\t\t\tqueriedItemsCacheByState.set( state, queriedItemsCache );\n\t\t}\n\n\t\tconst items = getQueriedItemsUncached( state, query, options );\n\t\tqueriedItemsCache.set( query, items );\n\t\treturn items;\n\t}\n);\n\nexport function getQueriedTotalItems( state, query = {} ) {\n\tconst { stableKey, context } = getQueryParts( query );\n\n\treturn state.queries?.[ context ]?.[ stableKey ]?.meta?.totalItems ?? null;\n}\n\nexport function getQueriedTotalPages( state, query = {} ) {\n\tconst { stableKey, context } = getQueryParts( query );\n\n\treturn state.queries?.[ context ]?.[ stableKey ]?.meta?.totalPages ?? null;\n}\n"],
5
+ "mappings": ";AAGA,OAAO,sBAAsB;AAK7B,SAAS,sBAAsB;AAK/B,OAAO,mBAAmB;AAC1B,SAAS,sBAAsB;AAS/B,IAAM,2BAA2B,oBAAI,QAAQ;AAY7C,SAAS,wBAAyB,OAAO,OAAO,UAAU,CAAC,GAAI;AAC9D,QAAM,EAAE,qBAAqB,KAAK,IAAI;AACtC,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI,cAAe,KAAM;AAEzB,QAAM,UAAU,MAAM,UAAW,OAAQ,IAAK,SAAU,GAAG;AAC3D,MAAK,CAAE,SAAU;AAChB,WAAO;AAAA,EACR;AAEA,QAAM,cAAc,sBAAsB,YAAY;AACtD,QAAM,cAAc,cAAc,gBAAiB,OAAO,KAAM,UAAU;AAC1E,QAAM,YAAY,cACf,KAAK,IAAK,cAAc,SAAS,QAAQ,MAAO,IAChD,QAAQ;AAKX,MAAK,eAAe,QAAQ,SAAS,cAAc,SAAU;AAC5D,UAAM,aACL,MAAM,QAAS,OAAQ,EAAG,SAAU,EAAE,MAAM;AAC7C,QAAK,OAAO,SAAU,UAAW,KAAK,QAAQ,SAAS,YAAa;AACnE,aAAO;AAAA,IACR;AAAA,EACD;AAEA,QAAM,QAAQ,CAAC;AACf,WAAU,IAAI,aAAa,IAAI,WAAW,KAAM;AAC/C,UAAM,SAAS,QAAS,CAAE;AAC1B,QAAK,MAAM,QAAS,OAAQ,KAAK,CAAE,QAAQ,SAAU,MAAO,GAAI;AAC/D;AAAA,IACD;AACA,QAAK,WAAW,QAAY;AAC3B;AAAA,IACD;AAEA,QAAK,CAA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QAAQ,CAAC,GAAI;AACzD,QAAM,EAAE,WAAW,QAAQ,IAAI,cAAe,KAAM;AAEpD,SAAO,MAAM,UAAW,OAAQ,IAAK,SAAU,GAAG,MAAM,cAAc;AACvE;",
6
6
  "names": []
7
7
  }
@@ -389,7 +389,7 @@ var getEntityRecords = (kind, name, query = {}) => async ({ dispatch, registry,
389
389
  );
390
390
  dispatch.__unstableReleaseStoreLock(lock);
391
391
  });
392
- } catch (e) {
392
+ } catch {
393
393
  dispatch.__unstableReleaseStoreLock(lock);
394
394
  }
395
395
  };
@@ -413,7 +413,7 @@ var getEmbedPreview = (url) => async ({ dispatch }) => {
413
413
  path: addQueryArgs("/oembed/1.0/proxy", { url })
414
414
  });
415
415
  dispatch.receiveEmbedPreview(url, embedProxyResponse);
416
- } catch (error) {
416
+ } catch {
417
417
  dispatch.receiveEmbedPreview(url, false);
418
418
  }
419
419
  };
@@ -460,7 +460,7 @@ var canUser = (requestedAction, resource, id) => async ({ dispatch, registry, re
460
460
  method: "OPTIONS",
461
461
  parse: false
462
462
  });
463
- } catch (error) {
463
+ } catch {
464
464
  return;
465
465
  }
466
466
  const permissions = getUserPermissionsFromAllowHeader(
@@ -689,7 +689,7 @@ var getRevisions = (kind, name, recordKey, query = {}) => async ({ dispatch, reg
689
689
  const isPaginated = entityConfig.supportsPagination && query.per_page !== -1;
690
690
  try {
691
691
  response = await apiFetch({ path, parse: !isPaginated });
692
- } catch (error) {
692
+ } catch {
693
693
  return;
694
694
  }
695
695
  if (response) {
@@ -784,7 +784,7 @@ var getRevision = (kind, name, recordKey, revisionKey, query) => async ({ select
784
784
  let record;
785
785
  try {
786
786
  record = await apiFetch({ path });
787
- } catch (error) {
787
+ } catch {
788
788
  return;
789
789
  }
790
790
  if (record) {
@@ -811,7 +811,7 @@ var getRegisteredPostMeta = (postType) => async ({ dispatch, resolveSelect }) =>
811
811
  path: `${restNamespace}/${restBase}/?context=edit`,
812
812
  method: "OPTIONS"
813
813
  });
814
- } catch (error) {
814
+ } catch {
815
815
  return;
816
816
  }
817
817
  if (options) {