@wordpress/core-data 7.32.0 → 7.32.1-next.ff1cebbba.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/actions.js +375 -632
- package/build/actions.js.map +7 -1
- package/build/batch/create-batch.js +49 -62
- package/build/batch/create-batch.js.map +7 -1
- package/build/batch/default-processor.js +43 -39
- package/build/batch/default-processor.js.map +7 -1
- package/build/batch/index.js +38 -17
- package/build/batch/index.js.map +7 -1
- package/build/dynamic-entities.js +30 -32
- package/build/dynamic-entities.js.map +7 -1
- package/build/entities.js +298 -410
- package/build/entities.js.map +7 -1
- package/build/entity-context.js +29 -12
- package/build/entity-context.js.map +7 -1
- package/build/entity-provider.js +38 -46
- package/build/entity-provider.js.map +7 -1
- package/build/entity-types/attachment.js +16 -5
- package/build/entity-types/attachment.js.map +7 -1
- package/build/entity-types/base-entity-records.js +16 -42
- package/build/entity-types/base-entity-records.js.map +7 -1
- package/build/entity-types/base.js +16 -5
- package/build/entity-types/base.js.map +7 -1
- package/build/entity-types/comment.js +16 -5
- package/build/entity-types/comment.js.map +7 -1
- package/build/entity-types/global-styles-revision.js +16 -5
- package/build/entity-types/global-styles-revision.js.map +7 -1
- package/build/entity-types/helpers.js +16 -5
- package/build/entity-types/helpers.js.map +7 -1
- package/build/entity-types/index.js +16 -5
- package/build/entity-types/index.js.map +7 -1
- package/build/entity-types/menu-location.js +16 -5
- package/build/entity-types/menu-location.js.map +7 -1
- package/build/entity-types/nav-menu-item.js +16 -5
- package/build/entity-types/nav-menu-item.js.map +7 -1
- package/build/entity-types/nav-menu.js +16 -5
- package/build/entity-types/nav-menu.js.map +7 -1
- package/build/entity-types/page.js +16 -5
- package/build/entity-types/page.js.map +7 -1
- package/build/entity-types/plugin.js +16 -5
- package/build/entity-types/plugin.js.map +7 -1
- package/build/entity-types/post-revision.js +16 -5
- package/build/entity-types/post-revision.js.map +7 -1
- package/build/entity-types/post-status.js +16 -5
- package/build/entity-types/post-status.js.map +7 -1
- package/build/entity-types/post.js +16 -5
- package/build/entity-types/post.js.map +7 -1
- package/build/entity-types/settings.js +16 -5
- package/build/entity-types/settings.js.map +7 -1
- package/build/entity-types/sidebar.js +16 -5
- package/build/entity-types/sidebar.js.map +7 -1
- package/build/entity-types/taxonomy.js +16 -5
- package/build/entity-types/taxonomy.js.map +7 -1
- package/build/entity-types/term.js +16 -5
- package/build/entity-types/term.js.map +7 -1
- package/build/entity-types/theme.js +16 -5
- package/build/entity-types/theme.js.map +7 -1
- package/build/entity-types/type.js +16 -5
- package/build/entity-types/type.js.map +7 -1
- package/build/entity-types/user.js +16 -5
- package/build/entity-types/user.js.map +7 -1
- package/build/entity-types/widget-type.js +16 -5
- package/build/entity-types/widget-type.js.map +7 -1
- package/build/entity-types/widget.js +16 -5
- package/build/entity-types/widget.js.map +7 -1
- package/build/entity-types/wp-template-part.js +16 -5
- package/build/entity-types/wp-template-part.js.map +7 -1
- package/build/entity-types/wp-template.js +16 -5
- package/build/entity-types/wp-template.js.map +7 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js +141 -154
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +7 -1
- package/build/fetch/__experimental-fetch-url-data.js +47 -59
- package/build/fetch/__experimental-fetch-url-data.js.map +7 -1
- package/build/fetch/index.js +53 -32
- package/build/fetch/index.js.map +7 -1
- package/build/footnotes/get-footnotes-order.js +38 -25
- package/build/footnotes/get-footnotes-order.js.map +7 -1
- package/build/footnotes/get-rich-text-values-cached.js +26 -27
- package/build/footnotes/get-rich-text-values-cached.js.map +7 -1
- package/build/footnotes/index.js +68 -55
- package/build/footnotes/index.js.map +7 -1
- package/build/hooks/constants.js +33 -12
- package/build/hooks/constants.js.map +7 -1
- package/build/hooks/index.js +59 -68
- package/build/hooks/index.js.map +7 -1
- package/build/hooks/memoize.js +34 -12
- package/build/hooks/memoize.js.map +7 -1
- package/build/hooks/use-entity-block-editor.js +111 -119
- package/build/hooks/use-entity-block-editor.js.map +7 -1
- package/build/hooks/use-entity-id.js +25 -23
- package/build/hooks/use-entity-id.js.map +7 -1
- package/build/hooks/use-entity-prop.js +59 -60
- package/build/hooks/use-entity-prop.js.map +7 -1
- package/build/hooks/use-entity-record.js +95 -155
- package/build/hooks/use-entity-record.js.map +7 -1
- package/build/hooks/use-entity-records.js +131 -139
- package/build/hooks/use-entity-records.js.map +7 -1
- package/build/hooks/use-query-select.js +65 -84
- package/build/hooks/use-query-select.js.map +7 -1
- package/build/hooks/use-resource-permissions.js +92 -145
- package/build/hooks/use-resource-permissions.js.map +7 -1
- package/build/index.js +96 -153
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -14
- package/build/lock-unlock.js.map +7 -1
- package/build/locks/actions.js +36 -19
- package/build/locks/actions.js.map +7 -1
- package/build/locks/engine.js +48 -47
- package/build/locks/engine.js.map +7 -1
- package/build/locks/reducer.js +54 -63
- package/build/locks/reducer.js.map +7 -1
- package/build/locks/selectors.js +35 -30
- package/build/locks/selectors.js.map +7 -1
- package/build/locks/utils.js +37 -16
- package/build/locks/utils.js.map +7 -1
- package/build/name.js +27 -12
- package/build/name.js.map +7 -1
- package/build/private-actions.js +67 -75
- package/build/private-actions.js.map +7 -1
- package/build/private-apis.js +33 -16
- package/build/private-apis.js.map +7 -1
- package/build/private-selectors.js +204 -184
- package/build/private-selectors.js.map +7 -1
- package/build/queried-data/actions.js +32 -41
- package/build/queried-data/actions.js.map +7 -1
- package/build/queried-data/get-query-parts.js +41 -79
- package/build/queried-data/get-query-parts.js.map +7 -1
- package/build/queried-data/index.js +39 -36
- package/build/queried-data/index.js.map +7 -1
- package/build/queried-data/reducer.js +162 -193
- package/build/queried-data/reducer.js.map +7 -1
- package/build/queried-data/selectors.js +57 -85
- package/build/queried-data/selectors.js.map +7 -1
- package/build/reducer.js +279 -404
- package/build/reducer.js.map +7 -1
- package/build/resolvers.js +553 -600
- package/build/resolvers.js.map +7 -1
- package/build/selectors.js +456 -981
- package/build/selectors.js.map +7 -1
- package/build/sync.js +34 -22
- package/build/sync.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build/utils/conservative-map-item.js +34 -27
- package/build/utils/conservative-map-item.js.map +7 -1
- package/build/utils/crdt-blocks.js +289 -0
- package/build/utils/crdt-blocks.js.map +7 -0
- package/build/utils/crdt.js +202 -0
- package/build/utils/crdt.js.map +7 -0
- package/build/utils/forward-resolver.js +24 -16
- package/build/utils/forward-resolver.js.map +7 -1
- package/build/utils/get-nested-value.js +26 -21
- package/build/utils/get-nested-value.js.map +7 -1
- package/build/utils/get-normalized-comma-separable.js +25 -17
- package/build/utils/get-normalized-comma-separable.js.map +7 -1
- package/build/utils/if-matching-action.js +25 -19
- package/build/utils/if-matching-action.js.map +7 -1
- package/build/utils/index.js +77 -108
- package/build/utils/index.js.map +7 -1
- package/build/utils/is-numeric-id.js +22 -12
- package/build/utils/is-numeric-id.js.map +7 -1
- package/build/utils/is-raw-attribute.js +22 -13
- package/build/utils/is-raw-attribute.js.map +7 -1
- package/build/utils/log-entity-deprecation.js +37 -38
- package/build/utils/log-entity-deprecation.js.map +7 -1
- package/build/utils/on-sub-key.js +30 -24
- package/build/utils/on-sub-key.js.map +7 -1
- package/build/utils/receive-intermediate-results.js +29 -6
- package/build/utils/receive-intermediate-results.js.map +7 -1
- package/build/utils/replace-action.js +24 -17
- package/build/utils/replace-action.js.map +7 -1
- package/build/utils/set-nested-value.js +25 -30
- package/build/utils/set-nested-value.js.map +7 -1
- package/build/utils/user-permissions.js +41 -13
- package/build/utils/user-permissions.js.map +7 -1
- package/build/utils/with-weak-map-cache.js +26 -22
- package/build/utils/with-weak-map-cache.js.map +7 -1
- package/build-module/actions.js +322 -601
- package/build-module/actions.js.map +7 -1
- package/build-module/batch/create-batch.js +21 -57
- package/build-module/batch/create-batch.js.map +7 -1
- package/build-module/batch/default-processor.js +14 -33
- package/build-module/batch/default-processor.js.map +7 -1
- package/build-module/batch/index.js +7 -3
- package/build-module/batch/index.js.map +7 -1
- package/build-module/dynamic-entities.js +7 -28
- package/build-module/dynamic-entities.js.map +7 -1
- package/build-module/entities.js +263 -399
- package/build-module/entities.js.map +7 -1
- package/build-module/entity-context.js +7 -7
- package/build-module/entity-context.js.map +7 -1
- package/build-module/entity-provider.js +19 -42
- package/build-module/entity-provider.js.map +7 -1
- package/build-module/entity-types/attachment.js +1 -2
- package/build-module/entity-types/attachment.js.map +7 -1
- package/build-module/entity-types/base-entity-records.js +1 -37
- package/build-module/entity-types/base-entity-records.js.map +7 -1
- package/build-module/entity-types/base.js +1 -2
- package/build-module/entity-types/base.js.map +7 -1
- package/build-module/entity-types/comment.js +1 -2
- package/build-module/entity-types/comment.js.map +7 -1
- package/build-module/entity-types/global-styles-revision.js +1 -2
- package/build-module/entity-types/global-styles-revision.js.map +7 -1
- package/build-module/entity-types/helpers.js +1 -2
- package/build-module/entity-types/helpers.js.map +7 -1
- package/build-module/entity-types/index.js +1 -2
- package/build-module/entity-types/index.js.map +7 -1
- package/build-module/entity-types/menu-location.js +1 -2
- package/build-module/entity-types/menu-location.js.map +7 -1
- package/build-module/entity-types/nav-menu-item.js +1 -2
- package/build-module/entity-types/nav-menu-item.js.map +7 -1
- package/build-module/entity-types/nav-menu.js +1 -2
- package/build-module/entity-types/nav-menu.js.map +7 -1
- package/build-module/entity-types/page.js +1 -2
- package/build-module/entity-types/page.js.map +7 -1
- package/build-module/entity-types/plugin.js +1 -2
- package/build-module/entity-types/plugin.js.map +7 -1
- package/build-module/entity-types/post-revision.js +1 -2
- package/build-module/entity-types/post-revision.js.map +7 -1
- package/build-module/entity-types/post-status.js +1 -2
- package/build-module/entity-types/post-status.js.map +7 -1
- package/build-module/entity-types/post.js +1 -2
- package/build-module/entity-types/post.js.map +7 -1
- package/build-module/entity-types/settings.js +1 -2
- package/build-module/entity-types/settings.js.map +7 -1
- package/build-module/entity-types/sidebar.js +1 -2
- package/build-module/entity-types/sidebar.js.map +7 -1
- package/build-module/entity-types/taxonomy.js +1 -2
- package/build-module/entity-types/taxonomy.js.map +7 -1
- package/build-module/entity-types/term.js +1 -2
- package/build-module/entity-types/term.js.map +7 -1
- package/build-module/entity-types/theme.js +1 -2
- package/build-module/entity-types/theme.js.map +7 -1
- package/build-module/entity-types/type.js +1 -2
- package/build-module/entity-types/type.js.map +7 -1
- package/build-module/entity-types/user.js +1 -2
- package/build-module/entity-types/user.js.map +7 -1
- package/build-module/entity-types/widget-type.js +1 -2
- package/build-module/entity-types/widget-type.js.map +7 -1
- package/build-module/entity-types/widget.js +1 -2
- package/build-module/entity-types/widget.js.map +7 -1
- package/build-module/entity-types/wp-template-part.js +1 -2
- package/build-module/entity-types/wp-template-part.js.map +7 -1
- package/build-module/entity-types/wp-template.js +1 -2
- package/build-module/entity-types/wp-template.js.map +7 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +111 -149
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +7 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +20 -49
- package/build-module/fetch/__experimental-fetch-url-data.js.map +7 -1
- package/build-module/fetch/index.js +20 -15
- package/build-module/fetch/index.js.map +7 -1
- package/build-module/footnotes/get-footnotes-order.js +10 -19
- package/build-module/footnotes/get-footnotes-order.js.map +7 -1
- package/build-module/footnotes/get-rich-text-values-cached.js +8 -23
- package/build-module/footnotes/get-rich-text-values-cached.js.map +7 -1
- package/build-module/footnotes/index.js +34 -47
- package/build-module/footnotes/index.js.map +7 -1
- package/build-module/hooks/constants.js +11 -8
- package/build-module/hooks/constants.js.map +7 -1
- package/build-module/hooks/index.js +27 -15
- package/build-module/hooks/index.js.map +7 -1
- package/build-module/hooks/memoize.js +6 -8
- package/build-module/hooks/memoize.js.map +7 -1
- package/build-module/hooks/use-entity-block-editor.js +80 -110
- package/build-module/hooks/use-entity-block-editor.js.map +7 -1
- package/build-module/hooks/use-entity-id.js +7 -19
- package/build-module/hooks/use-entity-id.js.map +7 -1
- package/build-module/hooks/use-entity-prop.js +31 -55
- package/build-module/hooks/use-entity-prop.js.map +7 -1
- package/build-module/hooks/use-entity-record.js +63 -148
- package/build-module/hooks/use-entity-record.js.map +7 -1
- package/build-module/hooks/use-entity-records.js +98 -131
- package/build-module/hooks/use-entity-records.js.map +7 -1
- package/build-module/hooks/use-query-select.js +27 -71
- package/build-module/hooks/use-query-select.js.map +7 -1
- package/build-module/hooks/use-resource-permissions.js +57 -136
- package/build-module/hooks/use-resource-permissions.js.map +7 -1
- package/build-module/index.js +49 -71
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/locks/actions.js +8 -13
- package/build-module/locks/actions.js.map +7 -1
- package/build-module/locks/engine.js +17 -38
- package/build-module/locks/engine.js.map +7 -1
- package/build-module/locks/reducer.js +37 -59
- package/build-module/locks/reducer.js.map +7 -1
- package/build-module/locks/selectors.js +16 -23
- package/build-module/locks/selectors.js.map +7 -1
- package/build-module/locks/utils.js +15 -12
- package/build-module/locks/utils.js.map +7 -1
- package/build-module/name.js +5 -8
- package/build-module/name.js.map +7 -1
- package/build-module/private-actions.js +35 -69
- package/build-module/private-actions.js.map +7 -1
- package/build-module/private-apis.js +8 -8
- package/build-module/private-apis.js.map +7 -1
- package/build-module/private-selectors.js +167 -174
- package/build-module/private-selectors.js.map +7 -1
- package/build-module/queried-data/actions.js +11 -38
- package/build-module/queried-data/actions.js.map +7 -1
- package/build-module/queried-data/get-query-parts.js +20 -75
- package/build-module/queried-data/get-query-parts.js.map +7 -1
- package/build-module/queried-data/index.js +7 -4
- package/build-module/queried-data/index.js.map +7 -1
- package/build-module/queried-data/reducer.js +134 -185
- package/build-module/queried-data/reducer.js.map +7 -1
- package/build-module/queried-data/selectors.js +23 -78
- package/build-module/queried-data/selectors.js.map +7 -1
- package/build-module/reducer.js +243 -393
- package/build-module/reducer.js.map +7 -1
- package/build-module/resolvers.js +478 -549
- package/build-module/resolvers.js.map +7 -1
- package/build-module/selectors.js +410 -953
- package/build-module/selectors.js.map +7 -1
- package/build-module/sync.js +14 -17
- package/build-module/sync.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/build-module/utils/conservative-map-item.js +6 -22
- package/build-module/utils/conservative-map-item.js.map +7 -1
- package/build-module/utils/crdt-blocks.js +255 -0
- package/build-module/utils/crdt-blocks.js.map +7 -0
- package/build-module/utils/crdt.js +167 -0
- package/build-module/utils/crdt.js.map +7 -0
- package/build-module/utils/forward-resolver.js +6 -12
- package/build-module/utils/forward-resolver.js.map +7 -1
- package/build-module/utils/get-nested-value.js +9 -18
- package/build-module/utils/get-nested-value.js.map +7 -1
- package/build-module/utils/get-normalized-comma-separable.js +7 -13
- package/build-module/utils/get-normalized-comma-separable.js.map +7 -1
- package/build-module/utils/if-matching-action.js +7 -15
- package/build-module/utils/if-matching-action.js.map +7 -1
- package/build-module/utils/index.js +35 -14
- package/build-module/utils/index.js.map +7 -1
- package/build-module/utils/is-numeric-id.js +5 -9
- package/build-module/utils/is-numeric-id.js.map +7 -1
- package/build-module/utils/is-raw-attribute.js +5 -10
- package/build-module/utils/is-raw-attribute.js.map +7 -1
- package/build-module/utils/log-entity-deprecation.js +8 -31
- package/build-module/utils/log-entity-deprecation.js.map +7 -1
- package/build-module/utils/on-sub-key.js +8 -19
- package/build-module/utils/on-sub-key.js.map +7 -1
- package/build-module/utils/receive-intermediate-results.js +7 -2
- package/build-module/utils/receive-intermediate-results.js.map +7 -1
- package/build-module/utils/replace-action.js +6 -13
- package/build-module/utils/replace-action.js.map +7 -1
- package/build-module/utils/set-nested-value.js +8 -27
- package/build-module/utils/set-nested-value.js.map +7 -1
- package/build-module/utils/user-permissions.js +19 -9
- package/build-module/utils/user-permissions.js.map +7 -1
- package/build-module/utils/with-weak-map-cache.js +8 -18
- package/build-module/utils/with-weak-map-cache.js.map +7 -1
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/entities.d.ts +0 -56
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/private-selectors.d.ts.map +1 -1
- package/build-types/resolvers.d.ts +3 -0
- package/build-types/resolvers.d.ts.map +1 -1
- package/build-types/selectors.d.ts.map +1 -1
- package/build-types/sync.d.ts +6 -1
- package/build-types/sync.d.ts.map +1 -1
- package/build-types/types.d.ts +9 -0
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils/crdt-blocks.d.ts +30 -0
- package/build-types/utils/crdt-blocks.d.ts.map +1 -0
- package/build-types/utils/crdt.d.ts +49 -0
- package/build-types/utils/crdt.d.ts.map +1 -0
- package/package.json +26 -19
- package/src/actions.js +56 -74
- package/src/entities.js +59 -113
- package/src/private-selectors.ts +32 -7
- package/src/resolvers.js +173 -120
- package/src/selectors.ts +0 -13
- package/src/sync.ts +12 -0
- package/src/test/resolvers.js +183 -0
- package/src/types.ts +12 -0
- package/src/utils/crdt-blocks.ts +503 -0
- package/src/utils/crdt.ts +310 -0
- package/src/utils/test/crdt-blocks.ts +375 -0
- package/src/utils/test/crdt.ts +254 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/sync.js +0 -27
|
@@ -1,163 +1,110 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var use_resource_permissions_exports = {};
|
|
30
|
+
__export(use_resource_permissions_exports, {
|
|
31
|
+
__experimentalUseResourcePermissions: () => __experimentalUseResourcePermissions,
|
|
32
|
+
default: () => use_resource_permissions_default
|
|
6
33
|
});
|
|
7
|
-
exports
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
|
|
14
|
-
/**
|
|
15
|
-
* WordPress dependencies
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Internal dependencies
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Is the data resolved by now?
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Resolves resource permissions.
|
|
28
|
-
*
|
|
29
|
-
* @since 6.1.0 Introduced in WordPress core.
|
|
30
|
-
*
|
|
31
|
-
* @param resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`
|
|
32
|
-
* or REST base as a string - `media`.
|
|
33
|
-
* @param id Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged
|
|
34
|
-
* when using an entity object as a resource to check permissions and will be ignored.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```js
|
|
38
|
-
* import { useResourcePermissions } from '@wordpress/core-data';
|
|
39
|
-
*
|
|
40
|
-
* function PagesList() {
|
|
41
|
-
* const { canCreate, isResolving } = useResourcePermissions( { kind: 'postType', name: 'page' } );
|
|
42
|
-
*
|
|
43
|
-
* if ( isResolving ) {
|
|
44
|
-
* return 'Loading ...';
|
|
45
|
-
* }
|
|
46
|
-
*
|
|
47
|
-
* return (
|
|
48
|
-
* <div>
|
|
49
|
-
* {canCreate ? (<button>+ Create a new page</button>) : false}
|
|
50
|
-
* // ...
|
|
51
|
-
* </div>
|
|
52
|
-
* );
|
|
53
|
-
* }
|
|
54
|
-
*
|
|
55
|
-
* // Rendered in the application:
|
|
56
|
-
* // <PagesList />
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```js
|
|
61
|
-
* import { useResourcePermissions } from '@wordpress/core-data';
|
|
62
|
-
*
|
|
63
|
-
* function Page({ pageId }) {
|
|
64
|
-
* const {
|
|
65
|
-
* canCreate,
|
|
66
|
-
* canUpdate,
|
|
67
|
-
* canDelete,
|
|
68
|
-
* isResolving
|
|
69
|
-
* } = useResourcePermissions( { kind: 'postType', name: 'page', id: pageId } );
|
|
70
|
-
*
|
|
71
|
-
* if ( isResolving ) {
|
|
72
|
-
* return 'Loading ...';
|
|
73
|
-
* }
|
|
74
|
-
*
|
|
75
|
-
* return (
|
|
76
|
-
* <div>
|
|
77
|
-
* {canCreate ? (<button>+ Create a new page</button>) : false}
|
|
78
|
-
* {canUpdate ? (<button>Edit page</button>) : false}
|
|
79
|
-
* {canDelete ? (<button>Delete page</button>) : false}
|
|
80
|
-
* // ...
|
|
81
|
-
* </div>
|
|
82
|
-
* );
|
|
83
|
-
* }
|
|
84
|
-
*
|
|
85
|
-
* // Rendered in the application:
|
|
86
|
-
* // <Page pageId={ 15 } />
|
|
87
|
-
* ```
|
|
88
|
-
*
|
|
89
|
-
* In the above example, when `PagesList` is rendered into an
|
|
90
|
-
* application, the appropriate permissions and the resolution details will be retrieved from
|
|
91
|
-
* the store state using `canUser()`, or resolved if missing.
|
|
92
|
-
*
|
|
93
|
-
* @return Entity records data.
|
|
94
|
-
* @template IdType
|
|
95
|
-
*/
|
|
34
|
+
module.exports = __toCommonJS(use_resource_permissions_exports);
|
|
35
|
+
var import_deprecated = __toESM(require("@wordpress/deprecated"));
|
|
36
|
+
var import_warning = __toESM(require("@wordpress/warning"));
|
|
37
|
+
var import__ = require("../");
|
|
38
|
+
var import_constants = require("./constants");
|
|
39
|
+
var import_use_query_select = __toESM(require("./use-query-select"));
|
|
96
40
|
function useResourcePermissions(resource, id) {
|
|
97
|
-
|
|
98
|
-
// We can't just pass `resource` as one of the deps, because if it is passed
|
|
99
|
-
// as an object literal, then it will be a different object on each call even
|
|
100
|
-
// if the values remain the same.
|
|
101
|
-
const isEntity = typeof resource === 'object';
|
|
41
|
+
const isEntity = typeof resource === "object";
|
|
102
42
|
const resourceAsString = isEntity ? JSON.stringify(resource) : resource;
|
|
103
|
-
if (isEntity && typeof id !==
|
|
104
|
-
|
|
43
|
+
if (isEntity && typeof id !== "undefined") {
|
|
44
|
+
(0, import_warning.default)(
|
|
45
|
+
`When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`
|
|
46
|
+
);
|
|
105
47
|
}
|
|
106
|
-
return (0,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
canUser
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
48
|
+
return (0, import_use_query_select.default)(
|
|
49
|
+
(resolve) => {
|
|
50
|
+
const hasId = isEntity ? !!resource.id : !!id;
|
|
51
|
+
const { canUser } = resolve(import__.store);
|
|
52
|
+
const create = canUser(
|
|
53
|
+
"create",
|
|
54
|
+
isEntity ? { kind: resource.kind, name: resource.name } : resource
|
|
55
|
+
);
|
|
56
|
+
if (!hasId) {
|
|
57
|
+
const read2 = canUser("read", resource);
|
|
58
|
+
const isResolving2 = create.isResolving || read2.isResolving;
|
|
59
|
+
const hasResolved2 = create.hasResolved && read2.hasResolved;
|
|
60
|
+
let status2 = import_constants.Status.Idle;
|
|
61
|
+
if (isResolving2) {
|
|
62
|
+
status2 = import_constants.Status.Resolving;
|
|
63
|
+
} else if (hasResolved2) {
|
|
64
|
+
status2 = import_constants.Status.Success;
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
status: status2,
|
|
68
|
+
isResolving: isResolving2,
|
|
69
|
+
hasResolved: hasResolved2,
|
|
70
|
+
canCreate: create.hasResolved && create.data,
|
|
71
|
+
canRead: read2.hasResolved && read2.data
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const read = canUser("read", resource, id);
|
|
75
|
+
const update = canUser("update", resource, id);
|
|
76
|
+
const _delete = canUser("delete", resource, id);
|
|
77
|
+
const isResolving = read.isResolving || create.isResolving || update.isResolving || _delete.isResolving;
|
|
78
|
+
const hasResolved = read.hasResolved && create.hasResolved && update.hasResolved && _delete.hasResolved;
|
|
79
|
+
let status = import_constants.Status.Idle;
|
|
120
80
|
if (isResolving) {
|
|
121
|
-
status =
|
|
81
|
+
status = import_constants.Status.Resolving;
|
|
122
82
|
} else if (hasResolved) {
|
|
123
|
-
status =
|
|
83
|
+
status = import_constants.Status.Success;
|
|
124
84
|
}
|
|
125
85
|
return {
|
|
126
86
|
status,
|
|
127
87
|
isResolving,
|
|
128
88
|
hasResolved,
|
|
129
|
-
|
|
130
|
-
|
|
89
|
+
canRead: hasResolved && read.data,
|
|
90
|
+
canCreate: hasResolved && create.data,
|
|
91
|
+
canUpdate: hasResolved && update.data,
|
|
92
|
+
canDelete: hasResolved && _delete.data
|
|
131
93
|
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const _delete = canUser('delete', resource, id);
|
|
136
|
-
const isResolving = read.isResolving || create.isResolving || update.isResolving || _delete.isResolving;
|
|
137
|
-
const hasResolved = read.hasResolved && create.hasResolved && update.hasResolved && _delete.hasResolved;
|
|
138
|
-
let status = _constants.Status.Idle;
|
|
139
|
-
if (isResolving) {
|
|
140
|
-
status = _constants.Status.Resolving;
|
|
141
|
-
} else if (hasResolved) {
|
|
142
|
-
status = _constants.Status.Success;
|
|
143
|
-
}
|
|
144
|
-
return {
|
|
145
|
-
status,
|
|
146
|
-
isResolving,
|
|
147
|
-
hasResolved,
|
|
148
|
-
canRead: hasResolved && read.data,
|
|
149
|
-
canCreate: hasResolved && create.data,
|
|
150
|
-
canUpdate: hasResolved && update.data,
|
|
151
|
-
canDelete: hasResolved && _delete.data
|
|
152
|
-
};
|
|
153
|
-
}, [resourceAsString, id]);
|
|
94
|
+
},
|
|
95
|
+
[resourceAsString, id]
|
|
96
|
+
);
|
|
154
97
|
}
|
|
155
|
-
var
|
|
98
|
+
var use_resource_permissions_default = useResourcePermissions;
|
|
156
99
|
function __experimentalUseResourcePermissions(resource, id) {
|
|
157
|
-
(0,
|
|
158
|
-
alternative:
|
|
159
|
-
since:
|
|
100
|
+
(0, import_deprecated.default)(`wp.data.__experimentalUseResourcePermissions`, {
|
|
101
|
+
alternative: "wp.data.useResourcePermissions",
|
|
102
|
+
since: "6.1"
|
|
160
103
|
});
|
|
161
104
|
return useResourcePermissions(resource, id);
|
|
162
105
|
}
|
|
163
|
-
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
__experimentalUseResourcePermissions
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=use-resource-permissions.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["_deprecated","_interopRequireDefault","require","_warning","_","_constants","_useQuerySelect","useResourcePermissions","resource","id","isEntity","resourceAsString","JSON","stringify","globalThis","SCRIPT_DEBUG","warning","useQuerySelect","resolve","hasId","canUser","coreStore","create","kind","name","read","isResolving","hasResolved","status","Status","Idle","Resolving","Success","canCreate","data","canRead","update","_delete","canUpdate","canDelete","_default","exports","default","__experimentalUseResourcePermissions","deprecated","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\nimport useQuerySelect from './use-query-select';\n\ninterface GlobalResourcePermissionsResolution {\n\t/** Can the current user create new resources of this type? */\n\tcanCreate: boolean;\n}\ninterface SpecificResourcePermissionsResolution {\n\t/** Can the current user update resources of this type? */\n\tcanUpdate: boolean;\n\t/** Can the current user delete resources of this type? */\n\tcanDelete: boolean;\n}\ninterface ResolutionDetails {\n\t/** Resolution status */\n\tstatus: Status;\n\t/**\n\t * Is the data still being resolved?\n\t */\n\tisResolving: boolean;\n}\n\n/**\n * Is the data resolved by now?\n */\ntype HasResolved = boolean;\n\ntype ResourcePermissionsResolution< IdType > = [\n\tHasResolved,\n\tResolutionDetails &\n\t\tGlobalResourcePermissionsResolution &\n\t\t( IdType extends void ? SpecificResourcePermissionsResolution : {} ),\n];\n\ntype EntityResource = { kind: string; name: string; id?: string | number };\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType >;\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: EntityResource,\n\tid?: never\n): ResourcePermissionsResolution< IdType >;\n\n/**\n * Resolves resource permissions.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`\n * or REST base as a string - `media`.\n * @param id Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged\n * when using an entity object as a resource to check permissions and will be ignored.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( { kind: 'postType', name: 'page' } );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PagesList />\n * ```\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function Page({ pageId }) {\n * const {\n * canCreate,\n * canUpdate,\n * canDelete,\n * isResolving\n * } = useResourcePermissions( { kind: 'postType', name: 'page', id: pageId } );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * {canUpdate ? (<button>Edit page</button>) : false}\n * {canDelete ? (<button>Delete page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <Page pageId={ 15 } />\n * ```\n *\n * In the above example, when `PagesList` is rendered into an\n * application, the appropriate permissions and the resolution details will be retrieved from\n * the store state using `canUser()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template IdType\n */\nfunction useResourcePermissions< IdType = void >(\n\tresource: string | EntityResource,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\t// Serialize `resource` to a string that can be safely used as a React dep.\n\t// We can't just pass `resource` as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst isEntity = typeof resource === 'object';\n\tconst resourceAsString = isEntity ? JSON.stringify( resource ) : resource;\n\n\tif ( isEntity && typeof id !== 'undefined' ) {\n\t\twarning(\n\t\t\t`When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`\n\t\t);\n\t}\n\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst hasId = isEntity ? !! resource.id : !! id;\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser(\n\t\t\t\t'create',\n\t\t\t\tisEntity\n\t\t\t\t\t? { kind: resource.kind, name: resource.name }\n\t\t\t\t\t: resource\n\t\t\t);\n\n\t\t\tif ( ! hasId ) {\n\t\t\t\tconst read = canUser( 'read', resource );\n\n\t\t\t\tconst isResolving = create.isResolving || read.isResolving;\n\t\t\t\tconst hasResolved = create.hasResolved && read.hasResolved;\n\t\t\t\tlet status = Status.Idle;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\tcanRead: read.hasResolved && read.data,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst read = canUser( 'read', resource, id );\n\t\t\tconst update = canUser( 'update', resource, id );\n\t\t\tconst _delete = canUser( 'delete', resource, id );\n\t\t\tconst isResolving =\n\t\t\t\tread.isResolving ||\n\t\t\t\tcreate.isResolving ||\n\t\t\t\tupdate.isResolving ||\n\t\t\t\t_delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tread.hasResolved &&\n\t\t\t\tcreate.hasResolved &&\n\t\t\t\tupdate.hasResolved &&\n\t\t\t\t_delete.hasResolved;\n\n\t\t\tlet status = Status.Idle;\n\t\t\tif ( isResolving ) {\n\t\t\t\tstatus = Status.Resolving;\n\t\t\t} else if ( hasResolved ) {\n\t\t\t\tstatus = Status.Success;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\n\t\t\t\tcanRead: hasResolved && read.data,\n\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t};\n\t\t},\n\t\t[ resourceAsString, id ]\n\t);\n}\n\nexport default useResourcePermissions;\n\nexport function __experimentalUseResourcePermissions(\n\tresource: string,\n\tid?: unknown\n) {\n\tdeprecated( `wp.data.__experimentalUseResourcePermissions`, {\n\t\talternative: 'wp.data.useResourcePermissions',\n\t\tsince: '6.1',\n\t} );\n\treturn useResourcePermissions( resource, id );\n}\n"],"mappings":"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","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hooks/use-resource-permissions.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\nimport useQuerySelect from './use-query-select';\n\ninterface GlobalResourcePermissionsResolution {\n\t/** Can the current user create new resources of this type? */\n\tcanCreate: boolean;\n}\ninterface SpecificResourcePermissionsResolution {\n\t/** Can the current user update resources of this type? */\n\tcanUpdate: boolean;\n\t/** Can the current user delete resources of this type? */\n\tcanDelete: boolean;\n}\ninterface ResolutionDetails {\n\t/** Resolution status */\n\tstatus: Status;\n\t/**\n\t * Is the data still being resolved?\n\t */\n\tisResolving: boolean;\n}\n\n/**\n * Is the data resolved by now?\n */\ntype HasResolved = boolean;\n\ntype ResourcePermissionsResolution< IdType > = [\n\tHasResolved,\n\tResolutionDetails &\n\t\tGlobalResourcePermissionsResolution &\n\t\t( IdType extends void ? SpecificResourcePermissionsResolution : {} ),\n];\n\ntype EntityResource = { kind: string; name: string; id?: string | number };\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType >;\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: EntityResource,\n\tid?: never\n): ResourcePermissionsResolution< IdType >;\n\n/**\n * Resolves resource permissions.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`\n * or REST base as a string - `media`.\n * @param id Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged\n * when using an entity object as a resource to check permissions and will be ignored.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( { kind: 'postType', name: 'page' } );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PagesList />\n * ```\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function Page({ pageId }) {\n * const {\n * canCreate,\n * canUpdate,\n * canDelete,\n * isResolving\n * } = useResourcePermissions( { kind: 'postType', name: 'page', id: pageId } );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * {canUpdate ? (<button>Edit page</button>) : false}\n * {canDelete ? (<button>Delete page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <Page pageId={ 15 } />\n * ```\n *\n * In the above example, when `PagesList` is rendered into an\n * application, the appropriate permissions and the resolution details will be retrieved from\n * the store state using `canUser()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template IdType\n */\nfunction useResourcePermissions< IdType = void >(\n\tresource: string | EntityResource,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\t// Serialize `resource` to a string that can be safely used as a React dep.\n\t// We can't just pass `resource` as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst isEntity = typeof resource === 'object';\n\tconst resourceAsString = isEntity ? JSON.stringify( resource ) : resource;\n\n\tif ( isEntity && typeof id !== 'undefined' ) {\n\t\twarning(\n\t\t\t`When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`\n\t\t);\n\t}\n\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst hasId = isEntity ? !! resource.id : !! id;\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser(\n\t\t\t\t'create',\n\t\t\t\tisEntity\n\t\t\t\t\t? { kind: resource.kind, name: resource.name }\n\t\t\t\t\t: resource\n\t\t\t);\n\n\t\t\tif ( ! hasId ) {\n\t\t\t\tconst read = canUser( 'read', resource );\n\n\t\t\t\tconst isResolving = create.isResolving || read.isResolving;\n\t\t\t\tconst hasResolved = create.hasResolved && read.hasResolved;\n\t\t\t\tlet status = Status.Idle;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\tcanRead: read.hasResolved && read.data,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst read = canUser( 'read', resource, id );\n\t\t\tconst update = canUser( 'update', resource, id );\n\t\t\tconst _delete = canUser( 'delete', resource, id );\n\t\t\tconst isResolving =\n\t\t\t\tread.isResolving ||\n\t\t\t\tcreate.isResolving ||\n\t\t\t\tupdate.isResolving ||\n\t\t\t\t_delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tread.hasResolved &&\n\t\t\t\tcreate.hasResolved &&\n\t\t\t\tupdate.hasResolved &&\n\t\t\t\t_delete.hasResolved;\n\n\t\t\tlet status = Status.Idle;\n\t\t\tif ( isResolving ) {\n\t\t\t\tstatus = Status.Resolving;\n\t\t\t} else if ( hasResolved ) {\n\t\t\t\tstatus = Status.Success;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\n\t\t\t\tcanRead: hasResolved && read.data,\n\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t};\n\t\t},\n\t\t[ resourceAsString, id ]\n\t);\n}\n\nexport default useResourcePermissions;\n\nexport function __experimentalUseResourcePermissions(\n\tresource: string,\n\tid?: unknown\n) {\n\tdeprecated( `wp.data.__experimentalUseResourcePermissions`, {\n\t\talternative: 'wp.data.useResourcePermissions',\n\t\tsince: '6.1',\n\t} );\n\treturn useResourcePermissions( resource, id );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAuB;AACvB,qBAAoB;AAKpB,eAAmC;AACnC,uBAAuB;AACvB,8BAA2B;AAmH3B,SAAS,uBACR,UACA,IAC0C;AAK1C,QAAM,WAAW,OAAO,aAAa;AACrC,QAAM,mBAAmB,WAAW,KAAK,UAAW,QAAS,IAAI;AAEjE,MAAK,YAAY,OAAO,OAAO,aAAc;AAC5C,uBAAAA;AAAA,MACC;AAAA,IACD;AAAA,EACD;AAEA,aAAO,wBAAAC;AAAA,IACN,CAAE,YAAa;AACd,YAAM,QAAQ,WAAW,CAAC,CAAE,SAAS,KAAK,CAAC,CAAE;AAC7C,YAAM,EAAE,QAAQ,IAAI,QAAS,SAAAC,KAAU;AACvC,YAAM,SAAS;AAAA,QACd;AAAA,QACA,WACG,EAAE,MAAM,SAAS,MAAM,MAAM,SAAS,KAAK,IAC3C;AAAA,MACJ;AAEA,UAAK,CAAE,OAAQ;AACd,cAAMC,QAAO,QAAS,QAAQ,QAAS;AAEvC,cAAMC,eAAc,OAAO,eAAeD,MAAK;AAC/C,cAAME,eAAc,OAAO,eAAeF,MAAK;AAC/C,YAAIG,UAAS,wBAAO;AACpB,YAAKF,cAAc;AAClB,UAAAE,UAAS,wBAAO;AAAA,QACjB,WAAYD,cAAc;AACzB,UAAAC,UAAS,wBAAO;AAAA,QACjB;AAEA,eAAO;AAAA,UACN,QAAAA;AAAA,UACA,aAAAF;AAAA,UACA,aAAAC;AAAA,UACA,WAAW,OAAO,eAAe,OAAO;AAAA,UACxC,SAASF,MAAK,eAAeA,MAAK;AAAA,QACnC;AAAA,MACD;AAEA,YAAM,OAAO,QAAS,QAAQ,UAAU,EAAG;AAC3C,YAAM,SAAS,QAAS,UAAU,UAAU,EAAG;AAC/C,YAAM,UAAU,QAAS,UAAU,UAAU,EAAG;AAChD,YAAM,cACL,KAAK,eACL,OAAO,eACP,OAAO,eACP,QAAQ;AACT,YAAM,cACL,KAAK,eACL,OAAO,eACP,OAAO,eACP,QAAQ;AAET,UAAI,SAAS,wBAAO;AACpB,UAAK,aAAc;AAClB,iBAAS,wBAAO;AAAA,MACjB,WAAY,aAAc;AACzB,iBAAS,wBAAO;AAAA,MACjB;AACA,aAAO;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAS,eAAe,KAAK;AAAA,QAC7B,WAAW,eAAe,OAAO;AAAA,QACjC,WAAW,eAAe,OAAO;AAAA,QACjC,WAAW,eAAe,QAAQ;AAAA,MACnC;AAAA,IACD;AAAA,IACA,CAAE,kBAAkB,EAAG;AAAA,EACxB;AACD;AAEA,IAAO,mCAAQ;AAER,SAAS,qCACf,UACA,IACC;AACD,wBAAAI,SAAY,gDAAgD;AAAA,IAC3D,aAAa;AAAA,IACb,OAAO;AAAA,EACR,CAAE;AACF,SAAO,uBAAwB,UAAU,EAAG;AAC7C;",
|
|
6
|
+
"names": ["warning", "useQuerySelect", "coreStore", "read", "isResolving", "hasResolved", "status", "deprecated"]
|
|
7
|
+
}
|
package/build/index.js
CHANGED
|
@@ -1,128 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
11
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
EntityProvider: () => import_entity_provider.default,
|
|
33
|
+
store: () => store
|
|
16
34
|
});
|
|
17
|
-
exports
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var selectors =
|
|
21
|
-
var privateSelectors =
|
|
22
|
-
var actions =
|
|
23
|
-
var privateActions =
|
|
24
|
-
var resolvers =
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
var _entityTypes = require("./entity-types");
|
|
44
|
-
Object.keys(_entityTypes).forEach(function (key) {
|
|
45
|
-
if (key === "default" || key === "__esModule") return;
|
|
46
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
47
|
-
if (key in exports && exports[key] === _entityTypes[key]) return;
|
|
48
|
-
Object.defineProperty(exports, key, {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
get: function () {
|
|
51
|
-
return _entityTypes[key];
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
var _fetch = require("./fetch");
|
|
56
|
-
Object.keys(_fetch).forEach(function (key) {
|
|
57
|
-
if (key === "default" || key === "__esModule") return;
|
|
58
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
59
|
-
if (key in exports && exports[key] === _fetch[key]) return;
|
|
60
|
-
Object.defineProperty(exports, key, {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
get: function () {
|
|
63
|
-
return _fetch[key];
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
var _hooks = require("./hooks");
|
|
68
|
-
Object.keys(_hooks).forEach(function (key) {
|
|
69
|
-
if (key === "default" || key === "__esModule") return;
|
|
70
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
71
|
-
if (key in exports && exports[key] === _hooks[key]) return;
|
|
72
|
-
Object.defineProperty(exports, key, {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
get: function () {
|
|
75
|
-
return _hooks[key];
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
var _privateApis = require("./private-apis");
|
|
80
|
-
Object.keys(_privateApis).forEach(function (key) {
|
|
81
|
-
if (key === "default" || key === "__esModule") return;
|
|
82
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
83
|
-
if (key in exports && exports[key] === _privateApis[key]) return;
|
|
84
|
-
Object.defineProperty(exports, key, {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
get: function () {
|
|
87
|
-
return _privateApis[key];
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
92
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
93
|
-
/**
|
|
94
|
-
* WordPress dependencies
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Internal dependencies
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
// The entity selectors/resolvers and actions are shortcuts to their generic equivalents
|
|
102
|
-
// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)
|
|
103
|
-
// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...
|
|
104
|
-
// The "kind" and the "name" of the entity are combined to generate these shortcuts.
|
|
105
|
-
const entitiesConfig = [..._entities.rootEntitiesConfig, ..._entities.additionalEntityConfigLoaders.filter(config => !!config.name)];
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
var import_data = require("@wordpress/data");
|
|
37
|
+
var import_reducer = __toESM(require("./reducer"));
|
|
38
|
+
var selectors = __toESM(require("./selectors"));
|
|
39
|
+
var privateSelectors = __toESM(require("./private-selectors"));
|
|
40
|
+
var actions = __toESM(require("./actions"));
|
|
41
|
+
var privateActions = __toESM(require("./private-actions"));
|
|
42
|
+
var resolvers = __toESM(require("./resolvers"));
|
|
43
|
+
var import_actions = __toESM(require("./locks/actions"));
|
|
44
|
+
var import_entities = require("./entities");
|
|
45
|
+
var import_name = require("./name");
|
|
46
|
+
var import_lock_unlock = require("./lock-unlock");
|
|
47
|
+
var import_dynamic_entities = require("./dynamic-entities");
|
|
48
|
+
var import_log_entity_deprecation = __toESM(require("./utils/log-entity-deprecation"));
|
|
49
|
+
var import_entity_provider = __toESM(require("./entity-provider"));
|
|
50
|
+
__reExport(index_exports, require("./entity-provider"), module.exports);
|
|
51
|
+
__reExport(index_exports, require("./entity-types"), module.exports);
|
|
52
|
+
__reExport(index_exports, require("./fetch"), module.exports);
|
|
53
|
+
__reExport(index_exports, require("./hooks"), module.exports);
|
|
54
|
+
__reExport(index_exports, require("./private-apis"), module.exports);
|
|
55
|
+
const entitiesConfig = [
|
|
56
|
+
...import_entities.rootEntitiesConfig,
|
|
57
|
+
...import_entities.additionalEntityConfigLoaders.filter((config) => !!config.name)
|
|
58
|
+
];
|
|
106
59
|
const entitySelectors = entitiesConfig.reduce((result, entity) => {
|
|
107
|
-
const {
|
|
108
|
-
|
|
109
|
-
name,
|
|
110
|
-
plural
|
|
111
|
-
} = entity;
|
|
112
|
-
const getEntityRecordMethodName = (0, _entities.getMethodName)(kind, name);
|
|
60
|
+
const { kind, name, plural } = entity;
|
|
61
|
+
const getEntityRecordMethodName = (0, import_entities.getMethodName)(kind, name);
|
|
113
62
|
result[getEntityRecordMethodName] = (state, key, query) => {
|
|
114
|
-
(0,
|
|
63
|
+
(0, import_log_entity_deprecation.default)(kind, name, getEntityRecordMethodName, {
|
|
115
64
|
isShorthandSelector: true,
|
|
116
|
-
alternativeFunctionName:
|
|
65
|
+
alternativeFunctionName: "getEntityRecord"
|
|
117
66
|
});
|
|
118
67
|
return selectors.getEntityRecord(state, kind, name, key, query);
|
|
119
68
|
};
|
|
120
69
|
if (plural) {
|
|
121
|
-
const getEntityRecordsMethodName = (0,
|
|
70
|
+
const getEntityRecordsMethodName = (0, import_entities.getMethodName)(kind, plural, "get");
|
|
122
71
|
result[getEntityRecordsMethodName] = (state, query) => {
|
|
123
|
-
(0,
|
|
72
|
+
(0, import_log_entity_deprecation.default)(kind, name, getEntityRecordsMethodName, {
|
|
124
73
|
isShorthandSelector: true,
|
|
125
|
-
alternativeFunctionName:
|
|
74
|
+
alternativeFunctionName: "getEntityRecords"
|
|
126
75
|
});
|
|
127
76
|
return selectors.getEntityRecords(state, kind, name, query);
|
|
128
77
|
};
|
|
@@ -130,81 +79,75 @@ const entitySelectors = entitiesConfig.reduce((result, entity) => {
|
|
|
130
79
|
return result;
|
|
131
80
|
}, {});
|
|
132
81
|
const entityResolvers = entitiesConfig.reduce((result, entity) => {
|
|
133
|
-
const {
|
|
134
|
-
|
|
135
|
-
name,
|
|
136
|
-
plural
|
|
137
|
-
} = entity;
|
|
138
|
-
const getEntityRecordMethodName = (0, _entities.getMethodName)(kind, name);
|
|
82
|
+
const { kind, name, plural } = entity;
|
|
83
|
+
const getEntityRecordMethodName = (0, import_entities.getMethodName)(kind, name);
|
|
139
84
|
result[getEntityRecordMethodName] = (key, query) => {
|
|
140
|
-
(0,
|
|
85
|
+
(0, import_log_entity_deprecation.default)(kind, name, getEntityRecordMethodName, {
|
|
141
86
|
isShorthandSelector: true,
|
|
142
|
-
alternativeFunctionName:
|
|
87
|
+
alternativeFunctionName: "getEntityRecord"
|
|
143
88
|
});
|
|
144
89
|
return resolvers.getEntityRecord(kind, name, key, query);
|
|
145
90
|
};
|
|
146
91
|
if (plural) {
|
|
147
|
-
const getEntityRecordsMethodName = (0,
|
|
92
|
+
const getEntityRecordsMethodName = (0, import_entities.getMethodName)(kind, plural, "get");
|
|
148
93
|
result[getEntityRecordsMethodName] = (...args) => {
|
|
149
|
-
(0,
|
|
94
|
+
(0, import_log_entity_deprecation.default)(kind, plural, getEntityRecordsMethodName, {
|
|
150
95
|
isShorthandSelector: true,
|
|
151
|
-
alternativeFunctionName:
|
|
96
|
+
alternativeFunctionName: "getEntityRecords"
|
|
152
97
|
});
|
|
153
98
|
return resolvers.getEntityRecords(kind, name, ...args);
|
|
154
99
|
};
|
|
155
|
-
result[getEntityRecordsMethodName].shouldInvalidate = action => resolvers.getEntityRecords.shouldInvalidate(action, kind, name);
|
|
100
|
+
result[getEntityRecordsMethodName].shouldInvalidate = (action) => resolvers.getEntityRecords.shouldInvalidate(action, kind, name);
|
|
156
101
|
}
|
|
157
102
|
return result;
|
|
158
103
|
}, {});
|
|
159
104
|
const entityActions = entitiesConfig.reduce((result, entity) => {
|
|
160
|
-
const {
|
|
161
|
-
|
|
162
|
-
name
|
|
163
|
-
} = entity;
|
|
164
|
-
const saveEntityRecordMethodName = (0, _entities.getMethodName)(kind, name, 'save');
|
|
105
|
+
const { kind, name } = entity;
|
|
106
|
+
const saveEntityRecordMethodName = (0, import_entities.getMethodName)(kind, name, "save");
|
|
165
107
|
result[saveEntityRecordMethodName] = (record, options) => {
|
|
166
|
-
(0,
|
|
108
|
+
(0, import_log_entity_deprecation.default)(kind, name, saveEntityRecordMethodName, {
|
|
167
109
|
isShorthandSelector: true,
|
|
168
|
-
alternativeFunctionName:
|
|
110
|
+
alternativeFunctionName: "saveEntityRecord"
|
|
169
111
|
});
|
|
170
112
|
return actions.saveEntityRecord(kind, name, record, options);
|
|
171
113
|
};
|
|
172
|
-
const deleteEntityRecordMethodName = (0,
|
|
114
|
+
const deleteEntityRecordMethodName = (0, import_entities.getMethodName)(kind, name, "delete");
|
|
173
115
|
result[deleteEntityRecordMethodName] = (key, query, options) => {
|
|
174
|
-
(0,
|
|
116
|
+
(0, import_log_entity_deprecation.default)(kind, name, deleteEntityRecordMethodName, {
|
|
175
117
|
isShorthandSelector: true,
|
|
176
|
-
alternativeFunctionName:
|
|
118
|
+
alternativeFunctionName: "deleteEntityRecord"
|
|
177
119
|
});
|
|
178
120
|
return actions.deleteEntityRecord(kind, name, key, query, options);
|
|
179
121
|
};
|
|
180
122
|
return result;
|
|
181
123
|
}, {});
|
|
182
124
|
const storeConfig = () => ({
|
|
183
|
-
reducer:
|
|
125
|
+
reducer: import_reducer.default,
|
|
184
126
|
actions: {
|
|
185
|
-
...
|
|
127
|
+
...import_dynamic_entities.dynamicActions,
|
|
186
128
|
...actions,
|
|
187
129
|
...entityActions,
|
|
188
|
-
...(0,
|
|
130
|
+
...(0, import_actions.default)()
|
|
189
131
|
},
|
|
190
132
|
selectors: {
|
|
191
|
-
...
|
|
133
|
+
...import_dynamic_entities.dynamicSelectors,
|
|
192
134
|
...selectors,
|
|
193
135
|
...entitySelectors
|
|
194
136
|
},
|
|
195
|
-
resolvers: {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
137
|
+
resolvers: { ...resolvers, ...entityResolvers }
|
|
138
|
+
});
|
|
139
|
+
const store = (0, import_data.createReduxStore)(import_name.STORE_NAME, storeConfig());
|
|
140
|
+
(0, import_lock_unlock.unlock)(store).registerPrivateSelectors(privateSelectors);
|
|
141
|
+
(0, import_lock_unlock.unlock)(store).registerPrivateActions(privateActions);
|
|
142
|
+
(0, import_data.register)(store);
|
|
143
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
+
0 && (module.exports = {
|
|
145
|
+
EntityProvider,
|
|
146
|
+
store,
|
|
147
|
+
...require("./entity-provider"),
|
|
148
|
+
...require("./entity-types"),
|
|
149
|
+
...require("./fetch"),
|
|
150
|
+
...require("./hooks"),
|
|
151
|
+
...require("./private-apis")
|
|
199
152
|
});
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Store definition for the code data namespace.
|
|
203
|
-
*
|
|
204
|
-
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
205
|
-
*/
|
|
206
|
-
const store = exports.store = (0, _data.createReduxStore)(_name.STORE_NAME, storeConfig());
|
|
207
|
-
(0, _lockUnlock.unlock)(store).registerPrivateSelectors(privateSelectors);
|
|
208
|
-
(0, _lockUnlock.unlock)(store).registerPrivateActions(privateActions);
|
|
209
|
-
(0, _data.register)(store); // Register store after unlocking private selectors to allow resolvers to use them.
|
|
210
|
-
//# sourceMappingURL=index.js.map
|
|
153
|
+
//# sourceMappingURL=index.js.map
|