@wordpress/core-data 6.16.0 → 6.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/actions.js +69 -134
  3. package/build/actions.js.map +1 -1
  4. package/build/batch/create-batch.js +0 -22
  5. package/build/batch/create-batch.js.map +1 -1
  6. package/build/batch/default-processor.js +3 -15
  7. package/build/batch/default-processor.js.map +1 -1
  8. package/build/batch/index.js +0 -3
  9. package/build/batch/index.js.map +1 -1
  10. package/build/entities.js +109 -36
  11. package/build/entities.js.map +1 -1
  12. package/build/entity-provider.js +34 -53
  13. package/build/entity-provider.js.map +1 -1
  14. package/build/entity-types/attachment.js.map +1 -1
  15. package/build/entity-types/base-entity-records.js +0 -3
  16. package/build/entity-types/base-entity-records.js.map +1 -1
  17. package/build/entity-types/comment.js.map +1 -1
  18. package/build/entity-types/helpers.js.map +1 -1
  19. package/build/entity-types/index.js.map +1 -1
  20. package/build/entity-types/menu-location.js.map +1 -1
  21. package/build/entity-types/nav-menu-item.js.map +1 -1
  22. package/build/entity-types/nav-menu.js.map +1 -1
  23. package/build/entity-types/page.js.map +1 -1
  24. package/build/entity-types/plugin.js.map +1 -1
  25. package/build/entity-types/post.js.map +1 -1
  26. package/build/entity-types/settings.js.map +1 -1
  27. package/build/entity-types/sidebar.js.map +1 -1
  28. package/build/entity-types/taxonomy.js.map +1 -1
  29. package/build/entity-types/theme.js.map +1 -1
  30. package/build/entity-types/type.js.map +1 -1
  31. package/build/entity-types/user.js.map +1 -1
  32. package/build/entity-types/widget-type.js.map +1 -1
  33. package/build/entity-types/widget.js.map +1 -1
  34. package/build/entity-types/wp-template-part.js.map +1 -1
  35. package/build/entity-types/wp-template.js.map +1 -1
  36. package/build/fetch/__experimental-fetch-link-suggestions.js +14 -20
  37. package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  38. package/build/fetch/__experimental-fetch-url-data.js +4 -13
  39. package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
  40. package/build/fetch/index.js +0 -3
  41. package/build/fetch/index.js.map +1 -1
  42. package/build/hooks/constants.js +4 -5
  43. package/build/hooks/constants.js.map +1 -1
  44. package/build/hooks/index.js +0 -5
  45. package/build/hooks/index.js.map +1 -1
  46. package/build/hooks/memoize.js +0 -3
  47. package/build/hooks/memoize.js.map +1 -1
  48. package/build/hooks/use-entity-record.js +0 -9
  49. package/build/hooks/use-entity-record.js.map +1 -1
  50. package/build/hooks/use-entity-records.js +2 -9
  51. package/build/hooks/use-entity-records.js.map +1 -1
  52. package/build/hooks/use-query-select.js +1 -13
  53. package/build/hooks/use-query-select.js.map +1 -1
  54. package/build/hooks/use-resource-permissions.js +0 -15
  55. package/build/hooks/use-resource-permissions.js.map +1 -1
  56. package/build/index.js +9 -41
  57. package/build/index.js.map +1 -1
  58. package/build/locks/actions.js +1 -6
  59. package/build/locks/actions.js.map +1 -1
  60. package/build/locks/engine.js +1 -9
  61. package/build/locks/engine.js.map +1 -1
  62. package/build/locks/reducer.js +8 -9
  63. package/build/locks/reducer.js.map +1 -1
  64. package/build/locks/selectors.js +8 -11
  65. package/build/locks/selectors.js.map +1 -1
  66. package/build/locks/utils.js +4 -19
  67. package/build/locks/utils.js.map +1 -1
  68. package/build/name.js +0 -1
  69. package/build/name.js.map +1 -1
  70. package/build/private-apis.js +1 -2
  71. package/build/private-apis.js.map +1 -1
  72. package/build/private-selectors.js +2 -5
  73. package/build/private-selectors.js.map +1 -1
  74. package/build/queried-data/actions.js +4 -6
  75. package/build/queried-data/actions.js.map +1 -1
  76. package/build/queried-data/get-query-parts.js +11 -24
  77. package/build/queried-data/get-query-parts.js.map +1 -1
  78. package/build/queried-data/index.js +0 -6
  79. package/build/queried-data/index.js.map +1 -1
  80. package/build/queried-data/reducer.js +33 -51
  81. package/build/queried-data/reducer.js.map +1 -1
  82. package/build/queried-data/selectors.js +4 -25
  83. package/build/queried-data/selectors.js.map +1 -1
  84. package/build/reducer.js +76 -128
  85. package/build/reducer.js.map +1 -1
  86. package/build/resolvers.js +91 -133
  87. package/build/resolvers.js.map +1 -1
  88. package/build/selectors.js +51 -145
  89. package/build/selectors.js.map +1 -1
  90. package/build/sync.js +19 -0
  91. package/build/sync.js.map +1 -0
  92. package/build/types.js.map +1 -1
  93. package/build/utils/conservative-map-item.js +3 -10
  94. package/build/utils/conservative-map-item.js.map +1 -1
  95. package/build/utils/forward-resolver.js +0 -2
  96. package/build/utils/forward-resolver.js.map +1 -1
  97. package/build/utils/get-normalized-comma-separable.js +0 -3
  98. package/build/utils/get-normalized-comma-separable.js.map +1 -1
  99. package/build/utils/if-matching-action.js +0 -3
  100. package/build/utils/if-matching-action.js.map +1 -1
  101. package/build/utils/index.js +0 -10
  102. package/build/utils/index.js.map +1 -1
  103. package/build/utils/is-raw-attribute.js +0 -1
  104. package/build/utils/is-raw-attribute.js.map +1 -1
  105. package/build/utils/on-sub-key.js +5 -9
  106. package/build/utils/on-sub-key.js.map +1 -1
  107. package/build/utils/replace-action.js +0 -2
  108. package/build/utils/replace-action.js.map +1 -1
  109. package/build/utils/set-nested-value.js +0 -4
  110. package/build/utils/set-nested-value.js.map +1 -1
  111. package/build/utils/with-weak-map-cache.js +3 -6
  112. package/build/utils/with-weak-map-cache.js.map +1 -1
  113. package/build-module/actions.js +72 -95
  114. package/build-module/actions.js.map +1 -1
  115. package/build-module/batch/create-batch.js +1 -20
  116. package/build-module/batch/create-batch.js.map +1 -1
  117. package/build-module/batch/default-processor.js +4 -13
  118. package/build-module/batch/default-processor.js.map +1 -1
  119. package/build-module/batch/index.js.map +1 -1
  120. package/build-module/entities.js +109 -25
  121. package/build-module/entities.js.map +1 -1
  122. package/build-module/entity-provider.js +35 -45
  123. package/build-module/entity-provider.js.map +1 -1
  124. package/build-module/entity-types/attachment.js.map +1 -1
  125. package/build-module/entity-types/base-entity-records.js +0 -2
  126. package/build-module/entity-types/base-entity-records.js.map +1 -1
  127. package/build-module/entity-types/comment.js.map +1 -1
  128. package/build-module/entity-types/helpers.js.map +1 -1
  129. package/build-module/entity-types/index.js.map +1 -1
  130. package/build-module/entity-types/menu-location.js.map +1 -1
  131. package/build-module/entity-types/nav-menu-item.js.map +1 -1
  132. package/build-module/entity-types/nav-menu.js.map +1 -1
  133. package/build-module/entity-types/page.js.map +1 -1
  134. package/build-module/entity-types/plugin.js.map +1 -1
  135. package/build-module/entity-types/post.js.map +1 -1
  136. package/build-module/entity-types/settings.js.map +1 -1
  137. package/build-module/entity-types/sidebar.js.map +1 -1
  138. package/build-module/entity-types/taxonomy.js.map +1 -1
  139. package/build-module/entity-types/theme.js.map +1 -1
  140. package/build-module/entity-types/type.js.map +1 -1
  141. package/build-module/entity-types/user.js.map +1 -1
  142. package/build-module/entity-types/widget-type.js.map +1 -1
  143. package/build-module/entity-types/widget.js.map +1 -1
  144. package/build-module/entity-types/wp-template-part.js.map +1 -1
  145. package/build-module/entity-types/wp-template.js.map +1 -1
  146. package/build-module/fetch/__experimental-fetch-link-suggestions.js +15 -15
  147. package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  148. package/build-module/fetch/__experimental-fetch-url-data.js +5 -10
  149. package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
  150. package/build-module/fetch/index.js.map +1 -1
  151. package/build-module/hooks/constants.js +3 -4
  152. package/build-module/hooks/constants.js.map +1 -1
  153. package/build-module/hooks/index.js.map +1 -1
  154. package/build-module/hooks/memoize.js +2 -1
  155. package/build-module/hooks/memoize.js.map +1 -1
  156. package/build-module/hooks/use-entity-record.js +1 -3
  157. package/build-module/hooks/use-entity-record.js.map +1 -1
  158. package/build-module/hooks/use-entity-records.js +2 -3
  159. package/build-module/hooks/use-entity-records.js.map +1 -1
  160. package/build-module/hooks/use-query-select.js +1 -9
  161. package/build-module/hooks/use-query-select.js.map +1 -1
  162. package/build-module/hooks/use-resource-permissions.js +1 -10
  163. package/build-module/hooks/use-resource-permissions.js.map +1 -1
  164. package/build-module/index.js +11 -19
  165. package/build-module/index.js.map +1 -1
  166. package/build-module/locks/actions.js +0 -3
  167. package/build-module/locks/actions.js.map +1 -1
  168. package/build-module/locks/engine.js +0 -5
  169. package/build-module/locks/engine.js.map +1 -1
  170. package/build-module/locks/reducer.js +7 -7
  171. package/build-module/locks/reducer.js.map +1 -1
  172. package/build-module/locks/selectors.js +7 -8
  173. package/build-module/locks/selectors.js.map +1 -1
  174. package/build-module/locks/utils.js +4 -14
  175. package/build-module/locks/utils.js.map +1 -1
  176. package/build-module/name.js.map +1 -1
  177. package/build-module/private-apis.js.map +1 -1
  178. package/build-module/private-selectors.js +2 -2
  179. package/build-module/private-selectors.js.map +1 -1
  180. package/build-module/queried-data/actions.js +4 -3
  181. package/build-module/queried-data/actions.js.map +1 -1
  182. package/build-module/queried-data/get-query-parts.js +13 -21
  183. package/build-module/queried-data/get-query-parts.js.map +1 -1
  184. package/build-module/queried-data/index.js.map +1 -1
  185. package/build-module/queried-data/reducer.js +33 -42
  186. package/build-module/queried-data/reducer.js.map +1 -1
  187. package/build-module/queried-data/selectors.js +6 -21
  188. package/build-module/queried-data/selectors.js.map +1 -1
  189. package/build-module/reducer.js +79 -104
  190. package/build-module/reducer.js.map +1 -1
  191. package/build-module/resolvers.js +94 -96
  192. package/build-module/resolvers.js.map +1 -1
  193. package/build-module/selectors.js +56 -92
  194. package/build-module/selectors.js.map +1 -1
  195. package/build-module/sync.js +12 -0
  196. package/build-module/sync.js.map +1 -0
  197. package/build-module/types.js.map +1 -1
  198. package/build-module/utils/conservative-map-item.js +4 -8
  199. package/build-module/utils/conservative-map-item.js.map +1 -1
  200. package/build-module/utils/forward-resolver.js +0 -1
  201. package/build-module/utils/forward-resolver.js.map +1 -1
  202. package/build-module/utils/get-normalized-comma-separable.js +0 -2
  203. package/build-module/utils/get-normalized-comma-separable.js.map +1 -1
  204. package/build-module/utils/if-matching-action.js +0 -2
  205. package/build-module/utils/if-matching-action.js.map +1 -1
  206. package/build-module/utils/index.js.map +1 -1
  207. package/build-module/utils/is-raw-attribute.js.map +1 -1
  208. package/build-module/utils/on-sub-key.js +5 -7
  209. package/build-module/utils/on-sub-key.js.map +1 -1
  210. package/build-module/utils/replace-action.js +0 -1
  211. package/build-module/utils/replace-action.js.map +1 -1
  212. package/build-module/utils/set-nested-value.js +0 -3
  213. package/build-module/utils/set-nested-value.js.map +1 -1
  214. package/build-module/utils/with-weak-map-cache.js +3 -5
  215. package/build-module/utils/with-weak-map-cache.js.map +1 -1
  216. package/build-types/actions.d.ts.map +1 -1
  217. package/build-types/entities.d.ts +53 -0
  218. package/build-types/entities.d.ts.map +1 -1
  219. package/build-types/entity-provider.d.ts +1 -1
  220. package/build-types/entity-provider.d.ts.map +1 -1
  221. package/build-types/hooks/memoize.d.ts +1 -1
  222. package/build-types/hooks/memoize.d.ts.map +1 -1
  223. package/build-types/index.d.ts +3 -3
  224. package/build-types/index.d.ts.map +1 -1
  225. package/build-types/resolvers.d.ts.map +1 -1
  226. package/build-types/sync.d.ts +2 -0
  227. package/build-types/sync.d.ts.map +1 -0
  228. package/package.json +17 -15
  229. package/src/actions.js +24 -14
  230. package/src/entities.js +91 -0
  231. package/src/entity-provider.js +11 -2
  232. package/src/resolvers.js +89 -41
  233. package/src/sync.js +18 -0
  234. package/src/test/entity-provider.js +272 -0
  235. package/tsconfig.json +1 -0
  236. package/tsconfig.tsbuildinfo +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/fetch/index.js"],"names":["default","__experimentalFetchLinkSuggestions","__experimentalFetchUrlData"],"mappings":"AAAA,SAASA,OAAO,IAAIC,kCAApB,QAA8D,yCAA9D;AACA,SAASD,OAAO,IAAIE,0BAApB,QAAsD,iCAAtD","sourcesContent":["export { default as __experimentalFetchLinkSuggestions } from './__experimental-fetch-link-suggestions';\nexport { default as __experimentalFetchUrlData } from './__experimental-fetch-url-data';\n"]}
