@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
package/build/resolvers.js
CHANGED
|
@@ -1,325 +1,370 @@
|
|
|
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 resolvers_exports = {};
|
|
30
|
+
__export(resolvers_exports, {
|
|
31
|
+
__experimentalGetCurrentGlobalStylesId: () => __experimentalGetCurrentGlobalStylesId,
|
|
32
|
+
__experimentalGetCurrentThemeBaseGlobalStyles: () => __experimentalGetCurrentThemeBaseGlobalStyles,
|
|
33
|
+
__experimentalGetCurrentThemeGlobalStylesVariations: () => __experimentalGetCurrentThemeGlobalStylesVariations,
|
|
34
|
+
canUser: () => canUser,
|
|
35
|
+
canUserEditEntityRecord: () => canUserEditEntityRecord,
|
|
36
|
+
getAuthors: () => getAuthors,
|
|
37
|
+
getAutosave: () => getAutosave,
|
|
38
|
+
getAutosaves: () => getAutosaves,
|
|
39
|
+
getBlockPatternCategories: () => getBlockPatternCategories,
|
|
40
|
+
getBlockPatterns: () => getBlockPatterns,
|
|
41
|
+
getCurrentTheme: () => getCurrentTheme,
|
|
42
|
+
getCurrentThemeGlobalStylesRevisions: () => getCurrentThemeGlobalStylesRevisions,
|
|
43
|
+
getCurrentUser: () => getCurrentUser,
|
|
44
|
+
getDefaultTemplateId: () => getDefaultTemplateId,
|
|
45
|
+
getEditedEntityRecord: () => getEditedEntityRecord,
|
|
46
|
+
getEmbedPreview: () => getEmbedPreview,
|
|
47
|
+
getEntitiesConfig: () => getEntitiesConfig,
|
|
48
|
+
getEntityRecord: () => getEntityRecord,
|
|
49
|
+
getEntityRecords: () => getEntityRecords,
|
|
50
|
+
getEntityRecordsTotalItems: () => getEntityRecordsTotalItems,
|
|
51
|
+
getEntityRecordsTotalPages: () => getEntityRecordsTotalPages,
|
|
52
|
+
getNavigationFallbackId: () => getNavigationFallbackId,
|
|
53
|
+
getRawEntityRecord: () => getRawEntityRecord,
|
|
54
|
+
getRegisteredPostMeta: () => getRegisteredPostMeta,
|
|
55
|
+
getRevision: () => getRevision,
|
|
56
|
+
getRevisions: () => getRevisions,
|
|
57
|
+
getTemplateAutoDraftId: () => getTemplateAutoDraftId,
|
|
58
|
+
getThemeSupports: () => getThemeSupports,
|
|
59
|
+
getUserPatternCategories: () => getUserPatternCategories
|
|
6
60
|
});
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Internal dependencies
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Requests authors from the REST API.
|
|
31
|
-
*
|
|
32
|
-
* @param {Object|undefined} query Optional object of query parameters to
|
|
33
|
-
* include with request.
|
|
34
|
-
*/
|
|
35
|
-
const getAuthors = query => async ({
|
|
36
|
-
dispatch
|
|
37
|
-
}) => {
|
|
38
|
-
const path = (0, _url.addQueryArgs)('/wp/v2/users/?who=authors&per_page=100', query);
|
|
39
|
-
const users = await (0, _apiFetch.default)({
|
|
40
|
-
path
|
|
41
|
-
});
|
|
61
|
+
module.exports = __toCommonJS(resolvers_exports);
|
|
62
|
+
var import_change_case = require("change-case");
|
|
63
|
+
var import_url = require("@wordpress/url");
|
|
64
|
+
var import_html_entities = require("@wordpress/html-entities");
|
|
65
|
+
var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
|
|
66
|
+
var import_name = require("./name");
|
|
67
|
+
var import_entities = require("./entities");
|
|
68
|
+
var import_sync = require("./sync");
|
|
69
|
+
var import_utils = require("./utils");
|
|
70
|
+
var import_fetch = require("./fetch");
|
|
71
|
+
const getAuthors = (query) => async ({ dispatch }) => {
|
|
72
|
+
const path = (0, import_url.addQueryArgs)(
|
|
73
|
+
"/wp/v2/users/?who=authors&per_page=100",
|
|
74
|
+
query
|
|
75
|
+
);
|
|
76
|
+
const users = await (0, import_api_fetch.default)({ path });
|
|
42
77
|
dispatch.receiveUserQuery(path, users);
|
|
43
78
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* Requests the current user from the REST API.
|
|
47
|
-
*/
|
|
48
|
-
exports.getAuthors = getAuthors;
|
|
49
|
-
const getCurrentUser = () => async ({
|
|
50
|
-
dispatch
|
|
51
|
-
}) => {
|
|
52
|
-
const currentUser = await (0, _apiFetch.default)({
|
|
53
|
-
path: '/wp/v2/users/me'
|
|
54
|
-
});
|
|
79
|
+
const getCurrentUser = () => async ({ dispatch }) => {
|
|
80
|
+
const currentUser = await (0, import_api_fetch.default)({ path: "/wp/v2/users/me" });
|
|
55
81
|
dispatch.receiveCurrentUser(currentUser);
|
|
56
82
|
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Requests an entity's record from the REST API.
|
|
60
|
-
*
|
|
61
|
-
* @param {string} kind Entity kind.
|
|
62
|
-
* @param {string} name Entity name.
|
|
63
|
-
* @param {number|string} key Record's key
|
|
64
|
-
* @param {Object|undefined} query Optional object of query parameters to
|
|
65
|
-
* include with request. If requesting specific
|
|
66
|
-
* fields, fields must always include the ID.
|
|
67
|
-
*/
|
|
68
|
-
exports.getCurrentUser = getCurrentUser;
|
|
69
|
-
const getEntityRecord = (kind, name, key = '', query) => async ({
|
|
70
|
-
select,
|
|
71
|
-
dispatch,
|
|
72
|
-
registry,
|
|
73
|
-
resolveSelect
|
|
74
|
-
}) => {
|
|
75
|
-
// For back-compat, we allow querying for static templates through
|
|
76
|
-
// wp_template.
|
|
77
|
-
if (kind === 'postType' && name === 'wp_template' && typeof key === 'string' &&
|
|
78
|
-
// __experimentalGetDirtyEntityRecords always calls getEntityRecord
|
|
79
|
-
// with a string key, so we need that it's not a numeric ID.
|
|
80
|
-
!/^\d+$/.test(key)) {
|
|
81
|
-
name = 'wp_registered_template';
|
|
82
|
-
}
|
|
83
|
+
const getEntityRecord = (kind, name, key = "", query) => async ({ select, dispatch, registry, resolveSelect }) => {
|
|
83
84
|
const configs = await resolveSelect.getEntitiesConfig(kind);
|
|
84
|
-
const entityConfig = configs.find(
|
|
85
|
+
const entityConfig = configs.find(
|
|
86
|
+
(config) => config.name === name && config.kind === kind
|
|
87
|
+
);
|
|
85
88
|
if (!entityConfig) {
|
|
86
89
|
return;
|
|
87
90
|
}
|
|
88
|
-
const lock = await dispatch.__unstableAcquireStoreLock(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
const lock = await dispatch.__unstableAcquireStoreLock(
|
|
92
|
+
import_name.STORE_NAME,
|
|
93
|
+
["entities", "records", kind, name, key],
|
|
94
|
+
{ exclusive: false }
|
|
95
|
+
);
|
|
91
96
|
try {
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
if (query !== void 0 && query._fields) {
|
|
98
|
+
query = {
|
|
99
|
+
...query,
|
|
100
|
+
_fields: [
|
|
101
|
+
.../* @__PURE__ */ new Set([
|
|
102
|
+
...(0, import_utils.getNormalizedCommaSeparable)(query._fields) || [],
|
|
103
|
+
entityConfig.key || import_entities.DEFAULT_ENTITY_KEY
|
|
104
|
+
])
|
|
105
|
+
].join()
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
if (query !== void 0 && query._fields) {
|
|
109
|
+
const hasRecord = select.hasEntityRecord(
|
|
110
|
+
kind,
|
|
111
|
+
name,
|
|
112
|
+
key,
|
|
113
|
+
query
|
|
114
|
+
);
|
|
115
|
+
if (hasRecord) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
let { baseURL } = entityConfig;
|
|
120
|
+
if (kind === "postType" && name === "wp_template" && key && typeof key === "string" && !/^\d+$/.test(key)) {
|
|
121
|
+
baseURL = baseURL.slice(0, baseURL.lastIndexOf("/")) + "/templates";
|
|
122
|
+
}
|
|
123
|
+
const path = (0, import_url.addQueryArgs)(baseURL + (key ? "/" + key : ""), {
|
|
124
|
+
...entityConfig.baseURLParams,
|
|
125
|
+
...query
|
|
126
|
+
});
|
|
127
|
+
const response = await (0, import_api_fetch.default)({ path, parse: false });
|
|
128
|
+
const record = await response.json();
|
|
129
|
+
const permissions = (0, import_utils.getUserPermissionsFromAllowHeader)(
|
|
130
|
+
response.headers?.get("allow")
|
|
131
|
+
);
|
|
132
|
+
const canUserResolutionsArgs = [];
|
|
133
|
+
const receiveUserPermissionArgs = {};
|
|
134
|
+
for (const action of import_utils.ALLOWED_RESOURCE_ACTIONS) {
|
|
135
|
+
receiveUserPermissionArgs[(0, import_utils.getUserPermissionCacheKey)(action, {
|
|
136
|
+
kind,
|
|
137
|
+
name,
|
|
138
|
+
id: key
|
|
139
|
+
})] = permissions[action];
|
|
140
|
+
canUserResolutionsArgs.push([
|
|
141
|
+
action,
|
|
142
|
+
{ kind, name, id: key }
|
|
143
|
+
]);
|
|
144
|
+
}
|
|
94
145
|
if (window.__experimentalEnableSync && entityConfig.syncConfig && !query) {
|
|
95
146
|
if (globalThis.IS_GUTENBERG_PLUGIN) {
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// Bootstraps the edited document as well (and load from peers).
|
|
104
|
-
await (0, _sync.getSyncProvider)().bootstrap(entityConfig.syncObjectType + '--edit', objectId, record => {
|
|
105
|
-
dispatch({
|
|
106
|
-
type: 'EDIT_ENTITY_RECORD',
|
|
107
|
-
kind,
|
|
108
|
-
name,
|
|
109
|
-
recordId: key,
|
|
110
|
-
edits: record,
|
|
111
|
-
meta: {
|
|
112
|
-
undo: undefined
|
|
113
|
-
}
|
|
114
|
-
});
|
|
147
|
+
const objectType = `${kind}/${name}`;
|
|
148
|
+
const objectId = key;
|
|
149
|
+
const recordWithTransients = { ...record };
|
|
150
|
+
Object.entries(entityConfig.transientEdits ?? {}).filter(
|
|
151
|
+
([propName, transientConfig]) => void 0 === recordWithTransients[propName] && transientConfig && "object" === typeof transientConfig && "read" in transientConfig && "function" === typeof transientConfig.read
|
|
152
|
+
).forEach(([propName, transientConfig]) => {
|
|
153
|
+
recordWithTransients[propName] = transientConfig.read(recordWithTransients);
|
|
115
154
|
});
|
|
155
|
+
await import_sync.syncManager.load(
|
|
156
|
+
entityConfig.syncConfig,
|
|
157
|
+
objectType,
|
|
158
|
+
objectId,
|
|
159
|
+
recordWithTransients,
|
|
160
|
+
{
|
|
161
|
+
// Handle edits sourced from the sync manager.
|
|
162
|
+
editRecord: (edits) => {
|
|
163
|
+
if (!Object.keys(edits).length) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
dispatch({
|
|
167
|
+
type: "EDIT_ENTITY_RECORD",
|
|
168
|
+
kind,
|
|
169
|
+
name,
|
|
170
|
+
recordId: key,
|
|
171
|
+
edits,
|
|
172
|
+
meta: {
|
|
173
|
+
undo: void 0
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
// Get the current entity record (with edits)
|
|
178
|
+
getEditedRecord: async () => await resolveSelect.getEditedEntityRecord(
|
|
179
|
+
kind,
|
|
180
|
+
name,
|
|
181
|
+
key
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
);
|
|
116
185
|
}
|
|
117
|
-
} else {
|
|
118
|
-
if (query !== undefined && query._fields) {
|
|
119
|
-
// If requesting specific fields, items and query association to said
|
|
120
|
-
// records are stored by ID reference. Thus, fields must always include
|
|
121
|
-
// the ID.
|
|
122
|
-
query = {
|
|
123
|
-
...query,
|
|
124
|
-
_fields: [...new Set([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entityConfig.key || _entities.DEFAULT_ENTITY_KEY])].join()
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
if (query !== undefined && query._fields) {
|
|
128
|
-
// The resolution cache won't consider query as reusable based on the
|
|
129
|
-
// fields, so it's tested here, prior to initiating the REST request,
|
|
130
|
-
// and without causing `getEntityRecord` resolution to occur.
|
|
131
|
-
const hasRecord = select.hasEntityRecord(kind, name, key, query);
|
|
132
|
-
if (hasRecord) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
const path = (0, _url.addQueryArgs)(entityConfig.baseURL + (key ? '/' + key : ''), {
|
|
137
|
-
...entityConfig.baseURLParams,
|
|
138
|
-
...query
|
|
139
|
-
});
|
|
140
|
-
const response = await (0, _apiFetch.default)({
|
|
141
|
-
path,
|
|
142
|
-
parse: false
|
|
143
|
-
});
|
|
144
|
-
const record = await response.json();
|
|
145
|
-
const permissions = (0, _utils.getUserPermissionsFromAllowHeader)(response.headers?.get('allow'));
|
|
146
|
-
const canUserResolutionsArgs = [];
|
|
147
|
-
const receiveUserPermissionArgs = {};
|
|
148
|
-
for (const action of _utils.ALLOWED_RESOURCE_ACTIONS) {
|
|
149
|
-
receiveUserPermissionArgs[(0, _utils.getUserPermissionCacheKey)(action, {
|
|
150
|
-
kind,
|
|
151
|
-
name,
|
|
152
|
-
id: key
|
|
153
|
-
})] = permissions[action];
|
|
154
|
-
canUserResolutionsArgs.push([action, {
|
|
155
|
-
kind,
|
|
156
|
-
name,
|
|
157
|
-
id: key
|
|
158
|
-
}]);
|
|
159
|
-
}
|
|
160
|
-
registry.batch(() => {
|
|
161
|
-
dispatch.receiveEntityRecords(kind, name, record, query);
|
|
162
|
-
dispatch.receiveUserPermissions(receiveUserPermissionArgs);
|
|
163
|
-
dispatch.finishResolutions('canUser', canUserResolutionsArgs);
|
|
164
|
-
});
|
|
165
186
|
}
|
|
187
|
+
registry.batch(() => {
|
|
188
|
+
dispatch.receiveEntityRecords(kind, name, record, query);
|
|
189
|
+
dispatch.receiveUserPermissions(receiveUserPermissionArgs);
|
|
190
|
+
dispatch.finishResolutions("canUser", canUserResolutionsArgs);
|
|
191
|
+
});
|
|
166
192
|
} finally {
|
|
167
193
|
dispatch.__unstableReleaseStoreLock(lock);
|
|
168
194
|
}
|
|
169
195
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
await dispatch.
|
|
196
|
+
getEntityRecord.shouldInvalidate = (action, kind, name) => {
|
|
197
|
+
return kind === "root" && name === "site" && (action.type === "RECEIVE_ITEMS" && // Making sure persistedEdits is set seems to be the only way of
|
|
198
|
+
// knowing whether it's an update or fetch. Only an update would
|
|
199
|
+
// have persistedEdits.
|
|
200
|
+
action.persistedEdits && action.persistedEdits.status !== "auto-draft" || action.type === "REMOVE_ITEMS") && action.kind === "postType" && action.name === "wp_template";
|
|
201
|
+
};
|
|
202
|
+
const getTemplateAutoDraftId = (staticTemplateId) => async ({ resolveSelect, dispatch }) => {
|
|
203
|
+
const record = await resolveSelect.getEntityRecord(
|
|
204
|
+
"postType",
|
|
205
|
+
"wp_registered_template",
|
|
206
|
+
staticTemplateId
|
|
207
|
+
);
|
|
208
|
+
const autoDraft = await dispatch.saveEntityRecord(
|
|
209
|
+
"postType",
|
|
210
|
+
"wp_template",
|
|
211
|
+
{
|
|
212
|
+
...record,
|
|
213
|
+
id: void 0,
|
|
214
|
+
type: "wp_template",
|
|
215
|
+
status: "auto-draft"
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
await dispatch.receiveTemplateAutoDraftId(
|
|
219
|
+
staticTemplateId,
|
|
220
|
+
autoDraft.id
|
|
221
|
+
);
|
|
183
222
|
};
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
*/
|
|
188
|
-
exports.getTemplateAutoDraftId = getTemplateAutoDraftId;
|
|
189
|
-
const getRawEntityRecord = exports.getRawEntityRecord = (0, _utils.forwardResolver)('getEntityRecord');
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Requests an entity's record from the REST API.
|
|
193
|
-
*/
|
|
194
|
-
const getEditedEntityRecord = exports.getEditedEntityRecord = (0, _utils.forwardResolver)('getEntityRecord');
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Requests the entity's records from the REST API.
|
|
198
|
-
*
|
|
199
|
-
* @param {string} kind Entity kind.
|
|
200
|
-
* @param {string} name Entity name.
|
|
201
|
-
* @param {?Object} query Query Object. If requesting specific fields, fields
|
|
202
|
-
* must always include the ID.
|
|
203
|
-
*/
|
|
204
|
-
const getEntityRecords = (kind, name, query = {}) => async ({
|
|
205
|
-
dispatch,
|
|
206
|
-
registry,
|
|
207
|
-
resolveSelect
|
|
208
|
-
}) => {
|
|
223
|
+
const getRawEntityRecord = (0, import_utils.forwardResolver)("getEntityRecord");
|
|
224
|
+
const getEditedEntityRecord = (0, import_utils.forwardResolver)("getEntityRecord");
|
|
225
|
+
const getEntityRecords = (kind, name, query = {}) => async ({ dispatch, registry, resolveSelect }) => {
|
|
209
226
|
const configs = await resolveSelect.getEntitiesConfig(kind);
|
|
210
|
-
const entityConfig = configs.find(
|
|
227
|
+
const entityConfig = configs.find(
|
|
228
|
+
(config) => config.name === name && config.kind === kind
|
|
229
|
+
);
|
|
211
230
|
if (!entityConfig) {
|
|
212
231
|
return;
|
|
213
232
|
}
|
|
214
|
-
const lock = await dispatch.__unstableAcquireStoreLock(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
// resolutions as finished.
|
|
222
|
-
const rawQuery = {
|
|
223
|
-
...query
|
|
224
|
-
};
|
|
225
|
-
const key = entityConfig.key || _entities.DEFAULT_ENTITY_KEY;
|
|
233
|
+
const lock = await dispatch.__unstableAcquireStoreLock(
|
|
234
|
+
import_name.STORE_NAME,
|
|
235
|
+
["entities", "records", kind, name],
|
|
236
|
+
{ exclusive: false }
|
|
237
|
+
);
|
|
238
|
+
const rawQuery = { ...query };
|
|
239
|
+
const key = entityConfig.key || import_entities.DEFAULT_ENTITY_KEY;
|
|
226
240
|
function getResolutionsArgs(records, recordsQuery) {
|
|
227
|
-
const queryArgs = Object.fromEntries(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
241
|
+
const queryArgs = Object.fromEntries(
|
|
242
|
+
Object.entries(recordsQuery).filter(([k, v]) => {
|
|
243
|
+
return ["context", "_fields"].includes(k) && !!v;
|
|
244
|
+
})
|
|
245
|
+
);
|
|
246
|
+
return records.filter((record) => record?.[key]).map((record) => [
|
|
247
|
+
kind,
|
|
248
|
+
name,
|
|
249
|
+
record[key],
|
|
250
|
+
Object.keys(queryArgs).length > 0 ? queryArgs : void 0
|
|
251
|
+
]);
|
|
231
252
|
}
|
|
232
253
|
try {
|
|
233
254
|
if (query._fields) {
|
|
234
|
-
// If requesting specific fields, items and query association to said
|
|
235
|
-
// records are stored by ID reference. Thus, fields must always include
|
|
236
|
-
// the ID.
|
|
237
255
|
query = {
|
|
238
256
|
...query,
|
|
239
|
-
_fields: [
|
|
257
|
+
_fields: [
|
|
258
|
+
.../* @__PURE__ */ new Set([
|
|
259
|
+
...(0, import_utils.getNormalizedCommaSeparable)(query._fields) || [],
|
|
260
|
+
key
|
|
261
|
+
])
|
|
262
|
+
].join()
|
|
240
263
|
};
|
|
241
264
|
}
|
|
242
|
-
|
|
265
|
+
let { baseURL } = entityConfig;
|
|
266
|
+
const { combinedTemplates = true } = query;
|
|
267
|
+
if (kind === "postType" && name === "wp_template" && combinedTemplates) {
|
|
268
|
+
baseURL = baseURL.slice(0, baseURL.lastIndexOf("/")) + "/templates";
|
|
269
|
+
}
|
|
270
|
+
const path = (0, import_url.addQueryArgs)(baseURL, {
|
|
243
271
|
...entityConfig.baseURLParams,
|
|
244
272
|
...query
|
|
245
273
|
});
|
|
246
|
-
let records = [],
|
|
247
|
-
meta;
|
|
274
|
+
let records = [], meta;
|
|
248
275
|
if (entityConfig.supportsPagination && query.per_page !== -1) {
|
|
249
|
-
const response = await (0,
|
|
250
|
-
path,
|
|
251
|
-
parse: false
|
|
252
|
-
});
|
|
276
|
+
const response = await (0, import_api_fetch.default)({ path, parse: false });
|
|
253
277
|
records = Object.values(await response.json());
|
|
254
278
|
meta = {
|
|
255
|
-
totalItems: parseInt(
|
|
256
|
-
|
|
279
|
+
totalItems: parseInt(
|
|
280
|
+
response.headers.get("X-WP-Total")
|
|
281
|
+
),
|
|
282
|
+
totalPages: parseInt(
|
|
283
|
+
response.headers.get("X-WP-TotalPages")
|
|
284
|
+
)
|
|
257
285
|
};
|
|
258
|
-
} else if (query.per_page === -1 && query[
|
|
286
|
+
} else if (query.per_page === -1 && query[import_utils.RECEIVE_INTERMEDIATE_RESULTS] === true) {
|
|
259
287
|
let page = 1;
|
|
260
288
|
let totalPages;
|
|
261
289
|
do {
|
|
262
|
-
const response = await (0,
|
|
263
|
-
path: (0,
|
|
264
|
-
page,
|
|
265
|
-
per_page: 100
|
|
266
|
-
}),
|
|
290
|
+
const response = await (0, import_api_fetch.default)({
|
|
291
|
+
path: (0, import_url.addQueryArgs)(path, { page, per_page: 100 }),
|
|
267
292
|
parse: false
|
|
268
293
|
});
|
|
269
294
|
const pageRecords = Object.values(await response.json());
|
|
270
|
-
totalPages = parseInt(
|
|
295
|
+
totalPages = parseInt(
|
|
296
|
+
response.headers.get("X-WP-TotalPages")
|
|
297
|
+
);
|
|
271
298
|
if (!meta) {
|
|
272
299
|
meta = {
|
|
273
|
-
totalItems: parseInt(
|
|
300
|
+
totalItems: parseInt(
|
|
301
|
+
response.headers.get("X-WP-Total")
|
|
302
|
+
),
|
|
274
303
|
totalPages: 1
|
|
275
304
|
};
|
|
276
305
|
}
|
|
277
306
|
records.push(...pageRecords);
|
|
278
307
|
registry.batch(() => {
|
|
279
|
-
dispatch.receiveEntityRecords(
|
|
280
|
-
|
|
308
|
+
dispatch.receiveEntityRecords(
|
|
309
|
+
kind,
|
|
310
|
+
name,
|
|
311
|
+
records,
|
|
312
|
+
query,
|
|
313
|
+
false,
|
|
314
|
+
void 0,
|
|
315
|
+
meta
|
|
316
|
+
);
|
|
317
|
+
dispatch.finishResolutions(
|
|
318
|
+
"getEntityRecord",
|
|
319
|
+
getResolutionsArgs(pageRecords, rawQuery)
|
|
320
|
+
);
|
|
281
321
|
});
|
|
282
322
|
page++;
|
|
283
323
|
} while (page <= totalPages);
|
|
284
324
|
} else {
|
|
285
|
-
records = Object.values(await (0,
|
|
286
|
-
path
|
|
287
|
-
}));
|
|
325
|
+
records = Object.values(await (0, import_api_fetch.default)({ path }));
|
|
288
326
|
meta = {
|
|
289
327
|
totalItems: records.length,
|
|
290
328
|
totalPages: 1
|
|
291
329
|
};
|
|
292
330
|
}
|
|
293
|
-
|
|
294
|
-
// If we request fields but the result doesn't contain the fields,
|
|
295
|
-
// explicitly set these fields as "undefined"
|
|
296
|
-
// that way we consider the query "fulfilled".
|
|
297
331
|
if (query._fields) {
|
|
298
|
-
records = records.map(record => {
|
|
299
|
-
query._fields.split(
|
|
332
|
+
records = records.map((record) => {
|
|
333
|
+
query._fields.split(",").forEach((field) => {
|
|
300
334
|
if (!record.hasOwnProperty(field)) {
|
|
301
|
-
record[field] =
|
|
335
|
+
record[field] = void 0;
|
|
302
336
|
}
|
|
303
337
|
});
|
|
304
338
|
return record;
|
|
305
339
|
});
|
|
306
340
|
}
|
|
307
341
|
registry.batch(() => {
|
|
308
|
-
dispatch.receiveEntityRecords(
|
|
309
|
-
|
|
342
|
+
dispatch.receiveEntityRecords(
|
|
343
|
+
kind,
|
|
344
|
+
name,
|
|
345
|
+
records,
|
|
346
|
+
query,
|
|
347
|
+
false,
|
|
348
|
+
void 0,
|
|
349
|
+
meta
|
|
350
|
+
);
|
|
351
|
+
const targetHints = records.filter(
|
|
352
|
+
(record) => !!record?.[key] && !!record?._links?.self?.[0]?.targetHints?.allow
|
|
353
|
+
).map((record) => ({
|
|
310
354
|
id: record[key],
|
|
311
|
-
permissions: (0,
|
|
355
|
+
permissions: (0, import_utils.getUserPermissionsFromAllowHeader)(
|
|
356
|
+
record._links.self[0].targetHints.allow
|
|
357
|
+
)
|
|
312
358
|
}));
|
|
313
359
|
const canUserResolutionsArgs = [];
|
|
314
360
|
const receiveUserPermissionArgs = {};
|
|
315
361
|
for (const targetHint of targetHints) {
|
|
316
|
-
for (const action of
|
|
317
|
-
canUserResolutionsArgs.push([
|
|
318
|
-
|
|
319
|
-
name,
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
receiveUserPermissionArgs[(0, _utils.getUserPermissionCacheKey)(action, {
|
|
362
|
+
for (const action of import_utils.ALLOWED_RESOURCE_ACTIONS) {
|
|
363
|
+
canUserResolutionsArgs.push([
|
|
364
|
+
action,
|
|
365
|
+
{ kind, name, id: targetHint.id }
|
|
366
|
+
]);
|
|
367
|
+
receiveUserPermissionArgs[(0, import_utils.getUserPermissionCacheKey)(action, {
|
|
323
368
|
kind,
|
|
324
369
|
name,
|
|
325
370
|
id: targetHint.id
|
|
@@ -327,327 +372,231 @@ const getEntityRecords = (kind, name, query = {}) => async ({
|
|
|
327
372
|
}
|
|
328
373
|
}
|
|
329
374
|
if (targetHints.length > 0) {
|
|
330
|
-
dispatch.receiveUserPermissions(
|
|
331
|
-
|
|
375
|
+
dispatch.receiveUserPermissions(
|
|
376
|
+
receiveUserPermissionArgs
|
|
377
|
+
);
|
|
378
|
+
dispatch.finishResolutions(
|
|
379
|
+
"canUser",
|
|
380
|
+
canUserResolutionsArgs
|
|
381
|
+
);
|
|
332
382
|
}
|
|
333
|
-
dispatch.finishResolutions(
|
|
383
|
+
dispatch.finishResolutions(
|
|
384
|
+
"getEntityRecord",
|
|
385
|
+
getResolutionsArgs(records, rawQuery)
|
|
386
|
+
);
|
|
334
387
|
dispatch.__unstableReleaseStoreLock(lock);
|
|
335
388
|
});
|
|
336
389
|
} catch (e) {
|
|
337
390
|
dispatch.__unstableReleaseStoreLock(lock);
|
|
338
391
|
}
|
|
339
392
|
};
|
|
340
|
-
exports.getEntityRecords = getEntityRecords;
|
|
341
393
|
getEntityRecords.shouldInvalidate = (action, kind, name) => {
|
|
342
|
-
return (action.type ===
|
|
394
|
+
return (action.type === "RECEIVE_ITEMS" || action.type === "REMOVE_ITEMS") && action.invalidateCache && kind === action.kind && name === action.name;
|
|
343
395
|
};
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
*/
|
|
353
|
-
const getEntityRecordsTotalPages = exports.getEntityRecordsTotalPages = (0, _utils.forwardResolver)('getEntityRecords');
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Requests the current theme.
|
|
357
|
-
*/
|
|
358
|
-
const getCurrentTheme = () => async ({
|
|
359
|
-
dispatch,
|
|
360
|
-
resolveSelect
|
|
361
|
-
}) => {
|
|
362
|
-
const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
|
|
363
|
-
status: 'active'
|
|
364
|
-
});
|
|
396
|
+
const getEntityRecordsTotalItems = (0, import_utils.forwardResolver)("getEntityRecords");
|
|
397
|
+
const getEntityRecordsTotalPages = (0, import_utils.forwardResolver)("getEntityRecords");
|
|
398
|
+
const getCurrentTheme = () => async ({ dispatch, resolveSelect }) => {
|
|
399
|
+
const activeThemes = await resolveSelect.getEntityRecords(
|
|
400
|
+
"root",
|
|
401
|
+
"theme",
|
|
402
|
+
{ status: "active" }
|
|
403
|
+
);
|
|
365
404
|
dispatch.receiveCurrentTheme(activeThemes[0]);
|
|
366
405
|
};
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
* Requests theme supports data from the index.
|
|
370
|
-
*/
|
|
371
|
-
exports.getCurrentTheme = getCurrentTheme;
|
|
372
|
-
const getThemeSupports = exports.getThemeSupports = (0, _utils.forwardResolver)('getCurrentTheme');
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* Requests a preview from the Embed API.
|
|
376
|
-
*
|
|
377
|
-
* @param {string} url URL to get the preview for.
|
|
378
|
-
*/
|
|
379
|
-
const getEmbedPreview = url => async ({
|
|
380
|
-
dispatch
|
|
381
|
-
}) => {
|
|
406
|
+
const getThemeSupports = (0, import_utils.forwardResolver)("getCurrentTheme");
|
|
407
|
+
const getEmbedPreview = (url) => async ({ dispatch }) => {
|
|
382
408
|
try {
|
|
383
|
-
const embedProxyResponse = await (0,
|
|
384
|
-
path: (0,
|
|
385
|
-
url
|
|
386
|
-
})
|
|
409
|
+
const embedProxyResponse = await (0, import_api_fetch.default)({
|
|
410
|
+
path: (0, import_url.addQueryArgs)("/oembed/1.0/proxy", { url })
|
|
387
411
|
});
|
|
388
412
|
dispatch.receiveEmbedPreview(url, embedProxyResponse);
|
|
389
413
|
} catch (error) {
|
|
390
|
-
// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.
|
|
391
414
|
dispatch.receiveEmbedPreview(url, false);
|
|
392
415
|
}
|
|
393
416
|
};
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
* Checks whether the current user can perform the given action on the given
|
|
397
|
-
* REST resource.
|
|
398
|
-
*
|
|
399
|
-
* @param {string} requestedAction Action to check. One of: 'create', 'read', 'update',
|
|
400
|
-
* 'delete'.
|
|
401
|
-
* @param {string|Object} resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`
|
|
402
|
-
* or REST base as a string - `media`.
|
|
403
|
-
* @param {?string} id ID of the rest resource to check.
|
|
404
|
-
*/
|
|
405
|
-
exports.getEmbedPreview = getEmbedPreview;
|
|
406
|
-
const canUser = (requestedAction, resource, id) => async ({
|
|
407
|
-
dispatch,
|
|
408
|
-
registry,
|
|
409
|
-
resolveSelect
|
|
410
|
-
}) => {
|
|
411
|
-
if (!_utils.ALLOWED_RESOURCE_ACTIONS.includes(requestedAction)) {
|
|
417
|
+
const canUser = (requestedAction, resource, id) => async ({ dispatch, registry, resolveSelect }) => {
|
|
418
|
+
if (!import_utils.ALLOWED_RESOURCE_ACTIONS.includes(requestedAction)) {
|
|
412
419
|
throw new Error(`'${requestedAction}' is not a valid action.`);
|
|
413
420
|
}
|
|
414
|
-
const {
|
|
415
|
-
|
|
416
|
-
} = registry.select(_name.STORE_NAME);
|
|
417
|
-
|
|
418
|
-
// Prevent resolving the same resource twice.
|
|
419
|
-
for (const relatedAction of _utils.ALLOWED_RESOURCE_ACTIONS) {
|
|
421
|
+
const { hasStartedResolution } = registry.select(import_name.STORE_NAME);
|
|
422
|
+
for (const relatedAction of import_utils.ALLOWED_RESOURCE_ACTIONS) {
|
|
420
423
|
if (relatedAction === requestedAction) {
|
|
421
424
|
continue;
|
|
422
425
|
}
|
|
423
|
-
const isAlreadyResolving = hasStartedResolution(
|
|
426
|
+
const isAlreadyResolving = hasStartedResolution("canUser", [
|
|
427
|
+
relatedAction,
|
|
428
|
+
resource,
|
|
429
|
+
id
|
|
430
|
+
]);
|
|
424
431
|
if (isAlreadyResolving) {
|
|
425
432
|
return;
|
|
426
433
|
}
|
|
427
434
|
}
|
|
428
435
|
let resourcePath = null;
|
|
429
|
-
if (typeof resource ===
|
|
436
|
+
if (typeof resource === "object") {
|
|
430
437
|
if (!resource.kind || !resource.name) {
|
|
431
|
-
throw new Error(
|
|
438
|
+
throw new Error("The entity resource object is not valid.");
|
|
432
439
|
}
|
|
433
|
-
const configs = await resolveSelect.getEntitiesConfig(
|
|
434
|
-
|
|
440
|
+
const configs = await resolveSelect.getEntitiesConfig(
|
|
441
|
+
resource.kind
|
|
442
|
+
);
|
|
443
|
+
const entityConfig = configs.find(
|
|
444
|
+
(config) => config.name === resource.name && config.kind === resource.kind
|
|
445
|
+
);
|
|
435
446
|
if (!entityConfig) {
|
|
436
447
|
return;
|
|
437
448
|
}
|
|
438
|
-
resourcePath = entityConfig.baseURL + (resource.id ?
|
|
449
|
+
resourcePath = entityConfig.baseURL + (resource.id ? "/" + resource.id : "");
|
|
439
450
|
} else {
|
|
440
|
-
resourcePath = `/wp/v2/${resource}` + (id ?
|
|
451
|
+
resourcePath = `/wp/v2/${resource}` + (id ? "/" + id : "");
|
|
441
452
|
}
|
|
442
453
|
let response;
|
|
443
454
|
try {
|
|
444
|
-
response = await (0,
|
|
455
|
+
response = await (0, import_api_fetch.default)({
|
|
445
456
|
path: resourcePath,
|
|
446
|
-
method:
|
|
457
|
+
method: "OPTIONS",
|
|
447
458
|
parse: false
|
|
448
459
|
});
|
|
449
460
|
} catch (error) {
|
|
450
|
-
// Do nothing if our OPTIONS request comes back with an API error (4xx or
|
|
451
|
-
// 5xx). The previously determined isAllowed value will remain in the store.
|
|
452
461
|
return;
|
|
453
462
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
// only return the result, without including response properties like the headers.
|
|
458
|
-
const permissions = (0, _utils.getUserPermissionsFromAllowHeader)(response.headers?.get('allow'));
|
|
463
|
+
const permissions = (0, import_utils.getUserPermissionsFromAllowHeader)(
|
|
464
|
+
response.headers?.get("allow")
|
|
465
|
+
);
|
|
459
466
|
registry.batch(() => {
|
|
460
|
-
for (const action of
|
|
461
|
-
const key = (0,
|
|
467
|
+
for (const action of import_utils.ALLOWED_RESOURCE_ACTIONS) {
|
|
468
|
+
const key = (0, import_utils.getUserPermissionCacheKey)(action, resource, id);
|
|
462
469
|
dispatch.receiveUserPermission(key, permissions[action]);
|
|
463
|
-
|
|
464
|
-
// Mark related action resolutions as finished.
|
|
465
470
|
if (action !== requestedAction) {
|
|
466
|
-
dispatch.finishResolution(
|
|
471
|
+
dispatch.finishResolution("canUser", [
|
|
472
|
+
action,
|
|
473
|
+
resource,
|
|
474
|
+
id
|
|
475
|
+
]);
|
|
467
476
|
}
|
|
468
477
|
}
|
|
469
478
|
});
|
|
470
479
|
};
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
* Checks whether the current user can perform the given action on the given
|
|
474
|
-
* REST resource.
|
|
475
|
-
*
|
|
476
|
-
* @param {string} kind Entity kind.
|
|
477
|
-
* @param {string} name Entity name.
|
|
478
|
-
* @param {number|string} recordId Record's id.
|
|
479
|
-
*/
|
|
480
|
-
exports.canUser = canUser;
|
|
481
|
-
const canUserEditEntityRecord = (kind, name, recordId) => async ({
|
|
482
|
-
dispatch
|
|
483
|
-
}) => {
|
|
484
|
-
await dispatch(canUser('update', {
|
|
485
|
-
kind,
|
|
486
|
-
name,
|
|
487
|
-
id: recordId
|
|
488
|
-
}));
|
|
480
|
+
const canUserEditEntityRecord = (kind, name, recordId) => async ({ dispatch }) => {
|
|
481
|
+
await dispatch(canUser("update", { kind, name, id: recordId }));
|
|
489
482
|
};
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* Request autosave data from the REST API.
|
|
493
|
-
*
|
|
494
|
-
* @param {string} postType The type of the parent post.
|
|
495
|
-
* @param {number} postId The id of the parent post.
|
|
496
|
-
*/
|
|
497
|
-
exports.canUserEditEntityRecord = canUserEditEntityRecord;
|
|
498
|
-
const getAutosaves = (postType, postId) => async ({
|
|
499
|
-
dispatch,
|
|
500
|
-
resolveSelect
|
|
501
|
-
}) => {
|
|
483
|
+
const getAutosaves = (postType, postId) => async ({ dispatch, resolveSelect }) => {
|
|
502
484
|
const {
|
|
503
485
|
rest_base: restBase,
|
|
504
|
-
rest_namespace: restNamespace =
|
|
486
|
+
rest_namespace: restNamespace = "wp/v2",
|
|
505
487
|
supports
|
|
506
488
|
} = await resolveSelect.getPostType(postType);
|
|
507
489
|
if (!supports?.autosave) {
|
|
508
490
|
return;
|
|
509
491
|
}
|
|
510
|
-
const autosaves = await (0,
|
|
492
|
+
const autosaves = await (0, import_api_fetch.default)({
|
|
511
493
|
path: `/${restNamespace}/${restBase}/${postId}/autosaves?context=edit`
|
|
512
494
|
});
|
|
513
495
|
if (autosaves && autosaves.length) {
|
|
514
496
|
dispatch.receiveAutosaves(postId, autosaves);
|
|
515
497
|
}
|
|
516
498
|
};
|
|
517
|
-
|
|
518
|
-
/**
|
|
519
|
-
* Request autosave data from the REST API.
|
|
520
|
-
*
|
|
521
|
-
* This resolver exists to ensure the underlying autosaves are fetched via
|
|
522
|
-
* `getAutosaves` when a call to the `getAutosave` selector is made.
|
|
523
|
-
*
|
|
524
|
-
* @param {string} postType The type of the parent post.
|
|
525
|
-
* @param {number} postId The id of the parent post.
|
|
526
|
-
*/
|
|
527
|
-
exports.getAutosaves = getAutosaves;
|
|
528
|
-
const getAutosave = (postType, postId) => async ({
|
|
529
|
-
resolveSelect
|
|
530
|
-
}) => {
|
|
499
|
+
const getAutosave = (postType, postId) => async ({ resolveSelect }) => {
|
|
531
500
|
await resolveSelect.getAutosaves(postType, postId);
|
|
532
501
|
};
|
|
533
|
-
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
});
|
|
541
|
-
const globalStylesURL = activeThemes?.[0]?._links?.['wp:user-global-styles']?.[0]?.href;
|
|
502
|
+
const __experimentalGetCurrentGlobalStylesId = () => async ({ dispatch, resolveSelect }) => {
|
|
503
|
+
const activeThemes = await resolveSelect.getEntityRecords(
|
|
504
|
+
"root",
|
|
505
|
+
"theme",
|
|
506
|
+
{ status: "active" }
|
|
507
|
+
);
|
|
508
|
+
const globalStylesURL = activeThemes?.[0]?._links?.["wp:user-global-styles"]?.[0]?.href;
|
|
542
509
|
if (!globalStylesURL) {
|
|
543
510
|
return;
|
|
544
511
|
}
|
|
545
|
-
|
|
546
|
-
// Regex matches the ID at the end of a URL or immediately before
|
|
547
|
-
// the query string.
|
|
548
512
|
const matches = globalStylesURL.match(/\/(\d+)(?:\?|$)/);
|
|
549
513
|
const id = matches ? Number(matches[1]) : null;
|
|
550
514
|
if (id) {
|
|
551
515
|
dispatch.__experimentalReceiveCurrentGlobalStylesId(id);
|
|
552
516
|
}
|
|
553
517
|
};
|
|
554
|
-
|
|
555
|
-
const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ({
|
|
556
|
-
resolveSelect,
|
|
557
|
-
dispatch
|
|
558
|
-
}) => {
|
|
518
|
+
const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ({ resolveSelect, dispatch }) => {
|
|
559
519
|
const currentTheme = await resolveSelect.getCurrentTheme();
|
|
560
|
-
|
|
561
|
-
const themeGlobalStyles = await (0, _apiFetch.default)({
|
|
520
|
+
const themeGlobalStyles = await (0, import_api_fetch.default)({
|
|
562
521
|
path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}?context=view`
|
|
563
522
|
});
|
|
564
|
-
dispatch.__experimentalReceiveThemeBaseGlobalStyles(
|
|
523
|
+
dispatch.__experimentalReceiveThemeBaseGlobalStyles(
|
|
524
|
+
currentTheme.stylesheet,
|
|
525
|
+
themeGlobalStyles
|
|
526
|
+
);
|
|
565
527
|
};
|
|
566
|
-
|
|
567
|
-
const __experimentalGetCurrentThemeGlobalStylesVariations = () => async ({
|
|
568
|
-
resolveSelect,
|
|
569
|
-
dispatch
|
|
570
|
-
}) => {
|
|
528
|
+
const __experimentalGetCurrentThemeGlobalStylesVariations = () => async ({ resolveSelect, dispatch }) => {
|
|
571
529
|
const currentTheme = await resolveSelect.getCurrentTheme();
|
|
572
|
-
|
|
573
|
-
const variations = await (0, _apiFetch.default)({
|
|
530
|
+
const variations = await (0, import_api_fetch.default)({
|
|
574
531
|
path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}/variations?context=view`
|
|
575
532
|
});
|
|
576
|
-
dispatch.__experimentalReceiveThemeGlobalStyleVariations(
|
|
533
|
+
dispatch.__experimentalReceiveThemeGlobalStyleVariations(
|
|
534
|
+
currentTheme.stylesheet,
|
|
535
|
+
variations
|
|
536
|
+
);
|
|
577
537
|
};
|
|
578
|
-
|
|
579
|
-
/**
|
|
580
|
-
* Fetches and returns the revisions of the current global styles theme.
|
|
581
|
-
*/
|
|
582
|
-
exports.__experimentalGetCurrentThemeGlobalStylesVariations = __experimentalGetCurrentThemeGlobalStylesVariations;
|
|
583
|
-
const getCurrentThemeGlobalStylesRevisions = () => async ({
|
|
584
|
-
resolveSelect,
|
|
585
|
-
dispatch
|
|
586
|
-
}) => {
|
|
538
|
+
const getCurrentThemeGlobalStylesRevisions = () => async ({ resolveSelect, dispatch }) => {
|
|
587
539
|
const globalStylesId = await resolveSelect.__experimentalGetCurrentGlobalStylesId();
|
|
588
|
-
const record = globalStylesId ? await resolveSelect.getEntityRecord(
|
|
589
|
-
|
|
540
|
+
const record = globalStylesId ? await resolveSelect.getEntityRecord(
|
|
541
|
+
"root",
|
|
542
|
+
"globalStyles",
|
|
543
|
+
globalStylesId
|
|
544
|
+
) : void 0;
|
|
545
|
+
const revisionsURL = record?._links?.["version-history"]?.[0]?.href;
|
|
590
546
|
if (revisionsURL) {
|
|
591
|
-
const resetRevisions = await (0,
|
|
547
|
+
const resetRevisions = await (0, import_api_fetch.default)({
|
|
592
548
|
url: revisionsURL
|
|
593
549
|
});
|
|
594
|
-
const revisions = resetRevisions?.map(
|
|
595
|
-
|
|
550
|
+
const revisions = resetRevisions?.map(
|
|
551
|
+
(revision) => Object.fromEntries(
|
|
552
|
+
Object.entries(revision).map(([key, value]) => [
|
|
553
|
+
(0, import_change_case.camelCase)(key),
|
|
554
|
+
value
|
|
555
|
+
])
|
|
556
|
+
)
|
|
557
|
+
);
|
|
558
|
+
dispatch.receiveThemeGlobalStyleRevisions(
|
|
559
|
+
globalStylesId,
|
|
560
|
+
revisions
|
|
561
|
+
);
|
|
596
562
|
}
|
|
597
563
|
};
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
return action.type === 'SAVE_ENTITY_RECORD_FINISH' && action.kind === 'root' && !action.error && action.name === 'globalStyles';
|
|
564
|
+
getCurrentThemeGlobalStylesRevisions.shouldInvalidate = (action) => {
|
|
565
|
+
return action.type === "SAVE_ENTITY_RECORD_FINISH" && action.kind === "root" && !action.error && action.name === "globalStyles";
|
|
601
566
|
};
|
|
602
|
-
const getBlockPatterns = () => async ({
|
|
603
|
-
|
|
604
|
-
})
|
|
605
|
-
const patterns = await (0, _fetch.fetchBlockPatterns)();
|
|
606
|
-
dispatch({
|
|
607
|
-
type: 'RECEIVE_BLOCK_PATTERNS',
|
|
608
|
-
patterns
|
|
609
|
-
});
|
|
567
|
+
const getBlockPatterns = () => async ({ dispatch }) => {
|
|
568
|
+
const patterns = await (0, import_fetch.fetchBlockPatterns)();
|
|
569
|
+
dispatch({ type: "RECEIVE_BLOCK_PATTERNS", patterns });
|
|
610
570
|
};
|
|
611
|
-
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
}) => {
|
|
615
|
-
const categories = await (0, _apiFetch.default)({
|
|
616
|
-
path: '/wp/v2/block-patterns/categories'
|
|
617
|
-
});
|
|
618
|
-
dispatch({
|
|
619
|
-
type: 'RECEIVE_BLOCK_PATTERN_CATEGORIES',
|
|
620
|
-
categories
|
|
571
|
+
const getBlockPatternCategories = () => async ({ dispatch }) => {
|
|
572
|
+
const categories = await (0, import_api_fetch.default)({
|
|
573
|
+
path: "/wp/v2/block-patterns/categories"
|
|
621
574
|
});
|
|
575
|
+
dispatch({ type: "RECEIVE_BLOCK_PATTERN_CATEGORIES", categories });
|
|
622
576
|
};
|
|
623
|
-
|
|
624
|
-
const
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
const mappedPatternCategories = patternCategories?.map(userCategory => ({
|
|
577
|
+
const getUserPatternCategories = () => async ({ dispatch, resolveSelect }) => {
|
|
578
|
+
const patternCategories = await resolveSelect.getEntityRecords(
|
|
579
|
+
"taxonomy",
|
|
580
|
+
"wp_pattern_category",
|
|
581
|
+
{
|
|
582
|
+
per_page: -1,
|
|
583
|
+
_fields: "id,name,description,slug",
|
|
584
|
+
context: "view"
|
|
585
|
+
}
|
|
586
|
+
);
|
|
587
|
+
const mappedPatternCategories = patternCategories?.map((userCategory) => ({
|
|
634
588
|
...userCategory,
|
|
635
|
-
label: (0,
|
|
589
|
+
label: (0, import_html_entities.decodeEntities)(userCategory.name),
|
|
636
590
|
name: userCategory.slug
|
|
637
591
|
})) || [];
|
|
638
592
|
dispatch({
|
|
639
|
-
type:
|
|
593
|
+
type: "RECEIVE_USER_PATTERN_CATEGORIES",
|
|
640
594
|
patternCategories: mappedPatternCategories
|
|
641
595
|
});
|
|
642
596
|
};
|
|
643
|
-
|
|
644
|
-
const
|
|
645
|
-
|
|
646
|
-
select,
|
|
647
|
-
registry
|
|
648
|
-
}) => {
|
|
649
|
-
const fallback = await (0, _apiFetch.default)({
|
|
650
|
-
path: (0, _url.addQueryArgs)('/wp-block-editor/v1/navigation-fallback', {
|
|
597
|
+
const getNavigationFallbackId = () => async ({ dispatch, select, registry }) => {
|
|
598
|
+
const fallback = await (0, import_api_fetch.default)({
|
|
599
|
+
path: (0, import_url.addQueryArgs)("/wp-block-editor/v1/navigation-fallback", {
|
|
651
600
|
_embed: true
|
|
652
601
|
})
|
|
653
602
|
});
|
|
@@ -657,212 +606,186 @@ const getNavigationFallbackId = () => async ({
|
|
|
657
606
|
if (!record) {
|
|
658
607
|
return;
|
|
659
608
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
609
|
+
const existingFallbackEntityRecord = select.getEntityRecord(
|
|
610
|
+
"postType",
|
|
611
|
+
"wp_navigation",
|
|
612
|
+
fallback.id
|
|
613
|
+
);
|
|
665
614
|
const invalidateNavigationQueries = !existingFallbackEntityRecord;
|
|
666
|
-
dispatch.receiveEntityRecords(
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
615
|
+
dispatch.receiveEntityRecords(
|
|
616
|
+
"postType",
|
|
617
|
+
"wp_navigation",
|
|
618
|
+
record,
|
|
619
|
+
void 0,
|
|
620
|
+
invalidateNavigationQueries
|
|
621
|
+
);
|
|
622
|
+
dispatch.finishResolution("getEntityRecord", [
|
|
623
|
+
"postType",
|
|
624
|
+
"wp_navigation",
|
|
625
|
+
fallback.id
|
|
626
|
+
]);
|
|
670
627
|
});
|
|
671
628
|
};
|
|
672
|
-
|
|
673
|
-
const
|
|
674
|
-
|
|
675
|
-
registry,
|
|
676
|
-
resolveSelect
|
|
677
|
-
}) => {
|
|
678
|
-
const template = await (0, _apiFetch.default)({
|
|
679
|
-
path: (0, _url.addQueryArgs)('/wp/v2/templates/lookup', query)
|
|
629
|
+
const getDefaultTemplateId = (query) => async ({ dispatch, registry, resolveSelect }) => {
|
|
630
|
+
const template = await (0, import_api_fetch.default)({
|
|
631
|
+
path: (0, import_url.addQueryArgs)("/wp/v2/templates/lookup", query)
|
|
680
632
|
});
|
|
681
|
-
|
|
682
|
-
// the template as an entity will not work.
|
|
683
|
-
await resolveSelect.getEntitiesConfig('postType');
|
|
633
|
+
await resolveSelect.getEntitiesConfig("postType");
|
|
684
634
|
const id = template?.wp_id || template?.id;
|
|
685
|
-
// Endpoint may return an empty object if no template is found.
|
|
686
635
|
if (id) {
|
|
687
636
|
template.id = id;
|
|
688
|
-
template.type = typeof id ===
|
|
637
|
+
template.type = typeof id === "string" ? "wp_registered_template" : "wp_template";
|
|
689
638
|
registry.batch(() => {
|
|
690
639
|
dispatch.receiveDefaultTemplateId(query, id);
|
|
691
|
-
dispatch.receiveEntityRecords(
|
|
692
|
-
|
|
693
|
-
|
|
640
|
+
dispatch.receiveEntityRecords("postType", template.type, [
|
|
641
|
+
template
|
|
642
|
+
]);
|
|
643
|
+
dispatch.finishResolution("getEntityRecord", [
|
|
644
|
+
"postType",
|
|
645
|
+
template.type,
|
|
646
|
+
id
|
|
647
|
+
]);
|
|
694
648
|
});
|
|
695
649
|
}
|
|
696
650
|
};
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
return action.type === 'EDIT_ENTITY_RECORD' && action.kind === 'root' && action.name === 'site';
|
|
651
|
+
getDefaultTemplateId.shouldInvalidate = (action) => {
|
|
652
|
+
return action.type === "RECEIVE_ITEMS" && action.kind === "root" && action.name === "site";
|
|
700
653
|
};
|
|
701
|
-
|
|
702
|
-
/**
|
|
703
|
-
* Requests an entity's revisions from the REST API.
|
|
704
|
-
*
|
|
705
|
-
* @param {string} kind Entity kind.
|
|
706
|
-
* @param {string} name Entity name.
|
|
707
|
-
* @param {number|string} recordKey The key of the entity record whose revisions you want to fetch.
|
|
708
|
-
* @param {Object|undefined} query Optional object of query parameters to
|
|
709
|
-
* include with request. If requesting specific
|
|
710
|
-
* fields, fields must always include the ID.
|
|
711
|
-
*/
|
|
712
|
-
const getRevisions = (kind, name, recordKey, query = {}) => async ({
|
|
713
|
-
dispatch,
|
|
714
|
-
registry,
|
|
715
|
-
resolveSelect
|
|
716
|
-
}) => {
|
|
654
|
+
const getRevisions = (kind, name, recordKey, query = {}) => async ({ dispatch, registry, resolveSelect }) => {
|
|
717
655
|
const configs = await resolveSelect.getEntitiesConfig(kind);
|
|
718
|
-
const entityConfig = configs.find(
|
|
656
|
+
const entityConfig = configs.find(
|
|
657
|
+
(config) => config.name === name && config.kind === kind
|
|
658
|
+
);
|
|
719
659
|
if (!entityConfig) {
|
|
720
660
|
return;
|
|
721
661
|
}
|
|
722
662
|
if (query._fields) {
|
|
723
|
-
// If requesting specific fields, items and query association to said
|
|
724
|
-
// records are stored by ID reference. Thus, fields must always include
|
|
725
|
-
// the ID.
|
|
726
663
|
query = {
|
|
727
664
|
...query,
|
|
728
|
-
_fields: [
|
|
665
|
+
_fields: [
|
|
666
|
+
.../* @__PURE__ */ new Set([
|
|
667
|
+
...(0, import_utils.getNormalizedCommaSeparable)(query._fields) || [],
|
|
668
|
+
entityConfig.revisionKey || import_entities.DEFAULT_ENTITY_KEY
|
|
669
|
+
])
|
|
670
|
+
].join()
|
|
729
671
|
};
|
|
730
672
|
}
|
|
731
|
-
const path = (0,
|
|
673
|
+
const path = (0, import_url.addQueryArgs)(
|
|
674
|
+
entityConfig.getRevisionsUrl(recordKey),
|
|
675
|
+
query
|
|
676
|
+
);
|
|
732
677
|
let records, response;
|
|
733
678
|
const meta = {};
|
|
734
679
|
const isPaginated = entityConfig.supportsPagination && query.per_page !== -1;
|
|
735
680
|
try {
|
|
736
|
-
response = await (0,
|
|
737
|
-
path,
|
|
738
|
-
parse: !isPaginated
|
|
739
|
-
});
|
|
681
|
+
response = await (0, import_api_fetch.default)({ path, parse: !isPaginated });
|
|
740
682
|
} catch (error) {
|
|
741
|
-
// Do nothing if our request comes back with an API error.
|
|
742
683
|
return;
|
|
743
684
|
}
|
|
744
685
|
if (response) {
|
|
745
686
|
if (isPaginated) {
|
|
746
687
|
records = Object.values(await response.json());
|
|
747
|
-
meta.totalItems = parseInt(
|
|
688
|
+
meta.totalItems = parseInt(
|
|
689
|
+
response.headers.get("X-WP-Total")
|
|
690
|
+
);
|
|
748
691
|
} else {
|
|
749
692
|
records = Object.values(response);
|
|
750
693
|
}
|
|
751
|
-
|
|
752
|
-
// If we request fields but the result doesn't contain the fields,
|
|
753
|
-
// explicitly set these fields as "undefined"
|
|
754
|
-
// that way we consider the query "fulfilled".
|
|
755
694
|
if (query._fields) {
|
|
756
|
-
records = records.map(record => {
|
|
757
|
-
query._fields.split(
|
|
695
|
+
records = records.map((record) => {
|
|
696
|
+
query._fields.split(",").forEach((field) => {
|
|
758
697
|
if (!record.hasOwnProperty(field)) {
|
|
759
|
-
record[field] =
|
|
698
|
+
record[field] = void 0;
|
|
760
699
|
}
|
|
761
700
|
});
|
|
762
701
|
return record;
|
|
763
702
|
});
|
|
764
703
|
}
|
|
765
704
|
registry.batch(() => {
|
|
766
|
-
dispatch.receiveRevisions(
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
705
|
+
dispatch.receiveRevisions(
|
|
706
|
+
kind,
|
|
707
|
+
name,
|
|
708
|
+
recordKey,
|
|
709
|
+
records,
|
|
710
|
+
query,
|
|
711
|
+
false,
|
|
712
|
+
meta
|
|
713
|
+
);
|
|
770
714
|
if (!query?._fields && !query.context) {
|
|
771
|
-
const key = entityConfig.key ||
|
|
772
|
-
const resolutionsArgs = records.filter(record => record[key]).map(record => [
|
|
773
|
-
|
|
715
|
+
const key = entityConfig.key || import_entities.DEFAULT_ENTITY_KEY;
|
|
716
|
+
const resolutionsArgs = records.filter((record) => record[key]).map((record) => [
|
|
717
|
+
kind,
|
|
718
|
+
name,
|
|
719
|
+
recordKey,
|
|
720
|
+
record[key]
|
|
721
|
+
]);
|
|
722
|
+
dispatch.finishResolutions(
|
|
723
|
+
"getRevision",
|
|
724
|
+
resolutionsArgs
|
|
725
|
+
);
|
|
774
726
|
}
|
|
775
727
|
});
|
|
776
728
|
}
|
|
777
729
|
};
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
exports.getRevisions = getRevisions;
|
|
781
|
-
getRevisions.shouldInvalidate = (action, kind, name, recordKey) => action.type === 'SAVE_ENTITY_RECORD_FINISH' && name === action.name && kind === action.kind && !action.error && recordKey === action.recordId;
|
|
782
|
-
|
|
783
|
-
/**
|
|
784
|
-
* Requests a specific Entity revision from the REST API.
|
|
785
|
-
*
|
|
786
|
-
* @param {string} kind Entity kind.
|
|
787
|
-
* @param {string} name Entity name.
|
|
788
|
-
* @param {number|string} recordKey The key of the entity record whose revisions you want to fetch.
|
|
789
|
-
* @param {number|string} revisionKey The revision's key.
|
|
790
|
-
* @param {Object|undefined} query Optional object of query parameters to
|
|
791
|
-
* include with request. If requesting specific
|
|
792
|
-
* fields, fields must always include the ID.
|
|
793
|
-
*/
|
|
794
|
-
const getRevision = (kind, name, recordKey, revisionKey, query) => async ({
|
|
795
|
-
dispatch,
|
|
796
|
-
resolveSelect
|
|
797
|
-
}) => {
|
|
730
|
+
getRevisions.shouldInvalidate = (action, kind, name, recordKey) => action.type === "SAVE_ENTITY_RECORD_FINISH" && name === action.name && kind === action.kind && !action.error && recordKey === action.recordId;
|
|
731
|
+
const getRevision = (kind, name, recordKey, revisionKey, query) => async ({ dispatch, resolveSelect }) => {
|
|
798
732
|
const configs = await resolveSelect.getEntitiesConfig(kind);
|
|
799
|
-
const entityConfig = configs.find(
|
|
733
|
+
const entityConfig = configs.find(
|
|
734
|
+
(config) => config.name === name && config.kind === kind
|
|
735
|
+
);
|
|
800
736
|
if (!entityConfig) {
|
|
801
737
|
return;
|
|
802
738
|
}
|
|
803
|
-
if (query !==
|
|
804
|
-
// If requesting specific fields, items and query association to said
|
|
805
|
-
// records are stored by ID reference. Thus, fields must always include
|
|
806
|
-
// the ID.
|
|
739
|
+
if (query !== void 0 && query._fields) {
|
|
807
740
|
query = {
|
|
808
741
|
...query,
|
|
809
|
-
_fields: [
|
|
742
|
+
_fields: [
|
|
743
|
+
.../* @__PURE__ */ new Set([
|
|
744
|
+
...(0, import_utils.getNormalizedCommaSeparable)(query._fields) || [],
|
|
745
|
+
entityConfig.revisionKey || import_entities.DEFAULT_ENTITY_KEY
|
|
746
|
+
])
|
|
747
|
+
].join()
|
|
810
748
|
};
|
|
811
749
|
}
|
|
812
|
-
const path = (0,
|
|
750
|
+
const path = (0, import_url.addQueryArgs)(
|
|
751
|
+
entityConfig.getRevisionsUrl(recordKey, revisionKey),
|
|
752
|
+
query
|
|
753
|
+
);
|
|
813
754
|
let record;
|
|
814
755
|
try {
|
|
815
|
-
record = await (0,
|
|
816
|
-
path
|
|
817
|
-
});
|
|
756
|
+
record = await (0, import_api_fetch.default)({ path });
|
|
818
757
|
} catch (error) {
|
|
819
|
-
// Do nothing if our request comes back with an API error.
|
|
820
758
|
return;
|
|
821
759
|
}
|
|
822
760
|
if (record) {
|
|
823
761
|
dispatch.receiveRevisions(kind, name, recordKey, record, query);
|
|
824
762
|
}
|
|
825
763
|
};
|
|
826
|
-
|
|
827
|
-
/**
|
|
828
|
-
* Requests a specific post type options from the REST API.
|
|
829
|
-
*
|
|
830
|
-
* @param {string} postType Post type slug.
|
|
831
|
-
*/
|
|
832
|
-
exports.getRevision = getRevision;
|
|
833
|
-
const getRegisteredPostMeta = postType => async ({
|
|
834
|
-
dispatch,
|
|
835
|
-
resolveSelect
|
|
836
|
-
}) => {
|
|
764
|
+
const getRegisteredPostMeta = (postType) => async ({ dispatch, resolveSelect }) => {
|
|
837
765
|
let options;
|
|
838
766
|
try {
|
|
839
767
|
const {
|
|
840
|
-
rest_namespace: restNamespace =
|
|
768
|
+
rest_namespace: restNamespace = "wp/v2",
|
|
841
769
|
rest_base: restBase
|
|
842
|
-
} =
|
|
843
|
-
options = await (0,
|
|
770
|
+
} = await resolveSelect.getPostType(postType) || {};
|
|
771
|
+
options = await (0, import_api_fetch.default)({
|
|
844
772
|
path: `${restNamespace}/${restBase}/?context=edit`,
|
|
845
|
-
method:
|
|
773
|
+
method: "OPTIONS"
|
|
846
774
|
});
|
|
847
775
|
} catch (error) {
|
|
848
|
-
// Do nothing if the request comes back with an API error.
|
|
849
776
|
return;
|
|
850
777
|
}
|
|
851
778
|
if (options) {
|
|
852
|
-
dispatch.receiveRegisteredPostMeta(
|
|
779
|
+
dispatch.receiveRegisteredPostMeta(
|
|
780
|
+
postType,
|
|
781
|
+
options?.schema?.properties?.meta?.properties
|
|
782
|
+
);
|
|
853
783
|
}
|
|
854
784
|
};
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
* @param {string} kind Entity kind.
|
|
860
|
-
*/
|
|
861
|
-
exports.getRegisteredPostMeta = getRegisteredPostMeta;
|
|
862
|
-
const getEntitiesConfig = kind => async ({
|
|
863
|
-
dispatch
|
|
864
|
-
}) => {
|
|
865
|
-
const loader = _entities.additionalEntityConfigLoaders.find(l => l.kind === kind);
|
|
785
|
+
const getEntitiesConfig = (kind) => async ({ dispatch }) => {
|
|
786
|
+
const loader = import_entities.additionalEntityConfigLoaders.find(
|
|
787
|
+
(l) => l.kind === kind
|
|
788
|
+
);
|
|
866
789
|
if (!loader) {
|
|
867
790
|
return;
|
|
868
791
|
}
|
|
@@ -873,8 +796,38 @@ const getEntitiesConfig = kind => async ({
|
|
|
873
796
|
}
|
|
874
797
|
dispatch.addEntities(configs);
|
|
875
798
|
} catch {
|
|
876
|
-
// Do nothing if the request comes back with an API error.
|
|
877
799
|
}
|
|
878
800
|
};
|
|
879
|
-
|
|
880
|
-
|
|
801
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
802
|
+
0 && (module.exports = {
|
|
803
|
+
__experimentalGetCurrentGlobalStylesId,
|
|
804
|
+
__experimentalGetCurrentThemeBaseGlobalStyles,
|
|
805
|
+
__experimentalGetCurrentThemeGlobalStylesVariations,
|
|
806
|
+
canUser,
|
|
807
|
+
canUserEditEntityRecord,
|
|
808
|
+
getAuthors,
|
|
809
|
+
getAutosave,
|
|
810
|
+
getAutosaves,
|
|
811
|
+
getBlockPatternCategories,
|
|
812
|
+
getBlockPatterns,
|
|
813
|
+
getCurrentTheme,
|
|
814
|
+
getCurrentThemeGlobalStylesRevisions,
|
|
815
|
+
getCurrentUser,
|
|
816
|
+
getDefaultTemplateId,
|
|
817
|
+
getEditedEntityRecord,
|
|
818
|
+
getEmbedPreview,
|
|
819
|
+
getEntitiesConfig,
|
|
820
|
+
getEntityRecord,
|
|
821
|
+
getEntityRecords,
|
|
822
|
+
getEntityRecordsTotalItems,
|
|
823
|
+
getEntityRecordsTotalPages,
|
|
824
|
+
getNavigationFallbackId,
|
|
825
|
+
getRawEntityRecord,
|
|
826
|
+
getRegisteredPostMeta,
|
|
827
|
+
getRevision,
|
|
828
|
+
getRevisions,
|
|
829
|
+
getTemplateAutoDraftId,
|
|
830
|
+
getThemeSupports,
|
|
831
|
+
getUserPatternCategories
|
|
832
|
+
});
|
|
833
|
+
//# sourceMappingURL=resolvers.js.map
|