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