1
+ {"version":3,"names":["default","__experimentalFetchLinkSuggestions","__experimentalFetchUrlData"],"sources":["@wordpress/core-data/src/fetch/index.js"],"sourcesContent":["export { default as __experimentalFetchLinkSuggestions } from './__experimental-fetch-link-suggestions';\nexport { default as __experimentalFetchUrlData } from './__experimental-fetch-url-data';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,kCAAkC,QAAQ,yCAAyC;AACvG,SAASD,OAAO,IAAIE,0BAA0B,QAAQ,iCAAiC"}
@@ -1,9 +1,8 @@
1
- export let Status;
2
-
3
- (function (Status) {
1
+ export let Status = /*#__PURE__*/function (Status) {
4
2
  Status["Idle"] = "IDLE";
5
3
  Status["Resolving"] = "RESOLVING";
6
4
  Status["Error"] = "ERROR";
7
5
  Status["Success"] = "SUCCESS";
8
- })(Status || (Status = {}));
6
+ return Status;
7
+ }({});
9
8
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/constants.ts"],"names":["Status"],"mappings":"AAAA,WAAkBA,MAAlB;;WAAkBA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;GAAAA,M,KAAAA,M","sourcesContent":["export const enum Status {\n\tIdle = 'IDLE',\n\tResolving = 'RESOLVING',\n\tError = 'ERROR',\n\tSuccess = 'SUCCESS',\n}\n"]}
1
+ {"version":3,"names":["Status"],"sources":["@wordpress/core-data/src/hooks/constants.ts"],"sourcesContent":["export const enum Status {\n\tIdle = 'IDLE',\n\tResolving = 'RESOLVING',\n\tError = 'ERROR',\n\tSuccess = 'SUCCESS',\n}\n"],"mappings":"AAAA,WAAkBA,MAAM,0BAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAAA,OAANA,MAAM;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/index.ts"],"names":["default","useEntityRecord","__experimentalUseEntityRecord","useEntityRecords","__experimentalUseEntityRecords","useResourcePermissions","__experimentalUseResourcePermissions"],"mappings":"AAAA,SACCA,OAAO,IAAIC,eADZ,EAECC,6BAFD,QAGO,qBAHP;AAIA,SACCF,OAAO,IAAIG,gBADZ,EAECC,8BAFD,QAGO,sBAHP;AAIA,SACCJ,OAAO,IAAIK,sBADZ,EAECC,oCAFD,QAGO,4BAHP","sourcesContent":["export {\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';\n"]}
1
+ {"version":3,"names":["default","useEntityRecord","__experimentalUseEntityRecord","useEntityRecords","__experimentalUseEntityRecords","useResourcePermissions","__experimentalUseResourcePermissions"],"sources":["@wordpress/core-data/src/hooks/index.ts"],"sourcesContent":["export {\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';\n"],"mappings":"AAAA,SACCA,OAAO,IAAIC,eAAe,EAC1BC,6BAA6B,QACvB,qBAAqB;AAC5B,SACCF,OAAO,IAAIG,gBAAgB,EAC3BC,8BAA8B,QACxB,sBAAsB;AAC7B,SACCJ,OAAO,IAAIK,sBAAsB,EACjCC,oCAAoC,QAC9B,4BAA4B"}
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import memoize from 'memize'; // re-export due to restrictive esModuleInterop setting
4
+ import memoize from 'memize';
5
5
 
6
+ // re-export due to restrictive esModuleInterop setting
6
7
  export default memoize;
7
8
  //# sourceMappingURL=memoize.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/memoize.js"],"names":["memoize"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,QAApB,C,CAEA;;AACA,eAAeA,OAAf","sourcesContent":["/**\n * External dependencies\n */\nimport memoize from 'memize';\n\n// re-export due to restrictive esModuleInterop setting\nexport default memoize;\n"]}
