@wordpress/core-data 7.4.0 → 7.6.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 (55) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +1 -1
  3. package/build/actions.js +1 -1
  4. package/build/actions.js.map +1 -1
  5. package/build/entity-types/wp-template.js.map +1 -1
  6. package/build/footnotes/get-rich-text-values-cached.js +2 -2
  7. package/build/footnotes/get-rich-text-values-cached.js.map +1 -1
  8. package/build/hooks/use-entity-records.js +39 -0
  9. package/build/hooks/use-entity-records.js.map +1 -1
  10. package/build/index.js +14 -2
  11. package/build/index.js.map +1 -1
  12. package/build/lock-unlock.js +18 -0
  13. package/build/lock-unlock.js.map +1 -0
  14. package/build/private-apis.js +8 -9
  15. package/build/private-apis.js.map +1 -1
  16. package/build/private-selectors.js +35 -0
  17. package/build/private-selectors.js.map +1 -1
  18. package/build-module/actions.js +1 -1
  19. package/build-module/actions.js.map +1 -1
  20. package/build-module/entity-types/wp-template.js.map +1 -1
  21. package/build-module/footnotes/get-rich-text-values-cached.js +1 -1
  22. package/build-module/footnotes/get-rich-text-values-cached.js.map +1 -1
  23. package/build-module/hooks/use-entity-records.js +38 -0
  24. package/build-module/hooks/use-entity-records.js.map +1 -1
  25. package/build-module/index.js +2 -1
  26. package/build-module/index.js.map +1 -1
  27. package/build-module/lock-unlock.js +9 -0
  28. package/build-module/lock-unlock.js.map +1 -0
  29. package/build-module/private-apis.js +7 -6
  30. package/build-module/private-apis.js.map +1 -1
  31. package/build-module/private-selectors.js +33 -0
  32. package/build-module/private-selectors.js.map +1 -1
  33. package/build-types/actions.d.ts +1 -1
  34. package/build-types/entity-types/wp-template.d.ts +4 -0
  35. package/build-types/entity-types/wp-template.d.ts.map +1 -1
  36. package/build-types/hooks/use-entity-records.d.ts +1 -0
  37. package/build-types/hooks/use-entity-records.d.ts.map +1 -1
  38. package/build-types/index.d.ts +1 -0
  39. package/build-types/index.d.ts.map +1 -1
  40. package/build-types/lock-unlock.d.ts +3 -0
  41. package/build-types/lock-unlock.d.ts.map +1 -0
  42. package/build-types/private-apis.d.ts +1 -2
  43. package/build-types/private-apis.d.ts.map +1 -1
  44. package/build-types/private-selectors.d.ts +15 -0
  45. package/build-types/private-selectors.d.ts.map +1 -1
  46. package/package.json +18 -18
  47. package/src/actions.js +1 -1
  48. package/src/entity-types/wp-template.ts +4 -0
  49. package/src/footnotes/get-rich-text-values-cached.js +1 -1
  50. package/src/hooks/use-entity-records.ts +50 -0
  51. package/src/index.js +2 -1
  52. package/src/lock-unlock.js +10 -0
  53. package/src/private-apis.js +7 -7
  54. package/src/private-selectors.ts +43 -0
  55. package/tsconfig.tsbuildinfo +1 -1
