@wordpress/core-data 7.41.2-next.v.202603161435.0 → 7.42.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 +1 -1
- package/build/awareness/post-editor-awareness.cjs +12 -5
- package/build/awareness/post-editor-awareness.cjs.map +2 -2
- package/build/entities.cjs +30 -5
- package/build/entities.cjs.map +2 -2
- package/build/hooks/use-post-editor-awareness-state.cjs +1 -1
- package/build/hooks/use-post-editor-awareness-state.cjs.map +2 -2
- package/build/queried-data/get-query-parts.cjs +7 -0
- package/build/queried-data/get-query-parts.cjs.map +2 -2
- package/build/queried-data/selectors.cjs +14 -3
- package/build/queried-data/selectors.cjs.map +2 -2
- package/build/reducer.cjs +6 -0
- package/build/reducer.cjs.map +2 -2
- package/build/sync.cjs +3 -0
- package/build/sync.cjs.map +2 -2
- package/build/types.cjs.map +2 -2
- package/build/utils/block-selection-history.cjs +1 -1
- package/build/utils/block-selection-history.cjs.map +2 -2
- package/build/utils/crdt-blocks.cjs +17 -3
- package/build/utils/crdt-blocks.cjs.map +2 -2
- package/build/utils/crdt-selection.cjs +4 -1
- package/build/utils/crdt-selection.cjs.map +2 -2
- package/build/utils/crdt-user-selections.cjs +1 -1
- package/build/utils/crdt-user-selections.cjs.map +2 -2
- package/build/utils/crdt-utils.cjs +54 -2
- package/build/utils/crdt-utils.cjs.map +2 -2
- package/build/utils/crdt.cjs +4 -23
- package/build/utils/crdt.cjs.map +2 -2
- package/build-module/awareness/post-editor-awareness.mjs +12 -5
- package/build-module/awareness/post-editor-awareness.mjs.map +2 -2
- package/build-module/entities.mjs +30 -5
- package/build-module/entities.mjs.map +2 -2
- package/build-module/hooks/use-post-editor-awareness-state.mjs +1 -1
- package/build-module/hooks/use-post-editor-awareness-state.mjs.map +2 -2
- package/build-module/queried-data/get-query-parts.mjs +7 -0
- package/build-module/queried-data/get-query-parts.mjs.map +2 -2
- package/build-module/queried-data/selectors.mjs +14 -3
- package/build-module/queried-data/selectors.mjs.map +2 -2
- package/build-module/reducer.mjs +6 -0
- package/build-module/reducer.mjs.map +2 -2
- package/build-module/sync.mjs +2 -0
- package/build-module/sync.mjs.map +2 -2
- package/build-module/types.mjs.map +2 -2
- package/build-module/utils/block-selection-history.mjs +5 -2
- package/build-module/utils/block-selection-history.mjs.map +2 -2
- package/build-module/utils/crdt-blocks.mjs +17 -3
- package/build-module/utils/crdt-blocks.mjs.map +2 -2
- package/build-module/utils/crdt-selection.mjs +8 -2
- package/build-module/utils/crdt-selection.mjs.map +2 -2
- package/build-module/utils/crdt-user-selections.mjs +2 -2
- package/build-module/utils/crdt-user-selections.mjs.map +2 -2
- package/build-module/utils/crdt-utils.mjs +51 -1
- package/build-module/utils/crdt-utils.mjs.map +2 -2
- package/build-module/utils/crdt.mjs +4 -23
- package/build-module/utils/crdt.mjs.map +2 -2
- package/build-types/awareness/post-editor-awareness.d.ts +2 -2
- package/build-types/awareness/post-editor-awareness.d.ts.map +1 -1
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/queried-data/get-query-parts.d.ts +7 -0
- package/build-types/queried-data/get-query-parts.d.ts.map +1 -1
- package/build-types/queried-data/selectors.d.ts.map +1 -1
- package/build-types/reducer.d.ts.map +1 -1
- package/build-types/sync.d.ts +2 -2
- package/build-types/sync.d.ts.map +1 -1
- package/build-types/types.d.ts +4 -2
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils/block-selection-history.d.ts.map +1 -1
- package/build-types/utils/crdt-blocks.d.ts.map +1 -1
- package/build-types/utils/crdt-selection.d.ts.map +1 -1
- package/build-types/utils/crdt-user-selections.d.ts +1 -2
- package/build-types/utils/crdt-user-selections.d.ts.map +1 -1
- package/build-types/utils/crdt-utils.d.ts +20 -0
- package/build-types/utils/crdt-utils.d.ts.map +1 -1
- package/build-types/utils/crdt.d.ts +6 -7
- package/build-types/utils/crdt.d.ts.map +1 -1
- package/build-types/utils/test/crdt-utils.d.ts +2 -0
- package/build-types/utils/test/crdt-utils.d.ts.map +1 -0
- package/package.json +18 -18
- package/src/awareness/post-editor-awareness.ts +13 -6
- package/src/awareness/test/post-editor-awareness.ts +15 -10
- package/src/entities.js +36 -5
- package/src/hooks/test/use-post-editor-awareness-state.ts +3 -3
- package/src/hooks/use-post-editor-awareness-state.ts +1 -1
- package/src/queried-data/get-query-parts.js +13 -0
- package/src/queried-data/selectors.js +22 -4
- package/src/queried-data/test/get-query-parts.js +34 -0
- package/src/queried-data/test/selectors.js +158 -0
- package/src/reducer.js +11 -0
- package/src/sync.ts +2 -0
- package/src/test/entities.js +185 -1
- package/src/types.ts +8 -2
- package/src/utils/block-selection-history.ts +5 -2
- package/src/utils/crdt-blocks.ts +32 -3
- package/src/utils/crdt-selection.ts +8 -2
- package/src/utils/crdt-user-selections.ts +13 -13
- package/src/utils/crdt-utils.ts +99 -0
- package/src/utils/crdt.ts +8 -30
- package/src/utils/test/crdt-blocks.ts +146 -0
- package/src/utils/test/crdt-user-selections.ts +5 -0
- package/src/utils/test/crdt-utils.ts +387 -0
- package/src/utils/test/crdt.ts +120 -53
|
@@ -23,10 +23,13 @@ __export(crdt_utils_exports, {
|
|
|
23
23
|
createYMap: () => createYMap,
|
|
24
24
|
findBlockByClientIdInDoc: () => findBlockByClientIdInDoc,
|
|
25
25
|
getRootMap: () => getRootMap,
|
|
26
|
-
|
|
26
|
+
htmlIndexToRichTextOffset: () => htmlIndexToRichTextOffset,
|
|
27
|
+
isYMap: () => isYMap,
|
|
28
|
+
richTextOffsetToHtmlIndex: () => richTextOffsetToHtmlIndex
|
|
27
29
|
});
|
|
28
30
|
module.exports = __toCommonJS(crdt_utils_exports);
|
|
29
31
|
var import_sync = require("@wordpress/sync");
|
|
32
|
+
var import_rich_text = require("@wordpress/rich-text");
|
|
30
33
|
var import_sync2 = require("../sync.cjs");
|
|
31
34
|
function getRootMap(doc, key) {
|
|
32
35
|
return doc.getMap(key);
|
|
@@ -45,6 +48,53 @@ function findBlockByClientIdInDoc(blockId, ydoc) {
|
|
|
45
48
|
}
|
|
46
49
|
return findBlockByClientIdInBlocks(blockId, blocks);
|
|
47
50
|
}
|
|
51
|
+
var MARKER_START = 57344;
|
|
52
|
+
function pickMarker(text) {
|
|
53
|
+
const tryCount = 16;
|
|
54
|
+
for (let code = MARKER_START; code < MARKER_START + tryCount; code++) {
|
|
55
|
+
const candidate = String.fromCharCode(code);
|
|
56
|
+
if (!text.includes(candidate)) {
|
|
57
|
+
return candidate;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
function htmlIndexToRichTextOffset(html, htmlIndex) {
|
|
63
|
+
if (!html.includes("<") && !html.includes("&")) {
|
|
64
|
+
return htmlIndex;
|
|
65
|
+
}
|
|
66
|
+
const marker = pickMarker(html);
|
|
67
|
+
if (!marker) {
|
|
68
|
+
return htmlIndex;
|
|
69
|
+
}
|
|
70
|
+
const withMarker = html.slice(0, htmlIndex) + marker + html.slice(htmlIndex);
|
|
71
|
+
const value = (0, import_rich_text.create)({ html: withMarker });
|
|
72
|
+
const markerPos = value.text.indexOf(marker);
|
|
73
|
+
return markerPos === -1 ? htmlIndex : markerPos;
|
|
74
|
+
}
|
|
75
|
+
function richTextOffsetToHtmlIndex(html, richTextOffset) {
|
|
76
|
+
if (!html.includes("<") && !html.includes("&")) {
|
|
77
|
+
return richTextOffset;
|
|
78
|
+
}
|
|
79
|
+
const marker = pickMarker(html);
|
|
80
|
+
if (!marker) {
|
|
81
|
+
return richTextOffset;
|
|
82
|
+
}
|
|
83
|
+
const value = (0, import_rich_text.create)({ html });
|
|
84
|
+
const markerValue = (0, import_rich_text.create)({ text: marker });
|
|
85
|
+
if (value.formats[richTextOffset]) {
|
|
86
|
+
markerValue.formats[0] = value.formats[richTextOffset];
|
|
87
|
+
}
|
|
88
|
+
const withMarker = (0, import_rich_text.insert)(
|
|
89
|
+
value,
|
|
90
|
+
markerValue,
|
|
91
|
+
richTextOffset,
|
|
92
|
+
richTextOffset
|
|
93
|
+
);
|
|
94
|
+
const htmlWithMarker = (0, import_rich_text.toHTMLString)({ value: withMarker });
|
|
95
|
+
const markerIndex = htmlWithMarker.indexOf(marker);
|
|
96
|
+
return markerIndex === -1 ? richTextOffset : markerIndex;
|
|
97
|
+
}
|
|
48
98
|
function findBlockByClientIdInBlocks(blockId, blocks) {
|
|
49
99
|
for (const block of blocks) {
|
|
50
100
|
if (block.get("clientId") === blockId) {
|
|
@@ -68,6 +118,8 @@ function findBlockByClientIdInBlocks(blockId, blocks) {
|
|
|
68
118
|
createYMap,
|
|
69
119
|
findBlockByClientIdInDoc,
|
|
70
120
|
getRootMap,
|
|
71
|
-
|
|
121
|
+
htmlIndexToRichTextOffset,
|
|
122
|
+
isYMap,
|
|
123
|
+
richTextOffsetToHtmlIndex
|
|
72
124
|
});
|
|
73
125
|
//# sourceMappingURL=crdt-utils.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/crdt-utils.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport type { YBlock, YBlocks } from './crdt-blocks';\nimport type { YPostRecord } from './crdt';\nimport { CRDT_RECORD_MAP_KEY } from '../sync';\n\n/**\n * A YMapRecord represents the shape of the data stored in a Y.Map.\n */\nexport type YMapRecord = Record< string, unknown >;\n\n/**\n * A wrapper around Y.Map to provide type safety. The generic type accepted by\n * Y.Map represents the union of possible values of the map, which are varied in\n * many cases. This type is accurate, but its non-specificity requires aggressive\n * type narrowing or type casting / destruction with `as`.\n *\n * This type provides type enhancements so that the correct value type can be\n * inferred based on the provided key. It is just a type wrap / overlay, and\n * does not change the runtime behavior of Y.Map.\n *\n * This interface cannot extend Y.Map directly due to the limitations of\n * TypeScript's structural typing. One negative consequence of this is that\n * `instanceof` checks against Y.Map continue to work at runtime but will blur\n * the type at compile time. To navigate this, use the `isYMap` function below.\n */\nexport interface YMapWrap< T extends YMapRecord > extends Y.AbstractType< T > {\n\tdelete: < K extends keyof T >( key: K ) => void;\n\tforEach: (\n\t\tcallback: (\n\t\t\tvalue: T[ keyof T ],\n\t\t\tkey: keyof T,\n\t\t\tmap: YMapWrap< T >\n\t\t) => void\n\t) => void;\n\thas: < K extends keyof T >( key: K ) => boolean;\n\tget: < K extends keyof T >( key: K ) => T[ K ] | undefined;\n\tset: < K extends keyof T >( key: K, value: T[ K ] ) => void;\n\ttoJSON: () => T;\n\t// add types for other Y.Map methods as needed\n}\n\n/**\n * Get or create a root-level Map for the given Y.Doc. Use this instead of\n * doc.getMap() for additional type safety.\n *\n * @param doc Y.Doc\n * @param key Map key\n */\nexport function getRootMap< T extends YMapRecord >(\n\tdoc: Y.Doc,\n\tkey: string\n): YMapWrap< T > {\n\treturn doc.getMap< T >( key ) as unknown as YMapWrap< T >;\n}\n\n/**\n * Create a new Y.Map (provided with YMapWrap type), optionally initialized with\n * data. Use this instead of `new Y.Map()` for additional type safety.\n *\n * @param partial Partial data to initialize the map with.\n */\nexport function createYMap< T extends YMapRecord >(\n\tpartial: Partial< T > = {}\n): YMapWrap< T > {\n\treturn new Y.Map( Object.entries( partial ) ) as unknown as YMapWrap< T >;\n}\n\n/**\n * Type guard to check if a value is a Y.Map without losing type information.\n *\n * @param value Value to check.\n */\nexport function isYMap< T extends YMapRecord >(\n\tvalue: YMapWrap< T > | undefined\n): value is YMapWrap< T > {\n\treturn value instanceof Y.Map;\n}\n\n/**\n * Given a block ID and a Y.Doc, find the block in the document.\n *\n * @param blockId The block ID to find\n * @param ydoc The Y.Doc to find the block in\n * @return The block, or null if the block is not found\n */\nexport function findBlockByClientIdInDoc(\n\tblockId: string,\n\tydoc: Y.Doc\n): YBlock | null {\n\tconst ymap = getRootMap< YPostRecord >( ydoc, CRDT_RECORD_MAP_KEY );\n\tconst blocks = ymap.get( 'blocks' );\n\n\tif ( ! ( blocks instanceof Y.Array ) ) {\n\t\treturn null;\n\t}\n\n\treturn findBlockByClientIdInBlocks( blockId, blocks );\n}\n\nfunction findBlockByClientIdInBlocks(\n\tblockId: string,\n\tblocks: YBlocks\n): YBlock | null {\n\tfor ( const block of blocks ) {\n\t\tif ( block.get( 'clientId' ) === blockId ) {\n\t\t\treturn block;\n\t\t}\n\n\t\tconst innerBlocks = block.get( 'innerBlocks' );\n\n\t\tif ( innerBlocks && innerBlocks.length > 0 ) {\n\t\t\tconst innerBlock = findBlockByClientIdInBlocks(\n\t\t\t\tblockId,\n\t\t\t\tinnerBlocks\n\t\t\t);\n\n\t\t\tif ( innerBlock ) {\n\t\t\t\treturn innerBlock;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn null;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAkB;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Y } from '@wordpress/sync';\nimport { create, insert, toHTMLString } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport type { YBlock, YBlocks } from './crdt-blocks';\nimport type { YPostRecord } from './crdt';\nimport { CRDT_RECORD_MAP_KEY } from '../sync';\n\n/**\n * A YMapRecord represents the shape of the data stored in a Y.Map.\n */\nexport type YMapRecord = Record< string, unknown >;\n\n/**\n * A wrapper around Y.Map to provide type safety. The generic type accepted by\n * Y.Map represents the union of possible values of the map, which are varied in\n * many cases. This type is accurate, but its non-specificity requires aggressive\n * type narrowing or type casting / destruction with `as`.\n *\n * This type provides type enhancements so that the correct value type can be\n * inferred based on the provided key. It is just a type wrap / overlay, and\n * does not change the runtime behavior of Y.Map.\n *\n * This interface cannot extend Y.Map directly due to the limitations of\n * TypeScript's structural typing. One negative consequence of this is that\n * `instanceof` checks against Y.Map continue to work at runtime but will blur\n * the type at compile time. To navigate this, use the `isYMap` function below.\n */\nexport interface YMapWrap< T extends YMapRecord > extends Y.AbstractType< T > {\n\tdelete: < K extends keyof T >( key: K ) => void;\n\tforEach: (\n\t\tcallback: (\n\t\t\tvalue: T[ keyof T ],\n\t\t\tkey: keyof T,\n\t\t\tmap: YMapWrap< T >\n\t\t) => void\n\t) => void;\n\thas: < K extends keyof T >( key: K ) => boolean;\n\tget: < K extends keyof T >( key: K ) => T[ K ] | undefined;\n\tset: < K extends keyof T >( key: K, value: T[ K ] ) => void;\n\ttoJSON: () => T;\n\t// add types for other Y.Map methods as needed\n}\n\n/**\n * Get or create a root-level Map for the given Y.Doc. Use this instead of\n * doc.getMap() for additional type safety.\n *\n * @param doc Y.Doc\n * @param key Map key\n */\nexport function getRootMap< T extends YMapRecord >(\n\tdoc: Y.Doc,\n\tkey: string\n): YMapWrap< T > {\n\treturn doc.getMap< T >( key ) as unknown as YMapWrap< T >;\n}\n\n/**\n * Create a new Y.Map (provided with YMapWrap type), optionally initialized with\n * data. Use this instead of `new Y.Map()` for additional type safety.\n *\n * @param partial Partial data to initialize the map with.\n */\nexport function createYMap< T extends YMapRecord >(\n\tpartial: Partial< T > = {}\n): YMapWrap< T > {\n\treturn new Y.Map( Object.entries( partial ) ) as unknown as YMapWrap< T >;\n}\n\n/**\n * Type guard to check if a value is a Y.Map without losing type information.\n *\n * @param value Value to check.\n */\nexport function isYMap< T extends YMapRecord >(\n\tvalue: YMapWrap< T > | undefined\n): value is YMapWrap< T > {\n\treturn value instanceof Y.Map;\n}\n\n/**\n * Given a block ID and a Y.Doc, find the block in the document.\n *\n * @param blockId The block ID to find\n * @param ydoc The Y.Doc to find the block in\n * @return The block, or null if the block is not found\n */\nexport function findBlockByClientIdInDoc(\n\tblockId: string,\n\tydoc: Y.Doc\n): YBlock | null {\n\tconst ymap = getRootMap< YPostRecord >( ydoc, CRDT_RECORD_MAP_KEY );\n\tconst blocks = ymap.get( 'blocks' );\n\n\tif ( ! ( blocks instanceof Y.Array ) ) {\n\t\treturn null;\n\t}\n\n\treturn findBlockByClientIdInBlocks( blockId, blocks );\n}\n\n// Marker for insertion.\nconst MARKER_START = 0xe000;\n\n/**\n * Pick a marker character that does not appear in `text`. Returns the marker\n * or `null` if all candidates are present (extremely unlikely in practice).\n *\n * @param text The string to check for existing marker characters.\n */\nfunction pickMarker( text: string ): string | null {\n\tconst tryCount = 0x10;\n\n\t// Scan the unicode private use area for the first code point not present\n\t// in the text.\n\tfor ( let code = MARKER_START; code < MARKER_START + tryCount; code++ ) {\n\t\tconst candidate = String.fromCharCode( code );\n\n\t\tif ( ! text.includes( candidate ) ) {\n\t\t\treturn candidate;\n\t\t}\n\t}\n\n\treturn null;\n}\n\n/**\n * Convert an HTML character index (counting tag characters) to a rich-text\n * offset (counting only text characters). Used on read paths where Y.Text\n * resolves to an HTML index but the block editor expects a text offset.\n *\n * @param html The full HTML string from Y.Text.\n * @param htmlIndex The HTML character index.\n * @return The corresponding rich-text offset.\n */\nexport function htmlIndexToRichTextOffset(\n\thtml: string,\n\thtmlIndex: number\n): number {\n\tif ( ! html.includes( '<' ) && ! html.includes( '&' ) ) {\n\t\treturn htmlIndex;\n\t}\n\n\tconst marker = pickMarker( html );\n\tif ( ! marker ) {\n\t\treturn htmlIndex;\n\t}\n\n\t// Insert marker and let create() do the parsing.\n\tconst withMarker =\n\t\thtml.slice( 0, htmlIndex ) + marker + html.slice( htmlIndex );\n\tconst value = create( { html: withMarker } );\n\tconst markerPos = value.text.indexOf( marker );\n\n\treturn markerPos === -1 ? htmlIndex : markerPos;\n}\n\n/**\n * Convert a rich-text offset (counting only text characters) to an HTML\n * character index (counting tag characters). Used on write paths where the\n * block editor provides a text offset but Y.Text expects an HTML index.\n *\n * @param html The full HTML string from Y.Text.\n * @param richTextOffset The rich-text text offset.\n * @return The corresponding HTML character index.\n */\nexport function richTextOffsetToHtmlIndex(\n\thtml: string,\n\trichTextOffset: number\n): number {\n\tif ( ! html.includes( '<' ) && ! html.includes( '&' ) ) {\n\t\treturn richTextOffset;\n\t}\n\n\tconst marker = pickMarker( html );\n\tif ( ! marker ) {\n\t\treturn richTextOffset;\n\t}\n\n\tconst value = create( { html } );\n\tconst markerValue = create( { text: marker } );\n\t// The marker must inherit the formatting at the insertion point so that\n\t// toHTMLString does not split surrounding tags (e.g. <strong>) around it.\n\tif ( value.formats[ richTextOffset ] ) {\n\t\tmarkerValue.formats[ 0 ] = value.formats[ richTextOffset ];\n\t}\n\n\tconst withMarker = insert(\n\t\tvalue,\n\t\tmarkerValue,\n\t\trichTextOffset,\n\t\trichTextOffset\n\t);\n\n\tconst htmlWithMarker = toHTMLString( { value: withMarker } );\n\tconst markerIndex = htmlWithMarker.indexOf( marker );\n\treturn markerIndex === -1 ? richTextOffset : markerIndex;\n}\n\nfunction findBlockByClientIdInBlocks(\n\tblockId: string,\n\tblocks: YBlocks\n): YBlock | null {\n\tfor ( const block of blocks ) {\n\t\tif ( block.get( 'clientId' ) === blockId ) {\n\t\t\treturn block;\n\t\t}\n\n\t\tconst innerBlocks = block.get( 'innerBlocks' );\n\n\t\tif ( innerBlocks && innerBlocks.length > 0 ) {\n\t\t\tconst innerBlock = findBlockByClientIdInBlocks(\n\t\t\t\tblockId,\n\t\t\t\tinnerBlocks\n\t\t\t);\n\n\t\t\tif ( innerBlock ) {\n\t\t\t\treturn innerBlock;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn null;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAkB;AAClB,uBAA6C;AAO7C,IAAAA,eAAoC;AA6C7B,SAAS,WACf,KACA,KACgB;AAChB,SAAO,IAAI,OAAa,GAAI;AAC7B;AAQO,SAAS,WACf,UAAwB,CAAC,GACT;AAChB,SAAO,IAAI,cAAE,IAAK,OAAO,QAAS,OAAQ,CAAE;AAC7C;AAOO,SAAS,OACf,OACyB;AACzB,SAAO,iBAAiB,cAAE;AAC3B;AASO,SAAS,yBACf,SACA,MACgB;AAChB,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AA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,QAAM,qBAAiB,+BAAc,EAAE,OAAO,WAAW,CAAE;AAC3D,QAAM,cAAc,eAAe,QAAS,MAAO;AACnD,SAAO,gBAAgB,KAAK,iBAAiB;AAC9C;AAEA,SAAS,4BACR,SACA,QACgB;AAChB,aAAY,SAAS,QAAS;AAC7B,QAAK,MAAM,IAAK,UAAW,MAAM,SAAU;AAC1C,aAAO;AAAA,IACR;AAEA,UAAM,cAAc,MAAM,IAAK,aAAc;AAE7C,QAAK,eAAe,YAAY,SAAS,GAAI;AAC5C,YAAM,aAAa;AAAA,QAClB;AAAA,QACA;AAAA,MACD;AAEA,UAAK,YAAa;AACjB,eAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AACR;",
|
|
6
6
|
"names": ["import_sync"]
|
|
7
7
|
}
|
package/build/utils/crdt.cjs
CHANGED
|
@@ -45,25 +45,6 @@ var import_sync2 = require("../sync.cjs");
|
|
|
45
45
|
var import_crdt_selection = require("./crdt-selection.cjs");
|
|
46
46
|
var import_crdt_utils = require("./crdt-utils.cjs");
|
|
47
47
|
var POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE = "_crdt_document";
|
|
48
|
-
var allowedPostProperties = /* @__PURE__ */ new Set([
|
|
49
|
-
"author",
|
|
50
|
-
"blocks",
|
|
51
|
-
"content",
|
|
52
|
-
"categories",
|
|
53
|
-
"comment_status",
|
|
54
|
-
"date",
|
|
55
|
-
"excerpt",
|
|
56
|
-
"featured_media",
|
|
57
|
-
"format",
|
|
58
|
-
"meta",
|
|
59
|
-
"ping_status",
|
|
60
|
-
"slug",
|
|
61
|
-
"status",
|
|
62
|
-
"sticky",
|
|
63
|
-
"tags",
|
|
64
|
-
"template",
|
|
65
|
-
"title"
|
|
66
|
-
]);
|
|
67
48
|
var disallowedPostMetaKeys = /* @__PURE__ */ new Set([
|
|
68
49
|
POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE
|
|
69
50
|
]);
|
|
@@ -82,10 +63,10 @@ function defaultApplyChangesToCRDTDoc(ydoc, changes) {
|
|
|
82
63
|
}
|
|
83
64
|
});
|
|
84
65
|
}
|
|
85
|
-
function applyPostChangesToCRDTDoc(ydoc, changes,
|
|
66
|
+
function applyPostChangesToCRDTDoc(ydoc, changes, syncedProperties) {
|
|
86
67
|
const ymap = (0, import_crdt_utils.getRootMap)(ydoc, import_sync2.CRDT_RECORD_MAP_KEY);
|
|
87
68
|
Object.keys(changes).forEach((key) => {
|
|
88
|
-
if (!
|
|
69
|
+
if (!syncedProperties.has(key)) {
|
|
89
70
|
return;
|
|
90
71
|
}
|
|
91
72
|
const newValue = changes[key];
|
|
@@ -172,12 +153,12 @@ function applyPostChangesToCRDTDoc(ydoc, changes, _postType) {
|
|
|
172
153
|
function defaultGetChangesFromCRDTDoc(crdtDoc) {
|
|
173
154
|
return (0, import_crdt_utils.getRootMap)(crdtDoc, import_sync2.CRDT_RECORD_MAP_KEY).toJSON();
|
|
174
155
|
}
|
|
175
|
-
function getPostChangesFromCRDTDoc(ydoc, editedRecord,
|
|
156
|
+
function getPostChangesFromCRDTDoc(ydoc, editedRecord, syncedProperties) {
|
|
176
157
|
const ymap = (0, import_crdt_utils.getRootMap)(ydoc, import_sync2.CRDT_RECORD_MAP_KEY);
|
|
177
158
|
let allowedMetaChanges = {};
|
|
178
159
|
const changes = Object.fromEntries(
|
|
179
160
|
Object.entries(ymap.toJSON()).filter(([key, newValue]) => {
|
|
180
|
-
if (!
|
|
161
|
+
if (!syncedProperties.has(key)) {
|
|
181
162
|
return false;
|
|
182
163
|
}
|
|
183
164
|
const currentValue = editedRecord[key];
|
package/build/utils/crdt.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/crdt.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\n// @ts-expect-error No exported types.\nimport { __unstableSerializeAndClean } from '@wordpress/blocks';\nimport {\n\ttype CRDTDoc,\n\ttype ObjectData,\n\ttype SyncConfig,\n\tY,\n} from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport { BaseAwareness } from '../awareness/base-awareness';\nimport {\n\tmergeCrdtBlocks,\n\tmergeRichTextUpdate,\n\ttype Block,\n\ttype YBlock,\n\ttype YBlocks,\n} from './crdt-blocks';\nimport { type Post } from '../entity-types/post';\nimport { type Type } from '../entity-types';\nimport { CRDT_DOC_META_PERSISTENCE_KEY, CRDT_RECORD_MAP_KEY } from '../sync';\nimport type { WPSelection } from '../types';\nimport {\n\tgetSelectionHistory,\n\tgetShiftedSelection,\n\tupdateSelectionHistory,\n} from './crdt-selection';\nimport {\n\tcreateYMap,\n\tgetRootMap,\n\tisYMap,\n\ttype YMapRecord,\n\ttype YMapWrap,\n} from './crdt-utils';\n\n// Changes that can be applied to a post entity record.\nexport type PostChanges = Partial< Post > & {\n\tblocks?: Block[];\n\tcontent?: Post[ 'content' ] | string;\n\texcerpt?: Post[ 'excerpt' ] | string;\n\tselection?: WPSelection;\n\ttitle?: Post[ 'title' ] | string;\n};\n\n// A post record as represented in the CRDT document (Y.Map).\nexport interface YPostRecord extends YMapRecord {\n\tauthor: number;\n\t// Blocks are undefined when they need to be re-parsed from content.\n\tblocks: YBlocks | undefined;\n\tcontent: Y.Text;\n\tcategories: number[];\n\tcomment_status: string;\n\tdate: string | null;\n\texcerpt: Y.Text;\n\tfeatured_media: number;\n\tformat: string;\n\tmeta: YMapWrap< YMapRecord >;\n\tping_status: string;\n\tslug: string;\n\tstatus: string;\n\tsticky: boolean;\n\ttags: number[];\n\ttemplate: string;\n\ttitle: Y.Text;\n}\n\nexport const POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE = '_crdt_document';\n\n// Properties that are allowed to be synced for a post.\nconst allowedPostProperties = new Set< string >( [\n\t'author',\n\t'blocks',\n\t'content',\n\t'categories',\n\t'comment_status',\n\t'date',\n\t'excerpt',\n\t'featured_media',\n\t'format',\n\t'meta',\n\t'ping_status',\n\t'slug',\n\t'status',\n\t'sticky',\n\t'tags',\n\t'template',\n\t'title',\n] );\n\n// Post meta keys that should *not* be synced.\nconst disallowedPostMetaKeys = new Set< string >( [\n\tPOST_META_KEY_FOR_CRDT_DOC_PERSISTENCE,\n] );\n\n/**\n * Given a set of local changes to a generic entity record, apply those changes\n * to the local Y.Doc.\n *\n * @param {CRDTDoc} ydoc\n * @param {Partial< ObjectData >} changes\n * @return {void}\n */\nfunction defaultApplyChangesToCRDTDoc(\n\tydoc: CRDTDoc,\n\tchanges: ObjectData\n): void {\n\tconst ymap = getRootMap( ydoc, CRDT_RECORD_MAP_KEY );\n\n\tObject.entries( changes ).forEach( ( [ key, newValue ] ) => {\n\t\t// Cannot serialize function values, so cannot sync them.\n\t\tif ( 'function' === typeof newValue ) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch ( key ) {\n\t\t\t// Add support for additional data types here.\n\n\t\t\tdefault: {\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tupdateMapValue( ymap, key, currentValue, newValue );\n\t\t\t}\n\t\t}\n\t} );\n}\n\n/**\n * Given a set of local changes to a post record, apply those changes to the\n * local Y.Doc.\n *\n * @param {CRDTDoc} ydoc\n * @param {PostChanges} changes\n * @param {Type} _postType\n * @return {void}\n */\nexport function applyPostChangesToCRDTDoc(\n\tydoc: CRDTDoc,\n\tchanges: PostChanges,\n\t_postType: Type // eslint-disable-line @typescript-eslint/no-unused-vars\n): void {\n\tconst ymap = getRootMap< YPostRecord >( ydoc, CRDT_RECORD_MAP_KEY );\n\n\tObject.keys( changes ).forEach( ( key ) => {\n\t\tif ( ! allowedPostProperties.has( key ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newValue = changes[ key ];\n\n\t\t// Cannot serialize function values, so cannot sync them.\n\t\tif ( 'function' === typeof newValue ) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch ( key ) {\n\t\t\tcase 'blocks': {\n\t\t\t\t// Blocks are undefined when they need to be re-parsed from content.\n\t\t\t\tif ( ! newValue ) {\n\t\t\t\t\t// Set to undefined instead of deleting the key. This is important\n\t\t\t\t\t// since we iterate over the Y.Map keys in getPostChangesFromCRDTDoc.\n\t\t\t\t\tymap.set( key, undefined );\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tlet currentBlocks = ymap.get( key );\n\n\t\t\t\t// Initialize.\n\t\t\t\tif ( ! ( currentBlocks instanceof Y.Array ) ) {\n\t\t\t\t\tcurrentBlocks = new Y.Array< YBlock >();\n\t\t\t\t\tymap.set( key, currentBlocks );\n\t\t\t\t}\n\n\t\t\t\t// Block changes from typing are bundled with a 'selection' update.\n\t\t\t\t// Pass the resulting cursor position to the mergeCrdtBlocks function.\n\t\t\t\tconst cursorPosition =\n\t\t\t\t\tchanges.selection?.selectionStart?.offset ?? null;\n\n\t\t\t\t// Merge blocks does not need `setValue` because it is operating on a\n\t\t\t\t// Yjs type that is already in the Y.Doc.\n\t\t\t\tmergeCrdtBlocks( currentBlocks, newValue, cursorPosition );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'content':\n\t\t\tcase 'excerpt':\n\t\t\tcase 'title': {\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tlet rawValue = getRawValue( newValue );\n\n\t\t\t\t// Copy logic from prePersistPostType to ensure that the \"Auto\n\t\t\t\t// Draft\" template title is not synced.\n\t\t\t\tif (\n\t\t\t\t\tkey === 'title' &&\n\t\t\t\t\t! currentValue?.toString() &&\n\t\t\t\t\t'Auto Draft' === rawValue\n\t\t\t\t) {\n\t\t\t\t\trawValue = '';\n\t\t\t\t}\n\n\t\t\t\tif ( currentValue instanceof Y.Text ) {\n\t\t\t\t\tmergeRichTextUpdate( currentValue, rawValue ?? '' );\n\t\t\t\t} else {\n\t\t\t\t\tconst newYText = new Y.Text( rawValue ?? '' );\n\t\t\t\t\tymap.set( key, newYText );\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// \"Meta\" is overloaded term; here, it refers to post meta.\n\t\t\tcase 'meta': {\n\t\t\t\tlet metaMap = ymap.get( 'meta' );\n\n\t\t\t\t// Initialize.\n\t\t\t\tif ( ! isYMap( metaMap ) ) {\n\t\t\t\t\tmetaMap = createYMap< YMapRecord >();\n\t\t\t\t\tymap.set( 'meta', metaMap );\n\t\t\t\t}\n\n\t\t\t\t// Iterate over each meta property in the new value and merge it if it\n\t\t\t\t// should be synced.\n\t\t\t\tObject.entries( newValue ?? {} ).forEach(\n\t\t\t\t\t( [ metaKey, metaValue ] ) => {\n\t\t\t\t\t\tif ( disallowedPostMetaKeys.has( metaKey ) ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tupdateMapValue(\n\t\t\t\t\t\t\tmetaMap,\n\t\t\t\t\t\t\tmetaKey,\n\t\t\t\t\t\t\tmetaMap.get( metaKey ), // current value in CRDT\n\t\t\t\t\t\t\tmetaValue // new value from changes\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'slug': {\n\t\t\t\t// Do not sync an empty slug. This indicates that the post is using\n\t\t\t\t// the default auto-generated slug.\n\t\t\t\tif ( ! newValue ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tupdateMapValue( ymap, key, currentValue, newValue );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Add support for additional properties here.\n\n\t\t\tdefault: {\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tupdateMapValue( ymap, key, currentValue, newValue );\n\t\t\t}\n\t\t}\n\t} );\n\n\t// Process changes that we don't want to persist to the CRDT document.\n\tif ( changes.selection ) {\n\t\tconst selection = changes.selection;\n\t\t// Persist selection changes at the end of the current event loop.\n\t\t// This allows undo meta to be saved with the current selection before\n\t\t// it is overwritten by the new selection from Gutenberg.\n\t\t// Without this, selection history will already contain the latest\n\t\t// selection (after this change) when the undo stack is saved.\n\t\tsetTimeout( () => {\n\t\t\tupdateSelectionHistory( ydoc, selection );\n\t\t}, 0 );\n\t}\n}\n\nfunction defaultGetChangesFromCRDTDoc( crdtDoc: CRDTDoc ): ObjectData {\n\treturn getRootMap( crdtDoc, CRDT_RECORD_MAP_KEY ).toJSON();\n}\n\n/**\n * Given a local Y.Doc that *may* contain changes from remote peers, compare\n * against the local record and determine if there are changes (edits) we want\n * to dispatch.\n *\n * @param {CRDTDoc} ydoc\n * @param {Post} editedRecord\n * @param {Type} _postType\n * @return {Partial<PostChanges>} The changes that should be applied to the local record.\n */\nexport function getPostChangesFromCRDTDoc(\n\tydoc: CRDTDoc,\n\teditedRecord: Post,\n\t_postType: Type // eslint-disable-line @typescript-eslint/no-unused-vars\n): PostChanges {\n\tconst ymap = getRootMap< YPostRecord >( ydoc, CRDT_RECORD_MAP_KEY );\n\n\tlet allowedMetaChanges: Post[ 'meta' ] = {};\n\n\tconst changes = Object.fromEntries(\n\t\tObject.entries( ymap.toJSON() ).filter( ( [ key, newValue ] ) => {\n\t\t\tif ( ! allowedPostProperties.has( key ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst currentValue = editedRecord[ key ];\n\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'blocks': {\n\t\t\t\t\t// When we are passed a persisted CRDT document, make a special\n\t\t\t\t\t// comparison of the content and blocks.\n\t\t\t\t\t//\n\t\t\t\t\t// When other fields (besides `blocks`) are mutated outside the block\n\t\t\t\t\t// editor, the change is caught by an equality check (see other cases\n\t\t\t\t\t// in this `switch` statement). As a transient property, `blocks`\n\t\t\t\t\t// cannot be directly mutated outside the block editor -- only\n\t\t\t\t\t// `content` can.\n\t\t\t\t\t//\n\t\t\t\t\t// Therefore, for this special comparison, we serialize the `blocks`\n\t\t\t\t\t// from the persisted CRDT document and compare that to the content\n\t\t\t\t\t// from the persisted record. If they differ, we know that the content\n\t\t\t\t\t// in the database has changed, and therefore the blocks have changed.\n\t\t\t\t\t//\n\t\t\t\t\t// We cannot directly compare the `blocks` from the CRDT document to\n\t\t\t\t\t// the `blocks` derived from the `content` in the persisted record,\n\t\t\t\t\t// because the latter will have different client IDs.\n\t\t\t\t\tif (\n\t\t\t\t\t\tydoc.meta?.get( CRDT_DOC_META_PERSISTENCE_KEY ) &&\n\t\t\t\t\t\teditedRecord.content\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst blocksJson = ymap.get( 'blocks' )?.toJSON() ?? [];\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t__unstableSerializeAndClean( blocksJson ).trim() !==\n\t\t\t\t\t\t\tgetRawValue( editedRecord.content )\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tcase 'date': {\n\t\t\t\t\t// Do not overwrite a \"floating\" date. Borrowing logic from the\n\t\t\t\t\t// isEditedPostDateFloating selector.\n\t\t\t\t\tconst currentDateIsFloating =\n\t\t\t\t\t\tnull === currentValue ||\n\t\t\t\t\t\teditedRecord.modified === currentValue;\n\n\t\t\t\t\tif ( currentDateIsFloating ) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\n\t\t\t\tcase 'meta': {\n\t\t\t\t\tallowedMetaChanges = Object.fromEntries(\n\t\t\t\t\t\tObject.entries( newValue ?? {} ).filter(\n\t\t\t\t\t\t\t( [ metaKey ] ) =>\n\t\t\t\t\t\t\t\t! disallowedPostMetaKeys.has( metaKey )\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\n\t\t\t\t\t// Merge the allowed meta changes with the current meta values since\n\t\t\t\t\t// not all meta properties are synced.\n\t\t\t\t\tconst mergedValue = {\n\t\t\t\t\t\t...( currentValue as PostChanges[ 'meta' ] ),\n\t\t\t\t\t\t...allowedMetaChanges,\n\t\t\t\t\t};\n\n\t\t\t\t\treturn haveValuesChanged( currentValue, mergedValue );\n\t\t\t\t}\n\n\t\t\t\tcase 'status': {\n\t\t\t\t\t// Do not sync an invalid status.\n\t\t\t\t\tif ( 'auto-draft' === newValue ) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\n\t\t\t\tcase 'content':\n\t\t\t\tcase 'excerpt':\n\t\t\t\tcase 'title': {\n\t\t\t\t\treturn haveValuesChanged(\n\t\t\t\t\t\tgetRawValue( currentValue ),\n\t\t\t\t\t\tnewValue\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Add support for additional data types here.\n\n\t\t\t\tdefault: {\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\t\t\t}\n\t\t} )\n\t);\n\n\t// Meta changes must be merged with the edited record since not all meta\n\t// properties are synced.\n\tif ( 'object' === typeof changes.meta ) {\n\t\tchanges.meta = {\n\t\t\t...editedRecord.meta,\n\t\t\t...allowedMetaChanges,\n\t\t};\n\t}\n\n\t// When remote content changes are detected, recalculate the local user's\n\t// selection using Y.RelativePosition to account for text shifts. The ydoc\n\t// has already been updated with remote content at this point, so converting\n\t// relative positions to absolute gives corrected offsets. Including the\n\t// selection in PostChanges ensures it dispatches atomically with content.\n\tconst selectionHistory = getSelectionHistory( ydoc );\n\tconst shiftedSelection = getShiftedSelection( ydoc, selectionHistory );\n\tif ( shiftedSelection ) {\n\t\tchanges.selection = {\n\t\t\t...shiftedSelection,\n\t\t\tinitialPosition: 0,\n\t\t};\n\t}\n\n\treturn changes;\n}\n\n/**\n * This default sync config can be used for entities that are flat maps of\n * primitive values and do not require custom logic to merge changes.\n */\nexport const defaultSyncConfig: SyncConfig = {\n\tapplyChangesToCRDTDoc: defaultApplyChangesToCRDTDoc,\n\tcreateAwareness: ( ydoc: CRDTDoc ) => new BaseAwareness( ydoc ),\n\tgetChangesFromCRDTDoc: defaultGetChangesFromCRDTDoc,\n};\n\n/**\n * Extract the raw string value from a property that may be a string or an object\n * with a `raw` property (`RenderedText`).\n *\n * @param {unknown} value The value to extract from.\n * @return {string|undefined} The raw string value, or undefined if it could not be determined.\n */\nfunction getRawValue( value?: unknown ): string | undefined {\n\t// Value may be a string property or a nested object with a `raw` property.\n\tif ( 'string' === typeof value ) {\n\t\treturn value;\n\t}\n\n\tif (\n\t\tvalue &&\n\t\t'object' === typeof value &&\n\t\t'raw' in value &&\n\t\t'string' === typeof value.raw\n\t) {\n\t\treturn value.raw;\n\t}\n\n\treturn undefined;\n}\n\nfunction haveValuesChanged< ValueType >(\n\tcurrentValue: ValueType | undefined,\n\tnewValue: ValueType | undefined\n): boolean {\n\treturn ! fastDeepEqual( currentValue, newValue );\n}\n\nfunction updateMapValue< T extends YMapRecord, K extends keyof T >(\n\tmap: YMapWrap< T >,\n\tkey: K,\n\tcurrentValue: T[ K ] | undefined,\n\tnewValue: T[ K ] | undefined\n): void {\n\tif ( undefined === newValue ) {\n\t\tmap.delete( key );\n\t\treturn;\n\t}\n\n\tif ( haveValuesChanged< T[ K ] >( currentValue, newValue ) ) {\n\t\tmap.set( key, newValue );\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA0B;AAM1B,oBAA4C;AAC5C,kBAKO;AAKP,4BAA8B;AAC9B,yBAMO;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\n// @ts-expect-error No exported types.\nimport { __unstableSerializeAndClean } from '@wordpress/blocks';\nimport {\n\ttype CRDTDoc,\n\ttype ObjectData,\n\ttype SyncConfig,\n\tY,\n} from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport { BaseAwareness } from '../awareness/base-awareness';\nimport {\n\tmergeCrdtBlocks,\n\tmergeRichTextUpdate,\n\ttype Block,\n\ttype YBlock,\n\ttype YBlocks,\n} from './crdt-blocks';\nimport { type Post } from '../entity-types/post';\nimport { CRDT_DOC_META_PERSISTENCE_KEY, CRDT_RECORD_MAP_KEY } from '../sync';\nimport type { WPSelection } from '../types';\nimport {\n\tgetSelectionHistory,\n\tgetShiftedSelection,\n\tupdateSelectionHistory,\n} from './crdt-selection';\nimport {\n\tcreateYMap,\n\tgetRootMap,\n\tisYMap,\n\ttype YMapRecord,\n\ttype YMapWrap,\n} from './crdt-utils';\n\n// Changes that can be applied to a post entity record.\nexport type PostChanges = Partial< Post > & {\n\tblocks?: Block[];\n\tcontent?: Post[ 'content' ] | string;\n\texcerpt?: Post[ 'excerpt' ] | string;\n\tselection?: WPSelection;\n\ttitle?: Post[ 'title' ] | string;\n};\n\n// A post record as represented in the CRDT document (Y.Map).\nexport interface YPostRecord extends YMapRecord {\n\tauthor: number;\n\t// Blocks are undefined when they need to be re-parsed from content.\n\tblocks: YBlocks | undefined;\n\tcontent: Y.Text;\n\tcategories: number[];\n\tcomment_status: string;\n\tdate: string | null;\n\texcerpt: Y.Text;\n\tfeatured_media: number;\n\tformat: string;\n\tmeta: YMapWrap< YMapRecord >;\n\tping_status: string;\n\tslug: string;\n\tstatus: string;\n\tsticky: boolean;\n\ttags: number[];\n\ttemplate: string;\n\ttitle: Y.Text;\n}\n\nexport const POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE = '_crdt_document';\n\n// Post meta keys that should *not* be synced.\nconst disallowedPostMetaKeys = new Set< string >( [\n\tPOST_META_KEY_FOR_CRDT_DOC_PERSISTENCE,\n] );\n\n/**\n * Given a set of local changes to a generic entity record, apply those changes\n * to the local Y.Doc.\n *\n * @param {CRDTDoc} ydoc\n * @param {Partial< ObjectData >} changes\n * @return {void}\n */\nfunction defaultApplyChangesToCRDTDoc(\n\tydoc: CRDTDoc,\n\tchanges: ObjectData\n): void {\n\tconst ymap = getRootMap( ydoc, CRDT_RECORD_MAP_KEY );\n\n\tObject.entries( changes ).forEach( ( [ key, newValue ] ) => {\n\t\t// Cannot serialize function values, so cannot sync them.\n\t\tif ( 'function' === typeof newValue ) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch ( key ) {\n\t\t\t// Add support for additional data types here.\n\n\t\t\tdefault: {\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tupdateMapValue( ymap, key, currentValue, newValue );\n\t\t\t}\n\t\t}\n\t} );\n}\n\n/**\n * Given a set of local changes to a post record, apply those changes to the\n * local Y.Doc.\n *\n * @param {CRDTDoc} ydoc\n * @param {PostChanges} changes\n * @param {Set<string>} syncedProperties\n * @return {void}\n */\nexport function applyPostChangesToCRDTDoc(\n\tydoc: CRDTDoc,\n\tchanges: PostChanges,\n\tsyncedProperties: Set< string >\n): void {\n\tconst ymap = getRootMap< YPostRecord >( ydoc, CRDT_RECORD_MAP_KEY );\n\n\tObject.keys( changes ).forEach( ( key ) => {\n\t\tif ( ! syncedProperties.has( key ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newValue = changes[ key ];\n\n\t\t// Cannot serialize function values, so cannot sync them.\n\t\tif ( 'function' === typeof newValue ) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch ( key ) {\n\t\t\tcase 'blocks': {\n\t\t\t\t// Blocks are undefined when they need to be re-parsed from content.\n\t\t\t\tif ( ! newValue ) {\n\t\t\t\t\t// Set to undefined instead of deleting the key. This is important\n\t\t\t\t\t// since we iterate over the Y.Map keys in getPostChangesFromCRDTDoc.\n\t\t\t\t\tymap.set( key, undefined );\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tlet currentBlocks = ymap.get( key );\n\n\t\t\t\t// Initialize.\n\t\t\t\tif ( ! ( currentBlocks instanceof Y.Array ) ) {\n\t\t\t\t\tcurrentBlocks = new Y.Array< YBlock >();\n\t\t\t\t\tymap.set( key, currentBlocks );\n\t\t\t\t}\n\n\t\t\t\t// Block changes from typing are bundled with a 'selection' update.\n\t\t\t\t// Pass the resulting cursor position to the mergeCrdtBlocks function.\n\t\t\t\tconst cursorPosition =\n\t\t\t\t\tchanges.selection?.selectionStart?.offset ?? null;\n\n\t\t\t\t// Merge blocks does not need `setValue` because it is operating on a\n\t\t\t\t// Yjs type that is already in the Y.Doc.\n\t\t\t\tmergeCrdtBlocks( currentBlocks, newValue, cursorPosition );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'content':\n\t\t\tcase 'excerpt':\n\t\t\tcase 'title': {\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tlet rawValue = getRawValue( newValue );\n\n\t\t\t\t// Copy logic from prePersistPostType to ensure that the \"Auto\n\t\t\t\t// Draft\" template title is not synced.\n\t\t\t\tif (\n\t\t\t\t\tkey === 'title' &&\n\t\t\t\t\t! currentValue?.toString() &&\n\t\t\t\t\t'Auto Draft' === rawValue\n\t\t\t\t) {\n\t\t\t\t\trawValue = '';\n\t\t\t\t}\n\n\t\t\t\tif ( currentValue instanceof Y.Text ) {\n\t\t\t\t\tmergeRichTextUpdate( currentValue, rawValue ?? '' );\n\t\t\t\t} else {\n\t\t\t\t\tconst newYText = new Y.Text( rawValue ?? '' );\n\t\t\t\t\tymap.set( key, newYText );\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// \"Meta\" is overloaded term; here, it refers to post meta.\n\t\t\tcase 'meta': {\n\t\t\t\tlet metaMap = ymap.get( 'meta' );\n\n\t\t\t\t// Initialize.\n\t\t\t\tif ( ! isYMap( metaMap ) ) {\n\t\t\t\t\tmetaMap = createYMap< YMapRecord >();\n\t\t\t\t\tymap.set( 'meta', metaMap );\n\t\t\t\t}\n\n\t\t\t\t// Iterate over each meta property in the new value and merge it if it\n\t\t\t\t// should be synced.\n\t\t\t\tObject.entries( newValue ?? {} ).forEach(\n\t\t\t\t\t( [ metaKey, metaValue ] ) => {\n\t\t\t\t\t\tif ( disallowedPostMetaKeys.has( metaKey ) ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tupdateMapValue(\n\t\t\t\t\t\t\tmetaMap,\n\t\t\t\t\t\t\tmetaKey,\n\t\t\t\t\t\t\tmetaMap.get( metaKey ), // current value in CRDT\n\t\t\t\t\t\t\tmetaValue // new value from changes\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'slug': {\n\t\t\t\t// Do not sync an empty slug. This indicates that the post is using\n\t\t\t\t// the default auto-generated slug.\n\t\t\t\tif ( ! newValue ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tupdateMapValue( ymap, key, currentValue, newValue );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Add support for additional properties here.\n\n\t\t\tdefault: {\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tupdateMapValue( ymap, key, currentValue, newValue );\n\t\t\t}\n\t\t}\n\t} );\n\n\t// Process changes that we don't want to persist to the CRDT document.\n\tif ( changes.selection ) {\n\t\tconst selection = changes.selection;\n\t\t// Persist selection changes at the end of the current event loop.\n\t\t// This allows undo meta to be saved with the current selection before\n\t\t// it is overwritten by the new selection from Gutenberg.\n\t\t// Without this, selection history will already contain the latest\n\t\t// selection (after this change) when the undo stack is saved.\n\t\tsetTimeout( () => {\n\t\t\tupdateSelectionHistory( ydoc, selection );\n\t\t}, 0 );\n\t}\n}\n\nfunction defaultGetChangesFromCRDTDoc( crdtDoc: CRDTDoc ): ObjectData {\n\treturn getRootMap( crdtDoc, CRDT_RECORD_MAP_KEY ).toJSON();\n}\n\n/**\n * Given a local Y.Doc that *may* contain changes from remote peers, compare\n * against the local record and determine if there are changes (edits) we want\n * to dispatch.\n *\n * @param {CRDTDoc} ydoc\n * @param {Post} editedRecord\n * @param {Set<string>} syncedProperties\n * @return {Partial<PostChanges>} The changes that should be applied to the local record.\n */\nexport function getPostChangesFromCRDTDoc(\n\tydoc: CRDTDoc,\n\teditedRecord: Post,\n\tsyncedProperties: Set< string >\n): PostChanges {\n\tconst ymap = getRootMap< YPostRecord >( ydoc, CRDT_RECORD_MAP_KEY );\n\n\tlet allowedMetaChanges: Post[ 'meta' ] = {};\n\n\tconst changes = Object.fromEntries(\n\t\tObject.entries( ymap.toJSON() ).filter( ( [ key, newValue ] ) => {\n\t\t\tif ( ! syncedProperties.has( key ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst currentValue = editedRecord[ key ];\n\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'blocks': {\n\t\t\t\t\t// When we are passed a persisted CRDT document, make a special\n\t\t\t\t\t// comparison of the content and blocks.\n\t\t\t\t\t//\n\t\t\t\t\t// When other fields (besides `blocks`) are mutated outside the block\n\t\t\t\t\t// editor, the change is caught by an equality check (see other cases\n\t\t\t\t\t// in this `switch` statement). As a transient property, `blocks`\n\t\t\t\t\t// cannot be directly mutated outside the block editor -- only\n\t\t\t\t\t// `content` can.\n\t\t\t\t\t//\n\t\t\t\t\t// Therefore, for this special comparison, we serialize the `blocks`\n\t\t\t\t\t// from the persisted CRDT document and compare that to the content\n\t\t\t\t\t// from the persisted record. If they differ, we know that the content\n\t\t\t\t\t// in the database has changed, and therefore the blocks have changed.\n\t\t\t\t\t//\n\t\t\t\t\t// We cannot directly compare the `blocks` from the CRDT document to\n\t\t\t\t\t// the `blocks` derived from the `content` in the persisted record,\n\t\t\t\t\t// because the latter will have different client IDs.\n\t\t\t\t\tif (\n\t\t\t\t\t\tydoc.meta?.get( CRDT_DOC_META_PERSISTENCE_KEY ) &&\n\t\t\t\t\t\teditedRecord.content\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst blocksJson = ymap.get( 'blocks' )?.toJSON() ?? [];\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t__unstableSerializeAndClean( blocksJson ).trim() !==\n\t\t\t\t\t\t\tgetRawValue( editedRecord.content )\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tcase 'date': {\n\t\t\t\t\t// Do not overwrite a \"floating\" date. Borrowing logic from the\n\t\t\t\t\t// isEditedPostDateFloating selector.\n\t\t\t\t\tconst currentDateIsFloating =\n\t\t\t\t\t\tnull === currentValue ||\n\t\t\t\t\t\teditedRecord.modified === currentValue;\n\n\t\t\t\t\tif ( currentDateIsFloating ) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\n\t\t\t\tcase 'meta': {\n\t\t\t\t\tallowedMetaChanges = Object.fromEntries(\n\t\t\t\t\t\tObject.entries( newValue ?? {} ).filter(\n\t\t\t\t\t\t\t( [ metaKey ] ) =>\n\t\t\t\t\t\t\t\t! disallowedPostMetaKeys.has( metaKey )\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\n\t\t\t\t\t// Merge the allowed meta changes with the current meta values since\n\t\t\t\t\t// not all meta properties are synced.\n\t\t\t\t\tconst mergedValue = {\n\t\t\t\t\t\t...( currentValue as PostChanges[ 'meta' ] ),\n\t\t\t\t\t\t...allowedMetaChanges,\n\t\t\t\t\t};\n\n\t\t\t\t\treturn haveValuesChanged( currentValue, mergedValue );\n\t\t\t\t}\n\n\t\t\t\tcase 'status': {\n\t\t\t\t\t// Do not sync an invalid status.\n\t\t\t\t\tif ( 'auto-draft' === newValue ) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\n\t\t\t\tcase 'content':\n\t\t\t\tcase 'excerpt':\n\t\t\t\tcase 'title': {\n\t\t\t\t\treturn haveValuesChanged(\n\t\t\t\t\t\tgetRawValue( currentValue ),\n\t\t\t\t\t\tnewValue\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Add support for additional data types here.\n\n\t\t\t\tdefault: {\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\t\t\t}\n\t\t} )\n\t);\n\n\t// Meta changes must be merged with the edited record since not all meta\n\t// properties are synced.\n\tif ( 'object' === typeof changes.meta ) {\n\t\tchanges.meta = {\n\t\t\t...editedRecord.meta,\n\t\t\t...allowedMetaChanges,\n\t\t};\n\t}\n\n\t// When remote content changes are detected, recalculate the local user's\n\t// selection using Y.RelativePosition to account for text shifts. The ydoc\n\t// has already been updated with remote content at this point, so converting\n\t// relative positions to absolute gives corrected offsets. Including the\n\t// selection in PostChanges ensures it dispatches atomically with content.\n\tconst selectionHistory = getSelectionHistory( ydoc );\n\tconst shiftedSelection = getShiftedSelection( ydoc, selectionHistory );\n\tif ( shiftedSelection ) {\n\t\tchanges.selection = {\n\t\t\t...shiftedSelection,\n\t\t\tinitialPosition: 0,\n\t\t};\n\t}\n\n\treturn changes;\n}\n\n/**\n * This default sync config can be used for entities that are flat maps of\n * primitive values and do not require custom logic to merge changes.\n */\nexport const defaultSyncConfig: SyncConfig = {\n\tapplyChangesToCRDTDoc: defaultApplyChangesToCRDTDoc,\n\tcreateAwareness: ( ydoc: CRDTDoc ) => new BaseAwareness( ydoc ),\n\tgetChangesFromCRDTDoc: defaultGetChangesFromCRDTDoc,\n};\n\n/**\n * Extract the raw string value from a property that may be a string or an object\n * with a `raw` property (`RenderedText`).\n *\n * @param {unknown} value The value to extract from.\n * @return {string|undefined} The raw string value, or undefined if it could not be determined.\n */\nfunction getRawValue( value?: unknown ): string | undefined {\n\t// Value may be a string property or a nested object with a `raw` property.\n\tif ( 'string' === typeof value ) {\n\t\treturn value;\n\t}\n\n\tif (\n\t\tvalue &&\n\t\t'object' === typeof value &&\n\t\t'raw' in value &&\n\t\t'string' === typeof value.raw\n\t) {\n\t\treturn value.raw;\n\t}\n\n\treturn undefined;\n}\n\nfunction haveValuesChanged< ValueType >(\n\tcurrentValue: ValueType | undefined,\n\tnewValue: ValueType | undefined\n): boolean {\n\treturn ! fastDeepEqual( currentValue, newValue );\n}\n\nfunction updateMapValue< T extends YMapRecord, K extends keyof T >(\n\tmap: YMapWrap< T >,\n\tkey: K,\n\tcurrentValue: T[ K ] | undefined,\n\tnewValue: T[ K ] | undefined\n): void {\n\tif ( undefined === newValue ) {\n\t\tmap.delete( key );\n\t\treturn;\n\t}\n\n\tif ( haveValuesChanged< T[ K ] >( currentValue, newValue ) ) {\n\t\tmap.set( key, newValue );\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA0B;AAM1B,oBAA4C;AAC5C,kBAKO;AAKP,4BAA8B;AAC9B,yBAMO;AAEP,IAAAA,eAAmE;AAEnE,4BAIO;AACP,wBAMO;AAiCA,IAAM,yCAAyC;AAGtD,IAAM,yBAAyB,oBAAI,IAAe;AAAA,EACjD;AACD,CAAE;AAUF,SAAS,6BACR,MACA,SACO;AACP,QAAM,WAAO,8BAAY,MAAM,gCAAoB;AAEnD,SAAO,QAAS,OAAQ,EAAE,QAAS,CAAE,CAAE,KAAK,QAAS,MAAO;AAE3D,QAAK,eAAe,OAAO,UAAW;AACrC;AAAA,IACD;AAEA,YAAS,KAAM;AAAA;AAAA,MAGd,SAAS;AACR,cAAM,eAAe,KAAK,IAAK,GAAI;AACnC,uBAAgB,MAAM,KAAK,cAAc,QAAS;AAAA,MACnD;AAAA,IACD;AAAA,EACD,CAAE;AACH;AAWO,SAAS,0BACf,MACA,SACA,kBACO;AACP,QAAM,WAAO,8BAA2B,MAAM,gCAAoB;AAElE,SAAO,KAAM,OAAQ,EAAE,QAAS,CAAE,QAAS;AAC1C,QAAK,CAAE,iBAAiB,IA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AK,aAAa,OAAO,OAAQ;AAChC,WAAO;AAAA,EACR;AAEA,MACC,SACA,aAAa,OAAO,SACpB,SAAS,SACT,aAAa,OAAO,MAAM,KACzB;AACD,WAAO,MAAM;AAAA,EACd;AAEA,SAAO;AACR;AAEA,SAAS,kBACR,cACA,UACU;AACV,SAAO,KAAE,WAAAC,SAAe,cAAc,QAAS;AAChD;AAEA,SAAS,eACR,KACA,KACA,cACA,UACO;AACP,MAAK,WAAc,UAAW;AAC7B,QAAI,OAAQ,GAAI;AAChB;AAAA,EACD;AAEA,MAAK,kBAA6B,cAAc,QAAS,GAAI;AAC5D,QAAI,IAAK,KAAK,QAAS;AAAA,EACxB;AACD;",
|
|
6
6
|
"names": ["import_sync", "fastDeepEqual"]
|
|
7
7
|
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
LOCAL_CURSOR_UPDATE_DEBOUNCE_IN_MS
|
|
10
10
|
} from "./config.mjs";
|
|
11
11
|
import { STORE_NAME as coreStore } from "../name.mjs";
|
|
12
|
+
import { htmlIndexToRichTextOffset } from "../utils/crdt-utils.mjs";
|
|
12
13
|
import {
|
|
13
14
|
areSelectionsStatesEqual,
|
|
14
15
|
getSelectionState,
|
|
@@ -143,11 +144,11 @@ var PostEditorAwareness = class extends BaseAwarenessState {
|
|
|
143
144
|
* clientIds (e.g. in "Show Template" mode where blocks are cloned).
|
|
144
145
|
*
|
|
145
146
|
* @param selection - The selection state.
|
|
146
|
-
* @return The text
|
|
147
|
+
* @return The rich-text offset and block client ID, or nulls if not resolvable.
|
|
147
148
|
*/
|
|
148
149
|
convertSelectionStateToAbsolute(selection) {
|
|
149
150
|
if (selection.type === SelectionType.None) {
|
|
150
|
-
return {
|
|
151
|
+
return { richTextOffset: null, localClientId: null };
|
|
151
152
|
}
|
|
152
153
|
if (selection.type === SelectionType.WholeBlock) {
|
|
153
154
|
const absolutePos = Y.createAbsolutePositionFromRelativePosition(
|
|
@@ -163,7 +164,7 @@ var PostEditorAwareness = class extends BaseAwarenessState {
|
|
|
163
164
|
localClientId2 = path2 ? resolveBlockClientIdByPath(path2) : null;
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
|
-
return {
|
|
167
|
+
return { richTextOffset: null, localClientId: localClientId2 };
|
|
167
168
|
}
|
|
168
169
|
const cursorPos = "cursorPosition" in selection ? selection.cursorPosition : selection.cursorStartPosition;
|
|
169
170
|
const absolutePosition = Y.createAbsolutePositionFromRelativePosition(
|
|
@@ -171,12 +172,18 @@ var PostEditorAwareness = class extends BaseAwarenessState {
|
|
|
171
172
|
this.doc
|
|
172
173
|
);
|
|
173
174
|
if (!absolutePosition) {
|
|
174
|
-
return {
|
|
175
|
+
return { richTextOffset: null, localClientId: null };
|
|
175
176
|
}
|
|
176
177
|
const yType = absolutePosition.type.parent?.parent;
|
|
177
178
|
const path = yType instanceof Y.Map ? getBlockPathInYdoc(yType) : null;
|
|
178
179
|
const localClientId = path ? resolveBlockClientIdByPath(path) : null;
|
|
179
|
-
return {
|
|
180
|
+
return {
|
|
181
|
+
richTextOffset: htmlIndexToRichTextOffset(
|
|
182
|
+
absolutePosition.type.toString(),
|
|
183
|
+
absolutePosition.index
|
|
184
|
+
),
|
|
185
|
+
localClientId
|
|
186
|
+
};
|
|
180
187
|
}
|
|
181
188
|
/**
|
|
182
189
|
* Type guard to check if a struct is a Y.Item (not Y.GC)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/awareness/post-editor-awareness.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { dispatch, select, subscribe } from '@wordpress/data';\nimport { Y } from '@wordpress/sync';\n// @ts-ignore No exported types for block editor store selectors.\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { BaseAwarenessState, baseEqualityFieldChecks } from './base-awareness';\nimport { getBlockPathInYdoc, resolveBlockClientIdByPath } from './block-lookup';\nimport {\n\tAWARENESS_CURSOR_UPDATE_THROTTLE_IN_MS,\n\tLOCAL_CURSOR_UPDATE_DEBOUNCE_IN_MS,\n} from './config';\nimport { STORE_NAME as coreStore } from '../name';\nimport {\n\tareSelectionsStatesEqual,\n\tgetSelectionState,\n\tSelectionType,\n} from '../utils/crdt-user-selections';\n\nimport { SelectionDirection } from '../types';\nimport type { SelectionState, WPBlockSelection } from '../types';\nimport type { YBlocks } from '../utils/crdt-blocks';\nimport type {\n\tDebugCollaboratorData,\n\tEditorState,\n\tPostEditorState,\n\tSerializableYItem,\n\tYDocDebugData,\n} from './types';\n\nexport class PostEditorAwareness extends BaseAwarenessState< PostEditorState > {\n\tprotected equalityFieldChecks = {\n\t\t...baseEqualityFieldChecks,\n\t\teditorState: this.areEditorStatesEqual,\n\t};\n\n\tpublic constructor(\n\t\tdoc: Y.Doc,\n\t\tprivate kind: string,\n\t\tprivate name: string,\n\t\tprivate postId: number\n\t) {\n\t\tsuper( doc );\n\t}\n\n\tprotected onSetUp(): void {\n\t\tsuper.onSetUp();\n\n\t\tthis.subscribeToCollaboratorSelectionChanges();\n\t}\n\n\t/**\n\t * Subscribe to collaborator selection changes and update the selection state.\n\t */\n\tprivate subscribeToCollaboratorSelectionChanges(): void {\n\t\tconst {\n\t\t\tgetSelectionStart,\n\t\t\tgetSelectionEnd,\n\t\t\tgetSelectedBlocksInitialCaretPosition,\n\t\t} = select( blockEditorStore );\n\n\t\t// Keep track of the current selection in the outer scope so we can compare\n\t\t// in the subscription.\n\t\tlet selectionStart = getSelectionStart();\n\t\tlet selectionEnd = getSelectionEnd();\n\t\tlet localCursorTimeout: NodeJS.Timeout | null = null;\n\n\t\t// During rapid selection changes (e.g. undo restoring content and\n\t\t// selection), the debounce discards intermediate events. If we use the\n\t\t// last intermediate state instead of the overall change it can produce\n\t\t// the wrong direction.\n\t\t// Use selectionBeforeDebounce to capture the selection state from\n\t\t// before the debounce window so that direction is computed across the\n\t\t// full window when it fires.\n\t\tlet selectionBeforeDebounce: {\n\t\t\tstart: WPBlockSelection;\n\t\t\tend: WPBlockSelection;\n\t\t} | null = null;\n\n\t\tsubscribe( () => {\n\t\t\tconst newSelectionStart = getSelectionStart();\n\t\t\tconst newSelectionEnd = getSelectionEnd();\n\n\t\t\tif (\n\t\t\t\tnewSelectionStart === selectionStart &&\n\t\t\t\tnewSelectionEnd === selectionEnd\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// On the first change of a debounce window, snapshot the state\n\t\t\t// we're moving away from.\n\t\t\tif ( ! selectionBeforeDebounce ) {\n\t\t\t\tselectionBeforeDebounce = {\n\t\t\t\t\tstart: selectionStart,\n\t\t\t\t\tend: selectionEnd,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tselectionStart = newSelectionStart;\n\t\t\tselectionEnd = newSelectionEnd;\n\n\t\t\t// Typically selection position is only persisted after typing in a block, which\n\t\t\t// can cause selection position to be reset by other users making block updates.\n\t\t\t// Ensure we update the controlled selection right away, persisting our cursor position locally.\n\t\t\tconst initialPosition = getSelectedBlocksInitialCaretPosition();\n\t\t\tvoid this.updateSelectionInEntityRecord(\n\t\t\t\tselectionStart,\n\t\t\t\tselectionEnd,\n\t\t\t\tinitialPosition\n\t\t\t);\n\n\t\t\t// We receive two selection changes in quick succession\n\t\t\t// from local selection events:\n\t\t\t// { clientId: \"123...\", attributeKey: \"content\", offset: undefined }\n\t\t\t// { clientId: \"123...\", attributeKey: \"content\", offset: 554 }\n\t\t\t// Add a short debounce to avoid sending the first selection change.\n\t\t\tif ( localCursorTimeout ) {\n\t\t\t\tclearTimeout( localCursorTimeout );\n\t\t\t}\n\n\t\t\tlocalCursorTimeout = setTimeout( () => {\n\t\t\t\t// Compute direction across the full debounce window.\n\t\t\t\tconst selectionStateOptions: {\n\t\t\t\t\tselectionDirection?: SelectionDirection;\n\t\t\t\t} = {};\n\n\t\t\t\tif ( selectionBeforeDebounce ) {\n\t\t\t\t\tselectionStateOptions.selectionDirection =\n\t\t\t\t\t\tdetectSelectionDirection(\n\t\t\t\t\t\t\tselectionBeforeDebounce.start,\n\t\t\t\t\t\t\tselectionBeforeDebounce.end,\n\t\t\t\t\t\t\tselectionStart,\n\t\t\t\t\t\t\tselectionEnd\n\t\t\t\t\t\t);\n\n\t\t\t\t\t// Reset debounced selection state.\n\t\t\t\t\tselectionBeforeDebounce = null;\n\t\t\t\t}\n\n\t\t\t\tconst selectionState = getSelectionState(\n\t\t\t\t\tselectionStart,\n\t\t\t\t\tselectionEnd,\n\t\t\t\t\tthis.doc,\n\t\t\t\t\tselectionStateOptions\n\t\t\t\t);\n\n\t\t\t\tthis.setThrottledLocalStateField(\n\t\t\t\t\t'editorState',\n\t\t\t\t\t{ selection: selectionState },\n\t\t\t\t\tAWARENESS_CURSOR_UPDATE_THROTTLE_IN_MS\n\t\t\t\t);\n\t\t\t}, LOCAL_CURSOR_UPDATE_DEBOUNCE_IN_MS );\n\t\t} );\n\t}\n\n\t/**\n\t * Update the entity record with the current collaborator's selection.\n\t *\n\t * @param selectionStart - The start position of the selection.\n\t * @param selectionEnd - The end position of the selection.\n\t * @param initialPosition - The initial position of the selection.\n\t */\n\tprivate async updateSelectionInEntityRecord(\n\t\tselectionStart: WPBlockSelection,\n\t\tselectionEnd: WPBlockSelection,\n\t\tinitialPosition: number | null\n\t): Promise< void > {\n\t\t// Send an entityRecord `selection` update if we have a selection.\n\t\t//\n\t\t// Normally WordPress updates the `selection` property of the post when changes are made to blocks.\n\t\t// In a multi-user setup, block changes can occur from other users. When an entity is updated from another\n\t\t// user's changes, useBlockSync() in Gutenberg will reset the user's selection to the last saved selection.\n\t\t//\n\t\t// Manually adding an edit for each movement ensures that other user's changes to the document will\n\t\t// not cause the local user's selection to reset to the last local change location.\n\t\tconst edits = {\n\t\t\tselection: { selectionStart, selectionEnd, initialPosition },\n\t\t};\n\n\t\tconst options = {\n\t\t\tundoIgnore: true,\n\t\t};\n\n\t\t// @ts-ignore Types are not provided when using store name instead of store instance.\n\t\tdispatch( coreStore ).editEntityRecord(\n\t\t\tthis.kind,\n\t\t\tthis.name,\n\t\t\tthis.postId,\n\t\t\tedits,\n\t\t\toptions\n\t\t);\n\t}\n\n\t/**\n\t * Check if two editor states are equal.\n\t *\n\t * @param state1 - The first editor state.\n\t * @param state2 - The second editor state.\n\t * @return True if the editor states are equal, false otherwise.\n\t */\n\tprivate areEditorStatesEqual(\n\t\tstate1?: EditorState,\n\t\tstate2?: EditorState\n\t): boolean {\n\t\tif ( ! state1 || ! state2 ) {\n\t\t\treturn state1 === state2;\n\t\t}\n\n\t\tif ( ! state1.selection || ! state2.selection ) {\n\t\t\treturn state1.selection === state2.selection;\n\t\t}\n\n\t\treturn areSelectionsStatesEqual( state1.selection, state2.selection );\n\t}\n\n\t/**\n\t * Resolve a selection state to a text index and block client ID.\n\t *\n\t * For text-based selections, navigates up from the resolved Y.Text via\n\t * AbstractType.parent to find the containing block, then resolves the\n\t * local clientId via the block's tree path.\n\t * For WholeBlock selections, resolves the block's relative position and\n\t * then finds the local clientId via tree path.\n\t *\n\t * Tree-path resolution is used instead of reading the clientId directly\n\t * from the Yjs block because the local block-editor store may use different\n\t * clientIds (e.g. in \"Show Template\" mode where blocks are cloned).\n\t *\n\t * @param selection - The selection state.\n\t * @return The text index and block client ID, or nulls if not resolvable.\n\t */\n\tpublic convertSelectionStateToAbsolute( selection: SelectionState ): {\n\t\ttextIndex: number | null;\n\t\tlocalClientId: string | null;\n\t} {\n\t\tif ( selection.type === SelectionType.None ) {\n\t\t\treturn { textIndex: null, localClientId: null };\n\t\t}\n\n\t\tif ( selection.type === SelectionType.WholeBlock ) {\n\t\t\tconst absolutePos = Y.createAbsolutePositionFromRelativePosition(\n\t\t\t\tselection.blockPosition,\n\t\t\t\tthis.doc\n\t\t\t);\n\n\t\t\tlet localClientId: string | null = null;\n\n\t\t\tif ( absolutePos && absolutePos.type instanceof Y.Array ) {\n\t\t\t\tconst parentArray = absolutePos.type as YBlocks;\n\t\t\t\tconst block = parentArray.get( absolutePos.index );\n\n\t\t\t\tif ( block instanceof Y.Map ) {\n\t\t\t\t\tconst path = getBlockPathInYdoc( block );\n\t\t\t\t\tlocalClientId = path\n\t\t\t\t\t\t? resolveBlockClientIdByPath( path )\n\t\t\t\t\t\t: null;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { textIndex: null, localClientId };\n\t\t}\n\n\t\t// Text-based selections: resolve cursor position and navigate up.\n\t\tconst cursorPos =\n\t\t\t'cursorPosition' in selection\n\t\t\t\t? selection.cursorPosition\n\t\t\t\t: selection.cursorStartPosition;\n\n\t\tconst absolutePosition = Y.createAbsolutePositionFromRelativePosition(\n\t\t\tcursorPos.relativePosition,\n\t\t\tthis.doc\n\t\t);\n\n\t\tif ( ! absolutePosition ) {\n\t\t\treturn { textIndex: null, localClientId: null };\n\t\t}\n\n\t\t// Navigate up: Y.Text -> attributes Y.Map -> block Y.Map\n\t\tconst yType = absolutePosition.type.parent?.parent;\n\t\tconst path =\n\t\t\tyType instanceof Y.Map ? getBlockPathInYdoc( yType ) : null;\n\t\tconst localClientId = path ? resolveBlockClientIdByPath( path ) : null;\n\n\t\treturn { textIndex: absolutePosition.index, localClientId };\n\t}\n\n\t/**\n\t * Type guard to check if a struct is a Y.Item (not Y.GC)\n\t * @param struct - The struct to check.\n\t * @return True if the struct is a Y.Item, false otherwise.\n\t */\n\tprivate isYItem( struct: Y.Item | Y.GC ): struct is Y.Item {\n\t\treturn 'content' in struct;\n\t}\n\n\t/**\n\t * Get data for debugging, using the awareness state.\n\t *\n\t * @return {YDocDebugData} The debug data.\n\t */\n\tpublic getDebugData(): YDocDebugData {\n\t\tconst ydoc = this.doc;\n\n\t\t// Manually extract doc data to avoid deprecated toJSON method\n\t\tconst docData: Record< string, unknown > = Object.fromEntries(\n\t\t\tArray.from( ydoc.share, ( [ key, value ] ) => [\n\t\t\t\tkey,\n\t\t\t\tvalue.toJSON(),\n\t\t\t] )\n\t\t);\n\n\t\t// Build collaboratorMap from awareness store (all collaborators seen this session)\n\t\tconst collaboratorMapData = new Map< string, DebugCollaboratorData >(\n\t\t\tArray.from( this.getSeenStates().entries() ).map(\n\t\t\t\t( [ clientId, collaboratorState ] ) => [\n\t\t\t\t\tString( clientId ),\n\t\t\t\t\t{\n\t\t\t\t\t\tname: collaboratorState.collaboratorInfo.name,\n\t\t\t\t\t\twpUserId: collaboratorState.collaboratorInfo.id,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t)\n\t\t);\n\n\t\t// Serialize Yjs client items to avoid deep nesting\n\t\tconst serializableClientItems: Record<\n\t\t\tnumber,\n\t\t\tArray< SerializableYItem >\n\t\t> = {};\n\n\t\tydoc.store.clients.forEach( ( structs, clientId ) => {\n\t\t\t// Filter for Y.Item only (skip Y.GC garbage collection structs)\n\t\t\tconst items = structs.filter( this.isYItem );\n\n\t\t\tserializableClientItems[ clientId ] = items.map( ( item ) => {\n\t\t\t\tconst { left, right, ...rest } = item;\n\n\t\t\t\treturn {\n\t\t\t\t\t...rest,\n\t\t\t\t\tleft: left\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tid: left.id,\n\t\t\t\t\t\t\t\tlength: left.length,\n\t\t\t\t\t\t\t\torigin: left.origin,\n\t\t\t\t\t\t\t\tcontent: left.content,\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: null,\n\t\t\t\t\tright: right\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tid: right.id,\n\t\t\t\t\t\t\t\tlength: right.length,\n\t\t\t\t\t\t\t\torigin: right.origin,\n\t\t\t\t\t\t\t\tcontent: right.content,\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: null,\n\t\t\t\t};\n\t\t\t} );\n\t\t} );\n\n\t\treturn {\n\t\t\tdoc: docData,\n\t\t\tclients: serializableClientItems,\n\t\t\tcollaboratorMap: Object.fromEntries( collaboratorMapData ),\n\t\t};\n\t}\n}\n\n/**\n * Detect the direction of a selection change by comparing old and new edges.\n *\n * When the user extends a selection backward (e.g. Shift+Left), the\n * selectionStart edge moves while selectionEnd stays fixed, so the caret\n * is at the start. The reverse is true for forward extension.\n *\n * @param prevStart - The previous selectionStart.\n * @param prevEnd - The previous selectionEnd.\n * @param newStart - The new selectionStart.\n * @param newEnd - The new selectionEnd.\n * @return The detected direction, defaulting to Forward when indeterminate.\n */\nfunction detectSelectionDirection(\n\tprevStart: WPBlockSelection,\n\tprevEnd: WPBlockSelection,\n\tnewStart: WPBlockSelection,\n\tnewEnd: WPBlockSelection\n): SelectionDirection {\n\tconst startMoved = ! areBlockSelectionsEqual( prevStart, newStart );\n\tconst endMoved = ! areBlockSelectionsEqual( prevEnd, newEnd );\n\n\tif ( startMoved && ! endMoved ) {\n\t\treturn SelectionDirection.Backward;\n\t}\n\n\treturn SelectionDirection.Forward;\n}\n\n/**\n * Compare two WPBlockSelection objects by value.\n *\n * @param a - First selection.\n * @param b - Second selection.\n * @return True if all fields are equal.\n */\nfunction areBlockSelectionsEqual(\n\ta: WPBlockSelection,\n\tb: WPBlockSelection\n): boolean {\n\treturn (\n\t\ta.clientId === b.clientId &&\n\t\ta.attributeKey === b.attributeKey &&\n\t\ta.offset === b.offset\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,UAAU,QAAQ,iBAAiB;AAC5C,SAAS,SAAS;AAElB,SAAS,SAAS,wBAAwB;AAK1C,SAAS,oBAAoB,+BAA+B;AAC5D,SAAS,oBAAoB,kCAAkC;AAC/D;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,cAAc,iBAAiB;AACxC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,SAAS,0BAA0B;AAW5B,IAAM,sBAAN,cAAkC,mBAAsC;AAAA,EAMvE,YACN,KACQ,MACA,MACA,QACP;AACD,UAAO,GAAI;AAJH;AACA;AACA;AAAA,EAGT;AAAA,EAZU,sBAAsB;AAAA,IAC/B,GAAG;AAAA,IACH,aAAa,KAAK;AAAA,EACnB;AAAA,EAWU,UAAgB;AACzB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C5D;AAEA,UAAM,UAAU;AAAA,MACf,YAAY;AAAA,IACb;AAGA,aAAU,SAAU,EAAE;AAAA,MACrB,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,qBACP,QACA,QACU;AACV,QAAK,CAAE,UAAU,CAAE,QAAS;AAC3B,aAAO,WAAW;AAAA,IACnB;AAEA,QAAK,CAAE,OAAO,aAAa,CAAE,OAAO,WAAY;AAC/C,aAAO,OAAO,cAAc,OAAO;AAAA,IACpC;AAEA,WAAO,yBAA0B,OAAO,WAAW,OAAO,SAAU;AAAA,EACrE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBO,gCAAiC,WAGtC;AACD,QAAK,UAAU,SAAS,cAAc,MAAO;AAC5C,aAAO,EAAE,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { dispatch, select, subscribe } from '@wordpress/data';\nimport { Y } from '@wordpress/sync';\n// @ts-ignore No exported types for block editor store selectors.\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { BaseAwarenessState, baseEqualityFieldChecks } from './base-awareness';\nimport { getBlockPathInYdoc, resolveBlockClientIdByPath } from './block-lookup';\nimport {\n\tAWARENESS_CURSOR_UPDATE_THROTTLE_IN_MS,\n\tLOCAL_CURSOR_UPDATE_DEBOUNCE_IN_MS,\n} from './config';\nimport { STORE_NAME as coreStore } from '../name';\nimport { htmlIndexToRichTextOffset } from '../utils/crdt-utils';\nimport {\n\tareSelectionsStatesEqual,\n\tgetSelectionState,\n\tSelectionType,\n} from '../utils/crdt-user-selections';\n\nimport { SelectionDirection } from '../types';\nimport type { SelectionState, WPBlockSelection } from '../types';\nimport type { YBlocks } from '../utils/crdt-blocks';\nimport type {\n\tDebugCollaboratorData,\n\tEditorState,\n\tPostEditorState,\n\tSerializableYItem,\n\tYDocDebugData,\n} from './types';\n\nexport class PostEditorAwareness extends BaseAwarenessState< PostEditorState > {\n\tprotected equalityFieldChecks = {\n\t\t...baseEqualityFieldChecks,\n\t\teditorState: this.areEditorStatesEqual,\n\t};\n\n\tpublic constructor(\n\t\tdoc: Y.Doc,\n\t\tprivate kind: string,\n\t\tprivate name: string,\n\t\tprivate postId: number\n\t) {\n\t\tsuper( doc );\n\t}\n\n\tprotected onSetUp(): void {\n\t\tsuper.onSetUp();\n\n\t\tthis.subscribeToCollaboratorSelectionChanges();\n\t}\n\n\t/**\n\t * Subscribe to collaborator selection changes and update the selection state.\n\t */\n\tprivate subscribeToCollaboratorSelectionChanges(): void {\n\t\tconst {\n\t\t\tgetSelectionStart,\n\t\t\tgetSelectionEnd,\n\t\t\tgetSelectedBlocksInitialCaretPosition,\n\t\t} = select( blockEditorStore );\n\n\t\t// Keep track of the current selection in the outer scope so we can compare\n\t\t// in the subscription.\n\t\tlet selectionStart = getSelectionStart();\n\t\tlet selectionEnd = getSelectionEnd();\n\t\tlet localCursorTimeout: NodeJS.Timeout | null = null;\n\n\t\t// During rapid selection changes (e.g. undo restoring content and\n\t\t// selection), the debounce discards intermediate events. If we use the\n\t\t// last intermediate state instead of the overall change it can produce\n\t\t// the wrong direction.\n\t\t// Use selectionBeforeDebounce to capture the selection state from\n\t\t// before the debounce window so that direction is computed across the\n\t\t// full window when it fires.\n\t\tlet selectionBeforeDebounce: {\n\t\t\tstart: WPBlockSelection;\n\t\t\tend: WPBlockSelection;\n\t\t} | null = null;\n\n\t\tsubscribe( () => {\n\t\t\tconst newSelectionStart = getSelectionStart();\n\t\t\tconst newSelectionEnd = getSelectionEnd();\n\n\t\t\tif (\n\t\t\t\tnewSelectionStart === selectionStart &&\n\t\t\t\tnewSelectionEnd === selectionEnd\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// On the first change of a debounce window, snapshot the state\n\t\t\t// we're moving away from.\n\t\t\tif ( ! selectionBeforeDebounce ) {\n\t\t\t\tselectionBeforeDebounce = {\n\t\t\t\t\tstart: selectionStart,\n\t\t\t\t\tend: selectionEnd,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tselectionStart = newSelectionStart;\n\t\t\tselectionEnd = newSelectionEnd;\n\n\t\t\t// Typically selection position is only persisted after typing in a block, which\n\t\t\t// can cause selection position to be reset by other users making block updates.\n\t\t\t// Ensure we update the controlled selection right away, persisting our cursor position locally.\n\t\t\tconst initialPosition = getSelectedBlocksInitialCaretPosition();\n\t\t\tvoid this.updateSelectionInEntityRecord(\n\t\t\t\tselectionStart,\n\t\t\t\tselectionEnd,\n\t\t\t\tinitialPosition\n\t\t\t);\n\n\t\t\t// We receive two selection changes in quick succession\n\t\t\t// from local selection events:\n\t\t\t// { clientId: \"123...\", attributeKey: \"content\", offset: undefined }\n\t\t\t// { clientId: \"123...\", attributeKey: \"content\", offset: 554 }\n\t\t\t// Add a short debounce to avoid sending the first selection change.\n\t\t\tif ( localCursorTimeout ) {\n\t\t\t\tclearTimeout( localCursorTimeout );\n\t\t\t}\n\n\t\t\tlocalCursorTimeout = setTimeout( () => {\n\t\t\t\t// Compute direction across the full debounce window.\n\t\t\t\tconst selectionStateOptions: {\n\t\t\t\t\tselectionDirection?: SelectionDirection;\n\t\t\t\t} = {};\n\n\t\t\t\tif ( selectionBeforeDebounce ) {\n\t\t\t\t\tselectionStateOptions.selectionDirection =\n\t\t\t\t\t\tdetectSelectionDirection(\n\t\t\t\t\t\t\tselectionBeforeDebounce.start,\n\t\t\t\t\t\t\tselectionBeforeDebounce.end,\n\t\t\t\t\t\t\tselectionStart,\n\t\t\t\t\t\t\tselectionEnd\n\t\t\t\t\t\t);\n\n\t\t\t\t\t// Reset debounced selection state.\n\t\t\t\t\tselectionBeforeDebounce = null;\n\t\t\t\t}\n\n\t\t\t\tconst selectionState = getSelectionState(\n\t\t\t\t\tselectionStart,\n\t\t\t\t\tselectionEnd,\n\t\t\t\t\tthis.doc,\n\t\t\t\t\tselectionStateOptions\n\t\t\t\t);\n\n\t\t\t\tthis.setThrottledLocalStateField(\n\t\t\t\t\t'editorState',\n\t\t\t\t\t{ selection: selectionState },\n\t\t\t\t\tAWARENESS_CURSOR_UPDATE_THROTTLE_IN_MS\n\t\t\t\t);\n\t\t\t}, LOCAL_CURSOR_UPDATE_DEBOUNCE_IN_MS );\n\t\t} );\n\t}\n\n\t/**\n\t * Update the entity record with the current collaborator's selection.\n\t *\n\t * @param selectionStart - The start position of the selection.\n\t * @param selectionEnd - The end position of the selection.\n\t * @param initialPosition - The initial position of the selection.\n\t */\n\tprivate async updateSelectionInEntityRecord(\n\t\tselectionStart: WPBlockSelection,\n\t\tselectionEnd: WPBlockSelection,\n\t\tinitialPosition: number | null\n\t): Promise< void > {\n\t\t// Send an entityRecord `selection` update if we have a selection.\n\t\t//\n\t\t// Normally WordPress updates the `selection` property of the post when changes are made to blocks.\n\t\t// In a multi-user setup, block changes can occur from other users. When an entity is updated from another\n\t\t// user's changes, useBlockSync() in Gutenberg will reset the user's selection to the last saved selection.\n\t\t//\n\t\t// Manually adding an edit for each movement ensures that other user's changes to the document will\n\t\t// not cause the local user's selection to reset to the last local change location.\n\t\tconst edits = {\n\t\t\tselection: { selectionStart, selectionEnd, initialPosition },\n\t\t};\n\n\t\tconst options = {\n\t\t\tundoIgnore: true,\n\t\t};\n\n\t\t// @ts-ignore Types are not provided when using store name instead of store instance.\n\t\tdispatch( coreStore ).editEntityRecord(\n\t\t\tthis.kind,\n\t\t\tthis.name,\n\t\t\tthis.postId,\n\t\t\tedits,\n\t\t\toptions\n\t\t);\n\t}\n\n\t/**\n\t * Check if two editor states are equal.\n\t *\n\t * @param state1 - The first editor state.\n\t * @param state2 - The second editor state.\n\t * @return True if the editor states are equal, false otherwise.\n\t */\n\tprivate areEditorStatesEqual(\n\t\tstate1?: EditorState,\n\t\tstate2?: EditorState\n\t): boolean {\n\t\tif ( ! state1 || ! state2 ) {\n\t\t\treturn state1 === state2;\n\t\t}\n\n\t\tif ( ! state1.selection || ! state2.selection ) {\n\t\t\treturn state1.selection === state2.selection;\n\t\t}\n\n\t\treturn areSelectionsStatesEqual( state1.selection, state2.selection );\n\t}\n\n\t/**\n\t * Resolve a selection state to a text index and block client ID.\n\t *\n\t * For text-based selections, navigates up from the resolved Y.Text via\n\t * AbstractType.parent to find the containing block, then resolves the\n\t * local clientId via the block's tree path.\n\t * For WholeBlock selections, resolves the block's relative position and\n\t * then finds the local clientId via tree path.\n\t *\n\t * Tree-path resolution is used instead of reading the clientId directly\n\t * from the Yjs block because the local block-editor store may use different\n\t * clientIds (e.g. in \"Show Template\" mode where blocks are cloned).\n\t *\n\t * @param selection - The selection state.\n\t * @return The rich-text offset and block client ID, or nulls if not resolvable.\n\t */\n\tpublic convertSelectionStateToAbsolute( selection: SelectionState ): {\n\t\trichTextOffset: number | null;\n\t\tlocalClientId: string | null;\n\t} {\n\t\tif ( selection.type === SelectionType.None ) {\n\t\t\treturn { richTextOffset: null, localClientId: null };\n\t\t}\n\n\t\tif ( selection.type === SelectionType.WholeBlock ) {\n\t\t\tconst absolutePos = Y.createAbsolutePositionFromRelativePosition(\n\t\t\t\tselection.blockPosition,\n\t\t\t\tthis.doc\n\t\t\t);\n\n\t\t\tlet localClientId: string | null = null;\n\n\t\t\tif ( absolutePos && absolutePos.type instanceof Y.Array ) {\n\t\t\t\tconst parentArray = absolutePos.type as YBlocks;\n\t\t\t\tconst block = parentArray.get( absolutePos.index );\n\n\t\t\t\tif ( block instanceof Y.Map ) {\n\t\t\t\t\tconst path = getBlockPathInYdoc( block );\n\t\t\t\t\tlocalClientId = path\n\t\t\t\t\t\t? resolveBlockClientIdByPath( path )\n\t\t\t\t\t\t: null;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { richTextOffset: null, localClientId };\n\t\t}\n\n\t\t// Text-based selections: resolve cursor position and navigate up.\n\t\tconst cursorPos =\n\t\t\t'cursorPosition' in selection\n\t\t\t\t? selection.cursorPosition\n\t\t\t\t: selection.cursorStartPosition;\n\n\t\tconst absolutePosition = Y.createAbsolutePositionFromRelativePosition(\n\t\t\tcursorPos.relativePosition,\n\t\t\tthis.doc\n\t\t);\n\n\t\tif ( ! absolutePosition ) {\n\t\t\treturn { richTextOffset: null, localClientId: null };\n\t\t}\n\n\t\t// Navigate up: Y.Text -> attributes Y.Map -> block Y.Map\n\t\tconst yType = absolutePosition.type.parent?.parent;\n\t\tconst path =\n\t\t\tyType instanceof Y.Map ? getBlockPathInYdoc( yType ) : null;\n\t\tconst localClientId = path ? resolveBlockClientIdByPath( path ) : null;\n\n\t\treturn {\n\t\t\trichTextOffset: htmlIndexToRichTextOffset(\n\t\t\t\tabsolutePosition.type.toString(),\n\t\t\t\tabsolutePosition.index\n\t\t\t),\n\t\t\tlocalClientId,\n\t\t};\n\t}\n\n\t/**\n\t * Type guard to check if a struct is a Y.Item (not Y.GC)\n\t * @param struct - The struct to check.\n\t * @return True if the struct is a Y.Item, false otherwise.\n\t */\n\tprivate isYItem( struct: Y.Item | Y.GC ): struct is Y.Item {\n\t\treturn 'content' in struct;\n\t}\n\n\t/**\n\t * Get data for debugging, using the awareness state.\n\t *\n\t * @return {YDocDebugData} The debug data.\n\t */\n\tpublic getDebugData(): YDocDebugData {\n\t\tconst ydoc = this.doc;\n\n\t\t// Manually extract doc data to avoid deprecated toJSON method\n\t\tconst docData: Record< string, unknown > = Object.fromEntries(\n\t\t\tArray.from( ydoc.share, ( [ key, value ] ) => [\n\t\t\t\tkey,\n\t\t\t\tvalue.toJSON(),\n\t\t\t] )\n\t\t);\n\n\t\t// Build collaboratorMap from awareness store (all collaborators seen this session)\n\t\tconst collaboratorMapData = new Map< string, DebugCollaboratorData >(\n\t\t\tArray.from( this.getSeenStates().entries() ).map(\n\t\t\t\t( [ clientId, collaboratorState ] ) => [\n\t\t\t\t\tString( clientId ),\n\t\t\t\t\t{\n\t\t\t\t\t\tname: collaboratorState.collaboratorInfo.name,\n\t\t\t\t\t\twpUserId: collaboratorState.collaboratorInfo.id,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t)\n\t\t);\n\n\t\t// Serialize Yjs client items to avoid deep nesting\n\t\tconst serializableClientItems: Record<\n\t\t\tnumber,\n\t\t\tArray< SerializableYItem >\n\t\t> = {};\n\n\t\tydoc.store.clients.forEach( ( structs, clientId ) => {\n\t\t\t// Filter for Y.Item only (skip Y.GC garbage collection structs)\n\t\t\tconst items = structs.filter( this.isYItem );\n\n\t\t\tserializableClientItems[ clientId ] = items.map( ( item ) => {\n\t\t\t\tconst { left, right, ...rest } = item;\n\n\t\t\t\treturn {\n\t\t\t\t\t...rest,\n\t\t\t\t\tleft: left\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tid: left.id,\n\t\t\t\t\t\t\t\tlength: left.length,\n\t\t\t\t\t\t\t\torigin: left.origin,\n\t\t\t\t\t\t\t\tcontent: left.content,\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: null,\n\t\t\t\t\tright: right\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tid: right.id,\n\t\t\t\t\t\t\t\tlength: right.length,\n\t\t\t\t\t\t\t\torigin: right.origin,\n\t\t\t\t\t\t\t\tcontent: right.content,\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: null,\n\t\t\t\t};\n\t\t\t} );\n\t\t} );\n\n\t\treturn {\n\t\t\tdoc: docData,\n\t\t\tclients: serializableClientItems,\n\t\t\tcollaboratorMap: Object.fromEntries( collaboratorMapData ),\n\t\t};\n\t}\n}\n\n/**\n * Detect the direction of a selection change by comparing old and new edges.\n *\n * When the user extends a selection backward (e.g. Shift+Left), the\n * selectionStart edge moves while selectionEnd stays fixed, so the caret\n * is at the start. The reverse is true for forward extension.\n *\n * @param prevStart - The previous selectionStart.\n * @param prevEnd - The previous selectionEnd.\n * @param newStart - The new selectionStart.\n * @param newEnd - The new selectionEnd.\n * @return The detected direction, defaulting to Forward when indeterminate.\n */\nfunction detectSelectionDirection(\n\tprevStart: WPBlockSelection,\n\tprevEnd: WPBlockSelection,\n\tnewStart: WPBlockSelection,\n\tnewEnd: WPBlockSelection\n): SelectionDirection {\n\tconst startMoved = ! areBlockSelectionsEqual( prevStart, newStart );\n\tconst endMoved = ! areBlockSelectionsEqual( prevEnd, newEnd );\n\n\tif ( startMoved && ! endMoved ) {\n\t\treturn SelectionDirection.Backward;\n\t}\n\n\treturn SelectionDirection.Forward;\n}\n\n/**\n * Compare two WPBlockSelection objects by value.\n *\n * @param a - First selection.\n * @param b - Second selection.\n * @return True if all fields are equal.\n */\nfunction areBlockSelectionsEqual(\n\ta: WPBlockSelection,\n\tb: WPBlockSelection\n): boolean {\n\treturn (\n\t\ta.clientId === b.clientId &&\n\t\ta.attributeKey === b.attributeKey &&\n\t\ta.offset === b.offset\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,UAAU,QAAQ,iBAAiB;AAC5C,SAAS,SAAS;AAElB,SAAS,SAAS,wBAAwB;AAK1C,SAAS,oBAAoB,+BAA+B;AAC5D,SAAS,oBAAoB,kCAAkC;AAC/D;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,cAAc,iBAAiB;AACxC,SAAS,iCAAiC;AAC1C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,SAAS,0BAA0B;AAW5B,IAAM,sBAAN,cAAkC,mBAAsC;AAAA,EAMvE,YACN,KACQ,MACA,MACA,QACP;AACD,UAAO,GAAI;AAJH;AACA;AACA;AAAA,EAGT;AAAA,EAZU,sBAAsB;AAAA,IAC/B,GAAG;AAAA,IACH,aAAa,KAAK;AAAA,EACnB;AAAA,EAWU,UAAgB;AACzB,UAAM,QAAQ;AAEd,SAAK,wCAAwC;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA,EAKQ,0CAAgD;AACvD,UAAM;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,I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J;AAAA,YACA,IAAI,MAAM;AAAA,YACV,QAAQ,MAAM;AAAA,YACd,QAAQ,MAAM;AAAA,YACd,SAAS,MAAM;AAAA,UACf,IACA;AAAA,QACJ;AAAA,MACD,CAAE;AAAA,IACH,CAAE;AAEF,WAAO;AAAA,MACN,KAAK;AAAA,MACL,SAAS;AAAA,MACT,iBAAiB,OAAO,YAAa,mBAAoB;AAAA,IAC1D;AAAA,EACD;AACD;AAeA,SAAS,yBACR,WACA,SACA,UACA,QACqB;AACrB,QAAM,aAAa,CAAE,wBAAyB,WAAW,QAAS;AAClE,QAAM,WAAW,CAAE,wBAAyB,SAAS,MAAO;AAE5D,MAAK,cAAc,CAAE,UAAW;AAC/B,WAAO,mBAAmB;AAAA,EAC3B;AAEA,SAAO,mBAAmB;AAC3B;AASA,SAAS,wBACR,GACA,GACU;AACV,SACC,EAAE,aAAa,EAAE,YACjB,EAAE,iBAAiB,EAAE,gBACrB,EAAE,WAAW,EAAE;AAEjB;",
|
|
6
6
|
"names": ["localClientId", "path"]
|
|
7
7
|
}
|
|
@@ -277,14 +277,35 @@ var prePersistPostType = async (persistedRecord, edits, name, isTemplate) => {
|
|
|
277
277
|
return newEdits;
|
|
278
278
|
};
|
|
279
279
|
async function loadPostTypeEntities() {
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
280
|
+
const postTypesPromise = apiFetch({ path: "/wp/v2/types?context=view" });
|
|
281
|
+
const taxonomiesPromise = window._wpCollaborationEnabled ? apiFetch({ path: "/wp/v2/taxonomies?context=view" }) : Promise.resolve({});
|
|
282
|
+
const [postTypes, taxonomies] = await Promise.all([
|
|
283
|
+
postTypesPromise,
|
|
284
|
+
taxonomiesPromise
|
|
285
|
+
]);
|
|
283
286
|
return Object.entries(postTypes ?? {}).map(([name, postType]) => {
|
|
284
287
|
const isTemplate = ["wp_template", "wp_template_part"].includes(
|
|
285
288
|
name
|
|
286
289
|
);
|
|
287
290
|
const namespace = postType?.rest_namespace ?? "wp/v2";
|
|
291
|
+
const syncedProperties = /* @__PURE__ */ new Set([
|
|
292
|
+
"author",
|
|
293
|
+
"blocks",
|
|
294
|
+
"content",
|
|
295
|
+
"comment_status",
|
|
296
|
+
"date",
|
|
297
|
+
"excerpt",
|
|
298
|
+
"featured_media",
|
|
299
|
+
"format",
|
|
300
|
+
"meta",
|
|
301
|
+
"ping_status",
|
|
302
|
+
"slug",
|
|
303
|
+
"status",
|
|
304
|
+
"sticky",
|
|
305
|
+
"template",
|
|
306
|
+
"title",
|
|
307
|
+
...postType.taxonomies?.map((taxonomy) => taxonomies?.[taxonomy]?.rest_base)?.filter(Boolean) ?? []
|
|
308
|
+
]);
|
|
288
309
|
const entity = {
|
|
289
310
|
kind: "postType",
|
|
290
311
|
baseURL: `/${namespace}/${postType.rest_base}`,
|
|
@@ -313,7 +334,7 @@ async function loadPostTypeEntities() {
|
|
|
313
334
|
* @param {Partial< import('@wordpress/sync').ObjectData >} changes
|
|
314
335
|
* @return {void}
|
|
315
336
|
*/
|
|
316
|
-
applyChangesToCRDTDoc: (crdtDoc, changes) => applyPostChangesToCRDTDoc(crdtDoc, changes,
|
|
337
|
+
applyChangesToCRDTDoc: (crdtDoc, changes) => applyPostChangesToCRDTDoc(crdtDoc, changes, syncedProperties),
|
|
317
338
|
/**
|
|
318
339
|
* Create the awareness instance for the entity's CRDT document.
|
|
319
340
|
*
|
|
@@ -334,7 +355,11 @@ async function loadPostTypeEntities() {
|
|
|
334
355
|
* @param {import('@wordpress/sync').ObjectData} editedRecord
|
|
335
356
|
* @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record
|
|
336
357
|
*/
|
|
337
|
-
getChangesFromCRDTDoc: (crdtDoc, editedRecord) => getPostChangesFromCRDTDoc(
|
|
358
|
+
getChangesFromCRDTDoc: (crdtDoc, editedRecord) => getPostChangesFromCRDTDoc(
|
|
359
|
+
crdtDoc,
|
|
360
|
+
editedRecord,
|
|
361
|
+
syncedProperties
|
|
362
|
+
),
|
|
338
363
|
/**
|
|
339
364
|
* Extract changes from a CRDT document that can be used to update the
|
|
340
365
|
* local editor state.
|
|
@@ -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 { PostEditorAwareness } from './awareness/post-editor-awareness';\nimport { getSyncManager } from './sync';\nimport {\n\tapplyPostChangesToCRDTDoc,\n\tdefaultSyncConfig,\n\tgetPostChangesFromCRDTDoc,\n\tPOST_META_KEY_FOR_CRDT_DOC_PERSISTENCE,\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-7.0/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'image_sizes',\n\t\t\t\t'image_size_threshold',\n\t\t\t\t'image_output_formats',\n\t\t\t\t'jpeg_interlaced',\n\t\t\t\t'png_interlaced',\n\t\t\t\t'gif_interlaced',\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\tsupportsPagination: true,\n\t},\n\t{\n\t\tlabel: __( 'Icons' ),\n\t\tname: 'icon',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/icons',\n\t\tbaseURLParams: { context: 'view' },\n\t\tplural: 'icons',\n\t\tkey: 'name',\n\t},\n].map( ( entity ) => {\n\tconst syncEnabledRootEntities = new Set( [ 'comment' ] );\n\n\tif ( syncEnabledRootEntities.has( entity.name ) ) {\n\t\tentity.syncConfig = defaultSyncConfig;\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 {Promise< Object >} Updated edits.\n */\nexport const prePersistPostType = async (\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 ( persistedRecord ) {\n\t\tconst objectType = `postType/${ name }`;\n\t\tconst objectId = persistedRecord.id;\n\t\tconst serializedDoc = await getSyncManager()?.createPersistedCRDTDoc(\n\t\t\tobjectType,\n\t\t\tobjectId\n\t\t);\n\n\t\tif ( serializedDoc ) {\n\t\t\tnewEdits.meta = {\n\t\t\t\t...edits.meta,\n\t\t\t\t[ POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE ]: serializedDoc,\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\t/**\n\t\t * @type {import('@wordpress/sync').SyncConfig}\n\t\t */\n\t\tentity.syncConfig = {\n\t\t\t/**\n\t\t\t * Apply changes from the local editor to the local CRDT document so\n\t\t\t * that those changes can be synced to other peers (via the provider).\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t * @param {Partial< import('@wordpress/sync').ObjectData >} changes\n\t\t\t * @return {void}\n\t\t\t */\n\t\t\tapplyChangesToCRDTDoc: ( crdtDoc, changes ) =>\n\t\t\t\tapplyPostChangesToCRDTDoc( crdtDoc, changes, postType ),\n\n\t\t\t/**\n\t\t\t * Create the awareness instance for the entity's CRDT document.\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').CRDTDoc} ydoc\n\t\t\t * @param {import('@wordpress/sync').ObjectID} objectId\n\t\t\t * @return {import('@wordpress/sync').Awareness} Awareness instance\n\t\t\t */\n\t\t\tcreateAwareness: ( ydoc, objectId ) => {\n\t\t\t\tconst kind = 'postType';\n\t\t\t\tconst id = parseInt( objectId, 10 );\n\t\t\t\treturn new PostEditorAwareness( ydoc, kind, name, id );\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Extract changes from a CRDT document that can be used to update the\n\t\t\t * local editor state.\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t * @param {import('@wordpress/sync').ObjectData} editedRecord\n\t\t\t * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record\n\t\t\t */\n\t\t\tgetChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>\n\t\t\t\tgetPostChangesFromCRDTDoc( crdtDoc, editedRecord, postType ),\n\n\t\t\t/**\n\t\t\t * Extract changes from a CRDT document that can be used to update the\n\t\t\t * local editor state.\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').ObjectData} record\n\t\t\t * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record\n\t\t\t */\n\t\t\tgetPersistedCRDTDoc: ( record ) => {\n\t\t\t\treturn (\n\t\t\t\t\trecord?.meta?.[ POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE ] ||\n\t\t\t\t\tnull\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\tentity.syncConfig = defaultSyncConfig;\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": ";AAGA,SAAS,aAAa,kBAAkB;AAKxC,OAAO,cAAc;AACrB,SAAS,6BAA6B,aAAa;AACnD,SAAS,UAAU;AAKnB,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEA,IAAM,qBAAqB;AAClC,IAAM,sBAAsB,CAAE,SAAS,WAAW,SAAU;AAE5D,IAAM,uBAAuB;AAAA,EAC5B,QAAQ;AAAA,IACP,MAAM,CAAE,WAAY,MAAO,OAAO,SAAS,OAAO,EAAG;AAAA,IACrD,OAAO,CAAE,YAAc;AAAA,MACtB,SAAS,4BAA6B,OAAO,MAAO;AAAA,IACrD;AAAA,EACD;AACD;AAEO,IAAM,qBAAqB;AAAA,EACjC;AAAA,IACC,OAAO,GAAI,MAAO;AAAA,IAClB,MAAM;AAAA,IACN,KAAK;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,eAAe;AAAA;AAAA;AAAA,MAGd,SAAS;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD,EAAE,KAAM,GAAI;AAAA,IACb;AAAA;AAAA;AAAA,IAGA,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,OAAO,GAAI,WAAY;AAAA,IACvB,MAAM;AAAA,IACN,MAAM;AAAA,IACN,KAAK;AAAA,IACL,SAAS;AAAA,IACT,eAAe,EAAE,SAAS,OAAO;AAAA,IACjC,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,M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N,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,cAAc;AAAA,EACf;AACD;AAWO,IAAM,qBAAqB,OACjC,iBACA,OACA,MACA,eACI;AACJ,QAAM,WAAW,CAAC;AAElB,MAAK,CAAE,cAAc,iBAAiB,WAAW,cAAe;AAE/D,QAAK,CAAE,MAAM,UAAU,CAAE,SAAS,QAAS;AAC1C,eAAS,SAAS;AAAA,IACnB;AAGA,SACG,CAAE,MAAM,SAAS,MAAM,UAAU,iBACnC,CAAE,SAAS,UACT,CAAE,iBAAiB,SACpB,iBAAiB,UAAU,eAC3B;AACD,eAAS,QAAQ;AAAA,IAClB;AAAA,EACD;AAGA,MAAK,iBAAkB;AACtB,UAAM,aAAa,YAAa,IAAK;AACrC,UAAM,WAAW,gBAAgB;AACjC,UAAM,gBAAgB,MAAM,eAAe,GAAG;AAAA,MAC7C;AAAA,MACA;AAAA,IACD;AAEA,QAAK,eAAgB;AACpB,eAAS,OAAO;AAAA,QACf,GAAG,MAAM;AAAA,QACT,CAAE,sCAAuC,GAAG;AAAA,MAC7C;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AACR;AAOA,eAAe,uBAAuB;AACrC,QAAM,
|
|
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\tPOST_META_KEY_FOR_CRDT_DOC_PERSISTENCE,\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-7.0/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'image_sizes',\n\t\t\t\t'image_size_threshold',\n\t\t\t\t'image_output_formats',\n\t\t\t\t'jpeg_interlaced',\n\t\t\t\t'png_interlaced',\n\t\t\t\t'gif_interlaced',\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\tsupportsPagination: true,\n\t},\n\t{\n\t\tlabel: __( 'Icons' ),\n\t\tname: 'icon',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/icons',\n\t\tbaseURLParams: { context: 'view' },\n\t\tplural: 'icons',\n\t\tkey: 'name',\n\t},\n].map( ( entity ) => {\n\tconst syncEnabledRootEntities = new Set( [ 'comment' ] );\n\n\tif ( syncEnabledRootEntities.has( entity.name ) ) {\n\t\tentity.syncConfig = defaultSyncConfig;\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 {Promise< Object >} Updated edits.\n */\nexport const prePersistPostType = async (\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 ( persistedRecord ) {\n\t\tconst objectType = `postType/${ name }`;\n\t\tconst objectId = persistedRecord.id;\n\t\tconst serializedDoc = await getSyncManager()?.createPersistedCRDTDoc(\n\t\t\tobjectType,\n\t\t\tobjectId\n\t\t);\n\n\t\tif ( serializedDoc ) {\n\t\t\tnewEdits.meta = {\n\t\t\t\t...edits.meta,\n\t\t\t\t[ POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE ]: serializedDoc,\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 postTypesPromise = apiFetch( { path: '/wp/v2/types?context=view' } );\n\tconst taxonomiesPromise = window._wpCollaborationEnabled\n\t\t? apiFetch( { path: '/wp/v2/taxonomies?context=view' } )\n\t\t: Promise.resolve( {} );\n\tconst [ postTypes, taxonomies ] = await Promise.all( [\n\t\tpostTypesPromise,\n\t\ttaxonomiesPromise,\n\t] );\n\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 syncedProperties = new Set( [\n\t\t\t'author',\n\t\t\t'blocks',\n\t\t\t'content',\n\t\t\t'comment_status',\n\t\t\t'date',\n\t\t\t'excerpt',\n\t\t\t'featured_media',\n\t\t\t'format',\n\t\t\t'meta',\n\t\t\t'ping_status',\n\t\t\t'slug',\n\t\t\t'status',\n\t\t\t'sticky',\n\t\t\t'template',\n\t\t\t'title',\n\t\t\t...( postType.taxonomies\n\t\t\t\t?.map( ( taxonomy ) => taxonomies?.[ taxonomy ]?.rest_base )\n\t\t\t\t?.filter( Boolean ) ?? [] ),\n\t\t] );\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\t/**\n\t\t * @type {import('@wordpress/sync').SyncConfig}\n\t\t */\n\t\tentity.syncConfig = {\n\t\t\t/**\n\t\t\t * Apply changes from the local editor to the local CRDT document so\n\t\t\t * that those changes can be synced to other peers (via the provider).\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t * @param {Partial< import('@wordpress/sync').ObjectData >} changes\n\t\t\t * @return {void}\n\t\t\t */\n\t\t\tapplyChangesToCRDTDoc: ( crdtDoc, changes ) =>\n\t\t\t\tapplyPostChangesToCRDTDoc( crdtDoc, changes, syncedProperties ),\n\n\t\t\t/**\n\t\t\t * Create the awareness instance for the entity's CRDT document.\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').CRDTDoc} ydoc\n\t\t\t * @param {import('@wordpress/sync').ObjectID} objectId\n\t\t\t * @return {import('@wordpress/sync').Awareness} Awareness instance\n\t\t\t */\n\t\t\tcreateAwareness: ( ydoc, objectId ) => {\n\t\t\t\tconst kind = 'postType';\n\t\t\t\tconst id = parseInt( objectId, 10 );\n\t\t\t\treturn new PostEditorAwareness( ydoc, kind, name, id );\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Extract changes from a CRDT document that can be used to update the\n\t\t\t * local editor state.\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t * @param {import('@wordpress/sync').ObjectData} editedRecord\n\t\t\t * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record\n\t\t\t */\n\t\t\tgetChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>\n\t\t\t\tgetPostChangesFromCRDTDoc(\n\t\t\t\t\tcrdtDoc,\n\t\t\t\t\teditedRecord,\n\t\t\t\t\tsyncedProperties\n\t\t\t\t),\n\n\t\t\t/**\n\t\t\t * Extract changes from a CRDT document that can be used to update the\n\t\t\t * local editor state.\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').ObjectData} record\n\t\t\t * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record\n\t\t\t */\n\t\t\tgetPersistedCRDTDoc: ( record ) => {\n\t\t\t\treturn (\n\t\t\t\t\trecord?.meta?.[ POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE ] ||\n\t\t\t\t\tnull\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\tentity.syncConfig = defaultSyncConfig;\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\tcon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,EACD;AAEA,SAAO,CAAE,EAAE,GAAG,QAAQ,MAAM,EAAE,OAAO,EAAE,CAAE;AAC1C;AAoBO,IAAM,gBAAgB,CAAE,MAAM,MAAM,SAAS,UAAW;AAC9D,QAAM,aAAa,SAAS,SAAS,KAAK,WAAY,IAAK;AAC3D,QAAM,SAAS,WAAY,IAAK;AAChC,SAAO,GAAI,MAAO,GAAI,UAAW,GAAI,MAAO;AAC7C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,7 +3,7 @@ import { usePrevious } from "@wordpress/compose";
|
|
|
3
3
|
import { useEffect, useState } from "@wordpress/element";
|
|
4
4
|
import { getSyncManager } from "../sync.mjs";
|
|
5
5
|
var defaultResolvedSelection = {
|
|
6
|
-
|
|
6
|
+
richTextOffset: null,
|
|
7
7
|
localClientId: null
|
|
8
8
|
};
|
|
9
9
|
var defaultState = {
|