@wordpress/core-data 7.33.0 → 7.33.1-next.36001005c.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 +1 -1
- package/build/actions.js.map +2 -2
- package/build/entities.js +44 -32
- package/build/entities.js.map +2 -2
- package/build/resolvers.js +1 -1
- package/build/resolvers.js.map +2 -2
- package/build/sync.js +10 -3
- package/build/sync.js.map +2 -2
- package/build-module/actions.js +2 -2
- package/build-module/actions.js.map +2 -2
- package/build-module/entities.js +44 -32
- package/build-module/entities.js.map +2 -2
- package/build-module/resolvers.js +2 -2
- package/build-module/resolvers.js.map +2 -2
- package/build-module/sync.js +9 -2
- package/build-module/sync.js.map +2 -2
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/sync.d.ts +2 -2
- package/build-types/sync.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/actions.js +2 -2
- package/src/entities.js +57 -40
- package/src/resolvers.js +2 -2
- package/src/sync.ts +13 -1
- package/src/test/resolvers.js +9 -5
- package/tsconfig.tsbuildinfo +1 -1
package/src/actions.js
CHANGED
|
@@ -19,7 +19,7 @@ import { receiveItems, removeItems, receiveQueriedItems } from './queried-data';
|
|
|
19
19
|
import { DEFAULT_ENTITY_KEY } from './entities';
|
|
20
20
|
import { createBatch } from './batch';
|
|
21
21
|
import { STORE_NAME } from './name';
|
|
22
|
-
import { LOCAL_EDITOR_ORIGIN,
|
|
22
|
+
import { LOCAL_EDITOR_ORIGIN, getSyncManager } from './sync';
|
|
23
23
|
import logEntityDeprecation from './utils/log-entity-deprecation';
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -415,7 +415,7 @@ export const editEntityRecord =
|
|
|
415
415
|
const objectType = `${ kind }/${ name }`;
|
|
416
416
|
const objectId = recordId;
|
|
417
417
|
|
|
418
|
-
|
|
418
|
+
getSyncManager()?.update(
|
|
419
419
|
objectType,
|
|
420
420
|
objectId,
|
|
421
421
|
edit.edits,
|
package/src/entities.js
CHANGED
|
@@ -272,41 +272,7 @@ async function loadPostTypeEntities() {
|
|
|
272
272
|
);
|
|
273
273
|
const namespace = postType?.rest_namespace ?? 'wp/v2';
|
|
274
274
|
|
|
275
|
-
|
|
276
|
-
* @type {import('@wordpress/sync').SyncConfig}
|
|
277
|
-
*/
|
|
278
|
-
const syncConfig = {
|
|
279
|
-
/**
|
|
280
|
-
* Apply changes from the local editor to the local CRDT document so
|
|
281
|
-
* that those changes can be synced to other peers (via the provider).
|
|
282
|
-
*
|
|
283
|
-
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
|
|
284
|
-
* @param {Partial< import('@wordpress/sync').ObjectData >} changes
|
|
285
|
-
* @return {void}
|
|
286
|
-
*/
|
|
287
|
-
applyChangesToCRDTDoc: ( crdtDoc, changes ) =>
|
|
288
|
-
applyPostChangesToCRDTDoc( crdtDoc, changes, postType ),
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Extract changes from a CRDT document that can be used to update the
|
|
292
|
-
* local editor state.
|
|
293
|
-
*
|
|
294
|
-
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
|
|
295
|
-
* @param {import('@wordpress/sync').ObjectData} editedRecord
|
|
296
|
-
* @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record
|
|
297
|
-
*/
|
|
298
|
-
getChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>
|
|
299
|
-
getPostChangesFromCRDTDoc( crdtDoc, editedRecord, postType ),
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Sync features supported by the entity.
|
|
303
|
-
*
|
|
304
|
-
* @type {Record< string, boolean >}
|
|
305
|
-
*/
|
|
306
|
-
supports: {},
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
return {
|
|
275
|
+
const entity = {
|
|
310
276
|
kind: 'postType',
|
|
311
277
|
baseURL: `/${ namespace }/${ postType.rest_base }`,
|
|
312
278
|
baseURLParams: { context: 'edit' },
|
|
@@ -326,7 +292,6 @@ async function loadPostTypeEntities() {
|
|
|
326
292
|
: String( record.id ) ),
|
|
327
293
|
__unstablePrePersist: isTemplate ? undefined : prePersistPostType,
|
|
328
294
|
__unstable_rest_base: postType.rest_base,
|
|
329
|
-
syncConfig,
|
|
330
295
|
supportsPagination: true,
|
|
331
296
|
getRevisionsUrl: ( parentId, revisionId ) =>
|
|
332
297
|
`/${ namespace }/${
|
|
@@ -336,6 +301,50 @@ async function loadPostTypeEntities() {
|
|
|
336
301
|
}`,
|
|
337
302
|
revisionKey: DEFAULT_ENTITY_KEY,
|
|
338
303
|
};
|
|
304
|
+
|
|
305
|
+
if ( window.__experimentalEnableSync ) {
|
|
306
|
+
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
|
|
307
|
+
/**
|
|
308
|
+
* @type {import('@wordpress/sync').SyncConfig}
|
|
309
|
+
*/
|
|
310
|
+
entity.syncConfig = {
|
|
311
|
+
/**
|
|
312
|
+
* Apply changes from the local editor to the local CRDT document so
|
|
313
|
+
* that those changes can be synced to other peers (via the provider).
|
|
314
|
+
*
|
|
315
|
+
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
|
|
316
|
+
* @param {Partial< import('@wordpress/sync').ObjectData >} changes
|
|
317
|
+
* @return {void}
|
|
318
|
+
*/
|
|
319
|
+
applyChangesToCRDTDoc: ( crdtDoc, changes ) =>
|
|
320
|
+
applyPostChangesToCRDTDoc( crdtDoc, changes, postType ),
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Extract changes from a CRDT document that can be used to update the
|
|
324
|
+
* local editor state.
|
|
325
|
+
*
|
|
326
|
+
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
|
|
327
|
+
* @param {import('@wordpress/sync').ObjectData} editedRecord
|
|
328
|
+
* @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record
|
|
329
|
+
*/
|
|
330
|
+
getChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>
|
|
331
|
+
getPostChangesFromCRDTDoc(
|
|
332
|
+
crdtDoc,
|
|
333
|
+
editedRecord,
|
|
334
|
+
postType
|
|
335
|
+
),
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Sync features supported by the entity.
|
|
339
|
+
*
|
|
340
|
+
* @type {Record< string, boolean >}
|
|
341
|
+
*/
|
|
342
|
+
supports: {},
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return entity;
|
|
339
348
|
} );
|
|
340
349
|
}
|
|
341
350
|
|
|
@@ -373,13 +382,21 @@ async function loadSiteEntity() {
|
|
|
373
382
|
name: 'site',
|
|
374
383
|
kind: 'root',
|
|
375
384
|
baseURL: '/wp/v2/settings',
|
|
376
|
-
syncConfig: {
|
|
377
|
-
applyChangesToCRDTDoc: defaultApplyChangesToCRDTDoc,
|
|
378
|
-
getChangesFromCRDTDoc: defaultGetChangesFromCRDTDoc,
|
|
379
|
-
},
|
|
380
385
|
meta: {},
|
|
381
386
|
};
|
|
382
387
|
|
|
388
|
+
if ( window.__experimentalEnableSync ) {
|
|
389
|
+
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
|
|
390
|
+
/**
|
|
391
|
+
* @type {import('@wordpress/sync').SyncConfig}
|
|
392
|
+
*/
|
|
393
|
+
entity.syncConfig = {
|
|
394
|
+
applyChangesToCRDTDoc: defaultApplyChangesToCRDTDoc,
|
|
395
|
+
getChangesFromCRDTDoc: defaultGetChangesFromCRDTDoc,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
383
400
|
const site = await apiFetch( {
|
|
384
401
|
path: entity.baseURL,
|
|
385
402
|
method: 'OPTIONS',
|
package/src/resolvers.js
CHANGED
|
@@ -15,7 +15,7 @@ import apiFetch from '@wordpress/api-fetch';
|
|
|
15
15
|
*/
|
|
16
16
|
import { STORE_NAME } from './name';
|
|
17
17
|
import { additionalEntityConfigLoaders, DEFAULT_ENTITY_KEY } from './entities';
|
|
18
|
-
import {
|
|
18
|
+
import { getSyncManager } from './sync';
|
|
19
19
|
import {
|
|
20
20
|
forwardResolver,
|
|
21
21
|
getNormalizedCommaSeparable,
|
|
@@ -185,7 +185,7 @@ export const getEntityRecord =
|
|
|
185
185
|
} );
|
|
186
186
|
|
|
187
187
|
// Load the entity record for syncing.
|
|
188
|
-
await
|
|
188
|
+
await getSyncManager()?.load(
|
|
189
189
|
entityConfig.syncConfig,
|
|
190
190
|
objectType,
|
|
191
191
|
objectId,
|
package/src/sync.ts
CHANGED
|
@@ -5,8 +5,20 @@ import {
|
|
|
5
5
|
CRDT_RECORD_MAP_KEY,
|
|
6
6
|
LOCAL_EDITOR_ORIGIN,
|
|
7
7
|
LOCAL_SYNC_MANAGER_ORIGIN,
|
|
8
|
+
type SyncManager,
|
|
8
9
|
createSyncManager,
|
|
9
10
|
} from '@wordpress/sync';
|
|
10
11
|
|
|
11
12
|
export { CRDT_RECORD_MAP_KEY, LOCAL_EDITOR_ORIGIN, LOCAL_SYNC_MANAGER_ORIGIN };
|
|
12
|
-
|
|
13
|
+
|
|
14
|
+
let syncManager: SyncManager;
|
|
15
|
+
|
|
16
|
+
export function getSyncManager(): SyncManager | undefined {
|
|
17
|
+
if ( syncManager ) {
|
|
18
|
+
return syncManager;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
syncManager = createSyncManager();
|
|
22
|
+
|
|
23
|
+
return syncManager;
|
|
24
|
+
}
|
package/src/test/resolvers.js
CHANGED
|
@@ -6,13 +6,11 @@ import triggerFetch from '@wordpress/api-fetch';
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { getSyncManager } from '../sync';
|
|
10
10
|
|
|
11
11
|
jest.mock( '@wordpress/api-fetch' );
|
|
12
12
|
jest.mock( '../sync', () => ( {
|
|
13
|
-
|
|
14
|
-
load: jest.fn(),
|
|
15
|
-
},
|
|
13
|
+
getSyncManager: jest.fn(),
|
|
16
14
|
} ) );
|
|
17
15
|
|
|
18
16
|
/**
|
|
@@ -42,6 +40,8 @@ describe( 'getEntityRecord', () => {
|
|
|
42
40
|
const resolveSelect = { getEntitiesConfig: jest.fn( () => ENTITIES ) };
|
|
43
41
|
|
|
44
42
|
let dispatch;
|
|
43
|
+
let syncManager;
|
|
44
|
+
|
|
45
45
|
beforeEach( async () => {
|
|
46
46
|
dispatch = Object.assign( jest.fn(), {
|
|
47
47
|
receiveEntityRecords: jest.fn(),
|
|
@@ -51,7 +51,11 @@ describe( 'getEntityRecord', () => {
|
|
|
51
51
|
finishResolutions: jest.fn(),
|
|
52
52
|
} );
|
|
53
53
|
triggerFetch.mockReset();
|
|
54
|
-
|
|
54
|
+
|
|
55
|
+
syncManager = {
|
|
56
|
+
load: jest.fn(),
|
|
57
|
+
};
|
|
58
|
+
getSyncManager.mockImplementation( () => syncManager );
|
|
55
59
|
} );
|
|
56
60
|
|
|
57
61
|
afterEach( () => {
|