@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
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var crdt_blocks_exports = {};
|
|
30
|
+
__export(crdt_blocks_exports, {
|
|
31
|
+
mergeCrdtBlocks: () => mergeCrdtBlocks
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(crdt_blocks_exports);
|
|
34
|
+
var import_uuid = require("uuid");
|
|
35
|
+
var import_es6 = __toESM(require("fast-deep-equal/es6"));
|
|
36
|
+
var import_rich_text = require("@wordpress/rich-text");
|
|
37
|
+
var import_sync = require("@wordpress/sync");
|
|
38
|
+
var import_blocks = require("@wordpress/blocks");
|
|
39
|
+
const serializableBlocksCache = /* @__PURE__ */ new WeakMap();
|
|
40
|
+
function makeBlockAttributesSerializable(attributes) {
|
|
41
|
+
const newAttributes = { ...attributes };
|
|
42
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
43
|
+
if (value instanceof import_rich_text.RichTextData) {
|
|
44
|
+
newAttributes[key] = value.valueOf();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return newAttributes;
|
|
48
|
+
}
|
|
49
|
+
function makeBlocksSerializable(blocks) {
|
|
50
|
+
return blocks.map((block) => {
|
|
51
|
+
const blockAsJson = block instanceof import_sync.Y.Map ? block.toJSON() : block;
|
|
52
|
+
const { name, innerBlocks, attributes, ...rest } = blockAsJson;
|
|
53
|
+
delete rest.validationIssues;
|
|
54
|
+
delete rest.originalContent;
|
|
55
|
+
return {
|
|
56
|
+
...rest,
|
|
57
|
+
name,
|
|
58
|
+
attributes: makeBlockAttributesSerializable(attributes),
|
|
59
|
+
innerBlocks: makeBlocksSerializable(innerBlocks)
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function areBlocksEqual(gblock, yblock) {
|
|
64
|
+
const yblockAsJson = yblock.toJSON();
|
|
65
|
+
const overwrites = {
|
|
66
|
+
innerBlocks: null,
|
|
67
|
+
clientId: null
|
|
68
|
+
};
|
|
69
|
+
const res = (0, import_es6.default)(
|
|
70
|
+
Object.assign({}, gblock, overwrites),
|
|
71
|
+
Object.assign({}, yblockAsJson, overwrites)
|
|
72
|
+
);
|
|
73
|
+
const inners = gblock.innerBlocks || [];
|
|
74
|
+
const yinners = yblock.get("innerBlocks");
|
|
75
|
+
return res && inners.length === yinners.length && inners.every(
|
|
76
|
+
(block, i) => areBlocksEqual(block, yinners.get(i))
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
function createNewYAttributeMap(blockName, attributes) {
|
|
80
|
+
return new import_sync.Y.Map(
|
|
81
|
+
Object.entries(attributes).map(
|
|
82
|
+
([attributeName, attributeValue]) => {
|
|
83
|
+
return [
|
|
84
|
+
attributeName,
|
|
85
|
+
createNewYAttributeValue(
|
|
86
|
+
blockName,
|
|
87
|
+
attributeName,
|
|
88
|
+
attributeValue
|
|
89
|
+
)
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
function createNewYAttributeValue(blockName, attributeName, attributeValue) {
|
|
96
|
+
const isRichText = isRichTextAttribute(blockName, attributeName);
|
|
97
|
+
if (isRichText) {
|
|
98
|
+
return new import_sync.Y.Text(attributeValue?.toString() ?? "");
|
|
99
|
+
}
|
|
100
|
+
return attributeValue;
|
|
101
|
+
}
|
|
102
|
+
function createNewYBlock(block) {
|
|
103
|
+
return new import_sync.Y.Map(
|
|
104
|
+
Object.entries(block).map(([key, value]) => {
|
|
105
|
+
switch (key) {
|
|
106
|
+
case "attributes": {
|
|
107
|
+
return [key, createNewYAttributeMap(block.name, value)];
|
|
108
|
+
}
|
|
109
|
+
case "innerBlocks": {
|
|
110
|
+
const innerBlocks = new import_sync.Y.Array();
|
|
111
|
+
if (!Array.isArray(value)) {
|
|
112
|
+
return [key, innerBlocks];
|
|
113
|
+
}
|
|
114
|
+
innerBlocks.insert(
|
|
115
|
+
0,
|
|
116
|
+
value.map(
|
|
117
|
+
(innerBlock) => createNewYBlock(innerBlock)
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
return [key, innerBlocks];
|
|
121
|
+
}
|
|
122
|
+
default:
|
|
123
|
+
return [key, value];
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
function mergeCrdtBlocks(yblocks, incomingBlocks, lastSelection) {
|
|
129
|
+
if (!serializableBlocksCache.has(incomingBlocks)) {
|
|
130
|
+
serializableBlocksCache.set(
|
|
131
|
+
incomingBlocks,
|
|
132
|
+
makeBlocksSerializable(incomingBlocks)
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
const allBlocks = serializableBlocksCache.get(incomingBlocks) ?? [];
|
|
136
|
+
const blocksToSync = allBlocks.filter(
|
|
137
|
+
(block) => shouldBlockBeSynced(block)
|
|
138
|
+
);
|
|
139
|
+
const numOfCommonEntries = Math.min(
|
|
140
|
+
blocksToSync.length ?? 0,
|
|
141
|
+
yblocks.length
|
|
142
|
+
);
|
|
143
|
+
let left = 0;
|
|
144
|
+
let right = 0;
|
|
145
|
+
for (; left < numOfCommonEntries && areBlocksEqual(blocksToSync[left], yblocks.get(left)); left++) {
|
|
146
|
+
}
|
|
147
|
+
for (; right < numOfCommonEntries - left && areBlocksEqual(
|
|
148
|
+
blocksToSync[blocksToSync.length - right - 1],
|
|
149
|
+
yblocks.get(yblocks.length - right - 1)
|
|
150
|
+
); right++) {
|
|
151
|
+
}
|
|
152
|
+
const numOfUpdatesNeeded = numOfCommonEntries - left - right;
|
|
153
|
+
const numOfInsertionsNeeded = Math.max(
|
|
154
|
+
0,
|
|
155
|
+
blocksToSync.length - yblocks.length
|
|
156
|
+
);
|
|
157
|
+
const numOfDeletionsNeeded = Math.max(
|
|
158
|
+
0,
|
|
159
|
+
yblocks.length - blocksToSync.length
|
|
160
|
+
);
|
|
161
|
+
for (let i = 0; i < numOfUpdatesNeeded; i++, left++) {
|
|
162
|
+
const block = blocksToSync[left];
|
|
163
|
+
const yblock = yblocks.get(left);
|
|
164
|
+
Object.entries(block).forEach(([key, value]) => {
|
|
165
|
+
switch (key) {
|
|
166
|
+
case "attributes": {
|
|
167
|
+
const currentAttributes = yblock.get(
|
|
168
|
+
key
|
|
169
|
+
);
|
|
170
|
+
if (!currentAttributes) {
|
|
171
|
+
yblock.set(
|
|
172
|
+
key,
|
|
173
|
+
createNewYAttributeMap(block.name, value)
|
|
174
|
+
);
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
Object.entries(value).forEach(
|
|
178
|
+
([attributeName, attributeValue]) => {
|
|
179
|
+
if ((0, import_es6.default)(
|
|
180
|
+
currentAttributes?.get(attributeName),
|
|
181
|
+
attributeValue
|
|
182
|
+
)) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const isRichText = isRichTextAttribute(
|
|
186
|
+
block.name,
|
|
187
|
+
attributeName
|
|
188
|
+
);
|
|
189
|
+
if (isRichText && "string" === typeof attributeValue) {
|
|
190
|
+
const blockYText = currentAttributes.get(
|
|
191
|
+
attributeName
|
|
192
|
+
);
|
|
193
|
+
mergeRichTextUpdate(
|
|
194
|
+
blockYText,
|
|
195
|
+
attributeValue,
|
|
196
|
+
lastSelection
|
|
197
|
+
);
|
|
198
|
+
} else {
|
|
199
|
+
currentAttributes.set(
|
|
200
|
+
attributeName,
|
|
201
|
+
createNewYAttributeValue(
|
|
202
|
+
block.name,
|
|
203
|
+
attributeName,
|
|
204
|
+
attributeValue
|
|
205
|
+
)
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
);
|
|
210
|
+
currentAttributes.forEach(
|
|
211
|
+
(_attrValue, attrName) => {
|
|
212
|
+
if (!value.hasOwnProperty(attrName)) {
|
|
213
|
+
currentAttributes.delete(attrName);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
case "innerBlocks": {
|
|
220
|
+
const yInnerBlocks = yblock.get(key);
|
|
221
|
+
mergeCrdtBlocks(yInnerBlocks, value ?? [], lastSelection);
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
default:
|
|
225
|
+
if (!(0, import_es6.default)(block[key], yblock.get(key))) {
|
|
226
|
+
yblock.set(key, value);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
yblock.forEach((_v, k) => {
|
|
231
|
+
if (!block.hasOwnProperty(k)) {
|
|
232
|
+
yblock.delete(k);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
yblocks.delete(left, numOfDeletionsNeeded);
|
|
237
|
+
for (let i = 0; i < numOfInsertionsNeeded; i++, left++) {
|
|
238
|
+
const newBlock = [createNewYBlock(blocksToSync[left])];
|
|
239
|
+
yblocks.insert(left, newBlock);
|
|
240
|
+
}
|
|
241
|
+
const knownClientIds = /* @__PURE__ */ new Set();
|
|
242
|
+
for (let j = 0; j < yblocks.length; j++) {
|
|
243
|
+
const yblock = yblocks.get(j);
|
|
244
|
+
let clientId = yblock.get("clientId");
|
|
245
|
+
if (knownClientIds.has(clientId)) {
|
|
246
|
+
clientId = (0, import_uuid.v4)();
|
|
247
|
+
yblock.set("clientId", clientId);
|
|
248
|
+
}
|
|
249
|
+
knownClientIds.add(clientId);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function shouldBlockBeSynced(block) {
|
|
253
|
+
if ("core/gallery" === block.name) {
|
|
254
|
+
return !block.innerBlocks.some(
|
|
255
|
+
(innerBlock) => innerBlock.attributes && innerBlock.attributes.blob
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
let cachedRichTextAttributes;
|
|
261
|
+
function isRichTextAttribute(blockName, attributeName) {
|
|
262
|
+
if (!cachedRichTextAttributes) {
|
|
263
|
+
cachedRichTextAttributes = /* @__PURE__ */ new Map();
|
|
264
|
+
for (const blockType of (0, import_blocks.getBlockTypes)()) {
|
|
265
|
+
const richTextAttributeMap = /* @__PURE__ */ new Map();
|
|
266
|
+
for (const [name, definition] of Object.entries(
|
|
267
|
+
blockType.attributes ?? {}
|
|
268
|
+
)) {
|
|
269
|
+
if ("rich-text" === definition.type) {
|
|
270
|
+
richTextAttributeMap.set(name, true);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
cachedRichTextAttributes.set(
|
|
274
|
+
blockType.name,
|
|
275
|
+
richTextAttributeMap
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return cachedRichTextAttributes.get(blockName)?.has(attributeName) ?? false;
|
|
280
|
+
}
|
|
281
|
+
function mergeRichTextUpdate(blockYText, updatedValue, lastSelection) {
|
|
282
|
+
blockYText.delete(0, blockYText.toString().length);
|
|
283
|
+
blockYText.insert(0, updatedValue);
|
|
284
|
+
}
|
|
285
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
286
|
+
0 && (module.exports = {
|
|
287
|
+
mergeCrdtBlocks
|
|
288
|
+
});
|
|
289
|
+
//# sourceMappingURL=crdt-blocks.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/crdt-blocks.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { v4 as uuidv4 } from 'uuid';\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { RichTextData } from '@wordpress/rich-text';\nimport { Y } from '@wordpress/sync';\n\n// @ts-expect-error No exported types.\nimport { getBlockTypes } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport type { WPBlockSelection } from '../types';\n\ninterface BlockAttributes {\n\t[ key: string ]: unknown;\n}\n\ninterface BlockType {\n\tname: string;\n\tattributes?: Record< string, { type?: string } >;\n}\n\nexport interface Block {\n\tattributes: BlockAttributes;\n\tclientId?: string;\n\tinnerBlocks: Block[];\n\toriginalContent?: string; // unserializable\n\tvalidationIssues?: string[]; // unserializable\n\tname: string;\n}\n\nexport type YBlock = Y.Map<\n\t/* name, clientId, and originalContent are strings. */\n\t| string\n\t/* validationIssues? is an array of strings. */\n\t| string[]\n\t/* attributes is a Y.Map< unknown >. */\n\t| YBlockAttributes\n\t/* innerBlocks is a Y.Array< YBlock >. */\n\t| YBlocks\n>;\n\nexport type YBlocks = Y.Array< YBlock >;\nexport type YBlockAttributes = Y.Map< Y.Text | unknown >;\n\n// The Y.Map type is not easy to work with. The generic type it accepts represents\n// the possible values of the map, which are varied in our case. This type is\n// accurate, but will require aggressive type narrowing when the map values are\n// accessed -- or type casting with `as`.\n// export type YBlock = Y.Map< Block[ keyof Block ] >;\n\nconst serializableBlocksCache = new WeakMap< WeakKey, Block[] >();\n\nfunction makeBlockAttributesSerializable(\n\tattributes: BlockAttributes\n): BlockAttributes {\n\tconst newAttributes = { ...attributes };\n\tfor ( const [ key, value ] of Object.entries( attributes ) ) {\n\t\tif ( value instanceof RichTextData ) {\n\t\t\tnewAttributes[ key ] = value.valueOf();\n\t\t}\n\t}\n\treturn newAttributes;\n}\n\nfunction makeBlocksSerializable( blocks: Block[] | YBlocks ): Block[] {\n\treturn blocks.map( ( block: Block | YBlock ) => {\n\t\tconst blockAsJson = block instanceof Y.Map ? block.toJSON() : block;\n\t\tconst { name, innerBlocks, attributes, ...rest } = blockAsJson;\n\t\tdelete rest.validationIssues;\n\t\tdelete rest.originalContent;\n\t\t// delete rest.isValid\n\t\treturn {\n\t\t\t...rest,\n\t\t\tname,\n\t\t\tattributes: makeBlockAttributesSerializable( attributes ),\n\t\t\tinnerBlocks: makeBlocksSerializable( innerBlocks ),\n\t\t};\n\t} );\n}\n\n/**\n * @param {any} gblock\n * @param {Y.Map} yblock\n */\nfunction areBlocksEqual( gblock: Block, yblock: YBlock ): boolean {\n\tconst yblockAsJson = yblock.toJSON();\n\n\t// we must not sync clientId, as this can't be generated consistently and\n\t// hence will lead to merge conflicts.\n\tconst overwrites = {\n\t\tinnerBlocks: null,\n\t\tclientId: null,\n\t};\n\tconst res = fastDeepEqual(\n\t\tObject.assign( {}, gblock, overwrites ),\n\t\tObject.assign( {}, yblockAsJson, overwrites )\n\t);\n\tconst inners = gblock.innerBlocks || [];\n\tconst yinners = yblock.get( 'innerBlocks' ) as YBlocks;\n\treturn (\n\t\tres &&\n\t\tinners.length === yinners.length &&\n\t\tinners.every( ( block: Block, i: number ) =>\n\t\t\tareBlocksEqual( block, yinners.get( i ) )\n\t\t)\n\t);\n}\n\nfunction createNewYAttributeMap(\n\tblockName: string,\n\tattributes: BlockAttributes\n): YBlockAttributes {\n\treturn new Y.Map(\n\t\tObject.entries( attributes ).map(\n\t\t\t( [ attributeName, attributeValue ] ) => {\n\t\t\t\treturn [\n\t\t\t\t\tattributeName,\n\t\t\t\t\tcreateNewYAttributeValue(\n\t\t\t\t\t\tblockName,\n\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\tattributeValue\n\t\t\t\t\t),\n\t\t\t\t];\n\t\t\t}\n\t\t)\n\t);\n}\n\nfunction createNewYAttributeValue(\n\tblockName: string,\n\tattributeName: string,\n\tattributeValue: unknown\n): Y.Text | unknown {\n\tconst isRichText = isRichTextAttribute( blockName, attributeName );\n\n\tif ( isRichText ) {\n\t\treturn new Y.Text( attributeValue?.toString() ?? '' );\n\t}\n\n\treturn attributeValue;\n}\n\nfunction createNewYBlock( block: Block ): YBlock {\n\treturn new Y.Map(\n\t\tObject.entries( block ).map( ( [ key, value ] ) => {\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'attributes': {\n\t\t\t\t\treturn [ key, createNewYAttributeMap( block.name, value ) ];\n\t\t\t\t}\n\n\t\t\t\tcase 'innerBlocks': {\n\t\t\t\t\tconst innerBlocks = new Y.Array();\n\n\t\t\t\t\t// If not an array, set to empty Y.Array.\n\t\t\t\t\tif ( ! Array.isArray( value ) ) {\n\t\t\t\t\t\treturn [ key, innerBlocks ];\n\t\t\t\t\t}\n\n\t\t\t\t\tinnerBlocks.insert(\n\t\t\t\t\t\t0,\n\t\t\t\t\t\tvalue.map( ( innerBlock: Block ) =>\n\t\t\t\t\t\t\tcreateNewYBlock( innerBlock )\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\n\t\t\t\t\treturn [ key, innerBlocks ];\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t\t\treturn [ key, value ];\n\t\t\t}\n\t\t} )\n\t);\n}\n\n/**\n * Merge incoming block data into the local Y.Doc.\n * This function is called to sync local block changes to a shared Y.Doc.\n *\n * @param yblocks The blocks in the local Y.Doc.\n * @param incomingBlocks Gutenberg blocks being synced, either from a peer or from the local editor.\n * @param lastSelection The last cursor position, used for hinting the diff algorithm.\n */\nexport function mergeCrdtBlocks(\n\tyblocks: YBlocks,\n\tincomingBlocks: Block[],\n\tlastSelection: WPBlockSelection | null\n): void {\n\t// Ensure we are working with serializable block data.\n\tif ( ! serializableBlocksCache.has( incomingBlocks ) ) {\n\t\tserializableBlocksCache.set(\n\t\t\tincomingBlocks,\n\t\t\tmakeBlocksSerializable( incomingBlocks )\n\t\t);\n\t}\n\tconst allBlocks = serializableBlocksCache.get( incomingBlocks ) ?? [];\n\n\t// Ensure we skip blocks that we don't want to sync at the moment\n\tconst blocksToSync = allBlocks.filter( ( block ) =>\n\t\tshouldBlockBeSynced( block )\n\t);\n\n\t// This is a rudimentary diff implementation similar to the y-prosemirror diffing\n\t// approach.\n\t// A better implementation would also diff the textual content and represent it\n\t// using a Y.Text type.\n\t// However, at this time it makes more sense to keep this algorithm generic to\n\t// support all kinds of block types.\n\t// Ideally, we ensure that block data structure have a consistent data format.\n\t// E.g.:\n\t// - textual content (using rich-text formatting?) may always be stored under `block.text`\n\t// - local information that shouldn't be shared (e.g. clientId or isDragging) is stored under `block.private`\n\t//\n\t// @credit Kevin Jahns (dmonad)\n\t// @link https://github.com/WordPress/gutenberg/pull/68483\n\tconst numOfCommonEntries = Math.min(\n\t\tblocksToSync.length ?? 0,\n\t\tyblocks.length\n\t);\n\n\tlet left = 0;\n\tlet right = 0;\n\n\t// skip equal blocks from left\n\tfor (\n\t\t;\n\t\tleft < numOfCommonEntries &&\n\t\tareBlocksEqual( blocksToSync[ left ], yblocks.get( left ) );\n\t\tleft++\n\t) {\n\t\t/* nop */\n\t}\n\n\t// skip equal blocks from right\n\tfor (\n\t\t;\n\t\tright < numOfCommonEntries - left &&\n\t\tareBlocksEqual(\n\t\t\tblocksToSync[ blocksToSync.length - right - 1 ],\n\t\t\tyblocks.get( yblocks.length - right - 1 )\n\t\t);\n\t\tright++\n\t) {\n\t\t/* nop */\n\t}\n\n\tconst numOfUpdatesNeeded = numOfCommonEntries - left - right;\n\tconst numOfInsertionsNeeded = Math.max(\n\t\t0,\n\t\tblocksToSync.length - yblocks.length\n\t);\n\tconst numOfDeletionsNeeded = Math.max(\n\t\t0,\n\t\tyblocks.length - blocksToSync.length\n\t);\n\n\t// updates\n\tfor ( let i = 0; i < numOfUpdatesNeeded; i++, left++ ) {\n\t\tconst block = blocksToSync[ left ];\n\t\tconst yblock = yblocks.get( left );\n\t\tObject.entries( block ).forEach( ( [ key, value ] ) => {\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'attributes': {\n\t\t\t\t\tconst currentAttributes = yblock.get(\n\t\t\t\t\t\tkey\n\t\t\t\t\t) as YBlockAttributes;\n\n\t\t\t\t\t// If attributes are not set on the yblock, use the new values.\n\t\t\t\t\tif ( ! currentAttributes ) {\n\t\t\t\t\t\tyblock.set(\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tcreateNewYAttributeMap( block.name, value )\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tObject.entries( value ).forEach(\n\t\t\t\t\t\t( [ attributeName, attributeValue ] ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tfastDeepEqual(\n\t\t\t\t\t\t\t\t\tcurrentAttributes?.get( attributeName ),\n\t\t\t\t\t\t\t\t\tattributeValue\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst isRichText = isRichTextAttribute(\n\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\tattributeName\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tisRichText &&\n\t\t\t\t\t\t\t\t'string' === typeof attributeValue\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t// Rich text values are stored as persistent Y.Text instances.\n\t\t\t\t\t\t\t\t// Update the value with a delta in place.\n\t\t\t\t\t\t\t\tconst blockYText = currentAttributes.get(\n\t\t\t\t\t\t\t\t\tattributeName\n\t\t\t\t\t\t\t\t) as Y.Text;\n\n\t\t\t\t\t\t\t\tmergeRichTextUpdate(\n\t\t\t\t\t\t\t\t\tblockYText,\n\t\t\t\t\t\t\t\t\tattributeValue,\n\t\t\t\t\t\t\t\t\tlastSelection\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcurrentAttributes.set(\n\t\t\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\t\t\tcreateNewYAttributeValue(\n\t\t\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\t\t\t\tattributeValue\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\t\t// Delete any attributes that are no longer present.\n\t\t\t\t\tcurrentAttributes.forEach(\n\t\t\t\t\t\t( _attrValue: unknown, attrName: string ) => {\n\t\t\t\t\t\t\tif ( ! value.hasOwnProperty( attrName ) ) {\n\t\t\t\t\t\t\t\tcurrentAttributes.delete( attrName );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase 'innerBlocks': {\n\t\t\t\t\t// Recursively merge innerBlocks\n\t\t\t\t\tconst yInnerBlocks = yblock.get( key ) as Y.Array< YBlock >;\n\t\t\t\t\tmergeCrdtBlocks( yInnerBlocks, value ?? [], lastSelection );\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t\t\tif ( ! fastDeepEqual( block[ key ], yblock.get( key ) ) ) {\n\t\t\t\t\t\tyblock.set( key, value );\n\t\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t\tyblock.forEach( ( _v, k ) => {\n\t\t\tif ( ! block.hasOwnProperty( k ) ) {\n\t\t\t\tyblock.delete( k );\n\t\t\t}\n\t\t} );\n\t}\n\n\t// deletes\n\tyblocks.delete( left, numOfDeletionsNeeded );\n\n\t// inserts\n\tfor ( let i = 0; i < numOfInsertionsNeeded; i++, left++ ) {\n\t\tconst newBlock = [ createNewYBlock( blocksToSync[ left ] ) ];\n\n\t\tyblocks.insert( left, newBlock );\n\t}\n\n\t// remove duplicate clientids\n\tconst knownClientIds = new Set< string >();\n\tfor ( let j = 0; j < yblocks.length; j++ ) {\n\t\tconst yblock: YBlock = yblocks.get( j );\n\n\t\tlet clientId: string = yblock.get( 'clientId' ) as string;\n\n\t\tif ( knownClientIds.has( clientId ) ) {\n\t\t\tclientId = uuidv4();\n\t\t\tyblock.set( 'clientId', clientId );\n\t\t}\n\t\tknownClientIds.add( clientId );\n\t}\n}\n\n/**\n * Determine if a block should be synced.\n *\n * Ex: A gallery block should not be synced until the images have been\n * uploaded to WordPress, and their url is available. Before that,\n * it's not possible to access the blobs on a client as those are\n * local.\n *\n * @param block The block to check.\n * @return True if the block should be synced, false otherwise.\n */\nfunction shouldBlockBeSynced( block: Block ): boolean {\n\t// Verify that the gallery block is ready to be synced.\n\t// This means that, all images have had their blobs converted to full URLs.\n\t// Checking for only the blobs ensures that blocks that have just been inserted work as well.\n\tif ( 'core/gallery' === block.name ) {\n\t\treturn ! block.innerBlocks.some(\n\t\t\t( innerBlock ) =>\n\t\t\t\tinnerBlock.attributes && innerBlock.attributes.blob\n\t\t);\n\t}\n\n\t// Allow all other blocks to be synced.\n\treturn true;\n}\n\n// Cache rich-text attributes for all block types.\nlet cachedRichTextAttributes: Map< string, Map< string, true > >;\n\n/**\n * Given a block name and attribute key, return true if the attribute is rich-text typed.\n *\n * @param blockName The name of the block, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute to check, e.g. 'content'.\n * @return True if the attribute is rich-text typed, false otherwise.\n */\nfunction isRichTextAttribute(\n\tblockName: string,\n\tattributeName: string\n): boolean {\n\tif ( ! cachedRichTextAttributes ) {\n\t\t// Parse the attributes for all blocks once.\n\t\tcachedRichTextAttributes = new Map< string, Map< string, true > >();\n\n\t\tfor ( const blockType of getBlockTypes() as BlockType[] ) {\n\t\t\tconst richTextAttributeMap = new Map< string, true >();\n\n\t\t\tfor ( const [ name, definition ] of Object.entries(\n\t\t\t\tblockType.attributes ?? {}\n\t\t\t) ) {\n\t\t\t\tif ( 'rich-text' === definition.type ) {\n\t\t\t\t\trichTextAttributeMap.set( name, true );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcachedRichTextAttributes.set(\n\t\t\t\tblockType.name,\n\t\t\t\trichTextAttributeMap\n\t\t\t);\n\t\t}\n\t}\n\n\treturn (\n\t\tcachedRichTextAttributes.get( blockName )?.has( attributeName ) ?? false\n\t);\n}\n\n/**\n * Given a Y.Text object and an updated string value, diff the new value and\n * apply the delta to the Y.Text.\n *\n * @param blockYText The Y.Text to update.\n * @param updatedValue The updated value.\n * @param lastSelection The last cursor position before this update, used to hint the diff algorithm.\n */\nfunction mergeRichTextUpdate(\n\tblockYText: Y.Text,\n\tupdatedValue: string,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tlastSelection: WPBlockSelection | null\n): void {\n\t// TODO\n\t// ====\n\t// Gutenberg does not use Yjs shared types natively, so we can only subscribe\n\t// to changes from store and apply them to Yjs types that we create and\n\t// manage. Crucially, for rich-text attributes, we do not receive granular\n\t// string updates; we get the new full string value on each change, even when\n\t// only a single character changed.\n\t//\n\t// The code below allows us to compute a delta between the current and new\n\t// value, then apply it to the Y.Text. However, it relies on a library\n\t// (quill-delta) with a licensing issue that we are working to resolve.\n\t//\n\t// For now, we simply replace the full text content on each change.\n\t//\n\t// if ( ! localDoc ) {\n\t// \t// Y.Text must be attached to a Y.Doc to be able to do operations on it.\n\t// \t// Create a temporary Y.Text attached to a local Y.Doc for delta computation.\n\t// \tlocalDoc = new Y.Doc();\n\t// }\n\n\t// const localYText = localDoc.getText( 'temporary-text' );\n\t// localYText.delete( 0, localYText.length );\n\t// localYText.insert( 0, updatedValue );\n\n\t// const currentValueAsDelta = new Delta( blockYText.toDelta() );\n\t// const updatedValueAsDelta = new Delta( localYText.toDelta() );\n\n\t// const deltaDiff = currentValueAsDelta.diff(\n\t// \tupdatedValueAsDelta,\n\t// \tlastSelection?.offset\n\t// );\n\n\t// blockYText.applyDelta( deltaDiff.ops );\n\n\tblockYText.delete( 0, blockYText.toString().length );\n\tblockYText.insert( 0, updatedValue );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;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Q,KAAM;AAC1C,UAAM,SAAiB,QAAQ,IAAK,CAAE;AAEtC,QAAI,WAAmB,OAAO,IAAK,UAAW;AAE9C,QAAK,eAAe,IAAK,QAAS,GAAI;AACrC,qBAAW,YAAAC,IAAO;AAClB,aAAO,IAAK,YAAY,QAAS;AAAA,IAClC;AACA,mBAAe,IAAK,QAAS;AAAA,EAC9B;AACD;AAaA,SAAS,oBAAqB,OAAwB;AAIrD,MAAK,mBAAmB,MAAM,MAAO;AACpC,WAAO,CAAE,MAAM,YAAY;AAAA,MAC1B,CAAE,eACD,WAAW,cAAc,WAAW,WAAW;AAAA,IACjD;AAAA,EACD;AAGA,SAAO;AACR;AAGA,IAAI;AASJ,SAAS,oBACR,WACA,eACU;AACV,MAAK,CAAE,0BAA2B;AAEjC,+BAA2B,oBAAI,IAAmC;AAElE,eAAY,iBAAa,6BAAc,GAAmB;AACzD,YAAM,uBAAuB,oBAAI,IAAoB;AAErD,iBAAY,CAAE,MAAM,UAAW,KAAK,OAAO;AAAA,QAC1C,UAAU,cAAc,CAAC;AAAA,MAC1B,GAAI;AACH,YAAK,gBAAgB,WAAW,MAAO;AACtC,+BAAqB,IAAK,MAAM,IAAK;AAAA,QACtC;AAAA,MACD;AAEA,+BAAyB;AAAA,QACxB,UAAU;AAAA,QACV;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,SACC,yBAAyB,IAAK,SAAU,GAAG,IAAK,aAAc,KAAK;AAErE;AAUA,SAAS,oBACR,YACA,cAEA,eACO;AAmCP,aAAW,OAAQ,GAAG,WAAW,SAAS,EAAE,MAAO;AACnD,aAAW,OAAQ,GAAG,YAAa;AACpC;",
|
|
6
|
+
"names": ["fastDeepEqual", "uuidv4"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var crdt_exports = {};
|
|
30
|
+
__export(crdt_exports, {
|
|
31
|
+
applyPostChangesToCRDTDoc: () => applyPostChangesToCRDTDoc,
|
|
32
|
+
defaultApplyChangesToCRDTDoc: () => defaultApplyChangesToCRDTDoc,
|
|
33
|
+
defaultGetChangesFromCRDTDoc: () => defaultGetChangesFromCRDTDoc,
|
|
34
|
+
getPostChangesFromCRDTDoc: () => getPostChangesFromCRDTDoc
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(crdt_exports);
|
|
37
|
+
var import_es6 = __toESM(require("fast-deep-equal/es6"));
|
|
38
|
+
var import_sync = require("@wordpress/sync");
|
|
39
|
+
var import_crdt_blocks = require("./crdt-blocks");
|
|
40
|
+
var import_sync2 = require("../sync");
|
|
41
|
+
let lastSelection = null;
|
|
42
|
+
const allowedPostProperties = /* @__PURE__ */ new Set([
|
|
43
|
+
"author",
|
|
44
|
+
"blocks",
|
|
45
|
+
"comment_status",
|
|
46
|
+
"date",
|
|
47
|
+
"excerpt",
|
|
48
|
+
"featured_media",
|
|
49
|
+
"format",
|
|
50
|
+
"ping_status",
|
|
51
|
+
"slug",
|
|
52
|
+
"status",
|
|
53
|
+
"sticky",
|
|
54
|
+
"tags",
|
|
55
|
+
"template",
|
|
56
|
+
"title"
|
|
57
|
+
]);
|
|
58
|
+
function defaultApplyChangesToCRDTDoc(ydoc, changes) {
|
|
59
|
+
const ymap = ydoc.getMap(import_sync2.CRDT_RECORD_MAP_KEY);
|
|
60
|
+
Object.entries(changes).forEach(([key, newValue]) => {
|
|
61
|
+
if ("function" === typeof newValue) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
function setValue(updatedValue) {
|
|
65
|
+
ymap.set(key, updatedValue);
|
|
66
|
+
}
|
|
67
|
+
switch (key) {
|
|
68
|
+
// Add support for additional data types here.
|
|
69
|
+
default: {
|
|
70
|
+
const currentValue = ymap.get(key);
|
|
71
|
+
mergeValue(currentValue, newValue, setValue);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function applyPostChangesToCRDTDoc(ydoc, changes, postType) {
|
|
77
|
+
const ymap = ydoc.getMap(import_sync2.CRDT_RECORD_MAP_KEY);
|
|
78
|
+
Object.entries(changes).forEach(([key, newValue]) => {
|
|
79
|
+
if (!allowedPostProperties.has(key)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if ("function" === typeof newValue) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
function setValue(updatedValue) {
|
|
86
|
+
ymap.set(key, updatedValue);
|
|
87
|
+
}
|
|
88
|
+
switch (key) {
|
|
89
|
+
case "blocks": {
|
|
90
|
+
let currentBlocks = ymap.get("blocks");
|
|
91
|
+
if (!(currentBlocks instanceof import_sync.Y.Array)) {
|
|
92
|
+
currentBlocks = new import_sync.Y.Array();
|
|
93
|
+
setValue(currentBlocks);
|
|
94
|
+
}
|
|
95
|
+
const newBlocks = newValue ?? [];
|
|
96
|
+
(0, import_crdt_blocks.mergeCrdtBlocks)(currentBlocks, newBlocks, lastSelection);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case "excerpt": {
|
|
100
|
+
const currentValue = ymap.get("excerpt");
|
|
101
|
+
const rawNewValue = getRawValue(newValue);
|
|
102
|
+
mergeValue(currentValue, rawNewValue, setValue);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case "slug": {
|
|
106
|
+
if (!newValue) {
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
const currentValue = ymap.get("slug");
|
|
110
|
+
mergeValue(currentValue, newValue, setValue);
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case "title": {
|
|
114
|
+
const currentValue = ymap.get("title");
|
|
115
|
+
let rawNewValue = getRawValue(newValue);
|
|
116
|
+
if (!currentValue && "Auto Draft" === rawNewValue) {
|
|
117
|
+
rawNewValue = "";
|
|
118
|
+
}
|
|
119
|
+
mergeValue(currentValue, rawNewValue, setValue);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
// Add support for additional data types here.
|
|
123
|
+
default: {
|
|
124
|
+
const currentValue = ymap.get(key);
|
|
125
|
+
mergeValue(currentValue, newValue, setValue);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
if ("selection" in changes) {
|
|
130
|
+
lastSelection = changes.selection?.selectionStart ?? null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function defaultGetChangesFromCRDTDoc(crdtDoc) {
|
|
134
|
+
return crdtDoc.getMap(import_sync2.CRDT_RECORD_MAP_KEY).toJSON();
|
|
135
|
+
}
|
|
136
|
+
function getPostChangesFromCRDTDoc(ydoc, editedRecord, postType) {
|
|
137
|
+
const ymap = ydoc.getMap(import_sync2.CRDT_RECORD_MAP_KEY);
|
|
138
|
+
return Object.fromEntries(
|
|
139
|
+
Object.entries(ymap.toJSON()).filter(([key, newValue]) => {
|
|
140
|
+
if (!allowedPostProperties.has(key)) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
const currentValue = editedRecord[key];
|
|
144
|
+
switch (key) {
|
|
145
|
+
case "blocks": {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
case "date": {
|
|
149
|
+
const currentDateIsFloating = ["draft", "auto-draft", "pending"].includes(
|
|
150
|
+
ymap.get("status")
|
|
151
|
+
) && (null === currentValue || editedRecord.modified === currentValue);
|
|
152
|
+
if (!newValue && currentDateIsFloating) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
return haveValuesChanged(currentValue, newValue);
|
|
156
|
+
}
|
|
157
|
+
case "status": {
|
|
158
|
+
if ("auto-draft" === newValue) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
return haveValuesChanged(currentValue, newValue);
|
|
162
|
+
}
|
|
163
|
+
case "excerpt":
|
|
164
|
+
case "title": {
|
|
165
|
+
return haveValuesChanged(
|
|
166
|
+
getRawValue(currentValue),
|
|
167
|
+
newValue
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
// Add support for additional data types here.
|
|
171
|
+
default: {
|
|
172
|
+
return haveValuesChanged(currentValue, newValue);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
function getRawValue(value) {
|
|
179
|
+
if ("string" === typeof value) {
|
|
180
|
+
return value;
|
|
181
|
+
}
|
|
182
|
+
if (value && "object" === typeof value && "raw" in value && "string" === typeof value.raw) {
|
|
183
|
+
return value.raw;
|
|
184
|
+
}
|
|
185
|
+
return void 0;
|
|
186
|
+
}
|
|
187
|
+
function haveValuesChanged(currentValue, newValue) {
|
|
188
|
+
return !(0, import_es6.default)(currentValue, newValue);
|
|
189
|
+
}
|
|
190
|
+
function mergeValue(currentValue, newValue, setValue) {
|
|
191
|
+
if (haveValuesChanged(currentValue, newValue)) {
|
|
192
|
+
setValue(newValue);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
196
|
+
0 && (module.exports = {
|
|
197
|
+
applyPostChangesToCRDTDoc,
|
|
198
|
+
defaultApplyChangesToCRDTDoc,
|
|
199
|
+
defaultGetChangesFromCRDTDoc,
|
|
200
|
+
getPostChangesFromCRDTDoc
|
|
201
|
+
});
|
|
202
|
+
//# sourceMappingURL=crdt.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/crdt.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { type CRDTDoc, type ObjectData, Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport {\n\tmergeCrdtBlocks,\n\ttype Block,\n\ttype YBlock,\n\ttype YBlocks,\n} from './crdt-blocks';\nimport { type Post } from '../entity-types/post';\nimport { type Type } from '../entity-types';\nimport { CRDT_RECORD_MAP_KEY } from '../sync';\nimport type { WPBlockSelection, WPSelection } from '../types';\n\nexport type PostChanges = Partial< Post > & {\n\tblocks?: Block[];\n\texcerpt?: Post[ 'excerpt' ] | string;\n\tselection?: WPSelection;\n\ttitle?: Post[ 'title' ] | string;\n};\n\n// Hold a reference to the last known selection to help compute Y.Text deltas.\nlet lastSelection: WPBlockSelection | null = null;\n\n// Properties that are allowed to be synced for a post.\nconst allowedPostProperties = new Set< string >( [\n\t'author',\n\t'blocks',\n\t'comment_status',\n\t'date',\n\t'excerpt',\n\t'featured_media',\n\t'format',\n\t'ping_status',\n\t'slug',\n\t'status',\n\t'sticky',\n\t'tags',\n\t'template',\n\t'title',\n] );\n\n/**\n * Given a set of local changes to a generic entity record, apply those changes\n * to the local Y.Doc.\n *\n * @param {CRDTDoc} ydoc\n * @param {Partial< ObjectData >} changes\n * @return {void}\n */\nexport function defaultApplyChangesToCRDTDoc(\n\tydoc: CRDTDoc,\n\tchanges: ObjectData\n): void {\n\tconst ymap = ydoc.getMap( CRDT_RECORD_MAP_KEY );\n\n\tObject.entries( changes ).forEach( ( [ key, newValue ] ) => {\n\t\t// Cannot serialize function values, so cannot sync them.\n\t\tif ( 'function' === typeof newValue ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Set the value in the root document.\n\t\tfunction setValue< T = unknown >( updatedValue: T ): void {\n\t\t\tymap.set( key, updatedValue );\n\t\t}\n\n\t\tswitch ( key ) {\n\t\t\t// Add support for additional data types here.\n\n\t\t\tdefault: {\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tmergeValue( currentValue, newValue, setValue );\n\t\t\t}\n\t\t}\n\t} );\n}\n\n/**\n * Given a set of local changes to a post record, apply those changes to the\n * local Y.Doc.\n *\n * @param {CRDTDoc} ydoc\n * @param {PostChanges} changes\n * @param {Type} postType\n * @return {void}\n */\nexport function applyPostChangesToCRDTDoc(\n\tydoc: CRDTDoc,\n\tchanges: PostChanges,\n\tpostType: Type // eslint-disable-line @typescript-eslint/no-unused-vars\n): void {\n\tconst ymap = ydoc.getMap( CRDT_RECORD_MAP_KEY );\n\n\tObject.entries( changes ).forEach( ( [ key, newValue ] ) => {\n\t\tif ( ! allowedPostProperties.has( key ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Cannot serialize function values, so cannot sync them.\n\t\tif ( 'function' === typeof newValue ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Set the value in the root document.\n\t\tfunction setValue< T = unknown >( updatedValue: T ): void {\n\t\t\tymap.set( key, updatedValue );\n\t\t}\n\n\t\tswitch ( key ) {\n\t\t\tcase 'blocks': {\n\t\t\t\tlet currentBlocks = ymap.get( 'blocks' ) as YBlocks;\n\n\t\t\t\t// Initialize.\n\t\t\t\tif ( ! ( currentBlocks instanceof Y.Array ) ) {\n\t\t\t\t\tcurrentBlocks = new Y.Array< YBlock >();\n\t\t\t\t\tsetValue( currentBlocks );\n\t\t\t\t}\n\n\t\t\t\t// Block[] from local changes.\n\t\t\t\tconst newBlocks = ( newValue as PostChanges[ 'blocks' ] ) ?? [];\n\n\t\t\t\t// Merge blocks does not need `setValue` because it is operating on a\n\t\t\t\t// Yjs type that is already in the Y.Doc.\n\t\t\t\tmergeCrdtBlocks( currentBlocks, newBlocks, lastSelection );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'excerpt': {\n\t\t\t\tconst currentValue = ymap.get( 'excerpt' ) as\n\t\t\t\t\t| string\n\t\t\t\t\t| undefined;\n\t\t\t\tconst rawNewValue = getRawValue( newValue );\n\n\t\t\t\tmergeValue( currentValue, rawNewValue, setValue );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'slug': {\n\t\t\t\t// Do not sync an empty slug. This indicates that the post is using\n\t\t\t\t// the default auto-generated slug.\n\t\t\t\tif ( ! newValue ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst currentValue = ymap.get( 'slug' ) as string;\n\t\t\t\tmergeValue( currentValue, newValue, setValue );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'title': {\n\t\t\t\tconst currentValue = ymap.get( 'title' ) as string | undefined;\n\n\t\t\t\t// Copy logic from prePersistPostType to ensure that the \"Auto\n\t\t\t\t// Draft\" template title is not synced.\n\t\t\t\tlet rawNewValue = getRawValue( newValue );\n\t\t\t\tif ( ! currentValue && 'Auto Draft' === rawNewValue ) {\n\t\t\t\t\trawNewValue = '';\n\t\t\t\t}\n\n\t\t\t\tmergeValue( currentValue, rawNewValue, setValue );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Add support for additional data types here.\n\n\t\t\tdefault: {\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tmergeValue( currentValue, newValue, setValue );\n\t\t\t}\n\t\t}\n\t} );\n\n\t// Update the lastSelection for use in computing Y.Text deltas.\n\tif ( 'selection' in changes ) {\n\t\tlastSelection = changes.selection?.selectionStart ?? null;\n\t}\n}\n\nexport function defaultGetChangesFromCRDTDoc( crdtDoc: CRDTDoc ): ObjectData {\n\treturn crdtDoc.getMap( CRDT_RECORD_MAP_KEY ).toJSON();\n}\n\n/**\n * Given a local Y.Doc that *may* contain changes from remote peers, compare\n * against the local record and determine if there are changes (edits) we want\n * to dispatch.\n *\n * @param {CRDTDoc} ydoc\n * @param {Post} editedRecord\n * @param {Type} postType\n * @return {Partial<PostChanges>} The changes that should be applied to the local record.\n */\nexport function getPostChangesFromCRDTDoc(\n\tydoc: CRDTDoc,\n\teditedRecord: Post,\n\tpostType: Type // eslint-disable-line @typescript-eslint/no-unused-vars\n): PostChanges {\n\tconst ymap = ydoc.getMap( CRDT_RECORD_MAP_KEY );\n\n\treturn Object.fromEntries(\n\t\tObject.entries( ymap.toJSON() ).filter( ( [ key, newValue ] ) => {\n\t\t\tif ( ! allowedPostProperties.has( key ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst currentValue = editedRecord[ key ];\n\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'blocks': {\n\t\t\t\t\t// The consumers of blocks have memoization that renders optimization\n\t\t\t\t\t// here unnecessary.\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tcase 'date': {\n\t\t\t\t\t// Do not sync an empty date if our current value is a \"floating\" date.\n\t\t\t\t\t// Borrowing logic from the isEditedPostDateFloating selector.\n\t\t\t\t\tconst currentDateIsFloating =\n\t\t\t\t\t\t[ 'draft', 'auto-draft', 'pending' ].includes(\n\t\t\t\t\t\t\tymap.get( 'status' ) as string\n\t\t\t\t\t\t) &&\n\t\t\t\t\t\t( null === currentValue ||\n\t\t\t\t\t\t\teditedRecord.modified === currentValue );\n\n\t\t\t\t\tif ( ! newValue && currentDateIsFloating ) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\n\t\t\t\tcase 'status': {\n\t\t\t\t\t// Do not sync an invalid status.\n\t\t\t\t\tif ( 'auto-draft' === newValue ) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\n\t\t\t\tcase 'excerpt':\n\t\t\t\tcase 'title': {\n\t\t\t\t\treturn haveValuesChanged(\n\t\t\t\t\t\tgetRawValue( currentValue ),\n\t\t\t\t\t\tnewValue\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Add support for additional data types here.\n\n\t\t\t\tdefault: {\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\t\t\t}\n\t\t} )\n\t);\n}\n\n/**\n * Extract the raw string value from a property that may be a string or an object\n * with a `raw` property (`RenderedText`).\n *\n * @param {unknown} value The value to extract from.\n * @return {string|undefined} The raw string value, or undefined if it could not be determined.\n */\nfunction getRawValue( value?: unknown ): string | undefined {\n\t// Value may be a string property or a nested object with a `raw` property.\n\tif ( 'string' === typeof value ) {\n\t\treturn value;\n\t}\n\n\tif (\n\t\tvalue &&\n\t\t'object' === typeof value &&\n\t\t'raw' in value &&\n\t\t'string' === typeof value.raw\n\t) {\n\t\treturn value.raw;\n\t}\n\n\treturn undefined;\n}\n\nfunction haveValuesChanged< ValueType = any >(\n\tcurrentValue: ValueType,\n\tnewValue: ValueType\n): boolean {\n\treturn ! fastDeepEqual( currentValue, newValue );\n}\n\nfunction mergeValue< ValueType = any >(\n\tcurrentValue: ValueType,\n\tnewValue: ValueType,\n\tsetValue: ( value: ValueType ) => void\n): void {\n\tif ( haveValuesChanged< ValueType >( currentValue, newValue ) ) {\n\t\tsetValue( newValue );\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA0B;AAK1B,kBAAiD;AAKjD,yBAKO;AAGP,IAAAA,eAAoC;AAWpC,IAAI,gBAAyC;AAG7C,MAAM,wBAAwB,oBAAI,IAAe;AAAA,EAChD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAUK,SAAS,6BACf,MACA,SACO;AACP,QAAM,OAAO,KAAK,OAAQ,gCAAoB;AAE9C,SAAO,QAAS,OAAQ,EAAE,QAAS,CAAE,CAAE,KAAK,QAAS,MAAO;AAE3D,QAAK,eAAe,OAAO,UAAW;AACrC;AAAA,IACD;AAGA,aAAS,SAAyB,cAAwB;AACzD,WAAK,IAAK,KAAK,YAAa;AAAA,IAC7B;AAEA,YAAS,KAAM;AAAA;AAAA,MAGd,SAAS;AACR,cAAM,eAAe,KAAK,IAAK,GAAI;AACnC,mBAAY,cAAc,UAAU,QAAS;AAAA,MAC9C;AAAA,IACD;AAAA,EACD,CAAE;AACH;AAWO,SAAS,0BACf,MACA,SACA,UACO;AACP,QAAM,OAAO,KAAK,OAAQ,gCAAoB;AAE9C,SAAO,QAAS,OAAQ,EAAE,QAAS,CAAE,CAAE,KAAK,QAAS,MAAO;AAC3D,QAAK,CAAE,sBAAsB,IAAK,GAAI,GAAI;AACzC;AAAA,IACD;AAGA,QAAK,eAAe,OAAO,UAAW;AACrC;AAAA,IACD;AAGA,aAAS,SAAyB,cAAwB;AACzD,WAAK,IAAK,KAAK,YA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
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var forward_resolver_exports = {};
|
|
20
|
+
__export(forward_resolver_exports, {
|
|
21
|
+
default: () => forward_resolver_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
* Higher-order function which forward the resolution to another resolver with the same arguments.
|
|
9
|
-
*
|
|
10
|
-
* @param {string} resolverName forwarded resolver.
|
|
11
|
-
*
|
|
12
|
-
* @return {Function} Enhanced resolver.
|
|
13
|
-
*/
|
|
14
|
-
const forwardResolver = resolverName => (...args) => async ({
|
|
15
|
-
resolveSelect
|
|
16
|
-
}) => {
|
|
23
|
+
module.exports = __toCommonJS(forward_resolver_exports);
|
|
24
|
+
const forwardResolver = (resolverName) => (...args) => async ({ resolveSelect }) => {
|
|
17
25
|
await resolveSelect[resolverName](...args);
|
|
18
26
|
};
|
|
19
|
-
var
|
|
20
|
-
//# sourceMappingURL=forward-resolver.js.map
|
|
27
|
+
var forward_resolver_default = forwardResolver;
|
|
28
|
+
//# sourceMappingURL=forward-resolver.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/forward-resolver.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Higher-order function which forward the resolution to another resolver with the same arguments.\n *\n * @param {string} resolverName forwarded resolver.\n *\n * @return {Function} Enhanced resolver.\n */\nconst forwardResolver =\n\t( resolverName ) =>\n\t( ...args ) =>\n\tasync ( { resolveSelect } ) => {\n\t\tawait resolveSelect[ resolverName ]( ...args );\n\t};\n\nexport default forwardResolver;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,MAAM,kBACL,CAAE,iBACF,IAAK,SACL,OAAQ,EAAE,cAAc,MAAO;AAC9B,QAAM,cAAe,YAAa,EAAG,GAAG,IAAK;AAC9C;AAED,IAAO,2BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|