@@ -1 +1 @@
1
- {"version":3,"names":["createSelector","createRegistrySelector","STORE_NAME","getUndoManager","state","undoManager","getNavigationFallbackId","navigationFallbackId","getBlockPatternsForPostType","select","postType","getBlockPatterns","filter","postTypes","Array","isArray","includes"],"sources":["@wordpress/core-data/src/private-selectors.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type { State } from './selectors';\nimport { STORE_NAME } from './name';\n\ntype EntityRecordKey = string | number;\n\n/**\n * Returns the previous edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * @param state State tree.\n *\n * @return The undo manager.\n */\nexport function getUndoManager( state: State ) {\n\treturn state.undoManager;\n}\n\n/**\n * Retrieve the fallback Navigation.\n *\n * @param state Data state.\n * @return The ID for the fallback Navigation post.\n */\nexport function getNavigationFallbackId(\n\tstate: State\n): EntityRecordKey | undefined {\n\treturn state.navigationFallbackId;\n}\n\nexport const getBlockPatternsForPostType = createRegistrySelector(\n\t( select: any ) =>\n\t\tcreateSelector(\n\t\t\t( state, postType ) =>\n\t\t\t\tselect( STORE_NAME )\n\t\t\t\t\t.getBlockPatterns()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( { postTypes } ) =>\n\t\t\t\t\t\t\t! postTypes ||\n\t\t\t\t\t\t\t( Array.isArray( postTypes ) &&\n\t\t\t\t\t\t\t\tpostTypes.includes( postType ) )\n\t\t\t\t\t),\n\t\t\t() => [ select( STORE_NAME ).getBlockPatterns() ]\n\t\t)\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAc,EAAEC,sBAAsB,QAAQ,iBAAiB;;AAExE;AACA;AACA;;AAEA,SAASC,UAAU,QAAQ,QAAQ;AAInC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAEC,KAAY,EAAG;EAC9C,OAAOA,KAAK,CAACC,WAAW;AACzB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CACtCF,KAAY,EACkB;EAC9B,OAAOA,KAAK,CAACG,oBAAoB;AAClC;AAEA,OAAO,MAAMC,2BAA2B,GAAGP,sBAAsB,CAC9DQ,MAAW,IACZT,cAAc,CACb,CAAEI,KAAK,EAAEM,QAAQ,KAChBD,MAAM,CAAEP,UAAW,CAAC,CAClBS,gBAAgB,CAAC,CAAC,CAClBC,MAAM,CACN,CAAE;EAAEC;AAAU,CAAC,KACd,CAAEA,SAAS,IACTC,KAAK,CAACC,OAAO,CAAEF,SAAU,CAAC,IAC3BA,SAAS,CAACG,QAAQ,CAAEN,QAAS,CAChC,CAAC,EACH,MAAM,CAAED,MAAM,CAAEP,UAAW,CAAC,CAACS,gBAAgB,CAAC,CAAC,CAChD,CACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["createSelector","createRegistrySelector","STORE_NAME","getUndoManager","state","undoManager","getNavigationFallbackId","navigationFallbackId","getBlockPatternsForPostType","select","postType","getBlockPatterns","filter","postTypes","Array","isArray","includes","getEntityRecordsPermissions","kind","name","ids","normalizedIds","map","id","delete","canUser","update","userPermissions","getEntityRecordPermissions"],"sources":["@wordpress/core-data/src/private-selectors.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type { State } from './selectors';\nimport { STORE_NAME } from './name';\n\ntype EntityRecordKey = string | number;\n\n/**\n * Returns the previous edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * @param state State tree.\n *\n * @return The undo manager.\n */\nexport function getUndoManager( state: State ) {\n\treturn state.undoManager;\n}\n\n/**\n * Retrieve the fallback Navigation.\n *\n * @param state Data state.\n * @return The ID for the fallback Navigation post.\n */\nexport function getNavigationFallbackId(\n\tstate: State\n): EntityRecordKey | undefined {\n\treturn state.navigationFallbackId;\n}\n\nexport const getBlockPatternsForPostType = createRegistrySelector(\n\t( select: any ) =>\n\t\tcreateSelector(\n\t\t\t( state, postType ) =>\n\t\t\t\tselect( STORE_NAME )\n\t\t\t\t\t.getBlockPatterns()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( { postTypes } ) =>\n\t\t\t\t\t\t\t! postTypes ||\n\t\t\t\t\t\t\t( Array.isArray( postTypes ) &&\n\t\t\t\t\t\t\t\tpostTypes.includes( postType ) )\n\t\t\t\t\t),\n\t\t\t() => [ select( STORE_NAME ).getBlockPatterns() ]\n\t\t)\n);\n\n/**\n * Returns the entity records permissions for the given entity record ids.\n */\nexport const getEntityRecordsPermissions = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t( state: State, kind: string, name: string, ids: string[] ) => {\n\t\t\tconst normalizedIds = Array.isArray( ids ) ? ids : [ ids ];\n\t\t\treturn normalizedIds.map( ( id ) => ( {\n\t\t\t\tdelete: select( STORE_NAME ).canUser( 'delete', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t\tupdate: select( STORE_NAME ).canUser( 'update', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t} ) );\n\t\t},\n\t\t( state ) => [ state.userPermissions ]\n\t)\n);\n\n/**\n * Returns the entity record permissions for the given entity record id.\n *\n * @param state Data state.\n * @param kind Entity kind.\n * @param name Entity name.\n * @param id Entity record id.\n *\n * @return The entity record permissions.\n */\nexport function getEntityRecordPermissions(\n\tstate: State,\n\tkind: string,\n\tname: string,\n\tid: string\n) {\n\treturn getEntityRecordsPermissions( state, kind, name, id )[ 0 ];\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAc,EAAEC,sBAAsB,QAAQ,iBAAiB;;AAExE;AACA;AACA;;AAEA,SAASC,UAAU,QAAQ,QAAQ;AAInC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAEC,KAAY,EAAG;EAC9C,OAAOA,KAAK,CAACC,WAAW;AACzB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CACtCF,KAAY,EACkB;EAC9B,OAAOA,KAAK,CAACG,oBAAoB;AAClC;AAEA,OAAO,MAAMC,2BAA2B,GAAGP,sBAAsB,CAC9DQ,MAAW,IACZT,cAAc,CACb,CAAEI,KAAK,EAAEM,QAAQ,KAChBD,MAAM,CAAEP,UAAW,CAAC,CAClBS,gBAAgB,CAAC,CAAC,CAClBC,MAAM,CACN,CAAE;EAAEC;AAAU,CAAC,KACd,CAAEA,SAAS,IACTC,KAAK,CAACC,OAAO,CAAEF,SAAU,CAAC,IAC3BA,SAAS,CAACG,QAAQ,CAAEN,QAAS,CAChC,CAAC,EACH,MAAM,CAAED,MAAM,CAAEP,UAAW,CAAC,CAACS,gBAAgB,CAAC,CAAC,CAChD,CACF,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMM,2BAA2B,GAAGhB,sBAAsB,CAAIQ,MAAM,IAC1ET,cAAc,CACb,CAAEI,KAAY,EAAEc,IAAY,EAAEC,IAAY,EAAEC,GAAa,KAAM;EAC9D,MAAMC,aAAa,GAAGP,KAAK,CAACC,OAAO,CAAEK,GAAI,CAAC,GAAGA,GAAG,GAAG,CAAEA,GAAG,CAAE;EAC1D,OAAOC,aAAa,CAACC,GAAG,CAAIC,EAAE,KAAQ;IACrCC,MAAM,EAAEf,MAAM,CAAEP,UAAW,CAAC,CAACuB,OAAO,CAAE,QAAQ,EAAE;MAC/CP,IAAI;MACJC,IAAI;MACJI;IACD,CAAE,CAAC;IACHG,MAAM,EAAEjB,MAAM,CAAEP,UAAW,CAAC,CAACuB,OAAO,CAAE,QAAQ,EAAE;MAC/CP,IAAI;MACJC,IAAI;MACJI;IACD,CAAE;EACH,CAAC,CAAG,CAAC;AACN,CAAC,EACCnB,KAAK,IAAM,CAAEA,KAAK,CAACuB,eAAe,CACrC,CACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,0BAA0BA,CACzCxB,KAAY,EACZc,IAAY,EACZC,IAAY,EACZI,EAAU,EACT;EACD,OAAON,2BAA2B,CAAEb,KAAK,EAAEc,IAAI,EAAEC,IAAI,EAAEI,EAAG,CAAC,CAAE,CAAC,CAAE;AACjE","ignoreList":[]}
@@ -91,7 +91,7 @@ export function __experimentalReceiveThemeGlobalStyleVariations(stylesheet: stri
91
91
  /**
92
92
  * Returns an action object used in signalling that the index has been received.
93
93
  *
94
- * @deprecated since WP 5.9, this is not useful anymore, use the selector direclty.
94
+ * @deprecated since WP 5.9, this is not useful anymore, use the selector directly.
95
95
  *
96
96
  * @return {Object} Action object.
97
97
  */
@@ -61,6 +61,10 @@ declare module './base-entity-records' {
61
61
  * Post ID.
62
62
  */
63
63
  wp_id: number;
64
+ /**
65
+ * Plugin that registered the template.
66
+ */
67
+ plugin?: string;
64
68
  /**
65
69
  * Theme file exists.
66
70
  */
@@ -1 +1 @@
1
- {"version":3,"file":"wp-template.d.ts","sourceRoot":"","sources":["../../src/entity-types/wp-template.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EACX,OAAO,EACP,UAAU,EACV,YAAY,EACZ,UAAU,EACV,eAA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AAkB,CAAC,UAAU,CAAE,CAAC,CAAE,CAClC,CAAC"}
1
+ {"version":3,"file":"wp-template.d.ts","sourceRoot":"","sources":["../../src/entity-types/wp-template.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EACX,OAAO,EACP,UAAU,EACV,YAAY,EACZ,UAAU,EACV,eAAe,EACf,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,iBAAiB,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAErF,OAAO,QAAQ,uBAAuB,CAAC;IACtC,UAAiB,iBAAiB,CAAC;QAClC,UAAiB,UAAU,CAAE,CAAC,SAAS,OAAO;YAC7C;;eAEG;YACH,EAAE,EAAE,MAAM,CAAC;YACX;;eAEG;YACH,IAAI,EAAE,MAAM,CAAC;YACb;;eAEG;YACH,KAAK,EAAE,MAAM,CAAC;YACd;;eAEG;YACH,IAAI,EAAE,MAAM,CAAC;YACb;;eAEG;YACH,MAAM,EAAE,MAAM,CAAC;YACf;;eAEG;YACH,MAAM,EAAE,MAAM,CAAC;YACf;;;;;;;;eAQG;YACH,OAAO,EAAE,eAAe,CACvB,YAAY,CAAE,CAAC,CAAE,GAAG;gBACnB;;mBAEG;gBACH,aAAa,EAAE,eAAe,CAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAE,CAAC;aACpD,EACD,MAAM,GAAG,MAAM,EACf,CAAC,CACD,CAAC;YACF;;eAEG;YACH,KAAK,EAAE,YAAY,CAAE,MAAM,CAAE,CAAC;YAC9B;;eAEG;YACH,WAAW,EAAE,MAAM,CAAC;YACpB;;eAEG;YACH,MAAM,EAAE,UAAU,CAAC;YACnB;;eAEG;YACH,KAAK,EAAE,MAAM,CAAC;YACd;;eAEG;YACH,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB;;eAEG;YACH,cAAc,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,CAAE,CAAC;YACzC;;eAEG;YACH,MAAM,EAAE,MAAM,CAAC;YACf;;eAEG;YACH,SAAS,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,CAAE,CAAC;YACpC;;eAEG;YACH,QAAQ,EAAE,eAAe,CAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAE,CAAC;SACxD;KACD;CACD;AAED,MAAM,MAAM,UAAU,CAAE,CAAC,SAAS,OAAO,GAAG,MAAM,IAAK,UAAU,CAChE,kBAAkB,CAAC,UAAU,CAAE,CAAC,CAAE,CAClC,CAAC"}
@@ -64,5 +64,6 @@ interface EntityRecordsResolution<RecordType> {
64
64
  */
65
65
  export default function useEntityRecords<RecordType>(kind: string, name: string, queryArgs?: Record<string, unknown>, options?: Options): EntityRecordsResolution<RecordType>;
66
66
  export declare function __experimentalUseEntityRecords(kind: string, name: string, queryArgs: any, options: any): EntityRecordsResolution<unknown>;
67
+ export declare function useEntityRecordsWithPermissions<RecordType>(kind: string, name: string, queryArgs?: Record<string, unknown>, options?: Options): EntityRecordsResolution<RecordType>;
67
68
  export {};
68
69
  //# sourceMappingURL=use-entity-records.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-entity-records.d.ts","sourceRoot":"","sources":["../../src/hooks/use-entity-records.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,UAAU,uBAAuB,CAAE,UAAU;IAC5C,kCAAkC;IAClC,OAAO,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAE7B;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAE1B;;OAEG;IACH,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAID;;;;;;;;;;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AAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,GAAG,EACd,OAAO,EAAE,GAAG,oCAOZ;AAED,wBAAgB,+BAA+B,CAAE,UAAU,EAC1D,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,SAAS,GAAE,MAAM,CAAE,MAAM,EAAE,OAAO,CAAO,EACzC,OAAO,GAAE,OAA2B,GAClC,uBAAuB,CAAE,UAAU,CAAE,CAyCvC"}
@@ -151,5 +151,6 @@ export * from "./entity-provider";
151
151
  export * from "./entity-types";
152
152
  export * from "./fetch";
153
153
  export * from "./hooks";
154
+ export * from "./private-apis";
154
155
  import * as selectors from './selectors';
155
156
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AA0EA;;;;GAIG;AACH;;;;;;;;;;;;;;;;;;;4CAS42pB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAThzpB;;;;;;2BAtExC,aAAa"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AA0EA;;;;GAIG;AACH;;;;;;;;;;;;;;;;;;;4CAU60pB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAVjxpB;;;;;;;2BAtExC,aAAa"}
@@ -0,0 +1,3 @@
1
+ export const lock: (object: any, privateData: any) => void;
2
+ export const unlock: (object: any) => any;
3
+ //# sourceMappingURL=lock-unlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lock-unlock.d.ts","sourceRoot":"","sources":["../src/lock-unlock.js"],"names":[],"mappings":""}
@@ -1,3 +1,2 @@
1
- export const lock: (object: any, privateData: any) => void;
2
- export const unlock: (object: any) => any;
1
+ export const privateApis: {};
3
2
  //# sourceMappingURL=private-apis.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"private-apis.d.ts","sourceRoot":"","sources":["../src/private-apis.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"private-apis.d.ts","sourceRoot":"","sources":["../src/private-apis.js"],"names":[],"mappings":"AAMA,6BAA8B"}
@@ -20,5 +20,20 @@ export declare function getUndoManager(state: State): import("@wordpress/undo-ma
20
20
  */
21
21
  export declare function getNavigationFallbackId(state: State): EntityRecordKey | undefined;
22
22
  export declare const getBlockPatternsForPostType: Function;
23
+ /**
24
+ * Returns the entity records permissions for the given entity record ids.
25
+ */
26
+ export declare const getEntityRecordsPermissions: Function;
27
+ /**
28
+ * Returns the entity record permissions for the given entity record id.
29
+ *
30
+ * @param state Data state.
31
+ * @param kind Entity kind.
32
+ * @param name Entity name.
33
+ * @param id Entity record id.
34
+ *
35
+ * @return The entity record permissions.
36
+ */
37
+ export declare function getEntityRecordPermissions(state: State, kind: string, name: string, id: string): any;
23
38
  export {};
24
39
  //# sourceMappingURL=private-selectors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"private-selectors.d.ts","sourceRoot":"","sources":["../src/private-selectors.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGzC,KAAK,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAE,KAAK,EAAE,KAAK,mEAE3C;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,KAAK,GACV,eAAe,GAAG,SAAS,CAE7B;AAED,eAAO,MAAM,2BAA2B,UAcvC,CAAC"}
1
+ {"version":3,"file":"private-selectors.d.ts","sourceRoot":"","sources":["../src/private-selectors.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGzC,KAAK,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAE,KAAK,EAAE,KAAK,mEAE3C;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,KAAK,GACV,eAAe,GAAG,SAAS,CAE7B;AAED,eAAO,MAAM,2BAA2B,UAcvC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,UAmBvC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACzC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,OAGV"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/core-data",
3
- "version": "7.4.0",
3
+ "version": "7.6.0",
4
4
  "description": "Access to and manipulation of core WordPress entities.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -32,22 +32,22 @@
32
32
  ],
33
33
  "dependencies": {
34
34
  "@babel/runtime": "^7.16.0",
35
- "@wordpress/api-fetch": "^7.4.0",
36
- "@wordpress/block-editor": "^13.4.0",
37
- "@wordpress/blocks": "^13.4.0",
38
- "@wordpress/compose": "^7.4.0",
39
- "@wordpress/data": "^10.4.0",
40
- "@wordpress/deprecated": "^4.4.0",
41
- "@wordpress/element": "^6.4.0",
42
- "@wordpress/html-entities": "^4.4.0",
43
- "@wordpress/i18n": "^5.4.0",
44
- "@wordpress/is-shallow-equal": "^5.4.0",
45
- "@wordpress/private-apis": "^1.4.0",
46
- "@wordpress/rich-text": "^7.4.0",
47
- "@wordpress/sync": "^1.4.0",
48
- "@wordpress/undo-manager": "^1.4.0",
49
- "@wordpress/url": "^4.4.0",
50
- "@wordpress/warning": "^3.4.0",
35
+ "@wordpress/api-fetch": "^7.6.0",
36
+ "@wordpress/block-editor": "^14.1.0",
37
+ "@wordpress/blocks": "^13.6.0",
38
+ "@wordpress/compose": "^7.6.0",
39
+ "@wordpress/data": "^10.6.0",
40
+ "@wordpress/deprecated": "^4.6.0",
41
+ "@wordpress/element": "^6.6.0",
42
+ "@wordpress/html-entities": "^4.6.0",
43
+ "@wordpress/i18n": "^5.6.0",
44
+ "@wordpress/is-shallow-equal": "^5.6.0",
45
+ "@wordpress/private-apis": "^1.6.0",
46
+ "@wordpress/rich-text": "^7.6.0",
47
+ "@wordpress/sync": "^1.6.0",
48
+ "@wordpress/undo-manager": "^1.6.0",
49
+ "@wordpress/url": "^4.6.0",
50
+ "@wordpress/warning": "^3.6.0",
51
51
  "change-case": "^4.1.2",
52
52
  "equivalent-key-map": "^0.2.2",
53
53
  "fast-deep-equal": "^3.1.3",
@@ -61,5 +61,5 @@
61
61
  "publishConfig": {
62
62
  "access": "public"
63
63
  },
64
- "gitHead": "363edb39b8dda8727f652e42cbb8497732693ed2"
64
+ "gitHead": "ab9564947967bb3f00343130954b9efacba6cdd7"
65
65
  }
package/src/actions.js CHANGED
@@ -200,7 +200,7 @@ export function __experimentalReceiveThemeGlobalStyleVariations(
200
200
  /**
201
201
  * Returns an action object used in signalling that the index has been received.
202
202
  *
203
- * @deprecated since WP 5.9, this is not useful anymore, use the selector direclty.
203
+ * @deprecated since WP 5.9, this is not useful anymore, use the selector directly.
204
204
  *
205
205
  * @return {Object} Action object.
206
206
  */
@@ -73,6 +73,10 @@ declare module './base-entity-records' {
73
73
  * Post ID.
74
74
  */
75
75
  wp_id: number;
76
+ /**
77
+ * Plugin that registered the template.
78
+ */
79
+ plugin?: string;
76
80
  /**
77
81
  * Theme file exists.
78
82
  */
@@ -6,7 +6,7 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
- import { unlock } from '../private-apis';
9
+ import { unlock } from '../lock-unlock';
10
10
 
11
11
  // TODO: The following line should have been:
12
12
  //
@@ -4,6 +4,7 @@
4
4
  import { addQueryArgs } from '@wordpress/url';
5
5
  import deprecated from '@wordpress/deprecated';
6
6
  import { useSelect } from '@wordpress/data';
7
+ import { useMemo } from '@wordpress/element';
7
8
 
8
9
  /**
9
10
  * Internal dependencies
@@ -12,6 +13,7 @@ import useQuerySelect from './use-query-select';
12
13
  import { store as coreStore } from '../';
13
14
  import type { Options } from './use-entity-record';
14
15
  import type { Status } from './constants';
16
+ import { unlock } from '../lock-unlock';
15
17
 
16
18
  interface EntityRecordsResolution< RecordType > {
17
19
  /** The requested entity record */
@@ -152,3 +154,51 @@ export function __experimentalUseEntityRecords(
152
154
  } );
153
155
  return useEntityRecords( kind, name, queryArgs, options );
154
156
  }
157
+
158
+ export function useEntityRecordsWithPermissions< RecordType >(
159
+ kind: string,
160
+ name: string,
161
+ queryArgs: Record< string, unknown > = {},
162
+ options: Options = { enabled: true }
163
+ ): EntityRecordsResolution< RecordType > {
164
+ const entityConfig = useSelect(
165
+ ( select ) => select( coreStore ).getEntityConfig( kind, name ),
166
+ [ kind, name ]
167
+ );
168
+ const { records: data, ...ret } = useEntityRecords(
169
+ kind,
170
+ name,
171
+ queryArgs,
172
+ options
173
+ );
174
+ const ids = useMemo(
175
+ () =>
176
+ data?.map(
177
+ // @ts-ignore
178
+ ( record: RecordType ) => record[ entityConfig?.key ?? 'id' ]
179
+ ) ?? [],
180
+ [ data, entityConfig?.key ]
181
+ );
182
+
183
+ const permissions = useSelect(
184
+ ( select ) => {
185
+ const { getEntityRecordsPermissions } = unlock(
186
+ select( coreStore )
187
+ );
188
+ return getEntityRecordsPermissions( kind, name, ids );
189
+ },
190
+ [ ids, kind, name ]
191
+ );
192
+
193
+ const dataWithPermissions = useMemo(
194
+ () =>
195
+ data?.map( ( record, index ) => ( {
196
+ // @ts-ignore
197
+ ...record,
198
+ permissions: permissions[ index ],
199
+ } ) ) ?? [],
200
+ [ data, permissions ]
201
+ );
202
+
203
+ return { records: dataWithPermissions, ...ret };
204
+ }
package/src/index.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  getMethodName,
19
19
  } from './entities';
20
20
  import { STORE_NAME } from './name';
21
- import { unlock } from './private-apis';
21
+ import { unlock } from './lock-unlock';
22
22
 
23
23
  // The entity selectors/resolvers and actions are shortcuts to their generic equivalents
24
24
  // (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)
@@ -86,3 +86,4 @@ export * from './entity-provider';
86
86
  export * from './entity-types';
87
87
  export * from './fetch';
88
88
  export * from './hooks';
89
+ export * from './private-apis';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
5
+
6
+ export const { lock, unlock } =
7
+ __dangerousOptInToUnstableAPIsOnlyForCoreModules(
8
+ 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
9
+ '@wordpress/core-data'
10
+ );
@@ -1,10 +1,10 @@
1
1
  /**
2
- * WordPress dependencies
2
+ * Internal dependencies
3
3
  */
4
- import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
4
+ import { useEntityRecordsWithPermissions } from './hooks/use-entity-records';
5
+ import { lock } from './lock-unlock';
5
6
 
6
- export const { lock, unlock } =
7
- __dangerousOptInToUnstableAPIsOnlyForCoreModules(
8
- 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
9
- '@wordpress/core-data'
10
- );
7
+ export const privateApis = {};
8
+ lock( privateApis, {
9
+ useEntityRecordsWithPermissions,
10
+ } );
@@ -50,3 +50,46 @@ export const getBlockPatternsForPostType = createRegistrySelector(
50
50
  () => [ select( STORE_NAME ).getBlockPatterns() ]
51
51
  )
52
52
  );
53
+
54
+ /**
55
+ * Returns the entity records permissions for the given entity record ids.
56
+ */
57
+ export const getEntityRecordsPermissions = createRegistrySelector( ( select ) =>
58
+ createSelector(
59
+ ( state: State, kind: string, name: string, ids: string[] ) => {
60
+ const normalizedIds = Array.isArray( ids ) ? ids : [ ids ];
61
+ return normalizedIds.map( ( id ) => ( {
62
+ delete: select( STORE_NAME ).canUser( 'delete', {
63
+ kind,
64
+ name,
65
+ id,
66
+ } ),
67
+ update: select( STORE_NAME ).canUser( 'update', {
68
+ kind,
69
+ name,
70
+ id,
71
+ } ),
72
+ } ) );
73
+ },
74
+ ( state ) => [ state.userPermissions ]
75
+ )
76
+ );
77
+
78
+ /**
79
+ * Returns the entity record permissions for the given entity record id.
80
+ *
81
+ * @param state Data state.
82
+ * @param kind Entity kind.
83
+ * @param name Entity name.
84
+ * @param id Entity record id.
85
+ *
86
+ * @return The entity record permissions.
87
+ */
88
+ export function getEntityRecordPermissions(
89
+ state: State,
90
+ kind: string,
91
+ name: string,
92
+ id: string
93
+ ) {
94
+ return getEntityRecordsPermissions( state, kind, name, id )[ 0 ];
95
+ }