@wordpress/core-data 7.38.1-next.v.0 → 7.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/actions.cjs +17 -6
- package/build/actions.cjs.map +2 -2
- package/build/awareness/base-awareness.cjs +62 -0
- package/build/awareness/base-awareness.cjs.map +7 -0
- package/build/awareness/post-editor-awareness.cjs +4 -18
- package/build/awareness/post-editor-awareness.cjs.map +3 -3
- package/build/entities.cjs +14 -2
- package/build/entities.cjs.map +2 -2
- package/build/resolvers.cjs +40 -0
- package/build/resolvers.cjs.map +2 -2
- package/build/types.cjs.map +1 -1
- package/build/utils/block-selection-history.cjs +101 -0
- package/build/utils/block-selection-history.cjs.map +7 -0
- package/build/utils/crdt-selection.cjs +139 -0
- package/build/utils/crdt-selection.cjs.map +7 -0
- package/build/utils/crdt-user-selections.cjs +2 -2
- package/build/utils/crdt-user-selections.cjs.map +2 -2
- package/build/utils/crdt-utils.cjs +29 -0
- package/build/utils/crdt-utils.cjs.map +3 -3
- package/build/utils/crdt.cjs +16 -4
- package/build/utils/crdt.cjs.map +2 -2
- package/build-module/actions.mjs +17 -6
- package/build-module/actions.mjs.map +2 -2
- package/build-module/awareness/base-awareness.mjs +35 -0
- package/build-module/awareness/base-awareness.mjs.map +7 -0
- package/build-module/awareness/post-editor-awareness.mjs +4 -18
- package/build-module/awareness/post-editor-awareness.mjs.map +2 -2
- package/build-module/entities.mjs +15 -2
- package/build-module/entities.mjs.map +2 -2
- package/build-module/resolvers.mjs +40 -0
- package/build-module/resolvers.mjs.map +2 -2
- package/build-module/utils/block-selection-history.mjs +75 -0
- package/build-module/utils/block-selection-history.mjs.map +7 -0
- package/build-module/utils/crdt-selection.mjs +115 -0
- package/build-module/utils/crdt-selection.mjs.map +7 -0
- package/build-module/utils/crdt-user-selections.mjs +2 -2
- package/build-module/utils/crdt-user-selections.mjs.map +2 -2
- package/build-module/utils/crdt-utils.mjs +28 -0
- package/build-module/utils/crdt-utils.mjs.map +2 -2
- package/build-module/utils/crdt.mjs +18 -3
- package/build-module/utils/crdt.mjs.map +2 -2
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/awareness/base-awareness.d.ts +19 -0
- package/build-types/awareness/base-awareness.d.ts.map +1 -0
- package/build-types/awareness/post-editor-awareness.d.ts +7 -8
- package/build-types/awareness/post-editor-awareness.d.ts.map +1 -1
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/entity-types/test/attachment.test.d.ts +10 -0
- package/build-types/entity-types/test/attachment.test.d.ts.map +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/resolvers.d.ts.map +1 -1
- package/build-types/types.d.ts +12 -2
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils/block-selection-history.d.ts +47 -0
- package/build-types/utils/block-selection-history.d.ts.map +1 -0
- package/build-types/utils/crdt-selection.d.ts +16 -0
- package/build-types/utils/crdt-selection.d.ts.map +1 -0
- package/build-types/utils/crdt-user-selections.d.ts.map +1 -1
- package/build-types/utils/crdt-utils.d.ts +12 -0
- package/build-types/utils/crdt-utils.d.ts.map +1 -1
- package/build-types/utils/crdt.d.ts +8 -14
- package/build-types/utils/crdt.d.ts.map +1 -1
- package/build-types/utils/test/block-selection-history.test.d.ts +2 -0
- package/build-types/utils/test/block-selection-history.test.d.ts.map +1 -0
- package/build-types/utils/test/crdt-blocks.d.ts +2 -0
- package/build-types/utils/test/crdt-blocks.d.ts.map +1 -0
- package/build-types/utils/test/crdt.d.ts +2 -0
- package/build-types/utils/test/crdt.d.ts.map +1 -0
- package/package.json +21 -19
- package/src/actions.js +40 -7
- package/src/awareness/base-awareness.ts +50 -0
- package/src/awareness/post-editor-awareness.ts +4 -24
- package/src/entities.js +18 -2
- package/src/entity-types/test/attachment.test.ts +4 -4
- package/src/resolvers.js +51 -0
- package/src/test/actions.js +402 -0
- package/src/test/resolvers.js +4 -0
- package/src/types.ts +12 -3
- package/src/utils/block-selection-history.ts +176 -0
- package/src/utils/crdt-selection.ts +205 -0
- package/src/utils/crdt-user-selections.ts +7 -3
- package/src/utils/crdt-utils.ts +54 -0
- package/src/utils/crdt.ts +36 -3
- package/src/utils/test/block-selection-history.test.ts +764 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// packages/core-data/src/awareness/base-awareness.ts
|
|
2
|
+
import { select } from "@wordpress/data";
|
|
3
|
+
import { AwarenessState } from "@wordpress/sync";
|
|
4
|
+
import { STORE_NAME as coreStore } from "../name.mjs";
|
|
5
|
+
import { generateUserInfo, areUserInfosEqual } from "./utils.mjs";
|
|
6
|
+
var BaseAwarenessState = class extends AwarenessState {
|
|
7
|
+
setUp() {
|
|
8
|
+
super.setUp();
|
|
9
|
+
this.setCurrentUserInfo();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Set the current user info in the local state.
|
|
13
|
+
*/
|
|
14
|
+
setCurrentUserInfo() {
|
|
15
|
+
const states = this.getStates();
|
|
16
|
+
const otherUserColors = Array.from(states.entries()).filter(
|
|
17
|
+
([clientId, state]) => state.userInfo && clientId !== this.clientID
|
|
18
|
+
).map(([, state]) => state.userInfo.color).filter(Boolean);
|
|
19
|
+
const currentUser = select(coreStore).getCurrentUser();
|
|
20
|
+
const userInfo = generateUserInfo(currentUser, otherUserColors);
|
|
21
|
+
this.setLocalStateField("userInfo", userInfo);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var baseEqualityFieldChecks = {
|
|
25
|
+
userInfo: areUserInfosEqual
|
|
26
|
+
};
|
|
27
|
+
var BaseAwareness = class extends BaseAwarenessState {
|
|
28
|
+
equalityFieldChecks = baseEqualityFieldChecks;
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
BaseAwareness,
|
|
32
|
+
BaseAwarenessState,
|
|
33
|
+
baseEqualityFieldChecks
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=base-awareness.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/awareness/base-awareness.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { select } from '@wordpress/data';\nimport { AwarenessState } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME as coreStore } from '../name';\nimport { generateUserInfo, areUserInfosEqual } from './utils';\n\nimport type { BaseState } from './types';\n\nexport abstract class BaseAwarenessState<\n\tState extends BaseState,\n> extends AwarenessState< State > {\n\tpublic setUp(): void {\n\t\tsuper.setUp();\n\n\t\tthis.setCurrentUserInfo();\n\t}\n\n\t/**\n\t * Set the current user info in the local state.\n\t */\n\tprivate setCurrentUserInfo(): void {\n\t\tconst states = this.getStates();\n\t\tconst otherUserColors = Array.from( states.entries() )\n\t\t\t.filter(\n\t\t\t\t( [ clientId, state ] ) =>\n\t\t\t\t\tstate.userInfo && clientId !== this.clientID\n\t\t\t)\n\t\t\t.map( ( [ , state ] ) => state.userInfo.color )\n\t\t\t.filter( Boolean );\n\n\t\t// Get current user info and set it in local state.\n\t\tconst currentUser = select( coreStore ).getCurrentUser();\n\t\tconst userInfo = generateUserInfo( currentUser, otherUserColors );\n\t\tthis.setLocalStateField( 'userInfo', userInfo );\n\t}\n}\n\nexport const baseEqualityFieldChecks = {\n\tuserInfo: areUserInfosEqual,\n};\n\nexport class BaseAwareness extends BaseAwarenessState< BaseState > {\n\tprotected equalityFieldChecks = baseEqualityFieldChecks;\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,cAAc;AACvB,SAAS,sBAAsB;AAK/B,SAAS,cAAc,iBAAiB;AACxC,SAAS,kBAAkB,yBAAyB;AAI7C,IAAe,qBAAf,cAEG,eAAwB;AAAA,EAC1B,QAAc;AACpB,UAAM,MAAM;AAEZ,SAAK,mBAAmB;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKQ,qBAA2B;AAClC,UAAM,SAAS,KAAK,UAAU;AAC9B,UAAM,kBAAkB,MAAM,KAAM,OAAO,QAAQ,CAAE,EACnD;AAAA,MACA,CAAE,CAAE,UAAU,KAAM,MACnB,MAAM,YAAY,aAAa,KAAK;AAAA,IACtC,EACC,IAAK,CAAE,CAAE,EAAE,KAAM,MAAO,MAAM,SAAS,KAAM,EAC7C,OAAQ,OAAQ;AAGlB,UAAM,cAAc,OAAQ,SAAU,EAAE,eAAe;AACvD,UAAM,WAAW,iBAAkB,aAAa,eAAgB;AAChE,SAAK,mBAAoB,YAAY,QAAS;AAAA,EAC/C;AACD;AAEO,IAAM,0BAA0B;AAAA,EACtC,UAAU;AACX;AAEO,IAAM,gBAAN,cAA4B,mBAAgC;AAAA,EACxD,sBAAsB;AACjC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
// packages/core-data/src/awareness/post-editor-awareness.ts
|
|
2
2
|
import { dispatch, select, subscribe } from "@wordpress/data";
|
|
3
|
-
import { AwarenessState } from "@wordpress/sync";
|
|
4
3
|
import { store as blockEditorStore } from "@wordpress/block-editor";
|
|
4
|
+
import { BaseAwarenessState, baseEqualityFieldChecks } from "./base-awareness.mjs";
|
|
5
5
|
import {
|
|
6
6
|
AWARENESS_CURSOR_UPDATE_THROTTLE_IN_MS,
|
|
7
7
|
LOCAL_CURSOR_UPDATE_DEBOUNCE_IN_MS
|
|
8
8
|
} from "./config.mjs";
|
|
9
9
|
import { STORE_NAME as coreStore } from "../name.mjs";
|
|
10
|
-
import { generateUserInfo, areUserInfosEqual } from "./utils.mjs";
|
|
11
10
|
import {
|
|
12
11
|
areSelectionsStatesEqual,
|
|
13
12
|
getSelectionState
|
|
14
13
|
} from "../utils/crdt-user-selections.mjs";
|
|
15
|
-
var PostEditorAwareness = class extends
|
|
14
|
+
var PostEditorAwareness = class extends BaseAwarenessState {
|
|
16
15
|
constructor(doc, kind, name, postId) {
|
|
17
16
|
super(doc);
|
|
18
17
|
this.kind = kind;
|
|
@@ -20,26 +19,13 @@ var PostEditorAwareness = class extends AwarenessState {
|
|
|
20
19
|
this.postId = postId;
|
|
21
20
|
}
|
|
22
21
|
equalityFieldChecks = {
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
...baseEqualityFieldChecks,
|
|
23
|
+
editorState: this.areEditorStatesEqual
|
|
25
24
|
};
|
|
26
25
|
setUp() {
|
|
27
26
|
super.setUp();
|
|
28
|
-
this.setCurrentUserInfo();
|
|
29
27
|
this.subscribeToUserSelectionChanges();
|
|
30
28
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Set the current user info in the local state.
|
|
33
|
-
*/
|
|
34
|
-
setCurrentUserInfo() {
|
|
35
|
-
const states = this.getStates();
|
|
36
|
-
const otherUserColors = Array.from(states.entries()).filter(
|
|
37
|
-
([clientId, state]) => state.userInfo && clientId !== this.clientID
|
|
38
|
-
).map(([, state]) => state.userInfo.color).filter(Boolean);
|
|
39
|
-
const currentUser = select(coreStore).getCurrentUser();
|
|
40
|
-
const userInfo = generateUserInfo(currentUser, otherUserColors);
|
|
41
|
-
this.setLocalStateField("userInfo", userInfo);
|
|
42
|
-
}
|
|
43
29
|
/**
|
|
44
30
|
* Subscribe to user selection changes and update the selection state.
|
|
45
31
|
*/
|
|
@@ -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 {
|
|
5
|
-
"mappings": ";AAGA,SAAS,UAAU,QAAQ,iBAAiB;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { dispatch, select, subscribe } from '@wordpress/data';\nimport type { 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 {\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} from '../utils/crdt-user-selections';\n\nimport type { WPBlockSelection } from '../types';\nimport type { EditorState, PostEditorState } 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\tpublic setUp(): void {\n\t\tsuper.setUp();\n\n\t\tthis.subscribeToUserSelectionChanges();\n\t}\n\n\t/**\n\t * Subscribe to user selection changes and update the selection state.\n\t */\n\tprivate subscribeToUserSelectionChanges(): 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\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\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\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);\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 user'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\treturn areSelectionsStatesEqual( state1.selection, state2.selection );\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,UAAU,QAAQ,iBAAiB;AAG5C,SAAS,SAAS,wBAAwB;AAK1C,SAAS,oBAAoB,+BAA+B;AAC5D;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,cAAc,iBAAiB;AACxC;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAKA,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,EAWO,QAAc;AACpB,UAAM,MAAM;AAEZ,SAAK,gCAAgC;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA,EAKQ,kCAAwC;AAC/C,UAAM;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACD,IAAI,OAAQ,gBAAiB;AAI7B,QAAI,iBAAiB,kBAAkB;AACvC,QAAI,eAAe,gBAAgB;AACnC,QAAI,qBAA4C;AAEhD,cAAW,MAAM;AAChB,YAAM,oBAAoB,kBAAkB;AAC5C,YAAM,kBAAkB,gBAAgB;AAExC,UACC,sBAAsB,kBACtB,oBAAoB,cACnB;AACD;AAAA,MACD;AAEA,uBAAiB;AACjB,qBAAe;AAKf,YAAM,kBAAkB,sCAAsC;AAC9D,WAAK,KAAK;AAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAOA,UAAK,oBAAqB;AACzB,qBAAc,kBAAmB;AAAA,MAClC;AAEA,2BAAqB,WAAY,MAAM;AACtC,cAAM,iBAAiB;AAAA,UACtB;AAAA,UACA;AAAA,UACA,KAAK;AAAA,QACN;AAEA,aAAK;AAAA,UACJ;AAAA,UACA,EAAE,WAAW,eAAe;AAAA,UAC5B;AAAA,QACD;AAAA,MACD,GAAG,kCAAmC;AAAA,IACvC,CAAE;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAc,8BACb,gBACA,cACA,iBACkB;AASlB,UAAM,QAAQ;AAAA,MACb,WAAW,EAAE,gBAAgB,cAAc,gBAAgB;AAAA,IAC5D;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,WAAO,yBAA0B,OAAO,WAAW,OAAO,SAAU;AAAA,EACrE;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,6 +7,7 @@ import { PostEditorAwareness } from "./awareness/post-editor-awareness.mjs";
|
|
|
7
7
|
import { getSyncManager } from "./sync.mjs";
|
|
8
8
|
import {
|
|
9
9
|
applyPostChangesToCRDTDoc,
|
|
10
|
+
defaultSyncConfig,
|
|
10
11
|
getPostChangesFromCRDTDoc
|
|
11
12
|
} from "./utils/crdt.mjs";
|
|
12
13
|
var DEFAULT_ENTITY_KEY = "id";
|
|
@@ -204,7 +205,15 @@ var rootEntitiesConfig = [
|
|
|
204
205
|
plural: "fontCollections",
|
|
205
206
|
key: "slug"
|
|
206
207
|
}
|
|
207
|
-
]
|
|
208
|
+
].map((entity) => {
|
|
209
|
+
const syncEnabledRootEntities = /* @__PURE__ */ new Set(["comment"]);
|
|
210
|
+
if (globalThis.IS_GUTENBERG_PLUGIN) {
|
|
211
|
+
if (syncEnabledRootEntities.has(entity.name)) {
|
|
212
|
+
entity.syncConfig = defaultSyncConfig;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return entity;
|
|
216
|
+
});
|
|
208
217
|
var deprecatedEntities = {
|
|
209
218
|
root: {
|
|
210
219
|
media: {
|
|
@@ -332,7 +341,7 @@ async function loadTaxonomyEntities() {
|
|
|
332
341
|
});
|
|
333
342
|
return Object.entries(taxonomies ?? {}).map(([name, taxonomy]) => {
|
|
334
343
|
const namespace = taxonomy?.rest_namespace ?? "wp/v2";
|
|
335
|
-
|
|
344
|
+
const entity = {
|
|
336
345
|
kind: "taxonomy",
|
|
337
346
|
baseURL: `/${namespace}/${taxonomy.rest_base}`,
|
|
338
347
|
baseURLParams: { context: "edit" },
|
|
@@ -341,6 +350,10 @@ async function loadTaxonomyEntities() {
|
|
|
341
350
|
getTitle: (record) => record?.name,
|
|
342
351
|
supportsPagination: true
|
|
343
352
|
};
|
|
353
|
+
if (globalThis.IS_GUTENBERG_PLUGIN) {
|
|
354
|
+
entity.syncConfig = defaultSyncConfig;
|
|
355
|
+
}
|
|
356
|
+
return entity;
|
|
344
357
|
});
|
|
345
358
|
}
|
|
346
359
|
async function loadSiteEntity() {
|
|
@@ -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\tgetPostChangesFromCRDTDoc,\n} from './utils/crdt';\n\nexport const DEFAULT_ENTITY_KEY = 'id';\nconst POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];\n\nconst blocksTransientEdits = {\n\tblocks: {\n\t\tread: ( record ) => parse( record.content?.raw ?? '' ),\n\t\twrite: ( record ) => ( {\n\t\t\tcontent: __unstableSerializeAndClean( record.blocks ),\n\t\t} ),\n\t},\n};\n\nexport const rootEntitiesConfig = [\n\t{\n\t\tlabel: __( 'Base' ),\n\t\tkind: 'root',\n\t\tkey: false,\n\t\tname: '__unstableBase',\n\t\tbaseURL: '/',\n\t\tbaseURLParams: {\n\t\t\t// Please also change the preload path when changing this.\n\t\t\t// @see lib/compat/wordpress-6.8/preload.php\n\t\t\t_fields: [\n\t\t\t\t'description',\n\t\t\t\t'gmt_offset',\n\t\t\t\t'home',\n\t\t\t\t'name',\n\t\t\t\t'site_icon',\n\t\t\t\t'site_icon_url',\n\t\t\t\t'site_logo',\n\t\t\t\t'timezone_string',\n\t\t\t\t'url',\n\t\t\t\t'page_for_posts',\n\t\t\t\t'page_on_front',\n\t\t\t\t'show_on_front',\n\t\t\t].join( ',' ),\n\t\t},\n\t\t// The entity doesn't support selecting multiple records.\n\t\t// The property is maintained for backward compatibility.\n\t\tplural: '__unstableBases',\n\t},\n\t{\n\t\tlabel: __( 'Post Type' ),\n\t\tname: 'postType',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'postTypes',\n\t},\n\t{\n\t\tname: 'media',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/media',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'mediaItems',\n\t\tlabel: __( 'Media' ),\n\t\trawAttributes: [ 'caption', 'title', 'description' ],\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'taxonomy',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/taxonomies',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'taxonomies',\n\t\tlabel: __( 'Taxonomy' ),\n\t},\n\t{\n\t\tname: 'sidebar',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/sidebars',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'sidebars',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widget areas' ),\n\t},\n\t{\n\t\tname: 'widget',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widgets',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgets',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widgets' ),\n\t},\n\t{\n\t\tname: 'widgetType',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widget-types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgetTypes',\n\t\tlabel: __( 'Widget types' ),\n\t},\n\t{\n\t\tlabel: __( 'User' ),\n\t\tname: 'user',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/users',\n\t\tgetTitle: ( record ) => record?.name || record?.slug,\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'users',\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'comment',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/comments',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'comments',\n\t\tlabel: __( 'Comment' ),\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menu',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menus',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menus',\n\t\tlabel: __( 'Menu' ),\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menuItem',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-items',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuItems',\n\t\tlabel: __( 'Menu Item' ),\n\t\trawAttributes: [ 'title' ],\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menuLocation',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-locations',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuLocations',\n\t\tlabel: __( 'Menu Location' ),\n\t\tkey: 'name',\n\t},\n\t{\n\t\tlabel: __( 'Global Styles' ),\n\t\tname: 'globalStyles',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/global-styles',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'globalStylesVariations', // Should be different from name.\n\t\tgetTitle: () => __( 'Custom Styles' ),\n\t\tgetRevisionsUrl: ( parentId, revisionId ) =>\n\t\t\t`/wp/v2/global-styles/${ parentId }/revisions${\n\t\t\t\trevisionId ? '/' + revisionId : ''\n\t\t\t}`,\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tlabel: __( 'Themes' ),\n\t\tname: 'theme',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/themes',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'themes',\n\t\tkey: 'stylesheet',\n\t},\n\t{\n\t\tlabel: __( 'Plugins' ),\n\t\tname: 'plugin',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/plugins',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'plugins',\n\t\tkey: 'plugin',\n\t},\n\t{\n\t\tlabel: __( 'Status' ),\n\t\tname: 'status',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/statuses',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'statuses',\n\t\tkey: 'slug',\n\t},\n\t{\n\t\tlabel: __( 'Registered Templates' ),\n\t\tname: 'registeredTemplate',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/registered-templates',\n\t\tkey: 'id',\n\t},\n\t{\n\t\tlabel: __( 'Font Collections' ),\n\t\tname: 'fontCollection',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/font-collections',\n\t\tbaseURLParams: { context: 'view' },\n\t\tplural: 'fontCollections',\n\t\tkey: 'slug',\n\t},\n];\n\nexport const deprecatedEntities = {\n\troot: {\n\t\tmedia: {\n\t\t\tsince: '6.9',\n\t\t\talternative: {\n\t\t\t\tkind: 'postType',\n\t\t\t\tname: 'attachment',\n\t\t\t},\n\t\t},\n\t},\n};\n\nexport const additionalEntityConfigLoaders = [\n\t{ kind: 'postType', loadEntities: loadPostTypeEntities },\n\t{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },\n\t{\n\t\tkind: 'root',\n\t\tname: 'site',\n\t\tplural: 'sites',\n\t\tloadEntities: loadSiteEntity,\n\t},\n];\n\n/**\n * Apply extra edits before persisting a post type.\n *\n * @param {Object} persistedRecord Already persisted Post\n * @param {Object} edits Edits.\n * @param {string} name Post type name.\n * @param {boolean} isTemplate Whether the post type is a template.\n * @return {Object} Updated edits.\n */\nexport const prePersistPostType = (\n\tpersistedRecord,\n\tedits,\n\tname,\n\tisTemplate\n) => {\n\tconst newEdits = {};\n\n\tif ( ! isTemplate && persistedRecord?.status === 'auto-draft' ) {\n\t\t// Saving an auto-draft should create a draft by default.\n\t\tif ( ! edits.status && ! newEdits.status ) {\n\t\t\tnewEdits.status = 'draft';\n\t\t}\n\n\t\t// Fix the auto-draft default title.\n\t\tif (\n\t\t\t( ! edits.title || edits.title === 'Auto Draft' ) &&\n\t\t\t! newEdits.title &&\n\t\t\t( ! persistedRecord?.title ||\n\t\t\t\tpersistedRecord?.title === 'Auto Draft' )\n\t\t) {\n\t\t\tnewEdits.title = '';\n\t\t}\n\t}\n\n\t// Add meta for persisted CRDT document.\n\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\tif ( persistedRecord ) {\n\t\t\tconst objectType = `postType/${ name }`;\n\t\t\tconst objectId = persistedRecord.id;\n\t\t\tconst meta = getSyncManager()?.createMeta( objectType, objectId );\n\t\t\tnewEdits.meta = {\n\t\t\t\t...edits.meta,\n\t\t\t\t...meta,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn newEdits;\n};\n\n/**\n * Returns the list of post type entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadPostTypeEntities() {\n\tconst postTypes = await apiFetch( {\n\t\tpath: '/wp/v2/types?context=view',\n\t} );\n\treturn Object.entries( postTypes ?? {} ).map( ( [ name, postType ] ) => {\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tname\n\t\t);\n\t\tconst namespace = postType?.rest_namespace ?? 'wp/v2';\n\n\t\tconst entity = {\n\t\t\tkind: 'postType',\n\t\t\tbaseURL: `/${ namespace }/${ postType.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: postType.name,\n\t\t\ttransientEdits: {\n\t\t\t\t...blocksTransientEdits,\n\t\t\t\tselection: true,\n\t\t\t},\n\t\t\tmergedEdits: { meta: true },\n\t\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t\t\tgetTitle: ( record ) =>\n\t\t\t\trecord?.title?.rendered ||\n\t\t\t\trecord?.title ||\n\t\t\t\t( isTemplate\n\t\t\t\t\t? capitalCase( record.slug ?? '' )\n\t\t\t\t\t: String( record.id ) ),\n\t\t\t__unstablePrePersist: ( persistedRecord, edits ) =>\n\t\t\t\tprePersistPostType( persistedRecord, edits, name, isTemplate ),\n\t\t\t__unstable_rest_base: postType.rest_base,\n\t\t\tsupportsPagination: true,\n\t\t\tgetRevisionsUrl: ( parentId, revisionId ) =>\n\t\t\t\t`/${ namespace }/${\n\t\t\t\t\tpostType.rest_base\n\t\t\t\t}/${ parentId }/revisions${\n\t\t\t\t\trevisionId ? '/' + revisionId : ''\n\t\t\t\t}`,\n\t\t\trevisionKey:\n\t\t\t\tisTemplate && ! window?.__experimentalTemplateActivate\n\t\t\t\t\t? 'wp_id'\n\t\t\t\t\t: DEFAULT_ENTITY_KEY,\n\t\t};\n\n\t\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\t\t/**\n\t\t\t * @type {import('@wordpress/sync').SyncConfig}\n\t\t\t */\n\t\t\tentity.syncConfig = {\n\t\t\t\t/**\n\t\t\t\t * Apply changes from the local editor to the local CRDT document so\n\t\t\t\t * that those changes can be synced to other peers (via the provider).\n\t\t\t\t *\n\t\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t\t * @param {Partial< import('@wordpress/sync').ObjectData >} changes\n\t\t\t\t * @return {void}\n\t\t\t\t */\n\t\t\t\tapplyChangesToCRDTDoc: ( crdtDoc, changes ) =>\n\t\t\t\t\tapplyPostChangesToCRDTDoc( crdtDoc, changes, postType ),\n\n\t\t\t\t/**\n\t\t\t\t * Create the awareness instance for the entity's CRDT document.\n\t\t\t\t *\n\t\t\t\t * @param {import('@wordpress/sync').CRDTDoc} ydoc\n\t\t\t\t * @param {import('@wordpress/sync').ObjectID} objectId\n\t\t\t\t * @return {import('@wordpress/sync').AwarenessState} AwarenessState instance\n\t\t\t\t */\n\t\t\t\tcreateAwareness: ( ydoc, objectId ) => {\n\t\t\t\t\tconst kind = 'postType';\n\t\t\t\t\tconst id = parseInt( objectId, 10 );\n\t\t\t\t\treturn new PostEditorAwareness( ydoc, kind, name, id );\n\t\t\t\t},\n\n\t\t\t\t/**\n\t\t\t\t * Extract changes from a CRDT document that can be used to update the\n\t\t\t\t * local editor state.\n\t\t\t\t *\n\t\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t\t * @param {import('@wordpress/sync').ObjectData} editedRecord\n\t\t\t\t * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record\n\t\t\t\t */\n\t\t\t\tgetChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>\n\t\t\t\t\tgetPostChangesFromCRDTDoc(\n\t\t\t\t\t\tcrdtDoc,\n\t\t\t\t\t\teditedRecord,\n\t\t\t\t\t\tpostType\n\t\t\t\t\t),\n\n\t\t\t\t/**\n\t\t\t\t * Sync features supported by the entity.\n\t\t\t\t *\n\t\t\t\t * @type {Record< string, boolean >}\n\t\t\t\t */\n\t\t\t\tsupports: {\n\t\t\t\t\tcrdtPersistence: true,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn entity;\n\t} );\n}\n\n/**\n * Returns the list of the taxonomies entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadTaxonomyEntities() {\n\tconst taxonomies = await apiFetch( {\n\t\tpath: '/wp/v2/taxonomies?context=view',\n\t} );\n\treturn Object.entries( taxonomies ?? {} ).map( ( [ name, taxonomy ] ) => {\n\t\tconst namespace = taxonomy?.rest_namespace ?? 'wp/v2';\n\t\treturn {\n\t\t\tkind: 'taxonomy',\n\t\t\tbaseURL: `/${ namespace }/${ taxonomy.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: taxonomy.name,\n\t\t\tgetTitle: ( record ) => record?.name,\n\t\t\tsupportsPagination: true,\n\t\t};\n\t} );\n}\n\n/**\n * Returns the Site entity.\n *\n * @return {Promise} Entity promise\n */\nasync function loadSiteEntity() {\n\tconst entity = {\n\t\tlabel: __( 'Site' ),\n\t\tname: 'site',\n\t\tkind: 'root',\n\t\tkey: false,\n\t\tbaseURL: '/wp/v2/settings',\n\t\tmeta: {},\n\t};\n\n\tconst site = await apiFetch( {\n\t\tpath: entity.baseURL,\n\t\tmethod: 'OPTIONS',\n\t} );\n\n\tconst labels = {};\n\tObject.entries( site?.schema?.properties ?? {} ).forEach(\n\t\t( [ key, value ] ) => {\n\t\t\t// Ignore properties `title` and `type` keys.\n\t\t\tif ( typeof value === 'object' && value.title ) {\n\t\t\t\tlabels[ key ] = value.title;\n\t\t\t}\n\t\t}\n\t);\n\n\treturn [ { ...entity, meta: { labels } } ];\n}\n\n/**\n * Returns the entity's getter method name given its kind and name or plural name.\n *\n * @example\n * ```js\n * const nameSingular = getMethodName( 'root', 'theme', 'get' );\n * // nameSingular is getRootTheme\n *\n * const namePlural = getMethodName( 'root', 'themes', 'set' );\n * // namePlural is setRootThemes\n * ```\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name or plural name.\n * @param {string} prefix Function prefix.\n *\n * @return {string} Method name\n */\nexport const getMethodName = ( kind, name, prefix = 'get' ) => {\n\tconst kindPrefix = kind === 'root' ? '' : pascalCase( kind );\n\tconst suffix = pascalCase( name );\n\treturn `${ prefix }${ kindPrefix }${ suffix }`;\n};\n"],
|
|
5
|
-
"mappings": ";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,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;AAA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A;AAAA,IACR,UAAU,MAAM,GAAI,eAAgB;AAAA,IACpC,iBAAiB,CAAE,UAAU,eAC5B,wBAAyB,QAAS,aACjC,aAAa,MAAM,aAAa,EACjC;AAAA,IACD,oBAAoB;AAAA,EACrB;AAAA,EACA;AAAA,IACC,OAAO,GAAI,QAAS;AAAA,IACpB,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,IACT,eAAe,EAAE,SAAS,OAAO;AAAA,IACjC,QAAQ;AAAA,IACR,KAAK;AAAA,EACN;AAAA,EACA;AAAA,IACC,OAAO,GAAI,SAAU;AAAA,IACrB,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,IACT,eAAe,EAAE,SAAS,OAAO;AAAA,IACjC,QAAQ;AAAA,IACR,KAAK;AAAA,EACN;AAAA,EACA;AAAA,IACC,OAAO,GAAI,QAAS;AAAA,IACpB,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,IACT,eAAe,EAAE,SAAS,OAAO;AAAA,IACjC,QAAQ;AAAA,IACR,KAAK;AAAA,EACN;AAAA,EACA;AAAA,IACC,OAAO,GAAI,sBAAuB;AAAA,IAClC,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,IACT,KAAK;AAAA,EACN;AAAA,EACA;AAAA,IACC,OAAO,GAAI,kBAAmB;AAAA,IAC9B,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,IACT,eAAe,EAAE,SAAS,OAAO;AAAA,IACjC,QAAQ;AAAA,IACR,KAAK;AAAA,EACN;AACD;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { capitalCase, pascalCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { __unstableSerializeAndClean, parse } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { PostEditorAwareness } from './awareness/post-editor-awareness';\nimport { getSyncManager } from './sync';\nimport {\n\tapplyPostChangesToCRDTDoc,\n\tdefaultSyncConfig,\n\tgetPostChangesFromCRDTDoc,\n} from './utils/crdt';\n\nexport const DEFAULT_ENTITY_KEY = 'id';\nconst POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];\n\nconst blocksTransientEdits = {\n\tblocks: {\n\t\tread: ( record ) => parse( record.content?.raw ?? '' ),\n\t\twrite: ( record ) => ( {\n\t\t\tcontent: __unstableSerializeAndClean( record.blocks ),\n\t\t} ),\n\t},\n};\n\nexport const rootEntitiesConfig = [\n\t{\n\t\tlabel: __( 'Base' ),\n\t\tkind: 'root',\n\t\tkey: false,\n\t\tname: '__unstableBase',\n\t\tbaseURL: '/',\n\t\tbaseURLParams: {\n\t\t\t// Please also change the preload path when changing this.\n\t\t\t// @see lib/compat/wordpress-6.8/preload.php\n\t\t\t_fields: [\n\t\t\t\t'description',\n\t\t\t\t'gmt_offset',\n\t\t\t\t'home',\n\t\t\t\t'name',\n\t\t\t\t'site_icon',\n\t\t\t\t'site_icon_url',\n\t\t\t\t'site_logo',\n\t\t\t\t'timezone_string',\n\t\t\t\t'url',\n\t\t\t\t'page_for_posts',\n\t\t\t\t'page_on_front',\n\t\t\t\t'show_on_front',\n\t\t\t].join( ',' ),\n\t\t},\n\t\t// The entity doesn't support selecting multiple records.\n\t\t// The property is maintained for backward compatibility.\n\t\tplural: '__unstableBases',\n\t},\n\t{\n\t\tlabel: __( 'Post Type' ),\n\t\tname: 'postType',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'postTypes',\n\t},\n\t{\n\t\tname: 'media',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/media',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'mediaItems',\n\t\tlabel: __( 'Media' ),\n\t\trawAttributes: [ 'caption', 'title', 'description' ],\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'taxonomy',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/taxonomies',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'taxonomies',\n\t\tlabel: __( 'Taxonomy' ),\n\t},\n\t{\n\t\tname: 'sidebar',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/sidebars',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'sidebars',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widget areas' ),\n\t},\n\t{\n\t\tname: 'widget',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widgets',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgets',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widgets' ),\n\t},\n\t{\n\t\tname: 'widgetType',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widget-types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgetTypes',\n\t\tlabel: __( 'Widget types' ),\n\t},\n\t{\n\t\tlabel: __( 'User' ),\n\t\tname: 'user',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/users',\n\t\tgetTitle: ( record ) => record?.name || record?.slug,\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'users',\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'comment',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/comments',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'comments',\n\t\tlabel: __( 'Comment' ),\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menu',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menus',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menus',\n\t\tlabel: __( 'Menu' ),\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menuItem',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-items',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuItems',\n\t\tlabel: __( 'Menu Item' ),\n\t\trawAttributes: [ 'title' ],\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menuLocation',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-locations',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuLocations',\n\t\tlabel: __( 'Menu Location' ),\n\t\tkey: 'name',\n\t},\n\t{\n\t\tlabel: __( 'Global Styles' ),\n\t\tname: 'globalStyles',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/global-styles',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'globalStylesVariations', // Should be different from name.\n\t\tgetTitle: () => __( 'Custom Styles' ),\n\t\tgetRevisionsUrl: ( parentId, revisionId ) =>\n\t\t\t`/wp/v2/global-styles/${ parentId }/revisions${\n\t\t\t\trevisionId ? '/' + revisionId : ''\n\t\t\t}`,\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tlabel: __( 'Themes' ),\n\t\tname: 'theme',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/themes',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'themes',\n\t\tkey: 'stylesheet',\n\t},\n\t{\n\t\tlabel: __( 'Plugins' ),\n\t\tname: 'plugin',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/plugins',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'plugins',\n\t\tkey: 'plugin',\n\t},\n\t{\n\t\tlabel: __( 'Status' ),\n\t\tname: 'status',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/statuses',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'statuses',\n\t\tkey: 'slug',\n\t},\n\t{\n\t\tlabel: __( 'Registered Templates' ),\n\t\tname: 'registeredTemplate',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/registered-templates',\n\t\tkey: 'id',\n\t},\n\t{\n\t\tlabel: __( 'Font Collections' ),\n\t\tname: 'fontCollection',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/font-collections',\n\t\tbaseURLParams: { context: 'view' },\n\t\tplural: 'fontCollections',\n\t\tkey: 'slug',\n\t},\n].map( ( entity ) => {\n\tconst syncEnabledRootEntities = new Set( [ 'comment' ] );\n\n\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\tif ( syncEnabledRootEntities.has( entity.name ) ) {\n\t\t\tentity.syncConfig = defaultSyncConfig;\n\t\t}\n\t}\n\treturn entity;\n} );\n\nexport const deprecatedEntities = {\n\troot: {\n\t\tmedia: {\n\t\t\tsince: '6.9',\n\t\t\talternative: {\n\t\t\t\tkind: 'postType',\n\t\t\t\tname: 'attachment',\n\t\t\t},\n\t\t},\n\t},\n};\n\nexport const additionalEntityConfigLoaders = [\n\t{ kind: 'postType', loadEntities: loadPostTypeEntities },\n\t{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },\n\t{\n\t\tkind: 'root',\n\t\tname: 'site',\n\t\tplural: 'sites',\n\t\tloadEntities: loadSiteEntity,\n\t},\n];\n\n/**\n * Apply extra edits before persisting a post type.\n *\n * @param {Object} persistedRecord Already persisted Post\n * @param {Object} edits Edits.\n * @param {string} name Post type name.\n * @param {boolean} isTemplate Whether the post type is a template.\n * @return {Object} Updated edits.\n */\nexport const prePersistPostType = (\n\tpersistedRecord,\n\tedits,\n\tname,\n\tisTemplate\n) => {\n\tconst newEdits = {};\n\n\tif ( ! isTemplate && persistedRecord?.status === 'auto-draft' ) {\n\t\t// Saving an auto-draft should create a draft by default.\n\t\tif ( ! edits.status && ! newEdits.status ) {\n\t\t\tnewEdits.status = 'draft';\n\t\t}\n\n\t\t// Fix the auto-draft default title.\n\t\tif (\n\t\t\t( ! edits.title || edits.title === 'Auto Draft' ) &&\n\t\t\t! newEdits.title &&\n\t\t\t( ! persistedRecord?.title ||\n\t\t\t\tpersistedRecord?.title === 'Auto Draft' )\n\t\t) {\n\t\t\tnewEdits.title = '';\n\t\t}\n\t}\n\n\t// Add meta for persisted CRDT document.\n\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\tif ( persistedRecord ) {\n\t\t\tconst objectType = `postType/${ name }`;\n\t\t\tconst objectId = persistedRecord.id;\n\t\t\tconst meta = getSyncManager()?.createMeta( objectType, objectId );\n\t\t\tnewEdits.meta = {\n\t\t\t\t...edits.meta,\n\t\t\t\t...meta,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn newEdits;\n};\n\n/**\n * Returns the list of post type entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadPostTypeEntities() {\n\tconst postTypes = await apiFetch( {\n\t\tpath: '/wp/v2/types?context=view',\n\t} );\n\treturn Object.entries( postTypes ?? {} ).map( ( [ name, postType ] ) => {\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tname\n\t\t);\n\t\tconst namespace = postType?.rest_namespace ?? 'wp/v2';\n\n\t\tconst entity = {\n\t\t\tkind: 'postType',\n\t\t\tbaseURL: `/${ namespace }/${ postType.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: postType.name,\n\t\t\ttransientEdits: {\n\t\t\t\t...blocksTransientEdits,\n\t\t\t\tselection: true,\n\t\t\t},\n\t\t\tmergedEdits: { meta: true },\n\t\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t\t\tgetTitle: ( record ) =>\n\t\t\t\trecord?.title?.rendered ||\n\t\t\t\trecord?.title ||\n\t\t\t\t( isTemplate\n\t\t\t\t\t? capitalCase( record.slug ?? '' )\n\t\t\t\t\t: String( record.id ) ),\n\t\t\t__unstablePrePersist: ( persistedRecord, edits ) =>\n\t\t\t\tprePersistPostType( persistedRecord, edits, name, isTemplate ),\n\t\t\t__unstable_rest_base: postType.rest_base,\n\t\t\tsupportsPagination: true,\n\t\t\tgetRevisionsUrl: ( parentId, revisionId ) =>\n\t\t\t\t`/${ namespace }/${\n\t\t\t\t\tpostType.rest_base\n\t\t\t\t}/${ parentId }/revisions${\n\t\t\t\t\trevisionId ? '/' + revisionId : ''\n\t\t\t\t}`,\n\t\t\trevisionKey:\n\t\t\t\tisTemplate && ! window?.__experimentalTemplateActivate\n\t\t\t\t\t? 'wp_id'\n\t\t\t\t\t: DEFAULT_ENTITY_KEY,\n\t\t};\n\n\t\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\t\t/**\n\t\t\t * @type {import('@wordpress/sync').SyncConfig}\n\t\t\t */\n\t\t\tentity.syncConfig = {\n\t\t\t\t/**\n\t\t\t\t * Apply changes from the local editor to the local CRDT document so\n\t\t\t\t * that those changes can be synced to other peers (via the provider).\n\t\t\t\t *\n\t\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t\t * @param {Partial< import('@wordpress/sync').ObjectData >} changes\n\t\t\t\t * @return {void}\n\t\t\t\t */\n\t\t\t\tapplyChangesToCRDTDoc: ( crdtDoc, changes ) =>\n\t\t\t\t\tapplyPostChangesToCRDTDoc( crdtDoc, changes, postType ),\n\n\t\t\t\t/**\n\t\t\t\t * Create the awareness instance for the entity's CRDT document.\n\t\t\t\t *\n\t\t\t\t * @param {import('@wordpress/sync').CRDTDoc} ydoc\n\t\t\t\t * @param {import('@wordpress/sync').ObjectID} objectId\n\t\t\t\t * @return {import('@wordpress/sync').AwarenessState} AwarenessState instance\n\t\t\t\t */\n\t\t\t\tcreateAwareness: ( ydoc, objectId ) => {\n\t\t\t\t\tconst kind = 'postType';\n\t\t\t\t\tconst id = parseInt( objectId, 10 );\n\t\t\t\t\treturn new PostEditorAwareness( ydoc, kind, name, id );\n\t\t\t\t},\n\n\t\t\t\t/**\n\t\t\t\t * Extract changes from a CRDT document that can be used to update the\n\t\t\t\t * local editor state.\n\t\t\t\t *\n\t\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t\t * @param {import('@wordpress/sync').ObjectData} editedRecord\n\t\t\t\t * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record\n\t\t\t\t */\n\t\t\t\tgetChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>\n\t\t\t\t\tgetPostChangesFromCRDTDoc(\n\t\t\t\t\t\tcrdtDoc,\n\t\t\t\t\t\teditedRecord,\n\t\t\t\t\t\tpostType\n\t\t\t\t\t),\n\n\t\t\t\t/**\n\t\t\t\t * Sync features supported by the entity.\n\t\t\t\t *\n\t\t\t\t * @type {Record< string, boolean >}\n\t\t\t\t */\n\t\t\t\tsupports: {\n\t\t\t\t\tcrdtPersistence: true,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn entity;\n\t} );\n}\n\n/**\n * Returns the list of the taxonomies entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadTaxonomyEntities() {\n\tconst taxonomies = await apiFetch( {\n\t\tpath: '/wp/v2/taxonomies?context=view',\n\t} );\n\treturn Object.entries( taxonomies ?? {} ).map( ( [ name, taxonomy ] ) => {\n\t\tconst namespace = taxonomy?.rest_namespace ?? 'wp/v2';\n\t\tconst entity = {\n\t\t\tkind: 'taxonomy',\n\t\t\tbaseURL: `/${ namespace }/${ taxonomy.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: taxonomy.name,\n\t\t\tgetTitle: ( record ) => record?.name,\n\t\t\tsupportsPagination: true,\n\t\t};\n\n\t\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\t\tentity.syncConfig = defaultSyncConfig;\n\t\t}\n\n\t\treturn entity;\n\t} );\n}\n\n/**\n * Returns the Site entity.\n *\n * @return {Promise} Entity promise\n */\nasync function loadSiteEntity() {\n\tconst entity = {\n\t\tlabel: __( 'Site' ),\n\t\tname: 'site',\n\t\tkind: 'root',\n\t\tkey: false,\n\t\tbaseURL: '/wp/v2/settings',\n\t\tmeta: {},\n\t};\n\n\tconst site = await apiFetch( {\n\t\tpath: entity.baseURL,\n\t\tmethod: 'OPTIONS',\n\t} );\n\n\tconst labels = {};\n\tObject.entries( site?.schema?.properties ?? {} ).forEach(\n\t\t( [ key, value ] ) => {\n\t\t\t// Ignore properties `title` and `type` keys.\n\t\t\tif ( typeof value === 'object' && value.title ) {\n\t\t\t\tlabels[ key ] = value.title;\n\t\t\t}\n\t\t}\n\t);\n\n\treturn [ { ...entity, meta: { labels } } ];\n}\n\n/**\n * Returns the entity's getter method name given its kind and name or plural name.\n *\n * @example\n * ```js\n * const nameSingular = getMethodName( 'root', 'theme', 'get' );\n * // nameSingular is getRootTheme\n *\n * const namePlural = getMethodName( 'root', 'themes', 'set' );\n * // namePlural is setRootThemes\n * ```\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name or plural name.\n * @param {string} prefix Function prefix.\n *\n * @return {string} Method name\n */\nexport const getMethodName = ( kind, name, prefix = 'get' ) => {\n\tconst kindPrefix = kind === 'root' ? '' : pascalCase( kind );\n\tconst suffix = pascalCase( name );\n\treturn `${ prefix }${ kindPrefix }${ suffix }`;\n};\n"],
|
|
5
|
+
"mappings": ";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,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;A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Aa,SAAS,SAAS,KAAK,WAAY,IAAK;AAC3D,QAAM,SAAS,WAAY,IAAK;AAChC,SAAO,GAAI,MAAO,GAAI,UAAW,GAAI,MAAO;AAC7C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
isNumericID
|
|
17
17
|
} from "./utils/index.mjs";
|
|
18
18
|
import { fetchBlockPatterns } from "./fetch/index.mjs";
|
|
19
|
+
import { restoreSelection, getSelectionHistory } from "./utils/crdt-selection.mjs";
|
|
19
20
|
var getAuthors = (query) => async ({ dispatch }) => {
|
|
20
21
|
const path = addQueryArgs(
|
|
21
22
|
"/wp/v2/users/?who=authors&per_page=100",
|
|
@@ -145,6 +146,26 @@ var getEntityRecord = (kind, name, key = "", query) => async ({ select, dispatch
|
|
|
145
146
|
name,
|
|
146
147
|
key
|
|
147
148
|
);
|
|
149
|
+
},
|
|
150
|
+
addUndoMeta: (ydoc, meta) => {
|
|
151
|
+
const selectionHistory = getSelectionHistory(ydoc);
|
|
152
|
+
if (selectionHistory) {
|
|
153
|
+
meta.set(
|
|
154
|
+
"selectionHistory",
|
|
155
|
+
selectionHistory
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
restoreUndoMeta: (ydoc, meta) => {
|
|
160
|
+
const selectionHistory = meta.get("selectionHistory");
|
|
161
|
+
if (selectionHistory) {
|
|
162
|
+
setTimeout(() => {
|
|
163
|
+
restoreSelection(
|
|
164
|
+
selectionHistory,
|
|
165
|
+
ydoc
|
|
166
|
+
);
|
|
167
|
+
}, 0);
|
|
168
|
+
}
|
|
148
169
|
}
|
|
149
170
|
}
|
|
150
171
|
);
|
|
@@ -273,6 +294,25 @@ var getEntityRecords = (kind, name, query = {}) => async ({ dispatch, registry,
|
|
|
273
294
|
totalPages: 1
|
|
274
295
|
};
|
|
275
296
|
}
|
|
297
|
+
if (globalThis.IS_GUTENBERG_PLUGIN) {
|
|
298
|
+
if (entityConfig.syncConfig && -1 === query.per_page) {
|
|
299
|
+
const objectType = `${kind}/${name}`;
|
|
300
|
+
getSyncManager()?.loadCollection(
|
|
301
|
+
entityConfig.syncConfig,
|
|
302
|
+
objectType,
|
|
303
|
+
{
|
|
304
|
+
refetchRecords: async () => {
|
|
305
|
+
dispatch.receiveEntityRecords(
|
|
306
|
+
kind,
|
|
307
|
+
name,
|
|
308
|
+
await apiFetch({ path, parse: true }),
|
|
309
|
+
query
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
276
316
|
if (query._fields) {
|
|
277
317
|
records = records.map((record) => {
|
|
278
318
|
query._fields.split(",").forEach((field) => {
|