@wordpress/core-data 7.40.0 → 7.40.1-next.v.202602191100.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.cjs +23 -29
- package/build/actions.cjs.map +2 -2
- package/build/entities.cjs +51 -63
- package/build/entities.cjs.map +2 -2
- package/build/private-selectors.cjs +1 -4
- package/build/private-selectors.cjs.map +2 -2
- package/build/resolvers.cjs +97 -108
- package/build/resolvers.cjs.map +2 -2
- package/build-module/actions.mjs +23 -29
- package/build-module/actions.mjs.map +2 -2
- package/build-module/entities.mjs +51 -63
- package/build-module/entities.mjs.map +2 -2
- package/build-module/private-selectors.mjs +1 -4
- package/build-module/private-selectors.mjs.map +2 -2
- package/build-module/resolvers.mjs +97 -108
- package/build-module/resolvers.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/package.json +18 -18
- package/src/actions.js +39 -45
- package/src/entities.js +54 -66
- package/src/private-selectors.ts +2 -6
- package/src/resolvers.js +129 -145
- package/src/test/resolvers.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-selectors.d.ts","sourceRoot":"","sources":["../src/private-selectors.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,EAGN,KAAK,KAAK,EACV,KAAK,IAAI,EACT,MAAM,aAAa,CAAC;AAMrB,KAAK,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAE,KAAK,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"private-selectors.d.ts","sourceRoot":"","sources":["../src/private-selectors.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,EAGN,KAAK,KAAK,EACV,KAAK,IAAI,EACT,MAAM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M,mCAPI,MAAM,QACN,MAAM,aACN,MAAM,GAAC,MAAM,UACb,MAAO,SAAS,IAMlB;;;;CAAqC,mBAkG5C;;IAGF,sFAK8B;;AAavB,kCARI,MAAM,QACN,MAAM,aACN,MAAM,GAAC,MAAM,eACb,MAAM,GAAC,MAAM,SACb,MAAO,SAAS,IAMlB;;;CAA2B,mBAyClC;AAOK,gDAFI,MAAM,IAIR;;;CAA2B,mBAsBlC;AAOK,wCAFI,MAAM,IAIR;;CAAY,mBAmBnB;AAKK,sCAEE;;CAAY,mBAKnB;AAKK,oCAEE;;CAAY,mBAKnB;AAKK,6BAEE;;CAAY,mBAKnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/core-data",
|
|
3
|
-
"version": "7.40.0",
|
|
3
|
+
"version": "7.40.1-next.v.202602191100.0+2f8ac7442",
|
|
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.40.0",
|
|
53
|
-
"@wordpress/block-editor": "^15.13.0",
|
|
54
|
-
"@wordpress/blocks": "^15.13.0",
|
|
55
|
-
"@wordpress/compose": "^7.40.0",
|
|
56
|
-
"@wordpress/data": "^10.40.0",
|
|
57
|
-
"@wordpress/deprecated": "^4.40.0",
|
|
58
|
-
"@wordpress/element": "^6.40.0",
|
|
59
|
-
"@wordpress/html-entities": "^4.40.0",
|
|
60
|
-
"@wordpress/i18n": "^6.13.0",
|
|
61
|
-
"@wordpress/is-shallow-equal": "^5.40.0",
|
|
62
|
-
"@wordpress/private-apis": "^1.40.0",
|
|
63
|
-
"@wordpress/rich-text": "^7.40.0",
|
|
64
|
-
"@wordpress/sync": "^1.40.0",
|
|
65
|
-
"@wordpress/undo-manager": "^1.40.0",
|
|
66
|
-
"@wordpress/url": "^4.40.0",
|
|
67
|
-
"@wordpress/warning": "^3.40.0",
|
|
52
|
+
"@wordpress/api-fetch": "^7.40.1-next.v.202602191100.0+2f8ac7442",
|
|
53
|
+
"@wordpress/block-editor": "^15.13.1-next.v.202602191100.0+2f8ac7442",
|
|
54
|
+
"@wordpress/blocks": "^15.13.1-next.v.202602191100.0+2f8ac7442",
|
|
55
|
+
"@wordpress/compose": "^7.40.1-next.v.202602191100.0+2f8ac7442",
|
|
56
|
+
"@wordpress/data": "^10.40.1-next.v.202602191100.0+2f8ac7442",
|
|
57
|
+
"@wordpress/deprecated": "^4.40.1-next.v.202602191100.0+2f8ac7442",
|
|
58
|
+
"@wordpress/element": "^6.40.1-next.v.202602191100.0+2f8ac7442",
|
|
59
|
+
"@wordpress/html-entities": "^4.40.1-next.v.202602191100.0+2f8ac7442",
|
|
60
|
+
"@wordpress/i18n": "^6.13.1-next.v.202602191100.0+2f8ac7442",
|
|
61
|
+
"@wordpress/is-shallow-equal": "^5.40.1-next.v.202602191100.0+2f8ac7442",
|
|
62
|
+
"@wordpress/private-apis": "^1.40.1-next.v.202602191100.0+2f8ac7442",
|
|
63
|
+
"@wordpress/rich-text": "^7.40.1-next.v.202602191100.0+2f8ac7442",
|
|
64
|
+
"@wordpress/sync": "^1.40.1-next.v.202602191100.0+2f8ac7442",
|
|
65
|
+
"@wordpress/undo-manager": "^1.40.1-next.v.202602191100.0+2f8ac7442",
|
|
66
|
+
"@wordpress/url": "^4.40.1-next.v.202602191100.0+2f8ac7442",
|
|
67
|
+
"@wordpress/warning": "^3.40.1-next.v.202602191100.0+2f8ac7442",
|
|
68
68
|
"change-case": "^4.1.2",
|
|
69
69
|
"equivalent-key-map": "^0.2.2",
|
|
70
70
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"publishConfig": {
|
|
85
85
|
"access": "public"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "de48b2351a7efb8a33a83067612960a0cf239592"
|
|
88
88
|
}
|
package/src/actions.js
CHANGED
|
@@ -340,13 +340,11 @@ export const deleteEntityRecord =
|
|
|
340
340
|
|
|
341
341
|
await dispatch( removeItems( kind, name, recordId, true ) );
|
|
342
342
|
|
|
343
|
-
if (
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const objectId = recordId;
|
|
343
|
+
if ( entityConfig.syncConfig ) {
|
|
344
|
+
const objectType = `${ kind }/${ name }`;
|
|
345
|
+
const objectId = recordId;
|
|
347
346
|
|
|
348
|
-
|
|
349
|
-
}
|
|
347
|
+
getSyncManager()?.unload( objectType, objectId );
|
|
350
348
|
}
|
|
351
349
|
} catch ( _error ) {
|
|
352
350
|
hasError = true;
|
|
@@ -427,35 +425,33 @@ export const editEntityRecord =
|
|
|
427
425
|
return acc;
|
|
428
426
|
}, {} ),
|
|
429
427
|
};
|
|
430
|
-
if (
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
);
|
|
458
|
-
}
|
|
428
|
+
if ( entityConfig.syncConfig ) {
|
|
429
|
+
const objectType = `${ kind }/${ name }`;
|
|
430
|
+
const objectId = recordId;
|
|
431
|
+
|
|
432
|
+
// Determine whether this edit should create a new undo level.
|
|
433
|
+
//
|
|
434
|
+
// In Gutenberg, block changes flow through two callbacks:
|
|
435
|
+
// - `onInput`: For transient/in-progress changes (e.g., typing each
|
|
436
|
+
// character). These use `isCached: true` and get merged into
|
|
437
|
+
// the current undo item.
|
|
438
|
+
// - `onChange`: For persistent/completed changes (e.g., formatting
|
|
439
|
+
// transforms, block insertions). These use `isCached: false` and
|
|
440
|
+
// should create a new undo level.
|
|
441
|
+
//
|
|
442
|
+
// Additionally, `undoIgnore: true` means the change should not
|
|
443
|
+
// affect the undo history at all (e.g., selection-only changes).
|
|
444
|
+
const isNewUndoLevel = options.undoIgnore
|
|
445
|
+
? false
|
|
446
|
+
: ! options.isCached;
|
|
447
|
+
|
|
448
|
+
getSyncManager()?.update(
|
|
449
|
+
objectType,
|
|
450
|
+
objectId,
|
|
451
|
+
editsWithMerges,
|
|
452
|
+
LOCAL_EDITOR_ORIGIN,
|
|
453
|
+
{ isNewUndoLevel }
|
|
454
|
+
);
|
|
459
455
|
}
|
|
460
456
|
if ( ! options.undoIgnore ) {
|
|
461
457
|
select.getUndoManager().addRecord(
|
|
@@ -796,16 +792,14 @@ export const saveEntityRecord =
|
|
|
796
792
|
true,
|
|
797
793
|
edits
|
|
798
794
|
);
|
|
799
|
-
if (
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
);
|
|
808
|
-
}
|
|
795
|
+
if ( entityConfig.syncConfig ) {
|
|
796
|
+
getSyncManager()?.update(
|
|
797
|
+
`${ kind }/${ name }`,
|
|
798
|
+
recordId,
|
|
799
|
+
updatedRecord,
|
|
800
|
+
LOCAL_EDITOR_ORIGIN,
|
|
801
|
+
{ isSave: true }
|
|
802
|
+
);
|
|
809
803
|
}
|
|
810
804
|
}
|
|
811
805
|
} catch ( _error ) {
|
package/src/entities.js
CHANGED
|
@@ -229,10 +229,8 @@ export const rootEntitiesConfig = [
|
|
|
229
229
|
].map( ( entity ) => {
|
|
230
230
|
const syncEnabledRootEntities = new Set( [ 'comment' ] );
|
|
231
231
|
|
|
232
|
-
if (
|
|
233
|
-
|
|
234
|
-
entity.syncConfig = defaultSyncConfig;
|
|
235
|
-
}
|
|
232
|
+
if ( syncEnabledRootEntities.has( entity.name ) ) {
|
|
233
|
+
entity.syncConfig = defaultSyncConfig;
|
|
236
234
|
}
|
|
237
235
|
return entity;
|
|
238
236
|
} );
|
|
@@ -295,16 +293,14 @@ export const prePersistPostType = (
|
|
|
295
293
|
}
|
|
296
294
|
|
|
297
295
|
// Add meta for persisted CRDT document.
|
|
298
|
-
if (
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
};
|
|
307
|
-
}
|
|
296
|
+
if ( persistedRecord ) {
|
|
297
|
+
const objectType = `postType/${ name }`;
|
|
298
|
+
const objectId = persistedRecord.id;
|
|
299
|
+
const meta = getSyncManager()?.createMeta( objectType, objectId );
|
|
300
|
+
newEdits.meta = {
|
|
301
|
+
...edits.meta,
|
|
302
|
+
...meta,
|
|
303
|
+
};
|
|
308
304
|
}
|
|
309
305
|
|
|
310
306
|
return newEdits;
|
|
@@ -359,60 +355,54 @@ async function loadPostTypeEntities() {
|
|
|
359
355
|
: DEFAULT_ENTITY_KEY,
|
|
360
356
|
};
|
|
361
357
|
|
|
362
|
-
|
|
358
|
+
/**
|
|
359
|
+
* @type {import('@wordpress/sync').SyncConfig}
|
|
360
|
+
*/
|
|
361
|
+
entity.syncConfig = {
|
|
363
362
|
/**
|
|
364
|
-
*
|
|
363
|
+
* Apply changes from the local editor to the local CRDT document so
|
|
364
|
+
* that those changes can be synced to other peers (via the provider).
|
|
365
|
+
*
|
|
366
|
+
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
|
|
367
|
+
* @param {Partial< import('@wordpress/sync').ObjectData >} changes
|
|
368
|
+
* @return {void}
|
|
365
369
|
*/
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
* Apply changes from the local editor to the local CRDT document so
|
|
369
|
-
* that those changes can be synced to other peers (via the provider).
|
|
370
|
-
*
|
|
371
|
-
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
|
|
372
|
-
* @param {Partial< import('@wordpress/sync').ObjectData >} changes
|
|
373
|
-
* @return {void}
|
|
374
|
-
*/
|
|
375
|
-
applyChangesToCRDTDoc: ( crdtDoc, changes ) =>
|
|
376
|
-
applyPostChangesToCRDTDoc( crdtDoc, changes, postType ),
|
|
370
|
+
applyChangesToCRDTDoc: ( crdtDoc, changes ) =>
|
|
371
|
+
applyPostChangesToCRDTDoc( crdtDoc, changes, postType ),
|
|
377
372
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
373
|
+
/**
|
|
374
|
+
* Create the awareness instance for the entity's CRDT document.
|
|
375
|
+
*
|
|
376
|
+
* @param {import('@wordpress/sync').CRDTDoc} ydoc
|
|
377
|
+
* @param {import('@wordpress/sync').ObjectID} objectId
|
|
378
|
+
* @return {import('@wordpress/sync').Awareness} Awareness instance
|
|
379
|
+
*/
|
|
380
|
+
createAwareness: ( ydoc, objectId ) => {
|
|
381
|
+
const kind = 'postType';
|
|
382
|
+
const id = parseInt( objectId, 10 );
|
|
383
|
+
return new PostEditorAwareness( ydoc, kind, name, id );
|
|
384
|
+
},
|
|
390
385
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
crdtDoc,
|
|
402
|
-
editedRecord,
|
|
403
|
-
postType
|
|
404
|
-
),
|
|
386
|
+
/**
|
|
387
|
+
* Extract changes from a CRDT document that can be used to update the
|
|
388
|
+
* local editor state.
|
|
389
|
+
*
|
|
390
|
+
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
|
|
391
|
+
* @param {import('@wordpress/sync').ObjectData} editedRecord
|
|
392
|
+
* @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record
|
|
393
|
+
*/
|
|
394
|
+
getChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>
|
|
395
|
+
getPostChangesFromCRDTDoc( crdtDoc, editedRecord, postType ),
|
|
405
396
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
397
|
+
/**
|
|
398
|
+
* Sync features supported by the entity.
|
|
399
|
+
*
|
|
400
|
+
* @type {Record< string, boolean >}
|
|
401
|
+
*/
|
|
402
|
+
supports: {
|
|
403
|
+
crdtPersistence: true,
|
|
404
|
+
},
|
|
405
|
+
};
|
|
416
406
|
|
|
417
407
|
return entity;
|
|
418
408
|
} );
|
|
@@ -439,9 +429,7 @@ async function loadTaxonomyEntities() {
|
|
|
439
429
|
supportsPagination: true,
|
|
440
430
|
};
|
|
441
431
|
|
|
442
|
-
|
|
443
|
-
entity.syncConfig = defaultSyncConfig;
|
|
444
|
-
}
|
|
432
|
+
entity.syncConfig = defaultSyncConfig;
|
|
445
433
|
|
|
446
434
|
return entity;
|
|
447
435
|
} );
|
package/src/private-selectors.ts
CHANGED
|
@@ -40,12 +40,8 @@ type EntityRecordKey = string | number;
|
|
|
40
40
|
* @return The undo manager.
|
|
41
41
|
*/
|
|
42
42
|
export function getUndoManager( state: State ) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return getSyncManager()?.undoManager ?? state.undoManager;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return state.undoManager;
|
|
43
|
+
// undoManager is undefined until the first sync-enabled entity is loaded.
|
|
44
|
+
return getSyncManager()?.undoManager ?? state.undoManager;
|
|
49
45
|
}
|
|
50
46
|
|
|
51
47
|
/**
|
package/src/resolvers.js
CHANGED
|
@@ -156,126 +156,112 @@ export const getEntityRecord =
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
// Entity supports syncing.
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
159
|
+
if ( entityConfig.syncConfig && isNumericID( key ) && ! query ) {
|
|
160
|
+
const objectType = `${ kind }/${ name }`;
|
|
161
|
+
const objectId = key;
|
|
162
|
+
|
|
163
|
+
// Use the new transient "read/write" config to compute transients for
|
|
164
|
+
// the sync manager. Otherwise these transients are not available
|
|
165
|
+
// if / until the record is edited. Use a copy of the record so that
|
|
166
|
+
// it does not change the behavior outside this experimental flag.
|
|
167
|
+
const recordWithTransients = { ...record };
|
|
168
|
+
Object.entries( entityConfig.transientEdits ?? {} )
|
|
169
|
+
.filter(
|
|
170
|
+
( [ propName, transientConfig ] ) =>
|
|
171
|
+
undefined === recordWithTransients[ propName ] &&
|
|
172
|
+
transientConfig &&
|
|
173
|
+
'object' === typeof transientConfig &&
|
|
174
|
+
'read' in transientConfig &&
|
|
175
|
+
'function' === typeof transientConfig.read
|
|
176
|
+
)
|
|
177
|
+
.forEach( ( [ propName, transientConfig ] ) => {
|
|
178
|
+
recordWithTransients[ propName ] =
|
|
179
|
+
transientConfig.read( recordWithTransients );
|
|
180
|
+
} );
|
|
181
|
+
|
|
182
|
+
// Load the entity record for syncing. Do not await promise.
|
|
183
|
+
void getSyncManager()?.load(
|
|
184
|
+
entityConfig.syncConfig,
|
|
185
|
+
objectType,
|
|
186
|
+
objectId,
|
|
187
|
+
recordWithTransients,
|
|
188
|
+
{
|
|
189
|
+
// Handle edits sourced from the sync manager.
|
|
190
|
+
editRecord: ( edits, options = {} ) => {
|
|
191
|
+
if ( ! Object.keys( edits ).length ) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
dispatch( {
|
|
196
|
+
type: 'EDIT_ENTITY_RECORD',
|
|
197
|
+
kind,
|
|
198
|
+
name,
|
|
199
|
+
recordId: key,
|
|
200
|
+
edits,
|
|
201
|
+
meta: {
|
|
202
|
+
undo: undefined,
|
|
203
|
+
},
|
|
204
|
+
options,
|
|
205
|
+
} );
|
|
206
|
+
},
|
|
207
|
+
// Get the current entity record (with edits)
|
|
208
|
+
getEditedRecord: async () =>
|
|
209
|
+
await resolveSelect.getEditedEntityRecord(
|
|
210
|
+
kind,
|
|
211
|
+
name,
|
|
212
|
+
key
|
|
213
|
+
),
|
|
214
|
+
// Handle sync connection status changes.
|
|
215
|
+
onStatusChange: ( status ) => {
|
|
216
|
+
dispatch.setSyncConnectionStatus(
|
|
217
|
+
kind,
|
|
218
|
+
name,
|
|
219
|
+
key,
|
|
220
|
+
status
|
|
221
|
+
);
|
|
222
|
+
},
|
|
223
|
+
// Refetch the current entity record from the database.
|
|
224
|
+
refetchRecord: async () => {
|
|
225
|
+
dispatch.receiveEntityRecords(
|
|
226
|
+
kind,
|
|
227
|
+
name,
|
|
228
|
+
await apiFetch( { path, parse: true } ),
|
|
229
|
+
query
|
|
230
|
+
);
|
|
231
|
+
},
|
|
232
|
+
// Save the current entity record's unsaved edits.
|
|
233
|
+
saveRecord: () => {
|
|
234
|
+
dispatch.saveEditedEntityRecord( kind, name, key );
|
|
235
|
+
},
|
|
236
|
+
addUndoMeta: ( ydoc, meta ) => {
|
|
237
|
+
const selectionHistory =
|
|
238
|
+
getSelectionHistory( ydoc );
|
|
239
|
+
|
|
240
|
+
if ( selectionHistory ) {
|
|
241
|
+
meta.set(
|
|
242
|
+
'selectionHistory',
|
|
243
|
+
selectionHistory
|
|
244
244
|
);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
// Use setTimeout() to wait until content is
|
|
266
|
-
// finished updating, and then set the correct
|
|
267
|
-
// selection.
|
|
268
|
-
setTimeout( () => {
|
|
269
|
-
restoreSelection(
|
|
270
|
-
selectionHistory,
|
|
271
|
-
ydoc
|
|
272
|
-
);
|
|
273
|
-
}, 0 );
|
|
274
|
-
}
|
|
275
|
-
},
|
|
276
|
-
}
|
|
277
|
-
);
|
|
278
|
-
}
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
restoreUndoMeta: ( ydoc, meta ) => {
|
|
248
|
+
const selectionHistory =
|
|
249
|
+
meta.get( 'selectionHistory' );
|
|
250
|
+
|
|
251
|
+
if ( selectionHistory ) {
|
|
252
|
+
// Because Yjs initiates an undo, we need to
|
|
253
|
+
// wait until the content is restored before
|
|
254
|
+
// we can update the selection.
|
|
255
|
+
// Use setTimeout() to wait until content is
|
|
256
|
+
// finished updating, and then set the correct
|
|
257
|
+
// selection.
|
|
258
|
+
setTimeout( () => {
|
|
259
|
+
restoreSelection( selectionHistory, ydoc );
|
|
260
|
+
}, 0 );
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
}
|
|
264
|
+
);
|
|
279
265
|
}
|
|
280
266
|
|
|
281
267
|
registry.batch( () => {
|
|
@@ -471,32 +457,30 @@ export const getEntityRecords =
|
|
|
471
457
|
};
|
|
472
458
|
}
|
|
473
459
|
|
|
474
|
-
if (
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
{
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
);
|
|
499
|
-
}
|
|
460
|
+
if ( entityConfig.syncConfig && -1 === query.per_page ) {
|
|
461
|
+
const objectType = `${ kind }/${ name }`;
|
|
462
|
+
getSyncManager()?.loadCollection(
|
|
463
|
+
entityConfig.syncConfig,
|
|
464
|
+
objectType,
|
|
465
|
+
{
|
|
466
|
+
onStatusChange: ( status ) => {
|
|
467
|
+
dispatch.setSyncConnectionStatus(
|
|
468
|
+
kind,
|
|
469
|
+
name,
|
|
470
|
+
null,
|
|
471
|
+
status
|
|
472
|
+
);
|
|
473
|
+
},
|
|
474
|
+
refetchRecords: async () => {
|
|
475
|
+
dispatch.receiveEntityRecords(
|
|
476
|
+
kind,
|
|
477
|
+
name,
|
|
478
|
+
await apiFetch( { path, parse: true } ),
|
|
479
|
+
query
|
|
480
|
+
);
|
|
481
|
+
},
|
|
482
|
+
}
|
|
483
|
+
);
|
|
500
484
|
}
|
|
501
485
|
|
|
502
486
|
// If we request fields but the result doesn't contain the fields,
|
package/src/test/resolvers.js
CHANGED
|
@@ -128,7 +128,7 @@ describe( 'getEntityRecord', () => {
|
|
|
128
128
|
);
|
|
129
129
|
} );
|
|
130
130
|
|
|
131
|
-
it( 'loads entity with sync manager
|
|
131
|
+
it( 'loads entity with sync manager', async () => {
|
|
132
132
|
const POST_RECORD = { id: 1, title: 'Test Post' };
|
|
133
133
|
const POST_RESPONSE = {
|
|
134
134
|
json: () => Promise.resolve( POST_RECORD ),
|