@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,81 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
|
-
import { STORE_NAME } from '../name';
|
|
12
|
-
import useEntityId from './use-entity-id';
|
|
13
|
-
import { updateFootnotesFromMeta } from '../footnotes';
|
|
1
|
+
import { useCallback, useMemo } from "@wordpress/element";
|
|
2
|
+
import { useDispatch, useSelect } from "@wordpress/data";
|
|
3
|
+
import { parse, __unstableSerializeAndClean } from "@wordpress/blocks";
|
|
4
|
+
import { STORE_NAME } from "../name";
|
|
5
|
+
import useEntityId from "./use-entity-id";
|
|
6
|
+
import { updateFootnotesFromMeta } from "../footnotes";
|
|
14
7
|
const EMPTY_ARRAY = [];
|
|
15
|
-
const parsedBlocksCache = new WeakMap();
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Hook that returns block content getters and setters for
|
|
19
|
-
* the nearest provided entity of the specified type.
|
|
20
|
-
*
|
|
21
|
-
* The return value has the shape `[ blocks, onInput, onChange ]`.
|
|
22
|
-
* `onInput` is for block changes that don't create undo levels
|
|
23
|
-
* or dirty the post, non-persistent changes, and `onChange` is for
|
|
24
|
-
* persistent changes. They map directly to the props of a
|
|
25
|
-
* `BlockEditorProvider` and are intended to be used with it,
|
|
26
|
-
* or similar components or hooks.
|
|
27
|
-
*
|
|
28
|
-
* @param {string} kind The entity kind.
|
|
29
|
-
* @param {string} name The entity name.
|
|
30
|
-
* @param {Object} options
|
|
31
|
-
* @param {string} [options.id] An entity ID to use instead of the context-provided one.
|
|
32
|
-
*
|
|
33
|
-
* @return {[unknown[], Function, Function]} The block array and setters.
|
|
34
|
-
*/
|
|
35
|
-
export default function useEntityBlockEditor(kind, name, {
|
|
36
|
-
id: _id
|
|
37
|
-
} = {}) {
|
|
8
|
+
const parsedBlocksCache = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
function useEntityBlockEditor(kind, name, { id: _id } = {}) {
|
|
38
10
|
const providerId = useEntityId(kind, name);
|
|
39
|
-
const id = _id
|
|
40
|
-
const {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
editedBlocks: editedRecord.blocks,
|
|
58
|
-
content: editedRecord.content,
|
|
59
|
-
meta: editedRecord.meta
|
|
60
|
-
};
|
|
61
|
-
}, [kind, name, id]);
|
|
62
|
-
const {
|
|
63
|
-
__unstableCreateUndoLevel,
|
|
64
|
-
editEntityRecord
|
|
65
|
-
} = useDispatch(STORE_NAME);
|
|
11
|
+
const id = _id ?? providerId;
|
|
12
|
+
const { getEntityRecord, getEntityRecordEdits } = useSelect(STORE_NAME);
|
|
13
|
+
const { content, editedBlocks, meta } = useSelect(
|
|
14
|
+
(select) => {
|
|
15
|
+
if (!id) {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
const { getEditedEntityRecord } = select(STORE_NAME);
|
|
19
|
+
const editedRecord = getEditedEntityRecord(kind, name, id);
|
|
20
|
+
return {
|
|
21
|
+
editedBlocks: editedRecord.blocks,
|
|
22
|
+
content: editedRecord.content,
|
|
23
|
+
meta: editedRecord.meta
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
[kind, name, id]
|
|
27
|
+
);
|
|
28
|
+
const { __unstableCreateUndoLevel, editEntityRecord } = useDispatch(STORE_NAME);
|
|
66
29
|
const blocks = useMemo(() => {
|
|
67
30
|
if (!id) {
|
|
68
|
-
return
|
|
31
|
+
return void 0;
|
|
69
32
|
}
|
|
70
33
|
if (editedBlocks) {
|
|
71
34
|
return editedBlocks;
|
|
72
35
|
}
|
|
73
|
-
if (!content || typeof content !==
|
|
36
|
+
if (!content || typeof content !== "string") {
|
|
74
37
|
return EMPTY_ARRAY;
|
|
75
38
|
}
|
|
76
|
-
|
|
77
|
-
// If there's an edit, cache the parsed blocks by the edit.
|
|
78
|
-
// If not, cache by the original entity record.
|
|
79
39
|
const edits = getEntityRecordEdits(kind, name, id);
|
|
80
40
|
const isUnedited = !edits || !Object.keys(edits).length;
|
|
81
41
|
const cackeKey = isUnedited ? getEntityRecord(kind, name, id) : edits;
|
|
@@ -85,47 +45,57 @@ export default function useEntityBlockEditor(kind, name, {
|
|
|
85
45
|
parsedBlocksCache.set(cackeKey, _blocks);
|
|
86
46
|
}
|
|
87
47
|
return _blocks;
|
|
88
|
-
}, [
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
selection,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
...rest
|
|
127
|
-
|
|
128
|
-
|
|
48
|
+
}, [
|
|
49
|
+
kind,
|
|
50
|
+
name,
|
|
51
|
+
id,
|
|
52
|
+
editedBlocks,
|
|
53
|
+
content,
|
|
54
|
+
getEntityRecord,
|
|
55
|
+
getEntityRecordEdits
|
|
56
|
+
]);
|
|
57
|
+
const onChange = useCallback(
|
|
58
|
+
(newBlocks, options) => {
|
|
59
|
+
const noChange = blocks === newBlocks;
|
|
60
|
+
if (noChange) {
|
|
61
|
+
return __unstableCreateUndoLevel(kind, name, id);
|
|
62
|
+
}
|
|
63
|
+
const { selection, ...rest } = options;
|
|
64
|
+
const edits = {
|
|
65
|
+
selection,
|
|
66
|
+
content: ({ blocks: blocksForSerialization = [] }) => __unstableSerializeAndClean(blocksForSerialization),
|
|
67
|
+
...updateFootnotesFromMeta(newBlocks, meta)
|
|
68
|
+
};
|
|
69
|
+
editEntityRecord(kind, name, id, edits, {
|
|
70
|
+
isCached: false,
|
|
71
|
+
...rest
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
[
|
|
75
|
+
kind,
|
|
76
|
+
name,
|
|
77
|
+
id,
|
|
78
|
+
blocks,
|
|
79
|
+
meta,
|
|
80
|
+
__unstableCreateUndoLevel,
|
|
81
|
+
editEntityRecord
|
|
82
|
+
]
|
|
83
|
+
);
|
|
84
|
+
const onInput = useCallback(
|
|
85
|
+
(newBlocks, options) => {
|
|
86
|
+
const { selection, ...rest } = options;
|
|
87
|
+
const footnotesChanges = updateFootnotesFromMeta(newBlocks, meta);
|
|
88
|
+
const edits = { selection, ...footnotesChanges };
|
|
89
|
+
editEntityRecord(kind, name, id, edits, {
|
|
90
|
+
isCached: true,
|
|
91
|
+
...rest
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
[kind, name, id, meta, editEntityRecord]
|
|
95
|
+
);
|
|
129
96
|
return [blocks, onInput, onChange];
|
|
130
97
|
}
|
|
131
|
-
|
|
98
|
+
export {
|
|
99
|
+
useEntityBlockEditor as default
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=use-entity-block-editor.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hooks/use-entity-block-editor.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../name';\nimport useEntityId from './use-entity-id';\nimport { updateFootnotesFromMeta } from '../footnotes';\n\nconst EMPTY_ARRAY = [];\nconst parsedBlocksCache = new WeakMap();\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * persistent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[unknown[], Function, Function]} The block array and setters.\n */\nexport default function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { getEntityRecord, getEntityRecordEdits } = useSelect( STORE_NAME );\n\tconst { content, editedBlocks, meta } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! id ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t\tconst { getEditedEntityRecord } = select( STORE_NAME );\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn {\n\t\t\t\teditedBlocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t\tmeta: editedRecord.meta,\n\t\t\t};\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } =\n\t\tuseDispatch( STORE_NAME );\n\n\tconst blocks = useMemo( () => {\n\t\tif ( ! id ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif ( editedBlocks ) {\n\t\t\treturn editedBlocks;\n\t\t}\n\n\t\tif ( ! content || typeof content !== 'string' ) {\n\t\t\treturn EMPTY_ARRAY;\n\t\t}\n\n\t\t// If there's an edit, cache the parsed blocks by the edit.\n\t\t// If not, cache by the original entity record.\n\t\tconst edits = getEntityRecordEdits( kind, name, id );\n\t\tconst isUnedited = ! edits || ! Object.keys( edits ).length;\n\t\tconst cackeKey = isUnedited ? getEntityRecord( kind, name, id ) : edits;\n\t\tlet _blocks = parsedBlocksCache.get( cackeKey );\n\n\t\tif ( ! _blocks ) {\n\t\t\t_blocks = parse( content );\n\t\t\tparsedBlocksCache.set( cackeKey, _blocks );\n\t\t}\n\n\t\treturn _blocks;\n\t}, [\n\t\tkind,\n\t\tname,\n\t\tid,\n\t\teditedBlocks,\n\t\tcontent,\n\t\tgetEntityRecord,\n\t\tgetEntityRecordEdits,\n\t] );\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst noChange = blocks === newBlocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, name, id );\n\t\t\t}\n\t\t\tconst { selection, ...rest } = options;\n\n\t\t\t// We create a new function here on every persistent edit\n\t\t\t// to make sure the edit makes the post dirty and creates\n\t\t\t// a new undo level.\n\t\t\tconst edits = {\n\t\t\t\tselection,\n\t\t\t\tcontent: ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t\t__unstableSerializeAndClean( blocksForSerialization ),\n\t\t\t\t...updateFootnotesFromMeta( newBlocks, meta ),\n\t\t\t};\n\n\t\t\teditEntityRecord( kind, name, id, edits, {\n\t\t\t\tisCached: false,\n\t\t\t\t...rest,\n\t\t\t} );\n\t\t},\n\t\t[\n\t\t\tkind,\n\t\t\tname,\n\t\t\tid,\n\t\t\tblocks,\n\t\t\tmeta,\n\t\t\t__unstableCreateUndoLevel,\n\t\t\teditEntityRecord,\n\t\t]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection, ...rest } = options;\n\t\t\tconst footnotesChanges = updateFootnotesFromMeta( newBlocks, meta );\n\t\t\tconst edits = { selection, ...footnotesChanges };\n\n\t\t\teditEntityRecord( kind, name, id, edits, {\n\t\t\t\tisCached: true,\n\t\t\t\t...rest,\n\t\t\t} );\n\t\t},\n\t\t[ kind, name, id, meta, editEntityRecord ]\n\t);\n\n\treturn [ blocks, onInput, onChange ];\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,aAAa,eAAe;AACrC,SAAS,aAAa,iBAAiB;AACvC,SAAS,OAAO,mCAAmC;AAKnD,SAAS,kBAAkB;AAC3B,OAAO,iBAAiB;AACxB,SAAS,+BAA+B;AAExC,MAAM,cAAc,CAAC;AACrB,MAAM,oBAAoB,oBAAI,QAAQ;AAoBvB,SAAR,qBAAuC,MAAM,MAAM,EAAE,IAAI,IAAI,IAAI,CAAC,GAAI;AAC5E,QAAM,aAAa,YAAa,MAAM,IAAK;AAC3C,QAAM,KAAK,OAAO;AAClB,QAAM,EAAE,iBAAiB,qBAAqB,IAAI,UAAW,UAAW;AACxE,QAAM,EAAE,SAAS,cAAc,KAAK,IAAI;AAAA,IACvC,CAAE,WAAY;AACb,UAAK,CAAE,IAAK;AACX,eAAO,CAAC;AAAA,MACT;AACA,YAAM,EAAE,sBAAsB,IAAI,OAAQ,UAAW;AACrD,YAAM,eAAe,sBAAuB,MAAM,MAAM,EAAG;AAC3D,aAAO;AAAA,QACN,cAAc,aAAa;AAAA,QAC3B,SAAS,aAAa;AAAA,QACtB,MAAM,aAAa;AAAA,MACpB;AAAA,IACD;AAAA,IACA,CAAE,MAAM,MAAM,EAAG;AAAA,EAClB;AACA,QAAM,EAAE,2BAA2B,iBAAiB,IACnD,YAAa,UAAW;AAEzB,QAAM,SAAS,QAAS,MAAM;AAC7B,QAAK,CAAE,IAAK;AACX,aAAO;AAAA,IACR;AAEA,QAAK,cAAe;AACnB,aAAO;AAAA,IACR;AAEA,QAAK,CAAE,WAAW,OAAO,YAAY,UAAW;AAC/C,aAAO;AAAA,IACR;AAIA,UAAM,QAAQ,qBAAsB,MAAM,MAAM,EAAG;AACnD,UAAM,aAAa,CAAE,SAAS,CAAE,OAAO,KAAM,KAAM,EAAE;AACrD,UAAM,WAAW,aAAa,gBAAiB,MAAM,MAAM,EAAG,IAAI;AAClE,QAAI,UAAU,kBAAkB,IAAK,QAAS;AAE9C,QAAK,CAAE,SAAU;AAChB,gBAAU,MAAO,OAAQ;AACzB,wBAAkB,IAAK,UAAU,OAAQ;AAAA,IAC1C;AAEA,WAAO;AAAA,EACR,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,QAAM,WAAW;AAAA,IAChB,CAAE,WAAW,YAAa;AACzB,YAAM,WAAW,WAAW;AAC5B,UAAK,UAAW;AACf,eAAO,0BAA2B,MAAM,MAAM,EAAG;AAAA,MAClD;AACA,YAAM,EAAE,WAAW,GAAG,KAAK,IAAI;AAK/B,YAAM,QAAQ;AAAA,QACb;AAAA,QACA,SAAS,CAAE,EAAE,QAAQ,yBAAyB,CAAC,EAAE,MAChD,4BAA6B,sBAAuB;AAAA,QACrD,GAAG,wBAAyB,WAAW,IAAK;AAAA,MAC7C;AAEA,uBAAkB,MAAM,MAAM,IAAI,OAAO;AAAA,QACxC,UAAU;AAAA,QACV,GAAG;AAAA,MACJ,CAAE;AAAA,IACH;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAEA,QAAM,UAAU;AAAA,IACf,CAAE,WAAW,YAAa;AACzB,YAAM,EAAE,WAAW,GAAG,KAAK,IAAI;AAC/B,YAAM,mBAAmB,wBAAyB,WAAW,IAAK;AAClE,YAAM,QAAQ,EAAE,WAAW,GAAG,iBAAiB;AAE/C,uBAAkB,MAAM,MAAM,IAAI,OAAO;AAAA,QACxC,UAAU;AAAA,QACV,GAAG;AAAA,MACJ,CAAE;AAAA,IACH;AAAA,IACA,CAAE,MAAM,MAAM,IAAI,MAAM,gBAAiB;AAAA,EAC1C;AAEA,SAAO,CAAE,QAAQ,SAAS,QAAS;AACpC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { useContext } from '@wordpress/element';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { EntityContext } from '../entity-context';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Hook that returns the ID for the nearest
|
|
13
|
-
* provided entity of the specified type.
|
|
14
|
-
*
|
|
15
|
-
* @param {string} kind The entity kind.
|
|
16
|
-
* @param {string} name The entity name.
|
|
17
|
-
*/
|
|
18
|
-
export default function useEntityId(kind, name) {
|
|
1
|
+
import { useContext } from "@wordpress/element";
|
|
2
|
+
import { EntityContext } from "../entity-context";
|
|
3
|
+
function useEntityId(kind, name) {
|
|
19
4
|
const context = useContext(EntityContext);
|
|
20
5
|
return context?.[kind]?.[name];
|
|
21
6
|
}
|
|
22
|
-
|
|
7
|
+
export {
|
|
8
|
+
useEntityId as default
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=use-entity-id.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hooks/use-entity-id.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { EntityContext } from '../entity-context';\n\n/**\n * Hook that returns the ID for the nearest\n * provided entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n */\nexport default function useEntityId( kind, name ) {\n\tconst context = useContext( EntityContext );\n\treturn context?.[ kind ]?.[ name ];\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,kBAAkB;AAK3B,SAAS,qBAAqB;AASf,SAAR,YAA8B,MAAM,MAAO;AACjD,QAAM,UAAU,WAAY,aAAc;AAC1C,SAAO,UAAW,IAAK,IAAK,IAAK;AAClC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,58 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { STORE_NAME } from '../name';
|
|
11
|
-
import useEntityId from './use-entity-id';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Hook that returns the value and a setter for the
|
|
15
|
-
* specified property of the nearest provided
|
|
16
|
-
* entity of the specified type.
|
|
17
|
-
*
|
|
18
|
-
* @param {string} kind The entity kind.
|
|
19
|
-
* @param {string} name The entity name.
|
|
20
|
-
* @param {string} prop The property name.
|
|
21
|
-
* @param {number|string} [_id] An entity ID to use instead of the context-provided one.
|
|
22
|
-
*
|
|
23
|
-
* @return {[*, Function, *]} An array where the first item is the
|
|
24
|
-
* property value, the second is the
|
|
25
|
-
* setter and the third is the full value
|
|
26
|
-
* object from REST API containing more
|
|
27
|
-
* information like `raw`, `rendered` and
|
|
28
|
-
* `protected` props.
|
|
29
|
-
*/
|
|
30
|
-
export default function useEntityProp(kind, name, prop, _id) {
|
|
1
|
+
import { useCallback } from "@wordpress/element";
|
|
2
|
+
import { useDispatch, useSelect } from "@wordpress/data";
|
|
3
|
+
import { STORE_NAME } from "../name";
|
|
4
|
+
import useEntityId from "./use-entity-id";
|
|
5
|
+
function useEntityProp(kind, name, prop, _id) {
|
|
31
6
|
const providerId = useEntityId(kind, name);
|
|
32
|
-
const id = _id
|
|
33
|
-
const {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
editEntityRecord
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
}, [editEntityRecord, kind, name, id, prop]);
|
|
7
|
+
const id = _id ?? providerId;
|
|
8
|
+
const { value, fullValue } = useSelect(
|
|
9
|
+
(select) => {
|
|
10
|
+
const { getEntityRecord, getEditedEntityRecord } = select(STORE_NAME);
|
|
11
|
+
const record = getEntityRecord(kind, name, id);
|
|
12
|
+
const editedRecord = getEditedEntityRecord(kind, name, id);
|
|
13
|
+
return record && editedRecord ? {
|
|
14
|
+
value: editedRecord[prop],
|
|
15
|
+
fullValue: record[prop]
|
|
16
|
+
} : {};
|
|
17
|
+
},
|
|
18
|
+
[kind, name, id, prop]
|
|
19
|
+
);
|
|
20
|
+
const { editEntityRecord } = useDispatch(STORE_NAME);
|
|
21
|
+
const setValue = useCallback(
|
|
22
|
+
(newValue) => {
|
|
23
|
+
editEntityRecord(kind, name, id, {
|
|
24
|
+
[prop]: newValue
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
[editEntityRecord, kind, name, id, prop]
|
|
28
|
+
);
|
|
56
29
|
return [value, setValue, fullValue];
|
|
57
30
|
}
|
|
58
|
-
|
|
31
|
+
export {
|
|
32
|
+
useEntityProp as default
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=use-entity-prop.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hooks/use-entity-prop.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../name';\nimport useEntityId from './use-entity-id';\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {string} prop The property name.\n * @param {number|string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport default function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ editEntityRecord, kind, name, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,mBAAmB;AAC5B,SAAS,aAAa,iBAAiB;AAKvC,SAAS,kBAAkB;AAC3B,OAAO,iBAAiB;AAmBT,SAAR,cAAgC,MAAM,MAAM,MAAM,KAAM;AAC9D,QAAM,aAAa,YAAa,MAAM,IAAK;AAC3C,QAAM,KAAK,OAAO;AAElB,QAAM,EAAE,OAAO,UAAU,IAAI;AAAA,IAC5B,CAAE,WAAY;AACb,YAAM,EAAE,iBAAiB,sBAAsB,IAC9C,OAAQ,UAAW;AACpB,YAAM,SAAS,gBAAiB,MAAM,MAAM,EAAG;AAC/C,YAAM,eAAe,sBAAuB,MAAM,MAAM,EAAG;AAC3D,aAAO,UAAU,eACd;AAAA,QACA,OAAO,aAAc,IAAK;AAAA,QAC1B,WAAW,OAAQ,IAAK;AAAA,MACxB,IACA,CAAC;AAAA,IACL;AAAA,IACA,CAAE,MAAM,MAAM,IAAI,IAAK;AAAA,EACxB;AACA,QAAM,EAAE,iBAAiB,IAAI,YAAa,UAAW;AACrD,QAAM,WAAW;AAAA,IAChB,CAAE,aAAc;AACf,uBAAkB,MAAM,MAAM,IAAI;AAAA,QACjC,CAAE,IAAK,GAAG;AAAA,MACX,CAAE;AAAA,IACH;AAAA,IACA,CAAE,kBAAkB,MAAM,MAAM,IAAI,IAAK;AAAA,EAC1C;AAEA,SAAO,CAAE,OAAO,UAAU,SAAU;AACrC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,150 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { useMemo } from '@wordpress/element';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
|
-
import useQuerySelect from './use-query-select';
|
|
12
|
-
import { store as coreStore } from '../';
|
|
1
|
+
import { useDispatch, useSelect } from "@wordpress/data";
|
|
2
|
+
import deprecated from "@wordpress/deprecated";
|
|
3
|
+
import { useMemo } from "@wordpress/element";
|
|
4
|
+
import useQuerySelect from "./use-query-select";
|
|
5
|
+
import { store as coreStore } from "../";
|
|
13
6
|
const EMPTY_OBJECT = {};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* return record.title;
|
|
36
|
-
* }
|
|
37
|
-
*
|
|
38
|
-
* // Rendered in the application:
|
|
39
|
-
* // <PageTitleDisplay id={ 1 } />
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* In the above example, when `PageTitleDisplay` is rendered into an
|
|
43
|
-
* application, the page and the resolution details will be retrieved from
|
|
44
|
-
* the store state using `getEntityRecord()`, or resolved if missing.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```js
|
|
48
|
-
* import { useCallback } from 'react';
|
|
49
|
-
* import { useDispatch } from '@wordpress/data';
|
|
50
|
-
* import { __ } from '@wordpress/i18n';
|
|
51
|
-
* import { TextControl } from '@wordpress/components';
|
|
52
|
-
* import { store as noticeStore } from '@wordpress/notices';
|
|
53
|
-
* import { useEntityRecord } from '@wordpress/core-data';
|
|
54
|
-
*
|
|
55
|
-
* function PageRenameForm( { id } ) {
|
|
56
|
-
* const page = useEntityRecord( 'postType', 'page', id );
|
|
57
|
-
* const { createSuccessNotice, createErrorNotice } =
|
|
58
|
-
* useDispatch( noticeStore );
|
|
59
|
-
*
|
|
60
|
-
* const setTitle = useCallback( ( title ) => {
|
|
61
|
-
* page.edit( { title } );
|
|
62
|
-
* }, [ page.edit ] );
|
|
63
|
-
*
|
|
64
|
-
* if ( page.isResolving ) {
|
|
65
|
-
* return 'Loading...';
|
|
66
|
-
* }
|
|
67
|
-
*
|
|
68
|
-
* async function onRename( event ) {
|
|
69
|
-
* event.preventDefault();
|
|
70
|
-
* try {
|
|
71
|
-
* await page.save();
|
|
72
|
-
* createSuccessNotice( __( 'Page renamed.' ), {
|
|
73
|
-
* type: 'snackbar',
|
|
74
|
-
* } );
|
|
75
|
-
* } catch ( error ) {
|
|
76
|
-
* createErrorNotice( error.message, { type: 'snackbar' } );
|
|
77
|
-
* }
|
|
78
|
-
* }
|
|
79
|
-
*
|
|
80
|
-
* return (
|
|
81
|
-
* <form onSubmit={ onRename }>
|
|
82
|
-
* <TextControl
|
|
83
|
-
* __nextHasNoMarginBottom
|
|
84
|
-
* __next40pxDefaultSize
|
|
85
|
-
* label={ __( 'Name' ) }
|
|
86
|
-
* value={ page.editedRecord.title }
|
|
87
|
-
* onChange={ setTitle }
|
|
88
|
-
* />
|
|
89
|
-
* <button type="submit">{ __( 'Save' ) }</button>
|
|
90
|
-
* </form>
|
|
91
|
-
* );
|
|
92
|
-
* }
|
|
93
|
-
*
|
|
94
|
-
* // Rendered in the application:
|
|
95
|
-
* // <PageRenameForm id={ 1 } />
|
|
96
|
-
* ```
|
|
97
|
-
*
|
|
98
|
-
* In the above example, updating and saving the page title is handled
|
|
99
|
-
* via the `edit()` and `save()` mutation helpers provided by
|
|
100
|
-
* `useEntityRecord()`;
|
|
101
|
-
*
|
|
102
|
-
* @return Entity record data.
|
|
103
|
-
* @template RecordType
|
|
104
|
-
*/
|
|
105
|
-
export default function useEntityRecord(kind, name, recordId, options = {
|
|
106
|
-
enabled: true
|
|
107
|
-
}) {
|
|
108
|
-
const {
|
|
109
|
-
editEntityRecord,
|
|
110
|
-
saveEditedEntityRecord
|
|
111
|
-
} = useDispatch(coreStore);
|
|
112
|
-
const mutations = useMemo(() => ({
|
|
113
|
-
edit: (record, editOptions = {}) => editEntityRecord(kind, name, recordId, record, editOptions),
|
|
114
|
-
save: (saveOptions = {}) => saveEditedEntityRecord(kind, name, recordId, {
|
|
115
|
-
throwOnError: true,
|
|
116
|
-
...saveOptions
|
|
117
|
-
})
|
|
118
|
-
}), [editEntityRecord, kind, name, recordId, saveEditedEntityRecord]);
|
|
119
|
-
const {
|
|
120
|
-
editedRecord,
|
|
121
|
-
hasEdits,
|
|
122
|
-
edits
|
|
123
|
-
} = useSelect(select => {
|
|
124
|
-
if (!options.enabled) {
|
|
125
|
-
return {
|
|
126
|
-
editedRecord: EMPTY_OBJECT,
|
|
127
|
-
hasEdits: false,
|
|
128
|
-
edits: EMPTY_OBJECT
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
editedRecord: select(coreStore).getEditedEntityRecord(kind, name, recordId),
|
|
133
|
-
hasEdits: select(coreStore).hasEditsForEntityRecord(kind, name, recordId),
|
|
134
|
-
edits: select(coreStore).getEntityRecordNonTransientEdits(kind, name, recordId)
|
|
135
|
-
};
|
|
136
|
-
}, [kind, name, recordId, options.enabled]);
|
|
137
|
-
const {
|
|
138
|
-
data: record,
|
|
139
|
-
...querySelectRest
|
|
140
|
-
} = useQuerySelect(query => {
|
|
141
|
-
if (!options.enabled) {
|
|
7
|
+
function useEntityRecord(kind, name, recordId, options = { enabled: true }) {
|
|
8
|
+
const { editEntityRecord, saveEditedEntityRecord } = useDispatch(coreStore);
|
|
9
|
+
const mutations = useMemo(
|
|
10
|
+
() => ({
|
|
11
|
+
edit: (record2, editOptions = {}) => editEntityRecord(kind, name, recordId, record2, editOptions),
|
|
12
|
+
save: (saveOptions = {}) => saveEditedEntityRecord(kind, name, recordId, {
|
|
13
|
+
throwOnError: true,
|
|
14
|
+
...saveOptions
|
|
15
|
+
})
|
|
16
|
+
}),
|
|
17
|
+
[editEntityRecord, kind, name, recordId, saveEditedEntityRecord]
|
|
18
|
+
);
|
|
19
|
+
const { editedRecord, hasEdits, edits } = useSelect(
|
|
20
|
+
(select) => {
|
|
21
|
+
if (!options.enabled) {
|
|
22
|
+
return {
|
|
23
|
+
editedRecord: EMPTY_OBJECT,
|
|
24
|
+
hasEdits: false,
|
|
25
|
+
edits: EMPTY_OBJECT
|
|
26
|
+
};
|
|
27
|
+
}
|
|
142
28
|
return {
|
|
143
|
-
|
|
29
|
+
editedRecord: select(coreStore).getEditedEntityRecord(
|
|
30
|
+
kind,
|
|
31
|
+
name,
|
|
32
|
+
recordId
|
|
33
|
+
),
|
|
34
|
+
hasEdits: select(coreStore).hasEditsForEntityRecord(
|
|
35
|
+
kind,
|
|
36
|
+
name,
|
|
37
|
+
recordId
|
|
38
|
+
),
|
|
39
|
+
edits: select(coreStore).getEntityRecordNonTransientEdits(
|
|
40
|
+
kind,
|
|
41
|
+
name,
|
|
42
|
+
recordId
|
|
43
|
+
)
|
|
144
44
|
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
45
|
+
},
|
|
46
|
+
[kind, name, recordId, options.enabled]
|
|
47
|
+
);
|
|
48
|
+
const { data: record, ...querySelectRest } = useQuerySelect(
|
|
49
|
+
(query) => {
|
|
50
|
+
if (!options.enabled) {
|
|
51
|
+
return {
|
|
52
|
+
data: null
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return query(coreStore).getEntityRecord(kind, name, recordId);
|
|
56
|
+
},
|
|
57
|
+
[kind, name, recordId, options.enabled]
|
|
58
|
+
);
|
|
148
59
|
return {
|
|
149
60
|
record,
|
|
150
61
|
editedRecord,
|
|
@@ -154,11 +65,15 @@ export default function useEntityRecord(kind, name, recordId, options = {
|
|
|
154
65
|
...mutations
|
|
155
66
|
};
|
|
156
67
|
}
|
|
157
|
-
|
|
68
|
+
function __experimentalUseEntityRecord(kind, name, recordId, options) {
|
|
158
69
|
deprecated(`wp.data.__experimentalUseEntityRecord`, {
|
|
159
|
-
alternative:
|
|
160
|
-
since:
|
|
70
|
+
alternative: "wp.data.useEntityRecord",
|
|
71
|
+
since: "6.1"
|
|
161
72
|
});
|
|
162
73
|
return useEntityRecord(kind, name, recordId, options);
|
|
163
74
|
}
|
|
164
|
-
|
|
75
|
+
export {
|
|
76
|
+
__experimentalUseEntityRecord,
|
|
77
|
+
useEntityRecord as default
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=use-entity-record.js.map
|