1
+ {"version":3,"names":["memoize"],"sources":["@wordpress/core-data/src/hooks/memoize.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport memoize from 'memize';\n\n// re-export due to restrictive esModuleInterop setting\nexport default memoize;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,OAAO,MAAM,QAAQ;;AAE5B;AACA,eAAeA,OAAO"}
@@ -4,13 +4,12 @@
4
4
  import { useDispatch, useSelect } from '@wordpress/data';
5
5
  import deprecated from '@wordpress/deprecated';
6
6
  import { useMemo } from '@wordpress/element';
7
+
7
8
  /**
8
9
  * Internal dependencies
9
10
  */
10
-
11
11
  import useQuerySelect from './use-query-select';
12
12
  import { store as coreStore } from '../';
13
-
14
13
  /**
15
14
  * Resolves the specified entity record.
16
15
  *
@@ -129,7 +128,6 @@ export default function useEntityRecord(kind, name, recordId, options = {
129
128
  data: null
130
129
  };
131
130
  }
132
-
133
131
  return query(coreStore).getEntityRecord(kind, name, recordId);
134
132
  }, [kind, name, recordId, options.enabled]);
135
133
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["useDispatch","useSelect","deprecated","useMemo","useQuerySelect","store","coreStore","useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","mutations","edit","record","save","saveOptions","throwOnError","editedRecord","hasEdits","select","getEditedEntityRecord","hasEditsForEntityRecord","data","querySelectRest","query","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AACA,SAASC,OAAT,QAAwB,oBAAxB;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,KAAK,IAAIC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E,MAAM,CAAEjB,SAAF,CAAN,CAAoBkB,qBAApB,CACbhB,IADa,EAEbC,IAFa,EAGbC,QAHa,CADC;AAMfY,IAAAA,QAAQ,EAAEC,MAAM,CAAEjB,SAAF,CAAN,CAAoBmB,uBAApB,CACTjB,IADS,EAETC,IAFS,EAGTC,QAHS;AANK,GAAhB,CAD2C,EAa3C,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,CAb2C,CAA5C;AAgBA,QAAM;AAAEgB,IAAAA,IAAI,EAAET,MAAR;AAAgB,OAAGU;AAAnB,MAAuCvB,cAAc,CACxDwB,KAAF,IAAa;AACZ,QAAK,CAAEjB,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO;AACNc,QAAAA,IAAI,EAAE;AADA,OAAP;AAGA;;AACD,WAAOE,KAAK,CAAEtB,SAAF,CAAL,CAAmBuB,eAAnB,CAAoCrB,IAApC,EAA0CC,IAA1C,EAAgDC,QAAhD,CAAP;AACA,GARyD,EAS1D,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAO,CAACC,OAAhC,CAT0D,CAA3D;AAYA,SAAO;AACNK,IAAAA,MADM;AAENI,IAAAA,YAFM;AAGNC,IAAAA,QAHM;AAIN,OAAGK,eAJG;AAKN,OAAGZ;AALG,GAAP;AAOA;AAED,OAAO,SAASe,6BAAT,CACNtB,IADM,EAENC,IAFM,EAGNC,QAHM,EAINC,OAJM,EAKL;AACDT,EAAAA,UAAU,CAAG,uCAAH,EAA2C;AACpD6B,IAAAA,WAAW,EAAE,yBADuC;AAEpDC,IAAAA,KAAK,EAAE;AAF6C,GAA3C,CAAV;AAIA,SAAOzB,eAAe,CAAEC,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAxB,CAAtB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\nexport interface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/** The edited entity record */\n\teditedRecord: Partial< RecordType >;\n\n\t/** Apply local (in-browser) edits to the edited entity record */\n\tedit: ( diff: Partial< RecordType > ) => void;\n\n\t/** Persist the edits to the server */\n\tsave: () => Promise< void >;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Does the record have any local edits?\n\t */\n\thasEdits: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nexport interface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\n/**\n * Resolves the specified entity record.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param recordId ID of the requested entity record.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @example\n * ```js\n * import { useDispatch } from '@wordpress/data';\n * import { useCallback } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n * import { TextControl } from '@wordpress/components';\n * import { store as noticeStore } from '@wordpress/notices';\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageRenameForm( { id } ) {\n * \tconst page = useEntityRecord( 'postType', 'page', id );\n * \tconst { createSuccessNotice, createErrorNotice } =\n * \t\tuseDispatch( noticeStore );\n *\n * \tconst setTitle = useCallback( ( title ) => {\n * \t\tpage.edit( { title } );\n * \t}, [ page.edit ] );\n *\n * \tif ( page.isResolving ) {\n * \t\treturn 'Loading...';\n * \t}\n *\n * \tasync function onRename( event ) {\n * \t\tevent.preventDefault();\n * \t\ttry {\n * \t\t\tawait page.save();\n * \t\t\tcreateSuccessNotice( __( 'Page renamed.' ), {\n * \t\t\t\ttype: 'snackbar',\n * \t\t\t} );\n * \t\t} catch ( error ) {\n * \t\t\tcreateErrorNotice( error.message, { type: 'snackbar' } );\n * \t\t}\n * \t}\n *\n * \treturn (\n * \t\t<form onSubmit={ onRename }>\n * \t\t\t<TextControl\n * \t\t\t\tlabel={ __( 'Name' ) }\n * \t\t\t\tvalue={ page.editedRecord.title }\n * \t\t\t\tonChange={ setTitle }\n * \t\t\t/>\n * \t\t\t<button type=\"submit\">{ __( 'Save' ) }</button>\n * \t\t</form>\n * \t);\n * }\n *\n * // Rendered in the application:\n * // <PageRenameForm id={ 1 } />\n * ```\n *\n * In the above example, updating and saving the page title is handled\n * via the `edit()` and `save()` mutation helpers provided by\n * `useEntityRecord()`;\n *\n * @return Entity record data.\n * @template RecordType\n */\nexport default function useEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\n\tconst mutations = useMemo(\n\t\t() => ( {\n\t\t\tedit: ( record ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record ),\n\t\t\tsave: ( saveOptions: any = {} ) =>\n\t\t\t\tsaveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t...saveOptions,\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ editEntityRecord, kind, name, recordId, saveEditedEntityRecord ]\n\t);\n\n\tconst { editedRecord, hasEdits } = useSelect(\n\t\t( select ) => ( {\n\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t} ),\n\t\t[ kind, name, recordId ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\tdata: null,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\teditedRecord,\n\t\thasEdits,\n\t\t...querySelectRest,\n\t\t...mutations,\n\t};\n}\n\nexport function __experimentalUseEntityRecord(\n\tkind: string,\n\tname: string,\n\trecordId: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecord`, {\n\t\talternative: 'wp.data.useEntityRecord',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecord( kind, name, recordId, options );\n}\n"]}
1
+ {"version":3,"names":["useDispatch","useSelect","deprecated","useMemo","useQuerySelect","store","coreStore","useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","mutations","edit","record","save","saveOptions","throwOnError","editedRecord","hasEdits","select","getEditedEntityRecord","hasEditsForEntityRecord","data","querySelectRest","query","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\nexport interface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/** The edited entity record */\n\teditedRecord: Partial< RecordType >;\n\n\t/** Apply local (in-browser) edits to the edited entity record */\n\tedit: ( diff: Partial< RecordType > ) => void;\n\n\t/** Persist the edits to the server */\n\tsave: () => Promise< void >;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Does the record have any local edits?\n\t */\n\thasEdits: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nexport interface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\n/**\n * Resolves the specified entity record.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param recordId ID of the requested entity record.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @example\n * ```js\n * import { useDispatch } from '@wordpress/data';\n * import { useCallback } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n * import { TextControl } from '@wordpress/components';\n * import { store as noticeStore } from '@wordpress/notices';\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageRenameForm( { id } ) {\n * \tconst page = useEntityRecord( 'postType', 'page', id );\n * \tconst { createSuccessNotice, createErrorNotice } =\n * \t\tuseDispatch( noticeStore );\n *\n * \tconst setTitle = useCallback( ( title ) => {\n * \t\tpage.edit( { title } );\n * \t}, [ page.edit ] );\n *\n * \tif ( page.isResolving ) {\n * \t\treturn 'Loading...';\n * \t}\n *\n * \tasync function onRename( event ) {\n * \t\tevent.preventDefault();\n * \t\ttry {\n * \t\t\tawait page.save();\n * \t\t\tcreateSuccessNotice( __( 'Page renamed.' ), {\n * \t\t\t\ttype: 'snackbar',\n * \t\t\t} );\n * \t\t} catch ( error ) {\n * \t\t\tcreateErrorNotice( error.message, { type: 'snackbar' } );\n * \t\t}\n * \t}\n *\n * \treturn (\n * \t\t<form onSubmit={ onRename }>\n * \t\t\t<TextControl\n * \t\t\t\tlabel={ __( 'Name' ) }\n * \t\t\t\tvalue={ page.editedRecord.title }\n * \t\t\t\tonChange={ setTitle }\n * \t\t\t/>\n * \t\t\t<button type=\"submit\">{ __( 'Save' ) }</button>\n * \t\t</form>\n * \t);\n * }\n *\n * // Rendered in the application:\n * // <PageRenameForm id={ 1 } />\n * ```\n *\n * In the above example, updating and saving the page title is handled\n * via the `edit()` and `save()` mutation helpers provided by\n * `useEntityRecord()`;\n *\n * @return Entity record data.\n * @template RecordType\n */\nexport default function useEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\n\tconst mutations = useMemo(\n\t\t() => ( {\n\t\t\tedit: ( record ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record ),\n\t\t\tsave: ( saveOptions: any = {} ) =>\n\t\t\t\tsaveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t...saveOptions,\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ editEntityRecord, kind, name, recordId, saveEditedEntityRecord ]\n\t);\n\n\tconst { editedRecord, hasEdits } = useSelect(\n\t\t( select ) => ( {\n\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t} ),\n\t\t[ kind, name, recordId ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\tdata: null,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\teditedRecord,\n\t\thasEdits,\n\t\t...querySelectRest,\n\t\t...mutations,\n\t};\n}\n\nexport function __experimentalUseEntityRecord(\n\tkind: string,\n\tname: string,\n\trecordId: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecord`, {\n\t\talternative: 'wp.data.useEntityRecord',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecord( kind, name, recordId, options );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,OAAOC,UAAU,MAAM,uBAAuB;AAC9C,SAASC,OAAO,QAAQ,oBAAoB;;AAE5C;AACA;AACA;AACA,OAAOC,cAAc,MAAM,oBAAoB;AAC/C,SAASC,KAAK,IAAIC,SAAS,QAAQ,KAAK;AA4CxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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,EACJC,QACD;EACD,CAAC,CAAE,EACH,CAAEF,IAAI,EAAEC,IAAI,EAAEC,QAAQ,CACvB,CAAC;EAED,MAAM;IAAEgB,IAAI,EAAET,MAAM;IAAE,GAAGU;EAAgB,CAAC,GAAGvB,cAAc,CACxDwB,KAAK,IAAM;IACZ,IAAK,CAAEjB,OAAO,CAACC,OAAO,EAAG;MACxB,OAAO;QACNc,IAAI,EAAE;MACP,CAAC;IACF;IACA,OAAOE,KAAK,CAAEtB,SAAU,CAAC,CAACuB,eAAe,CAAErB,IAAI,EAAEC,IAAI,EAAEC,QAAS,CAAC;EAClE,CAAC,EACD,CAAEF,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,CAACC,OAAO,CACxC,CAAC;EAED,OAAO;IACNK,MAAM;IACNI,YAAY;IACZC,QAAQ;IACR,GAAGK,eAAe;IAClB,GAAGZ;EACJ,CAAC;AACF;AAEA,OAAO,SAASe,6BAA6BA,CAC5CtB,IAAY,EACZC,IAAY,EACZC,QAAa,EACbC,OAAY,EACX;EACDT,UAAU,CAAG,uCAAsC,EAAE;IACpD6B,WAAW,EAAE,yBAAyB;IACtCC,KAAK,EAAE;EACR,CAAE,CAAC;EACH,OAAOzB,eAAe,CAAEC,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAQ,CAAC;AACxD"}
@@ -3,13 +3,14 @@
3
3
  */
4
4
  import { addQueryArgs } from '@wordpress/url';
5
5
  import deprecated from '@wordpress/deprecated';
6
+
6
7
  /**
7
8
  * Internal dependencies
8
9
  */
9
-
10
10
  import useQuerySelect from './use-query-select';
11
11
  import { store as coreStore } from '../';
12
12
  const EMPTY_ARRAY = [];
13
+
13
14
  /**
14
15
  * Resolves the specified entity records.
15
16
  *
@@ -50,7 +51,6 @@ const EMPTY_ARRAY = [];
50
51
  * @return Entity records data.
51
52
  * @template RecordType
52
53
  */
53
-
54
54
  export default function useEntityRecords(kind, name, queryArgs = {}, options = {
55
55
  enabled: true
56
56
  }) {
@@ -69,7 +69,6 @@ export default function useEntityRecords(kind, name, queryArgs = {}, options = {
69
69
  data: EMPTY_ARRAY
70
70
  };
71
71
  }
72
-
73
72
  return query(coreStore).getEntityRecords(kind, name, queryArgs);
74
73
  }, [kind, name, queryAsString, options.enabled]);
75
74
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["addQueryArgs","deprecated","useQuerySelect","store","coreStore","EMPTY_ARRAY","useEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","data","records","rest","query","getEntityRecords","__experimentalUseEntityRecords","alternative","since"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,gBAA7B;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,KAAnC;AAsBA,MAAMC,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,gBAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,SAAoC,GAAG,EAHzB,EAIdC,OAAgB,GAAG;AAAEC,EAAAA,OAAO,EAAE;AAAX,CAJL,EAK0B;AACxC;AACA;AACA;AACA;AACA,QAAMC,aAAa,GAAGZ,YAAY,CAAE,EAAF,EAAMS,SAAN,CAAlC;AAEA,QAAM;AAAEI,IAAAA,IAAI,EAAEC,OAAR;AAAiB,OAAGC;AAApB,MAA6Bb,cAAc,CAC9Cc,KAAF,IAAa;AACZ,QAAK,CAAEN,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO;AACN;AACAE,QAAAA,IAAI,EAAER;AAFA,OAAP;AAIA;;AACD,WAAOW,KAAK,CAAEZ,SAAF,CAAL,CAAmBa,gBAAnB,CAAqCV,IAArC,EAA2CC,IAA3C,EAAiDC,SAAjD,CAAP;AACA,GAT+C,EAUhD,CAAEF,IAAF,EAAQC,IAAR,EAAcI,aAAd,EAA6BF,OAAO,CAACC,OAArC,CAVgD,CAAjD;AAaA,SAAO;AACNG,IAAAA,OADM;AAEN,OAAGC;AAFG,GAAP;AAIA;AAED,OAAO,SAASG,8BAAT,CACNX,IADM,EAENC,IAFM,EAGNC,SAHM,EAINC,OAJM,EAKL;AACDT,EAAAA,UAAU,CAAG,wCAAH,EAA4C;AACrDkB,IAAAA,WAAW,EAAE,0BADwC;AAErDC,IAAAA,KAAK,EAAE;AAF8C,GAA5C,CAAV;AAIA,SAAOd,gBAAgB,CAAEC,IAAF,EAAQC,IAAR,EAAcC,SAAd,EAAyBC,OAAzB,CAAvB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport deprecated from '@wordpress/deprecated';\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';\n\ninterface EntityRecordsResolution< RecordType > {\n\t/** The requested entity record */\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\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\treturn {\n\t\trecords,\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"]}
1
+ {"version":3,"names":["addQueryArgs","deprecated","useQuerySelect","store","coreStore","EMPTY_ARRAY","useEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","data","records","rest","query","getEntityRecords","__experimentalUseEntityRecords","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport deprecated from '@wordpress/deprecated';\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';\n\ninterface EntityRecordsResolution< RecordType > {\n\t/** The requested entity record */\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\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\treturn {\n\t\trecords,\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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAY,QAAQ,gBAAgB;AAC7C,OAAOC,UAAU,MAAM,uBAAuB;;AAE9C;AACA;AACA;AACA,OAAOC,cAAc,MAAM,oBAAoB;AAC/C,SAASC,KAAK,IAAIC,SAAS,QAAQ,KAAK;AAsBxC,MAAMC,WAAW,GAAG,EAAE;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,gBAAgBA,CACvCC,IAAY,EACZC,IAAY,EACZC,SAAoC,GAAG,CAAC,CAAC,EACzCC,OAAgB,GAAG;EAAEC,OAAO,EAAE;AAAK,CAAC,EACI;EACxC;EACA;EACA;EACA;EACA,MAAMC,aAAa,GAAGZ,YAAY,CAAE,EAAE,EAAES,SAAU,CAAC;EAEnD,MAAM;IAAEI,IAAI,EAAEC,OAAO;IAAE,GAAGC;EAAK,CAAC,GAAGb,cAAc,CAC9Cc,KAAK,IAAM;IACZ,IAAK,CAAEN,OAAO,CAACC,OAAO,EAAG;MACxB,OAAO;QACN;QACAE,IAAI,EAAER;MACP,CAAC;IACF;IACA,OAAOW,KAAK,CAAEZ,SAAU,CAAC,CAACa,gBAAgB,CAAEV,IAAI,EAAEC,IAAI,EAAEC,SAAU,CAAC;EACpE,CAAC,EACD,CAAEF,IAAI,EAAEC,IAAI,EAAEI,aAAa,EAAEF,OAAO,CAACC,OAAO,CAC7C,CAAC;EAED,OAAO;IACNG,OAAO;IACP,GAAGC;EACJ,CAAC;AACF;AAEA,OAAO,SAASG,8BAA8BA,CAC7CX,IAAY,EACZC,IAAY,EACZC,SAAc,EACdC,OAAY,EACX;EACDT,UAAU,CAAG,wCAAuC,EAAE;IACrDkB,WAAW,EAAE,0BAA0B;IACvCC,KAAK,EAAE;EACR,CAAE,CAAC;EACH,OAAOd,gBAAgB,CAAEC,IAAI,EAAEC,IAAI,EAAEC,SAAS,EAAEC,OAAQ,CAAC;AAC1D"}
@@ -2,14 +2,13 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { useSelect } from '@wordpress/data';
5
+
5
6
  /**
6
7
  * Internal dependencies
7
8
  */
8
-
9
9
  import memoize from './memoize';
10
10
  import { Status } from './constants';
11
11
  export const META_SELECTORS = ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'];
12
-
13
12
  /**
14
13
  * Like useSelect, but the selectors return objects containing
15
14
  * both the original data AND the resolution info.
@@ -56,11 +55,9 @@ export const META_SELECTORS = ['getIsResolving', 'hasStartedResolution', 'hasFin
56
55
  export default function useQuerySelect(mapQuerySelect, deps) {
57
56
  return useSelect((select, registry) => {
58
57
  const resolve = store => enrichSelectors(select(store));
59
-
60
58
  return mapQuerySelect(resolve, registry);
61
59
  }, deps);
62
60
  }
63
-
64
61
  /**
65
62
  * Transform simple selectors into ones that return an object with the
66
63
  * original return value AND the resolution info.
@@ -70,12 +67,10 @@ export default function useQuerySelect(mapQuerySelect, deps) {
70
67
  */
71
68
  const enrichSelectors = memoize(selectors => {
72
69
  const resolvers = {};
73
-
74
70
  for (const selectorName in selectors) {
75
71
  if (META_SELECTORS.includes(selectorName)) {
76
72
  continue;
77
73
  }
78
-
79
74
  Object.defineProperty(resolvers, selectorName, {
80
75
  get: () => (...args) => {
81
76
  const {
@@ -86,7 +81,6 @@ const enrichSelectors = memoize(selectors => {
86
81
  const hasResolved = !isResolving && hasFinishedResolution(selectorName, args);
87
82
  const data = selectors[selectorName](...args);
88
83
  let status;
89
-
90
84
  if (isResolving) {
91
85
  status = Status.Resolving;
92
86
  } else if (hasResolved) {
@@ -98,7 +92,6 @@ const enrichSelectors = memoize(selectors => {
98
92
  } else {
99
93
  status = Status.Idle;
100
94
  }
101
-
102
95
  return {
103
96
  data,
104
97
  status,
@@ -108,7 +101,6 @@ const enrichSelectors = memoize(selectors => {
108
101
  }
109
102
  });
110
103
  }
111
-
112
104
  return resolvers;
113
105
  });
114
106
  //# sourceMappingURL=use-query-select.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"names":["useSelect","memoize","Status","META_SELECTORS","useQuerySelect","mapQuerySelect","deps","select","registry","resolve","store","enrichSelectors","selectors","resolvers","selectorName","includes","Object","defineProperty","get","args","getIsResolving","hasFinishedResolution","isResolving","hasResolved","data","status","Resolving","Success","Error","Idle"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,SAASC,MAAT,QAAuB,aAAvB;AAEA,OAAO,MAAMC,cAAc,GAAG,CA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AAEE,YAAF,CAAT,CAA2B,GAAGK,IAA9B,CAAb;AAEA,YAAIM,MAAJ;;AACA,YAAKH,WAAL,EAAmB;AAClBG,UAAAA,MAAM,GAAGvB,MAAM,CAACwB,SAAhB;AACA,SAFD,MAEO,IAAKH,WAAL,EAAmB;AACzB,cAAKC,IAAL,EAAY;AACXC,YAAAA,MAAM,GAAGvB,MAAM,CAACyB,OAAhB;AACA,WAFD,MAEO;AACNF,YAAAA,MAAM,GAAGvB,MAAM,CAAC0B,KAAhB;AACA;AACD,SANM,MAMA;AACNH,UAAAA,MAAM,GAAGvB,MAAM,CAAC2B,IAAhB;AACA;;AAED,eAAO;AACNL,UAAAA,IADM;AAENC,UAAAA,MAFM;AAGNH,UAAAA,WAHM;AAINC,UAAAA;AAJM,SAAP;AAMA;AA9B6C,KAAhD;AAgCA;;AACD,SAAOV,SAAP;AACA,CAxC8B,CAA/B","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 `getIsResolving` 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 { getIsResolving, hasFinishedResolution } = selectors;\n\t\t\t\t\tconst isResolving = !! getIsResolving( selectorName, args );\n\t\t\t\t\tconst hasResolved =\n\t\t\t\t\t\t! isResolving &&\n\t\t\t\t\t\thasFinishedResolution( selectorName, args );\n\t\t\t\t\tconst data = selectors[ selectorName ]( ...args );\n\n\t\t\t\t\tlet status;\n\t\t\t\t\tif ( isResolving ) {\n\t\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\t\tif ( data ) {\n\t\t\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tstatus = Status.Error;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstatus = Status.Idle;\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,\n\t\t\t\t\t\thasResolved,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t} );\n\t}\n\treturn resolvers;\n} ) as EnrichedSelectors );\n"]}
1
+ {"version":3,"names":["useSelect","memoize","Status","META_SELECTORS","useQuerySelect","mapQuerySelect","deps","select","registry","resolve","store","enrichSelectors","selectors","resolvers","selectorName","includes","Object","defineProperty","get","args","getIsResolving","hasFinishedResolution","isResolving","hasResolved","data","status","Resolving","Success","Error","Idle"],"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"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 `getIsResolving` 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 { getIsResolving, hasFinishedResolution } = selectors;\n\t\t\t\t\tconst isResolving = !! getIsResolving( selectorName, args );\n\t\t\t\t\tconst hasResolved =\n\t\t\t\t\t\t! isResolving &&\n\t\t\t\t\t\thasFinishedResolution( selectorName, args );\n\t\t\t\t\tconst data = selectors[ selectorName ]( ...args );\n\n\t\t\t\t\tlet status;\n\t\t\t\t\tif ( isResolving ) {\n\t\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\t\tif ( data ) {\n\t\t\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tstatus = Status.Error;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstatus = Status.Idle;\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,\n\t\t\t\t\t\thasResolved,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t} );\n\t}\n\treturn resolvers;\n} ) as EnrichedSelectors );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,iBAAiB;;AAE3C;AACA;AACA;AACA,OAAOC,OAAO,MAAM,WAAW;AAC/B,SAASC,MAAM,QAAQ,aAAa;AAEpC,OAAO,MAAMC,cAAc,GAAG,CAC7B,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,oBAAoB,CACpB;AAgBD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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GAAGvB,MAAM,CAAC2B,IAAI;QACrB;QAEA,OAAO;UACNL,IAAI;UACJC,MAAM;UACNH,WAAW;UACXC;QACD,CAAC;MACF;IACF,CAAE,CAAC;EACJ;EACA,OAAOV,SAAS;AACjB,CAAyB,CAAC"}
@@ -2,14 +2,13 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import deprecated from '@wordpress/deprecated';
5
+
5
6
  /**
6
7
  * Internal dependencies
7
8
  */
8
-
9
9
  import { store as coreStore } from '../';
10
10
  import { Status } from './constants';
11
11
  import useQuerySelect from './use-query-select';
12
-
13
12
  /**
14
13
  * Resolves resource permissions.
15
14
  *
@@ -84,19 +83,16 @@ export default function useResourcePermissions(resource, id) {
84
83
  canUser
85
84
  } = resolve(coreStore);
86
85
  const create = canUser('create', resource);
87
-
88
86
  if (!id) {
89
87
  const read = canUser('read', resource);
90
88
  const isResolving = create.isResolving || read.isResolving;
91
89
  const hasResolved = create.hasResolved && read.hasResolved;
92
90
  let status = Status.Idle;
93
-
94
91
  if (isResolving) {
95
92
  status = Status.Resolving;
96
93
  } else if (hasResolved) {
97
94
  status = Status.Success;
98
95
  }
99
-
100
96
  return {
101
97
  status,
102
98
  isResolving,
@@ -105,22 +101,17 @@ export default function useResourcePermissions(resource, id) {
105
101
  canRead: read.hasResolved && read.data
106
102
  };
107
103
  }
108
-
109
104
  const read = canUser('read', resource, id);
110
105
  const update = canUser('update', resource, id);
111
-
112
106
  const _delete = canUser('delete', resource, id);
113
-
114
107
  const isResolving = read.isResolving || create.isResolving || update.isResolving || _delete.isResolving;
115
108
  const hasResolved = read.hasResolved && create.hasResolved && update.hasResolved && _delete.hasResolved;
116
109
  let status = Status.Idle;
117
-
118
110
  if (isResolving) {
119
111
  status = Status.Resolving;
120
112
  } else if (hasResolved) {
121
113
  status = Status.Success;
122
114
  }
123
-
124
115
  return {
125
116
  status,
126
117
  isResolving,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"names":["deprecated","store","coreStore","Status","useQuerySelect","useResourcePermissions","resource","id","resolve","canUser","create","read","isResolving","hasResolved","status","Idle","Resolving","Success","canCreate","data","canRead","update","_delete","canUpdate","canDelete","__experimentalUseResourcePermissions","alternative","since"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,KAAnC;AACA,SAASC,MAAT,QAAuB,aAAvB;AACA,OAAOC,cAAP,MAA2B,oBAA3B;;AAiCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,sBAAT,CACdC,QADc,EAEdC,EAFc,EAG4B;AAC1C,SAAOH,cAAc,CAClBI,OAAF,IAAe;AACd,UAAM;AAAEC,MAAAA;AAAF,QAAcD,OAAO,CAAEN,SAAF,CAA3B;AACA,UAAMQ,MAAM,GAAGD,OAAO,CAAE,QAAF,EAAYH,QAAZ,CAAtB;;AACA,QAAK,CAAEC,EAAP,EAAY;AACX,YAAMI,IAAI,GAAGF,OAAO,CAAE,MAAF,EAAUH,QAAV,CAApB;AAEA,YAAMM,WAAW,GAAGF,MAAM,CAACE,WAAP,IAAsBD,IAAI,CAACC,WAA/C;AACA,YAAMC,WAAW,GAAGH,MAAM,CAACG,WAAP,IAAsBF,IAAI,CAACE,WAA/C;AACA,UAAIC,MAAM,GAAGX,MAAM,CAACY,IAApB;;AACA,UAAKH,WAAL,EAAmB;AAClBE,QAAAA,MAAM,GAAGX,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AEV,WAAW,IAAIQ,MAAM,CAACF,IAN3B;AAONK,MAAAA,SAAS,EAAEX,WAAW,IAAIS,OAAO,CAACH;AAP5B,KAAP;AASA,GAtDmB,EAuDpB,CAAEb,QAAF,EAAYC,EAAZ,CAvDoB,CAArB;AAyDA;AAED,OAAO,SAASkB,oCAAT,CACNnB,QADM,EAENC,EAFM,EAGL;AACDP,EAAAA,UAAU,CAAG,8CAAH,EAAkD;AAC3D0B,IAAAA,WAAW,EAAE,gCAD8C;AAE3DC,IAAAA,KAAK,EAAE;AAFoD,GAAlD,CAAV;AAIA,SAAOtB,sBAAsB,CAAEC,QAAF,EAAYC,EAAZ,CAA7B;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\nimport useQuerySelect from './use-query-select';\n\ninterface GlobalResourcePermissionsResolution {\n\t/** Can the current user create new resources of this type? */\n\tcanCreate: boolean;\n}\ninterface SpecificResourcePermissionsResolution {\n\t/** Can the current user update resources of this type? */\n\tcanUpdate: boolean;\n\t/** Can the current user delete resources of this type? */\n\tcanDelete: boolean;\n}\ninterface ResolutionDetails {\n\t/** Resolution status */\n\tstatus: Status;\n\t/**\n\t * Is the data still being resolved?\n\t */\n\tisResolving: boolean;\n}\n\n/**\n * Is the data resolved by now?\n */\ntype HasResolved = boolean;\n\ntype ResourcePermissionsResolution< IdType > = [\n\tHasResolved,\n\tResolutionDetails &\n\t\tGlobalResourcePermissionsResolution &\n\t\t( IdType extends void ? SpecificResourcePermissionsResolution : {} )\n];\n\n/**\n * Resolves resource permissions.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param resource The resource in question, e.g. media.\n * @param id ID of a specific resource entry, if needed, e.g. 10.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( 'pages' );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PagesList />\n * ```\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function Page({ pageId }) {\n * const {\n * canCreate,\n * canUpdate,\n * canDelete,\n * isResolving\n * } = useResourcePermissions( 'pages', pageId );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * {canUpdate ? (<button>Edit page</button>) : false}\n * {canDelete ? (<button>Delete page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <Page pageId={ 15 } />\n * ```\n *\n * In the above example, when `PagesList` is rendered into an\n * application, the appropriate permissions and the resolution details will be retrieved from\n * the store state using `canUser()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template IdType\n */\nexport default function useResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser( 'create', resource );\n\t\t\tif ( ! id ) {\n\t\t\t\tconst read = canUser( 'read', resource );\n\n\t\t\t\tconst isResolving = create.isResolving || read.isResolving;\n\t\t\t\tconst hasResolved = create.hasResolved && read.hasResolved;\n\t\t\t\tlet status = Status.Idle;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\tcanRead: read.hasResolved && read.data,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst read = canUser( 'read', resource, id );\n\t\t\tconst update = canUser( 'update', resource, id );\n\t\t\tconst _delete = canUser( 'delete', resource, id );\n\t\t\tconst isResolving =\n\t\t\t\tread.isResolving ||\n\t\t\t\tcreate.isResolving ||\n\t\t\t\tupdate.isResolving ||\n\t\t\t\t_delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tread.hasResolved &&\n\t\t\t\tcreate.hasResolved &&\n\t\t\t\tupdate.hasResolved &&\n\t\t\t\t_delete.hasResolved;\n\n\t\t\tlet status = Status.Idle;\n\t\t\tif ( isResolving ) {\n\t\t\t\tstatus = Status.Resolving;\n\t\t\t} else if ( hasResolved ) {\n\t\t\t\tstatus = Status.Success;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\n\t\t\t\tcanRead: hasResolved && read.data,\n\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t};\n\t\t},\n\t\t[ resource, id ]\n\t);\n}\n\nexport function __experimentalUseResourcePermissions(\n\tresource: string,\n\tid?: unknown\n) {\n\tdeprecated( `wp.data.__experimentalUseResourcePermissions`, {\n\t\talternative: 'wp.data.useResourcePermissions',\n\t\tsince: '6.1',\n\t} );\n\treturn useResourcePermissions( resource, id );\n}\n"]}
1
+ {"version":3,"names":["deprecated","store","coreStore","Status","useQuerySelect","useResourcePermissions","resource","id","resolve","canUser","create","read","isResolving","hasResolved","status","Idle","Resolving","Success","canCreate","data","canRead","update","_delete","canUpdate","canDelete","__experimentalUseResourcePermissions","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\nimport useQuerySelect from './use-query-select';\n\ninterface GlobalResourcePermissionsResolution {\n\t/** Can the current user create new resources of this type? */\n\tcanCreate: boolean;\n}\ninterface SpecificResourcePermissionsResolution {\n\t/** Can the current user update resources of this type? */\n\tcanUpdate: boolean;\n\t/** Can the current user delete resources of this type? */\n\tcanDelete: boolean;\n}\ninterface ResolutionDetails {\n\t/** Resolution status */\n\tstatus: Status;\n\t/**\n\t * Is the data still being resolved?\n\t */\n\tisResolving: boolean;\n}\n\n/**\n * Is the data resolved by now?\n */\ntype HasResolved = boolean;\n\ntype ResourcePermissionsResolution< IdType > = [\n\tHasResolved,\n\tResolutionDetails &\n\t\tGlobalResourcePermissionsResolution &\n\t\t( IdType extends void ? SpecificResourcePermissionsResolution : {} )\n];\n\n/**\n * Resolves resource permissions.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param resource The resource in question, e.g. media.\n * @param id ID of a specific resource entry, if needed, e.g. 10.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( 'pages' );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PagesList />\n * ```\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function Page({ pageId }) {\n * const {\n * canCreate,\n * canUpdate,\n * canDelete,\n * isResolving\n * } = useResourcePermissions( 'pages', pageId );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * {canUpdate ? (<button>Edit page</button>) : false}\n * {canDelete ? (<button>Delete page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <Page pageId={ 15 } />\n * ```\n *\n * In the above example, when `PagesList` is rendered into an\n * application, the appropriate permissions and the resolution details will be retrieved from\n * the store state using `canUser()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template IdType\n */\nexport default function useResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser( 'create', resource );\n\t\t\tif ( ! id ) {\n\t\t\t\tconst read = canUser( 'read', resource );\n\n\t\t\t\tconst isResolving = create.isResolving || read.isResolving;\n\t\t\t\tconst hasResolved = create.hasResolved && read.hasResolved;\n\t\t\t\tlet status = Status.Idle;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\tcanRead: read.hasResolved && read.data,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst read = canUser( 'read', resource, id );\n\t\t\tconst update = canUser( 'update', resource, id );\n\t\t\tconst _delete = canUser( 'delete', resource, id );\n\t\t\tconst isResolving =\n\t\t\t\tread.isResolving ||\n\t\t\t\tcreate.isResolving ||\n\t\t\t\tupdate.isResolving ||\n\t\t\t\t_delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tread.hasResolved &&\n\t\t\t\tcreate.hasResolved &&\n\t\t\t\tupdate.hasResolved &&\n\t\t\t\t_delete.hasResolved;\n\n\t\t\tlet status = Status.Idle;\n\t\t\tif ( isResolving ) {\n\t\t\t\tstatus = Status.Resolving;\n\t\t\t} else if ( hasResolved ) {\n\t\t\t\tstatus = Status.Success;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\n\t\t\t\tcanRead: hasResolved && read.data,\n\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t};\n\t\t},\n\t\t[ resource, id ]\n\t);\n}\n\nexport function __experimentalUseResourcePermissions(\n\tresource: string,\n\tid?: unknown\n) {\n\tdeprecated( `wp.data.__experimentalUseResourcePermissions`, {\n\t\talternative: 'wp.data.useResourcePermissions',\n\t\tsince: '6.1',\n\t} );\n\treturn useResourcePermissions( resource, id );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,uBAAuB;;AAE9C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,SAAS,QAAQ,KAAK;AACxC,SAASC,MAAM,QAAQ,aAAa;AACpC,OAAOC,cAAc,MAAM,oBAAoB;AAiC/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,sBAAsBA,CAC7CC,QAAgB,EAChBC,EAAW,EAC+B;EAC1C,OAAOH,cAAc,CAClBI,OAAO,IAAM;IACd,MAAM;MAAEC;IAAQ,CAAC,GAAGD,OAAO,CAAEN,SAAU,CAAC;IACxC,MAAMQ,MAAM,GAAGD,OAAO,CAAE,QAAQ,EAAEH,QAAS,CAAC;IAC5C,IAAK,CAAEC,EAAE,EAAG;MACX,MAAMI,IAAI,GAAGF,OAAO,CAAE,MAAM,EAAEH,QAAS,CAAC;MAExC,MAAMM,WAAW,GAAGF,MAAM,CAACE,WAAW,IAAID,IAAI,CAACC,WAAW;MAC1D,MAAMC,WAAW,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H,MAAM,CAACS,IAAI;MACrCI,SAAS,EAAEV,WAAW,IAAIQ,MAAM,CAACF,IAAI;MACrCK,SAAS,EAAEX,WAAW,IAAIS,OAAO,CAACH;IACnC,CAAC;EACF,CAAC,EACD,CAAEb,QAAQ,EAAEC,EAAE,CACf,CAAC;AACF;AAEA,OAAO,SAASkB,oCAAoCA,CACnDnB,QAAgB,EAChBC,EAAY,EACX;EACDP,UAAU,CAAG,8CAA6C,EAAE;IAC3D0B,WAAW,EAAE,gCAAgC;IAC7CC,KAAK,EAAE;EACR,CAAE,CAAC;EACH,OAAOtB,sBAAsB,CAAEC,QAAQ,EAAEC,EAAG,CAAC;AAC9C"}
@@ -2,10 +2,10 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { createReduxStore, register } from '@wordpress/data';
5
+
5
6
  /**
6
7
  * Internal dependencies
7
8
  */
8
-
9
9
  import reducer from './reducer';
10
10
  import * as selectors from './selectors';
11
11
  import * as privateSelectors from './private-selectors';
@@ -14,7 +14,9 @@ import * as resolvers from './resolvers';
14
14
  import createLocksActions from './locks/actions';
15
15
  import { rootEntitiesConfig, getMethodName } from './entities';
16
16
  import { STORE_NAME } from './name';
17
- import { unlock } from './private-apis'; // The entity selectors/resolvers and actions are shortcuts to their generic equivalents
17
+ import { unlock } from './private-apis';
18
+
19
+ // The entity selectors/resolvers and actions are shortcuts to their generic equivalents
18
20
  // (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)
19
21
  // Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...
20
22
  // The "kind" and the "name" of the entity are combined to generate these shortcuts.
@@ -24,11 +26,8 @@ const entitySelectors = rootEntitiesConfig.reduce((result, entity) => {
24
26
  kind,
25
27
  name
26
28
  } = entity;
27
-
28
29
  result[getMethodName(kind, name)] = (state, key, query) => selectors.getEntityRecord(state, kind, name, key, query);
29
-
30
30
  result[getMethodName(kind, name, 'get', true)] = (state, query) => selectors.getEntityRecords(state, kind, name, query);
31
-
32
31
  return result;
33
32
  }, {});
34
33
  const entityResolvers = rootEntitiesConfig.reduce((result, entity) => {
@@ -36,15 +35,10 @@ const entityResolvers = rootEntitiesConfig.reduce((result, entity) => {
36
35
  kind,
37
36
  name
38
37
  } = entity;
39
-
40
38
  result[getMethodName(kind, name)] = (key, query) => resolvers.getEntityRecord(kind, name, key, query);
41
-
42
39
  const pluralMethodName = getMethodName(kind, name, 'get', true);
43
-
44
40
  result[pluralMethodName] = (...args) => resolvers.getEntityRecords(kind, name, ...args);
45
-
46
41
  result[pluralMethodName].shouldInvalidate = action => resolvers.getEntityRecords.shouldInvalidate(action, kind, name);
47
-
48
42
  return result;
49
43
  }, {});
50
44
  const entityActions = rootEntitiesConfig.reduce((result, entity) => {
@@ -52,34 +46,32 @@ const entityActions = rootEntitiesConfig.reduce((result, entity) => {
52
46
  kind,
53
47
  name
54
48
  } = entity;
55
-
56
49
  result[getMethodName(kind, name, 'save')] = key => actions.saveEntityRecord(kind, name, key);
57
-
58
50
  result[getMethodName(kind, name, 'delete')] = (key, query) => actions.deleteEntityRecord(kind, name, key, query);
59
-
60
51
  return result;
61
52
  }, {});
62
-
63
53
  const storeConfig = () => ({
64
54
  reducer,
65
- actions: { ...actions,
55
+ actions: {
56
+ ...actions,
66
57
  ...entityActions,
67
58
  ...createLocksActions()
68
59
  },
69
- selectors: { ...selectors,
60
+ selectors: {
61
+ ...selectors,
70
62
  ...entitySelectors
71
63
  },
72
- resolvers: { ...resolvers,
64
+ resolvers: {
65
+ ...resolvers,
73
66
  ...entityResolvers
74
67
  }
75
68
  });
69
+
76
70
  /**
77
71
  * Store definition for the code data namespace.
78
72
  *
79
73
  * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
80
74
  */
81
-
82
-
83
75
  export const store = createReduxStore(STORE_NAME, storeConfig());
84
76
  unlock(store).registerPrivateSelectors(privateSelectors);
85
77
  register(store); // Register store after unlocking private selectors to allow resolvers to use them.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["createReduxStore","register","reducer","selectors","privateSelectors","actions","resolvers","createLocksActions","rootEntitiesConfig","getMethodName","STORE_NAME","unlock","entitySelectors","reduce","result","entity","kind","name","state","key","query","getEntityRecord","getEntityRecords","entityResolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","saveEntityRecord","deleteEntityRecord","storeConfig","store","registerPrivateSelectors","default","EntityProvider"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAT,EAA2BC,QAA3B,QAA2C,iBAA3C;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA,OAAO,KAAKC,gBAAZ,MAAkC,qBAAlC;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA,OAAOC,kBAAP,MAA+B,iBAA/B;AACA,SAASC,kBAAT,EAA6BC,aAA7B,QAAkD,YAAlD;AACA,SAASC,UAAT,QAA2B,QAA3B;AACA,SAASC,MAAT,QAAuB,gBAAvB,C,CAEA;AACA;AACA;AACA;;AAEA,MAAMC,eAAe,GAAGJ,kBAAkB,CAACK,MAAnB,CAA2B,CAAEC,MAAF,EAAUC,MAAV,KAAsB;AACxE,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAiBF,MAAvB;;AACAD,EAAAA,MAAM,CAAEL,aAAa,CAAEO,IAAF,EAAQC,IAAR,CAAf,CAAN,GAAwC,CAAEC,KAAF,EAASC,GAAT,EAAcC,KAAd,KACvCjB,SAAS,CAACkB,eAAV,CAA2BH,KAA3B,EAAkCF,IAAlC,EAAwCC,IAAxC,EAA8CE,GAA9C,EAAmDC,KAAnD,CADD;;AAEAN,EAAAA,MAAM,CAAEL,aAAa,CAAEO,IAAF,EAAQC,IAAR,EAAc,KAAd,EAAqB,IAArB,CAAf,CAAN,GAAqD,CAAEC,KAAF,EAAS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,GAAkDE,GAAF,IAC/Cd,OAAO,CAACwB,gBAAR,CAA0Bb,IAA1B,EAAgCC,IAAhC,EAAsCE,GAAtC,CADD;;AAEAL,EAAAA,MAAM,CAAEL,aAAa,CAAEO,IAAF,EAAQC,IAAR,EAAc,QAAd,CAAf,CAAN,GAAkD,CAAEE,GAAF,EAAOC,KAAP,KACjDf,OAAO,CAACyB,kBAAR,CAA4Bd,IAA5B,EAAkCC,IAAlC,EAAwCE,GAAxC,EAA6CC,KAA7C,CADD;;AAEA,SAAON,MAAP;AACA,CAPqB,EAOnB,EAPmB,CAAtB;;AASA,MAAMiB,WAAW,GAAG,OAAQ;AAC3B7B,EAAAA,OAD2B;AAE3BG,EAAAA,OAAO,EAAE,EAAE,GAAGA,OAAL;AAAc,OAAGuB,aAAjB;AAAgC,OAAGrB,kBAAkB;AAArD,GAFkB;AAG3BJ,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGS;AAAnB,GAHgB;AAI3BN,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGiB;AAAnB;AAJgB,CAAR,CAApB;AAOA;AACA;AACA;AACA;AACA;;;AACA,OAAO,MAAMS,KAAK,GAAGhC,gBAAgB,CAAEU,UAAF,EAAcqB,WAAW,EAAzB,CAA9B;AACPpB,MAAM,CAAEqB,KAAF,CAAN,CAAgBC,wBAAhB,CAA0C7B,gBAA1C;AACAH,QAAQ,CAAE+B,KAAF,CAAR,C,CAAmB;;AAEnB,SAASE,OAAO,IAAIC,cAApB,QAA0C,mBAA1C;AACA,cAAc,mBAAd;AACA,cAAc,gBAAd;AACA,cAAc,SAAd;AACA,cAAc,SAAd","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as privateSelectors from './private-selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { rootEntitiesConfig, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\nimport { unlock } from './private-apis';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\nunlock( store ).registerPrivateSelectors( privateSelectors );\nregister( store ); // Register store after unlocking private selectors to allow resolvers to use them.\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\n"]}
1
+ {"version":3,"names":["createReduxStore","register","reducer","selectors","privateSelectors","actions","resolvers","createLocksActions","rootEntitiesConfig","getMethodName","STORE_NAME","unlock","entitySelectors","reduce","result","entity","kind","name","state","key","query","getEntityRecord","getEntityRecords","entityResolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","saveEntityRecord","deleteEntityRecord","storeConfig","store","registerPrivateSelectors","default","EntityProvider"],"sources":["@wordpress/core-data/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as privateSelectors from './private-selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { rootEntitiesConfig, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\nimport { unlock } from './private-apis';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\nunlock( store ).registerPrivateSelectors( privateSelectors );\nregister( store ); // Register store after unlocking private selectors to allow resolvers to use them.\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAgB,EAAEC,QAAQ,QAAQ,iBAAiB;;AAE5D;AACA;AACA;AACA,OAAOC,OAAO,MAAM,WAAW;AAC/B,OAAO,KAAKC,SAAS,MAAM,aAAa;AACxC,OAAO,KAAKC,gBAAgB,MAAM,qBAAqB;AACvD,OAAO,KAAKC,OAAO,MAAM,WAAW;AACpC,OAAO,KAAKC,SAAS,MAAM,aA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,OAAO,MAAMS,KAAK,GAAGhC,gBAAgB,CAAEU,UAAU,EAAEqB,WAAW,CAAC,CAAE,CAAC;AAClEpB,MAAM,CAAEqB,KAAM,CAAC,CAACC,wBAAwB,CAAE7B,gBAAiB,CAAC;AAC5DH,QAAQ,CAAE+B,KAAM,CAAC,CAAC,CAAC;;AAEnB,SAASE,OAAO,IAAIC,cAAc,QAAQ,mBAAmB;AAC7D,cAAc,mBAAmB;AACjC,cAAc,gBAAgB;AAC9B,cAAc,SAAS;AACvB,cAAc,SAAS"}
@@ -4,17 +4,14 @@
4
4
  import createLocks from './engine';
5
5
  export default function createLocksActions() {
6
6
  const locks = createLocks();
7
-
8
7
  function __unstableAcquireStoreLock(store, path, {
9
8
  exclusive
10
9
  }) {
11
10
  return () => locks.acquire(store, path, exclusive);
12
11
  }
13
-
14
12
  function __unstableReleaseStoreLock(lock) {
15
13
  return () => locks.release(lock);
16
14
  }
17
-
18
15
  return {
19
16
  __unstableAcquireStoreLock,
20
17
  __unstableReleaseStoreLock
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/locks/actions.js"],"names":["createLocks","createLocksActions","locks","__unstableAcquireStoreLock","store","path","exclusive","acquire","__unstableReleaseStoreLock","lock","release"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAP,MAAwB,UAAxB;AAEA,eAAe,SAASC,kBAAT,GAA8B;AAC5C,QAAMC,KAAK,GAAGF,WAAW,EAAzB;;AAEA,WAASG,0BAAT,CAAqCC,KAArC,EAA4CC,IAA5C,EAAkD;AAAEC,IAAAA;AAAF,GAAlD,EAAkE;AACjE,WAAO,MAAMJ,KAAK,CAACK,OAAN,CAAeH,KAAf,EAAsBC,IAAtB,EAA4BC,SAA5B,CAAb;AACA;;AAED,WAASE,0BAAT,CAAqCC,IAArC,EAA4C;AAC3C,WAAO,MAAMP,KAAK,CAACQ,OAAN,CAAeD,IAAf,CAAb;AACA;;AAED,SAAO;AAAEN,IAAAA,0BAAF;AAA8BK,IAAAA;AAA9B,GAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport createLocks from './engine';\n\nexport default function createLocksActions() {\n\tconst locks = createLocks();\n\n\tfunction __unstableAcquireStoreLock( store, path, { exclusive } ) {\n\t\treturn () => locks.acquire( store, path, exclusive );\n\t}\n\n\tfunction __unstableReleaseStoreLock( lock ) {\n\t\treturn () => locks.release( lock );\n\t}\n\n\treturn { __unstableAcquireStoreLock, __unstableReleaseStoreLock };\n}\n"]}
1
+ {"version":3,"names":["createLocks","createLocksActions","locks","__unstableAcquireStoreLock","store","path","exclusive","acquire","__unstableReleaseStoreLock","lock","release"],"sources":["@wordpress/core-data/src/locks/actions.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport createLocks from './engine';\n\nexport default function createLocksActions() {\n\tconst locks = createLocks();\n\n\tfunction __unstableAcquireStoreLock( store, path, { exclusive } ) {\n\t\treturn () => locks.acquire( store, path, exclusive );\n\t}\n\n\tfunction __unstableReleaseStoreLock( lock ) {\n\t\treturn () => locks.release( lock );\n\t}\n\n\treturn { __unstableAcquireStoreLock, __unstableReleaseStoreLock };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAW,MAAM,UAAU;AAElC,eAAe,SAASC,kBAAkBA,CAAA,EAAG;EAC5C,MAAMC,KAAK,GAAGF,WAAW,CAAC,CAAC;EAE3B,SAASG,0BAA0BA,CAAEC,KAAK,EAAEC,IAAI,EAAE;IAAEC;EAAU,CAAC,EAAG;IACjE,OAAO,MAAMJ,KAAK,CAACK,OAAO,CAAEH,KAAK,EAAEC,IAAI,EAAEC,SAAU,CAAC;EACrD;EAEA,SAASE,0BAA0BA,CAAEC,IAAI,EAAG;IAC3C,OAAO,MAAMP,KAAK,CAACQ,OAAO,CAAED,IAAK,CAAC;EACnC;EAEA,OAAO;IAAEN,0BAA0B;IAAEK;EAA2B,CAAC;AAClE"}
@@ -7,7 +7,6 @@ export default function createLocks() {
7
7
  let state = reducer(undefined, {
8
8
  type: '@@INIT'
9
9
  });
10
-
11
10
  function processPendingLockRequests() {
12
11
  for (const request of getPendingLockRequests(state)) {
13
12
  const {
@@ -16,7 +15,6 @@ export default function createLocks() {
16
15
  exclusive,
17
16
  notifyAcquired
18
17
  } = request;
19
-
20
18
  if (isLockAvailable(state, store, path, {
21
19
  exclusive
22
20
  })) {
@@ -34,7 +32,6 @@ export default function createLocks() {
34
32
  }
35
33
  }
36
34
  }
37
-
38
35
  function acquire(store, path, exclusive) {
39
36
  return new Promise(resolve => {
40
37
  state = reducer(state, {
@@ -49,7 +46,6 @@ export default function createLocks() {
49
46
  processPendingLockRequests();
50
47
  });
51
48
  }
52
-
53
49
  function release(lock) {
54
50
  state = reducer(state, {
55
51
  type: 'RELEASE_LOCK',
@@ -57,7 +53,6 @@ export default function createLocks() {
57
53
  });
58
54
  processPendingLockRequests();
59
55
  }
60
-
61
56
  return {
62
57
  acquire,
63
58
  release
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/locks/engine.js"],"names":["reducer","isLockAvailable","getPendingLockRequests","createLocks","state","undefined","type","processPendingLockRequests","request","store","path","exclusive","notifyAcquired","lock","acquire","Promise","resolve","release"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,WAApB;AACA,SAASC,eAAT,EAA0BC,sBAA1B,QAAwD,aAAxD;AAEA,eAAe,SAASC,WAAT,GAAuB;AACrC,MAAIC,KAAK,GAAGJ,OAAO,CAAEK,SAAF,EAAa;AAAEC,IAAAA,IAAI,EAAE;AAAR,GAAb,CAAnB;;AAEA,WAASC,0BAAT,GAAsC;AACrC,SAAM,MAAMC,OAAZ,IAAuBN,sBAAsB,CAAEE,KAAF,CAA7C,EAAyD;AACxD,YAAM;AAAEK,QAAAA,KAAF;AAASC,QAAAA,IAAT;AAAeC,QAAAA,SAAf;AAA0BC,QAAAA;AAA1B,UAA6CJ,OAAnD;;AACA,UAAKP,eAAe,CAAEG,KAAF,EAASK,KAAT,EAAgBC,IAAhB,EAAsB;AAAEC,QAAAA;AAAF,OAAtB,CAApB,EAA4D;AAC3D,cAAME,IAAI,GAAG;AAAEJ,UAAAA,KAAF;AAASC,UAAAA,IAAT;AAAeC,UAAAA;AAAf,SAAb;AACAP,QAAAA,KAAK,GAAGJ,OAAO,CAAEI,KAAF,EAAS;AACvBE,UAAAA,IAAI,EAAE,oBADiB;AAEvBO,UAAAA,IAFuB;AAGvBL,UAAAA;AAHuB,SAAT,CAAf;AAKAI,QAAAA,cAAc,CAAEC,IAAF,CAAd;AACA;AACD;AACD;;AAED,WAASC,OAAT,CAAkBL,KAAlB,EAAyBC,IAAzB,EAA+BC,SAA/B,EAA2C;AAC1C,WAAO,IAAII,OAAJ,CAAeC,OAAF,IAAe;AAClCZ,MAAAA,KAAK,GAAGJ,OAAO,CAAEI,KAAF,EAAS;AACvBE,QAAAA,IAAI,EAAE,sBADiB;AAEvBE,QAAAA,OAAO,EAAE;AAAEC,UAAAA,KAAF;AAASC,UAAAA,IAAT;AAAeC,UAAAA,SAAf;AAA0BC,UAAAA,cAAc,EAAEI;AAA1C;AAFc,OAAT,CAAf;AAIAT,MAAAA,0BAA0B;AAC1B,KANM,CAAP;AAOA;;AACD,WAASU,OAAT,CAAkBJ,IAAlB,EAAyB;AACxBT,IAAAA,KAAK,GAAGJ,OAAO,CAAEI,KAAF,EAAS;AACvBE,MAAAA,IAAI,EAAE,cADiB;AAEvBO,MAAAA;AAFuB,KAAT,CAAf;AAIAN,IAAAA,0BAA0B;AAC1B;;AAED,SAAO;AAAEO,IAAAA,OAAF;AAAWG,IAAAA;AAAX,GAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport { isLockAvailable, getPendingLockRequests } from './selectors';\n\nexport default function createLocks() {\n\tlet state = reducer( undefined, { type: '@@INIT' } );\n\n\tfunction processPendingLockRequests() {\n\t\tfor ( const request of getPendingLockRequests( state ) ) {\n\t\t\tconst { store, path, exclusive, notifyAcquired } = request;\n\t\t\tif ( isLockAvailable( state, store, path, { exclusive } ) ) {\n\t\t\t\tconst lock = { store, path, exclusive };\n\t\t\t\tstate = reducer( state, {\n\t\t\t\t\ttype: 'GRANT_LOCK_REQUEST',\n\t\t\t\t\tlock,\n\t\t\t\t\trequest,\n\t\t\t\t} );\n\t\t\t\tnotifyAcquired( lock );\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction acquire( store, path, exclusive ) {\n\t\treturn new Promise( ( resolve ) => {\n\t\t\tstate = reducer( state, {\n\t\t\t\ttype: 'ENQUEUE_LOCK_REQUEST',\n\t\t\t\trequest: { store, path, exclusive, notifyAcquired: resolve },\n\t\t\t} );\n\t\t\tprocessPendingLockRequests();\n\t\t} );\n\t}\n\tfunction release( lock ) {\n\t\tstate = reducer( state, {\n\t\t\ttype: 'RELEASE_LOCK',\n\t\t\tlock,\n\t\t} );\n\t\tprocessPendingLockRequests();\n\t}\n\n\treturn { acquire, release };\n}\n"]}
1
+ {"version":3,"names":["reducer","isLockAvailable","getPendingLockRequests","createLocks","state","undefined","type","processPendingLockRequests","request","store","path","exclusive","notifyAcquired","lock","acquire","Promise","resolve","release"],"sources":["@wordpress/core-data/src/locks/engine.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport { isLockAvailable, getPendingLockRequests } from './selectors';\n\nexport default function createLocks() {\n\tlet state = reducer( undefined, { type: '@@INIT' } );\n\n\tfunction processPendingLockRequests() {\n\t\tfor ( const request of getPendingLockRequests( state ) ) {\n\t\t\tconst { store, path, exclusive, notifyAcquired } = request;\n\t\t\tif ( isLockAvailable( state, store, path, { exclusive } ) ) {\n\t\t\t\tconst lock = { store, path, exclusive };\n\t\t\t\tstate = reducer( state, {\n\t\t\t\t\ttype: 'GRANT_LOCK_REQUEST',\n\t\t\t\t\tlock,\n\t\t\t\t\trequest,\n\t\t\t\t} );\n\t\t\t\tnotifyAcquired( lock );\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction acquire( store, path, exclusive ) {\n\t\treturn new Promise( ( resolve ) => {\n\t\t\tstate = reducer( state, {\n\t\t\t\ttype: 'ENQUEUE_LOCK_REQUEST',\n\t\t\t\trequest: { store, path, exclusive, notifyAcquired: resolve },\n\t\t\t} );\n\t\t\tprocessPendingLockRequests();\n\t\t} );\n\t}\n\tfunction release( lock ) {\n\t\tstate = reducer( state, {\n\t\t\ttype: 'RELEASE_LOCK',\n\t\t\tlock,\n\t\t} );\n\t\tprocessPendingLockRequests();\n\t}\n\n\treturn { acquire, release };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,OAAO,MAAM,WAAW;AAC/B,SAASC,eAAe,EAAEC,sBAAsB,QAAQ,aAAa;AAErE,eAAe,SAASC,WAAWA,CAAA,EAAG;EACrC,IAAIC,KAAK,GAAGJ,OAAO,CAAEK,SAAS,EAAE;IAAEC,IAAI,EAAE;EAAS,CAAE,CAAC;EAEpD,SAASC,0BAA0BA,CAAA,EAAG;IACrC,KAAM,MAAMC,OAAO,IAAIN,sBAAsB,CAAEE,KAAM,CAAC,EAAG;MACxD,MAAM;QAAEK,KAAK;QAAEC,IAAI;QAAEC,SAAS;QAAEC;MAAe,CAAC,GAAGJ,OAAO;MAC1D,IAAKP,eAAe,CAAEG,KAAK,EAAEK,KAAK,EAAEC,IAAI,EAAE;QAAEC;MAAU,CAAE,CAAC,EAAG;QAC3D,MAAME,IAAI,GAAG;UAAEJ,KAAK;UAAEC,IAAI;UAAEC;QAAU,CAAC;QACvCP,KAAK,GAAGJ,OAAO,CAAEI,KAAK,EAAE;UACvBE,IAAI,EAAE,oBAAoB;UAC1BO,IAAI;UACJL;QACD,CAAE,CAAC;QACHI,cAAc,CAAEC,IAAK,CAAC;MACvB;IACD;EACD;EAEA,SAASC,OAAOA,CAAEL,KAAK,EAAEC,IAAI,EAAEC,SAAS,EAAG;IAC1C,OAAO,IAAII,OAAO,CAAIC,OAAO,IAAM;MAClCZ,KAAK,GAAGJ,OAAO,CAAEI,KAAK,EAAE;QACvBE,IAAI,E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