@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,281 +1,130 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// into a more detailed representation over time.
|
|
20
|
-
// See https://github.com/WordPress/gutenberg/pull/40025#discussion_r865410589 for more context.
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* HTTP Query parameters sent with the API request to fetch the entity records.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Arguments for EntityRecord selectors.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Shared reference to an empty object for cases where it is important to avoid
|
|
32
|
-
* returning a new object reference on every invocation, as in a connected or
|
|
33
|
-
* other pure component which performs `shouldComponentUpdate` check on props.
|
|
34
|
-
* This should be used as a last resort, since the normalized data should be
|
|
35
|
-
* maintained by the reducer result in state.
|
|
36
|
-
*/
|
|
1
|
+
import { createSelector, createRegistrySelector } from "@wordpress/data";
|
|
2
|
+
import { addQueryArgs } from "@wordpress/url";
|
|
3
|
+
import deprecated from "@wordpress/deprecated";
|
|
4
|
+
import { STORE_NAME } from "./name";
|
|
5
|
+
import {
|
|
6
|
+
getQueriedItems,
|
|
7
|
+
getQueriedTotalItems,
|
|
8
|
+
getQueriedTotalPages
|
|
9
|
+
} from "./queried-data";
|
|
10
|
+
import { DEFAULT_ENTITY_KEY } from "./entities";
|
|
11
|
+
import {
|
|
12
|
+
getNormalizedCommaSeparable,
|
|
13
|
+
isRawAttribute,
|
|
14
|
+
setNestedValue,
|
|
15
|
+
isNumericID,
|
|
16
|
+
getUserPermissionCacheKey
|
|
17
|
+
} from "./utils";
|
|
18
|
+
import logEntityDeprecation from "./utils/log-entity-deprecation";
|
|
37
19
|
const EMPTY_OBJECT = {};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* @return Whether a request is in progress for an embed preview.
|
|
47
|
-
*/
|
|
48
|
-
export const isRequestingEmbedPreview = createRegistrySelector(select => (state, url) => {
|
|
49
|
-
return select(STORE_NAME).isResolving('getEmbedPreview', [url]);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Returns all available authors.
|
|
54
|
-
*
|
|
55
|
-
* @deprecated since 11.3. Callers should use `select( 'core' ).getUsers({ who: 'authors' })` instead.
|
|
56
|
-
*
|
|
57
|
-
* @param state Data state.
|
|
58
|
-
* @param query Optional object of query parameters to
|
|
59
|
-
* include with request. For valid query parameters see the [Users page](https://developer.wordpress.org/rest-api/reference/users/) in the REST API Handbook and see the arguments for [List Users](https://developer.wordpress.org/rest-api/reference/users/#list-users) and [Retrieve a User](https://developer.wordpress.org/rest-api/reference/users/#retrieve-a-user).
|
|
60
|
-
* @return Authors list.
|
|
61
|
-
*/
|
|
62
|
-
export function getAuthors(state, query) {
|
|
20
|
+
const isRequestingEmbedPreview = createRegistrySelector(
|
|
21
|
+
(select) => (state, url) => {
|
|
22
|
+
return select(STORE_NAME).isResolving("getEmbedPreview", [
|
|
23
|
+
url
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
function getAuthors(state, query) {
|
|
63
28
|
deprecated("select( 'core' ).getAuthors()", {
|
|
64
|
-
since:
|
|
29
|
+
since: "5.9",
|
|
65
30
|
alternative: "select( 'core' ).getUsers({ who: 'authors' })"
|
|
66
31
|
});
|
|
67
|
-
const path = addQueryArgs(
|
|
32
|
+
const path = addQueryArgs(
|
|
33
|
+
"/wp/v2/users/?who=authors&per_page=100",
|
|
34
|
+
query
|
|
35
|
+
);
|
|
68
36
|
return getUserQueryResults(state, path);
|
|
69
37
|
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Returns the current user.
|
|
73
|
-
*
|
|
74
|
-
* @param state Data state.
|
|
75
|
-
*
|
|
76
|
-
* @return Current user object.
|
|
77
|
-
*/
|
|
78
|
-
export function getCurrentUser(state) {
|
|
38
|
+
function getCurrentUser(state) {
|
|
79
39
|
return state.currentUser;
|
|
80
40
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const queryResults = (_state$users$queries$ = state.users.queries[queryID]) !== null && _state$users$queries$ !== void 0 ? _state$users$queries$ : [];
|
|
93
|
-
return queryResults.map(id => state.users.byId[id]);
|
|
94
|
-
}, (state, queryID) => [state.users.queries[queryID], state.users.byId]);
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Returns the loaded entities for the given kind.
|
|
98
|
-
*
|
|
99
|
-
* @deprecated since WordPress 6.0. Use getEntitiesConfig instead
|
|
100
|
-
* @param state Data state.
|
|
101
|
-
* @param kind Entity kind.
|
|
102
|
-
*
|
|
103
|
-
* @return Array of entities with config matching kind.
|
|
104
|
-
*/
|
|
105
|
-
export function getEntitiesByKind(state, kind) {
|
|
41
|
+
const getUserQueryResults = createSelector(
|
|
42
|
+
(state, queryID) => {
|
|
43
|
+
const queryResults = state.users.queries[queryID] ?? [];
|
|
44
|
+
return queryResults.map((id) => state.users.byId[id]);
|
|
45
|
+
},
|
|
46
|
+
(state, queryID) => [
|
|
47
|
+
state.users.queries[queryID],
|
|
48
|
+
state.users.byId
|
|
49
|
+
]
|
|
50
|
+
);
|
|
51
|
+
function getEntitiesByKind(state, kind) {
|
|
106
52
|
deprecated("wp.data.select( 'core' ).getEntitiesByKind()", {
|
|
107
|
-
since:
|
|
53
|
+
since: "6.0",
|
|
108
54
|
alternative: "wp.data.select( 'core' ).getEntitiesConfig()"
|
|
109
55
|
});
|
|
110
56
|
return getEntitiesConfig(state, kind);
|
|
111
57
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
* @return Array of entities with config matching kind.
|
|
120
|
-
*/
|
|
121
|
-
export const getEntitiesConfig = createSelector((state, kind) => state.entities.config.filter(entity => entity.kind === kind), /* eslint-disable @typescript-eslint/no-unused-vars */
|
|
122
|
-
(state, kind) => state.entities.config
|
|
123
|
-
/* eslint-enable @typescript-eslint/no-unused-vars */);
|
|
124
|
-
/**
|
|
125
|
-
* Returns the entity config given its kind and name.
|
|
126
|
-
*
|
|
127
|
-
* @deprecated since WordPress 6.0. Use getEntityConfig instead
|
|
128
|
-
* @param state Data state.
|
|
129
|
-
* @param kind Entity kind.
|
|
130
|
-
* @param name Entity name.
|
|
131
|
-
*
|
|
132
|
-
* @return Entity config
|
|
133
|
-
*/
|
|
134
|
-
export function getEntity(state, kind, name) {
|
|
58
|
+
const getEntitiesConfig = createSelector(
|
|
59
|
+
(state, kind) => state.entities.config.filter((entity) => entity.kind === kind),
|
|
60
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
61
|
+
(state, kind) => state.entities.config
|
|
62
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
63
|
+
);
|
|
64
|
+
function getEntity(state, kind, name) {
|
|
135
65
|
deprecated("wp.data.select( 'core' ).getEntity()", {
|
|
136
|
-
since:
|
|
66
|
+
since: "6.0",
|
|
137
67
|
alternative: "wp.data.select( 'core' ).getEntityConfig()"
|
|
138
68
|
});
|
|
139
69
|
return getEntityConfig(state, kind, name);
|
|
140
70
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return state.entities.config?.find(config => config.kind === kind && config.name === name);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* GetEntityRecord is declared as a *callable interface* with
|
|
158
|
-
* two signatures to work around the fact that TypeScript doesn't
|
|
159
|
-
* allow currying generic functions:
|
|
160
|
-
*
|
|
161
|
-
* ```ts
|
|
162
|
-
* type CurriedState = F extends ( state: any, ...args: infer P ) => infer R
|
|
163
|
-
* ? ( ...args: P ) => R
|
|
164
|
-
* : F;
|
|
165
|
-
* type Selector = <K extends string | number>(
|
|
166
|
-
* state: any,
|
|
167
|
-
* kind: K,
|
|
168
|
-
* key: K extends string ? 'string value' : false
|
|
169
|
-
* ) => K;
|
|
170
|
-
* type BadlyInferredSignature = CurriedState< Selector >
|
|
171
|
-
* // BadlyInferredSignature evaluates to:
|
|
172
|
-
* // (kind: string number, key: false | "string value") => string number
|
|
173
|
-
* ```
|
|
174
|
-
*
|
|
175
|
-
* The signature without the state parameter shipped as CurriedSignature
|
|
176
|
-
* is used in the return value of `select( coreStore )`.
|
|
177
|
-
*
|
|
178
|
-
* See https://github.com/WordPress/gutenberg/pull/41578 for more details.
|
|
179
|
-
*/
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Returns the Entity's record object by key. Returns `null` if the value is not
|
|
183
|
-
* yet received, undefined if the value entity is known to not exist, or the
|
|
184
|
-
* entity object if it exists and is received.
|
|
185
|
-
*
|
|
186
|
-
* @param state State tree
|
|
187
|
-
* @param kind Entity kind.
|
|
188
|
-
* @param name Entity name.
|
|
189
|
-
* @param key Optional record's key. If requesting a global record (e.g. site settings), the key can be omitted. If requesting a specific item, the key must always be included.
|
|
190
|
-
* @param query Optional query. If requesting specific
|
|
191
|
-
* fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available "Retrieve a [Entity kind]".
|
|
192
|
-
*
|
|
193
|
-
* @return Record.
|
|
194
|
-
*/
|
|
195
|
-
export const getEntityRecord = createSelector((state, kind, name, key, query) => {
|
|
196
|
-
var _query$context, _getNormalizedCommaSe;
|
|
197
|
-
logEntityDeprecation(kind, name, 'getEntityRecord');
|
|
198
|
-
|
|
199
|
-
// For back-compat, we allow querying for static templates through
|
|
200
|
-
// wp_template.
|
|
201
|
-
if (kind === 'postType' && name === 'wp_template' && typeof key === 'string' &&
|
|
202
|
-
// __experimentalGetDirtyEntityRecords always calls getEntityRecord
|
|
203
|
-
// with a string key, so we need that it's not a numeric ID.
|
|
204
|
-
!/^\d+$/.test(key)) {
|
|
205
|
-
name = 'wp_registered_template';
|
|
206
|
-
}
|
|
207
|
-
const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
|
|
208
|
-
if (!queriedState) {
|
|
209
|
-
return undefined;
|
|
210
|
-
}
|
|
211
|
-
const context = (_query$context = query?.context) !== null && _query$context !== void 0 ? _query$context : 'default';
|
|
212
|
-
if (!query || !query._fields) {
|
|
213
|
-
// If expecting a complete item, validate that completeness.
|
|
214
|
-
if (!queriedState.itemIsComplete[context]?.[key]) {
|
|
215
|
-
return undefined;
|
|
71
|
+
function getEntityConfig(state, kind, name) {
|
|
72
|
+
logEntityDeprecation(kind, name, "getEntityConfig");
|
|
73
|
+
return state.entities.config?.find(
|
|
74
|
+
(config) => config.kind === kind && config.name === name
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
const getEntityRecord = createSelector(
|
|
78
|
+
((state, kind, name, key, query) => {
|
|
79
|
+
logEntityDeprecation(kind, name, "getEntityRecord");
|
|
80
|
+
const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
|
|
81
|
+
if (!queriedState) {
|
|
82
|
+
return void 0;
|
|
216
83
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
84
|
+
const context = query?.context ?? "default";
|
|
85
|
+
if (!query || !query._fields) {
|
|
86
|
+
if (!queriedState.itemIsComplete[context]?.[key]) {
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
return queriedState.items[context][key];
|
|
90
|
+
}
|
|
91
|
+
const item = queriedState.items[context]?.[key];
|
|
92
|
+
if (!item) {
|
|
93
|
+
return item;
|
|
94
|
+
}
|
|
95
|
+
const filteredItem = {};
|
|
96
|
+
const fields = getNormalizedCommaSeparable(query._fields) ?? [];
|
|
97
|
+
for (let f = 0; f < fields.length; f++) {
|
|
98
|
+
const field = fields[f].split(".");
|
|
99
|
+
let value = item;
|
|
100
|
+
field.forEach((fieldName) => {
|
|
101
|
+
value = value?.[fieldName];
|
|
102
|
+
});
|
|
103
|
+
setNestedValue(filteredItem, field, value);
|
|
104
|
+
}
|
|
105
|
+
return filteredItem;
|
|
106
|
+
}),
|
|
107
|
+
(state, kind, name, recordId, query) => {
|
|
108
|
+
const context = query?.context ?? "default";
|
|
109
|
+
const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
|
|
110
|
+
return [
|
|
111
|
+
queriedState?.items[context]?.[recordId],
|
|
112
|
+
queriedState?.itemIsComplete[context]?.[recordId]
|
|
113
|
+
];
|
|
232
114
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
var _query$context2;
|
|
236
|
-
const context = (_query$context2 = query?.context) !== null && _query$context2 !== void 0 ? _query$context2 : 'default';
|
|
237
|
-
const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
|
|
238
|
-
return [queriedState?.items[context]?.[recordId], queriedState?.itemIsComplete[context]?.[recordId]];
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Normalizes `recordKey`s that look like numeric IDs to numbers.
|
|
243
|
-
*
|
|
244
|
-
* @param args EntityRecordArgs the selector arguments.
|
|
245
|
-
* @return EntityRecordArgs the normalized arguments.
|
|
246
|
-
*/
|
|
247
|
-
getEntityRecord.__unstableNormalizeArgs = args => {
|
|
115
|
+
);
|
|
116
|
+
getEntityRecord.__unstableNormalizeArgs = (args) => {
|
|
248
117
|
const newArgs = [...args];
|
|
249
118
|
const recordKey = newArgs?.[2];
|
|
250
|
-
|
|
251
|
-
// If recordKey looks to be a numeric ID then coerce to number.
|
|
252
119
|
newArgs[2] = isNumericID(recordKey) ? Number(recordKey) : recordKey;
|
|
253
120
|
return newArgs;
|
|
254
121
|
};
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Returns true if a record has been received for the given set of parameters, or false otherwise.
|
|
258
|
-
*
|
|
259
|
-
* Note: This action does not trigger a request for the entity record from the API
|
|
260
|
-
* if it's not available in the local state.
|
|
261
|
-
*
|
|
262
|
-
* @param state State tree
|
|
263
|
-
* @param kind Entity kind.
|
|
264
|
-
* @param name Entity name.
|
|
265
|
-
* @param key Record's key.
|
|
266
|
-
* @param query Optional query.
|
|
267
|
-
*
|
|
268
|
-
* @return Whether an entity record has been received.
|
|
269
|
-
*/
|
|
270
|
-
export function hasEntityRecord(state, kind, name, key, query) {
|
|
271
|
-
var _query$context3, _getNormalizedCommaSe2;
|
|
122
|
+
function hasEntityRecord(state, kind, name, key, query) {
|
|
272
123
|
const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
|
|
273
124
|
if (!queriedState) {
|
|
274
125
|
return false;
|
|
275
126
|
}
|
|
276
|
-
const context =
|
|
277
|
-
|
|
278
|
-
// If expecting a complete item, validate that completeness.
|
|
127
|
+
const context = query?.context ?? "default";
|
|
279
128
|
if (!query || !query._fields) {
|
|
280
129
|
return !!queriedState.itemIsComplete[context]?.[key];
|
|
281
130
|
}
|
|
@@ -283,12 +132,9 @@ export function hasEntityRecord(state, kind, name, key, query) {
|
|
|
283
132
|
if (!item) {
|
|
284
133
|
return false;
|
|
285
134
|
}
|
|
286
|
-
|
|
287
|
-
// When `query._fields` is provided, check that each requested field exists,
|
|
288
|
-
// including any nested paths, on the item; return false if any part is missing.
|
|
289
|
-
const fields = (_getNormalizedCommaSe2 = getNormalizedCommaSeparable(query._fields)) !== null && _getNormalizedCommaSe2 !== void 0 ? _getNormalizedCommaSe2 : [];
|
|
135
|
+
const fields = getNormalizedCommaSeparable(query._fields) ?? [];
|
|
290
136
|
for (let i = 0; i < fields.length; i++) {
|
|
291
|
-
const path = fields[i].split(
|
|
137
|
+
const path = fields[i].split(".");
|
|
292
138
|
let value = item;
|
|
293
139
|
for (let p = 0; p < path.length; p++) {
|
|
294
140
|
const part = path[p];
|
|
@@ -300,139 +146,58 @@ export function hasEntityRecord(state, kind, name, key, query) {
|
|
|
300
146
|
}
|
|
301
147
|
return true;
|
|
302
148
|
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity records from the API if the entity record isn't available in the local state.
|
|
306
|
-
*
|
|
307
|
-
* @param state State tree
|
|
308
|
-
* @param kind Entity kind.
|
|
309
|
-
* @param name Entity name.
|
|
310
|
-
* @param key Record's key
|
|
311
|
-
*
|
|
312
|
-
* @return Record.
|
|
313
|
-
*/
|
|
314
|
-
export function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
|
|
149
|
+
function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
|
|
315
150
|
return getEntityRecord(state, kind, name, key);
|
|
316
151
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
return [state.entities.config, state.entities.records?.[kind]?.[name]?.queriedData?.items[context]?.[recordId], state.entities.records?.[kind]?.[name]?.queriedData?.itemIsComplete[context]?.[recordId]];
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Returns true if records have been received for the given set of parameters,
|
|
351
|
-
* or false otherwise.
|
|
352
|
-
*
|
|
353
|
-
* @param state State tree
|
|
354
|
-
* @param kind Entity kind.
|
|
355
|
-
* @param name Entity name.
|
|
356
|
-
* @param query Optional terms query. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".
|
|
357
|
-
*
|
|
358
|
-
* @return Whether entity records have been received.
|
|
359
|
-
*/
|
|
360
|
-
export function hasEntityRecords(state, kind, name, query) {
|
|
361
|
-
logEntityDeprecation(kind, name, 'hasEntityRecords');
|
|
152
|
+
const getRawEntityRecord = createSelector(
|
|
153
|
+
(state, kind, name, key) => {
|
|
154
|
+
logEntityDeprecation(kind, name, "getRawEntityRecord");
|
|
155
|
+
const record = getEntityRecord(
|
|
156
|
+
state,
|
|
157
|
+
kind,
|
|
158
|
+
name,
|
|
159
|
+
key
|
|
160
|
+
);
|
|
161
|
+
return record && Object.keys(record).reduce((accumulator, _key) => {
|
|
162
|
+
if (isRawAttribute(getEntityConfig(state, kind, name), _key)) {
|
|
163
|
+
accumulator[_key] = record[_key]?.raw !== void 0 ? record[_key]?.raw : record[_key];
|
|
164
|
+
} else {
|
|
165
|
+
accumulator[_key] = record[_key];
|
|
166
|
+
}
|
|
167
|
+
return accumulator;
|
|
168
|
+
}, {});
|
|
169
|
+
},
|
|
170
|
+
(state, kind, name, recordId, query) => {
|
|
171
|
+
const context = query?.context ?? "default";
|
|
172
|
+
return [
|
|
173
|
+
state.entities.config,
|
|
174
|
+
state.entities.records?.[kind]?.[name]?.queriedData?.items[context]?.[recordId],
|
|
175
|
+
state.entities.records?.[kind]?.[name]?.queriedData?.itemIsComplete[context]?.[recordId]
|
|
176
|
+
];
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
function hasEntityRecords(state, kind, name, query) {
|
|
180
|
+
logEntityDeprecation(kind, name, "hasEntityRecords");
|
|
362
181
|
return Array.isArray(getEntityRecords(state, kind, name, query));
|
|
363
182
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
* GetEntityRecord is declared as a *callable interface* with
|
|
367
|
-
* two signatures to work around the fact that TypeScript doesn't
|
|
368
|
-
* allow currying generic functions.
|
|
369
|
-
*
|
|
370
|
-
* @see GetEntityRecord
|
|
371
|
-
* @see https://github.com/WordPress/gutenberg/pull/41578
|
|
372
|
-
*/
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* Returns the Entity's records.
|
|
376
|
-
*
|
|
377
|
-
* @param state State tree
|
|
378
|
-
* @param kind Entity kind.
|
|
379
|
-
* @param name Entity name.
|
|
380
|
-
* @param query Optional terms query. If requesting specific
|
|
381
|
-
* fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".
|
|
382
|
-
*
|
|
383
|
-
* @return Records.
|
|
384
|
-
*/
|
|
385
|
-
export const getEntityRecords = (state, kind, name, query) => {
|
|
386
|
-
logEntityDeprecation(kind, name, 'getEntityRecords');
|
|
387
|
-
|
|
388
|
-
// Queried data state is prepopulated for all known entities. If this is not
|
|
389
|
-
// assigned for the given parameters, then it is known to not exist.
|
|
183
|
+
const getEntityRecords = ((state, kind, name, query) => {
|
|
184
|
+
logEntityDeprecation(kind, name, "getEntityRecords");
|
|
390
185
|
const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
|
|
391
186
|
if (!queriedState) {
|
|
392
187
|
return null;
|
|
393
188
|
}
|
|
394
189
|
return getQueriedItems(queriedState, query);
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
* Returns the Entity's total available records for a given query (ignoring pagination).
|
|
399
|
-
*
|
|
400
|
-
* @param state State tree
|
|
401
|
-
* @param kind Entity kind.
|
|
402
|
-
* @param name Entity name.
|
|
403
|
-
* @param query Optional terms query. If requesting specific
|
|
404
|
-
* fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".
|
|
405
|
-
*
|
|
406
|
-
* @return number | null.
|
|
407
|
-
*/
|
|
408
|
-
export const getEntityRecordsTotalItems = (state, kind, name, query) => {
|
|
409
|
-
logEntityDeprecation(kind, name, 'getEntityRecordsTotalItems');
|
|
410
|
-
|
|
411
|
-
// Queried data state is prepopulated for all known entities. If this is not
|
|
412
|
-
// assigned for the given parameters, then it is known to not exist.
|
|
190
|
+
});
|
|
191
|
+
const getEntityRecordsTotalItems = (state, kind, name, query) => {
|
|
192
|
+
logEntityDeprecation(kind, name, "getEntityRecordsTotalItems");
|
|
413
193
|
const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
|
|
414
194
|
if (!queriedState) {
|
|
415
195
|
return null;
|
|
416
196
|
}
|
|
417
197
|
return getQueriedTotalItems(queriedState, query);
|
|
418
198
|
};
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
* Returns the number of available pages for the given query.
|
|
422
|
-
*
|
|
423
|
-
* @param state State tree
|
|
424
|
-
* @param kind Entity kind.
|
|
425
|
-
* @param name Entity name.
|
|
426
|
-
* @param query Optional terms query. If requesting specific
|
|
427
|
-
* fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".
|
|
428
|
-
*
|
|
429
|
-
* @return number | null.
|
|
430
|
-
*/
|
|
431
|
-
export const getEntityRecordsTotalPages = (state, kind, name, query) => {
|
|
432
|
-
logEntityDeprecation(kind, name, 'getEntityRecordsTotalPages');
|
|
433
|
-
|
|
434
|
-
// Queried data state is prepopulated for all known entities. If this is not
|
|
435
|
-
// assigned for the given parameters, then it is known to not exist.
|
|
199
|
+
const getEntityRecordsTotalPages = (state, kind, name, query) => {
|
|
200
|
+
logEntityDeprecation(kind, name, "getEntityRecordsTotalPages");
|
|
436
201
|
const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
|
|
437
202
|
if (!queriedState) {
|
|
438
203
|
return null;
|
|
@@ -444,597 +209,269 @@ export const getEntityRecordsTotalPages = (state, kind, name, query) => {
|
|
|
444
209
|
if (!totalItems) {
|
|
445
210
|
return totalItems;
|
|
446
211
|
}
|
|
447
|
-
// If `per_page` is not set and the query relies on the defaults of the
|
|
448
|
-
// REST endpoint, get the info from query's meta.
|
|
449
212
|
if (!query?.per_page) {
|
|
450
213
|
return getQueriedTotalPages(queriedState, query);
|
|
451
214
|
}
|
|
452
215
|
return Math.ceil(totalItems / query.per_page);
|
|
453
216
|
};
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
217
|
+
const __experimentalGetDirtyEntityRecords = createSelector(
|
|
218
|
+
(state) => {
|
|
219
|
+
const {
|
|
220
|
+
entities: { records }
|
|
221
|
+
} = state;
|
|
222
|
+
const dirtyRecords = [];
|
|
223
|
+
Object.keys(records).forEach((kind) => {
|
|
224
|
+
Object.keys(records[kind]).forEach((name) => {
|
|
225
|
+
const primaryKeys = Object.keys(records[kind][name].edits).filter(
|
|
226
|
+
(primaryKey) => (
|
|
227
|
+
// The entity record must exist (not be deleted),
|
|
228
|
+
// and it must have edits.
|
|
229
|
+
getEntityRecord(state, kind, name, primaryKey) && hasEditsForEntityRecord(state, kind, name, primaryKey)
|
|
230
|
+
)
|
|
231
|
+
);
|
|
232
|
+
if (primaryKeys.length) {
|
|
233
|
+
const entityConfig = getEntityConfig(state, kind, name);
|
|
234
|
+
primaryKeys.forEach((primaryKey) => {
|
|
235
|
+
const entityRecord = getEditedEntityRecord(
|
|
236
|
+
state,
|
|
237
|
+
kind,
|
|
238
|
+
name,
|
|
239
|
+
primaryKey
|
|
240
|
+
);
|
|
241
|
+
dirtyRecords.push({
|
|
242
|
+
// We avoid using primaryKey because it's transformed into a string
|
|
243
|
+
// when it's used as an object key.
|
|
244
|
+
key: entityRecord ? entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY] : void 0,
|
|
245
|
+
title: entityConfig?.getTitle?.(entityRecord) || "",
|
|
246
|
+
name,
|
|
247
|
+
kind
|
|
248
|
+
});
|
|
485
249
|
});
|
|
486
|
-
}
|
|
487
|
-
}
|
|
250
|
+
}
|
|
251
|
+
});
|
|
488
252
|
});
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
253
|
+
return dirtyRecords;
|
|
254
|
+
},
|
|
255
|
+
(state) => [state.entities.records]
|
|
256
|
+
);
|
|
257
|
+
const __experimentalGetEntitiesBeingSaved = createSelector(
|
|
258
|
+
(state) => {
|
|
259
|
+
const {
|
|
260
|
+
entities: { records }
|
|
261
|
+
} = state;
|
|
262
|
+
const recordsBeingSaved = [];
|
|
263
|
+
Object.keys(records).forEach((kind) => {
|
|
264
|
+
Object.keys(records[kind]).forEach((name) => {
|
|
265
|
+
const primaryKeys = Object.keys(records[kind][name].saving).filter(
|
|
266
|
+
(primaryKey) => isSavingEntityRecord(state, kind, name, primaryKey)
|
|
267
|
+
);
|
|
268
|
+
if (primaryKeys.length) {
|
|
269
|
+
const entityConfig = getEntityConfig(state, kind, name);
|
|
270
|
+
primaryKeys.forEach((primaryKey) => {
|
|
271
|
+
const entityRecord = getEditedEntityRecord(
|
|
272
|
+
state,
|
|
273
|
+
kind,
|
|
274
|
+
name,
|
|
275
|
+
primaryKey
|
|
276
|
+
);
|
|
277
|
+
recordsBeingSaved.push({
|
|
278
|
+
// We avoid using primaryKey because it's transformed into a string
|
|
279
|
+
// when it's used as an object key.
|
|
280
|
+
key: entityRecord ? entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY] : void 0,
|
|
281
|
+
title: entityConfig?.getTitle?.(entityRecord) || "",
|
|
282
|
+
name,
|
|
283
|
+
kind
|
|
284
|
+
});
|
|
521
285
|
});
|
|
522
|
-
}
|
|
523
|
-
}
|
|
286
|
+
}
|
|
287
|
+
});
|
|
524
288
|
});
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
*
|
|
532
|
-
* @param state State tree.
|
|
533
|
-
* @param kind Entity kind.
|
|
534
|
-
* @param name Entity name.
|
|
535
|
-
* @param recordId Record ID.
|
|
536
|
-
*
|
|
537
|
-
* @return The entity record's edits.
|
|
538
|
-
*/
|
|
539
|
-
export function getEntityRecordEdits(state, kind, name, recordId) {
|
|
540
|
-
logEntityDeprecation(kind, name, 'getEntityRecordEdits');
|
|
289
|
+
return recordsBeingSaved;
|
|
290
|
+
},
|
|
291
|
+
(state) => [state.entities.records]
|
|
292
|
+
);
|
|
293
|
+
function getEntityRecordEdits(state, kind, name, recordId) {
|
|
294
|
+
logEntityDeprecation(kind, name, "getEntityRecordEdits");
|
|
541
295
|
return state.entities.records?.[kind]?.[name]?.edits?.[recordId];
|
|
542
296
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
*
|
|
551
|
-
* @param state State tree.
|
|
552
|
-
* @param kind Entity kind.
|
|
553
|
-
* @param name Entity name.
|
|
554
|
-
* @param recordId Record ID.
|
|
555
|
-
*
|
|
556
|
-
* @return The entity record's non transient edits.
|
|
557
|
-
*/
|
|
558
|
-
export const getEntityRecordNonTransientEdits = createSelector((state, kind, name, recordId) => {
|
|
559
|
-
logEntityDeprecation(kind, name, 'getEntityRecordNonTransientEdits');
|
|
560
|
-
const {
|
|
561
|
-
transientEdits
|
|
562
|
-
} = getEntityConfig(state, kind, name) || {};
|
|
563
|
-
const edits = getEntityRecordEdits(state, kind, name, recordId) || {};
|
|
564
|
-
if (!transientEdits) {
|
|
565
|
-
return edits;
|
|
566
|
-
}
|
|
567
|
-
return Object.keys(edits).reduce((acc, key) => {
|
|
568
|
-
if (!transientEdits[key]) {
|
|
569
|
-
acc[key] = edits[key];
|
|
297
|
+
const getEntityRecordNonTransientEdits = createSelector(
|
|
298
|
+
(state, kind, name, recordId) => {
|
|
299
|
+
logEntityDeprecation(kind, name, "getEntityRecordNonTransientEdits");
|
|
300
|
+
const { transientEdits } = getEntityConfig(state, kind, name) || {};
|
|
301
|
+
const edits = getEntityRecordEdits(state, kind, name, recordId) || {};
|
|
302
|
+
if (!transientEdits) {
|
|
303
|
+
return edits;
|
|
570
304
|
}
|
|
571
|
-
return acc
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
return false;
|
|
305
|
+
return Object.keys(edits).reduce((acc, key) => {
|
|
306
|
+
if (!transientEdits[key]) {
|
|
307
|
+
acc[key] = edits[key];
|
|
308
|
+
}
|
|
309
|
+
return acc;
|
|
310
|
+
}, {});
|
|
311
|
+
},
|
|
312
|
+
(state, kind, name, recordId) => [
|
|
313
|
+
state.entities.config,
|
|
314
|
+
state.entities.records?.[kind]?.[name]?.edits?.[recordId]
|
|
315
|
+
]
|
|
316
|
+
);
|
|
317
|
+
function hasEditsForEntityRecord(state, kind, name, recordId) {
|
|
318
|
+
logEntityDeprecation(kind, name, "hasEditsForEntityRecord");
|
|
319
|
+
return isSavingEntityRecord(state, kind, name, recordId) || Object.keys(
|
|
320
|
+
getEntityRecordNonTransientEdits(state, kind, name, recordId)
|
|
321
|
+
).length > 0;
|
|
322
|
+
}
|
|
323
|
+
const getEditedEntityRecord = createSelector(
|
|
324
|
+
(state, kind, name, recordId) => {
|
|
325
|
+
logEntityDeprecation(kind, name, "getEditedEntityRecord");
|
|
326
|
+
const raw = getRawEntityRecord(state, kind, name, recordId);
|
|
327
|
+
const edited = getEntityRecordEdits(state, kind, name, recordId);
|
|
328
|
+
if (!raw && !edited) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
...raw,
|
|
333
|
+
...edited
|
|
334
|
+
};
|
|
335
|
+
},
|
|
336
|
+
(state, kind, name, recordId, query) => {
|
|
337
|
+
const context = query?.context ?? "default";
|
|
338
|
+
return [
|
|
339
|
+
state.entities.config,
|
|
340
|
+
state.entities.records?.[kind]?.[name]?.queriedData.items[context]?.[recordId],
|
|
341
|
+
state.entities.records?.[kind]?.[name]?.queriedData.itemIsComplete[context]?.[recordId],
|
|
342
|
+
state.entities.records?.[kind]?.[name]?.edits?.[recordId]
|
|
343
|
+
];
|
|
611
344
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
};
|
|
616
|
-
}, (state, kind, name, recordId, query) => {
|
|
617
|
-
var _query$context5;
|
|
618
|
-
const context = (_query$context5 = query?.context) !== null && _query$context5 !== void 0 ? _query$context5 : 'default';
|
|
619
|
-
return [state.entities.config, state.entities.records?.[kind]?.[name]?.queriedData.items[context]?.[recordId], state.entities.records?.[kind]?.[name]?.queriedData.itemIsComplete[context]?.[recordId], state.entities.records?.[kind]?.[name]?.edits?.[recordId]];
|
|
620
|
-
});
|
|
621
|
-
|
|
622
|
-
/**
|
|
623
|
-
* Returns true if the specified entity record is autosaving, and false otherwise.
|
|
624
|
-
*
|
|
625
|
-
* @param state State tree.
|
|
626
|
-
* @param kind Entity kind.
|
|
627
|
-
* @param name Entity name.
|
|
628
|
-
* @param recordId Record ID.
|
|
629
|
-
*
|
|
630
|
-
* @return Whether the entity record is autosaving or not.
|
|
631
|
-
*/
|
|
632
|
-
export function isAutosavingEntityRecord(state, kind, name, recordId) {
|
|
633
|
-
var _state$entities$recor;
|
|
634
|
-
logEntityDeprecation(kind, name, 'isAutosavingEntityRecord');
|
|
635
|
-
const {
|
|
636
|
-
pending,
|
|
637
|
-
isAutosave
|
|
638
|
-
} = (_state$entities$recor = state.entities.records?.[kind]?.[name]?.saving?.[recordId]) !== null && _state$entities$recor !== void 0 ? _state$entities$recor : {};
|
|
345
|
+
);
|
|
346
|
+
function isAutosavingEntityRecord(state, kind, name, recordId) {
|
|
347
|
+
logEntityDeprecation(kind, name, "isAutosavingEntityRecord");
|
|
348
|
+
const { pending, isAutosave } = state.entities.records?.[kind]?.[name]?.saving?.[recordId] ?? {};
|
|
639
349
|
return Boolean(pending && isAutosave);
|
|
640
350
|
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
*
|
|
645
|
-
* @param state State tree.
|
|
646
|
-
* @param kind Entity kind.
|
|
647
|
-
* @param name Entity name.
|
|
648
|
-
* @param recordId Record ID.
|
|
649
|
-
*
|
|
650
|
-
* @return Whether the entity record is saving or not.
|
|
651
|
-
*/
|
|
652
|
-
export function isSavingEntityRecord(state, kind, name, recordId) {
|
|
653
|
-
var _state$entities$recor2;
|
|
654
|
-
logEntityDeprecation(kind, name, 'isSavingEntityRecord');
|
|
655
|
-
return (_state$entities$recor2 = state.entities.records?.[kind]?.[name]?.saving?.[recordId]?.pending) !== null && _state$entities$recor2 !== void 0 ? _state$entities$recor2 : false;
|
|
351
|
+
function isSavingEntityRecord(state, kind, name, recordId) {
|
|
352
|
+
logEntityDeprecation(kind, name, "isSavingEntityRecord");
|
|
353
|
+
return state.entities.records?.[kind]?.[name]?.saving?.[recordId]?.pending ?? false;
|
|
656
354
|
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
*
|
|
661
|
-
* @param state State tree.
|
|
662
|
-
* @param kind Entity kind.
|
|
663
|
-
* @param name Entity name.
|
|
664
|
-
* @param recordId Record ID.
|
|
665
|
-
*
|
|
666
|
-
* @return Whether the entity record is deleting or not.
|
|
667
|
-
*/
|
|
668
|
-
export function isDeletingEntityRecord(state, kind, name, recordId) {
|
|
669
|
-
var _state$entities$recor3;
|
|
670
|
-
logEntityDeprecation(kind, name, 'isDeletingEntityRecord');
|
|
671
|
-
return (_state$entities$recor3 = state.entities.records?.[kind]?.[name]?.deleting?.[recordId]?.pending) !== null && _state$entities$recor3 !== void 0 ? _state$entities$recor3 : false;
|
|
355
|
+
function isDeletingEntityRecord(state, kind, name, recordId) {
|
|
356
|
+
logEntityDeprecation(kind, name, "isDeletingEntityRecord");
|
|
357
|
+
return state.entities.records?.[kind]?.[name]?.deleting?.[recordId]?.pending ?? false;
|
|
672
358
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
* Returns the specified entity record's last save error.
|
|
676
|
-
*
|
|
677
|
-
* @param state State tree.
|
|
678
|
-
* @param kind Entity kind.
|
|
679
|
-
* @param name Entity name.
|
|
680
|
-
* @param recordId Record ID.
|
|
681
|
-
*
|
|
682
|
-
* @return The entity record's save error.
|
|
683
|
-
*/
|
|
684
|
-
export function getLastEntitySaveError(state, kind, name, recordId) {
|
|
685
|
-
logEntityDeprecation(kind, name, 'getLastEntitySaveError');
|
|
359
|
+
function getLastEntitySaveError(state, kind, name, recordId) {
|
|
360
|
+
logEntityDeprecation(kind, name, "getLastEntitySaveError");
|
|
686
361
|
return state.entities.records?.[kind]?.[name]?.saving?.[recordId]?.error;
|
|
687
362
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
* Returns the specified entity record's last delete error.
|
|
691
|
-
*
|
|
692
|
-
* @param state State tree.
|
|
693
|
-
* @param kind Entity kind.
|
|
694
|
-
* @param name Entity name.
|
|
695
|
-
* @param recordId Record ID.
|
|
696
|
-
*
|
|
697
|
-
* @return The entity record's save error.
|
|
698
|
-
*/
|
|
699
|
-
export function getLastEntityDeleteError(state, kind, name, recordId) {
|
|
700
|
-
logEntityDeprecation(kind, name, 'getLastEntityDeleteError');
|
|
363
|
+
function getLastEntityDeleteError(state, kind, name, recordId) {
|
|
364
|
+
logEntityDeprecation(kind, name, "getLastEntityDeleteError");
|
|
701
365
|
return state.entities.records?.[kind]?.[name]?.deleting?.[recordId]?.error;
|
|
702
366
|
}
|
|
703
|
-
|
|
704
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
705
|
-
/**
|
|
706
|
-
* Returns the previous edit from the current undo offset
|
|
707
|
-
* for the entity records edits history, if any.
|
|
708
|
-
*
|
|
709
|
-
* @deprecated since 6.3
|
|
710
|
-
*
|
|
711
|
-
* @param state State tree.
|
|
712
|
-
*
|
|
713
|
-
* @return The edit.
|
|
714
|
-
*/
|
|
715
|
-
export function getUndoEdit(state) {
|
|
367
|
+
function getUndoEdit(state) {
|
|
716
368
|
deprecated("select( 'core' ).getUndoEdit()", {
|
|
717
|
-
since:
|
|
369
|
+
since: "6.3"
|
|
718
370
|
});
|
|
719
|
-
return
|
|
371
|
+
return void 0;
|
|
720
372
|
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
724
|
-
/**
|
|
725
|
-
* Returns the next edit from the current undo offset
|
|
726
|
-
* for the entity records edits history, if any.
|
|
727
|
-
*
|
|
728
|
-
* @deprecated since 6.3
|
|
729
|
-
*
|
|
730
|
-
* @param state State tree.
|
|
731
|
-
*
|
|
732
|
-
* @return The edit.
|
|
733
|
-
*/
|
|
734
|
-
export function getRedoEdit(state) {
|
|
373
|
+
function getRedoEdit(state) {
|
|
735
374
|
deprecated("select( 'core' ).getRedoEdit()", {
|
|
736
|
-
since:
|
|
375
|
+
since: "6.3"
|
|
737
376
|
});
|
|
738
|
-
return
|
|
377
|
+
return void 0;
|
|
739
378
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
/**
|
|
743
|
-
* Returns true if there is a previous edit from the current undo offset
|
|
744
|
-
* for the entity records edits history, and false otherwise.
|
|
745
|
-
*
|
|
746
|
-
* @param state State tree.
|
|
747
|
-
*
|
|
748
|
-
* @return Whether there is a previous edit or not.
|
|
749
|
-
*/
|
|
750
|
-
export function hasUndo(state) {
|
|
379
|
+
function hasUndo(state) {
|
|
751
380
|
return state.undoManager.hasUndo();
|
|
752
381
|
}
|
|
753
|
-
|
|
754
|
-
/**
|
|
755
|
-
* Returns true if there is a next edit from the current undo offset
|
|
756
|
-
* for the entity records edits history, and false otherwise.
|
|
757
|
-
*
|
|
758
|
-
* @param state State tree.
|
|
759
|
-
*
|
|
760
|
-
* @return Whether there is a next edit or not.
|
|
761
|
-
*/
|
|
762
|
-
export function hasRedo(state) {
|
|
382
|
+
function hasRedo(state) {
|
|
763
383
|
return state.undoManager.hasRedo();
|
|
764
384
|
}
|
|
765
|
-
|
|
766
|
-
/**
|
|
767
|
-
* Return the current theme.
|
|
768
|
-
*
|
|
769
|
-
* @param state Data state.
|
|
770
|
-
*
|
|
771
|
-
* @return The current theme.
|
|
772
|
-
*/
|
|
773
|
-
export function getCurrentTheme(state) {
|
|
385
|
+
function getCurrentTheme(state) {
|
|
774
386
|
if (!state.currentTheme) {
|
|
775
387
|
return null;
|
|
776
388
|
}
|
|
777
|
-
return getEntityRecord(state,
|
|
389
|
+
return getEntityRecord(state, "root", "theme", state.currentTheme);
|
|
778
390
|
}
|
|
779
|
-
|
|
780
|
-
/**
|
|
781
|
-
* Return the ID of the current global styles object.
|
|
782
|
-
*
|
|
783
|
-
* @param state Data state.
|
|
784
|
-
*
|
|
785
|
-
* @return The current global styles ID.
|
|
786
|
-
*/
|
|
787
|
-
export function __experimentalGetCurrentGlobalStylesId(state) {
|
|
391
|
+
function __experimentalGetCurrentGlobalStylesId(state) {
|
|
788
392
|
return state.currentGlobalStylesId;
|
|
789
393
|
}
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
* Return theme supports data in the index.
|
|
793
|
-
*
|
|
794
|
-
* @param state Data state.
|
|
795
|
-
*
|
|
796
|
-
* @return Index data.
|
|
797
|
-
*/
|
|
798
|
-
export function getThemeSupports(state) {
|
|
799
|
-
var _getCurrentTheme$them;
|
|
800
|
-
return (_getCurrentTheme$them = getCurrentTheme(state)?.theme_supports) !== null && _getCurrentTheme$them !== void 0 ? _getCurrentTheme$them : EMPTY_OBJECT;
|
|
394
|
+
function getThemeSupports(state) {
|
|
395
|
+
return getCurrentTheme(state)?.theme_supports ?? EMPTY_OBJECT;
|
|
801
396
|
}
|
|
802
|
-
|
|
803
|
-
/**
|
|
804
|
-
* Returns the embed preview for the given URL.
|
|
805
|
-
*
|
|
806
|
-
* @param state Data state.
|
|
807
|
-
* @param url Embedded URL.
|
|
808
|
-
*
|
|
809
|
-
* @return Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API.
|
|
810
|
-
*/
|
|
811
|
-
export function getEmbedPreview(state, url) {
|
|
397
|
+
function getEmbedPreview(state, url) {
|
|
812
398
|
return state.embedPreviews[url];
|
|
813
399
|
}
|
|
814
|
-
|
|
815
|
-
/**
|
|
816
|
-
* Determines if the returned preview is an oEmbed link fallback.
|
|
817
|
-
*
|
|
818
|
-
* WordPress can be configured to return a simple link to a URL if it is not embeddable.
|
|
819
|
-
* We need to be able to determine if a URL is embeddable or not, based on what we
|
|
820
|
-
* get back from the oEmbed preview API.
|
|
821
|
-
*
|
|
822
|
-
* @param state Data state.
|
|
823
|
-
* @param url Embedded URL.
|
|
824
|
-
*
|
|
825
|
-
* @return Is the preview for the URL an oEmbed link fallback.
|
|
826
|
-
*/
|
|
827
|
-
export function isPreviewEmbedFallback(state, url) {
|
|
400
|
+
function isPreviewEmbedFallback(state, url) {
|
|
828
401
|
const preview = state.embedPreviews[url];
|
|
829
|
-
const oEmbedLinkCheck = '<a href="' + url + '">' + url +
|
|
402
|
+
const oEmbedLinkCheck = '<a href="' + url + '">' + url + "</a>";
|
|
830
403
|
if (!preview) {
|
|
831
404
|
return false;
|
|
832
405
|
}
|
|
833
406
|
return preview.html === oEmbedLinkCheck;
|
|
834
407
|
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
* Returns whether the current user can perform the given action on the given
|
|
838
|
-
* REST resource.
|
|
839
|
-
*
|
|
840
|
-
* Calling this may trigger an OPTIONS request to the REST API via the
|
|
841
|
-
* `canUser()` resolver.
|
|
842
|
-
*
|
|
843
|
-
* https://developer.wordpress.org/rest-api/reference/
|
|
844
|
-
*
|
|
845
|
-
* @param state Data state.
|
|
846
|
-
* @param action Action to check. One of: 'create', 'read', 'update', 'delete'.
|
|
847
|
-
* @param resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`
|
|
848
|
-
* or REST base as a string - `media`.
|
|
849
|
-
* @param id Optional ID of the rest resource to check.
|
|
850
|
-
*
|
|
851
|
-
* @return Whether or not the user can perform the action,
|
|
852
|
-
* or `undefined` if the OPTIONS request is still being made.
|
|
853
|
-
*/
|
|
854
|
-
export function canUser(state, action, resource, id) {
|
|
855
|
-
const isEntity = typeof resource === 'object';
|
|
408
|
+
function canUser(state, action, resource, id) {
|
|
409
|
+
const isEntity = typeof resource === "object";
|
|
856
410
|
if (isEntity && (!resource.kind || !resource.name)) {
|
|
857
411
|
return false;
|
|
858
412
|
}
|
|
859
413
|
if (isEntity) {
|
|
860
|
-
logEntityDeprecation(resource.kind, resource.name,
|
|
414
|
+
logEntityDeprecation(resource.kind, resource.name, "canUser");
|
|
861
415
|
}
|
|
862
416
|
const key = getUserPermissionCacheKey(action, resource, id);
|
|
863
417
|
return state.userPermissions[key];
|
|
864
418
|
}
|
|
865
|
-
|
|
866
|
-
/**
|
|
867
|
-
* Returns whether the current user can edit the given entity.
|
|
868
|
-
*
|
|
869
|
-
* Calling this may trigger an OPTIONS request to the REST API via the
|
|
870
|
-
* `canUser()` resolver.
|
|
871
|
-
*
|
|
872
|
-
* https://developer.wordpress.org/rest-api/reference/
|
|
873
|
-
*
|
|
874
|
-
* @param state Data state.
|
|
875
|
-
* @param kind Entity kind.
|
|
876
|
-
* @param name Entity name.
|
|
877
|
-
* @param recordId Record's id.
|
|
878
|
-
* @return Whether or not the user can edit,
|
|
879
|
-
* or `undefined` if the OPTIONS request is still being made.
|
|
880
|
-
*/
|
|
881
|
-
export function canUserEditEntityRecord(state, kind, name, recordId) {
|
|
419
|
+
function canUserEditEntityRecord(state, kind, name, recordId) {
|
|
882
420
|
deprecated(`wp.data.select( 'core' ).canUserEditEntityRecord()`, {
|
|
883
|
-
since:
|
|
421
|
+
since: "6.7",
|
|
884
422
|
alternative: `wp.data.select( 'core' ).canUser( 'update', { kind, name, id } )`
|
|
885
423
|
});
|
|
886
|
-
return canUser(state,
|
|
887
|
-
kind,
|
|
888
|
-
name,
|
|
889
|
-
id: recordId
|
|
890
|
-
});
|
|
424
|
+
return canUser(state, "update", { kind, name, id: recordId });
|
|
891
425
|
}
|
|
892
|
-
|
|
893
|
-
/**
|
|
894
|
-
* Returns the latest autosaves for the post.
|
|
895
|
-
*
|
|
896
|
-
* May return multiple autosaves since the backend stores one autosave per
|
|
897
|
-
* author for each post.
|
|
898
|
-
*
|
|
899
|
-
* @param state State tree.
|
|
900
|
-
* @param postType The type of the parent post.
|
|
901
|
-
* @param postId The id of the parent post.
|
|
902
|
-
*
|
|
903
|
-
* @return An array of autosaves for the post, or undefined if there is none.
|
|
904
|
-
*/
|
|
905
|
-
export function getAutosaves(state, postType, postId) {
|
|
426
|
+
function getAutosaves(state, postType, postId) {
|
|
906
427
|
return state.autosaves[postId];
|
|
907
428
|
}
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
* Returns the autosave for the post and author.
|
|
911
|
-
*
|
|
912
|
-
* @param state State tree.
|
|
913
|
-
* @param postType The type of the parent post.
|
|
914
|
-
* @param postId The id of the parent post.
|
|
915
|
-
* @param authorId The id of the author.
|
|
916
|
-
*
|
|
917
|
-
* @return The autosave for the post and author.
|
|
918
|
-
*/
|
|
919
|
-
export function getAutosave(state, postType, postId, authorId) {
|
|
920
|
-
if (authorId === undefined) {
|
|
429
|
+
function getAutosave(state, postType, postId, authorId) {
|
|
430
|
+
if (authorId === void 0) {
|
|
921
431
|
return;
|
|
922
432
|
}
|
|
923
433
|
const autosaves = state.autosaves[postId];
|
|
924
|
-
return autosaves?.find(
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
return select(STORE_NAME).hasFinishedResolution('getAutosaves', [postType, postId]);
|
|
938
|
-
});
|
|
939
|
-
|
|
940
|
-
/**
|
|
941
|
-
* Returns a new reference when edited values have changed. This is useful in
|
|
942
|
-
* inferring where an edit has been made between states by comparison of the
|
|
943
|
-
* return values using strict equality.
|
|
944
|
-
*
|
|
945
|
-
* @example
|
|
946
|
-
*
|
|
947
|
-
* ```
|
|
948
|
-
* const hasEditOccurred = (
|
|
949
|
-
* getReferenceByDistinctEdits( beforeState ) !==
|
|
950
|
-
* getReferenceByDistinctEdits( afterState )
|
|
951
|
-
* );
|
|
952
|
-
* ```
|
|
953
|
-
*
|
|
954
|
-
* @param state Editor state.
|
|
955
|
-
*
|
|
956
|
-
* @return A value whose reference will change only when an edit occurs.
|
|
957
|
-
*/
|
|
958
|
-
export function getReferenceByDistinctEdits(state) {
|
|
434
|
+
return autosaves?.find(
|
|
435
|
+
(autosave) => autosave.author === authorId
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
const hasFetchedAutosaves = createRegistrySelector(
|
|
439
|
+
(select) => (state, postType, postId) => {
|
|
440
|
+
return select(STORE_NAME).hasFinishedResolution("getAutosaves", [
|
|
441
|
+
postType,
|
|
442
|
+
postId
|
|
443
|
+
]);
|
|
444
|
+
}
|
|
445
|
+
);
|
|
446
|
+
function getReferenceByDistinctEdits(state) {
|
|
959
447
|
return state.editsReference;
|
|
960
448
|
}
|
|
961
|
-
|
|
962
|
-
/**
|
|
963
|
-
* Retrieve the current theme's base global styles
|
|
964
|
-
*
|
|
965
|
-
* @param state Editor state.
|
|
966
|
-
*
|
|
967
|
-
* @return The Global Styles object.
|
|
968
|
-
*/
|
|
969
|
-
export function __experimentalGetCurrentThemeBaseGlobalStyles(state) {
|
|
449
|
+
function __experimentalGetCurrentThemeBaseGlobalStyles(state) {
|
|
970
450
|
const currentTheme = getCurrentTheme(state);
|
|
971
451
|
if (!currentTheme) {
|
|
972
452
|
return null;
|
|
973
453
|
}
|
|
974
454
|
return state.themeBaseGlobalStyles[currentTheme.stylesheet];
|
|
975
455
|
}
|
|
976
|
-
|
|
977
|
-
/**
|
|
978
|
-
* Return the ID of the current global styles object.
|
|
979
|
-
*
|
|
980
|
-
* @param state Data state.
|
|
981
|
-
*
|
|
982
|
-
* @return The current global styles ID.
|
|
983
|
-
*/
|
|
984
|
-
export function __experimentalGetCurrentThemeGlobalStylesVariations(state) {
|
|
456
|
+
function __experimentalGetCurrentThemeGlobalStylesVariations(state) {
|
|
985
457
|
const currentTheme = getCurrentTheme(state);
|
|
986
458
|
if (!currentTheme) {
|
|
987
459
|
return null;
|
|
988
460
|
}
|
|
989
461
|
return state.themeGlobalStyleVariations[currentTheme.stylesheet];
|
|
990
462
|
}
|
|
991
|
-
|
|
992
|
-
/**
|
|
993
|
-
* Retrieve the list of registered block patterns.
|
|
994
|
-
*
|
|
995
|
-
* @param state Data state.
|
|
996
|
-
*
|
|
997
|
-
* @return Block pattern list.
|
|
998
|
-
*/
|
|
999
|
-
export function getBlockPatterns(state) {
|
|
463
|
+
function getBlockPatterns(state) {
|
|
1000
464
|
return state.blockPatterns;
|
|
1001
465
|
}
|
|
1002
|
-
|
|
1003
|
-
/**
|
|
1004
|
-
* Retrieve the list of registered block pattern categories.
|
|
1005
|
-
*
|
|
1006
|
-
* @param state Data state.
|
|
1007
|
-
*
|
|
1008
|
-
* @return Block pattern category list.
|
|
1009
|
-
*/
|
|
1010
|
-
export function getBlockPatternCategories(state) {
|
|
466
|
+
function getBlockPatternCategories(state) {
|
|
1011
467
|
return state.blockPatternCategories;
|
|
1012
468
|
}
|
|
1013
|
-
|
|
1014
|
-
/**
|
|
1015
|
-
* Retrieve the registered user pattern categories.
|
|
1016
|
-
*
|
|
1017
|
-
* @param state Data state.
|
|
1018
|
-
*
|
|
1019
|
-
* @return User patterns category array.
|
|
1020
|
-
*/
|
|
1021
|
-
|
|
1022
|
-
export function getUserPatternCategories(state) {
|
|
469
|
+
function getUserPatternCategories(state) {
|
|
1023
470
|
return state.userPatternCategories;
|
|
1024
471
|
}
|
|
1025
|
-
|
|
1026
|
-
/**
|
|
1027
|
-
* Returns the revisions of the current global styles theme.
|
|
1028
|
-
*
|
|
1029
|
-
* @deprecated since WordPress 6.5.0. Callers should use `select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )` instead, where `recordKey` is the id of the global styles parent post.
|
|
1030
|
-
*
|
|
1031
|
-
* @param state Data state.
|
|
1032
|
-
*
|
|
1033
|
-
* @return The current global styles.
|
|
1034
|
-
*/
|
|
1035
|
-
export function getCurrentThemeGlobalStylesRevisions(state) {
|
|
472
|
+
function getCurrentThemeGlobalStylesRevisions(state) {
|
|
1036
473
|
deprecated("select( 'core' ).getCurrentThemeGlobalStylesRevisions()", {
|
|
1037
|
-
since:
|
|
474
|
+
since: "6.5.0",
|
|
1038
475
|
alternative: "select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )"
|
|
1039
476
|
});
|
|
1040
477
|
const currentGlobalStylesId = __experimentalGetCurrentGlobalStylesId(state);
|
|
@@ -1043,87 +480,107 @@ export function getCurrentThemeGlobalStylesRevisions(state) {
|
|
|
1043
480
|
}
|
|
1044
481
|
return state.themeGlobalStyleRevisions[currentGlobalStylesId];
|
|
1045
482
|
}
|
|
1046
|
-
|
|
1047
|
-
/**
|
|
1048
|
-
* Returns the default template use to render a given query.
|
|
1049
|
-
*
|
|
1050
|
-
* @param state Data state.
|
|
1051
|
-
* @param query Query.
|
|
1052
|
-
*
|
|
1053
|
-
* @return The default template id for the given query.
|
|
1054
|
-
*/
|
|
1055
|
-
export function getDefaultTemplateId(state, query) {
|
|
483
|
+
function getDefaultTemplateId(state, query) {
|
|
1056
484
|
return state.defaultTemplates[JSON.stringify(query)];
|
|
1057
485
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
* Returns an entity's revisions.
|
|
1061
|
-
*
|
|
1062
|
-
* @param state State tree
|
|
1063
|
-
* @param kind Entity kind.
|
|
1064
|
-
* @param name Entity name.
|
|
1065
|
-
* @param recordKey The key of the entity record whose revisions you want to fetch.
|
|
1066
|
-
* @param query Optional query. If requesting specific
|
|
1067
|
-
* fields, fields must always include the ID. For valid query parameters see revisions schema in [the REST API Handbook](https://developer.wordpress.org/rest-api/reference/). Then see the arguments available "Retrieve a [Entity kind]".
|
|
1068
|
-
*
|
|
1069
|
-
* @return Record.
|
|
1070
|
-
*/
|
|
1071
|
-
export const getRevisions = (state, kind, name, recordKey, query) => {
|
|
1072
|
-
logEntityDeprecation(kind, name, 'getRevisions');
|
|
486
|
+
const getRevisions = (state, kind, name, recordKey, query) => {
|
|
487
|
+
logEntityDeprecation(kind, name, "getRevisions");
|
|
1073
488
|
const queriedStateRevisions = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey];
|
|
1074
489
|
if (!queriedStateRevisions) {
|
|
1075
490
|
return null;
|
|
1076
491
|
}
|
|
1077
492
|
return getQueriedItems(queriedStateRevisions, query);
|
|
1078
493
|
};
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
* @param name Entity name.
|
|
1086
|
-
* @param recordKey The key of the entity record whose revisions you want to fetch.
|
|
1087
|
-
* @param revisionKey The revision's key.
|
|
1088
|
-
* @param query Optional query. If requesting specific
|
|
1089
|
-
* fields, fields must always include the ID. For valid query parameters see revisions schema in [the REST API Handbook](https://developer.wordpress.org/rest-api/reference/). Then see the arguments available "Retrieve a [entity kind]".
|
|
1090
|
-
*
|
|
1091
|
-
* @return Record.
|
|
1092
|
-
*/
|
|
1093
|
-
export const getRevision = createSelector((state, kind, name, recordKey, revisionKey, query) => {
|
|
1094
|
-
var _query$context6, _getNormalizedCommaSe3;
|
|
1095
|
-
logEntityDeprecation(kind, name, 'getRevision');
|
|
1096
|
-
const queriedState = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey];
|
|
1097
|
-
if (!queriedState) {
|
|
1098
|
-
return undefined;
|
|
1099
|
-
}
|
|
1100
|
-
const context = (_query$context6 = query?.context) !== null && _query$context6 !== void 0 ? _query$context6 : 'default';
|
|
1101
|
-
if (!query || !query._fields) {
|
|
1102
|
-
// If expecting a complete item, validate that completeness.
|
|
1103
|
-
if (!queriedState.itemIsComplete[context]?.[revisionKey]) {
|
|
1104
|
-
return undefined;
|
|
494
|
+
const getRevision = createSelector(
|
|
495
|
+
(state, kind, name, recordKey, revisionKey, query) => {
|
|
496
|
+
logEntityDeprecation(kind, name, "getRevision");
|
|
497
|
+
const queriedState = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey];
|
|
498
|
+
if (!queriedState) {
|
|
499
|
+
return void 0;
|
|
1105
500
|
}
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
501
|
+
const context = query?.context ?? "default";
|
|
502
|
+
if (!query || !query._fields) {
|
|
503
|
+
if (!queriedState.itemIsComplete[context]?.[revisionKey]) {
|
|
504
|
+
return void 0;
|
|
505
|
+
}
|
|
506
|
+
return queriedState.items[context][revisionKey];
|
|
507
|
+
}
|
|
508
|
+
const item = queriedState.items[context]?.[revisionKey];
|
|
509
|
+
if (!item) {
|
|
510
|
+
return item;
|
|
511
|
+
}
|
|
512
|
+
const filteredItem = {};
|
|
513
|
+
const fields = getNormalizedCommaSeparable(query._fields) ?? [];
|
|
514
|
+
for (let f = 0; f < fields.length; f++) {
|
|
515
|
+
const field = fields[f].split(".");
|
|
516
|
+
let value = item;
|
|
517
|
+
field.forEach((fieldName) => {
|
|
518
|
+
value = value?.[fieldName];
|
|
519
|
+
});
|
|
520
|
+
setNestedValue(filteredItem, field, value);
|
|
521
|
+
}
|
|
522
|
+
return filteredItem;
|
|
523
|
+
},
|
|
524
|
+
(state, kind, name, recordKey, revisionKey, query) => {
|
|
525
|
+
const context = query?.context ?? "default";
|
|
526
|
+
const queriedState = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey];
|
|
527
|
+
return [
|
|
528
|
+
queriedState?.items?.[context]?.[revisionKey],
|
|
529
|
+
queriedState?.itemIsComplete?.[context]?.[revisionKey]
|
|
530
|
+
];
|
|
1121
531
|
}
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
532
|
+
);
|
|
533
|
+
export {
|
|
534
|
+
__experimentalGetCurrentGlobalStylesId,
|
|
535
|
+
__experimentalGetCurrentThemeBaseGlobalStyles,
|
|
536
|
+
__experimentalGetCurrentThemeGlobalStylesVariations,
|
|
537
|
+
__experimentalGetDirtyEntityRecords,
|
|
538
|
+
__experimentalGetEntitiesBeingSaved,
|
|
539
|
+
__experimentalGetEntityRecordNoResolver,
|
|
540
|
+
canUser,
|
|
541
|
+
canUserEditEntityRecord,
|
|
542
|
+
getAuthors,
|
|
543
|
+
getAutosave,
|
|
544
|
+
getAutosaves,
|
|
545
|
+
getBlockPatternCategories,
|
|
546
|
+
getBlockPatterns,
|
|
547
|
+
getCurrentTheme,
|
|
548
|
+
getCurrentThemeGlobalStylesRevisions,
|
|
549
|
+
getCurrentUser,
|
|
550
|
+
getDefaultTemplateId,
|
|
551
|
+
getEditedEntityRecord,
|
|
552
|
+
getEmbedPreview,
|
|
553
|
+
getEntitiesByKind,
|
|
554
|
+
getEntitiesConfig,
|
|
555
|
+
getEntity,
|
|
556
|
+
getEntityConfig,
|
|
557
|
+
getEntityRecord,
|
|
558
|
+
getEntityRecordEdits,
|
|
559
|
+
getEntityRecordNonTransientEdits,
|
|
560
|
+
getEntityRecords,
|
|
561
|
+
getEntityRecordsTotalItems,
|
|
562
|
+
getEntityRecordsTotalPages,
|
|
563
|
+
getLastEntityDeleteError,
|
|
564
|
+
getLastEntitySaveError,
|
|
565
|
+
getRawEntityRecord,
|
|
566
|
+
getRedoEdit,
|
|
567
|
+
getReferenceByDistinctEdits,
|
|
568
|
+
getRevision,
|
|
569
|
+
getRevisions,
|
|
570
|
+
getThemeSupports,
|
|
571
|
+
getUndoEdit,
|
|
572
|
+
getUserPatternCategories,
|
|
573
|
+
getUserQueryResults,
|
|
574
|
+
hasEditsForEntityRecord,
|
|
575
|
+
hasEntityRecord,
|
|
576
|
+
hasEntityRecords,
|
|
577
|
+
hasFetchedAutosaves,
|
|
578
|
+
hasRedo,
|
|
579
|
+
hasUndo,
|
|
580
|
+
isAutosavingEntityRecord,
|
|
581
|
+
isDeletingEntityRecord,
|
|
582
|
+
isPreviewEmbedFallback,
|
|
583
|
+
isRequestingEmbedPreview,
|
|
584
|
+
isSavingEntityRecord
|
|
585
|
+
};
|
|
586
|
+
//# sourceMappingURL=selectors.js.map
|