PluginProbe
Gutenberg / 24.1.0
Gutenberg v24.1.0
24.1.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 All 404 releases
← All changes | build/scripts/core-data/index.js +1415 -413 23.6.0 → 24.1.0 View file →
@@ -1,4 +1,5 @@
1 +(function() {
1 2 "use strict";
2 3 var wp;
3 4 (wp ||= {}).coreData = (() => {
4 5 var __create = Object.create;
@@ -384,8 +385,15 @@
384 385 module.exports = window.wp.deprecated;
385 386 }
386 387 });
387 388
389 + // package-external:@wordpress/notices
390 + var require_notices = __commonJS({
391 + "package-external:@wordpress/notices"(exports, module) {
392 + module.exports = window.wp.notices;
393 + }
394 + });
395 +
388 396 // package-external:@wordpress/html-entities
389 397 var require_html_entities = __commonJS({
390 398 "package-external:@wordpress/html-entities"(exports, module) {
391 399 module.exports = window.wp.htmlEntities;
@@ -412,8 +420,22 @@
412 420 module.exports = window.wp.warning;
413 421 }
414 422 });
415 423
424 + // package-external:@wordpress/primitives
425 + var require_primitives = __commonJS({
426 + "package-external:@wordpress/primitives"(exports, module) {
427 + module.exports = window.wp.primitives;
428 + }
429 + });
430 +
431 + // package-external:@wordpress/components
432 + var require_components = __commonJS({
433 + "package-external:@wordpress/components"(exports, module) {
434 + module.exports = window.wp.components;
435 + }
436 + });
437 +
416 438 // packages/core-data/build-module/index.mjs
417 439 var index_exports = {};
418 440 __export(index_exports, {
419 441 EntityProvider: () => EntityProvider,
@@ -431,9 +453,9 @@
431 453 useEntityRecord: () => useEntityRecord,
432 454 useEntityRecords: () => useEntityRecords,
433 455 useResourcePermissions: () => use_resource_permissions_default
434 456 });
435 - var import_data15 = __toESM(require_data(), 1);
457 + var import_data20 = __toESM(require_data(), 1);
436 458
437 459 // packages/core-data/build-module/reducer.mjs
438 460 var import_es65 = __toESM(require_es6(), 1);
439 461 var import_compose2 = __toESM(require_compose(), 1);
@@ -494,8 +516,58 @@
494 516 return null;
495 517 }
496 518 var get_normalized_comma_separable_default = getNormalizedCommaSeparable;
497 519
520 + // packages/core-data/build-module/utils/set-nested-value.mjs
521 + function setNestedValue(object, path, value) {
522 + if (!object || typeof object !== "object") {
523 + return object;
524 + }
525 + const normalizedPath = Array.isArray(path) ? path : path.split(".");
526 + normalizedPath.reduce((acc, key, idx) => {
527 + if (acc[key] === void 0) {
528 + if (Number.isInteger(normalizedPath[idx + 1])) {
529 + acc[key] = [];
530 + } else {
531 + acc[key] = {};
532 + }
533 + }
534 + if (idx === normalizedPath.length - 1) {
535 + acc[key] = value;
536 + }
537 + return acc[key];
538 + }, object);
539 + return object;
540 + }
541 +
542 + // packages/core-data/build-module/utils/get-filtered-item.mjs
543 + var filteredItemCache = /* @__PURE__ */ new WeakMap();
544 + function getFilteredItem(item, _fields) {
545 + const fields = get_normalized_comma_separable_default(_fields) ?? [];
546 + const fieldsKey = fields.join(",");
547 + let itemCache = filteredItemCache.get(item);
548 + if (itemCache) {
549 + const filtered = itemCache.get(fieldsKey);
550 + if (filtered !== void 0) {
551 + return filtered;
552 + }
553 + } else if (item !== null && typeof item === "object") {
554 + itemCache = /* @__PURE__ */ new Map();
555 + filteredItemCache.set(item, itemCache);
556 + }
557 + const filteredItem = {};
558 + for (let f = 0; f < fields.length; f++) {
559 + const field = fields[f].split(".");
560 + let value = item;
561 + field.forEach((fieldName) => {
562 + value = value?.[fieldName];
563 + });
564 + setNestedValue(filteredItem, field, value);
565 + }
566 + itemCache?.set(fieldsKey, filteredItem);
567 + return filteredItem;
568 + }
569 +
498 570 // packages/core-data/build-module/utils/if-matching-action.mjs
499 571 var ifMatchingAction = (isMatch) => (reducer) => (state, action) => {
500 572 if (state === void 0 || isMatch(action)) {
501 573 return reducer(state, action);
@@ -533,30 +605,8 @@
533 605 };
534 606 }
535 607 var with_weak_map_cache_default = withWeakMapCache;
536 608
537 - // packages/core-data/build-module/utils/set-nested-value.mjs
538 - function setNestedValue(object, path, value) {
539 - if (!object || typeof object !== "object") {
540 - return object;
541 - }
542 - const normalizedPath = Array.isArray(path) ? path : path.split(".");
543 - normalizedPath.reduce((acc, key, idx) => {
544 - if (acc[key] === void 0) {
545 - if (Number.isInteger(normalizedPath[idx + 1])) {
546 - acc[key] = [];
547 - } else {
548 - acc[key] = {};
549 - }
550 - }
551 - if (idx === normalizedPath.length - 1) {
552 - acc[key] = value;
553 - }
554 - return acc[key];
555 - }, object);
556 - return object;
557 - }
558 -
559 609 // packages/core-data/build-module/utils/get-nested-value.mjs
560 610 function getNestedValue(object, path, defaultValue) {
561 611 if (!object || typeof object !== "object" || typeof path !== "string" && !Array.isArray(path)) {
562 612 return object;
@@ -638,13 +688,17 @@
638 688 LOCAL_EDITOR_ORIGIN,
639 689 LOCAL_UNDO_IGNORED_ORIGIN,
640 690 retrySyncConnection
641 691 } = unlock(import_sync.privateApis);
692 + var CRDT_AUTOSAVE_SNAPSHOT_KEY = "crdt_snapshot";
642 693 var syncManager;
643 694 function getSyncManager() {
644 695 if (syncManager) {
645 696 return syncManager;
646 697 }
698 + if (!globalThis.window?.__experimentalEnableRealTimeCollaboration) {
699 + return void 0;
700 + }
647 701 syncManager = createSyncManager();
648 702 return syncManager;
649 703 }
650 704 function hasSyncManager() {
@@ -649,8 +703,27 @@
649 703 }
650 704 function hasSyncManager() {
651 705 return Boolean(syncManager);
652 706 }
707 + function getEntitySnapshot(kind, name, recordId) {
708 + if (!hasSyncManager()) {
709 + return void 0;
710 + }
711 + return getSyncManager()?.getEntitySnapshot(
712 + `${kind}/${name}`,
713 + `${recordId}`
714 + );
715 + }
716 + function entityContainsSnapshot(kind, name, recordId, encodedSnapshot) {
717 + if (!hasSyncManager()) {
718 + return false;
719 + }
720 + return getSyncManager()?.entityContainsSnapshot(
721 + `${kind}/${name}`,
722 + `${recordId}`,
723 + encodedSnapshot
724 + ) ?? false;
725 + }
653 726
654 727 // packages/core-data/build-module/utils/save-crdt-doc.mjs
655 728 var SYNC_SAVE_API_PATH = "/wp-sync/v1/save";
656 729 var saveCRDTDocQueues = /* @__PURE__ */ new Map();
@@ -685,8 +758,18 @@
685 758 }
686 759 }
687 760 }
688 761
762 + // packages/core-data/build-module/utils/get-pagination-meta.mjs
763 + function getPaginationMeta(headers) {
764 + const totalItems = parseInt(headers.get("X-WP-Total") ?? "");
765 + const totalPages = parseInt(headers.get("X-WP-TotalPages") ?? "");
766 + return {
767 + totalItems: Number.isFinite(totalItems) ? totalItems : null,
768 + totalPages: Number.isFinite(totalPages) ? totalPages : null
769 + };
770 + }
771 +
689 772 // packages/core-data/build-module/queried-data/actions.mjs
690 773 function receiveItems(items2, edits, meta) {
691 774 return {
692 775 type: "RECEIVE_ITEMS",
@@ -1005,18 +1088,49 @@
1005 1088 return Object.entries(collaboratorInfo1).every(([key, value]) => {
1006 1089 return value === collaboratorInfo2[key];
1007 1090 });
1008 1091 }
1009 - function generateCollaboratorInfo(currentCollaborator) {
1010 - const { avatar_urls, id, name, slug } = currentCollaborator;
1092 + function hasValidAvatarUrls(value) {
1093 + if ("object" !== typeof value || null === value || Array.isArray(value)) {
1094 + return false;
1095 + }
1096 + return ["24", "48", "96"].every(
1097 + (size) => !(size in value) || "string" === typeof value[size]
1098 + );
1099 + }
1100 + function isCollaboratorInfo(value) {
1101 + if ("object" !== typeof value || null === value) {
1102 + return false;
1103 + }
1104 + return "id" in value && "name" in value && "slug" in value && "browserType" in value && "enteredAt" in value && (null === value.id || "number" === typeof value.id && Number.isInteger(value.id) && value.id > 0) && "string" === typeof value.name && "" !== value.name.trim() && "string" === typeof value.slug && (!("avatar_urls" in value) || hasValidAvatarUrls(value.avatar_urls)) && "string" === typeof value.browserType && "number" === typeof value.enteredAt && Number.isFinite(value.enteredAt);
1105 + }
1106 + function generateCollaboratorInfo(currentCollaborator, clientId) {
1107 + const presentationInfo = {
1108 + browserType: getBrowserName(),
1109 + enteredAt: Date.now()
1110 + };
1111 + if ("object" === typeof currentCollaborator && currentCollaborator) {
1112 + const user = currentCollaborator;
1113 + if ("id" in user && "name" in user) {
1114 + const collaboratorInfo = {
1115 + ...presentationInfo,
1116 + ..."avatar_urls" in user && hasValidAvatarUrls(user.avatar_urls) ? { avatar_urls: user.avatar_urls } : {},
1117 + id: user.id,
1118 + name: user.name,
1119 + slug: "slug" in user && "string" === typeof user.slug ? user.slug : ""
1120 + };
1121 + if (isCollaboratorInfo(collaboratorInfo) && null !== collaboratorInfo.id) {
1122 + return collaboratorInfo;
1123 + }
1124 + }
1125 + }
1011 1126 return {
1012 - avatar_urls,
1013 - // eslint-disable-line camelcase
1014 - browserType: getBrowserName(),
1015 - enteredAt: Date.now(),
1016 - id,
1017 - name,
1018 - slug
1127 + ...presentationInfo,
1128 + id: null,
1129 + // Keep shared awareness data language-neutral. The editor localizes this
1130 + // fallback name for the viewer when it is displayed.
1131 + name: "Anonymous User",
1132 + slug: `anonymous-${clientId}`
1019 1133 };
1020 1134 }
1021 1135 function getRecordValue(obj, key) {
1022 1136 if ("object" === typeof obj && null !== obj && key in obj) {
@@ -1301,11 +1415,17 @@
1301 1415 /**
1302 1416 * Set the current collaborator info in the local state.
1303 1417 */
1304 1418 async setCurrentCollaboratorInfo() {
1305 - const currentUser2 = await (0, import_data.resolveSelect)(STORE_NAME).getCurrentUser();
1306 - const collaboratorInfo = generateCollaboratorInfo(currentUser2);
1307 - this.setLocalStateField("collaboratorInfo", collaboratorInfo);
1419 + let currentUser2;
1420 + try {
1421 + currentUser2 = await (0, import_data.resolveSelect)(STORE_NAME).getCurrentUser();
1422 + } catch {
1423 + }
1424 + this.setLocalStateField(
1425 + "collaboratorInfo",
1426 + generateCollaboratorInfo(currentUser2, this.clientID)
1427 + );
1308 1428 }
1309 1429 };
1310 1430 var baseEqualityFieldChecks = {
1311 1431 collaboratorInfo: areCollaboratorInfosEqual
@@ -1373,11 +1493,11 @@
1373 1493 }
1374 1494 return null;
1375 1495 }
1376 1496 function usePostContentBlocks() {
1377 - return (0, import_data2.useSelect)((select4) => {
1497 + return (0, import_data2.useSelect)((select5) => {
1378 1498 const { getBlocksByName, getClientIdsTree } = unlock(
1379 - select4(import_block_editor.store)
1499 + select5(import_block_editor.store)
1380 1500 );
1381 1501 const [postContentClientId] = getBlocksByName("core/post-content");
1382 1502 return getClientIdsTree(postContentClientId ?? "");
1383 1503 }, []);
@@ -1549,32 +1669,32 @@
1549 1669 type: "cursor",
1550 1670 cursorPosition
1551 1671 };
1552 1672 } else if (isSelectionInOneBlock) {
1553 - const cursorStartPosition2 = getCursorPosition(
1673 + const cursorStartPosition = getCursorPosition(
1554 1674 selectionStart,
1555 1675 yBlocks
1556 1676 );
1557 - const cursorEndPosition2 = getCursorPosition(selectionEnd, yBlocks);
1558 - if (!cursorStartPosition2 || !cursorEndPosition2) {
1677 + const cursorEndPosition = getCursorPosition(selectionEnd, yBlocks);
1678 + if (!cursorStartPosition || !cursorEndPosition) {
1559 1679 return noSelection;
1560 1680 }
1561 1681 return {
1562 1682 type: "selection-in-one-block",
1563 - cursorStartPosition: cursorStartPosition2,
1564 - cursorEndPosition: cursorEndPosition2,
1683 + cursorStartPosition,
1684 + cursorEndPosition,
1565 1685 selectionDirection
1566 1686 };
1567 1687 }
1568 - const cursorStartPosition = getCursorPosition(selectionStart, yBlocks);
1569 - const cursorEndPosition = getCursorPosition(selectionEnd, yBlocks);
1570 - if (!cursorStartPosition || !cursorEndPosition) {
1688 + const startEndpoint = getSelectionEndpoint(selectionStart, yBlocks);
1689 + const endEndpoint = getSelectionEndpoint(selectionEnd, yBlocks);
1690 + if (!startEndpoint || !endEndpoint) {
1571 1691 return noSelection;
1572 1692 }
1573 1693 return {
1574 1694 type: "selection-in-multiple-blocks",
1575 - cursorStartPosition,
1576 - cursorEndPosition,
1695 + startEndpoint,
1696 + endEndpoint,
1577 1697 selectionDirection
1578 1698 };
1579 1699 }
1580 1700 function getCursorPosition(selection, blocks) {
@@ -1600,8 +1720,20 @@
1600 1720 absoluteOffset: selection.offset,
1601 1721 attributeKey: selection.attributeKey
1602 1722 };
1603 1723 }
1724 + function getSelectionEndpoint(selection, blocks) {
1725 + const cursorPosition = getCursorPosition(selection, blocks);
1726 + if (cursorPosition) {
1727 + return { type: "cursor", cursorPosition };
1728 + }
1729 + const path = getBlockPathForLocalClientId(selection.clientId);
1730 + const blockPosition = path ? createRelativePositionForBlockPath(path, blocks) : null;
1731 + if (blockPosition) {
1732 + return { type: "whole-block", blockPosition };
1733 + }
1734 + return null;
1735 + }
1604 1736 function getBlockPathForLocalClientId(clientId) {
1605 1737 const { getBlockIndex, getBlockRootClientId, getBlockName } = (0, import_data3.select)(import_block_editor2.store);
1606 1738 const path = [];
1607 1739 let current = clientId;
@@ -1677,14 +1809,14 @@
1677 1809 selection1.cursorEndPosition,
1678 1810 selection2.cursorEndPosition
1679 1811 ) && selection1.selectionDirection === selection2.selectionDirection;
1680 1812 case "selection-in-multiple-blocks":
1681 - return areCursorPositionsEqual(
1682 - selection1.cursorStartPosition,
1683 - selection2.cursorStartPosition
1684 - ) && areCursorPositionsEqual(
1685 - selection1.cursorEndPosition,
1686 - selection2.cursorEndPosition
1813 + return areEndpointsEqual(
1814 + selection1.startEndpoint,
1815 + selection2.startEndpoint
1816 + ) && areEndpointsEqual(
1817 + selection1.endEndpoint,
1818 + selection2.endEndpoint
1687 1819 ) && selection1.selectionDirection === selection2.selectionDirection;
1688 1820 case "whole-block":
1689 1821 return import_sync7.Y.compareRelativePositions(
1690 1822 selection1.blockPosition,
@@ -1693,8 +1825,23 @@
1693 1825 default:
1694 1826 return false;
1695 1827 }
1696 1828 }
1829 + function areEndpointsEqual(ep1, ep2) {
1830 + if (ep1.type !== ep2.type) {
1831 + return false;
1832 + }
1833 + if (ep1.type === "cursor" && ep2.type === "cursor") {
1834 + return areCursorPositionsEqual(
1835 + ep1.cursorPosition,
1836 + ep2.cursorPosition
1837 + );
1838 + }
1839 + return import_sync7.Y.compareRelativePositions(
1840 + ep1.blockPosition,
1841 + ep2.blockPosition
1842 + );
1843 + }
1697 1844 function areCursorPositionsEqual(cursorPosition1, cursorPosition2) {
1698 1845 const isRelativePositionEqual = import_sync7.Y.compareRelativePositions(
1699 1846 cursorPosition1.relativePosition,
1700 1847 cursorPosition2.relativePosition
@@ -1862,8 +2009,15 @@
1862 2009 localClientId: localClientId2,
1863 2010 attributeKey: null
1864 2011 };
1865 2012 }
2013 + if (selection.type === SelectionType.SelectionInMultipleBlocks) {
2014 + return {
2015 + richTextOffset: null,
2016 + localClientId: null,
2017 + attributeKey: null
2018 + };
2019 + }
1866 2020 const cursorPos = "cursorPosition" in selection ? selection.cursorPosition : selection.cursorStartPosition;
1867 2021 const absolutePosition = import_sync9.Y.createAbsolutePositionFromRelativePosition(
1868 2022 cursorPos.relativePosition,
1869 2023 this.doc
@@ -1908,17 +2062,17 @@
1908 2062 value.toJSON()
1909 2063 ])
1910 2064 );
1911 2065 const collaboratorMapData = new Map(
1912 - Array.from(this.getSeenStates().entries()).map(
1913 - ([clientId, collaboratorState]) => [
1914 - String(clientId),
1915 - {
1916 - name: collaboratorState.collaboratorInfo.name,
1917 - wpUserId: collaboratorState.collaboratorInfo.id
1918 - }
1919 - ]
1920 - )
2066 + Array.from(this.getSeenStates().entries()).filter(
2067 + ([, collaboratorState]) => isCollaboratorInfo(collaboratorState.collaboratorInfo)
2068 + ).map(([clientId, collaboratorState]) => [
2069 + String(clientId),
2070 + {
2071 + name: collaboratorState.collaboratorInfo.name,
2072 + wpUserId: collaboratorState.collaboratorInfo.id
2073 + }
2074 + ])
1921 2075 );
1922 2076 const serializableClientItems = {};
1923 2077 ydoc.store.clients.forEach((structs, clientId) => {
1924 2078 const items2 = structs.filter(this.isYItem);
@@ -3179,9 +3333,9 @@
3179 3333 baseURLParams: { context: "edit" },
3180 3334 plural: "comments",
3181 3335 label: (0, import_i18n.__)("Comment"),
3182 3336 supportsPagination: true,
3183 - syncConfig: defaultCollectionSyncConfig
3337 + ...globalThis.window?.__experimentalEnableRealTimeCollaboration ? { syncConfig: defaultCollectionSyncConfig } : {}
3184 3338 },
3185 3339 {
3186 3340 name: "menu",
3187 3341 kind: "root",
@@ -3253,16 +3407,8 @@
3253 3407 key: "slug",
3254 3408 supportsPagination: false
3255 3409 },
3256 3410 {
3257 - label: (0, import_i18n.__)("Registered Templates"),
3258 - name: "registeredTemplate",
3259 - kind: "root",
3260 - baseURL: "/wp/v2/registered-templates",
3261 - key: "id",
3262 - supportsPagination: false
3263 - },
3264 - {
3265 3411 label: (0, import_i18n.__)("Font Collections"),
3266 3412 name: "fontCollection",
3267 3413 kind: "root",
3268 3414 baseURL: "/wp/v2/font-collections",
@@ -3322,9 +3468,9 @@
3322 3468 if ((!edits.title || edits.title === "Auto Draft") && !newEdits.title && (!persistedRecord?.title || persistedRecord?.title === "Auto Draft")) {
3323 3469 newEdits.title = "";
3324 3470 }
3325 3471 }
3326 - if (persistedRecord) {
3472 + if (window.__experimentalEnableRealTimeCollaboration && persistedRecord) {
3327 3473 const objectType = `postType/${name}`;
3328 3474 const objectId = persistedRecord.id;
3329 3475 const serializedDoc = await getSyncManager()?.createPersistedCRDTDoc(
3330 3476 objectType,
@@ -3340,9 +3486,9 @@
3340 3486 return newEdits;
3341 3487 };
3342 3488 async function loadPostTypeEntities() {
3343 3489 const postTypesPromise = (0, import_api_fetch2.default)({ path: "/wp/v2/types?context=view" });
3344 - const taxonomiesPromise = window._wpCollaborationEnabled ? (0, import_api_fetch2.default)({ path: "/wp/v2/taxonomies?context=view" }) : Promise.resolve({});
3490 + const taxonomiesPromise = window.__experimentalEnableRealTimeCollaboration ? (0, import_api_fetch2.default)({ path: "/wp/v2/taxonomies?context=view" }) : Promise.resolve({});
3345 3491 const [postTypes, taxonomies] = await Promise.all([
3346 3492 postTypesPromise,
3347 3493 taxonomiesPromise
3348 3494 ]);
@@ -3383,12 +3529,17 @@
3383 3529 rawAttributes: POST_RAW_ATTRIBUTES,
3384 3530 getTitle: (record) => record?.title?.rendered || record?.title || (isTemplate ? capitalCase(record.slug ?? "") : String(record.id)),
3385 3531 __unstablePrePersist: (persistedRecord, edits) => prePersistPostType(persistedRecord, edits, name, isTemplate),
3386 3532 __unstable_rest_base: postType.rest_base,
3387 - supportsPagination: true,
3533 + // The templates controller returns the whole collection and never
3534 + // paginates.
3535 + supportsPagination: !isTemplate,
3388 3536 getRevisionsUrl: (parentId, revisionId) => `/${namespace}/${postType.rest_base}/${parentId}/revisions${revisionId ? "/" + revisionId : ""}`,
3389 - revisionKey: isTemplate && !window?.__experimentalTemplateActivate ? "wp_id" : DEFAULT_ENTITY_KEY
3537 + revisionKey: isTemplate ? "wp_id" : DEFAULT_ENTITY_KEY
3390 3538 };
3539 + if (!window.__experimentalEnableRealTimeCollaboration) {
3540 + return entity2;
3541 + }
3391 3542 entity2.syncConfig = {
3392 3543 // Save a CRDT document with this entity
3393 3544 supportsPersistence: true,
3394 3545 /**
@@ -3454,9 +3605,11 @@
3454 3605 label: taxonomy.name,
3455 3606 getTitle: (record) => record?.name,
3456 3607 supportsPagination: true
3457 3608 };
3458 - entity2.syncConfig = defaultSyncConfig;
3609 + if (window.__experimentalEnableRealTimeCollaboration) {
3610 + entity2.syncConfig = defaultSyncConfig;
3611 + }
3459 3612 return entity2;
3460 3613 });
3461 3614 }
3462 3615 async function loadSiteEntity() {
@@ -3631,8 +3784,29 @@
3631 3784 ),
3632 3785 meta: action.meta
3633 3786 };
3634 3787 });
3788 + function removeQueryItems(queryItems, removedItems) {
3789 + const itemIds = queryItems.itemIds.filter(
3790 + (itemId) => !removedItems[itemId]
3791 + );
3792 + const removedCount = queryItems.itemIds.length - itemIds.length;
3793 + if (removedCount === 0) {
3794 + return queryItems;
3795 + }
3796 + const nextQueryItems = { ...queryItems, itemIds };
3797 + if (Number.isFinite(queryItems.meta?.totalItems)) {
3798 + nextQueryItems.meta = {
3799 + ...queryItems.meta,
3800 + totalItems: Math.max(
3801 + 0,
3802 + queryItems.meta.totalItems - removedCount
3803 + ),
3804 + totalPages: null
3805 + };
3806 + }
3807 + return nextQueryItems;
3808 + }
3635 3809 var queries = (state = {}, action) => {
3636 3810 switch (action.type) {
3637 3811 case "RECEIVE_ITEMS":
3638 3812 return receiveQueries(state, action);
@@ -3648,14 +3822,12 @@
3648 3822 Object.fromEntries(
3649 3823 Object.entries(contextQueries).map(
3650 3824 ([query, queryItems]) => [
3651 3825 query,
3652 - {
3653 - ...queryItems,
3654 - itemIds: queryItems.itemIds.filter(
3655 - (queryId) => !removedItems[queryId]
3656 - )
3657 - }
3826 + removeQueryItems(
3827 + queryItems,
3828 + removedItems
3829 + )
3658 3830 ]
3659 3831 )
3660 3832 )
3661 3833 ]
@@ -4217,8 +4389,9 @@
4217 4389 getEditorAssets: () => getEditorAssets,
4218 4390 getEditorSettings: () => getEditorSettings,
4219 4391 getEntityRecordPermissions: () => getEntityRecordPermissions,
4220 4392 getEntityRecordsPermissions: () => getEntityRecordsPermissions,
4393 + getEntitySyncConnectionStatus: () => getEntitySyncConnectionStatus,
4221 4394 getHomePage: () => getHomePage,
4222 4395 getNavigationFallbackId: () => getNavigationFallbackId,
4223 4396 getPostsPageId: () => getPostsPageId,
4224 4397 getRegisteredPostMeta: () => getRegisteredPostMeta,
@@ -4267,26 +4440,26 @@
4267 4440 function getNavigationFallbackId(state) {
4268 4441 return state.navigationFallbackId;
4269 4442 }
4270 4443 var getBlockPatternsForPostType = (0, import_data8.createRegistrySelector)(
4271 - (select4) => (0, import_data8.createSelector)(
4272 - (state, postType) => select4(STORE_NAME).getBlockPatterns().filter(
4444 + (select5) => (0, import_data8.createSelector)(
4445 + (state, postType) => select5(STORE_NAME).getBlockPatterns().filter(
4273 4446 ({ postTypes }) => !postTypes || Array.isArray(postTypes) && postTypes.includes(postType)
4274 4447 ),
4275 - () => [select4(STORE_NAME).getBlockPatterns()]
4448 + () => [select5(STORE_NAME).getBlockPatterns()]
4276 4449 )
4277 4450 );
4278 4451 var getEntityRecordsPermissions = (0, import_data8.createRegistrySelector)(
4279 - (select4) => (0, import_data8.createSelector)(
4452 + (select5) => (0, import_data8.createSelector)(
4280 4453 (state, kind, name, ids) => {
4281 4454 const normalizedIds = Array.isArray(ids) ? ids : [ids];
4282 4455 return normalizedIds.map((id) => ({
4283 - delete: select4(STORE_NAME).canUser("delete", {
4456 + delete: select5(STORE_NAME).canUser("delete", {
4284 4457 kind,
4285 4458 name,
4286 4459 id
4287 4460 }),
4288 - update: select4(STORE_NAME).canUser("update", {
4461 + update: select5(STORE_NAME).canUser("update", {
4289 4462 kind,
4290 4463 name,
4291 4464 id
4292 4465 })
@@ -4311,11 +4484,11 @@
4311 4484 }
4312 4485 return value.toString();
4313 4486 }
4314 4487 var getHomePage = (0, import_data8.createRegistrySelector)(
4315 - (select4) => (0, import_data8.createSelector)(
4488 + (select5) => (0, import_data8.createSelector)(
4316 4489 () => {
4317 - const siteData = select4(STORE_NAME).getEntityRecord(
4490 + const siteData = select5(STORE_NAME).getEntityRecord(
4318 4491 "root",
4319 4492 "__unstableBase"
4320 4493 );
4321 4494 if (!siteData) {
@@ -4324,9 +4497,9 @@
4324 4497 const homepageId = siteData?.show_on_front === "page" ? normalizePageId(siteData.page_on_front) : null;
4325 4498 if (homepageId) {
4326 4499 return { postType: "page", postId: homepageId };
4327 4500 }
4328 - const frontPageTemplateId = select4(
4501 + const frontPageTemplateId = select5(
4329 4502 STORE_NAME
4330 4503 ).getDefaultTemplateId({
4331 4504 slug: "front-page"
4332 4505 });
@@ -4351,10 +4524,10 @@
4351 4524 })
4352 4525 ]
4353 4526 )
4354 4527 );
4355 - var getPostsPageId = (0, import_data8.createRegistrySelector)((select4) => () => {
4356 - const siteData = select4(STORE_NAME).getEntityRecord(
4528 + var getPostsPageId = (0, import_data8.createRegistrySelector)((select5) => () => {
4529 + const siteData = select5(STORE_NAME).getEntityRecord(
4357 4530 "root",
4358 4531 "__unstableBase"
4359 4532 );
4360 4533 return siteData?.show_on_front === "page" ? normalizePageId(siteData.page_for_posts) : null;
@@ -4359,15 +4532,15 @@
4359 4532 );
4360 4533 return siteData?.show_on_front === "page" ? normalizePageId(siteData.page_for_posts) : null;
4361 4534 });
4362 4535 var getTemplateId = (0, import_data8.createRegistrySelector)(
4363 - (select4) => (state, postType, postId) => {
4364 - const homepage = unlock(select4(STORE_NAME)).getHomePage();
4536 + (select5) => (state, postType, postId) => {
4537 + const homepage = unlock(select5(STORE_NAME)).getHomePage();
4365 4538 if (!homepage) {
4366 4539 return;
4367 4540 }
4368 4541 if (postType === "page" && postType === homepage?.postType && postId.toString() === homepage?.postId) {
4369 - const templates = select4(STORE_NAME).getEntityRecords(
4542 + const templates = select5(STORE_NAME).getEntityRecords(
4370 4543 "postType",
4371 4544 "wp_template",
4372 4545 {
4373 4546 per_page: -1
@@ -4375,14 +4548,16 @@
4375 4548 );
4376 4549 if (!templates) {
4377 4550 return;
4378 4551 }
4379 - const id = templates.find(({ slug }) => slug === "front-page")?.id;
4552 + const id = templates.find(
4553 + ({ slug }) => slug === "front-page"
4554 + )?.id;
4380 4555 if (id) {
4381 4556 return id;
4382 4557 }
4383 4558 }
4384 - const editedEntity = select4(STORE_NAME).getEditedEntityRecord(
4559 + const editedEntity = select5(STORE_NAME).getEditedEntityRecord(
4385 4560 "postType",
4386 4561 postType,
4387 4562 postId
4388 4563 );
@@ -4388,17 +4563,17 @@
4388 4563 );
4389 4564 if (!editedEntity) {
4390 4565 return;
4391 4566 }
4392 - const postsPageId = unlock(select4(STORE_NAME)).getPostsPageId();
4567 + const postsPageId = unlock(select5(STORE_NAME)).getPostsPageId();
4393 4568 if (postType === "page" && postsPageId === postId.toString()) {
4394 - return select4(STORE_NAME).getDefaultTemplateId({
4569 + return select5(STORE_NAME).getDefaultTemplateId({
4395 4570 slug: "home"
4396 4571 });
4397 4572 }
4398 4573 const currentTemplateSlug = editedEntity.template;
4399 4574 if (currentTemplateSlug) {
4400 - const currentTemplate = select4(STORE_NAME).getEntityRecords("postType", "wp_template", {
4575 + const currentTemplate = select5(STORE_NAME).getEntityRecords("postType", "wp_template", {
4401 4576 per_page: -1
4402 4577 })?.find(({ slug }) => slug === currentTemplateSlug);
4403 4578 if (currentTemplate) {
4404 4579 return currentTemplate.id;
@@ -4409,9 +4584,9 @@
4409 4584 slugToCheck = postType === "page" ? `${postType}-${editedEntity.slug}` : `single-${postType}-${editedEntity.slug}`;
4410 4585 } else {
4411 4586 slugToCheck = postType === "page" ? "page" : `single-${postType}`;
4412 4587 }
4413 - return select4(STORE_NAME).getDefaultTemplateId({
4588 + return select5(STORE_NAME).getDefaultTemplateId({
4414 4589 slug: slugToCheck
4415 4590 });
4416 4591 }
4417 4592 );
@@ -4444,14 +4619,17 @@
4444 4619 }
4445 4620 }
4446 4621 return coalesced;
4447 4622 }
4623 + function getEntitySyncConnectionStatus(state, kind, name, recordId) {
4624 + return state.syncConnectionStatuses?.[`${kind}/${name}:${recordId}`];
4625 + }
4448 4626
4449 4627 // packages/core-data/build-module/selectors.mjs
4450 4628 var EMPTY_OBJECT2 = {};
4451 4629 var isRequestingEmbedPreview = (0, import_data9.createRegistrySelector)(
4452 - (select4) => (state, url) => {
4453 - return select4(STORE_NAME).isResolving("getEmbedPreview", [
4630 + (select5) => (state, url) => {
4631 + return select5(STORE_NAME).isResolving("getEmbedPreview", [
4454 4632 url
4455 4633 ]);
4456 4634 }
4457 4635 );
@@ -4504,54 +4682,34 @@
4504 4682 return state.entities.config?.find(
4505 4683 (config) => config.kind === kind && config.name === name
4506 4684 );
4507 4685 }
4508 - var getEntityRecord = (0, import_data9.createSelector)(
4509 - ((state, kind, name, key, query) => {
4510 - logEntityDeprecation(kind, name, "getEntityRecord");
4511 - const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
4512 - if (!queriedState) {
4686 + var getEntityRecord = ((state, kind, name, recordId, query) => {
4687 + logEntityDeprecation(kind, name, "getEntityRecord");
4688 + const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
4689 + if (!queriedState) {
4690 + return void 0;
4691 + }
4692 + const context = query?.context ?? "default";
4693 + if (!query || !query._fields) {
4694 + if (!queriedState.itemIsComplete[context]?.[recordId]) {
4513 4695 return void 0;
4514 4696 }
4515 - const context = query?.context ?? "default";
4516 - if (!query || !query._fields) {
4517 - if (!queriedState.itemIsComplete[context]?.[key]) {
4518 - return void 0;
4519 - }
4520 - return queriedState.items[context][key];
4521 - }
4522 - const item = queriedState.items[context]?.[key];
4523 - if (!item) {
4524 - return item;
4525 - }
4526 - const filteredItem = {};
4527 - const fields = get_normalized_comma_separable_default(query._fields) ?? [];
4528 - for (let f = 0; f < fields.length; f++) {
4529 - const field = fields[f].split(".");
4530 - let value = item;
4531 - field.forEach((fieldName) => {
4532 - value = value?.[fieldName];
4533 - });
4534 - setNestedValue(filteredItem, field, value);
4535 - }
4536 - return filteredItem;
4537 - }),
4538 - (state, kind, name, recordId, query) => {
4539 - const context = query?.context ?? "default";
4540 - const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
4541 - return [
4542 - queriedState?.items[context]?.[recordId],
4543 - queriedState?.itemIsComplete[context]?.[recordId]
4544 - ];
4697 + return queriedState.items[context][recordId];
4545 4698 }
4546 - );
4547 - getEntityRecord.__unstableNormalizeArgs = (args) => {
4699 + const item = queriedState.items[context]?.[recordId];
4700 + if (!item) {
4701 + return item;
4702 + }
4703 + return getFilteredItem(item, query._fields);
4704 + });
4705 + getEntityRecord.normalizeArgs = (args) => {
4548 4706 const newArgs = [...args];
4549 4707 const recordKey = newArgs?.[2];
4550 4708 newArgs[2] = isNumericID(recordKey) ? Number(recordKey) : recordKey;
4551 4709 return newArgs;
4552 4710 };
4553 - function hasEntityRecord(state, kind, name, key, query) {
4711 + function hasEntityRecord(state, kind, name, recordId, query) {
4554 4712 const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
4555 4713 if (!queriedState) {
4556 4714 return false;
4557 4715 }
@@ -4556,11 +4714,11 @@
4556 4714 return false;
4557 4715 }
4558 4716 const context = query?.context ?? "default";
4559 4717 if (!query || !query._fields) {
4560 - return !!queriedState.itemIsComplete[context]?.[key];
4718 + return !!queriedState.itemIsComplete[context]?.[recordId];
4561 4719 }
4562 - const item = queriedState.items[context]?.[key];
4720 + const item = queriedState.items[context]?.[recordId];
4563 4721 if (!item) {
4564 4722 return false;
4565 4723 }
4566 4724 const fields = get_normalized_comma_separable_default(query._fields) ?? [];
@@ -4576,19 +4734,19 @@
4576 4734 }
4577 4735 }
4578 4736 return true;
4579 4737 }
4580 - function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
4581 - return getEntityRecord(state, kind, name, key);
4738 + function __experimentalGetEntityRecordNoResolver(state, kind, name, recordId) {
4739 + return getEntityRecord(state, kind, name, recordId);
4582 4740 }
4583 4741 var getRawEntityRecord = (0, import_data9.createSelector)(
4584 - (state, kind, name, key) => {
4742 + (state, kind, name, recordId) => {
4585 4743 logEntityDeprecation(kind, name, "getRawEntityRecord");
4586 4744 const record = getEntityRecord(
4587 4745 state,
4588 4746 kind,
4589 4747 name,
4590 - key
4748 + recordId
4591 4749 );
4592 4750 const config = getEntityConfig(state, kind, name);
4593 4751 if (!record || !config?.rawAttributes?.length) {
4594 4752 return record;
@@ -4593,17 +4751,17 @@
4593 4751 if (!record || !config?.rawAttributes?.length) {
4594 4752 return record;
4595 4753 }
4596 4754 return Object.fromEntries(
4597 - Object.keys(record).map((_key) => {
4598 - if (config.rawAttributes.includes(_key)) {
4599 - const rawValue = record[_key]?.raw;
4755 + Object.keys(record).map((key) => {
4756 + if (config.rawAttributes.includes(key)) {
4757 + const rawValue = record[key]?.raw;
4600 4758 return [
4601 - _key,
4602 - rawValue !== void 0 ? rawValue : record[_key]
4759 + key,
4760 + rawValue !== void 0 ? rawValue : record[key]
4603 4761 ];
4604 4762 }
4605 - return [_key, record[_key]];
4763 + return [key, record[key]];
4606 4764 })
4607 4765 );
4608 4766 },
4609 4767 (state, kind, name, recordId, query) => {
@@ -4732,9 +4890,9 @@
4732 4890 (state) => [state.entities.records]
4733 4891 );
4734 4892 function getEntityRecordEdits(state, kind, name, recordId) {
4735 4893 logEntityDeprecation(kind, name, "getEntityRecordEdits");
4736 - return state.entities.records?.[kind]?.[name]?.edits?.[recordId];
4894 + return state.entities.records?.[kind]?.[name]?.edits?.[String(recordId)];
4737 4895 }
4738 4896 var getEntityRecordNonTransientEdits = (0, import_data9.createSelector)(
4739 4897 (state, kind, name, recordId) => {
4740 4898 logEntityDeprecation(kind, name, "getEntityRecordNonTransientEdits");
@@ -4751,9 +4909,9 @@
4751 4909 }, {});
4752 4910 },
4753 4911 (state, kind, name, recordId) => [
4754 4912 state.entities.config,
4755 - state.entities.records?.[kind]?.[name]?.edits?.[recordId]
4913 + state.entities.records?.[kind]?.[name]?.edits?.[String(recordId)]
4756 4914 ]
4757 4915 );
4758 4916 function hasEditsForEntityRecord(state, kind, name, recordId) {
4759 4917 logEntityDeprecation(kind, name, "hasEditsForEntityRecord");
@@ -4779,9 +4937,9 @@
4779 4937 return [
4780 4938 state.entities.config,
4781 4939 state.entities.records?.[kind]?.[name]?.queriedData.items[context]?.[recordId],
4782 4940 state.entities.records?.[kind]?.[name]?.queriedData.itemIsComplete[context]?.[recordId],
4783 - state.entities.records?.[kind]?.[name]?.edits?.[recordId]
4941 + state.entities.records?.[kind]?.[name]?.edits?.[String(recordId)]
4784 4942 ];
4785 4943 }
4786 4944 );
4787 4945 function isAutosavingEntityRecord(state, kind, name, recordId) {
@@ -4790,17 +4948,17 @@
4790 4948 return Boolean(pending && isAutosave);
4791 4949 }
4792 4950 function isSavingEntityRecord(state, kind, name, recordId) {
4793 4951 logEntityDeprecation(kind, name, "isSavingEntityRecord");
4794 - return state.entities.records?.[kind]?.[name]?.saving?.[recordId]?.pending ?? false;
4952 + return state.entities.records?.[kind]?.[name]?.saving?.[String(recordId)]?.pending ?? false;
4795 4953 }
4796 4954 function isDeletingEntityRecord(state, kind, name, recordId) {
4797 4955 logEntityDeprecation(kind, name, "isDeletingEntityRecord");
4798 - return state.entities.records?.[kind]?.[name]?.deleting?.[recordId]?.pending ?? false;
4956 + return state.entities.records?.[kind]?.[name]?.deleting?.[String(recordId)]?.pending ?? false;
4799 4957 }
4800 4958 function getLastEntitySaveError(state, kind, name, recordId) {
4801 4959 logEntityDeprecation(kind, name, "getLastEntitySaveError");
4802 - return state.entities.records?.[kind]?.[name]?.saving?.[recordId]?.error;
4960 + return state.entities.records?.[kind]?.[name]?.saving?.[String(recordId)]?.error;
4803 4961 }
4804 4962 function getLastEntityDeleteError(state, kind, name, recordId) {
4805 4963 logEntityDeprecation(kind, name, "getLastEntityDeleteError");
4806 4964 return state.entities.records?.[kind]?.[name]?.deleting?.[recordId]?.error;
@@ -4882,10 +5040,10 @@
4882 5040 (autosave) => autosave.author === authorId
4883 5041 );
4884 5042 }
4885 5043 var hasFetchedAutosaves = (0, import_data9.createRegistrySelector)(
4886 - (select4) => (state, postType, postId) => {
4887 - return select4(STORE_NAME).hasFinishedResolution("getAutosaves", [
5044 + (select5) => (state, postType, postId) => {
5045 + return select5(STORE_NAME).hasFinishedResolution("getAutosaves", [
4888 5046 postType,
4889 5047 postId
4890 5048 ]);
4891 5049 }
@@ -4964,47 +5122,27 @@
4964 5122 }
4965 5123 }
4966 5124 return true;
4967 5125 }
4968 - var getRevision = (0, import_data9.createSelector)(
4969 - (state, kind, name, recordKey, revisionKey, query) => {
4970 - logEntityDeprecation(kind, name, "getRevision");
4971 - const queriedState = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey];
4972 - if (!queriedState) {
5126 + var getRevision = (state, kind, name, recordKey, revisionKey, query) => {
5127 + logEntityDeprecation(kind, name, "getRevision");
5128 + const queriedState = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey];
5129 + if (!queriedState) {
5130 + return void 0;
5131 + }
5132 + const context = query?.context ?? "default";
5133 + if (!query || !query._fields) {
5134 + if (!queriedState.itemIsComplete[context]?.[revisionKey]) {
4973 5135 return void 0;
4974 5136 }
4975 - const context = query?.context ?? "default";
4976 - if (!query || !query._fields) {
4977 - if (!queriedState.itemIsComplete[context]?.[revisionKey]) {
4978 - return void 0;
4979 - }
4980 - return queriedState.items[context][revisionKey];
4981 - }
4982 - const item = queriedState.items[context]?.[revisionKey];
4983 - if (!item) {
4984 - return item;
4985 - }
4986 - const filteredItem = {};
4987 - const fields = get_normalized_comma_separable_default(query._fields) ?? [];
4988 - for (let f = 0; f < fields.length; f++) {
4989 - const field = fields[f].split(".");
4990 - let value = item;
4991 - field.forEach((fieldName) => {
4992 - value = value?.[fieldName];
4993 - });
4994 - setNestedValue(filteredItem, field, value);
4995 - }
4996 - return filteredItem;
4997 - },
4998 - (state, kind, name, recordKey, revisionKey, query) => {
4999 - const context = query?.context ?? "default";
5000 - const queriedState = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey];
5001 - return [
5002 - queriedState?.items?.[context]?.[revisionKey],
5003 - queriedState?.itemIsComplete?.[context]?.[revisionKey]
5004 - ];
5137 + return queriedState.items[context][revisionKey];
5005 5138 }
5006 - );
5139 + const item = queriedState.items[context]?.[revisionKey];
5140 + if (!item) {
5141 + return item;
5142 + }
5143 + return getFilteredItem(item, query._fields);
5144 + };
5007 5145
5008 5146 // packages/core-data/build-module/actions.mjs
5009 5147 var actions_exports = {};
5010 5148 __export(actions_exports, {
@@ -5036,8 +5174,9 @@
5036 5174 saveEditedEntityRecord: () => saveEditedEntityRecord,
5037 5175 saveEntityRecord: () => saveEntityRecord,
5038 5176 undo: () => undo
5039 5177 });
5178 + var import_es66 = __toESM(require_es6(), 1);
5040 5179 var import_api_fetch4 = __toESM(require_api_fetch(), 1);
5041 5180 var import_url3 = __toESM(require_url(), 1);
5042 5181 var import_deprecated3 = __toESM(require_deprecated(), 1);
5043 5182
@@ -5225,8 +5364,39 @@
5225 5364 // packages/core-data/build-module/actions.mjs
5226 5365 function addTitleToAutoDraft(record) {
5227 5366 return record.status === "auto-draft" ? { ...record, title: "" } : record;
5228 5367 }
5368 + function getServerMutatedMetaFields(updatedMeta, persistedMeta, syncedMeta) {
5369 + const baseline = { ...persistedMeta, ...syncedMeta };
5370 + return Object.fromEntries(
5371 + Object.entries(updatedMeta ?? {}).filter(([key, value]) => {
5372 + if (key === POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE) {
5373 + return false;
5374 + }
5375 + return !(0, import_es66.default)(value, baseline[key]);
5376 + })
5377 + );
5378 + }
5379 + function getServerMutatedFields(updatedRecord, persistedRecord, syncedChanges) {
5380 + return Object.fromEntries(
5381 + Object.entries(updatedRecord).flatMap(([key, value]) => {
5382 + if (key === "meta") {
5383 + const serverMutatedMeta = getServerMutatedMetaFields(
5384 + value,
5385 + persistedRecord.meta,
5386 + syncedChanges.meta
5387 + );
5388 + return Object.keys(serverMutatedMeta).length ? [[key, serverMutatedMeta]] : [];
5389 + }
5390 + const baseline = key in syncedChanges ? syncedChanges[key] : persistedRecord[key];
5391 + const wasServerMutated = !(0, import_es66.default)(
5392 + getRawValue(value) ?? value,
5393 + getRawValue(baseline) ?? baseline
5394 + );
5395 + return wasServerMutated ? [[key, value]] : [];
5396 + })
5397 + );
5398 + }
5229 5399 function receiveUserQuery(queryID, users2) {
5230 5400 return {
5231 5401 type: "RECEIVE_USER_QUERY",
5232 5402 users: Array.isArray(users2) ? users2 : [users2],
@@ -5340,12 +5510,9 @@
5340 5510 name,
5341 5511 recordId
5342 5512 });
5343 5513 let hasError = false;
5344 - let { baseURL } = entityConfig;
5345 - if (kind === "postType" && name === "wp_template" && (recordId && typeof recordId === "string" && !/^\d+$/.test(recordId) || !window?.__experimentalTemplateActivate)) {
5346 - baseURL = baseURL.slice(0, baseURL.lastIndexOf("/")) + "/templates";
5347 - }
5514 + const { baseURL } = entityConfig;
5348 5515 try {
5349 5516 let path = `${baseURL}/${recordId}`;
5350 5517 if (query) {
5351 5518 path = (0, import_url3.addQueryArgs)(path, query);
@@ -5378,11 +5545,11 @@
5378 5545 } finally {
5379 5546 dispatch3.__unstableReleaseStoreLock(lock2);
5380 5547 }
5381 5548 };
5382 - var editEntityRecord = (kind, name, recordId, edits, options = {}) => ({ select: select4, dispatch: dispatch3 }) => {
5549 + var editEntityRecord = (kind, name, recordId, edits, options = {}) => ({ select: select5, dispatch: dispatch3 }) => {
5383 5550 logEntityDeprecation(kind, name, "editEntityRecord");
5384 - const entityConfig = select4.getEntityConfig(kind, name);
5551 + const entityConfig = select5.getEntityConfig(kind, name);
5385 5552 if (!entityConfig) {
5386 5553 throw new Error(
5387 5554 `The entity being edited (${kind}, ${name}) does not have a loaded config.`
5388 5555 );
@@ -5387,10 +5554,10 @@
5387 5554 `The entity being edited (${kind}, ${name}) does not have a loaded config.`
5388 5555 );
5389 5556 }
5390 5557 const { mergedEdits = {} } = entityConfig;
5391 - const record = select4.getRawEntityRecord(kind, name, recordId);
5392 - const editedRecord = select4.getEditedEntityRecord(
5558 + const record = select5.getRawEntityRecord(kind, name, recordId);
5559 + const editedRecord = select5.getEditedEntityRecord(
5393 5560 kind,
5394 5561 name,
5395 5562 recordId
5396 5563 );
@@ -5419,9 +5586,9 @@
5419 5586 { isNewUndoLevel }
5420 5587 );
5421 5588 }
5422 5589 if (!options.undoIgnore) {
5423 - select4.getUndoManager().addRecord(
5590 + select5.getUndoManager().addRecord(
5424 5591 [
5425 5592 {
5426 5593 id: { kind, name, recordId },
5427 5594 changes: Object.keys(edits).reduce((acc, key) => {
@@ -5440,10 +5607,10 @@
5440 5607 type: "EDIT_ENTITY_RECORD",
5441 5608 ...edit
5442 5609 });
5443 5610 };
5444 - var clearEntityRecordEdits = (kind, name, recordId) => ({ select: select4, dispatch: dispatch3 }) => {
5445 - const entityConfig = select4.getEntityConfig(kind, name);
5611 + var clearEntityRecordEdits = (kind, name, recordId) => ({ select: select5, dispatch: dispatch3 }) => {
5612 + const entityConfig = select5.getEntityConfig(kind, name);
5446 5613 logEntityDeprecation(kind, name, "clearEntityRecordEdits");
5447 5614 if (!entityConfig) {
5448 5615 throw new Error(
5449 5616 `The entity being edited (${kind}, ${name}) does not have a loaded config.`
@@ -5448,9 +5615,9 @@
5448 5615 throw new Error(
5449 5616 `The entity being edited (${kind}, ${name}) does not have a loaded config.`
5450 5617 );
5451 5618 }
5452 - const currentEdits = select4.getEntityRecordEdits(
5619 + const currentEdits = select5.getEntityRecordEdits(
5453 5620 kind,
5454 5621 name,
5455 5622 recordId
5456 5623 );
@@ -5471,10 +5638,10 @@
5471 5638 recordId,
5472 5639 edits: clearedEdits
5473 5640 });
5474 5641 };
5475 - var undo = () => ({ select: select4, dispatch: dispatch3 }) => {
5476 - const undoRecord = select4.getUndoManager().undo();
5642 + var undo = () => ({ select: select5, dispatch: dispatch3 }) => {
5643 + const undoRecord = select5.getUndoManager().undo();
5477 5644 if (!undoRecord) {
5478 5645 return;
5479 5646 }
5480 5647 dispatch3({
@@ -5481,10 +5648,10 @@
5481 5648 type: "UNDO",
5482 5649 record: undoRecord
5483 5650 });
5484 5651 };
5485 - var redo = () => ({ select: select4, dispatch: dispatch3 }) => {
5486 - const redoRecord = select4.getUndoManager().redo();
5652 + var redo = () => ({ select: select5, dispatch: dispatch3 }) => {
5653 + const redoRecord = select5.getUndoManager().redo();
5487 5654 if (!redoRecord) {
5488 5655 return;
5489 5656 }
5490 5657 dispatch3({
@@ -5491,12 +5658,12 @@
5491 5658 type: "REDO",
5492 5659 record: redoRecord
5493 5660 });
5494 5661 };
5495 - var __unstableCreateUndoLevel = () => ({ select: select4 }) => {
5496 - select4.getUndoManager().addRecord();
5662 + var __unstableCreateUndoLevel = () => ({ select: select5 }) => {
5663 + select5.getUndoManager().addRecord();
5497 5664 };
5498 - var saveEntityRecord = (kind, name, record, options = {}) => async ({ select: select4, resolveSelect: resolveSelect2, dispatch: dispatch3 }) => {
5665 + var saveEntityRecord = (kind, name, record, options = {}) => async ({ select: select5, resolveSelect: resolveSelect2, dispatch: dispatch3 }) => {
5499 5666 const {
5500 5667 isAutosave = false,
5501 5668 __unstableFetch = import_api_fetch4.default,
5502 5669 __unstableSkipSyncUpdate = false,
@@ -5521,9 +5688,9 @@
5521 5688 try {
5522 5689 for (const [key, value] of Object.entries(record)) {
5523 5690 if (typeof value === "function") {
5524 5691 const evaluatedValue = value(
5525 - select4.getEditedEntityRecord(kind, name, recordId)
5692 + select5.getEditedEntityRecord(kind, name, recordId)
5526 5693 );
5527 5694 dispatch3.editEntityRecord(
5528 5695 kind,
5529 5696 name,
@@ -5545,15 +5712,20 @@
5545 5712 });
5546 5713 let updatedRecord;
5547 5714 let error;
5548 5715 let hasError = false;
5549 - let { baseURL } = entityConfig;
5550 - if (kind === "postType" && name === "wp_template" && (recordId && typeof recordId === "string" && !/^\d+$/.test(recordId) || !window?.__experimentalTemplateActivate)) {
5551 - baseURL = baseURL.slice(0, baseURL.lastIndexOf("/")) + "/templates";
5552 - }
5716 + const { baseURL } = entityConfig;
5553 5717 try {
5554 5718 const path = `${baseURL}${recordId ? "/" + recordId : ""}`;
5555 - const persistedRecord = !isNewRecord ? select4.getRawEntityRecord(kind, name, recordId) : {};
5719 + const persistedRecord = !isNewRecord ? select5.getRawEntityRecord(kind, name, recordId) : {};
5720 + if (entityConfig.syncConfig && !__unstableSkipSyncUpdate && !isNewRecord && persistedRecord) {
5721 + getSyncManager()?.update(
5722 + `${kind}/${name}`,
5723 + recordId,
5724 + record,
5725 + LOCAL_UNDO_IGNORED_ORIGIN
5726 + );
5727 + }
5556 5728 if (isAutosave) {
5557 5729 const merged = { ...persistedRecord, ...record };
5558 5730 const data = [
5559 5731 "title",
@@ -5574,8 +5746,17 @@
5574 5746 // have a draft post and change the status to publish.
5575 5747 status: merged.status === "auto-draft" ? "draft" : void 0
5576 5748 }
5577 5749 );
5750 + if (entityConfig.syncConfig) {
5751 + const crdtSnapshot = getSyncManager()?.getEntitySnapshot(
5752 + `${kind}/${name}`,
5753 + recordId
5754 + );
5755 + if (crdtSnapshot) {
5756 + data[CRDT_AUTOSAVE_SNAPSHOT_KEY] = crdtSnapshot;
5757 + }
5758 + }
5578 5759 updatedRecord = await __unstableFetch({
5579 5760 path: `${path}/autosaves`,
5580 5761 method: "POST",
5581 5762 data
@@ -5638,15 +5819,27 @@
5638 5819 name,
5639 5820 updatedRecord,
5640 5821 void 0,
5641 5822 true,
5642 - edits
5823 + record
5643 5824 );
5644 5825 if (entityConfig.syncConfig) {
5826 + let syncChanges;
5827 + if (__unstableSkipSyncUpdate) {
5828 + syncChanges = {};
5829 + } else if (isNewRecord || !persistedRecord) {
5830 + syncChanges = updatedRecord;
5831 + } else {
5832 + syncChanges = getServerMutatedFields(
5833 + updatedRecord,
5834 + persistedRecord,
5835 + record
5836 + );
5837 + }
5645 5838 getSyncManager()?.update(
5646 5839 `${kind}/${name}`,
5647 5840 recordId,
5648 - __unstableSkipSyncUpdate ? {} : updatedRecord,
5841 + syncChanges,
5649 5842 LOCAL_UNDO_IGNORED_ORIGIN,
5650 5843 { isSave: true }
5651 5844 );
5652 5845 }
@@ -5705,11 +5898,11 @@
5705 5898 ...resultPromises
5706 5899 ]);
5707 5900 return results;
5708 5901 };
5709 - var saveEditedEntityRecord = (kind, name, recordId, options) => async ({ select: select4, dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
5902 + var saveEditedEntityRecord = (kind, name, recordId, options) => async ({ select: select5, dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
5710 5903 logEntityDeprecation(kind, name, "saveEditedEntityRecord");
5711 - if (!select4.hasEditsForEntityRecord(kind, name, recordId)) {
5904 + if (!select5.hasEditsForEntityRecord(kind, name, recordId)) {
5712 5905 return;
5713 5906 }
5714 5907 const configs = await resolveSelect2.getEntitiesConfig(kind);
5715 5908 const entityConfig = configs.find(
@@ -5718,9 +5911,9 @@
5718 5911 if (!entityConfig) {
5719 5912 return;
5720 5913 }
5721 5914 const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
5722 - const edits = select4.getEntityRecordNonTransientEdits(
5915 + const edits = select5.getEntityRecordNonTransientEdits(
5723 5916 kind,
5724 5917 name,
5725 5918 recordId
5726 5919 );
@@ -5726,18 +5919,18 @@
5726 5919 );
5727 5920 const record = { [entityIdKey]: recordId, ...edits };
5728 5921 return await dispatch3.saveEntityRecord(kind, name, record, options);
5729 5922 };
5730 - var __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, itemsToSave, options) => async ({ select: select4, dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
5923 + var __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, itemsToSave, options) => async ({ select: select5, dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
5731 5924 logEntityDeprecation(
5732 5925 kind,
5733 5926 name,
5734 5927 "__experimentalSaveSpecifiedEntityEdits"
5735 5928 );
5736 - if (!select4.hasEditsForEntityRecord(kind, name, recordId)) {
5929 + if (!select5.hasEditsForEntityRecord(kind, name, recordId)) {
5737 5930 return;
5738 5931 }
5739 - const edits = select4.getEntityRecordNonTransientEdits(
5932 + const edits = select5.getEntityRecordNonTransientEdits(
5740 5933 kind,
5741 5934 name,
5742 5935 recordId
5743 5936 );
@@ -5828,12 +6021,17 @@
5828 6021 receiveEditorAssets: () => receiveEditorAssets,
5829 6022 receiveEditorSettings: () => receiveEditorSettings,
5830 6023 receiveRegisteredPostMeta: () => receiveRegisteredPostMeta,
5831 6024 receiveViewConfig: () => receiveViewConfig,
6025 + saveDirtyEntities: () => saveDirtyEntities,
5832 6026 setCollaborationSupported: () => setCollaborationSupported,
5833 6027 setSyncConnectionStatus: () => setSyncConnectionStatus
5834 6028 });
5835 6029 var import_api_fetch5 = __toESM(require_api_fetch(), 1);
6030 + var import_notices = __toESM(require_notices(), 1);
6031 + var import_block_editor5 = __toESM(require_block_editor(), 1);
6032 + var import_html_entities = __toESM(require_html_entities(), 1);
6033 + var import_i18n2 = __toESM(require_i18n(), 1);
5836 6034 function receiveRegisteredPostMeta(postType, registeredPostMeta2) {
5837 6035 return {
5838 6036 type: "RECEIVE_REGISTERED_POST_META",
5839 6037 postType,
@@ -5960,8 +6158,134 @@
5960 6158 key,
5961 6159 status
5962 6160 };
5963 6161 }
6162 + var saveDirtyEntities = ({
6163 + onSave,
6164 + dirtyEntityRecords = [],
6165 + entitiesToSkip = [],
6166 + close,
6167 + successNoticeContent
6168 + } = {}) => ({ registry }) => {
6169 + const PUBLISH_ON_SAVE_ENTITIES = [
6170 + { kind: "postType", name: "wp_navigation" }
6171 + ];
6172 + const saveNoticeId = "site-editor-save-success";
6173 + const homeUrl = registry.select(STORE_NAME).getEntityRecord("root", "__unstableBase")?.home;
6174 + registry.dispatch(import_notices.store).removeNotice(saveNoticeId);
6175 + const entitiesToSave = dirtyEntityRecords.filter(
6176 + ({ kind, name, key, property }) => {
6177 + return !entitiesToSkip.some(
6178 + (elt) => elt.kind === kind && elt.name === name && elt.key === key && elt.property === property
6179 + );
6180 + }
6181 + );
6182 + close?.(entitiesToSave);
6183 + const siteItemsToSave = [];
6184 + const pendingSavedRecords = [];
6185 + entitiesToSave.forEach(({ kind, name, key, property }) => {
6186 + if ("root" === kind && "site" === name) {
6187 + siteItemsToSave.push(property);
6188 + } else {
6189 + if (PUBLISH_ON_SAVE_ENTITIES.some(
6190 + (typeToPublish) => typeToPublish.kind === kind && typeToPublish.name === name
6191 + )) {
6192 + registry.dispatch(STORE_NAME).editEntityRecord(kind, name, key, {
6193 + status: "publish"
6194 + });
6195 + }
6196 + pendingSavedRecords.push(
6197 + registry.dispatch(STORE_NAME).saveEditedEntityRecord(kind, name, key, {
6198 + throwOnError: true
6199 + }).catch(ensureError)
6200 + );
6201 + }
6202 + });
6203 + if (siteItemsToSave.length) {
6204 + pendingSavedRecords.push(
6205 + registry.dispatch(STORE_NAME).__experimentalSaveSpecifiedEntityEdits(
6206 + "root",
6207 + "site",
6208 + void 0,
6209 + siteItemsToSave,
6210 + {
6211 + throwOnError: true
6212 + }
6213 + ).catch(ensureError)
6214 + );
6215 + }
6216 + registry.dispatch(import_block_editor5.store).__unstableMarkLastChangeAsPersistent();
6217 + return Promise.all(pendingSavedRecords).then(async (values) => {
6218 + if (onSave) {
6219 + await onSave();
6220 + }
6221 + return values;
6222 + }).then((values) => {
6223 + const errors = values.filter((v) => v instanceof Error);
6224 + if (errors.length) {
6225 + const firstMessage = errors.find(
6226 + (e) => e.message
6227 + )?.message;
6228 + registry.dispatch(import_notices.store).createErrorNotice(
6229 + (0, import_html_entities.decodeEntities)(
6230 + firstMessage || (0, import_i18n2.__)("Saving failed.")
6231 + ),
6232 + {
6233 + type: "snackbar",
6234 + id: saveNoticeId
6235 + }
6236 + );
6237 + } else {
6238 + registry.dispatch(import_notices.store).createSuccessNotice(
6239 + successNoticeContent || (0, import_i18n2.__)("Site updated."),
6240 + {
6241 + type: "snackbar",
6242 + id: saveNoticeId,
6243 + actions: [
6244 + {
6245 + label: (0, import_i18n2.__)("View site"),
6246 + url: homeUrl,
6247 + openInNewTab: true
6248 + }
6249 + ]
6250 + }
6251 + );
6252 + }
6253 + }).catch(
6254 + (error) => registry.dispatch(import_notices.store).createErrorNotice(
6255 + (0, import_html_entities.decodeEntities)(
6256 + error?.message || (0, import_i18n2.__)("Saving failed.")
6257 + ),
6258 + {
6259 + type: "snackbar",
6260 + id: saveNoticeId
6261 + }
6262 + )
6263 + );
6264 + function ensureError(error) {
6265 + if (error instanceof Error) {
6266 + return error;
6267 + }
6268 + let message;
6269 + if (!error) {
6270 + } else if (typeof error.message === "string") {
6271 + message = error.message;
6272 + } else if (typeof error === "string") {
6273 + message = error;
6274 + } else if (
6275 + // Only consider own method, lest we erroneously end up calling
6276 + // `Object#toString` at the end of the prototype chain, thereby
6277 + // returning `"[object Object]"`.
6278 + Object.hasOwn(error, "toString") && typeof error.toString === "function"
6279 + ) {
6280 + const result = error.toString();
6281 + if (typeof result === "string") {
6282 + message = result;
6283 + }
6284 + }
6285 + return new Error(message, { cause: error });
6286 + }
6287 + };
5964 6288
5965 6289 // packages/core-data/build-module/resolvers.mjs
5966 6290 var resolvers_exports = {};
5967 6291 __export(resolvers_exports, {
@@ -5997,9 +6321,9 @@
5997 6321 getUserPatternCategories: () => getUserPatternCategories2,
5998 6322 getViewConfig: () => getViewConfig2
5999 6323 });
6000 6324 var import_url6 = __toESM(require_url(), 1);
6001 - var import_html_entities2 = __toESM(require_html_entities(), 1);
6325 + var import_html_entities3 = __toESM(require_html_entities(), 1);
6002 6326 var import_api_fetch9 = __toESM(require_api_fetch(), 1);
6003 6327
6004 6328 // packages/core-data/build-module/fetch/index.mjs
6005 6329 var import_api_fetch8 = __toESM(require_api_fetch(), 1);
@@ -6006,10 +6330,10 @@
6006 6330
6007 6331 // packages/core-data/build-module/fetch/__experimental-fetch-link-suggestions.mjs
6008 6332 var import_api_fetch6 = __toESM(require_api_fetch(), 1);
6009 6333 var import_url4 = __toESM(require_url(), 1);
6010 - var import_html_entities = __toESM(require_html_entities(), 1);
6011 - var import_i18n2 = __toESM(require_i18n(), 1);
6334 + var import_html_entities2 = __toESM(require_html_entities(), 1);
6335 + var import_i18n3 = __toESM(require_i18n(), 1);
6012 6336 async function fetchLinkSuggestions(search, searchOptions = {}, editorSettings2 = {}) {
6013 6337 const searchOptionsToUse = searchOptions.isInitialSuggestions && searchOptions.initialSuggestionsSearchOptions ? {
6014 6338 ...searchOptions,
6015 6339 ...searchOptions.initialSuggestionsSearchOptions
@@ -6036,9 +6360,9 @@
6036 6360 return results2.map((result) => {
6037 6361 return {
6038 6362 id: result.id,
6039 6363 url: result.url,
6040 - title: (0, import_html_entities.decodeEntities)(result.title || "") || (0, import_i18n2.__)("(no title)"),
6364 + title: (0, import_html_entities2.decodeEntities)(result.title || "") || (0, import_i18n3.__)("(no title)"),
6041 6365 type: result.subtype || result.type,
6042 6366 kind: "post-type"
6043 6367 };
6044 6368 });
@@ -6060,9 +6384,9 @@
6060 6384 return results2.map((result) => {
6061 6385 return {
6062 6386 id: result.id,
6063 6387 url: result.url,
6064 - title: (0, import_html_entities.decodeEntities)(result.title || "") || (0, import_i18n2.__)("(no title)"),
6388 + title: (0, import_html_entities2.decodeEntities)(result.title || "") || (0, import_i18n3.__)("(no title)"),
6065 6389 type: result.subtype || result.type,
6066 6390 kind: "taxonomy"
6067 6391 };
6068 6392 });
@@ -6084,9 +6408,9 @@
6084 6408 return results2.map((result) => {
6085 6409 return {
6086 6410 id: result.id,
6087 6411 url: result.url,
6088 - title: (0, import_html_entities.decodeEntities)(result.title || "") || (0, import_i18n2.__)("(no title)"),
6412 + title: (0, import_html_entities2.decodeEntities)(result.title || "") || (0, import_i18n3.__)("(no title)"),
6089 6413 type: result.subtype || result.type,
6090 6414 kind: "taxonomy"
6091 6415 };
6092 6416 });
@@ -6106,9 +6430,9 @@
6106 6430 return results2.map((result) => {
6107 6431 return {
6108 6432 id: result.id,
6109 6433 url: result.source_url,
6110 - title: (0, import_html_entities.decodeEntities)(result.title.rendered || "") || (0, import_i18n2.__)("(no title)"),
6434 + title: (0, import_html_entities2.decodeEntities)(result.title.rendered || "") || (0, import_i18n3.__)("(no title)"),
6111 6435 type: result.type,
6112 6436 kind: "media"
6113 6437 };
6114 6438 });
@@ -6124,8 +6448,9 @@
6124 6448 return results;
6125 6449 }
6126 6450 function sortResults(results, search) {
6127 6451 const searchTokens = tokenize(search);
6452 + const scoreKey = (result) => `${result.kind}:${result.type}:${result.id}`;
6128 6453 const scores = {};
6129 6454 for (const result of results) {
6130 6455 if (result.title) {
6131 6456 const titleTokens = tokenize(result.title);
@@ -6140,14 +6465,16 @@
6140 6465 )
6141 6466 );
6142 6467 const exactMatchScore = exactMatchingTokens.length / titleTokens.length * 10;
6143 6468 const subMatchScore = subMatchingTokens.length / titleTokens.length;
6144 - scores[result.id] = exactMatchScore + subMatchScore;
6469 + scores[scoreKey(result)] = exactMatchScore + subMatchScore;
6145 6470 } else {
6146 - scores[result.id] = 0;
6471 + scores[scoreKey(result)] = 0;
6147 6472 }
6148 6473 }
6149 - return results.sort((a, b) => scores[b.id] - scores[a.id]);
6474 + return results.sort(
6475 + (a, b) => scores[scoreKey(b)] - scores[scoreKey(a)]
6476 + );
6150 6477 }
6151 6478 function tokenize(text) {
6152 6479 return text.toLowerCase().match(/[\p{L}\p{N}]+/gu) || [];
6153 6480 }
@@ -6201,12 +6528,32 @@
6201 6528 );
6202 6529 }
6203 6530
6204 6531 // packages/core-data/build-module/parsed-blocks-cache.mjs
6205 - var parsedBlocksCache = /* @__PURE__ */ new Map();
6532 + var import_data10 = __toESM(require_data(), 1);
6533 + var import_blocks5 = __toESM(require_blocks(), 1);
6534 + var caches = /* @__PURE__ */ new WeakMap();
6206 6535 function getCacheKey(kind, name, id) {
6207 6536 return `${kind}:${name}:${id}`;
6208 6537 }
6538 + function getBlockTypes2() {
6539 + return (0, import_data10.select)(import_blocks5.store).getBlockTypes();
6540 + }
6541 + function getCachedBlocks(kind, name, id, content) {
6542 + const cached = caches.get(getBlockTypes2())?.get(getCacheKey(kind, name, id));
6543 + if (cached && cached.content === content) {
6544 + return cached.blocks;
6545 + }
6546 + }
6547 + function setCachedBlocks(kind, name, id, content, blocks) {
6548 + const blockTypes = getBlockTypes2();
6549 + let cache3 = caches.get(blockTypes);
6550 + if (!cache3) {
6551 + cache3 = /* @__PURE__ */ new Map();
6552 + caches.set(blockTypes, cache3);
6553 + }
6554 + cache3.set(getCacheKey(kind, name, id), { content, blocks });
6555 + }
6209 6556
6210 6557 // packages/core-data/build-module/resolvers.mjs
6211 6558 var getAuthors2 = (query) => async ({ dispatch: dispatch3 }) => {
6212 6559 const path = (0, import_url6.addQueryArgs)(
@@ -6219,9 +6566,9 @@
6219 6566 var getCurrentUser2 = () => async ({ dispatch: dispatch3 }) => {
6220 6567 const currentUser2 = await (0, import_api_fetch9.default)({ path: "/wp/v2/users/me" });
6221 6568 dispatch3.receiveCurrentUser(currentUser2);
6222 6569 };
6223 - var getEntityRecord2 = (kind, name, key = "", query) => async ({ select: select4, dispatch: dispatch3, registry, resolveSelect: resolveSelect2 }) => {
6570 + var getEntityRecord2 = (kind, name, key = "", query) => async ({ select: select5, dispatch: dispatch3, registry, resolveSelect: resolveSelect2 }) => {
6224 6571 const configs = await resolveSelect2.getEntitiesConfig(kind);
6225 6572 const entityConfig = configs.find(
6226 6573 (config) => config.name === name && config.kind === kind
6227 6574 );
@@ -6245,9 +6592,9 @@
6245 6592 ].join()
6246 6593 };
6247 6594 }
6248 6595 if (query !== void 0 && query._fields) {
6249 - const hasRecord = select4.hasEntityRecord(
6596 + const hasRecord = select5.hasEntityRecord(
6250 6597 kind,
6251 6598 name,
6252 6599 key,
6253 6600 query
@@ -6255,12 +6602,9 @@
6255 6602 if (hasRecord) {
6256 6603 return;
6257 6604 }
6258 6605 }
6259 - let { baseURL } = entityConfig;
6260 - if (kind === "postType" && name === "wp_template" && (key && typeof key === "string" && !/^\d+$/.test(key) || !window?.__experimentalTemplateActivate)) {
6261 - baseURL = baseURL.slice(0, baseURL.lastIndexOf("/")) + "/templates";
6262 - }
6606 + const { baseURL } = entityConfig;
6263 6607 const path = (0, import_url6.addQueryArgs)(baseURL + (key ? "/" + key : ""), {
6264 6608 ...entityConfig.baseURLParams,
6265 6609 ...query
6266 6610 });
@@ -6268,9 +6612,8 @@
6268 6612 const record = await response.json();
6269 6613 const permissions = getUserPermissionsFromAllowHeader(
6270 6614 response.headers?.get("allow")
6271 6615 );
6272 - const canUserResolutionsArgs = [];
6273 6616 const receiveUserPermissionArgs = {};
6274 6617 for (const action of ALLOWED_RESOURCE_ACTIONS) {
6275 6618 receiveUserPermissionArgs[getUserPermissionCacheKey(action, {
6276 6619 kind,
@@ -6276,13 +6619,10 @@
6276 6619 kind,
6277 6620 name,
6278 6621 id: key
6279 6622 })] = permissions[action];
6280 - canUserResolutionsArgs.push([
6281 - action,
6282 - { kind, name, id: key }
6283 - ]);
6284 6623 }
6624 + const canUserResolutionsArgs = [[{ kind, name, id: key }]];
6285 6625 if (entityConfig.syncConfig && isNumericID(key) && !query) {
6286 6626 const objectType = `${kind}/${name}`;
6287 6627 const objectId = key;
6288 6628 const recordWithTransients = { ...record };
@@ -6291,14 +6631,17 @@
6291 6631 ).forEach(([propName, transientConfig]) => {
6292 6632 recordWithTransients[propName] = transientConfig.read(recordWithTransients);
6293 6633 });
6294 6634 if (recordWithTransients.blocks && typeof recordWithTransients.content?.raw === "string") {
6295 - parsedBlocksCache.set(getCacheKey(kind, name, key), {
6296 - content: recordWithTransients.content.raw,
6297 - blocks: recordWithTransients.blocks
6298 - });
6635 + setCachedBlocks(
6636 + kind,
6637 + name,
6638 + key,
6639 + recordWithTransients.content.raw,
6640 + recordWithTransients.blocks
6641 + );
6299 6642 }
6300 - const syncManager2 = select4?.isCollaborationSupported?.() === false ? void 0 : getSyncManager();
6643 + const syncManager2 = select5?.isCollaborationSupported?.() === false ? void 0 : getSyncManager();
6301 6644 void syncManager2?.load(
6302 6645 entityConfig.syncConfig,
6303 6646 objectType,
6304 6647 objectId,
@@ -6445,13 +6788,9 @@
6445 6788 ])
6446 6789 ].join()
6447 6790 };
6448 6791 }
6449 - let { baseURL } = entityConfig;
6450 - const { combinedTemplates = true } = query;
6451 - if (kind === "postType" && name === "wp_template" && combinedTemplates) {
6452 - baseURL = baseURL.slice(0, baseURL.lastIndexOf("/")) + "/templates";
6453 - }
6792 + const { baseURL } = entityConfig;
6454 6793 const path = (0, import_url6.addQueryArgs)(baseURL, {
6455 6794 ...entityConfig.baseURLParams,
6456 6795 ...query
6457 6796 });
@@ -6458,16 +6797,9 @@
6458 6797 let records = [], meta;
6459 6798 if (entityConfig.supportsPagination && query.per_page !== -1) {
6460 6799 const response = await (0, import_api_fetch9.default)({ path, parse: false });
6461 6800 records = Object.values(await response.json());
6462 - meta = {
6463 - totalItems: parseInt(
6464 - response.headers.get("X-WP-Total")
6465 - ),
6466 - totalPages: parseInt(
6467 - response.headers.get("X-WP-TotalPages")
6468 - )
6469 - };
6801 + meta = getPaginationMeta(response.headers);
6470 6802 } else if (query.per_page === -1 && query[RECEIVE_INTERMEDIATE_RESULTS] === true) {
6471 6803 let page = 1;
6472 6804 let totalPages;
6473 6805 do {
@@ -6475,16 +6807,13 @@
6475 6807 path: (0, import_url6.addQueryArgs)(path, { page, per_page: 100 }),
6476 6808 parse: false
6477 6809 });
6478 6810 const pageRecords = Object.values(await response.json());
6479 - totalPages = parseInt(
6480 - response.headers.get("X-WP-TotalPages")
6481 - );
6811 + const pageMeta = getPaginationMeta(response.headers);
6812 + totalPages = pageMeta.totalPages ?? 1;
6482 6813 if (!meta) {
6483 6814 meta = {
6484 - totalItems: parseInt(
6485 - response.headers.get("X-WP-Total")
6486 - ),
6815 + totalItems: pageMeta.totalItems,
6487 6816 totalPages: 1
6488 6817 };
6489 6818 }
6490 6819 records.push(...pageRecords);
@@ -6567,13 +6896,12 @@
6567 6896 }));
6568 6897 const canUserResolutionsArgs = [];
6569 6898 const receiveUserPermissionArgs = {};
6570 6899 for (const targetHint of targetHints) {
6900 + canUserResolutionsArgs.push([
6901 + { kind, name, id: targetHint.id }
6902 + ]);
6571 6903 for (const action of ALLOWED_RESOURCE_ACTIONS) {
6572 - canUserResolutionsArgs.push([
6573 - action,
6574 - { kind, name, id: targetHint.id }
6575 - ]);
6576 6904 receiveUserPermissionArgs[getUserPermissionCacheKey(action, {
6577 6905 kind,
6578 6906 name,
6579 6907 id: targetHint.id
@@ -6622,26 +6950,9 @@
6622 6950 } catch {
6623 6951 dispatch3.receiveEmbedPreview(url, false);
6624 6952 }
6625 6953 };
6626 - var canUser2 = (requestedAction, resource, id) => async ({ dispatch: dispatch3, registry, resolveSelect: resolveSelect2 }) => {
6627 - if (!ALLOWED_RESOURCE_ACTIONS.includes(requestedAction)) {
6628 - throw new Error(`'${requestedAction}' is not a valid action.`);
6629 - }
6630 - const { hasStartedResolution } = registry.select(STORE_NAME);
6631 - for (const relatedAction of ALLOWED_RESOURCE_ACTIONS) {
6632 - if (relatedAction === requestedAction) {
6633 - continue;
6634 - }
6635 - const isAlreadyResolving = hasStartedResolution("canUser", [
6636 - relatedAction,
6637 - resource,
6638 - id
6639 - ]);
6640 - if (isAlreadyResolving) {
6641 - return;
6642 - }
6643 - }
6954 + var canUser2 = (resource, id) => async ({ dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
6644 6955 let resourcePath = null;
6645 6956 if (typeof resource === "object") {
6646 6957 if (!resource.kind || !resource.name) {
6647 6958 throw new Error("The entity resource object is not valid.");
@@ -6672,22 +6983,16 @@
6672 6983 const permissions = getUserPermissionsFromAllowHeader(
6673 6984 response.headers?.get("allow")
6674 6985 );
6675 6986 const receiveUserPermissionArgs = {};
6676 - const canUserResolutionsArgs = [];
6677 6987 for (const action of ALLOWED_RESOURCE_ACTIONS) {
6678 6988 receiveUserPermissionArgs[getUserPermissionCacheKey(action, resource, id)] = permissions[action];
6679 - if (action !== requestedAction) {
6680 - canUserResolutionsArgs.push([action, resource, id]);
6681 - }
6682 6989 }
6683 - registry.batch(() => {
6684 - dispatch3.receiveUserPermissions(receiveUserPermissionArgs);
6685 - dispatch3.finishResolutions("canUser", canUserResolutionsArgs);
6686 - });
6990 + dispatch3.receiveUserPermissions(receiveUserPermissionArgs);
6687 6991 };
6688 - var canUserEditEntityRecord2 = (kind, name, recordId) => async ({ dispatch: dispatch3 }) => {
6689 - await dispatch3(canUser2("update", { kind, name, id: recordId }));
6992 + canUser2.getResolutionArgs = (action, resource, id) => [resource, id];
6993 + var canUserEditEntityRecord2 = (kind, name, recordId) => async ({ resolveSelect: resolveSelect2 }) => {
6994 + await resolveSelect2.canUser("update", { kind, name, id: recordId });
6690 6995 };
6691 6996 var getAutosaves2 = (postType, postId) => async ({ dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
6692 6997 const {
6693 6998 rest_base: restBase,
@@ -6793,9 +7098,9 @@
6793 7098 }
6794 7099 );
6795 7100 const mappedPatternCategories = patternCategories?.map((userCategory) => ({
6796 7101 ...userCategory,
6797 - label: (0, import_html_entities2.decodeEntities)(userCategory.name),
7102 + label: (0, import_html_entities3.decodeEntities)(userCategory.name),
6798 7103 name: userCategory.slug
6799 7104 })) || [];
6800 7105 dispatch3({
6801 7106 type: "RECEIVE_USER_PATTERN_CATEGORIES",
@@ -6801,9 +7106,9 @@
6801 7106 type: "RECEIVE_USER_PATTERN_CATEGORIES",
6802 7107 patternCategories: mappedPatternCategories
6803 7108 });
6804 7109 };
6805 - var getNavigationFallbackId2 = () => async ({ dispatch: dispatch3, select: select4, registry }) => {
7110 + var getNavigationFallbackId2 = () => async ({ dispatch: dispatch3, select: select5, registry }) => {
6806 7111 const fallback = await (0, import_api_fetch9.default)({
6807 7112 path: (0, import_url6.addQueryArgs)("/wp-block-editor/v1/navigation-fallback", {
6808 7113 _embed: true
6809 7114 })
@@ -6813,9 +7118,9 @@
6813 7118 dispatch3.receiveNavigationFallbackId(fallback?.id);
6814 7119 if (!record) {
6815 7120 return;
6816 7121 }
6817 - const existingFallbackEntityRecord = select4.getEntityRecord(
7122 + const existingFallbackEntityRecord = select5.getEntityRecord(
6818 7123 "postType",
6819 7124 "wp_navigation",
6820 7125 fallback.id
6821 7126 );
@@ -6838,9 +7143,9 @@
6838 7143 const template = await (0, import_api_fetch9.default)({
6839 7144 path: (0, import_url6.addQueryArgs)("/wp/v2/templates/lookup", query)
6840 7145 });
6841 7146 await resolveSelect2.getEntitiesConfig("postType");
6842 - const id = window?.__experimentalTemplateActivate ? template?.wp_id || template?.id : template?.id;
7147 + const id = template?.id;
6843 7148 registry.batch(() => {
6844 7149 dispatch3.receiveDefaultTemplateId(query, id || "");
6845 7150 if (id) {
6846 7151 template.id = id;
@@ -6856,12 +7161,9 @@
6856 7161 ]);
6857 7162 }
6858 7163 });
6859 7164 };
6860 - getDefaultTemplateId2.shouldInvalidate = (action) => {
6861 - return action.type === "RECEIVE_ITEMS" && action.kind === "root" && action.name === "site" && !!action.persistedEdits;
6862 - };
6863 - var getRevisions2 = (kind, name, recordKey, query = {}) => async ({ dispatch: dispatch3, registry, resolveSelect: resolveSelect2 }) => {
7165 + var getRevisions2 = (kind, name, recordKey, query = {}) => async ({ dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
6864 7166 const configs = await resolveSelect2.getEntitiesConfig(kind);
6865 7167 const entityConfig = configs.find(
6866 7168 (config) => config.name === name && config.kind === kind
6867 7169 );
@@ -6900,11 +7202,11 @@
6900 7202 }
6901 7203 if (response) {
6902 7204 if (isPaginated) {
6903 7205 records = Object.values(await response.json());
6904 - meta.totalItems = parseInt(
6905 - response.headers.get("X-WP-Total")
6906 - );
7206 + meta.totalItems = getPaginationMeta(
7207 + response.headers
7208 + ).totalItems;
6907 7209 } else {
6908 7210 records = Object.values(response);
6909 7211 }
6910 7212 if (query._fields) {
@@ -6916,32 +7218,27 @@
6916 7218 });
6917 7219 return record;
6918 7220 });
6919 7221 }
6920 - registry.batch(() => {
6921 - dispatch3.receiveRevisions(
6922 - kind,
6923 - name,
6924 - recordKey,
6925 - records,
6926 - query,
6927 - false,
6928 - meta
6929 - );
6930 - const key = entityConfig.revisionKey || DEFAULT_ENTITY_KEY;
6931 - const normalizedQuery = normalizeQueryForResolution(rawQuery);
6932 - const resolutionsArgs = records.filter((record) => record[key]).map((record) => [
6933 - kind,
6934 - name,
6935 - recordKey,
6936 - record[key],
6937 - normalizedQuery
6938 - ]);
6939 - dispatch3.finishResolutions(
6940 - "getRevision",
6941 - resolutionsArgs
6942 - );
6943 - });
7222 + await dispatch3.receiveRevisions(
7223 + kind,
7224 + name,
7225 + recordKey,
7226 + records,
7227 + query,
7228 + false,
7229 + meta
7230 + );
7231 + const key = entityConfig.revisionKey || DEFAULT_ENTITY_KEY;
7232 + const normalizedQuery = normalizeQueryForResolution(rawQuery);
7233 + const resolutionsArgs = records.filter((record) => record[key]).map((record) => [
7234 + kind,
7235 + name,
7236 + recordKey,
7237 + record[key],
7238 + normalizedQuery
7239 + ]);
7240 + dispatch3.finishResolutions("getRevision", resolutionsArgs);
6944 7241 }
6945 7242 } finally {
6946 7243 dispatch3.__unstableReleaseStoreLock(lock2);
6947 7244 }
@@ -6946,9 +7243,9 @@
6946 7243 dispatch3.__unstableReleaseStoreLock(lock2);
6947 7244 }
6948 7245 };
6949 7246 getRevisions2.shouldInvalidate = (action, kind, name, recordKey) => action.type === "SAVE_ENTITY_RECORD_FINISH" && name === action.name && kind === action.kind && !action.error && recordKey === action.recordId;
6950 - var getRevision2 = (kind, name, recordKey, revisionKey, query) => async ({ select: select4, dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
7247 + var getRevision2 = (kind, name, recordKey, revisionKey, query) => async ({ select: select5, dispatch: dispatch3, resolveSelect: resolveSelect2 }) => {
6951 7248 const configs = await resolveSelect2.getEntitiesConfig(kind);
6952 7249 const entityConfig = configs.find(
6953 7250 (config) => config.name === name && config.kind === kind
6954 7251 );
@@ -6979,9 +7276,9 @@
6979 7276 ],
6980 7277 { exclusive: false }
6981 7278 );
6982 7279 try {
6983 - if (select4.hasRevision(kind, name, recordKey, revisionKey, query)) {
7280 + if (select5.hasRevision(kind, name, recordKey, revisionKey, query)) {
6984 7281 return;
6985 7282 }
6986 7283 const path = (0, import_url6.addQueryArgs)(
6987 7284 entityConfig.getRevisionsUrl(recordKey, revisionKey),
@@ -6993,9 +7290,9 @@
6993 7290 } catch {
6994 7291 return;
6995 7292 }
6996 7293 if (record) {
6997 - dispatch3.receiveRevisions(
7294 + await dispatch3.receiveRevisions(
6998 7295 kind,
6999 7296 name,
7000 7297 recordKey,
7001 7298 record,
@@ -7150,9 +7447,9 @@
7150 7447 const node = getNode(newTree, storePath);
7151 7448 node.locks = [...node.locks, lock2];
7152 7449 return {
7153 7450 ...state,
7154 - requests: state.requests.filter((r) => r !== request),
7451 + requests: state.requests.filter((r2) => r2 !== request),
7155 7452 tree: newTree
7156 7453 };
7157 7454 }
7158 7455 case "RELEASE_LOCK": {
@@ -7272,9 +7569,17 @@
7272 7569 ...parent?.[kind],
7273 7570 [name]: id
7274 7571 }
7275 7572 },
7276 - ...revisionId !== void 0 && { revisionId }
7573 + ...revisionId !== void 0 && kind && {
7574 + revision: {
7575 + ...parent?.revision,
7576 + [kind]: {
7577 + ...parent?.revision?.[kind],
7578 + [name]: revisionId
7579 + }
7580 + }
7581 + }
7277 7582 }),
7278 7583 [parent, kind, name, id, revisionId]
7279 7584 );
7280 7585 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EntityContext.Provider, { value: childContext, children });
@@ -7280,9 +7585,9 @@
7280 7585 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EntityContext.Provider, { value: childContext, children });
7281 7586 }
7282 7587
7283 7588 // packages/core-data/build-module/hooks/use-entity-record.mjs
7284 - var import_data10 = __toESM(require_data(), 1);
7589 + var import_data11 = __toESM(require_data(), 1);
7285 7590 var import_deprecated4 = __toESM(require_deprecated(), 1);
7286 7591 var import_element3 = __toESM(require_element(), 1);
7287 7592
7288 7593 // packages/core-data/build-module/hooks/constants.mjs
@@ -7320,9 +7625,9 @@
7320 7625
7321 7626 // packages/core-data/build-module/hooks/use-entity-record.mjs
7322 7627 var EMPTY_OBJECT3 = {};
7323 7628 function useEntityRecord(kind, name, recordId, options = { enabled: true }) {
7324 - const { editEntityRecord: editEntityRecord2, saveEditedEntityRecord: saveEditedEntityRecord2 } = (0, import_data10.useDispatch)(store);
7629 + const { editEntityRecord: editEntityRecord2, saveEditedEntityRecord: saveEditedEntityRecord2 } = (0, import_data11.useDispatch)(store);
7325 7630 const mutations = (0, import_element3.useMemo)(
7326 7631 () => ({
7327 7632 edit: (record2, editOptions = {}) => editEntityRecord2(kind, name, recordId, record2, editOptions),
7328 7633 save: (saveOptions = {}) => saveEditedEntityRecord2(kind, name, recordId, {
@@ -7331,10 +7636,10 @@
7331 7636 })
7332 7637 }),
7333 7638 [editEntityRecord2, kind, name, recordId, saveEditedEntityRecord2]
7334 7639 );
7335 - const { record, editedRecord, hasEdits, edits, ...resolution } = (0, import_data10.useSelect)(
7336 - (select4) => {
7640 + const { record, editedRecord, hasEdits, edits, ...resolution } = (0, import_data11.useSelect)(
7641 + (select5) => {
7337 7642 if (!options.enabled) {
7338 7643 return {
7339 7644 record: null,
7340 7645 editedRecord: EMPTY_OBJECT3,
@@ -7342,9 +7647,9 @@
7342 7647 edits: EMPTY_OBJECT3,
7343 7648 ...getResolutionStatus()
7344 7649 };
7345 7650 }
7346 - const storeSelectors = select4(store);
7651 + const storeSelectors = select5(store);
7347 7652 const resolutionStatus = storeSelectors.getResolutionState(
7348 7653 "getEntityRecord",
7349 7654 [kind, name, recordId]
7350 7655 )?.status;
@@ -7393,15 +7698,15 @@
7393 7698
7394 7699 // packages/core-data/build-module/hooks/use-entity-records.mjs
7395 7700 var import_url7 = __toESM(require_url(), 1);
7396 7701 var import_deprecated5 = __toESM(require_deprecated(), 1);
7397 - var import_data11 = __toESM(require_data(), 1);
7702 + var import_data12 = __toESM(require_data(), 1);
7398 7703 var import_element4 = __toESM(require_element(), 1);
7399 7704 var EMPTY_ARRAY = [];
7400 7705 function useEntityRecords(kind, name, queryArgs = {}, options = { enabled: true }) {
7401 7706 const queryAsString = (0, import_url7.addQueryArgs)("", queryArgs);
7402 - const { records, totalItems, totalPages, ...rest } = (0, import_data11.useSelect)(
7403 - (select4) => {
7707 + const { records, totalItems, totalPages, ...rest } = (0, import_data12.useSelect)(
7708 + (select5) => {
7404 7709 if (!options.enabled) {
7405 7710 return {
7406 7711 // Avoiding returning a new reference on every execution.
7407 7712 records: EMPTY_ARRAY,
@@ -7409,9 +7714,9 @@
7409 7714 totalPages: null,
7410 7715 ...getResolutionStatus()
7411 7716 };
7412 7717 }
7413 - const storeSelectors = select4(store);
7718 + const storeSelectors = select5(store);
7414 7719 const resolutionStatus = storeSelectors.getResolutionState(
7415 7720 "getEntityRecords",
7416 7721 [kind, name, queryArgs]
7417 7722 )?.status;
@@ -7450,10 +7755,10 @@
7450 7755 });
7451 7756 return useEntityRecords(kind, name, queryArgs, options);
7452 7757 }
7453 7758 function useEntityRecordsWithPermissions(kind, name, queryArgs = {}, options = { enabled: true }) {
7454 - const entityConfig = (0, import_data11.useSelect)(
7455 - (select4) => select4(store).getEntityConfig(kind, name),
7759 + const entityConfig = (0, import_data12.useSelect)(
7760 + (select5) => select5(store).getEntityConfig(kind, name),
7456 7761 [kind, name]
7457 7762 );
7458 7763 const { records: data, ...ret } = useEntityRecords(
7459 7764 kind,
@@ -7475,17 +7780,17 @@
7475 7780 options
7476 7781 );
7477 7782 const ids = (0, import_element4.useMemo)(
7478 7783 () => data?.map(
7479 - // @ts-ignore
7784 + // @ts-expect-error `data` is `unknown[]`, so the callback signature does not line up.
7480 7785 (record) => record[entityConfig?.key ?? "id"]
7481 7786 ) ?? [],
7482 7787 [data, entityConfig?.key]
7483 7788 );
7484 - const permissions = (0, import_data11.useSelect)(
7485 - (select4) => {
7789 + const permissions = (0, import_data12.useSelect)(
7790 + (select5) => {
7486 7791 const { getEntityRecordsPermissions: getEntityRecordsPermissions2 } = unlock(
7487 - select4(store)
7792 + select5(store)
7488 7793 );
7489 7794 return getEntityRecordsPermissions2(kind, name, ids);
7490 7795 },
7491 7796 [ids, kind, name]
@@ -7491,9 +7796,9 @@
7491 7796 [ids, kind, name]
7492 7797 );
7493 7798 const dataWithPermissions = (0, import_element4.useMemo)(
7494 7799 () => data?.map((record, index) => ({
7495 - // @ts-ignore
7800 + // @ts-expect-error `record` is `unknown`, which cannot be spread.
7496 7801 ...record,
7497 7802 permissions: permissions[index]
7498 7803 })) ?? [],
7499 7804 [data, permissions]
@@ -7505,9 +7810,9 @@
7505 7810 var import_deprecated6 = __toESM(require_deprecated(), 1);
7506 7811 var import_warning = __toESM(require_warning(), 1);
7507 7812
7508 7813 // packages/core-data/build-module/hooks/use-query-select.mjs
7509 - var import_data12 = __toESM(require_data(), 1);
7814 + var import_data13 = __toESM(require_data(), 1);
7510 7815
7511 7816 // node_modules/memize/dist/index.js
7512 7817 function memize(fn, options) {
7513 7818 var size = 0;
@@ -7584,10 +7889,10 @@
7584 7889 "isResolving",
7585 7890 "getCachedResolvers"
7586 7891 ];
7587 7892 function useQuerySelect(mapQuerySelect, deps) {
7588 - return (0, import_data12.useSelect)((select4, registry) => {
7589 - const resolve = (store2) => enrichSelectors(select4(store2));
7893 + return (0, import_data13.useSelect)((select5, registry) => {
7894 + const resolve = (store2) => enrichSelectors(select5(store2));
7590 7895 return mapQuerySelect(resolve, registry);
7591 7896 }, deps);
7592 7897 }
7593 7898 var enrichSelectors = memize(((selectors) => {
@@ -7680,10 +7985,10 @@
7680 7985 }
7681 7986
7682 7987 // packages/core-data/build-module/hooks/use-entity-block-editor.mjs
7683 7988 var import_element6 = __toESM(require_element(), 1);
7684 - var import_data13 = __toESM(require_data(), 1);
7685 - var import_blocks5 = __toESM(require_blocks(), 1);
7989 + var import_data14 = __toESM(require_data(), 1);
7990 + var import_blocks6 = __toESM(require_blocks(), 1);
7686 7991
7687 7992 // packages/core-data/build-module/hooks/use-entity-id.mjs
7688 7993 var import_element5 = __toESM(require_element(), 1);
7689 7994 function useEntityId(kind, name) {
@@ -7692,16 +7997,17 @@
7692 7997 }
7693 7998
7694 7999 // packages/core-data/build-module/footnotes/index.mjs
7695 8000 var import_rich_text4 = __toESM(require_rich_text(), 1);
8001 + var import_warning2 = __toESM(require_warning(), 1);
7696 8002
7697 8003 // packages/core-data/build-module/footnotes/get-rich-text-values-cached.mjs
7698 - var import_block_editor5 = __toESM(require_block_editor(), 1);
8004 + var import_block_editor6 = __toESM(require_block_editor(), 1);
7699 8005 var unlockedApis;
7700 8006 var cache = /* @__PURE__ */ new WeakMap();
7701 8007 function getRichTextValuesCached(block) {
7702 8008 if (!unlockedApis) {
7703 - unlockedApis = unlock(import_block_editor5.privateApis);
8009 + unlockedApis = unlock(import_block_editor6.privateApis);
7704 8010 }
7705 8011 if (!cache.has(block)) {
7706 8012 const values = unlockedApis.getRichTextValues([block]);
7707 8013 cache.set(block, values);
@@ -7742,9 +8048,19 @@
7742 8048 if (meta.footnotes === void 0) {
7743 8049 return output;
7744 8050 }
7745 8051 const newOrder = getFootnotesOrder(blocks);
7746 - const footnotes = meta.footnotes ? JSON.parse(meta.footnotes) : [];
8052 + let parsed;
8053 + try {
8054 + parsed = JSON.parse(meta.footnotes || "[]");
8055 + } catch {
8056 + }
8057 + let footnotes = [];
8058 + if (Array.isArray(parsed)) {
8059 + footnotes = parsed;
8060 + } else {
8061 + (0, import_warning2.default)("Footnotes post meta is not a JSON array; ignoring it.");
8062 + }
7747 8063 const currentOrder = footnotes.map((fn) => fn.id);
7748 8064 if (currentOrder.join("") === newOrder.join("")) {
7749 8065 return output;
7750 8066 }
@@ -7830,14 +8146,14 @@
7830 8146 var EMPTY_ARRAY2 = [];
7831 8147 function useEntityBlockEditor(kind, name, { id: _id } = {}) {
7832 8148 const providerId = useEntityId(kind, name);
7833 8149 const id = _id ?? providerId;
7834 - const { content, editedBlocks, meta } = (0, import_data13.useSelect)(
7835 - (select4) => {
8150 + const { content, editedBlocks, meta } = (0, import_data14.useSelect)(
8151 + (select5) => {
7836 8152 if (!id) {
7837 8153 return {};
7838 8154 }
7839 - const { getEditedEntityRecord: getEditedEntityRecord3 } = select4(STORE_NAME);
8155 + const { getEditedEntityRecord: getEditedEntityRecord3 } = select5(STORE_NAME);
7840 8156 const editedRecord = getEditedEntityRecord3(kind, name, id);
7841 8157 return {
7842 8158 editedBlocks: editedRecord.blocks,
7843 8159 content: editedRecord.content,
@@ -7845,9 +8161,9 @@
7845 8161 };
7846 8162 },
7847 8163 [kind, name, id]
7848 8164 );
7849 - const { __unstableCreateUndoLevel: __unstableCreateUndoLevel2, editEntityRecord: editEntityRecord2 } = (0, import_data13.useDispatch)(STORE_NAME);
8165 + const { __unstableCreateUndoLevel: __unstableCreateUndoLevel2, editEntityRecord: editEntityRecord2 } = (0, import_data14.useDispatch)(STORE_NAME);
7850 8166 const blocks = (0, import_element6.useMemo)(() => {
7851 8167 if (!id) {
7852 8168 return void 0;
7853 8169 }
@@ -7856,16 +8172,12 @@
7856 8172 }
7857 8173 if (!content || typeof content !== "string") {
7858 8174 return EMPTY_ARRAY2;
7859 8175 }
7860 - const cacheKey = getCacheKey(kind, name, id);
7861 - const cached = parsedBlocksCache.get(cacheKey);
7862 - let _blocks;
7863 - if (cached && cached.content === content) {
7864 - _blocks = cached.blocks;
7865 - } else {
7866 - _blocks = (0, import_blocks5.parse)(content);
7867 - parsedBlocksCache.set(cacheKey, { content, blocks: _blocks });
8176 + let _blocks = getCachedBlocks(kind, name, id, content);
8177 + if (!_blocks) {
8178 + _blocks = (0, import_blocks6.parse)(content);
8179 + setCachedBlocks(kind, name, id, content, _blocks);
7868 8180 }
7869 8181 return _blocks;
7870 8182 }, [kind, name, id, editedBlocks, content]);
7871 8183 const onChange = (0, import_element6.useCallback)(
@@ -7876,9 +8188,9 @@
7876 8188 }
7877 8189 const { selection, ...rest } = options;
7878 8190 const edits = {
7879 8191 selection,
7880 - content: ({ blocks: blocksForSerialization = [] }) => (0, import_blocks5.__unstableSerializeAndClean)(blocksForSerialization),
8192 + content: ({ blocks: blocksForSerialization = [] }) => (0, import_blocks6.__unstableSerializeAndClean)(blocksForSerialization),
7881 8193 ...updateFootnotesFromMeta(newBlocks, meta)
7882 8194 };
7883 8195 editEntityRecord2(kind, name, id, edits, {
7884 8196 isCached: false,
@@ -7913,41 +8225,39 @@
7913 8225 }
7914 8226
7915 8227 // packages/core-data/build-module/hooks/use-entity-prop.mjs
7916 8228 var import_element7 = __toESM(require_element(), 1);
7917 - var import_data14 = __toESM(require_data(), 1);
8229 + var import_data15 = __toESM(require_data(), 1);
8230 + var REVISION_QUERY = {
8231 + context: "edit",
8232 + _fields: "id,date,author,meta,title,excerpt,content.raw"
8233 + };
7918 8234 function useEntityProp(kind, name, prop, _id) {
7919 8235 const providerId = useEntityId(kind, name);
7920 8236 const id = _id ?? providerId;
7921 8237 const context = (0, import_element7.useContext)(EntityContext);
7922 - const revisionId = context?.revisionId;
7923 - const { value, fullValue } = (0, import_data14.useSelect)(
7924 - (select4) => {
8238 + const revisionId = String(id) === String(providerId) ? context?.revision?.[kind]?.[name] : void 0;
8239 + const { value, fullValue } = (0, import_data15.useSelect)(
8240 + (select5) => {
7925 8241 if (revisionId) {
7926 - const revisions = select4(STORE_NAME).getRevisions(
8242 + const revision = select5(STORE_NAME).getRevision(
7927 8243 kind,
7928 8244 name,
7929 8245 id,
7930 - {
7931 - per_page: -1,
7932 - context: "edit",
7933 - _fields: "id,date,author,meta,title.raw,excerpt.raw,content.raw"
7934 - }
8246 + revisionId,
8247 + REVISION_QUERY
7935 8248 );
7936 - const entityConfig = select4(STORE_NAME).getEntityConfig(
7937 - kind,
7938 - name
7939 - );
7940 - const revKey = entityConfig?.revisionKey || DEFAULT_ENTITY_KEY;
7941 - const revision = revisions?.find(
7942 - (r) => r[revKey] === revisionId
7943 - );
7944 - return revision ? {
7945 - value: revision[prop]?.raw ?? revision[prop],
7946 - fullValue: revision[prop]
7947 - } : {};
8249 + const propValue = revision?.[prop];
8250 + if (propValue === void 0) {
8251 + return {};
8252 + }
8253 + const isRawAttribute = propValue !== null && typeof propValue === "object" && "raw" in propValue;
8254 + return {
8255 + value: isRawAttribute ? propValue.raw : propValue,
8256 + fullValue: propValue
8257 + };
7948 8258 }
7949 - const { getEntityRecord: getEntityRecord3, getEditedEntityRecord: getEditedEntityRecord3 } = select4(STORE_NAME);
8259 + const { getEntityRecord: getEntityRecord3, getEditedEntityRecord: getEditedEntityRecord3 } = select5(STORE_NAME);
7950 8260 const record = getEntityRecord3(kind, name, id);
7951 8261 const editedRecord = getEditedEntityRecord3(kind, name, id);
7952 8262 return record && editedRecord ? {
7953 8263 value: editedRecord[prop],
@@ -7955,9 +8265,9 @@
7955 8265 } : {};
7956 8266 },
7957 8267 [kind, name, id, prop, revisionId]
7958 8268 );
7959 - const { editEntityRecord: editEntityRecord2 } = (0, import_data14.useDispatch)(STORE_NAME);
8269 + const { editEntityRecord: editEntityRecord2 } = (0, import_data15.useDispatch)(STORE_NAME);
7960 8270 const setValue = (0, import_element7.useCallback)(
7961 8271 (newValue) => {
7962 8272 if (revisionId) {
7963 8273 return;
@@ -7989,9 +8299,11 @@
7989 8299 }),
7990 8300 isCurrentCollaboratorDisconnected: false
7991 8301 };
7992 8302 function getAwarenessState(awareness, newState) {
7993 - const activeCollaborators = newState ?? awareness.getCurrentState();
8303 + const activeCollaborators = (newState ?? awareness.getCurrentState()).filter(
8304 + (collaborator) => isCollaboratorInfo(collaborator.collaboratorInfo)
8305 + );
7994 8306 return {
7995 8307 activeCollaborators,
7996 8308 resolveSelection: (selection, blocks) => awareness.convertSelectionStateToAbsolute(selection, blocks),
7997 8309 getDebugData: () => awareness.getDebugData(),
@@ -8149,12 +8461,700 @@
8149 8461 callback(lastPostSave, saver, prevPostSave ?? null);
8150 8462 }, [lastPostSave, prevPostSave, activeCollaborators, callback]);
8151 8463 }
8152 8464
8465 + // packages/icons/build-module/library/footer.mjs
8466 + var import_primitives = __toESM(require_primitives(), 1);
8467 + var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
8468 + var footer_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", style: { fill: "none" }, stroke: "currentColor", strokeWidth: "1.5", children: [
8469 + /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives.Path, { d: "M9.75 4.75H18C18.6904 4.75 19.25 5.30964 19.25 6V14.25M9.75 4.75H6C5.30964 4.75 4.75 5.30964 4.75 6V14.25M9.75 4.75V14.25M19.25 14.25V18C19.25 18.6904 18.6904 19.25 18 19.25H6C5.30964 19.25 4.75 18.6904 4.75 18V14.25M19.25 14.25H9.75M9.75 14.25H4.75", vectorEffect: "non-scaling-stroke" }),
8470 + /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives.Path, { d: "M19.25 15.5V18C19.25 18.6904 18.6904 19.25 18 19.25H6C5.30964 19.25 4.75 18.6904 4.75 18V15.5C4.75 14.8096 5.30964 14.25 6 14.25H18C18.6904 14.25 19.25 14.8096 19.25 15.5Z", fill: "currentColor", vectorEffect: "non-scaling-stroke" })
8471 + ] });
8472 +
8473 + // packages/icons/build-module/library/header.mjs
8474 + var import_primitives2 = __toESM(require_primitives(), 1);
8475 + var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
8476 + var header_default = /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_primitives2.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", style: { fill: "none" }, stroke: "currentColor", strokeWidth: "1.5", children: [
8477 + /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives2.Path, { d: "M9.75 19.25H18C18.6904 19.25 19.25 18.6904 19.25 18V9.75M9.75 19.25H6C5.30964 19.25 4.75 18.6904 4.75 18V9.75M9.75 19.25V9.75M19.25 9.75V6C19.25 5.30964 18.6904 4.75 18 4.75H6C5.30964 4.75 4.75 5.30964 4.75 6V9.75M19.25 9.75H9.75M9.75 9.75H4.75", vectorEffect: "non-scaling-stroke" }),
8478 + /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives2.Path, { d: "M19.25 8.5V6C19.25 5.30964 18.6904 4.75 18 4.75H6C5.30964 4.75 4.75 5.30964 4.75 6V8.5C4.75 9.19036 5.30964 9.75 6 9.75H18C18.6904 9.75 19.25 9.19036 19.25 8.5Z", fill: "currentColor", vectorEffect: "non-scaling-stroke" })
8479 + ] });
8480 +
8481 + // packages/icons/build-module/library/layout.mjs
8482 + var import_primitives3 = __toESM(require_primitives(), 1);
8483 + var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
8484 + var layout_default = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives3.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", style: { fill: "none" }, stroke: "currentColor", strokeWidth: "1.5", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives3.Path, { d: "M9.75 19.25H18C18.6904 19.25 19.25 18.6904 19.25 18V9.75M9.75 19.25H6C5.30964 19.25 4.75 18.6904 4.75 18V9.75M9.75 19.25V9.75M19.25 9.75V6C19.25 5.30964 18.6904 4.75 18 4.75H6C5.30964 4.75 4.75 5.30964 4.75 6V9.75M19.25 9.75H9.75M9.75 9.75H4.75", vectorEffect: "non-scaling-stroke" }) });
8485 +
8486 + // packages/icons/build-module/library/navigation-overlay.mjs
8487 + var import_primitives4 = __toESM(require_primitives(), 1);
8488 + var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
8489 + var navigation_overlay_default = /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_primitives4.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", style: { fill: "none" }, stroke: "currentColor", strokeWidth: "1.5", children: [
8490 + /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives4.Path, { d: "M4.75 9.25V16C4.75 16.6904 5.30964 17.25 6 17.25H8M4.75 9.25V6C4.75 5.30964 5.30964 4.75 6 4.75H16C16.6904 4.75 17.25 5.30964 17.25 6V8M4.75 9.25H8", vectorEffect: "non-scaling-stroke" }),
8491 + /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives4.Path, { d: "M10.75 11.25C10.75 10.9739 10.9739 10.75 11.25 10.75H18.75C19.0261 10.75 19.25 10.9739 19.25 11.25V18.75C19.25 19.0261 19.0261 19.25 18.75 19.25H11.25C10.9739 19.25 10.75 19.0261 10.75 18.75V11.25Z", fill: "currentColor", vectorEffect: "non-scaling-stroke" })
8492 + ] });
8493 +
8494 + // packages/icons/build-module/library/sidebar.mjs
8495 + var import_primitives5 = __toESM(require_primitives(), 1);
8496 + var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
8497 + var sidebar_default = /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_primitives5.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", style: { fill: "none" }, stroke: "currentColor", strokeWidth: "1.5", children: [
8498 + /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives5.Path, { d: "M9.75 19.25H18C18.6904 19.25 19.25 18.6904 19.25 18V9.75M9.75 19.25H6C5.30964 19.25 4.75 18.6904 4.75 18V9.75M9.75 19.25V9.75M19.25 9.75V6C19.25 5.30964 18.6904 4.75 18 4.75H6C5.30964 4.75 4.75 5.30964 4.75 6V9.75M19.25 9.75H9.75M9.75 9.75H4.75", vectorEffect: "non-scaling-stroke" }),
8499 + /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives5.Path, { d: "M6 19.25H9.75V9.75H4.75V18C4.75 18.6904 5.30964 19.25 6 19.25Z", fill: "currentColor", vectorEffect: "non-scaling-stroke" })
8500 + ] });
8501 +
8502 + // packages/icons/build-module/library/symbol-filled.mjs
8503 + var import_primitives6 = __toESM(require_primitives(), 1);
8504 + var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
8505 + var symbol_filled_default = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_primitives6.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", style: { fill: "none" }, stroke: "currentColor", strokeWidth: "1.5", children: [
8506 + /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives6.Path, { d: "M15.2071 6.20711L20.2929 11.2929C20.6834 11.6834 20.6834 12.3166 20.2929 12.7071L15.2071 17.7929C14.8166 18.1834 14.1834 18.1834 13.7929 17.7929L8.70711 12.7071C8.31658 12.3166 8.31658 11.6834 8.70711 11.2929L13.7929 6.20711C14.1834 5.81658 14.8166 5.81658 15.2071 6.20711Z", fill: "currentColor", vectorEffect: "non-scaling-stroke" }),
8507 + /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives6.Path, { d: "M9.5 5.5L3.70711 11.2929C3.31658 11.6834 3.31658 12.3166 3.70711 12.7071L9.5 18.5", vectorEffect: "non-scaling-stroke" })
8508 + ] });
8509 +
8510 + // packages/core-data/build-module/utils/get-template-part-icon.mjs
8511 + function getTemplatePartIcon(areaOrIconName) {
8512 + if ("header" === areaOrIconName) {
8513 + return header_default;
8514 + } else if ("footer" === areaOrIconName) {
8515 + return footer_default;
8516 + } else if ("sidebar" === areaOrIconName) {
8517 + return sidebar_default;
8518 + } else if ("navigation-overlay" === areaOrIconName) {
8519 + return navigation_overlay_default;
8520 + }
8521 + return symbol_filled_default;
8522 + }
8523 +
8524 + // packages/core-data/build-module/utils/get-template-info.mjs
8525 + var EMPTY_OBJECT4 = {};
8526 + var getTemplateInfo = (params) => {
8527 + if (!params) {
8528 + return EMPTY_OBJECT4;
8529 + }
8530 + const { templateTypes, templateAreas, template } = params;
8531 + const { description, slug, title, area } = template;
8532 + const { title: defaultTitle, description: defaultDescription } = Object.values(templateTypes).find((type) => type.slug === slug) ?? EMPTY_OBJECT4;
8533 + const templateTitle = typeof title === "string" ? title : title?.rendered;
8534 + const templateDescription = typeof description === "string" ? description : description?.raw;
8535 + const templateAreasWithIcon = templateAreas?.map((item) => ({
8536 + ...item,
8537 + icon: getTemplatePartIcon(item.icon)
8538 + }));
8539 + const templateIcon = templateAreasWithIcon?.find((item) => area === item.area)?.icon || layout_default;
8540 + return {
8541 + title: templateTitle && templateTitle !== slug ? templateTitle : defaultTitle || slug,
8542 + description: templateDescription || defaultDescription,
8543 + icon: templateIcon
8544 + };
8545 + };
8546 +
8547 + // node_modules/clsx/dist/clsx.mjs
8548 + function r(e) {
8549 + var t, f, n = "";
8550 + if ("string" == typeof e || "number" == typeof e) n += e;
8551 + else if ("object" == typeof e) if (Array.isArray(e)) {
8552 + var o = e.length;
8553 + for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
8554 + } else for (f in e) e[f] && (n && (n += " "), n += f);
8555 + return n;
8556 + }
8557 + function clsx() {
8558 + for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
8559 + return n;
8560 + }
8561 + var clsx_default = clsx;
8562 +
8563 + // packages/core-data/build-module/components/entities-saved-states/index.mjs
8564 + var import_components3 = __toESM(require_components(), 1);
8565 + var import_i18n7 = __toESM(require_i18n(), 1);
8566 + var import_element10 = __toESM(require_element(), 1);
8567 + var import_compose4 = __toESM(require_compose(), 1);
8568 + var import_data19 = __toESM(require_data(), 1);
8569 +
8570 + // packages/core-data/build-module/components/entities-saved-states/entity-type-list.mjs
8571 + var import_i18n6 = __toESM(require_i18n(), 1);
8572 + var import_data17 = __toESM(require_data(), 1);
8573 + var import_components2 = __toESM(require_components(), 1);
8574 +
8575 + // packages/global-styles-engine/build-module/utils/get-global-styles-changes.mjs
8576 + var import_i18n4 = __toESM(require_i18n(), 1);
8577 + var import_blocks7 = __toESM(require_blocks(), 1);
8578 + var globalStylesChangesCache = /* @__PURE__ */ new Map();
8579 + var EMPTY_ARRAY3 = [];
8580 + var translationMap = {
8581 + caption: (0, import_i18n4.__)("Caption"),
8582 + link: (0, import_i18n4.__)("Link"),
8583 + button: (0, import_i18n4.__)("Button"),
8584 + heading: (0, import_i18n4.__)("Heading"),
8585 + h1: (0, import_i18n4.__)("H1"),
8586 + h2: (0, import_i18n4.__)("H2"),
8587 + h3: (0, import_i18n4.__)("H3"),
8588 + h4: (0, import_i18n4.__)("H4"),
8589 + h5: (0, import_i18n4.__)("H5"),
8590 + h6: (0, import_i18n4.__)("H6"),
8591 + "settings.color": (0, import_i18n4.__)("Color"),
8592 + "settings.typography": (0, import_i18n4.__)("Typography"),
8593 + "settings.shadow": (0, import_i18n4.__)("Shadow"),
8594 + "settings.layout": (0, import_i18n4.__)("Layout"),
8595 + "styles.color": (0, import_i18n4.__)("Colors"),
8596 + "styles.spacing": (0, import_i18n4.__)("Spacing"),
8597 + "styles.background": (0, import_i18n4.__)("Background"),
8598 + "styles.typography": (0, import_i18n4.__)("Typography"),
8599 + "styles.border": (0, import_i18n4.__)("Border"),
8600 + "styles.shadow": (0, import_i18n4.__)("Shadow"),
8601 + "styles.outline": (0, import_i18n4.__)("Outline"),
8602 + "styles.filter": (0, import_i18n4.__)("Filter"),
8603 + "styles.dimensions": (0, import_i18n4.__)("Dimensions")
8604 + };
8605 + var getBlockNames = memize(
8606 + () => (0, import_blocks7.getBlockTypes)().reduce(
8607 + (accumulator, {
8608 + name,
8609 + title
8610 + }) => {
8611 + accumulator[name] = title;
8612 + return accumulator;
8613 + },
8614 + {}
8615 + )
8616 + );
8617 + var isObject = (obj) => obj !== null && typeof obj === "object";
8618 + function getTranslation(key) {
8619 + if (translationMap[key]) {
8620 + return translationMap[key];
8621 + }
8622 + const keyArray = key.split(".");
8623 + if (keyArray?.[0] === "blocks") {
8624 + const blockName = getBlockNames()?.[keyArray[1]];
8625 + return blockName || keyArray[1];
8626 + }
8627 + if (keyArray?.[0] === "elements") {
8628 + return translationMap[keyArray[1]] || keyArray[1];
8629 + }
8630 + return void 0;
8631 + }
8632 + function deepCompare(changedObject, originalObject, parentPath = "") {
8633 + if (!isObject(changedObject) && !isObject(originalObject)) {
8634 + return changedObject !== originalObject ? parentPath.split(".").slice(0, 2).join(".") : void 0;
8635 + }
8636 + changedObject = isObject(changedObject) ? changedObject : {};
8637 + originalObject = isObject(originalObject) ? originalObject : {};
8638 + const allKeys = /* @__PURE__ */ new Set([
8639 + ...Object.keys(changedObject),
8640 + ...Object.keys(originalObject)
8641 + ]);
8642 + let diffs = [];
8643 + for (const key of allKeys) {
8644 + const path = parentPath ? parentPath + "." + key : key;
8645 + const changedPath = deepCompare(
8646 + changedObject[key],
8647 + originalObject[key],
8648 + path
8649 + );
8650 + if (changedPath) {
8651 + diffs = diffs.concat(changedPath);
8652 + }
8653 + }
8654 + return diffs;
8655 + }
8656 + var COMPARED_STYLE_KEYS = [
8657 + "background",
8658 + "color",
8659 + "typography",
8660 + "spacing",
8661 + "border",
8662 + "shadow",
8663 + "outline",
8664 + "filter",
8665 + "dimensions"
8666 + ];
8667 + function pickComparedStyles(config) {
8668 + return Object.fromEntries(
8669 + COMPARED_STYLE_KEYS.map((key) => [key, config?.styles?.[key]])
8670 + );
8671 + }
8672 + function getGlobalStylesChangelist(next, previous) {
8673 + const cacheKey = JSON.stringify({ next, previous });
8674 + if (globalStylesChangesCache.has(cacheKey)) {
8675 + return globalStylesChangesCache.get(cacheKey);
8676 + }
8677 + const changedValueTree = deepCompare(
8678 + {
8679 + styles: pickComparedStyles(next),
8680 + blocks: next?.styles?.blocks,
8681 + elements: next?.styles?.elements,
8682 + settings: next?.settings
8683 + },
8684 + {
8685 + styles: pickComparedStyles(previous),
8686 + blocks: previous?.styles?.blocks,
8687 + elements: previous?.styles?.elements,
8688 + settings: previous?.settings
8689 + }
8690 + );
8691 + if (!changedValueTree || Array.isArray(changedValueTree) && !changedValueTree.length) {
8692 + globalStylesChangesCache.set(cacheKey, []);
8693 + return [];
8694 + }
8695 + const changedValueArray = Array.isArray(changedValueTree) ? changedValueTree : [changedValueTree];
8696 + const result = [...new Set(changedValueArray)].reduce((acc, curr) => {
8697 + const translation = getTranslation(curr);
8698 + if (translation) {
8699 + acc.push([curr.split(".")[0], translation]);
8700 + }
8701 + return acc;
8702 + }, []);
8703 + globalStylesChangesCache.set(cacheKey, result);
8704 + return result;
8705 + }
8706 + function getGlobalStylesChanges(next, previous, options = {}) {
8707 + let changeList = getGlobalStylesChangelist(next, previous);
8708 + const changesLength = changeList.length;
8709 + const { maxResults } = options;
8710 + if (changesLength) {
8711 + if (!!maxResults && changesLength > maxResults) {
8712 + changeList = changeList.slice(0, maxResults);
8713 + }
8714 + return Object.entries(
8715 + changeList.reduce((acc, curr) => {
8716 + const group = acc[curr[0]] || [];
8717 + if (!group.includes(curr[1])) {
8718 + acc[curr[0]] = [...group, curr[1]];
8719 + }
8720 + return acc;
8721 + }, {})
8722 + ).map(([key, changeValues]) => {
8723 + const changeValuesLength = changeValues.length;
8724 + const joinedChangesValue = changeValues.join(
8725 + /* translators: Used between list items, there is a space after the comma. */
8726 + (0, import_i18n4.__)(", ")
8727 + // eslint-disable-line @wordpress/i18n-no-flanking-whitespace
8728 + );
8729 + switch (key) {
8730 + case "blocks": {
8731 + return (0, import_i18n4.sprintf)(
8732 + // translators: %s: a list of block names separated by a comma.
8733 + (0, import_i18n4._n)("%s block.", "%s blocks.", changeValuesLength),
8734 + joinedChangesValue
8735 + );
8736 + }
8737 + case "elements": {
8738 + return (0, import_i18n4.sprintf)(
8739 + // translators: %s: a list of element names separated by a comma.
8740 + (0, import_i18n4._n)("%s element.", "%s elements.", changeValuesLength),
8741 + joinedChangesValue
8742 + );
8743 + }
8744 + case "settings": {
8745 + return (0, import_i18n4.sprintf)(
8746 + // translators: %s: a list of theme.json setting labels separated by a comma.
8747 + (0, import_i18n4.__)("%s settings."),
8748 + joinedChangesValue
8749 + );
8750 + }
8751 + case "styles": {
8752 + return (0, import_i18n4.sprintf)(
8753 + // translators: %s: a list of theme.json top-level styles labels separated by a comma.
8754 + (0, import_i18n4.__)("%s styles."),
8755 + joinedChangesValue
8756 + );
8757 + }
8758 + default: {
8759 + return (0, import_i18n4.sprintf)(
8760 + // translators: %s: a list of global styles changes separated by a comma.
8761 + (0, import_i18n4.__)("%s."),
8762 + joinedChangesValue
8763 + );
8764 + }
8765 + }
8766 + });
8767 + }
8768 + return EMPTY_ARRAY3;
8769 + }
8770 +
8771 + // packages/core-data/build-module/components/entities-saved-states/entity-record-item.mjs
8772 + var import_components = __toESM(require_components(), 1);
8773 + var import_i18n5 = __toESM(require_i18n(), 1);
8774 + var import_data16 = __toESM(require_data(), 1);
8775 + var import_html_entities4 = __toESM(require_html_entities(), 1);
8776 + var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
8777 + function EntityRecordItem({ record, checked, onChange }) {
8778 + const { name, kind, title, key } = record;
8779 + const { entityRecordTitle } = (0, import_data16.useSelect)(
8780 + (select5) => {
8781 + if ("postType" !== kind || "wp_template" !== name) {
8782 + return {
8783 + entityRecordTitle: title
8784 + };
8785 + }
8786 + const template = select5(STORE_NAME).getEditedEntityRecord(
8787 + kind,
8788 + name,
8789 + key
8790 + );
8791 + const { default_template_types: templateTypes = [] } = select5(STORE_NAME).getCurrentTheme() ?? {};
8792 + return {
8793 + entityRecordTitle: getTemplateInfo({
8794 + template,
8795 + templateTypes
8796 + }).title
8797 + };
8798 + },
8799 + [name, kind, title, key]
8800 + );
8801 + return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components.PanelRow, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
8802 + import_components.CheckboxControl,
8803 + {
8804 + label: (0, import_html_entities4.decodeEntities)(entityRecordTitle) || (0, import_i18n5.__)("Untitled"),
8805 + checked,
8806 + onChange,
8807 + className: "entities-saved-states__change-control"
8808 + }
8809 + ) }) });
8810 + }
8811 +
8812 + // packages/core-data/build-module/components/entities-saved-states/entity-type-list.mjs
8813 + var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
8814 + function getEntityDescription(entity2, count) {
8815 + switch (entity2) {
8816 + case "site":
8817 + return 1 === count ? (0, import_i18n6.__)("This change will affect your whole site.") : (0, import_i18n6.__)("These changes will affect your whole site.");
8818 + case "wp_template":
8819 + return (0, import_i18n6.__)(
8820 + "This change will affect other parts of your site that use this template."
8821 + );
8822 + case "page":
8823 + case "post":
8824 + return (0, import_i18n6.__)("The following has been modified.");
8825 + }
8826 + }
8827 + function GlobalStylesDescription({ record }) {
8828 + const { editedRecord, savedRecord } = (0, import_data17.useSelect)(
8829 + (select5) => {
8830 + const { getEditedEntityRecord: getEditedEntityRecord3, getEntityRecord: getEntityRecord3 } = select5(STORE_NAME);
8831 + return {
8832 + editedRecord: getEditedEntityRecord3(
8833 + record.kind,
8834 + record.name,
8835 + record.key
8836 + ),
8837 + savedRecord: getEntityRecord3(
8838 + record.kind,
8839 + record.name,
8840 + record.key
8841 + )
8842 + };
8843 + },
8844 + [record.kind, record.name, record.key]
8845 + );
8846 + const globalStylesChanges = getGlobalStylesChanges(
8847 + editedRecord,
8848 + savedRecord,
8849 + {
8850 + maxResults: 10
8851 + }
8852 + );
8853 + return globalStylesChanges.length ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("ul", { className: "entities-saved-states__changes", children: globalStylesChanges.map((change) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("li", { children: change }, change)) }) : null;
8854 + }
8855 + function EntityDescription({ record, count }) {
8856 + if ("globalStyles" === record?.name) {
8857 + return null;
8858 + }
8859 + const description = getEntityDescription(record?.name, count);
8860 + return description ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components2.PanelRow, { children: description }) : null;
8861 + }
8862 + function EntityTypeList({
8863 + list,
8864 + unselectedEntities,
8865 + setUnselectedEntities
8866 + }) {
8867 + const count = list.length;
8868 + const firstRecord = list[0];
8869 + const entityConfig = (0, import_data17.useSelect)(
8870 + (select5) => select5(STORE_NAME).getEntityConfig(
8871 + firstRecord.kind,
8872 + firstRecord.name
8873 + ),
8874 + [firstRecord.kind, firstRecord.name]
8875 + );
8876 + let entityLabel = entityConfig.label;
8877 + if (firstRecord?.name === "wp_template_part") {
8878 + entityLabel = 1 === count ? (0, import_i18n6.__)("Template Part") : (0, import_i18n6.__)("Template Parts");
8879 + }
8880 + return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
8881 + import_components2.PanelBody,
8882 + {
8883 + title: entityLabel,
8884 + initialOpen: true,
8885 + className: "entities-saved-states__panel-body",
8886 + children: [
8887 + /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(EntityDescription, { record: firstRecord, count }),
8888 + list.map((record) => {
8889 + return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
8890 + EntityRecordItem,
8891 + {
8892 + record,
8893 + checked: !unselectedEntities.some(
8894 + (elt) => elt.kind === record.kind && elt.name === record.name && elt.key === record.key && elt.property === record.property
8895 + ),
8896 + onChange: (value) => setUnselectedEntities(record, value)
8897 + },
8898 + record.key || record.property
8899 + );
8900 + }),
8901 + "globalStyles" === firstRecord?.name && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(GlobalStylesDescription, { record: firstRecord })
8902 + ]
8903 + }
8904 + );
8905 + }
8906 +
8907 + // packages/core-data/build-module/components/entities-saved-states/hooks/use-is-dirty.mjs
8908 + var import_data18 = __toESM(require_data(), 1);
8909 + var import_element9 = __toESM(require_element(), 1);
8910 + var useIsDirty = () => {
8911 + const { editedEntities, siteEdits, siteEntityConfig } = (0, import_data18.useSelect)(
8912 + (select5) => {
8913 + const {
8914 + __experimentalGetDirtyEntityRecords: __experimentalGetDirtyEntityRecords2,
8915 + getEntityRecordEdits: getEntityRecordEdits2,
8916 + getEntityConfig: getEntityConfig2
8917 + } = select5(STORE_NAME);
8918 + return {
8919 + editedEntities: __experimentalGetDirtyEntityRecords2(),
8920 + siteEdits: getEntityRecordEdits2("root", "site"),
8921 + siteEntityConfig: getEntityConfig2("root", "site")
8922 + };
8923 + },
8924 + []
8925 + );
8926 + const dirtyEntityRecords = (0, import_element9.useMemo)(() => {
8927 + const editedEntitiesWithoutSite = editedEntities.filter(
8928 + (record) => !(record.kind === "root" && record.name === "site")
8929 + );
8930 + const siteEntityLabels = siteEntityConfig?.meta?.labels ?? {};
8931 + const {
8932 + title: siteTitleEdit,
8933 + description: siteDescriptionEdit,
8934 + site_logo: siteLogoEdit,
8935 + site_icon: siteIconEdit,
8936 + ...otherSiteEdits
8937 + } = siteEdits ?? {};
8938 + const orderedSiteProperties = [
8939 + siteTitleEdit !== void 0 && "title",
8940 + siteDescriptionEdit !== void 0 && "description",
8941 + siteLogoEdit !== void 0 && "site_logo",
8942 + siteIconEdit !== void 0 && "site_icon",
8943 + ...Object.keys(otherSiteEdits)
8944 + ].filter(Boolean);
8945 + const editedSiteEntities = orderedSiteProperties.map(
8946 + (property) => ({
8947 + kind: "root",
8948 + name: "site",
8949 + title: siteEntityLabels[property] || property,
8950 + property
8951 + })
8952 + );
8953 + return [...editedEntitiesWithoutSite, ...editedSiteEntities];
8954 + }, [editedEntities, siteEdits, siteEntityConfig]);
8955 + const [unselectedEntities, _setUnselectedEntities] = (0, import_element9.useState)([]);
8956 + const setUnselectedEntities = ({ kind, name, key, property }, checked) => {
8957 + if (checked) {
8958 + _setUnselectedEntities(
8959 + unselectedEntities.filter(
8960 + (elt) => elt.kind !== kind || elt.name !== name || elt.key !== key || elt.property !== property
8961 + )
8962 + );
8963 + } else {
8964 + _setUnselectedEntities([
8965 + ...unselectedEntities,
8966 + { kind, name, key, property }
8967 + ]);
8968 + }
8969 + };
8970 + const isDirty = dirtyEntityRecords.length - unselectedEntities.length > 0;
8971 + return {
8972 + dirtyEntityRecords,
8973 + isDirty,
8974 + setUnselectedEntities,
8975 + unselectedEntities
8976 + };
8977 + };
8978 +
8979 + // packages/core-data/build-module/components/entities-saved-states/index.mjs
8980 + var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
8981 + function EntitiesSavedStates({
8982 + close,
8983 + renderDialog,
8984 + variant
8985 + }) {
8986 + const isDirtyProps = useIsDirty();
8987 + return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
8988 + EntitiesSavedStatesExtensible,
8989 + {
8990 + close,
8991 + renderDialog,
8992 + variant,
8993 + ...isDirtyProps
8994 + }
8995 + );
8996 + }
8997 + function EntitiesSavedStatesExtensible({
8998 + additionalPrompt = void 0,
8999 + close,
9000 + onSave = void 0,
9001 + saveEnabled: saveEnabledProp = void 0,
9002 + saveLabel = (0, import_i18n7.__)("Save"),
9003 + renderDialog,
9004 + dirtyEntityRecords,
9005 + isDirty,
9006 + setUnselectedEntities,
9007 + unselectedEntities,
9008 + variant = "default",
9009 + successNoticeContent
9010 + }) {
9011 + const saveButtonRef = (0, import_element10.useRef)();
9012 + const { saveDirtyEntities: saveDirtyEntities2 } = unlock((0, import_data19.useDispatch)(STORE_NAME));
9013 + const partitionedSavables = dirtyEntityRecords.reduce((acc, record) => {
9014 + const { name } = record;
9015 + if (!acc[name]) {
9016 + acc[name] = [];
9017 + }
9018 + acc[name].push(record);
9019 + return acc;
9020 + }, {});
9021 + const {
9022 + site: siteSavables,
9023 + wp_template: templateSavables,
9024 + wp_template_part: templatePartSavables,
9025 + ...contentSavables
9026 + } = partitionedSavables;
9027 + const sortedPartitionedSavables = [
9028 + siteSavables,
9029 + templateSavables,
9030 + templatePartSavables,
9031 + ...Object.values(contentSavables)
9032 + ].filter(Array.isArray);
9033 + const saveEnabled = saveEnabledProp ?? isDirty;
9034 + const dismissPanel = (0, import_element10.useCallback)(() => close(), [close]);
9035 + const [saveDialogRef, saveDialogProps] = (0, import_compose4.__experimentalUseDialog)({
9036 + onClose: () => dismissPanel()
9037 + });
9038 + const dialogLabelId = (0, import_compose4.useInstanceId)(
9039 + EntitiesSavedStatesExtensible,
9040 + "entities-saved-states__panel-label"
9041 + );
9042 + const dialogDescriptionId = (0, import_compose4.useInstanceId)(
9043 + EntitiesSavedStatesExtensible,
9044 + "entities-saved-states__panel-description"
9045 + );
9046 + const selectItemsToSaveDescription = !!dirtyEntityRecords.length ? (0, import_i18n7.__)("Select the items you want to save.") : void 0;
9047 + const isInline = variant === "inline";
9048 + const actionButtons = /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
9049 + /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9050 + import_components3.FlexItem,
9051 + {
9052 + isBlock: isInline ? false : true,
9053 + as: import_components3.Button,
9054 + variant: isInline ? "tertiary" : "secondary",
9055 + size: isInline ? void 0 : "compact",
9056 + onClick: dismissPanel,
9057 + children: (0, import_i18n7.__)("Cancel")
9058 + }
9059 + ),
9060 + /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9061 + import_components3.FlexItem,
9062 + {
9063 + isBlock: isInline ? false : true,
9064 + as: import_components3.Button,
9065 + ref: saveButtonRef,
9066 + variant: "primary",
9067 + size: isInline ? void 0 : "compact",
9068 + disabled: !saveEnabled,
9069 + accessibleWhenDisabled: true,
9070 + onClick: () => saveDirtyEntities2({
9071 + onSave,
9072 + dirtyEntityRecords,
9073 + entitiesToSkip: unselectedEntities,
9074 + close,
9075 + successNoticeContent
9076 + }),
9077 + className: "entities-saved-states__save-button",
9078 + children: saveLabel
9079 + }
9080 + )
9081 + ] });
9082 + return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
9083 + "div",
9084 + {
9085 + ref: renderDialog ? saveDialogRef : void 0,
9086 + ...renderDialog && saveDialogProps,
9087 + className: clsx_default("entities-saved-states__panel", {
9088 + "is-inline": isInline
9089 + }),
9090 + role: renderDialog ? "dialog" : void 0,
9091 + "aria-labelledby": renderDialog ? dialogLabelId : void 0,
9092 + "aria-describedby": renderDialog ? dialogDescriptionId : void 0,
9093 + children: [
9094 + !isInline && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_components3.Flex, { className: "entities-saved-states__panel-header", gap: 2, children: actionButtons }),
9095 + /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "entities-saved-states__text-prompt", children: [
9096 + /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "entities-saved-states__text-prompt--header-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9097 + "strong",
9098 + {
9099 + id: renderDialog ? dialogLabelId : void 0,
9100 + className: "entities-saved-states__text-prompt--header",
9101 + children: (0, import_i18n7.__)("Are you ready to save?")
9102 + }
9103 + ) }),
9104 + /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { id: renderDialog ? dialogDescriptionId : void 0, children: [
9105 + additionalPrompt,
9106 + /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "entities-saved-states__text-prompt--changes-count", children: isDirty ? (0, import_element10.createInterpolateElement)(
9107 + (0, import_i18n7.sprintf)(
9108 + /* translators: %d: number of site changes waiting to be saved. */
9109 + (0, import_i18n7._n)(
9110 + "There is <strong>%d site change</strong> waiting to be saved.",
9111 + "There are <strong>%d site changes</strong> waiting to be saved.",
9112 + dirtyEntityRecords.length
9113 + ),
9114 + dirtyEntityRecords.length
9115 + ),
9116 + { strong: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("strong", {}) }
9117 + ) : selectItemsToSaveDescription })
9118 + ] })
9119 + ] }),
9120 + sortedPartitionedSavables.map((list) => {
9121 + return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9122 + EntityTypeList,
9123 + {
9124 + list,
9125 + unselectedEntities,
9126 + setUnselectedEntities
9127 + },
9128 + list[0].name
9129 + );
9130 + }),
9131 + isInline && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9132 + import_components3.Flex,
9133 + {
9134 + direction: "row",
9135 + justify: "flex-end",
9136 + className: "entities-saved-states__panel-footer",
9137 + children: actionButtons
9138 + }
9139 + )
9140 + ]
9141 + }
9142 + );
9143 + }
9144 +
8153 9145 // packages/core-data/build-module/private-apis.mjs
8154 9146 var lockedApis = {
9147 + EntitiesSavedStates,
9148 + EntitiesSavedStatesExtensible,
9149 + getTemplateInfo,
9150 + getTemplatePartIcon,
9151 + useEntitiesSavedStatesIsDirty: useIsDirty,
8155 9152 useEntityRecordsWithPermissions,
8156 9153 RECEIVE_INTERMEDIATE_RESULTS,
9154 + CRDT_AUTOSAVE_SNAPSHOT_KEY,
9155 + entityContainsSnapshot,
9156 + getEntitySnapshot,
8157 9157 retrySyncConnection,
8158 9158 useActiveCollaborators,
8159 9159 useResolvedSelection,
8160 9160 useOnCollaboratorJoin,
@@ -8250,11 +9250,13 @@
8250 9250 ...entitySelectors
8251 9251 },
8252 9252 resolvers: { ...resolvers_exports, ...entityResolvers }
8253 9253 });
8254 - var store = (0, import_data15.createReduxStore)(STORE_NAME, storeConfig());
9254 + var store = (0, import_data20.createReduxStore)(STORE_NAME, storeConfig());
8255 9255 unlock(store).registerPrivateSelectors(private_selectors_exports);
8256 9256 unlock(store).registerPrivateActions(private_actions_exports);
8257 - (0, import_data15.register)(store);
9257 + (0, import_data20.register)(store);
8258 9258 return __toCommonJS(index_exports);
9259 +})();
9260 +(window.wp ||= {}).coreData = wp.coreData;
8259 9261 })();
8260 9262 //# sourceMappingURL=index.js.map