@wordpress/core-data 7.37.1-next.v.0 → 7.38.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/CHANGELOG.md +2 -0
- package/build/actions.cjs +14 -2
- package/build/actions.cjs.map +2 -2
- package/build/entities.cjs +35 -45
- package/build/entities.cjs.map +2 -2
- package/build/private-selectors.cjs +2 -4
- package/build/private-selectors.cjs.map +2 -2
- package/build/resolvers.cjs +11 -2
- package/build/resolvers.cjs.map +2 -2
- package/build/types.cjs.map +1 -1
- package/build/utils/crdt-blocks.cjs +63 -41
- package/build/utils/crdt-blocks.cjs.map +2 -2
- package/build/utils/crdt-utils.cjs +44 -0
- package/build/utils/crdt-utils.cjs.map +7 -0
- package/build/utils/crdt.cjs +33 -37
- package/build/utils/crdt.cjs.map +2 -2
- package/build-module/actions.mjs +14 -2
- package/build-module/actions.mjs.map +2 -2
- package/build-module/entities.mjs +35 -47
- package/build-module/entities.mjs.map +2 -2
- package/build-module/private-selectors.mjs +2 -4
- package/build-module/private-selectors.mjs.map +2 -2
- package/build-module/resolvers.mjs +11 -2
- package/build-module/resolvers.mjs.map +2 -2
- package/build-module/utils/crdt-blocks.mjs +64 -42
- package/build-module/utils/crdt-blocks.mjs.map +2 -2
- package/build-module/utils/crdt-utils.mjs +17 -0
- package/build-module/utils/crdt-utils.mjs.map +7 -0
- package/build-module/utils/crdt.mjs +37 -37
- package/build-module/utils/crdt.mjs.map +2 -2
- package/build-types/actions.d.ts.map +1 -1
- 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.map +1 -1
- package/build-types/types.d.ts +0 -5
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils/crdt-blocks.d.ts +14 -5
- package/build-types/utils/crdt-blocks.d.ts.map +1 -1
- package/build-types/utils/crdt-utils.d.ts +53 -0
- package/build-types/utils/crdt-utils.d.ts.map +1 -0
- package/build-types/utils/crdt.d.ts +19 -1
- package/build-types/utils/crdt.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/actions.js +13 -2
- package/src/entities.js +38 -54
- package/src/private-selectors.ts +3 -4
- package/src/resolvers.js +15 -7
- package/src/test/entities.js +11 -9
- package/src/test/resolvers.js +3 -45
- package/src/types.ts +0 -6
- package/src/utils/crdt-blocks.ts +101 -99
- package/src/utils/crdt-utils.ts +77 -0
- package/src/utils/crdt.ts +76 -57
- package/src/utils/test/crdt.ts +28 -16
package/build-types/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC3B,CAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAI,GAAG,CAAC;CACxB;AAGD,MAAM,WAAW,gBAAgB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC3B,YAAY,EAAE,gBAAgB,CAAC;IAC/B,cAAc,EAAE,gBAAgB,CAAC;CACjC"}
|
|
@@ -2,7 +2,7 @@ import { Y } from '@wordpress/sync';
|
|
|
2
2
|
/**
|
|
3
3
|
* Internal dependencies
|
|
4
4
|
*/
|
|
5
|
-
import type
|
|
5
|
+
import { type YMapRecord, type YMapWrap } from './crdt-utils';
|
|
6
6
|
interface BlockAttributes {
|
|
7
7
|
[key: string]: unknown;
|
|
8
8
|
}
|
|
@@ -10,11 +10,20 @@ export interface Block {
|
|
|
10
10
|
attributes: BlockAttributes;
|
|
11
11
|
clientId?: string;
|
|
12
12
|
innerBlocks: Block[];
|
|
13
|
+
isValid?: boolean;
|
|
14
|
+
name: string;
|
|
13
15
|
originalContent?: string;
|
|
14
16
|
validationIssues?: string[];
|
|
17
|
+
}
|
|
18
|
+
interface YBlockRecord extends YMapRecord {
|
|
19
|
+
attributes: YBlockAttributes;
|
|
20
|
+
clientId: string;
|
|
21
|
+
innerBlocks: YBlocks;
|
|
22
|
+
isValid?: boolean;
|
|
23
|
+
originalContent?: string;
|
|
15
24
|
name: string;
|
|
16
25
|
}
|
|
17
|
-
export type YBlock =
|
|
26
|
+
export type YBlock = YMapWrap<YBlockRecord>;
|
|
18
27
|
export type YBlocks = Y.Array<YBlock>;
|
|
19
28
|
export type YBlockAttributes = Y.Map<Y.Text | unknown>;
|
|
20
29
|
/**
|
|
@@ -22,9 +31,9 @@ export type YBlockAttributes = Y.Map<Y.Text | unknown>;
|
|
|
22
31
|
* This function is called to sync local block changes to a shared Y.Doc.
|
|
23
32
|
*
|
|
24
33
|
* @param yblocks The blocks in the local Y.Doc.
|
|
25
|
-
* @param incomingBlocks Gutenberg blocks being synced
|
|
26
|
-
* @param
|
|
34
|
+
* @param incomingBlocks Gutenberg blocks being synced.
|
|
35
|
+
* @param cursorPosition The position of the cursor after the change occurs.
|
|
27
36
|
*/
|
|
28
|
-
export declare function mergeCrdtBlocks(yblocks: YBlocks, incomingBlocks: Block[],
|
|
37
|
+
export declare function mergeCrdtBlocks(yblocks: YBlocks, incomingBlocks: Block[], cursorPosition: number | null): void;
|
|
29
38
|
export {};
|
|
30
39
|
//# sourceMappingURL=crdt-blocks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crdt-blocks.d.ts","sourceRoot":"","sources":["../../src/utils/crdt-blocks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crdt-blocks.d.ts","sourceRoot":"","sources":["../../src/utils/crdt-blocks.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,CAAC,EAAS,MAAM,iBAAiB,CAAC;AAE3C;;GAEG;AACH,OAAO,EAAc,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE1E,UAAU,eAAe;IACxB,CAAE,GAAG,EAAE,MAAM,GAAI,OAAO,CAAC;CACzB;AAQD,MAAM,WAAW,KAAK;IACrB,UAAU,EAAE,eAAe,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,KAAK,EAAE,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAGD,UAAU,YAAa,SAAQ,UAAU;IACxC,UAAU,EAAE,gBAAgB,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,MAAM,GAAG,QAAQ,CAAE,YAAY,CAAE,CAAC;AAC9C,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAE,MAAM,CAAE,CAAC;AAIxC,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,GAAG,CAAE,CAAC,CAAC,IAAI,GAAG,OAAO,CAAE,CAAC;AAiIzD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC9B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,KAAK,EAAE,EACvB,cAAc,EAAE,MAAM,GAAG,IAAI,GAC3B,IAAI,CAwMN"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Y } from '@wordpress/sync';
|
|
5
|
+
/**
|
|
6
|
+
* A YMapRecord represents the shape of the data stored in a Y.Map.
|
|
7
|
+
*/
|
|
8
|
+
export type YMapRecord = Record<string, unknown>;
|
|
9
|
+
/**
|
|
10
|
+
* A wrapper around Y.Map to provide type safety. The generic type accepted by
|
|
11
|
+
* Y.Map represents the union of possible values of the map, which are varied in
|
|
12
|
+
* many cases. This type is accurate, but its non-specificity requires aggressive
|
|
13
|
+
* type narrowing or type casting / destruction with `as`.
|
|
14
|
+
*
|
|
15
|
+
* This type provides type enhancements so that the correct value type can be
|
|
16
|
+
* inferred based on the provided key. It is just a type wrap / overlay, and
|
|
17
|
+
* does not change the runtime behavior of Y.Map.
|
|
18
|
+
*
|
|
19
|
+
* This interface cannot extend Y.Map directly due to the limitations of
|
|
20
|
+
* TypeScript's structural typing. One negative consequence of this is that
|
|
21
|
+
* `instanceof` checks against Y.Map continue to work at runtime but will blur
|
|
22
|
+
* the type at compile time. To navigate this, use the `isYMap` function below.
|
|
23
|
+
*/
|
|
24
|
+
export interface YMapWrap<T extends YMapRecord> extends Y.AbstractType<T> {
|
|
25
|
+
delete: <K extends keyof T>(key: K) => void;
|
|
26
|
+
forEach: (callback: (value: T[keyof T], key: keyof T, map: YMapWrap<T>) => void) => void;
|
|
27
|
+
has: <K extends keyof T>(key: K) => boolean;
|
|
28
|
+
get: <K extends keyof T>(key: K) => T[K] | undefined;
|
|
29
|
+
set: <K extends keyof T>(key: K, value: T[K]) => void;
|
|
30
|
+
toJSON: () => T;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get or create a root-level Map for the given Y.Doc. Use this instead of
|
|
34
|
+
* doc.getMap() for additional type safety.
|
|
35
|
+
*
|
|
36
|
+
* @param doc Y.Doc
|
|
37
|
+
* @param key Map key
|
|
38
|
+
*/
|
|
39
|
+
export declare function getRootMap<T extends YMapRecord>(doc: Y.Doc, key: string): YMapWrap<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Create a new Y.Map (provided with YMapWrap type), optionally initialized with
|
|
42
|
+
* data. Use this instead of `new Y.Map()` for additional type safety.
|
|
43
|
+
*
|
|
44
|
+
* @param partial Partial data to initialize the map with.
|
|
45
|
+
*/
|
|
46
|
+
export declare function createYMap<T extends YMapRecord>(partial?: Partial<T>): YMapWrap<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Type guard to check if a value is a Y.Map without losing type information.
|
|
49
|
+
*
|
|
50
|
+
* @param value Value to check.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isYMap<T extends YMapRecord>(value: YMapWrap<T> | undefined): value is YMapWrap<T>;
|
|
53
|
+
//# sourceMappingURL=crdt-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crdt-utils.d.ts","sourceRoot":"","sources":["../../src/utils/crdt-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAC;AAEpC;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAE,MAAM,EAAE,OAAO,CAAE,CAAC;AAEnD;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,QAAQ,CAAE,CAAC,SAAS,UAAU,CAAG,SAAQ,CAAC,CAAC,YAAY,CAAE,CAAC,CAAE;IAC5E,MAAM,EAAE,CAAE,CAAC,SAAS,MAAM,CAAC,EAAI,GAAG,EAAE,CAAC,KAAM,IAAI,CAAC;IAChD,OAAO,EAAE,CACR,QAAQ,EAAE,CACT,KAAK,EAAE,CAAC,CAAE,MAAM,CAAC,CAAE,EACnB,GAAG,EAAE,MAAM,CAAC,EACZ,GAAG,EAAE,QAAQ,CAAE,CAAC,CAAE,KACd,IAAI,KACL,IAAI,CAAC;IACV,GAAG,EAAE,CAAE,CAAC,SAAS,MAAM,CAAC,EAAI,GAAG,EAAE,CAAC,KAAM,OAAO,CAAC;IAChD,GAAG,EAAE,CAAE,CAAC,SAAS,MAAM,CAAC,EAAI,GAAG,EAAE,CAAC,KAAM,CAAC,CAAE,CAAC,CAAE,GAAG,SAAS,CAAC;IAC3D,GAAG,EAAE,CAAE,CAAC,SAAS,MAAM,CAAC,EAAI,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAE,CAAC,CAAE,KAAM,IAAI,CAAC;IAC5D,MAAM,EAAE,MAAM,CAAC,CAAC;CAEhB;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAE,CAAC,SAAS,UAAU,EAC/C,GAAG,EAAE,CAAC,CAAC,GAAG,EACV,GAAG,EAAE,MAAM,GACT,QAAQ,CAAE,CAAC,CAAE,CAEf;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAE,CAAC,SAAS,UAAU,EAC/C,OAAO,GAAE,OAAO,CAAE,CAAC,CAAO,GACxB,QAAQ,CAAE,CAAC,CAAE,CAEf;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAE,CAAC,SAAS,UAAU,EAC3C,KAAK,EAAE,QAAQ,CAAE,CAAC,CAAE,GAAG,SAAS,GAC9B,KAAK,IAAI,QAAQ,CAAE,CAAC,CAAE,CAExB"}
|
|
@@ -2,16 +2,34 @@ import { type CRDTDoc, type ObjectData } from '@wordpress/sync';
|
|
|
2
2
|
/**
|
|
3
3
|
* Internal dependencies
|
|
4
4
|
*/
|
|
5
|
-
import { type Block } from './crdt-blocks';
|
|
5
|
+
import { type Block, type YBlocks } from './crdt-blocks';
|
|
6
6
|
import { type Post } from '../entity-types/post';
|
|
7
7
|
import { type Type } from '../entity-types';
|
|
8
8
|
import type { WPSelection } from '../types';
|
|
9
|
+
import { type YMapRecord, type YMapWrap } from './crdt-utils';
|
|
9
10
|
export type PostChanges = Partial<Post> & {
|
|
10
11
|
blocks?: Block[];
|
|
11
12
|
excerpt?: Post['excerpt'] | string;
|
|
12
13
|
selection?: WPSelection;
|
|
13
14
|
title?: Post['title'] | string;
|
|
14
15
|
};
|
|
16
|
+
export interface YPostRecord extends YMapRecord {
|
|
17
|
+
author: number;
|
|
18
|
+
blocks: YBlocks;
|
|
19
|
+
comment_status: string;
|
|
20
|
+
date: string | null;
|
|
21
|
+
excerpt: string;
|
|
22
|
+
featured_media: number;
|
|
23
|
+
format: string;
|
|
24
|
+
meta: YMapWrap<YMapRecord>;
|
|
25
|
+
ping_status: string;
|
|
26
|
+
slug: string;
|
|
27
|
+
status: string;
|
|
28
|
+
sticky: boolean;
|
|
29
|
+
tags: number[];
|
|
30
|
+
template: string;
|
|
31
|
+
title: string;
|
|
32
|
+
}
|
|
15
33
|
/**
|
|
16
34
|
* Given a set of local changes to a generic entity record, apply those changes
|
|
17
35
|
* to the local Y.Doc.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crdt.d.ts","sourceRoot":"","sources":["../../src/utils/crdt.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,UAAU,EAAK,MAAM,iBAAiB,CAAC;AAEnE;;GAEG;AACH,OAAO,EAEN,KAAK,KAAK,
|
|
1
|
+
{"version":3,"file":"crdt.d.ts","sourceRoot":"","sources":["../../src/utils/crdt.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,UAAU,EAAK,MAAM,iBAAiB,CAAC;AAEnE;;GAEG;AACH,OAAO,EAEN,KAAK,KAAK,EAEV,KAAK,OAAO,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAM5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAIN,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,MAAM,cAAc,CAAC;AAGtB,MAAM,MAAM,WAAW,GAAG,OAAO,CAAE,IAAI,CAAE,GAAG;IAC3C,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,IAAI,CAAE,SAAS,CAAE,GAAG,MAAM,CAAC;IACrC,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,KAAK,CAAC,EAAE,IAAI,CAAE,OAAO,CAAE,GAAG,MAAM,CAAC;CACjC,CAAC;AAGF,MAAM,WAAW,WAAY,SAAQ,UAAU;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAE,UAAU,CAAE,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACd;AA0BD;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC3C,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,UAAU,GACjB,IAAI,CAkBN;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACxC,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,IAAI,GACb,IAAI,CA8GN;AAED,wBAAgB,4BAA4B,CAAE,OAAO,EAAE,OAAO,GAAI,UAAU,CAE3E;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACxC,IAAI,EAAE,OAAO,EACb,YAAY,EAAE,IAAI,EAClB,SAAS,EAAE,IAAI,GACb,WAAW,CAwHb"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/core-data",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.38.0",
|
|
4
4
|
"description": "Access to and manipulation of core WordPress entities.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -49,22 +49,22 @@
|
|
|
49
49
|
"build-module/index.mjs"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@wordpress/api-fetch": "^7.
|
|
53
|
-
"@wordpress/block-editor": "^15.
|
|
54
|
-
"@wordpress/blocks": "^15.
|
|
55
|
-
"@wordpress/compose": "^7.
|
|
56
|
-
"@wordpress/data": "^10.
|
|
57
|
-
"@wordpress/deprecated": "^4.
|
|
58
|
-
"@wordpress/element": "^6.
|
|
59
|
-
"@wordpress/html-entities": "^4.
|
|
60
|
-
"@wordpress/i18n": "^6.
|
|
61
|
-
"@wordpress/is-shallow-equal": "^5.
|
|
62
|
-
"@wordpress/private-apis": "^1.
|
|
63
|
-
"@wordpress/rich-text": "^7.
|
|
64
|
-
"@wordpress/sync": "^1.
|
|
65
|
-
"@wordpress/undo-manager": "^1.
|
|
66
|
-
"@wordpress/url": "^4.
|
|
67
|
-
"@wordpress/warning": "^3.
|
|
52
|
+
"@wordpress/api-fetch": "^7.38.0",
|
|
53
|
+
"@wordpress/block-editor": "^15.11.0",
|
|
54
|
+
"@wordpress/blocks": "^15.11.0",
|
|
55
|
+
"@wordpress/compose": "^7.38.0",
|
|
56
|
+
"@wordpress/data": "^10.38.0",
|
|
57
|
+
"@wordpress/deprecated": "^4.38.0",
|
|
58
|
+
"@wordpress/element": "^6.38.0",
|
|
59
|
+
"@wordpress/html-entities": "^4.38.0",
|
|
60
|
+
"@wordpress/i18n": "^6.11.0",
|
|
61
|
+
"@wordpress/is-shallow-equal": "^5.38.0",
|
|
62
|
+
"@wordpress/private-apis": "^1.38.0",
|
|
63
|
+
"@wordpress/rich-text": "^7.38.0",
|
|
64
|
+
"@wordpress/sync": "^1.38.0",
|
|
65
|
+
"@wordpress/undo-manager": "^1.38.0",
|
|
66
|
+
"@wordpress/url": "^4.38.0",
|
|
67
|
+
"@wordpress/warning": "^3.38.0",
|
|
68
68
|
"change-case": "^4.1.2",
|
|
69
69
|
"equivalent-key-map": "^0.2.2",
|
|
70
70
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"publishConfig": {
|
|
82
82
|
"access": "public"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "50c4c0f51e4797c217946ce42adfaa5eb026f33f"
|
|
85
85
|
}
|
package/src/actions.js
CHANGED
|
@@ -411,8 +411,8 @@ export const editEntityRecord =
|
|
|
411
411
|
return acc;
|
|
412
412
|
}, {} ),
|
|
413
413
|
};
|
|
414
|
-
if (
|
|
415
|
-
if (
|
|
414
|
+
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
|
|
415
|
+
if ( entityConfig.syncConfig ) {
|
|
416
416
|
const objectType = `${ kind }/${ name }`;
|
|
417
417
|
const objectId = recordId;
|
|
418
418
|
|
|
@@ -714,6 +714,17 @@ export const saveEntityRecord =
|
|
|
714
714
|
true,
|
|
715
715
|
edits
|
|
716
716
|
);
|
|
717
|
+
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
|
|
718
|
+
if ( entityConfig.syncConfig ) {
|
|
719
|
+
getSyncManager()?.update(
|
|
720
|
+
`${ kind }/${ name }`,
|
|
721
|
+
recordId,
|
|
722
|
+
updatedRecord,
|
|
723
|
+
LOCAL_EDITOR_ORIGIN,
|
|
724
|
+
true // isSave
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
717
728
|
}
|
|
718
729
|
} catch ( _error ) {
|
|
719
730
|
hasError = true;
|
package/src/entities.js
CHANGED
|
@@ -16,8 +16,6 @@ import { __ } from '@wordpress/i18n';
|
|
|
16
16
|
import { getSyncManager } from './sync';
|
|
17
17
|
import {
|
|
18
18
|
applyPostChangesToCRDTDoc,
|
|
19
|
-
defaultApplyChangesToCRDTDoc,
|
|
20
|
-
defaultGetChangesFromCRDTDoc,
|
|
21
19
|
getPostChangesFromCRDTDoc,
|
|
22
20
|
} from './utils/crdt';
|
|
23
21
|
|
|
@@ -280,8 +278,8 @@ export const prePersistPostType = (
|
|
|
280
278
|
}
|
|
281
279
|
|
|
282
280
|
// Add meta for persisted CRDT document.
|
|
283
|
-
if (
|
|
284
|
-
if (
|
|
281
|
+
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
|
|
282
|
+
if ( persistedRecord ) {
|
|
285
283
|
const objectType = `postType/${ name }`;
|
|
286
284
|
const objectId = persistedRecord.id;
|
|
287
285
|
const meta = getSyncManager()?.createMeta( objectType, objectId );
|
|
@@ -344,48 +342,46 @@ async function loadPostTypeEntities() {
|
|
|
344
342
|
: DEFAULT_ENTITY_KEY,
|
|
345
343
|
};
|
|
346
344
|
|
|
347
|
-
if (
|
|
348
|
-
|
|
345
|
+
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
|
|
346
|
+
/**
|
|
347
|
+
* @type {import('@wordpress/sync').SyncConfig}
|
|
348
|
+
*/
|
|
349
|
+
entity.syncConfig = {
|
|
349
350
|
/**
|
|
350
|
-
*
|
|
351
|
+
* Apply changes from the local editor to the local CRDT document so
|
|
352
|
+
* that those changes can be synced to other peers (via the provider).
|
|
353
|
+
*
|
|
354
|
+
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
|
|
355
|
+
* @param {Partial< import('@wordpress/sync').ObjectData >} changes
|
|
356
|
+
* @return {void}
|
|
351
357
|
*/
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
* Apply changes from the local editor to the local CRDT document so
|
|
355
|
-
* that those changes can be synced to other peers (via the provider).
|
|
356
|
-
*
|
|
357
|
-
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
|
|
358
|
-
* @param {Partial< import('@wordpress/sync').ObjectData >} changes
|
|
359
|
-
* @return {void}
|
|
360
|
-
*/
|
|
361
|
-
applyChangesToCRDTDoc: ( crdtDoc, changes ) =>
|
|
362
|
-
applyPostChangesToCRDTDoc( crdtDoc, changes, postType ),
|
|
358
|
+
applyChangesToCRDTDoc: ( crdtDoc, changes ) =>
|
|
359
|
+
applyPostChangesToCRDTDoc( crdtDoc, changes, postType ),
|
|
363
360
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
361
|
+
/**
|
|
362
|
+
* Extract changes from a CRDT document that can be used to update the
|
|
363
|
+
* local editor state.
|
|
364
|
+
*
|
|
365
|
+
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
|
|
366
|
+
* @param {import('@wordpress/sync').ObjectData} editedRecord
|
|
367
|
+
* @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record
|
|
368
|
+
*/
|
|
369
|
+
getChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>
|
|
370
|
+
getPostChangesFromCRDTDoc(
|
|
371
|
+
crdtDoc,
|
|
372
|
+
editedRecord,
|
|
373
|
+
postType
|
|
374
|
+
),
|
|
378
375
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
376
|
+
/**
|
|
377
|
+
* Sync features supported by the entity.
|
|
378
|
+
*
|
|
379
|
+
* @type {Record< string, boolean >}
|
|
380
|
+
*/
|
|
381
|
+
supports: {
|
|
382
|
+
crdtPersistence: true,
|
|
383
|
+
},
|
|
384
|
+
};
|
|
389
385
|
}
|
|
390
386
|
|
|
391
387
|
return entity;
|
|
@@ -430,18 +426,6 @@ async function loadSiteEntity() {
|
|
|
430
426
|
meta: {},
|
|
431
427
|
};
|
|
432
428
|
|
|
433
|
-
if ( window.__experimentalEnableSync ) {
|
|
434
|
-
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
|
|
435
|
-
/**
|
|
436
|
-
* @type {import('@wordpress/sync').SyncConfig}
|
|
437
|
-
*/
|
|
438
|
-
entity.syncConfig = {
|
|
439
|
-
applyChangesToCRDTDoc: defaultApplyChangesToCRDTDoc,
|
|
440
|
-
getChangesFromCRDTDoc: defaultGetChangesFromCRDTDoc,
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
429
|
const site = await apiFetch( {
|
|
446
430
|
path: entity.baseURL,
|
|
447
431
|
method: 'OPTIONS',
|
package/src/private-selectors.ts
CHANGED
|
@@ -35,10 +35,9 @@ type EntityRecordKey = string | number;
|
|
|
35
35
|
* @return The undo manager.
|
|
36
36
|
*/
|
|
37
37
|
export function getUndoManager( state: State ) {
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
38
|
+
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
|
|
39
|
+
// undoManager is undefined until the first sync-enabled entity is loaded.
|
|
40
|
+
return getSyncManager()?.undoManager ?? state.undoManager;
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
return state.undoManager;
|
package/src/resolvers.js
CHANGED
|
@@ -155,13 +155,12 @@ export const getEntityRecord =
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
// Entity supports syncing.
|
|
158
|
-
if (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
|
|
158
|
+
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
|
|
159
|
+
if (
|
|
160
|
+
entityConfig.syncConfig &&
|
|
161
|
+
isNumericID( key ) &&
|
|
162
|
+
! query
|
|
163
|
+
) {
|
|
165
164
|
const objectType = `${ kind }/${ name }`;
|
|
166
165
|
const objectId = key;
|
|
167
166
|
|
|
@@ -216,6 +215,15 @@ export const getEntityRecord =
|
|
|
216
215
|
name,
|
|
217
216
|
key
|
|
218
217
|
),
|
|
218
|
+
// Refetch the current entity record from the database.
|
|
219
|
+
refetchRecord: async () => {
|
|
220
|
+
dispatch.receiveEntityRecords(
|
|
221
|
+
kind,
|
|
222
|
+
name,
|
|
223
|
+
await apiFetch( { path, parse: true } ),
|
|
224
|
+
query
|
|
225
|
+
);
|
|
226
|
+
},
|
|
219
227
|
// Save the current entity record's unsaved edits.
|
|
220
228
|
saveRecord: () => {
|
|
221
229
|
dispatch.saveEditedEntityRecord(
|
package/src/test/entities.js
CHANGED
|
@@ -53,14 +53,15 @@ describe( 'prePersistPostType', () => {
|
|
|
53
53
|
expect( prePersistPostType( record, edits, 'post', false ) ).toEqual( {
|
|
54
54
|
status: 'draft',
|
|
55
55
|
title: '',
|
|
56
|
+
meta: {},
|
|
56
57
|
} );
|
|
57
58
|
|
|
58
59
|
record = {
|
|
59
60
|
status: 'publish',
|
|
60
61
|
};
|
|
61
|
-
expect( prePersistPostType( record, edits, 'post', false ) ).toEqual(
|
|
62
|
-
{}
|
|
63
|
-
);
|
|
62
|
+
expect( prePersistPostType( record, edits, 'post', false ) ).toEqual( {
|
|
63
|
+
meta: {},
|
|
64
|
+
} );
|
|
64
65
|
|
|
65
66
|
record = {
|
|
66
67
|
status: 'auto-draft',
|
|
@@ -69,15 +70,16 @@ describe( 'prePersistPostType', () => {
|
|
|
69
70
|
expect( prePersistPostType( record, edits, 'post', false ) ).toEqual( {
|
|
70
71
|
status: 'draft',
|
|
71
72
|
title: '',
|
|
73
|
+
meta: {},
|
|
72
74
|
} );
|
|
73
75
|
|
|
74
76
|
record = {
|
|
75
77
|
status: 'publish',
|
|
76
78
|
title: 'My Title',
|
|
77
79
|
};
|
|
78
|
-
expect( prePersistPostType( record, edits, 'post', false ) ).toEqual(
|
|
79
|
-
{}
|
|
80
|
-
);
|
|
80
|
+
expect( prePersistPostType( record, edits, 'post', false ) ).toEqual( {
|
|
81
|
+
meta: {},
|
|
82
|
+
} );
|
|
81
83
|
} );
|
|
82
84
|
|
|
83
85
|
it( 'does not set the status to draft and empty the title when saving templates', () => {
|
|
@@ -86,9 +88,9 @@ describe( 'prePersistPostType', () => {
|
|
|
86
88
|
title: 'Auto Draft',
|
|
87
89
|
};
|
|
88
90
|
const edits = {};
|
|
89
|
-
expect( prePersistPostType( record, edits, 'post', true ) ).toEqual(
|
|
90
|
-
{}
|
|
91
|
-
);
|
|
91
|
+
expect( prePersistPostType( record, edits, 'post', true ) ).toEqual( {
|
|
92
|
+
meta: {},
|
|
93
|
+
} );
|
|
92
94
|
} );
|
|
93
95
|
} );
|
|
94
96
|
|
package/src/test/resolvers.js
CHANGED
|
@@ -59,10 +59,6 @@ describe( 'getEntityRecord', () => {
|
|
|
59
59
|
getSyncManager.mockImplementation( () => syncManager );
|
|
60
60
|
} );
|
|
61
61
|
|
|
62
|
-
afterEach( () => {
|
|
63
|
-
delete window.__experimentalEnableSync;
|
|
64
|
-
} );
|
|
65
|
-
|
|
66
62
|
it( 'yields with requested post type', async () => {
|
|
67
63
|
// Provide response
|
|
68
64
|
triggerFetch.mockImplementation( () => POST_TYPE_RESPONSE );
|
|
@@ -132,7 +128,7 @@ describe( 'getEntityRecord', () => {
|
|
|
132
128
|
);
|
|
133
129
|
} );
|
|
134
130
|
|
|
135
|
-
it( 'loads entity with sync manager when
|
|
131
|
+
it( 'loads entity with sync manager when IS_GUTENBERG_PLUGIN is true', async () => {
|
|
136
132
|
const POST_RECORD = { id: 1, title: 'Test Post' };
|
|
137
133
|
const POST_RESPONSE = {
|
|
138
134
|
json: () => Promise.resolve( POST_RECORD ),
|
|
@@ -147,8 +143,6 @@ describe( 'getEntityRecord', () => {
|
|
|
147
143
|
},
|
|
148
144
|
];
|
|
149
145
|
|
|
150
|
-
window.__experimentalEnableSync = true;
|
|
151
|
-
|
|
152
146
|
const resolveSelectWithSync = {
|
|
153
147
|
getEntitiesConfig: jest.fn( () => ENTITIES_WITH_SYNC ),
|
|
154
148
|
getEditedEntityRecord: jest.fn(),
|
|
@@ -176,6 +170,7 @@ describe( 'getEntityRecord', () => {
|
|
|
176
170
|
{
|
|
177
171
|
editRecord: expect.any( Function ),
|
|
178
172
|
getEditedRecord: expect.any( Function ),
|
|
173
|
+
refetchRecord: expect.any( Function ),
|
|
179
174
|
saveRecord: expect.any( Function ),
|
|
180
175
|
}
|
|
181
176
|
);
|
|
@@ -201,8 +196,6 @@ describe( 'getEntityRecord', () => {
|
|
|
201
196
|
},
|
|
202
197
|
];
|
|
203
198
|
|
|
204
|
-
window.__experimentalEnableSync = true;
|
|
205
|
-
|
|
206
199
|
const resolveSelectWithSync = {
|
|
207
200
|
getEntitiesConfig: jest.fn( () => ENTITIES_WITH_SYNC ),
|
|
208
201
|
getEditedEntityRecord: jest.fn(),
|
|
@@ -230,6 +223,7 @@ describe( 'getEntityRecord', () => {
|
|
|
230
223
|
{
|
|
231
224
|
editRecord: expect.any( Function ),
|
|
232
225
|
getEditedRecord: expect.any( Function ),
|
|
226
|
+
refetchRecord: expect.any( Function ),
|
|
233
227
|
saveRecord: expect.any( Function ),
|
|
234
228
|
}
|
|
235
229
|
);
|
|
@@ -250,8 +244,6 @@ describe( 'getEntityRecord', () => {
|
|
|
250
244
|
},
|
|
251
245
|
];
|
|
252
246
|
|
|
253
|
-
window.__experimentalEnableSync = true;
|
|
254
|
-
|
|
255
247
|
const resolveSelectWithSync = {
|
|
256
248
|
getEntitiesConfig: jest.fn( () => ENTITIES_WITH_SYNC ),
|
|
257
249
|
};
|
|
@@ -267,40 +259,6 @@ describe( 'getEntityRecord', () => {
|
|
|
267
259
|
|
|
268
260
|
expect( syncManager.load ).not.toHaveBeenCalled();
|
|
269
261
|
} );
|
|
270
|
-
|
|
271
|
-
it( 'does not load entity when __experimentalEnableSync is undefined', async () => {
|
|
272
|
-
const POST_RECORD = { id: 1, title: 'Test Post' };
|
|
273
|
-
const POST_RESPONSE = {
|
|
274
|
-
json: () => Promise.resolve( POST_RECORD ),
|
|
275
|
-
};
|
|
276
|
-
const ENTITIES_WITH_SYNC = [
|
|
277
|
-
{
|
|
278
|
-
name: 'post',
|
|
279
|
-
kind: 'postType',
|
|
280
|
-
baseURL: '/wp/v2/posts',
|
|
281
|
-
baseURLParams: { context: 'edit' },
|
|
282
|
-
syncConfig: {},
|
|
283
|
-
},
|
|
284
|
-
];
|
|
285
|
-
|
|
286
|
-
const resolveSelectWithSync = {
|
|
287
|
-
getEntitiesConfig: jest.fn( () => ENTITIES_WITH_SYNC ),
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
triggerFetch.mockImplementation( () => POST_RESPONSE );
|
|
291
|
-
|
|
292
|
-
await getEntityRecord(
|
|
293
|
-
'postType',
|
|
294
|
-
'post',
|
|
295
|
-
1
|
|
296
|
-
)( {
|
|
297
|
-
dispatch,
|
|
298
|
-
registry,
|
|
299
|
-
resolveSelect: resolveSelectWithSync,
|
|
300
|
-
} );
|
|
301
|
-
|
|
302
|
-
expect( syncManager.load ).not.toHaveBeenCalled();
|
|
303
|
-
} );
|
|
304
262
|
} );
|
|
305
263
|
|
|
306
264
|
describe( 'getEntityRecords', () => {
|