@wordpress/core-data 7.38.0 → 7.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/actions.cjs +17 -6
- package/build/actions.cjs.map +2 -2
- package/build/awareness/base-awareness.cjs +62 -0
- package/build/awareness/base-awareness.cjs.map +7 -0
- package/build/awareness/config.cjs +34 -0
- package/build/awareness/config.cjs.map +7 -0
- package/build/awareness/post-editor-awareness.cjs +130 -0
- package/build/awareness/post-editor-awareness.cjs.map +7 -0
- package/build/awareness/types.cjs +19 -0
- package/build/awareness/types.cjs.map +7 -0
- package/build/awareness/utils.cjs +116 -0
- package/build/awareness/utils.cjs.map +7 -0
- package/build/entities.cjs +27 -2
- package/build/entities.cjs.map +2 -2
- package/build/resolvers.cjs +43 -2
- package/build/resolvers.cjs.map +2 -2
- package/build/types.cjs.map +1 -1
- package/build/utils/block-selection-history.cjs +101 -0
- package/build/utils/block-selection-history.cjs.map +7 -0
- package/build/utils/crdt-selection.cjs +139 -0
- package/build/utils/crdt-selection.cjs.map +7 -0
- package/build/utils/crdt-user-selections.cjs +171 -0
- package/build/utils/crdt-user-selections.cjs.map +7 -0
- package/build/utils/crdt-utils.cjs +29 -0
- package/build/utils/crdt-utils.cjs.map +3 -3
- package/build/utils/crdt.cjs +16 -4
- package/build/utils/crdt.cjs.map +2 -2
- package/build-module/actions.mjs +17 -6
- package/build-module/actions.mjs.map +2 -2
- package/build-module/awareness/base-awareness.mjs +35 -0
- package/build-module/awareness/base-awareness.mjs.map +7 -0
- package/build-module/awareness/config.mjs +8 -0
- package/build-module/awareness/config.mjs.map +7 -0
- package/build-module/awareness/post-editor-awareness.mjs +111 -0
- package/build-module/awareness/post-editor-awareness.mjs.map +7 -0
- package/build-module/awareness/types.mjs +1 -0
- package/build-module/awareness/types.mjs.map +7 -0
- package/build-module/awareness/utils.mjs +90 -0
- package/build-module/awareness/utils.mjs.map +7 -0
- package/build-module/entities.mjs +28 -2
- package/build-module/entities.mjs.map +2 -2
- package/build-module/resolvers.mjs +43 -2
- package/build-module/resolvers.mjs.map +2 -2
- package/build-module/utils/block-selection-history.mjs +75 -0
- package/build-module/utils/block-selection-history.mjs.map +7 -0
- package/build-module/utils/crdt-selection.mjs +115 -0
- package/build-module/utils/crdt-selection.mjs.map +7 -0
- package/build-module/utils/crdt-user-selections.mjs +144 -0
- package/build-module/utils/crdt-user-selections.mjs.map +7 -0
- package/build-module/utils/crdt-utils.mjs +28 -0
- package/build-module/utils/crdt-utils.mjs.map +2 -2
- package/build-module/utils/crdt.mjs +18 -3
- package/build-module/utils/crdt.mjs.map +2 -2
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/awareness/base-awareness.d.ts +19 -0
- package/build-types/awareness/base-awareness.d.ts.map +1 -0
- package/build-types/awareness/config.d.ts +9 -0
- package/build-types/awareness/config.d.ts.map +1 -0
- package/build-types/awareness/post-editor-awareness.d.ts +38 -0
- package/build-types/awareness/post-editor-awareness.d.ts.map +1 -0
- package/build-types/awareness/types.d.ts +32 -0
- package/build-types/awareness/types.d.ts.map +1 -0
- package/build-types/awareness/utils.d.ts +22 -0
- package/build-types/awareness/utils.d.ts.map +1 -0
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/entity-types/test/attachment.test.d.ts +10 -0
- package/build-types/entity-types/test/attachment.test.d.ts.map +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/resolvers.d.ts.map +1 -1
- package/build-types/types.d.ts +12 -2
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils/block-selection-history.d.ts +47 -0
- package/build-types/utils/block-selection-history.d.ts.map +1 -0
- package/build-types/utils/crdt-selection.d.ts +16 -0
- package/build-types/utils/crdt-selection.d.ts.map +1 -0
- package/build-types/utils/crdt-user-selections.d.ts +66 -0
- package/build-types/utils/crdt-user-selections.d.ts.map +1 -0
- package/build-types/utils/crdt-utils.d.ts +12 -0
- package/build-types/utils/crdt-utils.d.ts.map +1 -1
- package/build-types/utils/crdt.d.ts +8 -14
- package/build-types/utils/crdt.d.ts.map +1 -1
- package/build-types/utils/test/block-selection-history.test.d.ts +2 -0
- package/build-types/utils/test/block-selection-history.test.d.ts.map +1 -0
- package/build-types/utils/test/crdt-blocks.d.ts +2 -0
- package/build-types/utils/test/crdt-blocks.d.ts.map +1 -0
- package/build-types/utils/test/crdt.d.ts +2 -0
- package/build-types/utils/test/crdt.d.ts.map +1 -0
- package/package.json +21 -18
- package/src/actions.js +40 -7
- package/src/awareness/base-awareness.ts +50 -0
- package/src/awareness/config.ts +9 -0
- package/src/awareness/post-editor-awareness.ts +167 -0
- package/src/awareness/types.ts +38 -0
- package/src/awareness/utils.ts +159 -0
- package/src/entities.js +32 -2
- package/src/entity-types/test/attachment.test.ts +4 -4
- package/src/resolvers.js +53 -1
- package/src/test/actions.js +402 -0
- package/src/test/entity-provider.js +2 -0
- package/src/test/resolvers.js +4 -0
- package/src/types.ts +12 -3
- package/src/utils/block-selection-history.ts +176 -0
- package/src/utils/crdt-selection.ts +205 -0
- package/src/utils/crdt-user-selections.ts +336 -0
- package/src/utils/crdt-utils.ts +54 -0
- package/src/utils/crdt.ts +36 -3
- package/src/utils/test/block-selection-history.test.ts +764 -0
- package/src/utils/test/crdt-blocks.ts +11 -4
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/core-data/src/awareness/utils.ts
|
|
21
|
+
var utils_exports = {};
|
|
22
|
+
__export(utils_exports, {
|
|
23
|
+
areUserInfosEqual: () => areUserInfosEqual,
|
|
24
|
+
generateUserInfo: () => generateUserInfo
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(utils_exports);
|
|
27
|
+
var COLOR_PALETTE = [
|
|
28
|
+
"#3858E9",
|
|
29
|
+
// blueberry
|
|
30
|
+
"#B42AED",
|
|
31
|
+
// purple
|
|
32
|
+
"#E33184",
|
|
33
|
+
// pink
|
|
34
|
+
"#F3661D",
|
|
35
|
+
// orange
|
|
36
|
+
"#ECBD3A",
|
|
37
|
+
// yellow
|
|
38
|
+
"#97FE17",
|
|
39
|
+
// green
|
|
40
|
+
"#00FDD9",
|
|
41
|
+
// teal
|
|
42
|
+
"#37C5F0"
|
|
43
|
+
// cyan
|
|
44
|
+
];
|
|
45
|
+
function generateRandomInt(min, max) {
|
|
46
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
47
|
+
}
|
|
48
|
+
function getNewUserColor(existingColors) {
|
|
49
|
+
const availableColors = COLOR_PALETTE.filter(
|
|
50
|
+
(color) => !existingColors.includes(color)
|
|
51
|
+
);
|
|
52
|
+
let hexColor;
|
|
53
|
+
if (availableColors.length > 0) {
|
|
54
|
+
const randomIndex = generateRandomInt(0, availableColors.length - 1);
|
|
55
|
+
hexColor = availableColors[randomIndex];
|
|
56
|
+
} else {
|
|
57
|
+
const randomIndex = generateRandomInt(0, COLOR_PALETTE.length - 1);
|
|
58
|
+
const baseColor = COLOR_PALETTE[randomIndex];
|
|
59
|
+
hexColor = generateColorVariation(baseColor);
|
|
60
|
+
}
|
|
61
|
+
return hexColor;
|
|
62
|
+
}
|
|
63
|
+
function generateColorVariation(hexColor) {
|
|
64
|
+
const r = parseInt(hexColor.slice(1, 3), 16);
|
|
65
|
+
const g = parseInt(hexColor.slice(3, 5), 16);
|
|
66
|
+
const b = parseInt(hexColor.slice(5, 7), 16);
|
|
67
|
+
const shift = generateRandomInt(-30, 30);
|
|
68
|
+
const newR = Math.min(255, Math.max(0, r + shift));
|
|
69
|
+
const newG = Math.min(255, Math.max(0, g + shift));
|
|
70
|
+
const newB = Math.min(255, Math.max(0, b + shift));
|
|
71
|
+
const toHex = (n) => n.toString(16).padStart(2, "0").toUpperCase();
|
|
72
|
+
return `#${toHex(newR)}${toHex(newG)}${toHex(newB)}`;
|
|
73
|
+
}
|
|
74
|
+
function getBrowserName() {
|
|
75
|
+
const userAgent = window.navigator.userAgent;
|
|
76
|
+
let browserName = "Unknown";
|
|
77
|
+
if (userAgent.includes("Firefox")) {
|
|
78
|
+
browserName = "Firefox";
|
|
79
|
+
} else if (userAgent.includes("Edg")) {
|
|
80
|
+
browserName = "Microsoft Edge";
|
|
81
|
+
} else if (userAgent.includes("Chrome") && !userAgent.includes("Edg")) {
|
|
82
|
+
browserName = "Chrome";
|
|
83
|
+
} else if (userAgent.includes("Safari") && !userAgent.includes("Chrome")) {
|
|
84
|
+
browserName = "Safari";
|
|
85
|
+
} else if (userAgent.includes("MSIE") || userAgent.includes("Trident")) {
|
|
86
|
+
browserName = "Internet Explorer";
|
|
87
|
+
} else if (userAgent.includes("Opera") || userAgent.includes("OPR")) {
|
|
88
|
+
browserName = "Opera";
|
|
89
|
+
}
|
|
90
|
+
return browserName;
|
|
91
|
+
}
|
|
92
|
+
function areUserInfosEqual(userInfo1, userInfo2) {
|
|
93
|
+
if (!userInfo1 || !userInfo2) {
|
|
94
|
+
return userInfo1 === userInfo2;
|
|
95
|
+
}
|
|
96
|
+
if (Object.keys(userInfo1).length !== Object.keys(userInfo2).length) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return Object.entries(userInfo1).every(([key, value]) => {
|
|
100
|
+
return value === userInfo2[key];
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function generateUserInfo(currentUser, existingColors) {
|
|
104
|
+
return {
|
|
105
|
+
...currentUser,
|
|
106
|
+
browserType: getBrowserName(),
|
|
107
|
+
color: getNewUserColor(existingColors),
|
|
108
|
+
enteredAt: Date.now()
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {
|
|
113
|
+
areUserInfosEqual,
|
|
114
|
+
generateUserInfo
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/awareness/utils.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { User } from '../entity-types';\nimport type { UserInfo } from './types';\n\n/**\n * The color palette for the user highlight.\n */\nconst COLOR_PALETTE = [\n\t'#3858E9', // blueberry\n\t'#B42AED', // purple\n\t'#E33184', // pink\n\t'#F3661D', // orange\n\t'#ECBD3A', // yellow\n\t'#97FE17', // green\n\t'#00FDD9', // teal\n\t'#37C5F0', // cyan\n];\n\n/**\n * Generate a random integer between min and max, inclusive.\n *\n * @param min - The minimum value.\n * @param max - The maximum value.\n * @return A random integer between min and max.\n */\nfunction generateRandomInt( min: number, max: number ): number {\n\treturn Math.floor( Math.random() * ( max - min + 1 ) ) + min;\n}\n\n/**\n * Get a unique user color from the palette, or generate a variation if none are available.\n * If the previously used color is available from localStorage, use it.\n *\n * @param existingColors - Colors that are already in use.\n * @return The new user color, in hex format.\n */\nfunction getNewUserColor( existingColors: string[] ): string {\n\tconst availableColors = COLOR_PALETTE.filter(\n\t\t( color ) => ! existingColors.includes( color )\n\t);\n\n\tlet hexColor: string;\n\n\tif ( availableColors.length > 0 ) {\n\t\tconst randomIndex = generateRandomInt( 0, availableColors.length - 1 );\n\t\thexColor = availableColors[ randomIndex ];\n\t} else {\n\t\t// All colors are used, generate a variation of a random palette color\n\t\tconst randomIndex = generateRandomInt( 0, COLOR_PALETTE.length - 1 );\n\t\tconst baseColor = COLOR_PALETTE[ randomIndex ];\n\t\thexColor = generateColorVariation( baseColor );\n\t}\n\n\treturn hexColor;\n}\n\n/**\n * Generate a variation of a hex color by adjusting its lightness.\n *\n * @param hexColor - The base hex color (e.g., '#3858E9').\n * @return A varied hex color.\n */\nfunction generateColorVariation( hexColor: string ): string {\n\t// Parse hex to RGB\n\tconst r = parseInt( hexColor.slice( 1, 3 ), 16 );\n\tconst g = parseInt( hexColor.slice( 3, 5 ), 16 );\n\tconst b = parseInt( hexColor.slice( 5, 7 ), 16 );\n\n\t// Apply a random lightness shift (-30 to +30)\n\tconst shift = generateRandomInt( -30, 30 );\n\tconst newR = Math.min( 255, Math.max( 0, r + shift ) );\n\tconst newG = Math.min( 255, Math.max( 0, g + shift ) );\n\tconst newB = Math.min( 255, Math.max( 0, b + shift ) );\n\n\t// Convert back to hex\n\tconst toHex = ( n: number ) =>\n\t\tn.toString( 16 ).padStart( 2, '0' ).toUpperCase();\n\treturn `#${ toHex( newR ) }${ toHex( newG ) }${ toHex( newB ) }`;\n}\n\n/**\n * Get the browser name from the user agent.\n * @return The browser name.\n */\nfunction getBrowserName(): string {\n\tconst userAgent = window.navigator.userAgent;\n\tlet browserName = 'Unknown';\n\n\tif ( userAgent.includes( 'Firefox' ) ) {\n\t\tbrowserName = 'Firefox';\n\t} else if ( userAgent.includes( 'Edg' ) ) {\n\t\tbrowserName = 'Microsoft Edge';\n\t} else if (\n\t\tuserAgent.includes( 'Chrome' ) &&\n\t\t! userAgent.includes( 'Edg' )\n\t) {\n\t\tbrowserName = 'Chrome';\n\t} else if (\n\t\tuserAgent.includes( 'Safari' ) &&\n\t\t! userAgent.includes( 'Chrome' )\n\t) {\n\t\tbrowserName = 'Safari';\n\t} else if (\n\t\tuserAgent.includes( 'MSIE' ) ||\n\t\tuserAgent.includes( 'Trident' )\n\t) {\n\t\tbrowserName = 'Internet Explorer';\n\t} else if ( userAgent.includes( 'Opera' ) || userAgent.includes( 'OPR' ) ) {\n\t\tbrowserName = 'Opera';\n\t}\n\n\treturn browserName;\n}\n\n/**\n * Check if two user infos are equal.\n *\n * @param userInfo1 - The first user info.\n * @param userInfo2 - The second user info.\n * @return True if the user infos are equal, false otherwise.\n */\nexport function areUserInfosEqual(\n\tuserInfo1?: UserInfo,\n\tuserInfo2?: UserInfo\n): boolean {\n\tif ( ! userInfo1 || ! userInfo2 ) {\n\t\treturn userInfo1 === userInfo2;\n\t}\n\n\tif ( Object.keys( userInfo1 ).length !== Object.keys( userInfo2 ).length ) {\n\t\treturn false;\n\t}\n\n\treturn Object.entries( userInfo1 ).every( ( [ key, value ] ) => {\n\t\t// Update this function with any non-primitive fields added to UserInfo.\n\t\treturn value === userInfo2[ key as keyof UserInfo ];\n\t} );\n}\n\n/**\n * Generate a user info object from a current user and a list of existing colors.\n *\n * @param currentUser - The current user.\n * @param existingColors - The existing colors.\n * @return The user info object.\n */\nexport function generateUserInfo(\n\tcurrentUser: User< 'view' >,\n\texistingColors: string[]\n): UserInfo {\n\treturn {\n\t\t...currentUser,\n\t\tbrowserType: getBrowserName(),\n\t\tcolor: getNewUserColor( existingColors ),\n\t\tenteredAt: Date.now(),\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,IAAM,gBAAgB;AAAA,EACrB;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AACD;AASA,SAAS,kBAAmB,KAAa,KAAsB;AAC9D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AAA,EACf,WAAY,UAAU,SAAU,KAAM,GAAI;AACzC,kBAAc;AAAA,EACf,WACC,UAAU,SAAU,QAAS,KAC7B,CAAE,UAAU,SAAU,KAAM,GAC3B;AACD,kBAAc;AAAA,EACf,WACC,UAAU,SAAU,QAAS,KAC7B,CAAE,UAAU,SAAU,QAAS,GAC9B;AACD,kBAAc;AAAA,EACf,WACC,UAAU,SAAU,MAAO,KAC3B,UAAU,SAAU,SAAU,GAC7B;AACD,kBAAc;AAAA,EACf,WAAY,UAAU,SAAU,OAAQ,KAAK,UAAU,SAAU,KAAM,GAAI;AAC1E,kBAAc;AAAA,EACf;AAEA,SAAO;AACR;AASO,SAAS,kBACf,WACA,WACU;AACV,MAAK,CAAE,aAAa,CAAE,WAAY;AACjC,WAAO,cAAc;AAAA,EACtB;AAEA,MAAK,OAAO,KAAM,SAAU,EAAE,WAAW,OAAO,KAAM,SAAU,EAAE,QAAS;AAC1E,WAAO;AAAA,EACR;AAEA,SAAO,OAAO,QAAS,SAAU,EAAE,MAAO,CAAE,CAAE,KAAK,KAAM,MAAO;AAE/D,WAAO,UAAU,UAAW,GAAsB;AAAA,EACnD,CAAE;AACH;AASO,SAAS,iBACf,aACA,gBACW;AACX,SAAO;AAAA,IACN,GAAG;AAAA,IACH,aAAa,eAAe;AAAA,IAC5B,OAAO,gBAAiB,cAAe;AAAA,IACvC,WAAW,KAAK,IAAI;AAAA,EACrB;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/entities.cjs
CHANGED
|
@@ -42,6 +42,7 @@ var import_change_case = require("change-case");
|
|
|
42
42
|
var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
|
|
43
43
|
var import_blocks = require("@wordpress/blocks");
|
|
44
44
|
var import_i18n = require("@wordpress/i18n");
|
|
45
|
+
var import_post_editor_awareness = require("./awareness/post-editor-awareness.cjs");
|
|
45
46
|
var import_sync = require("./sync.cjs");
|
|
46
47
|
var import_crdt = require("./utils/crdt.cjs");
|
|
47
48
|
var DEFAULT_ENTITY_KEY = "id";
|
|
@@ -239,7 +240,15 @@ var rootEntitiesConfig = [
|
|
|
239
240
|
plural: "fontCollections",
|
|
240
241
|
key: "slug"
|
|
241
242
|
}
|
|
242
|
-
]
|
|
243
|
+
].map((entity) => {
|
|
244
|
+
const syncEnabledRootEntities = /* @__PURE__ */ new Set(["comment"]);
|
|
245
|
+
if (globalThis.IS_GUTENBERG_PLUGIN) {
|
|
246
|
+
if (syncEnabledRootEntities.has(entity.name)) {
|
|
247
|
+
entity.syncConfig = import_crdt.defaultSyncConfig;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return entity;
|
|
251
|
+
});
|
|
243
252
|
var deprecatedEntities = {
|
|
244
253
|
root: {
|
|
245
254
|
media: {
|
|
@@ -323,6 +332,18 @@ async function loadPostTypeEntities() {
|
|
|
323
332
|
* @return {void}
|
|
324
333
|
*/
|
|
325
334
|
applyChangesToCRDTDoc: (crdtDoc, changes) => (0, import_crdt.applyPostChangesToCRDTDoc)(crdtDoc, changes, postType),
|
|
335
|
+
/**
|
|
336
|
+
* Create the awareness instance for the entity's CRDT document.
|
|
337
|
+
*
|
|
338
|
+
* @param {import('@wordpress/sync').CRDTDoc} ydoc
|
|
339
|
+
* @param {import('@wordpress/sync').ObjectID} objectId
|
|
340
|
+
* @return {import('@wordpress/sync').AwarenessState} AwarenessState instance
|
|
341
|
+
*/
|
|
342
|
+
createAwareness: (ydoc, objectId) => {
|
|
343
|
+
const kind = "postType";
|
|
344
|
+
const id = parseInt(objectId, 10);
|
|
345
|
+
return new import_post_editor_awareness.PostEditorAwareness(ydoc, kind, name, id);
|
|
346
|
+
},
|
|
326
347
|
/**
|
|
327
348
|
* Extract changes from a CRDT document that can be used to update the
|
|
328
349
|
* local editor state.
|
|
@@ -355,7 +376,7 @@ async function loadTaxonomyEntities() {
|
|
|
355
376
|
});
|
|
356
377
|
return Object.entries(taxonomies ?? {}).map(([name, taxonomy]) => {
|
|
357
378
|
const namespace = taxonomy?.rest_namespace ?? "wp/v2";
|
|
358
|
-
|
|
379
|
+
const entity = {
|
|
359
380
|
kind: "taxonomy",
|
|
360
381
|
baseURL: `/${namespace}/${taxonomy.rest_base}`,
|
|
361
382
|
baseURLParams: { context: "edit" },
|
|
@@ -364,6 +385,10 @@ async function loadTaxonomyEntities() {
|
|
|
364
385
|
getTitle: (record) => record?.name,
|
|
365
386
|
supportsPagination: true
|
|
366
387
|
};
|
|
388
|
+
if (globalThis.IS_GUTENBERG_PLUGIN) {
|
|
389
|
+
entity.syncConfig = import_crdt.defaultSyncConfig;
|
|
390
|
+
}
|
|
391
|
+
return entity;
|
|
367
392
|
});
|
|
368
393
|
}
|
|
369
394
|
async function loadSiteEntity() {
|
package/build/entities.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/entities.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { capitalCase, pascalCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { __unstableSerializeAndClean, parse } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { getSyncManager } from './sync';\nimport {\n\tapplyPostChangesToCRDTDoc,\n\tgetPostChangesFromCRDTDoc,\n} from './utils/crdt';\n\nexport const DEFAULT_ENTITY_KEY = 'id';\nconst POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];\n\nconst blocksTransientEdits = {\n\tblocks: {\n\t\tread: ( record ) => parse( record.content?.raw ?? '' ),\n\t\twrite: ( record ) => ( {\n\t\t\tcontent: __unstableSerializeAndClean( record.blocks ),\n\t\t} ),\n\t},\n};\n\nexport const rootEntitiesConfig = [\n\t{\n\t\tlabel: __( 'Base' ),\n\t\tkind: 'root',\n\t\tkey: false,\n\t\tname: '__unstableBase',\n\t\tbaseURL: '/',\n\t\tbaseURLParams: {\n\t\t\t// Please also change the preload path when changing this.\n\t\t\t// @see lib/compat/wordpress-6.8/preload.php\n\t\t\t_fields: [\n\t\t\t\t'description',\n\t\t\t\t'gmt_offset',\n\t\t\t\t'home',\n\t\t\t\t'name',\n\t\t\t\t'site_icon',\n\t\t\t\t'site_icon_url',\n\t\t\t\t'site_logo',\n\t\t\t\t'timezone_string',\n\t\t\t\t'url',\n\t\t\t\t'page_for_posts',\n\t\t\t\t'page_on_front',\n\t\t\t\t'show_on_front',\n\t\t\t].join( ',' ),\n\t\t},\n\t\t// The entity doesn't support selecting multiple records.\n\t\t// The property is maintained for backward compatibility.\n\t\tplural: '__unstableBases',\n\t},\n\t{\n\t\tlabel: __( 'Post Type' ),\n\t\tname: 'postType',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'postTypes',\n\t},\n\t{\n\t\tname: 'media',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/media',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'mediaItems',\n\t\tlabel: __( 'Media' ),\n\t\trawAttributes: [ 'caption', 'title', 'description' ],\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'taxonomy',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/taxonomies',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'taxonomies',\n\t\tlabel: __( 'Taxonomy' ),\n\t},\n\t{\n\t\tname: 'sidebar',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/sidebars',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'sidebars',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widget areas' ),\n\t},\n\t{\n\t\tname: 'widget',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widgets',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgets',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widgets' ),\n\t},\n\t{\n\t\tname: 'widgetType',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widget-types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgetTypes',\n\t\tlabel: __( 'Widget types' ),\n\t},\n\t{\n\t\tlabel: __( 'User' ),\n\t\tname: 'user',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/users',\n\t\tgetTitle: ( record ) => record?.name || record?.slug,\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'users',\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'comment',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/comments',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'comments',\n\t\tlabel: __( 'Comment' ),\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menu',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menus',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menus',\n\t\tlabel: __( 'Menu' ),\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menuItem',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-items',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuItems',\n\t\tlabel: __( 'Menu Item' ),\n\t\trawAttributes: [ 'title' ],\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menuLocation',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-locations',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuLocations',\n\t\tlabel: __( 'Menu Location' ),\n\t\tkey: 'name',\n\t},\n\t{\n\t\tlabel: __( 'Global Styles' ),\n\t\tname: 'globalStyles',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/global-styles',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'globalStylesVariations', // Should be different from name.\n\t\tgetTitle: () => __( 'Custom Styles' ),\n\t\tgetRevisionsUrl: ( parentId, revisionId ) =>\n\t\t\t`/wp/v2/global-styles/${ parentId }/revisions${\n\t\t\t\trevisionId ? '/' + revisionId : ''\n\t\t\t}`,\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tlabel: __( 'Themes' ),\n\t\tname: 'theme',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/themes',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'themes',\n\t\tkey: 'stylesheet',\n\t},\n\t{\n\t\tlabel: __( 'Plugins' ),\n\t\tname: 'plugin',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/plugins',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'plugins',\n\t\tkey: 'plugin',\n\t},\n\t{\n\t\tlabel: __( 'Status' ),\n\t\tname: 'status',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/statuses',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'statuses',\n\t\tkey: 'slug',\n\t},\n\t{\n\t\tlabel: __( 'Registered Templates' ),\n\t\tname: 'registeredTemplate',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/registered-templates',\n\t\tkey: 'id',\n\t},\n\t{\n\t\tlabel: __( 'Font Collections' ),\n\t\tname: 'fontCollection',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/font-collections',\n\t\tbaseURLParams: { context: 'view' },\n\t\tplural: 'fontCollections',\n\t\tkey: 'slug',\n\t},\n];\n\nexport const deprecatedEntities = {\n\troot: {\n\t\tmedia: {\n\t\t\tsince: '6.9',\n\t\t\talternative: {\n\t\t\t\tkind: 'postType',\n\t\t\t\tname: 'attachment',\n\t\t\t},\n\t\t},\n\t},\n};\n\nexport const additionalEntityConfigLoaders = [\n\t{ kind: 'postType', loadEntities: loadPostTypeEntities },\n\t{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },\n\t{\n\t\tkind: 'root',\n\t\tname: 'site',\n\t\tplural: 'sites',\n\t\tloadEntities: loadSiteEntity,\n\t},\n];\n\n/**\n * Apply extra edits before persisting a post type.\n *\n * @param {Object} persistedRecord Already persisted Post\n * @param {Object} edits Edits.\n * @param {string} name Post type name.\n * @param {boolean} isTemplate Whether the post type is a template.\n * @return {Object} Updated edits.\n */\nexport const prePersistPostType = (\n\tpersistedRecord,\n\tedits,\n\tname,\n\tisTemplate\n) => {\n\tconst newEdits = {};\n\n\tif ( ! isTemplate && persistedRecord?.status === 'auto-draft' ) {\n\t\t// Saving an auto-draft should create a draft by default.\n\t\tif ( ! edits.status && ! newEdits.status ) {\n\t\t\tnewEdits.status = 'draft';\n\t\t}\n\n\t\t// Fix the auto-draft default title.\n\t\tif (\n\t\t\t( ! edits.title || edits.title === 'Auto Draft' ) &&\n\t\t\t! newEdits.title &&\n\t\t\t( ! persistedRecord?.title ||\n\t\t\t\tpersistedRecord?.title === 'Auto Draft' )\n\t\t) {\n\t\t\tnewEdits.title = '';\n\t\t}\n\t}\n\n\t// Add meta for persisted CRDT document.\n\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\tif ( persistedRecord ) {\n\t\t\tconst objectType = `postType/${ name }`;\n\t\t\tconst objectId = persistedRecord.id;\n\t\t\tconst meta = getSyncManager()?.createMeta( objectType, objectId );\n\t\t\tnewEdits.meta = {\n\t\t\t\t...edits.meta,\n\t\t\t\t...meta,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn newEdits;\n};\n\n/**\n * Returns the list of post type entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadPostTypeEntities() {\n\tconst postTypes = await apiFetch( {\n\t\tpath: '/wp/v2/types?context=view',\n\t} );\n\treturn Object.entries( postTypes ?? {} ).map( ( [ name, postType ] ) => {\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tname\n\t\t);\n\t\tconst namespace = postType?.rest_namespace ?? 'wp/v2';\n\n\t\tconst entity = {\n\t\t\tkind: 'postType',\n\t\t\tbaseURL: `/${ namespace }/${ postType.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: postType.name,\n\t\t\ttransientEdits: {\n\t\t\t\t...blocksTransientEdits,\n\t\t\t\tselection: true,\n\t\t\t},\n\t\t\tmergedEdits: { meta: true },\n\t\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t\t\tgetTitle: ( record ) =>\n\t\t\t\trecord?.title?.rendered ||\n\t\t\t\trecord?.title ||\n\t\t\t\t( isTemplate\n\t\t\t\t\t? capitalCase( record.slug ?? '' )\n\t\t\t\t\t: String( record.id ) ),\n\t\t\t__unstablePrePersist: ( persistedRecord, edits ) =>\n\t\t\t\tprePersistPostType( persistedRecord, edits, name, isTemplate ),\n\t\t\t__unstable_rest_base: postType.rest_base,\n\t\t\tsupportsPagination: true,\n\t\t\tgetRevisionsUrl: ( parentId, revisionId ) =>\n\t\t\t\t`/${ namespace }/${\n\t\t\t\t\tpostType.rest_base\n\t\t\t\t}/${ parentId }/revisions${\n\t\t\t\t\trevisionId ? '/' + revisionId : ''\n\t\t\t\t}`,\n\t\t\trevisionKey:\n\t\t\t\tisTemplate && ! window?.__experimentalTemplateActivate\n\t\t\t\t\t? 'wp_id'\n\t\t\t\t\t: DEFAULT_ENTITY_KEY,\n\t\t};\n\n\t\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\t\t/**\n\t\t\t * @type {import('@wordpress/sync').SyncConfig}\n\t\t\t */\n\t\t\tentity.syncConfig = {\n\t\t\t\t/**\n\t\t\t\t * Apply changes from the local editor to the local CRDT document so\n\t\t\t\t * that those changes can be synced to other peers (via the provider).\n\t\t\t\t *\n\t\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t\t * @param {Partial< import('@wordpress/sync').ObjectData >} changes\n\t\t\t\t * @return {void}\n\t\t\t\t */\n\t\t\t\tapplyChangesToCRDTDoc: ( crdtDoc, changes ) =>\n\t\t\t\t\tapplyPostChangesToCRDTDoc( crdtDoc, changes, postType ),\n\n\t\t\t\t/**\n\t\t\t\t * Extract changes from a CRDT document that can be used to update the\n\t\t\t\t * local editor state.\n\t\t\t\t *\n\t\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t\t * @param {import('@wordpress/sync').ObjectData} editedRecord\n\t\t\t\t * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record\n\t\t\t\t */\n\t\t\t\tgetChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>\n\t\t\t\t\tgetPostChangesFromCRDTDoc(\n\t\t\t\t\t\tcrdtDoc,\n\t\t\t\t\t\teditedRecord,\n\t\t\t\t\t\tpostType\n\t\t\t\t\t),\n\n\t\t\t\t/**\n\t\t\t\t * Sync features supported by the entity.\n\t\t\t\t *\n\t\t\t\t * @type {Record< string, boolean >}\n\t\t\t\t */\n\t\t\t\tsupports: {\n\t\t\t\t\tcrdtPersistence: true,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn entity;\n\t} );\n}\n\n/**\n * Returns the list of the taxonomies entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadTaxonomyEntities() {\n\tconst taxonomies = await apiFetch( {\n\t\tpath: '/wp/v2/taxonomies?context=view',\n\t} );\n\treturn Object.entries( taxonomies ?? {} ).map( ( [ name, taxonomy ] ) => {\n\t\tconst namespace = taxonomy?.rest_namespace ?? 'wp/v2';\n\t\treturn {\n\t\t\tkind: 'taxonomy',\n\t\t\tbaseURL: `/${ namespace }/${ taxonomy.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: taxonomy.name,\n\t\t\tgetTitle: ( record ) => record?.name,\n\t\t\tsupportsPagination: true,\n\t\t};\n\t} );\n}\n\n/**\n * Returns the Site entity.\n *\n * @return {Promise} Entity promise\n */\nasync function loadSiteEntity() {\n\tconst entity = {\n\t\tlabel: __( 'Site' ),\n\t\tname: 'site',\n\t\tkind: 'root',\n\t\tkey: false,\n\t\tbaseURL: '/wp/v2/settings',\n\t\tmeta: {},\n\t};\n\n\tconst site = await apiFetch( {\n\t\tpath: entity.baseURL,\n\t\tmethod: 'OPTIONS',\n\t} );\n\n\tconst labels = {};\n\tObject.entries( site?.schema?.properties ?? {} ).forEach(\n\t\t( [ key, value ] ) => {\n\t\t\t// Ignore properties `title` and `type` keys.\n\t\t\tif ( typeof value === 'object' && value.title ) {\n\t\t\t\tlabels[ key ] = value.title;\n\t\t\t}\n\t\t}\n\t);\n\n\treturn [ { ...entity, meta: { labels } } ];\n}\n\n/**\n * Returns the entity's getter method name given its kind and name or plural name.\n *\n * @example\n * ```js\n * const nameSingular = getMethodName( 'root', 'theme', 'get' );\n * // nameSingular is getRootTheme\n *\n * const namePlural = getMethodName( 'root', 'themes', 'set' );\n * // namePlural is setRootThemes\n * ```\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name or plural name.\n * @param {string} prefix Function prefix.\n *\n * @return {string} Method name\n */\nexport const getMethodName = ( kind, name, prefix = 'get' ) => {\n\tconst kindPrefix = kind === 'root' ? '' : pascalCase( kind );\n\tconst suffix = pascalCase( name );\n\treturn `${ prefix }${ kindPrefix }${ suffix }`;\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAwC;AAKxC,uBAAqB;AACrB,oBAAmD;AACnD,kBAAmB;AAKnB,kBAA+B;AAC/B,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { capitalCase, pascalCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { __unstableSerializeAndClean, parse } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { PostEditorAwareness } from './awareness/post-editor-awareness';\nimport { getSyncManager } from './sync';\nimport {\n\tapplyPostChangesToCRDTDoc,\n\tdefaultSyncConfig,\n\tgetPostChangesFromCRDTDoc,\n} from './utils/crdt';\n\nexport const DEFAULT_ENTITY_KEY = 'id';\nconst POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];\n\nconst blocksTransientEdits = {\n\tblocks: {\n\t\tread: ( record ) => parse( record.content?.raw ?? '' ),\n\t\twrite: ( record ) => ( {\n\t\t\tcontent: __unstableSerializeAndClean( record.blocks ),\n\t\t} ),\n\t},\n};\n\nexport const rootEntitiesConfig = [\n\t{\n\t\tlabel: __( 'Base' ),\n\t\tkind: 'root',\n\t\tkey: false,\n\t\tname: '__unstableBase',\n\t\tbaseURL: '/',\n\t\tbaseURLParams: {\n\t\t\t// Please also change the preload path when changing this.\n\t\t\t// @see lib/compat/wordpress-6.8/preload.php\n\t\t\t_fields: [\n\t\t\t\t'description',\n\t\t\t\t'gmt_offset',\n\t\t\t\t'home',\n\t\t\t\t'name',\n\t\t\t\t'site_icon',\n\t\t\t\t'site_icon_url',\n\t\t\t\t'site_logo',\n\t\t\t\t'timezone_string',\n\t\t\t\t'url',\n\t\t\t\t'page_for_posts',\n\t\t\t\t'page_on_front',\n\t\t\t\t'show_on_front',\n\t\t\t].join( ',' ),\n\t\t},\n\t\t// The entity doesn't support selecting multiple records.\n\t\t// The property is maintained for backward compatibility.\n\t\tplural: '__unstableBases',\n\t},\n\t{\n\t\tlabel: __( 'Post Type' ),\n\t\tname: 'postType',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'postTypes',\n\t},\n\t{\n\t\tname: 'media',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/media',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'mediaItems',\n\t\tlabel: __( 'Media' ),\n\t\trawAttributes: [ 'caption', 'title', 'description' ],\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'taxonomy',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/taxonomies',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'taxonomies',\n\t\tlabel: __( 'Taxonomy' ),\n\t},\n\t{\n\t\tname: 'sidebar',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/sidebars',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'sidebars',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widget areas' ),\n\t},\n\t{\n\t\tname: 'widget',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widgets',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgets',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widgets' ),\n\t},\n\t{\n\t\tname: 'widgetType',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widget-types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgetTypes',\n\t\tlabel: __( 'Widget types' ),\n\t},\n\t{\n\t\tlabel: __( 'User' ),\n\t\tname: 'user',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/users',\n\t\tgetTitle: ( record ) => record?.name || record?.slug,\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'users',\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'comment',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/comments',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'comments',\n\t\tlabel: __( 'Comment' ),\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menu',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menus',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menus',\n\t\tlabel: __( 'Menu' ),\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menuItem',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-items',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuItems',\n\t\tlabel: __( 'Menu Item' ),\n\t\trawAttributes: [ 'title' ],\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menuLocation',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-locations',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuLocations',\n\t\tlabel: __( 'Menu Location' ),\n\t\tkey: 'name',\n\t},\n\t{\n\t\tlabel: __( 'Global Styles' ),\n\t\tname: 'globalStyles',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/global-styles',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'globalStylesVariations', // Should be different from name.\n\t\tgetTitle: () => __( 'Custom Styles' ),\n\t\tgetRevisionsUrl: ( parentId, revisionId ) =>\n\t\t\t`/wp/v2/global-styles/${ parentId }/revisions${\n\t\t\t\trevisionId ? '/' + revisionId : ''\n\t\t\t}`,\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tlabel: __( 'Themes' ),\n\t\tname: 'theme',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/themes',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'themes',\n\t\tkey: 'stylesheet',\n\t},\n\t{\n\t\tlabel: __( 'Plugins' ),\n\t\tname: 'plugin',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/plugins',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'plugins',\n\t\tkey: 'plugin',\n\t},\n\t{\n\t\tlabel: __( 'Status' ),\n\t\tname: 'status',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/statuses',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'statuses',\n\t\tkey: 'slug',\n\t},\n\t{\n\t\tlabel: __( 'Registered Templates' ),\n\t\tname: 'registeredTemplate',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/registered-templates',\n\t\tkey: 'id',\n\t},\n\t{\n\t\tlabel: __( 'Font Collections' ),\n\t\tname: 'fontCollection',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/font-collections',\n\t\tbaseURLParams: { context: 'view' },\n\t\tplural: 'fontCollections',\n\t\tkey: 'slug',\n\t},\n].map( ( entity ) => {\n\tconst syncEnabledRootEntities = new Set( [ 'comment' ] );\n\n\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\tif ( syncEnabledRootEntities.has( entity.name ) ) {\n\t\t\tentity.syncConfig = defaultSyncConfig;\n\t\t}\n\t}\n\treturn entity;\n} );\n\nexport const deprecatedEntities = {\n\troot: {\n\t\tmedia: {\n\t\t\tsince: '6.9',\n\t\t\talternative: {\n\t\t\t\tkind: 'postType',\n\t\t\t\tname: 'attachment',\n\t\t\t},\n\t\t},\n\t},\n};\n\nexport const additionalEntityConfigLoaders = [\n\t{ kind: 'postType', loadEntities: loadPostTypeEntities },\n\t{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },\n\t{\n\t\tkind: 'root',\n\t\tname: 'site',\n\t\tplural: 'sites',\n\t\tloadEntities: loadSiteEntity,\n\t},\n];\n\n/**\n * Apply extra edits before persisting a post type.\n *\n * @param {Object} persistedRecord Already persisted Post\n * @param {Object} edits Edits.\n * @param {string} name Post type name.\n * @param {boolean} isTemplate Whether the post type is a template.\n * @return {Object} Updated edits.\n */\nexport const prePersistPostType = (\n\tpersistedRecord,\n\tedits,\n\tname,\n\tisTemplate\n) => {\n\tconst newEdits = {};\n\n\tif ( ! isTemplate && persistedRecord?.status === 'auto-draft' ) {\n\t\t// Saving an auto-draft should create a draft by default.\n\t\tif ( ! edits.status && ! newEdits.status ) {\n\t\t\tnewEdits.status = 'draft';\n\t\t}\n\n\t\t// Fix the auto-draft default title.\n\t\tif (\n\t\t\t( ! edits.title || edits.title === 'Auto Draft' ) &&\n\t\t\t! newEdits.title &&\n\t\t\t( ! persistedRecord?.title ||\n\t\t\t\tpersistedRecord?.title === 'Auto Draft' )\n\t\t) {\n\t\t\tnewEdits.title = '';\n\t\t}\n\t}\n\n\t// Add meta for persisted CRDT document.\n\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\tif ( persistedRecord ) {\n\t\t\tconst objectType = `postType/${ name }`;\n\t\t\tconst objectId = persistedRecord.id;\n\t\t\tconst meta = getSyncManager()?.createMeta( objectType, objectId );\n\t\t\tnewEdits.meta = {\n\t\t\t\t...edits.meta,\n\t\t\t\t...meta,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn newEdits;\n};\n\n/**\n * Returns the list of post type entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadPostTypeEntities() {\n\tconst postTypes = await apiFetch( {\n\t\tpath: '/wp/v2/types?context=view',\n\t} );\n\treturn Object.entries( postTypes ?? {} ).map( ( [ name, postType ] ) => {\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tname\n\t\t);\n\t\tconst namespace = postType?.rest_namespace ?? 'wp/v2';\n\n\t\tconst entity = {\n\t\t\tkind: 'postType',\n\t\t\tbaseURL: `/${ namespace }/${ postType.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: postType.name,\n\t\t\ttransientEdits: {\n\t\t\t\t...blocksTransientEdits,\n\t\t\t\tselection: true,\n\t\t\t},\n\t\t\tmergedEdits: { meta: true },\n\t\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t\t\tgetTitle: ( record ) =>\n\t\t\t\trecord?.title?.rendered ||\n\t\t\t\trecord?.title ||\n\t\t\t\t( isTemplate\n\t\t\t\t\t? capitalCase( record.slug ?? '' )\n\t\t\t\t\t: String( record.id ) ),\n\t\t\t__unstablePrePersist: ( persistedRecord, edits ) =>\n\t\t\t\tprePersistPostType( persistedRecord, edits, name, isTemplate ),\n\t\t\t__unstable_rest_base: postType.rest_base,\n\t\t\tsupportsPagination: true,\n\t\t\tgetRevisionsUrl: ( parentId, revisionId ) =>\n\t\t\t\t`/${ namespace }/${\n\t\t\t\t\tpostType.rest_base\n\t\t\t\t}/${ parentId }/revisions${\n\t\t\t\t\trevisionId ? '/' + revisionId : ''\n\t\t\t\t}`,\n\t\t\trevisionKey:\n\t\t\t\tisTemplate && ! window?.__experimentalTemplateActivate\n\t\t\t\t\t? 'wp_id'\n\t\t\t\t\t: DEFAULT_ENTITY_KEY,\n\t\t};\n\n\t\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\t\t/**\n\t\t\t * @type {import('@wordpress/sync').SyncConfig}\n\t\t\t */\n\t\t\tentity.syncConfig = {\n\t\t\t\t/**\n\t\t\t\t * Apply changes from the local editor to the local CRDT document so\n\t\t\t\t * that those changes can be synced to other peers (via the provider).\n\t\t\t\t *\n\t\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t\t * @param {Partial< import('@wordpress/sync').ObjectData >} changes\n\t\t\t\t * @return {void}\n\t\t\t\t */\n\t\t\t\tapplyChangesToCRDTDoc: ( crdtDoc, changes ) =>\n\t\t\t\t\tapplyPostChangesToCRDTDoc( crdtDoc, changes, postType ),\n\n\t\t\t\t/**\n\t\t\t\t * Create the awareness instance for the entity's CRDT document.\n\t\t\t\t *\n\t\t\t\t * @param {import('@wordpress/sync').CRDTDoc} ydoc\n\t\t\t\t * @param {import('@wordpress/sync').ObjectID} objectId\n\t\t\t\t * @return {import('@wordpress/sync').AwarenessState} AwarenessState instance\n\t\t\t\t */\n\t\t\t\tcreateAwareness: ( ydoc, objectId ) => {\n\t\t\t\t\tconst kind = 'postType';\n\t\t\t\t\tconst id = parseInt( objectId, 10 );\n\t\t\t\t\treturn new PostEditorAwareness( ydoc, kind, name, id );\n\t\t\t\t},\n\n\t\t\t\t/**\n\t\t\t\t * Extract changes from a CRDT document that can be used to update the\n\t\t\t\t * local editor state.\n\t\t\t\t *\n\t\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t\t * @param {import('@wordpress/sync').ObjectData} editedRecord\n\t\t\t\t * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record\n\t\t\t\t */\n\t\t\t\tgetChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>\n\t\t\t\t\tgetPostChangesFromCRDTDoc(\n\t\t\t\t\t\tcrdtDoc,\n\t\t\t\t\t\teditedRecord,\n\t\t\t\t\t\tpostType\n\t\t\t\t\t),\n\n\t\t\t\t/**\n\t\t\t\t * Sync features supported by the entity.\n\t\t\t\t *\n\t\t\t\t * @type {Record< string, boolean >}\n\t\t\t\t */\n\t\t\t\tsupports: {\n\t\t\t\t\tcrdtPersistence: true,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn entity;\n\t} );\n}\n\n/**\n * Returns the list of the taxonomies entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadTaxonomyEntities() {\n\tconst taxonomies = await apiFetch( {\n\t\tpath: '/wp/v2/taxonomies?context=view',\n\t} );\n\treturn Object.entries( taxonomies ?? {} ).map( ( [ name, taxonomy ] ) => {\n\t\tconst namespace = taxonomy?.rest_namespace ?? 'wp/v2';\n\t\tconst entity = {\n\t\t\tkind: 'taxonomy',\n\t\t\tbaseURL: `/${ namespace }/${ taxonomy.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: taxonomy.name,\n\t\t\tgetTitle: ( record ) => record?.name,\n\t\t\tsupportsPagination: true,\n\t\t};\n\n\t\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\t\tentity.syncConfig = defaultSyncConfig;\n\t\t}\n\n\t\treturn entity;\n\t} );\n}\n\n/**\n * Returns the Site entity.\n *\n * @return {Promise} Entity promise\n */\nasync function loadSiteEntity() {\n\tconst entity = {\n\t\tlabel: __( 'Site' ),\n\t\tname: 'site',\n\t\tkind: 'root',\n\t\tkey: false,\n\t\tbaseURL: '/wp/v2/settings',\n\t\tmeta: {},\n\t};\n\n\tconst site = await apiFetch( {\n\t\tpath: entity.baseURL,\n\t\tmethod: 'OPTIONS',\n\t} );\n\n\tconst labels = {};\n\tObject.entries( site?.schema?.properties ?? {} ).forEach(\n\t\t( [ key, value ] ) => {\n\t\t\t// Ignore properties `title` and `type` keys.\n\t\t\tif ( typeof value === 'object' && value.title ) {\n\t\t\t\tlabels[ key ] = value.title;\n\t\t\t}\n\t\t}\n\t);\n\n\treturn [ { ...entity, meta: { labels } } ];\n}\n\n/**\n * Returns the entity's getter method name given its kind and name or plural name.\n *\n * @example\n * ```js\n * const nameSingular = getMethodName( 'root', 'theme', 'get' );\n * // nameSingular is getRootTheme\n *\n * const namePlural = getMethodName( 'root', 'themes', 'set' );\n * // namePlural is setRootThemes\n * ```\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name or plural name.\n * @param {string} prefix Function prefix.\n *\n * @return {string} Method name\n */\nexport const getMethodName = ( kind, name, prefix = 'get' ) => {\n\tconst kindPrefix = kind === 'root' ? '' : pascalCase( kind );\n\tconst suffix = pascalCase( name );\n\treturn `${ prefix }${ kindPrefix }${ suffix }`;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAwC;AAKxC,uBAAqB;AACrB,oBAAmD;AACnD,kBAAmB;AAKnB,mCAAoC;AACpC,kBAA+B;AAC/B,kBAIO;AAEA,IAAM,qBAAqB;AAClC,IAAM,sBAAsB,CAAE,SAAS,WAAW,SAAU;AAE5D,IAAM,uBAAuB;AAAA,EAC5B,QAAQ;AAAA,IACP,MAAM,CAAE,eAAY,qBAAO,OAAO,SAAS,OAAO,EAAG;AAAA,IACrD,OAAO,CAAE,YAAc;AAAA,MACtB,aAAS,2CAA6B,OAAO,MAAO;AAAA,IACrD;AAAA,EACD;AACD;AAEO,IAAM,qBAAqB;AAAA,EACjC;AAAA,IACC,WAAO,gBAAI,MAAO;AAAA,IAClB,MAAM;AAAA,IACN,KAAK;AAAA,IACL,MAAM;AAAA,IACN,S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E,MAAM,MAAM,SAAS,UAAW;AAC9D,QAAM,aAAa,SAAS,SAAS,SAAK,+BAAY,IAAK;AAC3D,QAAM,aAAS,+BAAY,IAAK;AAChC,SAAO,GAAI,MAAO,GAAI,UAAW,GAAI,MAAO;AAC7C;",
|
|
6
6
|
"names": ["apiFetch"]
|
|
7
7
|
}
|
package/build/resolvers.cjs
CHANGED
|
@@ -71,6 +71,7 @@ var import_entities = require("./entities.cjs");
|
|
|
71
71
|
var import_sync = require("./sync.cjs");
|
|
72
72
|
var import_utils = require("./utils/index.cjs");
|
|
73
73
|
var import_fetch = require("./fetch/index.cjs");
|
|
74
|
+
var import_crdt_selection = require("./utils/crdt-selection.cjs");
|
|
74
75
|
var getAuthors = (query) => async ({ dispatch }) => {
|
|
75
76
|
const path = (0, import_url.addQueryArgs)(
|
|
76
77
|
"/wp/v2/users/?who=authors&per_page=100",
|
|
@@ -162,7 +163,7 @@ var getEntityRecord = (kind, name, key = "", query) => async ({ select, dispatch
|
|
|
162
163
|
recordWithTransients,
|
|
163
164
|
{
|
|
164
165
|
// Handle edits sourced from the sync manager.
|
|
165
|
-
editRecord: (edits) => {
|
|
166
|
+
editRecord: (edits, options = {}) => {
|
|
166
167
|
if (!Object.keys(edits).length) {
|
|
167
168
|
return;
|
|
168
169
|
}
|
|
@@ -174,7 +175,8 @@ var getEntityRecord = (kind, name, key = "", query) => async ({ select, dispatch
|
|
|
174
175
|
edits,
|
|
175
176
|
meta: {
|
|
176
177
|
undo: void 0
|
|
177
|
-
}
|
|
178
|
+
},
|
|
179
|
+
options
|
|
178
180
|
});
|
|
179
181
|
},
|
|
180
182
|
// Get the current entity record (with edits)
|
|
@@ -199,6 +201,26 @@ var getEntityRecord = (kind, name, key = "", query) => async ({ select, dispatch
|
|
|
199
201
|
name,
|
|
200
202
|
key
|
|
201
203
|
);
|
|
204
|
+
},
|
|
205
|
+
addUndoMeta: (ydoc, meta) => {
|
|
206
|
+
const selectionHistory = (0, import_crdt_selection.getSelectionHistory)(ydoc);
|
|
207
|
+
if (selectionHistory) {
|
|
208
|
+
meta.set(
|
|
209
|
+
"selectionHistory",
|
|
210
|
+
selectionHistory
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
restoreUndoMeta: (ydoc, meta) => {
|
|
215
|
+
const selectionHistory = meta.get("selectionHistory");
|
|
216
|
+
if (selectionHistory) {
|
|
217
|
+
setTimeout(() => {
|
|
218
|
+
(0, import_crdt_selection.restoreSelection)(
|
|
219
|
+
selectionHistory,
|
|
220
|
+
ydoc
|
|
221
|
+
);
|
|
222
|
+
}, 0);
|
|
223
|
+
}
|
|
202
224
|
}
|
|
203
225
|
}
|
|
204
226
|
);
|
|
@@ -327,6 +349,25 @@ var getEntityRecords = (kind, name, query = {}) => async ({ dispatch, registry,
|
|
|
327
349
|
totalPages: 1
|
|
328
350
|
};
|
|
329
351
|
}
|
|
352
|
+
if (globalThis.IS_GUTENBERG_PLUGIN) {
|
|
353
|
+
if (entityConfig.syncConfig && -1 === query.per_page) {
|
|
354
|
+
const objectType = `${kind}/${name}`;
|
|
355
|
+
(0, import_sync.getSyncManager)()?.loadCollection(
|
|
356
|
+
entityConfig.syncConfig,
|
|
357
|
+
objectType,
|
|
358
|
+
{
|
|
359
|
+
refetchRecords: async () => {
|
|
360
|
+
dispatch.receiveEntityRecords(
|
|
361
|
+
kind,
|
|
362
|
+
name,
|
|
363
|
+
await (0, import_api_fetch.default)({ path, parse: true }),
|
|
364
|
+
query
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
330
371
|
if (query._fields) {
|
|
331
372
|
records = records.map((record) => {
|
|
332
373
|
query._fields.split(",").forEach((field) => {
|