@wordpress/core-data 7.32.0 → 7.32.1-next.ff1cebbba.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/actions.js +375 -632
- package/build/actions.js.map +7 -1
- package/build/batch/create-batch.js +49 -62
- package/build/batch/create-batch.js.map +7 -1
- package/build/batch/default-processor.js +43 -39
- package/build/batch/default-processor.js.map +7 -1
- package/build/batch/index.js +38 -17
- package/build/batch/index.js.map +7 -1
- package/build/dynamic-entities.js +30 -32
- package/build/dynamic-entities.js.map +7 -1
- package/build/entities.js +298 -410
- package/build/entities.js.map +7 -1
- package/build/entity-context.js +29 -12
- package/build/entity-context.js.map +7 -1
- package/build/entity-provider.js +38 -46
- package/build/entity-provider.js.map +7 -1
- package/build/entity-types/attachment.js +16 -5
- package/build/entity-types/attachment.js.map +7 -1
- package/build/entity-types/base-entity-records.js +16 -42
- package/build/entity-types/base-entity-records.js.map +7 -1
- package/build/entity-types/base.js +16 -5
- package/build/entity-types/base.js.map +7 -1
- package/build/entity-types/comment.js +16 -5
- package/build/entity-types/comment.js.map +7 -1
- package/build/entity-types/global-styles-revision.js +16 -5
- package/build/entity-types/global-styles-revision.js.map +7 -1
- package/build/entity-types/helpers.js +16 -5
- package/build/entity-types/helpers.js.map +7 -1
- package/build/entity-types/index.js +16 -5
- package/build/entity-types/index.js.map +7 -1
- package/build/entity-types/menu-location.js +16 -5
- package/build/entity-types/menu-location.js.map +7 -1
- package/build/entity-types/nav-menu-item.js +16 -5
- package/build/entity-types/nav-menu-item.js.map +7 -1
- package/build/entity-types/nav-menu.js +16 -5
- package/build/entity-types/nav-menu.js.map +7 -1
- package/build/entity-types/page.js +16 -5
- package/build/entity-types/page.js.map +7 -1
- package/build/entity-types/plugin.js +16 -5
- package/build/entity-types/plugin.js.map +7 -1
- package/build/entity-types/post-revision.js +16 -5
- package/build/entity-types/post-revision.js.map +7 -1
- package/build/entity-types/post-status.js +16 -5
- package/build/entity-types/post-status.js.map +7 -1
- package/build/entity-types/post.js +16 -5
- package/build/entity-types/post.js.map +7 -1
- package/build/entity-types/settings.js +16 -5
- package/build/entity-types/settings.js.map +7 -1
- package/build/entity-types/sidebar.js +16 -5
- package/build/entity-types/sidebar.js.map +7 -1
- package/build/entity-types/taxonomy.js +16 -5
- package/build/entity-types/taxonomy.js.map +7 -1
- package/build/entity-types/term.js +16 -5
- package/build/entity-types/term.js.map +7 -1
- package/build/entity-types/theme.js +16 -5
- package/build/entity-types/theme.js.map +7 -1
- package/build/entity-types/type.js +16 -5
- package/build/entity-types/type.js.map +7 -1
- package/build/entity-types/user.js +16 -5
- package/build/entity-types/user.js.map +7 -1
- package/build/entity-types/widget-type.js +16 -5
- package/build/entity-types/widget-type.js.map +7 -1
- package/build/entity-types/widget.js +16 -5
- package/build/entity-types/widget.js.map +7 -1
- package/build/entity-types/wp-template-part.js +16 -5
- package/build/entity-types/wp-template-part.js.map +7 -1
- package/build/entity-types/wp-template.js +16 -5
- package/build/entity-types/wp-template.js.map +7 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js +141 -154
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +7 -1
- package/build/fetch/__experimental-fetch-url-data.js +47 -59
- package/build/fetch/__experimental-fetch-url-data.js.map +7 -1
- package/build/fetch/index.js +53 -32
- package/build/fetch/index.js.map +7 -1
- package/build/footnotes/get-footnotes-order.js +38 -25
- package/build/footnotes/get-footnotes-order.js.map +7 -1
- package/build/footnotes/get-rich-text-values-cached.js +26 -27
- package/build/footnotes/get-rich-text-values-cached.js.map +7 -1
- package/build/footnotes/index.js +68 -55
- package/build/footnotes/index.js.map +7 -1
- package/build/hooks/constants.js +33 -12
- package/build/hooks/constants.js.map +7 -1
- package/build/hooks/index.js +59 -68
- package/build/hooks/index.js.map +7 -1
- package/build/hooks/memoize.js +34 -12
- package/build/hooks/memoize.js.map +7 -1
- package/build/hooks/use-entity-block-editor.js +111 -119
- package/build/hooks/use-entity-block-editor.js.map +7 -1
- package/build/hooks/use-entity-id.js +25 -23
- package/build/hooks/use-entity-id.js.map +7 -1
- package/build/hooks/use-entity-prop.js +59 -60
- package/build/hooks/use-entity-prop.js.map +7 -1
- package/build/hooks/use-entity-record.js +95 -155
- package/build/hooks/use-entity-record.js.map +7 -1
- package/build/hooks/use-entity-records.js +131 -139
- package/build/hooks/use-entity-records.js.map +7 -1
- package/build/hooks/use-query-select.js +65 -84
- package/build/hooks/use-query-select.js.map +7 -1
- package/build/hooks/use-resource-permissions.js +92 -145
- package/build/hooks/use-resource-permissions.js.map +7 -1
- package/build/index.js +96 -153
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -14
- package/build/lock-unlock.js.map +7 -1
- package/build/locks/actions.js +36 -19
- package/build/locks/actions.js.map +7 -1
- package/build/locks/engine.js +48 -47
- package/build/locks/engine.js.map +7 -1
- package/build/locks/reducer.js +54 -63
- package/build/locks/reducer.js.map +7 -1
- package/build/locks/selectors.js +35 -30
- package/build/locks/selectors.js.map +7 -1
- package/build/locks/utils.js +37 -16
- package/build/locks/utils.js.map +7 -1
- package/build/name.js +27 -12
- package/build/name.js.map +7 -1
- package/build/private-actions.js +67 -75
- package/build/private-actions.js.map +7 -1
- package/build/private-apis.js +33 -16
- package/build/private-apis.js.map +7 -1
- package/build/private-selectors.js +204 -184
- package/build/private-selectors.js.map +7 -1
- package/build/queried-data/actions.js +32 -41
- package/build/queried-data/actions.js.map +7 -1
- package/build/queried-data/get-query-parts.js +41 -79
- package/build/queried-data/get-query-parts.js.map +7 -1
- package/build/queried-data/index.js +39 -36
- package/build/queried-data/index.js.map +7 -1
- package/build/queried-data/reducer.js +162 -193
- package/build/queried-data/reducer.js.map +7 -1
- package/build/queried-data/selectors.js +57 -85
- package/build/queried-data/selectors.js.map +7 -1
- package/build/reducer.js +279 -404
- package/build/reducer.js.map +7 -1
- package/build/resolvers.js +553 -600
- package/build/resolvers.js.map +7 -1
- package/build/selectors.js +456 -981
- package/build/selectors.js.map +7 -1
- package/build/sync.js +34 -22
- package/build/sync.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build/utils/conservative-map-item.js +34 -27
- package/build/utils/conservative-map-item.js.map +7 -1
- package/build/utils/crdt-blocks.js +289 -0
- package/build/utils/crdt-blocks.js.map +7 -0
- package/build/utils/crdt.js +202 -0
- package/build/utils/crdt.js.map +7 -0
- package/build/utils/forward-resolver.js +24 -16
- package/build/utils/forward-resolver.js.map +7 -1
- package/build/utils/get-nested-value.js +26 -21
- package/build/utils/get-nested-value.js.map +7 -1
- package/build/utils/get-normalized-comma-separable.js +25 -17
- package/build/utils/get-normalized-comma-separable.js.map +7 -1
- package/build/utils/if-matching-action.js +25 -19
- package/build/utils/if-matching-action.js.map +7 -1
- package/build/utils/index.js +77 -108
- package/build/utils/index.js.map +7 -1
- package/build/utils/is-numeric-id.js +22 -12
- package/build/utils/is-numeric-id.js.map +7 -1
- package/build/utils/is-raw-attribute.js +22 -13
- package/build/utils/is-raw-attribute.js.map +7 -1
- package/build/utils/log-entity-deprecation.js +37 -38
- package/build/utils/log-entity-deprecation.js.map +7 -1
- package/build/utils/on-sub-key.js +30 -24
- package/build/utils/on-sub-key.js.map +7 -1
- package/build/utils/receive-intermediate-results.js +29 -6
- package/build/utils/receive-intermediate-results.js.map +7 -1
- package/build/utils/replace-action.js +24 -17
- package/build/utils/replace-action.js.map +7 -1
- package/build/utils/set-nested-value.js +25 -30
- package/build/utils/set-nested-value.js.map +7 -1
- package/build/utils/user-permissions.js +41 -13
- package/build/utils/user-permissions.js.map +7 -1
- package/build/utils/with-weak-map-cache.js +26 -22
- package/build/utils/with-weak-map-cache.js.map +7 -1
- package/build-module/actions.js +322 -601
- package/build-module/actions.js.map +7 -1
- package/build-module/batch/create-batch.js +21 -57
- package/build-module/batch/create-batch.js.map +7 -1
- package/build-module/batch/default-processor.js +14 -33
- package/build-module/batch/default-processor.js.map +7 -1
- package/build-module/batch/index.js +7 -3
- package/build-module/batch/index.js.map +7 -1
- package/build-module/dynamic-entities.js +7 -28
- package/build-module/dynamic-entities.js.map +7 -1
- package/build-module/entities.js +263 -399
- package/build-module/entities.js.map +7 -1
- package/build-module/entity-context.js +7 -7
- package/build-module/entity-context.js.map +7 -1
- package/build-module/entity-provider.js +19 -42
- package/build-module/entity-provider.js.map +7 -1
- package/build-module/entity-types/attachment.js +1 -2
- package/build-module/entity-types/attachment.js.map +7 -1
- package/build-module/entity-types/base-entity-records.js +1 -37
- package/build-module/entity-types/base-entity-records.js.map +7 -1
- package/build-module/entity-types/base.js +1 -2
- package/build-module/entity-types/base.js.map +7 -1
- package/build-module/entity-types/comment.js +1 -2
- package/build-module/entity-types/comment.js.map +7 -1
- package/build-module/entity-types/global-styles-revision.js +1 -2
- package/build-module/entity-types/global-styles-revision.js.map +7 -1
- package/build-module/entity-types/helpers.js +1 -2
- package/build-module/entity-types/helpers.js.map +7 -1
- package/build-module/entity-types/index.js +1 -2
- package/build-module/entity-types/index.js.map +7 -1
- package/build-module/entity-types/menu-location.js +1 -2
- package/build-module/entity-types/menu-location.js.map +7 -1
- package/build-module/entity-types/nav-menu-item.js +1 -2
- package/build-module/entity-types/nav-menu-item.js.map +7 -1
- package/build-module/entity-types/nav-menu.js +1 -2
- package/build-module/entity-types/nav-menu.js.map +7 -1
- package/build-module/entity-types/page.js +1 -2
- package/build-module/entity-types/page.js.map +7 -1
- package/build-module/entity-types/plugin.js +1 -2
- package/build-module/entity-types/plugin.js.map +7 -1
- package/build-module/entity-types/post-revision.js +1 -2
- package/build-module/entity-types/post-revision.js.map +7 -1
- package/build-module/entity-types/post-status.js +1 -2
- package/build-module/entity-types/post-status.js.map +7 -1
- package/build-module/entity-types/post.js +1 -2
- package/build-module/entity-types/post.js.map +7 -1
- package/build-module/entity-types/settings.js +1 -2
- package/build-module/entity-types/settings.js.map +7 -1
- package/build-module/entity-types/sidebar.js +1 -2
- package/build-module/entity-types/sidebar.js.map +7 -1
- package/build-module/entity-types/taxonomy.js +1 -2
- package/build-module/entity-types/taxonomy.js.map +7 -1
- package/build-module/entity-types/term.js +1 -2
- package/build-module/entity-types/term.js.map +7 -1
- package/build-module/entity-types/theme.js +1 -2
- package/build-module/entity-types/theme.js.map +7 -1
- package/build-module/entity-types/type.js +1 -2
- package/build-module/entity-types/type.js.map +7 -1
- package/build-module/entity-types/user.js +1 -2
- package/build-module/entity-types/user.js.map +7 -1
- package/build-module/entity-types/widget-type.js +1 -2
- package/build-module/entity-types/widget-type.js.map +7 -1
- package/build-module/entity-types/widget.js +1 -2
- package/build-module/entity-types/widget.js.map +7 -1
- package/build-module/entity-types/wp-template-part.js +1 -2
- package/build-module/entity-types/wp-template-part.js.map +7 -1
- package/build-module/entity-types/wp-template.js +1 -2
- package/build-module/entity-types/wp-template.js.map +7 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +111 -149
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +7 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +20 -49
- package/build-module/fetch/__experimental-fetch-url-data.js.map +7 -1
- package/build-module/fetch/index.js +20 -15
- package/build-module/fetch/index.js.map +7 -1
- package/build-module/footnotes/get-footnotes-order.js +10 -19
- package/build-module/footnotes/get-footnotes-order.js.map +7 -1
- package/build-module/footnotes/get-rich-text-values-cached.js +8 -23
- package/build-module/footnotes/get-rich-text-values-cached.js.map +7 -1
- package/build-module/footnotes/index.js +34 -47
- package/build-module/footnotes/index.js.map +7 -1
- package/build-module/hooks/constants.js +11 -8
- package/build-module/hooks/constants.js.map +7 -1
- package/build-module/hooks/index.js +27 -15
- package/build-module/hooks/index.js.map +7 -1
- package/build-module/hooks/memoize.js +6 -8
- package/build-module/hooks/memoize.js.map +7 -1
- package/build-module/hooks/use-entity-block-editor.js +80 -110
- package/build-module/hooks/use-entity-block-editor.js.map +7 -1
- package/build-module/hooks/use-entity-id.js +7 -19
- package/build-module/hooks/use-entity-id.js.map +7 -1
- package/build-module/hooks/use-entity-prop.js +31 -55
- package/build-module/hooks/use-entity-prop.js.map +7 -1
- package/build-module/hooks/use-entity-record.js +63 -148
- package/build-module/hooks/use-entity-record.js.map +7 -1
- package/build-module/hooks/use-entity-records.js +98 -131
- package/build-module/hooks/use-entity-records.js.map +7 -1
- package/build-module/hooks/use-query-select.js +27 -71
- package/build-module/hooks/use-query-select.js.map +7 -1
- package/build-module/hooks/use-resource-permissions.js +57 -136
- package/build-module/hooks/use-resource-permissions.js.map +7 -1
- package/build-module/index.js +49 -71
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/locks/actions.js +8 -13
- package/build-module/locks/actions.js.map +7 -1
- package/build-module/locks/engine.js +17 -38
- package/build-module/locks/engine.js.map +7 -1
- package/build-module/locks/reducer.js +37 -59
- package/build-module/locks/reducer.js.map +7 -1
- package/build-module/locks/selectors.js +16 -23
- package/build-module/locks/selectors.js.map +7 -1
- package/build-module/locks/utils.js +15 -12
- package/build-module/locks/utils.js.map +7 -1
- package/build-module/name.js +5 -8
- package/build-module/name.js.map +7 -1
- package/build-module/private-actions.js +35 -69
- package/build-module/private-actions.js.map +7 -1
- package/build-module/private-apis.js +8 -8
- package/build-module/private-apis.js.map +7 -1
- package/build-module/private-selectors.js +167 -174
- package/build-module/private-selectors.js.map +7 -1
- package/build-module/queried-data/actions.js +11 -38
- package/build-module/queried-data/actions.js.map +7 -1
- package/build-module/queried-data/get-query-parts.js +20 -75
- package/build-module/queried-data/get-query-parts.js.map +7 -1
- package/build-module/queried-data/index.js +7 -4
- package/build-module/queried-data/index.js.map +7 -1
- package/build-module/queried-data/reducer.js +134 -185
- package/build-module/queried-data/reducer.js.map +7 -1
- package/build-module/queried-data/selectors.js +23 -78
- package/build-module/queried-data/selectors.js.map +7 -1
- package/build-module/reducer.js +243 -393
- package/build-module/reducer.js.map +7 -1
- package/build-module/resolvers.js +478 -549
- package/build-module/resolvers.js.map +7 -1
- package/build-module/selectors.js +410 -953
- package/build-module/selectors.js.map +7 -1
- package/build-module/sync.js +14 -17
- package/build-module/sync.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/build-module/utils/conservative-map-item.js +6 -22
- package/build-module/utils/conservative-map-item.js.map +7 -1
- package/build-module/utils/crdt-blocks.js +255 -0
- package/build-module/utils/crdt-blocks.js.map +7 -0
- package/build-module/utils/crdt.js +167 -0
- package/build-module/utils/crdt.js.map +7 -0
- package/build-module/utils/forward-resolver.js +6 -12
- package/build-module/utils/forward-resolver.js.map +7 -1
- package/build-module/utils/get-nested-value.js +9 -18
- package/build-module/utils/get-nested-value.js.map +7 -1
- package/build-module/utils/get-normalized-comma-separable.js +7 -13
- package/build-module/utils/get-normalized-comma-separable.js.map +7 -1
- package/build-module/utils/if-matching-action.js +7 -15
- package/build-module/utils/if-matching-action.js.map +7 -1
- package/build-module/utils/index.js +35 -14
- package/build-module/utils/index.js.map +7 -1
- package/build-module/utils/is-numeric-id.js +5 -9
- package/build-module/utils/is-numeric-id.js.map +7 -1
- package/build-module/utils/is-raw-attribute.js +5 -10
- package/build-module/utils/is-raw-attribute.js.map +7 -1
- package/build-module/utils/log-entity-deprecation.js +8 -31
- package/build-module/utils/log-entity-deprecation.js.map +7 -1
- package/build-module/utils/on-sub-key.js +8 -19
- package/build-module/utils/on-sub-key.js.map +7 -1
- package/build-module/utils/receive-intermediate-results.js +7 -2
- package/build-module/utils/receive-intermediate-results.js.map +7 -1
- package/build-module/utils/replace-action.js +6 -13
- package/build-module/utils/replace-action.js.map +7 -1
- package/build-module/utils/set-nested-value.js +8 -27
- package/build-module/utils/set-nested-value.js.map +7 -1
- package/build-module/utils/user-permissions.js +19 -9
- package/build-module/utils/user-permissions.js.map +7 -1
- package/build-module/utils/with-weak-map-cache.js +8 -18
- package/build-module/utils/with-weak-map-cache.js.map +7 -1
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/entities.d.ts +0 -56
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/private-selectors.d.ts.map +1 -1
- package/build-types/resolvers.d.ts +3 -0
- package/build-types/resolvers.d.ts.map +1 -1
- package/build-types/selectors.d.ts.map +1 -1
- package/build-types/sync.d.ts +6 -1
- package/build-types/sync.d.ts.map +1 -1
- package/build-types/types.d.ts +9 -0
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils/crdt-blocks.d.ts +30 -0
- package/build-types/utils/crdt-blocks.d.ts.map +1 -0
- package/build-types/utils/crdt.d.ts +49 -0
- package/build-types/utils/crdt.d.ts.map +1 -0
- package/package.json +26 -19
- package/src/actions.js +56 -74
- package/src/entities.js +59 -113
- package/src/private-selectors.ts +32 -7
- package/src/resolvers.js +173 -120
- package/src/selectors.ts +0 -13
- package/src/sync.ts +12 -0
- package/src/test/resolvers.js +183 -0
- package/src/types.ts +12 -0
- package/src/utils/crdt-blocks.ts +503 -0
- package/src/utils/crdt.ts +310 -0
- package/src/utils/test/crdt-blocks.ts +375 -0
- package/src/utils/test/crdt.ts +254 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/sync.js +0 -27
package/build-module/entities.js
CHANGED
|
@@ -1,472 +1,336 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
syncObjectType: 'root/base',
|
|
46
|
-
getSyncObjectId: () => 'index'
|
|
47
|
-
}, {
|
|
48
|
-
label: __('Post Type'),
|
|
49
|
-
name: 'postType',
|
|
50
|
-
kind: 'root',
|
|
51
|
-
key: 'slug',
|
|
52
|
-
baseURL: '/wp/v2/types',
|
|
53
|
-
baseURLParams: {
|
|
54
|
-
context: 'edit'
|
|
55
|
-
},
|
|
56
|
-
plural: 'postTypes',
|
|
57
|
-
syncConfig: {
|
|
58
|
-
fetch: async id => {
|
|
59
|
-
return apiFetch({
|
|
60
|
-
path: `/wp/v2/types/${id}?context=edit`
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
applyChangesToDoc: (doc, changes) => {
|
|
64
|
-
const document = doc.getMap('document');
|
|
65
|
-
Object.entries(changes).forEach(([key, value]) => {
|
|
66
|
-
if (document.get(key) !== value) {
|
|
67
|
-
document.set(key, value);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
1
|
+
import { capitalCase, pascalCase } from "change-case";
|
|
2
|
+
import apiFetch from "@wordpress/api-fetch";
|
|
3
|
+
import { __unstableSerializeAndClean, parse } from "@wordpress/blocks";
|
|
4
|
+
import { __ } from "@wordpress/i18n";
|
|
5
|
+
import {
|
|
6
|
+
applyPostChangesToCRDTDoc,
|
|
7
|
+
defaultApplyChangesToCRDTDoc,
|
|
8
|
+
defaultGetChangesFromCRDTDoc,
|
|
9
|
+
getPostChangesFromCRDTDoc
|
|
10
|
+
} from "./utils/crdt";
|
|
11
|
+
const DEFAULT_ENTITY_KEY = "id";
|
|
12
|
+
const POST_RAW_ATTRIBUTES = ["title", "excerpt", "content"];
|
|
13
|
+
const blocksTransientEdits = {
|
|
14
|
+
blocks: {
|
|
15
|
+
read: (record) => parse(record.content?.raw ?? ""),
|
|
16
|
+
write: (record) => ({
|
|
17
|
+
content: __unstableSerializeAndClean(record.blocks)
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const rootEntitiesConfig = [
|
|
22
|
+
{
|
|
23
|
+
label: __("Base"),
|
|
24
|
+
kind: "root",
|
|
25
|
+
name: "__unstableBase",
|
|
26
|
+
baseURL: "/",
|
|
27
|
+
baseURLParams: {
|
|
28
|
+
// Please also change the preload path when changing this.
|
|
29
|
+
// @see lib/compat/wordpress-6.8/preload.php
|
|
30
|
+
_fields: [
|
|
31
|
+
"description",
|
|
32
|
+
"gmt_offset",
|
|
33
|
+
"home",
|
|
34
|
+
"name",
|
|
35
|
+
"site_icon",
|
|
36
|
+
"site_icon_url",
|
|
37
|
+
"site_logo",
|
|
38
|
+
"timezone_string",
|
|
39
|
+
"url",
|
|
40
|
+
"page_for_posts",
|
|
41
|
+
"page_on_front",
|
|
42
|
+
"show_on_front"
|
|
43
|
+
].join(",")
|
|
70
44
|
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
},
|
|
75
|
-
syncObjectType: 'root/postType',
|
|
76
|
-
getSyncObjectId: id => id
|
|
77
|
-
}, {
|
|
78
|
-
name: 'media',
|
|
79
|
-
kind: 'root',
|
|
80
|
-
baseURL: '/wp/v2/media',
|
|
81
|
-
baseURLParams: {
|
|
82
|
-
context: 'edit'
|
|
83
|
-
},
|
|
84
|
-
plural: 'mediaItems',
|
|
85
|
-
label: __('Media'),
|
|
86
|
-
rawAttributes: ['caption', 'title', 'description'],
|
|
87
|
-
supportsPagination: true
|
|
88
|
-
}, {
|
|
89
|
-
name: 'taxonomy',
|
|
90
|
-
kind: 'root',
|
|
91
|
-
key: 'slug',
|
|
92
|
-
baseURL: '/wp/v2/taxonomies',
|
|
93
|
-
baseURLParams: {
|
|
94
|
-
context: 'edit'
|
|
45
|
+
// The entity doesn't support selecting multiple records.
|
|
46
|
+
// The property is maintained for backward compatibility.
|
|
47
|
+
plural: "__unstableBases"
|
|
95
48
|
},
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
49
|
+
{
|
|
50
|
+
label: __("Post Type"),
|
|
51
|
+
name: "postType",
|
|
52
|
+
kind: "root",
|
|
53
|
+
key: "slug",
|
|
54
|
+
baseURL: "/wp/v2/types",
|
|
55
|
+
baseURLParams: { context: "edit" },
|
|
56
|
+
plural: "postTypes"
|
|
104
57
|
},
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
58
|
+
{
|
|
59
|
+
name: "media",
|
|
60
|
+
kind: "root",
|
|
61
|
+
baseURL: "/wp/v2/media",
|
|
62
|
+
baseURLParams: { context: "edit" },
|
|
63
|
+
plural: "mediaItems",
|
|
64
|
+
label: __("Media"),
|
|
65
|
+
rawAttributes: ["caption", "title", "description"],
|
|
66
|
+
supportsPagination: true
|
|
108
67
|
},
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
68
|
+
{
|
|
69
|
+
name: "taxonomy",
|
|
70
|
+
kind: "root",
|
|
71
|
+
key: "slug",
|
|
72
|
+
baseURL: "/wp/v2/taxonomies",
|
|
73
|
+
baseURLParams: { context: "edit" },
|
|
74
|
+
plural: "taxonomies",
|
|
75
|
+
label: __("Taxonomy")
|
|
116
76
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
77
|
+
{
|
|
78
|
+
name: "sidebar",
|
|
79
|
+
kind: "root",
|
|
80
|
+
baseURL: "/wp/v2/sidebars",
|
|
81
|
+
baseURLParams: { context: "edit" },
|
|
82
|
+
plural: "sidebars",
|
|
83
|
+
transientEdits: { blocks: true },
|
|
84
|
+
label: __("Widget areas")
|
|
120
85
|
},
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
86
|
+
{
|
|
87
|
+
name: "widget",
|
|
88
|
+
kind: "root",
|
|
89
|
+
baseURL: "/wp/v2/widgets",
|
|
90
|
+
baseURLParams: { context: "edit" },
|
|
91
|
+
plural: "widgets",
|
|
92
|
+
transientEdits: { blocks: true },
|
|
93
|
+
label: __("Widgets")
|
|
128
94
|
},
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
getTitle: record => record?.name || record?.slug,
|
|
137
|
-
baseURLParams: {
|
|
138
|
-
context: 'edit'
|
|
95
|
+
{
|
|
96
|
+
name: "widgetType",
|
|
97
|
+
kind: "root",
|
|
98
|
+
baseURL: "/wp/v2/widget-types",
|
|
99
|
+
baseURLParams: { context: "edit" },
|
|
100
|
+
plural: "widgetTypes",
|
|
101
|
+
label: __("Widget types")
|
|
139
102
|
},
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
103
|
+
{
|
|
104
|
+
label: __("User"),
|
|
105
|
+
name: "user",
|
|
106
|
+
kind: "root",
|
|
107
|
+
baseURL: "/wp/v2/users",
|
|
108
|
+
getTitle: (record) => record?.name || record?.slug,
|
|
109
|
+
baseURLParams: { context: "edit" },
|
|
110
|
+
plural: "users",
|
|
111
|
+
supportsPagination: true
|
|
148
112
|
},
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
context: 'edit'
|
|
113
|
+
{
|
|
114
|
+
name: "comment",
|
|
115
|
+
kind: "root",
|
|
116
|
+
baseURL: "/wp/v2/comments",
|
|
117
|
+
baseURLParams: { context: "edit" },
|
|
118
|
+
plural: "comments",
|
|
119
|
+
label: __("Comment"),
|
|
120
|
+
supportsPagination: true
|
|
158
121
|
},
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
context: 'edit'
|
|
122
|
+
{
|
|
123
|
+
name: "menu",
|
|
124
|
+
kind: "root",
|
|
125
|
+
baseURL: "/wp/v2/menus",
|
|
126
|
+
baseURLParams: { context: "edit" },
|
|
127
|
+
plural: "menus",
|
|
128
|
+
label: __("Menu"),
|
|
129
|
+
supportsPagination: true
|
|
168
130
|
},
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
context: 'edit'
|
|
131
|
+
{
|
|
132
|
+
name: "menuItem",
|
|
133
|
+
kind: "root",
|
|
134
|
+
baseURL: "/wp/v2/menu-items",
|
|
135
|
+
baseURLParams: { context: "edit" },
|
|
136
|
+
plural: "menuItems",
|
|
137
|
+
label: __("Menu Item"),
|
|
138
|
+
rawAttributes: ["title"],
|
|
139
|
+
supportsPagination: true
|
|
179
140
|
},
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
baseURLParams: {
|
|
189
|
-
context: 'edit'
|
|
141
|
+
{
|
|
142
|
+
name: "menuLocation",
|
|
143
|
+
kind: "root",
|
|
144
|
+
baseURL: "/wp/v2/menu-locations",
|
|
145
|
+
baseURLParams: { context: "edit" },
|
|
146
|
+
plural: "menuLocations",
|
|
147
|
+
label: __("Menu Location"),
|
|
148
|
+
key: "name"
|
|
190
149
|
},
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
context: 'edit'
|
|
150
|
+
{
|
|
151
|
+
label: __("Global Styles"),
|
|
152
|
+
name: "globalStyles",
|
|
153
|
+
kind: "root",
|
|
154
|
+
baseURL: "/wp/v2/global-styles",
|
|
155
|
+
baseURLParams: { context: "edit" },
|
|
156
|
+
plural: "globalStylesVariations",
|
|
157
|
+
// Should be different from name.
|
|
158
|
+
getTitle: () => __("Custom Styles"),
|
|
159
|
+
getRevisionsUrl: (parentId, revisionId) => `/wp/v2/global-styles/${parentId}/revisions${revisionId ? "/" + revisionId : ""}`,
|
|
160
|
+
supportsPagination: true
|
|
203
161
|
},
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
context: 'edit'
|
|
162
|
+
{
|
|
163
|
+
label: __("Themes"),
|
|
164
|
+
name: "theme",
|
|
165
|
+
kind: "root",
|
|
166
|
+
baseURL: "/wp/v2/themes",
|
|
167
|
+
baseURLParams: { context: "edit" },
|
|
168
|
+
plural: "themes",
|
|
169
|
+
key: "stylesheet"
|
|
213
170
|
},
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
context: 'edit'
|
|
171
|
+
{
|
|
172
|
+
label: __("Plugins"),
|
|
173
|
+
name: "plugin",
|
|
174
|
+
kind: "root",
|
|
175
|
+
baseURL: "/wp/v2/plugins",
|
|
176
|
+
baseURLParams: { context: "edit" },
|
|
177
|
+
plural: "plugins",
|
|
178
|
+
key: "plugin"
|
|
223
179
|
},
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
180
|
+
{
|
|
181
|
+
label: __("Status"),
|
|
182
|
+
name: "status",
|
|
183
|
+
kind: "root",
|
|
184
|
+
baseURL: "/wp/v2/statuses",
|
|
185
|
+
baseURLParams: { context: "edit" },
|
|
186
|
+
plural: "statuses",
|
|
187
|
+
key: "slug"
|
|
188
|
+
}
|
|
189
|
+
];
|
|
190
|
+
const deprecatedEntities = {
|
|
228
191
|
root: {
|
|
229
192
|
media: {
|
|
230
|
-
since:
|
|
193
|
+
since: "6.9",
|
|
231
194
|
alternative: {
|
|
232
|
-
kind:
|
|
233
|
-
name:
|
|
195
|
+
kind: "postType",
|
|
196
|
+
name: "attachment"
|
|
234
197
|
}
|
|
235
198
|
}
|
|
236
199
|
}
|
|
237
200
|
};
|
|
238
|
-
|
|
239
|
-
kind:
|
|
240
|
-
loadEntities:
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}];
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Returns a function to be used to retrieve extra edits to apply before persisting a post type.
|
|
253
|
-
*
|
|
254
|
-
* @param {Object} persistedRecord Already persisted Post
|
|
255
|
-
* @param {Object} edits Edits.
|
|
256
|
-
* @return {Object} Updated edits.
|
|
257
|
-
*/
|
|
258
|
-
export const prePersistPostType = (persistedRecord, edits) => {
|
|
201
|
+
const additionalEntityConfigLoaders = [
|
|
202
|
+
{ kind: "postType", loadEntities: loadPostTypeEntities },
|
|
203
|
+
{ kind: "taxonomy", loadEntities: loadTaxonomyEntities },
|
|
204
|
+
{
|
|
205
|
+
kind: "root",
|
|
206
|
+
name: "site",
|
|
207
|
+
plural: "sites",
|
|
208
|
+
loadEntities: loadSiteEntity
|
|
209
|
+
}
|
|
210
|
+
];
|
|
211
|
+
const prePersistPostType = (persistedRecord, edits) => {
|
|
259
212
|
const newEdits = {};
|
|
260
|
-
if (persistedRecord?.status ===
|
|
261
|
-
// Saving an auto-draft should create a draft by default.
|
|
213
|
+
if (persistedRecord?.status === "auto-draft") {
|
|
262
214
|
if (!edits.status && !newEdits.status) {
|
|
263
|
-
newEdits.status =
|
|
215
|
+
newEdits.status = "draft";
|
|
264
216
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if ((!edits.title || edits.title === 'Auto Draft') && !newEdits.title && (!persistedRecord?.title || persistedRecord?.title === 'Auto Draft')) {
|
|
268
|
-
newEdits.title = '';
|
|
217
|
+
if ((!edits.title || edits.title === "Auto Draft") && !newEdits.title && (!persistedRecord?.title || persistedRecord?.title === "Auto Draft")) {
|
|
218
|
+
newEdits.title = "";
|
|
269
219
|
}
|
|
270
220
|
}
|
|
271
221
|
return newEdits;
|
|
272
222
|
};
|
|
273
|
-
const serialisableBlocksCache = new WeakMap();
|
|
274
|
-
function makeBlockAttributesSerializable(attributes) {
|
|
275
|
-
const newAttributes = {
|
|
276
|
-
...attributes
|
|
277
|
-
};
|
|
278
|
-
for (const [key, value] of Object.entries(attributes)) {
|
|
279
|
-
if (value instanceof RichTextData) {
|
|
280
|
-
newAttributes[key] = value.valueOf();
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return newAttributes;
|
|
284
|
-
}
|
|
285
|
-
function makeBlocksSerializable(blocks) {
|
|
286
|
-
return blocks.map(block => {
|
|
287
|
-
const {
|
|
288
|
-
innerBlocks,
|
|
289
|
-
attributes,
|
|
290
|
-
...rest
|
|
291
|
-
} = block;
|
|
292
|
-
return {
|
|
293
|
-
...rest,
|
|
294
|
-
attributes: makeBlockAttributesSerializable(attributes),
|
|
295
|
-
innerBlocks: makeBlocksSerializable(innerBlocks)
|
|
296
|
-
};
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Returns the list of post type entities.
|
|
302
|
-
*
|
|
303
|
-
* @return {Promise} Entities promise
|
|
304
|
-
*/
|
|
305
223
|
async function loadPostTypeEntities() {
|
|
306
224
|
const postTypes = await apiFetch({
|
|
307
|
-
path:
|
|
225
|
+
path: "/wp/v2/types?context=view"
|
|
308
226
|
});
|
|
309
|
-
return Object.entries(postTypes
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
227
|
+
return Object.entries(postTypes ?? {}).map(([name, postType]) => {
|
|
228
|
+
const isTemplate = ["wp_template", "wp_template_part"].includes(
|
|
229
|
+
name
|
|
230
|
+
);
|
|
231
|
+
const namespace = postType?.rest_namespace ?? "wp/v2";
|
|
232
|
+
const syncConfig = {
|
|
233
|
+
/**
|
|
234
|
+
* Apply changes from the local editor to the local CRDT document so
|
|
235
|
+
* that those changes can be synced to other peers (via the provider).
|
|
236
|
+
*
|
|
237
|
+
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
|
|
238
|
+
* @param {Partial< import('@wordpress/sync').ObjectData >} changes
|
|
239
|
+
* @return {void}
|
|
240
|
+
*/
|
|
241
|
+
applyChangesToCRDTDoc: (crdtDoc, changes) => applyPostChangesToCRDTDoc(crdtDoc, changes, postType),
|
|
242
|
+
/**
|
|
243
|
+
* Extract changes from a CRDT document that can be used to update the
|
|
244
|
+
* local editor state.
|
|
245
|
+
*
|
|
246
|
+
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
|
|
247
|
+
* @param {import('@wordpress/sync').ObjectData} editedRecord
|
|
248
|
+
* @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record
|
|
249
|
+
*/
|
|
250
|
+
getChangesFromCRDTDoc: (crdtDoc, editedRecord) => getPostChangesFromCRDTDoc(crdtDoc, editedRecord, postType),
|
|
251
|
+
/**
|
|
252
|
+
* Sync features supported by the entity.
|
|
253
|
+
*
|
|
254
|
+
* @type {Record< string, boolean >}
|
|
255
|
+
*/
|
|
256
|
+
supports: {}
|
|
257
|
+
};
|
|
313
258
|
return {
|
|
314
|
-
kind:
|
|
259
|
+
kind: "postType",
|
|
315
260
|
baseURL: `/${namespace}/${postType.rest_base}`,
|
|
316
|
-
baseURLParams: {
|
|
317
|
-
context: 'edit'
|
|
318
|
-
},
|
|
261
|
+
baseURLParams: { context: "edit" },
|
|
319
262
|
name,
|
|
320
263
|
label: postType.name,
|
|
321
264
|
transientEdits: {
|
|
322
|
-
|
|
265
|
+
...blocksTransientEdits,
|
|
323
266
|
selection: true
|
|
324
267
|
},
|
|
325
|
-
mergedEdits: {
|
|
326
|
-
meta: true
|
|
327
|
-
},
|
|
268
|
+
mergedEdits: { meta: true },
|
|
328
269
|
rawAttributes: POST_RAW_ATTRIBUTES,
|
|
329
|
-
getTitle: record =>
|
|
330
|
-
|
|
331
|
-
return record?.title?.rendered || record?.title || (isTemplate ? capitalCase((_record$slug = record.slug) !== null && _record$slug !== void 0 ? _record$slug : '') : String(record.id));
|
|
332
|
-
},
|
|
333
|
-
__unstablePrePersist: isTemplate ? undefined : prePersistPostType,
|
|
270
|
+
getTitle: (record) => record?.title?.rendered || record?.title || (isTemplate ? capitalCase(record.slug ?? "") : String(record.id)),
|
|
271
|
+
__unstablePrePersist: isTemplate ? void 0 : prePersistPostType,
|
|
334
272
|
__unstable_rest_base: postType.rest_base,
|
|
335
|
-
syncConfig
|
|
336
|
-
fetch: async id => {
|
|
337
|
-
return apiFetch({
|
|
338
|
-
path: `/${namespace}/${postType.rest_base}/${id}?context=edit`
|
|
339
|
-
});
|
|
340
|
-
},
|
|
341
|
-
applyChangesToDoc: (doc, changes) => {
|
|
342
|
-
const document = doc.getMap('document');
|
|
343
|
-
Object.entries(changes).forEach(([key, value]) => {
|
|
344
|
-
if (typeof value !== 'function') {
|
|
345
|
-
if (key === 'blocks') {
|
|
346
|
-
if (!serialisableBlocksCache.has(value)) {
|
|
347
|
-
serialisableBlocksCache.set(value, makeBlocksSerializable(value));
|
|
348
|
-
}
|
|
349
|
-
value = serialisableBlocksCache.get(value);
|
|
350
|
-
}
|
|
351
|
-
if (document.get(key) !== value) {
|
|
352
|
-
document.set(key, value);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
},
|
|
357
|
-
fromCRDTDoc: doc => {
|
|
358
|
-
return doc.getMap('document').toJSON();
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
syncObjectType: 'postType/' + postType.name,
|
|
362
|
-
getSyncObjectId: id => id,
|
|
273
|
+
syncConfig,
|
|
363
274
|
supportsPagination: true,
|
|
364
|
-
getRevisionsUrl: (parentId, revisionId) => `/${namespace}/${postType.rest_base}/${parentId}/revisions${revisionId ?
|
|
275
|
+
getRevisionsUrl: (parentId, revisionId) => `/${namespace}/${postType.rest_base}/${parentId}/revisions${revisionId ? "/" + revisionId : ""}`,
|
|
365
276
|
revisionKey: DEFAULT_ENTITY_KEY
|
|
366
277
|
};
|
|
367
278
|
});
|
|
368
279
|
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Returns the list of the taxonomies entities.
|
|
372
|
-
*
|
|
373
|
-
* @return {Promise} Entities promise
|
|
374
|
-
*/
|
|
375
280
|
async function loadTaxonomyEntities() {
|
|
376
281
|
const taxonomies = await apiFetch({
|
|
377
|
-
path:
|
|
282
|
+
path: "/wp/v2/taxonomies?context=view"
|
|
378
283
|
});
|
|
379
|
-
return Object.entries(taxonomies
|
|
380
|
-
|
|
381
|
-
const namespace = (_taxonomy$rest_namesp = taxonomy?.rest_namespace) !== null && _taxonomy$rest_namesp !== void 0 ? _taxonomy$rest_namesp : 'wp/v2';
|
|
284
|
+
return Object.entries(taxonomies ?? {}).map(([name, taxonomy]) => {
|
|
285
|
+
const namespace = taxonomy?.rest_namespace ?? "wp/v2";
|
|
382
286
|
return {
|
|
383
|
-
kind:
|
|
287
|
+
kind: "taxonomy",
|
|
384
288
|
baseURL: `/${namespace}/${taxonomy.rest_base}`,
|
|
385
|
-
baseURLParams: {
|
|
386
|
-
context: 'edit'
|
|
387
|
-
},
|
|
289
|
+
baseURLParams: { context: "edit" },
|
|
388
290
|
name,
|
|
389
291
|
label: taxonomy.name,
|
|
390
|
-
getTitle: record => record?.name,
|
|
292
|
+
getTitle: (record) => record?.name,
|
|
391
293
|
supportsPagination: true
|
|
392
294
|
};
|
|
393
295
|
});
|
|
394
296
|
}
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Returns the Site entity.
|
|
398
|
-
*
|
|
399
|
-
* @return {Promise} Entity promise
|
|
400
|
-
*/
|
|
401
297
|
async function loadSiteEntity() {
|
|
402
|
-
var _site$schema$properti;
|
|
403
298
|
const entity = {
|
|
404
|
-
label: __(
|
|
405
|
-
name:
|
|
406
|
-
kind:
|
|
407
|
-
baseURL:
|
|
299
|
+
label: __("Site"),
|
|
300
|
+
name: "site",
|
|
301
|
+
kind: "root",
|
|
302
|
+
baseURL: "/wp/v2/settings",
|
|
408
303
|
syncConfig: {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
path: '/wp/v2/settings'
|
|
412
|
-
});
|
|
413
|
-
},
|
|
414
|
-
applyChangesToDoc: (doc, changes) => {
|
|
415
|
-
const document = doc.getMap('document');
|
|
416
|
-
Object.entries(changes).forEach(([key, value]) => {
|
|
417
|
-
if (document.get(key) !== value) {
|
|
418
|
-
document.set(key, value);
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
},
|
|
422
|
-
fromCRDTDoc: doc => {
|
|
423
|
-
return doc.getMap('document').toJSON();
|
|
424
|
-
}
|
|
304
|
+
applyChangesToCRDTDoc: defaultApplyChangesToCRDTDoc,
|
|
305
|
+
getChangesFromCRDTDoc: defaultGetChangesFromCRDTDoc
|
|
425
306
|
},
|
|
426
|
-
syncObjectType: 'root/site',
|
|
427
|
-
getSyncObjectId: () => 'index',
|
|
428
307
|
meta: {}
|
|
429
308
|
};
|
|
430
309
|
const site = await apiFetch({
|
|
431
310
|
path: entity.baseURL,
|
|
432
|
-
method:
|
|
311
|
+
method: "OPTIONS"
|
|
433
312
|
});
|
|
434
313
|
const labels = {};
|
|
435
|
-
Object.entries(
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
});
|
|
441
|
-
return [{
|
|
442
|
-
...entity,
|
|
443
|
-
meta: {
|
|
444
|
-
labels
|
|
314
|
+
Object.entries(site?.schema?.properties ?? {}).forEach(
|
|
315
|
+
([key, value]) => {
|
|
316
|
+
if (typeof value === "object" && value.title) {
|
|
317
|
+
labels[key] = value.title;
|
|
318
|
+
}
|
|
445
319
|
}
|
|
446
|
-
|
|
320
|
+
);
|
|
321
|
+
return [{ ...entity, meta: { labels } }];
|
|
447
322
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
* Returns the entity's getter method name given its kind and name or plural name.
|
|
451
|
-
*
|
|
452
|
-
* @example
|
|
453
|
-
* ```js
|
|
454
|
-
* const nameSingular = getMethodName( 'root', 'theme', 'get' );
|
|
455
|
-
* // nameSingular is getRootTheme
|
|
456
|
-
*
|
|
457
|
-
* const namePlural = getMethodName( 'root', 'themes', 'set' );
|
|
458
|
-
* // namePlural is setRootThemes
|
|
459
|
-
* ```
|
|
460
|
-
*
|
|
461
|
-
* @param {string} kind Entity kind.
|
|
462
|
-
* @param {string} name Entity name or plural name.
|
|
463
|
-
* @param {string} prefix Function prefix.
|
|
464
|
-
*
|
|
465
|
-
* @return {string} Method name
|
|
466
|
-
*/
|
|
467
|
-
export const getMethodName = (kind, name, prefix = 'get') => {
|
|
468
|
-
const kindPrefix = kind === 'root' ? '' : pascalCase(kind);
|
|
323
|
+
const getMethodName = (kind, name, prefix = "get") => {
|
|
324
|
+
const kindPrefix = kind === "root" ? "" : pascalCase(kind);
|
|
469
325
|
const suffix = pascalCase(name);
|
|
470
326
|
return `${prefix}${kindPrefix}${suffix}`;
|
|
471
327
|
};
|
|
472
|
-
|
|
328
|
+
export {
|
|
329
|
+
DEFAULT_ENTITY_KEY,
|
|
330
|
+
additionalEntityConfigLoaders,
|
|
331
|
+
deprecatedEntities,
|
|
332
|
+
getMethodName,
|
|
333
|
+
prePersistPostType,
|
|
334
|
+
rootEntitiesConfig
|
|
335
|
+
};
|
|
336
|
+
//# sourceMappingURL=entities.js.map
|