PluginProbe
Gutenberg / 22.7.0
Gutenberg v22.7.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
← All changes | build/scripts/core-data/index.js +969 -1843 23.5.222.7.0 View file →
@@ -108,29 +108,8 @@
108 108 module.exports = window.wp.undoManager;
109 109 }
110 110 });
111 111
112 - // package-external:@wordpress/api-fetch
113 - var require_api_fetch = __commonJS({
114 - "package-external:@wordpress/api-fetch"(exports, module) {
115 - module.exports = window.wp.apiFetch;
116 - }
117 - });
118 -
119 - // package-external:@wordpress/sync
120 - var require_sync = __commonJS({
121 - "package-external:@wordpress/sync"(exports, module) {
122 - module.exports = window.wp.sync;
123 - }
124 - });
125 -
126 - // package-external:@wordpress/private-apis
127 - var require_private_apis = __commonJS({
128 - "package-external:@wordpress/private-apis"(exports, module) {
129 - module.exports = window.wp.privateApis;
130 - }
131 - });
132 -
133 112 // node_modules/equivalent-key-map/equivalent-key-map.js
134 113 var require_equivalent_key_map = __commonJS({
135 114 "node_modules/equivalent-key-map/equivalent-key-map.js"(exports, module) {
136 115 "use strict";
@@ -349,8 +328,15 @@
349 328 module.exports = window.wp.url;
350 329 }
351 330 });
352 331
332 + // package-external:@wordpress/api-fetch
333 + var require_api_fetch = __commonJS({
334 + "package-external:@wordpress/api-fetch"(exports, module) {
335 + module.exports = window.wp.apiFetch;
336 + }
337 + });
338 +
353 339 // package-external:@wordpress/blocks
354 340 var require_blocks = __commonJS({
355 341 "package-external:@wordpress/blocks"(exports, module) {
356 342 module.exports = window.wp.blocks;
@@ -363,8 +349,15 @@
363 349 module.exports = window.wp.i18n;
364 350 }
365 351 });
366 352
353 + // package-external:@wordpress/sync
354 + var require_sync = __commonJS({
355 + "package-external:@wordpress/sync"(exports, module) {
356 + module.exports = window.wp.sync;
357 + }
358 + });
359 +
367 360 // package-external:@wordpress/block-editor
368 361 var require_block_editor = __commonJS({
369 362 "package-external:@wordpress/block-editor"(exports, module) {
370 363 module.exports = window.wp.blockEditor;
@@ -370,8 +363,15 @@
370 363 module.exports = window.wp.blockEditor;
371 364 }
372 365 });
373 366
367 + // package-external:@wordpress/private-apis
368 + var require_private_apis = __commonJS({
369 + "package-external:@wordpress/private-apis"(exports, module) {
370 + module.exports = window.wp.privateApis;
371 + }
372 + });
373 +
374 374 // package-external:@wordpress/rich-text
375 375 var require_rich_text = __commonJS({
376 376 "package-external:@wordpress/rich-text"(exports, module) {
377 377 module.exports = window.wp.richText;
@@ -416,13 +416,14 @@
416 416 // packages/core-data/build-module/index.mjs
417 417 var index_exports = {};
418 418 __export(index_exports, {
419 419 EntityProvider: () => EntityProvider,
420 + SelectionType: () => SelectionType,
420 421 __experimentalFetchLinkSuggestions: () => fetchLinkSuggestions,
421 422 __experimentalFetchUrlData: () => experimental_fetch_url_data_default,
422 - __experimentalUseEntityRecord: () => useDeprecatedEntityRecord,
423 - __experimentalUseEntityRecords: () => useDeprecatedEntityRecords,
424 - __experimentalUseResourcePermissions: () => useDeprecatedResourcePermissions,
423 + __experimentalUseEntityRecord: () => __experimentalUseEntityRecord,
424 + __experimentalUseEntityRecords: () => __experimentalUseEntityRecords,
425 + __experimentalUseResourcePermissions: () => __experimentalUseResourcePermissions,
425 426 fetchBlockPatterns: () => fetchBlockPatterns,
426 427 privateApis: () => privateApis,
427 428 store: () => store,
428 429 useEntityBlockEditor: () => useEntityBlockEditor,
@@ -431,35 +432,18 @@
431 432 useEntityRecord: () => useEntityRecord,
432 433 useEntityRecords: () => useEntityRecords,
433 434 useResourcePermissions: () => use_resource_permissions_default
434 435 });
435 - var import_data15 = __toESM(require_data(), 1);
436 + var import_data16 = __toESM(require_data(), 1);
436 437
437 438 // packages/core-data/build-module/reducer.mjs
438 - var import_es65 = __toESM(require_es6(), 1);
439 + var import_es64 = __toESM(require_es6(), 1);
439 440 var import_compose2 = __toESM(require_compose(), 1);
440 - var import_data7 = __toESM(require_data(), 1);
441 + var import_data8 = __toESM(require_data(), 1);
441 442 var import_undo_manager = __toESM(require_undo_manager(), 1);
442 443
443 - // packages/core-data/build-module/utils/clear-unchanged-edits.mjs
444 + // packages/core-data/build-module/utils/conservative-map-item.mjs
444 445 var import_es6 = __toESM(require_es6(), 1);
445 - function clearUnchangedEdits(edits, persistedRecord) {
446 - if (!persistedRecord) {
447 - return edits;
448 - }
449 - return Object.fromEntries(
450 - Object.entries(edits).map(([key, value]) => {
451 - const persisted = persistedRecord[key]?.raw ?? persistedRecord[key];
452 - return [
453 - key,
454 - (0, import_es6.default)(value, persisted) ? void 0 : value
455 - ];
456 - })
457 - );
458 - }
459 -
460 - // packages/core-data/build-module/utils/conservative-map-item.mjs
461 - var import_es62 = __toESM(require_es6(), 1);
462 446 function conservativeMapItem(item, nextItem) {
463 447 if (!item) {
464 448 return nextItem;
465 449 }
@@ -465,9 +449,9 @@
465 449 }
466 450 let hasChanges = false;
467 451 const result = {};
468 452 for (const key in nextItem) {
469 - if ((0, import_es62.default)(item[key], nextItem[key])) {
453 + if ((0, import_es6.default)(item[key], nextItem[key])) {
470 454 result[key] = item[key];
471 455 } else {
472 456 hasChanges = true;
473 457 result[key] = nextItem[key];
@@ -509,8 +493,25 @@
509 493 await resolveSelect2[resolverName](...args);
510 494 };
511 495 var forward_resolver_default = forwardResolver;
512 496
497 + // packages/core-data/build-module/utils/on-sub-key.mjs
498 + var onSubKey = (actionProperty) => (reducer) => (state = {}, action) => {
499 + const key = action[actionProperty];
500 + if (key === void 0) {
501 + return state;
502 + }
503 + const nextKeyState = reducer(state[key], action);
504 + if (nextKeyState === state[key]) {
505 + return state;
506 + }
507 + return {
508 + ...state,
509 + [key]: nextKeyState
510 + };
511 + };
512 + var on_sub_key_default = onSubKey;
513 +
513 514 // packages/core-data/build-module/utils/replace-action.mjs
514 515 var replaceAction = (replacer) => (reducer) => (state, action) => {
515 516 return reducer(state, replacer(action));
516 517 };
@@ -533,8 +534,13 @@
533 534 };
534 535 }
535 536 var with_weak_map_cache_default = withWeakMapCache;
536 537
538 + // packages/core-data/build-module/utils/is-raw-attribute.mjs
539 + function isRawAttribute(entity2, attribute) {
540 + return (entity2.rawAttributes || []).includes(attribute);
541 + }
542 +
537 543 // packages/core-data/build-module/utils/set-nested-value.mjs
538 544 function setNestedValue(object, path, value) {
539 545 if (!object || typeof object !== "object") {
540 546 return object;
@@ -582,8 +588,11 @@
582 588 "delete"
583 589 ];
584 590 function getUserPermissionsFromAllowHeader(allowedMethods) {
585 591 const permissions = {};
592 + if (!allowedMethods) {
593 + return permissions;
594 + }
586 595 const methods = {
587 596 create: "POST",
588 597 read: "GET",
589 598 update: "PUT",
@@ -589,9 +598,9 @@
589 598 update: "PUT",
590 599 delete: "DELETE"
591 600 };
592 601 for (const [actionName, methodName] of Object.entries(methods)) {
593 - permissions[actionName] = allowedMethods ? allowedMethods.includes(methodName) : false;
602 + permissions[actionName] = allowedMethods.includes(methodName);
594 603 }
595 604 return permissions;
596 605 }
597 606 function getUserPermissionCacheKey(action, resource, id) {
@@ -603,95 +612,13 @@
603 612 var RECEIVE_INTERMEDIATE_RESULTS = /* @__PURE__ */ Symbol(
604 613 "RECEIVE_INTERMEDIATE_RESULTS"
605 614 );
606 615
607 - // packages/core-data/build-module/utils/normalize-query-for-resolution.mjs
608 - function normalizeQueryForResolution(query) {
609 - if (!query) {
610 - return void 0;
611 - }
612 - const entries = Object.entries(query).filter(
613 - ([k, v]) => (k === "context" || k === "_fields") && v !== void 0 && v !== null
614 - );
615 - return entries.length > 0 ? Object.fromEntries(entries) : void 0;
616 - }
617 -
618 - // packages/core-data/build-module/utils/save-crdt-doc.mjs
619 - var import_api_fetch = __toESM(require_api_fetch(), 1);
620 -
621 - // packages/core-data/build-module/sync.mjs
622 - var import_sync = __toESM(require_sync(), 1);
623 -
624 - // packages/core-data/build-module/lock-unlock.mjs
625 - var import_private_apis = __toESM(require_private_apis(), 1);
626 - var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
627 - "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
628 - "@wordpress/core-data"
629 - );
630 -
631 - // packages/core-data/build-module/sync.mjs
632 - var {
633 - ConnectionErrorCode,
634 - createSyncManager,
635 - Delta,
636 - CRDT_DOC_META_PERSISTENCE_KEY,
637 - CRDT_RECORD_MAP_KEY,
638 - LOCAL_EDITOR_ORIGIN,
639 - LOCAL_UNDO_IGNORED_ORIGIN,
640 - retrySyncConnection
641 - } = unlock(import_sync.privateApis);
642 - var syncManager;
643 - function getSyncManager() {
644 - if (syncManager) {
645 - return syncManager;
646 - }
647 - syncManager = createSyncManager();
648 - return syncManager;
649 - }
650 - function hasSyncManager() {
651 - return Boolean(syncManager);
652 - }
653 -
654 - // packages/core-data/build-module/utils/save-crdt-doc.mjs
655 - var SYNC_SAVE_API_PATH = "/wp-sync/v1/save";
656 - var saveCRDTDocQueues = /* @__PURE__ */ new Map();
657 - async function serializeAndSaveCRDTDoc(objectType, objectId, room) {
658 - const serializedDoc = await getSyncManager()?.createPersistedCRDTDoc(
659 - objectType,
660 - objectId
661 - );
662 - if (!serializedDoc) {
663 - return;
664 - }
665 - await (0, import_api_fetch.default)({
666 - path: SYNC_SAVE_API_PATH,
667 - method: "POST",
668 - data: {
669 - room,
670 - doc: serializedDoc
671 - }
672 - });
673 - }
674 - async function saveCRDTDoc(objectType, objectId) {
675 - const room = `${objectType}:${objectId}`;
676 - const previousSave = saveCRDTDocQueues.get(room) || Promise.resolve();
677 - const currentSave = previousSave.catch(() => {
678 - }).then(() => serializeAndSaveCRDTDoc(objectType, objectId, room));
679 - saveCRDTDocQueues.set(room, currentSave);
680 - try {
681 - await currentSave;
682 - } finally {
683 - if (saveCRDTDocQueues.get(room) === currentSave) {
684 - saveCRDTDocQueues.delete(room);
685 - }
686 - }
687 - }
688 -
689 616 // packages/core-data/build-module/queried-data/actions.mjs
690 617 function receiveItems(items2, edits, meta) {
691 618 return {
692 619 type: "RECEIVE_ITEMS",
693 - items: items2,
620 + items: Array.isArray(items2) ? items2 : [items2],
694 621 persistedEdits: edits,
695 622 meta
696 623 };
697 624 }
@@ -712,8 +639,9 @@
712 639 }
713 640
714 641 // packages/core-data/build-module/queried-data/selectors.mjs
715 642 var import_equivalent_key_map = __toESM(require_equivalent_key_map(), 1);
643 + var import_data = __toESM(require_data(), 1);
716 644
717 645 // packages/core-data/build-module/queried-data/get-query-parts.mjs
718 646 var import_url = __toESM(require_url(), 1);
719 647 function getQueryParts(query) {
@@ -720,9 +648,8 @@
720 648 const parts = {
721 649 stableKey: "",
722 650 page: 1,
723 651 perPage: 10,
724 - offset: null,
725 652 fields: null,
726 653 include: null,
727 654 context: "default"
728 655 };
@@ -736,15 +663,8 @@
736 663 break;
737 664 case "per_page":
738 665 parts.perPage = Number(value);
739 666 break;
740 - case "offset": {
741 - const numericOffset = Number(value);
742 - if (Number.isFinite(numericOffset)) {
743 - parts.offset = numericOffset;
744 - }
745 - break;
746 - }
747 667 case "context":
748 668 parts.context = value;
749 669 break;
750 670 default:
@@ -767,32 +687,19 @@
767 687 var get_query_parts_default = with_weak_map_cache_default(getQueryParts);
768 688
769 689 // packages/core-data/build-module/queried-data/selectors.mjs
770 690 var queriedItemsCacheByState = /* @__PURE__ */ new WeakMap();
771 - function getQueriedItemsUncached(state, query, options = {}) {
772 - const { supportsPagination = true } = options;
773 - const {
774 - stableKey,
775 - page,
776 - perPage,
777 - offset: queryOffset,
778 - include,
779 - fields,
780 - context
781 - } = get_query_parts_default(query);
782 - const itemIds = state.queries?.[context]?.[stableKey]?.itemIds;
691 + function getQueriedItemsUncached(state, query) {
692 + const { stableKey, page, perPage, include, fields, context } = get_query_parts_default(query);
693 + let itemIds;
694 + if (state.queries?.[context]?.[stableKey]) {
695 + itemIds = state.queries[context][stableKey].itemIds;
696 + }
783 697 if (!itemIds) {
784 698 return null;
785 699 }
786 - const isPaginated = supportsPagination && perPage !== -1;
787 - const startOffset = isPaginated ? queryOffset ?? (page - 1) * perPage : 0;
788 - const endOffset = isPaginated ? Math.min(startOffset + perPage, itemIds.length) : itemIds.length;
789 - if (isPaginated && itemIds.length < startOffset + perPage) {
790 - const totalItems = state.queries[context][stableKey].meta?.totalItems;
791 - if (Number.isFinite(totalItems) && itemIds.length < totalItems) {
792 - return null;
793 - }
794 - }
700 + const startOffset = perPage === -1 ? 0 : (page - 1) * perPage;
701 + const endOffset = perPage === -1 ? itemIds.length : Math.min(startOffset + perPage, itemIds.length);
795 702 const items2 = [];
796 703 for (let i = startOffset; i < endOffset; i++) {
797 704 const itemId = itemIds[i];
798 705 if (Array.isArray(include) && !include.includes(itemId)) {
@@ -825,9 +732,9 @@
825 732 items2.push(filteredItem);
826 733 }
827 734 return items2;
828 735 }
829 - function getQueriedItems(state, query = {}, options = {}) {
736 + var getQueriedItems = (0, import_data.createSelector)((state, query = {}) => {
830 737 let queriedItemsCache = queriedItemsCacheByState.get(state);
831 738 if (queriedItemsCache) {
832 739 const queriedItems = queriedItemsCache.get(query);
833 740 if (queriedItems !== void 0) {
@@ -836,12 +743,12 @@
836 743 } else {
837 744 queriedItemsCache = new import_equivalent_key_map.default();
838 745 queriedItemsCacheByState.set(state, queriedItemsCache);
839 746 }
840 - const items2 = getQueriedItemsUncached(state, query, options);
747 + const items2 = getQueriedItemsUncached(state, query);
841 748 queriedItemsCache.set(query, items2);
842 749 return items2;
843 - }
750 + });
844 751 function getQueriedTotalItems(state, query = {}) {
845 752 const { stableKey, context } = get_query_parts_default(query);
846 753 return state.queries?.[context]?.[stableKey]?.meta?.totalItems ?? null;
847 754 }
@@ -850,9 +757,9 @@
850 757 return state.queries?.[context]?.[stableKey]?.meta?.totalPages ?? null;
851 758 }
852 759
853 760 // packages/core-data/build-module/queried-data/reducer.mjs
854 - var import_data6 = __toESM(require_data(), 1);
761 + var import_data7 = __toESM(require_data(), 1);
855 762 var import_compose = __toESM(require_compose(), 1);
856 763
857 764 // node_modules/tslib/tslib.es6.mjs
858 765 var __assign = function() {
@@ -941,19 +848,19 @@
941 848 return noCase(input, __assign({ delimiter: " ", transform: capitalCaseTransform }, options));
942 849 }
943 850
944 851 // packages/core-data/build-module/entities.mjs
945 - var import_api_fetch2 = __toESM(require_api_fetch(), 1);
852 + var import_api_fetch = __toESM(require_api_fetch(), 1);
946 853 var import_blocks4 = __toESM(require_blocks(), 1);
947 854 var import_i18n = __toESM(require_i18n(), 1);
948 855
949 856 // packages/core-data/build-module/awareness/post-editor-awareness.mjs
950 - var import_data4 = __toESM(require_data(), 1);
951 - var import_sync9 = __toESM(require_sync(), 1);
857 + var import_data5 = __toESM(require_data(), 1);
858 + var import_sync8 = __toESM(require_sync(), 1);
952 859 var import_block_editor3 = __toESM(require_block_editor(), 1);
953 860
954 861 // packages/core-data/build-module/awareness/base-awareness.mjs
955 - var import_data = __toESM(require_data(), 1);
862 + var import_data2 = __toESM(require_data(), 1);
956 863
957 864 // packages/core-data/build-module/awareness/config.mjs
958 865 var AWARENESS_CURSOR_UPDATE_THROTTLE_IN_MS = 100;
959 866 var LOCAL_CURSOR_UPDATE_DEBOUNCE_IN_MS = 5;
@@ -959,9 +866,9 @@
959 866 var LOCAL_CURSOR_UPDATE_DEBOUNCE_IN_MS = 5;
960 867 var REMOVAL_DELAY_IN_MS = 5e3;
961 868
962 869 // packages/core-data/build-module/awareness/typed-awareness.mjs
963 - var import_sync3 = __toESM(require_sync(), 1);
870 + var import_sync = __toESM(require_sync(), 1);
964 871
965 872 // packages/core-data/build-module/awareness/utils.mjs
966 873 function getBrowserName() {
967 874 const userAgent = window.navigator.userAgent;
@@ -1028,9 +935,9 @@
1028 935 return Object.keys(obj);
1029 936 }
1030 937
1031 938 // packages/core-data/build-module/awareness/typed-awareness.mjs
1032 - var TypedAwareness = class extends import_sync3.Awareness {
939 + var TypedAwareness = class extends import_sync.Awareness {
1033 940 /**
1034 941 * Get the states from an awareness document.
1035 942 */
1036 943 getStates() {
@@ -1301,9 +1208,9 @@
1301 1208 /**
1302 1209 * Set the current collaborator info in the local state.
1303 1210 */
1304 1211 async setCurrentCollaboratorInfo() {
1305 - const currentUser2 = await (0, import_data.resolveSelect)(STORE_NAME).getCurrentUser();
1212 + const currentUser2 = await (0, import_data2.resolveSelect)(STORE_NAME).getCurrentUser();
1306 1213 const collaboratorInfo = generateCollaboratorInfo(currentUser2);
1307 1214 this.setLocalStateField("collaboratorInfo", collaboratorInfo);
1308 1215 }
1309 1216 };
@@ -1314,28 +1221,17 @@
1314 1221 equalityFieldChecks = baseEqualityFieldChecks;
1315 1222 };
1316 1223
1317 1224 // packages/core-data/build-module/awareness/block-lookup.mjs
1318 - var import_data2 = __toESM(require_data(), 1);
1319 - var import_sync4 = __toESM(require_sync(), 1);
1225 + var import_data3 = __toESM(require_data(), 1);
1226 + var import_sync2 = __toESM(require_sync(), 1);
1320 1227 var import_block_editor = __toESM(require_block_editor(), 1);
1321 - function getContainingBlockYMap(yType) {
1322 - let current = yType;
1323 - while (current) {
1324 - const parent = current.parent;
1325 - if (parent instanceof import_sync4.Y.Map && parent.parent instanceof import_sync4.Y.Array && parent.get("clientId") !== void 0 && parent.get("innerBlocks") instanceof import_sync4.Y.Array) {
1326 - return parent;
1327 - }
1328 - current = parent instanceof import_sync4.Y.AbstractType ? parent : null;
1329 - }
1330 - return null;
1331 - }
1332 1228 function getBlockPathInYdoc(yType) {
1333 1229 const path = [];
1334 1230 let current = yType;
1335 1231 while (current) {
1336 1232 const parentArray = current.parent;
1337 - if (!parentArray || !(parentArray instanceof import_sync4.Y.Array)) {
1233 + if (!parentArray || !(parentArray instanceof import_sync2.Y.Array)) {
1338 1234 return null;
1339 1235 }
1340 1236 let index = -1;
1341 1237 for (let i = 0; i < parentArray.length; i++) {
@@ -1348,9 +1244,9 @@
1348 1244 return null;
1349 1245 }
1350 1246 path.unshift(index);
1351 1247 const grandparent = parentArray.parent;
1352 - if (grandparent instanceof import_sync4.Y.Map && grandparent.get("clientId") !== void 0) {
1248 + if (grandparent instanceof import_sync2.Y.Map && grandparent.get("clientId") !== void 0) {
1353 1249 current = grandparent;
1354 1250 } else {
1355 1251 break;
1356 1252 }
@@ -1356,12 +1252,15 @@
1356 1252 }
1357 1253 }
1358 1254 return path;
1359 1255 }
1360 - function resolveBlockClientIdByPath(path, blocks) {
1256 + function resolveBlockClientIdByPath(path) {
1361 1257 if (path.length === 0) {
1362 1258 return null;
1363 1259 }
1260 + const { getBlocks } = (0, import_data3.select)(import_block_editor.store);
1261 + const postContentBlocks = getPostContentBlocks(getBlocks(), getBlocks);
1262 + let blocks = postContentBlocks;
1364 1263 for (let i = 0; i < path.length; i++) {
1365 1264 const block = blocks[path[i]];
1366 1265 if (!block) {
1367 1266 return null;
@@ -1372,114 +1271,82 @@
1372 1271 blocks = block.innerBlocks;
1373 1272 }
1374 1273 return null;
1375 1274 }
1376 - function usePostContentBlocks() {
1377 - return (0, import_data2.useSelect)((select4) => {
1378 - const { getBlocksByName, getClientIdsTree } = unlock(
1379 - select4(import_block_editor.store)
1380 - );
1381 - const [postContentClientId] = getBlocksByName("core/post-content");
1382 - return getClientIdsTree(postContentClientId ?? "");
1383 - }, []);
1275 + function getPostContentBlocks(rootBlocks, getBlocks) {
1276 + const postContentBlock = findBlockByName(rootBlocks, "core/post-content");
1277 + if (postContentBlock) {
1278 + return getBlocks(postContentBlock.clientId);
1279 + }
1280 + return rootBlocks;
1384 1281 }
1282 + function findBlockByName(blocks, name) {
1283 + for (const block of blocks) {
1284 + if (block.name === name) {
1285 + return block;
1286 + }
1287 + if (block.innerBlocks?.length) {
1288 + const found = findBlockByName(block.innerBlocks, name);
1289 + if (found) {
1290 + return found;
1291 + }
1292 + }
1293 + }
1294 + return null;
1295 + }
1385 1296
1297 + // packages/core-data/build-module/utils/crdt-user-selections.mjs
1298 + var import_data4 = __toESM(require_data(), 1);
1299 + var import_sync6 = __toESM(require_sync(), 1);
1300 + var import_block_editor2 = __toESM(require_block_editor(), 1);
1301 +
1302 + // packages/core-data/build-module/sync.mjs
1303 + var import_sync3 = __toESM(require_sync(), 1);
1304 +
1305 + // packages/core-data/build-module/lock-unlock.mjs
1306 + var import_private_apis = __toESM(require_private_apis(), 1);
1307 + var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
1308 + "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
1309 + "@wordpress/core-data"
1310 + );
1311 +
1312 + // packages/core-data/build-module/sync.mjs
1313 + var {
1314 + createSyncManager,
1315 + Delta,
1316 + CRDT_DOC_META_PERSISTENCE_KEY,
1317 + CRDT_RECORD_MAP_KEY,
1318 + LOCAL_EDITOR_ORIGIN,
1319 + retrySyncConnection
1320 + } = unlock(import_sync3.privateApis);
1321 + var syncManager;
1322 + function getSyncManager() {
1323 + if (syncManager) {
1324 + return syncManager;
1325 + }
1326 + syncManager = createSyncManager();
1327 + return syncManager;
1328 + }
1329 +
1386 1330 // packages/core-data/build-module/utils/crdt-utils.mjs
1387 - var import_sync5 = __toESM(require_sync(), 1);
1388 - var import_rich_text = __toESM(require_rich_text(), 1);
1331 + var import_sync4 = __toESM(require_sync(), 1);
1389 1332 function getRootMap(doc, key) {
1390 1333 return doc.getMap(key);
1391 1334 }
1392 1335 function createYMap(partial = {}) {
1393 - return new import_sync5.Y.Map(Object.entries(partial));
1336 + return new import_sync4.Y.Map(Object.entries(partial));
1394 1337 }
1395 1338 function isYMap(value) {
1396 - return value instanceof import_sync5.Y.Map;
1339 + return value instanceof import_sync4.Y.Map;
1397 1340 }
1398 - function asRichTextOffset(offset) {
1399 - return offset;
1400 - }
1401 - function asHtmlStringIndex(index) {
1402 - return index;
1403 - }
1404 - function getYTextByAttributeKey(attributes, attributeKey) {
1405 - const directValue = attributes.get(attributeKey);
1406 - if (directValue instanceof import_sync5.Y.Text) {
1407 - return directValue;
1408 - }
1409 - let value = attributes;
1410 - for (const pathPart of attributeKey.split(".")) {
1411 - if (value instanceof import_sync5.Y.Map) {
1412 - value = value.get(pathPart);
1413 - } else if (value instanceof import_sync5.Y.Array) {
1414 - const index = Number.parseInt(pathPart, 10);
1415 - if (!Number.isSafeInteger(index) || index < 0 || index.toString() !== pathPart) {
1416 - return null;
1417 - }
1418 - value = value.get(index);
1419 - } else {
1420 - return null;
1421 - }
1422 - }
1423 - return value instanceof import_sync5.Y.Text ? value : null;
1424 - }
1425 1341 function findBlockByClientIdInDoc(blockId, ydoc) {
1426 1342 const ymap = getRootMap(ydoc, CRDT_RECORD_MAP_KEY);
1427 1343 const blocks = ymap.get("blocks");
1428 - if (!(blocks instanceof import_sync5.Y.Array)) {
1344 + if (!(blocks instanceof import_sync4.Y.Array)) {
1429 1345 return null;
1430 1346 }
1431 1347 return findBlockByClientIdInBlocks(blockId, blocks);
1432 1348 }
1433 - var MARKER_START = 57344;
1434 - function pickMarker(text) {
1435 - const tryCount = 16;
1436 - for (let code = MARKER_START; code < MARKER_START + tryCount; code++) {
1437 - const candidate = String.fromCharCode(code);
1438 - if (!text.includes(candidate)) {
1439 - return candidate;
1440 - }
1441 - }
1442 - return null;
1443 - }
1444 - function htmlIndexToRichTextOffset(html, htmlIndex) {
1445 - if (!html.includes("<") && !html.includes("&")) {
1446 - return asRichTextOffset(htmlIndex);
1447 - }
1448 - const marker = pickMarker(html);
1449 - if (!marker) {
1450 - return asRichTextOffset(htmlIndex);
1451 - }
1452 - const withMarker = html.slice(0, htmlIndex) + marker + html.slice(htmlIndex);
1453 - const value = (0, import_rich_text.create)({ html: withMarker });
1454 - const markerPos = value.text.indexOf(marker);
1455 - return asRichTextOffset(markerPos === -1 ? htmlIndex : markerPos);
1456 - }
1457 - function richTextOffsetToHtmlIndex(html, richTextOffset) {
1458 - if (!html.includes("<") && !html.includes("&")) {
1459 - return asHtmlStringIndex(richTextOffset);
1460 - }
1461 - const marker = pickMarker(html);
1462 - if (!marker) {
1463 - return asHtmlStringIndex(richTextOffset);
1464 - }
1465 - const value = (0, import_rich_text.create)({ html });
1466 - const markerValue = (0, import_rich_text.create)({ text: marker });
1467 - if (value.formats[richTextOffset]) {
1468 - markerValue.formats[0] = value.formats[richTextOffset];
1469 - }
1470 - const withMarker = (0, import_rich_text.insert)(
1471 - value,
1472 - markerValue,
1473 - richTextOffset,
1474 - richTextOffset
1475 - );
1476 - const htmlWithMarker = (0, import_rich_text.toHTMLString)({ value: withMarker });
1477 - const markerIndex = htmlWithMarker.indexOf(marker);
1478 - return asHtmlStringIndex(
1479 - markerIndex === -1 ? richTextOffset : markerIndex
1480 - );
1481 - }
1482 1349 function findBlockByClientIdInBlocks(blockId, blocks) {
1483 1350 for (const block of blocks) {
1484 1351 if (block.get("clientId") === blockId) {
1485 1352 return block;
@@ -1498,11 +1365,8 @@
1498 1365 return null;
1499 1366 }
1500 1367
1501 1368 // packages/core-data/build-module/utils/crdt-user-selections.mjs
1502 - var import_data3 = __toESM(require_data(), 1);
1503 - var import_sync7 = __toESM(require_sync(), 1);
1504 - var import_block_editor2 = __toESM(require_block_editor(), 1);
1505 1369 var SelectionType = /* @__PURE__ */ ((SelectionType2) => {
1506 1370 SelectionType2["None"] = "none";
1507 1371 SelectionType2["Cursor"] = "cursor";
1508 1372 SelectionType2["SelectionInOneBlock"] = "selection-in-one-block";
@@ -1509,15 +1373,9 @@
1509 1373 SelectionType2["SelectionInMultipleBlocks"] = "selection-in-multiple-blocks";
1510 1374 SelectionType2["WholeBlock"] = "whole-block";
1511 1375 return SelectionType2;
1512 1376 })(SelectionType || {});
1513 - var SelectionDirection = /* @__PURE__ */ ((SelectionDirection2) => {
1514 - SelectionDirection2["Forward"] = "f";
1515 - SelectionDirection2["Backward"] = "b";
1516 - return SelectionDirection2;
1517 - })(SelectionDirection || {});
1518 - function getSelectionState(selectionStart, selectionEnd, yDoc, options) {
1519 - const { selectionDirection } = options ?? {};
1377 + function getSelectionState(selectionStart, selectionEnd, yDoc) {
1520 1378 const ymap = getRootMap(yDoc, CRDT_RECORD_MAP_KEY);
1521 1379 const yBlocks = ymap.get("blocks");
1522 1380 const isSelectionEmpty = Object.keys(selectionStart).length === 0;
1523 1381 const noSelection = {
@@ -1560,10 +1418,9 @@
1560 1418 }
1561 1419 return {
1562 1420 type: "selection-in-one-block",
1563 1421 cursorStartPosition: cursorStartPosition2,
1564 - cursorEndPosition: cursorEndPosition2,
1565 - selectionDirection
1422 + cursorEndPosition: cursorEndPosition2
1566 1423 };
1567 1424 }
1568 1425 const cursorStartPosition = getCursorPosition(selectionStart, yBlocks);
1569 1426 const cursorEndPosition = getCursorPosition(selectionEnd, yBlocks);
@@ -1572,10 +1429,9 @@
1572 1429 }
1573 1430 return {
1574 1431 type: "selection-in-multiple-blocks",
1575 1432 cursorStartPosition,
1576 - cursorEndPosition,
1577 - selectionDirection
1433 + cursorEndPosition
1578 1434 };
1579 1435 }
1580 1436 function getCursorPosition(selection, blocks) {
1581 1437 const path = getBlockPathForLocalClientId(selection.clientId);
@@ -1583,27 +1439,23 @@
1583 1439 if (!block || !selection.attributeKey || void 0 === selection.offset) {
1584 1440 return null;
1585 1441 }
1586 1442 const attributes = block.get("attributes");
1587 - const currentYText = attributes ? getYTextByAttributeKey(attributes, selection.attributeKey) : null;
1588 - if (!(currentYText instanceof import_sync7.Y.Text)) {
1443 + const currentYText = attributes?.get(selection.attributeKey);
1444 + if (!(currentYText instanceof import_sync6.Y.Text)) {
1589 1445 return null;
1590 1446 }
1591 - const relativePosition = import_sync7.Y.createRelativePositionFromTypeIndex(
1447 + const relativePosition = import_sync6.Y.createRelativePositionFromTypeIndex(
1592 1448 currentYText,
1593 - richTextOffsetToHtmlIndex(
1594 - currentYText.toString(),
1595 - asRichTextOffset(selection.offset)
1596 - )
1449 + selection.offset
1597 1450 );
1598 1451 return {
1599 1452 relativePosition,
1600 - absoluteOffset: selection.offset,
1601 - attributeKey: selection.attributeKey
1453 + absoluteOffset: selection.offset
1602 1454 };
1603 1455 }
1604 1456 function getBlockPathForLocalClientId(clientId) {
1605 - const { getBlockIndex, getBlockRootClientId, getBlockName } = (0, import_data3.select)(import_block_editor2.store);
1457 + const { getBlockIndex, getBlockRootClientId, getBlockName } = (0, import_data4.select)(import_block_editor2.store);
1606 1458 const path = [];
1607 1459 let current = clientId;
1608 1460 while (current) {
1609 1461 const index = getBlockIndex(current);
@@ -1635,9 +1487,9 @@
1635 1487 }
1636 1488 if (i === path.length - 1) {
1637 1489 return block;
1638 1490 }
1639 - currentBlocks = block.get("innerBlocks") ?? new import_sync7.Y.Array();
1491 + currentBlocks = block.get("innerBlocks") ?? new import_sync6.Y.Array();
1640 1492 }
1641 1493 return null;
1642 1494 }
1643 1495 function createRelativePositionForBlockPath(path, blocks) {
@@ -1646,15 +1498,15 @@
1646 1498 if (path[i] >= currentBlocks.length) {
1647 1499 return null;
1648 1500 }
1649 1501 if (i === path.length - 1) {
1650 - return import_sync7.Y.createRelativePositionFromTypeIndex(
1502 + return import_sync6.Y.createRelativePositionFromTypeIndex(
1651 1503 currentBlocks,
1652 1504 path[i]
1653 1505 );
1654 1506 }
1655 1507 const block = currentBlocks.get(path[i]);
1656 - currentBlocks = block?.get("innerBlocks") ?? new import_sync7.Y.Array();
1508 + currentBlocks = block?.get("innerBlocks") ?? new import_sync6.Y.Array();
1657 1509 }
1658 1510 return null;
1659 1511 }
1660 1512 function areSelectionsStatesEqual(selection1, selection2) {
@@ -1675,9 +1527,9 @@
1675 1527 selection2.cursorStartPosition
1676 1528 ) && areCursorPositionsEqual(
1677 1529 selection1.cursorEndPosition,
1678 1530 selection2.cursorEndPosition
1679 - ) && selection1.selectionDirection === selection2.selectionDirection;
1531 + );
1680 1532 case "selection-in-multiple-blocks":
1681 1533 return areCursorPositionsEqual(
1682 1534 selection1.cursorStartPosition,
1683 1535 selection2.cursorStartPosition
@@ -1683,11 +1535,11 @@
1683 1535 selection2.cursorStartPosition
1684 1536 ) && areCursorPositionsEqual(
1685 1537 selection1.cursorEndPosition,
1686 1538 selection2.cursorEndPosition
1687 - ) && selection1.selectionDirection === selection2.selectionDirection;
1539 + );
1688 1540 case "whole-block":
1689 - return import_sync7.Y.compareRelativePositions(
1541 + return import_sync6.Y.compareRelativePositions(
1690 1542 selection1.blockPosition,
1691 1543 selection2.blockPosition
1692 1544 );
1693 1545 default:
@@ -1694,9 +1546,9 @@
1694 1546 return false;
1695 1547 }
1696 1548 }
1697 1549 function areCursorPositionsEqual(cursorPosition1, cursorPosition2) {
1698 - const isRelativePositionEqual = import_sync7.Y.compareRelativePositions(
1550 + const isRelativePositionEqual = import_sync6.Y.compareRelativePositions(
1699 1551 cursorPosition1.relativePosition,
1700 1552 cursorPosition2.relativePosition
1701 1553 );
1702 1554 const isAbsoluteOffsetEqual = cursorPosition1.absoluteOffset === cursorPosition2.absoluteOffset;
@@ -1726,25 +1578,18 @@
1726 1578 const {
1727 1579 getSelectionStart,
1728 1580 getSelectionEnd,
1729 1581 getSelectedBlocksInitialCaretPosition
1730 - } = (0, import_data4.select)(import_block_editor3.store);
1582 + } = (0, import_data5.select)(import_block_editor3.store);
1731 1583 let selectionStart = getSelectionStart();
1732 1584 let selectionEnd = getSelectionEnd();
1733 1585 let localCursorTimeout = null;
1734 - let selectionBeforeDebounce = null;
1735 - (0, import_data4.subscribe)(() => {
1586 + (0, import_data5.subscribe)(() => {
1736 1587 const newSelectionStart = getSelectionStart();
1737 1588 const newSelectionEnd = getSelectionEnd();
1738 1589 if (newSelectionStart === selectionStart && newSelectionEnd === selectionEnd) {
1739 1590 return;
1740 1591 }
1741 - if (!selectionBeforeDebounce) {
1742 - selectionBeforeDebounce = {
1743 - start: selectionStart,
1744 - end: selectionEnd
1745 - };
1746 - }
1747 1592 selectionStart = newSelectionStart;
1748 1593 selectionEnd = newSelectionEnd;
1749 1594 const initialPosition = getSelectedBlocksInitialCaretPosition();
1750 1595 void this.updateSelectionInEntityRecord(
@@ -1755,23 +1600,12 @@
1755 1600 if (localCursorTimeout) {
1756 1601 clearTimeout(localCursorTimeout);
1757 1602 }
1758 1603 localCursorTimeout = setTimeout(() => {
1759 - const selectionStateOptions = {};
1760 - if (selectionBeforeDebounce) {
1761 - selectionStateOptions.selectionDirection = detectSelectionDirection(
1762 - selectionBeforeDebounce.start,
1763 - selectionBeforeDebounce.end,
1764 - selectionStart,
1765 - selectionEnd
1766 - );
1767 - selectionBeforeDebounce = null;
1768 - }
1769 1604 const selectionState = getSelectionState(
1770 1605 selectionStart,
1771 1606 selectionEnd,
1772 - this.doc,
1773 - selectionStateOptions
1607 + this.doc
1774 1608 );
1775 1609 this.setThrottledLocalStateField(
1776 1610 "editorState",
1777 1611 { selection: selectionState },
@@ -1793,9 +1627,9 @@
1793 1627 };
1794 1628 const options = {
1795 1629 undoIgnore: true
1796 1630 };
1797 - (0, import_data4.dispatch)(STORE_NAME).editEntityRecord(
1631 + (0, import_data5.dispatch)(STORE_NAME).editEntityRecord(
1798 1632 this.kind,
1799 1633 this.name,
1800 1634 this.postId,
1801 1635 edits,
@@ -1812,11 +1646,8 @@
1812 1646 areEditorStatesEqual(state1, state2) {
1813 1647 if (!state1 || !state2) {
1814 1648 return state1 === state2;
1815 1649 }
1816 - if (!state1.selection || !state2.selection) {
1817 - return state1.selection === state2.selection;
1818 - }
1819 1650 return areSelectionsStatesEqual(state1.selection, state2.selection);
1820 1651 }
1821 1652 /**
1822 1653 * Resolve a selection state to a text index and block client ID.
@@ -1831,62 +1662,42 @@
1831 1662 * from the Yjs block because the local block-editor store may use different
1832 1663 * clientIds (e.g. in "Show Template" mode where blocks are cloned).
1833 1664 *
1834 1665 * @param selection - The selection state.
1835 - * @param blocks - The tree of block-editor store post content blocks.
1836 - * @return The rich-text offset and block client ID, or nulls if not resolvable.
1666 + * @return The text index and block client ID, or nulls if not resolvable.
1837 1667 */
1838 - convertSelectionStateToAbsolute(selection, blocks) {
1668 + convertSelectionStateToAbsolute(selection) {
1839 1669 if (selection.type === SelectionType.None) {
1840 - return {
1841 - richTextOffset: null,
1842 - localClientId: null,
1843 - attributeKey: null
1844 - };
1670 + return { textIndex: null, localClientId: null };
1845 1671 }
1846 1672 if (selection.type === SelectionType.WholeBlock) {
1847 - const absolutePos = import_sync9.Y.createAbsolutePositionFromRelativePosition(
1673 + const absolutePos = import_sync8.Y.createAbsolutePositionFromRelativePosition(
1848 1674 selection.blockPosition,
1849 1675 this.doc
1850 1676 );
1851 1677 let localClientId2 = null;
1852 - if (absolutePos && absolutePos.type instanceof import_sync9.Y.Array) {
1678 + if (absolutePos && absolutePos.type instanceof import_sync8.Y.Array) {
1853 1679 const parentArray = absolutePos.type;
1854 1680 const block = parentArray.get(absolutePos.index);
1855 - if (block instanceof import_sync9.Y.Map) {
1681 + if (block instanceof import_sync8.Y.Map) {
1856 1682 const path2 = getBlockPathInYdoc(block);
1857 - localClientId2 = path2 ? resolveBlockClientIdByPath(path2, blocks) : null;
1683 + localClientId2 = path2 ? resolveBlockClientIdByPath(path2) : null;
1858 1684 }
1859 1685 }
1860 - return {
1861 - richTextOffset: null,
1862 - localClientId: localClientId2,
1863 - attributeKey: null
1864 - };
1686 + return { textIndex: null, localClientId: localClientId2 };
1865 1687 }
1866 1688 const cursorPos = "cursorPosition" in selection ? selection.cursorPosition : selection.cursorStartPosition;
1867 - const absolutePosition = import_sync9.Y.createAbsolutePositionFromRelativePosition(
1689 + const absolutePosition = import_sync8.Y.createAbsolutePositionFromRelativePosition(
1868 1690 cursorPos.relativePosition,
1869 1691 this.doc
1870 1692 );
1871 1693 if (!absolutePosition) {
1872 - return {
1873 - richTextOffset: null,
1874 - localClientId: null,
1875 - attributeKey: null
1876 - };
1694 + return { textIndex: null, localClientId: null };
1877 1695 }
1878 - const yType = getContainingBlockYMap(absolutePosition.type);
1879 - const path = yType ? getBlockPathInYdoc(yType) : null;
1880 - const localClientId = path ? resolveBlockClientIdByPath(path, blocks) : null;
1881 - return {
1882 - richTextOffset: htmlIndexToRichTextOffset(
1883 - absolutePosition.type.toString(),
1884 - asHtmlStringIndex(absolutePosition.index)
1885 - ),
1886 - localClientId,
1887 - attributeKey: cursorPos.attributeKey ?? null
1888 - };
1696 + const yType = absolutePosition.type.parent?.parent;
1697 + const path = yType instanceof import_sync8.Y.Map ? getBlockPathInYdoc(yType) : null;
1698 + const localClientId = path ? resolveBlockClientIdByPath(path) : null;
1699 + return { textIndex: absolutePosition.index, localClientId };
1889 1700 }
1890 1701 /**
1891 1702 * Type guard to check if a struct is a Y.Item (not Y.GC)
1892 1703 * @param struct - The struct to check.
@@ -1947,60 +1758,53 @@
1947 1758 collaboratorMap: Object.fromEntries(collaboratorMapData)
1948 1759 };
1949 1760 }
1950 1761 };
1951 - function detectSelectionDirection(prevStart, prevEnd, newStart, newEnd) {
1952 - const startMoved = !areBlockSelectionsEqual(prevStart, newStart);
1953 - const endMoved = !areBlockSelectionsEqual(prevEnd, newEnd);
1954 - if (startMoved && !endMoved) {
1955 - return SelectionDirection.Backward;
1956 - }
1957 - return SelectionDirection.Forward;
1958 - }
1959 - function areBlockSelectionsEqual(a, b) {
1960 - return a.clientId === b.clientId && a.attributeKey === b.attributeKey && a.offset === b.offset;
1961 - }
1962 1762
1963 1763 // packages/core-data/build-module/utils/crdt.mjs
1964 - var import_es64 = __toESM(require_es6(), 1);
1764 + var import_es63 = __toESM(require_es6(), 1);
1965 1765 var import_blocks3 = __toESM(require_blocks(), 1);
1966 - var import_sync14 = __toESM(require_sync(), 1);
1766 + var import_sync13 = __toESM(require_sync(), 1);
1967 1767
1968 - // node_modules/uuid/dist/stringify.js
1768 + // node_modules/uuid/dist/esm-browser/rng.js
1769 + var getRandomValues;
1770 + var rnds8 = new Uint8Array(16);
1771 + function rng() {
1772 + if (!getRandomValues) {
1773 + getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
1774 + if (!getRandomValues) {
1775 + throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
1776 + }
1777 + }
1778 + return getRandomValues(rnds8);
1779 + }
1780 +
1781 + // node_modules/uuid/dist/esm-browser/stringify.js
1969 1782 var byteToHex = [];
1970 1783 for (let i = 0; i < 256; ++i) {
1971 1784 byteToHex.push((i + 256).toString(16).slice(1));
1972 1785 }
1973 1786 function unsafeStringify(arr, offset = 0) {
1974 - return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
1787 + return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
1975 1788 }
1976 1789
1977 - // node_modules/uuid/dist/rng.js
1978 - var rnds8 = new Uint8Array(16);
1979 - function rng() {
1980 - return crypto.getRandomValues(rnds8);
1981 - }
1790 + // node_modules/uuid/dist/esm-browser/native.js
1791 + var randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
1792 + var native_default = {
1793 + randomUUID
1794 + };
1982 1795
1983 - // node_modules/uuid/dist/v4.js
1796 + // node_modules/uuid/dist/esm-browser/v4.js
1984 1797 function v4(options, buf, offset) {
1985 - if (!buf && !options && crypto.randomUUID) {
1986 - return crypto.randomUUID();
1798 + if (native_default.randomUUID && !buf && !options) {
1799 + return native_default.randomUUID();
1987 1800 }
1988 - return _v4(options, buf, offset);
1989 - }
1990 - function _v4(options, buf, offset) {
1991 1801 options = options || {};
1992 - const rnds = options.random ?? options.rng?.() ?? rng();
1993 - if (rnds.length < 16) {
1994 - throw new Error("Random bytes length must be >= 16");
1995 - }
1802 + const rnds = options.random || (options.rng || rng)();
1996 1803 rnds[6] = rnds[6] & 15 | 64;
1997 1804 rnds[8] = rnds[8] & 63 | 128;
1998 1805 if (buf) {
1999 1806 offset = offset || 0;
2000 - if (offset < 0 || offset + 16 > buf.length) {
2001 - throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
2002 - }
2003 1807 for (let i = 0; i < 16; ++i) {
2004 1808 buf[offset + i] = rnds[i];
2005 1809 }
2006 1810 return buf;
@@ -2009,131 +1813,34 @@
2009 1813 }
2010 1814 var v4_default = v4;
2011 1815
2012 1816 // packages/core-data/build-module/utils/crdt-blocks.mjs
2013 - var import_es63 = __toESM(require_es6(), 1);
1817 + var import_es62 = __toESM(require_es6(), 1);
2014 1818 var import_blocks = __toESM(require_blocks(), 1);
2015 - var import_rich_text3 = __toESM(require_rich_text(), 1);
2016 - var import_sync10 = __toESM(require_sync(), 1);
2017 -
2018 - // packages/core-data/build-module/utils/crdt-text.mjs
2019 - var import_rich_text2 = __toESM(require_rich_text(), 1);
2020 - var RICH_TEXT_CACHE_MAX_SIZE = 500;
2021 - function createRichTextDataCache(maxSize) {
2022 - const cache3 = /* @__PURE__ */ new Map();
2023 - return function(value) {
2024 - const cached = cache3.get(value);
2025 - if (cached) {
2026 - return cached;
2027 - }
2028 - const result = import_rich_text2.RichTextData.fromHTMLString(value);
2029 - if (cache3.size >= maxSize) {
2030 - cache3.delete(cache3.keys().next().value);
2031 - }
2032 - cache3.set(value, result);
2033 - return result;
2034 - };
2035 - }
2036 - var getCachedRichTextData = createRichTextDataCache(
2037 - RICH_TEXT_CACHE_MAX_SIZE
2038 - );
2039 -
2040 - // packages/core-data/build-module/utils/crdt-blocks.mjs
1819 + var import_rich_text = __toESM(require_rich_text(), 1);
1820 + var import_sync9 = __toESM(require_sync(), 1);
2041 1821 var serializableBlocksCache = /* @__PURE__ */ new WeakMap();
2042 - function serializeAttributeValue(value) {
2043 - if (value instanceof import_rich_text3.RichTextData) {
2044 - return value.valueOf();
2045 - }
2046 - if (Array.isArray(value)) {
2047 - return value.map(serializeAttributeValue);
2048 - }
2049 - if (value && typeof value === "object") {
2050 - const result = {};
2051 - for (const [k, v] of Object.entries(value)) {
2052 - result[k] = serializeAttributeValue(v);
2053 - }
2054 - return result;
2055 - }
2056 - return value;
2057 - }
2058 - function makeBlockAttributesSerializable(blockName, attributes) {
1822 + function makeBlockAttributesSerializable(attributes) {
2059 1823 const newAttributes = { ...attributes };
2060 1824 for (const [key, value] of Object.entries(attributes)) {
2061 - if (isLocalAttribute(blockName, key)) {
2062 - delete newAttributes[key];
2063 - continue;
1825 + if (value instanceof import_rich_text.RichTextData) {
1826 + newAttributes[key] = value.valueOf();
2064 1827 }
2065 - newAttributes[key] = serializeAttributeValue(value);
2066 1828 }
2067 1829 return newAttributes;
2068 1830 }
2069 1831 function makeBlocksSerializable(blocks) {
2070 1832 return blocks.map((block) => {
2071 - const {
2072 - name,
2073 - innerBlocks,
2074 - attributes,
2075 - /*
2076 - * Any validation issues discovered when loading a block are appended
2077 - * to the block node with a logging function, which cannot be serialized.
2078 - *
2079 - * @see import("@wordpress/blocks/src/api/parser").parseRawBlock()
2080 - */
2081 - validationIssues,
2082 - ...rest
2083 - } = block;
1833 + const { name, innerBlocks, attributes, ...rest } = block;
1834 + delete rest.validationIssues;
2084 1835 return {
2085 1836 ...rest,
2086 1837 name,
2087 - attributes: makeBlockAttributesSerializable(name, attributes),
1838 + attributes: makeBlockAttributesSerializable(attributes),
2088 1839 innerBlocks: makeBlocksSerializable(innerBlocks)
2089 1840 };
2090 1841 });
2091 1842 }
2092 - function deserializeAttributeValue(schema, value) {
2093 - if (schema?.type === "rich-text" && typeof value === "string") {
2094 - return getCachedRichTextData(value);
2095 - }
2096 - if (Array.isArray(value)) {
2097 - return value.map(
2098 - (item) => deserializeAttributeValue(schema, item)
2099 - );
2100 - }
2101 - if (value && typeof value === "object") {
2102 - const result = {};
2103 - for (const [key, innerValue] of Object.entries(
2104 - value
2105 - )) {
2106 - result[key] = deserializeAttributeValue(
2107 - schema?.query?.[key],
2108 - innerValue
2109 - );
2110 - }
2111 - return result;
2112 - }
2113 - return value;
2114 - }
2115 - function deserializeBlockAttributes(blocks) {
2116 - return blocks.map((block) => {
2117 - const { name, innerBlocks, attributes, ...rest } = block;
2118 - const newAttributes = { ...attributes };
2119 - for (const [key, value] of Object.entries(attributes)) {
2120 - const schema = getBlockAttributeSchema(name, key);
2121 - if (schema) {
2122 - newAttributes[key] = deserializeAttributeValue(
2123 - schema,
2124 - value
2125 - );
2126 - }
2127 - }
2128 - return {
2129 - ...rest,
2130 - name,
2131 - attributes: newAttributes,
2132 - innerBlocks: deserializeBlockAttributes(innerBlocks ?? [])
2133 - };
2134 - });
2135 - }
2136 1843 function areBlocksEqual(gblock, yblock) {
2137 1844 const yblockAsJson = yblock.toJSON();
2138 1845 const overwrites = {
2139 1846 innerBlocks: null,
@@ -2138,9 +1845,9 @@
2138 1845 const overwrites = {
2139 1846 innerBlocks: null,
2140 1847 clientId: null
2141 1848 };
2142 - const res = (0, import_es63.default)(
1849 + const res = (0, import_es62.default)(
2143 1850 Object.assign({}, gblock, overwrites),
2144 1851 Object.assign({}, yblockAsJson, overwrites)
2145 1852 );
2146 1853 const inners = gblock.innerBlocks || [];
@@ -2149,9 +1856,9 @@
2149 1856 (block, i) => areBlocksEqual(block, yinners.get(i))
2150 1857 );
2151 1858 }
2152 1859 function createNewYAttributeMap(blockName, attributes) {
2153 - return new import_sync10.Y.Map(
1860 + return new import_sync9.Y.Map(
2154 1861 Object.entries(attributes).map(
2155 1862 ([attributeName, attributeValue]) => {
2156 1863 return [
2157 1864 attributeName,
@@ -2165,47 +1872,14 @@
2165 1872 )
2166 1873 );
2167 1874 }
2168 1875 function createNewYAttributeValue(blockName, attributeName, attributeValue) {
2169 - const schema = getBlockAttributeSchema(blockName, attributeName);
2170 - return createYValueFromSchema(schema, attributeValue);
2171 - }
2172 - function createYValueFromSchema(schema, value) {
2173 - if (!schema) {
2174 - return value;
1876 + const isRichText = isRichTextAttribute(blockName, attributeName);
1877 + if (isRichText) {
1878 + return new import_sync9.Y.Text(attributeValue?.toString() ?? "");
2175 1879 }
2176 - if (schema.type === "rich-text") {
2177 - return new import_sync10.Y.Text(value?.toString() ?? "");
2178 - }
2179 - if (schema.type === "array" && schema.query && Array.isArray(value)) {
2180 - const query = schema.query;
2181 - const yArray = new import_sync10.Y.Array();
2182 - yArray.insert(
2183 - 0,
2184 - value.map((item) => createYMapFromQuery(query, item))
2185 - );
2186 - return yArray;
2187 - }
2188 - if (schema.type === "object" && schema.query && isRecord(value)) {
2189 - return createYMapFromQuery(schema.query, value);
2190 - }
2191 - return value;
1880 + return attributeValue;
2192 1881 }
2193 - function isRecord(value) {
2194 - return !!value && typeof value === "object" && !Array.isArray(value);
2195 - }
2196 - function createYMapFromQuery(query, obj) {
2197 - if (!isRecord(obj)) {
2198 - return new import_sync10.Y.Map();
2199 - }
2200 - const entries = Object.entries(obj).map(
2201 - ([key, val]) => {
2202 - const subSchema = query[key];
2203 - return [key, createYValueFromSchema(subSchema, val)];
2204 - }
2205 - );
2206 - return new import_sync10.Y.Map(entries);
2207 - }
2208 1882 function createNewYBlock(block) {
2209 1883 return createYMap(
2210 1884 Object.fromEntries(
2211 1885 Object.entries(block).map(([key, value]) => {
@@ -2216,9 +1890,9 @@
2216 1890 createNewYAttributeMap(block.name, value)
2217 1891 ];
2218 1892 }
2219 1893 case "innerBlocks": {
2220 - const innerBlocks = new import_sync10.Y.Array();
1894 + const innerBlocks = new import_sync9.Y.Array();
2221 1895 if (!Array.isArray(value)) {
2222 1896 return [key, innerBlocks];
2223 1897 }
2224 1898 innerBlocks.insert(
@@ -2235,9 +1909,9 @@
2235 1909 })
2236 1910 )
2237 1911 );
2238 1912 }
2239 - function mergeCrdtBlocks(yblocks, incomingBlocks, attributeCursor, options = {}) {
1913 + function mergeCrdtBlocks(yblocks, incomingBlocks, cursorPosition) {
2240 1914 if (!serializableBlocksCache.has(incomingBlocks)) {
2241 1915 serializableBlocksCache.set(
2242 1916 incomingBlocks,
2243 1917 makeBlocksSerializable(incomingBlocks)
@@ -2242,19 +1916,22 @@
2242 1916 incomingBlocks,
2243 1917 makeBlocksSerializable(incomingBlocks)
2244 1918 );
2245 1919 }
2246 - const incomingBlocksToSync = serializableBlocksCache.get(incomingBlocks) ?? [];
1920 + const allBlocks = serializableBlocksCache.get(incomingBlocks) ?? [];
1921 + const blocksToSync = allBlocks.filter(
1922 + (block) => shouldBlockBeSynced(block)
1923 + );
2247 1924 const numOfCommonEntries = Math.min(
2248 - incomingBlocksToSync.length ?? 0,
1925 + blocksToSync.length ?? 0,
2249 1926 yblocks.length
2250 1927 );
2251 1928 let left = 0;
2252 1929 let right = 0;
2253 - for (; left < numOfCommonEntries && areBlocksEqual(incomingBlocksToSync[left], yblocks.get(left)); left++) {
1930 + for (; left < numOfCommonEntries && areBlocksEqual(blocksToSync[left], yblocks.get(left)); left++) {
2254 1931 }
2255 1932 for (; right < numOfCommonEntries - left && areBlocksEqual(
2256 - incomingBlocksToSync[incomingBlocksToSync.length - right - 1],
1933 + blocksToSync[blocksToSync.length - right - 1],
2257 1934 yblocks.get(yblocks.length - right - 1)
2258 1935 ); right++) {
2259 1936 }
2260 1937 const numOfUpdatesNeeded = numOfCommonEntries - left - right;
@@ -2259,129 +1936,88 @@
2259 1936 }
2260 1937 const numOfUpdatesNeeded = numOfCommonEntries - left - right;
2261 1938 const numOfInsertionsNeeded = Math.max(
2262 1939 0,
2263 - incomingBlocksToSync.length - yblocks.length
1940 + blocksToSync.length - yblocks.length
2264 1941 );
2265 1942 const numOfDeletionsNeeded = Math.max(
2266 1943 0,
2267 - yblocks.length - incomingBlocksToSync.length
1944 + yblocks.length - blocksToSync.length
2268 1945 );
2269 1946 for (let i = 0; i < numOfUpdatesNeeded; i++, left++) {
2270 - const incomingYBlock = incomingBlocksToSync[left];
2271 - const localYBlock = yblocks.get(left);
2272 - Object.entries(incomingYBlock).forEach(
2273 - ([incomingBlockProperty, incomingBlockPropertyValue]) => {
2274 - switch (incomingBlockProperty) {
2275 - case "attributes": {
2276 - const localAttributes = localYBlock.get(
2277 - incomingBlockProperty
1947 + const block = blocksToSync[left];
1948 + const yblock = yblocks.get(left);
1949 + Object.entries(block).forEach(([key, value]) => {
1950 + switch (key) {
1951 + case "attributes": {
1952 + const currentAttributes = yblock.get(key);
1953 + if (!currentAttributes) {
1954 + yblock.set(
1955 + key,
1956 + createNewYAttributeMap(block.name, value)
2278 1957 );
2279 - const incomingAttributes = incomingBlockPropertyValue;
2280 - if (!localAttributes) {
2281 - localYBlock.set(
2282 - incomingBlockProperty,
2283 - createNewYAttributeMap(
2284 - incomingYBlock.name,
2285 - incomingAttributes
2286 - )
1958 + break;
1959 + }
1960 + Object.entries(value).forEach(
1961 + ([attributeName, attributeValue]) => {
1962 + const currentAttribute = currentAttributes?.get(attributeName);
1963 + const isExpectedType = isExpectedAttributeType(
1964 + block.name,
1965 + attributeName,
1966 + currentAttribute
2287 1967 );
2288 - break;
2289 - }
2290 - Object.entries(incomingAttributes).forEach(
2291 - ([
2292 - incomingAttributeName,
2293 - incomingAttributeValue
2294 - ]) => {
2295 - const currentAttribute = localAttributes?.get(
2296 - incomingAttributeName
1968 + const isAttributeChanged = !isExpectedType || !(0, import_es62.default)(
1969 + currentAttribute,
1970 + attributeValue
1971 + );
1972 + if (isAttributeChanged) {
1973 + updateYBlockAttribute(
1974 + block.name,
1975 + attributeName,
1976 + attributeValue,
1977 + currentAttributes,
1978 + cursorPosition
2297 1979 );
2298 - const isExpectedType = isExpectedAttributeType(
2299 - incomingYBlock.name,
2300 - incomingAttributeName,
2301 - currentAttribute
2302 - );
2303 - const isYType = currentAttribute instanceof import_sync10.Y.AbstractType;
2304 - const isAttributeChanged = !isExpectedType || isYType || !(0, import_es63.default)(
2305 - currentAttribute,
2306 - incomingAttributeValue
2307 - );
2308 - if (isAttributeChanged) {
2309 - updateYBlockAttribute(
2310 - incomingYBlock.name,
2311 - incomingYBlock.clientId,
2312 - incomingAttributeName,
2313 - incomingAttributeValue,
2314 - localAttributes,
2315 - attributeCursor
2316 - );
2317 - }
2318 1980 }
2319 - );
2320 - localAttributes.forEach(
2321 - (_attrValue, attrName) => {
2322 - if (!incomingBlockPropertyValue.hasOwnProperty(
2323 - attrName
2324 - )) {
2325 - localAttributes.delete(attrName);
2326 - }
1981 + }
1982 + );
1983 + currentAttributes.forEach(
1984 + (_attrValue, attrName) => {
1985 + if (!value.hasOwnProperty(attrName)) {
1986 + currentAttributes.delete(attrName);
2327 1987 }
2328 - );
2329 - break;
2330 - }
2331 - case "innerBlocks": {
2332 - let yInnerBlocks = localYBlock.get(
2333 - incomingBlockProperty
2334 - );
2335 - if (!(yInnerBlocks instanceof import_sync10.Y.Array)) {
2336 - yInnerBlocks = new import_sync10.Y.Array();
2337 - localYBlock.set(
2338 - incomingBlockProperty,
2339 - yInnerBlocks
2340 - );
2341 1988 }
2342 - mergeCrdtBlocks(
2343 - yInnerBlocks,
2344 - incomingBlockPropertyValue ?? [],
2345 - attributeCursor,
2346 - options
2347 - );
2348 - break;
1989 + );
1990 + break;
1991 + }
1992 + case "innerBlocks": {
1993 + let yInnerBlocks = yblock.get(key);
1994 + if (!(yInnerBlocks instanceof import_sync9.Y.Array)) {
1995 + yInnerBlocks = new import_sync9.Y.Array();
1996 + yblock.set(key, yInnerBlocks);
2349 1997 }
2350 - case "clientId": {
2351 - if (options.preserveClientIds) {
2352 - break;
2353 - }
2354 - if (incomingBlockPropertyValue !== localYBlock.get(incomingBlockProperty)) {
2355 - localYBlock.set(
2356 - incomingBlockProperty,
2357 - incomingBlockPropertyValue
2358 - );
2359 - }
2360 - break;
1998 + mergeCrdtBlocks(
1999 + yInnerBlocks,
2000 + value ?? [],
2001 + cursorPosition
2002 + );
2003 + break;
2004 + }
2005 + default:
2006 + if (!(0, import_es62.default)(block[key], yblock.get(key))) {
2007 + yblock.set(key, value);
2361 2008 }
2362 - default:
2363 - if (!(0, import_es63.default)(
2364 - incomingYBlock[incomingBlockProperty],
2365 - localYBlock.get(incomingBlockProperty)
2366 - )) {
2367 - localYBlock.set(
2368 - incomingBlockProperty,
2369 - incomingBlockPropertyValue
2370 - );
2371 - }
2372 - }
2373 2009 }
2374 - );
2375 - localYBlock.forEach((_v, k) => {
2376 - if (!incomingYBlock.hasOwnProperty(k)) {
2377 - localYBlock.delete(k);
2010 + });
2011 + yblock.forEach((_v, k) => {
2012 + if (!block.hasOwnProperty(k)) {
2013 + yblock.delete(k);
2378 2014 }
2379 2015 });
2380 2016 }
2381 2017 yblocks.delete(left, numOfDeletionsNeeded);
2382 2018 for (let i = 0; i < numOfInsertionsNeeded; i++, left++) {
2383 - const newBlock = [createNewYBlock(incomingBlocksToSync[left])];
2019 + const newBlock = [createNewYBlock(blocksToSync[left])];
2384 2020 yblocks.insert(left, newBlock);
2385 2021 }
2386 2022 const knownClientIds = /* @__PURE__ */ new Set();
2387 2023 for (let j = 0; j < yblocks.length; j++) {
@@ -2396,200 +2032,89 @@
2396 2032 }
2397 2033 knownClientIds.add(clientId);
2398 2034 }
2399 2035 }
2400 - function areArrayElementsEqual(newElement, yElement) {
2401 - if (yElement instanceof import_sync10.Y.Map && isRecord(newElement)) {
2402 - return (0, import_es63.default)(newElement, yElement.toJSON());
2403 - }
2404 - return (0, import_es63.default)(newElement, yElement);
2405 - }
2406 - function mergeYArray(yArray, newValue, schema, cursorPosition, cursorScope) {
2407 - if (!schema.query) {
2408 - return;
2409 - }
2410 - const query = schema.query;
2411 - const numOfCommonEntries = Math.min(newValue.length, yArray.length);
2412 - let left = 0;
2413 - let right = 0;
2414 - for (; left < numOfCommonEntries && areArrayElementsEqual(newValue[left], yArray.get(left)); left++) {
2415 - }
2416 - for (; right < numOfCommonEntries - left && areArrayElementsEqual(
2417 - newValue[newValue.length - right - 1],
2418 - yArray.get(yArray.length - right - 1)
2419 - ); right++) {
2420 - }
2421 - const numOfUpdatesNeeded = numOfCommonEntries - left - right;
2422 - for (let i = 0; i < numOfUpdatesNeeded; i++) {
2423 - const currentElement = yArray.get(left + i);
2424 - const newElement = newValue[left + i];
2425 - if (currentElement instanceof import_sync10.Y.Map && isRecord(newElement)) {
2426 - mergeYMapValues(
2427 - currentElement,
2428 - newElement,
2429 - query,
2430 - cursorPosition,
2431 - cursorScope
2432 - );
2433 - } else {
2434 - yArray.delete(0, yArray.length);
2435 - yArray.insert(
2436 - 0,
2437 - newValue.map((item) => createYMapFromQuery(query, item))
2438 - );
2439 - return;
2440 - }
2441 - }
2442 - const numOfDeletionsNeeded = Math.max(0, yArray.length - newValue.length);
2443 - if (numOfDeletionsNeeded > 0) {
2444 - yArray.delete(left + numOfUpdatesNeeded, numOfDeletionsNeeded);
2445 - }
2446 - const numOfInsertionsNeeded = Math.max(
2447 - 0,
2448 - newValue.length - yArray.length
2449 - );
2450 - if (numOfInsertionsNeeded > 0) {
2451 - const insertAt = left + numOfUpdatesNeeded;
2452 - const itemsToInsert = new Array(
2453 - numOfInsertionsNeeded
2036 + function shouldBlockBeSynced(block) {
2037 + if ("core/gallery" === block.name) {
2038 + return !block.innerBlocks.some(
2039 + (innerBlock) => innerBlock.attributes && innerBlock.attributes.blob
2454 2040 );
2455 - for (let i = 0; i < numOfInsertionsNeeded; i++) {
2456 - itemsToInsert[i] = createYMapFromQuery(
2457 - query,
2458 - newValue[insertAt + i]
2459 - );
2460 - }
2461 - yArray.insert(insertAt, itemsToInsert);
2462 2041 }
2042 + return true;
2463 2043 }
2464 - function mergeYValue(schema, newVal, yMap, key, cursorPosition, cursorScope) {
2465 - const currentVal = yMap.get(key);
2466 - if (schema?.type === "rich-text" && typeof newVal === "string" && currentVal instanceof import_sync10.Y.Text) {
2467 - mergeRichTextUpdate(
2468 - currentVal,
2469 - newVal,
2470 - resolveRichTextCursorPosition(cursorPosition, cursorScope, newVal)
2471 - );
2472 - } else if (schema?.type === "array" && schema.query && Array.isArray(newVal) && currentVal instanceof import_sync10.Y.Array) {
2473 - mergeYArray(currentVal, newVal, schema, cursorPosition, cursorScope);
2474 - } else if (schema?.type === "object" && schema.query && isRecord(newVal) && currentVal instanceof import_sync10.Y.Map) {
2475 - mergeYMapValues(
2476 - currentVal,
2477 - newVal,
2478 - schema.query,
2479 - cursorPosition,
2480 - cursorScope
2481 - );
2044 + function updateYBlockAttribute(blockName, attributeName, attributeValue, currentAttributes, cursorPosition) {
2045 + const isRichText = isRichTextAttribute(blockName, attributeName);
2046 + const currentAttribute = currentAttributes.get(attributeName);
2047 + if (isRichText && "string" === typeof attributeValue && currentAttributes.has(attributeName) && currentAttribute instanceof import_sync9.Y.Text) {
2048 + mergeRichTextUpdate(currentAttribute, attributeValue, cursorPosition);
2482 2049 } else {
2483 - const newYValue = createYValueFromSchema(schema, newVal);
2484 - if (newYValue !== newVal || !(0, import_es63.default)(currentVal, newVal)) {
2485 - yMap.set(key, newYValue);
2486 - }
2487 - }
2488 - }
2489 - function mergeYMapValues(yMap, newObj, query, cursorPosition, cursorScope) {
2490 - for (const [key, newVal] of Object.entries(newObj)) {
2491 - mergeYValue(
2492 - query[key],
2493 - newVal,
2494 - yMap,
2495 - key,
2496 - cursorPosition,
2497 - cursorScope
2050 + currentAttributes.set(
2051 + attributeName,
2052 + createNewYAttributeValue(blockName, attributeName, attributeValue)
2498 2053 );
2499 2054 }
2500 - for (const key of yMap.keys()) {
2501 - if (!Object.hasOwn(newObj, key)) {
2502 - yMap.delete(key);
2503 - }
2504 - }
2505 2055 }
2506 - function updateYBlockAttribute(blockName, clientId, attributeName, attributeValue, currentAttributes, newCursorPosition) {
2507 - const schema = getBlockAttributeSchema(blockName, attributeName);
2508 - mergeYValue(
2509 - schema,
2510 - attributeValue,
2511 - currentAttributes,
2512 - attributeName,
2513 - newCursorPosition,
2514 - { attributeKey: attributeName, clientId }
2515 - );
2516 - }
2517 - function resolveRichTextCursorPosition(cursorPosition, cursorScope, updatedValue) {
2518 - return cursorPosition && cursorPosition.clientId === cursorScope.clientId && cursorPosition.attributeKey === cursorScope.attributeKey && "number" === typeof cursorPosition.offset && Number.isInteger(cursorPosition.offset) ? richTextOffsetToHtmlIndex(
2519 - updatedValue,
2520 - asRichTextOffset(cursorPosition.offset)
2521 - ) : null;
2522 - }
2523 - var cachedBlockAttributeSchemas;
2524 - function getBlockAttributeSchema(blockName, attributeName) {
2525 - if (!cachedBlockAttributeSchemas) {
2526 - cachedBlockAttributeSchemas = /* @__PURE__ */ new Map();
2056 + var cachedBlockAttributeTypes;
2057 + function getBlockAttributeType(blockName, attributeName) {
2058 + if (!cachedBlockAttributeTypes) {
2059 + cachedBlockAttributeTypes = /* @__PURE__ */ new Map();
2527 2060 for (const blockType of (0, import_blocks.getBlockTypes)()) {
2528 - cachedBlockAttributeSchemas.set(
2061 + const blockAttributeTypeMap = /* @__PURE__ */ new Map();
2062 + for (const [name, definition] of Object.entries(
2063 + blockType.attributes ?? {}
2064 + )) {
2065 + if (definition.type) {
2066 + blockAttributeTypeMap.set(name, definition.type);
2067 + }
2068 + }
2069 + cachedBlockAttributeTypes.set(
2529 2070 blockType.name,
2530 - new Map(
2531 - Object.entries(blockType.attributes ?? {}).map(
2532 - ([name, definition]) => {
2533 - const { role, type, query } = definition;
2534 - return [name, { role, type, query }];
2535 - }
2536 - )
2537 - )
2071 + blockAttributeTypeMap
2538 2072 );
2539 2073 }
2540 2074 }
2541 - return cachedBlockAttributeSchemas.get(blockName)?.get(attributeName);
2075 + return cachedBlockAttributeTypes.get(blockName)?.get(attributeName);
2542 2076 }
2543 2077 function isExpectedAttributeType(blockName, attributeName, attributeValue) {
2544 - const schema = getBlockAttributeSchema(blockName, attributeName);
2545 - if (schema?.type === "rich-text") {
2546 - return attributeValue instanceof import_sync10.Y.Text;
2547 - }
2548 - if (schema?.type === "string") {
2078 + const expectedAttributeType = getBlockAttributeType(
2079 + blockName,
2080 + attributeName
2081 + );
2082 + if (expectedAttributeType === "rich-text") {
2083 + return attributeValue instanceof import_sync9.Y.Text;
2084 + } else if (expectedAttributeType === "string") {
2549 2085 return typeof attributeValue === "string";
2550 2086 }
2551 - if (schema?.type === "array" && schema.query) {
2552 - return attributeValue instanceof import_sync10.Y.Array;
2553 - }
2554 - if (schema?.type === "object" && schema.query) {
2555 - return attributeValue instanceof import_sync10.Y.Map;
2556 - }
2557 2087 return true;
2558 2088 }
2559 - function isLocalAttribute(blockName, attributeName) {
2560 - return "local" === getBlockAttributeSchema(blockName, attributeName)?.role;
2089 + function isRichTextAttribute(blockName, attributeName) {
2090 + return "rich-text" === getBlockAttributeType(blockName, attributeName);
2561 2091 }
2562 2092 var localDoc;
2563 - function mergeRichTextUpdate(blockYText, updatedValue, htmlCursorIndex = null) {
2093 + function mergeRichTextUpdate(blockYText, updatedValue, cursorPosition = null) {
2094 + if (!localDoc) {
2095 + localDoc = new import_sync9.Y.Doc();
2096 + }
2097 + const localYText = localDoc.getText("temporary-text");
2098 + localYText.delete(0, localYText.length);
2099 + localYText.insert(0, updatedValue);
2564 2100 const currentValueAsDelta = new Delta(blockYText.toDelta());
2565 - const updatedValueAsDelta = new Delta([{ insert: updatedValue }]);
2101 + const updatedValueAsDelta = new Delta(localYText.toDelta());
2566 2102 const deltaDiff = currentValueAsDelta.diffWithCursor(
2567 2103 updatedValueAsDelta,
2568 - htmlCursorIndex
2104 + cursorPosition
2569 2105 );
2570 - const safeDiff = htmlCursorIndex === null || isDeltaVerificationMatch(blockYText, deltaDiff, updatedValue) ? deltaDiff : currentValueAsDelta.diff(updatedValueAsDelta);
2571 - blockYText.applyDelta(safeDiff.ops);
2106 + blockYText.applyDelta(deltaDiff.ops);
2572 2107 }
2573 - function isDeltaVerificationMatch(blockYText, delta, expectedValue) {
2574 - if (!localDoc) {
2575 - localDoc = new import_sync10.Y.Doc();
2576 - }
2577 - const verificationYText = localDoc.getText("verification-text");
2578 - verificationYText.delete(0, verificationYText.length);
2579 - verificationYText.insert(0, blockYText.toString());
2580 - verificationYText.applyDelta(delta.ops);
2581 - return verificationYText.toString() === expectedValue;
2582 - }
2583 2108
2584 2109 // packages/core-data/build-module/utils/crdt-selection.mjs
2585 - var import_data5 = __toESM(require_data(), 1);
2110 + var import_data6 = __toESM(require_data(), 1);
2586 2111 var import_block_editor4 = __toESM(require_block_editor(), 1);
2587 2112 var import_blocks2 = __toESM(require_blocks(), 1);
2588 - var import_sync13 = __toESM(require_sync(), 1);
2113 + var import_sync12 = __toESM(require_sync(), 1);
2589 2114
2590 2115 // packages/core-data/build-module/utils/block-selection-history.mjs
2591 - var import_sync12 = __toESM(require_sync(), 1);
2116 + var import_sync11 = __toESM(require_sync(), 1);
2592 2117 var SELECTION_HISTORY_DEFAULT_SIZE = 5;
2593 2118 var YSelectionType = /* @__PURE__ */ ((YSelectionType2) => {
2594 2119 YSelectionType2["RelativeSelection"] = "RelativeSelection";
2595 2120 YSelectionType2["BlockSelection"] = "BlockSelection";
@@ -2633,13 +2158,12 @@
2633 2158 const clientId = selection.clientId;
2634 2159 const block = findBlockByClientIdInDoc(clientId, ydoc);
2635 2160 const attributes = block?.get("attributes");
2636 2161 const attributeKey = selection.attributeKey;
2637 - let changedYText = null;
2638 - if (attributeKey && attributes) {
2639 - changedYText = getYTextByAttributeKey(attributes, attributeKey);
2640 - }
2641 - if (!(changedYText instanceof import_sync12.Y.Text) || !attributeKey || !clientId) {
2162 + const changedYText = attributeKey ? attributes?.get(attributeKey) : void 0;
2163 + const isYText = changedYText instanceof import_sync11.Y.Text;
2164 + const isFullyDefinedSelection = attributeKey && clientId;
2165 + if (!isYText || !isFullyDefinedSelection) {
2642 2166 return {
2643 2167 type: "BlockSelection",
2644 2168 clientId
2645 2169 };
@@ -2644,14 +2168,11 @@
2644 2168 clientId
2645 2169 };
2646 2170 }
2647 2171 const offset = selection.offset ?? 0;
2648 - const relativePosition = import_sync12.Y.createRelativePositionFromTypeIndex(
2172 + const relativePosition = import_sync11.Y.createRelativePositionFromTypeIndex(
2649 2173 changedYText,
2650 - richTextOffsetToHtmlIndex(
2651 - changedYText.toString(),
2652 - asRichTextOffset(offset)
2653 - )
2174 + offset
2654 2175 );
2655 2176 return {
2656 2177 type: "RelativeSelection",
2657 2178 attributeKey,
@@ -2679,9 +2200,9 @@
2679 2200 }
2680 2201 function convertYSelectionToBlockSelection(ySelection, ydoc) {
2681 2202 if (ySelection.type === YSelectionType.RelativeSelection) {
2682 2203 const { relativePosition, attributeKey, clientId } = ySelection;
2683 - const absolutePosition = import_sync13.Y.createAbsolutePositionFromRelativePosition(
2204 + const absolutePosition = import_sync12.Y.createAbsolutePositionFromRelativePosition(
2684 2205 relativePosition,
2685 2206 ydoc
2686 2207 );
2687 2208 if (absolutePosition) {
@@ -2687,12 +2208,9 @@
2687 2208 if (absolutePosition) {
2688 2209 return {
2689 2210 clientId,
2690 2211 attributeKey,
2691 - offset: htmlIndexToRichTextOffset(
2692 - absolutePosition.type.toString(),
2693 - asHtmlStringIndex(absolutePosition.index)
2694 - )
2212 + offset: absolutePosition.index
2695 2213 };
2696 2214 }
2697 2215 } else if (ySelection.type === YSelectionType.BlockSelection) {
2698 2216 return {
@@ -2742,10 +2260,10 @@
2742 2260 );
2743 2261 if (selectionToRestore === null) {
2744 2262 return;
2745 2263 }
2746 - const { getBlock } = (0, import_data5.select)(import_block_editor4.store);
2747 - const { resetSelection } = (0, import_data5.dispatch)(import_block_editor4.store);
2264 + const { getBlock } = (0, import_data6.select)(import_block_editor4.store);
2265 + const { resetSelection } = (0, import_data6.dispatch)(import_block_editor4.store);
2748 2266 const { selectionStart, selectionEnd } = selectionToRestore;
2749 2267 const isSelectionInSameBlock = selectionStart.clientId === selectionEnd.clientId;
2750 2268 if (isSelectionInSameBlock) {
2751 2269 const block = getBlock(selectionStart.clientId);
@@ -2792,8 +2310,27 @@
2792 2310 }
2793 2311
2794 2312 // packages/core-data/build-module/utils/crdt.mjs
2795 2313 var POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE = "_crdt_document";
2314 + var allowedPostProperties = /* @__PURE__ */ new Set([
2315 + "author",
2316 + "blocks",
2317 + "content",
2318 + "categories",
2319 + "comment_status",
2320 + "date",
2321 + "excerpt",
2322 + "featured_media",
2323 + "format",
2324 + "meta",
2325 + "ping_status",
2326 + "slug",
2327 + "status",
2328 + "sticky",
2329 + "tags",
2330 + "template",
2331 + "title"
2332 + ]);
2796 2333 var disallowedPostMetaKeys = /* @__PURE__ */ new Set([
2797 2334 POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE
2798 2335 ]);
2799 2336 function defaultApplyChangesToCRDTDoc(ydoc, changes) {
@@ -2810,12 +2347,12 @@
2810 2347 }
2811 2348 }
2812 2349 });
2813 2350 }
2814 - function applyPostChangesToCRDTDoc(ydoc, changes, syncedProperties) {
2351 + function applyPostChangesToCRDTDoc(ydoc, changes, _postType) {
2815 2352 const ymap = getRootMap(ydoc, CRDT_RECORD_MAP_KEY);
2816 2353 Object.keys(changes).forEach((key) => {
2817 - if (!syncedProperties.has(key)) {
2354 + if (!allowedPostProperties.has(key)) {
2818 2355 return;
2819 2356 }
2820 2357 const newValue = changes[key];
2821 2358 if ("function" === typeof newValue) {
@@ -2822,29 +2359,19 @@
2822 2359 return;
2823 2360 }
2824 2361 switch (key) {
2825 2362 case "blocks": {
2826 - const newCursorPosition = parseCursorSelection(
2827 - changes.selection
2828 - );
2829 - const rawContent = getRawValue(changes.content);
2830 - if (!newValue && typeof rawContent === "string") {
2831 - mergeContentWithoutBlocks(
2832 - ymap,
2833 - rawContent,
2834 - newCursorPosition
2835 - );
2836 - break;
2837 - } else if (!newValue) {
2363 + if (!newValue) {
2838 2364 ymap.set(key, void 0);
2839 2365 break;
2840 2366 }
2841 2367 let currentBlocks = ymap.get(key);
2842 - if (!(currentBlocks instanceof import_sync14.Y.Array)) {
2843 - currentBlocks = new import_sync14.Y.Array();
2368 + if (!(currentBlocks instanceof import_sync13.Y.Array)) {
2369 + currentBlocks = new import_sync13.Y.Array();
2844 2370 ymap.set(key, currentBlocks);
2845 2371 }
2846 - mergeCrdtBlocks(currentBlocks, newValue, newCursorPosition);
2372 + const cursorPosition = changes.selection?.selectionStart?.offset ?? null;
2373 + mergeCrdtBlocks(currentBlocks, newValue, cursorPosition);
2847 2374 break;
2848 2375 }
2849 2376 case "content":
2850 2377 case "excerpt":
@@ -2853,12 +2380,12 @@
2853 2380 let rawValue = getRawValue(newValue);
2854 2381 if (key === "title" && !currentValue?.toString() && "Auto Draft" === rawValue) {
2855 2382 rawValue = "";
2856 2383 }
2857 - if (currentValue instanceof import_sync14.Y.Text) {
2384 + if (currentValue instanceof import_sync13.Y.Text) {
2858 2385 mergeRichTextUpdate(currentValue, rawValue ?? "");
2859 2386 } else {
2860 - const newYText = new import_sync14.Y.Text(rawValue ?? "");
2387 + const newYText = new import_sync13.Y.Text(rawValue ?? "");
2861 2388 ymap.set(key, newYText);
2862 2389 }
2863 2390 break;
2864 2391 }
@@ -2907,43 +2434,17 @@
2907 2434 updateSelectionHistory(ydoc, selection);
2908 2435 }, 0);
2909 2436 }
2910 2437 }
2911 - function mergeContentWithoutBlocks(ymap, rawContent, cursorPosition) {
2912 - let currentBlocks = ymap.get("blocks");
2913 - if (!(currentBlocks instanceof import_sync14.Y.Array)) {
2914 - currentBlocks = new import_sync14.Y.Array();
2915 - ymap.set("blocks", currentBlocks);
2916 - }
2917 - mergeCrdtBlocks(
2918 - currentBlocks,
2919 - (0, import_blocks3.parse)(rawContent),
2920 - cursorPosition,
2921 - { preserveClientIds: true }
2922 - );
2438 + function defaultGetChangesFromCRDTDoc(crdtDoc) {
2439 + return getRootMap(crdtDoc, CRDT_RECORD_MAP_KEY).toJSON();
2923 2440 }
2924 - function parseCursorSelection(selection) {
2925 - const selectionStart = selection?.selectionStart;
2926 - return selectionStart?.clientId && selectionStart.attributeKey && "number" === typeof selectionStart.offset && Number.isInteger(selectionStart.offset) ? {
2927 - attributeKey: selectionStart.attributeKey,
2928 - clientId: selectionStart.clientId,
2929 - offset: asRichTextOffset(selectionStart.offset)
2930 - } : null;
2931 - }
2932 - function defaultGetChangesFromCRDTDoc(crdtDoc, editedRecord) {
2933 - const docRecord = getRootMap(crdtDoc, CRDT_RECORD_MAP_KEY).toJSON();
2934 - return Object.fromEntries(
2935 - Object.entries(docRecord).filter(
2936 - ([key, newValue]) => haveValuesChanged(editedRecord?.[key], newValue)
2937 - )
2938 - );
2939 - }
2940 - function getPostChangesFromCRDTDoc(ydoc, editedRecord, syncedProperties) {
2441 + function getPostChangesFromCRDTDoc(ydoc, editedRecord, _postType) {
2941 2442 const ymap = getRootMap(ydoc, CRDT_RECORD_MAP_KEY);
2942 2443 let allowedMetaChanges = {};
2943 2444 const changes = Object.fromEntries(
2944 2445 Object.entries(ymap.toJSON()).filter(([key, newValue]) => {
2945 - if (!syncedProperties.has(key)) {
2446 + if (!allowedPostProperties.has(key)) {
2946 2447 return false;
2947 2448 }
2948 2449 const currentValue = editedRecord[key];
2949 2450 switch (key) {
@@ -2961,21 +2462,15 @@
2961 2462 }
2962 2463 return haveValuesChanged(currentValue, newValue);
2963 2464 }
2964 2465 case "meta": {
2965 - const currentMeta = currentValue ?? {};
2966 2466 allowedMetaChanges = Object.fromEntries(
2967 2467 Object.entries(newValue ?? {}).filter(
2968 - ([metaKey]) => {
2969 - if (disallowedPostMetaKeys.has(metaKey)) {
2970 - return false;
2971 - }
2972 - return metaKey in currentMeta;
2973 - }
2468 + ([metaKey]) => !disallowedPostMetaKeys.has(metaKey)
2974 2469 )
2975 2470 );
2976 2471 const mergedValue = {
2977 - ...currentMeta,
2472 + ...currentValue,
2978 2473 ...allowedMetaChanges
2979 2474 };
2980 2475 return haveValuesChanged(currentValue, mergedValue);
2981 2476 }
@@ -2999,17 +2494,8 @@
2999 2494 }
3000 2495 }
3001 2496 })
3002 2497 );
3003 - if (changes.blocks) {
3004 - changes.blocks = deserializeBlockAttributes(
3005 - changes.blocks
3006 - );
3007 - }
3008 - if (changes.blocks && !changes.content) {
3009 - const capturedBlocks = changes.blocks;
3010 - changes.content = () => (0, import_blocks3.__unstableSerializeAndClean)(capturedBlocks);
3011 - }
3012 2498 if ("object" === typeof changes.meta) {
3013 2499 changes.meta = {
3014 2500 ...editedRecord.meta,
3015 2501 ...allowedMetaChanges
@@ -3029,14 +2515,8 @@
3029 2515 applyChangesToCRDTDoc: defaultApplyChangesToCRDTDoc,
3030 2516 createAwareness: (ydoc) => new BaseAwareness(ydoc),
3031 2517 getChangesFromCRDTDoc: defaultGetChangesFromCRDTDoc
3032 2518 };
3033 - var defaultCollectionSyncConfig = {
3034 - applyChangesToCRDTDoc: () => {
3035 - },
3036 - getChangesFromCRDTDoc: () => ({}),
3037 - shouldSync: (_, objectId) => null === objectId
3038 - };
3039 2519 function getRawValue(value) {
3040 2520 if ("string" === typeof value) {
3041 2521 return value;
3042 2522 }
@@ -3045,9 +2525,9 @@
3045 2525 }
3046 2526 return void 0;
3047 2527 }
3048 2528 function haveValuesChanged(currentValue, newValue) {
3049 - return !(0, import_es64.default)(currentValue, newValue);
2529 + return !(0, import_es63.default)(currentValue, newValue);
3050 2530 }
3051 2531 function updateMapValue(map, key, currentValue, newValue) {
3052 2532 if (void 0 === newValue) {
3053 2533 map.delete(key);
@@ -3077,9 +2557,9 @@
3077 2557 name: "__unstableBase",
3078 2558 baseURL: "/",
3079 2559 baseURLParams: {
3080 2560 // Please also change the preload path when changing this.
3081 - // @see lib/compat/wordpress-7.1/preload.php
2561 + // @see lib/compat/wordpress-7.0/preload.php
3082 2562 _fields: [
3083 2563 "description",
3084 2564 "gmt_offset",
3085 2565 "home",
@@ -3084,8 +2564,12 @@
3084 2564 "gmt_offset",
3085 2565 "home",
3086 2566 "image_sizes",
3087 2567 "image_size_threshold",
2568 + "image_output_formats",
2569 + "jpeg_interlaced",
2570 + "png_interlaced",
2571 + "gif_interlaced",
3088 2572 "name",
3089 2573 "site_icon",
3090 2574 "site_icon_url",
3091 2575 "site_logo",
@@ -3097,10 +2581,9 @@
3097 2581 ].join(",")
3098 2582 },
3099 2583 // The entity doesn't support selecting multiple records.
3100 2584 // The property is maintained for backward compatibility.
3101 - plural: "__unstableBases",
3102 - supportsPagination: false
2585 + plural: "__unstableBases"
3103 2586 },
3104 2587 {
3105 2588 label: (0, import_i18n.__)("Post Type"),
3106 2589 name: "postType",
@@ -3107,10 +2590,9 @@
3107 2590 kind: "root",
3108 2591 key: "slug",
3109 2592 baseURL: "/wp/v2/types",
3110 2593 baseURLParams: { context: "edit" },
3111 - plural: "postTypes",
3112 - supportsPagination: false
2594 + plural: "postTypes"
3113 2595 },
3114 2596 {
3115 2597 name: "media",
3116 2598 kind: "root",
@@ -3127,10 +2609,9 @@
3127 2609 key: "slug",
3128 2610 baseURL: "/wp/v2/taxonomies",
3129 2611 baseURLParams: { context: "edit" },
3130 2612 plural: "taxonomies",
3131 - label: (0, import_i18n.__)("Taxonomy"),
3132 - supportsPagination: false
2613 + label: (0, import_i18n.__)("Taxonomy")
3133 2614 },
3134 2615 {
3135 2616 name: "sidebar",
3136 2617 kind: "root",
@@ -3137,10 +2618,9 @@
3137 2618 baseURL: "/wp/v2/sidebars",
3138 2619 baseURLParams: { context: "edit" },
3139 2620 plural: "sidebars",
3140 2621 transientEdits: { blocks: true },
3141 - label: (0, import_i18n.__)("Widget areas"),
3142 - supportsPagination: false
2622 + label: (0, import_i18n.__)("Widget areas")
3143 2623 },
3144 2624 {
3145 2625 name: "widget",
3146 2626 kind: "root",
@@ -3147,10 +2627,9 @@
3147 2627 baseURL: "/wp/v2/widgets",
3148 2628 baseURLParams: { context: "edit" },
3149 2629 plural: "widgets",
3150 2630 transientEdits: { blocks: true },
3151 - label: (0, import_i18n.__)("Widgets"),
3152 - supportsPagination: false
2631 + label: (0, import_i18n.__)("Widgets")
3153 2632 },
3154 2633 {
3155 2634 name: "widgetType",
3156 2635 kind: "root",
@@ -3156,10 +2635,9 @@
3156 2635 kind: "root",
3157 2636 baseURL: "/wp/v2/widget-types",
3158 2637 baseURLParams: { context: "edit" },
3159 2638 plural: "widgetTypes",
3160 - label: (0, import_i18n.__)("Widget types"),
3161 - supportsPagination: false
2639 + label: (0, import_i18n.__)("Widget types")
3162 2640 },
3163 2641 {
3164 2642 label: (0, import_i18n.__)("User"),
3165 2643 name: "user",
@@ -3176,10 +2654,9 @@
3176 2654 baseURL: "/wp/v2/comments",
3177 2655 baseURLParams: { context: "edit" },
3178 2656 plural: "comments",
3179 2657 label: (0, import_i18n.__)("Comment"),
3180 - supportsPagination: true,
3181 - syncConfig: defaultCollectionSyncConfig
2658 + supportsPagination: true
3182 2659 },
3183 2660 {
3184 2661 name: "menu",
3185 2662 kind: "root",
@@ -3205,10 +2682,9 @@
3205 2682 baseURL: "/wp/v2/menu-locations",
3206 2683 baseURLParams: { context: "edit" },
3207 2684 plural: "menuLocations",
3208 2685 label: (0, import_i18n.__)("Menu Location"),
3209 - key: "name",
3210 - supportsPagination: false
2686 + key: "name"
3211 2687 },
3212 2688 {
3213 2689 label: (0, import_i18n.__)("Global Styles"),
3214 2690 name: "globalStyles",
@@ -3227,10 +2703,9 @@
3227 2703 kind: "root",
3228 2704 baseURL: "/wp/v2/themes",
3229 2705 baseURLParams: { context: "edit" },
3230 2706 plural: "themes",
3231 - key: "stylesheet",
3232 - supportsPagination: false
2707 + key: "stylesheet"
3233 2708 },
3234 2709 {
3235 2710 label: (0, import_i18n.__)("Plugins"),
3236 2711 name: "plugin",
@@ -3237,10 +2712,9 @@
3237 2712 kind: "root",
3238 2713 baseURL: "/wp/v2/plugins",
3239 2714 baseURLParams: { context: "edit" },
3240 2715 plural: "plugins",
3241 - key: "plugin",
3242 - supportsPagination: false
2716 + key: "plugin"
3243 2717 },
3244 2718 {
3245 2719 label: (0, import_i18n.__)("Status"),
3246 2720 name: "status",
@@ -3247,10 +2721,9 @@
3247 2721 kind: "root",
3248 2722 baseURL: "/wp/v2/statuses",
3249 2723 baseURLParams: { context: "edit" },
3250 2724 plural: "statuses",
3251 - key: "slug",
3252 - supportsPagination: false
2725 + key: "slug"
3253 2726 },
3254 2727 {
3255 2728 label: (0, import_i18n.__)("Registered Templates"),
3256 2729 name: "registeredTemplate",
@@ -3255,10 +2728,9 @@
3255 2728 label: (0, import_i18n.__)("Registered Templates"),
3256 2729 name: "registeredTemplate",
3257 2730 kind: "root",
3258 2731 baseURL: "/wp/v2/registered-templates",
3259 - key: "id",
3260 - supportsPagination: false
2732 + key: "id"
3261 2733 },
3262 2734 {
3263 2735 label: (0, import_i18n.__)("Font Collections"),
3264 2736 name: "fontCollection",
@@ -3265,10 +2737,9 @@
3265 2737 kind: "root",
3266 2738 baseURL: "/wp/v2/font-collections",
3267 2739 baseURLParams: { context: "view" },
3268 2740 plural: "fontCollections",
3269 - key: "slug",
3270 - supportsPagination: true
2741 + key: "slug"
3271 2742 },
3272 2743 {
3273 2744 label: (0, import_i18n.__)("Icons"),
3274 2745 name: "icon",
@@ -3275,12 +2746,17 @@
3275 2746 kind: "root",
3276 2747 baseURL: "/wp/v2/icons",
3277 2748 baseURLParams: { context: "view" },
3278 2749 plural: "icons",
3279 - key: "name",
3280 - supportsPagination: false
2750 + key: "name"
3281 2751 }
3282 - ];
2752 + ].map((entity2) => {
2753 + const syncEnabledRootEntities = /* @__PURE__ */ new Set(["comment"]);
2754 + if (syncEnabledRootEntities.has(entity2.name)) {
2755 + entity2.syncConfig = defaultSyncConfig;
2756 + }
2757 + return entity2;
2758 + });
3283 2759 var deprecatedEntities = {
3284 2760 root: {
3285 2761 media: {
3286 2762 since: "6.9",
@@ -3313,9 +2789,9 @@
3313 2789 }
3314 2790 if (persistedRecord) {
3315 2791 const objectType = `postType/${name}`;
3316 2792 const objectId = persistedRecord.id;
3317 - const serializedDoc = getSyncManager()?.createPersistedCRDTDoc(
2793 + const serializedDoc = await getSyncManager()?.createPersistedCRDTDoc(
3318 2794 objectType,
3319 2795 objectId
3320 2796 );
3321 2797 if (serializedDoc) {
@@ -3327,37 +2803,16 @@
3327 2803 }
3328 2804 return newEdits;
3329 2805 };
3330 2806 async function loadPostTypeEntities() {
3331 - const postTypesPromise = (0, import_api_fetch2.default)({ path: "/wp/v2/types?context=view" });
3332 - const taxonomiesPromise = window._wpCollaborationEnabled ? (0, import_api_fetch2.default)({ path: "/wp/v2/taxonomies?context=view" }) : Promise.resolve({});
3333 - const [postTypes, taxonomies] = await Promise.all([
3334 - postTypesPromise,
3335 - taxonomiesPromise
3336 - ]);
2807 + const postTypes = await (0, import_api_fetch.default)({
2808 + path: "/wp/v2/types?context=view"
2809 + });
3337 2810 return Object.entries(postTypes ?? {}).map(([name, postType]) => {
3338 2811 const isTemplate = ["wp_template", "wp_template_part"].includes(
3339 2812 name
3340 2813 );
3341 2814 const namespace = postType?.rest_namespace ?? "wp/v2";
3342 - const syncedProperties = /* @__PURE__ */ new Set([
3343 - "author",
3344 - "blocks",
3345 - "content",
3346 - "comment_status",
3347 - "date",
3348 - "excerpt",
3349 - "featured_media",
3350 - "format",
3351 - "meta",
3352 - "ping_status",
3353 - "slug",
3354 - "status",
3355 - "sticky",
3356 - "template",
3357 - "title",
3358 - ...postType.taxonomies?.map((taxonomy) => taxonomies?.[taxonomy]?.rest_base)?.filter(Boolean) ?? []
3359 - ]);
3360 2815 const entity2 = {
3361 2816 kind: "postType",
3362 2817 baseURL: `/${namespace}/${postType.rest_base}`,
3363 2818 baseURLParams: { context: "edit" },
@@ -3376,10 +2831,8 @@
3376 2831 getRevisionsUrl: (parentId, revisionId) => `/${namespace}/${postType.rest_base}/${parentId}/revisions${revisionId ? "/" + revisionId : ""}`,
3377 2832 revisionKey: isTemplate && !window?.__experimentalTemplateActivate ? "wp_id" : DEFAULT_ENTITY_KEY
3378 2833 };
3379 2834 entity2.syncConfig = {
3380 - // Save a CRDT document with this entity
3381 - supportsPersistence: true,
3382 2835 /**
3383 2836 * Apply changes from the local editor to the local CRDT document so
3384 2837 * that those changes can be synced to other peers (via the provider).
3385 2838 *
@@ -3386,9 +2839,9 @@
3386 2839 * @param {import('@wordpress/sync').CRDTDoc} crdtDoc
3387 2840 * @param {Partial< import('@wordpress/sync').ObjectData >} changes
3388 2841 * @return {void}
3389 2842 */
3390 - applyChangesToCRDTDoc: (crdtDoc, changes) => applyPostChangesToCRDTDoc(crdtDoc, changes, syncedProperties),
2843 + applyChangesToCRDTDoc: (crdtDoc, changes) => applyPostChangesToCRDTDoc(crdtDoc, changes, postType),
3391 2844 /**
3392 2845 * Create the awareness instance for the entity's CRDT document.
3393 2846 *
3394 2847 * @param {import('@wordpress/sync').CRDTDoc} ydoc
@@ -3407,13 +2860,9 @@
3407 2860 * @param {import('@wordpress/sync').CRDTDoc} crdtDoc
3408 2861 * @param {import('@wordpress/sync').ObjectData} editedRecord
3409 2862 * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record
3410 2863 */
3411 - getChangesFromCRDTDoc: (crdtDoc, editedRecord) => getPostChangesFromCRDTDoc(
3412 - crdtDoc,
3413 - editedRecord,
3414 - syncedProperties
3415 - ),
2864 + getChangesFromCRDTDoc: (crdtDoc, editedRecord) => getPostChangesFromCRDTDoc(crdtDoc, editedRecord, postType),
3416 2865 /**
3417 2866 * Extract changes from a CRDT document that can be used to update the
3418 2867 * local editor state.
3419 2868 *
@@ -3420,17 +2869,16 @@
3420 2869 * @param {import('@wordpress/sync').ObjectData} record
3421 2870 * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record
3422 2871 */
3423 2872 getPersistedCRDTDoc: (record) => {
3424 - return record?.meta?.[POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE] || null;
3425 - },
3426 - shouldSync: () => !(Array.isArray(window._wpCollaborationDisabledPostTypes) && window._wpCollaborationDisabledPostTypes.includes(name))
2873 + return record?.meta[POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE] || null;
2874 + }
3427 2875 };
3428 2876 return entity2;
3429 2877 });
3430 2878 }
3431 2879 async function loadTaxonomyEntities() {
3432 - const taxonomies = await (0, import_api_fetch2.default)({
2880 + const taxonomies = await (0, import_api_fetch.default)({
3433 2881 path: "/wp/v2/taxonomies?context=view"
3434 2882 });
3435 2883 return Object.entries(taxonomies ?? {}).map(([name, taxonomy]) => {
3436 2884 const namespace = taxonomy?.rest_namespace ?? "wp/v2";
@@ -3453,12 +2901,11 @@
3453 2901 name: "site",
3454 2902 kind: "root",
3455 2903 key: false,
3456 2904 baseURL: "/wp/v2/settings",
3457 - supportsPagination: false,
3458 2905 meta: {}
3459 2906 };
3460 - const site = await (0, import_api_fetch2.default)({
2907 + const site = await (0, import_api_fetch.default)({
3461 2908 path: entity2.baseURL,
3462 2909 method: "OPTIONS"
3463 2910 });
3464 2911 const labels = {};
@@ -3485,26 +2932,22 @@
3485 2932 }
3486 2933 const queryParts = get_query_parts_default(query);
3487 2934 return queryParts.context;
3488 2935 }
3489 - function getMergedItemIds(itemIds = [], nextItemIds, { page = 1, offset, perPage = 10 } = {}) {
3490 - if (perPage === -1) {
2936 + function getMergedItemIds(itemIds, nextItemIds, page, perPage) {
2937 + const receivedAllIds = page === 1 && perPage === -1;
2938 + if (receivedAllIds) {
3491 2939 return nextItemIds;
3492 2940 }
3493 - const nextItemIdsStartIndex = offset ?? (page - 1) * perPage;
3494 - const nextItemIdsRange = Math.max(perPage, nextItemIds.length);
2941 + const nextItemIdsStartIndex = (page - 1) * perPage;
3495 2942 const size = Math.max(
3496 - itemIds.length,
2943 + itemIds?.length ?? 0,
3497 2944 nextItemIdsStartIndex + nextItemIds.length
3498 2945 );
3499 2946 const mergedItemIds = new Array(size);
3500 2947 for (let i = 0; i < size; i++) {
3501 - const isInNextItemsRange = i >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + nextItemIdsRange;
3502 - if (isInNextItemsRange) {
3503 - mergedItemIds[i] = nextItemIds[i - nextItemIdsStartIndex];
3504 - } else {
3505 - mergedItemIds[i] = itemIds[i];
3506 - }
2948 + const isInNextItemsRange = i >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + perPage;
2949 + mergedItemIds[i] = isInNextItemsRange ? nextItemIds[i - nextItemIdsStartIndex] : itemIds?.[i];
3507 2950 }
3508 2951 return mergedItemIds;
3509 2952 }
3510 2953 function removeEntitiesById(entities2, ids) {
@@ -3523,22 +2966,20 @@
3523 2966 switch (action.type) {
3524 2967 case "RECEIVE_ITEMS": {
3525 2968 const context = getContextFromAction(action);
3526 2969 const key = action.key || DEFAULT_ENTITY_KEY;
3527 - const itemsList = Array.isArray(action.items) ? action.items : [action.items];
3528 2970 return {
3529 2971 ...state,
3530 2972 [context]: {
3531 2973 ...state[context],
3532 - ...Object.fromEntries(
3533 - itemsList.map((item) => [
3534 - item?.[key],
3535 - conservativeMapItem(
3536 - state?.[context]?.[item?.[key]],
3537 - item
3538 - )
3539 - ])
3540 - )
2974 + ...action.items.reduce((accumulator, value) => {
2975 + const itemId = value?.[key];
2976 + accumulator[itemId] = conservativeMapItem(
2977 + state?.[context]?.[itemId],
2978 + value
2979 + );
2980 + return accumulator;
2981 + }, {})
3541 2982 }
3542 2983 };
3543 2984 }
3544 2985 case "REMOVE_ITEMS":
@@ -3555,9 +2996,8 @@
3555 2996 switch (action.type) {
3556 2997 case "RECEIVE_ITEMS": {
3557 2998 const context = getContextFromAction(action);
3558 2999 const { query, key = DEFAULT_ENTITY_KEY } = action;
3559 - const itemsList = Array.isArray(action.items) ? action.items : [action.items];
3560 3000 const queryParts = query ? get_query_parts_default(query) : {};
3561 3001 const isCompleteQuery = !query || !Array.isArray(queryParts.fields);
3562 3002 return {
3563 3003 ...state,
@@ -3562,9 +3002,9 @@
3562 3002 return {
3563 3003 ...state,
3564 3004 [context]: {
3565 3005 ...state[context],
3566 - ...itemsList.reduce((result, item) => {
3006 + ...action.items.reduce((result, item) => {
3567 3007 const itemId = item?.[key];
3568 3008 result[itemId] = state?.[context]?.[itemId] || isCompleteQuery;
3569 3009 return result;
3570 3010 }, {})
@@ -3584,9 +3024,9 @@
3584 3024 var receiveQueries = (0, import_compose.compose)([
3585 3025 // Limit to matching action type so we don't attempt to replace action on
3586 3026 // an unhandled action.
3587 3027 if_matching_action_default((action) => "query" in action),
3588 - // Inject query parts into action for use both in `keyedReducer` and reducer.
3028 + // Inject query parts into action for use both in `onSubKey` and reducer.
3589 3029 replace_action_default((action) => {
3590 3030 if (action.query) {
3591 3031 return {
3592 3032 ...action,
@@ -3594,29 +3034,23 @@
3594 3034 };
3595 3035 }
3596 3036 return action;
3597 3037 }),
3598 - (0, import_data6.keyedReducer)("context"),
3038 + on_sub_key_default("context"),
3599 3039 // Queries shape is shared, but keyed by query `stableKey` part. Original
3600 3040 // reducer tracks only a single query object.
3601 - (0, import_data6.keyedReducer)("stableKey")
3041 + on_sub_key_default("stableKey")
3602 3042 ])((state = {}, action) => {
3603 - if (action.type !== "RECEIVE_ITEMS") {
3043 + const { type, page, perPage, key = DEFAULT_ENTITY_KEY } = action;
3044 + if (type !== "RECEIVE_ITEMS") {
3604 3045 return state;
3605 3046 }
3606 - if (!Array.isArray(action.items)) {
3607 - return state;
3608 - }
3609 - const key = action.key ?? DEFAULT_ENTITY_KEY;
3610 3047 return {
3611 3048 itemIds: getMergedItemIds(
3612 - state.itemIds,
3049 + state?.itemIds || [],
3613 3050 action.items.map((item) => item?.[key]).filter(Boolean),
3614 - {
3615 - page: action.page,
3616 - offset: action.offset,
3617 - perPage: action.perPage
3618 - }
3051 + page,
3052 + perPage
3619 3053 ),
3620 3054 meta: action.meta
3621 3055 };
3622 3056 });
@@ -3652,9 +3086,9 @@
3652 3086 default:
3653 3087 return state;
3654 3088 }
3655 3089 };
3656 - var reducer_default = (0, import_data6.combineReducers)({
3090 + var reducer_default = (0, import_data7.combineReducers)({
3657 3091 items,
3658 3092 itemIsComplete,
3659 3093 queries
3660 3094 });
@@ -3728,23 +3162,20 @@
3728 3162 if (action.type === "UNDO" || action.type === "REDO") {
3729 3163 const { record } = action;
3730 3164 let newState = state;
3731 3165 record.forEach(({ id: { kind, name, recordId }, changes }) => {
3732 - const persistedRecord = state?.queriedData?.items?.default?.[recordId];
3733 - const edits = Object.fromEntries(
3734 - Object.entries(changes).map(([key, value]) => [
3735 - key,
3736 - action.type === "UNDO" ? value.from : value.to
3737 - ])
3738 - );
3739 3166 newState = reducer(newState, {
3740 3167 type: "EDIT_ENTITY_RECORD",
3741 3168 kind,
3742 3169 name,
3743 3170 recordId,
3744 - // Clear edits matching the persisted record so the entity is
3745 - // no longer dirty after undoing back to its saved state.
3746 - edits: clearUnchangedEdits(edits, persistedRecord)
3171 + edits: Object.entries(changes).reduce(
3172 + (acc, [key, value]) => {
3173 + acc[key] = action.type === "UNDO" ? value.from : value.to;
3174 + return acc;
3175 + },
3176 + {}
3177 + )
3747 3178 });
3748 3179 });
3749 3180 return newState;
3750 3181 }
@@ -3765,9 +3196,9 @@
3765 3196 ...action
3766 3197 };
3767 3198 })
3768 3199 ])(
3769 - (0, import_data7.combineReducers)({
3200 + (0, import_data8.combineReducers)({
3770 3201 queriedData: reducer_default,
3771 3202 edits: (state = {}, action) => {
3772 3203 switch (action.type) {
3773 3204 case "RECEIVE_ITEMS":
@@ -3775,10 +3206,9 @@
3775 3206 if (context !== "default") {
3776 3207 return state;
3777 3208 }
3778 3209 const nextState = { ...state };
3779 - const itemsList = Array.isArray(action.items) ? action.items : [action.items];
3780 - for (const record of itemsList) {
3210 + for (const record of action.items) {
3781 3211 const recordId = record?.[action.key];
3782 3212 const edits = nextState[recordId];
3783 3213 if (!edits) {
3784 3214 continue;
@@ -3788,14 +3218,14 @@
3788 3218 if (
3789 3219 // Edits are the "raw" attribute values, but records may have
3790 3220 // objects with more properties, so we use `get` here for the
3791 3221 // comparison.
3792 - !(0, import_es65.default)(
3222 + !(0, import_es64.default)(
3793 3223 edits[key],
3794 3224 record[key]?.raw ?? record[key]
3795 3225 ) && // Sometimes the server alters the sent value which means
3796 3226 // we need to also remove the edits before the api request.
3797 - (!action.persistedEdits || !(0, import_es65.default)(
3227 + (!action.persistedEdits || !(0, import_es64.default)(
3798 3228 edits[key],
3799 3229 action.persistedEdits[key]
3800 3230 ))
3801 3231 ) {
@@ -3906,13 +3336,13 @@
3906 3336 }
3907 3337 acc[kind].push(record);
3908 3338 return acc;
3909 3339 }, {});
3910 - entitiesDataReducer = (0, import_data7.combineReducers)(
3340 + entitiesDataReducer = (0, import_data8.combineReducers)(
3911 3341 Object.fromEntries(
3912 3342 Object.entries(entitiesByKind).map(
3913 3343 ([kind, subEntities]) => {
3914 - const kindReducer = (0, import_data7.combineReducers)(
3344 + const kindReducer = (0, import_data8.combineReducers)(
3915 3345 Object.fromEntries(
3916 3346 subEntities.map((entityConfig) => [
3917 3347 entityConfig.name,
3918 3348 entity(entityConfig)
@@ -3937,18 +3367,8 @@
3937 3367 };
3938 3368 function undoManager(state = (0, import_undo_manager.createUndoManager)()) {
3939 3369 return state;
3940 3370 }
3941 - function syncUndoManagerState(state = { hasRedo: false, hasUndo: false }, action) {
3942 - switch (action.type) {
3943 - case "SYNC_UNDO_MANAGER_CHANGE":
3944 - return {
3945 - hasRedo: action.hasRedo,
3946 - hasUndo: action.hasUndo
3947 - };
3948 - }
3949 - return state;
3950 - }
3951 3371 function editsReference(state = {}, action) {
3952 3372 switch (action.type) {
3953 3373 case "EDIT_ENTITY_RECORD":
3954 3374 case "UNDO":
@@ -4086,32 +3506,12 @@
4086 3506 function collaborationSupported(state = true, action) {
4087 3507 switch (action.type) {
4088 3508 case "SET_COLLABORATION_SUPPORTED":
4089 3509 return action.supported;
4090 - case "SET_SYNC_CONNECTION_STATUS":
4091 - if (ConnectionErrorCode.DOCUMENT_SIZE_LIMIT_EXCEEDED === action.status?.error?.code) {
4092 - return false;
4093 - }
4094 - return state;
4095 3510 }
4096 3511 return state;
4097 3512 }
4098 - function viewConfigs(state = {}, action) {
4099 - switch (action.type) {
4100 - case "RECEIVE_VIEW_CONFIG": {
4101 - const key = `${action.kind}/${action.name}`;
4102 - return {
4103 - ...state,
4104 - [key]: {
4105 - ...state[key],
4106 - ...action.config
4107 - }
4108 - };
4109 - }
4110 - }
4111 - return state;
4112 - }
4113 - var reducer_default2 = (0, import_data7.combineReducers)({
3513 + var reducer_default2 = (0, import_data8.combineReducers)({
4114 3514 users,
4115 3515 currentTheme,
4116 3516 currentGlobalStylesId,
4117 3517 currentUser,
@@ -4119,9 +3519,8 @@
4119 3519 themeBaseGlobalStyles,
4120 3520 themeGlobalStyleRevisions,
4121 3521 entities,
4122 3522 editsReference,
4123 - syncUndoManagerState,
4124 3523 undoManager,
4125 3524 embedPreviews,
4126 3525 userPermissions,
4127 3526 autosaves,
@@ -4133,10 +3532,9 @@
4133 3532 registeredPostMeta,
4134 3533 editorSettings,
4135 3534 editorAssets,
4136 3535 syncConnectionStatuses,
4137 - collaborationSupported,
4138 - viewConfigs
3536 + collaborationSupported
4139 3537 });
4140 3538
4141 3539 // packages/core-data/build-module/selectors.mjs
4142 3540 var selectors_exports = {};
@@ -4176,8 +3574,9 @@
4176 3574 getRedoEdit: () => getRedoEdit,
4177 3575 getReferenceByDistinctEdits: () => getReferenceByDistinctEdits,
4178 3576 getRevision: () => getRevision,
4179 3577 getRevisions: () => getRevisions,
3578 + getSyncConnectionStatus: () => getSyncConnectionStatus,
4180 3579 getThemeSupports: () => getThemeSupports,
4181 3580 getUndoEdit: () => getUndoEdit,
4182 3581 getUserPatternCategories: () => getUserPatternCategories,
4183 3582 getUserQueryResults: () => getUserQueryResults,
@@ -4185,9 +3584,8 @@
4185 3584 hasEntityRecord: () => hasEntityRecord,
4186 3585 hasEntityRecords: () => hasEntityRecords,
4187 3586 hasFetchedAutosaves: () => hasFetchedAutosaves,
4188 3587 hasRedo: () => hasRedo,
4189 - hasRevision: () => hasRevision,
4190 3588 hasUndo: () => hasUndo,
4191 3589 isAutosavingEntityRecord: () => isAutosavingEntityRecord,
4192 3590 isDeletingEntityRecord: () => isDeletingEntityRecord,
4193 3591 isPreviewEmbedFallback: () => isPreviewEmbedFallback,
@@ -4193,9 +3591,9 @@
4193 3591 isPreviewEmbedFallback: () => isPreviewEmbedFallback,
4194 3592 isRequestingEmbedPreview: () => isRequestingEmbedPreview,
4195 3593 isSavingEntityRecord: () => isSavingEntityRecord
4196 3594 });
4197 - var import_data9 = __toESM(require_data(), 1);
3595 + var import_data10 = __toESM(require_data(), 1);
4198 3596 var import_url2 = __toESM(require_url(), 1);
4199 3597 var import_deprecated2 = __toESM(require_deprecated(), 1);
4200 3598
4201 3599 // packages/core-data/build-module/private-selectors.mjs
@@ -4209,15 +3607,13 @@
4209 3607 getHomePage: () => getHomePage,
4210 3608 getNavigationFallbackId: () => getNavigationFallbackId,
4211 3609 getPostsPageId: () => getPostsPageId,
4212 3610 getRegisteredPostMeta: () => getRegisteredPostMeta,
4213 - getSyncConnectionStatus: () => getSyncConnectionStatus,
4214 3611 getTemplateId: () => getTemplateId,
4215 3612 getUndoManager: () => getUndoManager,
4216 - getViewConfig: () => getViewConfig,
4217 3613 isCollaborationSupported: () => isCollaborationSupported
4218 3614 });
4219 - var import_data8 = __toESM(require_data(), 1);
3615 + var import_data9 = __toESM(require_data(), 1);
4220 3616
4221 3617 // packages/core-data/build-module/utils/log-entity-deprecation.mjs
4222 3618 var import_deprecated = __toESM(require_deprecated(), 1);
4223 3619 var loggedAlready = false;
@@ -4247,9 +3643,8 @@
4247 3643 }, 0);
4248 3644 }
4249 3645
4250 3646 // packages/core-data/build-module/private-selectors.mjs
4251 - var EMPTY_OBJECT = {};
4252 3647 function getUndoManager(state) {
4253 3648 return getSyncManager()?.undoManager ?? state.undoManager;
4254 3649 }
4255 3650 function getNavigationFallbackId(state) {
@@ -4254,27 +3649,27 @@
4254 3649 }
4255 3650 function getNavigationFallbackId(state) {
4256 3651 return state.navigationFallbackId;
4257 3652 }
4258 - var getBlockPatternsForPostType = (0, import_data8.createRegistrySelector)(
4259 - (select4) => (0, import_data8.createSelector)(
4260 - (state, postType) => select4(STORE_NAME).getBlockPatterns().filter(
3653 + var getBlockPatternsForPostType = (0, import_data9.createRegistrySelector)(
3654 + (select5) => (0, import_data9.createSelector)(
3655 + (state, postType) => select5(STORE_NAME).getBlockPatterns().filter(
4261 3656 ({ postTypes }) => !postTypes || Array.isArray(postTypes) && postTypes.includes(postType)
4262 3657 ),
4263 - () => [select4(STORE_NAME).getBlockPatterns()]
3658 + () => [select5(STORE_NAME).getBlockPatterns()]
4264 3659 )
4265 3660 );
4266 - var getEntityRecordsPermissions = (0, import_data8.createRegistrySelector)(
4267 - (select4) => (0, import_data8.createSelector)(
3661 + var getEntityRecordsPermissions = (0, import_data9.createRegistrySelector)(
3662 + (select5) => (0, import_data9.createSelector)(
4268 3663 (state, kind, name, ids) => {
4269 3664 const normalizedIds = Array.isArray(ids) ? ids : [ids];
4270 3665 return normalizedIds.map((id) => ({
4271 - delete: select4(STORE_NAME).canUser("delete", {
3666 + delete: select5(STORE_NAME).canUser("delete", {
4272 3667 kind,
4273 3668 name,
4274 3669 id
4275 3670 }),
4276 - update: select4(STORE_NAME).canUser("update", {
3671 + update: select5(STORE_NAME).canUser("update", {
4277 3672 kind,
4278 3673 name,
4279 3674 id
4280 3675 })
@@ -4298,12 +3693,12 @@
4298 3693 return null;
4299 3694 }
4300 3695 return value.toString();
4301 3696 }
4302 - var getHomePage = (0, import_data8.createRegistrySelector)(
4303 - (select4) => (0, import_data8.createSelector)(
3697 + var getHomePage = (0, import_data9.createRegistrySelector)(
3698 + (select5) => (0, import_data9.createSelector)(
4304 3699 () => {
4305 - const siteData = select4(STORE_NAME).getEntityRecord(
3700 + const siteData = select5(STORE_NAME).getEntityRecord(
4306 3701 "root",
4307 3702 "__unstableBase"
4308 3703 );
4309 3704 if (!siteData) {
@@ -4312,23 +3707,17 @@
4312 3707 const homepageId = siteData?.show_on_front === "page" ? normalizePageId(siteData.page_on_front) : null;
4313 3708 if (homepageId) {
4314 3709 return { postType: "page", postId: homepageId };
4315 3710 }
4316 - const frontPageTemplateId = select4(
3711 + const frontPageTemplateId = select5(
4317 3712 STORE_NAME
4318 3713 ).getDefaultTemplateId({
4319 3714 slug: "front-page"
4320 3715 });
4321 - if (frontPageTemplateId) {
4322 - return {
4323 - postType: "wp_template",
4324 - postId: frontPageTemplateId
4325 - };
3716 + if (!frontPageTemplateId) {
3717 + return null;
4326 3718 }
4327 - if (frontPageTemplateId === "") {
4328 - return EMPTY_OBJECT;
4329 - }
4330 - return null;
3719 + return { postType: "wp_template", postId: frontPageTemplateId };
4331 3720 },
4332 3721 (state) => [
4333 3722 // Even though getDefaultTemplateId.shouldInvalidate returns true when root/site changes,
4334 3723 // it doesn't seem to invalidate this cache, I'm not sure why.
@@ -4339,23 +3728,23 @@
4339 3728 })
4340 3729 ]
4341 3730 )
4342 3731 );
4343 - var getPostsPageId = (0, import_data8.createRegistrySelector)((select4) => () => {
4344 - const siteData = select4(STORE_NAME).getEntityRecord(
3732 + var getPostsPageId = (0, import_data9.createRegistrySelector)((select5) => () => {
3733 + const siteData = select5(STORE_NAME).getEntityRecord(
4345 3734 "root",
4346 3735 "__unstableBase"
4347 3736 );
4348 3737 return siteData?.show_on_front === "page" ? normalizePageId(siteData.page_for_posts) : null;
4349 3738 });
4350 - var getTemplateId = (0, import_data8.createRegistrySelector)(
4351 - (select4) => (state, postType, postId) => {
4352 - const homepage = unlock(select4(STORE_NAME)).getHomePage();
3739 + var getTemplateId = (0, import_data9.createRegistrySelector)(
3740 + (select5) => (state, postType, postId) => {
3741 + const homepage = unlock(select5(STORE_NAME)).getHomePage();
4353 3742 if (!homepage) {
4354 3743 return;
4355 3744 }
4356 3745 if (postType === "page" && postType === homepage?.postType && postId.toString() === homepage?.postId) {
4357 - const templates = select4(STORE_NAME).getEntityRecords(
3746 + const templates = select5(STORE_NAME).getEntityRecords(
4358 3747 "postType",
4359 3748 "wp_template",
4360 3749 {
4361 3750 per_page: -1
@@ -4368,9 +3757,9 @@
4368 3757 if (id) {
4369 3758 return id;
4370 3759 }
4371 3760 }
4372 - const editedEntity = select4(STORE_NAME).getEditedEntityRecord(
3761 + const editedEntity = select5(STORE_NAME).getEditedEntityRecord(
4373 3762 "postType",
4374 3763 postType,
4375 3764 postId
4376 3765 );
@@ -4376,17 +3765,17 @@
4376 3765 );
4377 3766 if (!editedEntity) {
4378 3767 return;
4379 3768 }
4380 - const postsPageId = unlock(select4(STORE_NAME)).getPostsPageId();
3769 + const postsPageId = unlock(select5(STORE_NAME)).getPostsPageId();
4381 3770 if (postType === "page" && postsPageId === postId.toString()) {
4382 - return select4(STORE_NAME).getDefaultTemplateId({
3771 + return select5(STORE_NAME).getDefaultTemplateId({
4383 3772 slug: "home"
4384 3773 });
4385 3774 }
4386 3775 const currentTemplateSlug = editedEntity.template;
4387 3776 if (currentTemplateSlug) {
4388 - const currentTemplate = select4(STORE_NAME).getEntityRecords("postType", "wp_template", {
3777 + const currentTemplate = select5(STORE_NAME).getEntityRecords("postType", "wp_template", {
4389 3778 per_page: -1
4390 3779 })?.find(({ slug }) => slug === currentTemplateSlug);
4391 3780 if (currentTemplate) {
4392 3781 return currentTemplate.id;
@@ -4397,9 +3786,9 @@
4397 3786 slugToCheck = postType === "page" ? `${postType}-${editedEntity.slug}` : `single-${postType}-${editedEntity.slug}`;
4398 3787 } else {
4399 3788 slugToCheck = postType === "page" ? "page" : `single-${postType}`;
4400 3789 }
4401 - return select4(STORE_NAME).getDefaultTemplateId({
3790 + return select5(STORE_NAME).getDefaultTemplateId({
4402 3791 slug: slugToCheck
4403 3792 });
4404 3793 }
4405 3794 );
@@ -4411,35 +3800,14 @@
4411 3800 }
4412 3801 function isCollaborationSupported(state) {
4413 3802 return state.collaborationSupported;
4414 3803 }
4415 - function getViewConfig(state, kind, name) {
4416 - return state.viewConfigs?.[`${kind}/${name}`] ?? {
4417 - default_view: void 0,
4418 - default_layouts: void 0,
4419 - view_list: void 0,
4420 - form: void 0
4421 - };
4422 - }
4423 - function getSyncConnectionStatus(state) {
4424 - if (!state.syncConnectionStatuses) {
4425 - return void 0;
4426 - }
4427 - const PRIORITIZED_STATUSES = ["disconnected", "connecting", "connected"];
4428 - let coalesced;
4429 - for (const status of Object.values(state.syncConnectionStatuses)) {
4430 - if (!coalesced || PRIORITIZED_STATUSES.indexOf(status.status) < PRIORITIZED_STATUSES.indexOf(coalesced.status)) {
4431 - coalesced = status;
4432 - }
4433 - }
4434 - return coalesced;
4435 - }
4436 3804
4437 3805 // packages/core-data/build-module/selectors.mjs
4438 - var EMPTY_OBJECT2 = {};
4439 - var isRequestingEmbedPreview = (0, import_data9.createRegistrySelector)(
4440 - (select4) => (state, url) => {
4441 - return select4(STORE_NAME).isResolving("getEmbedPreview", [
3806 + var EMPTY_OBJECT = {};
3807 + var isRequestingEmbedPreview = (0, import_data10.createRegistrySelector)(
3808 + (select5) => (state, url) => {
3809 + return select5(STORE_NAME).isResolving("getEmbedPreview", [
4442 3810 url
4443 3811 ]);
4444 3812 }
4445 3813 );
@@ -4456,9 +3824,9 @@
4456 3824 }
4457 3825 function getCurrentUser(state) {
4458 3826 return state.currentUser;
4459 3827 }
4460 - var getUserQueryResults = (0, import_data9.createSelector)(
3828 + var getUserQueryResults = (0, import_data10.createSelector)(
4461 3829 (state, queryID) => {
4462 3830 const queryResults = state.users.queries[queryID] ?? [];
4463 3831 return queryResults.map((id) => state.users.byId[id]);
4464 3832 },
@@ -4473,9 +3841,9 @@
4473 3841 alternative: "wp.data.select( 'core' ).getEntitiesConfig()"
4474 3842 });
4475 3843 return getEntitiesConfig(state, kind);
4476 3844 }
4477 - var getEntitiesConfig = (0, import_data9.createSelector)(
3845 + var getEntitiesConfig = (0, import_data10.createSelector)(
4478 3846 (state, kind) => state.entities.config.filter((entity2) => entity2.kind === kind),
4479 3847 /* eslint-disable @typescript-eslint/no-unused-vars */
4480 3848 (state, kind) => state.entities.config
4481 3849 /* eslint-enable @typescript-eslint/no-unused-vars */
@@ -4492,9 +3860,9 @@
4492 3860 return state.entities.config?.find(
4493 3861 (config) => config.kind === kind && config.name === name
4494 3862 );
4495 3863 }
4496 - var getEntityRecord = (0, import_data9.createSelector)(
3864 + var getEntityRecord = (0, import_data10.createSelector)(
4497 3865 ((state, kind, name, key, query) => {
4498 3866 logEntityDeprecation(kind, name, "getEntityRecord");
4499 3867 const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
4500 3868 if (!queriedState) {
@@ -4567,9 +3935,9 @@
4567 3935 }
4568 3936 function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
4569 3937 return getEntityRecord(state, kind, name, key);
4570 3938 }
4571 - var getRawEntityRecord = (0, import_data9.createSelector)(
3939 + var getRawEntityRecord = (0, import_data10.createSelector)(
4572 3940 (state, kind, name, key) => {
4573 3941 logEntityDeprecation(kind, name, "getRawEntityRecord");
4574 3942 const record = getEntityRecord(
4575 3943 state,
@@ -4576,24 +3944,16 @@
4576 3944 kind,
4577 3945 name,
4578 3946 key
4579 3947 );
4580 - const config = getEntityConfig(state, kind, name);
4581 - if (!record || !config?.rawAttributes?.length) {
4582 - return record;
4583 - }
4584 - return Object.fromEntries(
4585 - Object.keys(record).map((_key) => {
4586 - if (config.rawAttributes.includes(_key)) {
4587 - const rawValue = record[_key]?.raw;
4588 - return [
4589 - _key,
4590 - rawValue !== void 0 ? rawValue : record[_key]
4591 - ];
4592 - }
4593 - return [_key, record[_key]];
4594 - })
4595 - );
3948 + return record && Object.keys(record).reduce((accumulator, _key) => {
3949 + if (isRawAttribute(getEntityConfig(state, kind, name), _key)) {
3950 + accumulator[_key] = record[_key]?.raw !== void 0 ? record[_key]?.raw : record[_key];
3951 + } else {
3952 + accumulator[_key] = record[_key];
3953 + }
3954 + return accumulator;
3955 + }, {});
4596 3956 },
4597 3957 (state, kind, name, recordId, query) => {
4598 3958 const context = query?.context ?? "default";
4599 3959 return [
@@ -4612,11 +3972,9 @@
4612 3972 const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
4613 3973 if (!queriedState) {
4614 3974 return null;
4615 3975 }
4616 - return getQueriedItems(queriedState, query, {
4617 - supportsPagination: !!getEntityConfig(state, kind, name)?.supportsPagination
4618 - });
3976 + return getQueriedItems(queriedState, query);
4619 3977 });
4620 3978 var getEntityRecordsTotalItems = (state, kind, name, query) => {
4621 3979 logEntityDeprecation(kind, name, "getEntityRecordsTotalItems");
4622 3980 const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
@@ -4630,9 +3988,9 @@
4630 3988 const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
4631 3989 if (!queriedState) {
4632 3990 return null;
4633 3991 }
4634 - if (!getEntityConfig(state, kind, name)?.supportsPagination || query?.per_page === -1) {
3992 + if (query?.per_page === -1) {
4635 3993 return 1;
4636 3994 }
4637 3995 const totalItems = getQueriedTotalItems(queriedState, query);
4638 3996 if (!totalItems) {
@@ -4642,9 +4000,9 @@
4642 4000 return getQueriedTotalPages(queriedState, query);
4643 4001 }
4644 4002 return Math.ceil(totalItems / query.per_page);
4645 4003 };
4646 - var __experimentalGetDirtyEntityRecords = (0, import_data9.createSelector)(
4004 + var __experimentalGetDirtyEntityRecords = (0, import_data10.createSelector)(
4647 4005 (state) => {
4648 4006 const {
4649 4007 entities: { records }
4650 4008 } = state;
@@ -4682,9 +4040,9 @@
4682 4040 return dirtyRecords;
4683 4041 },
4684 4042 (state) => [state.entities.records]
4685 4043 );
4686 - var __experimentalGetEntitiesBeingSaved = (0, import_data9.createSelector)(
4044 + var __experimentalGetEntitiesBeingSaved = (0, import_data10.createSelector)(
4687 4045 (state) => {
4688 4046 const {
4689 4047 entities: { records }
4690 4048 } = state;
@@ -4722,9 +4080,9 @@
4722 4080 function getEntityRecordEdits(state, kind, name, recordId) {
4723 4081 logEntityDeprecation(kind, name, "getEntityRecordEdits");
4724 4082 return state.entities.records?.[kind]?.[name]?.edits?.[recordId];
4725 4083 }
4726 - var getEntityRecordNonTransientEdits = (0, import_data9.createSelector)(
4084 + var getEntityRecordNonTransientEdits = (0, import_data10.createSelector)(
4727 4085 (state, kind, name, recordId) => {
4728 4086 logEntityDeprecation(kind, name, "getEntityRecordNonTransientEdits");
4729 4087 const { transientEdits } = getEntityConfig(state, kind, name) || {};
4730 4088 const edits = getEntityRecordEdits(state, kind, name, recordId) || {};
@@ -4748,9 +4106,9 @@
4748 4106 return isSavingEntityRecord(state, kind, name, recordId) || Object.keys(
4749 4107 getEntityRecordNonTransientEdits(state, kind, name, recordId)
4750 4108 ).length > 0;
4751 4109 }
4752 - var getEditedEntityRecord = (0, import_data9.createSelector)(
4110 + var getEditedEntityRecord = (0, import_data10.createSelector)(
4753 4111 (state, kind, name, recordId) => {
4754 4112 logEntityDeprecation(kind, name, "getEditedEntityRecord");
4755 4113 const raw = getRawEntityRecord(state, kind, name, recordId);
4756 4114 const edited = getEntityRecordEdits(state, kind, name, recordId);
@@ -4805,17 +4163,11 @@
4805 4163 });
4806 4164 return void 0;
4807 4165 }
4808 4166 function hasUndo(state) {
4809 - if (getSyncManager()?.undoManager) {
4810 - return state.syncUndoManagerState.hasUndo;
4811 - }
4812 4167 return getUndoManager(state).hasUndo();
4813 4168 }
4814 4169 function hasRedo(state) {
4815 - if (getSyncManager()?.undoManager) {
4816 - return state.syncUndoManagerState.hasRedo;
4817 - }
4818 4170 return getUndoManager(state).hasRedo();
4819 4171 }
4820 4172 function getCurrentTheme(state) {
4821 4173 if (!state.currentTheme) {
@@ -4826,9 +4178,9 @@
4826 4178 function __experimentalGetCurrentGlobalStylesId(state) {
4827 4179 return state.currentGlobalStylesId;
4828 4180 }
4829 4181 function getThemeSupports(state) {
4830 - return getCurrentTheme(state)?.theme_supports ?? EMPTY_OBJECT2;
4182 + return getCurrentTheme(state)?.theme_supports ?? EMPTY_OBJECT;
4831 4183 }
4832 4184 function getEmbedPreview(state, url) {
4833 4185 return state.embedPreviews[url];
4834 4186 }
@@ -4869,11 +4221,11 @@
4869 4221 return autosaves2?.find(
4870 4222 (autosave) => autosave.author === authorId
4871 4223 );
4872 4224 }
4873 - var hasFetchedAutosaves = (0, import_data9.createRegistrySelector)(
4874 - (select4) => (state, postType, postId) => {
4875 - return select4(STORE_NAME).hasFinishedResolution("getAutosaves", [
4225 + var hasFetchedAutosaves = (0, import_data10.createRegistrySelector)(
4226 + (select5) => (state, postType, postId) => {
4227 + return select5(STORE_NAME).hasFinishedResolution("getAutosaves", [
4876 4228 postType,
4877 4229 postId
4878 4230 ]);
4879 4231 }
@@ -4925,36 +4277,9 @@
4925 4277 return null;
4926 4278 }
4927 4279 return getQueriedItems(queriedStateRevisions, query);
4928 4280 };
4929 - function hasRevision(state, kind, name, recordKey, revisionKey, query) {
4930 - const queriedState = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey];
4931 - if (!queriedState) {
4932 - return false;
4933 - }
4934 - const context = query?.context ?? "default";
4935 - if (!query || !query._fields) {
4936 - return !!queriedState.itemIsComplete[context]?.[revisionKey];
4937 - }
4938 - const item = queriedState.items[context]?.[revisionKey];
4939 - if (!item) {
4940 - return false;
4941 - }
4942 - const fields = get_normalized_comma_separable_default(query._fields) ?? [];
4943 - for (let i = 0; i < fields.length; i++) {
4944 - const path = fields[i].split(".");
4945 - let value = item;
4946 - for (let p = 0; p < path.length; p++) {
4947 - const part = path[p];
4948 - if (!value || !Object.hasOwn(value, part)) {
4949 - return false;
4950 - }
4951 - value = value[part];
4952 - }
4953 - }
4954 - return true;
4955 - }
4956 - var getRevision = (0, import_data9.createSelector)(
4281 + var getRevision = (0, import_data10.createSelector)(
4957 4282 (state, kind, name, recordKey, revisionKey, query) => {
4958 4283 logEntityDeprecation(kind, name, "getRevision");
4959 4284 const queriedState = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey];
4960 4285 if (!queriedState) {
@@ -4991,8 +4316,21 @@
4991 4316 queriedState?.itemIsComplete?.[context]?.[revisionKey]
4992 4317 ];
4993 4318 }
4994 4319 );
4320 + function getSyncConnectionStatus(state) {
4321 + if (!state.syncConnectionStatuses) {
4322 + return void 0;
4323 + }
4324 + const PRIORITIZED_STATUSES = ["disconnected", "connecting", "connected"];
4325 + let coalesced;
4326 + for (const status of Object.values(state.syncConnectionStatuses)) {
4327 + if (!coalesced || PRIORITIZED_STATUSES.indexOf(status.status) < PRIORITIZED_STATUSES.indexOf(coalesced.status)) {
4328 + coalesced = status;
4329 + }
4330 + }
4331 + return coalesced;
4332 + }
4995 4333
4996 4334 // packages/core-data/build-module/actions.mjs
4997 4335 var actions_exports = {};
4998 4336 __export(actions_exports, {
@@ -5022,16 +4360,18 @@
5022 4360 receiveUserQuery: () => receiveUserQuery,
5023 4361 redo: () => redo,
5024 4362 saveEditedEntityRecord: () => saveEditedEntityRecord,
5025 4363 saveEntityRecord: () => saveEntityRecord,
4364 + setSyncConnectionStatus: () => setSyncConnectionStatus,
5026 4365 undo: () => undo
5027 4366 });
5028 - var import_api_fetch4 = __toESM(require_api_fetch(), 1);
4367 + var import_es65 = __toESM(require_es6(), 1);
4368 + var import_api_fetch3 = __toESM(require_api_fetch(), 1);
5029 4369 var import_url3 = __toESM(require_url(), 1);
5030 4370 var import_deprecated3 = __toESM(require_deprecated(), 1);
5031 4371
5032 4372 // packages/core-data/build-module/batch/default-processor.mjs
5033 - var import_api_fetch3 = __toESM(require_api_fetch(), 1);
4373 + var import_api_fetch2 = __toESM(require_api_fetch(), 1);
5034 4374 var maxItems = null;
5035 4375 function chunk(arr, chunkSize) {
5036 4376 const tmp = [...arr];
5037 4377 const cache3 = [];
@@ -5041,9 +4381,9 @@
5041 4381 return cache3;
5042 4382 }
5043 4383 async function defaultProcessor(requests) {
5044 4384 if (maxItems === null) {
5045 - const preflightResponse = await (0, import_api_fetch3.default)({
4385 + const preflightResponse = await (0, import_api_fetch2.default)({
5046 4386 path: "/batch/v1",
5047 4387 method: "OPTIONS"
5048 4388 });
5049 4389 maxItems = preflightResponse.endpoints[0].args.requests.maxItems;
@@ -5049,9 +4389,9 @@
5049 4389 maxItems = preflightResponse.endpoints[0].args.requests.maxItems;
5050 4390 }
5051 4391 const results = [];
5052 4392 for (const batchRequests of chunk(requests, maxItems)) {
5053 - const batchResponse = await (0, import_api_fetch3.default)({
4393 + const batchResponse = await (0, import_api_fetch2.default)({
5054 4394 path: "/batch/v1",
5055 4395 method: "POST",
5056 4396 data: {
5057 4397 validation: "require-all-validate",
@@ -5210,11 +4550,8 @@
5210 4550 }
5211 4551 };
5212 4552
5213 4553 // packages/core-data/build-module/actions.mjs
5214 - function addTitleToAutoDraft(record) {
5215 - return record.status === "auto-draft" ? { ...record, title: "" } : record;
5216 - }
5217 4554 function receiveUserQuery(queryID, users2) {
5218 4555 return {
5219 4556 type: "RECEIVE_USER_QUERY",
5220 4557 users: Array.isArray(users2) ? users2 : [users2],
@@ -5234,9 +4571,11 @@
5234 4571 };
5235 4572 }
5236 4573 function receiveEntityRecords(kind, name, records, query = void 0, invalidateCache = false, edits = void 0, meta = void 0) {
5237 4574 if (kind === "postType") {
5238 - records = Array.isArray(records) ? records.map(addTitleToAutoDraft) : addTitleToAutoDraft(records);
4575 + records = (Array.isArray(records) ? records : [records]).map(
4576 + (record) => record.status === "auto-draft" ? { ...record, title: "" } : record
4577 + );
5239 4578 }
5240 4579 let action;
5241 4580 if (query) {
5242 4581 action = receiveQueriedItems(records, query, edits, meta);
@@ -5304,9 +4643,9 @@
5304 4643 url,
5305 4644 preview
5306 4645 };
5307 4646 }
5308 - var deleteEntityRecord = (kind, name, recordId, query, { __unstableFetch = import_api_fetch4.default, throwOnError = false } = {}) => async ({ dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
4647 + var deleteEntityRecord = (kind, name, recordId, query, { __unstableFetch = import_api_fetch3.default, throwOnError = false } = {}) => async ({ dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
5309 4648 logEntityDeprecation(kind, name, "deleteEntityRecord");
5310 4649 const configs = await resolveSelect2.getEntitiesConfig(kind);
5311 4650 const entityConfig = configs.find(
5312 4651 (config) => config.kind === kind && config.name === name
@@ -5366,11 +4705,11 @@
5366 4705 } finally {
5367 4706 dispatch3.__unstableReleaseStoreLock(lock2);
5368 4707 }
5369 4708 };
5370 - var editEntityRecord = (kind, name, recordId, edits, options = {}) => ({ select: select4, dispatch: dispatch3 }) => {
4709 + var editEntityRecord = (kind, name, recordId, edits, options = {}) => ({ select: select5, dispatch: dispatch3 }) => {
5371 4710 logEntityDeprecation(kind, name, "editEntityRecord");
5372 - const entityConfig = select4.getEntityConfig(kind, name);
4711 + const entityConfig = select5.getEntityConfig(kind, name);
5373 4712 if (!entityConfig) {
5374 4713 throw new Error(
5375 4714 `The entity being edited (${kind}, ${name}) does not have a loaded config.`
5376 4715 );
@@ -5375,10 +4714,10 @@
5375 4714 `The entity being edited (${kind}, ${name}) does not have a loaded config.`
5376 4715 );
5377 4716 }
5378 4717 const { mergedEdits = {} } = entityConfig;
5379 - const record = select4.getRawEntityRecord(kind, name, recordId);
5380 - const editedRecord = select4.getEditedEntityRecord(
4718 + const record = select5.getRawEntityRecord(kind, name, recordId);
4719 + const editedRecord = select5.getEditedEntityRecord(
5381 4720 kind,
5382 4721 name,
5383 4722 recordId
5384 4723 );
@@ -5391,25 +4730,29 @@
5391 4730 name,
5392 4731 recordId,
5393 4732 // Clear edits when they are equal to their persisted counterparts
5394 4733 // so that the property is not considered dirty.
5395 - edits: clearUnchangedEdits(editsWithMerges, record)
4734 + edits: Object.keys(edits).reduce((acc, key) => {
4735 + const recordValue = record[key];
4736 + const value = editsWithMerges[key];
4737 + acc[key] = (0, import_es65.default)(recordValue, value) ? void 0 : value;
4738 + return acc;
4739 + }, {})
5396 4740 };
5397 4741 if (entityConfig.syncConfig) {
5398 4742 const objectType = `${kind}/${name}`;
5399 4743 const objectId = recordId;
5400 4744 const isNewUndoLevel = options.undoIgnore ? false : !options.isCached;
5401 - const origin = options.undoIgnore ? LOCAL_UNDO_IGNORED_ORIGIN : LOCAL_EDITOR_ORIGIN;
5402 4745 getSyncManager()?.update(
5403 4746 objectType,
5404 4747 objectId,
5405 4748 editsWithMerges,
5406 - origin,
4749 + LOCAL_EDITOR_ORIGIN,
5407 4750 { isNewUndoLevel }
5408 4751 );
5409 4752 }
5410 4753 if (!options.undoIgnore) {
5411 - select4.getUndoManager().addRecord(
4754 + select5.getUndoManager().addRecord(
5412 4755 [
5413 4756 {
5414 4757 id: { kind, name, recordId },
5415 4758 changes: Object.keys(edits).reduce((acc, key) => {
@@ -5428,10 +4771,10 @@
5428 4771 type: "EDIT_ENTITY_RECORD",
5429 4772 ...edit
5430 4773 });
5431 4774 };
5432 - var clearEntityRecordEdits = (kind, name, recordId) => ({ select: select4, dispatch: dispatch3 }) => {
5433 - const entityConfig = select4.getEntityConfig(kind, name);
4775 + var clearEntityRecordEdits = (kind, name, recordId) => ({ select: select5, dispatch: dispatch3 }) => {
4776 + const entityConfig = select5.getEntityConfig(kind, name);
5434 4777 logEntityDeprecation(kind, name, "clearEntityRecordEdits");
5435 4778 if (!entityConfig) {
5436 4779 throw new Error(
5437 4780 `The entity being edited (${kind}, ${name}) does not have a loaded config.`
@@ -5436,9 +4779,9 @@
5436 4779 throw new Error(
5437 4780 `The entity being edited (${kind}, ${name}) does not have a loaded config.`
5438 4781 );
5439 4782 }
5440 - const currentEdits = select4.getEntityRecordEdits(
4783 + const currentEdits = select5.getEntityRecordEdits(
5441 4784 kind,
5442 4785 name,
5443 4786 recordId
5444 4787 );
@@ -5459,10 +4802,10 @@
5459 4802 recordId,
5460 4803 edits: clearedEdits
5461 4804 });
5462 4805 };
5463 - var undo = () => ({ select: select4, dispatch: dispatch3 }) => {
5464 - const undoRecord = select4.getUndoManager().undo();
4806 + var undo = () => ({ select: select5, dispatch: dispatch3 }) => {
4807 + const undoRecord = select5.getUndoManager().undo();
5465 4808 if (!undoRecord) {
5466 4809 return;
5467 4810 }
5468 4811 dispatch3({
@@ -5469,10 +4812,10 @@
5469 4812 type: "UNDO",
5470 4813 record: undoRecord
5471 4814 });
5472 4815 };
5473 - var redo = () => ({ select: select4, dispatch: dispatch3 }) => {
5474 - const redoRecord = select4.getUndoManager().redo();
4816 + var redo = () => ({ select: select5, dispatch: dispatch3 }) => {
4817 + const redoRecord = select5.getUndoManager().redo();
5475 4818 if (!redoRecord) {
5476 4819 return;
5477 4820 }
5478 4821 dispatch3({
@@ -5479,18 +4822,16 @@
5479 4822 type: "REDO",
5480 4823 record: redoRecord
5481 4824 });
5482 4825 };
5483 - var __unstableCreateUndoLevel = () => ({ select: select4 }) => {
5484 - select4.getUndoManager().addRecord();
4826 + var __unstableCreateUndoLevel = () => ({ select: select5 }) => {
4827 + select5.getUndoManager().addRecord();
5485 4828 };
5486 - var saveEntityRecord = (kind, name, record, options = {}) => async ({ select: select4, resolveSelect: resolveSelect2, dispatch: dispatch3 }) => {
5487 - const {
5488 - isAutosave = false,
5489 - __unstableFetch = import_api_fetch4.default,
5490 - __unstableSkipSyncUpdate = false,
5491 - throwOnError = false
5492 - } = options;
4829 + var saveEntityRecord = (kind, name, record, {
4830 + isAutosave = false,
4831 + __unstableFetch = import_api_fetch3.default,
4832 + throwOnError = false
4833 + } = {}) => async ({ select: select5, resolveSelect: resolveSelect2, dispatch: dispatch3 }) => {
5493 4834 logEntityDeprecation(kind, name, "saveEntityRecord");
5494 4835 const configs = await resolveSelect2.getEntitiesConfig(kind);
5495 4836 const entityConfig = configs.find(
5496 4837 (config) => config.kind === kind && config.name === name
@@ -5509,9 +4850,9 @@
5509 4850 try {
5510 4851 for (const [key, value] of Object.entries(record)) {
5511 4852 if (typeof value === "function") {
5512 4853 const evaluatedValue = value(
5513 - select4.getEditedEntityRecord(kind, name, recordId)
4854 + select5.getEditedEntityRecord(kind, name, recordId)
5514 4855 );
5515 4856 dispatch3.editEntityRecord(
5516 4857 kind,
5517 4858 name,
@@ -5539,20 +4880,31 @@
5539 4880 baseURL = baseURL.slice(0, baseURL.lastIndexOf("/")) + "/templates";
5540 4881 }
5541 4882 try {
5542 4883 const path = `${baseURL}${recordId ? "/" + recordId : ""}`;
5543 - const persistedRecord = !isNewRecord ? select4.getRawEntityRecord(kind, name, recordId) : {};
4884 + const persistedRecord = !isNewRecord ? select5.getRawEntityRecord(kind, name, recordId) : {};
5544 4885 if (isAutosave) {
5545 - const merged = { ...persistedRecord, ...record };
5546 - const data = [
5547 - "title",
5548 - "excerpt",
5549 - "content",
5550 - "meta"
5551 - ].reduce(
4886 + const currentUser2 = select5.getCurrentUser();
4887 + const currentUserId = currentUser2 ? currentUser2.id : void 0;
4888 + const autosavePost = await resolveSelect2.getAutosave(
4889 + persistedRecord.type,
4890 + persistedRecord.id,
4891 + currentUserId
4892 + );
4893 + let data = {
4894 + ...persistedRecord,
4895 + ...autosavePost,
4896 + ...record
4897 + };
4898 + data = Object.keys(data).reduce(
5552 4899 (acc, key) => {
5553 - if (key in merged) {
5554 - acc[key] = merged[key];
4900 + if ([
4901 + "title",
4902 + "excerpt",
4903 + "content",
4904 + "meta"
4905 + ].includes(key)) {
4906 + acc[key] = data[key];
5555 4907 }
5556 4908 return acc;
5557 4909 },
5558 4910 {
@@ -5559,9 +4911,9 @@
5559 4911 // Do not update the `status` if we have edited it when auto saving.
5560 4912 // It's very important to let the user explicitly save this change,
5561 4913 // because it can lead to unexpected results. An example would be to
5562 4914 // have a draft post and change the status to publish.
5563 - status: merged.status === "auto-draft" ? "draft" : void 0
4915 + status: data.status === "auto-draft" ? "draft" : void 0
5564 4916 }
5565 4917 );
5566 4918 updatedRecord = await __unstableFetch({
5567 4919 path: `${path}/autosaves`,
@@ -5575,14 +4927,11 @@
5575 4927 ...updatedRecord
5576 4928 };
5577 4929 newRecord = Object.keys(newRecord).reduce(
5578 4930 (acc, key) => {
5579 - if ([
5580 - "title",
5581 - "excerpt",
5582 - "content",
5583 - "meta"
5584 - ].includes(key)) {
4931 + if (["title", "excerpt", "content"].includes(
4932 + key
4933 + )) {
5585 4934 acc[key] = newRecord[key];
5586 4935 } else if (key === "status") {
5587 4936 acc[key] = persistedRecord.status === "auto-draft" && newRecord.status === "draft" ? newRecord.status : persistedRecord.status;
5588 4937 } else {
@@ -5632,10 +4981,10 @@
5632 4981 if (entityConfig.syncConfig) {
5633 4982 getSyncManager()?.update(
5634 4983 `${kind}/${name}`,
5635 4984 recordId,
5636 - __unstableSkipSyncUpdate ? {} : updatedRecord,
5637 - LOCAL_UNDO_IGNORED_ORIGIN,
4985 + updatedRecord,
4986 + LOCAL_EDITOR_ORIGIN,
5638 4987 { isSave: true }
5639 4988 );
5640 4989 }
5641 4990 }
@@ -5693,11 +5042,11 @@
5693 5042 ...resultPromises
5694 5043 ]);
5695 5044 return results;
5696 5045 };
5697 - var saveEditedEntityRecord = (kind, name, recordId, options) => async ({ select: select4, dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
5046 + var saveEditedEntityRecord = (kind, name, recordId, options) => async ({ select: select5, dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
5698 5047 logEntityDeprecation(kind, name, "saveEditedEntityRecord");
5699 - if (!select4.hasEditsForEntityRecord(kind, name, recordId)) {
5048 + if (!select5.hasEditsForEntityRecord(kind, name, recordId)) {
5700 5049 return;
5701 5050 }
5702 5051 const configs = await resolveSelect2.getEntitiesConfig(kind);
5703 5052 const entityConfig = configs.find(
@@ -5706,9 +5055,9 @@
5706 5055 if (!entityConfig) {
5707 5056 return;
5708 5057 }
5709 5058 const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
5710 - const edits = select4.getEntityRecordNonTransientEdits(
5059 + const edits = select5.getEntityRecordNonTransientEdits(
5711 5060 kind,
5712 5061 name,
5713 5062 recordId
5714 5063 );
@@ -5714,18 +5063,18 @@
5714 5063 );
5715 5064 const record = { [entityIdKey]: recordId, ...edits };
5716 5065 return await dispatch3.saveEntityRecord(kind, name, record, options);
5717 5066 };
5718 - var __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, itemsToSave, options) => async ({ select: select4, dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
5067 + var __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, itemsToSave, options) => async ({ select: select5, dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
5719 5068 logEntityDeprecation(
5720 5069 kind,
5721 5070 name,
5722 5071 "__experimentalSaveSpecifiedEntityEdits"
5723 5072 );
5724 - if (!select4.hasEditsForEntityRecord(kind, name, recordId)) {
5073 + if (!select5.hasEditsForEntityRecord(kind, name, recordId)) {
5725 5074 return;
5726 5075 }
5727 - const edits = select4.getEntityRecordNonTransientEdits(
5076 + const edits = select5.getEntityRecordNonTransientEdits(
5728 5077 kind,
5729 5078 name,
5730 5079 recordId
5731 5080 );
@@ -5793,13 +5142,13 @@
5793 5142 const configs = await resolveSelect2.getEntitiesConfig(kind);
5794 5143 const entityConfig = configs.find(
5795 5144 (config) => config.kind === kind && config.name === name
5796 5145 );
5797 - const key = entityConfig?.revisionKey ?? DEFAULT_ENTITY_KEY;
5146 + const key = entityConfig && entityConfig?.revisionKey ? entityConfig.revisionKey : DEFAULT_ENTITY_KEY;
5798 5147 dispatch3({
5799 5148 type: "RECEIVE_ITEM_REVISIONS",
5800 5149 key,
5801 - items: records,
5150 + items: Array.isArray(records) ? records : [records],
5802 5151 recordKey,
5803 5152 meta,
5804 5153 query,
5805 5154 kind,
@@ -5806,22 +5155,36 @@
5806 5155 name,
5807 5156 invalidateCache
5808 5157 });
5809 5158 };
5159 + function setSyncConnectionStatus(kind, name, key, status) {
5160 + if (!status) {
5161 + return {
5162 + type: "CLEAR_SYNC_CONNECTION_STATUS",
5163 + kind,
5164 + name,
5165 + key
5166 + };
5167 + }
5168 + return {
5169 + type: "SET_SYNC_CONNECTION_STATUS",
5170 + kind,
5171 + name,
5172 + key,
5173 + status
5174 + };
5175 + }
5810 5176
5811 5177 // packages/core-data/build-module/private-actions.mjs
5812 5178 var private_actions_exports = {};
5813 5179 __export(private_actions_exports, {
5814 - __unstableNotifySyncUndoManagerChange: () => __unstableNotifySyncUndoManagerChange,
5815 5180 editMediaEntity: () => editMediaEntity,
5816 5181 receiveEditorAssets: () => receiveEditorAssets,
5817 5182 receiveEditorSettings: () => receiveEditorSettings,
5818 5183 receiveRegisteredPostMeta: () => receiveRegisteredPostMeta,
5819 - receiveViewConfig: () => receiveViewConfig,
5820 - setCollaborationSupported: () => setCollaborationSupported,
5821 - setSyncConnectionStatus: () => setSyncConnectionStatus
5184 + setCollaborationSupported: () => setCollaborationSupported
5822 5185 });
5823 - var import_api_fetch5 = __toESM(require_api_fetch(), 1);
5186 + var import_api_fetch4 = __toESM(require_api_fetch(), 1);
5824 5187 function receiveRegisteredPostMeta(postType, registeredPostMeta2) {
5825 5188 return {
5826 5189 type: "RECEIVE_REGISTERED_POST_META",
5827 5190 postType,
@@ -5827,9 +5190,9 @@
5827 5190 postType,
5828 5191 registeredPostMeta: registeredPostMeta2
5829 5192 };
5830 5193 }
5831 - var editMediaEntity = (recordId, edits = {}, { __unstableFetch = import_api_fetch5.default, throwOnError = false } = {}) => async ({ dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
5194 + var editMediaEntity = (recordId, edits = {}, { __unstableFetch = import_api_fetch4.default, throwOnError = false } = {}) => async ({ dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
5832 5195 if (!recordId) {
5833 5196 return;
5834 5197 }
5835 5198 const kind = "postType";
@@ -5868,9 +5231,9 @@
5868 5231 if (newRecord) {
5869 5232 dispatch3.receiveEntityRecords(
5870 5233 kind,
5871 5234 name,
5872 - newRecord,
5235 + [newRecord],
5873 5236 void 0,
5874 5237 true,
5875 5238 void 0,
5876 5239 void 0
@@ -5909,43 +5272,9 @@
5909 5272 };
5910 5273 }
5911 5274 var setCollaborationSupported = (supported) => ({ dispatch: dispatch3 }) => {
5912 5275 dispatch3({ type: "SET_COLLABORATION_SUPPORTED", supported });
5913 - if (!supported && hasSyncManager()) {
5914 - getSyncManager().unloadAll();
5915 - }
5916 5276 };
5917 - function receiveViewConfig(kind, name, config) {
5918 - return {
5919 - type: "RECEIVE_VIEW_CONFIG",
5920 - kind,
5921 - name,
5922 - config
5923 - };
5924 - }
5925 - function __unstableNotifySyncUndoManagerChange(state) {
5926 - return {
5927 - type: "SYNC_UNDO_MANAGER_CHANGE",
5928 - ...state
5929 - };
5930 - }
5931 - function setSyncConnectionStatus(kind, name, key, status) {
5932 - if (!status) {
5933 - return {
5934 - type: "CLEAR_SYNC_CONNECTION_STATUS",
5935 - kind,
5936 - name,
5937 - key
5938 - };
5939 - }
5940 - return {
5941 - type: "SET_SYNC_CONNECTION_STATUS",
5942 - kind,
5943 - name,
5944 - key,
5945 - status
5946 - };
5947 - }
5948 5277
5949 5278 // packages/core-data/build-module/resolvers.mjs
5950 5279 var resolvers_exports = {};
5951 5280 __export(resolvers_exports, {
@@ -5977,20 +5306,19 @@
5977 5306 getRegisteredPostMeta: () => getRegisteredPostMeta2,
5978 5307 getRevision: () => getRevision2,
5979 5308 getRevisions: () => getRevisions2,
5980 5309 getThemeSupports: () => getThemeSupports2,
5981 - getUserPatternCategories: () => getUserPatternCategories2,
5982 - getViewConfig: () => getViewConfig2
5310 + getUserPatternCategories: () => getUserPatternCategories2
5983 5311 });
5984 5312 var import_url6 = __toESM(require_url(), 1);
5985 5313 var import_html_entities2 = __toESM(require_html_entities(), 1);
5986 - var import_api_fetch9 = __toESM(require_api_fetch(), 1);
5314 + var import_api_fetch8 = __toESM(require_api_fetch(), 1);
5987 5315
5988 5316 // packages/core-data/build-module/fetch/index.mjs
5989 - var import_api_fetch8 = __toESM(require_api_fetch(), 1);
5317 + var import_api_fetch7 = __toESM(require_api_fetch(), 1);
5990 5318
5991 5319 // packages/core-data/build-module/fetch/__experimental-fetch-link-suggestions.mjs
5992 - var import_api_fetch6 = __toESM(require_api_fetch(), 1);
5320 + var import_api_fetch5 = __toESM(require_api_fetch(), 1);
5993 5321 var import_url4 = __toESM(require_url(), 1);
5994 5322 var import_html_entities = __toESM(require_html_entities(), 1);
5995 5323 var import_i18n2 = __toESM(require_i18n(), 1);
5996 5324 async function fetchLinkSuggestions(search, searchOptions = {}, editorSettings2 = {}) {
@@ -6007,9 +5335,9 @@
6007 5335 const { disablePostFormats = false } = editorSettings2;
6008 5336 const queries2 = [];
6009 5337 if (!type || type === "post") {
6010 5338 queries2.push(
6011 - (0, import_api_fetch6.default)({
5339 + (0, import_api_fetch5.default)({
6012 5340 path: (0, import_url4.addQueryArgs)("/wp/v2/search", {
6013 5341 search,
6014 5342 page,
6015 5343 per_page: perPage,
@@ -6031,9 +5359,9 @@
6031 5359 );
6032 5360 }
6033 5361 if (!type || type === "term") {
6034 5362 queries2.push(
6035 - (0, import_api_fetch6.default)({
5363 + (0, import_api_fetch5.default)({
6036 5364 path: (0, import_url4.addQueryArgs)("/wp/v2/search", {
6037 5365 search,
6038 5366 page,
6039 5367 per_page: perPage,
@@ -6055,9 +5383,9 @@
6055 5383 );
6056 5384 }
6057 5385 if (!disablePostFormats && (!type || type === "post-format")) {
6058 5386 queries2.push(
6059 - (0, import_api_fetch6.default)({
5387 + (0, import_api_fetch5.default)({
6060 5388 path: (0, import_url4.addQueryArgs)("/wp/v2/search", {
6061 5389 search,
6062 5390 page,
6063 5391 per_page: perPage,
@@ -6079,9 +5407,9 @@
6079 5407 );
6080 5408 }
6081 5409 if (!type || type === "attachment") {
6082 5410 queries2.push(
6083 - (0, import_api_fetch6.default)({
5411 + (0, import_api_fetch5.default)({
6084 5412 path: (0, import_url4.addQueryArgs)("/wp/v2/media", {
6085 5413 search,
6086 5414 page,
6087 5415 per_page: perPage
@@ -6136,9 +5464,9 @@
6136 5464 return text.toLowerCase().match(/[\p{L}\p{N}]+/gu) || [];
6137 5465 }
6138 5466
6139 5467 // packages/core-data/build-module/fetch/__experimental-fetch-url-data.mjs
6140 - var import_api_fetch7 = __toESM(require_api_fetch(), 1);
5468 + var import_api_fetch6 = __toESM(require_api_fetch(), 1);
6141 5469 var import_url5 = __toESM(require_url(), 1);
6142 5470 var CACHE = /* @__PURE__ */ new Map();
6143 5471 var fetchUrlData = async (url, options = {}) => {
6144 5472 const endpoint = "/wp-block-editor/v1/url-details";
@@ -6156,9 +5484,9 @@
6156 5484 }
6157 5485 if (CACHE.has(url)) {
6158 5486 return CACHE.get(url);
6159 5487 }
6160 - return (0, import_api_fetch7.default)({
5488 + return (0, import_api_fetch6.default)({
6161 5489 path: (0, import_url5.addQueryArgs)(endpoint, args),
6162 5490 ...options
6163 5491 }).then((res) => {
6164 5492 CACHE.set(url, res);
@@ -6168,9 +5496,9 @@
6168 5496 var experimental_fetch_url_data_default = fetchUrlData;
6169 5497
6170 5498 // packages/core-data/build-module/fetch/index.mjs
6171 5499 async function fetchBlockPatterns() {
6172 - const restPatterns = await (0, import_api_fetch8.default)({
5500 + const restPatterns = await (0, import_api_fetch7.default)({
6173 5501 path: "/wp/v2/block-patterns/patterns"
6174 5502 });
6175 5503 if (!restPatterns) {
6176 5504 return [];
@@ -6184,14 +5512,8 @@
6184 5512 )
6185 5513 );
6186 5514 }
6187 5515
6188 - // packages/core-data/build-module/parsed-blocks-cache.mjs
6189 - var parsedBlocksCache = /* @__PURE__ */ new Map();
6190 - function getCacheKey(kind, name, id) {
6191 - return `${kind}:${name}:${id}`;
6192 - }
6193 -
6194 5516 // packages/core-data/build-module/resolvers.mjs
6195 5517 var getAuthors2 = (query) => async ({ dispatch: dispatch3 }) => {
6196 5518 const path = (0, import_url6.addQueryArgs)(
6197 5519 "/wp/v2/users/?who=authors&per_page=100",
@@ -6196,16 +5518,16 @@
6196 5518 const path = (0, import_url6.addQueryArgs)(
6197 5519 "/wp/v2/users/?who=authors&per_page=100",
6198 5520 query
6199 5521 );
6200 - const users2 = await (0, import_api_fetch9.default)({ path });
5522 + const users2 = await (0, import_api_fetch8.default)({ path });
6201 5523 dispatch3.receiveUserQuery(path, users2);
6202 5524 };
6203 5525 var getCurrentUser2 = () => async ({ dispatch: dispatch3 }) => {
6204 - const currentUser2 = await (0, import_api_fetch9.default)({ path: "/wp/v2/users/me" });
5526 + const currentUser2 = await (0, import_api_fetch8.default)({ path: "/wp/v2/users/me" });
6205 5527 dispatch3.receiveCurrentUser(currentUser2);
6206 5528 };
6207 - var getEntityRecord2 = (kind, name, key = "", query) => async ({ select: select4, dispatch: dispatch3, registry, resolveSelect: resolveSelect2 }) => {
5529 + var getEntityRecord2 = (kind, name, key = "", query) => async ({ select: select5, dispatch: dispatch3, registry, resolveSelect: resolveSelect2 }) => {
6208 5530 const configs = await resolveSelect2.getEntitiesConfig(kind);
6209 5531 const entityConfig = configs.find(
6210 5532 (config) => config.name === name && config.kind === kind
6211 5533 );
@@ -6229,9 +5551,9 @@
6229 5551 ].join()
6230 5552 };
6231 5553 }
6232 5554 if (query !== void 0 && query._fields) {
6233 - const hasRecord = select4.hasEntityRecord(
5555 + const hasRecord = select5.hasEntityRecord(
6234 5556 kind,
6235 5557 name,
6236 5558 key,
6237 5559 query
@@ -6247,9 +5569,9 @@
6247 5569 const path = (0, import_url6.addQueryArgs)(baseURL + (key ? "/" + key : ""), {
6248 5570 ...entityConfig.baseURLParams,
6249 5571 ...query
6250 5572 });
6251 - const response = await (0, import_api_fetch9.default)({ path, parse: false });
5573 + const response = await (0, import_api_fetch8.default)({ path, parse: false });
6252 5574 const record = await response.json();
6253 5575 const permissions = getUserPermissionsFromAllowHeader(
6254 5576 response.headers?.get("allow")
6255 5577 );
@@ -6274,14 +5596,8 @@
6274 5596 ([propName, transientConfig]) => void 0 === recordWithTransients[propName] && transientConfig && "object" === typeof transientConfig && "read" in transientConfig && "function" === typeof transientConfig.read
6275 5597 ).forEach(([propName, transientConfig]) => {
6276 5598 recordWithTransients[propName] = transientConfig.read(recordWithTransients);
6277 5599 });
6278 - if (recordWithTransients.blocks && typeof recordWithTransients.content?.raw === "string") {
6279 - parsedBlocksCache.set(getCacheKey(kind, name, key), {
6280 - content: recordWithTransients.content.raw,
6281 - blocks: recordWithTransients.blocks
6282 - });
6283 - }
6284 5600 void getSyncManager()?.load(
6285 5601 entityConfig.syncConfig,
6286 5602 objectType,
6287 5603 objectId,
@@ -6323,32 +5639,24 @@
6323 5639 refetchRecord: async () => {
6324 5640 dispatch3.receiveEntityRecords(
6325 5641 kind,
6326 5642 name,
6327 - await (0, import_api_fetch9.default)({ path, parse: true }),
5643 + await (0, import_api_fetch8.default)({ path, parse: true }),
6328 5644 query
6329 5645 );
6330 5646 },
6331 - // Persist the CRDT document.
6332 - //
6333 - // TODO: Currently, persisted CRDT documents are stored in post meta.
6334 - // This effectively means that only post entities support CRDT
6335 - // persistence. As we add support for syncing additional entity,
6336 - // we'll need to revisit where persisted CRDT documents are stored.
6337 - persistCRDTDoc: () => {
6338 - if (!entityConfig.syncConfig?.supportsPersistence) {
6339 - return;
6340 - }
6341 - return resolveSelect2.getEditedEntityRecord(kind, name, key).then(async (editedRecord) => {
6342 - const { meta, status } = editedRecord;
6343 - if ("auto-draft" === status || !meta) {
5647 + // Save the current entity record, whether or not it has unsaved
5648 + // edits. This is used to trigger a persisted CRDT document.
5649 + saveRecord: () => {
5650 + resolveSelect2.getEditedEntityRecord(kind, name, key).then((editedRecord) => {
5651 + const { status } = editedRecord;
5652 + if ("auto-draft" === status) {
6344 5653 return;
6345 5654 }
6346 - const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
6347 - const entityId = editedRecord[entityIdKey];
6348 - await saveCRDTDoc(
6349 - `${kind}/${name}`,
6350 - entityId
5655 + dispatch3.saveEntityRecord(
5656 + kind,
5657 + name,
5658 + editedRecord
6351 5659 );
6352 5660 });
6353 5661 },
6354 5662 addUndoMeta: (ydoc, meta) => {
@@ -6359,13 +5667,8 @@
6359 5667 selectionHistory
6360 5668 );
6361 5669 }
6362 5670 },
6363 - onUndoStackChange: (undoState) => {
6364 - dispatch3.__unstableNotifySyncUndoManagerChange(
6365 - undoState
6366 - );
6367 - },
6368 5671 restoreUndoMeta: (ydoc, meta) => {
6369 5672 const selectionHistory = meta.get("selectionHistory");
6370 5673 if (selectionHistory) {
6371 5674 setTimeout(() => {
@@ -6408,14 +5711,18 @@
6408 5711 );
6409 5712 const rawQuery = { ...query };
6410 5713 const key = entityConfig.key || DEFAULT_ENTITY_KEY;
6411 5714 function getResolutionsArgs(records, recordsQuery) {
6412 - const normalizedQuery = normalizeQueryForResolution(recordsQuery);
5715 + const queryArgs = Object.fromEntries(
5716 + Object.entries(recordsQuery).filter(([k, v]) => {
5717 + return ["context", "_fields"].includes(k) && !!v;
5718 + })
5719 + );
6413 5720 return records.filter((record) => record?.[key]).map((record) => [
6414 5721 kind,
6415 5722 name,
6416 5723 record[key],
6417 - normalizedQuery
5724 + Object.keys(queryArgs).length > 0 ? queryArgs : void 0
6418 5725 ]);
6419 5726 }
6420 5727 try {
6421 5728 if (query._fields) {
@@ -6439,9 +5746,9 @@
6439 5746 ...query
6440 5747 });
6441 5748 let records = [], meta;
6442 5749 if (entityConfig.supportsPagination && query.per_page !== -1) {
6443 - const response = await (0, import_api_fetch9.default)({ path, parse: false });
5750 + const response = await (0, import_api_fetch8.default)({ path, parse: false });
6444 5751 records = Object.values(await response.json());
6445 5752 meta = {
6446 5753 totalItems: parseInt(
6447 5754 response.headers.get("X-WP-Total")
@@ -6453,9 +5760,9 @@
6453 5760 } else if (query.per_page === -1 && query[RECEIVE_INTERMEDIATE_RESULTS] === true) {
6454 5761 let page = 1;
6455 5762 let totalPages;
6456 5763 do {
6457 - const response = await (0, import_api_fetch9.default)({
5764 + const response = await (0, import_api_fetch8.default)({
6458 5765 path: (0, import_url6.addQueryArgs)(path, { page, per_page: 100 }),
6459 5766 parse: false
6460 5767 });
6461 5768 const pageRecords = Object.values(await response.json());
@@ -6488,9 +5795,9 @@
6488 5795 });
6489 5796 page++;
6490 5797 } while (page <= totalPages);
6491 5798 } else {
6492 - records = Object.values(await (0, import_api_fetch9.default)({ path }));
5799 + records = Object.values(await (0, import_api_fetch8.default)({ path }));
6493 5800 meta = {
6494 5801 totalItems: records.length,
6495 5802 totalPages: 1
6496 5803 };
@@ -6512,9 +5819,9 @@
6512 5819 refetchRecords: async () => {
6513 5820 dispatch3.receiveEntityRecords(
6514 5821 kind,
6515 5822 name,
6516 - await (0, import_api_fetch9.default)({ path, parse: true }),
5823 + await (0, import_api_fetch8.default)({ path, parse: true }),
6517 5824 query
6518 5825 );
6519 5826 }
6520 5827 }
@@ -6577,9 +5884,9 @@
6577 5884 getResolutionsArgs(records, rawQuery)
6578 5885 );
6579 5886 dispatch3.__unstableReleaseStoreLock(lock2);
6580 5887 });
6581 - } catch {
5888 + } catch (e) {
6582 5889 dispatch3.__unstableReleaseStoreLock(lock2);
6583 5890 }
6584 5891 };
6585 5892 getEntityRecords2.shouldInvalidate = (action, kind, name) => {
@@ -6597,13 +5904,13 @@
6597 5904 };
6598 5905 var getThemeSupports2 = forward_resolver_default("getCurrentTheme");
6599 5906 var getEmbedPreview2 = (url) => async ({ dispatch: dispatch3 }) => {
6600 5907 try {
6601 - const embedProxyResponse = await (0, import_api_fetch9.default)({
5908 + const embedProxyResponse = await (0, import_api_fetch8.default)({
6602 5909 path: (0, import_url6.addQueryArgs)("/oembed/1.0/proxy", { url })
6603 5910 });
6604 5911 dispatch3.receiveEmbedPreview(url, embedProxyResponse);
6605 - } catch {
5912 + } catch (error) {
6606 5913 dispatch3.receiveEmbedPreview(url, false);
6607 5914 }
6608 5915 };
6609 5916 var canUser2 = (requestedAction, resource, id) => async ({ dispatch: dispatch3, registry, resolveSelect: resolveSelect2 }) => {
@@ -6643,14 +5950,14 @@
6643 5950 resourcePath = `/wp/v2/${resource}` + (id ? "/" + id : "");
6644 5951 }
6645 5952 let response;
6646 5953 try {
6647 - response = await (0, import_api_fetch9.default)({
5954 + response = await (0, import_api_fetch8.default)({
6648 5955 path: resourcePath,
6649 5956 method: "OPTIONS",
6650 5957 parse: false
6651 5958 });
6652 - } catch {
5959 + } catch (error) {
6653 5960 return;
6654 5961 }
6655 5962 const permissions = getUserPermissionsFromAllowHeader(
6656 5963 response.headers?.get("allow")
@@ -6679,9 +5986,9 @@
6679 5986 } = await resolveSelect2.getPostType(postType);
6680 5987 if (!supports?.autosave) {
6681 5988 return;
6682 5989 }
6683 - const autosaves2 = await (0, import_api_fetch9.default)({
5990 + const autosaves2 = await (0, import_api_fetch8.default)({
6684 5991 path: `/${restNamespace}/${restBase}/${postId}/autosaves?context=edit`
6685 5992 });
6686 5993 if (autosaves2 && autosaves2.length) {
6687 5994 dispatch3.receiveAutosaves(postId, autosaves2);
@@ -6707,9 +6014,9 @@
6707 6014 }
6708 6015 };
6709 6016 var __experimentalGetCurrentThemeBaseGlobalStyles2 = () => async ({ resolveSelect: resolveSelect2, dispatch: dispatch3 }) => {
6710 6017 const currentTheme2 = await resolveSelect2.getCurrentTheme();
6711 - const themeGlobalStyles = await (0, import_api_fetch9.default)({
6018 + const themeGlobalStyles = await (0, import_api_fetch8.default)({
6712 6019 path: `/wp/v2/global-styles/themes/${currentTheme2.stylesheet}?context=view`
6713 6020 });
6714 6021 dispatch3.__experimentalReceiveThemeBaseGlobalStyles(
6715 6022 currentTheme2.stylesheet,
@@ -6717,9 +6024,9 @@
6717 6024 );
6718 6025 };
6719 6026 var __experimentalGetCurrentThemeGlobalStylesVariations2 = () => async ({ resolveSelect: resolveSelect2, dispatch: dispatch3 }) => {
6720 6027 const currentTheme2 = await resolveSelect2.getCurrentTheme();
6721 - const variations = await (0, import_api_fetch9.default)({
6028 + const variations = await (0, import_api_fetch8.default)({
6722 6029 path: `/wp/v2/global-styles/themes/${currentTheme2.stylesheet}/variations?context=view`
6723 6030 });
6724 6031 dispatch3.__experimentalReceiveThemeGlobalStyleVariations(
6725 6032 currentTheme2.stylesheet,
@@ -6734,9 +6041,9 @@
6734 6041 globalStylesId
6735 6042 ) : void 0;
6736 6043 const revisionsURL = record?._links?.["version-history"]?.[0]?.href;
6737 6044 if (revisionsURL) {
6738 - const resetRevisions = await (0, import_api_fetch9.default)({
6045 + const resetRevisions = await (0, import_api_fetch8.default)({
6739 6046 url: revisionsURL
6740 6047 });
6741 6048 const revisions = resetRevisions?.map(
6742 6049 (revision) => Object.fromEntries(
@@ -6759,9 +6066,9 @@
6759 6066 const patterns = await fetchBlockPatterns();
6760 6067 dispatch3({ type: "RECEIVE_BLOCK_PATTERNS", patterns });
6761 6068 };
6762 6069 var getBlockPatternCategories2 = () => async ({ dispatch: dispatch3 }) => {
6763 - const categories = await (0, import_api_fetch9.default)({
6070 + const categories = await (0, import_api_fetch8.default)({
6764 6071 path: "/wp/v2/block-patterns/categories"
6765 6072 });
6766 6073 dispatch3({ type: "RECEIVE_BLOCK_PATTERN_CATEGORIES", categories });
6767 6074 };
@@ -6784,10 +6091,10 @@
6784 6091 type: "RECEIVE_USER_PATTERN_CATEGORIES",
6785 6092 patternCategories: mappedPatternCategories
6786 6093 });
6787 6094 };
6788 - var getNavigationFallbackId2 = () => async ({ dispatch: dispatch3, select: select4, registry }) => {
6789 - const fallback = await (0, import_api_fetch9.default)({
6095 + var getNavigationFallbackId2 = () => async ({ dispatch: dispatch3, select: select5, registry }) => {
6096 + const fallback = await (0, import_api_fetch8.default)({
6790 6097 path: (0, import_url6.addQueryArgs)("/wp-block-editor/v1/navigation-fallback", {
6791 6098 _embed: true
6792 6099 })
6793 6100 });
@@ -6796,9 +6103,9 @@
6796 6103 dispatch3.receiveNavigationFallbackId(fallback?.id);
6797 6104 if (!record) {
6798 6105 return;
6799 6106 }
6800 - const existingFallbackEntityRecord = select4.getEntityRecord(
6107 + const existingFallbackEntityRecord = select5.getEntityRecord(
6801 6108 "postType",
6802 6109 "wp_navigation",
6803 6110 fallback.id
6804 6111 );
@@ -6817,32 +6124,30 @@
6817 6124 ]);
6818 6125 });
6819 6126 };
6820 6127 var getDefaultTemplateId2 = (query) => async ({ dispatch: dispatch3, registry, resolveSelect: resolveSelect2 }) => {
6821 - const template = await (0, import_api_fetch9.default)({
6128 + const template = await (0, import_api_fetch8.default)({
6822 6129 path: (0, import_url6.addQueryArgs)("/wp/v2/templates/lookup", query)
6823 6130 });
6824 6131 await resolveSelect2.getEntitiesConfig("postType");
6825 6132 const id = window?.__experimentalTemplateActivate ? template?.wp_id || template?.id : template?.id;
6826 - registry.batch(() => {
6827 - dispatch3.receiveDefaultTemplateId(query, id || "");
6828 - if (id) {
6829 - template.id = id;
6830 - dispatch3.receiveEntityRecords(
6831 - "postType",
6832 - template.type,
6133 + if (id) {
6134 + template.id = id;
6135 + registry.batch(() => {
6136 + dispatch3.receiveDefaultTemplateId(query, id);
6137 + dispatch3.receiveEntityRecords("postType", template.type, [
6833 6138 template
6834 - );
6139 + ]);
6835 6140 dispatch3.finishResolution("getEntityRecord", [
6836 6141 "postType",
6837 6142 template.type,
6838 6143 id
6839 6144 ]);
6840 - }
6841 - });
6145 + });
6146 + }
6842 6147 };
6843 6148 getDefaultTemplateId2.shouldInvalidate = (action) => {
6844 - return action.type === "RECEIVE_ITEMS" && action.kind === "root" && action.name === "site" && !!action.persistedEdits;
6149 + return action.type === "RECEIVE_ITEMS" && action.kind === "root" && action.name === "site";
6845 6150 };
6846 6151 var getRevisions2 = (kind, name, recordKey, query = {}) => async ({ dispatch: dispatch3, registry, resolveSelect: resolveSelect2 }) => {
6847 6152 const configs = await resolveSelect2.getEntitiesConfig(kind);
6848 6153 const entityConfig = configs.find(
@@ -6850,88 +6155,78 @@
6850 6155 );
6851 6156 if (!entityConfig) {
6852 6157 return;
6853 6158 }
6854 - const rawQuery = { ...query };
6855 - const lock2 = await dispatch3.__unstableAcquireStoreLock(
6856 - STORE_NAME,
6857 - ["entities", "records", kind, name, recordKey, "revisions"],
6858 - { exclusive: false }
6159 + if (query._fields) {
6160 + query = {
6161 + ...query,
6162 + _fields: [
6163 + .../* @__PURE__ */ new Set([
6164 + ...get_normalized_comma_separable_default(query._fields) || [],
6165 + entityConfig.revisionKey || DEFAULT_ENTITY_KEY
6166 + ])
6167 + ].join()
6168 + };
6169 + }
6170 + const path = (0, import_url6.addQueryArgs)(
6171 + entityConfig.getRevisionsUrl(recordKey),
6172 + query
6859 6173 );
6174 + let records, response;
6175 + const meta = {};
6176 + const isPaginated = entityConfig.supportsPagination && query.per_page !== -1;
6860 6177 try {
6178 + response = await (0, import_api_fetch8.default)({ path, parse: !isPaginated });
6179 + } catch (error) {
6180 + return;
6181 + }
6182 + if (response) {
6183 + if (isPaginated) {
6184 + records = Object.values(await response.json());
6185 + meta.totalItems = parseInt(
6186 + response.headers.get("X-WP-Total")
6187 + );
6188 + } else {
6189 + records = Object.values(response);
6190 + }
6861 6191 if (query._fields) {
6862 - query = {
6863 - ...query,
6864 - _fields: [
6865 - .../* @__PURE__ */ new Set([
6866 - ...get_normalized_comma_separable_default(query._fields) || [],
6867 - entityConfig.revisionKey || DEFAULT_ENTITY_KEY
6868 - ])
6869 - ].join()
6870 - };
6192 + records = records.map((record) => {
6193 + query._fields.split(",").forEach((field) => {
6194 + if (!record.hasOwnProperty(field)) {
6195 + record[field] = void 0;
6196 + }
6197 + });
6198 + return record;
6199 + });
6871 6200 }
6872 - const path = (0, import_url6.addQueryArgs)(
6873 - entityConfig.getRevisionsUrl(recordKey),
6874 - query
6875 - );
6876 - let records, response;
6877 - const meta = {};
6878 - const isPaginated = entityConfig.supportsPagination && query.per_page !== -1;
6879 - try {
6880 - response = await (0, import_api_fetch9.default)({ path, parse: !isPaginated });
6881 - } catch {
6882 - return;
6883 - }
6884 - if (response) {
6885 - if (isPaginated) {
6886 - records = Object.values(await response.json());
6887 - meta.totalItems = parseInt(
6888 - response.headers.get("X-WP-Total")
6889 - );
6890 - } else {
6891 - records = Object.values(response);
6892 - }
6893 - if (query._fields) {
6894 - records = records.map((record) => {
6895 - query._fields.split(",").forEach((field) => {
6896 - if (!record.hasOwnProperty(field)) {
6897 - record[field] = void 0;
6898 - }
6899 - });
6900 - return record;
6901 - });
6902 - }
6903 - registry.batch(() => {
6904 - dispatch3.receiveRevisions(
6905 - kind,
6906 - name,
6907 - recordKey,
6908 - records,
6909 - query,
6910 - false,
6911 - meta
6912 - );
6201 + registry.batch(() => {
6202 + dispatch3.receiveRevisions(
6203 + kind,
6204 + name,
6205 + recordKey,
6206 + records,
6207 + query,
6208 + false,
6209 + meta
6210 + );
6211 + if (!query?._fields && !query.context) {
6913 6212 const key = entityConfig.revisionKey || DEFAULT_ENTITY_KEY;
6914 - const normalizedQuery = normalizeQueryForResolution(rawQuery);
6915 6213 const resolutionsArgs = records.filter((record) => record[key]).map((record) => [
6916 6214 kind,
6917 6215 name,
6918 6216 recordKey,
6919 - record[key],
6920 - normalizedQuery
6217 + record[key]
6921 6218 ]);
6922 6219 dispatch3.finishResolutions(
6923 6220 "getRevision",
6924 6221 resolutionsArgs
6925 6222 );
6926 - });
6927 - }
6928 - } finally {
6929 - dispatch3.__unstableReleaseStoreLock(lock2);
6223 + }
6224 + });
6930 6225 }
6931 6226 };
6932 6227 getRevisions2.shouldInvalidate = (action, kind, name, recordKey) => action.type === "SAVE_ENTITY_RECORD_FINISH" && name === action.name && kind === action.kind && !action.error && recordKey === action.recordId;
6933 - var getRevision2 = (kind, name, recordKey, revisionKey, query) => async ({ select: select4, dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
6228 + var getRevision2 = (kind, name, recordKey, revisionKey, query) => async ({ dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
6934 6229 const configs = await resolveSelect2.getEntitiesConfig(kind);
6935 6230 const entityConfig = configs.find(
6936 6231 (config) => config.name === name && config.kind === kind
6937 6232 );
@@ -6948,47 +6243,21 @@
6948 6243 ])
6949 6244 ].join()
6950 6245 };
6951 6246 }
6952 - const lock2 = await dispatch3.__unstableAcquireStoreLock(
6953 - STORE_NAME,
6954 - [
6955 - "entities",
6956 - "records",
6957 - kind,
6958 - name,
6959 - recordKey,
6960 - "revisions",
6961 - revisionKey
6962 - ],
6963 - { exclusive: false }
6247 + const path = (0, import_url6.addQueryArgs)(
6248 + entityConfig.getRevisionsUrl(recordKey, revisionKey),
6249 + query
6964 6250 );
6251 + let record;
6965 6252 try {
6966 - if (select4.hasRevision(kind, name, recordKey, revisionKey, query)) {
6967 - return;
6968 - }
6969 - const path = (0, import_url6.addQueryArgs)(
6970 - entityConfig.getRevisionsUrl(recordKey, revisionKey),
6971 - query
6972 - );
6973 - let record;
6974 - try {
6975 - record = await (0, import_api_fetch9.default)({ path });
6976 - } catch {
6977 - return;
6978 - }
6979 - if (record) {
6980 - dispatch3.receiveRevisions(
6981 - kind,
6982 - name,
6983 - recordKey,
6984 - record,
6985 - query
6986 - );
6987 - }
6988 - } finally {
6989 - dispatch3.__unstableReleaseStoreLock(lock2);
6253 + record = await (0, import_api_fetch8.default)({ path });
6254 + } catch (error) {
6255 + return;
6990 6256 }
6257 + if (record) {
6258 + dispatch3.receiveRevisions(kind, name, recordKey, record, query);
6259 + }
6991 6260 };
6992 6261 var getRegisteredPostMeta2 = (postType) => async ({ dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
6993 6262 let options;
6994 6263 try {
@@ -6995,13 +6264,13 @@
6995 6264 const {
6996 6265 rest_namespace: restNamespace = "wp/v2",
6997 6266 rest_base: restBase
6998 6267 } = await resolveSelect2.getPostType(postType) || {};
6999 - options = await (0, import_api_fetch9.default)({
6268 + options = await (0, import_api_fetch8.default)({
7000 6269 path: `${restNamespace}/${restBase}/?context=edit`,
7001 6270 method: "OPTIONS"
7002 6271 });
7003 - } catch {
6272 + } catch (error) {
7004 6273 return;
7005 6274 }
7006 6275 if (options) {
7007 6276 dispatch3.receiveRegisteredPostMeta(
@@ -7026,30 +6295,19 @@
7026 6295 } catch {
7027 6296 }
7028 6297 };
7029 6298 var getEditorSettings2 = () => async ({ dispatch: dispatch3 }) => {
7030 - const settings = await (0, import_api_fetch9.default)({
6299 + const settings = await (0, import_api_fetch8.default)({
7031 6300 path: "/wp-block-editor/v1/settings"
7032 6301 });
7033 6302 dispatch3.receiveEditorSettings(settings);
7034 6303 };
7035 6304 var getEditorAssets2 = () => async ({ dispatch: dispatch3 }) => {
7036 - const assets = await (0, import_api_fetch9.default)({
6305 + const assets = await (0, import_api_fetch8.default)({
7037 6306 path: "/wp-block-editor/v1/assets"
7038 6307 });
7039 6308 dispatch3.receiveEditorAssets(assets);
7040 6309 };
7041 - var getViewConfig2 = (kind, name, options = {}) => async ({ dispatch: dispatch3 }) => {
7042 - const query = { kind, name };
7043 - const fields = get_normalized_comma_separable_default(options.fields);
7044 - if (fields?.length) {
7045 - query._fields = fields.join(",");
7046 - }
7047 - const config = await (0, import_api_fetch9.default)({
7048 - path: (0, import_url6.addQueryArgs)("/wp/v2/view-config", query)
7049 - });
7050 - dispatch3.receiveViewConfig(kind, name, config);
7051 - };
7052 6310
7053 6311 // packages/core-data/build-module/locks/utils.mjs
7054 6312 function deepCopyLocksTreePath(tree, path) {
7055 6313 const newTree = { ...tree };
@@ -7238,37 +6496,102 @@
7238 6496 EntityContext.displayName = "EntityContext";
7239 6497
7240 6498 // packages/core-data/build-module/entity-provider.mjs
7241 6499 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
7242 - function EntityProvider({
7243 - kind,
7244 - type: name,
7245 - id,
7246 - revisionId,
7247 - children
7248 - }) {
6500 + function EntityProvider({ kind, type: name, id, children }) {
7249 6501 const parent = (0, import_element2.useContext)(EntityContext);
7250 6502 const childContext = (0, import_element2.useMemo)(
7251 6503 () => ({
7252 6504 ...parent,
7253 - ...kind && {
7254 - [kind]: {
7255 - ...parent?.[kind],
7256 - [name]: id
7257 - }
7258 - },
7259 - ...revisionId !== void 0 && { revisionId }
6505 + [kind]: {
6506 + ...parent?.[kind],
6507 + [name]: id
6508 + }
7260 6509 }),
7261 - [parent, kind, name, id, revisionId]
6510 + [parent, kind, name, id]
7262 6511 );
7263 6512 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EntityContext.Provider, { value: childContext, children });
7264 6513 }
7265 6514
7266 6515 // packages/core-data/build-module/hooks/use-entity-record.mjs
7267 - var import_data10 = __toESM(require_data(), 1);
6516 + var import_data12 = __toESM(require_data(), 1);
7268 6517 var import_deprecated4 = __toESM(require_deprecated(), 1);
7269 6518 var import_element3 = __toESM(require_element(), 1);
7270 6519
6520 + // packages/core-data/build-module/hooks/use-query-select.mjs
6521 + var import_data11 = __toESM(require_data(), 1);
6522 +
6523 + // node_modules/memize/dist/index.js
6524 + function memize(fn, options) {
6525 + var size = 0;
6526 + var head;
6527 + var tail;
6528 + options = options || {};
6529 + function memoized() {
6530 + var node = head, len = arguments.length, args, i;
6531 + searchCache: while (node) {
6532 + if (node.args.length !== arguments.length) {
6533 + node = node.next;
6534 + continue;
6535 + }
6536 + for (i = 0; i < len; i++) {
6537 + if (node.args[i] !== arguments[i]) {
6538 + node = node.next;
6539 + continue searchCache;
6540 + }
6541 + }
6542 + if (node !== head) {
6543 + if (node === tail) {
6544 + tail = node.prev;
6545 + }
6546 + node.prev.next = node.next;
6547 + if (node.next) {
6548 + node.next.prev = node.prev;
6549 + }
6550 + node.next = head;
6551 + node.prev = null;
6552 + head.prev = node;
6553 + head = node;
6554 + }
6555 + return node.val;
6556 + }
6557 + args = new Array(len);
6558 + for (i = 0; i < len; i++) {
6559 + args[i] = arguments[i];
6560 + }
6561 + node = {
6562 + args,
6563 + // Generate the result from original function
6564 + val: fn.apply(null, args)
6565 + };
6566 + if (head) {
6567 + head.prev = node;
6568 + node.next = head;
6569 + } else {
6570 + tail = node;
6571 + }
6572 + if (size === /** @type {MemizeOptions} */
6573 + options.maxSize) {
6574 + tail = /** @type {MemizeCacheNode} */
6575 + tail.prev;
6576 + tail.next = null;
6577 + } else {
6578 + size++;
6579 + }
6580 + head = node;
6581 + return node.val;
6582 + }
6583 + memoized.clear = function() {
6584 + head = null;
6585 + tail = null;
6586 + size = 0;
6587 + };
6588 + return memoized;
6589 + }
6590 +
6591 + // packages/core-data/build-module/hooks/memoize.mjs
6592 + var memoize_default = memize;
6593 +
7271 6594 // packages/core-data/build-module/hooks/constants.mjs
7272 6595 var Status = /* @__PURE__ */ ((Status2) => {
7273 6596 Status2["Idle"] = "IDLE";
7274 6597 Status2["Resolving"] = "RESOLVING";
@@ -7276,36 +6599,67 @@
7276 6599 Status2["Success"] = "SUCCESS";
7277 6600 return Status2;
7278 6601 })(Status || {});
7279 6602
7280 - // packages/core-data/build-module/hooks/utils.mjs
7281 - function getResolutionStatus(resolutionStatus) {
7282 - let status;
7283 - switch (resolutionStatus) {
7284 - case "resolving":
7285 - status = Status.Resolving;
7286 - break;
7287 - case "finished":
7288 - status = Status.Success;
7289 - break;
7290 - case "error":
7291 - status = Status.Error;
7292 - break;
7293 - default:
7294 - status = Status.Idle;
6603 + // packages/core-data/build-module/hooks/use-query-select.mjs
6604 + var META_SELECTORS = [
6605 + "getIsResolving",
6606 + "hasStartedResolution",
6607 + "hasFinishedResolution",
6608 + "isResolving",
6609 + "getCachedResolvers"
6610 + ];
6611 + function useQuerySelect(mapQuerySelect, deps) {
6612 + return (0, import_data11.useSelect)((select5, registry) => {
6613 + const resolve = (store2) => enrichSelectors(select5(store2));
6614 + return mapQuerySelect(resolve, registry);
6615 + }, deps);
6616 + }
6617 + var enrichSelectors = memoize_default(((selectors) => {
6618 + const resolvers = {};
6619 + for (const selectorName in selectors) {
6620 + if (META_SELECTORS.includes(selectorName)) {
6621 + continue;
6622 + }
6623 + Object.defineProperty(resolvers, selectorName, {
6624 + get: () => (...args) => {
6625 + const data = selectors[selectorName](...args);
6626 + const resolutionStatus = selectors.getResolutionState(
6627 + selectorName,
6628 + args
6629 + )?.status;
6630 + let status;
6631 + switch (resolutionStatus) {
6632 + case "resolving":
6633 + status = Status.Resolving;
6634 + break;
6635 + case "finished":
6636 + status = Status.Success;
6637 + break;
6638 + case "error":
6639 + status = Status.Error;
6640 + break;
6641 + case void 0:
6642 + status = Status.Idle;
6643 + break;
6644 + }
6645 + return {
6646 + data,
6647 + status,
6648 + isResolving: status === Status.Resolving,
6649 + hasStarted: status !== Status.Idle,
6650 + hasResolved: status === Status.Success || status === Status.Error
6651 + };
6652 + }
6653 + });
7295 6654 }
7296 - return {
7297 - status,
7298 - isResolving: status === Status.Resolving,
7299 - hasStarted: status !== Status.Idle,
7300 - hasResolved: status === Status.Success || status === Status.Error
7301 - };
7302 - }
6655 + return resolvers;
6656 + }));
7303 6657
7304 6658 // packages/core-data/build-module/hooks/use-entity-record.mjs
7305 - var EMPTY_OBJECT3 = {};
6659 + var EMPTY_OBJECT2 = {};
7306 6660 function useEntityRecord(kind, name, recordId, options = { enabled: true }) {
7307 - const { editEntityRecord: editEntityRecord2, saveEditedEntityRecord: saveEditedEntityRecord2 } = (0, import_data10.useDispatch)(store);
6661 + const { editEntityRecord: editEntityRecord2, saveEditedEntityRecord: saveEditedEntityRecord2 } = (0, import_data12.useDispatch)(store);
7308 6662 const mutations = (0, import_element3.useMemo)(
7309 6663 () => ({
7310 6664 edit: (record2, editOptions = {}) => editEntityRecord2(kind, name, recordId, record2, editOptions),
7311 6665 save: (saveOptions = {}) => saveEditedEntityRecord2(kind, name, recordId, {
@@ -7314,60 +6668,58 @@
7314 6668 })
7315 6669 }),
7316 6670 [editEntityRecord2, kind, name, recordId, saveEditedEntityRecord2]
7317 6671 );
7318 - const { record, editedRecord, hasEdits, edits, ...resolution } = (0, import_data10.useSelect)(
7319 - (select4) => {
6672 + const { editedRecord, hasEdits, edits } = (0, import_data12.useSelect)(
6673 + (select5) => {
7320 6674 if (!options.enabled) {
7321 6675 return {
7322 - record: null,
7323 - editedRecord: EMPTY_OBJECT3,
6676 + editedRecord: EMPTY_OBJECT2,
7324 6677 hasEdits: false,
7325 - edits: EMPTY_OBJECT3,
7326 - ...getResolutionStatus()
6678 + edits: EMPTY_OBJECT2
7327 6679 };
7328 6680 }
7329 - const storeSelectors = select4(store);
7330 - const resolutionStatus = storeSelectors.getResolutionState(
7331 - "getEntityRecord",
7332 - [kind, name, recordId]
7333 - )?.status;
7334 6681 return {
7335 - record: storeSelectors.getEntityRecord(
6682 + editedRecord: select5(store).getEditedEntityRecord(
7336 6683 kind,
7337 6684 name,
7338 6685 recordId
7339 - ) ?? null,
7340 - editedRecord: storeSelectors.getEditedEntityRecord(
7341 - kind,
7342 - name,
7343 - recordId
7344 6686 ),
7345 - hasEdits: storeSelectors.hasEditsForEntityRecord(
6687 + hasEdits: select5(store).hasEditsForEntityRecord(
7346 6688 kind,
7347 6689 name,
7348 6690 recordId
7349 6691 ),
7350 - edits: storeSelectors.getEntityRecordNonTransientEdits(
6692 + edits: select5(store).getEntityRecordNonTransientEdits(
7351 6693 kind,
7352 6694 name,
7353 6695 recordId
7354 - ),
7355 - ...getResolutionStatus(resolutionStatus)
6696 + )
7356 6697 };
7357 6698 },
7358 6699 [kind, name, recordId, options.enabled]
7359 6700 );
6701 + const { data: record, ...querySelectRest } = useQuerySelect(
6702 + (query) => {
6703 + if (!options.enabled) {
6704 + return {
6705 + data: null
6706 + };
6707 + }
6708 + return query(store).getEntityRecord(kind, name, recordId);
6709 + },
6710 + [kind, name, recordId, options.enabled]
6711 + );
7360 6712 return {
7361 6713 record,
7362 6714 editedRecord,
7363 6715 hasEdits,
7364 6716 edits,
7365 - ...resolution,
6717 + ...querySelectRest,
7366 6718 ...mutations
7367 6719 };
7368 6720 }
7369 - function useDeprecatedEntityRecord(kind, name, recordId, options) {
6721 + function __experimentalUseEntityRecord(kind, name, recordId, options) {
7370 6722 (0, import_deprecated4.default)(`wp.data.__experimentalUseEntityRecord`, {
7371 6723 alternative: "wp.data.useEntityRecord",
7372 6724 since: "6.1"
7373 6725 });
@@ -7376,46 +6728,44 @@
7376 6728
7377 6729 // packages/core-data/build-module/hooks/use-entity-records.mjs
7378 6730 var import_url7 = __toESM(require_url(), 1);
7379 6731 var import_deprecated5 = __toESM(require_deprecated(), 1);
7380 - var import_data11 = __toESM(require_data(), 1);
6732 + var import_data13 = __toESM(require_data(), 1);
7381 6733 var import_element4 = __toESM(require_element(), 1);
7382 6734 var EMPTY_ARRAY = [];
7383 6735 function useEntityRecords(kind, name, queryArgs = {}, options = { enabled: true }) {
7384 6736 const queryAsString = (0, import_url7.addQueryArgs)("", queryArgs);
7385 - const { records, totalItems, totalPages, ...rest } = (0, import_data11.useSelect)(
7386 - (select4) => {
6737 + const { data: records, ...rest } = useQuerySelect(
6738 + (query) => {
7387 6739 if (!options.enabled) {
7388 6740 return {
7389 6741 // Avoiding returning a new reference on every execution.
7390 - records: EMPTY_ARRAY,
6742 + data: EMPTY_ARRAY
6743 + };
6744 + }
6745 + return query(store).getEntityRecords(kind, name, queryArgs);
6746 + },
6747 + [kind, name, queryAsString, options.enabled]
6748 + );
6749 + const { totalItems, totalPages } = (0, import_data13.useSelect)(
6750 + (select5) => {
6751 + if (!options.enabled) {
6752 + return {
7391 6753 totalItems: null,
7392 - totalPages: null,
7393 - ...getResolutionStatus()
6754 + totalPages: null
7394 6755 };
7395 6756 }
7396 - const storeSelectors = select4(store);
7397 - const resolutionStatus = storeSelectors.getResolutionState(
7398 - "getEntityRecords",
7399 - [kind, name, queryArgs]
7400 - )?.status;
7401 6757 return {
7402 - records: storeSelectors.getEntityRecords(
6758 + totalItems: select5(store).getEntityRecordsTotalItems(
7403 6759 kind,
7404 6760 name,
7405 6761 queryArgs
7406 6762 ),
7407 - totalItems: storeSelectors.getEntityRecordsTotalItems(
6763 + totalPages: select5(store).getEntityRecordsTotalPages(
7408 6764 kind,
7409 6765 name,
7410 6766 queryArgs
7411 - ),
7412 - totalPages: storeSelectors.getEntityRecordsTotalPages(
7413 - kind,
7414 - name,
7415 - queryArgs
7416 - ),
7417 - ...getResolutionStatus(resolutionStatus)
6767 + )
7418 6768 };
7419 6769 },
7420 6770 [kind, name, queryAsString, options.enabled]
7421 6771 );
@@ -7425,9 +6775,9 @@
7425 6775 totalPages,
7426 6776 ...rest
7427 6777 };
7428 6778 }
7429 - function useDeprecatedEntityRecords(kind, name, queryArgs, options) {
6779 + function __experimentalUseEntityRecords(kind, name, queryArgs, options) {
7430 6780 (0, import_deprecated5.default)(`wp.data.__experimentalUseEntityRecords`, {
7431 6781 alternative: "wp.data.useEntityRecords",
7432 6782 since: "6.1"
7433 6783 });
@@ -7433,10 +6783,10 @@
7433 6783 });
7434 6784 return useEntityRecords(kind, name, queryArgs, options);
7435 6785 }
7436 6786 function useEntityRecordsWithPermissions(kind, name, queryArgs = {}, options = { enabled: true }) {
7437 - const entityConfig = (0, import_data11.useSelect)(
7438 - (select4) => select4(store).getEntityConfig(kind, name),
6787 + const entityConfig = (0, import_data13.useSelect)(
6788 + (select5) => select5(store).getEntityConfig(kind, name),
7439 6789 [kind, name]
7440 6790 );
7441 6791 const { records: data, ...ret } = useEntityRecords(
7442 6792 kind,
@@ -7463,12 +6813,12 @@
7463 6813 (record) => record[entityConfig?.key ?? "id"]
7464 6814 ) ?? [],
7465 6815 [data, entityConfig?.key]
7466 6816 );
7467 - const permissions = (0, import_data11.useSelect)(
7468 - (select4) => {
6817 + const permissions = (0, import_data13.useSelect)(
6818 + (select5) => {
7469 6819 const { getEntityRecordsPermissions: getEntityRecordsPermissions2 } = unlock(
7470 - select4(store)
6820 + select5(store)
7471 6821 );
7472 6822 return getEntityRecordsPermissions2(kind, name, ids);
7473 6823 },
7474 6824 [ids, kind, name]
@@ -7486,118 +6836,8 @@
7486 6836
7487 6837 // packages/core-data/build-module/hooks/use-resource-permissions.mjs
7488 6838 var import_deprecated6 = __toESM(require_deprecated(), 1);
7489 6839 var import_warning = __toESM(require_warning(), 1);
7490 -
7491 - // packages/core-data/build-module/hooks/use-query-select.mjs
7492 - var import_data12 = __toESM(require_data(), 1);
7493 -
7494 - // node_modules/memize/dist/index.js
7495 - function memize(fn, options) {
7496 - var size = 0;
7497 - var head;
7498 - var tail;
7499 - options = options || {};
7500 - function memoized() {
7501 - var node = head, len = arguments.length, args, i;
7502 - searchCache: while (node) {
7503 - if (node.args.length !== arguments.length) {
7504 - node = node.next;
7505 - continue;
7506 - }
7507 - for (i = 0; i < len; i++) {
7508 - if (node.args[i] !== arguments[i]) {
7509 - node = node.next;
7510 - continue searchCache;
7511 - }
7512 - }
7513 - if (node !== head) {
7514 - if (node === tail) {
7515 - tail = node.prev;
7516 - }
7517 - node.prev.next = node.next;
7518 - if (node.next) {
7519 - node.next.prev = node.prev;
7520 - }
7521 - node.next = head;
7522 - node.prev = null;
7523 - head.prev = node;
7524 - head = node;
7525 - }
7526 - return node.val;
7527 - }
7528 - args = new Array(len);
7529 - for (i = 0; i < len; i++) {
7530 - args[i] = arguments[i];
7531 - }
7532 - node = {
7533 - args,
7534 - // Generate the result from original function
7535 - val: fn.apply(null, args)
7536 - };
7537 - if (head) {
7538 - head.prev = node;
7539 - node.next = head;
7540 - } else {
7541 - tail = node;
7542 - }
7543 - if (size === /** @type {MemizeOptions} */
7544 - options.maxSize) {
7545 - tail = /** @type {MemizeCacheNode} */
7546 - tail.prev;
7547 - tail.next = null;
7548 - } else {
7549 - size++;
7550 - }
7551 - head = node;
7552 - return node.val;
7553 - }
7554 - memoized.clear = function() {
7555 - head = null;
7556 - tail = null;
7557 - size = 0;
7558 - };
7559 - return memoized;
7560 - }
7561 -
7562 - // packages/core-data/build-module/hooks/use-query-select.mjs
7563 - var META_SELECTORS = [
7564 - "getIsResolving",
7565 - "hasStartedResolution",
7566 - "hasFinishedResolution",
7567 - "isResolving",
7568 - "getCachedResolvers"
7569 - ];
7570 - function useQuerySelect(mapQuerySelect, deps) {
7571 - return (0, import_data12.useSelect)((select4, registry) => {
7572 - const resolve = (store2) => enrichSelectors(select4(store2));
7573 - return mapQuerySelect(resolve, registry);
7574 - }, deps);
7575 - }
7576 - var enrichSelectors = memize(((selectors) => {
7577 - const resolvers = {};
7578 - for (const selectorName in selectors) {
7579 - if (META_SELECTORS.includes(selectorName)) {
7580 - continue;
7581 - }
7582 - Object.defineProperty(resolvers, selectorName, {
7583 - get: () => (...args) => {
7584 - const data = selectors[selectorName](...args);
7585 - const resolutionStatus = selectors.getResolutionState(
7586 - selectorName,
7587 - args
7588 - )?.status;
7589 - return {
7590 - data,
7591 - ...getResolutionStatus(resolutionStatus)
7592 - };
7593 - }
7594 - });
7595 - }
7596 - return resolvers;
7597 - }));
7598 -
7599 - // packages/core-data/build-module/hooks/use-resource-permissions.mjs
7600 6840 function useResourcePermissions(resource, id) {
7601 6841 const isEntity = typeof resource === "object";
7602 6842 const resourceAsString = isEntity ? JSON.stringify(resource) : resource;
7603 6843 if (isEntity && typeof id !== "undefined") {
@@ -7608,14 +6848,16 @@
7608 6848 return useQuerySelect(
7609 6849 (resolve) => {
7610 6850 const hasId = isEntity ? !!resource.id : !!id;
7611 6851 const { canUser: canUser3 } = resolve(store);
7612 - const collectionResource = isEntity ? { kind: resource.kind, name: resource.name } : resource;
7613 - const create3 = canUser3("create", collectionResource);
6852 + const create2 = canUser3(
6853 + "create",
6854 + isEntity ? { kind: resource.kind, name: resource.name } : resource
6855 + );
7614 6856 if (!hasId) {
7615 - const read2 = canUser3("read", collectionResource);
7616 - const isResolving2 = create3.isResolving || read2.isResolving;
7617 - const hasResolved2 = create3.hasResolved && read2.hasResolved;
6857 + const read2 = canUser3("read", resource);
6858 + const isResolving2 = create2.isResolving || read2.isResolving;
6859 + const hasResolved2 = create2.hasResolved && read2.hasResolved;
7618 6860 let status2 = Status.Idle;
7619 6861 if (isResolving2) {
7620 6862 status2 = Status.Resolving;
7621 6863 } else if (hasResolved2) {
@@ -7624,9 +6866,9 @@
7624 6866 return {
7625 6867 status: status2,
7626 6868 isResolving: isResolving2,
7627 6869 hasResolved: hasResolved2,
7628 - canCreate: create3.hasResolved && create3.data,
6870 + canCreate: create2.hasResolved && create2.data,
7629 6871 canRead: read2.hasResolved && read2.data
7630 6872 };
7631 6873 }
7632 6874 const read = canUser3("read", resource, id);
@@ -7631,10 +6873,10 @@
7631 6873 }
7632 6874 const read = canUser3("read", resource, id);
7633 6875 const update = canUser3("update", resource, id);
7634 6876 const _delete = canUser3("delete", resource, id);
7635 - const isResolving = read.isResolving || create3.isResolving || update.isResolving || _delete.isResolving;
7636 - const hasResolved = read.hasResolved && create3.hasResolved && update.hasResolved && _delete.hasResolved;
6877 + const isResolving = read.isResolving || create2.isResolving || update.isResolving || _delete.isResolving;
6878 + const hasResolved = read.hasResolved && create2.hasResolved && update.hasResolved && _delete.hasResolved;
7637 6879 let status = Status.Idle;
7638 6880 if (isResolving) {
7639 6881 status = Status.Resolving;
7640 6882 } else if (hasResolved) {
@@ -7644,9 +6886,9 @@
7644 6886 status,
7645 6887 isResolving,
7646 6888 hasResolved,
7647 6889 canRead: hasResolved && read.data,
7648 - canCreate: hasResolved && create3.data,
6890 + canCreate: hasResolved && create2.data,
7649 6891 canUpdate: hasResolved && update.data,
7650 6892 canDelete: hasResolved && _delete.data
7651 6893 };
7652 6894 },
@@ -7653,9 +6895,9 @@
7653 6895 [resourceAsString, id]
7654 6896 );
7655 6897 }
7656 6898 var use_resource_permissions_default = useResourcePermissions;
7657 - function useDeprecatedResourcePermissions(resource, id) {
6899 + function __experimentalUseResourcePermissions(resource, id) {
7658 6900 (0, import_deprecated6.default)(`wp.data.__experimentalUseResourcePermissions`, {
7659 6901 alternative: "wp.data.useResourcePermissions",
7660 6902 since: "6.1"
7661 6903 });
@@ -7663,9 +6905,9 @@
7663 6905 }
7664 6906
7665 6907 // packages/core-data/build-module/hooks/use-entity-block-editor.mjs
7666 6908 var import_element6 = __toESM(require_element(), 1);
7667 - var import_data13 = __toESM(require_data(), 1);
6909 + var import_data14 = __toESM(require_data(), 1);
7668 6910 var import_blocks5 = __toESM(require_blocks(), 1);
7669 6911
7670 6912 // packages/core-data/build-module/hooks/use-entity-id.mjs
7671 6913 var import_element5 = __toESM(require_element(), 1);
@@ -7674,9 +6916,9 @@
7674 6916 return context?.[kind]?.[name];
7675 6917 }
7676 6918
7677 6919 // packages/core-data/build-module/footnotes/index.mjs
7678 - var import_rich_text4 = __toESM(require_rich_text(), 1);
6920 + var import_rich_text2 = __toESM(require_rich_text(), 1);
7679 6921
7680 6922 // packages/core-data/build-module/footnotes/get-rich-text-values-cached.mjs
7681 6923 var import_block_editor5 = __toESM(require_block_editor(), 1);
7682 6924 var unlockedApis;
@@ -7747,18 +6989,18 @@
7747 6989 if (Array.isArray(value)) {
7748 6990 attributes[key] = value.map(updateAttributes);
7749 6991 continue;
7750 6992 }
7751 - if (typeof value !== "string" && !(value instanceof import_rich_text4.RichTextData)) {
6993 + if (typeof value !== "string" && !(value instanceof import_rich_text2.RichTextData)) {
7752 6994 continue;
7753 6995 }
7754 - const richTextValue = typeof value === "string" ? import_rich_text4.RichTextData.fromHTMLString(value) : new import_rich_text4.RichTextData(value);
6996 + const richTextValue = typeof value === "string" ? import_rich_text2.RichTextData.fromHTMLString(value) : new import_rich_text2.RichTextData(value);
7755 6997 let hasFootnotes = false;
7756 6998 richTextValue.replacements.forEach((replacement) => {
7757 6999 if (replacement.type === "core/footnote") {
7758 7000 const id = replacement.attributes["data-fn"];
7759 7001 const index = newOrder.indexOf(id);
7760 - const countValue = (0, import_rich_text4.create)({
7002 + const countValue = (0, import_rich_text2.create)({
7761 7003 html: replacement.innerHTML
7762 7004 });
7763 7005 countValue.text = String(index + 1);
7764 7006 countValue.formats = Array.from(
@@ -7768,9 +7010,9 @@
7768 7010 countValue.replacements = Array.from(
7769 7011 { length: countValue.text.length },
7770 7012 () => countValue.replacements[0]
7771 7013 );
7772 - replacement.innerHTML = (0, import_rich_text4.toHTMLString)({
7014 + replacement.innerHTML = (0, import_rich_text2.toHTMLString)({
7773 7015 value: countValue
7774 7016 });
7775 7017 hasFootnotes = true;
7776 7018 }
@@ -7810,17 +7052,18 @@
7810 7052 }
7811 7053
7812 7054 // packages/core-data/build-module/hooks/use-entity-block-editor.mjs
7813 7055 var EMPTY_ARRAY2 = [];
7056 + var parsedBlocksCache = /* @__PURE__ */ new Map();
7814 7057 function useEntityBlockEditor(kind, name, { id: _id } = {}) {
7815 7058 const providerId = useEntityId(kind, name);
7816 7059 const id = _id ?? providerId;
7817 - const { content, editedBlocks, meta } = (0, import_data13.useSelect)(
7818 - (select4) => {
7060 + const { content, editedBlocks, meta } = (0, import_data14.useSelect)(
7061 + (select5) => {
7819 7062 if (!id) {
7820 7063 return {};
7821 7064 }
7822 - const { getEditedEntityRecord: getEditedEntityRecord3 } = select4(STORE_NAME);
7065 + const { getEditedEntityRecord: getEditedEntityRecord3 } = select5(STORE_NAME);
7823 7066 const editedRecord = getEditedEntityRecord3(kind, name, id);
7824 7067 return {
7825 7068 editedBlocks: editedRecord.blocks,
7826 7069 content: editedRecord.content,
@@ -7828,9 +7071,9 @@
7828 7071 };
7829 7072 },
7830 7073 [kind, name, id]
7831 7074 );
7832 - const { __unstableCreateUndoLevel: __unstableCreateUndoLevel2, editEntityRecord: editEntityRecord2 } = (0, import_data13.useDispatch)(STORE_NAME);
7075 + const { __unstableCreateUndoLevel: __unstableCreateUndoLevel2, editEntityRecord: editEntityRecord2 } = (0, import_data14.useDispatch)(STORE_NAME);
7833 7076 const blocks = (0, import_element6.useMemo)(() => {
7834 7077 if (!id) {
7835 7078 return void 0;
7836 7079 }
@@ -7839,9 +7082,9 @@
7839 7082 }
7840 7083 if (!content || typeof content !== "string") {
7841 7084 return EMPTY_ARRAY2;
7842 7085 }
7843 - const cacheKey = getCacheKey(kind, name, id);
7086 + const cacheKey = `${kind}:${name}:${id}`;
7844 7087 const cached = parsedBlocksCache.get(cacheKey);
7845 7088 let _blocks;
7846 7089 if (cached && cached.content === content) {
7847 7090 _blocks = cached.blocks;
@@ -7896,41 +7139,15 @@
7896 7139 }
7897 7140
7898 7141 // packages/core-data/build-module/hooks/use-entity-prop.mjs
7899 7142 var import_element7 = __toESM(require_element(), 1);
7900 - var import_data14 = __toESM(require_data(), 1);
7143 + var import_data15 = __toESM(require_data(), 1);
7901 7144 function useEntityProp(kind, name, prop, _id) {
7902 7145 const providerId = useEntityId(kind, name);
7903 7146 const id = _id ?? providerId;
7904 - const context = (0, import_element7.useContext)(EntityContext);
7905 - const revisionId = context?.revisionId;
7906 - const { value, fullValue } = (0, import_data14.useSelect)(
7907 - (select4) => {
7908 - if (revisionId) {
7909 - const revisions = select4(STORE_NAME).getRevisions(
7910 - kind,
7911 - name,
7912 - id,
7913 - {
7914 - per_page: -1,
7915 - context: "edit",
7916 - _fields: "id,date,author,meta,title.raw,excerpt.raw,content.raw"
7917 - }
7918 - );
7919 - const entityConfig = select4(STORE_NAME).getEntityConfig(
7920 - kind,
7921 - name
7922 - );
7923 - const revKey = entityConfig?.revisionKey || DEFAULT_ENTITY_KEY;
7924 - const revision = revisions?.find(
7925 - (r) => r[revKey] === revisionId
7926 - );
7927 - return revision ? {
7928 - value: revision[prop]?.raw ?? revision[prop],
7929 - fullValue: revision[prop]
7930 - } : {};
7931 - }
7932 - const { getEntityRecord: getEntityRecord3, getEditedEntityRecord: getEditedEntityRecord3 } = select4(STORE_NAME);
7147 + const { value, fullValue } = (0, import_data15.useSelect)(
7148 + (select5) => {
7149 + const { getEntityRecord: getEntityRecord3, getEditedEntityRecord: getEditedEntityRecord3 } = select5(STORE_NAME);
7933 7150 const record = getEntityRecord3(kind, name, id);
7934 7151 const editedRecord = getEditedEntityRecord3(kind, name, id);
7935 7152 return record && editedRecord ? {
7936 7153 value: editedRecord[prop],
@@ -7936,32 +7153,27 @@
7936 7153 value: editedRecord[prop],
7937 7154 fullValue: record[prop]
7938 7155 } : {};
7939 7156 },
7940 - [kind, name, id, prop, revisionId]
7157 + [kind, name, id, prop]
7941 7158 );
7942 - const { editEntityRecord: editEntityRecord2 } = (0, import_data14.useDispatch)(STORE_NAME);
7159 + const { editEntityRecord: editEntityRecord2 } = (0, import_data15.useDispatch)(STORE_NAME);
7943 7160 const setValue = (0, import_element7.useCallback)(
7944 7161 (newValue) => {
7945 - if (revisionId) {
7946 - return;
7947 - }
7948 7162 editEntityRecord2(kind, name, id, {
7949 7163 [prop]: newValue
7950 7164 });
7951 7165 },
7952 - [editEntityRecord2, kind, name, id, prop, revisionId]
7166 + [editEntityRecord2, kind, name, id, prop]
7953 7167 );
7954 7168 return [value, setValue, fullValue];
7955 7169 }
7956 7170
7957 7171 // packages/core-data/build-module/hooks/use-post-editor-awareness-state.mjs
7958 - var import_compose3 = __toESM(require_compose(), 1);
7959 7172 var import_element8 = __toESM(require_element(), 1);
7960 7173 var defaultResolvedSelection = {
7961 - richTextOffset: null,
7962 - localClientId: null,
7963 - attributeKey: null
7174 + textIndex: null,
7175 + localClientId: null
7964 7176 };
7965 7177 var defaultState = {
7966 7178 activeCollaborators: [],
7967 7179 resolveSelection: () => defaultResolvedSelection,
@@ -7975,9 +7187,9 @@
7975 7187 function getAwarenessState(awareness, newState) {
7976 7188 const activeCollaborators = newState ?? awareness.getCurrentState();
7977 7189 return {
7978 7190 activeCollaborators,
7979 - resolveSelection: (selection, blocks) => awareness.convertSelectionStateToAbsolute(selection, blocks),
7191 + resolveSelection: (selection) => awareness.convertSelectionStateToAbsolute(selection),
7980 7192 getDebugData: () => awareness.getDebugData(),
7981 7193 isCurrentCollaboratorDisconnected: activeCollaborators.find((collaborator) => collaborator.isMe)?.isConnected === false
7982 7194 };
7983 7195 }
@@ -8012,14 +7224,9 @@
8012 7224 function useActiveCollaborators(postId, postType) {
8013 7225 return usePostEditorAwarenessState(postId, postType).activeCollaborators;
8014 7226 }
8015 7227 function useResolvedSelection(postId, postType) {
8016 - const blocks = usePostContentBlocks();
8017 - const awarenessState = usePostEditorAwarenessState(postId, postType);
8018 - return (0, import_element8.useCallback)(
8019 - (selection) => awarenessState.resolveSelection(selection, blocks),
8020 - [blocks, awarenessState]
8021 - );
7228 + return usePostEditorAwarenessState(postId, postType).resolveSelection;
8022 7229 }
8023 7230 function useLastPostSave(postId, postType) {
8024 7231 const [lastSave, setLastSave] = (0, import_element8.useState)(null);
8025 7232 (0, import_element8.useEffect)(() => {
@@ -8055,100 +7262,19 @@
8055 7262 };
8056 7263 }, [postId, postType]);
8057 7264 return lastSave;
8058 7265 }
8059 - function useOnCollaboratorJoin(postId, postType, callback) {
8060 - const { activeCollaborators } = usePostEditorAwarenessState(
8061 - postId,
8062 - postType
8063 - );
8064 - const prevCollaborators = (0, import_compose3.usePrevious)(activeCollaborators);
8065 - (0, import_element8.useEffect)(() => {
8066 - if (!prevCollaborators || prevCollaborators.length === 0) {
8067 - return;
8068 - }
8069 - const prevMap = new Map(
8070 - prevCollaborators.map((collaborator) => [
8071 - collaborator.clientId,
8072 - collaborator
8073 - ])
8074 - );
8075 - const me = activeCollaborators.find(
8076 - (collaborator) => collaborator.isMe
8077 - );
8078 - for (const collaborator of activeCollaborators) {
8079 - if (!prevMap.has(collaborator.clientId) && !collaborator.isMe) {
8080 - callback(collaborator, me);
8081 - }
8082 - }
8083 - }, [activeCollaborators, prevCollaborators, callback]);
8084 - }
8085 - function useOnCollaboratorLeave(postId, postType, callback) {
8086 - const { activeCollaborators } = usePostEditorAwarenessState(
8087 - postId,
8088 - postType
8089 - );
8090 - const prevCollaborators = (0, import_compose3.usePrevious)(activeCollaborators);
8091 - (0, import_element8.useEffect)(() => {
8092 - if (!prevCollaborators || prevCollaborators.length === 0) {
8093 - return;
8094 - }
8095 - const newMap = new Map(
8096 - activeCollaborators.map((collaborator) => [
8097 - collaborator.clientId,
8098 - collaborator
8099 - ])
8100 - );
8101 - for (const prevCollab of prevCollaborators) {
8102 - if (prevCollab.isMe || !prevCollab.isConnected) {
8103 - continue;
8104 - }
8105 - const newCollab = newMap.get(prevCollab.clientId);
8106 - if (!newCollab?.isConnected) {
8107 - callback(prevCollab);
8108 - }
8109 - }
8110 - }, [activeCollaborators, prevCollaborators, callback]);
8111 - }
8112 - function useOnPostSave(postId, postType, callback) {
8113 - const { activeCollaborators } = usePostEditorAwarenessState(
8114 - postId,
8115 - postType
8116 - );
8117 - const lastPostSave = useLastPostSave(postId, postType);
8118 - const prevPostSave = (0, import_compose3.usePrevious)(lastPostSave);
8119 - (0, import_element8.useEffect)(() => {
8120 - if (!lastPostSave) {
8121 - return;
8122 - }
8123 - if (prevPostSave && lastPostSave.savedAt === prevPostSave.savedAt) {
8124 - return;
8125 - }
8126 - const saver = activeCollaborators.find(
8127 - (collaborator) => collaborator.clientId === lastPostSave.savedByClientId && !collaborator.isMe
8128 - );
8129 - if (!saver) {
8130 - return;
8131 - }
8132 - callback(lastPostSave, saver, prevPostSave ?? null);
8133 - }, [lastPostSave, prevPostSave, activeCollaborators, callback]);
8134 - }
8135 7266
8136 7267 // packages/core-data/build-module/private-apis.mjs
8137 - var lockedApis = {
7268 + var privateApis = {};
7269 + lock(privateApis, {
8138 7270 useEntityRecordsWithPermissions,
8139 7271 RECEIVE_INTERMEDIATE_RESULTS,
8140 7272 retrySyncConnection,
8141 7273 useActiveCollaborators,
8142 7274 useResolvedSelection,
8143 - useOnCollaboratorJoin,
8144 - useOnCollaboratorLeave,
8145 - useOnPostSave,
8146 - SelectionType,
8147 - SelectionDirection
8148 - };
8149 - var privateApis = {};
8150 - lock(privateApis, lockedApis);
7275 + useLastPostSave
7276 + });
8151 7277
8152 7278 // packages/core-data/build-module/index.mjs
8153 7279 var entitiesConfig2 = [
8154 7280 ...rootEntitiesConfig,
@@ -8233,11 +7359,11 @@
8233 7359 ...entitySelectors
8234 7360 },
8235 7361 resolvers: { ...resolvers_exports, ...entityResolvers }
8236 7362 });
8237 - var store = (0, import_data15.createReduxStore)(STORE_NAME, storeConfig());
7363 + var store = (0, import_data16.createReduxStore)(STORE_NAME, storeConfig());
8238 7364 unlock(store).registerPrivateSelectors(private_selectors_exports);
8239 7365 unlock(store).registerPrivateActions(private_actions_exports);
8240 - (0, import_data15.register)(store);
7366 + (0, import_data16.register)(store);
8241 7367 return __toCommonJS(index_exports);
8242 7368 })();
8243 7369 //# sourceMappingURL=index.js.map